[SR-Dev] git:andrei/script_vars: script engine: pvar & avp fixes

Andrei Pelinescu-Onciul andrei at iptel.org
Tue Dec 16 12:07:47 CET 2008


Module: sip-router
Branch: andrei/script_vars
Commit: a4ade2b9635011c0b66e1c2e96f77271b59551d8
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a4ade2b9635011c0b66e1c2e96f77271b59551d8

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Tue Dec 16 12:06:23 2008 +0100

script engine: pvar & avp fixes

- fix avp type flags in assignments (not always set/reset)
- always look first for the integer value of a pvar (since and int
  pvar can also have a str value)
- don't destroy the pvar values before using them (typo)

---

 lvalue.c |   44 +++++++++++++++++++++++++-------------------
 route.c  |    2 +-
 rvalue.c |    2 +-
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/lvalue.c b/lvalue.c
index e5f1afd..77a9a86 100644
--- a/lvalue.c
+++ b/lvalue.c
@@ -69,7 +69,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 			goto error;
 		case RV_INT:
 			value.n=rv->v.l;
-			flags=avp->type;
+			flags=avp->type & ~AVP_VAL_STR;
 			ret=!(!value.n);
 			break;
 		case RV_STR:
@@ -78,7 +78,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 			ret=(value.s.len>0);
 			break;
 		case RV_ACTION_ST:
-			flags=avp->type;
+			flags=avp->type & ~AVP_VAL_STR;
 			if (rv->v.action)
 				value.n=run_actions(h, rv->v.action, msg);
 			else
@@ -93,7 +93,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 				WARN("error in expression\n");
 				value.n=0; /* expr. is treated as false */
 			}
-			flags=avp->type;
+			flags=avp->type & ~AVP_VAL_STR;
 			ret=value.n;
 			break;
 		case RV_SEL:
@@ -107,7 +107,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 					value.s.len=0;
 				}
 			}
-			flags=avp->type;
+			flags=avp->type|AVP_VAL_STR;
 			ret=(value.s.len>0);
 			break;
 		case RV_AVP:
@@ -116,10 +116,11 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 				r_avp = search_first_avp(rv->v.avps.type, rv->v.avps.name,
 											&value, &st);
 				while(r_avp){
-					/* We take only the type and name from the source avp
-					 * and reset the class and track flags */
-					flags=(avp->type & ~AVP_INDEX_ALL) | 
-							(r_avp->flags & ~(AVP_CLASS_ALL|AVP_TRACK_ALL));
+					/* We take only the val type  from the source avp
+					 * and reset the class, track flags and name type  */
+					flags=(avp->type & ~(AVP_INDEX_ALL|AVP_VAL_STR)) | 
+							(r_avp->flags & ~(AVP_CLASS_ALL|AVP_TRACK_ALL|
+												AVP_NAME_STR|AVP_NAME_RE));
 					if (add_avp_before(avp_mark, flags, avp->name, value)<0){
 						ERR("failed to assign avp\n");
 						ret=-1;
@@ -139,8 +140,11 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
 											&value, rv->v.avps.index);
 				if (likely(r_avp)){
-					flags=avp->type | (r_avp->flags & 
-								~(AVP_CLASS_ALL|AVP_TRACK_ALL));
+					/* take only the val type from the source avp
+					 * and reset the class, track flags and name type  */
+					flags=(avp->type & ~AVP_VAL_STR) | (r_avp->flags & 
+								~(AVP_CLASS_ALL|AVP_TRACK_ALL|AVP_NAME_STR|
+									AVP_NAME_RE));
 					ret=1;
 				}else{
 					ret=-1;
@@ -149,27 +153,30 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 			}
 			break;
 		case RV_PVAR:
-			flags=avp->type;
 			memset(&pval, 0, sizeof(pval));
 			if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
 				destroy_pval=1;
-				if (pval.flags & PV_VAL_STR){
-					value.s=pval.rs;
-					ret=(value.s.len>0);
-				}else if (pval.flags & PV_TYPE_INT){
+				if (pval.flags & PV_TYPE_INT){
 					value.n=pval.ri;
 					ret=value.n;
+					flags=avp->type & ~AVP_VAL_STR;
+				}else if (pval.flags & PV_VAL_STR){
+					value.s=pval.rs;
+					ret=(value.s.len>0);
+					flags=avp->type | AVP_VAL_STR;
 				}else if (pval.flags==PV_VAL_NONE ||
 							(pval.flags & (PV_VAL_NULL|PV_VAL_EMPTY))){
 					value.s.s="";
 					value.s.len=0;
 					ret=0;
+					flags=avp->type | AVP_VAL_STR;
 				}
 			}else{
 				/* non existing pvar */
 				value.s.s="";
 				value.s.len=0;
 				ret=0;
+				flags=avp->type | AVP_VAL_STR;
 			}
 			break;
 	}
@@ -286,13 +293,12 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
 				}
 			break;
 		case RV_PVAR:
-			memset(&pval, 0, sizeof(pval));
 			if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
 				destroy_pval=1;
-				if (pval.flags & PV_VAL_STR){
-					ret=(pval.rs.len>0);
-				}else if (pval.flags & PV_TYPE_INT){
+				if (pval.flags & PV_TYPE_INT){
 					ret=!(!pval.ri);
+				}else if (pval.flags & PV_VAL_STR){
+					ret=(pval.rs.len>0);
 				}else{
 					ERR("no value in pvar assignment rval\n");
 					ret=-1;
diff --git a/route.c b/route.c
index 4164284..ad85c00 100644
--- a/route.c
+++ b/route.c
@@ -841,8 +841,8 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r,
 				return (op == DIFF_OP); /* error, not found => false */
 			}
 			if (likely(pval.flags & (PV_TYPE_INT|PV_VAL_INT))){
-				pv_value_destroy(&pval);
 				right=pval.ri;
+				pv_value_destroy(&pval);
 			}else{
 				pv_value_destroy(&pval);
 				return (op == DIFF_OP); /* not found or invalid type */
diff --git a/rvalue.c b/rvalue.c
index 6f9b118..063be00 100644
--- a/rvalue.c
+++ b/rvalue.c
@@ -661,8 +661,8 @@ int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg,
 				memset(&pval, 0, sizeof(pval));
 				if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
 					if (likely(pval.flags & PV_VAL_INT)){
-						pv_value_destroy(&pval);
 						*i=pval.ri;
+						pv_value_destroy(&pval);
 					}else if (likely(pval.flags & PV_VAL_STR)){
 						pv_value_destroy(&pval);
 						goto rv_str;




More information about the sr-dev mailing list