From: Vsevolod Stakhov Date: Wed, 19 Sep 2012 16:29:58 +0000 (+0400) Subject: Avoid global variables in map logic. X-Git-Tag: 0.5.3~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=91d183b8f4719ecc6b339cc3e8d9239bf7594e30;p=rspamd.git Avoid global variables in map logic. * Add support of simple maps like '/path/to/file' as it seems to be more comfortable than 'file:///...' --- diff --git a/src/cfg_file.h b/src/cfg_file.h index c4e820997..279f35988 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -314,12 +314,17 @@ struct config_file { GList *views; /**< views */ GList *pre_filters; /**< list of pre-processing lua filters */ GList *post_filters; /**< list of post-processing lua filters */ + gchar *dynamic_conf; /**< path to dynamic configuration */ GHashTable* domain_settings; /**< settings per-domains */ GHashTable* user_settings; /**< settings per-user */ gchar* domain_settings_str; /**< string representation of settings */ gchar* user_settings_str; gint clock_res; /**< resolution of clock used */ + GList *maps; /**< maps active */ + memory_pool_t *map_pool; /**< static maps pool */ + gdouble map_timeout; /**< maps watch timeout */ + struct symbols_cache *cache; /**< symbols cache object */ gchar *cache_filename; /**< filename of cache file */ struct metric *default_metric; /**< default metric */ diff --git a/src/cfg_utils.c b/src/cfg_utils.c index f08f55eab..1651f16ff 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -33,11 +33,13 @@ #include "cfg_xml.h" #include "lua/lua_common.h" #include "kvstorage_config.h" +#include "map.h" #define DEFAULT_SCORE 10.0 #define DEFAULT_RLIMIT_NOFILE 2048 #define DEFAULT_RLIMIT_MAXCORE 0 +#define DEFAULT_MAP_TIMEOUT 10 gboolean @@ -221,6 +223,8 @@ init_defaults (struct config_file *cfg) cfg->cfg_params = g_hash_table_new (g_str_hash, g_str_equal); cfg->metrics_symbols = g_hash_table_new (g_str_hash, g_str_equal); + cfg->map_timeout = DEFAULT_MAP_TIMEOUT; + cfg->log_level = G_LOG_LEVEL_WARNING; cfg->log_extended = TRUE; @@ -231,6 +235,7 @@ init_defaults (struct config_file *cfg) void free_config (struct config_file *cfg) { + remove_all_maps (cfg); g_hash_table_remove_all (cfg->modules_opts); g_hash_table_unref (cfg->modules_opts); g_hash_table_remove_all (cfg->variables); diff --git a/src/cfg_xml.c b/src/cfg_xml.c index dce02efbb..1f0c0aa78 100644 --- a/src/cfg_xml.c +++ b/src/cfg_xml.c @@ -1799,7 +1799,7 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam else if (g_ascii_strcasecmp (element_name, "view") == 0) { ud->state = XML_READ_VIEW; /* Create object */ - ud->section_pointer = init_view (ud->cfg->cfg_pool); + ud->section_pointer = init_view (ud->cfg, ud->cfg->cfg_pool); } #if GLIB_MINOR_VERSION >= 18 else if (subparsers != NULL && (subparser = g_hash_table_lookup (subparsers, element_name)) != NULL) { diff --git a/src/controller.c b/src/controller.c index 5e39a7afd..dc3f84ec0 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1642,7 +1642,7 @@ start_controller (struct rspamd_worker *worker) event_base_set (ctx->ev_base, &worker->bind_ev); event_add (&worker->bind_ev, NULL); - start_map_watch (ctx->ev_base); + start_map_watch (worker->srv->cfg, ctx->ev_base); ctx->resolver = dns_resolver_init (ctx->ev_base, worker->srv->cfg); gperf_profiler_init (worker->srv->cfg, "controller"); diff --git a/src/logger.c b/src/logger.c index 9b96bc73f..ea47b98b9 100644 --- a/src/logger.c +++ b/src/logger.c @@ -308,7 +308,7 @@ rspamd_set_logger (enum rspamd_log_type type, GQuark ptype, struct rspamd_main * radix_tree_free (rspamd->logger->debug_ip); } rspamd->logger->debug_ip = radix_tree_create (); - if (!add_map (rspamd->cfg->debug_ip_map, read_radix_list, fin_radix_list, (void **)&rspamd->logger->debug_ip)) { + if (!add_map (rspamd->cfg, rspamd->cfg->debug_ip_map, read_radix_list, fin_radix_list, (void **)&rspamd->logger->debug_ip)) { /* Try to parse it as list */ strvec = g_strsplit_set (rspamd->cfg->debug_ip_map, ",; ", 0); num = g_strv_length (strvec); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index d6db81309..ba9dfab37 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -567,7 +567,7 @@ lua_config_add_radix_map (lua_State *L) map_line = luaL_checkstring (L, 2); r = memory_pool_alloc (cfg->cfg_pool, sizeof (radix_tree_t *)); *r = radix_tree_create (); - if (!add_map (map_line, read_radix_list, fin_radix_list, (void **)r)) { + if (!add_map (cfg, map_line, read_radix_list, fin_radix_list, (void **)r)) { msg_warn ("invalid radix map %s", map_line); radix_tree_free (*r); lua_pushnil (L); @@ -596,7 +596,7 @@ lua_config_add_hash_map (lua_State *L) map_line = luaL_checkstring (L, 2); r = memory_pool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); - if (!add_map (map_line, read_host_list, fin_host_list, (void **)r)) { + if (!add_map (cfg, map_line, read_host_list, fin_host_list, (void **)r)) { msg_warn ("invalid hash map %s", map_line); g_hash_table_destroy (*r); lua_pushnil (L); @@ -626,7 +626,7 @@ lua_config_add_kv_map (lua_State *L) map_line = luaL_checkstring (L, 2); r = memory_pool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); - if (!add_map (map_line, read_kv_list, fin_kv_list, (void **)r)) { + if (!add_map (cfg, map_line, read_kv_list, fin_kv_list, (void **)r)) { msg_warn ("invalid hash map %s", map_line); g_hash_table_destroy (*r); lua_pushnil (L); diff --git a/src/lua_worker.c b/src/lua_worker.c index 51066624b..c75d275a6 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -493,7 +493,7 @@ start_lua_worker (struct rspamd_worker *worker) } /* Maps events */ - start_map_watch (ctx->ev_base); + start_map_watch (worker->srv->cfg, ctx->ev_base); event_base_loop (ctx->ev_base, 0); luaL_unref (L, LUA_REGISTRYINDEX, ctx->cbref_accept); diff --git a/src/main.c b/src/main.c index e00a3f9da..8bdcc5979 100644 --- a/src/main.c +++ b/src/main.c @@ -675,51 +675,6 @@ reopen_log_handler (gpointer key, gpointer value, gpointer unused) } } -#if 0 -/* XXX: remove this as it is unused now */ -static gboolean -convert_old_config (struct rspamd_main *rspamd) -{ - FILE *f; - - f = fopen (rspamd->cfg->cfg_name, "r"); - if (f == NULL) { - msg_err ("cannot open file: %s", rspamd->cfg->cfg_name); - return EBADF; - } - yyin = f; - - yacc_cfg = rspamd->cfg; - if (yyparse () != 0 || yynerrs > 0) { - msg_err ("cannot parse config file, %d errors", yynerrs); - return EBADF; - } - - /* Strictly set temp dir */ - if (!rspamd->cfg->temp_dir) { - msg_warn ("tempdir is not set, trying to use $TMPDIR"); - rspamd->cfg->temp_dir = memory_pool_strdup (rspamd->cfg->cfg_pool, getenv ("TMPDIR")); - - if (!rspamd->cfg->temp_dir) { - msg_warn ("$TMPDIR is empty too, using /tmp as default"); - rspamd->cfg->temp_dir = memory_pool_strdup (rspamd->cfg->cfg_pool, "/tmp"); - } - } - - - fclose (f); - /* Dump it to xml */ - if (get_config_checksum (rspamd->cfg)) { - if (xml_dump_config (rspamd->cfg, convert_config)) { - rspamd->cfg->cfg_name = convert_config; - return TRUE; - } - } - - return FALSE; -} -#endif - static void preload_statfiles (struct rspamd_main *rspamd) { @@ -1121,7 +1076,7 @@ main (gint argc, gchar **argv, gchar **env) reopen_log_priv (rspamd_main->logger, rspamd_main->workers_uid, rspamd_main->workers_gid); msg_info ("rspamd " RVERSION " is restarting"); g_hash_table_foreach (rspamd_main->workers, kill_old_workers, NULL); - remove_all_maps (); + remove_all_maps (rspamd_main->cfg); reread_config (rspamd_main); spawn_workers (rspamd_main); } diff --git a/src/map.c b/src/map.c index 1b1b2ffbb..0bc5b92ac 100644 --- a/src/map.c +++ b/src/map.c @@ -31,10 +31,7 @@ #include "util.h" #include "mem_pool.h" -static memory_pool_t *map_pool = NULL; - -static GList *maps = NULL; -static gchar *hash_fill = "1"; +static const gchar *hash_fill = "1"; /* Http reply */ struct http_reply { @@ -58,7 +55,7 @@ struct http_callback_data { }; /* Value in seconds after whitch we would try to do stat on list file */ -#define MON_TIMEOUT 10 + /* HTTP timeouts */ #define HTTP_CONNECT_TIMEOUT 2 #define HTTP_READ_TIMEOUT 10 @@ -466,6 +463,11 @@ check_map_proto (const gchar *map_line, gint *res, const gchar **pos) *pos = map_line + sizeof ("file://") - 1; } } + else if (*map_line == '/') { + /* Trivial file case */ + *res = PROTO_FILE; + *pos = map_line; + } else { msg_warn ("invalid map fetching protocol: %s", map_line); return FALSE; @@ -475,7 +477,7 @@ check_map_proto (const gchar *map_line, gint *res, const gchar **pos) } gboolean -add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data) +add_map (struct config_file *cfg, const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data) { struct rspamd_map *new_map; enum fetch_proto proto; @@ -491,10 +493,10 @@ add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callbac return FALSE; } /* Constant pool */ - if (map_pool == NULL) { - map_pool = memory_pool_new (memory_pool_get_size ()); + if (cfg->map_pool == NULL) { + cfg->map_pool = memory_pool_new (memory_pool_get_size ()); } - new_map = memory_pool_alloc0 (map_pool, sizeof (struct rspamd_map)); + new_map = memory_pool_alloc0 (cfg->map_pool, sizeof (struct rspamd_map)); new_map->read_callback = read_callback; new_map->fin_callback = fin_callback; new_map->user_data = user_data; @@ -506,13 +508,13 @@ add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callbac msg_warn ("cannot open file '%s': %s", def, strerror (errno)); return FALSE; } - fdata = memory_pool_alloc0 (map_pool, sizeof (struct file_map_data)); - fdata->filename = memory_pool_strdup (map_pool, def); + fdata = memory_pool_alloc0 (cfg->map_pool, sizeof (struct file_map_data)); + fdata->filename = memory_pool_strdup (cfg->map_pool, def); fstat (fd, &fdata->st); new_map->map_data = fdata; } else if (proto == PROTO_HTTP) { - hdata = memory_pool_alloc0 (map_pool, sizeof (struct http_map_data)); + hdata = memory_pool_alloc0 (cfg->map_pool, sizeof (struct http_map_data)); /* Try to search port */ if ((p = strchr (def, ':')) != NULL) { hostend = p; @@ -538,9 +540,9 @@ add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callbac } hostend = p; } - hdata->host = memory_pool_alloc (map_pool, hostend - def + 1); + hdata->host = memory_pool_alloc (cfg->map_pool, hostend - def + 1); rspamd_strlcpy (hdata->host, def, hostend - def + 1); - hdata->path = memory_pool_strdup (map_pool, p); + hdata->path = memory_pool_strdup (cfg->map_pool, p); hdata->rlen = 0; /* Now try to resolve */ if (!inet_aton (hdata->host, &hdata->addr)) { @@ -565,7 +567,7 @@ add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callbac /* Temp pool */ new_map->pool = memory_pool_new (memory_pool_get_size ()); - maps = g_list_prepend (maps, new_map); + cfg->maps = g_list_prepend (cfg->maps, new_map); return TRUE; } @@ -879,7 +881,7 @@ file_callback (gint fd, short what, void *ud) /* Plan event again with jitter */ evtimer_del (&map->ev); - map->tv.tv_sec = MON_TIMEOUT + MON_TIMEOUT * g_random_double (); + map->tv.tv_sec = (map->cfg->map_timeout + map->cfg->map_timeout * g_random_double ()) / 2.; map->tv.tv_usec = 0; evtimer_add (&map->ev, &map->tv); @@ -1000,7 +1002,7 @@ http_callback (gint fd, short what, void *ud) /* Plan event again with jitter */ evtimer_del (&map->ev); - map->tv.tv_sec = MON_TIMEOUT + MON_TIMEOUT * g_random_double (); + map->tv.tv_sec = map->cfg->map_timeout + map->cfg->map_timeout * g_random_double (); map->tv.tv_usec = 0; evtimer_add (&map->ev, &map->tv); @@ -1027,9 +1029,9 @@ http_callback (gint fd, short what, void *ud) /* Start watching event for all maps */ void -start_map_watch (struct event_base *ev_base) +start_map_watch (struct config_file *cfg, struct event_base *ev_base) { - GList *cur = maps; + GList *cur = cfg->maps; struct rspamd_map *map; /* First of all do synced read of data */ @@ -1042,7 +1044,7 @@ start_map_watch (struct event_base *ev_base) /* Read initial data */ read_map_file (map, map->map_data); /* Plan event with jitter */ - map->tv.tv_sec = MON_TIMEOUT + MON_TIMEOUT * g_random_double (); + map->tv.tv_sec = (map->cfg->map_timeout + map->cfg->map_timeout * g_random_double ()) / 2.; map->tv.tv_usec = 0; evtimer_add (&map->ev, &map->tv); } @@ -1052,7 +1054,7 @@ start_map_watch (struct event_base *ev_base) /* Read initial data */ read_http_sync (map, map->map_data); /* Plan event with jitter */ - map->tv.tv_sec = MON_TIMEOUT + MON_TIMEOUT * g_random_double (); + map->tv.tv_sec = (map->cfg->map_timeout + map->cfg->map_timeout * g_random_double ()); map->tv.tv_usec = 0; evtimer_add (&map->ev, &map->tv); } @@ -1061,13 +1063,13 @@ start_map_watch (struct event_base *ev_base) } void -remove_all_maps (void) +remove_all_maps (struct config_file *cfg) { - g_list_free (maps); - maps = NULL; - if (map_pool != NULL) { - memory_pool_delete (map_pool); - map_pool = NULL; + g_list_free (cfg->maps); + cfg->maps = NULL; + if (cfg->map_pool != NULL) { + memory_pool_delete (cfg->map_pool); + cfg->map_pool = NULL; } } diff --git a/src/map.h b/src/map.h index f4aae10ce..69fe5f87c 100644 --- a/src/map.h +++ b/src/map.h @@ -58,8 +58,10 @@ typedef void (*map_fin_cb_t)(memory_pool_t *pool, struct map_cb_data *data); /** * Common map object */ +struct config_file; struct rspamd_map { memory_pool_t *pool; + struct config_file *cfg; enum fetch_proto protocol; map_cb_t read_callback; map_fin_cb_t fin_callback; @@ -77,19 +79,19 @@ gboolean check_map_proto (const gchar *map_line, gint *res, const gchar **pos); /** * Add map from line */ -gboolean add_map (const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data); +gboolean add_map (struct config_file *cfg, const gchar *map_line, map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data); /** * Start watching of maps by adding events to libevent event loop */ -void start_map_watch (struct event_base *ev_base); +void start_map_watch (struct config_file *cfg, struct event_base *ev_base); /** * Remove all maps watched (remove events) */ -void remove_all_maps (void); +void remove_all_maps (struct config_file *cfg); -typedef void (*insert_func) (gpointer st, gconstpointer key, gpointer value); +typedef void (*insert_func) (gpointer st, gconstpointer key, gconstpointer value); /** * Common callbacks for frequent types of lists diff --git a/src/mem_pool.c b/src/mem_pool.c index 6038ff604..f7636e538 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -613,6 +613,7 @@ memory_pool_delete (memory_pool_t * pool) mem_pool_stat->pools_freed++; POOL_MTX_UNLOCK (); rspamd_mutex_free (pool->mtx); + g_slice_free (memory_pool_t, pool); } void diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index ef494a736..7bb32db55 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -158,12 +158,12 @@ dkim_module_config (struct config_file *cfg) dkim_module_ctx->time_jitter = DEFAULT_TIME_JITTER; } if ((value = get_module_opt (cfg, "dkim", "whitelist")) != NULL) { - if (! add_map (value, read_radix_list, fin_radix_list, (void **)&dkim_module_ctx->whitelist_ip)) { + if (! add_map (cfg, value, read_radix_list, fin_radix_list, (void **)&dkim_module_ctx->whitelist_ip)) { msg_warn ("cannot load whitelist from %s", value); } } if ((value = get_module_opt (cfg, "dkim", "domains")) != NULL) { - if (! add_map (value, read_kv_list, fin_kv_list, (void **)&dkim_module_ctx->dkim_domains)) { + if (! add_map (cfg, value, read_kv_list, fin_kv_list, (void **)&dkim_module_ctx->dkim_domains)) { msg_warn ("cannot load dkim domains list from %s", value); } else { diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 51bdd58c3..2f61ac1b3 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -419,7 +419,7 @@ fuzzy_check_module_config (struct config_file *cfg) if ((value = get_module_opt (cfg, "fuzzy_check", "whitelist")) != NULL) { fuzzy_module_ctx->whitelist = radix_tree_create (); - if (!add_map (value, read_radix_list, fin_radix_list, (void **)&fuzzy_module_ctx->whitelist)) { + if (!add_map (cfg, value, read_radix_list, fin_radix_list, (void **)&fuzzy_module_ctx->whitelist)) { msg_err ("cannot add whitelist '%s'", value); } } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index f8d1fb7fc..f5c94bd1f 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -611,7 +611,7 @@ regexp_module_config (struct config_file *cfg) jb->buf = NULL; jb->cfg = cfg; *pjb = jb; - if (!add_map (value, json_regexp_read_cb, json_regexp_fin_cb, (void **)pjb)) { + if (!add_map (cfg, value, json_regexp_read_cb, json_regexp_fin_cb, (void **)pjb)) { msg_err ("cannot add map %s", value); } } diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 3502aba38..d10498699 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -138,7 +138,7 @@ spf_module_config (struct config_file *cfg) cache_expire = DEFAULT_CACHE_MAXAGE; } if ((value = get_module_opt (cfg, "spf", "whitelist")) != NULL) { - if (! add_map (value, read_radix_list, fin_radix_list, (void **)&spf_module_ctx->whitelist_ip)) { + if (! add_map (cfg, value, read_radix_list, fin_radix_list, (void **)&spf_module_ctx->whitelist_ip)) { msg_warn ("cannot load whitelist from %s", value); } } diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 3d128b90d..18b8441ea 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -363,7 +363,7 @@ surbl_module_config (struct config_file *cfg) surbl_module_ctx->read_timeout = DEFAULT_REDIRECTOR_READ_TIMEOUT; } if ((value = get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) { - add_map (value, read_redirectors_list, fin_redirectors_list, (void **)&surbl_module_ctx->redirector_hosts); + add_map (cfg, value, read_redirectors_list, fin_redirectors_list, (void **)&surbl_module_ctx->redirector_hosts); } else { surbl_module_ctx->read_timeout = DEFAULT_REDIRECTOR_READ_TIMEOUT; @@ -375,12 +375,12 @@ surbl_module_config (struct config_file *cfg) surbl_module_ctx->max_urls = DEFAULT_SURBL_MAX_URLS; } if ((value = get_module_opt (cfg, "surbl", "exceptions")) != NULL) { - if (add_map (value, read_exceptions_list, fin_exceptions_list, (void **)&surbl_module_ctx->exceptions)) { + if (add_map (cfg, value, read_exceptions_list, fin_exceptions_list, (void **)&surbl_module_ctx->exceptions)) { surbl_module_ctx->tld2_file = memory_pool_strdup (surbl_module_ctx->surbl_pool, value + sizeof ("file://") - 1); } } if ((value = get_module_opt (cfg, "surbl", "whitelist")) != NULL) { - if (add_map (value, read_host_list, fin_host_list, (void **)&surbl_module_ctx->whitelist)) { + if (add_map (cfg, value, read_host_list, fin_host_list, (void **)&surbl_module_ctx->whitelist)) { surbl_module_ctx->whitelist_file = memory_pool_strdup (surbl_module_ctx->surbl_pool, value + sizeof ("file://") - 1); } } diff --git a/src/protocol.c b/src/protocol.c index 7df9ae673..a9c2638ef 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -598,7 +598,6 @@ parse_header (struct worker_task *task, f_str_t * line) case 'u': case 'U': if (g_ascii_strncasecmp (headern, USER_HEADER, sizeof (USER_HEADER) - 1) == 0) { - /* XXX: use this header somehow */ task->user = memory_pool_fstrdup (task->task_pool, line); } else { @@ -1417,7 +1416,6 @@ write_check_reply (struct worker_task *task) } } else { - /* XXX: add this for JSON as well */ /* Messages */ if (! show_messages (task)) { return FALSE; diff --git a/src/settings.c b/src/settings.c index 8bc784332..d21fe02d0 100644 --- a/src/settings.c +++ b/src/settings.c @@ -358,7 +358,7 @@ read_settings (const gchar *path, struct config_file *cfg, GHashTable * table) jb->buf = NULL; *pjb = jb; - if (!add_map (path, json_read_cb, json_fin_cb, (void **)pjb)) { + if (!add_map (cfg, path, json_read_cb, json_fin_cb, (void **)pjb)) { msg_err ("cannot add map %s", path); return FALSE; } diff --git a/src/smtp.c b/src/smtp.c index c1e8765e4..075e1b663 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -977,7 +977,7 @@ start_smtp (struct rspamd_worker *worker) event_add (&worker->bind_ev, NULL); /* Maps events */ - start_map_watch (ctx->ev_base); + start_map_watch (worker->srv->cfg, ctx->ev_base); /* DNS resolver */ ctx->resolver = dns_resolver_init (ctx->ev_base, worker->srv->cfg); diff --git a/src/view.c b/src/view.c index 5fb1576a8..b0d16dd5b 100644 --- a/src/view.c +++ b/src/view.c @@ -31,7 +31,7 @@ #include "map.h" struct rspamd_view * -init_view (memory_pool_t * pool) +init_view (struct config_file *cfg, memory_pool_t * pool) { struct rspamd_view *new; @@ -43,6 +43,7 @@ init_view (memory_pool_t * pool) new->rcpt_hash = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); new->ip_tree = radix_tree_create (); new->client_ip_tree = radix_tree_create (); + new->cfg = cfg; memory_pool_add_destructor (new->pool, (pool_destruct_func) g_hash_table_destroy, new->symbols_hash); @@ -54,7 +55,7 @@ add_view_from (struct rspamd_view * view, gchar *line) { struct rspamd_regexp *re = NULL; - if (add_map (line, read_host_list, fin_host_list, (void **)&view->from_hash)) { + if (add_map (view->cfg, line, read_host_list, fin_host_list, (void **)&view->from_hash)) { return TRUE; } else if ((re = parse_regexp (view->pool, line, TRUE)) != NULL) { @@ -70,7 +71,7 @@ add_view_rcpt (struct rspamd_view * view, gchar *line) { struct rspamd_regexp *re = NULL; - if (add_map (line, read_host_list, fin_host_list, (void **)&view->rcpt_hash)) { + if (add_map (view->cfg, line, read_host_list, fin_host_list, (void **)&view->rcpt_hash)) { return TRUE; } else if ((re = parse_regexp (view->pool, line, TRUE)) != NULL) { @@ -87,7 +88,7 @@ add_view_symbols (struct rspamd_view * view, gchar *line) struct rspamd_regexp *re = NULL; GList *symbols; - if (add_map (line, read_host_list, fin_host_list, (void **)&view->symbols_hash)) { + if (add_map (view->cfg, line, read_host_list, fin_host_list, (void **)&view->symbols_hash)) { return TRUE; } else if ((re = parse_regexp (view->pool, line, TRUE)) != NULL) { @@ -111,7 +112,7 @@ add_view_symbols (struct rspamd_view * view, gchar *line) gboolean add_view_ip (struct rspamd_view * view, gchar *line) { - if (add_map (line, read_radix_list, fin_radix_list, (void **)&view->ip_tree)) { + if (add_map (view->cfg, line, read_radix_list, fin_radix_list, (void **)&view->ip_tree)) { return TRUE; } @@ -121,7 +122,7 @@ add_view_ip (struct rspamd_view * view, gchar *line) gboolean add_view_client_ip (struct rspamd_view * view, gchar *line) { - if (add_map (line, read_radix_list, fin_radix_list, (void **)&view->client_ip_tree)) { + if (add_map (view->cfg, line, read_radix_list, fin_radix_list, (void **)&view->client_ip_tree)) { return TRUE; } diff --git a/src/view.h b/src/view.h index f62c65198..f36f2e1b4 100644 --- a/src/view.h +++ b/src/view.h @@ -7,7 +7,9 @@ #include "main.h" #include "radix.h" +struct config_file; struct rspamd_view { + struct config_file *cfg; GList *from_re_list; GHashTable *from_hash; @@ -30,7 +32,7 @@ struct rspamd_view { * @param pool pool for view * @return */ -struct rspamd_view* init_view (memory_pool_t *pool); +struct rspamd_view* init_view (struct config_file *cfg, memory_pool_t *pool); /** * Add from option for this view diff --git a/src/worker.c b/src/worker.c index c69f3a9e6..ce4041897 100644 --- a/src/worker.c +++ b/src/worker.c @@ -827,7 +827,7 @@ start_worker (struct rspamd_worker *worker) else { #endif /* Maps events */ - start_map_watch (ctx->ev_base); + start_map_watch (worker->srv->cfg, ctx->ev_base); #ifndef BUILD_STATIC } #endif