9fdfac7
From: rvlad-patrascu <vladp@opensips.org>
9fdfac7
Date: Fri, 13 Oct 2017 19:11:11 +0300
9fdfac7
Subject: [PATCH] dialog: fix a runtime bug with DLGCB_LOADED callbacks
9fdfac7
9fdfac7
Relying on the fact that all modules that register dialog callbacks are initialised
9fdfac7
after the dialog module (thanks to module dependencies), we can run all DLGCB_LOADED
9fdfac7
callbacks at registration time and also keep them in a list for calling them later
9fdfac7
(i.e reloading from database via MI cmd or receiving replicated dialog).
9fdfac7
9fdfac7
This fixes a series of bugs where the DLGCB_LOADED callback is not run during, e.g.
9fdfac7
"dlg_db_sync" MI command or received replicated dialogs which do not have their
9fdfac7
callbacks installed or run.
9fdfac7
9fdfac7
(cherry picked from commit 8c8f27f6091289061f6aaf0d3c85ccd27db80a0d)
9fdfac7
9fdfac7
diff --git a/modules/dialog/dialog.c b/modules/dialog/dialog.c
9fdfac7
index 64b210e4e..9e827343a 100644
9fdfac7
--- a/modules/dialog/dialog.c
9fdfac7
+++ b/modules/dialog/dialog.c
9fdfac7
@@ -961,10 +961,8 @@ static int mod_init(void)
9fdfac7
 			LM_ERR("failed to initialize the DB support\n");
9fdfac7
 			return -1;
9fdfac7
 		}
9fdfac7
-		run_load_callbacks();
9fdfac7
 	}
9fdfac7
 
9fdfac7
-	mark_dlg_loaded_callbacks_run();
9fdfac7
 	destroy_cachedb(0);
9fdfac7
 	
9fdfac7
 	return 0;
9fdfac7
diff --git a/modules/dialog/dlg_cb.c b/modules/dialog/dlg_cb.c
9fdfac7
index d1cca0264..d5437cf50 100644
9fdfac7
--- a/modules/dialog/dlg_cb.c
9fdfac7
+++ b/modules/dialog/dlg_cb.c
9fdfac7
@@ -36,7 +36,6 @@
9fdfac7
 
9fdfac7
 static struct dlg_head_cbl* create_cbs = 0;
9fdfac7
 
9fdfac7
-static int dlg_load_cbs_run = 0;
9fdfac7
 static struct dlg_head_cbl* load_cbs = 0;
9fdfac7
 
9fdfac7
 static struct dlg_cb_params params = {NULL, DLG_DIR_NONE, NULL, NULL};
9fdfac7
@@ -80,11 +79,6 @@ void destroy_dlg_callbacks_list(struct dlg_callback *cb)
9fdfac7
 	}
9fdfac7
 }
9fdfac7
 
9fdfac7
-void mark_dlg_loaded_callbacks_run(void)
9fdfac7
-{
9fdfac7
-	dlg_load_cbs_run = 1;
9fdfac7
-}
9fdfac7
-
9fdfac7
 
9fdfac7
 void destroy_dlg_callbacks(unsigned int types)
9fdfac7
 {
9fdfac7
@@ -161,11 +155,9 @@ int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f,
9fdfac7
 		create_cbs->first = cb;
9fdfac7
 		create_cbs->types |= types;
9fdfac7
 	} else if (types==DLGCB_LOADED) {
9fdfac7
-		if (dlg_load_cbs_run) {
9fdfac7
-			/* run the callback on the spot */
9fdfac7
-			run_load_callback(cb);
9fdfac7
-			return 0;
9fdfac7
-		}
9fdfac7
+		/* run the callback on the spot */
9fdfac7
+		run_load_callback(cb);
9fdfac7
+		/* also insert callback in list to be able to run it later */
9fdfac7
 		if (load_cbs==0) {
9fdfac7
 			/* not initialized yet */
9fdfac7
 			if ( (load_cbs=init_dlg_callback())==NULL ) {