]> git.ipfire.org Git - pakfire.git/commitdiff
client: Drop the custom build callback
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 09:25:48 +0000 (09:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 09:25:48 +0000 (09:25 +0000)
It is much easier and more versatile to return the entire raw response
and later maybe add some getter functions.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/client-build.c
src/pakfire/client.c
src/pakfire/client.h

index 36bcad181aa416362eb9b167a7a25470f82c6ed4..9bb09acd58d3e8c943889b84ef650e2b24be9f3b 100644 (file)
@@ -21,6 +21,8 @@
 #include <argp.h>
 
 #include <pakfire/client.h>
+#include <pakfire/json.h>
+#include <pakfire/xfer.h>
 
 #include "client-build.h"
 #include "command.h"
@@ -96,22 +98,21 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
        return 0;
 }
 
-static int build_callback(struct pakfire_client* client, int status, const char* uuid, void* data) {
-       struct cli_local_args* local_args = data;
-
-       // Was there an error?
-       if (status) {
-               // Store the status
-               local_args->status = status;
+static int build_callback(struct pakfire_xfer* xfer,
+               const pakfire_xfer_response* response, void* data) {
+       const char* uuid = NULL;
+       int r;
 
-               // XXX Can we add any useful information which package it was and what the reason was?
+       // Handle errors
+       if (response->error) {
                fprintf(stderr, "Failed to create build\n");
-
-               return 0;
+               return 1;
        }
 
-       // XXX Here, we should actually send another API request that fetches the entire build object
-       // or change the callback so that we receive the raw (parsed) JSON objects.
+       // Fetch the UUID
+       r = pakfire_json_get_string(response->data, "uuid", &uuid);
+       if (r < 0)
+               return r;
 
        // Show status
        printf("Created build %s\n", uuid);
@@ -127,7 +128,7 @@ static int upload_callback(struct pakfire_client* client,
 
        // Create the build
        r = pakfire_client_build(client, uuid, local_args->repo,
-                       local_args->arches, local_args->flags, build_callback, local_args);
+                       local_args->arches, local_args->flags, build_callback, NULL);
        if (r < 0) {
                fprintf(stderr, "Failed to create build from %s: %s\n", path, strerror(-r));
 
index 1f0c016b19b3c8f0cda585738dba77309ef669d2..cb4fba0e7fd023f9e66a599b5201a5fb2c408401 100644 (file)
@@ -851,78 +851,12 @@ int pakfire_client_builder_disconnected(struct pakfire_client* self, struct pakf
 
 // Build
 
-struct pakfire_client_build {
-       // Client
-       struct pakfire_client* client;
-
-       // Callback
-       pakfire_client_build_callback callback;
-       void* data;
-};
-
-static int pakfire_client_build_create(struct pakfire_client_build** build,
-               struct pakfire_client* client) {
-       struct pakfire_client_build* self = NULL;
-
-       // Allocate a new object
-       self = calloc(1, sizeof(*self));
-       if (!self)
-               return -errno;
-
-       // Store a reference to the client
-       self->client = pakfire_client_ref(client);
-
-       // Return the pointer
-       *build = self;
-
-       return 0;
-}
-
-static void pakfire_client_build_free(struct pakfire_client_build* self) {
-       if (self->client)
-               pakfire_client_unref(self->client);
-       free(self);
-}
-
-static int pakfire_client_build_response(struct pakfire_xfer* xfer,
-               const pakfire_xfer_response* response, void* data) {
-       struct pakfire_client_build* build = data;
-       const char* uuid = NULL;
-       int r = 0;
-
-       // Only process this if we have a callback
-       if (build->callback) {
-               // Extract the UUID from the response
-               r = pakfire_json_get_string(response->data, "uuid", &uuid);
-               if (r < 0)
-                       goto ERROR;
-
-               // Call the callback
-               r = build->callback(build->client, response->error, uuid, build->data);
-       }
-
-ERROR:
-       pakfire_client_build_free(build);
-
-       return r;
-}
-
 int pakfire_client_build(struct pakfire_client* self, const char* upload, const char* repo,
-               const char** arches, int flags, pakfire_client_build_callback callback, void* data) {
-       struct pakfire_client_build* build = NULL;
+               const char** arches, int flags, pakfire_xfer_response_callback callback, void* data) {
        struct pakfire_xfer* xfer = NULL;
        struct json_object* request = NULL;
        int r;
 
-       // Create a new build object
-       r = pakfire_client_build_create(&build, self);
-       if (r < 0)
-               goto ERROR;
-
-       // Store the callback
-       build->callback = callback;
-       build->data     = data;
-
        // Create a new xfer
        r = pakfire_client_xfer_create(&xfer, self, "/api/v1/builds");
        if (r < 0)
@@ -969,7 +903,7 @@ int pakfire_client_build(struct pakfire_client* self, const char* upload, const
                goto ERROR;
 
        // Register the callback
-       r = pakfire_xfer_set_response_callback(xfer, pakfire_client_build_response, build);
+       r = pakfire_xfer_set_response_callback(xfer, callback, data);
        if (r < 0)
                goto ERROR;
 
@@ -982,10 +916,6 @@ ERROR:
        if (xfer)
                pakfire_xfer_unref(xfer);
 
-       // Remove the build on error
-       if (r && build)
-               pakfire_client_build_free(build);
-
        return r;
 }
 
index 0aac5871e634badc9f3e8f4852f815bb9d90c21c..c8effeba15de421448eb63aaa8312f8ea4926147 100644 (file)
@@ -76,11 +76,8 @@ typedef enum pakfire_client_build_flags {
        PAKFIRE_CLIENT_DISABLE_TESTS = (1 << 0),
 } pakfire_client_build_flags_t;
 
-typedef int (*pakfire_client_build_callback)
-       (struct pakfire_client* client, int status, const char* uuid, void* data);
-
 int pakfire_client_build(struct pakfire_client* client, const char* upload, const char* repo,
-       const char** arches, int flags, pakfire_client_build_callback callback, void* data);
+       const char** arches, int flags, pakfire_xfer_response_callback callback, void* data);
 
 // Uploads