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

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

Issue 2951008: Update libxml to 2.7.7. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 5 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
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
11 */ 11 */
12 12
13 /* 13 /*
14 * TODOs: 14 * TODOs:
(...skipping 22 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 #define MAX_ERR_MSG_SIZE 64000
48
49 /*
50 * The following VA_COPY was coded following an example in
51 * the Samba project. It may not be sufficient for some
52 * esoteric implementations of va_list (i.e. it may need
53 * something involving a memcpy) but (hopefully) will be
54 * sufficient for libxml2.
55 */
56 #ifndef VA_COPY
57 #ifdef HAVE_VA_COPY
58 #define VA_COPY(dest, src) va_copy(dest, src)
59 #else
60 #ifdef HAVE___VA_COPY
61 #define VA_COPY(dest,src) __va_copy(dest, src)
62 #else
63 #define VA_COPY(dest,src) (dest) = (src)
64 #endif
65 #endif
66 #endif
67
47 /* #define DEBUG_CALLBACKS */ 68 /* #define DEBUG_CALLBACKS */
48 /* #define DEBUG_READER */ 69 /* #define DEBUG_READER */
49 70
50 /** 71 /**
51 * TODO: 72 * TODO:
52 * 73 *
53 * macro to flag unimplemented blocks 74 * macro to flag unimplemented blocks
54 */ 75 */
55 #define TODO » » » » » » » » \ 76 #define TODO» » » » » » » » \
56 xmlGenericError(xmlGenericErrorContext, \ 77 xmlGenericError(xmlGenericErrorContext, \
57 "Unimplemented block at %s:%d\n", \ 78 "Unimplemented block at %s:%d\n", \
58 __FILE__, __LINE__); 79 __FILE__, __LINE__);
59 80
60 #ifdef DEBUG_READER 81 #ifdef DEBUG_READER
61 #define DUMP_READER xmlTextReaderDebug(reader); 82 #define DUMP_READER xmlTextReaderDebug(reader);
62 #else 83 #else
63 #define DUMP_READER 84 #define DUMP_READER
64 #endif 85 #endif
65 86
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 xmlTextReaderState state; 121 xmlTextReaderState state;
101 xmlParserCtxtPtr ctxt; /* the parser context */ 122 xmlParserCtxtPtr ctxt; /* the parser context */
102 xmlSAXHandlerPtr sax; /* the parser SAX callbacks */ 123 xmlSAXHandlerPtr sax; /* the parser SAX callbacks */
103 xmlParserInputBufferPtr input; /* the input */ 124 xmlParserInputBufferPtr input; /* the input */
104 startElementSAXFunc startElement;/* initial SAX callbacks */ 125 startElementSAXFunc startElement;/* initial SAX callbacks */
105 endElementSAXFunc endElement; /* idem */ 126 endElementSAXFunc endElement; /* idem */
106 startElementNsSAX2Func startElementNs;/* idem */ 127 startElementNsSAX2Func startElementNs;/* idem */
107 endElementNsSAX2Func endElementNs; /* idem */ 128 endElementNsSAX2Func endElementNs; /* idem */
108 charactersSAXFunc characters; 129 charactersSAXFunc characters;
109 cdataBlockSAXFunc cdataBlock; 130 cdataBlockSAXFunc cdataBlock;
110 unsigned int » » base;» /* base of the segment in the input */ 131 unsigned int» » base;» /* base of the segment in the input */
111 unsigned int » » cur;» /* current position in the input */ 132 unsigned int» » cur;» /* current position in the input */
112 xmlNodePtr node; /* current node */ 133 xmlNodePtr node; /* current node */
113 xmlNodePtr curnode;/* current attribute node */ 134 xmlNodePtr curnode;/* current attribute node */
114 int depth; /* depth of the current node */ 135 int depth; /* depth of the current node */
115 xmlNodePtr faketext;/* fake xmlNs chld */ 136 xmlNodePtr faketext;/* fake xmlNs chld */
116 int preserve;/* preserve the resulting document */ 137 int preserve;/* preserve the resulting document */
117 xmlBufferPtr buffer; /* used to return const xmlChar * */ 138 xmlBufferPtr buffer; /* used to return const xmlChar * */
118 xmlDictPtr dict; /* the context dictionnary */ 139 xmlDictPtr dict; /* the context dictionnary */
119 140
120 /* entity stack when traversing entities content */ 141 /* entity stack when traversing entities content */
121 xmlNodePtr ent; /* Current Entity Ref Node */ 142 xmlNodePtr ent; /* Current Entity Ref Node */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 * * 200 * *
180 ************************************************************************/ 201 ************************************************************************/
181 /** 202 /**
182 * DICT_FREE: 203 * DICT_FREE:
183 * @str: a string 204 * @str: a string
184 * 205 *
185 * Free a string if it is not owned by the "dict" dictionnary in the 206 * Free a string if it is not owned by the "dict" dictionnary in the
186 * current scope 207 * current scope
187 */ 208 */
188 #define DICT_FREE(str) \ 209 #define DICT_FREE(str) \
189 » if ((str) && ((!dict) || » » » » \ 210 » if ((str) && ((!dict) ||» » » » \
190 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ 211 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \
191 xmlFree((char *)(str)); 212 xmlFree((char *)(str));
192 213
193 static void xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur); 214 static void xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur);
194 static void xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur); 215 static void xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur);
195 216
196 /** 217 /**
197 * xmlFreeID: 218 * xmlFreeID:
198 * @not: A id 219 * @not: A id
199 * 220 *
(...skipping 24 matching lines...) Expand all
224 */ 245 */
225 static int 246 static int
226 xmlTextReaderRemoveID(xmlDocPtr doc, xmlAttrPtr attr) { 247 xmlTextReaderRemoveID(xmlDocPtr doc, xmlAttrPtr attr) {
227 xmlIDTablePtr table; 248 xmlIDTablePtr table;
228 xmlIDPtr id; 249 xmlIDPtr id;
229 xmlChar *ID; 250 xmlChar *ID;
230 251
231 if (doc == NULL) return(-1); 252 if (doc == NULL) return(-1);
232 if (attr == NULL) return(-1); 253 if (attr == NULL) return(-1);
233 table = (xmlIDTablePtr) doc->ids; 254 table = (xmlIDTablePtr) doc->ids;
234 if (table == NULL) 255 if (table == NULL)
235 return(-1); 256 return(-1);
236 257
237 ID = xmlNodeListGetString(doc, attr->children, 1); 258 ID = xmlNodeListGetString(doc, attr->children, 1);
238 if (ID == NULL) 259 if (ID == NULL)
239 return(-1); 260 return(-1);
240 id = xmlHashLookup(table, ID); 261 id = xmlHashLookup(table, ID);
241 xmlFree(ID); 262 xmlFree(ID);
242 if (id == NULL || id->attr != attr) { 263 if (id == NULL || id->attr != attr) {
243 return(-1); 264 return(-1);
244 } 265 }
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 reader->state = oldstate; 835 reader->state = oldstate;
815 if ((oldstate != XML_TEXTREADER_START) || 836 if ((oldstate != XML_TEXTREADER_START) ||
816 (reader->ctxt->myDoc != NULL)) 837 (reader->ctxt->myDoc != NULL))
817 return(val); 838 return(val);
818 } else if (val == 0) { 839 } else if (val == 0) {
819 /* mark the end of the stream and process the remains */ 840 /* mark the end of the stream and process the remains */
820 reader->mode = XML_TEXTREADER_MODE_EOF; 841 reader->mode = XML_TEXTREADER_MODE_EOF;
821 break; 842 break;
822 } 843 }
823 844
824 » } else 845 » } else
825 break; 846 break;
826 } 847 }
827 /* 848 /*
828 * parse by block of CHUNK_SIZE bytes, various tests show that 849 * parse by block of CHUNK_SIZE bytes, various tests show that
829 * it's the best tradeoff at least on a 1.2GH Duron 850 * it's the best tradeoff at least on a 1.2GH Duron
830 */ 851 */
831 if (inbuf->use >= reader->cur + CHUNK_SIZE) { 852 if (inbuf->use >= reader->cur + CHUNK_SIZE) {
832 val = xmlParseChunk(reader->ctxt, 853 val = xmlParseChunk(reader->ctxt,
833 (const char *) &inbuf->content[reader->cur], 854 (const char *) &inbuf->content[reader->cur],
834 CHUNK_SIZE, 0); 855 CHUNK_SIZE, 0);
(...skipping 28 matching lines...) Expand all
863 } 884 }
864 885
865 /* 886 /*
866 * At the end of the stream signal that the work is done to the Push 887 * At the end of the stream signal that the work is done to the Push
867 * parser. 888 * parser.
868 */ 889 */
869 else if (reader->mode == XML_TEXTREADER_MODE_EOF) { 890 else if (reader->mode == XML_TEXTREADER_MODE_EOF) {
870 if (reader->state != XML_TEXTREADER_DONE) { 891 if (reader->state != XML_TEXTREADER_DONE) {
871 s = inbuf->use - reader->cur; 892 s = inbuf->use - reader->cur;
872 val = xmlParseChunk(reader->ctxt, 893 val = xmlParseChunk(reader->ctxt,
873 » » (const char *) &inbuf->content[reader->cur], 894 » » (const char *) &inbuf->content[reader->cur],
874 s, 1); 895 s, 1);
875 reader->cur = inbuf->use; 896 reader->cur = inbuf->use;
876 reader->state = XML_TEXTREADER_DONE; 897 reader->state = XML_TEXTREADER_DONE;
877 if ((val != 0) || (reader->ctxt->wellFormed == 0)) 898 if ((val != 0) || (reader->ctxt->wellFormed == 0))
878 return(-1); 899 return(-1);
879 } 900 }
880 } 901 }
881 reader->state = oldstate; 902 reader->state = oldstate;
882 return(0); 903 return(0);
883 } 904 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 xmlFree(qname); 1024 xmlFree(qname);
1004 } 1025 }
1005 } 1026 }
1006 #endif /* LIBXML_VALID_ENABLED */ 1027 #endif /* LIBXML_VALID_ENABLED */
1007 #ifdef LIBXML_SCHEMAS_ENABLED 1028 #ifdef LIBXML_SCHEMAS_ENABLED
1008 if ((reader->validate == XML_TEXTREADER_VALIDATE_RNG) && 1029 if ((reader->validate == XML_TEXTREADER_VALIDATE_RNG) &&
1009 (reader->rngValidCtxt != NULL)) { 1030 (reader->rngValidCtxt != NULL)) {
1010 int ret; 1031 int ret;
1011 1032
1012 if (reader->rngFullNode != NULL) { 1033 if (reader->rngFullNode != NULL) {
1013 » if (node == reader->rngFullNode) 1034 » if (node == reader->rngFullNode)
1014 reader->rngFullNode = NULL; 1035 reader->rngFullNode = NULL;
1015 return; 1036 return;
1016 } 1037 }
1017 ret = xmlRelaxNGValidatePopElement(reader->rngValidCtxt, 1038 ret = xmlRelaxNGValidatePopElement(reader->rngValidCtxt,
1018 reader->ctxt->myDoc, 1039 reader->ctxt->myDoc,
1019 node); 1040 node);
1020 if (ret != 1) 1041 if (ret != 1)
1021 reader->rngValidErrors++; 1042 reader->rngValidErrors++;
1022 } 1043 }
1023 #endif 1044 #endif
(...skipping 14 matching lines...) Expand all
1038 xmlParserCtxtPtr ctxt = reader->ctxt; 1059 xmlParserCtxtPtr ctxt = reader->ctxt;
1039 1060
1040 do { 1061 do {
1041 if (node->type == XML_ENTITY_REF_NODE) { 1062 if (node->type == XML_ENTITY_REF_NODE) {
1042 /* 1063 /*
1043 * Case where the underlying tree is not availble, lookup the entity 1064 * Case where the underlying tree is not availble, lookup the entity
1044 * and walk it. 1065 * and walk it.
1045 */ 1066 */
1046 if ((node->children == NULL) && (ctxt->sax != NULL) && 1067 if ((node->children == NULL) && (ctxt->sax != NULL) &&
1047 (ctxt->sax->getEntity != NULL)) { 1068 (ctxt->sax->getEntity != NULL)) {
1048 » » node->children = (xmlNodePtr) 1069 » » node->children = (xmlNodePtr)
1049 ctxt->sax->getEntity(ctxt, node->name); 1070 ctxt->sax->getEntity(ctxt, node->name);
1050 } 1071 }
1051 1072
1052 if ((node->children != NULL) && 1073 if ((node->children != NULL) &&
1053 (node->children->type == XML_ENTITY_DECL) && 1074 (node->children->type == XML_ENTITY_DECL) &&
1054 (node->children->children != NULL)) { 1075 (node->children->children != NULL)) {
1055 xmlTextReaderEntPush(reader, node); 1076 xmlTextReaderEntPush(reader, node);
1056 node = node->children->children; 1077 node = node->children->children;
1057 continue; 1078 continue;
1058 } else { 1079 } else {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 * 1249 *
1229 * Returns 1 if the node was read successfully, 0 if there is no more 1250 * Returns 1 if the node was read successfully, 0 if there is no more
1230 * nodes to read, or -1 in case of error 1251 * nodes to read, or -1 in case of error
1231 */ 1252 */
1232 int 1253 int
1233 xmlTextReaderRead(xmlTextReaderPtr reader) { 1254 xmlTextReaderRead(xmlTextReaderPtr reader) {
1234 int val, olddepth = 0; 1255 int val, olddepth = 0;
1235 xmlTextReaderState oldstate = XML_TEXTREADER_START; 1256 xmlTextReaderState oldstate = XML_TEXTREADER_START;
1236 xmlNodePtr oldnode = NULL; 1257 xmlNodePtr oldnode = NULL;
1237 1258
1238 1259
1239 if (reader == NULL) 1260 if (reader == NULL)
1240 return(-1); 1261 return(-1);
1241 reader->curnode = NULL; 1262 reader->curnode = NULL;
1242 if (reader->doc != NULL) 1263 if (reader->doc != NULL)
1243 return(xmlTextReaderReadTree(reader)); 1264 return(xmlTextReaderReadTree(reader));
1244 if (reader->ctxt == NULL) 1265 if (reader->ctxt == NULL)
1245 return(-1); 1266 return(-1);
1246 if (reader->ctxt->wellFormed != 1) 1267 if (reader->ctxt->wellFormed != 1)
1247 return(-1); 1268 return(-1);
1248 1269
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 reader->state = XML_TEXTREADER_DONE; 1429 reader->state = XML_TEXTREADER_DONE;
1409 if (val != 0) 1430 if (val != 0)
1410 return(-1); 1431 return(-1);
1411 } 1432 }
1412 reader->node = NULL; 1433 reader->node = NULL;
1413 reader->depth = -1; 1434 reader->depth = -1;
1414 1435
1415 /* 1436 /*
1416 * Cleanup of the old node 1437 * Cleanup of the old node
1417 */ 1438 */
1418 » if ((reader->preserves == 0) && 1439 » if ((oldnode != NULL) && (reader->preserves == 0) &&
1419 #ifdef LIBXML_XINCLUDE_ENABLED 1440 #ifdef LIBXML_XINCLUDE_ENABLED
1420 (reader->in_xinclude == 0) && 1441 (reader->in_xinclude == 0) &&
1421 #endif 1442 #endif
1422 (reader->entNr == 0) && 1443 (reader->entNr == 0) &&
1423 (oldnode->type != XML_DTD_NODE) && 1444 (oldnode->type != XML_DTD_NODE) &&
1424 ((oldnode->extra & NODE_IS_PRESERVED) == 0) && 1445 ((oldnode->extra & NODE_IS_PRESERVED) == 0) &&
1425 (reader->entNr == 0)) { 1446 (reader->entNr == 0)) {
1426 xmlUnlinkNode(oldnode); 1447 xmlUnlinkNode(oldnode);
1427 xmlTextReaderFreeNode(reader, oldnode); 1448 xmlTextReaderFreeNode(reader, oldnode);
1428 } 1449 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 /* 1482 /*
1462 * Handle XInclude if asked for 1483 * Handle XInclude if asked for
1463 */ 1484 */
1464 if ((reader->xinclude) && (reader->node != NULL) && 1485 if ((reader->xinclude) && (reader->node != NULL) &&
1465 (reader->node->type == XML_ELEMENT_NODE) && 1486 (reader->node->type == XML_ELEMENT_NODE) &&
1466 (reader->node->ns != NULL) && 1487 (reader->node->ns != NULL) &&
1467 ((xmlStrEqual(reader->node->ns->href, XINCLUDE_NS)) || 1488 ((xmlStrEqual(reader->node->ns->href, XINCLUDE_NS)) ||
1468 (xmlStrEqual(reader->node->ns->href, XINCLUDE_OLD_NS)))) { 1489 (xmlStrEqual(reader->node->ns->href, XINCLUDE_OLD_NS)))) {
1469 if (reader->xincctxt == NULL) { 1490 if (reader->xincctxt == NULL) {
1470 reader->xincctxt = xmlXIncludeNewContext(reader->ctxt->myDoc); 1491 reader->xincctxt = xmlXIncludeNewContext(reader->ctxt->myDoc);
1471 » xmlXIncludeSetFlags(reader->xincctxt, 1492 » xmlXIncludeSetFlags(reader->xincctxt,
1472 reader->parserFlags & (~XML_PARSE_NOXINCNODE)); 1493 reader->parserFlags & (~XML_PARSE_NOXINCNODE));
1473 } 1494 }
1474 /* 1495 /*
1475 * expand that node and process it 1496 * expand that node and process it
1476 */ 1497 */
1477 if (xmlTextReaderExpand(reader) == NULL) 1498 if (xmlTextReaderExpand(reader) == NULL)
1478 return -1; 1499 return -1;
1479 xmlXIncludeProcessNode(reader->xincctxt, reader->node); 1500 xmlXIncludeProcessNode(reader->xincctxt, reader->node);
1480 } 1501 }
1481 if ((reader->node != NULL) && (reader->node->type == XML_XINCLUDE_START)) { 1502 if ((reader->node != NULL) && (reader->node->type == XML_XINCLUDE_START)) {
1482 reader->in_xinclude++; 1503 reader->in_xinclude++;
1483 goto get_next_node; 1504 goto get_next_node;
1484 } 1505 }
1485 if ((reader->node != NULL) && (reader->node->type == XML_XINCLUDE_END)) { 1506 if ((reader->node != NULL) && (reader->node->type == XML_XINCLUDE_END)) {
1486 reader->in_xinclude--; 1507 reader->in_xinclude--;
1487 goto get_next_node; 1508 goto get_next_node;
1488 } 1509 }
1489 #endif 1510 #endif
1490 /* 1511 /*
1491 * Handle entities enter and exit when in entity replacement mode 1512 * Handle entities enter and exit when in entity replacement mode
1492 */ 1513 */
1493 if ((reader->node != NULL) && 1514 if ((reader->node != NULL) &&
1494 (reader->node->type == XML_ENTITY_REF_NODE) && 1515 (reader->node->type == XML_ENTITY_REF_NODE) &&
1495 (reader->ctxt != NULL) && (reader->ctxt->replaceEntities == 1)) { 1516 (reader->ctxt != NULL) && (reader->ctxt->replaceEntities == 1)) {
1496 /* 1517 /*
1497 * Case where the underlying tree is not availble, lookup the entity 1518 * Case where the underlying tree is not availble, lookup the entity
1498 * and walk it. 1519 * and walk it.
1499 */ 1520 */
1500 if ((reader->node->children == NULL) && (reader->ctxt->sax != NULL) && 1521 if ((reader->node->children == NULL) && (reader->ctxt->sax != NULL) &&
1501 (reader->ctxt->sax->getEntity != NULL)) { 1522 (reader->ctxt->sax->getEntity != NULL)) {
1502 » reader->node->children = (xmlNodePtr) 1523 » reader->node->children = (xmlNodePtr)
1503 reader->ctxt->sax->getEntity(reader->ctxt, reader->node->name); 1524 reader->ctxt->sax->getEntity(reader->ctxt, reader->node->name);
1504 } 1525 }
1505 1526
1506 if ((reader->node->children != NULL) && 1527 if ((reader->node->children != NULL) &&
1507 (reader->node->children->type == XML_ENTITY_DECL) && 1528 (reader->node->children->type == XML_ENTITY_DECL) &&
1508 (reader->node->children->children != NULL)) { 1529 (reader->node->children->children != NULL)) {
1509 xmlTextReaderEntPush(reader, reader->node); 1530 xmlTextReaderEntPush(reader, reader->node);
1510 reader->node = reader->node->children->children; 1531 reader->node = reader->node->children->children;
1511 } 1532 }
1512 #ifdef LIBXML_REGEXP_ENABLED 1533 #ifdef LIBXML_REGEXP_ENABLED
1513 } else if ((reader->node != NULL) && 1534 } else if ((reader->node != NULL) &&
1514 (reader->node->type == XML_ENTITY_REF_NODE) && 1535 (reader->node->type == XML_ENTITY_REF_NODE) &&
1515 (reader->ctxt != NULL) && (reader->validate)) { 1536 (reader->ctxt != NULL) && (reader->validate)) {
1516 xmlTextReaderValidateEntity(reader); 1537 xmlTextReaderValidateEntity(reader);
1517 #endif /* LIBXML_REGEXP_ENABLED */ 1538 #endif /* LIBXML_REGEXP_ENABLED */
1518 } 1539 }
1519 if ((reader->node != NULL) && 1540 if ((reader->node != NULL) &&
1520 (reader->node->type == XML_ENTITY_DECL) && 1541 (reader->node->type == XML_ENTITY_DECL) &&
1521 (reader->ent != NULL) && (reader->ent->children == reader->node)) { 1542 (reader->ent != NULL) && (reader->ent->children == reader->node)) {
1522 reader->node = xmlTextReaderEntPop(reader); 1543 reader->node = xmlTextReaderEntPop(reader);
1523 reader->depth++; 1544 reader->depth++;
1524 goto get_next_node; 1545 goto get_next_node;
1525 } 1546 }
1526 #ifdef LIBXML_REGEXP_ENABLED 1547 #ifdef LIBXML_REGEXP_ENABLED
1527 if ((reader->validate) && (reader->node != NULL)) { 1548 if ((reader->validate) && (reader->node != NULL)) {
1528 xmlNodePtr node = reader->node; 1549 xmlNodePtr node = reader->node;
1529 1550
1530 » if ((node->type == XML_ELEMENT_NODE) && 1551 » if ((node->type == XML_ELEMENT_NODE) &&
1531 ((reader->state != XML_TEXTREADER_END) && 1552 ((reader->state != XML_TEXTREADER_END) &&
1532 (reader->state != XML_TEXTREADER_BACKTRACK))) { 1553 (reader->state != XML_TEXTREADER_BACKTRACK))) {
1533 xmlTextReaderValidatePush(reader); 1554 xmlTextReaderValidatePush(reader);
1534 } else if ((node->type == XML_TEXT_NODE) || 1555 } else if ((node->type == XML_TEXT_NODE) ||
1535 (node->type == XML_CDATA_SECTION_NODE)) { 1556 (node->type == XML_CDATA_SECTION_NODE)) {
1536 xmlTextReaderValidateCData(reader, node->content, 1557 xmlTextReaderValidateCData(reader, node->content,
1537 xmlStrlen(node->content)); 1558 xmlStrlen(node->content));
1538 } 1559 }
1539 } 1560 }
1540 #endif /* LIBXML_REGEXP_ENABLED */ 1561 #endif /* LIBXML_REGEXP_ENABLED */
1541 #ifdef LIBXML_PATTERN_ENABLED 1562 #ifdef LIBXML_PATTERN_ENABLED
1542 if ((reader->patternNr > 0) && (reader->state != XML_TEXTREADER_END) && 1563 if ((reader->patternNr > 0) && (reader->state != XML_TEXTREADER_END) &&
1543 (reader->state != XML_TEXTREADER_BACKTRACK)) { 1564 (reader->state != XML_TEXTREADER_BACKTRACK)) {
1544 int i; 1565 int i;
1545 for (i = 0;i < reader->patternNr;i++) { 1566 for (i = 0;i < reader->patternNr;i++) {
1546 if (xmlPatternMatch(reader->patternTab[i], reader->node) == 1) { 1567 if (xmlPatternMatch(reader->patternTab[i], reader->node) == 1) {
1547 xmlTextReaderPreserve(reader); 1568 xmlTextReaderPreserve(reader);
1548 break; 1569 break;
1549 } 1570 }
1550 } 1571 }
1551 } 1572 }
1552 #endif /* LIBXML_PATTERN_ENABLED */ 1573 #endif /* LIBXML_PATTERN_ENABLED */
1553 #ifdef LIBXML_SCHEMAS_ENABLED 1574 #ifdef LIBXML_SCHEMAS_ENABLED
1554 if ((reader->validate == XML_TEXTREADER_VALIDATE_XSD) && 1575 if ((reader->validate == XML_TEXTREADER_VALIDATE_XSD) &&
1555 (reader->xsdValidErrors == 0) && 1576 (reader->xsdValidErrors == 0) &&
1556 (reader->xsdValidCtxt != NULL)) { 1577 (reader->xsdValidCtxt != NULL)) {
1557 reader->xsdValidErrors = !xmlSchemaIsValid(reader->xsdValidCtxt); 1578 reader->xsdValidErrors = !xmlSchemaIsValid(reader->xsdValidCtxt);
1558 } 1579 }
1559 #endif /* LIBXML_PATTERN_ENABLED */ 1580 #endif /* LIBXML_PATTERN_ENABLED */
1560 return(1); 1581 return(1);
1561 node_end: 1582 node_end:
1562 reader->state = XML_TEXTREADER_DONE; 1583 reader->state = XML_TEXTREADER_DONE;
1563 return(0); 1584 return(0);
1564 } 1585 }
1565 1586
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 } 1657 }
1637 1658
1638 #ifdef LIBXML_WRITER_ENABLED 1659 #ifdef LIBXML_WRITER_ENABLED
1639 /** 1660 /**
1640 * xmlTextReaderReadInnerXml: 1661 * xmlTextReaderReadInnerXml:
1641 * @reader: the xmlTextReaderPtr used 1662 * @reader: the xmlTextReaderPtr used
1642 * 1663 *
1643 * Reads the contents of the current node, including child nodes and markup. 1664 * Reads the contents of the current node, including child nodes and markup.
1644 * 1665 *
1645 * Returns a string containing the XML content, or NULL if the current node 1666 * Returns a string containing the XML content, or NULL if the current node
1646 * is neither an element nor attribute, or has no child nodes. The 1667 * is neither an element nor attribute, or has no child nodes. The
1647 * string must be deallocated by the caller. 1668 * string must be deallocated by the caller.
1648 */ 1669 */
1649 xmlChar * 1670 xmlChar *
1650 xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) 1671 xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED)
1651 { 1672 {
1652 xmlChar *resbuf; 1673 xmlChar *resbuf;
1653 xmlNodePtr node, cur_node; 1674 xmlNodePtr node, cur_node;
1654 xmlBufferPtr buff, buff2; 1675 xmlBufferPtr buff, buff2;
1655 xmlDocPtr doc; 1676 xmlDocPtr doc;
1656 1677
(...skipping 25 matching lines...) Expand all
1682 #endif 1703 #endif
1683 1704
1684 #ifdef LIBXML_WRITER_ENABLED 1705 #ifdef LIBXML_WRITER_ENABLED
1685 /** 1706 /**
1686 * xmlTextReaderReadOuterXml: 1707 * xmlTextReaderReadOuterXml:
1687 * @reader: the xmlTextReaderPtr used 1708 * @reader: the xmlTextReaderPtr used
1688 * 1709 *
1689 * Reads the contents of the current node, including child nodes and markup. 1710 * Reads the contents of the current node, including child nodes and markup.
1690 * 1711 *
1691 * Returns a string containing the XML content, or NULL if the current node 1712 * Returns a string containing the XML content, or NULL if the current node
1692 * is neither an element nor attribute, or has no child nodes. The 1713 * is neither an element nor attribute, or has no child nodes. The
1693 * string must be deallocated by the caller. 1714 * string must be deallocated by the caller.
1694 */ 1715 */
1695 xmlChar * 1716 xmlChar *
1696 xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) 1717 xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED)
1697 { 1718 {
1698 xmlChar *resbuf; 1719 xmlChar *resbuf;
1699 xmlNodePtr node; 1720 xmlNodePtr node;
1700 xmlBufferPtr buff; 1721 xmlBufferPtr buff;
1701 xmlDocPtr doc; 1722 xmlDocPtr doc;
1702 1723
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 reader->state = XML_TEXTREADER_END; 1861 reader->state = XML_TEXTREADER_END;
1841 return(0); 1862 return(0);
1842 } 1863 }
1843 1864
1844 reader->node = reader->doc->children; 1865 reader->node = reader->doc->children;
1845 reader->state = XML_TEXTREADER_START; 1866 reader->state = XML_TEXTREADER_START;
1846 return(1); 1867 return(1);
1847 } 1868 }
1848 1869
1849 if (reader->state != XML_TEXTREADER_BACKTRACK) { 1870 if (reader->state != XML_TEXTREADER_BACKTRACK) {
1850 if (reader->node->children != 0) { 1871 » /* Here removed traversal to child, because we want to skip the subtree,
1851 reader->node = reader->node->children; 1872 » replace with traversal to sibling to skip subtree */
1852 reader->depth++; 1873 if (reader->node->next != 0) {
1874 » /* Move to sibling if present,skipping sub-tree */
1875 reader->node = reader->node->next;
1853 reader->state = XML_TEXTREADER_START; 1876 reader->state = XML_TEXTREADER_START;
1854 return(1); 1877 return(1);
1855 } 1878 }
1856 1879
1880 /* if reader->node->next is NULL mean no subtree for current node,
1881 so need to move to sibling of parent node if present */
1857 if ((reader->node->type == XML_ELEMENT_NODE) || 1882 if ((reader->node->type == XML_ELEMENT_NODE) ||
1858 (reader->node->type == XML_ATTRIBUTE_NODE)) { 1883 (reader->node->type == XML_ATTRIBUTE_NODE)) {
1859 reader->state = XML_TEXTREADER_BACKTRACK; 1884 reader->state = XML_TEXTREADER_BACKTRACK;
1860 return(1); 1885 » /* This will move to parent if present */
1886 xmlTextReaderRead(reader);
1861 } 1887 }
1862 } 1888 }
1863 1889
1864 if (reader->node->next != 0) { 1890 if (reader->node->next != 0) {
1865 reader->node = reader->node->next; 1891 reader->node = reader->node->next;
1866 reader->state = XML_TEXTREADER_START; 1892 reader->state = XML_TEXTREADER_START;
1867 return(1); 1893 return(1);
1868 } 1894 }
1869 1895
1870 if (reader->node->parent != 0) { 1896 if (reader->node->parent != 0) {
1871 if (reader->node->parent->type == XML_DOCUMENT_NODE) { 1897 if (reader->node->parent->type == XML_DOCUMENT_NODE) {
1872 reader->state = XML_TEXTREADER_END; 1898 reader->state = XML_TEXTREADER_END;
1873 return(0); 1899 return(0);
1874 } 1900 }
1875 1901
1876 reader->node = reader->node->parent; 1902 reader->node = reader->node->parent;
1877 reader->depth--; 1903 reader->depth--;
1878 reader->state = XML_TEXTREADER_BACKTRACK; 1904 reader->state = XML_TEXTREADER_BACKTRACK;
1879 return(1); 1905 » /* Repeat process to move to sibling of parent node if present */
1906 xmlTextReaderNextTree(reader);
1880 } 1907 }
1881 1908
1882 reader->state = XML_TEXTREADER_END; 1909 reader->state = XML_TEXTREADER_END;
1883 1910
1884 return(1); 1911 return(1);
1885 } 1912 }
1886 1913
1887 /** 1914 /**
1888 * xmlTextReaderReadTree: 1915 * xmlTextReaderReadTree:
1889 * @reader: the xmlTextReaderPtr used 1916 * @reader: the xmlTextReaderPtr used
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 if (ret->input->buffer->use >= 4) { 2099 if (ret->input->buffer->use >= 4) {
2073 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, 2100 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL,
2074 (const char *) ret->input->buffer->content, 4, URI); 2101 (const char *) ret->input->buffer->content, 4, URI);
2075 ret->base = 0; 2102 ret->base = 0;
2076 ret->cur = 4; 2103 ret->cur = 4;
2077 } else { 2104 } else {
2078 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, NULL, 0, URI); 2105 ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, NULL, 0, URI);
2079 ret->base = 0; 2106 ret->base = 0;
2080 ret->cur = 0; 2107 ret->cur = 0;
2081 } 2108 }
2082 2109
2083 if (ret->ctxt == NULL) { 2110 if (ret->ctxt == NULL) {
2084 xmlGenericError(xmlGenericErrorContext, 2111 xmlGenericError(xmlGenericErrorContext,
2085 "xmlNewTextReader : malloc failed\n"); 2112 "xmlNewTextReader : malloc failed\n");
2086 xmlBufferFree(ret->buffer); 2113 xmlBufferFree(ret->buffer);
2087 xmlFree(ret->sax); 2114 xmlFree(ret->sax);
2088 xmlFree(ret); 2115 xmlFree(ret);
2089 return(NULL); 2116 return(NULL);
2090 } 2117 }
2091 ret->ctxt->parseMode = XML_PARSE_READER; 2118 ret->ctxt->parseMode = XML_PARSE_READER;
2092 ret->ctxt->_private = ret; 2119 ret->ctxt->_private = ret;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 #ifdef LIBXML_PATTERN_ENABLED 2207 #ifdef LIBXML_PATTERN_ENABLED
2181 if (reader->patternTab != NULL) { 2208 if (reader->patternTab != NULL) {
2182 int i; 2209 int i;
2183 for (i = 0;i < reader->patternNr;i++) { 2210 for (i = 0;i < reader->patternNr;i++) {
2184 if (reader->patternTab[i] != NULL) 2211 if (reader->patternTab[i] != NULL)
2185 xmlFreePattern(reader->patternTab[i]); 2212 xmlFreePattern(reader->patternTab[i]);
2186 } 2213 }
2187 xmlFree(reader->patternTab); 2214 xmlFree(reader->patternTab);
2188 } 2215 }
2189 #endif 2216 #endif
2217 if (reader->faketext != NULL) {
2218 xmlFreeNode(reader->faketext);
2219 }
2190 if (reader->ctxt != NULL) { 2220 if (reader->ctxt != NULL) {
2191 if (reader->dict == reader->ctxt->dict) 2221 if (reader->dict == reader->ctxt->dict)
2192 reader->dict = NULL; 2222 reader->dict = NULL;
2193 if (reader->ctxt->myDoc != NULL) { 2223 if (reader->ctxt->myDoc != NULL) {
2194 if (reader->preserve == 0) 2224 if (reader->preserve == 0)
2195 xmlTextReaderFreeDoc(reader, reader->ctxt->myDoc); 2225 xmlTextReaderFreeDoc(reader, reader->ctxt->myDoc);
2196 reader->ctxt->myDoc = NULL; 2226 reader->ctxt->myDoc = NULL;
2197 } 2227 }
2198 if ((reader->ctxt->vctxt.vstateTab != NULL) && 2228 if ((reader->ctxt->vctxt.vstateTab != NULL) &&
2199 (reader->ctxt->vctxt.vstateMax > 0)){ 2229 (reader->ctxt->vctxt.vstateMax > 0)){
2200 xmlFree(reader->ctxt->vctxt.vstateTab); 2230 xmlFree(reader->ctxt->vctxt.vstateTab);
2201 reader->ctxt->vctxt.vstateTab = NULL; 2231 reader->ctxt->vctxt.vstateTab = NULL;
2202 reader->ctxt->vctxt.vstateMax = 0; 2232 reader->ctxt->vctxt.vstateMax = 0;
2203 } 2233 }
2204 if (reader->allocs & XML_TEXTREADER_CTXT) 2234 if (reader->allocs & XML_TEXTREADER_CTXT)
2205 xmlFreeParserCtxt(reader->ctxt); 2235 xmlFreeParserCtxt(reader->ctxt);
2206 } 2236 }
2207 if (reader->sax != NULL) 2237 if (reader->sax != NULL)
2208 xmlFree(reader->sax); 2238 xmlFree(reader->sax);
2209 if ((reader->input != NULL) && (reader->allocs & XML_TEXTREADER_INPUT)) 2239 if ((reader->input != NULL) && (reader->allocs & XML_TEXTREADER_INPUT))
2210 xmlFreeParserInputBuffer(reader->input); 2240 xmlFreeParserInputBuffer(reader->input);
2211 if (reader->faketext != NULL) {
2212 xmlFreeNode(reader->faketext);
2213 }
2214 if (reader->buffer != NULL) 2241 if (reader->buffer != NULL)
2215 xmlBufferFree(reader->buffer); 2242 xmlBufferFree(reader->buffer);
2216 if (reader->entTab != NULL) 2243 if (reader->entTab != NULL)
2217 xmlFree(reader->entTab); 2244 xmlFree(reader->entTab);
2218 if (reader->dict != NULL) 2245 if (reader->dict != NULL)
2219 xmlDictFree(reader->dict); 2246 xmlDictFree(reader->dict);
2220 xmlFree(reader); 2247 xmlFree(reader);
2221 } 2248 }
2222 2249
2223 /************************************************************************ 2250 /************************************************************************
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 xmlAttrPtr cur; 2301 xmlAttrPtr cur;
2275 xmlNsPtr ns; 2302 xmlNsPtr ns;
2276 2303
2277 if (reader == NULL) 2304 if (reader == NULL)
2278 return(NULL); 2305 return(NULL);
2279 if (reader->node == NULL) 2306 if (reader->node == NULL)
2280 return(NULL); 2307 return(NULL);
2281 if (reader->curnode != NULL) 2308 if (reader->curnode != NULL)
2282 return(NULL); 2309 return(NULL);
2283 /* TODO: handle the xmlDecl */ 2310 /* TODO: handle the xmlDecl */
2284 if (reader->node->type != XML_ELEMENT_NODE) 2311 if (reader->node->type != XML_ELEMENT_NODE)
2285 return(NULL); 2312 return(NULL);
2286 2313
2287 ns = reader->node->nsDef; 2314 ns = reader->node->nsDef;
2288 for (i = 0;(i < no) && (ns != NULL);i++) { 2315 for (i = 0;(i < no) && (ns != NULL);i++) {
2289 ns = ns->next; 2316 ns = ns->next;
2290 } 2317 }
2291 if (ns != NULL) 2318 if (ns != NULL)
2292 return(xmlStrdup(ns->href)); 2319 return(xmlStrdup(ns->href));
2293 2320
2294 cur = reader->node->properties; 2321 cur = reader->node->properties;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 /* TODO: handle the xmlDecl */ 2431 /* TODO: handle the xmlDecl */
2405 if (reader->node->type != XML_ELEMENT_NODE) 2432 if (reader->node->type != XML_ELEMENT_NODE)
2406 return(NULL); 2433 return(NULL);
2407 2434
2408 if (xmlStrEqual(namespaceURI, BAD_CAST "http://www.w3.org/2000/xmlns/")) { 2435 if (xmlStrEqual(namespaceURI, BAD_CAST "http://www.w3.org/2000/xmlns/")) {
2409 if (! xmlStrEqual(localName, BAD_CAST "xmlns")) { 2436 if (! xmlStrEqual(localName, BAD_CAST "xmlns")) {
2410 prefix = BAD_CAST localName; 2437 prefix = BAD_CAST localName;
2411 } 2438 }
2412 ns = reader->node->nsDef; 2439 ns = reader->node->nsDef;
2413 while (ns != NULL) { 2440 while (ns != NULL) {
2414 » » » if ((prefix == NULL && ns->prefix == NULL) || 2441 » » » if ((prefix == NULL && ns->prefix == NULL) ||
2415 ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix , localName)))) { 2442 ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix , localName)))) {
2416 return xmlStrdup(ns->href); 2443 return xmlStrdup(ns->href);
2417 } 2444 }
2418 ns = ns->next; 2445 ns = ns->next;
2419 } 2446 }
2420 return NULL; 2447 return NULL;
2421 } 2448 }
2422 2449
2423 return(xmlGetNsProp(reader->node, localName, namespaceURI)); 2450 return(xmlGetNsProp(reader->node, localName, namespaceURI));
2424 } 2451 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 xmlTextReaderMoveToAttributeNo(xmlTextReaderPtr reader, int no) { 2543 xmlTextReaderMoveToAttributeNo(xmlTextReaderPtr reader, int no) {
2517 int i; 2544 int i;
2518 xmlAttrPtr cur; 2545 xmlAttrPtr cur;
2519 xmlNsPtr ns; 2546 xmlNsPtr ns;
2520 2547
2521 if (reader == NULL) 2548 if (reader == NULL)
2522 return(-1); 2549 return(-1);
2523 if (reader->node == NULL) 2550 if (reader->node == NULL)
2524 return(-1); 2551 return(-1);
2525 /* TODO: handle the xmlDecl */ 2552 /* TODO: handle the xmlDecl */
2526 if (reader->node->type != XML_ELEMENT_NODE) 2553 if (reader->node->type != XML_ELEMENT_NODE)
2527 return(-1); 2554 return(-1);
2528 2555
2529 reader->curnode = NULL; 2556 reader->curnode = NULL;
2530 2557
2531 ns = reader->node->nsDef; 2558 ns = reader->node->nsDef;
2532 for (i = 0;(i < no) && (ns != NULL);i++) { 2559 for (i = 0;(i < no) && (ns != NULL);i++) {
2533 ns = ns->next; 2560 ns = ns->next;
2534 } 2561 }
2535 if (ns != NULL) { 2562 if (ns != NULL) {
2536 reader->curnode = (xmlNodePtr) ns; 2563 reader->curnode = (xmlNodePtr) ns;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 */ 2630 */
2604 if ((xmlStrEqual(prop->name, name)) && 2631 if ((xmlStrEqual(prop->name, name)) &&
2605 ((prop->ns == NULL) || (prop->ns->prefix == NULL))) { 2632 ((prop->ns == NULL) || (prop->ns->prefix == NULL))) {
2606 reader->curnode = (xmlNodePtr) prop; 2633 reader->curnode = (xmlNodePtr) prop;
2607 return(1); 2634 return(1);
2608 } 2635 }
2609 prop = prop->next; 2636 prop = prop->next;
2610 } 2637 }
2611 return(0); 2638 return(0);
2612 } 2639 }
2613 2640
2614 /* 2641 /*
2615 * Namespace default decl 2642 * Namespace default decl
2616 */ 2643 */
2617 if (xmlStrEqual(prefix, BAD_CAST "xmlns")) { 2644 if (xmlStrEqual(prefix, BAD_CAST "xmlns")) {
2618 ns = reader->node->nsDef; 2645 ns = reader->node->nsDef;
2619 while (ns != NULL) { 2646 while (ns != NULL) {
2620 if ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localname))) { 2647 if ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localname))) {
2621 reader->curnode = (xmlNodePtr) ns; 2648 reader->curnode = (xmlNodePtr) ns;
2622 goto found; 2649 goto found;
2623 } 2650 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 if (reader->node->type != XML_ELEMENT_NODE) 2707 if (reader->node->type != XML_ELEMENT_NODE)
2681 return(0); 2708 return(0);
2682 node = reader->node; 2709 node = reader->node;
2683 2710
2684 if (xmlStrEqual(namespaceURI, BAD_CAST "http://www.w3.org/2000/xmlns/")) { 2711 if (xmlStrEqual(namespaceURI, BAD_CAST "http://www.w3.org/2000/xmlns/")) {
2685 if (! xmlStrEqual(localName, BAD_CAST "xmlns")) { 2712 if (! xmlStrEqual(localName, BAD_CAST "xmlns")) {
2686 prefix = BAD_CAST localName; 2713 prefix = BAD_CAST localName;
2687 } 2714 }
2688 ns = reader->node->nsDef; 2715 ns = reader->node->nsDef;
2689 while (ns != NULL) { 2716 while (ns != NULL) {
2690 » » » if ((prefix == NULL && ns->prefix == NULL) || 2717 » » » if ((prefix == NULL && ns->prefix == NULL) ||
2691 ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix , localName)))) { 2718 ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix , localName)))) {
2692 reader->curnode = (xmlNodePtr) ns; 2719 reader->curnode = (xmlNodePtr) ns;
2693 return(1); 2720 return(1);
2694 } 2721 }
2695 ns = ns->next; 2722 ns = ns->next;
2696 } 2723 }
2697 return(0); 2724 return(0);
2698 } 2725 }
2699 2726
2700 prop = node->properties; 2727 prop = node->properties;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2826 if (reader->curnode == NULL) 2853 if (reader->curnode == NULL)
2827 return(0); 2854 return(0);
2828 if (reader->curnode->type == XML_ATTRIBUTE_NODE) { 2855 if (reader->curnode->type == XML_ATTRIBUTE_NODE) {
2829 if (reader->curnode->children == NULL) 2856 if (reader->curnode->children == NULL)
2830 return(0); 2857 return(0);
2831 reader->curnode = reader->curnode->children; 2858 reader->curnode = reader->curnode->children;
2832 } else if (reader->curnode->type == XML_NAMESPACE_DECL) { 2859 } else if (reader->curnode->type == XML_NAMESPACE_DECL) {
2833 xmlNsPtr ns = (xmlNsPtr) reader->curnode; 2860 xmlNsPtr ns = (xmlNsPtr) reader->curnode;
2834 2861
2835 if (reader->faketext == NULL) { 2862 if (reader->faketext == NULL) {
2836 » reader->faketext = xmlNewDocText(reader->node->doc, 2863 » reader->faketext = xmlNewDocText(reader->node->doc,
2837 ns->href); 2864 ns->href);
2838 } else { 2865 } else {
2839 if ((reader->faketext->content != NULL) && 2866 if ((reader->faketext->content != NULL) &&
2840 (reader->faketext->content != 2867 (reader->faketext->content !=
2841 (xmlChar *) &(reader->faketext->properties))) 2868 (xmlChar *) &(reader->faketext->properties)))
2842 xmlFree(reader->faketext->content); 2869 xmlFree(reader->faketext->content);
2843 reader->faketext->content = xmlStrdup(ns->href); 2870 reader->faketext->content = xmlStrdup(ns->href);
2844 } 2871 }
2845 reader->curnode = reader->faketext; 2872 reader->curnode = reader->faketext;
2846 } else { 2873 } else {
(...skipping 17 matching lines...) Expand all
2864 xmlTextReaderConstEncoding(xmlTextReaderPtr reader) { 2891 xmlTextReaderConstEncoding(xmlTextReaderPtr reader) {
2865 xmlDocPtr doc = NULL; 2892 xmlDocPtr doc = NULL;
2866 if (reader == NULL) 2893 if (reader == NULL)
2867 return(NULL); 2894 return(NULL);
2868 if (reader->doc != NULL) 2895 if (reader->doc != NULL)
2869 doc = reader->doc; 2896 doc = reader->doc;
2870 else if (reader->ctxt != NULL) 2897 else if (reader->ctxt != NULL)
2871 doc = reader->ctxt->myDoc; 2898 doc = reader->ctxt->myDoc;
2872 if (doc == NULL) 2899 if (doc == NULL)
2873 return(NULL); 2900 return(NULL);
2874 2901
2875 if (doc->encoding == NULL) 2902 if (doc->encoding == NULL)
2876 return(NULL); 2903 return(NULL);
2877 else 2904 else
2878 return(CONSTSTR(doc->encoding)); 2905 return(CONSTSTR(doc->encoding));
2879 } 2906 }
2880 2907
2881 2908
2882 /************************************************************************ 2909 /************************************************************************
2883 * * 2910 * *
2884 * Acces API to the current node * 2911 * Acces API to the current node *
(...skipping 11 matching lines...) Expand all
2896 xmlTextReaderAttributeCount(xmlTextReaderPtr reader) { 2923 xmlTextReaderAttributeCount(xmlTextReaderPtr reader) {
2897 int ret; 2924 int ret;
2898 xmlAttrPtr attr; 2925 xmlAttrPtr attr;
2899 xmlNsPtr ns; 2926 xmlNsPtr ns;
2900 xmlNodePtr node; 2927 xmlNodePtr node;
2901 2928
2902 if (reader == NULL) 2929 if (reader == NULL)
2903 return(-1); 2930 return(-1);
2904 if (reader->node == NULL) 2931 if (reader->node == NULL)
2905 return(0); 2932 return(0);
2906 2933
2907 if (reader->curnode != NULL) 2934 if (reader->curnode != NULL)
2908 node = reader->curnode; 2935 node = reader->curnode;
2909 else 2936 else
2910 node = reader->node; 2937 node = reader->node;
2911 2938
2912 if (node->type != XML_ELEMENT_NODE) 2939 if (node->type != XML_ELEMENT_NODE)
2913 return(0); 2940 return(0);
2914 if ((reader->state == XML_TEXTREADER_END) || 2941 if ((reader->state == XML_TEXTREADER_END) ||
2915 (reader->state == XML_TEXTREADER_BACKTRACK)) 2942 (reader->state == XML_TEXTREADER_BACKTRACK))
2916 return(0); 2943 return(0);
(...skipping 17 matching lines...) Expand all
2934 * 2961 *
2935 * Get the node type of the current node 2962 * Get the node type of the current node
2936 * Reference: 2963 * Reference:
2937 * http://www.gnu.org/software/dotgnu/pnetlib-doc/System/Xml/XmlNodeType.html 2964 * http://www.gnu.org/software/dotgnu/pnetlib-doc/System/Xml/XmlNodeType.html
2938 * 2965 *
2939 * Returns the xmlNodeType of the current node or -1 in case of error 2966 * Returns the xmlNodeType of the current node or -1 in case of error
2940 */ 2967 */
2941 int 2968 int
2942 xmlTextReaderNodeType(xmlTextReaderPtr reader) { 2969 xmlTextReaderNodeType(xmlTextReaderPtr reader) {
2943 xmlNodePtr node; 2970 xmlNodePtr node;
2944 2971
2945 if (reader == NULL) 2972 if (reader == NULL)
2946 return(-1); 2973 return(-1);
2947 if (reader->node == NULL) 2974 if (reader->node == NULL)
2948 return(XML_READER_TYPE_NONE); 2975 return(XML_READER_TYPE_NONE);
2949 if (reader->curnode != NULL) 2976 if (reader->curnode != NULL)
2950 node = reader->curnode; 2977 node = reader->curnode;
2951 else 2978 else
2952 node = reader->node; 2979 node = reader->node;
2953 switch (node->type) { 2980 switch (node->type) {
2954 case XML_ELEMENT_NODE: 2981 case XML_ELEMENT_NODE:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 #endif 3057 #endif
3031 return((reader->node->extra & NODE_IS_EMPTY) != 0); 3058 return((reader->node->extra & NODE_IS_EMPTY) != 0);
3032 } 3059 }
3033 3060
3034 /** 3061 /**
3035 * xmlTextReaderLocalName: 3062 * xmlTextReaderLocalName:
3036 * @reader: the xmlTextReaderPtr used 3063 * @reader: the xmlTextReaderPtr used
3037 * 3064 *
3038 * The local name of the node. 3065 * The local name of the node.
3039 * 3066 *
3040 * Returns the local name or NULL if not available 3067 * Returns the local name or NULL if not available,
3068 * if non NULL it need to be freed by the caller.
3041 */ 3069 */
3042 xmlChar * 3070 xmlChar *
3043 xmlTextReaderLocalName(xmlTextReaderPtr reader) { 3071 xmlTextReaderLocalName(xmlTextReaderPtr reader) {
3044 xmlNodePtr node; 3072 xmlNodePtr node;
3045 if ((reader == NULL) || (reader->node == NULL)) 3073 if ((reader == NULL) || (reader->node == NULL))
3046 return(NULL); 3074 return(NULL);
3047 if (reader->curnode != NULL) 3075 if (reader->curnode != NULL)
3048 node = reader->curnode; 3076 node = reader->curnode;
3049 else 3077 else
3050 node = reader->node; 3078 node = reader->node;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3091 return(xmlTextReaderConstName(reader)); 3119 return(xmlTextReaderConstName(reader));
3092 return(node->name); 3120 return(node->name);
3093 } 3121 }
3094 3122
3095 /** 3123 /**
3096 * xmlTextReaderName: 3124 * xmlTextReaderName:
3097 * @reader: the xmlTextReaderPtr used 3125 * @reader: the xmlTextReaderPtr used
3098 * 3126 *
3099 * The qualified name of the node, equal to Prefix :LocalName. 3127 * The qualified name of the node, equal to Prefix :LocalName.
3100 * 3128 *
3101 * Returns the local name or NULL if not available 3129 * Returns the local name or NULL if not available,
3130 * if non NULL it need to be freed by the caller.
3102 */ 3131 */
3103 xmlChar * 3132 xmlChar *
3104 xmlTextReaderName(xmlTextReaderPtr reader) { 3133 xmlTextReaderName(xmlTextReaderPtr reader) {
3105 xmlNodePtr node; 3134 xmlNodePtr node;
3106 xmlChar *ret; 3135 xmlChar *ret;
3107 3136
3108 if ((reader == NULL) || (reader->node == NULL)) 3137 if ((reader == NULL) || (reader->node == NULL))
3109 return(NULL); 3138 return(NULL);
3110 if (reader->curnode != NULL) 3139 if (reader->curnode != NULL)
3111 node = reader->curnode; 3140 node = reader->curnode;
3112 else 3141 else
3113 node = reader->node; 3142 node = reader->node;
3114 switch (node->type) { 3143 switch (node->type) {
3115 case XML_ELEMENT_NODE: 3144 case XML_ELEMENT_NODE:
3116 case XML_ATTRIBUTE_NODE: 3145 case XML_ATTRIBUTE_NODE:
3117 if ((node->ns == NULL) || 3146 if ((node->ns == NULL) ||
3118 (node->ns->prefix == NULL)) 3147 (node->ns->prefix == NULL))
3119 return(xmlStrdup(node->name)); 3148 return(xmlStrdup(node->name));
3120 » 3149
3121 ret = xmlStrdup(node->ns->prefix); 3150 ret = xmlStrdup(node->ns->prefix);
3122 ret = xmlStrcat(ret, BAD_CAST ":"); 3151 ret = xmlStrcat(ret, BAD_CAST ":");
3123 ret = xmlStrcat(ret, node->name); 3152 ret = xmlStrcat(ret, node->name);
3124 return(ret); 3153 return(ret);
3125 case XML_TEXT_NODE: 3154 case XML_TEXT_NODE:
3126 return(xmlStrdup(BAD_CAST "#text")); 3155 return(xmlStrdup(BAD_CAST "#text"));
3127 case XML_CDATA_SECTION_NODE: 3156 case XML_CDATA_SECTION_NODE:
3128 return(xmlStrdup(BAD_CAST "#cdata-section")); 3157 return(xmlStrdup(BAD_CAST "#cdata-section"));
3129 case XML_ENTITY_NODE: 3158 case XML_ENTITY_NODE:
3130 case XML_ENTITY_REF_NODE: 3159 case XML_ENTITY_REF_NODE:
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3234 } 3263 }
3235 return(NULL); 3264 return(NULL);
3236 } 3265 }
3237 3266
3238 /** 3267 /**
3239 * xmlTextReaderPrefix: 3268 * xmlTextReaderPrefix:
3240 * @reader: the xmlTextReaderPtr used 3269 * @reader: the xmlTextReaderPtr used
3241 * 3270 *
3242 * A shorthand reference to the namespace associated with the node. 3271 * A shorthand reference to the namespace associated with the node.
3243 * 3272 *
3244 * Returns the prefix or NULL if not available 3273 * Returns the prefix or NULL if not available,
3274 * if non NULL it need to be freed by the caller.
3245 */ 3275 */
3246 xmlChar * 3276 xmlChar *
3247 xmlTextReaderPrefix(xmlTextReaderPtr reader) { 3277 xmlTextReaderPrefix(xmlTextReaderPtr reader) {
3248 xmlNodePtr node; 3278 xmlNodePtr node;
3249 if ((reader == NULL) || (reader->node == NULL)) 3279 if ((reader == NULL) || (reader->node == NULL))
3250 return(NULL); 3280 return(NULL);
3251 if (reader->curnode != NULL) 3281 if (reader->curnode != NULL)
3252 node = reader->curnode; 3282 node = reader->curnode;
3253 else 3283 else
3254 node = reader->node; 3284 node = reader->node;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3297 return(CONSTSTR(node->ns->prefix)); 3327 return(CONSTSTR(node->ns->prefix));
3298 return(NULL); 3328 return(NULL);
3299 } 3329 }
3300 3330
3301 /** 3331 /**
3302 * xmlTextReaderNamespaceUri: 3332 * xmlTextReaderNamespaceUri:
3303 * @reader: the xmlTextReaderPtr used 3333 * @reader: the xmlTextReaderPtr used
3304 * 3334 *
3305 * The URI defining the namespace associated with the node. 3335 * The URI defining the namespace associated with the node.
3306 * 3336 *
3307 * Returns the namespace URI or NULL if not available 3337 * Returns the namespace URI or NULL if not available,
3338 * if non NULL it need to be freed by the caller.
3308 */ 3339 */
3309 xmlChar * 3340 xmlChar *
3310 xmlTextReaderNamespaceUri(xmlTextReaderPtr reader) { 3341 xmlTextReaderNamespaceUri(xmlTextReaderPtr reader) {
3311 xmlNodePtr node; 3342 xmlNodePtr node;
3312 if ((reader == NULL) || (reader->node == NULL)) 3343 if ((reader == NULL) || (reader->node == NULL))
3313 return(NULL); 3344 return(NULL);
3314 if (reader->curnode != NULL) 3345 if (reader->curnode != NULL)
3315 node = reader->curnode; 3346 node = reader->curnode;
3316 else 3347 else
3317 node = reader->node; 3348 node = reader->node;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3352 return(CONSTSTR(node->ns->href)); 3383 return(CONSTSTR(node->ns->href));
3353 return(NULL); 3384 return(NULL);
3354 } 3385 }
3355 3386
3356 /** 3387 /**
3357 * xmlTextReaderBaseUri: 3388 * xmlTextReaderBaseUri:
3358 * @reader: the xmlTextReaderPtr used 3389 * @reader: the xmlTextReaderPtr used
3359 * 3390 *
3360 * The base URI of the node. 3391 * The base URI of the node.
3361 * 3392 *
3362 * Returns the base URI or NULL if not available 3393 * Returns the base URI or NULL if not available,
3394 * if non NULL it need to be freed by the caller.
3363 */ 3395 */
3364 xmlChar * 3396 xmlChar *
3365 xmlTextReaderBaseUri(xmlTextReaderPtr reader) { 3397 xmlTextReaderBaseUri(xmlTextReaderPtr reader) {
3366 if ((reader == NULL) || (reader->node == NULL)) 3398 if ((reader == NULL) || (reader->node == NULL))
3367 return(NULL); 3399 return(NULL);
3368 return(xmlNodeGetBase(NULL, reader->node)); 3400 return(xmlNodeGetBase(NULL, reader->node));
3369 } 3401 }
3370 3402
3371 /** 3403 /**
3372 * xmlTextReaderConstBaseUri: 3404 * xmlTextReaderConstBaseUri:
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 /* TODO maybe lookup the attribute value for " first */ 3642 /* TODO maybe lookup the attribute value for " first */
3611 return((int) '"'); 3643 return((int) '"');
3612 } 3644 }
3613 3645
3614 /** 3646 /**
3615 * xmlTextReaderXmlLang: 3647 * xmlTextReaderXmlLang:
3616 * @reader: the xmlTextReaderPtr used 3648 * @reader: the xmlTextReaderPtr used
3617 * 3649 *
3618 * The xml:lang scope within which the node resides. 3650 * The xml:lang scope within which the node resides.
3619 * 3651 *
3620 * Returns the xml:lang value or NULL if none exists. 3652 * Returns the xml:lang value or NULL if none exists.,
3653 * if non NULL it need to be freed by the caller.
3621 */ 3654 */
3622 xmlChar * 3655 xmlChar *
3623 xmlTextReaderXmlLang(xmlTextReaderPtr reader) { 3656 xmlTextReaderXmlLang(xmlTextReaderPtr reader) {
3624 if (reader == NULL) 3657 if (reader == NULL)
3625 return(NULL); 3658 return(NULL);
3626 if (reader->node == NULL) 3659 if (reader->node == NULL)
3627 return(NULL); 3660 return(NULL);
3628 return(xmlNodeGetLang(reader->node)); 3661 return(xmlNodeGetLang(reader->node));
3629 } 3662 }
3630 3663
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 * Hacking interface allowing to get the xmlNodePtr correponding to the 3868 * Hacking interface allowing to get the xmlNodePtr correponding to the
3836 * current node being accessed by the xmlTextReader. This is dangerous 3869 * current node being accessed by the xmlTextReader. This is dangerous
3837 * because the underlying node may be destroyed on the next Reads. 3870 * because the underlying node may be destroyed on the next Reads.
3838 * 3871 *
3839 * Returns the xmlNodePtr or NULL in case of error. 3872 * Returns the xmlNodePtr or NULL in case of error.
3840 */ 3873 */
3841 xmlNodePtr 3874 xmlNodePtr
3842 xmlTextReaderCurrentNode(xmlTextReaderPtr reader) { 3875 xmlTextReaderCurrentNode(xmlTextReaderPtr reader) {
3843 if (reader == NULL) 3876 if (reader == NULL)
3844 return(NULL); 3877 return(NULL);
3845 3878
3846 if (reader->curnode != NULL) 3879 if (reader->curnode != NULL)
3847 return(reader->curnode); 3880 return(reader->curnode);
3848 return(reader->node); 3881 return(reader->node);
3849 } 3882 }
3850 3883
3851 /** 3884 /**
3852 * xmlTextReaderPreserve: 3885 * xmlTextReaderPreserve:
3853 * @reader: the xmlTextReaderPtr used 3886 * @reader: the xmlTextReaderPtr used
3854 * 3887 *
3855 * This tells the XML Reader to preserve the current node. 3888 * This tells the XML Reader to preserve the current node.
3856 * The caller must also use xmlTextReaderCurrentDoc() to 3889 * The caller must also use xmlTextReaderCurrentDoc() to
3857 * keep an handle on the resulting document once parsing has finished 3890 * keep an handle on the resulting document once parsing has finished
3858 * 3891 *
3859 * Returns the xmlNodePtr or NULL in case of error. 3892 * Returns the xmlNodePtr or NULL in case of error.
3860 */ 3893 */
3861 xmlNodePtr 3894 xmlNodePtr
3862 xmlTextReaderPreserve(xmlTextReaderPtr reader) { 3895 xmlTextReaderPreserve(xmlTextReaderPtr reader) {
3863 xmlNodePtr cur, parent; 3896 xmlNodePtr cur, parent;
3864 3897
3865 if (reader == NULL) 3898 if (reader == NULL)
3866 return(NULL); 3899 return(NULL);
3867 3900
3868 if (reader->curnode != NULL) 3901 if (reader->curnode != NULL)
3869 cur = reader->curnode; 3902 cur = reader->curnode;
3870 else 3903 else
3871 cur = reader->node; 3904 cur = reader->node;
3872 if (cur == NULL) 3905 if (cur == NULL)
3873 return(NULL); 3906 return(NULL);
3874 3907
3875 if ((cur->type != XML_DOCUMENT_NODE) && (cur->type != XML_DTD_NODE)) { 3908 if ((cur->type != XML_DOCUMENT_NODE) && (cur->type != XML_DTD_NODE)) {
3876 cur->extra |= NODE_IS_PRESERVED; 3909 cur->extra |= NODE_IS_PRESERVED;
3877 cur->extra |= NODE_IS_SPRESERVED; 3910 cur->extra |= NODE_IS_SPRESERVED;
3878 } 3911 }
3879 reader->preserves++; 3912 reader->preserves++;
3880 3913
3881 parent = cur->parent;; 3914 parent = cur->parent;;
3882 while (parent != NULL) { 3915 while (parent != NULL) {
3883 if (parent->type == XML_ELEMENT_NODE) 3916 if (parent->type == XML_ELEMENT_NODE)
3884 parent->extra |= NODE_IS_PRESERVED; 3917 parent->extra |= NODE_IS_PRESERVED;
3885 parent = parent->parent; 3918 parent = parent->parent;
3886 } 3919 }
3887 return(cur); 3920 return(cur);
3888 } 3921 }
3889 3922
3890 #ifdef LIBXML_PATTERN_ENABLED 3923 #ifdef LIBXML_PATTERN_ENABLED
3891 /** 3924 /**
3892 * xmlTextReaderPreservePattern: 3925 * xmlTextReaderPreservePattern:
3893 * @reader: the xmlTextReaderPtr used 3926 * @reader: the xmlTextReaderPtr used
3894 * @pattern: an XPath subset pattern 3927 * @pattern: an XPath subset pattern
3895 * @namespaces: the prefix definitions, array of [URI, prefix] or NULL 3928 * @namespaces: the prefix definitions, array of [URI, prefix] or NULL
3896 * 3929 *
3897 * This tells the XML Reader to preserve all nodes matched by the 3930 * This tells the XML Reader to preserve all nodes matched by the
3898 * pattern. The caller must also use xmlTextReaderCurrentDoc() to 3931 * pattern. The caller must also use xmlTextReaderCurrentDoc() to
3899 * keep an handle on the resulting document once parsing has finished 3932 * keep an handle on the resulting document once parsing has finished
3900 * 3933 *
3901 * Returns a positive number in case of success and -1 in case of error 3934 * Returns a positive number in case of success and -1 in case of error
3902 */ 3935 */
3903 int 3936 int
3904 xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern, 3937 xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern,
3905 const xmlChar **namespaces) 3938 const xmlChar **namespaces)
3906 { 3939 {
3907 xmlPatternPtr comp; 3940 xmlPatternPtr comp;
3908 3941
3909 if ((reader == NULL) || (pattern == NULL)) 3942 if ((reader == NULL) || (pattern == NULL))
3910 return(-1); 3943 return(-1);
3911 3944
3912 comp = xmlPatterncompile(pattern, reader->dict, 0, namespaces); 3945 comp = xmlPatterncompile(pattern, reader->dict, 0, namespaces);
3913 if (comp == NULL) 3946 if (comp == NULL)
3914 return(-1); 3947 return(-1);
3915 3948
3916 if (reader->patternMax <= 0) { 3949 if (reader->patternMax <= 0) {
3917 reader->patternMax = 4; 3950 reader->patternMax = 4;
3918 reader->patternTab = (xmlPatternPtr *) xmlMalloc(reader->patternMax * 3951 reader->patternTab = (xmlPatternPtr *) xmlMalloc(reader->patternMax *
3919 sizeof(reader->patternTab[0])); 3952 sizeof(reader->patternTab[0]));
3920 if (reader->patternTab == NULL) { 3953 if (reader->patternTab == NULL) {
3921 xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n"); 3954 xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n");
(...skipping 16 matching lines...) Expand all
3938 reader->patternTab[reader->patternNr] = comp; 3971 reader->patternTab[reader->patternNr] = comp;
3939 return(reader->patternNr++); 3972 return(reader->patternNr++);
3940 } 3973 }
3941 #endif 3974 #endif
3942 3975
3943 /** 3976 /**
3944 * xmlTextReaderCurrentDoc: 3977 * xmlTextReaderCurrentDoc:
3945 * @reader: the xmlTextReaderPtr used 3978 * @reader: the xmlTextReaderPtr used
3946 * 3979 *
3947 * Hacking interface allowing to get the xmlDocPtr correponding to the 3980 * Hacking interface allowing to get the xmlDocPtr correponding to the
3948 * current document being accessed by the xmlTextReader. 3981 * current document being accessed by the xmlTextReader.
3949 * NOTE: as a result of this call, the reader will not destroy the 3982 * NOTE: as a result of this call, the reader will not destroy the
3950 * associated XML document and calling xmlFreeDoc() on the result 3983 * associated XML document and calling xmlFreeDoc() on the result
3951 * is needed once the reader parsing has finished. 3984 * is needed once the reader parsing has finished.
3952 * 3985 *
3953 * Returns the xmlDocPtr or NULL in case of error. 3986 * Returns the xmlDocPtr or NULL in case of error.
3954 */ 3987 */
3955 xmlDocPtr 3988 xmlDocPtr
3956 xmlTextReaderCurrentDoc(xmlTextReaderPtr reader) { 3989 xmlTextReaderCurrentDoc(xmlTextReaderPtr reader) {
3957 if (reader == NULL) 3990 if (reader == NULL)
3958 return(NULL); 3991 return(NULL);
3959 if (reader->doc != NULL) 3992 if (reader->doc != NULL)
3960 return(reader->doc); 3993 return(reader->doc);
3961 if ((reader->ctxt == NULL) || (reader->ctxt->myDoc == NULL)) 3994 if ((reader->ctxt == NULL) || (reader->ctxt->myDoc == NULL))
3962 return(NULL); 3995 return(NULL);
3963 3996
3964 reader->preserve = 1; 3997 reader->preserve = 1;
3965 return(reader->ctxt->myDoc); 3998 return(reader->ctxt->myDoc);
3966 } 3999 }
3967 4000
3968 #ifdef LIBXML_SCHEMAS_ENABLED 4001 #ifdef LIBXML_SCHEMAS_ENABLED
4002 static char *xmlTextReaderBuildMessage(const char *msg, va_list ap);
3969 4003
3970 static char * 4004 static void XMLCDECL
3971 xmlTextReaderBuildMessage(const char *msg, va_list ap);
3972
3973 static void XMLCDECL
3974 xmlTextReaderValidityError(void *ctxt, const char *msg, ...); 4005 xmlTextReaderValidityError(void *ctxt, const char *msg, ...);
3975 4006
3976 static void XMLCDECL 4007 static void XMLCDECL
3977 xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...); 4008 xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...);
3978 4009
3979 static void XMLCDECL xmlTextReaderValidityErrorRelay(void *ctx, const char *msg, ...) 4010 static void XMLCDECL
4011 xmlTextReaderValidityErrorRelay(void *ctx, const char *msg, ...)
3980 { 4012 {
3981 » xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx; 4013 xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx;
3982 » char * str;
3983 » va_list ap;
3984 4014
3985 » va_start(ap,msg); 4015 char *str;
3986 » str = xmlTextReaderBuildMessage(msg,ap); 4016
3987 » if (!reader->errorFunc) { 4017 va_list ap;
3988 » » xmlTextReaderValidityError(ctx, "%s", str); 4018
3989 » } else { 4019 va_start(ap, msg);
3990 » » reader->errorFunc(reader->errorFuncArg, str, XML_PARSER_SEVERITY _VALIDITY_ERROR, NULL /* locator */); 4020 str = xmlTextReaderBuildMessage(msg, ap);
3991 » } 4021 if (!reader->errorFunc) {
3992 » if (str != NULL) 4022 xmlTextReaderValidityError(ctx, "%s", str);
3993 » » xmlFree(str); 4023 } else {
3994 » va_end(ap); 4024 reader->errorFunc(reader->errorFuncArg, str,
4025 XML_PARSER_SEVERITY_VALIDITY_ERROR,
4026 NULL /* locator */ );
4027 }
4028 if (str != NULL)
4029 xmlFree(str);
4030 va_end(ap);
3995 } 4031 }
3996 4032
3997 static void XMLCDECL xmlTextReaderValidityWarningRelay(void *ctx, const char *ms g, ...) 4033 static void XMLCDECL
4034 xmlTextReaderValidityWarningRelay(void *ctx, const char *msg, ...)
3998 { 4035 {
3999 » xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx; 4036 xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx;
4000 » char * str;
4001 » va_list ap;
4002 4037
4003 » va_start(ap,msg); 4038 char *str;
4004 » str = xmlTextReaderBuildMessage(msg,ap); 4039
4005 » if (!reader->errorFunc) { 4040 va_list ap;
4006 » » xmlTextReaderValidityWarning(ctx, "%s", str); 4041
4007 » } else { 4042 va_start(ap, msg);
4008 » » reader->errorFunc(reader->errorFuncArg, str, XML_PARSER_SEVERITY _VALIDITY_WARNING, NULL /* locator */); 4043 str = xmlTextReaderBuildMessage(msg, ap);
4009 » } 4044 if (!reader->errorFunc) {
4010 » if (str != NULL) 4045 xmlTextReaderValidityWarning(ctx, "%s", str);
4011 » » xmlFree(str); 4046 } else {
4012 » va_end(ap); 4047 reader->errorFunc(reader->errorFuncArg, str,
4048 XML_PARSER_SEVERITY_VALIDITY_WARNING,
4049 NULL /* locator */ );
4050 }
4051 if (str != NULL)
4052 xmlFree(str);
4053 va_end(ap);
4013 } 4054 }
4014 4055
4015 static void 4056 static void
4016 xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error); 4057 xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error);
4017 4058
4018 static void xmlTextReaderValidityStructuredRelay(void * userData, xmlErrorPtr er ror) 4059 static void
4060 xmlTextReaderValidityStructuredRelay(void *userData, xmlErrorPtr error)
4019 { 4061 {
4020 » xmlTextReaderPtr reader = (xmlTextReaderPtr) userData; 4062 xmlTextReaderPtr reader = (xmlTextReaderPtr) userData;
4021 4063
4022 » if (reader->sErrorFunc) { 4064 if (reader->sErrorFunc) {
4023 » » reader->sErrorFunc(reader->errorFuncArg, error); 4065 reader->sErrorFunc(reader->errorFuncArg, error);
4024 » } else { 4066 } else {
4025 » » xmlTextReaderStructuredError(reader, error); 4067 xmlTextReaderStructuredError(reader, error);
4026 » } 4068 }
4027 } 4069 }
4028
4029 /** 4070 /**
4030 * xmlTextReaderRelaxNGSetSchema: 4071 * xmlTextReaderRelaxNGSetSchema:
4031 * @reader: the xmlTextReaderPtr used 4072 * @reader: the xmlTextReaderPtr used
4032 * @schema: a precompiled RelaxNG schema 4073 * @schema: a precompiled RelaxNG schema
4033 * 4074 *
4034 * Use RelaxNG to validate the document as it is processed. 4075 * Use RelaxNG to validate the document as it is processed.
4035 * Activation is only possible before the first Read(). 4076 * Activation is only possible before the first Read().
4036 * if @schema is NULL, then RelaxNG validation is desactivated. 4077 * if @schema is NULL, then RelaxNG validation is desactivated.
4037 @ The @schema should not be freed until the reader is deallocated 4078 @ The @schema should not be freed until the reader is deallocated
4038 * or its use has been deactivated. 4079 * or its use has been deactivated.
(...skipping 29 matching lines...) Expand all
4068 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema); 4109 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema);
4069 if (reader->rngValidCtxt == NULL) 4110 if (reader->rngValidCtxt == NULL)
4070 return(-1); 4111 return(-1);
4071 if (reader->errorFunc != NULL) { 4112 if (reader->errorFunc != NULL) {
4072 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, 4113 xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
4073 xmlTextReaderValidityErrorRelay, 4114 xmlTextReaderValidityErrorRelay,
4074 xmlTextReaderValidityWarningRelay, 4115 xmlTextReaderValidityWarningRelay,
4075 reader); 4116 reader);
4076 } 4117 }
4077 if (reader->sErrorFunc != NULL) { 4118 if (reader->sErrorFunc != NULL) {
4078 » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4119 » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4079 xmlTextReaderValidityStructuredRelay, 4120 xmlTextReaderValidityStructuredRelay,
4080 reader); 4121 reader);
4081 } 4122 }
4082 reader->rngValidErrors = 0; 4123 reader->rngValidErrors = 0;
4083 reader->rngFullNode = NULL; 4124 reader->rngFullNode = NULL;
4084 reader->validate = XML_TEXTREADER_VALIDATE_RNG; 4125 reader->validate = XML_TEXTREADER_VALIDATE_RNG;
4085 return(0); 4126 return(0);
4086 } 4127 }
4087 4128
4088 /** 4129 /**
(...skipping 15 matching lines...) Expand all
4104 if (reader == NULL) 4145 if (reader == NULL)
4105 return(-1); 4146 return(-1);
4106 if (schema == NULL) { 4147 if (schema == NULL) {
4107 if (reader->xsdPlug != NULL) { 4148 if (reader->xsdPlug != NULL) {
4108 xmlSchemaSAXUnplug(reader->xsdPlug); 4149 xmlSchemaSAXUnplug(reader->xsdPlug);
4109 reader->xsdPlug = NULL; 4150 reader->xsdPlug = NULL;
4110 } 4151 }
4111 if (reader->xsdValidCtxt != NULL) { 4152 if (reader->xsdValidCtxt != NULL) {
4112 if (! reader->xsdPreserveCtxt) 4153 if (! reader->xsdPreserveCtxt)
4113 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); 4154 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);
4114 » reader->xsdValidCtxt = NULL;» 4155 » reader->xsdValidCtxt = NULL;
4115 } 4156 }
4116 reader->xsdPreserveCtxt = 0; 4157 reader->xsdPreserveCtxt = 0;
4117 if (reader->xsdSchemas != NULL) { 4158 if (reader->xsdSchemas != NULL) {
4118 xmlSchemaFree(reader->xsdSchemas); 4159 xmlSchemaFree(reader->xsdSchemas);
4119 reader->xsdSchemas = NULL; 4160 reader->xsdSchemas = NULL;
4120 » }» 4161 » }
4121 return(0); 4162 return(0);
4122 } 4163 }
4123 if (reader->mode != XML_TEXTREADER_MODE_INITIAL) 4164 if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
4124 return(-1); 4165 return(-1);
4125 if (reader->xsdPlug != NULL) { 4166 if (reader->xsdPlug != NULL) {
4126 xmlSchemaSAXUnplug(reader->xsdPlug); 4167 xmlSchemaSAXUnplug(reader->xsdPlug);
4127 reader->xsdPlug = NULL; 4168 reader->xsdPlug = NULL;
4128 } 4169 }
4129 if (reader->xsdValidCtxt != NULL) { 4170 if (reader->xsdValidCtxt != NULL) {
4130 if (! reader->xsdPreserveCtxt) 4171 if (! reader->xsdPreserveCtxt)
4131 » xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);» 4172 » xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);
4132 reader->xsdValidCtxt = NULL; 4173 reader->xsdValidCtxt = NULL;
4133 } 4174 }
4134 reader->xsdPreserveCtxt = 0; 4175 reader->xsdPreserveCtxt = 0;
4135 if (reader->xsdSchemas != NULL) { 4176 if (reader->xsdSchemas != NULL) {
4136 xmlSchemaFree(reader->xsdSchemas); 4177 xmlSchemaFree(reader->xsdSchemas);
4137 reader->xsdSchemas = NULL; 4178 reader->xsdSchemas = NULL;
4138 } 4179 }
4139 reader->xsdValidCtxt = xmlSchemaNewValidCtxt(schema); 4180 reader->xsdValidCtxt = xmlSchemaNewValidCtxt(schema);
4140 if (reader->xsdValidCtxt == NULL) { 4181 if (reader->xsdValidCtxt == NULL) {
4141 xmlSchemaFree(reader->xsdSchemas); 4182 xmlSchemaFree(reader->xsdSchemas);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4179 * 4220 *
4180 * Returns 0 in case the RelaxNG validation could be (de)activated and 4221 * Returns 0 in case the RelaxNG validation could be (de)activated and
4181 * -1 in case of error. 4222 * -1 in case of error.
4182 */ 4223 */
4183 int 4224 int
4184 xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { 4225 xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) {
4185 xmlRelaxNGParserCtxtPtr ctxt; 4226 xmlRelaxNGParserCtxtPtr ctxt;
4186 4227
4187 if (reader == NULL) 4228 if (reader == NULL)
4188 return(-1); 4229 return(-1);
4189 4230
4190 if (rng == NULL) { 4231 if (rng == NULL) {
4191 if (reader->rngValidCtxt != NULL) { 4232 if (reader->rngValidCtxt != NULL) {
4192 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 4233 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
4193 reader->rngValidCtxt = NULL; 4234 reader->rngValidCtxt = NULL;
4194 } 4235 }
4195 if (reader->rngSchemas != NULL) { 4236 if (reader->rngSchemas != NULL) {
4196 xmlRelaxNGFree(reader->rngSchemas); 4237 xmlRelaxNGFree(reader->rngSchemas);
4197 reader->rngSchemas = NULL; 4238 reader->rngSchemas = NULL;
4198 } 4239 }
4199 return(0); 4240 return(0);
4200 } 4241 }
4201 if (reader->mode != XML_TEXTREADER_MODE_INITIAL) 4242 if (reader->mode != XML_TEXTREADER_MODE_INITIAL)
4202 return(-1); 4243 return(-1);
4203 if (reader->rngSchemas != NULL) { 4244 if (reader->rngSchemas != NULL) {
4204 xmlRelaxNGFree(reader->rngSchemas); 4245 xmlRelaxNGFree(reader->rngSchemas);
4205 reader->rngSchemas = NULL; 4246 reader->rngSchemas = NULL;
4206 } 4247 }
4207 if (reader->rngValidCtxt != NULL) { 4248 if (reader->rngValidCtxt != NULL) {
4208 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); 4249 xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt);
4209 reader->rngValidCtxt = NULL; 4250 reader->rngValidCtxt = NULL;
4210 } 4251 }
4211 ctxt = xmlRelaxNGNewParserCtxt(rng); 4252 ctxt = xmlRelaxNGNewParserCtxt(rng);
4212 if (reader->errorFunc != NULL) { 4253 if (reader->errorFunc != NULL) {
4213 xmlRelaxNGSetParserErrors(ctxt, 4254 xmlRelaxNGSetParserErrors(ctxt,
4214 xmlTextReaderValidityErrorRelay, 4255 xmlTextReaderValidityErrorRelay,
4215 xmlTextReaderValidityWarningRelay, 4256 xmlTextReaderValidityWarningRelay,
4216 reader); 4257 reader);
4217 } 4258 }
4218 if (reader->sErrorFunc != NULL) { 4259 if (reader->sErrorFunc != NULL) {
4219 » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4260 » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4220 xmlTextReaderValidityStructuredRelay, 4261 xmlTextReaderValidityStructuredRelay,
4221 reader); 4262 reader);
4222 } 4263 }
4223 reader->rngSchemas = xmlRelaxNGParse(ctxt); 4264 reader->rngSchemas = xmlRelaxNGParse(ctxt);
4224 xmlRelaxNGFreeParserCtxt(ctxt); 4265 xmlRelaxNGFreeParserCtxt(ctxt);
4225 if (reader->rngSchemas == NULL) 4266 if (reader->rngSchemas == NULL)
4226 return(-1); 4267 return(-1);
4227 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas); 4268 reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas);
4228 if (reader->rngValidCtxt == NULL) { 4269 if (reader->rngValidCtxt == NULL) {
4229 xmlRelaxNGFree(reader->rngSchemas); 4270 xmlRelaxNGFree(reader->rngSchemas);
4230 reader->rngSchemas = NULL; 4271 reader->rngSchemas = NULL;
4231 return(-1); 4272 return(-1);
4232 } 4273 }
4233 if (reader->errorFunc != NULL) { 4274 if (reader->errorFunc != NULL) {
4234 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, 4275 xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
4235 xmlTextReaderValidityErrorRelay, 4276 xmlTextReaderValidityErrorRelay,
4236 xmlTextReaderValidityWarningRelay, 4277 xmlTextReaderValidityWarningRelay,
4237 reader); 4278 reader);
4238 } 4279 }
4239 if (reader->sErrorFunc != NULL) { 4280 if (reader->sErrorFunc != NULL) {
4240 » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4281 » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4241 xmlTextReaderValidityStructuredRelay, 4282 xmlTextReaderValidityStructuredRelay,
4242 reader); 4283 reader);
4243 } 4284 }
4244 reader->rngValidErrors = 0; 4285 reader->rngValidErrors = 0;
4245 reader->rngFullNode = NULL; 4286 reader->rngFullNode = NULL;
4246 reader->validate = XML_TEXTREADER_VALIDATE_RNG; 4287 reader->validate = XML_TEXTREADER_VALIDATE_RNG;
4247 return(0); 4288 return(0);
4248 } 4289 }
4249 4290
4250 /** 4291 /**
4251 * xmlTextReaderSchemaValidateInternal: 4292 * xmlTextReaderSchemaValidateInternal:
4252 * @reader: the xmlTextReaderPtr used 4293 * @reader: the xmlTextReaderPtr used
4253 * @xsd: the path to a W3C XSD schema or NULL 4294 * @xsd: the path to a W3C XSD schema or NULL
4254 * @ctxt: the XML Schema validation context or NULL 4295 * @ctxt: the XML Schema validation context or NULL
4255 * @options: options (not used yet) 4296 * @options: options (not used yet)
4256 * 4297 *
4257 * Validate the document as it is processed using XML Schema. 4298 * Validate the document as it is processed using XML Schema.
4258 * Activation is only possible before the first Read(). 4299 * Activation is only possible before the first Read().
4259 * If both @xsd and @ctxt are NULL then XML Schema validation is deactivated. 4300 * If both @xsd and @ctxt are NULL then XML Schema validation is deactivated.
4260 * 4301 *
4261 * Returns 0 in case the schemas validation could be (de)activated and 4302 * Returns 0 in case the schemas validation could be (de)activated and
4262 * -1 in case of error. 4303 * -1 in case of error.
4263 */ 4304 */
4264 static int 4305 static int
4265 xmlTextReaderSchemaValidateInternal(xmlTextReaderPtr reader, 4306 xmlTextReaderSchemaValidateInternal(xmlTextReaderPtr reader,
4266 const char *xsd, 4307 const char *xsd,
4267 xmlSchemaValidCtxtPtr ctxt, 4308 xmlSchemaValidCtxtPtr ctxt,
4268 int options ATTRIBUTE_UNUSED) 4309 int options ATTRIBUTE_UNUSED)
4269 { 4310 {
4270 if (reader == NULL) 4311 if (reader == NULL)
4271 return(-1); 4312 return(-1);
4272 4313
4273 if ((xsd != NULL) && (ctxt != NULL)) 4314 if ((xsd != NULL) && (ctxt != NULL))
4274 return(-1); 4315 return(-1);
4275 4316
4276 if (((xsd != NULL) || (ctxt != NULL)) && 4317 if (((xsd != NULL) || (ctxt != NULL)) &&
4277 ((reader->mode != XML_TEXTREADER_MODE_INITIAL) || 4318 ((reader->mode != XML_TEXTREADER_MODE_INITIAL) ||
4278 (reader->ctxt == NULL))) 4319 (reader->ctxt == NULL)))
4279 return(-1); 4320 return(-1);
4280 4321
4281 /* Cleanup previous validation stuff. */ 4322 /* Cleanup previous validation stuff. */
4282 if (reader->xsdPlug != NULL) { 4323 if (reader->xsdPlug != NULL) {
4283 xmlSchemaSAXUnplug(reader->xsdPlug); 4324 xmlSchemaSAXUnplug(reader->xsdPlug);
4284 reader->xsdPlug = NULL; 4325 reader->xsdPlug = NULL;
4285 } 4326 }
4286 if (reader->xsdValidCtxt != NULL) { 4327 if (reader->xsdValidCtxt != NULL) {
4287 if (! reader->xsdPreserveCtxt) 4328 if (! reader->xsdPreserveCtxt)
4288 » xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);» 4329 » xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);
4289 reader->xsdValidCtxt = NULL; 4330 reader->xsdValidCtxt = NULL;
4290 } 4331 }
4291 reader->xsdPreserveCtxt = 0; 4332 reader->xsdPreserveCtxt = 0;
4292 if (reader->xsdSchemas != NULL) { 4333 if (reader->xsdSchemas != NULL) {
4293 xmlSchemaFree(reader->xsdSchemas); 4334 xmlSchemaFree(reader->xsdSchemas);
4294 reader->xsdSchemas = NULL; 4335 reader->xsdSchemas = NULL;
4295 } 4336 }
4296 4337
4297 if ((xsd == NULL) && (ctxt == NULL)) { 4338 if ((xsd == NULL) && (ctxt == NULL)) {
4298 /* We just want to deactivate the validation, so get out. */ 4339 /* We just want to deactivate the validation, so get out. */
4299 return(0); 4340 return(0);
4300 } 4341 }
4301 4342
4302 if (xsd != NULL) { 4343 if (xsd != NULL) {
4303 xmlSchemaParserCtxtPtr pctxt; 4344 xmlSchemaParserCtxtPtr pctxt;
4304 /* Parse the schema and create validation environment. */ 4345 /* Parse the schema and create validation environment. */
4305 pctxt = xmlSchemaNewParserCtxt(xsd); 4346 pctxt = xmlSchemaNewParserCtxt(xsd);
4306 if (reader->errorFunc != NULL) { 4347 if (reader->errorFunc != NULL) {
4307 xmlSchemaSetParserErrors(pctxt, 4348 xmlSchemaSetParserErrors(pctxt,
4308 xmlTextReaderValidityErrorRelay, 4349 xmlTextReaderValidityErrorRelay,
4309 xmlTextReaderValidityWarningRelay, 4350 xmlTextReaderValidityWarningRelay,
4310 reader); 4351 reader);
4311 } 4352 }
(...skipping 11 matching lines...) Expand all
4323 &(reader->ctxt->sax), 4364 &(reader->ctxt->sax),
4324 &(reader->ctxt->userData)); 4365 &(reader->ctxt->userData));
4325 if (reader->xsdPlug == NULL) { 4366 if (reader->xsdPlug == NULL) {
4326 xmlSchemaFree(reader->xsdSchemas); 4367 xmlSchemaFree(reader->xsdSchemas);
4327 reader->xsdSchemas = NULL; 4368 reader->xsdSchemas = NULL;
4328 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt); 4369 xmlSchemaFreeValidCtxt(reader->xsdValidCtxt);
4329 reader->xsdValidCtxt = NULL; 4370 reader->xsdValidCtxt = NULL;
4330 return(-1); 4371 return(-1);
4331 } 4372 }
4332 } else { 4373 } else {
4333 » /* Use the given validation context. */» 4374 » /* Use the given validation context. */
4334 reader->xsdValidCtxt = ctxt; 4375 reader->xsdValidCtxt = ctxt;
4335 reader->xsdPreserveCtxt = 1; 4376 reader->xsdPreserveCtxt = 1;
4336 reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt, 4377 reader->xsdPlug = xmlSchemaSAXPlug(reader->xsdValidCtxt,
4337 &(reader->ctxt->sax), 4378 &(reader->ctxt->sax),
4338 &(reader->ctxt->userData)); 4379 &(reader->ctxt->userData));
4339 » if (reader->xsdPlug == NULL) {» 4380 » if (reader->xsdPlug == NULL) {
4340 reader->xsdValidCtxt = NULL; 4381 reader->xsdValidCtxt = NULL;
4341 reader->xsdPreserveCtxt = 0; 4382 reader->xsdPreserveCtxt = 0;
4342 return(-1); 4383 return(-1);
4343 } 4384 }
4344 } 4385 }
4345 /* 4386 /*
4346 * Redirect the validation context's error channels to use 4387 * Redirect the validation context's error channels to use
4347 * the reader channels. 4388 * the reader channels.
4348 * TODO: In case the user provides the validation context we 4389 * TODO: In case the user provides the validation context we
4349 * could make this redirection optional. 4390 * could make this redirection optional.
4350 */ 4391 */
4351 if (reader->errorFunc != NULL) { 4392 if (reader->errorFunc != NULL) {
4352 xmlSchemaSetValidErrors(reader->xsdValidCtxt, 4393 xmlSchemaSetValidErrors(reader->xsdValidCtxt,
4353 xmlTextReaderValidityErrorRelay, 4394 xmlTextReaderValidityErrorRelay,
4354 xmlTextReaderValidityWarningRelay, 4395 xmlTextReaderValidityWarningRelay,
4355 reader); 4396 reader);
4356 } 4397 }
4357 if (reader->sErrorFunc != NULL) { 4398 if (reader->sErrorFunc != NULL) {
4358 » » xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, 4399 » » xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt,
4359 xmlTextReaderValidityStructuredRelay, 4400 xmlTextReaderValidityStructuredRelay,
4360 reader); 4401 reader);
4361 } 4402 }
4362 reader->xsdValidErrors = 0; 4403 reader->xsdValidErrors = 0;
4363 reader->validate = XML_TEXTREADER_VALIDATE_XSD; 4404 reader->validate = XML_TEXTREADER_VALIDATE_XSD;
4364 return(0); 4405 return(0);
4365 } 4406 }
4366 4407
4367 /** 4408 /**
4368 * xmlTextReaderSchemaValidateCtxt: 4409 * xmlTextReaderSchemaValidateCtxt:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4419 xmlTextReaderIsNamespaceDecl(xmlTextReaderPtr reader) { 4460 xmlTextReaderIsNamespaceDecl(xmlTextReaderPtr reader) {
4420 xmlNodePtr node; 4461 xmlNodePtr node;
4421 if (reader == NULL) 4462 if (reader == NULL)
4422 return(-1); 4463 return(-1);
4423 if (reader->node == NULL) 4464 if (reader->node == NULL)
4424 return(-1); 4465 return(-1);
4425 if (reader->curnode != NULL) 4466 if (reader->curnode != NULL)
4426 node = reader->curnode; 4467 node = reader->curnode;
4427 else 4468 else
4428 node = reader->node; 4469 node = reader->node;
4429 4470
4430 if (XML_NAMESPACE_DECL == node->type) 4471 if (XML_NAMESPACE_DECL == node->type)
4431 return(1); 4472 return(1);
4432 else 4473 else
4433 return(0); 4474 return(0);
4434 } 4475 }
4435 4476
4436 /** 4477 /**
4437 * xmlTextReaderConstXmlVersion: 4478 * xmlTextReaderConstXmlVersion:
4438 * @reader: the xmlTextReaderPtr used 4479 * @reader: the xmlTextReaderPtr used
4439 * 4480 *
4440 * Determine the XML version of the document being read. 4481 * Determine the XML version of the document being read.
4441 * 4482 *
4442 * Returns a string containing the XML version of the document or NULL 4483 * Returns a string containing the XML version of the document or NULL
4443 * in case of error. The string is deallocated with the reader. 4484 * in case of error. The string is deallocated with the reader.
4444 */ 4485 */
4445 const xmlChar * 4486 const xmlChar *
4446 xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader) { 4487 xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader) {
4447 xmlDocPtr doc = NULL; 4488 xmlDocPtr doc = NULL;
4448 if (reader == NULL) 4489 if (reader == NULL)
4449 return(NULL); 4490 return(NULL);
4450 if (reader->doc != NULL) 4491 if (reader->doc != NULL)
4451 doc = reader->doc; 4492 doc = reader->doc;
4452 else if (reader->ctxt != NULL) 4493 else if (reader->ctxt != NULL)
4453 » doc = reader->ctxt->myDoc; 4494 » doc = reader->ctxt->myDoc;
4454 if (doc == NULL) 4495 if (doc == NULL)
4455 return(NULL); 4496 return(NULL);
4456 4497
4457 if (doc->version == NULL) 4498 if (doc->version == NULL)
4458 return(NULL); 4499 return(NULL);
4459 else 4500 else
4460 return(CONSTSTR(doc->version)); 4501 return(CONSTSTR(doc->version));
4461 } 4502 }
4462 4503
4463 /** 4504 /**
4464 * xmlTextReaderStandalone: 4505 * xmlTextReaderStandalone:
4465 * @reader: the xmlTextReaderPtr used 4506 * @reader: the xmlTextReaderPtr used
4466 * 4507 *
(...skipping 20 matching lines...) Expand all
4487 4528
4488 /************************************************************************ 4529 /************************************************************************
4489 * * 4530 * *
4490 * Error Handling Extensions * 4531 * Error Handling Extensions *
4491 * * 4532 * *
4492 ************************************************************************/ 4533 ************************************************************************/
4493 4534
4494 /* helper to build a xmlMalloc'ed string from a format and va_list */ 4535 /* helper to build a xmlMalloc'ed string from a format and va_list */
4495 static char * 4536 static char *
4496 xmlTextReaderBuildMessage(const char *msg, va_list ap) { 4537 xmlTextReaderBuildMessage(const char *msg, va_list ap) {
4497 int size; 4538 int size = 0;
4498 int chars; 4539 int chars;
4499 char *larger; 4540 char *larger;
4500 char *str; 4541 char *str = NULL;
4501 4542 va_list aq;
4502 str = (char *) xmlMallocAtomic(150);
4503 if (str == NULL) {
4504 » xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n");
4505 return NULL;
4506 }
4507
4508 size = 150;
4509 4543
4510 while (1) { 4544 while (1) {
4511 chars = vsnprintf(str, size, msg, ap); 4545 VA_COPY(aq, ap);
4512 if ((chars > -1) && (chars < size)) 4546 chars = vsnprintf(str, size, msg, aq);
4547 va_end(aq);
4548 if (chars < 0) {
4549 » xmlGenericError(xmlGenericErrorContext, "vsnprintf failed !\n");
4550 » if (str)
4551 » » xmlFree(str);
4552 » return NULL;
4553 » }
4554 » if ((chars < size) || (size == MAX_ERR_MSG_SIZE))
4513 break; 4555 break;
4514 if (chars > -1) 4556 if (chars < MAX_ERR_MSG_SIZE)
4515 size += chars + 1; 4557 » size = chars + 1;
4516 else 4558 » else
4517 size += 100; 4559 » » size = MAX_ERR_MSG_SIZE;
4518 if ((larger = (char *) xmlRealloc(str, size)) == NULL) { 4560 if ((larger = (char *) xmlRealloc(str, size)) == NULL) {
4519 xmlGenericError(xmlGenericErrorContext, "xmlRealloc failed !\n"); 4561 xmlGenericError(xmlGenericErrorContext, "xmlRealloc failed !\n");
4520 xmlFree(str); 4562 » if (str)
4563 xmlFree(str);
4521 return NULL; 4564 return NULL;
4522 } 4565 }
4523 str = larger; 4566 str = larger;
4524 } 4567 }
4525 4568
4526 return str; 4569 return str;
4527 } 4570 }
4528 4571
4529 /** 4572 /**
4530 * xmlTextReaderLocatorLineNumber: 4573 * xmlTextReaderLocatorLineNumber:
(...skipping 15 matching lines...) Expand all
4546 ret = xmlGetLineNo(ctx->node); 4589 ret = xmlGetLineNo(ctx->node);
4547 } 4590 }
4548 else { 4591 else {
4549 /* inspired from error.c */ 4592 /* inspired from error.c */
4550 xmlParserInputPtr input; 4593 xmlParserInputPtr input;
4551 input = ctx->input; 4594 input = ctx->input;
4552 if ((input->filename == NULL) && (ctx->inputNr > 1)) 4595 if ((input->filename == NULL) && (ctx->inputNr > 1))
4553 input = ctx->inputTab[ctx->inputNr - 2]; 4596 input = ctx->inputTab[ctx->inputNr - 2];
4554 if (input != NULL) { 4597 if (input != NULL) {
4555 ret = input->line; 4598 ret = input->line;
4556 » } 4599 » }
4557 else { 4600 else {
4558 ret = -1; 4601 ret = -1;
4559 } 4602 }
4560 } 4603 }
4561 4604
4562 return ret; 4605 return ret;
4563 } 4606 }
4564 4607
4565 /** 4608 /**
4566 * xmlTextReaderLocatorBaseURI: 4609 * xmlTextReaderLocatorBaseURI:
4567 * @locator: the xmlTextReaderLocatorPtr used 4610 * @locator: the xmlTextReaderLocatorPtr used
4568 * 4611 *
4569 * Obtain the base URI for the given locator. 4612 * Obtain the base URI for the given locator.
4570 * 4613 *
4571 * Returns the base URI or NULL in case of error. 4614 * Returns the base URI or NULL in case of error,
4615 * if non NULL it need to be freed by the caller.
4572 */ 4616 */
4573 xmlChar * 4617 xmlChar *
4574 xmlTextReaderLocatorBaseURI(xmlTextReaderLocatorPtr locator) { 4618 xmlTextReaderLocatorBaseURI(xmlTextReaderLocatorPtr locator) {
4575 /* we know that locator is a xmlParserCtxtPtr */ 4619 /* we know that locator is a xmlParserCtxtPtr */
4576 xmlParserCtxtPtr ctx = (xmlParserCtxtPtr)locator; 4620 xmlParserCtxtPtr ctx = (xmlParserCtxtPtr)locator;
4577 xmlChar *ret = NULL; 4621 xmlChar *ret = NULL;
4578 4622
4579 if (locator == NULL) 4623 if (locator == NULL)
4580 return(NULL); 4624 return(NULL);
4581 if (ctx->node != NULL) { 4625 if (ctx->node != NULL) {
4582 ret = xmlNodeGetBase(NULL,ctx->node); 4626 ret = xmlNodeGetBase(NULL,ctx->node);
4583 } 4627 }
4584 else { 4628 else {
4585 /* inspired from error.c */ 4629 /* inspired from error.c */
4586 xmlParserInputPtr input; 4630 xmlParserInputPtr input;
4587 input = ctx->input; 4631 input = ctx->input;
4588 if ((input->filename == NULL) && (ctx->inputNr > 1)) 4632 if ((input->filename == NULL) && (ctx->inputNr > 1))
4589 input = ctx->inputTab[ctx->inputNr - 2]; 4633 input = ctx->inputTab[ctx->inputNr - 2];
4590 if (input != NULL) { 4634 if (input != NULL) {
4591 ret = xmlStrdup(BAD_CAST input->filename); 4635 ret = xmlStrdup(BAD_CAST input->filename);
4592 » } 4636 » }
4593 else { 4637 else {
4594 ret = NULL; 4638 ret = NULL;
4595 } 4639 }
4596 } 4640 }
4597 4641
4598 return ret; 4642 return ret;
4599 } 4643 }
4600 4644
4601 static void 4645 static void
4602 xmlTextReaderGenericError(void *ctxt, xmlParserSeverities severity, char *str) { 4646 xmlTextReaderGenericError(void *ctxt, xmlParserSeverities severity,
4603 xmlParserCtxtPtr ctx = (xmlParserCtxtPtr)ctxt; 4647 char *str)
4604 xmlTextReaderPtr reader = (xmlTextReaderPtr)ctx->_private; 4648 {
4649 xmlParserCtxtPtr ctx = (xmlParserCtxtPtr) ctxt;
4650
4651 xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx->_private;
4605 4652
4606 if (str != NULL) { 4653 if (str != NULL) {
4607 if (reader->errorFunc) 4654 if (reader->errorFunc)
4608 » reader->errorFunc(reader->errorFuncArg, 4655 reader->errorFunc(reader->errorFuncArg, str, severity,
4609 » » » str, 4656 (xmlTextReaderLocatorPtr) ctx);
4610 » » » severity, 4657 xmlFree(str);
4611 » » » (xmlTextReaderLocatorPtr)ctx);
4612 » xmlFree(str);
4613 } 4658 }
4614 } 4659 }
4615 4660
4616 static void 4661 static void
4617 xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error) { 4662 xmlTextReaderStructuredError(void *ctxt, xmlErrorPtr error)
4618 xmlParserCtxtPtr ctx = (xmlParserCtxtPtr) ctxt; 4663 {
4619 xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx->_private; 4664 xmlParserCtxtPtr ctx = (xmlParserCtxtPtr) ctxt;
4620 4665
4621 if (error && reader->sErrorFunc) { 4666 xmlTextReaderPtr reader = (xmlTextReaderPtr) ctx->_private;
4622 » reader->sErrorFunc(reader->errorFuncArg, 4667
4623 » » » (xmlErrorPtr) error); 4668 if (error && reader->sErrorFunc) {
4624 } 4669 reader->sErrorFunc(reader->errorFuncArg, (xmlErrorPtr) error);
4670 }
4625 } 4671 }
4626 4672
4627 static void XMLCDECL 4673 static void XMLCDECL
4628 xmlTextReaderError(void *ctxt, const char *msg, ...) { 4674 xmlTextReaderError(void *ctxt, const char *msg, ...)
4675 {
4629 va_list ap; 4676 va_list ap;
4630 4677
4631 va_start(ap,msg); 4678 va_start(ap, msg);
4632 xmlTextReaderGenericError(ctxt, 4679 xmlTextReaderGenericError(ctxt,
4633 XML_PARSER_SEVERITY_ERROR, 4680 XML_PARSER_SEVERITY_ERROR,
4634 » xmlTextReaderBuildMessage(msg,ap)); 4681 xmlTextReaderBuildMessage(msg, ap));
4635 va_end(ap); 4682 va_end(ap);
4636 4683
4637 } 4684 }
4638 4685
4639 static void XMLCDECL 4686 static void XMLCDECL
4640 xmlTextReaderWarning(void *ctxt, const char *msg, ...) { 4687 xmlTextReaderWarning(void *ctxt, const char *msg, ...)
4688 {
4641 va_list ap; 4689 va_list ap;
4642 4690
4643 va_start(ap,msg); 4691 va_start(ap, msg);
4644 xmlTextReaderGenericError(ctxt, 4692 xmlTextReaderGenericError(ctxt,
4645 XML_PARSER_SEVERITY_WARNING, 4693 XML_PARSER_SEVERITY_WARNING,
4646 » xmlTextReaderBuildMessage(msg,ap)); 4694 xmlTextReaderBuildMessage(msg, ap));
4647 va_end(ap); 4695 va_end(ap);
4648 } 4696 }
4649 4697
4650 static void XMLCDECL 4698 static void XMLCDECL
4651 xmlTextReaderValidityError(void *ctxt, const char *msg, ...) { 4699 xmlTextReaderValidityError(void *ctxt, const char *msg, ...)
4700 {
4652 va_list ap; 4701 va_list ap;
4702
4653 int len = xmlStrlen((const xmlChar *) msg); 4703 int len = xmlStrlen((const xmlChar *) msg);
4654 4704
4655 if ((len > 1) && (msg[len - 2] != ':')) { 4705 if ((len > 1) && (msg[len - 2] != ':')) {
4656 » /* 4706 /*
4657 » * some callbacks only report locator information: 4707 * some callbacks only report locator information:
4658 » * skip them (mimicking behaviour in error.c) 4708 * skip them (mimicking behaviour in error.c)
4659 » */ 4709 */
4660 » va_start(ap,msg); 4710 va_start(ap, msg);
4661 » xmlTextReaderGenericError(ctxt, 4711 xmlTextReaderGenericError(ctxt,
4662 » » » » XML_PARSER_SEVERITY_VALIDITY_ERROR, 4712 XML_PARSER_SEVERITY_VALIDITY_ERROR,
4663 » » » » xmlTextReaderBuildMessage(msg,ap)); 4713 xmlTextReaderBuildMessage(msg, ap));
4664 » va_end(ap); 4714 va_end(ap);
4665 } 4715 }
4666 } 4716 }
4667 4717
4668 static void XMLCDECL 4718 static void XMLCDECL
4669 xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...) { 4719 xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...)
4720 {
4670 va_list ap; 4721 va_list ap;
4722
4671 int len = xmlStrlen((const xmlChar *) msg); 4723 int len = xmlStrlen((const xmlChar *) msg);
4672 4724
4673 if ((len != 0) && (msg[len - 1] != ':')) { 4725 if ((len != 0) && (msg[len - 1] != ':')) {
4674 » /* 4726 /*
4675 » * some callbacks only report locator information: 4727 * some callbacks only report locator information:
4676 » * skip them (mimicking behaviour in error.c) 4728 * skip them (mimicking behaviour in error.c)
4677 » */ 4729 */
4678 » va_start(ap,msg); 4730 va_start(ap, msg);
4679 » xmlTextReaderGenericError(ctxt, 4731 xmlTextReaderGenericError(ctxt,
4680 » » » » XML_PARSER_SEVERITY_VALIDITY_WARNING, 4732 XML_PARSER_SEVERITY_VALIDITY_WARNING,
4681 » » » » xmlTextReaderBuildMessage(msg,ap)); 4733 xmlTextReaderBuildMessage(msg, ap));
4682 » va_end(ap); 4734 va_end(ap);
4683 } 4735 }
4684 } 4736 }
4685 4737
4686 /** 4738 /**
4687 * xmlTextReaderSetErrorHandler: 4739 * xmlTextReaderSetErrorHandler:
4688 * @reader: the xmlTextReaderPtr used 4740 * @reader: the xmlTextReaderPtr used
4689 * @f: the callback function to call on error and warnings 4741 * @f: the callback function to call on error and warnings
4690 * @arg: a user argument to pass to the callback function 4742 * @arg: a user argument to pass to the callback function
4691 * 4743 *
4692 * Register a callback function that will be called on error and warnings. 4744 * Register a callback function that will be called on error and warnings.
4693 * 4745 *
4694 * If @f is NULL, the default error and warning handlers are restored. 4746 * If @f is NULL, the default error and warning handlers are restored.
4695 */ 4747 */
4696 void 4748 void
4697 xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader, 4749 xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader,
4698 » » » xmlTextReaderErrorFunc f, 4750 xmlTextReaderErrorFunc f, void *arg)
4699 » » » void *arg) { 4751 {
4700 if (f != NULL) { 4752 if (f != NULL) {
4701 » reader->ctxt->sax->error = xmlTextReaderError; 4753 reader->ctxt->sax->error = xmlTextReaderError;
4702 » reader->ctxt->sax->serror = NULL; 4754 reader->ctxt->sax->serror = NULL;
4703 » reader->ctxt->vctxt.error = xmlTextReaderValidityError; 4755 reader->ctxt->vctxt.error = xmlTextReaderValidityError;
4704 » reader->ctxt->sax->warning = xmlTextReaderWarning; 4756 reader->ctxt->sax->warning = xmlTextReaderWarning;
4705 » reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning; 4757 reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning;
4706 » reader->errorFunc = f; 4758 reader->errorFunc = f;
4707 » reader->sErrorFunc = NULL; 4759 reader->sErrorFunc = NULL;
4708 » reader->errorFuncArg = arg; 4760 reader->errorFuncArg = arg;
4709 #ifdef LIBXML_SCHEMAS_ENABLED 4761 #ifdef LIBXML_SCHEMAS_ENABLED
4710 » » if (reader->rngValidCtxt) { 4762 if (reader->rngValidCtxt) {
4711 » » » xmlRelaxNGSetValidErrors(reader->rngValidCtxt, 4763 xmlRelaxNGSetValidErrors(reader->rngValidCtxt,
4712 » » » » xmlTextReaderValidityErrorRelay, 4764 xmlTextReaderValidityErrorRelay,
4713 » » » » xmlTextReaderValidityWarningRelay, 4765 xmlTextReaderValidityWarningRelay,
4714 » » » » reader); 4766 reader);
4715 » » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL, reader); 4767 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL,
4716 » » } 4768 reader);
4717 » » if (reader->xsdValidCtxt) { 4769 }
4718 » » » xmlSchemaSetValidErrors(reader->xsdValidCtxt, 4770 if (reader->xsdValidCtxt) {
4719 » » » » xmlTextReaderValidityErrorRelay, 4771 xmlSchemaSetValidErrors(reader->xsdValidCtxt,
4720 » » » » xmlTextReaderValidityWarningRelay, 4772 xmlTextReaderValidityErrorRelay,
4721 » » » » reader); 4773 xmlTextReaderValidityWarningRelay,
4722 » » » xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL, reader); 4774 reader);
4723 » » } 4775 xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL,
4776 reader);
4777 }
4724 #endif 4778 #endif
4725 } 4779 } else {
4726 else { 4780 /* restore defaults */
4727 » /* restore defaults */ 4781 reader->ctxt->sax->error = xmlParserError;
4728 » reader->ctxt->sax->error = xmlParserError; 4782 reader->ctxt->vctxt.error = xmlParserValidityError;
4729 » reader->ctxt->vctxt.error = xmlParserValidityError; 4783 reader->ctxt->sax->warning = xmlParserWarning;
4730 » reader->ctxt->sax->warning = xmlParserWarning; 4784 reader->ctxt->vctxt.warning = xmlParserValidityWarning;
4731 » reader->ctxt->vctxt.warning = xmlParserValidityWarning; 4785 reader->errorFunc = NULL;
4732 » reader->errorFunc = NULL; 4786 reader->sErrorFunc = NULL;
4733 » reader->sErrorFunc = NULL; 4787 reader->errorFuncArg = NULL;
4734 » reader->errorFuncArg = NULL;
4735 #ifdef LIBXML_SCHEMAS_ENABLED 4788 #ifdef LIBXML_SCHEMAS_ENABLED
4736 » » if (reader->rngValidCtxt) { 4789 if (reader->rngValidCtxt) {
4737 » » » xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NUL L, reader); 4790 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NULL,
4738 » » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL, reader); 4791 reader);
4739 » » } 4792 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL,
4740 » » if (reader->xsdValidCtxt) { 4793 reader);
4741 » » » xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL , reader); 4794 }
4742 » » » xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL, reader); 4795 if (reader->xsdValidCtxt) {
4743 » » } 4796 xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL,
4797 reader);
4798 xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL,
4799 reader);
4800 }
4744 #endif 4801 #endif
4745 } 4802 }
4746 } 4803 }
4747 4804
4748 /** 4805 /**
4749 * xmlTextReaderSetStructuredErrorHandler: 4806 * xmlTextReaderSetStructuredErrorHandler:
4750 * @reader: the xmlTextReaderPtr used 4807 * @reader: the xmlTextReaderPtr used
4751 * @f: the callback function to call on error and warnings 4808 * @f: the callback function to call on error and warnings
4752 * @arg: a user argument to pass to the callback function 4809 * @arg: a user argument to pass to the callback function
4753 * 4810 *
4754 * Register a callback function that will be called on error and warnings. 4811 * Register a callback function that will be called on error and warnings.
4755 * 4812 *
4756 * If @f is NULL, the default error and warning handlers are restored. 4813 * If @f is NULL, the default error and warning handlers are restored.
4757 */ 4814 */
4758 void 4815 void
4759 xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader, 4816 xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader,
4760 » » » » » xmlStructuredErrorFunc f, 4817 xmlStructuredErrorFunc f, void *arg)
4761 » » » » » void *arg) { 4818 {
4762 if (f != NULL) { 4819 if (f != NULL) {
4763 » reader->ctxt->sax->error = NULL; 4820 reader->ctxt->sax->error = NULL;
4764 » reader->ctxt->sax->serror = xmlTextReaderStructuredError; 4821 reader->ctxt->sax->serror = xmlTextReaderStructuredError;
4765 » reader->ctxt->vctxt.error = xmlTextReaderValidityError; 4822 reader->ctxt->vctxt.error = xmlTextReaderValidityError;
4766 » reader->ctxt->sax->warning = xmlTextReaderWarning; 4823 reader->ctxt->sax->warning = xmlTextReaderWarning;
4767 » reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning; 4824 reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning;
4768 » reader->sErrorFunc = f; 4825 reader->sErrorFunc = f;
4769 » reader->errorFunc = NULL; 4826 reader->errorFunc = NULL;
4770 » reader->errorFuncArg = arg; 4827 reader->errorFuncArg = arg;
4771 #ifdef LIBXML_SCHEMAS_ENABLED 4828 #ifdef LIBXML_SCHEMAS_ENABLED
4772 » » if (reader->rngValidCtxt) { 4829 if (reader->rngValidCtxt) {
4773 » » » xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NUL L, reader); 4830 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NULL,
4774 » » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, 4831 reader);
4775 » » » » xmlTextReaderValidityStructuredRelay, 4832 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt,
4776 » » » » reader); 4833 xmlTextReaderValidityStructuredRelay,
4777 » » } 4834 reader);
4778 » » if (reader->xsdValidCtxt) { 4835 }
4779 » » » xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL , reader); 4836 if (reader->xsdValidCtxt) {
4780 » » » xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, 4837 xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL,
4781 » » » » xmlTextReaderValidityStructuredRelay, 4838 reader);
4782 » » » » reader); 4839 xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt,
4783 » » } 4840 xmlTextReaderValidityStructuredRelay,
4841 reader);
4842 }
4784 #endif 4843 #endif
4785 } 4844 } else {
4786 else { 4845 /* restore defaults */
4787 » /* restore defaults */ 4846 reader->ctxt->sax->error = xmlParserError;
4788 » reader->ctxt->sax->error = xmlParserError; 4847 reader->ctxt->sax->serror = NULL;
4789 » reader->ctxt->sax->serror = NULL; 4848 reader->ctxt->vctxt.error = xmlParserValidityError;
4790 » reader->ctxt->vctxt.error = xmlParserValidityError; 4849 reader->ctxt->sax->warning = xmlParserWarning;
4791 » reader->ctxt->sax->warning = xmlParserWarning; 4850 reader->ctxt->vctxt.warning = xmlParserValidityWarning;
4792 » reader->ctxt->vctxt.warning = xmlParserValidityWarning; 4851 reader->errorFunc = NULL;
4793 » reader->errorFunc = NULL; 4852 reader->sErrorFunc = NULL;
4794 » reader->sErrorFunc = NULL; 4853 reader->errorFuncArg = NULL;
4795 » reader->errorFuncArg = NULL;
4796 #ifdef LIBXML_SCHEMAS_ENABLED 4854 #ifdef LIBXML_SCHEMAS_ENABLED
4797 » » if (reader->rngValidCtxt) { 4855 if (reader->rngValidCtxt) {
4798 » » » xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NUL L, reader); 4856 xmlRelaxNGSetValidErrors(reader->rngValidCtxt, NULL, NULL,
4799 » » » xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL, reader); 4857 reader);
4800 » » } 4858 xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, NULL,
4801 » » if (reader->xsdValidCtxt) { 4859 reader);
4802 » » » xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL , reader); 4860 }
4803 » » » xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL, reader); 4861 if (reader->xsdValidCtxt) {
4804 » » } 4862 xmlSchemaSetValidErrors(reader->xsdValidCtxt, NULL, NULL,
4863 reader);
4864 xmlSchemaSetValidStructuredErrors(reader->xsdValidCtxt, NULL,
4865 reader);
4866 }
4805 #endif 4867 #endif
4806 } 4868 }
4807 } 4869 }
4808 4870
4809 /** 4871 /**
4810 * xmlTextReaderIsValid: 4872 * xmlTextReaderIsValid:
4811 * @reader: the xmlTextReaderPtr used 4873 * @reader: the xmlTextReaderPtr used
4812 * 4874 *
4813 * Retrieve the validity status from the parser context 4875 * Retrieve the validity status from the parser context
4814 * 4876 *
4815 * Returns the flag value 1 if valid, 0 if no, and -1 in case of error 4877 * Returns the flag value 1 if valid, 0 if no, and -1 in case of error
4816 */ 4878 */
4817 int 4879 int
4818 xmlTextReaderIsValid(xmlTextReaderPtr reader) { 4880 xmlTextReaderIsValid(xmlTextReaderPtr reader)
4819 if (reader == NULL) return(-1); 4881 {
4882 if (reader == NULL)
4883 return (-1);
4820 #ifdef LIBXML_SCHEMAS_ENABLED 4884 #ifdef LIBXML_SCHEMAS_ENABLED
4821 if (reader->validate == XML_TEXTREADER_VALIDATE_RNG) 4885 if (reader->validate == XML_TEXTREADER_VALIDATE_RNG)
4822 return(reader->rngValidErrors == 0); 4886 return (reader->rngValidErrors == 0);
4823 if (reader->validate == XML_TEXTREADER_VALIDATE_XSD) 4887 if (reader->validate == XML_TEXTREADER_VALIDATE_XSD)
4824 return(reader->xsdValidErrors == 0); 4888 return (reader->xsdValidErrors == 0);
4825 #endif 4889 #endif
4826 if ((reader->ctxt != NULL) && (reader->ctxt->validate == 1)) 4890 if ((reader->ctxt != NULL) && (reader->ctxt->validate == 1))
4827 » return(reader->ctxt->valid); 4891 return (reader->ctxt->valid);
4828 return(0); 4892 return (0);
4829 } 4893 }
4830 4894
4831 /** 4895 /**
4832 * xmlTextReaderGetErrorHandler: 4896 * xmlTextReaderGetErrorHandler:
4833 * @reader: the xmlTextReaderPtr used 4897 * @reader: the xmlTextReaderPtr used
4834 * @f: the callback function or NULL is no callback has been registered 4898 * @f: the callback function or NULL is no callback has been registered
4835 * @arg: a user argument 4899 * @arg: a user argument
4836 * 4900 *
4837 * Retrieve the error callback function and user argument. 4901 * Retrieve the error callback function and user argument.
4838 */ 4902 */
4839 void 4903 void
4840 xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader, 4904 xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader,
4841 » » » xmlTextReaderErrorFunc *f, 4905 xmlTextReaderErrorFunc * f, void **arg)
4842 » » » void **arg) { 4906 {
4843 if (f != NULL) *f = reader->errorFunc; 4907 if (f != NULL)
4844 if (arg != NULL) *arg = reader->errorFuncArg; 4908 *f = reader->errorFunc;
4909 if (arg != NULL)
4910 *arg = reader->errorFuncArg;
4845 } 4911 }
4846
4847
4848 /************************************************************************ 4912 /************************************************************************
4849 * * 4913 * *
4850 * New set (2.6.0) of simpler and more flexible APIs * 4914 * New set (2.6.0) of simpler and more flexible APIs *
4851 * * 4915 * *
4852 ************************************************************************/ 4916 ************************************************************************/
4853 4917
4854 /** 4918 /**
4855 * xmlTextReaderSetup: 4919 * xmlTextReaderSetup:
4856 * @reader: an XML reader 4920 * @reader: an XML reader
4857 * @input: xmlParserInputBufferPtr used to feed the reader, will 4921 * @input: xmlParserInputBufferPtr used to feed the reader, will
4858 * be destroyed with it. 4922 * be destroyed with it.
4859 * @URL: the base URL to use for the document 4923 * @URL: the base URL to use for the document
4860 * @encoding: the document encoding, or NULL 4924 * @encoding: the document encoding, or NULL
4861 * @options: a combination of xmlParserOption 4925 * @options: a combination of xmlParserOption
4862 * 4926 *
4863 * Setup an XML reader with new options 4927 * Setup an XML reader with new options
4864 * 4928 *
4865 * Returns 0 in case of success and -1 in case of error. 4929 * Returns 0 in case of success and -1 in case of error.
4866 */ 4930 */
4867 int 4931 int
4868 xmlTextReaderSetup(xmlTextReaderPtr reader, 4932 xmlTextReaderSetup(xmlTextReaderPtr reader,
4869 xmlParserInputBufferPtr input, const char *URL, 4933 xmlParserInputBufferPtr input, const char *URL,
4870 const char *encoding, int options) 4934 const char *encoding, int options)
4871 { 4935 {
4872 if (reader == NULL) { 4936 if (reader == NULL) {
4873 if (input != NULL) 4937 if (input != NULL)
4874 xmlFreeParserInputBuffer(input); 4938 xmlFreeParserInputBuffer(input);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 } 5031 }
4968 5032
4969 if (URL == NULL) 5033 if (URL == NULL)
4970 inputStream->filename = NULL; 5034 inputStream->filename = NULL;
4971 else 5035 else
4972 inputStream->filename = (char *) 5036 inputStream->filename = (char *)
4973 xmlCanonicPath((const xmlChar *) URL); 5037 xmlCanonicPath((const xmlChar *) URL);
4974 inputStream->buf = buf; 5038 inputStream->buf = buf;
4975 inputStream->base = inputStream->buf->buffer->content; 5039 inputStream->base = inputStream->buf->buffer->content;
4976 inputStream->cur = inputStream->buf->buffer->content; 5040 inputStream->cur = inputStream->buf->buffer->content;
4977 » inputStream->end = 5041 » inputStream->end =
4978 » » &inputStream->buf->buffer->content[inputStream->buf->buffer->use ]; 5042 &inputStream->buf->buffer->content[inputStream->buf->buffer->use];
4979 5043
4980 inputPush(reader->ctxt, inputStream); 5044 inputPush(reader->ctxt, inputStream);
4981 reader->cur = 0; 5045 reader->cur = 0;
4982 } 5046 }
4983 if (reader->ctxt == NULL) { 5047 if (reader->ctxt == NULL) {
4984 xmlGenericError(xmlGenericErrorContext, 5048 xmlGenericError(xmlGenericErrorContext,
4985 "xmlTextReaderSetup : malloc failed\n"); 5049 "xmlTextReaderSetup : malloc failed\n");
4986 return (-1); 5050 return (-1);
4987 } 5051 }
4988 } 5052 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
5069 * 5133 *
5070 * Returns the index in bytes from the beginning of the entity or -1 5134 * Returns the index in bytes from the beginning of the entity or -1
5071 * in case the index could not be computed. 5135 * in case the index could not be computed.
5072 */ 5136 */
5073 long 5137 long
5074 xmlTextReaderByteConsumed(xmlTextReaderPtr reader) { 5138 xmlTextReaderByteConsumed(xmlTextReaderPtr reader) {
5075 if ((reader == NULL) || (reader->ctxt == NULL)) 5139 if ((reader == NULL) || (reader->ctxt == NULL))
5076 return(-1); 5140 return(-1);
5077 return(xmlByteConsumed(reader->ctxt)); 5141 return(xmlByteConsumed(reader->ctxt));
5078 } 5142 }
5079 5143
5080 5144
5081 /** 5145 /**
5082 * xmlReaderWalker: 5146 * xmlReaderWalker:
5083 * @doc: a preparsed document 5147 * @doc: a preparsed document
5084 * 5148 *
5085 * Create an xmltextReader for a preparsed document. 5149 * Create an xmltextReader for a preparsed document.
5086 * 5150 *
5087 * Returns the new reader or NULL in case of error. 5151 * Returns the new reader or NULL in case of error.
5088 */ 5152 */
5089 xmlTextReaderPtr 5153 xmlTextReaderPtr
5090 xmlReaderWalker(xmlDocPtr doc) 5154 xmlReaderWalker(xmlDocPtr doc)
5091 { 5155 {
5092 xmlTextReaderPtr ret; 5156 xmlTextReaderPtr ret;
5093 5157
5094 if (doc == NULL) 5158 if (doc == NULL)
5095 return(NULL); 5159 return(NULL);
5096 5160
(...skipping 20 matching lines...) Expand all
5117 5181
5118 /** 5182 /**
5119 * xmlReaderForDoc: 5183 * xmlReaderForDoc:
5120 * @cur: a pointer to a zero terminated string 5184 * @cur: a pointer to a zero terminated string
5121 * @URL: the base URL to use for the document 5185 * @URL: the base URL to use for the document
5122 * @encoding: the document encoding, or NULL 5186 * @encoding: the document encoding, or NULL
5123 * @options: a combination of xmlParserOption 5187 * @options: a combination of xmlParserOption
5124 * 5188 *
5125 * Create an xmltextReader for an XML in-memory document. 5189 * Create an xmltextReader for an XML in-memory document.
5126 * The parsing flags @options are a combination of xmlParserOption. 5190 * The parsing flags @options are a combination of xmlParserOption.
5127 * 5191 *
5128 * Returns the new reader or NULL in case of error. 5192 * Returns the new reader or NULL in case of error.
5129 */ 5193 */
5130 xmlTextReaderPtr 5194 xmlTextReaderPtr
5131 xmlReaderForDoc(const xmlChar * cur, const char *URL, const char *encoding, 5195 xmlReaderForDoc(const xmlChar * cur, const char *URL, const char *encoding,
5132 int options) 5196 int options)
5133 { 5197 {
5134 int len; 5198 int len;
5135 5199
5136 if (cur == NULL) 5200 if (cur == NULL)
5137 return (NULL); 5201 return (NULL);
5138 len = xmlStrlen(cur); 5202 len = xmlStrlen(cur);
5139 5203
5140 return (xmlReaderForMemory 5204 return (xmlReaderForMemory
5141 ((const char *) cur, len, URL, encoding, options)); 5205 ((const char *) cur, len, URL, encoding, options));
5142 } 5206 }
5143 5207
5144 /** 5208 /**
5145 * xmlReaderForFile: 5209 * xmlReaderForFile:
5146 * @filename: a file or URL 5210 * @filename: a file or URL
5147 * @encoding: the document encoding, or NULL 5211 * @encoding: the document encoding, or NULL
5148 * @options: a combination of xmlParserOption 5212 * @options: a combination of xmlParserOption
5149 * 5213 *
5150 * parse an XML file from the filesystem or the network. 5214 * parse an XML file from the filesystem or the network.
5151 * The parsing flags @options are a combination of xmlParserOption. 5215 * The parsing flags @options are a combination of xmlParserOption.
5152 * 5216 *
5153 * Returns the new reader or NULL in case of error. 5217 * Returns the new reader or NULL in case of error.
5154 */ 5218 */
5155 xmlTextReaderPtr 5219 xmlTextReaderPtr
5156 xmlReaderForFile(const char *filename, const char *encoding, int options) 5220 xmlReaderForFile(const char *filename, const char *encoding, int options)
5157 { 5221 {
5158 xmlTextReaderPtr reader; 5222 xmlTextReaderPtr reader;
5159 5223
5160 reader = xmlNewTextReaderFilename(filename); 5224 reader = xmlNewTextReaderFilename(filename);
5161 if (reader == NULL) 5225 if (reader == NULL)
5162 return (NULL); 5226 return (NULL);
5163 xmlTextReaderSetup(reader, NULL, NULL, encoding, options); 5227 xmlTextReaderSetup(reader, NULL, NULL, encoding, options);
5164 return (reader); 5228 return (reader);
5165 } 5229 }
5166 5230
5167 /** 5231 /**
5168 * xmlReaderForMemory: 5232 * xmlReaderForMemory:
5169 * @buffer: a pointer to a char array 5233 * @buffer: a pointer to a char array
5170 * @size: the size of the array 5234 * @size: the size of the array
5171 * @URL: the base URL to use for the document 5235 * @URL: the base URL to use for the document
5172 * @encoding: the document encoding, or NULL 5236 * @encoding: the document encoding, or NULL
5173 * @options: a combination of xmlParserOption 5237 * @options: a combination of xmlParserOption
5174 * 5238 *
5175 * Create an xmltextReader for an XML in-memory document. 5239 * Create an xmltextReader for an XML in-memory document.
5176 * The parsing flags @options are a combination of xmlParserOption. 5240 * The parsing flags @options are a combination of xmlParserOption.
5177 * 5241 *
5178 * Returns the new reader or NULL in case of error. 5242 * Returns the new reader or NULL in case of error.
5179 */ 5243 */
5180 xmlTextReaderPtr 5244 xmlTextReaderPtr
5181 xmlReaderForMemory(const char *buffer, int size, const char *URL, 5245 xmlReaderForMemory(const char *buffer, int size, const char *URL,
5182 const char *encoding, int options) 5246 const char *encoding, int options)
5183 { 5247 {
5184 xmlTextReaderPtr reader; 5248 xmlTextReaderPtr reader;
5185 xmlParserInputBufferPtr buf; 5249 xmlParserInputBufferPtr buf;
5186 5250
5187 buf = xmlParserInputBufferCreateStatic(buffer, size, 5251 buf = xmlParserInputBufferCreateStatic(buffer, size,
(...skipping 15 matching lines...) Expand all
5203 * xmlReaderForFd: 5267 * xmlReaderForFd:
5204 * @fd: an open file descriptor 5268 * @fd: an open file descriptor
5205 * @URL: the base URL to use for the document 5269 * @URL: the base URL to use for the document
5206 * @encoding: the document encoding, or NULL 5270 * @encoding: the document encoding, or NULL
5207 * @options: a combination of xmlParserOption 5271 * @options: a combination of xmlParserOption
5208 * 5272 *
5209 * Create an xmltextReader for an XML from a file descriptor. 5273 * Create an xmltextReader for an XML from a file descriptor.
5210 * The parsing flags @options are a combination of xmlParserOption. 5274 * The parsing flags @options are a combination of xmlParserOption.
5211 * NOTE that the file descriptor will not be closed when the 5275 * NOTE that the file descriptor will not be closed when the
5212 * reader is closed or reset. 5276 * reader is closed or reset.
5213 * 5277 *
5214 * Returns the new reader or NULL in case of error. 5278 * Returns the new reader or NULL in case of error.
5215 */ 5279 */
5216 xmlTextReaderPtr 5280 xmlTextReaderPtr
5217 xmlReaderForFd(int fd, const char *URL, const char *encoding, int options) 5281 xmlReaderForFd(int fd, const char *URL, const char *encoding, int options)
5218 { 5282 {
5219 xmlTextReaderPtr reader; 5283 xmlTextReaderPtr reader;
5220 xmlParserInputBufferPtr input; 5284 xmlParserInputBufferPtr input;
5221 5285
5222 if (fd < 0) 5286 if (fd < 0)
5223 return (NULL); 5287 return (NULL);
(...skipping 16 matching lines...) Expand all
5240 * xmlReaderForIO: 5304 * xmlReaderForIO:
5241 * @ioread: an I/O read function 5305 * @ioread: an I/O read function
5242 * @ioclose: an I/O close function 5306 * @ioclose: an I/O close function
5243 * @ioctx: an I/O handler 5307 * @ioctx: an I/O handler
5244 * @URL: the base URL to use for the document 5308 * @URL: the base URL to use for the document
5245 * @encoding: the document encoding, or NULL 5309 * @encoding: the document encoding, or NULL
5246 * @options: a combination of xmlParserOption 5310 * @options: a combination of xmlParserOption
5247 * 5311 *
5248 * Create an xmltextReader for an XML document from I/O functions and source. 5312 * Create an xmltextReader for an XML document from I/O functions and source.
5249 * The parsing flags @options are a combination of xmlParserOption. 5313 * The parsing flags @options are a combination of xmlParserOption.
5250 * 5314 *
5251 * Returns the new reader or NULL in case of error. 5315 * Returns the new reader or NULL in case of error.
5252 */ 5316 */
5253 xmlTextReaderPtr 5317 xmlTextReaderPtr
5254 xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, 5318 xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
5255 void *ioctx, const char *URL, const char *encoding, 5319 void *ioctx, const char *URL, const char *encoding,
5256 int options) 5320 int options)
5257 { 5321 {
5258 xmlTextReaderPtr reader; 5322 xmlTextReaderPtr reader;
5259 xmlParserInputBufferPtr input; 5323 xmlParserInputBufferPtr input;
5260 5324
(...skipping 14 matching lines...) Expand all
5275 return (reader); 5339 return (reader);
5276 } 5340 }
5277 5341
5278 /** 5342 /**
5279 * xmlReaderNewWalker: 5343 * xmlReaderNewWalker:
5280 * @reader: an XML reader 5344 * @reader: an XML reader
5281 * @doc: a preparsed document 5345 * @doc: a preparsed document
5282 * 5346 *
5283 * Setup an xmltextReader to parse a preparsed XML document. 5347 * Setup an xmltextReader to parse a preparsed XML document.
5284 * This reuses the existing @reader xmlTextReader. 5348 * This reuses the existing @reader xmlTextReader.
5285 * 5349 *
5286 * Returns 0 in case of success and -1 in case of error 5350 * Returns 0 in case of success and -1 in case of error
5287 */ 5351 */
5288 int 5352 int
5289 xmlReaderNewWalker(xmlTextReaderPtr reader, xmlDocPtr doc) 5353 xmlReaderNewWalker(xmlTextReaderPtr reader, xmlDocPtr doc)
5290 { 5354 {
5291 if (doc == NULL) 5355 if (doc == NULL)
5292 return (-1); 5356 return (-1);
5293 if (reader == NULL) 5357 if (reader == NULL)
5294 return (-1); 5358 return (-1);
5295 5359
(...skipping 27 matching lines...) Expand all
5323 * xmlReaderNewDoc: 5387 * xmlReaderNewDoc:
5324 * @reader: an XML reader 5388 * @reader: an XML reader
5325 * @cur: a pointer to a zero terminated string 5389 * @cur: a pointer to a zero terminated string
5326 * @URL: the base URL to use for the document 5390 * @URL: the base URL to use for the document
5327 * @encoding: the document encoding, or NULL 5391 * @encoding: the document encoding, or NULL
5328 * @options: a combination of xmlParserOption 5392 * @options: a combination of xmlParserOption
5329 * 5393 *
5330 * Setup an xmltextReader to parse an XML in-memory document. 5394 * Setup an xmltextReader to parse an XML in-memory document.
5331 * The parsing flags @options are a combination of xmlParserOption. 5395 * The parsing flags @options are a combination of xmlParserOption.
5332 * This reuses the existing @reader xmlTextReader. 5396 * This reuses the existing @reader xmlTextReader.
5333 * 5397 *
5334 * Returns 0 in case of success and -1 in case of error 5398 * Returns 0 in case of success and -1 in case of error
5335 */ 5399 */
5336 int 5400 int
5337 xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur, 5401 xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur,
5338 const char *URL, const char *encoding, int options) 5402 const char *URL, const char *encoding, int options)
5339 { 5403 {
5340 5404
5341 int len; 5405 int len;
5342 5406
5343 if (cur == NULL) 5407 if (cur == NULL)
5344 return (-1); 5408 return (-1);
5345 if (reader == NULL) 5409 if (reader == NULL)
5346 return (-1); 5410 return (-1);
5347 5411
5348 len = xmlStrlen(cur); 5412 len = xmlStrlen(cur);
5349 return (xmlReaderNewMemory(reader, (const char *)cur, len, 5413 return (xmlReaderNewMemory(reader, (const char *)cur, len,
5350 URL, encoding, options)); 5414 URL, encoding, options));
5351 } 5415 }
5352 5416
5353 /** 5417 /**
5354 * xmlReaderNewFile: 5418 * xmlReaderNewFile:
5355 * @reader: an XML reader 5419 * @reader: an XML reader
5356 * @filename: a file or URL 5420 * @filename: a file or URL
5357 * @encoding: the document encoding, or NULL 5421 * @encoding: the document encoding, or NULL
5358 * @options: a combination of xmlParserOption 5422 * @options: a combination of xmlParserOption
5359 * 5423 *
5360 * parse an XML file from the filesystem or the network. 5424 * parse an XML file from the filesystem or the network.
5361 * The parsing flags @options are a combination of xmlParserOption. 5425 * The parsing flags @options are a combination of xmlParserOption.
5362 * This reuses the existing @reader xmlTextReader. 5426 * This reuses the existing @reader xmlTextReader.
5363 * 5427 *
5364 * Returns 0 in case of success and -1 in case of error 5428 * Returns 0 in case of success and -1 in case of error
5365 */ 5429 */
5366 int 5430 int
5367 xmlReaderNewFile(xmlTextReaderPtr reader, const char *filename, 5431 xmlReaderNewFile(xmlTextReaderPtr reader, const char *filename,
5368 const char *encoding, int options) 5432 const char *encoding, int options)
5369 { 5433 {
5370 xmlParserInputBufferPtr input; 5434 xmlParserInputBufferPtr input;
5371 5435
5372 if (filename == NULL) 5436 if (filename == NULL)
5373 return (-1); 5437 return (-1);
(...skipping 13 matching lines...) Expand all
5387 * @reader: an XML reader 5451 * @reader: an XML reader
5388 * @buffer: a pointer to a char array 5452 * @buffer: a pointer to a char array
5389 * @size: the size of the array 5453 * @size: the size of the array
5390 * @URL: the base URL to use for the document 5454 * @URL: the base URL to use for the document
5391 * @encoding: the document encoding, or NULL 5455 * @encoding: the document encoding, or NULL
5392 * @options: a combination of xmlParserOption 5456 * @options: a combination of xmlParserOption
5393 * 5457 *
5394 * Setup an xmltextReader to parse an XML in-memory document. 5458 * Setup an xmltextReader to parse an XML in-memory document.
5395 * The parsing flags @options are a combination of xmlParserOption. 5459 * The parsing flags @options are a combination of xmlParserOption.
5396 * This reuses the existing @reader xmlTextReader. 5460 * This reuses the existing @reader xmlTextReader.
5397 * 5461 *
5398 * Returns 0 in case of success and -1 in case of error 5462 * Returns 0 in case of success and -1 in case of error
5399 */ 5463 */
5400 int 5464 int
5401 xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, int size, 5465 xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, int size,
5402 const char *URL, const char *encoding, int options) 5466 const char *URL, const char *encoding, int options)
5403 { 5467 {
5404 xmlParserInputBufferPtr input; 5468 xmlParserInputBufferPtr input;
5405 5469
5406 if (reader == NULL) 5470 if (reader == NULL)
5407 return (-1); 5471 return (-1);
(...skipping 14 matching lines...) Expand all
5422 * @fd: an open file descriptor 5486 * @fd: an open file descriptor
5423 * @URL: the base URL to use for the document 5487 * @URL: the base URL to use for the document
5424 * @encoding: the document encoding, or NULL 5488 * @encoding: the document encoding, or NULL
5425 * @options: a combination of xmlParserOption 5489 * @options: a combination of xmlParserOption
5426 * 5490 *
5427 * Setup an xmltextReader to parse an XML from a file descriptor. 5491 * Setup an xmltextReader to parse an XML from a file descriptor.
5428 * NOTE that the file descriptor will not be closed when the 5492 * NOTE that the file descriptor will not be closed when the
5429 * reader is closed or reset. 5493 * reader is closed or reset.
5430 * The parsing flags @options are a combination of xmlParserOption. 5494 * The parsing flags @options are a combination of xmlParserOption.
5431 * This reuses the existing @reader xmlTextReader. 5495 * This reuses the existing @reader xmlTextReader.
5432 * 5496 *
5433 * Returns 0 in case of success and -1 in case of error 5497 * Returns 0 in case of success and -1 in case of error
5434 */ 5498 */
5435 int 5499 int
5436 xmlReaderNewFd(xmlTextReaderPtr reader, int fd, 5500 xmlReaderNewFd(xmlTextReaderPtr reader, int fd,
5437 const char *URL, const char *encoding, int options) 5501 const char *URL, const char *encoding, int options)
5438 { 5502 {
5439 xmlParserInputBufferPtr input; 5503 xmlParserInputBufferPtr input;
5440 5504
5441 if (fd < 0) 5505 if (fd < 0)
5442 return (-1); 5506 return (-1);
(...skipping 14 matching lines...) Expand all
5457 * @ioclose: an I/O close function 5521 * @ioclose: an I/O close function
5458 * @ioctx: an I/O handler 5522 * @ioctx: an I/O handler
5459 * @URL: the base URL to use for the document 5523 * @URL: the base URL to use for the document
5460 * @encoding: the document encoding, or NULL 5524 * @encoding: the document encoding, or NULL
5461 * @options: a combination of xmlParserOption 5525 * @options: a combination of xmlParserOption
5462 * 5526 *
5463 * Setup an xmltextReader to parse an XML document from I/O functions 5527 * Setup an xmltextReader to parse an XML document from I/O functions
5464 * and source. 5528 * and source.
5465 * The parsing flags @options are a combination of xmlParserOption. 5529 * The parsing flags @options are a combination of xmlParserOption.
5466 * This reuses the existing @reader xmlTextReader. 5530 * This reuses the existing @reader xmlTextReader.
5467 * 5531 *
5468 * Returns 0 in case of success and -1 in case of error 5532 * Returns 0 in case of success and -1 in case of error
5469 */ 5533 */
5470 int 5534 int
5471 xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread, 5535 xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread,
5472 xmlInputCloseCallback ioclose, void *ioctx, 5536 xmlInputCloseCallback ioclose, void *ioctx,
5473 const char *URL, const char *encoding, int options) 5537 const char *URL, const char *encoding, int options)
5474 { 5538 {
5475 xmlParserInputBufferPtr input; 5539 xmlParserInputBufferPtr input;
5476 5540
5477 if (ioread == NULL) 5541 if (ioread == NULL)
5478 return (-1); 5542 return (-1);
5479 if (reader == NULL) 5543 if (reader == NULL)
5480 return (-1); 5544 return (-1);
5481 5545
5482 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, 5546 input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx,
5483 XML_CHAR_ENCODING_NONE); 5547 XML_CHAR_ENCODING_NONE);
5484 if (input == NULL) 5548 if (input == NULL)
5485 return (-1); 5549 return (-1);
5486 return (xmlTextReaderSetup(reader, input, URL, encoding, options)); 5550 return (xmlTextReaderSetup(reader, input, URL, encoding, options));
5487 } 5551 }
5488 /************************************************************************ 5552 /************************************************************************
5489 * * 5553 * *
5490 * Utilities * 5554 * Utilities *
5491 * * 5555 * *
5492 ************************************************************************/ 5556 ************************************************************************/
5493 #ifdef NOT_USED_YET 5557 #ifdef NOT_USED_YET
5558
5494 /** 5559 /**
5495 * xmlBase64Decode: 5560 * xmlBase64Decode:
5496 * @in: the input buffer 5561 * @in: the input buffer
5497 * @inlen: the size of the input (in), the size read from it (out) 5562 * @inlen: the size of the input (in), the size read from it (out)
5498 * @to: the output buffer 5563 * @to: the output buffer
5499 * @tolen: the size of the output (in), the size written to (out) 5564 * @tolen: the size of the output (in), the size written to (out)
5500 * 5565 *
5501 * Base64 decoder, reads from @in and save in @to 5566 * Base64 decoder, reads from @in and save in @to
5502 * TODO: tell jody when this is actually exported 5567 * TODO: tell jody when this is actually exported
5503 * 5568 *
5504 * Returns 0 if all the input was consumer, 1 if the Base64 end was reached, 5569 * Returns 0 if all the input was consumer, 1 if the Base64 end was reached,
5505 * 2 if there wasn't enough space on the output or -1 in case of error. 5570 * 2 if there wasn't enough space on the output or -1 in case of error.
5506 */ 5571 */
5507 static int 5572 static int
5508 xmlBase64Decode(const unsigned char *in, unsigned long *inlen, 5573 xmlBase64Decode(const unsigned char *in, unsigned long *inlen,
5509 » unsigned char *to, unsigned long *tolen) { 5574 unsigned char *to, unsigned long *tolen)
5510 unsigned long incur;» » /* current index in in[] */ 5575 {
5511 unsigned long inblk;» » /* last block index in in[] */ 5576 unsigned long incur; /* current index in in[] */
5512 unsigned long outcur;» » /* current index in out[] */ 5577
5513 unsigned long inmax;» » /* size of in[] */ 5578 unsigned long inblk; /* last block index in in[] */
5514 unsigned long outmax;» » /* size of out[] */ 5579
5515 unsigned char cur;» » » /* the current value read from in[] */ 5580 unsigned long outcur; /* current index in out[] */
5516 unsigned char intmp[4], outtmp[4];» /* temporary buffers for the convert */ 5581
5517 int nbintmp;» » » /* number of byte in intmp[] */ 5582 unsigned long inmax; /* size of in[] */
5518 int is_ignore;» » » /* cur should be ignored */ 5583
5519 int is_end = 0;» » » /* the end of the base64 was found */ 5584 unsigned long outmax; /* size of out[] */
5585
5586 unsigned char cur; /* the current value read from in[] */
5587
5588 unsigned char intmp[4], outtmp[4]; /* temporary buffers for the convert */
5589
5590 int nbintmp; /* number of byte in intmp[] */
5591
5592 int is_ignore; /* cur should be ignored */
5593
5594 int is_end = 0; /* the end of the base64 was found */
5595
5520 int retval = 1; 5596 int retval = 1;
5597
5521 int i; 5598 int i;
5522 5599
5523 if ((in == NULL) || (inlen == NULL) || (to == NULL) || (tolen == NULL)) 5600 if ((in == NULL) || (inlen == NULL) || (to == NULL) || (tolen == NULL))
5524 » return(-1); 5601 return (-1);
5525 5602
5526 incur = 0; 5603 incur = 0;
5527 inblk = 0; 5604 inblk = 0;
5528 outcur = 0; 5605 outcur = 0;
5529 inmax = *inlen; 5606 inmax = *inlen;
5530 outmax = *tolen; 5607 outmax = *tolen;
5531 nbintmp = 0; 5608 nbintmp = 0;
5532 5609
5533 while (1) { 5610 while (1) {
5534 if (incur >= inmax) 5611 if (incur >= inmax)
5535 break; 5612 break;
5536 cur = in[incur++]; 5613 cur = in[incur++];
5537 is_ignore = 0; 5614 is_ignore = 0;
5538 if ((cur >= 'A') && (cur <= 'Z')) 5615 if ((cur >= 'A') && (cur <= 'Z'))
5539 cur = cur - 'A'; 5616 cur = cur - 'A';
5540 else if ((cur >= 'a') && (cur <= 'z')) 5617 else if ((cur >= 'a') && (cur <= 'z'))
5541 cur = cur - 'a' + 26; 5618 cur = cur - 'a' + 26;
5542 else if ((cur >= '0') && (cur <= '9')) 5619 else if ((cur >= '0') && (cur <= '9'))
5543 cur = cur - '0' + 52; 5620 cur = cur - '0' + 52;
5544 else if (cur == '+') 5621 else if (cur == '+')
5545 cur = 62; 5622 cur = 62;
5546 else if (cur == '/') 5623 else if (cur == '/')
5547 cur = 63; 5624 cur = 63;
5548 else if (cur == '.') 5625 else if (cur == '.')
5549 cur = 0; 5626 cur = 0;
5550 else if (cur == '=') /*no op , end of the base64 stream */ 5627 else if (cur == '=') /*no op , end of the base64 stream */
5551 is_end = 1; 5628 is_end = 1;
5552 else { 5629 else {
5553 is_ignore = 1; 5630 is_ignore = 1;
5554 » if (nbintmp == 0) 5631 if (nbintmp == 0)
5555 » » inblk = incur; 5632 inblk = incur;
5556 » } 5633 }
5557 5634
5558 if (!is_ignore) { 5635 if (!is_ignore) {
5559 int nbouttmp = 3; 5636 int nbouttmp = 3;
5637
5560 int is_break = 0; 5638 int is_break = 0;
5561 5639
5562 if (is_end) { 5640 if (is_end) {
5563 if (nbintmp == 0) 5641 if (nbintmp == 0)
5564 break; 5642 break;
5565 if ((nbintmp == 1) || (nbintmp == 2)) 5643 if ((nbintmp == 1) || (nbintmp == 2))
5566 nbouttmp = 1; 5644 nbouttmp = 1;
5567 else 5645 else
5568 nbouttmp = 2; 5646 nbouttmp = 2;
5569 nbintmp = 3; 5647 nbintmp = 3;
5570 is_break = 1; 5648 is_break = 1;
5571 } 5649 }
5572 intmp[nbintmp++] = cur; 5650 intmp[nbintmp++] = cur;
5573 » /* 5651 /*
5574 » * if intmp is full, push the 4byte sequence as a 3 byte 5652 * if intmp is full, push the 4byte sequence as a 3 byte
5575 » * sequence out 5653 * sequence out
5576 » */ 5654 */
5577 if (nbintmp == 4) { 5655 if (nbintmp == 4) {
5578 nbintmp = 0; 5656 nbintmp = 0;
5579 outtmp[0] = (intmp[0] << 2) | ((intmp[1] & 0x30) >> 4); 5657 outtmp[0] = (intmp[0] << 2) | ((intmp[1] & 0x30) >> 4);
5580 outtmp[1] = 5658 outtmp[1] =
5581 ((intmp[1] & 0x0F) << 4) | ((intmp[2] & 0x3C) >> 2); 5659 ((intmp[1] & 0x0F) << 4) | ((intmp[2] & 0x3C) >> 2);
5582 outtmp[2] = ((intmp[2] & 0x03) << 6) | (intmp[3] & 0x3F); 5660 outtmp[2] = ((intmp[2] & 0x03) << 6) | (intmp[3] & 0x3F);
5583 » » if (outcur + 3 >= outmax) { 5661 if (outcur + 3 >= outmax) {
5584 » » retval = 2; 5662 retval = 2;
5585 » » break; 5663 break;
5586 » » } 5664 }
5587 5665
5588 for (i = 0; i < nbouttmp; i++) 5666 for (i = 0; i < nbouttmp; i++)
5589 » » to[outcur++] = outtmp[i]; 5667 to[outcur++] = outtmp[i];
5590 » » inblk = incur; 5668 inblk = incur;
5591 } 5669 }
5592 5670
5593 if (is_break) { 5671 if (is_break) {
5594 » » retval = 0; 5672 retval = 0;
5595 break; 5673 break;
5596 » } 5674 }
5597 } 5675 }
5598 } 5676 }
5599 5677
5600 *tolen = outcur; 5678 *tolen = outcur;
5601 *inlen = inblk; 5679 *inlen = inblk;
5602 return (retval); 5680 return (retval);
5603 } 5681 }
5604 5682
5605 /* 5683 /*
5606 * Test routine for the xmlBase64Decode function 5684 * Test routine for the xmlBase64Decode function
5607 */ 5685 */
5608 #if 0 5686 #if 0
5609 int main(int argc, char **argv) { 5687 int
5688 main(int argc, char **argv)
5689 {
5610 char *input = " VW4 gcGV0 \n aXQgdGVzdCAuCg== "; 5690 char *input = " VW4 gcGV0 \n aXQgdGVzdCAuCg== ";
5691
5611 char output[100]; 5692 char output[100];
5693
5612 char output2[100]; 5694 char output2[100];
5695
5613 char output3[100]; 5696 char output3[100];
5697
5614 unsigned long inlen = strlen(input); 5698 unsigned long inlen = strlen(input);
5699
5615 unsigned long outlen = 100; 5700 unsigned long outlen = 100;
5701
5616 int ret; 5702 int ret;
5703
5617 unsigned long cons, tmp, tmp2, prod; 5704 unsigned long cons, tmp, tmp2, prod;
5618 5705
5619 /* 5706 /*
5620 * Direct 5707 * Direct
5621 */ 5708 */
5622 ret = xmlBase64Decode(input, &inlen, output, &outlen); 5709 ret = xmlBase64Decode(input, &inlen, output, &outlen);
5623 5710
5624 output[outlen] = 0; 5711 output[outlen] = 0;
5625 printf("ret: %d, inlen: %ld , outlen: %ld, output: '%s'\n", ret, inlen, outl en, output); 5712 printf("ret: %d, inlen: %ld , outlen: %ld, output: '%s'\n", ret, inlen,
5626 5713 outlen, output)indent: Standard input:179: Error:Unmatched #endif
5714 ;
5715
5627 /* 5716 /*
5628 * output chunking 5717 * output chunking
5629 */ 5718 */
5630 cons = 0; 5719 cons = 0;
5631 prod = 0; 5720 prod = 0;
5632 while (cons < inlen) { 5721 while (cons < inlen) {
5633 » tmp = 5; 5722 tmp = 5;
5634 » tmp2 = inlen - cons; 5723 tmp2 = inlen - cons;
5635 5724
5636 » printf("%ld %ld\n", cons, prod); 5725 printf("%ld %ld\n", cons, prod);
5637 » ret = xmlBase64Decode(&input[cons], &tmp2, &output2[prod], &tmp); 5726 ret = xmlBase64Decode(&input[cons], &tmp2, &output2[prod], &tmp);
5638 » cons += tmp2; 5727 cons += tmp2;
5639 » prod += tmp; 5728 prod += tmp;
5640 » printf("%ld %ld\n", cons, prod); 5729 printf("%ld %ld\n", cons, prod);
5641 } 5730 }
5642 output2[outlen] = 0; 5731 output2[outlen] = 0;
5643 printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, prod, ou tput2); 5732 printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons,
5733 prod, output2);
5644 5734
5645 /* 5735 /*
5646 * input chunking 5736 * input chunking
5647 */ 5737 */
5648 cons = 0; 5738 cons = 0;
5649 prod = 0; 5739 prod = 0;
5650 while (cons < inlen) { 5740 while (cons < inlen) {
5651 » tmp = 100 - prod; 5741 tmp = 100 - prod;
5652 » tmp2 = inlen - cons; 5742 tmp2 = inlen - cons;
5653 » if (tmp2 > 5) 5743 if (tmp2 > 5)
5654 » tmp2 = 5; 5744 tmp2 = 5;
5655 5745
5656 » printf("%ld %ld\n", cons, prod); 5746 printf("%ld %ld\n", cons, prod);
5657 » ret = xmlBase64Decode(&input[cons], &tmp2, &output3[prod], &tmp); 5747 ret = xmlBase64Decode(&input[cons], &tmp2, &output3[prod], &tmp);
5658 » cons += tmp2; 5748 cons += tmp2;
5659 » prod += tmp; 5749 prod += tmp;
5660 » printf("%ld %ld\n", cons, prod); 5750 printf("%ld %ld\n", cons, prod);
5661 } 5751 }
5662 output3[outlen] = 0; 5752 output3[outlen] = 0;
5663 printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, prod, ou tput3); 5753 printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons,
5664 return(0); 5754 prod, output3);
5755 return (0);
5665 5756
5666 } 5757 }
5667 #endif 5758 #endif
5668 #endif /* NOT_USED_YET */ 5759 #endif /* NOT_USED_YET */
5669 #define bottom_xmlreader 5760 #define bottom_xmlreader
5670 #include "elfgcchack.h" 5761 #include "elfgcchack.h"
5671 #endif /* LIBXML_READER_ENABLED */ 5762 #endif /* LIBXML_READER_ENABLED */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698