aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/dynamic_cfg.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-25 10:07:49 +0200
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-25 10:08:06 +0200
commit0edaed34e4377c4cd06e2a28d14d9117499c1826 (patch)
tree43729bdd372521fe07798190650041fbe0799886 /src/libserver/dynamic_cfg.c
parent0758d1ea48a275214b79fc64908901d469e17b89 (diff)
downloadrspamd-0edaed34e4377c4cd06e2a28d14d9117499c1826.tar.gz
rspamd-0edaed34e4377c4cd06e2a28d14d9117499c1826.zip
[Feature] Allow to update dynamic conf in Redis
Diffstat (limited to 'src/libserver/dynamic_cfg.c')
-rw-r--r--src/libserver/dynamic_cfg.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c
index d31418588..56b7b17f0 100644
--- a/src/libserver/dynamic_cfg.c
+++ b/src/libserver/dynamic_cfg.c
@@ -19,6 +19,7 @@
#include "filter.h"
#include "dynamic_cfg.h"
#include "unix-std.h"
+#include "lua/lua_common.h"
struct config_json_buf {
GString *buf;
@@ -393,6 +394,102 @@ new_dynamic_elt (ucl_object_t *arr, const gchar *name, gdouble value)
return n;
}
+static gboolean
+rspamd_maybe_add_lua_dynsym (struct rspamd_config *cfg,
+ const gchar *sym,
+ gdouble score)
+{
+ lua_State *L = cfg->lua_state;
+ gboolean ret = FALSE;
+ struct rspamd_config **pcfg;
+
+ lua_getglobal (L, "rspamd_plugins");
+ if (lua_type (L, -1) == LUA_TTABLE) {
+ lua_pushstring (L, "dynamic_conf");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TTABLE) {
+ lua_pushstring (L, "add_symbol");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TFUNCTION) {
+ pcfg = lua_newuserdata (L, sizeof (*pcfg));
+ *pcfg = cfg;
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
+ lua_pushstring (L, sym);
+ lua_pushnumber (L, score);
+
+ if (lua_pcall (L, 3, 1, 0) != 0) {
+ msg_err_config ("cannot execute add_symbol script: %s",
+ lua_tostring (L, -1));
+ }
+ else {
+ ret = lua_toboolean (L, -1);
+ }
+
+ lua_pop (L, 1);
+ }
+ else {
+ lua_pop (L, 1);
+ }
+ }
+
+ lua_pop (L, 1);
+ }
+
+ lua_pop (L, 1);
+
+ return ret;
+}
+
+static gboolean
+rspamd_maybe_add_lua_dynact (struct rspamd_config *cfg,
+ const gchar *action,
+ gdouble score)
+{
+ lua_State *L = cfg->lua_state;
+ gboolean ret = FALSE;
+ struct rspamd_config **pcfg;
+
+ lua_getglobal (L, "rspamd_plugins");
+ if (lua_type (L, -1) == LUA_TTABLE) {
+ lua_pushstring (L, "dynamic_conf");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TTABLE) {
+ lua_pushstring (L, "add_action");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TFUNCTION) {
+ pcfg = lua_newuserdata (L, sizeof (*pcfg));
+ *pcfg = cfg;
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
+ lua_pushstring (L, action);
+ lua_pushnumber (L, score);
+
+ if (lua_pcall (L, 3, 1, 0) != 0) {
+ msg_err_config ("cannot execute add_action script: %s",
+ lua_tostring (L, -1));
+ }
+ else {
+ ret = lua_toboolean (L, -1);
+ }
+
+ lua_pop (L, 1);
+ }
+ else {
+ lua_pop (L, 1);
+ }
+ }
+
+ lua_pop (L, 1);
+ }
+
+ lua_pop (L, 1);
+
+ return ret;
+}
+
/**
* Add symbol for specified metric
* @param cfg config file object
@@ -409,6 +506,10 @@ add_dynamic_symbol (struct rspamd_config *cfg,
{
ucl_object_t *metric, *syms;
+ if (rspamd_maybe_add_lua_dynsym (cfg, symbol, value)) {
+ return TRUE;
+ }
+
if (cfg->dynamic_conf == NULL) {
msg_info ("dynamic conf is disabled");
return FALSE;
@@ -497,6 +598,10 @@ add_dynamic_action (struct rspamd_config *cfg,
ucl_object_t *metric, *acts;
const gchar *action_name = rspamd_action_to_str (action);
+ if (rspamd_maybe_add_lua_dynact (cfg, action_name, value)) {
+ return TRUE;
+ }
+
if (cfg->dynamic_conf == NULL) {
msg_info ("dynamic conf is disabled");
return FALSE;