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



details:   https://anonhg.NetBSD.org/pkgsrc/rev/51bddb26e27c
branches:  trunk
changeset: 541317:51bddb26e27c
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sat Apr 19 14:49:23 2008 +0000

description:
libfetch-2.6:
Change fetchList API to always return lists of full URLs.

diffstat:

 net/libfetch/Makefile         |   4 +-
 net/libfetch/buildlink3.mk    |   4 +-
 net/libfetch/files/common.c   |  73 +++++++++++++++++++++++++++++----------
 net/libfetch/files/common.h   |   5 +-
 net/libfetch/files/fetch.3    |  79 +++++++++++++++---------------------------
 net/libfetch/files/fetch.c    |  70 ++++++++-----------------------------
 net/libfetch/files/fetch.cat3 |  79 ++++++++++++++----------------------------
 net/libfetch/files/fetch.h    |  32 +++++++++-------
 net/libfetch/files/file.c     |  25 +++----------
 net/libfetch/files/ftp.c      |  28 ++++----------
 net/libfetch/files/http.c     |  33 +++++------------
 11 files changed, 174 insertions(+), 258 deletions(-)

diffs (truncated from 858 to 300 lines):

diff -r 04e09cb1c602 -r 51bddb26e27c net/libfetch/Makefile
--- a/net/libfetch/Makefile     Sat Apr 19 14:30:54 2008 +0000
+++ b/net/libfetch/Makefile     Sat Apr 19 14:49:23 2008 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.8 2008/04/18 21:13:10 joerg Exp $
+# $NetBSD: Makefile,v 1.9 2008/04/19 14:49:23 joerg Exp $
 #
 
-DISTNAME=      libfetch-2.5
+DISTNAME=      libfetch-2.6
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 04e09cb1c602 -r 51bddb26e27c net/libfetch/buildlink3.mk
--- a/net/libfetch/buildlink3.mk        Sat Apr 19 14:30:54 2008 +0000
+++ b/net/libfetch/buildlink3.mk        Sat Apr 19 14:49:23 2008 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: buildlink3.mk,v 1.2 2008/04/02 15:33:14 joerg Exp $
+# $NetBSD: buildlink3.mk,v 1.3 2008/04/19 14:49:23 joerg Exp $
 
 BUILDLINK_DEPMETHOD.libfetch?= build
 
@@ -14,7 +14,7 @@
 BUILDLINK_ORDER:=      ${BUILDLINK_ORDER} ${BUILDLINK_DEPTH}libfetch
 
 .if ${LIBFETCH_BUILDLINK3_MK} == "+"
-BUILDLINK_API_DEPENDS.libfetch+=       libfetch>=2.1
+BUILDLINK_API_DEPENDS.libfetch+=       libfetch>=2.5
 BUILDLINK_PKGSRCDIR.libfetch?= ../../net/libfetch
 .endif # LIBFETCH_BUILDLINK3_MK
 
diff -r 04e09cb1c602 -r 51bddb26e27c net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Sat Apr 19 14:30:54 2008 +0000
+++ b/net/libfetch/files/common.c       Sat Apr 19 14:49:23 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.7 2008/04/17 19:04:12 joerg Exp $ */
+/*     $NetBSD: common.c,v 1.8 2008/04/19 14:49:23 joerg Exp $ */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -620,40 +620,75 @@
 /*** Directory-related utility functions *************************************/
 
 int
-fetch_add_entry(struct url_ent **p, int *size, int *len,
-    const char *name, struct url_stat *us)
+fetch_add_entry(struct url_list *ue, struct url *base, const char *name)
 {
-       struct url_ent *tmp;
+       struct url *tmp;
+       char *tmp_name;
+       size_t base_doc_len, name_len;
 
-       if (*p == NULL) {
-               *size = 0;
-               *len = 0;
+       if (strchr(name, '/') != NULL ||
+           strcmp(name, "..") == 0 ||
+           strcmp(name, ".") == 0)
+               return 0;
+
+       base_doc_len = strlen(base->doc);
+       name_len = strlen(name);
+       tmp_name = malloc( base_doc_len + name_len + 2);
+       if (tmp_name == NULL) {
+               errno = ENOMEM;
+               fetch_syserr();
+               return (-1);
        }
 
-       if (*len >= *size - 1) {
-               tmp = realloc(*p, (*size * 2 + 1) * sizeof(**p));
+       if (ue->length + 1 >= ue->alloc_size) {
+               tmp = realloc(ue->urls, (ue->alloc_size * 2 + 1) * sizeof(*tmp));
                if (tmp == NULL) {
+                       free(tmp_name);
                        errno = ENOMEM;
                        fetch_syserr();
                        return (-1);
                }
-               *size = (*size * 2 + 1);
-               *p = tmp;
+               ue->alloc_size = ue->alloc_size * 2 + 1;
+               ue->urls = tmp;
        }
 
-       tmp = *p + *len;
-       snprintf(tmp->name, PATH_MAX, "%s", name);
-       if (us)
-               memcpy(&tmp->stat, us, sizeof(*us));
-       else
-               memset(&tmp->stat, 0, sizeof(*us));
+       tmp = ue->urls + ue->length;
+       strcpy(tmp->scheme, base->scheme);
+       strcpy(tmp->user, base->user);
+       strcpy(tmp->pwd, base->pwd);
+       strcpy(tmp->host, base->host);
+       tmp->port = base->port;
+       memcpy(tmp_name, base->doc, base_doc_len);
+       tmp_name[base_doc_len] = '/';
+       memcpy(tmp_name + base_doc_len + 1, name, name_len);
+       tmp_name[base_doc_len + name_len + 1] = '/';
+       tmp->doc = tmp_name;
+       tmp->offset = 0;
+       tmp->length = 0;
 
-       (*len)++;
-       (++tmp)->name[0] = 0;
+       ++ue->length;
 
        return (0);
 }
 
+void
+fetch_init_url_list(struct url_list *ue)
+{
+       ue->length = ue->alloc_size = 0;
+       ue->urls = NULL;
+}
+
+void
+fetch_free_url_list(struct url_list *ue)
+{
+       size_t i;
+
+       for (i = 0; i < ue->length; ++i)
+               free(ue->urls[i].doc);
+       free(ue->urls);
+       ue->length = ue->alloc_size = 0;
+}
+
 
 /*** Authentication-related utility functions ********************************/
 
diff -r 04e09cb1c602 -r 51bddb26e27c net/libfetch/files/common.h
--- a/net/libfetch/files/common.h       Sat Apr 19 14:30:54 2008 +0000
+++ b/net/libfetch/files/common.h       Sat Apr 19 14:49:23 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.h,v 1.5 2008/04/05 02:42:13 joerg Exp $ */
+/*     $NetBSD: common.h,v 1.6 2008/04/19 14:49:23 joerg Exp $ */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -93,8 +93,7 @@
 ssize_t                 fetch_writev(conn_t *, struct iovec *, int);
 int             fetch_putln(conn_t *, const char *, size_t);
 int             fetch_close(conn_t *);
-int             fetch_add_entry(struct url_ent **, int *, int *,
-                    const char *, struct url_stat *);
+int             fetch_add_entry(struct url_list *, struct url *, const char *);
 int             fetch_netrc_auth(struct url *url);
 int             fetch_no_proxy_match(const char *);
 
diff -r 04e09cb1c602 -r 51bddb26e27c net/libfetch/files/fetch.3
--- a/net/libfetch/files/fetch.3        Sat Apr 19 14:30:54 2008 +0000
+++ b/net/libfetch/files/fetch.3        Sat Apr 19 14:49:23 2008 +0000
@@ -24,9 +24,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $FreeBSD: fetch.3,v 1.64 2007/12/18 11:03:26 des Exp $
-.\" $NetBSD: fetch.3,v 1.4 2008/04/04 22:37:28 joerg Exp $
+.\" $NetBSD: fetch.3,v 1.5 2008/04/19 14:49:23 joerg Exp $
 .\"
-.Dd December 18, 2007
+.Dd April 19, 2008
 .Dt FETCH 3
 .Os
 .Sh NAME
@@ -37,31 +37,26 @@
 .Nm fetchGetURL ,
 .Nm fetchPutURL ,
 .Nm fetchStatURL ,
-.Nm fetchFilteredListURL ,
 .Nm fetchListURL ,
 .Nm fetchXGet ,
 .Nm fetchGet ,
 .Nm fetchPut ,
 .Nm fetchStat ,
-.Nm fetchFilteredList ,
 .Nm fetchList ,
 .Nm fetchXGetFile ,
 .Nm fetchGetFile ,
 .Nm fetchPutFile ,
 .Nm fetchStatFile ,
-.Nm fetchFilteredListFile ,
 .Nm fetchListFile ,
 .Nm fetchXGetHTTP ,
 .Nm fetchGetHTTP ,
 .Nm fetchPutHTTP ,
 .Nm fetchStatHTTP ,
-.Nm fetchFilteredListHTTP ,
 .Nm fetchListHTTP ,
 .Nm fetchXGetFTP ,
 .Nm fetchGetFTP ,
 .Nm fetchPutFTP ,
 .Nm fetchStatFTP ,
-.Nm fetchFilteredListFTP
 .Nm fetchListFTP
 .Nd file transfer functions
 .Sh LIBRARY
@@ -83,10 +78,8 @@
 .Fn fetchPutURL "const char *URL" "const char *flags"
 .Ft int
 .Fn fetchStatURL "const char *URL" "struct url_stat *us" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchFilteredListURL "const char *URL" "const char *pattern" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchListURL "const char *URL" "const char *flags"
+.Ft int
+.Fn fetchListURL "struct url_list *list" "const char *URL" "const char *flags"
 .Ft fetchIO *
 .Fn fetchXGet "struct url *u" "struct url_stat *us" "const char *flags"
 .Ft fetchIO *
@@ -95,10 +88,8 @@
 .Fn fetchPut "struct url *u" "const char *flags"
 .Ft int
 .Fn fetchStat "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchFilteredList "struct url *u" "const char *pattern" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchList "struct url *u" "const char *flags"
+.Ft int
+.Fn fetchList "struct url_list *list" "struct url *u" "const char *flags"
 .Ft fetchIO *
 .Fn fetchXGetFile "struct url *u" "struct url_stat *us" "const char *flags"
 .Ft fetchIO *
@@ -107,10 +98,8 @@
 .Fn fetchPutFile "struct url *u" "const char *flags"
 .Ft int
 .Fn fetchStatFile "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchFilteredListFile "struct url *u" "const char *pattern" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchListFile "struct url *u" "const char *flags"
+.Ft int
+.Fn fetchListFile "struct url_list *list" "struct url *u" "const char *flags"
 .Ft fetchIO *
 .Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "const char *flags"
 .Ft fetchIO *
@@ -119,10 +108,8 @@
 .Fn fetchPutHTTP "struct url *u" "const char *flags"
 .Ft int
 .Fn fetchStatHTTP "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchFilteredListHTTP "struct url *u" "const char *pattern" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchListHTTP "struct url *u" "const char *flags"
+.Ft int
+.Fn fetchListHTTP "struct url_list *list" "struct url *u" "const char *flags"
 .Ft fetchIO *
 .Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "const char *flags"
 .Ft fetchIO *
@@ -131,10 +118,8 @@
 .Fn fetchPutFTP "struct url *u" "const char *flags"
 .Ft int
 .Fn fetchStatFTP "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchFilteredListFTP "struct url *u" "const char *pattern" "const char *flags"
-.Ft struct url_ent *
-.Fn fetchListFTP "struct url *u" "const char *flags"
+.Ft int
+.Fn fetchListFTP "struct url_list *list" "struct url *u" "const char *flags"
 .Sh DESCRIPTION
 These functions implement a high-level library for retrieving and
 uploading files using Uniform Resource Locators (URLs).
@@ -241,34 +226,28 @@
 field is set to the modification time.
 .Pp
 .Fn fetchListURL
-attempts to list the contents of the directory pointed to by the URL
-provided.
-If successful, it returns a malloced array of
-.Vt url_ent
-structures.
+attempts to list the contents of the directory pointed to by the URL provided.
+The pattern can be a simple glob-like expression as hint.
+Callers should not depend on the server to filter names.
+If successful, it appends the list of entries to the 
+.Vt url_list
+structure.
 The
-.Vt url_ent
+.Vt url_list
 structure is defined as follows in
 .In fetch.h :
 .Bd -literal
-struct url_ent {
-    char         name[PATH_MAX];
-    struct url_stat stat;
+struct url_list {
+    size_t     length;
+    size_t     alloc_size;
+    struct url *urls;
 };
 .Ed
 .Pp
-The list is terminated by an entry with an empty name.
-.Pp
-The pointer returned by
-.Fn fetchListURL



Home | Main Index | Thread Index | Old Index