Commit 35bb3a32 authored by Michael Tremer's avatar Michael Tremer

libloc: Add function to set country code to database enumerator

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 2538ed9a
......@@ -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;
......
......@@ -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;
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment