]> git.ipfire.org Git - pakfire.git/commitdiff
client: Implement listing uploads asynchronously
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 18:19:46 +0000 (18:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 18:19:46 +0000 (18:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/upload_list.c
src/pakfire/client.c
src/pakfire/client.h

index 2809e7c3ee3066371aacbcfc6c5daaea6921cd43..3444601edf37802971bd7710de967a04a545aa28 100644 (file)
 
 static const char* doc = "Lists all uploads";
 
+static int list_callback(struct pakfire_xfer* xfer,
+               pakfire_xfer_error_code_t code, struct json_object* response, void* data) {
+       // XXX For now, just dump the entire JSON object
+       return cli_dump_json(response);
+}
+
+static int ready_callback(struct pakfire_client* client, void* data) {
+       return pakfire_client_list_uploads(client, list_callback, data);
+}
+
 int cli_upload_list(void* data, int argc, char* argv[]) {
        struct cli_global_args* global_args = data;
        struct pakfire_client* client = NULL;
-       struct json_object* uploads = NULL;
        int r;
 
        // Parse the command line
@@ -45,21 +54,15 @@ int cli_upload_list(void* data, int argc, char* argv[]) {
        if (r < 0)
                goto ERROR;
 
-       // List uploads
-       r = pakfire_client_list_uploads(client, &uploads);
-       if (r)
-               goto ERROR;
+       // Set ready callback
+       pakfire_client_set_ready_callback(client, ready_callback, NULL);
 
-       // Dump everything
-       r = cli_dump_json(uploads);
-       if (r)
-               goto ERROR;
+       // Run the client
+       r = pakfire_client_run(client);
 
 ERROR:
        if (client)
                pakfire_client_unref(client);
-       if (uploads)
-               json_object_put(uploads);
 
        return r;
 }
index cabe8cd31f13b1c5b9625260dd2b1aa4d112293d..84de034a769c40a8a973af07ed8c852b9c739355 100644 (file)
@@ -1174,43 +1174,34 @@ ERROR:
        return r;
 }
 
-int pakfire_client_list_uploads(struct pakfire_client* self, struct json_object** p) {
+int pakfire_client_list_uploads(struct pakfire_client* self,
+               pakfire_client_list_uploads_callback callback, void* data) {
        struct pakfire_xfer* xfer = NULL;
-       struct json_object* response = NULL;
-       struct json_object* uploads = NULL;
        int r;
 
        // Create a new xfer
        r = pakfire_client_xfer_create(&xfer, self, "/api/v1/uploads");
-       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)
+       // Register the callback
+       r = pakfire_xfer_set_response_callback(xfer, callback, data);
+       if (r < 0)
                goto ERROR;
 
-       // Fetch the uploads
-       uploads = json_object_object_get(response, "uploads");
-       if (!uploads) {
-               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(uploads);
 
 ERROR:
        if (xfer)
                pakfire_xfer_unref(xfer);
-       if (response)
-               json_object_put(response);
 
        return r;
 }
index 8237ae4ae7e7db6418f41dad2095e758fd057645..2823a52872d9ccd8d433ce094bd87e95ae0ae26d 100644 (file)
@@ -91,7 +91,11 @@ typedef int (*pakfire_client_upload_callback)
 
 int pakfire_client_upload(struct pakfire_client* client,
        const char* path, const char* filename, pakfire_client_upload_callback callback, void* data);
-int pakfire_client_list_uploads(struct pakfire_client* client, struct json_object** uploads);
+
+typedef pakfire_xfer_response_callback pakfire_client_list_uploads_callback;
+
+int pakfire_client_list_uploads(struct pakfire_client* client,
+               pakfire_client_list_uploads_callback callback, void* data);
 int pakfire_client_delete_upload(struct pakfire_client* client, const char* uuid);
 
 // Repositories