]> jfr.im git - solanum.git/blame - ircd/ircd_lexer.l
Show account name in cliconn snotes when SASL is used (#135)
[solanum.git] / ircd / ircd_lexer.l
CommitLineData
212380e3
AC
1/* src/ircd_lexer.l
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
16 * USA
17 *
212380e3
AC
18 */
19
20%option case-insensitive
21%option noyywrap
22%option nounput
23
24%{
25#include <sys/types.h>
26#include <sys/stat.h>
27
212380e3
AC
28#include <string.h>
29#include <errno.h>
30#include <limits.h>
31
32#define WE_ARE_MEMORY_C
33
34#include "stdinc.h"
35#include "ircd_defs.h"
9b8e9eb3 36#include "defaults.h"
93a426cb 37#include "logger.h"
212380e3
AC
38#include "s_conf.h"
39#include "newconf.h"
40
415b482c 41#include "ircd_parser.h"
212380e3
AC
42
43int yylex(void);
44
212380e3
AC
45#define MAX_INCLUDE_DEPTH 10
46
47YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
48int include_stack_ptr=0;
49int lineno = 1;
50void ccomment(void);
51void cinclude(void);
52void hashcomment(void);
53int ieof(void);
54int lineno_stack[MAX_INCLUDE_DEPTH];
7ac3261f
EM
55char conffile_stack[MAX_INCLUDE_DEPTH][BUFSIZE];
56char conffilebuf[BUFSIZE+1];
212380e3
AC
57char *current_file = conffilebuf;
58
59FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH];
60
401cb2bb 61char yy_linebuf[16384];
212380e3
AC
62
63#undef YY_INPUT
64
65#define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
66
67#define YY_INPUT(buf,result,max_size) \
68 if (!(result = conf_fgets(buf, max_size, conf_fbfile_in))) \
afba2488 69 YY_FATAL_ERROR("input in flex scanner failed");
212380e3
AC
70%}
71
72ws [ \t]*
73digit [0-9]
74comment #.*
75qstring \"[^\"\n]*[\"\n]
3d8f7aa7 76string [a-zA-Z_\~\:][a-zA-Z0-9_\:]*
212380e3
AC
77include \.include{ws}(\<.*\>|\".*\")
78
79%%
80{include} { cinclude(); }
81"/*" { ccomment(); }
401cb2bb 82\n.* { rb_strlcpy(yy_linebuf, yytext+1, sizeof(yy_linebuf)); lineno++; yyless(1); }
212380e3
AC
83
84{ws} ;
85{comment} { hashcomment(); }
86
87{digit}+ { yylval.number = atoi(yytext); return NUMBER; }
88
89{qstring} {
90 if(yytext[yyleng-2] == '\\')
91 {
92 yyless(yyleng-1); /* return last quote */
93 yymore(); /* append next string */
94 }
95 else
96 {
72640a9d 97 rb_strlcpy(yylval.string, yytext + 1, 1024);
212380e3
AC
98 if(yylval.string[yyleng-2] != '"')
99 ilog(L_MAIN, "Unterminated character string");
100 else
101 {
102 int i,j;
103 yylval.string[yyleng-2] = '\0'; /* remove close
afba2488 104 * quote
212380e3 105 */
afba2488 106
212380e3
AC
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++;
afba2488 116 if (yylval.string[i] == '\0') /* XXX
212380e3
AC
117 * should not
118 * happen
119 */
120 {
121 ilog(L_MAIN,
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
135loadmodule { return LOADMODULE; }
afba2488 136{string} {
72640a9d 137 rb_strlcpy(yylval.string, yytext, 1024);
212380e3
AC
138 yylval.string[yyleng] = '\0';
139 return STRING;
140 }
141
142\.\. { return TWODOTS; }
143. { return yytext[0]; }
144<<EOF>> { if (ieof()) yyterminate(); }
145%%
146
147/* C-comment ignoring routine -kre*/
148void ccomment()
149{
150 int c;
afba2488 151
212380e3
AC
152 /* log(L_NOTICE, "got comment"); */
153 while (1)
154 {
155 while ((c = input()) != '*' && c != EOF)
156 if (c == '\n') ++lineno;
157 if (c == '*')
158 {
159 while ((c = input()) == '*');
afba2488 160 if (c == '/')
212380e3 161 break;
4f3f411b 162 if (c == '\n') ++lineno;
212380e3
AC
163 }
164 if (c == EOF)
165 {
166 YY_FATAL_ERROR("EOF in comment");
167 /* XXX hack alert this disables
168 * the stupid unused function warning
169 * gcc generates
170 */
171 yy_fatal_error("EOF in comment");
172 break;
173 }
174 }
175}
176
177void cinclude(void)
178{
179 char *c;
180 if ((c = strchr(yytext, '<')) == NULL)
181 *strchr(c = strchr(yytext, '"') + 1, '"') = 0;
182 else
183 *strchr(++c, '>') = 0;
184
afba2488 185 /* do stacking and co. */
212380e3
AC
186 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
187 conf_report_error("Includes nested too deep (max is %d)", MAX_INCLUDE_DEPTH);
188 else
189 {
190 FILE *tmp_fbfile_in;
afba2488 191
212380e3 192 tmp_fbfile_in = fopen(c, "r");
afba2488 193
212380e3
AC
194 if (tmp_fbfile_in == NULL)
195 {
4d8cfacd 196 /* if its not found in PREFIX, look in IRCD_PATH_ETC */
7ac3261f 197 char fnamebuf[BUFSIZE];
212380e3 198
553dd5a7 199 snprintf(fnamebuf, sizeof(fnamebuf), "%s%c%s", ircd_paths[IRCD_PATH_ETC], RB_PATH_SEPARATOR, c);
212380e3
AC
200 tmp_fbfile_in = fopen(fnamebuf, "r");
201
202 /* wasnt found there either.. error. */
203 if(tmp_fbfile_in == NULL)
204 {
205 conf_report_error("Include %s: %s.", c, strerror(errno));
206 return;
207 }
208 }
209 lineno_stack[include_stack_ptr] = lineno;
210 lineno = 1;
211 inc_fbfile_in[include_stack_ptr] = conf_fbfile_in;
212 strcpy(conffile_stack[include_stack_ptr], c);
213 current_file = conffile_stack[include_stack_ptr];
214 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
215 conf_fbfile_in = tmp_fbfile_in;
216 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
217 }
218}
219
220int ieof(void)
221{
222 if (include_stack_ptr)
223 fclose(conf_fbfile_in);
224 if (--include_stack_ptr < 0)
225 {
226 /* We will now exit the lexer - restore init values if we get /rehash
227 * later and reenter lexer -kre */
228 include_stack_ptr = 0;
229 lineno = 1;
230 return 1;
231 }
232 /* switch buffer */
233 yy_delete_buffer(YY_CURRENT_BUFFER);
234 lineno = lineno_stack[include_stack_ptr];
235 conf_fbfile_in = inc_fbfile_in[include_stack_ptr];
236
237 if(include_stack_ptr)
238 current_file = conffile_stack[include_stack_ptr];
239 else
240 current_file = conffilebuf;
241
242 yy_switch_to_buffer(include_stack[include_stack_ptr]);
243 return 0;
244}
245
246/* #-comment style, look for #include */
247#define INCLUDE "#include"
248
249void hashcomment(void)
250{
251 if (strlen(yytext) < sizeof(INCLUDE) - 1)
252 return;
253
f956cb0f 254 if (!rb_strncasecmp(yytext, INCLUDE, sizeof(INCLUDE) - 1))
212380e3
AC
255 yyerror("You probably meant '.include', skipping");
256}