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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Sep 12 15:08:42 CDT 2011


branch "client-registration" has been updated
       via  7cf2d5832e61940212efbd808a54a1135ace49a6 (commit)
       via  d199b12db578f5ac2c51839f838d63f31cc682b7 (commit)
       via  132df0b6a986086f4ec94858e1d31317e90ba0da (commit)
       via  5b568aeb3078b9f94a36a5672f793664414ee3b1 (commit)
       via  626702b93dea964bdb35251fa6b8123c5236cd16 (commit)
       via  780b003c24252625f2a835cb493416a4e515bc42 (commit)
      from  6e3818ecf1213e1918454a129d1b49adcab0fc29 (commit)

Summary of changes:
 src/SipClientRegistration.cpp |   74 ++++++++++++--------
 src/SipClientRegistration.h   |  151 ++++++++++++++++++++++++++++++++++++++++-
 src/SipConfiguration.cpp      |   13 ++--
 src/SipEndpoint.cpp           |    2 +-
 4 files changed, 201 insertions(+), 39 deletions(-)


- Log -----------------------------------------------------------------
commit 7cf2d5832e61940212efbd808a54a1135ace49a6
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Sep 12 15:07:44 2011 -0500

    Adjust for configuration issue that had not been experienced previously.
    
    If the AOR changes in a registration group, we have to unregister and then
    reregister with the new AOR.
    
    This is pretty much done at this point, but I'm now seeing a NULL handle
    exception in the configurator that I'd like to track down if you please.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 76daac0..ba624f7 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -165,12 +165,28 @@ SipRegistrationClient::SipRegistrationClient(
         const Ice::ObjectAdapterPtr& backplaneAdapter,
         const ReplicaPrx& replica)
     : mEndpointName(sipEndpoint->getName()),
+    mAOR(confItem->aor),
     mManager(manager),
     mTimer(new IceUtil::Timer()),
     mReplicationContext(replicationContext),
     mBackplaneAdapter(backplaneAdapter),
     mReplica(replica)
 {
+    createPJSIPRegistration(confItem, pjEndpoint, sipEndpoint);
+}
+
+void SipRegistrationClient::activate()
+{
+    ReplicaListenerPtr listener(new ClientRegistrationReplicaListener(this));
+    mReplicaListenerProxy = ReplicaListenerPrx::uncheckedCast(mBackplaneAdapter->addWithUUID(listener));
+    mReplica->addListener(mReplicaListenerProxy);
+}
+
+void SipRegistrationClient::createPJSIPRegistration(
+        const SipClientRegistrationItemPtr& confItem,
+        pjsip_endpoint *pjEndpoint,
+        const SipEndpointPtr& sipEndpoint)
+{
     pjsip_regc_create(pjEndpoint, this, regCallback, &mReg);
 
     std::vector<pj_str_t> pjContacts;
@@ -204,17 +220,19 @@ SipRegistrationClient::SipRegistrationClient(
     setContacts(confItem->contacts);
 }
 
-void SipRegistrationClient::activate()
-{
-    ReplicaListenerPtr listener(new ClientRegistrationReplicaListener(this));
-    mReplicaListenerProxy = ReplicaListenerPrx::uncheckedCast(mBackplaneAdapter->addWithUUID(listener));
-    mReplica->addListener(mReplicaListenerProxy);
-}
-
 void SipRegistrationClient::destroy()
 {
     mReplica->removeListener(mReplicaListenerProxy);
     mBackplaneAdapter->remove(mReplicaListenerProxy->ice_getIdentity());
+    destroyPJSIPRegistration();
+}
+
+void SipRegistrationClient::destroyPJSIPRegistration()
+{
+    pjsip_tx_data *tdata;
+    pjsip_regc_unregister(mReg, &tdata);
+    pjsip_regc_send(mReg, tdata);
+
     pjsip_regc_destroy(mReg);
 }
 
@@ -229,6 +247,26 @@ void SipRegistrationClient::setContacts(const ContactInfoSeq& contacts)
     sendRegister();
 }
 
+void SipRegistrationClient::updateRegistration(
+        const SipClientRegistrationItemPtr& confItem,
+        pjsip_endpoint *pjEndpoint,
+        const SipEndpointPtr& sipEndpoint)
+{
+    if (confItem->aor != mAOR)
+    {
+        //If the AOR is new, then we have to kill off the
+        //current registration and create a new one.
+        destroyPJSIPRegistration();
+        createPJSIPRegistration(confItem, pjEndpoint, sipEndpoint);
+    }
+    else
+    {
+        //The AOR hasn't changed, so all we must do is to update
+        //the contacts bound for this registration
+        setContacts(confItem->contacts);
+    }
+}
+
 void SipRegistrationClient::sendRegister()
 {
     //Replicas just hold onto the necessary information. They don't actually
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index df09fde..035d95c 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -123,11 +123,43 @@ public:
     void activate();
 
     /**
+     * Create the PJSIP client registration structure
+     *
+     * This will result in setContacts being called, which thus implies
+     * that a REGISTER will be sent out.
+     */
+    void createPJSIPRegistration(
+            const AsteriskSCF::Configuration::SipSessionManager::V1::SipClientRegistrationItemPtr& confItem,
+            pjsip_endpoint* pjEndpoint,
+            const SipEndpointPtr& sipEndpoint);
+
+    /**
      * Remove servants from object adapter and remove replica listeners.
      */
     void destroy();
 
     /**
+     * Kill the PJSIP registration.
+     * 
+     * This both unregisters all contacts currently bound and targets the PJSIP client
+     * registration structure for destruction.
+     */
+    void destroyPJSIPRegistration();
+
+    void updateRegistration(
+            const AsteriskSCF::Configuration::SipSessionManager::V1::SipClientRegistrationItemPtr& confItem,
+            pjsip_endpoint *pjEndpoint,
+            const SipEndpointPtr& sipEndpoint);
+
+    /**
+     * Callback from PJSIP to handle the response from a REGISTER attempt
+     *
+     * @param param Data pertaining to the REGISTER response.
+     */
+    void handleRegisterResponse(pjsip_regc_cbparam *param);
+private:
+
+    /**
      * Set the contacts to bind to the AOR for this registration.
      *
      * Calling this will result in a REGISTER being sent out. If contacts
@@ -138,13 +170,6 @@ public:
      */
     void setContacts(const AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq& contacts);
 
-    /**
-     * Callback from PJSIP to handle the response from a REGISTER attempt
-     *
-     * @param param Data pertaining to the REGISTER response.
-     */
-    void handleRegisterResponse(pjsip_regc_cbparam *param);
-private:
 
     /**
      * Send a REGISTER
@@ -177,6 +202,11 @@ private:
     const std::string mEndpointName;
 
     /**
+     * The AOR for which this client registration exists.
+     */
+    const std::string mAOR;
+
+    /**
      * The contact headers to place in REGISTER messages.
      */
     AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq mContacts;
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 4569e4f..0dc9c83 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -375,7 +375,7 @@ void SipEndpoint::updateClientRegistrations(SipClientRegistrationItemSeq& items)
         if (iter != mImplPriv->mClientRegistrations.end())
         {
             //Updating one that exists
-            iter->second->setContacts((*item)->contacts);
+            iter->second->updateRegistration(*item, mImplPriv->mManager->getEndpoint(), this);
         }
         else
         {

commit d199b12db578f5ac2c51839f838d63f31cc682b7
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sun Sep 11 14:56:24 2011 -0500

    Remove unused function and add a needed return statement.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 04b95aa..76daac0 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -77,20 +77,6 @@ struct MakeContact
     pjsip_regc *mReg;
 };
 
-/**
- * Add new items to a vector, and remove duplicates.
- * This is formulated so that if duplicates are added,
- * the newer version will replace the old version in
- * the vector
- */
-template <class T>
-void unique_add(std::vector<T>& container, const std::vector<T>& stuffToAdd)
-{
-    container.insert(container.begin(), stuffToAdd.begin(), stuffToAdd.end());
-    std::stable_sort(container.begin(), container.end());
-    container.erase(std::unique(container.begin(), container.end()), container.end());
-}
-
 } // end anonymous namespace
 
 namespace AsteriskSCF
@@ -370,6 +356,7 @@ void SipRegistrationClient::authenticate(pjsip_rx_data *rdata)
                 pjsip_regc_set_credentials(mReg, creds.size(), &creds.front());
                 sendRegister();
             }
+            return;
         }
     }
 }

commit 132df0b6a986086f4ec94858e1d31317e90ba0da
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sun Sep 11 14:45:48 2011 -0500

    Add some documentation.

diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index 9a17683..df09fde 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -44,13 +44,30 @@ 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;
 };
@@ -68,6 +85,27 @@ class ClientRegistrationReplicaListener;
 class SipRegistrationClient : public IceUtil::Shared
 {
 public:
+    /**
+     * Constructor
+     *
+     * @param confItem The configuration item for the registration in question. This contains data
+     * such as the list of contacts, the AOR, and the default expiration for the registration.
+     *
+     * @param pjEndpoint The pjsip_endpoint from which REGISTERs will originate
+     *
+     * @param sipEndpoint The SIP endpoint for which this registration corresponds
+     *
+     * @param manager The registration client manager, used to get data needed for all registrations, such as
+     * authentication hooks.
+     *
+     * @param replicationContext Replication context. Used to determine whether the registration is operating
+     * in active or standby mode.
+     *
+     * @param backplaneAdapter Object adapter onto which servants are added. We use the backplane adapter because
+     * we create replica listeners, and these need to use the backplane adapter.
+     *
+     * @param replica The replica interface on which to add listeners we create.
+     */
     SipRegistrationClient(
             const AsteriskSCF::Configuration::SipSessionManager::V1::SipClientRegistrationItemPtr& confItem,
             pjsip_endpoint* pjEndpoint,
@@ -79,36 +117,117 @@ public:
 
     ~SipRegistrationClient();
 
+    /**
+     * Add servants to object adapter and create replica listeners.
+     */
     void activate();
 
+    /**
+     * Remove servants from object adapter and remove replica listeners.
+     */
     void destroy();
 
+    /**
+     * Set the contacts to bind to the AOR for this registration.
+     *
+     * Calling this will result in a REGISTER being sent out. If contacts
+     * were previously present but are no longer present in the new list,
+     * then they will automatically be unregistered.
+     *
+     * @param contacts The list of contacts to put in the outbound REGISTER.
+     */
     void setContacts(const AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq& contacts);
 
+    /**
+     * Callback from PJSIP to handle the response from a REGISTER attempt
+     *
+     * @param param Data pertaining to the REGISTER response.
+     */
     void handleRegisterResponse(pjsip_regc_cbparam *param);
 private:
+
+    /**
+     * Send a REGISTER
+     */
     void sendRegister();
 
+    /**
+     * When authenticating, get the realms from the WWW-Authenticate and Proxy-Authenticate
+     * headers.
+     *
+     * @param rdata The response data from which authentication headers are pulled.
+     */
     Ice::StringSeq getRealms(pjsip_rx_data *rdata);
 
+    /**
+     * Called when a 401/407 response is received as a response to a REGISTER.
+     *
+     * This will call out to authentication hooks in order to determine credentials
+     * to send. If credentials are provided, then we will send another REGISTER with
+     * the provided credentials.
+     *
+     * @param rdata Information pertaining to the REGISTER response.
+     */
     void authenticate(pjsip_rx_data *rdata);
 
+    /**
+     * The name of the SIP endpoint. This is kept mainly for debugging and identification
+     * purposes
+     */
     const std::string mEndpointName;
+
+    /**
+     * The contact headers to place in REGISTER messages.
+     */
     AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq mContacts;
+    
+    /**
+     * The central point from which to get information such as authentication hooks.
+     */
     SipRegistrationClientManagerPtr mManager;
+
+    /**
+     * The PJSIP client registration structure.
+     */
     pjsip_regc* mReg;
 
+    /**
+     * A timer task used when a REGISTER fails, and the response contains
+     * a Retry-After header. The task simply resends the REGISTER
+     */
     IceUtil::TimerTaskPtr mTimerTask;
+
+    /**
+     * Timer used to schedule mTimerTask
+     */
     IceUtil::TimerPtr mTimer;
 
+    /**
+     * Replication context. Used to determine active or standby status.
+     */
     SipReplicationContextPtr mReplicationContext;
 
+    /**
+     * Adapter onto which replica listener is added
+     */
     Ice::ObjectAdapterPtr mBackplaneAdapter;
 
+    /**
+     * Replica that we add our listener to
+     */
     AsteriskSCF::System::Component::V1::ReplicaPrx mReplica;
 
+    /**
+     * Replica listener. This is used to sense when the component moves
+     * from standby to active mode. When this happens, a REGISTER will be
+     * sent out.
+     */
     AsteriskSCF::System::Component::V1::ReplicaListenerPrx mReplicaListenerProxy;
 
+    /**
+     * These classes are declared friends so they will have access to
+     * sendRegister()
+     */
     friend class RescheduleRegister;
     friend class ClientRegistrationReplicaListener;
 };

commit 5b568aeb3078b9f94a36a5672f793664414ee3b1
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sun Sep 11 13:13:48 2011 -0500

    Fix a couple of logical errors in configuration
    
    * Continue instead of returning in for loop when problems occur.
    * Be sure to call updateClientRegistrations() even if the list is empty.

diff --git a/src/SipConfiguration.cpp b/src/SipConfiguration.cpp
index 440fd9f..b1c1965 100644
--- a/src/SipConfiguration.cpp
+++ b/src/SipConfiguration.cpp
@@ -430,7 +430,7 @@ public:
             if (entry == mRegistrationConfigMap.end())
             {
                 //Group doesn't exist.
-                return;
+                continue;
             }
 
             SipClientRegistrationItemPtr item = entry->second->getClientRegistrationItem();
@@ -438,15 +438,12 @@ public:
             if (item == 0)
             {
                 //Group doesn't have a configuration item.
-                return;
+                continue;
             }
 
             regItems.push_back(item);
         }
-        if (!regItems.empty())
-        {
-            mEndpoint->updateClientRegistrations(regItems);
-        }
+        mEndpoint->updateClientRegistrations(regItems);
     }
 
     void updated(const UpdateCommandList& updates)

commit 626702b93dea964bdb35251fa6b8123c5236cd16
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sun Sep 11 12:52:26 2011 -0500

    Allow post processing to run on remove operations.

diff --git a/src/SipConfiguration.cpp b/src/SipConfiguration.cpp
index 047c7f5..440fd9f 100644
--- a/src/SipConfiguration.cpp
+++ b/src/SipConfiguration.cpp
@@ -1758,10 +1758,12 @@ void ConfigurationServiceImpl::removeConfigurationItems(
     
     SipConfigurationGroupVisitorPtr v = new GroupsVisitor(this);
     
+    postProcesses.clear();
     for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
     {
 	(*group)->visit(v);
     }
+    runPostProcessing();
 }
 
 void ConfigurationServiceImpl::removeConfigurationGroups(
@@ -1818,10 +1820,12 @@ void ConfigurationServiceImpl::removeConfigurationGroups(
     
     SipConfigurationGroupVisitorPtr v = new Visitor(this);
     
+    postProcesses.clear();
     for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
     {
 	(*group)->visit(v);
     }
+    runPostProcessing();
 }
 };
 };

commit 780b003c24252625f2a835cb493416a4e515bc42
Author: Mark Michelson <mmichelson at digium.com>
Date:   Sun Sep 11 12:48:40 2011 -0500

    Switch from an "add/remove" model for contacts to a "set" method.
    
    This reflects the way PJSIP works more betterly.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index c7d7628..04b95aa 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -215,7 +215,7 @@ SipRegistrationClient::SipRegistrationClient(
             confItem->defaultExpiration
             );
 
-    addContacts(confItem->contacts);
+    setContacts(confItem->contacts);
 }
 
 void SipRegistrationClient::activate()
@@ -236,20 +236,9 @@ SipRegistrationClient::~SipRegistrationClient()
 {
 }
 
-void SipRegistrationClient::addContacts(const ContactInfoSeq& contacts)
+void SipRegistrationClient::setContacts(const ContactInfoSeq& contacts)
 {
-    unique_add(mContacts, contacts);
-
-    sendRegister();
-}
-
-void SipRegistrationClient::removeContacts(const Ice::StringSeq& contacts)
-{
-    for (Ice::StringSeq::const_iterator iter = contacts.begin();
-            iter != contacts.end(); ++iter)
-    {
-        mContacts.erase(std::find_if(mContacts.begin(), mContacts.end(), EqualContacts(*iter)));
-    }
+    mContacts = contacts;
 
     sendRegister();
 }
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index ca5581a..9a17683 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -83,9 +83,7 @@ public:
 
     void destroy();
 
-    void addContacts(const AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq& contacts);
-
-    void removeContacts(const Ice::StringSeq& contacts);
+    void setContacts(const AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq& contacts);
 
     void handleRegisterResponse(pjsip_regc_cbparam *param);
 private:
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index c995952..4569e4f 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -375,7 +375,7 @@ void SipEndpoint::updateClientRegistrations(SipClientRegistrationItemSeq& items)
         if (iter != mImplPriv->mClientRegistrations.end())
         {
             //Updating one that exists
-            iter->second->addContacts((*item)->contacts);
+            iter->second->setContacts((*item)->contacts);
         }
         else
         {

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list