- now = time(NULL);
- nm = req->rest;
- path = sstrdup(".");
- p = nm;
- while(1) {
- if((p2 = strchr(p, '/')) == NULL) {
- } else {
- *(p2++) = 0;
- }
-
- if(!*p) {
- if(p2 == NULL) {
- if(stat(path, &sb)) {
- flog(LOG_WARNING, "failed to stat previously stated directory %s: %s", path, strerror(errno));
- simpleerror(fd, 500, "Internal Server Error", "The server encountered an unexpected condition.");
- goto fail;
- }
- break;
- } else {
- simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
- goto fail;
- }
- }
- if(*p == '.') {
- simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
- goto fail;
- }
-
- getconfig(path);
-
- /*
- * First, check the name verbatimely:
- */
- buf = sprintf3("%s/%s", path, p);
- if(!stat(buf, &sb)) {
- if(S_ISDIR(sb.st_mode)) {
- tmp = path;
- if(!strcmp(path, "."))
- path = sstrdup(p);
- else
- path = sprintf2("%s/%s", path, p);
- free(tmp);
- if(p2 == NULL) {
- stdredir(req, fd, 301, sprintf3("%s/", p));
- goto out;
- }
- if(checkdir(req, fd, path))
- break;
- goto next;
- }
- if(S_ISREG(sb.st_mode)) {
- tmp = path;
- path = sprintf2("%s/%s", path, p);
- free(tmp);
- break;
- }
- simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
- goto fail;
- }
-
- /*
- * Check the file extensionlessly:
- */
- if(!strchr(p, '.') && ((dir = opendir(path)) != NULL)) {
- while((dent = readdir(dir)) != NULL) {
- buf = sprintf3("%s/%s", path, dent->d_name);
- if((p3 = strchr(dent->d_name, '.')) != NULL)
- *p3 = 0;
- if(strcmp(dent->d_name, p))
- continue;
- if(stat(buf, &sb))
- continue;
- if(!S_ISREG(sb.st_mode))
- continue;
- tmp = path;
- path = sstrdup(buf);
- free(tmp);
- break;
+ if(!el == '.') {
+ simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
+ return(1);
+ }
+ if(!stat(sprintf3("%s/%s", path, el), &sb)) {
+ if(S_ISDIR(sb.st_mode)) {
+ if(!*rest) {
+ stdredir(req, fd, 301, sprintf3("%s/", el));
+ return(1);