Browse code

dialog: added rpc command dlg.is_alive

- adjusted from GH #1740

Surendra Tiwari authored on 05/12/2018 09:58:18
Showing 3 changed files
... ...
@@ -2215,8 +2215,11 @@ static const char *rpc_profile_print_dlgs_doc[2] = {
2215 2215
 	"Lists all the dialogs belonging to a profile", 0
2216 2216
 };
2217 2217
 static const char *rpc_dlg_bridge_doc[2] = {
2218
-	"Bridge two SIP addresses in a call using INVITE(hold)-REFER-BYE mechanism:\
2219
- to, from, [outbound SIP proxy]", 0
2218
+	"Bridge two SIP addresses in a call using INVITE(hold)-REFER-BYE mechanism:"
2219
+		" to, from, [outbound SIP proxy]", 0
2220
+};
2221
+static const char *rpc_dlg_is_alive_doc[2] = {
2222
+	"Check whether dialog is alive or not", 0
2220 2223
 };
2221 2224
 
2222 2225
 
... ...
@@ -2272,6 +2275,40 @@ static void rpc_dlg_terminate_dlg(rpc_t *rpc,void *c){
2272 2272
     }
2273 2273
 }
2274 2274
 
2275
+static void rpc_dlg_is_alive(rpc_t *rpc, void *c)
2276
+{
2277
+	str callid = {NULL, 0};
2278
+	str ftag = {NULL, 0};
2279
+	str ttag = {NULL, 0};
2280
+
2281
+	dlg_cell_t *dlg = NULL;
2282
+	unsigned int dir = 0;
2283
+	unsigned int state = 0;
2284
+
2285
+	if (rpc->scan(c, ".S.S.S", &callid, &ftag, &ttag) < 3) {
2286
+		LM_DBG("Unable to read expected parameters\n");
2287
+		rpc->fault(c, 400, "Too few parameters (required callid, from-tag, to-tag)");
2288
+		return;
2289
+	}
2290
+
2291
+	dlg = get_dlg(&callid, &ftag, &ttag, &dir);
2292
+
2293
+	if (dlg == NULL) {
2294
+		LM_DBG("Couldnt find dialog with callid: '%.*s'\n", callid.len, callid.s);
2295
+		rpc->fault(c, 404, "Dialog not found");
2296
+		return;
2297
+	}
2298
+	state = dlg->state;
2299
+    dlg_release(dlg);
2300
+	if (state != DLG_STATE_CONFIRMED) {
2301
+		LM_DBG("Dialog with Call-ID '%.*s' is in state: %d (confirmed: %d)\n",
2302
+				callid.len, callid.s, state, DLG_STATE_CONFIRMED);
2303
+		rpc->fault(c, 500, "Dialog not in confirmed state");
2304
+		return;
2305
+	} else {
2306
+		rpc->add(c, "s", "Alive");
2307
+	}
2308
+}
2275 2309
 
2276 2310
 static void rpc_end_dlg_entry_id(rpc_t *rpc, void *c) {
2277 2311
 	unsigned int h_entry, h_id;
... ...
@@ -2428,5 +2465,6 @@ static rpc_export_t rpc_methods[] = {
2428 2428
 	{"dlg.bridge_dlg", rpc_dlg_bridge, rpc_dlg_bridge_doc, 0},
2429 2429
 	{"dlg.terminate_dlg", rpc_dlg_terminate_dlg, rpc_dlg_terminate_dlg_doc, 0},
2430 2430
 	{"dlg.stats_active", rpc_dlg_stats_active, rpc_dlg_stats_active_doc, 0},
2431
+	{"dlg.is_alive",  rpc_dlg_is_alive, rpc_dlg_is_alive_doc, 0},
2431 2432
 	{0, 0, 0, 0}
2432 2433
 };
... ...
@@ -53,6 +53,11 @@
53 53
 			<surname>Johansson</surname>
54 54
 			<email>oej@edvina.net</email>
55 55
 		</editor>
56
+		<editor>
57
+			<firstname>Surendra</firstname>
58
+			<surname>Tiwari</surname>
59
+			<email>surendratiwari3@gmail.com</email>
60
+		</editor>
56 61
 	</authorgroup>
57 62
 	<copyright>
58 63
 		<year>2006</year>
... ...
@@ -2640,6 +2640,36 @@ if(has_totag()) {
2640 2640
 ...
2641 2641
 		</programlisting>
2642 2642
 		</section>
2643
+		<section id="dlg.r.is_alive">
2644
+			<title>dlg.is_alive</title>
2645
+			<para>
2646
+				Check whether a dialog matching the parameter is in confirmed
2647
+				state (answered and alive).
2648
+			</para>
2649
+			<para>Name: <emphasis>dlg.is_alive</emphasis></para>
2650
+			<para>Parameters:</para>
2651
+			<itemizedlist>
2652
+				<listitem><para>
2653
+					<emphasis>callid</emphasis> - callid of dialog
2654
+				</para></listitem>
2655
+				<listitem><para>
2656
+					<emphasis>from_tag</emphasis> - from tag of the dialog
2657
+				</para></listitem>
2658
+				<listitem><para>
2659
+					<emphasis>to_tag</emphasis> - to tag of the dialog
2660
+				</para></listitem>
2661
+			</itemizedlist>
2662
+			<para>
2663
+				This command will return error if dialog is not found or not
2664
+				confirmed state (answered).
2665
+			</para>
2666
+			<para>RPC Command Format:</para>
2667
+			<programlisting format="linespecific">
2668
+...
2669
+&kamcmd; dlg.is_alive callid123 fromtag123 totag123
2670
+...
2671
+			</programlisting>
2672
+		</section>
2643 2673
 	</section>
2644 2674
 
2645 2675
 	<section>