r5753 - in trunk/varnish-cache/bin: varnishd varnishtest/tests
phk at varnish-cache.org
phk at varnish-cache.org
Fri Jan 14 20:45:50 CET 2011
Author: phk
Date: 2011-01-14 20:45:48 +0100 (Fri, 14 Jan 2011)
New Revision: 5753
Modified:
trunk/varnish-cache/bin/varnishd/cache_esi_parse.c
trunk/varnish-cache/bin/varnishd/mgt_param.c
trunk/varnish-cache/bin/varnishtest/tests/e00019.vtc
Log:
Fix bugs relating to the space that may or may not be between received
chunks and multiple storage segments.
Along the way add a couple more debug options.
Modified: trunk/varnish-cache/bin/varnishd/cache_esi_parse.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi_parse.c 2011-01-14 19:38:13 UTC (rev 5752)
+++ trunk/varnish-cache/bin/varnishd/cache_esi_parse.c 2011-01-14 19:45:48 UTC (rev 5753)
@@ -73,8 +73,10 @@
unsigned remove;
- unsigned o_verbatim;
- unsigned o_skip;
+ ssize_t o_verbatim;
+ ssize_t o_skip;
+ ssize_t o_pending;
+ ssize_t o_total;
const char *hack_p;
const char *ver_p;
@@ -250,26 +252,30 @@
}
static void
-vep_emit_skip(struct vep_state *vep)
+vep_emit_skip(struct vep_state *vep, ssize_t *l)
{
- ssize_t l;
- l = vep->o_skip;
- vep->o_skip = 0;
- assert(l > 0);
- vep_emit_len(vep, l, VEC_S1, VEC_S2, VEC_S8);
+ assert(*l > 0);
+ if (params->esi_syntax & 0x20) {
+ Debug("---> SKIP(%jd)\n", (intmax_t)*l);
+ }
+ vep_emit_len(vep, *l, VEC_S1, VEC_S2, VEC_S8);
+ vep->o_total += *l;
+ *l = 0;
}
static void
-vep_emit_verbatim(struct vep_state *vep)
+vep_emit_verbatim(struct vep_state *vep, ssize_t *l)
{
- ssize_t l;
- l = vep->o_verbatim;
- vep->o_verbatim = 0;
- assert(l > 0);
- vep_emit_len(vep, l, VEC_V1, VEC_V2, VEC_V8);
- vsb_printf(vep->vsb, "%lx\r\n%c", l, 0);
+ assert(*l > 0);
+ if (params->esi_syntax & 0x20) {
+ Debug("---> VERBATIM(%jd)\n", (intmax_t)*l);
+ }
+ vep_emit_len(vep, *l, VEC_V1, VEC_V2, VEC_V8);
+ vsb_printf(vep->vsb, "%lx\r\n%c", *l, 0);
+ vep->o_total += *l;
+ *l = 0;
}
static void
@@ -279,14 +285,20 @@
AN(vep->ver_p);
l = p - vep->ver_p;
- if (l == 0)
- return;
- if (vep->o_skip > 0)
- vep_emit_skip(vep);
- AZ(vep->o_skip);
- Debug("-->V(%d) [%.*s]\n", (int)l, (int)l, vep->ver_p);
- vep->o_verbatim += l;
vep->ver_p = p;
+ assert(l >= 0);
+ if (params->esi_syntax & 0x10) {
+ if (vep->o_pending)
+ vep_emit_verbatim(vep, &vep->o_pending);
+ if (l)
+ vep_emit_verbatim(vep, &l);
+ } else {
+ if (vep->o_skip > 0)
+ vep_emit_skip(vep, &vep->o_skip);
+ vep->o_verbatim += vep->o_pending;
+ vep->o_pending = 0;
+ vep->o_verbatim += l;
+ }
}
static void
@@ -296,14 +308,20 @@
AN(vep->ver_p);
l = p - vep->ver_p;
- if (l == 0)
- return;
- if (vep->o_verbatim > 0)
- vep_emit_verbatim(vep);
- AZ(vep->o_verbatim);
- Debug("-->S(%d) [%.*s]\n", (int)l, (int)l, vep->ver_p);
- vep->o_skip += l;
vep->ver_p = p;
+ assert(l >= 0);
+ if (params->esi_syntax & 0x10) {
+ if (vep->o_pending)
+ vep_emit_skip(vep, &vep->o_pending);
+ if (l)
+ vep_emit_skip(vep, &l);
+ } else {
+ if (vep->o_verbatim > 0)
+ vep_emit_verbatim(vep, &vep->o_verbatim);
+ vep->o_skip += vep->o_pending;
+ vep->o_pending = 0;
+ vep->o_skip += l;
+ }
}
/*---------------------------------------------------------------------
@@ -371,9 +389,9 @@
}
XXXAN(vep->include_src);
if (vep->o_skip > 0)
- vep_emit_skip(vep);
+ vep_emit_skip(vep, &vep->o_skip);
if (vep->o_verbatim > 0)
- vep_emit_verbatim(vep);
+ vep_emit_verbatim(vep, &vep->o_verbatim);
/* XXX: what if it contains NUL bytes ?? */
p = vsb_data(vep->include_src);
l = vsb_len(vep->include_src);
@@ -461,6 +479,7 @@
vep->remove,
vep->tag_i, vep->tag,
i, p);
+ assert(p >= vep->ver_p);
/******************************************************
* SECTION A
@@ -506,7 +525,7 @@
p++;
vep->state = VEP_NEXTTAG;
if (!vep->remove)
- vep_mark_verbatim(vep, p + 1);
+ vep_mark_verbatim(vep, p);
} else {
vep->tag_i = 0;
while (p < e) {
@@ -516,7 +535,7 @@
}
}
if (p < e && !vep->remove)
- vep_mark_verbatim(vep, p + 1);
+ vep_mark_verbatim(vep, p);
}
} else if (vep->state == VEP_NEXTTAG) {
/*
@@ -526,6 +545,7 @@
vep->emptytag = 0;
vep->endtag = 0;
vep->attr = NULL;
+ vep->dostuff = NULL;
while (p < e && *p != '<') {
if (vep->esicmt_p != NULL &&
*p == *vep->esicmt_p++) {
@@ -538,13 +558,12 @@
* should not be emitted.
* But the stuff before should
*/
- if (!vep->remove)
- vep_mark_verbatim(vep,
- p - 3);
vep_mark_skip(vep, p);
}
} else {
p++;
+ if (!vep->remove)
+ vep_mark_verbatim(vep, p);
vep->esicmt_p = vep->esicmt;
}
}
@@ -808,7 +827,8 @@
if (*p == '>') {
for (vm = vep->match;
vm->match != NULL; vm++)
- break;
+ continue;
+ AZ(vm->match);
} else {
vep->tag[vep->tag_i++] = *p++;
vm = vep_match(vep,
@@ -843,7 +863,8 @@
INCOMPL();
}
}
- /* XXX: should we return p ? */
+ vep->o_pending += p - vep->ver_p;
+ vep->ver_p = p;
}
/*---------------------------------------------------------------------
@@ -938,7 +959,7 @@
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
vep = sp->wrk->vep;
- Debug("BYTES %p\n", vep);
+ Debug("BYTES %jd\n", (intmax_t)bytes);
CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
AN(vep->bytes);
return (vep->bytes(sp, htc, bytes));
@@ -949,7 +970,7 @@
{
struct storage *st;
struct vep_state *vep;
- size_t l;
+ ssize_t l;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
vep = sp->wrk->vep;
@@ -957,17 +978,21 @@
Debug("ENDING %p\n", vep);
CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
- st = sp->wrk->storage;
- if (st != NULL)
- l = (const char *)(st->ptr + st->len) - (const char*)vep->ver_p;
- else
- l = 0;
- Debug("ENDING STATE: %s (%ld)\n", vep->state, l);
+ l = sp->obj->len - vep->o_total;
+ Debug("ENDING STATE: %s (skip %jd) (verbatim %jd)"
+ " (tot %jd) (len %jd) (diff %jd)\n",
+ vep->state,
+ (intmax_t)vep->o_skip, (intmax_t)vep->o_verbatim,
+ (intmax_t)vep->o_total, (intmax_t)sp->obj->len, (intmax_t)l);
+ assert(l >= 0);
if (vep->o_skip)
- vep_emit_skip(vep);
+ vep_emit_skip(vep, &vep->o_skip);
+ if (vep->o_verbatim)
+ vep_emit_verbatim(vep, &vep->o_verbatim);
+ l = sp->obj->len - vep->o_total;
+ if (l)
+ vep_emit_verbatim(vep, &l);
vep->o_verbatim += l;
- if (vep->o_verbatim)
- vep_emit_verbatim(vep);
vsb_finish(vep->vsb);
l = vsb_len(vep->vsb);
if (vep->state != VEP_NOTXML && l > 0) {
Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2011-01-14 19:38:13 UTC (rev 5752)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2011-01-14 19:45:48 UTC (rev 5753)
@@ -643,7 +643,8 @@
" 0x00000001 - Don't check if it looks like XML\n"
" 0x00000002 - Ignore non-esi elements\n"
" 0x00000004 - Emit parsing debug records\n"
- " 0x00000008 - Force-dplit parser input (debugging)\n"
+ " 0x00000008 - Force-split parser input (debugging)\n"
+ " 0x00000010 - Don't coalesce VEC string (debugging)\n"
"Use 0x notation and do the bitor in your head :-)\n",
0,
"0", "bitmap" },
Modified: trunk/varnish-cache/bin/varnishtest/tests/e00019.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/e00019.vtc 2011-01-14 19:38:13 UTC (rev 5752)
+++ trunk/varnish-cache/bin/varnishtest/tests/e00019.vtc 2011-01-14 19:45:48 UTC (rev 5753)
@@ -4,20 +4,37 @@
server s1 {
rxreq
- txresp -body {
- </esi:comment foo>
- <esi:comment / >
- <esi:remove foo="bar"></esi:remove>
- <esi:include src="foo">
- }
+ txresp -nolen -hdr "Transfer-encoding: chunked"
+ chunked {<1></esi:comment foo><1>}
+ chunked {<2><esi:comment / ><esi:comment doo><2>}
+ chunked {<3><esi:remove foo="bar"></esi:remove><3>}
+ chunked {<4><esi:include src="foo"><esi:incl><4>}
+ chunked {<H1><esi:remove>}
+ chunkedlen 256
+ chunked {</esi:remove></H1>}
+
+ chunked {<H2><esi:remove>}
+ chunkedlen 65536
+ chunked {</esi:remove></H2>}
+
+ chunked {<esi:comment/>}
+ chunkedlen 256
+ chunked {<esi:comment/>}
+ chunkedlen 65536
+ chunked {<esi:comment/>}
+
+ chunkedlen 0
+
rxreq
expect req.url == "bar/foo"
- txresp -body {<H1></H1>}
+ txresp -body {<INCL>}
} -start
varnish v1 -vcl+backend {
sub vcl_fetch {
- set beresp.do_esi = true;
+ if (req.url == "bar") {
+ set beresp.do_esi = true;
+ }
}
} -start
@@ -29,8 +46,8 @@
txreq -url bar
rxresp
expect resp.status == 200
- expect resp.bodylen == 23
+ expect resp.bodylen == 65840
} -run
-varnish v1 -expect esi_errors == 2
+varnish v1 -expect esi_errors == 4
varnish v1 -expect esi_warnings == 1
More information about the varnish-commit
mailing list