]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to set custom mempool variables from settings
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jul 2017 07:46:30 +0000 (08:46 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Jul 2017 07:46:30 +0000 (08:46 +0100)
src/lua/lua_task.c

index de5e57e7e1c2b9a9ef3cc066ebfd70d6e084c576..26f3da5adfd9bc305066853a3268eb1812347b15 100644 (file)
@@ -3480,7 +3480,8 @@ lua_task_set_settings (lua_State *L)
 {
        struct rspamd_task *task = lua_check_task (L, 1);
        ucl_object_t *settings;
-       const ucl_object_t *act, *elt, *metric_elt;
+       const ucl_object_t *act, *elt, *metric_elt, *vars, *cur;
+       ucl_object_iter_t it = NULL;
        struct rspamd_metric_result *mres;
        guint i;
 
@@ -3520,6 +3521,20 @@ lua_task_set_settings (lua_State *L)
                        }
                }
 
+               vars = ucl_object_lookup (task->settings, "variables");
+               if (vars && ucl_object_type (vars) == UCL_OBJECT) {
+                       /* Set memory pool variables */
+                       while ((cur = ucl_object_iterate (vars, &it, true)) != NULL) {
+                               if (ucl_object_type (cur) == UCL_STRING) {
+                                       rspamd_mempool_set_variable (task->task_pool,
+                                                       ucl_object_key (cur), rspamd_mempool_strdup (
+                                                                       task->task_pool,
+                                                                       ucl_object_tostring (cur)
+                                                       ), NULL);
+                               }
+                       }
+               }
+
                rspamd_symbols_cache_process_settings (task, task->cfg->cache);
        }
        else {