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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Aug 24 09:50:58 CDT 2011


branch "sessionparty2" has been created
        at  e0cbf32d3bbbc169cfa293bf23e8f9bfc0773c94 (commit)

- Log -----------------------------------------------------------------
commit e0cbf32d3bbbc169cfa293bf23e8f9bfc0773c94
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Aug 18 19:43:40 2011 -0500

    Session support for Party Identification.

diff --git a/config/Sip.config b/config/Sip.config
index ac8e349..6843989 100644
--- a/config/Sip.config
+++ b/config/Sip.config
@@ -19,6 +19,16 @@ type=transport-udp
 host=::1
 port=5061
 
+[bob-bar-office]
+type=identity
+name='robert bar (office)'
+number=100
+ 
+[bob-bar-cell]
+type=identity
+name='robert bar (cell)'
+number=200
+
 # Example of a TCP transport binding to IPv4 localhost
 [localhost-tcp]
 # A type of transport-tcp specifies transport using TCP
@@ -82,3 +92,12 @@ rtpoveripv6=no
 # Allowable media formats for the endpoint. Each format is separated using , and follows the format
 # <name>/<sample rate>@<frame size>;<format specific parameters>
 formats=ulaw/8000,alaw/8000
+#
+# Simple fields for a single identity record
+name='robert foo bar'
+number=123
+#
+# Or, a reference to a list of individual identity items
+ids=bob-bar-office,bob-bar-cell
+
+
diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index bafe933..f7d21fe 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -22,7 +22,8 @@
 import Ice, Configurator, sys, os, traceback
 
 # Load our component specific configuration definitions
-Ice.loadSlice("--underscore -I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSliceDir() + " --all ../slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice")
+Ice.loadSlice('-I. -IC:/Ice-3.4.1/slice -I../slice/slice -I../sip/slice --all ../sip/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice')
+
 import AsteriskSCF.Configuration.SipSessionManager.V1
 
 
@@ -102,6 +103,25 @@ class SipSectionVisitors(Configurator.SectionVisitors):
 
         self.groups.append(group)
 
+    def visit_identity(self, config, section):
+        group = AsteriskSCF.Configuration.SipSessionManager.V1.IdentityGroup()
+        group.name = section
+        group.configurationItems = { }
+
+        mapper = Configurator.OptionMapper()
+
+        item =  AsteriskSCF.Configuration.SipSessionManager.V1.IdentityItem()
+	#      map(option, object, item, item_name, method, default)
+        mapper.map('name', item, 'name', 'id', config.get, None)
+        mapper.map('number', item, 'number', 'id', config.get, None)
+
+        for option in config.options(section):
+            mapper.execute(group, section, option)
+
+        mapper.finish(group)
+
+        self.groups.append(group)
+
     def visit_endpoint(self, config, section):
         group = AsteriskSCF.Configuration.SipSessionManager.V1.SipEndpointGroup()
         group.name = section
@@ -111,6 +131,19 @@ class SipSectionVisitors(Configurator.SectionVisitors):
 
         mapper.map('routing', AsteriskSCF.Configuration.SipSessionManager.V1.SipRoutingItem(), 'routingServiceName', 'routingService', config.get, None)
 
+	item = AsteriskSCF.Configuration.SipSessionManager.V1.IdentityItem()
+	mapper.map('name', item, 'name', 'identity', config.get, None)
+        mapper.map('number', item, 'number', 'identity', config.get, None)
+      
+
+        # Alternate form of setting id is a list of references to IdentityGroup objects.
+        ids = config.get(section, 'ids')
+        idList = ids.split(',')
+        for id in idList:
+            item = AsteriskSCF.Configuration.SipSessionManager.V1.IdentityGroupRef()
+            item.identityGroupName = id
+            group.configurationItems[id] = item
+
         item = AsteriskSCF.Configuration.SipSessionManager.V1.SipSourceTransportAddressItem()
         mapper.map('sourcehost', item, 'host', 'sourceaddress', config.get, None)
         mapper.map('sourceport', item, 'port', 'sourceaddress', config.getint, 5060)
@@ -254,9 +287,11 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             self.visit_transport_tls(config, section)
         elif config.get(section, 'type') == 'endpoint':
             self.visit_endpoint(config, section)
+        elif config.get(section, 'type') == 'identity':
+            self.visit_identity(config, section)
 
 # In order to do service locator based lookup we need to pass in a params object
-serviceLocatorParams = AsteriskSCF.Configuration.SipSessionManager.V1.SipConfigurationParams()
+serviceLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
 serviceLocatorParams.category = AsteriskSCF.Configuration.SipSessionManager.V1.ConfigurationDiscoveryCategory
 serviceLocatorParams.service = 'default' 
 
diff --git a/config/test_sip.conf b/config/test_sip.conf
index 3b5b45c..ad26db5 100644
--- a/config/test_sip.conf
+++ b/config/test_sip.conf
@@ -39,7 +39,6 @@ Sip.StateReplicatorListener=no
 # Endpoints that we know about
 Sip.Endpoints=cisco 18005558355
 
-Sip.Standalone=true
 
 # This is Josh's phone
 Sip.Endpoint.cisco.Session.CallDirection=Both
@@ -50,3 +49,6 @@ Sip.Endpoint.18005558355.Transport.Address=172.16.1.10
 
 IceBox.InheritProperties = 1
 IceBox.Service.SipSessionManager=SipSessionManager:create
+
+SipSessionManager.Standalone=true
+
diff --git a/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice b/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
index 6bddae5..119a010 100644
--- a/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
+++ b/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
@@ -19,6 +19,7 @@
 #include <Ice/BuiltinSequences.ice>
 #include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
 #include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+#include <AsteriskSCF/SessionCommunications/PartyIdentificationIf.ice>
 
 module AsteriskSCF
 {
@@ -270,6 +271,30 @@ class SRTPCryptoItem extends SipConfigurationItem
     SRTPCryptoKeySeq cryptoKeys;
 };
 
+class IdentityItem extends SipConfigurationItem
+{
+    string name;
+    string number;
+};
+
+class IdentityGroup extends SipConfigurationGroup
+{
+    /** 
+     * Identifier for this IdentityGroup. IdentityGroup
+     * allows identities to be defined outside the body of 
+     * an endpoint, and refrenced by name from the endpoint. 
+     */ 
+    string name;
+};
+
+class IdentityGroupRef extends SipConfigurationItem
+{
+    /**
+     * Name of an identity group. 
+     */
+     string identityGroupName;
+};
+
 /**
  * Routing service configuration item
  */
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 9f8de91..2d21349 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -480,6 +480,10 @@ protected:
             {
                 // If this is not an attended transfer we can just route the session as normally
                 std::string operationId = ::IceUtil::generateUUID();
+
+                // Update the Party Id information on the session.
+                mSession->setSelfAsCaller();
+
                 SuspendableWorkListenerPtr listener = 0;
                 SipAMICallbackPtr cb(new SipAMICallback(listener, mSession, this, false, true));
                 Ice::CallbackPtr d = Ice::newCallback(cb, &SipAMICallback::callback);
diff --git a/src/SipConfiguration.cpp b/src/SipConfiguration.cpp
index d6a342a..4874e7d 100644
--- a/src/SipConfiguration.cpp
+++ b/src/SipConfiguration.cpp
@@ -40,6 +40,7 @@
 
 using namespace AsteriskSCF::System::Configuration::V1;
 using namespace AsteriskSCF::Configuration::SipSessionManager::V1;
+using namespace AsteriskSCF::SessionCommunications::PartyIdentification::V1;
 using namespace AsteriskSCF::Core::Routing::V1;
 using namespace std;
 
@@ -137,6 +138,101 @@ static void performSerialCheck(const ConfigurationItemDict& changedItems, const
 typedef boost::function<void()> UpdateCommand;
 typedef vector<UpdateCommand> UpdateCommandList;
 
+class ConfigBase
+{
+public:
+    virtual ~ConfigBase() {}
+
+    virtual SipConfigurationItemVisitorPtr getVisitor() { return 0; }
+};
+typedef boost::shared_ptr<ConfigBase> ConfigBasePtr;
+
+class IdentityConfig;
+typedef boost::shared_ptr<IdentityConfig> IdentityConfigPtr;
+typedef std::map<std::string, IdentityConfigPtr> IdentityConfigMap;
+
+/**
+ * Configured Identity groups. This has to be accessible to 
+ * the EndpointConfigHelper. 
+ */
+IdentityConfigMap mIdentityConfigMap;
+
+/** 
+ * Identity groups allow identity to be defined separately from endpoints, 
+ * and for endpoints to have multiple identities. 
+ */
+class IdentityConfig : public ConfigBase, public boost::enable_shared_from_this<IdentityConfig>
+{
+    class Visitor : public SipConfigurationItemVisitor
+    {
+    public:
+        Visitor(const boost::shared_ptr<IdentityConfig>& config) :
+            mConfig(config)
+        {
+        }
+
+        void visitIdentityItem(const IdentityItemPtr& identityItem)
+        {
+            mConfig->update(identityItem);
+        }
+
+    private:
+
+        UpdateCommandList mUpdates;
+
+        boost::shared_ptr<IdentityConfig> mConfig;
+    };
+    
+public:
+    /**
+     * Constructor implementation for this
+     */
+    IdentityConfig(const IdentityGroupPtr& group) :
+        mGroup(group)
+    {
+    };
+
+    /**
+     * Destructor implementation that shuts down the transport gracefully if we go away
+     */
+    ~IdentityConfig()
+    {
+    };
+    
+    SipConfigurationItemVisitorPtr getVisitor()
+    {
+        return new Visitor(shared_from_this());
+    }
+
+    void update(const IdentityItemPtr& identityItem)
+    {
+         boost::unique_lock<boost::shared_mutex> lock(mLock);
+         mIdentityItem = identityItem;
+    }
+
+    IdentityGroupPtr getTypedGroup() const
+    {
+        return mGroup;
+    }
+
+    IdentityItemPtr getIdentityItem()
+    {
+        return mIdentityItem;
+    }
+
+private:
+    boost::shared_mutex mLock;
+    
+    IdentityItemPtr mIdentityItem;
+
+    /**
+     * Configuration group itself.
+     */
+    mutable IdentityGroupPtr mGroup;
+
+}; // class IdentityConfig
+
+
 /**
  * A helper class and visitor for propogating configuration changes to the SIPEndPoint implementation.
  **/
@@ -160,7 +256,6 @@ class EndpointConfigHelper : public boost::enable_shared_from_this<EndpointConfi
         {
             try
             {
-                //
                 // Don't forget to tell the helper that all of the updates have been performed
                 // and it can perform final processing.
                 //
@@ -229,9 +324,19 @@ class EndpointConfigHelper : public boost::enable_shared_from_this<EndpointConfi
             mUpdates.push_back(boost::bind(&EndpointConfigHelper::updateDTMF, mConfig, dtmf));
         };
 
+        void visitIdentityItem(const IdentityItemPtr& identity)
+        {
+            mUpdates.push_back(boost::bind(&EndpointConfigHelper::updateIdentity, mConfig, identity));
+        };
+
+        void visitIdentityGroupRef(const IdentityGroupRefPtr& identityGroupRef)
+        {
+            mUpdates.push_back(boost::bind(&EndpointConfigHelper::updateIdentityGroupRef, mConfig, identityGroupRef));
+        };
+
     private:
 
-        UpdateCommandList mUpdates;;
+        UpdateCommandList mUpdates;
         //
         // We keep a reference to the parent as the helper itself isn't held by the configuration
         // object or client.
@@ -283,6 +388,48 @@ public:
         mEndpoint->setCallDirection(translateCallDirection(direction->callDirection));
     }
 
+    SessionOwnerIdPtr createSessionOwnerId(string name, string number)
+    {
+        IdPtr id = new Id(new Name(name), new Number(number));
+        IdSeq ids;
+        ids.push_back(id);
+        return new SessionOwnerId(ids);
+    }
+
+    void updateSessionOwnerId(string name, string number)
+    {
+        if (mSessionOwnerId == 0)
+        {
+            mSessionOwnerId = createSessionOwnerId(name, number);
+            return;
+        }
+
+        IdPtr id = new Id(new Name(name), new Number(number));
+        mSessionOwnerId->ids.push_back(id);
+    }
+
+    void updateIdentity(const IdentityItemPtr& identity)
+    {
+         updateSessionOwnerId(identity->name, identity->number);
+    }
+
+    void updateIdentityGroupRef(const IdentityGroupRefPtr& identityGroupRef)
+    {
+        IdentityConfigMap::const_iterator mapEntry = mIdentityConfigMap.find(identityGroupRef->identityGroupName);
+        if (mapEntry == mIdentityConfigMap.end())
+        {
+            return;
+        }
+
+        if (mapEntry->second->getIdentityItem() == 0)
+        {
+            return;
+        }
+
+        updateSessionOwnerId(mapEntry->second->getIdentityItem()->name, 
+                             mapEntry->second->getIdentityItem()->number);
+    }
+
     void addFormat(const SipMediaFormatItemPtr& format)
     {
 	mEndpoint->addFormat(format->name, format->sampleRate, format->frameSize, format->formatSpecific);
@@ -356,6 +503,10 @@ public:
                 UpdateCommand command = *op;
                 command();
             }
+            if (mSessionOwnerId != 0)
+            {
+                mEndpoint->addDefaultSessionCookie(mSessionOwnerId);
+            }
             if (updateSystem)
             {
                 mFactory->generateRoutingDestinations(destinations);
@@ -373,17 +524,9 @@ private:
     boost::shared_ptr<SipEndpointFactory> mFactory;
     LocatorRegistrySmartPrx mRegistry;
     string mRoutingId;
+    SessionOwnerIdPtr mSessionOwnerId;
 };
 
-class ConfigBase
-{
-public:
-    virtual ~ConfigBase() {}
-
-    virtual SipConfigurationItemVisitorPtr getVisitor() { return 0; }
-};
-typedef boost::shared_ptr<ConfigBase> ConfigBasePtr;
-
 /**
  * The Transport specializations take care of any transport specific configuration and
  * initialization. The UDP and TCP transports are so similar that they could probably
@@ -808,6 +951,7 @@ public:
         mRoutingId(routingId), 
         mRoutingServiceLocatorRegistry(registry) 
     {
+        mIdentityConfigMap.clear();
     }
 
     /**
@@ -940,6 +1084,24 @@ public:
         }
     }
 
+    void remove(const IdentityGroupPtr& group)
+    {
+        //
+        // It's a good idea to hold a reference to this until after we release the lock on the config item. That way any
+        // code that might happen as a result of its destruction cannot come back and cause deadlocks on this object.
+        //
+        IdentityConfigPtr config;
+        {
+            boost::unique_lock<boost::shared_mutex> lock(mLock);
+            IdentityConfigMap::iterator i = mIdentityConfigMap.find(group->name);
+            if (i != mIdentityConfigMap.end())
+            {
+                config = i->second;
+                mIdentityConfigMap.erase(i);
+            }
+        }
+    }
+
     void remove(const SipSTUNTransportGroupPtr& group)
     {
         STUNTransportConfigPtr config;
@@ -1035,6 +1197,35 @@ public:
         return 0;
     }
 
+    const IdentityGroupPtr getGroupFor(const IdentityGroupPtr& group)
+    {
+        IdentityConfigMap::const_iterator i;
+        if (getItem(mIdentityConfigMap, i, group->name))
+        {
+            return i->second->getTypedGroup();
+        }
+        return 0;
+    }
+
+    const IdentityGroupPtr getGroupByName(const std::string& groupName)
+    {
+        IdentityConfigMap::const_iterator i;
+        if (getItem(mIdentityConfigMap, i, groupName))
+        {
+            return i->second->getTypedGroup();
+        }
+        return 0;
+    }
+
+    void updateReferences()
+    {
+        for(EndpointMap::const_iterator i = mEndpoints.begin();
+            i != mEndpoints.end(); ++i)
+        {
+            
+        }
+    }
+
 private:
 
     boost::shared_mutex mLock;
@@ -1043,7 +1234,7 @@ private:
      * Configured SIP domains
      */
     DomainMap mDomains;
-    
+
     /**
      * Configured UDP SIP transports
      */
@@ -1217,6 +1408,22 @@ private:
         return transport->getVisitor();
     }
 
+    SipConfigurationItemVisitorPtr updateGroup(const IdentityGroupPtr& group)
+    {
+        IdentityConfigMap::const_iterator i;
+        IdentityConfigPtr identityConfig;
+        if (!getItem(mIdentityConfigMap, i, group->name))
+        {
+            identityConfig.reset(new IdentityConfig(group));
+            mIdentityConfigMap.insert(make_pair(group->name, identityConfig));
+        }
+        else
+        {
+            identityConfig = i->second;
+        }
+        return identityConfig->getVisitor();
+    }
+
     template <class T>
     void copyTemplates(ConfigurationGroupSeq& groups, const T& items)
     {
@@ -1355,6 +1562,11 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(
             getGeneric<SipEndpointGroupPtr>(mImpl->getData(), group, mGroups);
 	};
 
+        void visitIdentityGroup(const IdentityGroupPtr& group)
+        {
+            getGeneric<IdentityGroupPtr>(mImpl->getData(), group, mGroups);
+        }
+
 	ConfigurationServiceImplPtr mImpl;
 	ConfigurationGroupSeq& mGroups;
     };
@@ -1428,6 +1640,11 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(
             genericGetAll<SipEndpointGroupPtr>(mImpl->getData(), group, mGroups);
 	};
 
+        void visitIdentityGroup(const IdentityGroupPtr& group)
+        {
+            genericGetAll<IdentityGroupPtr>(mImpl->getData(), group, mGroups);
+        }
+
 	ConfigurationServiceImplPtr mImpl;
 	ConfigurationGroupSeq& mGroups;
     };
@@ -1513,6 +1730,11 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::Confi
         {
             genericSet<SipEndpointGroupPtr>(mImpl->getData(), group);
         };
+
+        void visitIdentityGroup(const IdentityGroupPtr& group)
+        {
+            genericSet<IdentityGroupPtr>(mImpl->getData(), group);
+        }
 	
 	ConfigurationServiceImplPtr mImpl;
     };
@@ -1570,6 +1792,12 @@ void ConfigurationServiceImpl::removeConfigurationItems(
         {
             mImpl->getData()->removeFromGroup(group);
         };
+
+        void visitIdentityGroup(const IdentityGroupPtr& group)
+        {
+            mImpl->getData()->removeFromGroup(group);
+        }
+
     private:
 	ConfigurationServiceImplPtr mImpl;
     };
@@ -1626,6 +1854,11 @@ void ConfigurationServiceImpl::removeConfigurationGroups(
             mImpl->getData()->remove(group);
         };
 
+        void visitIdentityGroup(const IdentityGroupPtr& group)
+        {
+            mImpl->getData()->remove(group);
+        }
+
 	ConfigurationServiceImplPtr mImpl;
     };
     
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 87c2d35..a8a3c92 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -16,6 +16,7 @@
 #include "PJSipManager.h"
 #include "SipEndpointFactory.h"
 #include "SipSession.h"
+
 #include <Ice/Ice.h>
 #include <IceUtil/UUID.h>
 
@@ -400,13 +401,15 @@ AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(co
 
     SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
 
-    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listeners, defaultCookies, mImplPriv->mManager,
-        mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, 
-	true, mImplPriv->mConfig, NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
+    SipSessionPtr session = SipSession::create(mImplPriv->mAdapter, this, destination, listeners, 
+        defaultCookies, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, 
+        mImplPriv->mConfig.sessionConfig.rtpOverIPv6, true, mImplPriv->mConfig, 
+        NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
         mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
         mImplPriv->mConfig.transportConfig.enableNAT));
 
     mImplPriv->mSessions.push_back(session);
+
     std::cout << "And now we're returing a session proxy..." << std::endl;
     return session->getSessionProxy();
 }
@@ -416,13 +419,12 @@ AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const s
     vector<SessionListenerPrx> defaultListeners = mImplPriv->mDefaultListeners->getAll();
     SessionCookies defaultCookies = mImplPriv->mDefaultSessionCookies->getAll();
 
-    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, defaultListeners, defaultCookies, mImplPriv->mManager,
-        mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false, 
-	mImplPriv->mConfig, 
-	NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
-            mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
-            mImplPriv->mConfig.transportConfig.enableNAT)
-        );
+    SipSessionPtr session = SipSession::create(mImplPriv->mAdapter, this, destination, defaultListeners, 
+        defaultCookies, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, 
+        mImplPriv->mConfig.sessionConfig.rtpOverIPv6, false, mImplPriv->mConfig, 
+        NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
+                           mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
+                           mImplPriv->mConfig.transportConfig.enableNAT));
 
     mImplPriv->mSessions.push_back(session);
     return session;
@@ -433,21 +435,30 @@ AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const s
  * Note: Default session cookies and listeners are part of the replicated state, so none are added
  * here. 
  */
-AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination,
-                                                                         const Ice::Identity& sessionid, const Ice::Identity& controllerid,
-                                                                         const Ice::Identity& mediaid,
-                                                                         const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq& mediasessions,
-                                                                         const AsteriskSCF::Media::V1::StreamSourceSeq& sources,
-                                                                         const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
-{
-    SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, sessionid, controllerid, mediaid, mediasessions,
-            sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, false, mImplPriv->mConfig,
-            NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
-                mImplPriv->mConfig.transportConfig.enableNAT));
+AsteriskSCF::SipSessionManager::SipSessionPtr 
+     SipEndpoint::createSession(const std::string& destination,
+                                const Ice::Identity& sessionid, const Ice::Identity& controllerid,
+                                const Ice::Identity& mediaid,
+                                const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq& mediasessions,
+                                const AsteriskSCF::Media::V1::StreamSourceSeq& sources,
+                                const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
+{
+    SipSessionPtr session = SipSession::create(mImplPriv->mAdapter, this, destination, sessionid, 
+             controllerid, mediaid, mediasessions, sources, sinks, mImplPriv->mManager, 
+             mImplPriv->mServiceLocator, mImplPriv->mReplicationContext, false, mImplPriv->mConfig,
+             NATEndpointOptions(mImplPriv->mConfig.sessionConfig.rtpOverICE, 
+             mImplPriv->mConfig.sessionConfig.rtpICEIncludeTURN,
+             mImplPriv->mConfig.transportConfig.enableNAT));
+
     mImplPriv->mSessions.push_back(session);
     return session;
 }
 
+/** 
+ * Remove the Session from our set of active sessions. 
+ * Note: The Session actually calls this method, and is responsible for removing
+ * itself from the object adapter. 
+ */
 void SipEndpoint::removeSession(const AsteriskSCF::SessionCommunications::V1::SessionPtr& session)
 {
     SipSessionPtr sipsession = SipSessionPtr::dynamicCast(session);
@@ -523,9 +534,47 @@ void SipEndpoint::removeDefaultSessionListener(const SessionListenerPrx& listene
     mImplPriv->mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(items);
 }
 
-void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+/** 
+ * Copies the input cookies minus the read-only cookies. 
+ */
+SessionCookies filterReadOnlyCookies(const SessionCookies& cookiesIn, const std::string& logMessage)
+{
+    SessionCookies cookiesOut;
+
+    // Filter out any read-only cookies passed in. They must be set through specific API calls, 
+    // not via generic cookie API. 
+    for(SessionCookies::const_iterator i=cookiesIn.begin(); i != cookiesIn.end(); ++i)
+    {
+        if (SipSession::isSessionCookieReadOnly(*i))
+        {
+            lg(Debug) << BOOST_CURRENT_FUNCTION << " " << logMessage << " of type " <<  (*i)->ice_id();
+            continue;
+        }
+        cookiesOut.push_back(*i);
+    }
+    return cookiesOut;
+}
+
+/**
+ * Adds to the endpoint's default session cookies. 
+ * @param cookies A sequence of cookies to be removed. 
+ * @param privileged Indicates if the calling operation has privilege to alter read-only cookies. 
+ */
+void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, bool privileged)
 {
-    mImplPriv->mDefaultSessionCookies->add(cookies);
+    SessionCookies modCookies;
+
+    if (privileged)
+    {
+        // Use the cookies passed in as-is. 
+        modCookies = cookies;
+    }
+    else
+    {
+        modCookies = filterReadOnlyCookies(cookies, "attempted to add read-only default Session Cookie");
+    }
+
+    mImplPriv->mDefaultSessionCookies->add(modCookies);
 
     if (mImplPriv->mReplicationContext->isReplicating() == false)
     {
@@ -534,20 +583,43 @@ void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const
 
     // Replicate this change. 
     SipStateItemSeq items;
-    for(SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
+    for(SessionCookies::const_iterator i=modCookies.begin(); i != modCookies.end(); ++i)
     {
         items.push_back(new DefaultSessionCookieItem(cookieKey(mImplPriv->mName,  *i),
                 "", 
-                    mImplPriv->mName, 
+                mImplPriv->mName, 
                 (*i)));
     }
 
     mImplPriv->mReplicationContext->getReplicator().tryOneWay()->setState(items);
 }
 
-void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+
+void SipEndpoint::addDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+{
+    addDefaultSessionCookies(cookies, false);
+}
+
+/**
+ * Alters the endpoint's default session cookies. 
+ * @param cookies A sequence of cookies to be removed. 
+ * @param privileged Indicates if the calling operation has privilege to alter read-only cookies. 
+ */
+void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, bool privileged)
 {
-    mImplPriv->mDefaultSessionCookies->remove(cookies);
+    SessionCookies modCookies;
+
+    if (privileged)
+    {
+        // Use the cookies passed in as-is. 
+        modCookies = cookies;
+    }
+    else
+    {
+         modCookies = filterReadOnlyCookies(cookies,  "attempted to remove read-only default Session Cookie");
+    }
+
+    mImplPriv->mDefaultSessionCookies->remove(modCookies);
 
     if (mImplPriv->mReplicationContext->isReplicating() == false)
     {
@@ -556,7 +628,7 @@ void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, con
 
     // Replicate this change. 
     SipStateItemSeq items;
-    for(SessionCookies::const_iterator i=cookies.begin(); i != cookies.end(); ++i)
+    for(SessionCookies::const_iterator i=modCookies.begin(); i != modCookies.end(); ++i)
     {
         items.push_back(new DefaultSessionCookieItem(cookieKey(mImplPriv->mName,  *i),
                 "", 
@@ -567,18 +639,23 @@ void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, con
     mImplPriv->mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(items);
 }
 
+void SipEndpoint::removeDefaultSessionCookies(const SessionCookies& cookies, const Ice::Current&)
+{
+    removeDefaultSessionCookies(cookies, false);
+}
+
 void SipEndpoint::addDefaultSessionCookie(const SessionCookiePtr& cookie)
 {
     SessionCookies cookies;
     cookies.push_back(cookie);
-    addDefaultSessionCookies(cookies);
+    addDefaultSessionCookies(cookies, true);
 }
 
 void SipEndpoint::removeDefaultSessionCookie(const SessionCookiePtr& cookie)
 {
     SessionCookies cookies;
     cookies.push_back(cookie);
-    removeDefaultSessionCookies(cookies);
+    removeDefaultSessionCookies(cookies, true);
 }
 
 SDPDescriptorServicePrx SipEndpoint::getDescriptorService(const SDPDescriptorPtr& descriptor)
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 3480fba..f76df9d 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -359,6 +359,11 @@ public:
         const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr& cookie);
 
 private:
+    void addDefaultSessionCookies(
+        const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookiesInput, bool privileged);
+    void removeDefaultSessionCookies(
+        const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookiesInput, bool privileged);
+
     /**
      * Private implementation details.
      */
diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index 13a63ed..40f1713 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
@@ -51,6 +51,8 @@ public:
 
     void generateRoutingDestinations(AsteriskSCF::Core::Routing::V1::RegExSeq&);
 
+    void updateReferences();
+
 private:
     /**
      * A pointer to the object adapter that endpoints will be added to.
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 0279d67..d5eb792 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -28,6 +28,7 @@
 #include <boost/thread/shared_mutex.hpp>
 #include <boost/lexical_cast.hpp>
 
+#include <AsteriskSCF/System/ExceptionsIf.h>
 #include <AsteriskSCF/System/WorkQueue/WorkQueueIf.h>
 #include <AsteriskSCF/logger.h>
 #include <AsteriskSCF/System/NAT/NATTraversalIf.h>
@@ -40,10 +41,12 @@
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::System::NAT::V1;
 using namespace AsteriskSCF::SessionCommunications::V1;
+using namespace AsteriskSCF::SessionCommunications::PartyIdentification::V1;
 using namespace AsteriskSCF::Media::RTP::V1;
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::Media;
 using namespace AsteriskSCF::Media::SDP::V1;
+using namespace AsteriskSCF::System::V1;
 using namespace std;
 
 namespace
@@ -91,6 +94,54 @@ private:
 };
 
 /**
+ * A class that identifies a set of read-only cookie types.
+ * The types in this set will be protected from being altered
+ * by the general-purpose setCookies() operation. These types 
+ * may, however, be altered via some other API that has the 
+ * privilege to to do so. 
+ * Note: immutable class. 
+ */
+class ReadOnlyCookieTypes
+{
+public:
+    ReadOnlyCookieTypes()
+    {
+        // All of the Party Identification cookies must be set 
+        // through API calls. 
+        DialedPtr dialed = new Dialed();
+        registerType(dialed);
+
+        CallerPtr caller = new Caller();
+        registerType(caller);
+
+        SessionOwnerIdPtr sessionOwnerId = new SessionOwnerId();
+        registerType(sessionOwnerId);
+
+        ConnectedLinePtr connectedLine = new ConnectedLine();
+        registerType(connectedLine);
+
+        RedirectingPtr redirecting = new Redirecting();
+        registerType(redirecting);
+    }
+
+    bool contains(const std::string& cookieTypeId) const 
+    {
+        // If we have an entry registered for cookieTypeId, it's read-only.
+        return (mRegisteredTypes.find(cookieTypeId) != mRegisteredTypes.end());
+    }
+
+private:
+
+    void registerType(SessionCookiePtr cookie)
+    {
+         mRegisteredTypes[cookie->ice_id()] = cookie->ice_id();
+    }
+
+    std::map<std::string, std::string> mRegisteredTypes;
+};
+
+
+/**
  * Private implementation details for SipSession.
  */
 class SipSessionPriv
@@ -108,6 +159,7 @@ public:
           mManager(manager), mServiceLocator(serviceLocator), mReplicationContext(replicationContext), 
 	  mNatOptions(natOptions), mSDP(0)
     { 
+
     }
 
     AsteriskSCF::SessionCommunications::V1::SessionInfoPtr getInfo()
@@ -193,6 +245,24 @@ public:
         return mBridge;
     }
 
+    /** 
+     * Replicate a change in cookie state if needed.
+     */
+    void cookiesUpdated()
+    {
+        if (mInviteSession)
+        {
+            PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(mInviteSession->mod_data[mManager->getSessionModule()->getModule().id]);
+            session_mod_info->updateSessionState(mInviteSession);
+            mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
+        }
+    }
+
+    static bool isCookieReadOnly(const std::string& typeId)
+    {
+        return mReadOnlyCookieTypes.contains(typeId);
+    }
+
     /**
      * An instance of a media session.
      */
@@ -335,7 +405,23 @@ public:
     AsteriskSCF::SessionCommunications::V1::TelephonyEventSourcePrx mEventSourcePrx;
 
     AsteriskSCF::SessionCommunications::V1::TelephonyEventSourceSeq mExternalEventSources;
-};
+
+private:
+    static ReadOnlyCookieTypes mReadOnlyCookieTypes;
+
+}; // class SipSessionPriv
+typedef boost::shared_ptr<SipSessionPriv> SipSessionPrivPtr;
+
+
+ReadOnlyCookieTypes SipSessionPriv::mReadOnlyCookieTypes;
+
+/**
+ * Static operation to allow other classes to test for read-only cookies. 
+ */
+bool SipSession::isSessionCookieReadOnly(const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr &cookie)
+{
+    return SipSessionPriv::isCookieReadOnly(cookie->ice_id());
+}
 
 /**
  * Template for allocating from a pool.
@@ -560,6 +646,84 @@ private:
     SipSessionPtr mSession;
 };
 
+class UpdateRedirectingOperation : public SuspendableWork
+{
+public:
+    UpdateRedirectingOperation(const RedirectingPtr& redirecting,
+                               const boost::shared_ptr<SipSessionPriv>& sessionPriv,
+                               const SipSessionPtr& session)
+        : mRedirecting(redirecting), mImplPriv(sessionPriv), mSession(session)
+    {
+    }
+
+    SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
+    {
+        lg(Debug) << "Executing an UpdateRedirecting operation";
+
+        SessionCookieDict cookies = mSession->getAllCookies();
+
+        SessionCookieDict::const_iterator search = mImplPriv->mSessionCookies.find(mRedirecting->ice_id());
+
+        int updatedCount = 1;
+        if (search != cookies.end())
+        {
+            RedirectingPtr found = RedirectingPtr::dynamicCast(search->second);
+            updatedCount = found->count + 1;
+        }
+
+        mRedirecting->count = updatedCount;
+
+        // Set or replace redirected info.
+        mImplPriv->mSessionCookies[mRedirecting->ice_id()] = mRedirecting;
+  
+        mImplPriv->cookiesUpdated();
+
+        return Complete;
+    }
+
+private:
+    RedirectingPtr mRedirecting;
+    boost::shared_ptr<SipSessionPriv> mImplPriv;
+    SipSessionPtr mSession;
+};
+
+class SetCookiesOperation : public SuspendableWork
+{
+public:
+    SetCookiesOperation(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies,
+                        const boost::shared_ptr<SipSessionPriv>& sessionPriv, 
+                        bool privileged = false)
+        : mCookies(cookies), mImplPriv(sessionPriv), mPrivileged(privileged) { }
+
+    SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
+    {
+        for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = mCookies.begin();
+             i != mCookies.end();
+             ++i)
+        {
+            string cookieType = (*i)->ice_id();
+            if (mImplPriv->isCookieReadOnly(cookieType))
+            {
+                lg(Debug) << "setCookies attempted to set read-only cookie of type " << cookieType;
+                continue;
+            }
+
+            mImplPriv->mSessionCookies.erase(cookieType);
+            mImplPriv->mSessionCookies.insert(make_pair(cookieType, (*i)));
+        }
+
+        mImplPriv->cookiesUpdated();
+
+        return Complete;
+    }
+
+private:
+    AsteriskSCF::SessionCommunications::V1::SessionCookies mCookies;
+    boost::shared_ptr<SipSessionPriv> mImplPriv;
+    bool mPrivileged;
+};
+
+
 /**
  * Implementation of a SessionController interface for the SipSession.
  */
@@ -590,6 +754,23 @@ public:
         mSession->enqueueSessionWork(new RemoveStreamsOperation(cb, streams, mImplPriv, mSession));
     }
     
+    void updateConnectedLine(const ConnectedLinePtr& connected, const Ice::Current&) 
+    {
+        AsteriskSCF::SessionCommunications::V1::SessionCookies cookies;
+        cookies.push_back(connected);
+
+        mSession->enqueueSessionWork(new SetCookiesOperation(cookies, mImplPriv, true));
+    }
+
+    void updateRedirecting(const RedirectingPtr& redirecting, const ::Ice::Current&) 
+    {
+        // TBD.. This merits discussion. I don't think the caller should pass in a new
+        // Redirecting record, but rather just the Id of who's being redirected to. 
+        // Counts and "from" should be maintained internally to the session that owns the record. 
+
+        mSession->enqueueSessionWork(new UpdateRedirectingOperation(redirecting, mImplPriv, mSession));
+    }
+
 private:
     /**
      * Private implementation details for SipSession.
@@ -602,6 +783,33 @@ private:
     SipSessionPtr mSession;
 };
 
+/**
+ * Sets the party id cookies to indicate that this session's SessionOwnerId is the Caller. 
+ */
+void SipSession::setSelfAsCaller()
+{
+    // Note: The SessionOwnerId is set via a default cookie added to the Endpoint. 
+    SessionOwnerIdPtr test = new SessionOwnerId();
+    SessionCookieDict::const_iterator search = mImplPriv->mSessionCookies.find(test->ice_id());
+
+    if (search == mImplPriv->mSessionCookies.end())
+    {
+        lg(Info) << "Party Id information not configured. " << BOOST_CURRENT_FUNCTION << 
+             "Can't update session Caller info. Endpoint" << mImplPriv->mEndpoint->getName();
+        return;
+    }
+
+    SessionOwnerIdPtr owner = SessionOwnerIdPtr::dynamicCast(search->second);
+    CallerPtr caller = new Caller(owner->ids);
+    mImplPriv->mSessionCookies[caller->ice_id()] = caller;
+
+    // If we're the caller, we know the Dialed info as well. 
+    NumberPtr number = new Number(mImplPriv->mDestination);
+    DialedPtr dialed = new Dialed(number);
+
+    mImplPriv->mSessionCookies[caller->ice_id()] = caller;
+}
+
 void SipSession::initializePJSIPStructs()
 {
     SipEndpointConfig& config = mImplPriv->mEndpoint->getConfig();
@@ -762,6 +970,7 @@ void SipSession::activateIceObjects(const AsteriskSCF::SessionCommunications::Ex
         }
     }
 }
+
 void SipSession::setTelephonyEventSourcesAndSinks(const SipEndpointConfig& config)
 {
     if (config.sessionConfig.dtmf == AsteriskSCF::Configuration::SipSessionManager::V1::INFO)
@@ -777,6 +986,69 @@ void SipSession::setTelephonyEventSourcesAndSinks(const SipEndpointConfig& confi
 }
 
 /**
+ * Standard factory method used by an active component to create SipSession objects.
+ */
+SipSessionPtr SipSession::create(const Ice::ObjectAdapterPtr& adapter, 
+        const SipEndpointPtr& endpoint,
+        const std::string& destination, 
+        const vector<SessionListenerPrx>& listeners,
+        const SessionCookies& cookies,
+        const PJSipManagerPtr& manager, 
+        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+        const SipReplicationContextPtr& replicationContext, 
+        bool doIpV6, 
+        bool isUAC, 
+        const SipEndpointConfig &config,
+        const NATEndpointOptions& natOptions)
+{
+    SipSessionPtr newSession = new SipSession(adapter, 
+       endpoint,
+       destination, 
+       listeners,
+       cookies,
+       manager, 
+       serviceLocator,
+       replicationContext, 
+       doIpV6, 
+       isUAC, 
+       config,
+       natOptions);
+
+    newSession->activateIceObjects(newSession->mImplPriv->mManager->getSessionModule()->getSessionCreationHooks());
+
+    return newSession;
+}
+
+/**
+ * Factory used by a standby component to create replicas. 
+ */
+SipSessionPtr SipSession::create(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
+                       const std::string& destination, 
+                       const Ice::Identity& sessionid,
+                       const Ice::Identity& controllerid,
+                       const Ice::Identity& mediaid, const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq& mediasessions,
+                       const AsteriskSCF::Media::V1::StreamSourceSeq& sources, const AsteriskSCF::Media::V1::StreamSinkSeq& sinks,
+                       const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+                       const SipReplicationContextPtr& replicationContext, bool isUAC, const SipEndpointConfig &config,
+                       const NATEndpointOptions& natOptions)
+{
+    SipSessionPtr newSession = new SipSession(adapter, 
+                       endpoint,
+                       destination, 
+                       sessionid,
+                       controllerid,
+                       mediaid, mediasessions,
+                       sources, sinks,
+                       manager, serviceLocator,
+                       replicationContext, isUAC, config,
+                       natOptions);
+
+    newSession->activateIceObjects(newSession->mImplPriv->mManager->getSessionModule()->getSessionCreationHooks());
+
+    return newSession;
+}
+
+/**
  * Standard constructor for use by an active component.
  */
 SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, 
@@ -800,8 +1072,6 @@ SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter,
         mImplPriv->mSessionCookies[(*i)->ice_id()] = (*i);
     }
 
-    activateIceObjects(mImplPriv->mManager->getSessionModule()->getSessionCreationHooks());
-
     mImplPriv->mMediaSession = new SipMediaSession(this);
     mImplPriv->mMediaSessionProxy =
         AsteriskSCF::Media::V1::SessionPrx::uncheckedCast(adapter->addWithUUID(mImplPriv->mMediaSession));
@@ -832,8 +1102,6 @@ SipSession::SipSession(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPt
                        const NATEndpointOptions& natOptions)
     : mImplPriv(new SipSessionPriv(adapter, endpoint, destination, manager, serviceLocator, replicationContext, natOptions))
 {
-    activateIceObjects(mImplPriv->mManager->getSessionModule()->getSessionCreationHooks());
-
     mImplPriv->mMediaSession = new SipMediaSession(this);
     mImplPriv->mMediaSessionProxy =
         AsteriskSCF::Media::V1::SessionPrx::uncheckedCast(adapter->add(mImplPriv->mMediaSession, mediaid));
@@ -1160,6 +1428,22 @@ public:
             }
 
             mImplPriv->mSessionController = mController;
+
+            // Update the party identification. 
+            SessionOwnerIdPtr test = new SessionOwnerId();
+            SessionCookieDict::const_iterator search = mImplPriv->mSessionCookies.find(test->ice_id());
+            if (search != mImplPriv->mSessionCookies.end())
+            {
+                // Set the ConnectedLine information on the other controller. 
+                SessionOwnerIdPtr owner = SessionOwnerIdPtr::dynamicCast(search->second);
+                ConnectedLinePtr connectedLine = new ConnectedLine(owner->ids);
+                mController->updateConnectedLine(connectedLine); // Need to be AMI?
+            }
+            else
+            {
+                lg(Info) << "Unable to set ConnectedLine party info. No Id configured for endpoint " << mImplPriv->mEndpoint->getName(); 
+            }
+
             mCb->ice_response(mImplPriv->mOurSessionControllerProxy);
             return Complete;
         }
@@ -1199,6 +1483,10 @@ public:
                 mImplPriv->mSessionController = 0;
             }
 
+            // Update the connected controller's ConnectedLine information.  
+            SessionOwnerIdPtr test;
+            mImplPriv->mSessionCookies.erase(test->ice_id());
+
             mCb->ice_response();
             return Complete;
         }
@@ -1440,50 +1728,111 @@ void SipSession::stop(const AsteriskSCF::SessionCommunications::V1::ResponseCode
     enqueueSessionWork(new StopOperation(response, mImplPriv->mInviteSession));
 }
 
-class SetCookiesOperation : public SuspendableWork
+/**
+ * An implementation of the setCookies method as defined in SessionCommunicationsIf.ice which sets cookies
+ * on the session. The task is enqueued for thread-safe access to the Session state information.
+ */
+void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies, const Ice::Current&)
+{
+    lg(Debug) << "queuing a setCookies operation";
+    enqueueSessionWork(new SetCookiesOperation(cookies, mImplPriv, false));
+}
+
+/**
+ * Get a cookie from the session of a specified type and pass it to 
+ * the given AMD callback handle. 
+ *
+ * typename CallbackPtr The specific AMD callback type.
+ * typename CookieType The subtype of cookie to get. 
+ * typename CookiePtr Handle to CookieType. NOTE: IceUtil::Handle<CookieType> isn't adequate, and we don't
+ *   want to resort to using IceInternal::Handle<CookieType>
+ */
+template<typename CallbackPtr, typename CookieType, typename CookiePtr>
+class GetCookieAmdOperation : public SuspendableWork
 {
 public:
-    SetCookiesOperation(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies,
-                        const boost::shared_ptr<SipSessionPriv>& sessionPriv)
-        : mCookies(cookies), mImplPriv(sessionPriv) { }
+    /**
+     * @param cb The callback handle for the AMD operation that requested the information.
+     * @param session The session for whom the information is requested from.
+     */
+    GetCookieAmdOperation(const CallbackPtr& cb,
+                          const SipSessionPrivPtr& sessionPriv)
+        : mCb(cb), mImplPriv(sessionPriv)
+    {
+    }
 
     SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
     {
-        for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = mCookies.begin();
-             i != mCookies.end();
-             ++i)
-        {
-            mImplPriv->mSessionCookies.erase((*i)->ice_id());
-            mImplPriv->mSessionCookies.insert(make_pair((*i)->ice_id(), (*i)));
-        }
+        lg(Debug) << "Executing a GetCookie operation";
+
+        CookiePtr test = new CookieType();
+        SessionCookieDict::const_iterator search = mImplPriv->mSessionCookies.find(test->ice_id());
 
-        if (mImplPriv->mInviteSession)
+        if (search == mImplPriv->mSessionCookies.end())
         {
-            PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(mImplPriv->mInviteSession->mod_data[mImplPriv->mManager->getSessionModule()->getModule().id]);
-            session_mod_info->updateSessionState(mImplPriv->mInviteSession);
-            mImplPriv->mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
+            lg(Warning) << "Party Identification cookie not set. " << test->ice_id() << " for Session Endpoint = " << mImplPriv->mEndpoint->getName() ;
+            UnknownObject unknownObject(test->ice_id());
+            mCb->ice_exception(unknownObject);
+            return Complete;
         }
 
+        CookiePtr found = CookiePtr::dynamicCast(search->second);
+        assert(found != 0);
+
+        mCb->ice_response(found);
+
         return Complete;
     }
 
 private:
-    AsteriskSCF::SessionCommunications::V1::SessionCookies mCookies;
-    boost::shared_ptr<SipSessionPriv> mImplPriv;
+    CallbackPtr mCb;
+    SipSessionPrivPtr mImplPriv;
 };
 
-/**
- * An implementation of the setCookies method as defined in SessionCommunications.ice which sets cookies
- * on the session.
+/** 
+ * Gets the Caller party identification record for this Session.
  */
-void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookies& cookies, const Ice::Current&)
+void SipSession::getCaller_async(const AMD_Session_getCallerPtr& cb, const Ice::Current&)
 {
-    lg(Debug) << "queuing a setCookies operation";
-    enqueueSessionWork(new SetCookiesOperation(cookies, mImplPriv));
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getCallerPtr, Caller, CallerPtr>(cb, mImplPriv));
+}
+
+/** 
+ * Gets the Dialed party identification record for this Session.
+ */
+void SipSession::getDialed_async(const AMD_Session_getDialedPtr& cb, const Ice::Current&)
+{
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getDialedPtr, Dialed, DialedPtr>(cb, mImplPriv));
+}
+
+/** 
+ * Gets the SessionId party identification record for this Session.
+ */
+void SipSession::getSessionOwnerId_async(const AMD_Session_getSessionOwnerIdPtr& cb, const ::Ice::Current&)
+{
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getSessionOwnerIdPtr, SessionOwnerId, SessionOwnerIdPtr>(cb, mImplPriv));
+}
+
+/** 
+ * Gets the ConnectedLine party identification record for this Session.
+ */
+void SipSession::getConnectedLine_async(const AMD_Session_getConnectedLinePtr& cb, const ::Ice::Current&)
+{
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getConnectedLinePtr, ConnectedLine, ConnectedLinePtr>(cb, mImplPriv));
+}
+
+/** 
+ * Gets the Redirected party identification record for this Session.
+ */
+void SipSession::getRedirecting_async(const AMD_Session_getRedirectingPtr& cb, const Ice::Current& )
+{
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getRedirectingPtr, Redirecting, RedirectingPtr>(cb, mImplPriv));
 }
 
 /**
- * Internal function to set the cookies (used in replication).
+ * Internal function to replace the cookie dictionary. Used in replication.
+ *
+ * @param cookies A complete dictionary of cookies. 
  */
 void SipSession::setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookieDict& cookies)
 {
@@ -1498,24 +1847,27 @@ public:
         : mCookieTypes(cookieTypes), mImplPriv(sessionPriv) { }
 
     SuspendableWorkResult execute(const SuspendableWorkListenerPtr&)
+    {
+        for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = mCookieTypes.begin();
+                i != mCookieTypes.end();
+                ++i)
         {
-            for (AsteriskSCF::SessionCommunications::V1::SessionCookies::const_iterator i = mCookieTypes.begin();
-                 i != mCookieTypes.end();
-                 ++i)
-            {
-                mImplPriv->mSessionCookies.erase((*i)->ice_id());
-            }
+            string cookieType = (*i)->ice_id();
 
-            if (mImplPriv->mInviteSession)
+            if (mImplPriv->isCookieReadOnly(cookieType))
             {
-                PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(mImplPriv->mInviteSession->mod_data[mImplPriv->mManager->getSessionModule()->getModule().id]);
-                session_mod_info->updateSessionState(mImplPriv->mInviteSession);
-                mImplPriv->mManager->getSessionModule()->replicateState(NULL, NULL, session_mod_info);
+                 lg(Debug) << "removeCookies operation attempted to remove read-only cookie of type " << cookieType;
+                continue;
             }
 
-            return Complete;
+            mImplPriv->mSessionCookies.erase(cookieType);
         }
 
+        mImplPriv->cookiesUpdated();
+
+        return Complete;
+    }
+
 private:
     AsteriskSCF::SessionCommunications::V1::SessionCookies mCookieTypes;
     boost::shared_ptr<SipSessionPriv> mImplPriv;
@@ -1665,6 +2017,7 @@ public:
     {
         // Remove all of the different interfaces we have exposed to the world.
         mSessionPriv->mAdapter->remove(mSessionPriv->mSessionProxy->ice_getIdentity());
+
         mSessionPriv->mAdapter->remove(mSessionPriv->mMediaSessionProxy->ice_getIdentity());
         if (mSessionPriv->mEventSink)
         {
diff --git a/src/SipSession.h b/src/SipSession.h
index e3ebff1..c5bd17f 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -64,7 +64,6 @@ class SipEndpointMediaSRTPConfig;
  */
 class SipSessionPriv;
 
-
 /**
  * This is where session related work items get enqueued.
  *
@@ -104,13 +103,24 @@ typedef IceUtil::Handle<SipTelephonyEventSource> SipTelephonyEventSourcePtr;
 
 class SipEndpointConfig;
 
+class SipSession;
+
+/**
+ * A typedef which creates a smart pointer type for SipSession.
+ */
+typedef IceUtil::Handle<SipSession> SipSessionPtr;
+
 /*
  * Implementation of the Session interface as defined in SessionCommunicationsIf.ice
  */
 class SipSession : public AsteriskSCF::SessionCommunications::V1::TelephonySession
 {
 public:
-    SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
+    /**
+     * Standard factory method used by an active component to create SipSession objects.
+     */
+    static SipSessionPtr create(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, 
+        const std::string&,
         const std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>&,         
         const AsteriskSCF::SessionCommunications::V1::SessionCookies&, 
         const PJSipManagerPtr& manager,
@@ -118,12 +128,18 @@ public:
         const SipReplicationContextPtr& replicationContext,
         bool ipv6, bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
 
-    SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&, const Ice::Identity&, const Ice::Identity&,
-        const Ice::Identity&, const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq&,
-        const AsteriskSCF::Media::V1::StreamSourceSeq&, const AsteriskSCF::Media::V1::StreamSinkSeq&,
+    /**
+     * Factory used by a standby component to create replicas. 
+     */
+    static SipSessionPtr create(const Ice::ObjectAdapterPtr& adapter, const SipEndpointPtr& endpoint,
+        const std::string& destination, 
+        const Ice::Identity& sessionid,
+        const Ice::Identity& controllerid,
+        const Ice::Identity& mediaid, const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq& mediasessions,
+        const AsteriskSCF::Media::V1::StreamSourceSeq& sources, const AsteriskSCF::Media::V1::StreamSinkSeq& sinks,
         const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
-        const SipReplicationContextPtr& replicationContext,
-        bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
+        const SipReplicationContextPtr& replicationContext, bool isUAC, const SipEndpointConfig &config,
+        const NATEndpointOptions& natOptions);
 
     bool operator==(const SipSession &other) const;
 
@@ -139,10 +155,6 @@ public:
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_indicatePtr& cb,
             const AsteriskSCF::SessionCommunications::V1::IndicationPtr&, const Ice::Current&);
 
-    void connect(const Ice::Current&);
-
-    void flash(const Ice::Current&);
-
     void getEndpoint_async(
             const AsteriskSCF::SessionCommunications::V1::AMD_Session_getEndpointPtr& cb,
             const Ice::Current&);
@@ -175,20 +187,24 @@ public:
 
     void activateIceObjects(const AsteriskSCF::SessionCommunications::ExtensionPoints::V1::SessionCreationHookSeq& hooks);
 
-    void hold(const Ice::Current&);
-    void progress(const AsteriskSCF::SessionCommunications::V1::ResponseCodePtr&, const Ice::Current&);
     void removeListener(const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const Ice::Current&);
-    void ring(const Ice::Current&);
     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 setCookies(const AsteriskSCF::SessionCommunications::V1::SessionCookieDict&);
-    void removeCookies(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&);
     AsteriskSCF::SessionCommunications::V1::SessionCookies getCookies();
     AsteriskSCF::SessionCommunications::V1::SessionCookieDict getAllCookies();
 
+
+    ///// Party Identification operations on a Session
+    void getCaller_async(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getCallerPtr& cb, const Ice::Current&);
+    void getDialed_async(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getDialedPtr& cb, const Ice::Current&);
+    void getSessionOwnerId_async(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getSessionOwnerIdPtr& cb, const ::Ice::Current&);
+    void getConnectedLine_async(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getConnectedLinePtr& cb, const ::Ice::Current&);
+    void getRedirecting_async(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getRedirectingPtr& cb, const Ice::Current& );
+
     void getStreams_async(
         const AsteriskSCF::SessionCommunications::V1::AMD_Session_getStreamsPtr&,
         const Ice::Current&);
@@ -225,6 +241,7 @@ public:
     /**
      * Implementation specific functions.
      */
+
     void destroy();
 
     void addNATAttributes(const SipEndpointSessionConfig& config, 
@@ -295,7 +312,27 @@ public:
     SipTelephonyEventSourcePtr getSipTelephonyEventSource();
 
     bool isTelephonyEventSink();
+
+    static bool isSessionCookieReadOnly(const AsteriskSCF::SessionCommunications::V1::SessionCookiePtr &cookie);
+
+    void setSelfAsCaller();
+
 private:
+    SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
+        const std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>&,         
+        const AsteriskSCF::SessionCommunications::V1::SessionCookies&, 
+        const PJSipManagerPtr& manager,
+        const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+        const SipReplicationContextPtr& replicationContext,
+        bool ipv6, bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
+
+    SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&, const Ice::Identity&, const Ice::Identity&,
+        const Ice::Identity&, const AsteriskSCF::Replication::SipSessionManager::V1::RTPMediaSessionSeq&,
+        const AsteriskSCF::Media::V1::StreamSourceSeq&, const AsteriskSCF::Media::V1::StreamSinkSeq&,
+        const PJSipManagerPtr& manager, const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+        const SipReplicationContextPtr& replicationContext,
+        bool isUAC, const SipEndpointConfig& config, const NATEndpointOptions& natOptions);
+
 
     void initializePJSIPStructs();
 
@@ -310,11 +347,6 @@ private:
     boost::shared_ptr<SipSessionPriv> mImplPriv;
 };
 
-/**
- * A typedef which creates a smart pointer type for SipSession.
- */
-typedef IceUtil::Handle<SipSession> SipSessionPtr;
-
 }; //End namespace SipSessionManager
 
 }; //End namespace AsteriskSCF

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list