From e7fa35baa22bf6710a904815456d3ff679005fc7 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 25 Apr 2021 11:03:54 -0700 Subject: add front-end provided context to callbacks Our callbacks require front-ends to maintain state in order to provide reasonable output. The new download callback in particular requires much more complex state information to be saved. Without the ability to provide context, state must be saved globally, which may not be possible for all front-ends. Scripting language bindings in particular have no way to register per-handle callbacks without some form of context. Implements: FS#12721 Signed-off-by: Andrew Gregory --- lib/libalpm/dload.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/libalpm/dload.c') diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index a4c42f8d..70ec318a 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -209,7 +209,8 @@ static int dload_progress_cb(void *file, curl_off_t dltotal, curl_off_t dlnow, * download_size (nor included in the total download size callback) */ cb_data.total = dltotal; cb_data.downloaded = dlnow; - payload->handle->dlcb(payload->remote_name, ALPM_DOWNLOAD_PROGRESS, &cb_data); + payload->handle->dlcb(payload->handle->dlcb_ctx, + payload->remote_name, ALPM_DOWNLOAD_PROGRESS, &cb_data); payload->prevprogress = current_size; return 0; @@ -672,7 +673,7 @@ cleanup: alpm_download_event_completed_t cb_data = {0}; cb_data.total = bytes_dl; cb_data.result = ret; - handle->dlcb(payload->remote_name, ALPM_DOWNLOAD_COMPLETED, &cb_data); + handle->dlcb(handle->dlcb_ctx, payload->remote_name, ALPM_DOWNLOAD_COMPLETED, &cb_data); } curl_multi_remove_handle(curlm, curl); @@ -806,7 +807,7 @@ static int curl_download_internal(alpm_handle_t *handle, if(curl_add_payload(handle, curlm, payload, localpath) == 0) { if(handle->dlcb && !payload->signature) { alpm_download_event_init_t cb_data = {.optional = payload->errors_ok}; - handle->dlcb(payload->remote_name, ALPM_DOWNLOAD_INIT, &cb_data); + handle->dlcb(handle->dlcb_ctx, payload->remote_name, ALPM_DOWNLOAD_INIT, &cb_data); } payloads = payloads->next; @@ -877,7 +878,7 @@ int _alpm_download(alpm_handle_t *handle, int success = 0; if(payload->fileurl) { - if (handle->fetchcb(payload->fileurl, localpath, payload->force) != -1) { + if (handle->fetchcb(handle->fetchcb_ctx, payload->fileurl, localpath, payload->force) != -1) { success = 1; break; } @@ -891,7 +892,7 @@ int _alpm_download(alpm_handle_t *handle, MALLOC(fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); snprintf(fileurl, len, "%s/%s", server, payload->filepath); - ret = handle->fetchcb(fileurl, localpath, payload->force); + ret = handle->fetchcb(handle->fetchcb_ctx, fileurl, localpath, payload->force); free(fileurl); if (ret != -1) { -- cgit v1.2.3-24-g4f1b