From: Victor Seva <vseva@sipwise.com>
Date: Fri, 28 Feb 2020 11:39:24 +0100
Subject: pua_dialoginfo: local_identity_dlg_var

---
 .../pua_dialoginfo/doc/pua_dialoginfo_admin.xml      | 20 ++++++++++++++++++++
 src/modules/pua_dialoginfo/pua_dialoginfo.c          | 17 +++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/src/modules/pua_dialoginfo/doc/pua_dialoginfo_admin.xml b/src/modules/pua_dialoginfo/doc/pua_dialoginfo_admin.xml
index bd48956..0dee5f9 100644
--- a/src/modules/pua_dialoginfo/doc/pua_dialoginfo_admin.xml
+++ b/src/modules/pua_dialoginfo/doc/pua_dialoginfo_admin.xml
@@ -554,6 +554,26 @@ modparam("pua_dialoginfo", "callee_trying", 1)
 </programlisting>
 		</example>
 		</section>
+
+		<section>
+		<title><varname>local_identity_dlg_var</varname> (str)</title>
+		<para>
+			PUBLISH-requests reporting dialog-information will use the value of
+			the dialog variable if exists
+		</para>
+		<para>
+			<emphasis>Default value is <quote>NULL</quote>.</emphasis>
+		</para>
+		<example>
+			<title>Set <varname>local_identity_dlg_var</varname> parameter</title>
+			<programlisting format="linespecific">
+...
+modparam("pua_dialoginfo", "local_identity_dlg_var", "local_identity")
+...
+</programlisting>
+		</example>
+		</section>
+
 	</section>
 
 	<section>
diff --git a/src/modules/pua_dialoginfo/pua_dialoginfo.c b/src/modules/pua_dialoginfo/pua_dialoginfo.c
index 2e25386..c70ea02 100644
--- a/src/modules/pua_dialoginfo/pua_dialoginfo.c
+++ b/src/modules/pua_dialoginfo/pua_dialoginfo.c
@@ -82,6 +82,7 @@ int_str pubruri_callee_avp_name;
 
 static str caller_dlg_var = {0, 0}; /* pubruri_caller */
 static str callee_dlg_var = {0, 0}; /* pubruri_callee */
+static str local_identity_dlg_var = STR_NULL;
 
 /* Module parameter variables */
 int include_callid         = DEF_INCLUDE_CALLID;
@@ -124,6 +125,7 @@ static param_export_t params[]={
 	{"pubruri_callee_avp",  PARAM_STRING, &pubruri_callee_avp },
 	{"pubruri_caller_dlg_var",  PARAM_STR, &caller_dlg_var },
 	{"pubruri_callee_dlg_var",  PARAM_STR, &callee_dlg_var },
+	{"local_identity_dlg_var",  PARAM_STR, &local_identity_dlg_var },
 	{"callee_trying",       INT_PARAM, &callee_trying },
 	{"disable_caller_publish_flag",   INT_PARAM, &disable_caller_publish_flag },
 	{"disable_callee_publish_flag",   INT_PARAM, &disable_callee_publish_flag },
@@ -300,6 +302,17 @@ void refresh_pubruri_avps(struct dlginfo_cell *dlginfo, str *uri)
 	}
 }
 
+void refresh_local_identity(struct dlg_cell *dlg, str *uri) {
+	str *s = dlg_api.get_dlg_var(dlg, &local_identity_dlg_var);
+
+	if(s != NULL) {
+		uri->s = s->s;
+		uri->len = s->len;
+		LM_DBG("Found local_identity in dialog '%.*s'\n",
+				uri->len, uri->s);
+	}
+}
+
 static void
 __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
 {
@@ -328,6 +341,10 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
 		refresh_pubruri_avps(dlginfo, &uri);
 	}
 
+	if(local_identity_dlg_var.len > 0) {
+		refresh_local_identity(dlg, &uri);
+	}
+
 	switch (type) {
 		case DLGCB_FAILED:
 		case DLGCB_TERMINATED:
