2 * catalog.c: set of generic Catalog related routines
4 * Reference: SGML Open Technical Resolution TR9401:1997.
5 * http://www.jclark.com/sp/catalog.htm
7 * XML Catalogs Working Draft 06 August 2001
8 * http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
10 * See Copyright for the status of this software.
12 * Daniel.Veillard@imag.fr
18 #ifdef LIBXML_CATALOG_ENABLED
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
22 #ifdef HAVE_SYS_STAT_H
35 #include <libxml/xmlmemory.h>
36 #include <libxml/hash.h>
37 #include <libxml/uri.h>
38 #include <libxml/parserInternals.h>
39 #include <libxml/catalog.h>
40 #include <libxml/xmlerror.h>
41 #include <libxml/threads.h>
42 #include <libxml/globals.h>
44 #define MAX_DELEGATE 50
45 #define MAX_CATAL_DEPTH 50
48 # define PATH_SEAPARATOR ';'
50 # define PATH_SEAPARATOR ':'
56 * macro to flag unimplemented blocks
57 * XML_CATALOG_PREFER user env to select between system/public prefered
58 * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk>
59 *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with
60 *> values "system" and "public". I have made the default be "system" to
64 xmlGenericError(xmlGenericErrorContext, \
65 "Unimplemented block at %s:%d\n", \
68 #define XML_URN_PUBID "urn:publicid:"
69 #define XML_CATAL_BREAK ((xmlChar *) -1)
70 #ifndef XML_XML_DEFAULT_CATALOG
71 #define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
73 #ifndef XML_SGML_DEFAULT_CATALOG
74 #define XML_SGML_DEFAULT_CATALOG "file:///etc/sgml/catalog"
77 #if defined(_WIN32) && defined(_MSC_VER)
78 #undef XML_XML_DEFAULT_CATALOG
79 static char XML_XML_DEFAULT_CATALOG[256] = "file:///etc/xml/catalog";
80 #if defined(_WIN32_WCE)
81 /* Windows CE don't have a A variant */
82 #define GetModuleHandleA GetModuleHandle
83 #define GetModuleFileNameA GetModuleFileName
85 void* __stdcall GetModuleHandleA(const char*);
86 unsigned long __stdcall GetModuleFileNameA(void*, char*, unsigned long);
90 static xmlChar *xmlCatalogNormalizePublic(const xmlChar *pubID);
91 static int xmlExpandCatalog(xmlCatalogPtr catal, const char *filename);
93 /************************************************************************
95 * Types, all private *
97 ************************************************************************/
100 XML_CATA_REMOVED = -1,
103 XML_CATA_BROKEN_CATALOG,
104 XML_CATA_NEXT_CATALOG,
108 XML_CATA_REWRITE_SYSTEM,
109 XML_CATA_DELEGATE_PUBLIC,
110 XML_CATA_DELEGATE_SYSTEM,
112 XML_CATA_REWRITE_URI,
113 XML_CATA_DELEGATE_URI,
126 } xmlCatalogEntryType;
128 typedef struct _xmlCatalogEntry xmlCatalogEntry;
129 typedef xmlCatalogEntry *xmlCatalogEntryPtr;
130 struct _xmlCatalogEntry {
131 struct _xmlCatalogEntry *next;
132 struct _xmlCatalogEntry *parent;
133 struct _xmlCatalogEntry *children;
134 xmlCatalogEntryType type;
137 xmlChar *URL; /* The expanded URL using the base */
138 xmlCatalogPrefer prefer;
141 struct _xmlCatalogEntry *group;
145 XML_XML_CATALOG_TYPE = 1,
146 XML_SGML_CATALOG_TYPE
149 #define XML_MAX_SGML_CATA_DEPTH 10
151 xmlCatalogType type; /* either XML or SGML */
154 * SGML Catalogs are stored as a simple hash table of catalog entries
155 * Catalog stack to check against overflows when building the
158 char *catalTab[XML_MAX_SGML_CATA_DEPTH]; /* stack of catals */
159 int catalNr; /* Number of current catal streams */
160 int catalMax; /* Max number of catal streams */
161 xmlHashTablePtr sgml;
164 * XML Catalogs are stored as a tree of Catalog entries
166 xmlCatalogPrefer prefer;
167 xmlCatalogEntryPtr xml;
170 /************************************************************************
174 ************************************************************************/
177 * Those are preferences
179 static int xmlDebugCatalogs = 0; /* used for debugging */
180 static xmlCatalogAllow xmlCatalogDefaultAllow = XML_CATA_ALLOW_ALL;
181 static xmlCatalogPrefer xmlCatalogDefaultPrefer = XML_CATA_PREFER_PUBLIC;
184 * Hash table containing all the trees of XML catalogs parsed by
187 static xmlHashTablePtr xmlCatalogXMLFiles = NULL;
190 * The default catalog in use by the application
192 static xmlCatalogPtr xmlDefaultCatalog = NULL;
195 * A mutex for modifying the shared global catalog(s)
196 * xmlDefaultCatalog tree.
197 * It also protects xmlCatalogXMLFiles
198 * The core of this readers/writer scheme is in xmlFetchXMLCatalogFile()
200 static xmlRMutexPtr xmlCatalogMutex = NULL;
203 * Whether the catalog support was initialized.
205 static int xmlCatalogInitialized = 0;
207 /************************************************************************
209 * Catalog error handlers *
211 ************************************************************************/
214 * xmlCatalogErrMemory:
215 * @extra: extra informations
217 * Handle an out of memory condition
220 xmlCatalogErrMemory(const char *extra)
222 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_CATALOG,
223 XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0,
224 extra, NULL, NULL, 0, 0,
225 "Memory allocation failed : %s\n", extra);
230 * @catal: the Catalog entry
231 * @node: the context node
232 * @msg: the error message
233 * @extra: extra informations
235 * Handle a catalog error
238 xmlCatalogErr(xmlCatalogEntryPtr catal, xmlNodePtr node, int error,
239 const char *msg, const xmlChar *str1, const xmlChar *str2,
242 __xmlRaiseError(NULL, NULL, NULL, catal, node, XML_FROM_CATALOG,
243 error, XML_ERR_ERROR, NULL, 0,
244 (const char *) str1, (const char *) str2,
245 (const char *) str3, 0, 0,
246 msg, str1, str2, str3);
250 /************************************************************************
252 * Allocation and Freeing *
254 ************************************************************************/
257 * xmlNewCatalogEntry:
258 * @type: type of entry
259 * @name: name of the entry
260 * @value: value of the entry
261 * @prefer: the PUBLIC vs. SYSTEM current preference value
262 * @group: for members of a group, the group entry
264 * create a new Catalog entry, this type is shared both by XML and
265 * SGML catalogs, but the acceptable types values differs.
267 * Returns the xmlCatalogEntryPtr or NULL in case of error
269 static xmlCatalogEntryPtr
270 xmlNewCatalogEntry(xmlCatalogEntryType type, const xmlChar *name,
271 const xmlChar *value, const xmlChar *URL, xmlCatalogPrefer prefer,
272 xmlCatalogEntryPtr group) {
273 xmlCatalogEntryPtr ret;
274 xmlChar *normid = NULL;
276 ret = (xmlCatalogEntryPtr) xmlMalloc(sizeof(xmlCatalogEntry));
278 xmlCatalogErrMemory("allocating catalog entry");
283 ret->children = NULL;
285 if (type == XML_CATA_PUBLIC || type == XML_CATA_DELEGATE_PUBLIC) {
286 normid = xmlCatalogNormalizePublic(name);
288 name = (*normid != 0 ? normid : NULL);
291 ret->name = xmlStrdup(name);
297 ret->value = xmlStrdup(value);
303 ret->URL = xmlStrdup(URL);
306 ret->prefer = prefer;
314 xmlFreeCatalogEntryList(xmlCatalogEntryPtr ret);
317 * xmlFreeCatalogEntry:
318 * @ret: a Catalog entry
320 * Free the memory allocated to a Catalog entry
323 xmlFreeCatalogEntry(xmlCatalogEntryPtr ret) {
327 * Entries stored in the file hash must be deallocated
328 * only by the file hash cleaner !
330 if (ret->dealloc == 1)
333 if (xmlDebugCatalogs) {
334 if (ret->name != NULL)
335 xmlGenericError(xmlGenericErrorContext,
336 "Free catalog entry %s\n", ret->name);
337 else if (ret->value != NULL)
338 xmlGenericError(xmlGenericErrorContext,
339 "Free catalog entry %s\n", ret->value);
341 xmlGenericError(xmlGenericErrorContext,
342 "Free catalog entry\n");
345 if (ret->name != NULL)
347 if (ret->value != NULL)
349 if (ret->URL != NULL)
355 * xmlFreeCatalogEntryList:
356 * @ret: a Catalog entry list
358 * Free the memory allocated to a full chained list of Catalog entries
361 xmlFreeCatalogEntryList(xmlCatalogEntryPtr ret) {
362 xmlCatalogEntryPtr next;
364 while (ret != NULL) {
366 xmlFreeCatalogEntry(ret);
372 * xmlFreeCatalogHashEntryList:
373 * @ret: a Catalog entry list
375 * Free the memory allocated to list of Catalog entries from the
379 xmlFreeCatalogHashEntryList(xmlCatalogEntryPtr catal) {
380 xmlCatalogEntryPtr children, next;
385 children = catal->children;
386 while (children != NULL) {
387 next = children->next;
388 children->dealloc = 0;
389 children->children = NULL;
390 xmlFreeCatalogEntry(children);
394 xmlFreeCatalogEntry(catal);
398 * xmlCreateNewCatalog:
399 * @type: type of catalog
400 * @prefer: the PUBLIC vs. SYSTEM current preference value
402 * create a new Catalog, this type is shared both by XML and
403 * SGML catalogs, but the acceptable types values differs.
405 * Returns the xmlCatalogPtr or NULL in case of error
408 xmlCreateNewCatalog(xmlCatalogType type, xmlCatalogPrefer prefer) {
411 ret = (xmlCatalogPtr) xmlMalloc(sizeof(xmlCatalog));
413 xmlCatalogErrMemory("allocating catalog");
416 memset(ret, 0, sizeof(xmlCatalog));
419 ret->catalMax = XML_MAX_SGML_CATA_DEPTH;
420 ret->prefer = prefer;
421 if (ret->type == XML_SGML_CATALOG_TYPE)
422 ret->sgml = xmlHashCreate(10);
430 * Free the memory allocated to a Catalog
433 xmlFreeCatalog(xmlCatalogPtr catal) {
436 if (catal->xml != NULL)
437 xmlFreeCatalogEntryList(catal->xml);
438 if (catal->sgml != NULL)
439 xmlHashFree(catal->sgml,
440 (xmlHashDeallocator) xmlFreeCatalogEntry);
444 /************************************************************************
446 * Serializing Catalogs *
448 ************************************************************************/
450 #ifdef LIBXML_OUTPUT_ENABLED
452 * xmlCatalogDumpEntry:
453 * @entry: the catalog entry
456 * Serialize an SGML Catalog entry
459 xmlCatalogDumpEntry(xmlCatalogEntryPtr entry, FILE *out) {
460 if ((entry == NULL) || (out == NULL))
462 switch (entry->type) {
463 case SGML_CATA_ENTITY:
464 fprintf(out, "ENTITY "); break;
465 case SGML_CATA_PENTITY:
466 fprintf(out, "ENTITY %%"); break;
467 case SGML_CATA_DOCTYPE:
468 fprintf(out, "DOCTYPE "); break;
469 case SGML_CATA_LINKTYPE:
470 fprintf(out, "LINKTYPE "); break;
471 case SGML_CATA_NOTATION:
472 fprintf(out, "NOTATION "); break;
473 case SGML_CATA_PUBLIC:
474 fprintf(out, "PUBLIC "); break;
475 case SGML_CATA_SYSTEM:
476 fprintf(out, "SYSTEM "); break;
477 case SGML_CATA_DELEGATE:
478 fprintf(out, "DELEGATE "); break;
480 fprintf(out, "BASE "); break;
481 case SGML_CATA_CATALOG:
482 fprintf(out, "CATALOG "); break;
483 case SGML_CATA_DOCUMENT:
484 fprintf(out, "DOCUMENT "); break;
485 case SGML_CATA_SGMLDECL:
486 fprintf(out, "SGMLDECL "); break;
490 switch (entry->type) {
491 case SGML_CATA_ENTITY:
492 case SGML_CATA_PENTITY:
493 case SGML_CATA_DOCTYPE:
494 case SGML_CATA_LINKTYPE:
495 case SGML_CATA_NOTATION:
496 fprintf(out, "%s", (const char *) entry->name); break;
497 case SGML_CATA_PUBLIC:
498 case SGML_CATA_SYSTEM:
499 case SGML_CATA_SGMLDECL:
500 case SGML_CATA_DOCUMENT:
501 case SGML_CATA_CATALOG:
503 case SGML_CATA_DELEGATE:
504 fprintf(out, "\"%s\"", entry->name); break;
508 switch (entry->type) {
509 case SGML_CATA_ENTITY:
510 case SGML_CATA_PENTITY:
511 case SGML_CATA_DOCTYPE:
512 case SGML_CATA_LINKTYPE:
513 case SGML_CATA_NOTATION:
514 case SGML_CATA_PUBLIC:
515 case SGML_CATA_SYSTEM:
516 case SGML_CATA_DELEGATE:
517 fprintf(out, " \"%s\"", entry->value); break;
525 * xmlDumpXMLCatalogNode:
526 * @catal: top catalog entry
527 * @catalog: pointer to the xml tree
528 * @doc: the containing document
529 * @ns: the current namespace
530 * @cgroup: group node for group members
532 * Serializes a Catalog entry, called by xmlDumpXMLCatalog and recursively
535 static void xmlDumpXMLCatalogNode(xmlCatalogEntryPtr catal, xmlNodePtr catalog,
536 xmlDocPtr doc, xmlNsPtr ns, xmlCatalogEntryPtr cgroup) {
538 xmlCatalogEntryPtr cur;
540 * add all the catalog entries
543 while (cur != NULL) {
544 if (cur->group == cgroup) {
546 case XML_CATA_REMOVED:
548 case XML_CATA_BROKEN_CATALOG:
549 case XML_CATA_CATALOG:
555 case XML_CATA_NEXT_CATALOG:
556 node = xmlNewDocNode(doc, ns, BAD_CAST "nextCatalog", NULL);
557 xmlSetProp(node, BAD_CAST "catalog", cur->value);
558 xmlAddChild(catalog, node);
563 node = xmlNewDocNode(doc, ns, BAD_CAST "group", NULL);
564 xmlSetProp(node, BAD_CAST "id", cur->name);
565 if (cur->value != NULL) {
567 xns = xmlSearchNsByHref(doc, node, XML_XML_NAMESPACE);
569 xmlSetNsProp(node, xns, BAD_CAST "base",
572 switch (cur->prefer) {
573 case XML_CATA_PREFER_NONE:
575 case XML_CATA_PREFER_PUBLIC:
576 xmlSetProp(node, BAD_CAST "prefer", BAD_CAST "public");
578 case XML_CATA_PREFER_SYSTEM:
579 xmlSetProp(node, BAD_CAST "prefer", BAD_CAST "system");
582 xmlDumpXMLCatalogNode(cur->next, node, doc, ns, cur);
583 xmlAddChild(catalog, node);
585 case XML_CATA_PUBLIC:
586 node = xmlNewDocNode(doc, ns, BAD_CAST "public", NULL);
587 xmlSetProp(node, BAD_CAST "publicId", cur->name);
588 xmlSetProp(node, BAD_CAST "uri", cur->value);
589 xmlAddChild(catalog, node);
591 case XML_CATA_SYSTEM:
592 node = xmlNewDocNode(doc, ns, BAD_CAST "system", NULL);
593 xmlSetProp(node, BAD_CAST "systemId", cur->name);
594 xmlSetProp(node, BAD_CAST "uri", cur->value);
595 xmlAddChild(catalog, node);
597 case XML_CATA_REWRITE_SYSTEM:
598 node = xmlNewDocNode(doc, ns, BAD_CAST "rewriteSystem", NULL);
599 xmlSetProp(node, BAD_CAST "systemIdStartString", cur->name);
600 xmlSetProp(node, BAD_CAST "rewritePrefix", cur->value);
601 xmlAddChild(catalog, node);
603 case XML_CATA_DELEGATE_PUBLIC:
604 node = xmlNewDocNode(doc, ns, BAD_CAST "delegatePublic", NULL);
605 xmlSetProp(node, BAD_CAST "publicIdStartString", cur->name);
606 xmlSetProp(node, BAD_CAST "catalog", cur->value);
607 xmlAddChild(catalog, node);
609 case XML_CATA_DELEGATE_SYSTEM:
610 node = xmlNewDocNode(doc, ns, BAD_CAST "delegateSystem", NULL);
611 xmlSetProp(node, BAD_CAST "systemIdStartString", cur->name);
612 xmlSetProp(node, BAD_CAST "catalog", cur->value);
613 xmlAddChild(catalog, node);
616 node = xmlNewDocNode(doc, ns, BAD_CAST "uri", NULL);
617 xmlSetProp(node, BAD_CAST "name", cur->name);
618 xmlSetProp(node, BAD_CAST "uri", cur->value);
619 xmlAddChild(catalog, node);
621 case XML_CATA_REWRITE_URI:
622 node = xmlNewDocNode(doc, ns, BAD_CAST "rewriteURI", NULL);
623 xmlSetProp(node, BAD_CAST "uriStartString", cur->name);
624 xmlSetProp(node, BAD_CAST "rewritePrefix", cur->value);
625 xmlAddChild(catalog, node);
627 case XML_CATA_DELEGATE_URI:
628 node = xmlNewDocNode(doc, ns, BAD_CAST "delegateURI", NULL);
629 xmlSetProp(node, BAD_CAST "uriStartString", cur->name);
630 xmlSetProp(node, BAD_CAST "catalog", cur->value);
631 xmlAddChild(catalog, node);
633 case SGML_CATA_SYSTEM:
634 case SGML_CATA_PUBLIC:
635 case SGML_CATA_ENTITY:
636 case SGML_CATA_PENTITY:
637 case SGML_CATA_DOCTYPE:
638 case SGML_CATA_LINKTYPE:
639 case SGML_CATA_NOTATION:
640 case SGML_CATA_DELEGATE:
642 case SGML_CATA_CATALOG:
643 case SGML_CATA_DOCUMENT:
644 case SGML_CATA_SGMLDECL:
653 xmlDumpXMLCatalog(FILE *out, xmlCatalogEntryPtr catal) {
659 xmlOutputBufferPtr buf;
664 doc = xmlNewDoc(NULL);
667 dtd = xmlNewDtd(doc, BAD_CAST "catalog",
668 BAD_CAST "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN",
669 BAD_CAST "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd");
671 xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);
673 ns = xmlNewNs(NULL, XML_CATALOGS_NAMESPACE, NULL);
678 catalog = xmlNewDocNode(doc, ns, BAD_CAST "catalog", NULL);
679 if (catalog == NULL) {
685 xmlAddChild((xmlNodePtr) doc, catalog);
687 xmlDumpXMLCatalogNode(catal, catalog, doc, ns, NULL);
692 buf = xmlOutputBufferCreateFile(out, NULL);
697 ret = xmlSaveFormatFileTo(buf, doc, NULL, 1);
706 #endif /* LIBXML_OUTPUT_ENABLED */
708 /************************************************************************
710 * Converting SGML Catalogs to XML *
712 ************************************************************************/
715 * xmlCatalogConvertEntry:
717 * @catal: pointer to the catalog being converted
719 * Convert one entry from the catalog
722 xmlCatalogConvertEntry(xmlCatalogEntryPtr entry, xmlCatalogPtr catal) {
723 if ((entry == NULL) || (catal == NULL) || (catal->sgml == NULL) ||
724 (catal->xml == NULL))
726 switch (entry->type) {
727 case SGML_CATA_ENTITY:
728 entry->type = XML_CATA_PUBLIC;
730 case SGML_CATA_PENTITY:
731 entry->type = XML_CATA_PUBLIC;
733 case SGML_CATA_DOCTYPE:
734 entry->type = XML_CATA_PUBLIC;
736 case SGML_CATA_LINKTYPE:
737 entry->type = XML_CATA_PUBLIC;
739 case SGML_CATA_NOTATION:
740 entry->type = XML_CATA_PUBLIC;
742 case SGML_CATA_PUBLIC:
743 entry->type = XML_CATA_PUBLIC;
745 case SGML_CATA_SYSTEM:
746 entry->type = XML_CATA_SYSTEM;
748 case SGML_CATA_DELEGATE:
749 entry->type = XML_CATA_DELEGATE_PUBLIC;
751 case SGML_CATA_CATALOG:
752 entry->type = XML_CATA_CATALOG;
755 xmlHashRemoveEntry(catal->sgml, entry->name,
756 (xmlHashDeallocator) xmlFreeCatalogEntry);
760 * Conversion successful, remove from the SGML catalog
761 * and add it to the default XML one
763 xmlHashRemoveEntry(catal->sgml, entry->name, NULL);
764 entry->parent = catal->xml;
766 if (catal->xml->children == NULL)
767 catal->xml->children = entry;
769 xmlCatalogEntryPtr prev;
771 prev = catal->xml->children;
772 while (prev->next != NULL)
779 * xmlConvertSGMLCatalog:
780 * @catal: the catalog
782 * Convert all the SGML catalog entries as XML ones
784 * Returns the number of entries converted if successful, -1 otherwise
787 xmlConvertSGMLCatalog(xmlCatalogPtr catal) {
789 if ((catal == NULL) || (catal->type != XML_SGML_CATALOG_TYPE))
792 if (xmlDebugCatalogs) {
793 xmlGenericError(xmlGenericErrorContext,
794 "Converting SGML catalog to XML\n");
796 xmlHashScan(catal->sgml,
797 (xmlHashScanner) xmlCatalogConvertEntry,
802 /************************************************************************
806 ************************************************************************/
809 * xmlCatalogUnWrapURN:
810 * @urn: an "urn:publicid:" to unwrap
812 * Expand the URN into the equivalent Public Identifier
814 * Returns the new identifier or NULL, the string must be deallocated
818 xmlCatalogUnWrapURN(const xmlChar *urn) {
819 xmlChar result[2000];
822 if (xmlStrncmp(urn, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1))
824 urn += sizeof(XML_URN_PUBID) - 1;
827 if (i > sizeof(result) - 4)
832 } else if (*urn == ':') {
836 } else if (*urn == ';') {
840 } else if (*urn == '%') {
841 if ((urn[1] == '2') && (urn[2] == 'B'))
843 else if ((urn[1] == '3') && (urn[2] == 'A'))
845 else if ((urn[1] == '2') && (urn[2] == 'F'))
847 else if ((urn[1] == '3') && (urn[2] == 'B'))
849 else if ((urn[1] == '2') && (urn[2] == '7'))
851 else if ((urn[1] == '3') && (urn[2] == 'F'))
853 else if ((urn[1] == '2') && (urn[2] == '3'))
855 else if ((urn[1] == '2') && (urn[2] == '5'))
870 return(xmlStrdup(result));
874 * xmlParseCatalogFile:
875 * @filename: the filename
877 * parse an XML file and build a tree. It's like xmlParseFile()
878 * except it bypass all catalog lookups.
880 * Returns the resulting document tree or NULL in case of error
884 xmlParseCatalogFile(const char *filename) {
886 xmlParserCtxtPtr ctxt;
887 char *directory = NULL;
888 xmlParserInputPtr inputStream;
889 xmlParserInputBufferPtr buf;
891 ctxt = xmlNewParserCtxt();
893 #ifdef LIBXML_SAX1_ENABLED
894 if (xmlDefaultSAXHandler.error != NULL) {
895 xmlDefaultSAXHandler.error(NULL, "out of memory\n");
901 buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
903 xmlFreeParserCtxt(ctxt);
907 inputStream = xmlNewInputStream(ctxt);
908 if (inputStream == NULL) {
909 xmlFreeParserCtxt(ctxt);
913 inputStream->filename = (char *) xmlCanonicPath((const xmlChar *)filename);
914 inputStream->buf = buf;
915 inputStream->base = inputStream->buf->buffer->content;
916 inputStream->cur = inputStream->buf->buffer->content;
918 &inputStream->buf->buffer->content[inputStream->buf->buffer->use];
920 inputPush(ctxt, inputStream);
921 if ((ctxt->directory == NULL) && (directory == NULL))
922 directory = xmlParserGetDirectory(filename);
923 if ((ctxt->directory == NULL) && (directory != NULL))
924 ctxt->directory = directory;
927 ctxt->loadsubset = 0;
931 xmlParseDocument(ctxt);
933 if (ctxt->wellFormed)
937 xmlFreeDoc(ctxt->myDoc);
940 xmlFreeParserCtxt(ctxt);
946 * xmlLoadFileContent:
947 * @filename: a file path
949 * Load a file content into memory.
951 * Returns a pointer to the 0 terminated string or NULL in case of error
954 xmlLoadFileContent(const char *filename)
969 if (filename == NULL)
973 if (stat(filename, &info) < 0)
978 if ((fd = open(filename, O_RDONLY)) < 0)
980 if ((fd = fopen(filename, "rb")) == NULL)
988 if (fseek(fd, 0, SEEK_END) || (size = ftell(fd)) == EOF || fseek(fd, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
993 content = xmlMallocAtomic(size + 10);
994 if (content == NULL) {
995 xmlCatalogErrMemory("allocating catalog data");
999 len = read(fd, content, size);
1002 len = fread(content, 1, size, fd);
1015 * xmlCatalogNormalizePublic:
1016 * @pubID: the public ID string
1018 * Normalizes the Public Identifier
1020 * Implements 6.2. Public Identifier Normalization
1021 * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
1023 * Returns the new string or NULL, the string must be deallocated
1027 xmlCatalogNormalizePublic(const xmlChar *pubID)
1039 for (p = pubID;*p != 0 && ok;p++) {
1040 if (!xmlIsBlank_ch(*p))
1042 else if (*p == 0x20 && !white)
1047 if (ok && !white) /* is normalized */
1050 ret = xmlStrdup(pubID);
1053 for (p = pubID;*p != 0;p++) {
1054 if (xmlIsBlank_ch(*p)) {
1069 /************************************************************************
1071 * The XML Catalog parser *
1073 ************************************************************************/
1075 static xmlCatalogEntryPtr
1076 xmlParseXMLCatalogFile(xmlCatalogPrefer prefer, const xmlChar *filename);
1078 xmlParseXMLCatalogNodeList(xmlNodePtr cur, xmlCatalogPrefer prefer,
1079 xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup);
1081 xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
1082 const xmlChar *sysID);
1084 xmlCatalogListXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI);
1088 * xmlGetXMLCatalogEntryType:
1091 * lookup the internal type associated to an XML catalog entry name
1093 * Returns the type associated with that name
1095 static xmlCatalogEntryType
1096 xmlGetXMLCatalogEntryType(const xmlChar *name) {
1097 xmlCatalogEntryType type = XML_CATA_NONE;
1098 if (xmlStrEqual(name, (const xmlChar *) "system"))
1099 type = XML_CATA_SYSTEM;
1100 else if (xmlStrEqual(name, (const xmlChar *) "public"))
1101 type = XML_CATA_PUBLIC;
1102 else if (xmlStrEqual(name, (const xmlChar *) "rewriteSystem"))
1103 type = XML_CATA_REWRITE_SYSTEM;
1104 else if (xmlStrEqual(name, (const xmlChar *) "delegatePublic"))
1105 type = XML_CATA_DELEGATE_PUBLIC;
1106 else if (xmlStrEqual(name, (const xmlChar *) "delegateSystem"))
1107 type = XML_CATA_DELEGATE_SYSTEM;
1108 else if (xmlStrEqual(name, (const xmlChar *) "uri"))
1109 type = XML_CATA_URI;
1110 else if (xmlStrEqual(name, (const xmlChar *) "rewriteURI"))
1111 type = XML_CATA_REWRITE_URI;
1112 else if (xmlStrEqual(name, (const xmlChar *) "delegateURI"))
1113 type = XML_CATA_DELEGATE_URI;
1114 else if (xmlStrEqual(name, (const xmlChar *) "nextCatalog"))
1115 type = XML_CATA_NEXT_CATALOG;
1116 else if (xmlStrEqual(name, (const xmlChar *) "catalog"))
1117 type = XML_CATA_CATALOG;
1122 * xmlParseXMLCatalogOneNode:
1123 * @cur: the XML node
1124 * @type: the type of Catalog entry
1125 * @name: the name of the node
1126 * @attrName: the attribute holding the value
1127 * @uriAttrName: the attribute holding the URI-Reference
1128 * @prefer: the PUBLIC vs. SYSTEM current preference value
1129 * @cgroup: the group which includes this node
1131 * Finishes the examination of an XML tree node of a catalog and build
1132 * a Catalog entry from it.
1134 * Returns the new Catalog entry node or NULL in case of error.
1136 static xmlCatalogEntryPtr
1137 xmlParseXMLCatalogOneNode(xmlNodePtr cur, xmlCatalogEntryType type,
1138 const xmlChar *name, const xmlChar *attrName,
1139 const xmlChar *uriAttrName, xmlCatalogPrefer prefer,
1140 xmlCatalogEntryPtr cgroup) {
1143 xmlChar *nameValue = NULL;
1144 xmlChar *base = NULL;
1145 xmlChar *URL = NULL;
1146 xmlCatalogEntryPtr ret = NULL;
1148 if (attrName != NULL) {
1149 nameValue = xmlGetProp(cur, attrName);
1150 if (nameValue == NULL) {
1151 xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR,
1152 "%s entry lacks '%s'\n", name, attrName, NULL);
1156 uriValue = xmlGetProp(cur, uriAttrName);
1157 if (uriValue == NULL) {
1158 xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR,
1159 "%s entry lacks '%s'\n", name, uriAttrName, NULL);
1163 if (nameValue != NULL)
1165 if (uriValue != NULL)
1170 base = xmlNodeGetBase(cur->doc, cur);
1171 URL = xmlBuildURI(uriValue, base);
1173 if (xmlDebugCatalogs > 1) {
1174 if (nameValue != NULL)
1175 xmlGenericError(xmlGenericErrorContext,
1176 "Found %s: '%s' '%s'\n", name, nameValue, URL);
1178 xmlGenericError(xmlGenericErrorContext,
1179 "Found %s: '%s'\n", name, URL);
1181 ret = xmlNewCatalogEntry(type, nameValue, uriValue, URL, prefer, cgroup);
1183 xmlCatalogErr(ret, cur, XML_CATALOG_ENTRY_BROKEN,
1184 "%s entry '%s' broken ?: %s\n", name, uriAttrName, uriValue);
1186 if (nameValue != NULL)
1188 if (uriValue != NULL)
1198 * xmlParseXMLCatalogNode:
1199 * @cur: the XML node
1200 * @prefer: the PUBLIC vs. SYSTEM current preference value
1201 * @parent: the parent Catalog entry
1202 * @cgroup: the group which includes this node
1204 * Examines an XML tree node of a catalog and build
1205 * a Catalog entry from it adding it to its parent. The examination can
1209 xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer,
1210 xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup)
1212 xmlChar *base = NULL;
1213 xmlCatalogEntryPtr entry = NULL;
1217 if (xmlStrEqual(cur->name, BAD_CAST "group")) {
1219 xmlCatalogPrefer pref = XML_CATA_PREFER_NONE;
1221 prop = xmlGetProp(cur, BAD_CAST "prefer");
1223 if (xmlStrEqual(prop, BAD_CAST "system")) {
1224 prefer = XML_CATA_PREFER_SYSTEM;
1225 } else if (xmlStrEqual(prop, BAD_CAST "public")) {
1226 prefer = XML_CATA_PREFER_PUBLIC;
1228 xmlCatalogErr(parent, cur, XML_CATALOG_PREFER_VALUE,
1229 "Invalid value for prefer: '%s'\n",
1235 prop = xmlGetProp(cur, BAD_CAST "id");
1236 base = xmlGetNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE);
1237 entry = xmlNewCatalogEntry(XML_CATA_GROUP, prop, base, NULL, pref, cgroup);
1239 } else if (xmlStrEqual(cur->name, BAD_CAST "public")) {
1240 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_PUBLIC,
1241 BAD_CAST "public", BAD_CAST "publicId", BAD_CAST "uri", prefer, cgroup);
1242 } else if (xmlStrEqual(cur->name, BAD_CAST "system")) {
1243 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_SYSTEM,
1244 BAD_CAST "system", BAD_CAST "systemId", BAD_CAST "uri", prefer, cgroup);
1245 } else if (xmlStrEqual(cur->name, BAD_CAST "rewriteSystem")) {
1246 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_REWRITE_SYSTEM,
1247 BAD_CAST "rewriteSystem", BAD_CAST "systemIdStartString",
1248 BAD_CAST "rewritePrefix", prefer, cgroup);
1249 } else if (xmlStrEqual(cur->name, BAD_CAST "delegatePublic")) {
1250 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_DELEGATE_PUBLIC,
1251 BAD_CAST "delegatePublic", BAD_CAST "publicIdStartString",
1252 BAD_CAST "catalog", prefer, cgroup);
1253 } else if (xmlStrEqual(cur->name, BAD_CAST "delegateSystem")) {
1254 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_DELEGATE_SYSTEM,
1255 BAD_CAST "delegateSystem", BAD_CAST "systemIdStartString",
1256 BAD_CAST "catalog", prefer, cgroup);
1257 } else if (xmlStrEqual(cur->name, BAD_CAST "uri")) {
1258 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_URI,
1259 BAD_CAST "uri", BAD_CAST "name",
1260 BAD_CAST "uri", prefer, cgroup);
1261 } else if (xmlStrEqual(cur->name, BAD_CAST "rewriteURI")) {
1262 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_REWRITE_URI,
1263 BAD_CAST "rewriteURI", BAD_CAST "uriStartString",
1264 BAD_CAST "rewritePrefix", prefer, cgroup);
1265 } else if (xmlStrEqual(cur->name, BAD_CAST "delegateURI")) {
1266 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_DELEGATE_URI,
1267 BAD_CAST "delegateURI", BAD_CAST "uriStartString",
1268 BAD_CAST "catalog", prefer, cgroup);
1269 } else if (xmlStrEqual(cur->name, BAD_CAST "nextCatalog")) {
1270 entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_NEXT_CATALOG,
1271 BAD_CAST "nextCatalog", NULL,
1272 BAD_CAST "catalog", prefer, cgroup);
1274 if (entry != NULL) {
1275 if (parent != NULL) {
1276 entry->parent = parent;
1277 if (parent->children == NULL)
1278 parent->children = entry;
1280 xmlCatalogEntryPtr prev;
1282 prev = parent->children;
1283 while (prev->next != NULL)
1288 if (entry->type == XML_CATA_GROUP) {
1290 * Recurse to propagate prefer to the subtree
1291 * (xml:base handling is automated)
1293 xmlParseXMLCatalogNodeList(cur->children, prefer, parent, entry);
1301 * xmlParseXMLCatalogNodeList:
1302 * @cur: the XML node list of siblings
1303 * @prefer: the PUBLIC vs. SYSTEM current preference value
1304 * @parent: the parent Catalog entry
1305 * @cgroup: the group which includes this list
1307 * Examines a list of XML sibling nodes of a catalog and build
1308 * a list of Catalog entry from it adding it to the parent.
1309 * The examination will recurse to examine node subtrees.
1312 xmlParseXMLCatalogNodeList(xmlNodePtr cur, xmlCatalogPrefer prefer,
1313 xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup) {
1314 while (cur != NULL) {
1315 if ((cur->ns != NULL) && (cur->ns->href != NULL) &&
1316 (xmlStrEqual(cur->ns->href, XML_CATALOGS_NAMESPACE))) {
1317 xmlParseXMLCatalogNode(cur, prefer, parent, cgroup);
1321 /* TODO: sort the list according to REWRITE lengths and prefer value */
1325 * xmlParseXMLCatalogFile:
1326 * @prefer: the PUBLIC vs. SYSTEM current preference value
1327 * @filename: the filename for the catalog
1329 * Parses the catalog file to extract the XML tree and then analyze the
1330 * tree to build a list of Catalog entries corresponding to this catalog
1332 * Returns the resulting Catalog entries list
1334 static xmlCatalogEntryPtr
1335 xmlParseXMLCatalogFile(xmlCatalogPrefer prefer, const xmlChar *filename) {
1339 xmlCatalogEntryPtr parent = NULL;
1341 if (filename == NULL)
1344 doc = xmlParseCatalogFile((const char *) filename);
1346 if (xmlDebugCatalogs)
1347 xmlGenericError(xmlGenericErrorContext,
1348 "Failed to parse catalog %s\n", filename);
1352 if (xmlDebugCatalogs)
1353 xmlGenericError(xmlGenericErrorContext,
1354 "%d Parsing catalog %s\n", xmlGetThreadId(), filename);
1356 cur = xmlDocGetRootElement(doc);
1357 if ((cur != NULL) && (xmlStrEqual(cur->name, BAD_CAST "catalog")) &&
1358 (cur->ns != NULL) && (cur->ns->href != NULL) &&
1359 (xmlStrEqual(cur->ns->href, XML_CATALOGS_NAMESPACE))) {
1361 parent = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
1362 (const xmlChar *)filename, NULL, prefer, NULL);
1363 if (parent == NULL) {
1368 prop = xmlGetProp(cur, BAD_CAST "prefer");
1370 if (xmlStrEqual(prop, BAD_CAST "system")) {
1371 prefer = XML_CATA_PREFER_SYSTEM;
1372 } else if (xmlStrEqual(prop, BAD_CAST "public")) {
1373 prefer = XML_CATA_PREFER_PUBLIC;
1375 xmlCatalogErr(NULL, cur, XML_CATALOG_PREFER_VALUE,
1376 "Invalid value for prefer: '%s'\n",
1381 cur = cur->children;
1382 xmlParseXMLCatalogNodeList(cur, prefer, parent, NULL);
1384 xmlCatalogErr(NULL, (xmlNodePtr) doc, XML_CATALOG_NOT_CATALOG,
1385 "File %s is not an XML Catalog\n",
1386 filename, NULL, NULL);
1395 * xmlFetchXMLCatalogFile:
1396 * @catal: an existing but incomplete catalog entry
1398 * Fetch and parse the subcatalog referenced by an entry
1400 * Returns 0 in case of success, -1 otherwise
1403 xmlFetchXMLCatalogFile(xmlCatalogEntryPtr catal) {
1404 xmlCatalogEntryPtr doc;
1408 if (catal->URL == NULL)
1410 if (catal->children != NULL)
1414 * lock the whole catalog for modification
1416 xmlRMutexLock(xmlCatalogMutex);
1417 if (catal->children != NULL) {
1418 /* Okay someone else did it in the meantime */
1419 xmlRMutexUnlock(xmlCatalogMutex);
1423 if (xmlCatalogXMLFiles != NULL) {
1424 doc = (xmlCatalogEntryPtr)
1425 xmlHashLookup(xmlCatalogXMLFiles, catal->URL);
1427 if (xmlDebugCatalogs)
1428 xmlGenericError(xmlGenericErrorContext,
1429 "Found %s in file hash\n", catal->URL);
1431 if (catal->type == XML_CATA_CATALOG)
1432 catal->children = doc->children;
1434 catal->children = doc;
1436 xmlRMutexUnlock(xmlCatalogMutex);
1439 if (xmlDebugCatalogs)
1440 xmlGenericError(xmlGenericErrorContext,
1441 "%s not found in file hash\n", catal->URL);
1445 * Fetch and parse. Note that xmlParseXMLCatalogFile does not
1446 * use the existing catalog, there is no recursion allowed at
1449 doc = xmlParseXMLCatalogFile(catal->prefer, catal->URL);
1451 catal->type = XML_CATA_BROKEN_CATALOG;
1452 xmlRMutexUnlock(xmlCatalogMutex);
1456 if (catal->type == XML_CATA_CATALOG)
1457 catal->children = doc->children;
1459 catal->children = doc;
1463 if (xmlCatalogXMLFiles == NULL)
1464 xmlCatalogXMLFiles = xmlHashCreate(10);
1465 if (xmlCatalogXMLFiles != NULL) {
1466 if (xmlDebugCatalogs)
1467 xmlGenericError(xmlGenericErrorContext,
1468 "%s added to file hash\n", catal->URL);
1469 xmlHashAddEntry(xmlCatalogXMLFiles, catal->URL, doc);
1471 xmlRMutexUnlock(xmlCatalogMutex);
1475 /************************************************************************
1477 * XML Catalog handling *
1479 ************************************************************************/
1483 * @catal: top of an XML catalog
1484 * @type: the type of record to add to the catalog
1485 * @orig: the system, public or prefix to match (or NULL)
1486 * @replace: the replacement value for the match
1488 * Add an entry in the XML catalog, it may overwrite existing but
1489 * different entries.
1491 * Returns 0 if successful, -1 otherwise
1494 xmlAddXMLCatalog(xmlCatalogEntryPtr catal, const xmlChar *type,
1495 const xmlChar *orig, const xmlChar *replace) {
1496 xmlCatalogEntryPtr cur;
1497 xmlCatalogEntryType typ;
1500 if ((catal == NULL) ||
1501 ((catal->type != XML_CATA_CATALOG) &&
1502 (catal->type != XML_CATA_BROKEN_CATALOG)))
1504 if (catal->children == NULL) {
1505 xmlFetchXMLCatalogFile(catal);
1507 if (catal->children == NULL)
1510 typ = xmlGetXMLCatalogEntryType(type);
1511 if (typ == XML_CATA_NONE) {
1512 if (xmlDebugCatalogs)
1513 xmlGenericError(xmlGenericErrorContext,
1514 "Failed to add unknown element %s to catalog\n", type);
1518 cur = catal->children;
1520 * Might be a simple "update in place"
1523 while (cur != NULL) {
1524 if ((orig != NULL) && (cur->type == typ) &&
1525 (xmlStrEqual(orig, cur->name))) {
1526 if (xmlDebugCatalogs)
1527 xmlGenericError(xmlGenericErrorContext,
1528 "Updating element %s to catalog\n", type);
1529 if (cur->value != NULL)
1530 xmlFree(cur->value);
1531 if (cur->URL != NULL)
1533 cur->value = xmlStrdup(replace);
1534 cur->URL = xmlStrdup(replace);
1537 if (cur->next == NULL)
1542 if (xmlDebugCatalogs)
1543 xmlGenericError(xmlGenericErrorContext,
1544 "Adding element %s to catalog\n", type);
1546 catal->children = xmlNewCatalogEntry(typ, orig, replace,
1547 NULL, catal->prefer, NULL);
1549 cur->next = xmlNewCatalogEntry(typ, orig, replace,
1550 NULL, catal->prefer, NULL);
1552 catal->type = XML_CATA_CATALOG;
1553 cur = xmlHashLookup(xmlCatalogXMLFiles, catal->URL);
1555 cur->children = catal->children;
1563 * @catal: top of an XML catalog
1564 * @value: the value to remove from the catalog
1566 * Remove entries in the XML catalog where the value or the URI
1567 * is equal to @value
1569 * Returns the number of entries removed if successful, -1 otherwise
1572 xmlDelXMLCatalog(xmlCatalogEntryPtr catal, const xmlChar *value) {
1573 xmlCatalogEntryPtr cur;
1576 if ((catal == NULL) ||
1577 ((catal->type != XML_CATA_CATALOG) &&
1578 (catal->type != XML_CATA_BROKEN_CATALOG)))
1582 if (catal->children == NULL) {
1583 xmlFetchXMLCatalogFile(catal);
1589 cur = catal->children;
1590 while (cur != NULL) {
1591 if (((cur->name != NULL) && (xmlStrEqual(value, cur->name))) ||
1592 (xmlStrEqual(value, cur->value))) {
1593 if (xmlDebugCatalogs) {
1594 if (cur->name != NULL)
1595 xmlGenericError(xmlGenericErrorContext,
1596 "Removing element %s from catalog\n", cur->name);
1598 xmlGenericError(xmlGenericErrorContext,
1599 "Removing element %s from catalog\n", cur->value);
1601 cur->type = XML_CATA_REMOVED;
1609 * xmlCatalogXMLResolve:
1610 * @catal: a catalog list
1611 * @pubID: the public ID string
1612 * @sysID: the system ID string
1614 * Do a complete resolution lookup of an External Identifier for a
1615 * list of catalog entries.
1617 * Implements (or tries to) 7.1. External Identifier Resolution
1618 * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
1620 * Returns the URI of the resource or NULL if not found
1623 xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
1624 const xmlChar *sysID) {
1625 xmlChar *ret = NULL;
1626 xmlCatalogEntryPtr cur;
1627 int haveDelegate = 0;
1631 * protection against loops
1633 if (catal->depth > MAX_CATAL_DEPTH) {
1634 xmlCatalogErr(catal, NULL, XML_CATALOG_RECURSION,
1635 "Detected recursion in catalog %s\n",
1636 catal->name, NULL, NULL);
1642 * First tries steps 2/ 3/ 4/ if a system ID is provided.
1644 if (sysID != NULL) {
1645 xmlCatalogEntryPtr rewrite = NULL;
1646 int lenrewrite = 0, len;
1649 while (cur != NULL) {
1650 switch (cur->type) {
1651 case XML_CATA_SYSTEM:
1652 if (xmlStrEqual(sysID, cur->name)) {
1653 if (xmlDebugCatalogs)
1654 xmlGenericError(xmlGenericErrorContext,
1655 "Found system match %s, using %s\n",
1656 cur->name, cur->URL);
1658 return(xmlStrdup(cur->URL));
1661 case XML_CATA_REWRITE_SYSTEM:
1662 len = xmlStrlen(cur->name);
1663 if ((len > lenrewrite) &&
1664 (!xmlStrncmp(sysID, cur->name, len))) {
1669 case XML_CATA_DELEGATE_SYSTEM:
1670 if (!xmlStrncmp(sysID, cur->name, xmlStrlen(cur->name)))
1673 case XML_CATA_NEXT_CATALOG:
1681 if (rewrite != NULL) {
1682 if (xmlDebugCatalogs)
1683 xmlGenericError(xmlGenericErrorContext,
1684 "Using rewriting rule %s\n", rewrite->name);
1685 ret = xmlStrdup(rewrite->URL);
1687 ret = xmlStrcat(ret, &sysID[lenrewrite]);
1692 const xmlChar *delegates[MAX_DELEGATE];
1696 * Assume the entries have been sorted by decreasing substring
1697 * matches when the list was produced.
1700 while (cur != NULL) {
1701 if ((cur->type == XML_CATA_DELEGATE_SYSTEM) &&
1702 (!xmlStrncmp(sysID, cur->name, xmlStrlen(cur->name)))) {
1703 for (i = 0;i < nbList;i++)
1704 if (xmlStrEqual(cur->URL, delegates[i]))
1710 if (nbList < MAX_DELEGATE)
1711 delegates[nbList++] = cur->URL;
1713 if (cur->children == NULL) {
1714 xmlFetchXMLCatalogFile(cur);
1716 if (cur->children != NULL) {
1717 if (xmlDebugCatalogs)
1718 xmlGenericError(xmlGenericErrorContext,
1719 "Trying system delegate %s\n", cur->URL);
1720 ret = xmlCatalogListXMLResolve(
1721 cur->children, NULL, sysID);
1731 * Apply the cut algorithm explained in 4/
1734 return(XML_CATAL_BREAK);
1738 * Then tries 5/ 6/ if a public ID is provided
1740 if (pubID != NULL) {
1743 while (cur != NULL) {
1744 switch (cur->type) {
1745 case XML_CATA_PUBLIC:
1746 if (xmlStrEqual(pubID, cur->name)) {
1747 if (xmlDebugCatalogs)
1748 xmlGenericError(xmlGenericErrorContext,
1749 "Found public match %s\n", cur->name);
1751 return(xmlStrdup(cur->URL));
1754 case XML_CATA_DELEGATE_PUBLIC:
1755 if (!xmlStrncmp(pubID, cur->name, xmlStrlen(cur->name)) &&
1756 (cur->prefer == XML_CATA_PREFER_PUBLIC))
1759 case XML_CATA_NEXT_CATALOG:
1769 const xmlChar *delegates[MAX_DELEGATE];
1773 * Assume the entries have been sorted by decreasing substring
1774 * matches when the list was produced.
1777 while (cur != NULL) {
1778 if ((cur->type == XML_CATA_DELEGATE_PUBLIC) &&
1779 (cur->prefer == XML_CATA_PREFER_PUBLIC) &&
1780 (!xmlStrncmp(pubID, cur->name, xmlStrlen(cur->name)))) {
1782 for (i = 0;i < nbList;i++)
1783 if (xmlStrEqual(cur->URL, delegates[i]))
1789 if (nbList < MAX_DELEGATE)
1790 delegates[nbList++] = cur->URL;
1792 if (cur->children == NULL) {
1793 xmlFetchXMLCatalogFile(cur);
1795 if (cur->children != NULL) {
1796 if (xmlDebugCatalogs)
1797 xmlGenericError(xmlGenericErrorContext,
1798 "Trying public delegate %s\n", cur->URL);
1799 ret = xmlCatalogListXMLResolve(
1800 cur->children, pubID, NULL);
1810 * Apply the cut algorithm explained in 4/
1813 return(XML_CATAL_BREAK);
1818 while (cur != NULL) {
1819 if (cur->type == XML_CATA_NEXT_CATALOG) {
1820 if (cur->children == NULL) {
1821 xmlFetchXMLCatalogFile(cur);
1823 if (cur->children != NULL) {
1824 ret = xmlCatalogListXMLResolve(cur->children, pubID, sysID);
1828 } else if (catal->depth > MAX_CATAL_DEPTH) {
1842 * xmlCatalogXMLResolveURI:
1843 * @catal: a catalog list
1845 * @sysID: the system ID string
1847 * Do a complete resolution lookup of an External Identifier for a
1848 * list of catalog entries.
1850 * Implements (or tries to) 7.2.2. URI Resolution
1851 * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
1853 * Returns the URI of the resource or NULL if not found
1856 xmlCatalogXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) {
1857 xmlChar *ret = NULL;
1858 xmlCatalogEntryPtr cur;
1859 int haveDelegate = 0;
1861 xmlCatalogEntryPtr rewrite = NULL;
1862 int lenrewrite = 0, len;
1870 if (catal->depth > MAX_CATAL_DEPTH) {
1871 xmlCatalogErr(catal, NULL, XML_CATALOG_RECURSION,
1872 "Detected recursion in catalog %s\n",
1873 catal->name, NULL, NULL);
1878 * First tries steps 2/ 3/ 4/ if a system ID is provided.
1882 while (cur != NULL) {
1883 switch (cur->type) {
1885 if (xmlStrEqual(URI, cur->name)) {
1886 if (xmlDebugCatalogs)
1887 xmlGenericError(xmlGenericErrorContext,
1888 "Found URI match %s\n", cur->name);
1889 return(xmlStrdup(cur->URL));
1892 case XML_CATA_REWRITE_URI:
1893 len = xmlStrlen(cur->name);
1894 if ((len > lenrewrite) &&
1895 (!xmlStrncmp(URI, cur->name, len))) {
1900 case XML_CATA_DELEGATE_URI:
1901 if (!xmlStrncmp(URI, cur->name, xmlStrlen(cur->name)))
1904 case XML_CATA_NEXT_CATALOG:
1912 if (rewrite != NULL) {
1913 if (xmlDebugCatalogs)
1914 xmlGenericError(xmlGenericErrorContext,
1915 "Using rewriting rule %s\n", rewrite->name);
1916 ret = xmlStrdup(rewrite->URL);
1918 ret = xmlStrcat(ret, &URI[lenrewrite]);
1922 const xmlChar *delegates[MAX_DELEGATE];
1926 * Assume the entries have been sorted by decreasing substring
1927 * matches when the list was produced.
1930 while (cur != NULL) {
1931 if (((cur->type == XML_CATA_DELEGATE_SYSTEM) ||
1932 (cur->type == XML_CATA_DELEGATE_URI)) &&
1933 (!xmlStrncmp(URI, cur->name, xmlStrlen(cur->name)))) {
1934 for (i = 0;i < nbList;i++)
1935 if (xmlStrEqual(cur->URL, delegates[i]))
1941 if (nbList < MAX_DELEGATE)
1942 delegates[nbList++] = cur->URL;
1944 if (cur->children == NULL) {
1945 xmlFetchXMLCatalogFile(cur);
1947 if (cur->children != NULL) {
1948 if (xmlDebugCatalogs)
1949 xmlGenericError(xmlGenericErrorContext,
1950 "Trying URI delegate %s\n", cur->URL);
1951 ret = xmlCatalogListXMLResolveURI(
1952 cur->children, URI);
1960 * Apply the cut algorithm explained in 4/
1962 return(XML_CATAL_BREAK);
1966 while (cur != NULL) {
1967 if (cur->type == XML_CATA_NEXT_CATALOG) {
1968 if (cur->children == NULL) {
1969 xmlFetchXMLCatalogFile(cur);
1971 if (cur->children != NULL) {
1972 ret = xmlCatalogListXMLResolveURI(cur->children, URI);
1985 * xmlCatalogListXMLResolve:
1986 * @catal: a catalog list
1987 * @pubID: the public ID string
1988 * @sysID: the system ID string
1990 * Do a complete resolution lookup of an External Identifier for a
1993 * Implements (or tries to) 7.1. External Identifier Resolution
1994 * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
1996 * Returns the URI of the resource or NULL if not found
1999 xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
2000 const xmlChar *sysID) {
2001 xmlChar *ret = NULL;
2002 xmlChar *urnID = NULL;
2007 if ((pubID == NULL) && (sysID == NULL))
2010 normid = xmlCatalogNormalizePublic(pubID);
2012 pubID = (*normid != 0 ? normid : NULL);
2014 if (!xmlStrncmp(pubID, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) {
2015 urnID = xmlCatalogUnWrapURN(pubID);
2016 if (xmlDebugCatalogs) {
2018 xmlGenericError(xmlGenericErrorContext,
2019 "Public URN ID %s expanded to NULL\n", pubID);
2021 xmlGenericError(xmlGenericErrorContext,
2022 "Public URN ID expanded to %s\n", urnID);
2024 ret = xmlCatalogListXMLResolve(catal, urnID, sysID);
2031 if (!xmlStrncmp(sysID, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) {
2032 urnID = xmlCatalogUnWrapURN(sysID);
2033 if (xmlDebugCatalogs) {
2035 xmlGenericError(xmlGenericErrorContext,
2036 "System URN ID %s expanded to NULL\n", sysID);
2038 xmlGenericError(xmlGenericErrorContext,
2039 "System URN ID expanded to %s\n", urnID);
2042 ret = xmlCatalogListXMLResolve(catal, urnID, NULL);
2043 else if (xmlStrEqual(pubID, urnID))
2044 ret = xmlCatalogListXMLResolve(catal, pubID, NULL);
2046 ret = xmlCatalogListXMLResolve(catal, pubID, urnID);
2054 while (catal != NULL) {
2055 if (catal->type == XML_CATA_CATALOG) {
2056 if (catal->children == NULL) {
2057 xmlFetchXMLCatalogFile(catal);
2059 if (catal->children != NULL) {
2060 ret = xmlCatalogXMLResolve(catal->children, pubID, sysID);
2063 } else if ((catal->children != NULL) &&
2064 (catal->children->depth > MAX_CATAL_DEPTH)) {
2070 catal = catal->next;
2078 * xmlCatalogListXMLResolveURI:
2079 * @catal: a catalog list
2082 * Do a complete resolution lookup of an URI for a list of catalogs
2084 * Implements (or tries to) 7.2. URI Resolution
2085 * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
2087 * Returns the URI of the resource or NULL if not found
2090 xmlCatalogListXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) {
2091 xmlChar *ret = NULL;
2092 xmlChar *urnID = NULL;
2099 if (!xmlStrncmp(URI, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) {
2100 urnID = xmlCatalogUnWrapURN(URI);
2101 if (xmlDebugCatalogs) {
2103 xmlGenericError(xmlGenericErrorContext,
2104 "URN ID %s expanded to NULL\n", URI);
2106 xmlGenericError(xmlGenericErrorContext,
2107 "URN ID expanded to %s\n", urnID);
2109 ret = xmlCatalogListXMLResolve(catal, urnID, NULL);
2114 while (catal != NULL) {
2115 if (catal->type == XML_CATA_CATALOG) {
2116 if (catal->children == NULL) {
2117 xmlFetchXMLCatalogFile(catal);
2119 if (catal->children != NULL) {
2120 ret = xmlCatalogXMLResolveURI(catal->children, URI);
2125 catal = catal->next;
2130 /************************************************************************
2132 * The SGML Catalog parser *
2134 ************************************************************************/
2139 #define SKIP(x) cur += x;
2141 #define SKIP_BLANKS while (IS_BLANK_CH(*cur)) NEXT;
2144 * xmlParseSGMLCatalogComment:
2145 * @cur: the current character
2147 * Skip a comment in an SGML catalog
2149 * Returns new current character
2151 static const xmlChar *
2152 xmlParseSGMLCatalogComment(const xmlChar *cur) {
2153 if ((cur[0] != '-') || (cur[1] != '-'))
2156 while ((cur[0] != 0) && ((cur[0] != '-') || ((cur[1] != '-'))))
2165 * xmlParseSGMLCatalogPubid:
2166 * @cur: the current character
2167 * @id: the return location
2169 * Parse an SGML catalog ID
2171 * Returns new current character and store the value in @id
2173 static const xmlChar *
2174 xmlParseSGMLCatalogPubid(const xmlChar *cur, xmlChar **id) {
2175 xmlChar *buf = NULL, *tmp;
2186 } else if (RAW == '\'') {
2192 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
2194 xmlCatalogErrMemory("allocating public ID");
2197 while (IS_PUBIDCHAR_CH(*cur) || (*cur == '?')) {
2198 if ((*cur == stop) && (stop != ' '))
2200 if ((stop == ' ') && (IS_BLANK_CH(*cur)))
2202 if (len + 1 >= size) {
2204 tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
2206 xmlCatalogErrMemory("allocating public ID");
2218 if (!IS_BLANK_CH(*cur)) {
2234 * xmlParseSGMLCatalogName:
2235 * @cur: the current character
2236 * @name: the return location
2238 * Parse an SGML catalog name
2240 * Returns new current character and store the value in @name
2242 static const xmlChar *
2243 xmlParseSGMLCatalogName(const xmlChar *cur, xmlChar **name) {
2244 xmlChar buf[XML_MAX_NAMELEN + 5];
2251 * Handler for more complex cases
2254 if ((!IS_LETTER(c) && (c != '_') && (c != ':'))) {
2258 while (((IS_LETTER(c)) || (IS_DIGIT(c)) ||
2259 (c == '.') || (c == '-') ||
2260 (c == '_') || (c == ':'))) {
2264 if (len >= XML_MAX_NAMELEN)
2267 *name = xmlStrndup(buf, len);
2272 * xmlGetSGMLCatalogEntryType:
2273 * @name: the entry name
2275 * Get the Catalog entry type for a given SGML Catalog name
2277 * Returns Catalog entry type
2279 static xmlCatalogEntryType
2280 xmlGetSGMLCatalogEntryType(const xmlChar *name) {
2281 xmlCatalogEntryType type = XML_CATA_NONE;
2282 if (xmlStrEqual(name, (const xmlChar *) "SYSTEM"))
2283 type = SGML_CATA_SYSTEM;
2284 else if (xmlStrEqual(name, (const xmlChar *) "PUBLIC"))
2285 type = SGML_CATA_PUBLIC;
2286 else if (xmlStrEqual(name, (const xmlChar *) "DELEGATE"))
2287 type = SGML_CATA_DELEGATE;
2288 else if (xmlStrEqual(name, (const xmlChar *) "ENTITY"))
2289 type = SGML_CATA_ENTITY;
2290 else if (xmlStrEqual(name, (const xmlChar *) "DOCTYPE"))
2291 type = SGML_CATA_DOCTYPE;
2292 else if (xmlStrEqual(name, (const xmlChar *) "LINKTYPE"))
2293 type = SGML_CATA_LINKTYPE;
2294 else if (xmlStrEqual(name, (const xmlChar *) "NOTATION"))
2295 type = SGML_CATA_NOTATION;
2296 else if (xmlStrEqual(name, (const xmlChar *) "SGMLDECL"))
2297 type = SGML_CATA_SGMLDECL;
2298 else if (xmlStrEqual(name, (const xmlChar *) "DOCUMENT"))
2299 type = SGML_CATA_DOCUMENT;
2300 else if (xmlStrEqual(name, (const xmlChar *) "CATALOG"))
2301 type = SGML_CATA_CATALOG;
2302 else if (xmlStrEqual(name, (const xmlChar *) "BASE"))
2303 type = SGML_CATA_BASE;
2308 * xmlParseSGMLCatalog:
2309 * @catal: the SGML Catalog
2310 * @value: the content of the SGML Catalog serialization
2311 * @file: the filepath for the catalog
2312 * @super: should this be handled as a Super Catalog in which case
2313 * parsing is not recursive
2315 * Parse an SGML catalog content and fill up the @catal hash table with
2316 * the new entries found.
2318 * Returns 0 in case of success, -1 in case of error.
2321 xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value,
2322 const char *file, int super) {
2323 const xmlChar *cur = value;
2324 xmlChar *base = NULL;
2327 if ((cur == NULL) || (file == NULL))
2329 base = xmlStrdup((const xmlChar *) file);
2331 while ((cur != NULL) && (cur[0] != 0)) {
2335 if ((cur[0] == '-') && (cur[1] == '-')) {
2336 cur = xmlParseSGMLCatalogComment(cur);
2342 xmlChar *sysid = NULL;
2343 xmlChar *name = NULL;
2344 xmlCatalogEntryType type = XML_CATA_NONE;
2346 cur = xmlParseSGMLCatalogName(cur, &name);
2351 if (!IS_BLANK_CH(*cur)) {
2356 if (xmlStrEqual(name, (const xmlChar *) "SYSTEM"))
2357 type = SGML_CATA_SYSTEM;
2358 else if (xmlStrEqual(name, (const xmlChar *) "PUBLIC"))
2359 type = SGML_CATA_PUBLIC;
2360 else if (xmlStrEqual(name, (const xmlChar *) "DELEGATE"))
2361 type = SGML_CATA_DELEGATE;
2362 else if (xmlStrEqual(name, (const xmlChar *) "ENTITY"))
2363 type = SGML_CATA_ENTITY;
2364 else if (xmlStrEqual(name, (const xmlChar *) "DOCTYPE"))
2365 type = SGML_CATA_DOCTYPE;
2366 else if (xmlStrEqual(name, (const xmlChar *) "LINKTYPE"))
2367 type = SGML_CATA_LINKTYPE;
2368 else if (xmlStrEqual(name, (const xmlChar *) "NOTATION"))
2369 type = SGML_CATA_NOTATION;
2370 else if (xmlStrEqual(name, (const xmlChar *) "SGMLDECL"))
2371 type = SGML_CATA_SGMLDECL;
2372 else if (xmlStrEqual(name, (const xmlChar *) "DOCUMENT"))
2373 type = SGML_CATA_DOCUMENT;
2374 else if (xmlStrEqual(name, (const xmlChar *) "CATALOG"))
2375 type = SGML_CATA_CATALOG;
2376 else if (xmlStrEqual(name, (const xmlChar *) "BASE"))
2377 type = SGML_CATA_BASE;
2378 else if (xmlStrEqual(name, (const xmlChar *) "OVERRIDE")) {
2380 cur = xmlParseSGMLCatalogName(cur, &name);
2392 case SGML_CATA_ENTITY:
2394 type = SGML_CATA_PENTITY;
2395 case SGML_CATA_PENTITY:
2396 case SGML_CATA_DOCTYPE:
2397 case SGML_CATA_LINKTYPE:
2398 case SGML_CATA_NOTATION:
2399 cur = xmlParseSGMLCatalogName(cur, &name);
2404 if (!IS_BLANK_CH(*cur)) {
2409 cur = xmlParseSGMLCatalogPubid(cur, &sysid);
2415 case SGML_CATA_PUBLIC:
2416 case SGML_CATA_SYSTEM:
2417 case SGML_CATA_DELEGATE:
2418 cur = xmlParseSGMLCatalogPubid(cur, &name);
2423 if (type != SGML_CATA_SYSTEM) {
2426 normid = xmlCatalogNormalizePublic(name);
2427 if (normid != NULL) {
2438 if (!IS_BLANK_CH(*cur)) {
2443 cur = xmlParseSGMLCatalogPubid(cur, &sysid);
2449 case SGML_CATA_BASE:
2450 case SGML_CATA_CATALOG:
2451 case SGML_CATA_DOCUMENT:
2452 case SGML_CATA_SGMLDECL:
2453 cur = xmlParseSGMLCatalogPubid(cur, &sysid);
2468 } else if (type == SGML_CATA_BASE) {
2471 base = xmlStrdup(sysid);
2472 } else if ((type == SGML_CATA_PUBLIC) ||
2473 (type == SGML_CATA_SYSTEM)) {
2476 filename = xmlBuildURI(sysid, base);
2477 if (filename != NULL) {
2478 xmlCatalogEntryPtr entry;
2480 entry = xmlNewCatalogEntry(type, name, filename,
2481 NULL, XML_CATA_PREFER_NONE, NULL);
2482 res = xmlHashAddEntry(catal->sgml, name, entry);
2484 xmlFreeCatalogEntry(entry);
2489 } else if (type == SGML_CATA_CATALOG) {
2491 xmlCatalogEntryPtr entry;
2493 entry = xmlNewCatalogEntry(type, sysid, NULL, NULL,
2494 XML_CATA_PREFER_NONE, NULL);
2495 res = xmlHashAddEntry(catal->sgml, sysid, entry);
2497 xmlFreeCatalogEntry(entry);
2502 filename = xmlBuildURI(sysid, base);
2503 if (filename != NULL) {
2504 xmlExpandCatalog(catal, (const char *)filename);
2510 * drop anything else we won't handle it
2525 /************************************************************************
2527 * SGML Catalog handling *
2529 ************************************************************************/
2532 * xmlCatalogGetSGMLPublic:
2533 * @catal: an SGML catalog hash
2534 * @pubID: the public ID string
2536 * Try to lookup the catalog local reference associated to a public ID
2538 * Returns the local resource if found or NULL otherwise.
2540 static const xmlChar *
2541 xmlCatalogGetSGMLPublic(xmlHashTablePtr catal, const xmlChar *pubID) {
2542 xmlCatalogEntryPtr entry;
2548 normid = xmlCatalogNormalizePublic(pubID);
2550 pubID = (*normid != 0 ? normid : NULL);
2552 entry = (xmlCatalogEntryPtr) xmlHashLookup(catal, pubID);
2553 if (entry == NULL) {
2558 if (entry->type == SGML_CATA_PUBLIC) {
2569 * xmlCatalogGetSGMLSystem:
2570 * @catal: an SGML catalog hash
2571 * @sysID: the system ID string
2573 * Try to lookup the catalog local reference for a system ID
2575 * Returns the local resource if found or NULL otherwise.
2577 static const xmlChar *
2578 xmlCatalogGetSGMLSystem(xmlHashTablePtr catal, const xmlChar *sysID) {
2579 xmlCatalogEntryPtr entry;
2584 entry = (xmlCatalogEntryPtr) xmlHashLookup(catal, sysID);
2587 if (entry->type == SGML_CATA_SYSTEM)
2593 * xmlCatalogSGMLResolve:
2594 * @catal: the SGML catalog
2595 * @pubID: the public ID string
2596 * @sysID: the system ID string
2598 * Do a complete resolution lookup of an External Identifier
2600 * Returns the URI of the resource or NULL if not found
2602 static const xmlChar *
2603 xmlCatalogSGMLResolve(xmlCatalogPtr catal, const xmlChar *pubID,
2604 const xmlChar *sysID) {
2605 const xmlChar *ret = NULL;
2607 if (catal->sgml == NULL)
2611 ret = xmlCatalogGetSGMLPublic(catal->sgml, pubID);
2615 ret = xmlCatalogGetSGMLSystem(catal->sgml, sysID);
2621 /************************************************************************
2623 * Specific Public interfaces *
2625 ************************************************************************/
2628 * xmlLoadSGMLSuperCatalog:
2629 * @filename: a file path
2631 * Load an SGML super catalog. It won't expand CATALOG or DELEGATE
2632 * references. This is only needed for manipulating SGML Super Catalogs
2633 * like adding and removing CATALOG or DELEGATE entries.
2635 * Returns the catalog parsed or NULL in case of error
2638 xmlLoadSGMLSuperCatalog(const char *filename)
2641 xmlCatalogPtr catal;
2644 content = xmlLoadFileContent(filename);
2645 if (content == NULL)
2648 catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE, xmlCatalogDefaultPrefer);
2649 if (catal == NULL) {
2654 ret = xmlParseSGMLCatalog(catal, content, filename, 1);
2657 xmlFreeCatalog(catal);
2665 * @filename: a file path
2667 * Load the catalog and build the associated data structures.
2668 * This can be either an XML Catalog or an SGML Catalog
2669 * It will recurse in SGML CATALOG entries. On the other hand XML
2670 * Catalogs are not handled recursively.
2672 * Returns the catalog parsed or NULL in case of error
2675 xmlLoadACatalog(const char *filename)
2679 xmlCatalogPtr catal;
2682 content = xmlLoadFileContent(filename);
2683 if (content == NULL)
2689 while ((*first != 0) && (*first != '-') && (*first != '<') &&
2690 (!(((*first >= 'A') && (*first <= 'Z')) ||
2691 ((*first >= 'a') && (*first <= 'z')))))
2694 if (*first != '<') {
2695 catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE, xmlCatalogDefaultPrefer);
2696 if (catal == NULL) {
2700 ret = xmlParseSGMLCatalog(catal, content, filename, 0);
2702 xmlFreeCatalog(catal);
2707 catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE, xmlCatalogDefaultPrefer);
2708 if (catal == NULL) {
2712 catal->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
2713 NULL, BAD_CAST filename, xmlCatalogDefaultPrefer, NULL);
2722 * @filename: a file path
2724 * Load the catalog and expand the existing catal structure.
2725 * This can be either an XML Catalog or an SGML Catalog
2727 * Returns 0 in case of success, -1 in case of error
2730 xmlExpandCatalog(xmlCatalogPtr catal, const char *filename)
2734 if ((catal == NULL) || (filename == NULL))
2738 if (catal->type == XML_SGML_CATALOG_TYPE) {
2741 content = xmlLoadFileContent(filename);
2742 if (content == NULL)
2745 ret = xmlParseSGMLCatalog(catal, content, filename, 0);
2752 xmlCatalogEntryPtr tmp, cur;
2753 tmp = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
2754 NULL, BAD_CAST filename, xmlCatalogDefaultPrefer, NULL);
2760 while (cur->next != NULL) cur = cur->next;
2768 * xmlACatalogResolveSystem:
2770 * @sysID: the system ID string
2772 * Try to lookup the catalog resource for a system ID
2774 * Returns the resource if found or NULL otherwise, the value returned
2775 * must be freed by the caller.
2778 xmlACatalogResolveSystem(xmlCatalogPtr catal, const xmlChar *sysID) {
2779 xmlChar *ret = NULL;
2781 if ((sysID == NULL) || (catal == NULL))
2784 if (xmlDebugCatalogs)
2785 xmlGenericError(xmlGenericErrorContext,
2786 "Resolve sysID %s\n", sysID);
2788 if (catal->type == XML_XML_CATALOG_TYPE) {
2789 ret = xmlCatalogListXMLResolve(catal->xml, NULL, sysID);
2790 if (ret == XML_CATAL_BREAK)
2793 const xmlChar *sgml;
2795 sgml = xmlCatalogGetSGMLSystem(catal->sgml, sysID);
2797 ret = xmlStrdup(sgml);
2803 * xmlACatalogResolvePublic:
2805 * @pubID: the public ID string
2807 * Try to lookup the catalog local reference associated to a public ID in that catalog
2809 * Returns the local resource if found or NULL otherwise, the value returned
2810 * must be freed by the caller.
2813 xmlACatalogResolvePublic(xmlCatalogPtr catal, const xmlChar *pubID) {
2814 xmlChar *ret = NULL;
2816 if ((pubID == NULL) || (catal == NULL))
2819 if (xmlDebugCatalogs)
2820 xmlGenericError(xmlGenericErrorContext,
2821 "Resolve pubID %s\n", pubID);
2823 if (catal->type == XML_XML_CATALOG_TYPE) {
2824 ret = xmlCatalogListXMLResolve(catal->xml, pubID, NULL);
2825 if (ret == XML_CATAL_BREAK)
2828 const xmlChar *sgml;
2830 sgml = xmlCatalogGetSGMLPublic(catal->sgml, pubID);
2832 ret = xmlStrdup(sgml);
2838 * xmlACatalogResolve:
2840 * @pubID: the public ID string
2841 * @sysID: the system ID string
2843 * Do a complete resolution lookup of an External Identifier
2845 * Returns the URI of the resource or NULL if not found, it must be freed
2849 xmlACatalogResolve(xmlCatalogPtr catal, const xmlChar * pubID,
2850 const xmlChar * sysID)
2852 xmlChar *ret = NULL;
2854 if (((pubID == NULL) && (sysID == NULL)) || (catal == NULL))
2857 if (xmlDebugCatalogs) {
2858 if ((pubID != NULL) && (sysID != NULL)) {
2859 xmlGenericError(xmlGenericErrorContext,
2860 "Resolve: pubID %s sysID %s\n", pubID, sysID);
2861 } else if (pubID != NULL) {
2862 xmlGenericError(xmlGenericErrorContext,
2863 "Resolve: pubID %s\n", pubID);
2865 xmlGenericError(xmlGenericErrorContext,
2866 "Resolve: sysID %s\n", sysID);
2870 if (catal->type == XML_XML_CATALOG_TYPE) {
2871 ret = xmlCatalogListXMLResolve(catal->xml, pubID, sysID);
2872 if (ret == XML_CATAL_BREAK)
2875 const xmlChar *sgml;
2877 sgml = xmlCatalogSGMLResolve(catal, pubID, sysID);
2879 ret = xmlStrdup(sgml);
2885 * xmlACatalogResolveURI:
2889 * Do a complete resolution lookup of an URI
2891 * Returns the URI of the resource or NULL if not found, it must be freed
2895 xmlACatalogResolveURI(xmlCatalogPtr catal, const xmlChar *URI) {
2896 xmlChar *ret = NULL;
2898 if ((URI == NULL) || (catal == NULL))
2901 if (xmlDebugCatalogs)
2902 xmlGenericError(xmlGenericErrorContext,
2903 "Resolve URI %s\n", URI);
2905 if (catal->type == XML_XML_CATALOG_TYPE) {
2906 ret = xmlCatalogListXMLResolveURI(catal->xml, URI);
2907 if (ret == XML_CATAL_BREAK)
2910 const xmlChar *sgml;
2912 sgml = xmlCatalogSGMLResolve(catal, NULL, URI);
2914 ret = xmlStrdup(sgml);
2919 #ifdef LIBXML_OUTPUT_ENABLED
2925 * Dump the given catalog to the given file.
2928 xmlACatalogDump(xmlCatalogPtr catal, FILE *out) {
2929 if ((out == NULL) || (catal == NULL))
2932 if (catal->type == XML_XML_CATALOG_TYPE) {
2933 xmlDumpXMLCatalog(out, catal->xml);
2935 xmlHashScan(catal->sgml,
2936 (xmlHashScanner) xmlCatalogDumpEntry, out);
2939 #endif /* LIBXML_OUTPUT_ENABLED */
2944 * @type: the type of record to add to the catalog
2945 * @orig: the system, public or prefix to match
2946 * @replace: the replacement value for the match
2948 * Add an entry in the catalog, it may overwrite existing but
2949 * different entries.
2951 * Returns 0 if successful, -1 otherwise
2954 xmlACatalogAdd(xmlCatalogPtr catal, const xmlChar * type,
2955 const xmlChar * orig, const xmlChar * replace)
2962 if (catal->type == XML_XML_CATALOG_TYPE) {
2963 res = xmlAddXMLCatalog(catal->xml, type, orig, replace);
2965 xmlCatalogEntryType cattype;
2967 cattype = xmlGetSGMLCatalogEntryType(type);
2968 if (cattype != XML_CATA_NONE) {
2969 xmlCatalogEntryPtr entry;
2971 entry = xmlNewCatalogEntry(cattype, orig, replace, NULL,
2972 XML_CATA_PREFER_NONE, NULL);
2973 if (catal->sgml == NULL)
2974 catal->sgml = xmlHashCreate(10);
2975 res = xmlHashAddEntry(catal->sgml, orig, entry);
2982 * xmlACatalogRemove:
2984 * @value: the value to remove
2986 * Remove an entry from the catalog
2988 * Returns the number of entries removed if successful, -1 otherwise
2991 xmlACatalogRemove(xmlCatalogPtr catal, const xmlChar *value) {
2994 if ((catal == NULL) || (value == NULL))
2997 if (catal->type == XML_XML_CATALOG_TYPE) {
2998 res = xmlDelXMLCatalog(catal->xml, value);
3000 res = xmlHashRemoveEntry(catal->sgml, value,
3001 (xmlHashDeallocator) xmlFreeCatalogEntry);
3010 * @sgml: should this create an SGML catalog
3012 * create a new Catalog.
3014 * Returns the xmlCatalogPtr or NULL in case of error
3017 xmlNewCatalog(int sgml) {
3018 xmlCatalogPtr catal = NULL;
3021 catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE,
3022 xmlCatalogDefaultPrefer);
3023 if ((catal != NULL) && (catal->sgml == NULL))
3024 catal->sgml = xmlHashCreate(10);
3026 catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE,
3027 xmlCatalogDefaultPrefer);
3032 * xmlCatalogIsEmpty:
3033 * @catal: should this create an SGML catalog
3035 * Check is a catalog is empty
3037 * Returns 1 if the catalog is empty, 0 if not, amd -1 in case of error.
3040 xmlCatalogIsEmpty(xmlCatalogPtr catal) {
3044 if (catal->type == XML_XML_CATALOG_TYPE) {
3045 if (catal->xml == NULL)
3047 if ((catal->xml->type != XML_CATA_CATALOG) &&
3048 (catal->xml->type != XML_CATA_BROKEN_CATALOG))
3050 if (catal->xml->children == NULL)
3056 if (catal->sgml == NULL)
3058 res = xmlHashSize(catal->sgml);
3067 /************************************************************************
3069 * Public interfaces manipulating the global shared default catalog *
3071 ************************************************************************/
3074 * xmlInitializeCatalogData:
3076 * Do the catalog initialization only of global data, doesn't try to load
3077 * any catalog actually.
3078 * this function is not thread safe, catalog initialization should
3079 * preferably be done once at startup
3082 xmlInitializeCatalogData(void) {
3083 if (xmlCatalogInitialized != 0)
3086 if (getenv("XML_DEBUG_CATALOG"))
3087 xmlDebugCatalogs = 1;
3088 xmlCatalogMutex = xmlNewRMutex();
3090 xmlCatalogInitialized = 1;
3093 * xmlInitializeCatalog:
3095 * Do the catalog initialization.
3096 * this function is not thread safe, catalog initialization should
3097 * preferably be done once at startup
3100 xmlInitializeCatalog(void) {
3101 if (xmlCatalogInitialized != 0)
3104 xmlInitializeCatalogData();
3105 xmlRMutexLock(xmlCatalogMutex);
3107 if (getenv("XML_DEBUG_CATALOG"))
3108 xmlDebugCatalogs = 1;
3110 if (xmlDefaultCatalog == NULL) {
3111 const char *catalogs;
3113 const char *cur, *paths;
3114 xmlCatalogPtr catal;
3115 xmlCatalogEntryPtr *nextent;
3117 catalogs = (const char *) getenv("XML_CATALOG_FILES");
3118 if (catalogs == NULL)
3119 #if defined(_WIN32) && defined(_MSC_VER)
3122 hmodule = GetModuleHandleA("libxml2.dll");
3123 if (hmodule == NULL)
3124 hmodule = GetModuleHandleA(NULL);
3125 if (hmodule != NULL) {
3127 unsigned long len = GetModuleFileNameA(hmodule, buf, 255);
3129 char* p = &(buf[len]);
3130 while (*p != '\\' && p > buf)
3134 strncpy(p, "\\..\\etc\\catalog", 255 - (p - buf));
3135 uri = xmlCanonicPath(buf);
3137 strncpy(XML_XML_DEFAULT_CATALOG, uri, 255);
3143 catalogs = XML_XML_DEFAULT_CATALOG;
3146 catalogs = XML_XML_DEFAULT_CATALOG;
3149 catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE,
3150 xmlCatalogDefaultPrefer);
3151 if (catal != NULL) {
3152 /* the XML_CATALOG_FILES envvar is allowed to contain a
3153 space-separated list of entries. */
3155 nextent = &catal->xml;
3156 while (*cur != '\0') {
3157 while (xmlIsBlank_ch(*cur))
3161 while ((*cur != 0) && (!xmlIsBlank_ch(*cur)))
3163 path = (char *) xmlStrndup((const xmlChar *)paths, cur - paths);
3165 *nextent = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
3166 NULL, BAD_CAST path, xmlCatalogDefaultPrefer, NULL);
3167 if (*nextent != NULL)
3168 nextent = &((*nextent)->next);
3173 xmlDefaultCatalog = catal;
3177 xmlRMutexUnlock(xmlCatalogMutex);
3183 * @filename: a file path
3185 * Load the catalog and makes its definitions effective for the default
3186 * external entity loader. It will recurse in SGML CATALOG entries.
3187 * this function is not thread safe, catalog initialization should
3188 * preferably be done once at startup
3190 * Returns 0 in case of success -1 in case of error
3193 xmlLoadCatalog(const char *filename)
3196 xmlCatalogPtr catal;
3198 if (!xmlCatalogInitialized)
3199 xmlInitializeCatalogData();
3201 xmlRMutexLock(xmlCatalogMutex);
3203 if (xmlDefaultCatalog == NULL) {
3204 catal = xmlLoadACatalog(filename);
3205 if (catal == NULL) {
3206 xmlRMutexUnlock(xmlCatalogMutex);
3210 xmlDefaultCatalog = catal;
3211 xmlRMutexUnlock(xmlCatalogMutex);
3215 ret = xmlExpandCatalog(xmlDefaultCatalog, filename);
3216 xmlRMutexUnlock(xmlCatalogMutex);
3222 * @pathss: a list of directories separated by a colon or a space.
3224 * Load the catalogs and makes their definitions effective for the default
3225 * external entity loader.
3226 * this function is not thread safe, catalog initialization should
3227 * preferably be done once at startup
3230 xmlLoadCatalogs(const char *pathss) {
3243 while (xmlIsBlank_ch(*cur)) cur++;
3246 while ((*cur != 0) && (*cur != PATH_SEAPARATOR) && (!xmlIsBlank_ch(*cur)))
3248 path = xmlStrndup((const xmlChar *)paths, cur - paths);
3250 iLen = strlen(path);
3251 for(i = 0; i < iLen; i++) {
3252 if(path[i] == '\\') {
3258 xmlLoadCatalog((const char *) path);
3262 while (*cur == PATH_SEAPARATOR)
3268 * xmlCatalogCleanup:
3270 * Free up all the memory associated with catalogs
3273 xmlCatalogCleanup(void) {
3274 if (xmlCatalogInitialized == 0)
3277 xmlRMutexLock(xmlCatalogMutex);
3278 if (xmlDebugCatalogs)
3279 xmlGenericError(xmlGenericErrorContext,
3280 "Catalogs cleanup\n");
3281 if (xmlCatalogXMLFiles != NULL)
3282 xmlHashFree(xmlCatalogXMLFiles,
3283 (xmlHashDeallocator)xmlFreeCatalogHashEntryList);
3284 xmlCatalogXMLFiles = NULL;
3285 if (xmlDefaultCatalog != NULL)
3286 xmlFreeCatalog(xmlDefaultCatalog);
3287 xmlDefaultCatalog = NULL;
3288 xmlDebugCatalogs = 0;
3289 xmlCatalogInitialized = 0;
3290 xmlRMutexUnlock(xmlCatalogMutex);
3291 xmlFreeRMutex(xmlCatalogMutex);
3295 * xmlCatalogResolveSystem:
3296 * @sysID: the system ID string
3298 * Try to lookup the catalog resource for a system ID
3300 * Returns the resource if found or NULL otherwise, the value returned
3301 * must be freed by the caller.
3304 xmlCatalogResolveSystem(const xmlChar *sysID) {
3307 if (!xmlCatalogInitialized)
3308 xmlInitializeCatalog();
3310 ret = xmlACatalogResolveSystem(xmlDefaultCatalog, sysID);
3315 * xmlCatalogResolvePublic:
3316 * @pubID: the public ID string
3318 * Try to lookup the catalog reference associated to a public ID
3320 * Returns the resource if found or NULL otherwise, the value returned
3321 * must be freed by the caller.
3324 xmlCatalogResolvePublic(const xmlChar *pubID) {
3327 if (!xmlCatalogInitialized)
3328 xmlInitializeCatalog();
3330 ret = xmlACatalogResolvePublic(xmlDefaultCatalog, pubID);
3335 * xmlCatalogResolve:
3336 * @pubID: the public ID string
3337 * @sysID: the system ID string
3339 * Do a complete resolution lookup of an External Identifier
3341 * Returns the URI of the resource or NULL if not found, it must be freed
3345 xmlCatalogResolve(const xmlChar *pubID, const xmlChar *sysID) {
3348 if (!xmlCatalogInitialized)
3349 xmlInitializeCatalog();
3351 ret = xmlACatalogResolve(xmlDefaultCatalog, pubID, sysID);
3356 * xmlCatalogResolveURI:
3359 * Do a complete resolution lookup of an URI
3361 * Returns the URI of the resource or NULL if not found, it must be freed
3365 xmlCatalogResolveURI(const xmlChar *URI) {
3368 if (!xmlCatalogInitialized)
3369 xmlInitializeCatalog();
3371 ret = xmlACatalogResolveURI(xmlDefaultCatalog, URI);
3375 #ifdef LIBXML_OUTPUT_ENABLED
3380 * Dump all the global catalog content to the given file.
3383 xmlCatalogDump(FILE *out) {
3387 if (!xmlCatalogInitialized)
3388 xmlInitializeCatalog();
3390 xmlACatalogDump(xmlDefaultCatalog, out);
3392 #endif /* LIBXML_OUTPUT_ENABLED */
3396 * @type: the type of record to add to the catalog
3397 * @orig: the system, public or prefix to match
3398 * @replace: the replacement value for the match
3400 * Add an entry in the catalog, it may overwrite existing but
3401 * different entries.
3402 * If called before any other catalog routine, allows to override the
3403 * default shared catalog put in place by xmlInitializeCatalog();
3405 * Returns 0 if successful, -1 otherwise
3408 xmlCatalogAdd(const xmlChar *type, const xmlChar *orig, const xmlChar *replace) {
3411 if (!xmlCatalogInitialized)
3412 xmlInitializeCatalogData();
3414 xmlRMutexLock(xmlCatalogMutex);
3416 * Specific case where one want to override the default catalog
3417 * put in place by xmlInitializeCatalog();
3419 if ((xmlDefaultCatalog == NULL) &&
3420 (xmlStrEqual(type, BAD_CAST "catalog"))) {
3421 xmlDefaultCatalog = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE,
3422 xmlCatalogDefaultPrefer);
3423 xmlDefaultCatalog->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
3424 orig, NULL, xmlCatalogDefaultPrefer, NULL);
3426 xmlRMutexUnlock(xmlCatalogMutex);
3430 res = xmlACatalogAdd(xmlDefaultCatalog, type, orig, replace);
3431 xmlRMutexUnlock(xmlCatalogMutex);
3437 * @value: the value to remove
3439 * Remove an entry from the catalog
3441 * Returns the number of entries removed if successful, -1 otherwise
3444 xmlCatalogRemove(const xmlChar *value) {
3447 if (!xmlCatalogInitialized)
3448 xmlInitializeCatalog();
3450 xmlRMutexLock(xmlCatalogMutex);
3451 res = xmlACatalogRemove(xmlDefaultCatalog, value);
3452 xmlRMutexUnlock(xmlCatalogMutex);
3457 * xmlCatalogConvert:
3459 * Convert all the SGML catalog entries as XML ones
3461 * Returns the number of entries converted if successful, -1 otherwise
3464 xmlCatalogConvert(void) {
3467 if (!xmlCatalogInitialized)
3468 xmlInitializeCatalog();
3470 xmlRMutexLock(xmlCatalogMutex);
3471 res = xmlConvertSGMLCatalog(xmlDefaultCatalog);
3472 xmlRMutexUnlock(xmlCatalogMutex);
3476 /************************************************************************
3478 * Public interface manipulating the common preferences *
3480 ************************************************************************/
3483 * xmlCatalogGetDefaults:
3485 * Used to get the user preference w.r.t. to what catalogs should
3488 * Returns the current xmlCatalogAllow value
3491 xmlCatalogGetDefaults(void) {
3492 return(xmlCatalogDefaultAllow);
3496 * xmlCatalogSetDefaults:
3497 * @allow: what catalogs should be accepted
3499 * Used to set the user preference w.r.t. to what catalogs should
3503 xmlCatalogSetDefaults(xmlCatalogAllow allow) {
3504 if (xmlDebugCatalogs) {
3506 case XML_CATA_ALLOW_NONE:
3507 xmlGenericError(xmlGenericErrorContext,
3508 "Disabling catalog usage\n");
3510 case XML_CATA_ALLOW_GLOBAL:
3511 xmlGenericError(xmlGenericErrorContext,
3512 "Allowing only global catalogs\n");
3514 case XML_CATA_ALLOW_DOCUMENT:
3515 xmlGenericError(xmlGenericErrorContext,
3516 "Allowing only catalogs from the document\n");
3518 case XML_CATA_ALLOW_ALL:
3519 xmlGenericError(xmlGenericErrorContext,
3520 "Allowing all catalogs\n");
3524 xmlCatalogDefaultAllow = allow;
3528 * xmlCatalogSetDefaultPrefer:
3529 * @prefer: the default preference for delegation
3531 * Allows to set the preference between public and system for deletion
3532 * in XML Catalog resolution. C.f. section 4.1.1 of the spec
3533 * Values accepted are XML_CATA_PREFER_PUBLIC or XML_CATA_PREFER_SYSTEM
3535 * Returns the previous value of the default preference for delegation
3538 xmlCatalogSetDefaultPrefer(xmlCatalogPrefer prefer) {
3539 xmlCatalogPrefer ret = xmlCatalogDefaultPrefer;
3541 if (prefer == XML_CATA_PREFER_NONE)
3544 if (xmlDebugCatalogs) {
3546 case XML_CATA_PREFER_PUBLIC:
3547 xmlGenericError(xmlGenericErrorContext,
3548 "Setting catalog preference to PUBLIC\n");
3550 case XML_CATA_PREFER_SYSTEM:
3551 xmlGenericError(xmlGenericErrorContext,
3552 "Setting catalog preference to SYSTEM\n");
3554 case XML_CATA_PREFER_NONE:
3558 xmlCatalogDefaultPrefer = prefer;
3563 * xmlCatalogSetDebug:
3564 * @level: the debug level of catalogs required
3566 * Used to set the debug level for catalog operation, 0 disable
3567 * debugging, 1 enable it
3569 * Returns the previous value of the catalog debugging level
3572 xmlCatalogSetDebug(int level) {
3573 int ret = xmlDebugCatalogs;
3576 xmlDebugCatalogs = 0;
3578 xmlDebugCatalogs = level;
3582 /************************************************************************
3584 * Minimal interfaces used for per-document catalogs by the parser *
3586 ************************************************************************/
3589 * xmlCatalogFreeLocal:
3590 * @catalogs: a document's list of catalogs
3592 * Free up the memory associated to the catalog list
3595 xmlCatalogFreeLocal(void *catalogs) {
3596 xmlCatalogEntryPtr catal;
3598 if (!xmlCatalogInitialized)
3599 xmlInitializeCatalog();
3601 catal = (xmlCatalogEntryPtr) catalogs;
3603 xmlFreeCatalogEntryList(catal);
3608 * xmlCatalogAddLocal:
3609 * @catalogs: a document's list of catalogs
3610 * @URL: the URL to a new local catalog
3612 * Add the new entry to the catalog list
3614 * Returns the updated list
3617 xmlCatalogAddLocal(void *catalogs, const xmlChar *URL) {
3618 xmlCatalogEntryPtr catal, add;
3620 if (!xmlCatalogInitialized)
3621 xmlInitializeCatalog();
3626 if (xmlDebugCatalogs)
3627 xmlGenericError(xmlGenericErrorContext,
3628 "Adding document catalog %s\n", URL);
3630 add = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, URL, NULL,
3631 xmlCatalogDefaultPrefer, NULL);
3635 catal = (xmlCatalogEntryPtr) catalogs;
3637 return((void *) add);
3639 while (catal->next != NULL)
3640 catal = catal->next;
3646 * xmlCatalogLocalResolve:
3647 * @catalogs: a document's list of catalogs
3648 * @pubID: the public ID string
3649 * @sysID: the system ID string
3651 * Do a complete resolution lookup of an External Identifier using a
3652 * document's private catalog list
3654 * Returns the URI of the resource or NULL if not found, it must be freed
3658 xmlCatalogLocalResolve(void *catalogs, const xmlChar *pubID,
3659 const xmlChar *sysID) {
3660 xmlCatalogEntryPtr catal;
3663 if (!xmlCatalogInitialized)
3664 xmlInitializeCatalog();
3666 if ((pubID == NULL) && (sysID == NULL))
3669 if (xmlDebugCatalogs) {
3670 if ((pubID != NULL) && (sysID != NULL)) {
3671 xmlGenericError(xmlGenericErrorContext,
3672 "Local Resolve: pubID %s sysID %s\n", pubID, sysID);
3673 } else if (pubID != NULL) {
3674 xmlGenericError(xmlGenericErrorContext,
3675 "Local Resolve: pubID %s\n", pubID);
3677 xmlGenericError(xmlGenericErrorContext,
3678 "Local Resolve: sysID %s\n", sysID);
3682 catal = (xmlCatalogEntryPtr) catalogs;
3685 ret = xmlCatalogListXMLResolve(catal, pubID, sysID);
3686 if ((ret != NULL) && (ret != XML_CATAL_BREAK))
3692 * xmlCatalogLocalResolveURI:
3693 * @catalogs: a document's list of catalogs
3696 * Do a complete resolution lookup of an URI using a
3697 * document's private catalog list
3699 * Returns the URI of the resource or NULL if not found, it must be freed
3703 xmlCatalogLocalResolveURI(void *catalogs, const xmlChar *URI) {
3704 xmlCatalogEntryPtr catal;
3707 if (!xmlCatalogInitialized)
3708 xmlInitializeCatalog();
3713 if (xmlDebugCatalogs)
3714 xmlGenericError(xmlGenericErrorContext,
3715 "Resolve URI %s\n", URI);
3717 catal = (xmlCatalogEntryPtr) catalogs;
3720 ret = xmlCatalogListXMLResolveURI(catal, URI);
3721 if ((ret != NULL) && (ret != XML_CATAL_BREAK))
3726 /************************************************************************
3728 * Deprecated interfaces *
3730 ************************************************************************/
3732 * xmlCatalogGetSystem:
3733 * @sysID: the system ID string
3735 * Try to lookup the catalog reference associated to a system ID
3736 * DEPRECATED, use xmlCatalogResolveSystem()
3738 * Returns the resource if found or NULL otherwise.
3741 xmlCatalogGetSystem(const xmlChar *sysID) {
3743 static xmlChar result[1000];
3746 if (!xmlCatalogInitialized)
3747 xmlInitializeCatalog();
3750 xmlGenericError(xmlGenericErrorContext,
3751 "Use of deprecated xmlCatalogGetSystem() call\n");
3759 * Check first the XML catalogs
3761 if (xmlDefaultCatalog != NULL) {
3762 ret = xmlCatalogListXMLResolve(xmlDefaultCatalog->xml, NULL, sysID);
3763 if ((ret != NULL) && (ret != XML_CATAL_BREAK)) {
3764 snprintf((char *) result, sizeof(result) - 1, "%s", (char *) ret);
3765 result[sizeof(result) - 1] = 0;
3770 if (xmlDefaultCatalog != NULL)
3771 return(xmlCatalogGetSGMLSystem(xmlDefaultCatalog->sgml, sysID));
3776 * xmlCatalogGetPublic:
3777 * @pubID: the public ID string
3779 * Try to lookup the catalog reference associated to a public ID
3780 * DEPRECATED, use xmlCatalogResolvePublic()
3782 * Returns the resource if found or NULL otherwise.
3785 xmlCatalogGetPublic(const xmlChar *pubID) {
3787 static xmlChar result[1000];
3790 if (!xmlCatalogInitialized)
3791 xmlInitializeCatalog();
3794 xmlGenericError(xmlGenericErrorContext,
3795 "Use of deprecated xmlCatalogGetPublic() call\n");
3803 * Check first the XML catalogs
3805 if (xmlDefaultCatalog != NULL) {
3806 ret = xmlCatalogListXMLResolve(xmlDefaultCatalog->xml, pubID, NULL);
3807 if ((ret != NULL) && (ret != XML_CATAL_BREAK)) {
3808 snprintf((char *) result, sizeof(result) - 1, "%s", (char *) ret);
3809 result[sizeof(result) - 1] = 0;
3814 if (xmlDefaultCatalog != NULL)
3815 return(xmlCatalogGetSGMLPublic(xmlDefaultCatalog->sgml, pubID));
3819 #define bottom_catalog
3820 #include "elfgcchack.h"
3821 #endif /* LIBXML_CATALOG_ENABLED */