aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_dns.c92
-rw-r--r--src/lua/lua_http.c6
-rw-r--r--src/lua/lua_redis.c6
3 files changed, 38 insertions, 66 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);
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index 26f699b78..324807005 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -302,7 +302,7 @@ static void
lua_http_dns_callback (struct rspamd_dns_reply *reply, gpointer arg)
{
struct lua_http_ud *ud = arg;
- union rspamd_reply_element *elt;
+ struct rspamd_reply_entry *elt;
struct in_addr ina;
struct timeval tv;
@@ -312,8 +312,8 @@ lua_http_dns_callback (struct rspamd_dns_reply *reply, gpointer arg)
}
/* Create socket to server */
- elt = reply->elements->data;
- memcpy (&ina, &elt->a.addr[0], sizeof (struct in_addr));
+ elt = reply->entries;
+ memcpy (&ina, &elt->content.a.addr, sizeof (struct in_addr));
ud->fd = make_universal_socket (inet_ntoa (ina), ud->port, SOCK_STREAM, TRUE, FALSE, FALSE);
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index a9006b773..c0b5c7d52 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -243,7 +243,7 @@ static void
lua_redis_dns_callback (struct rspamd_dns_reply *reply, gpointer arg)
{
struct lua_redis_userdata *ud = arg;
- union rspamd_reply_element *elt;
+ struct rspamd_reply_entry *elt;
if (reply->code != DNS_RC_NOERROR) {
@@ -251,8 +251,8 @@ lua_redis_dns_callback (struct rspamd_dns_reply *reply, gpointer arg)
return;
}
else {
- elt = reply->elements->data;
- memcpy (&ud->ina, &elt->a.addr[0], sizeof (struct in_addr));
+ elt = reply->entries;
+ memcpy (&ud->ina, &elt->content.a.addr, sizeof (struct in_addr));
/* Make real request */
lua_redis_make_request_real (ud);
}