Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 2 | * entities.c : implementation for the XML entities handling |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * daniel@veillard.com |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 9 | #define IN_LIBXML |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 10 | #include "libxml.h" |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 11 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 12 | #include <string.h> |
| 13 | #ifdef HAVE_STDLIB_H |
| 14 | #include <stdlib.h> |
| 15 | #endif |
| 16 | #include <libxml/xmlmemory.h> |
| 17 | #include <libxml/hash.h> |
| 18 | #include <libxml/entities.h> |
| 19 | #include <libxml/parser.h> |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 20 | #include <libxml/parserInternals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 21 | #include <libxml/xmlerror.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 22 | #include <libxml/globals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 23 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 24 | /* |
| 25 | * The XML predefined entities. |
| 26 | */ |
| 27 | |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 28 | static xmlEntity xmlEntityLt = { |
| 29 | NULL, XML_ENTITY_DECL, BAD_CAST "lt", |
| 30 | NULL, NULL, NULL, NULL, NULL, NULL, |
| 31 | BAD_CAST "<", BAD_CAST "<", 1, |
| 32 | XML_INTERNAL_PREDEFINED_ENTITY, |
| 33 | NULL, NULL, NULL, NULL, 0 |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 34 | }; |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 35 | static xmlEntity xmlEntityGt = { |
| 36 | NULL, XML_ENTITY_DECL, BAD_CAST "gt", |
| 37 | NULL, NULL, NULL, NULL, NULL, NULL, |
| 38 | BAD_CAST ">", BAD_CAST ">", 1, |
| 39 | XML_INTERNAL_PREDEFINED_ENTITY, |
| 40 | NULL, NULL, NULL, NULL, 0 |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 41 | }; |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 42 | static xmlEntity xmlEntityAmp = { |
| 43 | NULL, XML_ENTITY_DECL, BAD_CAST "amp", |
| 44 | NULL, NULL, NULL, NULL, NULL, NULL, |
| 45 | BAD_CAST "&", BAD_CAST "&", 1, |
| 46 | XML_INTERNAL_PREDEFINED_ENTITY, |
| 47 | NULL, NULL, NULL, NULL, 0 |
| 48 | }; |
| 49 | static xmlEntity xmlEntityQuot = { |
| 50 | NULL, XML_ENTITY_DECL, BAD_CAST "quot", |
| 51 | NULL, NULL, NULL, NULL, NULL, NULL, |
| 52 | BAD_CAST "\"", BAD_CAST "\"", 1, |
| 53 | XML_INTERNAL_PREDEFINED_ENTITY, |
| 54 | NULL, NULL, NULL, NULL, 0 |
| 55 | }; |
| 56 | static xmlEntity xmlEntityApos = { |
| 57 | NULL, XML_ENTITY_DECL, BAD_CAST "apos", |
| 58 | NULL, NULL, NULL, NULL, NULL, NULL, |
| 59 | BAD_CAST "'", BAD_CAST "'", 1, |
| 60 | XML_INTERNAL_PREDEFINED_ENTITY, |
| 61 | NULL, NULL, NULL, NULL, 0 |
| 62 | }; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * xmlFreeEntity : clean-up an entity record. |
| 66 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 67 | static void xmlFreeEntity(xmlEntityPtr entity) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 68 | if (entity == NULL) return; |
| 69 | |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 70 | if ((entity->children) && (entity->owner == 1) && |
Daniel Veillard | 2209073 | 2001-07-16 00:06:07 +0000 | [diff] [blame] | 71 | (entity == (xmlEntityPtr) entity->children->parent)) |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 72 | xmlFreeNodeList(entity->children); |
| 73 | if (entity->name != NULL) |
| 74 | xmlFree((char *) entity->name); |
| 75 | if (entity->ExternalID != NULL) |
| 76 | xmlFree((char *) entity->ExternalID); |
| 77 | if (entity->SystemID != NULL) |
| 78 | xmlFree((char *) entity->SystemID); |
| 79 | if (entity->URI != NULL) |
| 80 | xmlFree((char *) entity->URI); |
| 81 | if (entity->content != NULL) |
| 82 | xmlFree((char *) entity->content); |
| 83 | if (entity->orig != NULL) |
| 84 | xmlFree((char *) entity->orig); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 85 | xmlFree(entity); |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * xmlAddEntity : register a new entity for an entities table. |
| 90 | */ |
| 91 | static xmlEntityPtr |
| 92 | xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type, |
| 93 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 94 | const xmlChar *content) { |
| 95 | xmlEntitiesTablePtr table = NULL; |
| 96 | xmlEntityPtr ret; |
| 97 | |
| 98 | if (name == NULL) |
| 99 | return(NULL); |
| 100 | switch (type) { |
| 101 | case XML_INTERNAL_GENERAL_ENTITY: |
| 102 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 103 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 104 | if (dtd->entities == NULL) |
| 105 | dtd->entities = xmlHashCreate(0); |
| 106 | table = dtd->entities; |
| 107 | break; |
| 108 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 109 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 110 | if (dtd->pentities == NULL) |
| 111 | dtd->pentities = xmlHashCreate(0); |
| 112 | table = dtd->pentities; |
| 113 | break; |
| 114 | case XML_INTERNAL_PREDEFINED_ENTITY: |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 115 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 116 | } |
| 117 | if (table == NULL) |
| 118 | return(NULL); |
| 119 | ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); |
| 120 | if (ret == NULL) { |
| 121 | xmlGenericError(xmlGenericErrorContext, |
| 122 | "xmlAddEntity: out of memory\n"); |
| 123 | return(NULL); |
| 124 | } |
| 125 | memset(ret, 0, sizeof(xmlEntity)); |
| 126 | ret->type = XML_ENTITY_DECL; |
| 127 | |
| 128 | /* |
| 129 | * fill the structure. |
| 130 | */ |
| 131 | ret->name = xmlStrdup(name); |
| 132 | ret->etype = (xmlEntityType) type; |
| 133 | if (ExternalID != NULL) |
| 134 | ret->ExternalID = xmlStrdup(ExternalID); |
| 135 | if (SystemID != NULL) |
| 136 | ret->SystemID = xmlStrdup(SystemID); |
| 137 | if (content != NULL) { |
| 138 | ret->length = xmlStrlen(content); |
| 139 | ret->content = xmlStrndup(content, ret->length); |
| 140 | } else { |
| 141 | ret->length = 0; |
| 142 | ret->content = NULL; |
| 143 | } |
| 144 | ret->URI = NULL; /* to be computed by the layer knowing |
| 145 | the defining entity */ |
| 146 | ret->orig = NULL; |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 147 | ret->owner = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 148 | |
| 149 | if (xmlHashAddEntry(table, name, ret)) { |
| 150 | /* |
| 151 | * entity was already defined at another level. |
| 152 | */ |
| 153 | xmlFreeEntity(ret); |
| 154 | return(NULL); |
| 155 | } |
| 156 | return(ret); |
| 157 | } |
| 158 | |
| 159 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 160 | * xmlGetPredefinedEntity: |
| 161 | * @name: the entity name |
| 162 | * |
| 163 | * Check whether this name is an predefined entity. |
| 164 | * |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 165 | * Returns NULL if not, otherwise the entity |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 166 | */ |
| 167 | xmlEntityPtr |
| 168 | xmlGetPredefinedEntity(const xmlChar *name) { |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 169 | if (name == NULL) return(NULL); |
| 170 | switch (name[0]) { |
| 171 | case 'l': |
| 172 | if (xmlStrEqual(name, BAD_CAST "lt")) |
| 173 | return(&xmlEntityLt); |
| 174 | break; |
| 175 | case 'g': |
| 176 | if (xmlStrEqual(name, BAD_CAST "gt")) |
| 177 | return(&xmlEntityGt); |
| 178 | break; |
| 179 | case 'a': |
| 180 | if (xmlStrEqual(name, BAD_CAST "amp")) |
| 181 | return(&xmlEntityAmp); |
| 182 | if (xmlStrEqual(name, BAD_CAST "apos")) |
| 183 | return(&xmlEntityApos); |
| 184 | break; |
| 185 | case 'q': |
| 186 | if (xmlStrEqual(name, BAD_CAST "quot")) |
| 187 | return(&xmlEntityQuot); |
| 188 | break; |
| 189 | default: |
| 190 | break; |
| 191 | } |
| 192 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
| 196 | * xmlAddDtdEntity: |
| 197 | * @doc: the document |
| 198 | * @name: the entity name |
| 199 | * @type: the entity type XML_xxx_yyy_ENTITY |
| 200 | * @ExternalID: the entity external ID if available |
| 201 | * @SystemID: the entity system ID if available |
| 202 | * @content: the entity content |
| 203 | * |
| 204 | * Register a new entity for this document DTD external subset. |
| 205 | * |
| 206 | * Returns a pointer to the entity or NULL in case of error |
| 207 | */ |
| 208 | xmlEntityPtr |
| 209 | xmlAddDtdEntity(xmlDocPtr doc, const xmlChar *name, int type, |
| 210 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 211 | const xmlChar *content) { |
| 212 | xmlEntityPtr ret; |
| 213 | xmlDtdPtr dtd; |
| 214 | |
| 215 | if (doc == NULL) { |
| 216 | xmlGenericError(xmlGenericErrorContext, |
| 217 | "xmlAddDtdEntity: doc == NULL !\n"); |
| 218 | return(NULL); |
| 219 | } |
| 220 | if (doc->extSubset == NULL) { |
| 221 | xmlGenericError(xmlGenericErrorContext, |
| 222 | "xmlAddDtdEntity: document without external subset !\n"); |
| 223 | return(NULL); |
| 224 | } |
| 225 | dtd = doc->extSubset; |
| 226 | ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content); |
| 227 | if (ret == NULL) return(NULL); |
| 228 | |
| 229 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 230 | * Link it to the DTD |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 231 | */ |
| 232 | ret->parent = dtd; |
| 233 | ret->doc = dtd->doc; |
| 234 | if (dtd->last == NULL) { |
| 235 | dtd->children = dtd->last = (xmlNodePtr) ret; |
| 236 | } else { |
| 237 | dtd->last->next = (xmlNodePtr) ret; |
| 238 | ret->prev = dtd->last; |
| 239 | dtd->last = (xmlNodePtr) ret; |
| 240 | } |
| 241 | return(ret); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * xmlAddDocEntity: |
| 246 | * @doc: the document |
| 247 | * @name: the entity name |
| 248 | * @type: the entity type XML_xxx_yyy_ENTITY |
| 249 | * @ExternalID: the entity external ID if available |
| 250 | * @SystemID: the entity system ID if available |
| 251 | * @content: the entity content |
| 252 | * |
| 253 | * Register a new entity for this document. |
| 254 | * |
| 255 | * Returns a pointer to the entity or NULL in case of error |
| 256 | */ |
| 257 | xmlEntityPtr |
| 258 | xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type, |
| 259 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 260 | const xmlChar *content) { |
| 261 | xmlEntityPtr ret; |
| 262 | xmlDtdPtr dtd; |
| 263 | |
| 264 | if (doc == NULL) { |
| 265 | xmlGenericError(xmlGenericErrorContext, |
| 266 | "xmlAddDocEntity: document is NULL !\n"); |
| 267 | return(NULL); |
| 268 | } |
| 269 | if (doc->intSubset == NULL) { |
| 270 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 271 | "xmlAddDocEntity: document without internal subset !\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 272 | return(NULL); |
| 273 | } |
| 274 | dtd = doc->intSubset; |
| 275 | ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content); |
| 276 | if (ret == NULL) return(NULL); |
| 277 | |
| 278 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 279 | * Link it to the DTD |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 280 | */ |
| 281 | ret->parent = dtd; |
| 282 | ret->doc = dtd->doc; |
| 283 | if (dtd->last == NULL) { |
| 284 | dtd->children = dtd->last = (xmlNodePtr) ret; |
| 285 | } else { |
| 286 | dtd->last->next = (xmlNodePtr) ret; |
| 287 | ret->prev = dtd->last; |
| 288 | dtd->last = (xmlNodePtr) ret; |
| 289 | } |
| 290 | return(ret); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * xmlGetEntityFromTable: |
| 295 | * @table: an entity table |
| 296 | * @name: the entity name |
| 297 | * @parameter: look for parameter entities |
| 298 | * |
| 299 | * Do an entity lookup in the table. |
| 300 | * returns the corresponding parameter entity, if found. |
| 301 | * |
| 302 | * Returns A pointer to the entity structure or NULL if not found. |
| 303 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 304 | static xmlEntityPtr |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 305 | xmlGetEntityFromTable(xmlEntitiesTablePtr table, const xmlChar *name) { |
| 306 | return((xmlEntityPtr) xmlHashLookup(table, name)); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * xmlGetParameterEntity: |
| 311 | * @doc: the document referencing the entity |
| 312 | * @name: the entity name |
| 313 | * |
| 314 | * Do an entity lookup in the internal and external subsets and |
| 315 | * returns the corresponding parameter entity, if found. |
| 316 | * |
| 317 | * Returns A pointer to the entity structure or NULL if not found. |
| 318 | */ |
| 319 | xmlEntityPtr |
| 320 | xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) { |
| 321 | xmlEntitiesTablePtr table; |
| 322 | xmlEntityPtr ret; |
| 323 | |
Daniel Veillard | 3606581 | 2002-01-24 15:02:46 +0000 | [diff] [blame] | 324 | if (doc == NULL) |
| 325 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 326 | if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) { |
| 327 | table = (xmlEntitiesTablePtr) doc->intSubset->pentities; |
| 328 | ret = xmlGetEntityFromTable(table, name); |
| 329 | if (ret != NULL) |
| 330 | return(ret); |
| 331 | } |
| 332 | if ((doc->extSubset != NULL) && (doc->extSubset->pentities != NULL)) { |
| 333 | table = (xmlEntitiesTablePtr) doc->extSubset->pentities; |
| 334 | return(xmlGetEntityFromTable(table, name)); |
| 335 | } |
| 336 | return(NULL); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * xmlGetDtdEntity: |
| 341 | * @doc: the document referencing the entity |
| 342 | * @name: the entity name |
| 343 | * |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 344 | * Do an entity lookup in the DTD entity hash table and |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 345 | * returns the corresponding entity, if found. |
Daniel Veillard | 3606581 | 2002-01-24 15:02:46 +0000 | [diff] [blame] | 346 | * Note: the first argument is the document node, not the DTD node. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 347 | * |
| 348 | * Returns A pointer to the entity structure or NULL if not found. |
| 349 | */ |
| 350 | xmlEntityPtr |
| 351 | xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) { |
| 352 | xmlEntitiesTablePtr table; |
| 353 | |
Daniel Veillard | 3606581 | 2002-01-24 15:02:46 +0000 | [diff] [blame] | 354 | if (doc == NULL) |
| 355 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 356 | if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { |
| 357 | table = (xmlEntitiesTablePtr) doc->extSubset->entities; |
| 358 | return(xmlGetEntityFromTable(table, name)); |
| 359 | } |
| 360 | return(NULL); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * xmlGetDocEntity: |
| 365 | * @doc: the document referencing the entity |
| 366 | * @name: the entity name |
| 367 | * |
| 368 | * Do an entity lookup in the document entity hash table and |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 369 | * returns the corresponding entity, otherwise a lookup is done |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 370 | * in the predefined entities too. |
| 371 | * |
| 372 | * Returns A pointer to the entity structure or NULL if not found. |
| 373 | */ |
| 374 | xmlEntityPtr |
| 375 | xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) { |
| 376 | xmlEntityPtr cur; |
| 377 | xmlEntitiesTablePtr table; |
| 378 | |
| 379 | if (doc != NULL) { |
| 380 | if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { |
| 381 | table = (xmlEntitiesTablePtr) doc->intSubset->entities; |
| 382 | cur = xmlGetEntityFromTable(table, name); |
| 383 | if (cur != NULL) |
| 384 | return(cur); |
| 385 | } |
Daniel Veillard | 2875770 | 2002-02-18 11:19:30 +0000 | [diff] [blame] | 386 | if (doc->standalone != 1) { |
| 387 | if ((doc->extSubset != NULL) && |
| 388 | (doc->extSubset->entities != NULL)) { |
| 389 | table = (xmlEntitiesTablePtr) doc->extSubset->entities; |
| 390 | cur = xmlGetEntityFromTable(table, name); |
| 391 | if (cur != NULL) |
| 392 | return(cur); |
| 393 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 396 | return(xmlGetPredefinedEntity(name)); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /* |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 400 | * Macro used to grow the current buffer. |
| 401 | */ |
| 402 | #define growBufferReentrant() { \ |
| 403 | buffer_size *= 2; \ |
| 404 | buffer = (xmlChar *) \ |
| 405 | xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \ |
| 406 | if (buffer == NULL) { \ |
Daniel Veillard | 3487c8d | 2002-09-05 11:33:25 +0000 | [diff] [blame] | 407 | xmlGenericError(xmlGenericErrorContext, "realloc failed\n"); \ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 408 | return(NULL); \ |
| 409 | } \ |
| 410 | } |
| 411 | |
| 412 | |
| 413 | /** |
| 414 | * xmlEncodeEntitiesReentrant: |
| 415 | * @doc: the document containing the string |
| 416 | * @input: A string to convert to XML. |
| 417 | * |
| 418 | * Do a global encoding of a string, replacing the predefined entities |
| 419 | * and non ASCII values with their entities and CharRef counterparts. |
| 420 | * Contrary to xmlEncodeEntities, this routine is reentrant, and result |
| 421 | * must be deallocated. |
| 422 | * |
| 423 | * Returns A newly allocated string with the substitution done. |
| 424 | */ |
| 425 | xmlChar * |
| 426 | xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { |
| 427 | const xmlChar *cur = input; |
| 428 | xmlChar *buffer = NULL; |
| 429 | xmlChar *out = NULL; |
| 430 | int buffer_size = 0; |
| 431 | int html = 0; |
| 432 | |
| 433 | if (input == NULL) return(NULL); |
| 434 | if (doc != NULL) |
| 435 | html = (doc->type == XML_HTML_DOCUMENT_NODE); |
| 436 | |
| 437 | /* |
| 438 | * allocate an translation buffer. |
| 439 | */ |
| 440 | buffer_size = 1000; |
| 441 | buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); |
| 442 | if (buffer == NULL) { |
Daniel Veillard | 3487c8d | 2002-09-05 11:33:25 +0000 | [diff] [blame] | 443 | xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 444 | return(NULL); |
| 445 | } |
| 446 | out = buffer; |
| 447 | |
| 448 | while (*cur != '\0') { |
| 449 | if (out - buffer > buffer_size - 100) { |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 450 | int indx = out - buffer; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 451 | |
| 452 | growBufferReentrant(); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 453 | out = &buffer[indx]; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* |
| 457 | * By default one have to encode at least '<', '>', '"' and '&' ! |
| 458 | */ |
| 459 | if (*cur == '<') { |
| 460 | *out++ = '&'; |
| 461 | *out++ = 'l'; |
| 462 | *out++ = 't'; |
| 463 | *out++ = ';'; |
| 464 | } else if (*cur == '>') { |
| 465 | *out++ = '&'; |
| 466 | *out++ = 'g'; |
| 467 | *out++ = 't'; |
| 468 | *out++ = ';'; |
| 469 | } else if (*cur == '&') { |
| 470 | *out++ = '&'; |
| 471 | *out++ = 'a'; |
| 472 | *out++ = 'm'; |
| 473 | *out++ = 'p'; |
| 474 | *out++ = ';'; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 475 | } else if (((*cur >= 0x20) && (*cur < 0x80)) || |
Daniel Veillard | 0046c0f | 2003-02-23 13:52:30 +0000 | [diff] [blame] | 476 | (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 477 | /* |
| 478 | * default case, just copy ! |
| 479 | */ |
| 480 | *out++ = *cur; |
| 481 | } else if (*cur >= 0x80) { |
Daniel Veillard | 122376b | 2001-04-24 12:12:30 +0000 | [diff] [blame] | 482 | if (((doc != NULL) && (doc->encoding != NULL)) || (html)) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 483 | /* |
| 484 | * Bjørn Reese <br@sseusa.com> provided the patch |
| 485 | xmlChar xc; |
| 486 | xc = (*cur & 0x3F) << 6; |
| 487 | if (cur[1] != 0) { |
| 488 | xc += *(++cur) & 0x3F; |
| 489 | *out++ = xc; |
| 490 | } else |
| 491 | */ |
| 492 | *out++ = *cur; |
| 493 | } else { |
| 494 | /* |
| 495 | * We assume we have UTF-8 input. |
| 496 | */ |
Daniel Veillard | b2517d8 | 2003-10-01 19:13:56 +0000 | [diff] [blame] | 497 | char buf[11], *ptr; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 498 | int val = 0, l = 1; |
| 499 | |
| 500 | if (*cur < 0xC0) { |
| 501 | xmlGenericError(xmlGenericErrorContext, |
| 502 | "xmlEncodeEntitiesReentrant : input not UTF-8\n"); |
Daniel Veillard | 122376b | 2001-04-24 12:12:30 +0000 | [diff] [blame] | 503 | if (doc != NULL) |
| 504 | doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 505 | snprintf(buf, sizeof(buf), "&#%d;", *cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 506 | buf[sizeof(buf) - 1] = 0; |
| 507 | ptr = buf; |
| 508 | while (*ptr != 0) *out++ = *ptr++; |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 509 | cur++; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 510 | continue; |
| 511 | } else if (*cur < 0xE0) { |
| 512 | val = (cur[0]) & 0x1F; |
| 513 | val <<= 6; |
| 514 | val |= (cur[1]) & 0x3F; |
| 515 | l = 2; |
| 516 | } else if (*cur < 0xF0) { |
| 517 | val = (cur[0]) & 0x0F; |
| 518 | val <<= 6; |
| 519 | val |= (cur[1]) & 0x3F; |
| 520 | val <<= 6; |
| 521 | val |= (cur[2]) & 0x3F; |
| 522 | l = 3; |
| 523 | } else if (*cur < 0xF8) { |
| 524 | val = (cur[0]) & 0x07; |
| 525 | val <<= 6; |
| 526 | val |= (cur[1]) & 0x3F; |
| 527 | val <<= 6; |
| 528 | val |= (cur[2]) & 0x3F; |
| 529 | val <<= 6; |
| 530 | val |= (cur[3]) & 0x3F; |
| 531 | l = 4; |
| 532 | } |
| 533 | if ((l == 1) || (!IS_CHAR(val))) { |
| 534 | xmlGenericError(xmlGenericErrorContext, |
| 535 | "xmlEncodeEntitiesReentrant : char out of range\n"); |
Daniel Veillard | 122376b | 2001-04-24 12:12:30 +0000 | [diff] [blame] | 536 | if (doc != NULL) |
| 537 | doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 538 | snprintf(buf, sizeof(buf), "&#%d;", *cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 539 | buf[sizeof(buf) - 1] = 0; |
| 540 | ptr = buf; |
| 541 | while (*ptr != 0) *out++ = *ptr++; |
| 542 | cur++; |
| 543 | continue; |
| 544 | } |
| 545 | /* |
| 546 | * We could do multiple things here. Just save as a char ref |
| 547 | */ |
Daniel Veillard | 1669828 | 2001-09-14 10:29:27 +0000 | [diff] [blame] | 548 | if (html) |
| 549 | snprintf(buf, sizeof(buf), "&#%d;", val); |
| 550 | else |
| 551 | snprintf(buf, sizeof(buf), "&#x%X;", val); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 552 | buf[sizeof(buf) - 1] = 0; |
| 553 | ptr = buf; |
| 554 | while (*ptr != 0) *out++ = *ptr++; |
| 555 | cur += l; |
| 556 | continue; |
| 557 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 558 | } else if (IS_BYTE_CHAR(*cur)) { |
Daniel Veillard | b2517d8 | 2003-10-01 19:13:56 +0000 | [diff] [blame] | 559 | char buf[11], *ptr; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 560 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 561 | snprintf(buf, sizeof(buf), "&#%d;", *cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 562 | buf[sizeof(buf) - 1] = 0; |
| 563 | ptr = buf; |
| 564 | while (*ptr != 0) *out++ = *ptr++; |
| 565 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 566 | cur++; |
| 567 | } |
| 568 | *out++ = 0; |
| 569 | return(buffer); |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * xmlEncodeSpecialChars: |
| 574 | * @doc: the document containing the string |
| 575 | * @input: A string to convert to XML. |
| 576 | * |
| 577 | * Do a global encoding of a string, replacing the predefined entities |
| 578 | * this routine is reentrant, and result must be deallocated. |
| 579 | * |
| 580 | * Returns A newly allocated string with the substitution done. |
| 581 | */ |
| 582 | xmlChar * |
Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 583 | xmlEncodeSpecialChars(xmlDocPtr doc ATTRIBUTE_UNUSED, const xmlChar *input) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 584 | const xmlChar *cur = input; |
| 585 | xmlChar *buffer = NULL; |
| 586 | xmlChar *out = NULL; |
| 587 | int buffer_size = 0; |
William M. Brack | 899e64a | 2003-09-26 18:03:42 +0000 | [diff] [blame] | 588 | if (input == NULL) return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 589 | |
| 590 | /* |
| 591 | * allocate an translation buffer. |
| 592 | */ |
| 593 | buffer_size = 1000; |
| 594 | buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); |
| 595 | if (buffer == NULL) { |
Daniel Veillard | 3487c8d | 2002-09-05 11:33:25 +0000 | [diff] [blame] | 596 | xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 597 | return(NULL); |
| 598 | } |
| 599 | out = buffer; |
| 600 | |
| 601 | while (*cur != '\0') { |
| 602 | if (out - buffer > buffer_size - 10) { |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 603 | int indx = out - buffer; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 604 | |
| 605 | growBufferReentrant(); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 606 | out = &buffer[indx]; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /* |
| 610 | * By default one have to encode at least '<', '>', '"' and '&' ! |
| 611 | */ |
| 612 | if (*cur == '<') { |
| 613 | *out++ = '&'; |
| 614 | *out++ = 'l'; |
| 615 | *out++ = 't'; |
| 616 | *out++ = ';'; |
| 617 | } else if (*cur == '>') { |
| 618 | *out++ = '&'; |
| 619 | *out++ = 'g'; |
| 620 | *out++ = 't'; |
| 621 | *out++ = ';'; |
| 622 | } else if (*cur == '&') { |
| 623 | *out++ = '&'; |
| 624 | *out++ = 'a'; |
| 625 | *out++ = 'm'; |
| 626 | *out++ = 'p'; |
| 627 | *out++ = ';'; |
| 628 | } else if (*cur == '"') { |
| 629 | *out++ = '&'; |
| 630 | *out++ = 'q'; |
| 631 | *out++ = 'u'; |
| 632 | *out++ = 'o'; |
| 633 | *out++ = 't'; |
| 634 | *out++ = ';'; |
Daniel Veillard | 19ab45b | 2003-02-26 15:49:03 +0000 | [diff] [blame] | 635 | } else if (*cur == '\r') { |
| 636 | *out++ = '&'; |
| 637 | *out++ = '#'; |
| 638 | *out++ = '1'; |
| 639 | *out++ = '3'; |
| 640 | *out++ = ';'; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 641 | } else { |
| 642 | /* |
| 643 | * Works because on UTF-8, all extended sequences cannot |
| 644 | * result in bytes in the ASCII range. |
| 645 | */ |
| 646 | *out++ = *cur; |
| 647 | } |
| 648 | cur++; |
| 649 | } |
| 650 | *out++ = 0; |
| 651 | return(buffer); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * xmlCreateEntitiesTable: |
| 656 | * |
| 657 | * create and initialize an empty entities hash table. |
| 658 | * |
| 659 | * Returns the xmlEntitiesTablePtr just created or NULL in case of error. |
| 660 | */ |
| 661 | xmlEntitiesTablePtr |
| 662 | xmlCreateEntitiesTable(void) { |
| 663 | return((xmlEntitiesTablePtr) xmlHashCreate(0)); |
| 664 | } |
| 665 | |
| 666 | /** |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 667 | * xmlFreeEntityWrapper: |
| 668 | * @entity: An entity |
| 669 | * @name: its name |
| 670 | * |
| 671 | * Deallocate the memory used by an entities in the hash table. |
| 672 | */ |
| 673 | static void |
| 674 | xmlFreeEntityWrapper(xmlEntityPtr entity, |
| 675 | const xmlChar *name ATTRIBUTE_UNUSED) { |
| 676 | if (entity != NULL) |
| 677 | xmlFreeEntity(entity); |
| 678 | } |
| 679 | |
| 680 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 681 | * xmlFreeEntitiesTable: |
| 682 | * @table: An entity table |
| 683 | * |
| 684 | * Deallocate the memory used by an entities hash table. |
| 685 | */ |
| 686 | void |
| 687 | xmlFreeEntitiesTable(xmlEntitiesTablePtr table) { |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 688 | xmlHashFree(table, (xmlHashDeallocator) xmlFreeEntityWrapper); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 691 | #ifdef LIBXML_TREE_ENABLED |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 692 | /** |
| 693 | * xmlCopyEntity: |
| 694 | * @ent: An entity |
| 695 | * |
| 696 | * Build a copy of an entity |
| 697 | * |
| 698 | * Returns the new xmlEntitiesPtr or NULL in case of error. |
| 699 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 700 | static xmlEntityPtr |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 701 | xmlCopyEntity(xmlEntityPtr ent) { |
| 702 | xmlEntityPtr cur; |
| 703 | |
| 704 | cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); |
| 705 | if (cur == NULL) { |
| 706 | xmlGenericError(xmlGenericErrorContext, |
| 707 | "xmlCopyEntity: out of memory !\n"); |
| 708 | return(NULL); |
| 709 | } |
| 710 | memset(cur, 0, sizeof(xmlEntity)); |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 711 | cur->type = XML_ENTITY_DECL; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 712 | |
| 713 | cur->etype = ent->etype; |
| 714 | if (ent->name != NULL) |
| 715 | cur->name = xmlStrdup(ent->name); |
| 716 | if (ent->ExternalID != NULL) |
| 717 | cur->ExternalID = xmlStrdup(ent->ExternalID); |
| 718 | if (ent->SystemID != NULL) |
| 719 | cur->SystemID = xmlStrdup(ent->SystemID); |
| 720 | if (ent->content != NULL) |
| 721 | cur->content = xmlStrdup(ent->content); |
| 722 | if (ent->orig != NULL) |
| 723 | cur->orig = xmlStrdup(ent->orig); |
Daniel Veillard | 8ee9c8f | 2002-01-26 21:42:58 +0000 | [diff] [blame] | 724 | if (ent->URI != NULL) |
| 725 | cur->URI = xmlStrdup(ent->URI); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 726 | return(cur); |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * xmlCopyEntitiesTable: |
| 731 | * @table: An entity table |
| 732 | * |
| 733 | * Build a copy of an entity table. |
| 734 | * |
| 735 | * Returns the new xmlEntitiesTablePtr or NULL in case of error. |
| 736 | */ |
| 737 | xmlEntitiesTablePtr |
| 738 | xmlCopyEntitiesTable(xmlEntitiesTablePtr table) { |
| 739 | return(xmlHashCopy(table, (xmlHashCopier) xmlCopyEntity)); |
| 740 | } |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 741 | #endif /* LIBXML_TREE_ENABLED */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 742 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 743 | #ifdef LIBXML_OUTPUT_ENABLED |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 744 | /** |
| 745 | * xmlDumpEntityDecl: |
| 746 | * @buf: An XML buffer. |
| 747 | * @ent: An entity table |
| 748 | * |
| 749 | * This will dump the content of the entity table as an XML DTD definition |
| 750 | */ |
| 751 | void |
| 752 | xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) { |
| 753 | switch (ent->etype) { |
| 754 | case XML_INTERNAL_GENERAL_ENTITY: |
| 755 | xmlBufferWriteChar(buf, "<!ENTITY "); |
| 756 | xmlBufferWriteCHAR(buf, ent->name); |
| 757 | xmlBufferWriteChar(buf, " "); |
| 758 | if (ent->orig != NULL) |
| 759 | xmlBufferWriteQuotedString(buf, ent->orig); |
| 760 | else |
| 761 | xmlBufferWriteQuotedString(buf, ent->content); |
| 762 | xmlBufferWriteChar(buf, ">\n"); |
| 763 | break; |
| 764 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 765 | xmlBufferWriteChar(buf, "<!ENTITY "); |
| 766 | xmlBufferWriteCHAR(buf, ent->name); |
| 767 | if (ent->ExternalID != NULL) { |
| 768 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 769 | xmlBufferWriteQuotedString(buf, ent->ExternalID); |
| 770 | xmlBufferWriteChar(buf, " "); |
| 771 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 772 | } else { |
| 773 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 774 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 775 | } |
| 776 | xmlBufferWriteChar(buf, ">\n"); |
| 777 | break; |
| 778 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 779 | xmlBufferWriteChar(buf, "<!ENTITY "); |
| 780 | xmlBufferWriteCHAR(buf, ent->name); |
| 781 | if (ent->ExternalID != NULL) { |
| 782 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 783 | xmlBufferWriteQuotedString(buf, ent->ExternalID); |
| 784 | xmlBufferWriteChar(buf, " "); |
| 785 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 786 | } else { |
| 787 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 788 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 789 | } |
| 790 | if (ent->content != NULL) { /* Should be true ! */ |
| 791 | xmlBufferWriteChar(buf, " NDATA "); |
| 792 | if (ent->orig != NULL) |
| 793 | xmlBufferWriteCHAR(buf, ent->orig); |
| 794 | else |
| 795 | xmlBufferWriteCHAR(buf, ent->content); |
| 796 | } |
| 797 | xmlBufferWriteChar(buf, ">\n"); |
| 798 | break; |
| 799 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 800 | xmlBufferWriteChar(buf, "<!ENTITY % "); |
| 801 | xmlBufferWriteCHAR(buf, ent->name); |
| 802 | xmlBufferWriteChar(buf, " "); |
| 803 | if (ent->orig == NULL) |
| 804 | xmlBufferWriteQuotedString(buf, ent->content); |
| 805 | else |
| 806 | xmlBufferWriteQuotedString(buf, ent->orig); |
| 807 | xmlBufferWriteChar(buf, ">\n"); |
| 808 | break; |
| 809 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 810 | xmlBufferWriteChar(buf, "<!ENTITY % "); |
| 811 | xmlBufferWriteCHAR(buf, ent->name); |
| 812 | if (ent->ExternalID != NULL) { |
| 813 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 814 | xmlBufferWriteQuotedString(buf, ent->ExternalID); |
| 815 | xmlBufferWriteChar(buf, " "); |
| 816 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 817 | } else { |
| 818 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 819 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 820 | } |
| 821 | xmlBufferWriteChar(buf, ">\n"); |
| 822 | break; |
| 823 | default: |
| 824 | xmlGenericError(xmlGenericErrorContext, |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 825 | "xmlDumpEntitiesDecl: internal: unknown type %d\n", |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 826 | ent->etype); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | /** |
William M. Brack | 9e66059 | 2003-10-20 14:56:06 +0000 | [diff] [blame] | 831 | * xmlDumpEntityDeclScan: |
| 832 | * @ent: An entity table |
| 833 | * @buf: An XML buffer. |
| 834 | * |
| 835 | * When using the hash table scan function, arguments need to be reversed |
| 836 | */ |
| 837 | static void |
| 838 | xmlDumpEntityDeclScan(xmlEntityPtr ent, xmlBufferPtr buf) { |
| 839 | xmlDumpEntityDecl(buf, ent); |
| 840 | } |
| 841 | |
| 842 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 843 | * xmlDumpEntitiesTable: |
| 844 | * @buf: An XML buffer. |
| 845 | * @table: An entity table |
| 846 | * |
| 847 | * This will dump the content of the entity table as an XML DTD definition |
| 848 | */ |
| 849 | void |
| 850 | xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { |
William M. Brack | 9e66059 | 2003-10-20 14:56:06 +0000 | [diff] [blame] | 851 | xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 852 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 853 | #endif /* LIBXML_OUTPUT_ENABLED */ |