-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_gram.y
executable file
·184 lines (165 loc) · 4.35 KB
/
config_gram.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
%{
/* ======================================================================
* Copyright (c) 2000 Theo Schlossnagle
* All rights reserved.
* The following code was written by Theo Schlossnagle <[email protected]>
* This code was written to facilitate clustered logging via Spread.
* More information on Spread can be found at http://www.spread.org/
* Please refer to the LICENSE file before using this software.
* ======================================================================
*/
#include "sld_config.h"
extern int line_num, semantic_errors;
extern int buffsize;
extern char *sld_text;
extern char *module_dir;
static SpreadConfiguration *current_sc = NULL;
static LogFacility *current_lf = NULL;
int sld_error(char *str);
#define NEW_SC_IFNEEDED if(!current_sc) current_sc=config_new_spread_conf();
#define NEW_LF_IFNEEDED if(!current_sc) current_sc=config_new_spread_conf(); \
if(!current_lf) current_lf=config_new_logfacility();
%}
%start Config
%token BUFFERSIZE SPREAD PORT HOST LOG GROUP FILENAME MATCH VHOSTGROUP VHOSTDIR
%token OPENBRACE CLOSEBRACE EQUALS STRING CLF REWRITETIMES
%token PERLLIB PERLUSE PERLLOG PERLHUP PYTHONIMPORT PYTHONLOG PYTHONLIB
%token MODULEDIR LOADMODULE MODULELOG
%%
Config : Globals SpreadConfs
{ config_start(); }
;
Globals : GlobalParam Globals
|
;
GlobalParam : BUFFERSIZE EQUALS STRING
{ if(buffsize<0) {
buffsize = atoi($3);
}
}
| MODULEDIR EQUALS STRING
{ module_dir = strdup($3); }
| LOADMODULE STRING
{ module_load($2, NULL); }
| LOADMODULE STRING STRING
{ module_load($2, $3); }
| PERLLIB STRING
{
#ifdef PERL
perl_inc($2);
#else
fprintf(stderr, "PERL not compiled in\n");
exit(0);
#endif
}
| PERLUSE STRING
{
#ifdef PERL
perl_use($2);
#else
fprintf(stderr, "PERL not compiled in\n");
exit(0);
#endif
}
| PYTHONLIB STRING
{
#ifdef PYTHON
python_inc($2);
#else
fprintf(stderr, "PYTHON not compiled in\n");
exit(0);
#endif
}
| PYTHONIMPORT STRING
{
#ifdef PYTHON
python_import($2);
#else
fprintf(stderr, "PYTHON not compiled in\n");
exit(0);
#endif
}
SpreadConfs : SpreadConf SpreadConfs
| SpreadConf
;
SpreadConf : SPREAD OPENBRACE SPparams LogStructs CLOSEBRACE
{ config_add_spreadconf(current_sc);
current_sc = NULL; }
;
SPparams : SPparam SPparams
|
;
SPparam : PORT EQUALS STRING
{ NEW_SC_IFNEEDED;
config_set_spread_port(current_sc, $3); }
| HOST EQUALS STRING
{ NEW_SC_IFNEEDED;
config_set_spread_host(current_sc, $3); }
;
LogStructs : LogStruct LogStructs
|
;
LogStruct : LOG OPENBRACE Logparams CLOSEBRACE
{ config_add_logfacility(current_sc, current_lf);
current_lf = NULL; }
;
Logparams : Logparams Logparam
|
;
Logparam : GROUP EQUALS STRING
{ NEW_LF_IFNEEDED;
config_set_logfacility_group(current_lf, $3); }
| FILENAME EQUALS STRING
{ NEW_LF_IFNEEDED;
config_set_logfacility_filename(current_lf, $3); }
| MODULELOG STRING
{ NEW_LF_IFNEEDED;
config_set_logfacility_external_module(current_lf, $2);
}
| PERLLOG STRING
{ NEW_LF_IFNEEDED;
#ifdef PERL
config_set_logfacility_external_perl(current_lf, $2);
#else
fprintf(stderr, "PERL not compiled in\n");
exit(0);
#endif
}
| PERLHUP STRING
{ NEW_LF_IFNEEDED;
#ifdef PERL
config_set_hupfacility_external_perl(current_lf, $2);
#else
fprintf(stderr, "PERL not compiled in\n");
exit(0);
#endif
}
| PYTHONLOG STRING
{ NEW_LF_IFNEEDED;
#ifdef PYTHON
config_set_logfacility_external_python(current_lf, $2);
#else
fprintf(stderr, "PYTHON not compiled in\n");
exit(0);
#endif
}
| MATCH EQUALS STRING
{ NEW_LF_IFNEEDED;
config_add_logfacility_match(current_lf, $3); }
| VHOSTDIR EQUALS STRING
{ NEW_LF_IFNEEDED;
config_set_logfacility_vhostdir(current_lf, $3); }
| REWRITETIMES EQUALS CLF
{ NEW_LF_IFNEEDED;
config_set_logfaclity_rewritetimes_clf(current_lf); }
| REWRITETIMES EQUALS STRING
{ NEW_LF_IFNEEDED;
config_set_logfaclity_rewritetimes_user(current_lf,
$3); }
;
%%
int sld_error(char *str) {
fprintf(stderr, "Parser error on or before line %d\n", line_num);
fprintf(stderr, "Offending token: %s\n", sld_text);
return -1;
}