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