Browse code

core expr eval: various fixes

- fix pvars type evaluated to STRING almost always (when they had
PV_VAL_STR).
- fix undefined not properly propagated for avps (typo) which caused
some comparsion to behave in unexpected way (e.g.
$undef_avp != $undef_avp was true).
- fix <undef>+something (used to produce an error, now is
equivalent to "" + something).

Andrei Pelinescu-Onciul authored on 29/04/2009 11:55:01
Showing 1 changed files
... ...
@@ -314,18 +314,18 @@ inline static enum rval_type rval_get_btype(struct run_act_ctx* h,
314 314
 			}
315 315
 			memset(pv, 0, sizeof(tmp_pval));
316 316
 			if (likely(pv_get_spec_value(msg, &rv->v.pvs, pv)==0)){
317
-				if (pv->flags & PV_VAL_STR){
317
+				if (pv->flags & PV_TYPE_INT){
318 318
 					if (likely(val_cache!=0))
319
-						val_cache->val_type=RV_STR;
319
+						val_cache->val_type=RV_INT;
320 320
 					else
321 321
 						pv_value_destroy(pv);
322
-					return RV_STR;
323
-				}else if (pv->flags & PV_TYPE_INT){
322
+					return RV_INT;
323
+				}else if (pv->flags & PV_VAL_STR){
324 324
 					if (likely(val_cache!=0))
325
-						val_cache->val_type=RV_INT;
325
+						val_cache->val_type=RV_STR;
326 326
 					else
327 327
 						pv_value_destroy(pv);
328
-					return RV_INT;
328
+					return RV_STR;
329 329
 				}else{
330 330
 					pv_value_destroy(pv);
331 331
 					if (likely(val_cache!=0))
... ...
@@ -339,7 +339,7 @@ inline static enum rval_type rval_get_btype(struct run_act_ctx* h,
339 339
 			}
340 340
 			break;
341 341
 		case RV_AVP:
342
-			if (likely(val_cache && val_cache==RV_CACHE_EMPTY)){
342
+			if (likely(val_cache && val_cache->cache_type==RV_CACHE_EMPTY)){
343 343
 				ptype=&val_cache->val_type;
344 344
 				avpv=&val_cache->c.avp_val;
345 345
 				val_cache->cache_type=RV_CACHE_AVP;
... ...
@@ -718,6 +718,11 @@ int rve_check_type(enum rval_type* type, struct rval_expr* rve,
718 718
 			}
719 719
 			break;
720 720
 		case RVE_NONE_OP:
721
+		default:
722
+			BUG("unexpected rve op %d\n", rve->op);
723
+			if (bad_rve) *bad_rve=rve;
724
+			if (bad_t) *bad_t=RV_NONE;
725
+			if (exp_t) *exp_t=RV_STR;
721 726
 			break;
722 727
 	}
723 728
 	return 0;
... ...
@@ -2041,6 +2046,7 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg,
2041 2041
 					}
2042 2042
 					break;
2043 2043
 				case RV_STR:
2044
+				case RV_NONE:
2044 2045
 					rv2=rval_expr_eval(h, msg, rve->right.rve);
2045 2046
 					if (unlikely(rv2==0)){
2046 2047
 						ERR("rval expression evaluation failed\n");
... ...
@@ -2051,9 +2057,6 @@ struct rvalue* rval_expr_eval(struct run_act_ctx* h, struct sip_msg* msg,
2051 2051
 					break;
2052 2052
 				default:
2053 2053
 					BUG("rv unsupported basic type %d\n", type);
2054
-				case RV_NONE:
2055
-					rval_cache_clean(&c1);
2056
-					goto error;
2057 2054
 			}
2058 2055
 			rval_cache_clean(&c1);
2059 2056
 			break;