From: Fredrik Tolf Date: Sun, 5 Sep 2010 04:53:39 +0000 (+0200) Subject: dirplex: Added directory capture mode. X-Git-Tag: 0.1~19 X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=300d73d9ee0fe2fb09643a2a146711f1a8d7edd3 dirplex: Added directory capture mode. --- diff --git a/src/dirplex/conf.c b/src/dirplex/conf.c index e40a445..e83d847 100644 --- a/src/dirplex/conf.c +++ b/src/dirplex/conf.c @@ -76,6 +76,8 @@ static void freeconfig(struct config *cf) freepattern(pat); } freeca(cf->index); + if(cf->capture != NULL) + free(cf->capture); free(cf); } @@ -228,6 +230,14 @@ struct config *readconfig(char *file) cf->index = NULL; if(s->argc > 1) cf->index = cadup(s->argv + 1); + } else if(!strcmp(s->argv[0], "capture")) { + if(s->argc < 2) { + flog(LOG_WARNING, "%s:%i: missing argument to capture declaration", s->file, s->lno); + continue; + } + if(cf->capture != NULL) + free(cf->capture); + cf->capture = sstrdup(s->argv[1]); } else if(!strcmp(s->argv[0], "eof")) { break; } else { diff --git a/src/dirplex/dirplex.c b/src/dirplex/dirplex.c index 7f2a12d..f8ac25a 100644 --- a/src/dirplex/dirplex.c +++ b/src/dirplex/dirplex.c @@ -217,9 +217,34 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * return(0); } +static int checkdir(struct hthead *req, int fd, char *path, char *rest) +{ + char *cpath; + struct config *cf, *ccf; + struct child *ch; + + cf = getconfig(path); + if(cf->capture != NULL) { + cpath = sprintf2("%s/", path); + if((ch = findchild(cpath, cf->capture, &ccf)) == NULL) { + free(cpath); + flog(LOG_ERR, "child %s requested for capture, but was not declared", cf->capture); + simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.", cf->capture); + return(1); + } + free(cpath); + if(*rest == '/') + rest++; + replrest(req, rest); + if(childhandle(ch, req, fd, chinit, ccf->path)) + simpleerror(fd, 500, "Server Error", "The request handler crashed."); + return(1); + } + return(0); +} + static int checkpath(struct hthead *req, int fd, char *path, char *rest) { - struct config *cf; char *p, *el; int rv; @@ -228,7 +253,8 @@ static int checkpath(struct hthead *req, int fd, char *path, char *rest) if(!strncmp(path, "./", 2)) path += 2; - cf = getconfig(path); + if(checkdir(req, fd, path, rest)) + return(1); if((p = strchr(rest, '/')) == NULL) { el = unquoteurl(rest); diff --git a/src/dirplex/dirplex.h b/src/dirplex/dirplex.h index d486529..34402e3 100644 --- a/src/dirplex/dirplex.h +++ b/src/dirplex/dirplex.h @@ -16,6 +16,7 @@ struct config { struct child *children; struct pattern *patterns; char **index; + char *capture; }; struct rule {