pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/net/libfetch libfetch-2.17:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/07aabac34a43
branches:  trunk
changeset: 548020:07aabac34a43
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Mon Oct 06 23:37:56 2008 +0000

description:
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:

 net/libfetch/Makefile       |   4 ++--
 net/libfetch/files/common.c |  30 +++++++++++++++++++++++-------
 net/libfetch/files/common.h |   4 +++-
 3 files changed, 28 insertions(+), 10 deletions(-)

diffs (109 lines):

diff -r e44b010d2dbc -r 07aabac34a43 net/libfetch/Makefile
--- a/net/libfetch/Makefile     Mon Oct 06 22:40:12 2008 +0000
+++ b/net/libfetch/Makefile     Mon Oct 06 23:37:56 2008 +0000
@@ -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 -r e44b010d2dbc -r 07aabac34a43 net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Mon Oct 06 22:40:12 2008 +0000
+++ b/net/libfetch/files/common.c       Mon Oct 06 23:37:56 2008 +0000
@@ -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@localhost>
@@ -234,6 +234,8 @@
        /* 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 @@
        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 @@
 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 @@
                        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 @@
                        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 -r e44b010d2dbc -r 07aabac34a43 net/libfetch/files/common.h
--- a/net/libfetch/files/common.h       Mon Oct 06 22:40:12 2008 +0000
+++ b/net/libfetch/files/common.h       Mon Oct 06 23:37:56 2008 +0000
@@ -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 @@
        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 */



Home | Main Index | Thread Index | Old Index