]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/lua/location.c
lua: Export network flags
[people/ms/libloc.git] / src / lua / location.c
index e8441a489a7f0648c0c4eca564cce9a2228d1f86..6f2157cfc0bd9ef32f8d8fc89ad528501775ef8e 100644 (file)
        Lesser General Public License for more details.
 */
 
+#include <errno.h>
+#include <string.h>
+
 #include <lua.h>
 #include <lauxlib.h>
 #include <lualib.h>
 
+#include <libloc/libloc.h>
+#include <libloc/network.h>
+
 #include "location.h"
+#include "as.h"
+#include "country.h"
+#include "database.h"
+#include "network.h"
+
+struct loc_ctx* ctx = NULL;
 
 static int version(lua_State* L) {
        lua_pushstring(L, PACKAGE_VERSION);
@@ -31,7 +43,53 @@ static const struct luaL_Reg location_functions[] = {
 };
 
 int luaopen_location(lua_State* L) {
+       int r;
+
+       // Initialize the context
+       r = loc_new(&ctx);
+       if (r)
+               return luaL_error(L,
+                       "Could not initialize location context: %s\n", strerror(errno));
+
+       // Register functions
        luaL_newlib(L, location_functions);
 
+       // Register AS type
+       register_as(L);
+
+       lua_setfield(L, -2, "AS");
+
+       // Register Country type
+       register_country(L);
+
+       lua_setfield(L, -2, "Country");
+
+       // Register Database type
+       register_database(L);
+
+       lua_setfield(L, -2, "Database");
+
+       // Register Network type
+       register_network(L);
+
+       lua_setfield(L, -2, "Network");
+
+       // Set DATABASE_PATH
+       lua_pushstring(L, LIBLOC_DEFAULT_DATABASE_PATH);
+       lua_setfield(L, -2, "DATABASE_PATH");
+
+       // Add flags
+       lua_pushnumber(L, LOC_NETWORK_FLAG_ANONYMOUS_PROXY);
+       lua_setfield(L, -2, "NETWORK_FLAG_ANONYMOUS_PROXY");
+
+       lua_pushnumber(L, LOC_NETWORK_FLAG_SATELLITE_PROVIDER);
+       lua_setfield(L, -2, "NETWORK_FLAG_SATELLITE_PROVIDER");
+
+       lua_pushnumber(L, LOC_NETWORK_FLAG_ANYCAST);
+       lua_setfield(L, -2, "NETWORK_FLAG_ANYCAST");
+
+       lua_pushnumber(L, LOC_NETWORK_FLAG_DROP);
+       lua_setfield(L, -2, "NETWORK_FLAG_DROP");
+
        return 1;
 }