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 \
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 \
#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>
char keytab[PATH_MAX];
// A HTTP Client
- struct pakfire_downloader* httpclient;
+ struct pakfire_httpclient* httpclient;
// Kerberos Context
krb5_context krb5_ctx;
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;
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);
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;
#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>
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;
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;
}
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];
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;
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;
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;
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;
r = 0;
ERROR:
- if (downloader)
- pakfire_downloader_unref(downloader);
+ if (httpclient)
+ pakfire_httpclient_unref(httpclient);
if (mirrorlist)
pakfire_mirrorlist_unref(mirrorlist);
if (ctx)
#include <curl/curl.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
#include <pakfire/logging.h>
#include <pakfire/progress.h>
#include <pakfire/xfer.h>
struct pakfire_xfer* xfer;
};
-struct pakfire_downloader {
+struct pakfire_httpclient {
struct pakfire_ctx* ctx;
int nrefs;
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;
}
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
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;
}
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
}
// 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
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);
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;
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) {
}
// 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;
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;
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
// 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;
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);
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);
# #
#############################################################################*/
-#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 */
#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>
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);
struct pakfire_xfer;
#include <pakfire/ctx.h>
-#include <pakfire/downloader.h>
+#include <pakfire/httpclient.h>
#include <pakfire/mirrorlist.h>
#include <pakfire/progress.h>
} 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);
#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>
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;
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];
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;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (downloader)
- pakfire_downloader_unref(downloader);
+ if (httpclient)
+ pakfire_httpclient_unref(httpclient);
return r;
}
}
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;
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;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (downloader)
- pakfire_downloader_unref(downloader);
+ if (httpclient)
+ pakfire_httpclient_unref(httpclient);
if (url)
free(url);
}
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;
}
}
- // 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;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (downloader)
- pakfire_downloader_unref(downloader);
+ if (httpclient)
+ pakfire_httpclient_unref(httpclient);
return r;
}
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;
}
// 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;
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;
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;
ERROR:
if (xfer)
pakfire_xfer_unref(xfer);
- if (downloader)
- pakfire_downloader_unref(downloader);
+ if (httpclient)
+ pakfire_httpclient_unref(httpclient);
if (f)
fclose(f);
#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>
}
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;
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;
}
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;
}
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);
}
}
- // 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;
}
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;
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);
}
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;
// 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);