script parsing: fix bug in expression error checking
[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  addd strlen, strempty and defined operators (andrei)
82 */
83
84
85 %{
86         #include "dprint.h"
87         #include "globals.h"
88         #include "mem/mem.h"
89         #include <string.h>
90         #include <stdlib.h>
91         #include "ip_addr.h"
92         #include "usr_avp.h"
93         #include "select.h"
94         #include "cfg.tab.h"
95         #include "sr_compat.h"
96
97         /* states */
98         #define INITIAL_S               0
99         #define COMMENT_S               1
100         #define COMMENT_LN_S            2
101         #define STRING_S                3
102         #define ATTR_S                  4  /* avp/attr */
103         #define SELECT_S                5
104         #define AVP_PVAR_S              6  /* avp or pvar */
105         #define PVAR_P_S                7  /* pvar: $(...)  or $foo(...)*/
106         #define PVARID_S                8  /* $foo.bar...*/
107         #define STR_BETWEEN_S           9
108
109         #define STR_BUF_ALLOC_UNIT      128
110         struct str_buf{
111                 char* s;
112                 char* crt;
113                 int left;
114         };
115
116
117         static int comment_nest=0;
118         static int p_nest=0;
119         static int state=0, old_state=0, old_initial=0;
120         static struct str_buf s_buf;
121         int line=1;
122         int column=1;
123         int startcolumn=1;
124         int startline=1;
125         static int ign_lines=0;
126         static int ign_columns=0;
127
128         static char* addchar(struct str_buf *, char);
129         static char* addstr(struct str_buf *, char*, int);
130         static void count();
131         static void count_more();
132         static void count_ignore();
133
134
135 %}
136
137 /* start conditions */
138 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P 
139 %x PVARID
140
141 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
142 SER_CFG                 SER
143 KAMAILIO_CFG    KAMAILIO|OPENSER
144 MAXCOMPAT_CFG   MAXCOMPAT|ALL
145
146 /* action keywords */
147 FORWARD forward
148 FORWARD_TCP     forward_tcp
149 FORWARD_UDP     forward_udp
150 FORWARD_TLS     forward_tls
151 FORWARD_SCTP    forward_sctp
152 DROP    "drop"|"exit"
153 RETURN  "return"
154 BREAK   "break"
155 SEND    send
156 SEND_TCP        send_tcp
157 LOG             log
158 ERROR   error
159 ROUTE   route
160 ROUTE_FAILURE failure_route
161 ROUTE_ONREPLY onreply_route
162 ROUTE_BRANCH branch_route
163 ROUTE_SEND onsend_route
164 EXEC    exec
165 FORCE_RPORT             "force_rport"|"add_rport"
166 FORCE_TCP_ALIAS         "force_tcp_alias"|"add_tcp_alias"
167 UDP_MTU         "udp_mtu"
168 UDP_MTU_TRY_PROTO       "udp_mtu_try_proto"
169 SETFLAG         setflag
170 RESETFLAG       resetflag
171 ISFLAGSET       isflagset
172 FLAGS_DECL      "flags"|"bool"
173 SETAVPFLAG      setavpflag
174 RESETAVPFLAG    resetavpflag
175 ISAVPFLAGSET    isavpflagset
176 AVPFLAGS_DECL   avpflags
177 SET_HOST                "rewritehost"|"sethost"|"seth"
178 SET_HOSTPORT    "rewritehostport"|"sethostport"|"sethp"
179 SET_HOSTPORTTRANS       "rewritehostporttrans"|"sethostporttrans"|"sethpt"
180 SET_USER                "rewriteuser"|"setuser"|"setu"
181 SET_USERPASS    "rewriteuserpass"|"setuserpass"|"setup"
182 SET_PORT                "rewriteport"|"setport"|"setp"
183 SET_URI                 "rewriteuri"|"seturi"
184 REVERT_URI              "revert_uri"
185 PREFIX                  "prefix"
186 STRIP                   "strip"
187 STRIP_TAIL              "strip_tail"
188 SET_USERPHONE           "userphone"
189 APPEND_BRANCH   "append_branch"
190 IF                              "if"
191 ELSE                    "else"
192 SET_ADV_ADDRESS "set_advertised_address"
193 SET_ADV_PORT    "set_advertised_port"
194 FORCE_SEND_SOCKET       "force_send_socket"
195 SWITCH                  "switch"
196 CASE                    "case"
197 DEFAULT                 "default"
198 WHILE                   "while"
199
200 /*ACTION LVALUES*/
201 URIHOST                 "uri:host"
202 URIPORT                 "uri:port"
203
204 MAX_LEN                 "max_len"
205
206
207 /* condition keywords */
208 METHOD  method
209 /* hack -- the second element in first line is referable
210    as either uri or status; it only would makes sense to
211    call it "uri" from route{} and status from onreply_route{}
212 */
213 URI             "uri"|"status"
214 FROM_URI        "from_uri"
215 TO_URI          "to_uri"
216 SRCIP   src_ip
217 SRCPORT src_port
218 DSTIP   dst_ip
219 DSTPORT dst_port
220 SNDIP   snd_ip
221 SNDPORT snd_port
222 SNDPROTO        snd_proto|to_proto
223 SNDAF           snd_af|to_af
224 TOIP    to_ip
225 TOPORT  to_port
226 PROTO   proto
227 AF              af
228 MYSELF  myself
229 MSGLEN                  "msg:len"
230 RETCODE \$\?|\$retcode
231 /* operators */
232 EQUAL   =
233 EQUAL_T ==
234 GT      >
235 LT      <
236 GTE     >=
237 LTE     <=
238 DIFF    !=
239 MATCH   =~
240 ADDEQ     "+="
241 NOT             !|"not"
242 LOG_AND         "and"|"&&"
243 BIN_AND         "&"
244 LOG_OR          "or"|"||"
245 BIN_OR          "|"
246 PLUS    "+"
247 MINUS   "-"
248 STRLEN  "strlen"
249 STREMPTY        "strempty"
250 DEFINED         "defined"
251 STREQ   eq
252 INTEQ   ieq
253 STRDIFF ne
254 INTDIFF ine
255
256 /* Attribute specification */
257 ATTR_MARK   "%"
258 VAR_MARK    "$"
259 SELECT_MARK  "@"
260 ATTR_FROM         "f"
261 ATTR_TO           "t"
262 ATTR_FROMURI      "fr"
263 ATTR_TOURI       "tr"
264 ATTR_FROMUSER     "fu"
265 ATTR_TOUSER       "tu"
266 ATTR_FROMDOMAIN   "fd"
267 ATTR_TODOMAIN     "td"
268 ATTR_GLOBAL       "g"
269
270 /* avp prefix */
271 AVP_PREF        (([ft][rud]?)|g)\.
272
273 /* config vars. */
274 DEBUG   debug
275 FORK    fork
276 LOGSTDERROR     log_stderror
277 LOGFACILITY     log_facility
278 LISTEN          listen
279 ALIAS           alias
280 DNS              dns
281 REV_DNS  rev_dns
282 DNS_TRY_IPV6    dns_try_ipv6
283 DNS_TRY_NAPTR   dns_try_naptr
284 DNS_SRV_LB              dns_srv_lb|dns_srv_loadbalancing
285 DNS_UDP_PREF    dns_udp_pref|dns_udp_preference
286 DNS_TCP_PREF    dns_tcp_pref|dns_tcp_preference
287 DNS_TLS_PREF    dns_tls_pref|dns_tls_preference
288 DNS_SCTP_PREF   dns_sctp_pref|dns_sctp_preference
289 DNS_RETR_TIME   dns_retr_time
290 DNS_RETR_NO             dns_retr_no
291 DNS_SERVERS_NO  dns_servers_no
292 DNS_USE_SEARCH  dns_use_search_list
293 DNS_SEARCH_FMATCH       dns_search_full_match
294 /* dns cache */
295 DNS_CACHE_INIT  dns_cache_init
296 DNS_USE_CACHE   use_dns_cache
297 DNS_USE_FAILOVER        use_dns_failover
298 DNS_CACHE_FLAGS         dns_cache_flags
299 DNS_CACHE_NEG_TTL       dns_cache_negative_ttl
300 DNS_CACHE_MIN_TTL       dns_cache_min_ttl
301 DNS_CACHE_MAX_TTL       dns_cache_max_ttl
302 DNS_CACHE_MEM           dns_cache_mem
303 DNS_CACHE_GC_INT        dns_cache_gc_interval
304 DNS_CACHE_DEL_NONEXP    dns_cache_del_nonexp|dns_cache_delete_nonexpired
305 /* blacklist */
306 DST_BLST_INIT   dst_blacklist_init
307 USE_DST_BLST            use_dst_blacklist
308 DST_BLST_MEM            dst_blacklist_mem
309 DST_BLST_TTL            dst_blacklist_expire|dst_blacklist_ttl
310 DST_BLST_GC_INT         dst_blacklist_gc_interval
311
312
313 PORT    port
314 STAT    statistics
315 MAXBUFFER maxbuffer
316 CHILDREN children
317 CHECK_VIA       check_via
318 PHONE2TEL       phone2tel
319 SYN_BRANCH syn_branch
320 MEMLOG          "memlog"|"mem_log"
321 MEMDBG          "memdbg"|"mem_dbg"
322 SIP_WARNING sip_warning
323 SERVER_SIGNATURE server_signature
324 REPLY_TO_VIA reply_to_via
325 USER            "user"|"uid"
326 GROUP           "group"|"gid"
327 CHROOT          "chroot"
328 WDIR            "workdir"|"wdir"
329 MHOMED          mhomed
330 DISABLE_TCP             "disable_tcp"
331 TCP_CHILDREN    "tcp_children"
332 TCP_ACCEPT_ALIASES      "tcp_accept_aliases"
333 TCP_SEND_TIMEOUT        "tcp_send_timeout"
334 TCP_CONNECT_TIMEOUT     "tcp_connect_timeout"
335 TCP_CON_LIFETIME        "tcp_connection_lifetime"
336 TCP_POLL_METHOD         "tcp_poll_method"
337 TCP_MAX_CONNECTIONS     "tcp_max_connections"
338 TCP_NO_CONNECT          "tcp_no_connect"
339 TCP_SOURCE_IPV4         "tcp_source_ipv4"
340 TCP_SOURCE_IPV6         "tcp_source_ipv6"
341 TCP_OPT_FD_CACHE        "tcp_fd_cache"
342 TCP_OPT_BUF_WRITE       "tcp_buf_write"|"tcp_async"
343 TCP_OPT_CONN_WQ_MAX     "tcp_conn_wq_max"
344 TCP_OPT_WQ_MAX          "tcp_wq_max"
345 TCP_OPT_RD_BUF          "tcp_rd_buf_size"
346 TCP_OPT_WQ_BLK          "tcp_wq_blk_size"
347 TCP_OPT_DEFER_ACCEPT "tcp_defer_accept"
348 TCP_OPT_DELAYED_ACK     "tcp_delayed_ack"
349 TCP_OPT_SYNCNT          "tcp_syncnt"
350 TCP_OPT_LINGER2         "tcp_linger2"
351 TCP_OPT_KEEPALIVE       "tcp_keepalive"
352 TCP_OPT_KEEPIDLE        "tcp_keepidle"
353 TCP_OPT_KEEPINTVL       "tcp_keepintvl"
354 TCP_OPT_KEEPCNT         "tcp_keepcnt"
355 TCP_OPT_CRLF_PING       "tcp_crlf_ping"
356 DISABLE_TLS             "disable_tls"|"tls_disable"
357 ENABLE_TLS              "enable_tls"|"tls_enable"
358 TLSLOG                  "tlslog"|"tls_log"
359 TLS_PORT_NO             "tls_port_no"
360 TLS_METHOD              "tls_method"
361 TLS_VERIFY              "tls_verify"
362 TLS_REQUIRE_CERTIFICATE "tls_require_certificate"
363 TLS_CERTIFICATE "tls_certificate"
364 TLS_PRIVATE_KEY "tls_private_key"
365 TLS_CA_LIST             "tls_ca_list"
366 TLS_HANDSHAKE_TIMEOUT   "tls_handshake_timeout"
367 TLS_SEND_TIMEOUT        "tls_send_timeout"
368 DISABLE_SCTP    "disable_sctp"
369 ENABLE_SCTP     "enable_sctp"
370 SCTP_CHILDREN   "sctp_children"
371 SCTP_SOCKET_RCVBUF      "sctp_socket_rcvbuf"|"sctp_socket_receive_buffer"
372 SCTP_SOCKET_SNDBUF      "sctp_socket_sndbuf"|"sctp_socket_send_buffer"
373 SCTP_AUTOCLOSE  "sctp_autoclose"
374 SCTP_SEND_TTL   "sctp_send_ttl"
375 SCTP_SEND_RETRIES       "sctp_send_retries"
376 ADVERTISED_ADDRESS      "advertised_address"
377 ADVERTISED_PORT         "advertised_port"
378 DISABLE_CORE            "disable_core_dump"
379 OPEN_FD_LIMIT           "open_files_limit"
380 SHM_FORCE_ALLOC         "shm_force_alloc"
381 MLOCK_PAGES                     "mlock_pages"
382 REAL_TIME                       "real_time"
383 RT_PRIO                         "rt_prio"
384 RT_POLICY                       "rt_policy"
385 RT_TIMER1_PRIO          "rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
386 RT_TIMER1_POLICY        "rt_timer1_policy"|"rt_ftimer_policy"
387 RT_TIMER2_PRIO          "rt_timer2_prio"|"rt_stimer_prio"
388 RT_TIMER2_POLICY        "rt_timer2_policy"|"rt_stimer_policy"
389 MCAST_LOOPBACK          "mcast_loopback"
390 MCAST_TTL               "mcast_ttl"
391 TOS                     "tos"
392 PMTU_DISCOVERY  "pmtu_discovery"
393 KILL_TIMEOUT    "exit_timeout"|"ser_kill_timeout"
394 MAX_WLOOPS              "max_while_loops"
395
396 /* stun config variables */
397 STUN_REFRESH_INTERVAL "stun_refresh_interval"
398 STUN_ALLOW_STUN "stun_allow_stun"
399 STUN_ALLOW_FP "stun_allow_fp"
400
401 SERVER_ID     "server_id"
402
403 CFG_DESCRIPTION         "description"|"descr"|"desc"
404
405 LOADMODULE      loadmodule
406 LOADPATH        loadpath
407 MODPARAM        modparam
408
409 /* values */
410 YES                     "yes"|"true"|"on"|"enable"
411 NO                      "no"|"false"|"off"|"disable"
412 UDP                     "udp"|"UDP"
413 TCP                     "tcp"|"TCP"
414 TLS                     "tls"|"TLS"
415 SCTP            "sctp"|"SCTP"
416 INET            "inet"|"INET"
417 INET6           "inet6"|"INET6"
418 SSLv23                  "sslv23"|"SSLv23"|"SSLV23"
419 SSLv2                   "sslv2"|"SSLv2"|"SSLV2"
420 SSLv3                   "sslv3"|"SSLv3"|"SSLV3"
421 TLSv1                   "tlsv1"|"TLSv1"|"TLSV1"
422
423 LETTER          [a-zA-Z]
424 DIGIT           [0-9]
425 ALPHANUM        {LETTER}|{DIGIT}|[_]
426 ID                      {LETTER}{ALPHANUM}*
427 HEX                     [0-9a-fA-F]
428 HEXNUMBER       0x{HEX}+
429 OCTNUMBER       0[0-7]+
430 DECNUMBER       0|([1-9]{DIGIT}*)
431 BINNUMBER       [0-1]+b
432 HEX4            {HEX}{1,4}
433 IPV6ADDR        ({HEX4}":"){7}{HEX4}|({HEX4}":"){1,7}(":"{HEX4}){1,7}|":"(":"{HEX4}){1,7}|({HEX4}":"){1,7}":"|"::"
434 QUOTES          \"
435 TICK            \'
436 SLASH           "/"
437 SEMICOLON       ;
438 RPAREN          \)
439 LPAREN          \(
440 LBRACE          \{
441 RBRACE          \}
442 LBRACK          \[
443 RBRACK          \]
444 COMMA           ","
445 COLON           ":"
446 STAR            \*
447 DOT                     \.
448 CR                      \n
449
450
451
452 COM_LINE        #
453 COM_START       "/\*"
454 COM_END         "\*/"
455
456 EAT_ABLE        [\ \t\b\r]
457
458 %%
459
460
461 <INITIAL>{EAT_ABLE}     { count(); }
462
463 <INITIAL>{FORWARD}      {count(); yylval.strval=yytext; return FORWARD; }
464 <INITIAL>{FORWARD_TCP}  {count(); yylval.strval=yytext; return FORWARD_TCP; }
465 <INITIAL>{FORWARD_TLS}  {count(); yylval.strval=yytext; return FORWARD_TLS; }
466 <INITIAL>{FORWARD_SCTP} {count(); yylval.strval=yytext; return FORWARD_SCTP;}
467 <INITIAL>{FORWARD_UDP}  {count(); yylval.strval=yytext; return FORWARD_UDP; }
468 <INITIAL>{DROP} { count(); yylval.strval=yytext; return DROP; }
469 <INITIAL>{RETURN}       { count(); yylval.strval=yytext; return RETURN; }
470 <INITIAL>{BREAK}        { count(); yylval.strval=yytext; return BREAK; }
471 <INITIAL>{SEND} { count(); yylval.strval=yytext; return SEND; }
472 <INITIAL>{SEND_TCP}     { count(); yylval.strval=yytext; return SEND_TCP; }
473 <INITIAL>{LOG}  { count(); yylval.strval=yytext; return LOG_TOK; }
474 <INITIAL>{ERROR}        { count(); yylval.strval=yytext; return ERROR; }
475 <INITIAL>{SETFLAG}      { count(); yylval.strval=yytext; return SETFLAG; }
476 <INITIAL>{RESETFLAG}    { count(); yylval.strval=yytext; return RESETFLAG; }
477 <INITIAL>{ISFLAGSET}    { count(); yylval.strval=yytext; return ISFLAGSET; }
478 <INITIAL>{FLAGS_DECL}   { count(); yylval.strval=yytext; return FLAGS_DECL; }
479 <INITIAL>{SETAVPFLAG}   { count(); yylval.strval=yytext; return SETAVPFLAG; }
480 <INITIAL>{RESETAVPFLAG} { count(); yylval.strval=yytext; return RESETAVPFLAG; }
481 <INITIAL>{ISAVPFLAGSET} { count(); yylval.strval=yytext; return ISAVPFLAGSET; }
482 <INITIAL>{AVPFLAGS_DECL}        { count(); yylval.strval=yytext; return AVPFLAGS_DECL; }
483 <INITIAL>{MSGLEN}       { count(); yylval.strval=yytext; return MSGLEN; }
484 <INITIAL>{RETCODE}      { count(); yylval.strval=yytext; return RETCODE; }
485 <INITIAL>{ROUTE}        { count(); yylval.strval=yytext; return ROUTE; }
486 <INITIAL>{ROUTE_ONREPLY}        { count(); yylval.strval=yytext;
487                                                                 return ROUTE_ONREPLY; }
488 <INITIAL>{ROUTE_FAILURE}        { count(); yylval.strval=yytext;
489                                                                 return ROUTE_FAILURE; }
490 <INITIAL>{ROUTE_BRANCH} { count(); yylval.strval=yytext; return ROUTE_BRANCH; }
491 <INITIAL>{ROUTE_SEND} { count(); yylval.strval=yytext; return ROUTE_SEND; }
492 <INITIAL>{EXEC} { count(); yylval.strval=yytext; return EXEC; }
493 <INITIAL>{SET_HOST}     { count(); yylval.strval=yytext; return SET_HOST; }
494 <INITIAL>{SET_HOSTPORT} { count(); yylval.strval=yytext; return SET_HOSTPORT; }
495 <INITIAL>{SET_HOSTPORTTRANS}    { count(); yylval.strval=yytext; return SET_HOSTPORTTRANS; }
496 <INITIAL>{SET_USER}     { count(); yylval.strval=yytext; return SET_USER; }
497 <INITIAL>{SET_USERPASS} { count(); yylval.strval=yytext; return SET_USERPASS; }
498 <INITIAL>{SET_PORT}     { count(); yylval.strval=yytext; return SET_PORT; }
499 <INITIAL>{SET_URI}      { count(); yylval.strval=yytext; return SET_URI; }
500 <INITIAL>{REVERT_URI}   { count(); yylval.strval=yytext; return REVERT_URI; }
501 <INITIAL>{PREFIX}       { count(); yylval.strval=yytext; return PREFIX; }
502 <INITIAL>{STRIP}        { count(); yylval.strval=yytext; return STRIP; }
503 <INITIAL>{STRIP_TAIL}   { count(); yylval.strval=yytext; return STRIP_TAIL; }
504 <INITIAL>{APPEND_BRANCH}        { count(); yylval.strval=yytext;
505                                                                 return APPEND_BRANCH; }
506 <INITIAL>{SET_USERPHONE}        { count(); yylval.strval=yytext;
507                                                                 return SET_USERPHONE; }
508 <INITIAL>{FORCE_RPORT}  { count(); yylval.strval=yytext; return FORCE_RPORT; }
509 <INITIAL>{FORCE_TCP_ALIAS}      { count(); yylval.strval=yytext;
510                                                                 return FORCE_TCP_ALIAS; }
511 <INITIAL>{UDP_MTU}      { count(); yylval.strval=yytext; return UDP_MTU; }
512 <INITIAL>{UDP_MTU_TRY_PROTO}    { count(); yylval.strval=yytext;
513                                                                         return UDP_MTU_TRY_PROTO; }
514 <INITIAL>{IF}   { count(); yylval.strval=yytext; return IF; }
515 <INITIAL>{ELSE} { count(); yylval.strval=yytext; return ELSE; }
516
517 <INITIAL>{SET_ADV_ADDRESS}      { count(); yylval.strval=yytext;
518                                                                                 return SET_ADV_ADDRESS; }
519 <INITIAL>{SET_ADV_PORT} { count(); yylval.strval=yytext;
520                                                                                 return SET_ADV_PORT; }
521 <INITIAL>{FORCE_SEND_SOCKET}    {       count(); yylval.strval=yytext;
522                                                                         return FORCE_SEND_SOCKET; }
523 <INITIAL>{SWITCH}       { count(); yylval.strval=yytext; return SWITCH; }
524 <INITIAL>{CASE} { count(); yylval.strval=yytext; return CASE; }
525 <INITIAL>{DEFAULT}      { count(); yylval.strval=yytext; return DEFAULT; }
526 <INITIAL>{WHILE}        { count(); yylval.strval=yytext; return WHILE; }
527
528 <INITIAL>{URIHOST}      { count(); yylval.strval=yytext; return URIHOST; }
529 <INITIAL>{URIPORT}      { count(); yylval.strval=yytext; return URIPORT; }
530
531 <INITIAL>{MAX_LEN}      { count(); yylval.strval=yytext; return MAX_LEN; }
532
533 <INITIAL>{METHOD}       { count(); yylval.strval=yytext; return METHOD; }
534 <INITIAL>{URI}  { count(); yylval.strval=yytext; return URI; }
535 <INITIAL>{FROM_URI}     { count(); yylval.strval=yytext; return FROM_URI; }
536 <INITIAL>{TO_URI}       { count(); yylval.strval=yytext; return TO_URI; }
537 <INITIAL>{SRCIP}        { count(); yylval.strval=yytext; return SRCIP; }
538 <INITIAL>{SRCPORT}      { count(); yylval.strval=yytext; return SRCPORT; }
539 <INITIAL>{DSTIP}        { count(); yylval.strval=yytext; return DSTIP; }
540 <INITIAL>{DSTPORT}      { count(); yylval.strval=yytext; return DSTPORT; }
541 <INITIAL>{SNDIP}        { count(); yylval.strval=yytext; return SNDIP; }
542 <INITIAL>{SNDPORT}      { count(); yylval.strval=yytext; return SNDPORT; }
543 <INITIAL>{SNDPROTO}     { count(); yylval.strval=yytext; return SNDPROTO; }
544 <INITIAL>{SNDAF}        { count(); yylval.strval=yytext; return SNDAF; }
545 <INITIAL>{TOIP}         { count(); yylval.strval=yytext; return TOIP; }
546 <INITIAL>{TOPORT}       { count(); yylval.strval=yytext; return TOPORT; }
547 <INITIAL>{PROTO}        { count(); yylval.strval=yytext; return PROTO; }
548 <INITIAL>{AF}   { count(); yylval.strval=yytext; return AF; }
549 <INITIAL>{MYSELF}       { count(); yylval.strval=yytext; return MYSELF; }
550
551 <INITIAL>{DEBUG}        { count(); yylval.strval=yytext; return DEBUG_V; }
552 <INITIAL>{FORK}         { count(); yylval.strval=yytext; return FORK; }
553 <INITIAL>{LOGSTDERROR}  { yylval.strval=yytext; return LOGSTDERROR; }
554 <INITIAL>{LOGFACILITY}  { yylval.strval=yytext; return LOGFACILITY; }
555 <INITIAL>{LISTEN}       { count(); yylval.strval=yytext; return LISTEN; }
556 <INITIAL>{ALIAS}        { count(); yylval.strval=yytext; return ALIAS; }
557 <INITIAL>{DNS}  { count(); yylval.strval=yytext; return DNS; }
558 <INITIAL>{REV_DNS}      { count(); yylval.strval=yytext; return REV_DNS; }
559 <INITIAL>{DNS_TRY_IPV6} { count(); yylval.strval=yytext;
560                                                                 return DNS_TRY_IPV6; }
561 <INITIAL>{DNS_TRY_NAPTR}        { count(); yylval.strval=yytext;
562                                                                 return DNS_TRY_NAPTR; }
563 <INITIAL>{DNS_SRV_LB}   { count(); yylval.strval=yytext;
564                                                                 return DNS_SRV_LB; }
565 <INITIAL>{DNS_UDP_PREF} { count(); yylval.strval=yytext;
566                                                                 return DNS_UDP_PREF; }
567 <INITIAL>{DNS_TCP_PREF} { count(); yylval.strval=yytext;
568                                                                 return DNS_TCP_PREF; }
569 <INITIAL>{DNS_TLS_PREF} { count(); yylval.strval=yytext;
570                                                                 return DNS_TLS_PREF; }
571 <INITIAL>{DNS_SCTP_PREF}        { count(); yylval.strval=yytext;
572                                                                 return DNS_SCTP_PREF; }
573 <INITIAL>{DNS_RETR_TIME}        { count(); yylval.strval=yytext;
574                                                                 return DNS_RETR_TIME; }
575 <INITIAL>{DNS_RETR_NO}  { count(); yylval.strval=yytext;
576                                                                 return DNS_RETR_NO; }
577 <INITIAL>{DNS_SERVERS_NO}       { count(); yylval.strval=yytext;
578                                                                 return DNS_SERVERS_NO; }
579 <INITIAL>{DNS_USE_SEARCH}       { count(); yylval.strval=yytext;
580                                                                 return DNS_USE_SEARCH; }
581 <INITIAL>{DNS_SEARCH_FMATCH}    { count(); yylval.strval=yytext;
582                                                                 return DNS_SEARCH_FMATCH; }
583 <INITIAL>{DNS_CACHE_INIT}       { count(); yylval.strval=yytext;
584                                                                 return DNS_CACHE_INIT; }
585 <INITIAL>{DNS_USE_CACHE}        { count(); yylval.strval=yytext;
586                                                                 return DNS_USE_CACHE; }
587 <INITIAL>{DNS_USE_FAILOVER}     { count(); yylval.strval=yytext;
588                                                                 return DNS_USE_FAILOVER; }
589 <INITIAL>{DNS_CACHE_FLAGS}      { count(); yylval.strval=yytext;
590                                                                 return DNS_CACHE_FLAGS; }
591 <INITIAL>{DNS_CACHE_NEG_TTL}    { count(); yylval.strval=yytext;
592                                                                 return DNS_CACHE_NEG_TTL; }
593 <INITIAL>{DNS_CACHE_MIN_TTL}    { count(); yylval.strval=yytext;
594                                                                 return DNS_CACHE_MIN_TTL; }
595 <INITIAL>{DNS_CACHE_MAX_TTL}    { count(); yylval.strval=yytext;
596                                                                 return DNS_CACHE_MAX_TTL; }
597 <INITIAL>{DNS_CACHE_MEM}        { count(); yylval.strval=yytext;
598                                                                 return DNS_CACHE_MEM; }
599 <INITIAL>{DNS_CACHE_GC_INT}     { count(); yylval.strval=yytext;
600                                                                 return DNS_CACHE_GC_INT; }
601 <INITIAL>{DNS_CACHE_DEL_NONEXP} { count(); yylval.strval=yytext;
602                                                                 return DNS_CACHE_DEL_NONEXP; }
603 <INITIAL>{DST_BLST_INIT}        { count(); yylval.strval=yytext;
604                                                                 return DST_BLST_INIT; }
605 <INITIAL>{USE_DST_BLST} { count(); yylval.strval=yytext;
606                                                                 return USE_DST_BLST; }
607 <INITIAL>{DST_BLST_MEM} { count(); yylval.strval=yytext;
608                                                                 return DST_BLST_MEM; }
609 <INITIAL>{DST_BLST_TTL} { count(); yylval.strval=yytext;
610                                                                 return DST_BLST_TTL; }
611 <INITIAL>{DST_BLST_GC_INT}      { count(); yylval.strval=yytext;
612                                                                 return DST_BLST_GC_INT; }
613 <INITIAL>{PORT} { count(); yylval.strval=yytext; return PORT; }
614 <INITIAL>{STAT} { count(); yylval.strval=yytext; return STAT; }
615 <INITIAL>{MAXBUFFER}    { count(); yylval.strval=yytext; return MAXBUFFER; }
616 <INITIAL>{CHILDREN}     { count(); yylval.strval=yytext; return CHILDREN; }
617 <INITIAL>{CHECK_VIA}    { count(); yylval.strval=yytext; return CHECK_VIA; }
618 <INITIAL>{PHONE2TEL}    { count(); yylval.strval=yytext; return PHONE2TEL; }
619 <INITIAL>{SYN_BRANCH}   { count(); yylval.strval=yytext; return SYN_BRANCH; }
620 <INITIAL>{MEMLOG}       { count(); yylval.strval=yytext; return MEMLOG; }
621 <INITIAL>{MEMDBG}       { count(); yylval.strval=yytext; return MEMDBG; }
622 <INITIAL>{SIP_WARNING}  { count(); yylval.strval=yytext; return SIP_WARNING; }
623 <INITIAL>{USER}         { count(); yylval.strval=yytext; return USER; }
624 <INITIAL>{GROUP}        { count(); yylval.strval=yytext; return GROUP; }
625 <INITIAL>{CHROOT}       { count(); yylval.strval=yytext; return CHROOT; }
626 <INITIAL>{WDIR} { count(); yylval.strval=yytext; return WDIR; }
627 <INITIAL>{MHOMED}       { count(); yylval.strval=yytext; return MHOMED; }
628 <INITIAL>{DISABLE_TCP}  { count(); yylval.strval=yytext; return DISABLE_TCP; }
629 <INITIAL>{TCP_CHILDREN} { count(); yylval.strval=yytext; return TCP_CHILDREN; }
630 <INITIAL>{TCP_ACCEPT_ALIASES}   { count(); yylval.strval=yytext;
631                                                                         return TCP_ACCEPT_ALIASES; }
632 <INITIAL>{TCP_SEND_TIMEOUT}             { count(); yylval.strval=yytext;
633                                                                         return TCP_SEND_TIMEOUT; }
634 <INITIAL>{TCP_CONNECT_TIMEOUT}          { count(); yylval.strval=yytext;
635                                                                         return TCP_CONNECT_TIMEOUT; }
636 <INITIAL>{TCP_CON_LIFETIME}             { count(); yylval.strval=yytext;
637                                                                         return TCP_CON_LIFETIME; }
638 <INITIAL>{TCP_POLL_METHOD}              { count(); yylval.strval=yytext;
639                                                                         return TCP_POLL_METHOD; }
640 <INITIAL>{TCP_MAX_CONNECTIONS}  { count(); yylval.strval=yytext;
641                                                                         return TCP_MAX_CONNECTIONS; }
642 <INITIAL>{TCP_NO_CONNECT}               { count(); yylval.strval=yytext;
643                                                                         return TCP_NO_CONNECT; }
644 <INITIAL>{TCP_SOURCE_IPV4}              { count(); yylval.strval=yytext;
645                                                                         return TCP_SOURCE_IPV4; }
646 <INITIAL>{TCP_SOURCE_IPV6}              { count(); yylval.strval=yytext;
647                                                                         return TCP_SOURCE_IPV6; }
648 <INITIAL>{TCP_OPT_FD_CACHE}             { count(); yylval.strval=yytext;
649                                                                         return TCP_OPT_FD_CACHE; }
650 <INITIAL>{TCP_OPT_CONN_WQ_MAX}  { count(); yylval.strval=yytext;
651                                                                         return TCP_OPT_CONN_WQ_MAX; }
652 <INITIAL>{TCP_OPT_WQ_MAX}       { count(); yylval.strval=yytext;
653                                                                         return TCP_OPT_WQ_MAX; }
654 <INITIAL>{TCP_OPT_RD_BUF}       { count(); yylval.strval=yytext;
655                                                                         return TCP_OPT_RD_BUF; }
656 <INITIAL>{TCP_OPT_WQ_BLK}       { count(); yylval.strval=yytext;
657                                                                         return TCP_OPT_WQ_BLK; }
658 <INITIAL>{TCP_OPT_BUF_WRITE}    { count(); yylval.strval=yytext;
659                                                                         return TCP_OPT_BUF_WRITE; }
660 <INITIAL>{TCP_OPT_DEFER_ACCEPT} { count(); yylval.strval=yytext;
661                                                                         return TCP_OPT_DEFER_ACCEPT; }
662 <INITIAL>{TCP_OPT_DELAYED_ACK}  { count(); yylval.strval=yytext;
663                                                                         return TCP_OPT_DELAYED_ACK; }
664 <INITIAL>{TCP_OPT_SYNCNT}               { count(); yylval.strval=yytext;
665                                                                         return TCP_OPT_SYNCNT; }
666 <INITIAL>{TCP_OPT_LINGER2}              { count(); yylval.strval=yytext;
667                                                                         return TCP_OPT_LINGER2; }
668 <INITIAL>{TCP_OPT_KEEPALIVE}    { count(); yylval.strval=yytext;
669                                                                         return TCP_OPT_KEEPALIVE; }
670 <INITIAL>{TCP_OPT_KEEPIDLE}             { count(); yylval.strval=yytext;
671                                                                         return TCP_OPT_KEEPIDLE; }
672 <INITIAL>{TCP_OPT_KEEPINTVL}    { count(); yylval.strval=yytext;
673                                                                         return TCP_OPT_KEEPINTVL; }
674 <INITIAL>{TCP_OPT_KEEPCNT}      { count(); yylval.strval=yytext;
675                                                                         return TCP_OPT_KEEPCNT; }
676 <INITIAL>{TCP_OPT_CRLF_PING}    { count(); yylval.strval=yytext;
677                                                                         return TCP_OPT_CRLF_PING; }
678 <INITIAL>{DISABLE_TLS}  { count(); yylval.strval=yytext; return DISABLE_TLS; }
679 <INITIAL>{ENABLE_TLS}   { count(); yylval.strval=yytext; return ENABLE_TLS; }
680 <INITIAL>{TLSLOG}               { count(); yylval.strval=yytext; return TLS_PORT_NO; }
681 <INITIAL>{TLS_PORT_NO}  { count(); yylval.strval=yytext; return TLS_PORT_NO; }
682 <INITIAL>{TLS_METHOD}   { count(); yylval.strval=yytext; return TLS_METHOD; }
683 <INITIAL>{TLS_VERIFY}   { count(); yylval.strval=yytext; return TLS_VERIFY; }
684 <INITIAL>{TLS_REQUIRE_CERTIFICATE}      { count(); yylval.strval=yytext;
685                                                                                 return TLS_REQUIRE_CERTIFICATE; }
686 <INITIAL>{TLS_CERTIFICATE}      { count(); yylval.strval=yytext;
687                                                                                 return TLS_CERTIFICATE; }
688 <INITIAL>{TLS_PRIVATE_KEY}      { count(); yylval.strval=yytext;
689                                                                                 return TLS_PRIVATE_KEY; }
690 <INITIAL>{TLS_CA_LIST}  { count(); yylval.strval=yytext;
691                                                                                 return TLS_CA_LIST; }
692 <INITIAL>{TLS_HANDSHAKE_TIMEOUT}        { count(); yylval.strval=yytext;
693                                                                                 return TLS_HANDSHAKE_TIMEOUT; }
694 <INITIAL>{TLS_SEND_TIMEOUT}     { count(); yylval.strval=yytext;
695                                                                                 return TLS_SEND_TIMEOUT; }
696 <INITIAL>{DISABLE_SCTP} { count(); yylval.strval=yytext; return DISABLE_SCTP;}
697 <INITIAL>{ENABLE_SCTP}  { count(); yylval.strval=yytext; return ENABLE_SCTP;}
698 <INITIAL>{SCTP_CHILDREN}        { count(); yylval.strval=yytext;
699                                                                                 return SCTP_CHILDREN; }
700 <INITIAL>{SCTP_SOCKET_RCVBUF}   { count(); yylval.strval=yytext;
701                                                                                 return SCTP_SOCKET_RCVBUF; }
702 <INITIAL>{SCTP_SOCKET_SNDBUF}   { count(); yylval.strval=yytext;
703                                                                                 return SCTP_SOCKET_SNDBUF; }
704 <INITIAL>{SCTP_AUTOCLOSE}       { count(); yylval.strval=yytext;
705                                                                                 return SCTP_AUTOCLOSE; }
706 <INITIAL>{SCTP_SEND_TTL}        { count(); yylval.strval=yytext;
707                                                                                 return SCTP_SEND_TTL; }
708 <INITIAL>{SCTP_SEND_RETRIES}    { count(); yylval.strval=yytext;
709                                                                                 return SCTP_SEND_RETRIES; }
710 <INITIAL>{SERVER_SIGNATURE}     { count(); yylval.strval=yytext; return SERVER_SIGNATURE; }
711 <INITIAL>{REPLY_TO_VIA} { count(); yylval.strval=yytext; return REPLY_TO_VIA; }
712 <INITIAL>{ADVERTISED_ADDRESS}   {       count(); yylval.strval=yytext;
713                                                                         return ADVERTISED_ADDRESS; }
714 <INITIAL>{ADVERTISED_PORT}              {       count(); yylval.strval=yytext;
715                                                                         return ADVERTISED_PORT; }
716 <INITIAL>{DISABLE_CORE}         {       count(); yylval.strval=yytext;
717                                                                         return DISABLE_CORE; }
718 <INITIAL>{OPEN_FD_LIMIT}                {       count(); yylval.strval=yytext;
719                                                                         return OPEN_FD_LIMIT; }
720 <INITIAL>{SHM_FORCE_ALLOC}              {       count(); yylval.strval=yytext;
721                                                                         return SHM_FORCE_ALLOC; }
722 <INITIAL>{MLOCK_PAGES}          {       count(); yylval.strval=yytext;
723                                                                         return MLOCK_PAGES; }
724 <INITIAL>{REAL_TIME}            {       count(); yylval.strval=yytext;
725                                                                         return REAL_TIME; }
726 <INITIAL>{RT_PRIO}              {       count(); yylval.strval=yytext;
727                                                                         return RT_PRIO; }
728 <INITIAL>{RT_POLICY}            {       count(); yylval.strval=yytext;
729                                                                         return RT_POLICY; }
730 <INITIAL>{RT_TIMER1_PRIO}               {       count(); yylval.strval=yytext;
731                                                                         return RT_TIMER1_PRIO; }
732 <INITIAL>{RT_TIMER1_POLICY}             {       count(); yylval.strval=yytext;
733                                                                         return RT_TIMER1_POLICY; }
734 <INITIAL>{RT_TIMER2_PRIO}               {       count(); yylval.strval=yytext;
735                                                                         return RT_TIMER2_PRIO; }
736 <INITIAL>{RT_TIMER2_POLICY}             {       count(); yylval.strval=yytext;
737                                                                         return RT_TIMER2_POLICY; }
738 <INITIAL>{MCAST_LOOPBACK}               {       count(); yylval.strval=yytext;
739                                                                         return MCAST_LOOPBACK; }
740 <INITIAL>{MCAST_TTL}            {       count(); yylval.strval=yytext;
741                                                                         return MCAST_TTL; }
742 <INITIAL>{TOS}                  {       count(); yylval.strval=yytext;
743                                                                         return TOS; }
744 <INITIAL>{PMTU_DISCOVERY}               {       count(); yylval.strval=yytext;
745                                                                         return PMTU_DISCOVERY; }
746 <INITIAL>{KILL_TIMEOUT}                 {       count(); yylval.strval=yytext;
747                                                                         return KILL_TIMEOUT; }
748 <INITIAL>{MAX_WLOOPS}                   {       count(); yylval.strval=yytext;
749                                                                         return MAX_WLOOPS; }
750 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
751 <INITIAL>{CFG_DESCRIPTION}      { count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
752 <INITIAL>{LOADMODULE}   { count(); yylval.strval=yytext; return LOADMODULE; }
753 <INITIAL>{LOADPATH}             { count(); yylval.strval=yytext; return LOADPATH; }
754 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
755
756 <INITIAL>{STUN_REFRESH_INTERVAL} { count(); yylval.strval=yytext; return STUN_REFRESH_INTERVAL;}
757 <INITIAL>{STUN_ALLOW_STUN} { count(); yylval.strval=yytext; return STUN_ALLOW_STUN;}
758 <INITIAL>{STUN_ALLOW_FP} { count(); yylval.strval=yytext; return STUN_ALLOW_FP;}
759
760 <INITIAL>{EQUAL}        { count(); return EQUAL; }
761 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
762 <INITIAL>{EQUAL_T}      { count(); return EQUAL_T; }
763 <INITIAL>{GT}   { count(); return GT; }
764 <INITIAL>{LT}   { count(); return LT; }
765 <INITIAL>{GTE}  { count(); return GTE; }
766 <INITIAL>{LTE}  { count(); return LTE; }
767 <INITIAL>{DIFF} { count(); return DIFF; }
768 <INITIAL>{MATCH}        { count(); return MATCH; }
769 <INITIAL>{NOT}          { count(); return NOT; }
770 <INITIAL>{LOG_AND}      { count(); return LOG_AND; }
771 <INITIAL>{BIN_AND}      { count(); return BIN_AND; }
772 <INITIAL>{LOG_OR}       { count(); return LOG_OR;  }
773 <INITIAL>{BIN_OR}       { count(); return BIN_OR;  }
774 <INITIAL>{PLUS}         { count(); return PLUS; }
775 <INITIAL>{MINUS}        { count(); return MINUS; }
776 <INITIAL>{STRLEN}       { count(); return STRLEN; }
777 <INITIAL>{STREMPTY}     { count(); return STREMPTY; }
778 <INITIAL>{DEFINED}      { count(); return DEFINED; }
779 <INITIAL>{STREQ}        { count(); return STREQ; }
780 <INITIAL>{INTEQ}        { count(); return INTEQ; }
781 <INITIAL>{STRDIFF}      { count(); return STRDIFF; }
782 <INITIAL>{INTDIFF}      { count(); return INTDIFF; }
783
784 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
785 <SELECT>{ID}            { count(); addstr(&s_buf, yytext, yyleng);
786                           yylval.strval=s_buf.s;
787                           memset(&s_buf, 0, sizeof(s_buf));
788                           return ID;
789                         }
790 <SELECT>{DOT}           { count(); return DOT; }
791 <SELECT>{LBRACK}        { count(); return LBRACK; }
792 <SELECT>{RBRACK}        { count(); return RBRACK; }
793 <SELECT>{DECNUMBER}     { count(); yylval.intval=atoi(yytext);return NUMBER; }
794 <SELECT>{HEXNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 16); return NUMBER; }
795 <SELECT>{OCTNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 8); return NUMBER; }
796 <SELECT>{BINNUMBER}     { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
797
798
799 <INITIAL>{ATTR_MARK}    { count(); state = ATTR_S; BEGIN(ATTR);
800                                                         return ATTR_MARK; }
801 <ATTR>{ATTR_FROM}       { count(); return ATTR_FROM; }
802 <ATTR>{ATTR_TO}         { count(); return ATTR_TO; }
803 <ATTR>{ATTR_FROMURI}    { count(); return ATTR_FROMURI; }
804 <ATTR>{ATTR_TOURI}      { count(); return ATTR_TOURI; }
805 <ATTR>{ATTR_FROMUSER}   { count(); return ATTR_FROMUSER; }
806 <ATTR>{ATTR_TOUSER}     { count(); return ATTR_TOUSER; }
807 <ATTR>{ATTR_FROMDOMAIN} { count(); return ATTR_FROMDOMAIN; }
808 <ATTR>{ATTR_TODOMAIN}   { count(); return ATTR_TODOMAIN; }
809 <ATTR>{ATTR_GLOBAL}     { count(); return ATTR_GLOBAL; }
810 <ATTR>{DOT}             { count(); return DOT; }
811 <ATTR>{LBRACK}          { count(); return LBRACK; }
812 <ATTR>{RBRACK}          { count(); return RBRACK; }
813 <ATTR>{STAR}                    { count(); return STAR; }
814 <ATTR>{DECNUMBER}               { count(); yylval.intval=atoi(yytext);return NUMBER; }
815 <ATTR>{ID}                              { count(); addstr(&s_buf, yytext, yyleng);
816                                                         yylval.strval=s_buf.s;
817                                                         memset(&s_buf, 0, sizeof(s_buf));
818                                                         state = INITIAL_S;
819                                                         BEGIN(INITIAL);
820                                                         return ID;
821                                                 }
822
823 <INITIAL>{VAR_MARK}{LPAREN}     {
824                                                                 switch(sr_cfg_compat){
825                                                                         case SR_COMPAT_SER:
826                                                                                 state=ATTR_S; BEGIN(ATTR);
827                                                                                 yyless(1);
828                                                                                 count();
829                                                                                 return ATTR_MARK;
830                                                                                 break;
831                                                                         case SR_COMPAT_KAMAILIO:
832                                                                         case SR_COMPAT_MAX:
833                                                                         default:
834                                                                                 state = PVAR_P_S; BEGIN(PVAR_P);
835                                                                                 p_nest=1; yymore();
836                                                                                 break;
837                                                                 }
838                                                         }
839         /* eat everything between 2 () and return PVAR token and a string
840            containing everything (including $ and ()) */
841 <PVAR_P>{RPAREN}                        {       p_nest--;
842                                                                 if (p_nest==0){
843                                                                         count();
844                                                                         addstr(&s_buf, yytext, yyleng);
845                                                                         yylval.strval=s_buf.s;
846                                                                         memset(&s_buf, 0, sizeof(s_buf));
847                                                                         state=INITIAL_S;
848                                                                         BEGIN(INITIAL);
849                                                                         return PVAR;
850                                                                 }
851                                                                 yymore();
852                                                         }
853 <PVAR_P>{LPAREN}                        { p_nest++; yymore(); }
854 <PVAR_P>.                                       { yymore(); }
855
856 <PVARID>{ID}|'.'                        {yymore(); }
857 <PVARID>{LPAREN}                        {       state = PVAR_P_S; BEGIN(PVAR_P);
858                                                                 p_nest=1; yymore(); }
859 <PVARID>.                                       { yyless(0); state=INITIAL_S; BEGIN(INITIAL);
860                                                                 return PVAR;
861                                                         }
862
863
864 <INITIAL>{VAR_MARK}                     {
865                                                                 switch(sr_cfg_compat){
866                                                                         case SR_COMPAT_SER:
867                                                                                 count();
868                                                                                 state=ATTR_S; BEGIN(ATTR);
869                                                                                 return ATTR_MARK;
870                                                                                 break;
871                                                                         case SR_COMPAT_KAMAILIO:
872                                                                                 state=PVARID_S; BEGIN(PVARID);
873                                                                                 yymore();
874                                                                                 break;
875                                                                         case SR_COMPAT_MAX:
876                                                                         default: 
877                                                                                 state=AVP_PVAR_S; BEGIN(AVP_PVAR);
878                                                                                 yymore();
879                                                                                 break;
880                                                                 }
881                                                         }
882         /* avp prefix detected -> go to avp mode */
883 <AVP_PVAR>{AVP_PREF}            |
884 <AVP_PVAR>{ID}{LBRACK}          { state = ATTR_S; BEGIN(ATTR); yyless(1); count();
885                                                           return ATTR_MARK; }
886 <AVP_PVAR>{ID}{LPAREN}          { state = PVAR_P_S; p_nest=1; BEGIN(PVAR_P);
887                                                                 yymore(); }
888 <AVP_PVAR>{ID}                          {       count(); addstr(&s_buf, yytext, yyleng);
889                                                                 yylval.strval=s_buf.s;
890                                                                 memset(&s_buf, 0, sizeof(s_buf));
891                                                                 state = INITIAL_S;
892                                                                 BEGIN(INITIAL);
893                                                                 return AVP_OR_PVAR;
894                                                         }
895
896 <INITIAL>{IPV6ADDR}             { count(); yylval.strval=yytext; return IPV6ADDR; }
897 <INITIAL>{DECNUMBER}            { count(); yylval.intval=atoi(yytext);return NUMBER; }
898 <INITIAL>{HEXNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 16);
899                                                         return NUMBER; }
900 <INITIAL>{OCTNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 8);
901                                                         return NUMBER; }
902 <INITIAL>{BINNUMBER}    { count(); yylval.intval=(int)strtol(yytext, 0, 2); return NUMBER; }
903 <INITIAL>{YES}                  { count(); yylval.intval=1; return NUMBER; }
904 <INITIAL>{NO}                   { count(); yylval.intval=0; return NUMBER; }
905 <INITIAL>{TCP}                  { count(); return TCP; }
906 <INITIAL>{UDP}                  { count(); return UDP; }
907 <INITIAL>{TLS}                  { count(); return TLS; }
908 <INITIAL>{SCTP}                 { count(); return SCTP; }
909 <INITIAL>{INET}                 { count(); yylval.intval=AF_INET; return NUMBER; }
910 <INITIAL>{INET6}                { count();
911                                                 #ifdef USE_IPV6
912                                                   yylval.intval=AF_INET6;
913                                                 #else
914                                                   yylval.intval=-1; /* no match*/
915                                                 #endif
916                                                   return NUMBER; }
917 <INITIAL>{SSLv23}               { count(); yylval.strval=yytext; return SSLv23; }
918 <INITIAL>{SSLv2}                { count(); yylval.strval=yytext; return SSLv2; }
919 <INITIAL>{SSLv3}                { count(); yylval.strval=yytext; return SSLv3; }
920 <INITIAL>{TLSv1}                { count(); yylval.strval=yytext; return TLSv1; }
921
922 <INITIAL>{COMMA}                { count(); return COMMA; }
923 <INITIAL>{SEMICOLON}    { count(); return SEMICOLON; }
924 <INITIAL>{COLON}        { count(); return COLON; }
925 <INITIAL>{STAR}         { count(); return STAR; }
926 <INITIAL>{RPAREN}       { count(); return RPAREN; }
927 <INITIAL>{LPAREN}       { count(); return LPAREN; }
928 <INITIAL>{LBRACE}       { count(); return LBRACE; }
929 <INITIAL>{RBRACE}       { count(); return RBRACE; }
930 <INITIAL>{LBRACK}       { count(); return LBRACK; }
931 <INITIAL>{RBRACK}       { count(); return RBRACK; }
932 <INITIAL>{SLASH}        { count(); return SLASH; }
933 <INITIAL>{DOT}          { count(); return DOT; }
934 <INITIAL>\\{CR}         {count(); } /* eat the escaped CR */
935 <INITIAL>{CR}           { count();/* return CR;*/ }
936
937
938 <INITIAL,SELECT>{QUOTES} { count(); old_initial = YY_START; 
939                                                         old_state = state; state=STRING_S;
940                                                         BEGIN(STRING1); }
941 <INITIAL>{TICK} { count(); old_initial = YY_START; old_state = state;
942                                         state=STRING_S; BEGIN(STRING2); }
943
944
945 <STRING1>{QUOTES} { count_more(); 
946                                                 yytext[yyleng-1]=0; yyleng--;
947                                                 addstr(&s_buf, yytext, yyleng);
948                                                 BEGIN(STR_BETWEEN);
949                                         }
950 <STRING2>{TICK}  { count_more(); state=old_state; BEGIN(old_initial);
951                                                 yytext[yyleng-1]=0; yyleng--;
952                                                 addstr(&s_buf, yytext, yyleng);
953                                                 yylval.strval=s_buf.s;
954                                                 memset(&s_buf, 0, sizeof(s_buf));
955                                                 return STRING;
956                                         }
957 <STRING2>.|{EAT_ABLE}|{CR}      { yymore(); }
958
959 <STRING1>\\n            { count_more(); addchar(&s_buf, '\n'); }
960 <STRING1>\\r            { count_more(); addchar(&s_buf, '\r'); }
961 <STRING1>\\a            { count_more(); addchar(&s_buf, '\a'); }
962 <STRING1>\\t            { count_more(); addchar(&s_buf, '\t'); }
963 <STRING1>\\{QUOTES}     { count_more(); addchar(&s_buf, '"');  }
964 <STRING1>\\\\           { count_more(); addchar(&s_buf, '\\'); }
965 <STRING1>\\x{HEX}{1,2}  { count_more(); addchar(&s_buf,
966                                                                                         (char)strtol(yytext+2, 0, 16)); }
967  /* don't allow \[0-7]{1}, it will eat the backreferences from
968     subst_uri if allowed (although everybody should use '' in subt_uri) */
969 <STRING1>\\[0-7]{2,3}   { count_more(); addchar(&s_buf,
970                                                                                         (char)strtol(yytext+1, 0, 8));  }
971 <STRING1>\\{CR}         { count_more(); } /* eat escaped CRs */
972 <STRING1>.|{EAT_ABLE}|{CR}      { count_more(); addchar(&s_buf, *yytext); }
973
974 <STR_BETWEEN>{EAT_ABLE}|{CR}    { count_ignore(); }
975 <STR_BETWEEN>{QUOTES}                   { count_more(); state=STRING_S;
976                                                                   BEGIN(STRING1);}
977 <STR_BETWEEN>.                                  {       
978                                                                         yyless(0); /* reparse it */
979                                                                         /* ignore the whitespace now that is
980                                                                           counted, return saved string value */
981                                                                         state=old_state; BEGIN(old_initial);
982                                                                         yylval.strval=s_buf.s;
983                                                                         memset(&s_buf, 0, sizeof(s_buf));
984                                                                         return STRING;
985                                                                 }
986
987 <INITIAL,COMMENT>{COM_START}    { count(); comment_nest++; state=COMMENT_S;
988                                                                                 BEGIN(COMMENT); }
989 <COMMENT>{COM_END}                              { count(); comment_nest--;
990                                                                                 if (comment_nest==0){
991                                                                                         state=INITIAL_S;
992                                                                                         BEGIN(INITIAL);
993                                                                                 }
994                                                                 }
995 <COMMENT>.|{EAT_ABLE}|{CR}                              { count(); };
996
997 <INITIAL>{COM_LINE}!{SER_CFG}{CR}               { count();
998                                                                                         sr_cfg_compat=SR_COMPAT_SER;}
999 <INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR}  { count(); 
1000                                                                                         sr_cfg_compat=SR_COMPAT_KAMAILIO;}
1001 <INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR} { count(); 
1002                                                                                                 sr_cfg_compat=SR_COMPAT_MAX;}
1003 <INITIAL>{COM_LINE}.*{CR}       { count(); }
1004
1005 <INITIAL>{ID}                   { count(); addstr(&s_buf, yytext, yyleng);
1006                                                                         yylval.strval=s_buf.s;
1007                                                                         memset(&s_buf, 0, sizeof(s_buf));
1008                                                                         return ID; }
1009
1010 <SELECT>.               { unput(yytext[0]); state = INITIAL_S; BEGIN(INITIAL); } /* Rescan the token in INITIAL state */
1011
1012
1013 <<EOF>>                                                 {
1014                                                                         switch(state){
1015                                                                                 case STR_BETWEEN_S:
1016                                                                                         state=old_state;
1017                                                                                         BEGIN(old_initial);
1018                                                                                         yylval.strval=s_buf.s;
1019                                                                                         memset(&s_buf, 0, sizeof(s_buf));
1020                                                                                         return STRING;
1021                                                                                 case STRING_S:
1022                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
1023                                                                                                                 " unclosed string\n");
1024                                                                                         if (s_buf.s){
1025                                                                                                 pkg_free(s_buf.s);
1026                                                                                                 memset(&s_buf, 0,
1027                                                                                                                         sizeof(s_buf));
1028                                                                                         }
1029                                                                                         break;
1030                                                                                 case COMMENT_S:
1031                                                                                         LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
1032                                                                                                                 " %d comments open\n", comment_nest);
1033                                                                                         break;
1034                                                                                 case COMMENT_LN_S:
1035                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF:"
1036                                                                                                                 "comment line open\n");
1037                                                                                         break;
1038                                                                                 case  ATTR_S:
1039                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1040                                                                                                         " while parsing"
1041                                                                                                         " avp name\n");
1042                                                                                         break;
1043                                                                                 case PVARID_S:
1044                                                                                         p_nest=0;
1045                                                                                 case PVAR_P_S: 
1046                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1047                                                                                                         " while parsing pvar name"
1048                                                                                                         " (%d paranthesis open)\n",
1049                                                                                                         p_nest);
1050                                                                                         break;
1051                                                                                 case AVP_PVAR_S:
1052                                                                                         LOG(L_CRIT, "ERROR: unexpected EOF"
1053                                                                                                         " while parsing"
1054                                                                                                         " avp or pvar name\n");
1055                                                                         }
1056                                                                         return 0;
1057                                                                 }
1058
1059 %%
1060
1061
1062 static char* addchar(struct str_buf* dst, char c)
1063 {
1064         return addstr(dst, &c, 1);
1065 }
1066
1067
1068
1069 static char* addstr(struct str_buf* dst_b, char* src, int len)
1070 {
1071         char *tmp;
1072         unsigned size;
1073         unsigned used;
1074
1075         if (dst_b->left<(len+1)){
1076                 used=(unsigned)(dst_b->crt-dst_b->s);
1077                 size=used+len+1;
1078                 /* round up to next multiple */
1079                 size+= STR_BUF_ALLOC_UNIT-size%STR_BUF_ALLOC_UNIT;
1080                 tmp=pkg_malloc(size);
1081                 if (tmp==0) goto error;
1082                 if (dst_b->s){
1083                         memcpy(tmp, dst_b->s, used);
1084                         pkg_free(dst_b->s);
1085                 }
1086                 dst_b->s=tmp;
1087                 dst_b->crt=dst_b->s+used;
1088                 dst_b->left=size-used;
1089         }
1090         memcpy(dst_b->crt, src, len);
1091         dst_b->crt+=len;
1092         *(dst_b->crt)=0;
1093         dst_b->left-=len;
1094
1095         return dst_b->s;
1096 error:
1097         LOG(L_CRIT, "ERROR:lex:addstr: memory allocation error\n");
1098         return 0;
1099 }
1100
1101
1102
1103 /** helper function for count_*(). */
1104 static void count_lc(int* l, int* c)
1105 {
1106         int i;
1107         for (i=0; i<yyleng;i++){
1108                 if (yytext[i]=='\n'){
1109                         (*l)++;
1110                         (*c)=1;
1111                 }else if (yytext[i]=='\t'){
1112                         (*c)++;
1113                         /*(*c)+=8 -((*c)%8);*/
1114                 }else{
1115                         (*c)++;
1116                 }
1117         }
1118 }
1119
1120
1121
1122 /* helper function */
1123 static void count_restore_ignored()
1124 {
1125         if (ign_lines) /* ignored line(s) => column has changed */
1126                 column=ign_columns;
1127         else
1128                 column+=ign_columns;
1129         line+=ign_lines;
1130         ign_lines=ign_columns=0;
1131 }
1132
1133
1134
1135 /** count/record position for stuff added to the current token. */
1136 static void count_more()
1137 {
1138         count_restore_ignored();
1139         count_lc(&line, &column);
1140 }
1141
1142
1143
1144 /** count/record position for a new token. */
1145 static void count()
1146 {
1147         count_restore_ignored();
1148         startline=line;
1149         startcolumn=column;
1150         count_more();
1151 }
1152
1153
1154
1155 /** record discarded stuff (not contained in the token) so that
1156     the next token position can be adjusted properly*/
1157 static void count_ignore()
1158 {
1159         count_lc(&ign_lines, &ign_columns);
1160 }
1161
1162
1163 /* replacement yywrap, removes libfl dependency */
1164 int yywrap()
1165 {
1166         return 1;
1167 }