From aa1eaf20c775a1c2fb7e0eff9a6e62e7d24dd86e Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <manu@manu-laptop.(none)>
Date: Tue, 15 Sep 2009 23:10:32 -0400
Subject: [PATCH] [#2174] Clean up - remove stun settings in client network
 configuration panel

---
 .../src/config/accountconfigdialog.c          |   2 -
 .../src/config/preferencesdialog.c            |  87 +--------
 sflphone-common/libs/Makefile.am              |   2 +-
 sflphone-common/src/Makefile.am               |   1 -
 sflphone-common/src/managerimpl.cpp           |  53 ------
 sflphone-common/src/managerimpl.h             |  47 -----
 sflphone-common/src/sip/sipaccount.h          |   3 +-
 sflphone-common/src/sip/sipvoiplink.cpp       | 173 ++++--------------
 8 files changed, 45 insertions(+), 323 deletions(-)

diff --git a/sflphone-client-gnome/src/config/accountconfigdialog.c b/sflphone-client-gnome/src/config/accountconfigdialog.c
index b8a21586d2..27dd8fbaf0 100644
--- a/sflphone-client-gnome/src/config/accountconfigdialog.c
+++ b/sflphone-client-gnome/src/config/accountconfigdialog.c
@@ -978,8 +978,6 @@ show_account_window (account_t * a)
     		g_hash_table_replace(currentAccount->properties,
     				g_strdup(PUBLISHED_ADDRESS),
     				g_strdup((gchar *)gtk_entry_get_text(GTK_ENTRY(publishedAddressEntry))));	    
-    								    								
-			preferences_dialog_set_stun_visible();
 		}
 
 	    /* Set new credentials if any */
diff --git a/sflphone-client-gnome/src/config/preferencesdialog.c b/sflphone-client-gnome/src/config/preferencesdialog.c
index 4f650b28da..3ee0a2da68 100644
--- a/sflphone-client-gnome/src/config/preferencesdialog.c
+++ b/sflphone-client-gnome/src/config/preferencesdialog.c
@@ -45,10 +45,6 @@ gboolean accDialogOpen = FALSE;
 gboolean dialogOpen = FALSE;
 gboolean ringtoneEnabled = TRUE;
 
-/* STUN configuration part */
-GtkWidget * stunEnable;
-GtkWidget * stunFrame;
-GtkWidget * stunServer;
 GtkWidget * applyButton;
 GtkWidget * history_value;
 
@@ -121,43 +117,13 @@ static void history_enabled_cb (GtkWidget *widget)
     // Toggle it through D-Bus
     dbus_set_history_enabled ();
 }
-
-
-    void
+    
+	void
 clean_history( void )
 {
     calllist_clean_history();
 }
 
-
-void stun_state( void )
-{
-
-    guint stun_enabled = 0;
-
-    gboolean stunActive = (gboolean)gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( stunEnable ));
-    gtk_widget_set_sensitive( GTK_WIDGET( stunServer ) , stunActive );
-
-    // Check if we actually change the state
-    stun_enabled = dbus_stun_is_enabled();
-
-    if( (stunActive && stun_enabled ==0 ) || (!stunActive && stun_enabled ==1))
-    {
-        gtk_widget_set_sensitive( GTK_WIDGET( applyButton ) , TRUE );
-    }
-    else
-        gtk_widget_set_sensitive( GTK_WIDGET( applyButton ) , FALSE );
-
-}
-
-void update_registration( void )
-{
-    dbus_set_stun_server((gchar *)gtk_entry_get_text(GTK_ENTRY(stunServer)));
-    dbus_enable_stun();
-
-    gtk_widget_set_sensitive(GTK_WIDGET(applyButton) , FALSE );
-}
-
 static void show_advanced_zrtp_options_cb(GtkWidget *widget UNUSED, gpointer data)
 {
     DEBUG("Advanced options for ZRTP");
@@ -289,54 +255,10 @@ GtkWidget* create_network_tab()
     GtkWidget * label;
     GtkWidget * ret;
     gchar * description;
-    gchar * stun_server= "stun.sflphone.org:3478";
-    gchar * stun_enabled = "false";
 
     ret = gtk_vbox_new(FALSE, 10);
     gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
 
-    gnome_main_section_new_with_table (_("NAT Traversal"), &frame, &table, 3, 2);
-    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
-    gtk_widget_show (frame);
-    
-    /* Retrieve the STUN configuration */
-    stun_enabled = (dbus_stun_is_enabled()==1)?"true":"false";
-    stun_server = dbus_get_stun_server();
-    
-    gtk_table_set_col_spacings( GTK_TABLE(table), 10);
-    gtk_container_set_border_width(GTK_CONTAINER (table), 10);
-
-    // NAT detection code section
-    description = g_markup_printf_escaped(_("STUN will apply to each SIP account created.\nIt will be effective only after pressing \"apply\", closing all sessions."));
-    label = gtk_label_new(NULL);
-    gtk_label_set_markup(GTK_LABEL(label), description);
-    gtk_table_attach ( GTK_TABLE( table ), label, 0, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-
-    stunEnable = gtk_check_button_new_with_mnemonic( _("E_nable STUN"));
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stunEnable), strcmp(stun_enabled,"true") == 0 ? TRUE: FALSE);
-    g_signal_connect( G_OBJECT (GTK_TOGGLE_BUTTON(stunEnable)) , "toggled" , G_CALLBACK( stun_state ), NULL);
-#if GTK_CHECK_VERSION(2,12,0)
-    gtk_widget_set_tooltip_text( GTK_WIDGET( stunEnable ) , _("You should probably enable this if you are behind a firewall."));
-#endif
-    gtk_table_attach ( GTK_TABLE( table ), stunEnable, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-
-    stunServer = gtk_entry_new();
-    gtk_label_set_mnemonic_widget (GTK_LABEL (label), stunServer);
-    gtk_entry_set_text(GTK_ENTRY(stunServer), stun_server);
-#if GTK_CHECK_VERSION(2,12,0)
-    gtk_widget_set_tooltip_text( GTK_WIDGET( stunServer ) , _("Format : name.server:port"));
-#endif
-    gtk_widget_set_sensitive( GTK_WIDGET( stunServer ), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stunEnable)));
-    gtk_table_attach ( GTK_TABLE( table ), stunServer, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-
-    applyButton = gtk_button_new_from_stock(GTK_STOCK_APPLY);
-    gtk_widget_set_sensitive( GTK_WIDGET( applyButton ), FALSE );
-#if GTK_CHECK_VERSION(2,12,0)
-    gtk_widget_set_tooltip_text( GTK_WIDGET(applyButton) , _("Pressing \"apply\" will restart the network layer. Otherwise, SFLPhone would have to be restarted."));
-#endif
-    g_signal_connect( G_OBJECT( applyButton) , "clicked" , update_registration , NULL);
-    gtk_table_attach ( GTK_TABLE( table ), applyButton, 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
- 
     /** SIP port information */
     int curPort = dbus_get_sip_port();
     if(curPort <= 0 || curPort > 65535) {
@@ -482,11 +404,6 @@ void history_load_configuration ()
         history_enabled = FALSE;
 }
 
-void preferences_dialog_set_stun_visible()
-{
-    gtk_widget_set_sensitive( GTK_WIDGET(stunFrame), TRUE );
-}
-
 /**
  * Show configuration window with tabs
  */
diff --git a/sflphone-common/libs/Makefile.am b/sflphone-common/libs/Makefile.am
index ac4d6a2672..eb4a6b9b9a 100644
--- a/sflphone-common/libs/Makefile.am
+++ b/sflphone-common/libs/Makefile.am
@@ -1 +1 @@
-SUBDIRS = stund utilspp iax2 dbus-c++
+SUBDIRS = utilspp iax2 dbus-c++
diff --git a/sflphone-common/src/Makefile.am b/sflphone-common/src/Makefile.am
index ec1ebffe3f..928aadb91e 100644
--- a/sflphone-common/src/Makefile.am
+++ b/sflphone-common/src/Makefile.am
@@ -64,7 +64,6 @@ noinst_HEADERS = \
 		numbercleaner.h
 
 libsflphone_la_LIBADD = \
-	$(src)/libs/stund/libstun.la \
 	$(src)/libs/utilspp/libutilspp.la \
 	$(src)/libs/iax2/libiax2.la \
 	$(IAX_LIB) \
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index 4078b471a7..dab69f95cf 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -78,9 +78,6 @@ ManagerImpl::ManagerImpl (void)
         , _path ("")
         , _exist (0)
         , _setupLoaded (false)
-        , _firewallPort()
-        , _firewallAddr ("")
-        , _hasZeroconf (false)
         , _callAccountMap()
         , _callAccountMapMutex()
         , _callConfigMap()
@@ -1233,56 +1230,6 @@ void ManagerImpl::notificationIncomingCall (void)
     }
 }
 
-/**
- * Multi Thread
- */
-bool
-ManagerImpl::getStunInfo (StunAddress4& stunSvrAddr, int port)
-{
-    StunAddress4 mappedAddr;
-
-    struct in_addr in;
-    char* addr;
-
-    int fd1 = stunOpenSocket (stunSvrAddr, &mappedAddr, port);
-    bool ok = (fd1 == -1 || fd1 == INVALID_SOCKET) ? false : true;
-
-    if (ok) {
-        closesocket (fd1);
-        _firewallPort = mappedAddr.port;
-        // Convert ipv4 address to host byte ordering
-        in.s_addr = ntohl (mappedAddr.addr);
-        addr = inet_ntoa (in);
-        _firewallAddr = std::string (addr);
-        _debug ("STUN Firewall: [%s:%d]\n", _firewallAddr.data(), _firewallPort);
-        return true;
-    } else {
-        _debug ("Opening a stun socket pair failed\n");
-    }
-
-    return false;
-}
-
-bool
-ManagerImpl::isBehindNat (const std::string& svr, int port)
-{
-    StunAddress4 stunSvrAddr;
-    stunSvrAddr.addr = 0;
-
-    // Convert char* to StunAddress4 structure
-    bool ret = stunParseServerName ( (char*) svr.data(), stunSvrAddr);
-
-    if (!ret) {
-        _debug ("SIP: Stun server address (%s) is not valid\n", svr.data());
-        return 0;
-    }
-
-    // Firewall address
-    _debug ("STUN server: %s\n", svr.data());
-
-    return getStunInfo (stunSvrAddr, port);
-}
-
 
 ///////////////////////////////////////////////////////////////////////////////
 // Private functions
diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h
index 5622f0881e..d5c2c1d3b0 100644
--- a/sflphone-common/src/managerimpl.h
+++ b/sflphone-common/src/managerimpl.h
@@ -30,7 +30,6 @@
 #include <cc++/thread.h>
 #include "dbus/dbusmanager.h"
 
-#include "stund/stun.h"
 #include "observer.h"
 #include "config/config.h"
 
@@ -859,45 +858,6 @@ class ManagerImpl {
      */
     void setMicVolume(unsigned short mic_vol);
 
-    // Manage information about firewall
-
-    /*
-     * Get information about firewall
-     * @param  stunSvrAddr: stun server
-     * @param  port         port number to open to test the connection
-     * @return true if the connection is successful
-     */
-    bool getStunInfo(StunAddress4& stunSvrAddr, int port);
-
-    /*
-     * Inline functions to manage firewall settings
-     * @return int The firewall port
-     */
-    inline int getFirewallPort(void) 		{ return _firewallPort; }
-
-    /*
-     * Inline functions to manage firewall settings
-     * @param port The firewall port
-     */
-    inline void setFirewallPort(int port) 	{ _firewallPort = port; }
-
-    /*
-     * Inline functions to manage firewall settings
-     * @return std::string The firewall address
-     */
-    inline std::string getFirewallAddress (void) 	{ return _firewallAddr; }
-
-    /**
-     * If you are behind a NAT, you have to use STUN server, specified in
-     * STUN configuration(you can change this one by default) to give you an
-     * public IP address and assign a port number.
-     * Note: Set firewall port/address retreive
-     * @param svr   Server on which to send request
-     * @param port  On which port we want to listen to
-     * @return true if we are behind a NAT (without error)
-     */
-    bool isBehindNat(const std::string& svr, int port);
-
     /**
      * Init default values for the different fields in the config file.
      * Fills the local _config (Conf::ConfigTree) with the default contents.
@@ -1095,13 +1055,6 @@ class ManagerImpl {
     int _exist;
     int _setupLoaded;
 
-    // To handle firewall
-    int _firewallPort;
-    std::string _firewallAddr;
-
-    // tell if we have zeroconf is enabled
-    int _hasZeroconf;
-
 #ifdef USE_ZEROCONF
     // DNSService contain every zeroconf services
     //  configuration detected on the network
diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h
index ba01d608fe..b6d7b62f59 100644
--- a/sflphone-common/src/sip/sipaccount.h
+++ b/sflphone-common/src/sip/sipaccount.h
@@ -127,6 +127,7 @@ class SIPAccount : public Account
          * an alternate UDP transport.
          */
         inline pj_str_t getStunServerName(void) { return _stunServerName; }
+		inline void setStunServerName (pj_str_t srv) { _stunServerName = srv; }
 
 		/**
          * @return pj_uint8_t structure, filled from the configuration
@@ -134,7 +135,7 @@ class SIPAccount : public Account
          * an alternate UDP transport.
          */
         inline pj_uint16_t getStunPort (void) { return _stunPort; }
-        
+		inline void setStunPort (pj_uint16_t port) { _stunPort = port; }
         
         /**
          * @return bool Tells if current transport for that 
diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index 8b867066ae..a18b27288b 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -135,6 +135,11 @@ void set_voicemail_info (AccountID account, pjsip_msg_body *body);
 
 // Documentated from the PJSIP Developer's Guide, available on the pjsip website/
 
+
+pj_bool_t stun_sock_on_status (pj_stun_sock *stun_sock, pj_stun_sock_op op, pj_status_t status);
+pj_bool_t stun_sock_on_rx_data (pj_stun_sock *stun_sock, void *pkt, unsigned pkt_len, const pj_sockaddr_t *src_addr, unsigned addr_len);
+
+
 /*
  * Session callback
  * Called when the invite session state has changed.
@@ -455,7 +460,6 @@ int SIPVoIPLink::sendRegister (AccountID id)
 		}
 	}
 
-
     _mutexSIP.enterMutex();
 
     // Get the client registration information for this particular account
@@ -1606,7 +1610,6 @@ pj_status_t SIPVoIPLink::enable_dns_srv_resolver (pjsip_endpoint *endpt, pj_dns_
 
 }
 
-
 bool SIPVoIPLink::pjsip_init()
 {
     pj_status_t status;
@@ -1615,8 +1618,6 @@ bool SIPVoIPLink::pjsip_init()
     pjsip_inv_callback inv_cb;
     pj_str_t accepted;
     std::string name_mod;
-    bool useStun;
-    validStunServer = true;
     pj_dns_resolver *p_resv;
 
     name_mod = "sflphone";
@@ -1662,22 +1663,6 @@ bool SIPVoIPLink::pjsip_init()
     }
 
     port = _regPort;
-
-    /* Retrieve the STUN configuration */
-    //useStun = Manager::instance().getConfigBool (SIGNALISATION, SIP_USE_STUN);
-	useStun = false;
-
-	/*
-    if (useStun && !Manager::instance().isBehindNat (getStunServer(), port)) {
-        port = RANDOM_SIP_PORT;
-
-        if (!Manager::instance().isBehindNat (getStunServer(), port)) {
-            _debug ("UserAgent: Unable to check NAT setting\n");
-            validStunServer = false;
-            return false; // hoho we can't use the random sip port too...
-        }
-    }*/
-
     _localPort = port;
 
     // Retrieve Direct IP Calls settings.
@@ -1693,25 +1678,16 @@ bool SIPVoIPLink::pjsip_init()
         directIpCallsTlsEnabled = account->isTlsEnabled();
     }
 
-    if (useStun) {
-        // set by last isBehindNat() call (ish)...
-        //stunServerResolve();
-        _localExternAddress = Manager::instance().getFirewallAddress();
-        _localExternPort = Manager::instance().getFirewallPort();
-    } else {
-        _localExternAddress = _localIPAddress;
-        _localExternPort = _localPort;
-        errPjsip = createUDPServer();
-    }
-
+    _localExternAddress = _localIPAddress;
+    _localExternPort = _localPort;
     // Create a UDP listener meant for all accounts
     // for which TLS was not enabled
     errPjsip = createUDPServer();
 
-    // If stun was not enabled an the above UDP server
+    // If the above UDP server
     // could not be created, then give it another try
     // on a random sip port
-    if (errPjsip != PJ_SUCCESS && !useStun) {
+    if (errPjsip != PJ_SUCCESS) {
         _debug ("UserAgent: Could not initialize SIP listener on port %d\n", _localExternPort);
         _localExternPort = _localPort = RANDOM_SIP_PORT;
 
@@ -1724,16 +1700,6 @@ bool SIPVoIPLink::pjsip_init()
         }
     }
 
-    // If we use stun and UDP server creation
-    // failed, then just complain and return
-    // since retrying on a random sip port
-    // would just go against the need of
-    // using it.
-    if (errPjsip != PJ_SUCCESS && useStun) {
-        _debug ("Could not create UDP server with STUN\n");
-        return errPjsip;
-    }
-
     _debug ("UserAgent: SIP Init -- listening on port %d\n", _localExternPort);
 
     // Create a TLS listener meant for Direct IP calls
@@ -1842,13 +1808,12 @@ bool SIPVoIPLink::pjsip_init()
 
 pj_status_t SIPVoIPLink::stunServerResolve (AccountID id)
 {
-    pj_str_t stun_adr, stunServer, hostPart;
+    pj_str_t stunServer;
 	pj_uint16_t stunPort;
 	pj_stun_sock_cb stun_sock_cb;
 	pj_stun_sock *stun_sock;
     pj_stun_config stunCfg;
     pj_status_t status;
-	const int af = pj_AF_INET();
 
 	// Fetch the account information from the config file
 	SIPAccount * account = NULL;
@@ -1867,9 +1832,9 @@ pj_status_t SIPVoIPLink::stunServerResolve (AccountID id)
 
     status = PJ_EPENDING;
 
-	//pj_bzero (&stun_sock_cb, sizeof(stun_sock_cb));
-	//stun_sock_cb.on_rx_data = &stun_sock_on_rx_data;
-	//stun_sock_cb.on_status = &stun_sock_on_status;
+	pj_bzero (&stun_sock_cb, sizeof(stun_sock_cb));
+	stun_sock_cb.on_rx_data = &stun_sock_on_rx_data;
+	stun_sock_cb.on_status = &stun_sock_on_status;
 
 	status = pj_stun_sock_create (&stunCfg, "stunresolve", pj_AF_INET(), &stun_sock_cb, NULL, NULL, &stun_sock);
 
@@ -2092,15 +2057,13 @@ pj_status_t SIPVoIPLink::createTlsTransportRetryOnFailure (AccountID id)
 
 pj_status_t SIPVoIPLink::createAlternateUdpTransport (AccountID id)
 {
-    pj_sockaddr_in boundAddr, local_addr, bound_addr;
+    pj_sockaddr_in boundAddr;
     pjsip_host_port a_name;
     pj_status_t status;
-	pj_str_t stunServer, pjAddress;
-    pj_str_t hostPart;
-	pj_uint16_t stunPort, port;
+	pj_str_t stunServer;
+	pj_uint16_t stunPort;
 	pj_sockaddr_in pub_addr;
 	pj_sock_t sock;
-	pj_sockaddr stunSrvSocket;
 
     /* 
 	 * Retrieve the account information
@@ -2119,7 +2082,7 @@ pj_status_t SIPVoIPLink::createAlternateUdpTransport (AccountID id)
 	status = stunServerResolve (id);
 		
 	if (status != PJ_SUCCESS) {
-		_debug ("Error resolving STUN server: %s\n", status);
+		_debug ("Error resolving STUN server: %i\n", status);
 		return status;
 	}
 
@@ -2140,49 +2103,7 @@ pj_status_t SIPVoIPLink::createAlternateUdpTransport (AccountID id)
     	return status;
     }
 
-/*
-	status = pj_sockaddr_in_set_str_addr (PJ_AF_INET, &stunSrvSocket, &pjAddress);
-	if (status != PJ_SUCCESS) {
-		_debug ("Failed to set published address in %d\n", __LINE__);
-		return status;
-	}
-*/
-/*
-	pj_sockaddr_in_init (&local_addr, 0, 0);
-
-    pj_uint16_t localUdpPort = account->getLocalPort();
-
-    if (localUdpPort != 0) {
-        local_addr.sin_port = pj_htons (localUdpPort);
-    }
-
-    std::string localAddress = account->getLocalAddress();
-
-    if (!localAddress.empty()) {
-    	pj_str_t pjAddress;
-        pj_cstr (&pjAddress, localAddress.c_str());
-
-        pj_status_t success;
-        success = pj_sockaddr_in_set_str_addr (&local_addr, &pjAddress);
-
-        if (success != PJ_SUCCESS) {
-            _debug ("Failed to set published address in %d\n", __LINE__);
-        }
-    }
-
-*/
-    /* Init published name 
-    pj_bzero (&a_name, sizeof (pjsip_host_port));
-
-    pj_cstr (&a_name.host, (account->getPublishedAddress()).c_str());
-
-    a_name.port = account->getPublishedPort();
-
-    _debug ("Alternate UDP transport to be initialized with published address %.*s,"
-            " published port %d, local address %s, local port %d\n",
-            (int) a_name.host.slen, a_name.host.ptr,
-            (int) a_name.port, localAddress.c_str(), (int) localUdpPort);
-	*/
+	// Query the mapped IP address and port on the 'outside' of the NAT
 	status = pjstun_get_mapped_addr (&_cp.factory, 1, &sock, &stunServer, stunPort, &stunServer, stunPort, &pub_addr);
 	
 	if (status != PJ_SUCCESS) {
@@ -2195,48 +2116,21 @@ pj_status_t SIPVoIPLink::createAlternateUdpTransport (AccountID id)
               pj_inet_ntoa (pub_addr.sin_addr),
               pj_ntohs(pub_addr.sin_port));
 
-	// Create UDP-Server (default port: 5060)
-    // char tmpIP[32];
-    // strcpy (tmpIP, stunServer.ptr);
-    // pj_strdup2 (_pool, &a_name.host, tmpIP);
-    //a_name.port = (pj_uint16_t) stunPort;
 	a_name.host = pj_str (pj_inet_ntoa (pub_addr.sin_addr));
     a_name.port = pj_ntohs(pub_addr.sin_port);
 
+	_localExternAddress = std::string (a_name.host.ptr);
+	_localExternPort =  (int)a_name.port;
+	//account->setStunServerName (a_name.host);
+	//account->setStunPort (a_name.port);
+
+	// Create the UDP transport
 	pjsip_udp_transport_attach2 (_endpt, PJSIP_TRANSPORT_UDP, sock, &a_name, 1, NULL);
     if (status != PJ_SUCCESS) {
         _debug ("Error creating alternate SIP UDP listener (%d)\n", status);
     }
 
     return PJ_SUCCESS;
-
-    // Init bound address to ANY
-	/*
-    pj_memset (&bound_addr, 0, sizeof (bound_addr));
-
-    bound_addr.sin_addr.s_addr = pj_htonl (PJ_INADDR_ANY);
-    bound_addr.sin_port = pj_htons ( (pj_uint16_t) _localPort);
-    bound_addr.sin_family = PJ_AF_INET;
-    pj_bzero (bound_addr.sin_zero, sizeof (bound_addr.sin_zero));
-
-    // Create UDP-Server (default port: 5060)
-    strcpy (tmpIP, stunServer.ptr);
-    pj_strdup2 (_pool, &a_name.host, tmpIP);
-    a_name.port = (pj_uint16_t) stunPort;
-
-    //status = pjsip_udp_transport_start (_endpt, &bound_addr, &a_name, 1, NULL);
-
-    if (status != PJ_SUCCESS) {
-        _debug ("UserAgent: (%d) Unable to start UDP transport!\n", status);
-        return -1;
-    } else {
-        _debug ("UserAgent: UDP server listening on port %d\n", _localExternPort);
-    }
-
-    _debug ("Transport initialized successfully! \n");
-
-    return PJ_SUCCESS;
-*/
 }
 
 
@@ -3546,9 +3440,9 @@ bool setCallAudioLocal (SIPCall* call, std::string localIP)
 
     	if (account->isStunEnabled ()) {
         	// If use Stun server
-        	if (Manager::instance().isBehindNat (std::string (account->getStunServerName ().ptr), callLocalAudioPort)) {
-            	callLocalExternAudioPort = Manager::instance().getFirewallPort();
-        	}
+        	//if (Manager::instance().isBehindNat (std::string (account->getStunServerName ().ptr), callLocalAudioPort)) {
+            	callLocalExternAudioPort = account->getStunPort ();//localExternPort; //Manager::instance().getFirewallPort();
+        	//}
     	}
 
     	_debug ("            Setting local audio port to: %d\n", callLocalAudioPort);
@@ -3625,3 +3519,16 @@ std::vector<std::string> SIPVoIPLink::getAllIpInterface (void)
     }
 }
 
+
+pj_bool_t stun_sock_on_status (pj_stun_sock *stun_sock, pj_stun_sock_op op, pj_status_t status)
+{
+	if (status == PJ_SUCCESS)
+		return PJ_TRUE;
+	else
+		return PJ_FALSE;
+}
+
+pj_bool_t stun_sock_on_rx_data (pj_stun_sock *stun_sock, void *pkt, unsigned pkt_len, const pj_sockaddr_t *src_addr, unsigned addr_len)
+{
+	return PJ_TRUE;
+}
-- 
GitLab