diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 8ce1996ccb..3143fffa42 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2740,6 +2740,7 @@ const char *sofia_state_names[] = { "FAIL_WAIT", "EXPIRED", "NOREG", + "DOWN", "TIMEOUT", NULL }; @@ -3653,15 +3654,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t if (!strcasecmp(gname, "all")) { for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) { - gateway_ptr->retry = 0; - gateway_ptr->state = REG_STATE_UNREGED; + if (gateway_ptr->state != REG_STATE_NOREG) { + gateway_ptr->retry = 0; + gateway_ptr->state = REG_STATE_UNREGED; + } } stream->write_function(stream, "+OK\n"); } else if ((gateway_ptr = sofia_reg_find_gateway(gname))) { - gateway_ptr->retry = 0; - gateway_ptr->state = REG_STATE_UNREGED; - stream->write_function(stream, "+OK\n"); - sofia_reg_release_gateway(gateway_ptr); + if (gateway_ptr->state != REG_STATE_NOREG) { + gateway_ptr->retry = 0; + gateway_ptr->state = REG_STATE_UNREGED; + stream->write_function(stream, "+OK\n"); + sofia_reg_release_gateway(gateway_ptr); + } } else { stream->write_function(stream, "Invalid gateway!\n"); } @@ -3680,15 +3685,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t if (!strcasecmp(gname, "all")) { for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) { - gateway_ptr->retry = 0; - gateway_ptr->state = REG_STATE_UNREGISTER; + if (gateway_ptr->state != REG_STATE_NOREG) { + gateway_ptr->retry = 0; + gateway_ptr->state = REG_STATE_UNREGISTER; + } } stream->write_function(stream, "+OK\n"); } else if ((gateway_ptr = sofia_reg_find_gateway(gname))) { - gateway_ptr->retry = 0; - gateway_ptr->state = REG_STATE_UNREGISTER; - stream->write_function(stream, "+OK\n"); - sofia_reg_release_gateway(gateway_ptr); + if (gateway_ptr->state != REG_STATE_NOREG) { + gateway_ptr->retry = 0; + gateway_ptr->state = REG_STATE_UNREGISTER; + stream->write_function(stream, "+OK\n"); + sofia_reg_release_gateway(gateway_ptr); + } } else { stream->write_function(stream, "Invalid gateway!\n"); } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 3249533730..d4631b02d6 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -432,6 +432,7 @@ typedef enum { REG_STATE_FAIL_WAIT, REG_STATE_EXPIRED, REG_STATE_NOREG, + REG_STATE_DOWN, REG_STATE_TIMEOUT, REG_STATE_LAST } reg_state_t; diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 81d2ffdabd..b1586405b7 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -398,6 +398,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) } switch (ostate) { + case REG_STATE_DOWN: case REG_STATE_NOREG: if (!gateway_ptr->ping && !gateway_ptr->pinging && gateway_ptr->status != SOFIA_GATEWAY_UP) { gateway_ptr->status = SOFIA_GATEWAY_UP; @@ -432,7 +433,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) case REG_STATE_UNREGISTER: sofia_reg_kill_reg(gateway_ptr); - gateway_ptr->state = REG_STATE_NOREG; + gateway_ptr->state = REG_STATE_DOWN; gateway_ptr->status = SOFIA_GATEWAY_DOWN; break; case REG_STATE_UNREGED: