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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Jun 17 14:30:47 CDT 2011


branch "registrar" has been updated
       via  57993cd407779a00004dc426cb282f06bccb5bd5 (commit)
       via  413750665895171f8eae4c8d86ff672b04a8f7cd (commit)
       via  b874caeeddf70e7b3911a4312494c8ae6de1ffd4 (commit)
       via  89e5e5522e81f9f9be4351eb6aab5f346a35586d (commit)
       via  448088a4f28ccdf90471cb60642d28bd4fdfd589 (commit)
       via  abbaa0220ce9faf1e97fd4845ee7f78076436193 (commit)
       via  0ffdaa56376184435e2ebb6b59dac42fbde51ab9 (commit)
      from  47ce4d4e87b887297289ff6511bde2feb807a476 (commit)

Summary of changes:
 src/PJSipManager.cpp                     |    6 +-
 src/PJSipRegistrarModule.cpp             |  172 +++++++++++++++++-------------
 src/PJSipRegistrarModule.h               |   77 ++++++++++----
 src/SipEndpoint.cpp                      |    9 ++
 src/SipRegistrarListener.cpp             |   18 +++-
 src/SipSessionManagerEndpointLocator.cpp |   14 +++-
 src/SipStateReplicatorListener.cpp       |   84 +++++++++------
 7 files changed, 249 insertions(+), 131 deletions(-)


- Log -----------------------------------------------------------------
commit 57993cd407779a00004dc426cb282f06bccb5bd5
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 14:26:35 2011 -0500

    Actually remove the target address from a sip endpoint when a binding expires or is removed.
    
    This is a bit hacky but will be less so when endpoints can contain multiple bindings. Comments
    have been sprinkled around to show areas where things are a bit more hacky than others.

diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 3ff806f..9365199 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -139,6 +139,15 @@ void SipEndpoint::setSourceAddress(std::string address, int port)
 
 void SipEndpoint::setTargetAddress(std::string address, int port)
 {
+    if (address.empty() && port == 0)
+    {
+        //Special case where it's clear that we are trying to set NO
+        //destination address on the endpoint, so we set an empty string.
+        //This is a bit hacky but will become severely less so once
+        //endpoints may support multiple target addresses.
+        mImplPriv->mConfig.transportConfig.address = "";
+        return;
+    }
     char target[64];
     pj_ansi_snprintf(target, sizeof(target), "%s:%d", address.c_str(), port);
     mImplPriv->mConfig.transportConfig.address = target;
diff --git a/src/SipRegistrarListener.cpp b/src/SipRegistrarListener.cpp
index b351585..29a10e7 100644
--- a/src/SipRegistrarListener.cpp
+++ b/src/SipRegistrarListener.cpp
@@ -87,14 +87,26 @@ void SipDefaultRegistrarListener::contactsAdded(const BindingUpdateSeq& contacts
 
 void SipDefaultRegistrarListener::contactsRemoved(const BindingUpdateSeq& contacts, const Ice::Current&)
 {
+    pj_pool_t *pool = pj_pool_create(&mCachingPool.factory, "DefaultRegistrarListener", 256, 256, NULL);
     for (BindingUpdateSeq::const_iterator iter = contacts.begin(); iter != contacts.end(); ++iter)
     {
-        for (Ice::StringSeq::const_iterator contactIter = iter->contacts.begin();
-                contactIter != iter->contacts.end(); ++contactIter)
+        if (iter->contacts.empty())
         {
-            lg(Debug) << "Removing contact " << *contactIter << " from AoR " << iter->aor;
+            //If an aor has no contacts being removed, bail now.
+            continue;
+        }
+        SipEndpointSeq endpoints = getEndpoints(pool, iter->aor);
+        for (SipEndpointSeq::iterator endpointIter = endpoints.begin();
+                endpointIter != endpoints.end(); ++endpointIter)
+        {
+            lg(Debug) << "Removing contacts " << " from AoR " << iter->aor;
+            //Setting the endpoint's target address to be empty is the method we currently use
+            //to make the endpoint inaccessible. Once endpoints can support multiple addresses,
+            //it'll be a bit less hacky since we can just remove a specific contact from the list.
+            (*endpointIter)->setTargetAddress("", 0);
         }
     }
+    pj_pool_release(pool);
 }
 
 } // namespace SipSessionManager
diff --git a/src/SipSessionManagerEndpointLocator.cpp b/src/SipSessionManagerEndpointLocator.cpp
index 59bcc2c..ff0b388 100644
--- a/src/SipSessionManagerEndpointLocator.cpp
+++ b/src/SipSessionManagerEndpointLocator.cpp
@@ -13,6 +13,7 @@
  * the GNU General Public License Version 2. See the LICENSE.txt file
  * at the top of the source tree.
  */
+#include <AsteriskSCF/logger.h>
 
 #include "SipEndpointFactory.h"
 #include "SipSessionManagerEndpointLocator.h"
@@ -26,6 +27,12 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
+using namespace AsteriskSCF::System::Logging;
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
+}
+
 /**
  * Provide lookup capability to the Asterisk SCF system for endpoints that this component mananges. This 
  * operation is typically invoked by the routing service.
@@ -40,13 +47,18 @@ void SipSessionManagerEndpointLocator::lookup_async(const ::AsteriskSCF::Core::R
 
     if (endpoint != 0)
     {
+        if (endpoint->getConfig().transportConfig.address.empty())
+        {
+            lg(Warning) << "Endpoint " << endpoint->getName() << " located, but no destination address configured";
+            cb->ice_exception(::AsteriskSCF::Core::Routing::V1::DestinationNotFoundException(destination));
+            return;
+        }
         endpoints.push_back(endpoint->getEndpointProxy());
         cb->ice_response(endpoints);
         return;
     }
     
     cb->ice_exception(::AsteriskSCF::Core::Routing::V1::DestinationNotFoundException(destination));
-    
 }
 
 }; // end SipSessionManager

commit 413750665895171f8eae4c8d86ff672b04a8f7cd
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 13:04:16 2011 -0500

    Catch exceptions while attempting to replicate state.

diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index 3d96669..8f816bb 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -221,6 +221,11 @@ void PJSipRegistrarModule::replicateState(
         lg(Error) << "No endpoint when attempting to create oneway proxy for state replication in registrar";
         return;
     }
+    catch (const Ice::Exception& ex)
+    {
+        lg(Error) << "Caught exception while attempting to create oneway proxy for state replication in registrar\n" << ex.what();
+        return;
+    }
 
     try
     {
@@ -255,6 +260,10 @@ void PJSipRegistrarModule::replicateState(
     {
         lg(Error) << "State replication operations are not oneway";
     }
+    catch (const Ice::Exception& ex)
+    {
+        lg(Error) << "Exception caught attempting to replicate state in registrar\n" << ex.what();
+    }
 }
 
 void RegistrarI::updateBindings(const std::string &aor, BindingWrapperSeq& newBindings, BindingWrapperSeq& removedBindings)

commit b874caeeddf70e7b3911a4312494c8ae6de1ffd4
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 12:16:38 2011 -0500

    Actually define the PJSipManager::getEndpoint method.

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 334c6d4..85b157b 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -108,6 +108,11 @@ void PJSipManager::registerRegistrarModule(
             adapter->getCommunicator()->stringToIdentity(RegistrarId));
 }
 
+pjsip_endpoint* PJSipManager::getEndpoint()
+{
+    return mEndpoint;
+}
+
 PJSipSessionModulePtr PJSipManager::getSessionModule()
 {
     return mSessionModule;

commit 89e5e5522e81f9f9be4351eb6aab5f346a35586d
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 10:55:46 2011 -0500

    Cover a corner case when replicating state of existing bindings.

diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 66c76d0..05be87f 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -72,6 +72,20 @@ public:
         }
     }
 
+    BindingWrapper *createBindingWrapper(const std::string& aor, const BindingPtr& binding, const RegistrarIPtr& registrar)
+    {
+        int relativeExpiration = binding->expiration - time(NULL);
+
+        BindingWrapper *wrapper(new BindingWrapper(
+                    relativeExpiration,
+                    binding,
+                    registrar,
+                    mManager->getEndpoint(),
+                    aor));
+
+        return wrapper;
+    }
+
     void removeRegistrationState(
             const PJSipRegistrarModulePtr& regModule,
             const SipRegistrarStateItemPtr& regItem)
@@ -86,15 +100,7 @@ public:
             for (BindingSeq::iterator seqIter = bindings.begin();
                     seqIter != bindings.end(); ++seqIter)
             {
-                int relativeExpiration = (*seqIter)->expiration - time(NULL);
-
-                BindingWrapper *wrapper(new BindingWrapper(
-                            relativeExpiration,
-                            *seqIter,
-                            regModule->getRegistrar(),
-                            mManager->getEndpoint(),
-                            dictIter->first));
-
+                BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule->getRegistrar());
                 wrapperSeq.push_back(wrapper);
             }
             regModule->getRegistrar()->updateBindings(dictIter->first, emptySeq, wrapperSeq);
@@ -134,15 +140,7 @@ public:
             for (BindingSeq::iterator seqIter = bindings.begin();
                     seqIter != bindings.end(); ++seqIter)
             {
-                int relativeExpiration = (*seqIter)->expiration - time(NULL);
-
-                BindingWrapper *wrapper(new BindingWrapper(
-                            relativeExpiration,
-                            *seqIter,
-                            regModule->getRegistrar(),
-                            mManager->getEndpoint(),
-                            dictIter->first));
-
+                BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule->getRegistrar());
                 wrapperSeq.push_back(wrapper);
             }
             regModule->getRegistrar()->updateBindings(dictIter->first, wrapperSeq, emptySeq);
@@ -166,12 +164,34 @@ public:
                 dictIter != regItem->bindings.end(); ++dictIter)
         {
             BindingWrapperSeq& bindings = regModule->getRegistrar()->getAORBindingWrappers(dictIter->first);
+
+            BindingWrapperSeq newBindings;
+            BindingWrapperSeq emptySeq;
             for (BindingSeq::iterator seqIter = dictIter->second.begin();
                     seqIter != dictIter->second.end(); ++seqIter)
             {
                 BindingWrapperSeq::iterator bindingToUpdate = 
                     std::find_if(bindings.begin(), bindings.end(), BindingFinder(*seqIter));
-                (*bindingToUpdate)->updateBinding((*seqIter)->callid, (*seqIter)->cseq, (*seqIter)->expiration - time(NULL));
+
+                if (bindingToUpdate == bindings.end())
+                {
+                    //It's possible that we can't find a binding that we supposedly should know about.
+                    //This is potentially due to some sort of clock skew between the primary registrar and
+                    //this replica. In other words, it may be that the replica has already expired the
+                    //binding and removed it before the primary received the REGISTER to renew it.
+                    //
+                    //No biggie, just recreate the binding.
+                    BindingWrapper *wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule->getRegistrar());
+                    newBindings.push_back(wrapper);
+                }
+                else
+                {
+                    (*bindingToUpdate)->updateBinding((*seqIter)->callid, (*seqIter)->cseq, (*seqIter)->expiration - time(NULL));
+                }
+            }
+            if (!newBindings.empty())
+            {
+                regModule->getRegistrar()->updateBindings(dictIter->first, newBindings, emptySeq);
             }
         }
     }

commit 448088a4f28ccdf90471cb60642d28bd4fdfd589
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 10:23:45 2011 -0500

    Use oneway proxies for state replication.

diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index b2b948a..3d96669 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -45,6 +45,8 @@ static void registrationExpired(pj_timer_heap_t *, struct pj_timer_entry *entry)
         wrapper->mRegistrar->removeAOR(wrapper->mAOR);
     }
     delete wrapper;
+    //Note that we do not replicate state when a binding expires. This is because replicas
+    //maintain their own timers and will erase the bindings themselves when they expire.
 }
 
 static int expirationId;
@@ -209,31 +211,49 @@ void PJSipRegistrarModule::replicateState(
         BindingWrapperSeq& newBindings,
         BindingWrapperSeq& removedBindings)
 {
-    if (!newBindings.empty())
+    try
     {
-        BindingDict newDict = mRegistrar->createBindingDict(aor, newBindings);
-        SipRegistrarStateItemPtr newItem(new SipRegistrarStateItem(aor, aor, newDict, true));
-        SipStateItemSeq items;
-        items.push_back(newItem);
-        mStateReplicator->setState(items);
+        AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator =
+            AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(mStateReplicator->ice_oneway());
     }
-    
-    if (!existingBindings.empty())
+    catch (const Ice::NoEndpointException&)
     {
-        BindingDict existingDict = mRegistrar->createBindingDict(aor, existingBindings);
-        SipRegistrarStateItemPtr existingItem(new SipRegistrarStateItem(aor, aor, existingDict, false));
-        SipStateItemSeq items;
-        items.push_back(existingItem);
-        mStateReplicator->setState(items);
+        lg(Error) << "No endpoint when attempting to create oneway proxy for state replication in registrar";
+        return;
     }
 
-    if (!removedBindings.empty())
+    try
     {
-        BindingDict removedDict = mRegistrar->createBindingDict(aor, removedBindings);
-        SipRegistrarStateItemPtr removedItem(new SipRegistrarStateItem(aor, aor, removedDict, false));
-        SipStateItemSeq items;
-        items.push_back(removedItem);
-        mStateReplicator->removeStateForItems(items);
+        if (!newBindings.empty())
+        {
+            BindingDict newDict = mRegistrar->createBindingDict(aor, newBindings);
+            SipRegistrarStateItemPtr newItem(new SipRegistrarStateItem(aor, aor, newDict, true));
+            SipStateItemSeq items;
+            items.push_back(newItem);
+            mStateReplicator->setState(items);
+        }
+        
+        if (!existingBindings.empty())
+        {
+            BindingDict existingDict = mRegistrar->createBindingDict(aor, existingBindings);
+            SipRegistrarStateItemPtr existingItem(new SipRegistrarStateItem(aor, aor, existingDict, false));
+            SipStateItemSeq items;
+            items.push_back(existingItem);
+            mStateReplicator->setState(items);
+        }
+
+        if (!removedBindings.empty())
+        {
+            BindingDict removedDict = mRegistrar->createBindingDict(aor, removedBindings);
+            SipRegistrarStateItemPtr removedItem(new SipRegistrarStateItem(aor, aor, removedDict, false));
+            SipStateItemSeq items;
+            items.push_back(removedItem);
+            mStateReplicator->removeStateForItems(items);
+        }
+    }
+    catch (const Ice::TwowayOnlyException&)
+    {
+        lg(Error) << "State replication operations are not oneway";
     }
 }
 

commit abbaa0220ce9faf1e97fd4845ee7f78076436193
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 09:54:12 2011 -0500

    Add some simple comments to explain some things.

diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index 742665f..7203ef3 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -43,10 +43,23 @@ public:
 
     ~BindingWrapper();
 
+    /**
+     * Called when a binding expires.
+     */
     void expireRegistration();
+    /**
+     * Schedule expiration of a binding.
+     */
     void scheduleRegistrationExpiration(int expiration);
+    /**
+     * Cancel the expiration of a binding.
+     */
     void cancelRegistrationExpiration();
 
+    /**
+     * Update the binding in the wrapper with new information. This will
+     * result in rescheduling destruction of the binding.
+     */
     void updateBinding(const std::string &callID, int cSeq, int expiration);
 
     bool operator==(const BindingWrapper& rhs);
@@ -112,14 +125,39 @@ public:
     void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event);
     RegistrarIPtr getRegistrar();
 private:
+    /**
+     * Extract the AoR from the To header of a REGISTER request
+     */
     std::string getAOR(pjsip_rx_data *rdata);
+    /**
+     * Get the Contact URIs from a REGISTER request
+     */
     std::vector<pjsip_contact_hdr *> extractRegisterContacts(pjsip_rx_data *rdata);
+    /**
+     * Try to find an existing BindingWrapper matching a Contact header from
+     * a REGISTER
+     */
     BindingWrapperSeq::iterator findMatchingBinding(pjsip_contact_hdr *contact,
             BindingWrapperSeq& bindings);
+    /**
+     * Find the expiration of a binding from a REGISTER request
+     */
     int getExpiration(pjsip_contact_hdr *contact, pjsip_rx_data *rdata);
+    /**
+     * Create a new BindingWrapper based on information extracted from a
+     * REGISTER request
+     */
     BindingWrapper *createNewBinding(pjsip_contact_hdr *contact,
             const std::string& callID, int cSeq, int expiration, const std::string& aor);
 
+    /**
+     * Replicate state of bindings currently held by this registrar.
+     *
+     * State replication will send at most three RPCs.
+     * The first will contain any new bindings added by a REGISTER
+     * The next will contain any updates to existing bindings from a REGISTER
+     * The final will contain any bindings removed from a REGISTER
+     */
     void replicateState(
         const std::string &aor,
         BindingWrapperSeq& existingBindings,

commit 0ffdaa56376184435e2ebb6b59dac42fbde51ab9
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 17 09:36:03 2011 -0500

    s/BindingWrapper/BindingHolder/g

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 4e96b4c..334c6d4 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -106,7 +106,6 @@ void PJSipManager::registerRegistrarModule(
     //the object adapter
     adapter->add(mRegistrarModule->getRegistrar(),
             adapter->getCommunicator()->stringToIdentity(RegistrarId));
-    //XXX I suppose we need to add the registrar to the service locator too.
 }
 
 PJSipSessionModulePtr PJSipManager::getSessionModule()
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index ff5a3b9..b2b948a 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -35,21 +35,21 @@ namespace SipSessionManager
 
 static void registrationExpired(pj_timer_heap_t *, struct pj_timer_entry *entry)
 {
-    BindingHolder *holder = static_cast<BindingHolder *>(entry->user_data);
-    lg(Debug) << "Detected expiration of binding " << holder->mBinding->contact;
-    holder->cancelRegistrationExpiration();
-    BindingHolderSeq& currentBindings = holder->mRegistrar->getAORBindingHolders(holder->mAOR);
-    holder->mRegistrar->removeBinding(currentBindings, holder);
+    BindingWrapper *wrapper = static_cast<BindingWrapper *>(entry->user_data);
+    lg(Debug) << "Detected expiration of binding " << wrapper->mBinding->contact;
+    wrapper->cancelRegistrationExpiration();
+    BindingWrapperSeq& currentBindings = wrapper->mRegistrar->getAORBindingWrappers(wrapper->mAOR);
+    wrapper->mRegistrar->removeBinding(currentBindings, wrapper);
     if (currentBindings.empty())
     {
-        holder->mRegistrar->removeAOR(holder->mAOR);
+        wrapper->mRegistrar->removeAOR(wrapper->mAOR);
     }
-    delete holder;
+    delete wrapper;
 }
 
 static int expirationId;
 
-BindingHolder::BindingHolder(
+BindingWrapper::BindingWrapper(
         int expiration,
         const BindingPtr& binding,
         const RegistrarIPtr& registrar,
@@ -63,38 +63,33 @@ BindingHolder::BindingHolder(
     pjsip_endpt_schedule_timer(mEndpoint, &mEntry, &delay);
 }
 
-BindingHolder::~BindingHolder()
+BindingWrapper::~BindingWrapper()
 {
     cancelRegistrationExpiration();
 }
 
-bool BindingHolder::operator==(const BindingHolder& rhs)
+bool BindingWrapper::operator==(const BindingWrapper& rhs)
 {
     return mBinding->contact == rhs.mBinding->contact;
 }
 
-bool BindingHolder::operator==(const BindingPtr& rhs)
+bool BindingWrapper::operator==(const BindingPtr& rhs)
 {
     return mBinding->contact == rhs->contact;
 }
 
-bool BindingHolder::operator==(const Binding& rhs)
-{
-    return mBinding->contact == rhs.contact;
-}
-
-void BindingHolder::cancelRegistrationExpiration()
+void BindingWrapper::cancelRegistrationExpiration()
 {
     pjsip_endpt_cancel_timer(mEndpoint, &mEntry);
 }
 
-void BindingHolder::scheduleRegistrationExpiration(int expiration)
+void BindingWrapper::scheduleRegistrationExpiration(int expiration)
 {
     pj_time_val delay = {expiration, 0};
     pjsip_endpt_schedule_timer(mEndpoint, &mEntry, &delay);
 }
 
-void BindingHolder::updateBinding(const std::string &callID, int cSeq, int expiration)
+void BindingWrapper::updateBinding(const std::string &callID, int cSeq, int expiration)
 {
     mBinding->callid = callID;
     mBinding->cseq = cSeq;
@@ -132,14 +127,14 @@ BindingDict RegistrarI::getAllBindings(const Ice::Current&)
     BindingDict returnedBindings;
     //XXX
     //This is suboptimal. What may work better is to maintain 
-    //parallel maps of BindingHolders and Bindings so that
+    //parallel maps of BindingWrappers and Bindings so that
     //we can quickly return the appropriate information instead of
     //having to construct a BindingDict on each call.
-    for (BindingHolderDict::iterator iter = mBindings.begin();
+    for (BindingWrapperDict::iterator iter = mBindings.begin();
             iter != mBindings.end(); ++iter)
     {
         BindingSeq bindings;
-        for (BindingHolderSeq::iterator seqIter = iter->second.begin();
+        for (BindingWrapperSeq::iterator seqIter = iter->second.begin();
                 seqIter != iter->second.end(); ++seqIter)
         {
             bindings.push_back((*seqIter)->mBinding);
@@ -151,11 +146,11 @@ BindingDict RegistrarI::getAllBindings(const Ice::Current&)
 
 BindingSeq RegistrarI::getAORBindings(const std::string &aor, const Ice::Current&)
 {
-    BindingHolderDict::iterator iter = mBindings.find(aor);
+    BindingWrapperDict::iterator iter = mBindings.find(aor);
     if (iter != mBindings.end())
     {
         BindingSeq bindings;
-        for (BindingHolderSeq::iterator seqIter = iter->second.begin();
+        for (BindingWrapperSeq::iterator seqIter = iter->second.begin();
                 seqIter != iter->second.end(); ++seqIter)
         {
             bindings.push_back((*seqIter)->mBinding);
@@ -169,11 +164,11 @@ BindingSeq RegistrarI::getAORBindings(const std::string &aor, const Ice::Current
     }
 }
 
-static BindingHolderSeq Empty;
+static BindingWrapperSeq Empty;
 
-BindingHolderSeq& RegistrarI::getAORBindingHolders(const std::string &aor)
+BindingWrapperSeq& RegistrarI::getAORBindingWrappers(const std::string &aor)
 {
-    BindingHolderDict::iterator iter = mBindings.find(aor);
+    BindingWrapperDict::iterator iter = mBindings.find(aor);
     if (iter != mBindings.end())
     {
         return iter->second;
@@ -184,10 +179,10 @@ BindingHolderSeq& RegistrarI::getAORBindingHolders(const std::string &aor)
     }
 }
 
-void RegistrarI::removeBinding(BindingHolderSeq& currentBindings, BindingHolder *holder)
+void RegistrarI::removeBinding(BindingWrapperSeq& currentBindings, BindingWrapper *wrapper)
 {
-    lg(Debug) << "Removing binding " << holder->mBinding->contact;
-    currentBindings.erase(std::remove(currentBindings.begin(), currentBindings.end(), holder), currentBindings.end());
+    lg(Debug) << "Removing binding " << wrapper->mBinding->contact;
+    currentBindings.erase(std::remove(currentBindings.begin(), currentBindings.end(), wrapper), currentBindings.end());
 }
 
 void RegistrarI::removeAOR(const std::string& aor)
@@ -195,10 +190,10 @@ void RegistrarI::removeAOR(const std::string& aor)
     mBindings.erase(aor);
 }
 
-BindingDict RegistrarI::createBindingDict(const std::string& aor, const BindingHolderSeq& bindings)
+BindingDict RegistrarI::createBindingDict(const std::string& aor, const BindingWrapperSeq& bindings)
 {
     BindingSeq returnedBindings;
-    for (BindingHolderSeq::const_iterator seqIter = bindings.begin();
+    for (BindingWrapperSeq::const_iterator seqIter = bindings.begin();
             seqIter != bindings.end(); ++seqIter)
     {
         returnedBindings.push_back((*seqIter)->mBinding);
@@ -210,9 +205,9 @@ BindingDict RegistrarI::createBindingDict(const std::string& aor, const BindingH
 
 void PJSipRegistrarModule::replicateState(
         const std::string &aor,
-        BindingHolderSeq& existingBindings,
-        BindingHolderSeq& newBindings,
-        BindingHolderSeq& removedBindings)
+        BindingWrapperSeq& existingBindings,
+        BindingWrapperSeq& newBindings,
+        BindingWrapperSeq& removedBindings)
 {
     if (!newBindings.empty())
     {
@@ -242,10 +237,10 @@ void PJSipRegistrarModule::replicateState(
     }
 }
 
-void RegistrarI::updateBindings(const std::string &aor, BindingHolderSeq& newBindings, BindingHolderSeq& removedBindings)
+void RegistrarI::updateBindings(const std::string &aor, BindingWrapperSeq& newBindings, BindingWrapperSeq& removedBindings)
 {
 
-    BindingHolderDict::iterator aorBindings = mBindings.find(aor);
+    BindingWrapperDict::iterator aorBindings = mBindings.find(aor);
 
     if (aorBindings == mBindings.end())
     {
@@ -257,13 +252,13 @@ void RegistrarI::updateBindings(const std::string &aor, BindingHolderSeq& newBin
     }
     else
     {
-        BindingHolderSeq& currentBindings = aorBindings->second;
+        BindingWrapperSeq& currentBindings = aorBindings->second;
         if (!newBindings.empty())
         {
             lg(Debug) << "Adding new bindings for aor " << aor;
             currentBindings.insert(currentBindings.end(), newBindings.begin(), newBindings.end());
         }
-        for (BindingHolderSeq::iterator iter = removedBindings.begin(); iter != removedBindings.end(); ++iter)
+        for (BindingWrapperSeq::iterator iter = removedBindings.begin(); iter != removedBindings.end(); ++iter)
         {
             removeBinding(currentBindings, *iter);
             delete *iter;
@@ -287,11 +282,11 @@ void RegistrarI::updateBindings(const std::string &aor, BindingHolderSeq& newBin
     }
 }
 
-BindingUpdateSeq RegistrarI::createBindingUpdateSeq(const std::string& aor, BindingHolderSeq& bindings)
+BindingUpdateSeq RegistrarI::createBindingUpdateSeq(const std::string& aor, BindingWrapperSeq& bindings)
 {
     BindingUpdateSeq returnedSeq;
     Ice::StringSeq contacts;
-    for (BindingHolderSeq::iterator iter = bindings.begin(); iter != bindings.end(); ++iter)
+    for (BindingWrapperSeq::iterator iter = bindings.begin(); iter != bindings.end(); ++iter)
     {
         contacts.push_back((*iter)->mBinding->contact);
     }
@@ -380,7 +375,7 @@ bool verifyContacts(const std::vector<pjsip_contact_hdr *>& contacts)
     return true;
 }
 
-BindingHolderSeq::iterator PJSipRegistrarModule::findMatchingBinding(pjsip_contact_hdr *contact, BindingHolderSeq& bindings)
+BindingWrapperSeq::iterator PJSipRegistrarModule::findMatchingBinding(pjsip_contact_hdr *contact, BindingWrapperSeq& bindings)
 {
     char buf[512];
     pjsip_sip_uri *contactURI = (pjsip_sip_uri *)pjsip_uri_get_uri(contact->uri);
@@ -388,7 +383,7 @@ BindingHolderSeq::iterator PJSipRegistrarModule::findMatchingBinding(pjsip_conta
     std::string contactURIStr(buf, strlen(buf));
 
     lg(Debug) << "Searching for binding " << contactURIStr;
-    for (BindingHolderSeq::iterator iter = bindings.begin(); iter != bindings.end(); ++iter)
+    for (BindingWrapperSeq::iterator iter = bindings.begin(); iter != bindings.end(); ++iter)
     {
         lg(Debug) << "Comparing REGISTER contact " << contactURIStr << " with binding contact " << (*iter)->mBinding->contact;
         if (contactURIStr == (*iter)->mBinding->contact)
@@ -427,7 +422,7 @@ int PJSipRegistrarModule::getExpiration(pjsip_contact_hdr *contact, pjsip_rx_dat
     }
 }
 
-BindingHolder *PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *contact, const std::string &callID, int cSeq, int expiration, const std::string& aor)
+BindingWrapper *PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *contact, const std::string &callID, int cSeq, int expiration, const std::string& aor)
 {
     char buf[512];
     pjsip_sip_uri *contactURI = (pjsip_sip_uri *)pjsip_uri_get_uri(contact->uri);
@@ -440,10 +435,10 @@ BindingHolder *PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *contact
         << ", and Expires: " << expiration;
 
     BindingPtr binding(new Binding(contactURIStr, callID, cSeq, time(NULL) + expiration));
-    BindingHolder *holder(new BindingHolder(expiration, binding, mRegistrar, mEndpoint, aor));
-    //We could just return binding, but using holder here makes the compiler
+    BindingWrapper *wrapper(new BindingWrapper(expiration, binding, mRegistrar, mEndpoint, aor));
+    //We could just return binding, but using wrapper here makes the compiler
     //not complain about an unused variable.
-    return holder;
+    return wrapper;
 }
 
 pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
@@ -472,7 +467,7 @@ pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
 
     std::string aor = getAOR(rdata);
     lg(Debug) << "AoR in REGISTER is " << aor;
-    BindingHolderSeq& currentBindings = mRegistrar->getAORBindingHolders(aor);
+    BindingWrapperSeq& currentBindings = mRegistrar->getAORBindingWrappers(aor);
     std::vector<pjsip_contact_hdr *> registerContacts = extractRegisterContacts(rdata);
 
     std::string callID(pj_strbuf(&rdata->msg_info.cid->id), pj_strlen(&rdata->msg_info.cid->id));
@@ -488,13 +483,13 @@ pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
         pjsip_tsx_send_msg(tsx, tdata);
     }
 
-    BindingHolderSeq newBindings;
-    BindingHolderSeq removedBindings;
-    BindingHolderSeq existingBindings;
+    BindingWrapperSeq newBindings;
+    BindingWrapperSeq removedBindings;
+    BindingWrapperSeq existingBindings;
     for (std::vector<pjsip_contact_hdr *>::iterator iter = registerContacts.begin();
             iter != registerContacts.end(); ++iter)
     {
-        BindingHolderSeq::iterator bindingToUpdate = findMatchingBinding(*iter, currentBindings);
+        BindingWrapperSeq::iterator bindingToUpdate = findMatchingBinding(*iter, currentBindings);
 
         int expiration = getExpiration(*iter, rdata);
 
@@ -514,9 +509,9 @@ pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
         }
         else
         {
-            BindingHolder *holder = createNewBinding(*iter, callID, cSeq, expiration, aor);
-            lg(Debug) << "Adding " << holder->mBinding->contact << " to our bindings to add";
-            newBindings.push_back(holder);
+            BindingWrapper *wrapper = createNewBinding(*iter, callID, cSeq, expiration, aor);
+            lg(Debug) << "Adding " << wrapper->mBinding->contact << " to our bindings to add";
+            newBindings.push_back(wrapper);
         }
     }
 
diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index 1510c96..742665f 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -31,17 +31,17 @@ namespace SipSessionManager
 class RegistrarI;
 typedef IceUtil::Handle<RegistrarI> RegistrarIPtr;
 
-class BindingHolder
+class BindingWrapper
 {
 public:
-    BindingHolder(
+    BindingWrapper(
             int expiration,
             const AsteriskSCF::SIP::Registration::V1::BindingPtr& binding,
             const RegistrarIPtr& registrar,
             pjsip_endpoint *endpt,
             const std::string& aor);
 
-    ~BindingHolder();
+    ~BindingWrapper();
 
     void expireRegistration();
     void scheduleRegistrationExpiration(int expiration);
@@ -49,9 +49,8 @@ public:
 
     void updateBinding(const std::string &callID, int cSeq, int expiration);
 
-    bool operator==(const BindingHolder& rhs);
+    bool operator==(const BindingWrapper& rhs);
     bool operator==(const AsteriskSCF::SIP::Registration::V1::BindingPtr& rhs);
-    bool operator==(const AsteriskSCF::SIP::Registration::V1::Binding& rhs);
 
     RegistrarIPtr mRegistrar;
     AsteriskSCF::SIP::Registration::V1::BindingPtr mBinding;
@@ -60,8 +59,8 @@ public:
     const std::string mAOR;
 };
 
-typedef std::vector<BindingHolder *> BindingHolderSeq;
-typedef std::map<std::string, BindingHolderSeq> BindingHolderDict;
+typedef std::vector<BindingWrapper *> BindingWrapperSeq;
+typedef std::map<std::string, BindingWrapperSeq> BindingWrapperDict;
 
 class RegistrarI : public AsteriskSCF::SIP::Registration::V1::Registrar
 {
@@ -72,25 +71,25 @@ public:
     AsteriskSCF::SIP::Registration::V1::BindingDict getAllBindings(const Ice::Current&);
     AsteriskSCF::SIP::Registration::V1::BindingSeq getAORBindings(const std::string &aor, const Ice::Current&);
 
-    BindingHolderSeq& getAORBindingHolders(const std::string &aor);
+    BindingWrapperSeq& getAORBindingWrappers(const std::string &aor);
 
-    void removeBinding(BindingHolderSeq& currentBindings, BindingHolder *holder);
+    void removeBinding(BindingWrapperSeq& currentBindings, BindingWrapper *wrapper);
     void removeAOR(const std::string& aor);
 
     void updateBindings(
             const std::string &aor,
-            BindingHolderSeq& newBindings,
-            BindingHolderSeq& removedBindings);
+            BindingWrapperSeq& newBindings,
+            BindingWrapperSeq& removedBindings);
 
     AsteriskSCF::SIP::Registration::V1::BindingUpdateSeq createBindingUpdateSeq(
             const std::string& aor,
-            BindingHolderSeq& bindings);
+            BindingWrapperSeq& bindings);
 
     
-    AsteriskSCF::SIP::Registration::V1::BindingDict createBindingDict(const std::string& aor, const BindingHolderSeq& bindings);
+    AsteriskSCF::SIP::Registration::V1::BindingDict createBindingDict(const std::string& aor, const BindingWrapperSeq& bindings);
 
 private:
-    BindingHolderDict mBindings;
+    BindingWrapperDict mBindings;
     AsteriskSCF::SIP::Registration::V1::ContactDict mContacts;
     std::vector<AsteriskSCF::SIP::Registration::V1::RegistrarListenerPrx> mListeners;
 };
@@ -115,17 +114,17 @@ public:
 private:
     std::string getAOR(pjsip_rx_data *rdata);
     std::vector<pjsip_contact_hdr *> extractRegisterContacts(pjsip_rx_data *rdata);
-    BindingHolderSeq::iterator findMatchingBinding(pjsip_contact_hdr *contact,
-            BindingHolderSeq& bindings);
+    BindingWrapperSeq::iterator findMatchingBinding(pjsip_contact_hdr *contact,
+            BindingWrapperSeq& bindings);
     int getExpiration(pjsip_contact_hdr *contact, pjsip_rx_data *rdata);
-    BindingHolder *createNewBinding(pjsip_contact_hdr *contact,
+    BindingWrapper *createNewBinding(pjsip_contact_hdr *contact,
             const std::string& callID, int cSeq, int expiration, const std::string& aor);
 
     void replicateState(
         const std::string &aor,
-        BindingHolderSeq& existingBindings,
-        BindingHolderSeq& newBindings,
-        BindingHolderSeq& removedBindings);
+        BindingWrapperSeq& existingBindings,
+        BindingWrapperSeq& newBindings,
+        BindingWrapperSeq& removedBindings);
 
     pjsip_endpoint *mEndpoint;
     RegistrarIPtr mRegistrar;
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 4769f8f..66c76d0 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -81,23 +81,23 @@ public:
         {
 
             BindingSeq bindings = dictIter->second;
-            BindingHolderSeq emptySeq;
-            BindingHolderSeq holderSeq;
+            BindingWrapperSeq emptySeq;
+            BindingWrapperSeq wrapperSeq;
             for (BindingSeq::iterator seqIter = bindings.begin();
                     seqIter != bindings.end(); ++seqIter)
             {
                 int relativeExpiration = (*seqIter)->expiration - time(NULL);
 
-                BindingHolder *holder(new BindingHolder(
+                BindingWrapper *wrapper(new BindingWrapper(
                             relativeExpiration,
                             *seqIter,
                             regModule->getRegistrar(),
                             mManager->getEndpoint(),
                             dictIter->first));
 
-                holderSeq.push_back(holder);
+                wrapperSeq.push_back(wrapper);
             }
-            regModule->getRegistrar()->updateBindings(dictIter->first, emptySeq, holderSeq);
+            regModule->getRegistrar()->updateBindings(dictIter->first, emptySeq, wrapperSeq);
         }
     }
 
@@ -123,29 +123,29 @@ public:
 
     void setNewRegistrationState(const PJSipRegistrarModulePtr& regModule, const SipRegistrarStateItemPtr& regItem)
     {
-        //For new registrations, we need to create a sequence of BindingHolders and call the registrar's
+        //For new registrations, we need to create a sequence of BindingWrappers and call the registrar's
         //updateBindings() function.
         for (BindingDict::iterator dictIter = regItem->bindings.begin();
                 dictIter != regItem->bindings.end(); ++dictIter)
         {
             BindingSeq bindings = dictIter->second;
-            BindingHolderSeq emptySeq;
-            BindingHolderSeq holderSeq;
+            BindingWrapperSeq emptySeq;
+            BindingWrapperSeq wrapperSeq;
             for (BindingSeq::iterator seqIter = bindings.begin();
                     seqIter != bindings.end(); ++seqIter)
             {
                 int relativeExpiration = (*seqIter)->expiration - time(NULL);
 
-                BindingHolder *holder(new BindingHolder(
+                BindingWrapper *wrapper(new BindingWrapper(
                             relativeExpiration,
                             *seqIter,
                             regModule->getRegistrar(),
                             mManager->getEndpoint(),
                             dictIter->first));
 
-                holderSeq.push_back(holder);
+                wrapperSeq.push_back(wrapper);
             }
-            regModule->getRegistrar()->updateBindings(dictIter->first, holderSeq, emptySeq);
+            regModule->getRegistrar()->updateBindings(dictIter->first, wrapperSeq, emptySeq);
         }
     }
 
@@ -153,9 +153,9 @@ public:
     {
         BindingFinder(const BindingPtr& binding)
             : mBinding(binding) { }
-        bool operator()(BindingHolder *holder)
+        bool operator()(BindingWrapper *wrapper)
         {
-            return *holder == mBinding;
+            return *wrapper == mBinding;
         }
         BindingPtr mBinding;
     };
@@ -165,11 +165,11 @@ public:
         for (BindingDict::iterator dictIter = regItem->bindings.begin();
                 dictIter != regItem->bindings.end(); ++dictIter)
         {
-            BindingHolderSeq& bindings = regModule->getRegistrar()->getAORBindingHolders(dictIter->first);
+            BindingWrapperSeq& bindings = regModule->getRegistrar()->getAORBindingWrappers(dictIter->first);
             for (BindingSeq::iterator seqIter = dictIter->second.begin();
                     seqIter != dictIter->second.end(); ++seqIter)
             {
-                BindingHolderSeq::iterator bindingToUpdate = 
+                BindingWrapperSeq::iterator bindingToUpdate = 
                     std::find_if(bindings.begin(), bindings.end(), BindingFinder(*seqIter));
                 (*bindingToUpdate)->updateBinding((*seqIter)->callid, (*seqIter)->cseq, (*seqIter)->expiration - time(NULL));
             }

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list