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);
42 // We can close the database file straight away
43 // because loc_database_new creates a copy of the file descriptor
49 croak("Could not read database: %s\n", file);
64 struct loc_database* db;
68 RETVAL = loc_database_get_vendor(db);
76 lookup_country_code(db, address)
77 struct loc_database* db;
82 struct loc_network *network;
83 int err = loc_database_lookup_from_string(db, address, &network);
85 croak("Could not look up for %s\n", address);
88 // Extract the country code
89 const char* country_code = loc_network_get_country_code(network);
90 loc_network_unref(network);
93 RETVAL = strdup(country_code);
102 struct loc_database* db;
106 loc_database_unref(db);