Paul Cercueil / libxml2

Dependents:   libiio

Committer:
pcercuei
Date:
Thu Aug 25 10:05:35 2016 +0000
Revision:
0:03b5121a232e
Add basic C files of libxml2 2.9.4

Who changed what in which revision?

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