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.1:
details: https://anonhg.NetBSD.org/pkgsrc/rev/33918a27f7eb
branches: trunk
changeset: 540211:33918a27f7eb
user: joerg <joerg%pkgsrc.org@localhost>
date: Wed Apr 02 15:33:14 2008 +0000
description:
libfetch-2.1:
- remove most of the debug junk
- fix a buffer overflow in the config parser
- replace stdio usage with a simple abstract IO framework. currently
without explicit buffering, but that might be added later
diffstat:
net/libfetch/Makefile | 8 +-
net/libfetch/PLIST | 3 +-
net/libfetch/buildlink3.mk | 4 +-
net/libfetch/files/common.c | 64 +++++++++++++++++---
net/libfetch/files/common.h | 14 +--
net/libfetch/files/fetch.3 | 32 +++++-----
net/libfetch/files/fetch.c | 28 ++------
net/libfetch/files/fetch.cat3 | 30 ++++----
net/libfetch/files/fetch.h | 40 +++++++-----
net/libfetch/files/file.c | 130 +++++++++++++++++++++++++++++++++--------
net/libfetch/files/ftp.c | 83 ++++++++------------------
net/libfetch/files/http.c | 126 +++++++--------------------------------
12 files changed, 286 insertions(+), 276 deletions(-)
diffs (truncated from 1288 to 300 lines):
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/Makefile
--- a/net/libfetch/Makefile Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/Makefile Wed Apr 02 15:33:14 2008 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.1.1.1 2008/02/07 01:48:22 joerg Exp $
+# $NetBSD: Makefile,v 1.2 2008/04/02 15:33:14 joerg Exp $
#
-DISTNAME= libfetch-2.0
+DISTNAME= libfetch-2.1
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
@@ -17,7 +17,9 @@
USE_BSD_MAKEFILE= yes
-INSTALLATION_DIRS= lib ${PKGMANDIR}/cat3 ${PKGMANDIR}/man3
+INSTALLATION_DIRS= include lib ${PKGMANDIR}/cat3 ${PKGMANDIR}/man3
+
+INSTALL_TARGET= install includes
do-extract:
${CP} -r ${FILESDIR} ${WRKSRC}
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/PLIST
--- a/net/libfetch/PLIST Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/PLIST Wed Apr 02 15:33:14 2008 +0000
@@ -1,4 +1,5 @@
-@comment $NetBSD: PLIST,v 1.1.1.1 2008/02/07 01:48:22 joerg Exp $
+@comment $NetBSD: PLIST,v 1.2 2008/04/02 15:33:14 joerg Exp $
+include/fetch.h
lib/libfetch.a
man/cat3/fetch.0
man/man3/fetch.3
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/buildlink3.mk
--- a/net/libfetch/buildlink3.mk Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/buildlink3.mk Wed Apr 02 15:33:14 2008 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: buildlink3.mk,v 1.1.1.1 2008/02/07 01:48:22 joerg Exp $
+# $NetBSD: buildlink3.mk,v 1.2 2008/04/02 15:33:14 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.0
+BUILDLINK_API_DEPENDS.libfetch+= libfetch>=2.1
BUILDLINK_PKGSRCDIR.libfetch?= ../../net/libfetch
.endif # LIBFETCH_BUILDLINK3_MK
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/files/common.c
--- a/net/libfetch/files/common.c Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/files/common.c Wed Apr 02 15:33:14 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.4 2008/02/07 16:30:49 joerg Exp $ */
+/* $NetBSD: common.c,v 1.5 2008/04/02 15:33:14 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -271,8 +271,6 @@
struct addrinfo hints, *res, *res0;
int sd, err;
- DEBUG(fprintf(stderr, "---> %s:%d\n", host, port));
-
if (verbose)
fetch_info("looking up %s", host);
@@ -485,7 +483,6 @@
} while (c != '\n');
conn->buf[conn->buflen] = '\0';
- DEBUG(fprintf(stderr, "<<< %s", conn->buf));
return (0);
}
@@ -588,7 +585,6 @@
struct iovec iov[2];
int ret;
- DEBUG(fprintf(stderr, ">>> %s\n", str));
iov[0].iov_base = DECONST(char *, str);
iov[0].iov_len = len;
iov[1].iov_base = DECONST(char *, ENDL);
@@ -662,7 +658,7 @@
{
static char word[1024];
- if (fscanf(f, " %1024s ", word) != 1)
+ if (fscanf(f, " %1023s ", word) != 1)
return (NULL);
return (word);
}
@@ -699,14 +695,11 @@
if ((f = fopen(fn, "r")) == NULL)
return (-1);
while ((word = fetch_read_word(f)) != NULL) {
- if (strcmp(word, "default") == 0) {
- DEBUG(fetch_info("Using default .netrc settings"));
+ if (strcmp(word, "default") == 0)
break;
- }
if (strcmp(word, "machine") == 0 &&
(word = fetch_read_word(f)) != NULL &&
strcasecmp(word, url->host) == 0) {
- DEBUG(fetch_info("Using .netrc settings for %s", word));
break;
}
}
@@ -791,3 +784,54 @@
return (0);
}
+
+struct fetchIO {
+ void *io_cookie;
+ ssize_t (*io_read)(void *, void *, size_t);
+ ssize_t (*io_write)(void *, const void *, size_t);
+ void (*io_close)(void *);
+};
+
+void
+fetchIO_close(fetchIO *f)
+{
+ if (f->io_close != NULL)
+ (*f->io_close)(f->io_cookie);
+
+ free(f);
+}
+
+fetchIO *
+fetchIO_unopen(void *io_cookie, ssize_t (*io_read)(void *, void *, size_t),
+ ssize_t (*io_write)(void *, const void *, size_t),
+ void (*io_close)(void *))
+{
+ fetchIO *f;
+
+ f = malloc(sizeof(*f));
+ if (f == NULL)
+ return f;
+
+ f->io_cookie = io_cookie;
+ f->io_read = io_read;
+ f->io_write = io_write;
+ f->io_close = io_close;
+
+ return f;
+}
+
+ssize_t
+fetchIO_read(fetchIO *f, void *buf, size_t len)
+{
+ if (f->io_read == NULL)
+ return EBADF;
+ return (*f->io_read)(f->io_cookie, buf, len);
+}
+
+ssize_t
+fetchIO_write(fetchIO *f, const void *buf, size_t len)
+{
+ if (f->io_read == NULL)
+ return EBADF;
+ return (*f->io_write)(f->io_cookie, buf, len);
+}
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/files/common.h
--- a/net/libfetch/files/common.h Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/files/common.h Wed Apr 02 15:33:14 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.3 2008/02/21 14:40:43 tnn Exp $ */
+/* $NetBSD: common.h,v 1.4 2008/04/02 15:33:14 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -103,11 +103,8 @@
#define netdb_seterr(n) fetch_seterr(netdb_errlist, n)
#define url_seterr(n) fetch_seterr(url_errlist, n)
-#ifndef NDEBUG
-#define DEBUG(x) do { if (fetchDebug) { x; } } while (0)
-#else
-#define DEBUG(x) do { } while (0)
-#endif
+fetchIO *fetchIO_unopen(void *, ssize_t (*)(void *, void *, size_t),
+ ssize_t (*)(void *, const void *, size_t), void (*)(void *));
/*
* I don't really like exporting http_request() and ftp_request(),
@@ -118,11 +115,12 @@
* Note that _*_request() free purl, which is way ugly but saves us a
* whole lot of trouble.
*/
-FILE *http_request(struct url *, const char *,
+fetchIO *http_request(struct url *, const char *,
struct url_stat *, struct url *, const char *);
-FILE *ftp_request(struct url *, const char *,
+fetchIO *ftp_request(struct url *, const char *,
struct url_stat *, struct url *, const char *);
+
/*
* Check whether a particular flag is set
*/
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/files/fetch.3
--- a/net/libfetch/files/fetch.3 Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/files/fetch.3 Wed Apr 02 15:33:14 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.2 2008/02/07 16:14:32 joerg Exp $
+.\" $NetBSD: fetch.3,v 1.3 2008/04/02 15:33:14 joerg Exp $
.\"
.Dd December 18, 2007
.Dt FETCH 3
@@ -70,51 +70,51 @@
.Fn fetchParseURL "const char *URL"
.Ft void
.Fn fetchFreeURL "struct url *u"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchXGetURL "const char *URL" "struct url_stat *us" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchGetURL "const char *URL" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.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 fetchListURL "const char *URL" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchXGet "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchGet "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.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 fetchList "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchXGetFile "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchGetFile "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.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 fetchListFile "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchXGetHTTP "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchGetHTTP "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.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 fetchListHTTP "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchXGetFTP "struct url *u" "struct url_stat *us" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchGetFTP "struct url *u" "const char *flags"
-.Ft FILE *
+.Ft fetchIO *
.Fn fetchPutFTP "struct url *u" "const char *flags"
.Ft int
.Fn fetchStatFTP "struct url *u" "struct url_stat *us" "const char *flags"
diff -r 6bc32821143f -r 33918a27f7eb net/libfetch/files/fetch.c
--- a/net/libfetch/files/fetch.c Wed Apr 02 15:06:07 2008 +0000
+++ b/net/libfetch/files/fetch.c Wed Apr 02 15:33:14 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.1.1.1 2008/02/07 01:48:22 joerg Exp $ */
+/* $NetBSD: fetch.c,v 1.2 2008/04/02 15:33:14 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -69,7 +69,7 @@
* read-only stream connected to the document referenced by the URL.
* Also fill out the struct url_stat.
*/
-FILE *
+fetchIO *
fetchXGet(struct url *URL, struct url_stat *us, const char *flags)
{
Home |
Main Index |
Thread Index |
Old Index