[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "nat-support" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Jun 30 13:55:09 CDT 2011


branch "nat-support" has been updated
       via  e1867c092bbb2f049cabdb9404d7dd9c7fb90281 (commit)
      from  b901144df14b14678f9af78bd274c39a995ea506 (commit)

Summary of changes:
 src/STUNTransport.cpp |   50 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)


- Log -----------------------------------------------------------------
commit e1867c092bbb2f049cabdb9404d7dd9c7fb90281
Author: Brent Eagles <beagles at digium.com>
Date:   Thu Jun 30 16:22:27 2011 -0230

    Fixed a bug resulting from a mixup over a field in one of the pjsip structures.

diff --git a/src/STUNTransport.cpp b/src/STUNTransport.cpp
index b0942fd..1b509b4 100644
--- a/src/STUNTransport.cpp
+++ b/src/STUNTransport.cpp
@@ -28,6 +28,7 @@
 
 #include <boost/thread.hpp>
 #include <boost/thread/locks.hpp>
+#include <boost/enable_shared_from_this.hpp>
 #include <pjsip.h>
 
 using namespace AsteriskSCF::System::Logging;
@@ -44,7 +45,16 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-class STUNTransport : public Transport
+class STUNTransport;
+typedef boost::shared_ptr<STUNTransport> STUNTransportPtr;
+
+struct STUNTransportStruct : public pjsip_transport
+{
+    STUNTransportPtr stunTransport; 
+};
+typedef boost::shared_ptr<STUNTransportStruct> STUNTransportStructPtr;
+
+class STUNTransport : public Transport, public boost::enable_shared_from_this<STUNTransport>
 {
 private:
     /**
@@ -101,8 +111,15 @@ private:
     static pj_status_t sendMsgImplCB(pjsip_transport* transport, pjsip_tx_data* data, const pj_sockaddr_t* remoteAddress,
         int remoteAddressLength, void* token, pjsip_transport_callback callback)
     {
-        STUNTransport* t = reinterpret_cast<STUNTransport*>(transport->data);
-        return t->sendData(data, remoteAddress, remoteAddressLength, token, callback);
+        STUNTransportStruct* t = static_cast<STUNTransportStruct*>(transport);
+        data->op_key.tdata = data;
+        data->op_key.token = token;
+        data->op_key.callback = callback;
+        pj_status_t sendResult = t->stunTransport->sendData(data, remoteAddress, remoteAddressLength, token, callback);
+        if (sendResult != PJ_EPENDING)
+        {
+            data->op_key.tdata = 0;
+        }
     }
 
     static pj_status_t shutdownImplCB(pjsip_transport*)
@@ -115,8 +132,9 @@ private:
 
     static pj_status_t destroyImplCB(pjsip_transport* transport)
     {
-        STUNTransport* t = reinterpret_cast<STUNTransport*>(transport->data);
-        t->destroy();
+        STUNTransportStruct* t = static_cast<STUNTransportStruct*>(transport);
+        t->stunTransport->destroy();
+        t->stunTransport.reset();
         return PJ_SUCCESS;
     }
 
@@ -233,7 +251,7 @@ private:
     pjsip_endpoint* mEndpoint;
     STUNModulePtr mModule;
     pj_stun_sock* mSocket;
-    boost::shared_ptr<pjsip_transport> mTransport;
+    STUNTransportStructPtr mTransport;
     AsteriskSCF::Helpers::AddressPtr mMappedAddress;
 
     void destroyImpl()
@@ -269,17 +287,17 @@ private:
         return mTransport;
     }
 
-    boost::shared_ptr<pjsip_transport> resetCurrentTransport(const boost::shared_ptr<pjsip_transport>& transport)
+    STUNTransportStructPtr resetCurrentTransport(const STUNTransportStructPtr& transport)
     {
         boost::unique_lock<boost::shared_mutex> lock(mLock);
-        boost::shared_ptr<pjsip_transport> current = mTransport;
+        STUNTransportStructPtr current = mTransport;
         mTransport = transport;
         return current;
     }
 
     void updateBinding(const pj_stun_sock_info& socketInfo)
     {
-        boost::shared_ptr<pjsip_transport> newTransport(new pjsip_transport);
+        STUNTransportStructPtr newTransport(new STUNTransportStruct);
         initTransport(newTransport, socketInfo);
         pj_status_t result = pjsip_transport_register(newTransport->tpmgr, newTransport.get());
         if (fail(result))
@@ -291,17 +309,17 @@ private:
         //
         // TODO: The order of register and destroy might have to be reversed for this to work properly.
         //
-        boost::shared_ptr<pjsip_transport> oldTransport = resetCurrentTransport(newTransport);
+        STUNTransportStructPtr oldTransport = resetCurrentTransport(newTransport);
         if (oldTransport)
         {
             pjsip_transport_destroy(oldTransport.get());
         }
     }
 
-    void initTransport(const boost::shared_ptr<pjsip_transport>& transport, const pj_stun_sock_info& socketInfo)
+    void initTransport(const STUNTransportStructPtr& transport, const pj_stun_sock_info& socketInfo)
     {
         assert(transport != 0);
-        memset(transport.get(), 0, sizeof *transport);
+        memset(transport.get(), 0, sizeof(STUNTransportStruct));
         strcpy(transport->obj_name, "ASCFSTUN"); // TODO: proper name initialization.
         transport->send_msg = &sendMsgImplCB;
         transport->do_shutdown = &shutdownImplCB;
@@ -309,7 +327,8 @@ private:
         transport->endpt = mEndpoint;
         transport->tpmgr = pjsip_endpt_get_tpmgr(mEndpoint);
         transport->pool = mModule->getPool();
-        transport->data = this;
+        transport->data = 0;
+        transport->stunTransport = shared_from_this();
 
         pj_status_t result = pj_atomic_create(transport->pool, 0, &transport->ref_cnt);
         if (fail(result))
@@ -350,8 +369,7 @@ private:
         data->tp_info.transport = transport.get();
         data->tp_info.tp_data = 0;
         data->tp_info.op_key.rdata = data;
-        pj_ioqueue_op_key_init(&(data->tp_info.op_key.op_key), sizeof data->tp_info.op_key.op_key);
-
+        pj_ioqueue_op_key_init(&(data->tp_info.op_key.op_key), sizeof(pj_ioqueue_op_key_t));
 
         pj_gettimeofday(&data->pkt_info.timestamp);
         if (packetLength > sizeof data->pkt_info.packet)
@@ -373,7 +391,7 @@ private:
     pj_status_t sendData(pjsip_tx_data* data, const pj_sockaddr_t* remoteAddress, int remoteAddressLength, 
         void*, pjsip_transport_callback)
     {
-        return pj_stun_sock_sendto(mSocket, &data->op_key.key, &data->buf.start,
+        return pj_stun_sock_sendto(mSocket, (pj_ioqueue_op_key_t*)&data->op_key, &data->buf.start,
                 static_cast<pj_uint16_t>(data->buf.cur - data->buf.start), 0,
             remoteAddress, remoteAddressLength);
     }

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list