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