- use_dns_cache can be enabled/disabled runtime
[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  *  2004-10-08  more escapes: \", \xHH, \nnn and minor optimizations (andrei)
53  *  2004-10-19  added FROM_URI and TO_URI (andrei)
54  *  2004-11-30  added force_send_socket
55  *  2005-07-08  added tcp_connection_lifetime, tcp_poll_method,
56  *               tcp_max_connections (andrei)
57  *  2005-07-11  added dns_retr_{time,no}, dns_servers_no, dns_use_search_list,
58  *              dns_try_ipv6 (andrei)
59  *  2005-12-11  added onsend_route, snd_{ip,port,proto,af},
60  *              to_{ip,port} (andrei)
61  *  2005-12-12  separated drop, exit, break, return, added RETCODE (andrei)
62  *  2005-12-19  select framework (mma)
63  *  2006-09-11  added dns cache (use, flags, ttls, mem ,gc) & dst blacklist
64  *              options (andrei)
65  *  2006-10-13  added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
66  *              (vlada)
67  *  2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
68  *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
69  *              RT_TIMER2_POLICY (andrei)
70  *  2007-06-16  added DNS_SRV_LB, DNS_TRY_NAPTR (andrei)
71  *  2007-06-18  added DNS_{UDP,TCP,TLS}_PREF (andrei)
72  *  2007-09-10  introduced phone2tel option which allows NOT to consider
73  *              user=phone URIs as TEL URIs (jiri)
74  *  2007-10-10  added DNS_SEARCH_FMATCH (mma)
75  *  2007-11-28  added TCP_OPT_{FD_CACHE, DEFER_ACCEPT, DELAYED_ACK, SYNCNT,
76  *              LINGER2, KEEPALIVE, KEEPIDLE, KEEPINTVL, KEEPCNT} (andrei)
77  *  2008-01-24  added CFG_DESCRIPTION used by cfg_var (Miklos)
78 */
79
80
81 %{
82         #include "dprint.h"
83         #include "globals.h"
84         #include "mem/mem.h"
85         #include <string.h>
86         #include <stdlib.h>
87         #include "ip_addr.h"
88         #include "usr_avp.h"
89         #include "select.h"
90         #include "cfg.tab.h"
91
92         /* states */
93         #define INITIAL_S               0
94         #define COMMENT_S               1
95         #define COMMENT_LN_S            2
96         #define STRING_S                3
97         #define ATTR_S                  4
98         #define SELECT_S                5
99
100         #define STR_BUF_ALLOC_UNIT      128
101         struct str_buf{
102                 char* s;
103                 char* crt;
104                 int left;
105         };
106
107
108         static int comment_nest=0;
109         static int state=0, old_state=0, old_initial=0;
110         static struct str_buf s_buf;
111         int line=1;
112         int column=1;
113         int startcolumn=1;
114
115         static char* addchar(struct str_buf *, char);
116         static char* addstr(struct str_buf *, char*, int);
117         static void count();
118
119
120 %}
121
122 /* start conditions */
123 %x STRING1 STRING2 COMMENT COMMENT_LN ATTR SELECT
124
125 /* action keywords */
126 FORWARD forward
127 FORWARD_TCP     forward_tcp
128 FORWARD_UDP     forward_udp
129 FORWARD_TLS     forward_tls
130 DROP    "drop"|"exit"
131 RETURN  "return"
132 BREAK   "break"
133 SEND    send
134 SEND_TCP        send_tcp
135 LOG             log
136 ERROR   error
137 ROUTE   route
138 ROUTE_FAILURE failure_route
139 ROUTE_ONREPLY onreply_route
140 ROUTE_BRANCH branch_route
141 ROUTE_SEND onsend_route
142 EXEC    exec
143 FORCE_RPORT             "force_rport"|"add_rport"
144 FORCE_TCP_ALIAS         "force_tcp_alias"|"add_tcp_alias"
145 SETFLAG         setflag
146 RESETFLAG       resetflag
147 ISFLAGSET       isflagset
148 FLAGS_DECL      "flags"|"bool"
149 SETAVPFLAG      setavpflag
150 RESETAVPFLAG    resetavpflag
151 ISAVPFLAGSET    isavpflagset
152 AVPFLAGS_DECL   avpflags
153 SET_HOST                "rewritehost"|"sethost"|"seth"
154 SET_HOSTPORT    "rewritehostport"|"sethostport"|"sethp"
155 SET_USER                "rewriteuser"|"setuser"|"setu"
156 SET_USERPASS    "rewriteuserpass"|"setuserpass"|"setup"
157 SET_PORT                "rewriteport"|"setport"|"setp"
158 SET_URI                 "rewriteuri"|"seturi"
159 REVERT_URI              "revert_uri"
160 PREFIX                  "prefix"
161 STRIP                   "strip"
162 STRIP_TAIL              "strip_tail"
163 APPEND_BRANCH   "append_branch"
164 IF                              "if"
165 ELSE                    "else"
166 SET_ADV_ADDRESS "set_advertised_address"
167 SET_ADV_PORT    "set_advertised_port"
168 FORCE_SEND_SOCKET       "force_send_socket"
169
170 /*ACTION LVALUES*/
171 URIHOST                 "uri:host"
172 URIPORT                 "uri:port"
173
174 MAX_LEN                 "max_len"
175
176
177 /* condition keywords */
178 METHOD  method
179 /* hack -- the second element in first line is referable
180    as either uri or status; it only would makes sense to
181    call it "uri" from route{} and status from onreply_route{}
182 */
183 URI             "uri"|"status"
184 FROM_URI        "from_uri"
185 TO_URI          "to_uri"
186 SRCIP   src_ip
187 SRCPORT src_port
188 DSTIP   dst_ip
189 DSTPORT dst_port
190 SNDIP   snd_ip
191 SNDPORT snd_port
192 SNDPROTO        snd_proto|to_proto
193 SNDAF           snd_af|to_af
194 TOIP    to_ip
195 TOPORT  to_port
196 PROTO   proto
197 AF              af
198 MYSELF  myself
199 MSGLEN                  "msg:len"
200 RETCODE \$\?|\$retcode
201 /* operators */
202 EQUAL   =
203 EQUAL_T ==
204 GT      >
205 LT      <
206 GTE     >=
207 LTE     <=
208 DIFF    !=
209 MATCH   =~
210 ADDEQ     "+="
211 NOT             !|"not"
212 LOG_AND         "and"|"&&"
213 BIN_AND         "&"
214 LOG_OR          "or"|"||"
215 BIN_OR          "|"
216 PLUS    "+"
217 MINUS   "-"
218
219 /* Attribute specification */
220 ATTR_MARK   "$"|"%"
221 SELECT_MARK  "@"
222 ATTR_FROM         "f"
223 ATTR_TO           "t"
224 ATTR_FROMURI      "fr"
225 ATTR_TOURI       "tr"
226 ATTR_FROMUSER     "fu"
227 ATTR_TOUSER       "tu"
228 ATTR_FROMDOMAIN   "fd"
229 ATTR_TODOMAIN     "td"
230 ATTR_GLOBAL       "g"
231
232 /* config vars. */
233 DEBUG   debug
234 FORK    fork
235 LOGSTDERROR     log_stderror
236 LOGFACILITY     log_facility
237 LISTEN          listen
238 ALIAS           alias
239 DNS              dns
240 REV_DNS  rev_dns
241 DNS_TRY_IPV6    dns_try_ipv6
242 DNS_TRY_NAPTR   dns_try_naptr
243 DNS_SRV_LB              dns_srv_lb|dns_srv_loadbalancing
244 DNS_UDP_PREF    dns_udp_pref|dns_udp_preference
245 DNS_TCP_PREF    dns_tcp_pref|dns_tcp_preference
246 DNS_TLS_PREF    dns_tls_pref|dns_tls_preference
247 DNS_RETR_TIME   dns_retr_time
248 DNS_RETR_NO             dns_retr_no
249 DNS_SERVERS_NO  dns_servers_no
250 DNS_USE_SEARCH  dns_use_search_list
251 DNS_SEARCH_FMATCH       dns_search_full_match
252 /* dns cache */
253 DNS_CACHE_INIT  dns_cache_init
254 DNS_USE_CACHE   use_dns_cache
255 DNS_USE_FAILOVER        use_dns_failover
256 DNS_CACHE_FLAGS         dns_cache_flags
257 DNS_CACHE_NEG_TTL       dns_cache_negative_ttl
258 DNS_CACHE_MIN_TTL       dns_cache_min_ttl
259 DNS_CACHE_MAX_TTL       dns_cache_max_ttl
260 DNS_CACHE_MEM           dns_cache_mem
261 DNS_CACHE_GC_INT        dns_cache_gc_interval
262 DNS_CACHE_DEL_NONEXP    dns_cache_del_nonexp|dns_cache_delete_nonexpired
263 /* blacklist */
264 DST_BLST_INIT   dst_blacklist_init
265 USE_DST_BLST            use_dst_blacklist
266 DST_BLST_MEM            dst_blacklist_mem
267 DST_BLST_TTL            dst_blacklist_expire|dst_blacklist_ttl
268 DST_BLST_GC_INT         dst_blacklist_gc_interval
269
270
271 PORT    port
272 STAT    statistics
273 MAXBUFFER maxbuffer
274 CHILDREN children
275 CHECK_VIA       check_via
276 PHONE2TEL       phone2tel
277 SYN_BRANCH syn_branch
278 MEMLOG          "memlog"|"mem_log"
279 MEMDBG          "memdbg"|"mem_dbg"
280 SIP_WARNING sip_warning
281 SERVER_SIGNATURE server_signature
282 REPLY_TO_VIA reply_to_via
283 USER            "user"|"uid"
284 GROUP           "group"|"gid"
285 CHROOT          "chroot"
286 WDIR            "workdir"|"wdir"
287 MHOMED          mhomed
288 DISABLE_TCP             "disable_tcp"
289 TCP_CHILDREN    "tcp_children"
290 TCP_ACCEPT_ALIASES      "tcp_accept_aliases"
291 TCP_SEND_TIMEOUT        "tcp_send_timeout"
292 TCP_CONNECT_TIMEOUT     "tcp_connect_timeout"
293 TCP_CON_LIFETIME        "tcp_connection_lifetime"
294 TCP_POLL_METHOD         "tcp_poll_method"
295 TCP_MAX_CONNECTIONS     "tcp_max_connections"
296 TCP_SOURCE_IPV4         "tcp_source_ipv4"
297 TCP_SOURCE_IPV6         "tcp_source_ipv6"
298 TCP_OPT_FD_CACHE        "tcp_fd_cache"
299 TCP_OPT_BUF_WRITE       "tcp_buf_write"
300 TCP_OPT_CONN_WQ_MAX     "tcp_conn_wq_max"
301 TCP_OPT_WQ_MAX          "tcp_wq_max"
302 TCP_OPT_DEFER_ACCEPT "tcp_defer_accept"
303 TCP_OPT_DELAYED_ACK     "tcp_delayed_ack"
304 TCP_OPT_SYNCNT          "tcp_syncnt"
305 TCP_OPT_LINGER2         "tcp_linger2"
306 TCP_OPT_KEEPALIVE       "tcp_keepalive"
307 TCP_OPT_KEEPIDLE        "tcp_keepidle"
308 TCP_OPT_KEEPINTVL       "tcp_keepintvl"
309 TCP_OPT_KEEPCNT         "tcp_keepcnt"
310 DISABLE_TLS             "disable_tls"|"tls_disable"
311 ENABLE_TLS              "enable_tls"|"tls_enable"
312 TLSLOG                  "tlslog"|"tls_log"
313 TLS_PORT_NO             "tls_port_no"
314 TLS_METHOD              "tls_method"
315 TLS_VERIFY              "tls_verify"
316 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
317 TLS_CERTIFICATE "tls_certificate"
318 TLS_PRIVATE_KEY "tls_private_key"
319 TLS_CA_LIST             "tls_ca_list"
320 TLS_HANDSHAKE_TIMEOUT   "tls_handshake_timeout"
321 TLS_SEND_TIMEOUT        "tls_send_timeout"
322 ADVERTISED_ADDRESS      "advertised_address"
323 ADVERTISED_PORT         "advertised_port"
324 DISABLE_CORE            "disable_core_dump"
325 OPEN_FD_LIMIT           "open_files_limit"
326 SHM_FORCE_ALLOC         "shm_force_alloc"
327 MLOCK_PAGES                     "mlock_pages"
328 REAL_TIME                       "real_time"
329 RT_PRIO                         "rt_prio"
330 RT_POLICY                       "rt_policy"
331 RT_TIMER1_PRIO          "rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
332 RT_TIMER1_POLICY        "rt_timer1_policy"|"rt_ftimer_policy"
333 RT_TIMER2_PRIO          "rt_timer2_prio"|"rt_stimer_prio"
334 RT_TIMER2_POLICY        "rt_timer2_policy"|"rt_stimer_policy"
335 MCAST_LOOPBACK          "mcast_loopback"
336 MCAST_TTL               "mcast_ttl"
337 TOS                     "tos"
338 PMTU_DISCOVERY  "pmtu_discovery"
339 KILL_TIMEOUT    "exit_timeout"|"ser_kill_timeout"
340
341 /* stun config variables */
342 STUN_REFRESH_INTERVAL "stun_refresh_interval"
343 STUN_ALLOW_STUN "stun_allow_stun"
344 STUN_ALLOW_FP "stun_allow_fp"
345
346 CFG_DESCRIPTION         "description"|"descr"|"desc"
347
348 LOADMODULE      loadmodule
349 MODPARAM        modparam
350
351 /* values */
352 YES                     "yes"|"true"|"on"|"enable"
353 NO                      "no"|"false"|"off"|"disable"
354 UDP                     "udp"|"UDP"
355 TCP                     "tcp"|"TCP"
356 TLS                     "tls"|"TLS"
357 INET            "inet"|"INET"
358 INET6           "inet6"|"INET6"
359 SSLv23                  "sslv23"|"SSLv23"|"SSLV23"
360 SSLv2                   "sslv2"|"SSLv2"|"SSLV2"
361 SSLv3                   "sslv3"|"SSLv3"|"SSLV3"
362 TLSv1                   "tlsv1"|"TLSv1"|"TLSV1"
363
364 LETTER          [a-zA-Z]
365 DIGIT           [0-9]
366 ALPHANUM        {LETTER}|{DIGIT}|[_]
367 ID                      {LETTER}{ALPHANUM}*
368 HEX                     [0-9a-fA-F]
369 HEXNUMBER       0x{HEX}+
370 OCTNUMBER       0[0-7]+
371 DECNUMBER       0|-?([1-9]{DIGIT}*)
372 BINNUMBER       [0-1]+b
373 HEX4            {HEX}{1,4}
374 IPV6ADDR        ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
375 QUOTES          \"
376 TICK            \'
377 SLASH           "/"
378 SEMICOLON       ;
379 RPAREN          \)
380 LPAREN          \(
381 LBRACE          \{
382 RBRACE          \}
383 LBRACK          \[
384 RBRACK          \]
385 COMMA           ","
386 COLON           ":"
387 STAR            \*
388 DOT                     \.
389 CR                      \n
390
391
392
393 COM_LINE        #
394 COM_START       "/\*"
395 COM_END         "\*/"
396
397 EAT_ABLE        [\ \t\b\r]
398
399 %%
400
401
402 <INITIAL>{EAT_ABLE}     { count(); }
403
404 <INITIAL>{FORWARD}      {count(); yylval.strval=yytext; return FORWARD; }
405 <INITIAL>{FORWARD_TCP}  {count(); yylval.strval=yytext; return FORWARD_TCP; }
406 <INITIAL>{FORWARD_TLS}  {count(); yylval.strval=yytext; return FORWARD_TLS; }
407 <INITIAL>{FORWARD_UDP}  {count(); yylval.strval=yytext; return FORWARD_UDP; }
408 <INITIAL>{DROP} { count(); yylval.strval=yytext; return DROP; }
409 <INITIAL>{RETURN}       { count(); yylval.strval=yytext; return RETURN; }
410 <INITIAL>{BREAK}        { count(); yylval.strval=yytext; return BREAK; }
411 <INITIAL>{SEND} { count(); yylval.strval=yytext; return SEND; }
412 <INITIAL>{SEND_TCP}     { count(); yylval.strval=yytext; return SEND_TCP; }
413 <INITIAL>{LOG}  { count(); yylval.strval=yytext; return LOG_TOK; }
414 <INITIAL>{ERROR}        { count(); yylval.strval=yytext; return ERROR; }
415 <INITIAL>{SETFLAG}      { count(); yylval.strval=yytext; return SETFLAG; }
416 <INITIAL>{RESETFLAG}    { count(); yylval.strval=yytext; return RESETFLAG; }
417 <INITIAL>{ISFLAGSET}    { count(); yylval.strval=yytext; return ISFLAGSET; }
418 <INITIAL>{FLAGS_DECL}   { count(); yylval.strval=yytext; return FLAGS_DECL; }
419 <INITIAL>{SETAVPFLAG}   { count(); yylval.strval=yytext; return SETAVPFLAG; }
420 <INITIAL>{RESETAVPFLAG} { count(); yylval.strval=yytext; return RESETAVPFLAG; }
421 <INITIAL>{ISAVPFLAGSET} { count(); yylval.strval=yytext; return ISAVPFLAGSET; }
422 <INITIAL>{AVPFLAGS_DECL}        { count(); yylval.strval=yytext; return AVPFLAGS_DECL; }
423 <INITIAL>{MSGLEN}       { count(); yylval.strval=yytext; return MSGLEN; }
424 <INITIAL>{RETCODE}      { count(); yylval.strval=yytext; return RETCODE; }
425 <INITIAL>{ROUTE}        { count(); yylval.strval=yytext; return ROUTE; }
426 <INITIAL>{ROUTE_ONREPLY}        { count(); yylval.strval=yytext;
427                                                                 return ROUTE_ONREPLY; }
428 <INITIAL>{ROUTE_FAILURE}        { count(); yylval.strval=yytext;
429                                                                 return ROUTE_FAILURE; }
430 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
431 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
432 <INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
433 <INITIAL>{SET_HOST}     { count(); yylval.strval=yytext; return SET_HOST; }
434 <INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
435 <INITIAL>{SET_USER}     { count(); yylval.strval=yytext; return SET_USER; }
436 <INITIAL>{SET_USERPASS} { count(); yylval.strval=yytext; return SET_USERPASS; }
437 <INITIAL>{SET_PORT}     { count(); yylval.strval=yytext; return SET_PORT; }
438 <INITIAL>{SET_URI}      { count(); yylval.strval=yytext; return SET_URI; }
439 <INITIAL>{REVERT_URI}   { count(); yylval.strval=yytext; return REVERT_URI; }
440 <INITIAL>{PREFIX}       { count(); yylval.strval=yytext; return PREFIX; }
441 <INITIAL>{STRIP}        { count(); yylval.strval=yytext; return STRIP; }
442 <INITIAL>{STRIP_TAIL}   { count(); yylval.strval=yytext; return STRIP_TAIL; }
443 <INITIAL>{APPEND_BRANCH}        { count(); yylval.strval=yytext;
444                                                                 return APPEND_BRANCH; }
445 <INITIAL>{FORCE_RPORT}  { count(); yylval.strval=yytext; return FORCE_RPORT; }
446 <INITIAL>{FORCE_TCP_ALIAS}      { count(); yylval.strval=yytext;
447                                                                 return FORCE_TCP_ALIAS; }
448 <INITIAL>{IF}   { count(); yylval.strval=yytext; return IF; }
449 <INITIAL>{ELSE} { count(); yylval.strval=yytext; return ELSE; }
450
451 <INITIAL>{SET_ADV_ADDRESS}      { count(); yylval.strval=yytext;
452                                                                                 return SET_ADV_ADDRESS; }
453 <INITIAL>{SET_ADV_PORT} { count(); yylval.strval=yytext;
454                                                                                 return SET_ADV_PORT; }
455 <INITIAL>{FORCE_SEND_SOCKET}    {       count(); yylval.strval=yytext;
456                                                                         return FORCE_SEND_SOCKET; }
457
458 <INITIAL>{URIHOST}      { count(); yylval.strval=yytext; return URIHOST; }
459 <INITIAL>{URIPORT}      { count(); yylval.strval=yytext; return URIPORT; }
460
461 <INITIAL>{MAX_LEN}      { count(); yylval.strval=yytext; return MAX_LEN; }
462
463 <INITIAL>{METHOD}       { count(); yylval.strval=yytext; return METHOD; }
464 <INITIAL>{URI}  { count(); yylval.strval=yytext; return URI; }
465 <INITIAL>{FROM_URI}     { count(); yylval.strval=yytext; return FROM_URI; }
466 <INITIAL>{TO_URI}       { count(); yylval.strval=yytext; return TO_URI; }
467 <INITIAL>{SRCIP}        { count(); yylval.strval=yytext; return SRCIP; }
468 <INITIAL>{SRCPORT}      { count(); yylval.strval=yytext; return SRCPORT; }
469 <INITIAL>{DSTIP}        { count(); yylval.strval=yytext; return DSTIP; }
470 <INITIAL>{DSTPORT}      { count(); yylval.strval=yytext; return DSTPORT; }
471 <INITIAL>{SNDIP}        { count(); yylval.strval=yytext; return SNDIP; }
472 <INITIAL>{SNDPORT}      { count(); yylval.strval=yytext; return SNDPORT; }
473 <INITIAL>{SNDPROTO}     { count(); yylval.strval=yytext; return SNDPROTO; }
474 <INITIAL>{SNDAF}        { count(); yylval.strval=yytext; return SNDAF; }
475 <INITIAL>{TOIP}         { count(); yylval.strval=yytext; return TOIP; }
476 <INITIAL>{TOPORT}       { count(); yylval.strval=yytext; return TOPORT; }
477 <INITIAL>{PROTO}        { count(); yylval.strval=yytext; return PROTO; }
478 <INITIAL>{AF}   { count(); yylval.strval=yytext; return AF; }
479 <INITIAL>{MYSELF}       { count(); yylval.strval=yytext; return MYSELF; }
480
481 <INITIAL>{DEBUG}        { count(); yylval.strval=yytext; return DEBUG_V; }
482 <INITIAL>{FORK}         { count(); yylval.strval=yytext; return FORK; }
483 <INITIAL>{LOGSTDERROR}  { yylval.strval=yytext; return LOGSTDERROR; }
484 <INITIAL>{LOGFACILITY}  { yylval.strval=yytext; return LOGFACILITY; }
485 <INITIAL>{LISTEN}       { count(); yylval.strval=yytext; return LISTEN; }
486 <INITIAL>{ALIAS}        { count(); yylval.strval=yytext; return ALIAS; }
487 <INITIAL>{DNS}  { count(); yylval.strval=yytext; return DNS; }
488 <INITIAL>{REV_DNS}      { count(); yylval.strval=yytext; return REV_DNS; }
489 <INITIAL>{DNS_TRY_IPV6} { count(); yylval.strval=yytext;
490                                                                 return DNS_TRY_IPV6; }
491 <INITIAL>{DNS_TRY_NAPTR}        { count(); yylval.strval=yytext;
492                                                                 return DNS_TRY_NAPTR; }
493 <INITIAL>{DNS_SRV_LB}   { count(); yylval.strval=yytext;
494                                                                 return DNS_SRV_LB; }
495 <INITIAL>{DNS_UDP_PREF} { count(); yylval.strval=yytext;
496                                                                 return DNS_UDP_PREF; }
497 <INITIAL>{DNS_TCP_PREF} { count(); yylval.strval=yytext;
498                                                                 return DNS_TCP_PREF; }
499 <INITIAL>{DNS_TLS_PREF} { count(); yylval.strval=yytext;
500                                                                 return DNS_TLS_PREF; }
501 <INITIAL>{DNS_RETR_TIME}        { count(); yylval.strval=yytext;
502                                                                 return DNS_RETR_TIME; }
503 <INITIAL>{DNS_RETR_NO}  { count(); yylval.strval=yytext;
504                                                                 return DNS_RETR_NO; }
505 <INITIAL>{DNS_SERVERS_NO}       { count(); yylval.strval=yytext;
506                                                                 return DNS_SERVERS_NO; }
507 <INITIAL>{DNS_USE_SEARCH}       { count(); yylval.strval=yytext;
508                                                                 return DNS_USE_SEARCH; }
509 <INITIAL>{DNS_SEARCH_FMATCH}    { count(); yylval.strval=yytext;
510                                                                 return DNS_SEARCH_FMATCH; }
511 <INITIAL>{DNS_CACHE_INIT}       { count(); yylval.strval=yytext;
512                                                                 return DNS_CACHE_INIT; }
513 <INITIAL>{DNS_USE_CACHE}        { count(); yylval.strval=yytext;
514                                                                 return DNS_USE_CACHE; }
515 <INITIAL>{DNS_USE_FAILOVER}     { count(); yylval.strval=yytext;
516                                                                 return DNS_USE_FAILOVER; }
517 <INITIAL>{DNS_CACHE_FLAGS}      { count(); yylval.strval=yytext;
518                                                                 return DNS_CACHE_FLAGS; }
519 <INITIAL>{DNS_CACHE_NEG_TTL}    { count(); yylval.strval=yytext;
520                                                                 return DNS_CACHE_NEG_TTL; }
521 <INITIAL>{DNS_CACHE_MIN_TTL}    { count(); yylval.strval=yytext;
522                                                                 return DNS_CACHE_MIN_TTL; }
523 <INITIAL>{DNS_CACHE_MAX_TTL}    { count(); yylval.strval=yytext;
524                                                                 return DNS_CACHE_MAX_TTL; }
525 <INITIAL>{DNS_CACHE_MEM}        { count(); yylval.strval=yytext;
526                                                                 return DNS_CACHE_MEM; }
527 <INITIAL>{DNS_CACHE_GC_INT}     { count(); yylval.strval=yytext;
528                                                                 return DNS_CACHE_GC_INT; }
529 <INITIAL>{DNS_CACHE_DEL_NONEXP} { count(); yylval.strval=yytext;
530                                                                 return DNS_CACHE_DEL_NONEXP; }
531 <INITIAL>{DST_BLST_INIT}        { count(); yylval.strval=yytext;
532                                                                 return DST_BLST_INIT; }
533 <INITIAL>{USE_DST_BLST} { count(); yylval.strval=yytext;
534                                                                 return USE_DST_BLST; }
535 <INITIAL>{DST_BLST_MEM} { count(); yylval.strval=yytext;
536                                                                 return DST_BLST_MEM; }
537 <INITIAL>{DST_BLST_TTL} { count(); yylval.strval=yytext;
538                                                                 return DST_BLST_TTL; }
539 <INITIAL>{DST_BLST_GC_INT}      { count(); yylval.strval=yytext;
540                                                                 return DST_BLST_GC_INT; }
541 <INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
542 <INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
543 <INITIAL>{MAXBUFFER}    { count(); yylval.strval=yytext; return MAXBUFFER; }
544 <INITIAL>{CHILDREN}     { count(); yylval.strval=yytext; return CHILDREN; }
545 <INITIAL>{CHECK_VIA}    { count(); yylval.strval=yytext; return CHECK_VIA; }
546 <INITIAL>{PHONE2TEL}    { count(); yylval.strval=yytext; return PHONE2TEL; }
547 <INITIAL>{SYN_BRANCH}   { count(); yylval.strval=yytext; return SYN_BRANCH; }
548 <INITIAL>{MEMLOG}       { count(); yylval.strval=yytext; return MEMLOG; }
549 <INITIAL>{MEMDBG}       { count(); yylval.strval=yytext; return MEMDBG; }
550 <INITIAL>{SIP_WARNING}  { count(); yylval.strval=yytext; return SIP_WARNING; }
551 <INITIAL>{USER}         { count(); yylval.strval=yytext; return USER; }
552 <INITIAL>{GROUP}        { count(); yylval.strval=yytext; return GROUP; }
553 <INITIAL>{CHROOT}       { count(); yylval.strval=yytext; return CHROOT; }
554 <INITIAL>{WDIR} { count(); yylval.strval=yytext; return WDIR; }
555 <INITIAL>{MHOMED}       { count(); yylval.strval=yytext; return MHOMED; }
556 <INITIAL>{DISABLE_TCP}  { count(); yylval.strval=yytext; return DISABLE_TCP; }
557 <INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
558 <INITIAL>{TCP_ACCEPT_ALIASES}   { count(); yylval.strval=yytext;
559                                                                         return TCP_ACCEPT_ALIASES; }
560 <INITIAL>{TCP_SEND_TIMEOUT}             { count(); yylval.strval=yytext;
561                                                                         return TCP_SEND_TIMEOUT; }
562 <INITIAL>{TCP_CONNECT_TIMEOUT}          { count(); yylval.strval=yytext;
563                                                                         return TCP_CONNECT_TIMEOUT; }
564 <INITIAL>{TCP_CON_LIFETIME}             { count(); yylval.strval=yytext;
565                                                                         return TCP_CON_LIFETIME; }
566 <INITIAL>{TCP_POLL_METHOD}              { count(); yylval.strval=yytext;
567                                                                         return TCP_POLL_METHOD; }
568 <INITIAL>{TCP_MAX_CONNECTIONS}  { count(); yylval.strval=yytext;
569                                                                         return TCP_MAX_CONNECTIONS; }
570 <INITIAL>{TCP_SOURCE_IPV4}              { count(); yylval.strval=yytext;
571                                                                         return TCP_SOURCE_IPV4; }
572 <INITIAL>{TCP_SOURCE_IPV6}              { count(); yylval.strval=yytext;
573                                                                         return TCP_SOURCE_IPV6; }
574 <INITIAL>{TCP_OPT_FD_CACHE}             { count(); yylval.strval=yytext;
575                                                                         return TCP_OPT_FD_CACHE; }
576 <INITIAL>{TCP_OPT_CONN_WQ_MAX}  { count(); yylval.strval=yytext;
577                                                                         return TCP_OPT_CONN_WQ_MAX; }
578 <INITIAL>{TCP_OPT_WQ_MAX}       { count(); yylval.strval=yytext;
579                                                                         return TCP_OPT_WQ_MAX; }
580 <INITIAL>{TCP_OPT_BUF_WRITE}    { count(); yylval.strval=yytext;
581                                                                         return TCP_OPT_BUF_WRITE; }
582 <INITIAL>{TCP_OPT_DEFER_ACCEPT} { count(); yylval.strval=yytext;
583                                                                         return TCP_OPT_DEFER_ACCEPT; }
584 <INITIAL>{TCP_OPT_DELAYED_ACK}  { count(); yylval.strval=yytext;
585                                                                         return TCP_OPT_DELAYED_ACK; }
586 <INITIAL>{TCP_OPT_SYNCNT}               { count(); yylval.strval=yytext;
587                                                                         return TCP_OPT_SYNCNT; }
588 <INITIAL>{TCP_OPT_LINGER2}              { count(); yylval.strval=yytext;
589                                                                         return TCP_OPT_LINGER2; }
590 <INITIAL>{TCP_OPT_KEEPALIVE}    { count(); yylval.strval=yytext;
591                                                                         return TCP_OPT_KEEPALIVE; }
592 <INITIAL>{TCP_OPT_KEEPIDLE}             { count(); yylval.strval=yytext;
593                                                                         return TCP_OPT_KEEPIDLE; }
594 <INITIAL>{TCP_OPT_KEEPINTVL}    { count(); yylval.strval=yytext;
595                                                                         return TCP_OPT_KEEPINTVL; }
596 <INITIAL>{TCP_OPT_KEEPCNT}      { count(); yylval.strval=yytext;
597                                                                         return TCP_OPT_KEEPCNT; }
598 <INITIAL>{DISABLE_TLS}  { count(); yylval.strval=yytext; return DISABLE_TLS; }
599 <INITIAL>{ENABLE_TLS}   { count(); yylval.strval=yytext; return ENABLE_TLS; }
600 <INITIAL>{TLSLOG}               { count(); yylval.strval=yytext; return TLS_PORT_NO; }
601 <INITIAL>{TLS_PORT_NO}  { count(); yylval.strval=yytext; return TLS_PORT_NO; }
602 <INITIAL>{TLS_METHOD}   { count(); yylval.strval=yytext; return TLS_METHOD; }
603 <INITIAL>{TLS_VERIFY}   { count(); yylval.strval=yytext; return TLS_VERIFY; }
604 <INITIAL>{TLS_REQUIRE_CERTIFICATE}      { count(); yylval.strval=yytext;
605                                                                                 return TLS_REQUIRE_CERTIFICATE; }
606 <INITIAL>{TLS_CERTIFICATE}      { count(); yylval.strval=yytext;
607                                                                                 return TLS_CERTIFICATE; }
608 <INITIAL>{TLS_PRIVATE_KEY}      { count(); yylval.strval=yytext;
609                                                                                 return TLS_PRIVATE_KEY; }
610 <INITIAL>{TLS_CA_LIST}  { count(); yylval.strval=yytext;
611                                                                                 return TLS_CA_LIST; }
612 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}        { count(); yylval.strval=yytext;
613                                                                                 return TLS_HANDSHAKE_TIMEOUT; }
614 <INITIAL>{TLS_SEND_TIMEOUT}     { count(); yylval.strval=yytext;
615                                                                                 return TLS_SEND_TIMEOUT; }
616 <INITIAL>{SERVER_SIGNATURE}     { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
617 <INITIAL>{REPLY_TO_VIA} { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
618 <INITIAL>{ADVERTISED_ADDRESS}   {       count(); yylval.strval=yytext;
619                                                                         return ADVERTISED_ADDRESS; }
620 <INITIAL>{ADVERTISED_PORT}              {       count(); yylval.strval=yytext;
621                                                                         return ADVERTISED_PORT; }
622 <INITIAL>{DISABLE_CORE}         {       count(); yylval.strval=yytext;
623                                                                         return DISABLE_CORE; }
624 <INITIAL>{OPEN_FD_LIMIT}                {       count(); yylval.strval=yytext;
625                                                                         return OPEN_FD_LIMIT; }
626 <INITIAL>{SHM_FORCE_ALLOC}              {       count(); yylval.strval=yytext;
627                                                                         return SHM_FORCE_ALLOC; }
628 <INITIAL>{MLOCK_PAGES}          {       count(); yylval.strval=yytext;
629                                                                         return MLOCK_PAGES; }
630 <INITIAL>{REAL_TIME}            {       count(); yylval.strval=yytext;
631                                                                         return REAL_TIME; }
632 <INITIAL>{RT_PRIO}              {       count(); yylval.strval=yytext;
633                                                                         return RT_PRIO; }
634 <INITIAL>{RT_POLICY}            {       count(); yylval.strval=yytext;
635                                                                         return RT_POLICY; }
636 <INITIAL>{RT_TIMER1_PRIO}               {       count(); yylval.strval=yytext;
637                                                                         return RT_TIMER1_PRIO; }
638 <INITIAL>{RT_TIMER1_POLICY}             {       count(); yylval.strval=yytext;
639                                                                         return RT_TIMER1_POLICY; }
640 <INITIAL>{RT_TIMER2_PRIO}               {       count(); yylval.strval=yytext;
641                                                                         return RT_TIMER2_PRIO; }
642 <INITIAL>{RT_TIMER2_POLICY}             {       count(); yylval.strval=yytext;
643                                                                         return RT_TIMER2_POLICY; }
644 <INITIAL>{MCAST_LOOPBACK}               {       count(); yylval.strval=yytext;
645                                                                         return MCAST_LOOPBACK; }
646 <INITIAL>{MCAST_TTL}            {       count(); yylval.strval=yytext;
647                                                                         return MCAST_TTL; }
648 <INITIAL>{TOS}                  {       count(); yylval.strval=yytext;
649                                                                         return TOS; }
650 <INITIAL>{PMTU_DISCOVERY}               {       count(); yylval.strval=yytext;
651                                                                         return PMTU_DISCOVERY; }
652 <INITIAL>{KILL_TIMEOUT}                 {       count(); yylval.strval=yytext;
653                                                                         return KILL_TIMEOUT; }
654 <INITIAL>{CFG_DESCRIPTION}      { count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
655 <INITIAL>{LOADMODULE}   { count(); yylval.strval=yytext; return LOADMODULE; }
656 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
657
658 <INITIAL>{STUN_REFRESH_INTERVAL} { count(); yylval.strval=yytext; return STUN_REFRESH_INTERVAL;}
659 <INITIAL>{STUN_ALLOW_STUN} { count(); yylval.strval=yytext; return STUN_ALLOW_STUN;}
660 <INITIAL>{STUN_ALLOW_FP} { count(); yylval.strval=yytext; return STUN_ALLOW_FP;}
661
662 <INITIAL>{EQUAL}        { count(); return EQUAL; }
663 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
664 <INITIAL>{EQUAL_T}      { count(); return EQUAL_T; }
665 <INITIAL>{GT}   { count(); return GT; }
666 <INITIAL>{LT}   { count(); return LT; }
667 <INITIAL>{GTE}  { count(); return GTE; }
668 <INITIAL>{LTE}  { count(); return LTE; }
669 <INITIAL>{DIFF} { count(); return DIFF; }
670 <INITIAL>{MATCH}        { count(); return MATCH; }
671 <INITIAL>{NOT}          { count(); return NOT; }
672 <INITIAL>{LOG_AND}      { count(); return LOG_AND; }
673 <INITIAL>{BIN_AND}      { count(); return BIN_AND; }
674 <INITIAL>{LOG_OR}       { count(); return LOG_OR;  }
675 <INITIAL>{BIN_OR}       { count(); return BIN_OR;  }
676 <INITIAL>{PLUS}         { count(); return PLUS; }
677 <INITIAL>{MINUS}        { count(); return MINUS; }
678
679 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
680 <SELECT>{ID}            { count(); addstr(&s_buf, yytext, yyleng);
681                           yylval.strval=s_buf.s;
682                           memset(&s_buf, 0, sizeof(s_buf));
683                           return ID;
684                         }
685 <SELECT>{DOT}           { count(); return DOT; }
686 <SELECT>{LBRACK}        { count(); return LBRACK; }
687 <SELECT>{RBRACK}        { count(); return RBRACK; }
688 <SELECT>{DECNUMBER}     { count(); yylval.intval=atoi(yytext);return NUMBER; }
689 <SELECT>{HEXNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 16); return NUMBER; }
690 <SELECT>{OCTNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 8); return NUMBER; }
691 <SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
692
693
694 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR); return ATTR_MARK; }
695 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
696 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
697 <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
698 <ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
699 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
700 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
701 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
702 <ATTR>{ATTR_TODOMAIN}   { count(); return ATTR_TODOMAIN; }
703 <ATTR>{ATTR_GLOBAL}     { count(); return ATTR_GLOBAL; }
704 <ATTR>{DOT}             { count(); return DOT; }
705 <ATTR>{LBRACK}          { count(); return LBRACK; }
706 <ATTR>{RBRACK}          { count(); return RBRACK; }
707 <ATTR>{STAR}            { count(); return STAR; }
708 <ATTR>{DECNUMBER}       { count(); yylval.intval=atoi(yytext);return NUMBER; }
709 <ATTR>{ID}              { count(); addstr(&s_buf, yytext, yyleng);
710                            yylval.strval=s_buf.s;
711                            memset(&s_buf, 0, sizeof(s_buf));
712                            state = INITIAL_S;
713                            BEGIN(INITIAL);
714                            return ID;
715                         }
716
717 <INITIAL>{IPV6ADDR}             { count(); yylval.strval=yytext; return IPV6ADDR; }
718 <INITIAL>{DECNUMBER}            { count(); yylval.intval=atoi(yytext);return NUMBER; }
719 <INITIAL>{HEXNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 16);
720                                                         return NUMBER; }
721 <INITIAL>{OCTNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 8);
722                                                         return NUMBER; }
723 <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
724 <INITIAL>{YES}                  { count(); yylval.intval=1; return NUMBER; }
725 <INITIAL>{NO}                   { count(); yylval.intval=0; return NUMBER; }
726 <INITIAL>{TCP}                  { count(); return TCP; }
727 <INITIAL>{UDP}                  { count(); return UDP; }
728 <INITIAL>{TLS}                  { count(); return TLS; }
729 <INITIAL>{INET}                 { count(); yylval.intval=AF_INET; return NUMBER; }
730 <INITIAL>{INET6}                { count();
731                                                 #ifdef USE_IPV6
732                                                   yylval.intval=AF_INET6;
733                                                 #else
734                                                   yylval.intval=-1; /* no match*/
735                                                 #endif
736                                                   return NUMBER; }
737 <INITIAL>{SSLv23}               { count(); yylval.strval=yytext; return SSLv23; }
738 <INITIAL>{SSLv2}                { count(); yylval.strval=yytext; return SSLv2; }
739 <INITIAL>{SSLv3}                { count(); yylval.strval=yytext; return SSLv3; }
740 <INITIAL>{TLSv1}                { count(); yylval.strval=yytext; return TLSv1; }
741
742 <INITIAL>{COMMA}                { count(); return COMMA; }
743 <INITIAL>{SEMICOLON}    { count(); return SEMICOLON; }
744 <INITIAL>{COLON}        { count(); return COLON; }
745 <INITIAL>{STAR} { count(); return STAR; }
746 <INITIAL>{RPAREN}       { count(); return RPAREN; }
747 <INITIAL>{LPAREN}       { count(); return LPAREN; }
748 <INITIAL>{LBRACE}       { count(); return LBRACE; }
749 <INITIAL>{RBRACE}       { count(); return RBRACE; }
750 <INITIAL>{LBRACK}       { count(); return LBRACK; }
751 <INITIAL>{RBRACK}       { count(); return RBRACK; }
752 <INITIAL>{SLASH}        { count(); return SLASH; }
753 <INITIAL>{DOT}          { count(); return DOT; }
754 <INITIAL>\\{CR}         {count(); } /* eat the escaped CR */
755 <INITIAL>{CR}           { count();/* return CR;*/ }
756
757
758 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START; old_state = state; state=STRING_S; BEGIN(STRING1); }
759 <INITIAL>{TICK} { count(); old_initial = YY_START; old_state = state; state=STRING_S; BEGIN(STRING2); }
760
761
762 <STRING1>{QUOTES} { count(); state=old_state; BEGIN(old_initial);
763                                                 yytext[yyleng-1]=0; yyleng--;
764                                                 addstr(&s_buf, yytext, yyleng);
765                                                 yylval.strval=s_buf.s;
766                                                 memset(&s_buf, 0, sizeof(s_buf));
767                                                 return STRING;
768                                         }
769 <STRING2>{TICK}  { count(); state=old_state; BEGIN(old_initial);
770                                                 yytext[yyleng-1]=0; yyleng--;
771                                                 addstr(&s_buf, yytext, yyleng);
772                                                 yylval.strval=s_buf.s;
773                                                 memset(&s_buf, 0, sizeof(s_buf));
774                                                 return STRING;
775                                         }
776 <STRING2>.|{EAT_ABLE}|{CR}      { yymore(); }
777
778 <STRING1>\\n            { count(); addchar(&s_buf, '\n'); }
779 <STRING1>\\r            { count(); addchar(&s_buf, '\r'); }
780 <STRING1>\\a            { count(); addchar(&s_buf, '\a'); }
781 <STRING1>\\t            { count(); addchar(&s_buf, '\t'); }
782 <STRING1>\\{QUOTES}     { count(); addchar(&s_buf, '"');  }
783 <STRING1>\\\\           { count(); addchar(&s_buf, '\\'); }
784 <STRING1>\\x{HEX}{1,2}  { count(); addchar(&s_buf,
785                                                                                         (char)strtol(yytext+2, 0, 16)); }
786  /* don't allow \[0-7]{1}, it will eat the backreferences from
787     subst_uri if allowed (although everybody should use '' in subt_uri) */
788 <STRING1>\\[0-7]{2,3}   { count(); addchar(&s_buf,
789                                                                                         (char)strtol(yytext+1, 0, 8));  }
790 <STRING1>\\{CR}         { count(); } /* eat escaped CRs */
791 <STRING1>.|{EAT_ABLE}|{CR}      { addchar(&s_buf, *yytext); }
792
793
794 <INITIAL,COMMENT>{COM_START}    { count(); comment_nest++; state=COMMENT_S;
795                                                                                 BEGIN(COMMENT); }
796 <COMMENT>{COM_END}                              { count(); comment_nest--;
797                                                                                 if (comment_nest==0){
798                                                                                         state=INITIAL_S;
799                                                                                         BEGIN(INITIAL);
800                                                                                 }
801                                                                 }
802 <COMMENT>.|{EAT_ABLE}|{CR}                              { count(); };
803
804 <INITIAL>{COM_LINE}.*{CR}       { count(); }
805
806 <INITIAL>{ID}                   { count(); addstr(&s_buf, yytext, yyleng);
807                                                                         yylval.strval=s_buf.s;
808                                                                         memset(&s_buf, 0, sizeof(s_buf));
809                                                                         return ID; }
810
811 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
812
813
814 <<EOF>>                                                 {
815                                                                         switch(state){
816                                                                                 case STRING_S:
817                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
818                                                                                                                 " unclosed string\n");
819                                                                                         if (s_buf.s){
820                                                                                                 pkg_free(s_buf.s);
821                                                                                                 memset(&s_buf, 0,
822                                                                                                                         sizeof(s_buf));
823                                                                                         }
824                                                                                         break;
825                                                                                 case COMMENT_S:
826                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
827                                                                                                                 " %d comments open\n", comment_nest);
828                                                                                         break;
829                                                                                 case COMMENT_LN_S:
830                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF:"
831                                                                                                                 "comment line open\n");
832                                                                                         break;
833                                                                         }
834                                                                         return 0;
835                                                                 }
836
837 %%
838
839
840 static char* addchar(struct str_buf* dst, char c)
841 {
842         return addstr(dst, &c, 1);
843 }
844
845
846
847 static char* addstr(struct str_buf* dst_b, char* src, int len)
848 {
849         char *tmp;
850         unsigned size;
851         unsigned used;
852
853         if (dst_b->left<(len+1)){
854                 used=(unsigned)(dst_b->crt-dst_b->s);
855                 size=used+len+1;
856                 /* round up to next multiple */
857                 size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
858                 tmp=pkg_malloc(size);
859                 if (tmp==0) goto error;
860                 if (dst_b->s){
861                         memcpy(tmp, dst_b->s, used);
862                         pkg_free(dst_b->s);
863                 }
864                 dst_b->s=tmp;
865                 dst_b->crt=dst_b->s+used;
866                 dst_b->left=size-used;
867         }
868         memcpy(dst_b->crt, src, len);
869         dst_b->crt+=len;
870         *(dst_b->crt)=0;
871         dst_b->left-=len;
872
873         return dst_b->s;
874 error:
875         LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
876         return 0;
877 }
878
879
880
881 static void count()
882 {
883         int i;
884
885         startcolumn=column;
886         for (i=0; i<yyleng;i++){
887                 if (yytext[i]=='\n'){
888                         line++;
889                         column=startcolumn=1;
890                 }else if (yytext[i]=='\t'){
891                         column++;
892                         /*column+=8 -(column%8);*/
893                 }else{
894                         column++;
895                 }
896         }
897 }
898
899
900
901 /* replacement yywrap, removes libfl dependency */
902 int yywrap()
903 {
904         return 1;
905 }