dirplex: Match pathname directives relative to the config path.
[ashd.git] / src / dirplex / conf.c
index e2b1481..84c035d 100644 (file)
@@ -185,13 +185,16 @@ static struct pattern *parsepattern(struct cfstate *s)
            pat->childnm = sstrdup(s->argv[1]);
        } else if(!strcmp(s->argv[0], "fork")) {
            pat->fchild = cadup(s->argv + 1);
-       } else if(!strcmp(s->argv[0], "set")) {
+       } else if(!strcmp(s->argv[0], "set") || !strcmp(s->argv[0], "xset")) {
            if(s->argc < 3) {
-               flog(LOG_WARNING, "%s:%i: missing header name or pattern for `set' directive", s->file, s->lno);
+               flog(LOG_WARNING, "%s:%i: missing header name or pattern for `%s' directive", s->file, s->lno, s->argv[0]);
                continue;
            }
            omalloc(head);
-           head->name = sstrdup(s->argv[1]);
+           if(!strcmp(s->argv[0], "xset"))
+               head->name = sprintf2("X-Ash-%s", s->argv[1]);
+           else
+               head->name = sstrdup(s->argv[1]);
            head->value = sstrdup(s->argv[2]);
            head->next = pat->headers;
            pat->headers = head;
@@ -326,6 +329,8 @@ struct config **getconfigs(char *file)
     if(ret != NULL)
        free(ret);
     bufinit(buf);
+    if(!strncmp(file, "./", 2))
+       file += 2;
     tmp = sstrdup(file);
     while(1) {
        if((p = strrchr(tmp, '/')) == NULL)
@@ -369,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;
-    char *bn;
+    char *bn, *ln;
     struct config **cfs;
     struct pattern *pat;
     struct rule *rule;
@@ -381,6 +386,15 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
        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;
@@ -396,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++) {
-                       if(!fnmatch(rule->patterns[o], file, FNM_PATHNAME))
+                       if(!fnmatch(rule->patterns[o], ln, FNM_PATHNAME))
                            break;
                    }
                    if(rule->patterns[o] == NULL)
@@ -406,10 +420,7 @@ struct pattern *findmatch(char *file, int trydefault, int dir)
                    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;
                }
            }