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

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

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no iconv Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxml/src/win32/wince/wincecompat.c ('k') | third_party/libxml/src/xlink.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * xinclude.c : Code to implement XInclude processing 2 * xinclude.c : Code to implement XInclude processing
3 * 3 *
4 * World Wide Web Consortium W3C Last Call Working Draft 10 November 2003 4 * World Wide Web Consortium W3C Last Call Working Draft 10 November 2003
5 * http://www.w3.org/TR/2003/WD-xinclude-20031110 5 * http://www.w3.org/TR/2003/WD-xinclude-20031110
6 * 6 *
7 * See Copyright for the status of this software. 7 * See Copyright for the status of this software.
8 * 8 *
9 * daniel@veillard.com 9 * daniel@veillard.com
10 */ 10 */
11 11
12 #define IN_LIBXML 12 #define IN_LIBXML
13 #include "libxml.h" 13 #include "libxml.h"
14 14
15 #include <string.h> 15 #include <string.h>
16 #include <libxml/xmlmemory.h> 16 #include <libxml/xmlmemory.h>
17 #include <libxml/tree.h> 17 #include <libxml/tree.h>
18 #include <libxml/parser.h> 18 #include <libxml/parser.h>
19 #include <libxml/uri.h> 19 #include <libxml/uri.h>
20 #include <libxml/xpath.h>
20 #include <libxml/xpointer.h> 21 #include <libxml/xpointer.h>
21 #include <libxml/parserInternals.h> 22 #include <libxml/parserInternals.h>
22 #include <libxml/xmlerror.h> 23 #include <libxml/xmlerror.h>
23 #include <libxml/encoding.h> 24 #include <libxml/encoding.h>
24 #include <libxml/globals.h> 25 #include <libxml/globals.h>
25 26
26 #ifdef LIBXML_XINCLUDE_ENABLED 27 #ifdef LIBXML_XINCLUDE_ENABLED
27 #include <libxml/xinclude.h> 28 #include <libxml/xinclude.h>
28 29
30 #include "buf.h"
29 31
30 #define XINCLUDE_MAX_DEPTH 40 32 #define XINCLUDE_MAX_DEPTH 40
31 33
32 /* #define DEBUG_XINCLUDE */ 34 /* #define DEBUG_XINCLUDE */
33 #ifdef DEBUG_XINCLUDE 35 #ifdef DEBUG_XINCLUDE
34 #ifdef LIBXML_DEBUG_ENABLED 36 #ifdef LIBXML_DEBUG_ENABLED
35 #include <libxml/debugXML.h> 37 #include <libxml/debugXML.h>
36 #endif 38 #endif
37 #endif 39 #endif
38 40
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 87
86 void *_private; /* application data */ 88 void *_private; /* application data */
87 }; 89 };
88 90
89 static int 91 static int
90 xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree); 92 xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree);
91 93
92 94
93 /************************************************************************ 95 /************************************************************************
94 * * 96 * *
95 * » » » XInclude error handler» » » » * 97 *» » » XInclude error handler» » » » *
96 * * 98 * *
97 ************************************************************************/ 99 ************************************************************************/
98 100
99 /** 101 /**
100 * xmlXIncludeErrMemory: 102 * xmlXIncludeErrMemory:
101 * @extra: extra information 103 * @extra: extra information
102 * 104 *
103 * Handle an out of memory condition 105 * Handle an out of memory condition
104 */ 106 */
105 static void 107 static void
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 if (ctxt->base != NULL) { 407 if (ctxt->base != NULL) {
406 xmlFree(ctxt->base); 408 xmlFree(ctxt->base);
407 } 409 }
408 xmlFree(ctxt); 410 xmlFree(ctxt);
409 } 411 }
410 412
411 /** 413 /**
412 * xmlXIncludeParseFile: 414 * xmlXIncludeParseFile:
413 * @ctxt: the XInclude context 415 * @ctxt: the XInclude context
414 * @URL: the URL or file path 416 * @URL: the URL or file path
415 * 417 *
416 * parse a document for XInclude 418 * parse a document for XInclude
417 */ 419 */
418 static xmlDocPtr 420 static xmlDocPtr
419 xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) { 421 xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
420 xmlDocPtr ret; 422 xmlDocPtr ret;
421 xmlParserCtxtPtr pctxt; 423 xmlParserCtxtPtr pctxt;
422 xmlParserInputPtr inputStream; 424 xmlParserInputPtr inputStream;
423 425
424 xmlInitParser(); 426 xmlInitParser();
425 427
426 pctxt = xmlNewParserCtxt(); 428 pctxt = xmlNewParserCtxt();
427 if (pctxt == NULL) { 429 if (pctxt == NULL) {
428 xmlXIncludeErrMemory(ctxt, NULL, "cannot allocate parser context"); 430 xmlXIncludeErrMemory(ctxt, NULL, "cannot allocate parser context");
429 return(NULL); 431 return(NULL);
430 } 432 }
431 433
432 /* 434 /*
433 * pass in the application data to the parser context. 435 * pass in the application data to the parser context.
434 */ 436 */
435 pctxt->_private = ctxt->_private; 437 pctxt->_private = ctxt->_private;
436 438
437 /* 439 /*
438 * try to ensure that new documents included are actually 440 * try to ensure that new documents included are actually
439 * built with the same dictionary as the including document. 441 * built with the same dictionary as the including document.
440 */ 442 */
441 if ((ctxt->doc != NULL) && (ctxt->doc->dict != NULL)) { 443 if ((ctxt->doc != NULL) && (ctxt->doc->dict != NULL)) {
442 if (pctxt->dict != NULL) 444 if (pctxt->dict != NULL)
443 xmlDictFree(pctxt->dict); 445 xmlDictFree(pctxt->dict);
444 pctxt->dict = ctxt->doc->dict; 446 pctxt->dict = ctxt->doc->dict;
445 xmlDictReference(pctxt->dict); 447 xmlDictReference(pctxt->dict);
446 } 448 }
447 449
448 xmlCtxtUseOptions(pctxt, ctxt->parseFlags | XML_PARSE_DTDLOAD); 450 xmlCtxtUseOptions(pctxt, ctxt->parseFlags | XML_PARSE_DTDLOAD);
449 451
450 inputStream = xmlLoadExternalEntity(URL, NULL, pctxt); 452 inputStream = xmlLoadExternalEntity(URL, NULL, pctxt);
451 if (inputStream == NULL) { 453 if (inputStream == NULL) {
452 xmlFreeParserCtxt(pctxt); 454 xmlFreeParserCtxt(pctxt);
453 return(NULL); 455 return(NULL);
454 } 456 }
455 457
456 inputPush(pctxt, inputStream); 458 inputPush(pctxt, inputStream);
457 459
458 if (pctxt->directory == NULL) 460 if (pctxt->directory == NULL)
459 pctxt->directory = xmlParserGetDirectory(URL); 461 pctxt->directory = xmlParserGetDirectory(URL);
460 462
461 pctxt->loadsubset |= XML_DETECT_IDS; 463 pctxt->loadsubset |= XML_DETECT_IDS;
462 464
463 xmlParseDocument(pctxt); 465 xmlParseDocument(pctxt);
464 466
465 if (pctxt->wellFormed) { 467 if (pctxt->wellFormed) {
466 ret = pctxt->myDoc; 468 ret = pctxt->myDoc;
467 } 469 }
468 else { 470 else {
469 ret = NULL; 471 ret = NULL;
470 if (pctxt->myDoc != NULL) 472 if (pctxt->myDoc != NULL)
471 xmlFreeDoc(pctxt->myDoc); 473 xmlFreeDoc(pctxt->myDoc);
472 pctxt->myDoc = NULL; 474 pctxt->myDoc = NULL;
473 } 475 }
474 xmlFreeParserCtxt(pctxt); 476 xmlFreeParserCtxt(pctxt);
475 477
476 return(ret); 478 return(ret);
477 } 479 }
478 480
479 /** 481 /**
480 * xmlXIncludeAddNode: 482 * xmlXIncludeAddNode:
481 * @ctxt: the XInclude context 483 * @ctxt: the XInclude context
482 * @cur: the new node 484 * @cur: the new node
483 * 485 *
484 * Add a new node to process to an XInclude context 486 * Add a new node to process to an XInclude context
485 */ 487 */
486 static int 488 static int
487 xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) { 489 xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
488 xmlXIncludeRefPtr ref; 490 xmlXIncludeRefPtr ref;
489 xmlURIPtr uri; 491 xmlURIPtr uri;
490 xmlChar *URL; 492 xmlChar *URL;
491 xmlChar *fragment = NULL; 493 xmlChar *fragment = NULL;
492 xmlChar *href; 494 xmlChar *href;
493 xmlChar *parse; 495 xmlChar *parse;
(...skipping 10 matching lines...) Expand all
504 506
505 #ifdef DEBUG_XINCLUDE 507 #ifdef DEBUG_XINCLUDE
506 xmlGenericError(xmlGenericErrorContext, "Add node\n"); 508 xmlGenericError(xmlGenericErrorContext, "Add node\n");
507 #endif 509 #endif
508 /* 510 /*
509 * read the attributes 511 * read the attributes
510 */ 512 */
511 href = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_HREF); 513 href = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_HREF);
512 if (href == NULL) { 514 if (href == NULL) {
513 href = xmlStrdup(BAD_CAST ""); /* @@@@ href is now optional */ 515 href = xmlStrdup(BAD_CAST ""); /* @@@@ href is now optional */
514 » if (href == NULL) 516 » if (href == NULL)
515 return(-1); 517 return(-1);
516 } 518 }
517 if ((href[0] == '#') || (href[0] == 0)) 519 if ((href[0] == '#') || (href[0] == 0))
518 local = 1; 520 local = 1;
519 parse = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_PARSE); 521 parse = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_PARSE);
520 if (parse != NULL) { 522 if (parse != NULL) {
521 if (xmlStrEqual(parse, XINCLUDE_PARSE_XML)) 523 if (xmlStrEqual(parse, XINCLUDE_PARSE_XML))
522 xml = 1; 524 xml = 1;
523 else if (xmlStrEqual(parse, XINCLUDE_PARSE_TEXT)) 525 else if (xmlStrEqual(parse, XINCLUDE_PARSE_TEXT))
524 xml = 0; 526 xml = 0;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 ref->count = 1; 650 ref->count = 1;
649 xmlFree(URL); 651 xmlFree(URL);
650 return(0); 652 return(0);
651 } 653 }
652 654
653 /** 655 /**
654 * xmlXIncludeRecurseDoc: 656 * xmlXIncludeRecurseDoc:
655 * @ctxt: the XInclude context 657 * @ctxt: the XInclude context
656 * @doc: the new document 658 * @doc: the new document
657 * @url: the associated URL 659 * @url: the associated URL
658 * 660 *
659 * The XInclude recursive nature is handled at this point. 661 * The XInclude recursive nature is handled at this point.
660 */ 662 */
661 static void 663 static void
662 xmlXIncludeRecurseDoc(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, 664 xmlXIncludeRecurseDoc(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc,
663 const xmlURL url ATTRIBUTE_UNUSED) { 665 const xmlURL url ATTRIBUTE_UNUSED) {
664 xmlXIncludeCtxtPtr newctxt; 666 xmlXIncludeCtxtPtr newctxt;
665 int i; 667 int i;
666 668
667 /* 669 /*
668 * Avoid recursion in already substitued resources 670 * Avoid recursion in already substitued resources
669 for (i = 0;i < ctxt->urlNr;i++) { 671 for (i = 0;i < ctxt->urlNr;i++) {
670 if (xmlStrEqual(doc->URL, ctxt->urlTab[i])) 672 if (xmlStrEqual(doc->URL, ctxt->urlTab[i]))
671 return; 673 return;
672 } 674 }
673 */ 675 */
674 676
675 #ifdef DEBUG_XINCLUDE 677 #ifdef DEBUG_XINCLUDE
676 xmlGenericError(xmlGenericErrorContext, "Recursing in doc %s\n", doc->URL); 678 xmlGenericError(xmlGenericErrorContext, "Recursing in doc %s\n", doc->URL);
677 #endif 679 #endif
678 /* 680 /*
679 * Handle recursion here. 681 * Handle recursion here.
680 */ 682 */
681 683
682 newctxt = xmlXIncludeNewContext(doc); 684 newctxt = xmlXIncludeNewContext(doc);
683 if (newctxt != NULL) { 685 if (newctxt != NULL) {
684 /* 686 /*
685 * Copy the private user data 687 * Copy the private user data
686 */ 688 */
687 » newctxt->_private = ctxt->_private;» 689 » newctxt->_private = ctxt->_private;
688 /* 690 /*
689 * Copy the existing document set 691 * Copy the existing document set
690 */ 692 */
691 newctxt->incMax = ctxt->incMax; 693 newctxt->incMax = ctxt->incMax;
692 newctxt->incNr = ctxt->incNr; 694 newctxt->incNr = ctxt->incNr;
693 newctxt->incTab = (xmlXIncludeRefPtr *) xmlMalloc(newctxt->incMax * 695 newctxt->incTab = (xmlXIncludeRefPtr *) xmlMalloc(newctxt->incMax *
694 sizeof(newctxt->incTab[0])); 696 sizeof(newctxt->incTab[0]));
695 if (newctxt->incTab == NULL) { 697 if (newctxt->incTab == NULL) {
696 xmlXIncludeErrMemory(ctxt, (xmlNodePtr) doc, "processing doc"); 698 xmlXIncludeErrMemory(ctxt, (xmlNodePtr) doc, "processing doc");
697 xmlFree(newctxt); 699 xmlFree(newctxt);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 #ifdef DEBUG_XINCLUDE 744 #ifdef DEBUG_XINCLUDE
743 xmlGenericError(xmlGenericErrorContext, "Done recursing in doc %s\n", url); 745 xmlGenericError(xmlGenericErrorContext, "Done recursing in doc %s\n", url);
744 #endif 746 #endif
745 } 747 }
746 748
747 /** 749 /**
748 * xmlXIncludeAddTxt: 750 * xmlXIncludeAddTxt:
749 * @ctxt: the XInclude context 751 * @ctxt: the XInclude context
750 * @txt: the new text node 752 * @txt: the new text node
751 * @url: the associated URL 753 * @url: the associated URL
752 * 754 *
753 * Add a new txtument to the list 755 * Add a new txtument to the list
754 */ 756 */
755 static void 757 static void
756 xmlXIncludeAddTxt(xmlXIncludeCtxtPtr ctxt, xmlNodePtr txt, const xmlURL url) { 758 xmlXIncludeAddTxt(xmlXIncludeCtxtPtr ctxt, xmlNodePtr txt, const xmlURL url) {
757 #ifdef DEBUG_XINCLUDE 759 #ifdef DEBUG_XINCLUDE
758 xmlGenericError(xmlGenericErrorContext, "Adding text %s\n", url); 760 xmlGenericError(xmlGenericErrorContext, "Adding text %s\n", url);
759 #endif 761 #endif
760 if (ctxt->txtMax == 0) { 762 if (ctxt->txtMax == 0) {
761 ctxt->txtMax = 4; 763 ctxt->txtMax = 4;
762 ctxt->txtTab = (xmlNodePtr *) xmlMalloc(ctxt->txtMax * 764 ctxt->txtTab = (xmlNodePtr *) xmlMalloc(ctxt->txtMax *
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 static xmlNodePtr 803 static xmlNodePtr
802 xmlXIncludeCopyNodeList(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, 804 xmlXIncludeCopyNodeList(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
803 xmlDocPtr source, xmlNodePtr elem); 805 xmlDocPtr source, xmlNodePtr elem);
804 806
805 /** 807 /**
806 * xmlXIncludeCopyNode: 808 * xmlXIncludeCopyNode:
807 * @ctxt: the XInclude context 809 * @ctxt: the XInclude context
808 * @target: the document target 810 * @target: the document target
809 * @source: the document source 811 * @source: the document source
810 * @elem: the element 812 * @elem: the element
811 * 813 *
812 * Make a copy of the node while preserving the XInclude semantic 814 * Make a copy of the node while preserving the XInclude semantic
813 * of the Infoset copy 815 * of the Infoset copy
814 */ 816 */
815 static xmlNodePtr 817 static xmlNodePtr
816 xmlXIncludeCopyNode(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, 818 xmlXIncludeCopyNode(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
817 xmlDocPtr source, xmlNodePtr elem) { 819 xmlDocPtr source, xmlNodePtr elem) {
818 xmlNodePtr result = NULL; 820 xmlNodePtr result = NULL;
819 821
820 if ((ctxt == NULL) || (target == NULL) || (source == NULL) || 822 if ((ctxt == NULL) || (target == NULL) || (source == NULL) ||
821 (elem == NULL)) 823 (elem == NULL))
822 return(NULL); 824 return(NULL);
823 if (elem->type == XML_DTD_NODE) 825 if (elem->type == XML_DTD_NODE)
824 return(NULL); 826 return(NULL);
825 if (elem->type == XML_DOCUMENT_NODE) 827 if (elem->type == XML_DOCUMENT_NODE)
826 result = xmlXIncludeCopyNodeList(ctxt, target, source, elem->children); 828 result = xmlXIncludeCopyNodeList(ctxt, target, source, elem->children);
827 else 829 else
828 result = xmlDocCopyNode(elem, target, 1); 830 result = xmlDocCopyNode(elem, target, 1);
829 return(result); 831 return(result);
830 } 832 }
831 833
832 /** 834 /**
833 * xmlXIncludeCopyNodeList: 835 * xmlXIncludeCopyNodeList:
834 * @ctxt: the XInclude context 836 * @ctxt: the XInclude context
835 * @target: the document target 837 * @target: the document target
836 * @source: the document source 838 * @source: the document source
837 * @elem: the element list 839 * @elem: the element list
838 * 840 *
839 * Make a copy of the node list while preserving the XInclude semantic 841 * Make a copy of the node list while preserving the XInclude semantic
840 * of the Infoset copy 842 * of the Infoset copy
841 */ 843 */
842 static xmlNodePtr 844 static xmlNodePtr
843 xmlXIncludeCopyNodeList(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target, 845 xmlXIncludeCopyNodeList(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
844 xmlDocPtr source, xmlNodePtr elem) { 846 xmlDocPtr source, xmlNodePtr elem) {
845 xmlNodePtr cur, res, result = NULL, last = NULL; 847 xmlNodePtr cur, res, result = NULL, last = NULL;
846 848
847 if ((ctxt == NULL) || (target == NULL) || (source == NULL) || 849 if ((ctxt == NULL) || (target == NULL) || (source == NULL) ||
848 (elem == NULL)) 850 (elem == NULL))
(...skipping 18 matching lines...) Expand all
867 /** 869 /**
868 * xmlXIncludeGetNthChild: 870 * xmlXIncludeGetNthChild:
869 * @cur: the node 871 * @cur: the node
870 * @no: the child number 872 * @no: the child number
871 * 873 *
872 * Returns the @n'th element child of @cur or NULL 874 * Returns the @n'th element child of @cur or NULL
873 */ 875 */
874 static xmlNodePtr 876 static xmlNodePtr
875 xmlXIncludeGetNthChild(xmlNodePtr cur, int no) { 877 xmlXIncludeGetNthChild(xmlNodePtr cur, int no) {
876 int i; 878 int i;
877 if (cur == NULL) 879 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
878 » return(cur); 880 return(NULL);
879 cur = cur->children; 881 cur = cur->children;
880 for (i = 0;i <= no;cur = cur->next) { 882 for (i = 0;i <= no;cur = cur->next) {
881 » if (cur == NULL) 883 » if (cur == NULL)
882 return(cur); 884 return(cur);
883 if ((cur->type == XML_ELEMENT_NODE) || 885 if ((cur->type == XML_ELEMENT_NODE) ||
884 (cur->type == XML_DOCUMENT_NODE) || 886 (cur->type == XML_DOCUMENT_NODE) ||
885 (cur->type == XML_HTML_DOCUMENT_NODE)) { 887 (cur->type == XML_HTML_DOCUMENT_NODE)) {
886 i++; 888 i++;
887 if (i == no) 889 if (i == no)
888 break; 890 break;
889 } 891 }
890 } 892 }
891 return(cur); 893 return(cur);
(...skipping 23 matching lines...) Expand all
915 int index1, index2; 917 int index1, index2;
916 int level = 0, lastLevel = 0, endLevel = 0, endFlag = 0; 918 int level = 0, lastLevel = 0, endLevel = 0, endFlag = 0;
917 919
918 if ((ctxt == NULL) || (target == NULL) || (source == NULL) || 920 if ((ctxt == NULL) || (target == NULL) || (source == NULL) ||
919 (range == NULL)) 921 (range == NULL))
920 return(NULL); 922 return(NULL);
921 if (range->type != XPATH_RANGE) 923 if (range->type != XPATH_RANGE)
922 return(NULL); 924 return(NULL);
923 start = (xmlNodePtr) range->user; 925 start = (xmlNodePtr) range->user;
924 926
925 if (start == NULL) 927 if ((start == NULL) || (start->type == XML_NAMESPACE_DECL))
926 return(NULL); 928 return(NULL);
927 end = range->user2; 929 end = range->user2;
928 if (end == NULL) 930 if (end == NULL)
929 return(xmlDocCopyNode(start, target, 1)); 931 return(xmlDocCopyNode(start, target, 1));
932 if (end->type == XML_NAMESPACE_DECL)
933 return(NULL);
930 934
931 cur = start; 935 cur = start;
932 index1 = range->index; 936 index1 = range->index;
933 index2 = range->index2; 937 index2 = range->index2;
934 /* 938 /*
935 * level is depth of the current node under consideration 939 * level is depth of the current node under consideration
936 * list is the pointer to the root of the output tree 940 * list is the pointer to the root of the output tree
937 * listParent is a pointer to the parent of output tree (within 941 * listParent is a pointer to the parent of output tree (within
938 the included file) in case we need to add another level 942 the included file) in case we need to add another level
939 * last is a pointer to the last node added to the output tree 943 * last is a pointer to the last node added to the output tree
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 len = index2; 982 len = index2;
979 } 983 }
980 tmp = xmlNewTextLen(content, len); 984 tmp = xmlNewTextLen(content, len);
981 } 985 }
982 /* single sub text node selection */ 986 /* single sub text node selection */
983 if (list == NULL) 987 if (list == NULL)
984 return(tmp); 988 return(tmp);
985 /* prune and return full set */ 989 /* prune and return full set */
986 if (level == lastLevel) 990 if (level == lastLevel)
987 xmlAddNextSibling(last, tmp); 991 xmlAddNextSibling(last, tmp);
988 » » else 992 » » else
989 xmlAddChild(last, tmp); 993 xmlAddChild(last, tmp);
990 return(list); 994 return(list);
991 } else { /* ending node not a text node */ 995 } else { /* ending node not a text node */
992 endLevel = level; /* remember the level of the end node */ 996 endLevel = level; /* remember the level of the end node */
993 endFlag = 1; 997 endFlag = 1;
994 /* last node - need to take care of properties + namespaces */ 998 /* last node - need to take care of properties + namespaces */
995 tmp = xmlDocCopyNode(cur, target, 2); 999 tmp = xmlDocCopyNode(cur, target, 2);
996 if (list == NULL) { 1000 if (list == NULL) {
997 list = tmp; 1001 list = tmp;
998 listParent = cur->parent; 1002 listParent = cur->parent;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 else { 1201 else {
1198 xmlAddNextSibling(last, 1202 xmlAddNextSibling(last,
1199 xmlXIncludeCopyNode(ctxt, target, source, 1203 xmlXIncludeCopyNode(ctxt, target, source,
1200 set->nodeTab[i])); 1204 set->nodeTab[i]));
1201 if (last->next != NULL) 1205 if (last->next != NULL)
1202 last = last->next; 1206 last = last->next;
1203 } 1207 }
1204 } 1208 }
1205 break; 1209 break;
1206 } 1210 }
1211 #ifdef LIBXML_XPTR_ENABLED
1207 case XPATH_LOCATIONSET: { 1212 case XPATH_LOCATIONSET: {
1208 xmlLocationSetPtr set = (xmlLocationSetPtr) obj->user; 1213 xmlLocationSetPtr set = (xmlLocationSetPtr) obj->user;
1209 if (set == NULL) 1214 if (set == NULL)
1210 return(NULL); 1215 return(NULL);
1211 for (i = 0;i < set->locNr;i++) { 1216 for (i = 0;i < set->locNr;i++) {
1212 if (last == NULL) 1217 if (last == NULL)
1213 list = last = xmlXIncludeCopyXPointer(ctxt, target, source, 1218 list = last = xmlXIncludeCopyXPointer(ctxt, target, source,
1214 set->locTab[i]); 1219 set->locTab[i]);
1215 else 1220 else
1216 xmlAddNextSibling(last, 1221 xmlAddNextSibling(last,
1217 xmlXIncludeCopyXPointer(ctxt, target, source, 1222 xmlXIncludeCopyXPointer(ctxt, target, source,
1218 set->locTab[i])); 1223 set->locTab[i]));
1219 if (last != NULL) { 1224 if (last != NULL) {
1220 while (last->next != NULL) 1225 while (last->next != NULL)
1221 last = last->next; 1226 last = last->next;
1222 } 1227 }
1223 } 1228 }
1224 break; 1229 break;
1225 } 1230 }
1226 #ifdef LIBXML_XPTR_ENABLED
1227 case XPATH_RANGE: 1231 case XPATH_RANGE:
1228 return(xmlXIncludeCopyRange(ctxt, target, source, obj)); 1232 return(xmlXIncludeCopyRange(ctxt, target, source, obj));
1229 #endif 1233 #endif
1230 case XPATH_POINT: 1234 case XPATH_POINT:
1231 /* points are ignored in XInclude */ 1235 /* points are ignored in XInclude */
1232 break; 1236 break;
1233 default: 1237 default:
1234 break; 1238 break;
1235 } 1239 }
1236 return(list); 1240 return(list);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 ret = xmlAddDocEntity(doc, ent->name, ent->etype, ent->ExternalID, 1286 ret = xmlAddDocEntity(doc, ent->name, ent->etype, ent->ExternalID,
1283 ent->SystemID, ent->content); 1287 ent->SystemID, ent->content);
1284 if (ret != NULL) { 1288 if (ret != NULL) {
1285 if (ent->URI != NULL) 1289 if (ent->URI != NULL)
1286 ret->URI = xmlStrdup(ent->URI); 1290 ret->URI = xmlStrdup(ent->URI);
1287 } else { 1291 } else {
1288 prev = xmlGetDocEntity(doc, ent->name); 1292 prev = xmlGetDocEntity(doc, ent->name);
1289 if (prev != NULL) { 1293 if (prev != NULL) {
1290 if (ent->etype != prev->etype) 1294 if (ent->etype != prev->etype)
1291 goto error; 1295 goto error;
1292 » 1296
1293 if ((ent->SystemID != NULL) && (prev->SystemID != NULL)) { 1297 if ((ent->SystemID != NULL) && (prev->SystemID != NULL)) {
1294 if (!xmlStrEqual(ent->SystemID, prev->SystemID)) 1298 if (!xmlStrEqual(ent->SystemID, prev->SystemID))
1295 goto error; 1299 goto error;
1296 } else if ((ent->ExternalID != NULL) && 1300 } else if ((ent->ExternalID != NULL) &&
1297 (prev->ExternalID != NULL)) { 1301 (prev->ExternalID != NULL)) {
1298 if (!xmlStrEqual(ent->ExternalID, prev->ExternalID)) 1302 if (!xmlStrEqual(ent->ExternalID, prev->ExternalID))
1299 goto error; 1303 goto error;
1300 } else if ((ent->content != NULL) && (prev->content != NULL)) { 1304 } else if ((ent->content != NULL) && (prev->content != NULL)) {
1301 if (!xmlStrEqual(ent->content, prev->content)) 1305 if (!xmlStrEqual(ent->content, prev->content))
1302 goto error; 1306 goto error;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 } 1386 }
1383 } 1387 }
1384 return(0); 1388 return(0);
1385 } 1389 }
1386 1390
1387 /** 1391 /**
1388 * xmlXIncludeLoadDoc: 1392 * xmlXIncludeLoadDoc:
1389 * @ctxt: the XInclude context 1393 * @ctxt: the XInclude context
1390 * @url: the associated URL 1394 * @url: the associated URL
1391 * @nr: the xinclude node number 1395 * @nr: the xinclude node number
1392 * 1396 *
1393 * Load the document, and store the result in the XInclude context 1397 * Load the document, and store the result in the XInclude context
1394 * 1398 *
1395 * Returns 0 in case of success, -1 in case of failure 1399 * Returns 0 in case of success, -1 in case of failure
1396 */ 1400 */
1397 static int 1401 static int
1398 xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { 1402 xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
1399 xmlDocPtr doc; 1403 xmlDocPtr doc;
1400 xmlURIPtr uri; 1404 xmlURIPtr uri;
1401 xmlChar *URL; 1405 xmlChar *URL;
1402 xmlChar *fragment = NULL; 1406 xmlChar *fragment = NULL;
1403 int i = 0; 1407 int i = 0;
1404 #ifdef LIBXML_XPTR_ENABLED 1408 #ifdef LIBXML_XPTR_ENABLED
1405 int saveFlags; 1409 int saveFlags;
1406 #endif 1410 #endif
1407 1411
1408 #ifdef DEBUG_XINCLUDE 1412 #ifdef DEBUG_XINCLUDE
1409 xmlGenericError(xmlGenericErrorContext, "Loading doc %s:%d\n", url, nr); 1413 xmlGenericError(xmlGenericErrorContext, "Loading doc %s:%d\n", url, nr);
1410 #endif 1414 #endif
1411 /* 1415 /*
1412 * Check the URL and remove any fragment identifier 1416 * Check the URL and remove any fragment identifier
1413 */ 1417 */
1414 uri = xmlParseURI((const char *)url); 1418 uri = xmlParseURI((const char *)url);
1415 if (uri == NULL) { 1419 if (uri == NULL) {
1416 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1420 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1417 XML_XINCLUDE_HREF_URI, 1421 XML_XINCLUDE_HREF_URI,
1418 "invalid value URI %s\n", url); 1422 "invalid value URI %s\n", url);
1419 return(-1); 1423 return(-1);
1420 } 1424 }
1421 if (uri->fragment != NULL) { 1425 if (uri->fragment != NULL) {
1422 fragment = (xmlChar *) uri->fragment; 1426 fragment = (xmlChar *) uri->fragment;
1423 uri->fragment = NULL; 1427 uri->fragment = NULL;
1424 } 1428 }
1425 if ((ctxt->incTab != NULL) && (ctxt->incTab[nr] != NULL) && 1429 if ((ctxt->incTab != NULL) && (ctxt->incTab[nr] != NULL) &&
1426 (ctxt->incTab[nr]->fragment != NULL)) { 1430 (ctxt->incTab[nr]->fragment != NULL)) {
1427 if (fragment != NULL) xmlFree(fragment); 1431 if (fragment != NULL) xmlFree(fragment);
1428 fragment = xmlStrdup(ctxt->incTab[nr]->fragment); 1432 fragment = xmlStrdup(ctxt->incTab[nr]->fragment);
1429 } 1433 }
1430 URL = xmlSaveUri(uri); 1434 URL = xmlSaveUri(uri);
1431 xmlFreeURI(uri); 1435 xmlFreeURI(uri);
1432 if (URL == NULL) { 1436 if (URL == NULL) {
1433 if (ctxt->incTab != NULL) 1437 if (ctxt->incTab != NULL)
1434 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1438 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1435 XML_XINCLUDE_HREF_URI, 1439 XML_XINCLUDE_HREF_URI,
1436 "invalid value URI %s\n", url); 1440 "invalid value URI %s\n", url);
1437 else 1441 else
1438 xmlXIncludeErr(ctxt, NULL, 1442 xmlXIncludeErr(ctxt, NULL,
1439 XML_XINCLUDE_HREF_URI, 1443 XML_XINCLUDE_HREF_URI,
1440 "invalid value URI %s\n", url); 1444 "invalid value URI %s\n", url);
1441 if (fragment != NULL) 1445 if (fragment != NULL)
1442 xmlFree(fragment); 1446 xmlFree(fragment);
1443 return(-1); 1447 return(-1);
1444 } 1448 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 */ 1547 */
1544 if (doc == NULL) 1548 if (doc == NULL)
1545 { 1549 {
1546 /* Hopefully a DTD declaration won't be copied from 1550 /* Hopefully a DTD declaration won't be copied from
1547 * the same document */ 1551 * the same document */
1548 ctxt->incTab[nr]->inc = xmlCopyNodeList(ctxt->doc->children); 1552 ctxt->incTab[nr]->inc = xmlCopyNodeList(ctxt->doc->children);
1549 } else { 1553 } else {
1550 ctxt->incTab[nr]->inc = xmlXIncludeCopyNodeList(ctxt, ctxt->doc, 1554 ctxt->incTab[nr]->inc = xmlXIncludeCopyNodeList(ctxt, ctxt->doc,
1551 doc, doc->children); 1555 doc, doc->children);
1552 } 1556 }
1553 } 1557 }
1554 #ifdef LIBXML_XPTR_ENABLED 1558 #ifdef LIBXML_XPTR_ENABLED
1555 else { 1559 else {
1556 /* 1560 /*
1557 * Computes the XPointer expression and make a copy used 1561 * Computes the XPointer expression and make a copy used
1558 * as the replacement copy. 1562 * as the replacement copy.
1559 */ 1563 */
1560 xmlXPathObjectPtr xptr; 1564 xmlXPathObjectPtr xptr;
1561 xmlXPathContextPtr xptrctxt; 1565 xmlXPathContextPtr xptrctxt;
1562 xmlNodeSetPtr set; 1566 xmlNodeSetPtr set;
1563 1567
1564 if (doc == NULL) { 1568 if (doc == NULL) {
1565 xptrctxt = xmlXPtrNewContext(ctxt->doc, ctxt->incTab[nr]->ref, 1569 xptrctxt = xmlXPtrNewContext(ctxt->doc, ctxt->incTab[nr]->ref,
1566 NULL); 1570 NULL);
1567 } else { 1571 } else {
1568 xptrctxt = xmlXPtrNewContext(doc, NULL, NULL); 1572 xptrctxt = xmlXPtrNewContext(doc, NULL, NULL);
1569 } 1573 }
1570 if (xptrctxt == NULL) { 1574 if (xptrctxt == NULL) {
1571 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1575 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1572 XML_XINCLUDE_XPTR_FAILED, 1576 XML_XINCLUDE_XPTR_FAILED,
1573 "could not create XPointer context\n", NULL); 1577 "could not create XPointer context\n", NULL);
1574 xmlFree(URL); 1578 xmlFree(URL);
1575 xmlFree(fragment); 1579 xmlFree(fragment);
1576 return(-1); 1580 return(-1);
1577 } 1581 }
1578 xptr = xmlXPtrEval(fragment, xptrctxt); 1582 xptr = xmlXPtrEval(fragment, xptrctxt);
1579 if (xptr == NULL) { 1583 if (xptr == NULL) {
1580 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1584 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1581 XML_XINCLUDE_XPTR_FAILED, 1585 XML_XINCLUDE_XPTR_FAILED,
1582 "XPointer evaluation failed: #%s\n", 1586 "XPointer evaluation failed: #%s\n",
1583 fragment); 1587 fragment);
1584 xmlXPathFreeContext(xptrctxt); 1588 xmlXPathFreeContext(xptrctxt);
1585 xmlFree(URL); 1589 xmlFree(URL);
1586 xmlFree(fragment); 1590 xmlFree(fragment);
1587 return(-1); 1591 return(-1);
1588 } 1592 }
1589 switch (xptr->type) { 1593 switch (xptr->type) {
1590 case XPATH_UNDEFINED: 1594 case XPATH_UNDEFINED:
1591 case XPATH_BOOLEAN: 1595 case XPATH_BOOLEAN:
1592 case XPATH_NUMBER: 1596 case XPATH_NUMBER:
1593 case XPATH_STRING: 1597 case XPATH_STRING:
1594 case XPATH_POINT: 1598 case XPATH_POINT:
1595 case XPATH_USERS: 1599 case XPATH_USERS:
1596 case XPATH_XSLT_TREE: 1600 case XPATH_XSLT_TREE:
1597 » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1601 » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1598 XML_XINCLUDE_XPTR_RESULT, 1602 XML_XINCLUDE_XPTR_RESULT,
1599 "XPointer is not a range: #%s\n", 1603 "XPointer is not a range: #%s\n",
1600 fragment); 1604 fragment);
1601 xmlXPathFreeContext(xptrctxt); 1605 xmlXPathFreeContext(xptrctxt);
1602 xmlFree(URL); 1606 xmlFree(URL);
1603 xmlFree(fragment); 1607 xmlFree(fragment);
1604 return(-1); 1608 return(-1);
1605 case XPATH_NODESET: 1609 case XPATH_NODESET:
1606 if ((xptr->nodesetval == NULL) || 1610 if ((xptr->nodesetval == NULL) ||
1607 (xptr->nodesetval->nodeNr <= 0)) { 1611 (xptr->nodesetval->nodeNr <= 0)) {
(...skipping 21 matching lines...) Expand all
1629 case XML_PI_NODE: 1633 case XML_PI_NODE:
1630 case XML_COMMENT_NODE: 1634 case XML_COMMENT_NODE:
1631 case XML_DOCUMENT_NODE: 1635 case XML_DOCUMENT_NODE:
1632 case XML_HTML_DOCUMENT_NODE: 1636 case XML_HTML_DOCUMENT_NODE:
1633 #ifdef LIBXML_DOCB_ENABLED 1637 #ifdef LIBXML_DOCB_ENABLED
1634 case XML_DOCB_DOCUMENT_NODE: 1638 case XML_DOCB_DOCUMENT_NODE:
1635 #endif 1639 #endif
1636 continue; 1640 continue;
1637 1641
1638 case XML_ATTRIBUTE_NODE: 1642 case XML_ATTRIBUTE_NODE:
1639 » » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1643 » » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1640 XML_XINCLUDE_XPTR_RESULT, 1644 XML_XINCLUDE_XPTR_RESULT,
1641 "XPointer selects an attribute: #%s\n", 1645 "XPointer selects an attribute: #%s\n",
1642 fragment); 1646 fragment);
1643 set->nodeTab[i] = NULL; 1647 set->nodeTab[i] = NULL;
1644 continue; 1648 continue;
1645 case XML_NAMESPACE_DECL: 1649 case XML_NAMESPACE_DECL:
1646 » » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1650 » » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1647 XML_XINCLUDE_XPTR_RESULT, 1651 XML_XINCLUDE_XPTR_RESULT,
1648 "XPointer selects a namespace: #%s\n", 1652 "XPointer selects a namespace: #%s\n",
1649 fragment); 1653 fragment);
1650 set->nodeTab[i] = NULL; 1654 set->nodeTab[i] = NULL;
1651 continue; 1655 continue;
1652 case XML_DOCUMENT_TYPE_NODE: 1656 case XML_DOCUMENT_TYPE_NODE:
1653 case XML_DOCUMENT_FRAG_NODE: 1657 case XML_DOCUMENT_FRAG_NODE:
1654 case XML_NOTATION_NODE: 1658 case XML_NOTATION_NODE:
1655 case XML_DTD_NODE: 1659 case XML_DTD_NODE:
1656 case XML_ELEMENT_DECL: 1660 case XML_ELEMENT_DECL:
1657 case XML_ATTRIBUTE_DECL: 1661 case XML_ATTRIBUTE_DECL:
1658 case XML_ENTITY_DECL: 1662 case XML_ENTITY_DECL:
1659 case XML_XINCLUDE_START: 1663 case XML_XINCLUDE_START:
1660 case XML_XINCLUDE_END: 1664 case XML_XINCLUDE_END:
1661 » » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1665 » » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1662 XML_XINCLUDE_XPTR_RESULT, 1666 XML_XINCLUDE_XPTR_RESULT,
1663 "XPointer selects unexpected nodes: #%s\n", 1667 "XPointer selects unexpected nodes: #%s\n",
1664 fragment); 1668 fragment);
1665 set->nodeTab[i] = NULL; 1669 set->nodeTab[i] = NULL;
1666 set->nodeTab[i] = NULL; 1670 set->nodeTab[i] = NULL;
1667 continue; /* for */ 1671 continue; /* for */
1668 } 1672 }
1669 } 1673 }
1670 } 1674 }
1671 if (doc == NULL) { 1675 if (doc == NULL) {
1672 ctxt->incTab[nr]->xptr = xptr; 1676 ctxt->incTab[nr]->xptr = xptr;
1673 ctxt->incTab[nr]->inc = NULL; 1677 ctxt->incTab[nr]->inc = NULL;
1674 } else { 1678 } else {
1675 ctxt->incTab[nr]->inc = 1679 ctxt->incTab[nr]->inc =
1676 xmlXIncludeCopyXPointer(ctxt, ctxt->doc, doc, xptr); 1680 xmlXIncludeCopyXPointer(ctxt, ctxt->doc, doc, xptr);
1677 xmlXPathFreeObject(xptr); 1681 xmlXPathFreeObject(xptr);
1678 } 1682 }
1679 xmlXPathFreeContext(xptrctxt); 1683 xmlXPathFreeContext(xptrctxt);
1680 xmlFree(fragment); 1684 xmlFree(fragment);
1681 } 1685 }
1682 #endif 1686 #endif
1683 1687
1684 /* 1688 /*
1685 * Do the xml:base fixup if needed 1689 * Do the xml:base fixup if needed
1686 */ 1690 */
1687 if ((doc != NULL) && (URL != NULL) && (xmlStrchr(URL, (xmlChar) '/')) && 1691 if ((doc != NULL) && (URL != NULL) &&
1688 (!(ctxt->parseFlags & XML_PARSE_NOBASEFIX)) && 1692 (!(ctxt->parseFlags & XML_PARSE_NOBASEFIX)) &&
1689 (!(doc->parseFlags & XML_PARSE_NOBASEFIX))) { 1693 (!(doc->parseFlags & XML_PARSE_NOBASEFIX))) {
1690 xmlNodePtr node; 1694 xmlNodePtr node;
1691 xmlChar *base; 1695 xmlChar *base;
1692 xmlChar *curBase; 1696 xmlChar *curBase;
1693 1697
1694 /* 1698 /*
1695 * The base is only adjusted if "necessary", i.e. if the xinclude node 1699 * The base is only adjusted if "necessary", i.e. if the xinclude node
1696 * has a base specified, or the URL is relative 1700 * has a base specified, or the URL is relative
1697 */ 1701 */
1698 base = xmlGetNsProp(ctxt->incTab[nr]->ref, BAD_CAST "base", 1702 base = xmlGetNsProp(ctxt->incTab[nr]->ref, BAD_CAST "base",
1699 XML_XML_NAMESPACE); 1703 XML_XML_NAMESPACE);
1700 if (base == NULL) { 1704 if (base == NULL) {
1701 /* 1705 /*
1702 * No xml:base on the xinclude node, so we check whether the 1706 * No xml:base on the xinclude node, so we check whether the
1703 * URI base is different than (relative to) the context base 1707 * URI base is different than (relative to) the context base
1704 */ 1708 */
1705 curBase = xmlBuildRelativeURI(URL, ctxt->base); 1709 curBase = xmlBuildRelativeURI(URL, ctxt->base);
1706 if (curBase == NULL) { /* Error return */ 1710 if (curBase == NULL) { /* Error return */
1707 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1711 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1708 XML_XINCLUDE_HREF_URI, 1712 XML_XINCLUDE_HREF_URI,
1709 "trying to build relative URI from %s\n", URL); 1713 "trying to build relative URI from %s\n", URL);
1710 } else { 1714 } else {
1711 /* If the URI doesn't contain a slash, it's not relative */ 1715 /* If the URI doesn't contain a slash, it's not relative */
1712 if (!xmlStrchr(curBase, (xmlChar) '/')) 1716 if (!xmlStrchr(curBase, (xmlChar) '/'))
1713 xmlFree(curBase); 1717 xmlFree(curBase);
1714 else 1718 else
1715 base = curBase; 1719 base = curBase;
1716 } 1720 }
1717 } 1721 }
(...skipping 20 matching lines...) Expand all
1738 * set, then relativise it if necessary 1742 * set, then relativise it if necessary
1739 */ 1743 */
1740 xmlChar *xmlBase; 1744 xmlChar *xmlBase;
1741 xmlBase = xmlGetNsProp(node, 1745 xmlBase = xmlGetNsProp(node,
1742 BAD_CAST "base", 1746 BAD_CAST "base",
1743 XML_XML_NAMESPACE); 1747 XML_XML_NAMESPACE);
1744 if (xmlBase != NULL) { 1748 if (xmlBase != NULL) {
1745 xmlChar *relBase; 1749 xmlChar *relBase;
1746 relBase = xmlBuildURI(xmlBase, base); 1750 relBase = xmlBuildURI(xmlBase, base);
1747 if (relBase == NULL) { /* error */ 1751 if (relBase == NULL) { /* error */
1748 » » » » xmlXIncludeErr(ctxt, 1752 » » » » xmlXIncludeErr(ctxt,
1749 ctxt->incTab[nr]->ref, 1753 ctxt->incTab[nr]->ref,
1750 XML_XINCLUDE_HREF_URI, 1754 XML_XINCLUDE_HREF_URI,
1751 "trying to rebuild base from %s\n", 1755 "trying to rebuild base from %s\n",
1752 xmlBase); 1756 xmlBase);
1753 } else { 1757 } else {
1754 xmlNodeSetBase(node, relBase); 1758 xmlNodeSetBase(node, relBase);
1755 xmlFree(relBase); 1759 xmlFree(relBase);
1756 } 1760 }
1757 xmlFree(xmlBase); 1761 xmlFree(xmlBase);
1758 } 1762 }
(...skipping 16 matching lines...) Expand all
1775 } 1779 }
1776 xmlFree(URL); 1780 xmlFree(URL);
1777 return(0); 1781 return(0);
1778 } 1782 }
1779 1783
1780 /** 1784 /**
1781 * xmlXIncludeLoadTxt: 1785 * xmlXIncludeLoadTxt:
1782 * @ctxt: the XInclude context 1786 * @ctxt: the XInclude context
1783 * @url: the associated URL 1787 * @url: the associated URL
1784 * @nr: the xinclude node number 1788 * @nr: the xinclude node number
1785 * 1789 *
1786 * Load the content, and store the result in the XInclude context 1790 * Load the content, and store the result in the XInclude context
1787 * 1791 *
1788 * Returns 0 in case of success, -1 in case of failure 1792 * Returns 0 in case of success, -1 in case of failure
1789 */ 1793 */
1790 static int 1794 static int
1791 xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { 1795 xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
1792 xmlParserInputBufferPtr buf; 1796 xmlParserInputBufferPtr buf;
1793 xmlNodePtr node; 1797 xmlNodePtr node;
1794 xmlURIPtr uri; 1798 xmlURIPtr uri;
1795 xmlChar *URL; 1799 xmlChar *URL;
1796 int i; 1800 int i;
1797 xmlChar *encoding = NULL; 1801 xmlChar *encoding = NULL;
1798 xmlCharEncoding enc = (xmlCharEncoding) 0; 1802 xmlCharEncoding enc = (xmlCharEncoding) 0;
1803 xmlParserCtxtPtr pctxt;
1804 xmlParserInputPtr inputStream;
1805 int xinclude_multibyte_fallback_used = 0;
1799 1806
1800 /* 1807 /*
1801 * Check the URL and remove any fragment identifier 1808 * Check the URL and remove any fragment identifier
1802 */ 1809 */
1803 uri = xmlParseURI((const char *)url); 1810 uri = xmlParseURI((const char *)url);
1804 if (uri == NULL) { 1811 if (uri == NULL) {
1805 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, XML_XINCLUDE_HREF_URI, 1812 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, XML_XINCLUDE_HREF_URI,
1806 "invalid value URI %s\n", url); 1813 "invalid value URI %s\n", url);
1807 return(-1); 1814 return(-1);
1808 } 1815 }
(...skipping 10 matching lines...) Expand all
1819 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, XML_XINCLUDE_HREF_URI, 1826 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, XML_XINCLUDE_HREF_URI,
1820 "invalid value URI %s\n", url); 1827 "invalid value URI %s\n", url);
1821 return(-1); 1828 return(-1);
1822 } 1829 }
1823 1830
1824 /* 1831 /*
1825 * Handling of references to the local document are done 1832 * Handling of references to the local document are done
1826 * directly through ctxt->doc. 1833 * directly through ctxt->doc.
1827 */ 1834 */
1828 if (URL[0] == 0) { 1835 if (URL[0] == 0) {
1829 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1836 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1830 XML_XINCLUDE_TEXT_DOCUMENT, 1837 XML_XINCLUDE_TEXT_DOCUMENT,
1831 "text serialization of document not available\n", NULL); 1838 "text serialization of document not available\n", NULL);
1832 xmlFree(URL); 1839 xmlFree(URL);
1833 return(-1); 1840 return(-1);
1834 } 1841 }
1835 1842
1836 /* 1843 /*
1837 * Prevent reloading twice the document. 1844 * Prevent reloading twice the document.
1838 */ 1845 */
1839 for (i = 0; i < ctxt->txtNr; i++) { 1846 for (i = 0; i < ctxt->txtNr; i++) {
(...skipping 23 matching lines...) Expand all
1863 xmlFree(encoding); 1870 xmlFree(encoding);
1864 xmlFree(URL); 1871 xmlFree(URL);
1865 return(-1); 1872 return(-1);
1866 } 1873 }
1867 xmlFree(encoding); 1874 xmlFree(encoding);
1868 } 1875 }
1869 1876
1870 /* 1877 /*
1871 * Load it. 1878 * Load it.
1872 */ 1879 */
1873 buf = xmlParserInputBufferCreateFilename((const char *)URL, enc); 1880 pctxt = xmlNewParserCtxt();
1874 if (buf == NULL) { 1881 inputStream = xmlLoadExternalEntity((const char*)URL, NULL, pctxt);
1882 if(inputStream == NULL) {
1883 » xmlFreeParserCtxt(pctxt);
1875 xmlFree(URL); 1884 xmlFree(URL);
1876 return(-1); 1885 return(-1);
1877 } 1886 }
1887 buf = inputStream->buf;
1888 if (buf == NULL) {
1889 xmlFreeInputStream (inputStream);
1890 xmlFreeParserCtxt(pctxt);
1891 xmlFree(URL);
1892 return(-1);
1893 }
1894 if (buf->encoder)
1895 xmlCharEncCloseFunc(buf->encoder);
1896 buf->encoder = xmlGetCharEncodingHandler(enc);
1878 node = xmlNewText(NULL); 1897 node = xmlNewText(NULL);
1879 1898
1880 /* 1899 /*
1881 * Scan all chars from the resource and add the to the node 1900 * Scan all chars from the resource and add the to the node
1882 */ 1901 */
1902 xinclude_multibyte_fallback:
1883 while (xmlParserInputBufferRead(buf, 128) > 0) { 1903 while (xmlParserInputBufferRead(buf, 128) > 0) {
1884 int len; 1904 int len;
1885 const xmlChar *content; 1905 const xmlChar *content;
1886 1906
1887 » content = xmlBufferContent(buf->buffer); 1907 » content = xmlBufContent(buf->buffer);
1888 » len = xmlBufferLength(buf->buffer); 1908 » len = xmlBufLength(buf->buffer);
1889 for (i = 0;i < len;) { 1909 for (i = 0;i < len;) {
1890 int cur; 1910 int cur;
1891 int l; 1911 int l;
1892 1912
1893 cur = xmlStringCurrentChar(NULL, &content[i], &l); 1913 cur = xmlStringCurrentChar(NULL, &content[i], &l);
1894 if (!IS_CHAR(cur)) { 1914 if (!IS_CHAR(cur)) {
1895 » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 1915 » » /* Handle splitted multibyte char at buffer boundary */
1896 » » XML_XINCLUDE_INVALID_CHAR, 1916 » » if (((len - i) < 4) && (!xinclude_multibyte_fallback_used)) {
1897 » » » "%s contains invalid char\n", URL); 1917 » » xinclude_multibyte_fallback_used = 1;
1898 » » xmlFreeParserInputBuffer(buf); 1918 » » xmlBufShrink(buf->buffer, i);
1899 » » xmlFree(URL); 1919 » » goto xinclude_multibyte_fallback;
1900 » » return(-1); 1920 » » } else {
1921 » » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
1922 » » » » XML_XINCLUDE_INVALID_CHAR,
1923 » » » » "%s contains invalid char\n", URL);
1924 » » xmlFreeParserInputBuffer(buf);
1925 » » xmlFree(URL);
1926 » » return(-1);
1927 » » }
1901 } else { 1928 } else {
1929 xinclude_multibyte_fallback_used = 0;
1902 xmlNodeAddContentLen(node, &content[i], l); 1930 xmlNodeAddContentLen(node, &content[i], l);
1903 } 1931 }
1904 i += l; 1932 i += l;
1905 } 1933 }
1906 » xmlBufferShrink(buf->buffer, len); 1934 » xmlBufShrink(buf->buffer, len);
1907 } 1935 }
1908 xmlFreeParserInputBuffer(buf); 1936 xmlFreeParserCtxt(pctxt);
1909 xmlXIncludeAddTxt(ctxt, node, URL); 1937 xmlXIncludeAddTxt(ctxt, node, URL);
1938 xmlFreeInputStream(inputStream);
1910 1939
1911 loaded: 1940 loaded:
1912 /* 1941 /*
1913 * Add the element as the replacement copy. 1942 * Add the element as the replacement copy.
1914 */ 1943 */
1915 ctxt->incTab[nr]->inc = node; 1944 ctxt->incTab[nr]->inc = node;
1916 xmlFree(URL); 1945 xmlFree(URL);
1917 return(0); 1946 return(0);
1918 } 1947 }
1919 1948
1920 /** 1949 /**
1921 * xmlXIncludeLoadFallback: 1950 * xmlXIncludeLoadFallback:
1922 * @ctxt: the XInclude context 1951 * @ctxt: the XInclude context
1923 * @fallback: the fallback node 1952 * @fallback: the fallback node
1924 * @nr: the xinclude node number 1953 * @nr: the xinclude node number
1925 * 1954 *
1926 * Load the content of the fallback node, and store the result 1955 * Load the content of the fallback node, and store the result
1927 * in the XInclude context 1956 * in the XInclude context
1928 * 1957 *
1929 * Returns 0 in case of success, -1 in case of failure 1958 * Returns 0 in case of success, -1 in case of failure
1930 */ 1959 */
1931 static int 1960 static int
1932 xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) { 1961 xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
1933 xmlXIncludeCtxtPtr newctxt; 1962 xmlXIncludeCtxtPtr newctxt;
1934 int ret = 0; 1963 int ret = 0;
1935 1964
1936 if ((fallback == NULL) || (ctxt == NULL)) 1965 if ((fallback == NULL) || (fallback->type == XML_NAMESPACE_DECL) ||
1966 (ctxt == NULL))
1937 return(-1); 1967 return(-1);
1938 if (fallback->children != NULL) { 1968 if (fallback->children != NULL) {
1939 /* 1969 /*
1940 * It's possible that the fallback also has 'includes' 1970 * It's possible that the fallback also has 'includes'
1941 * (Bug 129969), so we re-process the fallback just in case 1971 * (Bug 129969), so we re-process the fallback just in case
1942 */ 1972 */
1943 newctxt = xmlXIncludeNewContext(ctxt->doc); 1973 newctxt = xmlXIncludeNewContext(ctxt->doc);
1944 if (newctxt == NULL) 1974 if (newctxt == NULL)
1945 return (-1); 1975 return (-1);
1946 newctxt->_private = ctxt->_private; 1976 newctxt->_private = ctxt->_private;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 cur = ctxt->incTab[nr]->ref; 2041 cur = ctxt->incTab[nr]->ref;
2012 if (cur == NULL) 2042 if (cur == NULL)
2013 return(-1); 2043 return(-1);
2014 2044
2015 /* 2045 /*
2016 * read the attributes 2046 * read the attributes
2017 */ 2047 */
2018 href = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_HREF); 2048 href = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_HREF);
2019 if (href == NULL) { 2049 if (href == NULL) {
2020 href = xmlStrdup(BAD_CAST ""); /* @@@@ href is now optional */ 2050 href = xmlStrdup(BAD_CAST ""); /* @@@@ href is now optional */
2021 » if (href == NULL) 2051 » if (href == NULL)
2022 return(-1); 2052 return(-1);
2023 } 2053 }
2024 parse = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_PARSE); 2054 parse = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_PARSE);
2025 if (parse != NULL) { 2055 if (parse != NULL) {
2026 if (xmlStrEqual(parse, XINCLUDE_PARSE_XML)) 2056 if (xmlStrEqual(parse, XINCLUDE_PARSE_XML))
2027 xml = 1; 2057 xml = 1;
2028 else if (xmlStrEqual(parse, XINCLUDE_PARSE_TEXT)) 2058 else if (xmlStrEqual(parse, XINCLUDE_PARSE_TEXT))
2029 xml = 0; 2059 xml = 0;
2030 else { 2060 else {
2031 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 2061 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
(...skipping 24 matching lines...) Expand all
2056 */ 2086 */
2057 escbase = xmlURIEscape(base); 2087 escbase = xmlURIEscape(base);
2058 eschref = xmlURIEscape(href); 2088 eschref = xmlURIEscape(href);
2059 URI = xmlBuildURI(eschref, escbase); 2089 URI = xmlBuildURI(eschref, escbase);
2060 if (escbase != NULL) 2090 if (escbase != NULL)
2061 xmlFree(escbase); 2091 xmlFree(escbase);
2062 if (eschref != NULL) 2092 if (eschref != NULL)
2063 xmlFree(eschref); 2093 xmlFree(eschref);
2064 } 2094 }
2065 if (URI == NULL) { 2095 if (URI == NULL) {
2066 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 2096 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
2067 XML_XINCLUDE_HREF_URI, "failed build URL\n", NULL); 2097 XML_XINCLUDE_HREF_URI, "failed build URL\n", NULL);
2068 if (parse != NULL) 2098 if (parse != NULL)
2069 xmlFree(parse); 2099 xmlFree(parse);
2070 if (href != NULL) 2100 if (href != NULL)
2071 xmlFree(href); 2101 xmlFree(href);
2072 if (base != NULL) 2102 if (base != NULL)
2073 xmlFree(base); 2103 xmlFree(base);
2074 return(-1); 2104 return(-1);
2075 } 2105 }
2076 #ifdef DEBUG_XINCLUDE 2106 #ifdef DEBUG_XINCLUDE
(...skipping 12 matching lines...) Expand all
2089 ret = xmlXIncludeLoadDoc(ctxt, URI, nr); 2119 ret = xmlXIncludeLoadDoc(ctxt, URI, nr);
2090 /* xmlXIncludeGetFragment(ctxt, cur, URI); */ 2120 /* xmlXIncludeGetFragment(ctxt, cur, URI); */
2091 } else { 2121 } else {
2092 ret = xmlXIncludeLoadTxt(ctxt, URI, nr); 2122 ret = xmlXIncludeLoadTxt(ctxt, URI, nr);
2093 } 2123 }
2094 2124
2095 /* 2125 /*
2096 * Restore the original base before checking for fallback 2126 * Restore the original base before checking for fallback
2097 */ 2127 */
2098 ctxt->base = oldBase; 2128 ctxt->base = oldBase;
2099 2129
2100 if (ret < 0) { 2130 if (ret < 0) {
2101 xmlNodePtr children; 2131 xmlNodePtr children;
2102 2132
2103 /* 2133 /*
2104 * Time to try a fallback if availble 2134 * Time to try a fallback if availble
2105 */ 2135 */
2106 #ifdef DEBUG_XINCLUDE 2136 #ifdef DEBUG_XINCLUDE
2107 xmlGenericError(xmlGenericErrorContext, "error looking for fallback\n"); 2137 xmlGenericError(xmlGenericErrorContext, "error looking for fallback\n");
2108 #endif 2138 #endif
2109 children = cur->children; 2139 children = cur->children;
2110 while (children != NULL) { 2140 while (children != NULL) {
2111 if ((children->type == XML_ELEMENT_NODE) && 2141 if ((children->type == XML_ELEMENT_NODE) &&
2112 (children->ns != NULL) && 2142 (children->ns != NULL) &&
2113 (xmlStrEqual(children->name, XINCLUDE_FALLBACK)) && 2143 (xmlStrEqual(children->name, XINCLUDE_FALLBACK)) &&
2114 ((xmlStrEqual(children->ns->href, XINCLUDE_NS)) || 2144 ((xmlStrEqual(children->ns->href, XINCLUDE_NS)) ||
2115 (xmlStrEqual(children->ns->href, XINCLUDE_OLD_NS)))) { 2145 (xmlStrEqual(children->ns->href, XINCLUDE_OLD_NS)))) {
2116 ret = xmlXIncludeLoadFallback(ctxt, children, nr); 2146 ret = xmlXIncludeLoadFallback(ctxt, children, nr);
2117 » » if (ret == 0) 2147 » » if (ret == 0)
2118 break; 2148 break;
2119 } 2149 }
2120 children = children->next; 2150 children = children->next;
2121 } 2151 }
2122 } 2152 }
2123 if (ret < 0) { 2153 if (ret < 0) {
2124 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 2154 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
2125 XML_XINCLUDE_NO_FALLBACK, 2155 XML_XINCLUDE_NO_FALLBACK,
2126 "could not load %s, and no fallback was found\n", 2156 "could not load %s, and no fallback was found\n",
2127 URI); 2157 URI);
2128 } 2158 }
2129 2159
2130 /* 2160 /*
2131 * Cleanup 2161 * Cleanup
2132 */ 2162 */
2133 if (URI != NULL) 2163 if (URI != NULL)
2134 xmlFree(URI); 2164 xmlFree(URI);
(...skipping 17 matching lines...) Expand all
2152 */ 2182 */
2153 static int 2183 static int
2154 xmlXIncludeIncludeNode(xmlXIncludeCtxtPtr ctxt, int nr) { 2184 xmlXIncludeIncludeNode(xmlXIncludeCtxtPtr ctxt, int nr) {
2155 xmlNodePtr cur, end, list, tmp; 2185 xmlNodePtr cur, end, list, tmp;
2156 2186
2157 if (ctxt == NULL) 2187 if (ctxt == NULL)
2158 return(-1); 2188 return(-1);
2159 if ((nr < 0) || (nr >= ctxt->incNr)) 2189 if ((nr < 0) || (nr >= ctxt->incNr))
2160 return(-1); 2190 return(-1);
2161 cur = ctxt->incTab[nr]->ref; 2191 cur = ctxt->incTab[nr]->ref;
2162 if (cur == NULL) 2192 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
2163 return(-1); 2193 return(-1);
2164 2194
2165 /* 2195 /*
2166 * If we stored an XPointer a late computation may be needed 2196 * If we stored an XPointer a late computation may be needed
2167 */ 2197 */
2168 if ((ctxt->incTab[nr]->inc == NULL) && 2198 if ((ctxt->incTab[nr]->inc == NULL) &&
2169 (ctxt->incTab[nr]->xptr != NULL)) { 2199 (ctxt->incTab[nr]->xptr != NULL)) {
2170 ctxt->incTab[nr]->inc = 2200 ctxt->incTab[nr]->inc =
2171 xmlXIncludeCopyXPointer(ctxt, ctxt->doc, ctxt->doc, 2201 xmlXIncludeCopyXPointer(ctxt, ctxt->doc, ctxt->doc,
2172 ctxt->incTab[nr]->xptr); 2202 ctxt->incTab[nr]->xptr);
(...skipping 10 matching lines...) Expand all
2183 (cur->parent->type != XML_ELEMENT_NODE)) { 2213 (cur->parent->type != XML_ELEMENT_NODE)) {
2184 int nb_elem = 0; 2214 int nb_elem = 0;
2185 2215
2186 tmp = list; 2216 tmp = list;
2187 while (tmp != NULL) { 2217 while (tmp != NULL) {
2188 if (tmp->type == XML_ELEMENT_NODE) 2218 if (tmp->type == XML_ELEMENT_NODE)
2189 nb_elem++; 2219 nb_elem++;
2190 tmp = tmp->next; 2220 tmp = tmp->next;
2191 } 2221 }
2192 if (nb_elem > 1) { 2222 if (nb_elem > 1) {
2193 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 2223 » xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
2194 XML_XINCLUDE_MULTIPLE_ROOT, 2224 XML_XINCLUDE_MULTIPLE_ROOT,
2195 "XInclude error: would result in multiple root nodes\n", 2225 "XInclude error: would result in multiple root nodes\n",
2196 NULL); 2226 NULL);
2197 return(-1); 2227 return(-1);
2198 } 2228 }
2199 } 2229 }
2200 2230
2201 if (ctxt->parseFlags & XML_PARSE_NOXINCNODE) { 2231 if (ctxt->parseFlags & XML_PARSE_NOXINCNODE) {
2202 /* 2232 /*
2203 * Add the list of nodes 2233 * Add the list of nodes
(...skipping 26 matching lines...) Expand all
2230 * Add the list of nodes 2260 * Add the list of nodes
2231 */ 2261 */
2232 while (list != NULL) { 2262 while (list != NULL) {
2233 cur = list; 2263 cur = list;
2234 list = list->next; 2264 list = list->next;
2235 2265
2236 xmlAddPrevSibling(end, cur); 2266 xmlAddPrevSibling(end, cur);
2237 } 2267 }
2238 } 2268 }
2239 2269
2240 2270
2241 return(0); 2271 return(0);
2242 } 2272 }
2243 2273
2244 /** 2274 /**
2245 * xmlXIncludeTestNode: 2275 * xmlXIncludeTestNode:
2246 * @ctxt: the XInclude processing context 2276 * @ctxt: the XInclude processing context
2247 * @node: an XInclude node 2277 * @node: an XInclude node
2248 * 2278 *
2249 * test if the node is an XInclude node 2279 * test if the node is an XInclude node
2250 * 2280 *
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 * 2357 *
2328 * Returns 0 if no substitution were done, -1 if some processing failed 2358 * Returns 0 if no substitution were done, -1 if some processing failed
2329 * or the number of substitutions done. 2359 * or the number of substitutions done.
2330 */ 2360 */
2331 static int 2361 static int
2332 xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree) { 2362 xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree) {
2333 xmlNodePtr cur; 2363 xmlNodePtr cur;
2334 int ret = 0; 2364 int ret = 0;
2335 int i, start; 2365 int i, start;
2336 2366
2337 if ((doc == NULL) || (tree == NULL)) 2367 if ((doc == NULL) || (tree == NULL) || (tree->type == XML_NAMESPACE_DECL))
2338 return(-1); 2368 return(-1);
2339 if (ctxt == NULL) 2369 if (ctxt == NULL)
2340 return(-1); 2370 return(-1);
2341 2371
2342 if (doc->URL != NULL) { 2372 if (doc->URL != NULL) {
2343 ret = xmlXIncludeURLPush(ctxt, doc->URL); 2373 ret = xmlXIncludeURLPush(ctxt, doc->URL);
2344 if (ret < 0) 2374 if (ret < 0)
2345 return(-1); 2375 return(-1);
2346 } 2376 }
2347 start = ctxt->incNr; 2377 start = ctxt->incNr;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 * 2471 *
2442 * Returns 0 if no substitution were done, -1 if some processing failed 2472 * Returns 0 if no substitution were done, -1 if some processing failed
2443 * or the number of substitutions done. 2473 * or the number of substitutions done.
2444 */ 2474 */
2445 2475
2446 int 2476 int
2447 xmlXIncludeProcessTreeFlagsData(xmlNodePtr tree, int flags, void *data) { 2477 xmlXIncludeProcessTreeFlagsData(xmlNodePtr tree, int flags, void *data) {
2448 xmlXIncludeCtxtPtr ctxt; 2478 xmlXIncludeCtxtPtr ctxt;
2449 int ret = 0; 2479 int ret = 0;
2450 2480
2451 if ((tree == NULL) || (tree->doc == NULL)) 2481 if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL) ||
2482 (tree->doc == NULL))
2452 return(-1); 2483 return(-1);
2453 2484
2454 ctxt = xmlXIncludeNewContext(tree->doc); 2485 ctxt = xmlXIncludeNewContext(tree->doc);
2455 if (ctxt == NULL) 2486 if (ctxt == NULL)
2456 return(-1); 2487 return(-1);
2457 ctxt->_private = data; 2488 ctxt->_private = data;
2458 ctxt->base = xmlStrdup((xmlChar *)tree->doc->URL); 2489 ctxt->base = xmlStrdup((xmlChar *)tree->doc->URL);
2459 xmlXIncludeSetFlags(ctxt, flags); 2490 xmlXIncludeSetFlags(ctxt, flags);
2460 ret = xmlXIncludeDoProcess(ctxt, tree->doc, tree); 2491 ret = xmlXIncludeDoProcess(ctxt, tree->doc, tree);
2461 if ((ret >= 0) && (ctxt->nbErrors > 0)) 2492 if ((ret >= 0) && (ctxt->nbErrors > 0))
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 * Implement the XInclude substitution for the given subtree 2557 * Implement the XInclude substitution for the given subtree
2527 * 2558 *
2528 * Returns 0 if no substitution were done, -1 if some processing failed 2559 * Returns 0 if no substitution were done, -1 if some processing failed
2529 * or the number of substitutions done. 2560 * or the number of substitutions done.
2530 */ 2561 */
2531 int 2562 int
2532 xmlXIncludeProcessTreeFlags(xmlNodePtr tree, int flags) { 2563 xmlXIncludeProcessTreeFlags(xmlNodePtr tree, int flags) {
2533 xmlXIncludeCtxtPtr ctxt; 2564 xmlXIncludeCtxtPtr ctxt;
2534 int ret = 0; 2565 int ret = 0;
2535 2566
2536 if ((tree == NULL) || (tree->doc == NULL)) 2567 if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL) ||
2568 (tree->doc == NULL))
2537 return(-1); 2569 return(-1);
2538 ctxt = xmlXIncludeNewContext(tree->doc); 2570 ctxt = xmlXIncludeNewContext(tree->doc);
2539 if (ctxt == NULL) 2571 if (ctxt == NULL)
2540 return(-1); 2572 return(-1);
2541 ctxt->base = xmlNodeGetBase(tree->doc, tree); 2573 ctxt->base = xmlNodeGetBase(tree->doc, tree);
2542 xmlXIncludeSetFlags(ctxt, flags); 2574 xmlXIncludeSetFlags(ctxt, flags);
2543 ret = xmlXIncludeDoProcess(ctxt, tree->doc, tree); 2575 ret = xmlXIncludeDoProcess(ctxt, tree->doc, tree);
2544 if ((ret >= 0) && (ctxt->nbErrors > 0)) 2576 if ((ret >= 0) && (ctxt->nbErrors > 0))
2545 ret = -1; 2577 ret = -1;
2546 2578
(...skipping 23 matching lines...) Expand all
2570 * Implement the XInclude substitution for the given subtree reusing 2602 * Implement the XInclude substitution for the given subtree reusing
2571 * the informations and data coming from the given context. 2603 * the informations and data coming from the given context.
2572 * 2604 *
2573 * Returns 0 if no substitution were done, -1 if some processing failed 2605 * Returns 0 if no substitution were done, -1 if some processing failed
2574 * or the number of substitutions done. 2606 * or the number of substitutions done.
2575 */ 2607 */
2576 int 2608 int
2577 xmlXIncludeProcessNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) { 2609 xmlXIncludeProcessNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node) {
2578 int ret = 0; 2610 int ret = 0;
2579 2611
2580 if ((node == NULL) || (node->doc == NULL) || (ctxt == NULL)) 2612 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) ||
2613 (node->doc == NULL) || (ctxt == NULL))
2581 return(-1); 2614 return(-1);
2582 ret = xmlXIncludeDoProcess(ctxt, node->doc, node); 2615 ret = xmlXIncludeDoProcess(ctxt, node->doc, node);
2583 if ((ret >= 0) && (ctxt->nbErrors > 0)) 2616 if ((ret >= 0) && (ctxt->nbErrors > 0))
2584 ret = -1; 2617 ret = -1;
2585 return(ret); 2618 return(ret);
2586 } 2619 }
2587 2620
2588 #else /* !LIBXML_XINCLUDE_ENABLED */ 2621 #else /* !LIBXML_XINCLUDE_ENABLED */
2589 #endif 2622 #endif
2590 #define bottom_xinclude 2623 #define bottom_xinclude
2591 #include "elfgcchack.h" 2624 #include "elfgcchack.h"
OLDNEW
« no previous file with comments | « third_party/libxml/src/win32/wince/wincecompat.c ('k') | third_party/libxml/src/xlink.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698