]> git.ipfire.org Git - location/libloc.git/commitdiff
country: Make country codes beginning with X invalid
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Sep 2021 10:23:11 +0000 (10:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Sep 2021 10:23:11 +0000 (10:23 +0000)
According to ISO3166, they are only allowed for "private use".

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/country.c
src/test-country.c
src/test-network.c

index 3ea04cc45c2f32656dc53cca2ab52e2b9299858b..0f133198e4ec50f1adcdf46bf334f511ecc071ec 100644 (file)
@@ -209,6 +209,10 @@ LOC_EXPORT int loc_country_code_is_valid(const char* cc) {
                        return 0;
        }
 
+       // The code cannot begin with an X (those are reserved for private use)
+       if (*cc == 'X')
+               return 0;
+
        // Looks valid
        return 1;
 }
index fabdbc02698b1fc35d2a164b34417c9e2037cb32..3e231ced63188dc4f12a7f4e81b91d88fcc51ac8 100644 (file)
@@ -33,8 +33,8 @@ int main(int argc, char** argv) {
        int err;
 
        // Check some valid country codes
-       if (!loc_country_code_is_valid("XX")) {
-               fprintf(stderr, "Valid country code detected as invalid: %s\n", "XX");
+       if (!loc_country_code_is_valid("DE")) {
+               fprintf(stderr, "Valid country code detected as invalid: %s\n", "DE");
                exit(EXIT_FAILURE);
        }
 
@@ -101,7 +101,7 @@ int main(int argc, char** argv) {
                exit(EXIT_FAILURE);
 
        // Create a country
-       err = loc_writer_add_country(writer, &country, "XX");
+       err = loc_writer_add_country(writer, &country, "DE");
        if (err) {
                fprintf(stderr, "Could not create country\n");
                exit(EXIT_FAILURE);
index daa844f18c732708f9da251187d0481a56fc0ac6..2a577c6ae260b3af53956cf997ffb396d38fcdbd 100644 (file)
@@ -62,7 +62,7 @@ int main(int argc, char** argv) {
                exit(EXIT_FAILURE);
        }
 
-       err = loc_network_set_country_code(network1, "XX");
+       err = loc_network_set_country_code(network1, "DE");
        if (err) {
                fprintf(stderr, "Could not set country code\n");
                exit(EXIT_FAILURE);
@@ -113,7 +113,7 @@ int main(int argc, char** argv) {
                exit(EXIT_FAILURE);
        }
 
-       err = loc_network_set_country_code(network2, "XY");
+       err = loc_network_set_country_code(network2, "DE");
        if (err) {
                fprintf(stderr, "Could not set country code\n");
                exit(EXIT_FAILURE);