From aef0c78138f490e5a494ee7673bdba95bcf08f56 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 9 Dec 2013 13:58:31 +0000 Subject: [PATCH] Add resolve_mx method. --- src/lua/lua_dns.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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} }; @@ -127,6 +129,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); @@ -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) { -- 2.39.5