Browse code

core: PV printing, revert 103ffecf7, add the proper fix from kamailio

revert not needed commit 103ffecf7, add the proper fix from kamailio for this
problem. Now its possible to print and use more then one pseudo-variable at a time.
The old implementation used only one static buffer, so in subsequent calls to the
function the previous printed variable was overwritten.

Henning Westerholt authored on 19/05/2009 16:20:59
Showing 1 changed files
... ...
@@ -1349,6 +1349,9 @@ int fixup_str_2(void** param, int param_no)
1349 1349
 }
1350 1350
 
1351 1351
 
1352
+
1353
+#define PV_PRINT_BUF_SIZE  1024
1354
+#define PV_PRINT_BUF_NO    3
1352 1355
 /** Get the function parameter value as string.
1353 1356
  *  @return  0 - Success
1354 1357
  *          -1 - Cannot get value
... ...
@@ -1359,8 +1362,8 @@ int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
1359 1359
 	int ret;
1360 1360
 	avp_t* avp;
1361 1361
 	pv_value_t pv_val;
1362
-	static char pve_buf[256]; /* ugly hack needed for PVE */
1363
-	memset(pve_buf, 0, sizeof(pve_buf));
1362
+	static int buf_itr = 0; /* ugly hack needed for PVE */
1363
+	static char pve_buf[PV_PRINT_BUF_NO][PV_PRINT_BUF_SIZE];
1364 1364
 	
1365 1365
 	switch(param->type) {
1366 1366
 		case FPARAM_REGEX:
... ...
@@ -1405,13 +1408,14 @@ int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
1405 1405
 			}
1406 1406
 			break;
1407 1407
 		case FPARAM_PVE:
1408
-			dst->len=sizeof(pve_buf);
1409
-			if (unlikely(pv_printf(msg, param->v.pve, pve_buf, &dst->len)!=0)){
1408
+			dst->s=pve_buf[buf_itr];
1409
+			dst->len=PV_PRINT_BUF_SIZE;
1410
+			buf_itr = (buf_itr+1)%PV_PRINT_BUF_NO;
1411
+			if (unlikely(pv_printf(msg, param->v.pve, dst->s, &dst->len)!=0)){
1410 1412
 				ERR("Could not convert the PV-formated string to str\n");
1411 1413
 				dst->len=0;
1412 1414
 				return -1;
1413 1415
 			};
1414
-			dst->s=pve_buf;
1415 1416
 			break;
1416 1417
 	}
1417 1418
 	return 0;