Commit 531fea4c authored by Timo Teräs's avatar Timo Teräs

libfetch: remove unwanted code conditionals

parent f6860e0e
CFLAGS_ALL += -DINET6 -DWITH_SSL -DFTP_COMBINE_CWDS
libs-y += libfetch.a libs-y += libfetch.a
libfetch.a-objs := common.o fetch.o file.o ftp.o http.o libfetch.a-objs := common.o fetch.o file.o ftp.o http.o
generate-y += ftperr.h httperr.h generate-y += ftperr.h httperr.h
......
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
* $FreeBSD: common.c,v 1.53 2007/12/19 00:26:36 des Exp $ * $FreeBSD: common.c,v 1.53 2007/12/19 00:26:36 des Exp $
*/ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <poll.h> #include <poll.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -53,10 +49,6 @@ ...@@ -53,10 +49,6 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifndef MSG_NOSIGNAL
#include <signal.h>
#endif
#include "fetch.h" #include "fetch.h"
#include "common.h" #include "common.h"
...@@ -66,9 +58,7 @@ ...@@ -66,9 +58,7 @@
* Error messages for resolver errors * Error messages for resolver errors
*/ */
static struct fetcherr netdb_errlist[] = { static struct fetcherr netdb_errlist[] = {
#ifdef EAI_NODATA
{ EAI_NODATA, FETCH_RESOLV, "Host not found" }, { EAI_NODATA, FETCH_RESOLV, "Host not found" },
#endif
{ EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" }, { EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" },
{ EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" }, { EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" },
{ EAI_NONAME, FETCH_RESOLV, "No address record" }, { EAI_NONAME, FETCH_RESOLV, "No address record" },
...@@ -156,7 +146,7 @@ fetch_syserr(void) ...@@ -156,7 +146,7 @@ fetch_syserr(void)
case EHOSTDOWN: case EHOSTDOWN:
fetchLastErrCode = FETCH_DOWN; fetchLastErrCode = FETCH_DOWN;
break; break;
default: default:
fetchLastErrCode = FETCH_UNKNOWN; fetchLastErrCode = FETCH_UNKNOWN;
} }
snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(errno)); snprintf(fetchLastErrString, MAXERRSTRING, "%s", strerror(errno));
...@@ -425,8 +415,6 @@ fetch_cache_put(conn_t *conn, int (*closecb)(conn_t *)) ...@@ -425,8 +415,6 @@ fetch_cache_put(conn_t *conn, int (*closecb)(conn_t *))
int int
fetch_ssl(conn_t *conn, const struct url *URL, int verbose) fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
{ {
#ifdef WITH_SSL
/* Init the SSL library and context */ /* Init the SSL library and context */
if (!SSL_library_init()){ if (!SSL_library_init()){
fprintf(stderr, "SSL library init failed\n"); fprintf(stderr, "SSL library init failed\n");
...@@ -446,14 +434,13 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose) ...@@ -446,14 +434,13 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
} }
conn->buf_events = 0; conn->buf_events = 0;
SSL_set_fd(conn->ssl, conn->sd); SSL_set_fd(conn->ssl, conn->sd);
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
if (!SSL_set_tlsext_host_name(conn->ssl, (char *)(uintptr_t)URL->host)) { if (!SSL_set_tlsext_host_name(conn->ssl, (char *)(uintptr_t)URL->host)) {
fprintf(stderr, fprintf(stderr,
"TLS server name indication extension failed for host %s\n", "TLS server name indication extension failed for host %s\n",
URL->host); URL->host);
return (-1); return (-1);
} }
#endif
if (SSL_connect(conn->ssl) == -1){ if (SSL_connect(conn->ssl) == -1){
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
return (-1); return (-1);
...@@ -477,12 +464,6 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose) ...@@ -477,12 +464,6 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
} }
return (0); return (0);
#else
(void)conn;
(void)verbose;
fprintf(stderr, "SSL support disabled\n");
return (-1);
#endif
} }
static int static int
...@@ -546,7 +527,7 @@ fetch_read(conn_t *conn, char *buf, size_t len) ...@@ -546,7 +527,7 @@ fetch_read(conn_t *conn, char *buf, size_t len)
} }
} while (pfd.revents == 0); } while (pfd.revents == 0);
} }
#ifdef WITH_SSL
if (conn->ssl != NULL) { if (conn->ssl != NULL) {
rlen = SSL_read(conn->ssl, buf, len); rlen = SSL_read(conn->ssl, buf, len);
if (rlen == -1) { if (rlen == -1) {
...@@ -566,9 +547,9 @@ fetch_read(conn_t *conn, char *buf, size_t len) ...@@ -566,9 +547,9 @@ fetch_read(conn_t *conn, char *buf, size_t len)
/* Assume buffering on the SSL layer. */ /* Assume buffering on the SSL layer. */
conn->buf_events = 0; conn->buf_events = 0;
} }
} else } else {
#endif
rlen = read(conn->sd, buf, len); rlen = read(conn->sd, buf, len);
}
if (rlen >= 0) if (rlen >= 0)
break; break;
...@@ -655,17 +636,6 @@ fetch_write(conn_t *conn, const void *buf, size_t len) ...@@ -655,17 +636,6 @@ fetch_write(conn_t *conn, const void *buf, size_t len)
fd_set writefds; fd_set writefds;
ssize_t wlen, total; ssize_t wlen, total;
int r; int r;
#ifndef MSG_NOSIGNAL
static int killed_sigpipe;
#endif
#ifndef MSG_NOSIGNAL
if (!killed_sigpipe) {
signal(SIGPIPE, SIG_IGN);
killed_sigpipe = 1;
}
#endif
if (fetchTimeout) { if (fetchTimeout) {
FD_ZERO(&writefds); FD_ZERO(&writefds);
...@@ -698,16 +668,10 @@ fetch_write(conn_t *conn, const void *buf, size_t len) ...@@ -698,16 +668,10 @@ fetch_write(conn_t *conn, const void *buf, size_t len)
} }
} }
errno = 0; errno = 0;
#ifdef WITH_SSL
if (conn->ssl != NULL) if (conn->ssl != NULL)
wlen = SSL_write(conn->ssl, buf, len); wlen = SSL_write(conn->ssl, buf, len);
else else
#endif
#ifndef MSG_NOSIGNAL
wlen = send(conn->sd, buf, len, 0);
#else
wlen = send(conn->sd, buf, len, MSG_NOSIGNAL); wlen = send(conn->sd, buf, len, MSG_NOSIGNAL);
#endif
if (wlen == 0) { if (wlen == 0) {
/* we consider a short write a failure */ /* we consider a short write a failure */
errno = EPIPE; errno = EPIPE;
...@@ -735,7 +699,6 @@ fetch_close(conn_t *conn) ...@@ -735,7 +699,6 @@ fetch_close(conn_t *conn)
{ {
int ret; int ret;
#ifdef WITH_SSL
if (conn->ssl) { if (conn->ssl) {
SSL_shutdown(conn->ssl); SSL_shutdown(conn->ssl);
SSL_set_connect_state(conn->ssl); SSL_set_connect_state(conn->ssl);
...@@ -747,7 +710,6 @@ fetch_close(conn_t *conn) ...@@ -747,7 +710,6 @@ fetch_close(conn_t *conn)
if (conn->ssl_cert) { if (conn->ssl_cert) {
X509_free(conn->ssl_cert); X509_free(conn->ssl_cert);
} }
#endif
ret = close(conn->sd); ret = close(conn->sd);
if (conn->cache_url) if (conn->cache_url)
......
...@@ -37,13 +37,11 @@ ...@@ -37,13 +37,11 @@
#define FTP_DEFAULT_PROXY_PORT 21 #define FTP_DEFAULT_PROXY_PORT 21
#define HTTP_DEFAULT_PROXY_PORT 3128 #define HTTP_DEFAULT_PROXY_PORT 3128
#ifdef WITH_SSL
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#endif
#if defined(__GNUC__) && __GNUC__ >= 3 #if defined(__GNUC__) && __GNUC__ >= 3
#define LIBFETCH_PRINTFLIKE(fmtarg, firstvararg) \ #define LIBFETCH_PRINTFLIKE(fmtarg, firstvararg) \
...@@ -70,19 +68,11 @@ struct fetchconn { ...@@ -70,19 +68,11 @@ struct fetchconn {
char *next_buf; /* pending buffer, e.g. after getln */ char *next_buf; /* pending buffer, e.g. after getln */
size_t next_len; /* size of pending buffer */ size_t next_len; /* size of pending buffer */
int err; /* last protocol reply code */ int err; /* last protocol reply code */
#ifdef WITH_SSL
SSL *ssl; /* SSL handle */ SSL *ssl; /* SSL handle */
SSL_CTX *ssl_ctx; /* SSL context */ SSL_CTX *ssl_ctx; /* SSL context */
X509 *ssl_cert; /* server certificate */ X509 *ssl_cert; /* server certificate */
# if OPENSSL_VERSION_NUMBER < 0x00909000L
SSL_METHOD *ssl_meth; /* SSL method */
# else
const SSL_METHOD *ssl_meth; /* SSL method */ const SSL_METHOD *ssl_meth; /* SSL method */
# endif
#endif
char *ftp_home; char *ftp_home;
struct url *cache_url; struct url *cache_url;
int cache_af; int cache_af;
int (*cache_close)(conn_t *); int (*cache_close)(conn_t *);
......
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
* $FreeBSD: fetch.c,v 1.41 2007/12/19 00:26:36 des Exp $ * $FreeBSD: fetch.c,v 1.41 2007/12/19 00:26:36 des Exp $
*/ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
...@@ -446,18 +442,17 @@ find_user: ...@@ -446,18 +442,17 @@ find_user:
} }
/* hostname */ /* hostname */
#ifdef INET6
if (*p == '[' && (q = strchr(p + 1, ']')) != NULL && if (*p == '[' && (q = strchr(p + 1, ']')) != NULL &&
(*++q == '\0' || *q == '/' || *q == ':')) { (*++q == '\0' || *q == '/' || *q == ':')) {
if ((i = q - p - 2) > URL_HOSTLEN) if ((i = q - p - 2) > URL_HOSTLEN)
i = URL_HOSTLEN; i = URL_HOSTLEN;
strncpy(u->host, ++p, i); strncpy(u->host, ++p, i);
p = q; p = q;
} else } else {
#endif
for (i = 0; *p && (*p != '/') && (*p != ':'); p++) for (i = 0; *p && (*p != '/') && (*p != ':'); p++)
if (i < URL_HOSTLEN) if (i < URL_HOSTLEN)
u->host[i++] = *p; u->host[i++] = *p;
}
/* port */ /* port */
if (*p == ':') { if (*p == ':') {
......
...@@ -30,12 +30,7 @@ ...@@ -30,12 +30,7 @@
* $FreeBSD: file.c,v 1.18 2007/12/14 10:26:58 des Exp $ * $FreeBSD: file.c,v 1.18 2007/12/14 10:26:58 des Exp $
*/ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#include <fnmatch.h> #include <fnmatch.h>
......
...@@ -57,16 +57,10 @@ ...@@ -57,16 +57,10 @@
* *
*/ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -353,7 +347,6 @@ ftp_cwd(conn_t *conn, const char *path, int subdir) ...@@ -353,7 +347,6 @@ ftp_cwd(conn_t *conn, const char *path, int subdir)
} }
free(pwd); free(pwd);
#ifdef FTP_COMBINE_CWDS
/* Skip leading slashes, even "////". */ /* Skip leading slashes, even "////". */
for (beg = dst + i; beg < end && *beg == '/'; ++beg, ++i) for (beg = dst + i; beg < end && *beg == '/'; ++beg, ++i)
/* nothing */ ; /* nothing */ ;
...@@ -370,7 +363,6 @@ ftp_cwd(conn_t *conn, const char *path, int subdir) ...@@ -370,7 +363,6 @@ ftp_cwd(conn_t *conn, const char *path, int subdir)
free(dst); free(dst);
return (0); return (0);
} }
#endif /* FTP_COMBINE_CWDS */
/* That didn't work so go back to legacy behavior (multiple CWDs). */ /* That didn't work so go back to legacy behavior (multiple CWDs). */
for (beg = dst + i; beg < end; beg = dst + i + 1) { for (beg = dst + i; beg < end; beg = dst + i + 1) {
...@@ -1019,11 +1011,7 @@ ftp_connect(struct url *url, struct url *purl, const char *flags) ...@@ -1019,11 +1011,7 @@ ftp_connect(struct url *url, struct url *purl, const char *flags)
{ {
conn_t *conn; conn_t *conn;
int e, direct, verbose; int e, direct, verbose;
#ifdef INET6
int af = AF_UNSPEC; int af = AF_UNSPEC;
#else
int af = AF_INET;
#endif
direct = CHECK_FLAG('d'); direct = CHECK_FLAG('d');
verbose = CHECK_FLAG('v'); verbose = CHECK_FLAG('v');
......
...@@ -63,16 +63,8 @@ ...@@ -63,16 +63,8 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* Needed for gmtime_r on Interix */
#define _REENTRANT
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
...@@ -702,19 +694,13 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached) ...@@ -702,19 +694,13 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
*cached = 0; *cached = 0;
#ifdef INET6
af = AF_UNSPEC; af = AF_UNSPEC;
#else
af = AF_INET;
#endif
verbose = CHECK_FLAG('v'); verbose = CHECK_FLAG('v');
if (CHECK_FLAG('4')) if (CHECK_FLAG('4'))
af = AF_INET; af = AF_INET;
#ifdef INET6
else if (CHECK_FLAG('6')) else if (CHECK_FLAG('6'))
af = AF_INET6; af = AF_INET6;
#endif
curl = (purl != NULL) ? purl : URL; curl = (purl != NULL) ? purl : URL;
...@@ -887,12 +873,10 @@ http_request(struct url *URL, const char *op, struct url_stat *us, ...@@ -887,12 +873,10 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
goto ouch; goto ouch;
host = url->host; host = url->host;
#ifdef INET6
if (strchr(url->host, ':')) { if (strchr(url->host, ':')) {
snprintf(hbuf, sizeof(hbuf), "[%s]", url->host); snprintf(hbuf, sizeof(hbuf), "[%s]", url->host);
host = hbuf; host = hbuf;
} }
#endif
if (url->port != fetch_default_port(url->scheme)) { if (url->port != fetch_default_port(url->scheme)) {
if (host != hbuf) { if (host != hbuf) {
strcpy(hbuf, host); strcpy(hbuf, host);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment