* xmlFetchXMLCatalogFile: * @catal: an existing but incomplete catalog entry * * Fetch and parse the subcatalog referenced by an entry * * Returns 0 in case of success, -1 otherwise */
| 1373 | * Returns 0 in case of success, -1 otherwise |
| 1374 | */ |
| 1375 | static int |
| 1376 | xmlFetchXMLCatalogFile(xmlCatalogEntryPtr catal) { |
| 1377 | xmlCatalogEntryPtr doc; |
| 1378 | |
| 1379 | if (catal == NULL) |
| 1380 | return(-1); |
| 1381 | if (catal->URL == NULL) |
| 1382 | return(-1); |
| 1383 | |
| 1384 | /* |
| 1385 | * lock the whole catalog for modification |
| 1386 | */ |
| 1387 | xmlRMutexLock(xmlCatalogMutex); |
| 1388 | if (catal->children != NULL) { |
| 1389 | /* Okay someone else did it in the meantime */ |
| 1390 | xmlRMutexUnlock(xmlCatalogMutex); |
| 1391 | return(0); |
| 1392 | } |
| 1393 | |
| 1394 | if (xmlCatalogXMLFiles != NULL) { |
| 1395 | doc = (xmlCatalogEntryPtr) |
| 1396 | xmlHashLookup(xmlCatalogXMLFiles, catal->URL); |
| 1397 | if (doc != NULL) { |
| 1398 | if (xmlDebugCatalogs) |
| 1399 | fprintf(stderr, |
| 1400 | "Found %s in file hash\n", catal->URL); |
| 1401 | |
| 1402 | if (catal->type == XML_CATA_CATALOG) |
| 1403 | catal->children = doc->children; |
| 1404 | else |
| 1405 | catal->children = doc; |
| 1406 | catal->dealloc = 0; |
| 1407 | xmlRMutexUnlock(xmlCatalogMutex); |
| 1408 | return(0); |
| 1409 | } |
| 1410 | if (xmlDebugCatalogs) |
| 1411 | fprintf(stderr, |
| 1412 | "%s not found in file hash\n", catal->URL); |
| 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * Fetch and parse. Note that xmlParseXMLCatalogFile does not |
| 1417 | * use the existing catalog, there is no recursion allowed at |
| 1418 | * that level. |
| 1419 | */ |
| 1420 | doc = xmlParseXMLCatalogFile(catal->prefer, catal->URL); |
| 1421 | if (doc == NULL) { |
| 1422 | catal->type = XML_CATA_BROKEN_CATALOG; |
| 1423 | xmlRMutexUnlock(xmlCatalogMutex); |
| 1424 | return(-1); |
| 1425 | } |
| 1426 | |
| 1427 | if (catal->type == XML_CATA_CATALOG) |
| 1428 | catal->children = doc->children; |
| 1429 | else |
| 1430 | catal->children = doc; |
| 1431 | |
| 1432 | doc->dealloc = 1; |
no test coverage detected