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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Dec 2 16:07:44 CST 2011


branch "party-id" has been updated
       via  4a1aef04a21ab0c33493b745b2123bcea00ff073 (commit)
       via  fa4ad6ffcb5786b086e07b5d81845be5bb2e91bd (commit)
       via  e9bef7f80aa63e9b09c9c63c481cbd7f7d69d271 (commit)
       via  8ec91edd2b48b4359a86eb83922c877394006dcc (commit)
       via  3cd729fbb9dc4d0a75185a443f9f433552ddf47d (commit)
       via  a0abb129f930f8dfe4e3c625323dcd08a34923f5 (commit)
       via  e8f492df476df52ba8c37ad0be6647646c4f41b9 (commit)
       via  6b8709327b6e2ba09b41863fa5e4de8b84666384 (commit)
       via  6e2f71bbd46c8475a112b35dd37ba2527bfc7907 (commit)
       via  582cd705da6d1c6837a797701844e4c55853f388 (commit)
       via  67af305c398f1ad12b626b5f2da01aa336b4e451 (commit)
       via  01875837a0d54f89089c83311c14c1f0b90f7b14 (commit)
       via  1a9c552d54bbabefed475aa78937ccacc812ef1d (commit)
       via  3c06c6776daf1595e29e7591a412cfd38c82febd (commit)
       via  83551dc94f1d5a0a8967290c60c65e72b99d101f (commit)
       via  585a2423a3a9ec40221c0310986e8d0064b28bbe (commit)
       via  96ecfc96638614b5bbe85a9094bc16c0a1cfdf96 (commit)
       via  ff24318d201429b0f2dc4226dee7424baf5e0bce (commit)
      from  ddf99b1e738d692d8b82b77006e5890180fc4d09 (commit)

Summary of changes:
 src/AuthManager.cpp                      |  215 +++++++++++++++++++++-------
 src/AuthManager.h                        |   86 +++++++-----
 src/Component.cpp                        |   14 +-
 src/PJSipLoggingModule.cpp               |   16 +-
 src/PJSipManager.cpp                     |   20 +--
 src/PJSipManager.h                       |   16 ++-
 src/PJSipModule.h                        |    2 +-
 src/PJSipRegistrarModule.cpp             |   42 +++++-
 src/PJSipRegistrarModule.h               |    9 ++
 src/PJSipRegistrarModuleConstruction.cpp |    6 +
 src/PJSipSessionModule.cpp               |  227 ++++++++++++++++++------------
 src/PJSipSessionModule.h                 |    4 +-
 src/SipClientRegistration.cpp            |   92 +-----------
 src/SipClientRegistration.h              |   48 +------
 src/SipEndpoint.cpp                      |   25 ++--
 src/SipEndpoint.h                        |    4 +-
 src/SipEndpointFactory.cpp               |   19 +++-
 src/SipEndpointFactory.h                 |   10 +-
 src/SipSession.cpp                       |  191 +++++++++++++++-----------
 src/SipSession.h                         |   14 ++
 src/SipStateReplicatorListener.cpp       |    1 +
 src/SipTransfer.cpp                      |    2 +-
 22 files changed, 616 insertions(+), 447 deletions(-)


- Log -----------------------------------------------------------------
commit 4a1aef04a21ab0c33493b745b2123bcea00ff073
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Dec 2 15:57:43 2011 -0600

    Adjust so that getInfo() gets identity information.
    
    This meant that things bled out a bit, but it'll be all right.

diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 0763f35..2bb6eda 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -137,59 +137,6 @@ public:
 
     }
 
-    AsteriskSCF::SessionCommunications::V1::SessionInfoPtr getInfo()
-    {
-        AsteriskSCF::SessionCommunications::V1::SessionInfoPtr sessioninfo =
-            new AsteriskSCF::SessionCommunications::V1::SessionInfo();
-        
-        /* TODO: Utilize locking so this becomes safe
-           if (!mImplPriv->mInviteSession || mImplPriv->mInviteSession->state == PJSIP_INV_STATE_NULL)
-           {
-           sessioninfo->currentState = "ready";
-           }
-           else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CALLING)
-           {
-           sessioninfo->currentState = "outbound";
-           }
-           else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_INCOMING)
-           {
-           sessioninfo->currentState = "inbound";
-           }
-           else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_EARLY)
-           {
-           sessioninfo->currentState = "early";
-           }
-           else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CONNECTING)
-           {
-           sessioninfo->currentState = "connecting";
-           }
-           else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CONFIRMED)
-           {
-           sessioninfo->currentState = "connected";
-           }
-           else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_DISCONNECTED)
-           {
-           sessioninfo->currentState = "disconnected";
-           }
-        */
-        return sessioninfo;
-    }
-
-    void addListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener)
-    {
-        mListeners.push_back(listener);
-        if (mInviteSession)
-        {
-            PJSipSessionModInfo *session_mod_info =
-                static_cast<PJSipSessionModInfo*>(
-                    mInviteSession->mod_data[mManager->getSessionModule()->getModule().id]);
-            if (session_mod_info)
-            {
-                session_mod_info->updateSessionState(mInviteSession);
-            }
-            mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
-        }
-    }
 
     void removeListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener)
     {
@@ -1454,22 +1401,20 @@ public:
     AddListenerOperation(
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_addListenerPtr& cb,
             const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
-            const boost::shared_ptr<SipSessionPriv>& sessionPriv)
-        : mCb(cb), mListener(listener), mImplPriv(sessionPriv) { }
+            const SipSessionPtr& session)
+        : mCb(cb), mListener(listener), mSession(session) { }
 
     SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
     {
         lg(Debug) << "Executing addListener operation";
-        mImplPriv->addListener(mListener);
-        AsteriskSCF::SessionCommunications::V1::SessionInfoPtr sessionInfo =
-            mImplPriv->getInfo();
-        mCb->ice_response(sessionInfo);
+        mSession->addListener(mListener);
+        mCb->ice_response(mSession->getInfo());
         return Complete;
     }
 private:
     AsteriskSCF::SessionCommunications::V1::AMD_Session_addListenerPtr mCb;
     AsteriskSCF::SessionCommunications::V1::SessionListenerPrx mListener;
-    boost::shared_ptr<SipSessionPriv> mImplPriv;
+    SipSessionPtr mSession;
 };
 
 void SipSession::addListener_async(
@@ -1478,7 +1423,23 @@ void SipSession::addListener_async(
         const Ice::Current&)
 {
     lg(Debug) << "Queueing addListener operation";
-    enqueueSessionWork(new AddListenerOperation(cb, listener, mImplPriv));
+    enqueueSessionWork(new AddListenerOperation(cb, listener, this));
+}
+
+void SipSession::addListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener)
+{
+    mImplPriv->mListeners.push_back(listener);
+    if (mImplPriv->mInviteSession)
+    {
+        PJSipSessionModInfo *session_mod_info =
+            static_cast<PJSipSessionModInfo*>(
+                mImplPriv->mInviteSession->mod_data[mImplPriv->mManager->getSessionModule()->getModule().id]);
+        if (session_mod_info)
+        {
+            session_mod_info->updateSessionState(mImplPriv->mInviteSession);
+        }
+        mImplPriv->mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
+    }
 }
 
 class IndicateOperation : public SuspendableWork
@@ -1661,22 +1622,19 @@ class GetInfoOperation : public SuspendableWork
 public:
     GetInfoOperation(
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_getInfoPtr& cb,
-            const boost::shared_ptr<SipSessionPriv>& sessionPriv)
-        : mCb(cb), mImplPriv(sessionPriv) { }
+            const SipSessionPtr& session)
+        : mCb(cb), mSession(session) { }
 
     SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
     {
         lg(Debug) << "Executing a GetInfo operation";
-        AsteriskSCF::SessionCommunications::V1::SessionInfoPtr sessionInfo =
-            mImplPriv->getInfo();
-
-        mCb->ice_response(sessionInfo);
+        mCb->ice_response(mSession->getInfo());
         return Complete;
     }
 
 private:
     AsteriskSCF::SessionCommunications::V1::AMD_Session_getInfoPtr mCb;
-    boost::shared_ptr<SipSessionPriv> mImplPriv;
+    SipSessionPtr mSession;
 };
 
 /**
@@ -1687,7 +1645,50 @@ void SipSession::getInfo_async(
         const Ice::Current&)
 {
     lg(Debug) << "queuing a getInfo operation";
-    enqueueSessionWork(new GetInfoOperation(cb, mImplPriv));
+    enqueueSessionWork(new GetInfoOperation(cb, this));
+}
+
+AsteriskSCF::SessionCommunications::V1::SessionInfoPtr SipSession::getInfo()
+{
+    AsteriskSCF::SessionCommunications::V1::SessionInfoPtr sessioninfo =
+        new AsteriskSCF::SessionCommunications::V1::SessionInfo();
+    
+    /*
+       if (!mImplPriv->mInviteSession || mImplPriv->mInviteSession->state == PJSIP_INV_STATE_NULL)
+       {
+       sessioninfo->currentState = "ready";
+       }
+       else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CALLING)
+       {
+       sessioninfo->currentState = "outbound";
+       }
+       else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_INCOMING)
+       {
+       sessioninfo->currentState = "inbound";
+       }
+       else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_EARLY)
+       {
+       sessioninfo->currentState = "early";
+       }
+       else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CONNECTING)
+       {
+       sessioninfo->currentState = "connecting";
+       }
+       else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CONFIRMED)
+       {
+       sessioninfo->currentState = "connected";
+       }
+       else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_DISCONNECTED)
+       {
+       sessioninfo->currentState = "disconnected";
+       }
+    */
+
+    sessioninfo->connectedLine = getConnectedLine();
+    sessioninfo->sessionOwner = getSessionOwnerId();
+    sessioninfo->callerID = getCaller();
+
+    return sessioninfo;
 }
 
 class GetMediaSessionOperation : public SuspendableWork
@@ -1897,25 +1898,23 @@ public:
     SetBridgeOperation(
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_setBridgePtr& cb,
             const SipSessionPtr& session,
-            const boost::shared_ptr<SipSessionPriv>& sessionPriv,
             const AsteriskSCF::SessionCommunications::V1::BridgePrx& bridge,
             const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener,
             const Ice::Current& current)
-        : mCb(cb), mSession(session), mImplPriv(sessionPriv), mBridge(bridge), mListener(listener), mCurrent(current) { }
+        : mCb(cb), mSession(session), mBridge(bridge), mListener(listener), mCurrent(current) { }
     
     SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
     {
         lg(Debug) << "Executing a SetBridge operation";
         mSession->setBridge(mBridge);
-        mImplPriv->addListener(mListener);
-        mCb->ice_response(mImplPriv->getInfo());
+        mSession->addListener(mListener);
+        mCb->ice_response(mSession->getInfo());
         return Complete;
     }
 
 private:
     AsteriskSCF::SessionCommunications::V1::AMD_Session_setBridgePtr mCb;
     SipSessionPtr mSession;
-    boost::shared_ptr<SipSessionPriv> mImplPriv;
     AsteriskSCF::SessionCommunications::V1::BridgePrx mBridge;
     AsteriskSCF::SessionCommunications::V1::SessionListenerPrx mListener;
     Ice::Current mCurrent;
@@ -1931,7 +1930,7 @@ void SipSession::setBridge_async(
     const Ice::Current& current)
 {
     lg(Debug) << "queuing a setBridge operation";
-    enqueueSessionWork(new SetBridgeOperation(cb, this, mImplPriv, bridge, listener, current));
+    enqueueSessionWork(new SetBridgeOperation(cb, this, bridge, listener, current));
 }
 
 /**
@@ -2397,6 +2396,43 @@ ConnectedLinePtr SipSession::getConnectedLine()
     return id;
 }
 
+/**
+ * Gets the SessionOwnerId party identification record for this Session.
+ * This is an internal method, intended to be called from within a queued operation.
+ */
+SessionOwnerIdPtr SipSession::getSessionOwnerId()
+{
+    SessionOwnerIdPtr id = 0;
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+    cookies.push_back(new SessionOwnerId());
+    AsteriskSCF::SessionCommunications::V1::SessionCookies results = getCookies(cookies);
+
+    if (!results.empty())
+    {
+        id = SessionOwnerIdPtr::dynamicCast(results.front());
+    }
+
+    return id;
+}
+
+/**
+ * Gets the Caller party identification record for this Session.
+ * This is an internal method, intended to be called from within a queued operation.
+ */
+CallerPtr SipSession::getCaller()
+{
+    CallerPtr id = 0;
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+    cookies.push_back(new Caller());
+    AsteriskSCF::SessionCommunications::V1::SessionCookies results = getCookies(cookies);
+
+    if (!results.empty())
+    {
+        id = CallerPtr::dynamicCast(results.front());
+    }
+
+    return id;
+}
 /** 
  * Gets the ConnectedLine party identification record for this Session.
  */
diff --git a/src/SipSession.h b/src/SipSession.h
index 9dfe0a3..31073d6 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -162,6 +162,8 @@ public:
             const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&,
             const Ice::Current&);
 
+    void addListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener);
+
     void indicate_async(
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_indicatePtr& cb,
             const AsteriskSCF::SessionCommunications::V1::IndicationPtr&, const Ice::Current&);
@@ -174,6 +176,8 @@ public:
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_getInfoPtr& cb,
             const Ice::Current&);
 
+    AsteriskSCF::SessionCommunications::V1::SessionInfoPtr getInfo();
+
     void getMediaSession_async(
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_getMediaSessionPtr& cb,
             const Ice::Current&);
@@ -234,6 +238,16 @@ public:
      * This is an internal method and should only be called from queued operations
      */
     AsteriskSCF::SessionCommunications::PartyIdentification::V1::ConnectedLinePtr getConnectedLine();
+    /**
+     * Gets the SessionOwnerId for the session.
+     * This is an internal method and should only be called from queued operations
+     */
+    AsteriskSCF::SessionCommunications::PartyIdentification::V1::SessionOwnerIdPtr getSessionOwnerId();
+    /**
+     * Gets the Caller for the session.
+     * This is an internal method and should only be called from queued operations
+     */
+    AsteriskSCF::SessionCommunications::PartyIdentification::V1::CallerPtr getCaller();
 
     void getStreams_async(
         const AsteriskSCF::SessionCommunications::V1::AMD_Session_getStreamsPtr&,
diff --git a/src/SipTransfer.cpp b/src/SipTransfer.cpp
index ee2bcaf..bb35b4b 100644
--- a/src/SipTransfer.cpp
+++ b/src/SipTransfer.cpp
@@ -480,7 +480,7 @@ SuspendableWorkResult HandleReferOperation::initial(const SuspendableWorkListene
 
             lg(Debug) << "handleRefer() calling router connectBridgedSessions(). ";
 
-            mSessionRouter->begin_connectBridgedSessions(operationId, mSession->getSessionProxy(), other_session->getSessionProxy(), false, other_session->getConnectedLine(), d);
+            mSessionRouter->begin_connectBridgedSessions(operationId, mSession->getSessionProxy(), other_session->getSessionProxy(), false, d);
             pjsip_dlg_dec_lock(other_dlg);
             return Complete;
         }

commit fa4ad6ffcb5786b086e07b5d81845be5bb2e91bd
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Dec 1 13:18:22 2011 -0600

    Remove unnecessary debug lines from the code of codes.

diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index d3c04ba..0763f35 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -947,7 +947,6 @@ void SipSession::setSelfAsCaller()
 
 void SipSession::setSessionOwnerId(const SessionOwnerIdPtr& owner)
 {
-    lg(Debug) << "!!!!!! Setting owner id on session " << mImplPriv->mEndpoint->getName();
     mImplPriv->mSessionCookies[owner->ice_id()] = owner;
     mImplPriv->cookiesUpdated();
 }
@@ -2385,8 +2384,6 @@ void SipSession::getSessionOwnerId_async(const AMD_Session_getSessionOwnerIdPtr&
 ConnectedLinePtr SipSession::getConnectedLine()
 {
 
-    lg(Debug) << "!!!!!!! Getting ConnectedLine for session " << mImplPriv->mEndpoint->getName();
-
     ConnectedLinePtr id = 0;
     AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
     cookies.push_back(new ConnectedLine());
@@ -2394,7 +2391,6 @@ ConnectedLinePtr SipSession::getConnectedLine()
 
     if (!results.empty())
     {
-        lg(Debug) << "!!!!!!!!! Found ConnectedLine";
         id = ConnectedLinePtr::dynamicCast(results.front());
     }
 

commit e9bef7f80aa63e9b09c9c63c481cbd7f7d69d271
Merge: ddf99b1 8ec91ed
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Dec 1 10:57:48 2011 -0600

    Merge branch 'master' into party-id
    
    Conflicts:
    	src/PJSipSessionModule.cpp

diff --cc src/PJSipSessionModule.cpp
index 721f9ce,5d1d207..2150d50
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@@ -26,7 -26,7 +26,8 @@@
  
  #include <IceUtil/UUID.h>
  #include <boost/lexical_cast.hpp>
 +#include <boost/algorithm/string.hpp>
+ #include <boost/numeric/conversion/cast.hpp>
  
  #include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
  #include <AsteriskSCF/Core/Routing/RoutingIf.h>
@@@ -1507,9 -1171,39 +1484,39 @@@ void PJSipSessionModule::handleInviteRe
      //to add code to handle.
  
      lg(Debug) << "Queuing a HandleInviteResponseOperation";
 -    enqueueSessionWork(new HandleInviteResponseOperation(respCode, inv->state, session), inv);
 +    enqueueSessionWork(new HandleInviteResponseOperation(respCode, inv->state, session, connected), inv);
  }
  
+ //There are some rejection codes that we can actually do something with other than
+ //just kill the code.
+ void PJSipSessionModule::handleInviteRejection(pjsip_inv_session* inv,
+     pjsip_rx_data* rdata, pjsip_transaction* tsx)
+ {
+     int respCode = rdata->msg_info.msg->line.status.code;
+     PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
+     SipSessionPtr session = session_mod_info->getSessionPtr();
+ 
+     if (respCode == 401 || respCode == 407)
+     {
+         //Aw peas, they be wanting to authenticate, boooooooooiiiiiiiiiii
+         std::vector<pjsip_cred_info> creds;
+         mAuthManager->getAuthCredentials(rdata, creds, session->getEndpoint()->getName());
+         if (creds.size() != 0)
+         {
+             pjsip_inv_uac_restart(inv, PJ_FALSE);
+             pjsip_auth_clt_set_credentials(&inv->dlg->auth_sess,
+                     boost::numeric_cast<int>(creds.size()), &creds.front());
+             pjsip_tx_data *tdata;
+             pjsip_auth_clt_reinit_req(&inv->dlg->auth_sess,
+                     rdata, tsx->last_tx, &tdata);
+             //XXX The actual sending of the message should probably be done as
+             //a queued operation.
+             pjsip_inv_send_msg(inv, tdata);
+         }
+         return;
+     }
+ }
+ 
  class TransactionStateOperation : public SipQueueableOperation
  {
  public:
diff --cc src/PJSipSessionModule.h
index 3b9c3a0,59e840a..d761e1c
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@@ -144,74 -140,9 +144,76 @@@ public
  
  private:
      void handleNewInvite(pjsip_rx_data *rdata);
 +
 +    /**
 +     * Gets the value of the Privacy setting and returns true if
 +     * the value is set to "id"
 +     */
 +    bool getPrivacy(pjsip_rx_data *rdata);
 +    /**
 +     * Generic method to get Ids from a header name.
 +     * 
 +     * This can be used for any header type that does not
 +     * have specific parameters that need to be read.
 +     */
 +    void getIds(const char *headerName,
 +            pjsip_rx_data *rdata,
 +            bool privacySet,
 +            AsteriskSCF::SessionCommunications::PartyIdentification::V1::IdSeq& ids);
 +    /**
 +     * Get the IDs in Diversion headers.
 +     *
 +     * This will also parse the reason parameters from the headers.
 +     */
 +    void getRedirectionIds(pjsip_rx_data *rdata,
 +            bool privacySet,
 +            ReasonIdSeq& ids);
 +
 +    /**
 +     * Get the IDs from Remote-Party-ID headers.
 +     *
 +     * This will also parse the privacy and screen parameters.
 +     */
 +    void getRemotePartyIds(pjsip_rx_data *rdata,
 +            bool privacySet,
 +            AsteriskSCF::SessionCommunications::PartyIdentification::V1::IdSeq& ids);
 +
 +    /**
 +     * Generic method to get a specific parameter from a header
 +     */
 +    std::string getParam(const std::string& headerVal, const char *paramName);
 +
 +    /**
 +     * Translate a reason string into the appropriate slice enum value
 +     */
 +    AsteriskSCF::SessionCommunications::PartyIdentification::V1::Reason translateReason(const std::string& reason);
 +
 +    /**
 +     * Get caller ID
 +     *
 +     * This will first attempt to find P-Asserted-Identity headers. If none are present, it
 +     * will use the From header to find the caller ID.
 +     */
 +    AsteriskSCF::SessionCommunications::PartyIdentification::V1::CallerPtr getCallerID(pjsip_rx_data *rdata);
 +
 +    /**
 +     * Get the connected ID
 +     *
 +     * This will first attempt to find P-Asserted-Identity headers. If none are present, it
 +     * will search for Remote-Party-ID headers.
 +     */
 +    AsteriskSCF::SessionCommunications::PartyIdentification::V1::ConnectedLinePtr getConnectedID(pjsip_rx_data *rdata);
 +
 +    /**
 +     * Get Redirections
 +     *
 +     * This will attempt to find Diversion headers.
 +     */
 +    AsteriskSCF::SessionCommunications::PartyIdentification::V1::RedirectionsPtr getRedirections(pjsip_rx_data *rdata, pjsip_sip_uri *ruri);
 +
      void handleInviteResponse(pjsip_inv_session *inv, pjsip_rx_data *rdata, pjsip_dialog *dlg);
+     void handleInviteRejection(pjsip_inv_session *inv, pjsip_rx_data *rdata, pjsip_transaction *tsx);
+     void handleNonInviteAuthentication(pjsip_inv_session *inv, pjsip_rx_data *rdata, pjsip_dialog *dlg, pjsip_transaction *tsx);
      void handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdata);
      void handleInfo(pjsip_inv_session *inv, pjsip_rx_data *rdata);
      bool isDTMF(pjsip_rx_data *rdata);

commit 8ec91edd2b48b4359a86eb83922c877394006dcc
Merge: 3cd729f 585a242
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Dec 1 10:27:16 2011 -0600

    Merge branch 'master' of git.asterisk.org:asterisk-scf/release/sip


commit 3cd729fbb9dc4d0a75185a443f9f433552ddf47d
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Nov 30 13:38:16 2011 -0600

    Remove an unnecessary #include

diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index e8102a9..115fd8e 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -23,7 +23,6 @@
 #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"
 

commit a0abb129f930f8dfe4e3c625323dcd08a34923f5
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Nov 30 12:23:38 2011 -0600

    s/moduleHookVector/ModuleHookVector/

diff --git a/src/AuthManager.cpp b/src/AuthManager.cpp
index d5e75f9..277eac3 100644
--- a/src/AuthManager.cpp
+++ b/src/AuthManager.cpp
@@ -48,7 +48,7 @@ public:
 class ServerAuthInstancePriv
 {
 public:
-    ServerAuthInstancePriv(pjsip_rx_data *rdata, const moduleHookVector &moduleHooks,
+    ServerAuthInstancePriv(pjsip_rx_data *rdata, const ModuleHookVector &moduleHooks,
             RequestType type, pjsip_endpoint *endpoint, const Logger &logger)
         : mEndpoint(endpoint),
         mPool(pjsip_endpt_create_pool(mEndpoint, "auth%p", 500, 256)),
@@ -61,7 +61,7 @@ public:
             return;
         }
 
-        for (moduleHookVector::const_iterator iter = moduleHooks.begin(); iter != moduleHooks.end(); ++iter)
+        for (ModuleHookVector::const_iterator iter = moduleHooks.begin(); iter != moduleHooks.end(); ++iter)
         {
             RequestTypeSeq types = (*iter)->mTypes;
             AuthHookPrx hook = (*iter)->mHook;
@@ -134,7 +134,7 @@ public:
     std::string callId;
 };
 
-ServerAuthInstance::ServerAuthInstance(pjsip_rx_data *rdata, const moduleHookVector &hooks,
+ServerAuthInstance::ServerAuthInstance(pjsip_rx_data *rdata, const ModuleHookVector &hooks,
         RequestType type, pjsip_endpoint *endpoint, const Logger &logger)
         : mImpl(new ServerAuthInstancePriv(rdata, hooks, type, endpoint, logger)) { }
 
@@ -351,7 +351,7 @@ public:
 
     std::vector<ServerAuthInstancePtr> mServerAuthInstances;
     pjsip_endpoint *mEndpoint;
-    moduleHookVector mRegisteredHooks;
+    ModuleHookVector mRegisteredHooks;
     Logger mLogger;
     int mCounter;
     boost::mutex mHooksLock;
@@ -532,7 +532,7 @@ void AuthManager::addAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHo
 void AuthManager::removeAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook)
 {
     boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
-    for (moduleHookVector::iterator iter = mImpl->mRegisteredHooks.begin();
+    for (ModuleHookVector::iterator iter = mImpl->mRegisteredHooks.begin();
             iter != mImpl->mRegisteredHooks.end(); ++iter)
     {
         if ((*iter)->mHook == hook)
@@ -553,7 +553,7 @@ AuthHookSeq AuthManager::getHooks()
 {
     boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
     AuthHookSeq retSeq;
-    for (moduleHookVector::iterator iter = mImpl->mRegisteredHooks.begin();
+    for (ModuleHookVector::iterator iter = mImpl->mRegisteredHooks.begin();
             iter != mImpl->mRegisteredHooks.end(); ++ iter)
     {
         retSeq.push_back((*iter)->mHook);
diff --git a/src/AuthManager.h b/src/AuthManager.h
index d9bdb23..c5a0431 100644
--- a/src/AuthManager.h
+++ b/src/AuthManager.h
@@ -32,7 +32,7 @@ namespace SipSessionManager
 
 class AuthHookWrapper;
 
-typedef std::vector<boost::shared_ptr<AuthHookWrapper> > moduleHookVector;
+typedef std::vector<boost::shared_ptr<AuthHookWrapper> > ModuleHookVector;
 
 void sessionAuthTimeout(pj_timer_heap_t *timer_heap, pj_timer_entry *entry);
 
@@ -99,7 +99,7 @@ public:
 private:
 
     ServerAuthInstance(pjsip_rx_data *rdata,
-            const moduleHookVector &hooks,
+            const ModuleHookVector &hooks,
             AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type,
             pjsip_endpoint *endpoint,
             const AsteriskSCF::System::Logging::Logger &logger);

commit e8f492df476df52ba8c37ad0be6647646c4f41b9
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Nov 21 15:01:30 2011 -0600

    * Change some names to be more accurate
    * Remove some inaccurate comments
    * Add a checkAuth() method to AuthManager to decrease duplication
    * Add more conditions before calling handleNonInviteAuthentication()

diff --git a/src/AuthManager.cpp b/src/AuthManager.cpp
index 34346b1..d5e75f9 100644
--- a/src/AuthManager.cpp
+++ b/src/AuthManager.cpp
@@ -349,7 +349,7 @@ public:
         return realms;
     }
 
-    std::vector<boost::shared_ptr<ServerAuthInstance> > mServerAuthInstances;
+    std::vector<ServerAuthInstancePtr> mServerAuthInstances;
     pjsip_endpoint *mEndpoint;
     moduleHookVector mRegisteredHooks;
     Logger mLogger;
@@ -365,28 +365,77 @@ AuthManager::~AuthManager()
 {
 }
 
-boost::shared_ptr<ServerAuthInstance> AuthManager::createServerAuthInstance(pjsip_rx_data *rdata, RequestType type)
+ServerAuthInstancePtr AuthManager::createServerAuthInstance(pjsip_rx_data *rdata, RequestType type)
 {
-    boost::shared_ptr<ServerAuthInstance> instance;
+    ServerAuthInstancePtr instance;
     {
         boost::lock_guard<boost::mutex> hookLock(mImpl->mHooksLock);
-        instance.reset(new ServerAuthInstance(rdata, mImpl->mRegisteredHooks,
-                type, mImpl->mEndpoint, mImpl->mLogger));
+        instance = new ServerAuthInstance(rdata, mImpl->mRegisteredHooks,
+                type, mImpl->mEndpoint, mImpl->mLogger);
     }
     boost::lock_guard<boost::mutex> instancesLock(mImpl->mServerAuthInstancesLock);
     mImpl->mServerAuthInstances.push_back(instance);
     return instance;
 }
 
+ServerAuthInstancePtr AuthManager::checkAuth(pjsip_rx_data *rdata, RequestInfoPtr& info, RequestType type, DigestChallengeSeq& digests)
+{
+    //First, let's see if this message has some auth that we know about.
+    if (authenticateRequest(rdata) == true)
+    {
+        //Oh yeah! Authentication succeeded!
+        return 0;
+    }
+
+    ServerAuthInstancePtr authInstance(createServerAuthInstance(rdata, type));
+    
+    AuthHookSeq hooks = authInstance->getHooks();
+    if (hooks.empty())
+    {
+        return 0;
+    }
+
+    authInstance->fillInRequestInfo(rdata, info);
+
+    //We have our RequestInfo created. Now start calling out to any registered hooks
+    //
+    //XXX While this seems like something that could be taken care of in either the
+    //ServerAuthInstance or AuthManager class, there are some specific issues with this.
+    //For instance, in this case, we create the outgoing message using the inv_session,
+    //whereas other PJSIP modules will either access the base dialog directly
+    //or have a different layer of indirection instead of the inv_session.
+    for (AuthHookSeq::iterator iter = hooks.begin(); iter != hooks.end(); ++iter)
+    {
+        HookResult result;
+        result = (*iter)->challengeRequest(info, digests);
+        if (result.status == Failed)
+        {
+            mImpl->mLogger(Error) << "SIP Authentication hook reported a failure: " << result.info;
+        }
+        else if (result.status == Succeeded)
+        {
+            if (digests.empty())
+            {
+                //Hook says not to challenge. This ServerAuthInstance
+                //is deader than dead.
+                destroyServerAuthInstance(authInstance);
+                return 0;
+            }
+            return authInstance;
+        }
+    }
+    return 0;
+}
+
 bool AuthManager::authenticateRequest(pjsip_rx_data *rdata)
 {
     const std::string fromTag(pj_strbuf(&rdata->msg_info.from->tag),
             pj_strlen(&rdata->msg_info.from->tag));
     const std::string callId(pj_strbuf(&rdata->msg_info.cid->id),
             pj_strlen(&rdata->msg_info.cid->id));
-    boost::shared_ptr<ServerAuthInstance> instance;
+    ServerAuthInstancePtr instance;
     boost::lock_guard<boost::mutex> lock(mImpl->mServerAuthInstancesLock);
-    for (std::vector<boost::shared_ptr<ServerAuthInstance> >::iterator iter = mImpl->mServerAuthInstances.begin();
+    for (std::vector<ServerAuthInstancePtr >::iterator iter = mImpl->mServerAuthInstances.begin();
             iter != mImpl->mServerAuthInstances.end(); ++iter)
     {
         if ((*iter)->isEqual(fromTag, callId))
@@ -405,13 +454,13 @@ bool AuthManager::authenticateRequest(pjsip_rx_data *rdata)
     return false;
 }
 
-void AuthManager::destroyServerAuthInstance(const boost::shared_ptr<ServerAuthInstance> &instance)
+void AuthManager::destroyServerAuthInstance(const ServerAuthInstancePtr &instance)
 {
     boost::lock_guard<boost::mutex> lock(mImpl->mServerAuthInstancesLock);
-    for (std::vector<boost::shared_ptr<ServerAuthInstance> >::iterator iter = mImpl->mServerAuthInstances.begin();
-            iter != mImpl->mServerAuthInstances.end(); ++ iter)
+    for (std::vector<ServerAuthInstancePtr>::iterator iter = mImpl->mServerAuthInstances.begin();
+            iter != mImpl->mServerAuthInstances.end(); ++iter)
     {
-        if (*iter == instance)
+        if ((*iter).get() == instance.get())
         {
             mImpl->mServerAuthInstances.erase(iter);
             break;
@@ -422,7 +471,7 @@ void AuthManager::destroyServerAuthInstance(const boost::shared_ptr<ServerAuthIn
 void AuthManager::destroyServerAuthInstance(const ServerAuthInstance* instance)
 {
     boost::lock_guard<boost::mutex> lock(mImpl->mServerAuthInstancesLock);
-    for (std::vector<boost::shared_ptr<ServerAuthInstance> >::iterator iter = mImpl->mServerAuthInstances.begin();
+    for (std::vector<ServerAuthInstancePtr>::iterator iter = mImpl->mServerAuthInstances.begin();
 	 iter != mImpl->mServerAuthInstances.end(); ++ iter)
     {
         if ((*iter).get() == instance)
@@ -461,7 +510,7 @@ void AuthManager::getAuthCredentials(pjsip_rx_data *rdata, std::vector<pjsip_cre
     }
 }
 
-void AuthManager::scheduleAuthTimeout(const boost::shared_ptr<ServerAuthInstance> &instance, pj_timer_heap_callback *cb)
+void AuthManager::scheduleAuthTimeout(const ServerAuthInstancePtr &instance, pj_timer_heap_callback *cb)
 {
     instance->scheduleAuthTimeout(mImpl->mCounter++, cb);
 }
diff --git a/src/AuthManager.h b/src/AuthManager.h
index 7dea61b..d9bdb23 100644
--- a/src/AuthManager.h
+++ b/src/AuthManager.h
@@ -43,7 +43,7 @@ class ServerAuthInstancePriv;
  * as the authentication server to authenticate a
  * SIP requester.
  */
-class ServerAuthInstance
+class ServerAuthInstance : public IceUtil::Shared
 {
 public:
 
@@ -107,6 +107,8 @@ private:
     boost::shared_ptr<ServerAuthInstancePriv> mImpl;
 };
 
+typedef IceUtil::Handle<ServerAuthInstance> ServerAuthInstancePtr;
+
 class AuthManagerPriv;
 
 /**
@@ -136,7 +138,11 @@ public:
      * so that the AuthManager will have a reference to the ServerAuthInstance
      * for later.
      */
-    boost::shared_ptr<ServerAuthInstance> createServerAuthInstance(pjsip_rx_data *rdata, AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type);
+    ServerAuthInstancePtr createServerAuthInstance(pjsip_rx_data *rdata, AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type);
+    ServerAuthInstancePtr checkAuth(pjsip_rx_data *rdata,
+            AsteriskSCF::SIP::ExtensionPoint::V1::RequestInfoPtr& info,
+            AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type,
+            AsteriskSCF::SIP::ExtensionPoint::V1::DigestChallengeSeq& digests);
     /**
      * Call out to registered hooks to get credentials.
      *
@@ -151,7 +157,7 @@ public:
      * the requester does not attempt to authenticate or never succeeds
      * in authenticating, the ServerAuthInstance will eventually be destroyed.
      */
-    void scheduleAuthTimeout(const boost::shared_ptr<ServerAuthInstance> &instance, pj_timer_heap_callback *cb);
+    void scheduleAuthTimeout(const ServerAuthInstancePtr &instance, pj_timer_heap_callback *cb);
     /**
      * Destroy an ServerAuthInstance
      * 
@@ -159,7 +165,7 @@ public:
      * but a failure condition occurs before a challenge can be sent to the
      * requesting UA.
      */
-    void destroyServerAuthInstance(const boost::shared_ptr<ServerAuthInstance> &instance);
+    void destroyServerAuthInstance(const ServerAuthInstancePtr &instance);
     /**
      * Destroy an ServerAuthInstance
      */
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index 101fbdf..f25624e 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -705,62 +705,25 @@ private:
 
 bool PJSipRegistrarModule::checkAuth(pjsip_rx_data *rdata, pjsip_transaction *tsx, RequestType type)
 {
-    //First, let's see if this message has some auth that we know about.
-    if (mAuthManager->authenticateRequest(rdata) == true)
-    {
-        //Oh yeah! Authentication succeeded!
-        return false;
-    }
+    DigestChallengeSeq digests;
+    RequestInfoPtr info(new RegisterRequestInfo);
+    ServerAuthInstancePtr authInstance =
+        mAuthManager->checkAuth(rdata, info, type, digests);
 
-    boost::shared_ptr<ServerAuthInstance> authInstance(mAuthManager->createServerAuthInstance(rdata, type));
-    
-    std::vector<AuthHookPrx> hooks = authInstance->getHooks();
-    if (hooks.empty())
+    if (!authInstance)
     {
         return false;
     }
 
-    RequestInfoPtr info(new RegisterRequestInfo);
-    authInstance->fillInRequestInfo(rdata, info);
-
-    //We have our RequestInfo created. Now start calling out to any registered hooks
-    //
-    //XXX While this seems like something that could be taken care of in either the
-    //ServerAuthInstance or AuthManager class, there are some specific issues with this.
-    //For instance, in this case, we create the outgoing message using the inv_session,
-    //whereas other PJSIP modules will either access the base dialog directly
-    //or have a different layer of indirection instead of the inv_session.
-    for (std::vector<AuthHookPrx>::iterator iter = hooks.begin(); iter != hooks.end(); ++iter)
-    {
-        DigestChallengeSeq digests;
-        HookResult result;
-        result = (*iter)->challengeRequest(info, digests);
-        if (result.status == Failed)
-        {
-            lg(Error) << "SIP Authentication hook reported a failure: " << result.info;
-        }
-        else if (result.status == Succeeded)
-        {
-            if (digests.empty())
-            {
-                //Hook says not to challenge. This ServerAuthInstance
-                //is deader than dead.
-                mAuthManager->destroyServerAuthInstance(authInstance);
-                return false;
-            }
-
-            pjsip_tx_data *tdata;
-            pjsip_endpt_create_response(tsx->endpt, rdata, 401, NULL, &tdata);
-
-            authInstance->addDigests(tdata, digests);
-
-            pjsip_tsx_send_msg(tsx, tdata);
-
-            mAuthManager->scheduleAuthTimeout(authInstance, registrarAuthTimeout);
-            return true;
-        }
-    }
-    return false;
+    pjsip_tx_data *tdata;
+    pjsip_endpt_create_response(tsx->endpt, rdata, 401, NULL, &tdata);
+    
+    authInstance->addDigests(tdata, digests);
+    
+    pjsip_tsx_send_msg(tsx, tdata);
+    
+    mAuthManager->scheduleAuthTimeout(authInstance, registrarAuthTimeout);
+    return true;
 }
 
 void PJSipRegistrarModule::authTimeout(pj_timer_heap_t *timer_heap, pj_timer_entry *entry)
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 9e960d8..5d1d207 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -338,61 +338,24 @@ pj_status_t PJSipSessionModule::unload()
 
 bool PJSipSessionModule::checkAuth(pjsip_rx_data *rdata, pjsip_inv_session *inv, RequestInfoPtr& info, RequestType type)
 {
-    //First, let's see if this message has some auth that we know about.
-    if (mAuthManager->authenticateRequest(rdata) == true)
-    {
-        //Oh yeah! Authentication succeeded!
-        return false;
-    }
+    DigestChallengeSeq digests;
+    ServerAuthInstancePtr authInstance =
+        mAuthManager->checkAuth(rdata, info, type, digests);
 
-    boost::shared_ptr<ServerAuthInstance> authInstance(mAuthManager->createServerAuthInstance(rdata, type));
-    
-    AuthHookSeq hooks = authInstance->getHooks();
-    if (hooks.empty())
+    if (!authInstance)
     {
         return false;
     }
 
-    authInstance->fillInRequestInfo(rdata, info);
-
-    //We have our RequestInfo created. Now start calling out to any registered hooks
-    //
-    //XXX While this seems like something that could be taken care of in either the
-    //ServerAuthInstance or AuthManager class, there are some specific issues with this.
-    //For instance, in this case, we create the outgoing message using the inv_session,
-    //whereas other PJSIP modules will either access the base dialog directly
-    //or have a different layer of indirection instead of the inv_session.
-    for (AuthHookSeq::iterator iter = hooks.begin(); iter != hooks.end(); ++iter)
-    {
-        DigestChallengeSeq digests;
-        HookResult result;
-        result = (*iter)->challengeRequest(info, digests);
-        if (result.status == Failed)
-        {
-            lg(Error) << "SIP Authentication hook reported a failure: " << result.info;
-        }
-        else if (result.status == Succeeded)
-        {
-            if (digests.empty())
-            {
-                //Hook says not to challenge. This ServerAuthInstance
-                //is deader than dead.
-                mAuthManager->destroyServerAuthInstance(authInstance);
-                return false;
-            }
-
-            pjsip_tx_data *tdata;
-            pjsip_inv_end_session(inv, 401, NULL, &tdata);
+    pjsip_tx_data *tdata;
+    pjsip_inv_end_session(inv, 401, NULL, &tdata);
 
-            authInstance->addDigests(tdata, digests);
+    authInstance->addDigests(tdata, digests);
 
-            pjsip_inv_send_msg(inv, tdata);
+    pjsip_inv_send_msg(inv, tdata);
 
-            mAuthManager->scheduleAuthTimeout(authInstance, sessionAuthTimeout);
-            return true;
-        }
-    }
-    return false;
+    mAuthManager->scheduleAuthTimeout(authInstance, sessionAuthTimeout);
+    return true;
 }
 
 class SessionCreationOperation : public SipQueueableOperation
@@ -1489,7 +1452,10 @@ void PJSipSessionModule::handleNonInviteAuthentication(pjsip_inv_session* inv,
 
 void PJSipSessionModule::invOnTsxStateChanged(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e)
 {
-    if (tsx->role == PJSIP_ROLE_UAC && tsx->state == PJSIP_TSX_STATE_COMPLETED)
+    if (e->type == PJSIP_EVENT_RX_MSG &&
+            tsx->role == PJSIP_ROLE_UAC &&
+            tsx->state == PJSIP_TSX_STATE_COMPLETED &&
+            tsx->method.id != PJSIP_INVITE_METHOD)
     {
         int respCode = e->body.tsx_state.src.rdata->msg_info.msg->line.status.code;
         if (respCode == 401 || respCode == 407)

commit 6b8709327b6e2ba09b41863fa5e4de8b84666384
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Nov 17 13:54:32 2011 -0600

    Some further cleanup to Auth code.

diff --git a/src/AuthManager.cpp b/src/AuthManager.cpp
index ec4dd50..34346b1 100644
--- a/src/AuthManager.cpp
+++ b/src/AuthManager.cpp
@@ -28,14 +28,14 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-class AuthHookData
+class AuthHookWrapper
 {
 public:
-    AuthHookData(int priority, const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook,
+    AuthHookWrapper(int priority, const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook,
             const AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq &types)
         : mPriority(priority), mHook(hook), mTypes(types) { }
 
-    bool operator< (const AuthHookData &rhs) const
+    bool operator< (const AuthHookWrapper &rhs) const
     {
         return mPriority < rhs.mPriority;
     }
@@ -45,10 +45,10 @@ public:
     AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq mTypes;
 };
 
-class AuthInstancePriv
+class ServerAuthInstancePriv
 {
 public:
-    AuthInstancePriv(pjsip_rx_data *rdata, const moduleHookVector &moduleHooks,
+    ServerAuthInstancePriv(pjsip_rx_data *rdata, const moduleHookVector &moduleHooks,
             RequestType type, pjsip_endpoint *endpoint, const Logger &logger)
         : mEndpoint(endpoint),
         mPool(pjsip_endpt_create_pool(mEndpoint, "auth%p", 500, 256)),
@@ -75,7 +75,7 @@ public:
         }
     }
 
-    ~AuthInstancePriv()
+    ~ServerAuthInstancePriv()
     {
         pjsip_endpt_release_pool(mEndpoint, mPool);
     }
@@ -134,16 +134,16 @@ public:
     std::string callId;
 };
 
-AuthInstance::AuthInstance(pjsip_rx_data *rdata, const moduleHookVector &hooks,
+ServerAuthInstance::ServerAuthInstance(pjsip_rx_data *rdata, const moduleHookVector &hooks,
         RequestType type, pjsip_endpoint *endpoint, const Logger &logger)
-        : mImpl(new AuthInstancePriv(rdata, hooks, type, endpoint, logger)) { }
+        : mImpl(new ServerAuthInstancePriv(rdata, hooks, type, endpoint, logger)) { }
 
-AuthHookSeq AuthInstance::getHooks()
+AuthHookSeq ServerAuthInstance::getHooks()
 {
     return mImpl->hooks;
 }
 
-bool AuthInstance::authenticate(pjsip_rx_data *rdata)
+bool ServerAuthInstance::authenticate(pjsip_rx_data *rdata)
 {
     //For each server auth, we need to call pjsip_auth_srv_verify(), which will then
     //annoyingly call into the lookup function we created for pjsip. That's where the
@@ -171,14 +171,14 @@ bool AuthInstance::authenticate(pjsip_rx_data *rdata)
 
 static const int AuthTimeoutSeconds = 60;
 
-void AuthInstance::scheduleAuthTimeout(int id, pj_timer_heap_callback *cb)
+void ServerAuthInstance::scheduleAuthTimeout(int id, pj_timer_heap_callback *cb)
 {
     const pj_time_val time = {AuthTimeoutSeconds, 0};
     pj_timer_entry_init(&mImpl->entry, id, this, cb);
     pjsip_endpt_schedule_timer(mImpl->mEndpoint, &mImpl->entry, &time);
 }
 
-void AuthInstance::addDigests(pjsip_tx_data *tdata, const DigestChallengeSeq &digests)
+void ServerAuthInstance::addDigests(pjsip_tx_data *tdata, const DigestChallengeSeq &digests)
 {
     static char qop[] = "auth";
     pj_str_t pjqop = pj_str(qop);
@@ -230,7 +230,7 @@ void AuthInstance::addDigests(pjsip_tx_data *tdata, const DigestChallengeSeq &di
     }
 }
 
-void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr &info)
+void ServerAuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr &info)
 {
     char buf[512];
     size_t pos;
@@ -303,12 +303,12 @@ void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr &info)
     }
 }
 
-bool AuthInstance::isEqual(const std::string &fromTag, const std::string &callId)
+bool ServerAuthInstance::isEqual(const std::string &fromTag, const std::string &callId)
 {
     return fromTag == mImpl->fromTag && callId == mImpl->callId;
 }
 
-void AuthInstance::cancelAuthTimeout()
+void ServerAuthInstance::cancelAuthTimeout()
 {
     pjsip_endpt_cancel_timer(mImpl->mEndpoint, &mImpl->entry);
 }
@@ -322,16 +322,40 @@ public:
 
     ~AuthManagerPriv()
     {
-        mAuthInstances.erase(mAuthInstances.begin(), mAuthInstances.end());
+        mServerAuthInstances.erase(mServerAuthInstances.begin(), mServerAuthInstances.end());
     }
 
-    std::vector<boost::shared_ptr<AuthInstance> > mAuthInstances;
+    Ice::StringSeq 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));
+            mLogger(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;
+    }
+
+    std::vector<boost::shared_ptr<ServerAuthInstance> > mServerAuthInstances;
     pjsip_endpoint *mEndpoint;
     moduleHookVector mRegisteredHooks;
     Logger mLogger;
     int mCounter;
     boost::mutex mHooksLock;
-    boost::mutex mAuthInstancesLock;
+    boost::mutex mServerAuthInstancesLock;
 };
 
 AuthManager::AuthManager(pjsip_endpoint *endpt, const Logger &logger)
@@ -341,16 +365,16 @@ AuthManager::~AuthManager()
 {
 }
 
-boost::shared_ptr<AuthInstance> AuthManager::createAuthInstance(pjsip_rx_data *rdata, RequestType type)
+boost::shared_ptr<ServerAuthInstance> AuthManager::createServerAuthInstance(pjsip_rx_data *rdata, RequestType type)
 {
-    boost::shared_ptr<AuthInstance> instance;
+    boost::shared_ptr<ServerAuthInstance> instance;
     {
         boost::lock_guard<boost::mutex> hookLock(mImpl->mHooksLock);
-        instance.reset(new AuthInstance(rdata, mImpl->mRegisteredHooks,
+        instance.reset(new ServerAuthInstance(rdata, mImpl->mRegisteredHooks,
                 type, mImpl->mEndpoint, mImpl->mLogger));
     }
-    boost::lock_guard<boost::mutex> instancesLock(mImpl->mAuthInstancesLock);
-    mImpl->mAuthInstances.push_back(instance);
+    boost::lock_guard<boost::mutex> instancesLock(mImpl->mServerAuthInstancesLock);
+    mImpl->mServerAuthInstances.push_back(instance);
     return instance;
 }
 
@@ -360,19 +384,19 @@ bool AuthManager::authenticateRequest(pjsip_rx_data *rdata)
             pj_strlen(&rdata->msg_info.from->tag));
     const std::string callId(pj_strbuf(&rdata->msg_info.cid->id),
             pj_strlen(&rdata->msg_info.cid->id));
-    boost::shared_ptr<AuthInstance> instance;
-    boost::lock_guard<boost::mutex> lock(mImpl->mAuthInstancesLock);
-    for (std::vector<boost::shared_ptr<AuthInstance> >::iterator iter = mImpl->mAuthInstances.begin();
-            iter != mImpl->mAuthInstances.end(); ++iter)
+    boost::shared_ptr<ServerAuthInstance> instance;
+    boost::lock_guard<boost::mutex> lock(mImpl->mServerAuthInstancesLock);
+    for (std::vector<boost::shared_ptr<ServerAuthInstance> >::iterator iter = mImpl->mServerAuthInstances.begin();
+            iter != mImpl->mServerAuthInstances.end(); ++iter)
     {
         if ((*iter)->isEqual(fromTag, callId))
         {
             if ((*iter)->authenticate(rdata))
             {
-                //If authentication has succeeded, then we can remove this AuthInstance
+                //If authentication has succeeded, then we can remove this ServerAuthInstance
                 //from our list, and we need to cancel the scheduled task
                 (*iter)->cancelAuthTimeout();
-                mImpl->mAuthInstances.erase(iter);
+                mImpl->mServerAuthInstances.erase(iter);
                 return true;
             }
             break;
@@ -381,58 +405,34 @@ bool AuthManager::authenticateRequest(pjsip_rx_data *rdata)
     return false;
 }
 
-void AuthManager::destroyAuthInstance(const boost::shared_ptr<AuthInstance> &instance)
+void AuthManager::destroyServerAuthInstance(const boost::shared_ptr<ServerAuthInstance> &instance)
 {
-    boost::lock_guard<boost::mutex> lock(mImpl->mAuthInstancesLock);
-    for (std::vector<boost::shared_ptr<AuthInstance> >::iterator iter = mImpl->mAuthInstances.begin();
-            iter != mImpl->mAuthInstances.end(); ++ iter)
+    boost::lock_guard<boost::mutex> lock(mImpl->mServerAuthInstancesLock);
+    for (std::vector<boost::shared_ptr<ServerAuthInstance> >::iterator iter = mImpl->mServerAuthInstances.begin();
+            iter != mImpl->mServerAuthInstances.end(); ++ iter)
     {
         if (*iter == instance)
         {
-            mImpl->mAuthInstances.erase(iter);
+            mImpl->mServerAuthInstances.erase(iter);
             break;
         }
     }
 }
 
-void AuthManager::destroyAuthInstance(const AuthInstance* instance)
+void AuthManager::destroyServerAuthInstance(const ServerAuthInstance* instance)
 {
-    boost::lock_guard<boost::mutex> lock(mImpl->mAuthInstancesLock);
-    for (std::vector<boost::shared_ptr<AuthInstance> >::iterator iter = mImpl->mAuthInstances.begin();
-	 iter != mImpl->mAuthInstances.end(); ++ iter)
+    boost::lock_guard<boost::mutex> lock(mImpl->mServerAuthInstancesLock);
+    for (std::vector<boost::shared_ptr<ServerAuthInstance> >::iterator iter = mImpl->mServerAuthInstances.begin();
+	 iter != mImpl->mServerAuthInstances.end(); ++ iter)
     {
         if ((*iter).get() == instance)
         {
-            mImpl->mAuthInstances.erase(iter);
+            mImpl->mServerAuthInstances.erase(iter);
             break;
         }
     }
 }
 
-Ice::StringSeq AuthManager::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));
-        mImpl->mLogger(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;
-}
-
 void AuthManager::getAuthCredentials(pjsip_rx_data *rdata, std::vector<pjsip_cred_info>& creds, const std::string& endpointName)
 {
     AuthHookSeq hooks = getHooks();
@@ -440,12 +440,11 @@ void AuthManager::getAuthCredentials(pjsip_rx_data *rdata, std::vector<pjsip_cre
             iter != hooks.end(); ++iter)
     {
         ClientAuthSeq auths;
-        Ice::StringSeq realms = getRealms(rdata);
+        Ice::StringSeq realms = mImpl->getRealms(rdata);
 
         HookResult result = (*iter)->respondToChallenge(endpointName, realms, auths);
         if (result.status == Succeeded)
         {
-            //Cool. So now we need to update the auth info on mReg
             for (ClientAuthSeq::iterator authIter = auths.begin();
                     authIter != auths.end(); ++authIter)
             {
@@ -462,20 +461,20 @@ void AuthManager::getAuthCredentials(pjsip_rx_data *rdata, std::vector<pjsip_cre
     }
 }
 
-void AuthManager::scheduleAuthTimeout(const boost::shared_ptr<AuthInstance> &instance, pj_timer_heap_callback *cb)
+void AuthManager::scheduleAuthTimeout(const boost::shared_ptr<ServerAuthInstance> &instance, pj_timer_heap_callback *cb)
 {
     instance->scheduleAuthTimeout(mImpl->mCounter++, cb);
 }
 
 void AuthManager::authTimeout(pj_timer_heap_t *, pj_timer_entry *entry)
 {
-    destroyAuthInstance(static_cast<AuthInstance *>(entry->user_data));
+    destroyServerAuthInstance(static_cast<ServerAuthInstance *>(entry->user_data));
 }
 
 void AuthManager::addAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook,
         int priority, const AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq &types)
 {
-    boost::shared_ptr<AuthHookData> hookData(new AuthHookData(priority, hook, types));
+    boost::shared_ptr<AuthHookWrapper> hookData(new AuthHookWrapper(priority, hook, types));
     boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
     mImpl->mRegisteredHooks.push_back(hookData);
     std::stable_sort(mImpl->mRegisteredHooks.begin(), mImpl->mRegisteredHooks.end());
diff --git a/src/AuthManager.h b/src/AuthManager.h
index 37d4341..7dea61b 100644
--- a/src/AuthManager.h
+++ b/src/AuthManager.h
@@ -30,25 +30,25 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-class AuthHookData;
+class AuthHookWrapper;
 
-typedef std::vector<boost::shared_ptr<AuthHookData> > moduleHookVector;
+typedef std::vector<boost::shared_ptr<AuthHookWrapper> > moduleHookVector;
 
 void sessionAuthTimeout(pj_timer_heap_t *timer_heap, pj_timer_entry *entry);
 
-class AuthInstancePriv;
+class ServerAuthInstancePriv;
 
 /**
- * An AuthInstance represents a single attempt of us
+ * An ServerAuthInstance represents a single attempt of us
  * as the authentication server to authenticate a
  * SIP requester.
  */
-class AuthInstance
+class ServerAuthInstance
 {
 public:
 
     /**
-     * The AuthInstance is able to distill all of the registered hooks
+     * The ServerAuthInstance is able to distill all of the registered hooks
      * down to a smaller list based on the request types that the hooks
      * service. This is a helper function to get the distilled
      * list of hooks.
@@ -71,26 +71,26 @@ public:
      * Attempt to authenticate an incoming request.
      *
      * It's most convenient to just call AuthManager::authenticate() so
-     * that the proper AuthInstance may be found for you.
+     * that the proper ServerAuthInstance may be found for you.
      */
     bool authenticate(pjsip_rx_data *rdata);
 
     /**
-     * Schedule the destruction of this AuthInstance.
+     * Schedule the destruction of this ServerAuthInstance.
      *
      * This will generally be called via AuthManager::scheduleAuthTimeout
      * so that the id parameter can be guaranteed to be unique per
-     * AuthInstance.
+     * ServerAuthInstance.
      */
     void scheduleAuthTimeout(int id, pj_timer_heap_callback *cb);
 
     /**
-     * Cancel the current scheduled auth timeout task on the AuthInstance.
+     * Cancel the current scheduled auth timeout task on the ServerAuthInstance.
      */
     void cancelAuthTimeout();
 
     /**
-     * Determine if this AuthInstance matches a message with the given
+     * Determine if this ServerAuthInstance matches a message with the given
      * from tag and call-id.
      */
     bool isEqual(const std::string &fromTag, const std::string &callId);
@@ -98,19 +98,19 @@ public:
     friend class AuthManager;
 private:
 
-    AuthInstance(pjsip_rx_data *rdata,
+    ServerAuthInstance(pjsip_rx_data *rdata,
             const moduleHookVector &hooks,
             AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type,
             pjsip_endpoint *endpoint,
             const AsteriskSCF::System::Logging::Logger &logger);
 
-    boost::shared_ptr<AuthInstancePriv> mImpl;
+    boost::shared_ptr<ServerAuthInstancePriv> mImpl;
 };
 
 class AuthManagerPriv;
 
 /**
- * The AuthManager contains all AuthInstances
+ * The AuthManager contains all ServerAuthInstances
  * for a given PJSIP module. It also contains
  * all of a PJSIP module's registered authentication
  * hooks.
@@ -123,27 +123,20 @@ public:
     /**
      * Attempt to authenticate a request
      *
-     * This will search through the AuthManager's AuthInstances to
+     * This will search through the AuthManager's ServerAuthInstances to
      * attempt to authenticate the request.
-     * XXX Note that since the current task at hand is just to set
-     * up the extension point for authentication and not to actually
-     * authenticate, this doesn't actually do anything useful.
      */
     bool authenticateRequest(pjsip_rx_data *rdata);
     /**
-     * Create a new AuthInstance
+     * Create a new ServerAuthInstance
      *
      * If a PJSIP module wants to challenge a requester, then
-     * it must create an AuthInstance in order to do so. Do not
-     * construct AuthInstances directly, but rather use this function
-     * so that the AuthManager will have a reference to the AuthInstance
+     * it must create an ServerAuthInstance in order to do so. Do not
+     * construct ServerAuthInstances directly, but rather use this function
+     * so that the AuthManager will have a reference to the ServerAuthInstance
      * for later.
      */
-    boost::shared_ptr<AuthInstance> createAuthInstance(pjsip_rx_data *rdata, AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type);
-    /**
-     * Get the realms from an authentication challenge
-     */
-    Ice::StringSeq getRealms(pjsip_rx_data *rdata);
+    boost::shared_ptr<ServerAuthInstance> createServerAuthInstance(pjsip_rx_data *rdata, AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type);
     /**
      * Call out to registered hooks to get credentials.
      *
@@ -151,26 +144,26 @@ public:
      */
     void getAuthCredentials(pjsip_rx_data *rdata, std::vector<pjsip_cred_info>& creds, const std::string& endpointName);
     /**
-     * Schedule the destruction of an AuthInstance
+     * Schedule the destruction of an ServerAuthInstance
      *
      * After challenging a requester for authentication information,
      * a PJSIP module should call this method. This will ensure that if
      * the requester does not attempt to authenticate or never succeeds
-     * in authenticating, the AuthInstance will eventually be destroyed.
+     * in authenticating, the ServerAuthInstance will eventually be destroyed.
      */
-    void scheduleAuthTimeout(const boost::shared_ptr<AuthInstance> &instance, pj_timer_heap_callback *cb);
+    void scheduleAuthTimeout(const boost::shared_ptr<ServerAuthInstance> &instance, pj_timer_heap_callback *cb);
     /**
-     * Destroy an AuthInstance
+     * Destroy an ServerAuthInstance
      * 
-     * This method is handy for destroying an AuthInstance if one has been created,
+     * This method is handy for destroying an ServerAuthInstance if one has been created,
      * but a failure condition occurs before a challenge can be sent to the
      * requesting UA.
      */
-    void destroyAuthInstance(const boost::shared_ptr<AuthInstance> &instance);
+    void destroyServerAuthInstance(const boost::shared_ptr<ServerAuthInstance> &instance);
     /**
-     * Destroy an AuthInstance
+     * Destroy an ServerAuthInstance
      */
-    void destroyAuthInstance(const AuthInstance* instance);
+    void destroyServerAuthInstance(const ServerAuthInstance* instance);
     /**
      * This is the callback that scheduleAuthDestruction sets up.
      *
@@ -189,12 +182,10 @@ public:
      * Remove all registered authentication hooks from the AuthManager
      */
     void clearAuthHooks();
-
     /**
      * Get all registered hooks
      */
     AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookSeq getHooks();
-
 private:
     boost::shared_ptr<AuthManagerPriv> mImpl;
 };
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index b7193c6..101fbdf 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -712,7 +712,7 @@ bool PJSipRegistrarModule::checkAuth(pjsip_rx_data *rdata, pjsip_transaction *ts
         return false;
     }
 
-    boost::shared_ptr<AuthInstance> authInstance(mAuthManager->createAuthInstance(rdata, type));
+    boost::shared_ptr<ServerAuthInstance> authInstance(mAuthManager->createServerAuthInstance(rdata, type));
     
     std::vector<AuthHookPrx> hooks = authInstance->getHooks();
     if (hooks.empty())
@@ -726,7 +726,7 @@ bool PJSipRegistrarModule::checkAuth(pjsip_rx_data *rdata, pjsip_transaction *ts
     //We have our RequestInfo created. Now start calling out to any registered hooks
     //
     //XXX While this seems like something that could be taken care of in either the
-    //AuthInstance or AuthManager class, there are some specific issues with this.
+    //ServerAuthInstance or AuthManager class, there are some specific issues with this.
     //For instance, in this case, we create the outgoing message using the inv_session,
     //whereas other PJSIP modules will either access the base dialog directly
     //or have a different layer of indirection instead of the inv_session.
@@ -743,9 +743,9 @@ bool PJSipRegistrarModule::checkAuth(pjsip_rx_data *rdata, pjsip_transaction *ts
         {
             if (digests.empty())
             {
-                //Hook says not to challenge. This AuthInstance
+                //Hook says not to challenge. This ServerAuthInstance
                 //is deader than dead.
-                mAuthManager->destroyAuthInstance(authInstance);
+                mAuthManager->destroyServerAuthInstance(authInstance);
                 return false;
             }
 
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 1d81826..9e960d8 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -345,7 +345,7 @@ bool PJSipSessionModule::checkAuth(pjsip_rx_data *rdata, pjsip_inv_session *inv,
         return false;
     }
 
-    boost::shared_ptr<AuthInstance> authInstance(mAuthManager->createAuthInstance(rdata, type));
+    boost::shared_ptr<ServerAuthInstance> authInstance(mAuthManager->createServerAuthInstance(rdata, type));
     
     AuthHookSeq hooks = authInstance->getHooks();
     if (hooks.empty())
@@ -358,7 +358,7 @@ bool PJSipSessionModule::checkAuth(pjsip_rx_data *rdata, pjsip_inv_session *inv,
     //We have our RequestInfo created. Now start calling out to any registered hooks
     //
     //XXX While this seems like something that could be taken care of in either the
-    //AuthInstance or AuthManager class, there are some specific issues with this.
+    //ServerAuthInstance or AuthManager class, there are some specific issues with this.
     //For instance, in this case, we create the outgoing message using the inv_session,
     //whereas other PJSIP modules will either access the base dialog directly
     //or have a different layer of indirection instead of the inv_session.
@@ -375,9 +375,9 @@ bool PJSipSessionModule::checkAuth(pjsip_rx_data *rdata, pjsip_inv_session *inv,
         {
             if (digests.empty())
             {
-                //Hook says not to challenge. This AuthInstance
+                //Hook says not to challenge. This ServerAuthInstance
                 //is deader than dead.
-                mAuthManager->destroyAuthInstance(authInstance);
+                mAuthManager->destroyServerAuthInstance(authInstance);
                 return false;
             }
 

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;
... 1254 lines suppressed ...


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list