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