Browse code

pua_dialoginfo: refresh_pubruri_avps_flag

Victor Seva authored on 20/02/2020 17:50:14 • Victor Seva committed on 16/06/2022 10:17:32
Showing 2 changed files
... ...
@@ -433,7 +433,25 @@ modparam("pua_dialoginfo", "use_pubruri_avps", 1)
433 433
 </programlisting>
434 434
 		</example>
435 435
 		</section>
436
-		
436
+
437
+	<section id="pua_dialoginfo.p.refresh_pubruri_avps_flag">
438
+		<title><varname>refresh_pubruri_avps_flag</varname> (int)</title>
439
+		<para>
440
+			If use_pubruri_avps is enabled, this message flag indicates whether to refresh R-Uri from avps before sending the PUBLISH requests.
441
+		</para>
442
+		<para>
443
+			<emphasis>Default value is <quote>-1</quote>.</emphasis>
444
+		</para>
445
+		<example>
446
+			<title>Set <varname>refresh_pubruri_avps_flag</varname> parameter</title>
447
+			<programlisting format="linespecific">
448
+...
449
+modparam("pua_dialoginfo", "refresh_pubruri_avps_flag", 11)
450
+...
451
+</programlisting>
452
+		</example>
453
+		</section>
454
+
437 455
 		<section>
438 456
 		<title><varname>pubruri_caller_avp</varname> (str)</title>
439 457
 		<para>
... ...
@@ -41,6 +41,7 @@
41 41
 #include "../../core/str_list.h"
42 42
 #include "../../core/mem/mem.h"
43 43
 #include "../../core/pt.h"
44
+#include "../../core/ut.h"
44 45
 #include "../../core/utils/sruid.h"
45 46
 #include "../dialog/dlg_load.h"
46 47
 #include "../dialog/dlg_hash.h"
... ...
@@ -59,6 +60,7 @@ MODULE_VERSION
59 60
 #define DEF_OVERRIDE_LIFETIME 0
60 61
 #define DEF_SEND_PUBLISH_FLAG -1
61 62
 #define DEF_USE_PUBRURI_AVPS 0
63
+#define DEF_REFRESH_PUBRURI_AVPS_FLAG -1
62 64
 #define DEF_PUBRURI_CALLER_AVP 0
63 65
 #define DEF_PUBRURI_CALLEE_AVP 0
64 66
 #define DEF_CALLEE_TRYING 0
... ...
@@ -95,6 +97,7 @@ int caller_confirmed       = DEF_CALLER_ALWAYS_CONFIRMED;
95 97
 int include_req_uri        = DEF_INCLUDE_REQ_URI;
96 98
 int send_publish_flag      = DEF_SEND_PUBLISH_FLAG;
97 99
 int use_pubruri_avps       = DEF_USE_PUBRURI_AVPS;
100
+int refresh_pubruri_avps_flag = DEF_REFRESH_PUBRURI_AVPS_FLAG;
98 101
 int callee_trying          = DEF_CALLEE_TRYING;
99 102
 int disable_caller_publish_flag = DEF_DISABLE_CALLER_PUBLISH_FLAG;
100 103
 int disable_callee_publish_flag = DEF_DISABLE_CALLEE_PUBLISH_FLAG;
... ...
@@ -124,6 +127,7 @@ static param_export_t params[]={
124 127
 	{"include_req_uri",     INT_PARAM, &include_req_uri },
125 128
 	{"send_publish_flag",   INT_PARAM, &send_publish_flag },
126 129
 	{"use_pubruri_avps",    INT_PARAM, &use_pubruri_avps },
130
+	{"refresh_pubruri_avps_flag",   INT_PARAM, &refresh_pubruri_avps_flag },
127 131
 	{"pubruri_caller_avp",  PARAM_STRING, &pubruri_caller_avp },
128 132
 	{"pubruri_callee_avp",  PARAM_STRING, &pubruri_callee_avp },
129 133
 	{"pubruri_caller_dlg_var",  PARAM_STR, &caller_dlg_var },
... ...
@@ -256,6 +260,58 @@ __dialog_cbtest(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
256 260
 }
257 261
 #endif
258 262
 
263
+static struct str_list* get_str_list(unsigned short avp_flags, int_str avp_name);
264
+static int is_ruri_in_list(struct str_list *list, str *ruri);
265
+
266
+void refresh_pubruri_avps(struct dlginfo_cell *dlginfo, str *uri)
267
+{
268
+	struct str_list *pubruris = get_str_list(pubruri_caller_avp_type,
269
+			pubruri_caller_avp_name);
270
+	struct str_list *list, *next;
271
+	str target = STR_NULL;
272
+
273
+	if(pubruris) {
274
+		list = dlginfo->pubruris_caller;
275
+		while(list) {
276
+			if(is_ruri_in_list(pubruris, &list->s) == 0) {
277
+				LM_DBG("ruri:'%.*s' removed from pubruris_caller list\n",
278
+					list->s.len, list->s.s);
279
+				next = list->next; list->next = NULL;
280
+				dialog_publish_multi("terminated", list,
281
+						&(dlginfo->from_uri), uri, &(dlginfo->callid), 1,
282
+						10, 0, 0, &(dlginfo->from_contact),
283
+						&target, send_publish_flag==-1?1:0, &(dlginfo->uuid));
284
+				list->next = next;
285
+			}
286
+			list = list->next;
287
+		}
288
+		free_str_list_all(dlginfo->pubruris_caller);
289
+		dlginfo->pubruris_caller = pubruris;
290
+		LM_DBG("refreshed pubruris_caller info from avp\n");
291
+	}
292
+	pubruris = get_str_list(pubruri_callee_avp_type,
293
+			pubruri_callee_avp_name);
294
+	if(pubruris) {
295
+		list = dlginfo->pubruris_callee;
296
+		while(list) {
297
+			if(is_ruri_in_list(pubruris, &list->s) == 0) {
298
+				LM_DBG("ruri:'%.*s' removed from pubruris_callee list\n",
299
+					list->s.len, list->s.s);
300
+				next = list->next; list->next = NULL;
301
+				dialog_publish_multi("terminated", list,
302
+						uri, &(dlginfo->from_uri), &(dlginfo->callid), 0,
303
+						10, 0, 0, &target, &(dlginfo->from_contact),
304
+						send_publish_flag==-1?1:0, &(dlginfo->uuid));
305
+				list->next = next;
306
+			}
307
+			list = list->next;
308
+		}
309
+		free_str_list_all(dlginfo->pubruris_callee);
310
+		dlginfo->pubruris_callee = pubruris;
311
+		LM_DBG("refreshed pubruris_callee info from avp\n");
312
+	}
313
+}
314
+
259 315
 static void
260 316
 __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
261 317
 {
... ...
@@ -294,6 +350,12 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
294 350
 		uri=callee_entity_when_publish_disabled;
295 351
 	}
296 352
 
353
+	if(use_pubruri_avps && (refresh_pubruri_avps_flag > -1
354
+		|| (request->flags & (1<<refresh_pubruri_avps_flag))))
355
+	{
356
+		refresh_pubruri_avps(dlginfo, &uri);
357
+	}
358
+
297 359
 	switch (type) {
298 360
 		case DLGCB_FAILED:
299 361
 		case DLGCB_TERMINATED:
... ...
@@ -884,6 +946,19 @@ void free_dlginfo_cell(void *param) {
884 946
 }
885 947
 
886 948
 
949
+int is_ruri_in_list(struct str_list *list, str *ruri) {
950
+	struct str_list *pubruris = list;
951
+	LM_DBG("search:'%.*s'\n", ruri->len, ruri->s);
952
+	while(pubruris) {
953
+		LM_DBG("compare with:'%.*s'\n", pubruris->s.len, pubruris->s.s);
954
+		if(str_strcmp(&pubruris->s, ruri) == 0) {
955
+			return 1;
956
+		}
957
+		pubruris = pubruris->next;
958
+	}
959
+	return 0;
960
+}
961
+
887 962
 void free_str_list_all(struct str_list * del_current) {
888 963
 
889 964
 	struct str_list* del_next;