From 9825882486b18abf73aaa55ed9ebca4b3c781ccb Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 24 Mar 2006 10:23:43 +0000 Subject: [PATCH] Change session memory management to avoid pollution Add fledling httpd parsing git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@68 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/Makefile.am | 1 + varnish-cache/bin/varnishd/cache_acceptor.c | 27 +++++++++----- varnish-cache/bin/varnishd/cache_httpd.c | 40 +++++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 varnish-cache/bin/varnishd/cache_httpd.c diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index 4d3fcf14..ef009320 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -6,6 +6,7 @@ bin_PROGRAMS = varnishd varnishd_SOURCES = \ cache_acceptor.c \ + cache_httpd.c \ cache_main.c \ cache_shmlog.c \ cli_event.c \ diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index beb01416..11f4ae2c 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -25,6 +25,11 @@ static struct event_base *evb; static struct event accept_e[2 * HERITAGE_NSOCKS]; +struct sessmem { + struct sess s; + struct event e; +}; + static void http_read_f(int fd, short event, void *arg) { @@ -37,9 +42,9 @@ http_read_f(int fd, short event, void *arg) i = read(fd, sp->rcv + sp->rcv_len, VCA_RXBUFSIZE - sp->rcv_len); if (i <= 0) { VSL(SLT_SessionClose, sp->fd, "remote %d", sp->rcv_len); - event_del(&sp->rd_e); + event_del(sp->rd_e); close(sp->fd); - free(sp); + free(sp->mem); return; } @@ -59,24 +64,30 @@ http_read_f(int fd, short event, void *arg) continue; break; } + event_del(sp->rd_e); + HttpdAnalyze(sp); printf("full <%s>\n", sp->rcv); - event_del(&sp->rd_e); } static void accept_f(int fd, short event, void *arg __unused) { socklen_t l; + struct sessmem *sm; struct sockaddr addr; struct sess *sp; char port[10]; - sp = calloc(sizeof *sp, 1); - assert(sp != NULL); /* + sm = calloc(sizeof *sm, 1); + assert(sm != NULL); /* * XXX: this is probably one we should handle * XXX: accept, emit error NNN and close */ + sp = &sm->s; + sp->rd_e = &sm->e; + sp->mem = sm; + l = sizeof addr; sp->fd = accept(fd, &addr, &l); if (sp->fd < 0) { @@ -89,10 +100,10 @@ accept_f(int fd, short event, void *arg __unused) strlcat(sp->addr, ":", VCA_ADDRBUFSIZE); strlcat(sp->addr, port, VCA_ADDRBUFSIZE); VSL(SLT_SessionOpen, sp->fd, "%s", sp->addr); - event_set(&sp->rd_e, sp->fd, EV_READ | EV_PERSIST, + event_set(sp->rd_e, sp->fd, EV_READ | EV_PERSIST, http_read_f, sp); - event_base_set(evb, &sp->rd_e); - event_add(&sp->rd_e, NULL); /* XXX: timeout */ + event_base_set(evb, sp->rd_e); + event_add(sp->rd_e, NULL); /* XXX: timeout */ } void * diff --git a/varnish-cache/bin/varnishd/cache_httpd.c b/varnish-cache/bin/varnishd/cache_httpd.c new file mode 100644 index 00000000..744c306f --- /dev/null +++ b/varnish-cache/bin/varnishd/cache_httpd.c @@ -0,0 +1,40 @@ +/* + * $Id$ + * + * Stuff relating to HTTP server side + */ + +#include +#include + +#include "libvarnish.h" +#include "shmlog.h" +#include "cache.h" + +void +HttpdAnalyze(struct sess *sp) +{ + const char *p, *q, *u; + + p = sp->rcv; + + if (p[0] == 'G' && p[1] == 'E' && p[2] == 'T' && p[3] == ' ') { + p += 4; + VSL(SLT_Request, sp->fd, "GET"); + } else if (p[0] == 'H' && p[1] == 'E' && p[2] == 'A' && p[3] == 'D' + && p[4] == ' ') { + p += 5; + VSL(SLT_Request, sp->fd, "HEAD"); + } else { + for (q = p; isupper(*q); q++) + ; + VSLR(SLT_Request, sp->fd, p, q); + p = q; + } + while (isspace(*p)) + p++; + u = p; + while (!isspace(*p)) + p++; + VSLR(SLT_URL, sp->fd, u, p); +} -- 2.39.5