diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-12 15:41:39 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-12 15:41:39 +0000 |
commit | 7d3f1e16638e114ad365a1e1647af53e9008e86a (patch) | |
tree | ca8e65a5bb21ed493716fb9726e5ced8b3f7c253 /src | |
parent | 1521c6a927e7fc0ff27fdaf19b4a9f355c2dade8 (diff) | |
download | rspamd-7d3f1e16638e114ad365a1e1647af53e9008e86a.tar.gz rspamd-7d3f1e16638e114ad365a1e1647af53e9008e86a.zip |
[Minor] Fix upstreams parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_upstream.c | 29 |
1 files 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; |