* xmlNewInputFromFile: * @ctxt: an XML parser context * @filename: the filename to use as entity * * Create a new input stream based on a file or an URL. * * Returns the new input stream or NULL in case of error */
| 1449 | * Returns the new input stream or NULL in case of error |
| 1450 | */ |
| 1451 | xmlParserInputPtr |
| 1452 | xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { |
| 1453 | xmlParserInputBufferPtr buf; |
| 1454 | xmlParserInputPtr inputStream; |
| 1455 | char *directory = NULL; |
| 1456 | xmlChar *URI = NULL; |
| 1457 | |
| 1458 | if (xmlParserDebugEntities) |
| 1459 | xmlGenericError(xmlGenericErrorContext, |
| 1460 | "new input from file: %s\n", filename); |
| 1461 | if (ctxt == NULL) return(NULL); |
| 1462 | buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE); |
| 1463 | if (buf == NULL) { |
| 1464 | if (filename == NULL) |
| 1465 | __xmlLoaderErr(ctxt, |
| 1466 | "failed to load external entity: NULL filename \n", |
| 1467 | NULL); |
| 1468 | else |
| 1469 | __xmlLoaderErr(ctxt, "failed to load external entity \"%s\"\n", |
| 1470 | (const char *) filename); |
| 1471 | return(NULL); |
| 1472 | } |
| 1473 | |
| 1474 | inputStream = xmlNewInputStream(ctxt); |
| 1475 | if (inputStream == NULL) |
| 1476 | return(NULL); |
| 1477 | |
| 1478 | inputStream->buf = buf; |
| 1479 | inputStream = xmlCheckHTTPInput(ctxt, inputStream); |
| 1480 | if (inputStream == NULL) |
| 1481 | return(NULL); |
| 1482 | |
| 1483 | if (inputStream->filename == NULL) |
| 1484 | URI = xmlStrdup((xmlChar *) filename); |
| 1485 | else |
| 1486 | URI = xmlStrdup((xmlChar *) inputStream->filename); |
| 1487 | directory = xmlParserGetDirectory((const char *) URI); |
| 1488 | if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename); |
| 1489 | inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI); |
| 1490 | if (URI != NULL) xmlFree((char *) URI); |
| 1491 | inputStream->directory = directory; |
| 1492 | |
| 1493 | inputStream->base = inputStream->buf->buffer->content; |
| 1494 | inputStream->cur = inputStream->buf->buffer->content; |
| 1495 | inputStream->end = &inputStream->base[inputStream->buf->buffer->use]; |
| 1496 | if ((ctxt->directory == NULL) && (directory != NULL)) |
| 1497 | ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory); |
| 1498 | return(inputStream); |
| 1499 | } |
| 1500 | |
| 1501 | /************************************************************************ |
| 1502 | * * |