dirplex: Match pathname directives relative to the config path.
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 23 Jan 2012 07:01:53 +0000 (08:01 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 23 Jan 2012 07:01:53 +0000 (08:01 +0100)
doc/dirplex.doc
src/dirplex/conf.c

index fb4b7e7..fce3565 100644 (file)
@@ -224,11 +224,13 @@ The following rules are recognized:
 
 *pathname* 'PATTERN'...::
 
 
 *pathname* 'PATTERN'...::
 
-       Matches if the entire path (relative as considered from the
-       root directory being served) of the file under consideration
+       Matches if the entire path of the file under consideration
        matches any of the 'PATTERNs'. A 'PATTERN' is an ordinary glob
        pattern, except that slashes are not matched by wildcards. See
        matches any of the 'PATTERNs'. A 'PATTERN' is an ordinary glob
        pattern, except that slashes are not matched by wildcards. See
-       *fnmatch*(3) for more information.
+       *fnmatch*(3) for more information. If a *pathname* rule is
+       specified in a `.htrc` file, the path will be examined as
+       relative to the directory containing the `.htrc` file, rather
+       than to the root directory being served.
 
 *default*::
 
 
 *default*::
 
index 10d501f..84c035d 100644 (file)
@@ -374,7 +374,7 @@ struct child *findchild(char *file, char *name, struct config **cf)
 struct pattern *findmatch(char *file, int trydefault, int dir)
 {
     int i, o, c;
 struct pattern *findmatch(char *file, int trydefault, int dir)
 {
     int i, o, c;
-    char *bn;
+    char *bn, *ln;
     struct config **cfs;
     struct pattern *pat;
     struct rule *rule;
     struct config **cfs;
     struct pattern *pat;
     struct rule *rule;
@@ -386,6 +386,15 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
        bn = file;
     cfs = getconfigs(file);
     for(c = 0; cfs[c] != NULL; c++) {
        bn = file;
     cfs = getconfigs(file);
     for(c = 0; cfs[c] != NULL; c++) {
+       if(cfs[c]->path == NULL) {
+           ln = file;
+       } else {
+           pl = strlen(cfs[c]->path);
+           if((strlen(file) > pl) && !strncmp(file, cfs[c]->path, pl) && (file[pl] == '/'))
+               ln = file + pl + 1;
+           else
+               ln = file;      /* This should only happen in the base directory. */
+       }
        for(pat = cfs[c]->patterns; pat != NULL; pat = pat->next) {
            if(!dir && (pat->type == PT_DIR))
                continue;
        for(pat = cfs[c]->patterns; pat != NULL; pat = pat->next) {
            if(!dir && (pat->type == PT_DIR))
                continue;
@@ -401,7 +410,7 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
                        break;
                } else if(rule->type == PAT_PATHNAME) {
                    for(o = 0; rule->patterns[o] != NULL; o++) {
                        break;
                } else if(rule->type == PAT_PATHNAME) {
                    for(o = 0; rule->patterns[o] != NULL; o++) {
-                       if(!fnmatch(rule->patterns[o], file, FNM_PATHNAME))
+                       if(!fnmatch(rule->patterns[o], ln, FNM_PATHNAME))
                            break;
                    }
                    if(rule->patterns[o] == NULL)
                            break;
                    }
                    if(rule->patterns[o] == NULL)
@@ -411,10 +420,7 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
                    if(!trydefault)
                        break;
                } else if(rule->type == PAT_LOCAL) {
                    if(!trydefault)
                        break;
                } else if(rule->type == PAT_LOCAL) {
-                   if(cfs[c]->path == NULL)
-                       break;
-                   pl = strlen(cfs[c]->path);
-                   if(!((strlen(file) > pl) && !strncmp(file, cfs[c]->path, pl) && (file[pl] == '/') && !strchr(file + pl + 1, '/')))
+                   if(strchr(ln, '/'))
                        break;
                }
            }
                        break;
                }
            }