Blob Blame History Raw
From: rvlad-patrascu <vladp@opensips.org>
Date: Fri, 13 Oct 2017 19:11:11 +0300
Subject: [PATCH] dialog: fix a runtime bug with DLGCB_LOADED callbacks

Relying on the fact that all modules that register dialog callbacks are initialised
after the dialog module (thanks to module dependencies), we can run all DLGCB_LOADED
callbacks at registration time and also keep them in a list for calling them later
(i.e reloading from database via MI cmd or receiving replicated dialog).

This fixes a series of bugs where the DLGCB_LOADED callback is not run during, e.g.
"dlg_db_sync" MI command or received replicated dialogs which do not have their
callbacks installed or run.

(cherry picked from commit 8c8f27f6091289061f6aaf0d3c85ccd27db80a0d)

diff --git a/modules/dialog/dialog.c b/modules/dialog/dialog.c
index 64b210e4e..9e827343a 100644
--- a/modules/dialog/dialog.c
+++ b/modules/dialog/dialog.c
@@ -961,10 +961,8 @@ static int mod_init(void)
 			LM_ERR("failed to initialize the DB support\n");
 			return -1;
 		}
-		run_load_callbacks();
 	}
 
-	mark_dlg_loaded_callbacks_run();
 	destroy_cachedb(0);
 	
 	return 0;
diff --git a/modules/dialog/dlg_cb.c b/modules/dialog/dlg_cb.c
index d1cca0264..d5437cf50 100644
--- a/modules/dialog/dlg_cb.c
+++ b/modules/dialog/dlg_cb.c
@@ -36,7 +36,6 @@
 
 static struct dlg_head_cbl* create_cbs = 0;
 
-static int dlg_load_cbs_run = 0;
 static struct dlg_head_cbl* load_cbs = 0;
 
 static struct dlg_cb_params params = {NULL, DLG_DIR_NONE, NULL, NULL};
@@ -80,11 +79,6 @@ void destroy_dlg_callbacks_list(struct dlg_callback *cb)
 	}
 }
 
-void mark_dlg_loaded_callbacks_run(void)
-{
-	dlg_load_cbs_run = 1;
-}
-
 
 void destroy_dlg_callbacks(unsigned int types)
 {
@@ -161,11 +155,9 @@ int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f,
 		create_cbs->first = cb;
 		create_cbs->types |= types;
 	} else if (types==DLGCB_LOADED) {
-		if (dlg_load_cbs_run) {
-			/* run the callback on the spot */
-			run_load_callback(cb);
-			return 0;
-		}
+		/* run the callback on the spot */
+		run_load_callback(cb);
+		/* also insert callback in list to be able to run it later */
 		if (load_cbs==0) {
 			/* not initialized yet */
 			if ( (load_cbs=init_dlg_callback())==NULL ) {