* xmlAddEntity: * @doc: the document * @extSubset: add to the external or internal subset * @name: the entity name * @type: the entity type XML_xxx_yyy_ENTITY * @ExternalID: the entity external ID if available * @SystemID: the entity system ID if available * @content: the entity content * @out: pointer to resulting entity (optional) * * Register a new entity for this document. *
| 182 | * Returns an xmlParserErrors error code. |
| 183 | */ |
| 184 | int |
| 185 | xmlAddEntity(xmlDocPtr doc, int extSubset, const xmlChar *name, int type, |
| 186 | const xmlChar *ExternalID, const xmlChar *SystemID, |
| 187 | const xmlChar *content, xmlEntityPtr *out) { |
| 188 | xmlDtdPtr dtd; |
| 189 | xmlDictPtr dict = NULL; |
| 190 | xmlEntitiesTablePtr table = NULL; |
| 191 | xmlEntityPtr ret, predef; |
| 192 | int res; |
| 193 | |
| 194 | if (out != NULL) |
| 195 | *out = NULL; |
| 196 | if ((doc == NULL) || (name == NULL)) |
| 197 | return(XML_ERR_ARGUMENT); |
| 198 | dict = doc->dict; |
| 199 | |
| 200 | if (extSubset) |
| 201 | dtd = doc->extSubset; |
| 202 | else |
| 203 | dtd = doc->intSubset; |
| 204 | if (dtd == NULL) |
| 205 | return(XML_DTD_NO_DTD); |
| 206 | |
| 207 | switch (type) { |
| 208 | case XML_INTERNAL_GENERAL_ENTITY: |
| 209 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| 210 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| 211 | predef = xmlGetPredefinedEntity(name); |
| 212 | if (predef != NULL) { |
| 213 | int valid = 0; |
| 214 | |
| 215 | /* 4.6 Predefined Entities */ |
| 216 | if ((type == XML_INTERNAL_GENERAL_ENTITY) && |
| 217 | (content != NULL)) { |
| 218 | int c = predef->content[0]; |
| 219 | |
| 220 | if (((content[0] == c) && (content[1] == 0)) && |
| 221 | ((c == '>') || (c == '\'') || (c == '"'))) { |
| 222 | valid = 1; |
| 223 | } else if ((content[0] == '&') && (content[1] == '#')) { |
| 224 | if (content[2] == 'x') { |
| 225 | xmlChar *hex = BAD_CAST "0123456789ABCDEF"; |
| 226 | xmlChar ref[] = "00;"; |
| 227 | |
| 228 | ref[0] = hex[c / 16 % 16]; |
| 229 | ref[1] = hex[c % 16]; |
| 230 | if (xmlStrcasecmp(&content[3], ref) == 0) |
| 231 | valid = 1; |
| 232 | } else { |
| 233 | xmlChar ref[] = "00;"; |
| 234 | |
| 235 | ref[0] = '0' + c / 10 % 10; |
| 236 | ref[1] = '0' + c % 10; |
| 237 | if (xmlStrEqual(&content[2], ref)) |
| 238 | valid = 1; |
| 239 | } |
| 240 | } |
| 241 | } |
no test coverage detected