script engine: rvalue fixes & cleanup
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 10 Dec 2008 13:50:36 +0000 (14:50 +0100)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 10 Dec 2008 13:50:36 +0000 (14:50 +0100)
- fixed rval_str_add2()
- more functions are now "public"
- support for optimization levels

rvalue.c
rvalue.h

index 8dd5c86..742e576 100644 (file)
--- a/rvalue.c
+++ b/rvalue.c
@@ -1099,12 +1099,11 @@ inline static struct rvalue* rval_str_add2(struct run_act_ctx* h,
                s2=&rv2->v.s;
        }
        /* do the actual copy */
-       ret->v.s.len=rv1->v.s.len;
-       memmove(ret->buf+ret->v.s.len, s2->s, s2->len);
+       memmove(ret->buf+rv1->v.s.len, s2->s, s2->len);
        if (s1){
                memcpy(ret->buf, s1->s, s1->len);
        }
-       ret->v.s.len+=s2->len;
+       ret->v.s.len=rv1->v.s.len+s2->len;
        ret->v.s.s[ret->v.s.len]=0;
        /* cleanup if needed */
        if (flags & RV_CNT_ALLOCED_F)
@@ -1155,17 +1154,6 @@ error:
 
 
 
-/* forward decl. */
-inline static int rval_expr_eval_rvint(struct run_act_ctx* h,
-                                                                          struct sip_msg* msg,
-                                                                          struct rvalue** res_rv,
-                                                                          int* res_i,
-                                                                          struct rval_expr* rve,
-                                                                          struct rval_cache* cache
-                                                                          );
-
-
-
 /** evals an integer expr  to an int.
  * 
  *  *res=(int)eval(rve)
@@ -1276,7 +1264,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg,
  * modified only if rv_chg_in_place() returns true.
  * @result  0 on success, -1 on error,  sets *res_rv or *res_i.
  */
-inline static int rval_expr_eval_rvint(struct run_act_ctx* h,
+int rval_expr_eval_rvint(                         struct run_act_ctx* h,
                                                                           struct sip_msg* msg,
                                                                           struct rvalue** res_rv,
                                                                           int* res_i,
@@ -1645,6 +1633,8 @@ struct rval_expr* mk_rval_expr2(enum rval_expr_op op, struct rval_expr* rve1,
  */
 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)
@@ -1671,6 +1661,8 @@ static int rve_can_optimize_int(struct rval_expr* rve)
  */
 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;
        DBG("rve_can_optimize_str: left %d, right %d\n", 
index 22c0cbc..faa6143 100644 (file)
--- a/rvalue.h
+++ b/rvalue.h
@@ -174,6 +174,11 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg,
 /** evals a rval expr.. */
 struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg,
                                                                struct rval_expr* rve);
+/** evals an integer expr  to an int or rvalue. */
+int rval_expr_eval_rvint( struct run_act_ctx* h, struct sip_msg* msg,
+                                                struct rvalue** rv_res, int* i_res,
+                                                struct rval_expr* rve, struct rval_cache* cache);
+
 
 /** guess the type of an expression.  */
 enum rval_type rve_guess_type(struct rval_expr* rve);