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