From: Michael Tremer Date: Wed, 25 Jun 2025 11:18:47 +0000 (+0000) Subject: client: Call the upload callback when the upload has finished X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8420c2c2bc2f991b42d7f97911894e369df0ae59;p=pakfire.git client: Call the upload callback when the upload has finished Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/upload_create.c b/src/cli/lib/upload_create.c index 2628d569..c31b2616 100644 --- a/src/cli/lib/upload_create.c +++ b/src/cli/lib/upload_create.c @@ -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: diff --git a/src/pakfire/client.c b/src/pakfire/client.c index d430102f..859bb206 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -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); diff --git a/src/pakfire/client.h b/src/pakfire/client.h index 6e0b8fd6..0f66c322 100644 --- a/src/pakfire/client.h +++ b/src/pakfire/client.h @@ -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);