From: Michael Tremer Date: Fri, 27 Jun 2025 08:37:08 +0000 (+0000) Subject: client: Refactor listing repositories X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b608e63e5c50500f7f8e7353e2130f15e2b9689a;p=pakfire.git client: Refactor listing repositories Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/repo_list.c b/src/cli/lib/repo_list.c index 1167169e..a155c5a1 100644 --- a/src/cli/lib/repo_list.c +++ b/src/cli/lib/repo_list.c @@ -52,38 +52,25 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) { return 0; } +static int ready_callback(struct pakfire_client* client, void* data) { + const struct cli_local_args* local_args = data; + + // XXX Needs a callback + + // List repos + return pakfire_client_list_repos(client, local_args->distro); +} + int cli_repo_list(void* data, int argc, char* argv[]) { struct cli_global_args* global_args = data; struct cli_local_args local_args = {}; - struct pakfire_client* client = NULL; - struct json_object* repos = NULL; int r; // Parse the command line r = cli_parse(NULL, NULL, NULL, doc, parse, 0, argc, argv, &local_args); if (r) - goto ERROR; - - // Connect to the build service - r = cli_setup_client(&client, global_args); - if (r < 0) - goto ERROR; - - // List repos - r = pakfire_client_list_repos(client, local_args.distro, &repos); - if (r) - goto ERROR; - - // Dump everything - r = cli_dump_json(repos); - if (r) - goto ERROR; - -ERROR: - if (client) - pakfire_client_unref(client); - if (repos) - json_object_put(repos); + return r; - return r; + // Run the client + return cli_run_client(global_args, ready_callback, &local_args); } diff --git a/src/pakfire/client.c b/src/pakfire/client.c index ffacdcd1..c182c38a 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -1332,11 +1332,8 @@ ERROR: // Repositories -int pakfire_client_list_repos(struct pakfire_client* self, - const char* distro, struct json_object** p) { +int pakfire_client_list_repos(struct pakfire_client* self, const char* distro) { struct pakfire_xfer* xfer = NULL; - struct json_object* response = NULL; - struct json_object* repos = NULL; int r; // Check inputs @@ -1345,34 +1342,24 @@ int pakfire_client_list_repos(struct pakfire_client* self, // Create a new xfer r = pakfire_client_xfer_create(&xfer, self, "/api/v1/repos/%s", distro); - if (r) + if (r < 0) goto ERROR; // Enable authentication r = pakfire_client_xfer_auth(self, xfer); - if (r) + if (r < 0) goto ERROR; - // Send the request - r = pakfire_xfer_run_api_request(xfer, NULL, &response); - if (r) - goto ERROR; + // XXX Needs a callback - // Fetch the repos - if (!json_object_object_get_ex(response, "repos", &repos)) { - ERROR(self->ctx, "Malformed response\n"); - r = -EBADMSG; + // Enqueue the transfer + r = pakfire_httpclient_enqueue(self->httpclient, xfer); + if (r < 0) goto ERROR; - } - - // Return the pointer - *p = json_object_get(repos); ERROR: if (xfer) pakfire_xfer_unref(xfer); - if (response) - json_object_put(response); return r; } diff --git a/src/pakfire/client.h b/src/pakfire/client.h index 99f07ad0..3e6bb549 100644 --- a/src/pakfire/client.h +++ b/src/pakfire/client.h @@ -104,8 +104,7 @@ int pakfire_client_delete_upload(struct pakfire_client* client, const char* uuid // Repositories -int pakfire_client_list_repos(struct pakfire_client* client, - const char* distro, struct json_object** repos); +int pakfire_client_list_repos(struct pakfire_client* client, const char* distro); int pakfire_client_get_repo(struct pakfire_client* client, const char* distro, const char* name); int pakfire_client_create_repo(struct pakfire_client* client,