| OLD | NEW |
| 1 /* | 1 /* |
| 2 * entities.c : implementation for the XML entities handling | 2 * entities.c : implementation for the XML entities handling |
| 3 * | 3 * |
| 4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
| 5 * | 5 * |
| 6 * daniel@veillard.com | 6 * daniel@veillard.com |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #define IN_LIBXML | 9 #define IN_LIBXML |
| 10 #include "libxml.h" | 10 #include "libxml.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 xmlFree((char *) entity->URI); | 132 xmlFree((char *) entity->URI); |
| 133 if (entity->content != NULL) | 133 if (entity->content != NULL) |
| 134 xmlFree((char *) entity->content); | 134 xmlFree((char *) entity->content); |
| 135 if (entity->orig != NULL) | 135 if (entity->orig != NULL) |
| 136 xmlFree((char *) entity->orig); | 136 xmlFree((char *) entity->orig); |
| 137 } | 137 } |
| 138 xmlFree(entity); | 138 xmlFree(entity); |
| 139 } | 139 } |
| 140 | 140 |
| 141 /* | 141 /* |
| 142 * xmlAddEntity : register a new entity for an entities table. | 142 * xmlCreateEntity: |
| 143 * |
| 144 * internal routine doing the entity node strutures allocations |
| 143 */ | 145 */ |
| 144 static xmlEntityPtr | 146 static xmlEntityPtr |
| 145 xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type, | 147 xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type, |
| 146 » const xmlChar *ExternalID, const xmlChar *SystemID, | 148 » const xmlChar *ExternalID, const xmlChar *SystemID, |
| 147 » const xmlChar *content) { | 149 » const xmlChar *content) { |
| 148 xmlDictPtr dict = NULL; | |
| 149 xmlEntitiesTablePtr table = NULL; | |
| 150 xmlEntityPtr ret; | 150 xmlEntityPtr ret; |
| 151 | 151 |
| 152 if (name == NULL) | |
| 153 return(NULL); | |
| 154 if (dtd == NULL) | |
| 155 return(NULL); | |
| 156 if (dtd->doc != NULL) | |
| 157 dict = dtd->doc->dict; | |
| 158 | |
| 159 switch (type) { | |
| 160 case XML_INTERNAL_GENERAL_ENTITY: | |
| 161 case XML_EXTERNAL_GENERAL_PARSED_ENTITY: | |
| 162 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: | |
| 163 if (dtd->entities == NULL) | |
| 164 dtd->entities = xmlHashCreateDict(0, dict); | |
| 165 table = dtd->entities; | |
| 166 break; | |
| 167 case XML_INTERNAL_PARAMETER_ENTITY: | |
| 168 case XML_EXTERNAL_PARAMETER_ENTITY: | |
| 169 if (dtd->pentities == NULL) | |
| 170 dtd->pentities = xmlHashCreateDict(0, dict); | |
| 171 table = dtd->pentities; | |
| 172 break; | |
| 173 case XML_INTERNAL_PREDEFINED_ENTITY: | |
| 174 return(NULL); | |
| 175 } | |
| 176 if (table == NULL) | |
| 177 return(NULL); | |
| 178 ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); | 152 ret = (xmlEntityPtr) xmlMalloc(sizeof(xmlEntity)); |
| 179 if (ret == NULL) { | 153 if (ret == NULL) { |
| 180 xmlEntitiesErrMemory("xmlAddEntity:: malloc failed"); | 154 xmlEntitiesErrMemory("xmlCreateEntity: malloc failed"); |
| 181 return(NULL); | 155 return(NULL); |
| 182 } | 156 } |
| 183 memset(ret, 0, sizeof(xmlEntity)); | 157 memset(ret, 0, sizeof(xmlEntity)); |
| 184 ret->type = XML_ENTITY_DECL; | 158 ret->type = XML_ENTITY_DECL; |
| 185 ret->checked = 0; | 159 ret->checked = 0; |
| 186 | 160 |
| 187 /* | 161 /* |
| 188 * fill the structure. | 162 * fill the structure. |
| 189 */ | 163 */ |
| 190 ret->etype = (xmlEntityType) type; | 164 ret->etype = (xmlEntityType) type; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 209 else | 183 else |
| 210 ret->content = xmlStrndup(content, ret->length); | 184 ret->content = xmlStrndup(content, ret->length); |
| 211 } else { | 185 } else { |
| 212 ret->length = 0; | 186 ret->length = 0; |
| 213 ret->content = NULL; | 187 ret->content = NULL; |
| 214 } | 188 } |
| 215 ret->URI = NULL; /* to be computed by the layer knowing | 189 ret->URI = NULL; /* to be computed by the layer knowing |
| 216 the defining entity */ | 190 the defining entity */ |
| 217 ret->orig = NULL; | 191 ret->orig = NULL; |
| 218 ret->owner = 0; | 192 ret->owner = 0; |
| 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); |
| 219 ret->doc = dtd->doc; | 237 ret->doc = dtd->doc; |
| 220 | 238 |
| 221 if (xmlHashAddEntry(table, name, ret)) { | 239 if (xmlHashAddEntry(table, name, ret)) { |
| 222 /* | 240 /* |
| 223 * entity was already defined at another level. | 241 * entity was already defined at another level. |
| 224 */ | 242 */ |
| 225 xmlFreeEntity(ret); | 243 xmlFreeEntity(ret); |
| 226 return(NULL); | 244 return(NULL); |
| 227 } | 245 } |
| 228 return(ret); | 246 return(ret); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 dtd->children = dtd->last = (xmlNodePtr) ret; | 374 dtd->children = dtd->last = (xmlNodePtr) ret; |
| 357 } else { | 375 } else { |
| 358 dtd->last->next = (xmlNodePtr) ret; | 376 dtd->last->next = (xmlNodePtr) ret; |
| 359 ret->prev = dtd->last; | 377 ret->prev = dtd->last; |
| 360 dtd->last = (xmlNodePtr) ret; | 378 dtd->last = (xmlNodePtr) ret; |
| 361 } | 379 } |
| 362 return(ret); | 380 return(ret); |
| 363 } | 381 } |
| 364 | 382 |
| 365 /** | 383 /** |
| 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 /** |
| 366 * xmlGetEntityFromTable: | 422 * xmlGetEntityFromTable: |
| 367 * @table: an entity table | 423 * @table: an entity table |
| 368 * @name: the entity name | 424 * @name: the entity name |
| 369 * @parameter: look for parameter entities | 425 * @parameter: look for parameter entities |
| 370 * | 426 * |
| 371 * Do an entity lookup in the table. | 427 * Do an entity lookup in the table. |
| 372 * returns the corresponding parameter entity, if found. | 428 * returns the corresponding parameter entity, if found. |
| 373 * | 429 * |
| 374 * Returns A pointer to the entity structure or NULL if not found. | 430 * Returns A pointer to the entity structure or NULL if not found. |
| 375 */ | 431 */ |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 } else if (IS_BYTE_CHAR(*cur)) { | 683 } else if (IS_BYTE_CHAR(*cur)) { |
| 628 char buf[11], *ptr; | 684 char buf[11], *ptr; |
| 629 | 685 |
| 630 snprintf(buf, sizeof(buf), "&#%d;", *cur); | 686 snprintf(buf, sizeof(buf), "&#%d;", *cur); |
| 631 buf[sizeof(buf) - 1] = 0; | 687 buf[sizeof(buf) - 1] = 0; |
| 632 ptr = buf; | 688 ptr = buf; |
| 633 while (*ptr != 0) *out++ = *ptr++; | 689 while (*ptr != 0) *out++ = *ptr++; |
| 634 } | 690 } |
| 635 cur++; | 691 cur++; |
| 636 } | 692 } |
| 637 *out++ = 0; | 693 *out = 0; |
| 638 return(buffer); | 694 return(buffer); |
| 639 } | 695 } |
| 640 | 696 |
| 641 /** | 697 /** |
| 642 * xmlEncodeSpecialChars: | 698 * xmlEncodeSpecialChars: |
| 643 * @doc: the document containing the string | 699 * @doc: the document containing the string |
| 644 * @input: A string to convert to XML. | 700 * @input: A string to convert to XML. |
| 645 * | 701 * |
| 646 * Do a global encoding of a string, replacing the predefined entities | 702 * Do a global encoding of a string, replacing the predefined entities |
| 647 * this routine is reentrant, and result must be deallocated. | 703 * this routine is reentrant, and result must be deallocated. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 *out++ = ';'; | 765 *out++ = ';'; |
| 710 } else { | 766 } else { |
| 711 /* | 767 /* |
| 712 * Works because on UTF-8, all extended sequences cannot | 768 * Works because on UTF-8, all extended sequences cannot |
| 713 * result in bytes in the ASCII range. | 769 * result in bytes in the ASCII range. |
| 714 */ | 770 */ |
| 715 *out++ = *cur; | 771 *out++ = *cur; |
| 716 } | 772 } |
| 717 cur++; | 773 cur++; |
| 718 } | 774 } |
| 719 *out++ = 0; | 775 *out = 0; |
| 720 return(buffer); | 776 return(buffer); |
| 721 } | 777 } |
| 722 | 778 |
| 723 /** | 779 /** |
| 724 * xmlCreateEntitiesTable: | 780 * xmlCreateEntitiesTable: |
| 725 * | 781 * |
| 726 * create and initialize an empty entities hash table. | 782 * create and initialize an empty entities hash table. |
| 727 * This really doesn't make sense and should be deprecated | 783 * This really doesn't make sense and should be deprecated |
| 728 * | 784 * |
| 729 * Returns the xmlEntitiesTablePtr just created or NULL in case of error. | 785 * Returns the xmlEntitiesTablePtr just created or NULL in case of error. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 * | 1013 * |
| 958 * This will dump the content of the entity table as an XML DTD definition | 1014 * This will dump the content of the entity table as an XML DTD definition |
| 959 */ | 1015 */ |
| 960 void | 1016 void |
| 961 xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { | 1017 xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { |
| 962 xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf); | 1018 xmlHashScan(table, (xmlHashScanner)xmlDumpEntityDeclScan, buf); |
| 963 } | 1019 } |
| 964 #endif /* LIBXML_OUTPUT_ENABLED */ | 1020 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 965 #define bottom_entities | 1021 #define bottom_entities |
| 966 #include "elfgcchack.h" | 1022 #include "elfgcchack.h" |
| OLD | NEW |