1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Get rid of ssl_iread/ssl_iwrite. Have the SSL code register its

routines for reading and writing data.
This commit is contained in:
hniksic 2003-11-05 17:12:03 -08:00
parent 1131c6a116
commit c8e92cdbd6
15 changed files with 473 additions and 475 deletions

View File

@ -1,3 +1,34 @@
2003-11-06 Hrvoje Niksic <hniksic@xemacs.org>
* connect.c: Updated all callers of
iread/ssl_iread/iwrite/ssl_iwrite to use xread and xwrite instead.
* rbuf.h (struct rbuf): Removed the SSL member because SSL is
handled automatically by xread.
* hash.c (ptrhash): Made private.
(ptrcmp): Ditto.
(inthash): Removed.
* connect.c (select_fd): Don't set errno, leave it to the caller.
* gen_sslfunc.c (connect_ssl): Use register_extended to register
SSL callbacks for communication with SSL-enabled endpoints.
(ssl_read): New function.
(ssl_write): Ditto.
(ssl_poll): Ditto.
(ssl_close): Ditto.
* connect.c (register_extended): New function -- register
callbacks for basic socket operations.
(xread): Ditto.
(xwrite): Ditto.
(xclose): Ditto.
(sock_read): New function, default implementation for reading.
(sock_write): Ditto for writing.
(sock_poll): Ditto for polling.
(sock_close): Ditto for closing.
2003-11-05 Hrvoje Niksic <hniksic@xemacs.org> 2003-11-05 Hrvoje Niksic <hniksic@xemacs.org>
* connect.c (bindport): Fix compilation under pre-C99 compilers. * connect.c (bindport): Fix compilation under pre-C99 compilers.

View File

@ -60,6 +60,7 @@ so, delete this exception statement from your version. */
#include "utils.h" #include "utils.h"
#include "host.h" #include "host.h"
#include "connect.h" #include "connect.h"
#include "hash.h"
#ifndef errno #ifndef errno
extern int errno; extern int errno;
@ -304,7 +305,7 @@ connect_to_ip (const ip_address *ip, int port, const char *print)
logprintf. */ logprintf. */
int save_errno = errno; int save_errno = errno;
if (sock >= 0) if (sock >= 0)
CLOSE (sock); xclose (sock);
if (print) if (print)
logprintf (LOG_VERBOSE, "failed: %s.\n", strerror (errno)); logprintf (LOG_VERBOSE, "failed: %s.\n", strerror (errno));
errno = save_errno; errno = save_errno;
@ -426,7 +427,7 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
sockaddr_set_data (sa, bind_address, *port); sockaddr_set_data (sa, bind_address, *port);
if (bind (sock, sa, sockaddr_size (sa)) < 0) if (bind (sock, sa, sockaddr_size (sa)) < 0)
{ {
CLOSE (sock); xclose (sock);
return BINDERR; return BINDERR;
} }
DEBUGP (("Local socket fd %d bound.\n", sock)); DEBUGP (("Local socket fd %d bound.\n", sock));
@ -435,7 +436,7 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
socklen_t sa_len = sockaddr_size (sa); socklen_t sa_len = sockaddr_size (sa);
if (getsockname (sock, sa, &sa_len) < 0) if (getsockname (sock, sa, &sa_len) < 0)
{ {
CLOSE (sock); xclose (sock);
return CONPORTERR; return CONPORTERR;
} }
sockaddr_get_data (sa, NULL, port); sockaddr_get_data (sa, NULL, port);
@ -444,7 +445,7 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
} }
if (listen (sock, 1) < 0) if (listen (sock, 1) < 0)
{ {
CLOSE (sock); xclose (sock);
return LISTENERR; return LISTENERR;
} }
*local_sock = sock; *local_sock = sock;
@ -454,14 +455,14 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
/* Wait for file descriptor FD to be readable or writable or both, /* Wait for file descriptor FD to be readable or writable or both,
timing out after MAXTIME seconds. Returns 1 if FD is available, 0 timing out after MAXTIME seconds. Returns 1 if FD is available, 0
for timeout and -1 for error. The argument WHAT can be a for timeout and -1 for error. The argument WAIT_FOR can be a
combination of WAIT_READ and WAIT_WRITE. combination of WAIT_READ and WAIT_WRITE.
This is a mere convenience wrapper around the select call, and This is a mere convenience wrapper around the select call, and
should be taken as such. */ should be taken as such. */
int int
select_fd (int fd, double maxtime, int wait) select_fd (int fd, double maxtime, int wait_for)
{ {
fd_set fdset; fd_set fdset;
fd_set *rd = NULL, *wr = NULL; fd_set *rd = NULL, *wr = NULL;
@ -470,23 +471,18 @@ select_fd (int fd, double maxtime, int wait)
FD_ZERO (&fdset); FD_ZERO (&fdset);
FD_SET (fd, &fdset); FD_SET (fd, &fdset);
if (wait & WAIT_READ) if (wait_for & WAIT_FOR_READ)
rd = &fdset; rd = &fdset;
if (wait & WAIT_WRITE) if (wait_for & WAIT_FOR_WRITE)
wr = &fdset; wr = &fdset;
tmout.tv_sec = (long)maxtime; tmout.tv_sec = (long) maxtime;
tmout.tv_usec = 1000000L * (maxtime - (long)maxtime); tmout.tv_usec = 1000000L * (maxtime - (long) maxtime);
do do
result = select (fd + 1, rd, wr, NULL, &tmout); result = select (fd + 1, rd, wr, NULL, &tmout);
while (result < 0 && errno == EINTR); while (result < 0 && errno == EINTR);
/* When we've timed out, set errno to ETIMEDOUT for the convenience
of the caller. */
if (result == 0)
errno = ETIMEDOUT;
return result; return result;
} }
#endif /* HAVE_SELECT */ #endif /* HAVE_SELECT */
@ -505,7 +501,7 @@ acceptport (int local_sock, int *sock)
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
if (opt.connect_timeout) if (opt.connect_timeout)
if (select_fd (local_sock, opt.connect_timeout, WAIT_READ) <= 0) if (select_fd (local_sock, opt.connect_timeout, WAIT_FOR_READ) <= 0)
return ACCEPTERR; return ACCEPTERR;
#endif #endif
if ((*sock = accept (local_sock, sa, &addrlen)) < 0) if ((*sock = accept (local_sock, sa, &addrlen)) < 0)
@ -555,58 +551,214 @@ conaddr (int fd, ip_address *ip)
return 0; return 0;
} }
/* Basic socket operations, mostly EINTR wrappers. */
/* Read at most LEN bytes from FD, storing them to BUF. This is #ifdef WINDOWS
virtually the same as read(), but takes care of EINTR braindamage # define read(fd, buf, cnt) recv (fd, buf, cnt, 0)
and uses select() to timeout the stale connections (a connection is # define write(fd, buf, cnt) send (fd, buf, cnt, 0)
stale if more than OPT.READ_TIMEOUT time is spent in select() or # define close(fd) closesocket (fd)
read()). */ #endif
int #ifdef __BEOS__
iread (int fd, char *buf, int len) # define read(fd, buf, cnt) recv (fd, buf, cnt, 0)
# define write(fd, buf, cnt) send (fd, buf, cnt, 0)
#endif
static int
sock_read (int fd, char *buf, int bufsize)
{ {
int res; int res;
#ifdef HAVE_SELECT
if (opt.read_timeout)
if (select_fd (fd, opt.read_timeout, WAIT_READ) <= 0)
return -1;
#endif
do do
res = READ (fd, buf, len); res = read (fd, buf, bufsize);
while (res == -1 && errno == EINTR); while (res == -1 && errno == EINTR);
return res; return res;
} }
/* Write LEN bytes from BUF to FD. This is similar to iread(), but static int
unlike iread(), it makes sure that all of BUF is actually written sock_write (int fd, char *buf, int bufsize)
to FD, so callers needn't bother with checking that the return
value equals to LEN. Instead, you should simply check for -1. */
int
iwrite (int fd, char *buf, int len)
{ {
int res = 0; int res = 0;
do
res = write (fd, buf, bufsize);
while (res == -1 && errno == EINTR);
return res;
}
/* `write' may write less than LEN bytes, thus the outward loop static int
keeps trying it until all was written, or an error occurred. The sock_poll (int fd, double timeout, int wait_for)
inner loop is reserved for the usual EINTR f*kage, and the {
innermost loop deals with the same during select(). */
while (len > 0)
{
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
if (opt.read_timeout) return select_fd (fd, timeout, wait_for);
if (select_fd (fd, opt.read_timeout, WAIT_WRITE) <= 0) #else
return -1; return 1;
#endif #endif
do }
res = WRITE (fd, buf, len);
while (res == -1 && errno == EINTR); static void
sock_close (int fd)
{
close (fd);
DEBUGP (("Closed fd %d\n", fd));
}
#undef read
#undef write
#undef close
/* Reading and writing from the network. We build around the socket
(file descriptor) API, but support "extended" operations for things
that are not mere file descriptors under the hood, such as SSL
sockets.
That way the user code can call xread(fd, ...) and we'll run read
or SSL_read or whatever is necessary. */
static struct hash_table *extended_map;
static long extended_map_modified_tick;
struct extended_info {
xreader_t reader;
xwriter_t writer;
xpoller_t poller;
xcloser_t closer;
void *ctx;
};
void
register_extended (int fd, xreader_t reader, xwriter_t writer,
xpoller_t poller, xcloser_t closer, void *ctx)
{
struct extended_info *info = xnew (struct extended_info);
info->reader = reader;
info->writer = writer;
info->poller = poller;
info->closer = closer;
info->ctx = ctx;
if (!extended_map)
extended_map = hash_table_new (0, NULL, NULL);
hash_table_put (extended_map, (void *) fd, info);
++extended_map_modified_tick;
}
/* When xread/xwrite are called multiple times in a loop, they should
remember the INFO pointer instead of fetching it every time. It is
not enough to compare FD to LAST_FD because FD might have been
closed and reopened. modified_tick ensures that changes to
extended_map will not be unnoticed.
This is a macro because we want the static storage variables to be
per-function. */
#define LAZY_RETRIEVE_INFO(info) do { \
static struct extended_info *last_info; \
static int last_fd = -1, last_tick; \
if (!extended_map) \
info = NULL; \
else if (last_fd == fd && last_tick == extended_map_modified_tick) \
info = last_info; \
else \
{ \
info = hash_table_get (extended_map, (void *) fd); \
last_fd = fd; \
last_tick = extended_map_modified_tick; \
} \
} while (0)
/* Read no more than BUFSIZE bytes of data from FD, storing them to
BUF. If TIMEOUT is non-zero, the operation aborts if no data is
received after that many seconds. If TIMEOUT is -1, the value of
opt.timeout is used for TIMEOUT. */
int
xread (int fd, char *buf, int bufsize, double timeout)
{
struct extended_info *info;
LAZY_RETRIEVE_INFO (info);
if (timeout == -1)
timeout = opt.read_timeout;
if (timeout)
{
int test;
if (info && info->poller)
test = info->poller (fd, timeout, WAIT_FOR_READ, info->ctx);
else
test = sock_poll (fd, timeout, WAIT_FOR_READ);
if (test == 0)
errno = ETIMEDOUT;
if (test <= 0)
return -1;
}
if (info && info->reader)
return info->reader (fd, buf, bufsize, info->ctx);
else
return sock_read (fd, buf, bufsize);
}
/* Write the entire contents of BUF to FD. If TIMEOUT is non-zero,
the operation aborts if no data is received after that many
seconds. If TIMEOUT is -1, the value of opt.timeout is used for
TIMEOUT. */
int
xwrite (int fd, char *buf, int bufsize, double timeout)
{
int res;
struct extended_info *info;
LAZY_RETRIEVE_INFO (info);
if (timeout == -1)
timeout = opt.read_timeout;
/* `write' may write less than LEN bytes, thus the loop keeps trying
it until all was written, or an error occurred. */
res = 0;
while (bufsize > 0)
{
if (timeout)
{
int test;
if (info && info->poller)
test = info->poller (fd, timeout, WAIT_FOR_WRITE, info->ctx);
else
test = sock_poll (fd, timeout, WAIT_FOR_WRITE);
if (test == 0)
errno = ETIMEDOUT;
if (test <= 0)
return -1;
}
if (info && info->writer)
res = info->writer (fd, buf, bufsize, info->ctx);
else
res = sock_write (fd, buf, bufsize);
if (res <= 0) if (res <= 0)
break; break;
buf += res; buf += res;
len -= res; bufsize -= res;
} }
return res; return res;
} }
/* Close the file descriptor FD. */
void
xclose (int fd)
{
struct extended_info *info;
if (fd < 0)
return;
/* We don't need to be extra-fast here, so save some code by
avoiding LAZY_RETRIEVE_INFO. */
info = NULL;
if (extended_map)
info = hash_table_get (extended_map, (void *) fd);
if (info && info->closer)
{
info->closer (fd, info->ctx);
hash_table_remove (extended_map, (void *) fd);
xfree (info);
++extended_map_modified_tick;
}
else
sock_close (fd);
}

View File

@ -32,17 +32,6 @@ so, delete this exception statement from your version. */
#include "host.h" /* for definition of ip_address */ #include "host.h" /* for definition of ip_address */
/* Returned by connect_to_host when host name cannot be resolved. */
enum {
E_HOST = -100
};
/* Flags for select_fd's WAIT argument. */
enum {
WAIT_READ = 1,
WAIT_WRITE = 2
};
/* bindport flags */ /* bindport flags */
#define BIND_ON_IPV4_ONLY LH_IPV4_ONLY #define BIND_ON_IPV4_ONLY LH_IPV4_ONLY
#define BIND_ON_IPV6_ONLY LH_IPV6_ONLY #define BIND_ON_IPV6_ONLY LH_IPV6_ONLY
@ -55,18 +44,35 @@ enum {
/* Function declarations */ /* Function declarations */
int connect_to_ip PARAMS ((const ip_address *, int, const char *)); /* Returned by connect_to_host when host name cannot be resolved. */
enum {
E_HOST = -100
};
int connect_to_host PARAMS ((const char *, int)); int connect_to_host PARAMS ((const char *, int));
int connect_to_ip PARAMS ((const ip_address *, int, const char *));
void sockaddr_get_data PARAMS ((const struct sockaddr *, ip_address *, int *)); void sockaddr_get_data PARAMS ((const struct sockaddr *, ip_address *, int *));
int test_socket_open PARAMS ((int));
int select_fd PARAMS ((int, double, int));
uerr_t bindport PARAMS ((const ip_address *, int *, int *)); uerr_t bindport PARAMS ((const ip_address *, int *, int *));
uerr_t acceptport PARAMS ((int, int *)); uerr_t acceptport PARAMS ((int, int *));
int conaddr PARAMS ((int, ip_address *)); int conaddr PARAMS ((int, ip_address *));
int iread PARAMS ((int, char *, int)); /* Flags for select_fd's WAIT_FOR argument. */
int iwrite PARAMS ((int, char *, int)); enum {
WAIT_FOR_READ = 1,
WAIT_FOR_WRITE = 2
};
int select_fd PARAMS ((int, double, int));
int test_socket_open PARAMS ((int));
typedef int (*xreader_t) PARAMS ((int, char *, int, void *));
typedef int (*xwriter_t) PARAMS ((int, char *, int, void *));
typedef int (*xpoller_t) PARAMS ((int, double, int, void *));
typedef void (*xcloser_t) PARAMS ((int, void *));
void register_extended PARAMS ((int,
xreader_t, xwriter_t, xpoller_t, xcloser_t,
void *));
int xread PARAMS ((int, char *, int, double));
int xwrite PARAMS ((int, char *, int, double));
void xclose PARAMS ((int));
#endif /* CONNECT_H */ #endif /* CONNECT_H */

View File

@ -158,7 +158,7 @@ ftp_login (struct rbuf *rbuf, const char *acc, const char *pass)
xfree (respline); xfree (respline);
/* Send USER username. */ /* Send USER username. */
request = ftp_request ("USER", acc); request = ftp_request ("USER", acc);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -225,7 +225,7 @@ ftp_login (struct rbuf *rbuf, const char *acc, const char *pass)
xfree (respline); xfree (respline);
/* Send PASS password. */ /* Send PASS password. */
request = ftp_request ("PASS", pass); request = ftp_request ("PASS", pass);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -303,11 +303,11 @@ ftp_port (struct rbuf *rbuf, int *local_sock)
/* Send PORT request. */ /* Send PORT request. */
request = ftp_request ("PORT", bytes); request = ftp_request ("PORT", bytes);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
CLOSE (*local_sock); xclose (*local_sock);
return WRITEFAILED; return WRITEFAILED;
} }
xfree (request); xfree (request);
@ -317,13 +317,13 @@ ftp_port (struct rbuf *rbuf, int *local_sock)
if (err != FTPOK) if (err != FTPOK)
{ {
xfree (respline); xfree (respline);
CLOSE (*local_sock); xclose (*local_sock);
return err; return err;
} }
if (*respline != '2') if (*respline != '2')
{ {
xfree (respline); xfree (respline);
CLOSE (*local_sock); xclose (*local_sock);
return FTPPORTERR; return FTPPORTERR;
} }
xfree (respline); xfree (respline);
@ -400,11 +400,11 @@ ftp_lprt (struct rbuf *rbuf, int *local_sock)
/* Send PORT request. */ /* Send PORT request. */
request = ftp_request ("LPRT", bytes); request = ftp_request ("LPRT", bytes);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
CLOSE (*local_sock); xclose (*local_sock);
return WRITEFAILED; return WRITEFAILED;
} }
xfree (request); xfree (request);
@ -413,13 +413,13 @@ ftp_lprt (struct rbuf *rbuf, int *local_sock)
if (err != FTPOK) if (err != FTPOK)
{ {
xfree (respline); xfree (respline);
CLOSE (*local_sock); xclose (*local_sock);
return err; return err;
} }
if (*respline != '2') if (*respline != '2')
{ {
xfree (respline); xfree (respline);
CLOSE (*local_sock); xclose (*local_sock);
return FTPPORTERR; return FTPPORTERR;
} }
xfree (respline); xfree (respline);
@ -484,11 +484,11 @@ ftp_eprt (struct rbuf *rbuf, int *local_sock)
/* Send PORT request. */ /* Send PORT request. */
request = ftp_request ("EPRT", bytes); request = ftp_request ("EPRT", bytes);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
CLOSE (*local_sock); xclose (*local_sock);
return WRITEFAILED; return WRITEFAILED;
} }
xfree (request); xfree (request);
@ -497,13 +497,13 @@ ftp_eprt (struct rbuf *rbuf, int *local_sock)
if (err != FTPOK) if (err != FTPOK)
{ {
xfree (respline); xfree (respline);
CLOSE (*local_sock); xclose (*local_sock);
return err; return err;
} }
if (*respline != '2') if (*respline != '2')
{ {
xfree (respline); xfree (respline);
CLOSE (*local_sock); xclose (*local_sock);
return FTPPORTERR; return FTPPORTERR;
} }
xfree (respline); xfree (respline);
@ -532,7 +532,7 @@ ftp_pasv (struct rbuf *rbuf, ip_address *addr, int *port)
/* Form the request. */ /* Form the request. */
request = ftp_request ("PASV", NULL); request = ftp_request ("PASV", NULL);
/* And send it. */ /* And send it. */
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -603,7 +603,7 @@ ftp_lpsv (struct rbuf *rbuf, ip_address *addr, int *port)
request = ftp_request ("LPSV", NULL); request = ftp_request ("LPSV", NULL);
/* And send it. */ /* And send it. */
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -779,7 +779,7 @@ ftp_epsv (struct rbuf *rbuf, ip_address *ip, int *port)
request = ftp_request ("EPSV", (sa->sa_family == AF_INET ? "1" : "2")); request = ftp_request ("EPSV", (sa->sa_family == AF_INET ? "1" : "2"));
/* And send it. */ /* And send it. */
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -879,7 +879,7 @@ ftp_type (struct rbuf *rbuf, int type)
stype[1] = 0; stype[1] = 0;
/* Send TYPE request. */ /* Send TYPE request. */
request = ftp_request ("TYPE", stype); request = ftp_request ("TYPE", stype);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -914,7 +914,7 @@ ftp_cwd (struct rbuf *rbuf, const char *dir)
/* Send CWD request. */ /* Send CWD request. */
request = ftp_request ("CWD", dir); request = ftp_request ("CWD", dir);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -954,7 +954,7 @@ ftp_rest (struct rbuf *rbuf, long offset)
number_to_string (numbuf, offset); number_to_string (numbuf, offset);
request = ftp_request ("REST", numbuf); request = ftp_request ("REST", numbuf);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -988,7 +988,7 @@ ftp_retr (struct rbuf *rbuf, const char *file)
/* Send RETR request. */ /* Send RETR request. */
request = ftp_request ("RETR", file); request = ftp_request ("RETR", file);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -1028,7 +1028,7 @@ ftp_list (struct rbuf *rbuf, const char *file)
/* Send LIST request. */ /* Send LIST request. */
request = ftp_request ("LIST", file); request = ftp_request ("LIST", file);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -1067,7 +1067,7 @@ ftp_syst (struct rbuf *rbuf, enum stype *server_type)
/* Send SYST request. */ /* Send SYST request. */
request = ftp_request ("SYST", NULL); request = ftp_request ("SYST", NULL);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -1123,7 +1123,7 @@ ftp_pwd (struct rbuf *rbuf, char **pwd)
/* Send PWD request. */ /* Send PWD request. */
request = ftp_request ("PWD", NULL); request = ftp_request ("PWD", NULL);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);
@ -1169,7 +1169,7 @@ ftp_size (struct rbuf *rbuf, const char *file, long int *size)
/* Send PWD request. */ /* Send PWD request. */
request = ftp_request ("SIZE", file); request = ftp_request ("SIZE", file);
nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request)); nwritten = xwrite (RBUF_FD (rbuf), request, strlen (request), -1);
if (nwritten < 0) if (nwritten < 0)
{ {
xfree (request); xfree (request);

140
src/ftp.c
View File

@ -327,14 +327,14 @@ getftp (struct url *u, long *len, long restval, ccon *con)
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
case FTPSRVERR: case FTPSRVERR:
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("Error in server greeting.\n")); logputs (LOG_NOTQUIET, _("Error in server greeting.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -342,21 +342,21 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
case FTPLOGREFUSED: case FTPLOGREFUSED:
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("The server refuses login.\n")); logputs (LOG_NOTQUIET, _("The server refuses login.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return FTPLOGREFUSED; return FTPLOGREFUSED;
break; break;
case FTPLOGINC: case FTPLOGINC:
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("Login incorrect.\n")); logputs (LOG_NOTQUIET, _("Login incorrect.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return FTPLOGINC; return FTPLOGINC;
break; break;
@ -380,7 +380,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -411,7 +411,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -465,7 +465,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -473,7 +473,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -482,7 +482,7 @@ Error in server response, closing control connection.\n"));
logprintf (LOG_NOTQUIET, logprintf (LOG_NOTQUIET,
_("Unknown type `%c', closing control connection.\n"), _("Unknown type `%c', closing control connection.\n"),
type_char); type_char);
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
case FTPOK: case FTPOK:
@ -580,7 +580,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -588,7 +588,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -596,7 +596,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("No such directory `%s'.\n\n"), logprintf (LOG_NOTQUIET, _("No such directory `%s'.\n\n"),
u->dir); u->dir);
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -631,7 +631,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -661,7 +661,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -669,7 +669,7 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -697,7 +697,7 @@ Error in server response, closing control connection.\n"));
if (dtsock < 0) if (dtsock < 0)
{ {
int save_errno = errno; int save_errno = errno;
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
logprintf (LOG_VERBOSE, _("couldn't connect to %s port %hu: %s\n"), logprintf (LOG_VERBOSE, _("couldn't connect to %s port %hu: %s\n"),
pretty_print_address (&passive_addr), passive_port, pretty_print_address (&passive_addr), passive_port,
@ -722,9 +722,9 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -732,18 +732,18 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
case CONSOCKERR: case CONSOCKERR:
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, "socket: %s\n", strerror (errno)); logprintf (LOG_NOTQUIET, "socket: %s\n", strerror (errno));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -752,16 +752,16 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("Bind error (%s).\n"), logprintf (LOG_NOTQUIET, _("Bind error (%s).\n"),
strerror (errno)); strerror (errno));
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
return err; return err;
break; break;
case FTPPORTERR: case FTPPORTERR:
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("Invalid PORT.\n")); logputs (LOG_NOTQUIET, _("Invalid PORT.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -791,9 +791,9 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -801,9 +801,9 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -816,9 +816,9 @@ Error in server response, closing control connection.\n"));
logprintf (LOG_NOTQUIET, logprintf (LOG_NOTQUIET,
_("\nREST failed; will not truncate `%s'.\n"), _("\nREST failed; will not truncate `%s'.\n"),
con->target); con->target);
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return CONTNOTSUPPORTED; return CONTNOTSUPPORTED;
} }
@ -844,9 +844,9 @@ Error in server response, closing control connection.\n"));
request. */ request. */
if (opt.spider) if (opt.spider)
{ {
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return RETRFINISHED; return RETRFINISHED;
} }
@ -869,9 +869,9 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -879,17 +879,17 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
case FTPNSFOD: case FTPNSFOD:
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("No such file `%s'.\n\n"), u->file); logprintf (LOG_NOTQUIET, _("No such file `%s'.\n\n"), u->file);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
return err; return err;
break; break;
case FTPOK: case FTPOK:
@ -920,9 +920,9 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("\ logputs (LOG_NOTQUIET, _("\
Error in server response, closing control connection.\n")); Error in server response, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -930,9 +930,9 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, logputs (LOG_NOTQUIET,
_("Write failed, closing control connection.\n")); _("Write failed, closing control connection.\n"));
CLOSE (csock); xclose (csock);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return err; return err;
break; break;
@ -940,8 +940,8 @@ Error in server response, closing control connection.\n"));
logputs (LOG_VERBOSE, "\n"); logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("No such file or directory `%s'.\n\n"), logprintf (LOG_NOTQUIET, _("No such file or directory `%s'.\n\n"),
"."); ".");
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
return err; return err;
break; break;
case FTPOK: case FTPOK:
@ -995,10 +995,10 @@ Error in server response, closing control connection.\n"));
if (!fp) if (!fp)
{ {
logprintf (LOG_NOTQUIET, "%s: %s\n", con->target, strerror (errno)); logprintf (LOG_NOTQUIET, "%s: %s\n", con->target, strerror (errno));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
return FOPENERR; return FOPENERR;
} }
} }
@ -1045,8 +1045,8 @@ Error in server response, closing control connection.\n"));
tms = time_str (NULL); tms = time_str (NULL);
tmrate = retr_rate (*len - restval, con->dltime, 0); tmrate = retr_rate (*len - restval, con->dltime, 0);
/* Close data connection socket. */ /* Close data connection socket. */
CLOSE (dtsock); xclose (dtsock);
CLOSE (local_sock); xclose (local_sock);
/* Close the local file. */ /* Close the local file. */
{ {
/* Close or flush the file. We have to be careful to check for /* Close or flush the file. We have to be careful to check for
@ -1066,7 +1066,7 @@ Error in server response, closing control connection.\n"));
{ {
logprintf (LOG_NOTQUIET, _("%s: %s, closing control connection.\n"), logprintf (LOG_NOTQUIET, _("%s: %s, closing control connection.\n"),
con->target, strerror (errno)); con->target, strerror (errno));
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return FWRITEERR; return FWRITEERR;
} }
@ -1094,7 +1094,7 @@ Error in server response, closing control connection.\n"));
return FTPRETRINT, since there is a possibility that the return FTPRETRINT, since there is a possibility that the
whole file was retrieved nevertheless (but that is for whole file was retrieved nevertheless (but that is for
ftp_loop_internal to decide). */ ftp_loop_internal to decide). */
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
return FTPRETRINT; return FTPRETRINT;
} /* err != FTPOK */ } /* err != FTPOK */
@ -1123,7 +1123,7 @@ Error in server response, closing control connection.\n"));
{ {
/* I should probably send 'QUIT' and check for a reply, but this /* I should probably send 'QUIT' and check for a reply, but this
is faster. #### Is it OK, though? */ is faster. #### Is it OK, though? */
CLOSE (csock); xclose (csock);
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
} }
/* If it was a listing, and opt.server_response is true, /* If it was a listing, and opt.server_response is true,
@ -1304,7 +1304,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
if (con->st & ON_YOUR_OWN) if (con->st & ON_YOUR_OWN)
{ {
CLOSE (RBUF_FD (&con->rbuf)); xclose (RBUF_FD (&con->rbuf));
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
} }
if (!opt.spider) if (!opt.spider)
@ -1366,7 +1366,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
if (rbuf_initialized_p (&con->rbuf) && (con->st & ON_YOUR_OWN)) if (rbuf_initialized_p (&con->rbuf) && (con->st & ON_YOUR_OWN))
{ {
CLOSE (RBUF_FD (&con->rbuf)); xclose (RBUF_FD (&con->rbuf));
rbuf_uninitialize (&con->rbuf); rbuf_uninitialize (&con->rbuf);
} }
return TRYLIMEXC; return TRYLIMEXC;
@ -1924,7 +1924,7 @@ ftp_loop (struct url *u, int *dt, struct url *proxy)
*dt |= RETROKF; *dt |= RETROKF;
/* If a connection was left, quench it. */ /* If a connection was left, quench it. */
if (rbuf_initialized_p (&con.rbuf)) if (rbuf_initialized_p (&con.rbuf))
CLOSE (RBUF_FD (&con.rbuf)); xclose (RBUF_FD (&con.rbuf));
xfree_null (con.id); xfree_null (con.id);
con.id = NULL; con.id = NULL;
xfree_null (con.target); xfree_null (con.target);

View File

@ -30,8 +30,6 @@ so, delete this exception statement from your version. */
#include <config.h> #include <config.h>
#ifdef HAVE_SSL
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
@ -256,50 +254,87 @@ init_ssl (SSL_CTX **ctx)
return 0; /* Succeded */ return 0; /* Succeded */
} }
void static
shutdown_ssl (SSL* con) int ssl_read (int fd, char *buf, int bufsize, void *ctx)
{ {
if (con == NULL) int res;
return; SSL *ssl = (SSL *) ctx;
if (0==SSL_shutdown (con)) /* #### Does SSL_read actually set EINTR? */
SSL_shutdown (con); do
SSL_free (con); res = SSL_read (ssl, buf, bufsize);
while (res == -1 && errno == EINTR);
return res;
} }
/* Sets up a SSL structure and performs the handshake on fd static int
Returns 0 if everything went right ssl_write (int fd, char *buf, int bufsize, void *ctx)
Returns 1 if something went wrong ----- TODO: More exit codes
*/
int
connect_ssl (SSL **con, SSL_CTX *ctx, int fd)
{ {
if (NULL == (*con = SSL_new (ctx))) int res = 0;
{ SSL *ssl = (SSL *) ctx;
ssl_printerrors (); /* #### Does SSL_write actually set EINTR? */
return 1; do
} res = SSL_write (ssl, buf, bufsize);
if (!SSL_set_fd (*con, fd)) while (res == -1 && errno == EINTR);
{ return res;
ssl_printerrors (); }
return 1;
} static int
SSL_set_connect_state (*con); ssl_poll (int fd, double timeout, int wait_for, void *ctx)
switch (SSL_connect (*con)) {
{ SSL *ssl = (SSL *) ctx;
case 1 : if (timeout == 0)
return (*con)->state != SSL_ST_OK; return 1;
default: if (SSL_pending (ssl))
ssl_printerrors (); return 1;
shutdown_ssl (*con); #ifdef HAVE_SELECT
*con = NULL; return select_fd (fd, timeout, wait_for);
return 1; #else
case 0 : return 1;
ssl_printerrors (); #endif
SSL_free (*con); }
*con = NULL;
return 1; static void
} ssl_close (int fd, void *ctx)
return 0; {
SSL *ssl = (SSL *) ctx;
SSL_shutdown (ssl);
SSL_free (ssl);
#ifdef WINDOWS
closesocket (fd);
#else
close (fd);
#endif
DEBUGP (("Closed %d/SSL 0x%0lx\n", fd, (unsigned long) ssl));
}
/* Sets up a SSL structure and performs the handshake on fd. */
SSL *
connect_ssl (int fd, SSL_CTX *ctx)
{
SSL *ssl = SSL_new (ctx);
if (!ssl)
goto err;
if (!SSL_set_fd (ssl, fd))
goto err;
SSL_set_connect_state (ssl);
if (SSL_connect (ssl) <= 0 || ssl->state != SSL_ST_OK)
goto err;
/* Register the FD to use our functions for read, write, etc. That
way the rest of Wget can keep using xread, xwrite, and
friends. */
register_extended (fd, ssl_read, ssl_write, ssl_poll, ssl_close, ssl);
DEBUGP (("Connected %d to SSL 0x%0lx\n", fd, (unsigned long) ssl));
return ssl;
err:
ssl_printerrors ();
if (ssl)
SSL_free (ssl);
return NULL;
} }
void void
@ -307,54 +342,3 @@ free_ssl_ctx (SSL_CTX * ctx)
{ {
SSL_CTX_free (ctx); SSL_CTX_free (ctx);
} }
/* SSL version of iread. Only exchanged read for SSL_read Read at
most LEN bytes from FD, storing them to BUF. */
int
ssl_iread (SSL *con, char *buf, int len)
{
int res, fd;
BIO_get_fd (con->rbio, &fd);
#ifdef HAVE_SELECT
if (opt.read_timeout && !SSL_pending (con))
if (select_fd (fd, opt.read_timeout, WAIT_READ) <= 0)
return -1;
#endif
do
res = SSL_read (con, buf, len);
while (res == -1 && errno == EINTR);
return res;
}
/* SSL version of iwrite. Only exchanged write for SSL_write Write
LEN bytes from BUF to FD. */
int
ssl_iwrite (SSL *con, char *buf, int len)
{
int res = 0, fd;
BIO_get_fd (con->rbio, &fd);
/* `write' may write less than LEN bytes, thus the outward loop
keeps trying it until all was written, or an error occurred. The
inner loop is reserved for the usual EINTR f*kage, and the
innermost loop deals with the same during select(). */
while (len > 0)
{
#ifdef HAVE_SELECT
if (opt.read_timeout)
if (select_fd (fd, opt.read_timeout, WAIT_WRITE) <= 0)
return -1;
#endif
do
res = SSL_write (con, buf, len);
while (res == -1 && errno == EINTR);
if (res <= 0)
break;
buf += res;
len -= res;
}
return res;
}
#endif /* HAVE_SSL */

View File

@ -38,12 +38,9 @@ so, delete this exception statement from your version. */
void ssl_init_prng PARAMS ((void)); void ssl_init_prng PARAMS ((void));
int init_ssl PARAMS ((SSL_CTX **)); int init_ssl PARAMS ((SSL_CTX **));
int connect_ssl PARAMS ((SSL **, SSL_CTX *, int)); SSL *connect_ssl PARAMS ((int, SSL_CTX *));
void shutdown_ssl PARAMS ((SSL*));
void free_ssl_ctx PARAMS ((SSL_CTX *)); void free_ssl_ctx PARAMS ((SSL_CTX *));
int verify_callback PARAMS ((int, X509_STORE_CTX *)); int verify_callback PARAMS ((int, X509_STORE_CTX *));
int ssl_iread PARAMS ((SSL *, char *, int));
int ssl_iwrite PARAMS ((SSL *, char *, int));
int ssl_printerrors PARAMS ((void)); int ssl_printerrors PARAMS ((void));
#endif /* GEN_SSLFUNC_H */ #endif /* GEN_SSLFUNC_H */

View File

@ -238,6 +238,9 @@ prime_size (int size, int *prime_offset)
return 0; return 0;
} }
static unsigned long ptrhash PARAMS ((const void *));
static int ptrcmp PARAMS ((const void *, const void *));
/* Create a hash table with hash function HASH_FUNCTION and test /* Create a hash table with hash function HASH_FUNCTION and test
function TEST_FUNCTION. The table is empty (its count is 0), but function TEST_FUNCTION. The table is empty (its count is 0), but
pre-allocated to store at least ITEMS items. pre-allocated to store at least ITEMS items.
@ -612,7 +615,7 @@ make_nocase_string_hash_table (int items)
pointer identity. (Common Lisp calls them EQ hash tables, and Java pointer identity. (Common Lisp calls them EQ hash tables, and Java
calls them IdentityHashMaps.) */ calls them IdentityHashMaps.) */
unsigned long static unsigned long
ptrhash (const void *ptr) ptrhash (const void *ptr)
{ {
unsigned long key = (unsigned long)ptr; unsigned long key = (unsigned long)ptr;
@ -637,29 +640,11 @@ ptrhash (const void *ptr)
return key; return key;
} }
int static int
ptrcmp (const void *ptr1, const void *ptr2) ptrcmp (const void *ptr1, const void *ptr2)
{ {
return ptr1 == ptr2; return ptr1 == ptr2;
} }
#if 0
/* Currently unused: hashing of integers. */
unsigned long
inthash (unsigned int key)
{
key += (key << 12);
key ^= (key >> 22);
key += (key << 4);
key ^= (key >> 9);
key += (key << 10);
key ^= (key >> 2);
key += (key << 7);
key ^= (key >> 12);
return key;
}
#endif
#ifdef STANDALONE #ifdef STANDALONE

View File

@ -69,7 +69,4 @@ int string_cmp PARAMS ((const void *, const void *));
struct hash_table *make_string_hash_table PARAMS ((int)); struct hash_table *make_string_hash_table PARAMS ((int));
struct hash_table *make_nocase_string_hash_table PARAMS ((int)); struct hash_table *make_nocase_string_hash_table PARAMS ((int));
unsigned long ptrhash PARAMS ((const void *));
int ptrcmp PARAMS ((const void *, const void *));
#endif /* HASH_H */ #endif /* HASH_H */

View File

@ -192,17 +192,13 @@ parse_http_status_line (const char *line, const char **reason_phrase_ptr)
longer, read only that much; if the file is shorter, report an error. */ longer, read only that much; if the file is shorter, report an error. */
static int static int
post_file (int sock, void *ssl, const char *file_name, long promised_size) post_file (int sock, const char *file_name, long promised_size)
{ {
static char chunk[8192]; static char chunk[8192];
long written = 0; long written = 0;
int write_error; int write_error;
FILE *fp; FILE *fp;
/* Only one of SOCK and SSL may be active at the same time. */
assert (sock > -1 || ssl != NULL);
assert (sock == -1 || ssl == NULL);
DEBUGP (("[writing POST file %s ... ", file_name)); DEBUGP (("[writing POST file %s ... ", file_name));
fp = fopen (file_name, "rb"); fp = fopen (file_name, "rb");
@ -215,12 +211,7 @@ post_file (int sock, void *ssl, const char *file_name, long promised_size)
if (length == 0) if (length == 0)
break; break;
towrite = WMIN (promised_size - written, length); towrite = WMIN (promised_size - written, length);
#ifdef HAVE_SSL write_error = xwrite (sock, chunk, towrite, -1);
if (ssl)
write_error = ssl_iwrite (ssl, chunk, towrite);
else
#endif
write_error = iwrite (sock, chunk, towrite);
if (write_error < 0) if (write_error < 0)
{ {
fclose (fp); fclose (fp);
@ -359,6 +350,7 @@ http_process_set_cookie (const char *hdr, void *arg)
/* Whether a persistent connection is active. */ /* Whether a persistent connection is active. */
static int pc_active_p; static int pc_active_p;
/* Host and port of currently active persistent connection. */ /* Host and port of currently active persistent connection. */
static struct address_list *pc_last_host_ip; static struct address_list *pc_last_host_ip;
static unsigned short pc_last_port; static unsigned short pc_last_port;
@ -366,12 +358,8 @@ static unsigned short pc_last_port;
/* File descriptor of the currently active persistent connection. */ /* File descriptor of the currently active persistent connection. */
static int pc_last_fd; static int pc_last_fd;
#ifdef HAVE_SSL
/* Whether a ssl handshake has occoured on this connection */ /* Whether a ssl handshake has occoured on this connection */
static int pc_active_ssl; static int pc_last_ssl_p;
/* SSL connection of the currently active persistent connection. */
static SSL *pc_last_ssl;
#endif /* HAVE_SSL */
/* Mark the persistent connection as invalid. This is used by the /* Mark the persistent connection as invalid. This is used by the
CLOSE_* macros after they forcefully close a registered persistent CLOSE_* macros after they forcefully close a registered persistent
@ -382,9 +370,7 @@ static void
invalidate_persistent (void) invalidate_persistent (void)
{ {
pc_active_p = 0; pc_active_p = 0;
#ifdef HAVE_SSL pc_last_ssl_p = 0;
pc_active_ssl = 0;
#endif /* HAVE_SSL */
if (pc_last_host_ip != NULL) if (pc_last_host_ip != NULL)
{ {
address_list_release (pc_last_host_ip); address_list_release (pc_last_host_ip);
@ -401,15 +387,9 @@ invalidate_persistent (void)
If a previous connection was persistent, it is closed. */ If a previous connection was persistent, it is closed. */
#ifdef HAVE_SSL
static void static void
register_persistent (const char *host, unsigned short port, int fd, SSL *ssl) register_persistent (const char *host, unsigned short port, int fd, int ssl)
{ {
#else
static void
register_persistent (const char *host, unsigned short port, int fd)
{
#endif
if (pc_active_p) if (pc_active_p)
{ {
if (pc_last_fd == fd) if (pc_last_fd == fd)
@ -425,13 +405,7 @@ register_persistent (const char *host, unsigned short port, int fd)
persistent connection exists, but we then connect to a persistent connection exists, but we then connect to a
different host, and try to register a persistent different host, and try to register a persistent
connection to that one. */ connection to that one. */
#ifdef HAVE_SSL xclose (pc_last_fd);
/* The ssl disconnect has to take place before the closing
of pc_last_fd. */
if (pc_last_ssl)
shutdown_ssl(pc_last_ssl);
#endif
CLOSE (pc_last_fd);
invalidate_persistent (); invalidate_persistent ();
} }
} }
@ -446,34 +420,16 @@ register_persistent (const char *host, unsigned short port, int fd)
pc_last_port = port; pc_last_port = port;
pc_last_fd = fd; pc_last_fd = fd;
pc_active_p = 1; pc_active_p = 1;
#ifdef HAVE_SSL pc_last_ssl_p = ssl;
pc_last_ssl = ssl;
pc_active_ssl = ssl ? 1 : 0;
#endif
DEBUGP (("Registered fd %d for persistent reuse.\n", fd)); DEBUGP (("Registered fd %d for persistent reuse.\n", fd));
} }
#ifdef HAVE_SSL
# define SHUTDOWN_SSL(ssl) do { \
if (ssl) \
shutdown_ssl (ssl); \
} while (0)
#else
# define SHUTDOWN_SSL(ssl)
#endif
/* Return non-zero if a persistent connection is available for /* Return non-zero if a persistent connection is available for
connecting to HOST:PORT. */ connecting to HOST:PORT. */
#ifdef HAVE_SSL
static int static int
persistent_available_p (const char *host, unsigned short port, int ssl) persistent_available_p (const char *host, unsigned short port, int ssl)
{ {
#else
static int
persistent_available_p (const char *host, unsigned short port)
{
#endif
int success; int success;
struct address_list *this_host_ip; struct address_list *this_host_ip;
@ -485,15 +441,13 @@ persistent_available_p (const char *host, unsigned short port)
if (port != pc_last_port) if (port != pc_last_port)
return 0; return 0;
#ifdef HAVE_SSL
/* Second, a): check if current connection is (not) ssl, too. This /* Second, a): check if current connection is (not) ssl, too. This
test is unlikely to fail because HTTP and HTTPS typicaly use test is unlikely to fail because HTTP and HTTPS typicaly use
different ports. Yet it is possible, or so I [Christian different ports. Yet it is possible, or so I [Christian
Fraenkel] have been told, to run HTTPS and HTTP simultaneus on Fraenkel] have been told, to run HTTPS and HTTP simultaneus on
the same port. */ the same port. */
if (ssl != pc_active_ssl) if (ssl != pc_last_ssl_p)
return 0; return 0;
#endif /* HAVE_SSL */
this_host_ip = lookup_host (host, LH_SILENT); this_host_ip = lookup_host (host, LH_SILENT);
if (!this_host_ip) if (!this_host_ip)
@ -518,11 +472,7 @@ persistent_available_p (const char *host, unsigned short port)
/* Oops, the socket is no longer open. Now that we know that, /* Oops, the socket is no longer open. Now that we know that,
let's invalidate the persistent connection before returning let's invalidate the persistent connection before returning
0. */ 0. */
CLOSE (pc_last_fd); xclose (pc_last_fd);
#ifdef HAVE_SSL
SHUTDOWN_SSL (pc_last_ssl);
pc_last_ssl = NULL;
#endif
invalidate_persistent (); invalidate_persistent ();
return 0; return 0;
} }
@ -547,16 +497,14 @@ persistent_available_p (const char *host, unsigned short port)
#define CLOSE_FINISH(fd) do { \ #define CLOSE_FINISH(fd) do { \
if (!keep_alive) \ if (!keep_alive) \
{ \ { \
SHUTDOWN_SSL (ssl); \ xclose (fd); \
CLOSE (fd); \
if (pc_active_p && (fd) == pc_last_fd) \ if (pc_active_p && (fd) == pc_last_fd) \
invalidate_persistent (); \ invalidate_persistent (); \
} \ } \
} while (0) } while (0)
#define CLOSE_INVALIDATE(fd) do { \ #define CLOSE_INVALIDATE(fd) do { \
SHUTDOWN_SSL (ssl); \ xclose (fd); \
CLOSE (fd); \
if (pc_active_p && (fd) == pc_last_fd) \ if (pc_active_p && (fd) == pc_last_fd) \
invalidate_persistent (); \ invalidate_persistent (); \
} while (0) } while (0)
@ -637,8 +585,8 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
struct rbuf rbuf; struct rbuf rbuf;
#ifdef HAVE_SSL #ifdef HAVE_SSL
static SSL_CTX *ssl_ctx = NULL; static SSL_CTX *ssl_ctx = NULL;
SSL *ssl = NULL;
#endif #endif
int using_ssl = 0;
char *cookies = NULL; char *cookies = NULL;
/* Whether this connection will be kept alive after the HTTP request /* Whether this connection will be kept alive after the HTTP request
@ -734,14 +682,13 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
/* First: establish the connection. */ /* First: establish the connection. */
if (inhibit_keep_alive if (inhibit_keep_alive
|| || !persistent_available_p (conn->host, conn->port,
#ifndef HAVE_SSL #ifdef HAVE_SSL
!persistent_available_p (conn->host, conn->port) u->scheme == SCHEME_HTTPS
#else #else
!persistent_available_p (conn->host, conn->port, 0
u->scheme == SCHEME_HTTPS) #endif
#endif /* HAVE_SSL */ ))
)
{ {
sock = connect_to_host (conn->host, conn->port); sock = connect_to_host (conn->host, conn->port);
if (sock == E_HOST) if (sock == E_HOST)
@ -751,14 +698,17 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
#ifdef HAVE_SSL #ifdef HAVE_SSL
if (conn->scheme == SCHEME_HTTPS) if (conn->scheme == SCHEME_HTTPS)
if (connect_ssl (&ssl, ssl_ctx,sock) != 0) {
{ if (!connect_ssl (sock, ssl_ctx))
logputs (LOG_VERBOSE, "\n"); {
logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n")); logputs (LOG_VERBOSE, "\n");
ssl_printerrors (); logprintf (LOG_NOTQUIET,
CLOSE (sock); _("Unable to establish SSL connection.\n"));
return CONSSLERR; xclose (sock);
} return CONSSLERR;
}
using_ssl = 1;
}
#endif /* HAVE_SSL */ #endif /* HAVE_SSL */
} }
else else
@ -768,9 +718,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
/* #### pc_last_fd should be accessed through an accessor /* #### pc_last_fd should be accessed through an accessor
function. */ function. */
sock = pc_last_fd; sock = pc_last_fd;
#ifdef HAVE_SSL using_ssl = pc_last_ssl_p;
ssl = pc_last_ssl;
#endif /* HAVE_SSL */
DEBUGP (("Reusing fd %d.\n", sock)); DEBUGP (("Reusing fd %d.\n", sock));
} }
@ -991,36 +939,17 @@ Accept: %s\r\n\
xfree (full_path); xfree (full_path);
/* Send the request to server. */ /* Send the request to server. */
#ifdef HAVE_SSL write_error = xwrite (sock, request, strlen (request), -1);
if (conn->scheme == SCHEME_HTTPS)
write_error = ssl_iwrite (ssl, request, strlen (request));
else
#endif
write_error = iwrite (sock, request, strlen (request));
if (write_error >= 0) if (write_error >= 0)
{ {
if (opt.post_data) if (opt.post_data)
{ {
DEBUGP (("[POST data: %s]\n", opt.post_data)); DEBUGP (("[POST data: %s]\n", opt.post_data));
#ifdef HAVE_SSL write_error = xwrite (sock, opt.post_data, post_data_size, -1);
if (conn->scheme == SCHEME_HTTPS)
write_error = ssl_iwrite (ssl, opt.post_data, post_data_size);
else
#endif
write_error = iwrite (sock, opt.post_data, post_data_size);
} }
else if (opt.post_file_name && post_data_size != 0) else if (opt.post_file_name && post_data_size != 0)
{ write_error = post_file (sock, opt.post_file_name, post_data_size);
#ifdef HAVE_SSL
if (conn->scheme == SCHEME_HTTPS)
write_error = post_file (-1, ssl, opt.post_file_name,
post_data_size);
else
#endif
write_error = post_file (sock, NULL, opt.post_file_name,
post_data_size);
}
} }
DEBUGP (("---request end---\n")); DEBUGP (("---request end---\n"));
@ -1040,12 +969,6 @@ Accept: %s\r\n\
/* Before reading anything, initialize the rbuf. */ /* Before reading anything, initialize the rbuf. */
rbuf_initialize (&rbuf, sock); rbuf_initialize (&rbuf, sock);
#ifdef HAVE_SSL
if (conn->scheme == SCHEME_HTTPS)
rbuf.ssl = ssl;
else
rbuf.ssl = NULL;
#endif /* HAVE_SSL */
all_headers = NULL; all_headers = NULL;
all_length = 0; all_length = 0;
/* Header-fetching loop. */ /* Header-fetching loop. */
@ -1239,11 +1162,7 @@ Accept: %s\r\n\
if (keep_alive) if (keep_alive)
/* The server has promised that it will not close the connection /* The server has promised that it will not close the connection
when we're done. This means that we can register it. */ when we're done. This means that we can register it. */
#ifndef HAVE_SSL register_persistent (conn->host, conn->port, sock, using_ssl);
register_persistent (conn->host, conn->port, sock);
#else
register_persistent (conn->host, conn->port, sock, ssl);
#endif /* HAVE_SSL */
if ((statcode == HTTP_STATUS_UNAUTHORIZED) if ((statcode == HTTP_STATUS_UNAUTHORIZED)
&& authenticate_h) && authenticate_h)

View File

@ -98,10 +98,6 @@ so, delete this exception statement from your version. */
#define REALCLOSE(x) closesocket (x) #define REALCLOSE(x) closesocket (x)
/* read & write don't work with sockets on Windows 95. */
#define READ(fd, buf, cnt) recv ((fd), (buf), (cnt), 0)
#define WRITE(fd, buf, cnt) send ((fd), (buf), (cnt), 0)
/* #### Do we need this? */ /* #### Do we need this? */
#include <direct.h> #include <direct.h>

View File

@ -42,24 +42,10 @@ so, delete this exception statement from your version. */
#include "rbuf.h" #include "rbuf.h"
#include "connect.h" #include "connect.h"
#ifdef HAVE_SSL
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include "gen_sslfunc.h" /* for ssl_iread */
#endif /* HAVE_SSL */
void void
rbuf_initialize (struct rbuf *rbuf, int fd) rbuf_initialize (struct rbuf *rbuf, int fd)
{ {
rbuf->fd = fd; rbuf->fd = fd;
#ifdef HAVE_SSL
/* pointing ssl to NULL results in an unchanged behaviour */
rbuf->ssl = NULL;
#endif /* HAVE_SSL */
rbuf->buffer_pos = rbuf->buffer; rbuf->buffer_pos = rbuf->buffer;
rbuf->buffer_left = 0; rbuf->buffer_left = 0;
} }
@ -79,12 +65,7 @@ rbuf_uninitialize (struct rbuf *rbuf)
int int
rbuf_read_bufferful (struct rbuf *rbuf) rbuf_read_bufferful (struct rbuf *rbuf)
{ {
#ifdef HAVE_SSL return xread (rbuf->fd, rbuf->buffer, sizeof (rbuf->buffer), -1);
if (rbuf->ssl)
return ssl_iread (rbuf->ssl, rbuf->buffer, sizeof (rbuf->buffer));
else
#endif
return iread (rbuf->fd, rbuf->buffer, sizeof (rbuf->buffer));
} }
/* Currently unused -- see RBUF_READCHAR. */ /* Currently unused -- see RBUF_READCHAR. */
@ -106,15 +87,7 @@ rbuf_peek (struct rbuf *rbuf, char *store)
int res; int res;
rbuf->buffer_pos = rbuf->buffer; rbuf->buffer_pos = rbuf->buffer;
rbuf->buffer_left = 0; rbuf->buffer_left = 0;
#ifdef HAVE_SSL res = xread (rbuf->fd, rbuf->buffer, sizeof (rbuf->buffer), -1);
if (rbuf->ssl != NULL) {
res = ssl_iread (rbuf->ssl, rbuf->buffer, sizeof (rbuf->buffer));
} else {
#endif /* HAVE_SSL */
res = iread (rbuf->fd, rbuf->buffer, sizeof (rbuf->buffer));
#ifdef HAVE_SSL
}
#endif /* HAVE_SSL */
if (res <= 0) if (res <= 0)
return res; return res;
rbuf->buffer_left = res; rbuf->buffer_left = res;

View File

@ -30,17 +30,10 @@ so, delete this exception statement from your version. */
#ifndef RBUF_H #ifndef RBUF_H
#define RBUF_H #define RBUF_H
#ifdef HAVE_SSL
# include <openssl/ssl.h>
#endif
/* Retrieval stream */ /* Retrieval stream */
struct rbuf struct rbuf
{ {
int fd; int fd;
#ifdef HAVE_SSL
SSL *ssl; /* the ssl structure -- replaces fd for ssl connections */
#endif /* HAVE_SSL */
char buffer[4096]; /* the input buffer */ char buffer[4096]; /* the input buffer */
char *buffer_pos; /* current position in the buffer */ char *buffer_pos; /* current position in the buffer */
size_t buffer_left; /* number of bytes left in the buffer: size_t buffer_left; /* number of bytes left in the buffer:
@ -75,9 +68,6 @@ struct rbuf
/* Return the file descriptor of RBUF. */ /* Return the file descriptor of RBUF. */
#define RBUF_FD(rbuf) ((rbuf)->fd) #define RBUF_FD(rbuf) ((rbuf)->fd)
/* Return the file descriptor of RBUF. */
#define RBUF_SSL(rbuf) ((rbuf)->ssl)
/* Function declarations */ /* Function declarations */
void rbuf_initialize PARAMS ((struct rbuf *, int)); void rbuf_initialize PARAMS ((struct rbuf *, int));
int rbuf_initialized_p PARAMS ((struct rbuf *)); int rbuf_initialized_p PARAMS ((struct rbuf *));

View File

@ -213,12 +213,7 @@ get_contents (int fd, FILE *fp, long *len, long restval, long expected,
{ {
int amount_to_read = (use_expected int amount_to_read = (use_expected
? MIN (expected - *len, dlbufsize) : dlbufsize); ? MIN (expected - *len, dlbufsize) : dlbufsize);
#ifdef HAVE_SSL res = xread (fd, dlbuf, amount_to_read, -1);
if (rbuf->ssl!=NULL)
res = ssl_iread (rbuf->ssl, dlbuf, amount_to_read);
else
#endif /* HAVE_SSL */
res = iread (fd, dlbuf, amount_to_read);
if (res <= 0) if (res <= 0)
break; break;

View File

@ -108,33 +108,6 @@ so, delete this exception statement from your version. */
#endif #endif
#endif #endif
#ifdef __BEOS__
# undef READ
# undef WRITE
# define READ(fd, buf, cnt) recv ((fd), (buf), (cnt), 0)
# define WRITE(fd, buf, cnt) send ((fd), (buf), (cnt), 0)
#endif
/* mswindows.h defines these. */
#ifndef READ
# define READ(fd, buf, cnt) read ((fd), (buf), (cnt))
#endif
#ifndef WRITE
# define WRITE(fd, buf, cnt) write ((fd), (buf), (cnt))
#endif
#ifndef REALCLOSE
# define REALCLOSE(x) close (x)
#endif
#define CLOSE(x) do { \
int C_sock = (x); \
if (C_sock >= 0) \
{ \
REALCLOSE (C_sock); \
DEBUGP (("Closing fd %d\n", C_sock)); \
} \
} while (0)
/* Define a large integral type useful for storing large sizes that /* Define a large integral type useful for storing large sizes that
exceed sizes of one download, such as when printing the sum of all exceed sizes of one download, such as when printing the sum of all
downloads. Note that this has nothing to do with large file downloads. Note that this has nothing to do with large file