]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_sofia] Keep noreg gateways as NOREG, mark unregistered gateways as DOWN.
authorAndrey Volk <andywolk@gmail.com>
Wed, 28 Oct 2020 20:14:00 +0000 (00:14 +0400)
committerAndrey Volk <andywolk@gmail.com>
Wed, 17 Mar 2021 15:20:32 +0000 (18:20 +0300)
Co-authored-by: Mike Jerris <mike@signalwire.com>
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_reg.c

index 8ce1996ccb1d180bf342b2d3aa728e84453b3ac4..3143fffa42a1671d6589736d918b093fbd7b9645 100644 (file)
@@ -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");
                }
index 324953373053f0afa29f21adec8b4cc8a9dc3a4f..d4631b02d639bd7a9a1a4f90e2cff6341ee04719 100644 (file)
@@ -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;
index 81d2ffdabd084797ffa3d9039f5812cf1141c3ef..b1586405b794de120e1030268afc99c9d1c29eaf 100644 (file)
@@ -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: