#include <stdio.h>
#include <stdlib.h>
+#include <json.h>
+
#include <pakfire/package.h>
#include <pakfire/packagelist.h>
#include <pakfire/pakfire.h>
ERROR:
return r;
}
+
+int cli_dump_json(struct json_object* object) {
+ int r;
+
+ // Serialize the object as a JSON string
+ const char* buffer = json_object_to_json_string_ext(object,
+ JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_PRETTY_TAB);
+
+ // Print to the console
+ r = printf("%s\n", buffer);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
#ifndef PAKFIRE_CLI_DUMP_H
#define PAKFIRE_CLI_DUMP_H
+#include <json.h>
+
#include <pakfire/package.h>
#include <pakfire/packagelist.h>
#include <pakfire/pakfire.h>
int cli_dump_repolist(struct pakfire_repolist* list, int flags);
+int cli_dump_json(struct json_object* object);
+
#endif /* PAKFIRE_CLI_DUMP_H */
# #
#############################################################################*/
+#include <json.h>
+
#include <pakfire/buildservice.h>
#include <pakfire/ctx.h>
#include "command.h"
+#include "dump.h"
#include "upload_list.h"
static const char* doc = "Lists all uploads";
int cli_upload_list(void* data, int argc, char* argv[]) {
struct pakfire_buildservice* service = NULL;
+ struct json_object* uploads = NULL;
int r;
struct pakfire_ctx* ctx = data;
if (r)
goto ERROR;
- // XXX TODO
+ // List uploads
+ r = pakfire_buildservice_list_uploads(service, &uploads);
+ if (r)
+ goto ERROR;
+
+ // Dump everything
+ r = cli_dump_json(uploads);
+ if (r)
+ goto ERROR;
ERROR:
if (service)
pakfire_buildservice_unref(service);
+ if (uploads)
+ json_object_put(uploads);
return r;
}
#include <limits.h>
#include <stdlib.h>
+#include <json.h>
+
#include <pakfire/buildservice.h>
#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/logging.h>
#include <pakfire/private.h>
#include <pakfire/string.h>
+#include <pakfire/util.h>
#include <krb5/krb5.h>
pakfire_buildservice_free(service);
return NULL;
}
+
+static int pakfire_buildservice_create_transfer(struct pakfire_transfer** transfer,
+ struct pakfire_buildservice* service, const char* url) {
+ struct pakfire_transfer* t = NULL;
+ int r;
+
+ // Create a new transfer
+ r = pakfire_downloader_transfer_create(&t, service->httpclient, url);
+ if (r)
+ goto ERROR;
+
+ // Set the base URL
+ r = pakfire_downloader_transfer_set_baseurl(t, service->url);
+ if (r)
+ goto ERROR;
+
+ // Return the new transfer
+ *transfer = pakfire_downloader_transfer_ref(t);
+
+ERROR:
+ if (t)
+ pakfire_downloader_transfer_unref(t);
+
+ return r;
+}
+
+// Uploads
+
+PAKFIRE_EXPORT int pakfire_buildservice_list_uploads(
+ struct pakfire_buildservice* service, struct json_object** p) {
+ struct pakfire_transfer* transfer = NULL;
+ struct json_object* response = NULL;
+ struct json_object* uploads = NULL;
+ char* buffer = NULL;
+ size_t length = 0;
+ int r;
+
+ // Create a new transfer
+ r = pakfire_downloader_transfer_create(&transfer, service->httpclient, "/api/v1/uploads");
+ if (r)
+ goto ERROR;
+
+ // Set the base URL
+ r = pakfire_downloader_transfer_set_baseurl(transfer, service->url);
+ if (r)
+ goto ERROR;
+
+ // Enable authentication
+ r = pakfire_downloader_transfer_auth(transfer);
+ if (r)
+ goto ERROR;
+
+ // Write the response to the buffer
+ r = pakfire_downloader_transfer_set_output_buffer(transfer, &buffer, &length);
+ if (r)
+ goto ERROR;
+
+ // Run the transfer
+ r = pakfire_downloader_transfer_run(transfer, PAKFIRE_TRANSFER_NO_PROGRESS);
+ if (r)
+ goto ERROR;
+
+ // XXX would be nice to have the JSON error here
+
+ // Parse the response
+ response = pakfire_json_parse(service->ctx, buffer, length);
+ if (!response) {
+ CTX_ERROR(service->ctx, "Could not parse the response\n");
+ r = -EBADMSG;
+ goto ERROR;
+ }
+
+ // Fetch the uploads
+ uploads = json_object_object_get(response, "uploads");
+ if (!uploads) {
+ CTX_ERROR(service->ctx, "Malformed response\n");
+ r = -EBADMSG;
+ goto ERROR;
+ }
+
+ // Return the pointer
+ *p = json_object_get(uploads);
+
+ERROR:
+ if (transfer)
+ pakfire_downloader_transfer_unref(transfer);
+ if (response)
+ json_object_put(response);
+ if (buffer)
+ free(buffer);
+
+ return r;
+}