Prechádzať zdrojové kódy

- added support to terminate a single dialog by providing call-id and from-tag
- can also be used to terminate all dialogs on proxy (e.g. before shutdown)

Missing: Provide optional headers for the BYE-Message.

Carsten Bock 15 rokov pred
rodič
commit
df1c754e95

+ 1 - 0
modules_k/dialog/dialog.c

@@ -232,6 +232,7 @@ static mi_export_t mi_cmds[] = {
 	{ "dlg_list",           mi_print_dlgs,       0,  0,  0},
 	{ "dlg_list",           mi_print_dlgs,       0,  0,  0},
 	{ "dlg_list_ctx",       mi_print_dlgs_ctx,   0,  0,  0},
 	{ "dlg_list_ctx",       mi_print_dlgs_ctx,   0,  0,  0},
 	{ "dlg_end_dlg",        mi_terminate_dlg,    0,  0,  0},
 	{ "dlg_end_dlg",        mi_terminate_dlg,    0,  0,  0},
+	{ "dlg_terminate_dlgs", mi_terminate_dlgs,   0,  0,  0},
 	{ "profile_get_size",   mi_get_profile,      0,  0,  0},
 	{ "profile_get_size",   mi_get_profile,      0,  0,  0},
 	{ "profile_list_dlgs",  mi_profile_list,     0,  0,  0},
 	{ "profile_list_dlgs",  mi_profile_list,     0,  0,  0},
 	{ "dlg_bridge",         mi_dlg_bridge,       0,  0,  0},
 	{ "dlg_bridge",         mi_dlg_bridge,       0,  0,  0},

+ 50 - 0
modules_k/dialog/dlg_hash.c

@@ -60,6 +60,7 @@
 #include "dlg_timer.h"
 #include "dlg_timer.h"
 #include "dlg_hash.h"
 #include "dlg_hash.h"
 #include "dlg_profile.h"
 #include "dlg_profile.h"
+#include "dlg_req_within.h"
 
 
 #define MAX_LDG_LOCKS  2048
 #define MAX_LDG_LOCKS  2048
 #define MIN_LDG_LOCKS  2
 #define MIN_LDG_LOCKS  2
@@ -1065,3 +1066,52 @@ error:
 	free_mi_tree(rpl_tree);
 	free_mi_tree(rpl_tree);
 	return NULL;
 	return NULL;
 }
 }
+
+/*!
+ * \brief Terminate all or selected dialogs via the MI interface
+ * \param cmd_tree MI command tree
+ * \param param unused
+ * \return mi node with the dialog information, or NULL on failure
+ */
+struct mi_root * mi_terminate_dlgs(struct mi_root *cmd_tree, void *param )
+{
+	struct mi_root* rpl_tree= NULL;
+	struct dlg_cell* dlg = NULL;
+	str headers = {0, 0};
+	unsigned int i;
+
+	rpl_tree = process_mi_params( cmd_tree, &dlg);
+	if (rpl_tree)
+		/* param error */
+		return rpl_tree;
+
+	rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
+	if (rpl_tree==0)
+		return 0;
+
+	if (dlg==NULL) {
+		LM_DBG("terminating %i dialogs\n", d_table->size);
+
+		for( i=0 ; i<d_table->size ; i++ ) {
+			dlg_lock( d_table, &(d_table->entries[i]) );
+
+			for( dlg=d_table->entries[i].first ; dlg ; dlg=dlg->next ) {
+				if (dlg_bye_all(dlg, &headers)!=0)
+					goto error_all;
+			}
+			dlg_unlock( d_table, &(d_table->entries[i]) );
+		}
+	} else {
+		if (dlg_bye_all(dlg, &headers)!=0)
+			goto error;
+	}
+	return rpl_tree;
+error_all:
+	dlg_unlock( d_table, &(d_table->entries[i]) );
+	free_mi_tree(rpl_tree);
+	return NULL;
+error:
+	free_mi_tree(rpl_tree);
+	return NULL;
+}
+

+ 7 - 0
modules_k/dialog/dlg_hash.h

@@ -327,6 +327,13 @@ struct mi_root * mi_print_dlgs(struct mi_root *cmd, void *param );
  */
  */
 struct mi_root * mi_print_dlgs_ctx(struct mi_root *cmd, void *param );
 struct mi_root * mi_print_dlgs_ctx(struct mi_root *cmd, void *param );
 
 
+/*!
+ * \brief Terminate all or selected dialogs via the MI interface
+ * \param cmd_tree MI command tree
+ * \param param unused
+ * \return mi node with the dialog information, or NULL on failure
+ */
+struct mi_root * mi_terminate_dlgs(struct mi_root *cmd_tree, void *param );
 
 
 /*!
 /*!
  * \brief Check if a dialog structure matches to a SIP message dialog
  * \brief Check if a dialog structure matches to a SIP message dialog

+ 1 - 0
modules_k/dialog/dlg_req_within.h

@@ -31,6 +31,7 @@
 #define DLG_REQUEST_WITHIN_H
 #define DLG_REQUEST_WITHIN_H
 
 
 #include "dlg_hash.h"
 #include "dlg_hash.h"
+#include "../../modules/tm/tm_load.h"
 
 
 #define MAX_FWD			"70"
 #define MAX_FWD			"70"
 #define MAX_SIZE		256
 #define MAX_SIZE		256

+ 39 - 0
modules_k/dialog/doc/dialog_admin.xml

@@ -1529,6 +1529,45 @@ if(dlg_get("abcdef", "123", "456"))
 		</programlisting>
 		</programlisting>
 		</section>
 		</section>
 
 
+		<section>
+		<title><varname>dlg_terminate_dlgs</varname></title>
+		<para>
+		Terminates a dialog or of all dialogs (calls). If only
+		one dialogs is to be terminated, the dialog identifiers are to be passed
+		as parameter (callid and fromtag).
+		</para>
+		<para>
+		Name: <emphasis>dlg_terminate_dlgs</emphasis>
+		</para>
+		<para>Parameters:</para>
+		<itemizedlist>
+			<listitem><para>
+				<emphasis>callid</emphasis> (optional) - callid if a single
+				dialog to be terminated.
+			</para></listitem>
+			<listitem><para>
+				<emphasis>from_tag</emphasis> (optional, but cannot be present
+				without the callid parameter) - from tag (as per initial request)
+				of the dialog to be terminated.  Note that if the from_tag is not
+				specified, only dialogs created by a request without a from tag
+				are matched, which will only occur with broken clients and is
+				thus a very rare situation.
+			</para></listitem>
+		</itemizedlist>
+		<para>
+		MI FIFO Command Format:
+		</para>
+		<programlisting  format="linespecific">
+		:dlg_terminate_dlgs:_reply_fifo_file_
+		_empty_line_
+		</programlisting>
+		<programlisting  format="linespecific">
+		:dlg_terminate_dlgs:_reply_fifo_file_
+		[email protected]
+		AAdfeEFF33
+		</programlisting>
+		</section>
+
 		<section>
 		<section>
 		<title><varname>profile_get_size</varname></title>
 		<title><varname>profile_get_size</varname></title>
 		<para>
 		<para>