]> source.dussan.org Git - rspamd.git/commitdiff
* Add ability to pass options to rspamd modules via flex start conditions
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 2 Sep 2008 15:42:58 +0000 (19:42 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 2 Sep 2008 15:42:58 +0000 (19:42 +0400)
cfg_file.h
cfg_file.l
cfg_file.y
cfg_utils.c

index 62856b489fd65744dd4e82070c2d4040dcfd3538..40159358406f63cbeaeb3c27617f977a6bf34829 100644 (file)
@@ -84,6 +84,12 @@ struct filter_chain {
        LIST_ENTRY (filter_chain) next;
 };
 
+struct module_opt {
+       char *param;
+       char *value;
+       LIST_ENTRY (module_opt) next;
+};
+
 struct config_file {
        char *cfg_name;
        char *pid_file;
@@ -108,6 +114,7 @@ struct config_file {
        LIST_HEAD (perlq, filter_chain) filters;
        LIST_HEAD (modulesq, perl_module) perl_modules;
        LIST_HEAD (cmodulesq, c_module) c_modules;
+       GHashTable* modules_opts;
 };
 
 int add_memcached_server (struct config_file *cf, char *str);
index 760afc1ad116d839737081b475f6a650fe96c460..8cde589b5df96cddd8ca9f1de07e13f8e757c87f 100644 (file)
@@ -1,4 +1,5 @@
 %x incl
+%x module
 
 %{
 #include <stdio.h>
@@ -98,6 +99,7 @@ parse_flag (const char *str)
 %%
 ^[ \t]*#.*                                             /* ignore comments */;
 .include                                               BEGIN(incl);
+.module                                                        BEGIN(module);
 tempdir                                                        return TEMPDIR;
 pidfile                                                        return PIDFILE;
 workers                                                        return WORKERS;
@@ -120,6 +122,7 @@ script_message                                      return SCRIPT_MESSAGE;
 script_url                                             return SCRIPT_URL;
 script_chain                                   return SCRIPT_CHAIN;
 
+
 \{                                                             return OBRACE;
 \}                                                             return EBRACE;
 ;                                                              return SEMICOLON;
@@ -177,6 +180,15 @@ yes|YES|no|NO|[yY]|[nN]                    yylval.flag=parse_flag(yytext); return FLAG;
             }
         }
 
+<module>\n                                                             /* ignore EOL */;
+<module>[ \t]+                                                 /* ignore whitespace */;
+<module>\'[a-zA-Z0-9_-]\'      yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return MODULE_OPT; 
+<module>\{     return OBRACE;
+<module>\}  return EBRACE;
+<module>\;     return SEMICOLON;
+<module>[a-zA-Z0-9_-]  yylval.string=strdup(yytext); return PARAM;
+<module>\"[^"]+\"      yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return QUOTEDSTRING;
+
 %%
 /* 
  * vi:ts=4 
index 91f84f4ceafcf610336dcf3e9a6dc83254ece3e7..8448933b490920f15cf3800ea6d07ad3b837d3c0 100644 (file)
@@ -26,6 +26,7 @@ extern char *yytext;
 
 struct scriptq *cur_scripts;
 unsigned int cur_scripts_num = 0;
+LIST_HEAD (moduleoptq, module_opt) *cur_module_opt = NULL;
 
 %}
 
@@ -47,9 +48,10 @@ unsigned int cur_scripts_num = 0;
 %token  READ_SERVERS WRITE_SERVER DIRECTORY_SERVERS MAILBOX_QUERY USERS_QUERY LASTLOGIN_QUERY
 %token  MEMCACHED WORKERS REQUIRE MODULE
 %token  FILTER METRIC SCRIPT_HEADER SCRIPT_MIME SCRIPT_MESSAGE SCRIPT_URL SCRIPT_CHAIN SCRIPT_PARAM
+%token  MODULE_OPT, PARAM
 
 %type  <string>        STRING
-%type  <string>        QUOTEDSTRING
+%type  <string>        QUOTEDSTRING MODULE_OPT PARAM
 %type  <string>        FILENAME 
 %type   <string>       SOCKCRED
 %type  <string>        IPADDR IPNETWORK
@@ -77,6 +79,7 @@ command       :
        | workers
        | require
        | filter
+       | module_opt
        ;
 
 tempdir :
@@ -130,7 +133,7 @@ bind_cred:
        ;
 
 memcached:
-       BEANSTALK OBRACE memcachedbody EBRACE
+       MEMCACHED OBRACE memcachedbody EBRACE
        ;
 
 memcachedbody:
@@ -374,6 +377,32 @@ requirecmd:
        }
        ;
 
+module_opt:
+       MODULE_OPT OBRACE moduleoptbody EBRACE {
+               g_hash_table_insert (cfg->modules_opts, $1, cur_module_opt);
+               cur_module_opt = NULL;
+       }
+       ;
+
+moduleoptbody:
+       optcmd SEMICOLON
+       | moduleoptbody optcmd SEMICOLON
+       ;
+
+optcmd:
+       PARAM EQSIGN QUOTEDSTRING {
+               struct module_opt *mopt;
+               if (cur_module_opt == NULL) {
+                       cur_module_opt = g_malloc (sizeof (cur_module_opt));
+                       LIST_INIT (cur_module_opt);
+               }
+               mopt = g_malloc (sizeof (struct module_opt));
+               mopt->param = $1;
+               mopt->value = $3;
+               LIST_INSERT_HEAD (cur_module_opt, mopt, next);
+       }
+       ;
+
 %%
 /* 
  * vi:ts=4 
index 78c37dabd4d8f99af2b4fab1f939186633b58ef6..83738aea629d3b85b6afce0535519f41d9bb669e 100644 (file)
 extern int yylineno;
 extern char *yytext;
 
+static void 
+clean_hash_bucket (gpointer key, gpointer value, gpointer unused)
+{
+       LIST_HEAD (moduleoptq, module_opt) *cur_module_opt = (struct moduleoptq *)value;
+       struct module_opt *cur, *tmp;
+
+       LIST_FOREACH_SAFE (cur, cur_module_opt, next, tmp) {
+               if (cur->param) {
+                       free (cur->param);
+               }
+               if (cur->value) {
+                       free (cur->value);
+               }
+               LIST_REMOVE (cur, next);
+               free (cur);
+       }
+}
+
 int
 add_memcached_server (struct config_file *cf, char *str)
 {
@@ -126,6 +144,7 @@ init_defaults (struct config_file *cfg)
        cfg->memcached_protocol = TCP_TEXT;
 
        cfg->workers_number = DEFAULT_WORKERS_NUM;
+       cfg->modules_opts = g_hash_table_new (g_str_hash, g_str_equal);
 
        LIST_INIT (&cfg->filters);
        LIST_INIT (&cfg->perl_modules);
@@ -178,6 +197,10 @@ free_config (struct config_file *cfg)
                }
                free (cmodule);
        }
+
+       g_hash_table_foreach (cfg->modules_opts, clean_hash_bucket, NULL);
+       g_hash_table_remove_all (cfg->modules_opts);
+       g_hash_table_unref (cfg->modules_opts);
 }
 
 int