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