Mailing List Archive

r68 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2006-03-24 11:23:43 +0100 (Fri, 24 Mar 2006)
New Revision: 68

Added:
trunk/varnish-cache/bin/varnishd/cache_httpd.c
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
Log:
Change session memory management to avoid <event.h> pollution

Add fledling httpd parsing



Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2006-03-24 10:22:47 UTC (rev 67)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2006-03-24 10:23:43 UTC (rev 68)
@@ -6,6 +6,7 @@

varnishd_SOURCES = \
cache_acceptor.c \
+ cache_httpd.c \
cache_main.c \
cache_shmlog.c \
cli_event.c \

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-03-24 10:22:47 UTC (rev 67)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-03-24 10:23:43 UTC (rev 68)
@@ -25,6 +25,11 @@

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 @@
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 @@
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 @@
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 *

Added: trunk/varnish-cache/bin/varnishd/cache_httpd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_httpd.c 2006-03-24 10:22:47 UTC (rev 67)
+++ trunk/varnish-cache/bin/varnishd/cache_httpd.c 2006-03-24 10:23:43 UTC (rev 68)
@@ -0,0 +1,40 @@
+/*
+ * $Id$
+ *
+ * Stuff relating to HTTP server side
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+
+#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);
+}