diff options
author | Ralf Corsépius <corsepiu@fedoraproject.org> | 2007-09-12 11:42:08 +0200 |
---|---|---|
committer | Ralf Corsépius <corsepiu@fedoraproject.org> | 2007-09-12 11:42:08 +0200 |
commit | 52bc67436f5bc28d2bd08a9fd3498cf16d5817bb (patch) | |
tree | 9149fd305ac9e5339afd21a413396f5cba71d6b0 | |
parent | 07c9cac938a6b5e8c41bf8afa92180c9ffd5b90c (diff) | |
parent | 1180de589bb6e18ec4edfcfa478f6c1b79dd17aa (diff) | |
download | rpm-52bc67436f5bc28d2bd08a9fd3498cf16d5817bb.tar.gz rpm-52bc67436f5bc28d2bd08a9fd3498cf16d5817bb.tar.bz2 rpm-52bc67436f5bc28d2bd08a9fd3498cf16d5817bb.zip |
Attempt to escape hg messed up the repo once more.
-rw-r--r-- | configure.ac | 35 | ||||
-rw-r--r-- | lib/poptALL.c | 10 | ||||
-rw-r--r-- | lib/tufdio.c | 2 | ||||
-rw-r--r-- | macros.in | 6 | ||||
-rw-r--r-- | rpmio/Makefile.am | 10 | ||||
-rw-r--r-- | rpmio/rpmdav.c | 663 | ||||
-rw-r--r-- | rpmio/rpmdav.h | 55 | ||||
-rw-r--r-- | rpmio/rpmio.c | 1327 | ||||
-rw-r--r-- | rpmio/rpmio.h | 8 | ||||
-rw-r--r-- | rpmio/rpmio_internal.h | 19 | ||||
-rw-r--r-- | rpmio/rpmrpc.c | 3 | ||||
-rw-r--r-- | rpmio/rpmurl.h | 15 | ||||
-rw-r--r-- | rpmio/tdir.c | 5 | ||||
-rw-r--r-- | rpmio/tfts.c | 5 | ||||
-rw-r--r-- | rpmio/tget.c | 9 | ||||
-rw-r--r-- | rpmio/tglob.c | 9 | ||||
-rw-r--r-- | rpmio/thkp.c | 8 | ||||
-rw-r--r-- | rpmio/tput.c | 9 | ||||
-rw-r--r-- | rpmio/tring.c | 4 | ||||
-rw-r--r-- | rpmio/url.c | 78 | ||||
-rw-r--r-- | tests/Makefile.am | 2 |
21 files changed, 62 insertions, 2220 deletions
diff --git a/configure.ac b/configure.ac index 8b9a9bb1e..5a6bc0930 100644 --- a/configure.ac +++ b/configure.ac @@ -423,41 +423,6 @@ AC_SUBST(WITH_BEECRYPT_INCLUDE) AC_SUBST(WITH_BEECRYPT_LIB) #================= -# Check for neon library. Prefer external, otherwise none. -AC_ARG_WITH(neon, [ --with-neon enable neon support], -[case "$with_neon" in -yes|no) ;; -*) AC_MSG_ERROR([invalid argument to --with-neon]) - ;; -esac], -[with_neon=no]) - -WITH_NEON_INCLUDE= -WITH_NEON_LIB= -AS_IF([test "$with_neon" = yes],[ - AC_CHECK_HEADER([neon/ne_session.h], [ - AC_CHECK_LIB(neon, ne_session_create, [ - AC_DEFINE(HAVE_LIBNEON, 1, [Define to 1 if you have the 'neon' library (-lneon).]) - AC_CHECK_LIB(neon, ne_get_response_header, [ - AC_DEFINE(HAVE_NEON_NE_GET_RESPONSE_HEADER, 1, [Define to 1 if you have ne_get_response_header() in libneon.]) - ]) - AC_CHECK_LIB(neon, ne_send_request_chunk, [ - AC_DEFINE(HAVE_NEON_NE_SEND_REQUEST_CHUNK, 1, [Define to 1 if you have ne_send_request_chunk() in libneon.]) - ]) - WITH_NEON_INCLUDE= - WITH_NEON_LIB="-lneon" - AC_DEFINE(WITH_NEON,1,[Build with neon support?]) - ],[ - AC_MSG_ERROR([--with-neon given, but required library libneon not found]) - ]) - ],[ - AC_MSG_ERROR([--with-neon given, but required header neon/ne_session.h not found]) - ]) -]) -AC_SUBST(WITH_NEON_INCLUDE) -AC_SUBST(WITH_NEON_LIB) - -#================= # Check for magic library. WITH_MAGIC_INCLUDE= WITH_MAGIC_LIB= diff --git a/lib/poptALL.c b/lib/poptALL.c index 481177ea2..73dd2a44d 100644 --- a/lib/poptALL.c +++ b/lib/poptALL.c @@ -70,10 +70,6 @@ const char * rpmcliRootDir = "/"; rpmQueryFlags rpmcliQueryFlags; -extern int _ftp_debug; -extern int _av_debug; -extern int _dav_debug; - extern int noLibio; extern int _rpmio_debug; @@ -262,12 +258,6 @@ struct poptOption rpmcliAllPoptTable[] = { N_("debug payload file state machine"), NULL}, { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1, N_("use threads for file state machine"), NULL}, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug FTP/HTTP data stream"), NULL}, - { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1, - N_("debug argv collections"), NULL}, - { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1, - N_("debug WebDAV data stream"), NULL}, { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1, NULL, NULL}, #ifdef DYING diff --git a/lib/tufdio.c b/lib/tufdio.c index 78e0bc84c..c77348fb8 100644 --- a/lib/tufdio.c +++ b/lib/tufdio.c @@ -11,7 +11,6 @@ #include <err.h> #include "debug.h" -extern int _ftp_debug; extern int _url_debug; extern int _rpmio_debug; @@ -152,7 +151,6 @@ int main (int argc, char * argv[]) { int rc; - _ftp_debug = -1; _url_debug = -1; _rpmio_debug = -1; @@ -1219,5 +1219,11 @@ done \ # %find_lang @RPMCONFIGDIR@/find-lang.sh %{buildroot} +# Commands + opts to use for retrieving remote files +%__urlhelpercmd /usr/bin/curl +%__urlhelperopts --silent --show-error --fail --location -o +%_urlhelper %{__urlhelpercmd} %{__urlhelperopts} + + # \endverbatim #*/ diff --git a/rpmio/Makefile.am b/rpmio/Makefile.am index 6a6e24479..0bf0fc969 100644 --- a/rpmio/Makefile.am +++ b/rpmio/Makefile.am @@ -3,7 +3,6 @@ AM_CPPFLAGS = -I. \ -I$(top_srcdir) \ @WITH_BEECRYPT_INCLUDE@ \ - @WITH_NEON_INCLUDE@ \ @WITH_LUA_INCLUDE@ \ @WITH_POPT_INCLUDE@ \ -I$(top_srcdir)/misc @@ -11,21 +10,20 @@ AM_CPPFLAGS += -DRPMCONFIGDIR="\"@RPMCONFIGDIR@\"" pkgincdir = $(pkgincludedir) pkginc_HEADERS = \ - argv.h fts.h rpmdav.h \ + argv.h fts.h \ rpmio.h rpmurl.h rpmmacro.h rpmlog.h rpmmessages.h rpmerr.h rpmpgp.h \ rpmsq.h rpmsw.h ugid.h usrlibdir = $(libdir) usrlib_LTLIBRARIES = librpmio.la librpmio_la_SOURCES = \ - argv.c digest.c fts.c macro.c rpmdav.c \ + argv.c digest.c fts.c macro.c \ rpmhook.c rpmio.c rpmlog.c rpmlua.c rpmmalloc.c \ rpmpgp.c rpmrpc.c rpmsq.c rpmsw.c strcasecmp.c stubs.c url.c ugid.c \ rpmio_internal.h rpmlua.h rpmhook.h librpmio_la_LDFLAGS = -release 4.4 librpmio_la_LIBADD = \ @WITH_BEECRYPT_LIB@ \ - @WITH_NEON_LIB@ \ @WITH_LUA_LIB@ \ @WITH_MAGIC_LIB@ \ @WITH_ZLIB_LIB@ \ @@ -53,10 +51,6 @@ check_PROGRAMS += thkp thkp_SOURCES = thkp.c rpmio_internal.h thkp_LDADD = librpmio.la @WITH_POPT_LIB@ -check_PROGRAMS += tput -tput_SOURCES = tput.c rpmio_internal.h -tput_LDADD = librpmio.la @WITH_POPT_LIB@ - check_PROGRAMS += tglob tglob_SOURCES = tglob.c rpmio_internal.h tglob_LDADD = librpmio.la @WITH_POPT_LIB@ diff --git a/rpmio/rpmdav.c b/rpmio/rpmdav.c deleted file mode 100644 index da4d29ede..000000000 --- a/rpmio/rpmdav.c +++ /dev/null @@ -1,663 +0,0 @@ -/** \ingroup rpmio - * \file rpmio/rpmdav.c - */ - -#include "system.h" - -#if defined(HAVE_PTHREAD_H) -#include <pthread.h> -#endif - -#ifdef WITH_NEON - -#include "neon/ne_alloc.h" -#include "neon/ne_auth.h" -#include "neon/ne_basic.h" -#include "neon/ne_dates.h" -#include "neon/ne_locks.h" - -#include "neon/ne_props.h" -#include "neon/ne_request.h" -#include "neon/ne_socket.h" -#include "neon/ne_string.h" -#include "neon/ne_utils.h" - -/* XXX don't assume access to neon internal headers, ugh.. */ -#define NEONBLOWSCHUNKS - -#endif /* WITH_NEON */ - -#include <rpmio_internal.h> - -#define _RPMDAV_INTERNAL -#include <rpmdav.h> - -#include "argv.h" -#include "ugid.h" -#include "debug.h" - - -#if 0 /* HACK: reasonable value needed. */ -#define TIMEOUT_SECS 60 -#else -#define TIMEOUT_SECS 5 -#endif - -#ifdef WITH_NEON -static int httpTimeoutSecs = TIMEOUT_SECS; -#endif - -/** - * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. - * @param p memory to free - * @retval NULL always - */ -static inline void * -_free(const void * p) -{ - if (p != NULL) free((void *)p); - return NULL; -} - -#ifdef WITH_NEON - -/* =============================================================== */ - -static void davProgress(void * userdata, off_t current, off_t total) -{ - urlinfo u = userdata; - ne_session * sess; - -assert(u != NULL); - sess = u->sess; -assert(sess != NULL); -assert(u == ne_get_session_private(sess, "urlinfo")); - - u->current = current; - u->total = total; - -if (_dav_debug < 0) -fprintf(stderr, "*** davProgress(%p,0x%x:0x%x) sess %p u %p\n", userdata, (unsigned int)current, (unsigned int)total, sess, u); -} - -static void davNotify(void * userdata, - ne_conn_status connstatus, const char * info) -{ - urlinfo u = userdata; - ne_session * sess; - static const char * connstates[] = { - "namelookup", - "connecting", - "connected", - "secure", - "unknown" - }; - -assert(u != NULL); - sess = u->sess; -assert(sess != NULL); -assert(u == ne_get_session_private(sess, "urlinfo")); - -#ifdef REFERENCE -typedef enum { - ne_conn_namelookup, /* lookup up hostname (info = hostname) */ - ne_conn_connecting, /* connecting to host (info = hostname) */ - ne_conn_connected, /* connected to host (info = hostname) */ - ne_conn_secure /* connection now secure (info = crypto level) */ -} ne_conn_status; -#endif - - u->connstatus = connstatus; - -if (_dav_debug < 0) -fprintf(stderr, "*** davNotify(%p,%d,%p) sess %p u %p %s\n", userdata, connstatus, info, sess, u, connstates[ (connstatus < 4 ? connstatus : 4)]); - -} - -static void davCreateRequest(ne_request * req, void * userdata, - const char * method, const char * uri) -{ - urlinfo u = userdata; - ne_session * sess; - void * private = NULL; - const char * id = "urlinfo"; - -assert(u != NULL); -assert(u->sess != NULL); -assert(req != NULL); - sess = ne_get_session(req); -assert(sess == u->sess); -assert(u == ne_get_session_private(sess, "urlinfo")); - -assert(sess != NULL); - private = ne_get_session_private(sess, id); -assert(u == private); - -if (_dav_debug < 0) -fprintf(stderr, "*** davCreateRequest(%p,%p,%s,%s) %s:%p\n", req, userdata, method, uri, id, private); -} - -static void davPreSend(ne_request * req, void * userdata, ne_buffer * buf) -{ - urlinfo u = userdata; - ne_session * sess; - const char * id = "fd"; - FD_t fd = NULL; - -assert(u != NULL); -assert(u->sess != NULL); -assert(req != NULL); - sess = ne_get_session(req); -assert(sess == u->sess); -assert(u == ne_get_session_private(sess, "urlinfo")); - - fd = ne_get_request_private(req, id); - -if (_dav_debug < 0) -fprintf(stderr, "*** davPreSend(%p,%p,%p) sess %p %s %p\n", req, userdata, buf, sess, id, fd); -if (_dav_debug) -fprintf(stderr, "-> %s\n", buf->data); - -} - -static int davPostSend(ne_request * req, void * userdata, const ne_status * status) -{ - urlinfo u = userdata; - ne_session * sess; - const char * id = "fd"; - FD_t fd = NULL; - -assert(u != NULL); -assert(u->sess != NULL); -assert(req != NULL); - sess = ne_get_session(req); -assert(sess == u->sess); -assert(u == ne_get_session_private(sess, "urlinfo")); - - fd = ne_get_request_private(req, id); - -if (_dav_debug < 0) -fprintf(stderr, "*** davPostSend(%p,%p,%p) sess %p %s %p %s\n", req, userdata, status, sess, id, fd, ne_get_error(sess)); - return NE_OK; -} - -static void davDestroyRequest(ne_request * req, void * userdata) -{ - urlinfo u = userdata; - ne_session * sess; - const char * id = "fd"; - FD_t fd = NULL; - -assert(u != NULL); -assert(u->sess != NULL); -assert(req != NULL); - sess = ne_get_session(req); -assert(sess == u->sess); -assert(u == ne_get_session_private(sess, "urlinfo")); - - fd = ne_get_request_private(req, id); - -if (_dav_debug < 0) -fprintf(stderr, "*** davDestroyRequest(%p,%p) sess %p %s %p\n", req, userdata, sess, id, fd); -} - -static void davDestroySession(void * userdata) -{ - urlinfo u = userdata; - ne_session * sess; - void * private = NULL; - const char * id = "urlinfo"; - -assert(u != NULL); -assert(u->sess != NULL); - sess = u->sess; -assert(u == ne_get_session_private(sess, "urlinfo")); - -assert(sess != NULL); - private = ne_get_session_private(sess, id); -assert(u == private); - -if (_dav_debug < 0) -fprintf(stderr, "*** davDestroySession(%p) sess %p %s %p\n", userdata, sess, id, private); -} - -static int -davVerifyCert(void *userdata, int failures, const ne_ssl_certificate *cert) -{ - const char *hostname = userdata; - -if (_dav_debug < 0) -fprintf(stderr, "*** davVerifyCert(%p,%d,%p) %s\n", userdata, failures, cert, hostname); - - return 0; /* HACK: trust all server certificates. */ -} - -static int davConnect(urlinfo u) -{ - const char * path = NULL; - int rc; - - /* HACK: hkp:// has no steenkin' options */ - if (!(u->urltype == URL_IS_HTTP || u->urltype == URL_IS_HTTPS)) - return 0; - - /* HACK: where should server capabilities be read? */ - (void) urlPath(u->url, &path); - /* HACK: perhaps capture Allow: tag, look for PUT permitted. */ - rc = ne_options(u->sess, path, u->capabilities); - switch (rc) { - case NE_OK: - break; - case NE_ERROR: - /* HACK: "301 Moved Permanently" on empty subdir. */ - if (!strncmp("301 ", ne_get_error(u->sess), sizeof("301 ")-1)) - break; - case NE_CONNECT: - case NE_LOOKUP: - default: -if (_dav_debug) -fprintf(stderr, "*** Connect to %s:%d failed(%d):\n\t%s\n", - u->host, u->port, rc, ne_get_error(u->sess)); - u = urlLink(u, __FUNCTION__); /* XXX error exit refcount adjustment */ - break; - } - - /* HACK: sensitive to error returns? */ - u->httpVersion = (ne_version_pre_http11(u->sess) ? 0 : 1); - - return rc; -} - -static int davInit(const char * url, urlinfo * uret) -{ - urlinfo u = NULL; - int rc = 0; - - if (urlSplit(url, &u)) - return -1; /* XXX error returns needed. */ - - if (u->url != NULL && u->sess == NULL) - switch (u->urltype) { - default: - assert(u->urltype != u->urltype); - break; - case URL_IS_HTTPS: - case URL_IS_HTTP: - case URL_IS_HKP: - { ne_server_capabilities * capabilities; - - /* HACK: oneshots should be done Somewhere Else Instead. */ - rc = ((_dav_debug < 0) ? NE_DBG_HTTP : 0); - ne_debug_init(stderr, rc); /* XXX oneshot? */ - rc = ne_sock_init(); /* XXX oneshot? */ - - u->lockstore = ne_lockstore_create(); /* XXX oneshot? */ - - u->capabilities = capabilities = xcalloc(1, sizeof(*capabilities)); - u->sess = ne_session_create(u->scheme, u->host, u->port); - - ne_lockstore_register(u->lockstore, u->sess); - - if (u->proxyh != NULL) - ne_session_proxy(u->sess, u->proxyh, u->proxyp); - -#if 0 - { const ne_inet_addr ** addrs; - unsigned int n; - ne_set_addrlist(u->sess, addrs, n); - } -#endif - - ne_set_progress(u->sess, davProgress, u); - ne_set_status(u->sess, davNotify, u); - - ne_set_persist(u->sess, 1); - ne_set_read_timeout(u->sess, httpTimeoutSecs); - ne_set_useragent(u->sess, PACKAGE "/" PACKAGE_VERSION); - - /* XXX check that neon is ssl enabled. */ - if (!strcasecmp(u->scheme, "https")) - ne_ssl_set_verify(u->sess, davVerifyCert, (char *)u->host); - - ne_set_session_private(u->sess, "urlinfo", u); - - ne_hook_destroy_session(u->sess, davDestroySession, u); - - ne_hook_create_request(u->sess, davCreateRequest, u); - ne_hook_pre_send(u->sess, davPreSend, u); - ne_hook_post_send(u->sess, davPostSend, u); - ne_hook_destroy_request(u->sess, davDestroyRequest, u); - - /* HACK: where should server capabilities be read? */ - rc = davConnect(u); - if (rc) - goto exit; - } break; - } - -exit: - if (rc == 0 && uret != NULL) - *uret = urlLink(u, __FUNCTION__); - u = urlFree(u, "urlSplit (davInit)"); - - return rc; -} - - -/* =============================================================== */ -static int my_result(const char * msg, int ret, FILE * fp) -{ - /* HACK: don't print unless debugging. */ - if (_dav_debug >= 0) - return ret; - if (fp == NULL) - fp = stderr; - if (msg != NULL) - fprintf(fp, "*** %s: ", msg); - - /* HACK FTPERR_NE_FOO == -NE_FOO error impedance match */ -#ifdef HACK - fprintf(fp, "%s: %s\n", ftpStrerror(-ret), ne_get_error(sess)); -#else - fprintf(fp, "%s\n", ftpStrerror(-ret)); -#endif - return ret; -} - -#ifdef DYING -static void hexdump(const unsigned char * buf, ssize_t len) -{ - int i; - if (len <= 0) - return; - for (i = 0; i < len; i++) { - if (i != 0 && (i%16) == 0) - fprintf(stderr, "\n"); - fprintf(stderr, " %02X", buf[i]); - } - fprintf(stderr, "\n"); -} -#endif - -static void davAcceptRanges(void * userdata, const char * value) -{ - urlinfo u = userdata; - - if (!(u && value)) return; -if (_dav_debug < 0) -fprintf(stderr, "*** u %p Accept-Ranges: %s\n", u, value); - if (!strcmp(value, "bytes")) - u->httpHasRange = 1; - if (!strcmp(value, "none")) - u->httpHasRange = 0; -} - -#if !defined(HAVE_NEON_NE_GET_RESPONSE_HEADER) -static void davAllHeaders(void * userdata, const char * value) -{ - FD_t ctrl = userdata; - - if (!(ctrl && value)) return; -if (_dav_debug) -fprintf(stderr, "<- %s\n", value); -} -#endif - -static void davContentLength(void * userdata, const char * value) -{ - FD_t ctrl = userdata; - - if (!(ctrl && value)) return; -if (_dav_debug < 0) -fprintf(stderr, "*** fd %p Content-Length: %s\n", ctrl, value); - ctrl->contentLength = strtoll(value, NULL, 10); -} - -static void davConnection(void * userdata, const char * value) -{ - FD_t ctrl = userdata; - - if (!(ctrl && value)) return; -if (_dav_debug < 0) -fprintf(stderr, "*** fd %p Connection: %s\n", ctrl, value); - if (!strcasecmp(value, "close")) - ctrl->persist = 0; - else if (!strcasecmp(value, "Keep-Alive")) - ctrl->persist = 1; -} - -/* HACK: stash error in *str. */ -int davResp(urlinfo u, FD_t ctrl, char *const * str) -{ - int rc = 0; - - rc = ne_begin_request(ctrl->req); - rc = my_result("ne_begin_req(ctrl->req)", rc, NULL); - -if (_dav_debug < 0) -fprintf(stderr, "*** davResp(%p,%p,%p) sess %p req %p rc %d\n", u, ctrl, str, u->sess, ctrl->req, rc); - - /* HACK FTPERR_NE_FOO == -NE_FOO error impedance match */ - if (rc) - fdSetSyserrno(ctrl, errno, ftpStrerror(-rc)); - - return rc; -} - -int davReq(FD_t ctrl, const char * httpCmd, const char * httpArg) -{ - urlinfo u; - int rc = 0; - -assert(ctrl != NULL); - u = ctrl->url; - URLSANE(u); - -if (_dav_debug < 0) -fprintf(stderr, "*** davReq(%p,%s,\"%s\") entry sess %p req %p\n", ctrl, httpCmd, (httpArg ? httpArg : ""), u->sess, ctrl->req); - - ctrl->persist = (u->httpVersion > 0 ? 1 : 0); - ctrl = fdLink(ctrl, "open ctrl (davReq)"); - -assert(u->sess != NULL); -assert(ctrl->req == NULL); - ctrl->req = ne_request_create(u->sess, httpCmd, httpArg); -assert(ctrl->req != NULL); - - ne_set_request_private(ctrl->req, "fd", ctrl); - -#if !defined(HAVE_NEON_NE_GET_RESPONSE_HEADER) - ne_add_response_header_catcher(ctrl->req, davAllHeaders, ctrl); - - ne_add_response_header_handler(ctrl->req, "Content-Length", - davContentLength, ctrl); - ne_add_response_header_handler(ctrl->req, "Connection", - davConnection, ctrl); -#endif - - if (!strcmp(httpCmd, "PUT")) { -#if defined(HAVE_NEON_NE_SEND_REQUEST_CHUNK) - ctrl->wr_chunked = 1; - ne_add_request_header(ctrl->req, "Transfer-Encoding", "chunked"); - ne_set_request_chunked(ctrl->req, 1); - /* HACK: no retries if/when chunking. */ - rc = davResp(u, ctrl, NULL); -#else - rc = FTPERR_SERVER_IO_ERROR; -#endif - } else { - /* HACK: possible Last-Modified: Tue, 02 Nov 2004 14:29:36 GMT */ - /* HACK: possible ETag: "inode-size-mtime" */ -#if !defined(HAVE_NEON_NE_GET_RESPONSE_HEADER) - ne_add_response_header_handler(ctrl->req, "Accept-Ranges", - davAcceptRanges, u); -#endif - /* HACK: possible Transfer-Encoding: on GET. */ - - /* HACK: other errors may need retry too. */ - /* HACK: neon retries once, gud enuf. */ - /* HACK: retry counter? */ - do { - rc = davResp(u, ctrl, NULL); - } while (rc == NE_RETRY); - } - if (rc) - goto errxit; - -if (_dav_debug < 0) -fprintf(stderr, "*** davReq(%p,%s,\"%s\") exit sess %p req %p rc %d\n", ctrl, httpCmd, (httpArg ? httpArg : ""), u->sess, ctrl->req, rc); - -#if defined(HAVE_NEON_NE_GET_RESPONSE_HEADER) - davContentLength(ctrl, - ne_get_response_header(ctrl->req, "Content-Length")); - davConnection(ctrl, - ne_get_response_header(ctrl->req, "Connection")); - if (strcmp(httpCmd, "PUT")) - davAcceptRanges(u, - ne_get_response_header(ctrl->req, "Accept-Ranges")); -#endif - - ctrl = fdLink(ctrl, "open data (davReq)"); - return 0; - -errxit: - fdSetSyserrno(ctrl, errno, ftpStrerror(rc)); - - /* HACK balance fd refs. ne_session_destroy to tear down non-keepalive? */ - ctrl = fdLink(ctrl, "error data (davReq)"); - - return rc; -} - -FD_t davOpen(const char * url, int flags, - mode_t mode, urlinfo * uret) -{ - const char * path = NULL; - urltype urlType = urlPath(url, &path); - urlinfo u = NULL; - FD_t fd = NULL; - int rc; - -#if 0 /* XXX makeTempFile() heartburn */ - assert(!(flags & O_RDWR)); -#endif - -if (_dav_debug < 0) -fprintf(stderr, "*** davOpen(%s,0x%x,0%o,%p)\n", url, flags, mode, uret); - rc = davInit(url, &u); - if (rc || u == NULL || u->sess == NULL) - goto exit; - - if (u->ctrl == NULL) - u->ctrl = fdNew("persist ctrl (davOpen)"); - if (u->ctrl->nrefs > 2 && u->data == NULL) - u->data = fdNew("persist data (davOpen)"); - - if (u->ctrl->url == NULL) - fd = fdLink(u->ctrl, "grab ctrl (davOpen persist ctrl)"); - else if (u->data->url == NULL) - fd = fdLink(u->data, "grab ctrl (davOpen persist data)"); - else - fd = fdNew("grab ctrl (davOpen)"); - - if (fd) { - fdSetIo(fd, ufdio); - fd->ftpFileDoneNeeded = 0; - fd->rd_timeoutsecs = httpTimeoutSecs; - fd->contentLength = fd->bytesRemain = -1; - fd->url = urlLink(u, "url (davOpen)"); - fd = fdLink(fd, "grab data (davOpen)"); -assert(urlType == URL_IS_HTTPS || urlType == URL_IS_HTTP || urlType == URL_IS_HKP); - fd->urlType = urlType; - } - -exit: - if (uret) - *uret = u; - return fd; -} - -ssize_t davRead(void * cookie, char * buf, size_t count) -{ - FD_t fd = cookie; - ssize_t rc; - -#if 0 -assert(count >= 128); /* HACK: see ne_request.h comment */ -#endif - rc = ne_read_response_block(fd->req, buf, count); - -if (_dav_debug < 0) { -fprintf(stderr, "*** davRead(%p,%p,0x%x) rc 0x%x\n", cookie, buf, (unsigned)count, (unsigned)rc); -#ifdef DYING -hexdump(buf, rc); -#endif - } - - return rc; -} - -ssize_t davWrite(void * cookie, const char * buf, size_t count) -{ - ssize_t rc; - int xx; - -#ifndef NEONBLOWSCHUNKS - ne_session * sess; - -assert(fd->req != NULL); - sess = ne_get_session(fd->req); -assert(sess != NULL); - - /* HACK: include ne_private.h to access sess->socket for now. */ - xx = ne_sock_fullwrite(sess->socket, buf, count); -#else -#if defined(HAVE_NEON_NE_SEND_REQUEST_CHUNK) -assert(fd->req != NULL); - xx = ne_send_request_chunk(fd->req, buf, count); -#else - errno = EIO; /* HACK */ - return -1; -#endif -#endif - - /* HACK: stupid error impedence matching. */ - rc = (xx == 0 ? count : -1); - -if (_dav_debug < 0) -fprintf(stderr, "*** davWrite(%p,%p,0x%x) rc 0x%x\n", cookie, buf, (unsigned)count, (unsigned)rc); -#ifdef DYING -if (count > 0) -hexdump(buf, count); -#endif - - return rc; -} - -int davSeek(void * cookie, _libio_pos_t pos, int whence) -{ -if (_dav_debug < 0) -fprintf(stderr, "*** davSeek(%p,pos,%d)\n", cookie, whence); - return -1; -} - -int davClose(void * cookie) -{ - FD_t fd = cookie; - int rc; - -assert(fd->req != NULL); - rc = ne_end_request(fd->req); - rc = my_result("ne_end_request(req)", rc, NULL); - - ne_request_destroy(fd->req); - fd->req = NULL; - -if (_dav_debug < 0) -fprintf(stderr, "*** davClose(%p) rc %d\n", fd, rc); - return rc; -} - - -#endif /* WITH_NEON */ - diff --git a/rpmio/rpmdav.h b/rpmio/rpmdav.h deleted file mode 100644 index eade89c3f..000000000 --- a/rpmio/rpmdav.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef RPMDAV_H -#define RPMDAV_H - -/** \ingroup rpmio - * \file rpmio/rpmdav.h - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Send a http request. - * @param ctrl - * @param httpCmd http command - * @param httpArg http command argument (NULL if none) - * @returns 0 on success - */ -int davReq(FD_t ctrl, const char * httpCmd, const char * httpArg); - -/** - * Read a http response. - * @param u - * @param cntl - * @retval *str error msg - * @returns 0 on success - */ -int davResp(urlinfo u, FD_t ctrl, char *const * str); - -/** - */ -FD_t davOpen(const char * url, int flags, - mode_t mode, urlinfo * uret); - -/** - */ -ssize_t davRead(void * cookie, char * buf, size_t count); - -/** - */ -ssize_t davWrite(void * cookie, const char * buf, size_t count); - -/** - */ -int davSeek(void * cookie, _libio_pos_t pos, int whence); - -/** - */ -int davClose(void * cookie); - -#ifdef __cplusplus -} -#endif - -#endif /* RPMDAV_H */ diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index ac7704f1c..59bf5a011 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -65,9 +65,11 @@ static int inet_aton(const char *cp, struct in_addr *inp) #undef fdClose #define fdClose __fdClose -#include <rpmdav.h> #include "ugid.h" #include "rpmmessages.h" +#include "argv.h" +#include "rpmerr.h" +#include "rpmmacro.h" #include "debug.h" @@ -95,29 +97,9 @@ int noLibio = 1; /** */ -static int ftpTimeoutSecs = TIMEOUT_SECS; - -/** - */ -static int httpTimeoutSecs = TIMEOUT_SECS; - -/** - */ int _rpmio_debug = 0; /** - */ -int _av_debug = 0; - -/** - */ -int _ftp_debug = 0; - -/** - */ -int _dav_debug = 0; - -/** * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. * @param p memory to free * @retval NULL always @@ -340,18 +322,7 @@ static ssize_t fdRead(void * cookie, char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ fdstat_enter(fd, FDSTAT_READ); - /* HACK: flimsy wiring for davRead */ - if (fd->req != NULL) { -#ifdef WITH_NEON - rc = davRead(fd, buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); -#else - rc = -1; -#endif - /* XXX Chunked davRead EOF. */ - if (rc == 0) - fd->bytesRemain = 0; - } else - rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); + rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); fdstat_exit(fd, FDSTAT_READ, rc); if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); @@ -374,15 +345,7 @@ static ssize_t fdWrite(void * cookie, const char * buf, size_t count) if (count == 0) return 0; fdstat_enter(fd, FDSTAT_WRITE); - /* HACK: flimsy wiring for davWrite */ - if (fd->req != NULL) { -#ifdef WITH_NEON - rc = davWrite(fd, buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); -#else - return -1; -#endif - } else - rc = write(fdno, buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); + rc = write(fdno, buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); fdstat_exit(fd, FDSTAT_WRITE, rc); DBGIO(fd, (stderr, "==>\tfdWrite(%p,%p,%ld) rc %ld %s\n", cookie, buf, (long)count, (long)rc, fdbg(fd))); @@ -423,15 +386,7 @@ static int fdClose( void * cookie) fdSetFdno(fd, -1); fdstat_enter(fd, FDSTAT_CLOSE); - /* HACK: flimsy wiring for davClose */ - if (fd->req != NULL) { -#ifdef WITH_NEON - rc = davClose(fd); -#else - return -1; -#endif - } else - rc = ((fdno >= 0) ? close(fdno) : -2); + rc = ((fdno >= 0) ? close(fdno) : -2); fdstat_exit(fd, FDSTAT_CLOSE, rc); DBGIO(fd, (stderr, "==>\tfdClose(%p) rc %lx %s\n", (fd ? fd : NULL), (unsigned long)rc, fdbg(fd))); @@ -478,10 +433,6 @@ int fdWritable(FD_t fd, int secs) FD_ZERO(&wrfds); #endif - /* HACK: flimsy wiring for davWrite */ - if (fd->req != NULL) - return 1; - if ((fdno = fdFileno(fd)) < 0) return -1; /* XXX W2DO? */ @@ -530,10 +481,6 @@ int fdReadable(FD_t fd, int secs) FD_ZERO(&rdfds); #endif - /* HACK: flimsy wiring for davRead */ - if (fd->req != NULL) - return 1; - if ((fdno = fdFileno(fd)) < 0) return -1; /* XXX W2DO? */ @@ -687,670 +634,6 @@ const char * ftpStrerror(int errorNumber) } } -const char *urlStrerror(const char *url) -{ - const char *retstr; - switch (urlIsURL(url)) { - case URL_IS_HTTPS: - case URL_IS_HTTP: - case URL_IS_HKP: - case URL_IS_FTP: - { urlinfo u; -/* XXX This only works for httpReq/ftpLogin/ftpReq failures */ - if (urlSplit(url, &u) == 0) { - retstr = ftpStrerror(u->openError); - } else - retstr = "Malformed URL"; - } break; - default: - retstr = strerror(errno); - break; - } - return retstr; -} - -#if !defined(HAVE_GETADDRINFO) -#if !defined(USE_ALT_DNS) || !USE_ALT_DNS -static int mygethostbyname(const char * host, - struct in_addr * address) -{ - struct hostent * hostinfo; - - hostinfo = gethostbyname(host); - if (!hostinfo) return 1; - - memcpy(address, hostinfo->h_addr_list[0], sizeof(*address)); - return 0; -} -#endif - -static int getHostAddress(const char * host, struct in_addr * address) -{ -#if 0 /* XXX workaround nss_foo module hand-off using valgrind. */ - if (!strcmp(host, "localhost")) { - if (!inet_aton("127.0.0.1", address)) - return FTPERR_BAD_HOST_ADDR; - } else -#endif - if (xisdigit(host[0])) { - if (!inet_aton(host, address)) - return FTPERR_BAD_HOST_ADDR; - } else { - if (mygethostbyname(host, address)) { - errno = h_errno; - return FTPERR_BAD_HOSTNAME; - } - } - - return 0; -} -#endif - -static int tcpConnect(FD_t ctrl, const char * host, int port) -{ - int fdno = -1; - int rc; -#ifdef HAVE_GETADDRINFO - struct addrinfo hints, *res, *res0; - char pbuf[NI_MAXSERV]; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - sprintf(pbuf, "%d", port); - pbuf[sizeof(pbuf)-1] = '\0'; - rc = FTPERR_FAILED_CONNECT; - if (getaddrinfo(host, pbuf, &hints, &res0) == 0) { - for (res = res0; res != NULL; res= res->ai_next) { - if ((fdno = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) - continue; - if (connect(fdno, res->ai_addr, res->ai_addrlen) < 0) { - close(fdno); - continue; - } - /* success */ - rc = 0; - if (_ftp_debug) { - char hbuf[NI_MAXHOST]; - getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), - NULL, 0, NI_NUMERICHOST); - fprintf(stderr,"++ connect [%s]:%d on fdno %d\n", - hbuf, port, fdno); - } - break; - } - freeaddrinfo(res0); - } - if (rc < 0) - goto errxit; - -#else /* HAVE_GETADDRINFO */ - struct sockaddr_in sin; - - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - sin.sin_addr.s_addr = INADDR_ANY; - - do { - if ((rc = getHostAddress(host, &sin.sin_addr)) < 0) - break; - - if ((fdno = socket(sin.sin_family, SOCK_STREAM, IPPROTO_IP)) < 0) { - rc = FTPERR_FAILED_CONNECT; - break; - } - - if (connect(fdno, (struct sockaddr *) &sin, sizeof(sin))) { - rc = FTPERR_FAILED_CONNECT; - break; - } - } while (0); - - if (rc < 0) - goto errxit; - -if (_ftp_debug) -fprintf(stderr,"++ connect %s:%d on fdno %d\n", -inet_ntoa(sin.sin_addr) -, -(int)ntohs(sin.sin_port), fdno); -#endif /* HAVE_GETADDRINFO */ - - fdSetFdno(ctrl, (fdno >= 0 ? fdno : -1)); - return 0; - -errxit: - fdSetSyserrno(ctrl, errno, ftpStrerror(rc)); - if (fdno >= 0) - (void) close(fdno); - return rc; -} - -static int checkResponse(void * uu, FD_t ctrl, - int *ecp, char ** str) -{ - urlinfo u = uu; - char *buf; - size_t bufAlloced; - int bufLength = 0; - const char *s; - char *se; - int ec = 0; - int moretodo = 1; - char errorCode[4]; - - URLSANE(u); - if (u->bufAlloced == 0 || u->buf == NULL) { - u->bufAlloced = _url_iobuf_size; - u->buf = xcalloc(u->bufAlloced, sizeof(u->buf[0])); - } - buf = u->buf; - bufAlloced = u->bufAlloced; - *buf = '\0'; - - errorCode[0] = '\0'; - - do { - int rc; - - /* - * Read next line from server. - */ - se = buf + bufLength; - *se = '\0'; - rc = fdFgets(ctrl, se, (bufAlloced - bufLength)); - if (rc < 0) { - ec = FTPERR_BAD_SERVER_RESPONSE; - continue; - } else if (rc == 0 || fdWritable(ctrl, 0) < 1) - moretodo = 0; - - /* - * Process next line from server. - */ - for (s = se; *s != '\0'; s = se) { - const char *e; - - while (*se && *se != '\n') se++; - - if (se > s && se[-1] == '\r') - se[-1] = '\0'; - if (*se == '\0') - break; - -if (_ftp_debug) -fprintf(stderr, "<- %s\n", s); - - /* HTTP: header termination on empty line */ - if (*s == '\0') { - moretodo = 0; - break; - } - *se++ = '\0'; - - /* HTTP: look for "HTTP/1.1 123 ..." */ - if (!strncmp(s, "HTTP", sizeof("HTTP")-1)) { - ctrl->contentLength = -1; - if ((e = strchr(s, '.')) != NULL) { - e++; - u->httpVersion = *e - '0'; - if (u->httpVersion < 1 || u->httpVersion > 2) - ctrl->persist = u->httpVersion = 0; - else - ctrl->persist = 1; - } - if ((e = strchr(s, ' ')) != NULL) { - e++; - if (strchr("0123456789", *e)) - strncpy(errorCode, e, 3); - errorCode[3] = '\0'; - } - continue; - } - - /* HTTP: look for "token: ..." */ - for (e = s; *e && !(*e == ' ' || *e == ':'); e++) - {}; - if (e > s && *e++ == ':') { - size_t ne = (e - s); - while (*e && *e == ' ') e++; -#if 0 - if (!strncmp(s, "Date:", ne)) { - } else - if (!strncmp(s, "Server:", ne)) { - } else - if (!strncmp(s, "Last-Modified:", ne)) { - } else - if (!strncmp(s, "ETag:", ne)) { - } else -#endif - if (!strncmp(s, "Accept-Ranges:", ne)) { - if (!strcmp(e, "bytes")) - u->httpHasRange = 1; - if (!strcmp(e, "none")) - u->httpHasRange = 0; - } else - if (!strncmp(s, "Content-Length:", ne)) { - if (strchr("0123456789", *e)) - ctrl->contentLength = atoi(e); - } else - if (!strncmp(s, "Connection:", ne)) { - if (!strcmp(e, "close")) - ctrl->persist = 0; - } -#if 0 - else - if (!strncmp(s, "Content-Type:", ne)) { - } else - if (!strncmp(s, "Transfer-Encoding:", ne)) { - if (!strcmp(e, "chunked")) - ctrl->wr_chunked = 1; - else - ctrl->wr_chunked = 0; - } else - if (!strncmp(s, "Allow:", ne)) { - } -#endif - continue; - } - - /* HTTP: look for "<TITLE>501 ... </TITLE>" */ - if (!strncmp(s, "<TITLE>", sizeof("<TITLE>")-1)) - s += sizeof("<TITLE>") - 1; - - /* FTP: look for "123-" and/or "123 " */ - if (strchr("0123456789", *s)) { - if (errorCode[0] != '\0') { - if (!strncmp(s, errorCode, sizeof("123")-1) && s[3] == ' ') - moretodo = 0; - } else { - strncpy(errorCode, s, sizeof("123")-1); - errorCode[3] = '\0'; - if (s[3] != '-') - moretodo = 0; - } - } - } - - if (moretodo && se > s) { - bufLength = se - s - 1; - if (s != buf) - memmove(buf, s, bufLength); - } else { - bufLength = 0; - } - } while (moretodo && ec == 0); - - if (str) *str = buf; - if (ecp) *ecp = atoi(errorCode); - - return ec; -} - -static int ftpCheckResponse(urlinfo u, char ** str) -{ - int ec = 0; - int rc; - - URLSANE(u); - rc = checkResponse(u, u->ctrl, &ec, str); - - switch (ec) { - case 550: - return FTPERR_FILE_NOT_FOUND; - break; - case 552: - return FTPERR_NIC_ABORT_IN_PROGRESS; - break; - default: - if (ec >= 400 && ec <= 599) { - return FTPERR_BAD_SERVER_RESPONSE; - } - break; - } - return rc; -} - -static int ftpCommand(urlinfo u, char ** str, ...) -{ - va_list ap; - int len = 0; - const char * s, * t; - char * te; - int rc; - - URLSANE(u); - va_start(ap, str); - while ((s = va_arg(ap, const char *)) != NULL) { - if (len) len++; - len += strlen(s); - } - len += sizeof("\r\n")-1; - va_end(ap); - - t = te = alloca(len + 1); - - va_start(ap, str); - while ((s = va_arg(ap, const char *)) != NULL) { - if (te > t) *te++ = ' '; - te = stpcpy(te, s); - } - te = stpcpy(te, "\r\n"); - va_end(ap); - -if (_ftp_debug) -fprintf(stderr, "-> %s", t); - if (fdWrite(u->ctrl, t, (te-t)) != (te-t)) - return FTPERR_SERVER_IO_ERROR; - - rc = ftpCheckResponse(u, str); - return rc; -} - -static int ftpLogin(urlinfo u) -{ - const char * host; - const char * user; - const char * password; - int port; - int rc; - - URLSANE(u); - u->ctrl = fdLink(u->ctrl, "open ctrl"); - - if (((host = (u->proxyh ? u->proxyh : u->host)) == NULL)) { - rc = FTPERR_BAD_HOSTNAME; - goto errxit; - } - - if ((port = (u->proxyp > 0 ? u->proxyp : u->port)) < 0) port = IPPORT_FTP; - - if ((user = (u->proxyu ? u->proxyu : u->user)) == NULL) - user = "anonymous"; - - if ((password = u->password) == NULL) { - uid_t uid = getuid(); - struct passwd * pw; - if (uid && (pw = getpwuid(uid)) != NULL) { - char *myp = alloca(strlen(pw->pw_name) + sizeof("@")); - strcpy(myp, pw->pw_name); - strcat(myp, "@"); - password = myp; - } else { - password = "root@"; - } - } - - if (fdFileno(u->ctrl) >= 0 && fdWritable(u->ctrl, 0) < 1) - (void) fdClose(u->ctrl); - - if (fdFileno(u->ctrl) < 0) { - rc = tcpConnect(u->ctrl, host, port); - if (rc < 0) - goto errxit2; - } - - if ((rc = ftpCheckResponse(u, NULL))) - goto errxit; - - if ((rc = ftpCommand(u, NULL, "USER", user, NULL))) - goto errxit; - - if ((rc = ftpCommand(u, NULL, "PASS", password, NULL))) - goto errxit; - - if ((rc = ftpCommand(u, NULL, "TYPE", "I", NULL))) - goto errxit; - - return 0; - -errxit: - fdSetSyserrno(u->ctrl, errno, ftpStrerror(rc)); -errxit2: - if (fdFileno(u->ctrl) >= 0) - (void) fdClose(u->ctrl); - return rc; -} - -int ftpReq(FD_t data, const char * ftpCmd, const char * ftpArg) -{ - urlinfo u = data->url; -#if !defined(HAVE_GETADDRINFO) - struct sockaddr_in dataAddress; -#endif /* HAVE_GETADDRINFO */ - char remoteIP[NI_MAXHOST]; - char * cmd; - int cmdlen; - char * passReply; - char * chptr; - int rc; - int epsv; - int port; - - URLSANE(u); - if (ftpCmd == NULL) - return FTPERR_UNKNOWN; /* XXX W2DO? */ - - cmdlen = strlen(ftpCmd) + (ftpArg ? 1+strlen(ftpArg) : 0) + sizeof("\r\n"); - chptr = cmd = alloca(cmdlen); - chptr = stpcpy(chptr, ftpCmd); - if (ftpArg) { - *chptr++ = ' '; - chptr = stpcpy(chptr, ftpArg); - } - chptr = stpcpy(chptr, "\r\n"); - cmdlen = chptr - cmd; - -/* - * Get the ftp version of the Content-Length. - */ - if (!strncmp(cmd, "RETR", 4)) { - unsigned cl; - - passReply = NULL; - rc = ftpCommand(u, &passReply, "SIZE", ftpArg, NULL); - if (rc) - goto errxit; - if (sscanf(passReply, "%d %u", &rc, &cl) != 2) { - rc = FTPERR_BAD_SERVER_RESPONSE; - goto errxit; - } - rc = 0; - data->contentLength = cl; - } - - epsv = 0; - passReply = NULL; -#ifdef HAVE_GETNAMEINFO - rc = ftpCommand(u, &passReply, "EPSV", NULL); - if (rc==0) { -#ifdef HAVE_GETADDRINFO - struct sockaddr_storage ss; -#else /* HAVE_GETADDRINFO */ - struct sockaddr_in ss; -#endif /* HAVE_GETADDRINFO */ - socklen_t size; - /* we need to know IP of remote host */ - size=sizeof(ss); - if ((getpeername(fdFileno(c2f(u->ctrl)), (struct sockaddr *)&ss, &size) == 0) && - (getnameinfo((struct sockaddr *)&ss, size, remoteIP, sizeof(remoteIP), - NULL, 0, NI_NUMERICHOST) == 0)) - epsv++; - else { - /* abort EPSV and fall back to PASV */ - rc = ftpCommand(u, &passReply, "ABOR", NULL); - if (rc) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - } - } - if (epsv==0) -#endif /* HAVE_GETNAMEINFO */ - rc = ftpCommand(u, &passReply, "PASV", NULL); - if (rc) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - - chptr = passReply; - while (*chptr && *chptr != '(') chptr++; - if (*chptr != '(') return FTPERR_PASSIVE_ERROR; - chptr++; - passReply = chptr; - while (*chptr && *chptr != ')') chptr++; - if (*chptr != ')') return FTPERR_PASSIVE_ERROR; - *chptr-- = '\0'; - - if (epsv) { - int i; - if(sscanf(passReply,"%*c%*c%*c%d%*c",&i) != 1) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - port = i; - } else { - - while (*chptr && *chptr != ',') chptr--; - if (*chptr != ',') return FTPERR_PASSIVE_ERROR; - chptr--; - while (*chptr && *chptr != ',') chptr--; - if (*chptr != ',') return FTPERR_PASSIVE_ERROR; - *chptr++ = '\0'; - - /* now passReply points to the IP portion, and chptr points to the - port number portion */ - - { int i, j; - if (sscanf(chptr, "%d,%d", &i, &j) != 2) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - port = (((unsigned)i) << 8) + j; - } - - chptr = passReply; - while (*chptr++ != '\0') { - if (*chptr == ',') *chptr = '.'; - } - sprintf(remoteIP, "%s", passReply); - } /* if (epsv) */ - -#ifdef HAVE_GETADDRINFO - { - struct addrinfo hints, *res, *res0; - char pbuf[NI_MAXSERV]; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_NUMERICHOST; - sprintf(pbuf, "%d", port); - pbuf[sizeof(pbuf)-1] = '\0'; - if (getaddrinfo(remoteIP, pbuf, &hints, &res0)) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - - for (res = res0; res != NULL; res = res->ai_next) { - rc = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - fdSetFdno(data, (rc >= 0 ? rc : -1)); - if (rc < 0) { - if (res->ai_next) - continue; - else { - rc = FTPERR_FAILED_CONNECT; - freeaddrinfo(res0); - goto errxit; - } - } - data = fdLink(data, "open data (ftpReq)"); - - /* XXX setsockopt SO_LINGER */ - /* XXX setsockopt SO_KEEPALIVE */ - /* XXX setsockopt SO_TOS IPTOS_THROUGHPUT */ - - { - int criterr = 0; - while (connect(fdFileno(data), res->ai_addr, res->ai_addrlen) < 0) { - if (errno == EINTR) - continue; - criterr++; - } - if (criterr) { - if (res->ai_addr) { - fdClose(data); - continue; - } else { - rc = FTPERR_PASSIVE_ERROR; - freeaddrinfo(res0); - goto errxit; - } - } - } - /* success */ - rc = 0; - break; - } - freeaddrinfo(res0); - } - -#else /* HAVE_GETADDRINFO */ - memset(&dataAddress, 0, sizeof(dataAddress)); - dataAddress.sin_family = AF_INET; - dataAddress.sin_port = htons(port); - - if (!inet_aton(remoteIP, &dataAddress.sin_addr)) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - - rc = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); - fdSetFdno(data, (rc >= 0 ? rc : -1)); - if (rc < 0) { - rc = FTPERR_FAILED_CONNECT; - goto errxit; - } - data = fdLink(data, "open data (ftpReq)"); - - /* XXX setsockopt SO_LINGER */ - /* XXX setsockopt SO_KEEPALIVE */ - /* XXX setsockopt SO_TOS IPTOS_THROUGHPUT */ - - while (connect(fdFileno(data), (struct sockaddr *) &dataAddress, - sizeof(dataAddress)) < 0) - { - if (errno == EINTR) - continue; - rc = FTPERR_FAILED_DATA_CONNECT; - goto errxit; - } -#endif /* HAVE_GETADDRINFO */ - -if (_ftp_debug) -fprintf(stderr, "-> %s", cmd); - if (fdWrite(u->ctrl, cmd, cmdlen) != cmdlen) { - rc = FTPERR_SERVER_IO_ERROR; - goto errxit; - } - - if ((rc = ftpCheckResponse(u, NULL))) { - goto errxit; - } - - data->ftpFileDoneNeeded = 1; - u->ctrl = fdLink(u->ctrl, "grab data (ftpReq)"); - u->ctrl = fdLink(u->ctrl, "open data (ftpReq)"); - return 0; - -errxit: - fdSetSyserrno(u->ctrl, errno, ftpStrerror(rc)); - if (fdFileno(data) >= 0) - (void) fdClose(data); - return rc; -} - static rpmCallbackFunction urlNotify = NULL; static void * urlNotifyData = NULL; @@ -1418,48 +701,6 @@ int ufdCopy(FD_t sfd, FD_t tfd) return rc; } -static int urlConnect(const char * url, urlinfo * uret) -{ - urlinfo u; - int rc = 0; - - if (urlSplit(url, &u) < 0) - return -1; - - if (u->urltype == URL_IS_FTP) { - FD_t fd; - - if ((fd = u->ctrl) == NULL) { - fd = u->ctrl = fdNew("persist ctrl (urlConnect FTP)"); - fdSetIo(u->ctrl, ufdio); - } - - fd->rd_timeoutsecs = ftpTimeoutSecs; - fd->contentLength = fd->bytesRemain = -1; - fd->url = NULL; /* XXX FTP ctrl has not */ - fd->ftpFileDoneNeeded = 0; - fd = fdLink(fd, "grab ctrl (urlConnect FTP)"); - - if (fdFileno(u->ctrl) < 0) { - rpmMessage(RPMMESS_DEBUG, _("logging into %s as %s, pw %s\n"), - u->host ? u->host : "???", - u->user ? u->user : "ftp", - u->password ? u->password : "(username)"); - - if ((rc = ftpLogin(u)) < 0) { /* XXX save ftpLogin error */ - u->ctrl = fdFree(fd, "grab ctrl (urlConnect FTP)"); - u->openError = rc; - } - } - } - - if (uret != NULL) - *uret = urlLink(u, "urlConnect"); - u = urlFree(u, "urlSplit (urlConnect)"); - - return rc; -} - int ufdGetFile(FD_t sfd, FD_t tfd) { int rc; @@ -1473,251 +714,6 @@ int ufdGetFile(FD_t sfd, FD_t tfd) return rc; } -int ftpCmd(const char * cmd, const char * url, const char * arg2) -{ - urlinfo u; - int rc; - const char * path; - - if (urlConnect(url, &u) < 0) - return -1; - - (void) urlPath(url, &path); - - rc = ftpCommand(u, NULL, cmd, path, arg2, NULL); - u->ctrl = fdFree(u->ctrl, "grab ctrl (ftpCmd)"); - return rc; -} - -/* XXX these aren't worth the pain of including correctly */ -#if !defined(IAC) -#define IAC 255 /* interpret as command: */ -#endif -#if !defined(IP) -#define IP 244 /* interrupt process--permanently */ -#endif -#if !defined(DM) -#define DM 242 /* data mark--for connect. cleaning */ -#endif -#if !defined(SHUT_RDWR) -#define SHUT_RDWR 1+1 -#endif - -static int ftpAbort(urlinfo u, FD_t data) -{ - static unsigned char ipbuf[3] = { IAC, IP, IAC }; - FD_t ctrl; - int rc; - int tosecs; - - URLSANE(u); - - if (data != NULL) { - data->ftpFileDoneNeeded = 0; - if (fdFileno(data) >= 0) - u->ctrl = fdFree(u->ctrl, "open data (ftpAbort)"); - u->ctrl = fdFree(u->ctrl, "grab data (ftpAbort)"); - } - ctrl = u->ctrl; - - DBGIO(0, (stderr, "-> ABOR\n")); - - if (send(fdFileno(ctrl), ipbuf, sizeof(ipbuf), MSG_OOB) != sizeof(ipbuf)) { - (void) fdClose(ctrl); - return FTPERR_SERVER_IO_ERROR; - } - - sprintf(u->buf, "%cABOR\r\n",(char) DM); - if (fdWrite(ctrl, u->buf, 7) != 7) { - (void) fdClose(ctrl); - return FTPERR_SERVER_IO_ERROR; - } - - if (data && fdFileno(data) >= 0) { - /* XXX shorten data drain time wait */ - tosecs = data->rd_timeoutsecs; - data->rd_timeoutsecs = 10; - if (fdReadable(data, data->rd_timeoutsecs) > 0) { - while (timedRead(data, u->buf, u->bufAlloced) > 0) - u->buf[0] = '\0'; - } - data->rd_timeoutsecs = tosecs; - /* XXX ftp abort needs to close the data channel to receive status */ - (void) shutdown(fdFileno(data), SHUT_RDWR); - (void) close(fdFileno(data)); - data->fps[0].fdno = -1; /* XXX WRONG but expedient */ - } - - /* XXX shorten ctrl drain time wait */ - tosecs = u->ctrl->rd_timeoutsecs; - u->ctrl->rd_timeoutsecs = 10; - if ((rc = ftpCheckResponse(u, NULL)) == FTPERR_NIC_ABORT_IN_PROGRESS) { - rc = ftpCheckResponse(u, NULL); - } - rc = ftpCheckResponse(u, NULL); - u->ctrl->rd_timeoutsecs = tosecs; - - return rc; -} - -static int ftpFileDone(urlinfo u, FD_t data) -{ - int rc = 0; - - URLSANE(u); - assert(data->ftpFileDoneNeeded); - - if (data->ftpFileDoneNeeded) { - data->ftpFileDoneNeeded = 0; - u->ctrl = fdFree(u->ctrl, "open data (ftpFileDone)"); - u->ctrl = fdFree(u->ctrl, "grab data (ftpFileDone)"); - rc = ftpCheckResponse(u, NULL); - } - return rc; -} - -static int httpResp(urlinfo u, FD_t ctrl, char ** str) -{ - int ec = 0; - int rc; - - URLSANE(u); - rc = checkResponse(u, ctrl, &ec, str); - -if (_ftp_debug && !(rc == 0 && (ec == 200 || ec == 201))) -fprintf(stderr, "*** httpResp: rc %d ec %d\n", rc, ec); - - switch (ec) { - case 200: - case 201: /* 201 Created. */ - break; - case 204: /* HACK: if overwriting, 204 No Content. */ - case 403: /* 403 Forbidden. */ - ctrl->syserrno = EACCES; /* HACK */ - rc = FTPERR_UNKNOWN; - break; - default: - rc = FTPERR_FILE_NOT_FOUND; - break; - } - return rc; -} - -static int httpReq(FD_t ctrl, const char * httpCmd, const char * httpArg) -{ - urlinfo u; - const char * host; - const char * path; - char hthost[NI_MAXHOST]; - int port; - int rc; - char * req; - size_t len; - int retrying = 0; - -assert(ctrl != NULL); - u = ctrl->url; - URLSANE(u); - - if (((host = (u->proxyh ? u->proxyh : u->host)) == NULL)) - return FTPERR_BAD_HOSTNAME; - if (strchr(host, ':')) - sprintf(hthost, "[%s]", host); - else - strcpy(hthost, host); - - if ((port = (u->proxyp > 0 ? u->proxyp : u->port)) < 0) port = 80; - path = (u->proxyh || u->proxyp > 0) ? u->url : httpArg; - if (path == NULL) path = ""; - -reopen: - if (fdFileno(ctrl) >= 0 && (rc = fdWritable(ctrl, 0)) < 1) { - (void) fdClose(ctrl); - } - - if (fdFileno(ctrl) < 0) { - rc = tcpConnect(ctrl, host, port); - if (rc < 0) - goto errxit2; - ctrl = fdLink(ctrl, "open ctrl (httpReq)"); - } - - len = sizeof("\ -req x HTTP/1.0\r\n\ -User-Agent: rpm/3.0.4\r\n\ -Host: y:z\r\n\ -Accept: text/plain\r\n\ -Transfer-Encoding: chunked\r\n\ -\r\n\ -") + strlen(httpCmd) + strlen(path) + sizeof(VERSION) + strlen(hthost) + 20; - - req = alloca(len); - *req = '\0'; - - if (!strcmp(httpCmd, "PUT")) { - sprintf(req, "\ -%s %s HTTP/1.%d\r\n\ -User-Agent: rpm/%s\r\n\ -Host: %s:%d\r\n\ -Accept: text/plain\r\n\ -Transfer-Encoding: chunked\r\n\ -\r\n\ -", httpCmd, path, (u->httpVersion ? 1 : 0), VERSION, hthost, port); -} else { - sprintf(req, "\ -%s %s HTTP/1.%d\r\n\ -User-Agent: rpm/%s\r\n\ -Host: %s:%d\r\n\ -Accept: text/plain\r\n\ -\r\n\ -", httpCmd, path, (u->httpVersion ? 1 : 0), VERSION, hthost, port); -} - -if (_ftp_debug) -fprintf(stderr, "-> %s", req); - - len = strlen(req); - if (fdWrite(ctrl, req, len) != len) { - rc = FTPERR_SERVER_IO_ERROR; - goto errxit; - } - - if (!strcmp(httpCmd, "PUT")) { - ctrl->wr_chunked = 1; - } else { - - rc = httpResp(u, ctrl, NULL); - - if (rc) { - if (!retrying) { /* not HTTP_OK */ - retrying = 1; - (void) fdClose(ctrl); - goto reopen; - } - goto errxit; - } - } - - ctrl = fdLink(ctrl, "open data (httpReq)"); - return 0; - -errxit: - fdSetSyserrno(ctrl, errno, ftpStrerror(rc)); -errxit2: - if (fdFileno(ctrl) >= 0) - (void) fdClose(ctrl); - return rc; -} - -/* XXX DYING: unused */ -void * ufdGetUrlinfo(FD_t fd) -{ - FDSANE(fd); - if (fd->url == NULL) - return NULL; - return urlLink(fd->url, "ufdGetUrlinfo"); -} - /* =============================================================== */ static ssize_t ufdRead(void * cookie, char * buf, size_t count) { @@ -1880,176 +876,59 @@ int ufdClose( void * cookie) fd->url = NULL; u->ctrl = fdFree(u->ctrl, "grab ctrl (ufdClose)"); - if (u->urltype == URL_IS_FTP) { - - /* XXX if not using libio, lose the fp from fpio */ - { FILE * fp; - fp = fdGetFILE(fd); - if (noLibio && fp) - fdSetFp(fd, NULL); - } - - /* - * Non-error FTP has 4 refs on the data fd: - * "persist data (ufdOpen FTP)" rpmio.c:888 - * "grab data (ufdOpen FTP)" rpmio.c:892 - * "open data (ftpReq)" ftp.c:633 - * "fopencookie" rpmio.c:1507 - * - * Non-error FTP has 5 refs on the ctrl fd: - * "persist ctrl" url.c:176 - * "grab ctrl (urlConnect FTP)" rpmio.c:404 - * "open ctrl" ftp.c:504 - * "grab data (ftpReq)" ftp.c:661 - * "open data (ftpReq)" ftp.c:662 - */ - if (fd->bytesRemain > 0) { - if (fd->ftpFileDoneNeeded) { - if (fdReadable(u->ctrl, 0) > 0) - (void) ftpFileDone(u, fd); - else - (void) ftpAbort(u, fd); - } - } else { - int rc; - /* XXX STOR et al require close before ftpFileDone */ - rc = fdClose(fd); -#if 0 /* XXX error exit from ufdOpen does not have this set */ - assert(fd->ftpFileDoneNeeded != 0); -#endif - /* FIX: u->data undefined */ - if (fd->ftpFileDoneNeeded) - (void) ftpFileDone(u, fd); - return rc; - } - } - - /* XXX Why not (u->urltype == URL_IS_HTTP) ??? */ - /* XXX Why not (u->urltype == URL_IS_HTTPS) ??? */ - /* XXX Why not (u->urltype == URL_IS_HKP) ??? */ - if (u->scheme != NULL - && (!strncmp(u->scheme, "http", sizeof("http")-1) || !strncmp(u->scheme, "hkp", sizeof("hkp")-1))) - { - /* - * HTTP has 4 (or 5 if persistent malloc) refs on the fd: - * "persist ctrl" url.c:177 - * "grab ctrl (ufdOpen HTTP)" rpmio.c:924 - * "grab data (ufdOpen HTTP)" rpmio.c:928 - * "open ctrl (httpReq)" ftp.c:382 - * "open data (httpReq)" ftp.c:435 - */ - - if (fd == u->ctrl) - fd = u->ctrl = fdFree(fd, "open data (ufdClose HTTP persist ctrl)"); - else if (fd == u->data) - fd = u->data = fdFree(fd, "open data (ufdClose HTTP persist data)"); - else - fd = fdFree(fd, "open data (ufdClose HTTP)"); - - /* XXX if not using libio, lose the fp from fpio */ - { FILE * fp; - fp = fdGetFILE(fd); - if (noLibio && fp) - fdSetFp(fd, NULL); - } - - /* If content remains, then don't persist. */ - if (fd->bytesRemain > 0) - fd->persist = 0; - fd->contentLength = fd->bytesRemain = -1; - - /* If persisting, then Fclose will juggle refcounts. */ - if (fd->persist && (fd == u->ctrl || fd == u->data)) - return 0; - } } return fdClose(fd); } -FD_t ftpOpen(const char *url, int flags, - mode_t mode, urlinfo *uret) +/* + * Deal with remote url's by fetching them with a helper application + * and treat as local file afterwards. + * TODO: + * - better error checking + reporting + * - curl & friends don't know about hkp://, transform to http? + */ +static FD_t urlOpen(const char * url, int flags, mode_t mode) { - urlinfo u = NULL; FD_t fd = NULL; + char cmd[BUFSIZ]; + char *dest = NULL; + char *urlhelper = NULL; + int rc; + pid_t pid, wait; -#if 0 /* XXX makeTempFile() heartburn */ - assert(!(flags & O_RDWR)); -#endif - if (urlConnect(url, &u) < 0) - goto exit; - - if (u->data == NULL) - u->data = fdNew("persist data (ftpOpen)"); + urlhelper = rpmExpand("%{?_urlhelper}", NULL); - if (u->data->url == NULL) - fd = fdLink(u->data, "grab data (ftpOpen persist data)"); - else - fd = fdNew("grab data (ftpOpen)"); + dest = (char *) rpmGenPath(NULL, "%{_tmppath}/", "rpm-transfer.XXXXXX"); + close(mkstemp(dest)); + sprintf(cmd, "%s %s %s\n", urlhelper, dest, url); + urlhelper = _free(urlhelper); - if (fd) { - fdSetIo(fd, ufdio); - fd->ftpFileDoneNeeded = 0; - fd->rd_timeoutsecs = ftpTimeoutSecs; - fd->contentLength = fd->bytesRemain = -1; - fd->url = urlLink(u, "url (ufdOpen FTP)"); - fd->urlType = URL_IS_FTP; + if ((pid = fork()) == 0) { + ARGV_t argv = NULL; + argvSplit(&argv, cmd, " "); + execvp(argv[0], (char *const *)argv); + exit(-1); /* error out if exec fails */ } + wait = waitpid(pid, &rc, 0); -exit: - if (uret) - *uret = u; - return fd; -} - -#ifndef WITH_NEON - /* FIX: u->{ctrl,data}->url undef after XurlLink. */ -static FD_t httpOpen(const char * url, int flags, - mode_t mode, urlinfo * uret) -{ - urlinfo u = NULL; - FD_t fd = NULL; - -#if 0 /* XXX makeTempFile() heartburn */ - assert(!(flags & O_RDWR)); -#endif - if (urlSplit(url, &u)) - goto exit; - - if (u->ctrl == NULL) - u->ctrl = fdNew("persist ctrl (httpOpen)"); - if (u->ctrl->nrefs > 2 && u->data == NULL) - u->data = fdNew("persist data (httpOpen)"); - - if (u->ctrl->url == NULL) - fd = fdLink(u->ctrl, "grab ctrl (httpOpen persist ctrl)"); - else if (u->data->url == NULL) - fd = fdLink(u->data, "grab ctrl (httpOpen persist data)"); - else - fd = fdNew("grab ctrl (httpOpen)"); - - if (fd) { - fdSetIo(fd, ufdio); - fd->ftpFileDoneNeeded = 0; - fd->rd_timeoutsecs = httpTimeoutSecs; - fd->contentLength = fd->bytesRemain = -1; - fd->url = urlLink(u, "url (httpOpen)"); - fd = fdLink(fd, "grab data (httpOpen)"); - fd->urlType = URL_IS_HTTP; + if (!WIFEXITED(rc) || WEXITSTATUS(rc)) { + rpmError(RPMERR_EXEC, _("URL helper failed: %s (%d)\n"), + cmd, WEXITSTATUS(rc)); + } else { + fd = fdOpen(dest, flags, mode); + unlink(dest); } + dest = _free(dest); -exit: - if (uret) - *uret = u; return fd; + } -#endif static FD_t ufdOpen(const char * url, int flags, mode_t mode) { FD_t fd = NULL; - const char * cmd; - urlinfo u; const char * path; + int timeout = 1; urltype urlType = urlPath(url, &path); if (_rpmio_debug) @@ -2057,79 +936,32 @@ fprintf(stderr, "*** ufdOpen(%s,0x%x,0%o)\n", url, (unsigned)flags, (unsigned)mo switch (urlType) { case URL_IS_FTP: - fd = ftpOpen(url, flags, mode, &u); - if (fd == NULL || u == NULL) - break; - - /* XXX W2DO? use STOU rather than STOR to prevent clobbering */ - cmd = ((flags & O_WRONLY) - ? ((flags & O_APPEND) ? "APPE" : - ((flags & O_CREAT) ? "STOR" : "STOR")) - : ((flags & O_CREAT) ? "STOR" : "RETR")); - u->openError = ftpReq(fd, cmd, path); - if (u->openError < 0) { - /* XXX make sure that we can exit through ufdClose */ - fd = fdLink(fd, "error data (ufdOpen FTP)"); - } else { - fd->bytesRemain = ((!strcmp(cmd, "RETR")) - ? fd->contentLength : -1); - fd->wr_chunked = 0; - } - break; case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_HKP: -#ifdef WITH_NEON - fd = davOpen(url, flags, mode, &u); -#else - fd = httpOpen(url, flags, mode, &u); -#endif - if (fd == NULL || u == NULL) - break; - - cmd = ((flags & O_WRONLY) - ? ((flags & O_APPEND) ? "PUT" : - ((flags & O_CREAT) ? "PUT" : "PUT")) - : "GET"); -#ifdef WITH_NEON - u->openError = davReq(fd, cmd, path); -#else - u->openError = httpReq(fd, cmd, path); -#endif - if (u->openError < 0) { - /* XXX make sure that we can exit through ufdClose */ - fd = fdLink(fd, "error ctrl (ufdOpen HTTP)"); - fd = fdLink(fd, "error data (ufdOpen HTTP)"); - } else { - fd->bytesRemain = ((!strcmp(cmd, "GET")) - ? fd->contentLength : -1); - fd->wr_chunked = ((!strcmp(cmd, "PUT")) - ? fd->wr_chunked : 0); - } + fd = urlOpen(url, flags, mode); + /* we're dealing with local file when urlOpen() returns */ + urlType = URL_IS_UNKNOWN; break; case URL_IS_DASH: assert(!(flags & O_RDWR)); fd = fdDup( ((flags & O_WRONLY) ? STDOUT_FILENO : STDIN_FILENO) ); - if (fd) { - fdSetIo(fd, ufdio); - fd->rd_timeoutsecs = 600; /* XXX W2DO? 10 mins? */ - fd->contentLength = fd->bytesRemain = -1; - } + timeout = 600; /* XXX W2DO? 10 mins? */ break; case URL_IS_PATH: case URL_IS_UNKNOWN: default: fd = fdOpen(path, flags, mode); - if (fd) { - fdSetIo(fd, ufdio); - fd->rd_timeoutsecs = 1; - fd->contentLength = fd->bytesRemain = -1; - } break; } if (fd == NULL) return NULL; + + fdSetIo(fd, ufdio); + fd->rd_timeoutsecs = timeout; + fd->contentLength = fd->bytesRemain = -1; fd->urlType = urlType; + if (Fileno(fd) < 0) { (void) ufdClose(fd); return NULL; @@ -2632,46 +1464,11 @@ DBGIO(fd, (stderr, "==> Fclose(%p) %s\n", (fd ? fd : NULL), fdbg(fd))); fp = fdGetFILE(fd); fpno = fileno(fp); - /* XXX persistent HTTP/1.1 returns the previously opened fp */ - if (fd->nfps > 0 && fpno == -1 && - fd->fps[fd->nfps-1].io == ufdio && - fd->fps[fd->nfps-1].fp == fp && - (fd->fps[fd->nfps-1].fdno >= 0 || fd->req != NULL)) - { - int hadreqpersist = (fd->req != NULL); - - if (fp) - rc = fflush(fp); - fd->nfps--; - rc = ufdClose(fd); - if (fdGetFdno(fd) >= 0) - break; - if (!fd->persist) - hadreqpersist = 0; - fdSetFp(fd, NULL); - fd->nfps++; - if (fp) { - /* HACK: flimsy Keepalive wiring. */ - if (hadreqpersist) { - fd->nfps--; - fdSetFp(fd, fp); - (void) fdClose(fd); - fdSetFp(fd, NULL); - fd->nfps++; - (void) fdClose(fd); - } else - rc = fclose(fp); - } - fdPop(fd); - if (noLibio) - fdSetFp(fd, NULL); - } else { - if (fp) - rc = fclose(fp); - if (fpno == -1) { - fd = fdFree(fd, "fopencookie (Fclose)"); - fdPop(fd); - } + if (fp) + rc = fclose(fp); + if (fpno == -1) { + fd = fdFree(fd, "fopencookie (Fclose)"); + fdPop(fd); } } else { fdio_close_function_t _close = FDIOVEC(fd, close); @@ -2882,17 +1679,12 @@ fprintf(stderr, "*** Fopen fdio path %s fmode %s\n", path, fmode); return NULL; } } else { - FILE *fp; - int fdno; - int isHTTP = 0; - /* XXX gzdio and bzdio here too */ switch (urlIsURL(path)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_HKP: - isHTTP = 1; case URL_IS_PATH: case URL_IS_DASH: case URL_IS_FTP: @@ -2910,12 +1702,6 @@ fprintf(stderr, "*** Fopen WTFO path %s fmode %s\n", path, fmode); break; } - /* XXX persistent HTTP/1.1 returns the previously opened fp */ - if (isHTTP && ((fp = fdGetFp(fd)) != NULL) && ((fdno = fdGetFdno(fd)) >= 0 || fd->req != NULL)) - { - fdPush(fd, fpio, fp, fileno(fp)); /* Push fpio onto stack */ - return fd; - } } if (fd) @@ -2946,10 +1732,6 @@ int Ferror(FD_t fd) int i, rc = 0; if (fd == NULL) return -1; - if (fd->req != NULL) { - /* HACK: flimsy wiring for neon errors. */ - rc = (fd->syserrno || fd->errcookie != NULL) ? -1 : 0; - } else for (i = fd->nfps; rc == 0 && i >= 0; i--) { FDSTACK_t * fps = &fd->fps[i]; int ec; @@ -2981,9 +1763,6 @@ int Fileno(FD_t fd) int i, rc = -1; if (fd == NULL) return -1; - if (fd->req != NULL) - rc = 123456789; /* HACK: https has no steenkin fileno. */ - else for (i = fd->nfps ; rc == -1 && i >= 0; i--) { rc = fd->fps[i].fdno; } diff --git a/rpmio/rpmio.h b/rpmio/rpmio.h index cb0c40f6e..16ee1a66c 100644 --- a/rpmio/rpmio.h +++ b/rpmio/rpmio.h @@ -440,14 +440,6 @@ const char * ftpStrerror(int errorNumber); /** */ -void * ufdGetUrlinfo(FD_t fd); - -/** - */ -const char * urlStrerror(const char * url); - -/** - */ int ufdCopy(FD_t sfd, FD_t tfd); /** diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h index 2c4befe4d..7c9e0348d 100644 --- a/rpmio/rpmio_internal.h +++ b/rpmio/rpmio_internal.h @@ -169,12 +169,6 @@ struct _FD_s { extern int _rpmio_debug; -extern int _av_debug; - -extern int _ftp_debug; - -extern int _dav_debug; - #define DBG(_f, _m, _x) \ \ if ((_rpmio_debug | ((_f) ? ((FD_t)(_f))->flags : 0)) & (_m)) fprintf _x \ @@ -192,19 +186,6 @@ int fdFgets(FD_t fd, char * buf, size_t len); /** \ingroup rpmio */ -FD_t ftpOpen(const char *url, int flags, - mode_t mode, urlinfo *uret); - -/** \ingroup rpmio - */ -int ftpReq(FD_t data, const char * ftpCmd, const char * ftpArg); - -/** \ingroup rpmio - */ -int ftpCmd(const char * cmd, const char * url, const char * arg2); - -/** \ingroup rpmio - */ int ufdClose( void * cookie); /** \ingroup rpmio diff --git a/rpmio/rpmrpc.c b/rpmio/rpmrpc.c index 06eb36ef3..228562cfb 100644 --- a/rpmio/rpmrpc.c +++ b/rpmio/rpmrpc.c @@ -10,9 +10,6 @@ #include <rpmio_internal.h> -#define _RPMDAV_INTERNAL -#include <rpmdav.h> - #include "ugid.h" #include "debug.h" diff --git a/rpmio/rpmurl.h b/rpmio/rpmurl.h index d100636ea..e31103615 100644 --- a/rpmio/rpmurl.h +++ b/rpmio/rpmurl.h @@ -44,21 +44,6 @@ int nrefs; /*!< no. of references */ FD_t ctrl; /*!< control channel */ FD_t data; /*!< per-xfer data channel */ - void * capabilities; /*!< neon: ne_server_capabilities ptr */ - void * lockstore; /*!< neon: ne_lock_store ptr */ - void * sess; /*!< neon: ne_session ptr */ - off_t current; /*!< neon: current body offset. */ - off_t total; /*!< neon: total body length. */ - int connstatus; /*!< neon: connection status. */ -#ifdef REFERENCE -typedef enum { - ne_conn_namelookup, /* lookup up hostname (info = hostname) */ - ne_conn_connecting, /* connecting to host (info = hostname) */ - ne_conn_connected, /* connected to host (info = hostname) */ - ne_conn_secure /* connection now secure (info = crypto level) */ -} ne_conn_status; -#endif - int bufAlloced; /*!< sizeof I/O buffer */ char * buf; /*!< I/O buffer */ int openError; /*!< Type of open failure */ diff --git a/rpmio/tdir.c b/rpmio/tdir.c index e909afffc..d1b34591c 100644 --- a/rpmio/tdir.c +++ b/rpmio/tdir.c @@ -39,8 +39,6 @@ dp->d_name); static struct poptOption optionsTable[] = { { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL }, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, @@ -71,9 +69,6 @@ main(int argc, const char *argv[]) rpmIncreaseVerbosity(); } -_av_debug = -1; -_ftp_debug = -1; -_dav_debug = -1; printDir(dirpath); printDir(ftppath); printDir(httppath); diff --git a/rpmio/tfts.c b/rpmio/tfts.c index 6a1ecbf03..d89cafe7a 100644 --- a/rpmio/tfts.c +++ b/rpmio/tfts.c @@ -131,8 +131,6 @@ static struct poptOption optionsTable[] = { { "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT, N_("return whiteout information"), NULL }, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, @@ -161,9 +159,6 @@ main(int argc, const char *argv[]) if (ftsOpts == 0) ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT); -_av_debug = -1; -_ftp_debug = -1; -_dav_debug = 1; #if 0 ftsWalk(dirpath); ftsWalk(ftppath); diff --git a/rpmio/tget.c b/rpmio/tget.c index eb412e9fb..ab7fbd603 100644 --- a/rpmio/tget.c +++ b/rpmio/tget.c @@ -9,8 +9,6 @@ static int _debug = 0; -int noNeon; - #define HTTPSPATH "https://localhost/test.txt" #define HTTPPATH "http://localhost/test.txt" #define FTPPATH "ftp://localhost/test.txt" @@ -38,10 +36,6 @@ fprintf(stderr, "===== %s\n", path); static struct poptOption optionsTable[] = { { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL }, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, - { "noneon", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noNeon, 1, - N_("disable use of libneon for HTTP"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, @@ -72,9 +66,6 @@ main(int argc, const char *argv[]) rpmIncreaseVerbosity(); } -_av_debug = -1; -_ftp_debug = -1; -_dav_debug = 1; #if 1 readFile(dirpath); #endif diff --git a/rpmio/tglob.c b/rpmio/tglob.c index b5554b052..8a5aa3e23 100644 --- a/rpmio/tglob.c +++ b/rpmio/tglob.c @@ -9,8 +9,6 @@ static int _debug = 0; -int noNeon; - #define HTTPSPATH "https://localhost/rawhide/test/*.rpm" #if 0 #define HTTPPATH "http://localhost/rawhide/test/*.rpm" @@ -52,10 +50,6 @@ fprintf(stderr, "*** Glob rc %d\n", rc); static struct poptOption optionsTable[] = { { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL }, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, - { "noneon", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noNeon, 1, - N_("disable use of libneon for HTTP"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, @@ -86,9 +80,6 @@ main(int argc, const char *argv[]) rpmIncreaseVerbosity(); } -_av_debug = -1; -_ftp_debug = -1; -_dav_debug = -1; #if 0 printGlob(dirpath); printGlob(ftppath); diff --git a/rpmio/thkp.c b/rpmio/thkp.c index 57fb4cfe0..267604cd7 100644 --- a/rpmio/thkp.c +++ b/rpmio/thkp.c @@ -10,8 +10,6 @@ static int _debug = 0; static int _printing = 0; -int noNeon; - #if 0 #define HKPPATH "hkp://pgp.mit.edu:11371/pks/lookup?op=get&search=0xF5C75256" #else @@ -91,12 +89,6 @@ static struct poptOption optionsTable[] = { { "print", 'p', POPT_ARG_VAL, &_printing, 1, NULL, NULL }, { "noprint", 'n', POPT_ARG_VAL, &_printing, 0, NULL, NULL }, { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL }, - { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1, - N_("debug protocol data stream"), NULL}, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, - { "noneon", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noNeon, 1, - N_("disable use of libneon for HTTP"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, diff --git a/rpmio/tput.c b/rpmio/tput.c index 244a6d7d8..fbbe74bea 100644 --- a/rpmio/tput.c +++ b/rpmio/tput.c @@ -9,8 +9,6 @@ static int _debug = 0; -int noNeon; - #define HTTPSPATH "https://localhost/rawhide/toad/tput.txt" #define HTTPPATH "http://localhost/rawhide/toad/tput.txt" #define FTPPATH "ftp://localhost/home/test/tput.txt" @@ -98,10 +96,6 @@ fprintf(stderr, "===== %s\n", path); static struct poptOption optionsTable[] = { { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL }, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, - { "noneon", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noNeon, 1, - N_("disable use of libneon for HTTP"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, @@ -132,9 +126,6 @@ main(int argc, const char *argv[]) rpmIncreaseVerbosity(); } -_av_debug = -1; -_ftp_debug = -1; -_dav_debug = -1; #if 0 doFile(dirpath); doFile(ftppath); diff --git a/rpmio/tring.c b/rpmio/tring.c index 7b3d31349..05649e324 100644 --- a/rpmio/tring.c +++ b/rpmio/tring.c @@ -11,10 +11,6 @@ static struct poptOption optionsTable[] = { { "print", 'p', POPT_ARG_VAL, &printing, 1, NULL, NULL }, { "noprint", 'n', POPT_ARG_VAL, &printing, 0, NULL, NULL }, { "debug", 'd', POPT_ARG_VAL, &_debug, -1, NULL, NULL }, - { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1, - N_("debug protocol data stream"), NULL}, - { "noneon", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noNeon, 1, - N_("disable use of libneon for HTTP"), NULL}, { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1, N_("debug rpmio I/O"), NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, diff --git a/rpmio/url.c b/rpmio/url.c index 6a647a7c0..f4ab25a65 100644 --- a/rpmio/url.c +++ b/rpmio/url.c @@ -130,13 +130,6 @@ URLDBGREFS(0, (stderr, "--> url %p -- %d %s at %s:%u\n", u, u->nrefs, msg, file, u, u->data, (u->host ? u->host : ""), (u->scheme ? u->scheme : "")); } - if (u->sess != NULL) { -#ifdef WITH_NEON - /* HACK: neon include has prototype. */ - ne_session_destroy(u->sess); -#endif - u->sess = NULL; - } u->buf = _free(u->buf); u->url = _free(u->url); u->scheme = _free((void *)u->scheme); @@ -240,77 +233,6 @@ static void urlFind(urlinfo * uret, int mustAsk) u->proxyp = -1; u->proxyh = _free(u->proxyh); - /* Perform one-time FTP initialization */ - if (u->urltype == URL_IS_FTP) { - - if (mustAsk || (u->user != NULL && u->password == NULL)) { - const char * host = (u->host ? u->host : ""); - const char * user = (u->user ? u->user : ""); - char * prompt; - prompt = alloca(strlen(host) + strlen(user) + 256); - sprintf(prompt, _("Password for %s@%s: "), user, host); - u->password = _free(u->password); - u->password = getpass(prompt); - if (u->password) - u->password = xstrdup(u->password); - } - - if (u->proxyh == NULL) { - const char *proxy = rpmExpand("%{_ftpproxy}", NULL); - if (proxy && *proxy != '%') { - const char * host = (u->host ? u->host : ""); - const char *uu = (u->user ? u->user : "anonymous"); - char *nu = xmalloc(strlen(uu) + sizeof("@") + strlen(host)); - (void) stpcpy( stpcpy( stpcpy(nu, uu), "@"), host); - u->proxyu = nu; - u->proxyh = xstrdup(proxy); - } - proxy = _free(proxy); - } - - if (u->proxyp < 0) { - const char *proxy = rpmExpand("%{_ftpport}", NULL); - if (proxy && *proxy != '%') { - char *end = NULL; - int port = strtol(proxy, &end, 0); - if (!(end && *end == '\0')) { - fprintf(stderr, _("error: %sport must be a number\n"), - (u->scheme ? u->scheme : "")); - return; - } - u->proxyp = port; - } - proxy = _free(proxy); - } - } - - /* Perform one-time HTTP initialization */ - if (u->urltype == URL_IS_HTTP || u->urltype == URL_IS_HTTPS || u->urltype == URL_IS_HKP) { - - if (u->proxyh == NULL) { - const char *proxy = rpmExpand("%{_httpproxy}", NULL); - if (proxy && *proxy != '%') - u->proxyh = xstrdup(proxy); - proxy = _free(proxy); - } - - if (u->proxyp < 0) { - const char *proxy = rpmExpand("%{_httpport}", NULL); - if (proxy && *proxy != '%') { - char *end; - int port = strtol(proxy, &end, 0); - if (!(end && *end == '\0')) { - fprintf(stderr, _("error: %sport must be a number\n"), - (u->scheme ? u->scheme : "")); - return; - } - u->proxyp = port; - } - proxy = _free(proxy); - } - - } - return; } diff --git a/tests/Makefile.am b/tests/Makefile.am index dbf756e9a..af7f3de3e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -113,7 +113,7 @@ check_DATA += testing$(rpmconfigdir)/macros check_DATA += testing$(rpmconfigdir)/rpmpopt-@VERSION@ check-local: $(check_DATA) - $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) + $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) ||: installcheck-local: $(check_DATA) $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \ |