]> git.ipfire.org Git - pakfire.git/commitdiff
client: Call the upload callback when the upload has finished
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 11:18:47 +0000 (11:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 11:23:09 +0000 (11:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/upload_create.c
src/pakfire/client.c
src/pakfire/client.h

index 2628d569851429b9266c8773ef36b8a64a3b5a46..c31b26168299e3f00fb03c47d8bfb3a83ce6b59e 100644 (file)
@@ -56,10 +56,10 @@ static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
 }
 
 static int upload_callback(struct pakfire_client* client,
-               pakfire_client_upload_status status, const char* uuid, void* data) {
+               pakfire_client_upload_status status, const char* path, const char* uuid, void* data) {
        switch (status) {
                case PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL:
-                       printf("Successfully created upload %s\n", uuid);
+                       printf("Successfully uploaded %s as %s\n", path, uuid);
                        return 0;
 
                default:
index d430102fa205b9fba79f90ada0425c5e19ae94ce..859bb2064d8e8b98bf1b0d73596e1c0f1acd92f5 100644 (file)
@@ -50,6 +50,9 @@ struct pakfire_client_upload {
        // UUID
        char uuid[UUID_STR_LEN];
 
+       // Path
+       char path[PATH_MAX];
+
        // Filename
        char filename[NAME_MAX];
 
@@ -640,6 +643,11 @@ static int pakfire_client_upload_create(struct pakfire_client_upload** upload,
        // Reference the client
        self->client = client;
 
+       // Store the path
+       r = pakfire_string_set(self->path, path);
+       if (r < 0)
+               goto ERROR;
+
        // Compute the basename
        r = pakfire_path_basename(basename, path);
        if (r < 0)
@@ -699,6 +707,32 @@ ERROR:
        return r;
 }
 
+static int pakfire_upload_payload_callback(struct pakfire_xfer* xfer,
+               pakfire_xfer_error_code_t code, struct json_object* response, void* data) {
+       pakfire_client_upload_status status = PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL;
+       struct pakfire_client_upload* upload = data;
+       int r = 0;
+
+       // Determine the status
+       switch (code) {
+               case PAKFIRE_XFER_OK:
+                       break;
+
+               default:
+                       status = PAKFIRE_CLIENT_UPLOAD_ERROR;
+                       break;
+       }
+
+       // Call the callback (if any)
+       if (upload->callback)
+               r = upload->callback(upload->client, status, upload->path, upload->uuid, upload->data);
+
+       // Free the upload
+       pakfire_client_upload_free(upload);
+
+       return r;
+}
+
 static int pakfire_client_upload_payload(struct pakfire_client_upload* upload) {
        struct pakfire_client* self = upload->client;
        struct pakfire_xfer* xfer = NULL;
@@ -724,7 +758,10 @@ static int pakfire_client_upload_payload(struct pakfire_client_upload* upload) {
        if (r < 0)
                goto ERROR;
 
-       // XXX Set the callback
+       // Set the callback
+       r = pakfire_xfer_set_response_callback(xfer, pakfire_upload_payload_callback, upload);
+       if (r < 0)
+               goto ERROR;
 
        // Send the request
        r = pakfire_httpclient_enqueue(self->httpclient, xfer);
index 6e0b8fd65782263cd93c3c90bd3f2fd702d97811..0f66c32275f908d1cc2c880995cb2d8b64ac80c7 100644 (file)
@@ -78,7 +78,8 @@ typedef enum {
 } pakfire_client_upload_status;
 
 typedef int (*pakfire_client_upload_callback)
-       (struct pakfire_client* client, pakfire_client_upload_status status, const char* uuid, void* data);
+       (struct pakfire_client* client, pakfire_client_upload_status status,
+       const char* path, const char* uuid, void* data);
 
 int pakfire_client_upload(struct pakfire_client* client,
        const char* path, const char* filename, pakfire_client_upload_callback callback, void* data);