PageRenderTime 63ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/cfg.y

https://bitbucket.org/viraptor/opensips-mirror
Happy | 2510 lines | 2374 code | 136 blank | 0 comment | 0 complexity | d444a1806e877ef5f6df0e2cd1413a9e MD5 | raw file
Possible License(s): AGPL-1.0
  1. /*
  2. * $Id$
  3. *
  4. * cfg grammar
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. * Copyright (C) 2005-2009 Voice Sistem S.R.L.
  8. * Copyright (C) 2006 enum.at
  9. *
  10. * This file is part of opensips, a free SIP server.
  11. *
  12. * opensips is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version
  16. *
  17. * opensips is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. /*
  27. * History:
  28. * ---------
  29. * 2003-01-29 src_port added (jiri)
  30. * 2003-01-23 mhomed added (jiri)
  31. * 2003-03-19 replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
  32. * 2003-03-19 Added support for route type in find_export (janakj)
  33. * 2003-03-20 Regex support in modparam (janakj)
  34. * 2003-04-01 added dst_port, proto , af (andrei)
  35. * 2003-04-05 s/reply_route/failure_route, onreply_route introduced (jiri)
  36. * 2003-04-12 added force_rport, chroot and wdir (andrei)
  37. * 2003-04-15 added tcp_children, disable_tcp (andrei)
  38. * 2003-04-22 strip_tail added (jiri)
  39. * 2003-07-03 tls* (disable, certificate, private_key, ca_list, verify,
  40. * require_certificate added (andrei)
  41. * 2003-07-06 more tls config. vars added: tls_method, tls_port_no (andrei)
  42. * 2003-10-02 added {,set_}advertised_{address,port} (andrei)
  43. * 2003-10-10 added <,>,<=,>=, != operators support
  44. * added msg:len (andrei)
  45. * 2003-10-11 if(){} doesn't require a ';' after it anymore (andrei)
  46. * 2003-10-13 added FIFO_DIR & proto:host:port listen/alias support (andrei)
  47. * 2003-10-24 converted to the new socket_info lists (andrei)
  48. * 2003-10-28 added tcp_accept_aliases (andrei)
  49. * 2003-11-20 added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
  50. * 2004-03-30 added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
  51. * 2004-04-29 added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
  52. * 2004-05-03 applied multicast support patch (MCAST_LOOPBACK) from janakj
  53. added MCAST_TTL (andrei)
  54. * 2004-07-05 src_ip & dst_ip will detect ip addresses between quotes
  55. * (andrei)
  56. * 2004-10-19 added FROM_URI, TO_URI (andrei)
  57. * 2004-11-30 added force_send_socket (andrei)
  58. * 2005-07-08 added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
  59. * (andrei)
  60. * 2005-07-26 default onreply route added (andrei)
  61. * 2005-11-22 added tos configurability (thanks to Andreas Granig)
  62. * 2005-11-29 added serialize_branches and next_branches (bogdan)
  63. * 2006-03-02 MODULE_T action points to a cmd_export_t struct instead to
  64. * a function address - more info is accessible (bogdan)
  65. * 2006-03-02 store the cfg line into the action struct to be able to
  66. * give more hints if fixups fail (bogdan)
  67. * 2006-05-22 forward(_udp,_tcp,_tls) and send(_tcp) merged in forward() and
  68. * send() (bogdan)
  69. * 2006-12-22 functions for script and branch flags added (bogdan)
  70. * 2007-01-11 auto_aliases option added (bogdan)
  71. * 2007-01-25 disable_dns_failover option added (bogdan)
  72. */
  73. %{
  74. #include <stdlib.h>
  75. #include <stdio.h>
  76. #include <sys/types.h>
  77. #include <sys/socket.h>
  78. #include <sys/stat.h>
  79. #include <unistd.h>
  80. #include <netinet/in.h>
  81. #include <netinet/in_systm.h>
  82. #include <netinet/ip.h>
  83. #include <arpa/inet.h>
  84. #include <string.h>
  85. #include <errno.h>
  86. #include "route_struct.h"
  87. #include "globals.h"
  88. #include "route.h"
  89. #include "dprint.h"
  90. #include "sr_module.h"
  91. #include "modparam.h"
  92. #include "ip_addr.h"
  93. #include "resolve.h"
  94. #include "socket_info.h"
  95. #include "name_alias.h"
  96. #include "ut.h"
  97. #include "dset.h"
  98. #include "pvar.h"
  99. #include "blacklists.h"
  100. #include "xlog.h"
  101. #include "config.h"
  102. #ifdef USE_TLS
  103. #include "tls/tls_config.h"
  104. #include "tls/tls_domain.h"
  105. #endif
  106. #ifdef DEBUG_DMALLOC
  107. #include <dmalloc.h>
  108. #endif
  109. /* hack to avoid alloca usage in the generated C file (needed for compiler
  110. with no built in alloca, like icc*/
  111. #undef _ALLOCA_H
  112. extern int yylex();
  113. static void yyerror(char* s);
  114. static void yyerrorf(char* fmt, ...);
  115. static char* tmp;
  116. static int i_tmp;
  117. static void* cmd_tmp;
  118. static struct socket_id* lst_tmp;
  119. static int rt; /* Type of route block for find_export */
  120. static str* str_tmp;
  121. static str s_tmp;
  122. static str tstr;
  123. static struct ip_addr* ip_tmp;
  124. static pv_spec_t *spec;
  125. static pv_elem_t *pvmodel;
  126. static struct bl_rule *bl_head = 0;
  127. static struct bl_rule *bl_tail = 0;
  128. static struct stat statf;
  129. action_elem_t elems[MAX_ACTION_ELEMS];
  130. #if !defined(USE_TLS) || !defined(USE_TCP) || !defined(USE_MCAST)
  131. static void warn(char* s);
  132. #endif
  133. static struct socket_id* mk_listen_id(char*, int, int);
  134. static struct socket_id* set_listen_id_adv(struct socket_id *, char *, int);
  135. static char *mpath=NULL;
  136. static char mpath_buf[256];
  137. static int mpath_len = 0;
  138. extern int line;
  139. #define mk_action0(_res, _type, _p1_type, _p2_type, _p1, _p2) \
  140. do { \
  141. _res = mk_action(_type, 0, 0, line); \
  142. } while(0)
  143. #define mk_action1(_res, _type, _p1_type, _p1) \
  144. do { \
  145. elems[0].type = _p1_type; \
  146. elems[0].u.data = _p1; \
  147. _res = mk_action(_type, 1, elems, line); \
  148. } while(0)
  149. #define mk_action2(_res, _type, _p1_type, _p2_type, _p1, _p2) \
  150. do { \
  151. elems[0].type = _p1_type; \
  152. elems[0].u.data = _p1; \
  153. elems[1].type = _p2_type; \
  154. elems[1].u.data = _p2; \
  155. _res = mk_action(_type, 2, elems, line); \
  156. } while(0)
  157. #define mk_action3(_res, _type, _p1_type, _p2_type, _p3_type, _p1, _p2, _p3) \
  158. do { \
  159. elems[0].type = _p1_type; \
  160. elems[0].u.data = _p1; \
  161. elems[1].type = _p2_type; \
  162. elems[1].u.data = _p2; \
  163. elems[2].type = _p3_type; \
  164. elems[2].u.data = _p3; \
  165. _res = mk_action(_type, 3, elems, line); \
  166. } while(0)
  167. %}
  168. %union {
  169. long intval;
  170. unsigned long uval;
  171. char* strval;
  172. struct expr* expr;
  173. struct action* action;
  174. struct net* ipnet;
  175. struct ip_addr* ipaddr;
  176. struct socket_id* sockid;
  177. struct _pv_spec *specval;
  178. }
  179. /* terminals */
  180. /* keywords */
  181. %token FORWARD
  182. %token SEND
  183. %token DROP
  184. %token EXIT
  185. %token RETURN
  186. %token LOG_TOK
  187. %token ERROR
  188. %token ROUTE
  189. %token ROUTE_FAILURE
  190. %token ROUTE_ONREPLY
  191. %token ROUTE_BRANCH
  192. %token ROUTE_ERROR
  193. %token ROUTE_LOCAL
  194. %token ROUTE_STARTUP
  195. %token ROUTE_TIMER
  196. %token SET_HOST
  197. %token SET_HOSTPORT
  198. %token PREFIX
  199. %token STRIP
  200. %token STRIP_TAIL
  201. %token APPEND_BRANCH
  202. %token PV_PRINTF
  203. %token SET_USER
  204. %token SET_USERPASS
  205. %token SET_PORT
  206. %token SET_URI
  207. %token REVERT_URI
  208. %token SET_DSTURI
  209. %token RESET_DSTURI
  210. %token ISDSTURISET
  211. %token FORCE_RPORT
  212. %token FORCE_LOCAL_RPORT
  213. %token FORCE_TCP_ALIAS
  214. %token IF
  215. %token ELSE
  216. %token SWITCH
  217. %token CASE
  218. %token DEFAULT
  219. %token SBREAK
  220. %token WHILE
  221. %token SET_ADV_ADDRESS
  222. %token SET_ADV_PORT
  223. %token FORCE_SEND_SOCKET
  224. %token SERIALIZE_BRANCHES
  225. %token NEXT_BRANCHES
  226. %token USE_BLACKLIST
  227. %token UNUSE_BLACKLIST
  228. %token MAX_LEN
  229. %token SETDEBUG
  230. %token SETFLAG
  231. %token RESETFLAG
  232. %token ISFLAGSET
  233. %token SETBFLAG
  234. %token RESETBFLAG
  235. %token ISBFLAGSET
  236. %token SETSFLAG
  237. %token RESETSFLAG
  238. %token ISSFLAGSET
  239. %token METHOD
  240. %token URI
  241. %token FROM_URI
  242. %token TO_URI
  243. %token SRCIP
  244. %token SRCPORT
  245. %token DSTIP
  246. %token DSTPORT
  247. %token PROTO
  248. %token AF
  249. %token MYSELF
  250. %token MSGLEN
  251. %token UDP
  252. %token TCP
  253. %token TLS
  254. %token SCTP
  255. %token NULLV
  256. %token CACHE_STORE
  257. %token CACHE_FETCH
  258. %token CACHE_REMOVE
  259. %token XDBG
  260. %token XLOG
  261. %token XLOG_BUF_SIZE
  262. %token XLOG_FORCE_COLOR
  263. /* config vars. */
  264. %token DEBUG
  265. %token FORK
  266. %token LOGSTDERROR
  267. %token LOGFACILITY
  268. %token LOGNAME
  269. %token AVP_ALIASES
  270. %token LISTEN
  271. %token ALIAS
  272. %token AUTO_ALIASES
  273. %token DNS
  274. %token REV_DNS
  275. %token DNS_TRY_IPV6
  276. %token DNS_RETR_TIME
  277. %token DNS_RETR_NO
  278. %token DNS_SERVERS_NO
  279. %token DNS_USE_SEARCH
  280. %token MAX_WHILE_LOOPS
  281. %token PORT
  282. %token CHILDREN
  283. %token CHECK_VIA
  284. %token MEMLOG
  285. %token MEMDUMP
  286. %token SIP_WARNING
  287. %token SOCK_MODE
  288. %token SOCK_USER
  289. %token SOCK_GROUP
  290. %token UNIX_SOCK
  291. %token UNIX_SOCK_CHILDREN
  292. %token UNIX_TX_TIMEOUT
  293. %token SERVER_SIGNATURE
  294. %token SERVER_HEADER
  295. %token USER_AGENT_HEADER
  296. %token LOADMODULE
  297. %token MPATH
  298. %token MODPARAM
  299. %token MAXBUFFER
  300. %token USER
  301. %token GROUP
  302. %token CHROOT
  303. %token WDIR
  304. %token MHOMED
  305. %token DISABLE_TCP
  306. %token TCP_ACCEPT_ALIASES
  307. %token TCP_CHILDREN
  308. %token TCP_CONNECT_TIMEOUT
  309. %token TCP_SEND_TIMEOUT
  310. %token TCP_CON_LIFETIME
  311. %token TCP_POLL_METHOD
  312. %token TCP_MAX_CONNECTIONS
  313. %token TCP_OPT_CRLF_PINGPONG
  314. %token DISABLE_TLS
  315. %token TLSLOG
  316. %token TLS_PORT_NO
  317. %token TLS_METHOD
  318. %token TLS_HANDSHAKE_TIMEOUT
  319. %token TLS_SEND_TIMEOUT
  320. %token TLS_SERVER_DOMAIN
  321. %token TLS_CLIENT_DOMAIN
  322. %token TLS_CLIENT_DOMAIN_AVP
  323. %token SSLv23
  324. %token SSLv2
  325. %token SSLv3
  326. %token TLSv1
  327. %token TLS_VERIFY_CLIENT
  328. %token TLS_VERIFY_SERVER
  329. %token TLS_REQUIRE_CLIENT_CERTIFICATE
  330. %token TLS_CERTIFICATE
  331. %token TLS_PRIVATE_KEY
  332. %token TLS_CA_LIST
  333. %token TLS_CIPHERS_LIST
  334. %token ADVERTISED_ADDRESS
  335. %token ADVERTISED_PORT
  336. %token DISABLE_CORE
  337. %token OPEN_FD_LIMIT
  338. %token MCAST_LOOPBACK
  339. %token MCAST_TTL
  340. %token TOS
  341. %token DISABLE_DNS_FAILOVER
  342. %token DISABLE_DNS_BLACKLIST
  343. %token DST_BLACKLIST
  344. %token DISABLE_STATELESS_FWD
  345. %token DB_VERSION_TABLE
  346. /* operators */
  347. %nonassoc EQUAL
  348. %nonassoc EQUAL_T
  349. %nonassoc GT
  350. %nonassoc LT
  351. %nonassoc GTE
  352. %nonassoc LTE
  353. %nonassoc DIFF
  354. %nonassoc MATCH
  355. %nonassoc NOTMATCH
  356. %nonassoc COLONEQ
  357. %nonassoc PLUSEQ
  358. %nonassoc MINUSEQ
  359. %nonassoc SLASHEQ
  360. %nonassoc MULTEQ
  361. %nonassoc MODULOEQ
  362. %nonassoc BANDEQ
  363. %nonassoc BOREQ
  364. %nonassoc BXOREQ
  365. %left OR AND
  366. %left BOR BAND BXOR BLSHIFT BRSHIFT
  367. %left PLUS MINUS SLASH MULT MODULO
  368. %right NOT BNOT
  369. /* values */
  370. %token <intval> NUMBER
  371. %token <intval> ZERO
  372. %token <strval> ID
  373. %token <strval> STRING
  374. %token <strval> SCRIPTVAR
  375. %token <strval> IPV6ADDR
  376. /* other */
  377. %token COMMA
  378. %token SEMICOLON
  379. %token RPAREN
  380. %token LPAREN
  381. %token LBRACE
  382. %token RBRACE
  383. %token LBRACK
  384. %token RBRACK
  385. %token SLASH
  386. %token AS
  387. %token DOT
  388. %token CR
  389. %token COLON
  390. %token ANY
  391. %token SCRIPTVARERR
  392. /*non-terminals */
  393. %type <expr> exp exp_elem exp_cond assignexp /*, condition*/
  394. %type <action> action actions cmd if_cmd stm exp_stm assign_cmd while_cmd
  395. %type <action> switch_cmd switch_stm case_stms case_stm default_stm
  396. %type <intval> module_func_param
  397. %type <ipaddr> ipv4 ipv6 ipv6addr ip
  398. %type <ipnet> ipnet
  399. %type <specval> script_var
  400. %type <strval> host
  401. %type <strval> listen_id
  402. %type <sockid> id_lst
  403. %type <sockid> phostport
  404. %type <intval> proto port
  405. %type <strval> host_sep
  406. %type <intval> uri_type
  407. %type <intval> equalop compop matchop strop intop
  408. %type <intval> assignop
  409. %type <intval> snumber
  410. %type <strval> route_name
  411. %%
  412. cfg: statements
  413. ;
  414. statements: statements statement {}
  415. | statement {}
  416. | statements error { yyerror(""); YYABORT;}
  417. ;
  418. statement: assign_stm
  419. | module_stm
  420. | {rt=REQUEST_ROUTE;} route_stm
  421. | {rt=FAILURE_ROUTE;} failure_route_stm
  422. | {rt=ONREPLY_ROUTE;} onreply_route_stm
  423. | {rt=BRANCH_ROUTE;} branch_route_stm
  424. | {rt=ERROR_ROUTE;} error_route_stm
  425. | {rt=LOCAL_ROUTE;} local_route_stm
  426. | {rt=STARTUP_ROUTE;} startup_route_stm
  427. | {rt=TIMER_ROUTE;} timer_route_stm
  428. | CR /* null statement*/
  429. ;
  430. listen_id: ip { tmp=ip_addr2a($1);
  431. if(tmp==0){
  432. LM_CRIT("cfg. parser: bad ip address.\n");
  433. $$=0;
  434. }else{
  435. $$=pkg_malloc(strlen(tmp)+1);
  436. if ($$==0){
  437. LM_CRIT("cfg. parser: out of memory.\n");
  438. }else{
  439. strncpy($$, tmp, strlen(tmp)+1);
  440. }
  441. }
  442. }
  443. | STRING { $$=pkg_malloc(strlen($1)+1);
  444. if ($$==0){
  445. LM_CRIT("cfg. parser: out of memory.\n");
  446. }else{
  447. strncpy($$, $1, strlen($1)+1);
  448. }
  449. }
  450. | host { if ($1==0) {
  451. $$ = 0;
  452. } else {
  453. $$=pkg_malloc(strlen($1)+1);
  454. if ($$==0){
  455. LM_CRIT("cfg. parser: out of memory.\n");
  456. }else{
  457. strncpy($$, $1, strlen($1)+1);
  458. }
  459. }
  460. }
  461. ;
  462. proto: UDP { $$=PROTO_UDP; }
  463. | TCP { $$=PROTO_TCP; }
  464. | TLS {
  465. #ifdef USE_TLS
  466. $$=PROTO_TLS;
  467. #else
  468. $$=PROTO_TCP;
  469. warn("tls support not compiled in");
  470. #endif
  471. }
  472. | SCTP {
  473. #ifdef USE_SCTP
  474. $$=PROTO_SCTP;
  475. #else
  476. yyerror("sctp support not compiled in\n");YYABORT;
  477. #endif
  478. }
  479. | ANY { $$=0; }
  480. ;
  481. port: NUMBER { $$=$1; }
  482. | ANY { $$=0; }
  483. ;
  484. snumber: NUMBER { $$=$1; }
  485. | PLUS NUMBER { $$=$2; }
  486. | MINUS NUMBER { $$=-$2; }
  487. ;
  488. phostport: listen_id { $$=mk_listen_id($1, 0, 0); }
  489. | listen_id COLON port { $$=mk_listen_id($1, 0, $3); }
  490. | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
  491. | proto COLON listen_id COLON port { $$=mk_listen_id($3, $1, $5);}
  492. | phostport AS listen_id { set_listen_id_adv((struct socket_id *)$1, $3, 5060); }
  493. | phostport AS listen_id COLON port{ set_listen_id_adv((struct socket_id *)$1, $3, $5); }
  494. | listen_id COLON error { $$=0; yyerror(" port number expected"); }
  495. ;
  496. id_lst: phostport { $$=$1 ; }
  497. | phostport id_lst { $$=$1; $$->next=$2; }
  498. ;
  499. blst_elem: LPAREN proto COMMA ipnet COMMA port COMMA STRING RPAREN {
  500. s_tmp.s=$8;
  501. s_tmp.len=strlen($8);
  502. if (add_rule_to_list(&bl_head,&bl_tail,$4,&s_tmp,$6,$2,0)) {
  503. yyerror("failed to add backlist element\n");YYABORT;
  504. }
  505. }
  506. | NOT LPAREN proto COMMA ipnet COMMA port COMMA STRING RPAREN {
  507. s_tmp.s=$9;
  508. s_tmp.len=strlen($9);
  509. if (add_rule_to_list(&bl_head,&bl_tail,$5,&s_tmp,
  510. $7,$3,BLR_APPLY_CONTRARY)) {
  511. yyerror("failed to add backlist element\n");YYABORT;
  512. }
  513. }
  514. ;
  515. blst_elem_list: blst_elem_list COMMA blst_elem {}
  516. | blst_elem {}
  517. | blst_elem_list error { yyerror("bad black list element");}
  518. ;
  519. assign_stm: DEBUG EQUAL snumber {
  520. #ifdef CHANGEABLE_DEBUG_LEVEL
  521. *debug=$3;
  522. #else
  523. debug=$3;
  524. #endif
  525. }
  526. | DEBUG EQUAL error { yyerror("number expected"); }
  527. | FORK EQUAL NUMBER { dont_fork= ! $3; }
  528. | FORK EQUAL error { yyerror("boolean value expected"); }
  529. | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
  530. | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
  531. | LOGFACILITY EQUAL ID {
  532. if ( (i_tmp=str2facility($3))==-1)
  533. yyerror("bad facility (see syslog(3) man page)");
  534. if (!config_check)
  535. log_facility=i_tmp;
  536. }
  537. | LOGFACILITY EQUAL error { yyerror("ID expected"); }
  538. | LOGNAME EQUAL STRING { log_name=$3; }
  539. | LOGNAME EQUAL error { yyerror("string value expected"); }
  540. | AVP_ALIASES EQUAL STRING {
  541. if ($3!=0 && $3[0]!=0)
  542. if ( add_avp_galias_str($3)!=0 )
  543. yyerror("invalid AVP aliases");;
  544. }
  545. | AVP_ALIASES EQUAL error { yyerror("string value expected"); }
  546. | DNS EQUAL NUMBER { received_dns|= ($3)?DO_DNS:0; }
  547. | DNS EQUAL error { yyerror("boolean value expected"); }
  548. | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
  549. | REV_DNS EQUAL error { yyerror("boolean value expected"); }
  550. | DNS_TRY_IPV6 EQUAL NUMBER { dns_try_ipv6=$3; }
  551. | DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
  552. | DNS_RETR_TIME EQUAL NUMBER { dns_retr_time=$3; }
  553. | DNS_RETR_TIME error { yyerror("number expected"); }
  554. | DNS_RETR_NO EQUAL NUMBER { dns_retr_no=$3; }
  555. | DNS_RETR_NO error { yyerror("number expected"); }
  556. | DNS_SERVERS_NO EQUAL NUMBER { dns_servers_no=$3; }
  557. | DNS_SERVERS_NO error { yyerror("number expected"); }
  558. | DNS_USE_SEARCH EQUAL NUMBER { dns_search_list=$3; }
  559. | DNS_USE_SEARCH error { yyerror("boolean value expected"); }
  560. | PORT EQUAL NUMBER { port_no=$3; }
  561. | PORT EQUAL error { yyerror("number expected"); }
  562. | MAX_WHILE_LOOPS EQUAL NUMBER { max_while_loops=$3; }
  563. | MAX_WHILE_LOOPS EQUAL error { yyerror("number expected"); }
  564. | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
  565. | MAXBUFFER EQUAL error { yyerror("number expected"); }
  566. | CHILDREN EQUAL NUMBER { children_no=$3; }
  567. | CHILDREN EQUAL error { yyerror("number expected"); }
  568. | CHECK_VIA EQUAL NUMBER { check_via=$3; }
  569. | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
  570. | MEMLOG EQUAL NUMBER { memlog=$3; memdump=$3; }
  571. | MEMLOG EQUAL error { yyerror("int value expected"); }
  572. | MEMDUMP EQUAL NUMBER { memdump=$3; }
  573. | MEMDUMP EQUAL error { yyerror("int value expected"); }
  574. | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
  575. | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
  576. | USER EQUAL STRING { user=$3; }
  577. | USER EQUAL ID { user=$3; }
  578. | USER EQUAL error { yyerror("string value expected"); }
  579. | GROUP EQUAL STRING { group=$3; }
  580. | GROUP EQUAL ID { group=$3; }
  581. | GROUP EQUAL error { yyerror("string value expected"); }
  582. | CHROOT EQUAL STRING { chroot_dir=$3; }
  583. | CHROOT EQUAL ID { chroot_dir=$3; }
  584. | CHROOT EQUAL error { yyerror("string value expected"); }
  585. | WDIR EQUAL STRING { working_dir=$3; }
  586. | WDIR EQUAL ID { working_dir=$3; }
  587. | WDIR EQUAL error { yyerror("string value expected"); }
  588. | MHOMED EQUAL NUMBER { mhomed=$3; }
  589. | MHOMED EQUAL error { yyerror("boolean value expected"); }
  590. | DISABLE_TCP EQUAL NUMBER {
  591. #ifdef USE_TCP
  592. tcp_disable=$3;
  593. #else
  594. warn("tcp support not compiled in");
  595. #endif
  596. }
  597. | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
  598. | TCP_ACCEPT_ALIASES EQUAL NUMBER {
  599. #ifdef USE_TCP
  600. tcp_accept_aliases=$3;
  601. #else
  602. warn("tcp support not compiled in");
  603. #endif
  604. }
  605. | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
  606. | TCP_CHILDREN EQUAL NUMBER {
  607. #ifdef USE_TCP
  608. tcp_children_no=$3;
  609. #else
  610. warn("tcp support not compiled in");
  611. #endif
  612. }
  613. | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
  614. | TCP_CONNECT_TIMEOUT EQUAL NUMBER {
  615. #ifdef USE_TCP
  616. tcp_connect_timeout=$3;
  617. #else
  618. warn("tcp support not compiled in");
  619. #endif
  620. }
  621. | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
  622. | TCP_SEND_TIMEOUT EQUAL NUMBER {
  623. #ifdef USE_TCP
  624. tcp_send_timeout=$3;
  625. #else
  626. warn("tcp support not compiled in");
  627. #endif
  628. }
  629. | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
  630. | TCP_CON_LIFETIME EQUAL NUMBER {
  631. #ifdef USE_TCP
  632. tcp_con_lifetime=$3;
  633. #else
  634. warn("tcp support not compiled in");
  635. #endif
  636. }
  637. | TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
  638. | TCP_POLL_METHOD EQUAL ID {
  639. #ifdef USE_TCP
  640. tcp_poll_method=get_poll_type($3);
  641. if (tcp_poll_method==POLL_NONE){
  642. LM_CRIT("bad poll method name:"
  643. " %s\n, try one of %s.\n",
  644. $3, poll_support);
  645. yyerror("bad tcp_poll_method "
  646. "value");
  647. }
  648. #else
  649. warn("tcp support not compiled in");
  650. #endif
  651. }
  652. | TCP_POLL_METHOD EQUAL STRING {
  653. #ifdef USE_TCP
  654. tcp_poll_method=get_poll_type($3);
  655. if (tcp_poll_method==POLL_NONE){
  656. LM_CRIT("bad poll method name:"
  657. " %s\n, try one of %s.\n",
  658. $3, poll_support);
  659. yyerror("bad tcp_poll_method "
  660. "value");
  661. }
  662. #else
  663. warn("tcp support not compiled in");
  664. #endif
  665. }
  666. | TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
  667. | TCP_MAX_CONNECTIONS EQUAL NUMBER {
  668. #ifdef USE_TCP
  669. tcp_max_connections=$3;
  670. #else
  671. warn("tcp support not compiled in");
  672. #endif
  673. }
  674. | TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
  675. | TCP_OPT_CRLF_PINGPONG EQUAL NUMBER {
  676. #ifdef USE_TCP
  677. tcp_crlf_pingpong=$3;
  678. #else
  679. warn("tcp support not compiled in");
  680. #endif
  681. }
  682. | TCP_OPT_CRLF_PINGPONG EQUAL error { yyerror("boolean value expected"); }
  683. | DISABLE_TLS EQUAL NUMBER {
  684. #ifdef USE_TLS
  685. tls_disable=$3;
  686. #else
  687. warn("tls support not compiled in");
  688. #endif
  689. }
  690. | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
  691. | TLSLOG EQUAL NUMBER {
  692. #ifdef USE_TLS
  693. tls_log=$3;
  694. #else
  695. warn("tls support not compiled in");
  696. #endif
  697. }
  698. | TLSLOG EQUAL error { yyerror("int value expected"); }
  699. | TLS_PORT_NO EQUAL NUMBER {
  700. #ifdef USE_TLS
  701. tls_port_no=$3;
  702. #else
  703. warn("tls support not compiled in");
  704. #endif
  705. }
  706. | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
  707. | TLS_METHOD EQUAL SSLv23 {
  708. #ifdef USE_TLS
  709. tls_default_server_domain->method =
  710. TLS_USE_SSLv23;
  711. tls_default_client_domain->method =
  712. TLS_USE_SSLv23;
  713. #else
  714. warn("tls support not compiled in");
  715. #endif
  716. }
  717. | TLS_METHOD EQUAL SSLv2 {
  718. #ifdef USE_TLS
  719. tls_default_server_domain->method =
  720. TLS_USE_SSLv2;
  721. tls_default_client_domain->method =
  722. TLS_USE_SSLv2;
  723. #else
  724. warn("tls support not compiled in");
  725. #endif
  726. }
  727. | TLS_METHOD EQUAL SSLv3 {
  728. #ifdef USE_TLS
  729. tls_default_server_domain->method =
  730. TLS_USE_SSLv3;
  731. tls_default_client_domain->method =
  732. TLS_USE_SSLv3;
  733. #else
  734. warn("tls support not compiled in");
  735. #endif
  736. }
  737. | TLS_METHOD EQUAL TLSv1 {
  738. #ifdef USE_TLS
  739. tls_default_server_domain->method =
  740. TLS_USE_TLSv1;
  741. tls_default_client_domain->method =
  742. TLS_USE_TLSv1;
  743. #else
  744. warn("tls support not compiled in");
  745. #endif
  746. }
  747. | TLS_METHOD EQUAL error {
  748. #ifdef USE_TLS
  749. yyerror("SSLv23, SSLv2, SSLv3 or TLSv1"
  750. " expected");
  751. #else
  752. warn("tls support not compiled in");
  753. #endif
  754. }
  755. | TLS_VERIFY_CLIENT EQUAL NUMBER {
  756. #ifdef USE_TLS
  757. tls_default_server_domain->verify_cert
  758. = $3;
  759. #else
  760. warn("tls support not compiled in");
  761. #endif
  762. }
  763. | TLS_VERIFY_CLIENT EQUAL error { yyerror("boolean value expected"); }
  764. | TLS_VERIFY_SERVER EQUAL NUMBER {
  765. #ifdef USE_TLS
  766. tls_default_client_domain->verify_cert
  767. =$3;
  768. #else
  769. warn("tls support not compiled in");
  770. #endif
  771. }
  772. | TLS_VERIFY_SERVER EQUAL error { yyerror("boolean value expected"); }
  773. | TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL NUMBER {
  774. #ifdef USE_TLS
  775. tls_default_server_domain->require_client_cert=$3;
  776. #else
  777. warn( "tls support not compiled in");
  778. #endif
  779. }
  780. | TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
  781. | TLS_CERTIFICATE EQUAL STRING {
  782. #ifdef USE_TLS
  783. tls_default_server_domain->cert_file=
  784. $3;
  785. tls_default_client_domain->cert_file=
  786. $3;
  787. #else
  788. warn("tls support not compiled in");
  789. #endif
  790. }
  791. | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
  792. | TLS_PRIVATE_KEY EQUAL STRING {
  793. #ifdef USE_TLS
  794. tls_default_server_domain->pkey_file=
  795. $3;
  796. tls_default_client_domain->pkey_file=
  797. $3;
  798. #else
  799. warn("tls support not compiled in");
  800. #endif
  801. }
  802. | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
  803. | TLS_CA_LIST EQUAL STRING {
  804. #ifdef USE_TLS
  805. tls_default_server_domain->ca_file =
  806. $3;
  807. tls_default_client_domain->ca_file =
  808. $3;
  809. #else
  810. warn("tls support not compiled in");
  811. #endif
  812. }
  813. | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
  814. | TLS_CIPHERS_LIST EQUAL STRING {
  815. #ifdef USE_TLS
  816. tls_default_server_domain->ciphers_list
  817. = $3;
  818. tls_default_client_domain->ciphers_list
  819. = $3;
  820. #else
  821. warn("tls support not compiled in");
  822. #endif
  823. }
  824. | TLS_CIPHERS_LIST EQUAL error { yyerror("string value expected"); }
  825. | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
  826. #ifdef USE_TLS
  827. tls_handshake_timeout=$3;
  828. #else
  829. warn("tls support not compiled in");
  830. #endif
  831. }
  832. | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
  833. | TLS_SEND_TIMEOUT EQUAL NUMBER {
  834. #ifdef USE_TLS
  835. tls_send_timeout=$3;
  836. #else
  837. warn("tls support not compiled in");
  838. #endif
  839. }
  840. | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
  841. | TLS_CLIENT_DOMAIN_AVP EQUAL NUMBER {
  842. #ifdef USE_TLS
  843. tls_client_domain_avp=$3;
  844. #else
  845. warn("tls support not compiled in");
  846. #endif
  847. }
  848. | TLS_CLIENT_DOMAIN_AVP EQUAL error { yyerror("number expected"); }
  849. | tls_server_domain_stm
  850. | tls_client_domain_stm
  851. | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
  852. | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
  853. | SERVER_HEADER EQUAL STRING { server_header.s=$3;
  854. server_header.len=strlen($3);
  855. }
  856. | SERVER_HEADER EQUAL error { yyerror("string value expected"); }
  857. | USER_AGENT_HEADER EQUAL STRING { user_agent_header.s=$3;
  858. user_agent_header.len=strlen($3);
  859. }
  860. | USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
  861. | XLOG_BUF_SIZE EQUAL NUMBER { xlog_buf_size = $3; }
  862. | XLOG_FORCE_COLOR EQUAL NUMBER { xlog_force_color = $3; }
  863. | XLOG_BUF_SIZE EQUAL error { yyerror("number expected"); }
  864. | XLOG_FORCE_COLOR EQUAL error { yyerror("boolean value expected"); }
  865. | LISTEN EQUAL id_lst {
  866. for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
  867. if (add_listen_iface( lst_tmp->name,
  868. lst_tmp->port,
  869. lst_tmp->proto,
  870. lst_tmp->adv_name,
  871. lst_tmp->adv_port,
  872. 0
  873. )!=0){
  874. LM_CRIT("cfg. parser: failed"
  875. " to add listen address\n");
  876. break;
  877. }
  878. }
  879. }
  880. | LISTEN EQUAL error { yyerror("ip address or hostname "
  881. "expected (use quotes if the hostname includes"
  882. " config keywords)"); }
  883. | ALIAS EQUAL id_lst {
  884. for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
  885. add_alias(lst_tmp->name, strlen(lst_tmp->name),
  886. lst_tmp->port, lst_tmp->proto);
  887. }
  888. | ALIAS EQUAL error { yyerror("hostname expected (use quotes"
  889. " if the hostname includes config keywords)"); }
  890. | AUTO_ALIASES EQUAL NUMBER { auto_aliases=$3; }
  891. | AUTO_ALIASES EQUAL error { yyerror("number expected"); }
  892. | ADVERTISED_ADDRESS EQUAL listen_id {
  893. if ($3) {
  894. default_global_address.s=$3;
  895. default_global_address.len=strlen($3);
  896. }
  897. }
  898. |ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname "
  899. "expected"); }
  900. | ADVERTISED_PORT EQUAL NUMBER {
  901. tmp=int2str($3, &i_tmp);
  902. if ((default_global_port.s=pkg_malloc(i_tmp))
  903. ==0){
  904. LM_CRIT("cfg. parser: out of memory.\n");
  905. default_global_port.len=0;
  906. }else{
  907. default_global_port.len=i_tmp;
  908. memcpy(default_global_port.s, tmp,
  909. default_global_port.len);
  910. };
  911. }
  912. |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname "
  913. "expected"); }
  914. | DISABLE_CORE EQUAL NUMBER {
  915. disable_core_dump=$3;
  916. }
  917. | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
  918. | OPEN_FD_LIMIT EQUAL NUMBER {
  919. open_files_limit=$3;
  920. }
  921. | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
  922. | MCAST_LOOPBACK EQUAL NUMBER {
  923. #ifdef USE_MCAST
  924. mcast_loopback=$3;
  925. #else
  926. warn("no multicast support compiled in");
  927. #endif
  928. }
  929. | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
  930. | MCAST_TTL EQUAL NUMBER {
  931. #ifdef USE_MCAST
  932. mcast_ttl=$3;
  933. #else
  934. warn("no multicast support compiled in");
  935. #endif
  936. }
  937. | MCAST_TTL EQUAL error { yyerror("number expected as tos"); }
  938. | TOS EQUAL NUMBER { tos = $3;
  939. if (tos<=0)
  940. yyerror("invalid tos value");
  941. }
  942. | TOS EQUAL ID { if (strcasecmp($3,"IPTOS_LOWDELAY")) {
  943. tos=IPTOS_LOWDELAY;
  944. } else if (strcasecmp($3,"IPTOS_THROUGHPUT")) {
  945. tos=IPTOS_THROUGHPUT;
  946. } else if (strcasecmp($3,"IPTOS_RELIABILITY")) {
  947. tos=IPTOS_RELIABILITY;
  948. #if defined(IPTOS_MINCOST)
  949. } else if (strcasecmp($3,"IPTOS_MINCOST")) {
  950. tos=IPTOS_MINCOST;
  951. #endif
  952. #if defined(IPTOS_LOWCOST)
  953. } else if (strcasecmp($3,"IPTOS_LOWCOST")) {
  954. tos=IPTOS_LOWCOST;
  955. #endif
  956. } else {
  957. yyerror("invalid tos value - allowed: "
  958. "IPTOS_LOWDELAY,IPTOS_THROUGHPUT,"
  959. "IPTOS_RELIABILITY"
  960. #if defined(IPTOS_LOWCOST)
  961. ",IPTOS_LOWCOST"
  962. #endif
  963. #if defined(IPTOS_MINCOST)
  964. ",IPTOS_MINCOST"
  965. #endif
  966. "\n");
  967. }
  968. }
  969. | TOS EQUAL error { yyerror("number expected"); }
  970. | MPATH EQUAL STRING { mpath=$3; strcpy(mpath_buf, $3);
  971. mpath_len=strlen($3);
  972. if(mpath_buf[mpath_len-1]!='/') {
  973. mpath_buf[mpath_len]='/';
  974. mpath_len++;
  975. mpath_buf[mpath_len]='\0';
  976. }
  977. }
  978. | MPATH EQUAL error { yyerror("string value expected"); }
  979. | DISABLE_DNS_FAILOVER EQUAL NUMBER {
  980. disable_dns_failover=$3;
  981. }
  982. | DISABLE_DNS_FAILOVER error { yyerror("boolean value expected"); }
  983. | DISABLE_DNS_BLACKLIST EQUAL NUMBER {
  984. disable_dns_blacklist=$3;
  985. }
  986. | DISABLE_DNS_BLACKLIST error { yyerror("boolean value expected"); }
  987. | DST_BLACKLIST EQUAL ID COLON LBRACE blst_elem_list RBRACE {
  988. s_tmp.s = $3;
  989. s_tmp.len = strlen($3);
  990. if ( create_bl_head( BL_CORE_ID, BL_READONLY_LIST,
  991. bl_head, bl_tail, &s_tmp)==0) {
  992. yyerror("failed to create blacklist\n");
  993. YYABORT;
  994. }
  995. bl_head = bl_tail = 0;
  996. }
  997. | DISABLE_STATELESS_FWD EQUAL NUMBER {
  998. sl_fwd_disabled=$3;
  999. }
  1000. | DB_VERSION_TABLE EQUAL STRING { db_version_table=$3; }
  1001. | DB_VERSION_TABLE EQUAL error { yyerror("string value expected"); }
  1002. | error EQUAL { yyerror("unknown config variable"); }
  1003. ;
  1004. module_stm: LOADMODULE STRING {
  1005. if(*$2!='/' && mpath!=NULL
  1006. && strlen($2)+mpath_len<255)
  1007. {
  1008. strcpy(mpath_buf+mpath_len, $2);
  1009. if (stat(mpath_buf, &statf) == -1) {
  1010. i_tmp = strlen(mpath_buf);
  1011. if(strchr($2, '/')==NULL &&
  1012. strncmp(mpath_buf+i_tmp-3, ".so", 3)==0)
  1013. {
  1014. if(i_tmp+strlen($2)<255)
  1015. {
  1016. strcpy(mpath_buf+i_tmp-3, "/");
  1017. strcpy(mpath_buf+i_tmp-2, $2);
  1018. if (stat(mpath_buf, &statf) == -1) {
  1019. mpath_buf[mpath_len]='\0';
  1020. LM_ERR("module '%s' not found in '%s'\n",
  1021. $2, mpath_buf);
  1022. yyerror("failed to load module");
  1023. }
  1024. } else {
  1025. yyerror("failed to load module - path too long");
  1026. }
  1027. } else {
  1028. yyerror("failed to load module - not found");
  1029. }
  1030. }
  1031. LM_DBG("loading module %s\n", mpath_buf);
  1032. if (sr_load_module(mpath_buf)!=0){
  1033. yyerror("failed to load module");
  1034. }
  1035. mpath_buf[mpath_len]='\0';
  1036. } else {
  1037. LM_DBG("loading module %s\n", $2);
  1038. if (sr_load_module($2)!=0){
  1039. yyerror("failed to load module");
  1040. }
  1041. }
  1042. }
  1043. | LOADMODULE error { yyerror("string expected"); }
  1044. | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
  1045. if (set_mod_param_regex($3, $5, STR_PARAM, $7) != 0) {
  1046. yyerrorf("Parameter <%s> not found in module <%s> - can't set",
  1047. $5, $3);
  1048. }
  1049. }
  1050. | MODPARAM LPAREN STRING COMMA STRING COMMA snumber RPAREN {
  1051. if (set_mod_param_regex($3, $5, INT_PARAM, (void*)$7) != 0) {
  1052. yyerrorf("Parameter <%s> not found in module <%s> - can't set",
  1053. $5, $3);
  1054. }
  1055. }
  1056. | MODPARAM error { yyerror("Invalid arguments"); }
  1057. ;
  1058. ip: ipv4 { $$=$1; }
  1059. |ipv6 { $$=$1; }
  1060. ;
  1061. ipv4: NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
  1062. $$=pkg_malloc(
  1063. sizeof(struct ip_addr));
  1064. if ($$==0){
  1065. LM_CRIT("cfg. "
  1066. "parser: out of memory.\n"
  1067. );
  1068. }else{
  1069. memset($$, 0,
  1070. sizeof(struct ip_addr));
  1071. $$->af=AF_INET;
  1072. $$->len=4;
  1073. if (($1>255) || ($1<0) ||
  1074. ($3>255) || ($3<0) ||
  1075. ($5>255) || ($5<0) ||
  1076. ($7>255) || ($7<0)){
  1077. yyerror("invalid ipv4"
  1078. "address");
  1079. $$->u.addr32[0]=0;
  1080. /* $$=0; */
  1081. }else{
  1082. $$->u.addr[0]=$1;
  1083. $$->u.addr[1]=$3;
  1084. $$->u.addr[2]=$5;
  1085. $$->u.addr[3]=$7;
  1086. /*
  1087. $$=htonl( ($1<<24)|
  1088. ($3<<16)| ($5<<8)|$7 );
  1089. */
  1090. }
  1091. }
  1092. }
  1093. ;
  1094. ipv6addr: IPV6ADDR {
  1095. $$=pkg_malloc(sizeof(struct ip_addr));
  1096. if ($$==0){
  1097. LM_CRIT("ERROR: cfg. parser: out of memory.\n");
  1098. }else{
  1099. memset($$, 0, sizeof(struct ip_addr));
  1100. $$->af=AF_INET6;
  1101. $$->len=16;
  1102. #ifdef USE_IPV6
  1103. if (inet_pton(AF_INET6, $1, $$->u.addr)<=0){
  1104. yyerror("bad ipv6 address");
  1105. }
  1106. #else
  1107. yyerror("ipv6 address & no ipv6 support compiled in");
  1108. YYABORT;
  1109. #endif
  1110. }
  1111. }
  1112. ;
  1113. ipv6: ipv6addr { $$=$1; }
  1114. | LBRACK ipv6addr RBRACK {$$=$2; }
  1115. ;
  1116. tls_server_domain_stm : TLS_SERVER_DOMAIN LBRACK ip COLON port RBRACK {
  1117. #ifdef USE_TLS
  1118. if (tls_new_server_domain($3, $5))
  1119. yyerror("tls_new_server_domain failed");
  1120. #else
  1121. warn("tls support not compiled in");
  1122. #endif
  1123. }
  1124. LBRACE tls_server_decls RBRACE
  1125. ;
  1126. tls_client_domain_stm : TLS_CLIENT_DOMAIN LBRACK ip COLON port RBRACK {
  1127. #ifdef USE_TLS
  1128. if (tls_new_client_domain($3, $5))
  1129. yyerror("tls_new_client_domain failed");
  1130. #else
  1131. warn("tls support not compiled in");
  1132. #endif
  1133. }
  1134. LBRACE tls_client_decls RBRACE
  1135. ;
  1136. tls_client_domain_stm : TLS_CLIENT_DOMAIN LBRACK STRING RBRACK {
  1137. #ifdef USE_TLS
  1138. if (tls_new_client_domain_name($3, strlen($3)))
  1139. yyerror("tls_new_client_domain_name failed");
  1140. #else
  1141. warn("tls support not compiled in");
  1142. #endif
  1143. }
  1144. LBRACE tls_client_decls RBRACE
  1145. ;
  1146. tls_server_decls : tls_server_var
  1147. | tls_server_decls tls_server_var
  1148. ;
  1149. tls_client_decls : tls_client_var
  1150. | tls_client_decls tls_client_var
  1151. ;
  1152. tls_server_var : TLS_METHOD EQUAL SSLv23 {
  1153. #ifdef USE_TLS
  1154. tls_server_domains->method=TLS_USE_SSLv23;
  1155. #else
  1156. warn("tls support not compiled in");
  1157. #endif
  1158. }
  1159. | TLS_METHOD EQUAL SSLv2 {
  1160. #ifdef USE_TLS
  1161. tls_server_domains->method=TLS_USE_SSLv2;
  1162. #else
  1163. warn("tls support not compiled in");
  1164. #endif
  1165. }
  1166. | TLS_METHOD EQUAL SSLv3 {
  1167. #ifdef USE_TLS
  1168. tls_server_domains->method=TLS_USE_SSLv3;
  1169. #else
  1170. warn("tls support not compiled in");
  1171. #endif
  1172. }
  1173. | TLS_METHOD EQUAL TLSv1 {
  1174. #ifdef USE_TLS
  1175. tls_server_domains->method=TLS_USE_TLSv1;
  1176. #else
  1177. warn("tls support not compiled in");
  1178. #endif
  1179. }
  1180. | TLS_METHOD EQUAL error { yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected"); }
  1181. | TLS_CERTIFICATE EQUAL STRING {
  1182. #ifdef USE_TLS
  1183. tls_server_domains->cert_file=$3;
  1184. #else
  1185. warn("tls support not compiled in");
  1186. #endif
  1187. }
  1188. | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
  1189. | TLS_PRIVATE_KEY EQUAL STRING {
  1190. #ifdef USE_TLS
  1191. tls_server_domains->pkey_file=$3;
  1192. #else
  1193. warn("tls support not compiled in");
  1194. #endif
  1195. }
  1196. | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
  1197. | TLS_CA_LIST EQUAL STRING {
  1198. #ifdef USE_TLS
  1199. tls_server_domains->ca_file=$3;
  1200. #else
  1201. warn("tls support not compiled in");
  1202. #endif
  1203. }
  1204. | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
  1205. | TLS_CIPHERS_LIST EQUAL STRING {
  1206. #ifdef USE_TLS
  1207. tls_server_domains->ciphers_list=$3;
  1208. #else
  1209. warn("tls support not compiled in");
  1210. #endif
  1211. }
  1212. | TLS_CIPHERS_LIST EQUAL error { yyerror("string value expected"); }
  1213. | TLS_VERIFY_CLIENT EQUAL NUMBER {
  1214. #ifdef USE_TLS
  1215. tls_server_domains->verify_cert=$3;
  1216. #else
  1217. warn("tls support not compiled in");
  1218. #endif
  1219. }
  1220. | TLS_VERIFY_CLIENT EQUAL error { yyerror("boolean value expected"); }
  1221. | TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL NUMBER {
  1222. #ifdef USE_TLS
  1223. tls_server_domains->require_client_cert=$3;
  1224. #else
  1225. warn( "tls support not compiled in");
  1226. #endif
  1227. }
  1228. | TLS_REQUIRE_CLIENT_CERTIFICATE EQUAL error {
  1229. yyerror("boolean value expected"); }
  1230. ;
  1231. tls_client_var : TLS_METHOD EQUAL SSLv23 {
  1232. #ifdef USE_TLS
  1233. tls_client_domains->method=TLS_USE_SSLv23;
  1234. #else
  1235. warn("tls support not compiled in");
  1236. #endif
  1237. }
  1238. | TLS_METHOD EQUAL SSLv2 {
  1239. #ifdef USE_TLS
  1240. tls_client_domains->method=TLS_USE_SSLv2;
  1241. #else
  1242. warn("tls support not compiled in");
  1243. #endif
  1244. }
  1245. | TLS_METHOD EQUAL SSLv3 {
  1246. #ifdef USE_TLS
  1247. tls_client_domains->method=TLS_USE_SSLv3;
  1248. #else
  1249. warn("tls support not compiled in");
  1250. #endif
  1251. }
  1252. | TLS_METHOD EQUAL TLSv1 {
  1253. #ifdef USE_TLS
  1254. tls_client_domains->method=TLS_USE_TLSv1;
  1255. #else
  1256. warn("tls support not compiled in");
  1257. #endif
  1258. }
  1259. | TLS_METHOD EQUAL error {
  1260. yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected"); }
  1261. | TLS_CERTIFICATE EQUAL STRING {
  1262. #ifdef USE_TLS
  1263. tls_client_domains->cert_file=$3;
  1264. #else
  1265. warn("tls support not compiled in");
  1266. #endif
  1267. }
  1268. | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
  1269. | TLS_PRIVATE_KEY EQUAL STRING {
  1270. #ifdef USE_TLS
  1271. tls_client_domains->pkey_file=$3;
  1272. #else
  1273. warn("tls support not compiled in");
  1274. #endif
  1275. }
  1276. | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
  1277. | TLS_CA_LIST EQUAL STRING {
  1278. #ifdef USE_TLS
  1279. tls_client_domains->ca_file=$3;
  1280. #else
  1281. warn("tls support not compiled in");
  1282. #endif
  1283. }
  1284. | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
  1285. | TLS_CIPHERS_LIST EQUAL STRING {
  1286. #ifdef USE_TLS
  1287. tls_client_domains->ciphers_list=$3;
  1288. #else
  1289. warn("tls support not compiled in");
  1290. #endif
  1291. }
  1292. | TLS_CIPHERS_LIST EQUAL error { yyerror("string value expected"); }
  1293. | TLS_VERIFY_SERVER EQUAL NUMBER {
  1294. #ifdef USE_TLS
  1295. tls_client_domains->verify_cert=$3;
  1296. #else
  1297. warn("tls support not compiled in");
  1298. #endif
  1299. }
  1300. | TLS_VERIFY_SERVER EQUAL error { yyerror("boolean value expected"); }
  1301. ;
  1302. route_name: ID {
  1303. $$ = $1;
  1304. }
  1305. | NUMBER {
  1306. tmp=int2str($1, &i_tmp);
  1307. if (($$=pkg_malloc(i_tmp+1))==0)
  1308. yyerror("cfg. parser: out of memory.\n");
  1309. memcpy( $$, tmp, i_tmp);
  1310. $$[i_tmp] = 0;
  1311. }
  1312. |STRING {
  1313. $$ = $1;
  1314. }
  1315. ;
  1316. route_stm: ROUTE LBRACE actions RBRACE {
  1317. if (rlist[DEFAULT_RT].a!=0) {
  1318. yyerror("overwritting default "
  1319. "request routing table");
  1320. YYABORT;
  1321. }
  1322. push($3, &rlist[DEFAULT_RT].a);
  1323. }
  1324. | ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
  1325. if ( strtol($3,&tmp,10)==0 && *tmp==0) {
  1326. /* route[0] detected */
  1327. if (rlist[DEFAULT_RT].a!=0) {
  1328. yyerror("overwritting(2) default "
  1329. "request routing table");
  1330. YYABORT;
  1331. }
  1332. push($6, &rlist[DEFAULT_RT].a);
  1333. } else {
  1334. i_tmp = get_script_route_idx($3,rlist,RT_NO,1);
  1335. if (i_tmp==-1) YYABORT;
  1336. push($6, &rlist[i_tmp].a);
  1337. }
  1338. }
  1339. | ROUTE error { yyerror("invalid route statement"); }
  1340. ;
  1341. failure_route_stm: ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
  1342. i_tmp = get_script_route_idx($3,failure_rlist,
  1343. FAILURE_RT_NO,1);
  1344. if (i_tmp==-1) YYABORT;
  1345. push($6, &failure_rlist[i_tmp].a);
  1346. }
  1347. | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
  1348. ;
  1349. onreply_route_stm: ROUTE_ONREPLY LBRACE actions RBRACE {
  1350. if (onreply_rlist[DEFAULT_RT].a!=0) {
  1351. yyerror("overwritting default "
  1352. "onreply routing table");
  1353. YYABORT;
  1354. }
  1355. push($3, &onreply_rlist[DEFAULT_RT].a);
  1356. }
  1357. | ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
  1358. i_tmp = get_script_route_idx($3,onreply_rlist,
  1359. ONREPLY_RT_NO,1);
  1360. if (i_tmp==-1) YYABORT;
  1361. push($6, &onreply_rlist[i_tmp].a);
  1362. }
  1363. | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
  1364. ;
  1365. branch_route_stm: ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
  1366. i_tmp = get_script_route_idx($3,branch_rlist,
  1367. BRANCH_RT_NO,1);
  1368. if (i_tmp==-1) YYABORT;
  1369. push($6, &branch_rlist[i_tmp].a);
  1370. }
  1371. | ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
  1372. ;
  1373. error_route_stm: ROUTE_ERROR LBRACE actions RBRACE {
  1374. if (error_rlist.a!=0) {
  1375. yyerror("overwritting default "
  1376. "error routing table");
  1377. YYABORT;
  1378. }
  1379. push($3, &error_rlist.a);
  1380. }
  1381. | ROUTE_ERROR error { yyerror("invalid error_route statement"); }
  1382. ;
  1383. local_route_stm: ROUTE_LOCAL LBRACE actions RBRACE {
  1384. if (local_rlist.a!=0) {
  1385. yyerror("re-definition of local "
  1386. "route detected");
  1387. YYABORT;
  1388. }
  1389. push($3, &local_rlist.a);
  1390. }
  1391. | ROUTE_LOCAL error { yyerror("invalid local_route statement"); }
  1392. ;
  1393. startup_route_stm: ROUTE_STARTUP LBRACE actions RBRACE {
  1394. if (startup_rlist.a!=0) {
  1395. yyerror("re-definition of startup "
  1396. "route detected");
  1397. YYABORT;
  1398. }
  1399. push($3, &startup_rlist.a);
  1400. }
  1401. | ROUTE_STARTUP error { yyerror("invalid startup_route statement"); }
  1402. ;
  1403. timer_route_stm: ROUTE_TIMER LBRACK route_name COMMA NUMBER RBRACK LBRACE actions RBRACE {
  1404. i_tmp = 0;
  1405. while (timer_rlist[i_tmp].a!=0 && i_tmp < TIMER_RT_NO) {
  1406. i_tmp++;
  1407. }
  1408. if(i_tmp == TIMER_RT_NO) {
  1409. yyerror("Too many timer routes defined\n");
  1410. YYABORT;
  1411. }
  1412. timer_rlist[i_tmp].interval = $5;
  1413. push($8, &timer_rlist[i_tmp].a);
  1414. }
  1415. | ROUTE_TIMER error { yyerror("invalid timer_route statement"); }
  1416. ;
  1417. exp: exp AND exp { $$=mk_exp(AND_OP, $1, $3); }
  1418. | exp OR exp { $$=mk_exp(OR_OP, $1, $3); }
  1419. | NOT exp { $$=mk_exp(NOT_OP, $2, 0); }
  1420. | LPAREN exp RPAREN { $$=mk_exp(EVAL_OP, $2, 0); }
  1421. | LBRACK assignexp RBRACK { $$=$2; }
  1422. | exp_elem { $$=$1; }
  1423. ;
  1424. equalop: EQUAL_T {$$=EQUAL_OP; }
  1425. | DIFF {$$=DIFF_OP; }
  1426. ;
  1427. compop: GT {$$=GT_OP; }
  1428. | LT {$$=LT_OP; }
  1429. | GTE {$$=GTE_OP; }
  1430. | LTE {$$=LTE_OP; }
  1431. ;
  1432. matchop: MATCH {$$=MATCH_OP; }
  1433. | NOTMATCH {$$=NOTMATCH_OP; }
  1434. ;
  1435. intop: equalop {$$=$1; }
  1436. | compop {$$=$1; }
  1437. ;
  1438. strop: equalop {$$=$1; }
  1439. | compop {$$=$1; }
  1440. | matchop {$$=$1; }
  1441. ;
  1442. uri_type: URI {$$=URI_O;}
  1443. | FROM_URI {$$=FROM_URI_O;}
  1444. | TO_URI {$$=TO_URI_O;}
  1445. ;
  1446. script_var: SCRIPTVAR {
  1447. spec = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t));
  1448. if (spec==NULL){
  1449. yyerror("no more pkg memory\n");
  1450. }
  1451. memset(spec, 0, sizeof(pv_spec_t));
  1452. tstr.s = $1;
  1453. tstr.len = strlen(tstr.s);
  1454. if(pv_parse_spec(&tstr, spec)==NULL)
  1455. {
  1456. yyerror("unknown script variable");
  1457. }
  1458. $$ = spec;
  1459. }
  1460. | SCRIPTVARERR {
  1461. $$=0; yyerror("invalid script variable name");
  1462. }
  1463. ;
  1464. exp_elem: exp_cond {$$=$1; }
  1465. | exp_stm {$$=mk_elem( NO_OP, ACTION_O, 0, ACTIONS_ST, $1 ); }
  1466. | snumber {$$=mk_elem( NO_OP, NUMBER_O, 0, NUMBER_ST,
  1467. (void*)$1 ); }
  1468. | script_var {
  1469. $$=mk_elem(NO_OP, SCRIPTVAR_O,0,SCRIPTVAR_ST,(void*)$1);
  1470. }
  1471. | uri_type strop host {$$ = mk_elem($2, $1, 0, STR_ST, $3);
  1472. }
  1473. | DSTIP equalop ipnet { $$=mk_elem($2, DSTIP_O, 0, NET_ST, $3);
  1474. }
  1475. | DSTIP strop host { $$=mk_elem($2, DSTIP_O, 0, STR_ST, $3);
  1476. }
  1477. | SRCIP equalop ipnet { $$=mk_elem($2, SRCIP_O, 0, NET_ST, $3);
  1478. }
  1479. | SRCIP strop host { $$=mk_elem($2, SRCIP_O, 0, STR_ST, $3);
  1480. }
  1481. ;
  1482. exp_cond: METHOD strop STRING {$$= mk_elem($2, METHOD_O, 0, STR_ST, $3);
  1483. }
  1484. | METHOD strop ID {$$ = mk_elem($2, METHOD_O, 0, STR_ST, $3);
  1485. }
  1486. | METHOD strop error { $$=0; yyerror("string expected"); }
  1487. | METHOD error { $$=0; yyerror("invalid operator,"
  1488. "== , !=, or =~ expected");
  1489. }
  1490. | script_var strop script_var {
  1491. $$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,SCRIPTVAR_ST,(void*)$3);
  1492. }
  1493. | script_var strop STRING {
  1494. $$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,STR_ST,$3);
  1495. }
  1496. | script_var strop ID {
  1497. $$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,STR_ST,$3);
  1498. }
  1499. | script_var intop snumber {
  1500. $$=mk_elem( $2, SCRIPTVAR_O,(void*)$1,NUMBER_ST,(void *)$3);
  1501. }
  1502. | script_var equalop MYSELF {
  1503. $$=mk_elem( $2, SCRIPTVAR_O,(void*)$1, MYSELF_ST, 0);
  1504. }
  1505. | script_var equalop NULLV {
  1506. $$=mk_elem( $2, SCRIPTVAR_O,(void*)$1, NULLV_ST, 0);
  1507. }
  1508. | uri_type strop STRING {$$ = mk_elem($2, $1, 0, STR_ST, $3);
  1509. }
  1510. | uri_type equalop MYSELF { $$=mk_elem($2, $1, 0, MYSELF_ST, 0);
  1511. }
  1512. | uri_type strop error { $$=0; yyerror("string or MYSELF expected"); }
  1513. | uri_type error { $$=0; yyerror("invalid operator,"
  1514. " == , != or =~ expected");
  1515. }
  1516. | SRCPORT intop NUMBER { $$=mk_elem($2, SRCPORT_O, 0, NUMBER_ST,
  1517. (void *) $3 ); }
  1518. | SRCPORT intop error { $$=0; yyerror("number expected"); }
  1519. | SRCPORT error { $$=0; yyerror("==, !=, <,>, >= or <= expected"); }
  1520. | DSTPORT intop NUMBER { $$=mk_elem($2, DSTPORT_O, 0, NUMBER_ST,
  1521. (void *) $3 ); }
  1522. | DSTPORT intop error { $$=0; yyerror("number expected"); }
  1523. | DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <= expected"); }
  1524. | PROTO intop proto { $$=mk_elem($2, PROTO_O, 0, NUMBER_ST,
  1525. (void *) $3 ); }
  1526. | PROTO intop error { $$=0;
  1527. yyerror("protocol expected (udp, tcp or tls)");
  1528. }
  1529. | PROTO error { $$=0; yyerror("equal/!= operator expected"); }
  1530. | AF intop NUMBER { $$=mk_elem($2, AF_O, 0, NUMBER_ST,
  1531. (void *) $3 ); }
  1532. | AF intop error { $$=0; yyerror("number expected"); }
  1533. | AF error { $$=0; yyerror("equal/!= operator expected"); }
  1534. | MSGLEN intop NUMBER { $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST,
  1535. (void *) $3 ); }
  1536. | MSGLEN intop MAX_LEN { $$=mk_elem($2, MSGLEN_O, 0, NUMBER_ST,
  1537. (void *) BUF_SIZE); }
  1538. | MSGLEN intop error { $$=0; yyerror("number expected"); }
  1539. | MSGLEN error { $$=0; yyerror("equal/!= operator expected"); }
  1540. | SRCIP strop STRING { s_tmp.s=$3;
  1541. s_tmp.len=strlen($3);
  1542. ip_tmp=str2ip(&s_tmp);
  1543. if (ip_tmp==0)
  1544. ip_tmp=str2ip6(&s_tmp);
  1545. if (ip_tmp){
  1546. $$=mk_elem($2, SRCIP_O, 0, NET_ST,
  1547. mk_net_bitlen(ip_tmp,
  1548. ip_tmp->len*8) );
  1549. }else{
  1550. $$=mk_elem($2, SRCIP_O, 0, STR_ST,
  1551. $3);
  1552. }
  1553. }
  1554. | SRCIP equalop MYSELF { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0);
  1555. }
  1556. | SRCIP strop error { $$=0; yyerror( "ip address or hostname"
  1557. "expected" ); }
  1558. | SRCIP error { $$=0;
  1559. yyerror("invalid operator, ==, != or =~ expected");}
  1560. | DSTIP strop STRING { s_tmp.s=$3;
  1561. s_tmp.len=strlen($3);
  1562. ip_tmp=str2ip(&s_tmp);
  1563. if (ip_tmp==0)
  1564. ip_tmp=str2ip6(&s_tmp);
  1565. if (ip_tmp){
  1566. $$=mk_elem($2, DSTIP_O, 0, NET_ST,
  1567. mk_net_bitlen(ip_tmp,
  1568. ip_tmp->len*8) );
  1569. }else{
  1570. $$=mk_elem($2, DSTIP_O, 0, STR_ST,
  1571. $3);
  1572. }
  1573. }
  1574. | DSTIP equalop MYSELF { $$=mk_elem($2, DSTIP_O, 0, MYSELF_ST, 0);
  1575. }
  1576. | DSTIP strop error { $$=0; yyerror( "ip address or hostname"
  1577. "expected" ); }
  1578. | DSTIP error { $$=0;
  1579. yyerror("invalid operator, ==, != or =~ expected");}
  1580. | MYSELF equalop uri_type { $$=mk_elem($2, $3, 0, MYSELF_ST, 0);
  1581. }
  1582. | MYSELF equalop SRCIP { $$=mk_elem($2, SRCIP_O, 0, MYSELF_ST, 0);
  1583. }
  1584. | MYSELF equalop DSTIP { $$=mk_elem($2, DSTIP_O, 0, MYSELF_ST, 0);
  1585. }
  1586. | MYSELF equalop error { $$=0;
  1587. yyerror(" URI, SRCIP or DSTIP expected"); }
  1588. | MYSELF error { $$=0;
  1589. yyerror ("invalid operator, == or != expected");
  1590. }
  1591. ;
  1592. ipnet: ip SLASH ip { $$=mk_net($1, $3); }
  1593. | ip SLASH NUMBER { if (($3<0) || ($3>(long)$1->len*8)){
  1594. yyerror("invalid bit number in netmask");
  1595. $$=0;
  1596. }else{
  1597. $$=mk_net_bitlen($1, $3);
  1598. /*
  1599. $$=mk_net($1,
  1600. htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
  1601. */
  1602. }
  1603. }
  1604. | ip { $$=mk_net_bitlen($1, $1->len*8); }
  1605. | ip SLASH error { $$=0;
  1606. yyerror("netmask (eg:255.0.0.0 or 8) expected");
  1607. }
  1608. ;
  1609. host_sep: DOT {$$=".";}
  1610. | MINUS {$$="-"; }
  1611. ;
  1612. host: ID { $$=$1; }
  1613. | host host_sep ID { $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
  1614. if ($$==0){
  1615. LM_CRIT("cfg. parser: memory allocation"
  1616. " failure while parsing host\n");
  1617. }else{
  1618. memcpy($$, $1, strlen($1));
  1619. $$[strlen($1)]=*$2;
  1620. memcpy($$+strlen($1)+1, $3, strlen($3));
  1621. $$[strlen($1)+1+strlen($3)]=0;
  1622. }
  1623. pkg_free($1); pkg_free($3);
  1624. }
  1625. | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname (use quotes if hostname has config keywords)"); }
  1626. ;
  1627. assignop:
  1628. EQUAL { $$ = EQ_T; }
  1629. | COLONEQ { $$ = COLONEQ_T; }
  1630. | PLUSEQ { $$ = PLUSEQ_T; }
  1631. | MINUSEQ { $$ = MINUSEQ_T;}
  1632. | SLASHEQ { $$ = DIVEQ_T; }
  1633. | MULTEQ { $$ = MULTEQ_T; }
  1634. | MODULOEQ { $$ = MODULOEQ_T; }
  1635. | BANDEQ { $$ = BANDEQ_T; }
  1636. | BOREQ { $$ = BOREQ_T; }
  1637. | BXOREQ { $$ = BXOREQ_T; }
  1638. ;
  1639. assignexp :
  1640. snumber { $$ = mk_elem(VALUE_OP, NUMBERV_O, (void*)$1, 0, 0); }
  1641. | STRING { $$ = mk_elem(VALUE_OP, STRINGV_O, $1, 0, 0); }
  1642. | ID { $$ = mk_elem(VALUE_OP, STRINGV_O, $1, 0, 0); }
  1643. | script_var { $$ = mk_elem(VALUE_OP, SCRIPTVAR_O, $1, 0, 0); }
  1644. | exp_cond { $$= $1; }
  1645. | cmd { $$=mk_elem( NO_OP, ACTION_O, 0, ACTIONS_ST, $1 ); }
  1646. | assignexp PLUS assignexp {
  1647. $$ = mk_elem(PLUS_OP, EXPR_O, $1, EXPR_ST, $3);
  1648. }
  1649. | assignexp MINUS assignexp {
  1650. $$ = mk_elem(MINUS_OP, EXPR_O, $1, EXPR_ST, $3);
  1651. }
  1652. | assignexp MULT assignexp {
  1653. $$ = mk_elem(MULT_OP, EXPR_O, $1, EXPR_ST, $3);
  1654. }
  1655. | assignexp SLASH assignexp {
  1656. $$ = mk_elem(DIV_OP, EXPR_O, $1, EXPR_ST, $3);
  1657. }
  1658. | assignexp MODULO assignexp {
  1659. $$ = mk_elem(MODULO_OP, EXPR_O, $1, EXPR_ST, $3);
  1660. }
  1661. | assignexp BAND assignexp {
  1662. $$ = mk_elem(BAND_OP, EXPR_O, $1, EXPR_ST, $3);
  1663. }
  1664. | assignexp BOR assignexp {
  1665. $$ = mk_elem(BOR_OP, EXPR_O, $1, EXPR_ST, $3);
  1666. }
  1667. | assignexp BXOR assignexp {
  1668. $$ = mk_elem(BXOR_OP, EXPR_O, $1, EXPR_ST, $3);
  1669. }
  1670. | assignexp BLSHIFT assignexp {
  1671. $$ = mk_elem(BLSHIFT_OP, EXPR_O, $1, EXPR_ST, $3);
  1672. }
  1673. | assignexp BRSHIFT assignexp {
  1674. $$ = mk_elem(BRSHIFT_OP, EXPR_O, $1, EXPR_ST, $3);
  1675. }
  1676. | BNOT assignexp {
  1677. $$ = mk_elem(BNOT_OP, EXPR_O, $2, 0, 0);
  1678. }
  1679. | LPAREN assignexp RPAREN { $$ = $2; }
  1680. ;
  1681. assign_cmd: script_var assignop assignexp {
  1682. if(!pv_is_w($1))
  1683. yyerror("invalid left operand in assignment");
  1684. if($1->trans!=0)
  1685. yyerror(
  1686. "transformations not accepted in right side of assignment");
  1687. mk_action2( $$, $2,
  1688. SCRIPTVAR_ST,
  1689. EXPR_ST,
  1690. $1,
  1691. $3);
  1692. }
  1693. | script_var EQUAL NULLV {
  1694. if(!pv_is_w($1))
  1695. yyerror("invalid left operand in assignment");
  1696. if($1->trans!=0)
  1697. yyerror(
  1698. "transformations not accepted in right side of assignment");
  1699. mk_action2( $$, EQ_T,
  1700. SCRIPTVAR_ST,
  1701. NULLV_ST,
  1702. $1,
  1703. 0);
  1704. }
  1705. | script_var COLONEQ NULLV {
  1706. if(!pv_is_w($1))
  1707. yyerror("invalid left operand in assignment");
  1708. /* not all can get NULL with := */
  1709. switch($1->type) {
  1710. case PVT_AVP:
  1711. break;
  1712. default:
  1713. yyerror("invalid left operand in NULL assignment");
  1714. }
  1715. if($1->trans!=0)
  1716. yyerror(
  1717. "transformations not accepted in right side of assignment");
  1718. mk_action2( $$, COLONEQ_T,
  1719. SCRIPTVAR_ST,
  1720. NULLV_ST,
  1721. $1,
  1722. 0);
  1723. }
  1724. ;
  1725. exp_stm: cmd { $$=$1; }
  1726. | if_cmd { $$=$1; }
  1727. | assign_cmd { $$=$1; }
  1728. | LBRACE actions RBRACE { $$=$2; }
  1729. | LBRACE RBRACE { $$=0; }
  1730. ;
  1731. stm: action { $$=$1; }
  1732. | LBRACE actions RBRACE { $$=$2; }
  1733. | LBRACE RBRACE { $$=0; }
  1734. ;
  1735. actions: actions action {$$=append_action($1, $2); }
  1736. | action {$$=$1;}
  1737. | actions error { $$=0; yyerror("bad command!)"); }
  1738. ;
  1739. action: cmd SEMICOLON {$$=$1;}
  1740. | if_cmd {$$=$1;}
  1741. | while_cmd { $$=$1;}
  1742. | switch_cmd {$$=$1;}
  1743. | assign_cmd SEMICOLON {$$=$1;}
  1744. | SEMICOLON /* null action */ {$$=0;}
  1745. | cmd error { $$=0; yyerror("bad command: missing ';'?"); }
  1746. ;
  1747. if_cmd: IF exp stm { mk_action3( $$, IF_T,
  1748. EXPR_ST,
  1749. ACTIONS_ST,
  1750. NOSUBTYPE,
  1751. $2,
  1752. $3,
  1753. 0);
  1754. }
  1755. | IF exp stm ELSE stm { mk_action3( $$, IF_T,
  1756. EXPR_ST,
  1757. ACTIONS_ST,
  1758. ACTIONS_ST,
  1759. $2,
  1760. $3,
  1761. $5);
  1762. }
  1763. ;
  1764. while_cmd: WHILE exp stm { mk_action2( $$, WHILE_T,
  1765. EXPR_ST,
  1766. ACTIONS_ST,
  1767. $2,
  1768. $3);
  1769. }
  1770. ;
  1771. switch_cmd: SWITCH LPAREN script_var RPAREN LBRACE switch_stm RBRACE {
  1772. mk_action2( $$, SWITCH_T,
  1773. SCRIPTVAR_ST,
  1774. ACTIONS_ST,
  1775. $3,
  1776. $6);
  1777. }
  1778. ;
  1779. switch_stm: case_stms default_stm { $$=append_action($1, $2); }
  1780. | case_stms { $$=$1; }
  1781. ;
  1782. case_stms: case_stms case_stm {$$=append_action($1, $2); }
  1783. | case_stm {$$=$1;}
  1784. ;
  1785. case_stm: CASE snumber COLON actions SBREAK SEMICOLON
  1786. { mk_action3( $$, CASE_T,
  1787. NUMBER_ST,
  1788. ACTIONS_ST,
  1789. NUMBER_ST,
  1790. (void*)$2,
  1791. $4,
  1792. (void*)1);
  1793. }
  1794. | CASE snumber COLON SBREAK SEMICOLON
  1795. { mk_action3( $$, CASE_T,
  1796. NUMBER_ST,
  1797. ACTIONS_ST,
  1798. NUMBER_ST,
  1799. (void*)$2,
  1800. 0,
  1801. (void*)1);
  1802. }
  1803. | CASE snumber COLON actions { mk_action3( $$, CASE_T,
  1804. NUMBER_ST,
  1805. ACTIONS_ST,
  1806. NUMBER_ST,
  1807. (void*)$2,
  1808. $4,
  1809. (void*)0);
  1810. }
  1811. | CASE snumber COLON { mk_action3( $$, CASE_T,
  1812. NUMBER_ST,
  1813. ACTIONS_ST,
  1814. NUMBER_ST,
  1815. (void*)$2,
  1816. 0,
  1817. (void*)0);
  1818. }
  1819. | CASE STRING COLON actions SBREAK SEMICOLON
  1820. { mk_action3( $$, CASE_T,
  1821. STR_ST,
  1822. ACTIONS_ST,
  1823. NUMBER_ST,
  1824. (void*)$2,
  1825. $4,
  1826. (void*)1);
  1827. }
  1828. | CASE STRING COLON SBREAK SEMICOLON
  1829. { mk_action3( $$, CASE_T,
  1830. STR_ST,
  1831. ACTIONS_ST,
  1832. NUMBER_ST,
  1833. (void*)$2,
  1834. 0,
  1835. (void*)1);
  1836. }
  1837. | CASE STRING COLON actions { mk_action3( $$, CASE_T,
  1838. STR_ST,
  1839. ACTIONS_ST,
  1840. NUMBER_ST,
  1841. (void*)$2,
  1842. $4,
  1843. (void*)0);
  1844. }
  1845. | CASE STRING COLON { mk_action3( $$, CASE_T,
  1846. STR_ST,
  1847. ACTIONS_ST,
  1848. NUMBER_ST,
  1849. (void*)$2,
  1850. 0,
  1851. (void*)0);
  1852. }
  1853. ;
  1854. default_stm: DEFAULT COLON actions { mk_action2( $$, DEFAULT_T,
  1855. ACTIONS_ST,
  1856. 0,
  1857. $3,
  1858. 0);
  1859. }
  1860. | DEFAULT COLON { mk_action2( $$, DEFAULT_T,
  1861. ACTIONS_ST,
  1862. 0,
  1863. 0,
  1864. 0);
  1865. }
  1866. ;
  1867. module_func_param: STRING {
  1868. elems[1].type = STRING_ST;
  1869. elems[1].u.data = $1;
  1870. $$=1;
  1871. }
  1872. | module_func_param COMMA STRING {
  1873. if ($1+1>=MAX_ACTION_ELEMS) {
  1874. yyerror("too many arguments in function\n");
  1875. $$=0;
  1876. }
  1877. elems[$1+1].type = STRING_ST;
  1878. elems[$1+1].u.data = $3;
  1879. $$=$1+1;
  1880. }
  1881. | NUMBER {
  1882. $$=0;
  1883. yyerror("numbers used as parameters - they should be quoted");
  1884. }
  1885. | module_func_param COMMA NUMBER {
  1886. $$=0;
  1887. yyerror("numbers used as parameters - they should be quoted");
  1888. }
  1889. ;
  1890. cmd: FORWARD LPAREN STRING RPAREN { mk_action2( $$, FORWARD_T,
  1891. STRING_ST,
  1892. 0,
  1893. $3,
  1894. 0);
  1895. }
  1896. | FORWARD LPAREN RPAREN {
  1897. mk_action2( $$, FORWARD_T,
  1898. 0,
  1899. 0,
  1900. 0,
  1901. 0);
  1902. }
  1903. | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
  1904. | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward "
  1905. "argument"); }
  1906. | SEND LPAREN STRING RPAREN { mk_action2( $$, SEND_T,
  1907. STRING_ST,
  1908. 0,
  1909. $3,
  1910. 0);
  1911. }
  1912. | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
  1913. | SEND LPAREN error RPAREN { $$=0; yyerror("bad send"
  1914. "argument"); }
  1915. | DROP LPAREN RPAREN {mk_action2( $$, DROP_T,0, 0, 0, 0); }
  1916. | DROP {mk_action2( $$, DROP_T,0, 0, 0, 0); }
  1917. | EXIT LPAREN RPAREN {mk_action2( $$, EXIT_T,0, 0, 0, 0); }
  1918. | EXIT {mk_action2( $$, EXIT_T,0, 0, 0, 0); }
  1919. | RETURN LPAREN snumber RPAREN {mk_action2( $$, RETURN_T,
  1920. NUMBER_ST,
  1921. 0,
  1922. (void*)$3,
  1923. 0);
  1924. }
  1925. | RETURN LPAREN script_var RPAREN {mk_action2( $$, RETURN_T,
  1926. SCRIPTVAR_ST,
  1927. 0,
  1928. (void*)$3,
  1929. 0);
  1930. }
  1931. | RETURN LPAREN RPAREN {mk_action2( $$, RETURN_T,
  1932. NUMBER_ST,
  1933. 0,
  1934. (void*)1,
  1935. 0);
  1936. }
  1937. | RETURN {mk_action2( $$, RETURN_T,
  1938. NUMBER_ST,
  1939. 0,
  1940. (void*)1,
  1941. 0);
  1942. }
  1943. | LOG_TOK LPAREN STRING RPAREN {mk_action2( $$, LOG_T, NUMBER_ST,
  1944. STRING_ST,(void*)4,$3);
  1945. }
  1946. | LOG_TOK LPAREN snumber COMMA STRING RPAREN {mk_action2( $$, LOG_T,
  1947. NUMBER_ST,
  1948. STRING_ST,
  1949. (void*)$3,
  1950. $5);
  1951. }
  1952. | LOG_TOK error { $$=0; yyerror("missing '(' or ')' ?"); }
  1953. | LOG_TOK LPAREN error RPAREN { $$=0; yyerror("bad log"
  1954. "argument"); }
  1955. | SETDEBUG LPAREN NUMBER RPAREN {mk_action2($$, SET_DEBUG_T, NUMBER_ST,
  1956. 0, (void *)$3, 0 ); }
  1957. | SETDEBUG LPAREN RPAREN {mk_action2( $$, SET_DEBUG_T, 0, 0, 0, 0 ); }
  1958. | SETDEBUG error { $$=0; yyerror("missing '(' or ')'?"); }
  1959. | SETFLAG LPAREN NUMBER RPAREN {mk_action2($$, SETFLAG_T, NUMBER_ST, 0,
  1960. (void *)$3, 0 ); }
  1961. | SETFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  1962. | RESETFLAG LPAREN NUMBER RPAREN {mk_action2( $$, RESETFLAG_T,
  1963. NUMBER_ST, 0, (void *)$3, 0 ); }
  1964. | RESETFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  1965. | ISFLAGSET LPAREN NUMBER RPAREN {mk_action2( $$, ISFLAGSET_T,
  1966. NUMBER_ST, 0, (void *)$3, 0 ); }
  1967. | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
  1968. | SETSFLAG LPAREN NUMBER RPAREN {mk_action2( $$, SETSFLAG_T, NUMBER_ST,
  1969. 0, (void *)$3, 0 ); }
  1970. | SETSFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  1971. | RESETSFLAG LPAREN NUMBER RPAREN {mk_action2( $$, RESETSFLAG_T,
  1972. NUMBER_ST, 0, (void *)$3, 0 ); }
  1973. | RESETSFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  1974. | ISSFLAGSET LPAREN NUMBER RPAREN {mk_action2( $$, ISSFLAGSET_T,
  1975. NUMBER_ST, 0, (void *)$3, 0 ); }
  1976. | ISSFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
  1977. | SETBFLAG LPAREN NUMBER COMMA NUMBER RPAREN {mk_action2( $$,
  1978. SETBFLAG_T,
  1979. NUMBER_ST, NUMBER_ST,
  1980. (void *)$3, (void *)$5 ); }
  1981. | SETBFLAG LPAREN NUMBER RPAREN {mk_action2( $$, SETBFLAG_T,
  1982. NUMBER_ST, NUMBER_ST,
  1983. 0, (void *)$3 ); }
  1984. | SETBFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  1985. | RESETBFLAG LPAREN NUMBER COMMA NUMBER RPAREN {mk_action2( $$,
  1986. RESETBFLAG_T,
  1987. NUMBER_ST, NUMBER_ST,
  1988. (void *)$3, (void *)$5 ); }
  1989. | RESETBFLAG LPAREN NUMBER RPAREN {mk_action2( $$,
  1990. RESETBFLAG_T,
  1991. NUMBER_ST, NUMBER_ST,
  1992. 0, (void *)$3 ); }
  1993. | RESETBFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  1994. | ISBFLAGSET LPAREN NUMBER COMMA NUMBER RPAREN {mk_action2( $$,
  1995. ISBFLAGSET_T,
  1996. NUMBER_ST, NUMBER_ST,
  1997. (void *)$3, (void *)$5 ); }
  1998. | ISBFLAGSET LPAREN NUMBER RPAREN {mk_action2( $$,
  1999. ISBFLAGSET_T,
  2000. NUMBER_ST, NUMBER_ST,
  2001. 0, (void *)$3 ); }
  2002. | ISBFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
  2003. | ERROR LPAREN STRING COMMA STRING RPAREN {mk_action2( $$, ERROR_T,
  2004. STRING_ST,
  2005. STRING_ST,
  2006. $3,
  2007. $5);
  2008. }
  2009. | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
  2010. | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error"
  2011. "argument"); }
  2012. | ROUTE LPAREN route_name RPAREN {
  2013. i_tmp = get_script_route_idx( $3, rlist, RT_NO, 0);
  2014. if (i_tmp==-1) yyerror("too many script routes");
  2015. mk_action2( $$, ROUTE_T, NUMBER_ST,
  2016. 0, (void*)(long)i_tmp, 0);
  2017. }
  2018. | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
  2019. | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route"
  2020. "argument"); }
  2021. | SET_HOST LPAREN STRING RPAREN { mk_action2( $$, SET_HOST_T, STR_ST,
  2022. 0, $3, 0); }
  2023. | SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
  2024. | SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2025. "string expected"); }
  2026. | PREFIX LPAREN STRING RPAREN { mk_action2( $$, PREFIX_T, STR_ST,
  2027. 0, $3, 0); }
  2028. | PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
  2029. | PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2030. "string expected"); }
  2031. | STRIP_TAIL LPAREN NUMBER RPAREN { mk_action2( $$, STRIP_TAIL_T,
  2032. NUMBER_ST, 0, (void *) $3, 0); }
  2033. | STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
  2034. | STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2035. "number expected"); }
  2036. | STRIP LPAREN NUMBER RPAREN { mk_action2( $$, STRIP_T, NUMBER_ST,
  2037. 0, (void *) $3, 0); }
  2038. | STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
  2039. | STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2040. "number expected"); }
  2041. | APPEND_BRANCH LPAREN STRING COMMA STRING RPAREN {
  2042. { qvalue_t q;
  2043. if (str2q(&q, $5, strlen($5)) < 0) {
  2044. yyerror("bad argument, q value expected");
  2045. }
  2046. mk_action2( $$, APPEND_BRANCH_T, STR_ST, NUMBER_ST, $3,
  2047. (void *)(long)q); }
  2048. }
  2049. | APPEND_BRANCH LPAREN STRING RPAREN { mk_action2( $$, APPEND_BRANCH_T,
  2050. STR_ST, NUMBER_ST, $3, (void *)Q_UNSPECIFIED) ; }
  2051. | APPEND_BRANCH LPAREN RPAREN { mk_action2( $$, APPEND_BRANCH_T,
  2052. STR_ST, NUMBER_ST, 0, (void *)Q_UNSPECIFIED) ; }
  2053. | APPEND_BRANCH { mk_action2( $$, APPEND_BRANCH_T,
  2054. STR_ST, NUMBER_ST, 0, (void *)Q_UNSPECIFIED ) ; }
  2055. | PV_PRINTF LPAREN STRING COMMA STRING RPAREN {
  2056. spec = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t));
  2057. memset(spec, 0, sizeof(pv_spec_t));
  2058. tstr.s = $3;
  2059. tstr.len = strlen(tstr.s);
  2060. if(pv_parse_spec(&tstr, spec)==NULL)
  2061. {
  2062. yyerror("unknown script variable in first parameter");
  2063. }
  2064. if(!pv_is_w(spec))
  2065. yyerror("read-only script variable in first parameter");
  2066. pvmodel = 0;
  2067. tstr.s = $5;
  2068. tstr.len = strlen(tstr.s);
  2069. if(pv_parse_format(&tstr, &pvmodel)<0)
  2070. {
  2071. yyerror("error in second parameter");
  2072. }
  2073. mk_action2( $$, PV_PRINTF_T,
  2074. SCRIPTVAR_ST, SCRIPTVAR_ELEM_ST, spec, pvmodel) ;
  2075. }
  2076. | PV_PRINTF LPAREN script_var COMMA STRING RPAREN {
  2077. if(!pv_is_w($3))
  2078. yyerror("read-only script variable in first parameter");
  2079. pvmodel = 0;
  2080. tstr.s = $5;
  2081. tstr.len = strlen(tstr.s);
  2082. if(pv_parse_format(&tstr, &pvmodel)<0)
  2083. {
  2084. yyerror("error in second parameter");
  2085. }
  2086. mk_action2( $$, PV_PRINTF_T,
  2087. SCRIPTVAR_ST, SCRIPTVAR_ELEM_ST, $3, pvmodel) ;
  2088. }
  2089. | SET_HOSTPORT LPAREN STRING RPAREN { mk_action2( $$, SET_HOSTPORT_T,
  2090. STR_ST, 0, $3, 0); }
  2091. | SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
  2092. | SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument,"
  2093. " string expected"); }
  2094. | SET_PORT LPAREN STRING RPAREN { mk_action2( $$, SET_PORT_T, STR_ST,
  2095. 0, $3, 0); }
  2096. | SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
  2097. | SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2098. "string expected"); }
  2099. | SET_USER LPAREN STRING RPAREN { mk_action2( $$, SET_USER_T,
  2100. STR_ST, 0, $3, 0); }
  2101. | SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
  2102. | SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2103. "string expected"); }
  2104. | SET_USERPASS LPAREN STRING RPAREN { mk_action2( $$, SET_USERPASS_T,
  2105. STR_ST, 0, $3, 0); }
  2106. | SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
  2107. | SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2108. "string expected"); }
  2109. | SET_URI LPAREN STRING RPAREN { mk_action2( $$, SET_URI_T, STR_ST,
  2110. 0, $3, 0); }
  2111. | SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
  2112. | SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2113. "string expected"); }
  2114. | REVERT_URI LPAREN RPAREN { mk_action2( $$, REVERT_URI_T, 0,0,0,0); }
  2115. | REVERT_URI { mk_action2( $$, REVERT_URI_T, 0,0,0,0); }
  2116. | SET_DSTURI LPAREN STRING RPAREN { mk_action2( $$, SET_DSTURI_T,
  2117. STR_ST, 0, $3, 0); }
  2118. | SET_DSTURI error { $$=0; yyerror("missing '(' or ')' ?"); }
  2119. | SET_DSTURI LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2120. "string expected"); }
  2121. | RESET_DSTURI LPAREN RPAREN { mk_action2( $$, RESET_DSTURI_T,
  2122. 0,0,0,0); }
  2123. | RESET_DSTURI { mk_action2( $$, RESET_DSTURI_T, 0,0,0,0); }
  2124. | ISDSTURISET LPAREN RPAREN { mk_action2( $$, ISDSTURISET_T, 0,0,0,0); }
  2125. | ISDSTURISET { mk_action2( $$, ISDSTURISET_T, 0,0,0,0); }
  2126. | FORCE_RPORT LPAREN RPAREN { mk_action2( $$, FORCE_RPORT_T,
  2127. 0, 0, 0, 0); }
  2128. | FORCE_RPORT { mk_action2( $$, FORCE_RPORT_T,0, 0, 0, 0); }
  2129. | FORCE_LOCAL_RPORT LPAREN RPAREN {
  2130. mk_action2( $$, FORCE_LOCAL_RPORT_T,0, 0, 0, 0); }
  2131. | FORCE_LOCAL_RPORT {
  2132. mk_action2( $$, FORCE_LOCAL_RPORT_T,0, 0, 0, 0); }
  2133. | FORCE_TCP_ALIAS LPAREN NUMBER RPAREN {
  2134. #ifdef USE_TCP
  2135. mk_action2( $$, FORCE_TCP_ALIAS_T,NUMBER_ST, 0,
  2136. (void*)$3, 0);
  2137. #else
  2138. yyerror("tcp support not compiled in");
  2139. #endif
  2140. }
  2141. | FORCE_TCP_ALIAS LPAREN RPAREN {
  2142. #ifdef USE_TCP
  2143. mk_action2( $$, FORCE_TCP_ALIAS_T,0, 0, 0, 0);
  2144. #else
  2145. yyerror("tcp support not compiled in");
  2146. #endif
  2147. }
  2148. | FORCE_TCP_ALIAS {
  2149. #ifdef USE_TCP
  2150. mk_action2( $$, FORCE_TCP_ALIAS_T,0, 0, 0, 0);
  2151. #else
  2152. yyerror("tcp support not compiled in");
  2153. #endif
  2154. }
  2155. | FORCE_TCP_ALIAS LPAREN error RPAREN {$$=0;
  2156. yyerror("bad argument, number expected");
  2157. }
  2158. | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
  2159. $$=0;
  2160. if ((str_tmp=pkg_malloc(sizeof(str)))==0){
  2161. LM_CRIT("cfg. parser: out of memory.\n");
  2162. }else if ($3!=0){
  2163. str_tmp->s=$3;
  2164. str_tmp->len=strlen($3);
  2165. mk_action2( $$, SET_ADV_ADDR_T, STR_ST,
  2166. 0, str_tmp, 0);
  2167. }
  2168. }
  2169. | SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2170. "string expected"); }
  2171. | SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
  2172. | SET_ADV_PORT LPAREN NUMBER RPAREN {
  2173. $$=0;
  2174. tmp=int2str($3, &i_tmp);
  2175. if ((str_tmp=pkg_malloc(sizeof(str)))==0){
  2176. LM_CRIT("cfg. parser: out of memory.\n");
  2177. }else{
  2178. if ((str_tmp->s=pkg_malloc(i_tmp))==0){
  2179. LM_CRIT("cfg. parser: out of memory.\n");
  2180. }else{
  2181. memcpy(str_tmp->s, tmp, i_tmp);
  2182. str_tmp->len=i_tmp;
  2183. mk_action2( $$, SET_ADV_PORT_T, STR_ST,
  2184. 0, str_tmp, 0);
  2185. }
  2186. }
  2187. }
  2188. | SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, "
  2189. "string expected"); }
  2190. | SET_ADV_PORT error {$$=0; yyerror("missing '(' or ')' ?"); }
  2191. | FORCE_SEND_SOCKET LPAREN phostport RPAREN {
  2192. mk_action2( $$, FORCE_SEND_SOCKET_T,
  2193. SOCKID_ST, 0, $3, 0);
  2194. }
  2195. | FORCE_SEND_SOCKET LPAREN error RPAREN { $$=0; yyerror("bad argument,"
  2196. " [proto:]host[:port] expected");
  2197. }
  2198. | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
  2199. | SERIALIZE_BRANCHES LPAREN NUMBER RPAREN {
  2200. mk_action2( $$, SERIALIZE_BRANCHES_T,
  2201. NUMBER_ST, 0, (void*)(long)$3, 0);
  2202. }
  2203. | SERIALIZE_BRANCHES LPAREN error RPAREN {$$=0; yyerror("bad argument,"
  2204. " number expected");
  2205. }
  2206. | SERIALIZE_BRANCHES error {$$=0; yyerror("missing '(' or ')' ?"); }
  2207. | NEXT_BRANCHES LPAREN RPAREN {
  2208. mk_action2( $$, NEXT_BRANCHES_T, 0, 0, 0, 0);
  2209. }
  2210. | NEXT_BRANCHES LPAREN error RPAREN {$$=0; yyerror("no argument is"
  2211. " expected");
  2212. }
  2213. | NEXT_BRANCHES error {$$=0; yyerror("missing '(' or ')' ?"); }
  2214. | USE_BLACKLIST LPAREN STRING RPAREN {
  2215. mk_action2( $$, USE_BLACKLIST_T,
  2216. STRING_ST, 0, $3, 0);
  2217. }
  2218. | USE_BLACKLIST LPAREN error RPAREN {$$=0; yyerror("bad argument,"
  2219. " string expected");
  2220. }
  2221. | USE_BLACKLIST error {$$=0; yyerror("missing '(' or ')' ?"); }
  2222. | UNUSE_BLACKLIST LPAREN STRING RPAREN {
  2223. mk_action2( $$, UNUSE_BLACKLIST_T,
  2224. STRING_ST, 0, $3, 0);
  2225. }
  2226. | UNUSE_BLACKLIST LPAREN error RPAREN {$$=0; yyerror("bad argument,"
  2227. " string expected");
  2228. }
  2229. | UNUSE_BLACKLIST error {$$=0; yyerror("missing '(' or ')' ?"); }
  2230. | CACHE_STORE LPAREN STRING COMMA STRING COMMA STRING RPAREN {
  2231. mk_action3( $$, CACHE_STORE_T,
  2232. STR_ST,
  2233. STR_ST,
  2234. STR_ST,
  2235. $3,
  2236. $5,
  2237. $7);
  2238. }
  2239. | CACHE_STORE LPAREN STRING COMMA STRING COMMA STRING COMMA NUMBER
  2240. RPAREN {
  2241. elems[0].type = STR_ST;
  2242. elems[0].u.data = $3;
  2243. elems[1].type = STR_ST;
  2244. elems[1].u.data = $5;
  2245. elems[2].type = STR_ST;
  2246. elems[2].u.data = $7;
  2247. elems[3].type = NUMBER_ST;
  2248. elems[3].u.number = $9;
  2249. $$ = mk_action(CACHE_STORE_T, 4, elems, line);
  2250. }
  2251. | CACHE_STORE LPAREN STRING COMMA STRING COMMA STRING COMMA script_var
  2252. RPAREN {
  2253. elems[0].type = STR_ST;
  2254. elems[0].u.data = $3;
  2255. elems[1].type = STR_ST;
  2256. elems[1].u.data = $5;
  2257. elems[2].type = STR_ST;
  2258. elems[2].u.data = $7;
  2259. elems[3].type = SCRIPTVAR_ST;
  2260. elems[3].u.data = $9;
  2261. $$ = mk_action(CACHE_STORE_T, 4, elems, line);
  2262. }
  2263. | CACHE_REMOVE LPAREN STRING COMMA STRING RPAREN {
  2264. mk_action2( $$, CACHE_REMOVE_T,
  2265. STR_ST,
  2266. STR_ST,
  2267. $3,
  2268. $5);
  2269. }
  2270. | CACHE_FETCH LPAREN STRING COMMA STRING COMMA script_var RPAREN {
  2271. mk_action3( $$, CACHE_FETCH_T,
  2272. STR_ST,
  2273. STR_ST,
  2274. SCRIPTVAR_ST,
  2275. $3,
  2276. $5,
  2277. $7);
  2278. }
  2279. | ID LPAREN RPAREN {
  2280. cmd_tmp=(void*)find_cmd_export_t($1, 0, rt);
  2281. if (cmd_tmp==0){
  2282. if (find_cmd_export_t($1, 0, 0)) {
  2283. yyerror("Command cannot be "
  2284. "used in the block\n");
  2285. } else {
  2286. yyerrorf("unknown command <%s>, "
  2287. "missing loadmodule?", $1);
  2288. }
  2289. $$=0;
  2290. }else{
  2291. elems[0].type = CMD_ST;
  2292. elems[0].u.data = cmd_tmp;
  2293. $$ = mk_action(MODULE_T, 1, elems, line);
  2294. }
  2295. }
  2296. | ID LPAREN module_func_param RPAREN {
  2297. cmd_tmp=(void*)find_cmd_export_t($1, $3, rt);
  2298. if (cmd_tmp==0){
  2299. if (find_cmd_export_t($1, $3, 0)) {
  2300. yyerror("Command cannot be "
  2301. "used in the block\n");
  2302. } else {
  2303. yyerrorf("unknown command <%s>, "
  2304. "missing loadmodule?", $1);
  2305. }
  2306. $$=0;
  2307. }else{
  2308. elems[0].type = CMD_ST;
  2309. elems[0].u.data = cmd_tmp;
  2310. $$ = mk_action(MODULE_T, $3+1, elems, line);
  2311. }
  2312. }
  2313. | ID LPAREN error RPAREN { $$=0; yyerrorf("bad arguments for "
  2314. "command <%s>", $1); }
  2315. | ID error { $$=0; yyerrorf("bare word <%s> found, command calls need '()'", $1); }
  2316. | XDBG LPAREN STRING RPAREN {
  2317. mk_action1($$, XDBG_T, STR_ST, $3); }
  2318. | XLOG LPAREN STRING RPAREN {
  2319. mk_action1($$, XLOG_T, STR_ST, $3); }
  2320. | XLOG LPAREN STRING COMMA STRING RPAREN {
  2321. mk_action2($$, XLOG_T, STR_ST, STR_ST, $3, $5); }
  2322. ;
  2323. %%
  2324. extern int column;
  2325. extern int startcolumn;
  2326. #if !defined(USE_TLS) || !defined(USE_TCP) \
  2327. || !defined(USE_MCAST)
  2328. static void warn(char* s)
  2329. {
  2330. LM_WARN("warning in config file, line %d, column %d-%d: %s\n", line, startcolumn,
  2331. column, s);
  2332. }
  2333. #endif
  2334. static void yyerror(char* s)
  2335. {
  2336. LM_CRIT("parse error in config file, line %d, column %d-%d: %s\n", line, startcolumn,
  2337. column, s);
  2338. cfg_errors++;
  2339. }
  2340. #define ERROR_MAXLEN 1024
  2341. static void yyerrorf(char *fmt, ...)
  2342. {
  2343. char *tmp = pkg_malloc(ERROR_MAXLEN);
  2344. va_list ap;
  2345. va_start(ap, fmt);
  2346. vsnprintf(tmp, ERROR_MAXLEN, fmt, ap);
  2347. yyerror(tmp);
  2348. pkg_free(tmp);
  2349. va_end(ap);
  2350. }
  2351. static struct socket_id* mk_listen_id(char* host, int proto, int port)
  2352. {
  2353. struct socket_id* l;
  2354. l=pkg_malloc(sizeof(struct socket_id));
  2355. if (l==0){
  2356. LM_CRIT("cfg. parser: out of memory.\n");
  2357. }else{
  2358. l->name=host;
  2359. l->port=port;
  2360. l->proto=proto;
  2361. l->adv_name=NULL;
  2362. l->adv_port=0;
  2363. l->next=0;
  2364. }
  2365. return l;
  2366. }
  2367. static struct socket_id* set_listen_id_adv(struct socket_id* sock,
  2368. char *adv_name,
  2369. int adv_port)
  2370. {
  2371. sock->adv_name=adv_name;
  2372. sock->adv_port=adv_port;
  2373. return sock;
  2374. }