commit bb516b4: [Rework] More abstractions to hide C++ internals
Vsevolod Stakhov
vsevolod at rspamd.com
Thu Aug 17 11:49:07 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-08-14 15:00:01 +0100
URL: https://github.com/rspamd/rspamd/commit/bb516b454ff9842c214e5cb77d984f7fd0ea2da7
[Rework] More abstractions to hide C++ internals
---
src/controller.c | 36 ++--
src/libmime/scan_result.c | 34 ++--
src/libserver/cfg_file.h | 26 +++
src/libserver/cfg_rcl.cxx | 485 ++++++++++++++++++++++----------------------
src/libserver/cfg_rcl.h | 20 +-
src/libserver/cfg_utils.cxx | 23 +++
src/lua/lua_config.c | 31 +--
src/lua/lua_task.c | 16 +-
8 files changed, 356 insertions(+), 315 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++;
}
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index a32c91280..ca17ad24b 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -56,6 +56,20 @@ rspamd_scan_result_dtor(gpointer d)
kh_destroy(rspamd_symbols_group_hash, r->sym_groups);
}
+static void
+rspamd_metric_actions_foreach_cb(int i, struct rspamd_action *act, void *cbd)
+{
+ struct rspamd_scan_result *metric_res = (struct rspamd_scan_result *) cbd;
+ metric_res->actions_config[i].flags = RSPAMD_ACTION_RESULT_DEFAULT;
+ if (!(act->flags & RSPAMD_ACTION_NO_THRESHOLD)) {
+ metric_res->actions_config[i].cur_limit = act->threshold;
+ }
+ else {
+ metric_res->actions_config[i].flags |= RSPAMD_ACTION_RESULT_NO_THRESHOLD;
+ }
+ metric_res->actions_config[i].action = act;
+}
+
struct rspamd_scan_result *
rspamd_create_metric_result(struct rspamd_task *task,
const gchar *name, gint lua_sym_cbref)
@@ -91,25 +105,13 @@ rspamd_create_metric_result(struct rspamd_task *task,
if (task->cfg) {
struct rspamd_action *act, *tmp;
+ int nact = rspamd_config_actions_size(task->cfg);
metric_res->actions_config = rspamd_mempool_alloc0(task->task_pool,
- sizeof(struct rspamd_action_config) * HASH_COUNT(task->cfg->actions));
- i = 0;
+ sizeof(struct rspamd_action_config) * nact);
- HASH_ITER(hh, task->cfg->actions, act, tmp)
- {
- metric_res->actions_config[i].flags = RSPAMD_ACTION_RESULT_DEFAULT;
- if (!(act->flags & RSPAMD_ACTION_NO_THRESHOLD)) {
- metric_res->actions_config[i].cur_limit = act->threshold;
- }
- else {
- metric_res->actions_config[i].flags |= RSPAMD_ACTION_RESULT_NO_THRESHOLD;
- }
- metric_res->actions_config[i].action = act;
-
- i++;
- }
+ rspamd_config_actions_foreach_enumerate(task->cfg, rspamd_metric_actions_foreach_cb, metric_res);
- metric_res->nactions = i;
+ metric_res->nactions = nact;
}
rspamd_mempool_add_destructor(task->task_pool,
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 18388e642..8779f8edc 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -785,6 +785,32 @@ struct rspamd_action *rspamd_config_get_action(struct rspamd_config *cfg,
struct rspamd_action *rspamd_config_get_action_by_type(struct rspamd_config *cfg,
enum rspamd_action_type type);
+/**
+ * Iterate over all actions
+ * @param cfg
+ * @param func
+ * @param data
+ */
+void rspamd_config_actions_foreach(struct rspamd_config *cfg,
+ void (*func)(struct rspamd_action *act, void *d),
+ void *data);
+/**
+ * Iterate over all actions with index
+ * @param cfg
+ * @param func
+ * @param data
+ */
+void rspamd_config_actions_foreach_enumerate(struct rspamd_config *cfg,
+ void (*func)(int idx, struct rspamd_action *act, void *d),
+ void *data);
+
+/**
+ * Returns number of actions defined in the config
+ * @param cfg
+ * @return
+ */
+gsize rspamd_config_actions_size(struct rspamd_config *cfg);
+
int rspamd_config_ev_backend_get(struct rspamd_config *cfg);
const gchar *rspamd_config_ev_backend_to_string(int ev_backend, gboolean *effective);
diff --git a/src/libserver/cfg_rcl.cxx b/src/libserver/cfg_rcl.cxx
index 8267a4bc8..c2b5a4975 100644
--- a/src/libserver/cfg_rcl.cxx
+++ b/src/libserver/cfg_rcl.cxx
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -28,6 +28,10 @@
#include "libmime/email_addr.h"
#include "libmime/lang_detection.h"
+#include <string>
+#include "contrib/ankerl/unordered_dense.h"
+#include "libutil/cxx/util.hxx"
+
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
@@ -36,23 +40,21 @@
struct rspamd_rcl_default_handler_data {
struct rspamd_rcl_struct_parser pd;
- gchar *key;
+ std::string key;
rspamd_rcl_default_handler_t handler;
- UT_hash_handle hh;
};
struct rspamd_rcl_section {
const gchar *name; /**< name of section */
const gchar *key_attr;
const gchar *default_key;
- rspamd_rcl_handler_t handler; /**< handler of section attributes */
- enum ucl_type type; /**< type of attribute */
- gboolean required; /**< whether this param is required */
- gboolean strict_type; /**< whether we need strict type */
- UT_hash_handle hh; /** hash handle */
- struct rspamd_rcl_section *subsections; /**< hash table of subsections */
- struct rspamd_rcl_default_handler_data *default_parser; /**< generic parsing fields */
- rspamd_rcl_section_fin_t fin; /** called at the end of section parsing */
+ rspamd_rcl_handler_t handler; /**< handler of section attributes */
+ enum ucl_type type; /**< type of attribute */
+ gboolean required; /**< whether this param is required */
+ gboolean strict_type; /**< whether we need strict type */
+ ankerl::unordered_dense::map<std::string, struct rspamd_rcl_section> subsections;
+ ankerl::unordered_dense::map<std::string, struct rspamd_rcl_default_handler_data> default_parser; /**< generic parsing fields */
+ rspamd_rcl_section_fin_t fin; /** called at the end of section parsing */
gpointer fin_ud;
ucl_object_t *doc_ref; /**< reference to the section's documentation */
};
@@ -77,10 +79,15 @@ struct rspamd_worker_cfg_parser {
gpointer def_ud;
};
-static gboolean rspamd_rcl_process_section(struct rspamd_config *cfg,
- struct rspamd_rcl_section *sec,
- gpointer ptr, const ucl_object_t *obj, rspamd_mempool_t *pool,
- GError **err);
+static bool rspamd_rcl_process_section(struct rspamd_config *cfg,
+ struct rspamd_rcl_section *sec,
+ gpointer ptr, const ucl_object_t *obj, rspamd_mempool_t *pool,
+ GError **err);
+static bool
+rspamd_rcl_section_parse_defaults(struct rspamd_config *cfg,
+ const struct rspamd_rcl_section §ion,
+ rspamd_mempool_t *pool, const ucl_object_t *obj, gpointer ptr,
+ GError **err);
/*
* Common section handlers
@@ -91,15 +98,15 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
GError **err)
{
const ucl_object_t *val;
- const gchar *facility = NULL, *log_type = NULL, *log_level = NULL;
- struct rspamd_config *cfg = ud;
+ const gchar *facility = nullptr, *log_type = nullptr, *log_level = nullptr;
+ auto *cfg = (struct rspamd_config *) ud;
val = ucl_object_lookup(obj, "type");
- if (val != NULL && ucl_object_tostring_safe(val, &log_type)) {
+ if (val != nullptr && ucl_object_tostring_safe(val, &log_type)) {
if (g_ascii_strcasecmp(log_type, "file") == 0) {
/* Need to get filename */
val = ucl_object_lookup(obj, "filename");
- if (val == NULL || val->type != UCL_STRING) {
+ if (val == nullptr || val->type != UCL_STRING) {
g_set_error(err,
CFG_RCL_ERROR,
ENOENT,
@@ -116,7 +123,7 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
cfg->log_facility = LOG_DAEMON;
cfg->log_type = RSPAMD_LOG_SYSLOG;
val = ucl_object_lookup(obj, "facility");
- if (val != NULL && ucl_object_tostring_safe(val, &facility)) {
+ if (val != nullptr && ucl_object_tostring_safe(val, &facility)) {
if (g_ascii_strcasecmp(facility, "LOG_AUTH") == 0 ||
g_ascii_strcasecmp(facility, "auth") == 0) {
cfg->log_facility = LOG_AUTH;
@@ -202,7 +209,7 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
/* Handle log level */
val = ucl_object_lookup(obj, "level");
- if (val != NULL && ucl_object_tostring_safe(val, &log_level)) {
+ if (val != nullptr && ucl_object_tostring_safe(val, &log_level)) {
if (g_ascii_strcasecmp(log_level, "error") == 0) {
cfg->log_level = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL;
}
@@ -234,17 +241,17 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
/* Handle flags */
- val = ucl_object_lookup_any(obj, "color", "log_color", NULL);
+ val = ucl_object_lookup_any(obj, "color", "log_color", nullptr);
if (val && ucl_object_toboolean(val)) {
cfg->log_flags |= RSPAMD_LOG_FLAG_COLOR;
}
- val = ucl_object_lookup_any(obj, "severity", "log_severity", NULL);
+ val = ucl_object_lookup_any(obj, "severity", "log_severity", nullptr);
if (val && ucl_object_toboolean(val)) {
cfg->log_flags |= RSPAMD_LOG_FLAG_SEVERITY;
}
- val = ucl_object_lookup_any(obj, "systemd", "log_systemd", NULL);
+ val = ucl_object_lookup_any(obj, "systemd", "log_systemd", nullptr);
if (val && ucl_object_toboolean(val)) {
cfg->log_flags |= RSPAMD_LOG_FLAG_SYSTEMD;
}
@@ -254,13 +261,13 @@ rspamd_rcl_logging_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
cfg->log_flags |= RSPAMD_LOG_FLAG_RE_CACHE;
}
- val = ucl_object_lookup_any(obj, "usec", "log_usec", NULL);
+ val = ucl_object_lookup_any(obj, "usec", "log_usec", nullptr);
if (val && ucl_object_toboolean(val)) {
cfg->log_flags |= RSPAMD_LOG_FLAG_USEC;
}
- return rspamd_rcl_section_parse_defaults(cfg, section, cfg->cfg_pool, obj,
- cfg, err);
+ return rspamd_rcl_section_parse_defaults(cfg, *section, cfg->cfg_pool, obj,
+ (void *) cfg, err);
}
static gboolean
@@ -269,15 +276,15 @@ rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *dns, *upstream, *neighbours;
- struct rspamd_config *cfg = ud;
+ auto *cfg = (struct rspamd_config *) ud;
struct rspamd_rcl_section *dns_section, *upstream_section, *neighbours_section;
- HASH_FIND_STR(section->subsections, "dns", dns_section);
+ auto maybe_subsection = rspamd::find_map(section->subsections, "dns");
dns = ucl_object_lookup(obj, "dns");
- if (dns_section != NULL && dns != NULL) {
+ if (maybe_subsection && dns != nullptr) {
if (!rspamd_rcl_section_parse_defaults(cfg,
- dns_section, cfg->cfg_pool, dns,
+ &maybe_subsection.value().get(), cfg->cfg_pool, dns,
cfg, err)) {
return FALSE;
}
@@ -285,8 +292,8 @@ rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
HASH_FIND_STR(section->subsections, "upstream", upstream_section);
- upstream = ucl_object_lookup_any(obj, "upstream", "upstreams", NULL);
- if (upstream_section != NULL && upstream != NULL) {
+ upstream = ucl_object_lookup_any(obj, "upstream", "upstreams", nullptr);
+ if (upstream_section != nullptr && upstream != nullptr) {
if (!rspamd_rcl_section_parse_defaults(cfg,
upstream_section, cfg->cfg_pool,
upstream, cfg, err)) {
@@ -297,7 +304,7 @@ rspamd_rcl_options_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
HASH_FIND_STR(section->subsections, "neighbours", neighbours_section);
neighbours = ucl_object_lookup(obj, "neighbours");
- if (neighbours_section != NULL && neighbours != NULL) {
+ if (neighbours_section != nullptr && neighbours != nullptr) {
const ucl_object_t *cur;
LL_FOREACH(neighbours, cur)
@@ -336,13 +343,13 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
const ucl_object_t *val, *elt;
struct rspamd_rcl_section *subsection;
struct rspamd_rcl_symbol_data sd;
- const gchar *description = NULL;
+ const gchar *description = nullptr;
- g_assert(key != NULL);
+ g_assert(key != nullptr);
gr = g_hash_table_lookup(cfg->groups, key);
- if (gr == NULL) {
+ if (gr == nullptr) {
gr = rspamd_config_new_group(cfg, key);
}
@@ -351,7 +358,7 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
return FALSE;
}
- if ((elt = ucl_object_lookup(obj, "one_shot")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "one_shot")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -366,7 +373,7 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "disabled")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "disabled")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -381,7 +388,7 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "enabled")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "enabled")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -396,7 +403,7 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "public")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "public")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -411,7 +418,7 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "private")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "private")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -439,9 +446,9 @@ rspamd_rcl_group_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
/* Handle symbols */
val = ucl_object_lookup(obj, "symbols");
- if (val != NULL && ucl_object_type(val) == UCL_OBJECT) {
+ if (val != nullptr && ucl_object_type(val) == UCL_OBJECT) {
HASH_FIND_STR(section->subsections, "symbols", subsection);
- g_assert(subsection != NULL);
+ g_assert(subsection != nullptr);
if (!rspamd_rcl_process_section(cfg, subsection, &sd, val,
pool, err)) {
@@ -460,15 +467,15 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
struct rspamd_rcl_symbol_data *sd = ud;
struct rspamd_config *cfg;
const ucl_object_t *elt;
- const gchar *description = NULL;
+ const gchar *description = nullptr;
gdouble score = NAN;
guint priority = 1, flags = 0;
gint nshots = 0;
- g_assert(key != NULL);
+ g_assert(key != nullptr);
cfg = sd->cfg;
- if ((elt = ucl_object_lookup(obj, "one_shot")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "one_shot")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -483,7 +490,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "any_shot")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "any_shot")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -498,7 +505,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "one_param")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "one_param")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -514,7 +521,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "ignore")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "ignore")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -530,7 +537,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "enabled")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "enabled")) != nullptr) {
if (ucl_object_type(elt) != UCL_BOOLEAN) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -546,7 +553,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
}
- if ((elt = ucl_object_lookup(obj, "nshots")) != NULL) {
+ if ((elt = ucl_object_lookup(obj, "nshots")) != nullptr) {
if (ucl_object_type(elt) != UCL_FLOAT && ucl_object_type(elt) != UCL_INT) {
g_set_error(err,
CFG_RCL_ERROR,
@@ -560,7 +567,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
nshots = ucl_object_toint(elt);
}
- elt = ucl_object_lookup_any(obj, "score", "weight", NULL);
+ elt = ucl_object_lookup_any(obj, "score", "weight", nullptr);
if (elt) {
if (ucl_object_type(elt) != UCL_FLOAT && ucl_object_type(elt) != UCL_INT) {
g_set_error(err,
@@ -604,7 +611,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
else {
rspamd_config_add_symbol(cfg, key, score,
- description, NULL, flags, priority, nshots);
+ description, nullptr, flags, priority, nshots);
}
elt = ucl_object_lookup(obj, "groups");
@@ -615,7 +622,7 @@ rspamd_rcl_symbol_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
gr_it = ucl_object_iterate_new(elt);
- while ((cur_gr = ucl_object_iterate_safe(gr_it, true)) != NULL) {
+ while ((cur_gr = ucl_object_iterate_safe(gr_it, true)) != nullptr) {
rspamd_config_add_symbol_group(cfg, key,
ucl_object_tostring(cur_gr));
}
@@ -637,7 +644,7 @@ rspamd_rcl_actions_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
it = ucl_object_iterate_new(obj);
- while ((cur = ucl_object_iterate_safe(it, true)) != NULL) {
+ while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) {
gint type = ucl_object_type(cur);
if (type == UCL_NULL) {
@@ -688,7 +695,7 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
{
const ucl_object_t *val, *cur, *cur_obj;
ucl_object_t *robj;
- ucl_object_iter_t it = NULL;
+ ucl_object_iter_t it = nullptr;
const gchar *worker_type, *worker_bind;
struct rspamd_config *cfg = ud;
GQuark qtype;
@@ -697,16 +704,16 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
struct rspamd_worker_param_parser *whandler;
struct rspamd_worker_param_key srch;
- g_assert(key != NULL);
+ g_assert(key != nullptr);
worker_type = key;
qtype = g_quark_try_string(worker_type);
if (qtype != 0) {
- wrk = rspamd_config_new_worker(cfg, NULL);
+ wrk = rspamd_config_new_worker(cfg, nullptr);
wrk->options = ucl_object_copy(obj);
wrk->worker = rspamd_get_worker_by_type(cfg, qtype);
- if (wrk->worker == NULL) {
+ if (wrk->worker == nullptr) {
g_set_error(err,
CFG_RCL_ERROR,
EINVAL,
@@ -726,12 +733,12 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
return TRUE;
}
- val = ucl_object_lookup_any(obj, "bind_socket", "listen", "bind", NULL);
+ val = ucl_object_lookup_any(obj, "bind_socket", "listen", "bind", nullptr);
/* This name is more logical */
- if (val != NULL) {
+ if (val != nullptr) {
it = ucl_object_iterate_new(val);
- while ((cur = ucl_object_iterate_safe(it, true)) != NULL) {
+ while ((cur = ucl_object_iterate_safe(it, true)) != nullptr) {
if (!ucl_object_tostring_safe(cur, &worker_bind)) {
continue;
}
@@ -757,15 +764,15 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
/* Parse other attributes */
wparser = g_hash_table_lookup(cfg->wrk_parsers, &qtype);
- if (wparser != NULL && obj->type == UCL_OBJECT) {
+ if (wparser != nullptr && obj->type == UCL_OBJECT) {
it = ucl_object_iterate_new(obj);
- while ((cur = ucl_object_iterate_full(it, UCL_ITERATE_EXPLICIT)) != NULL) {
+ while ((cur = ucl_object_iterate_full(it, UCL_ITERATE_EXPLICIT)) != nullptr) {
srch.name = ucl_object_key(cur);
srch.ptr = wrk->ctx; /* XXX: is it valid? Update! no, it is not valid, omfg... */
whandler = g_hash_table_lookup(wparser->parsers, &srch);
- if (whandler != NULL) {
+ if (whandler != nullptr) {
LL_FOREACH(cur, cur_obj)
{
@@ -788,7 +795,7 @@ rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
ucl_object_iterate_free(it);
- if (wparser->def_obj_parser != NULL) {
+ if (wparser->def_obj_parser != nullptr) {
robj = ucl_object_ref(obj);
if (!wparser->def_obj_parser(robj, wparser->def_ud)) {
@@ -823,7 +830,7 @@ rspamd_rcl_lua_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
if (lua_dir && lua_file) {
cur_dir = g_malloc(PATH_MAX);
- if (getcwd(cur_dir, PATH_MAX) != NULL && chdir(lua_dir) != -1) {
+ if (getcwd(cur_dir, PATH_MAX) != nullptr && chdir(lua_dir) != -1) {
/* Push traceback function */
lua_pushcfunction(L, &rspamd_lua_traceback);
err_idx = lua_gettop(L);
@@ -949,21 +956,21 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_config *cfg,
cur_mod->name);
ext_pos = strstr(cur_mod->name, ".lua");
- if (ext_pos != NULL) {
+ if (ext_pos != nullptr) {
*ext_pos = '\0';
}
if (modules_seen) {
seen_mod = g_hash_table_lookup(modules_seen, cur_mod->name);
- if (seen_mod != NULL) {
+ if (seen_mod != nullptr) {
msg_info_config("already seen module %s at %s, skip %s",
cur_mod->name, seen_mod->path, cur_mod->path);
continue;
}
}
- if (cfg->script_modules == NULL) {
+ if (cfg->script_modules == nullptr) {
cfg->script_modules = g_list_append(cfg->script_modules,
cur_mod);
rspamd_mempool_add_destructor(cfg->cfg_pool,
@@ -992,14 +999,14 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_config *cfg,
cur_mod->name);
ext_pos = strstr(cur_mod->name, ".lua");
- if (ext_pos != NULL) {
+ if (ext_pos != nullptr) {
*ext_pos = '\0';
}
if (modules_seen) {
seen_mod = g_hash_table_lookup(modules_seen, cur_mod->name);
- if (seen_mod != NULL) {
+ if (seen_mod != nullptr) {
msg_info_config("already seen module %s at %s, skip %s",
cur_mod->name, seen_mod->path, cur_mod->path);
@@ -1007,7 +1014,7 @@ rspamd_rcl_add_lua_plugins_path(struct rspamd_config *cfg,
}
}
- if (cfg->script_modules == NULL) {
+ if (cfg->script_modules == nullptr) {
cfg->script_modules = g_list_append(cfg->script_modules,
cur_mod);
rspamd_mempool_add_destructor(cfg->cfg_pool,
@@ -1109,7 +1116,7 @@ rspamd_rcl_modules_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
}
else if (ucl_object_tostring_safe(obj, &data)) {
if (!rspamd_rcl_add_lua_plugins_path(cfg,
- rspamd_mempool_strdup(cfg->cfg_pool, data), TRUE, NULL, err)) {
+ rspamd_mempool_strdup(cfg->cfg_pool, data), TRUE, nullptr, err)) {
return FALSE;
}
}
@@ -1141,29 +1148,29 @@ rspamd_rcl_statfile_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
struct rspamd_statfile_config *st;
GList *labels;
- g_assert(key != NULL);
+ g_assert(key != nullptr);
cfg = stud->cfg;
ccf = stud->ccf;
*** OUTPUT TRUNCATED, 1214 LINES SKIPPED ***
More information about the Commits
mailing list