#include <loc/libloc.h>
#include <loc/database.h>
+#include "locationmodule.h"
+#include "as.h"
#include "database.h"
static PyObject* Database_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
- // Create libloc context
- struct loc_ctx* ctx;
- int r = loc_new(&ctx);
- if (r)
- return NULL;
-
DatabaseObject* self = (DatabaseObject*)type->tp_alloc(type, 0);
- if (self) {
- self->ctx = ctx;
- }
return (PyObject*)self;
}
if (self->db)
loc_database_unref(self->db);
- if (self->ctx)
- loc_unref(self->ctx);
-
Py_TYPE(self)->tp_free((PyObject* )self);
}
return -1;
// Load the database
- int r = loc_database_new(self->ctx, &self->db, f);
+ int r = loc_database_new(loc_ctx, &self->db, f);
fclose(f);
// Return on any errors
return PyUnicode_FromString(vendor);
}
+static PyObject* Database_get_created_at(DatabaseObject* self) {
+ time_t created_at = loc_database_created_at(self->db);
+
+ return PyLong_FromLong(created_at);
+}
+
+static PyObject* Database_get_as(DatabaseObject* self, PyObject* args) {
+ struct loc_as* as = NULL;
+ uint32_t number = 0;
+
+ if (!PyArg_ParseTuple(args, "i", &number))
+ return NULL;
+
+ // Try to retrieve the AS
+ int r = loc_database_get_as(self->db, &as, number);
+ if (r)
+ return NULL;
+
+ // Create an AS object
+ if (as) {
+ PyObject* obj = new_as(&ASType, as);
+ loc_as_unref(as);
+
+ return obj;
+ }
+
+ // Nothing found
+ Py_RETURN_NONE;
+}
+
static struct PyMethodDef Database_methods[] = {
+ {
+ "get_as",
+ (PyCFunction)Database_get_as,
+ METH_VARARGS,
+ NULL,
+ },
{ NULL },
};
static struct PyGetSetDef Database_getsetters[] = {
+ {
+ "created_at",
+ (getter)Database_get_created_at,
+ NULL,
+ NULL,
+ NULL,
+ },
{
"description",
(getter)Database_get_description,
(getter)Database_get_vendor,
NULL,
NULL,
- NULL
+ NULL,
},
{ NULL },
};