]> source.dussan.org Git - rspamd.git/commitdiff
* Add ability to configure sections in statfiles
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 13 Mar 2009 11:11:31 +0000 (14:11 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 13 Mar 2009 11:11:31 +0000 (14:11 +0300)
* Add ability to define variables in modules blocks
* Add symbolic aliases for statfile sections

src/cfg_file.h
src/cfg_file.l
src/cfg_file.y
src/statfile.c
src/statfile.h

index 75c3a8c2f15b9b6fd4ad2d3baf24945679418174..b484d5b0d43dd444b279a95d07638e3614213fb9 100644 (file)
@@ -107,6 +107,15 @@ struct module_opt {
        LIST_ENTRY (module_opt) next;                                   
 };
 
+/**
+ * Statfile section definition
+ */
+struct statfile_section {
+       uint32_t code;                                                                  /**< section's code                                                                             */
+       uint64_t size;                                                                  /**< size of section                                                                    */
+       double weight;                                                                  /**< weight coefficient for section                                             */
+};
+
 /**
  * Statfile config definition
  */
@@ -117,6 +126,7 @@ struct statfile {
        char *metric;                                                                   /**< metric name                                                                                */
        size_t size;                                                                    /**< size of statfile                                                                   */
        struct tokenizer *tokenizer;                                    /**< tokenizer used for statfile                                                */
+       GList *sections;                                                                /**< list of sections in statfile                                               */
 };
 
 /**
index 7216cda7ea82c4034782dfbaa56b3b327fae45a1..ac26241558d12079926a84780bbcc2abd0c1454d 100644 (file)
@@ -59,6 +59,7 @@ weight                                                        return WEIGHT;
 size                                                   return SIZE;
 tokenizer                                              return TOKENIZER;
 classifier                                             return CLASSIFIER;
+section                                                        return SECTION;
 
 logging                                                        return LOGGING;
 
index dd48520f2c7671dbdb7ef9688913f6ec3fdd1c56..1593c80c997b6d93f8575983372a62b406717537 100644 (file)
@@ -17,6 +17,7 @@ extern char *yytext;
 LIST_HEAD (moduleoptq, module_opt) *cur_module_opt = NULL;
 struct metric *cur_metric = NULL;
 struct statfile *cur_statfile = NULL;
+struct statfile_section *cur_section = NULL;
 
 %}
 
@@ -43,7 +44,7 @@ struct statfile *cur_statfile = NULL;
 %token  LOGGING LOG_TYPE LOG_TYPE_CONSOLE LOG_TYPE_SYSLOG LOG_TYPE_FILE
 %token  LOG_LEVEL LOG_LEVEL_DEBUG LOG_LEVEL_INFO LOG_LEVEL_WARNING LOG_LEVEL_ERROR LOG_FACILITY LOG_FILENAME
 %token  STATFILE ALIAS PATTERN WEIGHT STATFILE_POOL_SIZE SIZE TOKENIZER CLASSIFIER
-%token DELIVERY LMTP ENABLED AGENT
+%token DELIVERY LMTP ENABLED AGENT SECTION
 
 %type  <string>        STRING
 %type  <string>        VARIABLE
@@ -442,6 +443,9 @@ optcmd:
                mopt->value = $3;
                LIST_INSERT_HEAD (cur_module_opt, mopt, next);
        }
+       | VARIABLE EQSIGN QUOTEDSTRING {
+               g_hash_table_insert (cfg->variables, $1, $3);
+       }
        ;
 
 variable:
@@ -581,6 +585,7 @@ statfilecmd:
        | statfilesize
        | statfilemetric
        | statfiletokenizer
+       | statfilesection
        ;
        
 statfilealias:
@@ -652,7 +657,69 @@ statfiletokenizer:
        }
        ;
 
+statfilesection:
+       SECTION OBRACE sectionbody EBRACE {
+               if (cur_statfile == NULL) {
+                       cur_statfile = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile));
+               }
+               if (cur_section == NULL || cur_section->code == 0) {
+                       yyerror ("yyparse: error in section definition");
+                       YYERROR;
+               }
+               cur_statfile->sections = g_list_prepend (cur_statfile->sections, cur_section);
+               cur_section = NULL;
+       }
+       ;
 
+sectionbody:
+       sectioncmd SEMICOLON
+       | sectionbody sectioncmd SEMICOLON
+       ;
+
+sectioncmd:
+       sectionname
+       | sectionsize
+       | sectionweight
+       ;
+
+sectionname:
+       NAME EQSIGN QUOTEDSTRING {
+               if (cur_section == NULL) {
+                       cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+               }
+               cur_section->code = statfile_get_section_by_name ($3);
+       }
+       ;
+
+sectionsize:
+       SIZE EQSIGN NUMBER {
+               if (cur_section == NULL) {
+                       cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+               }
+               cur_section->size = $3;
+       }
+       | SIZE EQSIGN SIZELIMIT {
+               if (cur_section == NULL) {
+                       cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+               }
+               cur_section->size = $3;
+       }
+       ;
+
+sectionweight:
+       WEIGHT EQSIGN NUMBER {
+               if (cur_section == NULL) {
+                       cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+               }
+               cur_section->weight = $3;
+       }
+       | WEIGHT EQSIGN FRACT {
+               if (cur_section == NULL) {
+                       cur_section = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_section));
+               }
+               cur_section->weight = $3;
+       }
+       ;
 
 statfile_pool_size:
        STATFILE_POOL_SIZE EQSIGN SIZELIMIT {
index 115e29442278f8786e2fa8b1cc80e7b0f2a83b32..b77ca87799bc94c9ec9ef279db1e3d820131f7de 100644 (file)
@@ -518,3 +518,19 @@ statfile_pool_add_section (statfile_pool_t *pool, char *filename, uint32_t code,
        return TRUE;
 
 }
+
+uint32_t 
+statfile_get_section_by_name (const char *name)
+{
+       if (g_ascii_strcasecmp (name, "common") == 0) {
+               return STATFILE_SECTION_COMMON;
+       }
+       else if (g_ascii_strcasecmp (name, "header") == 0) {
+               return STATFILE_SECTION_HEADERS;
+       }
+       else if (g_ascii_strcasecmp (name, "url") == 0) {
+               return STATFILE_SECTION_URLS;
+       }
+
+       return 0;
+}
index 38ec9d13f622fea78bd430d52dbb2ebe76dcbbec..ee89acda9394d2deaab376ab66c41e4996083553 100644 (file)
@@ -14,6 +14,8 @@
 
 /* Section types */
 #define STATFILE_SECTION_COMMON 1
+#define STATFILE_SECTION_HEADERS 2
+#define STATFILE_SECTION_URLS 3
 
 /**
  * Common statfile header
@@ -190,4 +192,12 @@ gboolean statfile_pool_set_section (statfile_pool_t *pool, char *filename, uint3
  */
 gboolean statfile_pool_add_section (statfile_pool_t *pool, char *filename, uint32_t code, uint64_t length);
 
+
+/**
+ * Return code of section identified by name
+ * @param name name of section
+ * @return code of section or 0 if name of section is unknown
+ */
+uint32_t statfile_get_section_by_name (const char *name);
+
 #endif