1e28409c56950d99d08008c6b2c6744c0f07da13
[sip-router] / cfg.lex
1 /*
2  * $Id$
3  *
4  * scanner for cfg files
5  *
6  * Copyright (C) 2001-2003 Fhg Fokus
7  *
8  * This file is part of ser, a free SIP server.
9  *
10  * ser is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version
14  *
15  * For a license to use the ser software under conditions
16  * other than those described here, or to purchase support for this
17  * software, please contact iptel.org by e-mail at the following addresses:
18  *    info@iptel.org
19  *
20  * ser is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License 
26  * along with this program; if not, write to the Free Software 
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  *
29  * History:
30  * -------
31  *  2003-01-29  src_port added (jiri)
32  *  2003-01-23  mhomed added (jiri)
33  *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34  *  2003-04-01  added dst_port, proto (tcp, udp, tls), af(inet, inet6) (andrei)
35  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
36  *  2003-04-12  added force_rport, chdir and wdir (andrei)
37  *  2003-04-22  strip_tail added (jiri)
38  *  2003-07-03  tls* (disable, certificate, private_key, ca_list, verify, 
39  *               require_certificate added (andrei)
40  *  2003-07-06  more tls config. vars added: tls_method, tls_port_no (andrei)
41  *  2003-10-02  added {,set_}advertised_{address,port} (andrei)
42  *  2003-10-07  added hex and octal numbers support (andrei)
43  *  2003-10-10  replaced len_gt w/ msg:len (andrei)
44  *  2003-10-13  added fifo_dir (andrei)
45  *  2003-10-28  added tcp_accept_aliases (andrei)
46  *  2003-11-29  added {tcp_send, tcp_connect, tls_*}_timeout (andrei)
47  *  2004-03-30  added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
48  *  2004-04-28  added sock_mode (replaces fifo_mode), sock_user &
49  *               sock_group  (andrei)
50  *  2004-05-03  applied multicast support patch from janakj
51  *              added MCAST_TTL (andrei)
52  */
53
54
55 %{
56         #include "cfg.tab.h"
57         #include "dprint.h"
58         #include "globals.h"
59         #include "mem/mem.h"
60         #include <string.h>
61         #include <stdlib.h>
62         #include "ip_addr.h"
63
64
65         /* states */
66         #define INITIAL_S               0
67         #define COMMENT_S               1
68         #define COMMENT_LN_S    2
69         #define STRING_S                3
70
71         
72         static int comment_nest=0;
73         static int state=0;
74         static char* tstr=0;
75         int line=1;
76         int column=1;
77         int startcolumn=1;
78
79         static char* addstr(char*, char**);
80         static void count();
81
82
83 %}
84
85 /* start conditions */
86 %x STRING1 STRING2 COMMENT COMMENT_LN
87
88 /* action keywords */
89 FORWARD forward
90 FORWARD_TCP     forward_tcp
91 FORWARD_UDP     forward_udp
92 FORWARD_TLS     forward_tls
93 DROP    "drop"|"break"
94 SEND    send
95 SEND_TCP        send_tcp
96 LOG             log
97 ERROR   error
98 ROUTE   route
99 ROUTE_FAILURE failure_route
100 ROUTE_ONREPLY onreply_route
101 EXEC    exec
102 FORCE_RPORT             "force_rport"|"add_rport"
103 FORCE_TCP_ALIAS         "force_tcp_alias"|"add_tcp_alias"
104 SETFLAG         setflag
105 RESETFLAG       resetflag
106 ISFLAGSET       isflagset
107 SET_HOST                "rewritehost"|"sethost"|"seth"
108 SET_HOSTPORT    "rewritehostport"|"sethostport"|"sethp"
109 SET_USER                "rewriteuser"|"setuser"|"setu"
110 SET_USERPASS    "rewriteuserpass"|"setuserpass"|"setup"
111 SET_PORT                "rewriteport"|"setport"|"setp"
112 SET_URI                 "rewriteuri"|"seturi"
113 REVERT_URI              "revert_uri"
114 PREFIX                  "prefix"
115 STRIP                   "strip"
116 STRIP_TAIL              "strip_tail"
117 APPEND_BRANCH   "append_branch"
118 IF                              "if"
119 ELSE                    "else"
120 SET_ADV_ADDRESS "set_advertised_address"
121 SET_ADV_PORT    "set_advertised_port"
122
123 /*ACTION LVALUES*/
124 URIHOST                 "uri:host"
125 URIPORT                 "uri:port"
126
127 MAX_LEN                 "max_len"
128
129
130 /* condition keywords */
131 METHOD  method
132 /* hack -- the second element in first line is referrable
133    as either uri or status; it only would makes sense to
134    call it "uri" from route{} and status from onreply_route{}
135 */
136 URI             "uri"|"status"
137 SRCIP   src_ip
138 SRCPORT src_port
139 DSTIP   dst_ip
140 DSTPORT dst_port
141 PROTO   proto
142 AF              af
143 MYSELF  myself
144 MSGLEN                  "msg:len"
145 /* operators */
146 EQUAL   =
147 EQUAL_T ==
148 GT      >
149 LT      <
150 GTE     >=
151 LTE     <=
152 DIFF    !=
153 MATCH   =~
154 NOT             !|"not"
155 AND             "and"|"&&"|"&"
156 OR              "or"|"||"|"|"
157
158 /* config vars. */
159 DEBUG   debug
160 FORK    fork
161 LOGSTDERROR     log_stderror
162 LOGFACILITY     log_facility
163 LISTEN          listen
164 ALIAS           alias
165 DNS              dns
166 REV_DNS  rev_dns
167 PORT    port
168 STAT    statistics
169 MAXBUFFER maxbuffer
170 CHILDREN children
171 CHECK_VIA       check_via
172 SYN_BRANCH syn_branch
173 MEMLOG          "memlog"|"mem_log"
174 SIP_WARNING sip_warning
175 FIFO fifo
176 FIFO_DIR  fifo_dir
177 SOCK_MODE "fifo_mode"|"sock_mode"|"file_mode"
178 SOCK_USER "fifo_user"|"sock_user"
179 SOCK_GROUP "fifo_group"|"sock_group"
180 FIFO_DB_URL fifo_db_url
181 UNIX_SOCK unix_sock
182 UNIX_SOCK_CHILDREN unix_sock_children
183 UNIX_TX_TIMEOUT unix_tx_timeout
184 SERVER_SIGNATURE server_signature
185 REPLY_TO_VIA reply_to_via
186 USER            "user"|"uid"
187 GROUP           "group"|"gid"
188 CHROOT          "chroot"
189 WDIR            "workdir"|"wdir"
190 MHOMED          mhomed
191 DISABLE_TCP             "disable_tcp"
192 TCP_CHILDREN    "tcp_children"
193 TCP_ACCEPT_ALIASES      "tcp_accept_aliases"
194 TCP_SEND_TIMEOUT        "tcp_send_timeout"
195 TCP_CONNECT_TIMEOUT     "tcp_connect_timeout"
196 DISABLE_TLS             "disable_tls"
197 TLSLOG                  "tlslog"|"tls_log"
198 TLS_PORT_NO             "tls_port_no"
199 TLS_METHOD              "tls_method"
200 TLS_VERIFY              "tls_verify"
201 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
202 TLS_CERTIFICATE "tls_certificate"
203 TLS_PRIVATE_KEY "tls_private_key"
204 TLS_CA_LIST             "tls_ca_list"
205 TLS_HANDSHAKE_TIMEOUT   "tls_handshake_timeout"
206 TLS_SEND_TIMEOUT        "tls_send_timeout"
207 ADVERTISED_ADDRESS      "advertised_address"
208 ADVERTISED_PORT         "advertised_port"
209 DISABLE_CORE            "disable_core_dump"
210 OPEN_FD_LIMIT           "open_files_limit"
211 MCAST_LOOPBACK          "mcast_loopback"
212 MCAST_TTL                       "mcast_ttl"
213
214 LOADMODULE      loadmodule
215 MODPARAM        modparam
216
217 /* values */
218 YES                     "yes"|"true"|"on"|"enable"
219 NO                      "no"|"false"|"off"|"disable"
220 UDP                     "udp"|"UDP"
221 TCP                     "tcp"|"TCP"
222 TLS                     "tls"|"TLS"
223 INET            "inet"|"INET"
224 INET6           "inet6"|"INET6"
225 SSLv23                  "sslv23"|"SSLv23"|"SSLV23"
226 SSLv2                   "sslv2"|"SSLv2"|"SSLV2"
227 SSLv3                   "sslv3"|"SSLv3"|"SSLV3"
228 TLSv1                   "tlsv1"|"TLSv1"|"TLSV1"
229
230 LETTER          [a-zA-Z]
231 DIGIT           [0-9]
232 ALPHANUM        {LETTER}|{DIGIT}|[_]
233 NUMBER          0|([1-9]{DIGIT}*)
234 ID                      {LETTER}{ALPHANUM}*
235 HEX                     [0-9a-fA-F]
236 HEXNUMBER       0x{HEX}+
237 OCTNUMBER       0[0-7]+
238 HEX4            {HEX}{1,4}
239 IPV6ADDR        ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
240 QUOTES          \"
241 TICK            \'
242 SLASH           "/"
243 SEMICOLON       ;
244 RPAREN          \)
245 LPAREN          \(
246 LBRACE          \{
247 RBRACE          \}
248 LBRACK          \[
249 RBRACK          \]
250 COMMA           ","
251 COLON           ":"
252 STAR            \*
253 DOT                     \.
254 CR                      \n
255
256
257
258 COM_LINE        #
259 COM_START       "/\*"
260 COM_END         "\*/"
261
262 EAT_ABLE        [\ \t\b\r]
263
264 %%
265
266
267 <INITIAL>{EAT_ABLE}     { count(); }
268
269 <INITIAL>{FORWARD}      {count(); yylval.strval=yytext; return FORWARD; }
270 <INITIAL>{FORWARD_TCP}  {count(); yylval.strval=yytext; return FORWARD_TCP; }
271 <INITIAL>{FORWARD_TLS}  {count(); yylval.strval=yytext; return FORWARD_TLS; }
272 <INITIAL>{FORWARD_UDP}  {count(); yylval.strval=yytext; return FORWARD_UDP; }
273 <INITIAL>{DROP} { count(); yylval.strval=yytext; return DROP; }
274 <INITIAL>{SEND} { count(); yylval.strval=yytext; return SEND; }
275 <INITIAL>{SEND_TCP}     { count(); yylval.strval=yytext; return SEND_TCP; }
276 <INITIAL>{LOG}  { count(); yylval.strval=yytext; return LOG_TOK; }
277 <INITIAL>{ERROR}        { count(); yylval.strval=yytext; return ERROR; }
278 <INITIAL>{SETFLAG}      { count(); yylval.strval=yytext; return SETFLAG; }
279 <INITIAL>{RESETFLAG}    { count(); yylval.strval=yytext; return RESETFLAG; }
280 <INITIAL>{ISFLAGSET}    { count(); yylval.strval=yytext; return ISFLAGSET; }
281 <INITIAL>{MSGLEN}       { count(); yylval.strval=yytext; return MSGLEN; }
282 <INITIAL>{ROUTE}        { count(); yylval.strval=yytext; return ROUTE; }
283 <INITIAL>{ROUTE_ONREPLY}        { count(); yylval.strval=yytext;
284                                                                 return ROUTE_ONREPLY; }
285 <INITIAL>{ROUTE_FAILURE}        { count(); yylval.strval=yytext;
286                                                                 return ROUTE_FAILURE; }
287 <INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
288 <INITIAL>{SET_HOST}     { count(); yylval.strval=yytext; return SET_HOST; }
289 <INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
290 <INITIAL>{SET_USER}     { count(); yylval.strval=yytext; return SET_USER; }
291 <INITIAL>{SET_USERPASS} { count(); yylval.strval=yytext; return SET_USERPASS; }
292 <INITIAL>{SET_PORT}     { count(); yylval.strval=yytext; return SET_PORT; }
293 <INITIAL>{SET_URI}      { count(); yylval.strval=yytext; return SET_URI; }
294 <INITIAL>{REVERT_URI}   { count(); yylval.strval=yytext; return REVERT_URI; }
295 <INITIAL>{PREFIX}       { count(); yylval.strval=yytext; return PREFIX; }
296 <INITIAL>{STRIP}        { count(); yylval.strval=yytext; return STRIP; }
297 <INITIAL>{STRIP_TAIL}   { count(); yylval.strval=yytext; return STRIP_TAIL; }
298 <INITIAL>{APPEND_BRANCH}        { count(); yylval.strval=yytext; 
299                                                                 return APPEND_BRANCH; }
300 <INITIAL>{FORCE_RPORT}  { count(); yylval.strval=yytext; return FORCE_RPORT; }
301 <INITIAL>{FORCE_TCP_ALIAS}      { count(); yylval.strval=yytext;
302                                                                 return FORCE_TCP_ALIAS; }
303 <INITIAL>{IF}   { count(); yylval.strval=yytext; return IF; }
304 <INITIAL>{ELSE} { count(); yylval.strval=yytext; return ELSE; }
305
306 <INITIAL>{SET_ADV_ADDRESS}      { count(); yylval.strval=yytext;
307                                                                                 return SET_ADV_ADDRESS; }
308 <INITIAL>{SET_ADV_PORT} { count(); yylval.strval=yytext;
309                                                                                 return SET_ADV_PORT; }
310
311 <INITIAL>{URIHOST}      { count(); yylval.strval=yytext; return URIHOST; }
312 <INITIAL>{URIPORT}      { count(); yylval.strval=yytext; return URIPORT; }
313
314 <INITIAL>{MAX_LEN}      { count(); yylval.strval=yytext; return MAX_LEN; }
315
316 <INITIAL>{METHOD}       { count(); yylval.strval=yytext; return METHOD; }
317 <INITIAL>{URI}  { count(); yylval.strval=yytext; return URI; }
318 <INITIAL>{SRCIP}        { count(); yylval.strval=yytext; return SRCIP; }
319 <INITIAL>{SRCPORT}      { count(); yylval.strval=yytext; return SRCPORT; }
320 <INITIAL>{DSTIP}        { count(); yylval.strval=yytext; return DSTIP; }
321 <INITIAL>{DSTPORT}      { count(); yylval.strval=yytext; return DSTPORT; }
322 <INITIAL>{PROTO}        { count(); yylval.strval=yytext; return PROTO; }
323 <INITIAL>{AF}   { count(); yylval.strval=yytext; return AF; }
324 <INITIAL>{MYSELF}       { count(); yylval.strval=yytext; return MYSELF; }
325
326 <INITIAL>{DEBUG}        { count(); yylval.strval=yytext; return DEBUG; }
327 <INITIAL>{FORK}         { count(); yylval.strval=yytext; return FORK; }
328 <INITIAL>{LOGSTDERROR}  { yylval.strval=yytext; return LOGSTDERROR; }
329 <INITIAL>{LOGFACILITY}  { yylval.strval=yytext; return LOGFACILITY; }
330 <INITIAL>{LISTEN}       { count(); yylval.strval=yytext; return LISTEN; }
331 <INITIAL>{ALIAS}        { count(); yylval.strval=yytext; return ALIAS; }
332 <INITIAL>{DNS}  { count(); yylval.strval=yytext; return DNS; }
333 <INITIAL>{REV_DNS}      { count(); yylval.strval=yytext; return REV_DNS; }
334 <INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
335 <INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
336 <INITIAL>{MAXBUFFER}    { count(); yylval.strval=yytext; return MAXBUFFER; }
337 <INITIAL>{CHILDREN}     { count(); yylval.strval=yytext; return CHILDREN; }
338 <INITIAL>{CHECK_VIA}    { count(); yylval.strval=yytext; return CHECK_VIA; }
339 <INITIAL>{SYN_BRANCH}   { count(); yylval.strval=yytext; return SYN_BRANCH; }
340 <INITIAL>{MEMLOG}       { count(); yylval.strval=yytext; return MEMLOG; }
341 <INITIAL>{SIP_WARNING}  { count(); yylval.strval=yytext; return SIP_WARNING; }
342 <INITIAL>{USER}         { count(); yylval.strval=yytext; return USER; }
343 <INITIAL>{GROUP}        { count(); yylval.strval=yytext; return GROUP; }
344 <INITIAL>{CHROOT}       { count(); yylval.strval=yytext; return CHROOT; }
345 <INITIAL>{WDIR} { count(); yylval.strval=yytext; return WDIR; }
346 <INITIAL>{MHOMED}       { count(); yylval.strval=yytext; return MHOMED; }
347 <INITIAL>{DISABLE_TCP}  { count(); yylval.strval=yytext; return DISABLE_TCP; }
348 <INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
349 <INITIAL>{TCP_ACCEPT_ALIASES}   { count(); yylval.strval=yytext;
350                                                                         return TCP_ACCEPT_ALIASES; }
351 <INITIAL>{TCP_SEND_TIMEOUT}             { count(); yylval.strval=yytext;
352                                                                         return TCP_SEND_TIMEOUT; }
353 <INITIAL>{TCP_CONNECT_TIMEOUT}          { count(); yylval.strval=yytext;
354                                                                         return TCP_CONNECT_TIMEOUT; }
355 <INITIAL>{DISABLE_TLS}  { count(); yylval.strval=yytext; return DISABLE_TLS; }
356 <INITIAL>{TLSLOG}               { count(); yylval.strval=yytext; return TLS_PORT_NO; }
357 <INITIAL>{TLS_PORT_NO}  { count(); yylval.strval=yytext; return TLS_PORT_NO; }
358 <INITIAL>{TLS_METHOD}   { count(); yylval.strval=yytext; return TLS_METHOD; }
359 <INITIAL>{TLS_VERIFY}   { count(); yylval.strval=yytext; return TLS_VERIFY; }
360 <INITIAL>{TLS_REQUIRE_CERTIFICATE}      { count(); yylval.strval=yytext;
361                                                                                 return TLS_REQUIRE_CERTIFICATE; }
362 <INITIAL>{TLS_CERTIFICATE}      { count(); yylval.strval=yytext; 
363                                                                                 return TLS_CERTIFICATE; }
364 <INITIAL>{TLS_PRIVATE_KEY}      { count(); yylval.strval=yytext; 
365                                                                                 return TLS_PRIVATE_KEY; }
366 <INITIAL>{TLS_CA_LIST}  { count(); yylval.strval=yytext; 
367                                                                                 return TLS_CA_LIST; }
368 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}        { count(); yylval.strval=yytext;
369                                                                                 return TLS_HANDSHAKE_TIMEOUT; }
370 <INITIAL>{TLS_SEND_TIMEOUT}     { count(); yylval.strval=yytext;
371                                                                                 return TLS_SEND_TIMEOUT; }
372 <INITIAL>{FIFO} { count(); yylval.strval=yytext; return FIFO; }
373 <INITIAL>{FIFO_DIR}     { count(); yylval.strval=yytext; return FIFO_DIR; }
374 <INITIAL>{FIFO_DB_URL}  { count(); yylval.strval=yytext; return FIFO_DB_URL; }
375 <INITIAL>{SOCK_MODE}    { count(); yylval.strval=yytext; return SOCK_MODE; }
376 <INITIAL>{SOCK_USER}    { count(); yylval.strval=yytext; return SOCK_USER; }
377 <INITIAL>{SOCK_GROUP}   { count(); yylval.strval=yytext; return SOCK_GROUP; }
378 <INITIAL>{UNIX_SOCK} { count(); yylval.strval=yytext; return UNIX_SOCK; }
379 <INITIAL>{UNIX_SOCK_CHILDREN} { count(); yylval.strval=yytext; return UNIX_SOCK_CHILDREN; }
380 <INITIAL>{UNIX_TX_TIMEOUT} { count(); yylval.strval=yytext; return UNIX_TX_TIMEOUT; }
381 <INITIAL>{SERVER_SIGNATURE}     { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
382 <INITIAL>{REPLY_TO_VIA} { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
383 <INITIAL>{ADVERTISED_ADDRESS}   {       count(); yylval.strval=yytext;
384                                                                         return ADVERTISED_ADDRESS; }
385 <INITIAL>{ADVERTISED_PORT}              {       count(); yylval.strval=yytext;
386                                                                         return ADVERTISED_PORT; }
387 <INITIAL>{DISABLE_CORE}         {       count(); yylval.strval=yytext;
388                                                                         return DISABLE_CORE; }
389 <INITIAL>{OPEN_FD_LIMIT}                {       count(); yylval.strval=yytext;
390                                                                         return OPEN_FD_LIMIT; }
391 <INITIAL>{MCAST_LOOPBACK}               {       count(); yylval.strval=yytext;
392                                                                         return MCAST_LOOPBACK; }
393 <INITIAL>{MCAST_TTL}            {       count(); yylval.strval=yytext;
394                                                                         return MCAST_TTL; }
395 <INITIAL>{LOADMODULE}   { count(); yylval.strval=yytext; return LOADMODULE; }
396 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
397
398 <INITIAL>{EQUAL}        { count(); return EQUAL; }
399 <INITIAL>{EQUAL_T}      { count(); return EQUAL_T; }
400 <INITIAL>{GT}   { count(); return GT; }
401 <INITIAL>{LT}   { count(); return LT; }
402 <INITIAL>{GTE}  { count(); return GTE; }
403 <INITIAL>{LTE}  { count(); return LTE; }
404 <INITIAL>{DIFF} { count(); return DIFF; }
405 <INITIAL>{MATCH}        { count(); return MATCH; }
406 <INITIAL>{NOT}          { count(); return NOT; }
407 <INITIAL>{AND}          { count(); return AND; }
408 <INITIAL>{OR}           { count(); return OR;  }
409
410
411
412 <INITIAL>{IPV6ADDR}             { count(); yylval.strval=yytext; return IPV6ADDR; }
413 <INITIAL>{NUMBER}               { count(); yylval.intval=atoi(yytext);return NUMBER; }
414 <INITIAL>{HEXNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 16);
415                                                         return NUMBER; }
416 <INITIAL>{OCTNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 8);
417                                                         return NUMBER; }
418 <INITIAL>{YES}                  { count(); yylval.intval=1; return NUMBER; }
419 <INITIAL>{NO}                   { count(); yylval.intval=0; return NUMBER; }
420 <INITIAL>{TCP}                  { count(); return TCP; }
421 <INITIAL>{UDP}                  { count(); return UDP; }
422 <INITIAL>{TLS}                  { count(); return TLS; }
423 <INITIAL>{INET}                 { count(); yylval.intval=AF_INET; return NUMBER; }
424 <INITIAL>{INET6}                { count();
425                                                 #ifdef USE_IPV6
426                                                   yylval.intval=AF_INET6;
427                                                 #else
428                                                   yylval.intval=-1; /* no match*/
429                                                 #endif
430                                                   return NUMBER; }
431 <INITIAL>{SSLv23}               { count(); yylval.strval=yytext; return SSLv23; }
432 <INITIAL>{SSLv2}                { count(); yylval.strval=yytext; return SSLv2; }
433 <INITIAL>{SSLv3}                { count(); yylval.strval=yytext; return SSLv3; }
434 <INITIAL>{TLSv1}                { count(); yylval.strval=yytext; return TLSv1; }
435
436 <INITIAL>{COMMA}                { count(); return COMMA; }
437 <INITIAL>{SEMICOLON}    { count(); return SEMICOLON; }
438 <INITIAL>{COLON}        { count(); return COLON; }
439 <INITIAL>{STAR} { count(); return STAR; }
440 <INITIAL>{RPAREN}       { count(); return RPAREN; }
441 <INITIAL>{LPAREN}       { count(); return LPAREN; }
442 <INITIAL>{LBRACE}       { count(); return LBRACE; }
443 <INITIAL>{RBRACE}       { count(); return RBRACE; }
444 <INITIAL>{LBRACK}       { count(); return LBRACK; }
445 <INITIAL>{RBRACK}       { count(); return RBRACK; }
446 <INITIAL>{SLASH}        { count(); return SLASH; }
447 <INITIAL>{DOT}          { count(); return DOT; }
448 <INITIAL>\\{CR}         {count(); } /* eat the escaped CR */
449 <INITIAL>{CR}           { count();/* return CR;*/ }
450
451
452 <INITIAL>{QUOTES} { count(); state=STRING_S; BEGIN(STRING1); }
453 <INITIAL>{TICK} { count(); state=STRING_S; BEGIN(STRING2); }
454
455
456 <STRING1>{QUOTES} { count(); state=INITIAL_S; BEGIN(INITIAL); 
457                                                 yytext[yyleng-1]=0; yyleng--;
458                                                 addstr(yytext, &tstr);
459                                                 yylval.strval=tstr; tstr=0;
460                                                 return STRING;
461                                         }
462 <STRING2>{TICK}  { count(); state=INITIAL_S; BEGIN(INITIAL); 
463                                                 yytext[yyleng-1]=0; yyleng--;
464                                                 addstr(yytext, &tstr);
465                                                 yylval.strval=tstr;
466                                                 tstr=0;
467                                                 return STRING;
468                                         }
469 <STRING2>.|{EAT_ABLE}|{CR}      { yymore(); }
470
471 <STRING1>\\n            { count(); yytext[yyleng-2]='\n';yytext[yyleng-1]=0; 
472                                                 yyleng--; addstr(yytext, &tstr); }
473 <STRING1>\\r            { count(); yytext[yyleng-2]='\r';yytext[yyleng-1]=0; 
474                                                 yyleng--; addstr(yytext, &tstr); }
475 <STRING1>\\a            { count(); yytext[yyleng-2]='\a';yytext[yyleng-1]=0; 
476                                                 yyleng--; addstr(yytext, &tstr); }
477 <STRING1>\\t            { count(); yytext[yyleng-2]='\t';yytext[yyleng-1]=0; 
478                                                 yyleng--; addstr(yytext, &tstr); }
479 <STRING1>\\\\           { count(); yytext[yyleng-2]='\\';yytext[yyleng-1]=0; 
480                                                 yyleng--; addstr(yytext, &tstr); } 
481 <STRING1>.|{EAT_ABLE}|{CR}      { yymore(); }
482
483
484 <INITIAL,COMMENT>{COM_START}    { count(); comment_nest++; state=COMMENT_S;
485                                                                                 BEGIN(COMMENT); }
486 <COMMENT>{COM_END}                              { count(); comment_nest--;
487                                                                                 if (comment_nest==0){
488                                                                                         state=INITIAL_S;
489                                                                                         BEGIN(INITIAL);
490                                                                                 }
491                                                                 }
492 <COMMENT>.|{EAT_ABLE}|{CR}                              { count(); };
493
494 <INITIAL>{COM_LINE}.*{CR}       { count(); } 
495
496 <INITIAL>{ID}                   { count(); addstr(yytext, &tstr);
497                                                   yylval.strval=tstr; tstr=0; return ID; }
498
499
500 <<EOF>>                                                 {
501                                                                         switch(state){
502                                                                                 case STRING_S: 
503                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
504                                                                                                                 " unclosed string\n");
505                                                                                         if (tstr) {pkg_free(tstr);tstr=0;}
506                                                                                         break;
507                                                                                 case COMMENT_S:
508                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
509                                                                                                                 " %d comments open\n", comment_nest);
510                                                                                         break;
511                                                                                 case COMMENT_LN_S:
512                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF:"
513                                                                                                                 "comment line open\n");
514                                                                                         break;
515                                                                         }
516                                                                         return 0;
517                                                                 }
518                         
519 %%
520
521 static char* addstr(char * src, char ** dest)
522 {
523         char *tmp;
524         unsigned len1, len2;
525         
526         if (*dest==0){
527                 len1 = strlen(src);
528                 *dest = pkg_malloc(len1 + 1);
529                 if (*dest == 0) goto error;
530                 memcpy(*dest, src, len1 + 1);
531         }else{
532                 len1=strlen(*dest);
533                 len2=strlen(src);
534                 tmp=pkg_malloc(len1+len2+1);
535                 if (tmp==0) goto error;
536                 memcpy(tmp, *dest, len1);
537                 memcpy(tmp+len1, src, len2);
538                 tmp[len1+len2]=0;
539                 pkg_free(*dest);
540                 *dest=tmp;
541         }
542         return *dest;
543 error:
544         LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
545         return 0;
546 }
547
548
549
550 static void count()
551 {
552         int i;
553         
554         startcolumn=column;
555         for (i=0; i<yyleng;i++){
556                 if (yytext[i]=='\n'){
557                         line++;
558                         column=startcolumn=1;
559                 }else if (yytext[i]=='\t'){
560                         column++;
561                         /*column+=8 -(column%8);*/
562                 }else{
563                         column++;
564                 }
565         }
566 }
567
568