Changeset 1744

Show
Ignore:
Timestamp:
12/01/10 11:51:26 (2 years ago)
Author:
ahu
Message:

fix up reentrant use of Lua within the same Lua struct (which does not work)

Location:
branches/pdns-dns64/pdns
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/pdns-dns64/pdns/lua-pdns-recursor.cc

    r1737 r1744  
    7979   
    8080  int res = sr.beginResolve(qname, QType(qtype), qclass, ret); 
    81   cerr<<"Result: "<<res<<endl; 
     81  // cerr<<"Result: "<<res<<endl; 
    8282  return res; 
    8383} 
     
    117117 
    118118extern "C" { 
    119  
     119#if 0 
    120120int getFakeAAAARecords(lua_State *lua) 
    121121{ 
     
    158158  return 2; 
    159159} 
     160 
     161#endif 
    160162 
    161163int netmaskMatchLua(lua_State *lua) 
     
    212214} 
    213215 
     216int getFakeAAAARecords(const std::string& qname, const std::string& prefix, vector<DNSResourceRecord>& ret) 
     217{ 
     218  int rcode=directResolve(qname, QType(QType::A), 1, ret); 
     219   
     220  ComboAddress prefixAddress(prefix); 
     221 
     222  BOOST_FOREACH(DNSResourceRecord& rr, ret) 
     223  {     
     224    if(rr.qtype.getCode() == QType::A && rr.d_place==DNSResourceRecord::ANSWER) { 
     225      ComboAddress ipv4(rr.content); 
     226      uint32_t tmp; 
     227      memcpy((void*)&tmp, &ipv4.sin4.sin_addr.s_addr, 4); 
     228      // tmp=htonl(tmp); 
     229      memcpy(((char*)&prefixAddress.sin6.sin6_addr.s6_addr)+12, &tmp, 4); 
     230      rr.content = prefixAddress.toString(); 
     231      rr.qtype = QType(QType::AAAA); 
     232    } 
     233  } 
     234  return rcode; 
     235} 
     236 
     237 
     238 
    214239PowerDNSLua::PowerDNSLua(const std::string& fname) 
    215240{ 
     
    232257  lua_setglobal(d_lua, "matchnetmask"); 
    233258 
     259/* 
    234260  lua_pushcfunction(d_lua, getFakeAAAARecords); 
    235261  lua_setglobal(d_lua, "getFakeAAAARecords"); 
     
    237263  lua_pushcfunction(d_lua, resolveName); 
    238264  lua_setglobal(d_lua, "resolveName"); 
    239  
     265*/ 
    240266  lua_pushcfunction(d_lua, logLua); 
    241267  lua_setglobal(d_lua, "pdnslog"); 
     
    338364  } 
    339365 
    340   if(lua_pcall(d_lua,  3 + extraParameter, 2, 0)) {  
    341     string error=string("lua error in '"+func+"': ")+lua_tostring(d_lua, -1); 
     366  if(lua_pcall(d_lua,  3 + extraParameter, 3, 0)) {  
     367    string error=string("lua error in '"+func+"' while processing query for '"+query+"|"+qtype.getName()+": ")+lua_tostring(d_lua, -1); 
    342368    lua_pop(d_lua, 1); 
    343369    throw runtime_error(error); 
     
    347373  *variable |= d_variable; 
    348374   
     375   
     376  if(!lua_isnumber(d_lua, 1)) { 
     377    string tocall = lua_tostring(d_lua,1); 
     378    string luaqname = lua_tostring(d_lua,2); 
     379    string luaprefix = lua_tostring(d_lua, 3); 
     380    lua_pop(d_lua, 3); 
     381    // cerr<<"should call '"<<tocall<<"' to finish off"<<endl; 
     382    ret.clear(); 
     383    res=getFakeAAAARecords(luaqname, luaprefix, ret); 
     384    return true; 
     385    // returned a followup  
     386  } 
     387   
    349388  int newres = (int)lua_tonumber(d_lua, 1); // new rcode 
    350389  if(newres < 0) { 
    351390    //    cerr << "handler did not handle"<<endl; 
    352     lua_pop(d_lua, 2); 
     391    lua_pop(d_lua, 3); 
    353392    return false; 
    354393  } 
     
    402441  } 
    403442 
    404   lua_pop(d_lua, 2); 
     443  lua_pop(d_lua, 3); 
    405444 
    406445  return true; 
  • branches/pdns-dns64/pdns/powerdns-example-script.lua

    r1743 r1744  
    5757        print ("nodata called for: ", remoteip, getlocaladdress(), domain, qtype) 
    5858        if qtype ~= pdns.AAAA then return -1, {} end  --  only AAAA records 
    59         for key,val in ipairs(records)  
    60         do 
    61                 print(val.qtype, val.ttl) 
    62         end 
    63          
    64         rcode, ret=getFakeAAAARecords(domain, "fe80::21b:77ff:0:0") 
     59--      for key,val in ipairs(records)  
     60--      do 
     61--              print(val.qtype, val.ttl) 
     62--      end 
     63 
    6564        setvariable() 
    66         return rcode, ret 
     65        return "getFakeAAAARecords", domain, "fe80::21b:77ff:0:0" 
    6766end      
    6867 
     
    8483                end 
    8584                 
    86                 print(val.content) 
     85        --      print(val.content) 
    8786        end 
    8887        return origrcode, records