]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add some very basic stun support to ext-sip-ip. please consider this support as...
authorMichael Jerris <mike@jerris.com>
Thu, 8 Mar 2007 20:05:09 +0000 (20:05 +0000)
committerMichael Jerris <mike@jerris.com>
Thu, 8 Mar 2007 20:05:09 +0000 (20:05 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4484 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.c

index 97b6e59544aa13bbbe3fe77ef7cc053e43914e29..9a8ea96448ef5299cf67683fd20a6c27b42dbcc3 100644 (file)
@@ -927,12 +927,46 @@ static void terminate_session(switch_core_session_t **session, switch_call_cause
 }
 
 
+
+static switch_status_t sofia_ext_address_lookup(char **ip, 
+                                                                                                 switch_port_t *port,
+                                                                                                 char *sourceip,
+                                                                                                 switch_memory_pool_t *pool)
+{
+       char *error;
+       
+       if (!sourceip) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       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 SWITCH_STATUS_FALSE;
+               }
+               if (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);
+                       return SWITCH_STATUS_FALSE;
+               }
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Stun Success [%s]:[%d]\n", *ip, *port);
+       } else {
+               *ip = sourceip;
+       }
+       return SWITCH_STATUS_SUCCESS;
+}
+
+
 static switch_status_t tech_choose_port(private_object_t *tech_pvt)
 {
        char *ip = tech_pvt->profile->rtpip;
        switch_channel_t *channel;
        switch_port_t sdp_port;
-       char *err;
        char tmp[50];
 
        channel = switch_core_session_get_channel(tech_pvt->session);
@@ -945,28 +979,13 @@ static switch_status_t tech_choose_port(private_object_t *tech_pvt)
        tech_pvt->local_sdp_audio_port = switch_rtp_request_port();
        sdp_port = tech_pvt->local_sdp_audio_port;
 
-
        if (tech_pvt->profile->extrtpip) {
-               if (!strncasecmp(tech_pvt->profile->extrtpip, "stun:", 5)) {
-                       char *stun_ip = tech_pvt->profile->extrtpip + 5;
-                       if (!stun_ip) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! NO STUN SERVER\n");
-                               terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
-                               return SWITCH_STATUS_FALSE;
-                       }
-                       if (switch_stun_lookup(&ip,
-                                                                  &sdp_port,
-                                                                  stun_ip,
-                                                                  SWITCH_STUN_DEFAULT_PORT,
-                                                                  &err,
-                                                                  switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip, SWITCH_STUN_DEFAULT_PORT, err);
+               if (sofia_ext_address_lookup(&ip,
+                                                                       &sdp_port,
+                                                                       tech_pvt->profile->extrtpip,
+                                                                       switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
                                terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
                                return SWITCH_STATUS_FALSE;
-                       }
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Stun Success [%s]:[%d]\n", ip, sdp_port);
-               } else {
-                       ip = tech_pvt->profile->extrtpip;
                }
        }
 
@@ -5242,6 +5261,23 @@ static switch_status_t config_sofia(int reload)
                                                profile->rtpip = switch_core_strdup(profile->pool, strcasecmp(val, "auto") ? val : globals.guess_ip);
                                        } else if (!strcasecmp(var, "sip-ip")) {
                                                profile->sipip = switch_core_strdup(profile->pool, strcasecmp(val, "auto") ? val : globals.guess_ip);
+                                       } else if (!strcasecmp(var, "ext-sip-ip")) {
+                                               if (!strcasecmp(val, "auto")) {
+                                                       profile->extsipip = switch_core_strdup(profile->pool, globals.guess_ip);
+                                               } else {
+                                                       char *ip = NULL;
+                                                       switch_port_t port = 0;
+                                                       if (sofia_ext_address_lookup(&ip,
+                                                                                                               &port,
+                                                                                                               val,
+                                                                                                               profile->pool) == SWITCH_STATUS_SUCCESS) {
+
+                                                               if (ip) {
+                                                                       profile->extsipip = switch_core_strdup(profile->pool, ip);
+                                                               }
+                                                       }
+                                               }
+
                                        } else if (!strcasecmp(var, "sip-domain")) {
                                                profile->sipdomain = switch_core_strdup(profile->pool, val);
                                        } else if (!strcasecmp(var, "rtp-timer-name")) {
@@ -5276,8 +5312,6 @@ static switch_status_t config_sofia(int reload)
                                                if (switch_true(val)) {
                                                        profile->pflags |= PFLAG_FULL_ID;
                                                }
-                                       } else if (!strcasecmp(var, "ext-sip-ip")) {
-                                               profile->extsipip = switch_core_strdup(profile->pool, strcasecmp(val, "auto") ? val : globals.guess_ip);
                                        } else if (!strcasecmp(var, "bitpacking")) {
                                                if (!strcasecmp(val, "aal2")) {
                                                        profile->codec_flags = SWITCH_CODEC_FLAG_AAL2;