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