Mailing List Archive

r92 - in trunk/varnish-cache: bin/varnishd include lib/libvcl
Author: phk
Date: 2006-03-31 10:27:08 +0200 (Fri, 31 Mar 2006)
New Revision: 92

Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_httpd.c
trunk/varnish-cache/include/vcl_lang.h
trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl
Log:
Use http_headers.h to define session fields for headers and to parse
them out of the header.


Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-03-31 08:26:23 UTC (rev 91)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-03-31 08:27:08 UTC (rev 92)
@@ -64,7 +64,6 @@
continue;
break;
}
- sp->hdr_e = p;
event_del(sp->rd_e);
DealWithSession(sp);
}

Modified: trunk/varnish-cache/bin/varnishd/cache_httpd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpd.c 2006-03-31 08:26:23 UTC (rev 91)
+++ trunk/varnish-cache/bin/varnishd/cache_httpd.c 2006-03-31 08:27:08 UTC (rev 92)
@@ -5,6 +5,8 @@
*/

#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
#include <ctype.h>

#include "libvarnish.h"
@@ -15,16 +17,16 @@
void
HttpdAnalyze(struct sess *sp)
{
- const char *p, *q;
+ char *p, *q, *r;

sp->handling = HND_Unclass;

/* First, isolate and possibly identify request type */
- p = sp->req_b = sp->rcv;
- for (q = p; isalpha(*q); q++)
+ sp->req_b = sp->rcv;
+ for (p = sp->rcv; isalpha(*p); p++)
;
- p = sp->req_e = q;
- VSLR(SLT_Request, sp->fd, sp->req_b, sp->req_e);
+ VSLR(SLT_Request, sp->fd, sp->req_b, p);
+ *p++ = '\0';

/* Next find the URI */
while (isspace(*p))
@@ -32,29 +34,54 @@
sp->url_b = p;
while (!isspace(*p))
p++;
- sp->url_e = p;
- VSLR(SLT_URL, sp->fd, sp->url_b, sp->url_e);
+ VSLR(SLT_URL, sp->fd, sp->url_b, p);
+ *p++ = '\0';

/* Finally, look for protocol, if any */
while (isspace(*p) && *p != '\n')
p++;
- sp->proto_b = sp->proto_e = p;
+ sp->proto_b = p;
if (*p != '\n') {
while (!isspace(*p))
p++;
- sp->proto_e = p;
}
- VSLR(SLT_Protocol, sp->fd, sp->proto_b, sp->proto_e);
+ VSLR(SLT_Protocol, sp->fd, sp->proto_b, p);
+ *p++ = '\0';

- /*
- * And mark the start of headers. The end of headers
- * is already set in acceptor where we detected the complete request.
- */
- while (*p != '\n')
+ while (isspace(*p) && *p != '\n')
p++;
+
p++;
- while (isspace(*p) && *p != '\n')
+ if (*p == '\r')
p++;
- sp->hdr_b = p;
- VSLR(SLT_Headers, sp->fd, sp->hdr_b, sp->hdr_e);
+
+#define HTTPH(a, b) sp->b = NULL;
+#include "http_headers.h"
+#undef HTTPH
+
+ for (; p < sp->rcv + sp->rcv_len; p = r) {
+ q = strchr(p, '\n');
+ r = q + 1;
+ if (q > p && q[-1] == '\r')
+ q--;
+ *q = '\0';
+ if (p == q)
+ break;
+
+#define W(a, b, p, q, sp) \
+ if (!strncasecmp(p, a, strlen(a))) { \
+ for (p += strlen(a); p < q && isspace(*p); p++) \
+ continue; \
+ sp->b = p; \
+ VSLR(SLT_##b, sp->fd, p, q); \
+ continue; \
+ }
+
+#define HTTPH(a, b) W(a ":", b, p, q, sp)
+#include "http_headers.h"
+#undef HTTPH
+#undef W
+ VSLR(SLT_H_Unknown, sp->fd, p, q);
+ }
+
}

Modified: trunk/varnish-cache/include/vcl_lang.h
===================================================================
--- trunk/varnish-cache/include/vcl_lang.h 2006-03-31 08:26:23 UTC (rev 91)
+++ trunk/varnish-cache/include/vcl_lang.h 2006-03-31 08:27:08 UTC (rev 92)
@@ -5,8 +5,8 @@
* XXX: *MUST* be rerun.
*/

+/* XXX: This include is bad. The VCL compiler shouldn't know about it. */
#include <sys/queue.h>
-#include <pthread.h>

struct vcl_ref {
unsigned line;
@@ -35,13 +35,11 @@

/* HTTP request info, points into rcv */
const char *req_b;
- const char *req_e;
const char *url_b;
- const char *url_e;
const char *proto_b;
- const char *proto_e;
- const char *hdr_b;
- const char *hdr_e;
+#define HTTPH(a, b) const char *b;
+#include <http_headers.h>
+#undef HTTPH

enum {
HND_Unclass,

Modified: trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c 2006-03-31 08:26:23 UTC (rev 91)
+++ trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c 2006-03-31 08:27:08 UTC (rev 92)
@@ -386,8 +386,8 @@
fputs(" * XXX: *MUST* be rerun.\n", f);
fputs(" */\n", f);
fputs("\n", f);
+ fputs("/* XXX: This include is bad. The VCL compiler shouldn't know about it. */\n", f);
fputs("#include <sys/queue.h>\n", f);
- fputs("#include <pthread.h>\n", f);
fputs("\n", f);
fputs("struct vcl_ref {\n", f);
fputs(" unsigned line;\n", f);
@@ -416,14 +416,36 @@
fputs("\n", f);
fputs(" /* HTTP request info, points into rcv */\n", f);
fputs(" const char *req_b;\n", f);
- fputs(" const char *req_e;\n", f);
fputs(" const char *url_b;\n", f);
- fputs(" const char *url_e;\n", f);
fputs(" const char *proto_b;\n", f);
- fputs(" const char *proto_e;\n", f);
- fputs(" const char *hdr_b;\n", f);
- fputs(" const char *hdr_e;\n", f);
+ fputs("#define HTTPH(a, b) const char *b;\n", f);
+ fputs("/*\n", f);
+ fputs(" * $Id$\n", f);
+ fputs(" */\n", f);
fputs("\n", f);
+ fputs("HTTPH(\"Accept-Charset\", H_Accept_Charset)\n", f);
+ fputs("HTTPH(\"Accept-Encoding\", H_Accept_Encoding)\n", f);
+ fputs("HTTPH(\"Accept-Language\", H_Accept_Language)\n", f);
+ fputs("HTTPH(\"Accept\", H_Accept)\n", f);
+ fputs("HTTPH(\"Authorization\", H_Authorization)\n", f);
+ fputs("HTTPH(\"Connection\", H_Connection)\n", f);
+ fputs("HTTPH(\"Expect\", H_Expect)\n", f);
+ fputs("HTTPH(\"From\", H_From)\n", f);
+ fputs("HTTPH(\"Host\", H_Host)\n", f);
+ fputs("HTTPH(\"If-Match\", H_If_Match)\n", f);
+ fputs("HTTPH(\"If-Modified-Since\", H_If_Modified_Since)\n", f);
+ fputs("HTTPH(\"If-None-Match\", H_If_None_Match)\n", f);
+ fputs("HTTPH(\"If-Range\", H_If_Range)\n", f);
+ fputs("HTTPH(\"If-Unmodified-Since\", H_If_Unmodifed_Since)\n", f);
+ fputs("HTTPH(\"Keep-Alive\", H_Keep_Alive)\n", f);
+ fputs("HTTPH(\"Max-Forwards\", H_Max_Forwards)\n", f);
+ fputs("HTTPH(\"Proxy-Authorization\", H_Proxy_Authorization)\n", f);
+ fputs("HTTPH(\"Range\", H_Range)\n", f);
+ fputs("HTTPH(\"Referer\", H_Referer)\n", f);
+ fputs("HTTPH(\"TE\", H_TE)\n", f);
+ fputs("HTTPH(\"User-Agent\", H_User_Agent)\n", f);
+ fputs("#undef HTTPH\n", f);
+ fputs("\n", f);
fputs(" enum {\n", f);
fputs(" HND_Unclass,\n", f);
fputs(" HND_Handle,\n", f);

Modified: trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl 2006-03-31 08:26:23 UTC (rev 91)
+++ trunk/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl 2006-03-31 08:27:08 UTC (rev 92)
@@ -180,6 +180,16 @@
puts $fo "vcl_output_lang_h(FILE *f)"
puts $fo "{"
while {[gets $fi a] >= 0} {
+ if {"$a" == "#include <http_headers.h>"} {
+ puts "FOO $a"
+ set fx [open "../../include/http_headers.h"]
+ while {[gets $fx b] >= 0} {
+ regsub -all {"} $b {\"} b
+ puts $fo "\tfputs(\"$b\\n\", f);"
+ }
+ close $fx
+ continue
+ }
puts $fo "\tfputs(\"$a\\n\", f);"
}
puts $fo "}"