#include <libloc/database.h>
#include "location.h"
+#include "as.h"
#include "database.h"
#include "network.h"
return 0;
}
+static int Database_get_as(lua_State* L) {
+ struct loc_as* as = NULL;
+ int r;
+
+ Database* self = luaL_checkdatabase(L, 1);
+
+ // Fetch number
+ uint32_t asn = luaL_checknumber(L, 2);
+
+ // Fetch the AS
+ r = loc_database_get_as(self->db, &as, asn);
+ if (r) {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ // Create a new AS object
+ r = create_as(L, as);
+ loc_as_unref(as);
+
+ return r;
+}
+
static int Database_lookup(lua_State* L) {
struct loc_network* network = NULL;
int r;
}
static const struct luaL_Reg database_functions[] = {
+ { "get_as", Database_get_as },
{ "open", Database_open },
{ "lookup", Database_lookup },
{ "__gc", Database_gc },
as = nil
end
+function test_fetch_as()
+ location = require("location")
+
+ -- Open the database
+ db = location.Database.open(ENV_TEST_DATABASE)
+
+ -- Fetch an AS
+ as = db:get_as(0)
+
+ -- This should not exist
+ luaunit.assertNil(as)
+
+ -- Fetch something that exists
+ as = db:get_as(204867)
+ luaunit.assertEquals(as:get_number(), 204867)
+ luaunit.assertEquals(as:get_name(), "Lightning Wire Labs GmbH")
+end
+
function test_country()
location = require("location")