diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-13 14:11:31 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-13 14:11:31 +0300 |
commit | 89f264624c1c846c995c22a8390b7e79f09ef960 (patch) | |
tree | c3a22a993c411510030930e88fff5b86890d5e24 /src | |
parent | 9a0362647374be48a29887d0571b8a665877be6b (diff) | |
download | rspamd-89f264624c1c846c995c22a8390b7e79f09ef960.tar.gz rspamd-89f264624c1c846c995c22a8390b7e79f09ef960.zip |
* Add ability to configure sections in statfiles
* Add ability to define variables in modules blocks
* Add symbolic aliases for statfile sections
Diffstat (limited to 'src')
-rw-r--r-- | src/cfg_file.h | 10 | ||||
-rw-r--r-- | src/cfg_file.l | 1 | ||||
-rw-r--r-- | src/cfg_file.y | 69 | ||||
-rw-r--r-- | src/statfile.c | 16 | ||||
-rw-r--r-- | src/statfile.h | 10 |
5 files changed, 105 insertions, 1 deletions
diff --git a/src/cfg_file.h b/src/cfg_file.h index 75c3a8c2f..b484d5b0d 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -108,6 +108,15 @@ struct module_opt { }; /** + * 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 */ struct statfile { @@ -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 */ }; /** diff --git a/src/cfg_file.l b/src/cfg_file.l index 7216cda7e..ac2624155 100644 --- a/src/cfg_file.l +++ b/src/cfg_file.l @@ -59,6 +59,7 @@ weight return WEIGHT; size return SIZE; tokenizer return TOKENIZER; classifier return CLASSIFIER; +section return SECTION; logging return LOGGING; diff --git a/src/cfg_file.y b/src/cfg_file.y index dd48520f2..1593c80c9 100644 --- a/src/cfg_file.y +++ b/src/cfg_file.y @@ -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 { diff --git a/src/statfile.c b/src/statfile.c index 115e29442..b77ca8779 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -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; +} diff --git a/src/statfile.h b/src/statfile.h index 38ec9d13f..ee89acda9 100644 --- a/src/statfile.h +++ b/src/statfile.h @@ -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 |