Skip to content

Commit

Permalink
dialog: added rpc command dlg.is_alive
Browse files Browse the repository at this point in the history
- adjusted from GH #1740
  • Loading branch information
surendratiwari3 authored and miconda committed Dec 5, 2018
1 parent b5dd847 commit d091de5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/modules/dialog/dialog.c
Expand Up @@ -2215,8 +2215,11 @@ static const char *rpc_profile_print_dlgs_doc[2] = {
"Lists all the dialogs belonging to a profile", 0
};
static const char *rpc_dlg_bridge_doc[2] = {
"Bridge two SIP addresses in a call using INVITE(hold)-REFER-BYE mechanism:\
to, from, [outbound SIP proxy]", 0
"Bridge two SIP addresses in a call using INVITE(hold)-REFER-BYE mechanism:"
" to, from, [outbound SIP proxy]", 0
};
static const char *rpc_dlg_is_alive_doc[2] = {
"Check whether dialog is alive or not", 0
};


Expand Down Expand Up @@ -2272,6 +2275,40 @@ static void rpc_dlg_terminate_dlg(rpc_t *rpc,void *c){
}
}

static void rpc_dlg_is_alive(rpc_t *rpc, void *c)
{
str callid = {NULL, 0};
str ftag = {NULL, 0};
str ttag = {NULL, 0};

dlg_cell_t *dlg = NULL;
unsigned int dir = 0;
unsigned int state = 0;

if (rpc->scan(c, ".S.S.S", &callid, &ftag, &ttag) < 3) {
LM_DBG("Unable to read expected parameters\n");
rpc->fault(c, 400, "Too few parameters (required callid, from-tag, to-tag)");
return;
}

dlg = get_dlg(&callid, &ftag, &ttag, &dir);

if (dlg == NULL) {
LM_DBG("Couldnt find dialog with callid: '%.*s'\n", callid.len, callid.s);
rpc->fault(c, 404, "Dialog not found");
return;
}
state = dlg->state;
dlg_release(dlg);
if (state != DLG_STATE_CONFIRMED) {
LM_DBG("Dialog with Call-ID '%.*s' is in state: %d (confirmed: %d)\n",
callid.len, callid.s, state, DLG_STATE_CONFIRMED);
rpc->fault(c, 500, "Dialog not in confirmed state");
return;
} else {
rpc->add(c, "s", "Alive");
}
}

static void rpc_end_dlg_entry_id(rpc_t *rpc, void *c) {
unsigned int h_entry, h_id;
Expand Down Expand Up @@ -2428,5 +2465,6 @@ static rpc_export_t rpc_methods[] = {
{"dlg.bridge_dlg", rpc_dlg_bridge, rpc_dlg_bridge_doc, 0},
{"dlg.terminate_dlg", rpc_dlg_terminate_dlg, rpc_dlg_terminate_dlg_doc, 0},
{"dlg.stats_active", rpc_dlg_stats_active, rpc_dlg_stats_active_doc, 0},
{"dlg.is_alive", rpc_dlg_is_alive, rpc_dlg_is_alive_doc, 0},
{0, 0, 0, 0}
};
5 changes: 5 additions & 0 deletions src/modules/dialog/doc/dialog.xml
Expand Up @@ -53,6 +53,11 @@
<surname>Johansson</surname>
<email>oej@edvina.net</email>
</editor>
<editor>
<firstname>Surendra</firstname>
<surname>Tiwari</surname>
<email>surendratiwari3@gmail.com</email>
</editor>
</authorgroup>
<copyright>
<year>2006</year>
Expand Down
30 changes: 30 additions & 0 deletions src/modules/dialog/doc/dialog_admin.xml
Expand Up @@ -2640,6 +2640,36 @@ if(has_totag()) {
...
</programlisting>
</section>
<section id="dlg.r.is_alive">
<title>dlg.is_alive</title>
<para>
Check whether a dialog matching the parameter is in confirmed
state (answered and alive).
</para>
<para>Name: <emphasis>dlg.is_alive</emphasis></para>
<para>Parameters:</para>
<itemizedlist>
<listitem><para>
<emphasis>callid</emphasis> - callid of dialog
</para></listitem>
<listitem><para>
<emphasis>from_tag</emphasis> - from tag of the dialog
</para></listitem>
<listitem><para>
<emphasis>to_tag</emphasis> - to tag of the dialog
</para></listitem>
</itemizedlist>
<para>
This command will return error if dialog is not found or not
confirmed state (answered).
</para>
<para>RPC Command Format:</para>
<programlisting format="linespecific">
...
&kamcmd; dlg.is_alive callid123 fromtag123 totag123
...
</programlisting>
</section>
</section>

<section>
Expand Down

0 comments on commit d091de5

Please sign in to comment.