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.26:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/ccbbdcd1b6de
branches:  trunk
changeset: 566129:ccbbdcd1b6de
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Thu Oct 15 12:36:57 2009 +0000

description:
libfetch-2.26:
- Add support to aggressively cache directory listenings, useful for
HTTP
- Avoid leaking memory in error cases. From Xavier from Arch Linux.

diffstat:

 net/libfetch/Makefile         |   4 +-
 net/libfetch/files/common.c   |  36 +++++++++++++++++-
 net/libfetch/files/fetch.3    |  11 ++++-
 net/libfetch/files/fetch.cat3 |   8 +++-
 net/libfetch/files/fetch.h    |   3 +-
 net/libfetch/files/file.c     |  11 +++-
 net/libfetch/files/ftp.c      |  40 ++++++++++++++----
 net/libfetch/files/http.c     |  88 +++++++++++++++++++++++++++++++++++++-----
 8 files changed, 170 insertions(+), 31 deletions(-)

diffs (truncated from 442 to 300 lines):

diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/Makefile
--- a/net/libfetch/Makefile     Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/Makefile     Thu Oct 15 12:36:57 2009 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.32 2009/08/16 20:31:29 joerg Exp $
+# $NetBSD: Makefile,v 1.33 2009/10/15 12:36:57 joerg Exp $
 #
 
-DISTNAME=      libfetch-2.25
+DISTNAME=      libfetch-2.26
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/files/common.c       Thu Oct 15 12:36:57 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.20 2009/08/16 20:31:29 joerg Exp $        */
+/*     $NetBSD: common.c,v 1.21 2009/10/15 12:36:57 joerg Exp $        */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -753,6 +753,40 @@
        ue->urls = NULL;
 }
 
+int
+fetchAppendURLList(struct url_list *dst, const struct url_list *src)
+{
+       size_t i, j, len;
+
+       len = dst->length + src->length;
+       if (len > dst->alloc_size) {
+               struct url *tmp;
+
+               tmp = realloc(dst->urls, len * sizeof(*tmp));
+               if (tmp == NULL) {
+                       errno = ENOMEM;
+                       fetch_syserr();
+                       return (-1);
+               }
+               dst->alloc_size = len;
+               dst->urls = tmp;
+       }
+
+       for (i = 0, j = dst->length; i < src->length; ++i, ++j) {
+               dst->urls[j] = src->urls[i];
+               dst->urls[j].doc = strdup(src->urls[i].doc);
+               if (dst->urls[j].doc == NULL) {
+                       while (i-- > 0)
+                               free(dst->urls[j].doc);
+                       fetch_syserr();
+                       return -1;
+               }
+       }
+       dst->length = len;
+
+       return 0;
+}
+
 void
 fetchFreeURLList(struct url_list *ue)
 {
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/fetch.3
--- a/net/libfetch/files/fetch.3        Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/files/fetch.3        Thu Oct 15 12:36:57 2009 +0000
@@ -24,7 +24,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $FreeBSD: fetch.3,v 1.64 2007/12/18 11:03:26 des Exp $
-.\" $NetBSD: fetch.3,v 1.12 2009/03/16 18:11:39 joerg Exp $
+.\" $NetBSD: fetch.3,v 1.13 2009/10/15 12:36:57 joerg Exp $
 .\"
 .Dd February 4, 2009
 .Dt FETCH 3
@@ -131,6 +131,8 @@
 .Fn fetchListFTP "struct url_list *list" "struct url *u" "const char *flags"
 .Ft void
 .Fn fetchInitURLList "struct url_list *ul"
+.Ft int
+.Fn fetchAppendURLList "struct url_list *dst" "const struct url_list *src"
 .Ft void
 .Fn fetchFreeURLList "struct url_list *ul"
 .Ft char *
@@ -281,6 +283,13 @@
 .Fn fetchInitURLList
 and the entries be freed by calling
 .Fn fetchFreeURLList .
+The function
+.Fn fetchAppendURLList
+can be used to append one URL lists to another.
+If the
+.Ql c
+(cache result) flag is specified, the library is allowed to internally
+cache the result.
 .Pp
 .Fn fetchStringifyURL
 returns the URL as string.
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/fetch.cat3
--- a/net/libfetch/files/fetch.cat3     Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/files/fetch.cat3     Thu Oct 15 12:36:57 2009 +0000
@@ -108,6 +108,9 @@
      _v_o_i_d
      ffeettcchhIInniittUURRLLLLiisstt(_s_t_r_u_c_t _u_r_l___l_i_s_t _*_u_l);
 
+     _i_n_t
+     ffeettcchhAAppppeennddUURRLLLLiisstt(_s_t_r_u_c_t _u_r_l___l_i_s_t _*_d_s_t, _c_o_n_s_t _s_t_r_u_c_t _u_r_l___l_i_s_t _*_s_r_c);
+
      _v_o_i_d
      ffeettcchhFFrreeeeUURRLLLLiisstt(_s_t_r_u_c_t _u_r_l___l_i_s_t _*_u_l);
 
@@ -204,7 +207,10 @@
      };
 
      The list should be initialized by calling ffeettcchhIInniittUURRLLLLiisstt() and the
-     entries be freed by calling ffeettcchhFFrreeeeUURRLLLLiisstt().
+     entries be freed by calling ffeettcchhFFrreeeeUURRLLLLiisstt().  The functio
+     ffeettcchhAAppppeennddUURRLLLLiisstt() can be used to append one URL lists to another.  If
+     the `c' (cache result) flag is specified, the library is allowed to
+     internally cache the result.
 
      ffeettcchhSSttrriinnggiiffyyUURRLL() returns the URL as string.  ffeettcchhUUnnqquuootteePPaatthh()
      returns the path name part of the URL with any quoting undone.  Query
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/fetch.h
--- a/net/libfetch/files/fetch.h        Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/files/fetch.h        Thu Oct 15 12:36:57 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.h,v 1.14 2009/02/05 22:45:25 joerg Exp $ */
+/*     $NetBSD: fetch.h,v 1.15 2009/10/15 12:36:57 joerg Exp $ */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -153,6 +153,7 @@
 
 /* URL listening */
 void            fetchInitURLList(struct url_list *);
+int             fetchAppendURLList(struct url_list *, const struct url_list *);
 void            fetchFreeURLList(struct url_list *);
 char           *fetchUnquotePath(struct url *);
 char           *fetchUnquoteFilename(struct url *);
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/file.c
--- a/net/libfetch/files/file.c Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/files/file.c Thu Oct 15 12:36:57 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file.c,v 1.14 2009/03/10 00:33:38 joerg Exp $  */
+/*     $NetBSD: file.c,v 1.15 2009/10/15 12:36:57 joerg Exp $  */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -234,6 +234,7 @@
        char *path;
        struct dirent *de;
        DIR *dir;
+       int ret;
 
        if ((path = fetchUnquotePath(u)) == NULL) {
                fetch_syserr();
@@ -248,13 +249,17 @@
                return -1;
        }
 
+       ret = 0;
+
        while ((de = readdir(dir)) != NULL) {
                if (pattern && fnmatch(pattern, de->d_name, 0) != 0)
                        continue;
-               fetch_add_entry(ue, u, de->d_name, 0);
+               ret = fetch_add_entry(ue, u, de->d_name, 0);
+               if (ret)
+                       break;
        }
 
        closedir(dir);
 
-       return 0;
+       return ret;
 }
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/ftp.c
--- a/net/libfetch/files/ftp.c  Thu Oct 15 12:28:47 2009 +0000
+++ b/net/libfetch/files/ftp.c  Thu Oct 15 12:36:57 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftp.c,v 1.29 2009/08/16 20:31:29 joerg Exp $   */
+/*     $NetBSD: ftp.c,v 1.30 2009/10/15 12:36:57 joerg Exp $   */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -587,8 +587,10 @@
        io->dconn->is_active = 0;
        io->dconn = NULL;
        r = ftp_chkerr(io->cconn);
-       if (io->cconn == cached_connection && io->cconn->ref == 1)
+       if (io->cconn == cached_connection && io->cconn->ref == 1) {
+               free(cached_host.doc);
                cached_connection = NULL;
+       }
        fetch_close(io->cconn);
        free(io);
        return;
@@ -1038,8 +1040,11 @@
 ftp_disconnect(conn_t *conn)
 {
        (void)ftp_cmd(conn, "QUIT");
-       if (conn == cached_connection && conn->ref == 1)
+       if (conn == cached_connection && conn->ref == 1) {
+               free(cached_host.doc);
+               cached_host.doc = NULL;
                cached_connection = NULL;
+       }
        fetch_close(conn);
 }
 
@@ -1063,6 +1068,7 @@
 static conn_t *
 ftp_cached_connect(struct url *url, struct url *purl, const char *flags)
 {
+       char *doc;
        conn_t *conn;
        int e;
 
@@ -1080,10 +1086,14 @@
        /* connect to server */
        if ((conn = ftp_connect(url, purl, flags)) == NULL)
                return (NULL);
-       if (cached_connection)
-               ftp_disconnect(cached_connection);
-       cached_connection = fetch_ref(conn);
-       memcpy(&cached_host, url, sizeof(*url));
+       doc = strdup(url->doc);
+       if (doc != NULL) {
+               if (cached_connection)
+                       ftp_disconnect(cached_connection);
+               cached_connection = fetch_ref(conn);
+               memcpy(&cached_host, url, sizeof(*url));
+               cached_host.doc = doc;
+       }
        return (conn);
 }
 
@@ -1176,14 +1186,17 @@
 
        if (if_modified_since && url->last_modified > 0 &&
            url->last_modified >= us->mtime) {
+               free(path);
                fetchLastErrCode = FETCH_UNCHANGED;
                snprintf(fetchLastErrString, MAXERRSTRING, "Unchanged");
                return NULL;
        }
 
        /* just a stat */
-       if (strcmp(op, "STAT") == 0)
+       if (strcmp(op, "STAT") == 0) {
+               free(path);
                return fetchIO_unopen(NULL, NULL, NULL, NULL);
+       }
        if (strcmp(op, "STOR") == 0 || strcmp(op, "APPE") == 0)
                oflag = O_WRONLY;
        else
@@ -1248,6 +1261,7 @@
        char buf[2 * PATH_MAX], *eol, *eos;
        ssize_t len;
        size_t cur_off;
+       int ret;
 
        /* XXX What about proxies? */
        if (pattern == NULL || strcmp(pattern, "*") == 0)
@@ -1257,6 +1271,8 @@
                return -1;
 
        cur_off = 0;
+       ret = 0;
+
        while ((len = fetchIO_read(f, buf + cur_off, sizeof(buf) - cur_off)) > 0) {
                cur_off += len;
                while ((eol = memchr(buf, '\n', cur_off)) != NULL) {
@@ -1268,11 +1284,15 @@
                                else
                                        eos = eol;
                                *eos = '\0';
-                               fetch_add_entry(ue, url, buf, 0);
+                               ret = fetch_add_entry(ue, url, buf, 0);
+                               if (ret)
+                                       break;
                                cur_off -= eol - buf + 1;
                                memmove(buf, eol + 1, cur_off);
                        }
                }
+               if (ret)
+                       break;
        }
        if (cur_off != 0 || len < 0) {
                /* Not RFC conform, bail out. */
@@ -1280,5 +1300,5 @@
                return -1;
        }
        fetchIO_close(f);
-       return 0;
+       return ret;
 }
diff -r 696e876272f6 -r ccbbdcd1b6de net/libfetch/files/http.c
--- a/net/libfetch/files/http.c Thu Oct 15 12:28:47 2009 +0000



Home | Main Index | Thread Index | Old Index