/[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 1474 - (show annotations)
Sun Jul 22 14:44:07 2012 UTC (10 years, 6 months ago) by michael
File size: 16312 byte(s)
- removed &localchannels

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

Properties

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

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