diff --git a/src/core/action.c b/src/core/action.c index b95c531e1dd..9f3438fc747 100644 --- a/src/core/action.c +++ b/src/core/action.c @@ -294,7 +294,8 @@ char *get_cfg_crt_route_name(void) int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) { int ret; - int v; + long li; + long v; struct dest_info dst; char* tmp; char *new_uri, *end, *crt; @@ -352,9 +353,10 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) break; case RVE_ST: rve=(struct rval_expr*)a->val[0].u.data; - if(rval_expr_eval_int(h, msg, &ret, rve)<0) { + if(rval_expr_eval_long(h, msg, &li, rve)<0) { LM_WARN("failed to eval int expression\n"); } + ret = (int)li; break; case RETCODE_ST: ret=h->last_retcode; @@ -1052,7 +1054,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) break; case IF_T: rve=(struct rval_expr*)a->val[0].u.data; - if (unlikely(rval_expr_eval_int(h, msg, &v, rve) != 0)){ + if (unlikely(rval_expr_eval_long(h, msg, &v, rve) != 0)){ ERR("if expression evaluation failed (%d,%d-%d,%d)\n", rve->fpos.s_line, rve->fpos.s_col, rve->fpos.e_line, rve->fpos.e_col); @@ -1184,7 +1186,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) case EVAL_T: /* only eval the expression to account for possible side-effect */ - rval_expr_eval_int(h, msg, &v, + rval_expr_eval_long(h, msg, &v, (struct rval_expr*)a->val[0].u.data); if (h->run_flags & EXIT_R_F){ ret=0; @@ -1196,7 +1198,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) break; case SWITCH_COND_T: sct=(struct switch_cond_table*)a->val[1].u.data; - if (unlikely( rval_expr_eval_int(h, msg, &v, + if (unlikely(rval_expr_eval_long(h, msg, &v, (struct rval_expr*)a->val[0].u.data) <0)){ /* handle error in expression => use default */ ret=-1; @@ -1227,7 +1229,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) break; case SWITCH_JT_T: sjt=(struct switch_jmp_table*)a->val[1].u.data; - if (unlikely( rval_expr_eval_int(h, msg, &v, + if (unlikely(rval_expr_eval_long(h, msg, &v, (struct rval_expr*)a->val[0].u.data) <0)){ /* handle error in expression => use default */ ret=-1; @@ -1278,7 +1280,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) rval_cache_init(&c1); rv=0; rv1=0; - ret=rval_expr_eval_rvint(h, msg, &rv, &v, + ret=rval_expr_eval_rvlong(h, msg, &rv, &v, (struct rval_expr*)a->val[0].u.data, &c1); if (unlikely( ret<0)){ @@ -1363,7 +1365,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) rve=(struct rval_expr*)a->val[0].u.data; ret=1; while(!(flags & (BREAK_R_F|RETURN_R_F|EXIT_R_F)) && - (rval_expr_eval_int(h, msg, &v, rve) == 0) && + (rval_expr_eval_long(h, msg, &v, rve) == 0) && ((ksr_return_mode==0 && v>0) || (ksr_return_mode!=0 && v!=0))) { if (cfg_get(core, core_cfg, max_while_loops) > 0) i++; @@ -1493,7 +1495,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) v=(int)a->val[1].u.number; break; case RVE_ST: - if (rval_expr_eval_int(h, msg, &v, (struct rval_expr*)a->val[1].u.data) < 0) { + if (rval_expr_eval_long(h, msg, &v, (struct rval_expr*)a->val[1].u.data) < 0) { ret=-1; goto error; } diff --git a/src/core/route.c b/src/core/route.c index 796fe0feb5c..41bcad5c8a2 100644 --- a/src/core/route.c +++ b/src/core/route.c @@ -618,7 +618,8 @@ int fix_actions(struct action* a) char *tmp; void *tmp_p; int ret; - int i; + long li; + long i; ksr_cmd_export_t* cmd; str s; struct hostent* he; @@ -1113,7 +1114,7 @@ int fix_actions(struct action* a) int */ rv = rval_expr_eval(0, 0, rve); if (rv == 0 || - rval_get_int( 0, 0, &i, rv, 0) < 0 ) { + rval_get_long(0, 0, &li, rv, 0) < 0 ) { LM_ERR("failed to fix constant rve"); if (rv) rval_destroy(rv); ret = E_BUG; @@ -1122,7 +1123,7 @@ int fix_actions(struct action* a) rval_destroy(rv); rve_destroy(rve); t->val[1].type = NUMBER_ST; - t->val[1].u.number = i; + t->val[1].u.number = li; } else { /* expression is not constant => fixup & optimize it */ @@ -1184,7 +1185,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r, int_str val; pv_value_t pval; avp_t* avp; - int right; + long right; if (unlikely(op==NO_OP)) return !(!left); switch(rtype){ @@ -1198,7 +1199,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r, right = r->numval; break; case RVE_ST: - if (unlikely(rval_expr_eval_int(h, msg, &right, r->param)<0)) + if (unlikely(rval_expr_eval_long(h, msg, &right, r->param)<0)) return (op == DIFF_OP); /* not found/invalid */ break; case PVAR_ST: @@ -1508,13 +1509,13 @@ inline static int comp_rve(int op, struct rval_expr* rve, int rtype, union exp_op* r, struct sip_msg* msg, struct run_act_ctx* h) { - int i; + long i; struct rvalue* rv; struct rvalue* rv1; struct rval_cache c1; - + rval_cache_init(&c1); - if (unlikely(rval_expr_eval_rvint(h, msg, &rv, &i, rve, &c1)<0)){ + if (unlikely(rval_expr_eval_rvlong(h, msg, &rv, &i, rve, &c1)<0)){ LM_ERR("failure evaluating expression: bad type\n"); i=0; /* false */ goto int_expr; @@ -1544,7 +1545,7 @@ inline static int comp_pvar(int op, pv_spec_t* pvs, int rtype, { pv_value_t pval; int ret; - + ret=0; memset(&pval, 0, sizeof(pv_value_t)); if (unlikely(pv_get_spec_value(msg, r->param, &pval)!=0)){ diff --git a/src/core/rvalue.c b/src/core/rvalue.c index 4ab93f44f49..a79d82689b3 100644 --- a/src/core/rvalue.c +++ b/src/core/rvalue.c @@ -905,8 +905,8 @@ int rve_check_type(enum rval_type* type, struct rval_expr* rve, -/** get the integer value of an rvalue. - * *i=(int)rv +/** get the long int value of an rvalue. + * *i=(long int)rv * if rv == undefined select, avp or pvar, return 0. * if an error occurs while evaluating a select, avp or pvar, behave as * for the undefined case (and return success). @@ -918,8 +918,8 @@ int rve_check_type(enum rval_type* type, struct rval_expr* rve, * * @return 0 on success, \<0 on error and EXPR_DROP on drop */ -int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, - int* i, struct rvalue* rv, +long rval_get_long(struct run_act_ctx* h, struct sip_msg* msg, + long* i, struct rvalue* rv, struct rval_cache* cache) { avp_t* r_avp; @@ -1040,7 +1040,7 @@ int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, /* rv is of string type => try to convert it to int */ /* if "" => 0 (most likely case) */ if (likely(s->len==0)) *i=0; - else if (unlikely(str2sint(s, i)!=0)){ + else if (unlikely(str2slong(s, i)!=0)){ /* dec to int failed, try hex to int */ if(!(s->len>2 && s->s[0]=='0' && (s->s[1]=='x' || s->s[1]=='X') && (hexstr2int(s->s+2, s->len-2, (unsigned int*)i)==0))) { @@ -1078,36 +1078,36 @@ int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, (rve)->fpos.e_line, rve->fpos.e_col ) -/** macro for checking and handling rval_get_int() retcode. - * check if the return code is an rval_get_int error and if so +/** macro for checking and handling rval_get_long() retcode. + * check if the return code is an rval_get_long error and if so * handle the error (e.g. print a log message, ignore the error by * setting ret to 0 a.s.o.) - * @param ret - retcode as returned by rval_get_int() (might be changed) + * @param ret - retcode as returned by rval_get_long() (might be changed) * @param txt - warning message txt (no pointer allowed) * @param rve - rval_expr, used to access the config. pos */ -#if defined RVAL_GET_INT_ERR_WARN && defined RVAL_GET_INT_ERR_IGN -#define rval_get_int_handle_ret(ret, txt, rve) \ +#if defined RVAL_GET_LONG_ERR_WARN && defined RVAL_GET_LONG_ERR_IGN +#define rval_get_LONG_handle_ret(ret, txt, rve) \ do { \ if (unlikely((ret)<0)) { \ RVE_LOG(L_WARN, rve, txt); \ (ret)=0; \ } \ }while(0) -#elif defined RVAL_GET_INT_ERR_WARN -#define rval_get_int_handle_ret(ret, txt, rve) \ +#elif defined RVAL_GET_LONG_ERR_WARN +#define rval_get_long_handle_ret(ret, txt, rve) \ do { \ if (unlikely((ret)<0)) \ RVE_LOG(L_WARN, rve, txt); \ }while(0) -#elif defined RVAL_GET_INT_ERR_IGN -#define rval_get_int_handle_ret(ret, txt, rve) \ +#elif defined RVAL_GET_LONG_ERR_IGN +#define rval_get_long_handle_ret(ret, txt, rve) \ do { \ if (unlikely((ret)<0)) \ (ret)=0; \ } while(0) #else -#define rval_get_int_handle_ret(ret, txt, rve) /* do nothing */ +#define rval_get_long_handle_ret(ret, txt, rve) /* do nothing */ #endif @@ -1335,7 +1335,7 @@ struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, enum rval_type type, struct rvalue* v, struct rval_cache* c) { - int i; + long i; struct rval_cache tmp_cache; str tmp; struct rvalue* ret; @@ -1347,7 +1347,7 @@ struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, } switch(type){ case RV_LONG: - if (unlikely(rval_get_int(h, msg, &i, v, c) < 0)) + if (unlikely(rval_get_long(h, msg, &i, v, c) < 0)) return 0; val.l=i; return rval_new(RV_LONG, &val, 0); @@ -1374,7 +1374,7 @@ struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, /** integer operation: *res= op v. * @return 0 on succes, \<0 on error */ -inline static int int_intop1(int* res, enum rval_expr_op op, int v) +inline static int long_longop1(long* res, enum rval_expr_op op, long v) { switch(op){ case RVE_UMINUS_OP: @@ -1401,7 +1401,7 @@ inline static int int_intop1(int* res, enum rval_expr_op op, int v) /** integer operation: *res= v1 op v2 * @return 0 on succes, \<0 on error */ -inline static int int_intop2(int* res, enum rval_expr_op op, int v1, int v2) +inline static int long_longop2(long* res, enum rval_expr_op op, long v1, long v2) { switch(op){ case RVE_PLUS_OP: @@ -1486,7 +1486,7 @@ inline static int int_intop2(int* res, enum rval_expr_op op, int v1, int v2) * Warning: rv1 & rv2 must be RV_STR * @return 0 on success, -1 on error */ -inline static int bool_rvstrop2( enum rval_expr_op op, int* res, +inline static int bool_rvstrop2( enum rval_expr_op op, long* res, struct rvalue* rv1, struct rvalue* rv2) { str* s1; @@ -1534,7 +1534,7 @@ inline static int bool_rvstrop2( enum rval_expr_op op, int* res, /** integer returning operation on string: *res= op str (returns integer) * @return 0 on succes, \<0 on error */ -inline static int int_strop1(int* res, enum rval_expr_op op, str* s1) +inline static int long_strop1(long* res, enum rval_expr_op op, str* s1) { switch(op){ case RVE_STRLEN_OP: @@ -1552,105 +1552,6 @@ inline static int int_strop1(int* res, enum rval_expr_op op, str* s1) } -#if 0 -/** integer operation: ret= op v (returns a rvalue). - * @return rvalue on success, 0 on error - */ -inline static struct rvalue* rval_intop1(struct run_act_ctx* h, - struct sip_msg* msg, - enum rval_expr_op op, - struct rvalue* v) -{ - struct rvalue* rv2; - struct rvalue* ret; - int i; - - i=0; - rv2=rval_convert(h, msg, RV_LONG, v, 0); - if (unlikely(rv2==0)){ - LM_ERR("rval int conversion failed\n"); - goto error; - } - if (unlikely(int_intop1(&i, op, rv2->v.l)<0)) - goto error; - if (rv_chg_in_place(rv2)){ - ret=rv2; - rv_ref(ret); - }else if (rv_chg_in_place(v)){ - ret=v; - rv_ref(ret); - }else{ - ret=rval_new(RV_LONG, &rv2->v, 0); - if (unlikely(ret==0)){ - LM_ERR("eval out of memory\n"); - goto error; - } - } - rval_destroy(rv2); - ret->v.l=i; - return ret; -error: - rval_destroy(rv2); - return 0; -} - - - -/** integer operation: ret= l op r (returns a rvalue). - * @return rvalue on success, 0 on error - */ -inline static struct rvalue* rval_intop2(struct run_act_ctx* h, - struct sip_msg* msg, - enum rval_expr_op op, - struct rvalue* l, - struct rvalue* r) -{ - struct rvalue* rv1; - struct rvalue* rv2; - struct rvalue* ret; - int i; - - rv2=rv1=0; - ret=0; - if ((rv1=rval_convert(h, msg, RV_LONG, l, 0))==0) - goto error; - if ((rv2=rval_convert(h, msg, RV_LONG, r, 0))==0) - goto error; - if (unlikely(int_intop2(&i, op, rv1->v.l, rv2->v.l)<0)) - goto error; - if (rv_chg_in_place(rv1)){ - /* try reusing rv1 */ - ret=rv1; - rv_ref(ret); - }else if (rv_chg_in_place(rv2)){ - /* try reusing rv2 */ - ret=rv2; - rv_ref(ret); - }else if ((l->type==RV_LONG) && (rv_chg_in_place(l))){ - ret=l; - rv_ref(ret); - } else if ((r->type==RV_LONG) && (rv_chg_in_place(r))){ - ret=r; - rv_ref(ret); - }else{ - ret=rval_new(RV_LONG, &rv1->v, 0); - if (unlikely(ret==0)){ - LM_ERR("rv eval out of memory\n"); - goto error; - } - } - rval_destroy(rv1); - rval_destroy(rv2); - ret->v.l=i; - return ret; -error: - rval_destroy(rv1); - rval_destroy(rv2); - return 0; -} -#endif /* #if 0 */ - - /** string add operation: ret= l . r (returns a rvalue). * Can use cached rvalues (c1 & c2). * @return rvalue on success, 0 on error @@ -1776,7 +1677,7 @@ inline static struct rvalue* rval_str_add2(struct run_act_ctx* h, */ inline static int rval_str_lop2(struct run_act_ctx* h, struct sip_msg* msg, - int* res, + long* res, enum rval_expr_op op, struct rvalue* l, struct rval_cache* c1, @@ -1818,9 +1719,9 @@ inline static int rval_str_lop2(struct run_act_ctx* h, * @param c1 rvalue cache * @return 0 success, -1 on error */ -inline static int rval_int_strop1(struct run_act_ctx* h, +inline static int rval_long_strop1(struct run_act_ctx* h, struct sip_msg* msg, - int* res, + long* res, enum rval_expr_op op, struct rvalue* l, struct rval_cache* c1) @@ -1832,7 +1733,7 @@ inline static int rval_int_strop1(struct run_act_ctx* h, ret=0; if ((rv1=rval_convert(h, msg, RV_STR, l, c1))==0) goto error; - ret=int_strop1(res, op, &rv1->v.s); + ret=long_strop1(res, op, &rv1->v.s); rval_destroy(rv1); return ret; error: @@ -1857,7 +1758,7 @@ inline static int rval_int_strop1(struct run_act_ctx* h, * undefined (and it's not reported) */ inline static int rv_defined(struct run_act_ctx* h, - struct sip_msg* msg, int* res, + struct sip_msg* msg, long* res, struct rvalue* rv, struct rval_cache* cache) { avp_t* r_avp; @@ -1921,8 +1822,8 @@ inline static int rv_defined(struct run_act_ctx* h, * @param rve rvalue expression * @return 0 on success, -1 on error */ -inline static int int_rve_defined(struct run_act_ctx* h, - struct sip_msg* msg, int* res, +inline static int long_rve_defined(struct run_act_ctx* h, + struct sip_msg* msg, long* res, struct rval_expr* rve) { /* only a rval can be undefined, any expression consisting on more @@ -1935,15 +1836,15 @@ inline static int int_rve_defined(struct run_act_ctx* h, -/** evals an integer expr to an int. +/** evals a long expr to a long. * * *res=(int)eval(rve) * @return 0 on success, \<0 on error */ -int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, - int* res, struct rval_expr* rve) +int rval_expr_eval_long( struct run_act_ctx* h, struct sip_msg* msg, + long* res, struct rval_expr* rve) { - int i1, i2, ret; + long i1, i2, ret; struct rval_cache c1, c2; struct rvalue* rv1; struct rvalue* rv2; @@ -1951,8 +1852,8 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, ret=-1; switch(rve->op){ case RVE_RVAL_OP: - ret=rval_get_int(h, msg, res, &rve->left.rval, 0); - rval_get_int_handle_ret(ret, "rval expression conversion to int" + ret=rval_get_long(h, msg, res, &rve->left.rval, 0); + rval_get_long_handle_ret(ret, "rval expression conversion to int" " failed", rve); break; case RVE_UMINUS_OP: @@ -1960,12 +1861,12 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, case RVE_LNOT_OP: case RVE_BNOT_OP: if (unlikely( - (ret=rval_expr_eval_int(h, msg, &i1, rve->left.rve)) <0) ) + (ret=rval_expr_eval_long(h, msg, &i1, rve->left.rve)) <0) ) break; - ret=int_intop1(res, rve->op, i1); + ret=long_longop1(res, rve->op, i1); break; case RVE_LONG_OP: - ret=rval_expr_eval_int(h, msg, res, rve->left.rve); + ret=rval_expr_eval_long(h, msg, res, rve->left.rve); break; case RVE_MUL_OP: case RVE_DIV_OP: @@ -1985,21 +1886,21 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, case RVE_IEQ_OP: case RVE_IDIFF_OP: if (unlikely( - (ret=rval_expr_eval_int(h, msg, &i1, rve->left.rve)) <0) ) + (ret=rval_expr_eval_long(h, msg, &i1, rve->left.rve)) <0) ) break; if (unlikely( - (ret=rval_expr_eval_int(h, msg, &i2, rve->right.rve)) <0) ) + (ret=rval_expr_eval_long(h, msg, &i2, rve->right.rve)) <0) ) break; - ret=int_intop2(res, rve->op, i1, i2); + ret=long_longop2(res, rve->op, i1, i2); break; case RVE_LAND_OP: if (unlikely( - (ret=rval_expr_eval_int(h, msg, &i1, rve->left.rve)) <0) ) + (ret=rval_expr_eval_long(h, msg, &i1, rve->left.rve)) <0) ) break; if (i1==0){ *res=0; }else{ - if (unlikely( (ret=rval_expr_eval_int(h, msg, &i2, + if (unlikely( (ret=rval_expr_eval_long(h, msg, &i2, rve->right.rve)) <0) ) break; *res=i1 && i2; @@ -2008,12 +1909,12 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, break; case RVE_LOR_OP: if (unlikely( - (ret=rval_expr_eval_int(h, msg, &i1, rve->left.rve)) <0) ) + (ret=rval_expr_eval_long(h, msg, &i1, rve->left.rve)) <0) ) break; if (i1){ *res=1; }else{ - if (unlikely( (ret=rval_expr_eval_int(h, msg, &i2, + if (unlikely( (ret=rval_expr_eval_long(h, msg, &i2, rve->right.rve)) <0) ) break; *res=i1 || i2; @@ -2028,7 +1929,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, * if left is undef, look at right and convert to right type */ rval_cache_init(&c1); - if (unlikely( (ret=rval_expr_eval_rvint(h, msg, &rv1, &i1, + if (unlikely( (ret=rval_expr_eval_rvlong(h, msg, &rv1, &i1, rve->left.rve, &c1))<0)){ /* error */ rval_cache_clean(&c1); @@ -2037,10 +1938,10 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, if (likely(rv1==0)){ /* int */ rval_cache_clean(&c1); - if (unlikely( (ret=rval_expr_eval_int(h, msg, &i2, + if (unlikely( (ret=rval_expr_eval_long(h, msg, &i2, rve->right.rve)) <0) ) break; /* error */ - ret=int_intop2(res, rve->op, i1, i2); + ret=long_longop2(res, rve->op, i1, i2); }else{ /* not int => str or undef */ /* check for undefined left operand */ @@ -2064,7 +1965,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, /* undef == val * => convert to (type_of(val)) (undef) == val */ rval_cache_init(&c2); - if (unlikely( (ret=rval_expr_eval_rvint(h, msg, &rv2, &i2, + if (unlikely( (ret=rval_expr_eval_rvlong(h, msg, &rv2, &i2, rve->right.rve, &c2))<0)){ /* error */ rval_cache_clean(&c1); @@ -2074,7 +1975,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, } if (rv2==0){ /* int */ - ret=int_intop2(res, rve->op, 0 /* undef */, i2); + ret=long_longop2(res, rve->op, 0 /* undef */, i2); }else{ /* str or undef */ ret=rval_str_lop2(h, msg, res, rve->op, rv1, &c1, @@ -2109,15 +2010,15 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, break; } /* convert to int */ - ret=rval_get_int(h, msg, res, rv1, 0); /* convert to int */ - rval_get_int_handle_ret(ret, "rval expression conversion to int" + ret=rval_get_long(h, msg, res, rv1, 0); /* convert to int */ + rval_get_long_handle_ret(ret, "rval expression conversion to int" " failed", rve); rval_destroy(rv1); break; case RVE_STR_OP: /* (str)expr => eval expression */ rval_cache_init(&c1); - if (unlikely((ret=rval_expr_eval_rvint(h, msg, &rv1, res, + if (unlikely((ret=rval_expr_eval_rvlong(h, msg, &rv1, res, rve->left.rve, &c1))<0)){ /* error */ rval_cache_clean(&c1); @@ -2125,36 +2026,19 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, } if (unlikely(rv1)){ /* expr evaluated to string => (int)(str)v == (int)v */ - ret=rval_get_int(h, msg, res, rv1, &c1); /* convert to int */ - rval_get_int_handle_ret(ret, "rval expression conversion" + ret=rval_get_long(h, msg, res, rv1, &c1); /* convert to int */ + rval_get_long_handle_ret(ret, "rval expression conversion" " to int failed", rve); rval_destroy(rv1); rval_cache_clean(&c1); } - /* else (rv1==0) - * => expr evaluated to int => - * return (int)(str)v == (int)v => do nothing */ break; -#if 0 - /* same thing as above, but in a not optimized, easier to - * understand way */ - /* 1. (str) expr => eval expr */ - if (unlikely((rv1=rval_expr_eval(h, msg, rve->left.rve))==0)){ - ret=-1; - break; - } - /* 2. convert to str and then convert to int - * but since (int)(str)v == (int)v skip over (str)v */ - ret=rval_get_int(h, msg, res, rv1, 0); /* convert to int */ - rval_destroy(rv1); - break; -#endif case RVE_DEFINED_OP: - ret=int_rve_defined(h, msg, res, rve->left.rve); + ret=long_rve_defined(h, msg, res, rve->left.rve); break; case RVE_NOTDEFINED_OP: - ret=int_rve_defined(h, msg, res, rve->left.rve); + ret=long_rve_defined(h, msg, res, rve->left.rve); *res = !(*res); break; case RVE_STREQ_OP: @@ -2179,7 +2063,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, ret=-1; break; } - ret=rval_int_strop1(h, msg, res, rve->op, rv1, 0); + ret=rval_long_strop1(h, msg, res, rve->op, rv1, 0); rval_destroy(rv1); break; case RVE_SELVALEXP_OP: @@ -2218,10 +2102,10 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, * when done. * @return 0 on success, -1 on error, sets *res_rv or *res_i. */ -int rval_expr_eval_rvint( struct run_act_ctx* h, +int rval_expr_eval_rvlong( struct run_act_ctx* h, struct sip_msg* msg, struct rvalue** res_rv, - int* res_i, + long* res_i, struct rval_expr* rve, struct rval_cache* cache ) @@ -2230,7 +2114,7 @@ int rval_expr_eval_rvint( struct run_act_ctx* h, struct rvalue* rv2; struct rval_cache c1; /* local cache */ int ret; - int r, i, j; + long r, i, j; enum rval_type type; rv1=0; @@ -2242,8 +2126,8 @@ int rval_expr_eval_rvint( struct run_act_ctx* h, rv_ref(rv1); type=rval_get_btype(h, msg, rv1, cache); if (type==RV_LONG){ - r=rval_get_int(h, msg, res_i, rv1, cache); - rval_get_int_handle_ret(r, "rval expression conversion" + r=rval_get_long(h, msg, res_i, rv1, cache); + rval_get_long_handle_ret(r, "rval expression conversion" " to int failed", rve); *res_rv=0; ret=r; /* equiv. to if (r<0) goto error */ @@ -2288,12 +2172,12 @@ int rval_expr_eval_rvint( struct run_act_ctx* h, case RVE_NOTDEFINED_OP: case RVE_LONG_OP: /* operator forces integer type */ - ret=rval_expr_eval_int(h, msg, res_i, rve); + ret=rval_expr_eval_long(h, msg, res_i, rve); *res_rv=0; break; case RVE_PLUS_OP: rval_cache_init(&c1); - r=rval_expr_eval_rvint(h, msg, &rv1, &i, rve->left.rve, &c1); + r=rval_expr_eval_rvlong(h, msg, &rv1, &i, rve->left.rve, &c1); if (unlikely(r<0)){ LM_ERR("rval expression evaluation failed (%d,%d-%d,%d)\n", rve->left.rve->fpos.s_line, rve->left.rve->fpos.s_col, @@ -2303,7 +2187,7 @@ int rval_expr_eval_rvint( struct run_act_ctx* h, goto error; } if (rv1==0){ - if (unlikely((r=rval_expr_eval_int(h, msg, &j, + if (unlikely((r=rval_expr_eval_long(h, msg, &j, rve->right.rve))<0)){ LM_ERR("rval expression evaluation failed (%d,%d-%d,%d)" "\n", rve->right.rve->fpos.s_line, @@ -2313,7 +2197,7 @@ int rval_expr_eval_rvint( struct run_act_ctx* h, rval_cache_clean(&c1); goto error; } - ret=int_intop2(res_i, rve->op, i, j); + ret=long_longop2(res_i, rve->op, i, j); *res_rv=0; }else{ rv2=rval_expr_eval(h, msg, rve->right.rve); @@ -2378,7 +2262,7 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, struct rvalue* ret; struct rval_cache c1; union rval_val v; - int r, i, j; + long r, i, j; enum rval_type type; rv1=0; @@ -2422,7 +2306,7 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, case RVE_NOTDEFINED_OP: case RVE_LONG_OP: /* operator forces integer type */ - r=rval_expr_eval_int(h, msg, &i, rve); + r=rval_expr_eval_long(h, msg, &i, rve); if (likely(r==0)){ v.l=i; ret=rval_new(RV_LONG, &v, 0); @@ -2450,15 +2334,15 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, type=rval_get_btype(h, msg, rv1, &c1); switch(type){ case RV_LONG: - r=rval_get_int(h, msg, &i, rv1, &c1); - rval_get_int_handle_ret(r, "rval expression left side " + r=rval_get_long(h, msg, &i, rv1, &c1); + rval_get_long_handle_ret(r, "rval expression left side " "conversion to int failed", rve); if (unlikely(r<0)){ rval_cache_clean(&c1); goto error; } - if (unlikely((r=rval_expr_eval_int(h, msg, &j, + if (unlikely((r=rval_expr_eval_long(h, msg, &j, rve->right.rve))<0)){ rval_cache_clean(&c1); LM_ERR("rval expression evaluation failed (%d,%d-%d,%d):" @@ -2467,7 +2351,7 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, rve->fpos.e_line, rve->fpos.e_col); goto error; } - int_intop2(&r, rve->op, i, j); + long_longop2(&r, rve->op, i, j); if (rv_chg_in_place(rv1)){ rv1->v.l=r; ret=rv1; @@ -2534,7 +2418,7 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, break; case RVE_SELVALEXP_OP: /* operator forces integer type */ - r=rval_expr_eval_int(h, msg, &i, rve->left.rve); + r=rval_expr_eval_long(h, msg, &i, rve->left.rve); if (unlikely(r!=0)){ LM_ERR("rval expression evaluation failed (%d,%d-%d,%d)\n", rve->fpos.s_line, rve->fpos.s_col, @@ -2556,8 +2440,8 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, type=rval_get_btype(h, msg, rv1, &c1); switch(type){ case RV_LONG: - r=rval_get_int(h, msg, &i, rv1, &c1); - rval_get_int_handle_ret(r, "rval expression left side " + r=rval_get_long(h, msg, &i, rv1, &c1); + rval_get_long_handle_ret(r, "rval expression left side " "conversion to int failed", rve); if (unlikely(r<0)){ @@ -2922,65 +2806,6 @@ static int rve_op_is_commutative(enum rval_expr_op op) } -#if 0 -/** returns true if the rval expr can be optimized to an int. - * (if left & right are leafs (RVE_RVAL_OP) and both of them are - * ints return true, else false) - * @return 0 or 1 - */ -static int rve_can_optimize_int(struct rval_expr* rve) -{ - if (scr_opt_lev<1) - return 0; - if (rve->op == RVE_RVAL_OP) - return 0; - if (rve->left.rve->op != RVE_RVAL_OP) - return 0; - if (rve->left.rve->left.rval.type!=RV_LONG) - return 0; - if (rve->right.rve){ - if (rve->right.rve->op != RVE_RVAL_OP) - return 0; - if (rve->right.rve->left.rval.type!=RV_LONG) - return 0; - } - LM_DBG("left %d, right %d\n", - rve->left.rve->op, rve->right.rve?rve->right.rve->op:0); - return 1; -} - - - -/** returns true if the rval expr can be optimized to a str. - * (if left & right are leafs (RVE_RVAL_OP) and both of them are - * str or left is str and right is int return true, else false) - * @return 0 or 1 - */ -static int rve_can_optimize_str(struct rval_expr* rve) -{ - if (scr_opt_lev<1) - return 0; - if (rve->op == RVE_RVAL_OP) - return 0; - LM_DBG("left %d, right %d\n", - rve->left.rve->op, rve->right.rve?rve->right.rve->op:0); - if (rve->left.rve->op != RVE_RVAL_OP) - return 0; - if (rve->left.rve->left.rval.type!=RV_STR) - return 0; - if (rve->right.rve){ - if (rve->right.rve->op != RVE_RVAL_OP) - return 0; - if ((rve->right.rve->left.rval.type!=RV_STR) && - (rve->right.rve->left.rval.type!=RV_LONG)) - return 0; - } - return 1; -} -#endif - - - static int fix_rval(struct rvalue* rv, struct rval_expr* rve) { LM_DBG("RV fixing type %d\n", rv->type); @@ -3072,13 +2897,13 @@ static int rve_replace_with_ct_rv(struct rval_expr* rve, struct rvalue* rv) { enum rval_type type; int flags; - int i; + long i; union rval_val v; type=rv->type; flags=0; if (rv->type==RV_LONG){ - if (rval_get_int(0, 0, &i, rv, 0)!=0){ + if (rval_get_long(0, 0, &i, rv, 0)!=0){ LM_BUG("unexpected int evaluation failure (%d,%d-%d,%d)\n", rve->fpos.s_line, rve->fpos.s_col, rve->fpos.e_line, rve->fpos.e_col); diff --git a/src/core/rvalue.h b/src/core/rvalue.h index bb62ff89fa0..3887b8bdd77 100644 --- a/src/core/rvalue.h +++ b/src/core/rvalue.h @@ -146,7 +146,7 @@ enum rval_cache_type{ /** value cache for a rvalue struct. * Used to optimize functions that would need to - * get the value repeatedly (e.g. rval_get_btype() and then rval_get_int()) + * get the value repeatedly (e.g. rval_get_btype() and then rval_get_long()) */ struct rval_cache{ enum rval_cache_type cache_type; @@ -212,8 +212,8 @@ struct rvalue* rval_convert(struct run_act_ctx* h, struct sip_msg* msg, enum rval_type type, struct rvalue* v, struct rval_cache* c); -/** get the integer value of an rvalue. */ -int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, int* i, +/** get the long int value of an rvalue. */ +long rval_get_long(struct run_act_ctx* h, struct sip_msg* msg, long* i, struct rvalue* rv, struct rval_cache* cache); /** get the string value of an rv. */ int rval_get_str(struct run_act_ctx* h, struct sip_msg* msg, @@ -225,9 +225,9 @@ int rval_get_tmp_str(struct run_act_ctx* h, struct sip_msg* msg, struct rval_cache* cache, struct rval_cache* tmp_cache); -/** evals an integer expr to an int. */ -int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg, - int* res, struct rval_expr* rve); +/** evals a long expr to a long. */ +int rval_expr_eval_long(struct run_act_ctx* h, struct sip_msg* msg, + long* res, struct rval_expr* rve); /** * @brief Evals a rval expression @@ -259,8 +259,8 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg, * when done. * @return 0 on success, -1 on error, sets *res_rv or *res_i. */ -int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg, - struct rvalue** rv_res, int* i_res, +int rval_expr_eval_rvlong( struct run_act_ctx* h, struct sip_msg* msg, + struct rvalue** rv_res, long* i_res, struct rval_expr* rve, struct rval_cache* cache); diff --git a/src/core/switch.c b/src/core/switch.c index 08b08c1d434..836905b10d0 100644 --- a/src/core/switch.c +++ b/src/core/switch.c @@ -148,7 +148,8 @@ void destroy_case_stms(struct case_stms *lst) int fix_switch(struct action* t) { struct case_stms* c; - int n, i, j, ret, val; + int n, i, j, ret; + long val; struct action* a; struct action* block; struct action* def_a; @@ -202,7 +203,7 @@ int fix_switch(struct action* t) LM_ERR("non constant expression in case\n"); return E_BUG; } - if (rval_expr_eval_int(0, 0, &c->label.match_int, c->ct_rve) + if (rval_expr_eval_long(0, 0, &c->label.match_int, c->ct_rve) <0){ LM_ERR("case expression (%d,%d) has non-interger type\n", c->ct_rve->fpos.s_line, @@ -293,7 +294,7 @@ int fix_switch(struct action* t) with the case rve block */ if ( (scr_opt_lev>=2) && !rve_has_side_effects(sw_rve) && rve_is_constant(sw_rve)){ - if (rval_expr_eval_int(0, 0, &val, sw_rve) <0){ + if (rval_expr_eval_long(0, 0, &val, sw_rve) <0){ LM_ERR("wrong type for switch(...) expression (%d,%d)\n", sw_rve->fpos.s_line, sw_rve->fpos.s_col); ret=E_UNSPEC; @@ -315,7 +316,7 @@ int fix_switch(struct action* t) t->val[1].type=0; t->val[1].u.data=0; ret=0; - LM_DBG("constant switch(%d) with %d cases optimized away to case" + LM_DBG("constant switch(%ld) with %d cases optimized away to case" " %d \n", val, n, i); goto end; } diff --git a/src/core/switch.h b/src/core/switch.h index acc1109083d..1f265fa2cae 100644 --- a/src/core/switch.h +++ b/src/core/switch.h @@ -32,7 +32,7 @@ struct case_stms{ int re_flags; /**< used only for REs */ int is_default; union { - int match_int; + long match_int; str match_str; regex_t* match_re; } label; /**< fixed case argument */