Commit 0b3ab071 authored by Nils Goroll's avatar Nils Goroll

whitespace ocd

parent 492d8fb3
AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2013 UPLEX - Nils Goroll Systemoptimierung])
AC_COPYRIGHT([Copyright (c) 2014 UPLEX - Nils Goroll Systemoptimierung])
AC_INIT([libvmod-esicookies], [master])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(src/vmod_esicookies.vcc)
......@@ -37,7 +37,10 @@ AC_HEADER_STDC
AC_CHECK_HEADERS([sys/stdlib.h])
# Check for python
AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])])
AC_CHECK_PROGS(PYTHON,
[python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 \
python],
[AC_MSG_ERROR([Python is needed to build this vmod.])])
# Varnish source tree
AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)])
......@@ -53,11 +56,13 @@ AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
# Check that varnishtest is built in the varnish source directory
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
[],
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])]
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". \
Please run a build from your varnish source])]
)
# vmod installation dir
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
AC_ARG_VAR([VMODDIR], [vmod installation directory \
@<:@LIBDIR/varnish/vmods@:>@])
if test "x$VMODDIR" = x; then
VMODDIR=`pkg-config --variable=vmoddir varnishapi`
if test "x$VMODDIR" = x; then
......@@ -66,29 +71,48 @@ if test "x$VMODDIR" = x; then
fi
# This corresponds to FreeBSD's WARNS level 6
DEVELOPER_CFLAGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wformat"
DEVELOPER_CFLAGS="-Wall -Wstrict-prototypes \
-Wmissing-prototypes \
-Wpointer-arith \
-Wreturn-type \
-Wcast-qual \
-Wwrite-strings \
-Wswitch \
-Wshadow \
-Wcast-align \
-Wunused-parameter \
-Wchar-subscripts \
-Winline \
-Wnested-externs \
-Wredundant-decls -Wformat"
# Additional flags for GCC 4
EXTRA_DEVELOPER_CFLAGS="-Wextra -Wno-missing-field-initializers -Wno-sign-compare"
EXTRA_DEVELOPER_CFLAGS="-Wextra \
-Wno-missing-field-initializers \
-Wno-sign-compare"
# --enable-developer-warnings
AC_ARG_ENABLE(developer-warnings,
AS_HELP_STRING([--enable-developer-warnings],[enable strict warnings (default is NO)]),
AS_HELP_STRING([--enable-developer-warnings],
[enable strict warnings (default is NO)]),
CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}")
# --enable-debugging-symbols
AC_ARG_ENABLE(debugging-symbols,
AS_HELP_STRING([--enable-debugging-symbols],[enable debugging symbols (default is NO)]),
AS_HELP_STRING([--enable-debugging-symbols],
[enable debugging symbols (default is NO)]),
CFLAGS="${CFLAGS} -O0 -g -fno-inline")
# --enable-diagnostics
AC_ARG_ENABLE(diagnostics,
AS_HELP_STRING([--enable-diagnostics],[enable run-time diagnostics (default is NO)]),
AS_HELP_STRING([--enable-diagnostics],
[enable run-time diagnostics (default is NO)]),
CFLAGS="${CFLAGS} -DDIAGNOSTICS")
# --enable-extra-developer-warnings
AC_ARG_ENABLE(extra-developer-warnings,
AS_HELP_STRING([--enable-extra-developer-warnings],[enable even stricter warnings (default is NO)]),
AS_HELP_STRING([--enable-extra-developer-warnings],
[enable even stricter warnings (default is NO)]),
[],
[enable_extra_developer_warnings=no])
......@@ -104,7 +128,8 @@ fi
# --enable-stack-protector
AC_ARG_ENABLE(stack-protector,
AS_HELP_STRING([--enable-stack-protector],[enable stack protector (default is NO)]),
AS_HELP_STRING([--enable-stack-protector],
[enable stack protector (default is NO)]),
[],
[enable_stack_protector=no])
......
AM_CPPFLAGS = \
-I$(VARNISHSRC)/include \
-I$(VARNISHSRC)/bin/varnishd
......@@ -10,7 +9,8 @@ vmod_LTLIBRARIES = libvmod_esicookies.la
vmod_srcdir = $(top_srcdir)/src
vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
libvmod_esicookies_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared
libvmod_esicookies_la_LDFLAGS = $(AM_LDFLAGS) \
-module -export-dynamic -avoid-version -shared
libvmod_esicookies_la_SOURCES = \
vmod_esicookies.c
......@@ -19,7 +19,9 @@ nodist_libvmod_esicookies_la_SOURCES = \
vcc_if.c \
vcc_if.h
# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
# BUILT_SOURCES is only a hack and dependency tracking does not help
# for the first build
vmod_esicookies.lo: vcc_if.h
vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod_esicookies.vcc
......@@ -39,4 +41,3 @@ EXTRA_DIST = \
$(VMOD_TESTS)
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
varnishtest "test vmod_esicookies"
server s1 {
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
<esi:include src="/body2"/>
After include 2
<esi:include src="/body3"/>
After include 3
<esi:include src="/body4"/>
After include 4
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
<esi:include src="/body2"/>
After include 2
<esi:include src="/body3"/>
After include 3
<esi:include src="/body4"/>
After include 4
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
-hdr "Set-Cookie: fromserver1=2; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly" \
-body {
Included file
}
rxreq
expect req.url == "/body2"
expect req.http.Cookie == "fromclient=1; frombody1=1; fromserver1=2"
txresp -hdr "Set-Cookie: a=1" \
Included file
}
rxreq
expect req.url == "/body2"
expect req.http.Cookie == "fromclient=1; frombody1=1; fromserver1=2"
txresp -hdr "Set-Cookie: a=1" \
-hdr "Set-Cookie: b =2" \
-hdr "Set-Cookie: c= 3" \
-hdr "Set-Cookie: d=4 " \
-hdr "Set-Cookie: e=5 ; foobar" \
-hdr "Set-Cookie: d=4 " \
-hdr "Set-Cookie: e=5 ; foobar" \
-hdr "Set-Cookie: f= 3; foobar" \
-body {
Included file
}
rxreq
expect req.url == "/body3"
expect req.http.Cookie == "fromclient=1; frombody1=1; fromserver1=2; a=1; b=2; c=3; d=4; e=5; f=3"
txresp -body {
Included file
}
rxreq
expect req.url == "/body4"
txresp -body {
Included file
}
Included file
}
rxreq
expect req.url == "/body3"
expect req.http.Cookie == "fromclient=1; frombody1=1; fromserver1=2; a=1; b=2; c=3; d=4; e=5; f=3"
txresp -body {
Included file
}
rxreq
expect req.url == "/body4"
txresp -body {
Included file
}
} -start
varnish v1 -vcl+backend {
......@@ -71,6 +71,6 @@ varnish v1 -vcl+backend {
} -start
client c1 {
txreq -url "/" -hdr "Cookie: fromclient=1"
txreq -url "/" -hdr "Cookie: fromclient=1"
rxresp
} -run
This diff is collapsed.
varnishtest "test vmod_esicookies reload (mem free)"
server s1 {
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
-hdr "Set-Cookie: fromserver1=2; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly" \
-hdr "Connection: close" \
-body {
Included file
}
Included file
}
close
accept
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
-hdr "Set-Cookie: fromserver1=2; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly" \
-hdr "Connection: close" \
-body {
Included file
}
Included file
}
close
accept
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
rxreq
expect req.http.Cookie == "fromclient=1"
txresp -hdr "Set-Cookie: fromserver1=1" -body {
<html>
Before include
<esi:include src="/body1"/>
After include 1
}
rxreq
expect req.url == "/body1"
expect req.http.Cookie == "fromclient=1; fromserver1=1"
txresp -hdr "Set-Cookie: frombody1=1; Secure" \
-hdr "Set-Cookie: fromserver1=2; Domain=.foo.com; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly" \
-hdr "Connection: close" \
-body {
Included file
}
Included file
}
} -start
shell "(echo 'backend foo { .host = \"${s1_addr}\"; .port = \"${s1_port}\"; }'; echo 'import esicookies from \"${vmod_topbuild}/src/.libs/libvmod_esicookies.so\";' ; cat ${vmod_topbuild}/src/tests/vmod_esicookies_reload.vcl ) >${tmpdir}/_esicookies_reload.vcl"
......@@ -73,7 +73,7 @@ varnish v1 -expect n_vcl == 1
varnish v1 -expect n_backend == 1
client c1 {
txreq -url "/" -hdr "Cookie: fromclient=1"
txreq -url "/" -hdr "Cookie: fromclient=1"
rxresp
} -run
......@@ -84,7 +84,7 @@ varnish v1 -cliok "vcl.discard foo1"
varnish v1 -cli "debug.backend" -cli "vcl.list"
client c1 {
txreq -url "/" -hdr "Cookie: fromclient=1"
txreq -url "/" -hdr "Cookie: fromclient=1"
rxresp
} -run
......@@ -100,6 +100,6 @@ varnish v1 -expect n_backend == 1
varnish v1 -cliok "vcl.discard foo2"
client c1 {
txreq -url "/" -hdr "Cookie: fromclient=1"
txreq -url "/" -hdr "Cookie: fromclient=1"
rxresp
} -run
/*-
* Copyright (c) 2013 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013-2014 UPLEX Nils Goroll Systemoptimierung
* All rights reserved
*
* Author: Nils Goroll <nils.goroll@uplex.de>
......@@ -48,45 +48,45 @@
static struct http *
vrt_selecthttp(const struct sess *sp, enum gethdr_e where)
{
struct http *hp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
switch (where) {
case HDR_REQ:
hp = sp->http;
break;
case HDR_BEREQ:
hp = sp->wrk->bereq;
break;
case HDR_BERESP:
hp = sp->wrk->beresp;
break;
case HDR_RESP:
hp = sp->wrk->resp;
break;
case HDR_OBJ:
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
hp = sp->obj->http;
break;
default:
INCOMPL();
}
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
return (hp);
struct http *hp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
switch (where) {
case HDR_REQ:
hp = sp->http;
break;
case HDR_BEREQ:
hp = sp->wrk->bereq;
break;
case HDR_BERESP:
hp = sp->wrk->beresp;
break;
case HDR_RESP:
hp = sp->wrk->resp;
break;
case HDR_OBJ:
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
hp = sp->obj->http;
break;
default:
INCOMPL();
}
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
return (hp);
}
static int
http_IsHdr(const txt *hh, const char *hdr)
{
unsigned l;
Tcheck(*hh);
AN(hdr);
l = hdr[0];
assert(l == strlen(hdr + 1));
assert(hdr[l] == ':');
hdr++;
return (!strncasecmp(hdr, hh->b, l));
unsigned l;
Tcheck(*hh);
AN(hdr);
l = hdr[0];
assert(l == strlen(hdr + 1));
assert(hdr[l] == ':');
hdr++;
return (!strncasecmp(hdr, hh->b, l));
}
/* ----------------------------------------------------------------------
......@@ -124,7 +124,7 @@ http0_free(void *ptr) {
return;
CHECK_OBJ_NOTNULL(meta, VMOD_HTTP0_META_MAGIC);
if (meta->nmem) {
for (i = 0; i < meta->nmem; i++) {
m = &(meta->mem[i]);
......@@ -150,7 +150,7 @@ init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
struct rlimit nofile, rltest;
int i;
(void)cfg;
(void)cfg;
AZ(getrlimit(RLIMIT_NOFILE, &nofile));
......@@ -173,7 +173,7 @@ init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
priv->priv = meta;
priv->free = http0_free;
return (0);
return (0);
}
static void
......@@ -187,13 +187,15 @@ http0_mem_ws_alloc(struct http0_mem *m) {
AN(space);
WS_Init(&m->ws[0], "http0 ws[0]", space, HTTP0_WS_SIZE);
WS_Init(&m->ws[1], "http0 ws[1]", (space + HTTP0_WS_SIZE), HTTP0_WS_SIZE);
WS_Init(&m->ws[0], "http0 ws[0]", space,
HTTP0_WS_SIZE);
WS_Init(&m->ws[1], "http0 ws[1]", (space + HTTP0_WS_SIZE),
HTTP0_WS_SIZE);
}
static struct ws *
http0_get_mem(struct sess *sp, struct http0_meta *meta) {
struct ws *ws;
struct ws *ws;
struct http0_mem *m;
assert(sp->id < meta->nmem);
......@@ -204,7 +206,7 @@ http0_get_mem(struct sess *sp, struct http0_meta *meta) {
if (m->xid != sp->xid) {
m->xid = sp->xid;
}
ws = &m->ws[m->next_ws];
m->next_ws = m->next_ws ? 0 : 1;
WS_Reset(ws, NULL);
......@@ -226,7 +228,7 @@ struct cookie {
};
VSTAILQ_HEAD(cookiehead, cookie);
/*
/*
* http://webdesign.about.com/od/cookies/f/cookies-per-domain-limit.htm
* Chrome 9 allowed 180 cookies per domain
*/
......@@ -259,7 +261,7 @@ vesico_cookie_lookup(struct cookiehead *cookies, const txt name) {
static int
vesico_analyze_cookie_header(struct sess *sp, const txt hdr,
struct cookiehead *cookies, struct cookies *cs) {
struct cookiehead *cookies, struct cookies *cs) {
char *p = hdr.b;
char *pp;
......@@ -302,7 +304,7 @@ vesico_analyze_cookie_header(struct sess *sp, const txt hdr,
if (pp <= c->value.b)
goto cookie_invalid;
c->value.e = pp;
// skip forward to next cookie
p++;
while (isspace(*p))
......@@ -360,7 +362,8 @@ vesico_analyze_cookie_header(struct sess *sp, const txt hdr,
const char *H_COOKIE = "\007Cookie:";
static const char *
vesico_write_cookie_hdr(struct sess *sp, struct http0_meta *meta, struct http *h0, struct cookiehead *cookies)
vesico_write_cookie_hdr(struct sess *sp, struct http0_meta *meta,
struct http *h0, struct cookiehead *cookies)
{
unsigned u;
char *b = NULL, *e = NULL;
......@@ -378,11 +381,11 @@ vesico_write_cookie_hdr(struct sess *sp, struct http0_meta *meta, struct http *h
memcpy(b, H_COOKIE + 1, *H_COOKIE);
b += *H_COOKIE;
*b++ = ' ';
VSTAILQ_FOREACH(c, cookies, list) {
if (! c->valid)
continue;
// data we read must not be from the ws we write to
assert(! ((c->name.b >= ws->s) && (c->name.e <= ws->e)));
......@@ -413,23 +416,27 @@ vesico_write_cookie_hdr(struct sess *sp, struct http0_meta *meta, struct http *h
http_SetHeader(sp->wrk, sp->fd, h0, ws->f);
WS_ReleaseP(ws, b);
return "";
}
// XXX optimize for the case where existing cookie is tail of CS and we don't change existing cookies ?
/*
* XXX TODO optimize for the case where existing cookie is tail of CS and we
* don't change existing cookies ?
*/
static const char *
vesico_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, const char *hdr)
vesico_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where,
const char *hdr)
{
struct http0_meta *meta = priv->priv;
struct cookiehead cookies =
struct cookiehead cookies =
VSTAILQ_HEAD_INITIALIZER(cookies);
struct cookies cs;
cs.used = 0;
struct http *hp, *h0;
unsigned n;
int used;
......@@ -442,17 +449,18 @@ vesico_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, co
/* collect existing cookies */
for (n = HTTP_HDR_FIRST; n < h0->nhd; n++) {
if (http_IsHdr(&h0->hd[n], H_COOKIE)) {
if (http_IsHdr(&h0->hd[n], H_COOKIE)) {
int ret;
txt h;
Tcheck(h0->hd[n]);
Tcheck(h0->hd[n]);
h.b = h0->hd[n].b + *H_COOKIE;
while (isspace(*(h.b)))
h.b++;
h.e = h0->hd[n].e;
ret = vesico_analyze_cookie_header(sp, h, &cookies, &cs);
ret = vesico_analyze_cookie_header(sp, h, &cookies,
&cs);
if (ret) {
return strerror(ret);
}
......@@ -464,12 +472,12 @@ vesico_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, co
/* collect cookies from the set-cookie hdr given */
hp = vrt_selecthttp(sp, where);
for (n = HTTP_HDR_FIRST; n < hp->nhd; n++) {
if (http_IsHdr(&hp->hd[n], hdr)) {
if (http_IsHdr(&hp->hd[n], hdr)) {
int ret;
txt h;
char *p;
Tcheck(hp->hd[n]);
Tcheck(hp->hd[n]);
h.b = hp->hd[n].b + *hdr;
while (isspace(*(h.b)))
h.b++;
......@@ -480,7 +488,8 @@ vesico_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, co
else
h.e = hp->hd[n].e;
ret = vesico_analyze_cookie_header(sp, h, &cookies, &cs);
ret = vesico_analyze_cookie_header(sp, h, &cookies,
&cs);
if (ret) {
return strerror(ret);
}
......@@ -492,14 +501,16 @@ vesico_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, co
return "";
return (vesico_write_cookie_hdr(sp, meta, h0, &cookies));
}
}
const char * __match_proto__()
vmod_to_http0_e(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, const char *hdr) {
vmod_to_http0_e(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where,
const char *hdr) {
return (vesico_to_http0(sp, priv, where, hdr));
}
void __match_proto__()
vmod_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where, const char *hdr) {
vmod_to_http0(struct sess *sp, struct vmod_priv *priv, enum gethdr_e where,
const char *hdr) {
return (void)(vesico_to_http0(sp, priv, where, hdr));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment