[mod_sofia] Keep noreg gateways as NOREG, mark unregistered gateways as DOWN.

Co-authored-by: Mike Jerris <mike@signalwire.com>
This commit is contained in:
Andrey Volk 2020-10-29 00:14:00 +04:00
parent aa91b46d3f
commit a746d12f6c
3 changed files with 24 additions and 13 deletions

View File

@ -2740,6 +2740,7 @@ const char *sofia_state_names[] = {
"FAIL_WAIT", "FAIL_WAIT",
"EXPIRED", "EXPIRED",
"NOREG", "NOREG",
"DOWN",
"TIMEOUT", "TIMEOUT",
NULL NULL
}; };
@ -3653,15 +3654,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
if (!strcasecmp(gname, "all")) { if (!strcasecmp(gname, "all")) {
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) { for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
if (gateway_ptr->state != REG_STATE_NOREG) {
gateway_ptr->retry = 0; gateway_ptr->retry = 0;
gateway_ptr->state = REG_STATE_UNREGED; gateway_ptr->state = REG_STATE_UNREGED;
} }
}
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if ((gateway_ptr = sofia_reg_find_gateway(gname))) { } else if ((gateway_ptr = sofia_reg_find_gateway(gname))) {
if (gateway_ptr->state != REG_STATE_NOREG) {
gateway_ptr->retry = 0; gateway_ptr->retry = 0;
gateway_ptr->state = REG_STATE_UNREGED; gateway_ptr->state = REG_STATE_UNREGED;
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
sofia_reg_release_gateway(gateway_ptr); sofia_reg_release_gateway(gateway_ptr);
}
} else { } else {
stream->write_function(stream, "Invalid gateway!\n"); 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")) { if (!strcasecmp(gname, "all")) {
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) { for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
if (gateway_ptr->state != REG_STATE_NOREG) {
gateway_ptr->retry = 0; gateway_ptr->retry = 0;
gateway_ptr->state = REG_STATE_UNREGISTER; gateway_ptr->state = REG_STATE_UNREGISTER;
} }
}
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
} else if ((gateway_ptr = sofia_reg_find_gateway(gname))) { } else if ((gateway_ptr = sofia_reg_find_gateway(gname))) {
if (gateway_ptr->state != REG_STATE_NOREG) {
gateway_ptr->retry = 0; gateway_ptr->retry = 0;
gateway_ptr->state = REG_STATE_UNREGISTER; gateway_ptr->state = REG_STATE_UNREGISTER;
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
sofia_reg_release_gateway(gateway_ptr); sofia_reg_release_gateway(gateway_ptr);
}
} else { } else {
stream->write_function(stream, "Invalid gateway!\n"); stream->write_function(stream, "Invalid gateway!\n");
} }

View File

@ -432,6 +432,7 @@ typedef enum {
REG_STATE_FAIL_WAIT, REG_STATE_FAIL_WAIT,
REG_STATE_EXPIRED, REG_STATE_EXPIRED,
REG_STATE_NOREG, REG_STATE_NOREG,
REG_STATE_DOWN,
REG_STATE_TIMEOUT, REG_STATE_TIMEOUT,
REG_STATE_LAST REG_STATE_LAST
} reg_state_t; } reg_state_t;

View File

@ -398,6 +398,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
} }
switch (ostate) { switch (ostate) {
case REG_STATE_DOWN:
case REG_STATE_NOREG: case REG_STATE_NOREG:
if (!gateway_ptr->ping && !gateway_ptr->pinging && gateway_ptr->status != SOFIA_GATEWAY_UP) { if (!gateway_ptr->ping && !gateway_ptr->pinging && gateway_ptr->status != SOFIA_GATEWAY_UP) {
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: case REG_STATE_UNREGISTER:
sofia_reg_kill_reg(gateway_ptr); sofia_reg_kill_reg(gateway_ptr);
gateway_ptr->state = REG_STATE_NOREG; gateway_ptr->state = REG_STATE_DOWN;
gateway_ptr->status = SOFIA_GATEWAY_DOWN; gateway_ptr->status = SOFIA_GATEWAY_DOWN;
break; break;
case REG_STATE_UNREGED: case REG_STATE_UNREGED: