This function can be used to get the stored name for a given country code.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/perl/Location.xs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/src/perl/Location.xs b/src/perl/Location.xs index 1cb2e21..dcf3f0d 100644 --- a/src/perl/Location.xs +++ b/src/perl/Location.xs @@ -243,6 +243,28 @@ lookup_asn(db, address) # # Get functions # +SV* +get_country_name(db, ccode) + struct loc_database* db; + char* ccode; + + CODE: + RETVAL = &PL_sv_undef; + + // Lookup country code + struct loc_country *country; + int err = loc_database_get_country(db, &country, ccode); + if(!err) { + // Extract the name for the given country code. + const char* country_name = loc_country_get_name(country); + RETVAL = newSVpv(country_name, strlen(country_name)); + + loc_country_unref(country); + } + + OUTPUT: + RETVAL + SV* get_continent_code(db, ccode) struct loc_database* db;
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- examples/python/create-database.py | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/examples/python/create-database.py b/examples/python/create-database.py index bf8838b..04b2dc3 100644 --- a/examples/python/create-database.py +++ b/examples/python/create-database.py @@ -22,6 +22,8 @@ with open(private_key_path, "r") as pkey:
# Add a country c = w.add_country("DE") + c.continent_code = "EU" + c.name = "Germany"
# Add an AS a = w.add_as(204867)
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/perl/t/Location.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/perl/t/Location.t b/src/perl/t/Location.t index a82bbb1..c922a94 100644 --- a/src/perl/t/Location.t +++ b/src/perl/t/Location.t @@ -12,7 +12,7 @@ use warnings; my $testdb = $ENV{'database'}; my $keyfile = $ENV{'keyfile'};
-use Test::More tests => 10; +use Test::More tests => 11; BEGIN { use_ok('Location') };
######################### @@ -65,3 +65,6 @@ ok(@locations != 0, "Test 11 - Get database countries.");
my $network_flag_anycast = &Location::lookup_network_has_flag($db, $address, "LOC_NETWORK_FLAG_ANYCAST"); ok($network_flag_anycast, "Network has Anycast flag."); + +my $country_name = &Location::get_country_name($db, "DE"); +ok($country_name eq "Germany", "Test 13 - Got country name: $country_name");
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- src/perl/t/Location.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/perl/t/Location.t b/src/perl/t/Location.t index c922a94..e256aec 100644 --- a/src/perl/t/Location.t +++ b/src/perl/t/Location.t @@ -12,7 +12,7 @@ use warnings; my $testdb = $ENV{'database'}; my $keyfile = $ENV{'keyfile'};
-use Test::More tests => 11; +use Test::More tests => 12; BEGIN { use_ok('Location') };
######################### @@ -68,3 +68,6 @@ ok($network_flag_anycast, "Network has Anycast flag.");
my $country_name = &Location::get_country_name($db, "DE"); ok($country_name eq "Germany", "Test 13 - Got country name: $country_name"); + +my $continent_code = &Location::get_continent_code($db, "DE"); +ok($continent_code eq "EU", "Test 14 - Got continent code $continent_code for country code 'DE'");