PageRenderTime 60ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/cfg.y

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