ReactOS 0.4.15-dev-8109-gd7be748
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/valid.h>
28#include <libxml/entities.h>
29#include <libxml/xmlerror.h>
30#include <libxml/encoding.h>
31#include <libxml/valid.h>
32#include <libxml/xmlIO.h>
33#include <libxml/uri.h>
34#include <libxml/dict.h>
35#include <libxml/SAX.h>
36#ifdef LIBXML_CATALOG_ENABLED
37#include <libxml/catalog.h>
38#endif
39#include <libxml/globals.h>
40#include <libxml/chvalid.h>
41
42#define CUR(ctxt) ctxt->input->cur
43#define END(ctxt) ctxt->input->end
44#define VALID_CTXT(ctxt) (CUR(ctxt) <= END(ctxt))
45
46#include "buf.h"
47#include "enc.h"
48
49/*
50 * Various global defaults for parsing
51 */
52
60void
62 int myversion = (int) LIBXML_VERSION;
63
65
66 if ((myversion / 10000) != (version / 10000)) {
68 "Fatal: program compiled against libxml %d using libxml %d\n",
69 (version / 10000), (myversion / 10000));
71 "Fatal: program compiled against libxml %d using libxml %d\n",
72 (version / 10000), (myversion / 10000));
73 }
74 if ((myversion / 100) < (version / 100)) {
76 "Warning: program compiled against libxml %d using older %d\n",
77 (version / 100), (myversion / 100));
78 }
79}
80
81
82/************************************************************************
83 * *
84 * Some factorized error routines *
85 * *
86 ************************************************************************/
87
88
96void
98{
99 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
100 (ctxt->instate == XML_PARSER_EOF))
101 return;
102 if (ctxt != NULL) {
103 ctxt->errNo = XML_ERR_NO_MEMORY;
104 ctxt->instate = XML_PARSER_EOF;
105 ctxt->disableSAX = 1;
106 }
107 if (extra)
108 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
110 NULL, NULL, 0, 0,
111 "Memory allocation failed : %s\n", extra);
112 else
113 __xmlRaiseError(NULL, NULL, NULL, ctxt, NULL, XML_FROM_PARSER,
115 NULL, NULL, 0, 0, "Memory allocation failed\n");
116}
117
128void
130 const char *msg, const xmlChar * str1, const xmlChar * str2)
131{
132 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
133 (ctxt->instate == XML_PARSER_EOF))
134 return;
135 if (ctxt != NULL)
136 ctxt->errNo = xmlerr;
137 __xmlRaiseError(NULL, NULL, NULL,
138 ctxt, NULL, XML_FROM_PARSER, xmlerr, XML_ERR_FATAL,
139 NULL, 0, (const char *) str1, (const char *) str2,
140 NULL, 0, 0, msg, str1, str2);
141 if (ctxt != NULL) {
142 ctxt->wellFormed = 0;
143 if (ctxt->recovery == 0)
144 ctxt->disableSAX = 1;
145 }
146}
147
156static void LIBXML_ATTR_FORMAT(2,0)
157xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str)
158{
159 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
160 (ctxt->instate == XML_PARSER_EOF))
161 return;
162 if (ctxt != NULL)
163 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
164 __xmlRaiseError(NULL, NULL, NULL,
166 XML_ERR_FATAL, NULL, 0, (const char *) str, NULL, NULL,
167 0, 0, msg, str);
168 if (ctxt != NULL) {
169 ctxt->wellFormed = 0;
170 if (ctxt->recovery == 0)
171 ctxt->disableSAX = 1;
172 }
173}
174
184static void LIBXML_ATTR_FORMAT(3,0)
185xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error,
186 const char *msg, int val)
187{
188 if ((ctxt != NULL) && (ctxt->disableSAX != 0) &&
189 (ctxt->instate == XML_PARSER_EOF))
190 return;
191 if (ctxt != NULL)
192 ctxt->errNo = error;
193 __xmlRaiseError(NULL, NULL, NULL,
195 NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
196 if (ctxt != NULL) {
197 ctxt->wellFormed = 0;
198 if (ctxt->recovery == 0)
199 ctxt->disableSAX = 1;
200 }
201}
202
212int
214 return(IS_BASECHAR(c) || IS_IDEOGRAPHIC(c));
215}
216
217/************************************************************************
218 * *
219 * Input handling functions for progressive parsing *
220 * *
221 ************************************************************************/
222
223/* #define DEBUG_INPUT */
224/* #define DEBUG_STACK */
225/* #define DEBUG_PUSH */
226
227
228/* we need to keep enough input to show errors in context */
229#define LINE_LEN 80
230
231#ifdef DEBUG_INPUT
232#define CHECK_BUFFER(in) check_buffer(in)
233
234static
236 if (in->base != xmlBufContent(in->buf->buffer)) {
238 "xmlParserInput: base mismatch problem\n");
239 }
240 if (in->cur < in->base) {
242 "xmlParserInput: cur < base problem\n");
243 }
244 if (in->cur > in->base + xmlBufUse(in->buf->buffer)) {
246 "xmlParserInput: cur > base + use problem\n");
247 }
248 xmlGenericError(xmlGenericErrorContext,"buffer %x : content %x, cur %d, use %d\n",
249 (int) in, (int) xmlBufContent(in->buf->buffer), in->cur - in->base,
250 xmlBufUse(in->buf->buffer));
251}
252
253#else
254#define CHECK_BUFFER(in)
255#endif
256
257
267int
269 return(-1);
270}
271
283int
285 int ret;
286 size_t indx;
287
288 if ((in == NULL) || (len < 0)) return(-1);
289#ifdef DEBUG_INPUT
291#endif
292 if (in->buf == NULL) return(-1);
293 if (in->base == NULL) return(-1);
294 if (in->cur == NULL) return(-1);
295 if (in->buf->buffer == NULL) return(-1);
296
298
299 indx = in->cur - in->base;
300 if (xmlBufUse(in->buf->buffer) > (unsigned int) indx + INPUT_CHUNK) {
301
303
304 return(0);
305 }
306 if (in->buf->readcallback != NULL) {
308 } else
309 return(0);
310
311 in->base = xmlBufContent(in->buf->buffer);
312 in->cur = in->base + indx;
313 in->end = xmlBufEnd(in->buf->buffer);
314
316
317 return(ret);
318}
319
326void
328 size_t used;
329 size_t ret;
330
331#ifdef DEBUG_INPUT
333#endif
334 if (in == NULL) return;
335 if (in->buf == NULL) return;
336 if (in->base == NULL) return;
337 if (in->cur == NULL) return;
338 if (in->buf->buffer == NULL) return;
339
341
342 used = in->cur - in->base;
343 /*
344 * Do not shrink on large buffers whose only a tiny fraction
345 * was consumed
346 */
347 if (used > INPUT_CHUNK) {
348 ret = xmlBufShrink(in->buf->buffer, used - LINE_LEN);
349 if (ret > 0) {
350 used -= ret;
351 in->consumed += ret;
352 }
353 }
354
355 if (xmlBufUse(in->buf->buffer) <= INPUT_CHUNK) {
357 }
358
359 in->base = xmlBufContent(in->buf->buffer);
360 in->cur = in->base + used;
361 in->end = xmlBufEnd(in->buf->buffer);
362
364}
365
366/************************************************************************
367 * *
368 * UTF8 character input and related functions *
369 * *
370 ************************************************************************/
371
379void
381{
382 if ((ctxt == NULL) || (ctxt->instate == XML_PARSER_EOF) ||
383 (ctxt->input == NULL))
384 return;
385
386 if (!(VALID_CTXT(ctxt))) {
387 xmlErrInternal(ctxt, "Parser input data memory error\n", NULL);
389 xmlStopParser(ctxt);
390 return;
391 }
392
393 if ((*ctxt->input->cur == 0) &&
394 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
395 return;
396 }
397
398 if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
399 const unsigned char *cur;
400 unsigned char c;
401
402 /*
403 * 2.11 End-of-Line Handling
404 * the literal two-character sequence "#xD#xA" or a standalone
405 * literal #xD, an XML processor must pass to the application
406 * the single character #xA.
407 */
408 if (*(ctxt->input->cur) == '\n') {
409 ctxt->input->line++; ctxt->input->col = 1;
410 } else
411 ctxt->input->col++;
412
413 /*
414 * We are supposed to handle UTF8, check it's valid
415 * From rfc2044: encoding of the Unicode values on UTF-8:
416 *
417 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
418 * 0000 0000-0000 007F 0xxxxxxx
419 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
420 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
421 *
422 * Check for the 0x110000 limit too
423 */
424 cur = ctxt->input->cur;
425
426 c = *cur;
427 if (c & 0x80) {
428 if (c == 0xC0)
429 goto encoding_error;
430 if (cur[1] == 0) {
432 cur = ctxt->input->cur;
433 }
434 if ((cur[1] & 0xc0) != 0x80)
435 goto encoding_error;
436 if ((c & 0xe0) == 0xe0) {
437 unsigned int val;
438
439 if (cur[2] == 0) {
441 cur = ctxt->input->cur;
442 }
443 if ((cur[2] & 0xc0) != 0x80)
444 goto encoding_error;
445 if ((c & 0xf0) == 0xf0) {
446 if (cur[3] == 0) {
448 cur = ctxt->input->cur;
449 }
450 if (((c & 0xf8) != 0xf0) ||
451 ((cur[3] & 0xc0) != 0x80))
452 goto encoding_error;
453 /* 4-byte code */
454 ctxt->input->cur += 4;
455 val = (cur[0] & 0x7) << 18;
456 val |= (cur[1] & 0x3f) << 12;
457 val |= (cur[2] & 0x3f) << 6;
458 val |= cur[3] & 0x3f;
459 } else {
460 /* 3-byte code */
461 ctxt->input->cur += 3;
462 val = (cur[0] & 0xf) << 12;
463 val |= (cur[1] & 0x3f) << 6;
464 val |= cur[2] & 0x3f;
465 }
466 if (((val > 0xd7ff) && (val < 0xe000)) ||
467 ((val > 0xfffd) && (val < 0x10000)) ||
468 (val >= 0x110000)) {
469 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
470 "Char 0x%X out of allowed range\n",
471 val);
472 }
473 } else
474 /* 2-byte code */
475 ctxt->input->cur += 2;
476 } else
477 /* 1-byte code */
478 ctxt->input->cur++;
479 } else {
480 /*
481 * Assume it's a fixed length encoding (1) with
482 * a compatible encoding for the ASCII set, since
483 * XML constructs only use < 128 chars
484 */
485
486 if (*(ctxt->input->cur) == '\n') {
487 ctxt->input->line++; ctxt->input->col = 1;
488 } else
489 ctxt->input->col++;
490 ctxt->input->cur++;
491 }
492 if (*ctxt->input->cur == 0)
494 return;
495encoding_error:
496 /*
497 * If we detect an UTF8 error that probably mean that the
498 * input encoding didn't get properly advertised in the
499 * declaration header. Report the error and switch the encoding
500 * to ISO-Latin-1 (if you don't like this policy, just declare the
501 * encoding !)
502 */
503 if ((ctxt == NULL) || (ctxt->input == NULL) ||
504 (ctxt->input->end - ctxt->input->cur < 4)) {
506 "Input is not proper UTF-8, indicate encoding !\n",
507 NULL, NULL);
508 } else {
509 char buffer[150];
510
511 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
512 ctxt->input->cur[0], ctxt->input->cur[1],
513 ctxt->input->cur[2], ctxt->input->cur[3]);
515 "Input is not proper UTF-8, indicate encoding !\n%s",
517 }
519 ctxt->input->cur++;
520 return;
521}
522
541int
543 if ((ctxt == NULL) || (len == NULL) || (ctxt->input == NULL)) return(0);
544 if (ctxt->instate == XML_PARSER_EOF)
545 return(0);
546
547 if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
548 *len = 1;
549 return((int) *ctxt->input->cur);
550 }
551 if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
552 /*
553 * We are supposed to handle UTF8, check it's valid
554 * From rfc2044: encoding of the Unicode values on UTF-8:
555 *
556 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
557 * 0000 0000-0000 007F 0xxxxxxx
558 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
559 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
560 *
561 * Check for the 0x110000 limit too
562 */
563 const unsigned char *cur = ctxt->input->cur;
564 unsigned char c;
565 unsigned int val;
566
567 c = *cur;
568 if (c & 0x80) {
569 if (((c & 0x40) == 0) || (c == 0xC0))
570 goto encoding_error;
571 if (cur[1] == 0) {
573 cur = ctxt->input->cur;
574 }
575 if ((cur[1] & 0xc0) != 0x80)
576 goto encoding_error;
577 if ((c & 0xe0) == 0xe0) {
578 if (cur[2] == 0) {
580 cur = ctxt->input->cur;
581 }
582 if ((cur[2] & 0xc0) != 0x80)
583 goto encoding_error;
584 if ((c & 0xf0) == 0xf0) {
585 if (cur[3] == 0) {
587 cur = ctxt->input->cur;
588 }
589 if (((c & 0xf8) != 0xf0) ||
590 ((cur[3] & 0xc0) != 0x80))
591 goto encoding_error;
592 /* 4-byte code */
593 *len = 4;
594 val = (cur[0] & 0x7) << 18;
595 val |= (cur[1] & 0x3f) << 12;
596 val |= (cur[2] & 0x3f) << 6;
597 val |= cur[3] & 0x3f;
598 if (val < 0x10000)
599 goto encoding_error;
600 } else {
601 /* 3-byte code */
602 *len = 3;
603 val = (cur[0] & 0xf) << 12;
604 val |= (cur[1] & 0x3f) << 6;
605 val |= cur[2] & 0x3f;
606 if (val < 0x800)
607 goto encoding_error;
608 }
609 } else {
610 /* 2-byte code */
611 *len = 2;
612 val = (cur[0] & 0x1f) << 6;
613 val |= cur[1] & 0x3f;
614 if (val < 0x80)
615 goto encoding_error;
616 }
617 if (!IS_CHAR(val)) {
618 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
619 "Char 0x%X out of allowed range\n", val);
620 }
621 return(val);
622 } else {
623 /* 1-byte code */
624 *len = 1;
625 if (*ctxt->input->cur == 0)
627 if ((*ctxt->input->cur == 0) &&
628 (ctxt->input->end > ctxt->input->cur)) {
629 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
630 "Char 0x0 out of allowed range\n", 0);
631 }
632 if (*ctxt->input->cur == 0xD) {
633 if (ctxt->input->cur[1] == 0xA) {
634 ctxt->input->cur++;
635 }
636 return(0xA);
637 }
638 return((int) *ctxt->input->cur);
639 }
640 }
641 /*
642 * Assume it's a fixed length encoding (1) with
643 * a compatible encoding for the ASCII set, since
644 * XML constructs only use < 128 chars
645 */
646 *len = 1;
647 if (*ctxt->input->cur == 0xD) {
648 if (ctxt->input->cur[1] == 0xA) {
649 ctxt->input->cur++;
650 }
651 return(0xA);
652 }
653 return((int) *ctxt->input->cur);
654encoding_error:
655 /*
656 * An encoding problem may arise from a truncated input buffer
657 * splitting a character in the middle. In that case do not raise
658 * an error but return 0 to indicate an end of stream problem
659 */
660 if (ctxt->input->end - ctxt->input->cur < 4) {
661 *len = 0;
662 return(0);
663 }
664
665 /*
666 * If we detect an UTF8 error that probably mean that the
667 * input encoding didn't get properly advertised in the
668 * declaration header. Report the error and switch the encoding
669 * to ISO-Latin-1 (if you don't like this policy, just declare the
670 * encoding !)
671 */
672 {
673 char buffer[150];
674
675 snprintf(&buffer[0], 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
676 ctxt->input->cur[0], ctxt->input->cur[1],
677 ctxt->input->cur[2], ctxt->input->cur[3]);
679 "Input is not proper UTF-8, indicate encoding !\n%s",
681 }
683 *len = 1;
684 return((int) *ctxt->input->cur);
685}
686
699int
701{
702 if ((len == NULL) || (cur == NULL)) return(0);
703 if ((ctxt == NULL) || (ctxt->charset == XML_CHAR_ENCODING_UTF8)) {
704 /*
705 * We are supposed to handle UTF8, check it's valid
706 * From rfc2044: encoding of the Unicode values on UTF-8:
707 *
708 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
709 * 0000 0000-0000 007F 0xxxxxxx
710 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
711 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
712 *
713 * Check for the 0x110000 limit too
714 */
715 unsigned char c;
716 unsigned int val;
717
718 c = *cur;
719 if (c & 0x80) {
720 if ((cur[1] & 0xc0) != 0x80)
721 goto encoding_error;
722 if ((c & 0xe0) == 0xe0) {
723
724 if ((cur[2] & 0xc0) != 0x80)
725 goto encoding_error;
726 if ((c & 0xf0) == 0xf0) {
727 if (((c & 0xf8) != 0xf0) || ((cur[3] & 0xc0) != 0x80))
728 goto encoding_error;
729 /* 4-byte code */
730 *len = 4;
731 val = (cur[0] & 0x7) << 18;
732 val |= (cur[1] & 0x3f) << 12;
733 val |= (cur[2] & 0x3f) << 6;
734 val |= cur[3] & 0x3f;
735 } else {
736 /* 3-byte code */
737 *len = 3;
738 val = (cur[0] & 0xf) << 12;
739 val |= (cur[1] & 0x3f) << 6;
740 val |= cur[2] & 0x3f;
741 }
742 } else {
743 /* 2-byte code */
744 *len = 2;
745 val = (cur[0] & 0x1f) << 6;
746 val |= cur[1] & 0x3f;
747 }
748 if (!IS_CHAR(val)) {
749 xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR,
750 "Char 0x%X out of allowed range\n", val);
751 }
752 return (val);
753 } else {
754 /* 1-byte code */
755 *len = 1;
756 return ((int) *cur);
757 }
758 }
759 /*
760 * Assume it's a fixed length encoding (1) with
761 * a compatible encoding for the ASCII set, since
762 * XML constructs only use < 128 chars
763 */
764 *len = 1;
765 return ((int) *cur);
766encoding_error:
767
768 /*
769 * An encoding problem may arise from a truncated input buffer
770 * splitting a character in the middle. In that case do not raise
771 * an error but return 0 to indicate an end of stream problem
772 */
773 if ((ctxt == NULL) || (ctxt->input == NULL) ||
774 (ctxt->input->end - ctxt->input->cur < 4)) {
775 *len = 0;
776 return(0);
777 }
778 /*
779 * If we detect an UTF8 error that probably mean that the
780 * input encoding didn't get properly advertised in the
781 * declaration header. Report the error and switch the encoding
782 * to ISO-Latin-1 (if you don't like this policy, just declare the
783 * encoding !)
784 */
785 {
786 char buffer[150];
787
788 snprintf(buffer, 149, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
789 ctxt->input->cur[0], ctxt->input->cur[1],
790 ctxt->input->cur[2], ctxt->input->cur[3]);
792 "Input is not proper UTF-8, indicate encoding !\n%s",
794 }
795 *len = 1;
796 return ((int) *cur);
797}
798
808int
810 if (out == NULL) return(0);
811 /*
812 * We are supposed to handle UTF8, check it's valid
813 * From rfc2044: encoding of the Unicode values on UTF-8:
814 *
815 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
816 * 0000 0000-0000 007F 0xxxxxxx
817 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
818 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
819 */
820 if (val >= 0x80) {
821 xmlChar *savedout = out;
822 int bits;
823 if (val < 0x800) { *out++= (val >> 6) | 0xC0; bits= 0; }
824 else if (val < 0x10000) { *out++= (val >> 12) | 0xE0; bits= 6;}
825 else if (val < 0x110000) { *out++= (val >> 18) | 0xF0; bits= 12; }
826 else {
827 xmlErrEncodingInt(NULL, XML_ERR_INVALID_CHAR,
828 "Internal error, xmlCopyCharMultiByte 0x%X out of bound\n",
829 val);
830 return(0);
831 }
832 for ( ; bits >= 0; bits-= 6)
833 *out++= ((val >> bits) & 0x3F) | 0x80 ;
834 return (out - savedout);
835 }
836 *out = (xmlChar) val;
837 return 1;
838}
839
851int
853 if (out == NULL) return(0);
854 /* the len parameter is ignored */
855 if (val >= 0x80) {
856 return(xmlCopyCharMultiByte (out, val));
857 }
858 *out = (xmlChar) val;
859 return 1;
860}
861
862/************************************************************************
863 * *
864 * Commodity functions to switch encodings *
865 * *
866 ************************************************************************/
867
868static int
881int
883{
885 int len = -1;
886 int ret;
887
888 if (ctxt == NULL) return(-1);
889 switch (enc) {
892 "encoding unknown\n", NULL, NULL);
893 return(-1);
895 /* let's assume it's UTF-8 without the XML decl */
897 return(0);
899 /* default encoding, no conversion should be needed */
901
902 /*
903 * Errata on XML-1.0 June 20 2001
904 * Specific handling of the Byte Order Mark for
905 * UTF-8
906 */
907 if ((ctxt->input != NULL) &&
908 (ctxt->input->cur[0] == 0xEF) &&
909 (ctxt->input->cur[1] == 0xBB) &&
910 (ctxt->input->cur[2] == 0xBF)) {
911 ctxt->input->cur += 3;
912 }
913 return(0);
916 /*The raw input characters are encoded
917 *in UTF-16. As we expect this function
918 *to be called after xmlCharEncInFunc, we expect
919 *ctxt->input->cur to contain UTF-8 encoded characters.
920 *So the raw UTF16 Byte Order Mark
921 *has also been converted into
922 *an UTF-8 BOM. Let's skip that BOM.
923 */
924 if ((ctxt->input != NULL) && (ctxt->input->cur != NULL) &&
925 (ctxt->input->cur[0] == 0xEF) &&
926 (ctxt->input->cur[1] == 0xBB) &&
927 (ctxt->input->cur[2] == 0xBF)) {
928 ctxt->input->cur += 3;
929 }
930 len = 90;
931 break;
933 len = 90;
934 break;
939 len = 180;
940 break;
955 len = 45;
956 break;
957 }
959 if (handler == NULL) {
960 /*
961 * Default handlers.
962 */
963 switch (enc) {
965 /* default encoding, no conversion should be needed */
967 return(0);
969 if ((ctxt->inputNr == 1) &&
970 (ctxt->encoding == NULL) &&
971 (ctxt->input != NULL) &&
972 (ctxt->input->encoding != NULL)) {
973 ctxt->encoding = xmlStrdup(ctxt->input->encoding);
974 }
975 ctxt->charset = enc;
976 return(0);
977 default:
979 "encoding not supported: %s\n",
981 /*
982 * TODO: We could recover from errors in external entities
983 * if we didn't stop the parser. But most callers of this
984 * function don't check the return value.
985 */
986 xmlStopParser(ctxt);
987 return(-1);
988 }
989 }
991 if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) {
992 /*
993 * on encoding conversion errors, stop the parser
994 */
995 xmlStopParser(ctxt);
997 }
998 return(ret);
999}
1000
1013static int
1016{
1017 int nbchars;
1018
1019 if (handler == NULL)
1020 return (-1);
1021 if (input == NULL)
1022 return (-1);
1023 if (input->buf != NULL) {
1025
1026 if (input->buf->encoder != NULL) {
1027 /*
1028 * Check in case the auto encoding detection triggered
1029 * in already.
1030 */
1031 if (input->buf->encoder == handler)
1032 return (0);
1033
1034 /*
1035 * "UTF-16" can be used for both LE and BE
1036 if ((!xmlStrncmp(BAD_CAST input->buf->encoder->name,
1037 BAD_CAST "UTF-16", 6)) &&
1038 (!xmlStrncmp(BAD_CAST handler->name,
1039 BAD_CAST "UTF-16", 6))) {
1040 return(0);
1041 }
1042 */
1043
1044 /*
1045 * Note: this is a bit dangerous, but that's what it
1046 * takes to use nearly compatible signature for different
1047 * encodings.
1048 *
1049 * FIXME: Encoders might buffer partial byte sequences, so
1050 * this probably can't work. We should return an error and
1051 * make sure that callers never try to switch the encoding
1052 * twice.
1053 */
1054 xmlCharEncCloseFunc(input->buf->encoder);
1055 input->buf->encoder = handler;
1056 return (0);
1057 }
1058 input->buf->encoder = handler;
1059
1060 /*
1061 * Is there already some content down the pipe to convert ?
1062 */
1063 if (xmlBufIsEmpty(input->buf->buffer) == 0) {
1064 int processed;
1065 unsigned int use;
1066
1067 /*
1068 * Specific handling of the Byte Order Mark for
1069 * UTF-16
1070 */
1071 if ((handler->name != NULL) &&
1072 (!strcmp(handler->name, "UTF-16LE") ||
1073 !strcmp(handler->name, "UTF-16")) &&
1074 (input->cur[0] == 0xFF) && (input->cur[1] == 0xFE)) {
1075 input->cur += 2;
1076 }
1077 if ((handler->name != NULL) &&
1078 (!strcmp(handler->name, "UTF-16BE")) &&
1079 (input->cur[0] == 0xFE) && (input->cur[1] == 0xFF)) {
1080 input->cur += 2;
1081 }
1082 /*
1083 * Errata on XML-1.0 June 20 2001
1084 * Specific handling of the Byte Order Mark for
1085 * UTF-8
1086 */
1087 if ((handler->name != NULL) &&
1088 (!strcmp(handler->name, "UTF-8")) &&
1089 (input->cur[0] == 0xEF) &&
1090 (input->cur[1] == 0xBB) && (input->cur[2] == 0xBF)) {
1091 input->cur += 3;
1092 }
1093
1094 /*
1095 * Shrink the current input buffer.
1096 * Move it as the raw buffer and create a new input buffer
1097 */
1098 processed = input->cur - input->base;
1099 xmlBufShrink(input->buf->buffer, processed);
1100 input->buf->raw = input->buf->buffer;
1101 input->buf->buffer = xmlBufCreate();
1102 input->buf->rawconsumed = processed;
1103 use = xmlBufUse(input->buf->raw);
1104
1105 if (ctxt->html) {
1106 /*
1107 * convert as much as possible of the buffer
1108 */
1109 nbchars = xmlCharEncInput(input->buf, 1);
1110 } else {
1111 /*
1112 * convert just enough to get
1113 * '<?xml version="1.0" encoding="xxx"?>'
1114 * parsed with the autodetected encoding
1115 * into the parser reading buffer.
1116 */
1117 nbchars = xmlCharEncFirstLineInput(input->buf, len);
1118 }
1119 xmlBufResetInput(input->buf->buffer, input);
1120 if (nbchars < 0) {
1121 xmlErrInternal(ctxt,
1122 "switching encoding: encoder error\n",
1123 NULL);
1124 return (-1);
1125 }
1126 input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
1127 }
1128 return (0);
1129 } else {
1130 xmlErrInternal(ctxt,
1131 "static memory buffer doesn't support encoding\n", NULL);
1132 /*
1133 * Callers assume that the input buffer takes ownership of the
1134 * encoding handler. xmlCharEncCloseFunc frees unregistered
1135 * handlers and avoids a memory leak.
1136 */
1138 return (-1);
1139 }
1140}
1141
1155int
1158 return(xmlSwitchInputEncodingInt(ctxt, input, handler, -1));
1159}
1160
1171int
1173{
1174 if (ctxt == NULL)
1175 return(-1);
1176 return(xmlSwitchInputEncodingInt(ctxt, ctxt->input, handler, -1));
1177}
1178
1179/************************************************************************
1180 * *
1181 * Commodity functions to handle entities processing *
1182 * *
1183 ************************************************************************/
1184
1191void
1193 if (input == NULL) return;
1194
1195 if (input->filename != NULL) xmlFree((char *) input->filename);
1196 if (input->directory != NULL) xmlFree((char *) input->directory);
1197 if (input->encoding != NULL) xmlFree((char *) input->encoding);
1198 if (input->version != NULL) xmlFree((char *) input->version);
1199 if ((input->free != NULL) && (input->base != NULL))
1200 input->free((xmlChar *) input->base);
1201 if (input->buf != NULL)
1203 xmlFree(input);
1204}
1205
1217
1219 if (input == NULL) {
1220 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1221 return(NULL);
1222 }
1223 memset(input, 0, sizeof(xmlParserInput));
1224 input->line = 1;
1225 input->col = 1;
1226 input->standalone = -1;
1227
1228 /*
1229 * If the context is NULL the id cannot be initialized, but that
1230 * should not happen while parsing which is the situation where
1231 * the id is actually needed.
1232 */
1233 if (ctxt != NULL)
1234 input->id = ctxt->input_id++;
1235
1236 return(input);
1237}
1238
1252 xmlCharEncoding enc) {
1253 xmlParserInputPtr inputStream;
1254
1255 if (input == NULL) return(NULL);
1257 xmlGenericError(xmlGenericErrorContext, "new input from I/O\n");
1258 inputStream = xmlNewInputStream(ctxt);
1259 if (inputStream == NULL) {
1260 return(NULL);
1261 }
1262 inputStream->filename = NULL;
1263 inputStream->buf = input;
1264 xmlBufResetInput(inputStream->buf->buffer, inputStream);
1265
1266 if (enc != XML_CHAR_ENCODING_NONE) {
1267 xmlSwitchEncoding(ctxt, enc);
1268 }
1269
1270 return(inputStream);
1271}
1272
1285
1286 if (entity == NULL) {
1287 xmlErrInternal(ctxt, "xmlNewEntityInputStream entity = NULL\n",
1288 NULL);
1289 return(NULL);
1290 }
1293 "new input from entity: %s\n", entity->name);
1294 if (entity->content == NULL) {
1295 switch (entity->etype) {
1297 xmlErrInternal(ctxt, "Cannot parse entity %s\n",
1298 entity->name);
1299 break;
1302 return(xmlLoadExternalEntity((char *) entity->URI,
1303 (char *) entity->ExternalID, ctxt));
1305 xmlErrInternal(ctxt,
1306 "Internal entity %s without content !\n",
1307 entity->name);
1308 break;
1310 xmlErrInternal(ctxt,
1311 "Internal parameter entity %s without content !\n",
1312 entity->name);
1313 break;
1315 xmlErrInternal(ctxt,
1316 "Predefined entity %s without content !\n",
1317 entity->name);
1318 break;
1319 }
1320 return(NULL);
1321 }
1322 input = xmlNewInputStream(ctxt);
1323 if (input == NULL) {
1324 return(NULL);
1325 }
1326 if (entity->URI != NULL)
1327 input->filename = (char *) xmlStrdup((xmlChar *) entity->URI);
1328 input->base = entity->content;
1329 if (entity->length == 0)
1330 entity->length = xmlStrlen(entity->content);
1331 input->cur = entity->content;
1332 input->length = entity->length;
1333 input->end = &entity->content[input->length];
1334 return(input);
1335}
1336
1348
1349 if (buffer == NULL) {
1350 xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
1351 NULL);
1352 return(NULL);
1353 }
1356 "new fixed input: %.30s\n", buffer);
1357 input = xmlNewInputStream(ctxt);
1358 if (input == NULL) {
1359 xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
1360 return(NULL);
1361 }
1362 input->base = buffer;
1363 input->cur = buffer;
1364 input->length = xmlStrlen(buffer);
1365 input->end = &buffer[input->length];
1366 return(input);
1367}
1368
1381 xmlParserInputPtr inputStream;
1382 char *directory = NULL;
1383 xmlChar *URI = NULL;
1384
1387 "new input from file: %s\n", filename);
1388 if (ctxt == NULL) return(NULL);
1390 if (buf == NULL) {
1391 if (filename == NULL)
1392 __xmlLoaderErr(ctxt,
1393 "failed to load external entity: NULL filename \n",
1394 NULL);
1395 else
1396 __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n",
1397 (const char *) filename);
1398 return(NULL);
1399 }
1400
1401 inputStream = xmlNewInputStream(ctxt);
1402 if (inputStream == NULL) {
1404 return(NULL);
1405 }
1406
1407 inputStream->buf = buf;
1408 inputStream = xmlCheckHTTPInput(ctxt, inputStream);
1409 if (inputStream == NULL)
1410 return(NULL);
1411
1412 if (inputStream->filename == NULL)
1413 URI = xmlStrdup((xmlChar *) filename);
1414 else
1415 URI = xmlStrdup((xmlChar *) inputStream->filename);
1416 directory = xmlParserGetDirectory((const char *) URI);
1417 if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename);
1418 inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI);
1419 if (URI != NULL) xmlFree((char *) URI);
1420 inputStream->directory = directory;
1421
1422 xmlBufResetInput(inputStream->buf->buffer, inputStream);
1423 if ((ctxt->directory == NULL) && (directory != NULL))
1424 ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
1425 return(inputStream);
1426}
1427
1428/************************************************************************
1429 * *
1430 * Commodity functions to handle parser contexts *
1431 * *
1432 ************************************************************************/
1433
1443int
1445{
1447
1448 if(ctxt==NULL) {
1449 xmlErrInternal(NULL, "Got NULL parser context\n", NULL);
1450 return(-1);
1451 }
1452
1453 xmlInitParser();
1454
1455 if (ctxt->dict == NULL)
1456 ctxt->dict = xmlDictCreate();
1457 if (ctxt->dict == NULL) {
1458 xmlErrMemory(NULL, "cannot initialize parser context\n");
1459 return(-1);
1460 }
1462
1463 if (ctxt->sax == NULL)
1464 ctxt->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
1465 if (ctxt->sax == NULL) {
1466 xmlErrMemory(NULL, "cannot initialize parser context\n");
1467 return(-1);
1468 }
1469 else
1470 xmlSAXVersion(ctxt->sax, 2);
1471
1472 ctxt->maxatts = 0;
1473 ctxt->atts = NULL;
1474 /* Allocate the Input stack */
1475 if (ctxt->inputTab == NULL) {
1476 ctxt->inputTab = (xmlParserInputPtr *)
1477 xmlMalloc(5 * sizeof(xmlParserInputPtr));
1478 ctxt->inputMax = 5;
1479 }
1480 if (ctxt->inputTab == NULL) {
1481 xmlErrMemory(NULL, "cannot initialize parser context\n");
1482 ctxt->inputNr = 0;
1483 ctxt->inputMax = 0;
1484 ctxt->input = NULL;
1485 return(-1);
1486 }
1487 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1489 }
1490 ctxt->inputNr = 0;
1491 ctxt->input = NULL;
1492
1493 ctxt->version = NULL;
1494 ctxt->encoding = NULL;
1495 ctxt->standalone = -1;
1496 ctxt->hasExternalSubset = 0;
1497 ctxt->hasPErefs = 0;
1498 ctxt->html = 0;
1499 ctxt->external = 0;
1500 ctxt->instate = XML_PARSER_START;
1501 ctxt->token = 0;
1502 ctxt->directory = NULL;
1503
1504 /* Allocate the Node stack */
1505 if (ctxt->nodeTab == NULL) {
1506 ctxt->nodeTab = (xmlNodePtr *) xmlMalloc(10 * sizeof(xmlNodePtr));
1507 ctxt->nodeMax = 10;
1508 }
1509 if (ctxt->nodeTab == NULL) {
1510 xmlErrMemory(NULL, "cannot initialize parser context\n");
1511 ctxt->nodeNr = 0;
1512 ctxt->nodeMax = 0;
1513 ctxt->node = NULL;
1514 ctxt->inputNr = 0;
1515 ctxt->inputMax = 0;
1516 ctxt->input = NULL;
1517 return(-1);
1518 }
1519 ctxt->nodeNr = 0;
1520 ctxt->node = NULL;
1521
1522 /* Allocate the Name stack */
1523 if (ctxt->nameTab == NULL) {
1524 ctxt->nameTab = (const xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
1525 ctxt->nameMax = 10;
1526 }
1527 if (ctxt->nameTab == NULL) {
1528 xmlErrMemory(NULL, "cannot initialize parser context\n");
1529 ctxt->nodeNr = 0;
1530 ctxt->nodeMax = 0;
1531 ctxt->node = NULL;
1532 ctxt->inputNr = 0;
1533 ctxt->inputMax = 0;
1534 ctxt->input = NULL;
1535 ctxt->nameNr = 0;
1536 ctxt->nameMax = 0;
1537 ctxt->name = NULL;
1538 return(-1);
1539 }
1540 ctxt->nameNr = 0;
1541 ctxt->name = NULL;
1542
1543 /* Allocate the space stack */
1544 if (ctxt->spaceTab == NULL) {
1545 ctxt->spaceTab = (int *) xmlMalloc(10 * sizeof(int));
1546 ctxt->spaceMax = 10;
1547 }
1548 if (ctxt->spaceTab == NULL) {
1549 xmlErrMemory(NULL, "cannot initialize parser context\n");
1550 ctxt->nodeNr = 0;
1551 ctxt->nodeMax = 0;
1552 ctxt->node = NULL;
1553 ctxt->inputNr = 0;
1554 ctxt->inputMax = 0;
1555 ctxt->input = NULL;
1556 ctxt->nameNr = 0;
1557 ctxt->nameMax = 0;
1558 ctxt->name = NULL;
1559 ctxt->spaceNr = 0;
1560 ctxt->spaceMax = 0;
1561 ctxt->space = NULL;
1562 return(-1);
1563 }
1564 ctxt->spaceNr = 1;
1565 ctxt->spaceMax = 10;
1566 ctxt->spaceTab[0] = -1;
1567 ctxt->space = &ctxt->spaceTab[0];
1568 ctxt->userData = ctxt;
1569 ctxt->myDoc = NULL;
1570 ctxt->wellFormed = 1;
1571 ctxt->nsWellFormed = 1;
1572 ctxt->valid = 1;
1574 if (ctxt->loadsubset) {
1575 ctxt->options |= XML_PARSE_DTDLOAD;
1576 }
1579 if (ctxt->pedantic) {
1580 ctxt->options |= XML_PARSE_PEDANTIC;
1581 }
1584 if (ctxt->keepBlanks == 0) {
1585 ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
1586 ctxt->options |= XML_PARSE_NOBLANKS;
1587 }
1588
1589 ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
1590 ctxt->vctxt.userData = ctxt;
1591 ctxt->vctxt.error = xmlParserValidityError;
1592 ctxt->vctxt.warning = xmlParserValidityWarning;
1593 if (ctxt->validate) {
1595 ctxt->vctxt.warning = NULL;
1596 else
1597 ctxt->vctxt.warning = xmlParserValidityWarning;
1598 ctxt->vctxt.nodeMax = 0;
1599 ctxt->options |= XML_PARSE_DTDVALID;
1600 }
1602 if (ctxt->replaceEntities) {
1603 ctxt->options |= XML_PARSE_NOENT;
1604 }
1605 ctxt->record_info = 0;
1606 ctxt->checkIndex = 0;
1607 ctxt->inSubset = 0;
1608 ctxt->errNo = XML_ERR_OK;
1609 ctxt->depth = 0;
1611 ctxt->catalogs = NULL;
1612 ctxt->nbentities = 0;
1613 ctxt->sizeentities = 0;
1614 ctxt->sizeentcopy = 0;
1615 ctxt->input_id = 1;
1617 return(0);
1618}
1619
1628void
1630{
1632
1633 if (ctxt == NULL) return;
1634
1635 while ((input = inputPop(ctxt)) != NULL) { /* Non consuming */
1637 }
1638 if (ctxt->spaceTab != NULL) xmlFree(ctxt->spaceTab);
1639 if (ctxt->nameTab != NULL) xmlFree((xmlChar * *)ctxt->nameTab);
1640 if (ctxt->nodeTab != NULL) xmlFree(ctxt->nodeTab);
1641 if (ctxt->nodeInfoTab != NULL) xmlFree(ctxt->nodeInfoTab);
1642 if (ctxt->inputTab != NULL) xmlFree(ctxt->inputTab);
1643 if (ctxt->version != NULL) xmlFree((char *) ctxt->version);
1644 if (ctxt->encoding != NULL) xmlFree((char *) ctxt->encoding);
1645 if (ctxt->extSubURI != NULL) xmlFree((char *) ctxt->extSubURI);
1646 if (ctxt->extSubSystem != NULL) xmlFree((char *) ctxt->extSubSystem);
1647#ifdef LIBXML_SAX1_ENABLED
1648 if ((ctxt->sax != NULL) &&
1650#else
1651 if (ctxt->sax != NULL)
1652#endif /* LIBXML_SAX1_ENABLED */
1653 xmlFree(ctxt->sax);
1654 if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
1655 if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
1656 if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
1657 if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);
1658 if (ctxt->nsTab != NULL) xmlFree((char *) ctxt->nsTab);
1659 if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab);
1660 if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs);
1661 if (ctxt->attsDefault != NULL)
1663 if (ctxt->attsSpecial != NULL)
1665 if (ctxt->freeElems != NULL) {
1667
1668 cur = ctxt->freeElems;
1669 while (cur != NULL) {
1670 next = cur->next;
1671 xmlFree(cur);
1672 cur = next;
1673 }
1674 }
1675 if (ctxt->freeAttrs != NULL) {
1677
1678 cur = ctxt->freeAttrs;
1679 while (cur != NULL) {
1680 next = cur->next;
1681 xmlFree(cur);
1682 cur = next;
1683 }
1684 }
1685 /*
1686 * cleanup the error strings
1687 */
1688 if (ctxt->lastError.message != NULL)
1689 xmlFree(ctxt->lastError.message);
1690 if (ctxt->lastError.file != NULL)
1691 xmlFree(ctxt->lastError.file);
1692 if (ctxt->lastError.str1 != NULL)
1693 xmlFree(ctxt->lastError.str1);
1694 if (ctxt->lastError.str2 != NULL)
1695 xmlFree(ctxt->lastError.str2);
1696 if (ctxt->lastError.str3 != NULL)
1697 xmlFree(ctxt->lastError.str3);
1698
1699#ifdef LIBXML_CATALOG_ENABLED
1700 if (ctxt->catalogs != NULL)
1701 xmlCatalogFreeLocal(ctxt->catalogs);
1702#endif
1703 xmlFree(ctxt);
1704}
1705
1716{
1717 xmlParserCtxtPtr ctxt;
1718
1719 ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
1720 if (ctxt == NULL) {
1721 xmlErrMemory(NULL, "cannot allocate parser context\n");
1722 return(NULL);
1723 }
1724 memset(ctxt, 0, sizeof(xmlParserCtxt));
1725 if (xmlInitParserCtxt(ctxt) < 0) {
1726 xmlFreeParserCtxt(ctxt);
1727 return(NULL);
1728 }
1729 return(ctxt);
1730}
1731
1732/************************************************************************
1733 * *
1734 * Handling of node information *
1735 * *
1736 ************************************************************************/
1737
1745void
1747{
1748 if (ctxt==NULL)
1749 return;
1751 xmlCtxtReset(ctxt);
1752}
1753
1754
1764const xmlParserNodeInfo *
1766{
1767 unsigned long pos;
1768
1769 if ((ctx == NULL) || (node == NULL))
1770 return (NULL);
1771 /* Find position where node should be at */
1772 pos = xmlParserFindNodeInfoIndex(&ctx->node_seq, node);
1773 if (pos < ctx->node_seq.length
1774 && ctx->node_seq.buffer[pos].node == node)
1775 return &ctx->node_seq.buffer[pos];
1776 else
1777 return NULL;
1778}
1779
1780
1787void
1789{
1790 if (seq == NULL)
1791 return;
1792 seq->length = 0;
1793 seq->maximum = 0;
1794 seq->buffer = NULL;
1795}
1796
1804void
1806{
1807 if (seq == NULL)
1808 return;
1809 if (seq->buffer != NULL)
1810 xmlFree(seq->buffer);
1811 xmlInitNodeInfoSeq(seq);
1812}
1813
1825unsigned long
1827 const xmlNodePtr node)
1828{
1829 unsigned long upper, lower, middle;
1830 int found = 0;
1831
1832 if ((seq == NULL) || (node == NULL))
1833 return ((unsigned long) -1);
1834
1835 /* Do a binary search for the key */
1836 lower = 1;
1837 upper = seq->length;
1838 middle = 0;
1839 while (lower <= upper && !found) {
1840 middle = lower + (upper - lower) / 2;
1841 if (node == seq->buffer[middle - 1].node)
1842 found = 1;
1843 else if (node < seq->buffer[middle - 1].node)
1844 upper = middle - 1;
1845 else
1846 lower = middle + 1;
1847 }
1848
1849 /* Return position */
1850 if (middle == 0 || seq->buffer[middle - 1].node < node)
1851 return middle;
1852 else
1853 return middle - 1;
1854}
1855
1856
1864void
1867{
1868 unsigned long pos;
1869
1870 if ((ctxt == NULL) || (info == NULL)) return;
1871
1872 /* Find pos and check to see if node is already in the sequence */
1874 info->node);
1875
1876 if ((pos < ctxt->node_seq.length) &&
1877 (ctxt->node_seq.buffer != NULL) &&
1878 (ctxt->node_seq.buffer[pos].node == info->node)) {
1879 ctxt->node_seq.buffer[pos] = *info;
1880 }
1881
1882 /* Otherwise, we need to add new node to buffer */
1883 else {
1884 if ((ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) ||
1885 (ctxt->node_seq.buffer == NULL)) {
1886 xmlParserNodeInfo *tmp_buffer;
1887 unsigned int byte_size;
1888
1889 if (ctxt->node_seq.maximum == 0)
1890 ctxt->node_seq.maximum = 2;
1891 byte_size = (sizeof(*ctxt->node_seq.buffer) *
1892 (2 * ctxt->node_seq.maximum));
1893
1894 if (ctxt->node_seq.buffer == NULL)
1895 tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);
1896 else
1897 tmp_buffer =
1899 byte_size);
1900
1901 if (tmp_buffer == NULL) {
1902 xmlErrMemory(ctxt, "failed to allocate buffer\n");
1903 return;
1904 }
1905 ctxt->node_seq.buffer = tmp_buffer;
1906 ctxt->node_seq.maximum *= 2;
1907 }
1908
1909 /* If position is not at end, move elements out of the way */
1910 if (pos != ctxt->node_seq.length) {
1911 unsigned long i;
1912
1913 for (i = ctxt->node_seq.length; i > pos; i--)
1914 ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
1915 }
1916
1917 /* Copy element and increase length */
1918 ctxt->node_seq.buffer[pos] = *info;
1919 ctxt->node_seq.length++;
1920 }
1921}
1922
1923/************************************************************************
1924 * *
1925 * Defaults settings *
1926 * *
1927 ************************************************************************/
1937int
1940
1942 return(old);
1943}
1944
1955int
1958
1960 return(old);
1961}
1962
1977int
1980
1982 return(old);
1983}
1984
2009int
2011 int old = xmlKeepBlanksDefaultValue;
2012
2014 if (!val) xmlIndentTreeOutput = 1;
2015 return(old);
2016}
2017
XMLPUBFUN void XMLCALL xmlSAX2IgnorableWhitespace(void *ctx, const xmlChar *ch, int len)
XMLPUBFUN int XMLCALL xmlSAXVersion(xmlSAXHandler *hdlr, int version)
Definition: SAX2.c:2858
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static int used
Definition: adh-main.c:39
#define msg(x)
Definition: auth_time.c:54
int xmlBufIsEmpty(const xmlBufPtr buf)
Definition: buf.c:673
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input)
Definition: buf.c:1094
xmlBufPtr xmlBufCreate(void)
Definition: buf.c:122
#define NULL
Definition: types.h:112
static const WCHAR version[]
Definition: asmname.c:66
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7482
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
int xmlCharEncFirstLineInput(xmlParserInputBufferPtr input, int len)
Definition: encoding.c:2181
int xmlCharEncInput(xmlParserInputBufferPtr input, int flush)
Definition: encoding.c:2288
XMLPUBFUN int XMLCALL xmlCharEncCloseFunc(xmlCharEncodingHandler *handler)
Definition: encoding.c:2796
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL xmlGetCharEncodingHandler(xmlCharEncoding enc)
Definition: encoding.c:1544
xmlCharEncoding
Definition: encoding.h:56
@ XML_CHAR_ENCODING_8859_6
Definition: encoding.h:73
@ XML_CHAR_ENCODING_UTF8
Definition: encoding.h:59
@ XML_CHAR_ENCODING_8859_7
Definition: encoding.h:74
@ XML_CHAR_ENCODING_8859_2
Definition: encoding.h:69
@ XML_CHAR_ENCODING_8859_4
Definition: encoding.h:71
@ XML_CHAR_ENCODING_8859_8
Definition: encoding.h:75
@ XML_CHAR_ENCODING_UTF16BE
Definition: encoding.h:61
@ XML_CHAR_ENCODING_UCS2
Definition: encoding.h:67
@ XML_CHAR_ENCODING_2022_JP
Definition: encoding.h:77
@ XML_CHAR_ENCODING_8859_3
Definition: encoding.h:70
@ XML_CHAR_ENCODING_EBCDIC
Definition: encoding.h:64
@ XML_CHAR_ENCODING_UCS4LE
Definition: encoding.h:62
@ XML_CHAR_ENCODING_ERROR
Definition: encoding.h:57
@ XML_CHAR_ENCODING_UCS4_3412
Definition: encoding.h:66
@ XML_CHAR_ENCODING_UCS4BE
Definition: encoding.h:63
@ XML_CHAR_ENCODING_8859_1
Definition: encoding.h:68
@ XML_CHAR_ENCODING_8859_9
Definition: encoding.h:76
@ XML_CHAR_ENCODING_UTF16LE
Definition: encoding.h:60
@ XML_CHAR_ENCODING_NONE
Definition: encoding.h:58
@ XML_CHAR_ENCODING_8859_5
Definition: encoding.h:72
@ XML_CHAR_ENCODING_ASCII
Definition: encoding.h:80
@ XML_CHAR_ENCODING_SHIFT_JIS
Definition: encoding.h:78
@ XML_CHAR_ENCODING_UCS4_2143
Definition: encoding.h:65
@ XML_CHAR_ENCODING_EUC_JP
Definition: encoding.h:79
XMLPUBFUN const char *XMLCALL xmlGetCharEncodingName(xmlCharEncoding enc)
Definition: encoding.c:1254
@ XML_EXTERNAL_GENERAL_PARSED_ENTITY
Definition: entities.h:26
@ XML_INTERNAL_PREDEFINED_ENTITY
Definition: entities.h:30
@ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY
Definition: entities.h:27
@ XML_INTERNAL_GENERAL_ENTITY
Definition: entities.h:25
@ XML_INTERNAL_PARAMETER_ENTITY
Definition: entities.h:28
@ XML_EXTERNAL_PARAMETER_ENTITY
Definition: entities.h:29
FxCollectionEntry * cur
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
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 stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define bits
Definition: infblock.c:15
const char * filename
Definition: ioapi.h:137
#define c
Definition: ke_i.h:80
void __xmlLoaderErr(void *ctx, const char *msg, const char *filename) LIBXML_ATTR_FORMAT(2
#define error(str)
Definition: mkdosfs.c:1605
static int xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler, int len)
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)
#define CHECK_BUFFER(in)
xmlParserCtxtPtr xmlNewParserCtxt(void)
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)
#define LINE_LEN
void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra)
int xmlKeepBlanksDefault(int val)
void xmlNextChar(xmlParserCtxtPtr ctxt)
xmlParserInputPtr xmlNewInputStream(xmlParserCtxtPtr ctxt)
int xmlStringCurrentChar(xmlParserCtxtPtr ctxt, const xmlChar *cur, int *len)
void xmlCheckVersion(int version)
void xmlClearParserCtxt(xmlParserCtxtPtr ctxt)
xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity)
int xmlParserInputGrow(xmlParserInputPtr in, int len)
void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
int xmlSwitchInputEncoding(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, xmlCharEncodingHandlerPtr handler)
int xmlPedanticParserDefault(int val)
#define VALID_CTXT(ctxt)
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)
int xmlSubstituteEntitiesDefault(int val)
void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq)
int xmlIsLetter(int c)
void xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, const xmlParserNodeInfoPtr info)
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)
#define IS_CHAR(c)
#define IS_IDEOGRAPHIC(c)
#define XML_MAX_DICTIONARY_LIMIT
XMLPUBFUN xmlParserInputPtr XMLCALL inputPop(xmlParserCtxtPtr ctxt)
Definition: parser.c:1774
#define INPUT_CHUNK
#define IS_BASECHAR(c)
static BOOL check_buffer(parse_buffer *buf, ULONG size)
Definition: parsing.c:1119
static unsigned __int64 next
Definition: rand_nt.c:6
static FILE * out
Definition: regtests2xml.c:44
const WCHAR * str
XMLPUBFUN xmlDictPtr XMLCALL xmlDictCreate(void)
Definition: dict.c:577
XMLPUBFUN size_t XMLCALL xmlDictSetLimit(xmlDictPtr dict, size_t limit)
Definition: dict.c:1265
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
Definition: dict.c:802
XMLPUBVAR int xmlSubstituteEntitiesDefaultValue
Definition: globals.h:458
XMLPUBVAR int xmlParserDebugEntities
Definition: globals.h:423
XMLPUBVAR int xmlLineNumbersDefaultValue
Definition: globals.h:405
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:248
XMLPUBVAR int xmlKeepBlanksDefaultValue
Definition: globals.h:396
XMLPUBVAR int xmlGetWarningsDefaultValue
Definition: globals.h:369
XMLPUBVAR int xmlLoadExtDtdDefaultValue
Definition: globals.h:414
XMLPUBVAR int xmlIndentTreeOutput
Definition: globals.h:378
XMLPUBVAR int xmlDoValidityCheckingDefaultValue
Definition: globals.h:328
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
XMLPUBVAR int xmlPedanticParserDefaultValue
Definition: globals.h:440
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlReallocFunc xmlRealloc
Definition: globals.h:250
XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler
Definition: globals.h:312
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
XMLPUBFUN void XMLCALL xmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f)
Definition: hash.c:322
XMLPUBFUN void XMLCALL xmlHashDefaultDeallocator(void *entry, const xmlChar *name)
@ XML_PARSER_EOF
Definition: parser.h:111
@ XML_PARSER_START
Definition: parser.h:112
XMLPUBFUN void XMLCALL xmlStopParser(xmlParserCtxtPtr ctxt)
Definition: parser.c:12583
XMLPUBFUN void XMLCALL xmlCtxtReset(xmlParserCtxtPtr ctxt)
Definition: parser.c:14801
XMLPUBFUN void XMLCALL xmlInitParser(void)
Definition: parser.c:14676
@ XML_PARSE_DTDVALID
Definition: parser.h:1097
@ XML_PARSE_NOBLANKS
Definition: parser.h:1101
@ XML_PARSE_DTDLOAD
Definition: parser.h:1095
@ XML_PARSE_NOENT
Definition: parser.h:1094
@ XML_PARSE_PEDANTIC
Definition: parser.h:1100
XMLPUBFUN xmlParserInputPtr XMLCALL xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:571
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:633
xmlParserInput * xmlParserInputPtr
Definition: tree.h:36
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:381
xmlParserCtxt * xmlParserCtxtPtr
Definition: tree.h:39
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:553
#define memset(x, y, z)
Definition: compat.h:39
Definition: tree.h:434
char * file
Definition: xmlerror.h:83
char * str3
Definition: xmlerror.h:87
char * str1
Definition: xmlerror.h:85
char * str2
Definition: xmlerror.h:86
char * message
Definition: xmlerror.h:81
Definition: tree.h:489
int inputMax
Definition: parser.h:201
xmlError lastError
Definition: parser.h:301
char * directory
Definition: parser.h:226
const xmlChar ** atts
Definition: parser.h:264
int nsWellFormed
Definition: parser.h:286
int replaceEntities
Definition: parser.h:189
int hasPErefs
Definition: parser.h:216
xmlValidCtxt vctxt
Definition: parser.h:221
int keepBlanks
Definition: parser.h:236
xmlStartTag * pushTab
Definition: parser.h:283
int external
Definition: parser.h:217
int spaceMax
Definition: parser.h:246
int wellFormed
Definition: parser.h:188
int * space
Definition: parser.h:244
int loadsubset
Definition: parser.h:258
int disableSAX
Definition: parser.h:237
xmlNodePtr * nodeTab
Definition: parser.h:208
xmlChar * extSubSystem
Definition: parser.h:241
struct _xmlSAXHandler * sax
Definition: parser.h:185
xmlParserNodeInfoSeq node_seq
Definition: parser.h:211
xmlDocPtr myDoc
Definition: parser.h:187
int hasExternalSubset
Definition: parser.h:215
long checkIndex
Definition: parser.h:235
int pedantic
Definition: parser.h:255
xmlParserInputState instate
Definition: parser.h:223
const xmlChar * encoding
Definition: parser.h:191
xmlDictPtr dict
Definition: parser.h:263
int recovery
Definition: parser.h:261
int * attallocs
Definition: parser.h:282
int input_id
Definition: parser.h:312
const xmlChar ** nsTab
Definition: parser.h:281
xmlHashTablePtr attsSpecial
Definition: parser.h:285
void * catalogs
Definition: parser.h:260
xmlChar * extSubURI
Definition: parser.h:240
const xmlChar * name
Definition: parser.h:229
unsigned long sizeentities
Definition: parser.h:304
const xmlChar * version
Definition: parser.h:190
xmlAttrPtr freeAttrs
Definition: parser.h:296
int record_info
Definition: parser.h:210
int * spaceTab
Definition: parser.h:247
int inSubset
Definition: parser.h:238
int standalone
Definition: parser.h:192
unsigned long sizeentcopy
Definition: parser.h:313
xmlParserInputPtr * inputTab
Definition: parser.h:202
const xmlChar ** nameTab
Definition: parser.h:232
void * userData
Definition: parser.h:186
unsigned long nbentities
Definition: parser.h:303
xmlHashTablePtr attsDefault
Definition: parser.h:284
int linenumbers
Definition: parser.h:259
xmlNodePtr node
Definition: parser.h:205
xmlParserNodeInfo * nodeInfoTab
Definition: parser.h:310
int validate
Definition: parser.h:220
xmlNodePtr freeElems
Definition: parser.h:294
xmlParserInputPtr input
Definition: parser.h:199
xmlBufPtr buffer
Definition: xmlIO.h:132
const char * filename
Definition: parser.h:56
const xmlChar * encoding
Definition: parser.h:71
const xmlChar * end
Definition: parser.h:60
xmlParserInputBufferPtr buf
Definition: parser.h:54
const char * directory
Definition: parser.h:57
const xmlChar * cur
Definition: parser.h:59
unsigned long length
Definition: parser.h:100
unsigned long maximum
Definition: parser.h:99
xmlParserNodeInfo * buffer
Definition: parser.h:101
const struct _xmlNode * node
Definition: parser.h:88
Definition: actctx.c:447
WCHAR * name
Definition: actctx.c:464
static int processed(const type_t *type)
Definition: typegen.c:2254
Definition: dlist.c:348
XMLPUBFUN xmlChar *XMLCALL xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2380
int ret
#define snprintf
Definition: wintirpc.h:48
XMLPUBFUN int XMLCALL xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len)
XMLPUBFUN char *XMLCALL xmlParserGetDirectory(const char *filename)
XMLPUBFUN void XMLCALL xmlFreeParserInputBuffer(xmlParserInputBufferPtr in)
XMLPUBFUN xmlParserInputPtr XMLCALL xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret)
XMLPUBFUN int XMLCALL xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len)
XMLPUBFUN xmlParserInputBufferPtr XMLCALL xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc)
XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL xmlParserValidityWarning(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL XMLPUBFUN void XMLCDECL xmlParserValidityError(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
@ XML_ERR_FATAL
Definition: xmlerror.h:28
@ XML_FROM_PARSER
Definition: xmlerror.h:38
xmlParserErrors
Definition: xmlerror.h:99
@ XML_I18N_CONV_FAILED
Definition: xmlerror.h:833
@ XML_ERR_OK
Definition: xmlerror.h:100
@ XML_ERR_INVALID_CHAR
Definition: xmlerror.h:109
@ XML_ERR_INTERNAL_ERROR
Definition: xmlerror.h:101
@ XML_ERR_UNKNOWN_ENCODING
Definition: xmlerror.h:131
@ XML_ERR_NO_MEMORY
Definition: xmlerror.h:102
@ XML_ERR_UNSUPPORTED_ENCODING
Definition: xmlerror.h:132
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:67
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:426
unsigned char xmlChar
Definition: xmlstring.h:28
#define LIBXML_ATTR_FORMAT(fmt, args)
Definition: xmlversion.h:486
#define LIBXML_VERSION
Definition: xmlversion.h:39
#define const
Definition: zconf.h:233