static void handleURI(const char *str) { int ret; xmlURIPtr uri; xmlChar *res = NULL, *parsed = NULL; uri = xmlCreateURI(); if (base == NULL) { ret = xmlParseURIReference(uri, str); if (ret != 0) printf("%s : error %d\n", str, ret); else { if (debug) { if (uri->scheme) printf("scheme: %s\n", uri->scheme); if (uri->opaque) printf("opaque: %s\n", uri->opaque); if (uri->authority) printf("authority: %s\n", uri->authority); if (uri->server) printf("server: %s\n", uri->server); if (uri->user) printf("user: %s\n", uri->user); if (uri->port != 0) printf("port: %d\n", uri->port); if (uri->path) printf("path: %s\n", uri->path); if (uri->query) printf("query: %s\n", uri->query); if (uri->fragment) printf("fragment: %s\n", uri->fragment); if (uri->query_raw) printf("query_raw: %s\n", uri->query_raw); if (uri->cleanup != 0) printf("cleanup\n"); } xmlNormalizeURIPath(uri->path); if (escape != 0) { parsed = xmlSaveUri(uri); res = xmlURIEscape(parsed); printf("%s\n", (char *) res); } else { xmlPrintURI(stdout, uri); printf("\n"); } } } else { res = xmlBuildURI((xmlChar *)str, (xmlChar *) base); if (res != NULL) { printf("%s\n", (char *) res); } else printf("::ERROR::\n"); } if (res != NULL) xmlFree(res); if (parsed != NULL) xmlFree(parsed); xmlFreeURI(uri); }
xmlChar * common_uri_escape (const xmlChar *url) { xmlChar *result; g_assert (NULL != url); /* xmlURIEscape returns NULL if spaces are in the URL, so we need to replace them first (see SF #2965158) */ result = common_strreplace (g_strdup (url), " ", "+"); result = xmlURIEscape (result); /* workaround if escaping somehow fails... */ if (!result) result = g_strdup (url); return result; }
/** * xmlXIncludeLoadNode: * @ctxt: an XInclude context * @nr: the node number * * Find and load the infoset replacement for the given node. * * Returns 0 if substitution succeeded, -1 if some processing failed */ static int xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) { xmlNodePtr cur; xmlChar *href; xmlChar *parse; xmlChar *base; xmlChar *URI; int xml = 1; /* default Issue 64 */ if (ctxt == NULL) return(-1); if ((nr < 0) || (nr >= ctxt->incNr)) return(-1); cur = ctxt->incTab[nr]; if (cur == NULL) return(-1); #ifdef DEBUG_XINCLUDE xmlDebugDumpNode(stdout, cur, 0); #endif /* * read the attributes */ href = xmlGetNsProp(cur, XINCLUDE_NS, XINCLUDE_HREF); if (href == NULL) { href = xmlGetProp(cur, XINCLUDE_HREF); if (href == NULL) { xmlGenericError(xmlGenericErrorContext, "XInclude: no href\n"); return(-1); } } parse = xmlGetNsProp(cur, XINCLUDE_NS, XINCLUDE_PARSE); if (parse == NULL) { parse = xmlGetProp(cur, XINCLUDE_PARSE); } if (parse != NULL) { if (xmlStrEqual(parse, XINCLUDE_PARSE_XML)) xml = 1; else if (xmlStrEqual(parse, XINCLUDE_PARSE_TEXT)) xml = 0; else { xmlGenericError(xmlGenericErrorContext, "XInclude: invalid value %s for %s\n", parse, XINCLUDE_PARSE); if (href != NULL) xmlFree(href); if (parse != NULL) xmlFree(parse); return(-1); } } /* * compute the URI */ base = xmlNodeGetBase(ctxt->doc, cur); if (base == NULL) { URI = xmlBuildURI(href, ctxt->doc->URL); } else { URI = xmlBuildURI(href, base); } if (URI == NULL) { xmlChar *escbase; xmlChar *eschref; /* * Some escaping may be needed */ escbase = xmlURIEscape(base); eschref = xmlURIEscape(href); URI = xmlBuildURI(eschref, escbase); if (escbase != NULL) xmlFree(escbase); if (eschref != NULL) xmlFree(eschref); } if (URI == NULL) { xmlGenericError(xmlGenericErrorContext, "XInclude: failed build URL\n"); if (parse != NULL) xmlFree(parse); if (href != NULL) xmlFree(href); if (base != NULL) xmlFree(base); return(-1); } #ifdef DEBUG_XINCLUDE xmlGenericError(xmlGenericErrorContext, "parse: %s\n", xml ? "xml": "text"); xmlGenericError(xmlGenericErrorContext, "URI: %s\n", URI); #endif /* * Cleanup */ if (xml) { xmlXIncludeLoadDoc(ctxt, URI, nr); /* xmlXIncludeGetFragment(ctxt, cur, URI); */ } else { xmlXIncludeLoadTxt(ctxt, URI, nr); } /* * Cleanup */ if (URI != NULL) xmlFree(URI); if (parse != NULL) xmlFree(parse); if (href != NULL) xmlFree(href); if (base != NULL) xmlFree(base); return(0); }