From: phk Date: Fri, 31 Mar 2006 08:27:08 +0000 (+0000) Subject: Use http_headers.h to define session fields for headers and to parse X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b1dedb3dddb258f95f0f70c857fa62da823d8f3;p=varnish Use http_headers.h to define session fields for headers and to parse them out of the header. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@92 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 5a66371d..c40e0a46 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -64,7 +64,6 @@ http_read_f(int fd, short event, void *arg) continue; break; } - sp->hdr_e = p; event_del(sp->rd_e); DealWithSession(sp); } diff --git a/varnish-cache/bin/varnishd/cache_httpd.c b/varnish-cache/bin/varnishd/cache_httpd.c index 1ed4f7eb..4e68c90f 100644 --- a/varnish-cache/bin/varnishd/cache_httpd.c +++ b/varnish-cache/bin/varnishd/cache_httpd.c @@ -5,6 +5,8 @@ */ #include +#include +#include #include #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 @@ HttpdAnalyze(struct sess *sp) 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); + } + } diff --git a/varnish-cache/include/vcl_lang.h b/varnish-cache/include/vcl_lang.h index 182a2025..4af3e8df 100644 --- a/varnish-cache/include/vcl_lang.h +++ b/varnish-cache/include/vcl_lang.h @@ -5,8 +5,8 @@ * XXX: *MUST* be rerun. */ +/* XXX: This include is bad. The VCL compiler shouldn't know about it. */ #include -#include struct vcl_ref { unsigned line; @@ -35,13 +35,11 @@ struct sess { /* 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 +#undef HTTPH enum { HND_Unclass, diff --git a/varnish-cache/lib/libvcl/vcl_fixed_token.c b/varnish-cache/lib/libvcl/vcl_fixed_token.c index 80733ce4..c05f0efc 100644 --- a/varnish-cache/lib/libvcl/vcl_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcl_fixed_token.c @@ -386,8 +386,8 @@ vcl_output_lang_h(FILE *f) 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 \n", f); - fputs("#include \n", f); fputs("\n", f); fputs("struct vcl_ref {\n", f); fputs(" unsigned line;\n", f); @@ -416,13 +416,35 @@ vcl_output_lang_h(FILE *f) 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); diff --git a/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl index 4a06af59..c10cbad5 100755 --- a/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl @@ -180,6 +180,16 @@ puts $fo "void" puts $fo "vcl_output_lang_h(FILE *f)" puts $fo "{" while {[gets $fi a] >= 0} { + if {"$a" == "#include "} { + 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 "}"