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 1399
 	avp_t* r_avp;
1398 1400
 	int_str avp_val;
1399 1401
 	pv_value_t pval;
1402
+	str tmp;
1400 1403
 	
1401 1404
 	*res=1;
1402 1405
 	switch(rv->type){
1406
+		case RV_SEL:
1407
+			if (unlikely(cache && cache->cache_type==RV_CACHE_SELECT)){
1408
+				*res=(cache->val_type!=RV_NONE);
1409
+			}else
1410
+				/* run select returns 0 on success, -1 on error and >0 on 
1411
+				   undefined. error is considered undefined */
1412
+				*res=(run_select(&tmp, &rv->v.sel, msg)==0);
1413
+			break;
1403 1414
 		case RV_AVP:
1404 1415
 			if (unlikely(cache && cache->cache_type==RV_CACHE_AVP)){
1405
-				if (cache->val_type==RV_NONE)
1406
-					*res=0;
1416
+				*res=(cache->val_type!=RV_NONE);
1407 1417
 			}else{
1408 1418
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
1409 1419
 											&avp_val, rv->v.avps.index);
... ...
@@ -1415,8 +1425,7 @@ inline static int rv_defined(struct run_act_ctx* h,
1415 1425
 		case RV_PVAR:
1416 1426
 			/* PV_VAL_NULL or pv_get_spec_value error => undef */
1417 1427
 			if (unlikely(cache && cache->cache_type==RV_CACHE_PVAR)){
1418
-				if (cache->val_type==RV_NONE)
1419
-					*res=0;
1428
+				*res=(cache->val_type==RV_NONE);
1420 1429
 			}else{
1421 1430
 				memset(&pval, 0, sizeof(pval));
1422 1431
 				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.