return PyUnicode_FromFormat("<Database %s>", self->path);
}
+static PyObject* Database_verify(DatabaseObject* self, PyObject* args) {
+ PyObject* public_key = NULL;
+ FILE* f = NULL;
+
+ // Parse arguments
+ if (!PyArg_ParseTuple(args, "O", &public_key))
+ return NULL;
+
+ // Convert into FILE*
+ int fd = PyObject_AsFileDescriptor(public_key);
+ if (fd < 0)
+ return NULL;
+
+ // Re-open file descriptor
+ f = fdopen(fd, "r");
+ if (!f) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
+
+ int r = loc_database_verify(self->db, f);
+
+ if (r == 0)
+ Py_RETURN_TRUE;
+
+ Py_RETURN_FALSE;
+}
+
static PyObject* Database_get_description(DatabaseObject* self) {
const char* description = loc_database_get_description(self->db);
}
static PyObject* Database_search_networks(DatabaseObject* self, PyObject* args, PyObject* kwargs) {
- char* kwlist[] = { "country_code", "asn", NULL };
+ char* kwlist[] = { "country_code", "asn", "flags", "family", NULL };
const char* country_code = NULL;
unsigned int asn = 0;
+ int flags = 0;
+ int family = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &country_code, &asn))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siii", kwlist, &country_code, &asn, &flags, &family))
return NULL;
struct loc_database_enumerator* enumerator;
}
}
+ // Set the flags we are searching for
+ if (flags) {
+ r = loc_database_enumerator_set_flag(enumerator, flags);
+
+ if (r) {
+ PyErr_SetFromErrno(PyExc_SystemError);
+ return NULL;
+ }
+ }
+
+ // Set the family we are searching for
+ if (family) {
+ r = loc_database_enumerator_set_family(enumerator, family);
+
+ if (r) {
+ PyErr_SetFromErrno(PyExc_SystemError);
+ return NULL;
+ }
+ }
+
PyObject* obj = new_database_enumerator(&DatabaseEnumeratorType, enumerator);
loc_database_enumerator_unref(enumerator);
METH_VARARGS|METH_KEYWORDS,
NULL,
},
+ {
+ "verify",
+ (PyCFunction)Database_verify,
+ METH_VARARGS,
+ NULL,
+ },
{ NULL },
};
// Enumerate all networks
int r = loc_database_enumerator_next_network(self->enumerator, &network);
if (r) {
+ PyErr_SetFromErrno(PyExc_ValueError);
return NULL;
}
r = loc_database_enumerator_next_as(self->enumerator, &as);
if (r) {
+ PyErr_SetFromErrno(PyExc_ValueError);
return NULL;
}