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