Coverage Report

Created: 2026-08-31 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensips/lib/yxml.c
Line
Count
Source
1
/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT! */
2
3
/* Copyright (c) 2013-2014 Yoran Heling
4
5
  Permission is hereby granted, free of charge, to any person obtaining
6
  a copy of this software and associated documentation files (the
7
  "Software"), to deal in the Software without restriction, including
8
  without limitation the rights to use, copy, modify, merge, publish,
9
  distribute, sublicense, and/or sell copies of the Software, and to
10
  permit persons to whom the Software is furnished to do so, subject to
11
  the following conditions:
12
13
  The above copyright notice and this permission notice shall be included
14
  in all copies or substantial portions of the Software.
15
16
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
*/
24
25
#include "yxml.h"
26
#include <string.h>
27
28
typedef enum {
29
  YXMLS_string,
30
  YXMLS_attr0,
31
  YXMLS_attr1,
32
  YXMLS_attr2,
33
  YXMLS_attr3,
34
  YXMLS_attr4,
35
  YXMLS_cd0,
36
  YXMLS_cd1,
37
  YXMLS_cd2,
38
  YXMLS_comment0,
39
  YXMLS_comment1,
40
  YXMLS_comment2,
41
  YXMLS_comment3,
42
  YXMLS_comment4,
43
  YXMLS_dt0,
44
  YXMLS_dt1,
45
  YXMLS_dt2,
46
  YXMLS_dt3,
47
  YXMLS_dt4,
48
  YXMLS_elem0,
49
  YXMLS_elem1,
50
  YXMLS_elem2,
51
  YXMLS_elem3,
52
  YXMLS_enc0,
53
  YXMLS_enc1,
54
  YXMLS_enc2,
55
  YXMLS_enc3,
56
  YXMLS_etag0,
57
  YXMLS_etag1,
58
  YXMLS_etag2,
59
  YXMLS_init,
60
  YXMLS_le0,
61
  YXMLS_le1,
62
  YXMLS_le2,
63
  YXMLS_le3,
64
  YXMLS_lee1,
65
  YXMLS_lee2,
66
  YXMLS_leq0,
67
  YXMLS_misc0,
68
  YXMLS_misc1,
69
  YXMLS_misc2,
70
  YXMLS_misc2a,
71
  YXMLS_misc3,
72
  YXMLS_pi0,
73
  YXMLS_pi1,
74
  YXMLS_pi2,
75
  YXMLS_pi3,
76
  YXMLS_pi4,
77
  YXMLS_std0,
78
  YXMLS_std1,
79
  YXMLS_std2,
80
  YXMLS_std3,
81
  YXMLS_ver0,
82
  YXMLS_ver1,
83
  YXMLS_ver2,
84
  YXMLS_ver3,
85
  YXMLS_xmldecl0,
86
  YXMLS_xmldecl1,
87
  YXMLS_xmldecl2,
88
  YXMLS_xmldecl3,
89
  YXMLS_xmldecl4,
90
  YXMLS_xmldecl5,
91
  YXMLS_xmldecl6,
92
  YXMLS_xmldecl7,
93
  YXMLS_xmldecl8,
94
  YXMLS_xmldecl9
95
} yxml_state_t;
96
97
98
0
#define yxml_isChar(c) 1
99
/* 0xd should be part of SP, too, but yxml_parse() already normalizes that into 0xa */
100
0
#define yxml_isSP(c) (c == 0x20 || c == 0x09 || c == 0x0a)
101
0
#define yxml_isAlpha(c) (((c) >= 'a' && (c) <= 'z') || \
102
0
  ((c) >= 'A' && (c) <= 'Z'))
103
0
#define yxml_isNum(c) ((c) >= '0' && (c) <= '9')
104
0
#define yxml_isHex(c) (yxml_isNum(c) || \
105
0
  (((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')))
106
0
#define yxml_isEncName(c) (yxml_isAlpha(c) || yxml_isNum(c) || c == '.' || c == '_' || c == '-')
107
0
#define yxml_isNameStart(c) (yxml_isAlpha(c) || c == ':' || c == '_' || c >= 128)
108
0
#define yxml_isName(c) (yxml_isNameStart(c) || yxml_isNum(c) || c == '-' || c == '.')
109
/* XXX: The valid characters are dependent on the quote char, hence the access to x->quote */
110
0
#define yxml_isAttValue(c) (yxml_isChar(c) && c != x->quote && c != '<' && c != '&')
111
/* Anything between '&' and ';', the yxml_ref* functions will do further
112
 * validation. Strictly speaking, this is "yxml_isName(c) || c == '#'", but
113
 * this parser doesn't understand entities with '.', ':', etc, anwyay.  */
114
0
#define yxml_isRef(c) (yxml_isNum(c) || yxml_isAlpha(c) || c == '#')
115
116
0
#define INTFROM5CHARS(a, b, c, d, e) ((((uint64_t)(a))<<32) | (((uint64_t)(b))<<24) | (((uint64_t)(c))<<16) | (((uint64_t)(d))<<8) | (uint64_t)(e))
117
118
119
/* Set the given char value to ch (0<=ch<=255).
120
 * This can't be done with simple assignment because char may be signed, and
121
 * unsigned-to-signed overflow is implementation defined in C. This function
122
 * /looks/ inefficient, but gcc compiles it down to a single movb instruction
123
 * on x86, even with -O0. */
124
0
static inline void yxml_setchar(char *dest, unsigned ch) {
125
0
  unsigned char _ch = ch;
126
0
  memcpy(dest, &_ch, 1);
127
0
}
128
129
130
/* Similar to yxml_setchar(), but will convert ch (any valid unicode point) to
131
 * UTF-8 and appends a '\0'. dest must have room for at least 5 bytes. */
132
0
static void yxml_setutf8(char *dest, unsigned ch) {
133
0
  if(ch <= 0x007F)
134
0
    yxml_setchar(dest++, ch);
135
0
  else if(ch <= 0x07FF) {
136
0
    yxml_setchar(dest++, 0xC0 | (ch>>6));
137
0
    yxml_setchar(dest++, 0x80 | (ch & 0x3F));
138
0
  } else if(ch <= 0xFFFF) {
139
0
    yxml_setchar(dest++, 0xE0 | (ch>>12));
140
0
    yxml_setchar(dest++, 0x80 | ((ch>>6) & 0x3F));
141
0
    yxml_setchar(dest++, 0x80 | (ch & 0x3F));
142
0
  } else {
143
0
    yxml_setchar(dest++, 0xF0 | (ch>>18));
144
0
    yxml_setchar(dest++, 0x80 | ((ch>>12) & 0x3F));
145
0
    yxml_setchar(dest++, 0x80 | ((ch>>6) & 0x3F));
146
0
    yxml_setchar(dest++, 0x80 | (ch & 0x3F));
147
0
  }
148
0
  *dest = 0;
149
0
}
150
151
152
0
static inline yxml_ret_t yxml_datacontent(yxml_t *x, unsigned ch) {
153
0
  yxml_setchar(x->data, ch);
154
0
  x->data[1] = 0;
155
0
  return YXML_CONTENT;
156
0
}
157
158
159
0
static inline yxml_ret_t yxml_datapi1(yxml_t *x, unsigned ch) {
160
0
  yxml_setchar(x->data, ch);
161
0
  x->data[1] = 0;
162
0
  return YXML_PICONTENT;
163
0
}
164
165
166
0
static inline yxml_ret_t yxml_datapi2(yxml_t *x, unsigned ch) {
167
0
  x->data[0] = '?';
168
0
  yxml_setchar(x->data+1, ch);
169
0
  x->data[2] = 0;
170
0
  return YXML_PICONTENT;
171
0
}
172
173
174
0
static inline yxml_ret_t yxml_datacd1(yxml_t *x, unsigned ch) {
175
0
  x->data[0] = ']';
176
0
  yxml_setchar(x->data+1, ch);
177
0
  x->data[2] = 0;
178
0
  return YXML_CONTENT;
179
0
}
180
181
182
0
static inline yxml_ret_t yxml_datacd2(yxml_t *x, unsigned ch) {
183
0
  x->data[0] = ']';
184
0
  x->data[1] = ']';
185
0
  yxml_setchar(x->data+2, ch);
186
0
  x->data[3] = 0;
187
0
  return YXML_CONTENT;
188
0
}
189
190
191
0
static inline yxml_ret_t yxml_dataattr(yxml_t *x, unsigned ch) {
192
  /* Normalize attribute values according to the XML spec section 3.3.3. */
193
0
  yxml_setchar(x->data, ch == 0x9 || ch == 0xa ? 0x20 : ch);
194
0
  x->data[1] = 0;
195
0
  return YXML_ATTRVAL;
196
0
}
197
198
199
0
static yxml_ret_t yxml_pushstack(yxml_t *x, char **res, unsigned ch) {
200
0
  if(x->stacklen+2 >= x->stacksize)
201
0
    return YXML_ESTACK;
202
0
  x->stacklen++;
203
0
  *res = (char *)x->stack+x->stacklen;
204
0
  x->stack[x->stacklen] = ch;
205
0
  x->stacklen++;
206
0
  x->stack[x->stacklen] = 0;
207
0
  return YXML_OK;
208
0
}
209
210
211
0
static yxml_ret_t yxml_pushstackc(yxml_t *x, unsigned ch) {
212
0
  if(x->stacklen+1 >= x->stacksize)
213
0
    return YXML_ESTACK;
214
0
  x->stack[x->stacklen] = ch;
215
0
  x->stacklen++;
216
0
  x->stack[x->stacklen] = 0;
217
0
  return YXML_OK;
218
0
}
219
220
221
0
static void yxml_popstack(yxml_t *x) {
222
0
  do
223
0
    x->stacklen--;
224
0
  while(x->stack[x->stacklen]);
225
0
}
226
227
228
0
static inline yxml_ret_t yxml_elemstart  (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->elem, ch); }
229
0
static inline yxml_ret_t yxml_elemname   (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
230
0
static inline yxml_ret_t yxml_elemnameend(yxml_t *x, unsigned ch) { return YXML_ELEMSTART; }
231
232
233
/* Also used in yxml_elemcloseend(), since this function just removes the last
234
 * element from the stack and returns ELEMEND. */
235
0
static yxml_ret_t yxml_selfclose(yxml_t *x, unsigned ch) {
236
0
  yxml_popstack(x);
237
0
  if(x->stacklen) {
238
0
    x->elem = (char *)x->stack+x->stacklen-1;
239
0
    while(*(x->elem-1))
240
0
      x->elem--;
241
0
    return YXML_ELEMEND;
242
0
  }
243
0
  x->elem = (char *)x->stack;
244
0
  x->state = YXMLS_misc3;
245
0
  return YXML_ELEMEND;
246
0
}
247
248
249
0
static inline yxml_ret_t yxml_elemclose(yxml_t *x, unsigned ch) {
250
0
  if(*((unsigned char *)x->elem) != ch)
251
0
    return YXML_ECLOSE;
252
0
  x->elem++;
253
0
  return YXML_OK;
254
0
}
255
256
257
0
static inline yxml_ret_t yxml_elemcloseend(yxml_t *x, unsigned ch) {
258
0
  if(*x->elem)
259
0
    return YXML_ECLOSE;
260
0
  return yxml_selfclose(x, ch);
261
0
}
262
263
264
0
static inline yxml_ret_t yxml_attrstart  (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->attr, ch); }
265
0
static inline yxml_ret_t yxml_attrname   (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
266
0
static inline yxml_ret_t yxml_attrnameend(yxml_t *x, unsigned ch) { return YXML_ATTRSTART; }
267
0
static inline yxml_ret_t yxml_attrvalend (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_ATTREND; }
268
269
270
0
static inline yxml_ret_t yxml_pistart  (yxml_t *x, unsigned ch) { return yxml_pushstack(x, &x->pi, ch); }
271
0
static inline yxml_ret_t yxml_piname   (yxml_t *x, unsigned ch) { return yxml_pushstackc(x, ch); }
272
0
static inline yxml_ret_t yxml_piabort  (yxml_t *x, unsigned ch) { yxml_popstack(x); return YXML_OK; }
273
0
static inline yxml_ret_t yxml_pinameend(yxml_t *x, unsigned ch) {
274
0
  return (x->pi[0]|32) == 'x' && (x->pi[1]|32) == 'm' && (x->pi[2]|32) == 'l' && !x->pi[3] ? YXML_ESYN : YXML_PISTART;
275
0
}
276
0
static inline yxml_ret_t yxml_pivalend (yxml_t *x, unsigned ch) { yxml_popstack(x); x->pi = (char *)x->stack; return YXML_PIEND; }
277
278
279
0
static inline yxml_ret_t yxml_refstart(yxml_t *x, unsigned ch) {
280
0
  memset(x->data, 0, sizeof(x->data));
281
0
  x->reflen = 0;
282
0
  return YXML_OK;
283
0
}
284
285
286
0
static yxml_ret_t yxml_ref(yxml_t *x, unsigned ch) {
287
0
  if(x->reflen >= sizeof(x->data)-1)
288
0
    return YXML_EREF;
289
0
  yxml_setchar(x->data+x->reflen, ch);
290
0
  x->reflen++;
291
0
  return YXML_OK;
292
0
}
293
294
295
0
static yxml_ret_t yxml_refend(yxml_t *x, yxml_ret_t ret) {
296
0
  unsigned char *r = (unsigned char *)x->data;
297
0
  unsigned ch = 0;
298
0
  if(*r == '#') {
299
0
    if(r[1] == 'x')
300
0
      for(r += 2; yxml_isHex((unsigned)*r); r++)
301
0
        ch = (ch<<4) + (*r <= '9' ? *r-'0' : (*r|32)-'a' + 10);
302
0
    else
303
0
      for(r++; yxml_isNum((unsigned)*r); r++)
304
0
        ch = (ch*10) + (*r-'0');
305
0
    if(*r)
306
0
      ch = 0;
307
0
  } else {
308
0
    uint64_t i = INTFROM5CHARS(r[0], r[1], r[2], r[3], r[4]);
309
0
    ch =
310
0
      i == INTFROM5CHARS('l','t', 0,  0, 0) ? '<' :
311
0
      i == INTFROM5CHARS('g','t', 0,  0, 0) ? '>' :
312
0
      i == INTFROM5CHARS('a','m','p', 0, 0) ? '&' :
313
0
      i == INTFROM5CHARS('a','p','o','s',0) ? '\'':
314
0
      i == INTFROM5CHARS('q','u','o','t',0) ? '"' : 0;
315
0
  }
316
317
  /* Codepoints not allowed in the XML 1.1 definition of a Char */
318
0
  if(!ch || ch > 0x10FFFF || ch == 0xFFFE || ch == 0xFFFF ||
319
0
      (ch-0xD800) < 0x800)
320
0
    return YXML_EREF;
321
0
  yxml_setutf8(x->data, ch);
322
0
  return ret;
323
0
}
324
325
326
0
static inline yxml_ret_t yxml_refcontent(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_CONTENT); }
327
0
static inline yxml_ret_t yxml_refattrval(yxml_t *x, unsigned ch) { return yxml_refend(x, YXML_ATTRVAL); }
328
329
330
0
void yxml_init(yxml_t *x, void *stack, size_t stacksize) {
331
0
  memset(x, 0, sizeof(*x));
332
0
  x->line = 1;
333
0
  x->stack = stack;
334
0
  x->stacksize = stacksize;
335
0
  *x->stack = 0;
336
0
  x->elem = x->pi = x->attr = (char *)x->stack;
337
0
  x->state = YXMLS_init;
338
0
}
339
340
341
0
yxml_ret_t yxml_parse(yxml_t *x, int _ch) {
342
  /* Ensure that characters are in the range of 0..255 rather than -126..125.
343
   * All character comparisons are done with positive integers. */
344
0
  unsigned ch = (unsigned)(_ch+256) & 0xff;
345
0
  if(!ch)
346
0
    return YXML_ESYN;
347
0
  x->total++;
348
349
  /* End-of-Line normalization, "\rX", "\r\n" and "\n" are recognized and
350
   * normalized to a single '\n' as per XML 1.0 section 2.11. XML 1.1 adds
351
   * some non-ASCII character sequences to this list, but we can only handle
352
   * ASCII here without making assumptions about the input encoding. */
353
0
  if(x->ignore == ch) {
354
0
    x->ignore = 0;
355
0
    return YXML_OK;
356
0
  }
357
0
  x->ignore = (ch == 0xd) * 0xa;
358
0
  if(ch == 0xa || ch == 0xd) {
359
0
    ch = 0xa;
360
0
    x->line++;
361
0
    x->byte = 0;
362
0
  }
363
0
  x->byte++;
364
365
0
  switch((yxml_state_t)x->state) {
366
0
  case YXMLS_string:
367
0
    if(ch == *x->string) {
368
0
      x->string++;
369
0
      if(!*x->string)
370
0
        x->state = x->nextstate;
371
0
      return YXML_OK;
372
0
    }
373
0
    break;
374
0
  case YXMLS_attr0:
375
0
    if(yxml_isName(ch))
376
0
      return yxml_attrname(x, ch);
377
0
    if(yxml_isSP(ch)) {
378
0
      x->state = YXMLS_attr1;
379
0
      return yxml_attrnameend(x, ch);
380
0
    }
381
0
    if(ch == (unsigned char)'=') {
382
0
      x->state = YXMLS_attr2;
383
0
      return yxml_attrnameend(x, ch);
384
0
    }
385
0
    break;
386
0
  case YXMLS_attr1:
387
0
    if(yxml_isSP(ch))
388
0
      return YXML_OK;
389
0
    if(ch == (unsigned char)'=') {
390
0
      x->state = YXMLS_attr2;
391
0
      return YXML_OK;
392
0
    }
393
0
    break;
394
0
  case YXMLS_attr2:
395
0
    if(yxml_isSP(ch))
396
0
      return YXML_OK;
397
0
    if(ch == (unsigned char)'\'' || ch == (unsigned char)'"') {
398
0
      x->state = YXMLS_attr3;
399
0
      x->quote = ch;
400
0
      return YXML_OK;
401
0
    }
402
0
    break;
403
0
  case YXMLS_attr3:
404
0
    if(yxml_isAttValue(ch))
405
0
      return yxml_dataattr(x, ch);
406
0
    if(ch == (unsigned char)'&') {
407
0
      x->state = YXMLS_attr4;
408
0
      return yxml_refstart(x, ch);
409
0
    }
410
0
    if(x->quote == ch) {
411
0
      x->state = YXMLS_elem2;
412
0
      return yxml_attrvalend(x, ch);
413
0
    }
414
0
    break;
415
0
  case YXMLS_attr4:
416
0
    if(yxml_isRef(ch))
417
0
      return yxml_ref(x, ch);
418
0
    if(ch == (unsigned char)'\x3b') {
419
0
      x->state = YXMLS_attr3;
420
0
      return yxml_refattrval(x, ch);
421
0
    }
422
0
    break;
423
0
  case YXMLS_cd0:
424
0
    if(ch == (unsigned char)']') {
425
0
      x->state = YXMLS_cd1;
426
0
      return YXML_OK;
427
0
    }
428
0
    if(yxml_isChar(ch))
429
0
      return yxml_datacontent(x, ch);
430
0
    break;
431
0
  case YXMLS_cd1:
432
0
    if(ch == (unsigned char)']') {
433
0
      x->state = YXMLS_cd2;
434
0
      return YXML_OK;
435
0
    }
436
0
    if(yxml_isChar(ch)) {
437
0
      x->state = YXMLS_cd0;
438
0
      return yxml_datacd1(x, ch);
439
0
    }
440
0
    break;
441
0
  case YXMLS_cd2:
442
0
    if(ch == (unsigned char)']')
443
0
      return yxml_datacontent(x, ch);
444
0
    if(ch == (unsigned char)'>') {
445
0
      x->state = YXMLS_misc2;
446
0
      return YXML_OK;
447
0
    }
448
0
    if(yxml_isChar(ch)) {
449
0
      x->state = YXMLS_cd0;
450
0
      return yxml_datacd2(x, ch);
451
0
    }
452
0
    break;
453
0
  case YXMLS_comment0:
454
0
    if(ch == (unsigned char)'-') {
455
0
      x->state = YXMLS_comment1;
456
0
      return YXML_OK;
457
0
    }
458
0
    break;
459
0
  case YXMLS_comment1:
460
0
    if(ch == (unsigned char)'-') {
461
0
      x->state = YXMLS_comment2;
462
0
      return YXML_OK;
463
0
    }
464
0
    break;
465
0
  case YXMLS_comment2:
466
0
    if(ch == (unsigned char)'-') {
467
0
      x->state = YXMLS_comment3;
468
0
      return YXML_OK;
469
0
    }
470
0
    if(yxml_isChar(ch))
471
0
      return YXML_OK;
472
0
    break;
473
0
  case YXMLS_comment3:
474
0
    if(ch == (unsigned char)'-') {
475
0
      x->state = YXMLS_comment4;
476
0
      return YXML_OK;
477
0
    }
478
0
    if(yxml_isChar(ch)) {
479
0
      x->state = YXMLS_comment2;
480
0
      return YXML_OK;
481
0
    }
482
0
    break;
483
0
  case YXMLS_comment4:
484
0
    if(ch == (unsigned char)'>') {
485
0
      x->state = x->nextstate;
486
0
      return YXML_OK;
487
0
    }
488
0
    break;
489
0
  case YXMLS_dt0:
490
0
    if(ch == (unsigned char)'>') {
491
0
      x->state = YXMLS_misc1;
492
0
      return YXML_OK;
493
0
    }
494
0
    if(ch == (unsigned char)'\'' || ch == (unsigned char)'"') {
495
0
      x->state = YXMLS_dt1;
496
0
      x->quote = ch;
497
0
      x->nextstate = YXMLS_dt0;
498
0
      return YXML_OK;
499
0
    }
500
0
    if(ch == (unsigned char)'<') {
501
0
      x->state = YXMLS_dt2;
502
0
      return YXML_OK;
503
0
    }
504
0
    if(yxml_isChar(ch))
505
0
      return YXML_OK;
506
0
    break;
507
0
  case YXMLS_dt1:
508
0
    if(x->quote == ch) {
509
0
      x->state = x->nextstate;
510
0
      return YXML_OK;
511
0
    }
512
0
    if(yxml_isChar(ch))
513
0
      return YXML_OK;
514
0
    break;
515
0
  case YXMLS_dt2:
516
0
    if(ch == (unsigned char)'?') {
517
0
      x->state = YXMLS_pi0;
518
0
      x->nextstate = YXMLS_dt0;
519
0
      return YXML_OK;
520
0
    }
521
0
    if(ch == (unsigned char)'!') {
522
0
      x->state = YXMLS_dt3;
523
0
      return YXML_OK;
524
0
    }
525
0
    break;
526
0
  case YXMLS_dt3:
527
0
    if(ch == (unsigned char)'-') {
528
0
      x->state = YXMLS_comment1;
529
0
      x->nextstate = YXMLS_dt0;
530
0
      return YXML_OK;
531
0
    }
532
0
    if(yxml_isChar(ch)) {
533
0
      x->state = YXMLS_dt4;
534
0
      return YXML_OK;
535
0
    }
536
0
    break;
537
0
  case YXMLS_dt4:
538
0
    if(ch == (unsigned char)'\'' || ch == (unsigned char)'"') {
539
0
      x->state = YXMLS_dt1;
540
0
      x->quote = ch;
541
0
      x->nextstate = YXMLS_dt4;
542
0
      return YXML_OK;
543
0
    }
544
0
    if(ch == (unsigned char)'>') {
545
0
      x->state = YXMLS_dt0;
546
0
      return YXML_OK;
547
0
    }
548
0
    if(yxml_isChar(ch))
549
0
      return YXML_OK;
550
0
    break;
551
0
  case YXMLS_elem0:
552
0
    if(yxml_isName(ch))
553
0
      return yxml_elemname(x, ch);
554
0
    if(yxml_isSP(ch)) {
555
0
      x->state = YXMLS_elem1;
556
0
      return yxml_elemnameend(x, ch);
557
0
    }
558
0
    if(ch == (unsigned char)'/') {
559
0
      x->state = YXMLS_elem3;
560
0
      return yxml_elemnameend(x, ch);
561
0
    }
562
0
    if(ch == (unsigned char)'>') {
563
0
      x->state = YXMLS_misc2;
564
0
      return yxml_elemnameend(x, ch);
565
0
    }
566
0
    break;
567
0
  case YXMLS_elem1:
568
0
    if(yxml_isSP(ch))
569
0
      return YXML_OK;
570
0
    if(ch == (unsigned char)'/') {
571
0
      x->state = YXMLS_elem3;
572
0
      return YXML_OK;
573
0
    }
574
0
    if(ch == (unsigned char)'>') {
575
0
      x->state = YXMLS_misc2;
576
0
      return YXML_OK;
577
0
    }
578
0
    if(yxml_isNameStart(ch)) {
579
0
      x->state = YXMLS_attr0;
580
0
      return yxml_attrstart(x, ch);
581
0
    }
582
0
    break;
583
0
  case YXMLS_elem2:
584
0
    if(yxml_isSP(ch)) {
585
0
      x->state = YXMLS_elem1;
586
0
      return YXML_OK;
587
0
    }
588
0
    if(ch == (unsigned char)'/') {
589
0
      x->state = YXMLS_elem3;
590
0
      return YXML_OK;
591
0
    }
592
0
    if(ch == (unsigned char)'>') {
593
0
      x->state = YXMLS_misc2;
594
0
      return YXML_OK;
595
0
    }
596
0
    break;
597
0
  case YXMLS_elem3:
598
0
    if(ch == (unsigned char)'>') {
599
0
      x->state = YXMLS_misc2;
600
0
      return yxml_selfclose(x, ch);
601
0
    }
602
0
    break;
603
0
  case YXMLS_enc0:
604
0
    if(yxml_isSP(ch))
605
0
      return YXML_OK;
606
0
    if(ch == (unsigned char)'=') {
607
0
      x->state = YXMLS_enc1;
608
0
      return YXML_OK;
609
0
    }
610
0
    break;
611
0
  case YXMLS_enc1:
612
0
    if(yxml_isSP(ch))
613
0
      return YXML_OK;
614
0
    if(ch == (unsigned char)'\'' || ch == (unsigned char)'"') {
615
0
      x->state = YXMLS_enc2;
616
0
      x->quote = ch;
617
0
      return YXML_OK;
618
0
    }
619
0
    break;
620
0
  case YXMLS_enc2:
621
0
    if(yxml_isAlpha(ch)) {
622
0
      x->state = YXMLS_enc3;
623
0
      return YXML_OK;
624
0
    }
625
0
    break;
626
0
  case YXMLS_enc3:
627
0
    if(yxml_isEncName(ch))
628
0
      return YXML_OK;
629
0
    if(x->quote == ch) {
630
0
      x->state = YXMLS_xmldecl6;
631
0
      return YXML_OK;
632
0
    }
633
0
    break;
634
0
  case YXMLS_etag0:
635
0
    if(yxml_isNameStart(ch)) {
636
0
      x->state = YXMLS_etag1;
637
0
      return yxml_elemclose(x, ch);
638
0
    }
639
0
    break;
640
0
  case YXMLS_etag1:
641
0
    if(yxml_isName(ch))
642
0
      return yxml_elemclose(x, ch);
643
0
    if(yxml_isSP(ch)) {
644
0
      x->state = YXMLS_etag2;
645
0
      return yxml_elemcloseend(x, ch);
646
0
    }
647
0
    if(ch == (unsigned char)'>') {
648
0
      x->state = YXMLS_misc2;
649
0
      return yxml_elemcloseend(x, ch);
650
0
    }
651
0
    break;
652
0
  case YXMLS_etag2:
653
0
    if(yxml_isSP(ch))
654
0
      return YXML_OK;
655
0
    if(ch == (unsigned char)'>') {
656
0
      x->state = YXMLS_misc2;
657
0
      return YXML_OK;
658
0
    }
659
0
    break;
660
0
  case YXMLS_init:
661
0
    if(ch == (unsigned char)'\xef') {
662
0
      x->state = YXMLS_string;
663
0
      x->nextstate = YXMLS_misc0;
664
0
      x->string = (unsigned char *)"\xbb\xbf";
665
0
      return YXML_OK;
666
0
    }
667
0
    if(yxml_isSP(ch)) {
668
0
      x->state = YXMLS_misc0;
669
0
      return YXML_OK;
670
0
    }
671
0
    if(ch == (unsigned char)'<') {
672
0
      x->state = YXMLS_le0;
673
0
      return YXML_OK;
674
0
    }
675
0
    break;
676
0
  case YXMLS_le0:
677
0
    if(ch == (unsigned char)'!') {
678
0
      x->state = YXMLS_lee1;
679
0
      return YXML_OK;
680
0
    }
681
0
    if(ch == (unsigned char)'?') {
682
0
      x->state = YXMLS_leq0;
683
0
      return YXML_OK;
684
0
    }
685
0
    if(yxml_isNameStart(ch)) {
686
0
      x->state = YXMLS_elem0;
687
0
      return yxml_elemstart(x, ch);
688
0
    }
689
0
    break;
690
0
  case YXMLS_le1:
691
0
    if(ch == (unsigned char)'!') {
692
0
      x->state = YXMLS_lee1;
693
0
      return YXML_OK;
694
0
    }
695
0
    if(ch == (unsigned char)'?') {
696
0
      x->state = YXMLS_pi0;
697
0
      x->nextstate = YXMLS_misc1;
698
0
      return YXML_OK;
699
0
    }
700
0
    if(yxml_isNameStart(ch)) {
701
0
      x->state = YXMLS_elem0;
702
0
      return yxml_elemstart(x, ch);
703
0
    }
704
0
    break;
705
0
  case YXMLS_le2:
706
0
    if(ch == (unsigned char)'!') {
707
0
      x->state = YXMLS_lee2;
708
0
      return YXML_OK;
709
0
    }
710
0
    if(ch == (unsigned char)'?') {
711
0
      x->state = YXMLS_pi0;
712
0
      x->nextstate = YXMLS_misc2;
713
0
      return YXML_OK;
714
0
    }
715
0
    if(ch == (unsigned char)'/') {
716
0
      x->state = YXMLS_etag0;
717
0
      return YXML_OK;
718
0
    }
719
0
    if(yxml_isNameStart(ch)) {
720
0
      x->state = YXMLS_elem0;
721
0
      return yxml_elemstart(x, ch);
722
0
    }
723
0
    break;
724
0
  case YXMLS_le3:
725
0
    if(ch == (unsigned char)'!') {
726
0
      x->state = YXMLS_comment0;
727
0
      x->nextstate = YXMLS_misc3;
728
0
      return YXML_OK;
729
0
    }
730
0
    if(ch == (unsigned char)'?') {
731
0
      x->state = YXMLS_pi0;
732
0
      x->nextstate = YXMLS_misc3;
733
0
      return YXML_OK;
734
0
    }
735
0
    break;
736
0
  case YXMLS_lee1:
737
0
    if(ch == (unsigned char)'-') {
738
0
      x->state = YXMLS_comment1;
739
0
      x->nextstate = YXMLS_misc1;
740
0
      return YXML_OK;
741
0
    }
742
0
    if(ch == (unsigned char)'D') {
743
0
      x->state = YXMLS_string;
744
0
      x->nextstate = YXMLS_dt0;
745
0
      x->string = (unsigned char *)"OCTYPE";
746
0
      return YXML_OK;
747
0
    }
748
0
    break;
749
0
  case YXMLS_lee2:
750
0
    if(ch == (unsigned char)'-') {
751
0
      x->state = YXMLS_comment1;
752
0
      x->nextstate = YXMLS_misc2;
753
0
      return YXML_OK;
754
0
    }
755
0
    if(ch == (unsigned char)'[') {
756
0
      x->state = YXMLS_string;
757
0
      x->nextstate = YXMLS_cd0;
758
0
      x->string = (unsigned char *)"CDATA[";
759
0
      return YXML_OK;
760
0
    }
761
0
    break;
762
0
  case YXMLS_leq0:
763
0
    if(ch == (unsigned char)'x') {
764
0
      x->state = YXMLS_xmldecl0;
765
0
      x->nextstate = YXMLS_misc1;
766
0
      return yxml_pistart(x, ch);
767
0
    }
768
0
    if(yxml_isNameStart(ch)) {
769
0
      x->state = YXMLS_pi1;
770
0
      x->nextstate = YXMLS_misc1;
771
0
      return yxml_pistart(x, ch);
772
0
    }
773
0
    break;
774
0
  case YXMLS_misc0:
775
0
    if(yxml_isSP(ch))
776
0
      return YXML_OK;
777
0
    if(ch == (unsigned char)'<') {
778
0
      x->state = YXMLS_le0;
779
0
      return YXML_OK;
780
0
    }
781
0
    break;
782
0
  case YXMLS_misc1:
783
0
    if(yxml_isSP(ch))
784
0
      return YXML_OK;
785
0
    if(ch == (unsigned char)'<') {
786
0
      x->state = YXMLS_le1;
787
0
      return YXML_OK;
788
0
    }
789
0
    break;
790
0
  case YXMLS_misc2:
791
0
    if(ch == (unsigned char)'<') {
792
0
      x->state = YXMLS_le2;
793
0
      return YXML_OK;
794
0
    }
795
0
    if(ch == (unsigned char)'&') {
796
0
      x->state = YXMLS_misc2a;
797
0
      return yxml_refstart(x, ch);
798
0
    }
799
0
    if(yxml_isChar(ch))
800
0
      return yxml_datacontent(x, ch);
801
0
    break;
802
0
  case YXMLS_misc2a:
803
0
    if(yxml_isRef(ch))
804
0
      return yxml_ref(x, ch);
805
0
    if(ch == (unsigned char)'\x3b') {
806
0
      x->state = YXMLS_misc2;
807
0
      return yxml_refcontent(x, ch);
808
0
    }
809
0
    break;
810
0
  case YXMLS_misc3:
811
0
    if(yxml_isSP(ch))
812
0
      return YXML_OK;
813
0
    if(ch == (unsigned char)'<') {
814
0
      x->state = YXMLS_le3;
815
0
      return YXML_OK;
816
0
    }
817
0
    break;
818
0
  case YXMLS_pi0:
819
0
    if(yxml_isNameStart(ch)) {
820
0
      x->state = YXMLS_pi1;
821
0
      return yxml_pistart(x, ch);
822
0
    }
823
0
    break;
824
0
  case YXMLS_pi1:
825
0
    if(yxml_isName(ch))
826
0
      return yxml_piname(x, ch);
827
0
    if(ch == (unsigned char)'?') {
828
0
      x->state = YXMLS_pi4;
829
0
      return yxml_pinameend(x, ch);
830
0
    }
831
0
    if(yxml_isSP(ch)) {
832
0
      x->state = YXMLS_pi2;
833
0
      return yxml_pinameend(x, ch);
834
0
    }
835
0
    break;
836
0
  case YXMLS_pi2:
837
0
    if(ch == (unsigned char)'?') {
838
0
      x->state = YXMLS_pi3;
839
0
      return YXML_OK;
840
0
    }
841
0
    if(yxml_isChar(ch))
842
0
      return yxml_datapi1(x, ch);
843
0
    break;
844
0
  case YXMLS_pi3:
845
0
    if(ch == (unsigned char)'>') {
846
0
      x->state = x->nextstate;
847
0
      return yxml_pivalend(x, ch);
848
0
    }
849
0
    if(yxml_isChar(ch)) {
850
0
      x->state = YXMLS_pi2;
851
0
      return yxml_datapi2(x, ch);
852
0
    }
853
0
    break;
854
0
  case YXMLS_pi4:
855
0
    if(ch == (unsigned char)'>') {
856
0
      x->state = x->nextstate;
857
0
      return yxml_pivalend(x, ch);
858
0
    }
859
0
    break;
860
0
  case YXMLS_std0:
861
0
    if(yxml_isSP(ch))
862
0
      return YXML_OK;
863
0
    if(ch == (unsigned char)'=') {
864
0
      x->state = YXMLS_std1;
865
0
      return YXML_OK;
866
0
    }
867
0
    break;
868
0
  case YXMLS_std1:
869
0
    if(yxml_isSP(ch))
870
0
      return YXML_OK;
871
0
    if(ch == (unsigned char)'\'' || ch == (unsigned char)'"') {
872
0
      x->state = YXMLS_std2;
873
0
      x->quote = ch;
874
0
      return YXML_OK;
875
0
    }
876
0
    break;
877
0
  case YXMLS_std2:
878
0
    if(ch == (unsigned char)'y') {
879
0
      x->state = YXMLS_string;
880
0
      x->nextstate = YXMLS_std3;
881
0
      x->string = (unsigned char *)"es";
882
0
      return YXML_OK;
883
0
    }
884
0
    if(ch == (unsigned char)'n') {
885
0
      x->state = YXMLS_string;
886
0
      x->nextstate = YXMLS_std3;
887
0
      x->string = (unsigned char *)"o";
888
0
      return YXML_OK;
889
0
    }
890
0
    break;
891
0
  case YXMLS_std3:
892
0
    if(x->quote == ch) {
893
0
      x->state = YXMLS_xmldecl8;
894
0
      return YXML_OK;
895
0
    }
896
0
    break;
897
0
  case YXMLS_ver0:
898
0
    if(yxml_isSP(ch))
899
0
      return YXML_OK;
900
0
    if(ch == (unsigned char)'=') {
901
0
      x->state = YXMLS_ver1;
902
0
      return YXML_OK;
903
0
    }
904
0
    break;
905
0
  case YXMLS_ver1:
906
0
    if(yxml_isSP(ch))
907
0
      return YXML_OK;
908
0
    if(ch == (unsigned char)'\'' || ch == (unsigned char)'"') {
909
0
      x->state = YXMLS_string;
910
0
      x->quote = ch;
911
0
      x->nextstate = YXMLS_ver2;
912
0
      x->string = (unsigned char *)"1.";
913
0
      return YXML_OK;
914
0
    }
915
0
    break;
916
0
  case YXMLS_ver2:
917
0
    if(yxml_isNum(ch)) {
918
0
      x->state = YXMLS_ver3;
919
0
      return YXML_OK;
920
0
    }
921
0
    break;
922
0
  case YXMLS_ver3:
923
0
    if(yxml_isNum(ch))
924
0
      return YXML_OK;
925
0
    if(x->quote == ch) {
926
0
      x->state = YXMLS_xmldecl4;
927
0
      return YXML_OK;
928
0
    }
929
0
    break;
930
0
  case YXMLS_xmldecl0:
931
0
    if(ch == (unsigned char)'m') {
932
0
      x->state = YXMLS_xmldecl1;
933
0
      return yxml_piname(x, ch);
934
0
    }
935
0
    if(yxml_isName(ch)) {
936
0
      x->state = YXMLS_pi1;
937
0
      return yxml_piname(x, ch);
938
0
    }
939
0
    if(ch == (unsigned char)'?') {
940
0
      x->state = YXMLS_pi4;
941
0
      return yxml_pinameend(x, ch);
942
0
    }
943
0
    if(yxml_isSP(ch)) {
944
0
      x->state = YXMLS_pi2;
945
0
      return yxml_pinameend(x, ch);
946
0
    }
947
0
    break;
948
0
  case YXMLS_xmldecl1:
949
0
    if(ch == (unsigned char)'l') {
950
0
      x->state = YXMLS_xmldecl2;
951
0
      return yxml_piname(x, ch);
952
0
    }
953
0
    if(yxml_isName(ch)) {
954
0
      x->state = YXMLS_pi1;
955
0
      return yxml_piname(x, ch);
956
0
    }
957
0
    if(ch == (unsigned char)'?') {
958
0
      x->state = YXMLS_pi4;
959
0
      return yxml_pinameend(x, ch);
960
0
    }
961
0
    if(yxml_isSP(ch)) {
962
0
      x->state = YXMLS_pi2;
963
0
      return yxml_pinameend(x, ch);
964
0
    }
965
0
    break;
966
0
  case YXMLS_xmldecl2:
967
0
    if(yxml_isSP(ch)) {
968
0
      x->state = YXMLS_xmldecl3;
969
0
      return yxml_piabort(x, ch);
970
0
    }
971
0
    if(yxml_isName(ch)) {
972
0
      x->state = YXMLS_pi1;
973
0
      return yxml_piname(x, ch);
974
0
    }
975
0
    break;
976
0
  case YXMLS_xmldecl3:
977
0
    if(yxml_isSP(ch))
978
0
      return YXML_OK;
979
0
    if(ch == (unsigned char)'v') {
980
0
      x->state = YXMLS_string;
981
0
      x->nextstate = YXMLS_ver0;
982
0
      x->string = (unsigned char *)"ersion";
983
0
      return YXML_OK;
984
0
    }
985
0
    break;
986
0
  case YXMLS_xmldecl4:
987
0
    if(yxml_isSP(ch)) {
988
0
      x->state = YXMLS_xmldecl5;
989
0
      return YXML_OK;
990
0
    }
991
0
    if(ch == (unsigned char)'?') {
992
0
      x->state = YXMLS_xmldecl9;
993
0
      return YXML_OK;
994
0
    }
995
0
    break;
996
0
  case YXMLS_xmldecl5:
997
0
    if(yxml_isSP(ch))
998
0
      return YXML_OK;
999
0
    if(ch == (unsigned char)'?') {
1000
0
      x->state = YXMLS_xmldecl9;
1001
0
      return YXML_OK;
1002
0
    }
1003
0
    if(ch == (unsigned char)'e') {
1004
0
      x->state = YXMLS_string;
1005
0
      x->nextstate = YXMLS_enc0;
1006
0
      x->string = (unsigned char *)"ncoding";
1007
0
      return YXML_OK;
1008
0
    }
1009
0
    if(ch == (unsigned char)'s') {
1010
0
      x->state = YXMLS_string;
1011
0
      x->nextstate = YXMLS_std0;
1012
0
      x->string = (unsigned char *)"tandalone";
1013
0
      return YXML_OK;
1014
0
    }
1015
0
    break;
1016
0
  case YXMLS_xmldecl6:
1017
0
    if(yxml_isSP(ch)) {
1018
0
      x->state = YXMLS_xmldecl7;
1019
0
      return YXML_OK;
1020
0
    }
1021
0
    if(ch == (unsigned char)'?') {
1022
0
      x->state = YXMLS_xmldecl9;
1023
0
      return YXML_OK;
1024
0
    }
1025
0
    break;
1026
0
  case YXMLS_xmldecl7:
1027
0
    if(yxml_isSP(ch))
1028
0
      return YXML_OK;
1029
0
    if(ch == (unsigned char)'?') {
1030
0
      x->state = YXMLS_xmldecl9;
1031
0
      return YXML_OK;
1032
0
    }
1033
0
    if(ch == (unsigned char)'s') {
1034
0
      x->state = YXMLS_string;
1035
0
      x->nextstate = YXMLS_std0;
1036
0
      x->string = (unsigned char *)"tandalone";
1037
0
      return YXML_OK;
1038
0
    }
1039
0
    break;
1040
0
  case YXMLS_xmldecl8:
1041
0
    if(yxml_isSP(ch))
1042
0
      return YXML_OK;
1043
0
    if(ch == (unsigned char)'?') {
1044
0
      x->state = YXMLS_xmldecl9;
1045
0
      return YXML_OK;
1046
0
    }
1047
0
    break;
1048
0
  case YXMLS_xmldecl9:
1049
0
    if(ch == (unsigned char)'>') {
1050
0
      x->state = YXMLS_misc1;
1051
0
      return YXML_OK;
1052
0
    }
1053
0
    break;
1054
0
  }
1055
0
  return YXML_ESYN;
1056
0
}
1057
1058
1059
0
yxml_ret_t yxml_eof(yxml_t *x) {
1060
0
  if(x->state != YXMLS_misc3)
1061
0
    return YXML_EEOF;
1062
0
  return YXML_OK;
1063
0
}
1064
1065
1066
/* vim: set noet sw=4 ts=4: */