core: added mem_summary config option
[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  *  2008-11-28  added support for kamailio pvars and avp/pvar guessing (andrei)
79  *  2008-12-11  added support for "string1" "string2" (andrei)
80  *  2009-03-10  added SET_USERPHONE action (Miklos)
81  *  2009-04-24  addd strlen, strempty and defined operators (andrei)
82 */
83
84
85 %{
86         #include "dprint.h"
87         #include "globals.h"
88         #include "mem/mem.h"
89         #include <string.h>
90         #include <stdlib.h>
91         #include "ip_addr.h"
92         #include "usr_avp.h"
93         #include "select.h"
94         #include "cfg.tab.h"
95         #include "sr_compat.h"
96
97         /* states */
98         #define INITIAL_S               0
99         #define COMMENT_S               1
100         #define COMMENT_LN_S            2
101         #define STRING_S                3
102         #define ATTR_S                  4  /* avp/attr */
103         #define SELECT_S                5
104         #define AVP_PVAR_S              6  /* avp or pvar */
105         #define PVAR_P_S                7  /* pvar: $(...)  or $foo(...)*/
106         #define PVARID_S                8  /* $foo.bar...*/
107         #define STR_BETWEEN_S           9
108
109         #define STR_BUF_ALLOC_UNIT      128
110         struct str_buf{
111                 char* s;
112                 char* crt;
113                 int left;
114         };
115
116
117         static int comment_nest=0;
118         static int p_nest=0;
119         static int state=0, old_state=0, old_initial=0;
120         static struct str_buf s_buf;
121         int line=1;
122         int column=1;
123         int startcolumn=1;
124         int startline=1;
125         char *finame = 0;
126         static int ign_lines=0;
127         static int ign_columns=0;
128         char* yy_number_str=0; /* str correspondent for the current NUMBER token */
129
130         static char* addchar(struct str_buf *, char);
131         static char* addstr(struct str_buf *, char*, int);
132         static void count();
133         static void count_more();
134         static void count_ignore();
135
136         #define MAX_INCLUDE_DEPTH 10
137         static struct sr_yy_state {
138                 YY_BUFFER_STATE state;
139                 int line;
140                 int column;
141                 int startcolumn;
142                 int startline;
143                 char *finame;
144         } include_stack[MAX_INCLUDE_DEPTH];
145         static int include_stack_ptr = 0;
146
147         static int sr_push_yy_state(char *fin);
148         static int sr_pop_yy_state();
149
150         static struct sr_yy_fname {
151                 char *fname;
152                 struct sr_yy_fname *next;
153         } *sr_yy_fname_list = 0;
154
155 %}
156
157 /* start conditions */
158 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P 
159 %x PVARID INCLF
160
161 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
162 SER_CFG                 SER
163 KAMAILIO_CFG    KAMAILIO|OPENSER
164 MAXCOMPAT_CFG   MAXCOMPAT|ALL
165
166 /* action keywords */
167 FORWARD forward
168 FORWARD_TCP     forward_tcp
169 FORWARD_UDP     forward_udp
170 FORWARD_TLS     forward_tls
171 FORWARD_SCTP    forward_sctp
172 DROP    "drop"
173 EXIT    "exit"
174 RETURN  "return"
175 BREAK   "break"
176 SEND    send
177 SEND_TCP        send_tcp
178 LOG             log
179 ERROR   error
180 ROUTE   route
181 ROUTE_FAILURE failure_route
182 ROUTE_ONREPLY onreply_route
183 ROUTE_BRANCH branch_route
184 ROUTE_SEND onsend_route
185 ROUTE_EVENT event_route
186 EXEC    exec
187 FORCE_RPORT             "force_rport"|"add_rport"
188 ADD_LOCAL_RPORT         "add_local_rport"
189 FORCE_TCP_ALIAS         "force_tcp_alias"|"add_tcp_alias"
190 UDP_MTU         "udp_mtu"
191 UDP_MTU_TRY_PROTO       "udp_mtu_try_proto"
192 SETFLAG         setflag
193 RESETFLAG       resetflag
194 ISFLAGSET       isflagset
195 FLAGS_DECL      "flags"|"bool"
196 SETAVPFLAG      setavpflag
197 RESETAVPFLAG    resetavpflag
198 ISAVPFLAGSET    isavpflagset
199 AVPFLAGS_DECL   avpflags
200 SET_HOST                "rewritehost"|"sethost"|"seth"
201 SET_HOSTPORT    "rewritehostport"|"sethostport"|"sethp"
202 SET_HOSTPORTTRANS       "rewritehostporttrans"|"sethostporttrans"|"sethpt"
203 SET_USER                "rewriteuser"|"setuser"|"setu"
204 SET_USERPASS    "rewriteuserpass"|"setuserpass"|"setup"
205 SET_PORT                "rewriteport"|"setport"|"setp"
206 SET_URI                 "rewriteuri"|"seturi"
207 REVERT_URI              "revert_uri"
208 PREFIX                  "prefix"
209 STRIP                   "strip"
210 STRIP_TAIL              "strip_tail"
211 SET_USERPHONE           "userphone"
212 APPEND_BRANCH   "append_branch"
213 IF                              "if"
214 ELSE                    "else"
215 SET_ADV_ADDRESS "set_advertised_address"
216 SET_ADV_PORT    "set_advertised_port"
217 FORCE_SEND_SOCKET       "force_send_socket"
218 SET_FWD_NO_CONNECT              "set_forward_no_connect"
219 SET_RPL_NO_CONNECT      "set_reply_no_connect"
220 SET_FWD_CLOSE   "set_forward_close"
221 SET_RPL_CLOSE   "set_reply_close"
222 SWITCH                  "switch"
223 CASE                    "case"
224 DEFAULT                 "default"
225 WHILE                   "while"
226
227 INCLUDEFILE     "include_file"
228
229 /*ACTION LVALUES*/
230 URIHOST                 "uri:host"
231 URIPORT                 "uri:port"
232
233 MAX_LEN                 "max_len"
234
235
236 /* condition keywords */
237 METHOD  method
238 /* hack -- the second element in first line is referable
239    as either uri or status; it only would makes sense to
240    call it "uri" from route{} and status from onreply_route{}
241 */
242 URI             "uri"|"status"
243 FROM_URI        "from_uri"
244 TO_URI          "to_uri"
245 SRCIP   src_ip
246 SRCPORT src_port
247 DSTIP   dst_ip
248 DSTPORT dst_port
249 SNDIP   snd_ip
250 SNDPORT snd_port
251 SNDPROTO        snd_proto|to_proto
252 SNDAF           snd_af|to_af
253 TOIP    to_ip
254 TOPORT  to_port
255 PROTO   proto
256 AF              af
257 MYSELF  myself
258 MSGLEN                  "msg:len"
259 RETCODE \$\?|\$retcode
260 /* operators */
261 EQUAL   =
262 EQUAL_T ==
263 GT      >
264 LT      <
265 GTE     >=
266 LTE     <=
267 DIFF    !=
268 MATCH   =~
269 ADDEQ     "+="
270 NOT             !|"not"
271 LOG_AND         "and"|"&&"
272 BIN_AND         "&"
273 LOG_OR          "or"|"||"
274 BIN_OR          "|"
275 PLUS    "+"
276 MINUS   "-"
277 MODULO  "mod"
278 STRLEN  "strlen"
279 STREMPTY        "strempty"
280 DEFINED         "defined"
281 STREQ   eq
282 INTEQ   ieq
283 STRDIFF ne
284 INTDIFF ine
285 INTCAST \(int\)
286 STRCAST \(str\)
287
288 /* Attribute specification */
289 ATTR_MARK   "%"
290 VAR_MARK    "$"
291 SELECT_MARK  "@"
292 ATTR_FROM         "f"
293 ATTR_TO           "t"
294 ATTR_FROMURI      "fr"
295 ATTR_TOURI       "tr"
296 ATTR_FROMUSER     "fu"
297 ATTR_TOUSER       "tu"
298 ATTR_FROMDOMAIN   "fd"
299 ATTR_TODOMAIN     "td"
300 ATTR_GLOBAL       "g"
301
302 /* avp prefix */
303 AVP_PREF        (([ft][rud]?)|g)\.
304
305 /* config vars. */
306 DEBUG   debug
307 FORK    fork
308 LOGSTDERROR     log_stderror
309 LOGFACILITY     log_facility
310 LOGNAME         log_name
311 LISTEN          listen
312 ALIAS           alias
313 SR_AUTO_ALIASES auto_aliases
314 DNS              dns
315 REV_DNS  rev_dns
316 DNS_TRY_IPV6    dns_try_ipv6
317 DNS_TRY_NAPTR   dns_try_naptr
318 DNS_SRV_LB              dns_srv_lb|dns_srv_loadbalancing
319 DNS_UDP_PREF    dns_udp_pref|dns_udp_preference
320 DNS_TCP_PREF    dns_tcp_pref|dns_tcp_preference
321 DNS_TLS_PREF    dns_tls_pref|dns_tls_preference
322 DNS_SCTP_PREF   dns_sctp_pref|dns_sctp_preference
323 DNS_RETR_TIME   dns_retr_time
324 DNS_RETR_NO             dns_retr_no
325 DNS_SERVERS_NO  dns_servers_no
326 DNS_USE_SEARCH  dns_use_search_list
327 DNS_SEARCH_FMATCH       dns_search_full_match
328 /* dns cache */
329 DNS_CACHE_INIT  dns_cache_init
330 DNS_USE_CACHE   use_dns_cache
331 DNS_USE_FAILOVER        use_dns_failover
332 DNS_CACHE_FLAGS         dns_cache_flags
333 DNS_CACHE_NEG_TTL       dns_cache_negative_ttl
334 DNS_CACHE_MIN_TTL       dns_cache_min_ttl
335 DNS_CACHE_MAX_TTL       dns_cache_max_ttl
336 DNS_CACHE_MEM           dns_cache_mem
337 DNS_CACHE_GC_INT        dns_cache_gc_interval
338 DNS_CACHE_DEL_NONEXP    dns_cache_del_nonexp|dns_cache_delete_nonexpired
339 /* blacklist */
340 DST_BLST_INIT   dst_blacklist_init
341 USE_DST_BLST            use_dst_blacklist
342 DST_BLST_MEM            dst_blacklist_mem
343 DST_BLST_TTL            dst_blacklist_expire|dst_blacklist_ttl
344 DST_BLST_GC_INT         dst_blacklist_gc_interval
345
346
347 PORT    port
348 STAT    statistics
349 MAXBUFFER maxbuffer
350 CHILDREN children
351 CHECK_VIA       check_via
352 PHONE2TEL       phone2tel
353 SYN_BRANCH syn_branch
354 MEMLOG          "memlog"|"mem_log"
355 MEMDBG          "memdbg"|"mem_dbg"
356 MEMSUM          "mem_summary"
357 SIP_WARNING sip_warning
358 SERVER_SIGNATURE server_signature
359 SERVER_HEADER server_header
360 USER_AGENT_HEADER user_agent_header
361 REPLY_TO_VIA reply_to_via
362 USER            "user"|"uid"
363 GROUP           "group"|"gid"
364 CHROOT          "chroot"
365 WDIR            "workdir"|"wdir"
366 MHOMED          mhomed
367 DISABLE_TCP             "disable_tcp"
368 TCP_CHILDREN    "tcp_children"
369 TCP_ACCEPT_ALIASES      "tcp_accept_aliases"
370 TCP_SEND_TIMEOUT        "tcp_send_timeout"
371 TCP_CONNECT_TIMEOUT     "tcp_connect_timeout"
372 TCP_CON_LIFETIME        "tcp_connection_lifetime"
373 TCP_POLL_METHOD         "tcp_poll_method"
374 TCP_MAX_CONNECTIONS     "tcp_max_connections"
375 TCP_NO_CONNECT          "tcp_no_connect"
376 TCP_SOURCE_IPV4         "tcp_source_ipv4"
377 TCP_SOURCE_IPV6         "tcp_source_ipv6"
378 TCP_OPT_FD_CACHE        "tcp_fd_cache"
379 TCP_OPT_BUF_WRITE       "tcp_buf_write"|"tcp_async"
380 TCP_OPT_CONN_WQ_MAX     "tcp_conn_wq_max"
381 TCP_OPT_WQ_MAX          "tcp_wq_max"
382 TCP_OPT_RD_BUF          "tcp_rd_buf_size"
383 TCP_OPT_WQ_BLK          "tcp_wq_blk_size"
384 TCP_OPT_DEFER_ACCEPT "tcp_defer_accept"
385 TCP_OPT_DELAYED_ACK     "tcp_delayed_ack"
386 TCP_OPT_SYNCNT          "tcp_syncnt"
387 TCP_OPT_LINGER2         "tcp_linger2"
388 TCP_OPT_KEEPALIVE       "tcp_keepalive"
389 TCP_OPT_KEEPIDLE        "tcp_keepidle"
390 TCP_OPT_KEEPINTVL       "tcp_keepintvl"
391 TCP_OPT_KEEPCNT         "tcp_keepcnt"
392 TCP_OPT_CRLF_PING       "tcp_crlf_ping"
393 DISABLE_TLS             "disable_tls"|"tls_disable"
394 ENABLE_TLS              "enable_tls"|"tls_enable"
395 TLSLOG                  "tlslog"|"tls_log"
396 TLS_PORT_NO             "tls_port_no"
397 TLS_METHOD              "tls_method"
398 TLS_VERIFY              "tls_verify"
399 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
400 TLS_CERTIFICATE "tls_certificate"
401 TLS_PRIVATE_KEY "tls_private_key"
402 TLS_CA_LIST             "tls_ca_list"
403 TLS_HANDSHAKE_TIMEOUT   "tls_handshake_timeout"
404 TLS_SEND_TIMEOUT        "tls_send_timeout"
405 DISABLE_SCTP    "disable_sctp"
406 ENABLE_SCTP     "enable_sctp"
407 SCTP_CHILDREN   "sctp_children"
408 SCTP_SOCKET_RCVBUF      "sctp_socket_rcvbuf"|"sctp_socket_receive_buffer"
409 SCTP_SOCKET_SNDBUF      "sctp_socket_sndbuf"|"sctp_socket_send_buffer"
410 SCTP_AUTOCLOSE  "sctp_autoclose"
411 SCTP_SEND_TTL   "sctp_send_ttl"
412 SCTP_SEND_RETRIES       "sctp_send_retries"
413 SCTP_ASSOC_TRACKING     "sctp_assoc_tracking"
414 SCTP_ASSOC_REUSE        "sctp_assoc_reuse"
415 SCTP_MAX_ASSOCS         "sctp_max_assocs"
416 SCTP_SRTO_INITIAL       "sctp_srto_initial"
417 SCTP_SRTO_MAX           "sctp_srto_max"
418 SCTP_SRTO_MIN           "sctp_srto_min"
419 SCTP_ASOCMAXRXT         "sctp_asocmaxrxt"
420 SCTP_INIT_MAX_ATTEMPTS          "sctp_init_max_attempts"
421 SCTP_INIT_MAX_TIMEO                     "sctp_init_max_timeo"
422 SCTP_HBINTERVAL                         "sctp_hbinterval"
423 SCTP_PATHMAXRXT                         "sctp_pathmaxrxt"
424 SCTP_SACK_DELAY                         "sctp_sack_delay"
425 SCTP_SACK_FREQ                          "sctp_sack_freq"
426 SCTP_MAX_BURST                          "sctp_max_burst"
427
428 ADVERTISED_ADDRESS      "advertised_address"
429 ADVERTISED_PORT         "advertised_port"
430 DISABLE_CORE            "disable_core_dump"
431 OPEN_FD_LIMIT           "open_files_limit"
432 SHM_FORCE_ALLOC         "shm_force_alloc"
433 MLOCK_PAGES                     "mlock_pages"
434 REAL_TIME                       "real_time"
435 RT_PRIO                         "rt_prio"
436 RT_POLICY                       "rt_policy"
437 RT_TIMER1_PRIO          "rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
438 RT_TIMER1_POLICY        "rt_timer1_policy"|"rt_ftimer_policy"
439 RT_TIMER2_PRIO          "rt_timer2_prio"|"rt_stimer_prio"
440 RT_TIMER2_POLICY        "rt_timer2_policy"|"rt_stimer_policy"
441 MCAST_LOOPBACK          "mcast_loopback"
442 MCAST_TTL               "mcast_ttl"
443 TOS                     "tos"
444 PMTU_DISCOVERY  "pmtu_discovery"
445 KILL_TIMEOUT    "exit_timeout"|"ser_kill_timeout"
446 MAX_WLOOPS              "max_while_loops"
447
448 /* stun config variables */
449 STUN_REFRESH_INTERVAL "stun_refresh_interval"
450 STUN_ALLOW_STUN "stun_allow_stun"
451 STUN_ALLOW_FP "stun_allow_fp"
452
453 SERVER_ID     "server_id"
454
455 CFG_DESCRIPTION         "description"|"descr"|"desc"
456
457 LOADMODULE      loadmodule
458 LOADPATH        "loadpath"|"mpath"
459 MODPARAM        modparam
460
461 /* values */
462 YES                     "yes"|"true"|"on"|"enable"
463 NO                      "no"|"false"|"off"|"disable"
464 UDP                     "udp"|"UDP"
465 TCP                     "tcp"|"TCP"
466 TLS                     "tls"|"TLS"
467 SCTP            "sctp"|"SCTP"
468 INET            "inet"|"INET"
469 INET6           "inet6"|"INET6"
470 SSLv23                  "sslv23"|"SSLv23"|"SSLV23"
471 SSLv2                   "sslv2"|"SSLv2"|"SSLV2"
472 SSLv3                   "sslv3"|"SSLv3"|"SSLV3"
473 TLSv1                   "tlsv1"|"TLSv1"|"TLSV1"
474
475 LETTER          [a-zA-Z]
476 DIGIT           [0-9]
477 ALPHANUM        {LETTER}|{DIGIT}|[_]
478 ID                      {LETTER}{ALPHANUM}*
479 NUM_ID          {ALPHANUM}+
480 HEX                     [0-9a-fA-F]
481 HEXNUMBER       0x{HEX}+
482 OCTNUMBER       0[0-7]+
483 DECNUMBER       0|([1-9]{DIGIT}*)
484 BINNUMBER       [0-1]+b
485 HEX4            {HEX}{1,4}
486 IPV6ADDR        ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
487 QUOTES          \"
488 TICK            \'
489 SLASH           "/"
490 SEMICOLON       ;
491 RPAREN          \)
492 LPAREN          \(
493 LBRACE          \{
494 RBRACE          \}
495 LBRACK          \[
496 RBRACK          \]
497 COMMA           ","
498 COLON           ":"
499 STAR            \*
500 DOT                     \.
501 CR                      \n
502 EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*":"[a-zA-Z][0-9a-zA-Z-]*
503
504
505 COM_LINE        #
506 COM_START       "/\*"
507 COM_END         "\*/"
508
509 EAT_ABLE        [\ \t\b\r]
510
511 %%
512
513
514 <INITIAL>{EAT_ABLE}     { count(); }
515
516 <INITIAL>{FORWARD}      {count(); yylval.strval=yytext; return FORWARD; }
517 <INITIAL>{FORWARD_TCP}  {count(); yylval.strval=yytext; return FORWARD_TCP; }
518 <INITIAL>{FORWARD_TLS}  {count(); yylval.strval=yytext; return FORWARD_TLS; }
519 <INITIAL>{FORWARD_SCTP} {count(); yylval.strval=yytext; return FORWARD_SCTP;}
520 <INITIAL>{FORWARD_UDP}  {count(); yylval.strval=yytext; return FORWARD_UDP; }
521 <INITIAL>{DROP} { count(); yylval.strval=yytext; return DROP; }
522 <INITIAL>{EXIT} { count(); yylval.strval=yytext; return EXIT; }
523 <INITIAL>{RETURN}       { count(); yylval.strval=yytext; return RETURN; }
524 <INITIAL>{BREAK}        { count(); yylval.strval=yytext; return BREAK; }
525 <INITIAL>{SEND} { count(); yylval.strval=yytext; return SEND; }
526 <INITIAL>{SEND_TCP}     { count(); yylval.strval=yytext; return SEND_TCP; }
527 <INITIAL>{LOG}  { count(); yylval.strval=yytext; return LOG_TOK; }
528 <INITIAL>{ERROR}        { count(); yylval.strval=yytext; return ERROR; }
529 <INITIAL>{SETFLAG}      { count(); yylval.strval=yytext; return SETFLAG; }
530 <INITIAL>{RESETFLAG}    { count(); yylval.strval=yytext; return RESETFLAG; }
531 <INITIAL>{ISFLAGSET}    { count(); yylval.strval=yytext; return ISFLAGSET; }
532 <INITIAL>{FLAGS_DECL}   { count(); yylval.strval=yytext; return FLAGS_DECL; }
533 <INITIAL>{SETAVPFLAG}   { count(); yylval.strval=yytext; return SETAVPFLAG; }
534 <INITIAL>{RESETAVPFLAG} { count(); yylval.strval=yytext; return RESETAVPFLAG; }
535 <INITIAL>{ISAVPFLAGSET} { count(); yylval.strval=yytext; return ISAVPFLAGSET; }
536 <INITIAL>{AVPFLAGS_DECL}        { count(); yylval.strval=yytext; return AVPFLAGS_DECL; }
537 <INITIAL>{MSGLEN}       { count(); yylval.strval=yytext; return MSGLEN; }
538 <INITIAL>{RETCODE}      { count(); yylval.strval=yytext; return RETCODE; }
539 <INITIAL>{ROUTE}        { count(); yylval.strval=yytext; return ROUTE; }
540 <INITIAL>{ROUTE_ONREPLY}        { count(); yylval.strval=yytext;
541                                                                 return ROUTE_ONREPLY; }
542 <INITIAL>{ROUTE_FAILURE}        { count(); yylval.strval=yytext;
543                                                                 return ROUTE_FAILURE; }
544 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
545 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
546 <INITIAL>{ROUTE_EVENT} { count(); yylval.strval=yytext; return ROUTE_EVENT; }
547 <INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
548 <INITIAL>{SET_HOST}     { count(); yylval.strval=yytext; return SET_HOST; }
549 <INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
550 <INITIAL>{SET_HOSTPORTTRANS}    { count(); yylval.strval=yytext; return SET_HOSTPORTTRANS; }
551 <INITIAL>{SET_USER}     { count(); yylval.strval=yytext; return SET_USER; }
552 <INITIAL>{SET_USERPASS} { count(); yylval.strval=yytext; return SET_USERPASS; }
553 <INITIAL>{SET_PORT}     { count(); yylval.strval=yytext; return SET_PORT; }
554 <INITIAL>{SET_URI}      { count(); yylval.strval=yytext; return SET_URI; }
555 <INITIAL>{REVERT_URI}   { count(); yylval.strval=yytext; return REVERT_URI; }
556 <INITIAL>{PREFIX}       { count(); yylval.strval=yytext; return PREFIX; }
557 <INITIAL>{STRIP}        { count(); yylval.strval=yytext; return STRIP; }
558 <INITIAL>{STRIP_TAIL}   { count(); yylval.strval=yytext; return STRIP_TAIL; }
559 <INITIAL>{APPEND_BRANCH}        { count(); yylval.strval=yytext;
560                                                                 return APPEND_BRANCH; }
561 <INITIAL>{SET_USERPHONE}        { count(); yylval.strval=yytext;
562                                                                 return SET_USERPHONE; }
563 <INITIAL>{FORCE_RPORT}  { count(); yylval.strval=yytext; return FORCE_RPORT; }
564 <INITIAL>{ADD_LOCAL_RPORT}      { count(); yylval.strval=yytext;
565                                                                 return ADD_LOCAL_RPORT; }
566 <INITIAL>{FORCE_TCP_ALIAS}      { count(); yylval.strval=yytext;
567                                                                 return FORCE_TCP_ALIAS; }
568 <INITIAL>{UDP_MTU}      { count(); yylval.strval=yytext; return UDP_MTU; }
569 <INITIAL>{UDP_MTU_TRY_PROTO}    { count(); yylval.strval=yytext;
570                                                                         return UDP_MTU_TRY_PROTO; }
571 <INITIAL>{IF}   { count(); yylval.strval=yytext; return IF; }
572 <INITIAL>{ELSE} { count(); yylval.strval=yytext; return ELSE; }
573
574 <INITIAL>{SET_ADV_ADDRESS}      { count(); yylval.strval=yytext;
575                                                                                 return SET_ADV_ADDRESS; }
576 <INITIAL>{SET_ADV_PORT} { count(); yylval.strval=yytext;
577                                                                                 return SET_ADV_PORT; }
578 <INITIAL>{FORCE_SEND_SOCKET}    {       count(); yylval.strval=yytext;
579                                                                         return FORCE_SEND_SOCKET; }
580 <INITIAL>{SET_FWD_NO_CONNECT}   { count(); yylval.strval=yytext;
581                                                                         return SET_FWD_NO_CONNECT; }
582 <INITIAL>{SET_RPL_NO_CONNECT}   { count(); yylval.strval=yytext;
583                                                                         return SET_RPL_NO_CONNECT; }
584 <INITIAL>{SET_FWD_CLOSE}                { count(); yylval.strval=yytext;
585                                                                         return SET_FWD_CLOSE; }
586 <INITIAL>{SET_RPL_CLOSE}                { count(); yylval.strval=yytext;
587                                                                         return SET_RPL_CLOSE; }
588 <INITIAL>{SWITCH}       { count(); yylval.strval=yytext; return SWITCH; }
589 <INITIAL>{CASE} { count(); yylval.strval=yytext; return CASE; }
590 <INITIAL>{DEFAULT}      { count(); yylval.strval=yytext; return DEFAULT; }
591 <INITIAL>{WHILE}        { count(); yylval.strval=yytext; return WHILE; }
592
593 <INITIAL>{INCLUDEFILE}  { count(); BEGIN(INCLF); }
594
595 <INITIAL>{URIHOST}      { count(); yylval.strval=yytext; return URIHOST; }
596 <INITIAL>{URIPORT}      { count(); yylval.strval=yytext; return URIPORT; }
597
598 <INITIAL>{MAX_LEN}      { count(); yylval.strval=yytext; return MAX_LEN; }
599
600 <INITIAL>{METHOD}       { count(); yylval.strval=yytext; return METHOD; }
601 <INITIAL>{URI}  { count(); yylval.strval=yytext; return URI; }
602 <INITIAL>{FROM_URI}     { count(); yylval.strval=yytext; return FROM_URI; }
603 <INITIAL>{TO_URI}       { count(); yylval.strval=yytext; return TO_URI; }
604 <INITIAL>{SRCIP}        { count(); yylval.strval=yytext; return SRCIP; }
605 <INITIAL>{SRCPORT}      { count(); yylval.strval=yytext; return SRCPORT; }
606 <INITIAL>{DSTIP}        { count(); yylval.strval=yytext; return DSTIP; }
607 <INITIAL>{DSTPORT}      { count(); yylval.strval=yytext; return DSTPORT; }
608 <INITIAL>{SNDIP}        { count(); yylval.strval=yytext; return SNDIP; }
609 <INITIAL>{SNDPORT}      { count(); yylval.strval=yytext; return SNDPORT; }
610 <INITIAL>{SNDPROTO}     { count(); yylval.strval=yytext; return SNDPROTO; }
611 <INITIAL>{SNDAF}        { count(); yylval.strval=yytext; return SNDAF; }
612 <INITIAL>{TOIP}         { count(); yylval.strval=yytext; return TOIP; }
613 <INITIAL>{TOPORT}       { count(); yylval.strval=yytext; return TOPORT; }
614 <INITIAL>{PROTO}        { count(); yylval.strval=yytext; return PROTO; }
615 <INITIAL>{AF}   { count(); yylval.strval=yytext; return AF; }
616 <INITIAL>{MYSELF}       { count(); yylval.strval=yytext; return MYSELF; }
617
618 <INITIAL>{DEBUG}        { count(); yylval.strval=yytext; return DEBUG_V; }
619 <INITIAL>{FORK}         { count(); yylval.strval=yytext; return FORK; }
620 <INITIAL>{LOGSTDERROR}  { yylval.strval=yytext; return LOGSTDERROR; }
621 <INITIAL>{LOGFACILITY}  { yylval.strval=yytext; return LOGFACILITY; }
622 <INITIAL>{LOGNAME}      { yylval.strval=yytext; return LOGNAME; }
623 <INITIAL>{LISTEN}       { count(); yylval.strval=yytext; return LISTEN; }
624 <INITIAL>{ALIAS}        { count(); yylval.strval=yytext; return ALIAS; }
625 <INITIAL>{SR_AUTO_ALIASES}      { count(); yylval.strval=yytext;
626                                                                         return SR_AUTO_ALIASES; }
627 <INITIAL>{DNS}  { count(); yylval.strval=yytext; return DNS; }
628 <INITIAL>{REV_DNS}      { count(); yylval.strval=yytext; return REV_DNS; }
629 <INITIAL>{DNS_TRY_IPV6} { count(); yylval.strval=yytext;
630                                                                 return DNS_TRY_IPV6; }
631 <INITIAL>{DNS_TRY_NAPTR}        { count(); yylval.strval=yytext;
632                                                                 return DNS_TRY_NAPTR; }
633 <INITIAL>{DNS_SRV_LB}   { count(); yylval.strval=yytext;
634                                                                 return DNS_SRV_LB; }
635 <INITIAL>{DNS_UDP_PREF} { count(); yylval.strval=yytext;
636                                                                 return DNS_UDP_PREF; }
637 <INITIAL>{DNS_TCP_PREF} { count(); yylval.strval=yytext;
638                                                                 return DNS_TCP_PREF; }
639 <INITIAL>{DNS_TLS_PREF} { count(); yylval.strval=yytext;
640                                                                 return DNS_TLS_PREF; }
641 <INITIAL>{DNS_SCTP_PREF}        { count(); yylval.strval=yytext;
642                                                                 return DNS_SCTP_PREF; }
643 <INITIAL>{DNS_RETR_TIME}        { count(); yylval.strval=yytext;
644                                                                 return DNS_RETR_TIME; }
645 <INITIAL>{DNS_RETR_NO}  { count(); yylval.strval=yytext;
646                                                                 return DNS_RETR_NO; }
647 <INITIAL>{DNS_SERVERS_NO}       { count(); yylval.strval=yytext;
648                                                                 return DNS_SERVERS_NO; }
649 <INITIAL>{DNS_USE_SEARCH}       { count(); yylval.strval=yytext;
650                                                                 return DNS_USE_SEARCH; }
651 <INITIAL>{DNS_SEARCH_FMATCH}    { count(); yylval.strval=yytext;
652                                                                 return DNS_SEARCH_FMATCH; }
653 <INITIAL>{DNS_CACHE_INIT}       { count(); yylval.strval=yytext;
654                                                                 return DNS_CACHE_INIT; }
655 <INITIAL>{DNS_USE_CACHE}        { count(); yylval.strval=yytext;
656                                                                 return DNS_USE_CACHE; }
657 <INITIAL>{DNS_USE_FAILOVER}     { count(); yylval.strval=yytext;
658                                                                 return DNS_USE_FAILOVER; }
659 <INITIAL>{DNS_CACHE_FLAGS}      { count(); yylval.strval=yytext;
660                                                                 return DNS_CACHE_FLAGS; }
661 <INITIAL>{DNS_CACHE_NEG_TTL}    { count(); yylval.strval=yytext;
662                                                                 return DNS_CACHE_NEG_TTL; }
663 <INITIAL>{DNS_CACHE_MIN_TTL}    { count(); yylval.strval=yytext;
664                                                                 return DNS_CACHE_MIN_TTL; }
665 <INITIAL>{DNS_CACHE_MAX_TTL}    { count(); yylval.strval=yytext;
666                                                                 return DNS_CACHE_MAX_TTL; }
667 <INITIAL>{DNS_CACHE_MEM}        { count(); yylval.strval=yytext;
668                                                                 return DNS_CACHE_MEM; }
669 <INITIAL>{DNS_CACHE_GC_INT}     { count(); yylval.strval=yytext;
670                                                                 return DNS_CACHE_GC_INT; }
671 <INITIAL>{DNS_CACHE_DEL_NONEXP} { count(); yylval.strval=yytext;
672                                                                 return DNS_CACHE_DEL_NONEXP; }
673 <INITIAL>{DST_BLST_INIT}        { count(); yylval.strval=yytext;
674                                                                 return DST_BLST_INIT; }
675 <INITIAL>{USE_DST_BLST} { count(); yylval.strval=yytext;
676                                                                 return USE_DST_BLST; }
677 <INITIAL>{DST_BLST_MEM} { count(); yylval.strval=yytext;
678                                                                 return DST_BLST_MEM; }
679 <INITIAL>{DST_BLST_TTL} { count(); yylval.strval=yytext;
680                                                                 return DST_BLST_TTL; }
681 <INITIAL>{DST_BLST_GC_INT}      { count(); yylval.strval=yytext;
682                                                                 return DST_BLST_GC_INT; }
683 <INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
684 <INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
685 <INITIAL>{MAXBUFFER}    { count(); yylval.strval=yytext; return MAXBUFFER; }
686 <INITIAL>{CHILDREN}     { count(); yylval.strval=yytext; return CHILDREN; }
687 <INITIAL>{CHECK_VIA}    { count(); yylval.strval=yytext; return CHECK_VIA; }
688 <INITIAL>{PHONE2TEL}    { count(); yylval.strval=yytext; return PHONE2TEL; }
689 <INITIAL>{SYN_BRANCH}   { count(); yylval.strval=yytext; return SYN_BRANCH; }
690 <INITIAL>{MEMLOG}       { count(); yylval.strval=yytext; return MEMLOG; }
691 <INITIAL>{MEMDBG}       { count(); yylval.strval=yytext; return MEMDBG; }
692 <INITIAL>{MEMSUM}       { count(); yylval.strval=yytext; return MEMSUM; }
693 <INITIAL>{SIP_WARNING}  { count(); yylval.strval=yytext; return SIP_WARNING; }
694 <INITIAL>{USER}         { count(); yylval.strval=yytext; return USER; }
695 <INITIAL>{GROUP}        { count(); yylval.strval=yytext; return GROUP; }
696 <INITIAL>{CHROOT}       { count(); yylval.strval=yytext; return CHROOT; }
697 <INITIAL>{WDIR} { count(); yylval.strval=yytext; return WDIR; }
698 <INITIAL>{MHOMED}       { count(); yylval.strval=yytext; return MHOMED; }
699 <INITIAL>{DISABLE_TCP}  { count(); yylval.strval=yytext; return DISABLE_TCP; }
700 <INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
701 <INITIAL>{TCP_ACCEPT_ALIASES}   { count(); yylval.strval=yytext;
702                                                                         return TCP_ACCEPT_ALIASES; }
703 <INITIAL>{TCP_SEND_TIMEOUT}             { count(); yylval.strval=yytext;
704                                                                         return TCP_SEND_TIMEOUT; }
705 <INITIAL>{TCP_CONNECT_TIMEOUT}          { count(); yylval.strval=yytext;
706                                                                         return TCP_CONNECT_TIMEOUT; }
707 <INITIAL>{TCP_CON_LIFETIME}             { count(); yylval.strval=yytext;
708                                                                         return TCP_CON_LIFETIME; }
709 <INITIAL>{TCP_POLL_METHOD}              { count(); yylval.strval=yytext;
710                                                                         return TCP_POLL_METHOD; }
711 <INITIAL>{TCP_MAX_CONNECTIONS}  { count(); yylval.strval=yytext;
712                                                                         return TCP_MAX_CONNECTIONS; }
713 <INITIAL>{TCP_NO_CONNECT}               { count(); yylval.strval=yytext;
714                                                                         return TCP_NO_CONNECT; }
715 <INITIAL>{TCP_SOURCE_IPV4}              { count(); yylval.strval=yytext;
716                                                                         return TCP_SOURCE_IPV4; }
717 <INITIAL>{TCP_SOURCE_IPV6}              { count(); yylval.strval=yytext;
718                                                                         return TCP_SOURCE_IPV6; }
719 <INITIAL>{TCP_OPT_FD_CACHE}             { count(); yylval.strval=yytext;
720                                                                         return TCP_OPT_FD_CACHE; }
721 <INITIAL>{TCP_OPT_CONN_WQ_MAX}  { count(); yylval.strval=yytext;
722                                                                         return TCP_OPT_CONN_WQ_MAX; }
723 <INITIAL>{TCP_OPT_WQ_MAX}       { count(); yylval.strval=yytext;
724                                                                         return TCP_OPT_WQ_MAX; }
725 <INITIAL>{TCP_OPT_RD_BUF}       { count(); yylval.strval=yytext;
726                                                                         return TCP_OPT_RD_BUF; }
727 <INITIAL>{TCP_OPT_WQ_BLK}       { count(); yylval.strval=yytext;
728                                                                         return TCP_OPT_WQ_BLK; }
729 <INITIAL>{TCP_OPT_BUF_WRITE}    { count(); yylval.strval=yytext;
730                                                                         return TCP_OPT_BUF_WRITE; }
731 <INITIAL>{TCP_OPT_DEFER_ACCEPT} { count(); yylval.strval=yytext;
732                                                                         return TCP_OPT_DEFER_ACCEPT; }
733 <INITIAL>{TCP_OPT_DELAYED_ACK}  { count(); yylval.strval=yytext;
734                                                                         return TCP_OPT_DELAYED_ACK; }
735 <INITIAL>{TCP_OPT_SYNCNT}               { count(); yylval.strval=yytext;
736                                                                         return TCP_OPT_SYNCNT; }
737 <INITIAL>{TCP_OPT_LINGER2}              { count(); yylval.strval=yytext;
738                                                                         return TCP_OPT_LINGER2; }
739 <INITIAL>{TCP_OPT_KEEPALIVE}    { count(); yylval.strval=yytext;
740                                                                         return TCP_OPT_KEEPALIVE; }
741 <INITIAL>{TCP_OPT_KEEPIDLE}             { count(); yylval.strval=yytext;
742                                                                         return TCP_OPT_KEEPIDLE; }
743 <INITIAL>{TCP_OPT_KEEPINTVL}    { count(); yylval.strval=yytext;
744                                                                         return TCP_OPT_KEEPINTVL; }
745 <INITIAL>{TCP_OPT_KEEPCNT}      { count(); yylval.strval=yytext;
746                                                                         return TCP_OPT_KEEPCNT; }
747 <INITIAL>{TCP_OPT_CRLF_PING}    { count(); yylval.strval=yytext;
748                                                                         return TCP_OPT_CRLF_PING; }
749 <INITIAL>{DISABLE_TLS}  { count(); yylval.strval=yytext; return DISABLE_TLS; }
750 <INITIAL>{ENABLE_TLS}   { count(); yylval.strval=yytext; return ENABLE_TLS; }
751 <INITIAL>{TLSLOG}               { count(); yylval.strval=yytext; return TLS_PORT_NO; }
752 <INITIAL>{TLS_PORT_NO}  { count(); yylval.strval=yytext; return TLS_PORT_NO; }
753 <INITIAL>{TLS_METHOD}   { count(); yylval.strval=yytext; return TLS_METHOD; }
754 <INITIAL>{TLS_VERIFY}   { count(); yylval.strval=yytext; return TLS_VERIFY; }
755 <INITIAL>{TLS_REQUIRE_CERTIFICATE}      { count(); yylval.strval=yytext;
756                                                                                 return TLS_REQUIRE_CERTIFICATE; }
757 <INITIAL>{TLS_CERTIFICATE}      { count(); yylval.strval=yytext;
758                                                                                 return TLS_CERTIFICATE; }
759 <INITIAL>{TLS_PRIVATE_KEY}      { count(); yylval.strval=yytext;
760                                                                                 return TLS_PRIVATE_KEY; }
761 <INITIAL>{TLS_CA_LIST}  { count(); yylval.strval=yytext;
762                                                                                 return TLS_CA_LIST; }
763 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}        { count(); yylval.strval=yytext;
764                                                                                 return TLS_HANDSHAKE_TIMEOUT; }
765 <INITIAL>{TLS_SEND_TIMEOUT}     { count(); yylval.strval=yytext;
766                                                                                 return TLS_SEND_TIMEOUT; }
767 <INITIAL>{DISABLE_SCTP} { count(); yylval.strval=yytext; return DISABLE_SCTP;}
768 <INITIAL>{ENABLE_SCTP}  { count(); yylval.strval=yytext; return ENABLE_SCTP;}
769 <INITIAL>{SCTP_CHILDREN}        { count(); yylval.strval=yytext;
770                                                                                 return SCTP_CHILDREN; }
771 <INITIAL>{SCTP_SOCKET_RCVBUF}   { count(); yylval.strval=yytext;
772                                                                                 return SCTP_SOCKET_RCVBUF; }
773 <INITIAL>{SCTP_SOCKET_SNDBUF}   { count(); yylval.strval=yytext;
774                                                                                 return SCTP_SOCKET_SNDBUF; }
775 <INITIAL>{SCTP_AUTOCLOSE}       { count(); yylval.strval=yytext;
776                                                                                 return SCTP_AUTOCLOSE; }
777 <INITIAL>{SCTP_SEND_TTL}        { count(); yylval.strval=yytext;
778                                                                                 return SCTP_SEND_TTL; }
779 <INITIAL>{SCTP_SEND_RETRIES}    { count(); yylval.strval=yytext;
780                                                                                 return SCTP_SEND_RETRIES; }
781 <INITIAL>{SCTP_ASSOC_TRACKING}  { count(); yylval.strval=yytext;
782                                                                                 return SCTP_ASSOC_TRACKING; }
783 <INITIAL>{SCTP_ASSOC_REUSE}             { count(); yylval.strval=yytext;
784                                                                                 return SCTP_ASSOC_REUSE; }
785 <INITIAL>{SCTP_MAX_ASSOCS}              { count(); yylval.strval=yytext;
786                                                                                 return SCTP_MAX_ASSOCS; }
787 <INITIAL>{SCTP_SRTO_INITIAL}    { count(); yylval.strval=yytext;
788                                                                                 return SCTP_SRTO_INITIAL; }
789 <INITIAL>{SCTP_SRTO_MAX}        { count(); yylval.strval=yytext;
790                                                                                 return SCTP_SRTO_MAX; }
791 <INITIAL>{SCTP_SRTO_MIN}        { count(); yylval.strval=yytext;
792                                                                                 return SCTP_SRTO_MIN; }
793 <INITIAL>{SCTP_ASOCMAXRXT}      { count(); yylval.strval=yytext;
794                                                                                 return SCTP_ASOCMAXRXT; }
795 <INITIAL>{SCTP_INIT_MAX_ATTEMPTS}       { count(); yylval.strval=yytext;
796                                                                                 return SCTP_INIT_MAX_ATTEMPTS; }
797 <INITIAL>{SCTP_INIT_MAX_TIMEO}  { count(); yylval.strval=yytext;
798                                                                                 return SCTP_INIT_MAX_TIMEO; }
799 <INITIAL>{SCTP_HBINTERVAL}      { count(); yylval.strval=yytext;
800                                                                                 return SCTP_HBINTERVAL; }
801 <INITIAL>{SCTP_PATHMAXRXT}      { count(); yylval.strval=yytext;
802                                                                                 return SCTP_PATHMAXRXT; }
803 <INITIAL>{SCTP_SACK_DELAY}      { count(); yylval.strval=yytext;
804                                                                                 return SCTP_SACK_DELAY; }
805 <INITIAL>{SCTP_SACK_FREQ}       { count(); yylval.strval=yytext;
806                                                                                 return SCTP_SACK_FREQ; }
807 <INITIAL>{SCTP_MAX_BURST}       { count(); yylval.strval=yytext;
808                                                                                 return SCTP_MAX_BURST; }
809 <INITIAL>{SERVER_SIGNATURE}     { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
810 <INITIAL>{SERVER_HEADER}        { count(); yylval.strval=yytext; return SERVER_HEADER; }
811 <INITIAL>{USER_AGENT_HEADER}    { count(); yylval.strval=yytext; return USER_AGENT_HEADER; }
812 <INITIAL>{REPLY_TO_VIA} { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
813 <INITIAL>{ADVERTISED_ADDRESS}   {       count(); yylval.strval=yytext;
814                                                                         return ADVERTISED_ADDRESS; }
815 <INITIAL>{ADVERTISED_PORT}              {       count(); yylval.strval=yytext;
816                                                                         return ADVERTISED_PORT; }
817 <INITIAL>{DISABLE_CORE}         {       count(); yylval.strval=yytext;
818                                                                         return DISABLE_CORE; }
819 <INITIAL>{OPEN_FD_LIMIT}                {       count(); yylval.strval=yytext;
820                                                                         return OPEN_FD_LIMIT; }
821 <INITIAL>{SHM_FORCE_ALLOC}              {       count(); yylval.strval=yytext;
822                                                                         return SHM_FORCE_ALLOC; }
823 <INITIAL>{MLOCK_PAGES}          {       count(); yylval.strval=yytext;
824                                                                         return MLOCK_PAGES; }
825 <INITIAL>{REAL_TIME}            {       count(); yylval.strval=yytext;
826                                                                         return REAL_TIME; }
827 <INITIAL>{RT_PRIO}              {       count(); yylval.strval=yytext;
828                                                                         return RT_PRIO; }
829 <INITIAL>{RT_POLICY}            {       count(); yylval.strval=yytext;
830                                                                         return RT_POLICY; }
831 <INITIAL>{RT_TIMER1_PRIO}               {       count(); yylval.strval=yytext;
832                                                                         return RT_TIMER1_PRIO; }
833 <INITIAL>{RT_TIMER1_POLICY}             {       count(); yylval.strval=yytext;
834                                                                         return RT_TIMER1_POLICY; }
835 <INITIAL>{RT_TIMER2_PRIO}               {       count(); yylval.strval=yytext;
836                                                                         return RT_TIMER2_PRIO; }
837 <INITIAL>{RT_TIMER2_POLICY}             {       count(); yylval.strval=yytext;
838                                                                         return RT_TIMER2_POLICY; }
839 <INITIAL>{MCAST_LOOPBACK}               {       count(); yylval.strval=yytext;
840                                                                         return MCAST_LOOPBACK; }
841 <INITIAL>{MCAST_TTL}            {       count(); yylval.strval=yytext;
842                                                                         return MCAST_TTL; }
843 <INITIAL>{TOS}                  {       count(); yylval.strval=yytext;
844                                                                         return TOS; }
845 <INITIAL>{PMTU_DISCOVERY}               {       count(); yylval.strval=yytext;
846                                                                         return PMTU_DISCOVERY; }
847 <INITIAL>{KILL_TIMEOUT}                 {       count(); yylval.strval=yytext;
848                                                                         return KILL_TIMEOUT; }
849 <INITIAL>{MAX_WLOOPS}                   {       count(); yylval.strval=yytext;
850                                                                         return MAX_WLOOPS; }
851 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
852 <INITIAL>{CFG_DESCRIPTION}      { count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
853 <INITIAL>{LOADMODULE}   { count(); yylval.strval=yytext; return LOADMODULE; }
854 <INITIAL>{LOADPATH}             { count(); yylval.strval=yytext; return LOADPATH; }
855 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
856
857 <INITIAL>{STUN_REFRESH_INTERVAL} { count(); yylval.strval=yytext; return STUN_REFRESH_INTERVAL;}
858 <INITIAL>{STUN_ALLOW_STUN} { count(); yylval.strval=yytext; return STUN_ALLOW_STUN;}
859 <INITIAL>{STUN_ALLOW_FP} { count(); yylval.strval=yytext; return STUN_ALLOW_FP;}
860
861 <INITIAL>{EQUAL}        { count(); return EQUAL; }
862 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
863 <INITIAL>{EQUAL_T}      { count(); return EQUAL_T; }
864 <INITIAL>{GT}   { count(); return GT; }
865 <INITIAL>{LT}   { count(); return LT; }
866 <INITIAL>{GTE}  { count(); return GTE; }
867 <INITIAL>{LTE}  { count(); return LTE; }
868 <INITIAL>{DIFF} { count(); return DIFF; }
869 <INITIAL>{MATCH}        { count(); return MATCH; }
870 <INITIAL>{NOT}          { count(); return NOT; }
871 <INITIAL>{LOG_AND}      { count(); return LOG_AND; }
872 <INITIAL>{BIN_AND}      { count(); return BIN_AND; }
873 <INITIAL>{LOG_OR}       { count(); return LOG_OR;  }
874 <INITIAL>{BIN_OR}       { count(); return BIN_OR;  }
875 <INITIAL>{PLUS}         { count(); return PLUS; }
876 <INITIAL>{MINUS}        { count(); return MINUS; }
877 <INITIAL>{MODULO}       { count(); return MODULO; }
878 <INITIAL>{STRLEN}       { count(); return STRLEN; }
879 <INITIAL>{STREMPTY}     { count(); return STREMPTY; }
880 <INITIAL>{DEFINED}      { count(); return DEFINED; }
881 <INITIAL>{STREQ}        { count(); return STREQ; }
882 <INITIAL>{INTEQ}        { count(); return INTEQ; }
883 <INITIAL>{STRDIFF}      { count(); return STRDIFF; }
884 <INITIAL>{INTDIFF}      { count(); return INTDIFF; }
885 <INITIAL>{INTCAST}      { count(); return INTCAST; }
886 <INITIAL>{STRCAST}      { count(); return STRCAST; }
887
888 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
889 <SELECT>{ID}            { count(); addstr(&s_buf, yytext, yyleng);
890                           yylval.strval=s_buf.s;
891                           memset(&s_buf, 0, sizeof(s_buf));
892                           return ID;
893                         }
894 <SELECT>{DOT}           { count(); return DOT; }
895 <SELECT>{LBRACK}        { count(); return LBRACK; }
896 <SELECT>{RBRACK}        { count(); return RBRACK; }
897 <SELECT>{DECNUMBER}     { count(); yylval.intval=atoi(yytext);
898                                                 yy_number_str=yytext; return NUMBER; }
899 <SELECT>{HEXNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 16);
900                                                 yy_number_str=yytext; return NUMBER; }
901 <SELECT>{OCTNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 8);
902                                                 yy_number_str=yytext; return NUMBER; }
903 <SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2);
904                                                 yy_number_str=yytext; return NUMBER; }
905
906
907 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
908                                                         return ATTR_MARK; }
909 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
910 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
911 <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
912 <ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
913 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
914 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
915 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
916 <ATTR>{ATTR_TODOMAIN}   { count(); return ATTR_TODOMAIN; }
917 <ATTR>{ATTR_GLOBAL}     { count(); return ATTR_GLOBAL; }
918 <ATTR>{DOT}             { count(); return DOT; }
919 <ATTR>{LBRACK}          { count(); return LBRACK; }
920 <ATTR>{RBRACK}          { count(); return RBRACK; }
921 <ATTR>{STAR}                    { count(); return STAR; }
922 <ATTR>{DECNUMBER}               { count(); yylval.intval=atoi(yytext);
923                                                         yy_number_str=yytext; return NUMBER; }
924 <ATTR>{ID}                              { count(); addstr(&s_buf, yytext, yyleng);
925                                                         yylval.strval=s_buf.s;
926                                                         memset(&s_buf, 0, sizeof(s_buf));
927                                                         state = INITIAL_S;
928                                                         BEGIN(INITIAL);
929                                                         return ID;
930                                                 }
931
932 <INITIAL>{VAR_MARK}{LPAREN}     {
933                                                                 switch(sr_cfg_compat){
934                                                                         case SR_COMPAT_SER:
935                                                                                 state=ATTR_S; BEGIN(ATTR);
936                                                                                 yyless(1);
937                                                                                 count();
938                                                                                 return ATTR_MARK;
939                                                                                 break;
940                                                                         case SR_COMPAT_KAMAILIO:
941                                                                         case SR_COMPAT_MAX:
942                                                                         default:
943                                                                                 state = PVAR_P_S; BEGIN(PVAR_P);
944                                                                                 p_nest=1; yymore();
945                                                                                 break;
946                                                                 }
947                                                         }
948         /* eat everything between 2 () and return PVAR token and a string
949            containing everything (including $ and ()) */
950 <PVAR_P>{RPAREN}                        {       p_nest--;
951                                                                 if (p_nest==0){
952                                                                         count();
953                                                                         addstr(&s_buf, yytext, yyleng);
954                                                                         yylval.strval=s_buf.s;
955                                                                         memset(&s_buf, 0, sizeof(s_buf));
956                                                                         state=INITIAL_S;
957                                                                         BEGIN(INITIAL);
958                                                                         return PVAR;
959                                                                 }
960                                                                 yymore();
961                                                         }
962 <PVAR_P>{LPAREN}                        { p_nest++; yymore(); }
963 <PVAR_P>.                                       { yymore(); }
964
965 <PVARID>{ID}|'.'                        {yymore(); }
966 <PVARID>{LPAREN}                        {       state = PVAR_P_S; BEGIN(PVAR_P);
967                                                                 p_nest=1; yymore(); }
968 <PVARID>.                                       { yyless(0); state=INITIAL_S; BEGIN(INITIAL);
969                                                                 return PVAR;
970                                                         }
971
972
973 <INITIAL>{VAR_MARK}                     {
974                                                                 switch(sr_cfg_compat){
975                                                                         case SR_COMPAT_SER:
976                                                                                 count();
977                                                                                 state=ATTR_S; BEGIN(ATTR);
978                                                                                 return ATTR_MARK;
979                                                                                 break;
980                                                                         case SR_COMPAT_KAMAILIO:
981                                                                                 state=PVARID_S; BEGIN(PVARID);
982                                                                                 yymore();
983                                                                                 break;
984                                                                         case SR_COMPAT_MAX:
985                                                                         default: 
986                                                                                 state=AVP_PVAR_S; BEGIN(AVP_PVAR);
987                                                                                 yymore();
988                                                                                 break;
989                                                                 }
990                                                         }
991         /* avp prefix detected -> go to avp mode */
992 <AVP_PVAR>{AVP_PREF}            |
993 <AVP_PVAR>{ID}{LBRACK}          { state = ATTR_S; BEGIN(ATTR); yyless(1); count();
994                                                           return ATTR_MARK; }
995 <AVP_PVAR>{ID}{LPAREN}          { state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
996                                                                 yymore(); }
997 <AVP_PVAR>{ID}                          {       count(); addstr(&s_buf, yytext, yyleng);
998                                                                 yylval.strval=s_buf.s;
999                                                                 memset(&s_buf, 0, sizeof(s_buf));
1000                                                                 state = INITIAL_S;
1001                                                                 BEGIN(INITIAL);
1002                                                                 return AVP_OR_PVAR;
1003                                                         }
1004
1005 <INITIAL>{IPV6ADDR}             { count(); yylval.strval=yytext; return IPV6ADDR; }
1006 <INITIAL>{DECNUMBER}    { count(); yylval.intval=atoi(yytext);
1007                                                                 yy_number_str=yytext; return NUMBER; }
1008 <INITIAL>{HEXNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 16);
1009                                                         yy_number_str=yytext; return NUMBER; }
1010 <INITIAL>{OCTNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 8);
1011                                                         yy_number_str=yytext; return NUMBER; }
1012 <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2);
1013                                                         yy_number_str=yytext; return NUMBER; }
1014 <INITIAL>{YES}                  { count(); yylval.intval=1;
1015                                                         yy_number_str=yytext; return NUMBER; }
1016 <INITIAL>{NO}                   { count(); yylval.intval=0;
1017                                                         yy_number_str=yytext; return NUMBER; }
1018 <INITIAL>{TCP}                  { count(); return TCP; }
1019 <INITIAL>{UDP}                  { count(); return UDP; }
1020 <INITIAL>{TLS}                  { count(); return TLS; }
1021 <INITIAL>{SCTP}                 { count(); return SCTP; }
1022 <INITIAL>{INET}                 { count(); yylval.intval=AF_INET;
1023                                                         yy_number_str=yytext; return NUMBER; }
1024 <INITIAL>{INET6}                { count();
1025                                                 #ifdef USE_IPV6
1026                                                   yylval.intval=AF_INET6;
1027                                                 #else
1028                                                   yylval.intval=-1; /* no match*/
1029                                                 #endif
1030                                                 yy_number_str=yytext;
1031                                                 return NUMBER; }
1032 <INITIAL>{SSLv23}               { count(); yylval.strval=yytext; return SSLv23; }
1033 <INITIAL>{SSLv2}                { count(); yylval.strval=yytext; return SSLv2; }
1034 <INITIAL>{SSLv3}                { count(); yylval.strval=yytext; return SSLv3; }
1035 <INITIAL>{TLSv1}                { count(); yylval.strval=yytext; return TLSv1; }
1036
1037 <INITIAL>{COMMA}                { count(); return COMMA; }
1038 <INITIAL>{SEMICOLON}    { count(); return SEMICOLON; }
1039 <INITIAL>{COLON}        { count(); return COLON; }
1040 <INITIAL>{STAR}         { count(); return STAR; }
1041 <INITIAL>{RPAREN}       { count(); return RPAREN; }
1042 <INITIAL>{LPAREN}       { count(); return LPAREN; }
1043 <INITIAL>{LBRACE}       { count(); return LBRACE; }
1044 <INITIAL>{RBRACE}       { count(); return RBRACE; }
1045 <INITIAL>{LBRACK}       { count(); return LBRACK; }
1046 <INITIAL>{RBRACK}       { count(); return RBRACK; }
1047 <INITIAL>{SLASH}        { count(); return SLASH; }
1048 <INITIAL>{DOT}          { count(); return DOT; }
1049 <INITIAL>\\{CR}         {count(); } /* eat the escaped CR */
1050 <INITIAL>{CR}           { count();/* return CR;*/ }
1051 <INITIAL>{EVENT_RT_NAME}        { count();
1052                                                                 addstr(&s_buf, yytext, yyleng);
1053                                                                 yylval.strval=s_buf.s;
1054                                                                 memset(&s_buf, 0, sizeof(s_buf));
1055                                                                 return EVENT_RT_NAME; }
1056
1057
1058 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START; 
1059                                                         old_state = state; state=STRING_S;
1060                                                         BEGIN(STRING1); }
1061 <INITIAL>{TICK} { count(); old_initial = YY_START; old_state = state;
1062                                         state=STRING_S; BEGIN(STRING2); }
1063
1064
1065 <STRING1>{QUOTES} { count_more(); 
1066                                                 yytext[yyleng-1]=0; yyleng--;
1067                                                 addstr(&s_buf, yytext, yyleng);
1068                                                 state=STR_BETWEEN_S;
1069                                                 BEGIN(STR_BETWEEN);
1070                                         }
1071 <STRING2>{TICK}  { count_more(); state=old_state; BEGIN(old_initial);
1072                                                 yytext[yyleng-1]=0; yyleng--;
1073                                                 addstr(&s_buf, yytext, yyleng);
1074                                                 yylval.strval=s_buf.s;
1075                                                 memset(&s_buf, 0, sizeof(s_buf));
1076                                                 return STRING;
1077                                         }
1078 <STRING2>.|{EAT_ABLE}|{CR}      { yymore(); }
1079
1080 <STRING1>\\n            { count_more(); addchar(&s_buf, '\n'); }
1081 <STRING1>\\r            { count_more(); addchar(&s_buf, '\r'); }
1082 <STRING1>\\a            { count_more(); addchar(&s_buf, '\a'); }
1083 <STRING1>\\t            { count_more(); addchar(&s_buf, '\t'); }
1084 <STRING1>\\{QUOTES}     { count_more(); addchar(&s_buf, '"');  }
1085 <STRING1>\\\\           { count_more(); addchar(&s_buf, '\\'); }
1086 <STRING1>\\x{HEX}{1,2}  { count_more(); addchar(&s_buf,
1087                                                                                         (char)strtol(yytext+2, 0, 16)); }
1088  /* don't allow \[0-7]{1}, it will eat the backreferences from
1089     subst_uri if allowed (although everybody should use '' in subt_uri) */
1090 <STRING1>\\[0-7]{2,3}   { count_more(); addchar(&s_buf,
1091                                                                                         (char)strtol(yytext+1, 0, 8));  }
1092 <STRING1>\\{CR}         { count_more(); } /* eat escaped CRs */
1093 <STRING1>.|{EAT_ABLE}|{CR}      { count_more(); addchar(&s_buf, *yytext); }
1094
1095 <STR_BETWEEN>{EAT_ABLE}|{CR}    { count_ignore(); }
1096 <STR_BETWEEN>{QUOTES}                   { count_more(); state=STRING_S;
1097                                                                   BEGIN(STRING1);}
1098 <STR_BETWEEN>.                                  {       
1099                                                                         yyless(0); /* reparse it */
1100                                                                         /* ignore the whitespace now that is
1101                                                                           counted, return saved string value */
1102                                                                         state=old_state; BEGIN(old_initial);
1103                                                                         yylval.strval=s_buf.s;
1104                                                                         memset(&s_buf, 0, sizeof(s_buf));
1105                                                                         return STRING;
1106                                                                 }
1107
1108 <INITIAL,COMMENT>{COM_START}    { count(); comment_nest++; state=COMMENT_S;
1109                                                                                 BEGIN(COMMENT); }
1110 <COMMENT>{COM_END}                              { count(); comment_nest--;
1111                                                                                 if (comment_nest==0){
1112                                                                                         state=INITIAL_S;
1113                                                                                         BEGIN(INITIAL);
1114                                                                                 }
1115                                                                 }
1116 <COMMENT>.|{EAT_ABLE}|{CR}                              { count(); };
1117
1118 <INITIAL>{COM_LINE}!{SER_CFG}{CR}               { count();
1119                                                                                         sr_cfg_compat=SR_COMPAT_SER;}
1120 <INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}  { count(); 
1121                                                                                         sr_cfg_compat=SR_COMPAT_KAMAILIO;}
1122 <INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR} { count(); 
1123                                                                                                 sr_cfg_compat=SR_COMPAT_MAX;}
1124 <INITIAL>{COM_LINE}.*{CR}       { count(); }
1125
1126 <INITIAL>{ID}                   { count(); addstr(&s_buf, yytext, yyleng);
1127                                                                         yylval.strval=s_buf.s;
1128                                                                         memset(&s_buf, 0, sizeof(s_buf));
1129                                                                         return ID; }
1130 <INITIAL>{NUM_ID}                       { count(); addstr(&s_buf, yytext, yyleng);
1131                                                                         yylval.strval=s_buf.s;
1132                                                                         memset(&s_buf, 0, sizeof(s_buf));
1133                                                                         return NUM_ID; }
1134
1135 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
1136
1137 <INCLF>[ \t]*      /* eat the whitespace */
1138 <INCLF>[^ \t\n]+   { /* get the include file name */
1139                                 if(sr_push_yy_state(yytext)<0)
1140                                         exit(-1);
1141                                 BEGIN(INITIAL);
1142 }
1143
1144
1145 <<EOF>>                                                 {
1146                                                                         switch(state){
1147                                                                                 case STR_BETWEEN_S:
1148                                                                                         state=old_state;
1149                                                                                         BEGIN(old_initial);
1150                                                                                         yylval.strval=s_buf.s;
1151                                                                                         memset(&s_buf, 0, sizeof(s_buf));
1152                                                                                         return STRING;
1153                                                                                 case STRING_S:
1154                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
1155                                                                                                                 " unclosed string\n");
1156                                                                                         if (s_buf.s){
1157                                                                                                 pkg_free(s_buf.s);
1158                                                                                                 memset(&s_buf, 0,
1159                                                                                                                         sizeof(s_buf));
1160                                                                                         }
1161                                                                                         break;
1162                                                                                 case COMMENT_S:
1163                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
1164                                                                                                                 " %d comments open\n", comment_nest);
1165                                                                                         break;
1166                                                                                 case COMMENT_LN_S:
1167                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF:"
1168                                                                                                                 "comment line open\n");
1169                                                                                         break;
1170                                                                                 case  ATTR_S:
1171                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1172                                                                                                         " while parsing"
1173                                                                                                         " avp name\n");
1174                                                                                         break;
1175                                                                                 case PVARID_S:
1176                                                                                         p_nest=0;
1177                                                                                 case PVAR_P_S: 
1178                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1179                                                                                                         " while parsing pvar name"
1180                                                                                                         " (%d paranthesis open)\n",
1181                                                                                                         p_nest);
1182                                                                                         break;
1183                                                                                 case AVP_PVAR_S:
1184                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1185                                                                                                         " while parsing"
1186                                                                                                         " avp or pvar name\n");
1187                                                                         }
1188                                                                         if(sr_pop_yy_state()<0)
1189                                                                                 return 0;
1190                                                                 }
1191
1192 %%
1193
1194
1195 static char* addchar(struct str_buf* dst, char c)
1196 {
1197         return addstr(dst, &c, 1);
1198 }
1199
1200
1201
1202 static char* addstr(struct str_buf* dst_b, char* src, int len)
1203 {
1204         char *tmp;
1205         unsigned size;
1206         unsigned used;
1207
1208         if (dst_b->left<(len+1)){
1209                 used=(unsigned)(dst_b->crt-dst_b->s);
1210                 size=used+len+1;
1211                 /* round up to next multiple */
1212                 size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
1213                 tmp=pkg_malloc(size);
1214                 if (tmp==0) goto error;
1215                 if (dst_b->s){
1216                         memcpy(tmp, dst_b->s, used);
1217                         pkg_free(dst_b->s);
1218                 }
1219                 dst_b->s=tmp;
1220                 dst_b->crt=dst_b->s+used;
1221                 dst_b->left=size-used;
1222         }
1223         memcpy(dst_b->crt, src, len);
1224         dst_b->crt+=len;
1225         *(dst_b->crt)=0;
1226         dst_b->left-=len;
1227
1228         return dst_b->s;
1229 error:
1230         LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
1231         return 0;
1232 }
1233
1234
1235
1236 /** helper function for count_*(). */
1237 static void count_lc(int* l, int* c)
1238 {
1239         int i;
1240         for (i=0; i<yyleng;i++){
1241                 if (yytext[i]=='\n'){
1242                         (*l)++;
1243                         (*c)=1;
1244                 }else if (yytext[i]=='\t'){
1245                         (*c)++;
1246                         /*(*c)+=8 -((*c)%8);*/
1247                 }else{
1248                         (*c)++;
1249                 }
1250         }
1251 }
1252
1253
1254
1255 /* helper function */
1256 static void count_restore_ignored()
1257 {
1258         if (ign_lines) /* ignored line(s) => column has changed */
1259                 column=ign_columns;
1260         else
1261                 column+=ign_columns;
1262         line+=ign_lines;
1263         ign_lines=ign_columns=0;
1264 }
1265
1266
1267
1268 /** count/record position for stuff added to the current token. */
1269 static void count_more()
1270 {
1271         count_restore_ignored();
1272         count_lc(&line, &column);
1273 }
1274
1275
1276
1277 /** count/record position for a new token. */
1278 static void count()
1279 {
1280         count_restore_ignored();
1281         startline=line;
1282         startcolumn=column;
1283         count_more();
1284 }
1285
1286
1287
1288 /** record discarded stuff (not contained in the token) so that
1289     the next token position can be adjusted properly*/
1290 static void count_ignore()
1291 {
1292         count_lc(&ign_lines, &ign_columns);
1293 }
1294
1295
1296 /* replacement yywrap, removes libfl dependency */
1297 int yywrap()
1298 {
1299         return 1;
1300 }
1301
1302 static int sr_push_yy_state(char *fin)
1303 {
1304         struct sr_yy_fname *fn = NULL;
1305         char *x = NULL;
1306         char *newf = NULL;
1307 #define MAX_INCLUDE_FNAME       128
1308         char fbuf[MAX_INCLUDE_FNAME];
1309         int i, j, l;
1310
1311         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
1312         {
1313                 LOG(L_CRIT, "too many includes\n");
1314                 return -1;
1315         }
1316         l = strlen(fin);
1317         if(l>=MAX_INCLUDE_FNAME)
1318         {
1319                 LOG(L_CRIT, "included file name too long\n");
1320                 return -1;
1321         }
1322         if(fin[0]!='"' || fin[l-1]!='"')
1323         {
1324                 LOG(L_CRIT, "included file name must be between quotes\n");
1325                 return -1;
1326         }
1327         j = 0;
1328         for(i=1; i<l-1; i++)
1329         {
1330                 switch(fin[i]) {
1331                         case '\\':
1332                                 if(i+1==l-1)
1333                                 {
1334                                         LOG(L_CRIT, "invalid escape in included file name\n");
1335                                         return -1;
1336                                 }
1337                                 i++;
1338                                 switch(fin[i]) {
1339                                         case 't':
1340                                                 fbuf[j++] = '\t';
1341                                         break;
1342                                         case 'n':
1343                                                 fbuf[j++] = '\n';
1344                                         break;
1345                                         case 'r':
1346                                                 fbuf[j++] = '\r';
1347                                         break;
1348                                         default:
1349                                                 fbuf[j++] = fin[i];
1350                                 }
1351                         break;
1352                         default:
1353                                 fbuf[j++] = fin[i];
1354                 }
1355         }
1356         if(j==0)
1357         {
1358                 LOG(L_CRIT, "invalid included file name\n");
1359                 return -1;
1360         }
1361         fbuf[j] = '\0';
1362
1363         include_stack[include_stack_ptr].state = YY_CURRENT_BUFFER;
1364         include_stack[include_stack_ptr].line = line;
1365         include_stack[include_stack_ptr].column = column;
1366         include_stack[include_stack_ptr].startline = startline;
1367         include_stack[include_stack_ptr].startcolumn = startcolumn;
1368         include_stack[include_stack_ptr].finame = finame;
1369         include_stack_ptr++;
1370
1371         line=1;
1372         column=1;
1373         startline=1;
1374         startcolumn=1;
1375
1376         yyin = fopen(fbuf, "r" );
1377
1378         if ( ! yyin )
1379         {
1380                 finame = (finame==0)?cfg_file:finame;
1381                 if(finame==0 || fbuf[0]=='/')
1382                 {
1383                         LOG(L_CRIT, "cannot open included file: %s\n", fin);
1384                         return -1;
1385                 }
1386                 x = strrchr(finame, '/');
1387                 if(x)
1388                 {
1389                         newf = (char*)pkg_malloc(x-finame+strlen(fbuf)+2);
1390                         if(newf==0)
1391                         {
1392                                 LOG(L_CRIT, "no more pkg\n");
1393                                 return -1;
1394                         }
1395                         newf[0] = '\0';
1396                         strncat(newf, finame, x-finame);
1397                         strcat(newf, "/");
1398                         strcat(newf, fbuf);
1399                 }
1400                 yyin = fopen(newf, "r" );
1401                 if ( ! yyin )
1402                 {
1403                         LOG(L_CRIT, "cannot open included file: %s (%s)\n", fbuf, newf);
1404                         return -1;
1405                 }
1406                 LOG(L_DBG, "including file: %s (%s)\n", fbuf, newf);
1407         } else {
1408                 newf = fbuf;
1409         }
1410
1411         /* make a copy in PKG if does not exist */
1412         fn = sr_yy_fname_list;
1413         while(fn!=0)
1414         {
1415                 if(strcmp(fn->fname, newf)==0)
1416                 {
1417                         if(newf!=fbuf)
1418                                 pkg_free(newf);
1419                         newf = fbuf;
1420                         break;
1421                 }
1422                 fn = fn->next;
1423         }
1424         if(fn==0)
1425         {
1426                 fn = (struct sr_yy_fname*)pkg_malloc(sizeof(struct sr_yy_fname));
1427                 if(fn==0)
1428                 {
1429                         if(newf!=fbuf)
1430                                 pkg_free(newf);
1431                         LOG(L_CRIT, "no more pkg\n");
1432                         return -1;
1433                 }
1434                 if(newf==fbuf)
1435                 {
1436                         fn->fname = (char*)pkg_malloc(strlen(fbuf)+1);
1437                         if(fn->fname==0)
1438                         {
1439                                 pkg_free(fn);
1440                                 LOG(L_CRIT, "no more pkg!\n");
1441                                 return -1;
1442                         }
1443                         strcpy(fn->fname, fbuf);
1444                 } else {
1445                         fn->fname = newf;
1446                 }
1447                 fn->next = sr_yy_fname_list;
1448                 sr_yy_fname_list = fn;
1449         }
1450
1451         finame = fn->fname;
1452
1453         yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE ) );
1454
1455         return 0;
1456
1457 }
1458
1459 static int sr_pop_yy_state()
1460 {
1461         include_stack_ptr--;
1462         if (include_stack_ptr<0 )
1463                 return -1;
1464
1465         yy_delete_buffer( YY_CURRENT_BUFFER );
1466         yy_switch_to_buffer(include_stack[include_stack_ptr].state);
1467         line=include_stack[include_stack_ptr].line;
1468         column=include_stack[include_stack_ptr].column;
1469         startline=include_stack[include_stack_ptr].startline;
1470         startcolumn=include_stack[include_stack_ptr].startcolumn;
1471         finame = include_stack[include_stack_ptr].finame;
1472         return 0;
1473 }
1474