]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Adopt plugins for new maps API
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 May 2016 14:29:05 +0000 (15:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 May 2016 14:29:05 +0000 (15:29 +0100)
src/controller.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/spf.c
src/plugins/surbl.c

index 62e2e8dd513757ee0a860f0c2526fc0d27644dea..8b16eda19302f1cb26bc1356e19b6865b5335fda 100644 (file)
@@ -145,7 +145,7 @@ struct rspamd_controller_worker_ctx {
        /* SSL private key */
        gchar *ssl_key;
        /* A map of secure IP */
-       GList *secure_ip;
+       const ucl_object_t *secure_ip;
        radix_compressed_t *secure_map;
 
        /* Static files dir */
@@ -2490,7 +2490,7 @@ init_controller_worker (struct rspamd_config *cfg)
        rspamd_rcl_register_worker_option (cfg,
                        type,
                        "secure_ip",
-                       rspamd_rcl_parse_struct_string_list,
+                       rspamd_rcl_parse_struct_ucl,
                        ctx,
                        G_STRUCT_OFFSET (struct rspamd_controller_worker_ctx, secure_ip),
                        0,
@@ -2499,7 +2499,7 @@ init_controller_worker (struct rspamd_config *cfg)
        rspamd_rcl_register_worker_option (cfg,
                        type,
                        "trusted_ips",
-                       rspamd_rcl_parse_struct_string_list,
+                       rspamd_rcl_parse_struct_ucl,
                        ctx,
                        G_STRUCT_OFFSET (struct rspamd_controller_worker_ctx, secure_ip),
                        0,
@@ -2545,12 +2545,12 @@ void
 start_controller_worker (struct rspamd_worker *worker)
 {
        struct rspamd_controller_worker_ctx *ctx = worker->ctx;
-       GList *cur;
        struct module_ctx *mctx;
        GHashTableIter iter;
        gpointer key, value;
        struct rspamd_keypair_cache *cache;
-       gchar *secure_ip;
+       const ucl_object_t *cur;
+       ucl_object_iter_t it = NULL;
        gpointer m;
 
        ctx->ev_base = rspamd_prepare_worker (worker,
@@ -2565,26 +2565,31 @@ start_controller_worker (struct rspamd_worker *worker)
        ctx->custom_commands = g_hash_table_new (rspamd_strcase_hash,
                        rspamd_strcase_equal);
        if (ctx->secure_ip != NULL) {
-               cur = ctx->secure_ip;
 
-               while (cur) {
-                       secure_ip = cur->data;
-
-                       /* Try map syntax */
-                       if (!rspamd_map_is_map (secure_ip)) {
-                               if (!radix_add_generic_iplist (secure_ip,
-                                               &ctx->secure_map)) {
-                                       msg_warn_ctx ("cannot load or parse ip list from '%s'",
-                                                       secure_ip);
+               if (ucl_object_type (ctx->secure_ip) == UCL_ARRAY) {
+                       while ((cur = ucl_object_iterate (ctx->secure_ip, &it, true)) != NULL) {
+                               /* Try map syntax */
+                               if (ucl_object_type (cur) == UCL_STRING &&
+                                               !rspamd_map_is_map (ucl_object_tostring (cur))) {
+                                       if (!radix_add_generic_iplist (ucl_object_tostring (cur),
+                                                       &ctx->secure_map)) {
+                                               msg_warn_ctx ("cannot load or parse ip list from '%s'",
+                                                               ucl_object_tostring (cur));
+                                       }
+                               }
+                               else {
+                                       rspamd_map_add_from_ucl (worker->srv->cfg, cur,
+                                                       "Allow webui access from the specified IP",
+                                                       rspamd_radix_read, rspamd_radix_fin,
+                                                       (void **)&ctx->secure_map);
                                }
                        }
-                       else {
-                               rspamd_map_add (worker->srv->cfg, secure_ip,
+               }
+               else {
+                       rspamd_map_add_from_ucl (worker->srv->cfg, ctx->secure_ip,
                                        "Allow webui access from the specified IP",
                                        rspamd_radix_read, rspamd_radix_fin,
                                        (void **)&ctx->secure_map);
-                       }
-                       cur = g_list_next (cur);
                }
        }
 
index 9cf89674edce8878bcdf4917c931931d24dbc9d6..3ea31485fe20ba912ba9ccc807f19187b076d9e3 100644 (file)
@@ -271,13 +271,14 @@ dkim_module_config (struct rspamd_config *cfg)
        }
        if ((value =
                rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) {
+
                str = ucl_obj_tostring (value);
-               if (!rspamd_map_is_map (str)) {
+               if (str && !rspamd_map_is_map (str)) {
                        radix_add_generic_iplist (str,
                                        &dkim_module_ctx->whitelist_ip);
                }
                else {
-                       rspamd_map_add (cfg, str,
+                       rspamd_map_add_from_ucl (cfg, value,
                                        "DKIM whitelist", rspamd_radix_read, rspamd_radix_fin,
                                        (void **)&dkim_module_ctx->whitelist_ip);
 
@@ -285,7 +286,7 @@ dkim_module_config (struct rspamd_config *cfg)
        }
        if ((value =
                rspamd_config_get_module_opt (cfg, "dkim", "domains")) != NULL) {
-               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
+               if (!rspamd_map_add_from_ucl (cfg, value,
                        "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin,
                        (void **)&dkim_module_ctx->dkim_domains)) {
                        msg_warn_config ("cannot load dkim domains list from %s",
@@ -297,7 +298,7 @@ dkim_module_config (struct rspamd_config *cfg)
        }
        if (!got_trusted && (value =
                        rspamd_config_get_module_opt (cfg, "dkim", "trusted_domains")) != NULL) {
-               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
+               if (!rspamd_map_add_from_ucl (cfg, value,
                                "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin,
                                (void **)&dkim_module_ctx->dkim_domains)) {
                        msg_warn_config ("cannot load dkim domains list from %s",
index 385b8aadcc8ae795803823f21be6778f2c1a21fd..a5b62875e7e29403911864db6a654c080c7bf721 100644 (file)
@@ -832,12 +832,12 @@ fuzzy_check_module_config (struct rspamd_config *cfg)
 
                str = ucl_obj_tostring (value);
 
-               if (!rspamd_map_is_map (str)) {
+               if (str && !rspamd_map_is_map (str)) {
                        radix_add_generic_iplist (str,
                                        &fuzzy_module_ctx->whitelist);
                }
                else {
-                       rspamd_map_add (cfg, str,
+                       rspamd_map_add_from_ucl (cfg, value,
                                        "Fuzzy whitelist", rspamd_radix_read, rspamd_radix_fin,
                                        (void **)&fuzzy_module_ctx->whitelist);
 
index 153422f510bb75f4846c192128c6d0379335b0fb..67c8732e7c52613d48e65601653785e770171709 100644 (file)
@@ -213,12 +213,12 @@ spf_module_config (struct rspamd_config *cfg)
 
                str = ucl_obj_tostring (value);
 
-               if (!rspamd_map_is_map (str)) {
+               if (str && !rspamd_map_is_map (str)) {
                        radix_add_generic_iplist (str,
                                        &spf_module_ctx->whitelist_ip);
                }
                else {
-                       rspamd_map_add (cfg, str,
+                       rspamd_map_add_from_ucl (cfg, value,
                                        "SPF whitelist", rspamd_radix_read, rspamd_radix_fin,
                                        (void **)&spf_module_ctx->whitelist_ip);
 
index 35383c829ef84c8e0da9828f40938d38d4507bc3..87b8effa733c6f5b77903a7259870561d4c7bf3e 100644 (file)
@@ -528,7 +528,7 @@ surbl_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "surbl",
                "redirector_hosts_map")) != NULL) {
-               if (!rspamd_map_add (cfg, ucl_obj_tostring (value),
+               if (!rspamd_map_add_from_ucl (cfg, value,
                        "SURBL redirectors list", read_redirectors_list, fin_redirectors_list,
                        (void **)&surbl_module_ctx->redirector_map_data)) {
 
@@ -546,7 +546,7 @@ surbl_module_config (struct rspamd_config *cfg)
        }
        if ((value =
                rspamd_config_get_module_opt (cfg, "surbl", "exceptions")) != NULL) {
-               if (rspamd_map_add (cfg, ucl_obj_tostring (value),
+               if (rspamd_map_add_from_ucl (cfg, value,
                        "SURBL exceptions list", read_exceptions_list, fin_exceptions_list,
                        (void **)&surbl_module_ctx->exceptions)) {
                        surbl_module_ctx->tld2_file = rspamd_mempool_strdup (
@@ -556,7 +556,7 @@ surbl_module_config (struct rspamd_config *cfg)
        }
        if ((value =
                        rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
-               if (rspamd_map_add (cfg, ucl_obj_tostring (value),
+               if (rspamd_map_add_from_ucl (cfg, value,
                        "SURBL whitelist", rspamd_hosts_read, rspamd_hosts_fin,
                        (void **)&surbl_module_ctx->whitelist)) {
                        surbl_module_ctx->whitelist_file = rspamd_mempool_strdup (