along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "contrib/cleanup.h"
-
#include "daemon/bindings/impl.h"
#include "daemon/worker.h"
- static void stackDump (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);
- printf("%d ", i); /* put a separator */
- 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 */
- }
-
-
static int wrk_resolve_pkt(lua_State *L)
{
- stackDump(L);
struct worker_ctx *worker = wrk_luaget(L);
if (!worker) {
return 0;
if (!pkt)
lua_error_maybe(L, ENOMEM);
- auto_free char *debug = kr_pkt_text(pkt);
- printf("%s\n", debug);
-
/* Create task and start with a first question */
struct qr_task *task = worker_resolve_start(worker, pkt, options);
local cond = condition.new()
local waiting, done = false, false
local finish_cb = function (answer, req)
- print(tostring(answer)) -- FIXME
-
output_ttl = get_http_ttl(answer)
-- binary output
output = ffi.string(answer.wire, answer.size)
if result ~= 0 then
return 400, 'unparseable DNS message'
end
- print(pkt)
-- set source address so filters can work
local function init_cb(req)
req.qsource.dst_addr = convert_sockaddr(stream:localname())
req.qsource.flags.tcp = true
req.qsource.flags.tls = (stream.connection:checktls() ~= nil)
- print(req.qsource.flags.tls)
req.qsource.flags.http = true
end
-- resolve query
worker.resolve_pkt(pkt, finish_cb, init_cb)
- -- Wait for asynchronous query and free callbacks -- FIXME
if not done then
waiting = true
cond:wait()
local result = ffi.C.knot_pkt_parse(pkt, 0)
ok(result == 0, desc .. ': knot_pkt_parse works on received answer')
- print(pkt)
return pkt
end
local exp_dstaddr = ffi.gc(ffi.C.kr_straddr_socket(host, port), ffi.C.free)
local function check_dstaddr(state, req)
triggered = true
- print(exp_dstaddr)
- print(req.qsource.dst_addr)
same(ffi.C.kr_sockaddr_cmp(req.qsource.dst_addr, exp_dstaddr), 0,
'request has correct server address')
return state