Browse code

core expr: fixes fo RVE_STRLEN/STREMPTY/DEFINED

- wrong return fixed
- missing fixups added

Andrei Pelinescu-Onciul authored on 24/04/2009 17:39:51
Showing 1 changed files
... ...
@@ -1094,6 +1094,7 @@ inline static int int_strop1(int* res, enum rval_expr_op op, str* s1)
1094 1094
 			break;
1095 1095
 		default:
1096 1096
 			BUG("rv unsupported int_strop1 %d\n", op);
1097
+			*res=0;
1097 1098
 			return -1;
1098 1099
 	}
1099 1100
 	return 0;
... ...
@@ -1355,6 +1356,7 @@ error:
1355 1355
 
1356 1356
 /** integer operation on rval evaluated as string.
1357 1357
  * Can use cached rvalues (c1 & c2).
1358
+ * @param res - will be set to the result
1358 1359
  * @return 0 success, -1 on error
1359 1360
  */
1360 1361
 inline static int rval_int_strop1(struct run_act_ctx* h,
... ...
@@ -1375,38 +1377,39 @@ inline static int rval_int_strop1(struct run_act_ctx* h,
1375 1375
 	rval_destroy(rv1); 
1376 1376
 	return ret;
1377 1377
 error:
1378
+	*res=0;
1378 1379
 	rval_destroy(rv1); 
1379
-	return 0;
1380
+	return -1;
1380 1381
 }
1381 1382
 
1382 1383
 
1383 1384
 
1384 1385
 /** checks if rv is defined.
1385
- * @return 1 defined, 0 not defined, -1 on error
1386
+ * @param res - set to the result 1 - defined, 0 not defined
1387
+ * @return 0 on success, -1 on error
1386 1388
  * Can use cached rvalues (c1).
1387 1389
  * Note: a rv can be undefined if it's an undefined avp or pvar or
1388 1390
  * if it's NONE
1389 1391
  */
1390 1392
 inline static int rv_defined(struct run_act_ctx* h,
1391
-						 struct sip_msg* msg,
1393
+						 struct sip_msg* msg, int* res,
1392 1394
 						 struct rvalue* rv, struct rval_cache* cache)
1393 1395
 {
1394 1396
 	avp_t* r_avp;
1395 1397
 	int_str avp_val;
1396 1398
 	pv_value_t pval;
1397
-	int ret;
1398 1399
 	
1399
-	ret=1;
1400
+	*res=1;
1400 1401
 	switch(rv->type){
1401 1402
 		case RV_AVP:
1402 1403
 			if (unlikely(cache && cache->cache_type==RV_CACHE_AVP)){
1403 1404
 				if (cache->val_type==RV_NONE)
1404
-					ret=0;
1405
+					*res=0;
1405 1406
 			}else{
1406 1407
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
1407 1408
 											&avp_val, rv->v.avps.index);
1408 1409
 				if (unlikely(r_avp==0)){
1409
-					ret=0;
1410
+					*res=0;
1410 1411
 				}
1411 1412
 			}
1412 1413
 			break;
... ...
@@ -1414,42 +1417,44 @@ inline static int rv_defined(struct run_act_ctx* h,
1414 1414
 			/* PV_VAL_NULL or pv_get_spec_value error => undef */
1415 1415
 			if (unlikely(cache && cache->cache_type==RV_CACHE_PVAR)){
1416 1416
 				if (cache->val_type==RV_NONE)
1417
-					ret=0;
1417
+					*res=0;
1418 1418
 			}else{
1419 1419
 				memset(&pval, 0, sizeof(pval));
1420 1420
 				if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
1421 1421
 					if ((pval.flags & PV_VAL_NULL) &&
1422 1422
 							! (pval.flags & (PV_VAL_INT|PV_VAL_STR))){
1423
-						ret=0;
1423
+						*res=0;
1424 1424
 					}
1425 1425
 					pv_value_destroy(&pval);
1426 1426
 				}else{
1427
-					ret=0; /* in case of error, consider it undef */
1427
+					*res=0; /* in case of error, consider it undef */
1428 1428
 				}
1429 1429
 			}
1430 1430
 			break;
1431 1431
 		case RV_NONE:
1432
-			ret=0;
1432
+			*res=0;
1433 1433
 			break;
1434 1434
 		default:
1435 1435
 			break;
1436 1436
 	}
1437
-	return 1; /* defined */
1437
+	return 0;
1438 1438
 }
1439 1439
 
1440 1440
 
1441 1441
 /** defined (integer) operation on rve.
1442
- * @return 1 defined, 0 not defined, -1 on error
1442
+ * @param res - set to  1 defined, 0 not defined
1443
+ * @return - 0 on success, -1 on error
1443 1444
  */
1444 1445
 inline static int int_rve_defined(struct run_act_ctx* h,
1445
-						 struct sip_msg* msg,
1446
+						 struct sip_msg* msg, int* res,
1446 1447
 						 struct rval_expr* rve)
1447 1448
 {
1448 1449
 	/* only a rval can be undefined, any expression consisting on more
1449 1450
 	   then one rval => defined */
1450 1451
 	if (likely(rve->op==RVE_RVAL_OP))
1451
-		return rv_defined(h, msg, &rve->left.rval, 0);
1452
-	return 1;
1452
+		return rv_defined(h, msg, res, &rve->left.rval, 0);
1453
+	*res=1;
1454
+	return 0;
1453 1455
 }
1454 1456
 
1455 1457
 
... ...
@@ -1580,7 +1585,7 @@ int rval_expr_eval_int( struct run_act_ctx* h, struct sip_msg* msg,
1580 1580
 			ret=-1;
1581 1581
 			break;
1582 1582
 		case RVE_DEFINED_OP:
1583
-			ret=int_rve_defined(h, msg, rve->left.rve);
1583
+			ret=int_rve_defined(h, msg, res, rve->left.rve);
1584 1584
 			break;
1585 1585
 		case RVE_STRLEN_OP:
1586 1586
 		case RVE_STREMPTY_OP:
... ...
@@ -2799,6 +2804,9 @@ int fix_rval_expr(void** p)
2799 2799
 		case RVE_UMINUS_OP: /* unary operators */
2800 2800
 		case RVE_BOOL_OP:
2801 2801
 		case RVE_LNOT_OP:
2802
+		case RVE_STRLEN_OP:
2803
+		case RVE_STREMPTY_OP:
2804
+		case RVE_DEFINED_OP:
2802 2805
 			ret=fix_rval_expr((void**)&rve->left.rve);
2803 2806
 			if (ret<0) return ret;
2804 2807
 			break;