]> git.ipfire.org Git - pakfire.git/commitdiff
client: Refactor showing repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 08:33:54 +0000 (08:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 08:33:54 +0000 (08:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/repo_show.c
src/pakfire/client.c
src/pakfire/client.h

index f9481f9a415918e6aa759ad037b5a98307ded34f..7ee79353d7b0f425d537c8bf1141c05d5edb6d48 100644 (file)
@@ -58,38 +58,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_get_repo(client, local_args->distro, local_args->name);
+}
+
 int cli_repo_show(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* repo = 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_get_repo(client, local_args.distro, local_args.name, &repo);
-       if (r)
-               goto ERROR;
-
-       // Dump everything
-       r = cli_dump_json(repo);
-       if (r)
-               goto ERROR;
-
-ERROR:
-       if (client)
-               pakfire_client_unref(client);
-       if (repo)
-               json_object_put(repo);
+               return r;
 
-       return r;
+       // Run the client
+       return cli_run_client(global_args, ready_callback, &local_args);
 }
index d20344e6a8f9c47602fb99e47829e3ab4b4c8129..ffacdcd18fdcdb3300c567cb374faba712c441e3 100644 (file)
@@ -1378,9 +1378,8 @@ ERROR:
 }
 
 int pakfire_client_get_repo(struct pakfire_client* self,
-               const char* distro, const char* name, struct json_object** p) {
+               const char* distro, const char* name) {
        struct pakfire_xfer* xfer = NULL;
-       struct json_object* response = NULL;
        int r;
 
        // Check inputs
@@ -1389,27 +1388,24 @@ int pakfire_client_get_repo(struct pakfire_client* self,
 
        // Create a new xfer
        r = pakfire_client_xfer_create(&xfer, self, "/api/v1/repos/%s/%s", distro, name);
-       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 This needs a callback
 
-       // Return the pointer
-       *p = json_object_get(response);
+       // Enqueue the transfer
+       r = pakfire_httpclient_enqueue(self->httpclient, xfer);
+       if (r < 0)
+               goto ERROR;
 
 ERROR:
        if (xfer)
                pakfire_xfer_unref(xfer);
-       if (response)
-               json_object_put(response);
 
        return r;
 }
index 10d03e18164658360a7712094b7e89115c6cba8b..99f07ad0ea10b46fb9607335bde2b5da1cf44386 100644 (file)
@@ -107,7 +107,7 @@ int pakfire_client_delete_upload(struct pakfire_client* client, const char* uuid
 int pakfire_client_list_repos(struct pakfire_client* client,
        const char* distro, struct json_object** repos);
 int pakfire_client_get_repo(struct pakfire_client* client,
-       const char* distro, const char* name, struct json_object** repo);
+       const char* distro, const char* name);
 int pakfire_client_create_repo(struct pakfire_client* client,
        const char* distro, const char* name, const char* description);
 int pakfire_client_delete_repo(struct pakfire_client* client,