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