libfetch: remove unwanted code conditionals

cute-signatures
Timo Teräs 2017-10-05 13:47:36 +03:00
parent f6860e0e11
commit 531fea4c90
7 changed files with 7 additions and 94 deletions

View File

@ -1,4 +1,3 @@
CFLAGS_ALL += -DINET6 -DWITH_SSL -DFTP_COMBINE_CWDS
libs-y += libfetch.a
libfetch.a-objs := common.o fetch.o file.o ftp.o http.o
generate-y += ftperr.h httperr.h

View File

@ -30,10 +30,6 @@
* $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 <sys/types.h>
#include <sys/socket.h>
@ -53,10 +49,6 @@
#include <string.h>
#include <unistd.h>
#ifndef MSG_NOSIGNAL
#include <signal.h>
#endif
#include "fetch.h"
#include "common.h"
@ -66,9 +58,7 @@
* Error messages for resolver errors
*/
static struct fetcherr netdb_errlist[] = {
#ifdef EAI_NODATA
{ EAI_NODATA, FETCH_RESOLV, "Host not found" },
#endif
{ EAI_AGAIN, FETCH_TEMP, "Transient resolver failure" },
{ EAI_FAIL, FETCH_RESOLV, "Non-recoverable resolver failure" },
{ EAI_NONAME, FETCH_RESOLV, "No address record" },
@ -425,8 +415,6 @@ fetch_cache_put(conn_t *conn, int (*closecb)(conn_t *))
int
fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
{
#ifdef WITH_SSL
/* Init the SSL library and context */
if (!SSL_library_init()){
fprintf(stderr, "SSL library init failed\n");
@ -446,14 +434,13 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
}
conn->buf_events = 0;
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)) {
fprintf(stderr,
"TLS server name indication extension failed for host %s\n",
URL->host);
return (-1);
}
#endif
if (SSL_connect(conn->ssl) == -1){
ERR_print_errors_fp(stderr);
return (-1);
@ -477,12 +464,6 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose)
}
return (0);
#else
(void)conn;
(void)verbose;
fprintf(stderr, "SSL support disabled\n");
return (-1);
#endif
}
static int
@ -546,7 +527,7 @@ fetch_read(conn_t *conn, char *buf, size_t len)
}
} while (pfd.revents == 0);
}
#ifdef WITH_SSL
if (conn->ssl != NULL) {
rlen = SSL_read(conn->ssl, buf, len);
if (rlen == -1) {
@ -566,9 +547,9 @@ fetch_read(conn_t *conn, char *buf, size_t len)
/* Assume buffering on the SSL layer. */
conn->buf_events = 0;
}
} else
#endif
} else {
rlen = read(conn->sd, buf, len);
}
if (rlen >= 0)
break;
@ -655,17 +636,6 @@ fetch_write(conn_t *conn, const void *buf, size_t len)
fd_set writefds;
ssize_t wlen, total;
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) {
FD_ZERO(&writefds);
@ -698,16 +668,10 @@ fetch_write(conn_t *conn, const void *buf, size_t len)
}
}
errno = 0;
#ifdef WITH_SSL
if (conn->ssl != NULL)
wlen = SSL_write(conn->ssl, buf, len);
else
#endif
#ifndef MSG_NOSIGNAL
wlen = send(conn->sd, buf, len, 0);
#else
wlen = send(conn->sd, buf, len, MSG_NOSIGNAL);
#endif
if (wlen == 0) {
/* we consider a short write a failure */
errno = EPIPE;
@ -735,7 +699,6 @@ fetch_close(conn_t *conn)
{
int ret;
#ifdef WITH_SSL
if (conn->ssl) {
SSL_shutdown(conn->ssl);
SSL_set_connect_state(conn->ssl);
@ -747,7 +710,6 @@ fetch_close(conn_t *conn)
if (conn->ssl_cert) {
X509_free(conn->ssl_cert);
}
#endif
ret = close(conn->sd);
if (conn->cache_url)

View File

@ -37,13 +37,11 @@
#define FTP_DEFAULT_PROXY_PORT 21
#define HTTP_DEFAULT_PROXY_PORT 3128
#ifdef WITH_SSL
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif
#if defined(__GNUC__) && __GNUC__ >= 3
#define LIBFETCH_PRINTFLIKE(fmtarg, firstvararg) \
@ -70,19 +68,11 @@ struct fetchconn {
char *next_buf; /* pending buffer, e.g. after getln */
size_t next_len; /* size of pending buffer */
int err; /* last protocol reply code */
#ifdef WITH_SSL
SSL *ssl; /* SSL handle */
SSL_CTX *ssl_ctx; /* SSL context */
X509 *ssl_cert; /* server certificate */
# if OPENSSL_VERSION_NUMBER < 0x00909000L
SSL_METHOD *ssl_meth; /* SSL method */
# else
const SSL_METHOD *ssl_meth; /* SSL method */
# endif
#endif
char *ftp_home;
struct url *cache_url;
int cache_af;
int (*cache_close)(conn_t *);

View File

@ -30,10 +30,6 @@
* $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 <errno.h>
#include <stdio.h>
@ -446,18 +442,17 @@ find_user:
}
/* hostname */
#ifdef INET6
if (*p == '[' && (q = strchr(p + 1, ']')) != NULL &&
(*++q == '\0' || *q == '/' || *q == ':')) {
if ((i = q - p - 2) > URL_HOSTLEN)
i = URL_HOSTLEN;
strncpy(u->host, ++p, i);
p = q;
} else
#endif
} else {
for (i = 0; *p && (*p != '/') && (*p != ':'); p++)
if (i < URL_HOSTLEN)
u->host[i++] = *p;
}
/* port */
if (*p == ':') {

View File

@ -30,12 +30,7 @@
* $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 <dirent.h>
#include <fcntl.h>
#include <fnmatch.h>

View File

@ -57,16 +57,10 @@
*
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@ -353,7 +347,6 @@ ftp_cwd(conn_t *conn, const char *path, int subdir)
}
free(pwd);
#ifdef FTP_COMBINE_CWDS
/* Skip leading slashes, even "////". */
for (beg = dst + i; beg < end && *beg == '/'; ++beg, ++i)
/* nothing */ ;
@ -370,7 +363,6 @@ ftp_cwd(conn_t *conn, const char *path, int subdir)
free(dst);
return (0);
}
#endif /* FTP_COMBINE_CWDS */
/* That didn't work so go back to legacy behavior (multiple CWDs). */
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)
{
conn_t *conn;
int e, direct, verbose;
#ifdef INET6
int af = AF_UNSPEC;
#else
int af = AF_INET;
#endif
direct = CHECK_FLAG('d');
verbose = CHECK_FLAG('v');

View File

@ -63,16 +63,8 @@
* SUCH DAMAGE.
*/
/* Needed for gmtime_r on Interix */
#define _REENTRANT
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <ctype.h>
#include <errno.h>
#include <locale.h>
@ -702,19 +694,13 @@ http_connect(struct url *URL, struct url *purl, const char *flags, int *cached)
*cached = 0;
#ifdef INET6
af = AF_UNSPEC;
#else
af = AF_INET;
#endif
verbose = CHECK_FLAG('v');
if (CHECK_FLAG('4'))
af = AF_INET;
#ifdef INET6
else if (CHECK_FLAG('6'))
af = AF_INET6;
#endif
curl = (purl != NULL) ? purl : URL;
@ -887,12 +873,10 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
goto ouch;
host = url->host;
#ifdef INET6
if (strchr(url->host, ':')) {
snprintf(hbuf, sizeof(hbuf), "[%s]", url->host);
host = hbuf;
}
#endif
if (url->port != fetch_default_port(url->scheme)) {
if (host != hbuf) {
strcpy(hbuf, host);