]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules+bindings: cleanup
authorMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 3 Jul 2015 14:27:12 +0000 (16:27 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 3 Jul 2015 14:27:12 +0000 (16:27 +0200)
daemon/bindings/kres.c
daemon/ffimodule.c
modules/README.rst

index 59cc178f949aa0a094015ce963ce37fe7bb3e8f4..6dc5b114a4b0482990dc0165035ae78406516692 100644 (file)
@@ -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;
index e056d54e0780034a3ef0e734906cb78024b4f969..902991552768eefbffad78b7fc551cd29fea84e3 100644 (file)
@@ -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)
index 766edd64f67ae903675bb5236f9438e320cc71f3..d4991304b95c5d5ced656e589d2ca7b8810b73cd 100644 (file)
@@ -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: