Browse code

pua_dialoginfo: use lock when use_puburi_avps is set

Victor Seva authored on 30/06/2020 07:27:58 • Victor Seva committed on 16/06/2022 10:17:32
Showing 2 changed files
... ...
@@ -353,6 +353,7 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
353 353
 	if(use_pubruri_avps && (refresh_pubruri_avps_flag > -1
354 354
 		|| (request->flags & (1<<refresh_pubruri_avps_flag))))
355 355
 	{
356
+		lock_get(&dlginfo->lock);
356 357
 		refresh_pubruri_avps(dlginfo, &uri);
357 358
 	}
358 359
 
... ...
@@ -496,6 +497,12 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
496 497
 						send_publish_flag==-1?1:0,&(dlginfo->uuid));
497 498
 			}
498 499
 	}
500
+
501
+	if(use_pubruri_avps && (refresh_pubruri_avps_flag > -1
502
+		|| (request->flags & (1<<refresh_pubruri_avps_flag))))
503
+	{
504
+		lock_release(&dlginfo->lock);
505
+	}
499 506
 }
500 507
 
501 508
 /*
... ...
@@ -577,6 +584,12 @@ struct dlginfo_cell* get_dialog_data(struct dlg_cell *dlg, int type, int disable
577 584
 	}
578 585
 	memset( dlginfo, 0, len);
579 586
 
587
+	if(use_pubruri_avps && lock_init(&dlginfo->lock) == 0) {
588
+		LM_ERR("cannot init the lock\n");
589
+		free_dlginfo_cell(dlginfo);
590
+		return NULL;
591
+	}
592
+
580 593
 	/* copy from dlg structure to dlginfo structure */
581 594
 	dlginfo->lifetime     = override_lifetime ? override_lifetime : dlg->lifetime;
582 595
 	dlginfo->disable_caller_publish     = disable_caller_publish;
... ...
@@ -756,20 +769,24 @@ __dialog_created(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
756 769
 
757 770
 	if ((!disable_caller_publish) && (disable_caller_publish_flag == -1 || !(request
758 771
 		&& (request->flags & (1<<disable_caller_publish_flag))))) {
772
+		if(use_pubruri_avps) lock_get(&dlginfo->lock);
759 773
 		dialog_publish_multi("Trying", dlginfo->pubruris_caller,
760 774
 				&identity_local,
761 775
 				&identity_remote,
762 776
 				&(dlg->callid), 1, dlginfo->lifetime,
763 777
 				0, 0, 0, 0, (send_publish_flag==-1)?1:0,&(dlginfo->uuid));
778
+		if(use_pubruri_avps) lock_release(&dlginfo->lock);
764 779
 	}
765 780
 
766 781
 	if (callee_trying && ((!disable_callee_publish) && (disable_callee_publish_flag == -1 || !(request
767 782
 			&& (request->flags & (1<<disable_callee_publish_flag)))))) {
783
+		if(use_pubruri_avps) lock_get(&dlginfo->lock);
768 784
 		dialog_publish_multi("Trying", dlginfo->pubruris_callee,
769 785
 				&identity_remote,
770 786
 				&identity_local,
771 787
 				&(dlg->callid), 0, dlginfo->lifetime,
772 788
 				0, 0, 0, 0, (send_publish_flag==-1)?1:0,&(dlginfo->uuid));
789
+		if(use_pubruri_avps) lock_release(&dlginfo->lock);
773 790
 	}
774 791
 }
775 792
 
... ...
@@ -939,9 +956,7 @@ void free_dlginfo_cell(void *param) {
939 956
 	free_str_list_all(cell->pubruris_caller);
940 957
 	free_str_list_all(cell->pubruris_callee);
941 958
 
942
-	/*if (cell->to_tag) {
943
-		shm_free(cell->to_tag);
944
-	}*/
959
+	if(use_pubruri_avps) lock_destroy(cell->lock);
945 960
 	shm_free(param);
946 961
 }
947 962
 
... ...
@@ -23,6 +23,7 @@
23 23
 
24 24
 #ifndef _PUA_DLGINFO_H
25 25
 #define _PUA_DLGINFO_H
26
+#include "../../core/locking.h"
26 27
 #include "../pua/pua_bind.h"
27 28
 
28 29
 extern send_publish_t pua_send_publish;
... ...
@@ -35,6 +36,7 @@ void dialog_publish_multi(char *state, struct str_list* ruris, str *entity, str
35 36
  * dlg_cell during the callback (as this could create a race condition
36 37
  * if the dlg_cell gets meanwhile deleted) */
37 38
 struct dlginfo_cell {
39
+	gen_lock_t lock;
38 40
 	str from_uri;
39 41
 	str to_uri;
40 42
 	str callid;