X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex.c;h=01d87157319005e62bf3a75682995eb2ba4e9b80;hb=6373daf9d9fdd9e24d2c657abf0625337f9b3a24;hp=f4cc6121cae2670d3b23a4d07740cf39e7ccb934;hpb=1eba4f97b3f976614da9d820b2130c0150c38910;p=ashd.git diff --git a/src/dirplex.c b/src/dirplex.c index f4cc612..01d8715 100644 --- a/src/dirplex.c +++ b/src/dirplex.c @@ -49,6 +49,7 @@ struct config { time_t mtime, lastck; struct child *children; struct pattern *patterns; + char **index; }; struct rule { @@ -106,6 +107,7 @@ static void freeconfig(struct config *cf) npat = pat->next; freepattern(pat); } + freeca(cf->index); free(cf); } @@ -251,6 +253,11 @@ static struct config *readconfig(char *file) } else if((pat = parsepattern(s)) != NULL) { pat->next = cf->patterns; cf->patterns = pat; + } else if(!strcmp(s->argv[0], "index-file")) { + freeca(cf->index); + cf->index = NULL; + if(s->argc > 1) + cf->index = cadup(s->argv + 1); } else if(!strcmp(s->argv[0], "eof")) { break; } else { @@ -413,8 +420,54 @@ static void handlefile(struct hthead *req, int fd, char *path) static void handledir(struct hthead *req, int fd, char *path) { - /* XXX: Todo */ - simpleerror(fd, 403, "Not Authorized", "Will not send directory listings or indices yet."); + struct config **cfs; + int i, o; + struct stat sb; + char *inm, *ipath, *p; + DIR *dir; + struct dirent *dent; + + cfs = getconfigs(sprintf3("%s/", path)); + for(i = 0; cfs[i] != NULL; i++) { + if(cfs[i]->index != NULL) { + for(o = 0; cfs[i]->index[o] != NULL; o++) { + inm = cfs[i]->index[o]; + ipath = sprintf2("%s/%s", path, inm); + if(!stat(ipath, &sb) && S_ISREG(sb.st_mode)) { + handlefile(req, fd, ipath); + free(ipath); + return; + } + free(ipath); + + ipath = NULL; + if(!strchr(inm, '.') && ((dir = opendir(path)) != NULL)) { + while((dent = readdir(dir)) != NULL) { + if((p = strchr(dent->d_name, '.')) == NULL) + continue; + if(strncmp(dent->d_name, inm, p - dent->d_name)) + continue; + ipath = sprintf2("%s/%s", path, dent->d_name); + if(stat(ipath, &sb) || !S_ISREG(sb.st_mode)) { + free(ipath); + ipath = NULL; + continue; + } + break; + } + closedir(dir); + } + if(ipath != NULL) { + handlefile(req, fd, ipath); + free(ipath); + return; + } + } + break; + } + } + /* XXX: Directory listings */ + simpleerror(fd, 403, "Not Authorized", "Will not send listings for this directory."); } static int checkdir(struct hthead *req, int fd, char *path)