Browse code

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)

Andrei Pelinescu-Onciul authored on 16/12/2008 11:06:23
Showing 3 changed files
... ...
@@ -69,7 +69,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
69 69
 			goto error;
70 70
 		case RV_INT:
71 71
 			value.n=rv->v.l;
72
-			flags=avp->type;
72
+			flags=avp->type & ~AVP_VAL_STR;
73 73
 			ret=!(!value.n);
74 74
 			break;
75 75
 		case RV_STR:
... ...
@@ -78,7 +78,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
78 78
 			ret=(value.s.len>0);
79 79
 			break;
80 80
 		case RV_ACTION_ST:
81
-			flags=avp->type;
81
+			flags=avp->type & ~AVP_VAL_STR;
82 82
 			if (rv->v.action)
83 83
 				value.n=run_actions(h, rv->v.action, msg);
84 84
 			else
... ...
@@ -93,7 +93,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
93 93
 				WARN("error in expression\n");
94 94
 				value.n=0; /* expr. is treated as false */
95 95
 			}
96
-			flags=avp->type;
96
+			flags=avp->type & ~AVP_VAL_STR;
97 97
 			ret=value.n;
98 98
 			break;
99 99
 		case RV_SEL:
... ...
@@ -107,7 +107,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
107 107
 					value.s.len=0;
108 108
 				}
109 109
 			}
110
-			flags=avp->type;
110
+			flags=avp->type|AVP_VAL_STR;
111 111
 			ret=(value.s.len>0);
112 112
 			break;
113 113
 		case RV_AVP:
... ...
@@ -116,10 +116,11 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
116 116
 				r_avp = search_first_avp(rv->v.avps.type, rv->v.avps.name,
117 117
 											&value, &st);
118 118
 				while(r_avp){
119
-					/* We take only the type and name from the source avp
120
-					 * and reset the class and track flags */
121
-					flags=(avp->type & ~AVP_INDEX_ALL) | 
122
-							(r_avp->flags & ~(AVP_CLASS_ALL|AVP_TRACK_ALL));
119
+					/* We take only the val type  from the source avp
120
+					 * and reset the class, track flags and name type  */
121
+					flags=(avp->type & ~(AVP_INDEX_ALL|AVP_VAL_STR)) | 
122
+							(r_avp->flags & ~(AVP_CLASS_ALL|AVP_TRACK_ALL|
123
+												AVP_NAME_STR|AVP_NAME_RE));
123 124
 					if (add_avp_before(avp_mark, flags, avp->name, value)<0){
124 125
 						ERR("failed to assign avp\n");
125 126
 						ret=-1;
... ...
@@ -139,8 +140,11 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
139 139
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
140 140
 											&value, rv->v.avps.index);
141 141
 				if (likely(r_avp)){
142
-					flags=avp->type | (r_avp->flags & 
143
-								~(AVP_CLASS_ALL|AVP_TRACK_ALL));
142
+					/* take only the val type from the source avp
143
+					 * and reset the class, track flags and name type  */
144
+					flags=(avp->type & ~AVP_VAL_STR) | (r_avp->flags & 
145
+								~(AVP_CLASS_ALL|AVP_TRACK_ALL|AVP_NAME_STR|
146
+									AVP_NAME_RE));
144 147
 					ret=1;
145 148
 				}else{
146 149
 					ret=-1;
... ...
@@ -149,27 +153,30 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
149 149
 			}
150 150
 			break;
151 151
 		case RV_PVAR:
152
-			flags=avp->type;
153 152
 			memset(&pval, 0, sizeof(pval));
154 153
 			if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
155 154
 				destroy_pval=1;
156
-				if (pval.flags & PV_VAL_STR){
157
-					value.s=pval.rs;
158
-					ret=(value.s.len>0);
159
-				}else if (pval.flags & PV_TYPE_INT){
155
+				if (pval.flags & PV_TYPE_INT){
160 156
 					value.n=pval.ri;
161 157
 					ret=value.n;
158
+					flags=avp->type & ~AVP_VAL_STR;
159
+				}else if (pval.flags & PV_VAL_STR){
160
+					value.s=pval.rs;
161
+					ret=(value.s.len>0);
162
+					flags=avp->type | AVP_VAL_STR;
162 163
 				}else if (pval.flags==PV_VAL_NONE ||
163 164
 							(pval.flags & (PV_VAL_NULL|PV_VAL_EMPTY))){
164 165
 					value.s.s="";
165 166
 					value.s.len=0;
166 167
 					ret=0;
168
+					flags=avp->type | AVP_VAL_STR;
167 169
 				}
168 170
 			}else{
169 171
 				/* non existing pvar */
170 172
 				value.s.s="";
171 173
 				value.s.len=0;
172 174
 				ret=0;
175
+				flags=avp->type | AVP_VAL_STR;
173 176
 			}
174 177
 			break;
175 178
 	}
... ...
@@ -286,13 +293,12 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
286 286
 				}
287 287
 			break;
288 288
 		case RV_PVAR:
289
-			memset(&pval, 0, sizeof(pval));
290 289
 			if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
291 290
 				destroy_pval=1;
292
-				if (pval.flags & PV_VAL_STR){
293
-					ret=(pval.rs.len>0);
294
-				}else if (pval.flags & PV_TYPE_INT){
291
+				if (pval.flags & PV_TYPE_INT){
295 292
 					ret=!(!pval.ri);
293
+				}else if (pval.flags & PV_VAL_STR){
294
+					ret=(pval.rs.len>0);
296 295
 				}else{
297 296
 					ERR("no value in pvar assignment rval\n");
298 297
 					ret=-1;
... ...
@@ -841,8 +841,8 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r,
841 841
 				return (op == DIFF_OP); /* error, not found => false */
842 842
 			}
843 843
 			if (likely(pval.flags & (PV_TYPE_INT|PV_VAL_INT))){
844
-				pv_value_destroy(&pval);
845 844
 				right=pval.ri;
845
+				pv_value_destroy(&pval);
846 846
 			}else{
847 847
 				pv_value_destroy(&pval);
848 848
 				return (op == DIFF_OP); /* not found or invalid type */
... ...
@@ -661,8 +661,8 @@ int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg,
661 661
 				memset(&pval, 0, sizeof(pval));
662 662
 				if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
663 663
 					if (likely(pval.flags & PV_VAL_INT)){
664
-						pv_value_destroy(&pval);
665 664
 						*i=pval.ri;
665
+						pv_value_destroy(&pval);
666 666
 					}else if (likely(pval.flags & PV_VAL_STR)){
667 667
 						pv_value_destroy(&pval);
668 668
 						goto rv_str;