]> git.ipfire.org Git - pakfire.git/commitdiff
httpclient: Rename the downloader to HTTP client
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 16:01:58 +0000 (16:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Oct 2023 11:11:51 +0000 (11:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/buildservice.c
src/libpakfire/dist.c
src/libpakfire/httpclient.c [moved from src/libpakfire/downloader.c with 55% similarity]
src/libpakfire/include/pakfire/httpclient.h [moved from src/libpakfire/include/pakfire/downloader.h with 70% similarity]
src/libpakfire/include/pakfire/repo.h
src/libpakfire/include/pakfire/xfer.h
src/libpakfire/repo.c
src/libpakfire/transaction.c
src/libpakfire/xfer.c

index 422ab6adca8b741439764dc5034977bd575a78d8..a4e13fd8f5c8247491a1f968303e09db5b7e1e1e 100644 (file)
@@ -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 \
index f70c001b4f2c2ba2fcd1171b3a4a36864b761f55..dd731b8543c4d2baf67561abb5abb2bc6694e590 100644 (file)
@@ -28,7 +28,7 @@
 #include <pakfire/config.h>
 #include <pakfire/ctx.h>
 #include <pakfire/digest.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/logging.h>
 #include <pakfire/path.h>
 #include <pakfire/private.h>
@@ -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;
 
index 989fd3386e62f664386eaf05679e28863c09c642..b7843304147acc66c025452f2a1714c5a85ad212 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <pakfire/arch.h>
 #include <pakfire/dist.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/i18n.h>
 #include <pakfire/linter.h>
 #include <pakfire/logging.h>
@@ -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)
similarity index 55%
rename from src/libpakfire/downloader.c
rename to src/libpakfire/httpclient.c
index 4809cd408dd28b393c5591096d9b5651fb2f4193..7a97dcef91910368bc00fb044c67828cffff08af 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <curl/curl.h>
 
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/logging.h>
 #include <pakfire/progress.h>
 #include <pakfire/xfer.h>
@@ -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);
similarity index 70%
rename from src/libpakfire/include/pakfire/downloader.h
rename to src/libpakfire/include/pakfire/httpclient.h
index 7909229f6a616f870c055e0d0af84e4645c63772..e937adb3c1a56094697a5790d80c485c8dd0e6ce 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#ifndef PAKFIRE_DOWNLOADER_H
-#define PAKFIRE_DOWNLOADER_H
+#ifndef PAKFIRE_HTTPCLIENT_H
+#define PAKFIRE_HTTPCLIENT_H
 
 #ifdef PAKFIRE_PRIVATE
 
 #include <curl/curl.h>
 
-struct pakfire_downloader;
+struct pakfire_httpclient;
 
 #include <pakfire/ctx.h>
 #include <pakfire/xfer.h>
 
-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 */
index ce2e0fbab58ab37c625554352f86e148aa19ea47..727879f5a4dc8b5c9cdf16c86bcd0ea9c13fecd7 100644 (file)
@@ -98,7 +98,7 @@ int pakfire_repo_compose(struct pakfire* pakfire, const char* path,
 
 #include <pakfire/archive.h>
 #include <pakfire/config.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/package.h>
 #include <pakfire/packagelist.h>
 #include <pakfire/xfer.h>
@@ -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);
 
index 332451b54565266ed57b24d9316bdf4c64f24bd7..09e6333578e61f5454b609eb7b64793cc10f6280 100644 (file)
@@ -28,7 +28,7 @@
 struct pakfire_xfer;
 
 #include <pakfire/ctx.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/mirrorlist.h>
 #include <pakfire/progress.h>
 
@@ -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);
index b4f3dc414e1c36cb983c5258477de502aa37cd2b..532acf90cac969b0141f30b022e739959c9a2f4e 100644 (file)
@@ -36,7 +36,7 @@
 #include <pakfire/config.h>
 #include <pakfire/constants.h>
 #include <pakfire/ctx.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/file.h>
 #include <pakfire/filelist.h>
 #include <pakfire/i18n.h>
@@ -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);
 
index d26da2ac5ae4fe476df3e1b48b14597c325e595d..c0913de1a8c6853e91b2068528f3175255d887b7 100644 (file)
@@ -31,9 +31,9 @@
 #include <pakfire/db.h>
 #include <pakfire/dependencies.h>
 #include <pakfire/digest.h>
-#include <pakfire/downloader.h>
 #include <pakfire/file.h>
 #include <pakfire/filelist.h>
+#include <pakfire/httpclient.h>
 #include <pakfire/i18n.h>
 #include <pakfire/jail.h>
 #include <pakfire/logging.h>
@@ -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;
 }
index 5b66afd5ef8959148ba2268993d4d3583c3c3586..7541072be7c294f3e466a29ea991f261235abc1d 100644 (file)
@@ -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);