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.21:
details: https://anonhg.NetBSD.org/pkgsrc/rev/39cb646d3998
branches: trunk
changeset: 553983:39cb646d3998
user: joerg <joerg%pkgsrc.org@localhost>
date: Thu Feb 05 16:59:45 2009 +0000
description:
libfetch-2.21:
Add support for conditional GET using the 'i' flag. Inspired by
the HTTP support for the same feature in FreeBSD by Murray Stokely, but
mostly rewritten and extended to work for all protocols.
diffstat:
net/libfetch/Makefile | 4 ++--
net/libfetch/buildlink3.mk | 4 ++--
net/libfetch/files/common.c | 3 ++-
net/libfetch/files/fetch.3 | 21 +++++++++++++++++++--
net/libfetch/files/fetch.cat3 | 12 ++++++++++--
net/libfetch/files/fetch.h | 4 +++-
net/libfetch/files/file.c | 19 ++++++++++++++++---
net/libfetch/files/ftp.c | 18 +++++++++++++++---
net/libfetch/files/http.c | 37 +++++++++++++++++++++++++++++++++----
net/libfetch/files/http.errors | 4 ++--
10 files changed, 104 insertions(+), 22 deletions(-)
diffs (truncated from 374 to 300 lines):
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/Makefile
--- a/net/libfetch/Makefile Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/Makefile Thu Feb 05 16:59:45 2009 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.23 2008/11/04 16:14:24 joerg Exp $
+# $NetBSD: Makefile,v 1.24 2009/02/05 16:59:45 joerg Exp $
#
-DISTNAME= libfetch-2.20
+DISTNAME= libfetch-2.21
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/buildlink3.mk
--- a/net/libfetch/buildlink3.mk Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/buildlink3.mk Thu Feb 05 16:59:45 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: buildlink3.mk,v 1.4 2008/10/06 22:03:43 joerg Exp $
+# $NetBSD: buildlink3.mk,v 1.5 2009/02/05 16:59:45 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.16
+BUILDLINK_API_DEPENDS.libfetch+= libfetch>=2.21
BUILDLINK_PKGSRCDIR.libfetch?= ../../net/libfetch
.endif # LIBFETCH_BUILDLINK3_MK
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/common.c
--- a/net/libfetch/files/common.c Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/common.c Thu Feb 05 16:59:45 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.16 2008/10/07 15:50:00 joerg Exp $ */
+/* $NetBSD: common.c,v 1.17 2009/02/05 16:59:45 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -728,6 +728,7 @@
tmp->offset = 0;
tmp->length = 0;
+ tmp->last_modified = -1;
++ue->length;
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/fetch.3
--- a/net/libfetch/files/fetch.3 Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/fetch.3 Thu Feb 05 16:59:45 2009 +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.10 2008/10/08 15:11:21 joerg Exp $
+.\" $NetBSD: fetch.3,v 1.11 2009/02/05 16:59:45 joerg Exp $
.\"
-.Dd April 25, 2008
+.Dd February 4, 2009
.Dt FETCH 3
.Os
.Sh NAME
@@ -194,6 +194,7 @@
char *doc;
off_t offset;
size_t length;
+ time_t last_modified;
};
.Ed
.Pp
@@ -204,6 +205,9 @@
.Fn fetchParseURL
should be freed using
.Fn fetchFreeURL .
+The size of
+.Vt struct URL
+is not part of the ABI.
.Pp
.Fn fetchXGetURL ,
.Fn fetchGetURL ,
@@ -326,6 +330,19 @@
functions is read-only, and that a stream returned by one of the
.Fn fetchPutXXX
functions is write-only.
+.Sh PROTOCOL INDEPENDENT FLAGS
+If the
+.Ql i
+(if-modified-since) flag is specified, the library will try to fetch
+the content only if it is newer than
+.Va last_modified .
+For HTTP an
+.Li If-Modified-Since
+HTTP header is sent.
+For FTP a
+.Li MTDM
+command is sent first and compared locally.
+For FILE the source file is compared.
.Sh FILE SCHEME
.Fn fetchXGetFile ,
.Fn fetchGetFile ,
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/fetch.cat3
--- a/net/libfetch/files/fetch.cat3 Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/fetch.cat3 Thu Feb 05 16:59:45 2009 +0000
@@ -157,10 +157,12 @@
char *doc;
off_t offset;
size_t length;
+ time_t last_modified;
};
The pointer returned by ffeettcchhMMaakkeeUURRLL(), ffeettcchhCCooppyyUURRLL(), and
- ffeettcchhPPaarrsseeUURRLL() should be freed using ffeettcchhFFrreeeeUURRLL().
+ ffeettcchhPPaarrsseeUURRLL() should be freed using ffeettcchhFFrreeeeUURRLL(). The size of _s_t_r_u_c_t
+ _U_R_L is not part of the ABI.
ffeettcchhXXGGeettUURRLL(), ffeettcchhGGeettUURRLL(), and ffeettcchhPPuuttUURRLL() constitute the recom-
mended interface to the ffeettcchh library. They examine the URL passed to
@@ -225,6 +227,12 @@
ffeettcchhGGeettXXXXXX() functions is read-only, and that a stream returned by one
of the ffeettcchhPPuuttXXXXXX() functions is write-only.
+PPRROOTTOOCCOOLL IINNDDEEPPEENNDDEENNTT FFLLAAGGSS
+ If the `i' (if-modified-since) flag is specified, the library will try to
+ fetch the content only if it is newer than _l_a_s_t___m_o_d_i_f_i_e_d. For HTTP an
+ If-Modified-Since HTTP header is sent. For FTP a MTDM command is sent
+ first and compared locally. For FILE the source file is compared.
+
FFIILLEE SSCCHHEEMMEE
ffeettcchhXXGGeettFFiillee(), ffeettcchhGGeettFFiillee(), and ffeettcchhPPuuttFFiillee() provide access to
documents which are files in a locally mounted file system. Only the
@@ -495,4 +503,4 @@
Some parts of the code are not fully reentrant.
-NetBSD 4.0 April 25, 2008 NetBSD 4.0
+NetBSD 5.0 February 4, 2009 NetBSD 5.0
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/fetch.h
--- a/net/libfetch/files/fetch.h Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/fetch.h Thu Feb 05 16:59:45 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.h,v 1.12 2008/10/06 12:58:29 joerg Exp $ */
+/* $NetBSD: fetch.h,v 1.13 2009/02/05 16:59:45 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
* All rights reserved.
@@ -54,6 +54,7 @@
char *doc;
off_t offset;
size_t length;
+ time_t last_modified;
};
struct url_stat {
@@ -94,6 +95,7 @@
#define FETCH_UNKNOWN 17
#define FETCH_URL 18
#define FETCH_VERBOSE 19
+#define FETCH_UNCHANGED 20
#if defined(__cplusplus)
extern "C" {
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/file.c
--- a/net/libfetch/files/file.c Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/file.c Thu Feb 05 16:59:45 2009 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: file.c,v 1.12 2008/10/06 12:58:29 joerg Exp $ */
+/* $NetBSD: file.c,v 1.13 2009/02/05 16:59:45 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
- * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
+ * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -79,7 +79,12 @@
{
char *path;
fetchIO *f;
- int fd, *cookie;
+ struct url_stat local_us;
+ int if_modified_since, fd, *cookie;
+
+ if_modified_since = CHECK_FLAG('i');
+ if (if_modified_since && us == NULL)
+ us = &local_us;
if ((path = fetchUnquotePath(u)) == NULL) {
fetch_syserr();
@@ -95,6 +100,14 @@
if (us && fetch_stat_file(fd, us) == -1) {
close(fd);
+ fetch_syserr();
+ return NULL;
+ }
+
+ if (if_modified_since && u->last_modified > 0 &&
+ u->last_modified >= us->mtime) {
+ fetchLastErrCode = FETCH_UNCHANGED;
+ snprintf(fetchLastErrString, MAXERRSTRING, "Unchanged");
return NULL;
}
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/ftp.c
--- a/net/libfetch/files/ftp.c Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/ftp.c Thu Feb 05 16:59:45 2009 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: ftp.c,v 1.25 2008/12/02 16:59:03 joerg Exp $ */
+/* $NetBSD: ftp.c,v 1.26 2009/02/05 16:59:45 joerg Exp $ */
/*-
* Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
- * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
+ * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1127,7 +1127,8 @@
fetchIO *f;
char *path;
conn_t *conn;
- int oflag;
+ int if_modified_since, oflag;
+ struct url_stat local_us;
/* check if we should use HTTP instead */
if (purl && strcasecmp(purl->scheme, SCHEME_HTTP) == 0) {
@@ -1159,6 +1160,10 @@
return (NULL);
}
+ if_modified_since = CHECK_FLAG('i');
+ if (if_modified_since && us == NULL)
+ us = &local_us;
+
/* stat file */
if (us && ftp_stat(conn, path, us) == -1
&& fetchLastErrCode != FETCH_PROTO
@@ -1167,6 +1172,13 @@
return (NULL);
}
+ if (if_modified_since && url->last_modified > 0 &&
+ url->last_modified >= us->mtime) {
+ fetchLastErrCode = FETCH_UNCHANGED;
+ snprintf(fetchLastErrString, MAXERRSTRING, "Unchanged");
+ return NULL;
+ }
+
/* just a stat */
if (strcmp(op, "STAT") == 0)
return fetchIO_unopen(NULL, NULL, NULL, NULL);
diff -r c72212a73d0e -r 39cb646d3998 net/libfetch/files/http.c
--- a/net/libfetch/files/http.c Thu Feb 05 16:39:18 2009 +0000
+++ b/net/libfetch/files/http.c Thu Feb 05 16:59:45 2009 +0000
@@ -1,8 +1,8 @@
-/* $NetBSD: http.c,v 1.20 2008/10/06 12:58:29 joerg Exp $ */
+/* $NetBSD: http.c,v 1.21 2009/02/05 16:59:45 joerg Exp $ */
/*-
* Copyright (c) 2000-2004 Dag-Erling Coïdan Smørgrav
* Copyright (c) 2003 Thomas Klausner <wiz%NetBSD.org@localhost>
- * Copyright (c) 2008 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
+ * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -112,6 +112,7 @@
#define HTTP_MOVED_PERM 301
#define HTTP_MOVED_TEMP 302
#define HTTP_SEE_OTHER 303
+#define HTTP_NOT_MODIFIED 304
#define HTTP_TEMP_REDIRECT 307
#define HTTP_NEED_AUTH 401
#define HTTP_NEED_PROXY_AUTH 407
@@ -745,6 +746,21 @@
return (NULL);
}
+static void
+set_if_modified_since(conn_t *conn, time_t last_modified)
+{
+ static const char weekdays[] = "SunMonTueWedThuFriSat";
+ static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+ struct tm tm;
+ char buf[80];
+ gmtime_r(&last_modified, &tm);
+ snprintf(buf, sizeof(buf), "%.3s, %02d %.3s %4d %02d:%02d:%02d GMT",
+ weekdays + tm.tm_wday * 3, tm.tm_mday, months + tm.tm_mon * 3,
+ tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
+ http_cmd(conn, "If-Modified-Since: %s", buf);
+}
+
+
/*****************************************************************************
* Core
*/
@@ -761,7 +777,7 @@
{
conn_t *conn;
struct url *url, *new;
Home |
Main Index |
Thread Index |
Old Index