Coverage Report

Created: 2026-11-11 06:09

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
4.34k
xmlSAX2ErrMemory(xmlParserCtxtPtr ctxt) {
43
4.34k
    xmlCtxtErrMemory(ctxt);
44
4.34k
}
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
15.7k
{
60
15.7k
    xmlCtxtErr(ctxt, NULL, XML_FROM_DTD, error, XML_ERR_ERROR,
61
15.7k
               str1, str2, NULL, 0, msg, str1, str2);
62
15.7k
    if (ctxt != NULL)
63
15.7k
  ctxt->valid = 0;
64
15.7k
}
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
516
{
80
516
    xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_FATAL,
81
516
               str1, str2, NULL, 0, msg, str1, str2);
82
516
}
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
1.99k
{
96
1.99k
    xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_ERROR,
97
1.99k
               str1, NULL, NULL, 0, msg, str1);
98
1.99k
}
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
8.16k
{
112
8.16k
    xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER, error, XML_ERR_WARNING,
113
8.16k
               str1, NULL, NULL, 0, msg, str1);
114
8.16k
}
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
66.9k
{
129
66.9k
    xmlCtxtErr(ctxt, NULL, XML_FROM_NAMESPACE, error, XML_ERR_WARNING,
130
66.9k
               str1, str2, NULL, 0, msg, str1, str2);
131
66.9k
}
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
48.3k
{
243
48.3k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
244
48.3k
    xmlDtdPtr dtd;
245
48.3k
    if (ctx == NULL) return;
246
247
48.3k
    if (ctxt->myDoc == NULL)
248
0
  return;
249
48.3k
    if ((ctxt->html) && (ctxt->instate != XML_PARSER_MISC))
250
0
        return;
251
48.3k
    dtd = xmlGetIntSubset(ctxt->myDoc);
252
48.3k
    if (dtd != NULL) {
253
0
  xmlUnlinkNode((xmlNodePtr) dtd);
254
0
  xmlFreeDtd(dtd);
255
0
  ctxt->myDoc->intSubset = NULL;
256
0
    }
257
48.3k
    ctxt->myDoc->intSubset =
258
48.3k
  xmlCreateIntSubset(ctxt->myDoc, name, publicId, systemId);
259
48.3k
    if (ctxt->myDoc->intSubset == NULL)
260
305
        xmlSAX2ErrMemory(ctxt);
261
48.3k
}
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
42.7k
{
275
42.7k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
276
42.7k
    if (ctx == NULL) return;
277
42.7k
    if ((systemId != NULL) &&
278
9.69k
        ((ctxt->options & XML_PARSE_NO_XXE) == 0) &&
279
8.77k
        (((ctxt->validate) || (ctxt->loadsubset & ~XML_SKIP_IDS)) &&
280
7.92k
   (ctxt->wellFormed && ctxt->myDoc))) {
281
  /*
282
   * Try to fetch and parse the external subset.
283
   */
284
5.72k
  xmlParserInputPtr oldinput;
285
5.72k
  int oldinputNr;
286
5.72k
  int oldinputMax;
287
5.72k
  xmlParserInputPtr *oldinputTab;
288
5.72k
  xmlParserInputPtr input = NULL;
289
5.72k
  xmlChar *oldencoding;
290
5.72k
        unsigned long consumed;
291
5.72k
        size_t buffered;
292
5.72k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
293
5.72k
        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
5.72k
  if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL))
302
5.72k
      input = ctxt->sax->resolveEntity(ctxt->userData, publicId,
303
5.72k
                                       systemId);
304
5.72k
  if (input == NULL) {
305
2.55k
      return;
306
2.55k
  }
307
308
3.17k
  if (xmlNewDtd(ctxt->myDoc, name, publicId, systemId) == NULL) {
309
16
            xmlSAX2ErrMemory(ctxt);
310
16
            xmlFreeInputStream(input);
311
16
            return;
312
16
        }
313
314
  /*
315
   * make sure we won't destroy the main document context
316
   */
317
3.15k
  oldinput = ctxt->input;
318
3.15k
  oldinputNr = ctxt->inputNr;
319
3.15k
  oldinputMax = ctxt->inputMax;
320
3.15k
  oldinputTab = ctxt->inputTab;
321
3.15k
  oldencoding = ctxt->encoding;
322
3.15k
  ctxt->encoding = NULL;
323
324
3.15k
  ctxt->inputTab = xmlMalloc(inputMax * sizeof(xmlParserInputPtr));
325
3.15k
  if (ctxt->inputTab == NULL) {
326
3
      xmlSAX2ErrMemory(ctxt);
327
3
            goto error;
328
3
  }
329
3.15k
  ctxt->inputNr = 0;
330
3.15k
  ctxt->inputMax = inputMax;
331
3.15k
  ctxt->input = NULL;
332
3.15k
  if (xmlCtxtPushInput(ctxt, input) < 0)
333
13
            goto error;
334
335
3.13k
  if (input->filename == NULL)
336
0
      input->filename = (char *) xmlCanonicPath(systemId);
337
3.13k
  input->line = 1;
338
3.13k
  input->col = 1;
339
3.13k
  input->base = ctxt->input->cur;
340
3.13k
  input->cur = ctxt->input->cur;
341
3.13k
  input->free = NULL;
342
343
  /*
344
   * let's parse that entity knowing it's an external subset.
345
   */
346
3.13k
  xmlParseExternalSubset(ctxt, publicId, systemId);
347
348
        /*
349
   * Free up the external entities
350
   */
351
352
3.30k
  while (ctxt->inputNr > 1)
353
168
      xmlFreeInputStream(xmlCtxtPopInput(ctxt));
354
355
3.13k
        consumed = ctxt->input->consumed;
356
3.13k
        buffered = ctxt->input->cur - ctxt->input->base;
357
3.13k
        if (buffered > ULONG_MAX - consumed)
358
0
            consumed = ULONG_MAX;
359
3.13k
        else
360
3.13k
            consumed += buffered;
361
3.13k
        if (consumed > ULONG_MAX - ctxt->sizeentities)
362
0
            ctxt->sizeentities = ULONG_MAX;
363
3.13k
        else
364
3.13k
            ctxt->sizeentities += consumed;
365
366
3.15k
error:
367
3.15k
  xmlFreeInputStream(input);
368
3.15k
        xmlFree(ctxt->inputTab);
369
370
  /*
371
   * Restore the parsing context of the main entity
372
   */
373
3.15k
  ctxt->input = oldinput;
374
3.15k
  ctxt->inputNr = oldinputNr;
375
3.15k
  ctxt->inputMax = oldinputMax;
376
3.15k
  ctxt->inputTab = oldinputTab;
377
3.15k
  if (ctxt->encoding != NULL)
378
117
      xmlFree(ctxt->encoding);
379
3.15k
  ctxt->encoding = oldencoding;
380
  /* ctxt->wellFormed = oldwellFormed; */
381
3.15k
    }
382
42.7k
}
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
5.72k
{
397
5.72k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
398
5.72k
    xmlParserInputPtr ret = NULL;
399
5.72k
    xmlChar *URI = NULL;
400
401
5.72k
    if (ctx == NULL) return(NULL);
402
403
5.72k
    if (systemId != NULL) {
404
5.72k
        const xmlChar *base = NULL;
405
5.72k
        int res;
406
407
5.72k
        if (ctxt->input != NULL)
408
5.72k
            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
5.72k
        if (base == NULL)
415
0
            base = BAD_CAST ctxt->directory;
416
417
5.72k
        if ((xmlStrlen(systemId) > XML_MAX_URI_LENGTH) ||
418
5.71k
            (xmlStrlen(base) > XML_MAX_URI_LENGTH)) {
419
6
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
420
6
            return(NULL);
421
6
        }
422
5.71k
        res = xmlBuildURISafe(systemId, base, &URI);
423
5.71k
        if (URI == NULL) {
424
370
            if (res < 0)
425
145
                xmlSAX2ErrMemory(ctxt);
426
225
            else
427
225
                xmlWarnMsg(ctxt, XML_ERR_INVALID_URI,
428
225
                           "Can't resolve URI: %s\n", systemId);
429
370
            return(NULL);
430
370
        }
431
5.34k
        if (xmlStrlen(URI) > XML_MAX_URI_LENGTH) {
432
5
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
433
5
            xmlFree(URI);
434
5
            return(NULL);
435
5
        }
436
5.34k
    }
437
438
5.34k
    ret = xmlLoadResource(ctxt, (const char *) URI,
439
5.34k
                          (const char *) publicId, XML_RESOURCE_DTD);
440
441
5.34k
    xmlFree(URI);
442
5.34k
    return(ret);
443
5.72k
}
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
1.90M
{
455
1.90M
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
456
1.90M
    xmlEntityPtr ret = NULL;
457
458
1.90M
    if (ctx == NULL) return(NULL);
459
460
1.90M
    if (ctxt->inSubset == 0) {
461
1.86M
  ret = xmlGetPredefinedEntity(name);
462
1.86M
  if (ret != NULL)
463
218k
      return(ret);
464
1.86M
    }
465
1.68M
    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->standalone == 1)) {
466
1.05k
  if (ctxt->inSubset == 2) {
467
215
      ctxt->myDoc->standalone = 0;
468
215
      ret = xmlGetDocEntity(ctxt->myDoc, name);
469
215
      ctxt->myDoc->standalone = 1;
470
835
  } else {
471
835
      ret = xmlGetDocEntity(ctxt->myDoc, name);
472
835
      if (ret == NULL) {
473
629
    ctxt->myDoc->standalone = 0;
474
629
    ret = xmlGetDocEntity(ctxt->myDoc, name);
475
629
    if (ret != NULL) {
476
213
        xmlFatalErrMsg(ctxt, XML_ERR_NOT_STANDALONE,
477
213
   "Entity(%s) document marked standalone but requires external subset\n",
478
213
           name, NULL);
479
213
    }
480
629
    ctxt->myDoc->standalone = 1;
481
629
      }
482
835
  }
483
1.68M
    } else {
484
1.68M
  ret = xmlGetDocEntity(ctxt->myDoc, name);
485
1.68M
    }
486
1.68M
    return(ret);
487
1.90M
}
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
504k
{
499
504k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
500
504k
    xmlEntityPtr ret;
501
502
504k
    if (ctx == NULL) return(NULL);
503
504
504k
    ret = xmlGetParameterEntity(ctxt->myDoc, name);
505
504k
    return(ret);
506
504k
}
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
77.3k
{
523
77.3k
    xmlEntityPtr ent;
524
77.3k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
525
77.3k
    int extSubset;
526
77.3k
    int res;
527
528
77.3k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
529
0
        return;
530
531
77.3k
    extSubset = ctxt->inSubset == 2;
532
77.3k
    res = xmlAddEntity(ctxt->myDoc, extSubset, name, type, publicId, systemId,
533
77.3k
                       content, &ent);
534
77.3k
    switch (res) {
535
51.9k
        case XML_ERR_OK:
536
51.9k
            break;
537
190
        case XML_ERR_NO_MEMORY:
538
190
            xmlSAX2ErrMemory(ctxt);
539
190
            return;
540
22.9k
        case XML_WAR_ENTITY_REDEFINED:
541
22.9k
            if (ctxt->pedantic) {
542
5.22k
                if (extSubset)
543
1.33k
                    xmlWarnMsg(ctxt, res, "Entity(%s) already defined in the"
544
1.33k
                               " external subset\n", name);
545
3.89k
                else
546
3.89k
                    xmlWarnMsg(ctxt, res, "Entity(%s) already defined in the"
547
3.89k
                               " internal subset\n", name);
548
5.22k
            }
549
22.9k
            return;
550
2.33k
        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.33k
            xmlWarnMsg(ctxt, res, "Invalid redeclaration of predefined"
556
2.33k
                       " entity '%s'", name);
557
2.33k
            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
77.3k
    }
564
565
51.9k
    if ((ent->URI == NULL) && (systemId != NULL)) {
566
15.7k
        xmlChar *URI;
567
15.7k
        const char *base = NULL;
568
15.7k
        int i;
569
570
15.7k
        for (i = ctxt->inputNr - 1; i >= 0; i--) {
571
15.7k
            if (ctxt->inputTab[i]->filename != NULL) {
572
15.7k
                base = ctxt->inputTab[i]->filename;
573
15.7k
                break;
574
15.7k
            }
575
15.7k
        }
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
15.7k
        if (base == NULL)
582
0
            base = ctxt->directory;
583
584
15.7k
        res = xmlBuildURISafe(systemId, (const xmlChar *) base, &URI);
585
586
15.7k
        if (URI == NULL) {
587
459
            if (res < 0) {
588
72
                xmlSAX2ErrMemory(ctxt);
589
387
            } else {
590
387
                xmlWarnMsg(ctxt, XML_ERR_INVALID_URI,
591
387
                           "Can't resolve URI: %s\n", systemId);
592
387
            }
593
15.2k
        } else if (xmlStrlen(URI) > XML_MAX_URI_LENGTH) {
594
105
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
595
105
            xmlFree(URI);
596
15.1k
        } else {
597
15.1k
            ent->URI = URI;
598
15.1k
        }
599
15.7k
    }
600
51.9k
}
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
114k
{
618
114k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
619
114k
    xmlAttributePtr attr;
620
114k
    const xmlChar *name = NULL;
621
114k
    xmlChar *prefix = NULL;
622
623
    /* Avoid unused variable warning if features are disabled. */
624
114k
    (void) attr;
625
626
114k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
627
0
        return;
628
629
114k
    if ((xmlStrEqual(fullname, BAD_CAST "xml:id")) &&
630
517
        (type != XML_ATTRIBUTE_ID)) {
631
219
  xmlErrId(ctxt, XML_DTD_XMLID_TYPE,
632
219
        "xml:id : attribute type should be ID\n", NULL);
633
219
    }
634
114k
    name = xmlSplitQName4(fullname, &prefix);
635
114k
    if (name == NULL)
636
36
        xmlSAX2ErrMemory(ctxt);
637
114k
    ctxt->vctxt.valid = 1;
638
114k
    if (ctxt->inSubset == 1)
639
56.2k
  attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, elem,
640
56.2k
         name, prefix, (xmlAttributeType) type,
641
56.2k
         (xmlAttributeDefault) def, defaultValue, tree);
642
58.6k
    else if (ctxt->inSubset == 2)
643
58.6k
  attr = xmlAddAttributeDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, elem,
644
58.6k
     name, prefix, (xmlAttributeType) type,
645
58.6k
     (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
114k
#ifdef LIBXML_VALID_ENABLED
655
114k
    if (ctxt->vctxt.valid == 0)
656
9.22k
  ctxt->valid = 0;
657
114k
    if ((attr != NULL) && (ctxt->validate) && (ctxt->wellFormed) &&
658
27.4k
        (ctxt->myDoc->intSubset != NULL))
659
27.4k
  ctxt->valid &= xmlValidateAttributeDecl(&ctxt->vctxt, ctxt->myDoc,
660
27.4k
                                          attr);
661
114k
#endif /* LIBXML_VALID_ENABLED */
662
114k
    if (prefix != NULL)
663
7.63k
  xmlFree(prefix);
664
114k
}
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
22.2k
{
678
22.2k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
679
22.2k
    xmlElementPtr elem = NULL;
680
681
    /* Avoid unused variable warning if features are disabled. */
682
22.2k
    (void) elem;
683
684
22.2k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
685
0
        return;
686
687
22.2k
    if (ctxt->inSubset == 1)
688
15.3k
        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->intSubset,
689
15.3k
                                 name, (xmlElementTypeVal) type, content);
690
6.91k
    else if (ctxt->inSubset == 2)
691
6.91k
        elem = xmlAddElementDecl(&ctxt->vctxt, ctxt->myDoc->extSubset,
692
6.91k
                                 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
22.2k
#ifdef LIBXML_VALID_ENABLED
700
22.2k
    if (elem == NULL)
701
3.54k
        ctxt->valid = 0;
702
22.2k
    if (ctxt->validate && ctxt->wellFormed &&
703
10.5k
        ctxt->myDoc && ctxt->myDoc->intSubset)
704
10.5k
        ctxt->valid &=
705
10.5k
            xmlValidateElementDecl(&ctxt->vctxt, ctxt->myDoc, elem);
706
22.2k
#endif /* LIBXML_VALID_ENABLED */
707
22.2k
}
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
5.45k
{
721
5.45k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
722
5.45k
    xmlNotationPtr nota = NULL;
723
724
    /* Avoid unused variable warning if features are disabled. */
725
5.45k
    (void) nota;
726
727
5.45k
    if ((ctxt == NULL) || (ctxt->myDoc == NULL))
728
0
        return;
729
730
5.45k
    if ((publicId == NULL) && (systemId == NULL)) {
731
303
  xmlFatalErrMsg(ctxt, XML_ERR_NOTATION_PROCESSING,
732
303
       "SAX.xmlSAX2NotationDecl(%s) externalID or PublicID missing\n",
733
303
                 name, NULL);
734
303
  return;
735
5.14k
    } else if (ctxt->inSubset == 1)
736
2.64k
  nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->intSubset, name,
737
2.64k
                              publicId, systemId);
738
2.50k
    else if (ctxt->inSubset == 2)
739
2.50k
  nota = xmlAddNotationDecl(&ctxt->vctxt, ctxt->myDoc->extSubset, name,
740
2.50k
                              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
5.14k
#ifdef LIBXML_VALID_ENABLED
748
5.14k
    if (nota == NULL) ctxt->valid = 0;
749
5.14k
    if ((ctxt->validate) && (ctxt->wellFormed) &&
750
1.61k
        (ctxt->myDoc->intSubset != NULL))
751
1.61k
  ctxt->valid &= xmlValidateNotationDecl(&ctxt->vctxt, ctxt->myDoc,
752
1.61k
                                         nota);
753
5.14k
#endif /* LIBXML_VALID_ENABLED */
754
5.14k
}
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
938
{
770
938
    xmlSAX2EntityDecl(ctx, name, XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,
771
938
                      publicId, systemId, (xmlChar *) notationName);
772
938
}
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
86.4k
{
784
86.4k
}
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
83.0k
{
794
83.0k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
795
83.0k
    xmlDocPtr doc;
796
797
83.0k
    if (ctx == NULL) return;
798
799
83.0k
#ifdef LIBXML_HTML_ENABLED
800
83.0k
    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
83.0k
#endif
811
83.0k
    {
812
83.0k
  doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
813
83.0k
  if (doc != NULL) {
814
82.7k
      doc->properties = 0;
815
82.7k
      if (ctxt->options & XML_PARSE_OLD10)
816
31.1k
          doc->properties |= XML_DOC_OLD10;
817
82.7k
      doc->parseFlags = ctxt->options;
818
82.7k
      doc->standalone = ctxt->standalone;
819
82.7k
  } else {
820
291
      xmlSAX2ErrMemory(ctxt);
821
291
      return;
822
291
  }
823
82.7k
  if ((ctxt->dictNames) && (doc != NULL)) {
824
53.3k
      doc->dict = ctxt->dict;
825
53.3k
      xmlDictReference(doc->dict);
826
53.3k
  }
827
82.7k
    }
828
82.7k
    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
829
82.7k
  (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
830
82.7k
  ctxt->myDoc->URL = xmlPathToURI((const xmlChar *)ctxt->input->filename);
831
82.7k
  if (ctxt->myDoc->URL == NULL)
832
396
      xmlSAX2ErrMemory(ctxt);
833
82.7k
    }
834
82.7k
}
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
74.5k
{
844
74.5k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
845
74.5k
    xmlDocPtr doc;
846
847
74.5k
    if (ctx == NULL) return;
848
74.5k
#ifdef LIBXML_VALID_ENABLED
849
74.5k
    if (ctxt->validate && ctxt->wellFormed &&
850
627
        ctxt->myDoc && ctxt->myDoc->intSubset)
851
627
  ctxt->valid &= xmlValidateDocumentFinal(&ctxt->vctxt, ctxt->myDoc);
852
74.5k
#endif /* LIBXML_VALID_ENABLED */
853
854
74.5k
    doc = ctxt->myDoc;
855
74.5k
    if (doc == NULL)
856
2.06k
        return;
857
858
72.4k
    if (doc->encoding == NULL) {
859
72.4k
        const xmlChar *encoding = xmlGetActualEncoding(ctxt);
860
861
72.4k
        if (encoding != NULL) {
862
2.74k
            doc->encoding = xmlStrdup(encoding);
863
2.74k
            if (doc->encoding == NULL)
864
20
                xmlSAX2ErrMemory(ctxt);
865
2.74k
        }
866
72.4k
    }
867
868
72.4k
#ifdef LIBXML_HTML_ENABLED
869
72.4k
    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
72.4k
#endif /* LIBXML_HTML_ENABLED */
880
72.4k
    {
881
72.4k
        if (ctxt->wellFormed) {
882
1.12k
            doc->properties |= XML_DOC_WELLFORMED;
883
1.12k
            if (ctxt->valid)
884
445
                doc->properties |= XML_DOC_DTDVALID;
885
1.12k
            if (ctxt->nsWellFormed)
886
1.05k
                doc->properties |= XML_DOC_NSVALID;
887
1.12k
        }
888
889
72.4k
        if (ctxt->options & XML_PARSE_OLD10)
890
27.5k
            doc->properties |= XML_DOC_OLD10;
891
72.4k
    }
892
72.4k
}
893
894
static void
895
1.49M
xmlSAX2AppendChild(xmlParserCtxtPtr ctxt, xmlNodePtr node) {
896
1.49M
    xmlNodePtr parent;
897
1.49M
    xmlNodePtr last;
898
899
1.49M
    if (ctxt->inSubset == 1) {
900
14.4k
  parent = (xmlNodePtr) ctxt->myDoc->intSubset;
901
1.48M
    } else if (ctxt->inSubset == 2) {
902
234k
  parent = (xmlNodePtr) ctxt->myDoc->extSubset;
903
1.24M
    } else {
904
1.24M
        parent = ctxt->node;
905
1.24M
        if (parent == NULL)
906
158k
            parent = (xmlNodePtr) ctxt->myDoc;
907
1.24M
    }
908
909
1.49M
    last = parent->last;
910
1.49M
    if (last == NULL) {
911
350k
        parent->children = node;
912
1.14M
    } else {
913
1.14M
        last->next = node;
914
1.14M
        node->prev = last;
915
1.14M
    }
916
917
1.49M
    parent->last = node;
918
1.49M
    node->parent = parent;
919
920
1.49M
    if ((node->type != XML_TEXT_NODE) &&
921
1.33M
  (ctxt->input != NULL)) {
922
1.33M
        if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
923
1.29M
            node->line = ctxt->input->line;
924
41.6k
        else
925
41.6k
            node->line = USHRT_MAX;
926
1.33M
    }
927
1.49M
}
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
11.0k
{
943
11.0k
    xmlCtxtErr(ctxt, NULL, XML_FROM_NAMESPACE, error, XML_ERR_ERROR,
944
11.0k
               str1, str2, NULL, 0, msg, str1, str2);
945
11.0k
}
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
153k
{
961
153k
    xmlAttrPtr ret;
962
153k
    const xmlChar *name;
963
153k
    xmlChar *ns;
964
153k
    xmlNsPtr namespace;
965
966
    /*
967
     * Split the full name into a namespace prefix and the tag name
968
     */
969
153k
    name = xmlSplitQName4(fullname, &ns);
970
153k
    if (name == NULL) {
971
40
        xmlSAX2ErrMemory(ctxt);
972
40
        return;
973
40
    }
974
975
    /*
976
     * Check whether it's a namespace definition
977
     */
978
153k
    if ((ns == NULL) &&
979
102k
        (name[0] == 'x') && (name[1] == 'm') && (name[2] == 'l') &&
980
60.6k
        (name[3] == 'n') && (name[4] == 's') && (name[5] == 0)) {
981
58.5k
  xmlNsPtr nsret;
982
58.5k
  xmlChar *val;
983
984
        /* Avoid unused variable warning if features are disabled. */
985
58.5k
        (void) nsret;
986
987
58.5k
        if (!ctxt->replaceEntities) {
988
            /* TODO: normalize if needed */
989
20.8k
      val = xmlExpandEntitiesInAttValue(ctxt, value, /* normalize */ 0);
990
20.8k
      if (val == NULL) {
991
62
          xmlSAX2ErrMemory(ctxt);
992
62
    return;
993
62
      }
994
37.7k
  } else {
995
37.7k
      val = (xmlChar *) value;
996
37.7k
  }
997
998
58.5k
  if (val[0] != 0) {
999
55.6k
      xmlURIPtr uri;
1000
1001
55.6k
      if (xmlParseURISafe((const char *)val, &uri) < 0)
1002
324
                xmlSAX2ErrMemory(ctxt);
1003
55.6k
      if (uri == NULL) {
1004
27.8k
                xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
1005
27.8k
                             "xmlns:%s: %s not a valid URI\n", name, value);
1006
27.8k
      } else {
1007
27.7k
    if (uri->scheme == NULL) {
1008
24.8k
                    xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
1009
24.8k
                                 "xmlns:%s: URI %s is not absolute\n",
1010
24.8k
                                 name, value);
1011
24.8k
    }
1012
27.7k
    xmlFreeURI(uri);
1013
27.7k
      }
1014
55.6k
  }
1015
1016
  /* a default namespace definition */
1017
58.5k
  nsret = xmlNewNs(ctxt->node, val, NULL);
1018
58.5k
        if (nsret == NULL) {
1019
87
            xmlSAX2ErrMemory(ctxt);
1020
87
        }
1021
58.4k
#ifdef LIBXML_VALID_ENABLED
1022
  /*
1023
   * Validate also for namespace decls, they are attributes from
1024
   * an XML-1.0 perspective
1025
   */
1026
58.4k
        else if (ctxt->validate && ctxt->wellFormed &&
1027
1.16k
                 ctxt->myDoc && ctxt->myDoc->intSubset) {
1028
1.16k
      ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
1029
1.16k
             ctxt->node, prefix, nsret, val);
1030
1.16k
        }
1031
58.5k
#endif /* LIBXML_VALID_ENABLED */
1032
58.5k
  if (val != value)
1033
20.7k
      xmlFree(val);
1034
58.5k
  return;
1035
58.5k
    }
1036
95.1k
    if ((ns != NULL) && (ns[0] == 'x') && (ns[1] == 'm') && (ns[2] == 'l') &&
1037
35.9k
        (ns[3] == 'n') && (ns[4] == 's') && (ns[5] == 0)) {
1038
28.5k
  xmlNsPtr nsret;
1039
28.5k
  xmlChar *val;
1040
1041
        /* Avoid unused variable warning if features are disabled. */
1042
28.5k
        (void) nsret;
1043
1044
28.5k
        if (!ctxt->replaceEntities) {
1045
            /* TODO: normalize if needed */
1046
17.7k
      val = xmlExpandEntitiesInAttValue(ctxt, value, /* normalize */ 0);
1047
17.7k
      if (val == NULL) {
1048
11
          xmlSAX2ErrMemory(ctxt);
1049
11
          xmlFree(ns);
1050
11
    return;
1051
11
      }
1052
17.7k
  } else {
1053
10.8k
      val = (xmlChar *) value;
1054
10.8k
  }
1055
1056
28.5k
  if (val[0] == 0) {
1057
614
      xmlNsErrMsg(ctxt, XML_NS_ERR_EMPTY,
1058
614
            "Empty namespace name for prefix %s\n", name, NULL);
1059
614
  }
1060
28.5k
  if ((ctxt->pedantic != 0) && (val[0] != 0)) {
1061
5.91k
      xmlURIPtr uri;
1062
1063
5.91k
      if (xmlParseURISafe((const char *)val, &uri) < 0)
1064
14
                xmlSAX2ErrMemory(ctxt);
1065
5.91k
      if (uri == NULL) {
1066
2.50k
          xmlNsWarnMsg(ctxt, XML_WAR_NS_URI,
1067
2.50k
       "xmlns:%s: %s not a valid URI\n", name, value);
1068
3.41k
      } else {
1069
3.41k
    if (uri->scheme == NULL) {
1070
3.00k
        xmlNsWarnMsg(ctxt, XML_WAR_NS_URI_RELATIVE,
1071
3.00k
         "xmlns:%s: URI %s is not absolute\n", name, value);
1072
3.00k
    }
1073
3.41k
    xmlFreeURI(uri);
1074
3.41k
      }
1075
5.91k
  }
1076
1077
  /* a standard namespace definition */
1078
28.5k
  nsret = xmlNewNs(ctxt->node, val, name);
1079
28.5k
  xmlFree(ns);
1080
1081
28.5k
        if (nsret == NULL) {
1082
29
            xmlSAX2ErrMemory(ctxt);
1083
29
        }
1084
28.5k
#ifdef LIBXML_VALID_ENABLED
1085
  /*
1086
   * Validate also for namespace decls, they are attributes from
1087
   * an XML-1.0 perspective
1088
   */
1089
28.5k
        else if (ctxt->validate && ctxt->wellFormed &&
1090
1.04k
           ctxt->myDoc && ctxt->myDoc->intSubset) {
1091
1.04k
      ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
1092
1.04k
             ctxt->node, prefix, nsret, value);
1093
1.04k
        }
1094
28.5k
#endif /* LIBXML_VALID_ENABLED */
1095
28.5k
  if (val != value)
1096
17.7k
      xmlFree(val);
1097
28.5k
  return;
1098
28.5k
    }
1099
1100
66.5k
    if (ns != NULL) {
1101
22.5k
        int res;
1102
1103
22.5k
  res = xmlSearchNsSafe(ctxt->node, ns, &namespace);
1104
22.5k
        if (res < 0)
1105
37
            xmlSAX2ErrMemory(ctxt);
1106
1107
22.5k
  if (namespace == NULL) {
1108
10.4k
      xmlNsErrMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
1109
10.4k
        "Namespace prefix %s of attribute %s is not defined\n",
1110
10.4k
                 ns, name);
1111
12.1k
  } else {
1112
12.1k
            xmlAttrPtr prop;
1113
1114
12.1k
            prop = ctxt->node->properties;
1115
53.0k
            while (prop != NULL) {
1116
41.1k
                if (prop->ns != NULL) {
1117
16.0k
                    if ((xmlStrEqual(name, prop->name)) &&
1118
439
                        ((namespace == prop->ns) ||
1119
439
                         (xmlStrEqual(namespace->href, prop->ns->href)))) {
1120
204
                        xmlCtxtErr(ctxt, NULL, XML_FROM_PARSER,
1121
204
                                   XML_ERR_ATTRIBUTE_REDEFINED, XML_ERR_FATAL,
1122
204
                                   name, NULL, NULL, 0,
1123
204
                                   "Attribute %s in %s redefined\n",
1124
204
                                   name, namespace->href);
1125
204
                        goto error;
1126
204
                    }
1127
16.0k
                }
1128
40.9k
                prop = prop->next;
1129
40.9k
            }
1130
12.1k
        }
1131
43.9k
    } else {
1132
43.9k
  namespace = NULL;
1133
43.9k
    }
1134
1135
    /* !!!!!! <a toto:arg="" xmlns:toto="http://toto.com"> */
1136
66.3k
    ret = xmlNewNsProp(ctxt->node, namespace, name, NULL);
1137
66.3k
    if (ret == NULL) {
1138
92
        xmlSAX2ErrMemory(ctxt);
1139
92
        goto error;
1140
92
    }
1141
1142
66.2k
    if (ctxt->replaceEntities == 0) {
1143
23.4k
        if (xmlNodeParseAttValue(ret->doc, ret, value, SIZE_MAX, NULL) < 0)
1144
94
            xmlSAX2ErrMemory(ctxt);
1145
42.8k
    } else if (value != NULL) {
1146
42.8k
        ret->children = xmlNewDocText(ctxt->myDoc, value);
1147
42.8k
        if (ret->children == NULL) {
1148
62
            xmlSAX2ErrMemory(ctxt);
1149
42.8k
        } else {
1150
42.8k
            ret->last = ret->children;
1151
42.8k
            ret->children->parent = (xmlNodePtr) ret;
1152
42.8k
        }
1153
42.8k
    }
1154
1155
66.2k
#ifdef LIBXML_VALID_ENABLED
1156
66.2k
    if (ctxt->validate && ctxt->wellFormed &&
1157
5.67k
        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
5.67k
        if (!ctxt->replaceEntities) {
1164
3.87k
      xmlChar *val;
1165
1166
            /* TODO: normalize if needed */
1167
3.87k
      val = xmlExpandEntitiesInAttValue(ctxt, value, /* normalize */ 0);
1168
1169
3.87k
      if (val == NULL)
1170
13
    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
1171
13
        ctxt->myDoc, ctxt->node, ret, value);
1172
3.85k
      else {
1173
3.85k
    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
3.85k
                nvalnorm = xmlValidCtxtNormalizeAttributeValue(
1181
3.85k
                                 &ctxt->vctxt, ctxt->myDoc,
1182
3.85k
                                 ctxt->node, fullname, val);
1183
3.85k
    if (nvalnorm != NULL) {
1184
1.73k
        xmlFree(val);
1185
1.73k
        val = nvalnorm;
1186
1.73k
    }
1187
1188
3.85k
    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
1189
3.85k
              ctxt->myDoc, ctxt->node, ret, val);
1190
3.85k
                xmlFree(val);
1191
3.85k
      }
1192
3.87k
  } 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
1.80k
            if (ctxt->input->entity != NULL)
1200
262
                ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
1201
1202
1.80k
      ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
1203
1.80k
                 ctxt->node, ret, value);
1204
1205
1.80k
            ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
1206
1.80k
  }
1207
5.67k
    } else
1208
60.6k
#endif /* LIBXML_VALID_ENABLED */
1209
60.6k
           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
1210
31.1k
               (ctxt->input->entity == NULL) &&
1211
               /* Don't create IDs containing entity references */
1212
24.8k
               (ret->children != NULL) &&
1213
23.0k
               (ret->children->type == XML_TEXT_NODE) &&
1214
22.5k
               (ret->children->next == NULL)) {
1215
22.3k
        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
22.3k
  if (xmlStrEqual(fullname, BAD_CAST "xml:id")) {
1221
      /*
1222
       * Add the xml:id value
1223
       *
1224
       * Open issue: normalization of the value.
1225
       */
1226
941
      if (xmlValidateNCName(content, 1) != 0) {
1227
514
          xmlErrId(ctxt, XML_DTD_XMLID_VALUE,
1228
514
             "xml:id : attribute value %s is not an NCName\n",
1229
514
             content);
1230
514
      }
1231
941
      xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
1232
21.3k
  } else {
1233
21.3k
            int res = xmlIsID(ctxt->myDoc, ctxt->node, ret);
1234
1235
21.3k
            if (res < 0)
1236
6
                xmlCtxtErrMemory(ctxt);
1237
21.3k
            else if (res > 0)
1238
3.09k
                xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
1239
18.2k
            else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
1240
1.47k
                xmlAddRef(&ctxt->vctxt, ctxt->myDoc, content, ret);
1241
21.3k
        }
1242
22.3k
    }
1243
1244
66.5k
error:
1245
66.5k
    if (ns != NULL)
1246
22.5k
  xmlFree(ns);
1247
66.5k
}
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
352k
  const xmlChar *prefix, const xmlChar **atts) {
1258
352k
    xmlElementPtr elemDecl;
1259
352k
    const xmlChar *att;
1260
352k
    int internal = 1;
1261
352k
    int i;
1262
1263
352k
    elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->intSubset, name, prefix);
1264
352k
    if (elemDecl == NULL) {
1265
261k
  elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset, name, prefix);
1266
261k
  internal = 0;
1267
261k
    }
1268
1269
444k
process_external_subset:
1270
1271
444k
    if (elemDecl != NULL) {
1272
96.2k
  xmlAttributePtr attr = elemDecl->attributes;
1273
1274
96.2k
#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
96.2k
  if ((ctxt->myDoc->standalone == 1) &&
1283
3.42k
      (ctxt->myDoc->extSubset != NULL) &&
1284
2.76k
      (ctxt->validate)) {
1285
3.35k
      while (attr != NULL) {
1286
1.56k
    if ((attr->defaultValue != NULL) &&
1287
1.24k
        (xmlGetDtdQAttrDesc(ctxt->myDoc->extSubset,
1288
1.24k
          attr->elem, attr->name,
1289
1.24k
          attr->prefix) == attr) &&
1290
1.17k
        (xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
1291
1.17k
          attr->elem, attr->name,
1292
1.17k
          attr->prefix) == NULL)) {
1293
1.17k
        xmlChar *fulln;
1294
1295
1.17k
        if (attr->prefix != NULL) {
1296
276
      fulln = xmlStrdup(attr->prefix);
1297
276
                        if (fulln != NULL)
1298
273
          fulln = xmlStrcat(fulln, BAD_CAST ":");
1299
276
                        if (fulln != NULL)
1300
271
          fulln = xmlStrcat(fulln, attr->name);
1301
894
        } else {
1302
894
      fulln = xmlStrdup(attr->name);
1303
894
        }
1304
1.17k
                    if (fulln == NULL) {
1305
11
                        xmlSAX2ErrMemory(ctxt);
1306
11
                        break;
1307
11
                    }
1308
1309
        /*
1310
         * Check that the attribute is not declared in the
1311
         * serialization
1312
         */
1313
1.15k
        att = NULL;
1314
1.15k
        if (atts != NULL) {
1315
446
      i = 0;
1316
446
      att = atts[i];
1317
900
      while (att != NULL) {
1318
678
          if (xmlStrEqual(att, fulln))
1319
224
        break;
1320
454
          i += 2;
1321
454
          att = atts[i];
1322
454
      }
1323
446
        }
1324
1.15k
        if (att == NULL) {
1325
935
            xmlErrValid(ctxt, XML_DTD_STANDALONE_DEFAULTED,
1326
935
      "standalone: attribute %s on %s defaulted from external subset\n",
1327
935
            fulln,
1328
935
            attr->elem);
1329
935
        }
1330
1.15k
                    xmlFree(fulln);
1331
1.15k
    }
1332
1.55k
    attr = attr->nexth;
1333
1.55k
      }
1334
1.80k
  }
1335
96.2k
#endif
1336
1337
  /*
1338
   * Actually insert defaulted values when needed
1339
   */
1340
96.2k
  attr = elemDecl->attributes;
1341
193k
  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
97.0k
      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
80.5k
    if (((attr->prefix != NULL) &&
1357
15.9k
         (xmlStrEqual(attr->prefix, BAD_CAST "xmlns"))) ||
1358
73.9k
        ((attr->prefix == NULL) &&
1359
64.5k
         (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) ||
1360
77.1k
        (ctxt->loadsubset & XML_COMPLETE_ATTRS)) {
1361
77.1k
        xmlAttributePtr tst;
1362
1363
77.1k
        tst = xmlGetDtdQAttrDesc(ctxt->myDoc->intSubset,
1364
77.1k
               attr->elem, attr->name,
1365
77.1k
               attr->prefix);
1366
77.1k
        if ((tst == attr) || (tst == NULL)) {
1367
77.1k
            xmlChar fn[50];
1368
77.1k
      xmlChar *fulln;
1369
1370
77.1k
                        fulln = xmlBuildQName(attr->name, attr->prefix, fn, 50);
1371
77.1k
      if (fulln == NULL) {
1372
10
          xmlSAX2ErrMemory(ctxt);
1373
10
          return;
1374
10
      }
1375
1376
      /*
1377
       * Check that the attribute is not declared in the
1378
       * serialization
1379
       */
1380
77.1k
      att = NULL;
1381
77.1k
      if (atts != NULL) {
1382
8.28k
          i = 0;
1383
8.28k
          att = atts[i];
1384
15.9k
          while (att != NULL) {
1385
9.63k
        if (xmlStrEqual(att, fulln))
1386
1.93k
            break;
1387
7.70k
        i += 2;
1388
7.70k
        att = atts[i];
1389
7.70k
          }
1390
8.28k
      }
1391
77.1k
      if (att == NULL) {
1392
75.1k
          xmlSAX1Attribute(ctxt, fulln,
1393
75.1k
               attr->defaultValue, prefix);
1394
75.1k
      }
1395
77.1k
      if ((fulln != fn) && (fulln != attr->name))
1396
7.35k
          xmlFree(fulln);
1397
77.1k
        }
1398
77.1k
    }
1399
80.5k
      }
1400
96.9k
      attr = attr->nexth;
1401
96.9k
  }
1402
96.2k
  if (internal == 1) {
1403
91.2k
      elemDecl = xmlGetDtdQElementDesc(ctxt->myDoc->extSubset,
1404
91.2k
                                 name, prefix);
1405
91.2k
      internal = 0;
1406
91.2k
      goto process_external_subset;
1407
91.2k
  }
1408
96.2k
    }
1409
444k
}
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
383k
{
1423
383k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1424
383k
    xmlNodePtr ret;
1425
383k
    xmlNodePtr parent;
1426
383k
    xmlNsPtr ns;
1427
383k
    const xmlChar *name;
1428
383k
    xmlChar *prefix;
1429
383k
    const xmlChar *att;
1430
383k
    const xmlChar *value;
1431
383k
    int i, res;
1432
1433
383k
    if ((ctx == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL)) return;
1434
1435
383k
#ifdef LIBXML_VALID_ENABLED
1436
    /*
1437
     * First check on validity:
1438
     */
1439
383k
    if (ctxt->validate && (ctxt->myDoc->extSubset == NULL) &&
1440
232k
        ((ctxt->myDoc->intSubset == NULL) ||
1441
225k
   ((ctxt->myDoc->intSubset->notations == NULL) &&
1442
225k
    (ctxt->myDoc->intSubset->elements == NULL) &&
1443
148k
    (ctxt->myDoc->intSubset->attributes == NULL) &&
1444
148k
    (ctxt->myDoc->intSubset->entities == NULL)))) {
1445
6.58k
  xmlErrValid(ctxt, XML_ERR_NO_DTD,
1446
6.58k
    "Validation failed: no DTD found !", NULL, NULL);
1447
6.58k
  ctxt->validate = 0;
1448
6.58k
    }
1449
383k
#endif
1450
1451
    /*
1452
     * Split the full name into a namespace prefix and the tag name
1453
     */
1454
383k
    name = xmlSplitQName4(fullname, &prefix);
1455
383k
    if (name == NULL) {
1456
23
        xmlSAX2ErrMemory(ctxt);
1457
23
        return;
1458
23
    }
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
383k
    ret = xmlNewDocNode(ctxt->myDoc, NULL, name, NULL);
1466
383k
    if (ret == NULL) {
1467
641
  xmlFree(prefix);
1468
641
  xmlSAX2ErrMemory(ctxt);
1469
641
        return;
1470
641
    }
1471
382k
    ctxt->nodemem = -1;
1472
1473
    /* Initialize parent before pushing node */
1474
382k
    parent = ctxt->node;
1475
382k
    if (parent == NULL)
1476
18.8k
        parent = (xmlNodePtr) ctxt->myDoc;
1477
1478
    /*
1479
     * Link the child element
1480
     */
1481
382k
    xmlSAX2AppendChild(ctxt, ret);
1482
1483
    /*
1484
     * We are parsing a new node.
1485
     */
1486
382k
    if (nodePush(ctxt, ret) < 0) {
1487
58
        xmlUnlinkNode(ret);
1488
58
        xmlFreeNode(ret);
1489
58
        if (prefix != NULL)
1490
8
            xmlFree(prefix);
1491
58
        return;
1492
58
    }
1493
1494
    /*
1495
     * Insert all the defaulted attributes from the DTD especially
1496
     * namespaces
1497
     */
1498
382k
    if ((ctxt->myDoc->intSubset != NULL) ||
1499
352k
        (ctxt->myDoc->extSubset != NULL)) {
1500
352k
        xmlCheckDefaultedAttributes(ctxt, name, prefix, atts);
1501
352k
    }
1502
1503
    /*
1504
     * process all the attributes whose name start with "xmlns"
1505
     */
1506
382k
    if (atts != NULL) {
1507
62.5k
        i = 0;
1508
62.5k
        att = atts[i++];
1509
62.5k
        value = atts[i++];
1510
141k
        while ((att != NULL) && (value != NULL)) {
1511
78.6k
            if ((att[0] == 'x') && (att[1] == 'm') && (att[2] == 'l') &&
1512
46.0k
                (att[3] == 'n') && (att[4] == 's'))
1513
39.7k
                xmlSAX1Attribute(ctxt, att, value, prefix);
1514
1515
78.6k
            att = atts[i++];
1516
78.6k
            value = atts[i++];
1517
78.6k
        }
1518
62.5k
    }
1519
1520
    /*
1521
     * Search the namespace, note that since the attributes have been
1522
     * processed, the local namespaces are available.
1523
     */
1524
382k
    res = xmlSearchNsSafe(ret, prefix, &ns);
1525
382k
    if (res < 0)
1526
9
        xmlSAX2ErrMemory(ctxt);
1527
382k
    if ((ns == NULL) && (parent != NULL)) {
1528
263k
        res = xmlSearchNsSafe(parent, prefix, &ns);
1529
263k
        if (res < 0)
1530
0
            xmlSAX2ErrMemory(ctxt);
1531
263k
    }
1532
382k
    if ((prefix != NULL) && (ns == NULL)) {
1533
8.67k
        xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
1534
8.67k
                     "Namespace prefix %s is not defined\n",
1535
8.67k
                     prefix, NULL);
1536
8.67k
        ns = xmlNewNs(ret, NULL, prefix);
1537
8.67k
        if (ns == NULL)
1538
16
            xmlSAX2ErrMemory(ctxt);
1539
8.67k
    }
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
382k
    if ((ns != NULL) && (ns->href != NULL) &&
1546
119k
        ((ns->href[0] != 0) || (ns->prefix != NULL)))
1547
113k
        xmlSetNs(ret, ns);
1548
1549
    /*
1550
     * process all the other attributes
1551
     */
1552
382k
    if (atts != NULL) {
1553
62.5k
        i = 0;
1554
62.5k
  att = atts[i++];
1555
62.5k
  value = atts[i++];
1556
141k
        while ((att != NULL) && (value != NULL)) {
1557
78.6k
            if ((att[0] != 'x') || (att[1] != 'm') || (att[2] != 'l') ||
1558
46.0k
                (att[3] != 'n') || (att[4] != 's'))
1559
38.8k
                xmlSAX1Attribute(ctxt, att, value, NULL);
1560
1561
            /*
1562
             * Next ones
1563
             */
1564
78.6k
            att = atts[i++];
1565
78.6k
            value = atts[i++];
1566
78.6k
        }
1567
62.5k
    }
1568
1569
382k
#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
382k
    if ((ctxt->validate) &&
1575
231k
        ((ctxt->vctxt.flags & XML_VCTXT_DTD_VALIDATED) == 0)) {
1576
6.34k
  int chk;
1577
1578
6.34k
  chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
1579
6.34k
  if (chk <= 0)
1580
27
      ctxt->valid = 0;
1581
6.34k
  if (chk < 0)
1582
0
      ctxt->wellFormed = 0;
1583
6.34k
  ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
1584
6.34k
  ctxt->vctxt.flags |= XML_VCTXT_DTD_VALIDATED;
1585
6.34k
    }
1586
382k
#endif /* LIBXML_VALID_ENABLED */
1587
1588
382k
    if (prefix != NULL)
1589
19.3k
  xmlFree(prefix);
1590
1591
382k
}
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
383k
xmlSAX2StartElement(void *ctx, const xmlChar *fullname, const xmlChar **atts) {
1714
383k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1715
1716
383k
    (void) atts;
1717
1718
383k
    if ((ctxt == NULL) || (fullname == NULL) || (ctxt->myDoc == NULL))
1719
0
        return;
1720
1721
383k
#ifdef LIBXML_SAX1_ENABLED
1722
383k
    if (!ctxt->html) {
1723
383k
        xmlSAX1StartElement(ctxt, fullname, atts);
1724
383k
        return;
1725
383k
    }
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
28.5k
{
1749
28.5k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
1750
1751
28.5k
    if (ctxt == NULL)
1752
0
        return;
1753
1754
28.5k
#if defined(LIBXML_SAX1_ENABLED) && defined(LIBXML_VALID_ENABLED)
1755
28.5k
    if (!ctxt->html && ctxt->validate && ctxt->wellFormed &&
1756
5.30k
        ctxt->myDoc && ctxt->myDoc->intSubset)
1757
5.30k
        ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
1758
5.30k
               ctxt->node);
1759
28.5k
#endif /* LIBXML_VALID_ENABLED */
1760
1761
28.5k
#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED)
1762
28.5k
    ctxt->nodemem = -1;
1763
1764
    /*
1765
     * end of parsing of this node.
1766
     */
1767
28.5k
    nodePop(ctxt);
1768
28.5k
#endif
1769
28.5k
}
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
352k
                int len) {
1784
352k
    xmlNodePtr ret;
1785
352k
    const xmlChar *intern = NULL;
1786
1787
    /*
1788
     * Allocate
1789
     */
1790
352k
    if (ctxt->freeElems != NULL) {
1791
0
  ret = ctxt->freeElems;
1792
0
  ctxt->freeElems = ret->next;
1793
0
  ctxt->freeElemsNr--;
1794
352k
    } else {
1795
352k
  ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
1796
352k
    }
1797
352k
    if (ret == NULL) {
1798
178
        xmlCtxtErrMemory(ctxt);
1799
178
  return(NULL);
1800
178
    }
1801
352k
    memset(ret, 0, sizeof(xmlNode));
1802
    /*
1803
     * intern the formatting blanks found between tags, or the
1804
     * very short strings
1805
     */
1806
352k
    if ((!ctxt->html) && (ctxt->dictNames)) {
1807
248k
        xmlChar cur = str[len];
1808
1809
248k
  if ((len < (int) (2 * sizeof(void *))) &&
1810
205k
      (ctxt->options & XML_PARSE_COMPACT)) {
1811
      /* store the string in the node overriding properties and nsDef */
1812
99.4k
      xmlChar *tmp = (xmlChar *) &(ret->properties);
1813
99.4k
      memcpy(tmp, str, len);
1814
99.4k
      tmp[len] = 0;
1815
99.4k
      intern = tmp;
1816
149k
  } else if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
1817
57.7k
      ((cur == '<') && (str[len + 1] != '!')))) {
1818
49.8k
      intern = xmlDictLookup(ctxt->dict, str, len);
1819
49.8k
            if (intern == NULL) {
1820
6
                xmlSAX2ErrMemory(ctxt);
1821
6
                xmlFree(ret);
1822
6
                return(NULL);
1823
6
            }
1824
99.2k
  } else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') &&
1825
3.20k
             (str[len + 1] != '!')) {
1826
2.71k
      int i;
1827
1828
8.69k
      for (i = 1;i < len;i++) {
1829
7.80k
    if (!IS_BLANK_CH(str[i])) goto skip;
1830
7.80k
      }
1831
886
      intern = xmlDictLookup(ctxt->dict, str, len);
1832
886
            if (intern == NULL) {
1833
6
                xmlSAX2ErrMemory(ctxt);
1834
6
                xmlFree(ret);
1835
6
                return(NULL);
1836
6
            }
1837
886
  }
1838
248k
    }
1839
352k
skip:
1840
352k
    ret->type = XML_TEXT_NODE;
1841
352k
    ret->doc = doc;
1842
1843
352k
    ret->name = xmlStringText;
1844
352k
    if (intern == NULL) {
1845
202k
  ret->content = xmlStrndup(str, len);
1846
202k
  if (ret->content == NULL) {
1847
104
      xmlSAX2ErrMemory(ctxt);
1848
104
      xmlFree(ret);
1849
104
      return(NULL);
1850
104
  }
1851
202k
    } else
1852
150k
  ret->content = (xmlChar *) intern;
1853
1854
352k
    if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
1855
0
  xmlRegisterNodeDefaultValue(ret);
1856
352k
    return(ret);
1857
352k
}
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
5.74k
                          const xmlChar *end) {
1872
5.74k
    const xmlChar *in;
1873
1874
5.74k
    in = str;
1875
26.1k
    while (in < end)
1876
21.5k
        if (*in++ == '&')
1877
1.22k
      goto decode;
1878
4.52k
    return(NULL);
1879
1.22k
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
1.22k
    return(xmlExpandEntitiesInAttValue(ctxt, str, /* normalize */ 0));
1886
5.74k
}
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
233k
{
1909
233k
    xmlAttrPtr ret;
1910
233k
    xmlNsPtr namespace = NULL;
1911
233k
    xmlChar *dup = NULL;
1912
1913
    /*
1914
     * Note: if prefix == NULL, the attribute is not in the default namespace
1915
     */
1916
233k
    if (prefix != NULL) {
1917
14.0k
  namespace = xmlParserNsLookupSax(ctxt, prefix);
1918
14.0k
  if ((namespace == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
1919
8.60k
            int res;
1920
1921
8.60k
      res = xmlSearchNsSafe(ctxt->node, prefix, &namespace);
1922
8.60k
            if (res < 0)
1923
50
                xmlSAX2ErrMemory(ctxt);
1924
8.60k
  }
1925
14.0k
    }
1926
1927
    /*
1928
     * allocate the node
1929
     */
1930
233k
    if (ctxt->freeAttrs != NULL) {
1931
0
        ret = ctxt->freeAttrs;
1932
0
  ctxt->freeAttrs = ret->next;
1933
0
  ctxt->freeAttrsNr--;
1934
233k
    } else {
1935
233k
        ret = xmlMalloc(sizeof(*ret));
1936
233k
        if (ret == NULL) {
1937
70
            xmlSAX2ErrMemory(ctxt);
1938
70
            return(NULL);
1939
70
        }
1940
233k
    }
1941
1942
233k
    memset(ret, 0, sizeof(xmlAttr));
1943
233k
    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
233k
    ret->parent = ctxt->node;
1955
233k
    ret->doc = ctxt->node->doc;
1956
233k
    ret->ns = namespace;
1957
1958
233k
    if (ctxt->dictNames) {
1959
211k
        ret->name = localname;
1960
211k
    } else {
1961
21.2k
        ret->name = xmlStrdup(localname);
1962
21.2k
        if (ret->name == NULL)
1963
41
            xmlSAX2ErrMemory(ctxt);
1964
21.2k
    }
1965
1966
233k
    if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
1967
0
        xmlRegisterNodeDefaultValue((xmlNodePtr)ret);
1968
1969
233k
    if ((ctxt->replaceEntities == 0) && (!ctxt->html)) {
1970
176k
  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
176k
  if (*valueend != 0) {
1978
40.2k
      tmp = xmlSAX2TextNode(ctxt, ret->doc, value, valueend - value);
1979
40.2k
      ret->children = tmp;
1980
40.2k
      ret->last = tmp;
1981
40.2k
      if (tmp != NULL) {
1982
40.2k
    tmp->parent = (xmlNodePtr) ret;
1983
40.2k
      }
1984
136k
  } else if (valueend > value) {
1985
133k
            if (xmlNodeParseAttValue(ret->doc, ret, value, valueend - value,
1986
133k
                                     NULL) < 0)
1987
122
                xmlSAX2ErrMemory(ctxt);
1988
133k
  }
1989
176k
    } else if (value != NULL) {
1990
56.3k
  xmlNodePtr tmp;
1991
1992
56.3k
  tmp = xmlSAX2TextNode(ctxt, ret->doc, value, valueend - value);
1993
56.3k
  ret->children = tmp;
1994
56.3k
  ret->last = tmp;
1995
56.3k
  if (tmp != NULL) {
1996
56.2k
      tmp->parent = (xmlNodePtr) ret;
1997
56.2k
  }
1998
56.3k
    }
1999
2000
233k
#ifdef LIBXML_VALID_ENABLED
2001
233k
    if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
2002
8.31k
        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
8.31k
        if (!ctxt->replaceEntities) {
2008
5.74k
      dup = xmlSAX2DecodeAttrEntities(ctxt, value, valueend);
2009
5.74k
      if (dup == NULL) {
2010
4.53k
          if (*valueend == 0) {
2011
3.22k
        ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2012
3.22k
            ctxt->myDoc, ctxt->node, ret, value);
2013
3.22k
    } 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.30k
        dup = xmlStrndup(value, valueend - value);
2020
1.30k
                    if (dup == NULL)
2021
6
                        xmlSAX2ErrMemory(ctxt);
2022
2023
1.30k
        ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2024
1.30k
            ctxt->myDoc, ctxt->node, ret, dup);
2025
1.30k
    }
2026
4.53k
      } 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
1.21k
    if (ctxt->attsSpecial != NULL) {
2035
815
        xmlChar *nvalnorm;
2036
815
        xmlChar fn[50];
2037
815
        xmlChar *fullname;
2038
2039
815
        fullname = xmlBuildQName(localname, prefix, fn, 50);
2040
815
                    if (fullname == NULL) {
2041
5
                        xmlSAX2ErrMemory(ctxt);
2042
810
                    } else {
2043
810
      ctxt->vctxt.valid = 1;
2044
810
            nvalnorm = xmlValidCtxtNormalizeAttributeValue(
2045
810
                       &ctxt->vctxt, ctxt->myDoc,
2046
810
           ctxt->node, fullname, dup);
2047
810
      if (ctxt->vctxt.valid != 1)
2048
0
          ctxt->valid = 0;
2049
2050
810
      if ((fullname != fn) && (fullname != localname))
2051
200
          xmlFree(fullname);
2052
810
      if (nvalnorm != NULL) {
2053
566
          xmlFree(dup);
2054
566
          dup = nvalnorm;
2055
566
      }
2056
810
        }
2057
815
    }
2058
2059
1.21k
    ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2060
1.21k
              ctxt->myDoc, ctxt->node, ret, dup);
2061
1.21k
      }
2062
5.74k
  } else {
2063
      /*
2064
       * if entities already have been substituted, then
2065
       * the attribute as passed is already normalized
2066
       */
2067
2.56k
      dup = xmlStrndup(value, valueend - value);
2068
2.56k
            if (dup == NULL)
2069
37
                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
2.56k
            if (ctxt->input->entity != NULL)
2078
263
                ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
2079
2080
2.56k
      ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
2081
2.56k
                               ctxt->myDoc, ctxt->node, ret, dup);
2082
2083
2.56k
            ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
2084
2.56k
  }
2085
8.31k
    } else
2086
224k
#endif /* LIBXML_VALID_ENABLED */
2087
224k
           if (((ctxt->loadsubset & XML_SKIP_IDS) == 0) &&
2088
199k
               (ctxt->input->entity == NULL) &&
2089
               /* Don't create IDs containing entity references */
2090
184k
               (ret->children != NULL) &&
2091
182k
               (ret->children->type == XML_TEXT_NODE) &&
2092
181k
               (ret->children->next == NULL)) {
2093
181k
        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
181k
        if ((prefix == ctxt->str_xml) &&
2099
5.07k
             (localname[0] == 'i') && (localname[1] == 'd') &&
2100
1.88k
       (localname[2] == 0)) {
2101
      /*
2102
       * Add the xml:id value
2103
       *
2104
       * Open issue: normalization of the value.
2105
       */
2106
1.68k
      if (xmlValidateNCName(content, 1) != 0) {
2107
1.26k
          xmlErrId(ctxt, XML_DTD_XMLID_VALUE,
2108
1.26k
                         "xml:id : attribute value %s is not an NCName\n",
2109
1.26k
                         content);
2110
1.26k
      }
2111
1.68k
      xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
2112
179k
  } else {
2113
179k
            int res = xmlIsID(ctxt->myDoc, ctxt->node, ret);
2114
2115
179k
            if (res < 0)
2116
6
                xmlCtxtErrMemory(ctxt);
2117
179k
            else if (res > 0)
2118
18.1k
                xmlAddID(&ctxt->vctxt, ctxt->myDoc, content, ret);
2119
161k
            else if (xmlIsRef(ctxt->myDoc, ctxt->node, ret))
2120
6.40k
                xmlAddRef(&ctxt->vctxt, ctxt->myDoc, content, ret);
2121
179k
  }
2122
181k
    }
2123
233k
    if (dup != NULL)
2124
5.04k
  xmlFree(dup);
2125
2126
233k
    return(ret);
2127
233k
}
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
416k
{
2156
416k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2157
416k
    xmlNodePtr ret;
2158
416k
    xmlNsPtr last = NULL, ns;
2159
416k
    const xmlChar *uri, *pref;
2160
416k
    xmlChar *lname = NULL;
2161
416k
    int i, j;
2162
2163
416k
    if (ctx == NULL) return;
2164
2165
416k
#ifdef LIBXML_VALID_ENABLED
2166
    /*
2167
     * First check on validity:
2168
     */
2169
416k
    if (ctxt->validate &&
2170
238k
        ((ctxt->myDoc == NULL) ||
2171
238k
         ((ctxt->myDoc->extSubset == NULL) &&
2172
227k
          ((ctxt->myDoc->intSubset == NULL) ||
2173
220k
     ((ctxt->myDoc->intSubset->notations == NULL) &&
2174
219k
      (ctxt->myDoc->intSubset->elements == NULL) &&
2175
73.4k
      (ctxt->myDoc->intSubset->attributes == NULL) &&
2176
73.4k
      (ctxt->myDoc->intSubset->entities == NULL)))))) {
2177
8.22k
  xmlErrValid(ctxt, XML_DTD_NO_DTD,
2178
8.22k
    "Validation failed: no DTD found !", NULL, NULL);
2179
8.22k
  ctxt->validate = 0;
2180
8.22k
    }
2181
416k
#endif /* LIBXML_VALID_ENABLED */
2182
2183
    /*
2184
     * Take care of the rare case of an undefined namespace prefix
2185
     */
2186
416k
    if ((prefix != NULL) && (URI == NULL)) {
2187
11.1k
        if (ctxt->dictNames) {
2188
9.15k
      const xmlChar *fullname;
2189
2190
9.15k
      fullname = xmlDictQLookup(ctxt->dict, prefix, localname);
2191
9.15k
      if (fullname == NULL) {
2192
20
                xmlSAX2ErrMemory(ctxt);
2193
20
                return;
2194
20
            }
2195
9.13k
      localname = fullname;
2196
9.13k
  } else {
2197
1.98k
      lname = xmlBuildQName(localname, prefix, NULL, 0);
2198
1.98k
            if (lname == NULL) {
2199
9
                xmlSAX2ErrMemory(ctxt);
2200
9
                return;
2201
9
            }
2202
1.98k
  }
2203
11.1k
    }
2204
    /*
2205
     * allocate the node
2206
     */
2207
416k
    if (ctxt->freeElems != NULL) {
2208
0
        ret = ctxt->freeElems;
2209
0
  ctxt->freeElems = ret->next;
2210
0
  ctxt->freeElemsNr--;
2211
0
  memset(ret, 0, sizeof(xmlNode));
2212
0
        ret->doc = ctxt->myDoc;
2213
0
  ret->type = XML_ELEMENT_NODE;
2214
2215
0
  if (ctxt->dictNames)
2216
0
      ret->name = localname;
2217
0
  else {
2218
0
      if (lname == NULL)
2219
0
    ret->name = xmlStrdup(localname);
2220
0
      else
2221
0
          ret->name = lname;
2222
0
      if (ret->name == NULL) {
2223
0
          xmlSAX2ErrMemory(ctxt);
2224
0
                xmlFree(ret);
2225
0
    return;
2226
0
      }
2227
0
  }
2228
0
  if ((xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))
2229
0
      xmlRegisterNodeDefaultValue(ret);
2230
416k
    } else {
2231
416k
  if (ctxt->dictNames)
2232
337k
      ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
2233
337k
                                 (xmlChar *) localname, NULL);
2234
78.3k
  else if (lname == NULL)
2235
76.3k
      ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
2236
1.97k
  else
2237
1.97k
      ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL, lname, NULL);
2238
416k
  if (ret == NULL) {
2239
320
      xmlSAX2ErrMemory(ctxt);
2240
320
      return;
2241
320
  }
2242
416k
    }
2243
2244
    /*
2245
     * Build the namespace list
2246
     */
2247
854k
    for (i = 0,j = 0;j < nb_namespaces;j++) {
2248
438k
        pref = namespaces[i++];
2249
438k
  uri = namespaces[i++];
2250
438k
  ns = xmlNewNs(NULL, uri, pref);
2251
438k
  if (ns != NULL) {
2252
438k
      if (last == NULL) {
2253
106k
          ret->nsDef = last = ns;
2254
332k
      } else {
2255
332k
          last->next = ns;
2256
332k
    last = ns;
2257
332k
      }
2258
438k
      if ((URI != NULL) && (prefix == pref))
2259
10.7k
    ret->ns = ns;
2260
438k
  } else {
2261
140
            xmlSAX2ErrMemory(ctxt);
2262
140
      continue;
2263
140
  }
2264
2265
438k
        xmlParserNsUpdateSax(ctxt, pref, ns);
2266
2267
438k
#ifdef LIBXML_VALID_ENABLED
2268
438k
  if ((!ctxt->html) && ctxt->validate && ctxt->wellFormed &&
2269
2.15k
      ctxt->myDoc && ctxt->myDoc->intSubset) {
2270
2.15k
      ctxt->valid &= xmlValidateOneNamespace(&ctxt->vctxt, ctxt->myDoc,
2271
2.15k
                                             ret, prefix, ns, uri);
2272
2.15k
  }
2273
438k
#endif /* LIBXML_VALID_ENABLED */
2274
438k
    }
2275
415k
    ctxt->nodemem = -1;
2276
2277
    /*
2278
     * Link the child element
2279
     */
2280
415k
    xmlSAX2AppendChild(ctxt, ret);
2281
2282
    /*
2283
     * We are parsing a new node.
2284
     */
2285
415k
    if (nodePush(ctxt, ret) < 0) {
2286
88
        xmlUnlinkNode(ret);
2287
88
        xmlFreeNode(ret);
2288
88
        return;
2289
88
    }
2290
2291
    /*
2292
     * Insert the defaulted attributes from the DTD only if requested:
2293
     */
2294
415k
    if ((nb_defaulted != 0) &&
2295
61.7k
        ((ctxt->loadsubset & XML_COMPLETE_ATTRS) == 0))
2296
28.6k
  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
415k
    if ((URI != NULL) && (ret->ns == NULL)) {
2303
41.5k
        ret->ns = xmlParserNsLookupSax(ctxt, prefix);
2304
41.5k
  if ((ret->ns == NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) {
2305
1.35k
            int res;
2306
2307
1.35k
      res = xmlSearchNsSafe(ret, prefix, &ret->ns);
2308
1.35k
            if (res < 0)
2309
12
                xmlSAX2ErrMemory(ctxt);
2310
1.35k
  }
2311
41.5k
  if (ret->ns == NULL) {
2312
68
      ns = xmlNewNs(ret, NULL, prefix);
2313
68
      if (ns == NULL) {
2314
2315
0
          xmlSAX2ErrMemory(ctxt);
2316
0
    return;
2317
0
      }
2318
68
            if (prefix != NULL)
2319
27
                xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
2320
27
                             "Namespace prefix %s was not found\n",
2321
27
                             prefix, NULL);
2322
41
            else
2323
41
                xmlNsWarnMsg(ctxt, XML_NS_ERR_UNDEFINED_NAMESPACE,
2324
41
                             "Namespace default prefix was not found\n",
2325
41
                             NULL, NULL);
2326
68
  }
2327
41.5k
    }
2328
2329
    /*
2330
     * process all the other attributes
2331
     */
2332
415k
    if (nb_attributes > 0) {
2333
74.9k
        xmlAttrPtr prev = NULL;
2334
2335
308k
        for (j = 0,i = 0;i < nb_attributes;i++,j+=5) {
2336
233k
            xmlAttrPtr attr = NULL;
2337
2338
      /*
2339
       * Handle the rare case of an undefined attribute prefix
2340
       */
2341
233k
      if ((attributes[j+1] != NULL) && (attributes[j+2] == NULL)) {
2342
19.2k
    if (ctxt->dictNames) {
2343
17.6k
        const xmlChar *fullname;
2344
2345
17.6k
        fullname = xmlDictQLookup(ctxt->dict, attributes[j+1],
2346
17.6k
                                  attributes[j]);
2347
17.6k
        if (fullname == NULL) {
2348
9
                        xmlSAX2ErrMemory(ctxt);
2349
9
                        return;
2350
9
                    }
2351
17.6k
                    attr = xmlSAX2AttributeNs(ctxt, fullname, NULL,
2352
17.6k
                                              attributes[j+3],
2353
17.6k
                                              attributes[j+4]);
2354
17.6k
                    goto have_attr;
2355
17.6k
    } else {
2356
1.52k
        lname = xmlBuildQName(attributes[j], attributes[j+1],
2357
1.52k
                              NULL, 0);
2358
1.52k
        if (lname == NULL) {
2359
6
                        xmlSAX2ErrMemory(ctxt);
2360
6
                        return;
2361
6
                    }
2362
1.52k
                    attr = xmlSAX2AttributeNs(ctxt, lname, NULL,
2363
1.52k
                                              attributes[j+3],
2364
1.52k
                                              attributes[j+4]);
2365
1.52k
                    xmlFree(lname);
2366
1.52k
                    goto have_attr;
2367
1.52k
    }
2368
19.2k
      }
2369
214k
            attr = xmlSAX2AttributeNs(ctxt, attributes[j], attributes[j+1],
2370
214k
                                      attributes[j+3], attributes[j+4]);
2371
233k
have_attr:
2372
233k
            if (attr == NULL)
2373
70
                continue;
2374
2375
            /* link at the end to preserve order */
2376
233k
            if (prev == NULL) {
2377
74.8k
                ctxt->node->properties = attr;
2378
158k
            } else {
2379
158k
                prev->next = attr;
2380
158k
                attr->prev = prev;
2381
158k
            }
2382
2383
233k
            prev = attr;
2384
233k
  }
2385
74.9k
    }
2386
2387
415k
#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
415k
    if ((ctxt->validate) &&
2393
230k
        ((ctxt->vctxt.flags & XML_VCTXT_DTD_VALIDATED) == 0)) {
2394
8.84k
  int chk;
2395
2396
8.84k
  chk = xmlValidateDtdFinal(&ctxt->vctxt, ctxt->myDoc);
2397
8.84k
  if (chk <= 0)
2398
43
      ctxt->valid = 0;
2399
8.84k
  if (chk < 0)
2400
0
      ctxt->wellFormed = 0;
2401
8.84k
  ctxt->valid &= xmlValidateRoot(&ctxt->vctxt, ctxt->myDoc);
2402
8.84k
  ctxt->vctxt.flags |= XML_VCTXT_DTD_VALIDATED;
2403
8.84k
    }
2404
415k
#endif /* LIBXML_VALID_ENABLED */
2405
415k
}
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
114k
{
2422
114k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2423
2424
114k
    if (ctx == NULL) return;
2425
114k
    ctxt->nodemem = -1;
2426
2427
114k
#ifdef LIBXML_VALID_ENABLED
2428
114k
    if (ctxt->validate && ctxt->wellFormed &&
2429
13.7k
        ctxt->myDoc && ctxt->myDoc->intSubset)
2430
13.7k
        ctxt->valid &= xmlValidateOneElement(&ctxt->vctxt, ctxt->myDoc,
2431
13.7k
                                             ctxt->node);
2432
114k
#endif /* LIBXML_VALID_ENABLED */
2433
2434
    /*
2435
     * end of parsing of this node.
2436
     */
2437
114k
    nodePop(ctxt);
2438
114k
}
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
39.0k
{
2449
39.0k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2450
39.0k
    xmlNodePtr ret;
2451
2452
39.0k
    if (ctx == NULL) return;
2453
39.0k
    ret = xmlNewReference(ctxt->myDoc, name);
2454
39.0k
    if (ret == NULL) {
2455
34
        xmlSAX2ErrMemory(ctxt);
2456
34
        return;
2457
34
    }
2458
2459
38.9k
    xmlSAX2AppendChild(ctxt, ret);
2460
38.9k
}
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.77M
{
2474
1.77M
    xmlNodePtr lastChild;
2475
1.77M
    xmlNodePtr parent;
2476
2477
1.77M
    if (ctxt == NULL)
2478
0
        return;
2479
2480
1.77M
    parent = ctxt->node;
2481
1.77M
    if (parent == NULL)
2482
0
        return;
2483
1.77M
    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.77M
    if ((lastChild == NULL) ||
2493
1.67M
        (lastChild->type != type) ||
2494
1.51M
        ((!ctxt->html) && (type != XML_TEXT_NODE))) {
2495
260k
        xmlNode *node;
2496
2497
260k
        if (type == XML_TEXT_NODE)
2498
256k
            node = xmlSAX2TextNode(ctxt, parent->doc, ch, len);
2499
4.00k
        else
2500
4.00k
            node = xmlNewCDataBlock(parent->doc, ch, len);
2501
260k
  if (node == NULL) {
2502
194
      xmlSAX2ErrMemory(ctxt);
2503
194
      return;
2504
194
  }
2505
2506
259k
        if (lastChild == NULL) {
2507
95.0k
            parent->children = node;
2508
95.0k
            parent->last = node;
2509
95.0k
            node->parent = parent;
2510
164k
        } else {
2511
164k
            xmlSAX2AppendChild(ctxt, node);
2512
164k
        }
2513
2514
259k
        ctxt->nodelen = len;
2515
259k
        ctxt->nodemem = len + 1;
2516
259k
        lastChild = node;
2517
1.51M
    } else {
2518
1.51M
        xmlChar *content;
2519
1.51M
        int oldSize, newSize, capacity;
2520
1.51M
        int maxSize = (ctxt->options & XML_PARSE_HUGE) ?
2521
343k
                      XML_MAX_HUGE_LENGTH :
2522
1.51M
                      XML_MAX_TEXT_LENGTH;
2523
2524
1.51M
        content = lastChild->content;
2525
1.51M
        oldSize = ctxt->nodelen;
2526
1.51M
        capacity = ctxt->nodemem;
2527
2528
        /* Shouldn't happen */
2529
1.51M
        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
1.51M
        if ((len > maxSize) || (oldSize > maxSize - len)) {
2536
60
            xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT,
2537
60
                        "Text node too long, try XML_PARSE_HUGE");
2538
60
            return;
2539
60
        }
2540
2541
1.51M
        newSize = oldSize + len;
2542
2543
1.51M
        if (newSize >= capacity) {
2544
116k
            if (newSize <= 20)
2545
49.2k
                capacity = 40;
2546
67.2k
            else
2547
67.2k
                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
116k
            if ((content == (xmlChar *) &lastChild->properties) ||
2554
95.0k
                ((ctxt->nodemem == oldSize + 1) &&
2555
67.3k
                 (xmlDictOwns(ctxt->dict, content)))) {
2556
22.5k
                xmlChar *newContent;
2557
2558
22.5k
                newContent = xmlMalloc(capacity);
2559
22.5k
                if (newContent == NULL) {
2560
11
                    xmlSAX2ErrMemory(ctxt);
2561
11
                    return;
2562
11
                }
2563
2564
22.5k
                memcpy(newContent, content, oldSize);
2565
22.5k
                lastChild->properties = NULL;
2566
22.5k
                content = newContent;
2567
93.9k
            } else {
2568
93.9k
                content = xmlRealloc(content, capacity);
2569
93.9k
                if (content == NULL) {
2570
22
                    xmlSAX2ErrMemory(ctxt);
2571
22
                    return;
2572
22
                }
2573
93.9k
            }
2574
2575
116k
            ctxt->nodemem = capacity;
2576
116k
            lastChild->content = content;
2577
116k
        }
2578
2579
1.51M
        memcpy(&content[oldSize], ch, len);
2580
1.51M
        content[newSize] = 0;
2581
1.51M
        ctxt->nodelen = newSize;
2582
1.51M
    }
2583
2584
1.77M
    if ((lastChild != NULL) &&
2585
1.77M
        (type == XML_TEXT_NODE) &&
2586
1.76M
        (ctxt->input != NULL)) {
2587
1.76M
        if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
2588
1.73M
            lastChild->line = ctxt->input->line;
2589
31.1k
        else {
2590
31.1k
            lastChild->line = USHRT_MAX;
2591
31.1k
            if (ctxt->options & XML_PARSE_BIG_LINES)
2592
8.15k
                lastChild->psvi = XML_INT_TO_PTR(ctxt->input->line);
2593
31.1k
        }
2594
1.76M
    }
2595
1.77M
}
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
1.76M
{
2607
1.76M
    xmlSAX2Text((xmlParserCtxtPtr) ctx, ch, len, XML_TEXT_NODE);
2608
1.76M
}
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
39.4k
{
2634
39.4k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2635
39.4k
    xmlNodePtr ret;
2636
2637
39.4k
    if (ctx == NULL) return;
2638
2639
39.4k
    ret = xmlNewDocPI(ctxt->myDoc, target, data);
2640
39.4k
    if (ret == NULL) {
2641
38
        xmlSAX2ErrMemory(ctxt);
2642
38
        return;
2643
38
    }
2644
2645
39.3k
    xmlSAX2AppendChild(ctxt, ret);
2646
39.3k
}
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
455k
{
2657
455k
    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
2658
455k
    xmlNodePtr ret;
2659
2660
455k
    if (ctx == NULL) return;
2661
2662
455k
    ret = xmlNewDocComment(ctxt->myDoc, value);
2663
455k
    if (ret == NULL) {
2664
44
        xmlSAX2ErrMemory(ctxt);
2665
44
        return;
2666
44
    }
2667
2668
455k
    xmlSAX2AppendChild(ctxt, ret);
2669
455k
}
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
4.00k
{
2681
4.00k
    xmlSAX2Text((xmlParserCtxtPtr) ctx, value, len, XML_CDATA_SECTION_NODE);
2682
4.00k
}
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 */