/[svn]/ircd-hybrid-7.2/src/ircd_lexer.l
ViewVC logotype

Contents of /ircd-hybrid-7.2/src/ircd_lexer.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1011 - (show annotations)
Fri Sep 18 10:14:09 2009 UTC (10 years, 1 month ago) by michael
File size: 16802 byte(s)
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

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

Properties

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

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