Changeset 1509

Show
Ignore:
Timestamp:
02/06/10 14:50:14 (3 years ago)
Author:
ahu
Message:

WARNING WARNING! This changes the Lua/PowerDNS interface in SVN, and restores the 3.1.7.* API!
From now, use getlocaladdress() call to get the address to which a query was sent. Implemented after advice from the ever helpful #lua!

Location:
trunk/pdns/pdns
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/lua-pdns-recursor.cc

    r1472 r1509  
    8585} 
    8686 
     87int 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 
    8796int logLua(lua_State *lua) 
    8897{ 
     
    118127  lua_setglobal(d_lua, "pdnslog"); 
    119128 
     129  lua_pushcfunction(d_lua, getLocalAddressLua); 
     130  lua_setglobal(d_lua, "getlocaladdress"); 
     131 
    120132  lua_newtable(d_lua); 
    121133 
     
    127139  lua_setfield(d_lua, -2, "NXDOMAIN"); 
    128140  lua_setglobal(d_lua, "pdns"); 
     141   
     142  lua_pushlightuserdata(d_lua, (void*)this);  
     143  lua_setfield(d_lua, LUA_REGISTRYINDEX, "__PowerDNSLua"); 
    129144} 
    130145 
     
    177192    return false; 
    178193  } 
     194   
     195  d_local = local; 
    179196  /* the first argument */ 
    180197  lua_pushstring(d_lua,  remote.toString().c_str() ); 
    181   lua_pushstring(d_lua,  local.toString().c_str() ); 
    182198  lua_pushstring(d_lua,  query.c_str() ); 
    183199  lua_pushnumber(d_lua,  qtype.getCode() ); 
    184200 
    185   if(lua_pcall(d_lua,  4, 2, 0)) { // error  
     201  if(lua_pcall(d_lua,  3, 2, 0)) { // error  
    186202    string error=string("lua error in '"+func+"': ")+lua_tostring(d_lua, -1); 
    187203    lua_pop(d_lua, 1); 
     
    218234    lua_gettable(d_lua, 2); 
    219235 
    220     uint32_t tmpnum; 
     236    uint32_t tmpnum=0; 
    221237    if(!getFromTable("qtype", tmpnum))  
    222238      rr.qtype=QType::A; 
  • trunk/pdns/pdns/lua-pdns-recursor.hh

    r1309 r1509  
    1414  bool preresolve(const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret); 
    1515  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  } 
    1621private: 
    1722  lua_State* d_lua; 
     
    2025  bool getFromTable(const std::string& key, uint32_t& value); 
    2126  bool d_failed; 
     27   
     28  ComboAddress d_local; 
    2229}; 
    2330 
  • 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); 
     1function 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()); 
    44        if domain == "www.powerdns.org."  
    55        then 
     
    2626end 
    2727 
    28 function nxdomain ( remoteip, localip, domain, qtype ) 
    29         print ("nxhandler called for: ", remoteip, localip, domain, qtype, pdns.AAAA) 
     28function nxdomain ( remoteip, domain, qtype ) 
     29        print ("nxhandler called for: ", remoteip, getlocaladdress(), domain, qtype, pdns.AAAA) 
    3030        if qtype ~= pdns.A then return -1, {} end  --  only A records 
    3131        if not string.find(domain, "^www%.") then return -1, {} end  -- only things that start with www.