diff options
author | joerg <joerg> | 2008-10-06 23:37:56 +0000 |
---|---|---|
committer | joerg <joerg> | 2008-10-06 23:37:56 +0000 |
commit | e1261362fd6b40e2408078db398afda6e4937e19 (patch) | |
tree | 0651c8b0fc33f3eae159e8470323a8b62908b701 /net/libfetch | |
parent | 75b2eb1232576d7c3ca38f2ee82c1e74b0574e72 (diff) | |
download | pkgsrc-e1261362fd6b40e2408078db398afda6e4937e19.tar.gz |
libfetch-2.17:
Fix line buffering to not drop content after the line we are interested
in. This magically worked for a local tnftpd that was only sending a
normal one line return message due to the challenge response protocol
always having the desired size. With the patch fetch_read will process
the remaining part of the buffer and fetch_getln will remember how much
of the data it was actually interested in, so it will now process the
complete output again.
Diffstat (limited to 'net/libfetch')
-rw-r--r-- | net/libfetch/Makefile | 4 | ||||
-rw-r--r-- | net/libfetch/files/common.c | 30 | ||||
-rw-r--r-- | net/libfetch/files/common.h | 4 |
3 files changed, 28 insertions, 10 deletions
diff --git a/net/libfetch/Makefile b/net/libfetch/Makefile index 68e94adf9b7..5130389b405 100644 --- a/net/libfetch/Makefile +++ b/net/libfetch/Makefile @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.19 2008/10/06 12:58:29 joerg Exp $ +# $NetBSD: Makefile,v 1.20 2008/10/06 23:37:56 joerg Exp $ # -DISTNAME= libfetch-2.16 +DISTNAME= libfetch-2.17 CATEGORIES= net MASTER_SITES= # empty DISTFILES= # empty diff --git a/net/libfetch/files/common.c b/net/libfetch/files/common.c index 77060d5ca71..b204eff6431 100644 --- a/net/libfetch/files/common.c +++ b/net/libfetch/files/common.c @@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.14 2008/10/06 12:58:29 joerg Exp $ */ +/* $NetBSD: common.c,v 1.15 2008/10/06 23:37:56 joerg Exp $ */ /*- * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org> @@ -234,6 +234,8 @@ fetch_reopen(int sd) /* allocate and fill connection structure */ if ((conn = calloc(1, sizeof(*conn))) == NULL) return (NULL); + conn->next_buf = NULL; + conn->next_len = 0; conn->sd = sd; ++conn->ref; return (conn); @@ -405,6 +407,15 @@ fetch_read(conn_t *conn, char *buf, size_t len) if (len == 0) return 0; + if (conn->next_len != 0) { + if (conn->next_len < len) + len = conn->next_len; + memmove(buf, conn->next_buf, len); + conn->next_len -= len; + conn->next_buf += len; + return len; + } + if (fetchTimeout) { FD_ZERO(&readfds); gettimeofday(&timeout, NULL); @@ -459,13 +470,12 @@ fetch_read(conn_t *conn, char *buf, size_t len) int fetch_getln(conn_t *conn) { - char *tmp; + char *tmp, *next; size_t tmpsize; ssize_t len; - int done; if (conn->buf == NULL) { - if ((conn->buf = malloc(MIN_BUF_SIZE)) == NULL) { + if ((conn->buf = malloc(MIN_BUF_SIZE + 1)) == NULL) { errno = ENOMEM; return (-1); } @@ -482,9 +492,10 @@ fetch_getln(conn_t *conn) return (-1); if (len == 0) break; - done = memchr(conn->buf + conn->buflen, '\n', len) != NULL; + next = memchr(conn->buf + conn->buflen, '\n', len); conn->buflen += len; - if (conn->buflen == conn->bufsize) { + if (conn->buflen == conn->bufsize && + (next == NULL || next[1] == '\0')) { tmp = conn->buf; tmpsize = conn->bufsize * 2 + 1; if ((tmp = realloc(tmp, tmpsize)) == NULL) { @@ -494,8 +505,13 @@ fetch_getln(conn_t *conn) conn->buf = tmp; conn->bufsize = tmpsize; } - } while (!done); + } while (next == NULL); + if (next != NULL) { + conn->next_buf = next + 1; + conn->next_len = conn->buflen - (conn->next_buf - conn->buf); + conn->buflen = next - conn->buf; + } conn->buf[conn->buflen] = '\0'; return (0); } diff --git a/net/libfetch/files/common.h b/net/libfetch/files/common.h index 97f0be49e7e..bddae5a3720 100644 --- a/net/libfetch/files/common.h +++ b/net/libfetch/files/common.h @@ -1,4 +1,4 @@ -/* $NetBSD: common.h,v 1.9 2008/10/06 12:58:29 joerg Exp $ */ +/* $NetBSD: common.h,v 1.10 2008/10/06 23:37:56 joerg Exp $ */ /*- * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav * All rights reserved. @@ -57,6 +57,8 @@ struct fetchconn { char *buf; /* buffer */ size_t bufsize; /* buffer size */ size_t buflen; /* length of buffer contents */ + 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 */ |