X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex%2Fdirplex.c;h=55b464801f3a28b0c3fc8f0101b6845f32ccac69;hb=3d6044aba083ec8fa366bf85794a9ae62eab9858;hp=162e4fd9dd1200796afb213d0e24c3925ef52b2c;hpb=c6cb01ef6ac92d48f1eb82e173662023547355fc;p=ashd.git diff --git a/src/dirplex/dirplex.c b/src/dirplex/dirplex.c index 162e4fd..55b4648 100644 --- a/src/dirplex/dirplex.c +++ b/src/dirplex/dirplex.c @@ -59,8 +59,15 @@ static void handle(struct hthead *req, int fd, char *path, struct pattern *pat) { struct child *ch; struct config *ccf; + struct headmod *head; char *twd; + for(head = pat->headers; head != NULL; head = head->next) { + headrmheader(req, head->name); + headappheader(req, head->name, head->value); + } + if(!strncmp(path, "./", 2) && path[2]) + path += 2; if(pat->fchild) { headappheader(req, "X-Ash-File", path); stdforkserve(pat->fchild, req, fd, NULL, NULL); @@ -70,8 +77,7 @@ static void handle(struct hthead *req, int fd, char *path, struct pattern *pat) simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.", pat->childnm); return; } - twd = NULL; - if((twd = ccf->path) != NULL) { + if((twd = ccf?ccf->path:NULL) != NULL) { if(!strcmp(twd, ".")) { twd = NULL; } else if(strncmp(path, twd, strlen(twd)) || (path[strlen(twd)] != '/')) { @@ -89,12 +95,25 @@ static void handle(struct hthead *req, int fd, char *path, struct pattern *pat) } } +static void handle404(struct hthead *req, int fd, char *path) +{ + struct child *ch; + struct config *ccf; + char *tmp; + + tmp = sstrdup(path); + ch = findchild(tmp, ".notfound", &ccf); + if(childhandle(ch, req, fd, chinit, ccf?ccf->path:NULL)) + simpleerror(fd, 500, "Server Error", "The request handler crashed."); + free(tmp); +} + static void handlefile(struct hthead *req, int fd, char *path) { struct pattern *pat; if((pat = findmatch(path, 0, 0)) == NULL) { - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, path); return; } handle(req, fd, path, pat); @@ -186,7 +205,7 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * int rv; if(*el == '.') { - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, sprintf3("%s/", path)); return(1); } if(!stat(sprintf3("%s/%s", path, el), &sb)) { @@ -206,7 +225,7 @@ static int checkentry(struct hthead *req, int fd, char *path, char *rest, char * free(newpath); return(1); } - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, sprintf3("%s/", path)); return(1); } if(!strchr(el, '.') && ((newpath = findfile(path, el, NULL)) != NULL)) { @@ -237,7 +256,7 @@ static int checkdir(struct hthead *req, int fd, char *path, char *rest) if(*rest == '/') rest++; replrest(req, rest); - if(childhandle(ch, req, fd, chinit, ccf->path)) + if(childhandle(ch, req, fd, chinit, ccf?ccf->path:NULL)) simpleerror(fd, 500, "Server Error", "The request handler crashed."); return(1); } @@ -273,7 +292,7 @@ static int checkpath(struct hthead *req, int fd, char *path, char *rest) goto out; } if(strchr(el, '/') || (!*el && *rest)) { - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, sprintf3("%s/", path)); rv = 1; goto out; } @@ -295,16 +314,18 @@ static void serve(struct hthead *req, int fd) { now = time(NULL); if(!checkpath(req, fd, ".", req->rest)) - simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource."); + handle404(req, fd, "."); } static void chldhandler(int sig) { pid_t pid; + int st; - do { - pid = waitpid(-1, NULL, WNOHANG); - } while(pid > 0); + while((pid = waitpid(-1, &st, WNOHANG)) > 0) { + if(WCOREDUMP(st)) + flog(LOG_WARNING, "child process %i dumped core", pid); + } } static void sighandler(int sig)