Changeset 1509
- Timestamp:
- 02/06/10 14:50:14 (3 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 3 modified
-
lua-pdns-recursor.cc (modified) (5 diffs)
-
lua-pdns-recursor.hh (modified) (2 diffs)
-
powerdns-example-script.lua (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/lua-pdns-recursor.cc
r1472 r1509 85 85 } 86 86 87 int getLocalAddressLua(lua_State* lua) 88 { 89 lua_getfield(lua, LUA_REGISTRYINDEX, "__PowerDNSLua"); 90 PowerDNSLua* pl = (PowerDNSLua*)lua_touserdata(lua, -1); 91 92 lua_pushstring(lua, pl->getLocal().toString().c_str()); 93 return 1; 94 } 95 87 96 int logLua(lua_State *lua) 88 97 { … … 118 127 lua_setglobal(d_lua, "pdnslog"); 119 128 129 lua_pushcfunction(d_lua, getLocalAddressLua); 130 lua_setglobal(d_lua, "getlocaladdress"); 131 120 132 lua_newtable(d_lua); 121 133 … … 127 139 lua_setfield(d_lua, -2, "NXDOMAIN"); 128 140 lua_setglobal(d_lua, "pdns"); 141 142 lua_pushlightuserdata(d_lua, (void*)this); 143 lua_setfield(d_lua, LUA_REGISTRYINDEX, "__PowerDNSLua"); 129 144 } 130 145 … … 177 192 return false; 178 193 } 194 195 d_local = local; 179 196 /* the first argument */ 180 197 lua_pushstring(d_lua, remote.toString().c_str() ); 181 lua_pushstring(d_lua, local.toString().c_str() );182 198 lua_pushstring(d_lua, query.c_str() ); 183 199 lua_pushnumber(d_lua, qtype.getCode() ); 184 200 185 if(lua_pcall(d_lua, 4, 2, 0)) { // error201 if(lua_pcall(d_lua, 3, 2, 0)) { // error 186 202 string error=string("lua error in '"+func+"': ")+lua_tostring(d_lua, -1); 187 203 lua_pop(d_lua, 1); … … 218 234 lua_gettable(d_lua, 2); 219 235 220 uint32_t tmpnum ;236 uint32_t tmpnum=0; 221 237 if(!getFromTable("qtype", tmpnum)) 222 238 rr.qtype=QType::A; -
trunk/pdns/pdns/lua-pdns-recursor.hh
r1309 r1509 14 14 bool preresolve(const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 15 15 bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 16 17 ComboAddress getLocal() 18 { 19 return d_local; 20 } 16 21 private: 17 22 lua_State* d_lua; … … 20 25 bool getFromTable(const std::string& key, uint32_t& value); 21 26 bool d_failed; 27 28 ComboAddress d_local; 22 29 }; 23 30 -
trunk/pdns/pdns/powerdns-example-script.lua
r1319 r1509 1 function preresolve ( remoteip, localip,domain, qtype )2 print ("prequery handler called for: ", remoteip, localip, domain, qtype)3 pdnslog("a test message.. received query from "..remoteip.." on ".. localip);1 function preresolve ( remoteip, domain, qtype ) 2 print ("prequery handler called for: ", remoteip, getlocaladdress(), domain, qtype) 3 pdnslog("a test message.. received query from "..remoteip.." on "..getlocaladdress()); 4 4 if domain == "www.powerdns.org." 5 5 then … … 26 26 end 27 27 28 function nxdomain ( remoteip, localip,domain, qtype )29 print ("nxhandler called for: ", remoteip, localip, domain, qtype, pdns.AAAA)28 function nxdomain ( remoteip, domain, qtype ) 29 print ("nxhandler called for: ", remoteip, getlocaladdress(), domain, qtype, pdns.AAAA) 30 30 if qtype ~= pdns.A then return -1, {} end -- only A records 31 31 if not string.find(domain, "^www%.") then return -1, {} end -- only things that start with www.