]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
database: Simplify network matching code
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Nov 2020 16:56:43 +0000 (16:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Nov 2020 16:56:43 +0000 (16:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c

index 51cb5cda2fca21e4863e577da342c177a7cc899a..1a354f63a353f3811adabb28119213f1e2d258ba 100644 (file)
@@ -1129,12 +1129,6 @@ static int loc_database_enumerator_stack_push_node(
        return 0;
 }
 
-static int loc_network_match_countries(struct loc_network* network, struct loc_country_list* countries) {
-       const char* country_code = loc_network_get_country_code(network);
-
-       return loc_country_list_contains_code(countries, country_code);
-}
-
 static int loc_network_match_asns(struct loc_network* network, struct loc_as_list* asns) {
        uint32_t asn = loc_network_get_asn(network);
 
@@ -1148,8 +1142,14 @@ static int loc_database_enumerator_filter_network(
                return 1;
 
        // Skip if the country code does not match
-       if (enumerator->countries && !loc_network_match_countries(network, enumerator->countries))
-               return 1;
+       if (enumerator->countries) {
+               if (!loc_country_list_empty(enumerator->countries)) {
+                       const char* country_code = loc_network_get_country_code(network);
+
+                       if (!loc_country_list_contains_code(enumerator->countries, country_code))
+                               return 1;
+               }
+       }
 
        // Skip if the ASN does not match
        if (enumerator->asns && !loc_network_match_asns(network, enumerator->asns))