summaryrefslogtreecommitdiff
path: root/net/libfetch
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2008-04-04 22:37:28 +0000
committerjoerg <joerg@pkgsrc.org>2008-04-04 22:37:28 +0000
commit5f8b22911d11cbc07fa54b9a84debdfdcd861bb1 (patch)
treef35cb0ccecb7e0e7c275860a9294873d75b75ea8 /net/libfetch
parent008871668755a88e599bf158fc546653b0c03999 (diff)
downloadpkgsrc-5f8b22911d11cbc07fa54b9a84debdfdcd861bb1.tar.gz
libfetch-2.2:
Add interface to glob a directory.
Diffstat (limited to 'net/libfetch')
-rw-r--r--net/libfetch/Makefile4
-rw-r--r--net/libfetch/files/fetch.323
-rw-r--r--net/libfetch/files/fetch.c42
-rw-r--r--net/libfetch/files/fetch.h8
-rw-r--r--net/libfetch/files/file.c13
-rw-r--r--net/libfetch/files/ftp.c12
-rw-r--r--net/libfetch/files/http.c12
7 files changed, 105 insertions, 9 deletions
diff --git a/net/libfetch/Makefile b/net/libfetch/Makefile
index fb4dc6663aa..c783bdaa0f1 100644
--- a/net/libfetch/Makefile
+++ b/net/libfetch/Makefile
@@ -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 --git a/net/libfetch/files/fetch.3 b/net/libfetch/files/fetch.3
index 7637eb781c0..b2ebe2e6f16 100644
--- a/net/libfetch/files/fetch.3
+++ b/net/libfetch/files/fetch.3
@@ -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 @@ The pointer returned by
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 --git a/net/libfetch/files/fetch.c b/net/libfetch/files/fetch.c
index 0c7fcc0d214..508d52f356d 100644
--- a/net/libfetch/files/fetch.c
+++ b/net/libfetch/files/fetch.c
@@ -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 @@ fetchList(struct url *URL, const char *flags)
}
/*
+ * 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 @@ fetchListURL(const char *URL, const char *flags)
}
/*
+ * 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 --git a/net/libfetch/files/fetch.h b/net/libfetch/files/fetch.h
index e6c94ae0db8..55378e303f1 100644
--- a/net/libfetch/files/fetch.h
+++ b/net/libfetch/files/fetch.h
@@ -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 *fetchXGetFile(struct url *, struct url_stat *, const char *);
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 *fetchXGetHTTP(struct url *, struct url_stat *, const char *);
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 *fetchXGetFTP(struct url *, struct url_stat *, const char *);
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 *fetchXGetURL(const char *, struct url_stat *, const char *);
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 --git a/net/libfetch/files/file.c b/net/libfetch/files/file.c
index 153a4ed56ce..b888d160835 100644
--- a/net/libfetch/files/file.c
+++ b/net/libfetch/files/file.c
@@ -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 @@ fetchStatFile(struct url *u, struct url_stat *us, const char *flags)
}
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 @@ fetchListFile(struct url *u, const char *flags)
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 @@ fetchListFile(struct url *u, const char *flags)
return (ue);
}
+
+struct url_ent *
+fetchListFile(struct url *u, const char *flags)
+{
+ return fetchFilteredListFile(u, "*", flags);
+}
diff --git a/net/libfetch/files/ftp.c b/net/libfetch/files/ftp.c
index 95448b73845..179bb0db255 100644
--- a/net/libfetch/files/ftp.c
+++ b/net/libfetch/files/ftp.c
@@ -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 @@ fetchStatFTP(struct url *url, struct url_stat *us, const char *flags)
* 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 --git a/net/libfetch/files/http.c b/net/libfetch/files/http.c
index e5ba72a7199..84c1e9e99b5 100644
--- a/net/libfetch/files/http.c
+++ b/net/libfetch/files/http.c
@@ -1,4 +1,4 @@
-/* $NetBSD: http.c,v 1.9 2008/04/02 15:33:15 joerg Exp $ */
+/* $NetBSD: http.c,v 1.10 2008/04/04 22:37:28 joerg Exp $ */
/*-
* Copyright (c) 2000-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -1145,6 +1145,16 @@ fetchStatHTTP(struct url *URL, struct url_stat *us, const char *flags)
* List a directory
*/
struct url_ent *
+fetchFilteredListHTTP(struct url *url, const char *pattern, const char *flags)
+{
+ fprintf(stderr, "fetchFilteredListHTTP(): not implemented\n");
+ return (NULL);
+}
+
+/*
+ * List a directory
+ */
+struct url_ent *
fetchListHTTP(struct url *url, const char *flags)
{
fprintf(stderr, "fetchListHTTP(): not implemented\n");