Browse code

dialog: update internal_get_dlg() after 0bde3ca changes

- keep also direction value for no-totag dialog
- reference and unlock only when returning, related to #2494

(cherry picked from commit 98436c73e8519e96e3d167b7610cbb58b9939885)

Daniel-Constantin Mierla authored on 28/10/2020 09:32:50
Showing 1 changed files
... ...
@@ -857,7 +857,7 @@ dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid)
857 857
  * \param ftag from tag
858 858
  * \param ttag to tag
859 859
  * \param dir direction
860
- * \param mode let hash table slot locked or not
860
+ * \param mode let hash table slot locked or not, even when dlg is not found
861 861
  * \return dialog structure on success, NULL on failure
862 862
  */
863 863
 static inline struct dlg_cell* internal_get_dlg(unsigned int h_entry,
... ...
@@ -867,33 +867,47 @@ static inline struct dlg_cell* internal_get_dlg(unsigned int h_entry,
867 867
 	struct dlg_cell *dlg;
868 868
 	struct dlg_cell *dlg_no_totag=NULL;
869 869
 	struct dlg_entry *d_entry;
870
+	unsigned int dir_no_totag = DLG_DIR_NONE;
870 871
 
871 872
 	d_entry = &(d_table->entries[h_entry]);
872 873
 
873 874
 	dlg_lock( d_table, d_entry);
874 875
 
875 876
 	for( dlg = d_entry->first ; dlg ; dlg = dlg->next ) {
876
-		/* Check callid / fromtag / totag */
877
+		/* check callid / fromtag / totag */
877 878
 		if (match_dialog( dlg, callid, ftag, ttag, dir)==1) {
878
-			ref_dlg_unsafe(dlg, 1);
879
-			if(likely(mode==0)) dlg_unlock( d_table, d_entry);
880
-
881
-			/* If to-tag is empty continue to search in case another dialog is found with a matching to-tag. */
882
-			if (dlg->tag[1].len == 0) {
883
-				dlg_no_totag=dlg;
884
-				LM_DBG("dialog callid='%.*s' found on entry %u, dir=%d\n",
885
-					callid->len, callid->s,h_entry,*dir);
879
+			/* if to-tag is empty continue to search in case another dialog
880
+			 * is found with a matching to-tag. */
881
+			if (dlg->tag[DLG_CALLEE_LEG].len == 0) {
882
+				dlg_no_totag = dlg;
883
+				dir_no_totag = *dir;
886 884
 				continue;
887 885
 			}
886
+
887
+			ref_dlg_unsafe(dlg, 1);
888
+			if(likely(mode==0)) {
889
+				dlg_unlock( d_table, d_entry);
890
+			}
888 891
 			LM_DBG("dialog callid='%.*s' found on entry %u, dir=%d to-tag='%.*s'\n",
889
-				callid->len, callid->s,h_entry,*dir, dlg->tag[1].len, dlg->tag[1].s);
892
+				callid->len, callid->s, h_entry, *dir,
893
+				dlg->tag[DLG_CALLEE_LEG].len, dlg->tag[DLG_CALLEE_LEG].s);
890 894
 
891 895
 			return dlg;
892 896
 		}
893 897
 	}
894 898
 
895
-	if(likely(mode==0)) dlg_unlock( d_table, d_entry);
896
-	if (dlg_no_totag) return dlg_no_totag;
899
+	if (dlg_no_totag) {
900
+		ref_dlg_unsafe(dlg_no_totag, 1);
901
+	}
902
+	if(likely(mode==0)) {
903
+		dlg_unlock(d_table, d_entry);
904
+	}
905
+	if (dlg_no_totag) {
906
+		*dir = dir_no_totag;
907
+		LM_DBG("dialog callid='%.*s' found on entry %u, dir=%d no-to-tag\n",
908
+				callid->len, callid->s, h_entry, *dir);
909
+		return dlg_no_totag;
910
+	}
897 911
 
898 912
 	LM_DBG("no dialog callid='%.*s' found\n", callid->len, callid->s);
899 913
 	return 0;