From: Fredrik Tolf Date: Sat, 28 Mar 2015 23:38:32 +0000 (+0100) Subject: dirplex: Added reparse support. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=539c7b9f70c856a6451685e405b3a6c870d34ee4;p=ashd.git dirplex: Added reparse support. --- diff --git a/src/dirplex/conf.c b/src/dirplex/conf.c index 359bf0c..9ae4ca7 100644 --- a/src/dirplex/conf.c +++ b/src/dirplex/conf.c @@ -86,6 +86,8 @@ static void freeconfig(struct config *cf) freeca(cf->index); if(cf->capture != NULL) free(cf->capture); + if(cf->reparse != NULL) + free(cf->reparse); free(cf); } @@ -267,6 +269,17 @@ struct config *readconfig(char *file) cf->caproot = 0; if((s->argc > 2) && strchr(s->argv[2], 'D')) cf->caproot = 1; + } else if(!strcmp(s->argv[0], "reparse")) { + if(s->argc < 2) { + flog(LOG_WARNING, "%s:%i: missing argument to reparse declaration", s->file, s->lno); + continue; + } + if(cf->reparse != NULL) + free(cf->reparse); + cf->reparse = sstrdup(s->argv[1]); + cf->parsecomb = 0; + if((s->argc > 2) && strchr(s->argv[2], 'c')) + cf->parsecomb = 1; } else if(!strcmp(s->argv[0], "eof")) { break; } else { diff --git a/src/dirplex/dirplex.c b/src/dirplex/dirplex.c index 65f09f7..73bb9cc 100644 --- a/src/dirplex/dirplex.c +++ b/src/dirplex/dirplex.c @@ -249,9 +249,11 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * static int checkdir(struct hthead *req, int fd, char *path, char *rest) { - char *cpath; + char *cpath, *newpath; struct config *cf, *ccf; struct child *ch; + struct stat sb; + int rv; cf = getconfig(path); if((cf->capture != NULL) && (cf->caproot || !cf->path || strcmp(cf->path, "."))) { @@ -270,6 +272,22 @@ static int checkdir(struct hthead *req, int fd, char *path, char *rest) childerror(req, fd); return(1); } + if(cf->reparse != NULL) { + newpath = (cf->reparse[0] == '/')?sstrdup(cf->reparse):sprintf2("%s/%s", path, cf->reparse); + rv = stat(newpath, &sb); + if(!rv && S_ISDIR(sb.st_mode)) { + rv = checkpath(req, fd, newpath, rest, !cf->parsecomb); + } else if(!rv && S_ISREG(sb.st_mode)) { + replrest(req, rest); + handlefile(req, fd, newpath); + rv = 1; + } else { + rv = !cf->parsecomb; + } + free(newpath); + if(rv) + return(rv); + } return(0); } diff --git a/src/dirplex/dirplex.h b/src/dirplex/dirplex.h index 77caa64..ffe12a6 100644 --- a/src/dirplex/dirplex.h +++ b/src/dirplex/dirplex.h @@ -18,8 +18,8 @@ struct config { struct child *children; struct pattern *patterns; char **index; - char *capture; - int caproot; + char *capture, *reparse; + int caproot, parsecomb; }; struct rule {