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