]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
libloc: Add function to set country code to database enumerator
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Oct 2019 14:07:13 +0000 (14:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Oct 2019 14:07:13 +0000 (14:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/libloc.sym
src/loc/database.h

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;
index 42e89e5faacb715474237fe9aaa381c86da320a6..7faa9c09260d8c3d9121f07ac1128063cc110539 100644 (file)
@@ -54,6 +54,7 @@ global:
        loc_database_enumerator_new;
        loc_database_enumerator_next_as;
        loc_database_enumerator_ref;
+       loc_database_enumerator_set_country_code;
        loc_database_enumerator_set_string;
        loc_database_enumerator_unref;
 
index 37810eb9d31396066d823d315839418efc634360..7cb80204c4acb6189e0c7b8f94590c036a996324 100644 (file)
@@ -49,6 +49,7 @@ struct loc_database_enumerator* loc_database_enumerator_ref(struct loc_database_
 struct loc_database_enumerator* loc_database_enumerator_unref(struct loc_database_enumerator* enumerator);
 
 int loc_database_enumerator_set_string(struct loc_database_enumerator* enumerator, const char* string);
+int loc_database_enumerator_set_country_code(struct loc_database_enumerator* enumerator, const char* country_code);
 struct loc_as* loc_database_enumerator_next_as(struct loc_database_enumerator* enumerator);
 
 #endif