/[svn]/ircd-hybrid-8/src/conf_lexer.l
ViewVC logotype

Contents of /ircd-hybrid-8/src/conf_lexer.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1324 - (show annotations)
Fri Mar 30 21:40:38 2012 UTC (7 years, 9 months ago) by michael
File size: 16011 byte(s)
- Remove log::timestamp configuration directive. Timestamps are now enabled by default.
- Timestamps are iso8601 now

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * conf_lexer.l: Scans the ircd configuration file for tokens.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 %option case-insensitive
26 %option noyywrap
27 %option nounput
28 %option never-interactive
29
30 %{
31 #include "stdinc.h"
32 #include "irc_string.h"
33 #include "conf.h"
34 #include "conf_parser.h" /* autogenerated header file */
35 #include "memory.h"
36 #include "hostmask.h"
37 #include "log.h"
38
39 #undef YY_INPUT
40 #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
41 #define YY_INPUT(buf,result,max_size) \
42 if (!(result = conf_fbgets(buf, max_size, conf_parser_ctx.conf_file))) \
43 YY_FATAL_ERROR("input in flex scanner failed");
44 #define MAX_INCLUDE_DEPTH 10
45
46
47 unsigned int lineno = 1;
48 char linebuf[IRCD_BUFSIZE];
49 char conffilebuf[IRCD_BUFSIZE];
50
51 static int include_stack_ptr = 0;
52 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
53 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
54 static FBFILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
55 static char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE];
56 static void ccomment(void);
57 static void cinclude(void);
58 static int ieof(void);
59 %}
60
61 WS [[:blank:]]*
62 DIGIT [[:digit:]]+
63 COMMENT ("//"|"#").*
64 qstring \"[^\"\n]*[\"\n]
65 include \.include{WS}(\<.*\>|\".*\")
66
67 %%
68 {include} { cinclude(); }
69 "/*" { ccomment(); }
70
71 \n.* { strcpy(linebuf, yytext+1); ++lineno; yyless(1); }
72
73 {WS} ;
74 {COMMENT} ;
75
76 {DIGIT} { yylval.number = atoi(yytext); return NUMBER; }
77
78 {qstring} { if (yytext[yyleng-2] == '\\')
79 {
80 yyless(yyleng-1); /* return last quote */
81 yymore(); /* append next string */
82 }
83 else
84 {
85 yylval.string = yytext+1;
86 if(yylval.string[yyleng-2] != '"')
87 ilog(LOG_TYPE_IRCD, "Unterminated character string");
88 else
89 {
90 int i,j;
91
92 yylval.string[yyleng-2] = '\0'; /* remove close
93 * quote
94 */
95
96 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
97 {
98 if (yylval.string[i] != '\\')
99 {
100 yylval.string[j] = yylval.string[i];
101 }
102 else
103 {
104 i++;
105 if (yylval.string[i] == '\0') /* XXX
106 * should not
107 * happen
108 */
109 {
110 ilog(LOG_TYPE_IRCD,
111 "Unterminated character string");
112 break;
113 }
114 yylval.string[j] = yylval.string[i];
115 }
116 }
117 yylval.string[j] = '\0';
118 return QSTRING;
119 }
120 }
121 }
122
123 accept_password { return ACCEPT_PASSWORD; }
124 action { return ACTION; }
125 admin { return ADMIN; }
126 administrator { return ADMIN; }
127 aftype { return AFTYPE; }
128 all { return T_ALL; }
129 allow { return T_ALLOW; }
130 auth { return IRCD_AUTH; }
131 autoconn { return AUTOCONN; }
132 block { return T_BLOCK; }
133 burst_away { return BURST_AWAY; }
134 burst_topicwho { return BURST_TOPICWHO; }
135 can_flood { return CAN_FLOOD; }
136 caller_id_wait { return CALLER_ID_WAIT; }
137 opers_bypass_callerid { return OPERS_BYPASS_CALLERID; }
138 channel { return CHANNEL; }
139 cidr_bitlen_ipv4 { return CIDR_BITLEN_IPV4; }
140 cidr_bitlen_ipv6 { return CIDR_BITLEN_IPV6; }
141 class { return CLASS; }
142 client_flood { return T_CLIENT_FLOOD; }
143 cluster { return T_CLUSTER; }
144 connect { return CONNECT; }
145 connectfreq { return CONNECTFREQ; }
146 default_floodcount { return DEFAULT_FLOODCOUNT; }
147 default_split_server_count { return DEFAULT_SPLIT_SERVER_COUNT; }
148 default_split_user_count { return DEFAULT_SPLIT_USER_COUNT; }
149 deny { return DENY; }
150 description { return DESCRIPTION; }
151 die { return DIE; }
152 disable_auth { return DISABLE_AUTH; }
153 disable_fake_channels { return DISABLE_FAKE_CHANNELS; }
154 disable_hidden { return DISABLE_HIDDEN; }
155 disable_local_channels { return DISABLE_LOCAL_CHANNELS; }
156 disable_remote_commands { return DISABLE_REMOTE_COMMANDS; }
157 dline { return T_DLINE; }
158 dots_in_ident { return DOTS_IN_IDENT; }
159 duration { return DURATION; }
160 egdpool_path { return EGDPOOL_PATH; }
161 email { return EMAIL; }
162 enable { return ENABLE; }
163 encrypted { return ENCRYPTED; }
164 exceed_limit { return EXCEED_LIMIT; }
165 exempt { return EXEMPT; }
166 file { return T_FILE; }
167 flags { return IRCD_FLAGS; }
168 flatten_links { return FLATTEN_LINKS; }
169 gecos { return GECOS; }
170 general { return GENERAL; }
171 gline { return GLINE; }
172 glines { return GLINES; }
173 gline_exempt { return GLINE_EXEMPT; }
174 gline_min_cidr { return GLINE_MIN_CIDR; }
175 gline_min_cidr6 { return GLINE_MIN_CIDR6; }
176 globops { return T_GLOBOPS; }
177 global_kill { return GLOBAL_KILL; }
178 have_ident { return NEED_IDENT; }
179 need_ident { return NEED_IDENT; }
180 havent_read_conf { return HAVENT_READ_CONF; }
181 hidden { return HIDDEN; }
182 hidden_name { return HIDDEN_NAME; }
183 hide_server_ips { return HIDE_SERVER_IPS; }
184 hide_servers { return HIDE_SERVERS; }
185 hide_spoof_ips { return HIDE_SPOOF_IPS; }
186 host { return HOST; }
187 hub { return HUB; }
188 hub_mask { return HUB_MASK; }
189 ignore_bogus_ts { return IGNORE_BOGUS_TS; }
190 invisible_on_connect { return INVISIBLE_ON_CONNECT; }
191 ip { return IP; }
192 ipv4 { return T_IPV4; }
193 ipv6 { return T_IPV6; }
194 join_flood_count { return JOIN_FLOOD_COUNT; }
195 join_flood_time { return JOIN_FLOOD_TIME; }
196 kill { return KILL; }
197 kill_chase_time_limit { return KILL_CHASE_TIME_LIMIT; }
198 kline { return KLINE; }
199 kline_exempt { return KLINE_EXEMPT; }
200 leaf_mask { return LEAF_MASK; }
201 listen { return LISTEN; }
202 log { return T_LOG; }
203 masked { return TMASKED; }
204 max_clients { return T_MAX_CLIENTS; }
205 max_ident { return MAX_IDENT; }
206 max_local { return MAX_LOCAL; }
207 max_global { return MAX_GLOBAL; }
208 max_number { return MAX_NUMBER; }
209 max_watch { return MAX_WATCH; }
210 message_locale { return MESSAGE_LOCALE; }
211 min_nonwildcard { return MIN_NONWILDCARD; }
212 min_nonwildcard_simple { return MIN_NONWILDCARD_SIMPLE; }
213 name { return NAME; }
214 need_password { return NEED_PASSWORD; }
215 network_desc { return NETWORK_DESC; }
216 network_name { return NETWORK_NAME; }
217 nick { return NICK; }
218 nick_changes { return NICK_CHANGES; }
219 no { yylval.number = 0; return TBOOL; }
220 no_create_on_split { return NO_CREATE_ON_SPLIT; }
221 no_join_on_split { return NO_JOIN_ON_SPLIT; }
222 no_oper_flood { return NO_OPER_FLOOD; }
223 no_tilde { return NO_TILDE; }
224 number_per_cidr { return NUMBER_PER_CIDR; }
225 number_per_ip { return NUMBER_PER_IP; }
226 oper { return OPERATOR; }
227 oper_pass_resv { return OPER_PASS_RESV; }
228 operator { return OPERATOR; }
229 passwd { return PASSWORD; }
230 password { return PASSWORD; }
231 ping_cookie { return PING_COOKIE; }
232 ping_time { return PING_TIME; }
233 ping_warning { return PING_WARNING; }
234 port { return PORT; }
235 quarantine { return RESV; }
236 quiet_on_ban { return QUIET_ON_BAN; }
237 reason { return REASON; }
238 redirport { return REDIRPORT; }
239 redirserv { return REDIRSERV; }
240 regex { return REGEX_T; }
241 rehash { return REHASH; }
242 reject { return T_REJECT; }
243 reject_hold_time { return TREJECT_HOLD_TIME; }
244 remote { return REMOTE; }
245 remoteban { return REMOTEBAN; }
246 restart { return T_RESTART; }
247 restrict_channels { return RESTRICT_CHANNELS; }
248 resv { return RESV; }
249 resv_exempt { return RESV_EXEMPT; }
250 rsa_private_key_file { return RSA_PRIVATE_KEY_FILE; }
251 rsa_public_key_file { return RSA_PUBLIC_KEY_FILE; }
252 ssl { return T_SSL; }
253 ssl_certificate_file { return SSL_CERTIFICATE_FILE; }
254 ssl_client_method { return T_SSL_CLIENT_METHOD; }
255 ssl_server_method { return T_SSL_SERVER_METHOD; }
256 ssl_dh_param_file { return SSL_DH_PARAM_FILE; }
257 ssl_cipher_list { return T_SSL_CIPHER_LIST; }
258 sslv3 { return T_SSLV3; }
259 tlsv1 { return T_TLSV1; }
260 send_password { return SEND_PASSWORD; }
261 sendq { return SENDQ; }
262 server { return T_SERVER; }
263 serverhide { return SERVERHIDE; }
264 serverinfo { return SERVERINFO; }
265 service { return T_SERVICE; }
266 services_name { return T_SERVICES_NAME; }
267 shared { return T_SHARED; }
268 short_motd { return SHORT_MOTD; }
269 sid { return IRCD_SID; }
270 silent { return SILENT; }
271 size { return T_SIZE; }
272 spoof { return SPOOF; }
273 spoof_notice { return SPOOF_NOTICE; }
274 tkline_expire_notices { return TKLINE_EXPIRE_NOTICES; }
275 type { return TYPE; }
276 true_no_oper_flood { return TRUE_NO_OPER_FLOOD; }
277 umodes { return T_UMODES; }
278 unkline { return UNKLINE; }
279 undline { return T_UNDLINE; }
280 unlimited { return T_UNLIMITED; }
281 use_egd { return USE_EGD; }
282 use_except { return USE_EXCEPT; }
283 use_invex { return USE_INVEX; }
284 use_knock { return USE_KNOCK; }
285 use_logging { return USE_LOGGING; }
286 use_whois_actually { return USE_WHOIS_ACTUALLY; }
287 throttle_time { return THROTTLE_TIME; }
288 user { return USER; }
289 tkline { return TKLINE; }
290 txline { return TXLINE; }
291 tresv { return TRESV; }
292 vhost { return VHOST; }
293 vhost6 { return VHOST6; }
294 warn { return WARN; }
295 xline { return XLINE; }
296 yes { yylval.number = 1; return TBOOL; }
297
298 failed_oper_notice { return FAILED_OPER_NOTICE; }
299 max_accept { return MAX_ACCEPT; }
300 max_nick_changes { return MAX_NICK_CHANGES; }
301 max_chans_per_user { return MAX_CHANS_PER_USER; }
302 max_nick_time { return MAX_NICK_TIME; }
303 anti_nick_flood { return ANTI_NICK_FLOOD; }
304 anti_spam_exit_message_time { return ANTI_SPAM_EXIT_MESSAGE_TIME; }
305 ts_max_delta { return TS_MAX_DELTA; }
306 ts_warn_delta { return TS_WARN_DELTA; }
307 links_delay { return LINKS_DELAY; }
308 kline_reason { return KLINE_REASON; }
309 kline_with_reason { return KLINE_WITH_REASON; }
310 warn_no_nline { return WARN_NO_NLINE; }
311
312 stats_e_disabled { return STATS_E_DISABLED; }
313 stats_o_oper_only { return STATS_O_OPER_ONLY; }
314 stats_k_oper_only { return STATS_K_OPER_ONLY; }
315 stats_i_oper_only { return STATS_I_OPER_ONLY; }
316 stats_P_oper_only { return STATS_P_OPER_ONLY; }
317 pace_wait { return PACE_WAIT; }
318 pace_wait_simple { return PACE_WAIT_SIMPLE; }
319 knock_delay { return KNOCK_DELAY; }
320 knock_delay_channel { return KNOCK_DELAY_CHANNEL; }
321 max_bans { return MAX_BANS; }
322 modules { return MODULES; }
323 module { return MODULE; }
324 path { return PATH; }
325 max_targets { return MAX_TARGETS; }
326
327 unxline { return T_UNXLINE; }
328 unresv { return T_UNRESV; }
329
330 oper_only_umodes { return OPER_ONLY_UMODES; }
331 oper_umodes { return OPER_UMODES; }
332 bots { return T_BOTS; }
333 cconn { return T_CCONN; }
334 cconn_full { return T_CCONN_FULL; }
335 deaf { return T_DEAF; }
336 debug { return T_DEBUG; }
337 full { return T_FULL; }
338 skill { return T_SKILL; }
339 nchange { return T_NCHANGE; }
340 rej { return T_REJ; }
341 unauth { return T_UNAUTH; }
342 spy { return T_SPY; }
343 external { return T_EXTERNAL; }
344 operwall { return T_OPERWALL; }
345 servnotice { return T_SERVNOTICE; }
346 invisible { return T_INVISIBLE; }
347 wallop { return T_WALLOP; }
348 callerid { return T_CALLERID; }
349 softcallerid { return T_SOFTCALLERID; }
350 drone { return T_DRONE; }
351 locops { return T_LOCOPS; }
352 topicburst { return TOPICBURST; }
353
354 weeks { return WEEKS; }
355 week { return WEEKS; }
356 days { return DAYS; }
357 day { return DAYS; }
358 hours { return HOURS; }
359 hour { return HOURS; }
360 minutes { return MINUTES; }
361 minute { return MINUTES; }
362 seconds { return SECONDS; }
363 second { return SECONDS; }
364
365 bytes { return BYTES; }
366 byte { return BYTES; }
367 kilobytes { return KBYTES; }
368 kilobyte { return KBYTES; }
369 kbytes { return KBYTES; }
370 kbyte { return KBYTES; }
371 kb { return KBYTES; }
372 megabytes { return MBYTES; }
373 megabyte { return MBYTES; }
374 mbytes { return MBYTES; }
375 mbyte { return MBYTES; }
376 mb { return MBYTES; }
377 gigabytes { return GBYTES; }
378 gigabyte { return GBYTES; }
379 gbytes { return GBYTES; }
380 gbyte { return GBYTES; }
381 gb { return GBYTES; }
382 terabytes { return TBYTES; }
383 terabyte { return TBYTES; }
384 tbytes { return TBYTES; }
385 tbyte { return TBYTES; }
386 tb { return TBYTES; }
387 \.\. { return TWODOTS; }
388
389 . { return yytext[0]; }
390 <<EOF>> { if (ieof()) yyterminate(); }
391
392 %%
393
394 /* C-comment ignoring routine -kre*/
395 static void
396 ccomment(void)
397 {
398 int c = 0;
399
400 /* log(L_NOTICE, "got comment"); */
401 while (1)
402 {
403 while ((c = input()) != '*' && c != EOF)
404 if (c == '\n')
405 ++lineno;
406
407 if (c == '*')
408 {
409 while ((c = input()) == '*')
410 /* Nothing */ ;
411 if (c == '/')
412 break;
413 else if (c == '\n')
414 ++lineno;
415 }
416
417 if (c == EOF)
418 {
419 YY_FATAL_ERROR("EOF in comment");
420 /* XXX hack alert this disables
421 * the stupid unused function warning
422 * gcc generates
423 */
424 if (1 == 0)
425 yy_fatal_error("EOF in comment");
426 break;
427 }
428 }
429 }
430
431 /* C-style .includes. This function will properly swap input conf buffers,
432 * and lineno -kre */
433 static void
434 cinclude(void)
435 {
436 char *p = NULL;
437
438 if ((p = strchr(yytext, '<')) == NULL)
439 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
440 else
441 *strchr(++p, '>') = '\0';
442
443 /* log(L_NOTICE, "got include %s!", c); */
444
445 /* do stacking and co. */
446 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
447 ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p);
448 else
449 {
450 FBFILE *tmp_fbfile_in = NULL;
451 char filenamebuf[IRCD_BUFSIZE];
452
453 if (*p == '/') /* if it is an absolute path */
454 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
455 else
456 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p);
457
458 tmp_fbfile_in = fbopen(filenamebuf, "r");
459
460 if (tmp_fbfile_in == NULL)
461 {
462 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
463 filenamebuf, strerror(errno));
464 return;
465 }
466
467 lineno_stack[include_stack_ptr] = lineno;
468 lineno = 1;
469 inc_fbfile_in[include_stack_ptr] = conf_parser_ctx.conf_file;
470 strlcpy(conffile_stack[include_stack_ptr], conffilebuf, IRCD_BUFSIZE);
471 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
472 conf_parser_ctx.conf_file = tmp_fbfile_in;
473 snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf);
474 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
475 }
476 }
477
478 /* This is function that will be called on EOF in conf file. It will
479 * apropriately close conf if it not main conf and swap input buffers -kre
480 * */
481 static int
482 ieof(void)
483 {
484 /* log(L_NOTICE, "return from include stack!"); */
485 if (include_stack_ptr)
486 fbclose(conf_parser_ctx.conf_file);
487 if (--include_stack_ptr < 0)
488 {
489 /* log(L_NOTICE, "terminating lexer"); */
490 /* We will now exit the lexer - restore init values if we get /rehash
491 * later and reenter lexer -kre */
492 include_stack_ptr = 0;
493 lineno = 1;
494 return 1;
495 }
496
497 /* switch buffer */
498 /* log(L_NOTICE, "deleting include_stack_ptr=%d", include_stack_ptr); */
499 yy_delete_buffer(YY_CURRENT_BUFFER);
500 lineno = lineno_stack[include_stack_ptr];
501 conf_parser_ctx.conf_file = inc_fbfile_in[include_stack_ptr];
502 strlcpy(conffilebuf, conffile_stack[include_stack_ptr], sizeof(conffilebuf));
503 yy_switch_to_buffer(include_stack[include_stack_ptr]);
504
505 return 0;
506 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26