* xmlSAX2ExternalSubset: * @ctx: the user data (XML parser context) * @name: the root element name * @ExternalID: the external ID * @SystemID: the SYSTEM ID (e.g. filename or URL) * * Callback on external subset declaration. */
| 271 | * Callback on external subset declaration. |
| 272 | */ |
| 273 | void |
| 274 | xmlSAX2ExternalSubset(void *ctx, const xmlChar *name, |
| 275 | const xmlChar *ExternalID, const xmlChar *SystemID) |
| 276 | { |
| 277 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; |
| 278 | if (ctx == NULL) return; |
| 279 | if ((SystemID != NULL) && |
| 280 | ((ctxt->options & XML_PARSE_NO_XXE) == 0) && |
| 281 | (((ctxt->validate) || (ctxt->loadsubset)) && |
| 282 | (ctxt->wellFormed && ctxt->myDoc))) { |
| 283 | /* |
| 284 | * Try to fetch and parse the external subset. |
| 285 | */ |
| 286 | xmlParserInputPtr oldinput; |
| 287 | int oldinputNr; |
| 288 | int oldinputMax; |
| 289 | xmlParserInputPtr *oldinputTab; |
| 290 | xmlParserInputPtr input = NULL; |
| 291 | const xmlChar *oldencoding; |
| 292 | unsigned long consumed; |
| 293 | size_t buffered; |
| 294 | |
| 295 | /* |
| 296 | * Ask the Entity resolver to load the damn thing |
| 297 | */ |
| 298 | if ((ctxt->sax != NULL) && (ctxt->sax->resolveEntity != NULL)) |
| 299 | input = ctxt->sax->resolveEntity(ctxt->userData, ExternalID, |
| 300 | SystemID); |
| 301 | if (input == NULL) { |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | if (xmlNewDtd(ctxt->myDoc, name, ExternalID, SystemID) == NULL) { |
| 306 | xmlSAX2ErrMemory(ctxt); |
| 307 | xmlFreeInputStream(input); |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | * make sure we won't destroy the main document context |
| 313 | */ |
| 314 | oldinput = ctxt->input; |
| 315 | oldinputNr = ctxt->inputNr; |
| 316 | oldinputMax = ctxt->inputMax; |
| 317 | oldinputTab = ctxt->inputTab; |
| 318 | oldencoding = ctxt->encoding; |
| 319 | ctxt->encoding = NULL; |
| 320 | |
| 321 | ctxt->inputTab = (xmlParserInputPtr *) |
| 322 | xmlMalloc(5 * sizeof(xmlParserInputPtr)); |
| 323 | if (ctxt->inputTab == NULL) { |
| 324 | xmlSAX2ErrMemory(ctxt); |
| 325 | xmlFreeInputStream(input); |
| 326 | ctxt->input = oldinput; |
| 327 | ctxt->inputNr = oldinputNr; |
| 328 | ctxt->inputMax = oldinputMax; |
| 329 | ctxt->inputTab = oldinputTab; |
| 330 | ctxt->encoding = oldencoding; |
no test coverage detected