aboutsummaryrefslogtreecommitdiffstats
path: root/cfg_file.y
diff options
context:
space:
mode:
Diffstat (limited to 'cfg_file.y')
-rw-r--r--cfg_file.y186
1 files changed, 179 insertions, 7 deletions
diff --git a/cfg_file.y b/cfg_file.y
index b4675f077..26b97871a 100644
--- a/cfg_file.y
+++ b/cfg_file.y
@@ -2,27 +2,32 @@
%{
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/queue.h>
#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <glib.h>
#include "cfg_file.h"
-#define YYDEBUG 0
+#define YYDEBUG 1
extern struct config_file *cfg;
extern int yylineno;
extern char *yytext;
+struct scriptq *cur_scripts;
%}
+
%union
{
char *string;
@@ -30,6 +35,7 @@ extern char *yytext;
char flag;
unsigned int seconds;
unsigned int number;
+ struct script_param *param;
}
%token ERROR STRING QUOTEDSTRING FLAG
@@ -38,20 +44,24 @@ extern char *yytext;
%token MAXSIZE SIZELIMIT SECONDS BEANSTALK MYSQL USER PASSWORD DATABASE
%token TEMPDIR PIDFILE SERVERS ERROR_TIME DEAD_TIME MAXERRORS CONNECT_TIMEOUT PROTOCOL RECONNECT_TIMEOUT
%token READ_SERVERS WRITE_SERVER DIRECTORY_SERVERS MAILBOX_QUERY USERS_QUERY LASTLOGIN_QUERY
-%token MEMCACHED WORKERS
+%token MEMCACHED WORKERS REQUIRE MODULE
+%token FILTER METRIC SCRIPT_HEADER SCRIPT_MIME SCRIPT_MESSAGE SCRIPT_URL SCRIPT_CHAIN SCRIPT_PARAM
%type <string> STRING
%type <string> QUOTEDSTRING
-%type <string> FILENAME
+%type <string> FILENAME
%type <string> SOCKCRED
%type <string> IPADDR IPNETWORK
%type <string> HOSTPORT
%type <string> DOMAIN
+%type <string> SCRIPT_PARAM
%type <limit> SIZELIMIT
%type <flag> FLAG
%type <seconds> SECONDS
%type <number> NUMBER
%type <string> memcached_hosts bind_cred
+%type <number> metric
+%type <param> filter_param
%%
file : /* empty */
@@ -64,16 +74,18 @@ command :
| pidfile
| memcached
| workers
+ | require
+ | filter
;
tempdir :
- TEMPDIR EQSIGN FILENAME {
+ TEMPDIR EQSIGN QUOTEDSTRING {
cfg->temp_dir = $3;
}
;
pidfile :
- PIDFILE EQSIGN FILENAME {
+ PIDFILE EQSIGN QUOTEDSTRING {
cfg->pid_file = $3;
}
;
@@ -101,7 +113,7 @@ bind_cred:
| HOSTPORT {
$$ = $1;
}
- | FILENAME {
+ | QUOTEDSTRING {
$$ = $1;
}
;
@@ -188,6 +200,166 @@ workers:
cfg->workers_number = $3;
}
;
+
+filter:
+ FILTER OBRACE filterbody EBRACE
+ ;
+
+filterbody:
+ metric SEMICOLON filter_chain {
+ struct filter_chain *cur_chain;
+ cur_chain = (struct filter_chain *) g_malloc (sizeof (struct filter_chain));
+ if (cur_chain == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror (errno));
+ YYERROR;
+ }
+
+ cur_chain->metric = $1;
+ cur_chain->scripts = cur_scripts;
+ LIST_INSERT_HEAD (&cfg->filters, cur_chain, next);
+
+ }
+ ;
+
+metric:
+ METRIC EQSIGN NUMBER {
+ $$ = $3;
+ }
+ ;
+
+filter_chain:
+ filter_param SEMICOLON {
+ cur_scripts = (struct scriptq *)g_malloc (sizeof (struct scriptq));
+ if (cur_scripts == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror (errno));
+ YYERROR;
+ }
+ LIST_INIT (cur_scripts);
+ if ($1 == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ LIST_INSERT_HEAD (cur_scripts, $1, next);
+ }
+ | filter_chain filter_param SEMICOLON {
+ if ($2 == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ LIST_INSERT_HEAD (cur_scripts, $2, next);
+ }
+ ;
+
+filter_param:
+ SCRIPT_HEADER EQSIGN SCRIPT_PARAM {
+ struct script_param *cur;
+
+ cur = g_malloc (sizeof (struct script_param));
+ if (cur == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ if (parse_script ($3, cur, SCRIPT_HEADER) == -1) {
+ yyerror ("yyparse: cannot parse filter param %s", $3);
+ YYERROR;
+ }
+
+ $$ = cur;
+ free ($3);
+ }
+ | SCRIPT_MIME EQSIGN SCRIPT_PARAM {
+ struct script_param *cur;
+
+ cur = g_malloc (sizeof (struct script_param));
+ if (cur == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ if (parse_script ($3, cur, SCRIPT_MIME) == -1) {
+ yyerror ("yyparse: cannot parse filter param %s", $3);
+ YYERROR;
+ }
+
+ $$ = cur;
+ free ($3);
+ }
+ | SCRIPT_MESSAGE EQSIGN SCRIPT_PARAM {
+ struct script_param *cur;
+
+ cur = g_malloc (sizeof (struct script_param));
+ if (cur == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ if (parse_script ($3, cur, SCRIPT_MESSAGE) == -1) {
+ yyerror ("yyparse: cannot parse filter param %s", $3);
+ YYERROR;
+ }
+
+ $$ = cur;
+ free ($3);
+ }
+ | SCRIPT_URL EQSIGN SCRIPT_PARAM {
+ struct script_param *cur;
+
+ cur = g_malloc (sizeof (struct script_param));
+ if (cur == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ if (parse_script ($3, cur, SCRIPT_URL) == -1) {
+ yyerror ("yyparse: cannot parse filter param %s", $3);
+ YYERROR;
+ }
+
+ $$ = cur;
+ free ($3);
+ }
+ | SCRIPT_CHAIN EQSIGN SCRIPT_PARAM {
+ struct script_param *cur;
+
+ cur = g_malloc (sizeof (struct script_param));
+ if (cur == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ if (parse_script ($3, cur, SCRIPT_CHAIN) == -1) {
+ yyerror ("yyparse: cannot parse filter param %s", $3);
+ YYERROR;
+ }
+
+ $$ = cur;
+ free ($3);
+ }
+ ;
+
+require:
+ REQUIRE OBRACE requirebody EBRACE
+ ;
+
+requirebody:
+ requirecmd SEMICOLON
+ | requirebody requirecmd SEMICOLON
+ ;
+
+requirecmd:
+ MODULE EQSIGN QUOTEDSTRING {
+ struct stat st;
+ struct perl_module *cur;
+ if (stat ($3, &st) == -1) {
+ yyerror ("yyparse: cannot stat file %s, %m", $3);
+ YYERROR;
+ }
+ cur = g_malloc (sizeof (struct perl_module));
+ if (cur == NULL) {
+ yyerror ("yyparse: g_malloc: %s", strerror(errno));
+ YYERROR;
+ }
+ cur->path = $3;
+ LIST_INSERT_HEAD (&cfg->modules, cur, next);
+ }
+ ;
+
%%
/*
* vi:ts=4