]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
perl: Add get_continent_code()
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 11 Dec 2019 10:38:14 +0000 (11:38 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 11 Dec 2019 14:34:24 +0000 (14:34 +0000)
This function allows to get the continent code by 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 02dff7d33aa26117df5a3070e2dbeba649102a37..5693744f77f6a8565a411c3d081fb0566e07cbca 100644 (file)
@@ -166,6 +166,31 @@ lookup_asn(db, address)
        OUTPUT:
                RETVAL
 
+#
+# Get functions
+#
+SV*
+get_continent_code(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 continent code for the given country code.
+                       const char* continent_code =  loc_country_get_continent_code(country);
+                       RETVAL = newSVpv(continent_code, strlen(continent_code));
+
+                       loc_country_unref(country);
+               }
+
+       OUTPUT:
+               RETVAL
+
 void
 DESTROY(db)
        struct loc_database* db;