fixed ssl.c bug when ssl backend returns IO_BLOCKED but IO engine doesn't get informe...
[ircu2.10.12-pk.git] / ircd / ircd_lexer.l
1 /*
2  * ircd_lexer.l: A lexical scanner for ircd config files.
3  * This is part of ircu, an Internet Relay Chat server.
4  * The contents of this file are Copyright(C) 2001 by Andrew Miller, the
5  * ircd-hybrid team and the ircu team.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19  *  USA.
20  * $Id: ircd_lexer.l 1851 2007-11-30 22:10:04Z klmitch $
21  */
22
23 %{
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "config.h"
29 #include "fileio.h"
30 #include "ircd.h"
31 #include "ircd_alloc.h"
32 #include "ircd_string.h"
33 #include "s_debug.h"
34 #include "y.tab.h"
35
36 extern int lineno;
37
38 static struct lexer_token {
39   const char *string;
40   int value;
41 } tokens[] = {
42 #define TOKEN(NAME) { #NAME, NAME }
43   TOKEN(ADMIN),
44   TOKEN(GENERAL),
45   TOKEN(LOCATION),
46   TOKEN(CONTACT),
47   TOKEN(CLASS),
48   TOKEN(PINGFREQ),
49   TOKEN(CONNECT),
50   TOKEN(CONNECTFREQ),
51   TOKEN(MAXLINKS),
52   TOKEN(MAXHOPS),
53   TOKEN(SENDQ),
54   TOKEN(NAME),
55   TOKEN(HOST),
56   TOKEN(IP),
57   TOKEN(USERNAME),
58   TOKEN(PASS),
59   TOKEN(SECONDS),
60   TOKEN(MINUTES),
61   TOKEN(HOURS),
62   TOKEN(DAYS),
63   TOKEN(WEEKS),
64   TOKEN(MONTHS),
65   TOKEN(YEARS),
66   TOKEN(DECADES),
67   TOKEN(BYTES),
68   TOKEN(KBYTES),
69   TOKEN(MBYTES),
70   TOKEN(GBYTES),
71   TOKEN(TBYTES),
72   TOKEN(PORT),
73   TOKEN(SERVER),
74   TOKEN(YES),
75   TOKEN(NO),
76   TOKEN(HUB),
77   TOKEN(LEAF),
78   TOKEN(UWORLD),
79   TOKEN(OPER),
80   TOKEN(LOCAL),
81   TOKEN(VHOST),
82   TOKEN(MASK),
83   TOKEN(HIDDEN),
84   TOKEN(MOTD),
85   TOKEN(NUMERIC),
86   TOKEN(NICK),
87   TOKEN(JUPE),
88   TOKEN(DESCRIPTION),
89   TOKEN(CLIENT),
90   TOKEN(REAL),
91   TOKEN(REASON),
92   TOKEN(RULE),
93   TOKEN(ALL),
94   TOKEN(CRULE),
95   TOKEN(KILL),
96   TOKEN(QUARANTINE),
97   TOKEN(IAUTH),
98   TOKEN(TIMEOUT),
99   TOKEN(FEATURES),
100   TOKEN(CHANNEL),
101   TOKEN(PSEUDO),
102   TOKEN(PREPEND),
103   TOKEN(USERMODE),
104   TOKEN(FAST),
105   TOKEN(AUTOCONNECT),
106   TOKEN(PROGRAM),
107   TOKEN(DNS),
108   TOKEN(FORWARDS),
109   TOKEN(SECURE),
110   TOKEN(WEBIRC),
111   TOKEN(SPOOF),
112   TOKEN(REQUIRED),
113   TOKEN(SSL),
114   TOKEN(CERT),
115   TOKEN(CACERT),
116 #undef TOKEN
117   { "administrator", ADMIN },
118   { "apass_opmode", TPRIV_APASS_OPMODE },
119   { "auto", AUTOCONNECT },
120   { "b", BYTES },
121   { "badchan", TPRIV_BADCHAN },
122   { "chan_limit", TPRIV_CHAN_LIMIT },
123   { "deop_lchan", TPRIV_DEOP_LCHAN },
124   { "die", TPRIV_DIE },
125   { "display", TPRIV_DISPLAY },
126   { "file", TFILE },
127   { "force_local_opmode", TPRIV_FORCE_LOCAL_OPMODE },
128   { "force_opmode", TPRIV_FORCE_OPMODE },
129   { "gb", GBYTES },
130   { "gigabytes", GBYTES },
131   { "gline", TPRIV_GLINE },
132   { "hide_channels", TPRIV_UMODE_NOCHAN },
133   { "hide_idletime", TPRIV_UMODE_NOIDLE },
134   { "umode_nochan", TPRIV_UMODE_NOCHAN },
135   { "umode_noidle", TPRIV_UMODE_NOIDLE },
136   { "extra_hide_idletime", TPRIV_HIDE_IDLETIME },
137   { "hide_idletime", TPRIV_HIDE_IDLETIME },
138   { "ipv4", TOK_IPV4 },
139   { "ipv6", TOK_IPV6 },
140   { "kb", KBYTES },
141   { "kilobytes", KBYTES },
142   { "list_chan", TPRIV_LIST_CHAN },
143   { "local_badchan", TPRIV_LOCAL_BADCHAN },
144   { "local_gline", TPRIV_LOCAL_GLINE },
145   { "local_jupe", TPRIV_LOCAL_JUPE },
146   { "local_kill", TPRIV_LOCAL_KILL },
147   { "local_opmode", TPRIV_LOCAL_OPMODE },
148   { "maxchans", MAXCHANS },
149   { "mb", MBYTES },
150   { "megabytes", MBYTES },
151   { "mode_lchan", TPRIV_MODE_LCHAN },
152   { "more_flood", TPRIV_HALFFLOOD },
153   { "noamsg_override", TPRIV_NOAMSG_OVERRIDE },
154   { "operator", OPER },
155   { "opmode", TPRIV_OPMODE },
156   { "password", PASS },
157   { "propagate", TPRIV_PROPAGATE },
158   { "realname", REAL },
159   { "rehash", TPRIV_REHASH },
160   { "restart", TPRIV_RESTART },
161   { "see_chan", TPRIV_SEE_CHAN },
162   { "see_idletime", TPRIV_SEE_IDLETIME },
163   { "see_opers", TPRIV_SEE_OPERS },
164   { "set", TPRIV_SET },
165   { "show_all_invis", TPRIV_SHOW_ALL_INVIS },
166   { "show_invis", TPRIV_SHOW_INVIS },
167   { "targetchange", TPRIV_UNLIMITED_TARGET },
168   { "unlimited_targets", TPRIV_UNLIMITED_TARGET },
169   { "tb", TBYTES },
170   { "terabytes", TBYTES },
171   { "umode_chserv", TPRIV_UMODE_CHSERV },
172   { "umode_xtraop", TPRIV_UMODE_XTRAOP },
173   { "umode_netserv", TPRIV_UMODE_NETSERV },
174   { "umode_overridecc", TPRIV_UMODE_OVERRIDECC },
175   { "unlimit_query", TPRIV_UNLIMIT_QUERY },
176   { "unlimited_flood", TPRIV_FLOOD },
177   { "walk_lchan", TPRIV_WALK_LCHAN },
178   { "wide_gline", TPRIV_WIDE_GLINE },
179   { "whox", TPRIV_WHOX },
180   { NULL, 0 }
181 };
182 static int ntokens;
183
184 static int
185 token_compare(const void *pa, const void *pb)
186 {
187   const struct lexer_token *ta = pa;
188   const struct lexer_token *tb = pb;
189   unsigned int ii = 0;
190   int res;
191   while (ta->string[ii] && (ToLower(ta->string[ii]) == ToLower(tb->string[ii])))
192     ii++;
193   res = ToLower(tb->string[ii]) - ToLower(ta->string[ii]);
194   return res;
195 }
196
197 static void
198 init_ntokens(void)
199 {
200   for (ntokens = 0; tokens[ntokens].string; ++ntokens) ;
201   qsort(tokens, ntokens, sizeof(tokens[0]), token_compare);
202 }
203
204 static int
205 find_token(char *token)
206 {
207   struct lexer_token *tok;
208   if (!ntokens)
209     init_ntokens();
210   tok = bsearch(&token, tokens, ntokens, sizeof(tokens[0]), token_compare);
211   return tok ? tok->value : 0;
212 }
213
214 static FBFILE *lexer_input;
215
216 #undef YY_INPUT
217 #define YY_INPUT(buf, res, size) res = (fbgets(buf, size, lexer_input) ? strlen(buf) : 0)
218
219 int
220 init_lexer(void)
221 {
222   lexer_input = fbopen(configfile, "r");
223   if (lexer_input == NULL)
224   {
225 #ifdef YY_FATAL_ERROR
226     YY_FATAL_ERROR("Could not open the configuration file.");
227 #else
228     fprintf(stderr, "Could not open the configuration file.");
229 #endif
230     return 0;
231   }
232 #ifdef YY_NEW_FILE
233   YY_NEW_FILE;
234 #endif
235   lineno = 1;
236   return 1;
237 }
238
239 void deinit_lexer(void)
240 {
241   if (lexer_input != NULL)
242   {
243     fbclose(lexer_input);
244     lexer_input = NULL;
245   }
246 }
247
248 int
249 yywrap(void)
250 {
251   return 1;
252 }
253
254 %}
255
256 WHITE [ \t\r]+
257 SHCOMMENT #[^\n]*
258 NUMBER [0-9]+
259 QSTRING \"[^"\n]+[\"\n]
260 %%
261
262 {QSTRING} {yytext[yyleng-1] = 0; DupString(yylval.text, yytext+1); return QSTRING;}
263 {NUMBER} {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
264 {WHITE} ;
265 {SHCOMMENT} ;
266
267 [a-zA-Z_][a-zA-Z_0-9]* { int res = find_token(yytext); if (res) return res; else REJECT; }
268 \n lineno++;
269 . return yytext[0];