From: Victor Seva <vseva@sipwise.com>
Date: Wed, 21 Dec 2022 12:14:57 +0100
Subject: pua_dialoginfo: use dlg_api.get_dlg_varval()

* rework creating str_list from dlg_var
---
 src/modules/pua_dialoginfo/pua_dialoginfo.c | 36 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/modules/pua_dialoginfo/pua_dialoginfo.c b/src/modules/pua_dialoginfo/pua_dialoginfo.c
index 94efcef..0fe87e3 100644
--- a/src/modules/pua_dialoginfo/pua_dialoginfo.c
+++ b/src/modules/pua_dialoginfo/pua_dialoginfo.c
@@ -574,8 +574,8 @@ struct str_list* get_str_list(unsigned short avp_flags, int_str avp_name) {
 struct dlginfo_cell* get_dialog_data(struct dlg_cell *dlg, int type, int disable_caller_publish, int disable_callee_publish)
 {
 	struct dlginfo_cell *dlginfo;
-	int len;
-	str* s=NULL;
+	int len, len_str_list;
+	str s = STR_NULL;
 
 	// generate new random uuid
 	if(sruid_next_safe(&_puadi_sruid) < 0) {
@@ -651,39 +651,39 @@ struct dlginfo_cell* get_dialog_data(struct dlg_cell *dlg, int type, int disable
 
 		} else {
 			if(caller_dlg_var.len>0
-					&& (s = dlg_api.get_dlg_varref(dlg, &caller_dlg_var))!=0) {
-				dlginfo->pubruris_caller =
-					(struct str_list*)shm_malloc(sizeof(struct str_list) + s->len + 1);
+					&& dlg_api.get_dlg_varval(dlg, &caller_dlg_var, &s) == 0) {
+				len_str_list = sizeof(struct str_list) + s.len + 1;
+				dlginfo->pubruris_caller = (struct str_list*)shm_malloc(len_str_list);
 				if (dlginfo->pubruris_caller==0) {
 					SHM_MEM_ERROR;
 					free_dlginfo_cell(dlginfo);
 					return NULL;
 				}
-				memset(dlginfo->pubruris_caller, 0, sizeof(struct str_list));
+				memset(dlginfo->pubruris_caller, 0, len_str_list);
 				dlginfo->pubruris_caller->s.s = (char*)dlginfo->pubruris_caller
-					+ sizeof(sizeof(struct str_list));
-				memcpy(dlginfo->pubruris_caller->s.s, s->s, s->len);
-				dlginfo->pubruris_caller->s.s[s->len] = '\0';
-				dlginfo->pubruris_caller->s.len = s->len;
+					+ (len_str_list - s.len - 1);
+				memcpy(dlginfo->pubruris_caller->s.s, s.s, s.len);
+				dlginfo->pubruris_caller->s.s[s.len] = '\0';
+				dlginfo->pubruris_caller->s.len = s.len;
 				LM_DBG("Found pubruris_caller in dialog '%.*s'\n",
 						dlginfo->pubruris_caller->s.len, dlginfo->pubruris_caller->s.s);
 			}
 
 			if(callee_dlg_var.len>0
-					&& (s = dlg_api.get_dlg_varref(dlg, &callee_dlg_var))!=0) {
-				dlginfo->pubruris_callee =
-					(struct str_list*)shm_malloc(sizeof(struct str_list) + s->len + 1);
+					&& dlg_api.get_dlg_varval(dlg, &callee_dlg_var, &s) == 0) {
+				len_str_list = sizeof(struct str_list) + s.len + 1;
+				dlginfo->pubruris_callee = (struct str_list*)shm_malloc(len_str_list);
 				if (dlginfo->pubruris_callee==0) {
 					SHM_MEM_ERROR;
 					free_dlginfo_cell(dlginfo);
 					return NULL;
 				}
-				memset(dlginfo->pubruris_callee, 0, sizeof(struct str_list));
+				memset(dlginfo->pubruris_callee, 0, len_str_list);
 				dlginfo->pubruris_callee->s.s = (char*)dlginfo->pubruris_callee
-					+ sizeof(sizeof(struct str_list));
-				memcpy(dlginfo->pubruris_callee->s.s, s->s, s->len);
-				dlginfo->pubruris_callee->s.s[s->len] = '\0';
-				dlginfo->pubruris_callee->s.len = s->len;
+					+ (len_str_list - s.len - 1);
+				memcpy(dlginfo->pubruris_callee->s.s, s.s, s.len);
+				dlginfo->pubruris_callee->s.s[s.len] = '\0';
+				dlginfo->pubruris_callee->s.len = s.len;
 				LM_DBG("Found pubruris_callee in dialog '%.*s'\n",
 						dlginfo->pubruris_callee->s.len, dlginfo->pubruris_callee->s.s);
 			}
