浏览代码

Merge remote branch 'origin/carstenbock/dialog2'

* origin/carstenbock/dialog2:
  - Updated docs
  - Use only call-id to get the h_id; otherwise dlg_list_dlg and dlg_terminate_dlg would require the from-tag, which is marked as optional in the docs
  - added support to terminate a single dialog by providing call-id and from-tag
Carsten Bock 15 年之前
父节点
当前提交
7e43797d47

+ 2 - 1
modules_k/dialog/dialog.c

@@ -233,6 +233,7 @@ static mi_export_t mi_cmds[] = {
 	{ "dlg_list",           mi_print_dlgs,       0,  0,  0},
 	{ "dlg_list_ctx",       mi_print_dlgs_ctx,   0,  0,  0},
 	{ "dlg_end_dlg",        mi_terminate_dlg,    0,  0,  0},
+	{ "dlg_terminate_dlg",  mi_terminate_dlgs,   0,  0,  0},
 	{ "profile_get_size",   mi_get_profile,      0,  0,  0},
 	{ "profile_list_dlgs",  mi_profile_list,     0,  0,  0},
 	{ "dlg_bridge",         mi_dlg_bridge,       0,  0,  0},
@@ -1200,7 +1201,7 @@ static void internal_rpc_print_single_dlg(rpc_t *rpc, void *c, int with_context)
 
 	if (rpc->scan(c, ".S.S", &callid, &from_tag) < 2) return;
 
-	h_entry = core_hash( &callid, &from_tag, d_table->size);
+	h_entry = core_hash( &callid, 0, d_table->size);
 	d_entry = &(d_table->entries[h_entry]);
 	dlg_lock( d_table, d_entry);
 	for( dlg = d_entry->first ; dlg ; dlg = dlg->next ) {

+ 36 - 3
modules_k/dialog/dlg_hash.c

@@ -60,6 +60,7 @@
 #include "dlg_timer.h"
 #include "dlg_hash.h"
 #include "dlg_profile.h"
+#include "dlg_req_within.h"
 
 #define MAX_LDG_LOCKS  2048
 #define MIN_LDG_LOCKS  2
@@ -239,7 +240,7 @@ struct dlg_cell* build_new_dlg( str *callid, str *from_uri, str *to_uri,
 	memset( dlg, 0, len);
 	dlg->state = DLG_STATE_UNCONFIRMED;
 
-	dlg->h_entry = core_hash( callid, from_tag->len?from_tag:0, d_table->size);
+	dlg->h_entry = core_hash( callid, 0, d_table->size);
 	LM_DBG("new dialog on hash %u\n",dlg->h_entry);
 
 	p = (char*)(dlg+1);
@@ -469,7 +470,7 @@ struct dlg_cell* get_dlg( str *callid, str *ftag, str *ttag, unsigned int *dir,
 {
 	struct dlg_cell *dlg;
 
-	if ((dlg = internal_get_dlg(core_hash(callid, ftag->len?ftag:0,
+	if ((dlg = internal_get_dlg(core_hash(callid, 0,
 			d_table->size), callid, ftag, ttag, dir, del)) == 0 &&
 			(dlg = internal_get_dlg(core_hash(callid, ttag->len
 			?ttag:0, d_table->size), callid, ftag, ttag, dir, del)) == 0) {
@@ -970,7 +971,7 @@ static inline struct mi_root* process_mi_params(struct mi_root *cmd_tree,
 			return init_mi_tree( 400, MI_SSTR(MI_MISSING_PARM));
 	}
 
-	h_entry = core_hash( callid, from_tag, d_table->size);
+	h_entry = core_hash( callid, 0, d_table->size);
 
 	d_entry = &(d_table->entries[h_entry]);
 	dlg_lock( d_table, d_entry);
@@ -1065,3 +1066,35 @@ error:
 	free_mi_tree(rpl_tree);
 	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;
+	if (dlg==NULL)
+		return init_mi_tree( 400, MI_SSTR(MI_MISSING_PARM));
+
+	rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
+	if (rpl_tree==0)
+		return 0;
+	if (dlg_bye_all(dlg, &headers)!=0)
+		goto error;
+	return rpl_tree;
+error:
+	free_mi_tree(rpl_tree);
+	return NULL;
+}
+

+ 19 - 6
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 );
 
+/*!
+ * \brief Terminate 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
@@ -428,13 +435,19 @@ static inline int match_dialog(struct dlg_cell *dlg, str *callid,
  */
 static inline int match_downstream_dialog(struct dlg_cell *dlg, str *callid, str *ftag)
 {
-	if(dlg==NULL || callid==NULL || ftag==NULL)
-		return 0;
-	if (dlg->callid.len!=callid->len ||
-		dlg->tag[DLG_CALLER_LEG].len!=ftag->len  ||
-		strncmp(dlg->callid.s,callid->s,callid->len)!=0 ||
-		strncmp(dlg->tag[DLG_CALLER_LEG].s,ftag->s,ftag->len)!=0)
+	if(dlg==NULL || callid==NULL)
 		return 0;
+	if (ftag==NULL) {
+		if (dlg->callid.len!=callid->len ||
+			strncmp(dlg->callid.s,callid->s,callid->len)!=0)
+			return 0;
+	} else {
+		if (dlg->callid.len!=callid->len ||
+			dlg->tag[DLG_CALLER_LEG].len!=ftag->len  ||
+			strncmp(dlg->callid.s,callid->s,callid->len)!=0 ||
+			strncmp(dlg->tag[DLG_CALLER_LEG].s,ftag->s,ftag->len)!=0)
+			return 0;
+	}
 	return 1;
 }
 

+ 1 - 0
modules_k/dialog/dlg_req_within.h

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

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

@@ -1519,6 +1519,9 @@ if(dlg_get("abcdef", "123", "456"))
 		MI command.
 		</para>
 		<para>
+		<emphasis>Note: Works only for confirmed dialogs.</emphasis>
+		</para>
+		<para>
 		MI FIFO Command Format:
 		</para>
 		<programlisting  format="linespecific">
@@ -1529,6 +1532,41 @@ if(dlg_get("abcdef", "123", "456"))
 		</programlisting>
 		</section>
 
+		<section>
+		<title><varname>dlg_terminate_dlg</varname></title>
+		<para>
+		Terminates a singe dialog, identified by a Call-ID.
+		</para>
+		<para>
+		Name: <emphasis>dlg_terminate_dlg</emphasis>
+		</para>
+		<para>Parameters:</para>
+		<itemizedlist>
+			<listitem><para>
+				<emphasis>callid</emphasis> - callid of the 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>
+		<emphasis>Note: Works only for confirmed dialogs.</emphasis>
+		</para>
+		<para>
+		MI FIFO Command Format:
+		</para>
+		<programlisting  format="linespecific">
+		:dlg_terminate_dlg:_reply_fifo_file_
+		[email protected]
+		AAdfeEFF33
+		</programlisting>
+		</section>
+
 		<section>
 		<title><varname>profile_get_size</varname></title>
 		<para>