X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/blobdiff_plain/25b3befe92ab6c1580d69c448f46ee0ad0bb1337..812e4bf21dbd3754acf9cec3ea8065054f684c8e:/httpd.c diff --git a/httpd.c b/httpd.c index 83961e1..486ca21 100644 --- a/httpd.c +++ b/httpd.c @@ -22,13 +22,22 @@ #include "malloc.h" #include "html.h" +#include "httpd.h" /* --- Logic driving what the web server's responses are. --- */ +enum { /* connctx states */ + READING_REQ_LINE, + READING_HEADERS, + DONE +}; + struct connctx { const void *t; char *data; int datalen, datasize; + char *method, *url, *headers, *auth; + int state; }; /* @@ -41,6 +50,8 @@ struct connctx *new_connection(const void *t) cctx->t = t; cctx->data = NULL; cctx->datalen = cctx->datasize = 0; + cctx->state = READING_REQ_LINE; + cctx->method = cctx->url = cctx->headers = cctx->auth = NULL; return cctx; } @@ -50,12 +61,14 @@ void free_connection(struct connctx *cctx) sfree(cctx); } -static char *http_error(char *code, char *errmsg, char *errtext, ...) +static char *http_error(char *code, char *errmsg, char *extraheader, + char *errtext, ...) { return dupfmt("HTTP/1.1 %s %s\r\n" "Date: %D\r\n" "Server: agedu\r\n" "Connection: close\r\n" + "%s" "Content-Type: text/html; charset=US-ASCII\r\n" "\r\n" "\r\n" @@ -65,6 +78,7 @@ static char *http_error(char *code, char *errmsg, char *errtext, ...) "
%s
\r\n" "