sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
assert(sb != NULL);
- sbuf_cat(sb, sp->req);
+ sbuf_cat(sb, sp->http.req);
sbuf_cat(sb, " ");
- sbuf_cat(sb, sp->url);
+ sbuf_cat(sb, sp->http.url);
sbuf_cat(sb, " ");
- sbuf_cat(sb, sp->proto);
+ sbuf_cat(sb, sp->http.proto);
sbuf_cat(sb, "\r\n");
#define HTTPH(a, b, c, d, e, f, g) \
do { \
- if (c && sp->b != NULL) { \
+ if (c && sp->http.b != NULL) { \
sbuf_cat(sb, a ": "); \
- sbuf_cat(sb, sp->b); \
+ sbuf_cat(sb, sp->http.b); \
sbuf_cat(sb, "\r\n"); \
} \
} while (0);
sp->handling = HND_Unclass;
/* First, isolate and possibly identify request type */
- sp->req = sp->rcv;
+ sp->http.req = sp->rcv;
for (p = sp->rcv; isalpha(*p); p++)
;
- VSLR(SLT_Request, sp->fd, sp->req, p);
+ VSLR(SLT_Request, sp->fd, sp->http.req, p);
*p++ = '\0';
/* Next find the URI */
while (isspace(*p))
p++;
- sp->url = p;
+ sp->http.url = p;
while (!isspace(*p))
p++;
- VSLR(SLT_URL, sp->fd, sp->url, p);
+ VSLR(SLT_URL, sp->fd, sp->http.url, p);
*p++ = '\0';
/* Finally, look for protocol, if any */
while (isspace(*p) && *p != '\n')
p++;
- sp->proto = p;
+ sp->http.proto = p;
if (*p != '\n') {
while (!isspace(*p))
p++;
}
- VSLR(SLT_Protocol, sp->fd, sp->proto, p);
+ VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
*p++ = '\0';
while (isspace(*p) && *p != '\n')
if (*p == '\r')
p++;
-#define HTTPH(a, b, c, d, e, f, g) sp->b = NULL;
-#include "http_headers.h"
-#undef HTTPH
+ memset(&sp->http, 0, sizeof sp->http);
for (; p < sp->rcv + sp->rcv_len; p = r) {
q = strchr(p, '\n');
if (!strncasecmp(p, a, strlen(a))) { \
for (p += strlen(a); p < q && isspace(*p); p++) \
continue; \
- sp->b = p; \
+ sp->http.b = p; \
VSLR(SLT_##b, sp->fd, p, q); \
continue; \
}
#include "http_headers.h"
#undef HTTPH
#undef W
- VSLR(SLT_H_Unknown, sp->fd, p, q);
+ if (sp->http.nuhdr < VCA_UNKNOWNHDR) {
+ sp->http.uhdr[sp->http.nuhdr++] = p;
+ VSLR(SLT_HD_Unknown, sp->fd, p, q);
+ } else {
+ VSLR(SLT_HD_Lost, sp->fd, p, q);
+ }
}
-
}
sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
assert(sb != NULL);
- sbuf_cat(sb, sp->req);
+ sbuf_cat(sb, sp->http.req);
sbuf_cat(sb, " ");
- sbuf_cat(sb, sp->url);
- if (sp->proto != NULL) {
+ sbuf_cat(sb, sp->http.url);
+ if (sp->http.proto != NULL) {
sbuf_cat(sb, " ");
- sbuf_cat(sb, sp->proto);
+ sbuf_cat(sb, sp->http.proto);
}
sbuf_cat(sb, "\r\n");
#define HTTPH(a, b, c, d, e, f, g) \
do { \
- if (sp->b != NULL) { \
+ if (sp->http.b != NULL) { \
sbuf_cat(sb, a ": "); \
- sbuf_cat(sb, sp->b); \
+ sbuf_cat(sb, sp->http.b); \
sbuf_cat(sb, "\r\n"); \
} \
} while (0);
SLTM(Request)
SLTM(URL)
SLTM(Protocol)
-SLTM(H_Unknown)
+SLTM(HD_Unknown)
+SLTM(HD_Lost)
#define HTTPH(a, b, c, d, e, f, g) SLTM(b)
#include "http_headers.h"
#undef HTTPH
#define VCA_RXBUFSIZE 1024
#define VCA_ADDRBUFSIZE 32
+#define VCA_UNKNOWNHDR 10
+
+struct httphdr {
+ const char *req;
+ const char *url;
+ const char *proto;
+#define HTTPH(a, b, c, d, e, f, g) const char *b;
+#include <http_headers.h>
+#undef HTTPH
+ const char *uhdr[VCA_UNKNOWNHDR];
+ unsigned nuhdr;
+};
struct sess {
int fd;
unsigned rcv_len;
/* HTTP request info, points into rcv */
- const char *req;
- const char *url;
- const char *proto;
-#define HTTPH(a, b, c, d, e, f, g) const char *b;
-#include <http_headers.h>
-#undef HTTPH
+ struct httphdr http;
enum {
HND_Unclass,
fputs("\n", f);
fputs("#define VCA_RXBUFSIZE 1024\n", f);
fputs("#define VCA_ADDRBUFSIZE 32\n", f);
+ fputs("#define VCA_UNKNOWNHDR 10\n", f);
fputs("\n", f);
- fputs("struct sess {\n", f);
- fputs(" int fd;\n", f);
- fputs("\n", f);
- fputs(" /* formatted ascii client address */\n", f);
- fputs(" char addr[VCA_ADDRBUFSIZE];\n", f);
- fputs("\n", f);
- fputs(" /* Receive buffer for HTTP header */\n", f);
- fputs(" char rcv[VCA_RXBUFSIZE + 1];\n", f);
- fputs(" unsigned rcv_len;\n", f);
- fputs("\n", f);
- fputs(" /* HTTP request info, points into rcv */\n", f);
+ fputs("struct httphdr {\n", f);
fputs(" const char *req;\n", f);
fputs(" const char *url;\n", f);
fputs(" const char *proto;\n", f);
fputs("HTTPH(\"TE\", H_TE, 0, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"User-Agent\", H_User_Agent, 1, 0, 0, 0, 0)\n", f);
fputs("#undef HTTPH\n", f);
+ fputs(" const char *uhdr[VCA_UNKNOWNHDR];\n", f);
+ fputs(" unsigned nuhdr;\n", f);
+ fputs("};\n", f);
+ fputs("\n", f);
+ fputs("struct sess {\n", f);
+ fputs(" int fd;\n", f);
+ fputs("\n", f);
+ fputs(" /* formatted ascii client address */\n", f);
+ fputs(" char addr[VCA_ADDRBUFSIZE];\n", f);
+ fputs("\n", f);
+ fputs(" /* Receive buffer for HTTP header */\n", f);
+ fputs(" char rcv[VCA_RXBUFSIZE + 1];\n", f);
+ fputs(" unsigned rcv_len;\n", f);
+ fputs("\n", f);
+ fputs(" /* HTTP request info, points into rcv */\n", f);
+ fputs(" struct httphdr http;\n", f);
fputs("\n", f);
fputs(" enum {\n", f);
fputs(" HND_Unclass,\n", f);