#include <pakfire/util.h>
#include "key.h"
+#include "pakfire.h"
-static PyObject* Key_new_core(PyTypeObject* type, PoolObject* pool, PakfireKey key) {
+static PyObject* Key_new_core(PyTypeObject* type, PakfireObject* pakfire, PakfireKey key) {
KeyObject* self = (KeyObject *)type->tp_alloc(type, 0);
if (self) {
- self->pool = pool;
+ self->pakfire = pakfire;
self->key = key;
}
return (PyObject *)self;
}
-PyObject* new_key(PoolObject* pool, PakfireKey key) {
- return Key_new_core(&KeyType, pool, key);
+PyObject* new_key(PakfireObject* pakfire, PakfireKey key) {
+ return Key_new_core(&KeyType, pakfire, key);
}
static PyObject* Key_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
if (self->key)
pakfire_key_free(self->key);
+ if (self->pakfire)
+ Py_DECREF(self->pakfire);
+
Py_TYPE(self)->tp_free((PyObject *)self);
}
static int Key_init(KeyObject* self, PyObject* args, PyObject* kwds) {
- PyObject* pool;
+ PyObject* pakfire;
const char* fingerprint = NULL;
- if (!PyArg_ParseTuple(args, "O!s", &PoolType, &pool, &fingerprint))
+ if (!PyArg_ParseTuple(args, "O!s", &PakfireType, &pakfire, &fingerprint))
return -1;
- self->pool = (PoolObject *)pool;
- Py_INCREF(self->pool);
+ self->pakfire = (PakfireObject *)pakfire;
+ Py_INCREF(self->pakfire);
- self->key = pakfire_key_get(self->pool->pool, fingerprint);
+ self->key = pakfire_key_get(self->pakfire->pakfire, fingerprint);
if (!self->key)
return -1;
#include <pakfire/key.h>
-#include "pool.h"
+#include "pakfire.h"
typedef struct {
PyObject_HEAD
- PoolObject* pool;
+ PakfireObject* pakfire;
PakfireKey key;
} KeyObject;
extern PyTypeObject KeyType;
-PyObject* new_key(PoolObject* pool, PakfireKey key);
+PyObject* new_key(PakfireObject* pakfire, PakfireKey key);
#endif /* PYTHON_PAKFIRE_KEY_H */
#include <Python.h>
#include <pakfire/pakfire.h>
+#include <pakfire/key.h>
+#include "key.h"
#include "pakfire.h"
static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
return PyUnicode_FromString(arch);
}
+static PyObject* Pakfire_get_keys(PakfireObject* self) {
+ PyObject* list = PyList_New(0);
+
+ PakfireKey* keys = pakfire_key_list(self->pakfire);
+ while (keys && *keys) {
+ PakfireKey key = *keys++;
+
+ PyObject* object = new_key(self, key);
+ PyList_Append(list, object);
+ Py_DECREF(object);
+
+ pakfire_key_free(key);
+ }
+
+ return list;
+}
+
+static PyObject* Pakfire_get_key(PakfireObject* self, PyObject* args) {
+ const char* pattern = NULL;
+
+ if (!PyArg_ParseTuple(args, "s", &pattern))
+ return NULL;
+
+ PakfireKey key = pakfire_key_get(self->pakfire, pattern);
+ if (!key)
+ Py_RETURN_NONE;
+
+ return new_key(self, key);
+}
+
+static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args) {
+ const char* userid = NULL;
+
+ if (!PyArg_ParseTuple(args, "s", &userid))
+ return NULL;
+
+ PakfireKey key = pakfire_key_generate(self->pakfire, userid);
+ assert(key);
+
+ return new_key(self, key);
+}
+
static struct PyMethodDef Pakfire_methods[] = {
+ {
+ "generate_key",
+ (PyCFunction)Pakfire_generate_key,
+ METH_VARARGS,
+ NULL
+ },
+ {
+ "get_key",
+ (PyCFunction)Pakfire_get_key,
+ METH_VARARGS,
+ NULL
+ },
{ NULL },
};
NULL,
NULL
},
+ {
+ "keys",
+ (getter)Pakfire_get_keys,
+ NULL,
+ NULL,
+ NULL
+ },
{
"path",
(getter)Pakfire_get_path,
#include <solv/solver.h>
#include <pakfire/errno.h>
-#include <pakfire/key.h>
#include <pakfire/pool.h>
#include <pakfire/repo.h>
#include "constants.h"
-#include "key.h"
#include "pool.h"
#include "relation.h"
#include "repo.h"
return PyList_FromPackageList(self, list);
}
-static PyObject* Pool_get_keys(PoolObject* self) {
- PyObject* list = PyList_New(0);
-
- PakfireKey* keys = pakfire_key_list(self->pool);
- while (keys && *keys) {
- PakfireKey key = *keys++;
-
- PyObject* object = new_key(self, key);
- PyList_Append(list, object);
- Py_DECREF(object);
-
- pakfire_key_free(key);
- }
-
- return list;
-}
-
-static PyObject* Pool_get_key(PoolObject* self, PyObject* args) {
- const char* pattern = NULL;
-
- if (!PyArg_ParseTuple(args, "s", &pattern))
- return NULL;
-
- PakfireKey key = pakfire_key_get(self->pool, pattern);
- if (!key)
- Py_RETURN_NONE;
-
- return new_key(self, key);
-}
-
-static PyObject* Pool_generate_key(PoolObject* self, PyObject* args) {
- const char* userid = NULL;
-
- if (!PyArg_ParseTuple(args, "s", &userid))
- return NULL;
-
- PakfireKey key = pakfire_key_generate(self->pool, userid);
- assert(key);
-
- return new_key(self, key);
-}
-
static struct PyMethodDef Pool_methods[] = {
- {
- "generate_key",
- (PyCFunction)Pool_generate_key,
- METH_VARARGS,
- NULL
- },
- {
- "get_key",
- (PyCFunction)Pool_get_key,
- METH_VARARGS,
- NULL
- },
{
"search",
(PyCFunction)Pool_search,
NULL,
NULL
},
- {
- "keys",
- (getter)Pool_get_keys,
- NULL,
- NULL,
- NULL
- },
{ NULL }
};
PAKFIRE_KEY_EXPORT_MODE_SECRET,
} pakfire_key_export_mode_t;
-PakfireKey* pakfire_key_list(PakfirePool pool);
+PakfireKey* pakfire_key_list(Pakfire pakfire);
-PakfireKey pakfire_key_create(PakfirePool pool, gpgme_key_t gpgkey);
+PakfireKey pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey);
void pakfire_key_free(PakfireKey key);
-PakfireKey pakfire_key_get(PakfirePool pool, const char* fingerprint);
+PakfireKey pakfire_key_get(Pakfire pakfire, const char* fingerprint);
const char* pakfire_key_get_fingerprint(PakfireKey key);
-PakfireKey pakfire_key_generate(PakfirePool pool, const char* userid);
+PakfireKey pakfire_key_generate(Pakfire pakfire, const char* userid);
char* pakfire_key_export(PakfireKey key, pakfire_key_export_mode_t mode);
#ifdef PAKFIRE_PRIVATE
struct _PakfireKey {
- PakfirePool pool;
+ Pakfire pakfire;
gpgme_key_t gpgkey;
int nrefs;
};
#include <gpgme.h>
#include <pakfire/key.h>
-#include <pakfire/pool.h>
+#include <pakfire/pakfire.h>
#include <pakfire/util.h>
-static gpgme_ctx_t pakfire_get_gpgctx(PakfirePool pool) {
+static gpgme_ctx_t pakfire_get_gpgctx(Pakfire pakfire) {
static int gpg_initialized = 0;
gpgme_error_t error;
const char* error_string;
goto FAIL;
// Use GPG
- error = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP,
- NULL, "/etc/pakfire/gnupg");
+ char* home = pakfire_path_join(pakfire->path, "/etc/pakfire/gnupg");
+ error = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, NULL, home);
+ pakfire_free(home);
if (gpg_err_code(error) != GPG_ERR_NO_ERROR)
goto FAIL;
return NULL;
}
-PakfireKey* pakfire_key_list(PakfirePool pool) {
- gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pool);
+PakfireKey* pakfire_key_list(Pakfire pakfire) {
+ gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pakfire);
assert(gpgctx);
PakfireKey* first = pakfire_calloc(1, sizeof(PakfireKey));
break;
// Add key to the list
- *list++ = pakfire_key_create(pool, gpgkey);
+ *list++ = pakfire_key_create(pakfire, gpgkey);
gpgme_key_release(gpgkey);
}
return first;
}
-PakfireKey pakfire_key_create(PakfirePool pool, gpgme_key_t gpgkey) {
+PakfireKey pakfire_key_create(Pakfire pakfire, gpgme_key_t gpgkey) {
PakfireKey key = pakfire_calloc(1, sizeof(*key));
if (key) {
- key->pool = pool;
+ key->pakfire = pakfire_ref(pakfire);
key->gpgkey = gpgkey;
gpgme_key_ref(key->gpgkey);
}
void pakfire_key_free(PakfireKey key) {
+ pakfire_unref(key->pakfire);
gpgme_key_unref(key->gpgkey);
pakfire_free(key);
}
-PakfireKey pakfire_key_get(PakfirePool pool, const char* fingerprint) {
- gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pool);
+PakfireKey pakfire_key_get(Pakfire pakfire, const char* fingerprint) {
+ gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pakfire);
assert(gpgctx);
gpgme_key_t gpgkey = NULL;
if (error != GPG_ERR_NO_ERROR)
return NULL;
- PakfireKey key = pakfire_key_create(pool, gpgkey);
+ PakfireKey key = pakfire_key_create(pakfire, gpgkey);
gpgme_key_unref(gpgkey);
gpgme_release(gpgctx);
return key->gpgkey->fpr;
}
-PakfireKey pakfire_key_generate(PakfirePool pool, const char* userid) {
- gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pool);
+PakfireKey pakfire_key_generate(Pakfire pakfire, const char* userid) {
+ gpgme_ctx_t gpgctx = pakfire_get_gpgctx(pakfire);
assert(gpgctx);
unsigned int flags = 0;
gpgme_release(gpgctx);
// Retrieve the key by its fingerprint
- return pakfire_key_get(pool, result->fpr);
+ return pakfire_key_get(pakfire, result->fpr);
}
char* pakfire_key_export(PakfireKey key, pakfire_key_export_mode_t mode) {
- gpgme_ctx_t gpgctx = pakfire_get_gpgctx(key->pool);
+ gpgme_ctx_t gpgctx = pakfire_get_gpgctx(key->pakfire);
assert(gpgctx);
gpgme_export_mode_t gpgmode = 0;
print(_("Generating the key may take a moment..."))
print()
- key = p.pool.generate_key("%s <%s>" % (ns.realname.pop(), ns.email.pop()))
+ key = p.generate_key("%s <%s>" % (ns.realname.pop(), ns.email.pop()))
def handle_list(self, ns):
p = self.pakfire(ns)
- for key in p.pool.keys:
+ for key in p.keys:
print(key)
def handle_export(self, ns):
p = self.pakfire(ns)
for fingerprint in ns.fingerprint:
- key = p.pool.get_key(fingerprint)
+ key = p.get_key(fingerprint)
if not key:
print(_("Could not find key with fingerprint %s") % fingerprint)
continue