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 | |
parent | a42332ca48be149ed950ed9ccaf81d58783a13c9 (diff) | |
download | rspamd-13cb93001a2cb7dbf7db85b25ac22558da4f610b.tar.gz rspamd-13cb93001a2cb7dbf7db85b25ac22558da4f610b.zip |
Fix upstreams usage
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 5 | ||||
-rw-r--r-- | src/http_proxy.c | 9 | ||||
-rw-r--r-- | src/libserver/cfg_file.h | 1 | ||||
-rw-r--r-- | src/libstat/backends/redis.c | 4 | ||||
-rw-r--r-- | src/lua/lua_upstream.c | 47 | ||||
-rw-r--r-- | src/plugins/fuzzy_check.c | 2 | ||||
-rw-r--r-- | src/plugins/surbl.c | 2 | ||||
-rw-r--r-- | src/smtp_proxy.c | 5 | ||||
-rw-r--r-- | src/worker.c | 5 |
9 files changed, 36 insertions, 44 deletions
diff --git a/src/controller.c b/src/controller.c index be60050fc..31274f5d6 100644 --- a/src/controller.c +++ b/src/controller.c @@ -2550,8 +2550,9 @@ start_controller_worker (struct rspamd_worker *worker) ctx->ev_base, worker->srv->cfg); - rspamd_upstreams_library_init (ctx->resolver->r, ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg); + worker->srv->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, + ctx->ev_base); + rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx); /* Maps events */ rspamd_map_watch (worker->srv->cfg, ctx->ev_base); rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base); diff --git a/src/http_proxy.c b/src/http_proxy.c index 85ee1c4bd..a5290de63 100644 --- a/src/http_proxy.c +++ b/src/http_proxy.c @@ -63,6 +63,7 @@ struct rspamd_http_upstream { struct http_proxy_ctx { gdouble timeout; struct timeval io_tv; + struct rspamd_config *cfg; /* DNS resolver */ struct rspamd_dns_resolver *resolver; /* Events base */ @@ -155,7 +156,7 @@ http_proxy_parse_upstream (rspamd_mempool_t *pool, goto err; } - up->u = rspamd_upstreams_create (); + up->u = rspamd_upstreams_create (ctx->cfg->ups_ctx); if (!rspamd_upstreams_from_ucl (up->u, elt, 11333, NULL)) { g_set_error (err, http_proxy_quark (), 100, "upstream has bad hosts definition"); @@ -200,6 +201,7 @@ init_http_proxy (struct rspamd_config *cfg) ctx->timeout = 5.0; ctx->upstreams = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); ctx->rotate_tm = DEFAULT_ROTATION_TIME; + ctx->cfg = cfg; rspamd_rcl_register_worker_option (cfg, type, "timeout", rspamd_rcl_parse_struct_time, ctx, @@ -457,8 +459,9 @@ start_http_proxy (struct rspamd_worker *worker) worker->srv->cfg); double_to_tv (ctx->timeout, &ctx->io_tv); - rspamd_upstreams_library_init (ctx->resolver->r, ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg); + ctx->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, + ctx->ev_base); + rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx); /* XXX: stupid default */ ctx->keys_cache = rspamd_keypair_cache_new (256); diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 96fc56d52..6263705ac 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -309,6 +309,7 @@ struct rspamd_config { guint upstream_max_errors; /**< upstream max errors before shutting off */ gdouble upstream_error_time; /**< rate of upstream errors */ gdouble upstream_revive_time; /**< revive timeout for upstreams */ + struct upstream_ctx *ups_ctx; /**< upstream context */ guint min_word_len; /**< minimum length of the word to be considered */ guint max_word_len; /**< maximum length of the word to be considered */ diff --git a/src/libstat/backends/redis.c b/src/libstat/backends/redis.c index 39d7dc21a..66bad4471 100644 --- a/src/libstat/backends/redis.c +++ b/src/libstat/backends/redis.c @@ -319,7 +319,7 @@ rspamd_redis_init (struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg) continue; } else { - backend->read_servers = rspamd_upstreams_create (); + backend->read_servers = rspamd_upstreams_create (cfg->ups_ctx); if (!rspamd_upstreams_from_ucl (backend->read_servers, elt, REDIS_DEFAULT_PORT, NULL)) { msg_err ("statfile %s cannot read servers configuration", @@ -337,7 +337,7 @@ rspamd_redis_init (struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg) continue; } else { - backend->write_servers = rspamd_upstreams_create (); + backend->write_servers = rspamd_upstreams_create (cfg->ups_ctx); if (!rspamd_upstreams_from_ucl (backend->write_servers, elt, REDIS_DEFAULT_PORT, NULL)) { msg_err ("statfile %s cannot write servers configuration", 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; } diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index f8379d477..c6db5e016 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -365,7 +365,7 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, gint cb_id } if ((value = ucl_object_find_key (obj, "servers")) != NULL) { - rule->servers = rspamd_upstreams_create (); + rule->servers = rspamd_upstreams_create (cfg->ups_ctx); rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool, (rspamd_mempool_destruct_t)rspamd_upstreams_destroy, rule->servers); diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 40ab9f668..c53fc00bd 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -350,7 +350,7 @@ surbl_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector")) != NULL) { - surbl_module_ctx->redirectors = rspamd_upstreams_create (); + surbl_module_ctx->redirectors = rspamd_upstreams_create (cfg->ups_ctx); rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t)rspamd_upstreams_destroy, surbl_module_ctx->redirectors); diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index 0ae9c70c4..390ca292b 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -1073,8 +1073,9 @@ start_smtp_proxy (struct rspamd_worker *worker) ctx->ev_base, worker->srv->cfg); - rspamd_upstreams_library_init (ctx->resolver->r, ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg); + worker->srv->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, + ctx->ev_base); + rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx); /* Set umask */ umask (S_IWGRP | S_IWOTH | S_IROTH | S_IRGRP); diff --git a/src/worker.c b/src/worker.c index 933e83053..cd63a4e00 100644 --- a/src/worker.c +++ b/src/worker.c @@ -352,8 +352,9 @@ start_worker (struct rspamd_worker *worker) ctx->ev_base, worker->srv->cfg); - rspamd_upstreams_library_init (ctx->resolver->r, ctx->ev_base); - rspamd_upstreams_library_config (worker->srv->cfg); + ctx->cfg->ups_ctx = rspamd_upstreams_library_init (ctx->resolver->r, + ctx->ev_base); + rspamd_upstreams_library_config (worker->srv->cfg, ctx->cfg->ups_ctx); /* XXX: stupid default */ ctx->keys_cache = rspamd_keypair_cache_new (256); |