| 613 | ************************************************************************/ |
| 614 | |
| 615 | static void |
| 616 | xmlXIncludeBaseFixup(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur, xmlNodePtr copy, |
| 617 | const xmlChar *targetBase) { |
| 618 | xmlChar *base = NULL; |
| 619 | xmlChar *relBase = NULL; |
| 620 | xmlNs ns; |
| 621 | int res; |
| 622 | |
| 623 | if (cur->type != XML_ELEMENT_NODE) |
| 624 | return; |
| 625 | |
| 626 | if (xmlNodeGetBaseSafe(cur->doc, cur, &base) < 0) |
| 627 | xmlXIncludeErrMemory(ctxt); |
| 628 | |
| 629 | if ((base != NULL) && !xmlStrEqual(base, targetBase)) { |
| 630 | if (xmlBuildRelativeURISafe(base, targetBase, &relBase) < 0) { |
| 631 | xmlXIncludeErrMemory(ctxt); |
| 632 | goto done; |
| 633 | } |
| 634 | if (relBase == NULL) { |
| 635 | xmlXIncludeErr(ctxt, cur, |
| 636 | XML_XINCLUDE_HREF_URI, |
| 637 | "Building relative URI failed: %s\n", |
| 638 | base); |
| 639 | goto done; |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * If the new base doesn't contain a slash, it can be omitted. |
| 644 | */ |
| 645 | if (xmlStrchr(relBase, '/') != NULL) { |
| 646 | res = xmlNodeSetBase(copy, relBase); |
| 647 | if (res < 0) |
| 648 | xmlXIncludeErrMemory(ctxt); |
| 649 | goto done; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | * Delete existing xml:base if bases are equal |
| 655 | */ |
| 656 | memset(&ns, 0, sizeof(ns)); |
| 657 | ns.href = XML_XML_NAMESPACE; |
| 658 | xmlUnsetNsProp(copy, &ns, BAD_CAST "base"); |
| 659 | |
| 660 | done: |
| 661 | xmlFree(base); |
| 662 | xmlFree(relBase); |
| 663 | } |
| 664 | |
| 665 | /** |
| 666 | * xmlXIncludeCopyNode: |
no test coverage detected