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