]> www.dolda2000.com Git - ashd.git/commitdiff
dirplex: Added directory-locality to matches.
authorFredrik Tolf <fredrik@dolda2000.com>
Sat, 15 Jan 2011 04:11:33 +0000 (05:11 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sat, 15 Jan 2011 04:14:41 +0000 (05:14 +0100)
doc/dirplex.doc
src/dirplex/conf.c
src/dirplex/dirplex.h

index cc243e06f43cd0781ac2e1d999411a8a990daf35..879823501dc57130a88121427facecf84db1e69a 100644 (file)
@@ -219,6 +219,12 @@ The following rules are recognized:
        Matches if and only if no *match* stanza without a *default*
        rule has matched.
 
+*local*::
+
+       Valid only in `.htrc` files, *local* matches if an only if the
+       file under consideration resides in the same directory as the
+       containing `.htrc` file.
+
 In addition to the rules, a *match* stanza must contain exactly one
 follow-up line specifying the action to take if it matches. The
 following actions are recognized:
index e83d847e665663037602649a450573cd804eba5f..8494050adecb658330055bd5e43302436ece5bd4 100644 (file)
@@ -164,6 +164,8 @@ static struct pattern *parsepattern(struct cfstate *s)
            newrule(pat)->type = PAT_ALL;
        } else if(!strcmp(s->argv[0], "default")) {
            newrule(pat)->type = PAT_DEFAULT;
+       } else if(!strcmp(s->argv[0], "local")) {
+           newrule(pat)->type = PAT_LOCAL;
        } else if(!strcmp(s->argv[0], "handler")) {
            if(s->argc < 2) {
                flog(LOG_WARNING, "%s:%i: missing child name for `handler' directive", s->file, s->lno);
@@ -363,6 +365,7 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
     struct config **cfs;
     struct pattern *pat;
     struct rule *rule;
+    size_t pl;
     
     if((bn = strrchr(file, '/')) != NULL)
        bn++;
@@ -394,6 +397,12 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
                } else if(rule->type == PAT_DEFAULT) {
                    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, '/')))
+                       break;
                }
            }
            if(!rule)
index 34402e32ffe036e8c450e25106cf9836384d6c04..028a3d93a40a97bde1f8c9f99eee2e4b245399ea 100644 (file)
@@ -5,6 +5,7 @@
 #define PAT_PATHNAME 1
 #define PAT_ALL 2
 #define PAT_DEFAULT 3
+#define PAT_LOCAL 4
 
 #define PT_FILE 0
 #define PT_DIR 1