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 | |
Stéphane Michaut | 454e397 | 2017-08-28 14:30:43 +0200 | [diff] [blame] | 9 | /* To avoid EBCDIC trouble when parsing on zOS */ |
| 10 | #if defined(__MVS__) |
| 11 | #pragma convert("ISO8859-1") |
| 12 | #endif |
| 13 | |
Daniel Veillard | 34ce8be | 2002-03-18 19:37:11 +0000 | [diff] [blame] | 14 | #define IN_LIBXML |
Bjorn Reese | 70a9da5 | 2001-04-21 16:57:29 +0000 | [diff] [blame] | 15 | #include "libxml.h" |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 16 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 17 | #include <string.h> |
| 18 | #ifdef HAVE_STDLIB_H |
| 19 | #include <stdlib.h> |
| 20 | #endif |
| 21 | #include <libxml/xmlmemory.h> |
| 22 | #include <libxml/hash.h> |
| 23 | #include <libxml/entities.h> |
| 24 | #include <libxml/parser.h> |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 25 | #include <libxml/parserInternals.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 26 | #include <libxml/xmlerror.h> |
Daniel Veillard | 3c01b1d | 2001-10-17 15:58:35 +0000 | [diff] [blame] | 27 | #include <libxml/globals.h> |
Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 28 | #include <libxml/dict.h> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 29 | |
Daniel Veillard | 7651606 | 2012-09-11 14:02:08 +0800 | [diff] [blame] | 30 | #include "save.h" |
| 31 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 32 | /* |
| 33 | * The XML predefined entities. |
| 34 | */ |
| 35 | |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 36 | static xmlEntity xmlEntityLt = { |
| 37 | NULL, XML_ENTITY_DECL, BAD_CAST "lt", |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 38 | NULL, NULL, NULL, NULL, NULL, NULL, |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 39 | BAD_CAST "<", BAD_CAST "<", 1, |
| 40 | XML_INTERNAL_PREDEFINED_ENTITY, |
Daniel Veillard | f4f4e48 | 2008-08-25 08:57:48 +0000 | [diff] [blame] | 41 | NULL, NULL, NULL, NULL, 0, 1 |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 42 | }; |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 43 | static xmlEntity xmlEntityGt = { |
| 44 | NULL, XML_ENTITY_DECL, BAD_CAST "gt", |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 45 | NULL, NULL, NULL, NULL, NULL, NULL, |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 46 | BAD_CAST ">", BAD_CAST ">", 1, |
| 47 | XML_INTERNAL_PREDEFINED_ENTITY, |
Daniel Veillard | f4f4e48 | 2008-08-25 08:57:48 +0000 | [diff] [blame] | 48 | NULL, NULL, NULL, NULL, 0, 1 |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 49 | }; |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 50 | static xmlEntity xmlEntityAmp = { |
| 51 | NULL, XML_ENTITY_DECL, BAD_CAST "amp", |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 52 | NULL, NULL, NULL, NULL, NULL, NULL, |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 53 | BAD_CAST "&", BAD_CAST "&", 1, |
| 54 | XML_INTERNAL_PREDEFINED_ENTITY, |
Daniel Veillard | f4f4e48 | 2008-08-25 08:57:48 +0000 | [diff] [blame] | 55 | NULL, NULL, NULL, NULL, 0, 1 |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 56 | }; |
| 57 | static xmlEntity xmlEntityQuot = { |
| 58 | NULL, XML_ENTITY_DECL, BAD_CAST "quot", |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 59 | NULL, NULL, NULL, NULL, NULL, NULL, |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 60 | BAD_CAST "\"", BAD_CAST "\"", 1, |
| 61 | XML_INTERNAL_PREDEFINED_ENTITY, |
Daniel Veillard | f4f4e48 | 2008-08-25 08:57:48 +0000 | [diff] [blame] | 62 | NULL, NULL, NULL, NULL, 0, 1 |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 63 | }; |
| 64 | static xmlEntity xmlEntityApos = { |
| 65 | NULL, XML_ENTITY_DECL, BAD_CAST "apos", |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 66 | NULL, NULL, NULL, NULL, NULL, NULL, |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 67 | BAD_CAST "'", BAD_CAST "'", 1, |
| 68 | XML_INTERNAL_PREDEFINED_ENTITY, |
Daniel Veillard | f4f4e48 | 2008-08-25 08:57:48 +0000 | [diff] [blame] | 69 | NULL, NULL, NULL, NULL, 0, 1 |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 70 | }; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 71 | |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 72 | /** |
| 73 | * xmlEntitiesErrMemory: |
| 74 | * @extra: extra informations |
| 75 | * |
| 76 | * Handle an out of memory condition |
| 77 | */ |
| 78 | static void |
| 79 | xmlEntitiesErrMemory(const char *extra) |
| 80 | { |
| 81 | __xmlSimpleError(XML_FROM_TREE, XML_ERR_NO_MEMORY, NULL, NULL, extra); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * xmlEntitiesErr: |
| 86 | * @code: the error code |
| 87 | * @msg: the message |
| 88 | * |
| 89 | * Handle an out of memory condition |
| 90 | */ |
David Kilzer | 4472c3a | 2016-05-13 15:13:17 +0800 | [diff] [blame] | 91 | static void LIBXML_ATTR_FORMAT(2,0) |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 92 | xmlEntitiesErr(xmlParserErrors code, const char *msg) |
| 93 | { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 94 | __xmlSimpleError(XML_FROM_TREE, code, NULL, msg, NULL); |
| 95 | } |
| 96 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 97 | /* |
| 98 | * xmlFreeEntity : clean-up an entity record. |
| 99 | */ |
Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 100 | static void |
| 101 | xmlFreeEntity(xmlEntityPtr entity) |
| 102 | { |
| 103 | xmlDictPtr dict = NULL; |
| 104 | |
| 105 | if (entity == NULL) |
| 106 | return; |
| 107 | |
| 108 | if (entity->doc != NULL) |
| 109 | dict = entity->doc->dict; |
| 110 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 111 | |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 112 | if ((entity->children) && (entity->owner == 1) && |
Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 113 | (entity == (xmlEntityPtr) entity->children->parent)) |
| 114 | xmlFreeNodeList(entity->children); |
| 115 | if (dict != NULL) { |
| 116 | if ((entity->name != NULL) && (!xmlDictOwns(dict, entity->name))) |
| 117 | xmlFree((char *) entity->name); |
| 118 | if ((entity->ExternalID != NULL) && |
| 119 | (!xmlDictOwns(dict, entity->ExternalID))) |
| 120 | xmlFree((char *) entity->ExternalID); |
| 121 | if ((entity->SystemID != NULL) && |
| 122 | (!xmlDictOwns(dict, entity->SystemID))) |
| 123 | xmlFree((char *) entity->SystemID); |
| 124 | if ((entity->URI != NULL) && (!xmlDictOwns(dict, entity->URI))) |
| 125 | xmlFree((char *) entity->URI); |
| 126 | if ((entity->content != NULL) |
| 127 | && (!xmlDictOwns(dict, entity->content))) |
| 128 | xmlFree((char *) entity->content); |
| 129 | if ((entity->orig != NULL) && (!xmlDictOwns(dict, entity->orig))) |
| 130 | xmlFree((char *) entity->orig); |
| 131 | } else { |
| 132 | if (entity->name != NULL) |
| 133 | xmlFree((char *) entity->name); |
| 134 | if (entity->ExternalID != NULL) |
| 135 | xmlFree((char *) entity->ExternalID); |
| 136 | if (entity->SystemID != NULL) |
| 137 | xmlFree((char *) entity->SystemID); |
| 138 | if (entity->URI != NULL) |
| 139 | xmlFree((char *) entity->URI); |
| 140 | if (entity->content != NULL) |
| 141 | xmlFree((char *) entity->content); |
| 142 | if (entity->orig != NULL) |
| 143 | xmlFree((char *) entity->orig); |
| 144 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 145 | xmlFree(entity); |
| 146 | } |
| 147 | |
| 148 | /* |
Daniel Veillard | aa6de47 | 2008-08-25 14:53:31 +0000 | [diff] [blame] | 149 | * xmlCreateEntity: |
| 150 | * |
| 151 | * internal routine doing the entity node strutures allocations |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 152 | */ |
| 153 | static xmlEntityPtr |
Daniel Veillard | aa6de47 | 2008-08-25 14:53:31 +0000 | [diff] [blame] | 154 | xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type, |
| 155 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 156 | const xmlChar *content) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 157 | xmlEntityPtr ret; |
| 158 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 159 | ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); |
| 160 | if (ret == NULL) { |
Daniel Veillard | aa6de47 | 2008-08-25 14:53:31 +0000 | [diff] [blame] | 161 | xmlEntitiesErrMemory("xmlCreateEntity: malloc failed"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 162 | return(NULL); |
| 163 | } |
| 164 | memset(ret, 0, sizeof(xmlEntity)); |
| 165 | ret->type = XML_ENTITY_DECL; |
Daniel Veillard | a37a6ad | 2006-10-10 20:05:45 +0000 | [diff] [blame] | 166 | ret->checked = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * fill the structure. |
| 170 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 171 | ret->etype = (xmlEntityType) type; |
Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 172 | if (dict == NULL) { |
| 173 | ret->name = xmlStrdup(name); |
| 174 | if (ExternalID != NULL) |
| 175 | ret->ExternalID = xmlStrdup(ExternalID); |
| 176 | if (SystemID != NULL) |
| 177 | ret->SystemID = xmlStrdup(SystemID); |
| 178 | } else { |
| 179 | ret->name = xmlDictLookup(dict, name, -1); |
| 180 | if (ExternalID != NULL) |
| 181 | ret->ExternalID = xmlDictLookup(dict, ExternalID, -1); |
| 182 | if (SystemID != NULL) |
| 183 | ret->SystemID = xmlDictLookup(dict, SystemID, -1); |
| 184 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 185 | if (content != NULL) { |
| 186 | ret->length = xmlStrlen(content); |
Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 187 | if ((dict != NULL) && (ret->length < 5)) |
| 188 | ret->content = (xmlChar *) |
| 189 | xmlDictLookup(dict, content, ret->length); |
| 190 | else |
| 191 | ret->content = xmlStrndup(content, ret->length); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 192 | } else { |
| 193 | ret->length = 0; |
| 194 | ret->content = NULL; |
| 195 | } |
| 196 | ret->URI = NULL; /* to be computed by the layer knowing |
| 197 | the defining entity */ |
| 198 | ret->orig = NULL; |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 199 | ret->owner = 0; |
Daniel Veillard | aa6de47 | 2008-08-25 14:53:31 +0000 | [diff] [blame] | 200 | |
| 201 | return(ret); |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * xmlAddEntity : register a new entity for an entities table. |
| 206 | */ |
| 207 | static xmlEntityPtr |
| 208 | xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type, |
| 209 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 210 | const xmlChar *content) { |
| 211 | xmlDictPtr dict = NULL; |
| 212 | xmlEntitiesTablePtr table = NULL; |
| 213 | xmlEntityPtr ret; |
| 214 | |
| 215 | if (name == NULL) |
| 216 | return(NULL); |
| 217 | if (dtd == NULL) |
| 218 | return(NULL); |
| 219 | if (dtd->doc != NULL) |
| 220 | dict = dtd->doc->dict; |
| 221 | |
| 222 | switch (type) { |
| 223 | case XML_INTERNAL_GENERAL_ENTITY: |
| 224 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 225 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 226 | if (dtd->entities == NULL) |
| 227 | dtd->entities = xmlHashCreateDict(0, dict); |
| 228 | table = dtd->entities; |
| 229 | break; |
| 230 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 231 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 232 | if (dtd->pentities == NULL) |
| 233 | dtd->pentities = xmlHashCreateDict(0, dict); |
| 234 | table = dtd->pentities; |
| 235 | break; |
| 236 | case XML_INTERNAL_PREDEFINED_ENTITY: |
| 237 | return(NULL); |
| 238 | } |
| 239 | if (table == NULL) |
| 240 | return(NULL); |
| 241 | ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content); |
| 242 | if (ret == NULL) |
| 243 | return(NULL); |
Daniel Veillard | 7da9270 | 2005-01-23 20:15:53 +0000 | [diff] [blame] | 244 | ret->doc = dtd->doc; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 245 | |
| 246 | if (xmlHashAddEntry(table, name, ret)) { |
| 247 | /* |
| 248 | * entity was already defined at another level. |
| 249 | */ |
| 250 | xmlFreeEntity(ret); |
| 251 | return(NULL); |
| 252 | } |
| 253 | return(ret); |
| 254 | } |
| 255 | |
| 256 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 257 | * xmlGetPredefinedEntity: |
| 258 | * @name: the entity name |
| 259 | * |
| 260 | * Check whether this name is an predefined entity. |
| 261 | * |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 262 | * Returns NULL if not, otherwise the entity |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 263 | */ |
| 264 | xmlEntityPtr |
| 265 | xmlGetPredefinedEntity(const xmlChar *name) { |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 266 | if (name == NULL) return(NULL); |
| 267 | switch (name[0]) { |
| 268 | case 'l': |
| 269 | if (xmlStrEqual(name, BAD_CAST "lt")) |
| 270 | return(&xmlEntityLt); |
| 271 | break; |
| 272 | case 'g': |
| 273 | if (xmlStrEqual(name, BAD_CAST "gt")) |
| 274 | return(&xmlEntityGt); |
| 275 | break; |
| 276 | case 'a': |
| 277 | if (xmlStrEqual(name, BAD_CAST "amp")) |
| 278 | return(&xmlEntityAmp); |
| 279 | if (xmlStrEqual(name, BAD_CAST "apos")) |
| 280 | return(&xmlEntityApos); |
| 281 | break; |
| 282 | case 'q': |
| 283 | if (xmlStrEqual(name, BAD_CAST "quot")) |
| 284 | return(&xmlEntityQuot); |
| 285 | break; |
| 286 | default: |
| 287 | break; |
| 288 | } |
| 289 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
| 293 | * xmlAddDtdEntity: |
| 294 | * @doc: the document |
| 295 | * @name: the entity name |
| 296 | * @type: the entity type XML_xxx_yyy_ENTITY |
| 297 | * @ExternalID: the entity external ID if available |
| 298 | * @SystemID: the entity system ID if available |
| 299 | * @content: the entity content |
| 300 | * |
| 301 | * Register a new entity for this document DTD external subset. |
| 302 | * |
| 303 | * Returns a pointer to the entity or NULL in case of error |
| 304 | */ |
| 305 | xmlEntityPtr |
| 306 | xmlAddDtdEntity(xmlDocPtr doc, const xmlChar *name, int type, |
| 307 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 308 | const xmlChar *content) { |
| 309 | xmlEntityPtr ret; |
| 310 | xmlDtdPtr dtd; |
| 311 | |
| 312 | if (doc == NULL) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 313 | xmlEntitiesErr(XML_DTD_NO_DOC, |
| 314 | "xmlAddDtdEntity: document is NULL"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 315 | return(NULL); |
| 316 | } |
| 317 | if (doc->extSubset == NULL) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 318 | xmlEntitiesErr(XML_DTD_NO_DTD, |
| 319 | "xmlAddDtdEntity: document without external subset"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 320 | return(NULL); |
| 321 | } |
| 322 | dtd = doc->extSubset; |
| 323 | ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content); |
| 324 | if (ret == NULL) return(NULL); |
| 325 | |
| 326 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 327 | * Link it to the DTD |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 328 | */ |
| 329 | ret->parent = dtd; |
| 330 | ret->doc = dtd->doc; |
| 331 | if (dtd->last == NULL) { |
| 332 | dtd->children = dtd->last = (xmlNodePtr) ret; |
| 333 | } else { |
| 334 | dtd->last->next = (xmlNodePtr) ret; |
| 335 | ret->prev = dtd->last; |
| 336 | dtd->last = (xmlNodePtr) ret; |
| 337 | } |
| 338 | return(ret); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * xmlAddDocEntity: |
| 343 | * @doc: the document |
| 344 | * @name: the entity name |
| 345 | * @type: the entity type XML_xxx_yyy_ENTITY |
| 346 | * @ExternalID: the entity external ID if available |
| 347 | * @SystemID: the entity system ID if available |
| 348 | * @content: the entity content |
| 349 | * |
| 350 | * Register a new entity for this document. |
| 351 | * |
| 352 | * Returns a pointer to the entity or NULL in case of error |
| 353 | */ |
| 354 | xmlEntityPtr |
| 355 | xmlAddDocEntity(xmlDocPtr doc, const xmlChar *name, int type, |
| 356 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 357 | const xmlChar *content) { |
| 358 | xmlEntityPtr ret; |
| 359 | xmlDtdPtr dtd; |
| 360 | |
| 361 | if (doc == NULL) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 362 | xmlEntitiesErr(XML_DTD_NO_DOC, |
| 363 | "xmlAddDocEntity: document is NULL"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 364 | return(NULL); |
| 365 | } |
| 366 | if (doc->intSubset == NULL) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 367 | xmlEntitiesErr(XML_DTD_NO_DTD, |
| 368 | "xmlAddDocEntity: document without internal subset"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 369 | return(NULL); |
| 370 | } |
| 371 | dtd = doc->intSubset; |
| 372 | ret = xmlAddEntity(dtd, name, type, ExternalID, SystemID, content); |
| 373 | if (ret == NULL) return(NULL); |
| 374 | |
| 375 | /* |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 376 | * Link it to the DTD |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 377 | */ |
| 378 | ret->parent = dtd; |
| 379 | ret->doc = dtd->doc; |
| 380 | if (dtd->last == NULL) { |
| 381 | dtd->children = dtd->last = (xmlNodePtr) ret; |
| 382 | } else { |
| 383 | dtd->last->next = (xmlNodePtr) ret; |
| 384 | ret->prev = dtd->last; |
| 385 | dtd->last = (xmlNodePtr) ret; |
| 386 | } |
| 387 | return(ret); |
| 388 | } |
| 389 | |
| 390 | /** |
Daniel Veillard | aa6de47 | 2008-08-25 14:53:31 +0000 | [diff] [blame] | 391 | * xmlNewEntity: |
| 392 | * @doc: the document |
| 393 | * @name: the entity name |
| 394 | * @type: the entity type XML_xxx_yyy_ENTITY |
| 395 | * @ExternalID: the entity external ID if available |
| 396 | * @SystemID: the entity system ID if available |
| 397 | * @content: the entity content |
| 398 | * |
| 399 | * Create a new entity, this differs from xmlAddDocEntity() that if |
| 400 | * the document is NULL or has no internal subset defined, then an |
| 401 | * unlinked entity structure will be returned, it is then the responsability |
| 402 | * of the caller to link it to the document later or free it when not needed |
| 403 | * anymore. |
| 404 | * |
| 405 | * Returns a pointer to the entity or NULL in case of error |
| 406 | */ |
| 407 | xmlEntityPtr |
| 408 | xmlNewEntity(xmlDocPtr doc, const xmlChar *name, int type, |
| 409 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 410 | const xmlChar *content) { |
| 411 | xmlEntityPtr ret; |
| 412 | xmlDictPtr dict; |
| 413 | |
| 414 | if ((doc != NULL) && (doc->intSubset != NULL)) { |
| 415 | return(xmlAddDocEntity(doc, name, type, ExternalID, SystemID, content)); |
| 416 | } |
| 417 | if (doc != NULL) |
| 418 | dict = doc->dict; |
| 419 | else |
| 420 | dict = NULL; |
| 421 | ret = xmlCreateEntity(dict, name, type, ExternalID, SystemID, content); |
| 422 | if (ret == NULL) |
| 423 | return(NULL); |
| 424 | ret->doc = doc; |
| 425 | return(ret); |
| 426 | } |
| 427 | |
| 428 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 429 | * xmlGetEntityFromTable: |
| 430 | * @table: an entity table |
| 431 | * @name: the entity name |
| 432 | * @parameter: look for parameter entities |
| 433 | * |
| 434 | * Do an entity lookup in the table. |
| 435 | * returns the corresponding parameter entity, if found. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 436 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 437 | * Returns A pointer to the entity structure or NULL if not found. |
| 438 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 439 | static xmlEntityPtr |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 440 | xmlGetEntityFromTable(xmlEntitiesTablePtr table, const xmlChar *name) { |
| 441 | return((xmlEntityPtr) xmlHashLookup(table, name)); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * xmlGetParameterEntity: |
| 446 | * @doc: the document referencing the entity |
| 447 | * @name: the entity name |
| 448 | * |
| 449 | * Do an entity lookup in the internal and external subsets and |
| 450 | * returns the corresponding parameter entity, if found. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 451 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 452 | * Returns A pointer to the entity structure or NULL if not found. |
| 453 | */ |
| 454 | xmlEntityPtr |
| 455 | xmlGetParameterEntity(xmlDocPtr doc, const xmlChar *name) { |
| 456 | xmlEntitiesTablePtr table; |
| 457 | xmlEntityPtr ret; |
| 458 | |
Daniel Veillard | 3606581 | 2002-01-24 15:02:46 +0000 | [diff] [blame] | 459 | if (doc == NULL) |
| 460 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 461 | if ((doc->intSubset != NULL) && (doc->intSubset->pentities != NULL)) { |
| 462 | table = (xmlEntitiesTablePtr) doc->intSubset->pentities; |
| 463 | ret = xmlGetEntityFromTable(table, name); |
| 464 | if (ret != NULL) |
| 465 | return(ret); |
| 466 | } |
| 467 | if ((doc->extSubset != NULL) && (doc->extSubset->pentities != NULL)) { |
| 468 | table = (xmlEntitiesTablePtr) doc->extSubset->pentities; |
| 469 | return(xmlGetEntityFromTable(table, name)); |
| 470 | } |
| 471 | return(NULL); |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * xmlGetDtdEntity: |
| 476 | * @doc: the document referencing the entity |
| 477 | * @name: the entity name |
| 478 | * |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 479 | * Do an entity lookup in the DTD entity hash table and |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 480 | * returns the corresponding entity, if found. |
Daniel Veillard | 3606581 | 2002-01-24 15:02:46 +0000 | [diff] [blame] | 481 | * Note: the first argument is the document node, not the DTD node. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 482 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 483 | * Returns A pointer to the entity structure or NULL if not found. |
| 484 | */ |
| 485 | xmlEntityPtr |
| 486 | xmlGetDtdEntity(xmlDocPtr doc, const xmlChar *name) { |
| 487 | xmlEntitiesTablePtr table; |
| 488 | |
Daniel Veillard | 3606581 | 2002-01-24 15:02:46 +0000 | [diff] [blame] | 489 | if (doc == NULL) |
| 490 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 491 | if ((doc->extSubset != NULL) && (doc->extSubset->entities != NULL)) { |
| 492 | table = (xmlEntitiesTablePtr) doc->extSubset->entities; |
| 493 | return(xmlGetEntityFromTable(table, name)); |
| 494 | } |
| 495 | return(NULL); |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * xmlGetDocEntity: |
| 500 | * @doc: the document referencing the entity |
| 501 | * @name: the entity name |
| 502 | * |
| 503 | * Do an entity lookup in the document entity hash table and |
Daniel Veillard | cbaf399 | 2001-12-31 16:16:02 +0000 | [diff] [blame] | 504 | * returns the corresponding entity, otherwise a lookup is done |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 505 | * in the predefined entities too. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 506 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 507 | * Returns A pointer to the entity structure or NULL if not found. |
| 508 | */ |
| 509 | xmlEntityPtr |
Kurt Roeckx | 95ebe53 | 2014-10-13 16:06:21 +0800 | [diff] [blame] | 510 | xmlGetDocEntity(const xmlDoc *doc, const xmlChar *name) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 511 | xmlEntityPtr cur; |
| 512 | xmlEntitiesTablePtr table; |
| 513 | |
| 514 | if (doc != NULL) { |
| 515 | if ((doc->intSubset != NULL) && (doc->intSubset->entities != NULL)) { |
| 516 | table = (xmlEntitiesTablePtr) doc->intSubset->entities; |
| 517 | cur = xmlGetEntityFromTable(table, name); |
| 518 | if (cur != NULL) |
| 519 | return(cur); |
| 520 | } |
Daniel Veillard | 2875770 | 2002-02-18 11:19:30 +0000 | [diff] [blame] | 521 | if (doc->standalone != 1) { |
| 522 | if ((doc->extSubset != NULL) && |
| 523 | (doc->extSubset->entities != NULL)) { |
| 524 | table = (xmlEntitiesTablePtr) doc->extSubset->entities; |
| 525 | cur = xmlGetEntityFromTable(table, name); |
| 526 | if (cur != NULL) |
| 527 | return(cur); |
| 528 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 529 | } |
| 530 | } |
Daniel Veillard | d3a2e4c | 2003-09-30 13:38:04 +0000 | [diff] [blame] | 531 | return(xmlGetPredefinedEntity(name)); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 535 | * Macro used to grow the current buffer. |
| 536 | */ |
| 537 | #define growBufferReentrant() { \ |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 538 | xmlChar *tmp; \ |
Aron Xu | baaf03f | 2012-07-20 15:41:34 +0800 | [diff] [blame] | 539 | size_t new_size = buffer_size * 2; \ |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 540 | if (new_size < buffer_size) goto mem_error; \ |
| 541 | tmp = (xmlChar *) xmlRealloc(buffer, new_size); \ |
| 542 | if (tmp == NULL) goto mem_error; \ |
| 543 | buffer = tmp; \ |
| 544 | buffer_size = new_size; \ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 547 | /** |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 548 | * xmlEncodeEntitiesInternal: |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 549 | * @doc: the document containing the string |
| 550 | * @input: A string to convert to XML. |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 551 | * @attr: are we handling an atrbute value |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 552 | * |
| 553 | * Do a global encoding of a string, replacing the predefined entities |
| 554 | * and non ASCII values with their entities and CharRef counterparts. |
| 555 | * Contrary to xmlEncodeEntities, this routine is reentrant, and result |
| 556 | * must be deallocated. |
| 557 | * |
| 558 | * Returns A newly allocated string with the substitution done. |
| 559 | */ |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 560 | static xmlChar * |
| 561 | xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 562 | const xmlChar *cur = input; |
| 563 | xmlChar *buffer = NULL; |
| 564 | xmlChar *out = NULL; |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 565 | size_t buffer_size = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 566 | int html = 0; |
| 567 | |
| 568 | if (input == NULL) return(NULL); |
| 569 | if (doc != NULL) |
| 570 | html = (doc->type == XML_HTML_DOCUMENT_NODE); |
| 571 | |
| 572 | /* |
| 573 | * allocate an translation buffer. |
| 574 | */ |
| 575 | buffer_size = 1000; |
| 576 | buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); |
| 577 | if (buffer == NULL) { |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 578 | xmlEntitiesErrMemory("xmlEncodeEntities: malloc failed"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 579 | return(NULL); |
| 580 | } |
| 581 | out = buffer; |
| 582 | |
| 583 | while (*cur != '\0') { |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 584 | size_t indx = out - buffer; |
| 585 | if (indx + 100 > buffer_size) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 586 | |
| 587 | growBufferReentrant(); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 588 | out = &buffer[indx]; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /* |
| 592 | * By default one have to encode at least '<', '>', '"' and '&' ! |
| 593 | */ |
| 594 | if (*cur == '<') { |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 595 | const xmlChar *end; |
| 596 | |
| 597 | /* |
| 598 | * Special handling of server side include in HTML attributes |
| 599 | */ |
| 600 | if (html && attr && |
| 601 | (cur[1] == '!') && (cur[2] == '-') && (cur[3] == '-') && |
| 602 | ((end = xmlStrstr(cur, BAD_CAST "-->")) != NULL)) { |
| 603 | while (cur != end) { |
| 604 | *out++ = *cur++; |
| 605 | indx = out - buffer; |
| 606 | if (indx + 100 > buffer_size) { |
| 607 | growBufferReentrant(); |
| 608 | out = &buffer[indx]; |
| 609 | } |
| 610 | } |
| 611 | *out++ = *cur++; |
| 612 | *out++ = *cur++; |
| 613 | *out++ = *cur++; |
| 614 | continue; |
| 615 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 616 | *out++ = '&'; |
| 617 | *out++ = 'l'; |
| 618 | *out++ = 't'; |
| 619 | *out++ = ';'; |
| 620 | } else if (*cur == '>') { |
| 621 | *out++ = '&'; |
| 622 | *out++ = 'g'; |
| 623 | *out++ = 't'; |
| 624 | *out++ = ';'; |
| 625 | } else if (*cur == '&') { |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 626 | /* |
| 627 | * Special handling of &{...} construct from HTML 4, see |
| 628 | * http://www.w3.org/TR/html401/appendix/notes.html#h-B.7.1 |
| 629 | */ |
Daniel Veillard | 7651606 | 2012-09-11 14:02:08 +0800 | [diff] [blame] | 630 | if (html && attr && (cur[1] == '{') && |
| 631 | (strchr((const char *) cur, '}'))) { |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 632 | while (*cur != '}') { |
| 633 | *out++ = *cur++; |
| 634 | indx = out - buffer; |
| 635 | if (indx + 100 > buffer_size) { |
| 636 | growBufferReentrant(); |
| 637 | out = &buffer[indx]; |
| 638 | } |
| 639 | } |
| 640 | *out++ = *cur++; |
| 641 | continue; |
| 642 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 643 | *out++ = '&'; |
| 644 | *out++ = 'a'; |
| 645 | *out++ = 'm'; |
| 646 | *out++ = 'p'; |
| 647 | *out++ = ';'; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 648 | } else if (((*cur >= 0x20) && (*cur < 0x80)) || |
Daniel Veillard | 0046c0f | 2003-02-23 13:52:30 +0000 | [diff] [blame] | 649 | (*cur == '\n') || (*cur == '\t') || ((html) && (*cur == '\r'))) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 650 | /* |
| 651 | * default case, just copy ! |
| 652 | */ |
| 653 | *out++ = *cur; |
| 654 | } else if (*cur >= 0x80) { |
Daniel Veillard | 122376b | 2001-04-24 12:12:30 +0000 | [diff] [blame] | 655 | if (((doc != NULL) && (doc->encoding != NULL)) || (html)) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 656 | /* |
Daniel Veillard | 0ab8ce5 | 2013-03-28 08:47:42 +0800 | [diff] [blame] | 657 | * Bjørn Reese <br@sseusa.com> provided the patch |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 658 | xmlChar xc; |
| 659 | xc = (*cur & 0x3F) << 6; |
| 660 | if (cur[1] != 0) { |
| 661 | xc += *(++cur) & 0x3F; |
| 662 | *out++ = xc; |
| 663 | } else |
| 664 | */ |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 665 | *out++ = *cur; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 666 | } else { |
| 667 | /* |
| 668 | * We assume we have UTF-8 input. |
| 669 | */ |
Daniel Veillard | b2517d8 | 2003-10-01 19:13:56 +0000 | [diff] [blame] | 670 | char buf[11], *ptr; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 671 | int val = 0, l = 1; |
| 672 | |
| 673 | if (*cur < 0xC0) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 674 | xmlEntitiesErr(XML_CHECK_NOT_UTF8, |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 675 | "xmlEncodeEntities: input not UTF-8"); |
Daniel Veillard | 122376b | 2001-04-24 12:12:30 +0000 | [diff] [blame] | 676 | if (doc != NULL) |
| 677 | doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 678 | snprintf(buf, sizeof(buf), "&#%d;", *cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 679 | buf[sizeof(buf) - 1] = 0; |
| 680 | ptr = buf; |
| 681 | while (*ptr != 0) *out++ = *ptr++; |
Daniel Veillard | 05c13a2 | 2001-09-09 08:38:09 +0000 | [diff] [blame] | 682 | cur++; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 683 | continue; |
| 684 | } else if (*cur < 0xE0) { |
| 685 | val = (cur[0]) & 0x1F; |
| 686 | val <<= 6; |
| 687 | val |= (cur[1]) & 0x3F; |
| 688 | l = 2; |
| 689 | } else if (*cur < 0xF0) { |
| 690 | val = (cur[0]) & 0x0F; |
| 691 | val <<= 6; |
| 692 | val |= (cur[1]) & 0x3F; |
| 693 | val <<= 6; |
| 694 | val |= (cur[2]) & 0x3F; |
| 695 | l = 3; |
| 696 | } else if (*cur < 0xF8) { |
| 697 | val = (cur[0]) & 0x07; |
| 698 | val <<= 6; |
| 699 | val |= (cur[1]) & 0x3F; |
| 700 | val <<= 6; |
| 701 | val |= (cur[2]) & 0x3F; |
| 702 | val <<= 6; |
| 703 | val |= (cur[3]) & 0x3F; |
| 704 | l = 4; |
| 705 | } |
| 706 | if ((l == 1) || (!IS_CHAR(val))) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 707 | xmlEntitiesErr(XML_ERR_INVALID_CHAR, |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 708 | "xmlEncodeEntities: char out of range\n"); |
Daniel Veillard | 122376b | 2001-04-24 12:12:30 +0000 | [diff] [blame] | 709 | if (doc != NULL) |
| 710 | doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 711 | snprintf(buf, sizeof(buf), "&#%d;", *cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 712 | buf[sizeof(buf) - 1] = 0; |
| 713 | ptr = buf; |
| 714 | while (*ptr != 0) *out++ = *ptr++; |
| 715 | cur++; |
| 716 | continue; |
| 717 | } |
| 718 | /* |
| 719 | * We could do multiple things here. Just save as a char ref |
| 720 | */ |
Daniel Veillard | 2728f84 | 2006-03-09 16:49:24 +0000 | [diff] [blame] | 721 | snprintf(buf, sizeof(buf), "&#x%X;", val); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 722 | buf[sizeof(buf) - 1] = 0; |
| 723 | ptr = buf; |
| 724 | while (*ptr != 0) *out++ = *ptr++; |
| 725 | cur += l; |
| 726 | continue; |
| 727 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 728 | } else if (IS_BYTE_CHAR(*cur)) { |
Daniel Veillard | b2517d8 | 2003-10-01 19:13:56 +0000 | [diff] [blame] | 729 | char buf[11], *ptr; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 730 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 731 | snprintf(buf, sizeof(buf), "&#%d;", *cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 732 | buf[sizeof(buf) - 1] = 0; |
| 733 | ptr = buf; |
| 734 | while (*ptr != 0) *out++ = *ptr++; |
| 735 | } |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 736 | cur++; |
| 737 | } |
Daniel Veillard | 13cee4e | 2009-09-05 14:52:55 +0200 | [diff] [blame] | 738 | *out = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 739 | return(buffer); |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 740 | |
| 741 | mem_error: |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 742 | xmlEntitiesErrMemory("xmlEncodeEntities: realloc failed"); |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 743 | xmlFree(buffer); |
| 744 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /** |
Daniel Veillard | 7d4c529 | 2012-09-05 11:45:32 +0800 | [diff] [blame] | 748 | * xmlEncodeAttributeEntities: |
| 749 | * @doc: the document containing the string |
| 750 | * @input: A string to convert to XML. |
| 751 | * |
| 752 | * Do a global encoding of a string, replacing the predefined entities |
| 753 | * and non ASCII values with their entities and CharRef counterparts for |
| 754 | * attribute values. |
| 755 | * |
| 756 | * Returns A newly allocated string with the substitution done. |
| 757 | */ |
| 758 | xmlChar * |
| 759 | xmlEncodeAttributeEntities(xmlDocPtr doc, const xmlChar *input) { |
| 760 | return xmlEncodeEntitiesInternal(doc, input, 1); |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * xmlEncodeEntitiesReentrant: |
| 765 | * @doc: the document containing the string |
| 766 | * @input: A string to convert to XML. |
| 767 | * |
| 768 | * Do a global encoding of a string, replacing the predefined entities |
| 769 | * and non ASCII values with their entities and CharRef counterparts. |
| 770 | * Contrary to xmlEncodeEntities, this routine is reentrant, and result |
| 771 | * must be deallocated. |
| 772 | * |
| 773 | * Returns A newly allocated string with the substitution done. |
| 774 | */ |
| 775 | xmlChar * |
| 776 | xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { |
| 777 | return xmlEncodeEntitiesInternal(doc, input, 0); |
| 778 | } |
| 779 | |
| 780 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 781 | * xmlEncodeSpecialChars: |
| 782 | * @doc: the document containing the string |
| 783 | * @input: A string to convert to XML. |
| 784 | * |
| 785 | * Do a global encoding of a string, replacing the predefined entities |
| 786 | * this routine is reentrant, and result must be deallocated. |
| 787 | * |
| 788 | * Returns A newly allocated string with the substitution done. |
| 789 | */ |
| 790 | xmlChar * |
Kurt Roeckx | 95ebe53 | 2014-10-13 16:06:21 +0800 | [diff] [blame] | 791 | xmlEncodeSpecialChars(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlChar *input) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 792 | const xmlChar *cur = input; |
| 793 | xmlChar *buffer = NULL; |
| 794 | xmlChar *out = NULL; |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 795 | size_t buffer_size = 0; |
William M. Brack | 899e64a | 2003-09-26 18:03:42 +0000 | [diff] [blame] | 796 | if (input == NULL) return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 797 | |
| 798 | /* |
| 799 | * allocate an translation buffer. |
| 800 | */ |
| 801 | buffer_size = 1000; |
| 802 | buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); |
| 803 | if (buffer == NULL) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 804 | xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 805 | return(NULL); |
| 806 | } |
| 807 | out = buffer; |
| 808 | |
| 809 | while (*cur != '\0') { |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 810 | size_t indx = out - buffer; |
| 811 | if (indx + 10 > buffer_size) { |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 812 | |
| 813 | growBufferReentrant(); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 814 | out = &buffer[indx]; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* |
| 818 | * By default one have to encode at least '<', '>', '"' and '&' ! |
| 819 | */ |
| 820 | if (*cur == '<') { |
| 821 | *out++ = '&'; |
| 822 | *out++ = 'l'; |
| 823 | *out++ = 't'; |
| 824 | *out++ = ';'; |
| 825 | } else if (*cur == '>') { |
| 826 | *out++ = '&'; |
| 827 | *out++ = 'g'; |
| 828 | *out++ = 't'; |
| 829 | *out++ = ';'; |
| 830 | } else if (*cur == '&') { |
| 831 | *out++ = '&'; |
| 832 | *out++ = 'a'; |
| 833 | *out++ = 'm'; |
| 834 | *out++ = 'p'; |
| 835 | *out++ = ';'; |
| 836 | } else if (*cur == '"') { |
| 837 | *out++ = '&'; |
| 838 | *out++ = 'q'; |
| 839 | *out++ = 'u'; |
| 840 | *out++ = 'o'; |
| 841 | *out++ = 't'; |
| 842 | *out++ = ';'; |
Daniel Veillard | 19ab45b | 2003-02-26 15:49:03 +0000 | [diff] [blame] | 843 | } else if (*cur == '\r') { |
| 844 | *out++ = '&'; |
| 845 | *out++ = '#'; |
| 846 | *out++ = '1'; |
| 847 | *out++ = '3'; |
| 848 | *out++ = ';'; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 849 | } else { |
| 850 | /* |
| 851 | * Works because on UTF-8, all extended sequences cannot |
| 852 | * result in bytes in the ASCII range. |
| 853 | */ |
| 854 | *out++ = *cur; |
| 855 | } |
| 856 | cur++; |
| 857 | } |
Daniel Veillard | 13cee4e | 2009-09-05 14:52:55 +0200 | [diff] [blame] | 858 | *out = 0; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 859 | return(buffer); |
Daniel Veillard | 4f9fdc7 | 2012-07-18 11:38:17 +0800 | [diff] [blame] | 860 | |
| 861 | mem_error: |
| 862 | xmlEntitiesErrMemory("xmlEncodeSpecialChars: realloc failed"); |
| 863 | xmlFree(buffer); |
| 864 | return(NULL); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | /** |
| 868 | * xmlCreateEntitiesTable: |
| 869 | * |
| 870 | * create and initialize an empty entities hash table. |
Daniel Veillard | 316a5c3 | 2005-01-23 22:56:39 +0000 | [diff] [blame] | 871 | * This really doesn't make sense and should be deprecated |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 872 | * |
| 873 | * Returns the xmlEntitiesTablePtr just created or NULL in case of error. |
| 874 | */ |
| 875 | xmlEntitiesTablePtr |
| 876 | xmlCreateEntitiesTable(void) { |
| 877 | return((xmlEntitiesTablePtr) xmlHashCreate(0)); |
| 878 | } |
| 879 | |
| 880 | /** |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 881 | * xmlFreeEntityWrapper: |
| 882 | * @entity: An entity |
| 883 | * @name: its name |
| 884 | * |
| 885 | * Deallocate the memory used by an entities in the hash table. |
| 886 | */ |
| 887 | static void |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 888 | xmlFreeEntityWrapper(void *entity, const xmlChar *name ATTRIBUTE_UNUSED) { |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 889 | if (entity != NULL) |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 890 | xmlFreeEntity((xmlEntityPtr) entity); |
Daniel Veillard | 2d84a89 | 2002-12-30 00:01:08 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 894 | * xmlFreeEntitiesTable: |
| 895 | * @table: An entity table |
| 896 | * |
| 897 | * Deallocate the memory used by an entities hash table. |
| 898 | */ |
| 899 | void |
| 900 | xmlFreeEntitiesTable(xmlEntitiesTablePtr table) { |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 901 | xmlHashFree(table, xmlFreeEntityWrapper); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 904 | #ifdef LIBXML_TREE_ENABLED |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 905 | /** |
| 906 | * xmlCopyEntity: |
| 907 | * @ent: An entity |
| 908 | * |
| 909 | * Build a copy of an entity |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 910 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 911 | * Returns the new xmlEntitiesPtr or NULL in case of error. |
| 912 | */ |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 913 | static void * |
| 914 | xmlCopyEntity(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) { |
| 915 | xmlEntityPtr ent = (xmlEntityPtr) payload; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 916 | xmlEntityPtr cur; |
| 917 | |
| 918 | cur = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); |
| 919 | if (cur == NULL) { |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 920 | xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 921 | return(NULL); |
| 922 | } |
| 923 | memset(cur, 0, sizeof(xmlEntity)); |
Daniel Veillard | 845cce4 | 2002-01-09 11:51:37 +0000 | [diff] [blame] | 924 | cur->type = XML_ENTITY_DECL; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 925 | |
| 926 | cur->etype = ent->etype; |
| 927 | if (ent->name != NULL) |
| 928 | cur->name = xmlStrdup(ent->name); |
| 929 | if (ent->ExternalID != NULL) |
| 930 | cur->ExternalID = xmlStrdup(ent->ExternalID); |
| 931 | if (ent->SystemID != NULL) |
| 932 | cur->SystemID = xmlStrdup(ent->SystemID); |
| 933 | if (ent->content != NULL) |
| 934 | cur->content = xmlStrdup(ent->content); |
| 935 | if (ent->orig != NULL) |
| 936 | cur->orig = xmlStrdup(ent->orig); |
Daniel Veillard | 8ee9c8f | 2002-01-26 21:42:58 +0000 | [diff] [blame] | 937 | if (ent->URI != NULL) |
| 938 | cur->URI = xmlStrdup(ent->URI); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 939 | return(cur); |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * xmlCopyEntitiesTable: |
| 944 | * @table: An entity table |
| 945 | * |
| 946 | * Build a copy of an entity table. |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 947 | * |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 948 | * Returns the new xmlEntitiesTablePtr or NULL in case of error. |
| 949 | */ |
| 950 | xmlEntitiesTablePtr |
| 951 | xmlCopyEntitiesTable(xmlEntitiesTablePtr table) { |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 952 | return(xmlHashCopy(table, xmlCopyEntity)); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 953 | } |
Daniel Veillard | 652327a | 2003-09-29 18:02:38 +0000 | [diff] [blame] | 954 | #endif /* LIBXML_TREE_ENABLED */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 955 | |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 956 | #ifdef LIBXML_OUTPUT_ENABLED |
Daniel Veillard | 18ab872 | 2003-12-09 22:51:37 +0000 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * xmlDumpEntityContent: |
| 960 | * @buf: An XML buffer. |
| 961 | * @content: The entity content. |
| 962 | * |
| 963 | * This will dump the quoted string value, taking care of the special |
| 964 | * treatment required by % |
| 965 | */ |
| 966 | static void |
| 967 | xmlDumpEntityContent(xmlBufferPtr buf, const xmlChar *content) { |
| 968 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; |
| 969 | if (xmlStrchr(content, '%')) { |
| 970 | const xmlChar * base, *cur; |
| 971 | |
| 972 | xmlBufferCCat(buf, "\""); |
| 973 | base = cur = content; |
| 974 | while (*cur != 0) { |
| 975 | if (*cur == '"') { |
| 976 | if (base != cur) |
| 977 | xmlBufferAdd(buf, base, cur - base); |
| 978 | xmlBufferAdd(buf, BAD_CAST """, 6); |
| 979 | cur++; |
| 980 | base = cur; |
| 981 | } else if (*cur == '%') { |
| 982 | if (base != cur) |
| 983 | xmlBufferAdd(buf, base, cur - base); |
| 984 | xmlBufferAdd(buf, BAD_CAST "%", 6); |
| 985 | cur++; |
| 986 | base = cur; |
| 987 | } else { |
| 988 | cur++; |
| 989 | } |
| 990 | } |
| 991 | if (base != cur) |
| 992 | xmlBufferAdd(buf, base, cur - base); |
| 993 | xmlBufferCCat(buf, "\""); |
| 994 | } else { |
| 995 | xmlBufferWriteQuotedString(buf, content); |
| 996 | } |
| 997 | } |
| 998 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 999 | /** |
| 1000 | * xmlDumpEntityDecl: |
| 1001 | * @buf: An XML buffer. |
| 1002 | * @ent: An entity table |
| 1003 | * |
| 1004 | * This will dump the content of the entity table as an XML DTD definition |
| 1005 | */ |
| 1006 | void |
| 1007 | xmlDumpEntityDecl(xmlBufferPtr buf, xmlEntityPtr ent) { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 1008 | if ((buf == NULL) || (ent == NULL)) return; |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1009 | switch (ent->etype) { |
| 1010 | case XML_INTERNAL_GENERAL_ENTITY: |
| 1011 | xmlBufferWriteChar(buf, "<!ENTITY "); |
| 1012 | xmlBufferWriteCHAR(buf, ent->name); |
| 1013 | xmlBufferWriteChar(buf, " "); |
| 1014 | if (ent->orig != NULL) |
| 1015 | xmlBufferWriteQuotedString(buf, ent->orig); |
| 1016 | else |
Daniel Veillard | 18ab872 | 2003-12-09 22:51:37 +0000 | [diff] [blame] | 1017 | xmlDumpEntityContent(buf, ent->content); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1018 | xmlBufferWriteChar(buf, ">\n"); |
| 1019 | break; |
| 1020 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 1021 | xmlBufferWriteChar(buf, "<!ENTITY "); |
| 1022 | xmlBufferWriteCHAR(buf, ent->name); |
| 1023 | if (ent->ExternalID != NULL) { |
| 1024 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 1025 | xmlBufferWriteQuotedString(buf, ent->ExternalID); |
| 1026 | xmlBufferWriteChar(buf, " "); |
| 1027 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 1028 | } else { |
| 1029 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 1030 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 1031 | } |
| 1032 | xmlBufferWriteChar(buf, ">\n"); |
| 1033 | break; |
| 1034 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 1035 | xmlBufferWriteChar(buf, "<!ENTITY "); |
| 1036 | xmlBufferWriteCHAR(buf, ent->name); |
| 1037 | if (ent->ExternalID != NULL) { |
| 1038 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 1039 | xmlBufferWriteQuotedString(buf, ent->ExternalID); |
| 1040 | xmlBufferWriteChar(buf, " "); |
| 1041 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 1042 | } else { |
| 1043 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 1044 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 1045 | } |
| 1046 | if (ent->content != NULL) { /* Should be true ! */ |
| 1047 | xmlBufferWriteChar(buf, " NDATA "); |
| 1048 | if (ent->orig != NULL) |
| 1049 | xmlBufferWriteCHAR(buf, ent->orig); |
| 1050 | else |
| 1051 | xmlBufferWriteCHAR(buf, ent->content); |
| 1052 | } |
| 1053 | xmlBufferWriteChar(buf, ">\n"); |
| 1054 | break; |
| 1055 | case XML_INTERNAL_PARAMETER_ENTITY: |
| 1056 | xmlBufferWriteChar(buf, "<!ENTITY % "); |
| 1057 | xmlBufferWriteCHAR(buf, ent->name); |
| 1058 | xmlBufferWriteChar(buf, " "); |
| 1059 | if (ent->orig == NULL) |
Daniel Veillard | 18ab872 | 2003-12-09 22:51:37 +0000 | [diff] [blame] | 1060 | xmlDumpEntityContent(buf, ent->content); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1061 | else |
| 1062 | xmlBufferWriteQuotedString(buf, ent->orig); |
| 1063 | xmlBufferWriteChar(buf, ">\n"); |
| 1064 | break; |
| 1065 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| 1066 | xmlBufferWriteChar(buf, "<!ENTITY % "); |
| 1067 | xmlBufferWriteCHAR(buf, ent->name); |
| 1068 | if (ent->ExternalID != NULL) { |
| 1069 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 1070 | xmlBufferWriteQuotedString(buf, ent->ExternalID); |
| 1071 | xmlBufferWriteChar(buf, " "); |
| 1072 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 1073 | } else { |
| 1074 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 1075 | xmlBufferWriteQuotedString(buf, ent->SystemID); |
| 1076 | } |
| 1077 | xmlBufferWriteChar(buf, ">\n"); |
| 1078 | break; |
| 1079 | default: |
Daniel Veillard | ce244ad | 2004-11-05 10:03:46 +0000 | [diff] [blame] | 1080 | xmlEntitiesErr(XML_DTD_UNKNOWN_ENTITY, |
| 1081 | "xmlDumpEntitiesDecl: internal: unknown type entity type"); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | /** |
William M. Brack | 9e66059 | 2003-10-20 14:56:06 +0000 | [diff] [blame] | 1086 | * xmlDumpEntityDeclScan: |
| 1087 | * @ent: An entity table |
| 1088 | * @buf: An XML buffer. |
| 1089 | * |
| 1090 | * When using the hash table scan function, arguments need to be reversed |
| 1091 | */ |
| 1092 | static void |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 1093 | xmlDumpEntityDeclScan(void *ent, void *buf, |
| 1094 | const xmlChar *name ATTRIBUTE_UNUSED) { |
| 1095 | xmlDumpEntityDecl((xmlBufferPtr) buf, (xmlEntityPtr) ent); |
William M. Brack | 9e66059 | 2003-10-20 14:56:06 +0000 | [diff] [blame] | 1096 | } |
Daniel Veillard | f8e3db0 | 2012-09-11 13:26:36 +0800 | [diff] [blame] | 1097 | |
William M. Brack | 9e66059 | 2003-10-20 14:56:06 +0000 | [diff] [blame] | 1098 | /** |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1099 | * xmlDumpEntitiesTable: |
| 1100 | * @buf: An XML buffer. |
| 1101 | * @table: An entity table |
| 1102 | * |
| 1103 | * This will dump the content of the entity table as an XML DTD definition |
| 1104 | */ |
| 1105 | void |
| 1106 | xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { |
Nick Wellnhofer | e03f0a1 | 2017-11-09 16:42:47 +0100 | [diff] [blame] | 1107 | xmlHashScan(table, xmlDumpEntityDeclScan, buf); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1108 | } |
Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1109 | #endif /* LIBXML_OUTPUT_ENABLED */ |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 1110 | #define bottom_entities |
| 1111 | #include "elfgcchack.h" |