]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
python: Permit passing family to database enumerator
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Sep 2021 13:22:23 +0000 (13:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Sep 2021 13:22:23 +0000 (13:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/database.c

index 0aa03cce946e71c4b4a09ff7f875a6b5f5940c62..f8bd94deebd1fb1e35b264cc362167d207afa4eb 100644 (file)
@@ -209,7 +209,8 @@ static PyObject* new_database_enumerator(PyTypeObject* type, struct loc_database
        return (PyObject*)self;
 }
 
-static PyObject* Database_iterate_all(DatabaseObject* self, enum loc_database_enumerator_mode what, int flags) {
+static PyObject* Database_iterate_all(DatabaseObject* self,
+               enum loc_database_enumerator_mode what, int family, int flags) {
        struct loc_database_enumerator* enumerator;
 
        int r = loc_database_enumerator_new(&enumerator, self->db, what, flags);
@@ -218,6 +219,10 @@ static PyObject* Database_iterate_all(DatabaseObject* self, enum loc_database_en
                return NULL;
        }
 
+       // Set family
+       if (family)
+               loc_database_enumerator_set_family(enumerator, family);
+
        PyObject* obj = new_database_enumerator(&DatabaseEnumeratorType, enumerator);
        loc_database_enumerator_unref(enumerator);
 
@@ -225,7 +230,7 @@ static PyObject* Database_iterate_all(DatabaseObject* self, enum loc_database_en
 }
 
 static PyObject* Database_ases(DatabaseObject* self) {
-       return Database_iterate_all(self, LOC_DB_ENUMERATE_ASES, 0);
+       return Database_iterate_all(self, LOC_DB_ENUMERATE_ASES, AF_UNSPEC, 0);
 }
 
 static PyObject* Database_search_as(DatabaseObject* self, PyObject* args) {
@@ -252,11 +257,12 @@ static PyObject* Database_search_as(DatabaseObject* self, PyObject* args) {
 }
 
 static PyObject* Database_networks(DatabaseObject* self) {
-       return Database_iterate_all(self, LOC_DB_ENUMERATE_NETWORKS, 0);
+       return Database_iterate_all(self, LOC_DB_ENUMERATE_NETWORKS, AF_UNSPEC, 0);
 }
 
 static PyObject* Database_networks_flattened(DatabaseObject *self) {
-       return Database_iterate_all(self, LOC_DB_ENUMERATE_NETWORKS, LOC_DB_ENUMERATOR_FLAGS_FLATTEN);
+       return Database_iterate_all(self, LOC_DB_ENUMERATE_NETWORKS, AF_UNSPEC,
+               LOC_DB_ENUMERATOR_FLAGS_FLATTEN);
 }
 
 static PyObject* Database_search_networks(DatabaseObject* self, PyObject* args, PyObject* kwargs) {
@@ -417,7 +423,7 @@ static PyObject* Database_search_networks(DatabaseObject* self, PyObject* args,
 }
 
 static PyObject* Database_countries(DatabaseObject* self) {
-       return Database_iterate_all(self, LOC_DB_ENUMERATE_COUNTRIES, 0);
+       return Database_iterate_all(self, LOC_DB_ENUMERATE_COUNTRIES, AF_UNSPEC, 0);
 }
 
 static struct PyMethodDef Database_methods[] = {