]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
database: Filter results coming from stack
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 13 Nov 2020 11:29:02 +0000 (11:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 13 Nov 2020 11:29:02 +0000 (11:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c

index 72bc8eb670e734a2d3640506fe6726009c4d83bd..0f3cdc2c0fe98ade6bba79d45d9e30af7341eace 100644 (file)
@@ -1157,9 +1157,23 @@ static int loc_database_enumerator_filter_network(
 static int __loc_database_enumerator_next_network(
                struct loc_database_enumerator* enumerator, struct loc_network** network, int filter) {
        // Return top element from the stack
-       *network = loc_network_list_pop(enumerator->stack);
-       if (*network)
+       while (1) {
+               *network = loc_network_list_pop(enumerator->stack);
+
+               // Stack is empty
+               if (!*network)
+                       break;
+
+               // Throw away any networks by filter
+               if (filter && loc_database_enumerator_filter_network(enumerator, *network)) {
+                       loc_network_unref(*network);
+                       *network = NULL;
+                       continue;
+               }
+
+               // Return result
                return 0;
+       }
 
        DEBUG(enumerator->ctx, "Called with a stack of %u nodes\n",
                enumerator->network_stack_depth);