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);
struct http_proxy_ctx {
gdouble timeout;
struct timeval io_tv;
+ struct rspamd_config *cfg;
/* DNS resolver */
struct rspamd_dns_resolver *resolver;
/* Events base */
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");
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,
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);
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 */
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",
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",
}
/***
- * @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;
}
}
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);
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);
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);
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);