#endif
}
+// expects a table at offset 2, and, importantly DOES NOT POP IT from the stack - only the contents
void popResourceRecordsTable(lua_State *lua, const string &query, vector<DNSResourceRecord>& ret)
{
/* get the result */
rr.d_place = DNSResourceRecord::ANSWER;
rr.ttl = 3600;
-// cerr<<"Lua stacksize "<<lua_gettop(lua)<<endl;
-
int tableLen = getLuaTableLength(lua, 2);
-// cerr<<"Got back "<<tableLen<< " answers from Lua"<<endl;
for(int n=1; n < tableLen + 1; ++n) {
lua_pushnumber(lua, n);
PowerDNSLua::PowerDNSLua(const std::string& fname)
{
-
d_lua = luaL_newstate();
lua_pushcfunction(d_lua, netmaskMatchLua);
{
lua_close(d_lua);
}
+
+#if 0
+void luaStackDump (lua_State *L) {
+ int i;
+ int top = lua_gettop(L);
+ for (i = 1; i <= top; i++) { /* repeat for each level */
+ int t = lua_type(L, i);
+ switch (t) {
+
+ case LUA_TSTRING: /* strings */
+ printf("`%s'", lua_tostring(L, i));
+ break;
+
+ case LUA_TBOOLEAN: /* booleans */
+ printf(lua_toboolean(L, i) ? "true" : "false");
+ break;
+
+ case LUA_TNUMBER: /* numbers */
+ printf("%g", lua_tonumber(L, i));
+ break;
+
+ default: /* other values */
+ printf("%s", lua_typename(L, t));
+ break;
+
+ }
+ printf(" "); /* put a separator */
+ }
+ printf("\n"); /* end the listing */
+}
+#endif
+
#endif
// empty
}
+int followCNAMERecords(vector<DNSResourceRecord>& ret, const QType& qtype)
+{
+ vector<DNSResourceRecord> resolved;
+ string target;
+ BOOST_FOREACH(DNSResourceRecord& rr, ret) {
+ if(rr.qtype.getCode() == QType::CNAME) {
+ target=rr.content;
+ break;
+ }
+ }
+ if(target.empty())
+ return 0;
+
+ if(target[target.size()-1]!='.')
+ target.append(1, '.');
+
+ int rcode=directResolve(target, qtype, 1, resolved); // 1 == class
+
+ BOOST_FOREACH(const DNSResourceRecord& rr, resolved)
+ {
+ ret.push_back(rr);
+ }
+ return rcode;
+
+}
+
int getFakeAAAARecords(const std::string& qname, const std::string& prefix, vector<DNSResourceRecord>& ret)
{
int rcode=directResolve(qname, QType(QType::A), 1, ret);
extraParameter+=2;
}
- if(lua_pcall(d_lua, 3 + extraParameter, 3, 0)) {
+ if(lua_pcall(d_lua, 3 + extraParameter, 3, 0)) { // NOTE! Means we always get 3 stack entries back!
string error=string("lua error in '"+func+"' while processing query for '"+query+"|"+qtype.getName()+": ")+lua_tostring(d_lua, -1);
lua_pop(d_lua, 1);
throw runtime_error(error);
return false;
}
-
+
*variable |= d_variable;
if(!lua_isnumber(d_lua, 1)) {
string tocall = lua_tostring(d_lua,1);
- string luaqname = lua_tostring(d_lua,2);
- string luaprefix = lua_tostring(d_lua, 3);
- lua_pop(d_lua, 3);
- // cerr<<"should call '"<<tocall<<"' to finish off"<<endl;
+ lua_remove(d_lua, 1); // the name
ret.clear();
- if(tocall == "getFakeAAAARecords")
+ if(tocall == "getFakeAAAARecords") {
+ string luaprefix = lua_tostring(d_lua, 2);
+ string luaqname = lua_tostring(d_lua,1);
+ lua_pop(d_lua, 2);
res = getFakeAAAARecords(luaqname, luaprefix, ret);
- else if(tocall == "getFakePTRRecords")
+ }
+ else if(tocall == "getFakePTRRecords") {
+ string luaprefix = lua_tostring(d_lua, 2);
+ string luaqname = lua_tostring(d_lua,1);
+ lua_pop(d_lua, 2);
res = getFakePTRRecords(luaqname, luaprefix, ret);
+ }
+ else if(tocall == "followCNAMERecords") {
+ popResourceRecordsTable(d_lua, query, ret);
+ lua_pop(d_lua, 2);
+ res = followCNAMERecords(ret, qtype);
+ }
+
return true;
// returned a followup
}
/* 1 2 3 4 */
/* stack: boolean table key row */
- popResourceRecordsTable(d_lua, query, ret);
-
+ popResourceRecordsTable(d_lua, query, ret); // doesn't actually pop the table itself!
lua_pop(d_lua, 3);
-
return true;
}