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