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
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;
}
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;
}
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