Browse code

core expr eval: defined @select

- a select can now be undefined (defined @select when run_select
returns >0 or error => true)
- RV_CACHE_SELECT introduced

Andrei Pelinescu-Onciul authored on 28/04/2009 07:50:07
Showing 2 changed files
... ...
@@ -1386,9 +1386,11 @@ error:
1386 1386
 /** checks if rv is defined.
1387 1387
  * @param res - set to the result 1 - defined, 0 not defined
1388 1388
  * @return 0 on success, -1 on error
1389
- * Can use cached rvalues (c1).
1390
- * Note: a rv can be undefined if it's an undefined avp or pvar or
1389
+ * Can use cached rvalues (cache).
1390
+ * Note: a rv can be undefined if it's an undefined avp or pvar or select or
1391 1391
  * if it's NONE
1392
+ * Note2: an error in the avp, pvar or select search is equivalent to 
1393
+ *  undefined (and it's not reported)
1392 1394
  */
1393 1395
 inline static int rv_defined(struct run_act_ctx* h,
1394 1396
 						 struct sip_msg* msg, int* res,
... ...
@@ -1397,13 +1399,21 @@ inline static int rv_defined(struct run_act_ctx* h,
1397 1397
 	avp_t* r_avp;
1398 1398
 	int_str avp_val;
1399 1399
 	pv_value_t pval;
1400
+	str tmp;
1400 1401
 	
1401 1402
 	*res=1;
1402 1403
 	switch(rv->type){
1404
+		case RV_SEL:
1405
+			if (unlikely(cache && cache->cache_type==RV_CACHE_SELECT)){
1406
+				*res=(cache->val_type!=RV_NONE);
1407
+			}else
1408
+				/* run select returns 0 on success, -1 on error and >0 on 
1409
+				   undefined. error is considered undefined */
1410
+				*res=(run_select(&tmp, &rv->v.sel, msg)==0);
1411
+			break;
1403 1412
 		case RV_AVP:
1404 1413
 			if (unlikely(cache && cache->cache_type==RV_CACHE_AVP)){
1405
-				if (cache->val_type==RV_NONE)
1406
-					*res=0;
1414
+				*res=(cache->val_type!=RV_NONE);
1407 1415
 			}else{
1408 1416
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
1409 1417
 											&avp_val, rv->v.avps.index);
... ...
@@ -1415,8 +1425,7 @@ inline static int rv_defined(struct run_act_ctx* h,
1415 1415
 		case RV_PVAR:
1416 1416
 			/* PV_VAL_NULL or pv_get_spec_value error => undef */
1417 1417
 			if (unlikely(cache && cache->cache_type==RV_CACHE_PVAR)){
1418
-				if (cache->val_type==RV_NONE)
1419
-					*res=0;
1418
+				*res=(cache->val_type==RV_NONE);
1420 1419
 			}else{
1421 1420
 				memset(&pval, 0, sizeof(pval));
1422 1421
 				if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
... ...
@@ -118,7 +118,8 @@ struct rval_expr{
118 118
 enum rval_cache_type{
119 119
 	RV_CACHE_EMPTY,
120 120
 	RV_CACHE_PVAR,
121
-	RV_CACHE_AVP
121
+	RV_CACHE_AVP,
122
+	RV_CACHE_SELECT
122 123
 };
123 124
 
124 125
 /** value cache for a rvalue struct.