From: Michael Tremer Date: Tue, 24 Jun 2025 14:49:00 +0000 (+0000) Subject: client: Bring back an own HTTP client instance X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64df485cf85d4626f9abd2830e4d757c1002ac60;p=pakfire.git client: Bring back an own HTTP client instance Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/pakfire.c b/src/cli/lib/pakfire.c index 4a5da2f2..083c38ff 100644 --- a/src/cli/lib/pakfire.c +++ b/src/cli/lib/pakfire.c @@ -154,7 +154,7 @@ int cli_setup_client(struct pakfire_client** client, struct cli_global_args* arg url = pakfire_config_get(config, "client", "url", "https://pakfire.ipfire.org/"); // Connect to the build service - r = pakfire_client_create(client, args->ctx, url); + r = pakfire_client_create(client, args->ctx, NULL, url); if (r < 0) { fprintf(stderr, "Could not setup the build service: %s\n", strerror(-r)); goto ERROR; diff --git a/src/pakfire/client.c b/src/pakfire/client.c index af6cae4f..5068598d 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -41,6 +41,9 @@ struct pakfire_client { struct pakfire_ctx* ctx; int nrefs; + // HTTP Client + struct pakfire_httpclient* httpclient; + // URL char url[PATH_MAX]; @@ -242,6 +245,8 @@ static int pakfire_client_xfer_auth(struct pakfire_client* self, struct pakfire_ } static void pakfire_client_free(struct pakfire_client* self) { + if (self->httpclient) + pakfire_httpclient_unref(self->httpclient); if (self->ctx) pakfire_ctx_unref(self->ctx); @@ -249,7 +254,7 @@ static void pakfire_client_free(struct pakfire_client* self) { } int pakfire_client_create(struct pakfire_client** client, - struct pakfire_ctx* ctx, const char* url) { + struct pakfire_ctx* ctx, sd_event* loop, const char* url) { struct pakfire_client* self = NULL; int r; @@ -264,6 +269,11 @@ int pakfire_client_create(struct pakfire_client** client, // Initialize the reference counter self->nrefs = 1; + // Create a new HTTP client + r = pakfire_httpclient_create(&self->httpclient, self->ctx, loop); + if (r < 0) + goto ERROR; + // Store the URL r = pakfire_string_set(self->url, url); if (r < 0) diff --git a/src/pakfire/client.h b/src/pakfire/client.h index b02f0d7f..f4d0b520 100644 --- a/src/pakfire/client.h +++ b/src/pakfire/client.h @@ -24,11 +24,12 @@ struct pakfire_client; #include +#include #include int pakfire_client_create(struct pakfire_client** client, - struct pakfire_ctx* ctx, const char* url); + struct pakfire_ctx* ctx, sd_event* loop, const char* url); struct pakfire_client* pakfire_client_ref(struct pakfire_client* client); struct pakfire_client* pakfire_client_unref(struct pakfire_client* client); diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index 5f43dad2..13b71f32 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -1136,7 +1136,7 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct goto ERROR; // Connect to the build service - r = pakfire_client_create(&d->client, d->ctx, d->url); + r = pakfire_client_create(&d->client, d->ctx, d->loop, d->url); if (r < 0) goto ERROR;