summaryrefslogtreecommitdiff
path: root/src/url.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-10-08 11:13:21 +0300
committerTimo Teräs <timo.teras@iki.fi>2014-10-08 11:13:21 +0300
commit32627939f5c57887b25100dd49aa91839876abed (patch)
treec39918143209386d1509c70d56fe8683878f2b30 /src/url.c
parent555363f056377508040d3a555d198c4b87aff3a3 (diff)
downloadapk-tools-32627939f5c57887b25100dd49aa91839876abed.tar.gz
apk-tools-32627939f5c57887b25100dd49aa91839876abed.tar.bz2
apk-tools-32627939f5c57887b25100dd49aa91839876abed.tar.xz
apk-tools-32627939f5c57887b25100dd49aa91839876abed.zip
io,url,db: support for if-modified-since
Diffstat (limited to 'src/url.c')
-rw-r--r--src/url.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/url.c b/src/url.c
index f3c6631..80f0a60 100644
--- a/src/url.c
+++ b/src/url.c
@@ -63,34 +63,43 @@ static void fetch_close(void *stream)
free(fis);
}
-static struct apk_istream *apk_istream_fetch(const char *url)
+static struct apk_istream *apk_istream_fetch(const char *url, time_t since)
{
struct apk_fetch_istream *fis;
+ struct url *u;
fetchIO *io;
- io = fetchGetURL(url, "");
- if (!io) return NULL;
-
- fis = malloc(sizeof(*fis));
- if (!fis) {
- fetchIO_close(io);
+ u = fetchParseURL(url);
+ if (!u) return NULL;
+ u->last_modified = since;
+ io = fetchGet(u, "i");
+ fetchFreeURL(u);
+ if (!io) {
+ if (fetchLastErrCode == FETCH_UNCHANGED) return ERR_PTR(-EALREADY);
return NULL;
}
+ fis = malloc(sizeof(*fis));
+ if (!fis) goto err;
+
*fis = (struct apk_fetch_istream) {
.is.read = fetch_read,
.is.close = fetch_close,
.fetchIO = io,
};
+ fetchFreeURL(u);
return &fis->is;
+err:
+ if (io) fetchIO_close(io);
+ return NULL;
}
-struct apk_istream *apk_istream_from_fd_url(int atfd, const char *url)
+struct apk_istream *apk_istream_from_fd_url_if_modified(int atfd, const char *url, time_t since)
{
if (apk_url_local_file(url) != NULL)
return apk_istream_from_file(atfd, apk_url_local_file(url));
- return apk_istream_fetch(url);
+ return apk_istream_fetch(url, since);
}
struct apk_istream *apk_istream_from_url_gz(const char *file)
@@ -98,9 +107,9 @@ struct apk_istream *apk_istream_from_url_gz(const char *file)
return apk_bstream_gunzip(apk_bstream_from_url(file));
}
-struct apk_bstream *apk_bstream_from_fd_url(int atfd, const char *url)
+struct apk_bstream *apk_bstream_from_fd_url_if_modified(int atfd, const char *url, time_t since)
{
if (apk_url_local_file(url) != NULL)
return apk_bstream_from_file(atfd, apk_url_local_file(url));
- return apk_bstream_from_istream(apk_istream_fetch(url));
+ return apk_bstream_from_istream(apk_istream_fetch(url, since));
}