diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-12-09 13:58:31 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-12-09 13:58:31 +0000 |
commit | aef0c78138f490e5a494ee7673bdba95bcf08f56 (patch) | |
tree | cd9f778c9aa9e41914fcbc87df102aa7d546c7aa /src/lua | |
parent | 0dd2ed02ae883de3cc19c14aeaf0180c3dd99952 (diff) | |
download | rspamd-aef0c78138f490e5a494ee7673bdba95bcf08f56.tar.gz rspamd-aef0c78138f490e5a494ee7673bdba95bcf08f56.zip |
Add resolve_mx method.
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_dns.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index c56ff4548..540fc7713 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -33,6 +33,7 @@ LUA_FUNCTION_DEF (dns_resolver, init); LUA_FUNCTION_DEF (dns_resolver, resolve_a); LUA_FUNCTION_DEF (dns_resolver, resolve_ptr); LUA_FUNCTION_DEF (dns_resolver, resolve_txt); +LUA_FUNCTION_DEF (dns_resolver, resolve_mx); static const struct luaL_reg dns_resolverlib_f[] = { LUA_INTERFACE_DEF (dns_resolver, init), @@ -43,6 +44,7 @@ static const struct luaL_reg dns_resolverlib_m[] = { LUA_INTERFACE_DEF (dns_resolver, resolve_a), LUA_INTERFACE_DEF (dns_resolver, resolve_ptr), LUA_INTERFACE_DEF (dns_resolver, resolve_txt), + LUA_INTERFACE_DEF (dns_resolver, resolve_mx), {"__tostring", lua_class_tostring}, {NULL, NULL} }; @@ -128,6 +130,24 @@ lua_dns_callback (struct rspamd_dns_reply *reply, gpointer arg) lua_pushnil (cd->L); } + else if (reply->type == DNS_REQUEST_MX) { + lua_newtable (cd->L); + cur = reply->elements; + while (cur) { + elt = cur->data; + /* mx['name'], mx['priority'] */ + lua_newtable (cd->L); + lua_set_table_index (cd->L, "name", elt->mx.name); + lua_pushstring (cd->L, "priority"); + lua_pushnumber (cd->L, elt->mx.priority); + lua_settable (cd->L, -3); + + lua_rawseti (cd->L, -2, ++i); + cur = g_list_next (cur); + } + lua_pushnil (cd->L); + + } else { lua_pushnil (cd->L); lua_pushstring (cd->L, "Unknown reply type"); @@ -288,6 +308,21 @@ lua_dns_resolver_resolve_txt (lua_State *L) return 1; } +static int +lua_dns_resolver_resolve_mx (lua_State *L) +{ + struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L); + + if (dns_resolver) { + return lua_dns_resolver_resolve_common (L, dns_resolver, DNS_REQUEST_MX); + } + else { + lua_pushnil (L); + } + + return 1; +} + gint luaopen_dns_resolver (lua_State * L) { |