diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-01-27 16:12:27 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-01-27 16:12:27 +0000 |
commit | 9bb4dcceadb7f78efe946946ccf7742a8c6e4f50 (patch) | |
tree | 70c25bfdf8bffbb6ac5eb424a20f9bba871612ee /src/lua/lua_dns.c | |
parent | 15b1bddab547189e5fbdcb4441b2d64e4c8f10aa (diff) | |
download | rspamd-9bb4dcceadb7f78efe946946ccf7742a8c6e4f50.tar.gz rspamd-9bb4dcceadb7f78efe946946ccf7742a8c6e4f50.zip |
Rework resolver library.
Diffstat (limited to 'src/lua/lua_dns.c')
-rw-r--r-- | src/lua/lua_dns.c | 92 |
1 files changed, 32 insertions, 60 deletions
diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 540fc7713..2bfbe582f 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -71,8 +71,7 @@ lua_dns_callback (struct rspamd_dns_reply *reply, gpointer arg) struct lua_dns_cbdata *cd = arg; gint i = 0; struct rspamd_dns_resolver **presolver; - union rspamd_reply_element *elt; - GList *cur; + struct rspamd_reply_entry *elt; lua_rawgeti (cd->L, LUA_REGISTRYINDEX, cd->cbref); presolver = lua_newuserdata (cd->L, sizeof (gpointer)); @@ -81,77 +80,50 @@ lua_dns_callback (struct rspamd_dns_reply *reply, gpointer arg) *presolver = cd->resolver; lua_pushstring (cd->L, cd->to_resolve); + /* + * XXX: rework to handle different request types + */ if (reply->code == DNS_RC_NOERROR) { - if (reply->type == DNS_REQUEST_A) { - - lua_newtable (cd->L); - cur = reply->elements; - while (cur) { - elt = cur->data; - lua_ip_push (cd->L, AF_INET, &elt->a.addr); - lua_rawseti (cd->L, -2, ++i); - cur = g_list_next (cur); + lua_newtable (cd->L); + LL_FOREACH (reply->entries, elt) { + if (elt->type != reply->request->type) { + /* + * XXX: Skip additional record here to be compatible + * with the existing plugins + */ + continue; } - lua_pushnil (cd->L); - } - else if (reply->type == DNS_REQUEST_AAA) { - - lua_newtable (cd->L); - cur = reply->elements; - while (cur) { - elt = cur->data; - lua_ip_push (cd->L, AF_INET6, &elt->aaa.addr); + switch (elt->type) { + case DNS_REQUEST_A: + lua_ip_push (cd->L, AF_INET, &elt->content.a.addr); lua_rawseti (cd->L, -2, ++i); - cur = g_list_next (cur); - } - lua_pushnil (cd->L); - } - else if (reply->type == DNS_REQUEST_PTR) { - lua_newtable (cd->L); - cur = reply->elements; - while (cur) { - elt = cur->data; - lua_pushstring (cd->L, elt->ptr.name); + break; + case DNS_REQUEST_AAA: + lua_ip_push (cd->L, AF_INET6, &elt->content.aaa.addr); lua_rawseti (cd->L, -2, ++i); - cur = g_list_next (cur); - } - lua_pushnil (cd->L); - - } - else if (reply->type == DNS_REQUEST_TXT) { - lua_newtable (cd->L); - cur = reply->elements; - while (cur) { - elt = cur->data; - lua_pushstring (cd->L, elt->txt.data); + break; + case DNS_REQUEST_PTR: + lua_pushstring (cd->L, elt->content.ptr.name); lua_rawseti (cd->L, -2, ++i); - cur = g_list_next (cur); - } - lua_pushnil (cd->L); - - } - else if (reply->type == DNS_REQUEST_MX) { - lua_newtable (cd->L); - cur = reply->elements; - while (cur) { - elt = cur->data; + break; + case DNS_REQUEST_TXT: + case DNS_REQUEST_SPF: + lua_pushstring (cd->L, elt->content.txt.data); + lua_rawseti (cd->L, -2, ++i); + break; + case DNS_REQUEST_MX: /* mx['name'], mx['priority'] */ lua_newtable (cd->L); - lua_set_table_index (cd->L, "name", elt->mx.name); + lua_set_table_index (cd->L, "name", elt->content.mx.name); lua_pushstring (cd->L, "priority"); - lua_pushnumber (cd->L, elt->mx.priority); + lua_pushnumber (cd->L, elt->content.mx.priority); lua_settable (cd->L, -3); lua_rawseti (cd->L, -2, ++i); - cur = g_list_next (cur); + break; } - lua_pushnil (cd->L); - - } - else { - lua_pushnil (cd->L); - lua_pushstring (cd->L, "Unknown reply type"); } + lua_pushnil (cd->L); } else { lua_pushnil (cd->L); |