From 0059f0cc1b34a59818a7bfc5074b7be94b2e432a Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 18 Mar 2021 00:53:38 +0300 Subject: [PATCH] [mod_sofia] Gateways DOWN state introduced a regression: REG gateways in DOWN state could not be killed. NOREG gateways could change state in some conditions. Register and Unregister commands will now error if a gateway is NOREG. --- src/mod/endpoints/mod_sofia/mod_sofia.c | 4 ++++ src/mod/endpoints/mod_sofia/sofia_reg.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 3143fffa42..ecc925cf78 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3666,6 +3666,8 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t gateway_ptr->state = REG_STATE_UNREGED; stream->write_function(stream, "+OK\n"); sofia_reg_release_gateway(gateway_ptr); + } else { + stream->write_function(stream, "-ERR NOREG gateway [%s] can't be registered!\n", gname); } } else { stream->write_function(stream, "Invalid gateway!\n"); @@ -3697,6 +3699,8 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t gateway_ptr->state = REG_STATE_UNREGISTER; stream->write_function(stream, "+OK\n"); sofia_reg_release_gateway(gateway_ptr); + } else { + stream->write_function(stream, "-ERR NOREG gateway [%s] can't be unregistered!\n", gname); } } else { stream->write_function(stream, "Invalid gateway!\n"); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 5eee1c17e3..22997cecae 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -323,7 +323,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) free(pkey); } - if (gateway_ptr->state == REG_STATE_NOREG) { + if (gateway_ptr->state == REG_STATE_NOREG || gateway_ptr->state == REG_STATE_DOWN) { if (last) { last->next = gateway_ptr->next; @@ -356,7 +356,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) char *user_via = NULL; char *register_host = NULL; - if (!now) { + if (!now && ostate != REG_STATE_NOREG) { gateway_ptr->state = ostate = REG_STATE_UNREGED; gateway_ptr->expires_str = "0"; }