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