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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Nov 16 13:14:01 CST 2011


branch "auth-corrections" has been updated
       via  6e2f71bbd46c8475a112b35dd37ba2527bfc7907 (commit)
       via  582cd705da6d1c6837a797701844e4c55853f388 (commit)
      from  67af305c398f1ad12b626b5f2da01aa336b4e451 (commit)

Summary of changes:
 src/AuthManager.h                  |    2 +
 src/PJSipManager.cpp               |   16 ++----
 src/PJSipManager.h                 |   16 ++++---
 src/PJSipModule.h                  |    2 +-
 src/SipClientRegistration.cpp      |   92 +++---------------------------------
 src/SipClientRegistration.h        |   48 +------------------
 src/SipEndpoint.cpp                |   13 ++++--
 src/SipEndpoint.h                  |    4 +-
 src/SipEndpointFactory.cpp         |   19 +++++++-
 src/SipEndpointFactory.h           |   11 ++--
 src/SipSession.cpp                 |    1 +
 src/SipStateReplicatorListener.cpp |    1 +
 12 files changed, 63 insertions(+), 162 deletions(-)


- Log -----------------------------------------------------------------
commit 6e2f71bbd46c8475a112b35dd37ba2527bfc7907
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Nov 16 12:41:48 2011 -0600

    Get rid of the SipRegistrationClientManager class. It has no use.

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index b041000..58b6523 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -62,7 +62,6 @@ void PJSipManager::addAuthHook(const AuthHookPrx &hook, int priority, const Requ
     {
         mLoggingModule->addAuthHook(hook, priority, types);
     }
-    mClientRegistrationManager->addAuthHook(hook);
 }
 
 void PJSipManager::removeAuthHook(const AuthHookPrx &hook)
@@ -75,7 +74,6 @@ void PJSipManager::removeAuthHook(const AuthHookPrx &hook)
     {
         mLoggingModule->removeAuthHook(hook);
     }
-    mClientRegistrationManager->removeAuthHook(hook);
 }
 
 void PJSipManager::clearAuthHooks()
@@ -88,7 +86,6 @@ void PJSipManager::clearAuthHooks()
     {
         mLoggingModule->clearAuthHooks();
     }
-    mClientRegistrationManager->clearAuthHooks();
 }
 
 static void *monitorThread(void *endpt)
@@ -264,18 +261,12 @@ pj_pool_t* PJSipManager::getMemoryPool()
     return mMemoryPool;
 }
 
-SipRegistrationClientManagerPtr PJSipManager::getClientRegistrationManager() const
-{
-    return mClientRegistrationManager;
-}
-
 PJSipManager::PJSipManager() :
     mEndpoint(0),
     mSessionModule(0),
     mLoggingModule(0),
     mPjThread(0),
-    mMemoryPool(0),
-    mClientRegistrationManager(new SipRegistrationClientManager)
+    mMemoryPool(0)
 {
     memset(&mCachingPool, 0, sizeof(mCachingPool));
 
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 5dd019d..c2c797d 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -137,8 +137,6 @@ public:
 
     void handleEvents();
 
-    SipRegistrationClientManagerPtr getClientRegistrationManager() const;
-
 private:
     pjsip_endpoint *mEndpoint;
     PJSipSessionModulePtr mSessionModule;
@@ -152,8 +150,6 @@ private:
     SipModuleMap mModules;
     std::map<std::string, TransportPtr> mTransports;
 
-    SipRegistrationClientManagerPtr mClientRegistrationManager;
-
     PJSipManager();
 };
 
diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 6ab868f..c792230 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -126,37 +126,6 @@ private:
 
 using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
 
-SipRegistrationClientManager::SipRegistrationClientManager()
-{
-}
-
-void SipRegistrationClientManager::addAuthHook(const AuthHookPrx& hook)
-{
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    if (std::find(mAuthHooks.begin(), mAuthHooks.end(), hook) == mAuthHooks.end())
-    {
-        mAuthHooks.push_back(hook);
-    }
-}
-
-void SipRegistrationClientManager::removeAuthHook(const AuthHookPrx& hook)
-{
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    mAuthHooks.erase(std::remove(mAuthHooks.begin(), mAuthHooks.end(), hook), mAuthHooks.end());
-}
-
-void SipRegistrationClientManager::clearAuthHooks()
-{
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    mAuthHooks.clear();
-}
-
-AuthHookSeq SipRegistrationClientManager::getAuthHooks()
-{
-    boost::shared_lock<boost::shared_mutex> lock(mLock);
-    return mAuthHooks;
-}
-
 SipRegistrationClient::SipRegistrationClient(
         const SipClientRegistrationItemPtr& confItem,
         pjsip_endpoint* pjEndpoint,
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index 8cc4132..edcd9e8 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -30,50 +30,6 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-/**
- * A centralized class.
- *
- * Outside entities will populate this with information
- * central to all client registrations.
- *
- * The client registrations themselves will then use
- * accessors in order to get the necessary information.
- */
-class SipRegistrationClientManager : public IceUtil::Shared
-{
-public:
-    SipRegistrationClientManager();
-
-    /**
-     * Get a list of registered authentication hooks
-     */
-    AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookSeq getAuthHooks();
-
-    /**
-     * Add an authentication hook
-     */
-    void addAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx& hook);
-
-    /**
-     * Remove an authentication hook
-     */
-    void removeAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx& hook);
-
-    /**
-     * Remove all authentication hooks
-     */
-    void clearAuthHooks();
-    
-private:
-    /**
-     * The registered auth hooks
-     */
-    AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookSeq mAuthHooks;
-    boost::shared_mutex mLock;
-};
-
-typedef IceUtil::Handle<SipRegistrationClientManager> SipRegistrationClientManagerPtr;
-
 class RescheduleRegister;
 class ClientRegistrationReplicaListener;
 

commit 582cd705da6d1c6837a797701844e4c55853f388
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Nov 16 12:29:00 2011 -0600

    Use the auth manager in the client registration code to get rid of duplicate code.

diff --git a/src/AuthManager.h b/src/AuthManager.h
index ade0127..37d4341 100644
--- a/src/AuthManager.h
+++ b/src/AuthManager.h
@@ -199,5 +199,7 @@ private:
     boost::shared_ptr<AuthManagerPriv> mImpl;
 };
 
+typedef boost::shared_ptr<AuthManager> AuthManagerPtr;
+
 }; //end namespace SipSessionManager
 }; //end namespace AsteriskSCF
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 6beef79..b041000 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -21,12 +21,15 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/thread/locks.hpp>
+#include <boost/lexical_cast.hpp>
 #include <vector>
 
 #include "PJUtil.h"
 #include "STUNModule.h"
 #include "UDPTransport.h"
-#include <boost/lexical_cast.hpp>
+#include "PJSipSessionModule.h"
+#include "PJSipRegistrarModule.h"
+#include "PJSipLoggingModule.h"
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::System::Hook::V1;
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 91f7e74..5dd019d 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -30,11 +30,8 @@
 #include <AsteriskSCF/SIP/SIPExtensionPointIf.h>
 #include <AsteriskSCF/System/Hook/HookIf.h>
 
-#include "PJSipSessionModule.h"
-#include "PJSipLoggingModule.h"
 #include "Transports.h"
 #include "SipModule.h"
-#include "PJSipRegistrarModule.h"
 #include "SipReplicationContext.h"
 #include "SipClientRegistration.h"
 
@@ -47,6 +44,15 @@ namespace SipSessionManager
 class PJSipManager;
 typedef boost::shared_ptr<PJSipManager> PJSipManagerPtr;
 
+class PJSipSessionModule;
+typedef IceUtil::Handle<PJSipSessionModule> PJSipSessionModulePtr;
+
+class PJSipRegistrarModule;
+typedef IceUtil::Handle<PJSipRegistrarModule> PJSipRegistrarModulePtr;
+
+class PJSipLoggingModule;
+typedef IceUtil::Handle<PJSipLoggingModule> PJSipLoggingModulePtr;
+
 /*
  * This class is responsible for providing access to the pjsip_endpoint for the Asterisk SCF SIP component.
  *
diff --git a/src/PJSipModule.h b/src/PJSipModule.h
index be85772..e2e13cc 100644
--- a/src/PJSipModule.h
+++ b/src/PJSipModule.h
@@ -56,7 +56,7 @@ protected:
     PJSipModule() { }
     virtual ~PJSipModule() { }
     pjsip_module mModule;
-    boost::shared_ptr<AuthManager> mAuthManager;
+    AuthManagerPtr mAuthManager;
 private:
     const std::string mName;
 };
diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 9aee763..6ab868f 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -161,7 +161,7 @@ SipRegistrationClient::SipRegistrationClient(
         const SipClientRegistrationItemPtr& confItem,
         pjsip_endpoint* pjEndpoint,
         const SipEndpointPtr& sipEndpoint,
-        const SipRegistrationClientManagerPtr& manager,
+        const AuthManagerPtr& manager,
         const SipReplicationContextPtr& replicationContext,
         const Ice::ObjectAdapterPtr& backplaneAdapter,
         const ReplicaPrx& replica)
@@ -337,67 +337,20 @@ void SipRegistrationClient::handleRegisterResponse(pjsip_regc_cbparam *param)
     }
 }
 
-Ice::StringSeq SipRegistrationClient::getRealms(pjsip_rx_data *rdata)
-{
-    Ice::StringSeq realms;
-
-    pjsip_proxy_authenticate_hdr *authHeader = (pjsip_proxy_authenticate_hdr*) &rdata->msg_info.msg->hdr;
-
-    while ((authHeader = (pjsip_proxy_authenticate_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_WWW_AUTHENTICATE, authHeader->next)))
-    {
-        std::string realm(pj_strbuf(&authHeader->challenge.digest.realm), pj_strlen(&authHeader->challenge.digest.realm));
-        lg(Debug) << "Found the realm " << realm;
-        realms.push_back(realm);
-    }
-
-    authHeader = (pjsip_proxy_authenticate_hdr*) &rdata->msg_info.msg->hdr;
-
-    while ((authHeader = (pjsip_proxy_authenticate_hdr*) pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_PROXY_AUTHENTICATE, authHeader->next)))
-    {
-        std::string realm(pj_strbuf(&authHeader->challenge.digest.realm), pj_strlen(&authHeader->challenge.digest.realm));
-        realms.push_back(realm);
-    }
-
-    return realms;
-}
-
 //XXX This function seems like it may fit better into AuthManager
 //or some more central place since it could be useful for authentication
 //responses for any type of request. This is mostly not REGISTER-specific, in
 //other words.
 void SipRegistrationClient::authenticate(pjsip_rx_data *rdata)
 {
-    AuthHookSeq hooks = mManager->getAuthHooks();
-    for (AuthHookSeq::iterator iter = hooks.begin();
-            iter != hooks.end(); ++iter)
+    std::vector<pjsip_cred_info> creds;
+    mManager->getAuthCredentials(rdata, creds, mEndpointName);
+    if (!creds.empty())
     {
-        ClientAuthSeq auths;
-        Ice::StringSeq realms = getRealms(rdata);
-
-        HookResult result = (*iter)->respondToChallenge(mEndpointName, realms, auths);
-        if (result.status == Succeeded)
-        {
-            std::vector<pjsip_cred_info> creds;
-            //Cool. So now we need to update the auth info on mReg
-            for (ClientAuthSeq::iterator authIter = auths.begin();
-                    authIter != auths.end(); ++authIter)
-            {
-                pjsip_cred_info info;
-                pj_cstr(&info.realm, authIter->realm.c_str());
-                pj_cstr(&info.scheme, "digest");
-                pj_cstr(&info.username, authIter->username.c_str());
-                pj_cstr(&info.data, authIter->password.c_str());
-                info.data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
-                creds.push_back(info);
-            }
-            if (creds.size() != 0)
-            {
-                pjsip_regc_set_credentials(mReg, boost::numeric_cast<int>(creds.size()), &creds.front());
-                sendRegister();
-            }
-            return;
-        }
+        pjsip_regc_set_credentials(mReg, boost::numeric_cast<int>(creds.size()), &creds.front());
+        sendRegister();
     }
+    return;
 }
 
 }
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index 035d95c..8cc4132 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -110,7 +110,7 @@ public:
             const AsteriskSCF::Configuration::SipSessionManager::V1::SipClientRegistrationItemPtr& confItem,
             pjsip_endpoint* pjEndpoint,
             const SipEndpointPtr& sipEndpoint,
-            const SipRegistrationClientManagerPtr& manager,
+            const AuthManagerPtr& manager,
             const SipReplicationContextPtr& replicationContext,
             const Ice::ObjectAdapterPtr& backplaneAdapter,
             const AsteriskSCF::System::Component::V1::ReplicaPrx& replica);
@@ -214,7 +214,7 @@ private:
     /**
      * The central point from which to get information such as authentication hooks.
      */
-    SipRegistrationClientManagerPtr mManager;
+    AuthManagerPtr mManager;
 
     /**
      * The PJSIP client registration structure.
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 7e5a4ca..b2e8185 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -199,7 +199,8 @@ public:
             const PJSipManagerPtr& manager,
             const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
             const SipReplicationContextPtr& replicationContext,
-            const ReplicaPrx& replica) :
+            const ReplicaPrx& replica,
+            const AuthManagerPtr& authManager) :
         mName(name),
         mAdapter(adapter),
         mBackplaneAdapter(backplaneAdapter),
@@ -208,6 +209,7 @@ public:
         mServiceLocator(serviceLocator),
         mReplicationContext(replicationContext),
         mReplica(replica),
+        mAuthManager(authManager),
         mDefaultListeners(new AsteriskSCF::Collections::ProxySet<SessionListenerPrx>(adapter, lg, "Default Session Listeners")),
         mDefaultSessionCookies(new AsteriskSCF::Collections::HandleSet<AsteriskSCF::SessionCommunications::V1::SessionCookiePtr>(lg, "Default Cookies"))
     {
@@ -230,6 +232,7 @@ public:
     Ice::ObjectAdapterPtr mAdapter;
 
     Ice::ObjectAdapterPtr mBackplaneAdapter;
+
     /**
      * The endpoint factory that created us.
      */
@@ -263,6 +266,7 @@ public:
     AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx mServiceLocator;
     SipReplicationContextPtr mReplicationContext;
     ReplicaPrx mReplica;
+    AuthManagerPtr mAuthManager;
     AsteriskSCF::Collections::ProxySet<SessionListenerPrx>::SetPtr mDefaultListeners;
 
     std::map<std::string, SipRegistrationClientPtr> mClientRegistrations;
@@ -276,8 +280,9 @@ SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter,
     const PJSipManagerPtr& manager, 
     const ServiceLocatorPrx& serviceLocator,
     const SipReplicationContextPtr& replicationContext,
-    const ReplicaPrx& replica)
-    : mImplPriv(new SipEndpointImplPriv(adapter, backplaneAdapter, factory, name, manager, serviceLocator, replicationContext, replica))
+    const ReplicaPrx& replica,
+    const AuthManagerPtr& authManager)
+    : mImplPriv(new SipEndpointImplPriv(adapter, backplaneAdapter, factory, name, manager, serviceLocator, replicationContext, replica, authManager))
 {
     lg(Debug) << "Constructing SIP endpoint " << name;
 
@@ -408,7 +413,7 @@ void SipEndpoint::updateClientRegistrations(SipClientRegistrationItemSeq& items)
                         *item,
                         mImplPriv->mManager->getEndpoint(),
                         this,
-                        mImplPriv->mManager->getClientRegistrationManager(),
+                        mImplPriv->mAuthManager,
                         mImplPriv->mReplicationContext,
                         mImplPriv->mBackplaneAdapter,
                         mImplPriv->mReplica);
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index f758392..0514c1e 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -38,6 +38,7 @@
 
 #include "SipSession.h"
 #include "SipReplicationContext.h"
+#include "AuthManager.h"
 
 namespace AsteriskSCF
 {
@@ -287,7 +288,8 @@ public:
             const PJSipManagerPtr& manager,
             const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
             const SipReplicationContextPtr& replicationContext,
-            const AsteriskSCF::System::Component::V1::ReplicaPrx& replica);
+            const AsteriskSCF::System::Component::V1::ReplicaPrx& replica,
+            const AuthManagerPtr& authManager);
 
     bool operator==(const std::string &name) const;
 
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index dfa4d74..a36626a 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -31,6 +31,22 @@ namespace AsteriskSCF
 {
 namespace SipSessionManager
 {
+
+SipEndpointFactory::SipEndpointFactory(
+        const Ice::ObjectAdapterPtr& adapter,
+        const Ice::ObjectAdapterPtr& backplaneAdapter,
+        const PJSipManagerPtr& manager,
+        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+        const SipReplicationContextPtr& replicationContext) :
+    mAdapter(adapter),
+    mBackplaneAdapter(backplaneAdapter),
+    mManager(manager),
+    mServiceLocator(serviceLocator),
+    mReplicationContext(replicationContext),
+    mAuthManager(new AuthManager(mManager->getEndpoint(), AsteriskSCF::System::Logging::getLoggerFactory().getLogger("AsteriskSCF.SipSessionGateway")))
+{
+}
+
 SipEndpointPtr SipEndpointFactory::createEndpoint(std::string endpointName)
 {
     SipEndpointPtr endpoint = new SipEndpoint(
@@ -41,7 +57,8 @@ SipEndpointPtr SipEndpointFactory::createEndpoint(std::string endpointName)
             mManager,
             mServiceLocator,
             mReplicationContext,
-            mReplica);
+            mReplica,
+            mAuthManager);
     mEndpoints.push_back(endpoint);
     return endpoint;
 }
diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index 7d792b5..e8102a9 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -23,7 +23,9 @@
 #include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
 #include <AsteriskSCF/SessionCommunications/SessionCommunicationsExtensionPointsIf.h>
 #include <AsteriskSCF/SIP/SIPRegistrarIf.h>
+#include <AsteriskSCF/logger.h>
 #include "SipReplicationContext.h"
+#include "PJSipManager.h"
 
 namespace AsteriskSCF
 {
@@ -43,12 +45,7 @@ public:
             const Ice::ObjectAdapterPtr& backplaneAdapter,
             const PJSipManagerPtr& manager,
             const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-            const SipReplicationContextPtr& replicationContext) :
-        mAdapter(adapter),
-        mBackplaneAdapter(backplaneAdapter),
-        mManager(manager),
-        mServiceLocator(serviceLocator),
-        mReplicationContext(replicationContext) { }
+            const SipReplicationContextPtr& replicationContext);
 
     SipEndpointPtr createEndpoint(std::string);
 
@@ -89,6 +86,8 @@ private:
     SipReplicationContextPtr mReplicationContext;
 
     AsteriskSCF::System::Component::V1::ReplicaPrx mReplica;
+
+    AuthManagerPtr mAuthManager;
 };
 
 }; // end SipSessionManager
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 3182731..21bf0fb 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -46,6 +46,7 @@
 #include <AsteriskSCF/SessionCookies/SipSessionManager/SipSessionCookiesIf.h>
 #include <AsteriskSCF/Collections/HandleSet.h>
 #include "NATOptions.h"
+#include "PJSipSessionModule.h"
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::System::NAT::V1;
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 689785a..7f5e01b 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -21,6 +21,7 @@
 #include "SipSession.h"
 #include "PJSipManager.h"
 #include "SipTransfer.h"
+#include "PJSipRegistrarModule.h"
 #include <pjlib.h>
 
 #include <IceUtil/UUID.h>

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list