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;
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);
%x incl
+%x module
%{
#include <stdio.h>
%%
^[ \t]*#.* /* ignore comments */;
.include BEGIN(incl);
+.module BEGIN(module);
tempdir return TEMPDIR;
pidfile return PIDFILE;
workers return WORKERS;
script_url return SCRIPT_URL;
script_chain return SCRIPT_CHAIN;
+
\{ return OBRACE;
\} return EBRACE;
; return SEMICOLON;
}
}
+<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
struct scriptq *cur_scripts;
unsigned int cur_scripts_num = 0;
+LIST_HEAD (moduleoptq, module_opt) *cur_module_opt = NULL;
%}
%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
| workers
| require
| filter
+ | module_opt
;
tempdir :
;
memcached:
- BEANSTALK OBRACE memcachedbody EBRACE
+ MEMCACHED OBRACE memcachedbody EBRACE
;
memcachedbody:
}
;
+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
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)
{
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);
}
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