* 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 */
| 2056 | * Returns the new input stream or NULL in case of error |
| 2057 | */ |
| 2058 | xmlParserInputPtr |
| 2059 | xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { |
| 2060 | xmlParserInputBufferPtr buf; |
| 2061 | xmlParserInputPtr inputStream; |
| 2062 | const xmlChar *URI; |
| 2063 | xmlChar *canonic; |
| 2064 | int code; |
| 2065 | |
| 2066 | if ((ctxt == NULL) || (filename == NULL)) |
| 2067 | return(NULL); |
| 2068 | |
| 2069 | code = xmlParserInputBufferCreateFilenameSafe(filename, |
| 2070 | XML_CHAR_ENCODING_NONE, &buf); |
| 2071 | if (buf == NULL) { |
| 2072 | xmlCtxtErrIO(ctxt, code, filename); |
| 2073 | return(NULL); |
| 2074 | } |
| 2075 | |
| 2076 | inputStream = xmlNewInputStream(ctxt); |
| 2077 | if (inputStream == NULL) { |
| 2078 | xmlFreeParserInputBuffer(buf); |
| 2079 | return(NULL); |
| 2080 | } |
| 2081 | |
| 2082 | inputStream->buf = buf; |
| 2083 | inputStream = xmlCheckHTTPInput(ctxt, inputStream); |
| 2084 | if (inputStream == NULL) |
| 2085 | return(NULL); |
| 2086 | |
| 2087 | if (inputStream->filename == NULL) |
| 2088 | URI = (xmlChar *) filename; |
| 2089 | else |
| 2090 | URI = (xmlChar *) inputStream->filename; |
| 2091 | canonic = xmlCanonicPath(URI); |
| 2092 | if (canonic == NULL) { |
| 2093 | xmlCtxtErrMemory(ctxt); |
| 2094 | xmlFreeInputStream(inputStream); |
| 2095 | return(NULL); |
| 2096 | } |
| 2097 | if (inputStream->filename != NULL) |
| 2098 | xmlFree((char *) inputStream->filename); |
| 2099 | inputStream->filename = (char *) canonic; |
| 2100 | |
| 2101 | xmlBufResetInput(inputStream->buf->buffer, inputStream); |
| 2102 | |
| 2103 | return(inputStream); |
| 2104 | } |
| 2105 | |
| 2106 | /** |
| 2107 | * xmlDefaultExternalEntityLoader: |
no test coverage detected