Browse code

dialog: rpc kill_active_dlg replaced with dlg.set_state

- enable the option to set different state values, although right now
targets the turning confirmed in terminated

Daniel-Constantin Mierla authored on 30/10/2019 12:41:42
Showing 2 changed files
... ...
@@ -2368,8 +2368,10 @@ static const char *rpc_end_dlg_entry_id_doc[2] = {
2368 2368
 static const char *rpc_dlg_terminate_dlg_doc[2] = {
2369 2369
         "End a given dialog based on callid", 0
2370 2370
 };
2371
-static const char *rpc_dlg_kill_active_dlg_doc[2] = {
2372
-        "Kill a given active dialog based on callid and tags", 0
2371
+static const char *rpc_dlg_set_state_doc[3] = {
2372
+        "Set state for a dialog based on callid and tags",
2373
+        "It is targeting the need to update from state 4 (confirmed) to 5 (terminated)",
2374
+        0
2373 2375
 };
2374 2376
 static const char *rpc_profile_get_size_doc[2] = {
2375 2377
 	"Returns the number of dialogs belonging to a profile", 0
... ...
@@ -2438,53 +2440,65 @@ static void rpc_dlg_terminate_dlg(rpc_t *rpc,void *c){
2438 2440
     }
2439 2441
 }
2440 2442
 
2441
-static void rpc_dlg_kill_active_dlg(rpc_t *rpc,void *c){
2443
+static void rpc_dlg_set_state(rpc_t *rpc,void *c){
2442 2444
 	str callid = {NULL,0};
2443 2445
 	str ftag = {NULL,0};
2444 2446
 	str ttag = {NULL,0};
2447
+	int sval = DLG_STATE_DELETED;
2448
+	int ostate = 0;
2445 2449
 
2446 2450
 	dlg_cell_t * dlg = NULL;
2447 2451
 	unsigned int dir;
2448 2452
 	int unref=1;
2449 2453
 	dir = 0;
2450 2454
 
2451
-	if(rpc->scan(c, ".S.S.S", &callid,&ftag,&ttag)<3) {
2452
-		LM_ERR("Unable to read the parameters dlg_terminate_dlg \n" );
2453
-		rpc->fault(c, 400, "Need a Callid ,from tag ,to tag");
2455
+	if(rpc->scan(c, ".S.S.Sd", &callid, &ftag, &ttag, &sval)<3) {
2456
+		LM_ERR("unable to read the parameters\n" );
2457
+		rpc->fault(c, 400, "Need the callid, from tag,to tag and state");
2458
+		return;
2459
+	}
2460
+	if(sval < DLG_STATE_UNCONFIRMED || sval > DLG_STATE_DELETED) {
2461
+		LM_ERR("invalid new state value: %d\n", sval);
2462
+		rpc->fault(c, 500, "Invalid state value");
2454 2463
 		return;
2455 2464
 	}
2456 2465
 
2457 2466
 	dlg=get_dlg(&callid, &ftag, &ttag, &dir);
2458 2467
 
2459 2468
 	if(dlg==NULL) {
2460
-		LM_ERR("Couldnt find callid in dialog '%.*s' \n",callid.len, callid.s);
2461
-		rpc->fault(c, 500, "Couldnt find callid in dialog");
2469
+		LM_ERR("dialog not found - callid '%.*s' \n", callid.len, callid.s);
2470
+		rpc->fault(c, 500, "Dialog not found");
2462 2471
 		return;
2463 2472
 	}
2464 2473
 
2465
-	LM_DBG("Dialog is found with callid '%.*s' for kill_active_dlg rpc \n",
2466
-			callid.len, callid.s);
2474
+	LM_DBG("dialog found - callid '%.*s'\n", callid.len, callid.s);
2467 2475
 
2468
-	if(dlg->state != 4) {
2469
-		LM_ERR("Not handling dialog with callid '%.*s': should be in active state to run this command \n",
2470
-			callid.len, callid.s);
2471
-		rpc->fault(c, 500, "Dialog not in active state");
2472
-		return;
2476
+	if(dlg->state != DLG_STATE_CONFIRMED || sval!=DLG_STATE_DELETED) {
2477
+		LM_WARN("updating states for not confirmed dialogs not properly supported yet,"
2478
+				" use at own risk: '%.*s'\n", callid.len, callid.s);
2473 2479
 	}
2474 2480
 
2475
-	/* Forcing next state for this dialog */
2476
-	dlg->state = 5;
2477
-	/* Updating timestamps, flags, dialog stats */
2478
-	dlg->init_ts = (unsigned int)(time(0));
2479
-	dlg->end_ts = (unsigned int)(time(0));
2481
+	/* setting new state for this dialog */
2482
+	ostate = dlg->state;
2483
+	dlg->state = sval;
2484
+
2485
+	/* updates for terminated dialogs */
2486
+	if(ostate==DLG_STATE_CONFIRMED && sval==DLG_STATE_DELETED) {
2487
+		/* updating timestamps, flags, dialog stats */
2488
+		dlg->init_ts = (unsigned int)(time(0));
2489
+		dlg->end_ts = (unsigned int)(time(0));
2490
+	}
2480 2491
 	dlg->dflags |= DLG_FLAG_NEW;
2481 2492
 
2482 2493
 	dlg_unref(dlg, unref);
2483
-	if_update_stat(dlg_enable_stats, active_dlgs, -1);
2494
+
2495
+	if(ostate==DLG_STATE_CONFIRMED && sval==DLG_STATE_DELETED) {
2496
+		if_update_stat(dlg_enable_stats, active_dlgs, -1);
2497
+	}
2484 2498
 
2485 2499
 	/* dlg_clean_run called by timer execution will handle timers deletion and all that stuff */
2486
-	LM_NOTICE("Dialog '%.*s' forced to deleted state: will be wiped out from memory in a few minutes \n",
2487
-			callid.len, callid.s);
2500
+	LM_NOTICE("dialog callid '%.*s' - state change forced - old: %d - new: %d\n",
2501
+			callid.len, callid.s, ostate, sval);
2488 2502
 
2489 2503
 	rpc->add(c, "s", "Done");
2490 2504
 
... ...
@@ -2835,7 +2849,7 @@ static rpc_export_t rpc_methods[] = {
2835 2849
 	{"dlg.profile_list", rpc_profile_print_dlgs, rpc_profile_print_dlgs_doc, RET_ARRAY},
2836 2850
 	{"dlg.bridge_dlg", rpc_dlg_bridge, rpc_dlg_bridge_doc, 0},
2837 2851
 	{"dlg.terminate_dlg", rpc_dlg_terminate_dlg, rpc_dlg_terminate_dlg_doc, 0},
2838
-	{"dlg.kill_active_dlg", rpc_dlg_kill_active_dlg, rpc_dlg_kill_active_dlg_doc, 0},
2852
+	{"dlg.set_state", rpc_dlg_set_state, rpc_dlg_set_state_doc, 0},
2839 2853
 	{"dlg.stats_active", rpc_dlg_stats_active, rpc_dlg_stats_active_doc, 0},
2840 2854
 	{"dlg.is_alive",  rpc_dlg_is_alive, rpc_dlg_is_alive_doc, 0},
2841 2855
 	{0, 0, 0, 0}
... ...
@@ -2600,9 +2600,9 @@ if(has_totag()) {
2600 2600
 		</programlisting>
2601 2601
 		</section>
2602 2602
 		<section>
2603
-			<title>dlg.kill_active_dlg</title>
2603
+			<title>dlg.set_state</title>
2604 2604
 			<para>
2605
-			Kills a given active dialog matching the dialog on Call-ID, From-Tag and To-Tag.
2605
+			Set state for the dialog matching the dialog on Call-ID, From-Tag and To-Tag.
2606 2606
 			</para>
2607 2607
 		<para>Name: <emphasis>dlg.kill_active_dlg</emphasis></para>
2608 2608
 		<para>Parameters:</para>
... ...
@@ -2616,11 +2616,16 @@ if(has_totag()) {
2616 2616
 			<listitem><para>
2617 2617
 				<emphasis>to_tag</emphasis> - To-tag of active dialog to kill
2618 2618
 			</para></listitem>
2619
+			<listitem><para>
2620
+				<emphasis>state</emphasis> - The value for new state
2621
+			</para></listitem>
2619 2622
 		</itemizedlist>
2620 2623
 		<para>
2621
-		This command only handles active dialogs (state 4), error is returned otherwise.
2622
-		Please be careful with it, it callously wipes out the given dialog: dialog ending
2623
-		functions will not be called, such as accounting end-of-call events, dialog-end
2624
+		At this moment, the command targets the need to change from active dialogs
2625
+		(state 4) to terminated state (5), although it allows setting other state
2626
+		value. Be careful using with it, it can cause side effects and the
2627
+		terminated dialog is wiped out silently. Dialog ending functions are not
2628
+		executed, such as accounting end-of-call events, dialog-end
2624 2629
 		events, module-generated BYE requests, etc. After executing the	command, dialog
2625 2630
 		remains in memory until execution of the recurring function in charge of removing
2626 2631
 		old dialogs (a "dialog in delete state is too old" will then be logged).
... ...
@@ -2628,7 +2633,7 @@ if(has_totag()) {
2628 2633
 		<para>RPC Command Format:</para>
2629 2634
 		<programlisting  format="linespecific">
2630 2635
 ...
2631
-&kamcmd; dlg.kill_active_dlg callid12345 fromtag123 totag123
2636
+&kamcmd; dlg.set_state callid12345 fromtag123 totag123 5
2632 2637
 ...
2633 2638
 		</programlisting>
2634 2639
 		</section>