[SR-Dev] git:master: core: PV printing, revert 103ffecf7, add the proper fix from kamailio

Henning Westerholt henning.westerholt at 1und1.de
Tue May 19 18:25:10 CEST 2009


Module: sip-router
Branch: master
Commit: 8f2817965f28c05947484023c324866288d7abb1
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8f2817965f28c05947484023c324866288d7abb1

Author: Henning Westerholt <henning.westerholt at 1und1.de>
Committer: Henning Westerholt <henning.westerholt at 1und1.de>
Date:   Tue May 19 18:20:59 2009 +0200

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.

---

 sr_module.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/sr_module.c b/sr_module.c
index 1ab8868..8dfcfad 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -1349,6 +1349,9 @@ int fixup_str_2(void** param, int param_no)
 }
 
 
+
+#define PV_PRINT_BUF_SIZE  1024
+#define PV_PRINT_BUF_NO    3
 /** Get the function parameter value as string.
  *  @return  0 - Success
  *          -1 - Cannot get value
@@ -1359,8 +1362,8 @@ int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
 	int ret;
 	avp_t* avp;
 	pv_value_t pv_val;
-	static char pve_buf[256]; /* ugly hack needed for PVE */
-	memset(pve_buf, 0, sizeof(pve_buf));
+	static int buf_itr = 0; /* ugly hack needed for PVE */
+	static char pve_buf[PV_PRINT_BUF_NO][PV_PRINT_BUF_SIZE];
 	
 	switch(param->type) {
 		case FPARAM_REGEX:
@@ -1405,13 +1408,14 @@ int get_str_fparam(str* dst, struct sip_msg* msg, fparam_t* param)
 			}
 			break;
 		case FPARAM_PVE:
-			dst->len=sizeof(pve_buf);
-			if (unlikely(pv_printf(msg, param->v.pve, pve_buf, &dst->len)!=0)){
+			dst->s=pve_buf[buf_itr];
+			dst->len=PV_PRINT_BUF_SIZE;
+			buf_itr = (buf_itr+1)%PV_PRINT_BUF_NO;
+			if (unlikely(pv_printf(msg, param->v.pve, dst->s, &dst->len)!=0)){
 				ERR("Could not convert the PV-formated string to str\n");
 				dst->len=0;
 				return -1;
 			};
-			dst->s=pve_buf;
 			break;
 	}
 	return 0;




More information about the sr-dev mailing list