4 * Copyright (C) 2001-2003 FhG Fokus
6 * This file is part of Kamailio, a free SIP server.
8 * Kamailio is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version
13 * Kamailio is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 /** Kamailio core :: expression evaluation, route fixups and routing lists.
32 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
48 #include "sr_module.h"
51 #include "socket_info.h"
52 #include "parser/parse_uri.h"
53 #include "parser/parse_from.h"
54 #include "parser/parse_to.h"
62 #include "cfg/cfg_struct.h"
64 #define RT_HASH_SIZE 8 /* route names hash */
66 /* main routing script table */
67 struct route_list main_rt;
68 struct route_list onreply_rt;
69 struct route_list failure_rt;
70 struct route_list branch_rt;
71 struct route_list onsend_rt;
72 struct route_list event_rt;
74 int route_type = REQUEST_ROUTE;
76 /** script optimization level, useful for debugging.
78 * 1 - optimize rval expressions
79 * 2 - optimize expr elems
83 inline static void destroy_rlist(struct route_list* rt)
85 struct str_hash_entry* e;
86 struct str_hash_entry* tmp;
94 clist_foreach_safe(rt->names.table, e, tmp, next){
97 pkg_free(rt->names.table);
105 void destroy_routes()
107 destroy_rlist(&main_rt);
108 destroy_rlist(&onreply_rt);
109 destroy_rlist(&failure_rt);
110 destroy_rlist(&branch_rt);
111 destroy_rlist(&event_rt);
116 /* adds route name -> i mapping
117 * WARNING: it doesn't check for pre-existing routes
118 * return -1 on error, route index on success
120 static int route_add(struct route_list* rt, char* name, int i)
122 struct str_hash_entry* e;
124 e=pkg_malloc(sizeof(struct str_hash_entry));
126 LM_CRIT("out of memory\n");
129 LM_DBG("mapping routing block (%p)[%s] to %d\n", rt, name, i);
131 e->key.len=strlen(name);
134 str_hash_add(&rt->names, e);
142 /* returns -1 on error, 0 on success */
143 inline static int init_rlist(char* r_name, struct route_list* rt,
144 int n_entries, int hash_size)
146 rt->rlist=pkg_malloc(sizeof(struct action*)*n_entries);
148 LM_CRIT("failed to allocate \"%s\" route tables: "
149 "out of memory\n", r_name);
152 memset(rt->rlist, 0 , sizeof(struct action*)*n_entries);
153 rt->idx=1; /* idx=0 == default == reserved */
154 rt->entries=n_entries;
155 if (str_hash_alloc(&rt->names, hash_size)<0){
156 LM_CRIT("\"%s\" route table: failed to alloc hash\n",
160 str_hash_init(&rt->names);
161 route_add(rt, "0", 0); /* default route */
170 /* init route tables */
173 if (init_rlist("main", &main_rt, RT_NO, RT_HASH_SIZE)<0)
175 if (init_rlist("on_reply", &onreply_rt, ONREPLY_RT_NO, RT_HASH_SIZE)<0)
177 if (init_rlist("failure", &failure_rt, FAILURE_RT_NO, RT_HASH_SIZE)<0)
179 if (init_rlist("branch", &branch_rt, BRANCH_RT_NO, RT_HASH_SIZE)<0)
181 if (init_rlist("on_send", &onsend_rt, ONSEND_RT_NO, RT_HASH_SIZE)<0)
183 if (init_rlist("event", &event_rt, EVENT_RT_NO, RT_HASH_SIZE)<0)
193 static inline int route_new_list(struct route_list* rt)
199 if (rt->idx >= rt->entries){
200 tmp=pkg_realloc(rt->rlist, 2*rt->entries*sizeof(struct action*));
202 LM_CRIT("out of memory\n");
205 /* init the newly allocated memory chunk */
206 memset(&tmp[rt->entries], 0, rt->entries*sizeof(struct action*));
210 if (rt->idx<rt->entries){
222 * if the "name" route already exists, return its index, else
223 * create a new empty route
224 * return route index in rt->rlist or -1 on error
226 int route_get(struct route_list* rt, char* name)
229 struct str_hash_entry* e;
233 /* check if exists an non empty*/
234 e=str_hash_get(&rt->names, name, len);
238 i=route_new_list(rt);
239 if (i==-1) goto error;
240 if (route_add(rt, name, i)<0){
252 * if the "name" route already exists, return its index, else
254 * return route index in rt->rlist or -1 on error
256 int route_lookup(struct route_list* rt, char* name)
259 struct str_hash_entry* e;
262 /* check if exists an non empty*/
263 e=str_hash_get(&rt->names, name, len);
273 int fix_actions(struct action* a); /*fwd declaration*/
276 /** optimize the left side of a struct expr.
277 * @return 1 if optimized, 0 if not and -1 on error
279 static int exp_optimize_left(struct expr* exp)
281 struct rval_expr* rve;
283 int old_ltype, old_rtype, old_op;
287 if (exp->type!=ELEM_T)
289 old_ltype=exp->l_type;
290 old_rtype=exp->r_type;
292 if (exp->l_type==RVEXP_O){
294 /* rve should be previously fixed/optimized */
295 /* optimize exp (rval(val)) -> exp(val) */
296 if (rve->op==RVE_RVAL_OP){
297 rval=&rve->left.rval;
301 exp->l_type=NUMBER_O;
303 exp->r_type=NUMBER_ST;
304 exp->r.numval=rval->v.l;
311 /* string evaluated in expression context - not
316 /* replace the current expr. */
317 *exp=*(rval->v.bexpr);
325 exp->l_type=ACTION_O;
327 exp->r_type=ACTION_ST;
328 exp->r.param=rval->v.action;
335 exp->l.select=pkg_malloc(sizeof(*exp->l.select));
337 exp->l_type=SELECT_O;
338 *exp->l.select=rval->v.sel;
346 exp->l.attr=pkg_malloc(sizeof(*exp->l.attr));
349 *exp->l.attr=rval->v.avps;
357 exp->l.param=pkg_malloc(sizeof(pv_spec_t));
360 *((pv_spec_t*)exp->l.param)=rval->v.pvs;
373 LM_DBG("op%d(_O%d_, ST%d) => op%d(_O%d_, ST%d)\n",
374 old_op, old_ltype, old_rtype, exp->op, exp->l_type, exp->r_type);
380 /** optimize the left side of a struct expr.
381 * @return 1 if optimized, 0 if not and -1 on error
383 static int exp_optimize_right(struct expr* exp)
385 struct rval_expr* rve;
387 int old_ltype, old_rtype, old_op;
391 if ((exp->type!=ELEM_T) ||(exp->op==NO_OP))
393 old_ltype=exp->l_type;
394 old_rtype=exp->r_type;
396 if (exp->r_type==RVE_ST){
398 /* rve should be previously fixed/optimized */
399 /* optimize exp (rval(val)) -> exp(val) */
400 if (rve->op==RVE_RVAL_OP){
401 rval=&rve->left.rval;
404 exp->r_type=NUMBER_ST;
405 exp->r.numval=rval->v.l;
411 exp->r.str.s=pkg_malloc(rval->v.s.len+1);
413 exp->r.str.len=rval->v.s.len;
414 memcpy(exp->r.str.s, rval->v.s.s, rval->v.s.len);
415 exp->r.str.s[exp->r.str.len]=0;
416 exp->r_type=STRING_ST;
424 /* cannot be optimized further, is an exp_elem
425 which is not constant */
428 /* cannot be optimized further, is not constant and
429 eval_elem() does not support ACTION_ST for op!=NO_OP*/
432 exp->r.select=pkg_malloc(sizeof(*exp->l.select));
434 exp->r_type=SELECT_ST;
435 *exp->r.select=rval->v.sel;
443 exp->r.attr=pkg_malloc(sizeof(*exp->l.attr));
446 *exp->r.attr=rval->v.avps;
454 exp->r.param=pkg_malloc(sizeof(pv_spec_t));
457 *((pv_spec_t*)exp->r.param)=rval->v.pvs;
471 LM_DBG("op%d(O%d, _ST%d_) => op%d(O%d, _ST%d_)\n",
472 old_op, old_ltype, old_rtype, exp->op, exp->l_type, exp->r_type);
478 /* traverses an expr tree and compiles the REs where necessary)
479 * returns: 0 for ok, <0 if errors */
480 int fix_expr(struct expr* exp)
488 LM_CRIT("null pointer\n");
491 if (exp->type==EXP_T){
495 if ((ret=fix_expr(exp->l.expr))!=0)
497 ret=fix_expr(exp->r.expr);
500 ret=fix_expr(exp->l.expr);
503 LM_CRIT("unknown op %d\n", exp->op);
505 }else if (exp->type==ELEM_T){
506 /* first calculate lengths of strings (only right side, since
507 left side can never be a string) */
508 if (exp->r_type==STRING_ST) {
509 if (exp->r.string) len = strlen(exp->r.string);
511 exp->r.str.s = exp->r.string;
512 exp->r.str.len = len;
514 /* then fix & optimize rve/rvals (they might be optimized
515 to non-rvals, e.g. string, avp a.s.o and needs to be done
516 before MATCH_OP and other fixups) */
517 if (exp->l_type==RVEXP_O){
518 if ((ret=fix_rval_expr(exp->l.param))<0){
519 LM_ERR("Unable to fix left rval expression\n");
523 exp_optimize_left(exp);
525 if (exp->r_type==RVE_ST){
526 if ((ret=fix_rval_expr(exp->r.param))<0){
527 LM_ERR("Unable to fix right rval expression\n");
531 exp_optimize_right(exp);
535 if (exp->op==MATCH_OP){
536 /* right side either has to be string, in which case
537 * we turn it into regular expression, or it is regular
538 * expression already. In that case we do nothing
540 if (exp->r_type==STRING_ST){
541 re=(regex_t*)pkg_malloc(sizeof(regex_t));
543 LM_CRIT("memory allocation failure\n");
546 if (regcomp(re, (char*) exp->r.param,
547 REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
548 LM_CRIT("bad re \"%s\"\n", (char*) exp->r.param);
552 /* replace the string with the re */
553 pkg_free(exp->r.param);
556 }else if (exp->r_type!=RE_ST && exp->r_type != AVP_ST
557 && exp->r_type != SELECT_ST &&
558 exp->r_type != SELECT_UNFIXED_ST &&
560 && exp->r_type != PVAR_ST){
561 LM_CRIT("invalid type for match\n");
565 if (exp->l_type==ACTION_O){
566 ret=fix_actions((struct action*)exp->r.param);
568 LM_CRIT("fix_actions error\n");
572 if (exp->l_type==SELECT_UNFIXED_O) {
573 if ((ret=resolve_select(exp->l.select)) < 0) {
574 LM_ERR("Unable to resolve select\n");
575 print_select(exp->l.select);
578 exp->l_type=SELECT_O;
580 if (exp->r_type==SELECT_UNFIXED_ST) {
581 if ((ret=resolve_select(exp->r.select)) < 0) {
582 LM_ERR("Unable to resolve select\n");
583 print_select(exp->r.select);
586 exp->r_type=SELECT_ST;
588 /* PVAR don't need fixing */
596 /* adds the proxies in the proxy list & resolves the hostnames */
597 /* returns 0 if ok, <0 on error */
598 int fix_actions(struct action* a)
606 sr31_cmd_export_t* cmd;
610 struct socket_info* si;
612 struct rval_expr* rve;
613 struct rval_expr* err_rve;
614 enum rval_type rve_type, err_type, expected_type;
619 LM_CRIT("null pointer\n");
622 for(t=a; t!=0; t=t->next){
629 switch(t->val[0].type){
631 tmp=strdup(ip_addr2a(
632 (struct ip_addr*)t->val[0].u.data));
634 LM_CRIT("memory allocation failure\n");
638 t->val[0].type=STRING_ST;
639 t->val[0].u.string=tmp;
642 s.s = t->val[0].u.string;
644 p=add_proxy(&s, t->val[1].u.number, 0); /* FIXME proto*/
645 if (p==0) { ret =E_BAD_ADDRESS; goto error; }
647 t->val[0].type=PROXY_ST;
652 LM_CRIT("invalid type %d (should be string or number)\n",
659 if (t->val[0].type!=RVE_ST){
660 LM_CRIT("invalid subtype %d for if (should be rval expr)\n",
664 }else if( (t->val[1].type!=ACTIONS_ST) &&
665 (t->val[1].type!=NOSUBTYPE) ){
666 LM_CRIT("invalid subtype %d for if() {...} (should be action)\n",
670 }else if( (t->val[2].type!=ACTIONS_ST) &&
671 (t->val[2].type!=NOSUBTYPE) ){
672 LM_CRIT("invalid subtype %d for if() {} else{...}(should be action)\n",
677 rve=(struct rval_expr*)t->val[0].u.data;
680 if (!rve_check_type(&rve_type, rve, &err_rve,
681 &err_type, &expected_type)){
683 LM_ERR("invalid expression "
684 "(%d,%d): subexpression (%d,%d) has type"
685 " %s, but %s is expected\n",
686 rve->fpos.s_line, rve->fpos.s_col,
687 err_rve->fpos.s_line, err_rve->fpos.s_col,
688 rval_type_name(err_type),
689 rval_type_name(expected_type) );
691 LM_ERR("invalid expression (%d,%d): type mismatch?",
692 rve->fpos.s_line, rve->fpos.s_col);
696 /* it's not an error anymore to have non-int in an if,
697 only a script warning (to allow backward compat. stuff
699 if (rve_type!=RV_INT && rve_type!=RV_NONE){
700 LM_ERR("fix_actions: invalid expression (%d,%d):"
701 " bad type, integer expected\n",
702 rve->fpos.s_line, rve->fpos.s_col);
706 if ((ret=fix_rval_expr(t->val[0].u.data))<0)
709 if ( (t->val[1].type==ACTIONS_ST)&&(t->val[1].u.data) ){
710 if ((ret=fix_actions((struct action*)t->val[1].u.data))<0)
713 if ( (t->val[2].type==ACTIONS_ST)&&(t->val[2].u.data) ){
714 if ((ret=fix_actions((struct action*)t->val[2].u.data))
720 if (t->val[0].type!=RVE_ST){
721 LM_CRIT("invalid subtype %d for switch() (should be expr)\n",
725 }else if (t->val[1].type!=CASE_ST){
726 LM_CRIT("invalid subtype %d for switch(...){...}(should be case)\n",
731 if (t->val[0].u.data){
732 if ((ret=fix_rval_expr(t->val[0].u.data))<0)
735 LM_CRIT("null switch() expression\n");
739 if ((ret=fix_switch(t))<0)
743 if (t->val[0].type!=RVE_ST){
744 LM_CRIT("invalid subtype %d for while() (should be expr)\n",
748 }else if (t->val[1].type!=ACTIONS_ST){
749 LM_CRIT("invalid subtype %d for while(...){...}(should be action)\n",
754 rve=(struct rval_expr*)t->val[0].u.data;
757 if (!rve_check_type(&rve_type, rve, &err_rve,
758 &err_type, &expected_type)){
760 LM_ERR("invalid expression "
761 "(%d,%d): subexpression (%d,%d) has type"
762 " %s, but %s is expected\n",
763 rve->fpos.s_line, rve->fpos.s_col,
764 err_rve->fpos.s_line, err_rve->fpos.s_col,
765 rval_type_name(err_type),
766 rval_type_name(expected_type) );
768 LM_ERR("invalid expression (%d,%d): type mismatch?",
769 rve->fpos.s_line, rve->fpos.s_col);
773 if (rve_type!=RV_INT && rve_type!=RV_NONE){
774 LM_ERR("invalid expression (%d,%d): bad type, integer expected\n",
775 rve->fpos.s_line, rve->fpos.s_col);
779 if ((ret=fix_rval_expr(t->val[0].u.data))<0)
782 LM_CRIT("null while() expression\n");
786 if ( t->val[1].u.data &&
787 ((ret= fix_actions((struct action*)t->val[1].u.data))<0)){
792 /* only RVEs need fixing for drop/return/break */
793 if (t->val[0].type!=RVE_ST)
795 rve=(struct rval_expr*)t->val[0].u.data;
798 if (!rve_check_type(&rve_type, rve, &err_rve,
799 &err_type, &expected_type)){
801 LM_ERR("invalid expression "
802 "(%d,%d): subexpression (%d,%d) has type"
803 " %s, but %s is expected\n",
804 rve->fpos.s_line, rve->fpos.s_col,
805 err_rve->fpos.s_line, err_rve->fpos.s_col,
806 rval_type_name(err_type),
807 rval_type_name(expected_type) );
809 LM_ERR("invalid expression (%d,%d): type mismatch?",
810 rve->fpos.s_line, rve->fpos.s_col);
814 if (rve_type!=RV_INT && rve_type!=RV_NONE){
815 LM_ERR("invalid expression (%d,%d): bad type, integer expected\n",
816 rve->fpos.s_line, rve->fpos.s_col);
820 if ((ret=fix_rval_expr(t->val[0].u.data))<0)
823 LM_CRIT("null drop/return expression\n");
830 if (t->val[0].type !=LVAL_ST) {
831 LM_CRIT("Invalid left side of assignment\n");
835 if (t->val[1].type !=RVE_ST) {
836 LM_CRIT("Invalid right side of assignment (%d)\n",
841 lval=t->val[0].u.data;
842 if (lval->type==LV_AVP){
843 if (lval->lv.avps.type & AVP_CLASS_DOMAIN) {
844 LM_ERR("You cannot change domain"
845 " attributes from the script, they are"
849 } else if (lval->lv.avps.type & AVP_CLASS_GLOBAL) {
850 LM_ERR("You cannot change global"
851 " attributes from the script, they are"
857 if ((ret=fix_rval_expr(t->val[1].u.data))<0)
869 cmd = t->val[0].u.data;
872 LM_DBG("fixing %s()\n", cmd->name);
873 if (t->val[1].u.number==0) {
874 ret = call_fixup(cmd->fixup, 0, 0);
878 for (i=0; i < t->val[1].u.number; i++) {
879 if (t->val[i+2].type == RVE_ST) {
880 rve = t->val[i+2].u.data;
881 if (rve_is_constant(rve)) {
882 /* if expression is constant => evaluate it
883 as string and replace it with the corresp.
885 rv = rval_expr_eval(0, 0, rve);
887 rval_get_str( 0, 0, &s, rv, 0) < 0 ) {
888 ERR("failed to fix constant rve");
889 if (rv) rval_destroy(rv);
895 t->val[i+2].type = STRING_ST;/*asciiz string*/
896 t->val[i+2].u.string = s.s;
897 /* len is not used for now */
898 t->val[i+2].u.str.len = s.len;
899 tmp_p = t->val[i+2].u.data;
900 ret = call_fixup(cmd->fixup,
901 &t->val[i+2].u.data, i+1);
902 if (t->val[i+2].u.data != tmp_p)
903 t->val[i+2].type = MODFIXUP_ST;
907 /* expression is not constant => fixup &
910 if ((ret=fix_rval_expr(t->val[i+2].u.data))
912 ERR("rve fixup failed\n");
917 } else if (t->val[i+2].type == STRING_ST) {
918 tmp_p = t->val[i+2].u.data;
919 ret = call_fixup(cmd->fixup,
920 &t->val[i+2].u.data, i+1);
921 if (t->val[i+2].u.data != tmp_p)
922 t->val[i+2].type = MODFIXUP_ST;
926 BUG("invalid module function param type %d\n",
932 /* here all the params are either STRING_ST
933 (constant RVEs), MODFIXUP_ST (fixed up)
934 or RVE_ST (non-ct RVEs) */
935 if (rve_param_no) { /* we have to fix the type */
937 !(cmd->fixup_flags & FIXUP_F_FPARAM_RVE) &&
938 cmd->free_fixup == 0) {
939 BUG("non-ct RVEs (%d) in module function call"
940 "that does not support them (%s)\n",
941 rve_param_no, cmd->name);
947 t->type = MODULE1_RVE_T;
950 t->type = MODULE2_RVE_T;
953 t->type = MODULE3_RVE_T;
956 t->type = MODULE4_RVE_T;
959 t->type = MODULE5_RVE_T;
962 t->type = MODULE6_RVE_T;
965 t->type = MODULEX_RVE_T;
968 BUG("unsupported module function type %d\n",
973 } /* if rve_param_no */
976 case FORCE_SEND_SOCKET_T:
977 if (t->val[0].type!=SOCKID_ST){
978 LM_CRIT("invalid subtype %d for force_send_socket\n",
984 ((struct socket_id*)t->val[0].u.data)->addr_lst->name
987 LM_ERR("force_send_socket: could not resolve %s\n",
988 ((struct socket_id*)t->val[0].u.data)->addr_lst->name);
992 hostent2ip_addr(&ip, he, 0);
993 si=find_si(&ip, ((struct socket_id*)t->val[0].u.data)->port,
994 ((struct socket_id*)t->val[0].u.data)->proto);
996 LM_ERR("bad force_send_socket argument: %s:%d (ser doesn't listen on it)\n",
997 ((struct socket_id*)t->val[0].u.data)->addr_lst->name,
998 ((struct socket_id*)t->val[0].u.data)->port);
1002 t->val[0].u.data=si;
1003 t->val[0].type=SOCKETINFO_ST;
1005 case UDP_MTU_TRY_PROTO_T:
1006 if (t->val[0].type!=NUMBER_ST){
1007 LM_CRIT("invalid subtype %d for udp_mtu_try_proto\n",
1012 switch(t->val[0].u.number){
1014 t->val[0].u.number=0;
1017 t->val[0].u.number=FL_MTU_TCP_FB;
1020 t->val[0].u.number=FL_MTU_TLS_FB;
1023 t->val[0].u.number=FL_MTU_SCTP_FB;
1026 LM_CRIT("invalid argument for udp_mtu_try_proto (%d)\n",
1027 (unsigned int)t->val[0].u.number);
1030 case APPEND_BRANCH_T:
1031 if (t->val[0].type!=STRING_ST){
1032 BUG("invalid subtype%d for append_branch_t\n",
1037 s.s=t->val[0].u.string;
1038 s.len=(s.s)?strlen(s.s):0;
1040 t->val[0].type=STR_ST;
1043 if (t->val[0].type == RVE_ST) {
1044 rve=(struct rval_expr*)t->val[0].u.data;
1045 if (!rve_is_constant(rve)) {
1046 if ((ret=fix_rval_expr(t->val[0].u.data)) < 0){
1047 LM_ERR("route() failed to fix rve at %s:%d\n",
1048 (t->cfile)?t->cfile:"line", t->cline);
1053 /* rve is constant => replace it with a string */
1054 if ((rv = rval_expr_eval(0, 0, rve)) == 0 ||
1055 rval_get_str(0, 0, &s, rv, 0) < 0) {
1056 /* out of mem. or bug ? */
1058 LM_ERR("route() failed to fix ct. rve at %s:%d\n",
1059 (t->cfile)?t->cfile:"line", t->cline);
1065 t->val[0].type = STRING_ST;
1066 t->val[0].u.string = s.s;
1067 t->val[0].u.str.len = s.len; /* not used */
1068 /* fall-through the STRING_ST if */
1071 if (t->val[0].type == STRING_ST) {
1072 i=route_lookup(&main_rt, t->val[0].u.string);
1074 LM_ERR("route \"%s\" not found at %s:%d\n",
1076 (t->cfile)?t->cfile:"line", t->cline);
1080 t->val[0].type = NUMBER_ST;
1081 pkg_free(t->val[0].u.string);
1082 t->val[0].u.number = i;
1083 } else if (t->val[0].type != NUMBER_ST &&
1084 t->val[0].type != RVE_ST) {
1085 BUG("invalid subtype %d for route()\n",
1092 if (t->val[1].type == RVE_ST) {
1093 rve = t->val[1].u.data;
1094 if (rve_is_constant(rve)) {
1095 /* if expression is constant => evaluate it
1096 as integer and replace it with the corresp.
1098 rv = rval_expr_eval(0, 0, rve);
1100 rval_get_int( 0, 0, &i, rv, 0) < 0 ) {
1101 LM_ERR("failed to fix constant rve");
1102 if (rv) rval_destroy(rv);
1108 t->val[1].type = NUMBER_ST;
1109 t->val[1].u.number = i;
1111 /* expression is not constant => fixup &
1113 if ((ret=fix_rval_expr(rve))
1115 LM_ERR("rve fixup failed\n");
1120 } else if (t->val[1].type != NUMBER_ST) {
1121 BUG("invalid subtype %d for cfg_select()\n",
1128 if (t->val[0].type != STRING_ST) {
1129 BUG("invalid subtype %d for cfg_select() or cfg_reset()\n",
1134 tmp_p = (void *)cfg_lookup_group(t->val[0].u.string, strlen(t->val[0].u.string));
1136 LM_ERR("configuration group \"%s\" not found\n",
1137 t->val[0].u.string);
1141 pkg_free(t->val[0].u.string);
1142 t->val[0].u.data = tmp_p;
1143 t->val[0].type = CFG_GROUP_ST;
1146 /* no fixup required for the rest */
1153 LM_ERR("fixing failed (code=%d) at cfg:%s:%d\n", ret,
1154 (t->cfile)?t->cfile:"", t->cline);
1159 /* Compare parameters as ordinary numbers
1161 * Left and right operands can be either numbers or
1162 * attributes. If either of the attributes if of string type then the length of
1163 * its value will be used.
1165 inline static int comp_num(int op, long left, int rtype, union exp_op* r,
1166 struct sip_msg* msg, struct run_act_ctx* h)
1173 if (unlikely(op==NO_OP)) return !(!left);
1176 avp = search_avp_by_index(r->attr->type, r->attr->name,
1177 &val, r->attr->index);
1178 if (avp && !(avp->flags & AVP_VAL_STR)) right = val.n;
1179 else return (op == DIFF_OP);
1185 if (unlikely(rval_expr_eval_int(h, msg, &right, r->param)<0))
1186 return (op == DIFF_OP); /* not found/invalid */
1189 memset(&pval, 0, sizeof(pv_value_t));
1190 if (unlikely(pv_get_spec_value(msg, r->param, &pval)!=0)){
1191 return (op == DIFF_OP); /* error, not found => false */
1193 if (likely(pval.flags & (PV_TYPE_INT|PV_VAL_INT))){
1195 pv_value_destroy(&pval);
1197 pv_value_destroy(&pval);
1198 return (op == DIFF_OP); /* not found or invalid type */
1202 LM_CRIT("Invalid right operand (%d)\n", rtype);
1207 case EQUAL_OP: return (long)left == (long)right;
1208 case DIFF_OP: return (long)left != (long)right;
1209 case GT_OP: return (long)left > (long)right;
1210 case LT_OP: return (long)left < (long)right;
1211 case GTE_OP: return (long)left >= (long)right;
1212 case LTE_OP: return (long)left <= (long)right;
1214 LM_CRIT("unknown operator: %d\n", op);
1221 * Compare given string "left" with right side of expression
1223 inline static int comp_str(int op, str* left, int rtype,
1224 union exp_op* r, struct sip_msg* msg,
1225 struct run_act_ctx* h)
1236 struct rval_cache rv_cache;
1240 right=0; /* warning fix */
1243 if (unlikely(op==NO_OP)) return (left->s!=0);
1246 avp = search_avp_by_index(r->attr->type, r->attr->name,
1247 &val, r->attr->index);
1248 if (likely(avp && (avp->flags & AVP_VAL_STR))) right = &val.s;
1249 else return (op == DIFF_OP);
1252 ret = run_select(&v, r->select, msg);
1253 if (unlikely(ret != 0))
1254 return (op == DIFF_OP); /* Not found or error */
1258 rval_cache_init(&rv_cache);
1259 rv=rval_expr_eval(h, msg, r->param);
1260 if (unlikely (rv==0))
1261 return (op==DIFF_OP); /* not found or error*/
1262 if (unlikely(rval_get_tmp_str(h, msg, &v, rv, 0, &rv_cache)<0)){
1268 memset(&pval, 0, sizeof(pv_value_t));
1269 if (unlikely(pv_get_spec_value(msg, r->param, &pval)!=0)){
1270 return (op == DIFF_OP); /* error, not found => false */
1273 if (likely(pval.flags & PV_VAL_STR)){
1276 pv_value_destroy(&pval);
1277 return (op == DIFF_OP); /* not found or invalid type */
1281 if (unlikely(op != MATCH_OP)){
1282 LM_CRIT("Bad operator %d, ~= expected\n", op);
1286 case STRING_ST: /* strings are stored as {asciiz, len } */
1291 /* "123" > 100 is not allowed by cfg.y rules
1292 * but can happen as @select or $avp evaluation
1294 * the right operator MUST be number to do the conversion
1296 if (str2int(left,&l) < 0)
1298 return comp_num(op, l, rtype, r, msg, h);
1300 LM_CRIT("Bad type %d, string or RE expected\n", rtype);
1307 if (left->len != right->len) return 0;
1308 ret=(strncasecmp(left->s, right->s, left->len)==0);
1311 if (left->len != right->len) return 1;
1312 ret = (strncasecmp(left->s, right->s, left->len)!=0);
1315 /* this is really ugly -- we put a temporary zero-terminating
1316 * character in the original string; that's because regexps
1317 * take 0-terminated strings and our messages are not
1318 * zero-terminated; it should not hurt as long as this function
1319 * is applied to content of pkg mem, which is always the case
1320 * with calls from route{}; the same goes for fline in
1323 * also, the received function should always give us an extra
1324 * character, into which we can put the 0-terminator now;
1325 * an alternative would be allocating a new piece of memory,
1326 * which might be too slow
1329 * janakj: AVPs are zero terminated too so this is not problem
1332 backup=left->s[left->len];
1333 left->s[left->len]='\0';
1341 /* we need to compile the RE on the fly */
1342 re=(regex_t*)pkg_malloc(sizeof(regex_t));
1344 LM_CRIT("memory allocation failure\n");
1345 left->s[left->len] = backup;
1348 if (regcomp(re, right->s,
1349 REG_EXTENDED|REG_NOSUB|REG_ICASE)) {
1351 left->s[left->len] = backup;
1354 ret=(regexec(re, left->s, 0, 0, 0)==0);
1359 ret=(regexec(r->re, left->s, 0, 0, 0)==0);
1362 LM_CRIT("Bad operator type %d, for ~= \n", rtype);
1365 left->s[left->len] = backup;
1368 LM_CRIT("unknown op %d\n", op);
1372 rval_cache_clean(&rv_cache);
1376 pv_value_destroy(&pval);
1381 rval_cache_clean(&rv_cache);
1385 pv_value_destroy(&pval);
1386 return (op == DIFF_OP) ? 1 : -1;
1390 /* eval_elem helping function, returns str op param */
1391 inline static int comp_string(int op, char* left, int rtype, union exp_op* r,
1392 struct sip_msg* msg, struct run_act_ctx* h)
1398 return comp_str(op, &s, rtype, r, msg, h);
1402 inline static int comp_avp(int op, avp_spec_t* spec, int rtype,
1403 union exp_op* r, struct sip_msg* msg,
1404 struct run_act_ctx* h)
1408 union exp_op num_val;
1412 if (spec->type & AVP_INDEX_ALL) {
1413 avp = search_first_avp(spec->type & ~AVP_INDEX_ALL, spec->name,
1417 avp = search_avp_by_index(spec->type, spec->name, &val, spec->index);
1418 if (!avp) return (op == DIFF_OP);
1421 if (avp->flags & AVP_VAL_STR) {
1422 return val.s.len!=0;
1427 if (avp->flags & AVP_VAL_STR) {
1428 return comp_str(op, &val.s, rtype, r, msg, h);
1435 return comp_num(op, val.n, rtype, r, msg, h);
1439 tmp.len=strlen(r->string);
1440 if (str2int(&tmp, &uval)<0){
1441 LM_WARN("cannot convert string value to int (%s)\n",
1445 num_val.numval=uval;
1446 return comp_num(op, val.n, NUMBER_ST, &num_val, msg, h);
1448 if (str2int(&r->str, &uval)<0){
1449 LM_WARN("cannot convert str value to int (%.*s)\n",
1450 r->str.len, ZSW(r->str.s));
1453 num_val.numval=uval;
1454 return comp_num(op, val.n, NUMBER_ST, &num_val, msg, h);
1456 LM_CRIT("invalid type for numeric avp comparison (%d)\n",
1462 return (op == DIFF_OP) ? 1 : -1;
1466 * Left side of expression was select
1468 inline static int comp_select(int op, select_t* sel, int rtype,
1469 union exp_op* r, struct sip_msg* msg,
1470 struct run_act_ctx* h)
1476 ret = run_select(&val, sel, msg);
1477 if (ret != 0) return (op == DIFF_OP);
1479 if (op==NO_OP) return (val.len>0);
1480 if (unlikely(val.len==0)) {
1481 /* make sure the string pointer uses accessible memory range
1482 * the comp_str function might dereference it
1486 return comp_str(op, &val, rtype, r, msg, h);
1490 inline static int comp_rve(int op, struct rval_expr* rve, int rtype,
1491 union exp_op* r, struct sip_msg* msg,
1492 struct run_act_ctx* h)
1497 struct rval_cache c1;
1499 rval_cache_init(&c1);
1500 if (unlikely(rval_expr_eval_rvint(h, msg, &rv, &i, rve, &c1)<0)){
1501 LM_ERR("failure evaluating expression: bad type\n");
1507 rv1=rval_convert(h, msg, RV_STR, rv, &c1);
1508 i=comp_str(op, &rv1->v.s, rtype, r, msg, h);
1511 rval_cache_clean(&c1);
1514 /* expr evaluated to int */
1516 rval_cache_clean(&c1);
1518 return !(!i); /* transform it into { 0, 1 } */
1519 return comp_num(op, i, rtype, r, msg, h);
1524 inline static int comp_pvar(int op, pv_spec_t* pvs, int rtype,
1525 union exp_op* r, struct sip_msg* msg,
1526 struct run_act_ctx* h)
1532 memset(&pval, 0, sizeof(pv_value_t));
1533 if (unlikely(pv_get_spec_value(msg, r->param, &pval)!=0)){
1534 return 0; /* error, not found => false */
1536 if (likely(pval.flags & PV_TYPE_INT)){
1540 ret=comp_num(op, pval.ri, rtype, r, msg, h);
1541 }else if ((pval.flags==PV_VAL_NONE) ||
1542 (pval.flags & (PV_VAL_NULL|PV_VAL_EMPTY))){
1546 ret=comp_num(op, 0, rtype, r, msg, h);
1550 ret=comp_num(op, ret, rtype, r, msg, h);
1552 pv_value_destroy(&pval);
1558 /* check_self wrapper -- it checks also for the op */
1559 inline static int check_self_op(int op, str* s, unsigned short p)
1563 ret=check_self(s, p, 0);
1569 ret=(ret > 0) ? 0 : 1;
1572 LM_CRIT("invalid operator %d\n", op);
1579 /* eval_elem helping function, returns an op param */
1580 inline static int comp_ip(int op, struct ip_addr* ip, int rtype,
1581 union exp_op* r, struct sip_msg* msg,
1582 struct run_act_ctx *ctx )
1590 union exp_op r_expop;
1592 struct rval_cache rv_cache;
1598 right=NULL; /* warning fix */
1602 he=NULL; /* warning fix */
1607 ret=(matchnet(ip, r->net)==1);
1610 ret=(matchnet(ip, r->net)!=1);
1615 return ret; /* exit directly */
1616 case MYSELF_ST: /* check if it's one of our addresses*/
1617 tmp.s=ip_addr2a(ip);
1618 tmp.len=strlen(tmp.s);
1619 ret=check_self_op(op, &tmp, 0);
1626 rval_cache_init(&rv_cache);
1627 rv=rval_expr_eval(ctx, msg, r->param);
1628 if (unlikely (rv==0))
1629 return (op==DIFF_OP); /* not found or error*/
1630 if (unlikely(rval_get_tmp_str(ctx, msg, &tmp, rv, 0, &rv_cache)
1637 /* we can still have AVP_ST due to the RVE optimisations
1638 (if a RVE == $avp => rve wrapper removed => pure avp) */
1639 avp = search_avp_by_index(r->attr->type, r->attr->name,
1640 &val, r->attr->index);
1641 if (likely(avp && (avp->flags & AVP_VAL_STR))) right = &val.s;
1642 else return (op == DIFF_OP);
1645 /* see AVP_ST comment and s/AVP_ST/SELECT_ST/ */
1646 ret = run_select(&tmp, r->select, msg);
1647 if (unlikely(ret != 0))
1648 return (op == DIFF_OP); /* Not found or error */
1652 /* see AVP_ST comment and s/AVP_ST/PVAR_ST/ */
1653 memset(&pval, 0, sizeof(pv_value_t));
1654 if (unlikely(pv_get_spec_value(msg, r->param, &pval)!=0)){
1655 return (op == DIFF_OP); /* error, not found => false */
1658 if (likely(pval.flags & PV_VAL_STR)){
1661 pv_value_destroy(&pval);
1662 return (op == DIFF_OP); /* not found or invalid type */
1666 if (unlikely(op != MATCH_OP))
1668 /* 1: compare with ip2str*/
1669 ret=comp_string(op, ip_addr2a(ip), rtype, r, msg, ctx);
1672 /* 3: (slow) rev dns the address
1673 * and compare with all the aliases
1674 * !!??!! review: remove this? */
1675 if (unlikely((received_dns & DO_REV_DNS) &&
1676 ((he=rev_resolvehost(ip))!=0) )){
1677 /* compare with primary host name */
1678 ret=comp_string(op, he->h_name, rtype, r, msg, ctx);
1679 /* compare with all the aliases */
1680 for(h=he->h_aliases; (ret!=1) && (*h); h++){
1681 ret=comp_string(op, *h, rtype, r, msg, ctx);
1688 LM_CRIT("invalid type for src_ip or dst_ip (%d)\n", rtype);
1691 /* here "right" is set to the str we compare with */
1695 /* 0: try if ip or network (ip/mask) */
1696 if (mk_net_str(&net, right) == 0) {
1697 ret=(matchnet(ip, &net)==1);
1700 /* 2: resolve (name) & compare w/ all the ips */
1701 he=resolvehost(right->s);
1703 LM_DBG("could not resolve %s\n", r->str.s);
1704 }else if (he->h_addrtype==ip->af){
1705 for(h=he->h_addr_list;(ret!=1)&& (*h); h++){
1706 ret=(memcmp(ip->u.addr, *h, ip->len)==0);
1710 /* 3: (slow) rev dns the address
1711 * and compare with all the aliases
1712 * !!??!! review: remove this? */
1713 if (unlikely((received_dns & DO_REV_DNS) &&
1714 ((he=rev_resolvehost(ip))!=0) )){
1715 /* compare with primary host name */
1716 ret=comp_string(op, he->h_name, STR_ST, &r_expop, msg, ctx);
1717 /* compare with all the aliases */
1718 for(h=he->h_aliases; (ret!=1) && (*h); h++){
1719 ret=comp_string(op, *h, STR_ST, &r_expop, msg, ctx);
1726 /* 0: try if ip or network (ip/mask)
1727 (one should not use MATCH for that, but try to be nice)*/
1728 if (mk_net_str(&net, right) == 0) {
1729 ret=(matchnet(ip, &net)==1);
1732 /* 1: compare with ip2str (but only for =~)*/
1733 ret=comp_string(op, ip_addr2a(ip), STR_ST, &r_expop, msg, ctx);
1734 if (likely(ret==1)) break;
1735 /* 2: resolve (name) & compare w/ all the ips */
1736 he=resolvehost(right->s);
1738 LM_DBG("could not resolve %s\n", r->str.s);
1739 }else if (he->h_addrtype==ip->af){
1740 for(h=he->h_addr_list;(ret!=1)&& (*h); h++){
1741 ret=(memcmp(ip->u.addr, *h, ip->len)==0);
1745 /* 3: (slow) rev dns the address
1746 * and compare with all the aliases
1747 * !!??!! review: remove this? */
1748 if (unlikely((received_dns & DO_REV_DNS) &&
1749 ((he=rev_resolvehost(ip))!=0) )){
1750 /* compare with primary host name */
1751 ret=comp_string(op, he->h_name, STR_ST, &r_expop, msg, ctx);
1752 /* compare with all the aliases */
1753 for(h=he->h_aliases; (ret!=1) && (*h); h++){
1754 ret=comp_string(op, *h, STR_ST, &r_expop, msg, ctx);
1761 ret=(comp_ip(EQUAL_OP, ip, STR_ST, &r_expop, msg, ctx) > 0)?0:1;
1767 rval_cache_clean(&rv_cache);
1771 pv_value_destroy(&pval);
1774 LM_CRIT("invalid operator %d for type %d\n", op, rtype);
1777 rval_cache_clean(&rv_cache);
1781 pv_value_destroy(&pval);
1787 /* returns: 0/1 (false/true) or -1 on error */
1788 inline static int eval_elem(struct run_act_ctx* h, struct expr* e,
1789 struct sip_msg* msg)
1793 struct onsend_info* snd_inf;
1797 if (e->type!=ELEM_T){
1798 LM_CRIT("invalid type\n");
1803 if(msg->first_line.type==SIP_REQUEST)
1805 ret=comp_str(e->op, &msg->first_line.u.request.method,
1806 e->r_type, &e->r, msg, h);
1808 if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL)
1810 LM_ERR("cannot parse cseq header\n");
1813 ret=comp_str(e->op, &get_cseq(msg)->method,
1814 e->r_type, &e->r, msg, h);
1818 if(msg->new_uri.s) {
1819 if (e->r_type==MYSELF_ST){
1820 if (parse_sip_msg_uri(msg)<0) ret=-1;
1821 else ret=check_self_op(e->op, &msg->parsed_uri.host,
1822 GET_URI_PORT(&msg->parsed_uri));
1824 ret=comp_str(e->op, &msg->new_uri,
1825 e->r_type, &e->r, msg, h);
1828 if (e->r_type==MYSELF_ST){
1829 if (parse_sip_msg_uri(msg)<0) ret=-1;
1830 else ret=check_self_op(e->op, &msg->parsed_uri.host,
1831 GET_URI_PORT(&msg->parsed_uri));
1833 ret=comp_str(e->op, &msg->first_line.u.request.uri,
1834 e->r_type, &e->r, msg, h);
1840 if (parse_from_header(msg)!=0){
1841 LM_ERR("bad or missing From: header\n");
1844 if (e->r_type==MYSELF_ST){
1845 if (parse_uri(get_from(msg)->uri.s, get_from(msg)->uri.len,
1847 LM_ERR("bad uri in From:\n");
1850 ret=check_self_op(e->op, &uri.host, GET_URI_PORT(&uri));
1852 ret=comp_str(e->op, &get_from(msg)->uri,
1853 e->r_type, &e->r, msg, h);
1858 if ((msg->to==0) && ((parse_headers(msg, HDR_TO_F, 0)==-1) ||
1860 LM_ERR("bad or missing To: header\n");
1863 /* to content is parsed automatically */
1864 if (e->r_type==MYSELF_ST){
1865 if (parse_uri(get_to(msg)->uri.s, get_to(msg)->uri.len,
1867 LM_ERR("bad uri in To:\n");
1870 ret=check_self_op(e->op, &uri.host, GET_URI_PORT(&uri));
1872 ret=comp_str(e->op, &get_to(msg)->uri,
1873 e->r_type, &e->r, msg, h);
1878 ret=comp_ip(e->op, &msg->rcv.src_ip, e->r_type, &e->r, msg, h);
1882 ret=comp_ip(e->op, &msg->rcv.dst_ip, e->r_type, &e->r, msg, h);
1886 snd_inf=get_onsend_info();
1887 if (likely(snd_inf && snd_inf->send_sock)){
1888 ret=comp_ip(e->op, &snd_inf->send_sock->address,
1889 e->r_type, &e->r, msg, h);
1891 BUG("eval_elem: snd_ip unknown (not in a onsend_route?)\n");
1896 snd_inf=get_onsend_info();
1897 if (likely(snd_inf && snd_inf->to)){
1898 su2ip_addr(&ip, snd_inf->to);
1899 ret=comp_ip(e->op, &ip, e->r_type, &e->r, msg, h);
1901 BUG("eval_elem: to_ip unknown (not in a onsend_route?)\n");
1906 ret=!(!e->r.numval); /* !! to transform it in {0,1} */
1910 ret=run_actions(h, (struct action*)e->r.param, msg);
1916 ret=comp_num(e->op, (int)msg->rcv.src_port, e->r_type, &e->r, msg, h);
1920 ret=comp_num(e->op, (int)msg->rcv.dst_port, e->r_type, &e->r, msg, h);
1924 snd_inf=get_onsend_info();
1925 if (likely(snd_inf && snd_inf->send_sock)){
1926 ret=comp_num(e->op, (int)snd_inf->send_sock->port_no,
1927 e->r_type, &e->r, msg, h);
1929 BUG("eval_elem: snd_port unknown (not in a onsend_route?)\n");
1934 snd_inf=get_onsend_info();
1935 if (likely(snd_inf && snd_inf->to)){
1936 ret=comp_num(e->op, (int)su_getport(snd_inf->to),
1937 e->r_type, &e->r, msg, h);
1939 BUG("eval_elem: to_port unknown (not in a onsend_route?)\n");
1944 ret=comp_num(e->op, msg->rcv.proto, e->r_type, &e->r, msg, h);
1948 snd_inf=get_onsend_info();
1949 if (likely(snd_inf && snd_inf->send_sock)){
1950 ret=comp_num(e->op, snd_inf->send_sock->proto,
1951 e->r_type, &e->r, msg, h);
1953 BUG("eval_elem: snd_proto unknown (not in a onsend_route?)\n");
1958 ret=comp_num(e->op, (int)msg->rcv.src_ip.af, e->r_type, &e->r, msg, h);
1962 snd_inf=get_onsend_info();
1963 if (likely(snd_inf && snd_inf->send_sock)){
1964 ret=comp_num(e->op, snd_inf->send_sock->address.af,
1965 e->r_type, &e->r, msg, h);
1967 BUG("eval_elem: snd_af unknown (not in a onsend_route?)\n");
1972 if ((snd_inf=get_onsend_info())!=0){
1973 ret=comp_num(e->op, (int)snd_inf->len, e->r_type, &e->r, msg, h);
1975 ret=comp_num(e->op, (int)msg->len, e->r_type, &e->r, msg, h);
1980 ret=comp_num(e->op, h->last_retcode, e->r_type, &e->r, msg, h);
1984 ret = comp_avp(e->op, e->l.attr, e->r_type, &e->r, msg, h);
1988 ret = comp_select(e->op, e->l.select, e->r_type, &e->r, msg, h);
1992 ret = comp_rve(e->op, e->l.param, e->r_type, &e->r, msg, h);
1996 ret=comp_pvar(e->op, e->l.param, e->r_type, &e->r, msg, h);
1999 case SELECT_UNFIXED_O:
2000 BUG("unexpected unfixed select operand %d\n", e->l_type);
2004 LM_CRIT("invalid operand %d\n", e->l_type);
2009 return (e->op == DIFF_OP) ? 1 : -1;
2014 /* ret= 1/0 (true/false) , -1 on error (evaluates as false)*/
2015 int eval_expr(struct run_act_ctx* h, struct expr* e, struct sip_msg* msg)
2019 if (e->type==ELEM_T){
2020 ret=eval_elem(h, e, msg);
2021 }else if (e->type==EXP_T){
2024 ret=eval_expr(h, e->l.expr, msg);
2025 /* if error or false stop evaluating the rest */
2026 if (ret <= 0) break;
2027 ret=eval_expr(h, e->r.expr, msg); /*ret1 is 1*/
2030 ret=eval_expr(h, e->l.expr, msg);
2031 /* if true stop evaluating the rest */
2033 ret=eval_expr(h, e->r.expr, msg); /* ret1 is 0 */
2036 ret=eval_expr(h, e->l.expr, msg);
2037 ret=(ret > 0) ? 0 : 1;
2040 LM_CRIT("unknown op %d\n", e->op);
2044 LM_CRIT("unknown type %d\n", e->type);
2051 /* adds an action list to head; a must be null terminated (last a->next=0))*/
2052 void push(struct action* a, struct action** head)
2059 for (t=*head; t->next;t=t->next);
2066 int add_actions(struct action* a, struct action** head)
2070 LM_DBG("fixing actions...\n");
2071 if ((ret=fix_actions(a))!=0) goto error;
2081 static int fix_rl(struct route_list* rt)
2086 for(i=0;i<rt->idx; i++){
2088 if ((ret=fix_actions(rt->rlist[i]))!=0){
2098 /* fixes all action tables */
2099 /* returns 0 if ok , <0 on error */
2104 if ((ret=fix_rl(&main_rt))!=0)
2106 if ((ret=fix_rl(&onreply_rt))!=0)
2108 if ((ret=fix_rl(&failure_rt))!=0)
2110 if ((ret=fix_rl(&branch_rt))!=0)
2112 if ((ret=fix_rl(&onsend_rt))!=0)
2114 if ((ret=fix_rl(&event_rt))!=0)
2122 static void print_rl(struct route_list* rt, char* name)
2126 for(j=0; j<rt->entries; j++){
2127 if (rt->rlist[j]==0){
2128 if ((j==0) && (rt==&main_rt))
2129 LM_DBG("WARNING: the main routing table is empty\n");
2132 DBG("%s routing table %d:\n", name, j);
2133 print_actions(rt->rlist[j]);
2139 /* debug function, prints routing tables */
2142 print_rl(&main_rt, "");
2143 print_rl(&onreply_rt, "onreply");
2144 print_rl(&failure_rt, "failure");
2145 print_rl(&branch_rt, "branch");
2146 print_rl(&onsend_rt, "onsend");
2147 print_rl(&event_rt, "event");