#define REFRESH_AGE_METADATA 2 * 3600
#define MAX_DESCRIPTION 4096
-#define MAX_KEY 4096
struct pakfire_repo_appdata {
// Reference Counter
time_t refresh;
// Key
- char key[MAX_KEY];
+ struct pakfire_key* key;
// Mirrorlist
struct pakfire_mirrorlist* mirrorlist;
return r;
}
-static int pakfire_repo_import_key(struct pakfire_repo* repo, const char* data) {
+static int pakfire_repo_import_key(struct pakfire_repo* self, const char* data) {
+ struct pakfire_key* key = NULL;
int r;
// Free any formerly imported keys (this should not happen)
- if (repo->key) {
- pakfire_key_unref(repo->key);
- repo->key = NULL;
+ if (self->key) {
+ pakfire_key_unref(self->key);
+ self->key = NULL;
}
// Import the key
- r = pakfire_key_import_from_string(&repo->key, repo->ctx, data, strlen(data));
+ r = pakfire_key_import_from_string(&key, self->ctx, data, strlen(data));
if (r < 0) {
- ERROR(repo->ctx, "Could not import key for repository '%s': %s\n",
- pakfire_repo_get_name(repo), strerror(-r));
+ ERROR(self->ctx, "Could not import key for repository '%s': %s\n",
+ pakfire_repo_get_name(self), strerror(-r));
goto ERROR;
}
// If the key could be successfully imported, we will store it in the appdata
- r = pakfire_string_set(repo->appdata->key, data);
- if (r < 0) {
- ERROR(repo->ctx, "Could not copy the key to appdata: %s\n", strerror(-r));
- goto ERROR;
- }
+ self->appdata->key = pakfire_key_ref(key);
ERROR:
+ if (key)
+ pakfire_key_unref(key);
+
return r;
}
if (appdata->mirrorlist)
pakfire_mirrorlist_unref(appdata->mirrorlist);
+ if (appdata->key)
+ pakfire_key_unref(appdata->key);
free(appdata);
}
pakfire_repo_free_appdata(self->appdata);
if (self->pakfire)
pakfire_unref(self->pakfire);
- if (self->key)
- pakfire_key_unref(self->key);
if (self->ctx)
pakfire_ctx_unref(self->ctx);
free(self);
return baseurl + strlen("file://");
}
-struct pakfire_key* pakfire_repo_get_key(struct pakfire_repo* repo) {
- int r;
-
- // It looks like no key has been imported
- if (!*repo->appdata->key)
- return NULL;
+struct pakfire_key* pakfire_repo_get_key(struct pakfire_repo* self) {
+ if (self->appdata->key)
+ return pakfire_key_ref(self->appdata->key);
- // Import the key
- if (!repo->key) {
- r = pakfire_key_import_from_string(&repo->key, repo->ctx,
- repo->appdata->key, strlen(repo->appdata->key));
- if (r)
- return NULL;
- }
-
- return pakfire_key_ref(repo->key);
+ return NULL;
}
const char* pakfire_repo_get_mirrorlist_url(struct pakfire_repo* repo) {