[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
Mon Mar 7 06:20:22 CST 2011


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

Summary of changes:
 src/PJSipManager.cpp     |   19 ++++++++
 src/PJSipManager.h       |    5 ++
 src/SipConfiguration.cpp |  114 +++++++++++++++++++++++++++++++++++++---------
 3 files changed, 116 insertions(+), 22 deletions(-)


- Log -----------------------------------------------------------------
commit e37d9494e7db63a6f9e0798020dc3de62533da91
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Mar 7 08:20:43 2011 -0400

    Add TLS transport configuration support. Since pjsip does not yet support IPv6 on TLS the actual code that starts the transport is currently commented out.

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 5140eac..e13e846 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -179,6 +179,25 @@ pjsip_tpfactory *PJSipManager::createTCPTransport(std::string address, int port)
     return tcpTransport;
 }
 
+pjsip_tpfactory *PJSipManager::createTLSTransport(std::string address, int port, pjsip_tls_setting *tlsSettings)
+{
+    pj_sockaddr tlsAddr;
+    pj_str_t tlsString;
+    pj_cstr(&tlsString, address.c_str());
+    pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &tlsString, &tlsAddr);
+    pj_sockaddr_set_port(&tlsAddr, port);
+
+    pjsip_tpfactory *tlsTransport = NULL;
+
+/*
+    if (pjsip_tls_transport_start(mEndpoint, tlsSettings, &tlsAddr, NULL, 2, &tlsTransport) != PJ_SUCCESS)
+    {
+        lg(Error) << "Failed to create TLS transport.";
+    }
+*/
+    return tlsTransport;
+}
+
 }; //End namespace SipSessionManager
 
 }; //End namespace AsteriskSCF
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 106da1e..8c78987 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -90,6 +90,11 @@ public:
      * Create a TCP transport.
      */
     pjsip_tpfactory *createTCPTransport(std::string, int);
+
+    /**
+     * Create a TLS transport.
+     */
+    pjsip_tpfactory *createTLSTransport(std::string, int, pjsip_tls_setting*);
 private:
     static PJSipManager *mInstance;
     pjsip_endpoint *mEndpoint;
diff --git a/src/SipConfiguration.cpp b/src/SipConfiguration.cpp
index 52de50e..1243bba 100644
--- a/src/SipConfiguration.cpp
+++ b/src/SipConfiguration.cpp
@@ -109,7 +109,52 @@ public:
     /**
      * Configuration group itself.
      */
-    SipTransportGroupPtr mGroup;
+    SipTCPTransportGroupPtr mGroup;
+
+    /**
+     * Transport factory within pjsip.
+     */
+    pjsip_tpfactory *mTransportFactory;
+};
+
+class TLSTransportImplPriv
+{
+public:
+    /**
+     * Constructor implementation for this
+     */
+    TLSTransportImplPriv() : mTransportFactory(0) { pjsip_tls_setting_default(&mTLSSettings); };
+
+    /**
+     * Destructor implementation that shuts down the transport gracefully if we go away
+     */
+    ~TLSTransportImplPriv()
+    {
+        if (mTransportFactory)
+        {
+            // Too bad this isn't possible right now
+        }
+    };
+
+    /**
+     * Address itself.
+     */
+    std::string mAddress;
+
+    /**
+     * Can't forget the port.
+     */
+    int mPort;
+
+    /**
+     * pjsip TLS settings.
+     */
+    pjsip_tls_setting mTLSSettings;
+
+    /**
+     * Configuration group itself.
+     */
+    SipTLSTransportGroupPtr mGroup;
 
     /**
      * Transport factory within pjsip.
@@ -143,7 +188,7 @@ public:
     /**
      * Configured TLS SIP transports
      */
-    std::map<std::string, SipTLSTransportGroupPtr> mConfiguredTLSTransports;
+    std::map<std::string, boost::shared_ptr<TLSTransportImplPriv> > mConfiguredTLSTransports;
     
     /**
      * Configured SIP endpoints
@@ -268,7 +313,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskS
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTLSTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
+	    std::map<std::string, boost::shared_ptr<TLSTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTLSTransports.end())
 	    {
@@ -278,7 +323,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskS
 	    SipTLSTransportGroupPtr returnedGroup = new SipTLSTransportGroup();
 	    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);
 	};
@@ -371,14 +416,14 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(const Asteri
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTLSTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
+	    std::map<std::string, boost::shared_ptr<TLSTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTLSTransports.end())
 	    {
 		return;
 	    }
 	    
-	    mGroups.push_back((*localTransport).second);
+	    mGroups.push_back((*localTransport).second->mGroup);
 	};
 	
 	void visitSipEndpointGroup(const ::AsteriskSCF::SIP::V1::SipEndpointGroupPtr& group)
@@ -445,12 +490,12 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationGroups(const Ice
 	groups.push_back(transport);
     }
     
-    for (std::map<std::string, SipTLSTransportGroupPtr>::iterator group = mImplPriv->mConfiguredTLSTransports.begin();
+    for (std::map<std::string, boost::shared_ptr<TLSTransportImplPriv> >::iterator group = mImplPriv->mConfiguredTLSTransports.begin();
 	 group != mImplPriv->mConfiguredTLSTransports.end();
 	 ++group)
     {
 	SipTLSTransportGroupPtr transport = new SipTLSTransportGroup();
-	transport->name = (*group).second->name;
+	transport->name = (*group).second->mGroup->name;
 	groups.push_back(transport);
     }
     
@@ -684,36 +729,61 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::Confi
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTLSTransportGroupPtr>::iterator localTransportGroup = mImplPriv->mConfiguredTLSTransports.find(group->name);
-	    SipTLSTransportGroupPtr localTransport;
-	    
+	    std::map<std::string,  boost::shared_ptr<TLSTransportImplPriv> >::iterator localTransportGroup = mImplPriv->mConfiguredTLSTransports.find(group->name);
+            boost::shared_ptr<TLSTransportImplPriv> localTransport;
+
 	    if (localTransportGroup == mImplPriv->mConfiguredTLSTransports.end())
 	    {
-		localTransport = new SipTLSTransportGroup;
-		localTransport->name = group->name;
+		boost::shared_ptr<TLSTransportImplPriv> newTransport(new TLSTransportImplPriv());
+		localTransport = newTransport;
+		localTransport->mGroup = new SipTLSTransportGroup;
+		localTransport->mGroup->name = group->name;
 		mImplPriv->mConfiguredTLSTransports.insert(make_pair(group->name, localTransport));
 	    }
 	    else
 	    {
 		localTransport = (*localTransportGroup).second;
-		performSerialCheck(group->configurationItems, localTransport->configurationItems);
+		performSerialCheck(group->configurationItems, localTransport->mGroup->configurationItems);
 	    }
-	    
+
 	    class tlsTransportItemsVisitor : public SipConfigurationItemVisitor
 	    {
 	    public:
+		tlsTransportItemsVisitor(boost::shared_ptr<TLSTransportImplPriv> localTransport) : mLocalTransport(localTransport) { };
+
+		void visitSipHostItem(const ::AsteriskSCF::SIP::V1::SipHostItemPtr& hostItem)
+		{
+		    mLocalTransport->mAddress = hostItem->host;
+		    mLocalTransport->mPort = hostItem->port;
+		};
 	    private:
+		boost::shared_ptr<TLSTransportImplPriv> mLocalTransport;
 	    };
-	    
-	    SipConfigurationItemVisitorPtr tlsTransportVisitor = new tlsTransportItemsVisitor();
-	    
+
+	    std::string oldAddress = localTransport->mAddress;
+	    int oldPort = localTransport->mPort;
+
+	    SipConfigurationItemVisitorPtr tlsTransportVisitor = new tlsTransportItemsVisitor(localTransport);
+
 	    for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
 		 item != group->configurationItems.end();
 		 ++item)
 	    {
-		localTransport->configurationItems.insert(make_pair((*item).first, (*item).second));
+		localTransport->mGroup->configurationItems.insert(make_pair((*item).first, (*item).second));
 		(*item).second->visit(tlsTransportVisitor);
 	    }
+
+	    // 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
+		}
+
+		std::cout << "Address: " << localTransport->mAddress << std::endl;
+		localTransport->mTransportFactory = mImplPriv->mPJSipManager->createTLSTransport(localTransport->mAddress, localTransport->mPort, &localTransport->mTLSSettings);
+	    }
 	};
 
         void visitSipEndpointGroup(const ::AsteriskSCF::SIP::V1::SipEndpointGroupPtr& group)
@@ -904,7 +974,7 @@ void ConfigurationServiceImpl::removeConfigurationItems(const AsteriskSCF::Syste
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTLSTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
+	    std::map<std::string, boost::shared_ptr<TLSTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTLSTransports.end())
 	    {
@@ -917,7 +987,7 @@ void ConfigurationServiceImpl::removeConfigurationItems(const AsteriskSCF::Syste
 	    private:
 	    } tlsTransportVisitor;
 	    
-	    removeItems(&tlsTransportVisitor, group->configurationItems, (*localTransport).second->configurationItems);
+	    removeItems(&tlsTransportVisitor, group->configurationItems, (*localTransport).second->mGroup->configurationItems);
 	};
 
         void visitSipEndpointGroup(const ::AsteriskSCF::SIP::V1::SipEndpointGroupPtr& group)
@@ -1007,7 +1077,7 @@ void ConfigurationServiceImpl::removeConfigurationGroups(const AsteriskSCF::Syst
 	
 	void visitSipTLSTransportGroup(const ::AsteriskSCF::SIP::V1::SipTLSTransportGroupPtr& group)
 	{
-	    std::map<std::string, SipTLSTransportGroupPtr>::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
+	    std::map<std::string, boost::shared_ptr<TLSTransportImplPriv> >::iterator localTransport = mImplPriv->mConfiguredTLSTransports.find(group->name);
 	    
 	    if (localTransport == mImplPriv->mConfiguredTLSTransports.end())
 	    {

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list