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

Fix some problems with GNU TLS.

This commit is contained in:
Giuseppe Scrivano 2010-06-14 19:40:03 +02:00
parent 117c25970b
commit b7814f7cf3
3 changed files with 35 additions and 17 deletions

2
NEWS
View File

@ -29,6 +29,8 @@ Please send GNU Wget bug reports to <bug-wget@gnu.org>.
** Report the average transfer speed correctly when multiple URL's are specified ** Report the average transfer speed correctly when multiple URL's are specified
and -c influences the transferred data amount. and -c influences the transferred data amount.
** GNU TLS backend works again.
* Changes in Wget 1.12 * Changes in Wget 1.12

View File

@ -1,5 +1,14 @@
2010-06-14 Giuseppe Scrivano <gscrivano@gnu.org> 2010-06-14 Giuseppe Scrivano <gscrivano@gnu.org>
* gnutls.c: Include <stdlib.h>.
(struct wgnutls_transport_context): Remove `peekstart'.
(ssl_connect_wget): Renamed from `ssl_connect'.
(wgnutls_poll): New variable `ctx'.
(wgnutls_read): Don't use `ctx->peekstart'.
(wgnutls_peek): Likewise. Don't attempt to read if there is not
ready data.
2010-06-14 Giuseppe Scrivano <gscrivano@gnu.org>
* http.c (http_loop): Always send a HEAD request when -N is used * http.c (http_loop): Always send a HEAD request when -N is used
together with --content-disposition. together with --content-disposition.
Reported by: Jochen Roderburg <Roderburg@Uni-Koeln.DE>. Reported by: Jochen Roderburg <Roderburg@Uni-Koeln.DE>.

View File

@ -37,6 +37,7 @@ as that of the covered work. */
#endif #endif
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <gnutls/gnutls.h> #include <gnutls/gnutls.h>
#include <gnutls/x509.h> #include <gnutls/x509.h>
@ -73,7 +74,7 @@ struct wgnutls_transport_context {
is stored to PEEKBUF, and wgnutls_read checks that buffer before is stored to PEEKBUF, and wgnutls_read checks that buffer before
actually reading. */ actually reading. */
char peekbuf[512]; char peekbuf[512];
int peekstart, peeklen; int peeklen;
}; };
#ifndef MIN #ifndef MIN
@ -83,19 +84,18 @@ struct wgnutls_transport_context {
static int static int
wgnutls_read (int fd, char *buf, int bufsize, void *arg) wgnutls_read (int fd, char *buf, int bufsize, void *arg)
{ {
int ret; int ret = 0;
struct wgnutls_transport_context *ctx = arg; struct wgnutls_transport_context *ctx = arg;
if (ctx->peeklen) if (ctx->peeklen)
{ {
/* If we have any peek data, simply return that. */ /* If we have any peek data, simply return that. */
int copysize = MIN (bufsize, ctx->peeklen); int copysize = MIN (bufsize, ctx->peeklen);
memcpy (buf, ctx->peekbuf + ctx->peekstart, copysize); memcpy (buf, ctx->peekbuf, copysize);
ctx->peeklen -= copysize; ctx->peeklen -= copysize;
if (ctx->peeklen != 0) if (ctx->peeklen != 0)
ctx->peekstart += copysize; memmove (ctx->peekbuf, ctx->peekbuf + copysize, ctx->peeklen);
else
ctx->peekstart = 0;
return copysize; return copysize;
} }
@ -124,31 +124,38 @@ wgnutls_write (int fd, char *buf, int bufsize, void *arg)
static int static int
wgnutls_poll (int fd, double timeout, int wait_for, void *arg) wgnutls_poll (int fd, double timeout, int wait_for, void *arg)
{ {
return 1; struct wgnutls_transport_context *ctx = arg;
return ctx->peeklen || gnutls_record_check_pending (ctx->session)
|| select_fd (fd, timeout, wait_for);
} }
static int static int
wgnutls_peek (int fd, char *buf, int bufsize, void *arg) wgnutls_peek (int fd, char *buf, int bufsize, void *arg)
{ {
int ret; int ret = 0;
struct wgnutls_transport_context *ctx = arg; struct wgnutls_transport_context *ctx = arg;
int offset = ctx->peeklen;
/* We don't support peeks following peeks: the reader must drain all
peeked data before the next peek. */
assert (ctx->peeklen == 0);
if (bufsize > sizeof ctx->peekbuf) if (bufsize > sizeof ctx->peekbuf)
bufsize = sizeof ctx->peekbuf; bufsize = sizeof ctx->peekbuf;
if (offset)
memcpy (buf, ctx->peekbuf, offset);
do do
ret = gnutls_record_recv (ctx->session, buf, bufsize); {
if (gnutls_record_check_pending (ctx->session)
|| select_fd (fd, 0, WAIT_FOR_READ))
ret = gnutls_record_recv (ctx->session, buf + offset, bufsize - offset);
}
while (ret == GNUTLS_E_INTERRUPTED); while (ret == GNUTLS_E_INTERRUPTED);
if (ret >= 0) if (ret > 0)
{ {
memcpy (ctx->peekbuf, buf, ret); memcpy (ctx->peekbuf + offset, buf + offset, ret);
ctx->peeklen = ret; ctx->peeklen += ret;
} }
return ret; return ctx->peeklen;
} }
static const char * static const char *
@ -177,7 +184,7 @@ static struct transport_implementation wgnutls_transport = {
}; };
bool bool
ssl_connect (int fd) ssl_connect_wget (int fd)
{ {
static const int cert_type_priority[] = { static const int cert_type_priority[] = {
GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0