Bug Summary

File:SAX2.c
Location:line 2559, column 5
Description:Value stored to 'parent' is never read

Annotated Source Code

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