bedf79caee55ccf310ae5e91d534343c4450d1f6
[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 SIP_WARNING sip_warning
357 SERVER_SIGNATURE server_signature
358 SERVER_HEADER server_header
359 USER_AGENT_HEADER user_agent_header
360 REPLY_TO_VIA reply_to_via
361 USER            "user"|"uid"
362 GROUP           "group"|"gid"
363 CHROOT          "chroot"
364 WDIR            "workdir"|"wdir"
365 MHOMED          mhomed
366 DISABLE_TCP             "disable_tcp"
367 TCP_CHILDREN    "tcp_children"
368 TCP_ACCEPT_ALIASES      "tcp_accept_aliases"
369 TCP_SEND_TIMEOUT        "tcp_send_timeout"
370 TCP_CONNECT_TIMEOUT     "tcp_connect_timeout"
371 TCP_CON_LIFETIME        "tcp_connection_lifetime"
372 TCP_POLL_METHOD         "tcp_poll_method"
373 TCP_MAX_CONNECTIONS     "tcp_max_connections"
374 TCP_NO_CONNECT          "tcp_no_connect"
375 TCP_SOURCE_IPV4         "tcp_source_ipv4"
376 TCP_SOURCE_IPV6         "tcp_source_ipv6"
377 TCP_OPT_FD_CACHE        "tcp_fd_cache"
378 TCP_OPT_BUF_WRITE       "tcp_buf_write"|"tcp_async"
379 TCP_OPT_CONN_WQ_MAX     "tcp_conn_wq_max"
380 TCP_OPT_WQ_MAX          "tcp_wq_max"
381 TCP_OPT_RD_BUF          "tcp_rd_buf_size"
382 TCP_OPT_WQ_BLK          "tcp_wq_blk_size"
383 TCP_OPT_DEFER_ACCEPT "tcp_defer_accept"
384 TCP_OPT_DELAYED_ACK     "tcp_delayed_ack"
385 TCP_OPT_SYNCNT          "tcp_syncnt"
386 TCP_OPT_LINGER2         "tcp_linger2"
387 TCP_OPT_KEEPALIVE       "tcp_keepalive"
388 TCP_OPT_KEEPIDLE        "tcp_keepidle"
389 TCP_OPT_KEEPINTVL       "tcp_keepintvl"
390 TCP_OPT_KEEPCNT         "tcp_keepcnt"
391 TCP_OPT_CRLF_PING       "tcp_crlf_ping"
392 DISABLE_TLS             "disable_tls"|"tls_disable"
393 ENABLE_TLS              "enable_tls"|"tls_enable"
394 TLSLOG                  "tlslog"|"tls_log"
395 TLS_PORT_NO             "tls_port_no"
396 TLS_METHOD              "tls_method"
397 TLS_VERIFY              "tls_verify"
398 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
399 TLS_CERTIFICATE "tls_certificate"
400 TLS_PRIVATE_KEY "tls_private_key"
401 TLS_CA_LIST             "tls_ca_list"
402 TLS_HANDSHAKE_TIMEOUT   "tls_handshake_timeout"
403 TLS_SEND_TIMEOUT        "tls_send_timeout"
404 DISABLE_SCTP    "disable_sctp"
405 ENABLE_SCTP     "enable_sctp"
406 SCTP_CHILDREN   "sctp_children"
407 SCTP_SOCKET_RCVBUF      "sctp_socket_rcvbuf"|"sctp_socket_receive_buffer"
408 SCTP_SOCKET_SNDBUF      "sctp_socket_sndbuf"|"sctp_socket_send_buffer"
409 SCTP_AUTOCLOSE  "sctp_autoclose"
410 SCTP_SEND_TTL   "sctp_send_ttl"
411 SCTP_SEND_RETRIES       "sctp_send_retries"
412 SCTP_ASSOC_TRACKING     "sctp_assoc_tracking"
413 SCTP_ASSOC_REUSE        "sctp_assoc_reuse"
414 SCTP_MAX_ASSOCS         "sctp_max_assocs"
415 SCTP_SRTO_INITIAL       "sctp_srto_initial"
416 SCTP_SRTO_MAX           "sctp_srto_max"
417 SCTP_SRTO_MIN           "sctp_srto_min"
418 SCTP_ASOCMAXRXT         "sctp_asocmaxrxt"
419 SCTP_INIT_MAX_ATTEMPTS          "sctp_init_max_attempts"
420 SCTP_INIT_MAX_TIMEO                     "sctp_init_max_timeo"
421 SCTP_HBINTERVAL                         "sctp_hbinterval"
422 SCTP_PATHMAXRXT                         "sctp_pathmaxrxt"
423 SCTP_SACK_DELAY                         "sctp_sack_delay"
424 SCTP_SACK_FREQ                          "sctp_sack_freq"
425 SCTP_MAX_BURST                          "sctp_max_burst"
426
427 ADVERTISED_ADDRESS      "advertised_address"
428 ADVERTISED_PORT         "advertised_port"
429 DISABLE_CORE            "disable_core_dump"
430 OPEN_FD_LIMIT           "open_files_limit"
431 SHM_FORCE_ALLOC         "shm_force_alloc"
432 MLOCK_PAGES                     "mlock_pages"
433 REAL_TIME                       "real_time"
434 RT_PRIO                         "rt_prio"
435 RT_POLICY                       "rt_policy"
436 RT_TIMER1_PRIO          "rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
437 RT_TIMER1_POLICY        "rt_timer1_policy"|"rt_ftimer_policy"
438 RT_TIMER2_PRIO          "rt_timer2_prio"|"rt_stimer_prio"
439 RT_TIMER2_POLICY        "rt_timer2_policy"|"rt_stimer_policy"
440 MCAST_LOOPBACK          "mcast_loopback"
441 MCAST_TTL               "mcast_ttl"
442 TOS                     "tos"
443 PMTU_DISCOVERY  "pmtu_discovery"
444 KILL_TIMEOUT    "exit_timeout"|"ser_kill_timeout"
445 MAX_WLOOPS              "max_while_loops"
446
447 /* stun config variables */
448 STUN_REFRESH_INTERVAL "stun_refresh_interval"
449 STUN_ALLOW_STUN "stun_allow_stun"
450 STUN_ALLOW_FP "stun_allow_fp"
451
452 SERVER_ID     "server_id"
453
454 CFG_DESCRIPTION         "description"|"descr"|"desc"
455
456 LOADMODULE      loadmodule
457 LOADPATH        "loadpath"|"mpath"
458 MODPARAM        modparam
459
460 /* values */
461 YES                     "yes"|"true"|"on"|"enable"
462 NO                      "no"|"false"|"off"|"disable"
463 UDP                     "udp"|"UDP"
464 TCP                     "tcp"|"TCP"
465 TLS                     "tls"|"TLS"
466 SCTP            "sctp"|"SCTP"
467 INET            "inet"|"INET"
468 INET6           "inet6"|"INET6"
469 SSLv23                  "sslv23"|"SSLv23"|"SSLV23"
470 SSLv2                   "sslv2"|"SSLv2"|"SSLV2"
471 SSLv3                   "sslv3"|"SSLv3"|"SSLV3"
472 TLSv1                   "tlsv1"|"TLSv1"|"TLSV1"
473
474 LETTER          [a-zA-Z]
475 DIGIT           [0-9]
476 ALPHANUM        {LETTER}|{DIGIT}|[_]
477 ID                      {LETTER}{ALPHANUM}*
478 NUM_ID          {ALPHANUM}+
479 HEX                     [0-9a-fA-F]
480 HEXNUMBER       0x{HEX}+
481 OCTNUMBER       0[0-7]+
482 DECNUMBER       0|([1-9]{DIGIT}*)
483 BINNUMBER       [0-1]+b
484 HEX4            {HEX}{1,4}
485 IPV6ADDR        ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
486 QUOTES          \"
487 TICK            \'
488 SLASH           "/"
489 SEMICOLON       ;
490 RPAREN          \)
491 LPAREN          \(
492 LBRACE          \{
493 RBRACE          \}
494 LBRACK          \[
495 RBRACK          \]
496 COMMA           ","
497 COLON           ":"
498 STAR            \*
499 DOT                     \.
500 CR                      \n
501 EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*":"[a-zA-Z][0-9a-zA-Z-]*
502
503
504 COM_LINE        #
505 COM_START       "/\*"
506 COM_END         "\*/"
507
508 EAT_ABLE        [\ \t\b\r]
509
510 %%
511
512
513 <INITIAL>{EAT_ABLE}     { count(); }
514
515 <INITIAL>{FORWARD}      {count(); yylval.strval=yytext; return FORWARD; }
516 <INITIAL>{FORWARD_TCP}  {count(); yylval.strval=yytext; return FORWARD_TCP; }
517 <INITIAL>{FORWARD_TLS}  {count(); yylval.strval=yytext; return FORWARD_TLS; }
518 <INITIAL>{FORWARD_SCTP} {count(); yylval.strval=yytext; return FORWARD_SCTP;}
519 <INITIAL>{FORWARD_UDP}  {count(); yylval.strval=yytext; return FORWARD_UDP; }
520 <INITIAL>{DROP} { count(); yylval.strval=yytext; return DROP; }
521 <INITIAL>{EXIT} { count(); yylval.strval=yytext; return EXIT; }
522 <INITIAL>{RETURN}       { count(); yylval.strval=yytext; return RETURN; }
523 <INITIAL>{BREAK}        { count(); yylval.strval=yytext; return BREAK; }
524 <INITIAL>{SEND} { count(); yylval.strval=yytext; return SEND; }
525 <INITIAL>{SEND_TCP}     { count(); yylval.strval=yytext; return SEND_TCP; }
526 <INITIAL>{LOG}  { count(); yylval.strval=yytext; return LOG_TOK; }
527 <INITIAL>{ERROR}        { count(); yylval.strval=yytext; return ERROR; }
528 <INITIAL>{SETFLAG}      { count(); yylval.strval=yytext; return SETFLAG; }
529 <INITIAL>{RESETFLAG}    { count(); yylval.strval=yytext; return RESETFLAG; }
530 <INITIAL>{ISFLAGSET}    { count(); yylval.strval=yytext; return ISFLAGSET; }
531 <INITIAL>{FLAGS_DECL}   { count(); yylval.strval=yytext; return FLAGS_DECL; }
532 <INITIAL>{SETAVPFLAG}   { count(); yylval.strval=yytext; return SETAVPFLAG; }
533 <INITIAL>{RESETAVPFLAG} { count(); yylval.strval=yytext; return RESETAVPFLAG; }
534 <INITIAL>{ISAVPFLAGSET} { count(); yylval.strval=yytext; return ISAVPFLAGSET; }
535 <INITIAL>{AVPFLAGS_DECL}        { count(); yylval.strval=yytext; return AVPFLAGS_DECL; }
536 <INITIAL>{MSGLEN}       { count(); yylval.strval=yytext; return MSGLEN; }
537 <INITIAL>{RETCODE}      { count(); yylval.strval=yytext; return RETCODE; }
538 <INITIAL>{ROUTE}        { count(); yylval.strval=yytext; return ROUTE; }
539 <INITIAL>{ROUTE_ONREPLY}        { count(); yylval.strval=yytext;
540                                                                 return ROUTE_ONREPLY; }
541 <INITIAL>{ROUTE_FAILURE}        { count(); yylval.strval=yytext;
542                                                                 return ROUTE_FAILURE; }
543 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
544 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
545 <INITIAL>{ROUTE_EVENT} { count(); yylval.strval=yytext; return ROUTE_EVENT; }
546 <INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
547 <INITIAL>{SET_HOST}     { count(); yylval.strval=yytext; return SET_HOST; }
548 <INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
549 <INITIAL>{SET_HOSTPORTTRANS}    { count(); yylval.strval=yytext; return SET_HOSTPORTTRANS; }
550 <INITIAL>{SET_USER}     { count(); yylval.strval=yytext; return SET_USER; }
551 <INITIAL>{SET_USERPASS} { count(); yylval.strval=yytext; return SET_USERPASS; }
552 <INITIAL>{SET_PORT}     { count(); yylval.strval=yytext; return SET_PORT; }
553 <INITIAL>{SET_URI}      { count(); yylval.strval=yytext; return SET_URI; }
554 <INITIAL>{REVERT_URI}   { count(); yylval.strval=yytext; return REVERT_URI; }
555 <INITIAL>{PREFIX}       { count(); yylval.strval=yytext; return PREFIX; }
556 <INITIAL>{STRIP}        { count(); yylval.strval=yytext; return STRIP; }
557 <INITIAL>{STRIP_TAIL}   { count(); yylval.strval=yytext; return STRIP_TAIL; }
558 <INITIAL>{APPEND_BRANCH}        { count(); yylval.strval=yytext;
559                                                                 return APPEND_BRANCH; }
560 <INITIAL>{SET_USERPHONE}        { count(); yylval.strval=yytext;
561                                                                 return SET_USERPHONE; }
562 <INITIAL>{FORCE_RPORT}  { count(); yylval.strval=yytext; return FORCE_RPORT; }
563 <INITIAL>{ADD_LOCAL_RPORT}      { count(); yylval.strval=yytext;
564                                                                 return ADD_LOCAL_RPORT; }
565 <INITIAL>{FORCE_TCP_ALIAS}      { count(); yylval.strval=yytext;
566                                                                 return FORCE_TCP_ALIAS; }
567 <INITIAL>{UDP_MTU}      { count(); yylval.strval=yytext; return UDP_MTU; }
568 <INITIAL>{UDP_MTU_TRY_PROTO}    { count(); yylval.strval=yytext;
569                                                                         return UDP_MTU_TRY_PROTO; }
570 <INITIAL>{IF}   { count(); yylval.strval=yytext; return IF; }
571 <INITIAL>{ELSE} { count(); yylval.strval=yytext; return ELSE; }
572
573 <INITIAL>{SET_ADV_ADDRESS}      { count(); yylval.strval=yytext;
574                                                                                 return SET_ADV_ADDRESS; }
575 <INITIAL>{SET_ADV_PORT} { count(); yylval.strval=yytext;
576                                                                                 return SET_ADV_PORT; }
577 <INITIAL>{FORCE_SEND_SOCKET}    {       count(); yylval.strval=yytext;
578                                                                         return FORCE_SEND_SOCKET; }
579 <INITIAL>{SET_FWD_NO_CONNECT}   { count(); yylval.strval=yytext;
580                                                                         return SET_FWD_NO_CONNECT; }
581 <INITIAL>{SET_RPL_NO_CONNECT}   { count(); yylval.strval=yytext;
582                                                                         return SET_RPL_NO_CONNECT; }
583 <INITIAL>{SET_FWD_CLOSE}                { count(); yylval.strval=yytext;
584                                                                         return SET_FWD_CLOSE; }
585 <INITIAL>{SET_RPL_CLOSE}                { count(); yylval.strval=yytext;
586                                                                         return SET_RPL_CLOSE; }
587 <INITIAL>{SWITCH}       { count(); yylval.strval=yytext; return SWITCH; }
588 <INITIAL>{CASE} { count(); yylval.strval=yytext; return CASE; }
589 <INITIAL>{DEFAULT}      { count(); yylval.strval=yytext; return DEFAULT; }
590 <INITIAL>{WHILE}        { count(); yylval.strval=yytext; return WHILE; }
591
592 <INITIAL>{INCLUDEFILE}  { count(); BEGIN(INCLF); }
593
594 <INITIAL>{URIHOST}      { count(); yylval.strval=yytext; return URIHOST; }
595 <INITIAL>{URIPORT}      { count(); yylval.strval=yytext; return URIPORT; }
596
597 <INITIAL>{MAX_LEN}      { count(); yylval.strval=yytext; return MAX_LEN; }
598
599 <INITIAL>{METHOD}       { count(); yylval.strval=yytext; return METHOD; }
600 <INITIAL>{URI}  { count(); yylval.strval=yytext; return URI; }
601 <INITIAL>{FROM_URI}     { count(); yylval.strval=yytext; return FROM_URI; }
602 <INITIAL>{TO_URI}       { count(); yylval.strval=yytext; return TO_URI; }
603 <INITIAL>{SRCIP}        { count(); yylval.strval=yytext; return SRCIP; }
604 <INITIAL>{SRCPORT}      { count(); yylval.strval=yytext; return SRCPORT; }
605 <INITIAL>{DSTIP}        { count(); yylval.strval=yytext; return DSTIP; }
606 <INITIAL>{DSTPORT}      { count(); yylval.strval=yytext; return DSTPORT; }
607 <INITIAL>{SNDIP}        { count(); yylval.strval=yytext; return SNDIP; }
608 <INITIAL>{SNDPORT}      { count(); yylval.strval=yytext; return SNDPORT; }
609 <INITIAL>{SNDPROTO}     { count(); yylval.strval=yytext; return SNDPROTO; }
610 <INITIAL>{SNDAF}        { count(); yylval.strval=yytext; return SNDAF; }
611 <INITIAL>{TOIP}         { count(); yylval.strval=yytext; return TOIP; }
612 <INITIAL>{TOPORT}       { count(); yylval.strval=yytext; return TOPORT; }
613 <INITIAL>{PROTO}        { count(); yylval.strval=yytext; return PROTO; }
614 <INITIAL>{AF}   { count(); yylval.strval=yytext; return AF; }
615 <INITIAL>{MYSELF}       { count(); yylval.strval=yytext; return MYSELF; }
616
617 <INITIAL>{DEBUG}        { count(); yylval.strval=yytext; return DEBUG_V; }
618 <INITIAL>{FORK}         { count(); yylval.strval=yytext; return FORK; }
619 <INITIAL>{LOGSTDERROR}  { yylval.strval=yytext; return LOGSTDERROR; }
620 <INITIAL>{LOGFACILITY}  { yylval.strval=yytext; return LOGFACILITY; }
621 <INITIAL>{LOGNAME}      { yylval.strval=yytext; return LOGNAME; }
622 <INITIAL>{LISTEN}       { count(); yylval.strval=yytext; return LISTEN; }
623 <INITIAL>{ALIAS}        { count(); yylval.strval=yytext; return ALIAS; }
624 <INITIAL>{SR_AUTO_ALIASES}      { count(); yylval.strval=yytext;
625                                                                         return SR_AUTO_ALIASES; }
626 <INITIAL>{DNS}  { count(); yylval.strval=yytext; return DNS; }
627 <INITIAL>{REV_DNS}      { count(); yylval.strval=yytext; return REV_DNS; }
628 <INITIAL>{DNS_TRY_IPV6} { count(); yylval.strval=yytext;
629                                                                 return DNS_TRY_IPV6; }
630 <INITIAL>{DNS_TRY_NAPTR}        { count(); yylval.strval=yytext;
631                                                                 return DNS_TRY_NAPTR; }
632 <INITIAL>{DNS_SRV_LB}   { count(); yylval.strval=yytext;
633                                                                 return DNS_SRV_LB; }
634 <INITIAL>{DNS_UDP_PREF} { count(); yylval.strval=yytext;
635                                                                 return DNS_UDP_PREF; }
636 <INITIAL>{DNS_TCP_PREF} { count(); yylval.strval=yytext;
637                                                                 return DNS_TCP_PREF; }
638 <INITIAL>{DNS_TLS_PREF} { count(); yylval.strval=yytext;
639                                                                 return DNS_TLS_PREF; }
640 <INITIAL>{DNS_SCTP_PREF}        { count(); yylval.strval=yytext;
641                                                                 return DNS_SCTP_PREF; }
642 <INITIAL>{DNS_RETR_TIME}        { count(); yylval.strval=yytext;
643                                                                 return DNS_RETR_TIME; }
644 <INITIAL>{DNS_RETR_NO}  { count(); yylval.strval=yytext;
645                                                                 return DNS_RETR_NO; }
646 <INITIAL>{DNS_SERVERS_NO}       { count(); yylval.strval=yytext;
647                                                                 return DNS_SERVERS_NO; }
648 <INITIAL>{DNS_USE_SEARCH}       { count(); yylval.strval=yytext;
649                                                                 return DNS_USE_SEARCH; }
650 <INITIAL>{DNS_SEARCH_FMATCH}    { count(); yylval.strval=yytext;
651                                                                 return DNS_SEARCH_FMATCH; }
652 <INITIAL>{DNS_CACHE_INIT}       { count(); yylval.strval=yytext;
653                                                                 return DNS_CACHE_INIT; }
654 <INITIAL>{DNS_USE_CACHE}        { count(); yylval.strval=yytext;
655                                                                 return DNS_USE_CACHE; }
656 <INITIAL>{DNS_USE_FAILOVER}     { count(); yylval.strval=yytext;
657                                                                 return DNS_USE_FAILOVER; }
658 <INITIAL>{DNS_CACHE_FLAGS}      { count(); yylval.strval=yytext;
659                                                                 return DNS_CACHE_FLAGS; }
660 <INITIAL>{DNS_CACHE_NEG_TTL}    { count(); yylval.strval=yytext;
661                                                                 return DNS_CACHE_NEG_TTL; }
662 <INITIAL>{DNS_CACHE_MIN_TTL}    { count(); yylval.strval=yytext;
663                                                                 return DNS_CACHE_MIN_TTL; }
664 <INITIAL>{DNS_CACHE_MAX_TTL}    { count(); yylval.strval=yytext;
665                                                                 return DNS_CACHE_MAX_TTL; }
666 <INITIAL>{DNS_CACHE_MEM}        { count(); yylval.strval=yytext;
667                                                                 return DNS_CACHE_MEM; }
668 <INITIAL>{DNS_CACHE_GC_INT}     { count(); yylval.strval=yytext;
669                                                                 return DNS_CACHE_GC_INT; }
670 <INITIAL>{DNS_CACHE_DEL_NONEXP} { count(); yylval.strval=yytext;
671                                                                 return DNS_CACHE_DEL_NONEXP; }
672 <INITIAL>{DST_BLST_INIT}        { count(); yylval.strval=yytext;
673                                                                 return DST_BLST_INIT; }
674 <INITIAL>{USE_DST_BLST} { count(); yylval.strval=yytext;
675                                                                 return USE_DST_BLST; }
676 <INITIAL>{DST_BLST_MEM} { count(); yylval.strval=yytext;
677                                                                 return DST_BLST_MEM; }
678 <INITIAL>{DST_BLST_TTL} { count(); yylval.strval=yytext;
679                                                                 return DST_BLST_TTL; }
680 <INITIAL>{DST_BLST_GC_INT}      { count(); yylval.strval=yytext;
681                                                                 return DST_BLST_GC_INT; }
682 <INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
683 <INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
684 <INITIAL>{MAXBUFFER}    { count(); yylval.strval=yytext; return MAXBUFFER; }
685 <INITIAL>{CHILDREN}     { count(); yylval.strval=yytext; return CHILDREN; }
686 <INITIAL>{CHECK_VIA}    { count(); yylval.strval=yytext; return CHECK_VIA; }
687 <INITIAL>{PHONE2TEL}    { count(); yylval.strval=yytext; return PHONE2TEL; }
688 <INITIAL>{SYN_BRANCH}   { count(); yylval.strval=yytext; return SYN_BRANCH; }
689 <INITIAL>{MEMLOG}       { count(); yylval.strval=yytext; return MEMLOG; }
690 <INITIAL>{MEMDBG}       { count(); yylval.strval=yytext; return MEMDBG; }
691 <INITIAL>{SIP_WARNING}  { count(); yylval.strval=yytext; return SIP_WARNING; }
692 <INITIAL>{USER}         { count(); yylval.strval=yytext; return USER; }
693 <INITIAL>{GROUP}        { count(); yylval.strval=yytext; return GROUP; }
694 <INITIAL>{CHROOT}       { count(); yylval.strval=yytext; return CHROOT; }
695 <INITIAL>{WDIR} { count(); yylval.strval=yytext; return WDIR; }
696 <INITIAL>{MHOMED}       { count(); yylval.strval=yytext; return MHOMED; }
697 <INITIAL>{DISABLE_TCP}  { count(); yylval.strval=yytext; return DISABLE_TCP; }
698 <INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
699 <INITIAL>{TCP_ACCEPT_ALIASES}   { count(); yylval.strval=yytext;
700                                                                         return TCP_ACCEPT_ALIASES; }
701 <INITIAL>{TCP_SEND_TIMEOUT}             { count(); yylval.strval=yytext;
702                                                                         return TCP_SEND_TIMEOUT; }
703 <INITIAL>{TCP_CONNECT_TIMEOUT}          { count(); yylval.strval=yytext;
704                                                                         return TCP_CONNECT_TIMEOUT; }
705 <INITIAL>{TCP_CON_LIFETIME}             { count(); yylval.strval=yytext;
706                                                                         return TCP_CON_LIFETIME; }
707 <INITIAL>{TCP_POLL_METHOD}              { count(); yylval.strval=yytext;
708                                                                         return TCP_POLL_METHOD; }
709 <INITIAL>{TCP_MAX_CONNECTIONS}  { count(); yylval.strval=yytext;
710                                                                         return TCP_MAX_CONNECTIONS; }
711 <INITIAL>{TCP_NO_CONNECT}               { count(); yylval.strval=yytext;
712                                                                         return TCP_NO_CONNECT; }
713 <INITIAL>{TCP_SOURCE_IPV4}              { count(); yylval.strval=yytext;
714                                                                         return TCP_SOURCE_IPV4; }
715 <INITIAL>{TCP_SOURCE_IPV6}              { count(); yylval.strval=yytext;
716                                                                         return TCP_SOURCE_IPV6; }
717 <INITIAL>{TCP_OPT_FD_CACHE}             { count(); yylval.strval=yytext;
718                                                                         return TCP_OPT_FD_CACHE; }
719 <INITIAL>{TCP_OPT_CONN_WQ_MAX}  { count(); yylval.strval=yytext;
720                                                                         return TCP_OPT_CONN_WQ_MAX; }
721 <INITIAL>{TCP_OPT_WQ_MAX}       { count(); yylval.strval=yytext;
722                                                                         return TCP_OPT_WQ_MAX; }
723 <INITIAL>{TCP_OPT_RD_BUF}       { count(); yylval.strval=yytext;
724                                                                         return TCP_OPT_RD_BUF; }
725 <INITIAL>{TCP_OPT_WQ_BLK}       { count(); yylval.strval=yytext;
726                                                                         return TCP_OPT_WQ_BLK; }
727 <INITIAL>{TCP_OPT_BUF_WRITE}    { count(); yylval.strval=yytext;
728                                                                         return TCP_OPT_BUF_WRITE; }
729 <INITIAL>{TCP_OPT_DEFER_ACCEPT} { count(); yylval.strval=yytext;
730                                                                         return TCP_OPT_DEFER_ACCEPT; }
731 <INITIAL>{TCP_OPT_DELAYED_ACK}  { count(); yylval.strval=yytext;
732                                                                         return TCP_OPT_DELAYED_ACK; }
733 <INITIAL>{TCP_OPT_SYNCNT}               { count(); yylval.strval=yytext;
734                                                                         return TCP_OPT_SYNCNT; }
735 <INITIAL>{TCP_OPT_LINGER2}              { count(); yylval.strval=yytext;
736                                                                         return TCP_OPT_LINGER2; }
737 <INITIAL>{TCP_OPT_KEEPALIVE}    { count(); yylval.strval=yytext;
738                                                                         return TCP_OPT_KEEPALIVE; }
739 <INITIAL>{TCP_OPT_KEEPIDLE}             { count(); yylval.strval=yytext;
740                                                                         return TCP_OPT_KEEPIDLE; }
741 <INITIAL>{TCP_OPT_KEEPINTVL}    { count(); yylval.strval=yytext;
742                                                                         return TCP_OPT_KEEPINTVL; }
743 <INITIAL>{TCP_OPT_KEEPCNT}      { count(); yylval.strval=yytext;
744                                                                         return TCP_OPT_KEEPCNT; }
745 <INITIAL>{TCP_OPT_CRLF_PING}    { count(); yylval.strval=yytext;
746                                                                         return TCP_OPT_CRLF_PING; }
747 <INITIAL>{DISABLE_TLS}  { count(); yylval.strval=yytext; return DISABLE_TLS; }
748 <INITIAL>{ENABLE_TLS}   { count(); yylval.strval=yytext; return ENABLE_TLS; }
749 <INITIAL>{TLSLOG}               { count(); yylval.strval=yytext; return TLS_PORT_NO; }
750 <INITIAL>{TLS_PORT_NO}  { count(); yylval.strval=yytext; return TLS_PORT_NO; }
751 <INITIAL>{TLS_METHOD}   { count(); yylval.strval=yytext; return TLS_METHOD; }
752 <INITIAL>{TLS_VERIFY}   { count(); yylval.strval=yytext; return TLS_VERIFY; }
753 <INITIAL>{TLS_REQUIRE_CERTIFICATE}      { count(); yylval.strval=yytext;
754                                                                                 return TLS_REQUIRE_CERTIFICATE; }
755 <INITIAL>{TLS_CERTIFICATE}      { count(); yylval.strval=yytext;
756                                                                                 return TLS_CERTIFICATE; }
757 <INITIAL>{TLS_PRIVATE_KEY}      { count(); yylval.strval=yytext;
758                                                                                 return TLS_PRIVATE_KEY; }
759 <INITIAL>{TLS_CA_LIST}  { count(); yylval.strval=yytext;
760                                                                                 return TLS_CA_LIST; }
761 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}        { count(); yylval.strval=yytext;
762                                                                                 return TLS_HANDSHAKE_TIMEOUT; }
763 <INITIAL>{TLS_SEND_TIMEOUT}     { count(); yylval.strval=yytext;
764                                                                                 return TLS_SEND_TIMEOUT; }
765 <INITIAL>{DISABLE_SCTP} { count(); yylval.strval=yytext; return DISABLE_SCTP;}
766 <INITIAL>{ENABLE_SCTP}  { count(); yylval.strval=yytext; return ENABLE_SCTP;}
767 <INITIAL>{SCTP_CHILDREN}        { count(); yylval.strval=yytext;
768                                                                                 return SCTP_CHILDREN; }
769 <INITIAL>{SCTP_SOCKET_RCVBUF}   { count(); yylval.strval=yytext;
770                                                                                 return SCTP_SOCKET_RCVBUF; }
771 <INITIAL>{SCTP_SOCKET_SNDBUF}   { count(); yylval.strval=yytext;
772                                                                                 return SCTP_SOCKET_SNDBUF; }
773 <INITIAL>{SCTP_AUTOCLOSE}       { count(); yylval.strval=yytext;
774                                                                                 return SCTP_AUTOCLOSE; }
775 <INITIAL>{SCTP_SEND_TTL}        { count(); yylval.strval=yytext;
776                                                                                 return SCTP_SEND_TTL; }
777 <INITIAL>{SCTP_SEND_RETRIES}    { count(); yylval.strval=yytext;
778                                                                                 return SCTP_SEND_RETRIES; }
779 <INITIAL>{SCTP_ASSOC_TRACKING}  { count(); yylval.strval=yytext;
780                                                                                 return SCTP_ASSOC_TRACKING; }
781 <INITIAL>{SCTP_ASSOC_REUSE}             { count(); yylval.strval=yytext;
782                                                                                 return SCTP_ASSOC_REUSE; }
783 <INITIAL>{SCTP_MAX_ASSOCS}              { count(); yylval.strval=yytext;
784                                                                                 return SCTP_MAX_ASSOCS; }
785 <INITIAL>{SCTP_SRTO_INITIAL}    { count(); yylval.strval=yytext;
786                                                                                 return SCTP_SRTO_INITIAL; }
787 <INITIAL>{SCTP_SRTO_MAX}        { count(); yylval.strval=yytext;
788                                                                                 return SCTP_SRTO_MAX; }
789 <INITIAL>{SCTP_SRTO_MIN}        { count(); yylval.strval=yytext;
790                                                                                 return SCTP_SRTO_MIN; }
791 <INITIAL>{SCTP_ASOCMAXRXT}      { count(); yylval.strval=yytext;
792                                                                                 return SCTP_ASOCMAXRXT; }
793 <INITIAL>{SCTP_INIT_MAX_ATTEMPTS}       { count(); yylval.strval=yytext;
794                                                                                 return SCTP_INIT_MAX_ATTEMPTS; }
795 <INITIAL>{SCTP_INIT_MAX_TIMEO}  { count(); yylval.strval=yytext;
796                                                                                 return SCTP_INIT_MAX_TIMEO; }
797 <INITIAL>{SCTP_HBINTERVAL}      { count(); yylval.strval=yytext;
798                                                                                 return SCTP_HBINTERVAL; }
799 <INITIAL>{SCTP_PATHMAXRXT}      { count(); yylval.strval=yytext;
800                                                                                 return SCTP_PATHMAXRXT; }
801 <INITIAL>{SCTP_SACK_DELAY}      { count(); yylval.strval=yytext;
802                                                                                 return SCTP_SACK_DELAY; }
803 <INITIAL>{SCTP_SACK_FREQ}       { count(); yylval.strval=yytext;
804                                                                                 return SCTP_SACK_FREQ; }
805 <INITIAL>{SCTP_MAX_BURST}       { count(); yylval.strval=yytext;
806                                                                                 return SCTP_MAX_BURST; }
807 <INITIAL>{SERVER_SIGNATURE}     { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
808 <INITIAL>{SERVER_HEADER}        { count(); yylval.strval=yytext; return SERVER_HEADER; }
809 <INITIAL>{USER_AGENT_HEADER}    { count(); yylval.strval=yytext; return USER_AGENT_HEADER; }
810 <INITIAL>{REPLY_TO_VIA} { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
811 <INITIAL>{ADVERTISED_ADDRESS}   {       count(); yylval.strval=yytext;
812                                                                         return ADVERTISED_ADDRESS; }
813 <INITIAL>{ADVERTISED_PORT}              {       count(); yylval.strval=yytext;
814                                                                         return ADVERTISED_PORT; }
815 <INITIAL>{DISABLE_CORE}         {       count(); yylval.strval=yytext;
816                                                                         return DISABLE_CORE; }
817 <INITIAL>{OPEN_FD_LIMIT}                {       count(); yylval.strval=yytext;
818                                                                         return OPEN_FD_LIMIT; }
819 <INITIAL>{SHM_FORCE_ALLOC}              {       count(); yylval.strval=yytext;
820                                                                         return SHM_FORCE_ALLOC; }
821 <INITIAL>{MLOCK_PAGES}          {       count(); yylval.strval=yytext;
822                                                                         return MLOCK_PAGES; }
823 <INITIAL>{REAL_TIME}            {       count(); yylval.strval=yytext;
824                                                                         return REAL_TIME; }
825 <INITIAL>{RT_PRIO}              {       count(); yylval.strval=yytext;
826                                                                         return RT_PRIO; }
827 <INITIAL>{RT_POLICY}            {       count(); yylval.strval=yytext;
828                                                                         return RT_POLICY; }
829 <INITIAL>{RT_TIMER1_PRIO}               {       count(); yylval.strval=yytext;
830                                                                         return RT_TIMER1_PRIO; }
831 <INITIAL>{RT_TIMER1_POLICY}             {       count(); yylval.strval=yytext;
832                                                                         return RT_TIMER1_POLICY; }
833 <INITIAL>{RT_TIMER2_PRIO}               {       count(); yylval.strval=yytext;
834                                                                         return RT_TIMER2_PRIO; }
835 <INITIAL>{RT_TIMER2_POLICY}             {       count(); yylval.strval=yytext;
836                                                                         return RT_TIMER2_POLICY; }
837 <INITIAL>{MCAST_LOOPBACK}               {       count(); yylval.strval=yytext;
838                                                                         return MCAST_LOOPBACK; }
839 <INITIAL>{MCAST_TTL}            {       count(); yylval.strval=yytext;
840                                                                         return MCAST_TTL; }
841 <INITIAL>{TOS}                  {       count(); yylval.strval=yytext;
842                                                                         return TOS; }
843 <INITIAL>{PMTU_DISCOVERY}               {       count(); yylval.strval=yytext;
844                                                                         return PMTU_DISCOVERY; }
845 <INITIAL>{KILL_TIMEOUT}                 {       count(); yylval.strval=yytext;
846                                                                         return KILL_TIMEOUT; }
847 <INITIAL>{MAX_WLOOPS}                   {       count(); yylval.strval=yytext;
848                                                                         return MAX_WLOOPS; }
849 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
850 <INITIAL>{CFG_DESCRIPTION}      { count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
851 <INITIAL>{LOADMODULE}   { count(); yylval.strval=yytext; return LOADMODULE; }
852 <INITIAL>{LOADPATH}             { count(); yylval.strval=yytext; return LOADPATH; }
853 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
854
855 <INITIAL>{STUN_REFRESH_INTERVAL} { count(); yylval.strval=yytext; return STUN_REFRESH_INTERVAL;}
856 <INITIAL>{STUN_ALLOW_STUN} { count(); yylval.strval=yytext; return STUN_ALLOW_STUN;}
857 <INITIAL>{STUN_ALLOW_FP} { count(); yylval.strval=yytext; return STUN_ALLOW_FP;}
858
859 <INITIAL>{EQUAL}        { count(); return EQUAL; }
860 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
861 <INITIAL>{EQUAL_T}      { count(); return EQUAL_T; }
862 <INITIAL>{GT}   { count(); return GT; }
863 <INITIAL>{LT}   { count(); return LT; }
864 <INITIAL>{GTE}  { count(); return GTE; }
865 <INITIAL>{LTE}  { count(); return LTE; }
866 <INITIAL>{DIFF} { count(); return DIFF; }
867 <INITIAL>{MATCH}        { count(); return MATCH; }
868 <INITIAL>{NOT}          { count(); return NOT; }
869 <INITIAL>{LOG_AND}      { count(); return LOG_AND; }
870 <INITIAL>{BIN_AND}      { count(); return BIN_AND; }
871 <INITIAL>{LOG_OR}       { count(); return LOG_OR;  }
872 <INITIAL>{BIN_OR}       { count(); return BIN_OR;  }
873 <INITIAL>{PLUS}         { count(); return PLUS; }
874 <INITIAL>{MINUS}        { count(); return MINUS; }
875 <INITIAL>{MODULO}       { count(); return MODULO; }
876 <INITIAL>{STRLEN}       { count(); return STRLEN; }
877 <INITIAL>{STREMPTY}     { count(); return STREMPTY; }
878 <INITIAL>{DEFINED}      { count(); return DEFINED; }
879 <INITIAL>{STREQ}        { count(); return STREQ; }
880 <INITIAL>{INTEQ}        { count(); return INTEQ; }
881 <INITIAL>{STRDIFF}      { count(); return STRDIFF; }
882 <INITIAL>{INTDIFF}      { count(); return INTDIFF; }
883 <INITIAL>{INTCAST}      { count(); return INTCAST; }
884 <INITIAL>{STRCAST}      { count(); return STRCAST; }
885
886 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
887 <SELECT>{ID}            { count(); addstr(&s_buf, yytext, yyleng);
888                           yylval.strval=s_buf.s;
889                           memset(&s_buf, 0, sizeof(s_buf));
890                           return ID;
891                         }
892 <SELECT>{DOT}           { count(); return DOT; }
893 <SELECT>{LBRACK}        { count(); return LBRACK; }
894 <SELECT>{RBRACK}        { count(); return RBRACK; }
895 <SELECT>{DECNUMBER}     { count(); yylval.intval=atoi(yytext);
896                                                 yy_number_str=yytext; return NUMBER; }
897 <SELECT>{HEXNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 16);
898                                                 yy_number_str=yytext; return NUMBER; }
899 <SELECT>{OCTNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 8);
900                                                 yy_number_str=yytext; return NUMBER; }
901 <SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2);
902                                                 yy_number_str=yytext; return NUMBER; }
903
904
905 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
906                                                         return ATTR_MARK; }
907 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
908 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
909 <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
910 <ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
911 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
912 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
913 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
914 <ATTR>{ATTR_TODOMAIN}   { count(); return ATTR_TODOMAIN; }
915 <ATTR>{ATTR_GLOBAL}     { count(); return ATTR_GLOBAL; }
916 <ATTR>{DOT}             { count(); return DOT; }
917 <ATTR>{LBRACK}          { count(); return LBRACK; }
918 <ATTR>{RBRACK}          { count(); return RBRACK; }
919 <ATTR>{STAR}                    { count(); return STAR; }
920 <ATTR>{DECNUMBER}               { count(); yylval.intval=atoi(yytext);
921                                                         yy_number_str=yytext; return NUMBER; }
922 <ATTR>{ID}                              { count(); addstr(&s_buf, yytext, yyleng);
923                                                         yylval.strval=s_buf.s;
924                                                         memset(&s_buf, 0, sizeof(s_buf));
925                                                         state = INITIAL_S;
926                                                         BEGIN(INITIAL);
927                                                         return ID;
928                                                 }
929
930 <INITIAL>{VAR_MARK}{LPAREN}     {
931                                                                 switch(sr_cfg_compat){
932                                                                         case SR_COMPAT_SER:
933                                                                                 state=ATTR_S; BEGIN(ATTR);
934                                                                                 yyless(1);
935                                                                                 count();
936                                                                                 return ATTR_MARK;
937                                                                                 break;
938                                                                         case SR_COMPAT_KAMAILIO:
939                                                                         case SR_COMPAT_MAX:
940                                                                         default:
941                                                                                 state = PVAR_P_S; BEGIN(PVAR_P);
942                                                                                 p_nest=1; yymore();
943                                                                                 break;
944                                                                 }
945                                                         }
946         /* eat everything between 2 () and return PVAR token and a string
947            containing everything (including $ and ()) */
948 <PVAR_P>{RPAREN}                        {       p_nest--;
949                                                                 if (p_nest==0){
950                                                                         count();
951                                                                         addstr(&s_buf, yytext, yyleng);
952                                                                         yylval.strval=s_buf.s;
953                                                                         memset(&s_buf, 0, sizeof(s_buf));
954                                                                         state=INITIAL_S;
955                                                                         BEGIN(INITIAL);
956                                                                         return PVAR;
957                                                                 }
958                                                                 yymore();
959                                                         }
960 <PVAR_P>{LPAREN}                        { p_nest++; yymore(); }
961 <PVAR_P>.                                       { yymore(); }
962
963 <PVARID>{ID}|'.'                        {yymore(); }
964 <PVARID>{LPAREN}                        {       state = PVAR_P_S; BEGIN(PVAR_P);
965                                                                 p_nest=1; yymore(); }
966 <PVARID>.                                       { yyless(0); state=INITIAL_S; BEGIN(INITIAL);
967                                                                 return PVAR;
968                                                         }
969
970
971 <INITIAL>{VAR_MARK}                     {
972                                                                 switch(sr_cfg_compat){
973                                                                         case SR_COMPAT_SER:
974                                                                                 count();
975                                                                                 state=ATTR_S; BEGIN(ATTR);
976                                                                                 return ATTR_MARK;
977                                                                                 break;
978                                                                         case SR_COMPAT_KAMAILIO:
979                                                                                 state=PVARID_S; BEGIN(PVARID);
980                                                                                 yymore();
981                                                                                 break;
982                                                                         case SR_COMPAT_MAX:
983                                                                         default: 
984                                                                                 state=AVP_PVAR_S; BEGIN(AVP_PVAR);
985                                                                                 yymore();
986                                                                                 break;
987                                                                 }
988                                                         }
989         /* avp prefix detected -> go to avp mode */
990 <AVP_PVAR>{AVP_PREF}            |
991 <AVP_PVAR>{ID}{LBRACK}          { state = ATTR_S; BEGIN(ATTR); yyless(1); count();
992                                                           return ATTR_MARK; }
993 <AVP_PVAR>{ID}{LPAREN}          { state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
994                                                                 yymore(); }
995 <AVP_PVAR>{ID}                          {       count(); addstr(&s_buf, yytext, yyleng);
996                                                                 yylval.strval=s_buf.s;
997                                                                 memset(&s_buf, 0, sizeof(s_buf));
998                                                                 state = INITIAL_S;
999                                                                 BEGIN(INITIAL);
1000                                                                 return AVP_OR_PVAR;
1001                                                         }
1002
1003 <INITIAL>{IPV6ADDR}             { count(); yylval.strval=yytext; return IPV6ADDR; }
1004 <INITIAL>{DECNUMBER}    { count(); yylval.intval=atoi(yytext);
1005                                                                 yy_number_str=yytext; return NUMBER; }
1006 <INITIAL>{HEXNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 16);
1007                                                         yy_number_str=yytext; return NUMBER; }
1008 <INITIAL>{OCTNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 8);
1009                                                         yy_number_str=yytext; return NUMBER; }
1010 <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2);
1011                                                         yy_number_str=yytext; return NUMBER; }
1012 <INITIAL>{YES}                  { count(); yylval.intval=1;
1013                                                         yy_number_str=yytext; return NUMBER; }
1014 <INITIAL>{NO}                   { count(); yylval.intval=0;
1015                                                         yy_number_str=yytext; return NUMBER; }
1016 <INITIAL>{TCP}                  { count(); return TCP; }
1017 <INITIAL>{UDP}                  { count(); return UDP; }
1018 <INITIAL>{TLS}                  { count(); return TLS; }
1019 <INITIAL>{SCTP}                 { count(); return SCTP; }
1020 <INITIAL>{INET}                 { count(); yylval.intval=AF_INET;
1021                                                         yy_number_str=yytext; return NUMBER; }
1022 <INITIAL>{INET6}                { count();
1023                                                 #ifdef USE_IPV6
1024                                                   yylval.intval=AF_INET6;
1025                                                 #else
1026                                                   yylval.intval=-1; /* no match*/
1027                                                 #endif
1028                                                 yy_number_str=yytext;
1029                                                 return NUMBER; }
1030 <INITIAL>{SSLv23}               { count(); yylval.strval=yytext; return SSLv23; }
1031 <INITIAL>{SSLv2}                { count(); yylval.strval=yytext; return SSLv2; }
1032 <INITIAL>{SSLv3}                { count(); yylval.strval=yytext; return SSLv3; }
1033 <INITIAL>{TLSv1}                { count(); yylval.strval=yytext; return TLSv1; }
1034
1035 <INITIAL>{COMMA}                { count(); return COMMA; }
1036 <INITIAL>{SEMICOLON}    { count(); return SEMICOLON; }
1037 <INITIAL>{COLON}        { count(); return COLON; }
1038 <INITIAL>{STAR}         { count(); return STAR; }
1039 <INITIAL>{RPAREN}       { count(); return RPAREN; }
1040 <INITIAL>{LPAREN}       { count(); return LPAREN; }
1041 <INITIAL>{LBRACE}       { count(); return LBRACE; }
1042 <INITIAL>{RBRACE}       { count(); return RBRACE; }
1043 <INITIAL>{LBRACK}       { count(); return LBRACK; }
1044 <INITIAL>{RBRACK}       { count(); return RBRACK; }
1045 <INITIAL>{SLASH}        { count(); return SLASH; }
1046 <INITIAL>{DOT}          { count(); return DOT; }
1047 <INITIAL>\\{CR}         {count(); } /* eat the escaped CR */
1048 <INITIAL>{CR}           { count();/* return CR;*/ }
1049 <INITIAL>{EVENT_RT_NAME}        { count();
1050                                                                 addstr(&s_buf, yytext, yyleng);
1051                                                                 yylval.strval=s_buf.s;
1052                                                                 memset(&s_buf, 0, sizeof(s_buf));
1053                                                                 return EVENT_RT_NAME; }
1054
1055
1056 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START; 
1057                                                         old_state = state; state=STRING_S;
1058                                                         BEGIN(STRING1); }
1059 <INITIAL>{TICK} { count(); old_initial = YY_START; old_state = state;
1060                                         state=STRING_S; BEGIN(STRING2); }
1061
1062
1063 <STRING1>{QUOTES} { count_more(); 
1064                                                 yytext[yyleng-1]=0; yyleng--;
1065                                                 addstr(&s_buf, yytext, yyleng);
1066                                                 state=STR_BETWEEN_S;
1067                                                 BEGIN(STR_BETWEEN);
1068                                         }
1069 <STRING2>{TICK}  { count_more(); state=old_state; BEGIN(old_initial);
1070                                                 yytext[yyleng-1]=0; yyleng--;
1071                                                 addstr(&s_buf, yytext, yyleng);
1072                                                 yylval.strval=s_buf.s;
1073                                                 memset(&s_buf, 0, sizeof(s_buf));
1074                                                 return STRING;
1075                                         }
1076 <STRING2>.|{EAT_ABLE}|{CR}      { yymore(); }
1077
1078 <STRING1>\\n            { count_more(); addchar(&s_buf, '\n'); }
1079 <STRING1>\\r            { count_more(); addchar(&s_buf, '\r'); }
1080 <STRING1>\\a            { count_more(); addchar(&s_buf, '\a'); }
1081 <STRING1>\\t            { count_more(); addchar(&s_buf, '\t'); }
1082 <STRING1>\\{QUOTES}     { count_more(); addchar(&s_buf, '"');  }
1083 <STRING1>\\\\           { count_more(); addchar(&s_buf, '\\'); }
1084 <STRING1>\\x{HEX}{1,2}  { count_more(); addchar(&s_buf,
1085                                                                                         (char)strtol(yytext+2, 0, 16)); }
1086  /* don't allow \[0-7]{1}, it will eat the backreferences from
1087     subst_uri if allowed (although everybody should use '' in subt_uri) */
1088 <STRING1>\\[0-7]{2,3}   { count_more(); addchar(&s_buf,
1089                                                                                         (char)strtol(yytext+1, 0, 8));  }
1090 <STRING1>\\{CR}         { count_more(); } /* eat escaped CRs */
1091 <STRING1>.|{EAT_ABLE}|{CR}      { count_more(); addchar(&s_buf, *yytext); }
1092
1093 <STR_BETWEEN>{EAT_ABLE}|{CR}    { count_ignore(); }
1094 <STR_BETWEEN>{QUOTES}                   { count_more(); state=STRING_S;
1095                                                                   BEGIN(STRING1);}
1096 <STR_BETWEEN>.                                  {       
1097                                                                         yyless(0); /* reparse it */
1098                                                                         /* ignore the whitespace now that is
1099                                                                           counted, return saved string value */
1100                                                                         state=old_state; BEGIN(old_initial);
1101                                                                         yylval.strval=s_buf.s;
1102                                                                         memset(&s_buf, 0, sizeof(s_buf));
1103                                                                         return STRING;
1104                                                                 }
1105
1106 <INITIAL,COMMENT>{COM_START}    { count(); comment_nest++; state=COMMENT_S;
1107                                                                                 BEGIN(COMMENT); }
1108 <COMMENT>{COM_END}                              { count(); comment_nest--;
1109                                                                                 if (comment_nest==0){
1110                                                                                         state=INITIAL_S;
1111                                                                                         BEGIN(INITIAL);
1112                                                                                 }
1113                                                                 }
1114 <COMMENT>.|{EAT_ABLE}|{CR}                              { count(); };
1115
1116 <INITIAL>{COM_LINE}!{SER_CFG}{CR}               { count();
1117                                                                                         sr_cfg_compat=SR_COMPAT_SER;}
1118 <INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}  { count(); 
1119                                                                                         sr_cfg_compat=SR_COMPAT_KAMAILIO;}
1120 <INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR} { count(); 
1121                                                                                                 sr_cfg_compat=SR_COMPAT_MAX;}
1122 <INITIAL>{COM_LINE}.*{CR}       { count(); }
1123
1124 <INITIAL>{ID}                   { count(); addstr(&s_buf, yytext, yyleng);
1125                                                                         yylval.strval=s_buf.s;
1126                                                                         memset(&s_buf, 0, sizeof(s_buf));
1127                                                                         return ID; }
1128 <INITIAL>{NUM_ID}                       { count(); addstr(&s_buf, yytext, yyleng);
1129                                                                         yylval.strval=s_buf.s;
1130                                                                         memset(&s_buf, 0, sizeof(s_buf));
1131                                                                         return NUM_ID; }
1132
1133 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
1134
1135 <INCLF>[ \t]*      /* eat the whitespace */
1136 <INCLF>[^ \t\n]+   { /* get the include file name */
1137                                 if(sr_push_yy_state(yytext)<0)
1138                                         exit(-1);
1139                                 BEGIN(INITIAL);
1140 }
1141
1142
1143 <<EOF>>                                                 {
1144                                                                         switch(state){
1145                                                                                 case STR_BETWEEN_S:
1146                                                                                         state=old_state;
1147                                                                                         BEGIN(old_initial);
1148                                                                                         yylval.strval=s_buf.s;
1149                                                                                         memset(&s_buf, 0, sizeof(s_buf));
1150                                                                                         return STRING;
1151                                                                                 case STRING_S:
1152                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
1153                                                                                                                 " unclosed string\n");
1154                                                                                         if (s_buf.s){
1155                                                                                                 pkg_free(s_buf.s);
1156                                                                                                 memset(&s_buf, 0,
1157                                                                                                                         sizeof(s_buf));
1158                                                                                         }
1159                                                                                         break;
1160                                                                                 case COMMENT_S:
1161                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
1162                                                                                                                 " %d comments open\n", comment_nest);
1163                                                                                         break;
1164                                                                                 case COMMENT_LN_S:
1165                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF:"
1166                                                                                                                 "comment line open\n");
1167                                                                                         break;
1168                                                                                 case  ATTR_S:
1169                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1170                                                                                                         " while parsing"
1171                                                                                                         " avp name\n");
1172                                                                                         break;
1173                                                                                 case PVARID_S:
1174                                                                                         p_nest=0;
1175                                                                                 case PVAR_P_S: 
1176                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1177                                                                                                         " while parsing pvar name"
1178                                                                                                         " (%d paranthesis open)\n",
1179                                                                                                         p_nest);
1180                                                                                         break;
1181                                                                                 case AVP_PVAR_S:
1182                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1183                                                                                                         " while parsing"
1184                                                                                                         " avp or pvar name\n");
1185                                                                         }
1186                                                                         if(sr_pop_yy_state()<0)
1187                                                                                 return 0;
1188                                                                 }
1189
1190 %%
1191
1192
1193 static char* addchar(struct str_buf* dst, char c)
1194 {
1195         return addstr(dst, &c, 1);
1196 }
1197
1198
1199
1200 static char* addstr(struct str_buf* dst_b, char* src, int len)
1201 {
1202         char *tmp;
1203         unsigned size;
1204         unsigned used;
1205
1206         if (dst_b->left<(len+1)){
1207                 used=(unsigned)(dst_b->crt-dst_b->s);
1208                 size=used+len+1;
1209                 /* round up to next multiple */
1210                 size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
1211                 tmp=pkg_malloc(size);
1212                 if (tmp==0) goto error;
1213                 if (dst_b->s){
1214                         memcpy(tmp, dst_b->s, used);
1215                         pkg_free(dst_b->s);
1216                 }
1217                 dst_b->s=tmp;
1218                 dst_b->crt=dst_b->s+used;
1219                 dst_b->left=size-used;
1220         }
1221         memcpy(dst_b->crt, src, len);
1222         dst_b->crt+=len;
1223         *(dst_b->crt)=0;
1224         dst_b->left-=len;
1225
1226         return dst_b->s;
1227 error:
1228         LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
1229         return 0;
1230 }
1231
1232
1233
1234 /** helper function for count_*(). */
1235 static void count_lc(int* l, int* c)
1236 {
1237         int i;
1238         for (i=0; i<yyleng;i++){
1239                 if (yytext[i]=='\n'){
1240                         (*l)++;
1241                         (*c)=1;
1242                 }else if (yytext[i]=='\t'){
1243                         (*c)++;
1244                         /*(*c)+=8 -((*c)%8);*/
1245                 }else{
1246                         (*c)++;
1247                 }
1248         }
1249 }
1250
1251
1252
1253 /* helper function */
1254 static void count_restore_ignored()
1255 {
1256         if (ign_lines) /* ignored line(s) => column has changed */
1257                 column=ign_columns;
1258         else
1259                 column+=ign_columns;
1260         line+=ign_lines;
1261         ign_lines=ign_columns=0;
1262 }
1263
1264
1265
1266 /** count/record position for stuff added to the current token. */
1267 static void count_more()
1268 {
1269         count_restore_ignored();
1270         count_lc(&line, &column);
1271 }
1272
1273
1274
1275 /** count/record position for a new token. */
1276 static void count()
1277 {
1278         count_restore_ignored();
1279         startline=line;
1280         startcolumn=column;
1281         count_more();
1282 }
1283
1284
1285
1286 /** record discarded stuff (not contained in the token) so that
1287     the next token position can be adjusted properly*/
1288 static void count_ignore()
1289 {
1290         count_lc(&ign_lines, &ign_columns);
1291 }
1292
1293
1294 /* replacement yywrap, removes libfl dependency */
1295 int yywrap()
1296 {
1297         return 1;
1298 }
1299
1300 static int sr_push_yy_state(char *fin)
1301 {
1302         struct sr_yy_fname *fn = NULL;
1303         char *x = NULL;
1304         char *newf = NULL;
1305 #define MAX_INCLUDE_FNAME       128
1306         char fbuf[MAX_INCLUDE_FNAME];
1307         int i, j, l;
1308
1309         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
1310         {
1311                 LOG(L_CRIT, "too many includes\n");
1312                 return -1;
1313         }
1314         l = strlen(fin);
1315         if(l>=MAX_INCLUDE_FNAME)
1316         {
1317                 LOG(L_CRIT, "included file name too long\n");
1318                 return -1;
1319         }
1320         if(fin[0]!='"' || fin[l-1]!='"')
1321         {
1322                 LOG(L_CRIT, "included file name must be between quotes\n");
1323                 return -1;
1324         }
1325         j = 0;
1326         for(i=1; i<l-1; i++)
1327         {
1328                 switch(fin[i]) {
1329                         case '\\':
1330                                 if(i+1==l-1)
1331                                 {
1332                                         LOG(L_CRIT, "invalid escape in included file name\n");
1333                                         return -1;
1334                                 }
1335                                 i++;
1336                                 switch(fin[i]) {
1337                                         case 't':
1338                                                 fbuf[j++] = '\t';
1339                                         break;
1340                                         case 'n':
1341                                                 fbuf[j++] = '\n';
1342                                         break;
1343                                         case 'r':
1344                                                 fbuf[j++] = '\r';
1345                                         break;
1346                                         default:
1347                                                 fbuf[j++] = fin[i];
1348                                 }
1349                         break;
1350                         default:
1351                                 fbuf[j++] = fin[i];
1352                 }
1353         }
1354         if(j==0)
1355         {
1356                 LOG(L_CRIT, "invalid included file name\n");
1357                 return -1;
1358         }
1359         fbuf[j] = '\0';
1360
1361         include_stack[include_stack_ptr].state = YY_CURRENT_BUFFER;
1362         include_stack[include_stack_ptr].line = line;
1363         include_stack[include_stack_ptr].column = column;
1364         include_stack[include_stack_ptr].startline = startline;
1365         include_stack[include_stack_ptr].startcolumn = startcolumn;
1366         include_stack[include_stack_ptr].finame = finame;
1367         include_stack_ptr++;
1368
1369         line=1;
1370         column=1;
1371         startline=1;
1372         startcolumn=1;
1373
1374         yyin = fopen(fbuf, "r" );
1375
1376         if ( ! yyin )
1377         {
1378                 finame = (finame==0)?cfg_file:finame;
1379                 if(finame==0 || fbuf[0]=='/')
1380                 {
1381                         LOG(L_CRIT, "cannot open included file: %s\n", fin);
1382                         return -1;
1383                 }
1384                 x = strrchr(finame, '/');
1385                 if(x)
1386                 {
1387                         newf = (char*)pkg_malloc(x-finame+strlen(fbuf)+2);
1388                         if(newf==0)
1389                         {
1390                                 LOG(L_CRIT, "no more pkg\n");
1391                                 return -1;
1392                         }
1393                         newf[0] = '\0';
1394                         strncat(newf, finame, x-finame);
1395                         strcat(newf, "/");
1396                         strcat(newf, fbuf);
1397                 }
1398                 yyin = fopen(newf, "r" );
1399                 if ( ! yyin )
1400                 {
1401                         LOG(L_CRIT, "cannot open included file: %s (%s)\n", fbuf, newf);
1402                         return -1;
1403                 }
1404                 LOG(L_DBG, "including file: %s (%s)\n", fbuf, newf);
1405         } else {
1406                 newf = fbuf;
1407         }
1408
1409         /* make a copy in PKG if does not exist */
1410         fn = sr_yy_fname_list;
1411         while(fn!=0)
1412         {
1413                 if(strcmp(fn->fname, newf)==0)
1414                 {
1415                         if(newf!=fbuf)
1416                                 pkg_free(newf);
1417                         newf = fbuf;
1418                         break;
1419                 }
1420                 fn = fn->next;
1421         }
1422         if(fn==0)
1423         {
1424                 fn = (struct sr_yy_fname*)pkg_malloc(sizeof(struct sr_yy_fname));
1425                 if(fn==0)
1426                 {
1427                         if(newf!=fbuf)
1428                                 pkg_free(newf);
1429                         LOG(L_CRIT, "no more pkg\n");
1430                         return -1;
1431                 }
1432                 if(newf==fbuf)
1433                 {
1434                         fn->fname = (char*)pkg_malloc(strlen(fbuf)+1);
1435                         if(fn->fname==0)
1436                         {
1437                                 pkg_free(fn);
1438                                 LOG(L_CRIT, "no more pkg!\n");
1439                                 return -1;
1440                         }
1441                         strcpy(fn->fname, fbuf);
1442                 } else {
1443                         fn->fname = newf;
1444                 }
1445                 fn->next = sr_yy_fname_list;
1446                 sr_yy_fname_list = fn;
1447         }
1448
1449         finame = fn->fname;
1450
1451         yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE ) );
1452
1453         return 0;
1454
1455 }
1456
1457 static int sr_pop_yy_state()
1458 {
1459         include_stack_ptr--;
1460         if (include_stack_ptr<0 )
1461                 return -1;
1462
1463         yy_delete_buffer( YY_CURRENT_BUFFER );
1464         yy_switch_to_buffer(include_stack[include_stack_ptr].state);
1465         line=include_stack[include_stack_ptr].line;
1466         column=include_stack[include_stack_ptr].column;
1467         startline=include_stack[include_stack_ptr].startline;
1468         startcolumn=include_stack[include_stack_ptr].startcolumn;
1469         finame = include_stack[include_stack_ptr].finame;
1470         return 0;
1471 }
1472