1 #define PERL_NO_GET_CONTEXT
10 #include <loc/libloc.h>
11 #include <loc/database.h>
12 #include <loc/network.h>
15 MODULE = Location PACKAGE = Location
22 struct loc_ctx* ctx = NULL;
24 int err = loc_new(&ctx);
28 FILE* f = fopen(file, "r");
30 croak("Could not open file for reading: %s\n", file);
33 struct loc_database *db = NULL;
34 err = loc_database_new(ctx, &db, f);
36 croak("Could not open database: %s\n", file);
44 get_country_code(db, address)
45 struct loc_database* db = NULL;
50 const char* country_code = NULL;
52 struct loc_network *network;
53 err = loc_database_lookup_from_string(db, address, &network);
55 croak("Could not look up for %s\n", address);
58 country_code = loc_network_get_country_code(network);
59 loc_network_unref(network);
62 croak("Could not get the country code\n");
65 RETVAL = strdup(country_code);
72 database_get_vendor(db)
73 struct loc_database* db = NULL;
76 const char* vendor = NULL;
78 vendor = loc_database_get_vendor(db);
80 croak("Could not retrieve vendor\n");
83 RETVAL = strdup(vendor);
89 struct loc_database* db = NULL;
92 loc_database_unref(db);