]> git.ipfire.org Git - pakfire.git/commitdiff
client: Bring back an own HTTP client instance
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 14:49:00 +0000 (14:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 14:49:00 +0000 (14:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/pakfire.c
src/pakfire/client.c
src/pakfire/client.h
src/pakfire/daemon.c

index 4a5da2f271b33d8cf019ea2346e1d4d9270c3b70..083c38fffde4278ca4efb96a650731c4b41b10ae 100644 (file)
@@ -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;
index af6cae4f21e0dd4ef4fd2ff88eaa798d19b6d648..5068598d7768cddb00f06771ebb5aea066ca34ea 100644 (file)
@@ -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)
index b02f0d7fabeaa99c44a7fe38e07a7c1774ee78b4..f4d0b5201da561e34a143d533ab9a76732c89d16 100644 (file)
 struct pakfire_client;
 
 #include <json.h>
+#include <systemd/sd-event.h>
 
 #include <pakfire/ctx.h>
 
 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);
index 5f43dad27c633c292f34ae68fbad62fe2a79b061..13b71f32ade3930695eb04623c1f50ac388af267 100644 (file)
@@ -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;