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