From e2fa0d8772728edd57dda78ada801235b85eda58 Mon Sep 17 00:00:00 2001 From: Sebastian Nowicki Date: Tue, 23 Dec 2008 01:39:23 +0900 Subject: [PATCH] Add fetch callback to allow frontend download support This allows a frontend to define its own download algorithm so that the libdownload/libfetch dependency can be omitted without using an external process. The callback will be used when it is defined and xfercommand is not. Signed-off-by: Sebastian Nowicki --- lib/libalpm/alpm.h | 5 +++++ lib/libalpm/dload.c | 2 ++ lib/libalpm/handle.c | 18 ++++++++++++++++++ lib/libalpm/handle.h | 1 + 4 files changed, 26 insertions(+), 0 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index eda35d3..c49fa78 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -83,6 +83,8 @@ int alpm_logaction(char *fmt, ...); typedef void (*alpm_cb_download)(const char *filename, off_t xfered, off_t total); typedef void (*alpm_cb_totaldl)(off_t total); +typedef void (*alpm_cb_fetch)(const char *url, const char *localpath, + time_t mtimeold, time_t *mtimenew, int *ret); /* * Options @@ -94,6 +96,9 @@ void alpm_option_set_logcb(alpm_cb_log cb); alpm_cb_download alpm_option_get_dlcb(); void alpm_option_set_dlcb(alpm_cb_download cb); +alpm_cb_fetch alpm_option_get_fetchcb(); +void alpm_option_set_fetchcb(alpm_cb_fetch cb); + alpm_cb_totaldl alpm_option_get_totaldlcb(); void alpm_option_set_totaldlcb(alpm_cb_totaldl cb); diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 9934f30..6da2323 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -362,6 +362,8 @@ static int download(const char *url, const char *localpath, #else RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1); #endif + } else if(handle->fetchcb) { + handle->fetchcb(url, localpath, mtimeold, mtimenew, &ret); } else { ret = download_external(url, localpath, mtimeold, mtimenew); } diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 7dc0122..f90d9fb 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -106,6 +106,15 @@ alpm_cb_download SYMEXPORT alpm_option_get_dlcb() return handle->dlcb; } +alpm_cb_fetch SYMEXPORT alpm_option_get_fetchcb() +{ + if (handle == NULL) { + pm_errno = PM_ERR_HANDLE_NULL; + return NULL; + } + return handle->fetchcb; +} + alpm_cb_totaldl SYMEXPORT alpm_option_get_totaldlcb() { if (handle == NULL) { @@ -268,6 +277,15 @@ void SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb) handle->dlcb = cb; } +void alpm_option_set_fetchcb(alpm_cb_fetch cb) +{ + if (handle == NULL) { + pm_errno = PM_ERR_HANDLE_NULL; + return; + } + handle->fetchcb = cb; +} + void SYMEXPORT alpm_option_set_totaldlcb(alpm_cb_totaldl cb) { if (handle == NULL) { diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index bec0a6f..7c69ffb 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -40,6 +40,7 @@ typedef struct _pmhandle_t { alpm_cb_log logcb; /* Log callback function */ alpm_cb_download dlcb; /* Download callback function */ alpm_cb_totaldl totaldlcb; /* Total download callback function */ + alpm_cb_fetch fetchcb; /* Download file callback function */ /* filesystem paths */ char *root; /* Root path, default '/' */ -- 1.6.0.1