perl: Add get_continent_code()

Message ID 20191211103814.4130-1-stefan.schantl@ipfire.org
State Accepted
Commit cd022c5f35688e02e546fd64577b20312ce5f2ec
Headers
Series perl: Add get_continent_code() |

Commit Message

Stefan Schantl Dec. 11, 2019, 10:38 a.m. UTC
  This function allows to get the continent code by a given country code.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 src/perl/Location.xs | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
  

Patch

diff --git a/src/perl/Location.xs b/src/perl/Location.xs
index 02dff7d..5693744 100644
--- a/src/perl/Location.xs
+++ b/src/perl/Location.xs
@@ -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;