From 7d3f1e16638e114ad365a1e1647af53e9008e86a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 12 Mar 2018 15:41:39 +0000 Subject: [PATCH] [Minor] Fix upstreams parsing --- src/lua/lua_upstream.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index e67d60443..680b2c61b 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -185,11 +185,12 @@ lua_upstream_list_create (lua_State *L) top = 1; } - def = luaL_checkstring (L, top); - if (def) { - if (lua_gettop (L) >= top + 1) { - default_port = luaL_checknumber (L, top + 1); - } + if (lua_gettop (L) >= top + 1) { + default_port = luaL_checknumber (L, top + 1); + } + + if (lua_type (L, top) == LUA_TSTRING) { + def = luaL_checkstring (L, top); new = rspamd_upstreams_create (cfg ? cfg->ups_ctx : NULL); @@ -203,8 +204,24 @@ lua_upstream_list_create (lua_State *L) lua_pushnil (L); } } + else if (lua_type (L, top) == LUA_TTABLE) { + new = rspamd_upstreams_create (cfg ? cfg->ups_ctx : NULL); + pnew = lua_newuserdata (L, sizeof (struct upstream_list *)); + rspamd_lua_setclass (L, "rspamd{upstream_list}", -1); + *pnew = new; + + for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) { + def = lua_tostring (L, -1); + + if (!def || !rspamd_upstreams_parse_line (new, def, default_port, NULL)) { + rspamd_upstreams_destroy (new); + msg_warn ("cannot parse %s", def); + lua_pushnil (L); + } + } + } else { - lua_error (L); + return luaL_error (L, "invalid arguments"); } return 1; -- 2.39.5