From 69248038292e9ea1a4ee8912cdfc8700456753ad Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 13 Nov 2020 11:23:33 +0000 Subject: [PATCH] database: Move network filtering into a separate function Signed-off-by: Michael Tremer --- src/database.c | 56 +++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/database.c b/src/database.c index 7a3d1a7..72bc8eb 100644 --- a/src/database.c +++ b/src/database.c @@ -1129,6 +1129,31 @@ static int loc_database_enumerator_stack_push_node( return 0; } +static int loc_database_enumerator_filter_network( + struct loc_database_enumerator* enumerator, struct loc_network* network) { + // Skip if the family does not match + if (enumerator->family && loc_network_address_family(network) != enumerator->family) + return 1; + + // Skip if the country code does not match + if (*enumerator->country_code && + !loc_network_match_country_code(network, enumerator->country_code)) + return 1; + + // Skip if the ASN does not match + if (enumerator->asn && + !loc_network_match_asn(network, enumerator->asn)) + return 1; + + // Skip if flags do not match + if (enumerator->flags && + !loc_network_match_flag(network, enumerator->flags)) + return 1; + + // Do not filter + return 0; +} + static int __loc_database_enumerator_next_network( struct loc_database_enumerator* enumerator, struct loc_network** network, int filter) { // Return top element from the stack @@ -1195,36 +1220,7 @@ static int __loc_database_enumerator_next_network( return 0; // Check if we are interested in this network - - // Skip if the family does not match - if (enumerator->family && loc_network_address_family(*network) != enumerator->family) { - loc_network_unref(*network); - *network = NULL; - - continue; - } - - // Skip if the country code does not match - if (*enumerator->country_code && - !loc_network_match_country_code(*network, enumerator->country_code)) { - loc_network_unref(*network); - *network = NULL; - - continue; - } - - // Skip if the ASN does not match - if (enumerator->asn && - !loc_network_match_asn(*network, enumerator->asn)) { - loc_network_unref(*network); - *network = NULL; - - continue; - } - - // Skip if flags do not match - if (enumerator->flags && - !loc_network_match_flag(*network, enumerator->flags)) { + if (loc_database_enumerator_filter_network(enumerator, *network)) { loc_network_unref(*network); *network = NULL; -- 2.39.2