Implement ap_getparent() using ap_normalize_path().
It is functionaly the same as AP_NORMALIZE_ALLOW_RELATIVE flag, while
ap_normalize_path() is more efficient (single pass).
@@ -607,70 +607,9 @@ AP_DECLARE(int) ap_normalize_path(char *path, unsigned int flags)
*/
AP_DECLARE(void) ap_getparents(char *name)
{
- char *next;
- int l, w, first_dot;
-
- /* Four paseses, as per RFC 1808 */
- /* a) remove ./ path segments */
- for (next = name; *next && (*next != '.'); next++) {
- }
-
- l = w = first_dot = next - name;
- while (name[l] != '\0') {
- if (name[l] == '.' && IS_SLASH(name[l + 1])
- && (l == 0 || IS_SLASH(name[l - 1])))
- l += 2;
- else
- name[w++] = name[l++];
+ (void)ap_normalize_path(name, AP_NORMALIZE_ALLOW_RELATIVE);
}
- /* b) remove trailing . path, segment */
- if (w == 1 && name[0] == '.')
- w--;
- else if (w > 1 && name[w - 1] == '.' && IS_SLASH(name[w - 2]))
- w--;
- name[w] = '\0';
-
- /* c) remove all xx/../ segments. (including leading ../ and /../) */
- l = first_dot;
-
- while (name[l] != '\0') {
- if (name[l] == '.' && name[l + 1] == '.' && IS_SLASH(name[l + 2])
- && (l == 0 || IS_SLASH(name[l - 1]))) {
- int m = l + 3, n;
-
- l = l - 2;
- if (l >= 0) {
- while (l >= 0 && !IS_SLASH(name[l]))
- l--;
- l++;
- }
- else
- l = 0;
- n = l;
- while ((name[n] = name[m]))
- (++n, ++m);
- }
- else
- ++l;
- }
-
- /* d) remove trailing xx/.. segment. */
- if (l == 2 && name[0] == '.' && name[1] == '.')
- name[0] = '\0';
- else if (l > 2 && name[l - 1] == '.' && name[l - 2] == '.'
- && IS_SLASH(name[l - 3])) {
- l = l - 4;
- if (l >= 0) {
- while (l >= 0 && !IS_SLASH(name[l]))
- l--;
- l++;
- }
- else
- l = 0;
- name[l] = '\0';
- }
-}
AP_DECLARE(void) ap_no2slash_ex(char *name, int is_fs_path)
{
