ReactOS 0.4.16-dev-2206-gc56950d
parserInternals.c
Go to the documentation of this file.
1/*
2 * parserInternals.c : Internal routines (and obsolete ones) needed for the
3 * XML and HTML parsers.
4 *
5 * See Copyright for the status of this software.
6 *
7 * daniel@veillard.com
8 */
9
10#define IN_LIBXML
11#include "libxml.h"
12
13#if defined(_WIN32)
14#define XML_DIR_SEP '\\'
15#else
16#define XML_DIR_SEP '/'
17#endif
18
19#include <string.h>
20#include <ctype.h>
21#include <stdlib.h>
22
23#include <libxml/xmlmemory.h>
24#include <libxml/tree.h>
25#include <libxml/parser.h>
27#include <libxml/entities.h>
28#include <libxml/xmlerror.h>
29#include <libxml/encoding.h>
30#include <libxml/xmlIO.h>
31#include <libxml/uri.h>
32#include <libxml/dict.h>
33#include <libxml/xmlsave.h>
34#ifdef LIBXML_CATALOG_ENABLED
35#include <libxml/catalog.h>
36#endif
37#include <libxml/chvalid.h>
38
39#define CUR(ctxt) ctxt->input->cur
40#define END(ctxt) ctxt->input->end
41
42#include "private/buf.h"
43#include "private/enc.h"
44#include "private/error.h"
45#include "private/io.h"
46#include "private/parser.h"
47
48/*
49 * XML_MAX_AMPLIFICATION_DEFAULT is the default maximum allowed amplification
50 * factor of serialized output after entity expansion.
51 */
52#define XML_MAX_AMPLIFICATION_DEFAULT 5
53
54/*
55 * Various global defaults for parsing
56 */
57
65void
67 int myversion = LIBXML_VERSION;
68
70
71 if ((myversion / 10000) != (version / 10000)) {
73 "Fatal: program compiled against libxml %d using libxml %d\n",
74 (version / 10000), (myversion / 10000));
76 "Fatal: program compiled against libxml %d using libxml %d\n",
77 (version / 10000), (myversion / 10000));
78 }
79 if ((myversion / 100) < (version / 100)) {
81 "Warning: program compiled against libxml %d using older %d\n",
82 (version / 100), (myversion / 100));
83 }
84}
85
86
87/************************************************************************
88 * *
89 * Some factorized error routines *
90 * *
91 ************************************************************************/
92
93
101void
102xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
103{
104 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
105 (ctxt->instate == XML_PARSER_EOF))
106 return;
107 if (ctxt != NULL) {
108 ctxt->errNo = XML_ERR_NO_MEMORY;
109 ctxt->instate = XML_PARSER_EOF;
110 ctxt->disableSAX = 1;
111 }
112 if (extra)
115 NULL, NULL, 0, 0,
116 "Memory allocation failed : %s\n", extra);
117 else
120 NULL, NULL, 0, 0, "Memory allocation failed\n");
121}
122
133void
134__xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr,
135 const char *msg, const xmlChar * str1, const xmlChar * str2)
136{
137 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
138 (ctxt->instate == XML_PARSER_EOF))
139 return;
140 if (ctxt != NULL)
141 ctxt->errNo = xmlerr;
143 ctxt, NULL, XML_FROM_PARSER, xmlerr, XML_ERR_FATAL,
144 NULL, 0, (const char *) str1, (const char *) str2,
145 NULL, 0, 0, msg, str1, str2);
146 if (ctxt != NULL) {
147 ctxt->wellFormed = 0;
148 if (ctxt->recovery == 0)
149 ctxt->disableSAX = 1;
150 }
151}
152
161static void LIBXML_ATTR_FORMAT(2,0)
162xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str)
163{
164 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
165 (ctxt->instate == XML_PARSER_EOF))
166 return;
167 if (ctxt != NULL)
168 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
171 XML_ERR_FATAL, NULL, 0, (const char *) str, NULL, NULL,
172 0, 0, msg, str);
173 if (ctxt != NULL) {
174 ctxt->wellFormed = 0;
175 if (ctxt->recovery == 0)
176 ctxt->disableSAX = 1;
177 }
178}
179
188void
189xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
190{
191 const char *errmsg;
192
193 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
194 (ctxt->instate == XML_PARSER_EOF))
195 return;
196 switch (error) {
198 errmsg = "CharRef: invalid hexadecimal value";
199 break;
201 errmsg = "CharRef: invalid decimal value";
202 break;
204 errmsg = "CharRef: invalid value";
205 break;
207 errmsg = "internal error";
208 break;
210 errmsg = "PEReference at end of document";
211 break;
213 errmsg = "PEReference in prolog";
214 break;
216 errmsg = "PEReference in epilog";
217 break;
219 errmsg = "PEReference: no name";
220 break;
222 errmsg = "PEReference: expecting ';'";
223 break;
225 errmsg = "Detected an entity reference loop";
226 break;
228 errmsg = "EntityValue: \" or ' expected";
229 break;
231 errmsg = "PEReferences forbidden in internal subset";
232 break;
234 errmsg = "EntityValue: \" or ' expected";
235 break;
237 errmsg = "AttValue: \" or ' expected";
238 break;
240 errmsg = "Unescaped '<' not allowed in attributes values";
241 break;
243 errmsg = "SystemLiteral \" or ' expected";
244 break;
246 errmsg = "Unfinished System or Public ID \" or ' expected";
247 break;
249 errmsg = "Sequence ']]>' not allowed in content";
250 break;
252 errmsg = "SYSTEM or PUBLIC, the URI is missing";
253 break;
255 errmsg = "PUBLIC, the Public Identifier is missing";
256 break;
258 errmsg = "Comment must not contain '--' (double-hyphen)";
259 break;
261 errmsg = "xmlParsePI : no target name";
262 break;
264 errmsg = "Invalid PI name";
265 break;
267 errmsg = "NOTATION: Name expected here";
268 break;
270 errmsg = "'>' required to close NOTATION declaration";
271 break;
273 errmsg = "Entity value required";
274 break;
276 errmsg = "Fragment not allowed";
277 break;
279 errmsg = "'(' required to start ATTLIST enumeration";
280 break;
282 errmsg = "NmToken expected in ATTLIST enumeration";
283 break;
285 errmsg = "')' required to finish ATTLIST enumeration";
286 break;
288 errmsg = "MixedContentDecl : '|' or ')*' expected";
289 break;
291 errmsg = "MixedContentDecl : '#PCDATA' expected";
292 break;
294 errmsg = "ContentDecl : Name or '(' expected";
295 break;
297 errmsg = "ContentDecl : ',' '|' or ')' expected";
298 break;
300 errmsg =
301 "PEReference: forbidden within markup decl in internal subset";
302 break;
304 errmsg = "expected '>'";
305 break;
307 errmsg = "XML conditional section '[' expected";
308 break;
310 errmsg = "Content error in the external subset";
311 break;
313 errmsg =
314 "conditional section INCLUDE or IGNORE keyword expected";
315 break;
317 errmsg = "XML conditional section not closed";
318 break;
320 errmsg = "Text declaration '<?xml' required";
321 break;
323 errmsg = "parsing XML declaration: '?>' expected";
324 break;
326 errmsg = "external parsed entities cannot be standalone";
327 break;
329 errmsg = "EntityRef: expecting ';'";
330 break;
332 errmsg = "DOCTYPE improperly terminated";
333 break;
335 errmsg = "EndTag: '</' not found";
336 break;
338 errmsg = "expected '='";
339 break;
341 errmsg = "String not closed expecting \" or '";
342 break;
344 errmsg = "String not started expecting ' or \"";
345 break;
347 errmsg = "Invalid XML encoding name";
348 break;
350 errmsg = "standalone accepts only 'yes' or 'no'";
351 break;
353 errmsg = "Document is empty";
354 break;
356 errmsg = "Extra content at the end of the document";
357 break;
359 errmsg = "chunk is not well balanced";
360 break;
362 errmsg = "extra content at the end of well balanced chunk";
363 break;
365 errmsg = "Malformed declaration expecting version";
366 break;
368 errmsg = "Name too long";
369 break;
371 errmsg = "Invalid bytes in character encoding";
372 break;
373 case XML_IO_UNKNOWN:
374 errmsg = "I/O error";
375 break;
376#if 0
377 case:
378 errmsg = "";
379 break;
380#endif
381 default:
382 errmsg = "Unregistered error message";
383 }
384 if (ctxt != NULL)
385 ctxt->errNo = error;
386 if (info == NULL) {
388 XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, "%s\n",
389 errmsg);
390 } else {
392 XML_ERR_FATAL, NULL, 0, info, NULL, NULL, 0, 0, "%s: %s\n",
393 errmsg, info);
394 }
395 if (ctxt != NULL) {
396 ctxt->wellFormed = 0;
397 if (ctxt->recovery == 0)
398 ctxt->disableSAX = 1;
399 }
400}
401
411static void LIBXML_ATTR_FORMAT(3,0)
412xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
413 const char *msg, int val)
414{
415 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
416 (ctxt->instate == XML_PARSER_EOF))
417 return;
418 if (ctxt != NULL)
419 ctxt->errNo = error;
422 NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
423 if (ctxt != NULL) {
424 ctxt->wellFormed = 0;
425 if (ctxt->recovery == 0)
426 ctxt->disableSAX = 1;
427 }
428}
429
439int
441 return(IS_BASECHAR(c) || IS_IDEOGRAPHIC(c));
442}
443
444/************************************************************************
445 * *
446 * Input handling functions for progressive parsing *
447 * *
448 ************************************************************************/
449
450/* we need to keep enough input to show errors in context */
451#define LINE_LEN 80
452
460void
461xmlHaltParser(xmlParserCtxtPtr ctxt) {
462 if (ctxt == NULL)
463 return;
464 ctxt->instate = XML_PARSER_EOF;
465 ctxt->disableSAX = 1;
466 while (ctxt->inputNr > 1)
468 if (ctxt->input != NULL) {
469 /*
470 * in case there was a specific allocation deallocate before
471 * overriding base
472 */
473 if (ctxt->input->free != NULL) {
474 ctxt->input->free((xmlChar *) ctxt->input->base);
475 ctxt->input->free = NULL;
476 }
477 if (ctxt->input->buf != NULL) {
478 xmlFreeParserInputBuffer(ctxt->input->buf);
479 ctxt->input->buf = NULL;
480 }
481 ctxt->input->cur = BAD_CAST"";
482 ctxt->input->length = 0;
483 ctxt->input->base = ctxt->input->cur;
484 ctxt->input->end = ctxt->input->cur;
485 }
486}
487
497int
499 return(-1);
500}
501
510int
511xmlParserGrow(xmlParserCtxtPtr ctxt) {
512 xmlParserInputPtr in = ctxt->input;
513 xmlParserInputBufferPtr buf = in->buf;
514 ptrdiff_t curEnd = in->end - in->cur;
515 ptrdiff_t curBase = in->cur - in->base;
516 int ret;
517
518 if (buf == NULL)
519 return(0);
520 /* Don't grow push parser buffer. */
521 if ((ctxt->progressive) && (ctxt->inputNr <= 1))
522 return(0);
523 /* Don't grow memory buffers. */
524 if ((buf->encoder == NULL) && (buf->readcallback == NULL))
525 return(0);
526 if (buf->error != 0)
527 return(-1);
528
529 if (((curEnd > XML_MAX_LOOKUP_LIMIT) ||
530 (curBase > XML_MAX_LOOKUP_LIMIT)) &&
531 ((ctxt->options & XML_PARSE_HUGE) == 0)) {
532 xmlErrMemory(ctxt, "Huge input lookup");
533 xmlHaltParser(ctxt);
534 return(-1);
535 }
536
537 if (curEnd >= INPUT_CHUNK)
538 return(0);
539
541 xmlBufUpdateInput(buf->buffer, in, curBase);
542
543 if (ret < 0) {
544 xmlFatalErr(ctxt, buf->error, NULL);
545 /* Buffer contents may be lost in case of memory errors. */
546 if (buf->error == XML_ERR_NO_MEMORY)
547 xmlHaltParser(ctxt);
548 }
549
550 return(ret);
551}
552
566int
567xmlParserInputGrow(xmlParserInputPtr in, int len) {
568 int ret;
569 size_t indx;
570
571 if ((in == NULL) || (len < 0)) return(-1);
572 if (in->buf == NULL) return(-1);
573 if (in->base == NULL) return(-1);
574 if (in->cur == NULL) return(-1);
575 if (in->buf->buffer == NULL) return(-1);
576
577 /* Don't grow memory buffers. */
578 if ((in->buf->encoder == NULL) && (in->buf->readcallback == NULL))
579 return(0);
580
581 indx = in->cur - in->base;
582 if (xmlBufUse(in->buf->buffer) > (unsigned int) indx + INPUT_CHUNK) {
583 return(0);
584 }
586
587 in->base = xmlBufContent(in->buf->buffer);
588 if (in->base == NULL) {
589 in->base = BAD_CAST "";
590 in->cur = in->base;
591 in->end = in->base;
592 return(-1);
593 }
594 in->cur = in->base + indx;
595 in->end = xmlBufEnd(in->buf->buffer);
596
597 return(ret);
598}
599
606void
607xmlParserShrink(xmlParserCtxtPtr ctxt) {
608 xmlParserInputPtr in = ctxt->input;
609 xmlParserInputBufferPtr buf = in->buf;
610 size_t used;
611
612 if (buf == NULL)
613 return;
614 /* Don't shrink pull parser memory buffers. */
615 if (((ctxt->progressive == 0) || (ctxt->inputNr > 1)) &&
616 (buf->encoder == NULL) &&
617 (buf->readcallback == NULL))
618 return;
619
620 used = in->cur - in->base;
621 /*
622 * Do not shrink on large buffers whose only a tiny fraction
623 * was consumed
624 */
625 if (used > INPUT_CHUNK) {
626 size_t res = xmlBufShrink(buf->buffer, used - LINE_LEN);
627
628 if (res > 0) {
629 used -= res;
630 if ((res > ULONG_MAX) ||
631 (in->consumed > ULONG_MAX - (unsigned long)res))
632 in->consumed = ULONG_MAX;
633 else
634 in->consumed += res;
635 }
636 }
637
638 xmlBufUpdateInput(buf->buffer, in, used);
639}
640
649void
650xmlParserInputShrink(xmlParserInputPtr in) {
651 size_t used;
652 size_t ret;
653
654 if (in == NULL) return;
655 if (in->buf == NULL) return;
656 if (in->base == NULL) return;
657 if (in->cur == NULL) return;
658 if (in->buf->buffer == NULL) return;
659
660 used = in->cur - in->base;
661 /*
662 * Do not shrink on large buffers whose only a tiny fraction
663 * was consumed
664 */
665 if (used > INPUT_CHUNK) {
666 ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
667 if (ret > 0) {
668 used -= ret;
669 if ((ret > ULONG_MAX) ||
670 (in->consumed > ULONG_MAX - (unsigned long)ret))
671 in->consumed = ULONG_MAX;
672 else
673 in->consumed += ret;
674 }
675 }
676
677 if (xmlBufUse(in->buf->buffer) <= INPUT_CHUNK) {
679 }
680
681 in->base = xmlBufContent(in->buf->buffer);
682 if (in->base == NULL) {
683 /* TODO: raise error */
684 in->base = BAD_CAST "";
685 in->cur = in->base;
686 in->end = in->base;
687 return;
688 }
689 in->cur = in->base + used;
690 in->end = xmlBufEnd(in->buf->buffer);
691}
692
693/************************************************************************
694 * *
695 * UTF8 character input and related functions *
696 * *
697 ************************************************************************/
698
708void
709xmlNextChar(xmlParserCtxtPtr ctxt)
710{
711 const unsigned char *cur;
712 size_t avail;
713 int c;
714
715 if ((ctxt == NULL) || (ctxt->instate == XML_PARSER_EOF) ||
716 (ctxt->input == NULL))
717 return;
718
719 avail = ctxt->input->end - ctxt->input->cur;
720
721 if (avail < INPUT_CHUNK) {
722 xmlParserGrow(ctxt);
723 if ((ctxt->instate == XML_PARSER_EOF) ||
724 (ctxt->input->cur >= ctxt->input->end))
725 return;
726 avail = ctxt->input->end - ctxt->input->cur;
727 }
728
729 cur = ctxt->input->cur;
730 c = *cur;
731
732 if (c < 0x80) {
733 if (c == '\n') {
734 ctxt->input->cur++;
735 ctxt->input->line++;
736 ctxt->input->col = 1;
737 } else if (c == '\r') {
738 /*
739 * 2.11 End-of-Line Handling
740 * the literal two-character sequence "#xD#xA" or a standalone
741 * literal #xD, an XML processor must pass to the application
742 * the single character #xA.
743 */
744 ctxt->input->cur += ((cur[1] == '\n') ? 2 : 1);
745 ctxt->input->line++;
746 ctxt->input->col = 1;
747 return;
748 } else {
749 ctxt->input->cur++;
750 ctxt->input->col++;
751 }
752 } else {
753 ctxt->input->col++;
754
755 if ((avail < 2) || (cur[1] & 0xc0) != 0x80)
756 goto encoding_error;
757
758 if (c < 0xe0) {
759 /* 2-byte code */
760 if (c < 0xc2)
761 goto encoding_error;
762 ctxt->input->cur += 2;
763 } else {
764 unsigned int val = (c << 8) | cur[1];
765
766 if ((avail < 3) || (cur[2] & 0xc0) != 0x80)
767 goto encoding_error;
768
769 if (c < 0xf0) {
770 /* 3-byte code */
771 if ((val < 0xe0a0) || ((val >= 0xeda0) && (val < 0xee00)))
772 goto encoding_error;
773 ctxt->input->cur += 3;
774 } else {
775 if ((avail < 4) || ((cur[3] & 0xc0) != 0x80))
776 goto encoding_error;
777
778 /* 4-byte code */
779 if ((val < 0xf090) || (val >= 0xf490))
780 goto encoding_error;
781 ctxt->input->cur += 4;
782 }
783 }
784 }
785
786 return;
787
788encoding_error:
789 /* Only report the first error */
790 if ((ctxt->input->flags & XML_INPUT_ENCODING_ERROR) == 0) {
791 if ((ctxt == NULL) || (ctxt->input == NULL) ||
792 (ctxt->input->end - ctxt->input->cur < 4)) {
794 "Input is not proper UTF-8, indicate encoding !\n",
795 NULL, NULL);
796 } else {
797 char buffer[150];
798
799 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
800 ctxt->input->cur[0], ctxt->input->cur[1],
801 ctxt->input->cur[2], ctxt->input->cur[3]);
803 "Input is not proper UTF-8, indicate encoding !\n%s",
805 }
806 ctxt->input->flags |= XML_INPUT_ENCODING_ERROR;
807 }
808 ctxt->input->cur++;
809 return;
810}
811
832int
833xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
834 const unsigned char *cur;
835 size_t avail;
836 int c;
837
838 if ((ctxt == NULL) || (len == NULL) || (ctxt->input == NULL)) return(0);
839 if (ctxt->instate == XML_PARSER_EOF)
840 return(0);
841
842 avail = ctxt->input->end - ctxt->input->cur;
843
844 if (avail < INPUT_CHUNK) {
845 xmlParserGrow(ctxt);
846 if (ctxt->instate == XML_PARSER_EOF)
847 return(0);
848 avail = ctxt->input->end - ctxt->input->cur;
849 }
850
851 cur = ctxt->input->cur;
852 c = *cur;
853
854 if (c < 0x80) {
855 /* 1-byte code */
856 if (c < 0x20) {
857 /*
858 * 2.11 End-of-Line Handling
859 * the literal two-character sequence "#xD#xA" or a standalone
860 * literal #xD, an XML processor must pass to the application
861 * the single character #xA.
862 */
863 if (c == '\r') {
864 /*
865 * TODO: This function shouldn't change the 'cur' pointer
866 * as side effect, but the NEXTL macro in parser.c relies
867 * on this behavior when incrementing line numbers.
868 */
869 if (cur[1] == '\n')
870 ctxt->input->cur++;
871 *len = 1;
872 c = '\n';
873 } else if (c == 0) {
874 if (ctxt->input->cur >= ctxt->input->end) {
875 *len = 0;
876 } else {
877 *len = 1;
878 /*
879 * TODO: Null bytes should be handled by callers,
880 * but this can be tricky.
881 */
882 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
883 "Char 0x0 out of allowed range\n", c);
884 }
885 } else {
886 *len = 1;
887 }
888 } else {
889 *len = 1;
890 }
891
892 return(c);
893 } else {
894 int val;
895
896 if (avail < 2)
897 goto incomplete_sequence;
898 if ((cur[1] & 0xc0) != 0x80)
899 goto encoding_error;
900
901 if (c < 0xe0) {
902 /* 2-byte code */
903 if (c < 0xc2)
904 goto encoding_error;
905 val = (c & 0x1f) << 6;
906 val |= cur[1] & 0x3f;
907 *len = 2;
908 } else {
909 if (avail < 3)
910 goto incomplete_sequence;
911 if ((cur[2] & 0xc0) != 0x80)
912 goto encoding_error;
913
914 if (c < 0xf0) {
915 /* 3-byte code */
916 val = (c & 0xf) << 12;
917 val |= (cur[1] & 0x3f) << 6;
918 val |= cur[2] & 0x3f;
919 if ((val < 0x800) || ((val >= 0xd800) && (val < 0xe000)))
920 goto encoding_error;
921 *len = 3;
922 } else {
923 if (avail < 4)
924 goto incomplete_sequence;
925 if ((cur[3] & 0xc0) != 0x80)
926 goto encoding_error;
927
928 /* 4-byte code */
929 val = (c & 0x0f) << 18;
930 val |= (cur[1] & 0x3f) << 12;
931 val |= (cur[2] & 0x3f) << 6;
932 val |= cur[3] & 0x3f;
933 if ((val < 0x10000) || (val >= 0x110000))
934 goto encoding_error;
935 *len = 4;
936 }
937 }
938
939 return(val);
940 }
941
942encoding_error:
943 /* Only report the first error */
944 if ((ctxt->input->flags & XML_INPUT_ENCODING_ERROR) == 0) {
945 if (ctxt->input->end - ctxt->input->cur < 4) {
947 "Input is not proper UTF-8, indicate encoding !\n",
948 NULL, NULL);
949 } else {
950 char buffer[150];
951
952 snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
953 ctxt->input->cur[0], ctxt->input->cur[1],
954 ctxt->input->cur[2], ctxt->input->cur[3]);
956 "Input is not proper UTF-8, indicate encoding !\n%s",
958 }
959 ctxt->input->flags |= XML_INPUT_ENCODING_ERROR;
960 }
961 *len = 1;
962 return(0xFFFD); /* U+FFFD Replacement Character */
963
964incomplete_sequence:
965 /*
966 * An encoding problem may arise from a truncated input buffer
967 * splitting a character in the middle. In that case do not raise
968 * an error but return 0. This should only happen when push parsing
969 * char data.
970 */
971 *len = 0;
972 return(0);
973}
974
989int
991 const xmlChar *cur, int *len) {
992 int c;
993
994 if ((cur == NULL) || (len == NULL))
995 return(0);
996
997 /* cur is zero-terminated, so we can lie about its length. */
998 *len = 4;
1000
1001 return((c < 0) ? 0 : c);
1002}
1003
1013int
1015 if ((out == NULL) || (val < 0)) return(0);
1016 /*
1017 * We are supposed to handle UTF8, check it's valid
1018 * From rfc2044: encoding of the Unicode values on UTF-8:
1019 *
1020 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
1021 * 0000 0000-0000 007F 0xxxxxxx
1022 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
1023 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
1024 */
1025 if (val >= 0x80) {
1026 xmlChar *savedout = out;
1027 int bits;
1028 if (val < 0x800) { *out++= (val >> 6) | 0xC0; bits= 0; }
1029 else if (val < 0x10000) { *out++= (val >> 12) | 0xE0; bits= 6;}
1030 else if (val < 0x110000) { *out++= (val >> 18) | 0xF0; bits= 12; }
1031 else {
1032 xmlErrEncodingInt(NULL, XML_ERR_INVALID_CHAR,
1033 "Internal error, xmlCopyCharMultiByte 0x%X out of bound\n",
1034 val);
1035 return(0);
1036 }
1037 for ( ; bits >= 0; bits-= 6)
1038 *out++= ((val >> bits) & 0x3F) | 0x80 ;
1039 return (out - savedout);
1040 }
1041 *out = val;
1042 return 1;
1043}
1044
1056int
1058 if ((out == NULL) || (val < 0)) return(0);
1059 /* the len parameter is ignored */
1060 if (val >= 0x80) {
1061 return(xmlCopyCharMultiByte (out, val));
1062 }
1063 *out = val;
1064 return 1;
1065}
1066
1067/************************************************************************
1068 * *
1069 * Commodity functions to switch encodings *
1070 * *
1071 ************************************************************************/
1072
1074xmlDetectEBCDIC(xmlParserInputPtr input) {
1075 xmlChar out[200];
1077 int inlen, outlen, res, i;
1078
1079 /*
1080 * To detect the EBCDIC code page, we convert the first 200 bytes
1081 * to EBCDIC-US and try to find the encoding declaration.
1082 */
1084 if (handler == NULL)
1085 return(NULL);
1086 outlen = sizeof(out) - 1;
1087 inlen = input->end - input->cur;
1088 res = xmlEncInputChunk(handler, out, &outlen, input->cur, &inlen);
1089 if (res < 0)
1090 return(handler);
1091 out[outlen] = 0;
1092
1093 for (i = 0; i < outlen; i++) {
1094 if (out[i] == '>')
1095 break;
1096 if ((out[i] == 'e') &&
1097 (xmlStrncmp(out + i, BAD_CAST "encoding", 8) == 0)) {
1098 int start, cur, quote;
1099
1100 i += 8;
1101 while (IS_BLANK_CH(out[i]))
1102 i += 1;
1103 if (out[i++] != '=')
1104 break;
1105 while (IS_BLANK_CH(out[i]))
1106 i += 1;
1107 quote = out[i++];
1108 if ((quote != '\'') && (quote != '"'))
1109 break;
1110 start = i;
1111 cur = out[i];
1112 while (((cur >= 'a') && (cur <= 'z')) ||
1113 ((cur >= 'A') && (cur <= 'Z')) ||
1114 ((cur >= '0') && (cur <= '9')) ||
1115 (cur == '.') || (cur == '_') ||
1116 (cur == '-'))
1117 cur = out[++i];
1118 if (cur != quote)
1119 break;
1120 out[i] = 0;
1122 return(xmlFindCharEncodingHandler((char *) out + start));
1123 }
1124 }
1125
1126 /*
1127 * ICU handlers are stateful, so we have to recreate them.
1128 */
1131}
1132
1145int
1146xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
1147{
1149 int check = 1;
1150 int ret;
1151
1152 if ((ctxt == NULL) || (ctxt->input == NULL))
1153 return(-1);
1154
1155 switch (enc) {
1159 check = 0;
1160 break;
1162 handler = xmlDetectEBCDIC(ctxt->input);
1163 break;
1164 default:
1166 break;
1167 }
1168
1169 if ((check) && (handler == NULL)) {
1170 const char *name = xmlGetCharEncodingName(enc);
1171
1173 "encoding not supported: %s\n",
1174 BAD_CAST (name ? name : "<null>"), NULL);
1175 /*
1176 * TODO: We could recover from errors in external entities
1177 * if we didn't stop the parser. But most callers of this
1178 * function don't check the return value.
1179 */
1180 xmlStopParser(ctxt);
1181 return(-1);
1182 }
1183
1184 ret = xmlSwitchInputEncoding(ctxt, ctxt->input, handler);
1185
1186 if ((ret >= 0) && (enc == XML_CHAR_ENCODING_NONE)) {
1187 ctxt->input->flags &= ~XML_INPUT_HAS_ENCODING;
1188 }
1189
1190 return(ret);
1191}
1192
1205int
1206xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
1208{
1209 int nbchars;
1210 xmlParserInputBufferPtr in;
1211
1212 if ((input == NULL) || (input->buf == NULL)) {
1214 return (-1);
1215 }
1216 in = input->buf;
1217
1218 input->flags |= XML_INPUT_HAS_ENCODING;
1219
1220 /*
1221 * UTF-8 requires no encoding handler.
1222 */
1223 if ((handler != NULL) &&
1224 (xmlStrcasecmp(BAD_CAST handler->name, BAD_CAST "UTF-8") == 0)) {
1226 handler = NULL;
1227 }
1228
1229 if (in->encoder == handler)
1230 return (0);
1231
1232 if (in->encoder != NULL) {
1233 /*
1234 * Switching encodings during parsing is a really bad idea,
1235 * but Chromium can switch between ISO-8859-1 and UTF-16 before
1236 * separate calls to xmlParseChunk.
1237 *
1238 * TODO: We should check whether the "raw" input buffer is empty and
1239 * convert the old content using the old encoder.
1240 */
1241
1242 xmlCharEncCloseFunc(in->encoder);
1243 in->encoder = handler;
1244 return (0);
1245 }
1246
1247 in->encoder = handler;
1248
1249 /*
1250 * Is there already some content down the pipe to convert ?
1251 */
1252 if (xmlBufIsEmpty(in->buffer) == 0) {
1253 size_t processed;
1254
1255 /*
1256 * Shrink the current input buffer.
1257 * Move it as the raw buffer and create a new input buffer
1258 */
1259 processed = input->cur - input->base;
1260 xmlBufShrink(in->buffer, processed);
1261 input->consumed += processed;
1262 in->raw = in->buffer;
1263 in->buffer = xmlBufCreate();
1264 in->rawconsumed = processed;
1265
1266 nbchars = xmlCharEncInput(in);
1267 xmlBufResetInput(in->buffer, input);
1268 if (nbchars < 0) {
1269 /* TODO: This could be an out of memory or an encoding error. */
1270 xmlErrInternal(ctxt,
1271 "switching encoding: encoder error\n",
1272 NULL);
1273 xmlHaltParser(ctxt);
1274 return (-1);
1275 }
1276 }
1277 return (0);
1278}
1279
1292int
1294{
1295 if (ctxt == NULL)
1296 return(-1);
1297 return(xmlSwitchInputEncoding(ctxt, ctxt->input, handler));
1298}
1299
1308void
1309xmlDetectEncoding(xmlParserCtxtPtr ctxt) {
1310 const xmlChar *in;
1311 xmlCharEncoding enc;
1312 int bomSize;
1313 int autoFlag = 0;
1314
1315 if (xmlParserGrow(ctxt) < 0)
1316 return;
1317 in = ctxt->input->cur;
1318 if (ctxt->input->end - in < 4)
1319 return;
1320
1321 if (ctxt->input->flags & XML_INPUT_HAS_ENCODING) {
1322 /*
1323 * If the encoding was already set, only skip the BOM which was
1324 * possibly decoded to UTF-8.
1325 */
1326 if ((in[0] == 0xEF) && (in[1] == 0xBB) && (in[2] == 0xBF)) {
1327 ctxt->input->cur += 3;
1328 }
1329
1330 return;
1331 }
1332
1334 bomSize = 0;
1335
1336 switch (in[0]) {
1337 case 0x00:
1338 if ((in[1] == 0x00) && (in[2] == 0x00) && (in[3] == 0x3C)) {
1340 autoFlag = XML_INPUT_AUTO_OTHER;
1341 } else if ((in[1] == 0x3C) && (in[2] == 0x00) && (in[3] == 0x3F)) {
1343 autoFlag = XML_INPUT_AUTO_UTF16BE;
1344 }
1345 break;
1346
1347 case 0x3C:
1348 if (in[1] == 0x00) {
1349 if ((in[2] == 0x00) && (in[3] == 0x00)) {
1351 autoFlag = XML_INPUT_AUTO_OTHER;
1352 } else if ((in[2] == 0x3F) && (in[3] == 0x00)) {
1354 autoFlag = XML_INPUT_AUTO_UTF16LE;
1355 }
1356 }
1357 break;
1358
1359 case 0x4C:
1360 if ((in[1] == 0x6F) && (in[2] == 0xA7) && (in[3] == 0x94)) {
1362 autoFlag = XML_INPUT_AUTO_OTHER;
1363 }
1364 break;
1365
1366 case 0xEF:
1367 if ((in[1] == 0xBB) && (in[2] == 0xBF)) {
1369 autoFlag = XML_INPUT_AUTO_UTF8;
1370 bomSize = 3;
1371 }
1372 break;
1373
1374 case 0xFE:
1375 if (in[1] == 0xFF) {
1377 autoFlag = XML_INPUT_AUTO_UTF16BE;
1378 bomSize = 2;
1379 }
1380 break;
1381
1382 case 0xFF:
1383 if (in[1] == 0xFE) {
1385 autoFlag = XML_INPUT_AUTO_UTF16LE;
1386 bomSize = 2;
1387 }
1388 break;
1389 }
1390
1391 if (bomSize > 0) {
1392 ctxt->input->cur += bomSize;
1393 }
1394
1395 if (enc != XML_CHAR_ENCODING_NONE) {
1396 ctxt->input->flags |= autoFlag;
1397 xmlSwitchEncoding(ctxt, enc);
1398 }
1399}
1400
1413void
1414xmlSetDeclaredEncoding(xmlParserCtxtPtr ctxt, xmlChar *encoding) {
1415 if (ctxt->encoding != NULL)
1416 xmlFree((xmlChar *) ctxt->encoding);
1417 ctxt->encoding = encoding;
1418
1419 if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) &&
1420 ((ctxt->options & XML_PARSE_IGNORE_ENC) == 0)) {
1422
1423 handler = xmlFindCharEncodingHandler((const char *) encoding);
1424 if (handler == NULL) {
1426 "Unsupported encoding: %s\n",
1427 encoding, NULL);
1428 return;
1429 }
1430
1432 ctxt->input->flags |= XML_INPUT_USES_ENC_DECL;
1433 } else if (ctxt->input->flags & XML_INPUT_AUTO_ENCODING) {
1434 static const char *allowedUTF8[] = {
1435 "UTF-8", "UTF8", NULL
1436 };
1437 static const char *allowedUTF16LE[] = {
1438 "UTF-16", "UTF-16LE", "UTF16", NULL
1439 };
1440 static const char *allowedUTF16BE[] = {
1441 "UTF-16", "UTF-16BE", "UTF16", NULL
1442 };
1443 const char **allowed = NULL;
1444 const char *autoEnc = NULL;
1445
1446 switch (ctxt->input->flags & XML_INPUT_AUTO_ENCODING) {
1448 allowed = allowedUTF8;
1449 autoEnc = "UTF-8";
1450 break;
1452 allowed = allowedUTF16LE;
1453 autoEnc = "UTF-16LE";
1454 break;
1456 allowed = allowedUTF16BE;
1457 autoEnc = "UTF-16BE";
1458 break;
1459 }
1460
1461 if (allowed != NULL) {
1462 const char **p;
1463 int match = 0;
1464
1465 for (p = allowed; *p != NULL; p++) {
1466 if (xmlStrcasecmp(encoding, BAD_CAST *p) == 0) {
1467 match = 1;
1468 break;
1469 }
1470 }
1471
1472 if (match == 0) {
1473 xmlWarningMsg(ctxt, XML_WAR_ENCODING_MISMATCH,
1474 "Encoding '%s' doesn't match "
1475 "auto-detected '%s'\n",
1476 encoding, BAD_CAST autoEnc);
1477 }
1478 }
1479 }
1480}
1481
1489const xmlChar *
1490xmlGetActualEncoding(xmlParserCtxtPtr ctxt) {
1491 const xmlChar *encoding = NULL;
1492
1493 if ((ctxt->input->flags & XML_INPUT_USES_ENC_DECL) ||
1494 (ctxt->input->flags & XML_INPUT_AUTO_ENCODING)) {
1495 /* Preserve encoding exactly */
1496 encoding = ctxt->encoding;
1497 } else if ((ctxt->input->buf) && (ctxt->input->buf->encoder)) {
1498 encoding = BAD_CAST ctxt->input->buf->encoder->name;
1499 } else if (ctxt->input->flags & XML_INPUT_HAS_ENCODING) {
1500 encoding = BAD_CAST "UTF-8";
1501 }
1502
1503 return(encoding);
1504}
1505
1506/************************************************************************
1507 * *
1508 * Commodity functions to handle entities processing *
1509 * *
1510 ************************************************************************/
1511
1518void
1519xmlFreeInputStream(xmlParserInputPtr input) {
1520 if (input == NULL) return;
1521
1522 if (input->filename != NULL) xmlFree((char *) input->filename);
1523 if (input->directory != NULL) xmlFree((char *) input->directory);
1524 if (input->version != NULL) xmlFree((char *) input->version);
1525 if ((input->free != NULL) && (input->base != NULL))
1526 input->free((xmlChar *) input->base);
1527 if (input->buf != NULL)
1529 xmlFree(input);
1530}
1531
1540xmlParserInputPtr
1541xmlNewInputStream(xmlParserCtxtPtr ctxt) {
1542 xmlParserInputPtr input;
1543
1544 input = (xmlParserInputPtr) xmlMalloc(sizeof(xmlParserInput));
1545 if (input == NULL) {
1546 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1547 return(NULL);
1548 }
1549 memset(input, 0, sizeof(xmlParserInput));
1550 input->line = 1;
1551 input->col = 1;
1552
1553 /*
1554 * If the context is NULL the id cannot be initialized, but that
1555 * should not happen while parsing which is the situation where
1556 * the id is actually needed.
1557 */
1558 if (ctxt != NULL) {
1559 if (input->id >= INT_MAX) {
1560 xmlErrMemory(ctxt, "Input ID overflow\n");
1561 return(NULL);
1562 }
1563 input->id = ctxt->input_id++;
1564 }
1565
1566 return(input);
1567}
1568
1580xmlParserInputPtr
1581xmlNewIOInputStream(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input,
1582 xmlCharEncoding enc) {
1583 xmlParserInputPtr inputStream;
1584
1585 if (input == NULL) return(NULL);
1587 xmlGenericError(xmlGenericErrorContext, "new input from I/O\n");
1588 inputStream = xmlNewInputStream(ctxt);
1589 if (inputStream == NULL) {
1590 return(NULL);
1591 }
1592 inputStream->filename = NULL;
1593 inputStream->buf = input;
1594 xmlBufResetInput(inputStream->buf->buffer, inputStream);
1595
1596 if (enc != XML_CHAR_ENCODING_NONE) {
1597 xmlSwitchEncoding(ctxt, enc);
1598 }
1599
1600 return(inputStream);
1601}
1602
1614xmlParserInputPtr
1615xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
1616 xmlParserInputPtr input;
1617
1618 if (entity == NULL) {
1619 xmlErrInternal(ctxt, "xmlNewEntityInputStream entity = NULL\n",
1620 NULL);
1621 return(NULL);
1622 }
1625 "new input from entity: %s\n", entity->name);
1626 if (entity->content == NULL) {
1627 switch (entity->etype) {
1629 xmlErrInternal(ctxt, "Cannot parse entity %s\n",
1630 entity->name);
1631 break;
1634 input = xmlLoadExternalEntity((char *) entity->URI,
1635 (char *) entity->ExternalID, ctxt);
1636 if (input != NULL)
1637 input->entity = entity;
1638 return(input);
1640 xmlErrInternal(ctxt,
1641 "Internal entity %s without content !\n",
1642 entity->name);
1643 break;
1645 xmlErrInternal(ctxt,
1646 "Internal parameter entity %s without content !\n",
1647 entity->name);
1648 break;
1650 xmlErrInternal(ctxt,
1651 "Predefined entity %s without content !\n",
1652 entity->name);
1653 break;
1654 }
1655 return(NULL);
1656 }
1657 input = xmlNewInputStream(ctxt);
1658 if (input == NULL) {
1659 return(NULL);
1660 }
1661 if (entity->URI != NULL)
1662 input->filename = (char *) xmlStrdup((xmlChar *) entity->URI);
1663 input->base = entity->content;
1664 if (entity->length == 0)
1665 entity->length = xmlStrlen(entity->content);
1666 input->cur = entity->content;
1667 input->length = entity->length;
1668 input->end = &entity->content[input->length];
1669 input->entity = entity;
1670 return(input);
1671}
1672
1681xmlParserInputPtr
1682xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
1683 xmlParserInputPtr input;
1684 xmlParserInputBufferPtr buf;
1685
1686 if (buffer == NULL) {
1687 xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
1688 NULL);
1689 return(NULL);
1690 }
1693 "new fixed input: %.30s\n", buffer);
1695 if (buf == NULL) {
1696 xmlErrMemory(ctxt, NULL);
1697 return(NULL);
1698 }
1699 input = xmlNewInputStream(ctxt);
1700 if (input == NULL) {
1701 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1703 return(NULL);
1704 }
1705 input->buf = buf;
1706 xmlBufResetInput(input->buf->buffer, input);
1707 return(input);
1708}
1709
1719xmlParserInputPtr
1720xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
1721 xmlParserInputBufferPtr buf;
1722 xmlParserInputPtr inputStream;
1723 char *directory = NULL;
1724 xmlChar *URI = NULL;
1725
1728 "new input from file: %s\n", filename);
1729 if (ctxt == NULL) return(NULL);
1731 if (buf == NULL) {
1732 if (filename == NULL)
1733 __xmlLoaderErr(ctxt,
1734 "failed to load external entity: NULL filename \n",
1735 NULL);
1736 else
1737 __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n",
1738 (const char *) filename);
1739 return(NULL);
1740 }
1741
1742 inputStream = xmlNewInputStream(ctxt);
1743 if (inputStream == NULL) {
1745 return(NULL);
1746 }
1747
1748 inputStream->buf = buf;
1749 inputStream = xmlCheckHTTPInput(ctxt, inputStream);
1750 if (inputStream == NULL)
1751 return(NULL);
1752
1753 if (inputStream->filename == NULL)
1754 URI = xmlStrdup((xmlChar *) filename);
1755 else
1756 URI = xmlStrdup((xmlChar *) inputStream->filename);
1757 directory = xmlParserGetDirectory((const char *) URI);
1758 if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename);
1759 inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI);
1760 if (URI != NULL) xmlFree((char *) URI);
1761 inputStream->directory = directory;
1762
1763 xmlBufResetInput(inputStream->buf->buffer, inputStream);
1764 if ((ctxt->directory == NULL) && (directory != NULL))
1765 ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
1766 return(inputStream);
1767}
1768
1769/************************************************************************
1770 * *
1771 * Commodity functions to handle parser contexts *
1772 * *
1773 ************************************************************************/
1774
1786static int
1787xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
1788 void *userData)
1789{
1790 xmlParserInputPtr input;
1791
1792 if(ctxt==NULL) {
1793 xmlErrInternal(NULL, "Got NULL parser context\n", NULL);
1794 return(-1);
1795 }
1796
1797 xmlInitParser();
1798
1799 if (ctxt->dict == NULL)
1800 ctxt->dict = xmlDictCreate();
1801 if (ctxt->dict == NULL) {
1802 xmlErrMemory(NULL, "cannot initialize parser context\n");
1803 return(-1);
1804 }
1806
1807 if (ctxt->sax == NULL)
1808 ctxt->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
1809 if (ctxt->sax == NULL) {
1810 xmlErrMemory(NULL, "cannot initialize parser context\n");
1811 return(-1);
1812 }
1813 if (sax == NULL) {
1814 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
1815 xmlSAXVersion(ctxt->sax, 2);
1816 ctxt->userData = ctxt;
1817 } else {
1818 if (sax->initialized == XML_SAX2_MAGIC) {
1819 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
1820 } else {
1821 memset(ctxt->sax, 0, sizeof(xmlSAXHandler));
1822 memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1));
1823 }
1824 ctxt->userData = userData ? userData : ctxt;
1825 }
1826
1827 ctxt->maxatts = 0;
1828 ctxt->atts = NULL;
1829 /* Allocate the Input stack */
1830 if (ctxt->inputTab == NULL) {
1831 ctxt->inputTab = (xmlParserInputPtr *)
1832 xmlMalloc(5 * sizeof(xmlParserInputPtr));
1833 ctxt->inputMax = 5;
1834 }
1835 if (ctxt->inputTab == NULL) {
1836 xmlErrMemory(NULL, "cannot initialize parser context\n");
1837 ctxt->inputNr = 0;
1838 ctxt->inputMax = 0;
1839 ctxt->input = NULL;
1840 return(-1);
1841 }
1842 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1844 }
1845 ctxt->inputNr = 0;
1846 ctxt->input = NULL;
1847
1848 ctxt->version = NULL;
1849 ctxt->encoding = NULL;
1850 ctxt->standalone = -1;
1851 ctxt->hasExternalSubset = 0;
1852 ctxt->hasPErefs = 0;
1853 ctxt->html = 0;
1854 ctxt->external = 0;
1855 ctxt->instate = XML_PARSER_START;
1856 ctxt->token = 0;
1857 ctxt->directory = NULL;
1858
1859 /* Allocate the Node stack */
1860 if (ctxt->nodeTab == NULL) {
1861 ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));
1862 ctxt->nodeMax = 10;
1863 }
1864 if (ctxt->nodeTab == NULL) {
1865 xmlErrMemory(NULL, "cannot initialize parser context\n");
1866 ctxt->nodeNr = 0;
1867 ctxt->nodeMax = 0;
1868 ctxt->node = NULL;
1869 ctxt->inputNr = 0;
1870 ctxt->inputMax = 0;
1871 ctxt->input = NULL;
1872 return(-1);
1873 }
1874 ctxt->nodeNr = 0;
1875 ctxt->node = NULL;
1876
1877 /* Allocate the Name stack */
1878 if (ctxt->nameTab == NULL) {
1879 ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
1880 ctxt->nameMax = 10;
1881 }
1882 if (ctxt->nameTab == NULL) {
1883 xmlErrMemory(NULL, "cannot initialize parser context\n");
1884 ctxt->nodeNr = 0;
1885 ctxt->nodeMax = 0;
1886 ctxt->node = NULL;
1887 ctxt->inputNr = 0;
1888 ctxt->inputMax = 0;
1889 ctxt->input = NULL;
1890 ctxt->nameNr = 0;
1891 ctxt->nameMax = 0;
1892 ctxt->name = NULL;
1893 return(-1);
1894 }
1895 ctxt->nameNr = 0;
1896 ctxt->name = NULL;
1897
1898 /* Allocate the space stack */
1899 if (ctxt->spaceTab == NULL) {
1900 ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));
1901 ctxt->spaceMax = 10;
1902 }
1903 if (ctxt->spaceTab == NULL) {
1904 xmlErrMemory(NULL, "cannot initialize parser context\n");
1905 ctxt->nodeNr = 0;
1906 ctxt->nodeMax = 0;
1907 ctxt->node = NULL;
1908 ctxt->inputNr = 0;
1909 ctxt->inputMax = 0;
1910 ctxt->input = NULL;
1911 ctxt->nameNr = 0;
1912 ctxt->nameMax = 0;
1913 ctxt->name = NULL;
1914 ctxt->spaceNr = 0;
1915 ctxt->spaceMax = 0;
1916 ctxt->space = NULL;
1917 return(-1);
1918 }
1919 ctxt->spaceNr = 1;
1920 ctxt->spaceMax = 10;
1921 ctxt->spaceTab[0] = -1;
1922 ctxt->space = &ctxt->spaceTab[0];
1923 ctxt->myDoc = NULL;
1924 ctxt->wellFormed = 1;
1925 ctxt->nsWellFormed = 1;
1926 ctxt->valid = 1;
1927 ctxt->loadsubset = xmlLoadExtDtdDefaultValue;
1928 if (ctxt->loadsubset) {
1929 ctxt->options |= XML_PARSE_DTDLOAD;
1930 }
1931 ctxt->validate = xmlDoValidityCheckingDefaultValue;
1932 ctxt->pedantic = xmlPedanticParserDefaultValue;
1933 if (ctxt->pedantic) {
1934 ctxt->options |= XML_PARSE_PEDANTIC;
1935 }
1936 ctxt->linenumbers = xmlLineNumbersDefaultValue;
1937 ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
1938 if (ctxt->keepBlanks == 0) {
1939 ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
1940 ctxt->options |= XML_PARSE_NOBLANKS;
1941 }
1942
1943 ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
1944 ctxt->vctxt.userData = ctxt;
1945 ctxt->vctxt.error = xmlParserValidityError;
1946 ctxt->vctxt.warning = xmlParserValidityWarning;
1947 if (ctxt->validate) {
1949 ctxt->vctxt.warning = NULL;
1950 else
1951 ctxt->vctxt.warning = xmlParserValidityWarning;
1952 ctxt->vctxt.nodeMax = 0;
1953 ctxt->options |= XML_PARSE_DTDVALID;
1954 }
1955 ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
1956 if (ctxt->replaceEntities) {
1957 ctxt->options |= XML_PARSE_NOENT;
1958 }
1959 ctxt->record_info = 0;
1960 ctxt->checkIndex = 0;
1961 ctxt->inSubset = 0;
1962 ctxt->errNo = XML_ERR_OK;
1963 ctxt->depth = 0;
1964 ctxt->catalogs = NULL;
1965 ctxt->sizeentities = 0;
1966 ctxt->sizeentcopy = 0;
1967 ctxt->input_id = 1;
1968 ctxt->maxAmpl = XML_MAX_AMPLIFICATION_DEFAULT;
1969 xmlInitNodeInfoSeq(&ctxt->node_seq);
1970
1971 if (ctxt->nsdb == NULL) {
1972 ctxt->nsdb = xmlParserNsCreate();
1973 if (ctxt->nsdb == NULL) {
1974 xmlErrMemory(ctxt, NULL);
1975 return(-1);
1976 }
1977 }
1978
1979 return(0);
1980}
1981
1994int
1995xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
1996{
1997 return(xmlInitSAXParserCtxt(ctxt, NULL, NULL));
1998}
1999
2008void
2009xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
2010{
2011 xmlParserInputPtr input;
2012
2013 if (ctxt == NULL) return;
2014
2015 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
2017 }
2018 if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
2019 if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);
2020 if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
2021 if (ctxt->nodeInfoTab != NULL) xmlFree(ctxt->nodeInfoTab);
2022 if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
2023 if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
2024 if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);
2025 if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);
2026 if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);
2027#ifdef LIBXML_SAX1_ENABLED
2028 if ((ctxt->sax != NULL) &&
2029 (ctxt->sax != (xmlSAXHandlerPtr) &xmlDefaultSAXHandler))
2030#else
2031 if (ctxt->sax != NULL)
2032#endif /* LIBXML_SAX1_ENABLED */
2033 xmlFree(ctxt->sax);
2034 if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
2035 if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
2036 if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
2037 if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
2038 if (ctxt->nsTab != NULL) xmlFree(ctxt->nsTab);
2039 if (ctxt->nsdb != NULL) xmlParserNsFree(ctxt->nsdb);
2040 if (ctxt->attrHash != NULL) xmlFree(ctxt->attrHash);
2041 if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab);
2042 if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs);
2043 if (ctxt->attsDefault != NULL)
2044 xmlHashFree(ctxt->attsDefault, xmlHashDefaultDeallocator);
2045 if (ctxt->attsSpecial != NULL)
2046 xmlHashFree(ctxt->attsSpecial, NULL);
2047 if (ctxt->freeElems != NULL) {
2048 xmlNodePtr cur, next;
2049
2050 cur = ctxt->freeElems;
2051 while (cur != NULL) {
2052 next = cur->next;
2053 xmlFree(cur);
2054 cur = next;
2055 }
2056 }
2057 if (ctxt->freeAttrs != NULL) {
2058 xmlAttrPtr cur, next;
2059
2060 cur = ctxt->freeAttrs;
2061 while (cur != NULL) {
2062 next = cur->next;
2063 xmlFree(cur);
2064 cur = next;
2065 }
2066 }
2067 /*
2068 * cleanup the error strings
2069 */
2070 if (ctxt->lastError.message != NULL)
2071 xmlFree(ctxt->lastError.message);
2072 if (ctxt->lastError.file != NULL)
2073 xmlFree(ctxt->lastError.file);
2074 if (ctxt->lastError.str1 != NULL)
2075 xmlFree(ctxt->lastError.str1);
2076 if (ctxt->lastError.str2 != NULL)
2077 xmlFree(ctxt->lastError.str2);
2078 if (ctxt->lastError.str3 != NULL)
2079 xmlFree(ctxt->lastError.str3);
2080
2081#ifdef LIBXML_CATALOG_ENABLED
2082 if (ctxt->catalogs != NULL)
2083 xmlCatalogFreeLocal(ctxt->catalogs);
2084#endif
2085 xmlFree(ctxt);
2086}
2087
2096xmlParserCtxtPtr
2098{
2099 return(xmlNewSAXParserCtxt(NULL, NULL));
2100}
2101
2113xmlParserCtxtPtr
2114xmlNewSAXParserCtxt(const xmlSAXHandler *sax, void *userData)
2115{
2116 xmlParserCtxtPtr ctxt;
2117
2118 ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
2119 if (ctxt == NULL) {
2120 xmlErrMemory(NULL, "cannot allocate parser context\n");
2121 return(NULL);
2122 }
2123 memset(ctxt, 0, sizeof(xmlParserCtxt));
2124 if (xmlInitSAXParserCtxt(ctxt, sax, userData) < 0) {
2125 xmlFreeParserCtxt(ctxt);
2126 return(NULL);
2127 }
2128 return(ctxt);
2129}
2130
2131/************************************************************************
2132 * *
2133 * Handling of node information *
2134 * *
2135 ************************************************************************/
2136
2144void
2145xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
2146{
2147 if (ctxt==NULL)
2148 return;
2149 xmlClearNodeInfoSeq(&ctxt->node_seq);
2150 xmlCtxtReset(ctxt);
2151}
2152
2153
2165const xmlParserNodeInfo *
2166xmlParserFindNodeInfo(const xmlParserCtxtPtr ctx, const xmlNodePtr node)
2167{
2168 unsigned long pos;
2169
2170 if ((ctx == NULL) || (node == NULL))
2171 return (NULL);
2172 /* Find position where node should be at */
2173 pos = xmlParserFindNodeInfoIndex(&ctx->node_seq, node);
2174 if (pos < ctx->node_seq.length
2175 && ctx->node_seq.buffer[pos].node == node)
2176 return &ctx->node_seq.buffer[pos];
2177 else
2178 return NULL;
2179}
2180
2181
2190void
2192{
2193 if (seq == NULL)
2194 return;
2195 seq->length = 0;
2196 seq->maximum = 0;
2197 seq->buffer = NULL;
2198}
2199
2209void
2211{
2212 if (seq == NULL)
2213 return;
2214 if (seq->buffer != NULL)
2215 xmlFree(seq->buffer);
2216 xmlInitNodeInfoSeq(seq);
2217}
2218
2231unsigned long
2233 const xmlNodePtr node)
2234{
2235 unsigned long upper, lower, middle;
2236 int found = 0;
2237
2238 if ((seq == NULL) || (node == NULL))
2239 return ((unsigned long) -1);
2240
2241 /* Do a binary search for the key */
2242 lower = 1;
2243 upper = seq->length;
2244 middle = 0;
2245 while (lower <= upper && !found) {
2246 middle = lower + (upper - lower) / 2;
2247 if (node == seq->buffer[middle - 1].node)
2248 found = 1;
2249 else if (node < seq->buffer[middle - 1].node)
2250 upper = middle - 1;
2251 else
2252 lower = middle + 1;
2253 }
2254
2255 /* Return position */
2256 if (middle == 0 || seq->buffer[middle - 1].node < node)
2257 return middle;
2258 else
2259 return middle - 1;
2260}
2261
2262
2272void
2273xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
2275{
2276 unsigned long pos;
2277
2278 if ((ctxt == NULL) || (info == NULL)) return;
2279
2280 /* Find pos and check to see if node is already in the sequence */
2281 pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (xmlNodePtr)
2282 info->node);
2283
2284 if ((pos < ctxt->node_seq.length) &&
2285 (ctxt->node_seq.buffer != NULL) &&
2286 (ctxt->node_seq.buffer[pos].node == info->node)) {
2287 ctxt->node_seq.buffer[pos] = *info;
2288 }
2289
2290 /* Otherwise, we need to add new node to buffer */
2291 else {
2292 if ((ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) ||
2293 (ctxt->node_seq.buffer == NULL)) {
2294 xmlParserNodeInfo *tmp_buffer;
2295 unsigned int byte_size;
2296
2297 if (ctxt->node_seq.maximum == 0)
2298 ctxt->node_seq.maximum = 2;
2299 byte_size = (sizeof(*ctxt->node_seq.buffer) *
2300 (2 * ctxt->node_seq.maximum));
2301
2302 if (ctxt->node_seq.buffer == NULL)
2303 tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);
2304 else
2305 tmp_buffer =
2306 (xmlParserNodeInfo *) xmlRealloc(ctxt->node_seq.buffer,
2307 byte_size);
2308
2309 if (tmp_buffer == NULL) {
2310 xmlErrMemory(ctxt, "failed to allocate buffer\n");
2311 return;
2312 }
2313 ctxt->node_seq.buffer = tmp_buffer;
2314 ctxt->node_seq.maximum *= 2;
2315 }
2316
2317 /* If position is not at end, move elements out of the way */
2318 if (pos != ctxt->node_seq.length) {
2319 unsigned long i;
2320
2321 for (i = ctxt->node_seq.length; i > pos; i--)
2322 ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
2323 }
2324
2325 /* Copy element and increase length */
2326 ctxt->node_seq.buffer[pos] = *info;
2327 ctxt->node_seq.length++;
2328 }
2329}
2330
2331/************************************************************************
2332 * *
2333 * Defaults settings *
2334 * *
2335 ************************************************************************/
2347int
2350
2352 return(old);
2353}
2354
2367int
2370
2372 return(old);
2373}
2374
2391int
2394
2396 return(old);
2397}
2398
2425int
2427 int old = xmlKeepBlanksDefaultValue;
2428
2430#ifdef LIBXML_OUTPUT_ENABLED
2431 if (!val)
2432 xmlIndentTreeOutput = 1;
2433#endif
2434 return(old);
2435}
XMLPUBFUN int xmlSAXVersion(xmlSAXHandler *hdlr, int version)
Definition: SAX2.c:2704
XMLPUBFUN void xmlSAX2IgnorableWhitespace(void *ctx, const xmlChar *ch, int len)
static int used
Definition: adh-main.c:39
static int avail
Definition: adh-main.c:39
#define msg(x)
Definition: auth_time.c:54
xmlChar * xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:508
int xmlBufIsEmpty(const xmlBufPtr buf)
Definition: buf.c:610
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1019
xmlBufPtr xmlBufCreate(void)
Definition: buf.c:122
xmlChar * xmlBufContent(const xmlBuf *buf)
Definition: buf.c:490
size_t xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:570
int xmlBufUpdateInput(xmlBufPtr buf, xmlParserInputPtr input, size_t pos)
Definition: buf.c:1044
size_t xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:328
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define NULL
Definition: types.h:112
static const WCHAR quote[]
Definition: reg.c:40
static const WCHAR version[]
Definition: asmname.c:66
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
int WINAPIV fprintf(FILE *file, const char *format,...)
Definition: file.c:5549
int ptrdiff_t
Definition: corecrt.h:194
#define stderr
#define ULONG_MAX
Definition: limits.h:31
#define INT_MAX
Definition: limits.h:26
#define check(expected, result)
Definition: dplayx.c:32
return ret
Definition: mutex.c:146
XML_HIDDEN int xmlCharEncInput(xmlParserInputBufferPtr input)
XML_HIDDEN int xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out, int *outlen, const unsigned char *in, int *inlen)
const char * xmlGetCharEncodingName(xmlCharEncoding enc)
Definition: encoding.c:1229
xmlCharEncodingHandlerPtr xmlGetCharEncodingHandler(xmlCharEncoding enc)
Definition: encoding.c:1547
xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char *name)
Definition: encoding.c:1677
xmlCharEncoding
Definition: encoding.h:65
@ XML_CHAR_ENCODING_UTF8
Definition: encoding.h:68
@ XML_CHAR_ENCODING_UTF16BE
Definition: encoding.h:70
@ XML_CHAR_ENCODING_EBCDIC
Definition: encoding.h:73
@ XML_CHAR_ENCODING_UCS4LE
Definition: encoding.h:71
@ XML_CHAR_ENCODING_UCS4BE
Definition: encoding.h:72
@ XML_CHAR_ENCODING_UTF16LE
Definition: encoding.h:69
@ XML_CHAR_ENCODING_NONE
Definition: encoding.h:67
@ XML_CHAR_ENCODING_ASCII
Definition: encoding.h:89
XMLPUBFUN int xmlCharEncCloseFunc(xmlCharEncodingHandler *handler)
FxCollectionEntry * cur
GLuint start
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint in
Definition: glext.h:9616
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLenum GLenum GLenum input
Definition: glext.h:9031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ATTRIBUTE_UNUSED
Definition: i386-dis.c:36
@ extra
Definition: id3.c:95
#define bits
Definition: infblock.c:15
const char * filename
Definition: ioapi.h:137
#define c
Definition: ke_i.h:80
@ XML_EXTERNAL_GENERAL_PARSED_ENTITY
Definition: entities.h:28
@ XML_INTERNAL_PREDEFINED_ENTITY
Definition: entities.h:32
@ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
Definition: entities.h:29
@ XML_INTERNAL_GENERAL_ENTITY
Definition: entities.h:27
@ XML_INTERNAL_PARAMETER_ENTITY
Definition: entities.h:30
@ XML_EXTERNAL_PARAMETER_ENTITY
Definition: entities.h:31
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq, const xmlNodePtr node)
void __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, const char *msg, const xmlChar *str1, const xmlChar *str2)
int xmlCopyCharMultiByte(xmlChar *out, int val)
xmlParserInputPtr xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer)
xmlParserCtxtPtr xmlNewParserCtxt(void)
int xmlParserGrow(xmlParserCtxtPtr ctxt)
void xmlFreeInputStream(xmlParserInputPtr input)
int xmlCopyChar(int len ATTRIBUTE_UNUSED, xmlChar *out, int val)
void xmlParserInputShrink(xmlParserInputPtr in)
int xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
static int xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax, void *userData)
#define LINE_LEN
xmlParserCtxtPtr xmlNewSAXParserCtxt(const xmlSAXHandler *sax, void *userData)
#define XML_MAX_AMPLIFICATION_DEFAULT
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
int xmlKeepBlanksDefault(int val)
void xmlNextChar(xmlParserCtxtPtr ctxt)
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
void xmlCheckVersion(int version)
void xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity)
int xmlStringCurrentChar(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, const xmlChar *cur, int *len)
int xmlParserInputGrow(xmlParserInputPtr in, int len)
void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
const xmlChar * xmlGetActualEncoding(xmlParserCtxtPtr ctxt)
void xmlSetDeclaredEncoding(xmlParserCtxtPtr ctxt, xmlChar *encoding)
int xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler)
int xmlPedanticParserDefault(int val)
xmlParserInputPtr xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename)
int xmlSwitchToEncoding(xmlParserCtxtPtr ctxt, xmlCharEncodingHandlerPtr handler)
const xmlParserNodeInfo * xmlParserFindNodeInfo(const xmlParserCtxtPtr ctx, const xmlNodePtr node)
int xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
static xmlCharEncodingHandlerPtr xmlDetectEBCDIC(xmlParserInputPtr input)
int xmlSubstituteEntitiesDefault(int val)
void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
int xmlIsLetter(int c)
void xmlFatalErr(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *info)
void xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, const xmlParserNodeInfoPtr info)
void xmlParserShrink(xmlParserCtxtPtr ctxt)
int xmlLineNumbersDefault(int val)
int xmlCurrentChar(xmlParserCtxtPtr ctxt, int *len)
int xmlParserInputRead(xmlParserInputPtr in ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUSED)
xmlParserInputPtr xmlNewIOInputStream(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input, xmlCharEncoding enc)
void xmlDetectEncoding(xmlParserCtxtPtr ctxt)
void xmlHaltParser(xmlParserCtxtPtr ctxt)
#define IS_IDEOGRAPHIC(c)
#define XML_MAX_LOOKUP_LIMIT
#define XML_MAX_DICTIONARY_LIMIT
XMLPUBFUN xmlParserInputPtr inputPop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1927
#define INPUT_CHUNK
#define IS_BASECHAR(c)
#define IS_BLANK_CH(c)
static unsigned __int64 next
Definition: rand_nt.c:6
const WCHAR * str
void xmlDictFree(xmlDictPtr dict)
Definition: dict.c:333
size_t xmlDictSetLimit(xmlDictPtr dict, size_t limit)
Definition: dict.c:421
xmlDictPtr xmlDictCreate(void)
Definition: dict.c:262
int xmlSubstituteEntitiesDefaultValue
Definition: globals.c:356
void * xmlGenericErrorContext
Definition: globals.c:410
xmlReallocFunc xmlRealloc
Definition: globals.c:214
xmlFreeFunc xmlFree
Definition: globals.c:184
xmlGenericErrorFunc xmlGenericError
Definition: globals.c:396
int xmlParserDebugEntities
Definition: globals.c:277
int xmlLoadExtDtdDefaultValue
Definition: globals.c:308
xmlMallocFunc xmlMalloc
Definition: globals.c:193
int xmlDoValidityCheckingDefaultValue
Definition: globals.c:287
int xmlKeepBlanksDefaultValue
Definition: globals.c:343
int xmlPedanticParserDefaultValue
Definition: globals.c:318
int xmlGetWarningsDefaultValue
Definition: globals.c:297
int xmlLineNumbersDefaultValue
Definition: globals.c:330
void xmlHashFree(xmlHashTablePtr hash, xmlHashDeallocator dealloc)
Definition: hash.c:229
void xmlHashDefaultDeallocator(void *entry, const xmlChar *key ATTRIBUTE_UNUSED)
Definition: hash.c:603
@ XML_PARSER_EOF
Definition: parser.h:116
@ XML_PARSER_START
Definition: parser.h:117
XMLPUBFUN xmlParserInputPtr xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
XML_GLOBALS_PARSER XMLPUBFUN void xmlInitParser(void)
Definition: threads.c:569
@ XML_PARSE_DTDVALID
Definition: parser.h:1234
@ XML_PARSE_NOBLANKS
Definition: parser.h:1238
@ XML_PARSE_IGNORE_ENC
Definition: parser.h:1253
@ XML_PARSE_DTDLOAD
Definition: parser.h:1232
@ XML_PARSE_HUGE
Definition: parser.h:1251
@ XML_PARSE_NOENT
Definition: parser.h:1231
@ XML_PARSE_PEDANTIC
Definition: parser.h:1237
#define XML_SAX2_MAGIC
Definition: parser.h:687
XMLPUBFUN void xmlStopParser(xmlParserCtxtPtr ctxt)
Definition: parser.c:12311
XMLPUBFUN void xmlCtxtReset(xmlParserCtxtPtr ctxt)
Definition: parser.c:14372
XML_HIDDEN void __xmlRaiseError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel, void *data, void *ctx, void *nod, int domain, int code, xmlErrorLevel level, const char *file, int line, const char *str1, const char *str2, const char *str3, int int1, int col, const char *msg,...) LIBXML_ATTR_FORMAT(16
XML_HIDDEN void xmlParserInputBufferPtr xmlParserInputBufferCreateString(const xmlChar *str)
XML_HIDDEN void __xmlLoaderErr(void *ctx, const char *msg, const char *filename) LIBXML_ATTR_FORMAT(2
#define XML_INPUT_ENCODING_ERROR
Definition: parser.h:27
#define XML_INPUT_AUTO_UTF16LE
Definition: parser.h:23
#define XML_INPUT_AUTO_UTF8
Definition: parser.h:22
XML_HIDDEN void xmlParserErrors const char const xmlChar const xmlChar * str2
Definition: parser.h:35
#define XML_INPUT_USES_ENC_DECL
Definition: parser.h:26
XML_HIDDEN void xmlParserNsFree(xmlParserNsData *nsdb)
Definition: parser.c:1431
#define XML_INPUT_AUTO_ENCODING
Definition: parser.h:21
#define XML_INPUT_AUTO_UTF16BE
Definition: parser.h:24
#define XML_INPUT_HAS_ENCODING
Definition: parser.h:20
XML_HIDDEN xmlParserNsData * xmlParserNsCreate(void)
Definition: parser.c:1413
XML_HIDDEN void xmlParserErrors const char const xmlChar * str1
Definition: parser.h:35
#define XML_VCTXT_USE_PCTXT
Definition: parser.h:18
#define XML_INPUT_AUTO_OTHER
Definition: parser.h:25
#define memset(x, y, z)
Definition: compat.h:39
unsigned long length
Definition: parser.h:105
unsigned long maximum
Definition: parser.h:104
xmlParserNodeInfo * buffer
Definition: parser.h:106
const struct _xmlNode * node
Definition: parser.h:93
char * name
Definition: compiler.c:66
Definition: actctx.c:446
WCHAR * name
Definition: actctx.c:463
Definition: match.c:28
Definition: name.c:39
static int processed(const type_t *type)
Definition: typegen.c:2524
Definition: dlist.c:348
XMLPUBFUN xmlChar * xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2394
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define snprintf
Definition: wintirpc.h:48
XMLPUBFUN void xmlFreeParserInputBuffer(xmlParserInputBufferPtr in)
XMLPUBFUN char * xmlParserGetDirectory(const char *filename)
XMLPUBFUN xmlParserInputPtr xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret)
XMLPUBFUN int xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len)
XMLPUBFUN xmlParserInputBufferPtr xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc)
XMLPUBFUN int xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len)
@ XML_ERR_FATAL
Definition: xmlerror.h:28
XMLPUBFUN void XMLPUBFUN void XMLPUBFUN void xmlParserValidityError(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
@ XML_FROM_PARSER
Definition: xmlerror.h:38
xmlParserErrors
Definition: xmlerror.h:99
@ XML_ERR_PEREF_NO_NAME
Definition: xmlerror.h:124
@ XML_ERR_NOT_WELL_BALANCED
Definition: xmlerror.h:185
@ XML_ERR_ENCODING_NAME
Definition: xmlerror.h:179
@ XML_ERR_ENTITY_NOT_FINISHED
Definition: xmlerror.h:137
@ XML_WAR_ENCODING_MISMATCH
Definition: xmlerror.h:213
@ XML_ERR_ENTITYREF_SEMICOL_MISSING
Definition: xmlerror.h:123
@ XML_ERR_PEREF_IN_PROLOG
Definition: xmlerror.h:119
@ XML_ERR_LT_IN_ATTRIBUTE
Definition: xmlerror.h:138
@ XML_ERR_ENTITY_PE_INTERNAL
Definition: xmlerror.h:188
@ XML_ERR_ATTLIST_NOT_STARTED
Definition: xmlerror.h:150
@ XML_ERR_LITERAL_NOT_FINISHED
Definition: xmlerror.h:144
@ XML_ERR_XMLDECL_NOT_FINISHED
Definition: xmlerror.h:157
@ XML_ERR_DOCUMENT_END
Definition: xmlerror.h:105
@ XML_ERR_ELEMCONTENT_NOT_STARTED
Definition: xmlerror.h:154
@ XML_ERR_LTSLASH_REQUIRED
Definition: xmlerror.h:174
@ XML_ERR_PI_NOT_STARTED
Definition: xmlerror.h:146
@ XML_ERR_MIXED_NOT_STARTED
Definition: xmlerror.h:152
@ XML_ERR_PEREF_IN_EPILOG
Definition: xmlerror.h:120
@ XML_ERR_OK
Definition: xmlerror.h:100
@ XML_ERR_DOCTYPE_NOT_FINISHED
Definition: xmlerror.h:161
@ XML_ERR_CONDSEC_INVALID
Definition: xmlerror.h:183
@ XML_ERR_ENTITY_LOOP
Definition: xmlerror.h:189
@ XML_ERR_INVALID_CHAR
Definition: xmlerror.h:109
@ XML_ERR_EXT_ENTITY_STANDALONE
Definition: xmlerror.h:182
@ XML_ERR_RESERVED_XML_NAME
Definition: xmlerror.h:164
@ XML_IO_UNKNOWN
Definition: xmlerror.h:419
@ XML_ERR_HYPHEN_IN_COMMENT
Definition: xmlerror.h:180
@ XML_ERR_MISPLACED_CDATA_END
Definition: xmlerror.h:162
@ XML_ERR_CONDSEC_INVALID_KEYWORD
Definition: xmlerror.h:195
@ XML_ERR_INTERNAL_ERROR
Definition: xmlerror.h:101
@ XML_ERR_URI_FRAGMENT
Definition: xmlerror.h:192
@ XML_ERR_VALUE_REQUIRED
Definition: xmlerror.h:184
@ XML_ERR_INVALID_ENCODING
Definition: xmlerror.h:181
@ XML_ERR_PEREF_AT_EOF
Definition: xmlerror.h:118
@ XML_ERR_INVALID_CHARREF
Definition: xmlerror.h:108
@ XML_ERR_NMTOKEN_REQUIRED
Definition: xmlerror.h:167
@ XML_ERR_PEREF_IN_INT_SUBSET
Definition: xmlerror.h:121
@ XML_ERR_GT_REQUIRED
Definition: xmlerror.h:173
@ XML_ERR_ELEMCONTENT_NOT_FINISHED
Definition: xmlerror.h:155
@ XML_ERR_PCDATA_REQUIRED
Definition: xmlerror.h:169
@ XML_ERR_NOTATION_NOT_STARTED
Definition: xmlerror.h:148
@ XML_ERR_STRING_NOT_CLOSED
Definition: xmlerror.h:134
@ XML_ERR_ATTRIBUTE_NOT_STARTED
Definition: xmlerror.h:139
@ XML_ERR_CONDSEC_NOT_FINISHED
Definition: xmlerror.h:159
@ XML_ERR_DOCUMENT_EMPTY
Definition: xmlerror.h:104
@ XML_ERR_INVALID_DEC_CHARREF
Definition: xmlerror.h:107
@ XML_ERR_LITERAL_NOT_STARTED
Definition: xmlerror.h:143
@ XML_ERR_PUBID_REQUIRED
Definition: xmlerror.h:171
@ XML_ERR_URI_REQUIRED
Definition: xmlerror.h:170
@ XML_ERR_STRING_NOT_STARTED
Definition: xmlerror.h:133
@ XML_ERR_INVALID_HEX_CHARREF
Definition: xmlerror.h:106
@ XML_ERR_VERSION_MISSING
Definition: xmlerror.h:196
@ XML_ERR_EXT_SUBSET_NOT_FINISHED
Definition: xmlerror.h:160
@ XML_ERR_STANDALONE_VALUE
Definition: xmlerror.h:178
@ XML_ERR_EQUAL_REQUIRED
Definition: xmlerror.h:175
@ XML_ERR_ATTLIST_NOT_FINISHED
Definition: xmlerror.h:151
@ XML_ERR_XMLDECL_NOT_STARTED
Definition: xmlerror.h:156
@ XML_ERR_PEREF_SEMICOL_MISSING
Definition: xmlerror.h:125
@ XML_ERR_EXTRA_CONTENT
Definition: xmlerror.h:186
@ XML_ERR_NOTATION_NOT_FINISHED
Definition: xmlerror.h:149
@ XML_ERR_NO_MEMORY
Definition: xmlerror.h:102
@ XML_ERR_UNSUPPORTED_ENCODING
Definition: xmlerror.h:132
@ XML_ERR_NAME_TOO_LONG
Definition: xmlerror.h:210
@ XML_ERR_ENTITY_NOT_STARTED
Definition: xmlerror.h:136
XMLPUBFUN void XMLPUBFUN void XMLPUBFUN void XMLPUBFUN void xmlParserValidityWarning(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
XMLPUBFUN int XMLPUBFUN int XMLPUBFUN int xmlGetUTF8Char(const unsigned char *utf, int *len)
Definition: xmlstring.c:708
XMLPUBFUN int xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:428
XMLPUBFUN int xmlStrcasecmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:277
XMLPUBFUN int xmlStrncmp(const xmlChar *str1, const xmlChar *str2, int len)
Definition: xmlstring.c:215
#define BAD_CAST
Definition: xmlstring.h:35
unsigned char xmlChar
Definition: xmlstring.h:28
XMLPUBFUN xmlChar * xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:69
#define LIBXML_ATTR_FORMAT(fmt, args)
Definition: xmlversion.h:472
#define LIBXML_VERSION
Definition: xmlversion.h:39
#define const
Definition: zconf.h:233