From: Michael Tremer Date: Fri, 27 Jun 2025 09:25:48 +0000 (+0000) Subject: client: Drop the custom build callback X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=731d3d79006b0547636622fc26ea98f766086272;p=pakfire.git client: Drop the custom build callback 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 --- diff --git a/src/cli/lib/client-build.c b/src/cli/lib/client-build.c index 36bcad18..9bb09acd 100644 --- a/src/cli/lib/client-build.c +++ b/src/cli/lib/client-build.c @@ -21,6 +21,8 @@ #include #include +#include +#include #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)); diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 1f0c016b..cb4fba0e 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -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; } diff --git a/src/pakfire/client.h b/src/pakfire/client.h index 0aac5871..c8effeba 100644 --- a/src/pakfire/client.h +++ b/src/pakfire/client.h @@ -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