aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-08-13 15:28:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-08-13 15:28:07 +0100
commit6f70b5767167f3414ee7c84346e84f32ebfeaf38 (patch)
tree1448f57c9730837667f5da5f037832b970e17993 /src
parent7a1cfea11cf27eea852be68b2373b233e650f689 (diff)
downloadrspamd-6f70b5767167f3414ee7c84346e84f32ebfeaf38.tar.gz
rspamd-6f70b5767167f3414ee7c84346e84f32ebfeaf38.zip
More fixes for the new symbols structure.
Diffstat (limited to 'src')
-rw-r--r--src/controller.c25
-rw-r--r--src/libserver/cfg_file.h10
-rw-r--r--src/libserver/cfg_rcl.c33
-rw-r--r--src/libserver/cfg_utils.c26
-rw-r--r--src/libserver/composites.c13
-rw-r--r--src/libserver/protocol.c4
-rw-r--r--src/libserver/symbols_cache.c1
-rw-r--r--src/libutil/util.c2
-rw-r--r--src/lua/lua_cfg_file.c17
-rw-r--r--src/main.h2
10 files changed, 69 insertions, 64 deletions
diff --git a/src/controller.c b/src/controller.c
index c2dda4863..2c9cfae3e 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -503,9 +503,10 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent,
struct rspamd_http_message *msg)
{
struct rspamd_controller_session *session = conn_ent->ud;
- GHashTableIter it;
+ GHashTableIter it, sit;
struct rspamd_symbols_group *gr;
- struct rspamd_symbol_def *sym, *cur;
+ struct rspamd_symbol_def *sym;
+ struct metric *metric;
ucl_object_t *obj, *top, *sym_obj, *group_symbols;
gpointer k, v;
@@ -515,29 +516,33 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent,
top = ucl_object_typed_new (UCL_ARRAY);
- /* Go through all symbols groups */
- g_hash_table_iter_init (&it, session->ctx->cfg->symbols_groups);
+ /* Go through all symbols groups in the default metric */
+ metric = g_hash_table_lookup (session->ctx->cfg->metrics, DEFAULT_METRIC);
+ g_assert (metric != NULL);
+ g_hash_table_iter_init (&it, metric->groups);
+
while (g_hash_table_iter_next (&it, &k, &v)) {
gr = v;
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_fromstring (
gr->name), "group", 0, false);
/* Iterate through all symbols */
- sym = gr->symbols;
+ g_hash_table_iter_init (&sit, gr->symbols);
group_symbols = ucl_object_typed_new (UCL_ARRAY);
- LL_FOREACH (sym, cur) {
+ while (g_hash_table_iter_next (&sit, &k, &v)) {
+ sym = v;
sym_obj = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (sym_obj, ucl_object_fromstring (cur->name),
+ ucl_object_insert_key (sym_obj, ucl_object_fromstring (sym->name),
"symbol", 0, false);
ucl_object_insert_key (sym_obj,
- ucl_object_fromdouble (*cur->weight_ptr),
+ ucl_object_fromdouble (*sym->weight_ptr),
"weight", 0, false);
- if (cur->description) {
+ if (sym->description) {
ucl_object_insert_key (sym_obj,
- ucl_object_fromstring (cur->description),
+ ucl_object_fromstring (sym->description),
"description", 0, false);
}
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 431f82ab1..49d48033e 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -17,6 +17,9 @@
#define DEFAULT_BIND_PORT 11333
#define DEFAULT_CONTROL_PORT 11334
+/* Default metric name */
+#define DEFAULT_METRIC "default"
+
struct expression;
struct tokenizer;
struct rspamd_stat_classifier;
@@ -360,6 +363,13 @@ struct rspamd_worker_conf * rspamd_config_new_worker (struct rspamd_config *cfg,
*/
struct metric * rspamd_config_new_metric (struct rspamd_config *cfg,
struct metric *c, const gchar *name);
+
+/*
+ * Return new symbols group definition
+ */
+struct rspamd_symbols_group * rspamd_config_new_group (
+ struct rspamd_config *cfg, struct metric *metric,
+ const gchar *name);
/*
* Return a new statfile structure, setting default and non-conflicting attributes
*/
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 1eaaa270b..def4ac4b3 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -273,17 +273,9 @@ rspamd_rcl_group_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
gr = g_hash_table_lookup (metric->groups, key);
if (gr == NULL) {
- gr = rspamd_mempool_alloc0 (pool, sizeof (*gr));
- gr->symbols = g_hash_table_new (rspamd_strcase_hash,
- rspamd_strcase_equal);
- rspamd_mempool_add_destructor (pool,
- (rspamd_mempool_destruct_t)g_hash_table_unref, gr->symbols);
- gr->name = rspamd_mempool_strdup (pool, key);
-
- g_hash_table_insert (metric->groups, gr->name);
+ gr = rspamd_config_new_group (sd->cfg, metric, key);
}
-
if (!rspamd_rcl_section_parse_defaults (section, pool, obj,
metric, err)) {
return FALSE;
@@ -360,7 +352,9 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
return FALSE;
}
- *sym_def->weight_ptr = sym_def->score;
+ if (ucl_object_find_key (obj, "score") != NULL) {
+ *sym_def->weight_ptr = sym_def->score;
+ }
return TRUE;
}
@@ -402,30 +396,17 @@ rspamd_rcl_metric_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
const gchar *key, gpointer ud,
struct rspamd_rcl_section *section, GError **err)
{
- const ucl_object_t *val, *cur, *elt;
+ const ucl_object_t *val, *cur;
struct rspamd_config *cfg = ud;
- const gchar *metric_name, *subject_name, *semicolon, *act_str;
struct metric *metric;
- struct rspamd_symbols_group *gr;
-
- gboolean new = TRUE, have_actions = FALSE, have_symbols = FALSE,
- have_unknown = FALSE;
- gdouble unknown_weight;
- ucl_object_iter_t it = NULL;
struct rspamd_rcl_section *subsection;
struct rspamd_rcl_symbol_data sd;
g_assert (key != NULL);
- metric_name = key;
-
- metric = g_hash_table_lookup (cfg->metrics, metric_name);
+ metric = g_hash_table_lookup (cfg->metrics, key);
if (metric == NULL) {
- metric = rspamd_config_new_metric (cfg, metric, metric_name);
- }
- else {
- new = FALSE;
- have_symbols = TRUE;
+ metric = rspamd_config_new_metric (cfg, metric, key);
}
if (!rspamd_rcl_section_parse_defaults (section, cfg->cfg_pool, obj,
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index fcf5b4fd9..5d8e261b9 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -574,6 +574,24 @@ rspamd_config_new_metric (struct rspamd_config *cfg, struct metric *c,
return c;
}
+struct rspamd_symbols_group *
+rspamd_config_new_group (struct rspamd_config *cfg, struct metric *metric,
+ const gchar *name)
+{
+ struct rspamd_symbols_group *gr;
+
+ gr = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*gr));
+ gr->symbols = g_hash_table_new (rspamd_strcase_hash,
+ rspamd_strcase_equal);
+ rspamd_mempool_add_destructor (cfg->cfg_pool,
+ (rspamd_mempool_destruct_t)g_hash_table_unref, gr->symbols);
+ gr->name = rspamd_mempool_strdup (cfg->cfg_pool, name);
+
+ g_hash_table_insert (metric->groups, gr->name, gr);
+
+ return gr;
+}
+
struct rspamd_worker_conf *
rspamd_config_new_worker (struct rspamd_config *cfg,
struct rspamd_worker_conf *c)
@@ -971,6 +989,7 @@ rspamd_config_add_metric_symbol (struct rspamd_config *cfg,
score_ptr = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (gdouble));
*score_ptr = score;
+ sym_def->score = score;
sym_def->weight_ptr = score_ptr;
sym_def->name = rspamd_mempool_strdup (cfg->cfg_pool, symbol);
sym_def->one_shot = one_shot;
@@ -1007,12 +1026,7 @@ rspamd_config_add_metric_symbol (struct rspamd_config *cfg,
sym_group = g_hash_table_lookup (metric->groups, group);
if (sym_group == NULL) {
/* Create new group */
- sym_group =
- rspamd_mempool_alloc0 (cfg->cfg_pool,
- sizeof (struct rspamd_symbols_group));
- sym_group->name = rspamd_mempool_strdup (cfg->cfg_pool, group);
- sym_group->symbols = NULL;
- g_hash_table_insert (metric->groups, sym_group->name, sym_group);
+ sym_group = rspamd_config_new_group (cfg, metric, group);
}
sym_def->gr = sym_group;
diff --git a/src/libserver/composites.c b/src/libserver/composites.c
index b6d2fb863..21e712e0d 100644
--- a/src/libserver/composites.c
+++ b/src/libserver/composites.c
@@ -143,6 +143,9 @@ rspamd_composite_expr_process (gpointer input, rspamd_expression_atom_t *atom)
struct symbol *ms;
struct rspamd_symbols_group *gr;
struct rspamd_symbol_def *sdef;
+ struct metric *metric;
+ GHashTableIter it;
+ gpointer k, v;
gint rc = 0;
gchar t = '\0';
@@ -157,11 +160,17 @@ rspamd_composite_expr_process (gpointer input, rspamd_expression_atom_t *atom)
}
if (strncmp (sym, "g:", 2) == 0) {
- gr = g_hash_table_lookup (cd->task->cfg->symbols_groups, sym + 2);
+ metric = g_hash_table_lookup (cd->task->cfg->metrics, DEFAULT_METRIC);
+ g_assert (metric != NULL);
+ gr = g_hash_table_lookup (metric->groups, sym + 2);
if (gr != NULL) {
- LL_FOREACH (gr->symbols, sdef) {
+ g_hash_table_iter_init (&it, gr->symbols);
+
+ while (g_hash_table_iter_next (&it, &k, &v)) {
+ sdef = v;
rc = rspamd_composite_process_single_symbol (cd, sdef->name, &ms);
+
if (rc) {
break;
}
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index c32eda21a..0928f0ad0 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -815,7 +815,9 @@ rspamd_metric_symbol_ucl (struct rspamd_task *task, struct metric *m,
rspamd_printf_gstring (logbuf, "%s,", sym->name);
}
- description = g_hash_table_lookup (m->descriptions, sym->name);
+ if (sym->def != NULL) {
+ description = sym->def->description;
+ }
obj = ucl_object_typed_new (UCL_OBJECT);
ucl_object_insert_key (obj, ucl_object_fromstring (
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 0cc285094..4cb022764 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -259,7 +259,6 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name)
const guchar *p;
gint fd;
gpointer map;
- double w;
fd = open (name, O_RDONLY);
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 055b6b0ff..943c37b08 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -738,7 +738,7 @@ setproctitle (const gchar *fmt, ...)
gint
init_title (gint argc, gchar *argv[], gchar *envp[])
{
-#if defined(DARWIN) || defined(SOLARIS)
+#if defined(DARWIN) || defined(SOLARIS) || defined(__APPLE__)
/* XXX: try to handle these OSes too */
return 0;
#else
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index a8e8dfbb8..049118504 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -40,7 +40,7 @@ static void
lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
{
GList *metric_list;
- gchar *symbol, *old_desc;
+ gchar *symbol;
const gchar *desc;
struct metric *metric;
gdouble *score;
@@ -75,20 +75,7 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
lua_gettable (L, -2);
if (lua_isstring (L, -1)) {
desc = lua_tostring (L, -1);
- old_desc =
- g_hash_table_lookup (metric->descriptions, symbol);
- if (old_desc) {
- msg_info ("replacing description for symbol %s",
- symbol);
- g_hash_table_replace (metric->descriptions,
- symbol,
- rspamd_mempool_strdup (cfg->cfg_pool, desc));
- }
- else {
- g_hash_table_insert (metric->descriptions,
- symbol,
- rspamd_mempool_strdup (cfg->cfg_pool, desc));
- }
+ s->description = rspamd_mempool_strdup (cfg->cfg_pool, desc);
}
lua_pop (L, 1);
}
diff --git a/src/main.h b/src/main.h
index 8374af56d..9b1f928b9 100644
--- a/src/main.h
+++ b/src/main.h
@@ -25,8 +25,6 @@
#define FIXED_CONFIG_FILE RSPAMD_CONFDIR "/rspamd.conf"
/* Time in seconds to exit for old worker */
#define SOFT_SHUTDOWN_TIME 10
-/* Default metric name */
-#define DEFAULT_METRIC "default"
/* Spam subject */
#define SPAM_SUBJECT "*** SPAM *** "