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!

Files:
1 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;