Commit 437a7adc authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add error messages from the XML/ESI parser


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2110 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent bd9b8094
...@@ -61,6 +61,54 @@ add_piece(txt t, int kind) ...@@ -61,6 +61,54 @@ add_piece(txt t, int kind)
printf("K%d \"%.*s\"\n", kind, t.e - t.b, t.b); printf("K%d \"%.*s\"\n", kind, t.e - t.b, t.b);
} }
static void
vxml_error(struct sess *sp, const char *p, txt t, size_t off, int i, const char *err)
{
int ellipsis = 0;
char buf[256], *q;
if (i == 0) {
i = t.e - p;
}
if (i > 20) {
i = 20;
ellipsis = 1;
}
q = buf;
q += sprintf(buf, "at %d: %s \"", off + (p - t.b), err);
while (i > 0) {
if (*p >= ' ' && *p <= '~') {
*q++ = *p;
} else if (*p == '\n') {
*q++ = '\\';
*q++ = 'n';
} else if (*p == '\r') {
*q++ = '\\';
*q++ = 'r';
} else if (*p == '\t') {
*q++ = '\\';
*q++ = 't';
} else {
/* XXX: use %%%02x instead ? */
q += sprintf(q, "\\x%02x", *p);
}
p++;
i--;
}
if (ellipsis) {
*q++ = '[';
*q++ = '.';
*q++ = '.';
*q++ = '.';
*q++ = ']';
}
*q++ = '"';
*q++ = '\0';
t.b = buf;
t.e = q;
WSPR(sp, SLT_ESI_xmlerror, t);
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Zoom over a piece of object and dike out all releveant esi: pieces. * Zoom over a piece of object and dike out all releveant esi: pieces.
* The entire txt may not be processed because an interesting part * The entire txt may not be processed because an interesting part
...@@ -69,7 +117,7 @@ add_piece(txt t, int kind) ...@@ -69,7 +117,7 @@ add_piece(txt t, int kind)
*/ */
static int static int
vxml(txt t) vxml(struct sess *sp, txt t, size_t off)
{ {
char *p, *q, *r; char *p, *q, *r;
txt o; txt o;
...@@ -165,7 +213,11 @@ vxml(txt t) ...@@ -165,7 +213,11 @@ vxml(txt t)
} }
if (p[1] == '!') { if (p[1] == '!') {
/* Ignore unrecognized <! sequence */ /*
* Unrecognized <! sequence, ignore
*/
vxml_error(sp, p, t, off, i,
"XML 1.0 Unknown <! sequence");
p += 2; p += 2;
continue; continue;
} }
...@@ -181,7 +233,8 @@ vxml(txt t) ...@@ -181,7 +233,8 @@ vxml(txt t)
celem = 1; celem = 1;
r = p + 2; r = p + 2;
if (q[-1] == '/') { if (q[-1] == '/') {
/* XML violation, ignore this ? */ vxml_error(sp, p, t, off, 1 + q - p,
"XML 1.0 empty and closing element");
} }
} else { } else {
celem = 0; celem = 0;
...@@ -191,7 +244,13 @@ vxml(txt t) ...@@ -191,7 +244,13 @@ vxml(txt t)
if (r + 9 < q && !memcmp(r, "esi:remove", 10)) { if (r + 9 < q && !memcmp(r, "esi:remove", 10)) {
if (celem != remflg) { if (celem != remflg) {
/* ESI 1.0 violation, ignore this element */ /*
* ESI 1.0 violation, ignore element
*/
vxml_error(sp, p, t, off, 1 + q - p,
remflg ? "ESI 1.0 forbids nested esi:remove"
: "ESI 1.0 esi:remove not opened");
if (!remflg) { if (!remflg) {
o.e = p; o.e = p;
add_piece(o, 0); add_piece(o, 0);
...@@ -215,7 +274,11 @@ vxml(txt t) ...@@ -215,7 +274,11 @@ vxml(txt t)
} }
if (remflg && r + 3 < q && !memcmp(r, "esi:", 4)) { if (remflg && r + 3 < q && !memcmp(r, "esi:", 4)) {
/* ESI 1.0 violation, no nesting in esi:remove */ /*
* ESI 1.0 violation, no esi: elements in esi:remove
*/
vxml_error(sp, p, t, off, 1 + q - p,
"ESI 1.0 forbids esi: elements inside esi:remove");
p = q + 1; p = q + 1;
continue; continue;
} }
...@@ -230,10 +293,12 @@ vxml(txt t) ...@@ -230,10 +293,12 @@ vxml(txt t)
o.e = q; o.e = q;
add_piece(o, 1); add_piece(o, 1);
if (q[-1] != '/') { if (q[-1] != '/') {
/* ESI 1.0 violation */ vxml_error(sp, p, t, off, 1 + q - p,
"ESI 1.0 wants emtpy esi:include");
} }
} else { } else {
/* ESI 1.0 violation */ vxml_error(sp, p, t, off, 1 + q - p,
"ESI 1.0 closing esi:include illegal");
} }
p = q + 1; p = q + 1;
o.b = p; o.b = p;
...@@ -244,6 +309,8 @@ vxml(txt t) ...@@ -244,6 +309,8 @@ vxml(txt t)
/* /*
* Unimplemented ESI element, ignore * Unimplemented ESI element, ignore
*/ */
vxml_error(sp, p, t, off, 1 + q - p,
"ESI 1.0 unimplemented element");
o.e = p; o.e = p;
add_piece(o, 0); add_piece(o, 0);
p = q + 1; p = q + 1;
...@@ -267,13 +334,16 @@ VRT_ESI(struct sess *sp) ...@@ -267,13 +334,16 @@ VRT_ESI(struct sess *sp)
struct storage *st; struct storage *st;
txt t; txt t;
int i; int i;
size_t o;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
o = 1;
VTAILQ_FOREACH(st, &sp->obj->store, list) { VTAILQ_FOREACH(st, &sp->obj->store, list) {
t.b = (void*)st->ptr; t.b = (void*)st->ptr;
t.e = t.b + st->len; t.e = t.b + st->len;
i = vxml(t); i = vxml(sp, t, o);
o += st->len;
printf("VXML(%p+%d) = %d", st->ptr, st->len, i); printf("VXML(%p+%d) = %d", st->ptr, st->len, i);
if (i < st->len) if (i < st->len)
printf(" \"%.*s\"", st->len - i, st->ptr + i); printf(" \"%.*s\"", st->len - i, st->ptr + i);
......
...@@ -92,3 +92,6 @@ SLTM(ExpPick) ...@@ -92,3 +92,6 @@ SLTM(ExpPick)
SLTM(ExpKill) SLTM(ExpKill)
SLTM(WorkThread) SLTM(WorkThread)
SLTM(Terminate) SLTM(Terminate)
SLTM(ESItrace)
SLTM(ESI_xmlerror)
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