From brian at freeswitch.org Tue Jun 2 13:57:55 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 15:57:55 -0500 Subject: [Freeswitch-branches] [commit] r13552 - freeswitch/branches/brian/trunk Message-ID: Author: brian Date: Tue Jun 2 15:57:54 2009 New Revision: 13552 Log: branch for nat testing Added: freeswitch/branches/brian/trunk/ - copied from r13551, /freeswitch/trunk/ From brian at freeswitch.org Tue Jun 2 14:02:48 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 16:02:48 -0500 Subject: [Freeswitch-branches] [commit] r13553 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 16:02:47 2009 New Revision: 13553 Log: adding NAT patch to my branch so others can help Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Tue Jun 2 16:02:47 2009 @@ -394,6 +394,7 @@ if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), + TAG_IF(!switch_strlen_zero(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END()); } @@ -407,7 +408,6 @@ nua_cancel(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), - TAG_IF(!switch_strlen_zero(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END()); } } else { @@ -2644,6 +2644,9 @@ } } else { + char *dup_dest = NULL, *dest_host, *dest_user; + + if (!(dest = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; @@ -2661,10 +2664,17 @@ profile_name = profile->domain_name; } + dup_dest = strdup(dest); + switch_assert(dup_dest != NULL); + sofia_glue_get_user_host(dup_dest, &dest_user, &dest_host); + tech_pvt->remote_ip = switch_core_session_sprintf(nsession, "%s", dest_host); + switch_safe_free(dup_dest); + if (!strncasecmp(dest, "sip:", 4) || !strncasecmp(dest, "sips:", 5)) { tech_pvt->dest = switch_core_session_strdup(nsession, dest); } else if ((host = strchr(dest, '%'))) { char buf[128]; + *host = '@'; tech_pvt->e_dest = switch_core_session_strdup(nsession, dest); *host++ = '\0'; @@ -2678,6 +2688,7 @@ } } else if (!(host = strchr(dest, '@'))) { char buf[128]; + tech_pvt->e_dest = switch_core_session_strdup(nsession, dest); if (sofia_reg_find_reg_url(profile, dest, profile_name, buf, sizeof(buf))) { tech_pvt->dest = switch_core_session_strdup(nsession, buf); @@ -3217,6 +3228,8 @@ mod_sofia_globals.running = 1; switch_mutex_unlock(mod_sofia_globals.mutex); + mod_sofia_globals.auto_nat = (switch_core_get_variable("nat_type") ? 1 : 0); + switch_queue_create(&mod_sofia_globals.presence_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool); switch_queue_create(&mod_sofia_globals.mwi_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Tue Jun 2 16:02:47 2009 @@ -192,6 +192,7 @@ PFLAG_MESSAGE_QUERY_ON_REGISTER, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE, PFLAG_PROXY_FOLLOW_REDIRECT, + PFLAG_AUTO_NAT, /* No new flags below this line */ PFLAG_MAX } PFLAGS; @@ -272,6 +273,7 @@ char guess_mask_str[16]; int debug_presence; int auto_restart; + int auto_nat; }; extern struct mod_sofia_globals mod_sofia_globals; @@ -408,9 +410,13 @@ char *extsipip; char *username; char *url; + char *public_url; char *bindurl; char *tls_url; + char *tls_public_url; char *tls_bindurl; + char *tcp_public_contact; + char *tls_public_contact; char *tcp_contact; char *tls_contact; char *sla_contact; @@ -489,6 +495,7 @@ uint32_t timer_t2; uint32_t timer_t4; char *contact_user; + char *local_network; }; struct private_object { @@ -613,6 +620,7 @@ switch_rtp_bug_flag_t rtp_bugs; switch_codec_implementation_t read_impl; switch_codec_implementation_t write_impl; + char *user_via; }; struct callback_t { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Tue Jun 2 16:02:47 2009 @@ -766,6 +766,7 @@ sofia_event_callback, /* Callback for processing events */ profile, /* Additional data to pass to callback */ NUTAG_URL(profile->bindurl), + NTATAG_USER_VIA(1), TAG_IF(!strchr(profile->sipip, ':'), SOATAG_AF(SOA_AF_IP4_ONLY)), TAG_IF(strchr(profile->sipip, ':'), SOATAG_AF(SOA_AF_IP6_ONLY)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_SIPS_URL(profile->tls_bindurl)), @@ -1759,6 +1760,8 @@ } } else if(!strcasecmp(var, "context")) { profile->context = switch_core_strdup(profile->pool, val); + } else if (!strcasecmp(var, "local-network-acl")) { + profile->local_network = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "force-register-domain")) { profile->reg_domain = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "force-register-db-domain")) { @@ -2163,8 +2166,11 @@ if (!strcmp(val, "0.0.0.0")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip); + } else if (!strcasecmp(val, "auto-nat")) { + ip = mod_sofia_globals.auto_nat ? switch_core_get_variable("nat_public_addr") : mod_sofia_globals.guess_ip; + sofia_set_pflag(profile, PFLAG_AUTO_NAT); } else { - ip = strcasecmp(val, "auto") ? val : mod_sofia_globals.guess_ip; + ip = strcasecmp(val, "auto") ? val : mod_sofia_globals.guess_ip; } profile->extrtpip = switch_core_strdup(profile->pool, ip); } else { @@ -2198,6 +2204,9 @@ if (!strcasecmp(val, "0.0.0.0")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip); + } else if (!strcasecmp(val, "auto-nat")) { + ip = mod_sofia_globals.auto_nat ? switch_core_get_variable("nat_public_addr") : mod_sofia_globals.guess_ip; + sofia_set_pflag(profile, PFLAG_AUTO_NAT); } else if (strcasecmp(val, "auto")) { switch_port_t port = 0; if (sofia_glue_ext_address_lookup(profile, NULL, &myip, &port, val, profile->pool) == SWITCH_STATUS_SUCCESS) { @@ -2210,6 +2219,8 @@ } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ext-sip-ip\n"); } + } else if (!strcasecmp(var, "local-network-acl")) { + profile->local_network = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "force-register-domain")) { profile->reg_domain = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "force-register-db-domain")) { @@ -2264,7 +2275,7 @@ } else if (!strcasecmp(var, "manage-shared-appearance")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE); - profile->sla_contact = switch_core_sprintf(profile->pool, "sip:sla-agent@%s", profile->sipip); + profile->sla_contact = switch_core_sprintf(profile->pool, "sla-agent"); } } else if (!strcasecmp(var, "disable-srv")) { if (switch_true(val)) { @@ -2548,7 +2559,18 @@ if (!profile->sipdomain) { profile->sipdomain = switch_core_strdup(profile->pool, profile->sipip); } - if (profile->extsipip) { + if (profile->extsipip && sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + char *ipv6 = strchr(profile->extsipip, ':'); + profile->public_url = switch_core_sprintf(profile->pool, + "sip:%s@%s%s%s:%d", + profile->contact_user, + ipv6 ? "[" : "", + profile->extsipip, + ipv6 ? "]" : "", + profile->sip_port); + } + + if (profile->extsipip && !sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { char *ipv6 = strchr(profile->extsipip, ':'); profile->url = switch_core_sprintf(profile->pool, "sip:%s@%s%s%s:%d", @@ -2571,7 +2593,11 @@ } profile->tcp_contact = switch_core_sprintf(profile->pool, "%s;transport=tcp", profile->url); - + + if(sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + profile->tcp_public_contact = switch_core_sprintf(profile->pool, "%s;transport=tcp", profile->public_url); + } + if (profile->bind_params) { char *bindurl = profile->bindurl; profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", bindurl, profile->bind_params); @@ -2585,7 +2611,18 @@ profile->tls_sip_port = atoi(SOFIA_DEFAULT_TLS_PORT); } - if (profile->extsipip) { + if (profile->extsipip && sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + char *ipv6 = strchr(profile->extsipip, ':'); + profile->tls_public_url = switch_core_sprintf(profile->pool, + "sip:%s@%s%s%s:%d", + profile->contact_user, + ipv6 ? "[" : "", + profile->extsipip, + ipv6 ? "]" : "", + profile->tls_sip_port); + } + + if (profile->extsipip && !sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { char *ipv6 = strchr(profile->extsipip, ':'); profile->tls_url = switch_core_sprintf(profile->pool, @@ -2632,6 +2669,9 @@ profile->tls_cert_dir = switch_core_sprintf(profile->pool, "%s/ssl", SWITCH_GLOBAL_dirs.conf_dir); } profile->tls_contact = switch_core_sprintf(profile->pool, "%s;transport=tls", profile->tls_url); + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + profile->tls_public_contact = switch_core_sprintf(profile->pool, "%s;transport=tls", profile->tls_public_url); + } } } if (profile) { @@ -4309,6 +4349,7 @@ get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); + if (sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION)) { if (sip && sip->sip_via) { const char *port = sip->sip_via->v_port; @@ -4428,6 +4469,12 @@ tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip); tech_pvt->remote_port = network_port; + + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { + sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); + tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), + profile->extsipip); + } channel = tech_pvt->channel = switch_core_session_get_channel(session); @@ -4626,7 +4673,8 @@ const char *url; - if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url)) { + if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : + (switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) ? profile->url : profile->public_url)) { if (strchr(url, '>')) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); } else { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Tue Jun 2 16:02:47 2009 @@ -642,15 +642,16 @@ switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port); } - tech_pvt->local_sdp_audio_ip = ip; + if (!(tech_pvt->local_sdp_audio_port = switch_rtp_request_port(tech_pvt->profile->rtpip))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No RTP ports available!\n"); return SWITCH_STATUS_FALSE; } + sdp_port = tech_pvt->local_sdp_audio_port; - if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_audio_ip"))) { + if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_audio_ip")) && !sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { if (tech_pvt->profile->extrtpip) { use_ip = tech_pvt->profile->extrtpip; } @@ -663,9 +664,24 @@ return SWITCH_STATUS_FALSE; } } - - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); + if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); + } else { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); + } + } else { + + if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); + } else { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); + } + } + tech_pvt->adv_sdp_audio_port = sdp_port; switch_snprintf(tmp, sizeof(tmp), "%d", sdp_port); @@ -1257,10 +1273,19 @@ check_decode(cid_num, session); if (!tech_pvt->from_str) { - const char* sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; - const char* format = strchr(sipip, ':') ? "\"%s\" " : "\"%s\" "; + const char* sipip; + const char* format; const char *alt = NULL; + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { + sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) + ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; + } else { + sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; + } + + format = strchr(sipip, ':') ? "\"%s\" " : "\"%s\" "; + if ((alt = switch_channel_get_variable(channel, "sip_invite_domain"))) { sipip = alt; } @@ -1303,7 +1328,7 @@ const char *invite_from_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_from_params"); const char *from_var = switch_channel_get_variable(tech_pvt->channel, "sip_from_uri"); const char *from_display = switch_channel_get_variable(tech_pvt->channel, "sip_from_display"); - + if (switch_strlen_zero(tech_pvt->dest)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "URL Error!\n"); return SWITCH_STATUS_FALSE; @@ -1365,6 +1390,13 @@ tech_pvt->transport = SOFIA_TRANSPORT_UDP; } } + + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + const char *transport = sofia_glue_transport2str(tech_pvt->transport); + tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", + transport, tech_pvt->profile->extsipip); + } + if (!sofia_test_pflag(tech_pvt->profile, PFLAG_TLS) && sofia_glue_transport_has_tls(tech_pvt->transport)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "TLS not supported by profile\n"); @@ -1374,8 +1406,18 @@ if (switch_strlen_zero(tech_pvt->invite_contact)) { const char * contact; if ((contact = switch_channel_get_variable(channel, "sip_contact_user"))) { - char *ip_addr = (tech_pvt->profile->extsipip) ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; - char *ipv6 = strchr(ip_addr, ':'); + char *ip_addr; + char *ipv6; + + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { + ip_addr = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) + ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; + } else { + ip_addr = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; + } + + ipv6 = strchr(ip_addr, ':'); + if (sofia_glue_transport_has_tls(tech_pvt->transport)) { tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact, ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", @@ -1388,7 +1430,12 @@ if (sofia_glue_transport_has_tls(tech_pvt->transport)) { tech_pvt->invite_contact = tech_pvt->profile->tls_url; } else { - tech_pvt->invite_contact = tech_pvt->profile->url; + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + tech_pvt->invite_contact = tech_pvt->profile->public_url; + } else { + tech_pvt->invite_contact = tech_pvt->profile->url; + } } } } @@ -1603,6 +1650,7 @@ nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(!switch_strlen_zero(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_IF(!switch_strlen_zero(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid)), TAG_IF(!switch_strlen_zero(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id)), TAG_IF(!switch_strlen_zero(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id)), @@ -1630,14 +1678,23 @@ private_object_t *tech_pvt = switch_core_session_get_private(session); switch_channel_t *channel = switch_core_session_get_channel(session); switch_caller_profile_t *caller_profile; - const char *sipip, *format; + const char *sipip, *format, *contact_url; switch_assert(tech_pvt != NULL); switch_mutex_lock(tech_pvt->sofia_mutex); caller_profile = switch_channel_get_caller_profile(channel); - sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { + sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) + ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; + contact_url = tech_pvt->profile->public_url; + } else { + sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; + contact_url = tech_pvt->profile->url; + } + format = strchr(sipip, ':') ? "\"%s\" " : "\"%s\" "; + if ((tech_pvt->from_str = switch_core_session_sprintf(session, format, caller_profile->caller_id_name, caller_profile->caller_id_number, sipip))) { @@ -1646,12 +1703,15 @@ tech_pvt->nh2 = nua_handle(tech_pvt->profile->nua, NULL, SIPTAG_TO_STR(tech_pvt->dest), - SIPTAG_FROM_STR(tech_pvt->from_str), SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END()); + SIPTAG_FROM_STR(tech_pvt->from_str), + SIPTAG_CONTACT_STR(contact_url), + TAG_END()); nua_handle_bind(tech_pvt->nh2, tech_pvt->sofia_private); nua_invite(tech_pvt->nh2, - SIPTAG_CONTACT_STR(tech_pvt->profile->url), + SIPTAG_CONTACT_STR(contact_url), + TAG_IF(!switch_strlen_zero(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Tue Jun 2 16:02:47 2009 @@ -306,12 +306,10 @@ for_everyone = 1; } - dup_account = strdup(account); switch_assert(dup_account != NULL); sofia_glue_get_user_host(dup_account, &user, &host); - if ((pname = switch_event_get_header(event, "sofia-profile"))) { if (!(profile = sofia_glue_find_profile(pname))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No profile %s\n", pname); @@ -375,11 +373,11 @@ } if (for_everyone) { - sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q' " + sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' " "from sip_registrations where sip_user='%q' and sip_host='%q'", stream.data, user, host); } else if (call_id) { - sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q' " + sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' " "from sip_registrations where sip_user='%q' and sip_host='%q' and call_id='%q'", stream.data, user, host, call_id); } @@ -1363,7 +1361,7 @@ profile = ext_profile; } } - + if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) { if (profile->debug) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id); @@ -1379,7 +1377,10 @@ nua_handle_bind(nh, &mod_sofia_globals.keep_private); nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR("active"), - SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END()); + SIPTAG_EVENT_STR(event), + SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), + SIPTAG_PAYLOAD_STR(body), + TAG_END()); switch_safe_free(id); @@ -1401,13 +1402,14 @@ char *event = "message-summary"; char *contact, *o_contact = argv[2]; char *profile_name = argv[3]; - char *body = argv[4]; + char *network_ip = argv[4]; + char *body = argv[5]; char *id = NULL; nua_handle_t *nh; struct mwi_helper *h = (struct mwi_helper *) pArg; sofia_profile_t *ext_profile = NULL, *profile = h->profile; - char *route = NULL, *route_uri = NULL; - char *p; + char *route = NULL, *route_uri = NULL, *user_via = NULL; + char *p, *contact_str; if (profile_name && strcasecmp(profile_name, h->profile->name)) { if ((ext_profile = sofia_glue_find_profile(profile_name))) { @@ -1415,9 +1417,24 @@ } } - id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host); + id = switch_mprintf("sip:%s@%s", sub_to_user, switch_check_network_list_ip(network_ip, profile->local_network) ? sub_to_host : profile->extsipip); contact = sofia_glue_get_url_from_contact(o_contact, 1); + + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + char *ptr = NULL; + if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { + sofia_transport_t transport = sofia_glue_str2transport(ptr); + user_via = switch_mprintf("SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), profile->extsipip); + printf("user_via -> %s\n", user_via); + } else { + user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); + } + + contact_str = profile->public_url; + } else { + contact_str = profile->url; + } if ((route = strstr(contact, ";fs_path=")) && (route = strdup(route + 9))) { for (p = route; p && *p ; p++) { @@ -1455,17 +1472,23 @@ } } - nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(h->profile->url), TAG_END()); + nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), + SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), + SIPTAG_CONTACT_STR(contact_str), TAG_END()); nua_handle_bind(nh, &mod_sofia_globals.destroy_private); nua_notify(nh, NUTAG_NEWSUB(1), TAG_IF(route_uri, NUTAG_PROXY(route_uri)), - SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END()); + TAG_IF(!switch_strlen_zero(user_via), SIPTAG_VIA_STR(user_via)), + SIPTAG_EVENT_STR(event), + SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), + SIPTAG_PAYLOAD_STR(body), TAG_END()); switch_safe_free(contact); switch_safe_free(id); switch_safe_free(route); + switch_safe_free(user_via); if (ext_profile) { sofia_glue_release_profile(ext_profile); } @@ -1508,6 +1531,7 @@ char *port; char new_port[25] = ""; char *is_nat = NULL; + int is_auto_nat = 0; const char *ipv6; if (!(contact && sip->sip_contact->m_url)) { @@ -1518,6 +1542,10 @@ get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + is_auto_nat = 1; + } + tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END()); event = sip_header_as_string(profile->home, (void *) sip->sip_event); @@ -1777,25 +1805,41 @@ network_port, params); } + + + if (is_auto_nat) { + contactstr = profile->public_url; + } else { + contactstr = profile->url; + } + if (switch_stristr("port=tcp", contact->m_url->url_params)) { - contactstr = profile->tcp_contact; + if (is_auto_nat) { + contactstr = profile->tcp_public_contact; + } else { + contactstr = profile->tcp_contact; + } } else if (switch_stristr("port=tls", contact->m_url->url_params)) { - contactstr = profile->tls_contact; + if (is_auto_nat) { + contactstr = profile->tls_contact; + } else { + contactstr = profile->tls_public_contact; + } } - if (nh && nh->nh_ds && nh->nh_ds->ds_usage) { nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP); } - nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(contactstr), NUTAG_WITH_THIS(nua), + nua_respond(nh, SIP_202_ACCEPTED, + SIPTAG_CONTACT_STR(contactstr), + NUTAG_WITH_THIS(nua), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EXPIRES_STR(exp_delta_str), TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END()); switch_safe_free(sticky); - } sent_reply++; Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Tue Jun 2 16:02:47 2009 @@ -76,6 +76,12 @@ struct sla_helper sh = { { 0 } }; char *contact_str = strip_uri(full_contact); sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); + su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); + char network_ip[80]; + int network_port = 0; + + get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); + network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'", mod_sofia_globals.hostname, profile->name, contact_str); @@ -99,8 +105,13 @@ nua_handle_bind(nh, &mod_sofia_globals.keep_private); switch_snprintf(exp_str, sizeof(exp_str), "%ld", exptime + 30); - switch_snprintf(my_contact, sizeof(my_contact), "<%s;transport=%s>;expires=%s", profile->sla_contact, sofia_glue_transport2str(transport), exp_str); - + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + switch_snprintf(my_contact, sizeof(my_contact), ";expires=%s", profile->sla_contact, + profile->extsipip, sofia_glue_transport2str(transport), exp_str); + } else { + switch_snprintf(my_contact, sizeof(my_contact), ";expires=%s", profile->sla_contact, + profile->sipip, sofia_glue_transport2str(transport), exp_str); + } nua_subscribe(nh, SIPTAG_TO(sip->sip_to), SIPTAG_FROM(sip->sip_to), @@ -125,8 +136,14 @@ char *sql = NULL; char *route_uri = NULL; char *sla_contact = NULL; + su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); + char network_ip[80]; + int network_port = 0; sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); + + get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); + network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); /* * XXX MTK FIXME - we don't look at the tag to see if NUTAG_SUBSTATE(nua_substate_terminated) or * a Subscription-State header with state "terminated" and/or expiration of 0. So we never forget @@ -187,8 +204,12 @@ *p++ = '\0'; } } - - sla_contact = switch_mprintf("<%s;transport=%s>", profile->sla_contact, sofia_glue_transport2str(transport)); + + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + sla_contact = switch_mprintf("", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport)); + } else { + sla_contact = switch_mprintf("", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport)); + } nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(sla_contact), NUTAG_WITH_THIS(nua), TAG_IF(route_uri, NUTAG_PROXY(route_uri)), From brian at freeswitch.org Tue Jun 2 14:49:39 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 16:49:39 -0500 Subject: [Freeswitch-branches] [commit] r13554 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 16:49:39 2009 New Revision: 13554 Log: tweak sla to work inside out Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Tue Jun 2 16:49:39 2009 @@ -3547,7 +3547,8 @@ " aor VARCHAR(255),\n" " profile_name VARCHAR(255),\n" " hostname VARCHAR(255),\n" - " contact_str VARCHAR(255)\n" + " contact_str VARCHAR(255),\n" + " network_ip VARCHAR(255)\n" ");\n"; char shared_appearance_dialogs_sql[] = Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Tue Jun 2 16:49:39 2009 @@ -159,7 +159,7 @@ */ aor = switch_mprintf("sip:%s@%s;transport=%s", sip->sip_contact->m_url->url_user, - sip->sip_from->a_url->url_host, sofia_glue_transport2str(transport)); + profile->sipip, sofia_glue_transport2str(transport)); /* * ok, and now that we HAVE the AOR, we REALLY should go check in the XML config and see if this particular @@ -180,9 +180,9 @@ } if ((sql = - switch_mprintf("insert into sip_shared_appearance_subscriptions (subscriber, call_id, aor, profile_name, hostname, contact_str) " - "values ('%q','%q','%q','%q','%q','%q')", - subscriber, sip->sip_call_id->i_id, aor, profile->name, mod_sofia_globals.hostname, contact_str))) { + switch_mprintf("insert into sip_shared_appearance_subscriptions (subscriber, call_id, aor, profile_name, hostname, contact_str, network_ip) " + "values ('%q','%q','%q','%q','%q','%q','%q')", + subscriber, sip->sip_call_id->i_id, aor, profile->name, mod_sofia_globals.hostname, contact_str, network_ip))) { sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); } @@ -298,7 +298,7 @@ /* calculate the AOR we're trying to tell people about. should probably double-check before derferencing XXX MTK */ aor = switch_mprintf("sip:%s@%s;transport=%s", sip->sip_to->a_url->url_user, - sip->sip_to->a_url->url_host, sofia_glue_transport2str(transport)); + profile->sipip, sofia_glue_transport2str(transport)); /* this isn't sufficient because on things like the polycom, the subscriber is the 'main' ext number, but the * 'main' ext number isn't in ANY of the headers they send us in the notify. of course. @@ -312,8 +312,10 @@ if (sip->sip_payload && sip->sip_payload->pl_data) { sql = switch_mprintf("select subscriber,call_id,aor,profile_name,hostname,contact_str from sip_shared_appearance_subscriptions where " - "aor='%q' and subscriber<>'%q' and profile_name='%q' and hostname='%q'", - aor, contact, profile->name, mod_sofia_globals.hostname); + "aor='%q' and profile_name='%q' and hostname='%q'", + aor, profile->name, mod_sofia_globals.hostname); + printf("WTF %s\n", sql); + helper.profile = profile; @@ -340,7 +342,6 @@ nua_handle_t *nh; char *route_uri = NULL; - nh = nua_handle_by_call_id(helper->profile->nua, call_id); /* that's all you need to find the subscription's nh */ if (nh) { From brian at freeswitch.org Tue Jun 2 14:51:25 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 16:51:25 -0500 Subject: [Freeswitch-branches] [commit] r13555 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 16:51:25 2009 New Revision: 13555 Log: tweak sla to work inside out Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Tue Jun 2 16:51:25 2009 @@ -158,6 +158,7 @@ * so we do what openser's pua_bla does and... */ + /* We always store the AOR as the sipip and not the request so SLA works with NAT inside out */ aor = switch_mprintf("sip:%s@%s;transport=%s", sip->sip_contact->m_url->url_user, profile->sipip, sofia_glue_transport2str(transport)); @@ -297,6 +298,7 @@ } /* calculate the AOR we're trying to tell people about. should probably double-check before derferencing XXX MTK */ + /* We always store the AOR as the sipip and not the request so SLA works with NAT inside out */ aor = switch_mprintf("sip:%s@%s;transport=%s", sip->sip_to->a_url->url_user, profile->sipip, sofia_glue_transport2str(transport)); @@ -314,9 +316,6 @@ sql = switch_mprintf("select subscriber,call_id,aor,profile_name,hostname,contact_str from sip_shared_appearance_subscriptions where " "aor='%q' and profile_name='%q' and hostname='%q'", aor, profile->name, mod_sofia_globals.hostname); - printf("WTF %s\n", sql); - - helper.profile = profile; helper.payload = sip->sip_payload->pl_data; /* could just send the WHOLE payload. you'd get the type that way. */ From brian at freeswitch.org Tue Jun 2 16:02:13 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 18:02:13 -0500 Subject: [Freeswitch-branches] [commit] r13558 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 18:02:13 2009 New Revision: 13558 Log: patch the XML so that if it happens to traverse nat it'll display the pickup and barge correctly for the phone Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Tue Jun 2 18:02:13 2009 @@ -1426,7 +1426,6 @@ if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { sofia_transport_t transport = sofia_glue_str2transport(ptr); user_via = switch_mprintf("SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), profile->extsipip); - printf("user_via -> %s\n", user_via); } else { user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Tue Jun 2 18:02:13 2009 @@ -313,7 +313,7 @@ sip->sip_contact->m_url->url_host, sofia_glue_transport2str(transport)); if (sip->sip_payload && sip->sip_payload->pl_data) { - sql = switch_mprintf("select subscriber,call_id,aor,profile_name,hostname,contact_str from sip_shared_appearance_subscriptions where " + sql = switch_mprintf("select subscriber,call_id,aor,profile_name,hostname,contact_str,network_ip from sip_shared_appearance_subscriptions where " "aor='%q' and profile_name='%q' and hostname='%q'", aor, profile->name, mod_sofia_globals.hostname); @@ -338,9 +338,10 @@ /* char *profile_name = argv[3]; */ /* char *hostname = argv[4]; */ char *contact_str = argv[5]; + char *network_ip = argv[6]; nua_handle_t *nh; char *route_uri = NULL; - + char *xml_fixup = NULL; nh = nua_handle_by_call_id(helper->profile->nua, call_id); /* that's all you need to find the subscription's nh */ if (nh) { @@ -363,14 +364,23 @@ *p++ = '\0'; } } - + + if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, helper->profile->local_network)) { + xml_fixup = switch_string_replace(helper->payload, helper->profile->sipip, helper->profile->extsipip); + } else if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT) && switch_check_network_list_ip(network_ip, helper->profile->local_network)) { + xml_fixup = switch_string_replace(helper->payload, helper->profile->extsipip, helper->profile->sipip); + } else { + xml_fixup = helper->payload; + } + nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=300"), /* XXX MTK FIXME - this is totally fake calculation */ TAG_IF(route_uri, NUTAG_PROXY(route_uri)), SIPTAG_CONTENT_TYPE_STR("application/dialog-info+xml"), /* could've just kept the type from the payload */ - SIPTAG_PAYLOAD_STR(helper->payload), + SIPTAG_PAYLOAD_STR(xml_fixup), TAG_END()); switch_safe_free(route_uri); + switch_safe_free(xml_fixup); } return 0; } From brian at freeswitch.org Tue Jun 2 16:42:44 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 18:42:44 -0500 Subject: [Freeswitch-branches] [commit] r13559 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 18:42:43 2009 New Revision: 13559 Log: reboot packets now work correctly Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Tue Jun 2 18:42:43 2009 @@ -843,7 +843,7 @@ const char *sofia_glue_strip_proto(const char *uri); switch_status_t reconfig_sofia(sofia_profile_t *profile); void sofia_glue_del_gateway(sofia_gateway_t *gp); -void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent); +void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip); void sofia_glue_restart_all_profiles(void); void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly); const char * sofia_state_string(int state); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Tue Jun 2 18:42:43 2009 @@ -1423,17 +1423,28 @@ if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { char *ptr = NULL; + const char *transport_str = NULL; if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { sofia_transport_t transport = sofia_glue_str2transport(ptr); - user_via = switch_mprintf("SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), profile->extsipip); + transport_str = sofia_glue_transport2str(transport); + user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); } else { user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); } - - contact_str = profile->public_url; + + if (switch_stristr("udp", transport_str)) { + contact_str = profile->public_url; + } else if (switch_stristr("tcp", transport_str)) { + contact_str = profile->tcp_public_contact; + } else if (switch_stristr("tls", transport_str)) { + contact_str = profile->tls_public_contact; + } else { + contact_str = profile->public_url; + } } else { contact_str = profile->url; } + if ((route = strstr(contact, ";fs_path=")) && (route = strdup(route + 9))) { for (p = route; p && *p ; p++) { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Tue Jun 2 18:42:43 2009 @@ -402,11 +402,13 @@ return 0; } -void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent) +void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip) { const char *event = "check-sync"; nua_handle_t *nh; char *contact_url = NULL; + char *contact_str = NULL; + char *user_via = NULL; char *id = NULL; if (switch_stristr("snom", user_agent)) { @@ -417,22 +419,47 @@ if ((contact_url = sofia_glue_get_url_from_contact((char *)contact, 1))) { char *p; - id = switch_mprintf("sip:%s@%s", user, host); + id = switch_mprintf("sip:%s@%s", user, network_ip); if ((p = strstr(contact_url, ";fs_"))) { *p = '\0'; } - + + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + char *ptr = NULL; + const char *transport_str = NULL; + if ((ptr = sofia_glue_find_parameter(contact_url, "transport="))) { + sofia_transport_t transport = sofia_glue_str2transport(ptr); + transport_str = sofia_glue_transport2str(transport); + user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); + } else { + user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); + } + + if (switch_stristr("udp", transport_str)) { + contact_str = profile->public_url; + } else if (switch_stristr("tcp", transport_str)) { + contact_str = profile->tcp_public_contact; + } else if (switch_stristr("tls", transport_str)) { + contact_str = profile->tls_public_contact; + } else { + contact_str = profile->public_url; + } + } else { + contact_str = profile->url; + } + nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact_url), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), - SIPTAG_CONTACT_STR(profile->url), + SIPTAG_CONTACT_STR(contact_str), TAG_END()); nua_handle_bind(nh, &mod_sofia_globals.destroy_private); nua_notify(nh, NUTAG_NEWSUB(1), + TAG_IF(!switch_strlen_zero(user_via), SIPTAG_VIA_STR(user_via)), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(""), @@ -462,8 +489,8 @@ switch_event_t *s_event; sofia_profile_t *profile = (sofia_profile_t *) pArg; - if (argc > 11 && atoi(argv[11]) == 1) { - sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7]); + if (argc > 12 && atoi(argv[12]) == 1) { + sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]); } if (argc >= 3) { @@ -508,7 +535,8 @@ switch_snprintf(sqlextra, sizeof(sqlextra), " or (sip_user='%s' and sip_host='%s')", user, host); } - switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name" + switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires" + ",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where call_id='%s' %s", reboot, call_id, sqlextra); @@ -548,7 +576,8 @@ switch_mutex_lock(profile->ireg_mutex); if (now) { - switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name" + switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires" + ",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where expires > 0 and expires <= %ld", reboot, (long) now); } else { switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name" From brian at freeswitch.org Tue Jun 2 16:56:06 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 18:56:06 -0500 Subject: [Freeswitch-branches] [commit] r13560 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 18:56:06 2009 New Revision: 13560 Log: adding map and unmap of profile ports when AUTO_NAT is on Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Tue Jun 2 18:56:06 2009 @@ -762,6 +762,15 @@ use_timer ? "timer, " : "" ); + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s\n", profile->name); + } + if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s\n", profile->name); + } + } + profile->nua = nua_create(profile->s_root, /* Event loop */ sofia_event_callback, /* Callback for processing events */ profile, /* Additional data to pass to callback */ @@ -903,6 +912,16 @@ su_root_run(profile->s_root); sofia_clear_pflag_locked(profile, PFLAG_RUNNING); + + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s\n", profile->name); + } + if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s\n", profile->name); + } + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for worker thread\n"); switch_thread_join(&st, worker_thread); From brian at freeswitch.org Tue Jun 2 17:14:45 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 19:14:45 -0500 Subject: [Freeswitch-branches] [commit] r13561 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 19:14:44 2009 New Revision: 13561 Log: adding nat mapping and unmapping for audio and video rtp ports Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Tue Jun 2 19:14:44 2009 @@ -684,6 +684,10 @@ tech_pvt->adv_sdp_audio_port = sdp_port; + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); + } + switch_snprintf(tmp, sizeof(tmp), "%d", sdp_port); switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip); switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp); @@ -724,6 +728,10 @@ tech_pvt->adv_sdp_video_port = sdp_port; + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); + } + switch_snprintf(tmp, sizeof(tmp), "%d", sdp_port); switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip); switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, tmp); @@ -1821,12 +1829,21 @@ switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port); } + if (tech_pvt->local_sdp_audio_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP); + } + if (tech_pvt->video_rtp_session) { switch_rtp_destroy(&tech_pvt->video_rtp_session); } else if (tech_pvt->local_sdp_video_port) { switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_video_port); } + if (tech_pvt->local_sdp_video_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP); + } } switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force) From brian at freeswitch.org Tue Jun 2 17:19:55 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 19:19:55 -0500 Subject: [Freeswitch-branches] [commit] r13562 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 19:19:54 2009 New Revision: 13562 Log: OCD Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Tue Jun 2 19:19:54 2009 @@ -1777,7 +1777,7 @@ } else { sofia_clear_pflag(profile, PFLAG_AUTH_CALLS); } - } else if(!strcasecmp(var, "context")) { + } else if (!strcasecmp(var, "context")) { profile->context = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "local-network-acl")) { profile->local_network = switch_core_strdup(profile->pool, val); @@ -2613,7 +2613,7 @@ profile->tcp_contact = switch_core_sprintf(profile->pool, "%s;transport=tcp", profile->url); - if(sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { profile->tcp_public_contact = switch_core_sprintf(profile->pool, "%s;transport=tcp", profile->public_url); } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Tue Jun 2 19:19:54 2009 @@ -2557,7 +2557,7 @@ if (map->rm_pt < 96) { match = (map->rm_pt == imp->ianacode) ? 1 : 0; } else { - if(map->rm_encoding) { + if (map->rm_encoding) { match = strcasecmp(map->rm_encoding, imp->iananame) ? 0 : 1; } else { match = 0; @@ -2565,7 +2565,7 @@ } if (match) { - if(ptime > 0) { + if (ptime > 0) { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh@%di", imp->iananame, (unsigned int) map->rm_rate, ptime); } else { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh", imp->iananame, (unsigned int) map->rm_rate); @@ -2598,7 +2598,7 @@ if (map->rm_pt < 96) { match = (map->rm_pt == imp->ianacode) ? 1 : 0; } else { - if(map->rm_encoding) { + if (map->rm_encoding) { match = strcasecmp(map->rm_encoding, imp->iananame) ? 0 : 1; } else { match = 0; @@ -2606,7 +2606,7 @@ } if (match) { - if(ptime > 0) { + if (ptime > 0) { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh@%di", imp->iananame, (unsigned int) map->rm_rate, ptime); } else { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh", imp->iananame, (unsigned int) map->rm_rate); From brian at freeswitch.org Tue Jun 2 17:33:59 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 19:33:59 -0500 Subject: [Freeswitch-branches] [commit] r13563 - freeswitch/branches/brian/trunk/src Message-ID: Author: brian Date: Tue Jun 2 19:33:59 2009 New Revision: 13563 Log: merge trunk down Modified: freeswitch/branches/brian/trunk/src/switch_core.c freeswitch/branches/brian/trunk/src/switch_nat.c freeswitch/branches/brian/trunk/src/switch_xml.c Modified: freeswitch/branches/brian/trunk/src/switch_core.c ============================================================================== --- freeswitch/branches/brian/trunk/src/switch_core.c (original) +++ freeswitch/branches/brian/trunk/src/switch_core.c Tue Jun 2 19:33:59 2009 @@ -1176,6 +1176,12 @@ runtime.flags = flags; runtime.sps_total = 30; + *err = NULL; + + if (console) { + runtime.console = stdout; + } + switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET); switch_core_set_variable("local_ip_v4", guess_ip); switch_core_set_variable("local_mask_v4", inet_ntoa(*(struct in_addr *)&mask)); @@ -1188,25 +1194,21 @@ switch_event_init(runtime.memory_pool); - if (switch_test_flag((&runtime), SCF_USE_AUTO_NAT)) { - switch_nat_init(runtime.memory_pool); - } - if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) { apr_terminate(); return SWITCH_STATUS_MEMERR; } - switch_load_core_config("switch.conf"); - + if (switch_test_flag((&runtime), SCF_USE_AUTO_NAT)) { + switch_nat_init(runtime.memory_pool); + } + switch_log_init(runtime.memory_pool, runtime.colorize_console); - switch_core_state_machine_init(runtime.memory_pool); - *err = NULL; + switch_load_core_config("switch.conf"); - if (console) { - runtime.console = stdout; - } + + switch_core_state_machine_init(runtime.memory_pool); if (switch_test_flag((&runtime), SCF_USE_SQL)) { switch_core_sqldb_start(runtime.memory_pool); Modified: freeswitch/branches/brian/trunk/src/switch_nat.c ============================================================================== --- freeswitch/branches/brian/trunk/src/switch_nat.c (original) +++ freeswitch/branches/brian/trunk/src/switch_nat.c Tue Jun 2 19:33:59 2009 @@ -101,11 +101,11 @@ static int init_pmp(void) { - int r = 0; + int r = 0, i = 0, max = 5; natpmpresp_t response; char *pubaddr = NULL; fd_set fds; - struct timeval timeout; + initnatpmp(&nat_globals.natpmp); r = sendpublicaddressrequest(&nat_globals.natpmp); @@ -115,12 +115,16 @@ } do { + struct timeval timeout = { 1, 0}; + i++; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP %d/%d\n", i, max); + FD_ZERO(&fds); FD_SET(nat_globals.natpmp.s, &fds); getnatpmprequesttimeout(&nat_globals.natpmp, &timeout); select(FD_SETSIZE, &fds, NULL, NULL, &timeout); r = readnatpmpresponseorretry(&nat_globals.natpmp, &response); - } while(r == NATPMP_TRYAGAIN); + } while(r == NATPMP_TRYAGAIN && i < max); if (r < 0) { goto end; @@ -146,9 +150,13 @@ switch_find_local_ip(nat_globals.pvt_addr, sizeof(nat_globals.pvt_addr), NULL, AF_INET); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Scanning for NAT\n"); + init_pmp(); if (!nat_globals.nat_type) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPnP\n"); init_upnp(); } @@ -156,8 +164,9 @@ switch_core_set_variable("nat_public_addr", nat_globals.pub_addr); switch_core_set_variable("nat_private_addr", nat_globals.pvt_addr); switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s\n", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp"); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No PMP or uPNP NAT device detected!\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or UPnP NAT detected!\n"); } } Modified: freeswitch/branches/brian/trunk/src/switch_xml.c ============================================================================== --- freeswitch/branches/brian/trunk/src/switch_xml.c (original) +++ freeswitch/branches/brian/trunk/src/switch_xml.c Tue Jun 2 19:33:59 2009 @@ -1287,8 +1287,8 @@ char *bp = expand_vars(buf, ebuf, sizeof(ebuf), &cur, &err); line++; - if (err && stderr) { - fprintf(stderr, "Error [%s] in file %s line %d\n", err, file, line); + if (err) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s] in file %s line %d\n", err, file, line); } /* we ignore or for the sake of validators as well as type stuff */ From brian at freeswitch.org Tue Jun 2 18:19:15 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Tue, 02 Jun 2009 20:19:15 -0500 Subject: [Freeswitch-branches] [commit] r13564 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Tue Jun 2 20:19:14 2009 New Revision: 13564 Log: fix seggy fault Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Tue Jun 2 20:19:14 2009 @@ -580,7 +580,8 @@ ",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where expires > 0 and expires <= %ld", reboot, (long) now); } else { - switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name" + switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires" + ",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where expires > 0", reboot); } From brian at freeswitch.org Wed Jun 3 06:42:37 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 08:42:37 -0500 Subject: [Freeswitch-branches] [commit] r13565 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 08:42:37 2009 New Revision: 13565 Log: adding sanity checking if local_network happens to never be set. Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 08:42:37 2009 @@ -4489,7 +4489,8 @@ tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip); tech_pvt->remote_port = network_port; - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && + !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), profile->extsipip); @@ -4689,11 +4690,25 @@ if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "", user, host); } else { - const char *url; - if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : - (switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) ? profile->url : profile->public_url)) { + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && + !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { + + if (sofia_glue_transport_has_tls(transport)) { + url = profile->tls_public_url; + } else { + url = profile->public_url; + } + + if (strchr(url, '>')) { + tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, + sofia_glue_transport2str(transport)); + } else { + tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, + sofia_glue_transport2str(transport)); + } + } else if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url)) { if (strchr(url, '>')) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); } else { @@ -4706,8 +4721,24 @@ } } else { const char *url; - - if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url)) { + + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && + !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { + + if (sofia_glue_transport_has_tls(transport)) { + url = profile->tls_public_url; + } else { + url = profile->public_url; + } + + if (strchr(url, '>')) { + tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, + sofia_glue_transport2str(transport)); + } else { + tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", url, + sofia_glue_transport2str(transport)); + } + } else if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url)) { if (strchr(url, '>')) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); } else { @@ -4718,7 +4749,7 @@ } } } - + if (sip->sip_contact && sip->sip_contact->m_url) { const char *contact_uri = url_set_chanvars(session, sip->sip_contact->m_url, sip_contact); if (!channel_name) { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 08:42:37 2009 @@ -666,15 +666,14 @@ } if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); } else { tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); } } else { - - if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); } else { @@ -716,11 +715,12 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No RTP ports available!\n"); return SWITCH_STATUS_FALSE; } - sdp_port = tech_pvt->local_sdp_video_port; + sdp_port = tech_pvt->local_sdp_video_port; if (tech_pvt->profile->extrtpip) { - if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &ip, &sdp_port, tech_pvt->profile->extrtpip, switch_core_session_get_pool(tech_pvt->session)) != + if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &ip, &sdp_port, tech_pvt->profile->extrtpip, + switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_FALSE; } @@ -728,7 +728,8 @@ tech_pvt->adv_sdp_video_port = sdp_port; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); } @@ -1285,7 +1286,7 @@ const char* format; const char *alt = NULL; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) { sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; } else { @@ -1399,7 +1400,8 @@ } } - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { const char *transport = sofia_glue_transport2str(tech_pvt->transport); tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", transport, tech_pvt->profile->extsipip); @@ -1417,7 +1419,7 @@ char *ip_addr; char *ipv6; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) { ip_addr = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; } else { @@ -1438,7 +1440,7 @@ if (sofia_glue_transport_has_tls(tech_pvt->transport)) { tech_pvt->invite_contact = tech_pvt->profile->tls_url; } else { - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { tech_pvt->invite_contact = tech_pvt->profile->public_url; } else { @@ -1692,7 +1694,7 @@ switch_mutex_lock(tech_pvt->sofia_mutex); caller_profile = switch_channel_get_caller_profile(channel); - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT)) { + if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) { sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; contact_url = tech_pvt->profile->public_url; @@ -1829,7 +1831,7 @@ switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port); } - if (tech_pvt->local_sdp_audio_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + if (tech_pvt->local_sdp_audio_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP); } @@ -1840,7 +1842,7 @@ switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_video_port); } - if (tech_pvt->local_sdp_video_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && + if (tech_pvt->local_sdp_video_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP); } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed Jun 3 08:42:37 2009 @@ -1417,13 +1417,17 @@ } } - id = switch_mprintf("sip:%s@%s", sub_to_user, switch_check_network_list_ip(network_ip, profile->local_network) ? sub_to_host : profile->extsipip); + id = switch_mprintf("sip:%s@%s", sub_to_user, (profile->local_network && switch_check_network_list_ip(network_ip, profile->local_network)) + ? sub_to_host : profile->extsipip); contact = sofia_glue_get_url_from_contact(o_contact, 1); if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { char *ptr = NULL; const char *transport_str = NULL; + + id = switch_mprintf("sip:%s@%s", sub_to_user, profile->extsipip); + if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { sofia_transport_t transport = sofia_glue_str2transport(ptr); transport_str = sofia_glue_transport2str(transport); @@ -1443,6 +1447,7 @@ } } else { contact_str = profile->url; + id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host); } if ((route = strstr(contact, ";fs_path=")) && (route = strdup(route + 9))) { From brian at freeswitch.org Wed Jun 3 07:33:32 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 09:33:32 -0500 Subject: [Freeswitch-branches] [commit] r13568 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 09:33:32 2009 New Revision: 13568 Log: adding nat detection to the gateways now Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed Jun 3 09:33:32 2009 @@ -2550,6 +2550,7 @@ if (!strncasecmp(profile_name, "gateway", 7)) { char *gw, *params; sofia_gateway_t *gateway_ptr = NULL; + char *dup_dest = NULL, *dest_host, *dest_user; if (!(gw = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); @@ -2632,6 +2633,12 @@ tech_pvt->invite_contact = switch_core_session_strdup(nsession, gateway_ptr->register_contact); } + dup_dest = strdup(dest); + switch_assert(dup_dest != NULL); + sofia_glue_get_user_host(dup_dest, &dest_user, &dest_host); + tech_pvt->remote_ip = switch_core_session_sprintf(nsession, "%s", dest_host); + switch_safe_free(dup_dest); + gateway_ptr->ob_calls++; if (gateway_ptr->ob_vars) { @@ -2645,7 +2652,6 @@ } else { char *dup_dest = NULL, *dest_host, *dest_user; - if (!(dest = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); @@ -2669,7 +2675,7 @@ sofia_glue_get_user_host(dup_dest, &dest_user, &dest_host); tech_pvt->remote_ip = switch_core_session_sprintf(nsession, "%s", dest_host); switch_safe_free(dup_dest); - + if (!strncasecmp(dest, "sip:", 4) || !strncasecmp(dest, "sips:", 5)) { tech_pvt->dest = switch_core_session_strdup(nsession, dest); } else if ((host = strchr(dest, '%'))) { From brian at freeswitch.org Wed Jun 3 07:36:39 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 09:36:39 -0500 Subject: [Freeswitch-branches] [commit] r13569 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 09:36:38 2009 New Revision: 13569 Log: adding addition sanity check Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed Jun 3 09:36:38 2009 @@ -1422,7 +1422,8 @@ contact = sofia_glue_get_url_from_contact(o_contact, 1); - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && + !switch_check_network_list_ip(network_ip, profile->local_network)) { char *ptr = NULL; const char *transport_str = NULL; From brian at freeswitch.org Wed Jun 3 08:05:28 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 10:05:28 -0500 Subject: [Freeswitch-branches] [commit] r13570 - in freeswitch/branches/brian/trunk: conf/autoload_configs src/mod/applications/mod_cluechoo src/mod/event_handlers/mod_event_socket Message-ID: Author: brian Date: Wed Jun 3 10:05:27 2009 New Revision: 13570 Log: trunk Modified: freeswitch/branches/brian/trunk/conf/autoload_configs/event_socket.conf.xml freeswitch/branches/brian/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Modified: freeswitch/branches/brian/trunk/conf/autoload_configs/event_socket.conf.xml ============================================================================== --- freeswitch/branches/brian/trunk/conf/autoload_configs/event_socket.conf.xml (original) +++ freeswitch/branches/brian/trunk/conf/autoload_configs/event_socket.conf.xml Wed Jun 3 10:05:27 2009 @@ -1,5 +1,6 @@ + Modified: freeswitch/branches/brian/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c (original) +++ freeswitch/branches/brian/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c Wed Jun 3 10:05:27 2009 @@ -42,10 +42,10 @@ */ SWITCH_MODULE_DEFINITION(mod_cluechoo, mod_cluechoo_load, mod_cluechoo_shutdown, NULL); -int add_D51(); -int add_sl(); -int add_man(); -int add_smoke(); +int add_D51(int x); +int add_sl(int x); +int add_man(int y, int x); +int add_smoke(int y, int x); int go(int i); int vgo(int i, switch_core_session_t *session); Modified: freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original) +++ freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Wed Jun 3 10:05:27 2009 @@ -115,6 +115,7 @@ char *acl[MAX_ACL]; uint32_t acl_count; uint32_t id; + int nat_map; } prefs; @@ -2211,6 +2212,10 @@ set_pref_ip(val); } else if (!strcmp(var, "debug")) { globals.debug = atoi(val); + } else if (!strcmp(var, "nat-map")) { + if (switch_true(val)) { + prefs.nat_map = 1; + } } else if (!strcmp(var, "listen-port")) { prefs.port = (uint16_t) atoi(val); } else if (!strcmp(var, "password")) { @@ -2235,6 +2240,10 @@ set_pref_pass("ClueCon"); } + if (!prefs.nat_map) { + prefs.nat_map = 0; + } + if (!prefs.port) { prefs.port = 8021; } @@ -2276,6 +2285,11 @@ if (rv) goto sock_fail; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port); + + if (prefs.nat_map) { + switch_nat_add_mapping(prefs.port, SWITCH_NAT_TCP); + } + break; sock_fail: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error! Could not listen on %s:%u\n", prefs.ip, prefs.port); @@ -2326,6 +2340,10 @@ } close_socket(&listen_list.sock); + + if (prefs.nat_map) { + switch_nat_del_mapping(prefs.port, SWITCH_NAT_TCP); + } if (pool) { switch_core_destroy_memory_pool(&pool); From brian at freeswitch.org Wed Jun 3 08:33:18 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 10:33:18 -0500 Subject: [Freeswitch-branches] [commit] r13571 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 10:33:17 2009 New Revision: 13571 Log: dont' leak Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed Jun 3 10:33:17 2009 @@ -469,6 +469,7 @@ free(contact_url); } + switch_safe_free(user_via); switch_safe_free(id); } From brian at freeswitch.org Wed Jun 3 08:43:34 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 10:43:34 -0500 Subject: [Freeswitch-branches] [commit] r13572 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 10:43:34 2009 New Revision: 13572 Log: port Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 10:43:34 2009 @@ -764,10 +764,10 @@ if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s\n", profile->name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port); } if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s\n", profile->name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); } } From brian at freeswitch.org Wed Jun 3 08:44:31 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 10:44:31 -0500 Subject: [Freeswitch-branches] [commit] r13574 - freeswitch/branches/brian/trunk/src/include Message-ID: Author: brian Date: Wed Jun 3 10:44:31 2009 New Revision: 13574 Log: merge trunk Modified: freeswitch/branches/brian/trunk/src/include/switch_utils.h Modified: freeswitch/branches/brian/trunk/src/include/switch_utils.h ============================================================================== --- freeswitch/branches/brian/trunk/src/include/switch_utils.h (original) +++ freeswitch/branches/brian/trunk/src/include/switch_utils.h Wed Jun 3 10:44:31 2009 @@ -172,7 +172,7 @@ \return SWITCH_STATUS_SUCCESSS for success, otherwise failure */ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(_Out_opt_bytecapcount_(len) - char *buf, _In_ int len, _In_ int *mask, _In_ int family); + char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family); /*! \brief find the char representation of an ip adress From brian at freeswitch.org Wed Jun 3 09:35:08 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 11:35:08 -0500 Subject: [Freeswitch-branches] [commit] r13575 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 11:35:08 2009 New Revision: 13575 Log: cleanup by mike and bkw Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed Jun 3 11:35:08 2009 @@ -2550,7 +2550,6 @@ if (!strncasecmp(profile_name, "gateway", 7)) { char *gw, *params; sofia_gateway_t *gateway_ptr = NULL; - char *dup_dest = NULL, *dest_host, *dest_user; if (!(gw = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); @@ -2633,12 +2632,6 @@ tech_pvt->invite_contact = switch_core_session_strdup(nsession, gateway_ptr->register_contact); } - dup_dest = strdup(dest); - switch_assert(dup_dest != NULL); - sofia_glue_get_user_host(dup_dest, &dest_user, &dest_host); - tech_pvt->remote_ip = switch_core_session_sprintf(nsession, "%s", dest_host); - switch_safe_free(dup_dest); - gateway_ptr->ob_calls++; if (gateway_ptr->ob_vars) { @@ -2651,8 +2644,6 @@ } } else { - char *dup_dest = NULL, *dest_host, *dest_user; - if (!(dest = strchr(profile_name, '/'))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; @@ -2670,12 +2661,6 @@ profile_name = profile->domain_name; } - dup_dest = strdup(dest); - switch_assert(dup_dest != NULL); - sofia_glue_get_user_host(dup_dest, &dest_user, &dest_host); - tech_pvt->remote_ip = switch_core_session_sprintf(nsession, "%s", dest_host); - switch_safe_free(dup_dest); - if (!strncasecmp(dest, "sip:", 4) || !strncasecmp(dest, "sips:", 5)) { tech_pvt->dest = switch_core_session_strdup(nsession, dest); } else if ((host = strchr(dest, '%'))) { @@ -2711,6 +2696,8 @@ } } + sofia_glue_get_user_host(switch_core_session_strdup(nsession, tech_pvt->dest), NULL, &tech_pvt->remote_ip); + if (dest_to) { if (strchr(dest_to, '@')) { tech_pvt->dest_to = switch_core_session_sprintf(nsession, "sip:%s", dest_to); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 11:35:08 2009 @@ -4038,7 +4038,10 @@ { char *p, *h, *u = in; - *user = NULL; + if (user) { + *user = NULL; + } + *host = NULL; /* First isolate the host part from the user part */ @@ -4049,7 +4052,7 @@ } /* Clean out the user part of its protocol prefix (if any) */ - if ((p = strchr(u, ':'))) { + if (user && (p = strchr(u, ':'))) { *p++ = '\0'; u = p; } @@ -4067,7 +4070,10 @@ *p = '\0'; } + if (user) { *user = u; + } + *host = h; return 1; From brian at freeswitch.org Wed Jun 3 09:40:18 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 11:40:18 -0500 Subject: [Freeswitch-branches] [commit] r13576 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 11:40:18 2009 New Revision: 13576 Log: fix debug Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 11:40:18 2009 @@ -915,10 +915,10 @@ if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s\n", profile->name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port); } if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s\n", profile->name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); } } From brian at freeswitch.org Wed Jun 3 10:30:50 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 12:30:50 -0500 Subject: [Freeswitch-branches] [commit] r13577 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 12:30:49 2009 New Revision: 13577 Log: cleanup by mike and bkw Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 12:30:49 2009 @@ -4491,8 +4491,8 @@ if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { - sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); - tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), + tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", + sofia_glue_transport2str(sofia_glue_url2transport(sip->sip_contact->m_url)), profile->extsipip); } @@ -4690,17 +4690,17 @@ if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "", user, host); } else { - const char *url; + const char *url = NULL; if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { - - if (sofia_glue_transport_has_tls(transport)) { - url = profile->tls_public_url; - } else { - url = profile->public_url; - } + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; + } else { + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url; + } + + if (url) { if (strchr(url, '>')) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); @@ -4708,42 +4708,30 @@ tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, sofia_glue_transport2str(transport)); } - } else if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url)) { - if (strchr(url, '>')) { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); - } else { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", url, sofia_glue_transport2str(transport)); - } } else { switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } } } } else { - const char *url; - + const char *url = NULL; + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { - if (sofia_glue_transport_has_tls(transport)) { - url = profile->tls_public_url; - } else { - url = profile->public_url; - } - + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; + } else { + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url; + } + + if (url) { if (strchr(url, '>')) { tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); } else { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", url, + tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, sofia_glue_transport2str(transport)); } - } else if ((url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url)) { - if (strchr(url, '>')) { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, sofia_glue_transport2str(transport)); - } else { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", url, sofia_glue_transport2str(transport)); - } } else { switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 12:30:49 2009 @@ -665,28 +665,16 @@ } } - if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); - } else { - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); - } + if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && + !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); + switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); } else { - if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); - } else { - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); - } + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); } - + tech_pvt->adv_sdp_audio_port = sdp_port; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { - switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); - } - switch_snprintf(tmp, sizeof(tmp), "%d", sdp_port); switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip); switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp); From brian at freeswitch.org Wed Jun 3 10:52:06 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 12:52:06 -0500 Subject: [Freeswitch-branches] [commit] r13578 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 12:52:05 2009 New Revision: 13578 Log: cleanup by mike and bkw Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed Jun 3 12:52:05 2009 @@ -1417,9 +1417,6 @@ } } - id = switch_mprintf("sip:%s@%s", sub_to_user, (profile->local_network && switch_check_network_list_ip(network_ip, profile->local_network)) - ? sub_to_host : profile->extsipip); - contact = sofia_glue_get_url_from_contact(o_contact, 1); if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && @@ -1432,20 +1429,26 @@ if ((ptr = sofia_glue_find_parameter(o_contact, "transport="))) { sofia_transport_t transport = sofia_glue_str2transport(ptr); transport_str = sofia_glue_transport2str(transport); + + switch (transport) { + case SOFIA_TRANSPORT_TCP: + contact_str = profile->tcp_public_contact; + break; + case SOFIA_TRANSPORT_TCP_TLS: + contact_str = profile->tls_public_contact; + break; + default: + contact_str = profile->public_url; + break; + } + user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); + } else { user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); - } - - if (switch_stristr("udp", transport_str)) { - contact_str = profile->public_url; - } else if (switch_stristr("tcp", transport_str)) { - contact_str = profile->tcp_public_contact; - } else if (switch_stristr("tls", transport_str)) { - contact_str = profile->tls_public_contact; - } else { contact_str = profile->public_url; } + } else { contact_str = profile->url; id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host); @@ -1496,7 +1499,7 @@ nua_notify(nh, NUTAG_NEWSUB(1), TAG_IF(route_uri, NUTAG_PROXY(route_uri)), - TAG_IF(!switch_strlen_zero(user_via), SIPTAG_VIA_STR(user_via)), + TAG_IF(user_via, SIPTAG_VIA_STR(user_via)), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END()); @@ -1505,6 +1508,7 @@ switch_safe_free(id); switch_safe_free(route); switch_safe_free(user_via); + if (ext_profile) { sofia_glue_release_profile(ext_profile); } @@ -1558,7 +1562,8 @@ get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && + !switch_check_network_list_ip(network_ip, profile->local_network)) { is_auto_nat = 1; } @@ -1663,8 +1668,6 @@ } } - - if (to) { to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host); } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed Jun 3 12:52:05 2009 @@ -425,26 +425,34 @@ *p = '\0'; } - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && + !switch_check_network_list_ip(network_ip, profile->local_network)) { char *ptr = NULL; const char *transport_str = NULL; + if ((ptr = sofia_glue_find_parameter(contact_url, "transport="))) { sofia_transport_t transport = sofia_glue_str2transport(ptr); transport_str = sofia_glue_transport2str(transport); - user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); + + switch (transport) { + case SOFIA_TRANSPORT_TCP: + contact_str = profile->tcp_public_contact; + break; + case SOFIA_TRANSPORT_TCP_TLS: + contact_str = profile->tls_public_contact; + break; + default: + contact_str = profile->public_url; + break; + } + + user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); + } else { user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); - } - - if (switch_stristr("udp", transport_str)) { - contact_str = profile->public_url; - } else if (switch_stristr("tcp", transport_str)) { - contact_str = profile->tcp_public_contact; - } else if (switch_stristr("tls", transport_str)) { - contact_str = profile->tls_public_contact; - } else { contact_str = profile->public_url; } + } else { contact_str = profile->url; } @@ -459,7 +467,7 @@ nua_handle_bind(nh, &mod_sofia_globals.destroy_private); nua_notify(nh, NUTAG_NEWSUB(1), - TAG_IF(!switch_strlen_zero(user_via), SIPTAG_VIA_STR(user_via)), + TAG_IF(user_via, SIPTAG_VIA_STR(user_via)), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(""), From mikej at freeswitch.org Wed Jun 3 11:16:51 2009 From: mikej at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 13:16:51 -0500 Subject: [Freeswitch-branches] [commit] r13579 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: mikej Date: Wed Jun 3 13:16:51 2009 New Revision: 13579 Log: factor out helper function for getting ip address information from a msg_t sofia_glue_get_addr() Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed Jun 3 13:16:51 2009 @@ -885,3 +885,4 @@ sofia_cid_type_t sofia_cid_name2type(const char *name); void sofia_glue_tech_set_local_sdp(private_object_t *tech_pvt, const char *sdp_str, switch_bool_t dup); void sofia_glue_set_rtp_stats(private_object_t *tech_pvt); +void sofia_glue_get_addr(msg_t *msg, char *buf, size_t buflen, int *port); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 13:16:51 2009 @@ -406,8 +406,7 @@ if (authorization) { char network_ip[80]; - su_addrinfo_t *addrinfo = msg_addrinfo(nua_current_request(nua)); - get_addr(network_ip, sizeof(network_ip), addrinfo->ai_addr, addrinfo->ai_addrlen); + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), NULL); auth_res = sofia_reg_parse_auth(profile, authorization, sip, (char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0, REG_INVITE, NULL, NULL); @@ -2833,13 +2832,11 @@ const char *uuid; switch_core_session_t *other_session; private_object_t *tech_pvt = switch_core_session_get_private(session); - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); char network_ip[80]; int network_port = 0; switch_caller_profile_t *caller_profile = NULL; - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); - network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); switch_channel_set_variable(channel, "sip_reply_host", network_ip); switch_channel_set_variable_printf(channel, "sip_reply_port", "%d", network_port); @@ -4341,7 +4338,6 @@ uint32_t sess_count = switch_core_session_count(); uint32_t sess_max = switch_core_session_limit(0); int is_auth = 0, calling_myself = 0; - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); int network_port = 0; char *is_nat = NULL; char acl_token[512] = ""; @@ -4365,9 +4361,7 @@ goto fail; } - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); - network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); - + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); if (sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION)) { if (sip && sip->sip_via) { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 13:16:51 2009 @@ -830,6 +830,18 @@ } } +void sofia_glue_get_addr(msg_t *msg, char *buf, size_t buflen, int *port) { + su_addrinfo_t *addrinfo = msg_addrinfo(msg); + + if (buf) { + get_addr(buf, buflen, addrinfo->ai_addr, addrinfo->ai_addrlen); + } + + if (port) { + *port = get_port(addrinfo->ai_addr); + } +} + char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only, const char *params) { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed Jun 3 13:16:51 2009 @@ -764,19 +764,17 @@ char *force_user; char received_data[128] = ""; char *path_val = NULL; - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); switch_event_t *auth_params = NULL; int r = 0; /* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */ switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL); - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr,my_addrinfo->ai_addrlen); - network_port = get_port(my_addrinfo->ai_addr); + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); snprintf(network_port_c, sizeof(network_port_c), "%d", network_port); - snprintf(url_ip, sizeof(url_ip), my_addrinfo->ai_addr->sa_family == AF_INET6 ? "[%s]" : "%s", network_ip); + snprintf(url_ip, sizeof(url_ip), (msg_addrinfo(nua_current_request(nua)))->ai_addr->sa_family == AF_INET6 ? "[%s]" : "%s", network_ip); expires = sip->sip_expires; authorization = sip->sip_authorization; @@ -1281,22 +1279,17 @@ } - void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]) { char key[128] = ""; switch_event_t *v_event = NULL; char network_ip[80]; - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); sofia_regtype_t type = REG_REGISTER; int network_port = 0; char *is_nat = NULL; - - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); - network_port = get_port(msg_addrinfo(nua_current_request(nua))->ai_addr); - + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); if (!(sip->sip_contact && sip->sip_contact->m_url)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n"); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Wed Jun 3 13:16:51 2009 @@ -76,12 +76,10 @@ struct sla_helper sh = { { 0 } }; char *contact_str = strip_uri(full_contact); sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); char network_ip[80]; int network_port = 0; - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); - network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'", mod_sofia_globals.hostname, profile->name, contact_str); @@ -136,14 +134,11 @@ char *sql = NULL; char *route_uri = NULL; char *sla_contact = NULL; - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); char network_ip[80]; int network_port = 0; sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); - - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); - network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); /* * XXX MTK FIXME - we don't look at the tag to see if NUTAG_SUBSTATE(nua_substate_terminated) or * a Subscription-State header with state "terminated" and/or expiration of 0. So we never forget From mikej at freeswitch.org Wed Jun 3 11:21:03 2009 From: mikej at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 13:21:03 -0500 Subject: [Freeswitch-branches] [commit] r13580 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: mikej Date: Wed Jun 3 13:21:03 2009 New Revision: 13580 Log: factor out helper function for getting ip address information from a msg_t sofia_glue_get_addr() Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed Jun 3 13:21:03 2009 @@ -1544,7 +1544,6 @@ switch_event_t *sevent; int sub_state; int sent_reply = 0; - su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); int network_port = 0; char network_ip[80]; const char *contact_host, *contact_user; @@ -1559,8 +1558,7 @@ return; } - get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr, my_addrinfo->ai_addrlen); - network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); + sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port); if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && !switch_check_network_list_ip(network_ip, profile->local_network)) { From brian at freeswitch.org Wed Jun 3 12:02:16 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:02:16 -0500 Subject: [Freeswitch-branches] [commit] r13581 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 14:02:16 2009 New Revision: 13581 Log: refactor and clean up Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed Jun 3 14:02:16 2009 @@ -830,7 +830,7 @@ const char *sofia_glue_transport2str(const sofia_transport_t tp); char * sofia_glue_find_parameter(const char *str, const char *param); - +int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip); int sofia_glue_transport_has_tls(const sofia_transport_t tp); const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name); switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, switch_rtp_crypto_key_type_t type, switch_rtp_crypto_direction_t direction); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 14:02:16 2009 @@ -665,9 +665,8 @@ } } - if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); } else { tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); @@ -716,8 +715,7 @@ tech_pvt->adv_sdp_video_port = sdp_port; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); } @@ -819,6 +817,14 @@ } } +int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip) +{ + return (network_ip && + profile->local_network && + sofia_test_pflag(profile, PFLAG_AUTO_NAT) && + !switch_check_network_list_ip(network_ip, profile->local_network)); +} + int sofia_glue_transport_has_tls(const sofia_transport_t tp) { switch (tp) { @@ -1286,9 +1292,8 @@ const char* format; const char *alt = NULL; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) { - sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) - ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->profile->local_network)) { + sipip = tech_pvt->profile->extsipip; } else { sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; } @@ -1400,8 +1405,7 @@ } } - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { const char *transport = sofia_glue_transport2str(tech_pvt->transport); tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", transport, tech_pvt->profile->extsipip); @@ -1419,7 +1423,7 @@ char *ip_addr; char *ipv6; - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) { + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { ip_addr = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; } else { @@ -1440,8 +1444,7 @@ if (sofia_glue_transport_has_tls(tech_pvt->transport)) { tech_pvt->invite_contact = tech_pvt->profile->tls_url; } else { - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { tech_pvt->invite_contact = tech_pvt->profile->public_url; } else { tech_pvt->invite_contact = tech_pvt->profile->url; @@ -1694,9 +1697,8 @@ switch_mutex_lock(tech_pvt->sofia_mutex); caller_profile = switch_channel_get_caller_profile(channel); - if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) { - sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) - ? tech_pvt->profile->sipip : tech_pvt->profile->extsipip; + if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { + sipip = tech_pvt->profile->extsipip; contact_url = tech_pvt->profile->public_url; } else { sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip; @@ -1831,8 +1833,7 @@ switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port); } - if (tech_pvt->local_sdp_audio_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + if (tech_pvt->local_sdp_audio_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP); } @@ -1842,8 +1843,8 @@ switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_video_port); } - if (tech_pvt->local_sdp_video_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) { + + if (tech_pvt->local_sdp_video_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP); } } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Wed Jun 3 14:02:16 2009 @@ -103,7 +103,7 @@ nua_handle_bind(nh, &mod_sofia_globals.keep_private); switch_snprintf(exp_str, sizeof(exp_str), "%ld", exptime + 30); - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + if (sofia_glue_check_nat(profile, network_ip)) { switch_snprintf(my_contact, sizeof(my_contact), ";expires=%s", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport), exp_str); } else { @@ -200,11 +200,10 @@ *p++ = '\0'; } } - - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) { + if (sofia_glue_check_nat(profile, network_ip)) { sla_contact = switch_mprintf("", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport)); } else { - sla_contact = switch_mprintf("", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport)); + sla_contact = switch_mprintf("", profile->sla_contact, profile->sipip, sofia_glue_transport2str(transport)); } nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(sla_contact), NUTAG_WITH_THIS(nua), @@ -337,6 +336,7 @@ nua_handle_t *nh; char *route_uri = NULL; char *xml_fixup = NULL; + char *fixup = NULL; nh = nua_handle_by_call_id(helper->profile->nua, call_id); /* that's all you need to find the subscription's nh */ if (nh) { @@ -359,11 +359,14 @@ *p++ = '\0'; } } - - if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, helper->profile->local_network)) { - xml_fixup = switch_string_replace(helper->payload, helper->profile->sipip, helper->profile->extsipip); - } else if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT) && switch_check_network_list_ip(network_ip, helper->profile->local_network)) { - xml_fixup = switch_string_replace(helper->payload, helper->profile->extsipip, helper->profile->sipip); + + if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT)) { + if (sofia_glue_check_nat(helper->profile, network_ip)) { + fixup = switch_string_replace(helper->payload, helper->profile->sipip, helper->profile->extsipip); + } else { + fixup = switch_string_replace(helper->payload, helper->profile->extsipip, helper->profile->sipip); + } + xml_fixup = fixup; } else { xml_fixup = helper->payload; } @@ -375,7 +378,7 @@ SIPTAG_PAYLOAD_STR(xml_fixup), TAG_END()); switch_safe_free(route_uri); - switch_safe_free(xml_fixup); + switch_safe_free(fixup); } return 0; } From brian at freeswitch.org Wed Jun 3 12:07:52 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:07:52 -0500 Subject: [Freeswitch-branches] [commit] r13582 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 14:07:52 2009 New Revision: 13582 Log: missed these Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 14:07:52 2009 @@ -4482,9 +4482,7 @@ tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip); tech_pvt->remote_port = network_port; - - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { + if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(sofia_glue_url2transport(sip->sip_contact->m_url)), profile->extsipip); @@ -4686,9 +4684,7 @@ } else { const char *url = NULL; - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { - + if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; } else { url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url; @@ -4709,11 +4705,8 @@ } } else { const char *url = NULL; - - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && - !switch_check_network_list_ip(tech_pvt->remote_ip, profile->local_network)) { - - url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; + if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; } else { url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url; } From brian at freeswitch.org Wed Jun 3 12:12:29 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:12:29 -0500 Subject: [Freeswitch-branches] [commit] r13583 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 14:12:29 2009 New Revision: 13583 Log: move this down to after the profile has stopped Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 14:12:29 2009 @@ -912,15 +912,6 @@ sofia_clear_pflag_locked(profile, PFLAG_RUNNING); - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { - if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port); - } - if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); - } - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for worker thread\n"); switch_thread_join(&st, worker_thread); @@ -958,6 +949,15 @@ switch_event_fire(&s_event); } + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port); + } + if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); + } + } + sofia_glue_sql_close(profile); su_home_unref(profile->home); su_root_destroy(profile->s_root); From brian at freeswitch.org Wed Jun 3 12:17:12 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:17:12 -0500 Subject: [Freeswitch-branches] [commit] r13584 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 14:17:11 2009 New Revision: 13584 Log: enable AUTO_NAT flag when you set ext-rtp-ip or ext-sip-ip Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 14:17:11 2009 @@ -2186,10 +2186,10 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip); } else if (!strcasecmp(val, "auto-nat")) { ip = mod_sofia_globals.auto_nat ? switch_core_get_variable("nat_public_addr") : mod_sofia_globals.guess_ip; - sofia_set_pflag(profile, PFLAG_AUTO_NAT); } else { ip = strcasecmp(val, "auto") ? val : mod_sofia_globals.guess_ip; } + sofia_set_pflag(profile, PFLAG_AUTO_NAT); profile->extrtpip = switch_core_strdup(profile->pool, ip); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ext-rtp-ip\n"); @@ -2224,7 +2224,6 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip); } else if (!strcasecmp(val, "auto-nat")) { ip = mod_sofia_globals.auto_nat ? switch_core_get_variable("nat_public_addr") : mod_sofia_globals.guess_ip; - sofia_set_pflag(profile, PFLAG_AUTO_NAT); } else if (strcasecmp(val, "auto")) { switch_port_t port = 0; if (sofia_glue_ext_address_lookup(profile, NULL, &myip, &port, val, profile->pool) == SWITCH_STATUS_SUCCESS) { @@ -2233,6 +2232,7 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to get external ip.\n"); } } + sofia_set_pflag(profile, PFLAG_AUTO_NAT); profile->extsipip = switch_core_strdup(profile->pool, ip); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ext-sip-ip\n"); From brian at freeswitch.org Wed Jun 3 12:25:27 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:25:27 -0500 Subject: [Freeswitch-branches] [commit] r13585 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 14:25:27 2009 New Revision: 13585 Log: adding tls port to auto map Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 14:25:27 2009 @@ -768,6 +768,9 @@ if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); } + if(profile->tls_sip_port && switch_nat_add_mapping((switch_port_t)profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port); + } } profile->nua = nua_create(profile->s_root, /* Event loop */ @@ -956,6 +959,9 @@ if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); } + if(profile->tls_sip_port && switch_nat_del_mapping((switch_port_t)profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port); + } } sofia_glue_sql_close(profile); From brian at freeswitch.org Wed Jun 3 12:26:36 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:26:36 -0500 Subject: [Freeswitch-branches] [commit] r13587 - freeswitch/branches/brian/trunk/src Message-ID: Author: brian Date: Wed Jun 3 14:26:35 2009 New Revision: 13587 Log: merge trunk Modified: freeswitch/branches/brian/trunk/src/switch_core.c Modified: freeswitch/branches/brian/trunk/src/switch_core.c ============================================================================== --- freeswitch/branches/brian/trunk/src/switch_core.c (original) +++ freeswitch/branches/brian/trunk/src/switch_core.c Wed Jun 3 14:26:35 2009 @@ -904,6 +904,12 @@ switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE); switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list); + tmp_name = "loopback.auto"; + switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name); + switch_network_list_add_cidr(rfc_list, "127.0.0.0/8", SWITCH_TRUE); + switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list); + tmp_name = "localnet.auto"; switch_network_list_create(&list, tmp_name, SWITCH_FALSE, IP_LIST.pool); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name); From mikej at freeswitch.org Wed Jun 3 12:42:34 2009 From: mikej at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:42:34 -0500 Subject: [Freeswitch-branches] [commit] r13588 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: mikej Date: Wed Jun 3 14:42:34 2009 New Revision: 13588 Log: don't free helper->payload Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c Wed Jun 3 14:42:34 2009 @@ -378,7 +378,9 @@ SIPTAG_PAYLOAD_STR(xml_fixup), TAG_END()); switch_safe_free(route_uri); - switch_safe_free(fixup); + if (fixup && fixup != helper->payload) { + free(fixup); + } } return 0; } From brian at freeswitch.org Wed Jun 3 12:44:25 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:44:25 -0500 Subject: [Freeswitch-branches] [commit] r13590 - freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket Message-ID: Author: brian Date: Wed Jun 3 14:44:25 2009 New Revision: 13590 Log: merge trunk Modified: freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Modified: freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original) +++ freeswitch/branches/brian/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Wed Jun 3 14:44:25 2009 @@ -2244,6 +2244,10 @@ prefs.nat_map = 0; } + if (prefs.nat_map && !switch_check_network_list_ip(prefs.ip, "loopback.auto")) { + prefs.nat_map = 0; + } + if (!prefs.port) { prefs.port = 8021; } From brian at freeswitch.org Wed Jun 3 12:46:26 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 14:46:26 -0500 Subject: [Freeswitch-branches] [commit] r13591 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 14:46:25 2009 New Revision: 13591 Log: more clean up Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed Jun 3 14:46:25 2009 @@ -424,9 +424,7 @@ if ((p = strstr(contact_url, ";fs_"))) { *p = '\0'; } - - if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && profile->local_network && - !switch_check_network_list_ip(network_ip, profile->local_network)) { + if (sofia_glue_check_nat(profile, network_ip)) { char *ptr = NULL; const char *transport_str = NULL; From brian at freeswitch.org Wed Jun 3 13:49:57 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 15:49:57 -0500 Subject: [Freeswitch-branches] [commit] r13592 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 15:49:57 2009 New Revision: 13592 Log: more clean up Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed Jun 3 15:49:57 2009 @@ -436,8 +436,8 @@ sofia_cid_type_t cid_type; sofia_dtmf_t dtmf_type; int auto_restart; - int sip_port; - int tls_sip_port; + switch_port_t sip_port; + switch_port_t tls_sip_port; int tls_version; char *codec_string; int running; @@ -830,6 +830,8 @@ const char *sofia_glue_transport2str(const sofia_transport_t tp); char * sofia_glue_find_parameter(const char *str, const char *param); +char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport); +char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport); int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip); int sofia_glue_transport_has_tls(const sofia_transport_t tp); const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name); Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 15:49:57 2009 @@ -762,13 +762,13 @@ ); if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { - if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { + if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port); } - if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); } - if(profile->tls_sip_port && switch_nat_add_mapping((switch_port_t)profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port); } } @@ -953,13 +953,13 @@ } if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { - if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { + if (switch_nat_del_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port); } - if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + if (switch_nat_del_mapping(profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s port %d\n", profile->name, profile->sip_port); } - if(profile->tls_sip_port && switch_nat_del_mapping((switch_port_t)profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { + if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_del_mapping(profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port); } } @@ -4347,6 +4347,7 @@ int network_port = 0; char *is_nat = NULL; char acl_token[512] = ""; + sofia_transport_t transport; profile->ib_calls++; @@ -4488,11 +4489,6 @@ tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip); tech_pvt->remote_port = network_port; - if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { - tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", - sofia_glue_transport2str(sofia_glue_url2transport(sip->sip_contact->m_url)), - profile->extsipip); - } channel = tech_pvt->channel = switch_core_session_get_channel(session); @@ -4509,7 +4505,7 @@ if (sip->sip_contact && sip->sip_contact->m_url) { char tmp[35] = ""; - sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url); + transport = sofia_glue_url2transport(sip->sip_contact->m_url); const char *ipv6 = strchr(tech_pvt->remote_ip, ':'); tech_pvt->record_route = @@ -4638,7 +4634,6 @@ if (sip->sip_to && sip->sip_to->a_url) { const char *host, *user; int port; - sofia_transport_t transport; url_t *transport_url; if (sip->sip_record_route && sip->sip_record_route->r_url) { @@ -4731,6 +4726,10 @@ } } + if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { + tech_pvt->user_via = sofia_glue_create_external_via(session, profile, tech_pvt->transport); + } + if (sip->sip_contact && sip->sip_contact->m_url) { const char *contact_uri = url_set_chanvars(session, sip->sip_contact->m_url, sip_contact); if (!channel_name) { Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 15:49:57 2009 @@ -817,6 +817,32 @@ } } +char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport) +{ + return sofia_glue_create_via(session, + profile->extsipip, + (sofia_glue_transport_has_tls(transport)) + ? profile->tls_sip_port : profile->sip_port, + transport); +} + +char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport) +{ + if (port && port != 5060) { + if (session) { + return switch_core_session_sprintf(session, "SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port); + } else { + return switch_mprintf("SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port); + } + } else { + if (session) { + return switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), ip); + } else { + return switch_mprintf("SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), ip); + } + } +} + int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip) { return (network_ip && @@ -1406,9 +1432,7 @@ } if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { - const char *transport = sofia_glue_transport2str(tech_pvt->transport); - tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", - transport, tech_pvt->profile->extsipip); + tech_pvt->user_via = sofia_glue_create_external_via(session, tech_pvt->profile, tech_pvt->transport); } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed Jun 3 15:49:57 2009 @@ -1441,11 +1441,9 @@ contact_str = profile->public_url; break; } - - user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); - + user_via = sofia_glue_create_external_via(NULL, profile, transport); } else { - user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); + user_via = sofia_glue_create_external_via(NULL, profile, SOFIA_TRANSPORT_UDP); contact_str = profile->public_url; } Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed Jun 3 15:49:57 2009 @@ -444,10 +444,9 @@ break; } - user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip); - + user_via = sofia_glue_create_external_via(NULL, profile, transport); } else { - user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip); + user_via = sofia_glue_create_external_via(NULL, profile, SOFIA_TRANSPORT_UDP); contact_str = profile->public_url; } From brian at freeswitch.org Wed Jun 3 13:57:58 2009 From: brian at freeswitch.org (FreeSWITCH SVN) Date: Wed, 03 Jun 2009 15:57:58 -0500 Subject: [Freeswitch-branches] [commit] r13593 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia Message-ID: Author: brian Date: Wed Jun 3 15:57:57 2009 New Revision: 13593 Log: fix compile warnings for windows Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 15:57:57 2009 @@ -2172,7 +2172,7 @@ } else if (!strcasecmp(var, "cng-pt") && !sofia_test_pflag(profile, PFLAG_SUPPRESS_CNG)) { profile->cng_pt = (switch_payload_t) atoi(val); } else if (!strcasecmp(var, "sip-port")) { - profile->sip_port = atoi(val); + profile->sip_port = (switch_port_t)atoi(val); } else if (!strcasecmp(var, "vad")) { if (!strcasecmp(val, "in")) { sofia_set_flag(profile, TFLAG_VAD_IN); @@ -2501,7 +2501,7 @@ } else if (!strcasecmp(var, "tls-bind-params")) { profile->tls_bind_params = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "tls-sip-port")) { - profile->tls_sip_port = atoi(val); + profile->tls_sip_port = (switch_port_t)atoi(val); } else if (!strcasecmp(var, "tls-cert-dir")) { profile->tls_cert_dir = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "tls-version")) { @@ -2569,7 +2569,7 @@ } if (!profile->sip_port) { - profile->sip_port = atoi(SOFIA_DEFAULT_PORT); + profile->sip_port = (switch_port_t)atoi(SOFIA_DEFAULT_PORT); } if (!profile->dialplan) { @@ -2632,7 +2632,7 @@ */ if (sofia_test_pflag(profile, PFLAG_TLS)) { if (!profile->tls_sip_port) { - profile->tls_sip_port = atoi(SOFIA_DEFAULT_TLS_PORT); + profile->tls_sip_port = (switch_port_t)atoi(SOFIA_DEFAULT_TLS_PORT); } if (profile->extsipip && sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { @@ -4505,9 +4505,10 @@ if (sip->sip_contact && sip->sip_contact->m_url) { char tmp[35] = ""; + const char *ipv6 = strchr(tech_pvt->remote_ip, ':'); + transport = sofia_glue_url2transport(sip->sip_contact->m_url); - const char *ipv6 = strchr(tech_pvt->remote_ip, ':'); tech_pvt->record_route = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d;transport=%s", Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 15:57:57 2009 @@ -665,8 +665,8 @@ } } - if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { - tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); + if (tech_pvt->profile->extrtpip && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { + tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip); switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP); } else { tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip); From dome_2k at freeswitch.org Tue Jun 23 23:29:50 2009 From: dome_2k at freeswitch.org (FreeSWITCH SVN) Date: Wed, 24 Jun 2009 01:29:50 -0500 Subject: [Freeswitch-branches] [commit] r13930 - in freeswitch/branches/dome_2k: . conf docs libs src w32 Message-ID: Author: dome_2k Date: Wed Jun 24 01:29:50 2009 New Revision: 13930 Log: remove all Removed: freeswitch/branches/dome_2k/AUTHORS freeswitch/branches/dome_2k/COPYING freeswitch/branches/dome_2k/ChangeLog freeswitch/branches/dome_2k/INSTALL freeswitch/branches/dome_2k/Makefile.am freeswitch/branches/dome_2k/Makefile.in freeswitch/branches/dome_2k/NEWS freeswitch/branches/dome_2k/README freeswitch/branches/dome_2k/TODO freeswitch/branches/dome_2k/aclocal.m4 freeswitch/branches/dome_2k/build.sh freeswitch/branches/dome_2k/buildlib.sh freeswitch/branches/dome_2k/checkversion.sh freeswitch/branches/dome_2k/compile freeswitch/branches/dome_2k/conf/ freeswitch/branches/dome_2k/config.guess freeswitch/branches/dome_2k/config.h.in freeswitch/branches/dome_2k/config.sub freeswitch/branches/dome_2k/configure freeswitch/branches/dome_2k/configure.in freeswitch/branches/dome_2k/configure.scan freeswitch/branches/dome_2k/depcomp freeswitch/branches/dome_2k/docs/ freeswitch/branches/dome_2k/generic_mod.mk freeswitch/branches/dome_2k/indent_options.sh freeswitch/branches/dome_2k/install-sh freeswitch/branches/dome_2k/libs/ freeswitch/branches/dome_2k/ltmain.sh freeswitch/branches/dome_2k/missing freeswitch/branches/dome_2k/mkinstalldirs freeswitch/branches/dome_2k/modmake.sh freeswitch/branches/dome_2k/modules.conf freeswitch/branches/dome_2k/modules.conf.in freeswitch/branches/dome_2k/src/ freeswitch/branches/dome_2k/w32/ From dome_2k at freeswitch.org Tue Jun 23 23:32:02 2009 From: dome_2k at freeswitch.org (FreeSWITCH SVN) Date: Wed, 24 Jun 2009 01:32:02 -0500 Subject: [Freeswitch-branches] [commit] r13931 - freeswitch/branches/dome_2k/trunk Message-ID: Author: dome_2k Date: Wed Jun 24 01:32:02 2009 New Revision: 13931 Log: copy code from trunk Added: freeswitch/branches/dome_2k/trunk/ - copied from r13930, /freeswitch/trunk/ From dome_2k at freeswitch.org Tue Jun 23 23:44:14 2009 From: dome_2k at freeswitch.org (FreeSWITCH SVN) Date: Wed, 24 Jun 2009 01:44:14 -0500 Subject: [Freeswitch-branches] [commit] r13932 - in freeswitch/branches/dome_2k: trunk tuxza Message-ID: Author: dome_2k Date: Wed Jun 24 01:44:14 2009 New Revision: 13932 Log: prepare tuxza branche Added: freeswitch/branches/dome_2k/tuxza/ - copied from r13931, /freeswitch/branches/dome_2k/trunk/ Removed: freeswitch/branches/dome_2k/trunk/ From dome_2k at freeswitch.org Wed Jun 24 03:22:04 2009 From: dome_2k at freeswitch.org (FreeSWITCH SVN) Date: Wed, 24 Jun 2009 05:22:04 -0500 Subject: [Freeswitch-branches] [commit] r13934 - freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th Message-ID: Author: dome_2k Date: Wed Jun 24 05:22:04 2009 New Revision: 13934 Log: add mod_say_th Added: freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/ freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/Makefile freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.2008.vcproj freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.c freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.vcproj Added: freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/Makefile ============================================================================== --- (empty file) +++ freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/Makefile Wed Jun 24 05:22:04 2009 @@ -0,0 +1,2 @@ +BASE=../../../.. +include $(BASE)/build/modmake.rules Added: freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.2008.vcproj ============================================================================== --- (empty file) +++ freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.2008.vcproj Wed Jun 24 05:22:04 2009 @@ -0,0 +1,283 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.c ============================================================================== --- (empty file) +++ freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.c Wed Jun 24 05:22:04 2009 @@ -0,0 +1,654 @@ +/* + * Copyright (c) 2007, Anthony Minessale II + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * PeteDao + * Steve Underwood 0.0.1 + * Dome Charoenyost + * + * + * mod_say_th.c -- Say for Thai + * + */ + +#include +#include +#include + +/* SSM_COUNTED means ordinal number + SSM_PRONOUNCED + SSM_ITERATED */ + +SWITCH_MODULE_LOAD_FUNCTION(mod_say_th_load); +SWITCH_MODULE_DEFINITION(mod_say_th, mod_say_th_load, NULL, NULL); + +#define say_num(num, t) { \ + char tmp[80];\ + switch_status_t tstatus;\ + switch_snprintf(tmp, sizeof(tmp), "%u", (unsigned)num); \ + if ((tstatus = th_say_general_count(session, tmp, SST_ITEMS, t, args)) != SWITCH_STATUS_SUCCESS) {\ + return tstatus;\ + }\ +}\ + +#define say_file(...) {\ + char tmp[80];\ + switch_status_t tstatus;\ + switch_snprintf(tmp, sizeof(tmp), __VA_ARGS__);\ + if ((tstatus = switch_ivr_play_file(session, NULL, tmp, args)) != SWITCH_STATUS_SUCCESS){ \ + return tstatus;\ + }\ + if (!switch_channel_ready(switch_core_session_get_channel(session))) {\ + return SWITCH_STATUS_FALSE;\ + }\ +}\ + + +static switch_status_t th_spell(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args) +{ + char *p; + + for (p = tosay; p && *p; p++) { + int a = tolower((int) *p); + if (a >= '0' && a <= '9') { + say_file("digits/%d.wav", a - '0'); + } else { + if (type == SST_NAME_SPELLED) { + say_file("ascii/%d.wav", a); + } else if (type == SST_NAME_PHONETIC) { + say_file("phonetic-ascii/%d.wav", a); + } + } + } + + return SWITCH_STATUS_SUCCESS; +} + +static char *strip_commas(char *in, char *out, switch_size_t len) +{ + char *p = in; + char *q = out; + char *ret = out; + switch_size_t x = 0; + + for ( ; p && *p; p++) { + if ((*p >= '0' && *p <= '9')) { + *q++ = *p; + } else if (*p != ',') { + ret = NULL; + break; + } + + if (++x > len) { + ret = NULL; + break; + } + } + + return ret; +} + +static char *strip_nonnumerics(char *in, char *out, switch_size_t len) +{ + char *p = in; + char *q = out; + char *ret = out; + switch_size_t x = 0; + + /* valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others */ + for (; p && *p; p++) { + if ((*p >= '0' && *p <= '9') || *p == '.' || *p == '-' || *p == '+') { + *q++ = *p; + } + + if (++x > len) { + ret = NULL; + break; + } + } + + return ret; +} + +static switch_status_t th_say_general_count(switch_core_session_t *session, + char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args) +{ + int in; + char sbuf[13] = ""; + char digits[11]; + int i; + + if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); + return SWITCH_STATUS_GENERR; + } + + in = atoi(tosay); + + if (in != 0) { + snprintf(digits, sizeof(digits), "%10.10d", in); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Say: %s \n",digits); + switch (method) { + case SSM_COUNTED: + say_file("digits/ordinal.wav"); + /* Fall through */ + case SSM_PRONOUNCED: + for (i = 0; i <= 9; i++) + { + switch (i) + { + case 0: + /* Billions column */ + if (digits[i] != '0') + { + if (digits[i] != '1') + say_file("digits/%c.wav", digits[i]); + say_file("digits/10.wav"); + } + break; + case 1: + /* Hundred millions columns */ + if (digits[i] != '0') + say_file("digits/%c.wav", digits[i]); + if (memcmp (digits, "00", 2) != 0) + say_file("digits/100000000.wav"); + break; + case 2: + /* ten Millions column */ + if (digits[i] != '0') + { + say_file("digits/%c.wav", digits[i]); + say_file("digits/10000000.wav"); + } + break; + case 3: + /* Millions column */ + if (digits[i] != '0') + { + say_file("digits/%c.wav", digits[i]); + say_file("digits/1000000.wav"); + } + break; + case 4: + /* Hundred thousands column */ + if (digits[i] != '0') + { + say_file("digits/%c.wav", digits[i]); + if (memcmp (digits + 2, "00000", 4) != 0) + say_file("digits/100000.wav"); + } + + break; + + case 5: + /* Ten thousands column */ + if (digits[i] != '0') + { + say_file("digits/%c.wav", digits[i]); + if (memcmp (digits + 2, "0000", 4) != 0) + say_file("digits/10000.wav"); + } + break; + case 6: + /* Ten millions or thousands column */ + if (digits[i] != '0') + { + say_file("digits/%c.wav", digits[i]); + say_file("digits/1000.wav"); + } + break; + case 7: + /* hundreds column */ + if (digits[i] != '0') + { + say_file("digits/%c.wav", digits[i]); + say_file("digits/100.wav"); + } + break; + case 8: + /* Tens column */ + if (digits[i] != '0') + { + if (digits[i] == '2' + || + memcmp (digits, "00000000", 8) != 0) + { + say_file("digits/20.wav"); + break; + } + if (digits[i] != '1' + || + memcmp (digits, "00000000", 8) != 0) + { + say_file("digits/%c.wav", digits[i]); + } + } + if (digits[8] != '0') + say_file("digits/10.wav"); + break; + case 9: + /* Units column */ + if (digits[9] == '1'){ + if (digits[8] != '0'){ + say_file("digits/ed.wav", digits[i]); + }else{ + say_file("digits/%c.wav", digits[i]); + } + break; + } + if (digits[9] != '0') + say_file("digits/%c.wav", digits[i]); + break; + } + } + break; + case SSM_ITERATED: + { + char *p; + + for (p = tosay; p && *p; p++) { + say_file("digits/%c.wav", *p); + } + } + break; + default: + break; + } + } else { + say_file("digits/0.wav"); + } + + return SWITCH_STATUS_SUCCESS; +} + + +static switch_status_t th_ip(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args) +{ + char *a, *b, *c, *d; + if (!(a = switch_core_session_strdup(session, tosay))) { + return SWITCH_STATUS_FALSE; + } + + if (!(b = strchr(a, '.'))) { + return SWITCH_STATUS_FALSE; + } + + *b++ = '\0'; + + if (!(c = strchr(b, '.'))) { + return SWITCH_STATUS_FALSE; + } + + *c++ = '\0'; + + if (!(d = strchr(c, '.'))) { + return SWITCH_STATUS_FALSE; + } + + *d++ = '\0'; + + say_num(atoi(a), method); + say_file("digits/dot.wav"); + say_num(atoi(b), method); + say_file("digits/dot.wav"); + say_num(atoi(c), method); + say_file("digits/dot.wav"); + say_num(atoi(d), method); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t th_say_time(switch_core_session_t *session, + char *tosay, + switch_say_type_t type, + switch_say_method_t method, + switch_input_args_t *args) +{ + int32_t t; + switch_time_t target = 0; + switch_time_exp_t tm; +#if 0 + switch_time_t this_morning; + switch_time_exp_t tm2; +#endif + uint8_t say_date = 0; + uint8_t say_time = 0; + + if (type == SST_TIME_MEASUREMENT) { + int64_t hours = 0; + int64_t minutes = 0; + int64_t seconds = 0; + int64_t r = 0; + + if (strchr(tosay, ':')) { + char *tme = switch_core_session_strdup(session, tosay); + char *p; + + if ((p = strrchr(tme, ':'))) { + *p++ = '\0'; + seconds = atoi(p); + if ((p = strchr(tme, ':'))) { + *p++ = '\0'; + minutes = atoi(p); + if (tme) { + hours = atoi(tme); + } + } else { + minutes = atoi(tme); + } + } + } else { + if ((seconds = atoi(tosay)) <= 0) { + seconds = (int64_t) switch_epoch_time_now(NULL); + } + + if (seconds >= 60) { + minutes = seconds / 60; + r = seconds % 60; + seconds = r; + } + + if (minutes >= 60) { + hours = minutes / 60; + r = minutes % 60; + minutes = r; + } + } + + if (hours) { + if (hours == 2) { + say_file("time/2s.wav"); + } else { + say_num(hours, SSM_PRONOUNCED); + } + say_file("time/hours.wav"); + } + if (minutes) { + if (minutes == 2) { + say_file("time/2s.wav"); + } else { + say_num(minutes, SSM_PRONOUNCED); + } + say_file("time/minute.wav"); + } else { + if (hours) { + say_file("digits/0.wav"); + say_file("time/minute.wav"); + } + } + + if (seconds) { + if (seconds == 2) { + say_file("time/2s.wav"); + } else { + say_num(hours, SSM_PRONOUNCED); + } + say_file("time/seconds.wav"); + } else { + if (hours || minutes) { + say_file("digits/0.wav"); + say_file("time/second.wav"); + } + } + + return SWITCH_STATUS_SUCCESS; + } + + if ((t = atoi(tosay)) > 0) + target = switch_time_make(t, 0); + else + target = switch_micro_time_now(); + switch_time_exp_lt(&tm, target); + + switch (type) { + case SST_CURRENT_DATE_TIME: + say_date = + say_time = 1; + break; + case SST_CURRENT_DATE: + say_date = 1; + break; + case SST_CURRENT_TIME: + say_time = 1; + break; + default: + break; + } + + if (say_date) { + say_num(tm.tm_year + 1900, SSM_ITERATED); + say_file("time/year.wav"); + say_num(tm.tm_mon + 1, SSM_PRONOUNCED); + say_file("time/month.wav"); + say_num(tm.tm_mday, SSM_PRONOUNCED); + say_file("time/day.wav"); + say_file("time/day-%d.wav", tm.tm_wday); + +#if 0 + tm = *localtime(&then); + + this_morning = switch_micro_time_now(); + switch_time_exp_lt(&tm2, this_morning); + tm2->tm_hour = 0; + tm2->tm_min = 0; + tm2->tm_sec = 0; + this_morning = mktime(tm2); + + if (this_morning <= then && then < (this_morning + 86400L)) + { + say_file("time/today.wav"); + } + else if ((this_morning - 86400L) <= then && then < this_morning) + { + say_file("time/yesterday.wav"); + } + else if ((this_morning + 86400L) <= then && then < (this_morning + 2*86400L)) + { + say_file("time/tomorrow.wav"); + } + else if ((this_morning - 7*86400L) <= then && then < this_morning) + { + say_file("time/day-%d.wav", tm.tm_wday); + } + else + { + if (tm2->tm_year != tm.tm_year) + { + say_num(tm.tm_year + 1900, SSM_ITERATED); + say_file("time/year.wav"); + } + /*endif*/ + if (tm2->tm_year != tm.tm_year + || + tm2->tm_mon != tm.tm_mon) + { + say_num(tm.tm_mon + 1, SSM_PRONOUNCED); + say_file("time/month.wav"); + } + /*endif*/ + /* Always say the day and the day of the week */ + say_num(tm.tm_mday, SSM_PRONOUNCED); + say_file("time/day.wav"); + say_file("time/day-%d.wav", tm.tm_wday); + } +#endif + } + + if (say_time) { + int32_t hour = tm.tm_hour; + + if (hour < 6) { + say_file("time/morning.wav"); + } else if (hour < 12) { + say_file("time/am.wav"); + } else if (tm.tm_hour < 18) { + say_file("time/pm.wav"); + } else { + say_file("time/evening.wav"); + } + if (hour > 12) + hour -= 12; + if (hour == 0) + hour = 12; + + if (hour == 2) { + say_file("time/2s.wav"); + } else { + say_num(hour, SSM_PRONOUNCED); + } + say_file("time/hour.wav"); + if (tm.tm_min == 2) { + say_file("time/2s.wav"); + } else { + say_num(tm.tm_min, SSM_PRONOUNCED); + } + say_file("time/minute.wav"); + } + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t th_say_money(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, + switch_input_args_t *args) +{ + char sbuf[16] = ""; /* enough for 999,999,999,999.99 (w/o the commas or leading $) */ + char *dollars = NULL; + char *cents = NULL; + + if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n"); + return SWITCH_STATUS_GENERR; + } + + dollars = sbuf; + + if ((cents = strchr(sbuf, '.'))) { + *cents++ = '\0'; + if (strlen(cents) > 2) { + cents[2] = '\0'; + } + } + + /* If positive sign - skip over" */ + if (sbuf[0] == '+') { + dollars++; + } + + /* If negative say "negative" */ + if (sbuf[0] == '-') { + say_file("currency/negative.wav"); + dollars++; + } + + /* Say dollar amount */ + th_say_general_count(session, dollars, type, method, args); + say_file("currency/dollar.wav"); + + /* Say cents */ + if (cents) { + th_say_general_count(session, cents, type, method, args); + } else { + say_file("digits/0.wav"); + } + say_file("currency/cent.wav"); + + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t th_say(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args) +{ + switch_say_callback_t say_cb = NULL; + + switch (type) { + case SST_NUMBER: + case SST_ITEMS: + case SST_PERSONS: + case SST_MESSAGES: + say_cb = th_say_general_count; + break; + case SST_TIME_MEASUREMENT: + case SST_CURRENT_DATE: + case SST_CURRENT_TIME: + case SST_CURRENT_DATE_TIME: + say_cb = th_say_time; + break; + case SST_IP_ADDRESS: + say_cb = th_ip; + break; + case SST_NAME_SPELLED: + case SST_NAME_PHONETIC: + say_cb = th_spell; + break; + case SST_CURRENCY: + say_cb = th_say_money; + break; + default: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", type); + break; + } + + if (say_cb) { + return say_cb(session, tosay, type, method, args); + } + + return SWITCH_STATUS_FALSE; +} + +SWITCH_MODULE_LOAD_FUNCTION(mod_say_th_load) +{ + switch_say_interface_t *say_interface; + /* connect my internal structure to the blank pointer passed to me */ + *module_interface = switch_loadable_module_create_module_interface(pool, modname); + say_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_SAY_INTERFACE); + say_interface->interface_name = "th"; + say_interface->say_function = th_say; + + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: + */ Added: freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.vcproj ============================================================================== --- (empty file) +++ freeswitch/branches/dome_2k/tuxza/src/mod/say/mod_say_th/mod_say_th.vcproj Wed Jun 24 05:22:04 2009 @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + +