Coverage Report

Created: 2025-12-04 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxml2/SAX2.c
Line
Count
Source
1
/*
2
 * SAX2.c : Default SAX2 handler to build a tree.
3
 *
4
 * See Copyright for the status of this software.
5
 *
6
 * Author: Daniel Veillard
7
 */
8
9
10
#define IN_LIBXML
11
#include "libxml.h"
12
#include <stdlib.h>
13
#include <string.h>
14
#include <limits.h>
15
#include <stddef.h>
16
#include <libxml/SAX2.h>
17
#include <libxml/xmlmemory.h>
18
#include <libxml/tree.h>
19
#include <libxml/parser.h>
20
#include <libxml/parserInternals.h>
21
#include <libxml/valid.h>
22
#include <libxml/entities.h>
23
#include <libxml/xmlerror.h>
24
#include <libxml/xmlIO.h>
25
#include <libxml/uri.h>
26
#include <libxml/valid.h>
27
#include <libxml/HTMLtree.h>
28
29
#include "private/error.h"
30
#include "private/parser.h"
31
#include "private/tree.h"
32
33
#ifndef SIZE_MAX
34
  #define SIZE_MAX ((size_t) -1)
35
#endif
36
37
/*
38
 * @param ctxt  an XML validation parser context
39
 * @param msg  a string to accompany the error message
40
 */
41
static void
42
798
xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt) {
43
798
    xmlCtxtErrMemory(ctxt);
44
798
}
45
46
#ifdef LIBXML_VALID_ENABLED
47
/**
48
 * Handle a validation error
49
 *
50
 * @param ctxt  an XML validation parser context
51
 * @param error  the error number
52
 * @param msg  the error message
53
 * @param str1  extra data
54
 * @param str2  extra data
55
 */
56
static void LIBXML_ATTR_FORMAT(3,0)
57
xmlErrValid(xmlParserCtxtPtr ctxt, xmlParserErrors error,
58
            const char *msg, const xmlChar *str1, const xmlChar *str2)
59
11.4k
{
60
11.4k
    xmlCtxtErr(ctxt, NULL, XML_FROM_DTD, error, XML_ERR_ERROR,
61
11.4k
               str1, str2, NULL, 0, msg, str1, str2);
62
11.4k
    if (ctxt != NULL)
63
11.4k
  ctxt->valid = 0;
64
11.4k
}
65
#endif /* LIBXML_VALID_ENABLED */
66
67
/**
68
 * Handle a fatal parser error, i.e. violating Well-Formedness constraints
69
 *
70
 * @param ctxt  an XML parser context
71
 * @param error  the error number
72
 * @param msg  the error message
73
 * @param str1  an error string
74
 * @param str2  an error string
75
 */
76
static void LIBXML_ATTR_FORMAT(3,0)
77
xmlFatalErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
78
               const char *msg, const xmlChar *str1, const xmlChar *str2)
79
485
{
80
485
    xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
81
485
               str1, str2, NULL, 0, msg, str1, str2);
82
485
}
83
84
/**
85
 * Handle an xml:id error
86
 *
87
 * @param ctxt  an XML validation parser context
88
 * @param error  the error number
89
 * @param msg  the error message
90
 * @param str1  extra data
91
 */
92
static void LIBXML_ATTR_FORMAT(3,0)
93
xmlErrId(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *msg,
94
         const xmlChar *str1)
95
2.02k
{
96
2.02k
    xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_ERROR,
97
2.02k
               str1, NULL, NULL, 0, msg, str1);
98
2.02k
}
99
100
/**
101
 * Handle a parser warning
102
 *
103
 * @param ctxt  an XML parser context
104
 * @param error  the error number
105
 * @param msg  the error message
106
 * @param str1  an error string
107
 */
108
static void LIBXML_ATTR_FORMAT(3,0)
109
xmlWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
110
               const char *msg, const xmlChar *str1)
111
15.2k
{
112
15.2k
    xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_WARNING,
113
15.2k
               str1, NULL, NULL, 0, msg, str1);
114
15.2k
}
115
116
/**
117
 * Handle a namespace warning
118
 *
119
 * @param ctxt  an XML parser context
120
 * @param error  the error number
121
 * @param msg  the error message
122
 * @param str1  an error string
123
 * @param str2  an error string
124
 */
125
static void LIBXML_ATTR_FORMAT(3,0)
126
xmlNsWarnMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
127
             const char *msg, const xmlChar *str1, const xmlChar *str2)
128
42.5k
{
129
42.5k
    xmlCtxtErr(ctxt, NULL, XML_FROM_NAMESPACE, error, XML_ERR_WARNING,
130
42.5k
               str1, str2, NULL, 0, msg, str1, str2);
131
42.5k
}
132
133
/**
134
 * Provides the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN"
135
 *
136
 * @param ctx  the user data (XML parser context)
137
 * @returns a xmlChar *
138
 */
139
const xmlChar *
140
xmlSAX2GetPublicId(void *ctx ATTRIBUTE_UNUSED)
141
0
{
142
    /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */
143
0
    return(NULL);
144
0
}
145
146
/**
147
 * Provides the system ID, basically URL or filename e.g.
148
 * http://www.sgmlsource.com/dtds/memo.dtd
149
 *
150
 * @param ctx  the user data (XML parser context)
151
 * @returns a xmlChar *
152
 */
153
const xmlChar *
154
xmlSAX2GetSystemId(void *ctx)
155
0
{
156
0
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
157
0
    if ((ctx == NULL) || (ctxt->input == NULL)) return(NULL);
158
0
    return((const xmlChar *) ctxt->input->filename);
159
0
}
160
161
/**
162
 * Provide the line number of the current parsing point.
163
 *
164
 * @param ctx  the user data (XML parser context)
165
 * @returns an int
166
 */
167
int
168
xmlSAX2GetLineNumber(void *ctx)
169
0
{
170
0
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
171
0
    if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
172
0
    return(ctxt->input->line);
173
0
}
174
175
/**
176
 * Provide the column number of the current parsing point.
177
 *
178
 * @param ctx  the user data (XML parser context)
179
 * @returns an int
180
 */
181
int
182
xmlSAX2GetColumnNumber(void *ctx)
183
0
{
184
0
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
185
0
    if ((ctx == NULL) || (ctxt->input == NULL)) return(0);
186
0
    return(ctxt->input->col);
187
0
}
188
189
/**
190
 * Is this document tagged standalone ?
191
 *
192
 * @param ctx  the user data (XML parser context)
193
 * @returns 1 if true
194
 */
195
int
196
xmlSAX2IsStandalone(void *ctx)
197
0
{
198
0
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
199
0
    if ((ctx == NULL) || (ctxt->myDoc == NULL)) return(0);
200
0
    return(ctxt->myDoc->standalone == 1);
201
0
}
202
203
/**
204
 * Does this document has an internal subset
205
 *
206
 * @param ctx  the user data (XML parser context)
207
 * @returns 1 if true
208
 */
209
int
210
xmlSAX2HasInternalSubset(void *ctx)
211
0
{
212
0
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
213
0
    if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0);
214
0
    return(ctxt->myDoc->intSubset != NULL);
215
0
}
216
217
/**
218
 * Does this document has an external subset
219
 *
220
 * @param ctx  the user data (XML parser context)
221
 * @returns 1 if true
222
 */
223
int
224
xmlSAX2HasExternalSubset(void *ctx)
225
0
{
226
0
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
227
0
    if ((ctxt == NULL) || (ctxt->myDoc == NULL)) return(0);
228
0
    return(ctxt->myDoc->extSubset != NULL);
229
0
}
230
231
/**
232
 * Callback on internal subset declaration.
233
 *
234
 * @param ctx  the user data (XML parser context)
235
 * @param name  the root element name
236
 * @param publicId  public identifier of the DTD (optional)
237
 * @param systemId  system identifier (URL) of the DTD
238
 */
239
void
240
xmlSAX2InternalSubset(void *ctx, const xmlChar *name,
241
         const xmlChar *publicId, const xmlChar *systemId)
242
20.0k
{
243
20.0k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
244
20.0k
    xmlDtdPtr dtd;
245
20.0k
    if (ctx == NULL) return;
246
247
20.0k
    if (ctxt->myDoc == NULL)
248
0
  return;
249
20.0k
    if ((ctxt->html) && (ctxt->instate != XML_PARSER_MISC))
250
0
        return;
251
20.0k
    dtd = xmlGetIntSubset(ctxt->myDoc);
252
20.0k
    if (dtd != NULL) {
253
0
  xmlUnlinkNode((xmlNodePtr) dtd);
254
0
  xmlFreeDtd(dtd);
255
0
  ctxt->myDoc->intSubset = NULL;
256
0
    }
257
20.0k
    ctxt->myDoc->intSubset =
258
20.0k
  xmlCreateIntSubset(ctxt->myDoc, name, publicId, systemId);
259
20.0k
    if (ctxt->myDoc->intSubset == NULL)
260
6
        xmlSAX2ErrMemory(ctxt);
261
20.0k
}
262
263
/**
264
 * Callback on external subset declaration.
265
 *
266
 * @param ctx  the user data (XML parser context)
267
 * @param name  the root element name
268
 * @param publicId  public identifier of the DTD (optional)
269
 * @param systemId  system identifier (URL) of the DTD
270
 */
271
void
272
xmlSAX2ExternalSubset(void *ctx, const xmlChar *name,
273
         const xmlChar *publicId, const xmlChar *systemId)
274
17.4k
{
275
17.4k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
276
17.4k
    if (ctx == NULL) return;
277
17.4k
    if ((systemId != NULL) &&
278
2.70k
        ((ctxt->options & XML_PARSE_NO_XXE) == 0) &&
279
2.46k
        (((ctxt->validate) || (ctxt->loadsubset & ~XML_SKIP_IDS)) &&
280
2.25k
   (ctxt->wellFormed && ctxt->myDoc))) {
281
  /*
282
   * Try to fetch and parse the external subset.
283
   */
284
2.19k
  xmlParserInputPtr oldinput;
285
2.19k
  int oldinputNr;
286
2.19k
  int oldinputMax;
287
2.19k
  xmlParserInputPtr *oldinputTab;
288
2.19k
  xmlParserInputPtr input = NULL;
289
2.19k
  xmlChar *oldencoding;
290
2.19k
        unsigned long consumed;
291
2.19k
        size_t buffered;
292
2.19k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
293
2.19k
        int inputMax = 1;
294
#else
295
        int inputMax = 5;
296
#endif
297
298
  /*
299
   * Ask the Entity resolver to load the damn thing
300
   */
301
2.19k
  if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
302
2.19k
      input = ctxt->sax->resolveEntity(ctxt->userData, publicId,
303
2.19k
                                       systemId);
304
2.19k
  if (input == NULL) {
305
614
      return;
306
614
  }
307
308
1.57k
  if (xmlNewDtd(ctxt->myDoc, name, publicId, systemId) == NULL) {
309
4
            xmlSAX2ErrMemory(ctxt);
310
4
            xmlFreeInputStream(input);
311
4
            return;
312
4
        }
313
314
  /*
315
   * make sure we won't destroy the main document context
316
   */
317
1.57k
  oldinput = ctxt->input;
318
1.57k
  oldinputNr = ctxt->inputNr;
319
1.57k
  oldinputMax = ctxt->inputMax;
320
1.57k
  oldinputTab = ctxt->inputTab;
321
1.57k
  oldencoding = ctxt->encoding;
322
1.57k
  ctxt->encoding = NULL;
323
324
1.57k
  ctxt->inputTab = xmlMalloc(inputMax * sizeof(xmlParserInputPtr));
325
1.57k
  if (ctxt->inputTab == NULL) {
326
1
      xmlSAX2ErrMemory(ctxt);
327
1
            goto error;
328
1
  }
329
1.57k
  ctxt->inputNr = 0;
330
1.57k
  ctxt->inputMax = inputMax;
331
1.57k
  ctxt->input = NULL;
332
1.57k
  if (xmlCtxtPushInput(ctxt, input) < 0)
333
1
            goto error;
334
335
1.57k
  if (input->filename == NULL)
336
0
      input->filename = (char *) xmlCanonicPath(systemId);
337
1.57k
  input->line = 1;
338
1.57k
  input->col = 1;
339
1.57k
  input->base = ctxt->input->cur;
340
1.57k
  input->cur = ctxt->input->cur;
341
1.57k
  input->free = NULL;
342
343
  /*
344
   * let's parse that entity knowing it's an external subset.
345
   */
346
1.57k
  xmlParseExternalSubset(ctxt, publicId, systemId);
347
348
        /*
349
   * Free up the external entities
350
   */
351
352
1.64k
  while (ctxt->inputNr > 1)
353
70
      xmlFreeInputStream(xmlCtxtPopInput(ctxt));
354
355
1.57k
        consumed = ctxt->input->consumed;
356
1.57k
        buffered = ctxt->input->cur - ctxt->input->base;
357
1.57k
        if (buffered > ULONG_MAX - consumed)
358
0
            consumed = ULONG_MAX;
359
1.57k
        else
360
1.57k
            consumed += buffered;
361
1.57k
        if (consumed > ULONG_MAX - ctxt->sizeentities)
362
0
            ctxt->sizeentities = ULONG_MAX;
363
1.57k
        else
364
1.57k
            ctxt->sizeentities += consumed;
365
366
1.57k
error:
367
1.57k
  xmlFreeInputStream(input);
368
1.57k
        xmlFree(ctxt->inputTab);
369
370
  /*
371
   * Restore the parsing context of the main entity
372
   */
373
1.57k
  ctxt->input = oldinput;
374
1.57k
  ctxt->inputNr = oldinputNr;
375
1.57k
  ctxt->inputMax = oldinputMax;
376
1.57k
  ctxt->inputTab = oldinputTab;
377
1.57k
  if (ctxt->encoding != NULL)
378
66
      xmlFree(ctxt->encoding);
379
1.57k
  ctxt->encoding = oldencoding;
380
  /* ctxt->wellFormed = oldwellFormed; */
381
1.57k
    }
382
17.4k
}
383
384
/**
385
 * This is only used to load DTDs. The preferred way to install
386
 * custom resolvers is #xmlCtxtSetResourceLoader.
387
 *
388
 * @param ctx  the user data (XML parser context)
389
 * @param publicId  The public ID of the entity
390
 * @param systemId  The system ID (URL) of the entity
391
 * @returns a parser input.
392
 */
393
xmlParserInput *
394
xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId,
395
                     const xmlChar *systemId)
396
2.19k
{
397
2.19k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
398
2.19k
    xmlParserInputPtr ret = NULL;
399
2.19k
    xmlChar *URI = NULL;
400
401
2.19k
    if (ctx == NULL) return(NULL);
402
403
2.19k
    if (systemId != NULL) {
404
2.19k
        const xmlChar *base = NULL;
405
2.19k
        int res;
406
407
2.19k
        if (ctxt->input != NULL)
408
2.19k
            base = BAD_CAST ctxt->input->filename;
409
410
        /*
411
         * We don't really need the 'directory' struct member, but some
412
         * users set it manually to a base URI for memory streams.
413
         */
414
2.19k
        if (base == NULL)
415
2.06k
            base = BAD_CAST ctxt->directory;
416
417
2.19k
        if ((xmlStrlen(systemId) > XML_MAX_URI_LENGTH) ||
418
2.18k
            (xmlStrlen(base) > XML_MAX_URI_LENGTH)) {
419
3
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
420
3
            return(NULL);
421
3
        }
422
2.18k
        res = xmlBuildURISafe(systemId, base, &URI);
423
2.18k
        if (URI == NULL) {
424
9
            if (res < 0)
425
3
                xmlSAX2ErrMemory(ctxt);
426
6
            else
427
6
                xmlWarnMsg(ctxt, XML_ERR_INVALID_URI,
428
6
                           "Can't resolve URI: %s\n", systemId);
429
9
            return(NULL);
430
9
        }
431
2.17k
        if (xmlStrlen(URI) > XML_MAX_URI_LENGTH) {
432
0
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
433
0
            xmlFree(URI);
434
0
            return(NULL);
435
0
        }
436
2.17k
    }
437
438
2.17k
    ret = xmlLoadResource(ctxt, (const char *) URI,
439
2.17k
                          (const char *) publicId, XML_RESOURCE_DTD);
440
441
2.17k
    xmlFree(URI);
442
2.17k
    return(ret);
443
2.19k
}
444
445
/**
446
 * Get an entity by name
447
 *
448
 * @param ctx  the user data (XML parser context)
449
 * @param name  The entity name
450
 * @returns the xmlEntity if found.
451
 */
452
xmlEntity *
453
xmlSAX2GetEntity(void *ctx, const xmlChar *name)
454
4.50M
{
455
4.50M
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
456
4.50M
    xmlEntityPtr ret = NULL;
457
458
4.50M
    if (ctx == NULL) return(NULL);
459
460
4.50M
    if (ctxt->inSubset == 0) {
461
3.78M
  ret = xmlGetPredefinedEntity(name);
462
3.78M
  if (ret != NULL)
463
913k
      return(ret);
464
3.78M
    }
465
3.59M
    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->standalone == 1)) {
466
1.19k
  if (ctxt->inSubset == 2) {
467
215
      ctxt->myDoc->standalone = 0;
468
215
      ret = xmlGetDocEntity(ctxt->myDoc, name);
469
215
      ctxt->myDoc->standalone = 1;
470
977
  } else {
471
977
      ret = xmlGetDocEntity(ctxt->myDoc, name);
472
977
      if (ret == NULL) {
473
649
    ctxt->myDoc->standalone = 0;
474
649
    ret = xmlGetDocEntity(ctxt->myDoc, name);
475
649
    if (ret != NULL) {
476
241
        xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE,
477
241
   "Entity(%s) document marked standalone but requires external subset\n",
478
241
           name, NULL);
479
241
    }
480
649
    ctxt->myDoc->standalone = 1;
481
649
      }
482
977
  }
483
3.59M
    } else {
484
3.59M
  ret = xmlGetDocEntity(ctxt->myDoc, name);
485
3.59M
    }
486
3.59M
    return(ret);
487
4.50M
}
488
489
/**
490
 * Get a parameter entity by name
491
 *
492
 * @param ctx  the user data (XML parser context)
493
 * @param name  The entity name
494
 * @returns the xmlEntity if found.
495
 */
496
xmlEntity *
497
xmlSAX2GetParameterEntity(void *ctx, const xmlChar *name)
498
493k
{
499
493k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
500
493k
    xmlEntityPtr ret;
501
502
493k
    if (ctx == NULL) return(NULL);
503
504
493k
    ret = xmlGetParameterEntity(ctxt->myDoc, name);
505
493k
    return(ret);
506
493k
}
507
508
509
/**
510
 * An entity definition has been parsed
511
 *
512
 * @param ctx  the user data (XML parser context)
513
 * @param name  the entity name
514
 * @param type  the entity type
515
 * @param publicId  The public ID of the entity
516
 * @param systemId  The system ID of the entity
517
 * @param content  the entity value (without processing).
518
 */
519
void
520
xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
521
          const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
522
155k
{
523
155k
    xmlEntityPtr ent;
524
155k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
525
155k
    int extSubset;
526
155k
    int res;
527
528
155k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
529
0
        return;
530
531
155k
    extSubset = ctxt->inSubset == 2;
532
155k
    res = xmlAddEntity(ctxt->myDoc, extSubset, name, type, publicId, systemId,
533
155k
                       content, &ent);
534
155k
    switch (res) {
535
21.5k
        case XML_ERR_OK:
536
21.5k
            break;
537
38
        case XML_ERR_NO_MEMORY:
538
38
            xmlSAX2ErrMemory(ctxt);
539
38
            return;
540
131k
        case XML_WAR_ENTITY_REDEFINED:
541
131k
            if (ctxt->pedantic) {
542
12.4k
                if (extSubset)
543
1.37k
                    xmlWarnMsg(ctxt, res, "Entity(%s) already defined in the"
544
1.37k
                               " external subset\n", name);
545
11.0k
                else
546
11.0k
                    xmlWarnMsg(ctxt, res, "Entity(%s) already defined in the"
547
11.0k
                               " internal subset\n", name);
548
12.4k
            }
549
131k
            return;
550
2.64k
        case XML_ERR_REDECL_PREDEF_ENTITY:
551
            /*
552
             * Technically an error but it's a common mistake to get double
553
             * escaping according to "4.6 Predefined Entities" wrong.
554
             */
555
2.64k
            xmlWarnMsg(ctxt, res, "Invalid redeclaration of predefined"
556
2.64k
                       " entity '%s'", name);
557
2.64k
            return;
558
0
        default:
559
0
            xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
560
0
                           "Unexpected error code from xmlAddEntity\n",
561
0
                           NULL, NULL);
562
0
            return;
563
155k
    }
564
565
21.5k
    if ((ent->URI == NULL) && (systemId != NULL)) {
566
7.45k
        xmlChar *URI;
567
7.45k
        const char *base = NULL;
568
7.45k
        int i;
569
570
14.4k
        for (i = ctxt->inputNr - 1; i >= 0; i--) {
571
7.52k
            if (ctxt->inputTab[i]->filename != NULL) {
572
547
                base = ctxt->inputTab[i]->filename;
573
547
                break;
574
547
            }
575
7.52k
        }
576
577
        /*
578
         * We don't really need the 'directory' struct member, but some
579
         * users set it manually to a base URI for memory streams.
580
         */
581
7.45k
        if (base == NULL)
582
6.91k
            base = ctxt->directory;
583
584
7.45k
        res = xmlBuildURISafe(systemId, (const xmlChar *) base, &URI);
585
586
7.45k
        if (URI == NULL) {
587
109
            if (res < 0) {
588
2
                xmlSAX2ErrMemory(ctxt);
589
107
            } else {
590
107
                xmlWarnMsg(ctxt, XML_ERR_INVALID_URI,
591
107
                           "Can't resolve URI: %s\n", systemId);
592
107
            }
593
7.35k
        } else if (xmlStrlen(URI) > XML_MAX_URI_LENGTH) {
594
3
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
595
3
            xmlFree(URI);
596
7.34k
        } else {
597
7.34k
            ent->URI = URI;
598
7.34k
        }
599
7.45k
    }
600
21.5k
}
601
602
/**
603
 * An attribute definition has been parsed
604
 *
605
 * @param ctx  the user data (XML parser context)
606
 * @param elem  the name of the element
607
 * @param fullname  the attribute name
608
 * @param type  the attribute type
609
 * @param def  the type of default value
610
 * @param defaultValue  the attribute default value
611
 * @param tree  the tree of enumerated value set
612
 */
613
void
614
xmlSAX2AttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname,
615
              int type, int def, const xmlChar *defaultValue,
616
        xmlEnumeration *tree)
617
63.7k
{
618
63.7k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
619
63.7k
    xmlAttributePtr attr;
620
63.7k
    const xmlChar *name = NULL;
621
63.7k
    xmlChar *prefix = NULL;
622
623
    /* Avoid unused variable warning if features are disabled. */
624
63.7k
    (void) attr;
625
626
63.7k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
627
0
        return;
628
629
63.7k
    if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) &&
630
519
        (type != XML_ATTRIBUTE_ID)) {
631
144
  xmlErrId(ctxt, XML_DTD_XMLID_TYPE,
632
144
        "xml:id : attribute type should be ID\n", NULL);
633
144
    }
634
63.7k
    name = xmlSplitQName4(fullname, &prefix);
635
63.7k
    if (name == NULL)
636
9
        xmlSAX2ErrMemory(ctxt);
637
63.7k
    ctxt->vctxt.valid = 1;
638
63.7k
    if (ctxt->inSubset == 1)
639
39.7k
  attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,
640
39.7k
         name, prefix, (xmlAttributeType) type,
641
39.7k
         (xmlAttributeDefault) def, defaultValue, tree);
642
24.0k
    else if (ctxt->inSubset == 2)
643
24.0k
  attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,
644
24.0k
     name, prefix, (xmlAttributeType) type,
645
24.0k
     (xmlAttributeDefault) def, defaultValue, tree);
646
0
    else {
647
0
        xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
648
0
       "SAX.xmlSAX2AttributeDecl(%s) called while not in subset\n",
649
0
                 name, NULL);
650
0
  xmlFree(prefix);
651
0
  xmlFreeEnumeration(tree);
652
0
  return;
653
0
    }
654
63.7k
#ifdef LIBXML_VALID_ENABLED
655
63.7k
    if (ctxt->vctxt.valid == 0)
656
8.86k
  ctxt->valid = 0;
657
63.7k
    if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) &&
658
19.6k
        (ctxt->myDoc->intSubset != NULL))
659
19.6k
  ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
660
19.6k
                                          attr);
661
63.7k
#endif /* LIBXML_VALID_ENABLED */
662
63.7k
    if (prefix != NULL)
663
6.12k
  xmlFree(prefix);
664
63.7k
}
665
666
/**
667
 * An element definition has been parsed
668
 *
669
 * @param ctx  the user data (XML parser context)
670
 * @param name  the element name
671
 * @param type  the element type
672
 * @param content  the element value tree
673
 */
674
void
675
xmlSAX2ElementDecl(void *ctx, const xmlChar * name, int type,
676
            xmlElementContent *content)
677
39.9k
{
678
39.9k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
679
39.9k
    xmlElementPtr elem = NULL;
680
681
    /* Avoid unused variable warning if features are disabled. */
682
39.9k
    (void) elem;
683
684
39.9k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
685
0
        return;
686
687
39.9k
    if (ctxt->inSubset == 1)
688
15.2k
        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,
689
15.2k
                                 name, (xmlElementTypeVal) type, content);
690
24.7k
    else if (ctxt->inSubset == 2)
691
24.7k
        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
692
24.7k
                                 name, (xmlElementTypeVal) type, content);
693
0
    else {
694
0
        xmlFatalErrMsg(ctxt, XML_ERR_INTERNAL_ERROR,
695
0
       "SAX.xmlSAX2ElementDecl(%s) called while not in subset\n",
696
0
                 name, NULL);
697
0
        return;
698
0
    }
699
39.9k
#ifdef LIBXML_VALID_ENABLED
700
39.9k
    if (elem == NULL)
701
25.8k
        ctxt->valid = 0;
702
39.9k
    if (ctxt->validate && ctxt->wellFormed &&
703
10.9k
        ctxt->myDoc && ctxt->myDoc->intSubset)
704
10.9k
        ctxt->valid &=
705
10.9k
            xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);
706
39.9k
#endif /* LIBXML_VALID_ENABLED */
707
39.9k
}
708
709
/**
710
 * What to do when a notation declaration has been parsed.
711
 *
712
 * @param ctx  the user data (XML parser context)
713
 * @param name  The name of the notation
714
 * @param publicId  The public ID of the entity
715
 * @param systemId  The system ID of the entity
716
 */
717
void
718
xmlSAX2NotationDecl(void *ctx, const xmlChar *name,
719
       const xmlChar *publicId, const xmlChar *systemId)
720
2.62k
{
721
2.62k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
722
2.62k
    xmlNotationPtr nota = NULL;
723
724
    /* Avoid unused variable warning if features are disabled. */
725
2.62k
    (void) nota;
726
727
2.62k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
728
0
        return;
729
730
2.62k
    if ((publicId == NULL) && (systemId == NULL)) {
731
244
  xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
732
244
       "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n",
733
244
                 name, NULL);
734
244
  return;
735
2.37k
    } else if (ctxt->inSubset == 1)
736
1.60k
  nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
737
1.60k
                              publicId, systemId);
738
773
    else if (ctxt->inSubset == 2)
739
773
  nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
740
773
                              publicId, systemId);
741
0
    else {
742
0
  xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
743
0
       "SAX.xmlSAX2NotationDecl(%s) called while not in subset\n",
744
0
                 name, NULL);
745
0
  return;
746
0
    }
747
2.37k
#ifdef LIBXML_VALID_ENABLED
748
2.37k
    if (nota == NULL) ctxt->valid = 0;
749
2.37k
    if ((ctxt->validate) && (ctxt->wellFormed) &&
750
382
        (ctxt->myDoc->intSubset != NULL))
751
382
  ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
752
382
                                         nota);
753
2.37k
#endif /* LIBXML_VALID_ENABLED */
754
2.37k
}
755
756
/**
757
 * What to do when an unparsed entity declaration is parsed
758
 *
759
 * @param ctx  the user data (XML parser context)
760
 * @param name  The name of the entity
761
 * @param publicId  The public ID of the entity
762
 * @param systemId  The system ID of the entity
763
 * @param notationName  the name of the notation
764
 */
765
void
766
xmlSAX2UnparsedEntityDecl(void *ctx, const xmlChar *name,
767
       const xmlChar *publicId, const xmlChar *systemId,
768
       const xmlChar *notationName)
769
606
{
770
606
    xmlSAX2EntityDecl(ctx, name, XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
771
606
                      publicId, systemId, (xmlChar *) notationName);
772
606
}
773
774
/**
775
 * Receive the document locator at startup, actually xmlDefaultSAXLocator
776
 * Everything is available on the context, so this is useless in our case.
777
 *
778
 * @param ctx  the user data (XML parser context)
779
 * @param loc  A SAX Locator
780
 */
781
void
782
xmlSAX2SetDocumentLocator(void *ctx ATTRIBUTE_UNUSED, xmlSAXLocator *loc ATTRIBUTE_UNUSED)
783
46.0k
{
784
46.0k
}
785
786
/**
787
 * called when the document start being processed.
788
 *
789
 * @param ctx  the user data (XML parser context)
790
 */
791
void
792
xmlSAX2StartDocument(void *ctx)
793
45.5k
{
794
45.5k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
795
45.5k
    xmlDocPtr doc;
796
797
45.5k
    if (ctx == NULL) return;
798
799
45.5k
#ifdef LIBXML_HTML_ENABLED
800
45.5k
    if (ctxt->html) {
801
0
  if (ctxt->myDoc == NULL)
802
0
      ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
803
0
  if (ctxt->myDoc == NULL) {
804
0
      xmlSAX2ErrMemory(ctxt);
805
0
      return;
806
0
  }
807
0
  ctxt->myDoc->properties = XML_DOC_HTML;
808
0
  ctxt->myDoc->parseFlags = ctxt->options;
809
0
    } else
810
45.5k
#endif
811
45.5k
    {
812
45.5k
  doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
813
45.5k
  if (doc != NULL) {
814
45.5k
      doc->properties = 0;
815
45.5k
      if (ctxt->options & XML_PARSE_OLD10)
816
17.1k
          doc->properties |= XML_DOC_OLD10;
817
45.5k
      doc->parseFlags = ctxt->options;
818
45.5k
      doc->standalone = ctxt->standalone;
819
45.5k
  } else {
820
17
      xmlSAX2ErrMemory(ctxt);
821
17
      return;
822
17
  }
823
45.5k
  if ((ctxt->dictNames) && (doc != NULL)) {
824
25.6k
      doc->dict = ctxt->dict;
825
25.6k
      xmlDictReference(doc->dict);
826
25.6k
  }
827
45.5k
    }
828
45.5k
    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
829
45.5k
  (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
830
7.40k
  ctxt->myDoc->URL = xmlPathToURI((const xmlChar *)ctxt->input->filename);
831
7.40k
  if (ctxt->myDoc->URL == NULL)
832
2
      xmlSAX2ErrMemory(ctxt);
833
7.40k
    }
834
45.5k
}
835
836
/**
837
 * called when the document end has been detected.
838
 *
839
 * @param ctx  the user data (XML parser context)
840
 */
841
void
842
xmlSAX2EndDocument(void *ctx)
843
24.4k
{
844
24.4k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
845
24.4k
    xmlDocPtr doc;
846
847
24.4k
    if (ctx == NULL) return;
848
24.4k
#ifdef LIBXML_VALID_ENABLED
849
24.4k
    if (ctxt->validate && ctxt->wellFormed &&
850
506
        ctxt->myDoc && ctxt->myDoc->intSubset)
851
506
  ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
852
24.4k
#endif /* LIBXML_VALID_ENABLED */
853
854
24.4k
    doc = ctxt->myDoc;
855
24.4k
    if (doc == NULL)
856
97
        return;
857
858
24.3k
    if (doc->encoding == NULL) {
859
24.3k
        const xmlChar *encoding = xmlGetActualEncoding(ctxt);
860
861
24.3k
        if (encoding != NULL) {
862
336
            doc->encoding = xmlStrdup(encoding);
863
336
            if (doc->encoding == NULL)
864
2
                xmlSAX2ErrMemory(ctxt);
865
336
        }
866
24.3k
    }
867
868
24.3k
#ifdef LIBXML_HTML_ENABLED
869
24.3k
    if (ctxt->html) {
870
0
        if (((ctxt->options & HTML_PARSE_NODEFDTD) == 0) &&
871
0
            (doc->intSubset == NULL)) {
872
0
            doc->intSubset = xmlCreateIntSubset(doc, BAD_CAST "html",
873
0
                    BAD_CAST "-//W3C//DTD HTML 4.0 Transitional//EN",
874
0
                    BAD_CAST "http://www.w3.org/TR/REC-html40/loose.dtd");
875
0
            if (doc->intSubset == NULL)
876
0
                xmlSAX2ErrMemory(ctxt);
877
0
        }
878
0
    } else
879
24.3k
#endif /* LIBXML_HTML_ENABLED */
880
24.3k
    {
881
24.3k
        if (ctxt->wellFormed) {
882
11.2k
            doc->properties |= XML_DOC_WELLFORMED;
883
11.2k
            if (ctxt->valid)
884
6.34k
                doc->properties |= XML_DOC_DTDVALID;
885
11.2k
            if (ctxt->nsWellFormed)
886
8.77k
                doc->properties |= XML_DOC_NSVALID;
887
11.2k
        }
888
889
24.3k
        if (ctxt->options & XML_PARSE_OLD10)
890
9.73k
            doc->properties |= XML_DOC_OLD10;
891
24.3k
    }
892
24.3k
}
893
894
static void
895
2.31M
xmlSAX2AppendChild(xmlParserCtxtPtr ctxt, xmlNodePtr node) {
896
2.31M
    xmlNodePtr parent;
897
2.31M
    xmlNodePtr last;
898
899
2.31M
    if (ctxt->inSubset == 1) {
900
16.8k
  parent = (xmlNodePtr) ctxt->myDoc->intSubset;
901
2.29M
    } else if (ctxt->inSubset == 2) {
902
326k
  parent = (xmlNodePtr) ctxt->myDoc->extSubset;
903
1.97M
    } else {
904
1.97M
        parent = ctxt->node;
905
1.97M
        if (parent == NULL)
906
123k
            parent = (xmlNodePtr) ctxt->myDoc;
907
1.97M
    }
908
909
2.31M
    last = parent->last;
910
2.31M
    if (last == NULL) {
911
449k
        parent->children = node;
912
1.86M
    } else {
913
1.86M
        last->next = node;
914
1.86M
        node->prev = last;
915
1.86M
    }
916
917
2.31M
    parent->last = node;
918
2.31M
    node->parent = parent;
919
920
2.31M
    if ((node->type != XML_TEXT_NODE) &&
921
1.77M
  (ctxt->input != NULL)) {
922
1.77M
        if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
923
1.67M
            node->line = ctxt->input->line;
924
99.0k
        else
925
99.0k
            node->line = USHRT_MAX;
926
1.77M
    }
927
2.31M
}
928
929
#if defined(LIBXML_SAX1_ENABLED)
930
/**
931
 * Handle a namespace error
932
 *
933
 * @param ctxt  an XML parser context
934
 * @param error  the error number
935
 * @param msg  the error message
936
 * @param str1  an error string
937
 * @param str2  an error string
938
 */
939
static void LIBXML_ATTR_FORMAT(3,0)
940
xmlNsErrMsg(xmlParserCtxtPtr ctxt, xmlParserErrors error,
941
            const char *msg, const xmlChar *str1, const xmlChar *str2)
942
8.92k
{
943
8.92k
    xmlCtxtErr(ctxt, NULL, XML_FROM_NAMESPACE, error, XML_ERR_ERROR,
944
8.92k
               str1, str2, NULL, 0, msg, str1, str2);
945
8.92k
}
946
947
/**
948
 * Handle an attribute that has been read by the parser.
949
 *
950
 * Deprecated SAX1 interface.
951
 *
952
 * @param ctxt  the parser context
953
 * @param fullname  the attribute name, including namespace prefix
954
 * @param value  the attribute value
955
 * @param prefix  the namespace prefix
956
 */
957
static void
958
xmlSAX1Attribute(xmlParserCtxtPtr ctxt, const xmlChar *fullname,
959
                 const xmlChar *value, const xmlChar *prefix)
960
118k
{
961
118k
    xmlAttrPtr ret;
962
118k
    const xmlChar *name;
963
118k
    xmlChar *ns;
964
118k
    xmlNsPtr namespace;
965
966
    /*
967
     * Split the full name into a namespace prefix and the tag name
968
     */
969
118k
    name = xmlSplitQName4(fullname, &ns);
970
118k
    if (name == NULL) {
971
18
        xmlSAX2ErrMemory(ctxt);
972
18
        return;
973
18
    }
974
975
    /*
976
     * Check whether it's a namespace definition
977
     */
978
118k
    if ((ns == NULL) &&
979
56.3k
        (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
980
9.35k
        (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
981
6.81k
  xmlNsPtr nsret;
982
6.81k
  xmlChar *val;
983
984
        /* Avoid unused variable warning if features are disabled. */
985
6.81k
        (void) nsret;
986
987
6.81k
        if (!ctxt->replaceEntities) {
988
            /* TODO: normalize if needed */
989
4.66k
      val = xmlExpandEntitiesInAttValue(ctxt, value, /* normalize */ 0);
990
4.66k
      if (val == NULL) {
991
11
          xmlSAX2ErrMemory(ctxt);
992
11
    return;
993
11
      }
994
4.66k
  } else {
995
2.14k
      val = (xmlChar *) value;
996
2.14k
  }
997
998
6.80k
  if (val[0] != 0) {
999
5.69k
      xmlURIPtr uri;
1000
1001
5.69k
      if (xmlParseURISafe((const char *)val, &uri) < 0)
1002
7
                xmlSAX2ErrMemory(ctxt);
1003
5.69k
      if (uri == NULL) {
1004
1.52k
                xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
1005
1.52k
                             "xmlns:%s: %s not a valid URI\n", name, value);
1006
4.16k
      } else {
1007
4.16k
    if (uri->scheme == NULL) {
1008
3.89k
                    xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
1009
3.89k
                                 "xmlns:%s: URI %s is not absolute\n",
1010
3.89k
                                 name, value);
1011
3.89k
    }
1012
4.16k
    xmlFreeURI(uri);
1013
4.16k
      }
1014
5.69k
  }
1015
1016
  /* a default namespace definition */
1017
6.80k
  nsret = xmlNewNs(ctxt->node, val, NULL);
1018
6.80k
        if (nsret == NULL) {
1019
9
            xmlSAX2ErrMemory(ctxt);
1020
9
        }
1021
6.79k
#ifdef LIBXML_VALID_ENABLED
1022
  /*
1023
   * Validate also for namespace decls, they are attributes from
1024
   * an XML-1.0 perspective
1025
   */
1026
6.79k
        else if (ctxt->validate && ctxt->wellFormed &&
1027
2.85k
                 ctxt->myDoc && ctxt->myDoc->intSubset) {
1028
2.85k
      ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
1029
2.85k
             ctxt->node, prefix, nsret, val);
1030
2.85k
        }
1031
6.80k
#endif /* LIBXML_VALID_ENABLED */
1032
6.80k
  if (val != value)
1033
4.65k
      xmlFree(val);
1034
6.80k
  return;
1035
6.81k
    }
1036
111k
    if ((ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
1037
52.7k
        (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
1038
44.1k
  xmlNsPtr nsret;
1039
44.1k
  xmlChar *val;
1040
1041
        /* Avoid unused variable warning if features are disabled. */
1042
44.1k
        (void) nsret;
1043
1044
44.1k
        if (!ctxt->replaceEntities) {
1045
            /* TODO: normalize if needed */
1046
6.54k
      val = xmlExpandEntitiesInAttValue(ctxt, value, /* normalize */ 0);
1047
6.54k
      if (val == NULL) {
1048
1
          xmlSAX2ErrMemory(ctxt);
1049
1
          xmlFree(ns);
1050
1
    return;
1051
1
      }
1052
37.6k
  } else {
1053
37.6k
      val = (xmlChar *) value;
1054
37.6k
  }
1055
1056
44.1k
  if (val[0] == 0) {
1057
575
      xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY,
1058
575
            "Empty namespace name for prefix %s\n", name, NULL);
1059
575
  }
1060
44.1k
  if ((ctxt->pedantic != 0) && (val[0] != 0)) {
1061
26.4k
      xmlURIPtr uri;
1062
1063
26.4k
      if (xmlParseURISafe((const char *)val, &uri) < 0)
1064
3
                xmlSAX2ErrMemory(ctxt);
1065
26.4k
      if (uri == NULL) {
1066
963
          xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
1067
963
       "xmlns:%s: %s not a valid URI\n", name, value);
1068
25.4k
      } else {
1069
25.4k
    if (uri->scheme == NULL) {
1070
23.4k
        xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
1071
23.4k
         "xmlns:%s: URI %s is not absolute\n", name, value);
1072
23.4k
    }
1073
25.4k
    xmlFreeURI(uri);
1074
25.4k
      }
1075
26.4k
  }
1076
1077
  /* a standard namespace definition */
1078
44.1k
  nsret = xmlNewNs(ctxt->node, val, name);
1079
44.1k
  xmlFree(ns);
1080
1081
44.1k
        if (nsret == NULL) {
1082
5
            xmlSAX2ErrMemory(ctxt);
1083
5
        }
1084
44.1k
#ifdef LIBXML_VALID_ENABLED
1085
  /*
1086
   * Validate also for namespace decls, they are attributes from
1087
   * an XML-1.0 perspective
1088
   */
1089
44.1k
        else if (ctxt->validate && ctxt->wellFormed &&
1090
2.56k
           ctxt->myDoc && ctxt->myDoc->intSubset) {
1091
2.56k
      ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
1092
2.56k
             ctxt->node, prefix, nsret, value);
1093
2.56k
        }
1094
44.1k
#endif /* LIBXML_VALID_ENABLED */
1095
44.1k
  if (val != value)
1096
6.54k
      xmlFree(val);
1097
44.1k
  return;
1098
44.1k
    }
1099
1100
67.7k
    if (ns != NULL) {
1101
18.2k
        int res;
1102
1103
18.2k
  res = xmlSearchNsSafe(ctxt->node, ns, &namespace);
1104
18.2k
        if (res < 0)
1105
8
            xmlSAX2ErrMemory(ctxt);
1106
1107
18.2k
  if (namespace == NULL) {
1108
8.35k
      xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
1109
8.35k
        "Namespace prefix %s of attribute %s is not defined\n",
1110
8.35k
                 ns, name);
1111
9.92k
  } else {
1112
9.92k
            xmlAttrPtr prop;
1113
1114
9.92k
            prop = ctxt->node->properties;
1115
71.3k
            while (prop != NULL) {
1116
61.6k
                if (prop->ns != NULL) {
1117
39.4k
                    if ((xmlStrEqual(name, prop->name)) &&
1118
410
                        ((namespace == prop->ns) ||
1119
410
                         (xmlStrEqual(namespace->href, prop->ns->href)))) {
1120
197
                        xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER,
1121
197
                                   XML_ERR_ATTRIBUTE_REDEFINED, XML_ERR_FATAL,
1122
197
                                   name, NULL, NULL, 0,
1123
197
                                   "Attribute %s in %s redefined\n",
1124
197
                                   name, namespace->href);
1125
197
                        goto error;
1126
197
                    }
1127
39.4k
                }
1128
61.4k
                prop = prop->next;
1129
61.4k
            }
1130
9.92k
        }
1131
49.4k
    } else {
1132
49.4k
  namespace = NULL;
1133
49.4k
    }
1134
1135
    /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */
1136
67.5k
    ret = xmlNewNsProp(ctxt->node, namespace, name, NULL);
1137
67.5k
    if (ret == NULL) {
1138
40
        xmlSAX2ErrMemory(ctxt);
1139
40
        goto error;
1140
40
    }
1141
1142
67.5k
    if (ctxt->replaceEntities == 0) {
1143
32.8k
        if (xmlNodeParseAttValue(ret->doc, ret, value, SIZE_MAX, NULL) < 0)
1144
48
            xmlSAX2ErrMemory(ctxt);
1145
34.6k
    } else if (value != NULL) {
1146
34.6k
        ret->children = xmlNewDocText(ctxt->myDoc, value);
1147
34.6k
        if (ret->children == NULL) {
1148
33
            xmlSAX2ErrMemory(ctxt);
1149
34.6k
        } else {
1150
34.6k
            ret->last = ret->children;
1151
34.6k
            ret->children->parent = (xmlNodePtr) ret;
1152
34.6k
        }
1153
34.6k
    }
1154
1155
67.5k
#ifdef LIBXML_VALID_ENABLED
1156
67.5k
    if (ctxt->validate && ctxt->wellFormed &&
1157
8.71k
        ctxt->myDoc && ctxt->myDoc->intSubset) {
1158
1159
  /*
1160
   * If we don't substitute entities, the validation should be
1161
   * done on a value with replaced entities anyway.
1162
   */
1163
8.71k
        if (!ctxt->replaceEntities) {
1164
5.01k
      xmlChar *val;
1165
1166
            /* TODO: normalize if needed */
1167
5.01k
      val = xmlExpandEntitiesInAttValue(ctxt, value, /* normalize */ 0);
1168
1169
5.01k
      if (val == NULL)
1170
1
    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
1171
1
        ctxt->myDoc, ctxt->node, ret, value);
1172
5.01k
      else {
1173
5.01k
    xmlChar *nvalnorm;
1174
1175
    /*
1176
     * Do the last stage of the attribute normalization
1177
     * It need to be done twice ... it's an extra burden related
1178
     * to the ability to keep xmlSAX2References in attributes
1179
     */
1180
5.01k
                nvalnorm = xmlValidCtxtNormalizeAttributeValue(
1181
5.01k
                                 &ctxt->vctxt, ctxt->myDoc,
1182
5.01k
                                 ctxt->node, fullname, val);
1183
5.01k
    if (nvalnorm != NULL) {
1184
3.05k
        xmlFree(val);
1185
3.05k
        val = nvalnorm;
1186
3.05k
    }
1187
1188
5.01k
    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
1189
5.01k
              ctxt->myDoc, ctxt->node, ret, val);
1190
5.01k
                xmlFree(val);
1191
5.01k
      }
1192
5.01k
  } else {
1193
            /*
1194
             * When replacing entities, make sure that IDs in
1195
             * entities aren't registered. This also shouldn't be
1196
             * done when entities aren't replaced, but this would
1197
             * require to rework IDREF checks.
1198
             */
1199
3.70k
            if (ctxt->input->entity != NULL)
1200
410
                ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
1201
1202
3.70k
      ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
1203
3.70k
                 ctxt->node, ret, value);
1204
1205
3.70k
            ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
1206
3.70k
  }
1207
8.71k
    } else
1208
58.8k
#endif /* LIBXML_VALID_ENABLED */
1209
58.8k
           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
1210
37.4k
               (ctxt->input->entity == NULL) &&
1211
               /* Don't create IDs containing entity references */
1212
33.8k
               (ret->children != NULL) &&
1213
30.9k
               (ret->children->type == XML_TEXT_NODE) &&
1214
30.6k
               (ret->children->next == NULL)) {
1215
30.4k
        xmlChar *content = ret->children->content;
1216
        /*
1217
   * when validating, the ID registration is done at the attribute
1218
   * validation level. Otherwise we have to do specific handling here.
1219
   */
1220
30.4k
  if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {
1221
      /*
1222
       * Add the xml:id value
1223
       *
1224
       * Open issue: normalization of the value.
1225
       */
1226
796
      if (xmlValidateNCName(content, 1) != 0) {
1227
454
          xmlErrId(ctxt, XML_DTD_XMLID_VALUE,
1228
454
             "xml:id : attribute value %s is not an NCName\n",
1229
454
             content);
1230
454
      }
1231
796
      xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
1232
29.6k
  } else {
1233
29.6k
            int res = xmlIsID(ctxt->myDoc, ctxt->node, ret);
1234
1235
29.6k
            if (res < 0)
1236
1
                xmlCtxtErrMemory(ctxt);
1237
29.6k
            else if (res > 0)
1238
2.68k
                xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
1239
26.9k
            else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
1240
8.84k
                xmlAddRef(&ctxt->vctxt, ctxt->myDoc, content, ret);
1241
29.6k
        }
1242
30.4k
    }
1243
1244
67.7k
error:
1245
67.7k
    if (ns != NULL)
1246
18.2k
  xmlFree(ns);
1247
67.7k
}
1248
1249
/*
1250
 *
1251
 * Check defaulted attributes from the DTD
1252
 *
1253
 * Deprecated SAX1 interface.
1254
 */
1255
static void
1256
xmlCheckDefaultedAttributes(xmlParserCtxtPtr ctxt, const xmlChar *name,
1257
149k
  const xmlChar *prefix, const xmlChar **atts) {
1258
149k
    xmlElementPtr elemDecl;
1259
149k
    const xmlChar *att;
1260
149k
    int internal = 1;
1261
149k
    int i;
1262
1263
149k
    elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset, name, prefix);
1264
149k
    if (elemDecl == NULL) {
1265
105k
  elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, name, prefix);
1266
105k
  internal = 0;
1267
105k
    }
1268
1269
193k
process_external_subset:
1270
1271
193k
    if (elemDecl != NULL) {
1272
47.4k
  xmlAttributePtr attr = elemDecl->attributes;
1273
1274
47.4k
#ifdef LIBXML_VALID_ENABLED
1275
        /*
1276
         * Check against defaulted attributes from the external subset
1277
         * if the document is stamped as standalone.
1278
         *
1279
         * This should be moved to valid.c, but we don't keep track
1280
         * whether an attribute was defaulted.
1281
         */
1282
47.4k
  if ((ctxt->myDoc->standalone == 1) &&
1283
1.66k
      (ctxt->myDoc->extSubset != NULL) &&
1284
1.39k
      (ctxt->validate)) {
1285
2.17k
      while (attr != NULL) {
1286
977
    if ((attr->defaultValue != NULL) &&
1287
712
        (xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,
1288
712
          attr->elem, attr->name,
1289
712
          attr->prefix) == attr) &&
1290
712
        (xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
1291
712
          attr->elem, attr->name,
1292
712
          attr->prefix) == NULL)) {
1293
712
        xmlChar *fulln;
1294
1295
712
        if (attr->prefix != NULL) {
1296
72
      fulln = xmlStrdup(attr->prefix);
1297
72
                        if (fulln != NULL)
1298
71
          fulln = xmlStrcat(fulln, BAD_CAST ":");
1299
72
                        if (fulln != NULL)
1300
71
          fulln = xmlStrcat(fulln, attr->name);
1301
640
        } else {
1302
640
      fulln = xmlStrdup(attr->name);
1303
640
        }
1304
712
                    if (fulln == NULL) {
1305
2
                        xmlSAX2ErrMemory(ctxt);
1306
2
                        break;
1307
2
                    }
1308
1309
        /*
1310
         * Check that the attribute is not declared in the
1311
         * serialization
1312
         */
1313
710
        att = NULL;
1314
710
        if (atts != NULL) {
1315
360
      i = 0;
1316
360
      att = atts[i];
1317
722
      while (att != NULL) {
1318
429
          if (xmlStrEqual(att, fulln))
1319
67
        break;
1320
362
          i += 2;
1321
362
          att = atts[i];
1322
362
      }
1323
360
        }
1324
710
        if (att == NULL) {
1325
643
            xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED,
1326
643
      "standalone: attribute %s on %s defaulted from external subset\n",
1327
643
            fulln,
1328
643
            attr->elem);
1329
643
        }
1330
710
                    xmlFree(fulln);
1331
710
    }
1332
975
    attr = attr->nexth;
1333
975
      }
1334
1.19k
  }
1335
47.4k
#endif
1336
1337
  /*
1338
   * Actually insert defaulted values when needed
1339
   */
1340
47.4k
  attr = elemDecl->attributes;
1341
97.8k
  while (attr != NULL) {
1342
      /*
1343
       * Make sure that attributes redefinition occurring in the
1344
       * internal subset are not overridden by definitions in the
1345
       * external subset.
1346
       */
1347
50.3k
      if (attr->defaultValue != NULL) {
1348
    /*
1349
     * the element should be instantiated in the tree if:
1350
     *  - this is a namespace prefix
1351
     *  - the user required for completion in the tree
1352
     *    like XSLT
1353
     *  - there isn't already an attribute definition
1354
     *    in the internal subset overriding it.
1355
     */
1356
43.2k
    if (((attr->prefix != NULL) &&
1357
13.2k
         (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
1358
37.6k
        ((attr->prefix == NULL) &&
1359
30.0k
         (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
1360
36.9k
        (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
1361
36.9k
        xmlAttributePtr tst;
1362
1363
36.9k
        tst = xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
1364
36.9k
               attr->elem, attr->name,
1365
36.9k
               attr->prefix);
1366
36.9k
        if ((tst == attr) || (tst == NULL)) {
1367
36.9k
            xmlChar fn[50];
1368
36.9k
      xmlChar *fulln;
1369
1370
36.9k
                        fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50);
1371
36.9k
      if (fulln == NULL) {
1372
6
          xmlSAX2ErrMemory(ctxt);
1373
6
          return;
1374
6
      }
1375
1376
      /*
1377
       * Check that the attribute is not declared in the
1378
       * serialization
1379
       */
1380
36.9k
      att = NULL;
1381
36.9k
      if (atts != NULL) {
1382
2.30k
          i = 0;
1383
2.30k
          att = atts[i];
1384
4.63k
          while (att != NULL) {
1385
2.71k
        if (xmlStrEqual(att, fulln))
1386
376
            break;
1387
2.33k
        i += 2;
1388
2.33k
        att = atts[i];
1389
2.33k
          }
1390
2.30k
      }
1391
36.9k
      if (att == NULL) {
1392
36.6k
          xmlSAX1Attribute(ctxt, fulln,
1393
36.6k
               attr->defaultValue, prefix);
1394
36.6k
      }
1395
36.9k
      if ((fulln != fn) && (fulln != attr->name))
1396
9.21k
          xmlFree(fulln);
1397
36.9k
        }
1398
36.9k
    }
1399
43.2k
      }
1400
50.3k
      attr = attr->nexth;
1401
50.3k
  }
1402
47.4k
  if (internal == 1) {
1403
43.9k
      elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
1404
43.9k
                                 name, prefix);
1405
43.9k
      internal = 0;
1406
43.9k
      goto process_external_subset;
1407
43.9k
  }
1408
47.4k
    }
1409
193k
}
1410
1411
/**
1412
 * called when an opening tag has been processed.
1413
 *
1414
 * Deprecated SAX1 interface.
1415
 *
1416
 * @param ctx  the user data (XML parser context)
1417
 * @param fullname  The element name, including namespace prefix
1418
 * @param atts  An array of name/value attributes pairs, NULL terminated
1419
 */
1420
static void
1421
xmlSAX1StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts)
1422
415k
{
1423
415k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1424
415k
    xmlNodePtr ret;
1425
415k
    xmlNodePtr parent;
1426
415k
    xmlNsPtr ns;
1427
415k
    const xmlChar *name;
1428
415k
    xmlChar *prefix;
1429
415k
    const xmlChar *att;
1430
415k
    const xmlChar *value;
1431
415k
    int i, res;
1432
1433
415k
    if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return;
1434
1435
415k
#ifdef LIBXML_VALID_ENABLED
1436
    /*
1437
     * First check on validity:
1438
     */
1439
415k
    if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
1440
87.4k
        ((ctxt->myDoc->intSubset == NULL) ||
1441
83.0k
   ((ctxt->myDoc->intSubset->notations == NULL) &&
1442
82.7k
    (ctxt->myDoc->intSubset->elements == NULL) &&
1443
9.24k
    (ctxt->myDoc->intSubset->attributes == NULL) &&
1444
9.24k
    (ctxt->myDoc->intSubset->entities == NULL)))) {
1445
5.52k
  xmlErrValid(ctxt, XML_ERR_NO_DTD,
1446
5.52k
    "Validation failed: no DTD found !", NULL, NULL);
1447
5.52k
  ctxt->validate = 0;
1448
5.52k
    }
1449
415k
#endif
1450
1451
    /*
1452
     * Split the full name into a namespace prefix and the tag name
1453
     */
1454
415k
    name = xmlSplitQName4(fullname, &prefix);
1455
415k
    if (name == NULL) {
1456
2
        xmlSAX2ErrMemory(ctxt);
1457
2
        return;
1458
2
    }
1459
1460
    /*
1461
     * Note : the namespace resolution is deferred until the end of the
1462
     *        attributes parsing, since local namespace can be defined as
1463
     *        an attribute at this level.
1464
     */
1465
415k
    ret = xmlNewDocNode(ctxt->myDoc, NULL, name, NULL);
1466
415k
    if (ret == NULL) {
1467
44
  xmlFree(prefix);
1468
44
  xmlSAX2ErrMemory(ctxt);
1469
44
        return;
1470
44
    }
1471
415k
    ctxt->nodemem = -1;
1472
1473
    /* Initialize parent before pushing node */
1474
415k
    parent = ctxt->node;
1475
415k
    if (parent == NULL)
1476
16.0k
        parent = (xmlNodePtr) ctxt->myDoc;
1477
1478
    /*
1479
     * Link the child element
1480
     */
1481
415k
    xmlSAX2AppendChild(ctxt, ret);
1482
1483
    /*
1484
     * We are parsing a new node.
1485
     */
1486
415k
    if (nodePush(ctxt, ret) < 0) {
1487
16
        xmlUnlinkNode(ret);
1488
16
        xmlFreeNode(ret);
1489
16
        if (prefix != NULL)
1490
4
            xmlFree(prefix);
1491
16
        return;
1492
16
    }
1493
1494
    /*
1495
     * Insert all the defaulted attributes from the DTD especially
1496
     * namespaces
1497
     */
1498
415k
    if ((ctxt->myDoc->intSubset != NULL) ||
1499
265k
        (ctxt->myDoc->extSubset != NULL)) {
1500
149k
        xmlCheckDefaultedAttributes(ctxt, name, prefix, atts);
1501
149k
    }
1502
1503
    /*
1504
     * process all the attributes whose name start with "xmlns"
1505
     */
1506
415k
    if (atts != NULL) {
1507
63.2k
        i = 0;
1508
63.2k
        att = atts[i++];
1509
63.2k
        value = atts[i++];
1510
145k
        while ((att != NULL) && (value != NULL)) {
1511
82.1k
            if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') &&
1512
49.7k
                (att[3] == 'n') && (att[4] == 's'))
1513
42.7k
                xmlSAX1Attribute(ctxt, att, value, prefix);
1514
1515
82.1k
            att = atts[i++];
1516
82.1k
            value = atts[i++];
1517
82.1k
        }
1518
63.2k
    }
1519
1520
    /*
1521
     * Search the namespace, note that since the attributes have been
1522
     * processed, the local namespaces are available.
1523
     */
1524
415k
    res = xmlSearchNsSafe(ret, prefix, &ns);
1525
415k
    if (res < 0)
1526
4
        xmlSAX2ErrMemory(ctxt);
1527
415k
    if ((ns == NULL) && (parent != NULL)) {
1528
357k
        res = xmlSearchNsSafe(parent, prefix, &ns);
1529
357k
        if (res < 0)
1530
0
            xmlSAX2ErrMemory(ctxt);
1531
357k
    }
1532
415k
    if ((prefix != NULL) && (ns == NULL)) {
1533
12.7k
        xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
1534
12.7k
                     "Namespace prefix %s is not defined\n",
1535
12.7k
                     prefix, NULL);
1536
12.7k
        ns = xmlNewNs(ret, NULL, prefix);
1537
12.7k
        if (ns == NULL)
1538
2
            xmlSAX2ErrMemory(ctxt);
1539
12.7k
    }
1540
1541
    /*
1542
     * set the namespace node, making sure that if the default namespace
1543
     * is unbound on a parent we simply keep it NULL
1544
     */
1545
415k
    if ((ns != NULL) && (ns->href != NULL) &&
1546
57.7k
        ((ns->href[0] != 0) || (ns->prefix != NULL)))
1547
56.1k
        xmlSetNs(ret, ns);
1548
1549
    /*
1550
     * process all the other attributes
1551
     */
1552
415k
    if (atts != NULL) {
1553
63.2k
        i = 0;
1554
63.2k
  att = atts[i++];
1555
63.2k
  value = atts[i++];
1556
145k
        while ((att != NULL) && (value != NULL)) {
1557
82.1k
            if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l') ||
1558
49.7k
                (att[3] != 'n') || (att[4] != 's'))
1559
39.4k
                xmlSAX1Attribute(ctxt, att, value, NULL);
1560
1561
            /*
1562
             * Next ones
1563
             */
1564
82.1k
            att = atts[i++];
1565
82.1k
            value = atts[i++];
1566
82.1k
        }
1567
63.2k
    }
1568
1569
415k
#ifdef LIBXML_VALID_ENABLED
1570
    /*
1571
     * If it's the Document root, finish the DTD validation and
1572
     * check the document root element for validity
1573
     */
1574
415k
    if ((ctxt->validate) &&
1575
94.5k
        ((ctxt->vctxt.flags & XML_VCTXT_DTD_VALIDATED) == 0)) {
1576
2.62k
  int chk;
1577
1578
2.62k
  chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
1579
2.62k
  if (chk <= 0)
1580
50
      ctxt->valid = 0;
1581
2.62k
  if (chk < 0)
1582
0
      ctxt->wellFormed = 0;
1583
2.62k
  ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
1584
2.62k
  ctxt->vctxt.flags |= XML_VCTXT_DTD_VALIDATED;
1585
2.62k
    }
1586
415k
#endif /* LIBXML_VALID_ENABLED */
1587
1588
415k
    if (prefix != NULL)
1589
56.3k
  xmlFree(prefix);
1590
1591
415k
}
1592
#endif /* LIBXML_SAX1_ENABLED */
1593
1594
#ifdef LIBXML_HTML_ENABLED
1595
static void
1596
xmlSAX2HtmlAttribute(xmlParserCtxtPtr ctxt, const xmlChar *fullname,
1597
0
                     const xmlChar *value) {
1598
0
    xmlAttrPtr ret;
1599
0
    xmlChar *nval = NULL;
1600
1601
0
    ret = xmlNewNsProp(ctxt->node, NULL, fullname, NULL);
1602
0
    if (ret == NULL) {
1603
0
        xmlSAX2ErrMemory(ctxt);
1604
0
        return;
1605
0
    }
1606
1607
0
    if ((value == NULL) && (htmlIsBooleanAttr(fullname))) {
1608
0
        nval = xmlStrdup(fullname);
1609
0
        if (nval == NULL) {
1610
0
            xmlSAX2ErrMemory(ctxt);
1611
0
            return;
1612
0
        }
1613
0
        value = nval;
1614
0
    }
1615
1616
0
    if (value != NULL) {
1617
0
        ret->children = xmlNewDocText(ctxt->myDoc, value);
1618
0
        if (ret->children == NULL) {
1619
0
            xmlSAX2ErrMemory(ctxt);
1620
0
        } else {
1621
0
            ret->last = ret->children;
1622
0
            ret->children->parent = (xmlNodePtr) ret;
1623
0
        }
1624
0
    }
1625
1626
0
    if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
1627
        /*
1628
         * Don't create IDs containing entity references (should
1629
         * be always the case with HTML)
1630
         */
1631
0
        (ret->children != NULL) &&
1632
0
        (ret->children->type == XML_TEXT_NODE) &&
1633
0
        (ret->children->next == NULL)) {
1634
0
        int res = xmlIsID(ctxt->myDoc, ctxt->node, ret);
1635
1636
0
        if (res < 0)
1637
0
            xmlCtxtErrMemory(ctxt);
1638
0
        else if (res > 0)
1639
0
            xmlAddID(&ctxt->vctxt, ctxt->myDoc, ret->children->content, ret);
1640
0
    }
1641
1642
0
    if (nval != NULL)
1643
0
        xmlFree(nval);
1644
0
}
1645
1646
/**
1647
 * Called when an opening tag has been processed.
1648
 *
1649
 * @param ctxt  parser context
1650
 * @param fullname  The element name, including namespace prefix
1651
 * @param atts  An array of name/value attributes pairs, NULL terminated
1652
 */
1653
static void
1654
xmlSAX2StartHtmlElement(xmlParserCtxtPtr ctxt, const xmlChar *fullname,
1655
0
                        const xmlChar **atts) {
1656
0
    xmlNodePtr ret;
1657
0
    xmlNodePtr parent;
1658
0
    const xmlChar *att;
1659
0
    const xmlChar *value;
1660
0
    int i;
1661
1662
0
    ret = xmlNewDocNode(ctxt->myDoc, NULL, fullname, NULL);
1663
0
    if (ret == NULL) {
1664
0
  xmlSAX2ErrMemory(ctxt);
1665
0
        return;
1666
0
    }
1667
0
    ctxt->nodemem = -1;
1668
1669
    /* Initialize parent before pushing node */
1670
0
    parent = ctxt->node;
1671
0
    if (parent == NULL)
1672
0
        parent = (xmlNodePtr) ctxt->myDoc;
1673
1674
    /*
1675
     * Link the child element
1676
     */
1677
0
    xmlSAX2AppendChild(ctxt, ret);
1678
1679
    /*
1680
     * We are parsing a new node.
1681
     */
1682
0
    if (nodePush(ctxt, ret) < 0) {
1683
0
        xmlUnlinkNode(ret);
1684
0
        xmlFreeNode(ret);
1685
0
        return;
1686
0
    }
1687
1688
0
    if (atts != NULL) {
1689
0
        i = 0;
1690
0
  att = atts[i++];
1691
0
  value = atts[i++];
1692
0
        while (att != NULL) {
1693
0
            xmlSAX2HtmlAttribute(ctxt, att, value);
1694
0
            att = atts[i++];
1695
0
            value = atts[i++];
1696
0
        }
1697
0
    }
1698
0
}
1699
#endif /* LIBXML_HTML_ENABLED */
1700
1701
/**
1702
 * Called when an opening tag has been processed.
1703
 *
1704
 * @deprecated Don't call this function directly.
1705
 *
1706
 * Used for HTML and SAX1.
1707
 *
1708
 * @param ctx  the user data (XML parser context)
1709
 * @param fullname  The element name, including namespace prefix
1710
 * @param atts  An array of name/value attributes pairs, NULL terminated
1711
 */
1712
void
1713
415k
xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) {
1714
415k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1715
1716
415k
    (void) atts;
1717
1718
415k
    if ((ctxt == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL))
1719
0
        return;
1720
1721
415k
#ifdef LIBXML_SAX1_ENABLED
1722
415k
    if (!ctxt->html) {
1723
415k
        xmlSAX1StartElement(ctxt, fullname, atts);
1724
415k
        return;
1725
415k
    }
1726
0
#endif
1727
1728
0
#ifdef LIBXML_HTML_ENABLED
1729
0
    if (ctxt->html) {
1730
0
        xmlSAX2StartHtmlElement(ctxt, fullname, atts);
1731
0
        return;
1732
0
    }
1733
0
#endif
1734
0
}
1735
1736
/**
1737
 * called when the end of an element has been detected.
1738
 *
1739
 * @deprecated Don't call this function directly.
1740
 *
1741
 * Used for HTML and SAX1.
1742
 *
1743
 * @param ctx  the user data (XML parser context)
1744
 * @param name  The element name
1745
 */
1746
void
1747
xmlSAX2EndElement(void *ctx, const xmlChar *name ATTRIBUTE_UNUSED)
1748
313k
{
1749
313k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1750
1751
313k
    if (ctxt == NULL)
1752
0
        return;
1753
1754
313k
#if defined(LIBXML_SAX1_ENABLED) && defined(LIBXML_VALID_ENABLED)
1755
313k
    if (!ctxt->html && ctxt->validate && ctxt->wellFormed &&
1756
39.7k
        ctxt->myDoc && ctxt->myDoc->intSubset)
1757
39.7k
        ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
1758
39.7k
               ctxt->node);
1759
313k
#endif /* LIBXML_VALID_ENABLED */
1760
1761
313k
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED)
1762
313k
    ctxt->nodemem = -1;
1763
1764
    /*
1765
     * end of parsing of this node.
1766
     */
1767
313k
    nodePop(ctxt);
1768
313k
#endif
1769
313k
}
1770
1771
/*
1772
 * @param ctxt  the parser context
1773
 * @param doc  the document
1774
 * @param str  the input string
1775
 * @param len  the string length
1776
 *
1777
 * Callback for a text node
1778
 *
1779
 * @returns the newly allocated string or NULL if not needed or error
1780
 */
1781
static xmlNodePtr
1782
xmlSAX2TextNode(xmlParserCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *str,
1783
973k
                int len) {
1784
973k
    xmlNodePtr ret;
1785
973k
    const xmlChar *intern = NULL;
1786
1787
    /*
1788
     * Allocate
1789
     */
1790
973k
    if (ctxt->freeElems != NULL) {
1791
2.39k
  ret = ctxt->freeElems;
1792
2.39k
  ctxt->freeElems = ret->next;
1793
2.39k
  ctxt->freeElemsNr--;
1794
970k
    } else {
1795
970k
  ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
1796
970k
    }
1797
973k
    if (ret == NULL) {
1798
91
        xmlCtxtErrMemory(ctxt);
1799
91
  return(NULL);
1800
91
    }
1801
973k
    memset(ret, 0, sizeof(xmlNode));
1802
    /*
1803
     * intern the formatting blanks found between tags, or the
1804
     * very short strings
1805
     */
1806
973k
    if ((!ctxt->html) && (ctxt->dictNames)) {
1807
501k
        xmlChar cur = str[len];
1808
1809
501k
  if ((len < (int) (2 * sizeof(void *))) &&
1810
366k
      (ctxt->options & XML_PARSE_COMPACT)) {
1811
      /* store the string in the node overriding properties and nsDef */
1812
366k
      xmlChar *tmp = (xmlChar *) &(ret->properties);
1813
366k
      memcpy(tmp, str, len);
1814
366k
      tmp[len] = 0;
1815
366k
      intern = tmp;
1816
366k
  } else if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
1817
0
      ((cur == '<') && (str[len + 1] != '!')))) {
1818
0
      intern = xmlDictLookup(ctxt->dict, str, len);
1819
0
            if (intern == NULL) {
1820
0
                xmlSAX2ErrMemory(ctxt);
1821
0
                xmlFree(ret);
1822
0
                return(NULL);
1823
0
            }
1824
134k
  } else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') &&
1825
7.51k
             (str[len + 1] != '!')) {
1826
7.12k
      int i;
1827
1828
65.3k
      for (i = 1;i < len;i++) {
1829
62.8k
    if (!IS_BLANK_CH(str[i])) goto skip;
1830
62.8k
      }
1831
2.46k
      intern = xmlDictLookup(ctxt->dict, str, len);
1832
2.46k
            if (intern == NULL) {
1833
1
                xmlSAX2ErrMemory(ctxt);
1834
1
                xmlFree(ret);
1835
1
                return(NULL);
1836
1
            }
1837
2.46k
  }
1838
501k
    }
1839
973k
skip:
1840
973k
    ret->type = XML_TEXT_NODE;
1841
973k
    ret->doc = doc;
1842
1843
973k
    ret->name = xmlStringText;
1844
973k
    if (intern == NULL) {
1845
604k
  ret->content = xmlStrndup(str, len);
1846
604k
  if (ret->content == NULL) {
1847
38
      xmlSAX2ErrMemory(ctxt);
1848
38
      xmlFree(ret);
1849
38
      return(NULL);
1850
38
  }
1851
604k
    } else
1852
368k
  ret->content = (xmlChar *) intern;
1853
1854
973k
    if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
1855
0
  xmlRegisterNodeDefaultValue(ret);
1856
973k
    return(ret);
1857
973k
}
1858
1859
#ifdef LIBXML_VALID_ENABLED
1860
/*
1861
 * @param ctxt  the parser context
1862
 * @param str  the input string
1863
 * @param len  the string length
1864
 *
1865
 * Remove the entities from an attribute value
1866
 *
1867
 * @returns the newly allocated string or NULL if not needed or error
1868
 */
1869
static xmlChar *
1870
xmlSAX2DecodeAttrEntities(xmlParserCtxtPtr ctxt, const xmlChar *str,
1871
10.3k
                          const xmlChar *end) {
1872
10.3k
    const xmlChar *in;
1873
1874
10.3k
    in = str;
1875
133k
    while (in < end)
1876
126k
        if (*in++ == '&')
1877
3.67k
      goto decode;
1878
6.69k
    return(NULL);
1879
3.67k
decode:
1880
    /*
1881
     * If the value contains '&', we can be sure it was allocated and is
1882
     * zero-terminated.
1883
     */
1884
    /* TODO: normalize if needed */
1885
3.67k
    return(xmlExpandEntitiesInAttValue(ctxt, str, /* normalize */ 0));
1886
10.3k
}
1887
#endif /* LIBXML_VALID_ENABLED */
1888
1889
/**
1890
 * Handle an attribute that has been read by the parser.
1891
 * The default handling is to convert the attribute into an
1892
 * DOM subtree and past it in a new xmlAttr element added to
1893
 * the element.
1894
 *
1895
 * @param ctxt  the parser context
1896
 * @param localname  the local name of the attribute
1897
 * @param prefix  the attribute namespace prefix if available
1898
 * @param value  start of the attribute value
1899
 * @param valueend  end of the attribute value
1900
 * @returns the new attribute or NULL in case of error.
1901
 */
1902
static xmlAttrPtr
1903
xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
1904
                   const xmlChar * localname,
1905
                   const xmlChar * prefix,
1906
       const xmlChar * value,
1907
       const xmlChar * valueend)
1908
275k
{
1909
275k
    xmlAttrPtr ret;
1910
275k
    xmlNsPtr namespace = NULL;
1911
275k
    xmlChar *dup = NULL;
1912
1913
    /*
1914
     * Note: if prefix == NULL, the attribute is not in the default namespace
1915
     */
1916
275k
    if (prefix != NULL) {
1917
67.5k
  namespace = xmlParserNsLookupSax(ctxt, prefix);
1918
67.5k
  if ((namespace == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
1919
44.2k
            int res;
1920
1921
44.2k
      res = xmlSearchNsSafe(ctxt->node, prefix, &namespace);
1922
44.2k
            if (res < 0)
1923
7
                xmlSAX2ErrMemory(ctxt);
1924
44.2k
  }
1925
67.5k
    }
1926
1927
    /*
1928
     * allocate the node
1929
     */
1930
275k
    if (ctxt->freeAttrs != NULL) {
1931
1.39k
        ret = ctxt->freeAttrs;
1932
1.39k
  ctxt->freeAttrs = ret->next;
1933
1.39k
  ctxt->freeAttrsNr--;
1934
274k
    } else {
1935
274k
        ret = xmlMalloc(sizeof(*ret));
1936
274k
        if (ret == NULL) {
1937
29
            xmlSAX2ErrMemory(ctxt);
1938
29
            return(NULL);
1939
29
        }
1940
274k
    }
1941
1942
275k
    memset(ret, 0, sizeof(xmlAttr));
1943
275k
    ret->type = XML_ATTRIBUTE_NODE;
1944
1945
    /*
1946
     * xmlParseBalancedChunkMemoryRecover had a bug that could result in
1947
     * a mismatch between ctxt->node->doc and ctxt->myDoc. We use
1948
     * ctxt->node->doc here, but we should somehow make sure that the
1949
     * document pointers match.
1950
     */
1951
1952
    /* assert(ctxt->node->doc == ctxt->myDoc); */
1953
1954
275k
    ret->parent = ctxt->node;
1955
275k
    ret->doc = ctxt->node->doc;
1956
275k
    ret->ns = namespace;
1957
1958
275k
    if (ctxt->dictNames) {
1959
160k
        ret->name = localname;
1960
160k
    } else {
1961
114k
        ret->name = xmlStrdup(localname);
1962
114k
        if (ret->name == NULL)
1963
70
            xmlSAX2ErrMemory(ctxt);
1964
114k
    }
1965
1966
275k
    if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
1967
0
        xmlRegisterNodeDefaultValue((xmlNodePtr)ret);
1968
1969
275k
    if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
1970
88.2k
  xmlNodePtr tmp;
1971
1972
  /*
1973
   * We know that if there is an entity reference, then
1974
   * the string has been dup'ed and terminates with 0
1975
   * otherwise with ' or "
1976
   */
1977
88.2k
  if (*valueend != 0) {
1978
35.7k
      tmp = xmlSAX2TextNode(ctxt, ret->doc, value, valueend - value);
1979
35.7k
      ret->children = tmp;
1980
35.7k
      ret->last = tmp;
1981
35.7k
      if (tmp != NULL) {
1982
35.7k
    tmp->parent = (xmlNodePtr) ret;
1983
35.7k
      }
1984
52.4k
  } else if (valueend > value) {
1985
51.8k
            if (xmlNodeParseAttValue(ret->doc, ret, value, valueend - value,
1986
51.8k
                                     NULL) < 0)
1987
35
                xmlSAX2ErrMemory(ctxt);
1988
51.8k
  }
1989
187k
    } else if (value != NULL) {
1990
187k
  xmlNodePtr tmp;
1991
1992
187k
  tmp = xmlSAX2TextNode(ctxt, ret->doc, value, valueend - value);
1993
187k
  ret->children = tmp;
1994
187k
  ret->last = tmp;
1995
187k
  if (tmp != NULL) {
1996
187k
      tmp->parent = (xmlNodePtr) ret;
1997
187k
  }
1998
187k
    }
1999
2000
275k
#ifdef LIBXML_VALID_ENABLED
2001
275k
    if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
2002
54.0k
        ctxt->myDoc && ctxt->myDoc->intSubset) {
2003
  /*
2004
   * If we don't substitute entities, the validation should be
2005
   * done on a value with replaced entities anyway.
2006
   */
2007
54.0k
        if (!ctxt->replaceEntities) {
2008
10.3k
      dup = xmlSAX2DecodeAttrEntities(ctxt, value, valueend);
2009
10.3k
      if (dup == NULL) {
2010
6.69k
          if (*valueend == 0) {
2011
5.56k
        ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2012
5.56k
            ctxt->myDoc, ctxt->node, ret, value);
2013
5.56k
    } else {
2014
        /*
2015
         * That should already be normalized.
2016
         * cheaper to finally allocate here than duplicate
2017
         * entry points in the full validation code
2018
         */
2019
1.13k
        dup = xmlStrndup(value, valueend - value);
2020
1.13k
                    if (dup == NULL)
2021
1
                        xmlSAX2ErrMemory(ctxt);
2022
2023
1.13k
        ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2024
1.13k
            ctxt->myDoc, ctxt->node, ret, dup);
2025
1.13k
    }
2026
6.69k
      } else {
2027
          /*
2028
     * dup now contains a string of the flattened attribute
2029
     * content with entities substituted. Check if we need to
2030
     * apply an extra layer of normalization.
2031
     * It need to be done twice ... it's an extra burden related
2032
     * to the ability to keep references in attributes
2033
     */
2034
3.67k
    if (ctxt->attsSpecial != NULL) {
2035
3.37k
        xmlChar *nvalnorm;
2036
3.37k
        xmlChar fn[50];
2037
3.37k
        xmlChar *fullname;
2038
2039
3.37k
        fullname = xmlBuildQName(localname, prefix, fn, 50);
2040
3.37k
                    if (fullname == NULL) {
2041
1
                        xmlSAX2ErrMemory(ctxt);
2042
3.37k
                    } else {
2043
3.37k
      ctxt->vctxt.valid = 1;
2044
3.37k
            nvalnorm = xmlValidCtxtNormalizeAttributeValue(
2045
3.37k
                       &ctxt->vctxt, ctxt->myDoc,
2046
3.37k
           ctxt->node, fullname, dup);
2047
3.37k
      if (ctxt->vctxt.valid != 1)
2048
0
          ctxt->valid = 0;
2049
2050
3.37k
      if ((fullname != fn) && (fullname != localname))
2051
486
          xmlFree(fullname);
2052
3.37k
      if (nvalnorm != NULL) {
2053
3.16k
          xmlFree(dup);
2054
3.16k
          dup = nvalnorm;
2055
3.16k
      }
2056
3.37k
        }
2057
3.37k
    }
2058
2059
3.67k
    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2060
3.67k
              ctxt->myDoc, ctxt->node, ret, dup);
2061
3.67k
      }
2062
43.7k
  } else {
2063
      /*
2064
       * if entities already have been substituted, then
2065
       * the attribute as passed is already normalized
2066
       */
2067
43.7k
      dup = xmlStrndup(value, valueend - value);
2068
43.7k
            if (dup == NULL)
2069
11
                xmlSAX2ErrMemory(ctxt);
2070
2071
            /*
2072
             * When replacing entities, make sure that IDs in
2073
             * entities aren't registered. This also shouldn't be
2074
             * done when entities aren't replaced, but this would
2075
             * require to rework IDREF checks.
2076
             */
2077
43.7k
            if (ctxt->input->entity != NULL)
2078
352
                ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
2079
2080
43.7k
      ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2081
43.7k
                               ctxt->myDoc, ctxt->node, ret, dup);
2082
2083
43.7k
            ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
2084
43.7k
  }
2085
54.0k
    } else
2086
221k
#endif /* LIBXML_VALID_ENABLED */
2087
221k
           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
2088
89.7k
               (ctxt->input->entity == NULL) &&
2089
               /* Don't create IDs containing entity references */
2090
84.4k
               (ret->children != NULL) &&
2091
84.0k
               (ret->children->type == XML_TEXT_NODE) &&
2092
83.5k
               (ret->children->next == NULL)) {
2093
83.1k
        xmlChar *content = ret->children->content;
2094
        /*
2095
   * when validating, the ID registration is done at the attribute
2096
   * validation level. Otherwise we have to do specific handling here.
2097
   */
2098
83.1k
        if ((prefix == ctxt->str_xml) &&
2099
13.4k
             (localname[0] == 'i') && (localname[1] == 'd') &&
2100
2.46k
       (localname[2] == 0)) {
2101
      /*
2102
       * Add the xml:id value
2103
       *
2104
       * Open issue: normalization of the value.
2105
       */
2106
2.02k
      if (xmlValidateNCName(content, 1) != 0) {
2107
1.42k
          xmlErrId(ctxt, XML_DTD_XMLID_VALUE,
2108
1.42k
                         "xml:id : attribute value %s is not an NCName\n",
2109
1.42k
                         content);
2110
1.42k
      }
2111
2.02k
      xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
2112
81.1k
  } else {
2113
81.1k
            int res = xmlIsID(ctxt->myDoc, ctxt->node, ret);
2114
2115
81.1k
            if (res < 0)
2116
1
                xmlCtxtErrMemory(ctxt);
2117
81.1k
            else if (res > 0)
2118
2.96k
                xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
2119
78.2k
            else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
2120
30.6k
                xmlAddRef(&ctxt->vctxt, ctxt->myDoc, content, ret);
2121
81.1k
  }
2122
83.1k
    }
2123
275k
    if (dup != NULL)
2124
48.4k
  xmlFree(dup);
2125
2126
275k
    return(ret);
2127
275k
}
2128
2129
/**
2130
 * SAX2 callback when an element start has been detected by the parser.
2131
 * It provides the namespace information for the element, as well as
2132
 * the new namespace declarations on the element.
2133
 *
2134
 * @param ctx  the user data (XML parser context)
2135
 * @param localname  the local name of the element
2136
 * @param prefix  the element namespace prefix if available
2137
 * @param URI  the element namespace name if available
2138
 * @param nb_namespaces  number of namespace definitions on that node
2139
 * @param namespaces  pointer to the array of prefix/URI pairs namespace definitions
2140
 * @param nb_attributes  the number of attributes on that node
2141
 * @param nb_defaulted  the number of defaulted attributes.
2142
 * @param attributes  pointer to the array of (localname/prefix/URI/value/end)
2143
 *               attribute values.
2144
 */
2145
void
2146
xmlSAX2StartElementNs(void *ctx,
2147
                      const xmlChar *localname,
2148
          const xmlChar *prefix,
2149
          const xmlChar *URI,
2150
          int nb_namespaces,
2151
          const xmlChar **namespaces,
2152
          int nb_attributes,
2153
          int nb_defaulted,
2154
          const xmlChar **attributes)
2155
635k
{
2156
635k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2157
635k
    xmlNodePtr ret;
2158
635k
    xmlNsPtr last = NULL, ns;
2159
635k
    const xmlChar *uri, *pref;
2160
635k
    xmlChar *lname = NULL;
2161
635k
    int i, j;
2162
2163
635k
    if (ctx == NULL) return;
2164
2165
635k
#ifdef LIBXML_VALID_ENABLED
2166
    /*
2167
     * First check on validity:
2168
     */
2169
635k
    if (ctxt->validate &&
2170
140k
        ((ctxt->myDoc == NULL) ||
2171
140k
         ((ctxt->myDoc->extSubset == NULL) &&
2172
136k
          ((ctxt->myDoc->intSubset == NULL) ||
2173
131k
     ((ctxt->myDoc->intSubset->notations == NULL) &&
2174
130k
      (ctxt->myDoc->intSubset->elements == NULL) &&
2175
16.0k
      (ctxt->myDoc->intSubset->attributes == NULL) &&
2176
16.0k
      (ctxt->myDoc->intSubset->entities == NULL)))))) {
2177
5.33k
  xmlErrValid(ctxt, XML_DTD_NO_DTD,
2178
5.33k
    "Validation failed: no DTD found !", NULL, NULL);
2179
5.33k
  ctxt->validate = 0;
2180
5.33k
    }
2181
635k
#endif /* LIBXML_VALID_ENABLED */
2182
2183
    /*
2184
     * Take care of the rare case of an undefined namespace prefix
2185
     */
2186
635k
    if ((prefix != NULL) && (URI == NULL)) {
2187
22.0k
        if (ctxt->dictNames) {
2188
11.7k
      const xmlChar *fullname;
2189
2190
11.7k
      fullname = xmlDictQLookup(ctxt->dict, prefix, localname);
2191
11.7k
      if (fullname == NULL) {
2192
2
                xmlSAX2ErrMemory(ctxt);
2193
2
                return;
2194
2
            }
2195
11.7k
      localname = fullname;
2196
11.7k
  } else {
2197
10.3k
      lname = xmlBuildQName(localname, prefix, NULL, 0);
2198
10.3k
            if (lname == NULL) {
2199
2
                xmlSAX2ErrMemory(ctxt);
2200
2
                return;
2201
2
            }
2202
10.3k
  }
2203
22.0k
    }
2204
    /*
2205
     * allocate the node
2206
     */
2207
635k
    if (ctxt->freeElems != NULL) {
2208
1.90k
        ret = ctxt->freeElems;
2209
1.90k
  ctxt->freeElems = ret->next;
2210
1.90k
  ctxt->freeElemsNr--;
2211
1.90k
  memset(ret, 0, sizeof(xmlNode));
2212
1.90k
        ret->doc = ctxt->myDoc;
2213
1.90k
  ret->type = XML_ELEMENT_NODE;
2214
2215
1.90k
  if (ctxt->dictNames)
2216
770
      ret->name = localname;
2217
1.13k
  else {
2218
1.13k
      if (lname == NULL)
2219
920
    ret->name = xmlStrdup(localname);
2220
219
      else
2221
219
          ret->name = lname;
2222
1.13k
      if (ret->name == NULL) {
2223
1
          xmlSAX2ErrMemory(ctxt);
2224
1
                xmlFree(ret);
2225
1
    return;
2226
1
      }
2227
1.13k
  }
2228
1.90k
  if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
2229
0
      xmlRegisterNodeDefaultValue(ret);
2230
633k
    } else {
2231
633k
  if (ctxt->dictNames)
2232
337k
      ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
2233
337k
                                 (xmlChar *) localname, NULL);
2234
296k
  else if (lname == NULL)
2235
286k
      ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
2236
10.1k
  else
2237
10.1k
      ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, lname, NULL);
2238
633k
  if (ret == NULL) {
2239
61
      xmlSAX2ErrMemory(ctxt);
2240
61
      return;
2241
61
  }
2242
633k
    }
2243
2244
    /*
2245
     * Build the namespace list
2246
     */
2247
761k
    for (i = 0,j = 0;j < nb_namespaces;j++) {
2248
125k
        pref = namespaces[i++];
2249
125k
  uri = namespaces[i++];
2250
125k
  ns = xmlNewNs(NULL, uri, pref);
2251
125k
  if (ns != NULL) {
2252
125k
      if (last == NULL) {
2253
70.7k
          ret->nsDef = last = ns;
2254
70.7k
      } else {
2255
55.0k
          last->next = ns;
2256
55.0k
    last = ns;
2257
55.0k
      }
2258
125k
      if ((URI != NULL) && (prefix == pref))
2259
51.0k
    ret->ns = ns;
2260
125k
  } else {
2261
69
            xmlSAX2ErrMemory(ctxt);
2262
69
      continue;
2263
69
  }
2264
2265
125k
        xmlParserNsUpdateSax(ctxt, pref, ns);
2266
2267
125k
#ifdef LIBXML_VALID_ENABLED
2268
125k
  if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
2269
7.05k
      ctxt->myDoc && ctxt->myDoc->intSubset) {
2270
7.05k
      ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
2271
7.05k
                                             ret, prefix, ns, uri);
2272
7.05k
  }
2273
125k
#endif /* LIBXML_VALID_ENABLED */
2274
125k
    }
2275
635k
    ctxt->nodemem = -1;
2276
2277
    /*
2278
     * Link the child element
2279
     */
2280
635k
    xmlSAX2AppendChild(ctxt, ret);
2281
2282
    /*
2283
     * We are parsing a new node.
2284
     */
2285
635k
    if (nodePush(ctxt, ret) < 0) {
2286
18
        xmlUnlinkNode(ret);
2287
18
        xmlFreeNode(ret);
2288
18
        return;
2289
18
    }
2290
2291
    /*
2292
     * Insert the defaulted attributes from the DTD only if requested:
2293
     */
2294
635k
    if ((nb_defaulted != 0) &&
2295
76.3k
        ((ctxt->loadsubset & XML_COMPLETE_ATTRS) == 0))
2296
10.4k
  nb_attributes -= nb_defaulted;
2297
2298
    /*
2299
     * Search the namespace if it wasn't already found
2300
     * Note that, if prefix is NULL, this searches for the default Ns
2301
     */
2302
635k
    if ((URI != NULL) && (ret->ns == NULL)) {
2303
30.7k
        ret->ns = xmlParserNsLookupSax(ctxt, prefix);
2304
30.7k
  if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
2305
484
            int res;
2306
2307
484
      res = xmlSearchNsSafe(ret, prefix, &ret->ns);
2308
484
            if (res < 0)
2309
4
                xmlSAX2ErrMemory(ctxt);
2310
484
  }
2311
30.7k
  if (ret->ns == NULL) {
2312
26
      ns = xmlNewNs(ret, NULL, prefix);
2313
26
      if (ns == NULL) {
2314
2315
0
          xmlSAX2ErrMemory(ctxt);
2316
0
    return;
2317
0
      }
2318
26
            if (prefix != NULL)
2319
10
                xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
2320
10
                             "Namespace prefix %s was not found\n",
2321
10
                             prefix, NULL);
2322
16
            else
2323
16
                xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
2324
16
                             "Namespace default prefix was not found\n",
2325
16
                             NULL, NULL);
2326
26
  }
2327
30.7k
    }
2328
2329
    /*
2330
     * process all the other attributes
2331
     */
2332
635k
    if (nb_attributes > 0) {
2333
107k
        xmlAttrPtr prev = NULL;
2334
2335
383k
        for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {
2336
275k
            xmlAttrPtr attr = NULL;
2337
2338
      /*
2339
       * Handle the rare case of an undefined attribute prefix
2340
       */
2341
275k
      if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) {
2342
64.8k
    if (ctxt->dictNames) {
2343
22.7k
        const xmlChar *fullname;
2344
2345
22.7k
        fullname = xmlDictQLookup(ctxt->dict, attributes[j+1],
2346
22.7k
                                  attributes[j]);
2347
22.7k
        if (fullname == NULL) {
2348
1
                        xmlSAX2ErrMemory(ctxt);
2349
1
                        return;
2350
1
                    }
2351
22.7k
                    attr = xmlSAX2AttributeNs(ctxt, fullname, NULL,
2352
22.7k
                                              attributes[j+3],
2353
22.7k
                                              attributes[j+4]);
2354
22.7k
                    goto have_attr;
2355
42.1k
    } else {
2356
42.1k
        lname = xmlBuildQName(attributes[j], attributes[j+1],
2357
42.1k
                              NULL, 0);
2358
42.1k
        if (lname == NULL) {
2359
4
                        xmlSAX2ErrMemory(ctxt);
2360
4
                        return;
2361
4
                    }
2362
42.1k
                    attr = xmlSAX2AttributeNs(ctxt, lname, NULL,
2363
42.1k
                                              attributes[j+3],
2364
42.1k
                                              attributes[j+4]);
2365
42.1k
                    xmlFree(lname);
2366
42.1k
                    goto have_attr;
2367
42.1k
    }
2368
64.8k
      }
2369
211k
            attr = xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],
2370
211k
                                      attributes[j+3], attributes[j+4]);
2371
275k
have_attr:
2372
275k
            if (attr == NULL)
2373
29
                continue;
2374
2375
            /* link at the end to preserve order */
2376
275k
            if (prev == NULL) {
2377
107k
                ctxt->node->properties = attr;
2378
168k
            } else {
2379
168k
                prev->next = attr;
2380
168k
                attr->prev = prev;
2381
168k
            }
2382
2383
275k
            prev = attr;
2384
275k
  }
2385
107k
    }
2386
2387
635k
#ifdef LIBXML_VALID_ENABLED
2388
    /*
2389
     * If it's the Document root, finish the DTD validation and
2390
     * check the document root element for validity
2391
     */
2392
635k
    if ((ctxt->validate) &&
2393
135k
        ((ctxt->vctxt.flags & XML_VCTXT_DTD_VALIDATED) == 0)) {
2394
3.79k
  int chk;
2395
2396
3.79k
  chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
2397
3.79k
  if (chk <= 0)
2398
76
      ctxt->valid = 0;
2399
3.79k
  if (chk < 0)
2400
0
      ctxt->wellFormed = 0;
2401
3.79k
  ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
2402
3.79k
  ctxt->vctxt.flags |= XML_VCTXT_DTD_VALIDATED;
2403
3.79k
    }
2404
635k
#endif /* LIBXML_VALID_ENABLED */
2405
635k
}
2406
2407
/**
2408
 * SAX2 callback when an element end has been detected by the parser.
2409
 * It provides the namespace information for the element.
2410
 *
2411
 * @param ctx  the user data (XML parser context)
2412
 * @param localname  the local name of the element
2413
 * @param prefix  the element namespace prefix if available
2414
 * @param URI  the element namespace name if available
2415
 */
2416
void
2417
xmlSAX2EndElementNs(void *ctx,
2418
                    const xmlChar * localname ATTRIBUTE_UNUSED,
2419
                    const xmlChar * prefix ATTRIBUTE_UNUSED,
2420
        const xmlChar * URI ATTRIBUTE_UNUSED)
2421
458k
{
2422
458k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2423
2424
458k
    if (ctx == NULL) return;
2425
458k
    ctxt->nodemem = -1;
2426
2427
458k
#ifdef LIBXML_VALID_ENABLED
2428
458k
    if (ctxt->validate && ctxt->wellFormed &&
2429
27.3k
        ctxt->myDoc && ctxt->myDoc->intSubset)
2430
27.3k
        ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
2431
27.3k
                                             ctxt->node);
2432
458k
#endif /* LIBXML_VALID_ENABLED */
2433
2434
    /*
2435
     * end of parsing of this node.
2436
     */
2437
458k
    nodePop(ctxt);
2438
458k
}
2439
2440
/**
2441
 * called when an entity #xmlSAX2Reference is detected.
2442
 *
2443
 * @param ctx  the user data (XML parser context)
2444
 * @param name  The entity name
2445
 */
2446
void
2447
xmlSAX2Reference(void *ctx, const xmlChar *name)
2448
32.7k
{
2449
32.7k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2450
32.7k
    xmlNodePtr ret;
2451
2452
32.7k
    if (ctx == NULL) return;
2453
32.7k
    ret = xmlNewReference(ctxt->myDoc, name);
2454
32.7k
    if (ret == NULL) {
2455
10
        xmlSAX2ErrMemory(ctxt);
2456
10
        return;
2457
10
    }
2458
2459
32.7k
    xmlSAX2AppendChild(ctxt, ret);
2460
32.7k
}
2461
2462
/**
2463
 * Append characters.
2464
 *
2465
 * @param ctxt  the parser context
2466
 * @param ch  a xmlChar string
2467
 * @param len  the number of xmlChar
2468
 * @param type  text or cdata
2469
 */
2470
static void
2471
xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
2472
            xmlElementType type)
2473
1.07M
{
2474
1.07M
    xmlNodePtr lastChild;
2475
1.07M
    xmlNodePtr parent;
2476
2477
1.07M
    if (ctxt == NULL)
2478
0
        return;
2479
2480
1.07M
    parent = ctxt->node;
2481
1.07M
    if (parent == NULL)
2482
0
        return;
2483
1.07M
    lastChild = parent->last;
2484
2485
    /*
2486
     * Try to merge with previous text node using size and capacity
2487
     * stored in the parser context to avoid naive concatenation.
2488
     *
2489
     * Don't merge CDATA sections. In HTML mode, CDATA is used for
2490
     * raw text which should be merged.
2491
     */
2492
1.07M
    if ((lastChild == NULL) ||
2493
869k
        (lastChild->type != type) ||
2494
854k
        ((!ctxt->html) && (type != XML_TEXT_NODE))) {
2495
854k
        xmlNode *node;
2496
2497
854k
        if (type == XML_TEXT_NODE)
2498
749k
            node = xmlSAX2TextNode(ctxt, parent->doc, ch, len);
2499
104k
        else
2500
104k
            node = xmlNewCDataBlock(parent->doc, ch, len);
2501
854k
  if (node == NULL) {
2502
88
      xmlSAX2ErrMemory(ctxt);
2503
88
      return;
2504
88
  }
2505
2506
853k
        if (lastChild == NULL) {
2507
207k
            parent->children = node;
2508
207k
            parent->last = node;
2509
207k
            node->parent = parent;
2510
646k
        } else {
2511
646k
            xmlSAX2AppendChild(ctxt, node);
2512
646k
        }
2513
2514
853k
        ctxt->nodelen = len;
2515
853k
        ctxt->nodemem = len + 1;
2516
853k
        lastChild = node;
2517
853k
    } else {
2518
223k
        xmlChar *content;
2519
223k
        int oldSize, newSize, capacity;
2520
223k
        int maxSize = (ctxt->options & XML_PARSE_HUGE) ?
2521
132k
                      XML_MAX_HUGE_LENGTH :
2522
223k
                      XML_MAX_TEXT_LENGTH;
2523
2524
223k
        content = lastChild->content;
2525
223k
        oldSize = ctxt->nodelen;
2526
223k
        capacity = ctxt->nodemem;
2527
2528
        /* Shouldn't happen */
2529
223k
        if ((content == NULL) || (capacity <= 0)) {
2530
0
            xmlFatalErr(ctxt, XML_ERR_INTERNAL_ERROR,
2531
0
                        "xmlSAX2Text: no content");
2532
0
            return;
2533
0
        }
2534
2535
223k
        if ((len > maxSize) || (oldSize > maxSize - len)) {
2536
0
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
2537
0
                        "Text node too long, try XML_PARSE_HUGE");
2538
0
            return;
2539
0
        }
2540
2541
223k
        newSize = oldSize + len;
2542
2543
223k
        if (newSize >= capacity) {
2544
82.1k
            if (newSize <= 20)
2545
43.8k
                capacity = 40;
2546
38.3k
            else
2547
38.3k
                capacity = newSize > INT_MAX / 2 ? INT_MAX : newSize * 2;
2548
2549
            /*
2550
             * If the content was stored in properties or in
2551
             * the dictionary, don't realloc.
2552
             */
2553
82.1k
            if ((content == (xmlChar *) &lastChild->properties) ||
2554
48.1k
                ((ctxt->nodemem == oldSize + 1) &&
2555
34.1k
                 (xmlDictOwns(ctxt->dict, content)))) {
2556
34.1k
                xmlChar *newContent;
2557
2558
34.1k
                newContent = xmlMalloc(capacity);
2559
34.1k
                if (newContent == NULL) {
2560
12
                    xmlSAX2ErrMemory(ctxt);
2561
12
                    return;
2562
12
                }
2563
2564
34.1k
                memcpy(newContent, content, oldSize);
2565
34.1k
                lastChild->properties = NULL;
2566
34.1k
                content = newContent;
2567
47.9k
            } else {
2568
47.9k
                content = xmlRealloc(content, capacity);
2569
47.9k
                if (content == NULL) {
2570
11
                    xmlSAX2ErrMemory(ctxt);
2571
11
                    return;
2572
11
                }
2573
47.9k
            }
2574
2575
82.1k
            ctxt->nodemem = capacity;
2576
82.1k
            lastChild->content = content;
2577
82.1k
        }
2578
2579
223k
        memcpy(&content[oldSize], ch, len);
2580
223k
        content[newSize] = 0;
2581
223k
        ctxt->nodelen = newSize;
2582
223k
    }
2583
2584
1.07M
    if ((lastChild != NULL) &&
2585
1.07M
        (type == XML_TEXT_NODE) &&
2586
973k
        (ctxt->input != NULL)) {
2587
973k
        if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
2588
886k
            lastChild->line = ctxt->input->line;
2589
86.1k
        else {
2590
86.1k
            lastChild->line = USHRT_MAX;
2591
86.1k
            if (ctxt->options & XML_PARSE_BIG_LINES)
2592
20.2k
                lastChild->psvi = XML_INT_TO_PTR(ctxt->input->line);
2593
86.1k
        }
2594
973k
    }
2595
1.07M
}
2596
2597
/**
2598
 * receiving some chars from the parser.
2599
 *
2600
 * @param ctx  the user data (XML parser context)
2601
 * @param ch  a xmlChar string
2602
 * @param len  the number of xmlChar
2603
 */
2604
void
2605
xmlSAX2Characters(void *ctx, const xmlChar *ch, int len)
2606
973k
{
2607
973k
    xmlSAX2Text((xmlParserCtxtPtr) ctx, ch, len, XML_TEXT_NODE);
2608
973k
}
2609
2610
/**
2611
 * receiving some ignorable whitespaces from the parser.
2612
 * UNUSED: by default the DOM building will use #xmlSAX2Characters
2613
 *
2614
 * @param ctx  the user data (XML parser context)
2615
 * @param ch  a xmlChar string
2616
 * @param len  the number of xmlChar
2617
 */
2618
void
2619
xmlSAX2IgnorableWhitespace(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
2620
0
{
2621
0
}
2622
2623
/**
2624
 * A processing instruction has been parsed.
2625
 *
2626
 * @param ctx  the user data (XML parser context)
2627
 * @param target  the target name
2628
 * @param data  the PI data's
2629
 */
2630
void
2631
xmlSAX2ProcessingInstruction(void *ctx, const xmlChar *target,
2632
                      const xmlChar *data)
2633
177k
{
2634
177k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2635
177k
    xmlNodePtr ret;
2636
2637
177k
    if (ctx == NULL) return;
2638
2639
177k
    ret = xmlNewDocPI(ctxt->myDoc, target, data);
2640
177k
    if (ret == NULL) {
2641
5
        xmlSAX2ErrMemory(ctxt);
2642
5
        return;
2643
5
    }
2644
2645
177k
    xmlSAX2AppendChild(ctxt, ret);
2646
177k
}
2647
2648
/**
2649
 * A #xmlSAX2Comment has been parsed.
2650
 *
2651
 * @param ctx  the user data (XML parser context)
2652
 * @param value  the #xmlSAX2Comment content
2653
 */
2654
void
2655
xmlSAX2Comment(void *ctx, const xmlChar *value)
2656
406k
{
2657
406k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2658
406k
    xmlNodePtr ret;
2659
2660
406k
    if (ctx == NULL) return;
2661
2662
406k
    ret = xmlNewDocComment(ctxt->myDoc, value);
2663
406k
    if (ret == NULL) {
2664
8
        xmlSAX2ErrMemory(ctxt);
2665
8
        return;
2666
8
    }
2667
2668
406k
    xmlSAX2AppendChild(ctxt, ret);
2669
406k
}
2670
2671
/**
2672
 * called when a pcdata block has been parsed
2673
 *
2674
 * @param ctx  the user data (XML parser context)
2675
 * @param value  The pcdata content
2676
 * @param len  the block length
2677
 */
2678
void
2679
xmlSAX2CDataBlock(void *ctx, const xmlChar *value, int len)
2680
104k
{
2681
104k
    xmlSAX2Text((xmlParserCtxtPtr) ctx, value, len, XML_CDATA_SECTION_NODE);
2682
104k
}
2683
2684
#ifdef LIBXML_SAX1_ENABLED
2685
/**
2686
 * Has no effect.
2687
 *
2688
 * @deprecated Use parser option XML_PARSE_SAX1.
2689
 *
2690
 * @param version  the version, must be 2
2691
 * @returns 2 in case of success and -1 in case of error.
2692
 */
2693
int
2694
xmlSAXDefaultVersion(int version)
2695
0
{
2696
0
    if (version != 2)
2697
0
        return(-1);
2698
0
    return(2);
2699
0
}
2700
#endif /* LIBXML_SAX1_ENABLED */
2701
2702
/**
2703
 * Initialize the default XML SAX handler according to the version
2704
 *
2705
 * @param hdlr  the SAX handler
2706
 * @param version  the version, 1 or 2
2707
 * @returns 0 in case of success and -1 in case of error.
2708
 */
2709
int
2710
xmlSAXVersion(xmlSAXHandler *hdlr, int version)
2711
87.1k
{
2712
87.1k
    if (hdlr == NULL) return(-1);
2713
87.1k
    if (version == 2) {
2714
87.1k
  hdlr->startElementNs = xmlSAX2StartElementNs;
2715
87.1k
  hdlr->endElementNs = xmlSAX2EndElementNs;
2716
87.1k
  hdlr->serror = NULL;
2717
87.1k
  hdlr->initialized = XML_SAX2_MAGIC;
2718
87.1k
#ifdef LIBXML_SAX1_ENABLED
2719
87.1k
    } else if (version == 1) {
2720
0
  hdlr->initialized = 1;
2721
0
#endif /* LIBXML_SAX1_ENABLED */
2722
0
    } else
2723
0
        return(-1);
2724
87.1k
#ifdef LIBXML_SAX1_ENABLED
2725
87.1k
    hdlr->startElement = xmlSAX2StartElement;
2726
87.1k
    hdlr->endElement = xmlSAX2EndElement;
2727
#else
2728
    hdlr->startElement = NULL;
2729
    hdlr->endElement = NULL;
2730
#endif /* LIBXML_SAX1_ENABLED */
2731
87.1k
    hdlr->internalSubset = xmlSAX2InternalSubset;
2732
87.1k
    hdlr->externalSubset = xmlSAX2ExternalSubset;
2733
87.1k
    hdlr->isStandalone = xmlSAX2IsStandalone;
2734
87.1k
    hdlr->hasInternalSubset = xmlSAX2HasInternalSubset;
2735
87.1k
    hdlr->hasExternalSubset = xmlSAX2HasExternalSubset;
2736
87.1k
    hdlr->resolveEntity = xmlSAX2ResolveEntity;
2737
87.1k
    hdlr->getEntity = xmlSAX2GetEntity;
2738
87.1k
    hdlr->getParameterEntity = xmlSAX2GetParameterEntity;
2739
87.1k
    hdlr->entityDecl = xmlSAX2EntityDecl;
2740
87.1k
    hdlr->attributeDecl = xmlSAX2AttributeDecl;
2741
87.1k
    hdlr->elementDecl = xmlSAX2ElementDecl;
2742
87.1k
    hdlr->notationDecl = xmlSAX2NotationDecl;
2743
87.1k
    hdlr->unparsedEntityDecl = xmlSAX2UnparsedEntityDecl;
2744
87.1k
    hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
2745
87.1k
    hdlr->startDocument = xmlSAX2StartDocument;
2746
87.1k
    hdlr->endDocument = xmlSAX2EndDocument;
2747
87.1k
    hdlr->reference = xmlSAX2Reference;
2748
87.1k
    hdlr->characters = xmlSAX2Characters;
2749
87.1k
    hdlr->cdataBlock = xmlSAX2CDataBlock;
2750
87.1k
    hdlr->ignorableWhitespace = xmlSAX2Characters;
2751
87.1k
    hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
2752
87.1k
    hdlr->comment = xmlSAX2Comment;
2753
87.1k
    hdlr->warning = xmlParserWarning;
2754
87.1k
    hdlr->error = xmlParserError;
2755
87.1k
    hdlr->fatalError = xmlParserError;
2756
2757
87.1k
    return(0);
2758
87.1k
}
2759
2760
/**
2761
 * Initialize the default XML SAX2 handler
2762
 *
2763
 * @param hdlr  the SAX handler
2764
 * @param warning  flag if non-zero sets the handler warning procedure
2765
 */
2766
void
2767
xmlSAX2InitDefaultSAXHandler(xmlSAXHandler *hdlr, int warning)
2768
0
{
2769
0
    if ((hdlr == NULL) || (hdlr->initialized != 0))
2770
0
  return;
2771
2772
0
    xmlSAXVersion(hdlr, 2);
2773
0
    if (warning == 0)
2774
0
  hdlr->warning = NULL;
2775
0
}
2776
2777
/**
2778
 * Initialize the default SAX2 handler
2779
 *
2780
 * @deprecated This function is a no-op. Call #xmlInitParser to
2781
 * initialize the library.
2782
 *
2783
 */
2784
void
2785
xmlDefaultSAXHandlerInit(void)
2786
0
{
2787
0
}
2788
2789
#ifdef LIBXML_HTML_ENABLED
2790
2791
/**
2792
 * Initialize the default HTML SAX2 handler
2793
 *
2794
 * @param hdlr  the SAX handler
2795
 */
2796
void
2797
xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr)
2798
0
{
2799
0
    if ((hdlr == NULL) || (hdlr->initialized != 0))
2800
0
  return;
2801
2802
0
    hdlr->internalSubset = xmlSAX2InternalSubset;
2803
0
    hdlr->externalSubset = NULL;
2804
0
    hdlr->isStandalone = NULL;
2805
0
    hdlr->hasInternalSubset = NULL;
2806
0
    hdlr->hasExternalSubset = NULL;
2807
0
    hdlr->resolveEntity = NULL;
2808
0
    hdlr->getEntity = xmlSAX2GetEntity;
2809
0
    hdlr->getParameterEntity = NULL;
2810
0
    hdlr->entityDecl = NULL;
2811
0
    hdlr->attributeDecl = NULL;
2812
0
    hdlr->elementDecl = NULL;
2813
0
    hdlr->notationDecl = NULL;
2814
0
    hdlr->unparsedEntityDecl = NULL;
2815
0
    hdlr->setDocumentLocator = xmlSAX2SetDocumentLocator;
2816
0
    hdlr->startDocument = xmlSAX2StartDocument;
2817
0
    hdlr->endDocument = xmlSAX2EndDocument;
2818
0
    hdlr->startElement = xmlSAX2StartElement;
2819
0
    hdlr->endElement = xmlSAX2EndElement;
2820
0
    hdlr->reference = NULL;
2821
0
    hdlr->characters = xmlSAX2Characters;
2822
0
    hdlr->cdataBlock = xmlSAX2CDataBlock;
2823
0
    hdlr->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
2824
0
    hdlr->processingInstruction = xmlSAX2ProcessingInstruction;
2825
0
    hdlr->comment = xmlSAX2Comment;
2826
0
    hdlr->warning = xmlParserWarning;
2827
0
    hdlr->error = xmlParserError;
2828
0
    hdlr->fatalError = xmlParserError;
2829
2830
0
    hdlr->initialized = 1;
2831
0
}
2832
2833
/**
2834
 * @deprecated This function is a no-op. Call #xmlInitParser to
2835
 * initialize the library.
2836
 */
2837
void
2838
htmlDefaultSAXHandlerInit(void)
2839
0
{
2840
0
}
2841
2842
#endif /* LIBXML_HTML_ENABLED */