#include <log.h>
#include <req.h>
#include <proc.h>
+#include <resp.h>
#define CH_SOCKET 0
#define CH_FORK 1
for(i = 0; pat->rules[i]; i++);
pat->rules = srealloc(pat->rules, sizeof(*pat->rules) * (i + 2));
- rule = pat->rules[i] = smalloc(sizeof(*rule));
+ rule = pat->rules[i] = szmalloc(sizeof(*rule));
pat->rules[i + 1] = NULL;
return(rule);
}
struct rule *rule;
struct stat sb;
- if(stat(path, &sb))
+ p = sprintf3("%s/.htrc", path);
+ if(stat(p, &sb))
return(NULL);
- if((s = fopen(sprintf3("%s/.htrc", path), "r")) == NULL)
+ if((s = fopen(p, "r")) == NULL)
return(NULL);
omalloc(cf);
cf->mtime = sb.st_mtime;
for(cf = cflist; cf != NULL; cf = cf->next) {
if(!strcmp(cf->path, path)) {
- if(stat(path, &sb))
+ if(stat(sprintf3("%s/.htrc", path), &sb))
return(NULL);
if(sb.st_mtime != cf->mtime) {
freeconfig(cf);
return;
}
if((ch = findchild(path, pat->childnm)) == NULL) {
- /* XXX: Send a 500 error. */
flog(LOG_ERR, "child %s requested, but was not declared", pat->childnm);
+ simpleerror(fd, 500, "Configuration Error", "The server is erroneously configured. Handler %s was requested, but not declared.", pat->childnm);
return;
}
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");
}
static int checkdir(struct hthead *req, int fd, char *path)
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 == '.')
+ if(*p == '.') {
+ simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
goto fail;
+ }
getconfig(path);
free(tmp);
break;
}
+ simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
goto fail;
}
break;
}
+ simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
goto fail;
next:
} else if(S_ISREG(sb.st_mode)) {
handlefile(req, fd, path);
} else {
+ simpleerror(fd, 404, "Not Found", "The requested URL has no corresponding resource.");
goto fail;
}
goto out;
fail:
- /* XXX: Send error report. */
+ /* No special handling, for now at least. */
out:
free(path);
}