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