73be332a2918033ee9dfca4b681877ebd91b3893
[kamailio] / src / core / cfg.lex
1 /*
2  * scanner for cfg files
3  *
4  * Copyright (C) 2001-2003 FhG Fokus
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * Kamailio is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26  *
27 */
28
29 %option noinput
30
31 %{
32         #include "dprint.h"
33         #include "globals.h"
34         #include "mem/mem.h"
35         #include <string.h>
36         #include <stdlib.h>
37         #include "ip_addr.h"
38         #include "usr_avp.h"
39         #include "select.h"
40         #include "cfg.tab.h"
41         #include "sr_compat.h"
42         #include "daemonize.h"
43         #include "ppcfg.h"
44
45         static void ksr_yy_fatal_error(const char* msg);
46         #define YY_FATAL_ERROR(msg) ksr_yy_fatal_error(msg);
47
48         /* states */
49         #define INITIAL_S               0
50         #define COMMENT_S               1
51         #define COMMENT_LN_S            2
52         #define STRING_S                3
53         #define ATTR_S                  4  /* avp/attr */
54         #define SELECT_S                5
55         #define AVP_PVAR_S              6  /* avp or pvar */
56         #define PVAR_P_S                7  /* pvar: $(...)  or $foo(...)*/
57         #define PVARID_S                8  /* $foo.bar...*/
58         #define STR_BETWEEN_S           9
59         #define LINECOMMENT_S           10
60         #define DEFINE_S                11
61         #define DEFINE_EOL_S            12
62         #define IFDEF_S                 13
63         #define IFDEF_EOL_S             14
64         #define IFDEF_SKIP_S            15
65         #define DEFINE_DATA_S           16
66         #define EVRT_NAME_S             17
67
68         #define STR_BUF_ALLOC_UNIT      128
69         struct str_buf{
70                 char* s;
71                 char* crt;
72                 int left;
73         };
74
75
76         static int comment_nest=0;
77         static int p_nest=0;
78         static int state=0, old_state=0, old_initial=0;
79         static struct str_buf s_buf;
80         int line=1;
81         int column=1;
82         int startcolumn=1;
83         int startline=1;
84         char *finame = 0;
85         char *routename = 0;
86         char *default_routename = 0;
87
88         static int ign_lines=0;
89         static int ign_columns=0;
90         char* yy_number_str=0; /* str correspondent for the current NUMBER token */
91         int r = 0;
92         str *sdef = 0;
93
94         static char* addchar(struct str_buf *, char);
95         static char* addstr(struct str_buf *, char*, int);
96         static void count();
97         static void count_more();
98         static void count_ignore();
99
100         #define MAX_INCLUDE_DEPTH 10
101         static struct sr_yy_state {
102                 YY_BUFFER_STATE state;
103                 int line;
104                 int column;
105                 int startcolumn;
106                 int startline;
107                 char *finame;
108                 char *routename;
109         } include_stack[MAX_INCLUDE_DEPTH];
110         static int include_stack_ptr = 0;
111
112         static int sr_push_yy_state(char *fin, int mode);
113         static int sr_pop_yy_state();
114
115         static struct sr_yy_fname {
116                 char *fname;
117                 struct sr_yy_fname *next;
118         } *sr_yy_fname_list = 0;
119
120         str  *pp_define_get(int len, const char * text);
121         static int  pp_ifdef_type(int pos);
122         static void pp_ifdef_var(int len, const char * text);
123         static void pp_ifdef();
124         static void pp_else();
125         static void pp_endif();
126
127 %}
128
129 /* start conditions */
130 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
131 %x PVARID INCLF IMPTF EVRTNAME
132 %x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP
133
134 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
135 SER_CFG                 SER
136 KAMAILIO_CFG    KAMAILIO|OPENSER
137 MAXCOMPAT_CFG   MAXCOMPAT|ALL
138
139 /* action keywords */
140 FORWARD forward
141 FORWARD_TCP     forward_tcp
142 FORWARD_UDP     forward_udp
143 FORWARD_TLS     forward_tls
144 FORWARD_SCTP    forward_sctp
145 DROP    "drop"
146 EXIT    "exit"
147 RETURN  "return"
148 BREAK   "break"
149 LOG             log
150 ERROR   error
151 ROUTE   route
152 ROUTE_REQUEST request_route
153 ROUTE_FAILURE failure_route
154 ROUTE_REPLY reply_route
155 ROUTE_ONREPLY onreply_route
156 ROUTE_BRANCH branch_route
157 ROUTE_SEND onsend_route
158 ROUTE_EVENT event_route
159 EXEC    exec
160 FORCE_RPORT             "force_rport"|"add_rport"
161 ADD_LOCAL_RPORT         "add_local_rport"
162 FORCE_TCP_ALIAS         "force_tcp_alias"|"add_tcp_alias"
163 UDP_MTU         "udp_mtu"
164 UDP_MTU_TRY_PROTO       "udp_mtu_try_proto"
165 UDP4_RAW                "udp4_raw"
166 UDP4_RAW_MTU    "udp4_raw_mtu"
167 UDP4_RAW_TTL    "udp4_raw_ttl"
168 SETFLAG         setflag
169 RESETFLAG       resetflag
170 ISFLAGSET       isflagset
171 FLAGS_DECL      "flags"|"bool"
172 SETAVPFLAG      setavpflag
173 RESETAVPFLAG    resetavpflag
174 ISAVPFLAGSET    isavpflagset
175 AVPFLAGS_DECL   avpflags
176 SET_HOST                "rewritehost"|"sethost"|"seth"
177 SET_HOSTPORT    "rewritehostport"|"sethostport"|"sethp"
178 SET_HOSTPORTTRANS       "rewritehostporttrans"|"sethostporttrans"|"sethpt"
179 SET_USER                "rewriteuser"|"setuser"|"setu"
180 SET_USERPASS    "rewriteuserpass"|"setuserpass"|"setup"
181 SET_PORT                "rewriteport"|"setport"|"setp"
182 SET_URI                 "rewriteuri"|"seturi"
183 REVERT_URI              "revert_uri"
184 PREFIX                  "prefix"
185 STRIP                   "strip"
186 STRIP_TAIL              "strip_tail"
187 SET_USERPHONE           "userphone"
188 REMOVE_BRANCH   "remove_branch"
189 CLEAR_BRANCHES  "clear_branches"
190 IF                              "if"
191 ELSE                    "else"
192 SET_ADV_ADDRESS "set_advertised_address"
193 SET_ADV_PORT    "set_advertised_port"
194 FORCE_SEND_SOCKET       "force_send_socket"
195 SET_FWD_NO_CONNECT              "set_forward_no_connect"
196 SET_RPL_NO_CONNECT      "set_reply_no_connect"
197 SET_FWD_CLOSE   "set_forward_close"
198 SET_RPL_CLOSE   "set_reply_close"
199 SWITCH                  "switch"
200 CASE                    "case"
201 DEFAULT                 "default"
202 WHILE                   "while"
203
204 CFG_SELECT      "cfg_select"
205 CFG_RESET       "cfg_reset"
206
207 /*ACTION LVALUES*/
208 URIHOST                 "uri:host"
209 URIPORT                 "uri:port"
210
211 MAX_LEN                 "max_len"
212
213
214 /* condition keywords */
215 METHOD  method
216 /* hack -- the second element in first line is referable
217  * as either uri or status; it only would makes sense to
218  * call it "uri" from route{} and status from onreply_route{}
219  */
220 URI             "uri"|"status"
221 FROM_URI        "from_uri"
222 TO_URI          "to_uri"
223 SRCIP   src_ip
224 SRCPORT src_port
225 DSTIP   dst_ip
226 DSTPORT dst_port
227 SNDIP   snd_ip
228 SNDPORT snd_port
229 SNDPROTO        snd_proto|to_proto
230 SNDAF           snd_af|to_af
231 TOIP    to_ip
232 TOPORT  to_port
233 PROTO   proto
234 AF              af
235 MYSELF  myself
236 MSGLEN                  "msg:len"
237 RETCODE \$\?|\$retcode|\$rc
238 /* operators */
239 EQUAL   =
240 EQUAL_T ==
241 GT      >
242 LT      <
243 GTE     >=
244 LTE     <=
245 DIFF    !=
246 MATCH   =~
247 ADDEQ     "+="
248 NOT             !|"not"
249 LOG_AND         "and"|"&&"
250 BIN_AND         "&"
251 LOG_OR          "or"|"||"
252 BIN_OR          "|"
253 BIN_NOT     "~"
254 BIN_XOR     "^"
255 BIN_LSHIFT     "<<"
256 BIN_RSHIFT     ">>"
257 PLUS    "+"
258 MINUS   "-"
259 MODULO  "mod"
260 STRLEN  "strlen"
261 STREMPTY        "strempty"
262 DEFINED         "defined"
263 STREQ   eq
264 INTEQ   ieq
265 STRDIFF ne
266 INTDIFF ine
267 INTCAST \(int\)
268 STRCAST \(str\)
269
270 /* Attribute specification */
271 ATTR_MARK   "%"
272 VAR_MARK    "$"
273 SELECT_MARK  "@"
274 ATTR_FROM         "f"
275 ATTR_TO           "t"
276 ATTR_FROMURI      "fr"
277 ATTR_TOURI       "tr"
278 ATTR_FROMUSER     "fu"
279 ATTR_TOUSER       "tu"
280 ATTR_FROMDOMAIN   "fd"
281 ATTR_TODOMAIN     "td"
282 ATTR_GLOBAL       "g"
283
284 /* avp prefix */
285 AVP_PREF        (([ft][rud]?)|g)\.
286
287 /* config vars. */
288 DEBUG   debug
289 FORK    fork
290 FORK_DELAY      fork_delay
291 MODINIT_DELAY   modinit_delay
292 LOGSTDERROR     log_stderror
293 LOGFACILITY     log_facility
294 LOGNAME         log_name
295 LOGCOLOR        log_color
296 LOGPREFIX       log_prefix
297 LOGPREFIXMODE   log_prefix_mode
298 LOGENGINETYPE   log_engine_type
299 LOGENGINEDATA   log_engine_data
300 XAVPVIAPARAMS   xavp_via_params
301 XAVPVIAFIELDS   xavp_via_fields
302 LISTEN          listen
303 ADVERTISE       advertise|ADVERTISE
304 STRNAME         name|NAME
305 ALIAS           alias
306 SR_AUTO_ALIASES auto_aliases
307 DNS              dns
308 REV_DNS  rev_dns
309 DNS_TRY_IPV6    dns_try_ipv6
310 DNS_TRY_NAPTR   dns_try_naptr
311 DNS_SRV_LB              dns_srv_lb|dns_srv_loadbalancing
312 DNS_UDP_PREF    dns_udp_pref|dns_udp_preference
313 DNS_TCP_PREF    dns_tcp_pref|dns_tcp_preference
314 DNS_TLS_PREF    dns_tls_pref|dns_tls_preference
315 DNS_SCTP_PREF   dns_sctp_pref|dns_sctp_preference
316 DNS_RETR_TIME   dns_retr_time
317 DNS_SLOW_QUERY_MS       dns_slow_query_ms
318 DNS_RETR_NO             dns_retr_no
319 DNS_SERVERS_NO  dns_servers_no
320 DNS_USE_SEARCH  dns_use_search_list
321 DNS_SEARCH_FMATCH       dns_search_full_match
322 DNS_NAPTR_IGNORE_RFC    dns_naptr_ignore_rfc
323 /* dns cache */
324 DNS_CACHE_INIT  dns_cache_init
325 DNS_USE_CACHE   use_dns_cache
326 DNS_USE_FAILOVER        use_dns_failover
327 DNS_CACHE_FLAGS         dns_cache_flags
328 DNS_CACHE_NEG_TTL       dns_cache_negative_ttl
329 DNS_CACHE_MIN_TTL       dns_cache_min_ttl
330 DNS_CACHE_MAX_TTL       dns_cache_max_ttl
331 DNS_CACHE_MEM           dns_cache_mem
332 DNS_CACHE_GC_INT        dns_cache_gc_interval
333 DNS_CACHE_DEL_NONEXP    dns_cache_del_nonexp|dns_cache_delete_nonexpired
334 DNS_CACHE_REC_PREF      dns_cache_rec_pref
335 /* ipv6 auto bind */
336 AUTO_BIND_IPV6          auto_bind_ipv6
337 BIND_IPV6_LINK_LOCAL    bind_ipv6_link_local
338 /* blacklist */
339 DST_BLST_INIT   dst_blacklist_init
340 USE_DST_BLST            use_dst_blacklist
341 DST_BLST_MEM            dst_blacklist_mem
342 DST_BLST_TTL            dst_blacklist_expire|dst_blacklist_ttl
343 DST_BLST_GC_INT         dst_blacklist_gc_interval
344 DST_BLST_UDP_IMASK      dst_blacklist_udp_imask
345 DST_BLST_TCP_IMASK      dst_blacklist_tcp_imask
346 DST_BLST_TLS_IMASK      dst_blacklist_tls_imask
347 DST_BLST_SCTP_IMASK     dst_blacklist_sctp_imask
348
349 IP_FREE_BIND            ip_free_bind|ipfreebind|ip_nonlocal_bind
350
351 PORT    port
352 STAT    statistics
353 STATS_NAMESEP   stats_name_separator
354 MAXBUFFER maxbuffer
355 SQL_BUFFER_SIZE sql_buffer_size
356 CHILDREN children
357 SOCKET_WORKERS socket_workers
358 ASYNC_WORKERS async_workers
359 ASYNC_USLEEP async_usleep
360 ASYNC_NONBLOCK async_nonblock
361 CHECK_VIA       check_via
362 PHONE2TEL       phone2tel
363 MEMLOG          "memlog"|"mem_log"
364 MEMDBG          "memdbg"|"mem_dbg"
365 MEMSUM          "mem_summary"
366 MEMSAFETY       "mem_safety"
367 MEMJOIN         "mem_join"
368 MEMSTATUSMODE           "mem_status_mode"
369 CORELOG         "corelog"|"core_log"
370 SIP_WARNING sip_warning
371 SERVER_SIGNATURE server_signature
372 SERVER_HEADER server_header
373 USER_AGENT_HEADER user_agent_header
374 REPLY_TO_VIA reply_to_via
375 USER            "user"|"uid"
376 GROUP           "group"|"gid"
377 CHROOT          "chroot"
378 WDIR            "workdir"|"wdir"
379 RUNDIR          "rundir"|"run_dir"
380 MHOMED          mhomed
381 DISABLE_TCP             "disable_tcp"
382 TCP_CHILDREN    "tcp_children"
383 TCP_ACCEPT_ALIASES      "tcp_accept_aliases"
384 TCP_ACCEPT_UNIQUE       "tcp_accept_unique"
385 TCP_SEND_TIMEOUT        "tcp_send_timeout"
386 TCP_CONNECT_TIMEOUT     "tcp_connect_timeout"
387 TCP_CON_LIFETIME        "tcp_connection_lifetime"
388 TCP_CONNECTION_MATCH    "tcp_connection_match"
389 TCP_POLL_METHOD         "tcp_poll_method"
390 TCP_MAX_CONNECTIONS     "tcp_max_connections"
391 TLS_MAX_CONNECTIONS     "tls_max_connections"
392 TCP_NO_CONNECT          "tcp_no_connect"
393 TCP_SOURCE_IPV4         "tcp_source_ipv4"
394 TCP_SOURCE_IPV6         "tcp_source_ipv6"
395 TCP_OPT_FD_CACHE        "tcp_fd_cache"
396 TCP_OPT_BUF_WRITE       "tcp_buf_write"|"tcp_async"
397 TCP_OPT_CONN_WQ_MAX     "tcp_conn_wq_max"
398 TCP_OPT_WQ_MAX          "tcp_wq_max"
399 TCP_OPT_RD_BUF          "tcp_rd_buf_size"
400 TCP_OPT_WQ_BLK          "tcp_wq_blk_size"
401 TCP_OPT_DEFER_ACCEPT "tcp_defer_accept"
402 TCP_OPT_DELAYED_ACK     "tcp_delayed_ack"
403 TCP_OPT_SYNCNT          "tcp_syncnt"
404 TCP_OPT_LINGER2         "tcp_linger2"
405 TCP_OPT_KEEPALIVE       "tcp_keepalive"
406 TCP_OPT_KEEPIDLE        "tcp_keepidle"
407 TCP_OPT_KEEPINTVL       "tcp_keepintvl"
408 TCP_OPT_KEEPCNT         "tcp_keepcnt"
409 TCP_OPT_CRLF_PING       "tcp_crlf_ping"
410 TCP_OPT_ACCEPT_NO_CL    "tcp_accept_no_cl"
411 TCP_OPT_ACCEPT_HEP3     "tcp_accept_hep3"
412 TCP_OPT_ACCEPT_HAPROXY  "tcp_accept_haproxy"
413 TCP_CLONE_RCVBUF        "tcp_clone_rcvbuf"
414 TCP_REUSE_PORT          "tcp_reuse_port"
415 DISABLE_TLS             "disable_tls"|"tls_disable"
416 ENABLE_TLS              "enable_tls"|"tls_enable"
417 TLSLOG                  "tlslog"|"tls_log"
418 TLS_PORT_NO             "tls_port_no"
419 TLS_METHOD              "tls_method"
420 TLS_VERIFY              "tls_verify"
421 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
422 TLS_CERTIFICATE "tls_certificate"
423 TLS_PRIVATE_KEY "tls_private_key"
424 TLS_CA_LIST             "tls_ca_list"
425 TLS_HANDSHAKE_TIMEOUT   "tls_handshake_timeout"
426 TLS_SEND_TIMEOUT        "tls_send_timeout"
427 DISABLE_SCTP    "disable_sctp"
428 ENABLE_SCTP     "enable_sctp"
429 SCTP_CHILDREN   "sctp_children"
430
431 ADVERTISED_ADDRESS      "advertised_address"
432 ADVERTISED_PORT         "advertised_port"
433 DISABLE_CORE            "disable_core_dump"
434 OPEN_FD_LIMIT           "open_files_limit"
435 SHM_MEM_SZ              "shm"|"shm_mem"|"shm_mem_size"
436 SHM_FORCE_ALLOC         "shm_force_alloc"
437 MLOCK_PAGES                     "mlock_pages"
438 REAL_TIME                       "real_time"
439 RT_PRIO                         "rt_prio"
440 RT_POLICY                       "rt_policy"
441 RT_TIMER1_PRIO          "rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
442 RT_TIMER1_POLICY        "rt_timer1_policy"|"rt_ftimer_policy"
443 RT_TIMER2_PRIO          "rt_timer2_prio"|"rt_stimer_prio"
444 RT_TIMER2_POLICY        "rt_timer2_policy"|"rt_stimer_policy"
445 MCAST_LOOPBACK          "mcast_loopback"
446 MCAST_TTL               "mcast_ttl"
447 MCAST           "mcast"
448 TOS                     "tos"
449 PMTU_DISCOVERY  "pmtu_discovery"
450 KILL_TIMEOUT    "exit_timeout"|"ser_kill_timeout"
451 MAX_WLOOPS              "max_while_loops"
452 PVBUFSIZE               "pv_buffer_size"
453 PVBUFSLOTS              "pv_buffer_slots"
454 PVCACHELIMIT    "pv_cache_limit"
455 PVCACHEACTION   "pv_cache_action"
456 HTTP_REPLY_PARSE        "http_reply_hack"|"http_reply_parse"
457 VERSION_TABLE_CFG       "version_table"
458 VERBOSE_STARTUP         "verbose_startup"
459
460 SERVER_ID     "server_id"
461 ROUTE_LOCKS_SIZE     "route_locks_size"
462
463 KEMI     "kemi"
464 ONSEND_ROUTE_CALLBACK   "onsend_route_callback"
465 REPLY_ROUTE_CALLBACK    "reply_route_callback"
466 EVENT_ROUTE_CALLBACK    "event_route_callback"
467 RECEIVED_ROUTE_CALLBACK "received_route_callback"
468 RECEIVED_ROUTE_MODE             "received_route_mode"
469
470 MAX_RECURSIVE_LEVEL             "max_recursive_level"
471 MAX_BRANCHES_PARAM              "max_branches"
472
473 LATENCY_CFG_LOG                 latency_cfg_log
474 LATENCY_LOG                             latency_log
475 LATENCY_LIMIT_DB                latency_limit_db
476 LATENCY_LIMIT_ACTION    latency_limit_action
477 LATENCY_LIMIT_CFG               latency_limit_cfg
478
479 URI_HOST_EXTRA_CHARS    "uri_host_extra_chars"
480
481 MSG_TIME        msg_time
482 ONSEND_RT_REPLY         "onsend_route_reply"
483 CFG_DESCRIPTION         "description"|"descr"|"desc"
484
485 LOADMODULE      loadmodule
486 LOADPATH        "loadpath"|"mpath"
487 MODPARAM        modparam
488
489 CFGENGINE       "cfgengine"
490
491 /* values */
492 YES                     "yes"|"true"|"on"|"enable"
493 NO                      "no"|"false"|"off"|"disable"
494 UDP                     "udp"|"UDP"
495 TCP                     "tcp"|"TCP"
496 TLS                     "tls"|"TLS"
497 SCTP            "sctp"|"SCTP"
498 WS              "ws"|"WS"
499 WSS             "wss"|"WSS"
500 INET            "inet"|"INET"
501 INET6           "inet6"|"INET6"
502 SSLv23                  "sslv23"|"SSLv23"|"SSLV23"
503 SSLv2                   "sslv2"|"SSLv2"|"SSLV2"
504 SSLv3                   "sslv3"|"SSLv3"|"SSLV3"
505 TLSv1                   "tlsv1"|"TLSv1"|"TLSV1"
506
507 LETTER          [a-zA-Z]
508 DIGIT           [0-9]
509 LETTER_     {LETTER}|[_]
510 ALPHANUM    {LETTER_}|{DIGIT}
511 ID          {LETTER_}{ALPHANUM}*
512 NUM_ID          {ALPHANUM}+
513 HEX                     [0-9a-fA-F]
514 HEXNUMBER       0x{HEX}+
515 OCTNUMBER       0[0-7]+
516 DECNUMBER       0|([1-9]{DIGIT}*)
517 BINNUMBER       [0-1]+b
518 HEX4            {HEX}{1,4}
519 IPV6ADDR        ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
520 QUOTES          \"
521 TICK            \'
522 SLASH           "/"
523 SEMICOLON       ;
524 RPAREN          \)
525 LPAREN          \(
526 LBRACE          \{
527 RBRACE          \}
528 LBRACK          \[
529 RBRACK          \]
530 COMMA           ","
531 COLON           ":"
532 STAR            \*
533 DOT                     \.
534 CR                      \n
535 EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*(":"[a-zA-Z][0-9a-zA-Z_-]*)+
536
537
538 COM_LINE        "#"|"//"
539 COM_START       "/\*"
540 COM_END         "\*/"
541
542 /* start of pre-processing directives */
543 PREP_START      "#!"|"!!"
544
545 DEFINE       "define"|"def"
546 IFDEF        ifdef
547 IFNDEF       ifndef
548 ENDIF        endif
549 TRYDEF       "trydefine"|"trydef"
550 REDEF        "redefine"|"redef"
551
552 /* else is already defined */
553
554 EAT_ABLE        [\ \t\b\r]
555
556 /* pre-processing blocks */
557 SUBST       subst
558 SUBSTDEF    substdef
559 SUBSTDEFS   substdefs
560
561 /* include files */
562 INCLUDEFILE     "include_file"
563 IMPORTFILE      "import_file"
564
565 %%
566
567
568 <INITIAL>{EAT_ABLE}     { count(); }
569
570 <INITIAL>{FORWARD}      {count(); yylval.strval=yytext; return FORWARD; }
571 <INITIAL>{FORWARD_TCP}  {count(); yylval.strval=yytext; return FORWARD_TCP; }
572 <INITIAL>{FORWARD_TLS}  {count(); yylval.strval=yytext; return FORWARD_TLS; }
573 <INITIAL>{FORWARD_SCTP} {count(); yylval.strval=yytext; return FORWARD_SCTP;}
574 <INITIAL>{FORWARD_UDP}  {count(); yylval.strval=yytext; return FORWARD_UDP; }
575 <INITIAL>{DROP} { count(); yylval.strval=yytext; return DROP; }
576 <INITIAL>{EXIT} { count(); yylval.strval=yytext; return EXIT; }
577 <INITIAL>{RETURN}       { count(); yylval.strval=yytext; return RETURN; }
578 <INITIAL>{BREAK}        { count(); yylval.strval=yytext; return BREAK; }
579 <INITIAL>{LOG}  { count(); yylval.strval=yytext; return LOG_TOK; }
580 <INITIAL>{ERROR}        { count(); yylval.strval=yytext; return ERROR; }
581 <INITIAL>{SETFLAG}      { count(); yylval.strval=yytext; return SETFLAG; }
582 <INITIAL>{RESETFLAG}    { count(); yylval.strval=yytext; return RESETFLAG; }
583 <INITIAL>{ISFLAGSET}    { count(); yylval.strval=yytext; return ISFLAGSET; }
584 <INITIAL>{FLAGS_DECL}   { count(); yylval.strval=yytext; return FLAGS_DECL; }
585 <INITIAL>{SETAVPFLAG}   { count(); yylval.strval=yytext; return SETAVPFLAG; }
586 <INITIAL>{RESETAVPFLAG} { count(); yylval.strval=yytext; return RESETAVPFLAG; }
587 <INITIAL>{ISAVPFLAGSET} { count(); yylval.strval=yytext; return ISAVPFLAGSET; }
588 <INITIAL>{AVPFLAGS_DECL}        { count(); yylval.strval=yytext; return AVPFLAGS_DECL; }
589 <INITIAL>{MSGLEN}       { count(); yylval.strval=yytext; return MSGLEN; }
590 <INITIAL>{ROUTE}        { count(); default_routename="DEFAULT_ROUTE";
591                                                 yylval.strval=yytext; return ROUTE; }
592 <INITIAL>{ROUTE_REQUEST}        { count(); default_routename="DEFAULT_ROUTE";
593                                                                 yylval.strval=yytext; return ROUTE_REQUEST; }
594 <INITIAL>{ROUTE_ONREPLY}        { count(); default_routename="DEFAULT_ONREPLY";
595                                                                 yylval.strval=yytext;
596                                                                 return ROUTE_ONREPLY; }
597 <INITIAL>{ROUTE_REPLY}  { count(); default_routename="DEFAULT_ONREPLY";
598                                                         yylval.strval=yytext; return ROUTE_REPLY; }
599 <INITIAL>{ROUTE_FAILURE}        { count(); default_routename="DEFAULT_FAILURE";
600                                                                 yylval.strval=yytext;
601                                                                 return ROUTE_FAILURE; }
602 <INITIAL>{ROUTE_BRANCH} { count(); default_routename="DEFAULT_BRANCH";
603                                                         yylval.strval=yytext; return ROUTE_BRANCH; }
604 <INITIAL>{ROUTE_SEND} { count(); default_routename="DEFAULT_SEND";
605                                                         yylval.strval=yytext; return ROUTE_SEND; }
606 <INITIAL>{ROUTE_EVENT} { count(); default_routename="DEFAULT_EVENT";
607                                                         yylval.strval=yytext;
608                                                         state=EVRT_NAME_S; BEGIN(EVRTNAME);
609                                                         return ROUTE_EVENT; }
610 <EVRTNAME>{LBRACK}          { count(); return LBRACK; }
611 <EVRTNAME>{EAT_ABLE}|{CR}                               { count(); };
612 <EVRTNAME>{EVENT_RT_NAME}       { count();
613                                                                 addstr(&s_buf, yytext, yyleng);
614                                                                 yylval.strval=s_buf.s;
615                                                                 routename=s_buf.s;
616                                                                 memset(&s_buf, 0, sizeof(s_buf));
617                                                                 return EVENT_RT_NAME; }
618 <EVRTNAME>{RBRACK}          { count();
619                                                                 state=INITIAL_S; BEGIN(INITIAL);
620                                                                 return RBRACK; }
621 <INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
622 <INITIAL>{SET_HOST}     { count(); yylval.strval=yytext; return SET_HOST; }
623 <INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
624 <INITIAL>{SET_HOSTPORTTRANS}    { count(); yylval.strval=yytext; return SET_HOSTPORTTRANS; }
625 <INITIAL>{SET_USER}     { count(); yylval.strval=yytext; return SET_USER; }
626 <INITIAL>{SET_USERPASS} { count(); yylval.strval=yytext; return SET_USERPASS; }
627 <INITIAL>{SET_PORT}     { count(); yylval.strval=yytext; return SET_PORT; }
628 <INITIAL>{SET_URI}      { count(); yylval.strval=yytext; return SET_URI; }
629 <INITIAL>{REVERT_URI}   { count(); yylval.strval=yytext; return REVERT_URI; }
630 <INITIAL>{PREFIX}       { count(); yylval.strval=yytext; return PREFIX; }
631 <INITIAL>{STRIP}        { count(); yylval.strval=yytext; return STRIP; }
632 <INITIAL>{STRIP_TAIL}   { count(); yylval.strval=yytext; return STRIP_TAIL; }
633 <INITIAL>{REMOVE_BRANCH}        { count(); yylval.strval=yytext;
634                                                                 return REMOVE_BRANCH; }
635 <INITIAL>{CLEAR_BRANCHES}       { count(); yylval.strval=yytext;
636                                                                 return CLEAR_BRANCHES; }
637 <INITIAL>{SET_USERPHONE}        { count(); yylval.strval=yytext;
638                                                                 return SET_USERPHONE; }
639 <INITIAL>{FORCE_RPORT}  { count(); yylval.strval=yytext; return FORCE_RPORT; }
640 <INITIAL>{ADD_LOCAL_RPORT}      { count(); yylval.strval=yytext;
641                                                                 return ADD_LOCAL_RPORT; }
642 <INITIAL>{FORCE_TCP_ALIAS}      { count(); yylval.strval=yytext;
643                                                                 return FORCE_TCP_ALIAS; }
644 <INITIAL>{UDP_MTU}      { count(); yylval.strval=yytext; return UDP_MTU; }
645 <INITIAL>{UDP_MTU_TRY_PROTO}    { count(); yylval.strval=yytext;
646                                                                         return UDP_MTU_TRY_PROTO; }
647 <INITIAL>{UDP4_RAW}     { count(); yylval.strval=yytext; return UDP4_RAW; }
648 <INITIAL>{UDP4_RAW_MTU} { count(); yylval.strval=yytext; return UDP4_RAW_MTU; }
649 <INITIAL>{UDP4_RAW_TTL} { count(); yylval.strval=yytext; return UDP4_RAW_TTL; }
650 <INITIAL>{IF}   { count(); yylval.strval=yytext; return IF; }
651 <INITIAL>{ELSE} { count(); yylval.strval=yytext; return ELSE; }
652
653 <INITIAL>{SET_ADV_ADDRESS}      { count(); yylval.strval=yytext;
654                                                                                 return SET_ADV_ADDRESS; }
655 <INITIAL>{SET_ADV_PORT} { count(); yylval.strval=yytext;
656                                                                                 return SET_ADV_PORT; }
657 <INITIAL>{FORCE_SEND_SOCKET}    {       count(); yylval.strval=yytext;
658                                                                         return FORCE_SEND_SOCKET; }
659 <INITIAL>{SET_FWD_NO_CONNECT}   { count(); yylval.strval=yytext;
660                                                                         return SET_FWD_NO_CONNECT; }
661 <INITIAL>{SET_RPL_NO_CONNECT}   { count(); yylval.strval=yytext;
662                                                                         return SET_RPL_NO_CONNECT; }
663 <INITIAL>{SET_FWD_CLOSE}                { count(); yylval.strval=yytext;
664                                                                         return SET_FWD_CLOSE; }
665 <INITIAL>{SET_RPL_CLOSE}                { count(); yylval.strval=yytext;
666                                                                         return SET_RPL_CLOSE; }
667 <INITIAL>{SWITCH}       { count(); yylval.strval=yytext; return SWITCH; }
668 <INITIAL>{CASE} { count(); yylval.strval=yytext; return CASE; }
669 <INITIAL>{DEFAULT}      { count(); yylval.strval=yytext; return DEFAULT; }
670 <INITIAL>{WHILE}        { count(); yylval.strval=yytext; return WHILE; }
671
672 <INITIAL>{INCLUDEFILE}  { count(); BEGIN(INCLF); }
673 <INITIAL>{PREP_START}{INCLUDEFILE}  { count(); BEGIN(INCLF); }
674
675 <INITIAL>{IMPORTFILE}  { count(); BEGIN(IMPTF); }
676 <INITIAL>{PREP_START}{IMPORTFILE}  { count(); BEGIN(IMPTF); }
677
678 <INITIAL>{CFG_SELECT}   { count(); yylval.strval=yytext; return CFG_SELECT; }
679 <INITIAL>{CFG_RESET}    { count(); yylval.strval=yytext; return CFG_RESET; }
680
681 <INITIAL>{URIHOST}      { count(); yylval.strval=yytext; return URIHOST; }
682 <INITIAL>{URIPORT}      { count(); yylval.strval=yytext; return URIPORT; }
683
684 <INITIAL>{MAX_LEN}      { count(); yylval.strval=yytext; return MAX_LEN; }
685
686 <INITIAL>{METHOD}       { count(); yylval.strval=yytext; return METHOD; }
687 <INITIAL>{URI}  { count(); yylval.strval=yytext; return URI; }
688 <INITIAL>{FROM_URI}     { count(); yylval.strval=yytext; return FROM_URI; }
689 <INITIAL>{TO_URI}       { count(); yylval.strval=yytext; return TO_URI; }
690 <INITIAL>{SRCIP}        { count(); yylval.strval=yytext; return SRCIP; }
691 <INITIAL>{SRCPORT}      { count(); yylval.strval=yytext; return SRCPORT; }
692 <INITIAL>{DSTIP}        { count(); yylval.strval=yytext; return DSTIP; }
693 <INITIAL>{DSTPORT}      { count(); yylval.strval=yytext; return DSTPORT; }
694 <INITIAL>{SNDIP}        { count(); yylval.strval=yytext; return SNDIP; }
695 <INITIAL>{SNDPORT}      { count(); yylval.strval=yytext; return SNDPORT; }
696 <INITIAL>{SNDPROTO}     { count(); yylval.strval=yytext; return SNDPROTO; }
697 <INITIAL>{SNDAF}        { count(); yylval.strval=yytext; return SNDAF; }
698 <INITIAL>{TOIP}         { count(); yylval.strval=yytext; return TOIP; }
699 <INITIAL>{TOPORT}       { count(); yylval.strval=yytext; return TOPORT; }
700 <INITIAL>{PROTO}        { count(); yylval.strval=yytext; return PROTO; }
701 <INITIAL>{AF}   { count(); yylval.strval=yytext; return AF; }
702 <INITIAL>{MYSELF}       { count(); yylval.strval=yytext; return MYSELF; }
703
704 <INITIAL>{DEBUG}        { count(); yylval.strval=yytext; return DEBUG_V; }
705 <INITIAL>{FORK}         { count(); yylval.strval=yytext; return FORK; }
706 <INITIAL>{FORK_DELAY}   { count(); yylval.strval=yytext; return FORK_DELAY; }
707 <INITIAL>{MODINIT_DELAY}        { count(); yylval.strval=yytext; return MODINIT_DELAY; }
708 <INITIAL>{LOGSTDERROR}  { yylval.strval=yytext; return LOGSTDERROR; }
709 <INITIAL>{LOGFACILITY}  { yylval.strval=yytext; return LOGFACILITY; }
710 <INITIAL>{LOGNAME}      { yylval.strval=yytext; return LOGNAME; }
711 <INITIAL>{LOGCOLOR}     { yylval.strval=yytext; return LOGCOLOR; }
712 <INITIAL>{LOGPREFIX}    { yylval.strval=yytext; return LOGPREFIX; }
713 <INITIAL>{LOGPREFIXMODE}        { yylval.strval=yytext; return LOGPREFIXMODE; }
714 <INITIAL>{LOGENGINETYPE}        { yylval.strval=yytext; return LOGENGINETYPE; }
715 <INITIAL>{LOGENGINEDATA}        { yylval.strval=yytext; return LOGENGINEDATA; }
716 <INITIAL>{XAVPVIAPARAMS}        { yylval.strval=yytext; return XAVPVIAPARAMS; }
717 <INITIAL>{XAVPVIAFIELDS}        { yylval.strval=yytext; return XAVPVIAFIELDS; }
718 <INITIAL>{LISTEN}       { count(); yylval.strval=yytext; return LISTEN; }
719 <INITIAL>{ADVERTISE}    { count(); yylval.strval=yytext; return ADVERTISE; }
720 <INITIAL>{STRNAME}      { count(); yylval.strval=yytext; return STRNAME; }
721 <INITIAL>{ALIAS}        { count(); yylval.strval=yytext; return ALIAS; }
722 <INITIAL>{SR_AUTO_ALIASES}      { count(); yylval.strval=yytext;
723                                                                         return SR_AUTO_ALIASES; }
724 <INITIAL>{DNS}  { count(); yylval.strval=yytext; return DNS; }
725 <INITIAL>{REV_DNS}      { count(); yylval.strval=yytext; return REV_DNS; }
726 <INITIAL>{DNS_TRY_IPV6} { count(); yylval.strval=yytext;
727                                                                 return DNS_TRY_IPV6; }
728 <INITIAL>{DNS_TRY_NAPTR}        { count(); yylval.strval=yytext;
729                                                                 return DNS_TRY_NAPTR; }
730 <INITIAL>{DNS_SRV_LB}   { count(); yylval.strval=yytext;
731                                                                 return DNS_SRV_LB; }
732 <INITIAL>{DNS_UDP_PREF} { count(); yylval.strval=yytext;
733                                                                 return DNS_UDP_PREF; }
734 <INITIAL>{DNS_TCP_PREF} { count(); yylval.strval=yytext;
735                                                                 return DNS_TCP_PREF; }
736 <INITIAL>{DNS_TLS_PREF} { count(); yylval.strval=yytext;
737                                                                 return DNS_TLS_PREF; }
738 <INITIAL>{DNS_SCTP_PREF}        { count(); yylval.strval=yytext;
739                                                                 return DNS_SCTP_PREF; }
740 <INITIAL>{DNS_RETR_TIME}        { count(); yylval.strval=yytext;
741                                                                 return DNS_RETR_TIME; }
742 <INITIAL>{DNS_SLOW_QUERY_MS}    { count(); yylval.strval=yytext;
743                                                                 return DNS_SLOW_QUERY_MS; }
744 <INITIAL>{DNS_RETR_NO}  { count(); yylval.strval=yytext;
745                                                                 return DNS_RETR_NO; }
746 <INITIAL>{DNS_SERVERS_NO}       { count(); yylval.strval=yytext;
747                                                                 return DNS_SERVERS_NO; }
748 <INITIAL>{DNS_USE_SEARCH}       { count(); yylval.strval=yytext;
749                                                                 return DNS_USE_SEARCH; }
750 <INITIAL>{DNS_SEARCH_FMATCH}    { count(); yylval.strval=yytext;
751                                                                 return DNS_SEARCH_FMATCH; }
752 <INITIAL>{DNS_NAPTR_IGNORE_RFC} { count(); yylval.strval=yytext;
753                                                                 return DNS_NAPTR_IGNORE_RFC; }
754 <INITIAL>{DNS_CACHE_INIT}       { count(); yylval.strval=yytext;
755                                                                 return DNS_CACHE_INIT; }
756 <INITIAL>{DNS_USE_CACHE}        { count(); yylval.strval=yytext;
757                                                                 return DNS_USE_CACHE; }
758 <INITIAL>{DNS_USE_FAILOVER}     { count(); yylval.strval=yytext;
759                                                                 return DNS_USE_FAILOVER; }
760 <INITIAL>{DNS_CACHE_FLAGS}      { count(); yylval.strval=yytext;
761                                                                 return DNS_CACHE_FLAGS; }
762 <INITIAL>{DNS_CACHE_NEG_TTL}    { count(); yylval.strval=yytext;
763                                                                 return DNS_CACHE_NEG_TTL; }
764 <INITIAL>{DNS_CACHE_MIN_TTL}    { count(); yylval.strval=yytext;
765                                                                 return DNS_CACHE_MIN_TTL; }
766 <INITIAL>{DNS_CACHE_MAX_TTL}    { count(); yylval.strval=yytext;
767                                                                 return DNS_CACHE_MAX_TTL; }
768 <INITIAL>{DNS_CACHE_MEM}        { count(); yylval.strval=yytext;
769                                                                 return DNS_CACHE_MEM; }
770 <INITIAL>{DNS_CACHE_GC_INT}     { count(); yylval.strval=yytext;
771                                                                 return DNS_CACHE_GC_INT; }
772 <INITIAL>{DNS_CACHE_DEL_NONEXP} { count(); yylval.strval=yytext;
773                                                                 return DNS_CACHE_DEL_NONEXP; }
774 <INITIAL>{DNS_CACHE_REC_PREF}   { count(); yylval.strval=yytext;
775                                                                 return DNS_CACHE_REC_PREF; }
776 <INITIAL>{AUTO_BIND_IPV6}       { count(); yylval.strval=yytext;
777                                                                 return AUTO_BIND_IPV6; }
778 <INITIAL>{BIND_IPV6_LINK_LOCAL} { count(); yylval.strval=yytext;
779                                                                 return BIND_IPV6_LINK_LOCAL; }
780 <INITIAL>{DST_BLST_INIT}        { count(); yylval.strval=yytext;
781                                                                 return DST_BLST_INIT; }
782 <INITIAL>{USE_DST_BLST} { count(); yylval.strval=yytext;
783                                                                 return USE_DST_BLST; }
784 <INITIAL>{DST_BLST_MEM} { count(); yylval.strval=yytext;
785                                                                 return DST_BLST_MEM; }
786 <INITIAL>{DST_BLST_TTL} { count(); yylval.strval=yytext;
787                                                                 return DST_BLST_TTL; }
788 <INITIAL>{DST_BLST_GC_INT}      { count(); yylval.strval=yytext;
789                                                                 return DST_BLST_GC_INT; }
790 <INITIAL>{DST_BLST_UDP_IMASK}   { count(); yylval.strval=yytext;
791                                                                 return DST_BLST_UDP_IMASK; }
792 <INITIAL>{DST_BLST_TCP_IMASK}   { count(); yylval.strval=yytext;
793                                                                 return DST_BLST_TCP_IMASK; }
794 <INITIAL>{DST_BLST_TLS_IMASK}   { count(); yylval.strval=yytext;
795                                                                 return DST_BLST_TLS_IMASK; }
796 <INITIAL>{DST_BLST_SCTP_IMASK}  { count(); yylval.strval=yytext;
797                                                                 return DST_BLST_SCTP_IMASK; }
798 <INITIAL>{IP_FREE_BIND} { count(); yylval.strval=yytext; return IP_FREE_BIND; }
799 <INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
800 <INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
801 <INITIAL>{STATS_NAMESEP}        { count(); yylval.strval=yytext; return STATS_NAMESEP; }
802 <INITIAL>{MAXBUFFER}    { count(); yylval.strval=yytext; return MAXBUFFER; }
803 <INITIAL>{SQL_BUFFER_SIZE}      { count(); yylval.strval=yytext; return SQL_BUFFER_SIZE; }
804 <INITIAL>{CHILDREN}     { count(); yylval.strval=yytext; return CHILDREN; }
805 <INITIAL>{SOCKET_WORKERS}       { count(); yylval.strval=yytext; return SOCKET_WORKERS; }
806 <INITIAL>{ASYNC_WORKERS}        { count(); yylval.strval=yytext; return ASYNC_WORKERS; }
807 <INITIAL>{ASYNC_USLEEP} { count(); yylval.strval=yytext; return ASYNC_USLEEP; }
808 <INITIAL>{ASYNC_NONBLOCK}       { count(); yylval.strval=yytext; return ASYNC_NONBLOCK; }
809 <INITIAL>{CHECK_VIA}    { count(); yylval.strval=yytext; return CHECK_VIA; }
810 <INITIAL>{PHONE2TEL}    { count(); yylval.strval=yytext; return PHONE2TEL; }
811 <INITIAL>{MEMLOG}       { count(); yylval.strval=yytext; return MEMLOG; }
812 <INITIAL>{MEMDBG}       { count(); yylval.strval=yytext; return MEMDBG; }
813 <INITIAL>{MEMSUM}       { count(); yylval.strval=yytext; return MEMSUM; }
814 <INITIAL>{MEMSAFETY}    { count(); yylval.strval=yytext; return MEMSAFETY; }
815 <INITIAL>{MEMJOIN}      { count(); yylval.strval=yytext; return MEMJOIN; }
816 <INITIAL>{MEMSTATUSMODE}        { count(); yylval.strval=yytext; return MEMSTATUSMODE; }
817 <INITIAL>{CORELOG}      { count(); yylval.strval=yytext; return CORELOG; }
818 <INITIAL>{SIP_WARNING}  { count(); yylval.strval=yytext; return SIP_WARNING; }
819 <INITIAL>{USER}         { count(); yylval.strval=yytext; return USER; }
820 <INITIAL>{GROUP}        { count(); yylval.strval=yytext; return GROUP; }
821 <INITIAL>{CHROOT}       { count(); yylval.strval=yytext; return CHROOT; }
822 <INITIAL>{WDIR} { count(); yylval.strval=yytext; return WDIR; }
823 <INITIAL>{RUNDIR}       { count(); yylval.strval=yytext; return RUNDIR; }
824 <INITIAL>{MHOMED}       { count(); yylval.strval=yytext; return MHOMED; }
825 <INITIAL>{DISABLE_TCP}  { count(); yylval.strval=yytext; return DISABLE_TCP; }
826 <INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
827 <INITIAL>{TCP_ACCEPT_ALIASES}   { count(); yylval.strval=yytext;
828                                                                         return TCP_ACCEPT_ALIASES; }
829 <INITIAL>{TCP_ACCEPT_UNIQUE}    { count(); yylval.strval=yytext;
830                                                                         return TCP_ACCEPT_UNIQUE; }
831 <INITIAL>{TCP_CONNECTION_MATCH} { count(); yylval.strval=yytext;
832                                                                         return TCP_CONNECTION_MATCH; }
833 <INITIAL>{TCP_SEND_TIMEOUT}             { count(); yylval.strval=yytext;
834                                                                         return TCP_SEND_TIMEOUT; }
835 <INITIAL>{TCP_CONNECT_TIMEOUT}          { count(); yylval.strval=yytext;
836                                                                         return TCP_CONNECT_TIMEOUT; }
837 <INITIAL>{TCP_CON_LIFETIME}             { count(); yylval.strval=yytext;
838                                                                         return TCP_CON_LIFETIME; }
839 <INITIAL>{TCP_POLL_METHOD}              { count(); yylval.strval=yytext;
840                                                                         return TCP_POLL_METHOD; }
841 <INITIAL>{TCP_MAX_CONNECTIONS}  { count(); yylval.strval=yytext;
842                                                                         return TCP_MAX_CONNECTIONS; }
843 <INITIAL>{TLS_MAX_CONNECTIONS}  { count(); yylval.strval=yytext;
844                                                                         return TLS_MAX_CONNECTIONS; }
845 <INITIAL>{TCP_NO_CONNECT}               { count(); yylval.strval=yytext;
846                                                                         return TCP_NO_CONNECT; }
847 <INITIAL>{TCP_SOURCE_IPV4}              { count(); yylval.strval=yytext;
848                                                                         return TCP_SOURCE_IPV4; }
849 <INITIAL>{TCP_SOURCE_IPV6}              { count(); yylval.strval=yytext;
850                                                                         return TCP_SOURCE_IPV6; }
851 <INITIAL>{TCP_OPT_FD_CACHE}             { count(); yylval.strval=yytext;
852                                                                         return TCP_OPT_FD_CACHE; }
853 <INITIAL>{TCP_OPT_CONN_WQ_MAX}  { count(); yylval.strval=yytext;
854                                                                         return TCP_OPT_CONN_WQ_MAX; }
855 <INITIAL>{TCP_OPT_WQ_MAX}       { count(); yylval.strval=yytext;
856                                                                         return TCP_OPT_WQ_MAX; }
857 <INITIAL>{TCP_OPT_RD_BUF}       { count(); yylval.strval=yytext;
858                                                                         return TCP_OPT_RD_BUF; }
859 <INITIAL>{TCP_OPT_WQ_BLK}       { count(); yylval.strval=yytext;
860                                                                         return TCP_OPT_WQ_BLK; }
861 <INITIAL>{TCP_OPT_BUF_WRITE}    { count(); yylval.strval=yytext;
862                                                                         return TCP_OPT_BUF_WRITE; }
863 <INITIAL>{TCP_OPT_DEFER_ACCEPT} { count(); yylval.strval=yytext;
864                                                                         return TCP_OPT_DEFER_ACCEPT; }
865 <INITIAL>{TCP_OPT_DELAYED_ACK}  { count(); yylval.strval=yytext;
866                                                                         return TCP_OPT_DELAYED_ACK; }
867 <INITIAL>{TCP_OPT_SYNCNT}               { count(); yylval.strval=yytext;
868                                                                         return TCP_OPT_SYNCNT; }
869 <INITIAL>{TCP_OPT_LINGER2}              { count(); yylval.strval=yytext;
870                                                                         return TCP_OPT_LINGER2; }
871 <INITIAL>{TCP_OPT_KEEPALIVE}    { count(); yylval.strval=yytext;
872                                                                         return TCP_OPT_KEEPALIVE; }
873 <INITIAL>{TCP_OPT_KEEPIDLE}             { count(); yylval.strval=yytext;
874                                                                         return TCP_OPT_KEEPIDLE; }
875 <INITIAL>{TCP_OPT_KEEPINTVL}    { count(); yylval.strval=yytext;
876                                                                         return TCP_OPT_KEEPINTVL; }
877 <INITIAL>{TCP_OPT_KEEPCNT}      { count(); yylval.strval=yytext;
878                                                                         return TCP_OPT_KEEPCNT; }
879 <INITIAL>{TCP_OPT_CRLF_PING}    { count(); yylval.strval=yytext;
880                                                                         return TCP_OPT_CRLF_PING; }
881 <INITIAL>{TCP_OPT_ACCEPT_NO_CL} { count(); yylval.strval=yytext;
882                                                                         return TCP_OPT_ACCEPT_NO_CL; }
883 <INITIAL>{TCP_OPT_ACCEPT_HEP3}  { count(); yylval.strval=yytext;
884                                                                         return TCP_OPT_ACCEPT_HEP3; }
885 <INITIAL>{TCP_OPT_ACCEPT_HAPROXY}       { count(); yylval.strval=yytext;
886                                                                         return TCP_OPT_ACCEPT_HAPROXY; }
887 <INITIAL>{TCP_CLONE_RCVBUF}             { count(); yylval.strval=yytext;
888                                                                         return TCP_CLONE_RCVBUF; }
889 <INITIAL>{TCP_REUSE_PORT}       { count(); yylval.strval=yytext; return TCP_REUSE_PORT; }
890 <INITIAL>{DISABLE_TLS}  { count(); yylval.strval=yytext; return DISABLE_TLS; }
891 <INITIAL>{ENABLE_TLS}   { count(); yylval.strval=yytext; return ENABLE_TLS; }
892 <INITIAL>{TLSLOG}               { count(); yylval.strval=yytext; return TLS_PORT_NO; }
893 <INITIAL>{TLS_PORT_NO}  { count(); yylval.strval=yytext; return TLS_PORT_NO; }
894 <INITIAL>{TLS_METHOD}   { count(); yylval.strval=yytext; return TLS_METHOD; }
895 <INITIAL>{TLS_VERIFY}   { count(); yylval.strval=yytext; return TLS_VERIFY; }
896 <INITIAL>{TLS_REQUIRE_CERTIFICATE}      { count(); yylval.strval=yytext;
897                                                                                 return TLS_REQUIRE_CERTIFICATE; }
898 <INITIAL>{TLS_CERTIFICATE}      { count(); yylval.strval=yytext;
899                                                                                 return TLS_CERTIFICATE; }
900 <INITIAL>{TLS_PRIVATE_KEY}      { count(); yylval.strval=yytext;
901                                                                                 return TLS_PRIVATE_KEY; }
902 <INITIAL>{TLS_CA_LIST}  { count(); yylval.strval=yytext;
903                                                                                 return TLS_CA_LIST; }
904 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}        { count(); yylval.strval=yytext;
905                                                                                 return TLS_HANDSHAKE_TIMEOUT; }
906 <INITIAL>{TLS_SEND_TIMEOUT}     { count(); yylval.strval=yytext;
907                                                                                 return TLS_SEND_TIMEOUT; }
908 <INITIAL>{DISABLE_SCTP} { count(); yylval.strval=yytext; return DISABLE_SCTP;}
909 <INITIAL>{ENABLE_SCTP}  { count(); yylval.strval=yytext; return ENABLE_SCTP;}
910 <INITIAL>{SCTP_CHILDREN}        { count(); yylval.strval=yytext;
911                                                                                 return SCTP_CHILDREN; }
912 <INITIAL>{SERVER_SIGNATURE}     { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
913 <INITIAL>{SERVER_HEADER}        { count(); yylval.strval=yytext; return SERVER_HEADER; }
914 <INITIAL>{USER_AGENT_HEADER}    { count(); yylval.strval=yytext; return USER_AGENT_HEADER; }
915 <INITIAL>{REPLY_TO_VIA} { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
916 <INITIAL>{ADVERTISED_ADDRESS}   {       count(); yylval.strval=yytext;
917                                                                         return ADVERTISED_ADDRESS; }
918 <INITIAL>{ADVERTISED_PORT}              {       count(); yylval.strval=yytext;
919                                                                         return ADVERTISED_PORT; }
920 <INITIAL>{DISABLE_CORE}         {       count(); yylval.strval=yytext;
921                                                                         return DISABLE_CORE; }
922 <INITIAL>{OPEN_FD_LIMIT}                {       count(); yylval.strval=yytext;
923                                                                         return OPEN_FD_LIMIT; }
924 <INITIAL>{SHM_MEM_SZ}           {       count(); yylval.strval=yytext;
925                                                                         return SHM_MEM_SZ; }
926 <INITIAL>{SHM_FORCE_ALLOC}              {       count(); yylval.strval=yytext;
927                                                                         return SHM_FORCE_ALLOC; }
928 <INITIAL>{MLOCK_PAGES}          {       count(); yylval.strval=yytext;
929                                                                         return MLOCK_PAGES; }
930 <INITIAL>{REAL_TIME}            {       count(); yylval.strval=yytext;
931                                                                         return REAL_TIME; }
932 <INITIAL>{RT_PRIO}              {       count(); yylval.strval=yytext;
933                                                                         return RT_PRIO; }
934 <INITIAL>{RT_POLICY}            {       count(); yylval.strval=yytext;
935                                                                         return RT_POLICY; }
936 <INITIAL>{RT_TIMER1_PRIO}               {       count(); yylval.strval=yytext;
937                                                                         return RT_TIMER1_PRIO; }
938 <INITIAL>{RT_TIMER1_POLICY}             {       count(); yylval.strval=yytext;
939                                                                         return RT_TIMER1_POLICY; }
940 <INITIAL>{RT_TIMER2_PRIO}               {       count(); yylval.strval=yytext;
941                                                                         return RT_TIMER2_PRIO; }
942 <INITIAL>{RT_TIMER2_POLICY}             {       count(); yylval.strval=yytext;
943                                                                         return RT_TIMER2_POLICY; }
944 <INITIAL>{MCAST_LOOPBACK}               {       count(); yylval.strval=yytext;
945                                                                         return MCAST_LOOPBACK; }
946 <INITIAL>{MCAST_TTL}            {       count(); yylval.strval=yytext;
947                                                                         return MCAST_TTL; }
948 <INITIAL>{MCAST}                {       count(); yylval.strval=yytext;
949                                                                         return MCAST; }
950 <INITIAL>{TOS}                  {       count(); yylval.strval=yytext;
951                                                                         return TOS; }
952 <INITIAL>{PMTU_DISCOVERY}               {       count(); yylval.strval=yytext;
953                                                                         return PMTU_DISCOVERY; }
954 <INITIAL>{KILL_TIMEOUT}                 {       count(); yylval.strval=yytext;
955                                                                         return KILL_TIMEOUT; }
956 <INITIAL>{MAX_WLOOPS}                   {       count(); yylval.strval=yytext;
957                                                                         return MAX_WLOOPS; }
958 <INITIAL>{PVBUFSIZE}                    {       count(); yylval.strval=yytext;
959                                                                         return PVBUFSIZE; }
960 <INITIAL>{PVBUFSLOTS}                   {       count(); yylval.strval=yytext;
961                                                                         return PVBUFSLOTS; }
962 <INITIAL>{PVCACHELIMIT}                 {       count(); yylval.strval=yytext;
963                                                                         return PVCACHELIMIT; }
964 <INITIAL>{PVCACHEACTION}                {       count(); yylval.strval=yytext;
965                                                                         return PVCACHEACTION; }
966 <INITIAL>{HTTP_REPLY_PARSE}             {       count(); yylval.strval=yytext;
967                                                                         return HTTP_REPLY_PARSE; }
968 <INITIAL>{VERSION_TABLE_CFG}  { count(); yylval.strval=yytext; return VERSION_TABLE_CFG;}
969 <INITIAL>{VERBOSE_STARTUP}              {       count(); yylval.strval=yytext;
970                                                                         return VERBOSE_STARTUP; }
971 <INITIAL>{ROUTE_LOCKS_SIZE}  { count(); yylval.strval=yytext; return ROUTE_LOCKS_SIZE; }
972 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
973 <INITIAL>{KEMI}  { count(); yylval.strval=yytext; return KEMI;}
974 <INITIAL>{REPLY_ROUTE_CALLBACK}  { count(); yylval.strval=yytext; return REPLY_ROUTE_CALLBACK;}
975 <INITIAL>{ONSEND_ROUTE_CALLBACK}  { count(); yylval.strval=yytext; return ONSEND_ROUTE_CALLBACK;}
976 <INITIAL>{EVENT_ROUTE_CALLBACK}  { count(); yylval.strval=yytext; return EVENT_ROUTE_CALLBACK;}
977 <INITIAL>{RECEIVED_ROUTE_CALLBACK}  { count(); yylval.strval=yytext; return RECEIVED_ROUTE_CALLBACK;}
978 <INITIAL>{RECEIVED_ROUTE_MODE}  { count(); yylval.strval=yytext; return RECEIVED_ROUTE_MODE;}
979 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
980 <INITIAL>{MAX_BRANCHES_PARAM}  { count(); yylval.strval=yytext; return MAX_BRANCHES_PARAM;}
981 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
982 <INITIAL>{LATENCY_CFG_LOG}  { count(); yylval.strval=yytext; return LATENCY_CFG_LOG;}
983 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
984 <INITIAL>{ONSEND_RT_REPLY}      { count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
985 <INITIAL>{LATENCY_LIMIT_DB}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
986 <INITIAL>{LATENCY_LIMIT_ACTION}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_ACTION;}
987 <INITIAL>{LATENCY_LIMIT_CFG}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_CFG;}
988 <INITIAL>{CFG_DESCRIPTION}      { count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
989 <INITIAL>{LOADMODULE}   { count(); yylval.strval=yytext; return LOADMODULE; }
990 <INITIAL>{LOADPATH}             { count(); yylval.strval=yytext; return LOADPATH; }
991 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
992 <INITIAL>{CFGENGINE}    { count(); yylval.strval=yytext; return CFGENGINE; }
993 <INITIAL>{URI_HOST_EXTRA_CHARS} { yylval.strval=yytext; return URI_HOST_EXTRA_CHARS; }
994
995 <INITIAL>{EQUAL}        { count(); return EQUAL; }
996 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
997 <INITIAL>{EQUAL_T}      { count(); return EQUAL_T; }
998 <INITIAL>{GT}   { count(); return GT; }
999 <INITIAL>{LT}   { count(); return LT; }
1000 <INITIAL>{GTE}  { count(); return GTE; }
1001 <INITIAL>{LTE}  { count(); return LTE; }
1002 <INITIAL>{DIFF} { count(); return DIFF; }
1003 <INITIAL>{MATCH}        { count(); return MATCH; }
1004 <INITIAL>{NOT}          { count(); return NOT; }
1005 <INITIAL>{LOG_AND}      { count(); return LOG_AND; }
1006 <INITIAL>{BIN_AND}      { count(); return BIN_AND; }
1007 <INITIAL>{LOG_OR}       { count(); return LOG_OR;  }
1008 <INITIAL>{BIN_OR}       { count(); return BIN_OR;  }
1009 <INITIAL>{BIN_NOT}      { count(); return BIN_NOT;  }
1010 <INITIAL>{BIN_XOR}      { count(); return BIN_XOR;  }
1011 <INITIAL>{BIN_LSHIFT}   { count(); return BIN_LSHIFT;  }
1012 <INITIAL>{BIN_RSHIFT}   { count(); return BIN_RSHIFT;  }
1013 <INITIAL>{PLUS}         { count(); return PLUS; }
1014 <INITIAL>{MINUS}        { count(); return MINUS; }
1015 <INITIAL>{MODULO}       { count(); return MODULO; }
1016 <INITIAL>{STRLEN}       { count(); return STRLEN; }
1017 <INITIAL>{STREMPTY}     { count(); return STREMPTY; }
1018 <INITIAL>{DEFINED}      { count(); return DEFINED; }
1019 <INITIAL>{STREQ}        { count(); return STREQ; }
1020 <INITIAL>{INTEQ}        { count(); return INTEQ; }
1021 <INITIAL>{STRDIFF}      { count(); return STRDIFF; }
1022 <INITIAL>{INTDIFF}      { count(); return INTDIFF; }
1023 <INITIAL>{INTCAST}      { count(); return INTCAST; }
1024 <INITIAL>{STRCAST}      { count(); return STRCAST; }
1025
1026 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
1027 <SELECT>{ID}            { count(); addstr(&s_buf, yytext, yyleng);
1028                                                 yylval.strval=s_buf.s;
1029                                                 memset(&s_buf, 0, sizeof(s_buf));
1030                                                 return ID;
1031                                         }
1032 <SELECT>{DOT}           { count(); return DOT; }
1033 <SELECT>{LBRACK}        { count(); return LBRACK; }
1034 <SELECT>{RBRACK}        { count(); return RBRACK; }
1035 <SELECT>{DECNUMBER}     { count(); yylval.intval=atoi(yytext);
1036                                                 yy_number_str=yytext; return NUMBER; }
1037 <SELECT>{HEXNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 16);
1038                                                 yy_number_str=yytext; return NUMBER; }
1039 <SELECT>{OCTNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 8);
1040                                                 yy_number_str=yytext; return NUMBER; }
1041 <SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2);
1042                                                 yy_number_str=yytext; return NUMBER; }
1043
1044
1045 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
1046                                                         return ATTR_MARK; }
1047 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
1048 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
1049 <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
1050 <ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
1051 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
1052 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
1053 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
1054 <ATTR>{ATTR_TODOMAIN}   { count(); return ATTR_TODOMAIN; }
1055 <ATTR>{ATTR_GLOBAL}     { count(); return ATTR_GLOBAL; }
1056 <ATTR>{DOT}             { count(); return DOT; }
1057 <ATTR>{LBRACK}          { count(); return LBRACK; }
1058 <ATTR>{RBRACK}          { count(); return RBRACK; }
1059 <ATTR>{STAR}                    { count(); return STAR; }
1060 <ATTR>{DECNUMBER}               { count(); yylval.intval=atoi(yytext);
1061                                                         yy_number_str=yytext; return NUMBER; }
1062 <ATTR>{ID}                              { count(); addstr(&s_buf, yytext, yyleng);
1063                                                         yylval.strval=s_buf.s;
1064                                                         memset(&s_buf, 0, sizeof(s_buf));
1065                                                         state = INITIAL_S;
1066                                                         BEGIN(INITIAL);
1067                                                         return ID;
1068                                                 }
1069
1070 <INITIAL>{VAR_MARK}{LPAREN}     {
1071                                                                 switch(sr_cfg_compat){
1072                                                                         case SR_COMPAT_SER:
1073                                                                                 state=ATTR_S; BEGIN(ATTR);
1074                                                                                 yyless(1);
1075                                                                                 count();
1076                                                                                 return ATTR_MARK;
1077                                                                                 break;
1078                                                                         case SR_COMPAT_KAMAILIO:
1079                                                                         case SR_COMPAT_MAX:
1080                                                                         default:
1081                                                                                 state = PVAR_P_S; BEGIN(PVAR_P);
1082                                                                                 p_nest=1; yymore();
1083                                                                                 break;
1084                                                                 }
1085                                                         }
1086         /* eat everything between 2 () and return PVAR token and a string
1087          * containing everything (including $ and ()) */
1088 <PVAR_P>{RPAREN}                        {       p_nest--;
1089                                                                 if (p_nest==0){
1090                                                                         count();
1091                                                                         addstr(&s_buf, yytext, yyleng);
1092                                                                         r = pp_subst_run(&s_buf.s);
1093                                                                         yylval.strval=s_buf.s;
1094                                                                         memset(&s_buf, 0, sizeof(s_buf));
1095                                                                         state=INITIAL_S;
1096                                                                         BEGIN(INITIAL);
1097                                                                         return PVAR;
1098                                                                 }
1099                                                                 yymore();
1100                                                         }
1101 <PVAR_P>{LPAREN}                        { p_nest++; yymore(); }
1102 <PVAR_P>.                                       { yymore(); }
1103
1104 <PVARID>{ID}|'\.'                       {yymore(); }
1105 <PVARID>{LPAREN}                        {       state = PVAR_P_S; BEGIN(PVAR_P);
1106                                                                 p_nest=1; yymore(); }
1107 <PVARID>{CR}|{EAT_ABLE}|.       {       yyless(yyleng-1);
1108                                                                 count();
1109                                                                 addstr(&s_buf, yytext, yyleng);
1110                                                                 r = pp_subst_run(&s_buf.s);
1111                                                                 yylval.strval=s_buf.s;
1112                                                                 memset(&s_buf, 0, sizeof(s_buf));
1113                                                                 state=INITIAL_S;
1114                                                                 BEGIN(INITIAL);
1115                                                                 return PVAR;
1116                                                         }
1117
1118         /* if found retcode => it's a built-in pvar */
1119 <INITIAL>{RETCODE}                      { count(); yylval.strval=yytext; return PVAR; }
1120
1121 <INITIAL>{VAR_MARK}                     {
1122                                                                 switch(sr_cfg_compat){
1123                                                                         case SR_COMPAT_SER:
1124                                                                                 count();
1125                                                                                 state=ATTR_S; BEGIN(ATTR);
1126                                                                                 return ATTR_MARK;
1127                                                                                 break;
1128                                                                         case SR_COMPAT_KAMAILIO:
1129                                                                                 state=PVARID_S; BEGIN(PVARID);
1130                                                                                 yymore();
1131                                                                                 break;
1132                                                                         case SR_COMPAT_MAX:
1133                                                                         default:
1134                                                                                 state=AVP_PVAR_S; BEGIN(AVP_PVAR);
1135                                                                                 yymore();
1136                                                                                 break;
1137                                                                 }
1138                                                         }
1139         /* avp prefix detected -> go to avp mode */
1140 <AVP_PVAR>{AVP_PREF}            |
1141 <AVP_PVAR>{ID}{LBRACK}          { state = ATTR_S; BEGIN(ATTR); yyless(1); count();
1142                                                                 return ATTR_MARK; }
1143 <AVP_PVAR>{ID}{LPAREN}          { state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
1144                                                                 yymore(); }
1145 <AVP_PVAR>{ID}                          {       count(); addstr(&s_buf, yytext, yyleng);
1146                                                                 yylval.strval=s_buf.s;
1147                                                                 memset(&s_buf, 0, sizeof(s_buf));
1148                                                                 state = INITIAL_S;
1149                                                                 BEGIN(INITIAL);
1150                                                                 return AVP_OR_PVAR;
1151                                                         }
1152
1153 <INITIAL>{IPV6ADDR}             { count(); yylval.strval=yytext; return IPV6ADDR; }
1154 <INITIAL>{DECNUMBER}    { count(); yylval.intval=atoi(yytext);
1155                                                                 yy_number_str=yytext; return NUMBER; }
1156 <INITIAL>{HEXNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 16);
1157                                                         yy_number_str=yytext; return NUMBER; }
1158 <INITIAL>{OCTNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 8);
1159                                                         yy_number_str=yytext; return NUMBER; }
1160 <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2);
1161                                                         yy_number_str=yytext; return NUMBER; }
1162 <INITIAL>{YES}                  { count(); yylval.intval=1;
1163                                                         yy_number_str=yytext; return NUMBER; }
1164 <INITIAL>{NO}                   { count(); yylval.intval=0;
1165                                                         yy_number_str=yytext; return NUMBER; }
1166 <INITIAL>{TCP}                  { count(); return TCP; }
1167 <INITIAL>{UDP}                  { count(); return UDP; }
1168 <INITIAL>{TLS}                  { count(); return TLS; }
1169 <INITIAL>{SCTP}                 { count(); return SCTP; }
1170 <INITIAL>{WS}                   { count(); return WS; }
1171 <INITIAL>{WSS}                  { count(); return WSS; }
1172 <INITIAL>{INET}                 { count(); yylval.intval=AF_INET;
1173                                                         yy_number_str=yytext; return NUMBER; }
1174 <INITIAL>{INET6}                { count();
1175                                                 yylval.intval=AF_INET6;
1176                                                 yy_number_str=yytext;
1177                                                 return NUMBER; }
1178 <INITIAL>{SSLv23}               { count(); yylval.strval=yytext; return SSLv23; }
1179 <INITIAL>{SSLv2}                { count(); yylval.strval=yytext; return SSLv2; }
1180 <INITIAL>{SSLv3}                { count(); yylval.strval=yytext; return SSLv3; }
1181 <INITIAL>{TLSv1}                { count(); yylval.strval=yytext; return TLSv1; }
1182
1183 <INITIAL>{COMMA}                { count(); return COMMA; }
1184 <INITIAL>{SEMICOLON}    { count(); return SEMICOLON; }
1185 <INITIAL>{COLON}        { count(); return COLON; }
1186 <INITIAL>{STAR}         { count(); return STAR; }
1187 <INITIAL>{RPAREN}       { count(); return RPAREN; }
1188 <INITIAL>{LPAREN}       { count(); return LPAREN; }
1189 <INITIAL>{LBRACE}       { count(); return LBRACE; }
1190 <INITIAL>{RBRACE}       { count(); return RBRACE; }
1191 <INITIAL>{LBRACK}       { count(); return LBRACK; }
1192 <INITIAL>{RBRACK}       { count(); return RBRACK; }
1193 <INITIAL>{SLASH}        { count(); return SLASH; }
1194 <INITIAL>{DOT}          { count(); return DOT; }
1195 <INITIAL>\\{CR}         {count(); } /* eat the escaped CR */
1196 <INITIAL>{CR}           { count();/* return CR;*/ }
1197
1198
1199 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START;
1200                                                         old_state = state; state=STRING_S;
1201                                                         BEGIN(STRING1); }
1202 <INITIAL>{TICK} { count(); old_initial = YY_START; old_state = state;
1203                                         state=STRING_S; BEGIN(STRING2); }
1204
1205
1206 <STRING1>{QUOTES} { count_more();
1207                                                 yytext[yyleng-1]=0; yyleng--;
1208                                                 addstr(&s_buf, yytext, yyleng);
1209                                                 state=STR_BETWEEN_S;
1210                                                 BEGIN(STR_BETWEEN);
1211                                         }
1212 <STRING2>{TICK}  { count_more(); state=old_state; BEGIN(old_initial);
1213                                                 yytext[yyleng-1]=0; yyleng--;
1214                                                 addstr(&s_buf, yytext, yyleng);
1215                                                 r = pp_subst_run(&s_buf.s);
1216                                                 yylval.strval=s_buf.s;
1217                                                 memset(&s_buf, 0, sizeof(s_buf));
1218                                                 return STRING;
1219                                         }
1220 <STRING2>.|{EAT_ABLE}|{CR}      { yymore(); }
1221
1222 <STRING1>\\n            { count_more(); addchar(&s_buf, '\n'); }
1223 <STRING1>\\r            { count_more(); addchar(&s_buf, '\r'); }
1224 <STRING1>\\a            { count_more(); addchar(&s_buf, '\a'); }
1225 <STRING1>\\t            { count_more(); addchar(&s_buf, '\t'); }
1226 <STRING1>\\{QUOTES}     { count_more(); addchar(&s_buf, '"');  }
1227 <STRING1>\\\\           { count_more(); addchar(&s_buf, '\\'); }
1228 <STRING1>\\x{HEX}{1,2}  { count_more(); addchar(&s_buf,
1229                                                                                         (char)strtol(yytext+2, 0, 16)); }
1230         /* don't allow \[0-7]{1}, it will eat the backreferences from
1231          * subst_uri if allowed (although everybody should use '' in subt_uri) */
1232 <STRING1>\\[0-7]{2,3}   { count_more(); addchar(&s_buf,
1233                                                                                         (char)strtol(yytext+1, 0, 8));  }
1234 <STRING1>\\{CR}         { count_more(); } /* eat escaped CRs */
1235 <STRING1>.|{EAT_ABLE}|{CR}      { count_more(); addchar(&s_buf, *yytext); }
1236
1237 <STR_BETWEEN>{EAT_ABLE}|{CR}    { count_ignore(); }
1238 <STR_BETWEEN>{QUOTES}                   { count_more(); state=STRING_S;
1239                                                                         BEGIN(STRING1);}
1240 <STR_BETWEEN>.                                  {
1241                                                                         yyless(0); /* reparse it */
1242                                                                         /* ignore the whitespace now that is
1243                                                                          * counted, return saved string value */
1244                                                                         state=old_state; BEGIN(old_initial);
1245                                                                         r = pp_subst_run(&s_buf.s);
1246                                                                         yylval.strval=s_buf.s;
1247                                                                         memset(&s_buf, 0, sizeof(s_buf));
1248                                                                         return STRING;
1249                                                                 }
1250
1251 <INITIAL,COMMENT>{COM_START}    { count(); comment_nest++; state=COMMENT_S;
1252                                                                                 BEGIN(COMMENT); }
1253 <COMMENT>{COM_END}                              { count(); comment_nest--;
1254                                                                                 if (comment_nest==0){
1255                                                                                         state=INITIAL_S;
1256                                                                                         BEGIN(INITIAL);
1257                                                                                 }
1258                                                                 }
1259 <COMMENT>.|{EAT_ABLE}|{CR}                              { count(); };
1260
1261 <INITIAL>{COM_LINE}!{SER_CFG}{CR}               { count();
1262                                                                                         sr_cfg_compat=SR_COMPAT_SER;}
1263 <INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}  { count();
1264                                                                                         sr_cfg_compat=SR_COMPAT_KAMAILIO;}
1265 <INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR} { count();
1266                                                                                                 sr_cfg_compat=SR_COMPAT_MAX;}
1267
1268 <INITIAL>{PREP_START}{DEFINE}{EAT_ABLE}+        {       count(); pp_define_set_type(0);
1269                                                                                         state = DEFINE_S; BEGIN(DEFINE_ID); }
1270 <INITIAL>{PREP_START}{TRYDEF}{EAT_ABLE}+        {       count(); pp_define_set_type(1);
1271                                                                                         state = DEFINE_S; BEGIN(DEFINE_ID); }
1272 <INITIAL>{PREP_START}{REDEF}{EAT_ABLE}+ {       count(); pp_define_set_type(2);
1273                                                                                         state = DEFINE_S; BEGIN(DEFINE_ID); }
1274 <DEFINE_ID>{ID}{MINUS}          {       count();
1275                                                                         LM_CRIT(
1276                                                                                 "error at %s line %d: '-' not allowed\n",
1277                                                                                 (finame)?finame:"cfg", line);
1278                                                                         ksr_exit(-1);
1279                                                                 }
1280 <DEFINE_ID>{ID}                 {       count();
1281                                                                         if (pp_define(yyleng, yytext)) return 1;
1282                                                                         state = DEFINE_EOL_S; BEGIN(DEFINE_EOL); }
1283 <DEFINE_EOL>{EAT_ABLE}                  {       count(); }
1284 <DEFINE_EOL>{CR}                                {       count();
1285                                                                         state = INITIAL; BEGIN(INITIAL); }
1286 <DEFINE_EOL>.                   {       count();
1287                                                                         addstr(&s_buf, yytext, yyleng);
1288                                                                         state = DEFINE_DATA_S; BEGIN(DEFINE_DATA); }
1289 <DEFINE_DATA>\\{CR}             {       count(); } /* eat the escaped CR */
1290 <DEFINE_DATA>{CR}               {       count();
1291                                                         if (pp_define_set(strlen(s_buf.s), s_buf.s)) return 1;
1292                                                         memset(&s_buf, 0, sizeof(s_buf));
1293                                                         state = INITIAL; BEGIN(INITIAL); }
1294 <DEFINE_DATA>.          {       count();
1295                                                         addstr(&s_buf, yytext, yyleng); }
1296
1297 <INITIAL>{PREP_START}{SUBST}    { count();  return SUBST;}
1298 <INITIAL>{PREP_START}{SUBSTDEF} { count();  return SUBSTDEF;}
1299 <INITIAL>{PREP_START}{SUBSTDEFS}        { count();  return SUBSTDEFS;}
1300
1301 <INITIAL,IFDEF_SKIP>{PREP_START}{IFDEF}{EAT_ABLE}+    { count();
1302                                                                 if (pp_ifdef_type(1)) return 1;
1303                                                                 state = IFDEF_S; BEGIN(IFDEF_ID); }
1304 <INITIAL,IFDEF_SKIP>{PREP_START}{IFNDEF}{EAT_ABLE}+    { count();
1305                                                                 if (pp_ifdef_type(0)) return 1;
1306                                                                 state = IFDEF_S; BEGIN(IFDEF_ID); }
1307 <IFDEF_ID>{ID}{MINUS}           { count();
1308                                                                         LM_CRIT(
1309                                                                                 "error at %s line %d: '-' not allowed\n",
1310                                                                                 (finame)?finame:"cfg", line);
1311                                                                         ksr_exit(-1);
1312                                                                 }
1313 <IFDEF_ID>{ID}                { count();
1314                                                                 pp_ifdef_var(yyleng, yytext);
1315                                                                 state = IFDEF_EOL_S; BEGIN(IFDEF_EOL); }
1316 <IFDEF_EOL>{EAT_ABLE}*{CR}    { count(); pp_ifdef(); }
1317
1318 <INITIAL,IFDEF_SKIP>{PREP_START}{ELSE}{EAT_ABLE}*{CR}    { count(); pp_else(); }
1319
1320 <INITIAL,IFDEF_SKIP>{PREP_START}{ENDIF}{EAT_ABLE}*{CR}    { count();
1321                                                                                                                         pp_endif(); }
1322
1323         /* we're in an ifdef that evaluated to false -- throw it away */
1324 <IFDEF_SKIP>.|{CR}    { count(); }
1325
1326         /* this is split so the shebangs match more, giving them priority */
1327 <INITIAL>{COM_LINE}        { count(); state = LINECOMMENT_S;
1328                                                                 BEGIN(LINECOMMENT); }
1329 <LINECOMMENT>.*{CR}        { count(); state = INITIAL_S; BEGIN(INITIAL); }
1330
1331 <INITIAL>{ID}           {       if ((sdef = pp_define_get(yyleng, yytext))!=NULL) {
1332                                                         for (r=sdef->len-1; r>=0; r--)
1333                                                                 unput(sdef->s[r]); /* reverse order */
1334                                                 } else {
1335                                                         count();
1336                                                         addstr(&s_buf, yytext, yyleng);
1337                                                         yylval.strval=s_buf.s;
1338                                                         memset(&s_buf, 0, sizeof(s_buf));
1339                                                         return ID;
1340                                                 }
1341                                         }
1342 <INITIAL>{NUM_ID}                       { count(); addstr(&s_buf, yytext, yyleng);
1343                                                                         yylval.strval=s_buf.s;
1344                                                                         memset(&s_buf, 0, sizeof(s_buf));
1345                                                                         return NUM_ID; }
1346
1347 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); }
1348                                                         /* Rescan the token in INITIAL state */
1349
1350 <INCLF>[ \t]*      /* eat the whitespace */
1351 <INCLF>[^ \t\r\n]+   { /* get the include file name */
1352                                 memset(&s_buf, 0, sizeof(s_buf));
1353                                 addstr(&s_buf, yytext, yyleng);
1354                                 r = pp_subst_run(&s_buf.s);
1355                                 if(sr_push_yy_state(s_buf.s, 0)<0)
1356                                 {
1357                                         LOG(L_CRIT, "error at %s line %d\n", (finame)?finame:"cfg", line);
1358                                         ksr_exit(-1);
1359                                 }
1360                                 memset(&s_buf, 0, sizeof(s_buf));
1361                                 BEGIN(INITIAL);
1362 }
1363
1364 <IMPTF>[ \t]*      /* eat the whitespace */
1365 <IMPTF>[^ \t\r\n]+   { /* get the import file name */
1366                                 memset(&s_buf, 0, sizeof(s_buf));
1367                                 addstr(&s_buf, yytext, yyleng);
1368                                 r = pp_subst_run(&s_buf.s);
1369                                 if(sr_push_yy_state(s_buf.s, 1)<0)
1370                                 {
1371                                         LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1372                                         ksr_exit(-1);
1373                                 }
1374                                 memset(&s_buf, 0, sizeof(s_buf));
1375                                 BEGIN(INITIAL);
1376 }
1377
1378
1379 <<EOF>>                                                 {
1380                                                                         switch(state){
1381                                                                                 case STR_BETWEEN_S:
1382                                                                                         state=old_state;
1383                                                                                         BEGIN(old_initial);
1384                                                                                         r = pp_subst_run(&s_buf.s);
1385                                                                                         yylval.strval=s_buf.s;
1386                                                                                         memset(&s_buf, 0, sizeof(s_buf));
1387                                                                                         return STRING;
1388                                                                                 case STRING_S:
1389                                                                                         LM_CRIT("cfg. parser: unexpected EOF in"
1390                                                                                                                 " unclosed string\n");
1391                                                                                         if (s_buf.s){
1392                                                                                                 pkg_free(s_buf.s);
1393                                                                                                 memset(&s_buf, 0,
1394                                                                                                                         sizeof(s_buf));
1395                                                                                         }
1396                                                                                         break;
1397                                                                                 case COMMENT_S:
1398                                                                                         LM_CRIT("cfg. parser: unexpected EOF:"
1399                                                                                                                 " %d comments open\n", comment_nest);
1400                                                                                         break;
1401                                                                                 case COMMENT_LN_S:
1402                                                                                         LM_CRIT("unexpected EOF:"
1403                                                                                                                 "comment line open\n");
1404                                                                                         break;
1405                                                                                 case  ATTR_S:
1406                                                                                         LM_CRIT("unexpected EOF"
1407                                                                                                         " while parsing"
1408                                                                                                         " avp name\n");
1409                                                                                         break;
1410                                                                                 case PVARID_S:
1411                                                                                         p_nest=0;
1412                                                                                 case PVAR_P_S:
1413                                                                                         LM_CRIT("unexpected EOF"
1414                                                                                                         " while parsing pvar name"
1415                                                                                                         " (%d parenthesis open)\n",
1416                                                                                                         p_nest);
1417                                                                                         break;
1418                                                                                 case AVP_PVAR_S:
1419                                                                                         LM_CRIT("unexpected EOF"
1420                                                                                                         " while parsing"
1421                                                                                                         " avp or pvar name\n");
1422                                                                         }
1423                                                                         if(sr_pop_yy_state()<0)
1424                                                                                 return 0;
1425                                                                 }
1426
1427 %%
1428
1429
1430 static char* addchar(struct str_buf* dst, char c)
1431 {
1432         return addstr(dst, &c, 1);
1433 }
1434
1435
1436
1437 static char* addstr(struct str_buf* dst_b, char* src, int len)
1438 {
1439         char *tmp;
1440         unsigned size;
1441         unsigned used;
1442
1443         if (dst_b->left<(len+1)){
1444                 used=(unsigned)(dst_b->crt-dst_b->s);
1445                 size=used+len+1;
1446                 /* round up to next multiple */
1447                 size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
1448                 tmp=pkg_malloc(size);
1449                 if (tmp==0) goto error;
1450                 if (dst_b->s){
1451                         memcpy(tmp, dst_b->s, used);
1452                         pkg_free(dst_b->s);
1453                 }
1454                 dst_b->s=tmp;
1455                 dst_b->crt=dst_b->s+used;
1456                 dst_b->left=size-used;
1457         }
1458         memcpy(dst_b->crt, src, len);
1459         dst_b->crt+=len;
1460         *(dst_b->crt)=0;
1461         dst_b->left-=len;
1462
1463         return dst_b->s;
1464 error:
1465         PKG_MEM_CRITICAL;
1466         ksr_exit(-1);
1467 }
1468
1469
1470
1471 /** helper function for count_*(). */
1472 static void count_lc(int* l, int* c)
1473 {
1474         int i;
1475         for (i=0; i<yyleng;i++){
1476                 if (yytext[i]=='\n'){
1477                         (*l)++;
1478                         (*c)=1;
1479                 }else if (yytext[i]=='\t'){
1480                         (*c)++;
1481                         /*(*c)+=8 -((*c)%8);*/
1482                 }else{
1483                         (*c)++;
1484                 }
1485         }
1486 }
1487
1488
1489
1490 /* helper function */
1491 static void count_restore_ignored()
1492 {
1493         if (ign_lines) /* ignored line(s) => column has changed */
1494                 column=ign_columns;
1495         else
1496                 column+=ign_columns;
1497         line+=ign_lines;
1498         ign_lines=ign_columns=0;
1499 }
1500
1501
1502
1503 /** count/record position for stuff added to the current token. */
1504 static void count_more()
1505 {
1506         count_restore_ignored();
1507         count_lc(&line, &column);
1508 }
1509
1510
1511
1512 /** count/record position for a new token. */
1513 static void count()
1514 {
1515         count_restore_ignored();
1516         startline=line;
1517         startcolumn=column;
1518         count_more();
1519 }
1520
1521
1522
1523 /** record discarded stuff (not contained in the token) so that
1524  * the next token position can be adjusted properly */
1525 static void count_ignore()
1526 {
1527         count_lc(&ign_lines, &ign_columns);
1528 }
1529
1530
1531 /* replacement yywrap, removes libfl dependency */
1532 int yywrap()
1533 {
1534         return 1;
1535 }
1536
1537 static int sr_push_yy_state(char *fin, int mode)
1538 {
1539         struct sr_yy_fname *fn = NULL;
1540         FILE *fp = NULL;
1541         char *x = NULL;
1542         char *newf = NULL;
1543 #define MAX_INCLUDE_FNAME       128
1544         char fbuf[MAX_INCLUDE_FNAME];
1545         int i, j, l;
1546         char *tmpfiname = 0;
1547
1548         if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
1549         {
1550                 LM_CRIT("too many includes\n");
1551                 return -1;
1552         }
1553         l = strlen(fin);
1554         if(l>=MAX_INCLUDE_FNAME)
1555         {
1556                 LM_CRIT("included file name too long: %s\n", fin);
1557                 return -1;
1558         }
1559         if(fin[0]!='"' || fin[l-1]!='"')
1560         {
1561                 LM_CRIT("included file name must be between quotes: %s\n", fin);
1562                 return -1;
1563         }
1564         j = 0;
1565         for(i=1; i<l-1; i++)
1566         {
1567                 switch(fin[i]) {
1568                         case '\\':
1569                                 if(i+1==l-1)
1570                                 {
1571                                         LM_CRIT("invalid escape at %d in included file name: %s\n", i, fin);
1572                                         return -1;
1573                                 }
1574                                 i++;
1575                                 switch(fin[i]) {
1576                                         case 't':
1577                                                 fbuf[j++] = '\t';
1578                                         break;
1579                                         case 'n':
1580                                                 fbuf[j++] = '\n';
1581                                         break;
1582                                         case 'r':
1583                                                 fbuf[j++] = '\r';
1584                                         break;
1585                                         default:
1586                                                 fbuf[j++] = fin[i];
1587                                 }
1588                         break;
1589                         default:
1590                                 fbuf[j++] = fin[i];
1591                 }
1592         }
1593         if(j==0)
1594         {
1595                 LM_CRIT("invalid included file name: %s\n", fin);
1596                 return -1;
1597         }
1598         fbuf[j] = '\0';
1599
1600         fp = fopen(fbuf, "r" );
1601
1602         if ( ! fp )
1603         {
1604                 tmpfiname = (finame==0)?cfg_file:finame;
1605                 if(tmpfiname==0 || fbuf[0]=='/')
1606                 {
1607                         if(mode==0)
1608                         {
1609                                 LM_CRIT("cannot open included file: %s\n", fin);
1610                                 return -1;
1611                         } else {
1612                                 LM_DBG("importing file ignored: %s\n", fin);
1613                                 return 0;
1614                         }
1615                 }
1616                 x = strrchr(tmpfiname, '/');
1617                 if(x==NULL)
1618                 {
1619                         /* nothing else to try */
1620                         if(mode==0)
1621                         {
1622                                 LM_CRIT("cannot open included file: %s\n", fin);
1623                                 return -1;
1624                         } else {
1625                                 LM_DBG("importing file ignored: %s\n", fin);
1626                                 return 0;
1627                         }
1628                 }
1629
1630                 newf = (char*)pkg_malloc(x-tmpfiname+strlen(fbuf)+2);
1631                 if(newf==0)
1632                 {
1633                         PKG_MEM_CRITICAL;
1634                         return -1;
1635                 }
1636                 newf[0] = '\0';
1637                 strncat(newf, tmpfiname, x-tmpfiname);
1638                 strcat(newf, "/");
1639                 strcat(newf, fbuf);
1640
1641                 fp = fopen(newf, "r" );
1642                 if ( fp==NULL )
1643                 {
1644                         pkg_free(newf);
1645                         if(mode==0)
1646                         {
1647                                 LM_CRIT("cannot open included file: %s (%s)\n", fbuf, newf);
1648                                 return -1;
1649                         } else {
1650                                 LM_DBG("importing file ignored: %s (%s)\n", fbuf, newf);
1651                                 return 0;
1652                         }
1653                 }
1654                 LM_DBG("including file: %s (%s)\n", fbuf, newf);
1655         } else {
1656                 newf = fbuf;
1657         }
1658
1659         include_stack[include_stack_ptr].state = YY_CURRENT_BUFFER;
1660         include_stack[include_stack_ptr].line = line;
1661         include_stack[include_stack_ptr].column = column;
1662         include_stack[include_stack_ptr].startline = startline;
1663         include_stack[include_stack_ptr].startcolumn = startcolumn;
1664         include_stack[include_stack_ptr].finame = finame;
1665         include_stack[include_stack_ptr].routename = routename;
1666         include_stack_ptr++;
1667
1668         line=1;
1669         column=1;
1670         startline=1;
1671         startcolumn=1;
1672
1673         yyin = fp;
1674
1675         /* make a copy in PKG if does not exist */
1676         fn = sr_yy_fname_list;
1677         while(fn!=0)
1678         {
1679                 if(strcmp(fn->fname, newf)==0)
1680                 {
1681                         if(newf!=fbuf)
1682                                 pkg_free(newf);
1683                         newf = fbuf;
1684                         break;
1685                 }
1686                 fn = fn->next;
1687         }
1688         if(fn==0)
1689         {
1690                 fn = (struct sr_yy_fname*)pkg_malloc(sizeof(struct sr_yy_fname));
1691                 if(fn==0)
1692                 {
1693                         if(newf!=fbuf)
1694                                 pkg_free(newf);
1695                         PKG_MEM_CRITICAL;
1696                         return -1;
1697                 }
1698                 if(newf==fbuf)
1699                 {
1700                         fn->fname = (char*)pkg_malloc(strlen(fbuf)+1);
1701                         if(fn->fname==0)
1702                         {
1703                                 pkg_free(fn);
1704                                 PKG_MEM_CRITICAL;
1705                                 return -1;
1706                         }
1707                         strcpy(fn->fname, fbuf);
1708                 } else {
1709                         fn->fname = newf;
1710                 }
1711                 fn->next = sr_yy_fname_list;
1712                 sr_yy_fname_list = fn;
1713         }
1714
1715         finame = fn->fname;
1716
1717         yy_switch_to_buffer( yy_create_buffer(yyin, YY_BUF_SIZE ) );
1718
1719         return 0;
1720
1721 }
1722
1723 static int sr_pop_yy_state()
1724 {
1725         include_stack_ptr--;
1726         if (include_stack_ptr<0 )
1727                 return -1;
1728
1729         yy_delete_buffer( YY_CURRENT_BUFFER );
1730         yy_switch_to_buffer(include_stack[include_stack_ptr].state);
1731         line=include_stack[include_stack_ptr].line;
1732         column=include_stack[include_stack_ptr].column;
1733         startline=include_stack[include_stack_ptr].startline;
1734         startcolumn=include_stack[include_stack_ptr].startcolumn;
1735         finame = include_stack[include_stack_ptr].finame;
1736         return 0;
1737 }
1738
1739 /* define/ifdef support */
1740
1741 #define MAX_DEFINES    512
1742 static ksr_ppdefine_t pp_defines[MAX_DEFINES];
1743 static int pp_num_defines = 0;
1744 static int pp_define_type = 0;
1745 static int pp_define_index = -1;
1746
1747 /* pp_ifdef_stack[i] is 1 if the ifdef test at depth i is either
1748  * ifdef(defined), ifndef(undefined), or the opposite of these
1749  * two, but in an else branch
1750  */
1751 #define MAX_IFDEFS    512
1752 static int pp_ifdef_stack[MAX_IFDEFS];
1753 static int pp_sptr = 0; /* stack pointer */
1754
1755 str* pp_get_define_name(int idx)
1756 {
1757         if(idx<0 || idx>=pp_num_defines)
1758                 return NULL;
1759         return &pp_defines[idx].name;
1760 }
1761
1762 ksr_ppdefine_t* pp_get_define(int idx)
1763 {
1764         if(idx<0 || idx>=pp_num_defines)
1765                 return NULL;
1766         return &pp_defines[idx];
1767 }
1768
1769 static int pp_lookup(int len, const char * text)
1770 {
1771         str var = {(char *)text, len};
1772         int i;
1773
1774         for (i=0; i<pp_num_defines; i++)
1775                 if (STR_EQ(pp_defines[i].name, var))
1776                         return i;
1777
1778         return -1;
1779 }
1780
1781 int pp_define_set_type(int type)
1782 {
1783         pp_define_type = type;
1784         return 0;
1785 }
1786
1787 int pp_define(int len, const char * text)
1788 {
1789         int ppos;
1790
1791         LM_DBG("defining id: %.*s\n", len, text);
1792
1793         if (pp_num_defines == MAX_DEFINES) {
1794                 LM_CRIT("too many defines -- adjust MAX_DEFINES\n");
1795                 return -1;
1796         }
1797
1798         pp_define_index = -1;
1799         ppos = pp_lookup(len, text);
1800         if(ppos >= 0) {
1801                 if(pp_define_type==1) {
1802                         LM_DBG("ignoring - already defined: %.*s\n", len, text);
1803                         pp_define_index = -2;
1804                         return 0;
1805                 } else if(pp_define_type==2) {
1806                         LM_DBG("redefining: %.*s\n", len, text);
1807                         pp_define_index = ppos;
1808                         if(pp_defines[ppos].value.s != NULL) {
1809                                 pkg_free(pp_defines[ppos].value.s);
1810                                 pp_defines[ppos].value.len = 0;
1811                                 pp_defines[ppos].value.s = NULL;
1812                         }
1813                         pp_defines[ppos].dtype = pp_define_type;
1814                         return 0;
1815                 } else {
1816                         LM_CRIT("already defined: %.*s\n", len, text);
1817                         return -1;
1818                 }
1819         }
1820
1821         pp_defines[pp_num_defines].name.len = len;
1822         pp_defines[pp_num_defines].name.s = (char*)pkg_malloc(len+1);
1823         if(pp_defines[pp_num_defines].name.s==NULL) {
1824                 PKG_MEM_CRITICAL;
1825                 return -1;
1826         }
1827         memcpy(pp_defines[pp_num_defines].name.s, text, len);
1828         pp_defines[pp_num_defines].name.s[len] = '\0';
1829         pp_defines[pp_num_defines].value.len = 0;
1830         pp_defines[pp_num_defines].value.s = NULL;
1831         pp_defines[pp_num_defines].dtype = pp_define_type;
1832         pp_define_index = pp_num_defines;
1833         pp_num_defines++;
1834
1835         return 0;
1836 }
1837
1838 int pp_define_set(int len, char *text)
1839 {
1840         int ppos;
1841
1842         if(pp_define_index == -2) {
1843                 /* #!trydef that should be ignored */
1844                 return 0;
1845         }
1846
1847         if(pp_define_index < 0) {
1848                 /* invalid position in define table */
1849                 LM_BUG("BUG: the index in define table not set yet\n");
1850                 return -1;
1851         }
1852         if(len<=0) {
1853                 LM_DBG("no define value - ignoring\n");
1854                 return 0;
1855         }
1856         if (pp_num_defines == MAX_DEFINES) {
1857                 LM_CRIT("too many defines -- adjust MAX_DEFINES\n");
1858                 return -1;
1859         }
1860         if (pp_num_defines == 0) {
1861                 LM_BUG("BUG: setting define value, but no define id yet\n");
1862                 return -1;
1863         }
1864
1865         ppos = pp_define_index;
1866         if (pp_defines[ppos].name.s == NULL) {
1867                 LM_BUG("BUG: last define ID is null\n");
1868                 return -1;
1869         }
1870
1871         if (pp_defines[ppos].value.s != NULL) {
1872                 LM_BUG("BUG: ID %.*s [%d] overwritten\n",
1873                         pp_defines[ppos].name.len,
1874                         pp_defines[ppos].name.s, ppos);
1875                 return -1;
1876         }
1877
1878         pp_defines[ppos].value.len = len;
1879         pp_defines[ppos].value.s = text;
1880         LM_DBG("### setting define ID [%.*s] value [%.*s]\n",
1881                         pp_defines[ppos].name.len,
1882                         pp_defines[ppos].name.s,
1883                         pp_defines[ppos].value.len,
1884                         pp_defines[ppos].value.s);
1885         return 0;
1886 }
1887
1888 str *pp_define_get(int len, const char * text)
1889 {
1890         str var = {(char *)text, len};
1891         int i;
1892
1893         for (i=0; i<pp_num_defines; i++)
1894         {
1895                 if (STR_EQ(pp_defines[i].name, var))
1896                 {
1897                         if(pp_defines[i].name.s!=NULL)
1898                         {
1899                                 LM_DBG("### returning define ID [%.*s] value [%.*s]\n",
1900                                         pp_defines[i].name.len,
1901                                         pp_defines[i].name.s,
1902                                         pp_defines[i].value.len,
1903                                         pp_defines[i].value.s);
1904                                 return &pp_defines[i].value;
1905                         }
1906                         return NULL;
1907                 }
1908         }
1909         return NULL;
1910 }
1911
1912 static int pp_ifdef_type(int type)
1913 {
1914         if (pp_sptr == MAX_IFDEFS) {
1915                 LM_CRIT("too many nested ifdefs -- adjust MAX_IFDEFS\n");
1916                 return -1;
1917         }
1918
1919         pp_ifdef_stack[pp_sptr] = type;
1920         pp_ifdef_level_update(1);
1921         return 0;
1922 }
1923
1924 /* this sets the result of the if[n]def expr:
1925  * ifdef  defined   -> 1
1926  * ifdef  undefined -> 0
1927  * ifndef defined   -> 0
1928  * ifndef undefined -> 1
1929  */
1930 static void pp_ifdef_var(int len, const char * text)
1931 {
1932         pp_ifdef_stack[pp_sptr] ^= (pp_lookup(len, text) < 0);
1933 }
1934
1935 static void pp_update_state()
1936 {
1937         int i;
1938
1939         for (i=0; i<pp_sptr; i++)
1940                 if (! pp_ifdef_stack[i]) {
1941                         state = IFDEF_SKIP_S; BEGIN(IFDEF_SKIP);
1942                         return;
1943                 }
1944
1945         state = INITIAL; BEGIN(INITIAL);
1946 }
1947
1948 static void pp_ifdef()
1949 {
1950         pp_sptr++;
1951         pp_update_state();
1952 }
1953
1954 static void pp_else()
1955 {
1956         if(pp_sptr==0) {
1957                 LM_WARN("invalid position for preprocessor directive 'else'"
1958                                 " - at %s line %d\n", (finame)?finame:"cfg", line);
1959                 return;
1960         }
1961         pp_ifdef_stack[pp_sptr-1] ^= 1;
1962         pp_update_state();
1963 }
1964
1965 static void pp_endif()
1966 {
1967         pp_ifdef_level_update(-1);
1968         if(pp_sptr==0) {
1969                 LM_WARN("invalid position for preprocessor directive 'endif'"
1970                                 " - at %s line %d\n", (finame)?finame:"cfg", line);
1971                 return;
1972         }
1973         pp_sptr--;
1974         pp_update_state();
1975 }
1976
1977 static void ksr_yy_fatal_error(const char* msg)
1978 {
1979         if(ksr_atexit_mode==1) {
1980                 yy_fatal_error(msg);
1981         }
1982
1983         fprintf( stderr, "%s\n", msg );
1984         _exit( YY_EXIT_FAILURE );
1985 }