LUA_VAR_UNKNOWN
};
+enum rspamd_symbol_group_flags {
+ RSPAMD_SYMBOL_GROUP_NORMAL = 0,
+ RSPAMD_SYMBOL_GROUP_DISABLED = (1 << 0),
+ RSPAMD_SYMBOL_GROUP_ONE_SHOT = (1 << 1),
+ RSPAMD_SYMBOL_GROUP_UNGROUPED = (1 << 2),
+};
+
/**
* Symbols group
*/
gchar *name;
GHashTable *symbols;
gdouble max_score;
- gboolean disabled;
- gboolean one_shot;
+ enum rspamd_symbol_group_flags flags;
};
-#define RSPAMD_SYMBOL_FLAG_IGNORE (1 << 1)
-#define RSPAMD_SYMBOL_FLAG_ONEPARAM (1 << 2)
-#define RSPAMD_SYMBOL_FLAG_UNGROUPPED (1 << 3)
+enum rspamd_symbol_flags {
+ RSPAMD_SYMBOL_FLAG_NORMAL = 0,
+ RSPAMD_SYMBOL_FLAG_IGNORE = (1 << 1),
+ RSPAMD_SYMBOL_FLAG_ONEPARAM = (1 << 2),
+ RSPAMD_SYMBOL_FLAG_UNGROUPPED = (1 << 3),
+};
/**
* Symbol config definition
guint priority;
struct rspamd_symbols_group *gr; /* Main group */
GPtrArray *groups; /* Other groups */
- guint flags;
+ enum rspamd_symbol_flags flags;
gint nshots;
};
{
struct rspamd_config *cfg = ud;
struct rspamd_symbols_group *gr;
- const ucl_object_t *val;
+ const ucl_object_t *val, *elt;
struct rspamd_rcl_section *subsection;
struct rspamd_rcl_symbol_data sd;
return FALSE;
}
+ if ((elt = ucl_object_lookup (obj, "one_shot")) != NULL) {
+ if (ucl_object_type (elt) != UCL_BOOLEAN) {
+ g_set_error (err,
+ CFG_RCL_ERROR,
+ EINVAL,
+ "one_shot attribute is not boolean for symbol: '%s'",
+ key);
+
+ return FALSE;
+ }
+ if (ucl_object_toboolean (elt)) {
+ gr->flags |= RSPAMD_SYMBOL_GROUP_ONE_SHOT;
+ }
+ }
+
+ if ((elt = ucl_object_lookup (obj, "disabled")) != NULL) {
+ if (ucl_object_type (elt) != UCL_BOOLEAN) {
+ g_set_error (err,
+ CFG_RCL_ERROR,
+ EINVAL,
+ "disabled attribute is not boolean for symbol: '%s'",
+ key);
+
+ return FALSE;
+ }
+ if (ucl_object_toboolean (elt)) {
+ gr->flags |= RSPAMD_SYMBOL_GROUP_DISABLED;
+ }
+ }
+
+ if ((elt = ucl_object_lookup (obj, "enabled")) != NULL) {
+ if (ucl_object_type (elt) != UCL_BOOLEAN) {
+ g_set_error (err,
+ CFG_RCL_ERROR,
+ EINVAL,
+ "enabled attribute is not boolean for symbol: '%s'",
+ key);
+
+ return FALSE;
+ }
+ if (!ucl_object_toboolean (elt)) {
+ gr->flags |= RSPAMD_SYMBOL_GROUP_DISABLED;
+ }
+ }
+
sd.gr = gr;
sd.cfg = cfg;
rspamd_config_add_symbol (cfg, composite_name, score,
description, group,
0,
- ucl_object_get_priority (obj) + 1,
+ ucl_object_get_priority (obj), /* No +1 as it is default... */
1);
elt = ucl_object_lookup (obj, "groups");
"Symbols configuration");
/* Group part */
- rspamd_rcl_add_default_handler (sub,
- "disabled",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_symbols_group, disabled),
- 0,
- "Disable symbols group");
- rspamd_rcl_add_default_handler (sub,
- "enabled",
- rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct rspamd_symbols_group, disabled),
- RSPAMD_CL_FLAG_BOOLEAN_INVERSE,
- "Enable or disable symbols group");
rspamd_rcl_add_default_handler (sub,
"max_score",
rspamd_rcl_parse_struct_double,
(rspamd_mempool_destruct_t)g_hash_table_unref, gr->symbols);
gr->name = rspamd_mempool_strdup (cfg->cfg_pool, name);
+ if (strcmp (gr->name, "ungrouped") == 0) {
+ gr->flags |= RSPAMD_SYMBOL_GROUP_UNGROUPED;
+ }
+
g_hash_table_insert (cfg->groups, gr->name, gr);
return gr;
/* We also check group information in this case */
if (group != NULL && sym_def->gr != NULL &&
strcmp (group, sym_def->gr->name) != 0) {
- msg_debug_config ("move symbol %s from group %s to %s",
- sym_def->gr->name, group);
- g_hash_table_remove (sym_def->gr->symbols, sym_def->name);
sym_group = g_hash_table_lookup (cfg->groups, group);
if (sym_group == NULL) {
sym_group = rspamd_config_new_group (cfg, group);
}
- sym_def->gr = sym_group;
- g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def);
+ if (!(sym_group->flags & RSPAMD_SYMBOL_GROUP_UNGROUPED)) {
+ msg_debug_config ("move symbol %s from group %s to %s",
+ sym_def->gr->name, group);
+ g_hash_table_remove (sym_def->gr->symbols, sym_def->name);
+ sym_def->gr = sym_group;
+ g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def);
+ }
}
return TRUE;
gr = g_hash_table_lookup (cfg->groups, module_name);
if (gr) {
- if (gr->disabled) {
+ if (gr->flags & RSPAMD_SYMBOL_GROUP_DISABLED) {
rspamd_plugins_table_push_elt (L,
"disabled_explicitly", module_name);
msg_info_config ("%s module %s is disabled in the configuration as "