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 // Initialise location context
25 int err = loc_new(&ctx);
27 croak("Could not initialize libloc context: %d\n", err);
29 // Open the database file for reading
30 FILE* f = fopen(file, "r");
34 croak("Could not open file for reading: %s: %s\n",
35 file, strerror(errno));
39 struct loc_database* db = NULL;
40 err = loc_database_new(ctx, &db, f);
44 croak("Could not read database: %s\n", file);
55 get_country_code(db, address)
56 struct loc_database* db = NULL;
61 const char* country_code = NULL;
64 struct loc_network *network;
65 err = loc_database_lookup_from_string(db, address, &network);
67 croak("Could not look up for %s\n", address);
70 country_code = loc_network_get_country_code(network);
71 loc_network_unref(network);
74 croak("Could not get the country code for %s\n", address);
77 RETVAL = strdup(country_code);
84 database_get_vendor(db)
85 struct loc_database* db = NULL;
88 const char* vendor = NULL;
91 vendor = loc_database_get_vendor(db);
93 croak("Could not retrieve vendor\n");
96 RETVAL = strdup(vendor);
102 struct loc_database* db = NULL;
106 loc_database_unref(db);