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