Commit 6aa97cac authored by Stefan Schantl's avatar Stefan Schantl Committed by Michael Tremer

perl: Fix lookup if given address is invalid or not in DB.

In this case now undef will be returned.
Signed-off-by: default avatarStefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent f852b157
...@@ -92,27 +92,23 @@ get_license(db) ...@@ -92,27 +92,23 @@ get_license(db)
# #
# Lookup functions # Lookup functions
# #
char* SV*
lookup_country_code(db, address) lookup_country_code(db, address)
struct loc_database* db; struct loc_database* db;
char* address; char* address;
CODE: CODE:
RETVAL = &PL_sv_undef;
// Lookup network // Lookup network
struct loc_network *network; struct loc_network *network;
int err = loc_database_lookup_from_string(db, address, &network); int err = loc_database_lookup_from_string(db, address, &network);
if (err) { if (!err) {
croak("Could not look up for %s\n", address); // Extract the country code
} const char* country_code = loc_network_get_country_code(network);
RETVAL = newSVpv(country_code, strlen(country_code));
// Extract the country code
const char* country_code = loc_network_get_country_code(network);
loc_network_unref(network);
if (country_code) { loc_network_unref(network);
RETVAL = strdup(country_code);
} else {
RETVAL = NULL;
} }
OUTPUT: OUTPUT:
RETVAL RETVAL
......
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