ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/ircd_lexer.l
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
File size: 16393 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


File Contents

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

Properties

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