* xmlCheckHTTPInput: * @ctxt: an XML parser context * @ret: an XML parser input * * DEPRECATED: Internal function, don't use. * * Check an input in case it was created from an HTTP stream, in that * case it will handle encoding and update of the base URL in case of * redirection. It also checks for HTTP errors in which case the input * is cleanly freed up and an appropriate error is raise
| 1999 | * Returns the input or NULL in case of HTTP error. |
| 2000 | */ |
| 2001 | xmlParserInputPtr |
| 2002 | xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) { |
| 2003 | /* Avoid unused variable warning if features are disabled. */ |
| 2004 | (void) ctxt; |
| 2005 | |
| 2006 | #ifdef LIBXML_HTTP_ENABLED |
| 2007 | if ((ret != NULL) && (ret->buf != NULL) && |
| 2008 | (ret->buf->readcallback == xmlIOHTTPRead) && |
| 2009 | (ret->buf->context != NULL)) { |
| 2010 | const char *encoding; |
| 2011 | const char *redir; |
| 2012 | const char *mime; |
| 2013 | int code; |
| 2014 | |
| 2015 | code = xmlNanoHTTPReturnCode(ret->buf->context); |
| 2016 | if (code >= 400) { |
| 2017 | /* fatal error */ |
| 2018 | if (ret->filename != NULL) |
| 2019 | xmlCtxtErrIO(ctxt, XML_IO_LOAD_ERROR, ret->filename); |
| 2020 | else |
| 2021 | xmlCtxtErrIO(ctxt, XML_IO_LOAD_ERROR, "<null>"); |
| 2022 | xmlFreeInputStream(ret); |
| 2023 | ret = NULL; |
| 2024 | } else { |
| 2025 | |
| 2026 | mime = xmlNanoHTTPMimeType(ret->buf->context); |
| 2027 | if ((xmlStrstr(BAD_CAST mime, BAD_CAST "/xml")) || |
| 2028 | (xmlStrstr(BAD_CAST mime, BAD_CAST "+xml"))) { |
| 2029 | encoding = xmlNanoHTTPEncoding(ret->buf->context); |
| 2030 | if (encoding != NULL) |
| 2031 | xmlSwitchEncodingName(ctxt, encoding); |
| 2032 | #if 0 |
| 2033 | } else if (xmlStrstr(BAD_CAST mime, BAD_CAST "html")) { |
| 2034 | #endif |
| 2035 | } |
| 2036 | redir = xmlNanoHTTPRedir(ret->buf->context); |
| 2037 | if (redir != NULL) { |
| 2038 | if (ret->filename != NULL) |
| 2039 | xmlFree((xmlChar *) ret->filename); |
| 2040 | ret->filename = |
| 2041 | (char *) xmlStrdup((const xmlChar *) redir); |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | #endif |
| 2046 | return(ret); |
| 2047 | } |
| 2048 | |
| 2049 | /** |
| 2050 | * xmlNewInputFromFile: |
no test coverage detected