]> Pileus Git - ~andy/fetchmail/blob - rcfile_l.l
21f05b4ec992226a3f83adf390f69fc1ea573bdf
[~andy/fetchmail] / rcfile_l.l
1 %{
2
3 /*
4  * rcfile_l.l -- lexer for the run control file
5  *
6  * For license terms, see the file COPYING in this directory.
7  */
8 #include <string.h>
9
10 #include "config.h"
11 #include "fetchmail.h"
12 #include "rcfile_y.h"
13
14 int prc_lineno = 1;
15
16 #ifdef LEXDEBUG
17 #define SETSTATE(n)     do {BEGIN(n); if (yydebug) fprintf(stderr, "Entering lexer state %d\n", n);} while (0)
18 #else
19 #define SETSTATE(n)     BEGIN(n)
20 #endif /* LEXDEBUG */
21 %}
22
23 /* this doesn't work with Linux lex, see the INSTALL file */
24 %o 7000
25 %a 4000
26 %p 3000
27 %option nounput
28
29 %s NAME AUTH
30
31 %%
32
33 \"[^\"]*\"      {
34                         yytext[yyleng-1] = '\0';
35                         escapes(yytext+1, yytext);
36                         yyleng = strlen(yytext);
37                         yylval.sval = yytext;
38                         SETSTATE(0);
39                         return STRING;
40                 }
41 \'[^\']*\'      {
42                         yytext[yyleng-1] = '\0';
43                         escapes(yytext+1, yytext);
44                         yyleng = strlen(yytext);
45                         yylval.sval = yytext;
46                         SETSTATE(0);
47                         return STRING;
48                 }
49
50 "*"             { BEGIN(0); return WILDCARD; }
51
52 <NAME>[^=;:, \t\r\n]+   {
53                         static char *in;
54                         static size_t ins;
55
56                         if (yyleng + 1 > ins) {
57                             ins = yyleng + 1;
58                             in = xrealloc(in, ins);
59                         }
60                         memcpy(in, yytext, yyleng);
61                         in[yyleng] = '\0';
62                         escapes(in, in);
63                         yyleng = strlen(in);
64                         yylval.sval = in;
65                         SETSTATE(0);
66                         return STRING;
67                 }
68
69 set             { return SET; }
70 logfile         { return LOGFILE; }
71 idfile          { return IDFILE; }
72 daemon          { return DAEMON; }
73 syslog          { return SYSLOG; }
74 invisible       { return INVISIBLE; }
75 showdots        { return SHOWDOTS; }
76 postmaster      { return POSTMASTER; }
77 bouncemail      { return BOUNCEMAIL; }
78 spambounce      { return SPAMBOUNCE; }
79 warnings        { return WARNINGS; }
80 tracepolls      { return TRACEPOLLS; }
81
82 defaults        { return DEFAULTS; }
83 server          { return POLL; }
84 poll            { return POLL; }
85 skip            { return SKIP; }
86 via             { return VIA; }
87 aka             { return AKA; }
88 local(domains)  { return LOCALDOMAINS; }
89 proto(col)?     { return PROTOCOL; }
90 service         { return SERVICE; }
91 port            { return PORT; }
92 interval        { return INTERVAL; }
93 preauth(enticate)?      { SETSTATE(AUTH); return AUTHENTICATE; }
94 auth(enticate)? { SETSTATE(AUTH); return AUTHENTICATE; }
95 any             { SETSTATE(0); yylval.proto = A_ANY; return AUTHTYPE;}
96 gssapi          { SETSTATE(0); yylval.proto = A_GSSAPI; return AUTHTYPE;}
97 kerberos(_v)?4  { SETSTATE(0); yylval.proto = A_KERBEROS_V4; return AUTHTYPE;}
98 kerberos(_v)?5  { SETSTATE(0); yylval.proto = A_KERBEROS_V5; return AUTHTYPE;}
99 kerberos        { SETSTATE(0); yylval.proto = A_KERBEROS_V4; return AUTHTYPE;}
100 ssh             { SETSTATE(0); yylval.proto = A_SSH; return AUTHTYPE;}
101 (otp|opie)      { SETSTATE(0); yylval.proto = A_OTP; return AUTHTYPE;}
102 cram(-md5)?     { SETSTATE(0); yylval.proto = A_CRAM_MD5; return AUTHTYPE;}
103 ntlm            { SETSTATE(0); yylval.proto = A_NTLM; return AUTHTYPE;}
104 <AUTH>password  { SETSTATE(0); yylval.proto = A_PASSWORD; return AUTHTYPE;}
105 timeout         { return TIMEOUT;}
106 envelope        { return ENVELOPE; }
107 qvirtual        { return QVIRTUAL; }
108 principal       { return PRINCIPAL; }
109 esmtpname       { return ESMTPNAME; }
110 esmtppassword   { return ESMTPPASSWORD; }
111
112
113 user(name)?     {SETSTATE(NAME); return USERNAME; }
114 <INITIAL,NAME>pass(word)?       {SETSTATE(NAME); return PASSWORD; }
115 folder(s)?      { return FOLDER; }
116 smtp(host)?     { return SMTPHOST; }
117 fetchdomains    { return FETCHDOMAINS; }
118 smtpaddress     { return SMTPADDRESS; }
119 smtpname        { return SMTPNAME; }
120 antispam        { return SPAMRESPONSE; }
121 mda             { return MDA; }
122 bsmtp           { return BSMTP; }
123 lmtp            { return LMTP; }
124 pre(connect)?   { return PRECONNECT; }
125 post(connect)?  { return POSTCONNECT; }
126 interface       { return INTERFACE; }
127 monitor         { return MONITOR; }
128 plugin          { return PLUGIN; }
129 plugout         { return PLUGOUT; }
130 batchlimit      { return BATCHLIMIT; }
131 fetchlimit      { return FETCHLIMIT; }
132 fetchsizelimit  { return FETCHSIZELIMIT; }
133 fastuidl        { return FASTUIDL; }
134 expunge         { return EXPUNGE; }
135 properties      { return PROPERTIES; }
136
137 is              { SETSTATE(NAME); return IS; }
138 here            { return HERE; }
139 there           { return THERE; }
140 to              { SETSTATE(NAME); return TO; }
141 =               { SETSTATE(NAME); return MAP; }
142
143 nobouncemail    |
144 nouidl          |
145 nocheckalias    |
146 nodns           |
147 noenvelope      |
148 nokeep          |
149 noflush         |
150 nofetchall      |
151 norewrite       |
152 noforcecr       |
153 nostripcr       |
154 nopass8(bits)?  |
155 nodropstatus    |
156 nodropdelivered |
157 nomimedec(ode)? |
158 nospambounce    |
159 noidle          {
160                    yyless(2);
161                    return NO;
162                 }
163
164 no              {return NO;}
165
166 keep            { return KEEP; }
167 flush           { return FLUSH; }
168 fetchall        { return FETCHALL; }
169 rewrite         { return REWRITE; }
170 forcecr         { return FORCECR; }
171 stripcr         { return STRIPCR; }
172 pass8(bits)?    { return PASS8BITS; }
173 dropstatus      { return DROPSTATUS; }
174 dropdelivered   { return DROPDELIVERED; }
175 mimedec(ode)?   { return MIMEDECODE; }
176 idle            { return IDLE; }
177 dns             { return DNS; }
178 uidl            { return UIDL; }
179 ssl             { return SSL; }
180 sslkey          { return SSLKEY; }
181 sslcert         { return SSLCERT; }
182 sslproto        { return SSLPROTO; }
183 sslcertck       { return SSLCERTCK; }
184 sslcertpath     { return SSLCERTPATH; }
185 sslfingerprint  { return SSLFINGERPRINT; }
186 checkalias      { return CHECKALIAS; }
187
188 limit           { return LIMIT; }
189
190 with            {/* EMPTY */}
191 and             {/* EMPTY */}
192 has             {/* EMPTY */}
193 wants           {/* EMPTY */}
194 options         {/* EMPTY */}
195 [;:,]           {/* EMPTY */}
196
197 (auto)|(AUTO)   { yylval.proto = P_AUTO;  return PROTO; }
198 (pop2)|(POP2)   { yylval.proto = P_POP2;  return PROTO; }
199 (sdps)|(SDPS)   { return SDPS; }
200 (pop3)|(POP3)   { yylval.proto = P_POP3;  return PROTO; }
201 (imap)|(IMAP)   { yylval.proto = P_IMAP;  return PROTO; }
202 (apop)|(APOP)   { yylval.proto = P_APOP;  return PROTO; }
203 (rpop)|(RPOP)   { yylval.proto = P_RPOP;  return PROTO; }
204 (etrn)|(ETRN)   { yylval.proto = P_ETRN;  return PROTO; }
205 (odmr)|(ODMR)   { yylval.proto = P_ODMR;  return PROTO; }
206 (kpop)|(KPOP)   { return KPOP; }
207
208 (#.*)?\\?\n     { prc_lineno++; }   /* newline is ignored */
209
210 -?[0-9]+        { yylval.number = atoi(yytext); return NUMBER; }
211
212 [^=;:, \t\r\n]+ {
213                         escapes(yytext, yytext);
214                         yyleng = strlen(yytext);
215                         yylval.sval = yytext;
216                         return STRING;
217                 }
218
219 [ \t\r]+        ;       /* whitespace */
220
221 %%
222
223 void escapes(cp, tp)
224 /* process standard C-style escape sequences in a string,
225  * this can never lengthen the output, so cp and tp may overlap as long
226  * as cp >= tp. */
227 const char      *cp;    /* source string with escapes */
228 char            *tp;    /* target buffer for digested string */
229 {
230     while (*cp)
231     {
232         int     cval = 0;
233
234         if (*cp == '\\' && strchr("0123456789xX", cp[1]))
235         {
236             char *dp;
237             const char *hex = "00112233445566778899aAbBcCdDeEfF";
238             int dcount = 0;
239
240             if (*++cp == 'x' || *cp == 'X')
241                 for (++cp; (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
242                     cval = (cval * 16) + (dp - hex) / 2;
243             else if (*cp == '0')
244                 while (strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
245                     cval = (cval * 8) + (*cp++ - '0');
246             else
247                 while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
248                     cval = (cval * 10) + (*cp++ - '0');
249         }
250         else if (*cp == '\\')           /* C-style character escapes */
251         {
252             switch (*++cp)
253             {
254             case '\\': cval = '\\'; break;
255             case 'n': cval = '\n'; break;
256             case 't': cval = '\t'; break;
257             case 'b': cval = '\b'; break;
258             case 'r': cval = '\r'; break;
259             default: cval = *cp;
260             }
261             cp++;
262         }
263         else
264             cval = *cp++;
265         *tp++ = cval;
266     }
267     *tp = '\0';
268 }