[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
Thu Sep 8 19:17:13 CDT 2011


branch "client-registration" has been updated
       via  627496611f923896f9af9492d63b97c1eeb25b1d (commit)
       via  d7b7717cfd58774cb42c60875538809e6cd4d473 (commit)
       via  0fde963b9043996f95488778f12ff9c868709fbe (commit)
       via  26b319bfb38e0d0787162de8dfb1957b464fe359 (commit)
      from  7654c9134f255423b8e94e4b88accb878796e4a7 (commit)

Summary of changes:
 src/SipClientRegistration.cpp |   94 +++++++++++++++++++----------------------
 src/SipClientRegistration.h   |   17 +++----
 2 files changed, 50 insertions(+), 61 deletions(-)


- Log -----------------------------------------------------------------
commit 627496611f923896f9af9492d63b97c1eeb25b1d
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Sep 8 19:18:09 2011 -0500

    Cancel a re-register attempt if something else causes us to attempt re-registering early.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index e32a7dc..e389ff7 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -213,6 +213,17 @@ void SipRegistrationClient::removeContacts(const Ice::StringSeq& contacts)
 
 void SipRegistrationClient::sendRegister()
 {
+
+    //There's a decent chance that there's no actual
+    //scheduled task, but in case there is, we need
+    //to cancel that dude.
+    //
+    //Note that the Ice manual states that attempting to cancel
+    //a one-time task results in nothing occurring. However,
+    //I ran some independent tests and found that at least in
+    //Ice 3.4.2, you can cancel a one-time task succesfully.
+    mTimer->cancel(mTimerTask);
+
     std::vector<pj_str_t> contacts;
     std::transform(mContacts.begin(), mContacts.end(), std::back_inserter(contacts), MakeContact(mReg));
 
@@ -248,7 +259,11 @@ void SipRegistrationClient::handleRegisterResponse(pjsip_regc_cbparam *param)
         if (retryAfter)
         {
             lg(Notice) << "REGISTER attempt failure for endpoint " << mEndpointName << " contains Retry-After of " << retryAfter->ivalue;
-            mTimer->schedule(new RescheduleRegister(this), IceUtil::Time::seconds(retryAfter->ivalue));
+            if (!mTimerTask)
+            {
+                mTimerTask = new RescheduleRegister(this);
+            }
+            mTimer->schedule(mTimerTask, IceUtil::Time::seconds(retryAfter->ivalue));
         }
         else
         {
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index 3b4fa65..2941b36 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -92,6 +92,7 @@ private:
     SipRegistrationClientManagerPtr mManager;
     pjsip_regc* mReg;
 
+    IceUtil::TimerTaskPtr mTimerTask;
     IceUtil::TimerPtr mTimer;
 
     friend class RescheduleRegister;

commit d7b7717cfd58774cb42c60875538809e6cd4d473
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Sep 8 17:40:22 2011 -0500

    Honor Retry-After headers in registration failures.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 40089da..e32a7dc 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -31,7 +31,6 @@ void regCallback(struct pjsip_regc_cbparam *param)
 {
     //I'd much rather be able to control things within the confines of my
     //class thank you very much.
-
     SipRegistrationClient *client = static_cast<SipRegistrationClient*>(param->token);
     client->handleRegisterResponse(param);
 }
@@ -100,6 +99,22 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
+class RescheduleRegister : public IceUtil::TimerTask
+{
+public:
+    RescheduleRegister(const SipRegistrationClientPtr& client)
+        : mClient(client) { }
+
+    void runTimerTask()
+    {
+        mClient->sendRegister();
+    }
+private:
+    SipRegistrationClientPtr mClient;
+};
+
+typedef IceUtil::Handle<RescheduleRegister> RescheduleRegisterPtr;
+
 using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
 
 SipRegistrationClientManager::SipRegistrationClientManager()
@@ -138,7 +153,7 @@ SipRegistrationClient::SipRegistrationClient(
         pjsip_endpoint* pjEndpoint,
         const SipEndpointPtr& sipEndpoint,
         const SipRegistrationClientManagerPtr manager)
-    : mEndpointName(sipEndpoint->getName()), mManager(manager)
+    : mEndpointName(sipEndpoint->getName()), mManager(manager), mTimer(new IceUtil::Timer())
 {
     pjsip_regc_create(pjEndpoint, this, regCallback, &mReg);
 
@@ -226,8 +241,19 @@ void SipRegistrationClient::handleRegisterResponse(pjsip_regc_cbparam *param)
         break;
     }
     default:
-        //The rest of these are failure cases. It may be possible to look
-        //at Retry-After headers.
+        //The rest of these are failure cases.
+        pjsip_retry_after_hdr *retryAfter =
+            (pjsip_retry_after_hdr *) pjsip_msg_find_hdr(
+                    param->rdata->msg_info.msg, PJSIP_H_RETRY_AFTER, NULL);
+        if (retryAfter)
+        {
+            lg(Notice) << "REGISTER attempt failure for endpoint " << mEndpointName << " contains Retry-After of " << retryAfter->ivalue;
+            mTimer->schedule(new RescheduleRegister(this), IceUtil::Time::seconds(retryAfter->ivalue));
+        }
+        else
+        {
+            lg(Error) << "REGISTER attempt failure for endpoint " << mEndpointName << " and no Retry-After. Reconfigure endpoint to retry.";
+        }
         break;
     }
 }
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index dffe50f..3b4fa65 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -57,6 +57,8 @@ private:
 
 typedef IceUtil::Handle<SipRegistrationClientManager> SipRegistrationClientManagerPtr;
 
+class RescheduleRegister;
+
 /**
  * One of these exists per endpoint.
  * This takes care of sending REGISTER
@@ -89,6 +91,10 @@ private:
     AsteriskSCF::Configuration::SipSessionManager::V1::ContactInfoSeq mContacts;
     SipRegistrationClientManagerPtr mManager;
     pjsip_regc* mReg;
+
+    IceUtil::TimerPtr mTimer;
+
+    friend class RescheduleRegister;
 };
 
 typedef IceUtil::Handle<SipRegistrationClient> SipRegistrationClientPtr;

commit 0fde963b9043996f95488778f12ff9c868709fbe
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Sep 8 16:54:09 2011 -0500

    Clarify some comments for accuracy's sake.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 2eb5f4f..40089da 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -213,7 +213,7 @@ void SipRegistrationClient::handleRegisterResponse(pjsip_regc_cbparam *param)
     switch (param->code)
     {
     case 100:
-        //Nobody cares
+        //Nobody cares!
         break;
     case 200:
         //This is a success!
@@ -227,8 +227,7 @@ void SipRegistrationClient::handleRegisterResponse(pjsip_regc_cbparam *param)
     }
     default:
         //The rest of these are failure cases. It may be possible to look
-        //at Retry-After headers, and on a 423, it may be possible to try again
-        //with modified expirations.
+        //at Retry-After headers.
         break;
     }
 }
@@ -259,7 +258,7 @@ Ice::StringSeq SipRegistrationClient::getRealms(pjsip_rx_data *rdata)
 
 //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 not REGISTER-specific, in
+//responses for any type of request. This is mostly not REGISTER-specific, in
 //other words.
 void SipRegistrationClient::authenticate(pjsip_rx_data *rdata)
 {

commit 26b319bfb38e0d0787162de8dfb1957b464fe359
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Sep 8 16:28:17 2011 -0500

    Remove the addition and retrieval of Allow and Supported from SipRegistrationClientManager.
    
    This is for two simple reasons:
    1) PJSIP already adds an Allow header for us.
    2) Supported options would belong better in the specific method being used or in an OPTIONS response.

diff --git a/src/SipClientRegistration.cpp b/src/SipClientRegistration.cpp
index 47c7f27..2eb5f4f 100644
--- a/src/SipClientRegistration.cpp
+++ b/src/SipClientRegistration.cpp
@@ -106,30 +106,6 @@ SipRegistrationClientManager::SipRegistrationClientManager()
 {
 }
 
-void SipRegistrationClientManager::addAllow(const Ice::StringSeq& allows)
-{
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    unique_add(mAllow, allows);
-}
-
-Ice::StringSeq SipRegistrationClientManager::getAllow()
-{
-    boost::shared_lock<boost::shared_mutex> lock(mLock);
-    return mAllow;
-}
-
-void SipRegistrationClientManager::addSupported(const Ice::StringSeq& supporteds)
-{
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    unique_add(mSupported, supporteds);
-}
-
-Ice::StringSeq SipRegistrationClientManager::getSupported()
-{
-    boost::shared_lock<boost::shared_mutex> lock(mLock);
-    return mSupported;
-}
-
 void SipRegistrationClientManager::addAuthHook(const AuthHookPrx& hook)
 {
     boost::unique_lock<boost::shared_mutex> lock(mLock);
@@ -222,30 +198,6 @@ void SipRegistrationClient::removeContacts(const Ice::StringSeq& contacts)
 
 void SipRegistrationClient::sendRegister()
 {
-    //The idea here is to send a REGISTER with all the info we know.
-    //
-    //What we do is create a contact array that pjsip can handle. PJSIP
-    //expects the contact URIs to just be strings. It will do the parsing
-    //for us.
-    //
-    //So what we need to do is to ask the SipRegistrationClientManager
-    //for what methods are allowed. We will add an Allow header with these
-    //methods.
-    //
-    //Then we need to ask the SipRegistrationClientManager for what stuff
-    //is supported and add that as a Supported: header.
-    //
-    //Then we can simply call pjsip_regc_update_contact, then pjsip_regc_register,
-    //and then pjsip_regc_send. Simple-dimple.
-
-    Ice::StringSeq allow = mManager->getAllow();
-    Ice::StringSeq supported = mManager->getSupported();
-
-    //For now don't worry about this stuff. We can add these headers in once
-    //we have registration messages being sent out properly.
-    (void) allow;
-    (void) supported;
-
     std::vector<pj_str_t> contacts;
     std::transform(mContacts.begin(), mContacts.end(), std::back_inserter(contacts), MakeContact(mReg));
 
diff --git a/src/SipClientRegistration.h b/src/SipClientRegistration.h
index e72e15e..dffe50f 100644
--- a/src/SipClientRegistration.h
+++ b/src/SipClientRegistration.h
@@ -44,14 +44,6 @@ class SipRegistrationClientManager : public IceUtil::Shared
 public:
     SipRegistrationClientManager();
 
-    void addAllow(const Ice::StringSeq& allows);
-
-    Ice::StringSeq getAllow();
-
-    void addSupported(const Ice::StringSeq& supporteds);
-
-    Ice::StringSeq getSupported();
-
     AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookSeq getAuthHooks();
 
     void addAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx& hook);
@@ -59,8 +51,6 @@ public:
     void clearAuthHooks();
     
 private:
-    Ice::StringSeq mAllow;
-    Ice::StringSeq mSupported;
     AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookSeq mAuthHooks;
     boost::shared_mutex mLock;
 };

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list