From b85d77d156476bcb910b2a25b21a091957d10de6 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 20 Apr 2025 14:31:24 +0200 Subject: [PATCH] http: Remove built-in HTTP client Stubs are retained for ABI compatibility. Fixes #631. Obsoletes #160. --- CMakeLists.txt | 10 +- NEWS | 4 + README.md | 3 +- config.h.cmake.in | 3 - configure.ac | 34 +- include/Makefile.am | 2 +- include/libxml/nanohttp.h | 4 +- include/libxml/xmlIO.h | 13 +- include/libxml/xmlversion.h.in | 6 +- include/wsockcompat.h | 49 - libxml2-config.cmake.cmake.in | 4 - libxml2-config.cmake.in | 5 - meson.build | 26 - meson_options.txt | 2 +- nanohttp.c | 1770 +++----------------------------- parser.c | 10 +- parserInternals.c | 92 +- testapi.c | 40 +- win32/Makefile.bcb | 3 - win32/Makefile.mingw | 3 - win32/Makefile.msvc | 3 - xmlIO.c | 120 --- 22 files changed, 210 insertions(+), 1996 deletions(-) delete mode 100644 include/wsockcompat.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f95b2868..f3bdd906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(LIBXML2_WITH_CATALOG "Add the Catalog support" ON) option(LIBXML2_WITH_DEBUG "Add the debugging module" ON) option(LIBXML2_WITH_HTML "Add the HTML support" ON) -option(LIBXML2_WITH_HTTP "Add the HTTP support" OFF) +option(LIBXML2_WITH_HTTP "ABI compatibility for removed HTTP support" OFF) option(LIBXML2_WITH_ICONV "Add ICONV support" ON) option(LIBXML2_WITH_ICU "Add ICU support" OFF) option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON) @@ -146,10 +146,6 @@ if(LIBXML2_WITH_READLINE) endif() endif() -if(LIBXML2_WITH_HTTP) - check_include_files(poll.h HAVE_POLL_H) -endif() - if(LIBXML2_WITH_TLS) check_c_source_compiles( "_Thread_local int v; int main(){return 0;}" @@ -347,10 +343,6 @@ endif() if(WIN32) target_link_libraries(LibXml2 PRIVATE bcrypt) set(CRYPTO_LIBS "-lbcrypt") - if(LIBXML2_WITH_HTTP) - target_link_libraries(LibXml2 PRIVATE ws2_32) - set(WINSOCK_LIBS "-lws2_32") - endif() endif() if(LIBXML2_WITH_ICONV) diff --git a/NEWS b/NEWS index a4965896..b45b616d 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ v2.15.0: not released yet The Python bindings are disabled by default now. +### Removals + +The built-in HTTP client was removed. + ### Planned removals The Python bindings are planned to be removed in the 2.16 release. diff --git a/README.md b/README.md index f5fb7c8a..d75f42e5 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ The following options disable or enable code modules and relevant symbols: --with-history history support for xmllint shell (off) --with-readline[=DIR] use readline in DIR for shell (off) --with-html HTML parser (on) - --with-http HTTP support (off) + --with-http ABI compatibility for removed HTTP support (off) --with-iconv[=DIR] iconv support (on) --with-icu ICU support (off) --with-iso8859x ISO-8859-X support if no iconv (on) @@ -133,7 +133,6 @@ See the `meson_options.txt` file for options. For example: -Dprefix=$prefix -Dhistory=enabled - -Dhttp=enabled -Dschematron=disabled -Dzlib=enabled diff --git a/config.h.cmake.in b/config.h.cmake.in index a2f7d9b6..0d69da9d 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -22,9 +22,6 @@ /* Define if readline library is there (-lreadline) */ #cmakedefine HAVE_LIBREADLINE 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_POLL_H 1 - /* Have shl_load based dso */ #cmakedefine HAVE_SHLLOAD 1 diff --git a/configure.ac b/configure.ac index 99ee4298..0006b2f2 100644 --- a/configure.ac +++ b/configure.ac @@ -80,7 +80,7 @@ AC_ARG_WITH(readline, AC_ARG_WITH(html, [ --with-html HTML parser (on)]) AC_ARG_WITH(http, -[ --with-http HTTP support (off)]) +[ --with-http ABI compatibility for removed HTTP support (off)]) AC_ARG_WITH(iconv, [ --with-iconv[[=DIR]] iconv support (on)]) AC_ARG_WITH(icu, @@ -312,36 +312,6 @@ AC_CHECK_DECLS([mmap], [], [], [#include ]) AM_CONDITIONAL(WITH_GLOB, test "$ac_cv_have_decl_glob" = "yes") -dnl -dnl Checks for inet libraries -dnl -if test "$with_http" = "yes"; then - AC_CHECK_HEADERS([poll.h]) - - case "$host" in - *-*-mingw*) - dnl AC_SEARCH_LIBS doesn't work because of non-standard calling - dnl conventions on 32-bit Windows. - NET_LIBS="$NET_LIBS -lws2_32" - ;; - *) - _libs=$LIBS - AC_SEARCH_LIBS(gethostbyname, [nsl], [ - if test "$ac_cv_search_gethostbyname" != "none required"; then - NET_LIBS="$NET_LIBS $ac_cv_search_gethostbyname" - fi], [:], [$NET_LIBS]) - AC_SEARCH_LIBS(connect, [bsd socket inet], [ - if test "$ac_cv_search_connect" != "none required"; then - NET_LIBS="$NET_LIBS $ac_cv_search_connect" - fi], [:], [$NET_LIBS]) - LIBS=$_libs - ;; - esac - - XML_PRIVATE_LIBS="${XML_PRIVATE_LIBS} ${NET_LIBS}" - XML_PC_LIBS="${XML_PC_LIBS} ${NET_LIBS}" -fi - dnl Thread-local storage if test "$with_tls" = "yes"; then AC_COMPILE_IFELSE([ @@ -416,7 +386,7 @@ dnl if test "$with_http" != "yes" ; then WITH_HTTP=0 else - echo Enabling HTTP support + echo Enabling ABI compatibility stubs for removed HTTP support WITH_HTTP=1 fi AC_SUBST(WITH_HTTP) diff --git a/include/Makefile.am b/include/Makefile.am index c2f978db..983add13 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,5 +1,5 @@ ## Process this file with automake to produce Makefile.in SUBDIRS=libxml private -EXTRA_DIST = wsockcompat.h meson.build +EXTRA_DIST = meson.build diff --git a/include/libxml/nanohttp.h b/include/libxml/nanohttp.h index c70d1c26..a01680e1 100644 --- a/include/libxml/nanohttp.h +++ b/include/libxml/nanohttp.h @@ -13,7 +13,7 @@ #include -#ifdef LIBXML_HTTP_ENABLED +#ifdef LIBXML_HTTP_STUBS_ENABLED #ifdef __cplusplus extern "C" { @@ -94,5 +94,5 @@ XMLPUBFUN void } #endif -#endif /* LIBXML_HTTP_ENABLED */ +#endif /* LIBXML_HTTP_STUBS_ENABLED */ #endif /* __NANO_HTTP_H__ */ diff --git a/include/libxml/xmlIO.h b/include/libxml/xmlIO.h index 06472b04..9a5d7476 100644 --- a/include/libxml/xmlIO.h +++ b/include/libxml/xmlIO.h @@ -324,12 +324,11 @@ xmlOutputBufferPtr xmlCharEncodingHandlerPtr encoder, int compression); -#ifdef LIBXML_HTTP_ENABLED -/* This function only exists if HTTP support built into the library */ +#ifdef LIBXML_HTTP_STUBS_ENABLED XML_DEPRECATED XMLPUBFUN void xmlRegisterHTTPPostCallbacks (void ); -#endif /* LIBXML_HTTP_ENABLED */ +#endif /* LIBXML_HTTP_STUBS_ENABLED */ #endif /* LIBXML_OUTPUT_ENABLED */ @@ -338,9 +337,7 @@ XMLPUBFUN xmlParserInputPtr xmlCheckHTTPInput (xmlParserCtxtPtr ctxt, xmlParserInputPtr ret); -/* - * A predefined entity loader disabling network accesses - */ +XML_DEPRECATED XMLPUBFUN xmlParserInputPtr xmlNoNetExternalEntityLoader (const char *URL, const char *ID, @@ -374,7 +371,7 @@ XMLPUBFUN int /** * Default 'http://' protocol callbacks */ -#ifdef LIBXML_HTTP_ENABLED +#ifdef LIBXML_HTTP_STUBS_ENABLED XML_DEPRECATED XMLPUBFUN int xmlIOHTTPMatch (const char *filename); @@ -395,7 +392,7 @@ XMLPUBFUN int XML_DEPRECATED XMLPUBFUN int xmlIOHTTPClose (void * context); -#endif /* LIBXML_HTTP_ENABLED */ +#endif /* LIBXML_HTTP_STUBS_ENABLED */ XMLPUBFUN xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameDefault( diff --git a/include/libxml/xmlversion.h.in b/include/libxml/xmlversion.h.in index c3f0e4db..462b7c0a 100644 --- a/include/libxml/xmlversion.h.in +++ b/include/libxml/xmlversion.h.in @@ -126,12 +126,12 @@ #endif /** - * LIBXML_HTTP_ENABLED: + * LIBXML_HTTP_STUBS_ENABLED: * - * Whether the HTTP support is configured in + * HTTP support was removed in 2.15 */ #if @WITH_HTTP@ -#define LIBXML_HTTP_ENABLED +#define LIBXML_HTTP_STUBS_ENABLED #endif /** diff --git a/include/wsockcompat.h b/include/wsockcompat.h deleted file mode 100644 index a9af26b1..00000000 --- a/include/wsockcompat.h +++ /dev/null @@ -1,49 +0,0 @@ -/* include/wsockcompat.h - * Windows -> Berkeley Sockets compatibility things. - */ - -#if !defined __XML_WSOCKCOMPAT_H__ -#define __XML_WSOCKCOMPAT_H__ - -#include -#include - -/* Fix for old MinGW. */ -#ifndef _WINSOCKAPI_ -#define _WINSOCKAPI_ -#endif - -/* the following is a workaround a problem for 'inline' keyword in said - header when compiled with Borland C++ 6 */ -#if defined(__BORLANDC__) && !defined(__cplusplus) -#define inline __inline -#define _inline __inline -#endif - -#include - -/* Check if ws2tcpip.h is a recent version which provides getaddrinfo() */ -#if defined(GetAddrInfo) -#include -#ifndef SUPPORT_IP6 - #define SUPPORT_IP6 -#endif -#endif - -#ifndef ECONNRESET -#define ECONNRESET WSAECONNRESET -#endif -#ifndef EINPROGRESS -#define EINPROGRESS WSAEINPROGRESS -#endif -#ifndef EINTR -#define EINTR WSAEINTR -#endif -#ifndef ESHUTDOWN -#define ESHUTDOWN WSAESHUTDOWN -#endif -#ifndef EWOULDBLOCK -#define EWOULDBLOCK WSAEWOULDBLOCK -#endif - -#endif /* __XML_WSOCKCOMPAT_H__ */ diff --git a/libxml2-config.cmake.cmake.in b/libxml2-config.cmake.cmake.in index de084bdf..b12f3dc8 100644 --- a/libxml2-config.cmake.cmake.in +++ b/libxml2-config.cmake.cmake.in @@ -97,7 +97,6 @@ set(LIBXML2_WITH_THREADS @LIBXML2_WITH_THREADS@) set(LIBXML2_WITH_ICU @LIBXML2_WITH_ICU@) set(LIBXML2_WITH_LZMA @LIBXML2_WITH_LZMA@) set(LIBXML2_WITH_ZLIB @LIBXML2_WITH_ZLIB@) -set(LIBXML2_WITH_HTTP @LIBXML2_WITH_HTTP@) if(LIBXML2_WITH_ICONV) find_dependency(Iconv) @@ -159,9 +158,6 @@ if(NOT LIBXML2_SHARED) if(WIN32) list(APPEND LIBXML2_LIBRARIES Bcrypt) - if(LIBXML2_WITH_HTTP) - list(APPEND LIBXML2_LIBRARIES ws2_32) - endif() endif() endif() diff --git a/libxml2-config.cmake.in b/libxml2-config.cmake.in index 31036805..57b54adb 100644 --- a/libxml2-config.cmake.in +++ b/libxml2-config.cmake.in @@ -50,7 +50,6 @@ set(LIBXML2_WITH_THREADS @WITH_THREADS@) set(LIBXML2_WITH_ICU @WITH_ICU@) set(LIBXML2_WITH_LZMA @WITH_LZMA@) set(LIBXML2_WITH_ZLIB @WITH_ZLIB@) -set(LIBXML2_WITH_HTTP @WITH_HTTP@) if(LIBXML2_WITH_ICONV) find_dependency(Iconv) @@ -116,10 +115,6 @@ endif() if(WIN32) list(APPEND LIBXML2_LIBRARIES Bcrypt) list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") - if(LIBXML2_WITH_HTTP) - list(APPEND LIBXML2_LIBRARIES ws2_32) - list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") - endif() endif() # whether libxml2 has dso support diff --git a/meson.build b/meson.build index 7236fb28..110cc576 100644 --- a/meson.build +++ b/meson.build @@ -256,7 +256,6 @@ config_h.set_quoted('XML_SYSCONFDIR', # header files xml_check_headers = [ [ 'stdint.h', true ], - [ 'poll.h', want_http ], ] foreach header : xml_check_headers @@ -361,30 +360,6 @@ if sys_windows == true xml_deps += bcrypt_dep endif -### inet -if want_http == true - if sys_windows == true - net_dep = cc.find_library('ws2_32', required: true) - xml_deps += net_dep - else - net_dep = dependency('', required: false) - has_in_libc = cc.has_function('gethostbyname') - if has_in_libc == false - net_dep = cc.find_library('nsl', required: true) - if net_dep.found() - has_in_nsl = cc.has_function( - 'gethostbyname', - dependencies: net_dep, - required: false, - ) - if has_in_nsl == true - xml_deps += net_dep - endif - endif - endif - endif -endif - ### zlib if want_zlib xml_deps += dependency('zlib') @@ -598,7 +573,6 @@ config_cmake.set('LIBXML_MAJOR_VERSION', v_maj) config_cmake.set('LIBXML_MINOR_VERSION', v_min) config_cmake.set('LIBXML_MICRO_VERSION', v_mic) config_cmake.set('VERSION', meson.project_version()) -config_cmake.set('WITH_HTTP', want_http.to_int().to_string()) config_cmake.set('WITH_ICONV', want_iconv.to_int().to_string()) config_cmake.set('WITH_ICU', want_icu.to_int().to_string()) config_cmake.set('WITH_LZMA', want_lzma.to_int().to_string()) diff --git a/meson_options.txt b/meson_options.txt index 0bfbebbb..6530c823 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -61,7 +61,7 @@ option('html', option('http', type: 'feature', - description: 'HTTP support' + description: 'ABI compatibility for removed HTTP support' ) # TODO meson custom dependency diff --git a/nanohttp.c b/nanohttp.c index f405da41..e1168eb5 100644 --- a/nanohttp.c +++ b/nanohttp.c @@ -1,1127 +1,61 @@ /* - * nanohttp.c: minimalist HTTP GET implementation to fetch external subsets. - * focuses on size, streamability, reentrancy and portability - * - * This is clearly not a general purpose HTTP implementation - * If you look for one, check: - * http://www.w3.org/Library/ + * nanohttp.c: ABI compatibility stubs for removed HTTP client * * See Copyright for the status of this software. - * - * daniel@veillard.com */ #define IN_LIBXML #include "libxml.h" -#ifdef LIBXML_HTTP_ENABLED -#include -#include -#include -#include +#ifdef LIBXML_HTTP_STUBS_ENABLED -#include +#include -#ifdef _WIN32 - -#include -#include -#define XML_SOCKLEN_T int - -#else /* _WIN32 */ - -#include -#include -#include -#include -#include - -#ifdef HAVE_POLL_H - #include -#else - #include -#endif - -/* This can be disabled if you don't have getaddrinfo */ -#define SUPPORT_IP6 -#define XML_SOCKLEN_T socklen_t - -#endif /* _WIN32 */ - -#ifdef LIBXML_ZLIB_ENABLED -#include -#endif - -#include -#include -#include /* for xmlStr(n)casecmp() */ #include -#include - -#include "private/error.h" -#include "private/io.h" - -/** - * A couple portability macros - */ -#ifndef _WINSOCKAPI_ -#define closesocket(s) close(s) -#define SOCKET int -#define INVALID_SOCKET (-1) -#endif - -#define GETHOSTBYNAME_ARG_CAST (char *) -#define SEND_ARG2_CAST (char *) - -#define XML_NANO_HTTP_MAX_REDIR 10 - -#define XML_NANO_HTTP_CHUNK 4096 - -#define XML_NANO_HTTP_CLOSED 0 -#define XML_NANO_HTTP_WRITE 1 -#define XML_NANO_HTTP_READ 2 -#define XML_NANO_HTTP_NONE 4 - -#define __xmlIOErr(domain, code, extra) ((void) 0) - -typedef struct xmlNanoHTTPCtxt { - char *protocol; /* the protocol name */ - char *hostname; /* the host name */ - int port; /* the port */ - char *path; /* the path within the URL */ - char *query; /* the query string */ - SOCKET fd; /* the file descriptor for the socket */ - int state; /* WRITE / READ / CLOSED */ - char *out; /* buffer sent (zero terminated) */ - char *outptr; /* index within the buffer sent */ - char *in; /* the receiving buffer */ - char *content; /* the start of the content */ - char *inptr; /* the next byte to read from network */ - char *inrptr; /* the next byte to give back to the client */ - int inlen; /* len of the input buffer */ - int last; /* return code for last operation */ - int returnValue; /* the protocol return value */ - int version; /* the protocol version */ - int ContentLength; /* specified content length from HTTP header */ - char *contentType; /* the MIME type for the input */ - char *location; /* the new URL in case of redirect */ - char *authHeader; /* contents of {WWW,Proxy}-Authenticate header */ - char *encoding; /* encoding extracted from the contentType */ - char *mimeType; /* Mime-Type extracted from the contentType */ -#ifdef LIBXML_ZLIB_ENABLED - z_stream *strm; /* Zlib stream object */ - int usesGzip; /* "Content-Encoding: gzip" was detected */ -#endif -} xmlNanoHTTPCtxt, *xmlNanoHTTPCtxtPtr; - -static int initialized = 0; -static char *proxy = NULL; /* the proxy name if any */ -static int proxyPort; /* the proxy port if any */ -static unsigned int timeout = 60;/* the select() timeout in seconds */ - -static int xmlNanoHTTPFetchContent( void * ctx, char ** ptr, int * len ); - -/** - * xmlHTTPErrMemory: - * @extra: extra information - * - * Handle an out of memory condition - */ -static void -xmlHTTPErrMemory(void) -{ - xmlRaiseMemoryError(NULL, NULL, NULL, XML_FROM_HTTP, NULL); -} - -/** - * A portability function - */ -static int socket_errno(void) { -#ifdef _WINSOCKAPI_ - int err = WSAGetLastError(); - switch(err) { - case WSAECONNRESET: - return(ECONNRESET); - case WSAEINPROGRESS: - return(EINPROGRESS); - case WSAEINTR: - return(EINTR); - case WSAESHUTDOWN: - return(ESHUTDOWN); - case WSAEWOULDBLOCK: - return(EWOULDBLOCK); - default: - return(err); - } -#else - return(errno); -#endif -} +#include /** * xmlNanoHTTPInit: * - * Initialize the HTTP protocol layer. - * Currently it just checks for proxy information + * DEPRECATED: HTTP support was removed in 2.15. */ - void xmlNanoHTTPInit(void) { - const char *env; -#ifdef _WINSOCKAPI_ - WSADATA wsaData; -#endif - - if (initialized) - return; - -#ifdef _WINSOCKAPI_ - if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) - return; -#endif - - if (proxy == NULL) { - proxyPort = 80; - env = getenv("no_proxy"); - if (env && ((env[0] == '*') && (env[1] == 0))) - goto done; - env = getenv("http_proxy"); - if (env != NULL) { - xmlNanoHTTPScanProxy(env); - goto done; - } - env = getenv("HTTP_PROXY"); - if (env != NULL) { - xmlNanoHTTPScanProxy(env); - goto done; - } - } -done: - initialized = 1; } /** * xmlNanoHTTPCleanup: * - * Cleanup the HTTP protocol layer. + * DEPRECATED: HTTP support was removed in 2.15. */ - void xmlNanoHTTPCleanup(void) { - if (proxy != NULL) { - xmlFree(proxy); - proxy = NULL; - } -#ifdef _WINSOCKAPI_ - if (initialized) - WSACleanup(); -#endif - initialized = 0; - return; -} - -/** - * xmlNanoHTTPScanURL: - * @ctxt: an HTTP context - * @URL: The URL used to initialize the context - * - * (Re)Initialize an HTTP context by parsing the URL and finding - * the protocol host port and path it indicates. - */ - -static void -xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) { - xmlURIPtr uri; - int len; - - /* - * Clear any existing data from the context - */ - if (ctxt->protocol != NULL) { - xmlFree(ctxt->protocol); - ctxt->protocol = NULL; - } - if (ctxt->hostname != NULL) { - xmlFree(ctxt->hostname); - ctxt->hostname = NULL; - } - if (ctxt->path != NULL) { - xmlFree(ctxt->path); - ctxt->path = NULL; - } - if (ctxt->query != NULL) { - xmlFree(ctxt->query); - ctxt->query = NULL; - } - if (URL == NULL) return; - - uri = xmlParseURIRaw(URL, 1); - if (uri == NULL) - return; - - if ((uri->scheme == NULL) || (uri->server == NULL)) { - xmlFreeURI(uri); - return; - } - - ctxt->protocol = xmlMemStrdup(uri->scheme); - /* special case of IPv6 addresses, the [] need to be removed */ - if ((uri->server != NULL) && (*uri->server == '[')) { - len = strlen(uri->server); - if ((len > 2) && (uri->server[len - 1] == ']')) { - ctxt->hostname = (char *) xmlCharStrndup(uri->server + 1, len -2); - } else - ctxt->hostname = xmlMemStrdup(uri->server); - } else - ctxt->hostname = xmlMemStrdup(uri->server); - if (uri->path != NULL) - ctxt->path = xmlMemStrdup(uri->path); - else - ctxt->path = xmlMemStrdup("/"); - if (uri->query != NULL) - ctxt->query = xmlMemStrdup(uri->query); - if (uri->port != 0) - ctxt->port = uri->port; - - xmlFreeURI(uri); } /** * xmlNanoHTTPScanProxy: * @URL: The proxy URL used to initialize the proxy context * - * (Re)Initialize the HTTP Proxy context by parsing the URL and finding - * the protocol host port it indicates. - * Should be like http://myproxy/ or http://myproxy:3128/ - * A NULL URL cleans up proxy information. + * DEPRECATED: HTTP support was removed in 2.15. */ - void -xmlNanoHTTPScanProxy(const char *URL) { - xmlURIPtr uri; - - if (proxy != NULL) { - xmlFree(proxy); - proxy = NULL; - } - proxyPort = 0; - - if (URL == NULL) return; - - uri = xmlParseURIRaw(URL, 1); - if ((uri == NULL) || (uri->scheme == NULL) || - (strcmp(uri->scheme, "http")) || (uri->server == NULL)) { - __xmlIOErr(XML_FROM_HTTP, XML_HTTP_URL_SYNTAX, "Syntax Error\n"); - if (uri != NULL) - xmlFreeURI(uri); - return; - } - - proxy = xmlMemStrdup(uri->server); - if (uri->port != 0) - proxyPort = uri->port; - - xmlFreeURI(uri); +xmlNanoHTTPScanProxy(const char *URL ATTRIBUTE_UNUSED) { } -/** - * xmlNanoHTTPNewCtxt: - * @URL: The URL used to initialize the context - * - * Allocate and initialize a new HTTP context. - * - * Returns an HTTP context or NULL in case of error. - */ - -static xmlNanoHTTPCtxtPtr -xmlNanoHTTPNewCtxt(const char *URL) { - xmlNanoHTTPCtxtPtr ret; - - ret = (xmlNanoHTTPCtxtPtr) xmlMalloc(sizeof(xmlNanoHTTPCtxt)); - if (ret == NULL) { - xmlHTTPErrMemory(); - return(NULL); - } - - memset(ret, 0, sizeof(xmlNanoHTTPCtxt)); - ret->port = 80; - ret->returnValue = 0; - ret->fd = INVALID_SOCKET; - ret->ContentLength = -1; - - xmlNanoHTTPScanURL(ret, URL); - - return(ret); -} - -/** - * xmlNanoHTTPFreeCtxt: - * @ctxt: an HTTP context - * - * Frees the context after closing the connection. - */ - -static void -xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) { - if (ctxt == NULL) return; - if (ctxt->hostname != NULL) xmlFree(ctxt->hostname); - if (ctxt->protocol != NULL) xmlFree(ctxt->protocol); - if (ctxt->path != NULL) xmlFree(ctxt->path); - if (ctxt->query != NULL) xmlFree(ctxt->query); - if (ctxt->out != NULL) xmlFree(ctxt->out); - if (ctxt->in != NULL) xmlFree(ctxt->in); - if (ctxt->contentType != NULL) xmlFree(ctxt->contentType); - if (ctxt->encoding != NULL) xmlFree(ctxt->encoding); - if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType); - if (ctxt->location != NULL) xmlFree(ctxt->location); - if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader); -#ifdef LIBXML_ZLIB_ENABLED - if (ctxt->strm != NULL) { - inflateEnd(ctxt->strm); - xmlFree(ctxt->strm); - } -#endif - - ctxt->state = XML_NANO_HTTP_NONE; - if (ctxt->fd != INVALID_SOCKET) closesocket(ctxt->fd); - ctxt->fd = INVALID_SOCKET; - xmlFree(ctxt); -} - -/** - * xmlNanoHTTPSend: - * @ctxt: an HTTP context - * - * Send the input needed to initiate the processing on the server side - * Returns number of bytes sent or -1 on error. - */ - -static int -xmlNanoHTTPSend(xmlNanoHTTPCtxtPtr ctxt, const char *xmt_ptr, int outlen) -{ - int total_sent = 0; -#ifdef HAVE_POLL_H - struct pollfd p; -#else - struct timeval tv; - fd_set wfd; -#endif - - if ((ctxt->state & XML_NANO_HTTP_WRITE) && (xmt_ptr != NULL)) { - while (total_sent < outlen) { - int nsent = send(ctxt->fd, SEND_ARG2_CAST (xmt_ptr + total_sent), - outlen - total_sent, 0); - - if (nsent > 0) - total_sent += nsent; - else if ((nsent == -1) && -#if defined(EAGAIN) && EAGAIN != EWOULDBLOCK - (socket_errno() != EAGAIN) && -#endif - (socket_errno() != EWOULDBLOCK)) { - __xmlIOErr(XML_FROM_HTTP, 0, "send failed\n"); - if (total_sent == 0) - total_sent = -1; - break; - } else { - /* - * No data sent - * Since non-blocking sockets are used, wait for - * socket to be writable or default timeout prior - * to retrying. - */ -#ifndef HAVE_POLL_H -#ifndef _WINSOCKAPI_ - if (ctxt->fd > FD_SETSIZE) - return -1; -#endif - - tv.tv_sec = timeout; - tv.tv_usec = 0; - FD_ZERO(&wfd); -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4018) -#endif - FD_SET(ctxt->fd, &wfd); -#ifdef _MSC_VER -#pragma warning(pop) -#endif - (void) select(ctxt->fd + 1, NULL, &wfd, NULL, &tv); -#else - p.fd = ctxt->fd; - p.events = POLLOUT; - (void) poll(&p, 1, timeout * 1000); -#endif /* !HAVE_POLL_H */ - } - } - } - - return total_sent; -} - -/** - * xmlNanoHTTPRecv: - * @ctxt: an HTTP context - * - * Read information coming from the HTTP connection. - * This is a blocking call (but it blocks in select(), not read()). - * - * Returns the number of byte read or -1 in case of error. - */ - -static int -xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt) -{ -#ifdef HAVE_POLL_H - struct pollfd p; -#else - fd_set rfd; - struct timeval tv; -#endif - - - while (ctxt->state & XML_NANO_HTTP_READ) { - if (ctxt->in == NULL) { - ctxt->in = xmlMalloc(65000); - if (ctxt->in == NULL) { - xmlHTTPErrMemory(); - ctxt->last = -1; - return (-1); - } - ctxt->inlen = 65000; - ctxt->inptr = ctxt->content = ctxt->inrptr = ctxt->in; - } - if (ctxt->inrptr > ctxt->in + XML_NANO_HTTP_CHUNK) { - int delta = ctxt->inrptr - ctxt->in; - int len = ctxt->inptr - ctxt->inrptr; - - memmove(ctxt->in, ctxt->inrptr, len); - ctxt->inrptr -= delta; - ctxt->content -= delta; - ctxt->inptr -= delta; - } - if ((ctxt->in + ctxt->inlen) < (ctxt->inptr + XML_NANO_HTTP_CHUNK)) { - int d_inptr = ctxt->inptr - ctxt->in; - int d_content = ctxt->content - ctxt->in; - int d_inrptr = ctxt->inrptr - ctxt->in; - char *tmp_ptr = ctxt->in; - - ctxt->inlen *= 2; - ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen); - if (ctxt->in == NULL) { - xmlHTTPErrMemory(); - xmlFree(tmp_ptr); - ctxt->last = -1; - return (-1); - } - ctxt->inptr = ctxt->in + d_inptr; - ctxt->content = ctxt->in + d_content; - ctxt->inrptr = ctxt->in + d_inrptr; - } - ctxt->last = recv(ctxt->fd, ctxt->inptr, XML_NANO_HTTP_CHUNK, 0); - if (ctxt->last > 0) { - ctxt->inptr += ctxt->last; - return (ctxt->last); - } - if (ctxt->last == 0) { - return (0); - } - if (ctxt->last == -1) { - switch (socket_errno()) { - case EINPROGRESS: - case EWOULDBLOCK: -#if defined(EAGAIN) && EAGAIN != EWOULDBLOCK - case EAGAIN: -#endif - break; - - case ECONNRESET: - case ESHUTDOWN: - return (0); - - default: - __xmlIOErr(XML_FROM_HTTP, 0, "recv failed\n"); - return (-1); - } - } -#ifdef HAVE_POLL_H - p.fd = ctxt->fd; - p.events = POLLIN; - if ((poll(&p, 1, timeout * 1000) < 1) -#if defined(EINTR) - && (errno != EINTR) -#endif - ) - return (0); -#else /* !HAVE_POLL_H */ -#ifndef _WINSOCKAPI_ - if (ctxt->fd > FD_SETSIZE) - return 0; -#endif - - tv.tv_sec = timeout; - tv.tv_usec = 0; - FD_ZERO(&rfd); - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4018) -#endif - - FD_SET(ctxt->fd, &rfd); - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - - if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1) -#if defined(EINTR) - && (socket_errno() != EINTR) -#endif - ) - return (0); -#endif /* !HAVE_POLL_H */ - } - return (0); -} - -/** - * xmlNanoHTTPReadLine: - * @ctxt: an HTTP context - * - * Read one line in the HTTP server output, usually for extracting - * the HTTP protocol information from the answer header. - * - * Returns a newly allocated string with a copy of the line, or NULL - * which indicate the end of the input. - */ - -static char * -xmlNanoHTTPReadLine(xmlNanoHTTPCtxtPtr ctxt) { - char buf[4096]; - char *bp = buf; - int rc; - - while (bp - buf < 4095) { - if (ctxt->inrptr == ctxt->inptr) { - if ( (rc = xmlNanoHTTPRecv(ctxt)) == 0) { - if (bp == buf) - return(NULL); - else - *bp = 0; - return(xmlMemStrdup(buf)); - } - else if ( rc == -1 ) { - return ( NULL ); - } - } - *bp = *ctxt->inrptr++; - if (*bp == '\n') { - *bp = 0; - return(xmlMemStrdup(buf)); - } - if (*bp != '\r') - bp++; - } - buf[4095] = 0; - return(xmlMemStrdup(buf)); -} - - -/** - * xmlNanoHTTPScanAnswer: - * @ctxt: an HTTP context - * @line: an HTTP header line - * - * Try to extract useful information from the server answer. - * We currently parse and process: - * - The HTTP revision/ return code - * - The Content-Type, Mime-Type and charset used - * - The Location for redirect processing. - * - * Returns -1 in case of failure, the file descriptor number otherwise - */ - -static void -xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) { - const char *cur = line; - - if (line == NULL) return; - - if (!strncmp(line, "HTTP/", 5)) { - int version = 0; - int ret = 0; - - cur += 5; - while ((*cur >= '0') && (*cur <= '9')) { - version *= 10; - version += *cur - '0'; - cur++; - } - if (*cur == '.') { - cur++; - if ((*cur >= '0') && (*cur <= '9')) { - version *= 10; - version += *cur - '0'; - cur++; - } - while ((*cur >= '0') && (*cur <= '9')) - cur++; - } else - version *= 10; - if ((*cur != ' ') && (*cur != '\t')) return; - while ((*cur == ' ') || (*cur == '\t')) cur++; - if ((*cur < '0') || (*cur > '9')) return; - while ((*cur >= '0') && (*cur <= '9')) { - ret *= 10; - ret += *cur - '0'; - cur++; - } - if ((*cur != 0) && (*cur != ' ') && (*cur != '\t')) return; - ctxt->returnValue = ret; - ctxt->version = version; - } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Content-Type:", 13)) { - const xmlChar *charset, *last, *mime; - cur += 13; - while ((*cur == ' ') || (*cur == '\t')) cur++; - if (ctxt->contentType != NULL) - xmlFree(ctxt->contentType); - ctxt->contentType = xmlMemStrdup(cur); - mime = (const xmlChar *) cur; - last = mime; - while ((*last != 0) && (*last != ' ') && (*last != '\t') && - (*last != ';') && (*last != ',')) - last++; - if (ctxt->mimeType != NULL) - xmlFree(ctxt->mimeType); - ctxt->mimeType = (char *) xmlStrndup(mime, last - mime); - charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset="); - if (charset != NULL) { - charset += 8; - last = charset; - while ((*last != 0) && (*last != ' ') && (*last != '\t') && - (*last != ';') && (*last != ',')) - last++; - if (ctxt->encoding != NULL) - xmlFree(ctxt->encoding); - ctxt->encoding = (char *) xmlStrndup(charset, last - charset); - } - } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"ContentType:", 12)) { - const xmlChar *charset, *last, *mime; - cur += 12; - if (ctxt->contentType != NULL) return; - while ((*cur == ' ') || (*cur == '\t')) cur++; - ctxt->contentType = xmlMemStrdup(cur); - mime = (const xmlChar *) cur; - last = mime; - while ((*last != 0) && (*last != ' ') && (*last != '\t') && - (*last != ';') && (*last != ',')) - last++; - if (ctxt->mimeType != NULL) - xmlFree(ctxt->mimeType); - ctxt->mimeType = (char *) xmlStrndup(mime, last - mime); - charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset="); - if (charset != NULL) { - charset += 8; - last = charset; - while ((*last != 0) && (*last != ' ') && (*last != '\t') && - (*last != ';') && (*last != ',')) - last++; - if (ctxt->encoding != NULL) - xmlFree(ctxt->encoding); - ctxt->encoding = (char *) xmlStrndup(charset, last - charset); - } - } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Location:", 9)) { - cur += 9; - while ((*cur == ' ') || (*cur == '\t')) cur++; - if (ctxt->location != NULL) - xmlFree(ctxt->location); - if (*cur == '/') { - xmlChar *tmp_http = xmlStrdup(BAD_CAST "http://"); - xmlChar *tmp_loc = - xmlStrcat(tmp_http, (const xmlChar *) ctxt->hostname); - ctxt->location = - (char *) xmlStrcat (tmp_loc, (const xmlChar *) cur); - } else { - ctxt->location = xmlMemStrdup(cur); - } - } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"WWW-Authenticate:", 17)) { - cur += 17; - while ((*cur == ' ') || (*cur == '\t')) cur++; - if (ctxt->authHeader != NULL) - xmlFree(ctxt->authHeader); - ctxt->authHeader = xmlMemStrdup(cur); - } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Proxy-Authenticate:", 19)) { - cur += 19; - while ((*cur == ' ') || (*cur == '\t')) cur++; - if (ctxt->authHeader != NULL) - xmlFree(ctxt->authHeader); - ctxt->authHeader = xmlMemStrdup(cur); -#ifdef LIBXML_ZLIB_ENABLED - } else if ( !xmlStrncasecmp( BAD_CAST line, BAD_CAST"Content-Encoding:", 17) ) { - cur += 17; - while ((*cur == ' ') || (*cur == '\t')) cur++; - if ( !xmlStrncasecmp( BAD_CAST cur, BAD_CAST"gzip", 4) ) { - ctxt->usesGzip = 1; - - ctxt->strm = xmlMalloc(sizeof(z_stream)); - - if (ctxt->strm != NULL) { - ctxt->strm->zalloc = Z_NULL; - ctxt->strm->zfree = Z_NULL; - ctxt->strm->opaque = Z_NULL; - ctxt->strm->avail_in = 0; - ctxt->strm->next_in = Z_NULL; - - inflateInit2( ctxt->strm, 31 ); - } - } -#endif - } else if ( !xmlStrncasecmp( BAD_CAST line, BAD_CAST"Content-Length:", 15) ) { - cur += 15; - ctxt->ContentLength = strtol( cur, NULL, 10 ); - } -} - -/** - * xmlNanoHTTPConnectAttempt: - * @addr: a socket address structure - * - * Attempt a connection to the given IP:port endpoint. It forces - * non-blocking semantic on the socket, and allow 60 seconds for - * the host to answer. - * - * Returns -1 in case of failure, the file descriptor number otherwise - */ - -static SOCKET -xmlNanoHTTPConnectAttempt(struct sockaddr *addr) -{ -#ifndef HAVE_POLL_H - fd_set wfd; -#ifdef _WINSOCKAPI_ - fd_set xfd; -#endif - struct timeval tv; -#else /* !HAVE_POLL_H */ - struct pollfd p; -#endif /* !HAVE_POLL_H */ - int status; - - int addrlen; - - SOCKET s; - -#ifdef SUPPORT_IP6 - if (addr->sa_family == AF_INET6) { - s = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); - addrlen = sizeof(struct sockaddr_in6); - } else -#endif - { - s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - addrlen = sizeof(struct sockaddr_in); - } - if (s == INVALID_SOCKET) { - __xmlIOErr(XML_FROM_HTTP, 0, "socket failed\n"); - return INVALID_SOCKET; - } -#ifdef _WINSOCKAPI_ - { - u_long one = 1; - - status = ioctlsocket(s, FIONBIO, &one) == SOCKET_ERROR ? -1 : 0; - } -#else /* _WINSOCKAPI_ */ -#if defined(VMS) - { - int enable = 1; - - status = ioctl(s, FIONBIO, &enable); - } -#else /* VMS */ - if ((status = fcntl(s, F_GETFL, 0)) != -1) { -#ifdef O_NONBLOCK - status |= O_NONBLOCK; -#else /* O_NONBLOCK */ -#ifdef F_NDELAY - status |= F_NDELAY; -#endif /* F_NDELAY */ -#endif /* !O_NONBLOCK */ - status = fcntl(s, F_SETFL, status); - } - if (status < 0) { - __xmlIOErr(XML_FROM_HTTP, 0, "error setting non-blocking IO\n"); - closesocket(s); - return INVALID_SOCKET; - } -#endif /* !VMS */ -#endif /* !_WINSOCKAPI_ */ - - if (connect(s, addr, addrlen) == -1) { - switch (socket_errno()) { - case EINPROGRESS: - case EWOULDBLOCK: - break; - default: - __xmlIOErr(XML_FROM_HTTP, 0, - "error connecting to HTTP server"); - closesocket(s); - return INVALID_SOCKET; - } - } -#ifndef HAVE_POLL_H - tv.tv_sec = timeout; - tv.tv_usec = 0; - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4018) -#endif -#ifndef _WINSOCKAPI_ - if (s > FD_SETSIZE) - return INVALID_SOCKET; -#endif - FD_ZERO(&wfd); - FD_SET(s, &wfd); - -#ifdef _WINSOCKAPI_ - FD_ZERO(&xfd); - FD_SET(s, &xfd); - - switch (select(s + 1, NULL, &wfd, &xfd, &tv)) -#else - switch (select(s + 1, NULL, &wfd, NULL, &tv)) -#endif -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#else /* !HAVE_POLL_H */ - p.fd = s; - p.events = POLLOUT; - switch (poll(&p, 1, timeout * 1000)) -#endif /* !HAVE_POLL_H */ - - { - case 0: - /* Time out */ - __xmlIOErr(XML_FROM_HTTP, 0, "Connect attempt timed out"); - closesocket(s); - return INVALID_SOCKET; - case -1: - /* Ermm.. ?? */ - __xmlIOErr(XML_FROM_HTTP, 0, "Connect failed"); - closesocket(s); - return INVALID_SOCKET; - } - -#ifndef HAVE_POLL_H - if (FD_ISSET(s, &wfd) -#ifdef _WINSOCKAPI_ - || FD_ISSET(s, &xfd) -#endif - ) -#else /* !HAVE_POLL_H */ - if (p.revents == POLLOUT) -#endif /* !HAVE_POLL_H */ - { - XML_SOCKLEN_T len; - - len = sizeof(status); -#ifdef SO_ERROR - if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char *) &status, &len) < - 0) { - /* Solaris error code */ - __xmlIOErr(XML_FROM_HTTP, 0, "getsockopt failed\n"); - closesocket(s); - return INVALID_SOCKET; - } -#endif - if (status) { - __xmlIOErr(XML_FROM_HTTP, 0, - "Error connecting to remote host"); - closesocket(s); - errno = status; - return INVALID_SOCKET; - } - } else { - /* pbm */ - __xmlIOErr(XML_FROM_HTTP, 0, "select failed\n"); - closesocket(s); - return INVALID_SOCKET; - } - - return (s); -} - -/** - * xmlNanoHTTPConnectHost: - * @host: the host name - * @port: the port number - * - * Attempt a connection to the given host:port endpoint. It tries - * the multiple IP provided by the DNS if available. - * - * Returns -1 in case of failure, the file descriptor number otherwise - */ - -static SOCKET -xmlNanoHTTPConnectHost(const char *host, int port) -{ - struct sockaddr *addr = NULL; - struct sockaddr_in sockin; - -#ifdef SUPPORT_IP6 - struct sockaddr_in6 sockin6; -#endif - SOCKET s; - - memset (&sockin, 0, sizeof(sockin)); - -#if defined(SUPPORT_IP6) - { - int status; - struct addrinfo hints, *res, *result; - - memset (&sockin6, 0, sizeof(sockin6)); - - result = NULL; - memset (&hints, 0,sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - - status = getaddrinfo (host, NULL, &hints, &result); - if (status) { - __xmlIOErr(XML_FROM_HTTP, 0, "getaddrinfo failed\n"); - return INVALID_SOCKET; - } - - for (res = result; res; res = res->ai_next) { - if (res->ai_family == AF_INET) { - if ((size_t)res->ai_addrlen > sizeof(sockin)) { - __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); - freeaddrinfo (result); - return INVALID_SOCKET; - } - memcpy (&sockin, res->ai_addr, res->ai_addrlen); - sockin.sin_port = htons (port); - addr = (struct sockaddr *)&sockin; - } else if (res->ai_family == AF_INET6) { - if ((size_t)res->ai_addrlen > sizeof(sockin6)) { - __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); - freeaddrinfo (result); - return INVALID_SOCKET; - } - memcpy (&sockin6, res->ai_addr, res->ai_addrlen); - sockin6.sin6_port = htons (port); - addr = (struct sockaddr *)&sockin6; - } else - continue; /* for */ - - s = xmlNanoHTTPConnectAttempt (addr); - if (s != INVALID_SOCKET) { - freeaddrinfo (result); - return (s); - } - } - - if (result) - freeaddrinfo (result); - } -#else - { - struct hostent *h; - struct in_addr ia; - int i; - - h = gethostbyname (GETHOSTBYNAME_ARG_CAST host); - if (h == NULL) { - -/* - * Okay, I got fed up by the non-portability of this error message - * extraction code. it work on Linux, if it work on your platform - * and one want to enable it, send me the defined(foobar) needed - */ -#if defined(HOST_NOT_FOUND) && defined(__linux__) - const char *h_err_txt = ""; - - switch (h_errno) { - case HOST_NOT_FOUND: - h_err_txt = "Authoritative host not found"; - break; - - case TRY_AGAIN: - h_err_txt = - "Non-authoritative host not found or server failure."; - break; - - case NO_RECOVERY: - h_err_txt = - "Non-recoverable errors: FORMERR, REFUSED, or NOTIMP."; - break; - -#ifdef NO_ADDRESS - case NO_ADDRESS: - h_err_txt = - "Valid name, no data record of requested type."; - break; -#endif - - default: - h_err_txt = "No error text defined."; - break; - } - __xmlIOErr(XML_FROM_HTTP, 0, h_err_txt); -#else - __xmlIOErr(XML_FROM_HTTP, 0, "Failed to resolve host"); -#endif - return INVALID_SOCKET; - } - - for (i = 0; h->h_addr_list[i]; i++) { - if (h->h_addrtype == AF_INET) { - /* A records (IPv4) */ - if ((unsigned int) h->h_length > sizeof(ia)) { - __xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n"); - return INVALID_SOCKET; - } - memcpy (&ia, h->h_addr_list[i], h->h_length); - sockin.sin_family = h->h_addrtype; - sockin.sin_addr = ia; - sockin.sin_port = (unsigned short)htons ((unsigned short)port); - addr = (struct sockaddr *) &sockin; - } else - break; /* for */ - - s = xmlNanoHTTPConnectAttempt (addr); - if (s != INVALID_SOCKET) - return (s); - } - } -#endif - - return INVALID_SOCKET; -} - - /** * xmlNanoHTTPOpen: * @URL: The URL to load * @contentType: if available the Content-Type information will be * returned at that location * - * This function try to open a connection to the indicated resource - * via HTTP GET. + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns NULL in case of failure, otherwise a request handler. - * The contentType, if provided must be freed by the caller + * Returns NULL. */ - void* -xmlNanoHTTPOpen(const char *URL, char **contentType) { +xmlNanoHTTPOpen(const char *URL ATTRIBUTE_UNUSED, char **contentType) { if (contentType != NULL) *contentType = NULL; - return(xmlNanoHTTPMethod(URL, NULL, NULL, contentType, NULL, 0)); + return(NULL); } /** @@ -1131,18 +65,16 @@ xmlNanoHTTPOpen(const char *URL, char **contentType) { * returned at that location * @redir: if available the redirected URL will be returned * - * This function try to open a connection to the indicated resource - * via HTTP GET. + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns NULL in case of failure, otherwise a request handler. - * The contentType, if provided must be freed by the caller + * Returns NULL. */ - void* -xmlNanoHTTPOpenRedir(const char *URL, char **contentType, char **redir) { +xmlNanoHTTPOpenRedir(const char *URL ATTRIBUTE_UNUSED, char **contentType, + char **redir) { if (contentType != NULL) *contentType = NULL; if (redir != NULL) *redir = NULL; - return(xmlNanoHTTPMethodRedir(URL, NULL, NULL, contentType, redir, NULL,0)); + return(NULL); } /** @@ -1151,180 +83,26 @@ xmlNanoHTTPOpenRedir(const char *URL, char **contentType, char **redir) { * @dest: a buffer * @len: the buffer length * - * This function tries to read @len bytes from the existing HTTP connection - * and saves them in @dest. This is a blocking call. + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns the number of byte read. 0 is an indication of an end of connection. - * -1 indicates a parameter error. + * Returns -1. */ int -xmlNanoHTTPRead(void *ctx, void *dest, int len) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx; -#ifdef LIBXML_ZLIB_ENABLED - int bytes_read = 0; - int orig_avail_in; - int z_ret; -#endif - - if (ctx == NULL) return(-1); - if (dest == NULL) return(-1); - if (len <= 0) return(0); - -#ifdef LIBXML_ZLIB_ENABLED - if (ctxt->usesGzip == 1) { - if (ctxt->strm == NULL) return(0); - - ctxt->strm->next_out = dest; - ctxt->strm->avail_out = len; - ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr; - - while (ctxt->strm->avail_out > 0 && - (ctxt->strm->avail_in > 0 || xmlNanoHTTPRecv(ctxt) > 0)) { - orig_avail_in = ctxt->strm->avail_in = - ctxt->inptr - ctxt->inrptr - bytes_read; - ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read); - - z_ret = inflate(ctxt->strm, Z_NO_FLUSH); - bytes_read += orig_avail_in - ctxt->strm->avail_in; - - if (z_ret != Z_OK) break; - } - - ctxt->inrptr += bytes_read; - return(len - ctxt->strm->avail_out); - } -#endif - - while (ctxt->inptr - ctxt->inrptr < len) { - if (xmlNanoHTTPRecv(ctxt) <= 0) break; - } - if (ctxt->inptr - ctxt->inrptr < len) - len = ctxt->inptr - ctxt->inrptr; - if (len > 0) { - memcpy(dest, ctxt->inrptr, len); - ctxt->inrptr += len; - } - return(len); +xmlNanoHTTPRead(void *ctx ATTRIBUTE_UNUSED, void *dest ATTRIBUTE_UNUSED, + int len ATTRIBUTE_UNUSED) { + return(-1); } /** * xmlNanoHTTPClose: * @ctx: the HTTP context * - * This function closes an HTTP context, it ends up the connection and - * free all data related to it. + * DEPRECATED: HTTP support was removed in 2.15. */ void -xmlNanoHTTPClose(void *ctx) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx; - - if (ctx == NULL) return; - - xmlNanoHTTPFreeCtxt(ctxt); +xmlNanoHTTPClose(void *ctx ATTRIBUTE_UNUSED) { } - -/** - * xmlNanoHTTPHostnameMatch: - * @pattern: The pattern as it appears in no_proxy environment variable - * @hostname: The hostname to test as it appears in the URL - * - * This function tests whether a given hostname matches a pattern. The pattern - * usually is a token from the no_proxy environment variable. Wildcards in the - * pattern are not supported. - * - * Returns true, iff hostname matches the pattern. - */ - -static int -xmlNanoHTTPHostnameMatch(const char *pattern, const char *hostname) { - int idx_pattern, idx_hostname; - const char * pattern_start; - - if (!pattern || *pattern == '\0' || !hostname) - return 0; - - /* Ignore trailing '.' */ - if (*pattern == '.') { - idx_pattern = strlen(pattern) -1; - pattern_start = pattern + 1; - } - else { - idx_pattern = strlen(pattern); - pattern_start = pattern; - } - idx_hostname = strlen(hostname); - - for (; idx_pattern >= 0 && idx_hostname >= 0; - --idx_pattern, --idx_hostname) { - if (tolower((unsigned char)pattern_start[idx_pattern]) != - tolower((unsigned char)hostname[idx_hostname])) - break; - } - - return idx_pattern == -1 && (idx_hostname == -1|| hostname[idx_hostname] == '.'); -} - - -/** - * xmlNanoHTTPBypassProxy: - * @hostname: The hostname as it appears in the URL - * - * This function evaluates the no_proxy environment variable and returns - * whether the proxy server should be bypassed for a given host. - * - * Returns true, iff a proxy server should be bypassed for the given hostname. - */ - -static int -xmlNanoHTTPBypassProxy(const char *hostname) { - size_t envlen; - char *env = getenv("no_proxy"), *cpy=NULL, *p=NULL; - if (!env) - return 0; - - /* (Avoid strdup because it's not portable.) */ - envlen = strlen(env) + 1; - cpy = xmlMalloc(envlen); - memcpy(cpy, env, envlen); - env = cpy; - - /* The remainder of the function is basically a tokenizing: */ - while (isspace((unsigned char)*env)) - ++env; - if (*env == '\0') { - xmlFree(cpy); - return 0; - } - - p = env; - while (*env) { - - if (*env != ',') { - ++env; - continue; - } - - *(env++) = '\0'; - if (xmlNanoHTTPHostnameMatch(p, hostname)) { - xmlFree(cpy); - return 1; - } - - while (isspace((unsigned char)*env)) - ++env; - p = env; - } - if (xmlNanoHTTPHostnameMatch(p, hostname)) { - xmlFree(cpy); - return 1; - } - - xmlFree(cpy); - return 0; -} - - /** * xmlNanoHTTPMethodRedir: * @URL: The URL to load @@ -1335,200 +113,20 @@ xmlNanoHTTPBypassProxy(const char *hostname) { * @headers: the extra headers * @ilen: input length * - * This function try to open a connection to the indicated resource - * via HTTP using the given @method, adding the given extra headers - * and the input buffer for the request content. + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns NULL in case of failure, otherwise a request handler. - * The contentType, or redir, if provided must be freed by the caller + * Returns NULL. */ - void* -xmlNanoHTTPMethodRedir(const char *URL, const char *method, const char *input, - char **contentType, char **redir, - const char *headers, int ilen ) { - xmlNanoHTTPCtxtPtr ctxt; - char *bp, *p; - int blen; - SOCKET ret; - int nbRedirects = 0; - int use_proxy; - char *redirURL = NULL; - - if (URL == NULL) return(NULL); - if (method == NULL) method = "GET"; - xmlNanoHTTPInit(); - -retry: - if (redirURL == NULL) { - ctxt = xmlNanoHTTPNewCtxt(URL); - if (ctxt == NULL) - return(NULL); - } else { - ctxt = xmlNanoHTTPNewCtxt(redirURL); - if (ctxt == NULL) - return(NULL); - ctxt->location = xmlMemStrdup(redirURL); - } - - if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) { - __xmlIOErr(XML_FROM_IO, XML_IO_UNSUPPORTED_PROTOCOL, ctxt->protocol); - xmlNanoHTTPFreeCtxt(ctxt); - if (redirURL != NULL) xmlFree(redirURL); - return(NULL); - } - if (ctxt->hostname == NULL) { - __xmlIOErr(XML_FROM_HTTP, XML_HTTP_UNKNOWN_HOST, - "Failed to identify host in URI"); - xmlNanoHTTPFreeCtxt(ctxt); - if (redirURL != NULL) xmlFree(redirURL); - return(NULL); - } - use_proxy = proxy && !xmlNanoHTTPBypassProxy(ctxt->hostname); - if (use_proxy) { - blen = strlen(ctxt->hostname) * 2 + 16; - ret = xmlNanoHTTPConnectHost(proxy, proxyPort); - } - else { - blen = strlen(ctxt->hostname); - ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port); - } - if (ret == INVALID_SOCKET) { - xmlNanoHTTPFreeCtxt(ctxt); - if (redirURL != NULL) xmlFree(redirURL); - return(NULL); - } - ctxt->fd = ret; - - if (input == NULL) - ilen = 0; - else - blen += 36; - - if (headers != NULL) - blen += strlen(headers) + 2; - if (contentType && *contentType) - /* reserve for string plus 'Content-Type: \r\n" */ - blen += strlen(*contentType) + 16; - if (ctxt->query != NULL) - /* 1 for '?' */ - blen += strlen(ctxt->query) + 1; - blen += strlen(method) + strlen(ctxt->path) + 24; -#ifdef LIBXML_ZLIB_ENABLED - /* reserve for possible 'Accept-Encoding: gzip' string */ - blen += 23; -#endif - if (ctxt->port != 80) { - /* reserve space for ':xxxxx', incl. potential proxy */ - if (use_proxy) - blen += 17; - else - blen += 11; - } - bp = xmlMalloc(blen); - if ( bp == NULL ) { - xmlNanoHTTPFreeCtxt( ctxt ); - xmlHTTPErrMemory(); - return ( NULL ); - } - - p = bp; - - if (use_proxy) { - if (ctxt->port != 80) { - p += snprintf( p, blen - (p - bp), "%s http://%s:%d%s", - method, ctxt->hostname, - ctxt->port, ctxt->path ); - } - else - p += snprintf( p, blen - (p - bp), "%s http://%s%s", method, - ctxt->hostname, ctxt->path); - } - else - p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path); - - if (ctxt->query != NULL) - p += snprintf( p, blen - (p - bp), "?%s", ctxt->query); - - if (ctxt->port == 80) { - p += snprintf( p, blen - (p - bp), " HTTP/1.0\r\nHost: %s\r\n", - ctxt->hostname); - } else { - p += snprintf( p, blen - (p - bp), " HTTP/1.0\r\nHost: %s:%d\r\n", - ctxt->hostname, ctxt->port); - } - -#ifdef LIBXML_ZLIB_ENABLED - p += snprintf(p, blen - (p - bp), "Accept-Encoding: gzip\r\n"); -#endif - - if (contentType != NULL && *contentType) - p += snprintf(p, blen - (p - bp), "Content-Type: %s\r\n", *contentType); - - if (headers != NULL) - p += snprintf( p, blen - (p - bp), "%s", headers ); - - if (input != NULL) - snprintf(p, blen - (p - bp), "Content-Length: %d\r\n\r\n", ilen ); - else - snprintf(p, blen - (p - bp), "\r\n"); - - ctxt->outptr = ctxt->out = bp; - ctxt->state = XML_NANO_HTTP_WRITE; - blen = strlen( ctxt->out ); - xmlNanoHTTPSend(ctxt, ctxt->out, blen ); - - if ( input != NULL ) { - xmlNanoHTTPSend( ctxt, input, ilen ); - } - - ctxt->state = XML_NANO_HTTP_READ; - - while ((p = xmlNanoHTTPReadLine(ctxt)) != NULL) { - if (*p == 0) { - ctxt->content = ctxt->inrptr; - xmlFree(p); - break; - } - xmlNanoHTTPScanAnswer(ctxt, p); - - xmlFree(p); - } - - if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) && - (ctxt->returnValue < 400)) { - while ( xmlNanoHTTPRecv(ctxt) > 0 ) - ; - if (nbRedirects < XML_NANO_HTTP_MAX_REDIR) { - nbRedirects++; - if (redirURL != NULL) - xmlFree(redirURL); - redirURL = xmlMemStrdup(ctxt->location); - xmlNanoHTTPFreeCtxt(ctxt); - goto retry; - } - xmlNanoHTTPFreeCtxt(ctxt); - if (redirURL != NULL) xmlFree(redirURL); - return(NULL); - } - - if (contentType != NULL) { - if (ctxt->contentType != NULL) - *contentType = xmlMemStrdup(ctxt->contentType); - else - *contentType = NULL; - } - - if ((redir != NULL) && (redirURL != NULL)) { - *redir = redirURL; - } else { - if (redirURL != NULL) - xmlFree(redirURL); - if (redir != NULL) - *redir = NULL; - } - - return((void *) ctxt); +xmlNanoHTTPMethodRedir(const char *URL ATTRIBUTE_UNUSED, + const char *method ATTRIBUTE_UNUSED, + const char *input ATTRIBUTE_UNUSED, + char **contentType, char **redir, + const char *headers ATTRIBUTE_UNUSED, + int ilen ATTRIBUTE_UNUSED) { + if (contentType != NULL) *contentType = NULL; + if (redir != NULL) *redir = NULL; + return(NULL); } /** @@ -1540,19 +138,18 @@ retry: * @headers: the extra headers * @ilen: input length * - * This function try to open a connection to the indicated resource - * via HTTP using the given @method, adding the given extra headers - * and the input buffer for the request content. + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns NULL in case of failure, otherwise a request handler. - * The contentType, if provided must be freed by the caller + * Returns NULL. */ - void* -xmlNanoHTTPMethod(const char *URL, const char *method, const char *input, - char **contentType, const char *headers, int ilen) { - return(xmlNanoHTTPMethodRedir(URL, method, input, contentType, - NULL, headers, ilen)); +xmlNanoHTTPMethod(const char *URL ATTRIBUTE_UNUSED, + const char *method ATTRIBUTE_UNUSED, + const char *input ATTRIBUTE_UNUSED, + char **contentType, const char *headers ATTRIBUTE_UNUSED, + int ilen ATTRIBUTE_UNUSED) { + if (contentType != NULL) *contentType = NULL; + return(NULL); } /** @@ -1562,48 +159,15 @@ xmlNanoHTTPMethod(const char *URL, const char *method, const char *input, * @contentType: if available the Content-Type information will be * returned at that location * - * This function try to fetch the indicated resource via HTTP GET - * and save it's content in the file. + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns -1 in case of failure, 0 in case of success. The contentType, - * if provided must be freed by the caller + * Returns -1. */ int -xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) { - void *ctxt = NULL; - char *buf = NULL; - int fd; - int len; - int ret = 0; - - if (filename == NULL) return(-1); - ctxt = xmlNanoHTTPOpen(URL, contentType); - if (ctxt == NULL) return(-1); - - if (!strcmp(filename, "-")) - fd = 1; /* STDOUT_FILENO */ - else { - fd = open(filename, O_CREAT | O_WRONLY, 00644); - if (fd < 0) { - xmlNanoHTTPClose(ctxt); - if ((contentType != NULL) && (*contentType != NULL)) { - xmlFree(*contentType); - *contentType = NULL; - } - return(-1); - } - } - - xmlNanoHTTPFetchContent( ctxt, &buf, &len ); - if ( len > 0 ) { - if (write(fd, buf, len) == -1) { - ret = -1; - } - } - - xmlNanoHTTPClose(ctxt); - close(fd); - return(ret); +xmlNanoHTTPFetch(const char *URL ATTRIBUTE_UNUSED, + const char *filename ATTRIBUTE_UNUSED, char **contentType) { + if (contentType != NULL) *contentType = NULL; + return(-1); } #ifdef LIBXML_OUTPUT_ENABLED @@ -1612,40 +176,14 @@ xmlNanoHTTPFetch(const char *URL, const char *filename, char **contentType) { * @ctxt: the HTTP context * @filename: the filename where the content should be saved * - * This function saves the output of the HTTP transaction to a file - * It closes and free the context at the end + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns -1 in case of failure, 0 in case of success. + * Returns -1. */ int -xmlNanoHTTPSave(void *ctxt, const char *filename) { - char *buf = NULL; - int fd; - int len; - int ret = 0; - - if ((ctxt == NULL) || (filename == NULL)) return(-1); - - if (!strcmp(filename, "-")) - fd = 1; /* STDOUT_FILENO */ - else { - fd = open(filename, O_CREAT | O_WRONLY, 0666); - if (fd < 0) { - xmlNanoHTTPClose(ctxt); - return(-1); - } - } - - xmlNanoHTTPFetchContent( ctxt, &buf, &len ); - if ( len > 0 ) { - if (write(fd, buf, len) == -1) { - ret = -1; - } - } - - xmlNanoHTTPClose(ctxt); - close(fd); - return(ret); +xmlNanoHTTPSave(void *ctxt ATTRIBUTE_UNUSED, + const char *filename ATTRIBUTE_UNUSED) { + return(-1); } #endif /* LIBXML_OUTPUT_ENABLED */ @@ -1653,155 +191,161 @@ xmlNanoHTTPSave(void *ctxt, const char *filename) { * xmlNanoHTTPReturnCode: * @ctx: the HTTP context * - * Get the latest HTTP return code received + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns the HTTP return code for the request. + * Returns -1. */ int -xmlNanoHTTPReturnCode(void *ctx) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx; - - if (ctxt == NULL) return(-1); - - return(ctxt->returnValue); +xmlNanoHTTPReturnCode(void *ctx ATTRIBUTE_UNUSED) { + return(-1); } /** * xmlNanoHTTPAuthHeader: * @ctx: the HTTP context * - * Get the authentication header of an HTTP context + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns the stashed value of the WWW-Authenticate or Proxy-Authenticate - * header. + * Returns NULL. */ const char * -xmlNanoHTTPAuthHeader(void *ctx) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx; - - if (ctxt == NULL) return(NULL); - - return(ctxt->authHeader); +xmlNanoHTTPAuthHeader(void *ctx ATTRIBUTE_UNUSED) { + return(NULL); } /** * xmlNanoHTTPContentLength: * @ctx: the HTTP context * - * Provides the specified content length from the HTTP header. + * DEPRECATED: HTTP support was removed in 2.15. * - * Return the specified content length from the HTTP header. Note that - * a value of -1 indicates that the content length element was not included in - * the response header. + * Returns -1. */ int -xmlNanoHTTPContentLength( void * ctx ) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx; - - return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength ); +xmlNanoHTTPContentLength(void *ctx ATTRIBUTE_UNUSED) { + return(-1); } /** * xmlNanoHTTPRedir: * @ctx: the HTTP context * - * Provides the specified redirection URL if available from the HTTP header. + * DEPRECATED: HTTP support was removed in 2.15. * - * Return the specified redirection URL or NULL if not redirected. + * Returns NULL. */ const char * -xmlNanoHTTPRedir( void * ctx ) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx; - - return ( ( ctxt == NULL ) ? NULL : ctxt->location ); +xmlNanoHTTPRedir(void *ctx ATTRIBUTE_UNUSED) { + return(NULL); } /** * xmlNanoHTTPEncoding: * @ctx: the HTTP context * - * Provides the specified encoding if specified in the HTTP headers. + * DEPRECATED: HTTP support was removed in 2.15. * - * Return the specified encoding or NULL if not available + * Returns NULL. */ const char * -xmlNanoHTTPEncoding( void * ctx ) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx; - - return ( ( ctxt == NULL ) ? NULL : ctxt->encoding ); +xmlNanoHTTPEncoding(void *ctx ATTRIBUTE_UNUSED) { + return(NULL); } /** * xmlNanoHTTPMimeType: * @ctx: the HTTP context * - * Provides the specified Mime-Type if specified in the HTTP headers. + * DEPRECATED: HTTP support was removed in 2.15. * - * Return the specified Mime-Type or NULL if not available + * Returns NULL. */ const char * -xmlNanoHTTPMimeType( void * ctx ) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx; - - return ( ( ctxt == NULL ) ? NULL : ctxt->mimeType ); +xmlNanoHTTPMimeType(void *ctx ATTRIBUTE_UNUSED) { + return(NULL); } /** - * xmlNanoHTTPFetchContent: - * @ctx: the HTTP context - * @ptr: pointer to set to the content buffer. - * @len: integer pointer to hold the length of the content + * xmlIOHTTPMatch: + * @filename: the URI for matching * - * Check if all the content was read + * DEPRECATED: HTTP support was removed in 2.15. * - * Returns 0 if all the content was read and available, returns - * -1 if received content length was less than specified or an error - * occurred. + * Returns 0. */ -static int -xmlNanoHTTPFetchContent( void * ctx, char ** ptr, int * len ) { - xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx; - - int rc = 0; - int cur_lgth; - int rcvd_lgth; - int dummy_int; - char * dummy_ptr = NULL; - - /* Dummy up return input parameters if not provided */ - - if ( len == NULL ) - len = &dummy_int; - - if ( ptr == NULL ) - ptr = &dummy_ptr; - - /* But can't work without the context pointer */ - - if ( ( ctxt == NULL ) || ( ctxt->content == NULL ) ) { - *len = 0; - *ptr = NULL; - return ( -1 ); - } - - rcvd_lgth = ctxt->inptr - ctxt->content; - - while ( (cur_lgth = xmlNanoHTTPRecv( ctxt )) > 0 ) { - - rcvd_lgth += cur_lgth; - if ( (ctxt->ContentLength > 0) && (rcvd_lgth >= ctxt->ContentLength) ) - break; - } - - *ptr = ctxt->content; - *len = rcvd_lgth; - - if ( ( ctxt->ContentLength > 0 ) && ( rcvd_lgth < ctxt->ContentLength ) ) - rc = -1; - else if ( rcvd_lgth == 0 ) - rc = -1; - - return ( rc ); +int +xmlIOHTTPMatch(const char *filename ATTRIBUTE_UNUSED) { + return(0); } -#endif /* LIBXML_HTTP_ENABLED */ +/** + * xmlIOHTTPOpen: + * @filename: the URI for matching + * + * DEPRECATED: HTTP support was removed in 2.15. + * + * Returns NULL. + */ +void * +xmlIOHTTPOpen(const char *filename ATTRIBUTE_UNUSED) { + return(NULL); +} + +#ifdef LIBXML_OUTPUT_ENABLED +/** + * xmlIOHTTPOpenW: + * @post_uri: The destination URI for the document + * @compression: The compression desired for the document. + * + * DEPRECATED: HTTP support was removed in 2.15. + * + * Returns NULL. + */ +void * +xmlIOHTTPOpenW(const char *post_uri ATTRIBUTE_UNUSED, + int compression ATTRIBUTE_UNUSED) +{ + return(NULL); +} +#endif /* LIBXML_OUTPUT_ENABLED */ + +/** + * xmlIOHTTPRead: + * @context: the I/O context + * @buffer: where to drop data + * @len: number of bytes to write + * + * DEPRECATED: HTTP support was removed in 2.15. + * + * Returns -1. + */ +int +xmlIOHTTPRead(void *context ATTRIBUTE_UNUSED, char *buffer ATTRIBUTE_UNUSED, + int len ATTRIBUTE_UNUSED) { + return(-1); +} + +/** + * xmlIOHTTPClose: + * @context: the I/O context + * + * DEPRECATED: Internal function, don't use. + * + * Returns 0 + */ +int +xmlIOHTTPClose (void *context ATTRIBUTE_UNUSED) { + return 0; +} + +/** + * xmlRegisterHTTPPostCallbacks: + * + * DEPRECATED: HTTP support was removed in 2.15. + */ +void +xmlRegisterHTTPPostCallbacks(void) { + xmlRegisterDefaultOutputCallbacks(); +} + +#endif /* LIBXML_HTTP_STUBS_ENABLED */ diff --git a/parser.c b/parser.c index d8d590ff..46b1237b 100644 --- a/parser.c +++ b/parser.c @@ -557,11 +557,7 @@ xmlHasFeature(xmlFeature feature) return(0); #endif case XML_WITH_HTTP: -#ifdef LIBXML_HTTP_ENABLED - return(1); -#else return(0); -#endif case XML_WITH_VALID: #ifdef LIBXML_VALID_ENABLED return(1); @@ -13583,7 +13579,11 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask) * * XML_PARSE_NONET * - * Disable network access with the builtin HTTP client. + * Disable network access with the built-in HTTP or FTP clients. + * + * After the last built-in network client was removed in 2.15, + * this option has no effect expect for being passed on to custom + * resource loaders. * * XML_PARSE_NODICT * diff --git a/parserInternals.c b/parserInternals.c index 6dc539e0..34f81b0f 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -35,7 +35,6 @@ #include #endif #include -#include #define CUR(ctxt) ctxt->input->cur #define END(ctxt) ctxt->input->end @@ -2374,53 +2373,6 @@ xmlResolveResourceFromCatalog(const char *URL, const char *ID, #endif -#ifdef LIBXML_HTTP_ENABLED -static xmlParserErrors -xmlCheckHTTPInputInternal(xmlParserInputPtr input) { - const char *encoding; - const char *redir; - const char *mime; - int code; - - if ((input == NULL) || (input->buf == NULL) || - (input->buf->readcallback != xmlIOHTTPRead) || - (input->buf->context == NULL)) - return(XML_ERR_OK); - - code = xmlNanoHTTPReturnCode(input->buf->context); - if (code >= 400) { - /* fatal error */ - return(XML_IO_LOAD_ERROR); - } - - mime = xmlNanoHTTPMimeType(input->buf->context); - if ((xmlStrstr(BAD_CAST mime, BAD_CAST "/xml")) || - (xmlStrstr(BAD_CAST mime, BAD_CAST "+xml"))) { - encoding = xmlNanoHTTPEncoding(input->buf->context); - if (encoding != NULL) { - xmlCharEncodingHandlerPtr handler; - xmlParserErrors res; - - res = xmlOpenCharEncodingHandler(encoding, /* output */ 0, - &handler); - if (res == 0) - xmlInputSetEncodingHandler(input, handler); - } - } - - redir = xmlNanoHTTPRedir(input->buf->context); - if (redir != NULL) { - if (input->filename != NULL) - xmlFree((xmlChar *) input->filename); - input->filename = xmlMemStrdup(redir); - if (input->filename == NULL) - return(XML_ERR_NO_MEMORY); - } - - return(XML_ERR_OK); -} -#endif /* LIBXML_HTTP_ENABLED */ - /** * xmlCheckHTTPInput: * @ctxt: an XML parser context @@ -2428,34 +2380,12 @@ xmlCheckHTTPInputInternal(xmlParserInputPtr 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 raised in context - * - * Returns the input or NULL in case of HTTP error. + * Returns NULL. */ xmlParserInputPtr -xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) { - /* Avoid unused variable warning if features are disabled. */ - (void) ctxt; - -#ifdef LIBXML_HTTP_ENABLED - { - int code = xmlCheckHTTPInputInternal(ret); - - if (code != XML_ERR_OK) { - if (ret->filename != NULL) - xmlCtxtErrIO(ctxt, XML_IO_LOAD_ERROR, ret->filename); - else - xmlCtxtErrIO(ctxt, XML_IO_LOAD_ERROR, ""); - xmlFreeInputStream(ret); - return(NULL); - } - } -#endif - - return(ret); +xmlCheckHTTPInput(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, + xmlParserInputPtr ret ATTRIBUTE_UNUSED) { + return(NULL); } /** @@ -2478,7 +2408,6 @@ xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) { * - the default loader which will return * - the result from a matching global input callback set with * xmlRegisterInputCallbacks (deprecated) - * - a HTTP resource if support is compiled in. * - a file opened from the filesystem, with automatic detection * of compressed files if support is compiled in. * @@ -2515,14 +2444,6 @@ xmlNewInputFromUrl(const char *filename, xmlParserInputFlags flags, if (input == NULL) return(XML_ERR_NO_MEMORY); -#ifdef LIBXML_HTTP_ENABLED - code = xmlCheckHTTPInputInternal(input); - if (code != XML_ERR_OK) { - xmlFreeInputStream(input); - return(code); - } -#endif - *out = input; return(XML_ERR_OK); } @@ -2589,6 +2510,10 @@ xmlDefaultExternalEntityLoader(const char *url, const char *ID, url = resource; #endif + /* + * Several downstream test suites expect this error whenever + * an http URI is passed and NONET is set. + */ if ((ctxt != NULL) && (ctxt->options & XML_PARSE_NONET) && (xmlStrncasecmp(BAD_CAST url, BAD_CAST "http://", 7) == 0)) { @@ -2773,7 +2698,6 @@ xmlLoadResource(xmlParserCtxtPtr ctxt, const char *url, const char *publicId, * - the default loader which will return * - the result from a matching global input callback set with * xmlRegisterInputCallbacks (deprecated) - * - a HTTP resource if support is compiled in. * - a file opened from the filesystem, with automatic detection * of compressed files if support is compiled in. * diff --git a/testapi.c b/testapi.c index 5e3e6fb9..e815d3df 100644 --- a/testapi.c +++ b/testapi.c @@ -669,7 +669,7 @@ static void des_xmlOutputBufferPtr(int no ATTRIBUTE_UNUSED, xmlOutputBufferPtr v } #endif -#ifdef LIBXML_HTTP_ENABLED +#ifdef LIBXML_HTTP_STUBS_ENABLED #define gen_nb_xmlNanoHTTPCtxtPtr 1 static void *gen_xmlNanoHTTPCtxtPtr(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return(xmlNanoHTTPOpen(REMOTE1GOOD, NULL)); @@ -862,7 +862,7 @@ static void desret_xmlRelaxNGParserCtxtPtr(xmlRelaxNGParserCtxtPtr val) { static void desret_const_htmlEntityDesc_ptr(const htmlEntityDesc * val ATTRIBUTE_UNUSED) { } #endif -#ifdef LIBXML_HTTP_ENABLED +#ifdef LIBXML_HTTP_STUBS_ENABLED static void desret_xmlNanoHTTPCtxtPtr(void *val) { xmlNanoHTTPClose(val); } @@ -11184,7 +11184,7 @@ static int test_xmlNanoHTTPAuthHeader(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; const char * ret_val; void * ctx; /* the HTTP context */ @@ -11218,7 +11218,7 @@ static int test_xmlNanoHTTPCleanup(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; mem_base = xmlMemBlocks(); @@ -11243,7 +11243,7 @@ static int test_xmlNanoHTTPContentLength(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; void * ctx; /* the HTTP context */ @@ -11277,7 +11277,7 @@ static int test_xmlNanoHTTPEncoding(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; const char * ret_val; void * ctx; /* the HTTP context */ @@ -11315,7 +11315,7 @@ static int test_xmlNanoHTTPFetch(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; const char * URL; /* The URL to load */ @@ -11363,7 +11363,7 @@ static int test_xmlNanoHTTPInit(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; mem_base = xmlMemBlocks(); @@ -11388,7 +11388,7 @@ static int test_xmlNanoHTTPMimeType(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; const char * ret_val; void * ctx; /* the HTTP context */ @@ -11422,7 +11422,7 @@ static int test_xmlNanoHTTPOpen(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; void * ret_val; const char * URL; /* The URL to load */ @@ -11463,7 +11463,7 @@ static int test_xmlNanoHTTPOpenRedir(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; void * ret_val; const char * URL; /* The URL to load */ @@ -11511,7 +11511,7 @@ static int test_xmlNanoHTTPRead(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; void * ctx; /* the HTTP context */ @@ -11569,7 +11569,7 @@ static int test_xmlNanoHTTPReturnCode(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; void * ctx; /* the HTTP context */ @@ -11603,7 +11603,7 @@ static int test_xmlNanoHTTPSave(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) int mem_base; int ret_val; void * ctxt; /* the HTTP context */ @@ -11644,7 +11644,7 @@ static int test_xmlNanoHTTPScanProxy(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) const char * URL; /* The proxy URL used to initialize the proxy context */ int n_URL; @@ -28511,7 +28511,7 @@ static int test_xmlIOHTTPClose(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; void * context; /* the I/O context */ @@ -28545,7 +28545,7 @@ static int test_xmlIOHTTPMatch(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; const char * filename; /* the URI for matching */ @@ -28579,7 +28579,7 @@ static int test_xmlIOHTTPOpen(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; void * ret_val; const char * filename; /* the URI for matching */ @@ -28613,7 +28613,7 @@ static int test_xmlIOHTTPRead(void) { int test_ret = 0; -#if defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; int ret_val; void * context; /* the I/O context */ @@ -29563,7 +29563,7 @@ static int test_xmlRegisterHTTPPostCallbacks(void) { int test_ret = 0; -#if defined(LIBXML_OUTPUT_ENABLED) && defined(LIBXML_HTTP_ENABLED) +#if defined(LIBXML_OUTPUT_ENABLED) && defined(LIBXML_HTTP_STUBS_ENABLED) int mem_base; mem_base = xmlMemBlocks(); diff --git a/win32/Makefile.bcb b/win32/Makefile.bcb index db891e3f..0c77ccb2 100644 --- a/win32/Makefile.bcb +++ b/win32/Makefile.bcb @@ -75,9 +75,6 @@ LIBS = $(LIBS) cw32i.lib !else LIBS = $(LIBS) cw32.lib !endif -!if "$(WITH_HTTP)" == "1" -LIBS = $(LIBS) wsock32.lib ws2_32.lib -!endif !if "$(WITH_ICONV)" == "1" LIBS = $(LIBS) iconvomf.lib !endif diff --git a/win32/Makefile.mingw b/win32/Makefile.mingw index 1eb058b6..a02b2035 100644 --- a/win32/Makefile.mingw +++ b/win32/Makefile.mingw @@ -49,9 +49,6 @@ LDFLAGS += -Wl,--major-image-version,$(LIBXML_MAJOR_VERSION) LDFLAGS += -Wl,--minor-image-version,$(LIBXML_MINOR_VERSION) LDFLAGS += -Wl,-L,$(BINDIR) -Wl,-L,$(LIBPREFIX) LIBS = -ifeq ($(WITH_HTTP),1) -LIBS += -lwsock32 -lws2_32 -endif ifeq ($(WITH_ICONV),1) LIBS += -liconv endif diff --git a/win32/Makefile.msvc b/win32/Makefile.msvc index df6e487d..253e593f 100644 --- a/win32/Makefile.msvc +++ b/win32/Makefile.msvc @@ -52,9 +52,6 @@ LD = link.exe LDFLAGS = /nologo /VERSION:$(LIBXML_MAJOR_VERSION).$(LIBXML_MINOR_VERSION) LDFLAGS = $(LDFLAGS) /LIBPATH:$(BINDIR) /LIBPATH:$(LIBPREFIX) LIBS = -!if "$(WITH_HTTP)" == "1" -LIBS = $(LIBS) wsock32.lib ws2_32.lib -!endif !if "$(WITH_ICONV)" == "1" LIBS = $(LIBS) iconv.lib !endif diff --git a/xmlIO.c b/xmlIO.c index b453c28e..b4a49cb9 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #ifdef LIBXML_CATALOG_ENABLED @@ -929,98 +928,6 @@ xmlXzfileClose (void * context) { } #endif /* LIBXML_LZMA_ENABLED */ -/************************************************************************ - * * - * I/O for HTTP file accesses * - * * - ************************************************************************/ - -#ifdef LIBXML_HTTP_ENABLED -/** - * xmlIOHTTPMatch: - * @filename: the URI for matching - * - * DEPRECATED: Internal function, don't use. - * - * check if the URI matches an HTTP one - * - * Returns 1 if matches, 0 otherwise - */ -int -xmlIOHTTPMatch (const char *filename) { - if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "http://", 7)) - return(1); - return(0); -} - -/** - * xmlIOHTTPOpen: - * @filename: the URI for matching - * - * DEPRECATED: Internal function, don't use. - * - * open an HTTP I/O channel - * - * Returns an I/O context or NULL in case of error - */ -void * -xmlIOHTTPOpen (const char *filename) { - return(xmlNanoHTTPOpen(filename, NULL)); -} - -#ifdef LIBXML_OUTPUT_ENABLED -/** - * xmlIOHTTPOpenW: - * @post_uri: The destination URI for the document - * @compression: The compression desired for the document. - * - * DEPRECATED: Support for HTTP POST has been removed. - * - * Returns NULL. - */ -void * -xmlIOHTTPOpenW(const char *post_uri ATTRIBUTE_UNUSED, - int compression ATTRIBUTE_UNUSED) -{ - return(NULL); -} -#endif /* LIBXML_OUTPUT_ENABLED */ - -/** - * xmlIOHTTPRead: - * @context: the I/O context - * @buffer: where to drop data - * @len: number of bytes to write - * - * DEPRECATED: Internal function, don't use. - * - * Read @len bytes to @buffer from the I/O channel. - * - * Returns the number of bytes written - */ -int -xmlIOHTTPRead(void * context, char * buffer, int len) { - if ((buffer == NULL) || (len < 0)) return(-1); - return(xmlNanoHTTPRead(context, &buffer[0], len)); -} - -/** - * xmlIOHTTPClose: - * @context: the I/O context - * - * DEPRECATED: Internal function, don't use. - * - * Close an HTTP I/O channel - * - * Returns 0 - */ -int -xmlIOHTTPClose (void * context) { - xmlNanoHTTPClose(context); - return 0; -} -#endif /* LIBXML_HTTP_ENABLED */ - /************************************************************************ * * * Input/output buffers * @@ -1161,21 +1068,6 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename, xmlParserErrors ret; int fd; -#ifdef LIBXML_HTTP_ENABLED - if (xmlIOHTTPMatch(filename)) { - if ((flags & XML_INPUT_NETWORK) == 0) - return(XML_IO_NETWORK_ATTEMPT); - - buf->context = xmlIOHTTPOpen(filename); - - if (buf->context != NULL) { - buf->readcallback = xmlIOHTTPRead; - buf->closecallback = xmlIOHTTPClose; - return(XML_ERR_OK); - } - } -#endif /* LIBXML_HTTP_ENABLED */ - if (!xmlFileMatch(filename)) return(XML_IO_ENOENT); @@ -2886,17 +2778,5 @@ xmlCleanupOutputCallbacks(void) xmlOutputCallbackNr = 0; } - -#ifdef LIBXML_HTTP_ENABLED -/** - * xmlRegisterHTTPPostCallbacks: - * - * DEPRECATED: Support for HTTP POST has been removed. - */ -void -xmlRegisterHTTPPostCallbacks(void) { - xmlRegisterDefaultOutputCallbacks(); -} -#endif #endif /* LIBXML_OUTPUT_ENABLED */