From cb34e117a397a6d27734cf3564001bfec97ec0ea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 22 Feb 2011 17:36:34 +0300 Subject: [PATCH] * Add options section into config to organize options * Add one_shot option for avoiding inserting several results from one rule Fix parsing of headers with \t symbol [1] Reported by: Victor Ustugov [1] --- rspamd.xml.sample | 33 +++++++++++++---- src/cfg_file.h | 1 + src/cfg_xml.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ src/cfg_xml.h | 1 + src/filter.c | 2 +- src/message.c | 1 + 6 files changed, 123 insertions(+), 8 deletions(-) diff --git a/rspamd.xml.sample b/rspamd.xml.sample index 1048da2ca..72fd663f0 100644 --- a/rspamd.xml.sample +++ b/rspamd.xml.sample @@ -1,13 +1,32 @@ - -/tmp -/var/run/rspamd/rspamd.pid -regexp,surbl,chartable,fuzzy_check,spf -262144000 -yes + - + + + + + /tmp + + /var/run/rspamd/rspamd.pid + + regexp,surbl,chartable,fuzzy_check,spf + + 250M + + yes + + no + + no + + 1s + + 5 + + /var/run/rspamd/symbols.cache + + diff --git a/src/cfg_file.h b/src/cfg_file.h index 09eea3976..3a9a7d12e 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -253,6 +253,7 @@ struct config_file { gboolean no_fork; /**< if 1 do not call daemon() */ gboolean config_test; /**< if TRUE do only config file test */ gboolean raw_mode; /**< work in raw mode instead of utf one */ + gboolean one_shot_mode; /**< rules add only one symbol */ gboolean check_text_attachements; /**< check text attachements as text */ gboolean convert_config; /**< convert config to XML format */ diff --git a/src/cfg_xml.c b/src/cfg_xml.c index 885af3a57..06cdab069 100644 --- a/src/cfg_xml.c +++ b/src/cfg_xml.c @@ -61,6 +61,7 @@ enum xml_config_section { XML_SECTION_MAIN, + XML_SECTION_OPTIONS, XML_SECTION_LOGGING, XML_SECTION_WORKER, XML_SECTION_METRIC, @@ -187,6 +188,83 @@ static struct xml_parser_rule grammar[] = { }, NULL_DEF_ATTR }, + { XML_SECTION_OPTIONS, { + { + "statfile_pool_size", + xml_handle_size, + G_STRUCT_OFFSET (struct config_file, max_statfile_size), + NULL + }, + { + "user_settings", + handle_user_settings, + 0, + NULL + }, + { + "domain_settings", + handle_domain_settings, + 0, + NULL + }, + { + "cache_file", + xml_handle_string, + G_STRUCT_OFFSET (struct config_file, cache_filename), + NULL + }, + { + "dns_timeout", + xml_handle_seconds, + G_STRUCT_OFFSET (struct config_file, dns_timeout), + NULL + }, + { + "dns_retransmits", + xml_handle_uint32, + G_STRUCT_OFFSET (struct config_file, dns_retransmits), + NULL + }, + { + "raw_mode", + xml_handle_boolean, + G_STRUCT_OFFSET (struct config_file, raw_mode), + NULL + }, + { + "one_shot", + xml_handle_boolean, + G_STRUCT_OFFSET (struct config_file, one_shot_mode), + NULL + }, + { + "check_attachements", + xml_handle_boolean, + G_STRUCT_OFFSET (struct config_file, check_text_attachements), + NULL + }, + { + "tempdir", + xml_handle_string, + G_STRUCT_OFFSET (struct config_file, temp_dir), + NULL + }, + { + "pidfile", + xml_handle_string, + G_STRUCT_OFFSET (struct config_file, pid_file), + NULL + }, + { + "filters", + xml_handle_string, + G_STRUCT_OFFSET (struct config_file, filters_str), + NULL + }, + NULL_ATTR + }, + NULL_DEF_ATTR + }, { XML_SECTION_LOGGING, { { "type", @@ -465,6 +543,8 @@ xml_state_to_string (struct rspamd_xml_userdata *ud) return "read param"; case XML_READ_MODULE: return "read module section"; + case XML_READ_OPTIONS: + return "read options section"; case XML_READ_MODULES: return "read modules section"; case XML_READ_CLASSIFIER: @@ -1441,6 +1521,9 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam else if (g_ascii_strcasecmp (element_name, "modules") == 0) { ud->state = XML_READ_MODULES; } + else if (g_ascii_strcasecmp (element_name, "options") == 0) { + ud->state = XML_READ_OPTIONS; + } else if (g_ascii_strcasecmp (element_name, "logging") == 0) { ud->state = XML_READ_LOGGING; } @@ -1519,6 +1602,7 @@ rspamd_xml_start_element (GMarkupParseContext *context, const gchar *element_nam case XML_READ_WORKER: case XML_READ_LOGGING: case XML_READ_VIEW: + case XML_READ_OPTIONS: rspamd_strlcpy (ud->section_name, element_name, sizeof (ud->section_name)); /* Save attributes */ ud->cur_attrs = process_attrs (ud->cfg, attribute_names, attribute_values); @@ -1618,6 +1702,9 @@ rspamd_xml_end_element (GMarkupParseContext *context, const gchar *element_name, case XML_READ_MODULES: CHECK_TAG ("modules", FALSE); break; + case XML_READ_OPTIONS: + CHECK_TAG ("options", FALSE); + break; case XML_READ_METRIC: CHECK_TAG ("metric", FALSE); if (res) { @@ -1703,6 +1790,12 @@ rspamd_xml_text (GMarkupParseContext *context, const gchar *text, gsize text_len ud->state = XML_ERROR; } break; + case XML_READ_OPTIONS: + if (!call_param_handler (ud, ud->section_name, val, cfg, XML_SECTION_OPTIONS)) { + *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "cannot parse tag '%s' data: %s", ud->section_name, val); + ud->state = XML_ERROR; + } + break; case XML_READ_CLASSIFIER: if (!call_param_handler (ud, ud->section_name, val, ud->section_pointer, XML_SECTION_CLASSIFIER)) { *error = g_error_new (xml_error_quark (), XML_EXTRA_ELEMENT, "cannot parse tag '%s' data: %s", ud->section_name, val); diff --git a/src/cfg_xml.h b/src/cfg_xml.h index 2abdf650b..cd6f2eff4 100644 --- a/src/cfg_xml.h +++ b/src/cfg_xml.h @@ -23,6 +23,7 @@ enum xml_read_state { XML_READ_WORKER, XML_READ_VIEW, XML_READ_LOGGING, + XML_READ_OPTIONS, XML_READ_VALUE, XML_SKIP_ELEMENTS, XML_ERROR, diff --git a/src/filter.c b/src/filter.c index 4b8585a7c..d41c85ff0 100644 --- a/src/filter.c +++ b/src/filter.c @@ -171,7 +171,7 @@ insert_result_common (struct worker_task *task, const gchar *symbol, double flag void insert_result (struct worker_task *task, const gchar *symbol, double flag, GList * opts) { - insert_result_common (task, symbol, flag, opts, FALSE); + insert_result_common (task, symbol, flag, opts, task->cfg->one_shot_mode); } /* Insert result as a single option */ diff --git a/src/message.c b/src/message.c index bf2896009..38f9a663e 100644 --- a/src/message.c +++ b/src/message.c @@ -513,6 +513,7 @@ process_raw_headers (struct worker_task *task) /* We got header's name, so skip any \t or spaces */ if (*p == '\t') { new->tab_separated = TRUE; + p ++; } else if (*p == ' '){ p ++; -- 2.39.5