}
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:
// UUID
char uuid[UUID_STR_LEN];
+ // Path
+ char path[PATH_MAX];
+
// Filename
char filename[NAME_MAX];
// 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)
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;
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);
} 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);