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.2:
details: https://anonhg.NetBSD.org/pkgsrc/rev/c17db58fa4b2
branches: trunk
changeset: 540619:c17db58fa4b2
user: joerg <joerg%pkgsrc.org@localhost>
date: Fri Apr 04 22:37:28 2008 +0000
description:
libfetch-2.2:
Add interface to glob a directory.
diffstat:
net/libfetch/Makefile | 4 ++--
net/libfetch/files/fetch.3 | 23 ++++++++++++++++++++++-
net/libfetch/files/fetch.c | 42 +++++++++++++++++++++++++++++++++++++++++-
net/libfetch/files/fetch.h | 8 +++++++-
net/libfetch/files/file.c | 13 +++++++++++--
net/libfetch/files/ftp.c | 12 +++++++++++-
net/libfetch/files/http.c | 12 +++++++++++-
7 files changed, 105 insertions(+), 9 deletions(-)
diffs (truncated from 323 to 300 lines):
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/Makefile
--- a/net/libfetch/Makefile Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/Makefile Fri Apr 04 22:37:28 2008 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.2 2008/04/02 15:33:14 joerg Exp $
+# $NetBSD: Makefile,v 1.3 2008/04/04 22:37:28 joerg Exp $
#
-DISTNAME= libfetch-2.1
+DISTNAME= libfetch-2.2
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/files/fetch.3
--- a/net/libfetch/files/fetch.3 Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/files/fetch.3 Fri Apr 04 22:37:28 2008 +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.3 2008/04/02 15:33:14 joerg Exp $
+.\" $NetBSD: fetch.3,v 1.4 2008/04/04 22:37:28 joerg Exp $
.\"
.Dd December 18, 2007
.Dt FETCH 3
@@ -37,26 +37,31 @@
.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
@@ -79,6 +84,8 @@
.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 fetchIO *
.Fn fetchXGet "struct url *u" "struct url_stat *us" "const char *flags"
@@ -89,6 +96,8 @@
.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 fetchIO *
.Fn fetchXGetFile "struct url *u" "struct url_stat *us" "const char *flags"
@@ -99,6 +108,8 @@
.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 fetchIO *
.Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "const char *flags"
@@ -109,6 +120,8 @@
.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 fetchIO *
.Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "const char *flags"
@@ -119,6 +132,8 @@
.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"
.Sh DESCRIPTION
These functions implement a high-level library for retrieving and
@@ -249,6 +264,12 @@
should be freed using
.Fn free .
.Pp
+.Fn fetchFilteredListURL
+works like
+.Fn fetchListURL ,
+but filters the list according to the given glob pattern.
+Only * and ? should be used in the pattern.
+.Pp
.Fn fetchXGet ,
.Fn fetchGet ,
.Fn fetchPut
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/files/fetch.c
--- a/net/libfetch/files/fetch.c Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/files/fetch.c Fri Apr 04 22:37:28 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.2 2008/04/02 15:33:14 joerg Exp $ */
+/* $NetBSD: fetch.c,v 1.3 2008/04/04 22:37:28 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -172,6 +172,28 @@
}
/*
+ * Select the appropriate protocol for the URL scheme, and return a
+ * list of files in the directory pointed to by the URL.
+ */
+struct url_ent *
+fetchFilteredList(struct url *URL, const char *pattern, const char *flags)
+{
+ int direct;
+
+ direct = CHECK_FLAG('d');
+ if (strcasecmp(URL->scheme, SCHEME_FILE) == 0)
+ return (fetchFilteredListFile(URL, pattern, flags));
+ else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0)
+ return (fetchFilteredListFTP(URL, pattern, flags));
+ else if (strcasecmp(URL->scheme, SCHEME_HTTP) == 0)
+ return (fetchFilteredListHTTP(URL, pattern, flags));
+ else if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0)
+ return (fetchFilteredListHTTP(URL, pattern, flags));
+ url_seterr(URL_BAD_SCHEME);
+ return (NULL);
+}
+
+/*
* Attempt to parse the given URL; if successful, call fetchXGet().
*/
fetchIO *
@@ -253,6 +275,24 @@
}
/*
+ * Attempt to parse the given URL; if successful, call fetchList().
+ */
+struct url_ent *
+fetchFilteredListURL(const char *URL, const char *pattern, const char *flags)
+{
+ struct url *u;
+ struct url_ent *ue;
+
+ if ((u = fetchParseURL(URL)) == NULL)
+ return (NULL);
+
+ ue = fetchFilteredList(u, pattern, flags);
+
+ fetchFreeURL(u);
+ return (ue);
+}
+
+/*
* Make a URL
*/
struct url *
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/files/fetch.h
--- a/net/libfetch/files/fetch.h Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/files/fetch.h Fri Apr 04 22:37:28 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.h,v 1.4 2008/04/02 15:33:14 joerg Exp $ */
+/* $NetBSD: fetch.h,v 1.5 2008/04/04 22:37:28 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -107,6 +107,8 @@
fetchIO *fetchGetFile(struct url *, const char *);
fetchIO *fetchPutFile(struct url *, const char *);
int fetchStatFile(struct url *, struct url_stat *, const char *);
+struct url_ent *fetchFilteredListFile(struct url *, const char *,
+ const char *);
struct url_ent *fetchListFile(struct url *, const char *);
/* HTTP-specific functions */
@@ -114,6 +116,7 @@
fetchIO *fetchGetHTTP(struct url *, const char *);
fetchIO *fetchPutHTTP(struct url *, const char *);
int fetchStatHTTP(struct url *, struct url_stat *, const char *);
+struct url_ent *fetchFilteredListHTTP(struct url *,const char *, const char *);
struct url_ent *fetchListHTTP(struct url *, const char *);
/* FTP-specific functions */
@@ -121,6 +124,7 @@
fetchIO *fetchGetFTP(struct url *, const char *);
fetchIO *fetchPutFTP(struct url *, const char *);
int fetchStatFTP(struct url *, struct url_stat *, const char *);
+struct url_ent *fetchFilteredListFTP(struct url *, const char *, const char *);
struct url_ent *fetchListFTP(struct url *, const char *);
/* Generic functions */
@@ -128,11 +132,13 @@
fetchIO *fetchGetURL(const char *, const char *);
fetchIO *fetchPutURL(const char *, const char *);
int fetchStatURL(const char *, struct url_stat *, const char *);
+struct url_ent *fetchFilteredListURL(const char *, const char *, const char *);
struct url_ent *fetchListURL(const char *, const char *);
fetchIO *fetchXGet(struct url *, struct url_stat *, const char *);
fetchIO *fetchGet(struct url *, const char *);
fetchIO *fetchPut(struct url *, const char *);
int fetchStat(struct url *, struct url_stat *, const char *);
+struct url_ent *fetchFilteredList(struct url *, const char *, const char *);
struct url_ent *fetchList(struct url *, const char *);
/* URL parsing */
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/files/file.c
--- a/net/libfetch/files/file.c Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/files/file.c Fri Apr 04 22:37:28 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: file.c,v 1.3 2008/04/02 15:33:14 joerg Exp $ */
+/* $NetBSD: file.c,v 1.4 2008/04/04 22:37:28 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -33,6 +33,7 @@
#include <dirent.h>
#include <fcntl.h>
+#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -187,7 +188,7 @@
}
struct url_ent *
-fetchListFile(struct url *u, const char *flags)
+fetchFilteredListFile(struct url *u, const char *pattern, const char *flags)
{
struct dirent *de;
struct url_stat us;
@@ -210,6 +211,8 @@
l = sizeof(fn) - strlen(fn) - 1;
while ((de = readdir(dir)) != NULL) {
+ if (fnmatch(pattern, de->d_name, FNM_PERIOD) != 0)
+ continue;
strncpy(p, de->d_name, l - 1);
p[l - 1] = 0;
if (fetch_stat_file2(fn, &us) == -1) {
@@ -221,3 +224,9 @@
return (ue);
}
+
+struct url_ent *
+fetchListFile(struct url *u, const char *flags)
+{
+ return fetchFilteredListFile(u, "*", flags);
+}
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/files/ftp.c
--- a/net/libfetch/files/ftp.c Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/files/ftp.c Fri Apr 04 22:37:28 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.11 2008/04/04 15:17:51 joerg Exp $ */
+/* $NetBSD: ftp.c,v 1.12 2008/04/04 22:37:28 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -1171,6 +1171,16 @@
* List a directory
*/
struct url_ent *
+fetchFilteredListFTP(struct url *url, const char *pattern, const char *flags)
+{
+ fprintf(stderr, "fetchFilteredListFTP(): not implemented\n");
+ return (NULL);
+}
+
+/*
+ * List a directory
+ */
+struct url_ent *
fetchListFTP(struct url *url, const char *flags)
{
fprintf(stderr, "fetchListFTP(): not implemented\n");
diff -r 1cf64109649e -r c17db58fa4b2 net/libfetch/files/http.c
--- a/net/libfetch/files/http.c Fri Apr 04 21:55:51 2008 +0000
+++ b/net/libfetch/files/http.c Fri Apr 04 22:37:28 2008 +0000
Home |
Main Index |
Thread Index |
Old Index