ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_lexer.l
Revision: 1832
Committed: Fri Apr 19 19:16:09 2013 UTC (10 years, 11 months ago) by michael
File size: 15621 byte(s)
Log Message:
- Made all numeric defines use the actual string instead of the numeric value
  which allows to use gcc's printf format attribute
- Remove current message locale implementation

File Contents

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

Properties

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