longer, read only that much; if the file is shorter, report an error. */
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];
long written = 0;
int write_error;
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));
fp = fopen (file_name, "rb");
if (length == 0)
break;
towrite = WMIN (promised_size - written, length);
-#ifdef HAVE_SSL
- if (ssl)
- write_error = ssl_iwrite (ssl, chunk, towrite);
- else
-#endif
- write_error = iwrite (sock, chunk, towrite);
+ write_error = xwrite (sock, chunk, towrite, -1);
if (write_error < 0)
{
fclose (fp);
/* The jar should have been created by now. */
assert (wget_cookie_jar != NULL);
- cookie_jar_process_set_cookie (wget_cookie_jar, u->host, u->port, u->path,
- hdr);
+ cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port, u->path, hdr);
return 1;
}
/* Whether a persistent connection is active. */
static int pc_active_p;
+
/* Host and port of currently active persistent connection. */
static struct address_list *pc_last_host_ip;
static unsigned short pc_last_port;
/* File descriptor of the currently active persistent connection. */
static int pc_last_fd;
-#ifdef HAVE_SSL
/* Whether a ssl handshake has occoured on this connection */
-static int pc_active_ssl;
-/* SSL connection of the currently active persistent connection. */
-static SSL *pc_last_ssl;
-#endif /* HAVE_SSL */
+static int pc_last_ssl_p;
/* Mark the persistent connection as invalid. This is used by the
CLOSE_* macros after they forcefully close a registered persistent
invalidate_persistent (void)
{
pc_active_p = 0;
-#ifdef HAVE_SSL
- pc_active_ssl = 0;
-#endif /* HAVE_SSL */
+ pc_last_ssl_p = 0;
if (pc_last_host_ip != NULL)
{
address_list_release (pc_last_host_ip);
If a previous connection was persistent, it is closed. */
-#ifdef HAVE_SSL
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_last_fd == fd)
persistent connection exists, but we then connect to a
different host, and try to register a persistent
connection to that one. */
-#ifdef HAVE_SSL
- /* 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);
+ xclose (pc_last_fd);
invalidate_persistent ();
}
}
/* This lookup_host cannot fail, because it has the results in the
cache. */
- pc_last_host_ip = lookup_host (host, 1);
+ pc_last_host_ip = lookup_host (host, LH_SILENT);
assert (pc_last_host_ip != NULL);
pc_last_port = port;
pc_last_fd = fd;
pc_active_p = 1;
-#ifdef HAVE_SSL
- pc_last_ssl = ssl;
- pc_active_ssl = ssl ? 1 : 0;
-#endif
+ pc_last_ssl_p = ssl;
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
connecting to HOST:PORT. */
-#ifdef HAVE_SSL
static int
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;
struct address_list *this_host_ip;
if (port != pc_last_port)
return 0;
-#ifdef HAVE_SSL
/* Second, a): check if current connection is (not) ssl, too. This
test is unlikely to fail because HTTP and HTTPS typicaly use
different ports. Yet it is possible, or so I [Christian
Fraenkel] have been told, to run HTTPS and HTTP simultaneus on
the same port. */
- if (ssl != pc_active_ssl)
+ if (ssl != pc_last_ssl_p)
return 0;
-#endif /* HAVE_SSL */
- this_host_ip = lookup_host (host, 1);
+ this_host_ip = lookup_host (host, LH_SILENT);
if (!this_host_ip)
return 0;
/* Oops, the socket is no longer open. Now that we know that,
let's invalidate the persistent connection before returning
0. */
- CLOSE (pc_last_fd);
-#ifdef HAVE_SSL
- SHUTDOWN_SSL (pc_last_ssl);
- pc_last_ssl = NULL;
-#endif
+ xclose (pc_last_fd);
invalidate_persistent ();
return 0;
}
#define CLOSE_FINISH(fd) do { \
if (!keep_alive) \
{ \
- SHUTDOWN_SSL (ssl); \
- CLOSE (fd); \
+ xclose (fd); \
if (pc_active_p && (fd) == pc_last_fd) \
invalidate_persistent (); \
} \
} while (0)
#define CLOSE_INVALIDATE(fd) do { \
- SHUTDOWN_SSL (ssl); \
- CLOSE (fd); \
+ xclose (fd); \
if (pc_active_p && (fd) == pc_last_fd) \
invalidate_persistent (); \
} while (0)
static void
free_hstat (struct http_stat *hs)
{
- FREE_MAYBE (hs->newloc);
- FREE_MAYBE (hs->remote_time);
- FREE_MAYBE (hs->error);
+ xfree_null (hs->newloc);
+ xfree_null (hs->remote_time);
+ xfree_null (hs->error);
/* Guard against being called twice. */
hs->newloc = NULL;
struct rbuf rbuf;
#ifdef HAVE_SSL
static SSL_CTX *ssl_ctx = NULL;
- SSL *ssl = NULL;
#endif
+ int using_ssl = 0;
char *cookies = NULL;
/* Whether this connection will be kept alive after the HTTP request
/* First: establish the connection. */
if (inhibit_keep_alive
- ||
-#ifndef HAVE_SSL
- !persistent_available_p (conn->host, conn->port)
+ || !persistent_available_p (conn->host, conn->port,
+#ifdef HAVE_SSL
+ u->scheme == SCHEME_HTTPS
#else
- !persistent_available_p (conn->host, conn->port,
- u->scheme == SCHEME_HTTPS)
-#endif /* HAVE_SSL */
- )
+ 0
+#endif
+ ))
{
- struct address_list *al = lookup_host (conn->host, 0);
- if (!al)
+ sock = connect_to_host (conn->host, conn->port);
+ if (sock == E_HOST)
return HOSTERR;
- set_connection_host_name (conn->host);
- sock = connect_to_many (al, conn->port, 0);
- set_connection_host_name (NULL);
- address_list_release (al);
-
- if (sock < 0)
+ else if (sock < 0)
return CONNECT_ERROR (errno);
#ifdef HAVE_SSL
if (conn->scheme == SCHEME_HTTPS)
- if (connect_ssl (&ssl, ssl_ctx,sock) != 0)
- {
- logputs (LOG_VERBOSE, "\n");
- logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
- ssl_printerrors ();
- CLOSE (sock);
- return CONSSLERR;
- }
+ {
+ if (!connect_ssl (sock, ssl_ctx))
+ {
+ logputs (LOG_VERBOSE, "\n");
+ logprintf (LOG_NOTQUIET,
+ _("Unable to establish SSL connection.\n"));
+ xclose (sock);
+ return CONSSLERR;
+ }
+ using_ssl = 1;
+ }
#endif /* HAVE_SSL */
}
else
/* #### pc_last_fd should be accessed through an accessor
function. */
sock = pc_last_fd;
-#ifdef HAVE_SSL
- ssl = pc_last_ssl;
-#endif /* HAVE_SSL */
+ using_ssl = pc_last_ssl_p;
DEBUGP (("Reusing fd %d.\n", sock));
}
request_keep_alive = NULL;
if (opt.cookies)
- cookies = cookie_jar_generate_cookie_header (wget_cookie_jar, u->host,
- u->port, u->path,
+ cookies = cookie_header (wget_cookie_jar, u->host, u->port, u->path,
#ifdef HAVE_SSL
- u->scheme == SCHEME_HTTPS
+ u->scheme == SCHEME_HTTPS
#else
- 0
+ 0
#endif
- );
+ );
if (opt.post_data || opt.post_file_name)
{
DEBUGP (("---request begin---\n%s", request));
/* Free the temporary memory. */
- FREE_MAYBE (wwwauth);
- FREE_MAYBE (proxyauth);
- FREE_MAYBE (cookies);
+ xfree_null (wwwauth);
+ xfree_null (proxyauth);
+ xfree_null (cookies);
xfree (full_path);
/* Send the request to server. */
-#ifdef HAVE_SSL
- if (conn->scheme == SCHEME_HTTPS)
- write_error = ssl_iwrite (ssl, request, strlen (request));
- else
-#endif
- write_error = iwrite (sock, request, strlen (request));
+ write_error = xwrite (sock, request, strlen (request), -1);
if (write_error >= 0)
{
if (opt.post_data)
{
DEBUGP (("[POST data: %s]\n", opt.post_data));
-#ifdef HAVE_SSL
- 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);
+ write_error = xwrite (sock, opt.post_data, post_data_size, -1);
}
else if (opt.post_file_name && post_data_size != 0)
- {
-#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);
- }
+ write_error = post_file (sock, opt.post_file_name, post_data_size);
}
DEBUGP (("---request end---\n"));
/* Before reading anything, initialize the rbuf. */
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_length = 0;
/* Header-fetching loop. */
logputs (LOG_VERBOSE, "\n");
logputs (LOG_NOTQUIET, _("End of file while parsing headers.\n"));
xfree (hdr);
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return HEOF;
}
logprintf (LOG_NOTQUIET, _("Read error (%s) in headers.\n"),
strerror (errno));
xfree (hdr);
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return HERR;
}
if (keep_alive)
/* The server has promised that it will not close the connection
when we're done. This means that we can register it. */
-#ifndef HAVE_SSL
- register_persistent (conn->host, conn->port, sock);
-#else
- register_persistent (conn->host, conn->port, sock, ssl);
-#endif /* HAVE_SSL */
+ register_persistent (conn->host, conn->port, sock, using_ssl);
if ((statcode == HTTP_STATUS_UNAUTHORIZED)
&& authenticate_h)
{
/* Authorization is required. */
- FREE_MAYBE (type);
+ xfree_null (type);
type = NULL;
free_hstat (hs);
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
hs->newloc ? _(" [following]") : "");
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
return NEWLOCATION;
}
}
{
char* last_period_in_local_filename = strrchr(*hs->local_file, '.');
- if (last_period_in_local_filename == NULL ||
- !(strcasecmp(last_period_in_local_filename, ".htm") == EQ ||
- strcasecmp(last_period_in_local_filename, ".html") == EQ))
+ if (last_period_in_local_filename == NULL
+ || !(0 == strcasecmp (last_period_in_local_filename, ".htm")
+ || 0 == strcasecmp (last_period_in_local_filename, ".html")))
{
size_t local_filename_len = strlen(*hs->local_file);
hs->res = 0;
/* Mark as successfully retrieved. */
*dt |= RETROKF;
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
return RETRUNNEEDED;
\n\
Continued download failed on this file, which conflicts with `-c'.\n\
Refusing to truncate existing file `%s'.\n\n"), *hs->local_file);
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return CONTNOTSUPPORTED;
}
{
/* This means the whole request was somehow misunderstood by the
server. Bail out. */
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock);
return RANGEERR;
}
logputs (LOG_VERBOSE, "\n");
}
}
- FREE_MAYBE (type);
+ xfree_null (type);
type = NULL; /* We don't need it any more. */
/* Return if we have no intention of further downloading. */
/* In case the caller cares to look... */
hs->len = 0L;
hs->res = 0;
- FREE_MAYBE (type);
- FREE_MAYBE (all_headers);
+ xfree_null (type);
+ xfree_null (all_headers);
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
return RETRFINISHED;
logprintf (LOG_NOTQUIET, "%s: %s\n", *hs->local_file, strerror (errno));
CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there
might be more bytes in the body. */
- FREE_MAYBE (all_headers);
+ xfree_null (all_headers);
return FOPENERR;
}
}
if (flush_res == EOF)
hs->res = -2;
}
- FREE_MAYBE (all_headers);
+ xfree_null (all_headers);
if (hs->res == -2)
return FWRITEERR;
return RETRFINISHED;
if (has_html_suffix_p (*hstat.local_file))
*dt |= TEXTHTML;
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
use_ts = 0;
if (opt.timestamping)
{
- boolean local_dot_orig_file_exists = FALSE;
+ int local_dot_orig_file_exists = 0;
if (opt.backup_converted)
/* If -K is specified, we'll act on the assumption that it was specified
/* Try to stat() the .orig file. */
if (stat (filename_plus_orig_suffix, &st) == 0)
{
- local_dot_orig_file_exists = TRUE;
+ local_dot_orig_file_exists = 1;
local_filename = filename_plus_orig_suffix;
}
}
printwhat (count, opt.ntry);
continue;
break;
- case HOSTERR: case CONREFUSED: case PROXERR: case AUTHFAILED:
+ case HOSTERR: case CONIMPOSSIBLE: case PROXERR: case AUTHFAILED:
case SSLERRCTXCREATE: case CONTNOTSUPPORTED:
/* Fatal errors just return from the function. */
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return err;
break;
case FWRITEERR: case FOPENERR:
logprintf (LOG_NOTQUIET, _("Cannot write to `%s' (%s).\n"),
*hstat.local_file, strerror (errno));
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return err;
break;
case CONSSLERR:
logputs (LOG_VERBOSE, "\n");
logprintf (LOG_NOTQUIET, _("Unable to establish SSL connection.\n"));
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return err;
break;
case NEWLOCATION:
_("ERROR: Redirection (%d) without location.\n"),
hstat.statcode);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return WRONGCODE;
}
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return NEWLOCATION;
break;
case RETRUNNEEDED:
/* The file was already fully retrieved. */
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
break;
case RETRFINISHED:
tms, hstat.statcode, hstat.error);
logputs (LOG_VERBOSE, "\n");
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return WRONGCODE;
}
Server file no newer than local file `%s' -- not retrieving.\n\n"),
local_filename);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else if (tml >= tmr)
if (opt.spider)
{
logprintf (LOG_NOTQUIET, "%d %s\n\n", hstat.statcode, hstat.error);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else if (hstat.res == 0) /* No read error */
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else if (hstat.len < hstat.contlen) /* meaning we lost the
downloaded_file(FILE_DOWNLOADED_NORMALLY, locf);
free_hstat (&hstat);
- FREE_MAYBE (dummy);
+ xfree_null (dummy);
return RETROK;
}
else /* the same, but not accepted */
;
if (!*ep)
return -1;
- FREE_MAYBE (*ret);
+ xfree_null (*ret);
*ret = strdupdelim (cp, ep);
return ep - au + 1;
}
options[i].variable);
if (skip < 0)
{
- FREE_MAYBE (realm);
- FREE_MAYBE (opaque);
- FREE_MAYBE (nonce);
+ xfree_null (realm);
+ xfree_null (opaque);
+ xfree_null (nonce);
return NULL;
}
else if (skip)
}
if (!realm || !nonce || !user || !passwd || !path || !method)
{
- FREE_MAYBE (realm);
- FREE_MAYBE (opaque);
- FREE_MAYBE (nonce);
+ xfree_null (realm);
+ xfree_null (opaque);
+ xfree_null (nonce);
return NULL;
}