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