]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
tweak stun handling
authorMichael Jerris <mike@jerris.com>
Thu, 7 Feb 2008 18:54:20 +0000 (18:54 +0000)
committerMichael Jerris <mike@jerris.com>
Thu, 7 Feb 2008 18:54:20 +0000 (18:54 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7543 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index 79e4bbb62347910737ee2e1f7d5448ff1bdf16cb..13806ac809247a3d698c0e099b2ff2d621b12375 100644 (file)
@@ -997,10 +997,9 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                                        char *ip = mod_sofia_globals.guess_ip;
                                                        switch_port_t port = 0;
                                                        if (sofia_glue_ext_address_lookup(&ip, &port, val, profile->pool) == SWITCH_STATUS_SUCCESS) {
-
-                                                               if (ip) {
-                                                                       profile->extsipip = switch_core_strdup(profile->pool, ip);
-                                                               }
+                                                               profile->extsipip = switch_core_strdup(profile->pool, ip);
+                                                       } else {
+                                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to get external ip.\n");
                                                        }
                                                }
                                        } else if (!strcasecmp(var, "force-register-domain")) {
index 660b7475bd431674141d5745d08f3e7bd9095550..442d3116d3a0827e041793fbb0b86d10d5ba79bd 100644 (file)
@@ -403,31 +403,35 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
 
 switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool)
 {
-       char *error;
-       switch_status_t status;
+       char *error = "";
+       switch_status_t status = SWITCH_STATUS_FALSE;
        int x;
 
        if (!sourceip) {
-               return SWITCH_STATUS_FALSE;
+               return status;
        }
 
        if (!strncasecmp(sourceip, "stun:", 5)) {
+               char *stun_ip = sourceip + 5;
+               if (!stun_ip) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! NO STUN SERVER\n");
+                       return status;
+               }
                for (x = 0; x < 5; x++) {
-                       char *stun_ip = sourceip + 5;
-                       if (!stun_ip) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! NO STUN SERVER\n");
-                               return SWITCH_STATUS_FALSE;
-                       }
                        if ((status = switch_stun_lookup(ip, port, stun_ip, SWITCH_STUN_DEFAULT_PORT, &error, pool)) != SWITCH_STATUS_SUCCESS) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip, SWITCH_STUN_DEFAULT_PORT, error);
                                switch_yield(100000);
                        } else {
                                break;
                        }
                }
                if (status != SWITCH_STATUS_SUCCESS) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip, SWITCH_STUN_DEFAULT_PORT, error);
                        return status;
                }
+               if (!*ip) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! No IP returned\n");
+                       return SWITCH_STATUS_FALSE;
+               }
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stun Success [%s]:[%d]\n", *ip, *port);
        } else {
                *ip = sourceip;