]> Pileus Git - ~andy/fetchmail/blob - rcfile_l.l
Merge Sunil Shetye's --limitflush patch.
[~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 nolimitflush    |
151 nofetchall      |
152 norewrite       |
153 noforcecr       |
154 nostripcr       |
155 nopass8(bits)?  |
156 nodropstatus    |
157 nodropdelivered |
158 nomimedec(ode)? |
159 nospambounce    |
160 noidle          {
161                    yyless(2);
162                    return NO;
163                 }
164
165 no              {return NO;}
166
167 keep            { return KEEP; }
168 flush           { return FLUSH; }
169 limitflush      { return LIMITFLUSH; }
170 fetchall        { return FETCHALL; }
171 rewrite         { return REWRITE; }
172 forcecr         { return FORCECR; }
173 stripcr         { return STRIPCR; }
174 pass8(bits)?    { return PASS8BITS; }
175 dropstatus      { return DROPSTATUS; }
176 dropdelivered   { return DROPDELIVERED; }
177 mimedec(ode)?   { return MIMEDECODE; }
178 idle            { return IDLE; }
179 dns             { return DNS; }
180 uidl            { return UIDL; }
181 ssl             { return SSL; }
182 sslkey          { return SSLKEY; }
183 sslcert         { return SSLCERT; }
184 sslproto        { return SSLPROTO; }
185 sslcertck       { return SSLCERTCK; }
186 sslcertpath     { return SSLCERTPATH; }
187 sslfingerprint  { return SSLFINGERPRINT; }
188 checkalias      { return CHECKALIAS; }
189
190 limit           { return LIMIT; }
191
192 with            {/* EMPTY */}
193 and             {/* EMPTY */}
194 has             {/* EMPTY */}
195 wants           {/* EMPTY */}
196 options         {/* EMPTY */}
197 [;:,]           {/* EMPTY */}
198
199 (auto)|(AUTO)   { yylval.proto = P_AUTO;  return PROTO; }
200 (pop2)|(POP2)   { yylval.proto = P_POP2;  return PROTO; }
201 (sdps)|(SDPS)   { return SDPS; }
202 (pop3)|(POP3)   { yylval.proto = P_POP3;  return PROTO; }
203 (imap)|(IMAP)   { yylval.proto = P_IMAP;  return PROTO; }
204 (apop)|(APOP)   { yylval.proto = P_APOP;  return PROTO; }
205 (rpop)|(RPOP)   { yylval.proto = P_RPOP;  return PROTO; }
206 (etrn)|(ETRN)   { yylval.proto = P_ETRN;  return PROTO; }
207 (odmr)|(ODMR)   { yylval.proto = P_ODMR;  return PROTO; }
208 (kpop)|(KPOP)   { return KPOP; }
209
210 (#.*)?\\?\n     { prc_lineno++; }   /* newline is ignored */
211
212 -?[0-9]+        { yylval.number = atoi(yytext); return NUMBER; }
213
214 [^=;:, \t\r\n]+ {
215                         escapes(yytext, yytext);
216                         yyleng = strlen(yytext);
217                         yylval.sval = yytext;
218                         return STRING;
219                 }
220
221 [ \t\r]+        ;       /* whitespace */
222
223 %%
224
225 void escapes(cp, tp)
226 /* process standard C-style escape sequences in a string,
227  * this can never lengthen the output, so cp and tp may overlap as long
228  * as cp >= tp. */
229 const char      *cp;    /* source string with escapes */
230 char            *tp;    /* target buffer for digested string */
231 {
232     while (*cp)
233     {
234         int     cval = 0;
235
236         if (*cp == '\\' && strchr("0123456789xX", cp[1]))
237         {
238             char *dp;
239             const char *hex = "00112233445566778899aAbBcCdDeEfF";
240             int dcount = 0;
241
242             if (*++cp == 'x' || *cp == 'X')
243                 for (++cp; (dp = strchr(hex, *cp)) && (dcount++ < 2); cp++)
244                     cval = (cval * 16) + (dp - hex) / 2;
245             else if (*cp == '0')
246                 while (strchr("01234567",*cp) != (char*)NULL && (dcount++ < 3))
247                     cval = (cval * 8) + (*cp++ - '0');
248             else
249                 while ((strchr("0123456789",*cp)!=(char*)NULL)&&(dcount++ < 3))
250                     cval = (cval * 10) + (*cp++ - '0');
251         }
252         else if (*cp == '\\')           /* C-style character escapes */
253         {
254             switch (*++cp)
255             {
256             case '\\': cval = '\\'; break;
257             case 'n': cval = '\n'; break;
258             case 't': cval = '\t'; break;
259             case 'b': cval = '\b'; break;
260             case 'r': cval = '\r'; break;
261             default: cval = *cp;
262             }
263             cp++;
264         }
265         else
266             cval = *cp++;
267         *tp++ = cval;
268     }
269     *tp = '\0';
270 }