From 119bcf6cd0f8be7ddc4ca0e3fa8d51fbcda35f14 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Tue, 16 Jun 2015 13:07:53 +0200 Subject: [PATCH] make luabackend compile --- modules/luabackend/lua_functions.cc | 147 +++++++++++++++------------- modules/luabackend/luabackend.hh | 47 ++++----- modules/luabackend/minimal.cc | 92 ++++++++--------- 3 files changed, 151 insertions(+), 135 deletions(-) diff --git a/modules/luabackend/lua_functions.cc b/modules/luabackend/lua_functions.cc index 1a8483155..7d627a719 100644 --- a/modules/luabackend/lua_functions.cc +++ b/modules/luabackend/lua_functions.cc @@ -2,7 +2,7 @@ Copyright (C) 2011 Fredrik Danerklint This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published + it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation This program is distributed in the hope that it will be useful, @@ -40,7 +40,7 @@ const luaL_Reg lualibs[] = { {LUA_MATHLIBNAME, luaopen_math}, {LUA_DBLIBNAME, luaopen_debug}, // {LUA_COLIBNAME, luaopen_coroutine}, -#ifdef USE_LUAJIT +#ifdef USE_LUAJIT {"bit", luaopen_bit}, {"jit", luaopen_jit}, #endif @@ -48,17 +48,17 @@ const luaL_Reg lualibs[] = { }; int my_lua_panic (lua_State *lua) { - lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); + lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); LUABackend* lb = (LUABackend*)lua_touserdata(lua, -1); - + assert(lua == lb->lua); - + stringstream e; - + e << lb->backend_name << "LUA PANIC! '" << lua_tostring(lua,-1) << "'" << endl; - + throw LUAException (e.str()); - + return 0; } @@ -66,15 +66,15 @@ int l_arg_get (lua_State *lua) { int i = lua_gettop(lua); if (i < 1) return 0; - - lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); + + lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); LUABackend* lb = (LUABackend*)lua_touserdata(lua, -1); string a = lua_tostring(lua, 1); if (::arg().isEmpty(a)) lua_pushnil(lua); - else + else lua_pushstring(lua, lb->my_getArg(a).c_str()); return 1; @@ -84,43 +84,43 @@ int l_arg_mustdo (lua_State *lua) { int i = lua_gettop(lua); if (i < 1) return 0; - - lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); + + lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); LUABackend* lb = (LUABackend*)lua_touserdata(lua, -1); - + string a = lua_tostring(lua, 1); if (::arg().isEmpty(a)) lua_pushnil(lua); - else + else lua_pushboolean(lua, lb->my_mustDo(a)); return 1; } int l_dnspacket (lua_State *lua) { - lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); + lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); LUABackend* lb = (LUABackend*)lua_touserdata(lua, -1); if (lb->dnspacket == NULL) { lua_pushnil(lua); - + return 1; } lua_pushstring(lua, lb->dnspacket->getRemote().c_str()); lua_pushnumber(lua, lb->dnspacket->getRemotePort()); lua_pushstring(lua, lb->dnspacket->getLocal().c_str()); - + return 3; } int l_logger (lua_State *lua) { // assert(lua == lb->lua); - - lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); + + lua_getfield(lua, LUA_REGISTRYINDEX, "__LUABACKEND"); LUABackend* lb = (LUABackend*)lua_touserdata(lua, -1); - + int i = lua_gettop(lua); if (i < 1) return 0; @@ -131,22 +131,22 @@ int l_logger (lua_State *lua) { const char *ss; log_level = lua_tointeger(lua, 1); - + string space = ""; - + for(j=2; j<=i; j++) { ss = lua_tostring(lua, j); s << space << ss; space = " "; } - + L.log(lb->backend_name + s.str(), (Logger::Urgency) log_level); - + return 0; } void register_lua_functions(lua_State *lua) { - lua_gc(lua, LUA_GCSTOP, 0); // stop collector during initialization + lua_gc(lua, LUA_GCSTOP, 0); // stop collector during initialization const luaL_Reg *lib = lualibs; for (; lib->func; lib++) { @@ -180,16 +180,16 @@ void register_lua_functions(lua_State *lua) { lua_pushinteger(lua, Logger::Info); lua_setglobal(lua, "log_info"); - + lua_pushinteger(lua, Logger::Debug); lua_setglobal(lua, "log_debug"); lua_pushinteger(lua, Logger::None); lua_setglobal(lua, "log_none"); - + lua_pushcfunction(lua, l_dnspacket); lua_setglobal(lua, "dnspacket"); - + lua_pushcfunction(lua, l_logger); lua_setglobal(lua, "logger"); @@ -198,7 +198,7 @@ void register_lua_functions(lua_State *lua) { lua_pushcfunction(lua, l_arg_mustdo); lua_setglobal(lua, "mustdo"); - + lua_newtable(lua); for(vector::const_iterator iter = QType::names.begin(); iter != QType::names.end(); ++iter) { lua_pushnumber(lua, iter->second); @@ -210,114 +210,129 @@ void register_lua_functions(lua_State *lua) { } bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, string& value) { - lua_pushstring(lua, key.c_str()); - lua_gettable(lua, -2); + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = lua_tostring(lua, -1); ret = true; } - + + lua_pop(lua, 1); + + return ret; +} + +bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, DNSName& value) { + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); + + bool ret = false; + + if(!lua_isnil(lua, -1)) { + value = DNSName(lua_tostring(lua, -1)); + ret = true; + } + lua_pop(lua, 1); - + return ret; } bool LUABackend::getValueFromTable(lua_State *lua, uint32_t key, string& value) { - lua_pushnumber(lua, key); - lua_gettable(lua, -2); + lua_pushnumber(lua, key); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = lua_tostring(lua, -1); ret = true; } - + lua_pop(lua, 1); - + return ret; } bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, time_t& value) { - lua_pushstring(lua, key.c_str()); - lua_gettable(lua, -2); + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = (time_t)lua_tonumber(lua, -1); ret = true; } - + lua_pop(lua, 1); - + return ret; } bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, uint32_t& value) { - lua_pushstring(lua, key.c_str()); - lua_gettable(lua, -2); + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = (uint32_t)lua_tonumber(lua, -1); ret = true; } - + lua_pop(lua, 1); - + return ret; } bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, uint16_t& value) { - lua_pushstring(lua, key.c_str()); - lua_gettable(lua, -2); + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = (uint16_t)lua_tonumber(lua, -1); ret = true; } - + lua_pop(lua, 1); - + return ret; } bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, int& value) { - lua_pushstring(lua, key.c_str()); - lua_gettable(lua, -2); + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = (int)lua_tonumber(lua, -1); ret = true; } - + lua_pop(lua, 1); - + return ret; } bool LUABackend::getValueFromTable(lua_State *lua, const std::string& key, bool& value) { - lua_pushstring(lua, key.c_str()); - lua_gettable(lua, -2); + lua_pushstring(lua, key.c_str()); + lua_gettable(lua, -2); bool ret = false; - + if(!lua_isnil(lua, -1)) { value = lua_toboolean(lua, -1); ret = true; } - + lua_pop(lua, 1); - + return ret; } - diff --git a/modules/luabackend/luabackend.hh b/modules/luabackend/luabackend.hh index 8054ff374..03d6222e1 100644 --- a/modules/luabackend/luabackend.hh +++ b/modules/luabackend/luabackend.hh @@ -32,8 +32,8 @@ public: LUABackend(const string &suffix=""); ~LUABackend(); - bool list(const string &target, int domain_id, bool include_disabled=false); - void lookup(const QType &qtype, const string &qname, DNSPacket *p, int domain_id); + bool list(const DNSName &target, int domain_id, bool include_disabled=false); + void lookup(const QType &qtype, const DNSName &qname, DNSPacket *p, int domain_id); bool get(DNSResourceRecord &rr); //! fills the soadata struct with the SOA details. Returns false if there is no SOA. bool getSOA(const string &name, SOAData &soadata, DNSPacket *p=0); @@ -46,7 +46,7 @@ public: // SLAVE BACKEND - + bool getDomainInfo(const string &domain, DomainInfo &di); bool isMaster(const string &name, const string &ip); void getUnfreshSlaveInfos(vector* domains); @@ -81,12 +81,12 @@ public: bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after); bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const std::string& qname, const std::string& ordername, bool auth); bool updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth); - - + + // OTHER void reload(); void rediscover(string* status=0); - + string backend_name; lua_State *lua; @@ -100,15 +100,15 @@ private: pthread_t backend_pid; unsigned int backend_count; - + int f_lua_exec_error; - + //minimal functions.... int f_lua_list; int f_lua_lookup; int f_lua_get; int f_lua_getsoa; - + //master functions.... int f_lua_getupdatedmasters; int f_lua_setnotifed; @@ -153,6 +153,7 @@ private: // FUNCTIONS TO THIS BACKEND bool getValueFromTable(lua_State *lua, const std::string& key, string& value); + bool getValueFromTable(lua_State *lua, const std::string& key, DNSName& value); bool getValueFromTable(lua_State *lua, uint32_t key, string& value); bool getValueFromTable(lua_State *lua, const std::string& key, time_t& value); bool getValueFromTable(lua_State *lua, const std::string& key, uint32_t& value); @@ -166,7 +167,7 @@ private: void dnsrr_to_table(lua_State *lua, const DNSResourceRecord *rr); //reload.cc - void get_lua_function(lua_State *lua, const char *name, int *function); + void get_lua_function(lua_State *lua, const char *name, int *function); bool dnssec; @@ -179,14 +180,14 @@ private: /* //minimal.cc bool content(DNSResourceRecord* rr); - + void getTheFreshOnes(vector* domains, string *type, string *f_name); bool checkDomainInfo(const string *domain, mongo::BSONObj *mongo_r, string *f_name, string *mongo_q, DomainInfo *di, SOAData *soadata = NULL); - - + + //crc32.cc int generateCRC32(const string& my_string); - + string mongo_db; string collection_domains; string collection_records; @@ -196,11 +197,11 @@ private: string collection_tsigkeys; mongo::DBClientConnection m_db; - + auto_ptr cursor; - + string q_name; - + // long long unsigned int count; mongo::Query mongo_query; mongo::BSONObj mongo_record; @@ -208,9 +209,9 @@ private: DNSResourceRecord rr_record; string type; mongo::BSONObjIterator* contents; - - - + + + unsigned int default_ttl; bool logging_cerr; @@ -219,10 +220,10 @@ private: bool checkindex; bool use_default_ttl; - + bool axfr_soa; SOAData last_soadata; -*/ +*/ }; -#endif +#endif diff --git a/modules/luabackend/minimal.cc b/modules/luabackend/minimal.cc index d92a7d9f8..da0264fcc 100644 --- a/modules/luabackend/minimal.cc +++ b/modules/luabackend/minimal.cc @@ -2,7 +2,7 @@ Copyright (C) 2011 Fredrik Danerklint This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published + it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation This program is distributed in the hope that it will be useful, @@ -30,7 +30,7 @@ LUABackend::LUABackend(const string &suffix) { setArgPrefix("lua"+suffix); - + try { if (pthread_equal(backend_pid, pthread_self())) { @@ -39,7 +39,7 @@ LUABackend::LUABackend(const string &suffix) { backend_count = 1; backend_pid = pthread_self(); } - + // lb = NULL; lua = NULL; dnspacket = NULL; @@ -54,68 +54,68 @@ LUABackend::LUABackend(const string &suffix) { } } - + LUABackend::~LUABackend() { L< 0) + if (soadata.ttl == 0 && soadata.default_ttl > 0) soadata.ttl = soadata.default_ttl; - + if (soadata.ttl == 0) { lua_pop(lua, 1 ); return false; } - + if (!getValueFromTable(lua, "nameserver", soadata.nameserver)) { soadata.nameserver = arg()["default-soa-name"]; if (soadata.nameserver.empty()) { - L<