[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "session_cookies" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Mar 21 14:55:12 CDT 2011


branch "session_cookies" has been created
        at  928dba7dd84db90557a2259854d6dcc3ece04db0 (commit)

- Log -----------------------------------------------------------------
commit 928dba7dd84db90557a2259854d6dcc3ece04db0
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Mar 21 15:20:42 2011 -0300

    Add session cookie implementation complete with replication.

diff --git a/local-slice/SipStateReplicationIf.ice b/local-slice/SipStateReplicationIf.ice
index 80d9fae..e778855 100644
--- a/local-slice/SipStateReplicationIf.ice
+++ b/local-slice/SipStateReplicationIf.ice
@@ -151,6 +151,7 @@ module V1
       AsteriskSCF::Media::V1::Session *mMediaSession;
       SessionListenerSeq mListeners;
       AsteriskSCF::SessionCommunications::V1::Bridge *mBridge;
+      AsteriskSCF::SessionCommunications::V1::SessionCookieDict mCookies;
    };
 
 }; //module V1
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 69dd032..03269c3 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -215,6 +215,7 @@ void PJSipSessionModInfo::updateSessionState(pjsip_inv_session *inv_session)
         {
             mSessionState->mBridge = 0;
         }
+	mSessionState->mCookies = mSession->getAllCookies();
     }
 
     //Now we get stuff from the inv_session itself.
@@ -783,7 +784,6 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
     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();
-    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
     //Commented because they are currently unused. They
     //will be once the individual cases are mapped out.
     //pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
@@ -815,7 +815,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
                 ListenerCallbackPtr cb(new ListenerCallback(RingingCallbackName));
                 Callback_SessionListener_ringingPtr ringingCB =
                     newCallback_SessionListener_ringing(cb, &ListenerCallback::failure);
-                (*listener)->begin_ringing(session->getSessionProxy(), cookies, ringingCB);
+                (*listener)->begin_ringing(session->getSessionProxy(), session->getCookies(), ringingCB);
             }
             catch (const Ice::Exception &ex)
             {
@@ -838,7 +838,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
                 ListenerCallbackPtr cb(new ListenerCallback(ProgressingCallbackName));
                 Callback_SessionListener_progressingPtr progressingCB =
                     newCallback_SessionListener_progressing(cb, &ListenerCallback::failure);
-                (*listener)->begin_progressing(session->getSessionProxy(), cookies, response, progressingCB);
+                (*listener)->begin_progressing(session->getSessionProxy(), session->getCookies(), response, progressingCB);
             }
             catch (const Ice::Exception &ex)
             {
@@ -861,7 +861,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
                     ListenerCallbackPtr cb(new ListenerCallback(ConnectedCallbackName));
                     Callback_SessionListener_connectedPtr connectedCB =
                         newCallback_SessionListener_connected(cb, &ListenerCallback::failure);
-                    (*listener)->begin_connected(session->getSessionProxy(), cookies, connectedCB);
+                    (*listener)->begin_connected(session->getSessionProxy(), session->getCookies(), connectedCB);
                 }
                 catch (const Ice::Exception &ex)
                 {
@@ -874,8 +874,6 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
 
 void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *event)
 {
-    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
-
     if ((inv->state == PJSIP_INV_STATE_EARLY || inv->state == PJSIP_INV_STATE_CONNECTING) &&
         event->type == PJSIP_EVENT_TSX_STATE &&
         inv->role == PJSIP_ROLE_UAC)
@@ -913,7 +911,7 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
         {
             try
             {
-                (*listener)->stopped(session->getSessionProxy(), cookies, response);
+                (*listener)->stopped(session->getSessionProxy(), session->getCookies(), response);
             }
             catch (const Ice::Exception &ex)
             {
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 1879979..055eb41 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -153,6 +153,11 @@ public:
     AsteriskSCF::SessionCommunications::V1::BridgePrx mBridge;
 
     /**
+     * Cookies present on the session.
+     */
+    AsteriskSCF::SessionCommunications::V1::SessionCookieDict mSessionCookies;
+
+    /**
      * The PJSIP manager
      */
     PJSipManager *mManager;
@@ -534,29 +539,114 @@ void SipSession::unhold(const Ice::Current&)
  * An implementation of the setCookies method as defined in SessionCommunications.ice which sets cookies
  * on the session.
  */
-void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&)
+void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies, const Ice::Current&)
 {
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+    for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = cookies.begin();
+         i != cookies.end();
+         ++i)
+    {
+        mImplPriv->mSessionCookies.erase((*i)->ice_id());
+	mImplPriv->mSessionCookies.insert(make_pair((*i)->ice_id(), (*i)));
+    }
+
+    if (mImplPriv->mInviteSession)
+    {
+        PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(mImplPriv->mInviteSession->mod_data[mImplPriv->mManager->getSessionModule()->getModule().id]);
+        lock.unlock();
+        session_mod_info->updateSessionState(mImplPriv->mInviteSession);
+        mImplPriv->mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
+    }
+}
+
+/**
+ * Internal function to set the cookies (used in replication).
+ */
+void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookieDict& cookies)
+{
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    mImplPriv->mSessionCookies = cookies;
 }
 
 /**
  * An implementation of the removeCookies method as defined in SessionCommunications.ice which removes specific
  * cookies from the session.
  */
-void SipSession::removeCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&)
+void SipSession::removeCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookieTypes, const Ice::Current&)
 {
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+    for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = cookieTypes.begin();
+         i != cookieTypes.end();
+         ++i)
+    {
+	mImplPriv->mSessionCookies.erase((*i)->ice_id());
+    }
+
+    if (mImplPriv->mInviteSession)
+    {
+        PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(mImplPriv->mInviteSession->mod_data[mImplPriv->mManager->getSessionModule()->getModule().id]);
+        lock.unlock();
+        session_mod_info->updateSessionState(mImplPriv->mInviteSession);
+        mImplPriv->mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
+    }
 }
 
 /**
  * An implementation of the getCookies method as defined in SessionCommunications.ice which gets specific cookies
  * from the session.
  */
-AsteriskSCF::SessionCommunications::V1::SessionCookies SipSession::getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&)
+AsteriskSCF::SessionCommunications::V1::SessionCookies SipSession::getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookieTypes, const Ice::Current&)
 {
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
     AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+
+    for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = cookieTypes.begin();
+	 i != cookieTypes.end();
+	 ++i)
+    {
+	AsteriskSCF::SessionCommunications::V1::SessionCookieDict::const_iterator cookie = mImplPriv->mSessionCookies.find((*i)->ice_id());
+
+	if (cookie == mImplPriv->mSessionCookies.end())
+	{
+	    continue;
+	}
+
+	cookies.push_back(cookie->second);
+    }
+
     return cookies;
 }
 
 /**
+ * Internal function which returns all cookies on the session.
+ */
+AsteriskSCF::SessionCommunications::V1::SessionCookies SipSession::getCookies()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+
+    for (AsteriskSCF::SessionCommunications::V1::SessionCookieDict::const_iterator i = mImplPriv->mSessionCookies.begin();
+         i != mImplPriv->mSessionCookies.end();
+         ++i)
+    {
+        cookies.push_back(i->second);
+    }
+
+    return cookies;
+}
+
+/**
+ * Internal function which returns all cookies on the session.
+ */
+AsteriskSCF::SessionCommunications::V1::SessionCookieDict SipSession::getAllCookies()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    return mImplPriv->mSessionCookies;
+}
+
+/**
  * Internal function called to destroy an endpoint. This is controlled by signaling.
  */
 void SipSession::destroy()
diff --git a/src/SipSession.h b/src/SipSession.h
index 16b4431..7848799 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -93,8 +93,11 @@ public:
     void stop(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&);
     void unhold(const Ice::Current&);
     void setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
+    void setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookieDict&);
     void removeCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
     AsteriskSCF::SessionCommunications::V1::SessionCookies getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
+    AsteriskSCF::SessionCommunications::V1::SessionCookies getCookies();
+    AsteriskSCF::SessionCommunications::V1::SessionCookieDict getAllCookies();
 
     /**
      * Implementation specific functions.
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 9f1f3db..f2ac013 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -109,6 +109,7 @@ public:
 
                 localitem->getSession()->setListeners(session->mListeners);
                 localitem->getSession()->setBridge(session->mBridge);
+		localitem->getSession()->setCookies(session->mCookies);
             }
             else if ((dialog = SipDialogStateItemPtr::dynamicCast((*item))))
             {

commit 0fa9381647fd4ee71a8bdef72493ccc2b3cdd564
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Mar 21 12:17:53 2011 -0300

    Add bits for session cookies.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 3080204..69dd032 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -783,6 +783,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
     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();
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
     //Commented because they are currently unused. They
     //will be once the individual cases are mapped out.
     //pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
@@ -814,7 +815,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
                 ListenerCallbackPtr cb(new ListenerCallback(RingingCallbackName));
                 Callback_SessionListener_ringingPtr ringingCB =
                     newCallback_SessionListener_ringing(cb, &ListenerCallback::failure);
-                (*listener)->begin_ringing(session->getSessionProxy(), ringingCB);
+                (*listener)->begin_ringing(session->getSessionProxy(), cookies, ringingCB);
             }
             catch (const Ice::Exception &ex)
             {
@@ -837,7 +838,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
                 ListenerCallbackPtr cb(new ListenerCallback(ProgressingCallbackName));
                 Callback_SessionListener_progressingPtr progressingCB =
                     newCallback_SessionListener_progressing(cb, &ListenerCallback::failure);
-                (*listener)->begin_progressing(session->getSessionProxy(), response, progressingCB);
+                (*listener)->begin_progressing(session->getSessionProxy(), cookies, response, progressingCB);
             }
             catch (const Ice::Exception &ex)
             {
@@ -860,7 +861,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
                     ListenerCallbackPtr cb(new ListenerCallback(ConnectedCallbackName));
                     Callback_SessionListener_connectedPtr connectedCB =
                         newCallback_SessionListener_connected(cb, &ListenerCallback::failure);
-                    (*listener)->begin_connected(session->getSessionProxy(), connectedCB);
+                    (*listener)->begin_connected(session->getSessionProxy(), cookies, connectedCB);
                 }
                 catch (const Ice::Exception &ex)
                 {
@@ -873,6 +874,8 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
 
 void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *event)
 {
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+
     if ((inv->state == PJSIP_INV_STATE_EARLY || inv->state == PJSIP_INV_STATE_CONNECTING) &&
         event->type == PJSIP_EVENT_TSX_STATE &&
         inv->role == PJSIP_ROLE_UAC)
@@ -910,7 +913,7 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
         {
             try
             {
-                (*listener)->stopped(session->getSessionProxy(), response);
+                (*listener)->stopped(session->getSessionProxy(), cookies, response);
             }
             catch (const Ice::Exception &ex)
             {
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 0c6dd3e..1879979 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -531,6 +531,32 @@ void SipSession::unhold(const Ice::Current&)
 }
 
 /**
+ * An implementation of the setCookies method as defined in SessionCommunications.ice which sets cookies
+ * on the session.
+ */
+void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&)
+{
+}
+
+/**
+ * An implementation of the removeCookies method as defined in SessionCommunications.ice which removes specific
+ * cookies from the session.
+ */
+void SipSession::removeCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&)
+{
+}
+
+/**
+ * An implementation of the getCookies method as defined in SessionCommunications.ice which gets specific cookies
+ * from the session.
+ */
+AsteriskSCF::SessionCommunications::V1::SessionCookies SipSession::getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&)
+{
+    AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+    return cookies;
+}
+
+/**
  * Internal function called to destroy an endpoint. This is controlled by signaling.
  */
 void SipSession::destroy()
diff --git a/src/SipSession.h b/src/SipSession.h
index 105af5c..16b4431 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -92,6 +92,9 @@ public:
     void start(const Ice::Current&);
     void stop(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&);
     void unhold(const Ice::Current&);
+    void setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
+    void removeCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
+    AsteriskSCF::SessionCommunications::V1::SessionCookies getCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies&, const Ice::Current&);
 
     /**
      * Implementation specific functions.

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list