#include <json.h>
#include <pakfire/client.h>
+#include <pakfire/json.h>
+#include "api.h"
#include "command.h"
#include "dump.h"
#include "pakfire.h"
return 0;
}
-static int ready_callback(pakfire_client* client, void* data) {
- const struct cli_local_args* local_args = data;
+static int response_callback(struct pakfire_xfer* xfer,
+ const pakfire_xfer_response* response, void* data) {
+ struct cli_local_args* local_args = data;
+ json_object* repo = NULL;
+ const char* name = NULL;
+ int64_t priority = 0;
+ int r;
+
+ // Handle errors
+ r = cli_api_error(response, "Failed to fetch repositories for %s", local_args->distro);
+ if (r < 0)
+ return 0;
+
+ // Show a header
+ printf("%-12s %-12s\n", "Name", "Priority");
+
+ // Loop through all repos
+ for (size_t i = 0; i < json_object_array_length(response->data); i++) {
+ repo = json_object_array_get_idx(response->data, i);
+ if (!repo)
+ break;
+
+ // Fetch the name
+ r = pakfire_json_get_string(repo, "name", &name);
+ if (r < 0)
+ break;
- // XXX Needs a callback
+ // Fetch the priority
+ r = pakfire_json_get_int64(repo, "priority", &priority);
+ if (r < 0)
+ break;
+
+ printf("%-12s %-12ld\n", name, priority);
+ }
+
+ return r;
+}
+
+static int ready_callback(pakfire_client* client, void* data) {
+ struct cli_local_args* local_args = data;
// List repos
- return pakfire_client_list_repos(client, local_args->distro);
+ return pakfire_client_list_repos(client,
+ local_args->distro, response_callback, local_args);
}
int cli_repo_list(void* data, int argc, char* argv[]) {
// Repositories
-int pakfire_client_list_repos(pakfire_client* self, const char* distro) {
+int pakfire_client_list_repos(pakfire_client* self, const char* distro,
+ pakfire_xfer_response_callback callback, void* data) {
pakfire_xfer* xfer = NULL;
int r;
return -EINVAL;
// Create a new xfer
- r = pakfire_client_xfer_create(&xfer, self, "/api/v1/repos/%s", distro);
+ r = pakfire_client_xfer_create(&xfer, self, "/api/v1/distros/%s/repos", distro);
if (r < 0)
goto ERROR;
if (r < 0)
goto ERROR;
- // XXX Needs a callback
+ // Register the callback
+ r = pakfire_xfer_set_response_callback(xfer, callback, data);
+ if (r < 0)
+ goto ERROR;
// Enqueue the transfer
r = pakfire_httpclient_enqueue(self->httpclient, xfer);
// Repositories
-int pakfire_client_list_repos(pakfire_client* client, const char* distro);
+int pakfire_client_list_repos(pakfire_client* client, const char* distro,
+ pakfire_xfer_response_callback callback, void* data);
int pakfire_client_get_repo(pakfire_client* client,
const char* distro, const char* name);
int pakfire_client_create_repo(pakfire_client* client,