From: Mikhail Galanin Date: Tue, 14 Aug 2018 15:22:00 +0000 (+0100) Subject: [Minor] Better return value - table/string for result, true/false as error sign X-Git-Tag: 1.8.0~234^2~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f146f7b7123820c368d224aec697da1acfd2aa33;p=rspamd.git [Minor] Better return value - table/string for result, true/false as error sign --- diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 8baa3e615..37a53a8b5 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -228,21 +228,6 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg) } lua_pushnil (cd->L); } - else { - lua_pushnil (cd->L); - lua_pushstring (cd->L, rdns_strerror (reply->code)); - } - - if (cd->cbref != -1) { - if (cd->user_str != NULL) { - lua_pushstring (cd->L, cd->user_str); - } - else { - lua_pushnil (cd->L); - } - } - - lua_pushboolean (cd->L, reply->authenticated); if (cd->cbref != -1) { /* @@ -253,6 +238,19 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg) * 5 - user_str * 6 - reply->authenticated */ + if (reply->code != RDNS_RC_NOERROR) { + lua_pushnil (cd->L); + lua_pushstring (cd->L, rdns_strerror (reply->code)); + } + if (cd->user_str != NULL) { + lua_pushstring (cd->L, cd->user_str); + } + else { + lua_pushnil (cd->L); + } + + lua_pushboolean (cd->L, reply->authenticated); + if (lua_pcall (cd->L, 6, 0, 0) != 0) { msg_info ("call to dns callback failed: %s", lua_tostring (cd->L, -1)); lua_pop (cd->L, 1); @@ -262,11 +260,28 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg) luaL_unref (cd->L, LUA_REGISTRYINDEX, cd->cbref); } else { /* - * 1 - entries - * 2 - error | nil - * 3 - reply->authenticated + * 1 - true | false in the case of error + * 2. string - error message or table { + * [0] -> entry 1 + * [1] -> entry 2 + * ... + * is_authenticated = true|false + * } */ - lua_resume_thread (cd->task, cd->thread, 3); + if (reply->code != RDNS_RC_NOERROR) { + lua_pushboolean (cd->L, false); + lua_pushstring (cd->L, rdns_strerror (reply->code)); + } + else { + lua_pushboolean (cd->L, reply->authenticated); + lua_setfield (cd->L, -3, "authenticated"); + + /* result 1 - not and error */ + lua_pushboolean (cd->L, true); + /* push table into stack, result 2 - results itself */ + lua_pushvalue (cd->L, -3); + } + lua_resume_thread (cd->task, cd->thread, 2); } if (cd->s) {