Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(955)

Side by Side Diff: third_party/libxml/src/xmlreader.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no iconv Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxml/src/xmlmodule.c ('k') | third_party/libxml/src/xmlregexp.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * xmlreader.c: implements the xmlTextReader streaming node API 2 * xmlreader.c: implements the xmlTextReader streaming node API
3 * 3 *
4 * NOTE: 4 * NOTE:
5 * XmlTextReader.Normalization Property won't be supported, since 5 * XmlTextReader.Normalization Property won't be supported, since
6 * it makes the parser non compliant to the XML recommendation 6 * it makes the parser non compliant to the XML recommendation
7 * 7 *
8 * See Copyright for the status of this software. 8 * See Copyright for the status of this software.
9 * 9 *
10 * daniel@veillard.com 10 * daniel@veillard.com
(...skipping 26 matching lines...) Expand all
37 #include <libxml/xmlschemas.h> 37 #include <libxml/xmlschemas.h>
38 #endif 38 #endif
39 #include <libxml/uri.h> 39 #include <libxml/uri.h>
40 #ifdef LIBXML_XINCLUDE_ENABLED 40 #ifdef LIBXML_XINCLUDE_ENABLED
41 #include <libxml/xinclude.h> 41 #include <libxml/xinclude.h>
42 #endif 42 #endif
43 #ifdef LIBXML_PATTERN_ENABLED 43 #ifdef LIBXML_PATTERN_ENABLED
44 #include <libxml/pattern.h> 44 #include <libxml/pattern.h>
45 #endif 45 #endif
46 46
47 #include "buf.h"
48
47 #define MAX_ERR_MSG_SIZE 64000 49 #define MAX_ERR_MSG_SIZE 64000
48 50
49 /* 51 /*
50 * The following VA_COPY was coded following an example in 52 * The following VA_COPY was coded following an example in
51 * the Samba project. It may not be sufficient for some 53 * the Samba project. It may not be sufficient for some
52 * esoteric implementations of va_list (i.e. it may need 54 * esoteric implementations of va_list but (hopefully) will
53 * something involving a memcpy) but (hopefully) will be 55 * be sufficient for libxml2.
54 * sufficient for libxml2.
55 */ 56 */
56 #ifndef VA_COPY 57 #ifndef VA_COPY
57 #ifdef HAVE_VA_COPY 58 #ifdef HAVE_VA_COPY
58 #define VA_COPY(dest, src) va_copy(dest, src) 59 #define VA_COPY(dest, src) va_copy(dest, src)
59 #else 60 #else
60 #ifdef HAVE___VA_COPY 61 #ifdef HAVE___VA_COPY
61 #define VA_COPY(dest,src) __va_copy(dest, src) 62 #define VA_COPY(dest,src) __va_copy(dest, src)
62 #else 63 #else
63 #define VA_COPY(dest,src) (dest) = (src) 64 #ifndef VA_LIST_IS_ARRAY
65 #define VA_COPY(dest,src) (dest) = (src)
66 #else
67 #include <string.h>
68 #define VA_COPY(dest,src) memcpy((char *)(dest),(char *)(src),sizeof(va_ list))
69 #endif
64 #endif 70 #endif
65 #endif 71 #endif
66 #endif 72 #endif
67 73
68 /* #define DEBUG_CALLBACKS */ 74 /* #define DEBUG_CALLBACKS */
69 /* #define DEBUG_READER */ 75 /* #define DEBUG_READER */
70 76
71 /** 77 /**
72 * TODO: 78 * TODO:
73 * 79 *
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 endElementNsSAX2Func endElementNs; /* idem */ 134 endElementNsSAX2Func endElementNs; /* idem */
129 charactersSAXFunc characters; 135 charactersSAXFunc characters;
130 cdataBlockSAXFunc cdataBlock; 136 cdataBlockSAXFunc cdataBlock;
131 unsigned int base; /* base of the segment in the input */ 137 unsigned int base; /* base of the segment in the input */
132 unsigned int cur; /* current position in the input */ 138 unsigned int cur; /* current position in the input */
133 xmlNodePtr node; /* current node */ 139 xmlNodePtr node; /* current node */
134 xmlNodePtr curnode;/* current attribute node */ 140 xmlNodePtr curnode;/* current attribute node */
135 int depth; /* depth of the current node */ 141 int depth; /* depth of the current node */
136 xmlNodePtr faketext;/* fake xmlNs chld */ 142 xmlNodePtr faketext;/* fake xmlNs chld */
137 int preserve;/* preserve the resulting document */ 143 int preserve;/* preserve the resulting document */
138 xmlBufferPtr» » buffer; /* used to return const xmlChar * */ 144 xmlBufPtr» » buffer; /* used to return const xmlChar * */
139 xmlDictPtr dict; /* the context dictionnary */ 145 xmlDictPtr dict; /* the context dictionnary */
140 146
141 /* entity stack when traversing entities content */ 147 /* entity stack when traversing entities content */
142 xmlNodePtr ent; /* Current Entity Ref Node */ 148 xmlNodePtr ent; /* Current Entity Ref Node */
143 int entNr; /* Depth of the entities stack */ 149 int entNr; /* Depth of the entities stack */
144 int entMax; /* Max depth of the entities stack */ 150 int entMax; /* Max depth of the entities stack */
145 xmlNodePtr *entTab; /* array of entities */ 151 xmlNodePtr *entTab; /* array of entities */
146 152
147 /* error handling */ 153 /* error handling */
148 xmlTextReaderErrorFunc errorFunc; /* callback function */ 154 xmlTextReaderErrorFunc errorFunc; /* callback function */
149 void *errorFuncArg; /* callback function user argument */ 155 void *errorFuncArg; /* callback function user argument */
150 156
151 #ifdef LIBXML_SCHEMAS_ENABLED 157 #ifdef LIBXML_SCHEMAS_ENABLED
152 /* Handling of RelaxNG validation */ 158 /* Handling of RelaxNG validation */
153 xmlRelaxNGPtr rngSchemas; /* The Relax NG schemas */ 159 xmlRelaxNGPtr rngSchemas; /* The Relax NG schemas */
154 xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */ 160 xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */
161 int rngPreserveCtxt; /* 1 if the context was provided by the user */
155 int rngValidErrors;/* The number of errors detected */ 162 int rngValidErrors;/* The number of errors detected */
156 xmlNodePtr rngFullNode; /* the node if RNG not progressive */ 163 xmlNodePtr rngFullNode; /* the node if RNG not progressive */
157 /* Handling of Schemas validation */ 164 /* Handling of Schemas validation */
158 xmlSchemaPtr xsdSchemas; /* The Schemas schemas */ 165 xmlSchemaPtr xsdSchemas; /* The Schemas schemas */
159 xmlSchemaValidCtxtPtr xsdValidCtxt;/* The Schemas validation context */ 166 xmlSchemaValidCtxtPtr xsdValidCtxt;/* The Schemas validation context */
160 int xsdPreserveCtxt; /* 1 if the context was provided by t he user */ 167 int xsdPreserveCtxt; /* 1 if the context was provided by t he user */
161 int xsdValidErrors;/* The number of errors detected */ 168 int xsdValidErrors;/* The number of errors detected */
162 xmlSchemaSAXPlugPtr xsdPlug; /* the schemas plug in SAX pipeline */ 169 xmlSchemaSAXPlugPtr xsdPlug; /* the schemas plug in SAX pipeline */
163 #endif 170 #endif
164 #ifdef LIBXML_XINCLUDE_ENABLED 171 #ifdef LIBXML_XINCLUDE_ENABLED
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 * xmlTextReaderFreeProp: 279 * xmlTextReaderFreeProp:
273 * @reader: the xmlTextReaderPtr used 280 * @reader: the xmlTextReaderPtr used
274 * @cur: the node 281 * @cur: the node
275 * 282 *
276 * Free a node. 283 * Free a node.
277 */ 284 */
278 static void 285 static void
279 xmlTextReaderFreeProp(xmlTextReaderPtr reader, xmlAttrPtr cur) { 286 xmlTextReaderFreeProp(xmlTextReaderPtr reader, xmlAttrPtr cur) {
280 xmlDictPtr dict; 287 xmlDictPtr dict;
281 288
282 dict = reader->ctxt->dict; 289 if ((reader != NULL) && (reader->ctxt != NULL))
290 » dict = reader->ctxt->dict;
291 else
292 dict = NULL;
283 if (cur == NULL) return; 293 if (cur == NULL) return;
284 294
285 if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) 295 if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue))
286 xmlDeregisterNodeDefaultValue((xmlNodePtr) cur); 296 xmlDeregisterNodeDefaultValue((xmlNodePtr) cur);
287 297
288 /* Check for ID removal -> leading to invalid references ! */ 298 /* Check for ID removal -> leading to invalid references ! */
289 if ((cur->parent != NULL) && (cur->parent->doc != NULL) && 299 if ((cur->parent != NULL) && (cur->parent->doc != NULL) &&
290 ((cur->parent->doc->intSubset != NULL) || 300 ((cur->parent->doc->intSubset != NULL) ||
291 (cur->parent->doc->extSubset != NULL))) { 301 (cur->parent->doc->extSubset != NULL))) {
292 if (xmlIsID(cur->parent->doc, cur->parent, cur)) 302 if (xmlIsID(cur->parent->doc, cur->parent, cur))
(...skipping 16 matching lines...) Expand all
309 /** 319 /**
310 * xmlTextReaderFreePropList: 320 * xmlTextReaderFreePropList:
311 * @reader: the xmlTextReaderPtr used 321 * @reader: the xmlTextReaderPtr used
312 * @cur: the first property in the list 322 * @cur: the first property in the list
313 * 323 *
314 * Free a property and all its siblings, all the children are freed too. 324 * Free a property and all its siblings, all the children are freed too.
315 */ 325 */
316 static void 326 static void
317 xmlTextReaderFreePropList(xmlTextReaderPtr reader, xmlAttrPtr cur) { 327 xmlTextReaderFreePropList(xmlTextReaderPtr reader, xmlAttrPtr cur) {
318 xmlAttrPtr next; 328 xmlAttrPtr next;
319 if (cur == NULL) return; 329
320 while (cur != NULL) { 330 while (cur != NULL) {
321 next = cur->next; 331 next = cur->next;
322 xmlTextReaderFreeProp(reader, cur); 332 xmlTextReaderFreeProp(reader, cur);
323 cur = next; 333 cur = next;
324 } 334 }
325 } 335 }
326 336
327 /** 337 /**
328 * xmlTextReaderFreeNodeList: 338 * xmlTextReaderFreeNodeList:
329 * @reader: the xmlTextReaderPtr used 339 * @reader: the xmlTextReaderPtr used
330 * @cur: the first node in the list 340 * @cur: the first node in the list
331 * 341 *
332 * Free a node and all its siblings, this is a recursive behaviour, all 342 * Free a node and all its siblings, this is a recursive behaviour, all
333 * the children are freed too. 343 * the children are freed too.
334 */ 344 */
335 static void 345 static void
336 xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur) { 346 xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur) {
337 xmlNodePtr next; 347 xmlNodePtr next;
338 xmlDictPtr dict; 348 xmlDictPtr dict;
339 349
340 dict = reader->ctxt->dict; 350 if ((reader != NULL) && (reader->ctxt != NULL))
351 » dict = reader->ctxt->dict;
352 else
353 dict = NULL;
341 if (cur == NULL) return; 354 if (cur == NULL) return;
342 if (cur->type == XML_NAMESPACE_DECL) { 355 if (cur->type == XML_NAMESPACE_DECL) {
343 xmlFreeNsList((xmlNsPtr) cur); 356 xmlFreeNsList((xmlNsPtr) cur);
344 return; 357 return;
345 } 358 }
346 if ((cur->type == XML_DOCUMENT_NODE) || 359 if ((cur->type == XML_DOCUMENT_NODE) ||
347 (cur->type == XML_HTML_DOCUMENT_NODE)) { 360 (cur->type == XML_HTML_DOCUMENT_NODE)) {
348 xmlFreeDoc((xmlDocPtr) cur); 361 xmlFreeDoc((xmlDocPtr) cur);
349 return; 362 return;
350 } 363 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 * @reader: the xmlTextReaderPtr used 420 * @reader: the xmlTextReaderPtr used
408 * @cur: the node 421 * @cur: the node
409 * 422 *
410 * Free a node, this is a recursive behaviour, all the children are freed too. 423 * Free a node, this is a recursive behaviour, all the children are freed too.
411 * This doesn't unlink the child from the list, use xmlUnlinkNode() first. 424 * This doesn't unlink the child from the list, use xmlUnlinkNode() first.
412 */ 425 */
413 static void 426 static void
414 xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur) { 427 xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur) {
415 xmlDictPtr dict; 428 xmlDictPtr dict;
416 429
417 dict = reader->ctxt->dict; 430 if ((reader != NULL) && (reader->ctxt != NULL))
431 » dict = reader->ctxt->dict;
432 else
433 dict = NULL;
418 if (cur->type == XML_DTD_NODE) { 434 if (cur->type == XML_DTD_NODE) {
419 xmlFreeDtd((xmlDtdPtr) cur); 435 xmlFreeDtd((xmlDtdPtr) cur);
420 return; 436 return;
421 } 437 }
422 if (cur->type == XML_NAMESPACE_DECL) { 438 if (cur->type == XML_NAMESPACE_DECL) {
423 xmlFreeNs((xmlNsPtr) cur); 439 xmlFreeNs((xmlNsPtr) cur);
424 return; 440 return;
425 } 441 }
426 if (cur->type == XML_ATTRIBUTE_NODE) { 442 if (cur->type == XML_ATTRIBUTE_NODE) {
427 xmlTextReaderFreeProp(reader, (xmlAttrPtr) cur); 443 xmlTextReaderFreeProp(reader, (xmlAttrPtr) cur);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 * xmlTextReaderPushData: 815 * xmlTextReaderPushData:
800 * @reader: the xmlTextReaderPtr used 816 * @reader: the xmlTextReaderPtr used
801 * 817 *
802 * Push data down the progressive parser until a significant callback 818 * Push data down the progressive parser until a significant callback
803 * got raised. 819 * got raised.
804 * 820 *
805 * Returns -1 in case of failure, 0 otherwise 821 * Returns -1 in case of failure, 0 otherwise
806 */ 822 */
807 static int 823 static int
808 xmlTextReaderPushData(xmlTextReaderPtr reader) { 824 xmlTextReaderPushData(xmlTextReaderPtr reader) {
809 xmlBufferPtr inbuf; 825 xmlBufPtr inbuf;
810 int val, s; 826 int val, s;
811 xmlTextReaderState oldstate; 827 xmlTextReaderState oldstate;
828 int alloc;
812 829
813 if ((reader->input == NULL) || (reader->input->buffer == NULL)) 830 if ((reader->input == NULL) || (reader->input->buffer == NULL))
814 return(-1); 831 return(-1);
815 832
816 oldstate = reader->state; 833 oldstate = reader->state;
817 reader->state = XML_TEXTREADER_NONE; 834 reader->state = XML_TEXTREADER_NONE;
818 inbuf = reader->input->buffer; 835 inbuf = reader->input->buffer;
836 alloc = xmlBufGetAllocationScheme(inbuf);
819 837
820 while (reader->state == XML_TEXTREADER_NONE) { 838 while (reader->state == XML_TEXTREADER_NONE) {
821 » if (inbuf->use < reader->cur + CHUNK_SIZE) { 839 » if (xmlBufUse(inbuf) < reader->cur + CHUNK_SIZE) {
822 /* 840 /*
823 * Refill the buffer unless we are at the end of the stream 841 * Refill the buffer unless we are at the end of the stream
824 */ 842 */
825 if (reader->mode != XML_TEXTREADER_MODE_EOF) { 843 if (reader->mode != XML_TEXTREADER_MODE_EOF) {
826 val = xmlParserInputBufferRead(reader->input, 4096); 844 val = xmlParserInputBufferRead(reader->input, 4096);
827 if ((val == 0) && 845 if ((val == 0) &&
828 » » (inbuf->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) { 846 » » (alloc == XML_BUFFER_ALLOC_IMMUTABLE)) {
829 » » if (inbuf->use == reader->cur) { 847 » » if (xmlBufUse(inbuf) == reader->cur) {
830 reader->mode = XML_TEXTREADER_MODE_EOF; 848 reader->mode = XML_TEXTREADER_MODE_EOF;
831 reader->state = oldstate; 849 reader->state = oldstate;
832 } 850 }
833 } else if (val < 0) { 851 } else if (val < 0) {
834 reader->mode = XML_TEXTREADER_MODE_EOF; 852 reader->mode = XML_TEXTREADER_MODE_EOF;
835 reader->state = oldstate; 853 reader->state = oldstate;
836 if ((oldstate != XML_TEXTREADER_START) || 854 if ((oldstate != XML_TEXTREADER_START) ||
837 (reader->ctxt->myDoc != NULL)) 855 (reader->ctxt->myDoc != NULL))
838 return(val); 856 return(val);
839 } else if (val == 0) { 857 } else if (val == 0) {
840 /* mark the end of the stream and process the remains */ 858 /* mark the end of the stream and process the remains */
841 reader->mode = XML_TEXTREADER_MODE_EOF; 859 reader->mode = XML_TEXTREADER_MODE_EOF;
842 break; 860 break;
843 } 861 }
844 862
845 } else 863 } else
846 break; 864 break;
847 } 865 }
848 /* 866 /*
849 * parse by block of CHUNK_SIZE bytes, various tests show that 867 * parse by block of CHUNK_SIZE bytes, various tests show that
850 * it's the best tradeoff at least on a 1.2GH Duron 868 * it's the best tradeoff at least on a 1.2GH Duron
851 */ 869 */
852 » if (inbuf->use >= reader->cur + CHUNK_SIZE) { 870 » if (xmlBufUse(inbuf) >= reader->cur + CHUNK_SIZE) {
853 val = xmlParseChunk(reader->ctxt, 871 val = xmlParseChunk(reader->ctxt,
854 » » (const char *) &inbuf->content[reader->cur], 872 (const char *) xmlBufContent(inbuf) + reader->cur,
855 » » » CHUNK_SIZE, 0); 873 CHUNK_SIZE, 0);
856 reader->cur += CHUNK_SIZE; 874 reader->cur += CHUNK_SIZE;
857 » if ((val != 0) || (reader->ctxt->wellFormed == 0)) 875 » if (val != 0)
858 » » return(-1); 876 » » reader->ctxt->wellFormed = 0;
877 » if (reader->ctxt->wellFormed == 0)
878 » » break;
859 } else { 879 } else {
860 » s = inbuf->use - reader->cur; 880 » s = xmlBufUse(inbuf) - reader->cur;
861 val = xmlParseChunk(reader->ctxt, 881 val = xmlParseChunk(reader->ctxt,
862 » » (const char *) &inbuf->content[reader->cur], 882 » » (const char *) xmlBufContent(inbuf) + reader->cur,
863 » » » s, 0); 883 » » » s, 0);
864 reader->cur += s; 884 reader->cur += s;
865 » if ((val != 0) || (reader->ctxt->wellFormed == 0)) 885 » if (val != 0)
866 » » return(-1); 886 » » reader->ctxt->wellFormed = 0;
867 break; 887 break;
868 } 888 }
869 } 889 }
870 890
871 /* 891 /*
872 * Discard the consumed input when needed and possible 892 * Discard the consumed input when needed and possible
873 */ 893 */
874 if (reader->mode == XML_TEXTREADER_MODE_INTERACTIVE) { 894 if (reader->mode == XML_TEXTREADER_MODE_INTERACTIVE) {
875 if (inbuf->alloc != XML_BUFFER_ALLOC_IMMUTABLE) { 895 if (alloc != XML_BUFFER_ALLOC_IMMUTABLE) {
876 if ((reader->cur >= 4096) && 896 if ((reader->cur >= 4096) &&
877 » » (inbuf->use - reader->cur <= CHUNK_SIZE)) { 897 » » (xmlBufUse(inbuf) - reader->cur <= CHUNK_SIZE)) {
878 » » val = xmlBufferShrink(inbuf, reader->cur); 898 » » val = xmlBufShrink(inbuf, reader->cur);
879 if (val >= 0) { 899 if (val >= 0) {
880 reader->cur -= val; 900 reader->cur -= val;
881 } 901 }
882 } 902 }
883 } 903 }
884 } 904 }
885 905
886 /* 906 /*
887 * At the end of the stream signal that the work is done to the Push 907 * At the end of the stream signal that the work is done to the Push
888 * parser. 908 * parser.
889 */ 909 */
890 else if (reader->mode == XML_TEXTREADER_MODE_EOF) { 910 else if (reader->mode == XML_TEXTREADER_MODE_EOF) {
891 if (reader->state != XML_TEXTREADER_DONE) { 911 if (reader->state != XML_TEXTREADER_DONE) {
892 » s = inbuf->use - reader->cur; 912 » s = xmlBufUse(inbuf) - reader->cur;
893 val = xmlParseChunk(reader->ctxt, 913 val = xmlParseChunk(reader->ctxt,
894 » » (const char *) &inbuf->content[reader->cur], 914 » » (const char *) xmlBufContent(inbuf) + reader->cur,
895 » » s, 1); 915 » » » s, 1);
896 » reader->cur = inbuf->use; 916 » reader->cur = xmlBufUse(inbuf);
897 reader->state = XML_TEXTREADER_DONE; 917 reader->state = XML_TEXTREADER_DONE;
898 » if ((val != 0) || (reader->ctxt->wellFormed == 0)) 918 » if (val != 0) {
899 » return(-1); 919 » if (reader->ctxt->wellFormed)
920 » » reader->ctxt->wellFormed = 0;
921 » » else
922 » » return(-1);
923 » }
900 } 924 }
901 } 925 }
902 reader->state = oldstate; 926 reader->state = oldstate;
927 if (reader->ctxt->wellFormed == 0) {
928 reader->mode = XML_TEXTREADER_MODE_EOF;
929 return(-1);
930 }
931
903 return(0); 932 return(0);
904 } 933 }
905 934
906 #ifdef LIBXML_REGEXP_ENABLED 935 #ifdef LIBXML_REGEXP_ENABLED
907 /** 936 /**
908 * xmlTextReaderValidatePush: 937 * xmlTextReaderValidatePush:
909 * @reader: the xmlTextReaderPtr used 938 * @reader: the xmlTextReaderPtr used
910 * 939 *
911 * Push the current node for validation 940 * Push the current node for validation
912 */ 941 */
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (ret != 1) 990 if (ret != 1)
962 reader->rngValidErrors++; 991 reader->rngValidErrors++;
963 } 992 }
964 #endif 993 #endif
965 } 994 }
966 995
967 /** 996 /**
968 * xmlTextReaderValidateCData: 997 * xmlTextReaderValidateCData:
969 * @reader: the xmlTextReaderPtr used 998 * @reader: the xmlTextReaderPtr used
970 * @data: pointer to the CData 999 * @data: pointer to the CData
971 * @len: lenght of the CData block in bytes. 1000 * @len: length of the CData block in bytes.
972 * 1001 *
973 * Push some CData for validation 1002 * Push some CData for validation
974 */ 1003 */
975 static void 1004 static void
976 xmlTextReaderValidateCData(xmlTextReaderPtr reader, 1005 xmlTextReaderValidateCData(xmlTextReaderPtr reader,
977 const xmlChar *data, int len) { 1006 const xmlChar *data, int len) {
978 #ifdef LIBXML_VALID_ENABLED 1007 #ifdef LIBXML_VALID_ENABLED
979 if ((reader->validate == XML_TEXTREADER_VALIDATE_DTD) && 1008 if ((reader->validate == XML_TEXTREADER_VALIDATE_DTD) &&
980 (reader->ctxt != NULL) && (reader->ctxt->validate == 1)) { 1009 (reader->ctxt != NULL) && (reader->ctxt->validate == 1)) {
981 reader->ctxt->valid &= xmlValidatePushCData(&reader->ctxt->vctxt, 1010 reader->ctxt->valid &= xmlValidatePushCData(&reader->ctxt->vctxt,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 * to xmlTextReaderReadString. 1234 * to xmlTextReaderReadString.
1206 * 1235 *
1207 * Returns a string containing the content, or NULL in case of error. 1236 * Returns a string containing the content, or NULL in case of error.
1208 */ 1237 */
1209 static xmlChar * 1238 static xmlChar *
1210 xmlTextReaderCollectSiblings(xmlNodePtr node) 1239 xmlTextReaderCollectSiblings(xmlNodePtr node)
1211 { 1240 {
1212 xmlBufferPtr buffer; 1241 xmlBufferPtr buffer;
1213 xmlChar *ret; 1242 xmlChar *ret;
1214 1243
1244 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
1245 return(NULL);
1246
1215 buffer = xmlBufferCreate(); 1247 buffer = xmlBufferCreate();
1216 if (buffer == NULL) 1248 if (buffer == NULL)
1217 return NULL; 1249 return NULL;
1218 1250
1219 for ( ; node != NULL; node = node->next) { 1251 for ( ; node != NULL; node = node->next) {
1220 switch (node->type) { 1252 switch (node->type) {
1221 case XML_TEXT_NODE: 1253 case XML_TEXT_NODE:
1222 case XML_CDATA_SECTION_NODE: 1254 case XML_CDATA_SECTION_NODE:
1223 xmlBufferCat(buffer, node->content); 1255 xmlBufferCat(buffer, node->content);
1224 break; 1256 break;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 xmlNodePtr oldnode = NULL; 1289 xmlNodePtr oldnode = NULL;
1258 1290
1259 1291
1260 if (reader == NULL) 1292 if (reader == NULL)
1261 return(-1); 1293 return(-1);
1262 reader->curnode = NULL; 1294 reader->curnode = NULL;
1263 if (reader->doc != NULL) 1295 if (reader->doc != NULL)
1264 return(xmlTextReaderReadTree(reader)); 1296 return(xmlTextReaderReadTree(reader));
1265 if (reader->ctxt == NULL) 1297 if (reader->ctxt == NULL)
1266 return(-1); 1298 return(-1);
1267 if (reader->ctxt->wellFormed != 1)
1268 return(-1);
1269 1299
1270 #ifdef DEBUG_READER 1300 #ifdef DEBUG_READER
1271 fprintf(stderr, "\nREAD "); 1301 fprintf(stderr, "\nREAD ");
1272 DUMP_READER 1302 DUMP_READER
1273 #endif 1303 #endif
1274 if (reader->mode == XML_TEXTREADER_MODE_INITIAL) { 1304 if (reader->mode == XML_TEXTREADER_MODE_INITIAL) {
1275 reader->mode = XML_TEXTREADER_MODE_INTERACTIVE; 1305 reader->mode = XML_TEXTREADER_MODE_INTERACTIVE;
1276 /* 1306 /*
1277 * Initial state 1307 * Initial state
1278 */ 1308 */
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1415
1386 /* 1416 /*
1387 * Cleanup of the old node 1417 * Cleanup of the old node
1388 */ 1418 */
1389 if ((reader->preserves == 0) && 1419 if ((reader->preserves == 0) &&
1390 #ifdef LIBXML_XINCLUDE_ENABLED 1420 #ifdef LIBXML_XINCLUDE_ENABLED
1391 (reader->in_xinclude == 0) && 1421 (reader->in_xinclude == 0) &&
1392 #endif 1422 #endif
1393 (reader->entNr == 0) && 1423 (reader->entNr == 0) &&
1394 (reader->node->prev != NULL) && 1424 (reader->node->prev != NULL) &&
1395 » (reader->node->prev->type != XML_DTD_NODE)) { 1425 (reader->node->prev->type != XML_DTD_NODE)) {
1396 xmlNodePtr tmp = reader->node->prev; 1426 xmlNodePtr tmp = reader->node->prev;
1397 if ((tmp->extra & NODE_IS_PRESERVED) == 0) { 1427 if ((tmp->extra & NODE_IS_PRESERVED) == 0) {
1398 xmlUnlinkNode(tmp); 1428 xmlUnlinkNode(tmp);
1399 xmlTextReaderFreeNode(reader, tmp); 1429 xmlTextReaderFreeNode(reader, tmp);
1400 } 1430 }
1401 } 1431 }
1402 1432
1403 goto node_found; 1433 goto node_found;
1404 } 1434 }
1405 if ((oldstate == XML_TEXTREADER_ELEMENT) && 1435 if ((oldstate == XML_TEXTREADER_ELEMENT) &&
1406 (reader->node->type == XML_ELEMENT_NODE) && 1436 (reader->node->type == XML_ELEMENT_NODE) &&
1407 (reader->node->children == NULL) && 1437 (reader->node->children == NULL) &&
1408 ((reader->node->extra & NODE_IS_EMPTY) == 0)) {; 1438 ((reader->node->extra & NODE_IS_EMPTY) == 0)) {;
1409 reader->state = XML_TEXTREADER_END; 1439 reader->state = XML_TEXTREADER_END;
1410 goto node_found; 1440 goto node_found;
1411 } 1441 }
1412 #ifdef LIBXML_REGEXP_ENABLED 1442 #ifdef LIBXML_REGEXP_ENABLED
1413 if ((reader->validate) && (reader->node->type == XML_ELEMENT_NODE)) 1443 if ((reader->validate != XML_TEXTREADER_NOT_VALIDATE) && (reader->node->type == XML_ELEMENT_NODE))
1414 xmlTextReaderValidatePop(reader); 1444 xmlTextReaderValidatePop(reader);
1415 #endif /* LIBXML_REGEXP_ENABLED */ 1445 #endif /* LIBXML_REGEXP_ENABLED */
1416 if ((reader->preserves > 0) && 1446 if ((reader->preserves > 0) &&
1417 (reader->node->extra & NODE_IS_SPRESERVED)) 1447 (reader->node->extra & NODE_IS_SPRESERVED))
1418 reader->preserves--; 1448 reader->preserves--;
1419 reader->node = reader->node->parent; 1449 reader->node = reader->node->parent;
1420 if ((reader->node == NULL) || 1450 if ((reader->node == NULL) ||
1421 (reader->node->type == XML_DOCUMENT_NODE) || 1451 (reader->node->type == XML_DOCUMENT_NODE) ||
1422 #ifdef LIBXML_DOCB_ENABLED 1452 #ifdef LIBXML_DOCB_ENABLED
1423 (reader->node->type == XML_DOCB_DOCUMENT_NODE) || 1453 (reader->node->type == XML_DOCB_DOCUMENT_NODE) ||
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 #endif /* LIBXML_REGEXP_ENABLED */ 1566 #endif /* LIBXML_REGEXP_ENABLED */
1537 } 1567 }
1538 if ((reader->node != NULL) && 1568 if ((reader->node != NULL) &&
1539 (reader->node->type == XML_ENTITY_DECL) && 1569 (reader->node->type == XML_ENTITY_DECL) &&
1540 (reader->ent != NULL) && (reader->ent->children == reader->node)) { 1570 (reader->ent != NULL) && (reader->ent->children == reader->node)) {
1541 reader->node = xmlTextReaderEntPop(reader); 1571 reader->node = xmlTextReaderEntPop(reader);
1542 reader->depth++; 1572 reader->depth++;
1543 goto get_next_node; 1573 goto get_next_node;
1544 } 1574 }
1545 #ifdef LIBXML_REGEXP_ENABLED 1575 #ifdef LIBXML_REGEXP_ENABLED
1546 if ((reader->validate) && (reader->node != NULL)) { 1576 if ((reader->validate != XML_TEXTREADER_NOT_VALIDATE) && (reader->node != NU LL)) {
1547 xmlNodePtr node = reader->node; 1577 xmlNodePtr node = reader->node;
1548 1578
1549 if ((node->type == XML_ELEMENT_NODE) && 1579 if ((node->type == XML_ELEMENT_NODE) &&
1550 ((reader->state != XML_TEXTREADER_END) && 1580 ((reader->state != XML_TEXTREADER_END) &&
1551 (reader->state != XML_TEXTREADER_BACKTRACK))) { 1581 (reader->state != XML_TEXTREADER_BACKTRACK))) {
1552 xmlTextReaderValidatePush(reader); 1582 xmlTextReaderValidatePush(reader);
1553 } else if ((node->type == XML_TEXT_NODE) || 1583 } else if ((node->type == XML_TEXT_NODE) ||
1554 (node->type == XML_CDATA_SECTION_NODE)) { 1584 (node->type == XML_CDATA_SECTION_NODE)) {
1555 xmlTextReaderValidateCData(reader, node->content, 1585 xmlTextReaderValidateCData(reader, node->content,
1556 xmlStrlen(node->content)); 1586 xmlStrlen(node->content));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 } 1730 }
1701 #endif 1731 #endif
1702 1732
1703 #ifdef LIBXML_WRITER_ENABLED 1733 #ifdef LIBXML_WRITER_ENABLED
1704 /** 1734 /**
1705 * xmlTextReaderReadOuterXml: 1735 * xmlTextReaderReadOuterXml:
1706 * @reader: the xmlTextReaderPtr used 1736 * @reader: the xmlTextReaderPtr used
1707 * 1737 *
1708 * Reads the contents of the current node, including child nodes and markup. 1738 * Reads the contents of the current node, including child nodes and markup.
1709 * 1739 *
1710 * Returns a string containing the XML content, or NULL if the current node 1740 * Returns a string containing the node and any XML content, or NULL if the
1711 * is neither an element nor attribute, or has no child nodes. The 1741 * current node cannot be serialized. The string must be deallocated
1712 * string must be deallocated by the caller. 1742 * by the caller.
1713 */ 1743 */
1714 xmlChar * 1744 xmlChar *
1715 xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) 1745 xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED)
1716 { 1746 {
1717 xmlChar *resbuf; 1747 xmlChar *resbuf;
1718 xmlNodePtr node; 1748 xmlNodePtr node;
1719 xmlBufferPtr buff; 1749 xmlBufferPtr buff;
1720 xmlDocPtr doc; 1750 xmlDocPtr doc;
1721 1751
1722 node = reader->node; 1752 node = reader->node;
1723 doc = reader->doc; 1753 doc = reader->doc;
1724 if (xmlTextReaderExpand(reader) == NULL) { 1754 if (xmlTextReaderExpand(reader) == NULL) {
1725 return NULL; 1755 return NULL;
1726 } 1756 }
1727 node = xmlDocCopyNode(node, doc, 1); 1757 » if (node->type == XML_DTD_NODE) {
1758 » » node = (xmlNodePtr) xmlCopyDtd((xmlDtdPtr) node);
1759 » } else {
1760 » » node = xmlDocCopyNode(node, doc, 1);
1761 » }
1728 buff = xmlBufferCreate(); 1762 buff = xmlBufferCreate();
1729 if (xmlNodeDump(buff, doc, node, 0, 0) == -1) { 1763 if (xmlNodeDump(buff, doc, node, 0, 0) == -1) {
1730 xmlFreeNode(node); 1764 xmlFreeNode(node);
1731 xmlBufferFree(buff); 1765 xmlBufferFree(buff);
1732 return NULL; 1766 return NULL;
1733 } 1767 }
1734 1768
1735 resbuf = buff->content; 1769 resbuf = buff->content;
1736 buff->content = NULL; 1770 buff->content = NULL;
1737 1771
(...skipping 24 matching lines...) Expand all
1762 node = (reader->curnode != NULL) ? reader->curnode : reader->node; 1796 node = (reader->curnode != NULL) ? reader->curnode : reader->node;
1763 switch (node->type) { 1797 switch (node->type) {
1764 case XML_TEXT_NODE: 1798 case XML_TEXT_NODE:
1765 if (node->content != NULL) 1799 if (node->content != NULL)
1766 return(xmlStrdup(node->content)); 1800 return(xmlStrdup(node->content));
1767 break; 1801 break;
1768 case XML_ELEMENT_NODE: 1802 case XML_ELEMENT_NODE:
1769 if (xmlTextReaderDoExpand(reader) != -1) { 1803 if (xmlTextReaderDoExpand(reader) != -1) {
1770 return xmlTextReaderCollectSiblings(node->children); 1804 return xmlTextReaderCollectSiblings(node->children);
1771 } 1805 }
1806 break;
1772 case XML_ATTRIBUTE_NODE: 1807 case XML_ATTRIBUTE_NODE:
1773 TODO 1808 TODO
1774 break; 1809 break;
1775 default: 1810 default:
1776 break; 1811 break;
1777 } 1812 }
1778 return(NULL); 1813 return(NULL);
1779 } 1814 }
1780 1815
1781 #if 0 1816 #if 0
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2042 xmlGenericError(xmlGenericErrorContext, 2077 xmlGenericError(xmlGenericErrorContext,
2043 "xmlNewTextReader : malloc failed\n"); 2078 "xmlNewTextReader : malloc failed\n");
2044 return(NULL); 2079 return(NULL);
2045 } 2080 }
2046 memset(ret, 0, sizeof(xmlTextReader)); 2081 memset(ret, 0, sizeof(xmlTextReader));
2047 ret->doc = NULL; 2082 ret->doc = NULL;
2048 ret->entTab = NULL; 2083 ret->entTab = NULL;
2049 ret->entMax = 0; 2084 ret->entMax = 0;
2050 ret->entNr = 0; 2085 ret->entNr = 0;
2051 ret->input = input; 2086 ret->input = input;
2052 ret->buffer = xmlBufferCreateSize(100); 2087 ret->buffer = xmlBufCreateSize(100);
2053 if (ret->buffer == NULL) { 2088 if (ret->buffer == NULL) {
2054 xmlFree(ret); 2089 xmlFree(ret);
2055 xmlGenericError(xmlGenericErrorContext, 2090 xmlGenericError(xmlGenericErrorContext,
2056 "xmlNewTextReader : malloc failed\n"); 2091 "xmlNewTextReader : malloc failed\n");
2057 return(NULL); 2092 return(NULL);
2058 } 2093 }
2059 ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler)); 2094 ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
2060 if (ret->sax == NULL) { 2095 if (ret->sax == NULL) {
2061 » xmlBufferFree(ret->buffer); 2096 » xmlBufFree(ret->buffer);
2062 xmlFree(ret); 2097 xmlFree(ret);
2063 xmlGenericError(xmlGenericErrorContext, 2098 xmlGenericError(xmlGenericErrorContext,
2064 "xmlNewTextReader : malloc failed\n"); 2099 "xmlNewTextReader : malloc failed\n");
2065 return(NULL); 2100 return(NULL);
2066 } 2101 }
2067 xmlSAXVersion(ret->sax, 2); 2102 xmlSAXVersion(ret->sax, 2);
2068 ret->startElement = ret->sax->startElement; 2103 ret->startElement = ret->sax->startElement;
2069 ret->sax->startElement = xmlTextReaderStartElement; 2104 ret->sax->startElement = xmlTextReaderStartElement;
2070 ret->endElement = ret->sax->endElement; 2105 ret->endElement = ret->sax->endElement;
2071 ret->sax->endElement = xmlTextReaderEndElement; 2106 ret->sax->endElement = xmlTextReaderEndElement;
(...skipping 12 matching lines...) Expand all
2084 #endif /* LIBXML_SAX1_ENABLED */ 2119 #endif /* LIBXML_SAX1_ENABLED */
2085 ret->characters = ret->sax->characters; 2120 ret->characters = ret->sax->characters;
2086 ret->sax->characters = xmlTextReaderCharacters; 2121 ret->sax->characters = xmlTextReaderCharacters;
2087 ret->sax->ignorableWhitespace = xmlTextReaderCharacters; 2122 ret->sax->ignorableWhitespace = xmlTextReaderCharacters;
2088 ret->cdataBlock = ret->sax->cdataBlock; 2123 ret->cdataBlock = ret->sax->cdataBlock;
2089 ret->sax->cdataBlock = xmlTextReaderCDataBlock; 2124 ret->sax->cdataBlock = xmlTextReaderCDataBlock;
2090 2125
2091 ret->mode = XML_TEXTREADER_MODE_INITIAL; 2126 ret->mode = XML_TEXTREADER_MODE_INITIAL;
2092 ret->node = NULL; 2127 ret->node = NULL;
2093 ret->curnode = NULL; 2128 ret->curnode = NULL;
2094 if (ret->input->buffer->use < 4) { 2129 if (xmlBufUse(ret->input->buffer) < 4) {
2095 xmlParserInputBufferRead(input, 4); 2130 xmlParserInputBufferRead(input, 4);
2096 } 2131 }
2097 if (ret->input->buffer->use >= 4) { 2132 if (xmlBufUse(ret->input->buffer) >= 4) {
2098 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, 2133 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL,
2099 » » » (const char *) ret->input->buffer->content, 4, URI); 2134 » » » (const char *) xmlBufContent(ret->input->buffer),
2135 4, URI);
2100 ret->base = 0; 2136 ret->base = 0;
2101 ret->cur = 4; 2137 ret->cur = 4;
2102 } else { 2138 } else {
2103 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, NULL, 0, URI); 2139 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, NULL, 0, URI);
2104 ret->base = 0; 2140 ret->base = 0;
2105 ret->cur = 0; 2141 ret->cur = 0;
2106 } 2142 }
2107 2143
2108 if (ret->ctxt == NULL) { 2144 if (ret->ctxt == NULL) {
2109 xmlGenericError(xmlGenericErrorContext, 2145 xmlGenericError(xmlGenericErrorContext,
2110 "xmlNewTextReader : malloc failed\n"); 2146 "xmlNewTextReader : malloc failed\n");
2111 » xmlBufferFree(ret->buffer); 2147 » xmlBufFree(ret->buffer);
2112 xmlFree(ret->sax); 2148 xmlFree(ret->sax);
2113 xmlFree(ret); 2149 xmlFree(ret);
2114 return(NULL); 2150 return(NULL);
2115 } 2151 }
2116 ret->ctxt->parseMode = XML_PARSE_READER; 2152 ret->ctxt->parseMode = XML_PARSE_READER;
2117 ret->ctxt->_private = ret; 2153 ret->ctxt->_private = ret;
2118 ret->ctxt->linenumbers = 1; 2154 ret->ctxt->linenumbers = 1;
2119 ret->ctxt->dictNames = 1; 2155 ret->ctxt->dictNames = 1;
2120 ret->allocs = XML_TEXTREADER_CTXT; 2156 ret->allocs = XML_TEXTREADER_CTXT;
2121 /* 2157 /*
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 void 2210 void
2175 xmlFreeTextReader(xmlTextReaderPtr reader) { 2211 xmlFreeTextReader(xmlTextReaderPtr reader) {
2176 if (reader == NULL) 2212 if (reader == NULL)
2177 return; 2213 return;
2178 #ifdef LIBXML_SCHEMAS_ENABLED 2214 #ifdef LIBXML_SCHEMAS_ENABLED
2179 if (reader->rngSchemas != NULL) { 2215 if (reader->rngSchemas != NULL) {
2180 xmlRelaxNGFree(reader->rngSchemas); 2216 xmlRelaxNGFree(reader->rngSchemas);
2181 reader->rngSchemas = NULL; 2217 reader->rngSchemas = NULL;
2182 } 2218 }
2183 if (reader->rngValidCtxt != NULL) { 2219 if (reader->rngValidCtxt != NULL) {
2184 » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 2220 » if (! reader->rngPreserveCtxt)
2221 » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
2185 reader->rngValidCtxt = NULL; 2222 reader->rngValidCtxt = NULL;
2186 } 2223 }
2187 if (reader->xsdPlug != NULL) { 2224 if (reader->xsdPlug != NULL) {
2188 xmlSchemaSAXUnplug(reader->xsdPlug); 2225 xmlSchemaSAXUnplug(reader->xsdPlug);
2189 reader->xsdPlug = NULL; 2226 reader->xsdPlug = NULL;
2190 } 2227 }
2191 if (reader->xsdValidCtxt != NULL) { 2228 if (reader->xsdValidCtxt != NULL) {
2192 if (! reader->xsdPreserveCtxt) 2229 if (! reader->xsdPreserveCtxt)
2193 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); 2230 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);
2194 reader->xsdValidCtxt = NULL; 2231 reader->xsdValidCtxt = NULL;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 reader->ctxt->vctxt.vstateMax = 0; 2267 reader->ctxt->vctxt.vstateMax = 0;
2231 } 2268 }
2232 if (reader->allocs & XML_TEXTREADER_CTXT) 2269 if (reader->allocs & XML_TEXTREADER_CTXT)
2233 xmlFreeParserCtxt(reader->ctxt); 2270 xmlFreeParserCtxt(reader->ctxt);
2234 } 2271 }
2235 if (reader->sax != NULL) 2272 if (reader->sax != NULL)
2236 xmlFree(reader->sax); 2273 xmlFree(reader->sax);
2237 if ((reader->input != NULL) && (reader->allocs & XML_TEXTREADER_INPUT)) 2274 if ((reader->input != NULL) && (reader->allocs & XML_TEXTREADER_INPUT))
2238 xmlFreeParserInputBuffer(reader->input); 2275 xmlFreeParserInputBuffer(reader->input);
2239 if (reader->buffer != NULL) 2276 if (reader->buffer != NULL)
2240 xmlBufferFree(reader->buffer); 2277 xmlBufFree(reader->buffer);
2241 if (reader->entTab != NULL) 2278 if (reader->entTab != NULL)
2242 xmlFree(reader->entTab); 2279 xmlFree(reader->entTab);
2243 if (reader->dict != NULL) 2280 if (reader->dict != NULL)
2244 xmlDictFree(reader->dict); 2281 xmlDictFree(reader->dict);
2245 xmlFree(reader); 2282 xmlFree(reader);
2246 } 2283 }
2247 2284
2248 /************************************************************************ 2285 /************************************************************************
2249 * * 2286 * *
2250 * Methods for XmlTextReader * 2287 * Methods for XmlTextReader *
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3578 case XML_NAMESPACE_DECL: 3615 case XML_NAMESPACE_DECL:
3579 return(((xmlNsPtr) node)->href); 3616 return(((xmlNsPtr) node)->href);
3580 case XML_ATTRIBUTE_NODE:{ 3617 case XML_ATTRIBUTE_NODE:{
3581 xmlAttrPtr attr = (xmlAttrPtr) node; 3618 xmlAttrPtr attr = (xmlAttrPtr) node;
3582 3619
3583 if ((attr->children != NULL) && 3620 if ((attr->children != NULL) &&
3584 (attr->children->type == XML_TEXT_NODE) && 3621 (attr->children->type == XML_TEXT_NODE) &&
3585 (attr->children->next == NULL)) 3622 (attr->children->next == NULL))
3586 return(attr->children->content); 3623 return(attr->children->content);
3587 else { 3624 else {
3588 if (reader->buffer == NULL)
3589 reader->buffer = xmlBufferCreateSize(100);
3590 if (reader->buffer == NULL) { 3625 if (reader->buffer == NULL) {
3591 » » xmlGenericError(xmlGenericErrorContext, 3626 » » reader->buffer = xmlBufCreateSize(100);
3592 » » » » "xmlTextReaderSetup : malloc failed\n"); 3627 if (reader->buffer == NULL) {
3593 » » return (NULL); 3628 xmlGenericError(xmlGenericErrorContext,
3594 » » } 3629 "xmlTextReaderSetup : malloc failed\n");
3595 » reader->buffer->use = 0; 3630 return (NULL);
3596 » xmlNodeBufGetContent(reader->buffer, node); 3631 }
3597 » » return(reader->buffer->content); 3632 } else
3633 xmlBufEmpty(reader->buffer);
3634 » xmlBufGetNodeContent(reader->buffer, node);
3635 » » return(xmlBufContent(reader->buffer));
3598 } 3636 }
3599 break; 3637 break;
3600 } 3638 }
3601 case XML_TEXT_NODE: 3639 case XML_TEXT_NODE:
3602 case XML_CDATA_SECTION_NODE: 3640 case XML_CDATA_SECTION_NODE:
3603 case XML_PI_NODE: 3641 case XML_PI_NODE:
3604 case XML_COMMENT_NODE: 3642 case XML_COMMENT_NODE:
3605 return(node->content); 3643 return(node->content);
3606 default: 3644 default:
3607 break; 3645 break;
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 int 4120 int
4083 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) { 4121 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) {
4084 if (reader == NULL) 4122 if (reader == NULL)
4085 return(-1); 4123 return(-1);
4086 if (schema == NULL) { 4124 if (schema == NULL) {
4087 if (reader->rngSchemas != NULL) { 4125 if (reader->rngSchemas != NULL) {
4088 xmlRelaxNGFree(reader->rngSchemas); 4126 xmlRelaxNGFree(reader->rngSchemas);
4089 reader->rngSchemas = NULL; 4127 reader->rngSchemas = NULL;
4090 } 4128 }
4091 if (reader->rngValidCtxt != NULL) { 4129 if (reader->rngValidCtxt != NULL) {
4092 » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 4130 » if (! reader->rngPreserveCtxt)
4131 » » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
4093 reader->rngValidCtxt = NULL; 4132 reader->rngValidCtxt = NULL;
4094 } 4133 }
4134 reader->rngPreserveCtxt = 0;
4095 return(0); 4135 return(0);
4096 } 4136 }
4097 if (reader->mode != XML_TEXTREADER_MODE_INITIAL) 4137 if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
4098 return(-1); 4138 return(-1);
4099 if (reader->rngSchemas != NULL) { 4139 if (reader->rngSchemas != NULL) {
4100 xmlRelaxNGFree(reader->rngSchemas); 4140 xmlRelaxNGFree(reader->rngSchemas);
4101 reader->rngSchemas = NULL; 4141 reader->rngSchemas = NULL;
4102 } 4142 }
4103 if (reader->rngValidCtxt != NULL) { 4143 if (reader->rngValidCtxt != NULL) {
4104 » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 4144 » if (! reader->rngPreserveCtxt)
4145 » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
4105 reader->rngValidCtxt = NULL; 4146 reader->rngValidCtxt = NULL;
4106 } 4147 }
4148 reader->rngPreserveCtxt = 0;
4107 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema); 4149 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema);
4108 if (reader->rngValidCtxt == NULL) 4150 if (reader->rngValidCtxt == NULL)
4109 return(-1); 4151 return(-1);
4110 if (reader->errorFunc != NULL) { 4152 if (reader->errorFunc != NULL) {
4111 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, 4153 xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
4112 xmlTextReaderValidityErrorRelay, 4154 xmlTextReaderValidityErrorRelay,
4113 xmlTextReaderValidityWarningRelay, 4155 xmlTextReaderValidityWarningRelay,
4114 reader); 4156 reader);
4115 } 4157 }
4116 if (reader->sErrorFunc != NULL) { 4158 if (reader->sErrorFunc != NULL) {
4117 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4159 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4118 xmlTextReaderValidityStructuredRelay, 4160 xmlTextReaderValidityStructuredRelay,
4119 reader); 4161 reader);
4120 } 4162 }
4121 reader->rngValidErrors = 0; 4163 reader->rngValidErrors = 0;
4122 reader->rngFullNode = NULL; 4164 reader->rngFullNode = NULL;
4123 reader->validate = XML_TEXTREADER_VALIDATE_RNG; 4165 reader->validate = XML_TEXTREADER_VALIDATE_RNG;
4124 return(0); 4166 return(0);
4125 } 4167 }
4126 4168
4127 /** 4169 /**
4170 * xmlTextReaderLocator:
4171 * @ctx: the xmlTextReaderPtr used
4172 * @file: returned file information
4173 * @line: returned line information
4174 *
4175 * Internal locator function for the readers
4176 *
4177 * Returns 0 in case the Schema validation could be (des)activated and
4178 * -1 in case of error.
4179 */
4180 static int
4181 xmlTextReaderLocator(void *ctx, const char **file, unsigned long *line) {
4182 xmlTextReaderPtr reader;
4183
4184 if ((ctx == NULL) || ((file == NULL) && (line == NULL)))
4185 return(-1);
4186
4187 if (file != NULL)
4188 *file = NULL;
4189 if (line != NULL)
4190 *line = 0;
4191
4192 reader = (xmlTextReaderPtr) ctx;
4193 if ((reader->ctxt != NULL) && (reader->ctxt->input != NULL)) {
4194 if (file != NULL)
4195 *file = reader->ctxt->input->filename;
4196 if (line != NULL)
4197 *line = reader->ctxt->input->line;
4198 return(0);
4199 }
4200 if (reader->node != NULL) {
4201 long res;
4202 int ret = 0;
4203
4204 if (line != NULL) {
4205 res = xmlGetLineNo(reader->node);
4206 if (res > 0)
4207 *line = (unsigned long) res;
4208 else
4209 ret = -1;
4210 }
4211 if (file != NULL) {
4212 xmlDocPtr doc = reader->node->doc;
4213 if ((doc != NULL) && (doc->URL != NULL))
4214 *file = (const char *) doc->URL;
4215 else
4216 ret = -1;
4217 }
4218 return(ret);
4219 }
4220 return(-1);
4221 }
4222
4223 /**
4128 * xmlTextReaderSetSchema: 4224 * xmlTextReaderSetSchema:
4129 * @reader: the xmlTextReaderPtr used 4225 * @reader: the xmlTextReaderPtr used
4130 * @schema: a precompiled Schema schema 4226 * @schema: a precompiled Schema schema
4131 * 4227 *
4132 * Use XSD Schema to validate the document as it is processed. 4228 * Use XSD Schema to validate the document as it is processed.
4133 * Activation is only possible before the first Read(). 4229 * Activation is only possible before the first Read().
4134 * if @schema is NULL, then Schema validation is desactivated. 4230 * if @schema is NULL, then Schema validation is desactivated.
4135 @ The @schema should not be freed until the reader is deallocated 4231 @ The @schema should not be freed until the reader is deallocated
4136 * or its use has been deactivated. 4232 * or its use has been deactivated.
4137 * 4233 *
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4184 reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt, 4280 reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt,
4185 &(reader->ctxt->sax), 4281 &(reader->ctxt->sax),
4186 &(reader->ctxt->userData)); 4282 &(reader->ctxt->userData));
4187 if (reader->xsdPlug == NULL) { 4283 if (reader->xsdPlug == NULL) {
4188 xmlSchemaFree(reader->xsdSchemas); 4284 xmlSchemaFree(reader->xsdSchemas);
4189 reader->xsdSchemas = NULL; 4285 reader->xsdSchemas = NULL;
4190 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); 4286 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);
4191 reader->xsdValidCtxt = NULL; 4287 reader->xsdValidCtxt = NULL;
4192 return(-1); 4288 return(-1);
4193 } 4289 }
4290 xmlSchemaValidateSetLocator(reader->xsdValidCtxt,
4291 xmlTextReaderLocator,
4292 (void *) reader);
4293
4194 if (reader->errorFunc != NULL) { 4294 if (reader->errorFunc != NULL) {
4195 xmlSchemaSetValidErrors(reader->xsdValidCtxt, 4295 xmlSchemaSetValidErrors(reader->xsdValidCtxt,
4196 xmlTextReaderValidityErrorRelay, 4296 xmlTextReaderValidityErrorRelay,
4197 xmlTextReaderValidityWarningRelay, 4297 xmlTextReaderValidityWarningRelay,
4198 reader); 4298 reader);
4199 } 4299 }
4200 if (reader->sErrorFunc != NULL) { 4300 if (reader->sErrorFunc != NULL) {
4201 xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, 4301 xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt,
4202 xmlTextReaderValidityStructuredRelay, 4302 xmlTextReaderValidityStructuredRelay,
4203 reader); 4303 reader);
4204 } 4304 }
4205 reader->xsdValidErrors = 0; 4305 reader->xsdValidErrors = 0;
4206 reader->validate = XML_TEXTREADER_VALIDATE_XSD; 4306 reader->validate = XML_TEXTREADER_VALIDATE_XSD;
4207 return(0); 4307 return(0);
4208 } 4308 }
4209 4309
4210 /** 4310 /**
4211 * xmlTextReaderRelaxNGValidate: 4311 * xmlTextReaderRelaxNGValidateInternal:
4212 * @reader: the xmlTextReaderPtr used 4312 * @reader: the xmlTextReaderPtr used
4213 * @rng: the path to a RelaxNG schema or NULL 4313 * @rng: the path to a RelaxNG schema or NULL
4314 * @ctxt: the RelaxNG schema validation context or NULL
4315 * @options: options (not yet used)
4214 * 4316 *
4215 * Use RelaxNG to validate the document as it is processed. 4317 * Use RelaxNG to validate the document as it is processed.
4216 * Activation is only possible before the first Read(). 4318 * Activation is only possible before the first Read().
4217 * if @rng is NULL, then RelaxNG validation is deactivated. 4319 * If both @rng and @ctxt are NULL, then RelaxNG validation is deactivated.
4218 * 4320 *
4219 * Returns 0 in case the RelaxNG validation could be (de)activated and 4321 * Returns 0 in case the RelaxNG validation could be (de)activated and
4220 * -1 in case of error. 4322 *» -1 in case of error.
4221 */ 4323 */
4222 int 4324 static int
4223 xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { 4325 xmlTextReaderRelaxNGValidateInternal(xmlTextReaderPtr reader,
4224 xmlRelaxNGParserCtxtPtr ctxt; 4326 » » » » const char *rng,
4327 » » » » xmlRelaxNGValidCtxtPtr ctxt,
4328 » » » » int options ATTRIBUTE_UNUSED)
4329 {
4330 if (reader == NULL)
4331 » return(-1);
4225 4332
4226 if (reader == NULL) 4333 if ((rng != NULL) && (ctxt != NULL))
4227 return(-1); 4334 » return (-1);
4228 4335
4229 if (rng == NULL) { 4336 if (((rng != NULL) || (ctxt != NULL)) &&
4230 if (reader->rngValidCtxt != NULL) { 4337 » ((reader->mode != XML_TEXTREADER_MODE_INITIAL) ||
4338 » (reader->ctxt == NULL)))
4339 » return(-1);
4340
4341 /* Cleanup previous validation stuff. */
4342 if (reader->rngValidCtxt != NULL) {
4343 » if ( !reader->rngPreserveCtxt)
4231 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 4344 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
4232 » reader->rngValidCtxt = NULL; 4345 » reader->rngValidCtxt = NULL;
4233 }
4234 if (reader->rngSchemas != NULL) {
4235 » xmlRelaxNGFree(reader->rngSchemas);
4236 » reader->rngSchemas = NULL;
4237 » }
4238 » return(0);
4239 } 4346 }
4240 if (reader->mode != XML_TEXTREADER_MODE_INITIAL) 4347 reader->rngPreserveCtxt = 0;
4241 » return(-1);
4242 if (reader->rngSchemas != NULL) { 4348 if (reader->rngSchemas != NULL) {
4243 xmlRelaxNGFree(reader->rngSchemas); 4349 xmlRelaxNGFree(reader->rngSchemas);
4244 reader->rngSchemas = NULL; 4350 reader->rngSchemas = NULL;
4245 } 4351 }
4246 if (reader->rngValidCtxt != NULL) { 4352
4247 » xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 4353 if ((rng == NULL) && (ctxt == NULL)) {
4248 » reader->rngValidCtxt = NULL; 4354 » /* We just want to deactivate the validation, so get out. */
4355 » return(0);
4249 } 4356 }
4250 ctxt = xmlRelaxNGNewParserCtxt(rng); 4357
4251 if (reader->errorFunc != NULL) { 4358
4252 » xmlRelaxNGSetParserErrors(ctxt, 4359 if (rng != NULL) {
4253 » » » xmlTextReaderValidityErrorRelay, 4360 » xmlRelaxNGParserCtxtPtr pctxt;
4254 » » » xmlTextReaderValidityWarningRelay, 4361 » /* Parse the schema and create validation environment. */
4255 » » » reader); 4362
4363 » pctxt = xmlRelaxNGNewParserCtxt(rng);
4364 » if (reader->errorFunc != NULL) {
4365 » xmlRelaxNGSetParserErrors(pctxt,
4366 » » xmlTextReaderValidityErrorRelay,
4367 » » xmlTextReaderValidityWarningRelay,
4368 » » reader);
4369 » }
4370 » if (reader->sErrorFunc != NULL) {
4371 » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4372 » » xmlTextReaderValidityStructuredRelay,
4373 » » reader);
4374 » }
4375 » reader->rngSchemas = xmlRelaxNGParse(pctxt);
4376 » xmlRelaxNGFreeParserCtxt(pctxt);
4377 » if (reader->rngSchemas == NULL)
4378 » return(-1);
4379 » reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas);
4380 » if (reader->rngValidCtxt == NULL) {
4381 » xmlRelaxNGFree(reader->rngSchemas);
4382 » reader->rngSchemas = NULL;
4383 » return(-1);
4384 » }
4385 } else {
4386 » /* Use the given validation context. */
4387 » reader->rngValidCtxt = ctxt;
4388 » reader->rngPreserveCtxt = 1;
4256 } 4389 }
4257 if (reader->sErrorFunc != NULL) { 4390 /*
4258 » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4391 * Redirect the validation context's error channels to use
4259 » » » xmlTextReaderValidityStructuredRelay, 4392 * the reader channels.
4260 » » » reader); 4393 * TODO: In case the user provides the validation context we
4261 } 4394 *» could make this redirection optional.
4262 reader->rngSchemas = xmlRelaxNGParse(ctxt); 4395 */
4263 xmlRelaxNGFreeParserCtxt(ctxt);
4264 if (reader->rngSchemas == NULL)
4265 return(-1);
4266 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas);
4267 if (reader->rngValidCtxt == NULL) {
4268 » xmlRelaxNGFree(reader->rngSchemas);
4269 » reader->rngSchemas = NULL;
4270 return(-1);
4271 }
4272 if (reader->errorFunc != NULL) { 4396 if (reader->errorFunc != NULL) {
4273 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, 4397 xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
4274 xmlTextReaderValidityErrorRelay, 4398 xmlTextReaderValidityErrorRelay,
4275 xmlTextReaderValidityWarningRelay, 4399 xmlTextReaderValidityWarningRelay,
4276 reader); 4400 reader);
4277 } 4401 }
4278 if (reader->sErrorFunc != NULL) { 4402 if (reader->sErrorFunc != NULL) {
4279 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4403 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4280 xmlTextReaderValidityStructuredRelay, 4404 xmlTextReaderValidityStructuredRelay,
4281 reader); 4405 reader);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
4374 reader->xsdPreserveCtxt = 1; 4498 reader->xsdPreserveCtxt = 1;
4375 reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt, 4499 reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt,
4376 &(reader->ctxt->sax), 4500 &(reader->ctxt->sax),
4377 &(reader->ctxt->userData)); 4501 &(reader->ctxt->userData));
4378 if (reader->xsdPlug == NULL) { 4502 if (reader->xsdPlug == NULL) {
4379 reader->xsdValidCtxt = NULL; 4503 reader->xsdValidCtxt = NULL;
4380 reader->xsdPreserveCtxt = 0; 4504 reader->xsdPreserveCtxt = 0;
4381 return(-1); 4505 return(-1);
4382 } 4506 }
4383 } 4507 }
4508 xmlSchemaValidateSetLocator(reader->xsdValidCtxt,
4509 xmlTextReaderLocator,
4510 (void *) reader);
4384 /* 4511 /*
4385 * Redirect the validation context's error channels to use 4512 * Redirect the validation context's error channels to use
4386 * the reader channels. 4513 * the reader channels.
4387 * TODO: In case the user provides the validation context we 4514 * TODO: In case the user provides the validation context we
4388 * could make this redirection optional. 4515 * could make this redirection optional.
4389 */ 4516 */
4390 if (reader->errorFunc != NULL) { 4517 if (reader->errorFunc != NULL) {
4391 xmlSchemaSetValidErrors(reader->xsdValidCtxt, 4518 xmlSchemaSetValidErrors(reader->xsdValidCtxt,
4392 xmlTextReaderValidityErrorRelay, 4519 xmlTextReaderValidityErrorRelay,
4393 xmlTextReaderValidityWarningRelay, 4520 xmlTextReaderValidityWarningRelay,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4434 * If @xsd is NULL, then XML Schema validation is deactivated. 4561 * If @xsd is NULL, then XML Schema validation is deactivated.
4435 * 4562 *
4436 * Returns 0 in case the schemas validation could be (de)activated and 4563 * Returns 0 in case the schemas validation could be (de)activated and
4437 * -1 in case of error. 4564 * -1 in case of error.
4438 */ 4565 */
4439 int 4566 int
4440 xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, const char *xsd) 4567 xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, const char *xsd)
4441 { 4568 {
4442 return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0)); 4569 return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0));
4443 } 4570 }
4571
4572 /**
4573 * xmlTextReaderRelaxNGValidateCtxt:
4574 * @reader: the xmlTextReaderPtr used
4575 * @ctxt: the RelaxNG schema validation context or NULL
4576 * @options: options (not used yet)
4577 *
4578 * Use RelaxNG schema context to validate the document as it is processed.
4579 * Activation is only possible before the first Read().
4580 * If @ctxt is NULL, then RelaxNG schema validation is deactivated.
4581 *
4582 * Returns 0 in case the schemas validation could be (de)activated and
4583 * -1 in case of error.
4584 */
4585 int
4586 xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader,
4587 xmlRelaxNGValidCtxtPtr ctxt,
4588 int options)
4589 {
4590 return(xmlTextReaderRelaxNGValidateInternal(reader, NULL, ctxt, options));
4591 }
4592
4593 /**
4594 * xmlTextReaderRelaxNGValidate:
4595 * @reader: the xmlTextReaderPtr used
4596 * @rng: the path to a RelaxNG schema or NULL
4597 *
4598 * Use RelaxNG schema to validate the document as it is processed.
4599 * Activation is only possible before the first Read().
4600 * If @rng is NULL, then RelaxNG schema validation is deactivated.
4601 *
4602 * Returns 0 in case the schemas validation could be (de)activated and
4603 * -1 in case of error.
4604 */
4605 int
4606 xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng)
4607 {
4608 return(xmlTextReaderRelaxNGValidateInternal(reader, rng, NULL, 0));
4609 }
4610
4444 #endif 4611 #endif
4445 4612
4446 /** 4613 /**
4447 * xmlTextReaderIsNamespaceDecl: 4614 * xmlTextReaderIsNamespaceDecl:
4448 * @reader: the xmlTextReaderPtr used 4615 * @reader: the xmlTextReaderPtr used
4449 * 4616 *
4450 * Determine whether the current node is a namespace declaration 4617 * Determine whether the current node is a namespace declaration
4451 * rather than a regular attribute. 4618 * rather than a regular attribute.
4452 * 4619 *
4453 * Returns 1 if the current node is a namespace declaration, 0 if it 4620 * Returns 1 if the current node is a namespace declaration, 0 if it
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
4951 (reader->allocs & XML_TEXTREADER_INPUT)) { 5118 (reader->allocs & XML_TEXTREADER_INPUT)) {
4952 xmlFreeParserInputBuffer(reader->input); 5119 xmlFreeParserInputBuffer(reader->input);
4953 reader->input = NULL; 5120 reader->input = NULL;
4954 reader->allocs -= XML_TEXTREADER_INPUT; 5121 reader->allocs -= XML_TEXTREADER_INPUT;
4955 } 5122 }
4956 if (input != NULL) { 5123 if (input != NULL) {
4957 reader->input = input; 5124 reader->input = input;
4958 reader->allocs |= XML_TEXTREADER_INPUT; 5125 reader->allocs |= XML_TEXTREADER_INPUT;
4959 } 5126 }
4960 if (reader->buffer == NULL) 5127 if (reader->buffer == NULL)
4961 reader->buffer = xmlBufferCreateSize(100); 5128 reader->buffer = xmlBufCreateSize(100);
4962 if (reader->buffer == NULL) { 5129 if (reader->buffer == NULL) {
4963 xmlGenericError(xmlGenericErrorContext, 5130 xmlGenericError(xmlGenericErrorContext,
4964 "xmlTextReaderSetup : malloc failed\n"); 5131 "xmlTextReaderSetup : malloc failed\n");
4965 return (-1); 5132 return (-1);
4966 } 5133 }
4967 if (reader->sax == NULL) 5134 if (reader->sax == NULL)
4968 reader->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler)); 5135 reader->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler));
4969 if (reader->sax == NULL) { 5136 if (reader->sax == NULL) {
4970 xmlGenericError(xmlGenericErrorContext, 5137 xmlGenericError(xmlGenericErrorContext,
4971 "xmlTextReaderSetup : malloc failed\n"); 5138 "xmlTextReaderSetup : malloc failed\n");
(...skipping 20 matching lines...) Expand all
4992 reader->characters = reader->sax->characters; 5159 reader->characters = reader->sax->characters;
4993 reader->sax->characters = xmlTextReaderCharacters; 5160 reader->sax->characters = xmlTextReaderCharacters;
4994 reader->sax->ignorableWhitespace = xmlTextReaderCharacters; 5161 reader->sax->ignorableWhitespace = xmlTextReaderCharacters;
4995 reader->cdataBlock = reader->sax->cdataBlock; 5162 reader->cdataBlock = reader->sax->cdataBlock;
4996 reader->sax->cdataBlock = xmlTextReaderCDataBlock; 5163 reader->sax->cdataBlock = xmlTextReaderCDataBlock;
4997 5164
4998 reader->mode = XML_TEXTREADER_MODE_INITIAL; 5165 reader->mode = XML_TEXTREADER_MODE_INITIAL;
4999 reader->node = NULL; 5166 reader->node = NULL;
5000 reader->curnode = NULL; 5167 reader->curnode = NULL;
5001 if (input != NULL) { 5168 if (input != NULL) {
5002 if (reader->input->buffer->use < 4) { 5169 if (xmlBufUse(reader->input->buffer) < 4) {
5003 xmlParserInputBufferRead(input, 4); 5170 xmlParserInputBufferRead(input, 4);
5004 } 5171 }
5005 if (reader->ctxt == NULL) { 5172 if (reader->ctxt == NULL) {
5006 if (reader->input->buffer->use >= 4) { 5173 if (xmlBufUse(reader->input->buffer) >= 4) {
5007 reader->ctxt = xmlCreatePushParserCtxt(reader->sax, NULL, 5174 reader->ctxt = xmlCreatePushParserCtxt(reader->sax, NULL,
5008 » » (const char *) reader->input->buffer->content, 4, URL); 5175 » » (const char *) xmlBufContent(reader->input->buffer),
5176 4, URL);
5009 reader->base = 0; 5177 reader->base = 0;
5010 reader->cur = 4; 5178 reader->cur = 4;
5011 } else { 5179 } else {
5012 reader->ctxt = 5180 reader->ctxt =
5013 xmlCreatePushParserCtxt(reader->sax, NULL, NULL, 0, URL); 5181 xmlCreatePushParserCtxt(reader->sax, NULL, NULL, 0, URL);
5014 reader->base = 0; 5182 reader->base = 0;
5015 reader->cur = 0; 5183 reader->cur = 0;
5016 } 5184 }
5017 } else { 5185 } else {
5018 xmlParserInputPtr inputStream; 5186 xmlParserInputPtr inputStream;
5019 xmlParserInputBufferPtr buf; 5187 xmlParserInputBufferPtr buf;
5020 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; 5188 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
5021 5189
5022 xmlCtxtReset(reader->ctxt); 5190 xmlCtxtReset(reader->ctxt);
5023 buf = xmlAllocParserInputBuffer(enc); 5191 buf = xmlAllocParserInputBuffer(enc);
5024 if (buf == NULL) return(-1); 5192 if (buf == NULL) return(-1);
5025 inputStream = xmlNewInputStream(reader->ctxt); 5193 inputStream = xmlNewInputStream(reader->ctxt);
5026 if (inputStream == NULL) { 5194 if (inputStream == NULL) {
5027 xmlFreeParserInputBuffer(buf); 5195 xmlFreeParserInputBuffer(buf);
5028 return(-1); 5196 return(-1);
5029 } 5197 }
5030 5198
5031 if (URL == NULL) 5199 if (URL == NULL)
5032 inputStream->filename = NULL; 5200 inputStream->filename = NULL;
5033 else 5201 else
5034 inputStream->filename = (char *) 5202 inputStream->filename = (char *)
5035 xmlCanonicPath((const xmlChar *) URL); 5203 xmlCanonicPath((const xmlChar *) URL);
5036 inputStream->buf = buf; 5204 inputStream->buf = buf;
5037 » inputStream->base = inputStream->buf->buffer->content; 5205 xmlBufResetInput(buf->buffer, inputStream);
5038 » inputStream->cur = inputStream->buf->buffer->content;
5039 » inputStream->end =
5040 &inputStream->buf->buffer->content[inputStream->buf->buffer->use];
5041 5206
5042 inputPush(reader->ctxt, inputStream); 5207 inputPush(reader->ctxt, inputStream);
5043 reader->cur = 0; 5208 reader->cur = 0;
5044 } 5209 }
5045 if (reader->ctxt == NULL) { 5210 if (reader->ctxt == NULL) {
5046 xmlGenericError(xmlGenericErrorContext, 5211 xmlGenericError(xmlGenericErrorContext,
5047 "xmlTextReaderSetup : malloc failed\n"); 5212 "xmlTextReaderSetup : malloc failed\n");
5048 return (-1); 5213 return (-1);
5049 } 5214 }
5050 } 5215 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
5318 int options) 5483 int options)
5319 { 5484 {
5320 xmlTextReaderPtr reader; 5485 xmlTextReaderPtr reader;
5321 xmlParserInputBufferPtr input; 5486 xmlParserInputBufferPtr input;
5322 5487
5323 if (ioread == NULL) 5488 if (ioread == NULL)
5324 return (NULL); 5489 return (NULL);
5325 5490
5326 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 5491 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
5327 XML_CHAR_ENCODING_NONE); 5492 XML_CHAR_ENCODING_NONE);
5328 if (input == NULL) 5493 if (input == NULL) {
5494 if (ioclose != NULL)
5495 ioclose(ioctx);
5329 return (NULL); 5496 return (NULL);
5497 }
5330 reader = xmlNewTextReader(input, URL); 5498 reader = xmlNewTextReader(input, URL);
5331 if (reader == NULL) { 5499 if (reader == NULL) {
5332 xmlFreeParserInputBuffer(input); 5500 xmlFreeParserInputBuffer(input);
5333 return (NULL); 5501 return (NULL);
5334 } 5502 }
5335 reader->allocs |= XML_TEXTREADER_INPUT; 5503 reader->allocs |= XML_TEXTREADER_INPUT;
5336 xmlTextReaderSetup(reader, NULL, URL, encoding, options); 5504 xmlTextReaderSetup(reader, NULL, URL, encoding, options);
5337 return (reader); 5505 return (reader);
5338 } 5506 }
5339 5507
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
5536 { 5704 {
5537 xmlParserInputBufferPtr input; 5705 xmlParserInputBufferPtr input;
5538 5706
5539 if (ioread == NULL) 5707 if (ioread == NULL)
5540 return (-1); 5708 return (-1);
5541 if (reader == NULL) 5709 if (reader == NULL)
5542 return (-1); 5710 return (-1);
5543 5711
5544 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 5712 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
5545 XML_CHAR_ENCODING_NONE); 5713 XML_CHAR_ENCODING_NONE);
5546 if (input == NULL) 5714 if (input == NULL) {
5715 if (ioclose != NULL)
5716 ioclose(ioctx);
5547 return (-1); 5717 return (-1);
5718 }
5548 return (xmlTextReaderSetup(reader, input, URL, encoding, options)); 5719 return (xmlTextReaderSetup(reader, input, URL, encoding, options));
5549 } 5720 }
5721
5550 /************************************************************************ 5722 /************************************************************************
5551 * * 5723 * *
5552 * Utilities * 5724 * Utilities *
5553 * * 5725 * *
5554 ************************************************************************/ 5726 ************************************************************************/
5555 #ifdef NOT_USED_YET 5727 #ifdef NOT_USED_YET
5556 5728
5557 /** 5729 /**
5558 * xmlBase64Decode: 5730 * xmlBase64Decode:
5559 * @in: the input buffer 5731 * @in: the input buffer
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
5751 printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, 5923 printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons,
5752 prod, output3); 5924 prod, output3);
5753 return (0); 5925 return (0);
5754 5926
5755 } 5927 }
5756 #endif 5928 #endif
5757 #endif /* NOT_USED_YET */ 5929 #endif /* NOT_USED_YET */
5758 #define bottom_xmlreader 5930 #define bottom_xmlreader
5759 #include "elfgcchack.h" 5931 #include "elfgcchack.h"
5760 #endif /* LIBXML_READER_ENABLED */ 5932 #endif /* LIBXML_READER_ENABLED */
OLDNEW
« no previous file with comments | « third_party/libxml/src/xmlmodule.c ('k') | third_party/libxml/src/xmlregexp.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698