]> git.ipfire.org Git - location/libloc.git/commitdiff
perl: Add get_country_name() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 10 Sep 2020 15:57:44 +0000 (17:57 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 10 Sep 2020 16:12:00 +0000 (16:12 +0000)
This function can be used to get the stored name for a given country
code.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/perl/Location.xs

index 1cb2e21bbfbcaa3f9b53901c6d2aec314c123758..dcf3f0d79524801083aafe5497091f4abfd2aec6 100644 (file)
@@ -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;