]> source.dussan.org Git - rspamd.git/commitdiff
Add resolve_mx method.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Dec 2013 13:58:31 +0000 (13:58 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Dec 2013 13:58:31 +0000 (13:58 +0000)
src/lua/lua_dns.c

index c56ff4548f1c8eac861c8ea1f0a7803f4716debb..540fc77130b4e1c35e9d0d6d0b3f78026d4363d7 100644 (file)
@@ -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)
 {