From: Vsevolod Stakhov Date: Fri, 28 Feb 2014 17:31:45 +0000 (+0000) Subject: Add an utility to parse IP tree from a string. X-Git-Tag: 0.6.9~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70cbdb19bb3834365fe3b0e497e4761dd8def28b;p=thirdparty%2Frspamd.git Add an utility to parse IP tree from a string. Conflicts: src/webui.c --- diff --git a/src/cfg_file.h b/src/cfg_file.h index 6f3489455c..9908868a2d 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -505,6 +505,11 @@ gboolean check_classifier_statfiles (struct classifier_config *cf); */ struct classifier_config* find_classifier_conf (struct config_file *cfg, const gchar *name); +/* + * Parse input `ip_list` to radix tree `tree`. Now supports only IPv4 addresses. + */ +gboolean rspamd_parse_ip_list (const gchar *ip_list, radix_tree_t **tree); + #endif /* ifdef CFG_FILE_H */ /* * vi:ts=4 diff --git a/src/cfg_utils.c b/src/cfg_utils.c index eb2bfdd9d7..d2e61cbfd7 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -994,6 +994,30 @@ rspamd_ucl_fin_cb (memory_pool_t * pool, struct map_cb_data *data) } } +gboolean +rspamd_parse_ip_list (const gchar *ip_list, radix_tree_t **tree) +{ + gchar **strvec, **cur; + struct in_addr ina; + guint32 mask; + + strvec = g_strsplit_set (ip_list, ",", 0); + cur = strvec; + + while (*cur != NULL) { + /* XXX: handle only ipv4 addresses */ + if (parse_ipmask_v4 (*cur, &ina, &mask)) { + if (*tree == NULL) { + *tree = radix_tree_create (); + } + radix32tree_add (*tree, htonl (ina.s_addr), mask, 1); + } + cur ++; + } + + return (*tree != NULL); +} + /* * vi:ts=4 */ diff --git a/src/webui.c b/src/webui.c index 24271e0abf..28c3e85761 100644 --- a/src/webui.c +++ b/src/webui.c @@ -1772,6 +1772,9 @@ start_webui_worker (struct rspamd_worker *worker) ctx->start_time = time (NULL); ctx->worker = worker; + ctx->cfg = worker->srv->cfg; + ctx->srv = worker->srv; + /* Accept event */ ctx->http = evhttp_new (ctx->ev_base);