ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_lexer.l
Revision: 6599
Committed: Thu Oct 22 17:52:15 2015 UTC (10 years, 11 months ago) by michael
File size: 19492 byte(s)
Log Message:
- Added serverhide::flatten_links_file configuration option and get rid of LIPATH

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2000-2015 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file ircd_lexer.l
23 * \brief Scans the ircd configuration file for tokens.
24 * \version $Id$
25 */
26
27 %option case-insensitive
28 %option noyywrap
29 %option nounput
30 %option never-interactive
31
32 %{
33 #include "stdinc.h"
34 #include "irc_string.h"
35 #include "conf.h"
36 #include "conf_parser.h" /* autogenerated header file */
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 \n.* { strlcpy(linebuf, yytext + 1, sizeof(linebuf)); ++lineno; yyless(1); }
84 {WS} ;
85 {COMMENT} ;
86 {DIGIT} { yylval.number = atoi(yytext); return NUMBER; }
87 {qstring} { if (yytext[yyleng - 2] == '\\')
88 {
89 yyless(yyleng - 1); /* Return last quote */
90 yymore(); /* Append next string */
91 }
92 else
93 {
94 yylval.string = yytext + 1;
95
96 if (yylval.string[yyleng - 2] != '"')
97 ilog(LOG_TYPE_IRCD, "Unterminated character string");
98 else
99 {
100 unsigned int i = 0, j = 0;
101
102 yylval.string[yyleng - 2] = '\0'; /* Remove close quote */
103
104 for (; yylval.string[i] != '\0'; ++i, ++j)
105 {
106 if (yylval.string[i] != '\\')
107 yylval.string[j] = yylval.string[i];
108 else
109 {
110 ++i;
111
112 if (yylval.string[i] == '\0') /* XXX: should not happen */
113 {
114 ilog(LOG_TYPE_IRCD, "Unterminated character string");
115 break;
116 }
117
118 yylval.string[j] = yylval.string[i];
119 }
120 }
121
122 yylval.string[j] = '\0';
123 return QSTRING;
124 }
125 }
126 }
127
128 accept_password { return ACCEPT_PASSWORD; }
129 admin { return ADMIN; }
130 administrator { return ADMIN; }
131 aftype { return AFTYPE; }
132 all { return T_ALL; }
133 anti_nick_flood { return ANTI_NICK_FLOOD; }
134 anti_spam_exit_message_time { return ANTI_SPAM_EXIT_MESSAGE_TIME; }
135 auth { return IRCD_AUTH; }
136 autoconn { return AUTOCONN; }
137 away_count { return AWAY_COUNT; }
138 away_time { return AWAY_TIME; }
139 bots { return T_BOTS; }
140 caller_id_wait { return CALLER_ID_WAIT; }
141 callerid { return T_CALLERID; }
142 can_flood { return CAN_FLOOD; }
143 cconn { return T_CCONN; }
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 close { return CLOSE; }
149 cluster { return T_CLUSTER; }
150 command { return T_COMMAND; }
151 connect { return CONNECT; }
152 connectfreq { return CONNECTFREQ; }
153 cycle_on_host_change { return CYCLE_ON_HOST_CHANGE; }
154 deaf { return T_DEAF; }
155 debug { return T_DEBUG; }
156 default_floodcount { return DEFAULT_FLOODCOUNT; }
157 default_join_flood_count { return DEFAULT_JOIN_FLOOD_COUNT; }
158 default_join_flood_time { return DEFAULT_JOIN_FLOOD_TIME; }
159 default_max_clients { return DEFAULT_MAX_CLIENTS; }
160 deny { return DENY; }
161 description { return DESCRIPTION; }
162 die { return DIE; }
163 disable_auth { return DISABLE_AUTH; }
164 disable_fake_channels { return DISABLE_FAKE_CHANNELS; }
165 disable_remote_commands { return DISABLE_REMOTE_COMMANDS; }
166 dline { return T_DLINE; }
167 dline_min_cidr { return DLINE_MIN_CIDR; }
168 dline_min_cidr6 { return DLINE_MIN_CIDR6; }
169 dots_in_ident { return DOTS_IN_IDENT; }
170 email { return EMAIL; }
171 encrypted { return ENCRYPTED; }
172 exceed_limit { return EXCEED_LIMIT; }
173 exempt { return EXEMPT; }
174 external { return T_EXTERNAL; }
175 failed_oper_notice { return FAILED_OPER_NOTICE; }
176 farconnect { return T_FARCONNECT; }
177 file { return T_FILE; }
178 flags { return IRCD_FLAGS; }
179 flatten_links { return FLATTEN_LINKS; }
180 flatten_links_delay { return FLATTEN_LINKS_DELAY; }
181 flatten_links_file { return FLATTEN_LINKS_FILE; }
182 full { return T_FULL; }
183 gecos { return GECOS; }
184 general { return GENERAL; }
185 kline_min_cidr { return KLINE_MIN_CIDR; }
186 kline_min_cidr6 { return KLINE_MIN_CIDR6; }
187 globops { return T_GLOBOPS; }
188 have_ident { return NEED_IDENT; }
189 hidden { return HIDDEN; }
190 hidden_name { return HIDDEN_NAME; }
191 hidechans { return HIDE_CHANS; }
192 hideidle { return HIDE_IDLE; }
193 hide_idle_from_opers { return HIDE_IDLE_FROM_OPERS; }
194 hide_server_ips { return HIDE_SERVER_IPS; }
195 hide_servers { return HIDE_SERVERS; }
196 hide_services { return HIDE_SERVICES; }
197 host { return HOST; }
198 hub { return HUB; }
199 hub_mask { return HUB_MASK; }
200 ignore_bogus_ts { return IGNORE_BOGUS_TS; }
201 invisible { return T_INVISIBLE; }
202 invisible_on_connect { return INVISIBLE_ON_CONNECT; }
203 invite_client_count { return INVITE_CLIENT_COUNT; }
204 invite_client_time { return INVITE_CLIENT_TIME; }
205 ip { return IP; }
206 ipv4 { return T_IPV4; }
207 ipv6 { return T_IPV6; }
208 join { return JOIN; }
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 knock_client_count { return KNOCK_CLIENT_COUNT; }
214 knock_client_time { return KNOCK_CLIENT_TIME; }
215 knock_delay_channel { return KNOCK_DELAY_CHANNEL; }
216 leaf_mask { return LEAF_MASK; }
217 listen { return LISTEN; }
218 locops { return T_LOCOPS; }
219 log { return T_LOG; }
220 mask { return MASK; }
221 masked { return TMASKED; }
222 max_accept { return MAX_ACCEPT; }
223 max_bans { return MAX_BANS; }
224 max_channels { return MAX_CHANNELS; }
225 max_global { return MAX_GLOBAL; }
226 max_ident { return MAX_IDENT; }
227 max_idle { return MAX_IDLE; }
228 max_local { return MAX_LOCAL; }
229 max_nick_changes { return MAX_NICK_CHANGES; }
230 max_nick_length { return MAX_NICK_LENGTH; }
231 max_nick_time { return MAX_NICK_TIME; }
232 max_number { return MAX_NUMBER; }
233 max_targets { return MAX_TARGETS; }
234 max_topic_length { return MAX_TOPIC_LENGTH; }
235 max_watch { return MAX_WATCH; }
236 min_idle { return MIN_IDLE; }
237 min_nonwildcard { return MIN_NONWILDCARD; }
238 min_nonwildcard_simple { return MIN_NONWILDCARD_SIMPLE; }
239 module { return MODULE; }
240 modules { return MODULES; }
241 motd { return MOTD; }
242 name { return NAME; }
243 nchange { return T_NCHANGE; }
244 need_ident { return NEED_IDENT; }
245 need_password { return NEED_PASSWORD; }
246 network_desc { return NETWORK_DESC; }
247 network_name { return NETWORK_NAME; }
248 nick { return NICK; }
249 no_oper_flood { return NO_OPER_FLOOD; }
250 no_tilde { return NO_TILDE; }
251 nononreg { return T_NONONREG; }
252 number_per_cidr { return NUMBER_PER_CIDR; }
253 number_per_ip { return NUMBER_PER_IP; }
254 oper { return OPERATOR; }
255 oper_only_umodes { return OPER_ONLY_UMODES; }
256 oper_umodes { return OPER_UMODES; }
257 operator { return OPERATOR; }
258 opers_bypass_callerid { return OPERS_BYPASS_CALLERID; }
259 opme { return T_OPME; }
260 pace_wait { return PACE_WAIT; }
261 pace_wait_simple { return PACE_WAIT_SIMPLE; }
262 passwd { return PASSWORD; }
263 password { return PASSWORD; }
264 path { return PATH; }
265 ping_cookie { return PING_COOKIE; }
266 ping_time { return PING_TIME; }
267 port { return PORT; }
268 prepend { return T_PREPEND; }
269 pseudo { return T_PSEUDO; }
270 quarantine { return RESV; }
271 random_idle { return RANDOM_IDLE; }
272 reason { return REASON; }
273 recvq { return T_RECVQ; }
274 redirport { return REDIRPORT; }
275 redirserv { return REDIRSERV; }
276 rehash { return REHASH; }
277 rej { return T_REJ; }
278 remote { return REMOTE; }
279 remoteban { return REMOTEBAN; }
280 restart { return T_RESTART; }
281 resv { return RESV; }
282 resv_exempt { return RESV_EXEMPT; }
283 rsa_private_key_file { return RSA_PRIVATE_KEY_FILE; }
284 send_password { return SEND_PASSWORD; }
285 sendq { return SENDQ; }
286 server { return T_SERVER; }
287 serverhide { return SERVERHIDE; }
288 serverinfo { return SERVERINFO; }
289 service { return T_SERVICE; }
290 servnotice { return T_SERVNOTICE; }
291 set { return T_SET; }
292 shared { return T_SHARED; }
293 short_motd { return SHORT_MOTD; }
294 sid { return IRCD_SID; }
295 size { return T_SIZE; }
296 skill { return T_SKILL; }
297 softcallerid { return T_SOFTCALLERID; }
298 spoof { return SPOOF; }
299 spoof_notice { return SPOOF_NOTICE; }
300 spy { return T_SPY; }
301 squit { return SQUIT; }
302 ssl { return T_SSL; }
303 ssl_certificate_file { return SSL_CERTIFICATE_FILE; }
304 ssl_certificate_fingerprint { return SSL_CERTIFICATE_FINGERPRINT; }
305 ssl_cipher_list { return T_SSL_CIPHER_LIST; }
306 ssl_connection_required { return SSL_CONNECTION_REQUIRED; }
307 ssl_dh_elliptic_curve { return SSL_DH_ELLIPTIC_CURVE; }
308 ssl_dh_param_file { return SSL_DH_PARAM_FILE; }
309 ssl_message_digest_algorithm { return SSL_MESSAGE_DIGEST_ALGORITHM; }
310 stats_e_disabled { return STATS_E_DISABLED; }
311 stats_i_oper_only { return STATS_I_OPER_ONLY; }
312 stats_k_oper_only { return STATS_K_OPER_ONLY; }
313 stats_m_oper_only { return STATS_M_OPER_ONLY; }
314 stats_o_oper_only { return STATS_O_OPER_ONLY; }
315 stats_P_oper_only { return STATS_P_OPER_ONLY; }
316 stats_u_oper_only { return STATS_U_OPER_ONLY; }
317 target { return T_TARGET; }
318 throttle_count { return THROTTLE_COUNT; }
319 throttle_time { return THROTTLE_TIME; }
320 tkline_expire_notices { return TKLINE_EXPIRE_NOTICES; }
321 ts_max_delta { return TS_MAX_DELTA; }
322 ts_warn_delta { return TS_WARN_DELTA; }
323 type { return TYPE; }
324 umodes { return T_UMODES; }
325 unauth { return T_UNAUTH; }
326 undline { return T_UNDLINE; }
327 unkline { return UNKLINE; }
328 unlimited { return T_UNLIMITED; }
329 unresv { return T_UNRESV; }
330 unxline { return T_UNXLINE; }
331 use_logging { return USE_LOGGING; }
332 user { return USER; }
333 vhost { return VHOST; }
334 vhost6 { return VHOST6; }
335 wallop { return T_WALLOP; }
336 wallops { return T_WALLOPS; }
337 warn_no_connect_block { return WARN_NO_CONNECT_BLOCK; }
338 webirc { return T_WEBIRC; }
339 whois { return WHOIS; }
340 xline { return XLINE; }
341 xline_exempt { return XLINE_EXEMPT; }
342
343 yes { yylval.number = 1; return TBOOL; }
344 no { yylval.number = 0; return TBOOL; }
345
346 years { return YEARS; }
347 year { return YEARS; }
348 months { return MONTHS; }
349 month { return MONTHS; }
350 weeks { return WEEKS; }
351 week { return WEEKS; }
352 days { return DAYS; }
353 day { return DAYS; }
354 hours { return HOURS; }
355 hour { return HOURS; }
356 minutes { return MINUTES; }
357 minute { return MINUTES; }
358 seconds { return SECONDS; }
359 second { return SECONDS; }
360
361 bytes { return BYTES; }
362 byte { return BYTES; }
363 kilobytes { return KBYTES; }
364 kilobyte { return KBYTES; }
365 kbytes { return KBYTES; }
366 kbyte { return KBYTES; }
367 kb { return KBYTES; }
368 megabytes { return MBYTES; }
369 megabyte { return MBYTES; }
370 mbytes { return MBYTES; }
371 mbyte { return MBYTES; }
372 mb { return MBYTES; }
373 \.\. { return TWODOTS; }
374
375 . { return yytext[0]; }
376 <<EOF>> { if (ieof()) yyterminate(); }
377
378 %%
379
380 /* C-comment ignoring routine -kre*/
381 static void
382 ccomment(void)
383 {
384 int c = 0;
385
386 /* log(L_NOTICE, "got comment"); */
387 while (1)
388 {
389 while ((c = input()) != '*' && c != EOF)
390 if (c == '\n')
391 ++lineno;
392
393 if (c == '*')
394 {
395 while ((c = input()) == '*')
396 /* Nothing */ ;
397 if (c == '/')
398 break;
399 else if (c == '\n')
400 ++lineno;
401 }
402
403 if (c == EOF)
404 {
405 YY_FATAL_ERROR("EOF in comment");
406 /* XXX hack alert this disables
407 * the stupid unused function warning
408 * gcc generates
409 */
410 if (1 == 0)
411 yy_fatal_error("EOF in comment");
412 break;
413 }
414 }
415 }
416
417 /* C-style .includes. This function will properly swap input conf buffers,
418 * and lineno -kre */
419 static void
420 cinclude(void)
421 {
422 char *p = NULL;
423
424 if ((p = strchr(yytext, '<')) == NULL)
425 *strchr(p = strchr(yytext, '"') + 1, '"') = '\0';
426 else
427 *strchr(++p, '>') = '\0';
428
429 /* log(L_NOTICE, "got include %s!", c); */
430
431 /* do stacking and co. */
432 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
433 ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p);
434 else
435 {
436 FILE *tmp_fbfile_in = NULL;
437 char filenamebuf[IRCD_BUFSIZE];
438
439 if (*p == '/') /* if it is an absolute path */
440 snprintf(filenamebuf, sizeof(filenamebuf), "%s", p);
441 else
442 snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p);
443
444 tmp_fbfile_in = fopen(filenamebuf, "r");
445
446 if (tmp_fbfile_in == NULL)
447 {
448 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
449 filenamebuf, strerror(errno));
450 return;
451 }
452
453 lineno_stack[include_stack_ptr] = lineno;
454 lineno = 1;
455 inc_fbfile_in[include_stack_ptr] = conf_parser_ctx.conf_file;
456 strlcpy(conffile_stack[include_stack_ptr], conffilebuf, IRCD_BUFSIZE);
457 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
458 conf_parser_ctx.conf_file = tmp_fbfile_in;
459 snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf);
460 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
461 }
462 }
463
464 /* This is function that will be called on EOF in conf file. It will
465 * apropriately close conf if it not main conf and swap input buffers -kre
466 * */
467 static int
468 ieof(void)
469 {
470 /* log(L_NOTICE, "return from include stack!"); */
471 if (include_stack_ptr)
472 fclose(conf_parser_ctx.conf_file);
473 if (--include_stack_ptr < 0)
474 {
475 /* log(L_NOTICE, "terminating lexer"); */
476 /* We will now exit the lexer - restore init values if we get /rehash
477 * later and reenter lexer -kre */
478 include_stack_ptr = 0;
479 lineno = 1;
480 return 1;
481 }
482
483 /* switch buffer */
484 /* log(L_NOTICE, "deleting include_stack_ptr=%d", include_stack_ptr); */
485 yy_delete_buffer(YY_CURRENT_BUFFER);
486 lineno = lineno_stack[include_stack_ptr];
487 conf_parser_ctx.conf_file = inc_fbfile_in[include_stack_ptr];
488 strlcpy(conffilebuf, conffile_stack[include_stack_ptr], sizeof(conffilebuf));
489 yy_switch_to_buffer(include_stack[include_stack_ptr]);
490
491 return 0;
492 }

Properties

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