From: Michael Tremer Date: Fri, 20 Oct 2023 16:01:58 +0000 (+0000) Subject: httpclient: Rename the downloader to HTTP client X-Git-Tag: 0.9.30~1401 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10db1faea58739fca4904b245ef6031ee061f1ef;p=pakfire.git httpclient: Rename the downloader to HTTP client Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 422ab6adc..a4e13fd8f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -223,10 +223,10 @@ libpakfire_la_SOURCES = \ src/libpakfire/dependencies.c \ src/libpakfire/digest.c \ src/libpakfire/dist.c \ - src/libpakfire/downloader.c \ src/libpakfire/fhs.c \ src/libpakfire/file.c \ src/libpakfire/filelist.c \ + src/libpakfire/httpclient.c \ src/libpakfire/jail.c \ src/libpakfire/key.c \ src/libpakfire/linter.c \ @@ -267,10 +267,10 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/dependencies.h \ src/libpakfire/include/pakfire/digest.h \ src/libpakfire/include/pakfire/dist.h \ - src/libpakfire/include/pakfire/downloader.h \ src/libpakfire/include/pakfire/fhs.h \ src/libpakfire/include/pakfire/file.h \ src/libpakfire/include/pakfire/filelist.h \ + src/libpakfire/include/pakfire/httpclient.h \ src/libpakfire/include/pakfire/i18n.h \ src/libpakfire/include/pakfire/jail.h \ src/libpakfire/include/pakfire/key.h \ diff --git a/src/libpakfire/buildservice.c b/src/libpakfire/buildservice.c index f70c001b4..dd731b854 100644 --- a/src/libpakfire/buildservice.c +++ b/src/libpakfire/buildservice.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ struct pakfire_buildservice { char keytab[PATH_MAX]; // A HTTP Client - struct pakfire_downloader* httpclient; + struct pakfire_httpclient* httpclient; // Kerberos Context krb5_context krb5_ctx; @@ -108,8 +108,8 @@ static int pakfire_buildservice_setup(struct pakfire_buildservice* service) { if (r) goto ERROR; - // Setup the downloader - r = pakfire_downloader_create(&service->httpclient, service->ctx); + // Setup the HTTP client + r = pakfire_httpclient_create(&service->httpclient, service->ctx); if (r) goto ERROR; @@ -129,7 +129,7 @@ static void pakfire_buildservice_free(struct pakfire_buildservice* service) { if (service->krb5_ctx) krb5_free_context(service->krb5_ctx); if (service->httpclient) - pakfire_downloader_unref(service->httpclient); + pakfire_httpclient_unref(service->httpclient); if (service->ctx) pakfire_ctx_unref(service->ctx); @@ -190,7 +190,7 @@ static int pakfire_buildservice_create_xfer(struct pakfire_xfer** xfer, int r; // Create a new xfer - r = pakfire_downloader_create_xfer(&t, service->httpclient, url); + r = pakfire_httpclient_create_xfer(&t, service->httpclient, url); if (r) goto ERROR; diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 989fd3386..b78433041 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -277,7 +277,7 @@ ERROR: return r; } -static int pakfire_dist_download_source(struct pakfire_downloader* downloader, +static int pakfire_dist_download_source(struct pakfire_httpclient* httpclient, struct pakfire_mirrorlist* mirrorlist, const char* filename, const char* cache_path) { struct pakfire_xfer* xfer = NULL; int r; @@ -287,7 +287,7 @@ static int pakfire_dist_download_source(struct pakfire_downloader* downloader, return 0; // Create a new transfer - r = pakfire_downloader_create_xfer(&xfer, downloader, filename); + r = pakfire_httpclient_create_xfer(&xfer, httpclient, filename); if (r) goto ERROR; @@ -314,7 +314,7 @@ ERROR: } static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packager* packager, - struct pakfire_package* pkg, struct pakfire_downloader* downloader, + struct pakfire_package* pkg, struct pakfire_httpclient* httpclient, struct pakfire_mirrorlist* mirrorlist, const char* filename) { char archive_path[PATH_MAX]; char cache_path[PATH_MAX]; @@ -328,7 +328,7 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa return r; // Download the source file - r = pakfire_dist_download_source(downloader, mirrorlist, filename, cache_path); + r = pakfire_dist_download_source(httpclient, mirrorlist, filename, cache_path); if (r) return r; @@ -342,7 +342,7 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_packager* packager, struct pakfire_package* pkg, struct pakfire_parser* makefile) { - struct pakfire_downloader* downloader = NULL; + struct pakfire_httpclient* httpclient = NULL; struct pakfire_mirrorlist* mirrorlist = NULL; char* sources = NULL; char* p = NULL; @@ -357,8 +357,8 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack struct pakfire_ctx* ctx = pakfire_ctx(pakfire); - // Create a downloader - r = pakfire_downloader_create(&downloader, ctx); + // Create a HTTP client + r = pakfire_httpclient_create(&httpclient, ctx); if (r) goto ERROR; @@ -373,7 +373,7 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack while (source) { DEBUG(pakfire, "Adding source file %s\n", source); - r = pakfire_dist_add_source(pakfire, packager, pkg, downloader, mirrorlist, source); + r = pakfire_dist_add_source(pakfire, packager, pkg, httpclient, mirrorlist, source); if (r) { ERROR(pakfire, "Could not add '%s' to package: %m\n", source); goto ERROR; @@ -386,8 +386,8 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack r = 0; ERROR: - if (downloader) - pakfire_downloader_unref(downloader); + if (httpclient) + pakfire_httpclient_unref(httpclient); if (mirrorlist) pakfire_mirrorlist_unref(mirrorlist); if (ctx) diff --git a/src/libpakfire/downloader.c b/src/libpakfire/httpclient.c similarity index 55% rename from src/libpakfire/downloader.c rename to src/libpakfire/httpclient.c index 4809cd408..7a97dcef9 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/httpclient.c @@ -24,7 +24,7 @@ #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ struct pakfire_xfer_element { struct pakfire_xfer* xfer; }; -struct pakfire_downloader { +struct pakfire_httpclient { struct pakfire_ctx* ctx; int nrefs; @@ -56,34 +56,34 @@ struct pakfire_downloader { TAILQ_HEAD(xfers_finished, pakfire_xfer_element) xfers_finished; }; -static int pakfire_downloader_setup_curl(struct pakfire_downloader* downloader) { +static int pakfire_httpclient_setup_curl(struct pakfire_httpclient* client) { int r; // Initialize cURL r = curl_global_init(CURL_GLOBAL_DEFAULT); if (r) { - CTX_ERROR(downloader->ctx, "Could not initialize cURL: %d\n", r); + CTX_ERROR(client->ctx, "Could not initialize cURL: %d\n", r); return r; } // Create a new share handle - downloader->share = curl_share_init(); - if (!downloader->share) { - CTX_ERROR(downloader->ctx, "Could not setup cURL share handle\n"); + client->share = curl_share_init(); + if (!client->share) { + CTX_ERROR(client->ctx, "Could not setup cURL share handle\n"); return 1; } // Create a new multi handle - downloader->curl = curl_multi_init(); - if (!downloader->curl) { - CTX_ERROR(downloader->ctx, "Could not create cURL multi handle\n"); + client->curl = curl_multi_init(); + if (!client->curl) { + CTX_ERROR(client->ctx, "Could not create cURL multi handle\n"); return 1; } // Share connections between handles - r = curl_share_setopt(downloader->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); + r = curl_share_setopt(client->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); if (r) { - CTX_ERROR(downloader->ctx, "Could not configure the share handle: %s\n", + CTX_ERROR(client->ctx, "Could not configure the share handle: %s\n", curl_share_strerror(r)); return r; } @@ -91,7 +91,7 @@ static int pakfire_downloader_setup_curl(struct pakfire_downloader* downloader) return 0; } -static struct pakfire_xfer_element* pakfire_downloader_xfer_create(struct pakfire_xfer* xfer) { +static struct pakfire_xfer_element* pakfire_httpclient_xfer_create(struct pakfire_xfer* xfer) { struct pakfire_xfer_element* x = NULL; // Allocate a new element @@ -105,11 +105,11 @@ static struct pakfire_xfer_element* pakfire_downloader_xfer_create(struct pakfir return x; } -static struct pakfire_xfer_element* pakfire_downloader_xfer_find_running( - struct pakfire_downloader* downloader, struct pakfire_xfer* xfer) { +static struct pakfire_xfer_element* pakfire_httpclient_xfer_find_running( + struct pakfire_httpclient* client, struct pakfire_xfer* xfer) { struct pakfire_xfer_element* x = NULL; - TAILQ_FOREACH(x, &downloader->xfers_running, nodes) { + TAILQ_FOREACH(x, &client->xfers_running, nodes) { if (x->xfer == xfer) return x; } @@ -117,52 +117,51 @@ static struct pakfire_xfer_element* pakfire_downloader_xfer_find_running( return NULL; } -static void pakfire_downloader_xfer_free(struct pakfire_xfer_element* x) { +static void pakfire_httpclient_xfer_free(struct pakfire_xfer_element* x) { if (x->xfer) pakfire_xfer_unref(x->xfer); free(x); } -static void pakfire_downloader_free(struct pakfire_downloader* downloader) { +static void pakfire_httpclient_free(struct pakfire_httpclient* client) { struct pakfire_xfer_element* x = NULL; // Free any queued transfers - while (!TAILQ_EMPTY(&downloader->xfers_queued)) { - x = TAILQ_LAST(&downloader->xfers_queued, xfers_queued); - TAILQ_REMOVE(&downloader->xfers_queued, x, nodes); + while (!TAILQ_EMPTY(&client->xfers_queued)) { + x = TAILQ_LAST(&client->xfers_queued, xfers_queued); + TAILQ_REMOVE(&client->xfers_queued, x, nodes); - pakfire_downloader_xfer_free(x); + pakfire_httpclient_xfer_free(x); } // Free any running transfers - while (!TAILQ_EMPTY(&downloader->xfers_running)) { - x = TAILQ_LAST(&downloader->xfers_running, xfers_running); - TAILQ_REMOVE(&downloader->xfers_running, x, nodes); + while (!TAILQ_EMPTY(&client->xfers_running)) { + x = TAILQ_LAST(&client->xfers_running, xfers_running); + TAILQ_REMOVE(&client->xfers_running, x, nodes); - pakfire_downloader_xfer_free(x); + pakfire_httpclient_xfer_free(x); } // Free any finished transfers - while (!TAILQ_EMPTY(&downloader->xfers_finished)) { - x = TAILQ_LAST(&downloader->xfers_finished, xfers_finished); - TAILQ_REMOVE(&downloader->xfers_finished, x, nodes); + while (!TAILQ_EMPTY(&client->xfers_finished)) { + x = TAILQ_LAST(&client->xfers_finished, xfers_finished); + TAILQ_REMOVE(&client->xfers_finished, x, nodes); - pakfire_downloader_xfer_free(x); + pakfire_httpclient_xfer_free(x); } - if (downloader->share) - curl_share_cleanup(downloader->share); - if (downloader->curl) - curl_multi_cleanup(downloader->curl); - if (downloader->ctx) - pakfire_ctx_unref(downloader->ctx); - free(downloader); + if (client->share) + curl_share_cleanup(client->share); + if (client->curl) + curl_multi_cleanup(client->curl); + if (client->ctx) + pakfire_ctx_unref(client->ctx); + free(client); } -int pakfire_downloader_create( - struct pakfire_downloader** downloader, struct pakfire_ctx* ctx) { - struct pakfire_downloader* d = NULL; +int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire_ctx* ctx) { + struct pakfire_httpclient* c = NULL; int r; // Fail if the context is flagged as offline @@ -172,85 +171,85 @@ int pakfire_downloader_create( } // Allocate a new object - d = calloc(1, sizeof(*d)); - if (!d) + c = calloc(1, sizeof(*c)); + if (!c) return -ENOMEM; // Store reference to the context - d->ctx = pakfire_ctx_ref(ctx); + c->ctx = pakfire_ctx_ref(ctx); // Initialize reference counting - d->nrefs = 1; + c->nrefs = 1; // Set parallelism - d->parallel = MAX_PARALLEL; + c->parallel = MAX_PARALLEL; // Init transfer queues - TAILQ_INIT(&d->xfers_queued); - TAILQ_INIT(&d->xfers_running); - TAILQ_INIT(&d->xfers_finished); + TAILQ_INIT(&c->xfers_queued); + TAILQ_INIT(&c->xfers_running); + TAILQ_INIT(&c->xfers_finished); // Setup cURL - r = pakfire_downloader_setup_curl(d); + r = pakfire_httpclient_setup_curl(c); if (r) goto ERROR; // Success - *downloader = d; + *client = c; return 0; ERROR: - pakfire_downloader_free(d); + pakfire_httpclient_free(c); return r; } -struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* downloader) { - ++downloader->nrefs; +struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* client) { + ++client->nrefs; - return downloader; + return client; } -struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* downloader) { - if (--downloader->nrefs > 0) - return downloader; +struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* client) { + if (--client->nrefs > 0) + return client; - pakfire_downloader_free(downloader); + pakfire_httpclient_free(client); return NULL; } -CURLSH* pakfire_downloader_share(struct pakfire_downloader* downloader) { - return downloader->share; +CURLSH* pakfire_httpclient_share(struct pakfire_httpclient* client) { + return client->share; } -int pakfire_downloader_create_xfer(struct pakfire_xfer** xfer, - struct pakfire_downloader* downloader, const char* url) { - return pakfire_xfer_create(xfer, downloader->ctx, downloader, url); +int pakfire_httpclient_create_xfer(struct pakfire_xfer** xfer, + struct pakfire_httpclient* client, const char* url) { + return pakfire_xfer_create(xfer, client->ctx, client, url); } -int pakfire_downloader_enqueue_xfer(struct pakfire_downloader* downloader, +int pakfire_httpclient_enqueue_xfer(struct pakfire_httpclient* client, struct pakfire_xfer* xfer) { struct pakfire_xfer_element* x = NULL; // Create a new queueable object - x = pakfire_downloader_xfer_create(xfer); + x = pakfire_httpclient_xfer_create(xfer); if (!x) return -errno; // Push this transfer onto the queue - TAILQ_INSERT_HEAD(&downloader->xfers_queued, x, nodes); + TAILQ_INSERT_HEAD(&client->xfers_queued, x, nodes); return 0; } -static size_t pakfire_downloader_total_downloadsize(struct pakfire_downloader* downloader) { +static size_t pakfire_httpclient_total_downloadsize(struct pakfire_httpclient* client) { struct pakfire_xfer_element* x = NULL; size_t size; size_t total_size = 0; - TAILQ_FOREACH(x, &downloader->xfers_queued, nodes) { + TAILQ_FOREACH(x, &client->xfers_queued, nodes) { size = pakfire_xfer_get_size(x->xfer); // Return zero if the size isn't known @@ -263,30 +262,30 @@ static size_t pakfire_downloader_total_downloadsize(struct pakfire_downloader* d return total_size; } -static unsigned int pakfire_downloader_total_queued_xfers(struct pakfire_downloader* downloader) { +static unsigned int pakfire_httpclient_total_queued_xfers(struct pakfire_httpclient* client) { struct pakfire_xfer_element* x = NULL; unsigned int counter = 0; - TAILQ_FOREACH(x, &downloader->xfers_queued, nodes) + TAILQ_FOREACH(x, &client->xfers_queued, nodes) counter++; return counter; } -static int pakfire_downloader_start_transfers(struct pakfire_downloader* downloader, +static int pakfire_httpclient_start_transfers(struct pakfire_httpclient* client, struct pakfire_progress* progress, unsigned int* running_transfers) { struct pakfire_xfer_element* x = NULL; int r; // Keep running until we have reached our ceiling - while (*running_transfers < downloader->parallel) { + while (*running_transfers < client->parallel) { // We are done if there are no more transfers in the queue - if (TAILQ_EMPTY(&downloader->xfers_queued)) + if (TAILQ_EMPTY(&client->xfers_queued)) break; // Fetch the next transfer - x = TAILQ_LAST(&downloader->xfers_queued, xfers_queued); - TAILQ_REMOVE(&downloader->xfers_queued, x, nodes); + x = TAILQ_LAST(&client->xfers_queued, xfers_queued); + TAILQ_REMOVE(&client->xfers_queued, x, nodes); // Prepare the xfer r = pakfire_xfer_prepare(x->xfer, progress, 0); @@ -294,25 +293,25 @@ static int pakfire_downloader_start_transfers(struct pakfire_downloader* downloa goto ERROR; // Add the handle to cURL - r = curl_multi_add_handle(downloader->curl, pakfire_xfer_handle(x->xfer)); + r = curl_multi_add_handle(client->curl, pakfire_xfer_handle(x->xfer)); if (r) { - CTX_ERROR(downloader->ctx, "Adding handle failed: %s\n", curl_multi_strerror(r)); + CTX_ERROR(client->ctx, "Adding handle failed: %s\n", curl_multi_strerror(r)); goto ERROR; } - TAILQ_INSERT_TAIL(&downloader->xfers_running, x, nodes); + TAILQ_INSERT_TAIL(&client->xfers_running, x, nodes); (*running_transfers)++; } return 0; ERROR: - TAILQ_INSERT_TAIL(&downloader->xfers_finished, x, nodes); + TAILQ_INSERT_TAIL(&client->xfers_finished, x, nodes); return r; } -int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* title) { +int pakfire_httpclient_run(struct pakfire_httpclient* client, const char* title) { struct pakfire_progress* progress = NULL; struct pakfire_xfer* xfer = NULL; unsigned int running_xfers = 0; @@ -328,7 +327,7 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti int msgs_left = -1; // Fetch the total downloadsize - const size_t downloadsize = pakfire_downloader_total_downloadsize(downloader); + const size_t downloadsize = pakfire_httpclient_total_downloadsize(client); // If we know the downloadsize, we can show more details if (downloadsize) { @@ -341,10 +340,10 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti } // Fetch the total number of queued transfers - const unsigned int num_queued_xfers = pakfire_downloader_total_queued_xfers(downloader); + const unsigned int num_queued_xfers = pakfire_httpclient_total_queued_xfers(client); // Create a new progress indicator - r = pakfire_progress_create(&progress, downloader->ctx, progress_flags, NULL); + r = pakfire_progress_create(&progress, client->ctx, progress_flags, NULL); if (r) goto ERROR; @@ -363,21 +362,21 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti do { // Make sure that we have up to parallel transfers active if (!r) { - r = pakfire_downloader_start_transfers(downloader, progress, &running_xfers); + r = pakfire_httpclient_start_transfers(client, progress, &running_xfers); if (r) goto ERROR; } // Run cURL - r = curl_multi_perform(downloader->curl, &still_running); + r = curl_multi_perform(client->curl, &still_running); if (r) { - CTX_ERROR(downloader->ctx, "cURL error: %s\n", curl_easy_strerror(r)); + CTX_ERROR(client->ctx, "cURL error: %s\n", curl_easy_strerror(r)); goto ERROR; } for (;;) { // Read the next message - msg = curl_multi_info_read(downloader->curl, &msgs_left); + msg = curl_multi_info_read(client->curl, &msgs_left); if (!msg) break; @@ -387,14 +386,14 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &xfer); // Remove the handle - curl_multi_remove_handle(downloader->curl, pakfire_xfer_handle(xfer)); + curl_multi_remove_handle(client->curl, pakfire_xfer_handle(xfer)); // Find the matching xfer element - x = pakfire_downloader_xfer_find_running(downloader, xfer); + x = pakfire_httpclient_xfer_find_running(client, xfer); // Remove the transfer from the running list if (x) - TAILQ_REMOVE(&downloader->xfers_running, x, nodes); + TAILQ_REMOVE(&client->xfers_running, x, nodes); running_xfers--; // Call the done callback @@ -403,13 +402,13 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti // If we are asked to try again we will re-queue the transfer case EAGAIN: if (x) - TAILQ_INSERT_TAIL(&downloader->xfers_queued, x, nodes); + TAILQ_INSERT_TAIL(&client->xfers_queued, x, nodes); break; // Otherwise this transfer has finished default: if (x) - TAILQ_INSERT_TAIL(&downloader->xfers_finished, x, nodes); + TAILQ_INSERT_TAIL(&client->xfers_finished, x, nodes); if (r) goto ERROR; break; @@ -420,15 +419,15 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti break; default: - CTX_ERROR(downloader->ctx, "Received unhandled cURL message %u\n", msg->msg); + CTX_ERROR(client->ctx, "Received unhandled cURL message %u\n", msg->msg); break; } } // Wait a little before going through the loop again if (still_running) - curl_multi_wait(downloader->curl, NULL, 0, 100, NULL); - } while (still_running || !TAILQ_EMPTY(&downloader->xfers_queued)); + curl_multi_wait(client->curl, NULL, 0, 100, NULL); + } while (still_running || !TAILQ_EMPTY(&client->xfers_queued)); // We are finished! r = pakfire_progress_finish(progress); @@ -436,10 +435,10 @@ int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* ti goto ERROR; ERROR: - // If the downloader was aborted, we need to fail all remaining running transfers - while (!TAILQ_EMPTY(&downloader->xfers_running)) { - x = TAILQ_LAST(&downloader->xfers_running, xfers_running); - TAILQ_REMOVE(&downloader->xfers_running, x, nodes); + // If the client was aborted, we need to fail all remaining running transfers + while (!TAILQ_EMPTY(&client->xfers_running)) { + x = TAILQ_LAST(&client->xfers_running, xfers_running); + TAILQ_REMOVE(&client->xfers_running, x, nodes); // Fail the transfer pakfire_xfer_fail(x->xfer, 0); diff --git a/src/libpakfire/include/pakfire/downloader.h b/src/libpakfire/include/pakfire/httpclient.h similarity index 70% rename from src/libpakfire/include/pakfire/downloader.h rename to src/libpakfire/include/pakfire/httpclient.h index 7909229f6..e937adb3c 100644 --- a/src/libpakfire/include/pakfire/downloader.h +++ b/src/libpakfire/include/pakfire/httpclient.h @@ -18,32 +18,32 @@ # # #############################################################################*/ -#ifndef PAKFIRE_DOWNLOADER_H -#define PAKFIRE_DOWNLOADER_H +#ifndef PAKFIRE_HTTPCLIENT_H +#define PAKFIRE_HTTPCLIENT_H #ifdef PAKFIRE_PRIVATE #include -struct pakfire_downloader; +struct pakfire_httpclient; #include #include -int pakfire_downloader_create(struct pakfire_downloader** downloader, struct pakfire_ctx* ctx); +int pakfire_httpclient_create(struct pakfire_httpclient** downloader, struct pakfire_ctx* ctx); -struct pakfire_downloader* pakfire_downloader_ref(struct pakfire_downloader* downloader); -struct pakfire_downloader* pakfire_downloader_unref(struct pakfire_downloader* downloader); +struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* downloader); +struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* downloader); -CURLSH* pakfire_downloader_share(struct pakfire_downloader* downloader); +CURLSH* pakfire_httpclient_share(struct pakfire_httpclient* downloader); -int pakfire_downloader_create_xfer(struct pakfire_xfer** xfer, - struct pakfire_downloader* downloader, const char* url); +int pakfire_httpclient_create_xfer(struct pakfire_xfer** xfer, + struct pakfire_httpclient* downloader, const char* url); -int pakfire_downloader_enqueue_xfer( - struct pakfire_downloader* downloader, struct pakfire_xfer* xfer); +int pakfire_httpclient_enqueue_xfer( + struct pakfire_httpclient* downloader, struct pakfire_xfer* xfer); -int pakfire_downloader_run(struct pakfire_downloader* downloader, const char* title); +int pakfire_httpclient_run(struct pakfire_httpclient* downloader, const char* title); #endif /* PAKFIRE_PRIVATE */ -#endif /* PAKFIRE_DOWNLOADER_H */ +#endif /* PAKFIRE_HTTPCLIENT_H */ diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index ce2e0fbab..727879f5a 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -98,7 +98,7 @@ int pakfire_repo_compose(struct pakfire* pakfire, const char* path, #include #include -#include +#include #include #include #include @@ -126,7 +126,7 @@ int pakfire_repo_add_archive(struct pakfire_repo* repo, int pakfire_repo_download_package( struct pakfire_repo* repo, - struct pakfire_downloader* downloader, + struct pakfire_httpclient* httpclient, struct pakfire_package* pkg, struct pakfire_xfer** xfer); diff --git a/src/libpakfire/include/pakfire/xfer.h b/src/libpakfire/include/pakfire/xfer.h index 332451b54..09e633357 100644 --- a/src/libpakfire/include/pakfire/xfer.h +++ b/src/libpakfire/include/pakfire/xfer.h @@ -28,7 +28,7 @@ struct pakfire_xfer; #include -#include +#include #include #include @@ -43,7 +43,7 @@ typedef enum pakfire_transfer_method { } pakfire_xfer_method_t; int pakfire_xfer_create(struct pakfire_xfer** transfer, struct pakfire_ctx* ctx, - struct pakfire_downloader* downloader, const char* url); + struct pakfire_httpclient* httpclient, const char* url); struct pakfire_xfer* pakfire_xfer_ref(struct pakfire_xfer* xfer); struct pakfire_xfer* pakfire_xfer_unref(struct pakfire_xfer* xfer); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index b4f3dc414..532acf90c 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -226,14 +226,14 @@ static int __pakfire_repo_path(struct pakfire_repo* repo, settings of this repository. */ static int pakfire_repo_create_xfer(struct pakfire_xfer** xfer, - struct pakfire_repo* repo, struct pakfire_downloader* downloader, const char* url) { + struct pakfire_repo* repo, struct pakfire_httpclient* httpclient, const char* url) { struct pakfire_mirrorlist* mirrorlist = NULL; struct pakfire_xfer* x = NULL; const char* baseurl = NULL; int r; // Create a new transfer - r = pakfire_downloader_create_xfer(&x, downloader, url); + r = pakfire_httpclient_create_xfer(&x, httpclient, url); if (r) goto ERROR; @@ -431,7 +431,7 @@ struct pakfire_mirrorlist* pakfire_repo_get_mirrorlist(struct pakfire_repo* repo static int pakfire_repo_download_database(struct pakfire_repo* repo, const char* filename, const char* path) { - struct pakfire_downloader* downloader = NULL; + struct pakfire_httpclient* httpclient = NULL; struct pakfire_xfer* xfer = NULL; char title[NAME_MAX]; char url[PATH_MAX]; @@ -455,13 +455,13 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo, if (r) return r; - // Create a downloader - r = pakfire_downloader_create(&downloader, repo->ctx); + // Create a HTTP client + r = pakfire_httpclient_create(&httpclient, repo->ctx); if (r) goto ERROR; // Create a new transfer - r = pakfire_repo_create_xfer(&xfer, repo, downloader, url); + r = pakfire_repo_create_xfer(&xfer, repo, httpclient, url); if (r) goto ERROR; @@ -483,8 +483,8 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo, ERROR: if (xfer) pakfire_xfer_unref(xfer); - if (downloader) - pakfire_downloader_unref(downloader); + if (httpclient) + pakfire_httpclient_unref(httpclient); return r; } @@ -581,7 +581,7 @@ ERROR: } static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int force) { - struct pakfire_downloader* downloader = NULL; + struct pakfire_httpclient* httpclient = NULL; struct pakfire_xfer* xfer = NULL; char* url = NULL; int r; @@ -622,13 +622,13 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int goto ERROR; } - // Create a new downloader - r = pakfire_downloader_create(&downloader, repo->ctx); + // Create a new HTTP client + r = pakfire_httpclient_create(&httpclient, repo->ctx); if (r) goto ERROR; // Create a new xfer - r = pakfire_repo_create_xfer(&xfer, repo, downloader, url); + r = pakfire_repo_create_xfer(&xfer, repo, httpclient, url); if (r) goto ERROR; @@ -640,8 +640,8 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int ERROR: if (xfer) pakfire_xfer_unref(xfer); - if (downloader) - pakfire_downloader_unref(downloader); + if (httpclient) + pakfire_httpclient_unref(httpclient); if (url) free(url); @@ -649,7 +649,7 @@ ERROR: } static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char* path, int force) { - struct pakfire_downloader* downloader = NULL; + struct pakfire_httpclient* httpclient = NULL; struct pakfire_xfer* xfer = NULL; int r; @@ -682,13 +682,13 @@ static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char* } } - // Create a downloader - r = pakfire_downloader_create(&downloader, repo->ctx); + // Create a HTTP client + r = pakfire_httpclient_create(&httpclient, repo->ctx); if (r) goto ERROR; // Create a new transfer - r = pakfire_repo_create_xfer(&xfer, repo, downloader, "repodata/repomd.json"); + r = pakfire_repo_create_xfer(&xfer, repo, httpclient, "repodata/repomd.json"); if (r) goto ERROR; @@ -705,8 +705,8 @@ static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char* ERROR: if (xfer) pakfire_xfer_unref(xfer); - if (downloader) - pakfire_downloader_unref(downloader); + if (httpclient) + pakfire_httpclient_unref(httpclient); return r; } @@ -1183,7 +1183,7 @@ PAKFIRE_EXPORT int pakfire_repo_is_installed_repo(struct pakfire_repo* repo) { return (r == 0); } -int pakfire_repo_download_package(struct pakfire_repo* repo, struct pakfire_downloader* downloader, +int pakfire_repo_download_package(struct pakfire_repo* repo, struct pakfire_httpclient* httpclient, struct pakfire_package* pkg, struct pakfire_xfer** xfer) { struct pakfire_xfer* x = NULL; const unsigned char* digest = NULL; @@ -1222,7 +1222,7 @@ int pakfire_repo_download_package(struct pakfire_repo* repo, struct pakfire_down } // Create a new transfer - r = pakfire_repo_create_xfer(&x, repo, downloader, url); + r = pakfire_repo_create_xfer(&x, repo, httpclient, url); if (r) goto ERROR; @@ -1265,7 +1265,7 @@ ERROR: static int pakfire_repo_download(struct pakfire_repo* repo, const char* url, struct pakfire_package** package) { - struct pakfire_downloader* downloader = NULL; + struct pakfire_httpclient* httpclient = NULL; struct pakfire_xfer* xfer = NULL; FILE* f = NULL; int r; @@ -1279,13 +1279,13 @@ static int pakfire_repo_download(struct pakfire_repo* repo, const char* url, goto ERROR; } - // Create the downloader - r = pakfire_downloader_create(&downloader, repo->ctx); + // Create the HTTP client + r = pakfire_httpclient_create(&httpclient, repo->ctx); if (r) goto ERROR; // Create a new transfer - r = pakfire_downloader_create_xfer(&xfer, downloader, url); + r = pakfire_httpclient_create_xfer(&xfer, httpclient, url); if (r) goto ERROR; @@ -1307,8 +1307,8 @@ static int pakfire_repo_download(struct pakfire_repo* repo, const char* url, ERROR: if (xfer) pakfire_xfer_unref(xfer); - if (downloader) - pakfire_downloader_unref(downloader); + if (httpclient) + pakfire_httpclient_unref(httpclient); if (f) fclose(f); diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index d26da2ac5..c0913de1a 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -31,9 +31,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -1818,7 +1818,7 @@ ERROR: } static int pakfire_transaction_download_package(struct pakfire_transaction* transaction, - struct pakfire_downloader* downloader, struct pakfire_package* pkg) { + struct pakfire_httpclient* httpclient, struct pakfire_package* pkg) { struct pakfire_repo* repo = NULL; struct pakfire_xfer* xfer = NULL; int r = 1; @@ -1829,7 +1829,7 @@ static int pakfire_transaction_download_package(struct pakfire_transaction* tran goto ERROR; // Create a xfer for this package - r = pakfire_repo_download_package(repo, downloader, pkg, &xfer); + r = pakfire_repo_download_package(repo, httpclient, pkg, &xfer); if (r) goto ERROR; @@ -1891,13 +1891,13 @@ END: } PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* transaction) { - struct pakfire_downloader* downloader; + struct pakfire_httpclient* httpclient = NULL; int r; - // Initialize the downloader - r = pakfire_downloader_create(&downloader, transaction->ctx); + // Initialize the HTTP client + r = pakfire_httpclient_create(&httpclient, transaction->ctx); if (r) { - ERROR(transaction->pakfire, "Could not initialize downloader: %m\n"); + ERROR(transaction->pakfire, "Could not initialize HTTP client: %m\n"); return 1; } @@ -1909,7 +1909,7 @@ PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* tran continue; // Enqueue download - r = pakfire_transaction_download_package(transaction, downloader, pkg); + r = pakfire_transaction_download_package(transaction, httpclient, pkg); if (r) { const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); @@ -1918,11 +1918,11 @@ PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* tran } } - // Run the downloader - r = pakfire_downloader_run(downloader, _("Downloading Packages")); + // Run the HTTP client + r = pakfire_httpclient_run(httpclient, _("Downloading Packages")); ERROR: - pakfire_downloader_unref(downloader); + pakfire_httpclient_unref(httpclient); return r; } diff --git a/src/libpakfire/xfer.c b/src/libpakfire/xfer.c index 5b66afd5e..7541072be 100644 --- a/src/libpakfire/xfer.c +++ b/src/libpakfire/xfer.c @@ -40,8 +40,8 @@ struct pakfire_xfer { struct pakfire_ctx* ctx; int nrefs; - // Reference to the downloader - struct pakfire_downloader* downloader; + // Reference to the HTTP client + struct pakfire_httpclient* client; // Reference to the progress indicator struct pakfire_progress* progress; @@ -211,7 +211,7 @@ static int pakfire_xfer_setup(struct pakfire_xfer* xfer) { const char* proxy = NULL; int r; - CURLSH* share = pakfire_downloader_share(xfer->downloader); + CURLSH* share = pakfire_httpclient_share(xfer->client); // Configure the share handle r = curl_easy_setopt(xfer->handle, CURLOPT_SHARE, share); @@ -280,7 +280,7 @@ static int pakfire_xfer_setup(struct pakfire_xfer* xfer) { } int pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx, - struct pakfire_downloader* downloader, const char* url) { + struct pakfire_httpclient* client, const char* url) { struct pakfire_xfer* x = NULL; int r; @@ -295,8 +295,8 @@ int pakfire_xfer_create(struct pakfire_xfer** xfer, struct pakfire_ctx* ctx, // Initialize the reference counter x->nrefs = 1; - // Store a reference to the downloader - x->downloader = pakfire_downloader_ref(downloader); + // Store a reference to the HTTP client + x->client = pakfire_httpclient_ref(client); // Store the URL r = pakfire_string_set(x->url, url);