]> git.ipfire.org Git - location/libloc.git/blobdiff - src/database.c
libloc: Add function to set country code to database enumerator
[location/libloc.git] / src / database.c
index fe5e6dc6e0ebcb86a56b5629dc982ff5bc879ff1..e8ec9b7ec4843669d215eb084e135b4358d3012c 100644 (file)
@@ -69,6 +69,7 @@ struct loc_database_enumerator {
 
        // Search string
        char* string;
+       char country_code[3];
 
        // Index of the AS we are looking at
        unsigned int as_index;
@@ -610,6 +611,24 @@ LOC_EXPORT int loc_database_enumerator_set_string(struct loc_database_enumerator
        return 0;
 }
 
+LOC_EXPORT int loc_database_enumerator_set_country_code(struct loc_database_enumerator* enumerator, const char* country_code) {
+       // Set empty country code
+       if (!country_code || !*country_code) {
+               *enumerator->country_code = '\0';
+               return 0;
+       }
+
+       // Country codes must be two characters
+       if (strlen(country_code) != 2)
+               return -EINVAL;
+
+       for (unsigned int i = 0; i < 3; i++) {
+               enumerator->country_code[i] = country_code[i];
+       }
+
+       return 0;
+}
+
 LOC_EXPORT struct loc_as* loc_database_enumerator_next_as(struct loc_database_enumerator* enumerator) {
        struct loc_database* db = enumerator->db;
        struct loc_as* as;