#include <argp.h>
#include <pakfire/client.h>
+#include <pakfire/json.h>
+#include <pakfire/xfer.h>
#include "client-build.h"
#include "command.h"
return 0;
}
-static int build_callback(struct pakfire_client* client, int status, const char* uuid, void* data) {
- struct cli_local_args* local_args = data;
-
- // Was there an error?
- if (status) {
- // Store the status
- local_args->status = status;
+static int build_callback(struct pakfire_xfer* xfer,
+ const pakfire_xfer_response* response, void* data) {
+ const char* uuid = NULL;
+ int r;
- // XXX Can we add any useful information which package it was and what the reason was?
+ // Handle errors
+ if (response->error) {
fprintf(stderr, "Failed to create build\n");
-
- return 0;
+ return 1;
}
- // XXX Here, we should actually send another API request that fetches the entire build object
- // or change the callback so that we receive the raw (parsed) JSON objects.
+ // Fetch the UUID
+ r = pakfire_json_get_string(response->data, "uuid", &uuid);
+ if (r < 0)
+ return r;
// Show status
printf("Created build %s\n", uuid);
// Create the build
r = pakfire_client_build(client, uuid, local_args->repo,
- local_args->arches, local_args->flags, build_callback, local_args);
+ local_args->arches, local_args->flags, build_callback, NULL);
if (r < 0) {
fprintf(stderr, "Failed to create build from %s: %s\n", path, strerror(-r));
// Build
-struct pakfire_client_build {
- // Client
- struct pakfire_client* client;
-
- // Callback
- pakfire_client_build_callback callback;
- void* data;
-};
-
-static int pakfire_client_build_create(struct pakfire_client_build** build,
- struct pakfire_client* client) {
- struct pakfire_client_build* self = NULL;
-
- // Allocate a new object
- self = calloc(1, sizeof(*self));
- if (!self)
- return -errno;
-
- // Store a reference to the client
- self->client = pakfire_client_ref(client);
-
- // Return the pointer
- *build = self;
-
- return 0;
-}
-
-static void pakfire_client_build_free(struct pakfire_client_build* self) {
- if (self->client)
- pakfire_client_unref(self->client);
- free(self);
-}
-
-static int pakfire_client_build_response(struct pakfire_xfer* xfer,
- const pakfire_xfer_response* response, void* data) {
- struct pakfire_client_build* build = data;
- const char* uuid = NULL;
- int r = 0;
-
- // Only process this if we have a callback
- if (build->callback) {
- // Extract the UUID from the response
- r = pakfire_json_get_string(response->data, "uuid", &uuid);
- if (r < 0)
- goto ERROR;
-
- // Call the callback
- r = build->callback(build->client, response->error, uuid, build->data);
- }
-
-ERROR:
- pakfire_client_build_free(build);
-
- return r;
-}
-
int pakfire_client_build(struct pakfire_client* self, const char* upload, const char* repo,
- const char** arches, int flags, pakfire_client_build_callback callback, void* data) {
- struct pakfire_client_build* build = NULL;
+ const char** arches, int flags, pakfire_xfer_response_callback callback, void* data) {
struct pakfire_xfer* xfer = NULL;
struct json_object* request = NULL;
int r;
- // Create a new build object
- r = pakfire_client_build_create(&build, self);
- if (r < 0)
- goto ERROR;
-
- // Store the callback
- build->callback = callback;
- build->data = data;
-
// Create a new xfer
r = pakfire_client_xfer_create(&xfer, self, "/api/v1/builds");
if (r < 0)
goto ERROR;
// Register the callback
- r = pakfire_xfer_set_response_callback(xfer, pakfire_client_build_response, build);
+ r = pakfire_xfer_set_response_callback(xfer, callback, data);
if (r < 0)
goto ERROR;
if (xfer)
pakfire_xfer_unref(xfer);
- // Remove the build on error
- if (r && build)
- pakfire_client_build_free(build);
-
return r;
}
PAKFIRE_CLIENT_DISABLE_TESTS = (1 << 0),
} pakfire_client_build_flags_t;
-typedef int (*pakfire_client_build_callback)
- (struct pakfire_client* client, int status, const char* uuid, void* data);
-
int pakfire_client_build(struct pakfire_client* client, const char* upload, const char* repo,
- const char** arches, int flags, pakfire_client_build_callback callback, void* data);
+ const char** arches, int flags, pakfire_xfer_response_callback callback, void* data);
// Uploads