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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Aug 23 19:04:42 CDT 2011


branch "sessionparty" has been updated
       via  4a5a6552bdb445e3a24c2445ae061135322288a6 (commit)
      from  06b3ee6a41a18dfee3930f1486b8787ca806e87f (commit)

Summary of changes:
 config/Sip.config                                  |   22 ++-
 config/SipConfigurator.py                          |   37 +++-
 config/test_sip.conf                               |    4 +-
 .../SipSessionManager/SipConfigurationIf.ice       |   24 ++-
 src/PJSipSessionModule.cpp                         |    4 +
 src/SipConfiguration.cpp                           |  241 ++++++++++++++++++--
 src/SipEndpoint.cpp                                |   84 ++++++-
 src/SipEndpoint.h                                  |    5 +
 src/SipEndpointFactory.h                           |    2 +
 src/SipSession.cpp                                 |   94 +++++++--
 src/SipSession.h                                   |   18 +-
 11 files changed, 464 insertions(+), 71 deletions(-)


- Log -----------------------------------------------------------------
commit 4a5a6552bdb445e3a24c2445ae061135322288a6
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Aug 23 19:04:58 2011 -0500

    Updates.

diff --git a/config/Sip.config b/config/Sip.config
index 84dc5af..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,6 +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
-# Party identification
-callername=robert bar
-callernumber=123
+#
+# 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 4c94729..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)
@@ -258,7 +291,7 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             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 e6c9532..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,25 +271,28 @@ class SRTPCryptoItem extends SipConfigurationItem
     SRTPCryptoKeySeq cryptoKeys;
 };
 
-class IdentityGroup extends SipConfigurationGroup
+class IdentityItem extends SipConfigurationItem
 {
-    /** 
-     * Identifier for this IdentityGroup
-     */ 
     string name;
+    string number;
 };
 
-class IdentityItem extends SipConfigurationItem
+class IdentityGroup extends SipConfigurationGroup
 {
     /** 
-     * Name part of this identity.
+     * 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;
+};
 
-    /** 
-     * Number part of this identity.
-     */ 
-    string number;
+class IdentityGroupRef extends SipConfigurationItem
+{
+    /**
+     * Name of an identity group. 
+     */
+     string identityGroupName;
 };
 
 /**
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 8646def..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)
     {
@@ -1357,7 +1564,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(
 
         void visitIdentityGroup(const IdentityGroupPtr& group)
         {
-            // TBD...
+            getGeneric<IdentityGroupPtr>(mImpl->getData(), group, mGroups);
         }
 
 	ConfigurationServiceImplPtr mImpl;
@@ -1435,7 +1642,7 @@ ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(
 
         void visitIdentityGroup(const IdentityGroupPtr& group)
         {
-            // TBD...
+            genericGetAll<IdentityGroupPtr>(mImpl->getData(), group, mGroups);
         }
 
 	ConfigurationServiceImplPtr mImpl;
@@ -1526,7 +1733,7 @@ void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::Confi
 
         void visitIdentityGroup(const IdentityGroupPtr& group)
         {
-            // TBD...
+            genericSet<IdentityGroupPtr>(mImpl->getData(), group);
         }
 	
 	ConfigurationServiceImplPtr mImpl;
@@ -1588,7 +1795,7 @@ void ConfigurationServiceImpl::removeConfigurationItems(
 
         void visitIdentityGroup(const IdentityGroupPtr& group)
         {
-            // TBD...
+            mImpl->getData()->removeFromGroup(group);
         }
 
     private:
@@ -1649,7 +1856,7 @@ void ConfigurationServiceImpl::removeConfigurationGroups(
 
         void visitIdentityGroup(const IdentityGroupPtr& group)
         {
-            // TBD...
+            mImpl->getData()->remove(group);
         }
 
 	ConfigurationServiceImplPtr mImpl;
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index bf96161..a8a3c92 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -534,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)
 {
-    mImplPriv->mDefaultSessionCookies->add(cookies);
+    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)
+{
+    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)
     {
@@ -545,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)
     {
@@ -567,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),
                 "", 
@@ -578,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 b028861..d5eb792 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -114,8 +114,8 @@ public:
         CallerPtr caller = new Caller();
         registerType(caller);
 
-        SessionIdPtr sessionId = new SessionId();
-        registerType(sessionId);
+        SessionOwnerIdPtr sessionOwnerId = new SessionOwnerId();
+        registerType(sessionOwnerId);
 
         ConnectedLinePtr connectedLine = new ConnectedLine();
         registerType(connectedLine);
@@ -140,6 +140,7 @@ private:
     std::map<std::string, std::string> mRegisteredTypes;
 };
 
+
 /**
  * Private implementation details for SipSession.
  */
@@ -257,7 +258,7 @@ public:
         }
     }
 
-    bool isCookieReadOnly(const std::string& typeId)
+    static bool isCookieReadOnly(const std::string& typeId)
     {
         return mReadOnlyCookieTypes.contains(typeId);
     }
@@ -409,10 +410,20 @@ 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.
  */
 template<typename T>
@@ -753,6 +764,10 @@ public:
 
     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));
     }
 
@@ -768,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();
@@ -1386,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;
         }
@@ -1425,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;
         }
@@ -1694,8 +1756,8 @@ public:
      * @param session The session for whom the information is requested from.
      */
     GetCookieAmdOperation(const CallbackPtr& cb,
-                          const SipSessionPtr& session)
-        : mCb(cb), mSession(session)
+                          const SipSessionPrivPtr& sessionPriv)
+        : mCb(cb), mImplPriv(sessionPriv)
     {
     }
 
@@ -1703,14 +1765,12 @@ public:
     {
         lg(Debug) << "Executing a GetCookie operation";
 
-        SessionCookieDict cookies = mSession->getAllCookies();
-
         CookiePtr test = new CookieType();
-        SessionCookieDict::const_iterator search = cookies.find(test->ice_id());
+        SessionCookieDict::const_iterator search = mImplPriv->mSessionCookies.find(test->ice_id());
 
-        if (search == cookies.end())
+        if (search == mImplPriv->mSessionCookies.end())
         {
-            lg(Warning) << "Party Identification cookie not set. " << test->ice_id() << " for Session Endpoint = " << mSession->getEndpoint()->getName() ;
+            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;
@@ -1726,7 +1786,7 @@ public:
 
 private:
     CallbackPtr mCb;
-    SipSessionPtr mSession;
+    SipSessionPrivPtr mImplPriv;
 };
 
 /** 
@@ -1734,7 +1794,7 @@ private:
  */
 void SipSession::getCaller_async(const AMD_Session_getCallerPtr& cb, const Ice::Current&)
 {
-    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getCallerPtr, Caller, CallerPtr>(cb, this));
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getCallerPtr, Caller, CallerPtr>(cb, mImplPriv));
 }
 
 /** 
@@ -1742,15 +1802,15 @@ void SipSession::getCaller_async(const AMD_Session_getCallerPtr& cb, const Ice::
  */
 void SipSession::getDialed_async(const AMD_Session_getDialedPtr& cb, const Ice::Current&)
 {
-    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getDialedPtr, Dialed, DialedPtr>(cb, this));
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getDialedPtr, Dialed, DialedPtr>(cb, mImplPriv));
 }
 
 /** 
  * Gets the SessionId party identification record for this Session.
  */
-void SipSession::getSessionId_async(const AMD_Session_getSessionIdPtr& cb, const ::Ice::Current&)
+void SipSession::getSessionOwnerId_async(const AMD_Session_getSessionOwnerIdPtr& cb, const ::Ice::Current&)
 {
-    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getSessionIdPtr, SessionId, SessionIdPtr>(cb, this));
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getSessionOwnerIdPtr, SessionOwnerId, SessionOwnerIdPtr>(cb, mImplPriv));
 }
 
 /** 
@@ -1758,7 +1818,7 @@ void SipSession::getSessionId_async(const AMD_Session_getSessionIdPtr& cb, const
  */
 void SipSession::getConnectedLine_async(const AMD_Session_getConnectedLinePtr& cb, const ::Ice::Current&)
 {
-    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getConnectedLinePtr, ConnectedLine, ConnectedLinePtr>(cb, this));
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getConnectedLinePtr, ConnectedLine, ConnectedLinePtr>(cb, mImplPriv));
 }
 
 /** 
@@ -1766,7 +1826,7 @@ void SipSession::getConnectedLine_async(const AMD_Session_getConnectedLinePtr& c
  */
 void SipSession::getRedirecting_async(const AMD_Session_getRedirectingPtr& cb, const Ice::Current& )
 {
-    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getRedirectingPtr, Redirecting, RedirectingPtr>(cb, this));
+    enqueueSessionWork(new GetCookieAmdOperation<AMD_Session_getRedirectingPtr, Redirecting, RedirectingPtr>(cb, mImplPriv));
 }
 
 /**
diff --git a/src/SipSession.h b/src/SipSession.h
index 28692db..c5bd17f 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -59,14 +59,11 @@ struct NATEndpointOptions;
 class SipEndpointSessionConfig;
 class SipEndpointMediaSRTPConfig;
 
-class SessionIdentifcationManager;
-
 /*
  * Private implementation class for SipSession.
  */
 class SipSessionPriv;
 
-
 /**
  * This is where session related work items get enqueued.
  *
@@ -158,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&);
@@ -194,13 +187,9 @@ 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& );
@@ -212,7 +201,7 @@ public:
     ///// 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 getSessionId_async(const AsteriskSCF::SessionCommunications::V1::AMD_Session_getSessionIdPtr& 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& );
 
@@ -323,6 +312,11 @@ 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>&,         

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list