+static PyObject* Database_get_license(DatabaseObject* self) {
+ const char* license = loc_database_get_license(self->db);
+
+ return PyUnicode_FromString(license);
+}
+
+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);
+
+ // We got an AS
+ if (r == 0) {
+ PyObject* obj = new_as(&ASType, as);
+ loc_as_unref(as);
+
+ return obj;
+
+ // Nothing found
+ } else if (r == 1) {
+ Py_RETURN_NONE;
+ }
+
+ // Unexpected error
+ return NULL;
+}
+
+static PyObject* Database_lookup(DatabaseObject* self, PyObject* args) {
+ struct loc_network* network = NULL;
+ const char* address = NULL;
+
+ if (!PyArg_ParseTuple(args, "s", &address))
+ return NULL;
+
+ // Try to retrieve a matching network
+ int r = loc_database_lookup_from_string(self->db, address, &network);
+
+ // We got a network
+ if (r == 0) {
+ PyObject* obj = new_network(&NetworkType, network);
+ loc_network_unref(network);
+
+ return obj;
+
+ // Nothing found
+ } else if (r == 1) {
+ Py_RETURN_NONE;
+
+ // Invalid input
+ } else if (r == -EINVAL) {
+ PyErr_Format(PyExc_ValueError, "Invalid IP address: %s", address);
+ return NULL;
+ }
+
+ // Unexpected error
+ return NULL;
+}
+
+static PyObject* new_database_enumerator(PyTypeObject* type, struct loc_database_enumerator* enumerator) {
+ DatabaseEnumeratorObject* self = (DatabaseEnumeratorObject*)type->tp_alloc(type, 0);
+ if (self) {
+ self->enumerator = loc_database_enumerator_ref(enumerator);
+ }
+
+ return (PyObject*)self;
+}
+
+static PyObject* Database_search_as(DatabaseObject* self, PyObject* args) {
+ const char* string = NULL;
+
+ if (!PyArg_ParseTuple(args, "s", &string))
+ return NULL;
+
+ struct loc_database_enumerator* enumerator;
+
+ int r = loc_database_enumerator_new(&enumerator, self->db);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_SystemError);
+ return NULL;
+ }
+
+ // Search string we are searching for
+ loc_database_enumerator_set_string(enumerator, string);
+
+ PyObject* obj = new_database_enumerator(&DatabaseEnumeratorType, enumerator);
+ loc_database_enumerator_unref(enumerator);
+
+ return obj;
+}
+