Browse code

pua_dialoginfo: new param attribute_display

- if set to 1, the display name attribute is added with user part of the
URI for local and remote targets

Daniel-Constantin Mierla authored on 31/03/2021 07:56:58
Showing 2 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 
29 29
 #include "../../core/parser/parse_expires.h"
30 30
 #include "../../core/parser/msg_parser.h"
31
+#include "../../core/parser/parse_uri.h"
31 32
 #include "../../core/str.h"
32 33
 #include "../../core/str_list.h"
33 34
 #include "../../core/name_alias.h"
... ...
@@ -42,7 +43,7 @@
42 43
 extern int include_callid;
43 44
 extern int include_localremote;
44 45
 extern int include_tags;
45
-
46
+extern int puadinfo_attribute_display;
46 47
 
47 48
 /* for debug purpose only */
48 49
 void print_publ(publ_info_t* p)
... ...
@@ -95,7 +96,9 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
95 96
 	xmlNodePtr remote_node = NULL;
96 97
 	xmlNodePtr local_node = NULL;
97 98
 	xmlNodePtr tag_node = NULL;
98
-	str *body= NULL;
99
+	str *body = NULL;
100
+	str *suri = NULL;
101
+	sip_uri_t puri;
99 102
 
100 103
 	/* create the Publish body */
101 104
 	doc = xmlNewDoc(BAD_CAST "1.0");
... ...
@@ -175,7 +178,7 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
175 178
 	}
176 179
 
177 180
 	if (include_localremote) {
178
-		/* remote tag*/
181
+		/* remote tag */
179 182
 		remote_node = xmlNewChild(dialog_node, NULL, BAD_CAST "remote", NULL) ;
180 183
 		if( remote_node == NULL) {
181 184
 			LM_ERR("while adding child\n");
... ...
@@ -187,18 +190,29 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
187 190
 			LM_ERR("while adding child\n");
188 191
 			goto error;
189 192
 		}
193
+
190 194
 		tag_node = xmlNewChild(remote_node, NULL, BAD_CAST "target", NULL);
191 195
 		if(tag_node == NULL) {
192 196
 			LM_ERR("while adding child\n");
193 197
 			goto error;
194 198
 		}
195 199
 		if (remotetarget && remotetarget->s) {
196
-			puadi_xmlNewPropStr(tag_node, "uri", remotetarget);
200
+			suri = remotetarget;
197 201
 		} else {
198
-			puadi_xmlNewPropStr(tag_node, "uri", peer);
202
+			suri = peer;
199 203
 		}
204
+		if(puadinfo_attribute_display) {
205
+			if(parse_uri(suri->s, suri->len, &puri)<0) {
206
+				LM_ERR("failed to parse uri [%.*s]\n", suri->len, suri->s);
207
+				goto error;
208
+			}
209
+			if(puri.user.s!=NULL && puri.user.len>0) {
210
+				puadi_xmlNewPropStr(tag_node, "display", &puri.user);
211
+			}
212
+		}
213
+		puadi_xmlNewPropStr(tag_node, "uri", suri);
200 214
 
201
-		/* local tag*/
215
+		/* local tag */
202 216
 		local_node = xmlNewChild(dialog_node, NULL, BAD_CAST "local", NULL);
203 217
 		if(local_node == NULL) {
204 218
 			LM_ERR("while adding child\n");
... ...
@@ -210,16 +224,27 @@ str* build_dialoginfo(char *state, str *entity, str *peer, str *callid,
210 224
 			LM_ERR("while adding child\n");
211 225
 			goto error;
212 226
 		}
227
+
213 228
 		tag_node = xmlNewChild(local_node, NULL, BAD_CAST "target", NULL);
214
-		if(tag_node ==NULL) {
229
+		if(tag_node == NULL) {
215 230
 			LM_ERR("while adding child\n");
216 231
 			goto error;
217 232
 		}
218 233
 		if (localtarget && localtarget->s) {
219
-			puadi_xmlNewPropStr(tag_node, "uri", localtarget);
234
+			suri = localtarget;
220 235
 		} else {
221
-			puadi_xmlNewPropStr(tag_node, "uri", entity);
236
+			suri = entity;
237
+		}
238
+		if(puadinfo_attribute_display) {
239
+			if(parse_uri(suri->s, suri->len, &puri)<0) {
240
+				LM_ERR("failed to parse uri [%.*s]\n", suri->len, suri->s);
241
+				goto error;
242
+			}
243
+			if(puri.user.s!=NULL && puri.user.len>0) {
244
+				puadi_xmlNewPropStr(tag_node, "display", &puri.user);
245
+			}
222 246
 		}
247
+		puadi_xmlNewPropStr(tag_node, "uri", suri);
223 248
 	}
224 249
 
225 250
 	/* create the body */
... ...
@@ -100,6 +100,8 @@ char * pubruri_caller_avp  = DEF_PUBRURI_CALLER_AVP;
100 100
 char * pubruri_callee_avp  = DEF_PUBRURI_CALLEE_AVP;
101 101
 int publish_dialog_req_within = DEF_PUBLISH_DIALOG_REQ_WITHIN;
102 102
 
103
+int puadinfo_attribute_display = 0;
104
+
103 105
 send_publish_t pua_send_publish;
104 106
 /** module functions */
105 107
 
... ...
@@ -129,6 +131,7 @@ static param_export_t params[]={
129 131
 	{"caller_entity_when_publish_disabled",  PARAM_STR, &caller_entity_when_publish_disabled },
130 132
 	{"callee_entity_when_publish_disabled",  PARAM_STR, &callee_entity_when_publish_disabled },
131 133
 	{"publish_dialog_req_within",      INT_PARAM, &publish_dialog_req_within },
134
+	{"attribute_display",   PARAM_INT, &puadinfo_attribute_display },
132 135
 	{0, 0, 0 }
133 136
 };
134 137