diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-20 16:17:24 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-20 16:17:24 +0000 |
commit | 13cb93001a2cb7dbf7db85b25ac22558da4f610b (patch) | |
tree | 468ad6403e5649017593b3c8ae960132759a7045 /src/lua/lua_upstream.c | |
parent | a42332ca48be149ed950ed9ccaf81d58783a13c9 (diff) | |
download | rspamd-13cb93001a2cb7dbf7db85b25ac22558da4f610b.tar.gz rspamd-13cb93001a2cb7dbf7db85b25ac22558da4f610b.zip |
Fix upstreams usage
Diffstat (limited to 'src/lua/lua_upstream.c')
-rw-r--r-- | src/lua/lua_upstream.c | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index 0b2739903..8ceadcc8c 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -168,54 +168,39 @@ lua_check_upstream_list (lua_State * L) } /*** - * @function upstream_list.create(def) + * @function upstream_list.create(cfg, def, [default_port]) * Create new upstream list from its string definition in form `<upstream>,<upstream>;<upstream>` + * @param {rspamd_config} cfg configuration reference * @param {string} def upstream list definition + * @param {number} default_port default port for upstreams * @return {upstream_list} upstream list structure */ static gint lua_upstream_list_create (lua_State *L) { struct upstream_list *new = NULL, **pnew; + struct rspamd_config *cfg = lua_check_config (L, 1); const gchar *def; - char **tokens, **t; guint default_port = 0; - def = luaL_checkstring (L, 1); + def = luaL_checkstring (L, 2); if (def) { - if (lua_gettop (L) >= 2) { - default_port = luaL_checknumber (L, 2); + if (lua_gettop (L) >= 3) { + default_port = luaL_checknumber (L, 3); } - tokens = g_strsplit_set (def, ",;", 0); - if (!tokens || !tokens[0]) { - goto err; - } - t = tokens; + new = rspamd_upstreams_create (cfg->ups_ctx); - new = rspamd_upstreams_create (); - while (*t != NULL) { - if (!rspamd_upstreams_add_upstream (new, *t, default_port, NULL)) { - goto err; - } - t ++; + if (rspamd_upstreams_parse_line (new, def, default_port, NULL)) { + pnew = lua_newuserdata (L, sizeof (struct upstream_list *)); + rspamd_lua_setclass (L, "rspamd{upstream_list}", -1); + *pnew = new; + } + else { + rspamd_upstreams_destroy (new); + lua_pushnil (L); } - pnew = lua_newuserdata (L, sizeof (struct upstream_list *)); - rspamd_lua_setclass (L, "rspamd{upstream_list}", -1); - - g_strfreev (tokens); - *pnew = new; - } - - return 1; -err: - if (tokens) { - g_strfreev (tokens); - } - if (new) { - rspamd_upstreams_destroy (new); } - lua_pushnil (L); return 1; } |