STAILQ_HEAD(uploads, pakfire_client_upload) uploads;
};
+static int pakfire_client_store_read(struct pakfire_client* self) {
+ struct json_object* store = NULL;
+ char path[PATH_MAX];
+ char* error = NULL;
+ int r;
+
+ // Make the path
+ r = pakfire_path_format(path, "%s/pakfire-store.%s", PAKFIRE_TMP_DIR, self->principal);
+ if (r < 0)
+ goto ERROR;
+
+ // Read the store
+ r = pakfire_json_parse_from_file(&store, &error, path);
+ if (r < 0) {
+ switch (-r) {
+ // Skip if don't have any data to read
+ case ENOENT:
+ r = 0;
+ goto ERROR;
+
+ default:
+ if (error)
+ ERROR(self->ctx, "Failed to parse store: %s\n", error);
+ else
+ ERROR(self->ctx, "Failed to read store: %s\n", strerror(-r));
+ goto ERROR;
+ }
+ }
+
+ // XXX Parse the credentials
+
+ERROR:
+ if (store)
+ json_object_put(store);
+ if (error)
+ free(error);
+
+ return r;
+}
+
+static int pakfire_client_store_write(struct pakfire_client* self) {
+ struct json_object* store = NULL;
+ char path[PATH_MAX];
+ int r;
+
+ // Make the path
+ r = pakfire_path_format(path, "%s/pakfire-store.%s", PAKFIRE_TMP_DIR, self->principal);
+ if (r < 0)
+ goto ERROR;
+
+ // Create a new store object
+ r = pakfire_json_new_object(&store);
+ if (r < 0)
+ goto ERROR;
+
+ // Add the refresh token
+ r = pakfire_json_add_string(store, "refresh_token", self->auth.refresh_token);
+ if (r < 0)
+ goto ERROR;
+
+ // Store the data
+ r = pakfire_json_to_file(path, 0, 0, 0600, store);
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to write store at %s: %s\n", path, strerror(-r));
+ goto ERROR;
+ }
+
+ // Log action
+ DEBUG(self->ctx, "Stored credentials in %s\n", path);
+
+ERROR:
+ if (store)
+ json_object_put(store);
+
+ return r;
+}
+
static int pakfire_client_xfer_create(struct pakfire_xfer** xfer,
struct pakfire_client* self, const char* url, ...) __attribute__((format(printf, 3, 4)));
DEBUG(self->ctx, "Initializing client...\n");
+ // Read the store
+ r = pakfire_client_store_read(self);
+ if (r < 0)
+ return r;
+
// Request authentication
r = pakfire_client_auth_required(self);
if (r < 0)
static void pakfire_client_free(struct pakfire_client* self) {
struct pakfire_client_upload* upload = NULL;
+ // Store any credentials
+ pakfire_client_store_write(self);
+
if (self->auth.access_timer)
sd_event_source_unref(self->auth.access_timer);
if (self->auth.refresh_timer)