Parcourir la source

dialog: reset local variables shortcuts after reply and failure processing

- avoid using wrong values to find dialogs with processing of next messages
- reported by Julia Boudniatsky

(cherry picked from commit dcdb73d792719e38844eef60f821365b587893d7)
Daniel-Constantin Mierla il y a 10 ans
Parent
commit
8a6660697b

+ 10 - 0
modules/dialog/dialog.c

@@ -626,6 +626,16 @@ static int mod_init(void)
 		return -1;
 	}
 
+	if (register_script_cb( cb_dlg_locals_reset, POST_SCRIPT_CB|ONREPLY_CB_TYPE,0)<0) {
+		LM_ERR("cannot register reply post-script dlg locals reset callback\n");
+		return -1;
+	}
+
+	if (register_script_cb( cb_dlg_locals_reset, POST_SCRIPT_CB|FAILURE_CB_TYPE,0)<0) {
+		LM_ERR("cannot register failure post-script dlg locals reset callback\n");
+		return -1;
+	}
+
 	if(dlg_timer_procs<=0) {
 		if ( register_timer( dlg_timer_routine, 0, 1)<0 ) {
 			LM_ERR("failed to register timer \n");

+ 21 - 0
modules/dialog/dlg_profile.c

@@ -408,6 +408,27 @@ int remove_profile(dlg_profile_table_t *profile, str *value, str *puid)
 }
 
 
+/*!
+ * \brief Callback for cleanup of profile local vars
+ * \param msg SIP message
+ * \param flags unused
+ * \param param unused
+ * \return 1
+ */
+int cb_profile_reset( struct sip_msg *msg, unsigned int flags, void *param )
+{
+	current_dlg_msg_id = 0;
+	current_dlg_msg_pid = 0;
+	if (current_pending_linkers) {
+		destroy_linkers(current_pending_linkers);
+		current_pending_linkers = NULL;
+	}
+
+	/* need to return non-zero - 0 will break the exec of the request */
+	return 1;
+}
+
+
 /*!
  * \brief Cleanup a profile
  * \param msg SIP message

+ 10 - 0
modules/dialog/dlg_profile.h

@@ -115,6 +115,16 @@ void destroy_dlg_profiles(void);
 struct dlg_profile_table* search_dlg_profile(str *name);
 
 
+/*!
+ * \brief Callback for cleanup of profile local vars
+ * \param msg SIP message
+ * \param flags unused
+ * \param param unused
+ * \return 1
+ */
+int cb_profile_reset( struct sip_msg *msg, unsigned int flags, void *param );
+
+
 /*!
  * \brief Cleanup a profile
  * \param msg SIP message

+ 15 - 0
modules/dialog/dlg_var.c

@@ -69,6 +69,21 @@ int dlg_cfg_cb(sip_msg_t *msg, unsigned int flags, void *cbp)
 	return 1;
 }
 
+int cb_dlg_cfg_reset(sip_msg_t *msg, unsigned int flags, void *cbp)
+{
+	memset(&_dlg_ctx, 0, sizeof(dlg_ctx_t));
+
+	return 1;
+}
+
+int cb_dlg_locals_reset(sip_msg_t *msg, unsigned int flags, void *cbp)
+{
+	LM_DBG("resetting the local dialog shortcuts\n");
+	cb_dlg_cfg_reset(msg, flags, cbp);
+	cb_profile_reset(msg, flags, cbp);
+
+	return 1;
+}
 
 static inline struct dlg_var *new_dlg_var(str *key, str *val)
 {

+ 2 - 0
modules/dialog/dlg_var.h

@@ -82,6 +82,8 @@ int pv_get_dlg(sip_msg_t *msg,  pv_param_t *param,
 int pv_parse_dlg_name(pv_spec_p sp, str *in);
 
 int dlg_cfg_cb(sip_msg_t *foo, unsigned int flags, void *bar);
+int cb_dlg_cfg_reset(sip_msg_t *msg, unsigned int flags, void *cbp);
+int cb_dlg_locals_reset(sip_msg_t *msg, unsigned int flags, void *cbp);
 
 void dlg_set_ctx_iuid(dlg_cell_t *dlg);
 void dlg_reset_ctx_iuid(void);