* xmlXIncludeLoadDoc: * @ctxt: the XInclude context * @url: the associated URL * @ref: an XMLXincludeRefPtr * * Load the document, and store the result in the XInclude context * * Returns 0 in case of success, -1 in case of failure */
| 1302 | * Returns 0 in case of success, -1 in case of failure |
| 1303 | */ |
| 1304 | static int |
| 1305 | xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, xmlXIncludeRefPtr ref) { |
| 1306 | xmlXIncludeDocPtr cache; |
| 1307 | xmlDocPtr doc; |
| 1308 | const xmlChar *url = ref->URI; |
| 1309 | const xmlChar *fragment = ref->fragment; |
| 1310 | int i = 0; |
| 1311 | int ret = -1; |
| 1312 | int cacheNr; |
| 1313 | #ifdef LIBXML_XPTR_ENABLED |
| 1314 | int saveFlags; |
| 1315 | #endif |
| 1316 | |
| 1317 | /* |
| 1318 | * Handling of references to the local document are done |
| 1319 | * directly through ctxt->doc. |
| 1320 | */ |
| 1321 | if ((url[0] == 0) || (url[0] == '#') || |
| 1322 | ((ctxt->doc != NULL) && (xmlStrEqual(url, ctxt->doc->URL)))) { |
| 1323 | doc = ctxt->doc; |
| 1324 | goto loaded; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
| 1328 | * Prevent reloading the document twice. |
| 1329 | */ |
| 1330 | for (i = 0; i < ctxt->urlNr; i++) { |
| 1331 | if (xmlStrEqual(url, ctxt->urlTab[i].url)) { |
| 1332 | if (ctxt->urlTab[i].expanding) { |
| 1333 | xmlXIncludeErr(ctxt, ref->elem, XML_XINCLUDE_RECURSION, |
| 1334 | "inclusion loop detected\n", NULL); |
| 1335 | goto error; |
| 1336 | } |
| 1337 | doc = ctxt->urlTab[i].doc; |
| 1338 | if (doc == NULL) |
| 1339 | goto error; |
| 1340 | goto loaded; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /* |
| 1345 | * Load it. |
| 1346 | */ |
| 1347 | #ifdef LIBXML_XPTR_ENABLED |
| 1348 | /* |
| 1349 | * If this is an XPointer evaluation, we want to assure that |
| 1350 | * all entities have been resolved prior to processing the |
| 1351 | * referenced document |
| 1352 | */ |
| 1353 | saveFlags = ctxt->parseFlags; |
| 1354 | if (fragment != NULL) { /* if this is an XPointer eval */ |
| 1355 | ctxt->parseFlags |= XML_PARSE_NOENT; |
| 1356 | } |
| 1357 | #endif |
| 1358 | |
| 1359 | doc = xmlXIncludeParseFile(ctxt, (const char *)url); |
| 1360 | #ifdef LIBXML_XPTR_ENABLED |
| 1361 | ctxt->parseFlags = saveFlags; |
no test coverage detected