From: Marek VavruĊĦa Date: Fri, 3 Jul 2015 14:27:12 +0000 (+0200) Subject: modules+bindings: cleanup X-Git-Tag: v1.0.0-beta1~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0f2cf65fa65709ad5c22373283413494ed6ab1b;p=thirdparty%2Fknot-resolver.git modules+bindings: cleanup --- diff --git a/daemon/bindings/kres.c b/daemon/bindings/kres.c index 59cc178f9..6dc5b114a 100644 --- a/daemon/bindings/kres.c +++ b/daemon/bindings/kres.c @@ -88,8 +88,15 @@ static lookup_table_t wire_flag_names[] = { { 0, NULL } }; +#define PKT_UDATA_CHECK(L) \ + if (!lua_touserdata(L, 1)) { \ + lua_pushstring(L, "bad parameters, expected (pkt[, newvalue])"); \ + lua_error(L); \ + } + static int pkt_flag(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); if (lua_gettop(L) > 1 && lua_isnumber(L, 2)) { int flag_id = lua_tonumber(L, 2); @@ -104,6 +111,7 @@ static int pkt_flag(lua_State *L) static int pkt_opcode(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); if (lua_gettop(L) > 1 && lua_isnumber(L, 2)) { knot_wire_set_opcode(pkt->wire, lua_tonumber(L, 2)); @@ -114,6 +122,7 @@ static int pkt_opcode(lua_State *L) static int pkt_rcode(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); if (lua_gettop(L) > 1 && lua_isnumber(L, 2)) { knot_wire_set_rcode(pkt->wire, lua_tonumber(L, 2)); @@ -124,6 +133,7 @@ static int pkt_rcode(lua_State *L) static int pkt_qtype(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); lua_pushnumber(L, knot_pkt_qtype(pkt)); return 1; @@ -131,6 +141,7 @@ static int pkt_qtype(lua_State *L) static int pkt_qclass(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); lua_pushnumber(L, knot_pkt_qclass(pkt)); return 1; @@ -138,6 +149,7 @@ static int pkt_qclass(lua_State *L) static int pkt_qname(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); lua_pushdname(L, knot_pkt_qname(pkt)); return 1; @@ -145,6 +157,7 @@ static int pkt_qname(lua_State *L) static int pkt_question(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); if (lua_gettop(L) < 4) { return 0; @@ -161,6 +174,7 @@ static int pkt_question(lua_State *L) static int pkt_begin(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); knot_pkt_begin(pkt, lua_tointeger(L, 2)); return 0; @@ -168,6 +182,7 @@ static int pkt_begin(lua_State *L) static int pkt_add(lua_State *L) { + PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); if (lua_gettop(L) < 6) { return 0; diff --git a/daemon/ffimodule.c b/daemon/ffimodule.c index e056d54e0..902991552 100644 --- a/daemon/ffimodule.c +++ b/daemon/ffimodule.c @@ -158,9 +158,12 @@ static int l_ffi_layer_reset(knot_layer_t *ctx) static int l_ffi_layer_finish(knot_layer_t *ctx) { + struct kr_request *req = ctx->data; LAYER_FFI_CALL(ctx, "finish"); - lua_pushlightuserdata(L, ctx->data); - return l_ffi_call(L, 2); + lua_pushlightuserdata(L, req); + lua_pushlightuserdata(L, req->answer); + set_metatable(L, META_PKT); + return l_ffi_call(L, 3); } static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt) diff --git a/modules/README.rst b/modules/README.rst index 766edd64f..d4991304b 100644 --- a/modules/README.rst +++ b/modules/README.rst @@ -167,9 +167,8 @@ doesn't provide any layer to capture events. The Lua module can however provide counter.total = counter.total + 1 return state end, - finish = function (state, req) - -- catch KNOT_STATE_FAIL = 8, no bindings yet - if state == 8 then + finish = function (state, req, answer) + if state == kres.FAIL then counter.failed = counter.failed + 1 end return state @@ -256,7 +255,7 @@ See the CGO_ for more information about type conversions and interoperability be Configuring modules ------------------- -There is a callback ``X_config()`` but it's NOOP for now, as the configuration is not yet implemented. +There is a callback ``X_config()`` that you can implement, see hints module. .. _mod-properties: