From: Vsevolod Stakhov Date: Tue, 13 Jun 2017 20:01:42 +0000 (+0100) Subject: [Minor] Allow to specify config when doing TCP request X-Git-Tag: 1.6.1~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5e5552c424e856419a2b5261bf496d91328b8ac1;p=rspamd.git [Minor] Allow to specify config when doing TCP request --- diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index c0938d684..1f7b2b05b 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -216,12 +216,17 @@ static void lua_tcp_plan_handler_event (struct lua_tcp_cbdata *cbd, static const int default_tcp_timeout = 5000; static struct rspamd_dns_resolver * -lua_tcp_global_resolver (struct event_base *ev_base) +lua_tcp_global_resolver (struct event_base *ev_base, + struct rspamd_config *cfg) { static struct rspamd_dns_resolver *global_resolver; + if (cfg && cfg->dns_resolver) { + return cfg->dns_resolver; + } + if (global_resolver == NULL) { - global_resolver = dns_resolver_init (NULL, ev_base, NULL); + global_resolver = dns_resolver_init (NULL, ev_base, cfg); } return global_resolver; @@ -923,6 +928,7 @@ lua_tcp_request (lua_State *L) struct rspamd_dns_resolver *resolver; struct rspamd_async_session *session; struct rspamd_task *task = NULL; + struct rspamd_config *cfg; struct iovec *iov = NULL; guint niov = 0, total_out; guint64 h; @@ -980,23 +986,33 @@ lua_tcp_request (lua_State *L) } lua_pop (L, 1); - lua_pushstring (L, "resolver"); + lua_pushstring (L, "session"); lua_gettable (L, -2); - if (rspamd_lua_check_udata_maybe (L, -1, "rspamd{resolver}")) { - resolver = *(struct rspamd_dns_resolver **)lua_touserdata (L, -1); + if (rspamd_lua_check_udata_maybe (L, -1, "rspamd{session}")) { + session = *(struct rspamd_async_session **)lua_touserdata (L, -1); } else { - resolver = lua_tcp_global_resolver (ev_base); + session = NULL; } lua_pop (L, 1); - lua_pushstring (L, "session"); + lua_pushstring (L, "config"); lua_gettable (L, -2); - if (rspamd_lua_check_udata_maybe (L, -1, "rspamd{session}")) { - session = *(struct rspamd_async_session **)lua_touserdata (L, -1); + if (rspamd_lua_check_udata_maybe (L, -1, "rspamd{config}")) { + cfg = *(struct rspamd_config **)lua_touserdata (L, -1); } else { - session = NULL; + cfg = NULL; + } + lua_pop (L, 1); + + lua_pushstring (L, "resolver"); + lua_gettable (L, -2); + if (rspamd_lua_check_udata_maybe (L, -1, "rspamd{resolver}")) { + resolver = *(struct rspamd_dns_resolver **)lua_touserdata (L, -1); + } + else { + resolver = lua_tcp_global_resolver (ev_base, cfg); } lua_pop (L, 1); }