Module: sip-router
Branch: carstenbock/dialog
Commit: df1c754e9563bc20f0c5e740ab1102f9f27c435b
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=df1c754…
Author: Carsten Bock <lists(a)bock.info>
Committer: Carsten Bock <lists(a)bock.info>
Date: Wed Aug 18 22:35:01 2010 +0200
- 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.
---
modules_k/dialog/dialog.c | 1 +
modules_k/dialog/dlg_hash.c | 50 +++++++++++++++++++++++++++++++++
modules_k/dialog/dlg_hash.h | 7 ++++
modules_k/dialog/dlg_req_within.h | 1 +
modules_k/dialog/doc/dialog_admin.xml | 39 +++++++++++++++++++++++++
5 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/modules_k/dialog/dialog.c b/modules_k/dialog/dialog.c
index 0ca60b4..e19e56b 100644
--- a/modules_k/dialog/dialog.c
+++ b/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_ctx", mi_print_dlgs_ctx, 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_list_dlgs", mi_profile_list, 0, 0, 0},
{ "dlg_bridge", mi_dlg_bridge, 0, 0, 0},
diff --git a/modules_k/dialog/dlg_hash.c b/modules_k/dialog/dlg_hash.c
index b004cef..80f506f 100644
--- a/modules_k/dialog/dlg_hash.c
+++ b/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
@@ -1065,3 +1066,52 @@ 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;
+
+ 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;
+}
+
diff --git a/modules_k/dialog/dlg_hash.h b/modules_k/dialog/dlg_hash.h
index e555837..aa70d84 100644
--- a/modules_k/dialog/dlg_hash.h
+++ b/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 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
diff --git a/modules_k/dialog/dlg_req_within.h b/modules_k/dialog/dlg_req_within.h
index 732f430..066361f 100644
--- a/modules_k/dialog/dlg_req_within.h
+++ b/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
diff --git a/modules_k/dialog/doc/dialog_admin.xml
b/modules_k/dialog/doc/dialog_admin.xml
index af697d9..98769f5 100644
--- a/modules_k/dialog/doc/dialog_admin.xml
+++ b/modules_k/dialog/doc/dialog_admin.xml
@@ -1530,6 +1530,45 @@ if(dlg_get("abcdef", "123", "456"))
</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_
+ abcdrssfrs122444(a)192.168.1.1
+ AAdfeEFF33
+ </programlisting>
+ </section>
+
+ <section>
<title><varname>profile_get_size</varname></title>
<para>
Returns the number of dialogs belonging to a profile. If the profile