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