aboutsummaryrefslogtreecommitdiffstats
path: root/src/controller.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-08-14 15:00:01 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-08-14 15:00:01 +0100
commitbb516b454ff9842c214e5cb77d984f7fd0ea2da7 (patch)
treee7d45399a61201b961996c9de8827beb83bfae66 /src/controller.c
parent2778ec22a2ff4c81c7adcae657d39db08749851d (diff)
downloadrspamd-bb516b454ff9842c214e5cb77d984f7fd0ea2da7.tar.gz
rspamd-bb516b454ff9842c214e5cb77d984f7fd0ea2da7.zip
[Rework] More abstractions to hide C++ internals
Diffstat (limited to 'src/controller.c')
-rw-r--r--src/controller.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/controller.c b/src/controller.c
index 6f0611ec2..13e6794af 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -870,6 +870,20 @@ rspamd_controller_handle_symbols(struct rspamd_http_connection_entry *conn_ent,
return 0;
}
+static void
+rspamd_controller_actions_cb(struct rspamd_action *act, void *cbd)
+{
+ ucl_object_t *top = (ucl_object_t *) cbd;
+ ucl_object_t *obj = ucl_object_typed_new(UCL_OBJECT);
+ ucl_object_insert_key(obj,
+ ucl_object_fromstring(act->name),
+ "action", 0, false);
+ ucl_object_insert_key(obj,
+ ucl_object_fromdouble(act->threshold),
+ "value", 0, false);
+ ucl_array_append(top, obj);
+}
+
/*
* Actions command handler:
* request: /actions
@@ -884,8 +898,7 @@ rspamd_controller_handle_actions(struct rspamd_http_connection_entry *conn_ent,
struct rspamd_http_message *msg)
{
struct rspamd_controller_session *session = conn_ent->ud;
- struct rspamd_action *act, *tmp;
- ucl_object_t *obj, *top;
+ ucl_object_t *top;
if (!rspamd_controller_check_password(conn_ent, session, msg, FALSE)) {
return 0;
@@ -893,18 +906,7 @@ rspamd_controller_handle_actions(struct rspamd_http_connection_entry *conn_ent,
top = ucl_object_typed_new(UCL_ARRAY);
- HASH_ITER(hh, session->cfg->actions, act, tmp)
- {
- obj = ucl_object_typed_new(UCL_OBJECT);
- ucl_object_insert_key(obj,
- ucl_object_fromstring(act->name),
- "action", 0, false);
- ucl_object_insert_key(obj,
- ucl_object_fromdouble(act->threshold),
- "value", 0, false);
- ucl_array_append(top, obj);
- }
-
+ rspamd_config_actions_foreach(session->cfg, rspamd_controller_actions_cb, top);
rspamd_controller_send_ucl(conn_ent, top);
ucl_object_unref(top);
@@ -2300,8 +2302,10 @@ rspamd_controller_handle_saveactions(
score = ucl_object_todouble(cur);
}
- if ((isnan(session->cfg->actions[act].threshold) != isnan(score)) ||
- (session->cfg->actions[act].threshold != score)) {
+ struct rspamd_action *cfg_action = rspamd_config_get_action_by_type(ctx->cfg, act);
+
+ if (cfg_action && ((isnan(cfg_action->threshold) != isnan(score)) ||
+ (cfg_action->threshold != score))) {
add_dynamic_action(ctx->cfg, DEFAULT_METRIC, act, score);
added++;
}