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