varnish-cache/bin/varnishd/cache/cache_esi_parse.c
1
/*-
2
 * Copyright (c) 2011 Varnish Software AS
3
 * All rights reserved.
4
 *
5
 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 * SUCH DAMAGE.
27
 *
28
 * VEP Varnish Esi Parsing
29
 */
30
31
#include "config.h"
32
33
#include "cache_varnishd.h"
34
#include "cache_filter.h"
35
36
#include "cache_vgz.h"
37
#include "cache_esi.h"
38
#include "vct.h"
39
#include "vend.h"
40
#include "vgz.h"
41
42
//#define Debug(fmt, ...) printf(fmt, __VA_ARGS__)
43
#define Debug(fmt, ...) /**/
44
45
struct vep_state;
46
47
enum dowhat {DO_ATTR, DO_TAG};
48
typedef void dostuff_f(struct vep_state *, enum dowhat);
49
50
struct vep_match {
51
        const char      *match;
52
        const char      * const *state;
53
};
54
55
enum vep_mark { VERBATIM = 0, SKIP };
56
57
struct vep_state {
58
        unsigned                magic;
59
#define VEP_MAGIC               0x55cb9b82
60
        struct vsb              *vsb;
61
62
        const char              *url;
63
        struct vfp_ctx          *vc;
64
        int                     dogzip;
65
        vep_callback_t          *cb;
66
        void                    *cb_priv;
67
68
        /* Internal Counter for default call-back function */
69
        ssize_t                 cb_x;
70
71
        /* parser state */
72
        const char              *state;
73
        unsigned                startup;
74
        unsigned                esi_found;
75
76
        unsigned                endtag;
77
        unsigned                emptytag;
78
        unsigned                canattr;
79
80
        unsigned                remove;
81
82
        ssize_t                 o_wait;
83
        ssize_t                 o_pending;
84
        ssize_t                 o_total;
85
        uint32_t                crc;
86
        ssize_t                 o_crc;
87
        uint32_t                crcp;
88
        ssize_t                 o_last;
89
90
        const char              *hack_p;
91
        const char              *ver_p;
92
93
        const char              *until;
94
        const char              *until_p;
95
        const char              *until_s;
96
97
        int                     in_esi_tag;
98
99
        const char              *esicmt;
100
        const char              *esicmt_p;
101
102
        struct vep_match        *attr;
103
        struct vsb              *attr_vsb;
104
        int                     attr_delim;
105
106
        struct vep_match        *match;
107
        struct vep_match        *match_hit;
108
109
        char                    tag[8];
110
        int                     tag_i;
111
112
        dostuff_f               *dostuff;
113
114
        struct vsb              *include_src;
115
116
        unsigned                nm_skip;
117
        unsigned                nm_verbatim;
118
        unsigned                nm_pending;
119
        enum vep_mark           last_mark;
120
};
121
122
/*---------------------------------------------------------------------*/
123
124
static const char * const VEP_START =           "[Start]";
125
static const char * const VEP_BOM =             "[BOM]";
126
static const char * const VEP_TESTXML =         "[TestXml]";
127
static const char * const VEP_NOTXML =          "[NotXml]";
128
129
static const char * const VEP_NEXTTAG =         "[NxtTag]";
130
static const char * const VEP_NOTMYTAG =        "[NotMyTag]";
131
132
static const char * const VEP_STARTTAG =        "[StartTag]";
133
static const char * const VEP_COMMENTESI =      "[CommentESI]";
134
static const char * const VEP_COMMENT =         "[Comment]";
135
static const char * const VEP_CDATA =           "[CDATA]";
136
static const char * const VEP_ESITAG =          "[ESITag]";
137
static const char * const VEP_ESIENDTAG =       "[/ESITag]";
138
139
static const char * const VEP_ESIREMOVE =       "[ESI:Remove]";
140
static const char * const VEP_ESIINCLUDE =      "[ESI:Include]";
141
static const char * const VEP_ESICOMMENT =      "[ESI:Comment]";
142
static const char * const VEP_ESIBOGON =        "[ESI:Bogon]";
143
144
static const char * const VEP_INTAG =           "[InTag]";
145
static const char * const VEP_TAGERROR =        "[TagError]";
146
147
static const char * const VEP_ATTR =            "[Attribute]";
148
static const char * const VEP_SKIPATTR =        "[SkipAttribute]";
149
static const char * const VEP_ATTRDELIM =       "[AttrDelim]";
150
static const char * const VEP_ATTRGETVAL =      "[AttrGetValue]";
151
static const char * const VEP_ATTRVAL =         "[AttrValue]";
152
153
static const char * const VEP_UNTIL =           "[Until]";
154
static const char * const VEP_MATCHBUF =        "[MatchBuf]";
155
static const char * const VEP_MATCH =           "[Match]";
156
157
/*---------------------------------------------------------------------*/
158
159
static struct vep_match vep_match_starttag[] = {
160
        { "!--esi",     &VEP_COMMENTESI },
161
        { "!---->",     &VEP_NEXTTAG },
162
        { "!--",        &VEP_COMMENT },
163
        { "/esi:",      &VEP_ESIENDTAG },
164
        { "esi:",       &VEP_ESITAG },
165
        { "![CDATA[",   &VEP_CDATA },
166
        { NULL,         &VEP_NOTMYTAG }
167
};
168
169
/*---------------------------------------------------------------------*/
170
171
static struct vep_match vep_match_esi[] = {
172
        { "include",    &VEP_ESIINCLUDE },
173
        { "remove",     &VEP_ESIREMOVE },
174
        { "comment",    &VEP_ESICOMMENT },
175
        { NULL,         &VEP_ESIBOGON }
176
};
177
178
/*---------------------------------------------------------------------*/
179
180
static struct vep_match vep_match_attr_include[] = {
181
        { "src=",       &VEP_ATTRGETVAL },
182
        { NULL,         &VEP_SKIPATTR }
183
};
184
185
/*---------------------------------------------------------------------*/
186
187
static struct vep_match vep_match_bom[] = {
188
        { "\xeb\xbb\xbf",       &VEP_START },
189
        { NULL,                 &VEP_BOM }
190
};
191
192
/*--------------------------------------------------------------------
193
 * Report a parsing error
194
 */
195
196
static void
197 36
vep_error(const struct vep_state *vep, const char *p)
198
{
199 36
        VSC_C_main->esi_errors++;
200 36
        VSLb(vep->vc->wrk->vsl, SLT_ESI_xmlerror, "ERR after %zd %s",
201
             vep->o_last, p);
202 36
}
203
204
/*--------------------------------------------------------------------
205
 * Report a parsing warning
206
 */
207
208
static void
209 5
vep_warn(const struct vep_state *vep, const char *p)
210
{
211 5
        VSC_C_main->esi_warnings++;
212 5
        VSLb(vep->vc->wrk->vsl, SLT_ESI_xmlerror, "WARN after %zd %s",
213
             vep->o_last, p);
214 5
}
215
216
/*---------------------------------------------------------------------
217
 * return match or NULL if more input needed.
218
 */
219
220
static struct vep_match *
221 12147
vep_match(const struct vep_state *vep, const char *b, const char *e)
222
{
223
        struct vep_match *vm;
224
        const char *q, *r;
225
226 79482
        for (vm = vep->match; vm->match != NULL; vm++) {
227 68597
                assert(strlen(vm->match) <= sizeof (vep->tag));
228 68597
                r = b;
229 74603
                for (q = vm->match; *q != '\0' && r < e; q++, r++)
230 73341
                        if (*q != *r)
231 67335
                                break;
232 68597
                if (*q == '\0')
233 1034
                        break;
234 67563
                if (r == e)
235 228
                        return (NULL);
236
        }
237 11919
        return (vm);
238
}
239
240
/*---------------------------------------------------------------------
241
 *
242
 */
243
244
static void
245 785
vep_emit_len(const struct vep_state *vep, ssize_t l, int m8, int m16, int m64)
246
{
247
        uint8_t buf[9];
248
249 785
        assert(l > 0);
250 785
        if (l < 256) {
251 772
                buf[0] = (uint8_t)m8;
252 772
                buf[1] = (uint8_t)l;
253 772
                assert((ssize_t)buf[1] == l);
254 772
                VSB_bcat(vep->vsb, buf, 2);
255 13
        } else if (l < 65536) {
256 7
                buf[0] = (uint8_t)m16;
257 7
                vbe16enc(buf + 1, (uint16_t)l);
258 7
                assert((ssize_t)vbe16dec(buf + 1) == l);
259 7
                VSB_bcat(vep->vsb, buf, 3);
260
        } else {
261 6
                buf[0] = (uint8_t)m64;
262 6
                vbe64enc(buf + 1, l);
263 6
                assert((ssize_t)vbe64dec(buf + 1) == l);
264 6
                VSB_bcat(vep->vsb, buf, 9);
265
        }
266 785
}
267
268
static void
269 373
vep_emit_skip(const struct vep_state *vep, ssize_t l)
270
{
271
272 373
        vep_emit_len(vep, l, VEC_S1, VEC_S2, VEC_S8);
273 373
}
274
275
static void
276 351
vep_emit_verbatim(const struct vep_state *vep, ssize_t l, ssize_t l_crc)
277
{
278
        uint8_t buf[4];
279
280 351
        vep_emit_len(vep, l, VEC_V1, VEC_V2, VEC_V8);
281 351
        if (vep->dogzip) {
282 61
                vep_emit_len(vep, l_crc, VEC_C1, VEC_C2, VEC_C8);
283 61
                vbe32enc(buf, vep->crc);
284 61
                VSB_bcat(vep->vsb, buf, sizeof buf);
285
        }
286 351
}
287
288
static void
289 843
vep_emit_common(struct vep_state *vep, ssize_t l, enum vep_mark mark)
290
{
291
292 843
        assert(l >= 0);
293 843
        if (l == 0)
294 119
                return;
295 724
        assert(mark == SKIP || mark == VERBATIM);
296 724
        if (mark == SKIP)
297 373
                vep_emit_skip(vep, l);
298
        else
299 351
                vep_emit_verbatim(vep, l, vep->o_crc);
300
301 724
        vep->crc = crc32(0L, Z_NULL, 0);
302 724
        vep->o_crc = 0;
303 724
        vep->o_total += l;
304
}
305
306
/*---------------------------------------------------------------------
307
 *
308
 */
309
310
static void
311 65989
vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
312
{
313
        ssize_t l, lcb;
314
315 65989
        assert(mark == SKIP || mark == VERBATIM);
316
317
        /* The NO-OP case, no data, no pending data & no change of mode */
318 65989
        if (vep->last_mark == mark && p == vep->ver_p && vep->o_pending == 0)
319 37
                return;
320
321
        /*
322
         * If we changed mode, emit whatever the opposite mode
323
         * assembled before the pending bytes.
324
         */
325
326 65952
        if (vep->last_mark != mark && (vep->o_wait > 0 || vep->startup)) {
327 687
                lcb = vep->cb(vep->vc, vep->cb_priv, 0,
328
                    mark == VERBATIM ? VGZ_RESET : VGZ_ALIGN);
329 687
                vep_emit_common(vep, lcb - vep->o_last, vep->last_mark);
330 687
                vep->o_last = lcb;
331 687
                vep->o_wait = 0;
332
        }
333
334
        /* Transfer pending bytes CRC into active mode CRC */
335 65952
        if (vep->o_pending) {
336 67
                (void)vep->cb(vep->vc, vep->cb_priv, vep->o_pending,
337
                     VGZ_NORMAL);
338 67
                if (vep->o_crc == 0) {
339 51
                        vep->crc = vep->crcp;
340 51
                        vep->o_crc = vep->o_pending;
341
                } else {
342 32
                        vep->crc = crc32_combine(vep->crc,
343 16
                            vep->crcp, vep->o_pending);
344 16
                        vep->o_crc += vep->o_pending;
345
                }
346 67
                vep->crcp = crc32(0L, Z_NULL, 0);
347 67
                vep->o_wait += vep->o_pending;
348 67
                vep->o_pending = 0;
349
        }
350
351
        /* * Process this bit of input */
352 65952
        AN(vep->ver_p);
353 65952
        l = p - vep->ver_p;
354 65952
        assert(l >= 0);
355 65952
        vep->crc = crc32(vep->crc, (const void*)vep->ver_p, l);
356 65952
        vep->o_crc += l;
357 65952
        vep->ver_p = p;
358
359 65952
        vep->o_wait += l;
360 65952
        vep->last_mark = mark;
361 65952
        (void)vep->cb(vep->vc, vep->cb_priv, l, VGZ_NORMAL);
362
}
363
364
static void
365 38110
vep_mark_verbatim(struct vep_state *vep, const char *p)
366
{
367
368 38110
        vep_mark_common(vep, p, VERBATIM);
369 38110
        vep->nm_verbatim++;
370 38110
}
371
372
static void
373 27723
vep_mark_skip(struct vep_state *vep, const char *p)
374
{
375
376 27723
        vep_mark_common(vep, p, SKIP);
377 27723
        vep->nm_skip++;
378 27723
}
379
380
static void
381 122
vep_mark_pending(struct vep_state *vep, const char *p)
382
{
383
        ssize_t l;
384
385 122
        AN(vep->ver_p);
386 122
        l = p - vep->ver_p;
387 122
        assert(l > 0);
388 122
        vep->crcp = crc32(vep->crcp, (const void *)vep->ver_p, l);
389 122
        vep->ver_p = p;
390
391 122
        vep->o_pending += l;
392 122
        vep->nm_pending++;
393 122
}
394
395
/*---------------------------------------------------------------------
396
 */
397
398
static void v_matchproto_()
399 6
vep_do_comment(struct vep_state *vep, enum dowhat what)
400
{
401
        Debug("DO_COMMENT(%d)\n", what);
402 6
        assert(what == DO_TAG);
403 6
        if (!vep->emptytag)
404 2
                vep_error(vep, "ESI 1.0 <esi:comment> needs final '/'");
405 6
}
406
407
/*---------------------------------------------------------------------
408
 */
409
410
static void v_matchproto_()
411 142
vep_do_remove(struct vep_state *vep, enum dowhat what)
412
{
413
        Debug("DO_REMOVE(%d, end %d empty %d remove %d)\n",
414
            what, vep->endtag, vep->emptytag, vep->remove);
415 142
        assert(what == DO_TAG);
416 142
        if (vep->emptytag)
417 1
                vep_error(vep, "ESI 1.0 <esi:remove/> not legal");
418 141
        else if (vep->remove && !vep->endtag)
419 1
                vep_error(vep, "ESI 1.0 <esi:remove> already open");
420 140
        else if (!vep->remove && vep->endtag)
421 1
                vep_error(vep, "ESI 1.0 <esi:remove> not open");
422
        else
423 139
                vep->remove = !vep->endtag;
424 142
}
425
426
/*---------------------------------------------------------------------
427
 */
428
429
static void v_matchproto_()
430 449
vep_do_include(struct vep_state *vep, enum dowhat what)
431
{
432
        const char *p, *q, *h;
433
        ssize_t l;
434
435
        Debug("DO_INCLUDE(%d)\n", what);
436 449
        if (what == DO_ATTR) {
437
                Debug("ATTR (%s) (%s)\n", vep->match_hit->match,
438
                        VSB_data(vep->attr_vsb));
439 225
                if (vep->include_src != NULL) {
440 1
                        vep_error(vep,
441
                            "ESI 1.0 <esi:include> "
442
                            "has multiple src= attributes");
443 1
                        vep->state = VEP_TAGERROR;
444 1
                        VSB_destroy(&vep->attr_vsb);
445 1
                        VSB_destroy(&vep->include_src);
446 1
                        return;
447
                }
448 9022
                for (p = VSB_data(vep->attr_vsb); *p != '\0'; p++)
449 8799
                        if (vct_islws(*p))
450 1
                                break;
451 224
                if (*p != '\0') {
452 1
                        vep_error(vep,
453
                            "ESI 1.0 <esi:include> "
454
                            "has whitespace in src= attribute");
455 1
                        vep->state = VEP_TAGERROR;
456 1
                        VSB_destroy(&vep->attr_vsb);
457 1
                        if (vep->include_src != NULL)
458 0
                                VSB_destroy(&vep->include_src);
459 1
                        return;
460
                }
461 223
                vep->include_src = vep->attr_vsb;
462 223
                vep->attr_vsb = NULL;
463 223
                return;
464
        }
465 224
        assert(what == DO_TAG);
466 224
        if (!vep->emptytag)
467 2
                vep_warn(vep, "ESI 1.0 <esi:include> lacks final '/'");
468 224
        if (vep->include_src == NULL) {
469 2
                vep_error(vep, "ESI 1.0 <esi:include> lacks src attr");
470 2
                return;
471
        }
472
473
        /*
474
         * Strictly speaking, we ought to spit out any piled up skip before
475
         * emitting the VEC for the include, but objectively that makes no
476
         * difference and robs us of a chance to collapse another skip into
477
         * this on so we don't do that.
478
         * However, we cannot tolerate any verbatim stuff piling up.
479
         * The mark_skip() before calling dostuff should have taken
480
         * care of that.  Make sure.
481
         */
482 222
        assert(vep->o_wait == 0 || vep->last_mark == SKIP);
483
        /* XXX: what if it contains NUL bytes ?? */
484 222
        p = VSB_data(vep->include_src);
485 222
        l = VSB_len(vep->include_src);
486 222
        h = 0;
487
488 222
        if (l > 7 && !memcmp(p, "http://", 7)) {
489 2
                h = p + 7;
490 2
                p = strchr(h, '/');
491 2
                if (p == NULL) {
492 1
                        vep_error(vep,
493
                            "ESI 1.0 <esi:include> invalid src= URL");
494 1
                        vep->state = VEP_TAGERROR;
495 1
                        AZ(vep->attr_vsb);
496 1
                        VSB_destroy(&vep->include_src);
497 1
                        return;
498
                }
499
                Debug("HOST <%.*s> PATH <%s>\n", (int)(p-h),h, p);
500 1
                VSB_printf(vep->vsb, "%c", VEC_INCL);
501 1
                VSB_printf(vep->vsb, "Host: %.*s%c", (int)(p-h), h, 0);
502 220
        } else if (l > 8 && !memcmp(p, "https://", 8)) {
503 3
                if (!FEATURE(FEATURE_ESI_IGNORE_HTTPS)) {
504 1
                        vep_warn(vep,
505
                            "ESI 1.0 <esi:include> with https:// ignored");
506 1
                        vep->state = VEP_TAGERROR;
507 1
                        AZ(vep->attr_vsb);
508 1
                        VSB_destroy(&vep->include_src);
509 1
                        return;
510
                }
511 2
                vep_warn(vep,
512
                    "ESI 1.0 <esi:include> https:// treated as http://");
513 2
                h = p + 8;
514 2
                p = strchr(h, '/');
515 2
                if (p == NULL) {
516 1
                        vep_error(vep,
517
                            "ESI 1.0 <esi:include> invalid src= URL");
518 1
                        vep->state = VEP_TAGERROR;
519 1
                        AZ(vep->attr_vsb);
520 1
                        VSB_destroy(&vep->include_src);
521 1
                        return;
522
                }
523 1
                VSB_printf(vep->vsb, "%c", VEC_INCL);
524 1
                VSB_printf(vep->vsb, "Host: %.*s%c", (int)(p-h), h, 0);
525 217
        } else if (*p == '/') {
526 189
                VSB_printf(vep->vsb, "%c", VEC_INCL);
527 189
                VSB_printf(vep->vsb, "%c", 0);
528
        } else {
529 28
                VSB_printf(vep->vsb, "%c", VEC_INCL);
530 28
                VSB_printf(vep->vsb, "%c", 0);
531
                /* Look for the last / before a '?' */
532 28
                h = NULL;
533 72
                for (q = vep->url; *q && *q != '?'; q++)
534 44
                        if (*q == '/')
535 29
                                h = q;
536 28
                if (h == NULL)
537 1
                        h = q + 1;
538
539
                Debug("INCL:: [%.*s]/[%s]\n",
540
                    (int)(h - vep->url), vep->url, p);
541 28
                VSB_printf(vep->vsb, "%.*s/", (int)(h - vep->url), vep->url);
542
        }
543 219
        l -= (p - VSB_data(vep->include_src));
544 9123
        for (q = p; *q != '\0'; ) {
545 8685
                if (*q == '&') {
546
#define R(w,f,r)                                                        \
547
                        if (q + w <= p + l && !memcmp(q, f, w)) { \
548
                                VSB_printf(vep->vsb, "%c", r);  \
549
                                q += w;                         \
550
                                continue;                       \
551
                        }
552 10
                        R(6, "&apos;", '\'');
553 8
                        R(6, "&quot;", '"');
554 6
                        R(4, "&lt;", '<');
555 4
                        R(4, "&gt;", '>');
556 2
                        R(5, "&amp;", '&');
557
                }
558 8675
                VSB_printf(vep->vsb, "%c", *q++);
559
        }
560
#undef R
561 219
        VSB_printf(vep->vsb, "%c", 0);
562 219
        VSB_destroy(&vep->include_src);
563
}
564
565
/*---------------------------------------------------------------------
566
 * Lex/Parse object for ESI instructions
567
 *
568
 * This function is called with the input object piecemal so do not
569
 * assume that we have more than one char available at at time, but
570
 * optimize for getting huge chunks.
571
 *
572
 * NB: At the bottom of this source-file, there is a dot-diagram matching
573
 * NB: the state-machine.  Please maintain it along with the code.
574
 */
575
576
void
577 53821
VEP_Parse(struct vep_state *vep, const char *p, size_t l)
578
{
579
        const char *e;
580
        struct vep_match *vm;
581
        int i;
582
583 53821
        CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
584 53821
        assert(l > 0);
585
586 53821
        if (vep->startup) {
587
                /*
588
                 * We must force the GZIP header out as a SKIP string,
589
                 * otherwise an object starting with <esi:include would
590
                 * have its GZIP header appear after the included object
591
                 * (e000026.vtc)
592
                 */
593 156
                vep->ver_p = "";
594 156
                vep->last_mark = SKIP;
595 156
                vep_mark_common(vep, vep->ver_p, VERBATIM);
596 156
                vep->startup = 0;
597 156
                AZ(vep->hack_p);
598 156
                vep->hack_p = p;
599
        }
600
601 53821
        vep->ver_p = p;
602
603 53821
        e = p + l;
604
605 209414
        while (p < e) {
606 101772
                AN(vep->state);
607
                Debug("EP %s %d (%.*s) [%.*s]\n",
608
                    vep->state,
609
                    vep->remove,
610
                    vep->tag_i, vep->tag,
611
                    (e - p) > 10 ? 10 : (int)(e-p), p);
612 101772
                assert(p >= vep->ver_p);
613
614
                /******************************************************
615
                 * SECTION A
616
                 */
617
618 101772
                if (vep->state == VEP_START) {
619 165
                        if (FEATURE(FEATURE_ESI_REMOVE_BOM) &&
620 6
                            *p == (char)0xeb) {
621 4
                                vep->match = vep_match_bom;
622 4
                                vep->state = VEP_MATCH;
623
                        } else
624 155
                                vep->state = VEP_BOM;
625 101613
                } else if (vep->state == VEP_BOM) {
626 156
                        vep_mark_skip(vep, p);
627 156
                        if (FEATURE(FEATURE_ESI_DISABLE_XML_CHECK))
628 44
                                vep->state = VEP_NEXTTAG;
629
                        else
630 112
                                vep->state = VEP_TESTXML;
631 101457
                } else if (vep->state == VEP_TESTXML) {
632
                        /*
633
                         * If the first non-whitespace char is different
634
                         * from '<' we assume this is not XML.
635
                         */
636 394
                        while (p < e && vct_islws(*p))
637 152
                                p++;
638 121
                        vep_mark_verbatim(vep, p);
639 121
                        if (p < e && *p == '<') {
640 104
                                p++;
641 104
                                vep->state = VEP_STARTTAG;
642 17
                        } else if (p < e && *p == (char)0xeb) {
643 2
                                VSLb(vep->vc->wrk->vsl, SLT_ESI_xmlerror,
644
                                    "No ESI processing, "
645
                                    "first char not '<' but BOM."
646
                                    " (See feature esi_remove_bom)"
647
                                );
648 2
                                vep->state = VEP_NOTXML;
649 15
                        } else if (p < e) {
650 5
                                VSLb(vep->vc->wrk->vsl, SLT_ESI_xmlerror,
651
                                    "No ESI processing, "
652
                                    "first char not '<'."
653
                                    " (See feature esi_disable_xml_check)"
654
                                );
655 5
                                vep->state = VEP_NOTXML;
656
                        }
657 101336
                } else if (vep->state == VEP_NOTXML) {
658
                        /*
659
                         * This is not recognized as XML, just skip thru
660
                         * vfp_esi_end() will handle the rest
661
                         */
662 7
                        p = e;
663 7
                        vep_mark_verbatim(vep, p);
664
665
                /******************************************************
666
                 * SECTION B
667
                 */
668
669 101329
                } else if (vep->state == VEP_NOTMYTAG) {
670 10916
                        if (FEATURE(FEATURE_ESI_IGNORE_OTHER_ELEMENTS)) {
671 2
                                p++;
672 2
                                vep->state = VEP_NEXTTAG;
673
                        } else {
674 10914
                                vep->tag_i = 0;
675 57556
                                while (p < e) {
676 46601
                                        if (*p++ == '>') {
677 10873
                                                vep->state = VEP_NEXTTAG;
678 10873
                                                break;
679
                                        }
680
                                }
681
                        }
682 10916
                        if (p == e && !vep->remove)
683 72
                                vep_mark_verbatim(vep, p);
684 90413
                } else if (vep->state == VEP_NEXTTAG) {
685
                        /*
686
                         * Hunt for start of next tag and keep an eye
687
                         * out for end of EsiCmt if armed.
688
                         */
689 64405
                        vep->emptytag = 0;
690 64405
                        vep->attr = NULL;
691 64405
                        vep->dostuff = NULL;
692 2286457
                        while (p < e && *p != '<') {
693 2157647
                                if (vep->esicmt_p == NULL) {
694 2157541
                                        p++;
695 2157541
                                        continue;
696
                                }
697 106
                                if (*p != *vep->esicmt_p) {
698 62
                                        p++;
699 62
                                        vep->esicmt_p = vep->esicmt;
700 62
                                        continue;
701
                                }
702 44
                                if (!vep->remove && vep->esicmt_p == vep->esicmt)
703 10
                                        vep_mark_verbatim(vep, p);
704 44
                                p++;
705 44
                                if (*++vep->esicmt_p == '\0') {
706 14
                                        vep->esi_found = 1;
707 14
                                        vep->esicmt = NULL;
708 14
                                        vep->esicmt_p = NULL;
709
                                        /*
710
                                         * The end of the esicmt
711
                                         * should not be emitted.
712
                                         * But the stuff before should
713
                                         */
714 14
                                        vep_mark_skip(vep, p);
715
                                }
716
                        }
717 64405
                        if (p < e) {
718 11188
                                if (!vep->remove)
719 11105
                                        vep_mark_verbatim(vep, p);
720 11188
                                assert(*p == '<');
721 11188
                                p++;
722 11188
                                vep->state = VEP_STARTTAG;
723 53217
                        } else if (vep->esicmt_p == vep->esicmt && !vep->remove)
724 26775
                                vep_mark_verbatim(vep, p);
725
726
                /******************************************************
727
                 * SECTION C
728
                 */
729
730 26008
                } else if (vep->state == VEP_STARTTAG) {
731
                        /* Start of tag, set up match table */
732 11292
                        vep->endtag = 0;
733 11292
                        vep->match = vep_match_starttag;
734 11292
                        vep->state = VEP_MATCH;
735 14716
                } else if (vep->state == VEP_COMMENT) {
736 5
                        vep->esicmt_p = vep->esicmt = NULL;
737 5
                        vep->until_p = vep->until = "-->";
738 5
                        vep->until_s = VEP_NEXTTAG;
739 5
                        vep->state = VEP_UNTIL;
740 14711
                } else if (vep->state == VEP_COMMENTESI) {
741 15
                        if (vep->remove)
742 5
                                vep_error(vep,
743
                                    "ESI 1.0 Nested <!--esi"
744
                                    " element in <esi:remove>");
745 15
                        vep->esicmt_p = vep->esicmt = "-->";
746 15
                        vep->state = VEP_NEXTTAG;
747 15
                        vep_mark_skip(vep, p);
748 14696
                } else if (vep->state == VEP_CDATA) {
749
                        /*
750
                         * Easy: just look for the end of CDATA
751
                         */
752 4
                        vep->until_p = vep->until = "]]>";
753 4
                        vep->until_s = VEP_NEXTTAG;
754 4
                        vep->state = VEP_UNTIL;
755 14692
                } else if (vep->state == VEP_ESIENDTAG) {
756 73
                        vep->endtag = 1;
757 73
                        vep->state = VEP_ESITAG;
758 14619
                } else if (vep->state == VEP_ESITAG) {
759 390
                        vep->in_esi_tag = 1;
760 390
                        vep->esi_found = 1;
761 390
                        vep_mark_skip(vep, p);
762 390
                        vep->match = vep_match_esi;
763 390
                        vep->state = VEP_MATCH;
764 14229
                } else if (vep->state == VEP_ESIINCLUDE) {
765 236
                        if (vep->remove) {
766 4
                                vep_error(vep,
767
                                    "ESI 1.0 <esi:include> element"
768
                                    " nested in <esi:remove>");
769 4
                                vep->state = VEP_TAGERROR;
770 232
                        } else if (vep->endtag) {
771 1
                                vep_error(vep,
772
                                    "ESI 1.0 </esi:include> illegal end-tag");
773 1
                                vep->state = VEP_TAGERROR;
774
                        } else {
775 231
                                vep->dostuff = vep_do_include;
776 231
                                vep->state = VEP_INTAG;
777 231
                                vep->attr = vep_match_attr_include;
778
                        }
779 13993
                } else if (vep->state == VEP_ESIREMOVE) {
780 142
                        vep->dostuff = vep_do_remove;
781 142
                        vep->state = VEP_INTAG;
782 13851
                } else if (vep->state == VEP_ESICOMMENT) {
783 10
                        if (vep->remove) {
784 1
                                vep_error(vep,
785
                                    "ESI 1.0 <esi:comment> element"
786
                                    " nested in <esi:remove>");
787 1
                                vep->state = VEP_TAGERROR;
788 9
                        } else if (vep->endtag) {
789 2
                                vep_error(vep,
790
                                    "ESI 1.0 </esi:comment> illegal end-tag");
791 2
                                vep->state = VEP_TAGERROR;
792
                        } else {
793 7
                                vep->dostuff = vep_do_comment;
794 7
                                vep->state = VEP_INTAG;
795
                        }
796 13841
                } else if (vep->state == VEP_ESIBOGON) {
797 2
                        vep_error(vep,
798
                            "ESI 1.0 <esi:bogus> element");
799 2
                        vep->state = VEP_TAGERROR;
800
801
                /******************************************************
802
                 * SECTION D
803
                 */
804
805 13839
                } else if (vep->state == VEP_INTAG) {
806 641
                        vep->tag_i = 0;
807 1627
                        while (p < e && vct_islws(*p) && !vep->emptytag) {
808 345
                                p++;
809 345
                                vep->canattr = 1;
810
                        }
811 641
                        if (p < e && *p == '/' && !vep->emptytag) {
812 228
                                p++;
813 228
                                vep->emptytag = 1;
814 228
                                vep->canattr = 0;
815
                        }
816 641
                        if (p < e && *p == '>') {
817 372
                                p++;
818 372
                                AN(vep->dostuff);
819 372
                                vep_mark_skip(vep, p);
820 372
                                vep->dostuff(vep, DO_TAG);
821 372
                                vep->in_esi_tag = 0;
822 372
                                vep->state = VEP_NEXTTAG;
823 269
                        } else if (p < e && vep->emptytag) {
824 1
                                vep_error(vep,
825
                                    "XML 1.0 '>' does not follow '/' in tag");
826 1
                                vep->state = VEP_TAGERROR;
827 505
                        } else if (p < e && vep->canattr &&
828 237
                            vct_isxmlnamestart(*p)) {
829 236
                                vep->state = VEP_ATTR;
830 32
                        } else if (p < e) {
831 1
                                vep_error(vep,
832
                                    "XML 1.0 Illegal attribute start char");
833 1
                                vep->state = VEP_TAGERROR;
834
                        }
835 13198
                } else if (vep->state == VEP_TAGERROR) {
836 226
                        while (p < e && *p != '>')
837 130
                                p++;
838 48
                        if (p < e) {
839 18
                                p++;
840 18
                                vep_mark_skip(vep, p);
841 18
                                vep->in_esi_tag = 0;
842 18
                                vep->state = VEP_NEXTTAG;
843 18
                                if (vep->attr_vsb)
844 1
                                        VSB_destroy(&vep->attr_vsb);
845
                        }
846
847
                /******************************************************
848
                 * SECTION E
849
                 */
850
851 13150
                } else if (vep->state == VEP_ATTR) {
852 236
                        AZ(vep->attr_delim);
853 236
                        if (vep->attr == NULL) {
854 3
                                p++;
855 3
                                AZ(vep->attr_vsb);
856 3
                                vep->state = VEP_SKIPATTR;
857
                        } else {
858 233
                                vep->match = vep->attr;
859 233
                                vep->state = VEP_MATCH;
860
                        }
861 12914
                } else if (vep->state == VEP_SKIPATTR) {
862 43
                        while (p < e && vct_isxmlname(*p))
863 17
                                p++;
864 13
                        if (p < e && *p == '=') {
865 3
                                p++;
866 3
                                vep->state = VEP_ATTRDELIM;
867 10
                        } else if (p < e && *p == '>') {
868 1
                                vep->state = VEP_INTAG;
869 9
                        } else if (p < e && *p == '/') {
870 1
                                vep->state = VEP_INTAG;
871 8
                        } else if (p < e && vct_issp(*p)) {
872 2
                                vep->state = VEP_INTAG;
873 6
                        } else if (p < e) {
874 1
                                vep_error(vep,
875
                                    "XML 1.0 Illegal attr char");
876 1
                                vep->state = VEP_TAGERROR;
877
                        }
878 12901
                } else if (vep->state == VEP_ATTRGETVAL) {
879 228
                        AZ(vep->attr_vsb);
880 228
                        vep->attr_vsb = VSB_new_auto();
881 228
                        vep->state = VEP_ATTRDELIM;
882 12673
                } else if (vep->state == VEP_ATTRDELIM) {
883 231
                        AZ(vep->attr_delim);
884 231
                        if (*p == '"' || *p == '\'') {
885 227
                                vep->attr_delim = *p++;
886 227
                                vep->state = VEP_ATTRVAL;
887 4
                        } else if (!vct_issp(*p)) {
888 3
                                vep->attr_delim = ' ';
889 3
                                vep->state = VEP_ATTRVAL;
890
                        } else {
891 1
                                vep_error(vep,
892
                                    "XML 1.0 Illegal attribute delimiter");
893 1
                                vep->state = VEP_TAGERROR;
894
                        }
895
896 12442
                } else if (vep->state == VEP_ATTRVAL) {
897 18178
                        while (p < e && *p != '>' && *p != vep->attr_delim &&
898 8829
                           (vep->attr_delim != ' ' || !vct_issp(*p))) {
899 8819
                                if (vep->attr_vsb != NULL)
900 8810
                                        VSB_putc(vep->attr_vsb, *p);
901 8819
                                p++;
902
                        }
903 270
                        if (p < e && *p == '>') {
904 2
                                vep_error(vep,
905
                                    "XML 1.0 Missing end attribute delimiter");
906 2
                                vep->state = VEP_TAGERROR;
907 2
                                vep->attr_delim = 0;
908 4
                                if (vep->attr_vsb != NULL) {
909 2
                                        AZ(VSB_finish(vep->attr_vsb));
910 2
                                        VSB_destroy(&vep->attr_vsb);
911
                                }
912 268
                        } else if (p < e) {
913 228
                                vep->attr_delim = 0;
914 228
                                p++;
915 228
                                vep->state = VEP_INTAG;
916 228
                                if (vep->attr_vsb != NULL) {
917 225
                                        AZ(VSB_finish(vep->attr_vsb));
918 225
                                        AN(vep->dostuff);
919 225
                                        vep->dostuff(vep, DO_ATTR);
920 225
                                        vep->attr_vsb = NULL;
921
                                }
922
                        }
923
924
                /******************************************************
925
                 * Utility Section
926
                 */
927
928 12172
                } else if (vep->state == VEP_MATCH) {
929
                        /*
930
                         * Match against a table
931
                         */
932 11919
                        vm = vep_match(vep, p, e);
933 11919
                        vep->match_hit = vm;
934 11919
                        if (vm != NULL) {
935 11779
                                if (vm->match != NULL)
936 902
                                        p += strlen(vm->match);
937 11779
                                vep->state = *vm->state;
938 11779
                                vep->match = NULL;
939 11779
                                vep->tag_i = 0;
940
                        } else {
941 140
                                assert(e - p <= sizeof(vep->tag));
942 140
                                memcpy(vep->tag, p, e - p);
943 140
                                vep->tag_i = e - p;
944 140
                                vep->state = VEP_MATCHBUF;
945 140
                                p = e;
946
                        }
947 253
                } else if (vep->state == VEP_MATCHBUF) {
948
                        /*
949
                         * Match against a table while split over input
950
                         * sections.
951
                         */
952 228
                        AN(vep->match);
953 228
                        i = sizeof(vep->tag) - vep->tag_i;
954 228
                        if (i > e - p)
955 194
                                i = e - p;
956 228
                        memcpy(vep->tag + vep->tag_i, p, i);
957 228
                        vm = vep_match(vep, vep->tag,
958 228
                            vep->tag + vep->tag_i + i);
959
                        Debug("MB (%.*s) tag_i %d i %d = vm %p match %s\n",
960
                            vep->tag_i + i, vep->tag,
961
                            vep->tag_i,
962
                            i,
963
                            vm,
964
                            vm ? vm->match : "(nil)");
965
966 228
                        if (vm == NULL) {
967 88
                                vep->tag_i += i;
968 88
                                p += i;
969 88
                                assert(p == e);
970
                        } else {
971 140
                                vep->match_hit = vm;
972 140
                                vep->state = *vm->state;
973 140
                                if (vm->match != NULL) {
974 132
                                        i = strlen(vm->match);
975 132
                                        if (i > vep->tag_i)
976 131
                                                p += i - vep->tag_i;
977
                                }
978 140
                                vep->match = NULL;
979 140
                                vep->tag_i = 0;
980
                        }
981 25
                } else if (vep->state == VEP_UNTIL) {
982
                        /*
983
                         * Skip until we see magic string
984
                         */
985 212
                        while (p < e) {
986 169
                                if (*p++ != *vep->until_p++) {
987 146
                                        vep->until_p = vep->until;
988 23
                                } else if (*vep->until_p == '\0') {
989 7
                                        vep->state = vep->until_s;
990 7
                                        break;
991
                                }
992
                        }
993 25
                        if (p == e && !vep->remove)
994 20
                                vep_mark_verbatim(vep, p);
995
                } else {
996
                        Debug("*** Unknown state %s\n", vep->state);
997 0
                        WRONG("WRONG ESI PARSER STATE");
998
                }
999
        }
1000
        /*
1001
         * We must always mark up the storage we got, try to do so
1002
         * in the most efficient way, in particular with respect to
1003
         * minimizing and limiting use of pending.
1004
         */
1005 53821
        if (p == vep->ver_p)
1006
                ;
1007 26880
        else if (vep->in_esi_tag)
1008 285
                vep_mark_skip(vep, p);
1009 26595
        else if (vep->remove)
1010 26473
                vep_mark_skip(vep, p);
1011
        else
1012 122
                vep_mark_pending(vep, p);
1013 53821
}
1014
1015
/*---------------------------------------------------------------------
1016
 */
1017
1018
static ssize_t v_matchproto_(vep_callback_t)
1019 66169
vep_default_cb(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg)
1020
{
1021
        ssize_t *s;
1022
1023 66169
        CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
1024 66169
        AN(priv);
1025 66169
        s = priv;
1026 66169
        *s += l;
1027
        (void)flg;
1028 66169
        return (*s);
1029
}
1030
1031
/*---------------------------------------------------------------------
1032
 */
1033
1034
struct vep_state *
1035 159
VEP_Init(struct vfp_ctx *vc, const struct http *req, vep_callback_t *cb,
1036
    void *cb_priv)
1037
{
1038
        struct vep_state *vep;
1039
1040 159
        CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
1041 159
        CHECK_OBJ_NOTNULL(req, HTTP_MAGIC);
1042 159
        vep = WS_Alloc(vc->resp->ws, sizeof *vep);
1043 159
        AN(vep);
1044
1045 159
        INIT_OBJ(vep, VEP_MAGIC);
1046 159
        vep->url = req->hd[HTTP_HDR_URL].b;
1047 159
        vep->vc = vc;
1048 159
        vep->vsb = VSB_new_auto();
1049 159
        AN(vep->vsb);
1050
1051 159
        if (cb != NULL) {
1052 39
                vep->dogzip = 1;
1053
                /* XXX */
1054 39
                VSB_printf(vep->vsb, "%c", VEC_GZ);
1055 39
                vep->cb = cb;
1056 39
                vep->cb_priv = cb_priv;
1057
        } else {
1058 120
                vep->cb = vep_default_cb;
1059 120
                vep->cb_priv = &vep->cb_x;
1060
        }
1061
1062 159
        vep->state = VEP_START;
1063 159
        vep->crc = crc32(0L, Z_NULL, 0);
1064 159
        vep->crcp = crc32(0L, Z_NULL, 0);
1065
1066 159
        vep->startup = 1;
1067 159
        return (vep);
1068
}
1069
1070
/*---------------------------------------------------------------------
1071
 */
1072
1073
struct vsb *
1074 159
VEP_Finish(struct vep_state *vep)
1075
{
1076
        ssize_t l, lcb;
1077
1078 159
        CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
1079
1080 159
        if (vep->include_src)
1081 0
                VSB_destroy(&vep->include_src);
1082 159
        if (vep->attr_vsb)
1083 0
                VSB_destroy(&vep->attr_vsb);
1084
1085 315
        if (vep->state != VEP_START &&
1086 312
            vep->state != VEP_BOM &&
1087 311
            vep->state != VEP_TESTXML &&
1088 303
            vep->state != VEP_NOTXML &&
1089 148
            vep->state != VEP_NEXTTAG) {
1090 4
                vep_error(vep, "VEP ended inside a tag");
1091
        }
1092
1093 159
        if (vep->o_pending)
1094 0
                vep_mark_common(vep, vep->ver_p, vep->last_mark);
1095 159
        if (vep->o_wait > 0) {
1096 156
                lcb = vep->cb(vep->vc, vep->cb_priv, 0, VGZ_ALIGN);
1097 156
                vep_emit_common(vep, lcb - vep->o_last, vep->last_mark);
1098
        }
1099
        // NB: We don't account for PAD+SUM+LEN in gzip'ed objects
1100 159
        (void)vep->cb(vep->vc, vep->cb_priv, 0, VGZ_FINISH);
1101
1102 159
        AZ(VSB_finish(vep->vsb));
1103 159
        l = VSB_len(vep->vsb);
1104 159
        if (vep->esi_found && l > 0)
1105 92
                return (vep->vsb);
1106 67
        VSB_destroy(&vep->vsb);
1107 67
        return (NULL);
1108
}
1109
1110
#if 0
1111
1112
digraph xml {
1113
        rankdir="LR"
1114
        size="7,10"
1115
#################################################################
1116
# SECTION A
1117
#
1118
1119
START           [shape=ellipse]
1120
TESTXML         [shape=ellipse]
1121
NOTXML          [shape=ellipse]
1122
NEXTTAGa        [shape=hexagon, label="NEXTTAG"]
1123
STARTTAGa       [shape=hexagon, label="STARTTAG"]
1124
START           -> TESTXML
1125
START           -> NEXTTAGa     [style=dotted, label="syntax:1"]
1126
TESTXML         -> TESTXML      [label="lws"]
1127
TESTXML         -> NOTXML
1128
TESTXML         -> STARTTAGa    [label="'<'"]
1129
1130
#################################################################
1131
# SECTION B
1132
1133
NOTMYTAG        [shape=ellipse]
1134
NEXTTAG         [shape=ellipse]
1135
NOTMYTAG        -> NEXTTAG      [style=dotted, label="syntax:2"]
1136
STARTTAGb       [shape=hexagon, label="STARTTAG"]
1137
NOTMYTAG        -> NEXTTAG      [label="'>'"]
1138
NOTMYTAG        -> NOTMYTAG     [label="*"]
1139
NEXTTAG         -> NEXTTAG      [label="'-->'"]
1140
NEXTTAG         -> NEXTTAG      [label="*"]
1141
NEXTTAG         -> STARTTAGb    [label="'<'"]
1142
1143
#################################################################
1144
# SECTION C
1145
1146
STARTTAG        [shape=ellipse]
1147
COMMENT         [shape=ellipse]
1148
CDATA           [shape=ellipse]
1149
ESITAG          [shape=ellipse]
1150
ESIETAG         [shape=ellipse]
1151
ESIINCLUDE      [shape=ellipse]
1152
ESIREMOVE       [shape=ellipse]
1153
ESICOMMENT      [shape=ellipse]
1154
ESIBOGON        [shape=ellipse]
1155
INTAGc          [shape=hexagon, label="INTAG"]
1156
NOTMYTAGc       [shape=hexagon, label="NOTMYTAG"]
1157
NEXTTAGc        [shape=hexagon, label="NEXTTAG"]
1158
TAGERRORc       [shape=hexagon, label="TAGERROR"]
1159
C1              [shape=circle,label=""]
1160
STARTTAG        -> COMMENT      [label="'<!--'"]
1161
STARTTAG        -> ESITAG       [label="'<esi'"]
1162
STARTTAG        -> CDATA        [label="'<![CDATA['"]
1163
STARTTAG        -> NOTMYTAGc    [label="'*'"]
1164
COMMENT         -> NEXTTAGc     [label="'esi'"]
1165
COMMENT         -> C1           [label="*"]
1166
C1              -> C1           [label="*"]
1167
C1              -> NEXTTAGc     [label="-->"]
1168
CDATA           -> CDATA        [label="*"]
1169
CDATA           -> NEXTTAGc     [label="]]>"]
1170
ESITAG          -> ESIINCLUDE   [label="'include'"]
1171
ESITAG          -> ESIREMOVE    [label="'remove'"]
1172
ESITAG          -> ESICOMMENT   [label="'comment'"]
1173
ESITAG          -> ESIBOGON     [label="*"]
1174
ESICOMMENT      -> INTAGc
1175
ESICOMMENT      -> TAGERRORc
1176
ESICOMMENT      -> TAGERRORc    [style=dotted, label="nested\nin\nremove"]
1177
ESIREMOVE       -> INTAGc
1178
ESIREMOVE       -> TAGERRORc
1179
ESIINCLUDE      -> INTAGc
1180
ESIINCLUDE      -> TAGERRORc
1181
ESIINCLUDE      -> TAGERRORc    [style=dotted, label="nested\nin\nremove"]
1182
ESIBOGON        -> TAGERRORc
1183
1184
#################################################################
1185
# SECTION D
1186
1187
INTAG           [shape=ellipse]
1188
TAGERROR        [shape=ellipse]
1189
NEXTTAGd        [shape=hexagon, label="NEXTTAG"]
1190
ATTRd           [shape=hexagon, label="ATTR"]
1191
D1              [shape=circle, label=""]
1192
D2              [shape=circle, label=""]
1193
INTAG           -> D1           [label="lws"]
1194
D1              -> D2           [label="/"]
1195
INTAG           -> D2           [label="/"]
1196
INTAG           -> NEXTTAGd     [label=">"]
1197
D1              -> NEXTTAGd     [label=">"]
1198
D2              -> NEXTTAGd     [label=">"]
1199
D1              -> ATTRd        [label="XMLstartchar"]
1200
D1              -> TAGERROR     [label="*"]
1201
D2              -> TAGERROR     [label="*"]
1202
TAGERROR        -> TAGERROR     [label="*"]
1203
TAGERROR        -> NEXTTAGd     [label="'>'"]
1204
1205
#################################################################
1206
# SECTION E
1207
1208
ATTR            [shape=ellipse]
1209
SKIPATTR        [shape=ellipse]
1210
ATTRGETVAL      [shape=ellipse]
1211
ATTRDELIM       [shape=ellipse]
1212
ATTRVAL         [shape=ellipse]
1213
TAGERRORe       [shape=hexagon, label="TAGERROR"]
1214
INTAGe          [shape=hexagon, label="INTAG"]
1215
ATTR            -> SKIPATTR     [label="*"]
1216
ATTR            -> ATTRGETVAL   [label="wanted attr"]
1217
SKIPATTR        -> SKIPATTR     [label="XMLname"]
1218
SKIPATTR        -> ATTRDELIM    [label="'='"]
1219
SKIPATTR        -> TAGERRORe    [label="*"]
1220
ATTRGETVAL      -> ATTRDELIM
1221
ATTRDELIM       -> ATTRVAL      [label="\""]
1222
ATTRDELIM       -> ATTRVAL      [label="\'"]
1223
ATTRDELIM       -> ATTRVAL      [label="*"]
1224
ATTRDELIM       -> TAGERRORe    [label="lws"]
1225
ATTRVAL         -> TAGERRORe    [label="'>'"]
1226
ATTRVAL         -> INTAGe       [label="delim"]
1227
ATTRVAL         -> ATTRVAL      [label="*"]
1228
1229
}
1230
1231
#endif