Add autoconnect option for Connect block.
[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$
21  */
22
23 %{
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "config.h"
28 #include "ircd.h"
29 #include "ircd_alloc.h"
30 #include "ircd_string.h"
31 #include "s_debug.h"
32 #include "y.tab.h"
33
34 extern int lineno;
35
36 static struct lexer_token {
37   const char *string;
38   int value;
39 } tokens[] = {
40 #define TOKEN(NAME) { #NAME, NAME }
41   TOKEN(ADMIN),
42   TOKEN(GENERAL),
43   TOKEN(LOCATION),
44   TOKEN(CONTACT),
45   TOKEN(CLASS),
46   TOKEN(PINGFREQ),
47   TOKEN(CONNECT),
48   TOKEN(CONNECTFREQ),
49   TOKEN(MAXLINKS),
50   TOKEN(MAXHOPS),
51   TOKEN(SENDQ),
52   TOKEN(NAME),
53   TOKEN(HOST),
54   TOKEN(IP),
55   TOKEN(USERNAME),
56   TOKEN(PASS),
57   TOKEN(SECONDS),
58   TOKEN(MINUTES),
59   TOKEN(HOURS),
60   TOKEN(DAYS),
61   TOKEN(WEEKS),
62   TOKEN(MONTHS),
63   TOKEN(YEARS),
64   TOKEN(DECADES),
65   TOKEN(BYTES),
66   TOKEN(KBYTES),
67   TOKEN(MBYTES),
68   TOKEN(GBYTES),
69   TOKEN(TBYTES),
70   TOKEN(PORT),
71   TOKEN(SERVER),
72   TOKEN(YES),
73   TOKEN(NO),
74   TOKEN(HUB),
75   TOKEN(LEAF),
76   TOKEN(UWORLD),
77   TOKEN(OPER),
78   TOKEN(LOCAL),
79   TOKEN(VHOST),
80   TOKEN(MASK),
81   TOKEN(HIDDEN),
82   TOKEN(MOTD),
83   TOKEN(NUMERIC),
84   TOKEN(NICK),
85   TOKEN(JUPE),
86   TOKEN(DESCRIPTION),
87   TOKEN(CLIENT),
88   TOKEN(REAL),
89   TOKEN(REASON),
90   TOKEN(RULE),
91   TOKEN(ALL),
92   TOKEN(CRULE),
93   TOKEN(KILL),
94   TOKEN(QUARANTINE),
95   TOKEN(IAUTH),
96   TOKEN(TIMEOUT),
97   TOKEN(FEATURES),
98   TOKEN(CHANNEL),
99   TOKEN(PSEUDO),
100   TOKEN(PREPEND),
101   TOKEN(USERMODE),
102   TOKEN(FAST),
103   TOKEN(AUTOCONNECT),
104 #undef TOKEN
105   { "administrator", ADMIN },
106   { "apass_opmode", TPRIV_APASS_OPMODE },
107   { "auto", AUTOCONNECT },
108   { "b", BYTES },
109   { "badchan", TPRIV_BADCHAN },
110   { "chan_limit", TPRIV_CHAN_LIMIT },
111   { "deop_lchan", TPRIV_DEOP_LCHAN },
112   { "die", TPRIV_DIE },
113   { "display", TPRIV_DISPLAY },
114   { "file", TFILE },
115   { "force_local_opmode", TPRIV_FORCE_LOCAL_OPMODE },
116   { "force_opmode", TPRIV_FORCE_OPMODE },
117   { "gline", TPRIV_GLINE },
118   { "kb", KBYTES },
119   { "kilobytes", KBYTES },
120   { "local_badchan", TPRIV_LOCAL_BADCHAN },
121   { "local_gline", TPRIV_LOCAL_GLINE },
122   { "local_jupe", TPRIV_LOCAL_JUPE },
123   { "local_kill", TPRIV_LOCAL_KILL },
124   { "local_opmode", TPRIV_LOCAL_OPMODE },
125   { "mb", MBYTES },
126   { "megabytes", MBYTES },
127   { "mode_lchan", TPRIV_MODE_LCHAN },
128   { "gb", GBYTES },
129   { "gigabytes", GBYTES },
130   { "operator", OPER },
131   { "opmode", TPRIV_OPMODE },
132   { "password", PASS },
133   { "propagate", TPRIV_PROPAGATE },
134   { "realname", REAL },
135   { "rehash", TPRIV_REHASH },
136   { "restart", TPRIV_RESTART },
137   { "see_chan", TPRIV_SEE_CHAN },
138   { "see_opers", TPRIV_SEE_OPERS },
139   { "set", TPRIV_SET },
140   { "show_all_invis", TPRIV_SHOW_ALL_INVIS },
141   { "show_invis", TPRIV_SHOW_INVIS },
142   { "tb", TBYTES },
143   { "terabytes", TBYTES },
144   { "unlimit_query", TPRIV_UNLIMIT_QUERY },
145   { "walk_lchan", TPRIV_WALK_LCHAN },
146   { "wide_gline", TPRIV_WIDE_GLINE },
147   { "whox", TPRIV_WHOX },
148   { NULL, 0 }
149 };
150 static int ntokens;
151
152 static int
153 token_compare(const void *pa, const void *pb)
154 {
155   const struct lexer_token *ta = pa;
156   const struct lexer_token *tb = pb;
157   unsigned int ii = 0;
158   int res;
159   while (ta->string[ii] && (ToLower(ta->string[ii]) == ToLower(tb->string[ii])))
160     ii++;
161   res = ToLower(tb->string[ii]) - ToLower(ta->string[ii]);
162   return res;
163 }
164
165 static void
166 init_ntokens(void)
167 {
168   for (ntokens = 0; tokens[ntokens].string; ++ntokens) ;
169   qsort(tokens, ntokens, sizeof(tokens[0]), token_compare);
170 }
171
172 static int
173 find_token(char *token)
174 {
175   struct lexer_token *tok;
176   if (!ntokens)
177     init_ntokens();
178   tok = bsearch(&token, tokens, ntokens, sizeof(tokens[0]), token_compare);
179   return tok ? tok->value : 0;
180 }
181
182 void
183 init_lexer(void)
184 {
185   yyin = fopen(configfile, "r");
186   if (yyin == NULL)
187   {
188 #ifdef YY_FATAL_ERROR
189     YY_FATAL_ERROR("Could not open the configuration file.");
190 #else
191     fprintf(stderr, "Could not open the configuration file.");
192 #endif
193   }
194 #ifdef YY_NEW_FILE
195   YY_NEW_FILE;
196 #endif
197   lineno = 1;
198 }
199
200 %}
201
202 WHITE [ \t\r]+
203 SHCOMMENT #[^\n]*
204 NUMBER [0-9]+
205 QSTRING \"[^"\n]+[\"\n]
206 %%
207
208 {QSTRING} {yytext[yyleng-1] = 0; DupString(yylval.text, yytext+1); return QSTRING;}
209 {NUMBER} {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
210 {WHITE} ;
211 {SHCOMMENT} ;
212
213 [a-zA-Z_]+ { int res = find_token(yytext); if (res) return res; else REJECT; }
214 \n lineno++;
215 . return yytext[0];