Browse code

fixups: support for PVE & PVS in get_*_fparam()

- get_str_fparam() and get_int_fparam() support now FPARAM_PVE & FPARAM_PVS

Andrei Pelinescu-Onciul authored on 27/11/2008 01:34:09
Showing 1 changed files
... ...
@@ -1348,16 +1348,17 @@ int fixup_str_2(void** param, int param_no)
1348 1348
 }
1349 1349
 
1350 1350
 
1351
-/*
1352
- * Get the function parameter value as string
1353
- * Return values:  0 - Success
1354
- *                -1 - Cannot get value
1351
+/** Get the function parameter value as string.
1352
+ *  @return  0 - Success
1353
+ *          -1 - Cannot get value
1355 1354
  */
1356 1355
 int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
1357 1356
 {
1358 1357
 	int_str val;
1359 1358
 	int ret;
1360 1359
 	avp_t* avp;
1360
+	pv_value_t pv_val;
1361
+	static char pve_buf[256]; /* ugly hack needed for PVE */
1361 1362
 	
1362 1363
 	switch(param->type) {
1363 1364
 		case FPARAM_REGEX:
... ...
@@ -1374,12 +1375,12 @@ int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
1374 1374
 		case FPARAM_AVP:
1375 1375
 			avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
1376 1376
 									&val, 0);
1377
-			if (!avp) {
1377
+			if (unlikely(!avp)) {
1378 1378
 				DBG("Could not find AVP from function parameter '%s'\n",
1379 1379
 						param->orig);
1380 1380
 				return -1;
1381 1381
 			}
1382
-			if (avp->flags & AVP_VAL_STR) {
1382
+			if (likely(avp->flags & AVP_VAL_STR)) {
1383 1383
 				*dst = val.s;
1384 1384
 			} else {
1385 1385
 		 		/* The caller does not know of what type the AVP will be so
... ...
@@ -1390,17 +1391,34 @@ int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
1390 1390
 			break;
1391 1391
 		case FPARAM_SELECT:
1392 1392
 			ret = run_select(dst, param->v.select, msg);
1393
-			if (ret < 0 || ret > 0) return -1;
1393
+			if (unlikely(ret < 0 || ret > 0)) return -1;
1394
+			break;
1395
+		case FPARAM_PVS:
1396
+			if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) &&
1397
+					   ((pv_val.flags&(PV_VAL_NULL|PV_VAL_STR))==PV_VAL_STR))){
1398
+					*dst=pv_val.rs;
1399
+			}else{
1400
+				ERR("Could not convert PV to str\n");
1401
+				return -1;
1402
+			}
1403
+			break;
1404
+		case FPARAM_PVE:
1405
+			dst->len=sizeof(pve_buf);
1406
+			if (unlikely(pv_printf(msg, param->v.pve, pve_buf, &dst->len)!=0)){
1407
+				ERR("Could not convert the PV-formated string to str\n");
1408
+				dst->len=0;
1409
+				return -1;
1410
+			};
1411
+			dst->s=pve_buf;
1394 1412
 			break;
1395 1413
 	}
1396 1414
 	return 0;
1397 1415
 }
1398 1416
 
1399 1417
 
1400
-/*
1401
- * Get the function parameter value as integer
1402
- * Return values:  0 - Success
1403
- *                -1 - Cannot get value
1418
+/** Get the function parameter value as integer.
1419
+ *  @return  0 - Success
1420
+ *          -1 - Cannot get value
1404 1421
  */
1405 1422
 int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
1406 1423
 {
... ...
@@ -1408,6 +1426,7 @@ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
1408 1408
 	int ret;
1409 1409
 	avp_t* avp;
1410 1410
 	str tmp;
1411
+	pv_value_t pv_val;
1411 1412
 
1412 1413
 	switch(param->type) {
1413 1414
 		case FPARAM_INT:
... ...
@@ -1421,7 +1440,7 @@ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
1421 1421
 		case FPARAM_AVP:
1422 1422
 			avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
1423 1423
 									&val, 0);
1424
-			if (!avp) {
1424
+			if (unlikely(!avp)) {
1425 1425
 				DBG("Could not find AVP from function parameter '%s'\n",
1426 1426
 						param->orig);
1427 1427
 				return -1;
... ...
@@ -1437,12 +1456,23 @@ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
1437 1437
 			break;
1438 1438
 		case FPARAM_SELECT:
1439 1439
 			ret = run_select(&tmp, param->v.select, msg);
1440
-			if (ret < 0 || ret > 0) return -1;
1441
-			if (str2int(&tmp, (unsigned int*)dst) < 0) {
1440
+			if (unlikely(ret < 0 || ret > 0)) return -1;
1441
+			if (unlikely(str2int(&tmp, (unsigned int*)dst) < 0)) {
1442 1442
 				ERR("Could not convert select result to int\n");
1443 1443
 				return -1;
1444 1444
 			}
1445 1445
 			break;
1446
+		case FPARAM_PVS:
1447
+			if (likely((pv_get_spec_value(msg, param->v.pvs, &pv_val)==0) &&
1448
+					   ((pv_val.flags&(PV_VAL_NULL|PV_VAL_INT))==PV_VAL_INT))){
1449
+					*dst=pv_val.ri;
1450
+			}else{
1451
+				ERR("Could not convert PV to int\n");
1452
+				return -1;
1453
+			}
1454
+			break;
1455
+		case FPARAM_PVE:
1456
+			return -1;
1446 1457
 	}
1447 1458
 	return 0;
1448 1459
 }