Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 1 | /** |
| 2 | * catalog.c: set of generic Catalog related routines |
| 3 | * |
| 4 | * Reference: SGML Open Technical Resolution TR9401:1997. |
| 5 | * http://www.jclark.com/sp/catalog.htm |
| 6 | * |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 7 | * XML Catalogs Working Draft 06 August 2001 |
| 8 | * http://www.oasis-open.org/committees/entity/spec-2001-08-06.html |
| 9 | * |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 10 | * See Copyright for the status of this software. |
| 11 | * |
| 12 | * Daniel.Veillard@imag.fr |
| 13 | */ |
| 14 | |
Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 15 | #define IN_LIBXML |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 16 | #include "libxml.h" |
| 17 | |
| 18 | #ifdef LIBXML_CATALOG_ENABLED |
| 19 | #ifdef HAVE_SYS_TYPES_H |
| 20 | #include <sys/types.h> |
| 21 | #endif |
| 22 | #ifdef HAVE_SYS_STAT_H |
| 23 | #include <sys/stat.h> |
| 24 | #endif |
| 25 | #ifdef HAVE_UNISTD_H |
| 26 | #include <unistd.h> |
| 27 | #endif |
| 28 | #ifdef HAVE_FCNTL_H |
| 29 | #include <fcntl.h> |
| 30 | #endif |
Daniel Veillard | c0631a6 | 2001-09-20 13:56:06 +0000 | [diff] [blame] | 31 | #ifdef HAVE_STDLIB_H |
| 32 | #include <stdlib.h> |
| 33 | #endif |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 34 | #include <string.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> |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 41 | #include <libxml/threads.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 42 | #include <libxml/globals.h> |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 43 | |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 44 | #define MAX_DELEGATE 50 |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 45 | #define MAX_CATAL_DEPTH 50 |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 46 | |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 47 | /** |
| 48 | * TODO: |
| 49 | * |
| 50 | * macro to flag unimplemented blocks |
Daniel Veillard | 3e59fc5 | 2003-04-18 12:34:58 +0000 | [diff] [blame] | 51 | * XML_CATALOG_PREFER user env to select between system/public prefered |
| 52 | * option. C.f. Richard Tobin <richard@cogsci.ed.ac.uk> |
| 53 | *> Just FYI, I am using an environment variable XML_CATALOG_PREFER with |
| 54 | *> values "system" and "public". I have made the default be "system" to |
| 55 | *> match yours. |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 56 | */ |
| 57 | #define TODO \ |
| 58 | xmlGenericError(xmlGenericErrorContext, \ |
| 59 | "Unimplemented block at %s:%d\n", \ |
| 60 | __FILE__, __LINE__); |
| 61 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 62 | #define XML_URN_PUBID "urn:publicid:" |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 63 | #define XML_CATAL_BREAK ((xmlChar *) -1) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 64 | #ifndef XML_XML_DEFAULT_CATALOG |
Daniel Veillard | f7b094f | 2001-11-15 13:54:39 +0000 | [diff] [blame] | 65 | #define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog" |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 66 | #endif |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 67 | #ifndef XML_SGML_DEFAULT_CATALOG |
Daniel Veillard | f7b094f | 2001-11-15 13:54:39 +0000 | [diff] [blame] | 68 | #define XML_SGML_DEFAULT_CATALOG "file:///etc/sgml/catalog" |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Daniel Veillard | fb382b8 | 2004-06-14 12:13:12 +0000 | [diff] [blame] | 71 | #if defined(_WIN32) && defined(_MSC_VER) |
| 72 | #undef XML_XML_DEFAULT_CATALOG |
| 73 | static char XML_XML_DEFAULT_CATALOG[256] = "file:///etc/xml/catalog"; |
| 74 | void* __stdcall GetModuleHandleA(const char*); |
| 75 | unsigned long __stdcall GetModuleFileNameA(void*, char*, unsigned long); |
| 76 | #endif |
| 77 | |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 78 | static xmlChar *xmlCatalogNormalizePublic(const xmlChar *pubID); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 79 | static int xmlExpandCatalog(xmlCatalogPtr catal, const char *filename); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 80 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 81 | /************************************************************************ |
| 82 | * * |
| 83 | * Types, all private * |
| 84 | * * |
| 85 | ************************************************************************/ |
| 86 | |
| 87 | typedef enum { |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 88 | XML_CATA_REMOVED = -1, |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 89 | XML_CATA_NONE = 0, |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 90 | XML_CATA_CATALOG, |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 91 | XML_CATA_BROKEN_CATALOG, |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 92 | XML_CATA_NEXT_CATALOG, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 93 | XML_CATA_GROUP, |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 94 | XML_CATA_PUBLIC, |
| 95 | XML_CATA_SYSTEM, |
| 96 | XML_CATA_REWRITE_SYSTEM, |
| 97 | XML_CATA_DELEGATE_PUBLIC, |
| 98 | XML_CATA_DELEGATE_SYSTEM, |
| 99 | XML_CATA_URI, |
| 100 | XML_CATA_REWRITE_URI, |
| 101 | XML_CATA_DELEGATE_URI, |
| 102 | SGML_CATA_SYSTEM, |
| 103 | SGML_CATA_PUBLIC, |
| 104 | SGML_CATA_ENTITY, |
| 105 | SGML_CATA_PENTITY, |
| 106 | SGML_CATA_DOCTYPE, |
| 107 | SGML_CATA_LINKTYPE, |
| 108 | SGML_CATA_NOTATION, |
| 109 | SGML_CATA_DELEGATE, |
| 110 | SGML_CATA_BASE, |
| 111 | SGML_CATA_CATALOG, |
| 112 | SGML_CATA_DOCUMENT, |
| 113 | SGML_CATA_SGMLDECL |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 114 | } xmlCatalogEntryType; |
| 115 | |
| 116 | typedef struct _xmlCatalogEntry xmlCatalogEntry; |
| 117 | typedef xmlCatalogEntry *xmlCatalogEntryPtr; |
| 118 | struct _xmlCatalogEntry { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 119 | struct _xmlCatalogEntry *next; |
| 120 | struct _xmlCatalogEntry *parent; |
| 121 | struct _xmlCatalogEntry *children; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 122 | xmlCatalogEntryType type; |
| 123 | xmlChar *name; |
| 124 | xmlChar *value; |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 125 | xmlChar *URL; /* The expanded URL using the base */ |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 126 | xmlCatalogPrefer prefer; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 127 | int dealloc; |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 128 | int depth; |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 129 | struct _xmlCatalogEntry *group; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 132 | typedef enum { |
| 133 | XML_XML_CATALOG_TYPE = 1, |
| 134 | XML_SGML_CATALOG_TYPE |
| 135 | } xmlCatalogType; |
| 136 | |
| 137 | #define XML_MAX_SGML_CATA_DEPTH 10 |
| 138 | struct _xmlCatalog { |
| 139 | xmlCatalogType type; /* either XML or SGML */ |
| 140 | |
| 141 | /* |
| 142 | * SGML Catalogs are stored as a simple hash table of catalog entries |
| 143 | * Catalog stack to check against overflows when building the |
| 144 | * SGML catalog |
| 145 | */ |
| 146 | char *catalTab[XML_MAX_SGML_CATA_DEPTH]; /* stack of catals */ |
| 147 | int catalNr; /* Number of current catal streams */ |
| 148 | int catalMax; /* Max number of catal streams */ |
| 149 | xmlHashTablePtr sgml; |
| 150 | |
| 151 | /* |
| 152 | * XML Catalogs are stored as a tree of Catalog entries |
| 153 | */ |
| 154 | xmlCatalogPrefer prefer; |
| 155 | xmlCatalogEntryPtr xml; |
| 156 | }; |
| 157 | |
| 158 | /************************************************************************ |
| 159 | * * |
| 160 | * Global variables * |
| 161 | * * |
| 162 | ************************************************************************/ |
| 163 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 164 | /* |
| 165 | * Those are preferences |
| 166 | */ |
| 167 | static int xmlDebugCatalogs = 0; /* used for debugging */ |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 168 | static xmlCatalogAllow xmlCatalogDefaultAllow = XML_CATA_ALLOW_ALL; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 169 | static xmlCatalogPrefer xmlCatalogDefaultPrefer = XML_CATA_PREFER_PUBLIC; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Hash table containing all the trees of XML catalogs parsed by |
| 173 | * the application. |
| 174 | */ |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 175 | static xmlHashTablePtr xmlCatalogXMLFiles = NULL; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * The default catalog in use by the application |
| 179 | */ |
| 180 | static xmlCatalogPtr xmlDefaultCatalog = NULL; |
| 181 | |
| 182 | /* |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 183 | * A mutex for modifying the shared global catalog(s) |
| 184 | * xmlDefaultCatalog tree. |
| 185 | * It also protects xmlCatalogXMLFiles |
| 186 | * The core of this readers/writer scheme is in xmlFetchXMLCatalogFile() |
| 187 | */ |
| 188 | static xmlRMutexPtr xmlCatalogMutex = NULL; |
| 189 | |
| 190 | /* |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 191 | * Whether the catalog support was initialized. |
| 192 | */ |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 193 | static int xmlCatalogInitialized = 0; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 194 | |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 195 | /************************************************************************ |
| 196 | * * |
| 197 | * Catalog error handlers * |
| 198 | * * |
| 199 | ************************************************************************/ |
| 200 | |
| 201 | /** |
| 202 | * xmlCatalogErrMemory: |
| 203 | * @extra: extra informations |
| 204 | * |
| 205 | * Handle an out of memory condition |
| 206 | */ |
| 207 | static void |
| 208 | xmlCatalogErrMemory(const char *extra) |
| 209 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 210 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_CATALOG, |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 211 | XML_ERR_NO_MEMORY, XML_ERR_ERROR, NULL, 0, |
| 212 | extra, NULL, NULL, 0, 0, |
| 213 | "Memory allocation failed : %s\n", extra); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * xmlCatalogErr: |
| 218 | * @catal: the Catalog entry |
| 219 | * @node: the context node |
| 220 | * @msg: the error message |
| 221 | * @extra: extra informations |
| 222 | * |
| 223 | * Handle a catalog error |
| 224 | */ |
| 225 | static void |
| 226 | xmlCatalogErr(xmlCatalogEntryPtr catal, xmlNodePtr node, int error, |
| 227 | const char *msg, const xmlChar *str1, const xmlChar *str2, |
| 228 | const xmlChar *str3) |
| 229 | { |
Daniel Veillard | 659e71e | 2003-10-10 14:10:40 +0000 | [diff] [blame] | 230 | __xmlRaiseError(NULL, NULL, NULL, catal, node, XML_FROM_CATALOG, |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 231 | error, XML_ERR_ERROR, NULL, 0, |
| 232 | (const char *) str1, (const char *) str2, |
| 233 | (const char *) str3, 0, 0, |
| 234 | msg, str1, str2, str3); |
| 235 | } |
| 236 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 237 | |
| 238 | /************************************************************************ |
| 239 | * * |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 240 | * Allocation and Freeing * |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 241 | * * |
| 242 | ************************************************************************/ |
| 243 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 244 | /** |
| 245 | * xmlNewCatalogEntry: |
| 246 | * @type: type of entry |
| 247 | * @name: name of the entry |
| 248 | * @value: value of the entry |
| 249 | * @prefer: the PUBLIC vs. SYSTEM current preference value |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 250 | * @group: for members of a group, the group entry |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 251 | * |
| 252 | * create a new Catalog entry, this type is shared both by XML and |
| 253 | * SGML catalogs, but the acceptable types values differs. |
| 254 | * |
| 255 | * Returns the xmlCatalogEntryPtr or NULL in case of error |
| 256 | */ |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 257 | static xmlCatalogEntryPtr |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 258 | xmlNewCatalogEntry(xmlCatalogEntryType type, const xmlChar *name, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 259 | const xmlChar *value, const xmlChar *URL, xmlCatalogPrefer prefer, |
| 260 | xmlCatalogEntryPtr group) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 261 | xmlCatalogEntryPtr ret; |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 262 | xmlChar *normid = NULL; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 263 | |
| 264 | ret = (xmlCatalogEntryPtr) xmlMalloc(sizeof(xmlCatalogEntry)); |
| 265 | if (ret == NULL) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 266 | xmlCatalogErrMemory("allocating catalog entry"); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 267 | return(NULL); |
| 268 | } |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 269 | ret->next = NULL; |
| 270 | ret->parent = NULL; |
| 271 | ret->children = NULL; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 272 | ret->type = type; |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 273 | if (type == XML_CATA_PUBLIC || type == XML_CATA_DELEGATE_PUBLIC) { |
| 274 | normid = xmlCatalogNormalizePublic(name); |
| 275 | if (normid != NULL) |
| 276 | name = (*normid != 0 ? normid : NULL); |
| 277 | } |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 278 | if (name != NULL) |
| 279 | ret->name = xmlStrdup(name); |
| 280 | else |
| 281 | ret->name = NULL; |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 282 | if (normid != NULL) |
| 283 | xmlFree(normid); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 284 | if (value != NULL) |
| 285 | ret->value = xmlStrdup(value); |
| 286 | else |
| 287 | ret->value = NULL; |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 288 | if (URL == NULL) |
| 289 | URL = value; |
| 290 | if (URL != NULL) |
| 291 | ret->URL = xmlStrdup(URL); |
| 292 | else |
| 293 | ret->URL = NULL; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 294 | ret->prefer = prefer; |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 295 | ret->dealloc = 0; |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 296 | ret->depth = 0; |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 297 | ret->group = group; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 298 | return(ret); |
| 299 | } |
| 300 | |
| 301 | static void |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 302 | xmlFreeCatalogEntryList(xmlCatalogEntryPtr ret); |
| 303 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 304 | /** |
| 305 | * xmlFreeCatalogEntry: |
| 306 | * @ret: a Catalog entry |
| 307 | * |
| 308 | * Free the memory allocated to a Catalog entry |
| 309 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 310 | static void |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 311 | xmlFreeCatalogEntry(xmlCatalogEntryPtr ret) { |
| 312 | if (ret == NULL) |
| 313 | return; |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 314 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 315 | * Entries stored in the file hash must be deallocated |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 316 | * only by the file hash cleaner ! |
| 317 | */ |
| 318 | if (ret->dealloc == 1) |
| 319 | return; |
| 320 | |
| 321 | if (xmlDebugCatalogs) { |
| 322 | if (ret->name != NULL) |
| 323 | xmlGenericError(xmlGenericErrorContext, |
| 324 | "Free catalog entry %s\n", ret->name); |
| 325 | else if (ret->value != NULL) |
| 326 | xmlGenericError(xmlGenericErrorContext, |
| 327 | "Free catalog entry %s\n", ret->value); |
| 328 | else |
| 329 | xmlGenericError(xmlGenericErrorContext, |
| 330 | "Free catalog entry\n"); |
| 331 | } |
| 332 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 333 | if (ret->name != NULL) |
| 334 | xmlFree(ret->name); |
| 335 | if (ret->value != NULL) |
| 336 | xmlFree(ret->value); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 337 | if (ret->URL != NULL) |
| 338 | xmlFree(ret->URL); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 339 | xmlFree(ret); |
| 340 | } |
| 341 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 342 | /** |
| 343 | * xmlFreeCatalogEntryList: |
| 344 | * @ret: a Catalog entry list |
| 345 | * |
| 346 | * Free the memory allocated to a full chained list of Catalog entries |
| 347 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 348 | static void |
| 349 | xmlFreeCatalogEntryList(xmlCatalogEntryPtr ret) { |
| 350 | xmlCatalogEntryPtr next; |
| 351 | |
| 352 | while (ret != NULL) { |
| 353 | next = ret->next; |
| 354 | xmlFreeCatalogEntry(ret); |
| 355 | ret = next; |
| 356 | } |
| 357 | } |
| 358 | |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 359 | /** |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 360 | * xmlFreeCatalogHashEntryList: |
| 361 | * @ret: a Catalog entry list |
| 362 | * |
| 363 | * Free the memory allocated to list of Catalog entries from the |
| 364 | * catalog file hash. |
| 365 | */ |
| 366 | static void |
| 367 | xmlFreeCatalogHashEntryList(xmlCatalogEntryPtr catal) { |
| 368 | xmlCatalogEntryPtr children, next; |
| 369 | |
| 370 | if (catal == NULL) |
| 371 | return; |
| 372 | |
| 373 | children = catal->children; |
| 374 | while (children != NULL) { |
| 375 | next = children->next; |
| 376 | children->dealloc = 0; |
| 377 | children->children = NULL; |
| 378 | xmlFreeCatalogEntry(children); |
| 379 | children = next; |
| 380 | } |
| 381 | catal->dealloc = 0; |
| 382 | xmlFreeCatalogEntry(catal); |
| 383 | } |
| 384 | |
| 385 | /** |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 386 | * xmlCreateNewCatalog: |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 387 | * @type: type of catalog |
| 388 | * @prefer: the PUBLIC vs. SYSTEM current preference value |
| 389 | * |
| 390 | * create a new Catalog, this type is shared both by XML and |
| 391 | * SGML catalogs, but the acceptable types values differs. |
| 392 | * |
| 393 | * Returns the xmlCatalogPtr or NULL in case of error |
| 394 | */ |
| 395 | static xmlCatalogPtr |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 396 | xmlCreateNewCatalog(xmlCatalogType type, xmlCatalogPrefer prefer) { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 397 | xmlCatalogPtr ret; |
| 398 | |
| 399 | ret = (xmlCatalogPtr) xmlMalloc(sizeof(xmlCatalog)); |
| 400 | if (ret == NULL) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 401 | xmlCatalogErrMemory("allocating catalog"); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 402 | return(NULL); |
| 403 | } |
| 404 | memset(ret, 0, sizeof(xmlCatalog)); |
| 405 | ret->type = type; |
| 406 | ret->catalNr = 0; |
| 407 | ret->catalMax = XML_MAX_SGML_CATA_DEPTH; |
| 408 | ret->prefer = prefer; |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 409 | if (ret->type == XML_SGML_CATALOG_TYPE) |
| 410 | ret->sgml = xmlHashCreate(10); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 411 | return(ret); |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * xmlFreeCatalog: |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 416 | * @catal: a Catalog |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 417 | * |
| 418 | * Free the memory allocated to a Catalog |
| 419 | */ |
| 420 | void |
| 421 | xmlFreeCatalog(xmlCatalogPtr catal) { |
| 422 | if (catal == NULL) |
| 423 | return; |
| 424 | if (catal->xml != NULL) |
| 425 | xmlFreeCatalogEntryList(catal->xml); |
| 426 | if (catal->sgml != NULL) |
| 427 | xmlHashFree(catal->sgml, |
| 428 | (xmlHashDeallocator) xmlFreeCatalogEntry); |
| 429 | xmlFree(catal); |
| 430 | } |
| 431 | |
| 432 | /************************************************************************ |
| 433 | * * |
| 434 | * Serializing Catalogs * |
| 435 | * * |
| 436 | ************************************************************************/ |
| 437 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 438 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 439 | /** |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 440 | * xmlCatalogDumpEntry: |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 441 | * @entry: the catalog entry |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 442 | * @out: the file. |
| 443 | * |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 444 | * Serialize an SGML Catalog entry |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 445 | */ |
| 446 | static void |
| 447 | xmlCatalogDumpEntry(xmlCatalogEntryPtr entry, FILE *out) { |
| 448 | if ((entry == NULL) || (out == NULL)) |
| 449 | return; |
| 450 | switch (entry->type) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 451 | case SGML_CATA_ENTITY: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 452 | fprintf(out, "ENTITY "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 453 | case SGML_CATA_PENTITY: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 454 | fprintf(out, "ENTITY %%"); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 455 | case SGML_CATA_DOCTYPE: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 456 | fprintf(out, "DOCTYPE "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 457 | case SGML_CATA_LINKTYPE: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 458 | fprintf(out, "LINKTYPE "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 459 | case SGML_CATA_NOTATION: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 460 | fprintf(out, "NOTATION "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 461 | case SGML_CATA_PUBLIC: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 462 | fprintf(out, "PUBLIC "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 463 | case SGML_CATA_SYSTEM: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 464 | fprintf(out, "SYSTEM "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 465 | case SGML_CATA_DELEGATE: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 466 | fprintf(out, "DELEGATE "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 467 | case SGML_CATA_BASE: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 468 | fprintf(out, "BASE "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 469 | case SGML_CATA_CATALOG: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 470 | fprintf(out, "CATALOG "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 471 | case SGML_CATA_DOCUMENT: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 472 | fprintf(out, "DOCUMENT "); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 473 | case SGML_CATA_SGMLDECL: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 474 | fprintf(out, "SGMLDECL "); break; |
| 475 | default: |
| 476 | return; |
| 477 | } |
| 478 | switch (entry->type) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 479 | case SGML_CATA_ENTITY: |
| 480 | case SGML_CATA_PENTITY: |
| 481 | case SGML_CATA_DOCTYPE: |
| 482 | case SGML_CATA_LINKTYPE: |
| 483 | case SGML_CATA_NOTATION: |
Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 484 | fprintf(out, "%s", (const char *) entry->name); break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 485 | case SGML_CATA_PUBLIC: |
| 486 | case SGML_CATA_SYSTEM: |
| 487 | case SGML_CATA_SGMLDECL: |
| 488 | case SGML_CATA_DOCUMENT: |
| 489 | case SGML_CATA_CATALOG: |
| 490 | case SGML_CATA_BASE: |
| 491 | case SGML_CATA_DELEGATE: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 492 | fprintf(out, "\"%s\"", entry->name); break; |
| 493 | default: |
| 494 | break; |
| 495 | } |
| 496 | switch (entry->type) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 497 | case SGML_CATA_ENTITY: |
| 498 | case SGML_CATA_PENTITY: |
| 499 | case SGML_CATA_DOCTYPE: |
| 500 | case SGML_CATA_LINKTYPE: |
| 501 | case SGML_CATA_NOTATION: |
| 502 | case SGML_CATA_PUBLIC: |
| 503 | case SGML_CATA_SYSTEM: |
| 504 | case SGML_CATA_DELEGATE: |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 505 | fprintf(out, " \"%s\"", entry->value); break; |
| 506 | default: |
| 507 | break; |
| 508 | } |
| 509 | fprintf(out, "\n"); |
| 510 | } |
| 511 | |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 512 | /** |
| 513 | * xmlDumpXMLCatalogNode: |
| 514 | * @catal: top catalog entry |
| 515 | * @catalog: pointer to the xml tree |
| 516 | * @doc: the containing document |
| 517 | * @ns: the current namespace |
| 518 | * @cgroup: group node for group members |
| 519 | * |
| 520 | * Serializes a Catalog entry, called by xmlDumpXMLCatalog and recursively |
| 521 | * for group entries |
| 522 | */ |
| 523 | static void xmlDumpXMLCatalogNode(xmlCatalogEntryPtr catal, xmlNodePtr catalog, |
| 524 | xmlDocPtr doc, xmlNsPtr ns, xmlCatalogEntryPtr cgroup) { |
| 525 | xmlNodePtr node; |
| 526 | xmlCatalogEntryPtr cur; |
| 527 | /* |
| 528 | * add all the catalog entries |
| 529 | */ |
| 530 | cur = catal; |
| 531 | while (cur != NULL) { |
| 532 | if (cur->group == cgroup) { |
| 533 | switch (cur->type) { |
| 534 | case XML_CATA_REMOVED: |
| 535 | break; |
| 536 | case XML_CATA_BROKEN_CATALOG: |
| 537 | case XML_CATA_CATALOG: |
| 538 | if (cur == catal) { |
| 539 | cur = cur->children; |
| 540 | continue; |
| 541 | } |
| 542 | break; |
| 543 | case XML_CATA_NEXT_CATALOG: |
| 544 | node = xmlNewDocNode(doc, ns, BAD_CAST "nextCatalog", NULL); |
| 545 | xmlSetProp(node, BAD_CAST "catalog", cur->value); |
| 546 | xmlAddChild(catalog, node); |
| 547 | break; |
| 548 | case XML_CATA_NONE: |
| 549 | break; |
| 550 | case XML_CATA_GROUP: |
| 551 | node = xmlNewDocNode(doc, ns, BAD_CAST "group", NULL); |
| 552 | xmlSetProp(node, BAD_CAST "id", cur->name); |
William M. Brack | 6218b31 | 2004-10-06 17:52:32 +0000 | [diff] [blame] | 553 | if (cur->value != NULL) { |
| 554 | xmlNsPtr xns; |
| 555 | xns = xmlSearchNsByHref(doc, node, XML_XML_NAMESPACE); |
| 556 | if (xns != NULL) |
| 557 | xmlSetNsProp(node, xns, BAD_CAST "base", |
| 558 | cur->value); |
| 559 | } |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 560 | switch (cur->prefer) { |
| 561 | case XML_CATA_PREFER_NONE: |
| 562 | break; |
| 563 | case XML_CATA_PREFER_PUBLIC: |
| 564 | xmlSetProp(node, BAD_CAST "prefer", BAD_CAST "public"); |
| 565 | break; |
| 566 | case XML_CATA_PREFER_SYSTEM: |
| 567 | xmlSetProp(node, BAD_CAST "prefer", BAD_CAST "system"); |
| 568 | break; |
| 569 | } |
| 570 | xmlDumpXMLCatalogNode(cur->next, node, doc, ns, cur); |
| 571 | xmlAddChild(catalog, node); |
| 572 | break; |
| 573 | case XML_CATA_PUBLIC: |
| 574 | node = xmlNewDocNode(doc, ns, BAD_CAST "public", NULL); |
| 575 | xmlSetProp(node, BAD_CAST "publicId", cur->name); |
| 576 | xmlSetProp(node, BAD_CAST "uri", cur->value); |
| 577 | xmlAddChild(catalog, node); |
| 578 | break; |
| 579 | case XML_CATA_SYSTEM: |
| 580 | node = xmlNewDocNode(doc, ns, BAD_CAST "system", NULL); |
| 581 | xmlSetProp(node, BAD_CAST "systemId", cur->name); |
| 582 | xmlSetProp(node, BAD_CAST "uri", cur->value); |
| 583 | xmlAddChild(catalog, node); |
| 584 | break; |
| 585 | case XML_CATA_REWRITE_SYSTEM: |
| 586 | node = xmlNewDocNode(doc, ns, BAD_CAST "rewriteSystem", NULL); |
| 587 | xmlSetProp(node, BAD_CAST "systemIdStartString", cur->name); |
| 588 | xmlSetProp(node, BAD_CAST "rewritePrefix", cur->value); |
| 589 | xmlAddChild(catalog, node); |
| 590 | break; |
| 591 | case XML_CATA_DELEGATE_PUBLIC: |
| 592 | node = xmlNewDocNode(doc, ns, BAD_CAST "delegatePublic", NULL); |
| 593 | xmlSetProp(node, BAD_CAST "publicIdStartString", cur->name); |
| 594 | xmlSetProp(node, BAD_CAST "catalog", cur->value); |
| 595 | xmlAddChild(catalog, node); |
| 596 | break; |
| 597 | case XML_CATA_DELEGATE_SYSTEM: |
| 598 | node = xmlNewDocNode(doc, ns, BAD_CAST "delegateSystem", NULL); |
| 599 | xmlSetProp(node, BAD_CAST "systemIdStartString", cur->name); |
| 600 | xmlSetProp(node, BAD_CAST "catalog", cur->value); |
| 601 | xmlAddChild(catalog, node); |
| 602 | break; |
| 603 | case XML_CATA_URI: |
| 604 | node = xmlNewDocNode(doc, ns, BAD_CAST "uri", NULL); |
| 605 | xmlSetProp(node, BAD_CAST "name", cur->name); |
| 606 | xmlSetProp(node, BAD_CAST "uri", cur->value); |
| 607 | xmlAddChild(catalog, node); |
| 608 | break; |
| 609 | case XML_CATA_REWRITE_URI: |
| 610 | node = xmlNewDocNode(doc, ns, BAD_CAST "rewriteURI", NULL); |
| 611 | xmlSetProp(node, BAD_CAST "uriStartString", cur->name); |
| 612 | xmlSetProp(node, BAD_CAST "rewritePrefix", cur->value); |
| 613 | xmlAddChild(catalog, node); |
| 614 | break; |
| 615 | case XML_CATA_DELEGATE_URI: |
| 616 | node = xmlNewDocNode(doc, ns, BAD_CAST "delegateURI", NULL); |
| 617 | xmlSetProp(node, BAD_CAST "uriStartString", cur->name); |
| 618 | xmlSetProp(node, BAD_CAST "catalog", cur->value); |
| 619 | xmlAddChild(catalog, node); |
| 620 | break; |
| 621 | case SGML_CATA_SYSTEM: |
| 622 | case SGML_CATA_PUBLIC: |
| 623 | case SGML_CATA_ENTITY: |
| 624 | case SGML_CATA_PENTITY: |
| 625 | case SGML_CATA_DOCTYPE: |
| 626 | case SGML_CATA_LINKTYPE: |
| 627 | case SGML_CATA_NOTATION: |
| 628 | case SGML_CATA_DELEGATE: |
| 629 | case SGML_CATA_BASE: |
| 630 | case SGML_CATA_CATALOG: |
| 631 | case SGML_CATA_DOCUMENT: |
| 632 | case SGML_CATA_SGMLDECL: |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | cur = cur->next; |
| 637 | } |
| 638 | } |
| 639 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 640 | static int |
| 641 | xmlDumpXMLCatalog(FILE *out, xmlCatalogEntryPtr catal) { |
| 642 | int ret; |
| 643 | xmlDocPtr doc; |
| 644 | xmlNsPtr ns; |
| 645 | xmlDtdPtr dtd; |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 646 | xmlNodePtr catalog; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 647 | xmlOutputBufferPtr buf; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * Rebuild a catalog |
| 651 | */ |
| 652 | doc = xmlNewDoc(NULL); |
| 653 | if (doc == NULL) |
| 654 | return(-1); |
| 655 | dtd = xmlNewDtd(doc, BAD_CAST "catalog", |
| 656 | BAD_CAST "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN", |
| 657 | BAD_CAST "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"); |
| 658 | |
| 659 | xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd); |
| 660 | |
| 661 | ns = xmlNewNs(NULL, XML_CATALOGS_NAMESPACE, NULL); |
| 662 | if (ns == NULL) { |
| 663 | xmlFreeDoc(doc); |
| 664 | return(-1); |
| 665 | } |
| 666 | catalog = xmlNewDocNode(doc, ns, BAD_CAST "catalog", NULL); |
| 667 | if (catalog == NULL) { |
| 668 | xmlFreeNs(ns); |
| 669 | xmlFreeDoc(doc); |
| 670 | return(-1); |
| 671 | } |
| 672 | catalog->nsDef = ns; |
| 673 | xmlAddChild((xmlNodePtr) doc, catalog); |
| 674 | |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 675 | xmlDumpXMLCatalogNode(catal, catalog, doc, ns, NULL); |
| 676 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 677 | /* |
| 678 | * reserialize it |
| 679 | */ |
| 680 | buf = xmlOutputBufferCreateFile(out, NULL); |
| 681 | if (buf == NULL) { |
| 682 | xmlFreeDoc(doc); |
| 683 | return(-1); |
| 684 | } |
| 685 | ret = xmlSaveFormatFileTo(buf, doc, NULL, 1); |
| 686 | |
| 687 | /* |
| 688 | * Free it |
| 689 | */ |
| 690 | xmlFreeDoc(doc); |
| 691 | |
| 692 | return(ret); |
| 693 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 694 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 695 | |
| 696 | /************************************************************************ |
| 697 | * * |
| 698 | * Converting SGML Catalogs to XML * |
| 699 | * * |
| 700 | ************************************************************************/ |
| 701 | |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 702 | /** |
| 703 | * xmlCatalogConvertEntry: |
| 704 | * @entry: the entry |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 705 | * @catal: pointer to the catalog being converted |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 706 | * |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 707 | * Convert one entry from the catalog |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 708 | */ |
| 709 | static void |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 710 | xmlCatalogConvertEntry(xmlCatalogEntryPtr entry, xmlCatalogPtr catal) { |
| 711 | if ((entry == NULL) || (catal == NULL) || (catal->sgml == NULL) || |
| 712 | (catal->xml == NULL)) |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 713 | return; |
| 714 | switch (entry->type) { |
| 715 | case SGML_CATA_ENTITY: |
| 716 | entry->type = XML_CATA_PUBLIC; |
| 717 | break; |
| 718 | case SGML_CATA_PENTITY: |
| 719 | entry->type = XML_CATA_PUBLIC; |
| 720 | break; |
| 721 | case SGML_CATA_DOCTYPE: |
| 722 | entry->type = XML_CATA_PUBLIC; |
| 723 | break; |
| 724 | case SGML_CATA_LINKTYPE: |
| 725 | entry->type = XML_CATA_PUBLIC; |
| 726 | break; |
| 727 | case SGML_CATA_NOTATION: |
| 728 | entry->type = XML_CATA_PUBLIC; |
| 729 | break; |
| 730 | case SGML_CATA_PUBLIC: |
| 731 | entry->type = XML_CATA_PUBLIC; |
| 732 | break; |
| 733 | case SGML_CATA_SYSTEM: |
| 734 | entry->type = XML_CATA_SYSTEM; |
| 735 | break; |
| 736 | case SGML_CATA_DELEGATE: |
| 737 | entry->type = XML_CATA_DELEGATE_PUBLIC; |
| 738 | break; |
| 739 | case SGML_CATA_CATALOG: |
| 740 | entry->type = XML_CATA_CATALOG; |
| 741 | break; |
| 742 | default: |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 743 | xmlHashRemoveEntry(catal->sgml, entry->name, |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 744 | (xmlHashDeallocator) xmlFreeCatalogEntry); |
| 745 | return; |
| 746 | } |
| 747 | /* |
| 748 | * Conversion successful, remove from the SGML catalog |
| 749 | * and add it to the default XML one |
| 750 | */ |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 751 | xmlHashRemoveEntry(catal->sgml, entry->name, NULL); |
| 752 | entry->parent = catal->xml; |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 753 | entry->next = NULL; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 754 | if (catal->xml->children == NULL) |
| 755 | catal->xml->children = entry; |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 756 | else { |
| 757 | xmlCatalogEntryPtr prev; |
| 758 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 759 | prev = catal->xml->children; |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 760 | while (prev->next != NULL) |
| 761 | prev = prev->next; |
| 762 | prev->next = entry; |
| 763 | } |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
| 767 | * xmlConvertSGMLCatalog: |
| 768 | * @catal: the catalog |
| 769 | * |
| 770 | * Convert all the SGML catalog entries as XML ones |
| 771 | * |
| 772 | * Returns the number of entries converted if successful, -1 otherwise |
| 773 | */ |
| 774 | int |
| 775 | xmlConvertSGMLCatalog(xmlCatalogPtr catal) { |
| 776 | |
| 777 | if ((catal == NULL) || (catal->type != XML_SGML_CATALOG_TYPE)) |
| 778 | return(-1); |
| 779 | |
| 780 | if (xmlDebugCatalogs) { |
| 781 | xmlGenericError(xmlGenericErrorContext, |
| 782 | "Converting SGML catalog to XML\n"); |
| 783 | } |
| 784 | xmlHashScan(catal->sgml, |
| 785 | (xmlHashScanner) xmlCatalogConvertEntry, |
| 786 | &catal); |
| 787 | return(0); |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 790 | /************************************************************************ |
| 791 | * * |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 792 | * Helper function * |
| 793 | * * |
| 794 | ************************************************************************/ |
| 795 | |
| 796 | /** |
| 797 | * xmlCatalogUnWrapURN: |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 798 | * @urn: an "urn:publicid:" to unwrap |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 799 | * |
| 800 | * Expand the URN into the equivalent Public Identifier |
| 801 | * |
| 802 | * Returns the new identifier or NULL, the string must be deallocated |
| 803 | * by the caller. |
| 804 | */ |
| 805 | static xmlChar * |
| 806 | xmlCatalogUnWrapURN(const xmlChar *urn) { |
| 807 | xmlChar result[2000]; |
| 808 | unsigned int i = 0; |
| 809 | |
| 810 | if (xmlStrncmp(urn, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) |
| 811 | return(NULL); |
| 812 | urn += sizeof(XML_URN_PUBID) - 1; |
| 813 | |
| 814 | while (*urn != 0) { |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 815 | if (i > sizeof(result) - 4) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 816 | break; |
| 817 | if (*urn == '+') { |
| 818 | result[i++] = ' '; |
| 819 | urn++; |
| 820 | } else if (*urn == ':') { |
| 821 | result[i++] = '/'; |
| 822 | result[i++] = '/'; |
| 823 | urn++; |
| 824 | } else if (*urn == ';') { |
| 825 | result[i++] = ':'; |
| 826 | result[i++] = ':'; |
| 827 | urn++; |
| 828 | } else if (*urn == '%') { |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 829 | if ((urn[1] == '2') && (urn[2] == 'B')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 830 | result[i++] = '+'; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 831 | else if ((urn[1] == '3') && (urn[2] == 'A')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 832 | result[i++] = ':'; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 833 | else if ((urn[1] == '2') && (urn[2] == 'F')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 834 | result[i++] = '/'; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 835 | else if ((urn[1] == '3') && (urn[2] == 'B')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 836 | result[i++] = ';'; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 837 | else if ((urn[1] == '2') && (urn[2] == '7')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 838 | result[i++] = '\''; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 839 | else if ((urn[1] == '3') && (urn[2] == 'F')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 840 | result[i++] = '?'; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 841 | else if ((urn[1] == '2') && (urn[2] == '3')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 842 | result[i++] = '#'; |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 843 | else if ((urn[1] == '2') && (urn[2] == '5')) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 844 | result[i++] = '%'; |
| 845 | else { |
| 846 | result[i++] = *urn; |
| 847 | urn++; |
| 848 | continue; |
| 849 | } |
| 850 | urn += 3; |
| 851 | } else { |
| 852 | result[i++] = *urn; |
| 853 | urn++; |
| 854 | } |
| 855 | } |
| 856 | result[i] = 0; |
| 857 | |
| 858 | return(xmlStrdup(result)); |
| 859 | } |
| 860 | |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 861 | /** |
| 862 | * xmlParseCatalogFile: |
| 863 | * @filename: the filename |
| 864 | * |
| 865 | * parse an XML file and build a tree. It's like xmlParseFile() |
| 866 | * except it bypass all catalog lookups. |
| 867 | * |
| 868 | * Returns the resulting document tree or NULL in case of error |
| 869 | */ |
| 870 | |
| 871 | xmlDocPtr |
| 872 | xmlParseCatalogFile(const char *filename) { |
| 873 | xmlDocPtr ret; |
| 874 | xmlParserCtxtPtr ctxt; |
| 875 | char *directory = NULL; |
| 876 | xmlParserInputPtr inputStream; |
| 877 | xmlParserInputBufferPtr buf; |
| 878 | |
| 879 | ctxt = xmlNewParserCtxt(); |
| 880 | if (ctxt == NULL) { |
| 881 | if (xmlDefaultSAXHandler.error != NULL) { |
| 882 | xmlDefaultSAXHandler.error(NULL, "out of memory\n"); |
| 883 | } |
| 884 | return(NULL); |
| 885 | } |
| 886 | |
| 887 | buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
| 888 | if (buf == NULL) { |
| 889 | xmlFreeParserCtxt(ctxt); |
| 890 | return(NULL); |
| 891 | } |
| 892 | |
| 893 | inputStream = xmlNewInputStream(ctxt); |
| 894 | if (inputStream == NULL) { |
| 895 | xmlFreeParserCtxt(ctxt); |
| 896 | return(NULL); |
| 897 | } |
| 898 | |
Daniel Veillard | c3ca5ba | 2003-05-09 22:26:28 +0000 | [diff] [blame] | 899 | inputStream->filename = (char *) xmlCanonicPath((const xmlChar *)filename); |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 900 | inputStream->buf = buf; |
| 901 | inputStream->base = inputStream->buf->buffer->content; |
| 902 | inputStream->cur = inputStream->buf->buffer->content; |
| 903 | inputStream->end = |
| 904 | &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; |
| 905 | |
| 906 | inputPush(ctxt, inputStream); |
| 907 | if ((ctxt->directory == NULL) && (directory == NULL)) |
| 908 | directory = xmlParserGetDirectory(filename); |
| 909 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 910 | ctxt->directory = directory; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 911 | ctxt->valid = 0; |
| 912 | ctxt->validate = 0; |
| 913 | ctxt->loadsubset = 0; |
| 914 | ctxt->pedantic = 0; |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 915 | |
| 916 | xmlParseDocument(ctxt); |
| 917 | |
| 918 | if (ctxt->wellFormed) |
| 919 | ret = ctxt->myDoc; |
| 920 | else { |
| 921 | ret = NULL; |
| 922 | xmlFreeDoc(ctxt->myDoc); |
| 923 | ctxt->myDoc = NULL; |
| 924 | } |
| 925 | xmlFreeParserCtxt(ctxt); |
| 926 | |
| 927 | return(ret); |
| 928 | } |
| 929 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 930 | /** |
| 931 | * xmlLoadFileContent: |
| 932 | * @filename: a file path |
| 933 | * |
| 934 | * Load a file content into memory. |
| 935 | * |
| 936 | * Returns a pointer to the 0 terminated string or NULL in case of error |
| 937 | */ |
| 938 | static xmlChar * |
| 939 | xmlLoadFileContent(const char *filename) |
| 940 | { |
| 941 | #ifdef HAVE_STAT |
| 942 | int fd; |
| 943 | #else |
| 944 | FILE *fd; |
| 945 | #endif |
| 946 | int len; |
| 947 | long size; |
| 948 | |
| 949 | #ifdef HAVE_STAT |
| 950 | struct stat info; |
| 951 | #endif |
| 952 | xmlChar *content; |
| 953 | |
| 954 | if (filename == NULL) |
| 955 | return (NULL); |
| 956 | |
| 957 | #ifdef HAVE_STAT |
| 958 | if (stat(filename, &info) < 0) |
| 959 | return (NULL); |
| 960 | #endif |
| 961 | |
| 962 | #ifdef HAVE_STAT |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 963 | if ((fd = open(filename, O_RDONLY)) < 0) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 964 | #else |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 965 | if ((fd = fopen(filename, "rb")) == NULL) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 966 | #endif |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 967 | { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 968 | return (NULL); |
| 969 | } |
| 970 | #ifdef HAVE_STAT |
| 971 | size = info.st_size; |
| 972 | #else |
| 973 | if (fseek(fd, 0, SEEK_END) || (size = ftell(fd)) == EOF || fseek(fd, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */ |
| 974 | fclose(fd); |
| 975 | return (NULL); |
| 976 | } |
| 977 | #endif |
Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 978 | content = xmlMallocAtomic(size + 10); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 979 | if (content == NULL) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 980 | xmlCatalogErrMemory("allocating catalog data"); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 981 | return (NULL); |
| 982 | } |
| 983 | #ifdef HAVE_STAT |
| 984 | len = read(fd, content, size); |
| 985 | #else |
| 986 | len = fread(content, 1, size, fd); |
| 987 | #endif |
| 988 | if (len < 0) { |
| 989 | xmlFree(content); |
| 990 | return (NULL); |
| 991 | } |
| 992 | #ifdef HAVE_STAT |
| 993 | close(fd); |
| 994 | #else |
| 995 | fclose(fd); |
| 996 | #endif |
| 997 | content[len] = 0; |
| 998 | |
| 999 | return(content); |
| 1000 | } |
| 1001 | |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 1002 | /** |
| 1003 | * xmlCatalogNormalizePublic: |
| 1004 | * @pubID: the public ID string |
| 1005 | * |
| 1006 | * Normalizes the Public Identifier |
| 1007 | * |
| 1008 | * Implements 6.2. Public Identifier Normalization |
| 1009 | * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html |
| 1010 | * |
| 1011 | * Returns the new string or NULL, the string must be deallocated |
| 1012 | * by the caller. |
| 1013 | */ |
| 1014 | static xmlChar * |
| 1015 | xmlCatalogNormalizePublic(const xmlChar *pubID) |
| 1016 | { |
| 1017 | int ok = 1; |
| 1018 | int white; |
| 1019 | const xmlChar *p; |
| 1020 | xmlChar *ret; |
| 1021 | xmlChar *q; |
| 1022 | |
| 1023 | if (pubID == NULL) |
| 1024 | return(NULL); |
| 1025 | |
| 1026 | white = 1; |
| 1027 | for (p = pubID;*p != 0 && ok;p++) { |
| 1028 | if (!xmlIsBlank_ch(*p)) |
| 1029 | white = 0; |
| 1030 | else if (*p == 0x20 && !white) |
| 1031 | white = 1; |
| 1032 | else |
| 1033 | ok = 0; |
| 1034 | } |
| 1035 | if (ok && !white) /* is normalized */ |
| 1036 | return(NULL); |
| 1037 | |
| 1038 | ret = xmlStrdup(pubID); |
| 1039 | q = ret; |
| 1040 | white = 0; |
| 1041 | for (p = pubID;*p != 0;p++) { |
| 1042 | if (xmlIsBlank_ch(*p)) { |
| 1043 | if (q != ret) |
| 1044 | white = 1; |
| 1045 | } else { |
| 1046 | if (white) { |
| 1047 | *(q++) = 0x20; |
| 1048 | white = 0; |
| 1049 | } |
| 1050 | *(q++) = *p; |
| 1051 | } |
| 1052 | } |
| 1053 | *q = 0; |
| 1054 | return(ret); |
| 1055 | } |
| 1056 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1057 | /************************************************************************ |
| 1058 | * * |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1059 | * The XML Catalog parser * |
| 1060 | * * |
| 1061 | ************************************************************************/ |
| 1062 | |
| 1063 | static xmlCatalogEntryPtr |
| 1064 | xmlParseXMLCatalogFile(xmlCatalogPrefer prefer, const xmlChar *filename); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1065 | static void |
| 1066 | xmlParseXMLCatalogNodeList(xmlNodePtr cur, xmlCatalogPrefer prefer, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1067 | xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1068 | static xmlChar * |
| 1069 | xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, |
| 1070 | const xmlChar *sysID); |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1071 | static xmlChar * |
| 1072 | xmlCatalogListXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI); |
| 1073 | |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1074 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1075 | /** |
| 1076 | * xmlGetXMLCatalogEntryType: |
| 1077 | * @name: the name |
| 1078 | * |
| 1079 | * lookup the internal type associated to an XML catalog entry name |
| 1080 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 1081 | * Returns the type associated with that name |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1082 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1083 | static xmlCatalogEntryType |
| 1084 | xmlGetXMLCatalogEntryType(const xmlChar *name) { |
| 1085 | xmlCatalogEntryType type = XML_CATA_NONE; |
| 1086 | if (xmlStrEqual(name, (const xmlChar *) "system")) |
| 1087 | type = XML_CATA_SYSTEM; |
| 1088 | else if (xmlStrEqual(name, (const xmlChar *) "public")) |
| 1089 | type = XML_CATA_PUBLIC; |
| 1090 | else if (xmlStrEqual(name, (const xmlChar *) "rewriteSystem")) |
| 1091 | type = XML_CATA_REWRITE_SYSTEM; |
| 1092 | else if (xmlStrEqual(name, (const xmlChar *) "delegatePublic")) |
| 1093 | type = XML_CATA_DELEGATE_PUBLIC; |
| 1094 | else if (xmlStrEqual(name, (const xmlChar *) "delegateSystem")) |
| 1095 | type = XML_CATA_DELEGATE_SYSTEM; |
| 1096 | else if (xmlStrEqual(name, (const xmlChar *) "uri")) |
| 1097 | type = XML_CATA_URI; |
| 1098 | else if (xmlStrEqual(name, (const xmlChar *) "rewriteURI")) |
| 1099 | type = XML_CATA_REWRITE_URI; |
| 1100 | else if (xmlStrEqual(name, (const xmlChar *) "delegateURI")) |
| 1101 | type = XML_CATA_DELEGATE_URI; |
| 1102 | else if (xmlStrEqual(name, (const xmlChar *) "nextCatalog")) |
| 1103 | type = XML_CATA_NEXT_CATALOG; |
| 1104 | else if (xmlStrEqual(name, (const xmlChar *) "catalog")) |
| 1105 | type = XML_CATA_CATALOG; |
| 1106 | return(type); |
| 1107 | } |
| 1108 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1109 | /** |
| 1110 | * xmlParseXMLCatalogOneNode: |
| 1111 | * @cur: the XML node |
| 1112 | * @type: the type of Catalog entry |
| 1113 | * @name: the name of the node |
| 1114 | * @attrName: the attribute holding the value |
| 1115 | * @uriAttrName: the attribute holding the URI-Reference |
| 1116 | * @prefer: the PUBLIC vs. SYSTEM current preference value |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1117 | * @cgroup: the group which includes this node |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1118 | * |
| 1119 | * Finishes the examination of an XML tree node of a catalog and build |
| 1120 | * a Catalog entry from it. |
| 1121 | * |
| 1122 | * Returns the new Catalog entry node or NULL in case of error. |
| 1123 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1124 | static xmlCatalogEntryPtr |
| 1125 | xmlParseXMLCatalogOneNode(xmlNodePtr cur, xmlCatalogEntryType type, |
| 1126 | const xmlChar *name, const xmlChar *attrName, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1127 | const xmlChar *uriAttrName, xmlCatalogPrefer prefer, |
| 1128 | xmlCatalogEntryPtr cgroup) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1129 | int ok = 1; |
| 1130 | xmlChar *uriValue; |
| 1131 | xmlChar *nameValue = NULL; |
| 1132 | xmlChar *base = NULL; |
| 1133 | xmlChar *URL = NULL; |
| 1134 | xmlCatalogEntryPtr ret = NULL; |
| 1135 | |
| 1136 | if (attrName != NULL) { |
| 1137 | nameValue = xmlGetProp(cur, attrName); |
| 1138 | if (nameValue == NULL) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1139 | xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR, |
| 1140 | "%s entry lacks '%s'\n", name, attrName, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1141 | ok = 0; |
| 1142 | } |
| 1143 | } |
| 1144 | uriValue = xmlGetProp(cur, uriAttrName); |
| 1145 | if (uriValue == NULL) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1146 | xmlCatalogErr(ret, cur, XML_CATALOG_MISSING_ATTR, |
| 1147 | "%s entry lacks '%s'\n", name, uriAttrName, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1148 | ok = 0; |
| 1149 | } |
| 1150 | if (!ok) { |
| 1151 | if (nameValue != NULL) |
| 1152 | xmlFree(nameValue); |
| 1153 | if (uriValue != NULL) |
| 1154 | xmlFree(uriValue); |
| 1155 | return(NULL); |
| 1156 | } |
| 1157 | |
| 1158 | base = xmlNodeGetBase(cur->doc, cur); |
| 1159 | URL = xmlBuildURI(uriValue, base); |
| 1160 | if (URL != NULL) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1161 | if (xmlDebugCatalogs > 1) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1162 | if (nameValue != NULL) |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1163 | xmlGenericError(xmlGenericErrorContext, |
| 1164 | "Found %s: '%s' '%s'\n", name, nameValue, URL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1165 | else |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1166 | xmlGenericError(xmlGenericErrorContext, |
| 1167 | "Found %s: '%s'\n", name, URL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1168 | } |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1169 | ret = xmlNewCatalogEntry(type, nameValue, uriValue, URL, prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1170 | } else { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1171 | xmlCatalogErr(ret, cur, XML_CATALOG_ENTRY_BROKEN, |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1172 | "%s entry '%s' broken ?: %s\n", name, uriAttrName, uriValue); |
| 1173 | } |
| 1174 | if (nameValue != NULL) |
| 1175 | xmlFree(nameValue); |
| 1176 | if (uriValue != NULL) |
| 1177 | xmlFree(uriValue); |
| 1178 | if (base != NULL) |
| 1179 | xmlFree(base); |
| 1180 | if (URL != NULL) |
| 1181 | xmlFree(URL); |
| 1182 | return(ret); |
| 1183 | } |
| 1184 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1185 | /** |
| 1186 | * xmlParseXMLCatalogNode: |
| 1187 | * @cur: the XML node |
| 1188 | * @prefer: the PUBLIC vs. SYSTEM current preference value |
| 1189 | * @parent: the parent Catalog entry |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1190 | * @cgroup: the group which includes this node |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1191 | * |
| 1192 | * Examines an XML tree node of a catalog and build |
| 1193 | * a Catalog entry from it adding it to its parent. The examination can |
| 1194 | * be recursive. |
| 1195 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1196 | static void |
| 1197 | xmlParseXMLCatalogNode(xmlNodePtr cur, xmlCatalogPrefer prefer, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1198 | xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1199 | { |
| 1200 | xmlChar *uri = NULL; |
| 1201 | xmlChar *URL = NULL; |
| 1202 | xmlChar *base = NULL; |
| 1203 | xmlCatalogEntryPtr entry = NULL; |
| 1204 | |
| 1205 | if (cur == NULL) |
| 1206 | return; |
| 1207 | if (xmlStrEqual(cur->name, BAD_CAST "group")) { |
| 1208 | xmlChar *prop; |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1209 | xmlCatalogPrefer pref = XML_CATA_PREFER_NONE; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1210 | |
| 1211 | prop = xmlGetProp(cur, BAD_CAST "prefer"); |
| 1212 | if (prop != NULL) { |
| 1213 | if (xmlStrEqual(prop, BAD_CAST "system")) { |
| 1214 | prefer = XML_CATA_PREFER_SYSTEM; |
| 1215 | } else if (xmlStrEqual(prop, BAD_CAST "public")) { |
| 1216 | prefer = XML_CATA_PREFER_PUBLIC; |
| 1217 | } else { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1218 | xmlCatalogErr(parent, cur, XML_CATALOG_PREFER_VALUE, |
| 1219 | "Invalid value for prefer: '%s'\n", |
| 1220 | prop, NULL, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1221 | } |
| 1222 | xmlFree(prop); |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1223 | pref = prefer; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1224 | } |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1225 | prop = xmlGetProp(cur, BAD_CAST "id"); |
| 1226 | base = xmlGetNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE); |
| 1227 | entry = xmlNewCatalogEntry(XML_CATA_GROUP, prop, base, NULL, pref, cgroup); |
William M. Brack | 181a1ca | 2004-10-06 18:00:29 +0000 | [diff] [blame^] | 1228 | xmlFree(prop); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1229 | } else if (xmlStrEqual(cur->name, BAD_CAST "public")) { |
| 1230 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_PUBLIC, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1231 | BAD_CAST "public", BAD_CAST "publicId", BAD_CAST "uri", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1232 | } else if (xmlStrEqual(cur->name, BAD_CAST "system")) { |
| 1233 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_SYSTEM, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1234 | BAD_CAST "system", BAD_CAST "systemId", BAD_CAST "uri", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1235 | } else if (xmlStrEqual(cur->name, BAD_CAST "rewriteSystem")) { |
| 1236 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_REWRITE_SYSTEM, |
| 1237 | BAD_CAST "rewriteSystem", BAD_CAST "systemIdStartString", |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1238 | BAD_CAST "rewritePrefix", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1239 | } else if (xmlStrEqual(cur->name, BAD_CAST "delegatePublic")) { |
| 1240 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_DELEGATE_PUBLIC, |
| 1241 | BAD_CAST "delegatePublic", BAD_CAST "publicIdStartString", |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1242 | BAD_CAST "catalog", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1243 | } else if (xmlStrEqual(cur->name, BAD_CAST "delegateSystem")) { |
| 1244 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_DELEGATE_SYSTEM, |
| 1245 | BAD_CAST "delegateSystem", BAD_CAST "systemIdStartString", |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1246 | BAD_CAST "catalog", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1247 | } else if (xmlStrEqual(cur->name, BAD_CAST "uri")) { |
| 1248 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_URI, |
| 1249 | BAD_CAST "uri", BAD_CAST "name", |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1250 | BAD_CAST "uri", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1251 | } else if (xmlStrEqual(cur->name, BAD_CAST "rewriteURI")) { |
| 1252 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_REWRITE_URI, |
| 1253 | BAD_CAST "rewriteURI", BAD_CAST "uriStartString", |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1254 | BAD_CAST "rewritePrefix", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1255 | } else if (xmlStrEqual(cur->name, BAD_CAST "delegateURI")) { |
| 1256 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_DELEGATE_URI, |
| 1257 | BAD_CAST "delegateURI", BAD_CAST "uriStartString", |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1258 | BAD_CAST "catalog", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1259 | } else if (xmlStrEqual(cur->name, BAD_CAST "nextCatalog")) { |
| 1260 | entry = xmlParseXMLCatalogOneNode(cur, XML_CATA_NEXT_CATALOG, |
| 1261 | BAD_CAST "nextCatalog", NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1262 | BAD_CAST "catalog", prefer, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1263 | } |
| 1264 | if ((entry != NULL) && (parent != NULL)) { |
| 1265 | entry->parent = parent; |
| 1266 | if (parent->children == NULL) |
| 1267 | parent->children = entry; |
| 1268 | else { |
| 1269 | xmlCatalogEntryPtr prev; |
| 1270 | |
| 1271 | prev = parent->children; |
| 1272 | while (prev->next != NULL) |
| 1273 | prev = prev->next; |
| 1274 | prev->next = entry; |
| 1275 | } |
| 1276 | } |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1277 | if (entry->type == XML_CATA_GROUP) { |
| 1278 | /* |
| 1279 | * Recurse to propagate prefer to the subtree |
| 1280 | * (xml:base handling is automated) |
| 1281 | */ |
| 1282 | xmlParseXMLCatalogNodeList(cur->children, prefer, parent, entry); |
| 1283 | } |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1284 | if (base != NULL) |
| 1285 | xmlFree(base); |
| 1286 | if (uri != NULL) |
| 1287 | xmlFree(uri); |
| 1288 | if (URL != NULL) |
| 1289 | xmlFree(URL); |
| 1290 | } |
| 1291 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1292 | /** |
| 1293 | * xmlParseXMLCatalogNodeList: |
| 1294 | * @cur: the XML node list of siblings |
| 1295 | * @prefer: the PUBLIC vs. SYSTEM current preference value |
| 1296 | * @parent: the parent Catalog entry |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1297 | * @cgroup: the group which includes this list |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1298 | * |
| 1299 | * Examines a list of XML sibling nodes of a catalog and build |
| 1300 | * a list of Catalog entry from it adding it to the parent. |
| 1301 | * The examination will recurse to examine node subtrees. |
| 1302 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1303 | static void |
| 1304 | xmlParseXMLCatalogNodeList(xmlNodePtr cur, xmlCatalogPrefer prefer, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1305 | xmlCatalogEntryPtr parent, xmlCatalogEntryPtr cgroup) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1306 | while (cur != NULL) { |
| 1307 | if ((cur->ns != NULL) && (cur->ns->href != NULL) && |
| 1308 | (xmlStrEqual(cur->ns->href, XML_CATALOGS_NAMESPACE))) { |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1309 | xmlParseXMLCatalogNode(cur, prefer, parent, cgroup); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1310 | } |
| 1311 | cur = cur->next; |
| 1312 | } |
| 1313 | /* TODO: sort the list according to REWRITE lengths and prefer value */ |
| 1314 | } |
| 1315 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1316 | /** |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1317 | * xmlParseXMLCatalogFile: |
| 1318 | * @prefer: the PUBLIC vs. SYSTEM current preference value |
| 1319 | * @filename: the filename for the catalog |
| 1320 | * |
| 1321 | * Parses the catalog file to extract the XML tree and then analyze the |
| 1322 | * tree to build a list of Catalog entries corresponding to this catalog |
| 1323 | * |
| 1324 | * Returns the resulting Catalog entries list |
| 1325 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1326 | static xmlCatalogEntryPtr |
| 1327 | xmlParseXMLCatalogFile(xmlCatalogPrefer prefer, const xmlChar *filename) { |
| 1328 | xmlDocPtr doc; |
| 1329 | xmlNodePtr cur; |
| 1330 | xmlChar *prop; |
| 1331 | xmlCatalogEntryPtr parent = NULL; |
| 1332 | |
| 1333 | if (filename == NULL) |
| 1334 | return(NULL); |
| 1335 | |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 1336 | doc = xmlParseCatalogFile((const char *) filename); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1337 | if (doc == NULL) { |
| 1338 | if (xmlDebugCatalogs) |
| 1339 | xmlGenericError(xmlGenericErrorContext, |
| 1340 | "Failed to parse catalog %s\n", filename); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1341 | return(NULL); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | if (xmlDebugCatalogs) |
| 1345 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 1346 | "%d Parsing catalog %s\n", xmlGetThreadId(), filename); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1347 | |
| 1348 | cur = xmlDocGetRootElement(doc); |
| 1349 | if ((cur != NULL) && (xmlStrEqual(cur->name, BAD_CAST "catalog")) && |
| 1350 | (cur->ns != NULL) && (cur->ns->href != NULL) && |
| 1351 | (xmlStrEqual(cur->ns->href, XML_CATALOGS_NAMESPACE))) { |
| 1352 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1353 | parent = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1354 | (const xmlChar *)filename, NULL, prefer, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1355 | if (parent == NULL) { |
| 1356 | xmlFreeDoc(doc); |
| 1357 | return(NULL); |
| 1358 | } |
| 1359 | |
| 1360 | prop = xmlGetProp(cur, BAD_CAST "prefer"); |
| 1361 | if (prop != NULL) { |
| 1362 | if (xmlStrEqual(prop, BAD_CAST "system")) { |
| 1363 | prefer = XML_CATA_PREFER_SYSTEM; |
| 1364 | } else if (xmlStrEqual(prop, BAD_CAST "public")) { |
| 1365 | prefer = XML_CATA_PREFER_PUBLIC; |
| 1366 | } else { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1367 | xmlCatalogErr(NULL, cur, XML_CATALOG_PREFER_VALUE, |
| 1368 | "Invalid value for prefer: '%s'\n", |
| 1369 | prop, NULL, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1370 | } |
| 1371 | xmlFree(prop); |
| 1372 | } |
| 1373 | cur = cur->children; |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1374 | xmlParseXMLCatalogNodeList(cur, prefer, parent, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1375 | } else { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1376 | xmlCatalogErr(NULL, (xmlNodePtr) doc, XML_CATALOG_NOT_CATALOG, |
| 1377 | "File %s is not an XML Catalog\n", |
| 1378 | filename, NULL, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1379 | xmlFreeDoc(doc); |
| 1380 | return(NULL); |
| 1381 | } |
| 1382 | xmlFreeDoc(doc); |
| 1383 | return(parent); |
| 1384 | } |
| 1385 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1386 | /** |
| 1387 | * xmlFetchXMLCatalogFile: |
| 1388 | * @catal: an existing but incomplete catalog entry |
| 1389 | * |
| 1390 | * Fetch and parse the subcatalog referenced by an entry |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1391 | * |
| 1392 | * Returns 0 in case of success, -1 otherwise |
| 1393 | */ |
| 1394 | static int |
| 1395 | xmlFetchXMLCatalogFile(xmlCatalogEntryPtr catal) { |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1396 | xmlCatalogEntryPtr doc; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1397 | |
| 1398 | if (catal == NULL) |
| 1399 | return(-1); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1400 | if (catal->URL == NULL) |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1401 | return(-1); |
| 1402 | if (catal->children != NULL) |
| 1403 | return(-1); |
| 1404 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 1405 | /* |
| 1406 | * lock the whole catalog for modification |
| 1407 | */ |
| 1408 | xmlRMutexLock(xmlCatalogMutex); |
| 1409 | if (catal->children != NULL) { |
| 1410 | /* Okay someone else did it in the meantime */ |
| 1411 | xmlRMutexUnlock(xmlCatalogMutex); |
| 1412 | return(0); |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1415 | if (xmlCatalogXMLFiles != NULL) { |
| 1416 | doc = (xmlCatalogEntryPtr) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1417 | xmlHashLookup(xmlCatalogXMLFiles, catal->URL); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1418 | if (doc != NULL) { |
| 1419 | if (xmlDebugCatalogs) |
| 1420 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1421 | "Found %s in file hash\n", catal->URL); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1422 | |
| 1423 | if (catal->type == XML_CATA_CATALOG) |
| 1424 | catal->children = doc->children; |
| 1425 | else |
| 1426 | catal->children = doc; |
| 1427 | catal->dealloc = 0; |
| 1428 | xmlRMutexUnlock(xmlCatalogMutex); |
| 1429 | return(0); |
| 1430 | } |
| 1431 | if (xmlDebugCatalogs) |
| 1432 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1433 | "%s not found in file hash\n", catal->URL); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1436 | /* |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1437 | * Fetch and parse. Note that xmlParseXMLCatalogFile does not |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 1438 | * use the existing catalog, there is no recursion allowed at |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1439 | * that level. |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1440 | */ |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1441 | doc = xmlParseXMLCatalogFile(catal->prefer, catal->URL); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1442 | if (doc == NULL) { |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 1443 | catal->type = XML_CATA_BROKEN_CATALOG; |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 1444 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1445 | return(-1); |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 1446 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1447 | |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1448 | if (catal->type == XML_CATA_CATALOG) |
| 1449 | catal->children = doc->children; |
| 1450 | else |
| 1451 | catal->children = doc; |
| 1452 | |
| 1453 | doc->dealloc = 1; |
| 1454 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 1455 | if (xmlCatalogXMLFiles == NULL) |
| 1456 | xmlCatalogXMLFiles = xmlHashCreate(10); |
| 1457 | if (xmlCatalogXMLFiles != NULL) { |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1458 | if (xmlDebugCatalogs) |
| 1459 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1460 | "%s added to file hash\n", catal->URL); |
| 1461 | xmlHashAddEntry(xmlCatalogXMLFiles, catal->URL, doc); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1462 | } |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 1463 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1464 | return(0); |
| 1465 | } |
| 1466 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 1467 | /************************************************************************ |
| 1468 | * * |
| 1469 | * XML Catalog handling * |
| 1470 | * * |
| 1471 | ************************************************************************/ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1472 | |
| 1473 | /** |
| 1474 | * xmlAddXMLCatalog: |
| 1475 | * @catal: top of an XML catalog |
| 1476 | * @type: the type of record to add to the catalog |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1477 | * @orig: the system, public or prefix to match (or NULL) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1478 | * @replace: the replacement value for the match |
| 1479 | * |
| 1480 | * Add an entry in the XML catalog, it may overwrite existing but |
| 1481 | * different entries. |
| 1482 | * |
| 1483 | * Returns 0 if successful, -1 otherwise |
| 1484 | */ |
| 1485 | static int |
| 1486 | xmlAddXMLCatalog(xmlCatalogEntryPtr catal, const xmlChar *type, |
| 1487 | const xmlChar *orig, const xmlChar *replace) { |
| 1488 | xmlCatalogEntryPtr cur; |
| 1489 | xmlCatalogEntryType typ; |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1490 | int doregister = 0; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1491 | |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 1492 | if ((catal == NULL) || |
| 1493 | ((catal->type != XML_CATA_CATALOG) && |
| 1494 | (catal->type != XML_CATA_BROKEN_CATALOG))) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1495 | return(-1); |
Daniel Veillard | ffe09c9 | 2001-11-05 14:21:47 +0000 | [diff] [blame] | 1496 | if (catal->children == NULL) { |
| 1497 | xmlFetchXMLCatalogFile(catal); |
| 1498 | } |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1499 | if (catal->children == NULL) |
| 1500 | doregister = 1; |
| 1501 | |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1502 | typ = xmlGetXMLCatalogEntryType(type); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1503 | if (typ == XML_CATA_NONE) { |
| 1504 | if (xmlDebugCatalogs) |
| 1505 | xmlGenericError(xmlGenericErrorContext, |
| 1506 | "Failed to add unknown element %s to catalog\n", type); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1507 | return(-1); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1508 | } |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1509 | |
| 1510 | cur = catal->children; |
| 1511 | /* |
| 1512 | * Might be a simple "update in place" |
| 1513 | */ |
| 1514 | if (cur != NULL) { |
| 1515 | while (cur != NULL) { |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1516 | if ((orig != NULL) && (cur->type == typ) && |
| 1517 | (xmlStrEqual(orig, cur->name))) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1518 | if (xmlDebugCatalogs) |
| 1519 | xmlGenericError(xmlGenericErrorContext, |
| 1520 | "Updating element %s to catalog\n", type); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1521 | if (cur->value != NULL) |
| 1522 | xmlFree(cur->value); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1523 | if (cur->URL != NULL) |
| 1524 | xmlFree(cur->URL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1525 | cur->value = xmlStrdup(replace); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1526 | cur->URL = xmlStrdup(replace); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1527 | return(0); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1528 | } |
| 1529 | if (cur->next == NULL) |
| 1530 | break; |
| 1531 | cur = cur->next; |
| 1532 | } |
| 1533 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1534 | if (xmlDebugCatalogs) |
| 1535 | xmlGenericError(xmlGenericErrorContext, |
| 1536 | "Adding element %s to catalog\n", type); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1537 | if (cur == NULL) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1538 | catal->children = xmlNewCatalogEntry(typ, orig, replace, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1539 | NULL, catal->prefer, NULL); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 1540 | else |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1541 | cur->next = xmlNewCatalogEntry(typ, orig, replace, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 1542 | NULL, catal->prefer, NULL); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1543 | if (doregister) { |
| 1544 | cur = xmlHashLookup(xmlCatalogXMLFiles, catal->URL); |
| 1545 | if (cur != NULL) |
| 1546 | cur->children = catal->children; |
| 1547 | } |
| 1548 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1549 | return(0); |
| 1550 | } |
| 1551 | |
| 1552 | /** |
| 1553 | * xmlDelXMLCatalog: |
| 1554 | * @catal: top of an XML catalog |
Daniel Veillard | 60087f3 | 2001-10-10 09:45:09 +0000 | [diff] [blame] | 1555 | * @value: the value to remove from the catalog |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1556 | * |
| 1557 | * Remove entries in the XML catalog where the value or the URI |
| 1558 | * is equal to @value |
| 1559 | * |
| 1560 | * Returns the number of entries removed if successful, -1 otherwise |
| 1561 | */ |
| 1562 | static int |
| 1563 | xmlDelXMLCatalog(xmlCatalogEntryPtr catal, const xmlChar *value) { |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1564 | xmlCatalogEntryPtr cur; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1565 | int ret = 0; |
| 1566 | |
Daniel Veillard | 9f7b84b | 2001-08-23 15:31:19 +0000 | [diff] [blame] | 1567 | if ((catal == NULL) || |
| 1568 | ((catal->type != XML_CATA_CATALOG) && |
| 1569 | (catal->type != XML_CATA_BROKEN_CATALOG))) |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1570 | return(-1); |
| 1571 | if (value == NULL) |
| 1572 | return(-1); |
Daniel Veillard | ffe09c9 | 2001-11-05 14:21:47 +0000 | [diff] [blame] | 1573 | if (catal->children == NULL) { |
| 1574 | xmlFetchXMLCatalogFile(catal); |
| 1575 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1576 | |
| 1577 | /* |
| 1578 | * Scan the children |
| 1579 | */ |
| 1580 | cur = catal->children; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1581 | while (cur != NULL) { |
| 1582 | if (((cur->name != NULL) && (xmlStrEqual(value, cur->name))) || |
| 1583 | (xmlStrEqual(value, cur->value))) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1584 | if (xmlDebugCatalogs) { |
| 1585 | if (cur->name != NULL) |
| 1586 | xmlGenericError(xmlGenericErrorContext, |
| 1587 | "Removing element %s from catalog\n", cur->name); |
| 1588 | else |
| 1589 | xmlGenericError(xmlGenericErrorContext, |
| 1590 | "Removing element %s from catalog\n", cur->value); |
| 1591 | } |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1592 | cur->type = XML_CATA_REMOVED; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1593 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1594 | cur = cur->next; |
| 1595 | } |
| 1596 | return(ret); |
| 1597 | } |
| 1598 | |
| 1599 | /** |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1600 | * xmlCatalogXMLResolve: |
| 1601 | * @catal: a catalog list |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 1602 | * @pubID: the public ID string |
| 1603 | * @sysID: the system ID string |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1604 | * |
| 1605 | * Do a complete resolution lookup of an External Identifier for a |
| 1606 | * list of catalog entries. |
| 1607 | * |
| 1608 | * Implements (or tries to) 7.1. External Identifier Resolution |
| 1609 | * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html |
| 1610 | * |
| 1611 | * Returns the URI of the resource or NULL if not found |
| 1612 | */ |
| 1613 | static xmlChar * |
| 1614 | xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, |
| 1615 | const xmlChar *sysID) { |
| 1616 | xmlChar *ret = NULL; |
| 1617 | xmlCatalogEntryPtr cur; |
| 1618 | int haveDelegate = 0; |
| 1619 | int haveNext = 0; |
| 1620 | |
| 1621 | /* |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1622 | * protection against loops |
| 1623 | */ |
| 1624 | if (catal->depth > MAX_CATAL_DEPTH) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 1625 | xmlCatalogErr(catal, NULL, XML_CATALOG_RECURSION, |
| 1626 | "Detected recursion in catalog %s\n", |
| 1627 | catal->name, NULL, NULL); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1628 | return(NULL); |
| 1629 | } |
| 1630 | catal->depth++; |
| 1631 | |
| 1632 | /* |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1633 | * First tries steps 2/ 3/ 4/ if a system ID is provided. |
| 1634 | */ |
| 1635 | if (sysID != NULL) { |
| 1636 | xmlCatalogEntryPtr rewrite = NULL; |
| 1637 | int lenrewrite = 0, len; |
| 1638 | cur = catal; |
| 1639 | haveDelegate = 0; |
| 1640 | while (cur != NULL) { |
| 1641 | switch (cur->type) { |
| 1642 | case XML_CATA_SYSTEM: |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1643 | if (xmlStrEqual(sysID, cur->name)) { |
| 1644 | if (xmlDebugCatalogs) |
| 1645 | xmlGenericError(xmlGenericErrorContext, |
| 1646 | "Found system match %s\n", cur->name); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1647 | catal->depth--; |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1648 | return(xmlStrdup(cur->URL)); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1649 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1650 | break; |
| 1651 | case XML_CATA_REWRITE_SYSTEM: |
| 1652 | len = xmlStrlen(cur->name); |
| 1653 | if ((len > lenrewrite) && |
| 1654 | (!xmlStrncmp(sysID, cur->name, len))) { |
| 1655 | lenrewrite = len; |
| 1656 | rewrite = cur; |
| 1657 | } |
| 1658 | break; |
| 1659 | case XML_CATA_DELEGATE_SYSTEM: |
| 1660 | if (!xmlStrncmp(sysID, cur->name, xmlStrlen(cur->name))) |
| 1661 | haveDelegate++; |
| 1662 | break; |
| 1663 | case XML_CATA_NEXT_CATALOG: |
| 1664 | haveNext++; |
| 1665 | break; |
| 1666 | default: |
| 1667 | break; |
| 1668 | } |
| 1669 | cur = cur->next; |
| 1670 | } |
| 1671 | if (rewrite != NULL) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1672 | if (xmlDebugCatalogs) |
| 1673 | xmlGenericError(xmlGenericErrorContext, |
| 1674 | "Using rewriting rule %s\n", rewrite->name); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1675 | ret = xmlStrdup(rewrite->URL); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1676 | if (ret != NULL) |
| 1677 | ret = xmlStrcat(ret, &sysID[lenrewrite]); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1678 | catal->depth--; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1679 | return(ret); |
| 1680 | } |
| 1681 | if (haveDelegate) { |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1682 | const xmlChar *delegates[MAX_DELEGATE]; |
| 1683 | int nbList = 0, i; |
| 1684 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1685 | /* |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1686 | * Assume the entries have been sorted by decreasing substring |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1687 | * matches when the list was produced. |
| 1688 | */ |
| 1689 | cur = catal; |
| 1690 | while (cur != NULL) { |
| 1691 | if ((cur->type == XML_CATA_DELEGATE_SYSTEM) && |
| 1692 | (!xmlStrncmp(sysID, cur->name, xmlStrlen(cur->name)))) { |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1693 | for (i = 0;i < nbList;i++) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1694 | if (xmlStrEqual(cur->URL, delegates[i])) |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1695 | break; |
| 1696 | if (i < nbList) { |
| 1697 | cur = cur->next; |
| 1698 | continue; |
| 1699 | } |
| 1700 | if (nbList < MAX_DELEGATE) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1701 | delegates[nbList++] = cur->URL; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1702 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1703 | if (cur->children == NULL) { |
| 1704 | xmlFetchXMLCatalogFile(cur); |
| 1705 | } |
| 1706 | if (cur->children != NULL) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1707 | if (xmlDebugCatalogs) |
| 1708 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1709 | "Trying system delegate %s\n", cur->URL); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1710 | ret = xmlCatalogListXMLResolve( |
| 1711 | cur->children, NULL, sysID); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1712 | if (ret != NULL) { |
| 1713 | catal->depth--; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1714 | return(ret); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1715 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | cur = cur->next; |
| 1719 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1720 | /* |
| 1721 | * Apply the cut algorithm explained in 4/ |
| 1722 | */ |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1723 | catal->depth--; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1724 | return(XML_CATAL_BREAK); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1725 | } |
| 1726 | } |
| 1727 | /* |
| 1728 | * Then tries 5/ 6/ if a public ID is provided |
| 1729 | */ |
| 1730 | if (pubID != NULL) { |
| 1731 | cur = catal; |
| 1732 | haveDelegate = 0; |
| 1733 | while (cur != NULL) { |
| 1734 | switch (cur->type) { |
| 1735 | case XML_CATA_PUBLIC: |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1736 | if (xmlStrEqual(pubID, cur->name)) { |
| 1737 | if (xmlDebugCatalogs) |
| 1738 | xmlGenericError(xmlGenericErrorContext, |
| 1739 | "Found public match %s\n", cur->name); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1740 | catal->depth--; |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1741 | return(xmlStrdup(cur->URL)); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1742 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1743 | break; |
| 1744 | case XML_CATA_DELEGATE_PUBLIC: |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1745 | if (!xmlStrncmp(pubID, cur->name, xmlStrlen(cur->name)) && |
| 1746 | (cur->prefer == XML_CATA_PREFER_PUBLIC)) |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1747 | haveDelegate++; |
| 1748 | break; |
| 1749 | case XML_CATA_NEXT_CATALOG: |
| 1750 | if (sysID == NULL) |
| 1751 | haveNext++; |
| 1752 | break; |
| 1753 | default: |
| 1754 | break; |
| 1755 | } |
| 1756 | cur = cur->next; |
| 1757 | } |
| 1758 | if (haveDelegate) { |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1759 | const xmlChar *delegates[MAX_DELEGATE]; |
| 1760 | int nbList = 0, i; |
| 1761 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1762 | /* |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1763 | * Assume the entries have been sorted by decreasing substring |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1764 | * matches when the list was produced. |
| 1765 | */ |
| 1766 | cur = catal; |
| 1767 | while (cur != NULL) { |
| 1768 | if ((cur->type == XML_CATA_DELEGATE_PUBLIC) && |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1769 | (cur->prefer == XML_CATA_PREFER_PUBLIC) && |
| 1770 | (!xmlStrncmp(pubID, cur->name, xmlStrlen(cur->name)))) { |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1771 | |
| 1772 | for (i = 0;i < nbList;i++) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1773 | if (xmlStrEqual(cur->URL, delegates[i])) |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1774 | break; |
| 1775 | if (i < nbList) { |
| 1776 | cur = cur->next; |
| 1777 | continue; |
| 1778 | } |
| 1779 | if (nbList < MAX_DELEGATE) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1780 | delegates[nbList++] = cur->URL; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1781 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1782 | if (cur->children == NULL) { |
| 1783 | xmlFetchXMLCatalogFile(cur); |
| 1784 | } |
| 1785 | if (cur->children != NULL) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1786 | if (xmlDebugCatalogs) |
| 1787 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1788 | "Trying public delegate %s\n", cur->URL); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1789 | ret = xmlCatalogListXMLResolve( |
| 1790 | cur->children, pubID, NULL); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1791 | if (ret != NULL) { |
| 1792 | catal->depth--; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1793 | return(ret); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1794 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | cur = cur->next; |
| 1798 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1799 | /* |
| 1800 | * Apply the cut algorithm explained in 4/ |
| 1801 | */ |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1802 | catal->depth--; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1803 | return(XML_CATAL_BREAK); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | if (haveNext) { |
| 1807 | cur = catal; |
| 1808 | while (cur != NULL) { |
| 1809 | if (cur->type == XML_CATA_NEXT_CATALOG) { |
| 1810 | if (cur->children == NULL) { |
| 1811 | xmlFetchXMLCatalogFile(cur); |
| 1812 | } |
| 1813 | if (cur->children != NULL) { |
Daniel Veillard | 6433954 | 2001-08-21 12:57:59 +0000 | [diff] [blame] | 1814 | ret = xmlCatalogListXMLResolve(cur->children, pubID, sysID); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1815 | if (ret != NULL) { |
| 1816 | catal->depth--; |
Daniel Veillard | 6433954 | 2001-08-21 12:57:59 +0000 | [diff] [blame] | 1817 | return(ret); |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1818 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1819 | } |
| 1820 | } |
| 1821 | cur = cur->next; |
| 1822 | } |
| 1823 | } |
| 1824 | |
Daniel Veillard | 5ee43b0 | 2003-08-04 00:58:46 +0000 | [diff] [blame] | 1825 | catal->depth--; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1826 | return(NULL); |
| 1827 | } |
| 1828 | |
| 1829 | /** |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1830 | * xmlCatalogXMLResolveURI: |
| 1831 | * @catal: a catalog list |
| 1832 | * @URI: the URI |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 1833 | * @sysID: the system ID string |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1834 | * |
| 1835 | * Do a complete resolution lookup of an External Identifier for a |
| 1836 | * list of catalog entries. |
| 1837 | * |
| 1838 | * Implements (or tries to) 7.2.2. URI Resolution |
| 1839 | * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html |
| 1840 | * |
| 1841 | * Returns the URI of the resource or NULL if not found |
| 1842 | */ |
| 1843 | static xmlChar * |
| 1844 | xmlCatalogXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) { |
| 1845 | xmlChar *ret = NULL; |
| 1846 | xmlCatalogEntryPtr cur; |
| 1847 | int haveDelegate = 0; |
| 1848 | int haveNext = 0; |
| 1849 | xmlCatalogEntryPtr rewrite = NULL; |
| 1850 | int lenrewrite = 0, len; |
| 1851 | |
| 1852 | if (catal == NULL) |
| 1853 | return(NULL); |
| 1854 | |
| 1855 | if (URI == NULL) |
| 1856 | return(NULL); |
| 1857 | |
| 1858 | /* |
| 1859 | * First tries steps 2/ 3/ 4/ if a system ID is provided. |
| 1860 | */ |
| 1861 | cur = catal; |
| 1862 | haveDelegate = 0; |
| 1863 | while (cur != NULL) { |
| 1864 | switch (cur->type) { |
| 1865 | case XML_CATA_URI: |
| 1866 | if (xmlStrEqual(URI, cur->name)) { |
| 1867 | if (xmlDebugCatalogs) |
| 1868 | xmlGenericError(xmlGenericErrorContext, |
| 1869 | "Found URI match %s\n", cur->name); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1870 | return(xmlStrdup(cur->URL)); |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1871 | } |
| 1872 | break; |
| 1873 | case XML_CATA_REWRITE_URI: |
| 1874 | len = xmlStrlen(cur->name); |
| 1875 | if ((len > lenrewrite) && |
| 1876 | (!xmlStrncmp(URI, cur->name, len))) { |
| 1877 | lenrewrite = len; |
| 1878 | rewrite = cur; |
| 1879 | } |
| 1880 | break; |
| 1881 | case XML_CATA_DELEGATE_URI: |
| 1882 | if (!xmlStrncmp(URI, cur->name, xmlStrlen(cur->name))) |
| 1883 | haveDelegate++; |
| 1884 | break; |
| 1885 | case XML_CATA_NEXT_CATALOG: |
| 1886 | haveNext++; |
| 1887 | break; |
| 1888 | default: |
| 1889 | break; |
| 1890 | } |
| 1891 | cur = cur->next; |
| 1892 | } |
| 1893 | if (rewrite != NULL) { |
| 1894 | if (xmlDebugCatalogs) |
| 1895 | xmlGenericError(xmlGenericErrorContext, |
| 1896 | "Using rewriting rule %s\n", rewrite->name); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1897 | ret = xmlStrdup(rewrite->URL); |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1898 | if (ret != NULL) |
| 1899 | ret = xmlStrcat(ret, &URI[lenrewrite]); |
| 1900 | return(ret); |
| 1901 | } |
| 1902 | if (haveDelegate) { |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1903 | const xmlChar *delegates[MAX_DELEGATE]; |
| 1904 | int nbList = 0, i; |
| 1905 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1906 | /* |
| 1907 | * Assume the entries have been sorted by decreasing substring |
| 1908 | * matches when the list was produced. |
| 1909 | */ |
| 1910 | cur = catal; |
| 1911 | while (cur != NULL) { |
Daniel Veillard | 652d8a9 | 2003-02-04 19:28:49 +0000 | [diff] [blame] | 1912 | if (((cur->type == XML_CATA_DELEGATE_SYSTEM) || |
| 1913 | (cur->type == XML_CATA_DELEGATE_URI)) && |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1914 | (!xmlStrncmp(URI, cur->name, xmlStrlen(cur->name)))) { |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1915 | for (i = 0;i < nbList;i++) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1916 | if (xmlStrEqual(cur->URL, delegates[i])) |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1917 | break; |
| 1918 | if (i < nbList) { |
| 1919 | cur = cur->next; |
| 1920 | continue; |
| 1921 | } |
| 1922 | if (nbList < MAX_DELEGATE) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1923 | delegates[nbList++] = cur->URL; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 1924 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1925 | if (cur->children == NULL) { |
| 1926 | xmlFetchXMLCatalogFile(cur); |
| 1927 | } |
| 1928 | if (cur->children != NULL) { |
| 1929 | if (xmlDebugCatalogs) |
| 1930 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 1931 | "Trying URI delegate %s\n", cur->URL); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 1932 | ret = xmlCatalogListXMLResolveURI( |
| 1933 | cur->children, URI); |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 1934 | if (ret != NULL) |
| 1935 | return(ret); |
| 1936 | } |
| 1937 | } |
| 1938 | cur = cur->next; |
| 1939 | } |
| 1940 | /* |
| 1941 | * Apply the cut algorithm explained in 4/ |
| 1942 | */ |
| 1943 | return(XML_CATAL_BREAK); |
| 1944 | } |
| 1945 | if (haveNext) { |
| 1946 | cur = catal; |
| 1947 | while (cur != NULL) { |
| 1948 | if (cur->type == XML_CATA_NEXT_CATALOG) { |
| 1949 | if (cur->children == NULL) { |
| 1950 | xmlFetchXMLCatalogFile(cur); |
| 1951 | } |
| 1952 | if (cur->children != NULL) { |
| 1953 | ret = xmlCatalogListXMLResolveURI(cur->children, URI); |
| 1954 | if (ret != NULL) |
| 1955 | return(ret); |
| 1956 | } |
| 1957 | } |
| 1958 | cur = cur->next; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | return(NULL); |
| 1963 | } |
| 1964 | |
| 1965 | /** |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1966 | * xmlCatalogListXMLResolve: |
| 1967 | * @catal: a catalog list |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 1968 | * @pubID: the public ID string |
| 1969 | * @sysID: the system ID string |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 1970 | * |
| 1971 | * Do a complete resolution lookup of an External Identifier for a |
| 1972 | * list of catalogs |
| 1973 | * |
| 1974 | * Implements (or tries to) 7.1. External Identifier Resolution |
| 1975 | * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html |
| 1976 | * |
| 1977 | * Returns the URI of the resource or NULL if not found |
| 1978 | */ |
| 1979 | static xmlChar * |
| 1980 | xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, |
| 1981 | const xmlChar *sysID) { |
| 1982 | xmlChar *ret = NULL; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1983 | xmlChar *urnID = NULL; |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 1984 | xmlChar *normid; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1985 | |
| 1986 | if (catal == NULL) |
| 1987 | return(NULL); |
| 1988 | if ((pubID == NULL) && (sysID == NULL)) |
| 1989 | return(NULL); |
| 1990 | |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 1991 | normid = xmlCatalogNormalizePublic(pubID); |
| 1992 | if (normid != NULL) |
| 1993 | pubID = (*normid != 0 ? normid : NULL); |
| 1994 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 1995 | if (!xmlStrncmp(pubID, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) { |
| 1996 | urnID = xmlCatalogUnWrapURN(pubID); |
| 1997 | if (xmlDebugCatalogs) { |
| 1998 | if (urnID == NULL) |
| 1999 | xmlGenericError(xmlGenericErrorContext, |
| 2000 | "Public URN ID %s expanded to NULL\n", pubID); |
| 2001 | else |
| 2002 | xmlGenericError(xmlGenericErrorContext, |
| 2003 | "Public URN ID expanded to %s\n", urnID); |
| 2004 | } |
| 2005 | ret = xmlCatalogListXMLResolve(catal, urnID, sysID); |
| 2006 | if (urnID != NULL) |
| 2007 | xmlFree(urnID); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2008 | if (normid != NULL) |
| 2009 | xmlFree(normid); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2010 | return(ret); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2011 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2012 | if (!xmlStrncmp(sysID, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) { |
| 2013 | urnID = xmlCatalogUnWrapURN(sysID); |
| 2014 | if (xmlDebugCatalogs) { |
| 2015 | if (urnID == NULL) |
| 2016 | xmlGenericError(xmlGenericErrorContext, |
| 2017 | "System URN ID %s expanded to NULL\n", sysID); |
| 2018 | else |
| 2019 | xmlGenericError(xmlGenericErrorContext, |
| 2020 | "System URN ID expanded to %s\n", urnID); |
| 2021 | } |
| 2022 | if (pubID == NULL) |
| 2023 | ret = xmlCatalogListXMLResolve(catal, urnID, NULL); |
| 2024 | else if (xmlStrEqual(pubID, urnID)) |
| 2025 | ret = xmlCatalogListXMLResolve(catal, pubID, NULL); |
| 2026 | else { |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 2027 | ret = xmlCatalogListXMLResolve(catal, pubID, urnID); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2028 | } |
| 2029 | if (urnID != NULL) |
| 2030 | xmlFree(urnID); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2031 | if (normid != NULL) |
| 2032 | xmlFree(normid); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2033 | return(ret); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2034 | } |
| 2035 | while (catal != NULL) { |
| 2036 | if (catal->type == XML_CATA_CATALOG) { |
| 2037 | if (catal->children == NULL) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2038 | xmlFetchXMLCatalogFile(catal); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2039 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2040 | if (catal->children != NULL) { |
| 2041 | ret = xmlCatalogXMLResolve(catal->children, pubID, sysID); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2042 | if (ret != NULL) { |
| 2043 | if (normid != NULL) |
| 2044 | xmlFree(normid); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2045 | return(ret); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2046 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2047 | } |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2048 | } |
| 2049 | catal = catal->next; |
| 2050 | } |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2051 | if (normid != NULL) |
| 2052 | xmlFree(normid); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2053 | return(ret); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 2056 | /** |
| 2057 | * xmlCatalogListXMLResolveURI: |
| 2058 | * @catal: a catalog list |
| 2059 | * @URI: the URI |
| 2060 | * |
| 2061 | * Do a complete resolution lookup of an URI for a list of catalogs |
| 2062 | * |
| 2063 | * Implements (or tries to) 7.2. URI Resolution |
| 2064 | * from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html |
| 2065 | * |
| 2066 | * Returns the URI of the resource or NULL if not found |
| 2067 | */ |
| 2068 | static xmlChar * |
| 2069 | xmlCatalogListXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) { |
| 2070 | xmlChar *ret = NULL; |
| 2071 | xmlChar *urnID = NULL; |
| 2072 | |
| 2073 | if (catal == NULL) |
| 2074 | return(NULL); |
| 2075 | if (URI == NULL) |
| 2076 | return(NULL); |
| 2077 | |
| 2078 | if (!xmlStrncmp(URI, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) { |
| 2079 | urnID = xmlCatalogUnWrapURN(URI); |
| 2080 | if (xmlDebugCatalogs) { |
| 2081 | if (urnID == NULL) |
| 2082 | xmlGenericError(xmlGenericErrorContext, |
| 2083 | "URN ID %s expanded to NULL\n", URI); |
| 2084 | else |
| 2085 | xmlGenericError(xmlGenericErrorContext, |
| 2086 | "URN ID expanded to %s\n", urnID); |
| 2087 | } |
| 2088 | ret = xmlCatalogListXMLResolve(catal, urnID, NULL); |
| 2089 | if (urnID != NULL) |
| 2090 | xmlFree(urnID); |
| 2091 | return(ret); |
| 2092 | } |
| 2093 | while (catal != NULL) { |
| 2094 | if (catal->type == XML_CATA_CATALOG) { |
| 2095 | if (catal->children == NULL) { |
| 2096 | xmlFetchXMLCatalogFile(catal); |
| 2097 | } |
| 2098 | if (catal->children != NULL) { |
| 2099 | ret = xmlCatalogXMLResolveURI(catal->children, URI); |
| 2100 | if (ret != NULL) |
| 2101 | return(ret); |
| 2102 | } |
| 2103 | } |
| 2104 | catal = catal->next; |
| 2105 | } |
| 2106 | return(ret); |
| 2107 | } |
| 2108 | |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2109 | /************************************************************************ |
| 2110 | * * |
| 2111 | * The SGML Catalog parser * |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2112 | * * |
| 2113 | ************************************************************************/ |
| 2114 | |
| 2115 | |
| 2116 | #define RAW *cur |
| 2117 | #define NEXT cur++; |
| 2118 | #define SKIP(x) cur += x; |
| 2119 | |
William M. Brack | 272693c | 2003-11-14 16:20:34 +0000 | [diff] [blame] | 2120 | #define SKIP_BLANKS while (IS_BLANK_CH(*cur)) NEXT; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2121 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2122 | /** |
| 2123 | * xmlParseSGMLCatalogComment: |
| 2124 | * @cur: the current character |
| 2125 | * |
| 2126 | * Skip a comment in an SGML catalog |
| 2127 | * |
| 2128 | * Returns new current character |
| 2129 | */ |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2130 | static const xmlChar * |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2131 | xmlParseSGMLCatalogComment(const xmlChar *cur) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2132 | if ((cur[0] != '-') || (cur[1] != '-')) |
| 2133 | return(cur); |
| 2134 | SKIP(2); |
| 2135 | while ((cur[0] != 0) && ((cur[0] != '-') || ((cur[1] != '-')))) |
| 2136 | NEXT; |
| 2137 | if (cur[0] == 0) { |
| 2138 | return(NULL); |
| 2139 | } |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2140 | return(cur + 2); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2143 | /** |
| 2144 | * xmlParseSGMLCatalogPubid: |
| 2145 | * @cur: the current character |
| 2146 | * @id: the return location |
| 2147 | * |
| 2148 | * Parse an SGML catalog ID |
| 2149 | * |
| 2150 | * Returns new current character and store the value in @id |
| 2151 | */ |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2152 | static const xmlChar * |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2153 | xmlParseSGMLCatalogPubid(const xmlChar *cur, xmlChar **id) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 2154 | xmlChar *buf = NULL, *tmp; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2155 | int len = 0; |
| 2156 | int size = 50; |
| 2157 | xmlChar stop; |
| 2158 | int count = 0; |
| 2159 | |
| 2160 | *id = NULL; |
| 2161 | |
| 2162 | if (RAW == '"') { |
| 2163 | NEXT; |
| 2164 | stop = '"'; |
| 2165 | } else if (RAW == '\'') { |
| 2166 | NEXT; |
| 2167 | stop = '\''; |
| 2168 | } else { |
| 2169 | stop = ' '; |
| 2170 | } |
Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 2171 | buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar)); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2172 | if (buf == NULL) { |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 2173 | xmlCatalogErrMemory("allocating public ID"); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2174 | return(NULL); |
| 2175 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2176 | while (IS_PUBIDCHAR_CH(*cur) || (*cur == '?')) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2177 | if ((*cur == stop) && (stop != ' ')) |
| 2178 | break; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2179 | if ((stop == ' ') && (IS_BLANK_CH(*cur))) |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2180 | break; |
| 2181 | if (len + 1 >= size) { |
| 2182 | size *= 2; |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 2183 | tmp = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar)); |
| 2184 | if (tmp == NULL) { |
| 2185 | xmlCatalogErrMemory("allocating public ID"); |
| 2186 | xmlFree(buf); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2187 | return(NULL); |
| 2188 | } |
Daniel Veillard | 69d2c17 | 2003-10-09 11:46:07 +0000 | [diff] [blame] | 2189 | buf = tmp; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2190 | } |
| 2191 | buf[len++] = *cur; |
| 2192 | count++; |
| 2193 | NEXT; |
| 2194 | } |
| 2195 | buf[len] = 0; |
| 2196 | if (stop == ' ') { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2197 | if (!IS_BLANK_CH(*cur)) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2198 | xmlFree(buf); |
| 2199 | return(NULL); |
| 2200 | } |
| 2201 | } else { |
| 2202 | if (*cur != stop) { |
| 2203 | xmlFree(buf); |
| 2204 | return(NULL); |
| 2205 | } |
| 2206 | NEXT; |
| 2207 | } |
| 2208 | *id = buf; |
| 2209 | return(cur); |
| 2210 | } |
| 2211 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2212 | /** |
| 2213 | * xmlParseSGMLCatalogName: |
| 2214 | * @cur: the current character |
| 2215 | * @name: the return location |
| 2216 | * |
| 2217 | * Parse an SGML catalog name |
| 2218 | * |
| 2219 | * Returns new current character and store the value in @name |
| 2220 | */ |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2221 | static const xmlChar * |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2222 | xmlParseSGMLCatalogName(const xmlChar *cur, xmlChar **name) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2223 | xmlChar buf[XML_MAX_NAMELEN + 5]; |
| 2224 | int len = 0; |
| 2225 | int c; |
| 2226 | |
| 2227 | *name = NULL; |
| 2228 | |
| 2229 | /* |
| 2230 | * Handler for more complex cases |
| 2231 | */ |
| 2232 | c = *cur; |
| 2233 | if ((!IS_LETTER(c) && (c != '_') && (c != ':'))) { |
| 2234 | return(NULL); |
| 2235 | } |
| 2236 | |
| 2237 | while (((IS_LETTER(c)) || (IS_DIGIT(c)) || |
| 2238 | (c == '.') || (c == '-') || |
| 2239 | (c == '_') || (c == ':'))) { |
| 2240 | buf[len++] = c; |
| 2241 | cur++; |
| 2242 | c = *cur; |
| 2243 | if (len >= XML_MAX_NAMELEN) |
| 2244 | return(NULL); |
| 2245 | } |
| 2246 | *name = xmlStrndup(buf, len); |
| 2247 | return(cur); |
| 2248 | } |
| 2249 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2250 | /** |
| 2251 | * xmlGetSGMLCatalogEntryType: |
| 2252 | * @name: the entry name |
| 2253 | * |
| 2254 | * Get the Catalog entry type for a given SGML Catalog name |
| 2255 | * |
| 2256 | * Returns Catalog entry type |
| 2257 | */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2258 | static xmlCatalogEntryType |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2259 | xmlGetSGMLCatalogEntryType(const xmlChar *name) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2260 | xmlCatalogEntryType type = XML_CATA_NONE; |
| 2261 | if (xmlStrEqual(name, (const xmlChar *) "SYSTEM")) |
| 2262 | type = SGML_CATA_SYSTEM; |
| 2263 | else if (xmlStrEqual(name, (const xmlChar *) "PUBLIC")) |
| 2264 | type = SGML_CATA_PUBLIC; |
| 2265 | else if (xmlStrEqual(name, (const xmlChar *) "DELEGATE")) |
| 2266 | type = SGML_CATA_DELEGATE; |
| 2267 | else if (xmlStrEqual(name, (const xmlChar *) "ENTITY")) |
| 2268 | type = SGML_CATA_ENTITY; |
| 2269 | else if (xmlStrEqual(name, (const xmlChar *) "DOCTYPE")) |
| 2270 | type = SGML_CATA_DOCTYPE; |
| 2271 | else if (xmlStrEqual(name, (const xmlChar *) "LINKTYPE")) |
| 2272 | type = SGML_CATA_LINKTYPE; |
| 2273 | else if (xmlStrEqual(name, (const xmlChar *) "NOTATION")) |
| 2274 | type = SGML_CATA_NOTATION; |
| 2275 | else if (xmlStrEqual(name, (const xmlChar *) "SGMLDECL")) |
| 2276 | type = SGML_CATA_SGMLDECL; |
| 2277 | else if (xmlStrEqual(name, (const xmlChar *) "DOCUMENT")) |
| 2278 | type = SGML_CATA_DOCUMENT; |
| 2279 | else if (xmlStrEqual(name, (const xmlChar *) "CATALOG")) |
| 2280 | type = SGML_CATA_CATALOG; |
| 2281 | else if (xmlStrEqual(name, (const xmlChar *) "BASE")) |
| 2282 | type = SGML_CATA_BASE; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2283 | return(type); |
| 2284 | } |
| 2285 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2286 | /** |
| 2287 | * xmlParseSGMLCatalog: |
| 2288 | * @catal: the SGML Catalog |
| 2289 | * @value: the content of the SGML Catalog serialization |
| 2290 | * @file: the filepath for the catalog |
| 2291 | * @super: should this be handled as a Super Catalog in which case |
| 2292 | * parsing is not recursive |
| 2293 | * |
| 2294 | * Parse an SGML catalog content and fill up the @catal hash table with |
| 2295 | * the new entries found. |
| 2296 | * |
| 2297 | * Returns 0 in case of success, -1 in case of error. |
| 2298 | */ |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2299 | static int |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2300 | xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value, |
| 2301 | const char *file, int super) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2302 | const xmlChar *cur = value; |
| 2303 | xmlChar *base = NULL; |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2304 | int res; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2305 | |
| 2306 | if ((cur == NULL) || (file == NULL)) |
| 2307 | return(-1); |
| 2308 | base = xmlStrdup((const xmlChar *) file); |
| 2309 | |
Daniel Veillard | bc2ddbe | 2001-08-23 10:24:27 +0000 | [diff] [blame] | 2310 | while ((cur != NULL) && (cur[0] != 0)) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2311 | SKIP_BLANKS; |
Daniel Veillard | bc2ddbe | 2001-08-23 10:24:27 +0000 | [diff] [blame] | 2312 | if (cur[0] == 0) |
| 2313 | break; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2314 | if ((cur[0] == '-') && (cur[1] == '-')) { |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2315 | cur = xmlParseSGMLCatalogComment(cur); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2316 | if (cur == NULL) { |
| 2317 | /* error */ |
| 2318 | break; |
| 2319 | } |
| 2320 | } else { |
| 2321 | xmlChar *sysid = NULL; |
| 2322 | xmlChar *name = NULL; |
| 2323 | xmlCatalogEntryType type = XML_CATA_NONE; |
| 2324 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2325 | cur = xmlParseSGMLCatalogName(cur, &name); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2326 | if (name == NULL) { |
| 2327 | /* error */ |
| 2328 | break; |
| 2329 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2330 | if (!IS_BLANK_CH(*cur)) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2331 | /* error */ |
| 2332 | break; |
| 2333 | } |
| 2334 | SKIP_BLANKS; |
| 2335 | if (xmlStrEqual(name, (const xmlChar *) "SYSTEM")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2336 | type = SGML_CATA_SYSTEM; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2337 | else if (xmlStrEqual(name, (const xmlChar *) "PUBLIC")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2338 | type = SGML_CATA_PUBLIC; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2339 | else if (xmlStrEqual(name, (const xmlChar *) "DELEGATE")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2340 | type = SGML_CATA_DELEGATE; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2341 | else if (xmlStrEqual(name, (const xmlChar *) "ENTITY")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2342 | type = SGML_CATA_ENTITY; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2343 | else if (xmlStrEqual(name, (const xmlChar *) "DOCTYPE")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2344 | type = SGML_CATA_DOCTYPE; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2345 | else if (xmlStrEqual(name, (const xmlChar *) "LINKTYPE")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2346 | type = SGML_CATA_LINKTYPE; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2347 | else if (xmlStrEqual(name, (const xmlChar *) "NOTATION")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2348 | type = SGML_CATA_NOTATION; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2349 | else if (xmlStrEqual(name, (const xmlChar *) "SGMLDECL")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2350 | type = SGML_CATA_SGMLDECL; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2351 | else if (xmlStrEqual(name, (const xmlChar *) "DOCUMENT")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2352 | type = SGML_CATA_DOCUMENT; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2353 | else if (xmlStrEqual(name, (const xmlChar *) "CATALOG")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2354 | type = SGML_CATA_CATALOG; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2355 | else if (xmlStrEqual(name, (const xmlChar *) "BASE")) |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2356 | type = SGML_CATA_BASE; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2357 | else if (xmlStrEqual(name, (const xmlChar *) "OVERRIDE")) { |
| 2358 | xmlFree(name); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2359 | cur = xmlParseSGMLCatalogName(cur, &name); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2360 | if (name == NULL) { |
| 2361 | /* error */ |
| 2362 | break; |
| 2363 | } |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2364 | xmlFree(name); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2365 | continue; |
| 2366 | } |
| 2367 | xmlFree(name); |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2368 | name = NULL; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2369 | |
| 2370 | switch(type) { |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2371 | case SGML_CATA_ENTITY: |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2372 | if (*cur == '%') |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2373 | type = SGML_CATA_PENTITY; |
| 2374 | case SGML_CATA_PENTITY: |
| 2375 | case SGML_CATA_DOCTYPE: |
| 2376 | case SGML_CATA_LINKTYPE: |
| 2377 | case SGML_CATA_NOTATION: |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2378 | cur = xmlParseSGMLCatalogName(cur, &name); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2379 | if (cur == NULL) { |
| 2380 | /* error */ |
| 2381 | break; |
| 2382 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2383 | if (!IS_BLANK_CH(*cur)) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2384 | /* error */ |
| 2385 | break; |
| 2386 | } |
| 2387 | SKIP_BLANKS; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2388 | cur = xmlParseSGMLCatalogPubid(cur, &sysid); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2389 | if (cur == NULL) { |
| 2390 | /* error */ |
| 2391 | break; |
| 2392 | } |
| 2393 | break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2394 | case SGML_CATA_PUBLIC: |
| 2395 | case SGML_CATA_SYSTEM: |
| 2396 | case SGML_CATA_DELEGATE: |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2397 | cur = xmlParseSGMLCatalogPubid(cur, &name); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2398 | if (cur == NULL) { |
| 2399 | /* error */ |
| 2400 | break; |
| 2401 | } |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2402 | if (type != SGML_CATA_SYSTEM) { |
| 2403 | xmlChar *normid; |
| 2404 | |
| 2405 | normid = xmlCatalogNormalizePublic(name); |
| 2406 | if (normid != NULL) { |
| 2407 | if (name != NULL) |
| 2408 | xmlFree(name); |
| 2409 | if (*normid != 0) |
| 2410 | name = normid; |
| 2411 | else { |
| 2412 | xmlFree(normid); |
| 2413 | name = NULL; |
| 2414 | } |
| 2415 | } |
| 2416 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 2417 | if (!IS_BLANK_CH(*cur)) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2418 | /* error */ |
| 2419 | break; |
| 2420 | } |
| 2421 | SKIP_BLANKS; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2422 | cur = xmlParseSGMLCatalogPubid(cur, &sysid); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2423 | if (cur == NULL) { |
| 2424 | /* error */ |
| 2425 | break; |
| 2426 | } |
| 2427 | break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2428 | case SGML_CATA_BASE: |
| 2429 | case SGML_CATA_CATALOG: |
| 2430 | case SGML_CATA_DOCUMENT: |
| 2431 | case SGML_CATA_SGMLDECL: |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2432 | cur = xmlParseSGMLCatalogPubid(cur, &sysid); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2433 | if (cur == NULL) { |
| 2434 | /* error */ |
| 2435 | break; |
| 2436 | } |
| 2437 | break; |
| 2438 | default: |
| 2439 | break; |
| 2440 | } |
| 2441 | if (cur == NULL) { |
| 2442 | if (name != NULL) |
| 2443 | xmlFree(name); |
| 2444 | if (sysid != NULL) |
| 2445 | xmlFree(sysid); |
| 2446 | break; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2447 | } else if (type == SGML_CATA_BASE) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2448 | if (base != NULL) |
| 2449 | xmlFree(base); |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2450 | base = xmlStrdup(sysid); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2451 | } else if ((type == SGML_CATA_PUBLIC) || |
| 2452 | (type == SGML_CATA_SYSTEM)) { |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2453 | xmlChar *filename; |
| 2454 | |
| 2455 | filename = xmlBuildURI(sysid, base); |
| 2456 | if (filename != NULL) { |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2457 | xmlCatalogEntryPtr entry; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2458 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2459 | entry = xmlNewCatalogEntry(type, name, filename, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 2460 | NULL, XML_CATA_PREFER_NONE, NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2461 | res = xmlHashAddEntry(catal->sgml, name, entry); |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2462 | if (res < 0) { |
| 2463 | xmlFreeCatalogEntry(entry); |
| 2464 | } |
| 2465 | xmlFree(filename); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2466 | } |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2467 | |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 2468 | } else if (type == SGML_CATA_CATALOG) { |
Daniel Veillard | 82d7533 | 2001-10-08 15:01:59 +0000 | [diff] [blame] | 2469 | if (super) { |
| 2470 | xmlCatalogEntryPtr entry; |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2471 | |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 2472 | entry = xmlNewCatalogEntry(type, sysid, NULL, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 2473 | XML_CATA_PREFER_NONE, NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2474 | res = xmlHashAddEntry(catal->sgml, sysid, entry); |
Daniel Veillard | 82d7533 | 2001-10-08 15:01:59 +0000 | [diff] [blame] | 2475 | if (res < 0) { |
| 2476 | xmlFreeCatalogEntry(entry); |
| 2477 | } |
| 2478 | } else { |
| 2479 | xmlChar *filename; |
| 2480 | |
| 2481 | filename = xmlBuildURI(sysid, base); |
| 2482 | if (filename != NULL) { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2483 | xmlExpandCatalog(catal, (const char *)filename); |
Daniel Veillard | 82d7533 | 2001-10-08 15:01:59 +0000 | [diff] [blame] | 2484 | xmlFree(filename); |
| 2485 | } |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2486 | } |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2487 | } |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 2488 | /* |
| 2489 | * drop anything else we won't handle it |
| 2490 | */ |
| 2491 | if (name != NULL) |
| 2492 | xmlFree(name); |
| 2493 | if (sysid != NULL) |
| 2494 | xmlFree(sysid); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | if (base != NULL) |
| 2498 | xmlFree(base); |
| 2499 | if (cur == NULL) |
| 2500 | return(-1); |
| 2501 | return(0); |
| 2502 | } |
| 2503 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2504 | /************************************************************************ |
| 2505 | * * |
| 2506 | * SGML Catalog handling * |
| 2507 | * * |
| 2508 | ************************************************************************/ |
| 2509 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2510 | /** |
| 2511 | * xmlCatalogGetSGMLPublic: |
| 2512 | * @catal: an SGML catalog hash |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2513 | * @pubID: the public ID string |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2514 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2515 | * Try to lookup the catalog local reference associated to a public ID |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2516 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2517 | * Returns the local resource if found or NULL otherwise. |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2518 | */ |
| 2519 | static const xmlChar * |
| 2520 | xmlCatalogGetSGMLPublic(xmlHashTablePtr catal, const xmlChar *pubID) { |
| 2521 | xmlCatalogEntryPtr entry; |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2522 | xmlChar *normid; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2523 | |
| 2524 | if (catal == NULL) |
| 2525 | return(NULL); |
| 2526 | |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2527 | normid = xmlCatalogNormalizePublic(pubID); |
| 2528 | if (normid != NULL) |
| 2529 | pubID = (*normid != 0 ? normid : NULL); |
| 2530 | |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2531 | entry = (xmlCatalogEntryPtr) xmlHashLookup(catal, pubID); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2532 | if (entry == NULL) { |
| 2533 | if (normid != NULL) |
| 2534 | xmlFree(normid); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2535 | return(NULL); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2536 | } |
| 2537 | if (entry->type == SGML_CATA_PUBLIC) { |
| 2538 | if (normid != NULL) |
| 2539 | xmlFree(normid); |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 2540 | return(entry->URL); |
Daniel Veillard | c815505 | 2004-07-16 09:03:08 +0000 | [diff] [blame] | 2541 | } |
| 2542 | if (normid != NULL) |
| 2543 | xmlFree(normid); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2544 | return(NULL); |
| 2545 | } |
| 2546 | |
| 2547 | /** |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2548 | * xmlCatalogGetSGMLSystem: |
| 2549 | * @catal: an SGML catalog hash |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2550 | * @sysID: the system ID string |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2551 | * |
| 2552 | * Try to lookup the catalog local reference for a system ID |
| 2553 | * |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 2554 | * Returns the local resource if found or NULL otherwise. |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2555 | */ |
| 2556 | static const xmlChar * |
| 2557 | xmlCatalogGetSGMLSystem(xmlHashTablePtr catal, const xmlChar *sysID) { |
| 2558 | xmlCatalogEntryPtr entry; |
| 2559 | |
| 2560 | if (catal == NULL) |
| 2561 | return(NULL); |
| 2562 | |
| 2563 | entry = (xmlCatalogEntryPtr) xmlHashLookup(catal, sysID); |
| 2564 | if (entry == NULL) |
| 2565 | return(NULL); |
| 2566 | if (entry->type == SGML_CATA_SYSTEM) |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 2567 | return(entry->URL); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 2568 | return(NULL); |
| 2569 | } |
| 2570 | |
| 2571 | /** |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2572 | * xmlCatalogSGMLResolve: |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2573 | * @catal: the SGML catalog |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2574 | * @pubID: the public ID string |
| 2575 | * @sysID: the system ID string |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2576 | * |
| 2577 | * Do a complete resolution lookup of an External Identifier |
| 2578 | * |
| 2579 | * Returns the URI of the resource or NULL if not found |
| 2580 | */ |
| 2581 | static const xmlChar * |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2582 | xmlCatalogSGMLResolve(xmlCatalogPtr catal, const xmlChar *pubID, |
| 2583 | const xmlChar *sysID) { |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 2584 | const xmlChar *ret = NULL; |
| 2585 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2586 | if (catal->sgml == NULL) |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 2587 | return(NULL); |
| 2588 | |
| 2589 | if (pubID != NULL) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2590 | ret = xmlCatalogGetSGMLPublic(catal->sgml, pubID); |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 2591 | if (ret != NULL) |
| 2592 | return(ret); |
| 2593 | if (sysID != NULL) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2594 | ret = xmlCatalogGetSGMLSystem(catal->sgml, sysID); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 2595 | return(NULL); |
| 2596 | } |
| 2597 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 2598 | /************************************************************************ |
| 2599 | * * |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2600 | * Specific Public interfaces * |
| 2601 | * * |
| 2602 | ************************************************************************/ |
| 2603 | |
| 2604 | /** |
| 2605 | * xmlLoadSGMLSuperCatalog: |
| 2606 | * @filename: a file path |
| 2607 | * |
| 2608 | * Load an SGML super catalog. It won't expand CATALOG or DELEGATE |
| 2609 | * references. This is only needed for manipulating SGML Super Catalogs |
| 2610 | * like adding and removing CATALOG or DELEGATE entries. |
| 2611 | * |
| 2612 | * Returns the catalog parsed or NULL in case of error |
| 2613 | */ |
| 2614 | xmlCatalogPtr |
| 2615 | xmlLoadSGMLSuperCatalog(const char *filename) |
| 2616 | { |
| 2617 | xmlChar *content; |
| 2618 | xmlCatalogPtr catal; |
| 2619 | int ret; |
| 2620 | |
| 2621 | content = xmlLoadFileContent(filename); |
| 2622 | if (content == NULL) |
| 2623 | return(NULL); |
| 2624 | |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 2625 | catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE, xmlCatalogDefaultPrefer); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2626 | if (catal == NULL) { |
| 2627 | xmlFree(content); |
| 2628 | return(NULL); |
| 2629 | } |
| 2630 | |
| 2631 | ret = xmlParseSGMLCatalog(catal, content, filename, 1); |
| 2632 | xmlFree(content); |
| 2633 | if (ret < 0) { |
| 2634 | xmlFreeCatalog(catal); |
| 2635 | return(NULL); |
| 2636 | } |
| 2637 | return (catal); |
| 2638 | } |
| 2639 | |
| 2640 | /** |
| 2641 | * xmlLoadACatalog: |
| 2642 | * @filename: a file path |
| 2643 | * |
| 2644 | * Load the catalog and build the associated data structures. |
| 2645 | * This can be either an XML Catalog or an SGML Catalog |
| 2646 | * It will recurse in SGML CATALOG entries. On the other hand XML |
| 2647 | * Catalogs are not handled recursively. |
| 2648 | * |
| 2649 | * Returns the catalog parsed or NULL in case of error |
| 2650 | */ |
| 2651 | xmlCatalogPtr |
| 2652 | xmlLoadACatalog(const char *filename) |
| 2653 | { |
| 2654 | xmlChar *content; |
| 2655 | xmlChar *first; |
| 2656 | xmlCatalogPtr catal; |
| 2657 | int ret; |
| 2658 | |
| 2659 | content = xmlLoadFileContent(filename); |
| 2660 | if (content == NULL) |
| 2661 | return(NULL); |
| 2662 | |
| 2663 | |
| 2664 | first = content; |
| 2665 | |
| 2666 | while ((*first != 0) && (*first != '-') && (*first != '<') && |
| 2667 | (!(((*first >= 'A') && (*first <= 'Z')) || |
| 2668 | ((*first >= 'a') && (*first <= 'z'))))) |
| 2669 | first++; |
| 2670 | |
| 2671 | if (*first != '<') { |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 2672 | catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE, xmlCatalogDefaultPrefer); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2673 | if (catal == NULL) { |
| 2674 | xmlFree(content); |
| 2675 | return(NULL); |
| 2676 | } |
| 2677 | ret = xmlParseSGMLCatalog(catal, content, filename, 0); |
| 2678 | if (ret < 0) { |
| 2679 | xmlFreeCatalog(catal); |
| 2680 | xmlFree(content); |
| 2681 | return(NULL); |
| 2682 | } |
| 2683 | } else { |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 2684 | catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE, xmlCatalogDefaultPrefer); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2685 | if (catal == NULL) { |
| 2686 | xmlFree(content); |
| 2687 | return(NULL); |
| 2688 | } |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 2689 | catal->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 2690 | NULL, BAD_CAST filename, xmlCatalogDefaultPrefer, NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2691 | } |
| 2692 | xmlFree(content); |
| 2693 | return (catal); |
| 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * xmlExpandCatalog: |
| 2698 | * @catal: a catalog |
| 2699 | * @filename: a file path |
| 2700 | * |
| 2701 | * Load the catalog and expand the existing catal structure. |
| 2702 | * This can be either an XML Catalog or an SGML Catalog |
| 2703 | * |
| 2704 | * Returns 0 in case of success, -1 in case of error |
| 2705 | */ |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 2706 | static int |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2707 | xmlExpandCatalog(xmlCatalogPtr catal, const char *filename) |
| 2708 | { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2709 | int ret; |
| 2710 | |
| 2711 | if ((catal == NULL) || (filename == NULL)) |
| 2712 | return(-1); |
| 2713 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2714 | |
| 2715 | if (catal->type == XML_SGML_CATALOG_TYPE) { |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 2716 | xmlChar *content; |
| 2717 | |
| 2718 | content = xmlLoadFileContent(filename); |
| 2719 | if (content == NULL) |
| 2720 | return(-1); |
| 2721 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2722 | ret = xmlParseSGMLCatalog(catal, content, filename, 0); |
| 2723 | if (ret < 0) { |
| 2724 | xmlFree(content); |
| 2725 | return(-1); |
| 2726 | } |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 2727 | xmlFree(content); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2728 | } else { |
| 2729 | xmlCatalogEntryPtr tmp, cur; |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 2730 | tmp = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 2731 | NULL, BAD_CAST filename, xmlCatalogDefaultPrefer, NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2732 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2733 | cur = catal->xml; |
| 2734 | if (cur == NULL) { |
| 2735 | catal->xml = tmp; |
| 2736 | } else { |
| 2737 | while (cur->next != NULL) cur = cur->next; |
| 2738 | cur->next = tmp; |
| 2739 | } |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2740 | } |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2741 | return (0); |
| 2742 | } |
| 2743 | |
| 2744 | /** |
| 2745 | * xmlACatalogResolveSystem: |
| 2746 | * @catal: a Catalog |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2747 | * @sysID: the system ID string |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2748 | * |
| 2749 | * Try to lookup the catalog resource for a system ID |
| 2750 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2751 | * Returns the resource if found or NULL otherwise, the value returned |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2752 | * must be freed by the caller. |
| 2753 | */ |
| 2754 | xmlChar * |
| 2755 | xmlACatalogResolveSystem(xmlCatalogPtr catal, const xmlChar *sysID) { |
| 2756 | xmlChar *ret = NULL; |
| 2757 | |
| 2758 | if ((sysID == NULL) || (catal == NULL)) |
| 2759 | return(NULL); |
| 2760 | |
| 2761 | if (xmlDebugCatalogs) |
| 2762 | xmlGenericError(xmlGenericErrorContext, |
| 2763 | "Resolve sysID %s\n", sysID); |
| 2764 | |
| 2765 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2766 | ret = xmlCatalogListXMLResolve(catal->xml, NULL, sysID); |
| 2767 | if (ret == XML_CATAL_BREAK) |
| 2768 | ret = NULL; |
| 2769 | } else { |
| 2770 | const xmlChar *sgml; |
| 2771 | |
| 2772 | sgml = xmlCatalogGetSGMLSystem(catal->sgml, sysID); |
| 2773 | if (sgml != NULL) |
| 2774 | ret = xmlStrdup(sgml); |
| 2775 | } |
| 2776 | return(ret); |
| 2777 | } |
| 2778 | |
| 2779 | /** |
| 2780 | * xmlACatalogResolvePublic: |
| 2781 | * @catal: a Catalog |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 2782 | * @pubID: the public ID string |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2783 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2784 | * Try to lookup the catalog local reference associated to a public ID in that catalog |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2785 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 2786 | * Returns the local resource if found or NULL otherwise, the value returned |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2787 | * must be freed by the caller. |
| 2788 | */ |
| 2789 | xmlChar * |
| 2790 | xmlACatalogResolvePublic(xmlCatalogPtr catal, const xmlChar *pubID) { |
| 2791 | xmlChar *ret = NULL; |
| 2792 | |
| 2793 | if ((pubID == NULL) || (catal == NULL)) |
| 2794 | return(NULL); |
| 2795 | |
| 2796 | if (xmlDebugCatalogs) |
| 2797 | xmlGenericError(xmlGenericErrorContext, |
| 2798 | "Resolve pubID %s\n", pubID); |
| 2799 | |
| 2800 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2801 | ret = xmlCatalogListXMLResolve(catal->xml, pubID, NULL); |
| 2802 | if (ret == XML_CATAL_BREAK) |
| 2803 | ret = NULL; |
| 2804 | } else { |
| 2805 | const xmlChar *sgml; |
| 2806 | |
| 2807 | sgml = xmlCatalogGetSGMLPublic(catal->sgml, pubID); |
| 2808 | if (sgml != NULL) |
| 2809 | ret = xmlStrdup(sgml); |
| 2810 | } |
| 2811 | return(ret); |
| 2812 | } |
| 2813 | |
| 2814 | /** |
| 2815 | * xmlACatalogResolve: |
| 2816 | * @catal: a Catalog |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 2817 | * @pubID: the public ID string |
| 2818 | * @sysID: the system ID string |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2819 | * |
| 2820 | * Do a complete resolution lookup of an External Identifier |
| 2821 | * |
| 2822 | * Returns the URI of the resource or NULL if not found, it must be freed |
| 2823 | * by the caller. |
| 2824 | */ |
| 2825 | xmlChar * |
| 2826 | xmlACatalogResolve(xmlCatalogPtr catal, const xmlChar * pubID, |
| 2827 | const xmlChar * sysID) |
| 2828 | { |
| 2829 | xmlChar *ret = NULL; |
| 2830 | |
| 2831 | if (((pubID == NULL) && (sysID == NULL)) || (catal == NULL)) |
| 2832 | return (NULL); |
| 2833 | |
| 2834 | if (xmlDebugCatalogs) { |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 2835 | if ((pubID != NULL) && (sysID != NULL)) { |
| 2836 | xmlGenericError(xmlGenericErrorContext, |
| 2837 | "Resolve: pubID %s sysID %s\n", pubID, sysID); |
| 2838 | } else if (pubID != NULL) { |
| 2839 | xmlGenericError(xmlGenericErrorContext, |
| 2840 | "Resolve: pubID %s\n", pubID); |
| 2841 | } else { |
| 2842 | xmlGenericError(xmlGenericErrorContext, |
| 2843 | "Resolve: sysID %s\n", sysID); |
| 2844 | } |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2848 | ret = xmlCatalogListXMLResolve(catal->xml, pubID, sysID); |
| 2849 | if (ret == XML_CATAL_BREAK) |
| 2850 | ret = NULL; |
| 2851 | } else { |
| 2852 | const xmlChar *sgml; |
| 2853 | |
| 2854 | sgml = xmlCatalogSGMLResolve(catal, pubID, sysID); |
| 2855 | if (sgml != NULL) |
| 2856 | ret = xmlStrdup(sgml); |
| 2857 | } |
| 2858 | return (ret); |
| 2859 | } |
| 2860 | |
| 2861 | /** |
| 2862 | * xmlACatalogResolveURI: |
| 2863 | * @catal: a Catalog |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2864 | * @URI: the URI |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2865 | * |
| 2866 | * Do a complete resolution lookup of an URI |
| 2867 | * |
| 2868 | * Returns the URI of the resource or NULL if not found, it must be freed |
| 2869 | * by the caller. |
| 2870 | */ |
| 2871 | xmlChar * |
| 2872 | xmlACatalogResolveURI(xmlCatalogPtr catal, const xmlChar *URI) { |
| 2873 | xmlChar *ret = NULL; |
| 2874 | |
| 2875 | if ((URI == NULL) || (catal == NULL)) |
| 2876 | return(NULL); |
| 2877 | |
Daniel Veillard | b44025c | 2001-10-11 22:55:55 +0000 | [diff] [blame] | 2878 | if (xmlDebugCatalogs) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2879 | xmlGenericError(xmlGenericErrorContext, |
| 2880 | "Resolve URI %s\n", URI); |
| 2881 | |
| 2882 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2883 | ret = xmlCatalogListXMLResolveURI(catal->xml, URI); |
| 2884 | if (ret == XML_CATAL_BREAK) |
| 2885 | ret = NULL; |
| 2886 | } else { |
| 2887 | const xmlChar *sgml; |
| 2888 | |
| 2889 | sgml = xmlCatalogSGMLResolve(catal, NULL, URI); |
| 2890 | if (sgml != NULL) |
| 2891 | sgml = xmlStrdup(sgml); |
| 2892 | } |
| 2893 | return(ret); |
| 2894 | } |
| 2895 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2896 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2897 | /** |
| 2898 | * xmlACatalogDump: |
| 2899 | * @catal: a Catalog |
| 2900 | * @out: the file. |
| 2901 | * |
Daniel Veillard | a8dc288 | 2004-03-29 12:21:26 +0000 | [diff] [blame] | 2902 | * Dump the given catalog to the given file. |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2903 | */ |
| 2904 | void |
| 2905 | xmlACatalogDump(xmlCatalogPtr catal, FILE *out) { |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 2906 | if ((out == NULL) || (catal == NULL)) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2907 | return; |
| 2908 | |
| 2909 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2910 | xmlDumpXMLCatalog(out, catal->xml); |
| 2911 | } else { |
| 2912 | xmlHashScan(catal->sgml, |
| 2913 | (xmlHashScanner) xmlCatalogDumpEntry, out); |
| 2914 | } |
| 2915 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 2916 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2917 | |
| 2918 | /** |
| 2919 | * xmlACatalogAdd: |
| 2920 | * @catal: a Catalog |
| 2921 | * @type: the type of record to add to the catalog |
| 2922 | * @orig: the system, public or prefix to match |
| 2923 | * @replace: the replacement value for the match |
| 2924 | * |
| 2925 | * Add an entry in the catalog, it may overwrite existing but |
| 2926 | * different entries. |
| 2927 | * |
| 2928 | * Returns 0 if successful, -1 otherwise |
| 2929 | */ |
| 2930 | int |
| 2931 | xmlACatalogAdd(xmlCatalogPtr catal, const xmlChar * type, |
| 2932 | const xmlChar * orig, const xmlChar * replace) |
| 2933 | { |
| 2934 | int res = -1; |
| 2935 | |
| 2936 | if (catal == NULL) |
| 2937 | return(-1); |
| 2938 | |
| 2939 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2940 | res = xmlAddXMLCatalog(catal->xml, type, orig, replace); |
| 2941 | } else { |
| 2942 | xmlCatalogEntryType cattype; |
| 2943 | |
| 2944 | cattype = xmlGetSGMLCatalogEntryType(type); |
| 2945 | if (cattype != XML_CATA_NONE) { |
| 2946 | xmlCatalogEntryPtr entry; |
| 2947 | |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 2948 | entry = xmlNewCatalogEntry(cattype, orig, replace, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 2949 | XML_CATA_PREFER_NONE, NULL); |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 2950 | if (catal->sgml == NULL) |
| 2951 | catal->sgml = xmlHashCreate(10); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 2952 | res = xmlHashAddEntry(catal->sgml, orig, entry); |
| 2953 | } |
| 2954 | } |
| 2955 | return (res); |
| 2956 | } |
| 2957 | |
| 2958 | /** |
| 2959 | * xmlACatalogRemove: |
| 2960 | * @catal: a Catalog |
| 2961 | * @value: the value to remove |
| 2962 | * |
| 2963 | * Remove an entry from the catalog |
| 2964 | * |
| 2965 | * Returns the number of entries removed if successful, -1 otherwise |
| 2966 | */ |
| 2967 | int |
| 2968 | xmlACatalogRemove(xmlCatalogPtr catal, const xmlChar *value) { |
| 2969 | int res = -1; |
| 2970 | |
| 2971 | if ((catal == NULL) || (value == NULL)) |
| 2972 | return(-1); |
| 2973 | |
| 2974 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 2975 | res = xmlDelXMLCatalog(catal->xml, value); |
| 2976 | } else { |
| 2977 | res = xmlHashRemoveEntry(catal->sgml, value, |
| 2978 | (xmlHashDeallocator) xmlFreeCatalogEntry); |
| 2979 | if (res == 0) |
| 2980 | res = 1; |
| 2981 | } |
| 2982 | return(res); |
| 2983 | } |
| 2984 | |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 2985 | /** |
| 2986 | * xmlNewCatalog: |
| 2987 | * @sgml: should this create an SGML catalog |
| 2988 | * |
| 2989 | * create a new Catalog. |
| 2990 | * |
| 2991 | * Returns the xmlCatalogPtr or NULL in case of error |
| 2992 | */ |
| 2993 | xmlCatalogPtr |
| 2994 | xmlNewCatalog(int sgml) { |
| 2995 | xmlCatalogPtr catal = NULL; |
| 2996 | |
| 2997 | if (sgml) { |
| 2998 | catal = xmlCreateNewCatalog(XML_SGML_CATALOG_TYPE, |
| 2999 | xmlCatalogDefaultPrefer); |
| 3000 | if ((catal != NULL) && (catal->sgml == NULL)) |
| 3001 | catal->sgml = xmlHashCreate(10); |
| 3002 | } else |
| 3003 | catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE, |
| 3004 | xmlCatalogDefaultPrefer); |
| 3005 | return(catal); |
| 3006 | } |
| 3007 | |
| 3008 | /** |
| 3009 | * xmlCatalogIsEmpty: |
| 3010 | * @catal: should this create an SGML catalog |
| 3011 | * |
| 3012 | * Check is a catalog is empty |
| 3013 | * |
| 3014 | * Returns 1 if the catalog is empty, 0 if not, amd -1 in case of error. |
| 3015 | */ |
| 3016 | int |
| 3017 | xmlCatalogIsEmpty(xmlCatalogPtr catal) { |
| 3018 | if (catal == NULL) |
| 3019 | return(-1); |
| 3020 | |
| 3021 | if (catal->type == XML_XML_CATALOG_TYPE) { |
| 3022 | if (catal->xml == NULL) |
| 3023 | return(1); |
| 3024 | if ((catal->xml->type != XML_CATA_CATALOG) && |
| 3025 | (catal->xml->type != XML_CATA_BROKEN_CATALOG)) |
| 3026 | return(-1); |
| 3027 | if (catal->xml->children == NULL) |
| 3028 | return(1); |
| 3029 | return(0); |
| 3030 | } else { |
| 3031 | int res; |
| 3032 | |
| 3033 | if (catal->sgml == NULL) |
| 3034 | return(1); |
| 3035 | res = xmlHashSize(catal->sgml); |
| 3036 | if (res == 0) |
| 3037 | return(1); |
| 3038 | if (res < 0) |
| 3039 | return(-1); |
| 3040 | } |
| 3041 | return(0); |
| 3042 | } |
| 3043 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3044 | /************************************************************************ |
| 3045 | * * |
| 3046 | * Public interfaces manipulating the global shared default catalog * |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3047 | * * |
| 3048 | ************************************************************************/ |
| 3049 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 3050 | /** |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3051 | * xmlInitializeCatalogData: |
| 3052 | * |
| 3053 | * Do the catalog initialization only of global data, doesn't try to load |
| 3054 | * any catalog actually. |
| 3055 | * this function is not thread safe, catalog initialization should |
| 3056 | * preferably be done once at startup |
| 3057 | */ |
| 3058 | static void |
| 3059 | xmlInitializeCatalogData(void) { |
| 3060 | if (xmlCatalogInitialized != 0) |
| 3061 | return; |
| 3062 | |
| 3063 | if (getenv("XML_DEBUG_CATALOG")) |
| 3064 | xmlDebugCatalogs = 1; |
| 3065 | xmlCatalogMutex = xmlNewRMutex(); |
| 3066 | |
| 3067 | xmlCatalogInitialized = 1; |
| 3068 | } |
| 3069 | /** |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3070 | * xmlInitializeCatalog: |
| 3071 | * |
| 3072 | * Do the catalog initialization. |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3073 | * this function is not thread safe, catalog initialization should |
| 3074 | * preferably be done once at startup |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3075 | */ |
| 3076 | void |
| 3077 | xmlInitializeCatalog(void) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3078 | if (xmlCatalogInitialized != 0) |
| 3079 | return; |
| 3080 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3081 | xmlInitializeCatalogData(); |
| 3082 | xmlRMutexLock(xmlCatalogMutex); |
| 3083 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3084 | if (getenv("XML_DEBUG_CATALOG")) |
| 3085 | xmlDebugCatalogs = 1; |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3086 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3087 | if (xmlDefaultCatalog == NULL) { |
| 3088 | const char *catalogs; |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3089 | char *path; |
| 3090 | const char *cur, *paths; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3091 | xmlCatalogPtr catal; |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3092 | xmlCatalogEntryPtr *nextent; |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3093 | |
Daniel Veillard | b44025c | 2001-10-11 22:55:55 +0000 | [diff] [blame] | 3094 | catalogs = (const char *) getenv("XML_CATALOG_FILES"); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3095 | if (catalogs == NULL) |
Daniel Veillard | fb382b8 | 2004-06-14 12:13:12 +0000 | [diff] [blame] | 3096 | #if defined(_WIN32) && defined(_MSC_VER) |
| 3097 | { |
| 3098 | void* hmodule; |
| 3099 | hmodule = GetModuleHandleA("libxml2.dll"); |
| 3100 | if (hmodule == NULL) |
| 3101 | hmodule = GetModuleHandleA(NULL); |
| 3102 | if (hmodule != NULL) { |
| 3103 | char buf[256]; |
| 3104 | unsigned long len = GetModuleFileNameA(hmodule, buf, 255); |
| 3105 | if (len != 0) { |
| 3106 | char* p = &(buf[len]); |
| 3107 | while (*p != '\\' && p > buf) |
| 3108 | p--; |
| 3109 | if (p != buf) { |
| 3110 | xmlChar* uri; |
| 3111 | strncpy(p, "\\..\\etc\\catalog", 255 - (p - buf)); |
| 3112 | uri = xmlCanonicPath(buf); |
| 3113 | if (uri != NULL) { |
| 3114 | strncpy(XML_XML_DEFAULT_CATALOG, uri, 255); |
| 3115 | xmlFree(uri); |
| 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | } |
| 3120 | catalogs = XML_XML_DEFAULT_CATALOG; |
| 3121 | } |
| 3122 | #else |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3123 | catalogs = XML_XML_DEFAULT_CATALOG; |
Daniel Veillard | fb382b8 | 2004-06-14 12:13:12 +0000 | [diff] [blame] | 3124 | #endif |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3125 | |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3126 | catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE, |
| 3127 | xmlCatalogDefaultPrefer); |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 3128 | if (catal != NULL) { |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3129 | /* the XML_CATALOG_FILES envvar is allowed to contain a |
| 3130 | space-separated list of entries. */ |
| 3131 | cur = catalogs; |
| 3132 | nextent = &catal->xml; |
| 3133 | while (*cur != '\0') { |
William M. Brack | 68aca05 | 2003-10-11 15:22:13 +0000 | [diff] [blame] | 3134 | while (xmlIsBlank_ch(*cur)) |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3135 | cur++; |
| 3136 | if (*cur != 0) { |
| 3137 | paths = cur; |
William M. Brack | 68aca05 | 2003-10-11 15:22:13 +0000 | [diff] [blame] | 3138 | while ((*cur != 0) && (!xmlIsBlank_ch(*cur))) |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3139 | cur++; |
Daniel Veillard | e645e8c | 2002-10-22 17:35:37 +0000 | [diff] [blame] | 3140 | path = (char *) xmlStrndup((const xmlChar *)paths, cur - paths); |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3141 | if (path != NULL) { |
| 3142 | *nextent = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 3143 | NULL, BAD_CAST path, xmlCatalogDefaultPrefer, NULL); |
Igor Zlatkovic | 124ec31 | 2002-10-04 13:32:49 +0000 | [diff] [blame] | 3144 | if (*nextent != NULL) |
| 3145 | nextent = &((*nextent)->next); |
| 3146 | xmlFree(path); |
| 3147 | } |
| 3148 | } |
| 3149 | } |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 3150 | xmlDefaultCatalog = catal; |
| 3151 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3154 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
Daniel Veillard | 82d7533 | 2001-10-08 15:01:59 +0000 | [diff] [blame] | 3157 | |
| 3158 | /** |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3159 | * xmlLoadCatalog: |
| 3160 | * @filename: a file path |
| 3161 | * |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3162 | * Load the catalog and makes its definitions effective for the default |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3163 | * external entity loader. It will recurse in SGML CATALOG entries. |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3164 | * this function is not thread safe, catalog initialization should |
| 3165 | * preferably be done once at startup |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3166 | * |
| 3167 | * Returns 0 in case of success -1 in case of error |
| 3168 | */ |
| 3169 | int |
Daniel Veillard | 16756b6 | 2001-10-01 07:36:25 +0000 | [diff] [blame] | 3170 | xmlLoadCatalog(const char *filename) |
| 3171 | { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3172 | int ret; |
| 3173 | xmlCatalogPtr catal; |
Daniel Veillard | 16756b6 | 2001-10-01 07:36:25 +0000 | [diff] [blame] | 3174 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3175 | if (!xmlCatalogInitialized) |
| 3176 | xmlInitializeCatalogData(); |
| 3177 | |
| 3178 | xmlRMutexLock(xmlCatalogMutex); |
| 3179 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3180 | if (xmlDefaultCatalog == NULL) { |
| 3181 | catal = xmlLoadACatalog(filename); |
William M. Brack | 59002e7 | 2003-07-04 17:01:59 +0000 | [diff] [blame] | 3182 | if (catal == NULL) { |
| 3183 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3184 | return(-1); |
William M. Brack | 59002e7 | 2003-07-04 17:01:59 +0000 | [diff] [blame] | 3185 | } |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3186 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3187 | xmlDefaultCatalog = catal; |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3188 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3189 | return(0); |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 3190 | } |
Daniel Veillard | af86c7f | 2001-05-21 14:11:26 +0000 | [diff] [blame] | 3191 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3192 | ret = xmlExpandCatalog(xmlDefaultCatalog, filename); |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3193 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3194 | return(ret); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
Daniel Veillard | 5e2dace | 2001-07-18 19:30:27 +0000 | [diff] [blame] | 3197 | /** |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3198 | * xmlLoadCatalogs: |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 3199 | * @pathss: a list of directories separated by a colon or a space. |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3200 | * |
| 3201 | * Load the catalogs and makes their definitions effective for the default |
| 3202 | * external entity loader. |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3203 | * this function is not thread safe, catalog initialization should |
| 3204 | * preferably be done once at startup |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3205 | */ |
| 3206 | void |
| 3207 | xmlLoadCatalogs(const char *pathss) { |
| 3208 | const char *cur; |
| 3209 | const char *paths; |
| 3210 | xmlChar *path; |
| 3211 | |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3212 | if (pathss == NULL) |
| 3213 | return; |
| 3214 | |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3215 | cur = pathss; |
| 3216 | while ((cur != NULL) && (*cur != 0)) { |
William M. Brack | 68aca05 | 2003-10-11 15:22:13 +0000 | [diff] [blame] | 3217 | while (xmlIsBlank_ch(*cur)) cur++; |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3218 | if (*cur != 0) { |
| 3219 | paths = cur; |
William M. Brack | 68aca05 | 2003-10-11 15:22:13 +0000 | [diff] [blame] | 3220 | while ((*cur != 0) && (*cur != ':') && (!xmlIsBlank_ch(*cur))) |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3221 | cur++; |
| 3222 | path = xmlStrndup((const xmlChar *)paths, cur - paths); |
| 3223 | if (path != NULL) { |
| 3224 | xmlLoadCatalog((const char *) path); |
| 3225 | xmlFree(path); |
| 3226 | } |
| 3227 | } |
Igor Zlatkovic | 130e579 | 2002-11-06 22:51:58 +0000 | [diff] [blame] | 3228 | while (*cur == ':') |
| 3229 | cur++; |
Daniel Veillard | 81418e3 | 2001-05-22 15:08:55 +0000 | [diff] [blame] | 3230 | } |
| 3231 | } |
| 3232 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3233 | /** |
| 3234 | * xmlCatalogCleanup: |
| 3235 | * |
| 3236 | * Free up all the memory associated with catalogs |
| 3237 | */ |
| 3238 | void |
| 3239 | xmlCatalogCleanup(void) { |
Daniel Veillard | 364789a | 2001-10-16 12:45:00 +0000 | [diff] [blame] | 3240 | if (xmlCatalogInitialized == 0) |
| 3241 | return; |
| 3242 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3243 | xmlRMutexLock(xmlCatalogMutex); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3244 | if (xmlDebugCatalogs) |
| 3245 | xmlGenericError(xmlGenericErrorContext, |
| 3246 | "Catalogs cleanup\n"); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3247 | if (xmlCatalogXMLFiles != NULL) |
Daniel Veillard | 85c11fa | 2001-10-16 21:03:08 +0000 | [diff] [blame] | 3248 | xmlHashFree(xmlCatalogXMLFiles, |
| 3249 | (xmlHashDeallocator)xmlFreeCatalogHashEntryList); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3250 | xmlCatalogXMLFiles = NULL; |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3251 | if (xmlDefaultCatalog != NULL) |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3252 | xmlFreeCatalog(xmlDefaultCatalog); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3253 | xmlDefaultCatalog = NULL; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3254 | xmlDebugCatalogs = 0; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3255 | xmlCatalogInitialized = 0; |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3256 | xmlRMutexUnlock(xmlCatalogMutex); |
| 3257 | xmlFreeRMutex(xmlCatalogMutex); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | /** |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3261 | * xmlCatalogResolveSystem: |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3262 | * @sysID: the system ID string |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3263 | * |
| 3264 | * Try to lookup the catalog resource for a system ID |
| 3265 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3266 | * Returns the resource if found or NULL otherwise, the value returned |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3267 | * must be freed by the caller. |
| 3268 | */ |
| 3269 | xmlChar * |
| 3270 | xmlCatalogResolveSystem(const xmlChar *sysID) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3271 | xmlChar *ret; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3272 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3273 | if (!xmlCatalogInitialized) |
| 3274 | xmlInitializeCatalog(); |
| 3275 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3276 | ret = xmlACatalogResolveSystem(xmlDefaultCatalog, sysID); |
| 3277 | return(ret); |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | /** |
| 3281 | * xmlCatalogResolvePublic: |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 3282 | * @pubID: the public ID string |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3283 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3284 | * Try to lookup the catalog reference associated to a public ID |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3285 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3286 | * Returns the resource if found or NULL otherwise, the value returned |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3287 | * must be freed by the caller. |
| 3288 | */ |
| 3289 | xmlChar * |
| 3290 | xmlCatalogResolvePublic(const xmlChar *pubID) { |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3291 | xmlChar *ret; |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3292 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3293 | if (!xmlCatalogInitialized) |
| 3294 | xmlInitializeCatalog(); |
| 3295 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3296 | ret = xmlACatalogResolvePublic(xmlDefaultCatalog, pubID); |
| 3297 | return(ret); |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 3298 | } |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3299 | |
Daniel Veillard | 7d6fd21 | 2001-05-10 15:34:11 +0000 | [diff] [blame] | 3300 | /** |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 3301 | * xmlCatalogResolve: |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 3302 | * @pubID: the public ID string |
| 3303 | * @sysID: the system ID string |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 3304 | * |
| 3305 | * Do a complete resolution lookup of an External Identifier |
| 3306 | * |
| 3307 | * Returns the URI of the resource or NULL if not found, it must be freed |
| 3308 | * by the caller. |
| 3309 | */ |
| 3310 | xmlChar * |
| 3311 | xmlCatalogResolve(const xmlChar *pubID, const xmlChar *sysID) { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3312 | xmlChar *ret; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3313 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3314 | if (!xmlCatalogInitialized) |
| 3315 | xmlInitializeCatalog(); |
| 3316 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3317 | ret = xmlACatalogResolve(xmlDefaultCatalog, pubID, sysID); |
| 3318 | return(ret); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | /** |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3322 | * xmlCatalogResolveURI: |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3323 | * @URI: the URI |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3324 | * |
| 3325 | * Do a complete resolution lookup of an URI |
| 3326 | * |
| 3327 | * Returns the URI of the resource or NULL if not found, it must be freed |
| 3328 | * by the caller. |
| 3329 | */ |
| 3330 | xmlChar * |
| 3331 | xmlCatalogResolveURI(const xmlChar *URI) { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3332 | xmlChar *ret; |
| 3333 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3334 | if (!xmlCatalogInitialized) |
| 3335 | xmlInitializeCatalog(); |
| 3336 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3337 | ret = xmlACatalogResolveURI(xmlDefaultCatalog, URI); |
| 3338 | return(ret); |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3339 | } |
| 3340 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3341 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3342 | /** |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3343 | * xmlCatalogDump: |
| 3344 | * @out: the file. |
| 3345 | * |
Daniel Veillard | a8dc288 | 2004-03-29 12:21:26 +0000 | [diff] [blame] | 3346 | * Dump all the global catalog content to the given file. |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3347 | */ |
| 3348 | void |
| 3349 | xmlCatalogDump(FILE *out) { |
| 3350 | if (out == NULL) |
| 3351 | return; |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3352 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3353 | if (!xmlCatalogInitialized) |
| 3354 | xmlInitializeCatalog(); |
| 3355 | |
| 3356 | xmlACatalogDump(xmlDefaultCatalog, out); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3357 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 3358 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3359 | |
| 3360 | /** |
| 3361 | * xmlCatalogAdd: |
| 3362 | * @type: the type of record to add to the catalog |
| 3363 | * @orig: the system, public or prefix to match |
| 3364 | * @replace: the replacement value for the match |
| 3365 | * |
| 3366 | * Add an entry in the catalog, it may overwrite existing but |
| 3367 | * different entries. |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3368 | * If called before any other catalog routine, allows to override the |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3369 | * default shared catalog put in place by xmlInitializeCatalog(); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3370 | * |
| 3371 | * Returns 0 if successful, -1 otherwise |
| 3372 | */ |
| 3373 | int |
| 3374 | xmlCatalogAdd(const xmlChar *type, const xmlChar *orig, const xmlChar *replace) { |
| 3375 | int res = -1; |
| 3376 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3377 | if (!xmlCatalogInitialized) |
| 3378 | xmlInitializeCatalogData(); |
| 3379 | |
| 3380 | xmlRMutexLock(xmlCatalogMutex); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3381 | /* |
| 3382 | * Specific case where one want to override the default catalog |
| 3383 | * put in place by xmlInitializeCatalog(); |
| 3384 | */ |
| 3385 | if ((xmlDefaultCatalog == NULL) && |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 3386 | (xmlStrEqual(type, BAD_CAST "catalog"))) { |
Daniel Veillard | cd21dc7 | 2001-11-04 20:03:38 +0000 | [diff] [blame] | 3387 | xmlDefaultCatalog = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE, |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3388 | xmlCatalogDefaultPrefer); |
| 3389 | xmlDefaultCatalog->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 3390 | orig, NULL, xmlCatalogDefaultPrefer, NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3391 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3392 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | e7ead2d | 2001-08-22 23:44:09 +0000 | [diff] [blame] | 3393 | return(0); |
| 3394 | } |
| 3395 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3396 | res = xmlACatalogAdd(xmlDefaultCatalog, type, orig, replace); |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3397 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3398 | return(res); |
| 3399 | } |
| 3400 | |
| 3401 | /** |
| 3402 | * xmlCatalogRemove: |
| 3403 | * @value: the value to remove |
| 3404 | * |
| 3405 | * Remove an entry from the catalog |
| 3406 | * |
Daniel Veillard | 82d7533 | 2001-10-08 15:01:59 +0000 | [diff] [blame] | 3407 | * Returns the number of entries removed if successful, -1 otherwise |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3408 | */ |
| 3409 | int |
| 3410 | xmlCatalogRemove(const xmlChar *value) { |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3411 | int res; |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 3412 | |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3413 | if (!xmlCatalogInitialized) |
| 3414 | xmlInitializeCatalog(); |
| 3415 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3416 | xmlRMutexLock(xmlCatalogMutex); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3417 | res = xmlACatalogRemove(xmlDefaultCatalog, value); |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3418 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | cda9692 | 2001-08-21 10:56:31 +0000 | [diff] [blame] | 3419 | return(res); |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | /** |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3423 | * xmlCatalogConvert: |
| 3424 | * |
| 3425 | * Convert all the SGML catalog entries as XML ones |
| 3426 | * |
| 3427 | * Returns the number of entries converted if successful, -1 otherwise |
| 3428 | */ |
| 3429 | int |
| 3430 | xmlCatalogConvert(void) { |
| 3431 | int res = -1; |
| 3432 | |
| 3433 | if (!xmlCatalogInitialized) |
| 3434 | xmlInitializeCatalog(); |
| 3435 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3436 | xmlRMutexLock(xmlCatalogMutex); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3437 | res = xmlConvertSGMLCatalog(xmlDefaultCatalog); |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3438 | xmlRMutexUnlock(xmlCatalogMutex); |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3439 | return(res); |
| 3440 | } |
| 3441 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3442 | /************************************************************************ |
| 3443 | * * |
| 3444 | * Public interface manipulating the common preferences * |
| 3445 | * * |
| 3446 | ************************************************************************/ |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3447 | |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3448 | /** |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3449 | * xmlCatalogGetDefaults: |
| 3450 | * |
| 3451 | * Used to get the user preference w.r.t. to what catalogs should |
| 3452 | * be accepted |
| 3453 | * |
| 3454 | * Returns the current xmlCatalogAllow value |
| 3455 | */ |
| 3456 | xmlCatalogAllow |
| 3457 | xmlCatalogGetDefaults(void) { |
| 3458 | return(xmlCatalogDefaultAllow); |
| 3459 | } |
| 3460 | |
| 3461 | /** |
| 3462 | * xmlCatalogSetDefaults: |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3463 | * @allow: what catalogs should be accepted |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3464 | * |
| 3465 | * Used to set the user preference w.r.t. to what catalogs should |
| 3466 | * be accepted |
| 3467 | */ |
| 3468 | void |
| 3469 | xmlCatalogSetDefaults(xmlCatalogAllow allow) { |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3470 | if (xmlDebugCatalogs) { |
| 3471 | switch (allow) { |
| 3472 | case XML_CATA_ALLOW_NONE: |
| 3473 | xmlGenericError(xmlGenericErrorContext, |
| 3474 | "Disabling catalog usage\n"); |
| 3475 | break; |
| 3476 | case XML_CATA_ALLOW_GLOBAL: |
| 3477 | xmlGenericError(xmlGenericErrorContext, |
| 3478 | "Allowing only global catalogs\n"); |
| 3479 | break; |
| 3480 | case XML_CATA_ALLOW_DOCUMENT: |
| 3481 | xmlGenericError(xmlGenericErrorContext, |
| 3482 | "Allowing only catalogs from the document\n"); |
| 3483 | break; |
| 3484 | case XML_CATA_ALLOW_ALL: |
| 3485 | xmlGenericError(xmlGenericErrorContext, |
| 3486 | "Allowing all catalogs\n"); |
| 3487 | break; |
| 3488 | } |
| 3489 | } |
| 3490 | xmlCatalogDefaultAllow = allow; |
| 3491 | } |
| 3492 | |
| 3493 | /** |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3494 | * xmlCatalogSetDefaultPrefer: |
| 3495 | * @prefer: the default preference for delegation |
| 3496 | * |
| 3497 | * Allows to set the preference between public and system for deletion |
| 3498 | * in XML Catalog resolution. C.f. section 4.1.1 of the spec |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3499 | * Values accepted are XML_CATA_PREFER_PUBLIC or XML_CATA_PREFER_SYSTEM |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3500 | * |
| 3501 | * Returns the previous value of the default preference for delegation |
| 3502 | */ |
| 3503 | xmlCatalogPrefer |
| 3504 | xmlCatalogSetDefaultPrefer(xmlCatalogPrefer prefer) { |
| 3505 | xmlCatalogPrefer ret = xmlCatalogDefaultPrefer; |
| 3506 | |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3507 | if (prefer == XML_CATA_PREFER_NONE) |
| 3508 | return(ret); |
| 3509 | |
| 3510 | if (xmlDebugCatalogs) { |
| 3511 | switch (prefer) { |
| 3512 | case XML_CATA_PREFER_PUBLIC: |
| 3513 | xmlGenericError(xmlGenericErrorContext, |
| 3514 | "Setting catalog preference to PUBLIC\n"); |
| 3515 | break; |
| 3516 | case XML_CATA_PREFER_SYSTEM: |
| 3517 | xmlGenericError(xmlGenericErrorContext, |
| 3518 | "Setting catalog preference to SYSTEM\n"); |
| 3519 | break; |
| 3520 | case XML_CATA_PREFER_NONE: |
| 3521 | break; |
| 3522 | } |
| 3523 | } |
Daniel Veillard | e2940dd | 2001-08-22 00:06:49 +0000 | [diff] [blame] | 3524 | xmlCatalogDefaultPrefer = prefer; |
| 3525 | return(ret); |
| 3526 | } |
| 3527 | |
| 3528 | /** |
Daniel Veillard | 344cee7 | 2001-08-20 00:08:40 +0000 | [diff] [blame] | 3529 | * xmlCatalogSetDebug: |
| 3530 | * @level: the debug level of catalogs required |
| 3531 | * |
| 3532 | * Used to set the debug level for catalog operation, 0 disable |
| 3533 | * debugging, 1 enable it |
| 3534 | * |
| 3535 | * Returns the previous value of the catalog debugging level |
| 3536 | */ |
| 3537 | int |
| 3538 | xmlCatalogSetDebug(int level) { |
| 3539 | int ret = xmlDebugCatalogs; |
| 3540 | |
| 3541 | if (level <= 0) |
| 3542 | xmlDebugCatalogs = 0; |
| 3543 | else |
| 3544 | xmlDebugCatalogs = level; |
| 3545 | return(ret); |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3546 | } |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3547 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3548 | /************************************************************************ |
| 3549 | * * |
| 3550 | * Minimal interfaces used for per-document catalogs by the parser * |
| 3551 | * * |
| 3552 | ************************************************************************/ |
| 3553 | |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3554 | /** |
| 3555 | * xmlCatalogFreeLocal: |
| 3556 | * @catalogs: a document's list of catalogs |
| 3557 | * |
| 3558 | * Free up the memory associated to the catalog list |
| 3559 | */ |
| 3560 | void |
| 3561 | xmlCatalogFreeLocal(void *catalogs) { |
| 3562 | xmlCatalogEntryPtr catal; |
| 3563 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3564 | if (!xmlCatalogInitialized) |
| 3565 | xmlInitializeCatalog(); |
| 3566 | |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3567 | catal = (xmlCatalogEntryPtr) catalogs; |
| 3568 | if (catal != NULL) |
| 3569 | xmlFreeCatalogEntryList(catal); |
| 3570 | } |
| 3571 | |
| 3572 | |
| 3573 | /** |
| 3574 | * xmlCatalogAddLocal: |
| 3575 | * @catalogs: a document's list of catalogs |
| 3576 | * @URL: the URL to a new local catalog |
| 3577 | * |
| 3578 | * Add the new entry to the catalog list |
| 3579 | * |
| 3580 | * Returns the updated list |
| 3581 | */ |
| 3582 | void * |
| 3583 | xmlCatalogAddLocal(void *catalogs, const xmlChar *URL) { |
| 3584 | xmlCatalogEntryPtr catal, add; |
| 3585 | |
| 3586 | if (!xmlCatalogInitialized) |
| 3587 | xmlInitializeCatalog(); |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3588 | |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3589 | if (URL == NULL) |
| 3590 | return(catalogs); |
| 3591 | |
| 3592 | if (xmlDebugCatalogs) |
| 3593 | xmlGenericError(xmlGenericErrorContext, |
| 3594 | "Adding document catalog %s\n", URL); |
| 3595 | |
Daniel Veillard | c853b32 | 2001-11-06 15:24:37 +0000 | [diff] [blame] | 3596 | add = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL, URL, NULL, |
William M. Brack | b7b54de | 2004-10-06 16:38:01 +0000 | [diff] [blame] | 3597 | xmlCatalogDefaultPrefer, NULL); |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3598 | if (add == NULL) |
| 3599 | return(catalogs); |
| 3600 | |
| 3601 | catal = (xmlCatalogEntryPtr) catalogs; |
| 3602 | if (catal == NULL) |
| 3603 | return((void *) add); |
| 3604 | |
| 3605 | while (catal->next != NULL) |
| 3606 | catal = catal->next; |
| 3607 | catal->next = add; |
| 3608 | return(catalogs); |
| 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * xmlCatalogLocalResolve: |
| 3613 | * @catalogs: a document's list of catalogs |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 3614 | * @pubID: the public ID string |
| 3615 | * @sysID: the system ID string |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3616 | * |
| 3617 | * Do a complete resolution lookup of an External Identifier using a |
| 3618 | * document's private catalog list |
| 3619 | * |
| 3620 | * Returns the URI of the resource or NULL if not found, it must be freed |
| 3621 | * by the caller. |
| 3622 | */ |
| 3623 | xmlChar * |
| 3624 | xmlCatalogLocalResolve(void *catalogs, const xmlChar *pubID, |
| 3625 | const xmlChar *sysID) { |
| 3626 | xmlCatalogEntryPtr catal; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3627 | xmlChar *ret; |
| 3628 | |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3629 | if (!xmlCatalogInitialized) |
| 3630 | xmlInitializeCatalog(); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3631 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3632 | if ((pubID == NULL) && (sysID == NULL)) |
| 3633 | return(NULL); |
| 3634 | |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3635 | if (xmlDebugCatalogs) { |
Daniel Veillard | 770075b | 2004-02-25 10:44:30 +0000 | [diff] [blame] | 3636 | if ((pubID != NULL) && (sysID != NULL)) { |
| 3637 | xmlGenericError(xmlGenericErrorContext, |
| 3638 | "Local Resolve: pubID %s sysID %s\n", pubID, sysID); |
| 3639 | } else if (pubID != NULL) { |
| 3640 | xmlGenericError(xmlGenericErrorContext, |
| 3641 | "Local Resolve: pubID %s\n", pubID); |
| 3642 | } else { |
| 3643 | xmlGenericError(xmlGenericErrorContext, |
| 3644 | "Local Resolve: sysID %s\n", sysID); |
| 3645 | } |
Daniel Veillard | 6c5f9d1 | 2001-08-25 13:33:14 +0000 | [diff] [blame] | 3646 | } |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3647 | |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3648 | catal = (xmlCatalogEntryPtr) catalogs; |
| 3649 | if (catal == NULL) |
| 3650 | return(NULL); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3651 | ret = xmlCatalogListXMLResolve(catal, pubID, sysID); |
| 3652 | if ((ret != NULL) && (ret != XML_CATAL_BREAK)) |
| 3653 | return(ret); |
| 3654 | return(NULL); |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 3655 | } |
| 3656 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3657 | /** |
| 3658 | * xmlCatalogLocalResolveURI: |
| 3659 | * @catalogs: a document's list of catalogs |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 3660 | * @URI: the URI |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3661 | * |
| 3662 | * Do a complete resolution lookup of an URI using a |
| 3663 | * document's private catalog list |
| 3664 | * |
| 3665 | * Returns the URI of the resource or NULL if not found, it must be freed |
| 3666 | * by the caller. |
| 3667 | */ |
| 3668 | xmlChar * |
| 3669 | xmlCatalogLocalResolveURI(void *catalogs, const xmlChar *URI) { |
| 3670 | xmlCatalogEntryPtr catal; |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3671 | xmlChar *ret; |
| 3672 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3673 | if (!xmlCatalogInitialized) |
| 3674 | xmlInitializeCatalog(); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3675 | |
Daniel Veillard | 8146394 | 2001-10-16 12:34:39 +0000 | [diff] [blame] | 3676 | if (URI == NULL) |
| 3677 | return(NULL); |
| 3678 | |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3679 | if (xmlDebugCatalogs) |
| 3680 | xmlGenericError(xmlGenericErrorContext, |
| 3681 | "Resolve URI %s\n", URI); |
| 3682 | |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3683 | catal = (xmlCatalogEntryPtr) catalogs; |
| 3684 | if (catal == NULL) |
| 3685 | return(NULL); |
Daniel Veillard | 6990bf3 | 2001-08-23 21:17:48 +0000 | [diff] [blame] | 3686 | ret = xmlCatalogListXMLResolveURI(catal, URI); |
| 3687 | if ((ret != NULL) && (ret != XML_CATAL_BREAK)) |
| 3688 | return(ret); |
| 3689 | return(NULL); |
Daniel Veillard | dc2cee2 | 2001-08-22 16:30:37 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3692 | /************************************************************************ |
| 3693 | * * |
| 3694 | * Deprecated interfaces * |
| 3695 | * * |
| 3696 | ************************************************************************/ |
| 3697 | /** |
| 3698 | * xmlCatalogGetSystem: |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 3699 | * @sysID: the system ID string |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3700 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3701 | * Try to lookup the catalog reference associated to a system ID |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3702 | * DEPRECATED, use xmlCatalogResolveSystem() |
| 3703 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3704 | * Returns the resource if found or NULL otherwise. |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3705 | */ |
| 3706 | const xmlChar * |
| 3707 | xmlCatalogGetSystem(const xmlChar *sysID) { |
Daniel Veillard | ab690c5 | 2004-06-14 12:19:09 +0000 | [diff] [blame] | 3708 | xmlChar *ret; |
| 3709 | static xmlChar result[1000]; |
| 3710 | static int msg = 0; |
| 3711 | |
| 3712 | if (!xmlCatalogInitialized) |
| 3713 | xmlInitializeCatalog(); |
| 3714 | |
| 3715 | if (msg == 0) { |
| 3716 | xmlGenericError(xmlGenericErrorContext, |
| 3717 | "Use of deprecated xmlCatalogGetSystem() call\n"); |
| 3718 | msg++; |
| 3719 | } |
| 3720 | |
| 3721 | if (sysID == NULL) |
| 3722 | return(NULL); |
| 3723 | |
| 3724 | /* |
| 3725 | * Check first the XML catalogs |
| 3726 | */ |
| 3727 | if (xmlDefaultCatalog != NULL) { |
| 3728 | ret = xmlCatalogListXMLResolve(xmlDefaultCatalog->xml, NULL, sysID); |
| 3729 | if ((ret != NULL) && (ret != XML_CATAL_BREAK)) { |
| 3730 | snprintf((char *) result, sizeof(result) - 1, "%s", (char *) ret); |
| 3731 | result[sizeof(result) - 1] = 0; |
| 3732 | return(result); |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | if (xmlDefaultCatalog != NULL) |
| 3737 | return(xmlCatalogGetSGMLSystem(xmlDefaultCatalog->sgml, sysID)); |
| 3738 | return(NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | /** |
| 3742 | * xmlCatalogGetPublic: |
Daniel Veillard | 5aad832 | 2002-12-11 15:59:44 +0000 | [diff] [blame] | 3743 | * @pubID: the public ID string |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3744 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3745 | * Try to lookup the catalog reference associated to a public ID |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3746 | * DEPRECATED, use xmlCatalogResolvePublic() |
| 3747 | * |
Daniel Veillard | 06d2524 | 2004-02-25 13:01:42 +0000 | [diff] [blame] | 3748 | * Returns the resource if found or NULL otherwise. |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3749 | */ |
| 3750 | const xmlChar * |
| 3751 | xmlCatalogGetPublic(const xmlChar *pubID) { |
Daniel Veillard | ab690c5 | 2004-06-14 12:19:09 +0000 | [diff] [blame] | 3752 | xmlChar *ret; |
| 3753 | static xmlChar result[1000]; |
| 3754 | static int msg = 0; |
| 3755 | |
| 3756 | if (!xmlCatalogInitialized) |
| 3757 | xmlInitializeCatalog(); |
| 3758 | |
| 3759 | if (msg == 0) { |
| 3760 | xmlGenericError(xmlGenericErrorContext, |
| 3761 | "Use of deprecated xmlCatalogGetPublic() call\n"); |
| 3762 | msg++; |
| 3763 | } |
| 3764 | |
| 3765 | if (pubID == NULL) |
| 3766 | return(NULL); |
| 3767 | |
| 3768 | /* |
| 3769 | * Check first the XML catalogs |
| 3770 | */ |
| 3771 | if (xmlDefaultCatalog != NULL) { |
| 3772 | ret = xmlCatalogListXMLResolve(xmlDefaultCatalog->xml, pubID, NULL); |
| 3773 | if ((ret != NULL) && (ret != XML_CATAL_BREAK)) { |
| 3774 | snprintf((char *) result, sizeof(result) - 1, "%s", (char *) ret); |
| 3775 | result[sizeof(result) - 1] = 0; |
| 3776 | return(result); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | if (xmlDefaultCatalog != NULL) |
| 3781 | return(xmlCatalogGetSGMLPublic(xmlDefaultCatalog->sgml, pubID)); |
| 3782 | return(NULL); |
Daniel Veillard | 75b9682 | 2001-10-11 18:59:45 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
Daniel Veillard | a737459 | 2001-05-10 14:17:55 +0000 | [diff] [blame] | 3785 | #endif /* LIBXML_CATALOG_ENABLED */ |