From 99390287c4f97e94283b303036e5eac99bfa850f Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Fri, 11 Feb 2022 00:03:53 +0200 Subject: [PATCH] b2b_logic: fix and document the b2b_terminate_call MI command Closes #2530 (cherry picked from commit 0a6b2607fcf3282c941e4dedae122ddfc2fd927a) --- modules/b2b_logic/b2b_logic.c | 38 ++++++++++++++++++++--- modules/b2b_logic/doc/b2b_logic_admin.xml | 25 +++++++++++++++ 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/modules/b2b_logic/b2b_logic.c b/modules/b2b_logic/b2b_logic.c index 1763f94dde1..448992881d2 100644 --- a/modules/b2b_logic/b2b_logic.c +++ b/modules/b2b_logic/b2b_logic.c @@ -220,7 +220,7 @@ static mi_export_t mi_cmds[] = { {EMPTY_MI_RECIPE}} }, {"b2b_terminate_call", 0, 0, 0, { - {mi_b2b_terminate_call, {0}}, + {mi_b2b_terminate_call, {"key", 0}}, {EMPTY_MI_RECIPE}} }, {EMPTY_MI_EXPORT} @@ -522,7 +522,7 @@ void b2bl_db_timer_update(unsigned int ticks, void* param) b2b_logic_dump(0); } -static void term_expired_entity(b2bl_entity_id_t *entity, int hash_index) +static void term_entity(b2bl_entity_id_t *entity, int hash_index) { str bye = {BYE, BYE_LEN}; b2b_req_data_t req_data; @@ -581,10 +581,10 @@ void b2bl_clean(unsigned int ticks, void* param) if(tuple->bridge_entities[0] && tuple->bridge_entities[1] && !tuple->to_del) { if(!tuple->bridge_entities[0]->disconnected) - term_expired_entity(tuple->bridge_entities[0], i); + term_entity(tuple->bridge_entities[0], i); if(!tuple->bridge_entities[1]->disconnected) - term_expired_entity(tuple->bridge_entities[1], i); + term_entity(tuple->bridge_entities[1], i); } b2bl_delete(tuple, i, 1, tuple->repl_flag != TUPLE_REPL_RECV); } @@ -1259,11 +1259,39 @@ static mi_response_t *mi_b2b_terminate_call(const mi_params_t *params, struct mi_handler *async_hdl) { str key; + unsigned int hash_index, local_index; + b2bl_tuple_t* tuple; if (get_mi_string_param(params, "key", &key.s, &key.len) < 0) return init_mi_param_error(); - b2bl_terminate_call(&key); + if (b2bl_get_tuple_key(&key, &hash_index, &local_index) < 0) + return init_mi_error(404, MI_SSTR("B2B session not found")); + + lock_get(&b2bl_htable[hash_index].lock); + + tuple = b2bl_search_tuple_safe(hash_index, local_index); + if(tuple == NULL) + { + lock_release(&b2bl_htable[hash_index].lock); + return init_mi_error(404, MI_SSTR("B2B session not found")); + } + + if(tuple->bridge_entities[0] && tuple->bridge_entities[1] && !tuple->to_del) + { + if(!tuple->bridge_entities[0]->disconnected) { + term_entity(tuple->bridge_entities[0], hash_index); + tuple->bridge_entities[0]->disconnected = 1; + } + + if(!tuple->bridge_entities[1]->disconnected) { + term_entity(tuple->bridge_entities[1], hash_index); + tuple->bridge_entities[1]->disconnected = 1; + } + } + b2b_mark_todel(tuple); + + lock_release(&b2bl_htable[hash_index].lock); return init_mi_result_ok(); } diff --git a/modules/b2b_logic/doc/b2b_logic_admin.xml b/modules/b2b_logic/doc/b2b_logic_admin.xml index ccfbfec0ce6..9f64865f718 100644 --- a/modules/b2b_logic/doc/b2b_logic_admin.xml +++ b/modules/b2b_logic/doc/b2b_logic_admin.xml @@ -644,6 +644,31 @@ route[b2b_request] +
+ + <function moreinfo="none">b2b_terminate_call</function> + + + Terminates an ongoing B2B session. + + + Name: b2b_terminate_call + + Parameters: + + + key : the b2b_logic key + or the callid;from-tag;to-tag of + one of call legs of the ongoing session. + + + + MI FIFO Command Format: + + opensips-cli -x mi b2b_terminate_call 159.0 + +
+