]> source.dussan.org Git - rspamd.git/commitdiff
* Add options section into config to organize options
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 22 Feb 2011 14:36:34 +0000 (17:36 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 22 Feb 2011 14:36:34 +0000 (17:36 +0300)
* 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
src/cfg_file.h
src/cfg_xml.c
src/cfg_xml.h
src/filter.c
src/message.c

index 1048da2ca8e57c3119a9043c57e8b1cf1813b258..72fd663f05a6e7e28f03627330ecc0f46ca14705 100644 (file)
@@ -1,13 +1,32 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <rspamd>
-<!-- Main section -->
-<tempdir>/tmp</tempdir>
-<pidfile>/var/run/rspamd/rspamd.pid</pidfile>
-<filters>regexp,surbl,chartable,fuzzy_check,spf</filters>
-<statfile_pool_size>262144000</statfile_pool_size>
-<raw_mode>yes</raw_mode>
+<!-- Global section -->
 <lua src="@ETC_PREFIX@/rspamd/lua/rspamd.lua" />
-<!-- End of main section -->
+
+<!-- Options -->
+<options>
+  <!-- Temporary directory -->
+  <tempdir>/tmp</tempdir>
+  <!-- Path to pid file -->
+  <pidfile>/var/run/rspamd/rspamd.pid</pidfile>
+  <!-- Turned on C filters -->
+  <filters>regexp,surbl,chartable,fuzzy_check,spf</filters>
+  <!-- Maximum size of statistics mapped in memory -->
+  <statfile_pool_size>250M</statfile_pool_size>
+  <!-- Raw mode is non-utf mode. In utf mode all messages are converted to utf8 (if possible) -->
+  <raw_mode>yes</raw_mode>
+  <!-- Check text attachements as ordinary text parts -->
+  <check_attachements>no</check_attachements>
+  <!-- If a rule has been met several times do not add additional score -->
+  <one_shot>no</one_shot>
+  <!-- DNS requests global timeout -->
+  <dns_timeout>1s</dns_timeout>
+  <!-- DNS retransmits count -->
+  <dns_retransmits>5</dns_retransmits>
+  <!-- File for saving settings of symbols cache -->
+  <cache_file>/var/run/rspamd/symbols.cache</cache_file>
+</options>
+<!-- End of options section -->
 
 <!-- Logging section -->
 <logging>
index 09eea39766d9c926e45ad04d4e960c3169eb8d6f..3a9a7d12e6493917146cc9ec891999bfd9a2f6cc 100644 (file)
@@ -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                                               */
 
index 885af3a57b238910bb1238ca08cb367fbfa3344f..06cdab069c08e0785cb076627c2181b4071e0b1a 100644 (file)
@@ -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);
index 2abdf650b52c5c5d08b5892569e3a8625691d2c1..cd6f2eff43b20e7e6ca326f3f48f89efa52a2acd 100644 (file)
@@ -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,
index 4b8585a7cbf3c1291258fce3d9bdbc5673340a22..d41c85ff05728b34e9ba65b3fbd2d49091042e38 100644 (file)
@@ -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 */
index bf2896009734fa972cd77653e9ace8a2003f4ad9..38f9a663ec441453abfed45c5f55b4f2f5965710 100644 (file)
@@ -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 ++;