]> granicus.if.org Git - apache/commitdiff
This is part two.
authorAndré Malo <nd@apache.org>
Mon, 24 Feb 2003 21:44:15 +0000 (21:44 +0000)
committerAndré Malo <nd@apache.org>
Mon, 24 Feb 2003 21:44:15 +0000 (21:44 +0000)
It fixes the prefix_stat function. (which does a stat call on the first
path segment). This function was still tailored for unix systems only.
It should work on other systems as well now.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98782 13f79535-47bb-0310-9956-ffa450edef68

modules/mappers/mod_rewrite.c
modules/mappers/mod_rewrite.h

index 75e17a101057b1fb40f261f7a2af77166600ab01..84e20714bcac96d82ec214714c7a4f9143a87439 100644 (file)
@@ -1083,7 +1083,6 @@ static int hook_uri2file(request_rec *r)
     char docroot[512];
     char *cp, *cp2;
     const char *ccp;
-    apr_finfo_t finfo;
     unsigned int port;
     int rulestatus;
     int n;
@@ -1313,7 +1312,7 @@ static int hook_uri2file(request_rec *r)
              * because we only do stat() on the first directory
              * and this gets cached by the kernel for along time!
              */
-            n = prefix_stat(r->filename, &finfo);
+            n = prefix_stat(r->filename, r->pool);
             if (n == 0) {
                 if ((ccp = ap_document_root(r)) != NULL) {
                     l = apr_cpystrn(docroot, ccp, sizeof(docroot)) - docroot;
@@ -4219,24 +4218,45 @@ static int subreq_ok(request_rec *r)
 **
 */
 
-static int prefix_stat(const char *path, apr_finfo_t *sb)
+static int prefix_stat(const char *path, apr_pool_t *pool)
 {
-    char curpath[LONG_STRING_LEN];
-    char *cp;
+    const char *curpath = path;
+    char *root;
+    char *slash;
+    char *statpath;
+    apr_status_t rv;
 
-    apr_cpystrn(curpath, path, sizeof(curpath));
-    if (curpath[0] != '/') {
+    rv = apr_filepath_root(&root, &curpath, APR_FILEPATH_TRUENAME, pool);
+
+    if (rv != APR_SUCCESS) {
         return 0;
     }
-    if ((cp = strchr(curpath+1, '/')) != NULL) {
-        *cp = '\0';
-    }
-    if (apr_stat(sb, curpath, APR_FINFO_MIN, NULL) == APR_SUCCESS) {
-        return 1;
+
+    /* let's recognize slashes only, the mod_rewrite semantics are opaque
+     * enough.
+     */
+    if ((slash = ap_strchr(curpath, '/')) != NULL) {
+        rv = apr_filepath_merge(&statpath, root,
+                                apr_pstrndup(pool, curpath,
+                                             (apr_size_t)(slash - curpath)),
+                                APR_FILEPATH_NOTABOVEROOT |
+                                APR_FILEPATH_NOTRELATIVE, pool);
     }
     else {
-        return 0;
+        rv = apr_filepath_merge(&statpath, root, curpath,
+                                APR_FILEPATH_NOTABOVEROOT |
+                                APR_FILEPATH_NOTRELATIVE, pool);
     }
+
+    if (rv == APR_SUCCESS) {
+        apr_finfo_t sb;
+        
+        if (apr_stat(&sb, statpath, APR_FINFO_MIN, pool) == APR_SUCCESS) {
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 
index 08824eb5a4b0664e7a3c463fbe41d2a347ea5f95..c826359b41cb7769689c7390fc9b24b4286b3620 100644 (file)
@@ -462,7 +462,7 @@ static void   store_cache_string(cache *c, const char *res, cacheentry *ce);
 static char  *subst_prefix_path(request_rec *r, char *input, char *match,
                                 const char *subst);
 static int    parseargline(char *str, char **a1, char **a2, char **a3);
-static int    prefix_stat(const char *path, apr_finfo_t *sb);
+static int    prefix_stat(const char *path, apr_pool_t *pool);
 static void   add_env_variable(request_rec *r, char *s);
 static void   add_cookie(request_rec *r, char *s);
 static int    subreq_ok(request_rec *r);