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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Sun Mar 6 18:09:26 CST 2011


branch "configuration" has been updated
       via  72138cabee93955fb3d648ac78c1faea422e2733 (commit)
      from  01940e42606ff1b41b53778a2b5148021be8d80b (commit)

Summary of changes:
 src/PJSipManager.cpp     |   18 +++++++
 src/PJSipManager.h       |    5 ++
 src/SipConfiguration.cpp |  124 +++++++++++++++++++++++++++++++++++-----------
 3 files changed, 117 insertions(+), 30 deletions(-)


- Log -----------------------------------------------------------------
commit 72138cabee93955fb3d648ac78c1faea422e2733
Author: Joshua Colp <jcolp at digium.com>
Date:   Sun Mar 6 20:10:21 2011 -0400

    Add support for configuring TCP transports.

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 8fbaca9..5140eac 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -161,6 +161,24 @@ pjsip_transport *PJSipManager::createUDPTransport(std::string address, int port)
     return udpTransport;
 }
 
+pjsip_tpfactory *PJSipManager::createTCPTransport(std::string address, int port)
+{
+    pj_sockaddr tcpAddr;
+    pj_str_t tcpString;
+    pj_cstr(&tcpString, address.c_str());
+    pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &tcpString, &tcpAddr);
+    pj_sockaddr_set_port(&tcpAddr, port);
+
+    pjsip_tpfactory *tcpTransport = NULL;
+
+    if (pjsip_tcp_transport_start(mEndpoint, &tcpAddr, 2, &tcpTransport) != PJ_SUCCESS)
+    {
+	lg(Error) << "Failed to create TCP transport.";
+    }
+
+    return tcpTransport;
+}
+
 }; //End namespace SipSessionManager
 
 }; //End namespace AsteriskSCF
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index fde60b6..106da1e 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -85,6 +85,11 @@ public:
      * Create a UDP transport.
      */
     pjsip_transport *createUDPTransport(std::string, int);
+
+    /**
+     * Create a TCP transport.
+     */
+    pjsip_tpfactory *createTCPTransport(std::string, int);
 private:
     static PJSipManager *mInstance;
     pjsip_endpoint *mEndpoint;
diff --git a/src/SipConfiguration.cpp b/src/SipConfiguration.cpp
index 9732c6e..52de50e 100644
--- a/src/SipConfiguration.cpp
+++ b/src/SipConfiguration.cpp
@@ -77,6 +77,46 @@ public:
     pjsip_transport *mTransport;
 };
 
+class TCPTransportImplPriv
+{
+public:
+    /**
+     * Constructor implementation for this
+     */
+    TCPTransportImplPriv() : mTransportFactory(0) { };
+
+    /**
+     * Destructor implementation that shuts down the transport gracefully if we go away
+     */
+    ~TCPTransportImplPriv()
+    {
+        if (mTransportFactory)
+        {
+            // I hope in the future it will be possible to shut down TCP based transports but for now... it is not
+        }
+    };
+
+    /**
+     * Address itself.
+     */
+    std::string mAddress;
+
+    /**
+     * Can't forget the port.
+     */
+    int mPort;
+
+    /**
+     * Configuration group itself.
+     */
+    SipTransportGroupPtr mGroup;
+
+    /**
+     * Transport factory within pjsip.
+     */
+    pjsip_tpfactory *mTransportFactory;
+};
+
 class ConfigurationServiceImplPriv
 {
 public:
@@ -98,7 +138,7 @@ public:
     /**
      * Configured TCP SIP transports
      */
-    std::map<std::string, SipTCPTransportGroupPtr> mConfiguredTCPTransports;
+    std::map<std::string, boost::shared_ptr<TCPTransportImplPriv> > mConfiguredTCPTransports;
     
     /**
      * Configured TLS SIP transports
@@ -211,7 +251,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskS
 	
 	void visitSipTCPTransportGroup(const ::AsteriskSCF::SIP::V1::SipTCPTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTCPTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
+	    std::map<std::string,  boost::shared_ptr<TCPTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTCPTransports.end())
 	    {
@@ -221,7 +261,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskS
 	    SipTCPTransportGroupPtr returnedGroup = new SipTCPTransportGroup();
 	    returnedGroup->name = group->name;
 	    
-	    insertRequestedConfigurationItems(group->configurationItems, (*localTransport).second->configurationItems, returnedGroup->configurationItems);
+	    insertRequestedConfigurationItems(group->configurationItems, (*localTransport).second->mGroup->configurationItems, returnedGroup->configurationItems);
 	    
 	    mGroups.push_back(returnedGroup);
 	};
@@ -319,14 +359,14 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(const Asteri
 	
 	void visitSipTCPTransportGroup(const ::AsteriskSCF::SIP::V1::SipTCPTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTCPTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
+	    std::map<std::string,  boost::shared_ptr<TCPTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTCPTransports.end())
 	    {
 		return;
 	    }
 	    
-	    mGroups.push_back((*localTransport).second);
+	    mGroups.push_back((*localTransport).second->mGroup);
 	};
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
@@ -396,12 +436,12 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationGroups(const Ice
 	groups.push_back(transport);
     }
     
-    for (std::map<std::string, SipTCPTransportGroupPtr>::iterator group = mImplPriv->mConfiguredTCPTransports.begin();
+    for (std::map<std::string,  boost::shared_ptr<TCPTransportImplPriv> >::iterator group = mImplPriv->mConfiguredTCPTransports.begin();
 	 group != mImplPriv->mConfiguredTCPTransports.end();
 	 ++group)
     {
 	SipTCPTransportGroupPtr transport = new SipTCPTransportGroup();
-	transport->name = (*group).second->name;
+	transport->name = (*group).second->mGroup->name;
 	groups.push_back(transport);
     }
     
@@ -586,36 +626,60 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::Confi
 	
 	void visitSipTCPTransportGroup(const ::AsteriskSCF::SIP::V1::SipTCPTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTCPTransportGroupPtr>::iterator localTransportGroup = mImplPriv->mConfiguredTCPTransports.find(group->name);
-	    SipTCPTransportGroupPtr localTransport;
+	    std::map<std::string,  boost::shared_ptr<TCPTransportImplPriv> >::iterator localTransportGroup = mImplPriv->mConfiguredTCPTransports.find(group->name);
+	    boost::shared_ptr<TCPTransportImplPriv> localTransport;
 	    
 	    if (localTransportGroup == mImplPriv->mConfiguredTCPTransports.end())
 	    {
-		localTransport = new SipTCPTransportGroup;
-		localTransport->name = group->name;
+		boost::shared_ptr<TCPTransportImplPriv> newTransport(new TCPTransportImplPriv());
+                localTransport = newTransport;
+                localTransport->mGroup = new SipTCPTransportGroup;
+                localTransport->mGroup->name = group->name;
 		mImplPriv->mConfiguredTCPTransports.insert(make_pair(group->name, localTransport));
 	    }
 	    else
 	    {
 		localTransport = (*localTransportGroup).second;
-		performSerialCheck(group->configurationItems, localTransport->configurationItems);
+		performSerialCheck(group->configurationItems, localTransport->mGroup->configurationItems);
 	    }
 	    
-	    class tcpTransportItemsVisitor : public SipConfigurationItemVisitor
-	    {
-	    public:
-	    private:
-	    };
-	    
-	    SipConfigurationItemVisitorPtr tcpTransportVisitor = new tcpTransportItemsVisitor();
-	    
-	    for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
-		 item != group->configurationItems.end();
-		 ++item)
-	    {
-		localTransport->configurationItems.insert(make_pair((*item).first, (*item).second));
-		(*item).second->visit(tcpTransportVisitor);
-	    }
+            class tcpTransportItemsVisitor : public SipConfigurationItemVisitor
+            {
+            public:
+                tcpTransportItemsVisitor(boost::shared_ptr<TCPTransportImplPriv> localTransport) : mLocalTransport(localTransport) { };
+
+                void visitSipHostItem(const ::AsteriskSCF::SIP::V1::SipHostItemPtr& hostItem)
+                {
+                    mLocalTransport->mAddress = hostItem->host;
+                    mLocalTransport->mPort = hostItem->port;
+                };
+            private:
+		boost::shared_ptr<TCPTransportImplPriv> mLocalTransport;
+            };
+
+	    std::string oldAddress = localTransport->mAddress;
+            int oldPort = localTransport->mPort;
+
+            SipConfigurationItemVisitorPtr tcpTransportVisitor = new tcpTransportItemsVisitor(localTransport);
+
+            for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
+                 item != group->configurationItems.end();
+                 ++item)
+            {
+                localTransport->mGroup->configurationItems.insert(make_pair((*item).first, (*item).second));
+                (*item).second->visit(tcpTransportVisitor);
+            }
+
+            // Reconcile all the changes received
+            if (oldAddress != localTransport->mAddress || oldPort != localTransport->mPort)
+            {
+                if (localTransport->mTransportFactory)
+                {
+		    // I hope eventually it becomes possible to do this... but for now it is not
+                }
+
+                localTransport->mTransportFactory = mImplPriv->mPJSipManager->createTCPTransport(localTransport->mAddress, localTransport->mPort);
+            }
 	};
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
@@ -822,7 +886,7 @@ void ConfigurationServiceImpl::removeConfigurationItems(const AsteriskSCF::Syste
 	
 	void visitSipTCPTransportGroup(const ::AsteriskSCF::SIP::V1::SipTCPTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTCPTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
+	    std::map<std::string, boost::shared_ptr<TCPTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTCPTransports.end())
 	    {
@@ -835,7 +899,7 @@ void ConfigurationServiceImpl::removeConfigurationItems(const AsteriskSCF::Syste
 	    private:
 	    } tcpTransportVisitor;
 	    
-	    removeItems(&tcpTransportVisitor, group->configurationItems, (*localTransport).second->configurationItems);
+	    removeItems(&tcpTransportVisitor, group->configurationItems, (*localTransport).second->mGroup->configurationItems);
 	};
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
@@ -931,7 +995,7 @@ void ConfigurationServiceImpl::removeConfigurationGroups(const AsteriskSCF::Syst
 	
 	void visitSipTCPTransportGroup(const ::AsteriskSCF::SIP::V1::SipTCPTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTCPTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
+	    std::map<std::string, boost::shared_ptr<TCPTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTCPTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTCPTransports.end())
 	    {

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list