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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Sat Jun 25 15:47:51 CDT 2011


branch "media" has been updated
       via  ad2772d4e6e236de480122ba840de8243b16dcc8 (commit)
       via  fd7191be17df8c5bc2f23ca085cb1e990667fd9b (commit)
       via  0040a0b14f452da357c829f37310ae5d3d3c8a99 (commit)
       via  1de67641a3e4c2c0bfcfa244a455543af8797ac0 (commit)
       via  95864a0251eff34e50f500caa52a059cd2a69b62 (commit)
       via  0d651e8263be7bee4cbbf00f8e58f4b09e15f447 (commit)
       via  66e14b4c296a134fcbbf03aaf113b405d88703d0 (commit)
       via  a6453ee3997ea4797c32ebd103a14f60bd6930d5 (commit)
       via  359b473d2d15b382e6a82211086ca8af9a5ee5a5 (commit)
       via  85f9eed8c9e2add8d2cb62a7a5b84f5ec9e67bd5 (commit)
       via  666e13eed057d105b86b6c93a94c30b2ffcc7f20 (commit)
       via  5acf69d414ec69896438a0b12668a7803bb2217e (commit)
       via  4cc73e761cbe287f3d79572a07054d22316e665a (commit)
       via  7e5c7f003fefb179ba7d4861a6bbea00b74ff064 (commit)
       via  397eed56f8c9621c4e6a3fc9910405d5acca69af (commit)
       via  e8b826ae01d1de3261627a3f75ab1bca6b337ce4 (commit)
       via  c75f3b9b6d21058d881faf51736b4221522cc7d3 (commit)
       via  d9ad2557af844f4241a8e9c42cdf7da57d63ac98 (commit)
      from  f3022477eb62617f2a573b149e6b04f62e6d458a (commit)

Summary of changes:
 config/Sip.config                                  |    4 +-
 config/SipConfigurator.py                          |   96 +++++++++++---------
 .../SipSessionManager/SipConfigurationIf.ice       |   27 +++++-
 src/PJSipSessionModule.cpp                         |   52 +++++++++--
 src/PJSipSessionModule.h                           |    1 +
 src/PJSipSessionModuleConstruction.cpp             |   22 +++++
 src/SipConfiguration.cpp                           |    8 +-
 src/SipEndpoint.cpp                                |   43 ++++++----
 src/SipEndpoint.h                                  |    2 +-
 src/SipSession.cpp                                 |   31 ++++++-
 src/SipSession.h                                   |    7 +-
 11 files changed, 208 insertions(+), 85 deletions(-)


- Log -----------------------------------------------------------------
commit ad2772d4e6e236de480122ba840de8243b16dcc8
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:47:59 2011 -0300

    Update documentation to include formats.

diff --git a/config/Sip.config b/config/Sip.config
index 176d796..ac8e349 100644
--- a/config/Sip.config
+++ b/config/Sip.config
@@ -79,4 +79,6 @@ direction=both
 securetransport=none
 # Whether to use IPv6 for media transport or not
 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

commit fd7191be17df8c5bc2f23ca085cb1e990667fd9b
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:46:49 2011 -0300

    Add support for specifying more details in the configuration file for media formats.

diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index 7db7217..1d34378 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -157,6 +157,28 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             mapper.execute(group, section, option)
         mapper.finish(group)
 
+        try:
+            formats = config.get(section, 'formats')
+            configuredFormats = formats.split(',')
+            for format in configuredFormats:
+                name, found, rest = format.partition('/')
+                sampleRate, found, rest = rest.partition('@')
+                frameSize, found, formatSpecific = rest.partition(';')
+
+                item = AsteriskSCF.Configuration.SipSessionManager.V1.SipMediaFormatItem()
+                item.name = name
+                if sampleRate:
+                    item.sampleRate = sampleRate
+                if frameSize:
+                    item.frameSize = frameSize
+                item.formatSpecific = [ ]
+                if formatSpecific:
+                    item.formatSpecific.append(formatSpecific)
+
+                group.configurationItems[format] = item
+        except:
+            print 'No configured formats for endpoint ' + section
+
         self.groups.append(group)
 
     def visit_unsupported(self, config, section):

commit 0040a0b14f452da357c829f37310ae5d3d3c8a99
Merge: 95864a0 1de6764
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:15:49 2011 -0300

    Merge branch 'master' into media


commit 1de67641a3e4c2c0bfcfa244a455543af8797ac0
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:15:39 2011 -0300

    Make logging available.

diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index 9c76951..56a0beb 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -14,11 +14,20 @@
  * at the top of the source tree.
  */
 
+#include <AsteriskSCF/logger.h>
 #include <AsteriskSCF/WorkQueue/WorkQueue.h>
 #include <AsteriskSCF/ThreadPool/ThreadPool.h>
 
 #include "PJSipSessionModule.h"
 
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
+}
+
+
 namespace AsteriskSCF
 {
 

commit 95864a0251eff34e50f500caa52a059cd2a69b62
Merge: 66e14b4 0d651e8
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:13:07 2011 -0300

    Merge branch 'master' into media


commit 0d651e8263be7bee4cbbf00f8e58f4b09e15f447
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:12:52 2011 -0300

    Okay, NOW this will be compile. Thought it did before but was mistaken.

diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index e72d3a4..9c76951 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -25,7 +25,7 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-using namespace AsteriskSCF::WorkQueue::V1;
+using namespace AsteriskSCF::WorkQueue;
 using namespace AsteriskSCF::ThreadPool;
 
 
@@ -163,7 +163,7 @@ PJSipSessionModule::~PJSipSessionModule()
     {
         mPoolQueue->shutdown();
     }
-    catch (const ShuttingDown&)
+    catch (const AsteriskSCF::System::WorkQueue::V1::ShuttingDown&)
     {
         lg(Warning) << "Attempted to shut down a Queue that is already shut down.";
     }

commit 66e14b4c296a134fcbbf03aaf113b405d88703d0
Merge: 359b473 a6453ee
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:09:34 2011 -0300

    Merge branch 'master' into media


commit a6453ee3997ea4797c32ebd103a14f60bd6930d5
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 17:09:20 2011 -0300

    Make this compile.

diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index c7af8d2..e72d3a4 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -25,9 +25,10 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
-using namespace AsteriskSCF::WorkQueue;
+using namespace AsteriskSCF::WorkQueue::V1;
 using namespace AsteriskSCF::ThreadPool;
 
+
 static char moduleName[] = "PJSipSessionModule";
 
 static PJSipSessionModule *sessionModule;

commit 359b473d2d15b382e6a82211086ca8af9a5ee5a5
Merge: 666e13e 85f9eed
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 16:28:05 2011 -0300

    Merge branch 'master' into media
    
    Conflicts:
    	src/SipSession.cpp

diff --cc src/SipSession.cpp
index cea3015,972b5b0..05e81e4
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@@ -319,12 -294,10 +320,13 @@@ void SipSession::initializePJSIPStructs
      mImplPriv->mDialog = dialog;
      
      pjsip_inv_session *inviteSession;
 +
 +    // Create an SDP offer based on what is configured
      pjmedia_sdp_session *sdp = createSDPOffer();
 +
      if ((pjsip_inv_create_uac(dialog, sdp, 0, &inviteSession)) != PJ_SUCCESS)
      {
+         lg(Error) << "Failed to create a UAC INVITE session!";
          pjsip_dlg_terminate(dialog);
          // What should we do here? Throw an exception?
          return;
@@@ -362,8 -335,13 +364,9 @@@ SipSession::SipSession(const Ice::Objec
      mImplPriv->mMediaSessionProxy =
          AsteriskSCF::Media::V1::SessionPrx::uncheckedCast(adapter->addWithUUID(mImplPriv->mMediaSession));
  
 -    // Get an RTP session capable of handling the formats we are going to offer
 -    AsteriskSCF::Media::V1::FormatSeq formats;
 -    requestRTPSessions(formats, ipv6);
 -
      if (isUAC)
      {
+         lg(Debug) << "New session is UAC, so we're creating the necessary PJSIP structures";
          initializePJSIPStructs();
      }
  }
@@@ -453,7 -434,9 +456,8 @@@ public
  
          if ((Connect = AsteriskSCF::SessionCommunications::V1::ConnectIndicationPtr::dynamicCast(mIndication)))
          {
+             lg(Debug) << "Processing a Connect indication";
 -            pjmedia_sdp_session *sdp = mSession->createSDPOffer();
 -            status = pjsip_inv_answer(mImplPriv->mInviteSession, 200, NULL, sdp, &packet);
 +            status = pjsip_inv_answer(mImplPriv->mInviteSession, 200, NULL, NULL, &packet);
          }
          else if ((Flash = AsteriskSCF::SessionCommunications::V1::FlashIndicationPtr::dynamicCast(mIndication)))
          {
@@@ -467,7 -452,9 +473,8 @@@
          }
          else if ((Progress = AsteriskSCF::SessionCommunications::V1::ProgressIndicationPtr::dynamicCast(mIndication)))
          {
+             lg(Debug) << "Processing a Progress indication";
 -            pjmedia_sdp_session *sdp = mSession->createSDPOffer();
 -            status = pjsip_inv_answer(mImplPriv->mInviteSession, 183, NULL, sdp, &packet);
 +            status = pjsip_inv_answer(mImplPriv->mInviteSession, 183, NULL, NULL, &packet);
          }
          else if ((Ring = AsteriskSCF::SessionCommunications::V1::RingIndicationPtr::dynamicCast(mIndication)))
          {
@@@ -1070,13 -1064,16 +1083,14 @@@ pjmedia_sdp_session *SipSession::create
      sdp->origin.version = sdp->origin.id = (pj_uint32_t) (tv.sec + 2208988800UL);
      pj_strdup2(mImplPriv->mDialog->pool, &sdp->origin.net_type, "IN");
  
 -    // Right now we only support a single stream so go and get it
 -    AsteriskSCF::Media::RTP::V1::StreamSourceRTPPrx stream =
 -        AsteriskSCF::Media::RTP::V1::StreamSourceRTPPrx::uncheckedCast(mImplPriv->mSources.front());
 +    sdp->origin.addr = *pj_gethostname();
  
 -    std::string address = stream->getLocalAddress();
 +    std::string address = std::string(pj_strbuf(&sdp->origin.addr), pj_strlen(&sdp->origin.addr));
  
+     lg(Debug) << "The local address we are placing in our SDP is " << address;
      if (address.find(":") != std::string::npos)
      {
 -	pj_strdup2(mImplPriv->mDialog->pool, &sdp->origin.addr_type, "IP6");
 +        pj_strdup2(mImplPriv->mDialog->pool, &sdp->origin.addr_type, "IP6");
      }
      else
      {

commit 85f9eed8c9e2add8d2cb62a7a5b84f5ec9e67bd5
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 16:27:03 2011 -0300

    Update to support namespace change and moving of files.

diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index 980cded..7db7217 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -19,26 +19,26 @@
 # Sip configurator
 
 # Bring in the common configuration infrastructure
-import Ice, Configurator, sys
+import Ice, Configurator, sys, os
 
 # Load our component specific configuration definitions
-Ice.loadSlice('-I. -I/opt/Ice-3.4.1/slice -I../../slice --all ../local-slice/SipConfigurationIf.ice')
-import AsteriskSCF.SIP.V1
+Ice.loadSlice("-I" + os.environ["ASTSCF_HOME"] + " -I" + Ice.getSliceDir() + " --all ../slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice")
+import AsteriskSCF.Configuration.SipSessionManager.V1
 
 # Add our own visitor implementations for the sections we support
 class SipSectionVisitors(Configurator.SectionVisitors):
     def visit_general(self, config, section):
-        group = AsteriskSCF.SIP.V1.SipGeneralGroup()
+        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipGeneralGroup()
         group.configurationItems = { }
         self.groups.append(group)
 
     def visit_transport_udp(self, config, section):
-        group = AsteriskSCF.SIP.V1.SipUDPTransportGroup()
+        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipUDPTransportGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
-        item = AsteriskSCF.SIP.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
         mapper.map('host', item, 'host', 'address', config.get, None)
         mapper.map('port', item, 'port', 'address', config.getint, 5060)
         for option in config.options(section):
@@ -49,12 +49,12 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_transport_tcp(self, config, section):
-        group = AsteriskSCF.SIP.V1.SipTCPTransportGroup()
+        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipTCPTransportGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
-        item = AsteriskSCF.SIP.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
         mapper.map('host', item, 'host', 'address', config.get, None)
         mapper.map('port', item, 'port', 'address', config.getint, 5060)
         for option in config.options(section):
@@ -65,12 +65,12 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_transport_tls(self, config, section):
-        group = AsteriskSCF.SIP.V1.SipTLSTransportGroup()
+        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipTLSTransportGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
-        item = AsteriskSCF.SIP.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
         mapper.map('host', item, 'host', 'address', config.get, None)
         mapper.map('port', item, 'port', 'address', config.getint, 5060)
         for option in config.options(section):
@@ -81,19 +81,19 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_endpoint(self, config, section):
-        group = AsteriskSCF.SIP.V1.SipEndpointGroup()
+        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipEndpointGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
 
-        mapper.map('routing', AsteriskSCF.SIP.V1.SipRoutingItem(), 'routingServiceName', 'routingService', config.get, None)
+        mapper.map('routing', AsteriskSCF.Configuration.SipSessionManager.V1.SipRoutingItem(), 'routingServiceName', 'routingService', config.get, None)
 
-        item = AsteriskSCF.SIP.V1.SipSourceTransportAddressItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipSourceTransportAddressItem()
         mapper.map('sourcehost', item, 'host', 'sourceaddress', config.get, None)
         mapper.map('sourceport', item, 'port', 'sourceaddress', config.getint, 5060)
 
-        item = AsteriskSCF.SIP.V1.SipTargetDestinationAddressItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipTargetDestinationAddressItem()
         mapper.map('targethost', item, 'host', 'targetaddress', config.get, None)
         mapper.map('targetport', item, 'port', 'targetaddress', config.getint, 5060)
 
@@ -102,35 +102,35 @@ class SipSectionVisitors(Configurator.SectionVisitors):
                 self.config = config
             def get(self, section, item):
                 if self.config.get(section, item) == 'inbound':
-                    return AsteriskSCF.SIP.V1.SipAllowableCallDirection.Inbound
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Inbound
                 elif self.config.get(section, item) == 'outbound':
-                    return AsteriskSCF.SIP.V1.SipAllowableCallDirection.Outbound
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Outbound
                 elif self.config.get(section, item) == 'both':
-                    return AsteriskSCF.SIP.V1.SipAllowableCallDirection.Both
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Both
                 elif self.config.get(section, item) == 'none':
-                    return AsteriskSCF.SIP.V1.SipAllowableCallDirection.Disabled
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Disabled
 
         transformer = AllowableCallDirectionTransformer(config)
 
-        mapper.map('direction', AsteriskSCF.SIP.V1.SipAllowableCallDirectionItem(), 'callDirection', 'callDirection', transformer.get, None)
+        mapper.map('direction', AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirectionItem(), 'callDirection', 'callDirection', transformer.get, None)
 
-        mapper.map('securetransport', AsteriskSCF.SIP.V1.SipEndpointTransportItem(), 'secureTransport', 'transport', transformer.get, None)
+        mapper.map('securetransport', AsteriskSCF.Configuration.SipSessionManager.V1.SipEndpointTransportItem(), 'secureTransport', 'transport', transformer.get, None)
 
-        item = AsteriskSCF.SIP.V1.SipRTPMediaServiceItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipRTPMediaServiceItem()
         mapper.map('rtpoveripv6', item, 'requireIPv6', 'mediaservice', config.getboolean, None)
 
-        item = AsteriskSCF.SIP.V1.SipCryptoCertificateItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipCryptoCertificateItem()
         mapper.map('certificateauthorityfile', item, 'certificateAuthority', 'cryptocert', config.get, None)
         mapper.map('certificatefile', item, 'certificate', 'cryptocert', config.get, None)
         mapper.map('privatekeyfile', item, 'privateKey', 'cryptocert', config.get, None)
         mapper.map('privatekeypassword', item, 'privateKeyPassword', 'cryptocert', config.get, None)
 
-        item = AsteriskSCF.SIP.V1.SipCryptoRequirementsItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipCryptoRequirementsItem()
         mapper.map('requireverifiedserver', item, 'requireVerifiedServer', 'cryptorequirements', config.getboolean, None)
         mapper.map('requireverifiedclient', item, 'requireVerifiedClient', 'cryptorequirements', config.getboolean, None)
         mapper.map('requireclientcertificate', item, 'requireClientCertificate', 'cryptorequirements', config.getboolean, None)
 
-        item = AsteriskSCF.SIP.V1.SipCryptoItem()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipCryptoItem()
         mapper.map('supportedciphers', item, 'supportedCiphers', 'crypto', config.get, None)
         mapper.map('tlsservername', item, 'serverName', 'crypto', config.get, None)
         mapper.map('tlstimeout', item, 'timeout', 'crypto', config.getint, None)
@@ -140,15 +140,15 @@ class SipSectionVisitors(Configurator.SectionVisitors):
                 self.config = config
             def get(self, section, item):
                 if self.config.get(section, item) == 'unspecified':
-                    return AsteriskSCF.SIP.V1.TLSProtocolMethod.PROTOCOLMETHODUNSPECIFIED
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODUNSPECIFIED
                 elif self.config.get(section, item) == 'tlsv1':
-                    return AsteriskSCF.SIP.V1.TLSProtocolMethod.PROTOCOLMETHODTLSV1
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODTLSV1
                 elif self.config.get(section, item) == 'sslv2':
-                    return AsteriskSCF.SIP.V1.TLSProtocolMethod.PROTOCOLMETHODTSSLV2
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODTSSLV2
                 elif self.config.get(section, item) == 'sslv3':
-                    return AsteriskSCF.SIP.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV3
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV3
                 elif self.config.get(section, item) == 'sslv23':
-                    return AsteriskSCF.SIP.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV23
+                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV23
 
         transformer = TLSProtocolMethodTransformer(config)
         mapper.map('tlsprotocolmethod', item, 'protocolMethod', 'crypto', transformer.get, None)
@@ -170,8 +170,8 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             self.visit_endpoint(config, section)
 
 # In order to do service locator based lookup we need to pass in a params object
-serviceLocatorParams = AsteriskSCF.SIP.V1.SipConfigurationParams()
-serviceLocatorParams.category = AsteriskSCF.SIP.V1.ConfigurationDiscoveryCategory
+serviceLocatorParams = AsteriskSCF.Configuration.SipSessionManager.V1.SipConfigurationParams()
+serviceLocatorParams.category = AsteriskSCF.Configuration.SipSessionManager.V1.ConfigurationDiscoveryCategory
 
 # Make a configurator application and let it run
 app = Configurator.ConfiguratorApp('Sip.config', SipSectionVisitors(), None, serviceLocatorParams)

commit 666e13eed057d105b86b6c93a94c30b2ffcc7f20
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 16:12:20 2011 -0300

    Update to changes on getNamedFormat, need to finish configurator changes.

diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index dcd8716..980cded 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -153,18 +153,6 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         transformer = TLSProtocolMethodTransformer(config)
         mapper.map('tlsprotocolmethod', item, 'protocolMethod', 'crypto', transformer.get, None)
 
-        item = AsteriskSCF.SIP.V1.SipMediaFormatsItem()
-        item.formats = [ ]
-
-        class FormatTransformer():
-            def __init__(self, config):
-                self.config = config
-            def get(self, section, item):
-                return self.config.get(section, item).split(',')
-
-        transformer = FormatTransformer(config)
-        mapper.map('formats', item, 'formats', 'formats', transformer.get, None)
-
         for option in config.options(section):
             mapper.execute(group, section, option)
         mapper.finish(group)
diff --git a/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice b/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
index 1f61203..7d3b57b 100644
--- a/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
+++ b/slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice
@@ -362,14 +362,33 @@ module V1
    };
 
    /**
-    * Allowable media formats item
+    * Allowable media format item
     */
-   class SipMediaFormatsItem extends SipConfigurationItem
+   class SipMediaFormatItem extends SipConfigurationItem
    {
        /**
-        * A sequence of all configured media formats, in string form
+        * Name of the media format
         */
-       Ice::StringSeq formats;
+       string name;
+
+       /**
+        * Sample rate for frames
+        *
+        * This is specified in Hz and has a default value of 8000. 
+        */
+       int sampleRate = 8000;
+
+       /**
+        * Amount of audio in frames
+        *
+        * This is specified in 
+        */
+       int frameSize;
+
+       /**
+        * Any format specific parameters
+        */
+       Ice::StringSeq formatSpecific;
    };
 
    /**
diff --git a/src/SipConfiguration.cpp b/src/SipConfiguration.cpp
index bb8c010..d4077a8 100644
--- a/src/SipConfiguration.cpp
+++ b/src/SipConfiguration.cpp
@@ -184,9 +184,9 @@ class EndpointConfigHelper : public boost::enable_shared_from_this<EndpointConfi
             mUpdates.push_back(boost::bind(&EndpointConfigHelper::updateDirection, mConfig, direction));
         }
 
-	void visitSipMediaFormatsItem(const SipMediaFormatsItemPtr& formats)
+	void visitSipMediaFormatItem(const SipMediaFormatItemPtr& format)
 	{
-            mUpdates.push_back(boost::bind(&EndpointConfigHelper::updateFormats, mConfig, formats));
+            mUpdates.push_back(boost::bind(&EndpointConfigHelper::addFormat, mConfig, format));
 	}
         
         void visitSipSourceTransportAddressItem(const SipSourceTransportAddressItemPtr& source)
@@ -263,9 +263,9 @@ public:
         mEndpoint->setCallDirection(translateCallDirection(direction->callDirection));
     }
 
-    void updateFormats(const SipMediaFormatsItemPtr& formats)
+    void addFormat(const SipMediaFormatItemPtr& format)
     {
-	mEndpoint->setFormats(formats->formats);
+	mEndpoint->addFormat(format->name, format->sampleRate, format->frameSize, format->formatSpecific);
     }
 
     void updateSource(const SipSourceTransportAddressItemPtr& source)
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 366af84..ac3518a 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -45,7 +45,8 @@ namespace SipSessionManager
 class ConfiguredFormat : public IceUtil::Shared
 {
 public:
-    ConfiguredFormat(std::string& name) : mName(name), mAvailable(false) { }
+    ConfiguredFormat(const std::string& name, int sampleRate, int frameSize, const Ice::StringSeq& formatSpecific) :
+        mName(name), mSampleRate(sampleRate), mFrameSize(frameSize), mFormatSpecific(formatSpecific), mAvailable(false) { }
 
     void locateCB(const Ice::ObjectPrx& service)
     {
@@ -57,7 +58,7 @@ public:
             this, &ConfiguredFormat::getNamedFormatCB, &ConfiguredFormat::getNamedFormatFailureCB);
 
 	// Send it off
-	mDescriptorService->begin_getNamedFormat(mName, descriptorCB);
+	mDescriptorService->begin_getNamedFormat(mName, mSampleRate, mFrameSize, mFormatSpecific, descriptorCB);
     }
 
     void locateFailureCB(const Ice::Exception&)
@@ -116,6 +117,21 @@ private:
     std::string mName;
 
     /**
+     * Sample rate of the media.
+     */
+    int mSampleRate;
+
+    /**
+     * Size of the media frames.
+     */
+    int mFrameSize;
+
+    /**
+     * Format specific parameters.
+     */
+    Ice::StringSeq mFormatSpecific;
+
+    /**
      * Whether this configured format is available or not.
      */
     bool mAvailable;
@@ -250,23 +266,18 @@ void SipEndpoint::setRTPOverIPv6(bool enabled)
     mImplPriv->mConfig.sessionConfig.rtpOverIPv6 = enabled;
 }
 
-void SipEndpoint::setFormats(const Ice::StringSeq& formats)
+void SipEndpoint::addFormat(const std::string& name, int sampleRate, int frameSize, const Ice::StringSeq& formatSpecific)
 {
-    for (Ice::StringSeq::const_iterator format = formats.begin(); format != formats.end(); ++format)
-    {
-	SDPDescriptorServiceLocatorParamsPtr params = new SDPDescriptorServiceLocatorParams();
-	params->category = "Media/SDP_Descriptor";
-	params->name = (*format);
-
-        ConfiguredFormatPtr configuredFormat = new ConfiguredFormat(params->name);
-        Callback_ServiceLocator_locatePtr descriptorCB = newCallback_ServiceLocator_locate(
-            configuredFormat, &ConfiguredFormat::locateCB, &ConfiguredFormat::locateFailureCB);
+    SDPDescriptorServiceLocatorParamsPtr params = new SDPDescriptorServiceLocatorParams();
+    params->category = "Media/SDP_Descriptor";
+    params->name = name;
 
-        // Before we do the locate make sure this is part of the endpoint
-        mImplPriv->mFormats.push_back(configuredFormat);
+    ConfiguredFormatPtr configuredFormat = new ConfiguredFormat(name, sampleRate, frameSize, formatSpecific);
+    Callback_ServiceLocator_locatePtr descriptorCB = newCallback_ServiceLocator_locate(
+        configuredFormat, &ConfiguredFormat::locateCB, &ConfiguredFormat::locateFailureCB);
 
-        mImplPriv->mServiceLocator->begin_locate(params, descriptorCB);
-    }
+    mImplPriv->mFormats.push_back(configuredFormat);
+    mImplPriv->mServiceLocator->begin_locate(params, descriptorCB);
 }
 
 Direction SipEndpointConfig::stringToDirection(const std::string& directionString)
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 5580b25..ebf4d87 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -261,7 +261,7 @@ public:
     void setCallDirection(enum Direction);
     void setSecureTransport(enum Direction);
     void setRTPOverIPv6(bool);
-    void setFormats(const Ice::StringSeq&);
+    void addFormat(const std::string& name, int sampleRate, int frameSize, const Ice::StringSeq& formatSpecific);
 
     /**
      * API call which returns a proxy to an SDP descriptor service given a descriptor.

commit 5acf69d414ec69896438a0b12668a7803bb2217e
Author: Joshua Colp <jcolp at digium.com>
Date:   Sat Jun 25 15:53:50 2011 -0300

    Use boost::lexical_cast to turn the payload into a number instead of a std::stringstream

diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index c233025..cea3015 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -1283,7 +1283,7 @@ pjmedia_sdp_session *SipSession::createSDPAnswer(const pjmedia_sdp_session* offe
 
 	    std::string payload = std::string(pj_strbuf(&offer->media[stream]->desc.fmt[format]),
                 pj_strlen(&offer->media[stream]->desc.fmt[format]));
-            std::stringstream(payload) >> descriptor->payload;
+	    descriptor->payload = boost::lexical_cast<int>(payload);
             descriptor->type = std::string(pj_strbuf(&offer->media[stream]->desc.media),
                                            pj_strlen(&offer->media[stream]->desc.media));
 

commit 4cc73e761cbe287f3d79572a07054d22316e665a
Merge: b49bbff 7e5c7f0
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 24 16:28:46 2011 -0500

    Merge branch 'queue-shutdown'

diff --cc src/PJSipSessionModule.h
index 73f5f60,1519f21..7b4cd30
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@@ -89,8 -89,9 +89,9 @@@ public
          const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
              sessionRouter,
          const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
 -        const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
 +        const AsteriskSCF::Discovery::SmartProxy<SipStateReplicatorPrx>& stateReplicator,
          const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
+     ~PJSipSessionModule();
      pj_status_t load(pjsip_endpoint *endpoint);
      pj_status_t start();
      pj_status_t stop();

commit 7e5c7f003fefb179ba7d4861a6bbea00b74ff064
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Jun 24 16:23:15 2011 -0500

    Change shutDown to shutdown

diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index 9db407e..ace8e3e 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -160,7 +160,7 @@ PJSipSessionModule::~PJSipSessionModule()
 {
     try
     {
-        mPoolQueue->shutDown();
+        mPoolQueue->shutdown();
     }
     catch (const ShuttingDown&)
     {

commit 397eed56f8c9621c4e6a3fc9910405d5acca69af
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Jun 8 14:19:46 2011 -0500

    Add try-catch block around a queue call that I had missed earlier.

diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index 9649b3c..9db407e 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -158,7 +158,14 @@ PJSipSessionModule::PJSipSessionModule(pjsip_endpoint *endpt,
 
 PJSipSessionModule::~PJSipSessionModule()
 {
-    mPoolQueue->shutDown();
+    try
+    {
+        mPoolQueue->shutDown();
+    }
+    catch (const ShuttingDown&)
+    {
+        lg(Warning) << "Attempted to shut down a Queue that is already shut down.";
+    }
 }
 
 }; //end namespace SipSessionManager

commit e8b826ae01d1de3261627a3f75ab1bca6b337ce4
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Jun 8 09:57:33 2011 -0500

    Make adjustments based on review feedback.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index aeb6d24..b4bdd69 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -1617,7 +1617,7 @@ void SessionWork::workAdded(const QueueBasePtr&, Ice::Long, bool wasEmpty)
         {
             mThreadPoolQueue->enqueueWork(this);
         }
-        catch (ShuttingDown)
+        catch (const ShuttingDown&)
         {
             lg(Warning) << "Queue has shut down. Not enqueueing task.";
         }
@@ -1630,7 +1630,7 @@ void SessionWork::workResumable(const QueueBasePtr&)
     {
         mThreadPoolQueue->enqueueWork(this);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         lg(Warning) << "Queue has shut down. Not enqueueing task.";
     }
@@ -1654,7 +1654,7 @@ void SessionWork::execute()
             // no-op
         }
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         lg(Warning) << "Queue has shut down. Not enqueueing task.";
     }
@@ -1666,7 +1666,7 @@ void SessionWork::enqueueWork(const SuspendableWorkPtr& work)
     {
         mInternalQueue->enqueueWork(work);
     }
-    catch (ShuttingDown)
+    catch (const ShuttingDown&)
     {
         lg(Warning) << "Queue has shut down. Not enqueueing task.";
     }
diff --git a/src/PJSipSessionModule.cpp.orig b/src/PJSipSessionModule.cpp.orig
deleted file mode 100644
index 32ed923..0000000
--- a/src/PJSipSessionModule.cpp.orig
+++ /dev/null
@@ -1,1355 +0,0 @@
-/*
- * Asterisk SCF -- An open-source communications framework.
- *
- * Copyright (C) 2010, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-#include <IceUtil/UUID.h>
-
-#include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
-#include <AsteriskSCF/Core/Routing/RoutingIf.h>
-#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.h>
-#include <AsteriskSCF/Media/MediaIf.h>
-#include <AsteriskSCF/logger.h>
-#include <AsteriskSCF/WorkQueue.h>
-#include <AsteriskSCF/SuspendableWorkQueue.h>
-
-#include "PJSipSessionModule.h"
-#include "SipEndpoint.h"
-#include "SipEndpointFactory.h"
-#include "SipSession.h"
-#include "PJSipManager.h"
-#include "SipStateReplicator.h"
-
-using namespace AsteriskSCF::System::Logging;
-
-namespace
-{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
-//Constants used for AMI callback class construction when calling
-//SessionListenerPrx methods.
-const std::string RingingCallbackName("ringing");
-const std::string ProgressingCallbackName("progressing");
-const std::string ConnectedCallbackName("connected");
-}
-
-namespace AsteriskSCF
-{
-
-namespace SipSessionManager
-{
-
-using namespace AsteriskSCF::Core::Routing::V1;
-using namespace AsteriskSCF::Core::Endpoint::V1;
-using namespace AsteriskSCF::SessionCommunications::V1;
-using namespace AsteriskSCF::Media::V1;
-using namespace AsteriskSCF::SIP::V1;
-using namespace AsteriskSCF::System::ThreadPool::V1;
-using namespace AsteriskSCF::System::WorkQueue::V1;
-using namespace AsteriskSCF::WorkQueue;
-
-class RouteSessionCallback : public IceUtil::Shared
-{
-public:
-    RouteSessionCallback(pjsip_inv_session *inv_session, 
-                         pjsip_tx_data *tdata,
-                         const SipSessionPtr& session,
-                         const std::string& destination,
-                         const std::string& operationId)
-        : mInvSession(inv_session), 
-          mTData(tdata),
-          mSession(session),
-          mDestination(destination),
-          mOperationId(operationId)
-    { 
-    }
-
-    void callback(const Ice::AsyncResultPtr& r)
-    {
-        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
-        try
-        {
-            router->end_routeSession(r);
-        }
-        catch (const DestinationNotFoundException &)
-        {
-            pjsip_inv_end_session(mInvSession, 404, NULL, &mTData);
-            pjsip_inv_send_msg(mInvSession, mTData);
-        }
-        catch (...)
-        {
-            pjsip_inv_end_session(mInvSession, 500, NULL, &mTData);
-            pjsip_inv_send_msg(mInvSession, mTData);
-        }
-    }
-private:
-    pjsip_inv_session *mInvSession;
-    pjsip_tx_data *mTData;
-    SipSessionPtr mSession;
-    std::string mDestination;
-    std::string mOperationId;
-};
-typedef IceUtil::Handle<RouteSessionCallback> RouteSessionCallbackPtr;
-
-class ConnectBridgedSessionsCallback : public IceUtil::Shared
-{
-public:
-    ConnectBridgedSessionsCallback(pjsip_inv_session *inv_session,
-                                   pjsip_tx_data *tdata, 
-                                   pjsip_transaction *tsx,
-                                   const SipSessionPtr& session,
-                                   const SipSessionPtr& otherSession,
-                                   const std::string& operationId)
-        : mInvSession(inv_session), 
-          mTData(tdata), 
-          mTsx(tsx),
-          mSession(session),
-          mOtherSession(otherSession),
-          mOperationId(operationId)
-
-    { 
-    }
-
-    void callback(const Ice::AsyncResultPtr &r)
-    {
-        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
-        try
-        {
-            router->end_connectBridgedSessions(r);
-        }
-        catch (const std::exception &e)
-        {
-            lg(Debug) << "ConnectBridgedSessionsCallback sending 400 due to exception:  " << e.what();
-            pjsip_dlg_modify_response(mInvSession->dlg, mTData, 400, NULL);
-            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
-            return;
-        }
-        pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
-        
-        Ice::Current current;
-        lg(Debug) << "ConnectBridgedSessionsCallback calling session->stop(). ";
-        mSession->stop(new ResponseCode(16), current);
-    }
-private:
-    pjsip_inv_session *mInvSession;
-    pjsip_tx_data *mTData;
-    pjsip_transaction *mTsx;
-    SipSessionPtr mSession;
-    SipSessionPtr mOtherSession;
-    std::string mOperationId;
-};
-
-typedef IceUtil::Handle<ConnectBridgedSessionsCallback> ConnectBridgedSessionsCallbackPtr;
-
-class ConnectBridgedSessionsWithDestinationCallback : public IceUtil::Shared
-{
-public:
-    ConnectBridgedSessionsWithDestinationCallback(pjsip_inv_session *inv_session, 
-                                                  pjsip_tx_data *tdata, 
-                                                  pjsip_transaction *tsx,
-                                                  SipSessionPtr session, 
-                                                  const std::string& target,
-                                                  const std::string& operationId)
-        : mInvSession(inv_session), 
-          mTData(tdata), 
-          mTsx(tsx),
-          mSession(session), 
-          mTarget(target),
-          mOperationId(operationId)
-    { 
-    }
-
-    void callback(const Ice::AsyncResultPtr &r)
-    {
-        SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
-        try
-        {
-            router->end_connectBridgedSessions(r);
-        }
-        catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException &)
-        {
-            lg(Debug) << "ConnectBridgedSessionsWithDestination sending 404 due to destination not found for target: "
-                      << mTarget;
-
-            pjsip_dlg_modify_response(mInvSession->dlg, mTData, 400, NULL);
-            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
-            return;
-        }
-        catch (const std::exception &e)
-        {
-            lg(Debug) << "ConnectBridgedSessionsWithDestination sending 400 due to exception:  " << e.what();
-            pjsip_dlg_modify_response(mInvSession->dlg, mTData, 400, NULL);
-            pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
-            return;
-        }
-        pjsip_dlg_send_response(mInvSession->dlg, mTsx, mTData);
-        
-        Ice::Current current;
-        lg(Debug) << "ConnectBridgedSessionsWithDestination calling session->stop(). ";
-        mSession->stop(new ResponseCode(16), current);
-    }
-private:
-    pjsip_inv_session *mInvSession;
-    pjsip_tx_data *mTData;
-    pjsip_transaction *mTsx;
-    SipSessionPtr mSession;
-    std::string mTarget;
-    std::string mOperationId;
-};
-
-typedef IceUtil::Handle<ConnectBridgedSessionsWithDestinationCallback> ConnectBridgedSessionsWithDestinationCallbackPtr;
-
-class ListenerCallback : public IceUtil::Shared
-{
-public:
-    ListenerCallback(const std::string& name) : mCallbackName(name) {}
-    void failure(const Ice::Exception& ex)
-    {
-        lg(Error) << "Ice exception when attempting to relate " << mCallbackName << " state: " << ex.what();
-    }
-private:
-    const std::string mCallbackName;
-};
-
-typedef IceUtil::Handle<ListenerCallback> ListenerCallbackPtr;
-
-PJSipSessionModInfo::PJSipSessionModInfo(pjsip_inv_session *inv_session,
-    const SipSessionPtr& session) :
-    mSessionState(new SipSessionStateItem),
-    mInviteState(new SipInviteSessionStateItem),
-    mNeedsReplication(true),
-    mNeedsRemoval(false),
-    mSession(session)
-{
-    mSessionState->key = IceUtil::generateUUID();
-    mInviteState->key = IceUtil::generateUUID();
-    mSessionState->mSessionId = mSessionState->key;
-    mInviteState->mSessionId = mSessionState->key;
-    updateSessionState(inv_session);
-}
-
-PJSipSessionModInfo::~PJSipSessionModInfo()
-{
-    if (mSession)
-    {
-        mSession->destroy();
-        mSession = 0;
-    }
-}
-
-void PJSipSessionModInfo::updateSessionState(pjsip_inv_session *inv_session)
-{
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
-    if (mSession)
-    {
-        mSessionState->mEndpointName = mSession->getEndpoint()->getName();
-        mSessionState->mSessionObjectId = mSession->getSessionProxy()->ice_getIdentity();
-        mSessionState->mMediaSessionObjectId = mSession->getMediaSessionProxy()->ice_getIdentity();
-        mSessionState->mSources = mSession->getSources();
-        mSessionState->mSinks = mSession->getSinks();
-        mSessionState->mMediaSession = mSession->getHiddenMediaSession();
-        mSessionState->mListeners = mSession->getListeners();
-        try
-        {
-            mSessionState->mBridge = mSession->getBridge();
-        }
-        catch (...)
-        {
-            mSessionState->mBridge = 0;
-        }
-    }
-
-    //Now we get stuff from the inv_session itself.
-    mInviteState->mCancelling = inv_session->cancelling == PJ_TRUE ? true : false;
-    mInviteState->mPendingCancel = inv_session->pending_cancel == PJ_TRUE ? true : false;
-    mInviteState->mCause = inv_session->cause;
-    mInviteState->mCauseText = std::string(pj_strbuf(&inv_session->cause_text), pj_strlen(&inv_session->cause_text));
-    mInviteState->mNotify = inv_session->notify == PJ_TRUE ? true : false;
-    mInviteState->mLastAckCseq = inv_session->last_ack_cseq;
-    mInviteState->mCurrentState = inviteStateTranslate(inv_session->state);
-    mNeedsReplication = true;
-}
-
-SipSessionPtr PJSipSessionModInfo::getSessionPtr()
-{
-    return mSession;
-}
-
-void PJSipSessionModInfo::setSessionPtr(const SipSessionPtr& sessionPtr)
-{
-    mSession = sessionPtr;
-}
-
-InviteSessionState PJSipSessionModInfo::inviteStateTranslate(pjsip_inv_state state)
-{
-    InviteSessionState retState;
-    switch (state)
-    {
-    case PJSIP_INV_STATE_NULL:
-        retState = InviteSessionStateNull;
-        break;
-    case PJSIP_INV_STATE_CALLING:
-        retState = InviteSessionStateCalling;
-        break;
-    case PJSIP_INV_STATE_INCOMING:
-        retState = InviteSessionStateIncoming;
-        break;
-    case PJSIP_INV_STATE_EARLY:
-        retState = InviteSessionStateEarly;
-        break;
-    case PJSIP_INV_STATE_CONNECTING:
-        retState = InviteSessionStateConnecting;
-        break;
-    case PJSIP_INV_STATE_CONFIRMED:
-        retState = InviteSessionStateConfirmed;
-        break;
-    case PJSIP_INV_STATE_DISCONNECTED:
-        retState = InviteSessionStateDisconnected;
-        break;
-    default:
-        lg(Warning) << "Unknwon PJSIP INVITE state encountered: " << state;
-        retState = InviteSessionStateNull;
-        break;
-    }
-    return retState;
-}
-
-void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransactionModInfo *tsxInfo,
-    PJSipSessionModInfo *sessionInfo)
-{
-    SipStateItemSeq setItems;
-    Ice::StringSeq removeItems;
-
-    lg(Debug) << "========== Begin State Replication Dump ==========";
-
-    if (dlgInfo)
-    {
-        lg(Debug) << "--- Begin Dialog " << dlgInfo->mDialogState->key;
-        lg(Debug) << "Callid: " << dlgInfo->mDialogState->mCallId;
-        lg(Debug) << "Is Dialog Established: " << dlgInfo->mDialogState->mIsDialogEstablished;
-        lg(Debug) << "Is Secure: " << dlgInfo->mDialogState->mIsSecure;
-        lg(Debug) << "Local CSeq: " << dlgInfo->mDialogState->mLocalCSeq;
-        lg(Debug) << "Local URI: " << dlgInfo->mDialogState->mLocalUri;
-        lg(Debug) << "Remote CSeq: " << dlgInfo->mDialogState->mRemoteCSeq;
-        lg(Debug) << "Remote URI: " << dlgInfo->mDialogState->mRemoteUri;
-        lg(Debug) << "Transport: " << dlgInfo->mDialogState->mTransport;
-        lg(Debug) << "UAC Has 2xx: " << dlgInfo->mDialogState->mUacHas2xx;
-        lg(Debug) << "Is Uac: " << dlgInfo->mDialogState->mIsUac;
-        if (dlgInfo->mNeedsRemoval == true)
-        {
-            lg(Debug) << "Removing dialog";
-            removeItems.push_back(dlgInfo->mDialogState->key);
-        }
-        else if (dlgInfo->mNeedsReplication == true)
-        {
-            lg(Debug) << "Replicating dialog";
-            setItems.push_back(dlgInfo->mDialogState);
-            dlgInfo->mNeedsReplication = false;
-        }
-        lg(Debug) << "--- End Dialog " << dlgInfo->mDialogState->key;
-    }
-    if (sessionInfo)
-    {
-        boost::shared_lock<boost::shared_mutex> lock(sessionInfo->mLock);
-        lg(Debug) << "--- Begin Session " << sessionInfo->mSessionState->key;
-        lg(Debug) << "Endpoint name: " << sessionInfo->mSessionState->mEndpointName;
-        lg(Debug) << "Session object identity: " << sessionInfo->mSessionState->mSessionObjectId.name;
-        lg(Debug) << "Media session object identity: " << sessionInfo->mSessionState->mMediaSessionObjectId.name;
-        lg(Debug) << "Media session: " << sessionInfo->mSessionState->mMediaSession;
-        lg(Debug) << "Bridge: " << sessionInfo->mSessionState->mBridge;
-        lg(Debug) << "--- Begin Invite Session " << sessionInfo->mInviteState->key;
-        lg(Debug) << "Current state: " << sessionInfo->mInviteState->mCurrentState;
-        lg(Debug) << "Cancelling: " << sessionInfo->mInviteState->mCancelling;
-        lg(Debug) << "Pending cancel: " << sessionInfo->mInviteState->mPendingCancel;
-        lg(Debug) << "Cause: " << sessionInfo->mInviteState->mCause;
-        lg(Debug) << "Cause text: " << sessionInfo->mInviteState->mCauseText;
-        lg(Debug) << "Notify: " << sessionInfo->mInviteState->mNotify;
-        lg(Debug) << "Last Ack CSeq: " << sessionInfo->mInviteState->mLastAckCseq;
-        if (sessionInfo->mNeedsRemoval == true)
-        {
-            removeItems.push_back(sessionInfo->mInviteState->key);
-            removeItems.push_back(sessionInfo->mSessionState->key);
-            lg(Debug) << "Removing session and invite session";
-        }
-        else if (sessionInfo->mNeedsReplication == true)
-        {
-            setItems.push_back(sessionInfo->mInviteState);
-            setItems.insert(setItems.begin(), sessionInfo->mSessionState);
-            sessionInfo->mNeedsReplication = false;
-            lg(Debug) << "Replicating session and invite session";
-        }
-        lg(Debug) << "--- End Session and Invite Session";
-    }
-    if (tsxInfo)
-    {
-        if (tsxInfo->mNeedsRemoval == true)
-        {
-            removeItems.push_back(tsxInfo->mTransactionState->key);
-        }
-        else if (tsxInfo->mNeedsReplication == true)
-        {
-            setItems.push_back(tsxInfo->mTransactionState);
-            tsxInfo->mNeedsReplication = false;
-        }
-    }
-    lg(Debug) << "========== End State Replication Dump ==========";
-    if (mReplica->isActive() == true)
-    {
-        if (setItems.size() != 0 && mStateReplicator)
-        {
-            Ice::ObjectPrx oneway;
-            try
-            {
-                oneway = mStateReplicator->ice_oneway();
-            }
-            catch (const Ice::NoEndpointException&)
-            {
-                lg(Error) << "No endpoint for oneway invocation of setState() for state replication.";
-            }
-
-            AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator = 
-                AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(oneway);
-
-            try
-            {
-                oneWayStateReplicator->setState(setItems);
-            }
-            catch (const Ice::TwowayOnlyException&)
-            {
-                lg(Error) << "setState() is not oneway.";
-            }
-        }
-
-        if (removeItems.size() != 0 && mStateReplicator)
-        {
-            Ice::ObjectPrx oneway;
-            try
-            {
-                oneway = mStateReplicator->ice_oneway();
-            }
-            catch (const Ice::NoEndpointException&)
-            {
-                lg(Error) << "No endpoint for oneway invocation of removeState() for state replication.";
-            }
-
-            AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator =
-                AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(oneway);
-
-            try
-            {
-                oneWayStateReplicator->removeState(removeItems);
-            }
-            catch (const Ice::TwowayOnlyException&)
-            {
-                lg(Error) << "removeState() is not oneway.";
-            }
-        }
-    }
-}
-
-pj_status_t PJSipSessionModule::load(pjsip_endpoint*)
-{
-    return PJ_SUCCESS;
-}
-
-pj_status_t PJSipSessionModule::start()
-{
-    return PJ_SUCCESS;
-}
-
-pj_status_t PJSipSessionModule::stop()
-{
-    return PJ_SUCCESS;
-}
-
-pj_status_t PJSipSessionModule::unload()
-{
-    return PJ_SUCCESS;
-}
-
-void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
-{
-    //What do we do here?
-    //
-    //First we need to identify who this is coming from.
-    //If it's someone we recognize, then we can figure
-    //out whether we need to send a 401/407 request.
-    //For now, we don't have any sort of configured users,
-    //so we skip this step. Instead, we'll skip ahead to
-    //creating an endpoint, creating the invite session,
-    //sending a 100 trying, finding the remote endpoint
-    //to call, and placing a call to it.
-
-    //XXX Put caller identification code in here!
-
-    pjsip_tx_data *tdata = NULL;
-    unsigned options = PJSIP_INV_SUPPORT_100REL;
-
-    // Verify we can handle this invite request and respond accordingly if we can not
-    if (pjsip_inv_verify_request(rdata, &options, NULL, NULL, mEndpoint, &tdata) != PJ_SUCCESS)
-    {
-	if (tdata)
-	{
-	    pjsip_endpt_send_response2(mEndpoint, rdata, tdata, NULL, NULL);
-	}
-	else
-	{
-	    pjsip_endpt_respond_stateless(mEndpoint, rdata, 500, NULL, NULL, NULL);
-	}
-	return;
-    }
-
-    pjsip_dialog *dlg, *replaced_dlg;
-
-    // If this is an attended transfer and something is amuck... respond accordingly
-    if (pjsip_replaces_verify_request(rdata, &replaced_dlg, PJ_FALSE, &tdata) != PJ_SUCCESS)
-    {
-	if (tdata)
-	{
-	    pjsip_endpt_send_response2(mEndpoint, rdata, tdata, NULL, NULL);
-	}
-	else
-	{
-	    pjsip_endpt_respond_stateless(mEndpoint, rdata, 500, NULL, NULL, NULL);
-	}
-        return;
-    }
-
-    //XXX The NULL parameter should be replaced with
-    //An appropriate Contact header. Leaving it NULL makes
-    //PJSIP create the contact header for responses based
-    //on the To header of the incoming Invite.
-    if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS)
-    {
-        lg(Warning) << "Unable to create UAS dialog on incoming INVITE";
-        return;
-    }
-
-    PJSipDialogModInfo *dlg_mod_info = new PJSipDialogModInfo(dlg);
-
-    pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
-    PJSipTransactionModInfo *tsx_mod_info = new PJSipTransactionModInfo(tsx);
-    tsx->mod_data[mModule.id] = (void *)tsx_mod_info;
-
-    //XXX The sdp argument is NULL for now, but can be changed if we
-    //know what has been configured for this particular caller.
-    pjsip_inv_session *inv_session;
-    if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS)
-    {
-        lg(Warning) << "Unable to create INVITE session";
-        //Since the inv_session was not created, we need to access the base dialog
-        //directly instead. Other failure cases will use pjsip_inv_terminate instead.
-        pjsip_dlg_terminate(dlg);
-        return;
-    }
-
-    // Add our own module as a dialog usage
-    pjsip_dlg_add_usage(dlg, &mModule, NULL);
-
-    pjsip_timer_setting session_timer_settings;
-    pjsip_timer_setting_default(&session_timer_settings);
-    pjsip_timer_init_session(inv_session, &session_timer_settings);
-
-    if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
-    {
-        lg(Warning) << "Failed to create 100 Trying response";
-        pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
-        return;
-    }
-
-    if (pjsip_inv_send_msg(inv_session, tdata) != PJ_SUCCESS)
-    {
-        lg(Warning) << "Failed to send 100 Trying response";
-        pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
-    }
-
-    pjsip_uri *from = rdata->msg_info.from->uri;
-    std::string callerName("");
-    if (PJSIP_URI_SCHEME_IS_SIP(from) || PJSIP_URI_SCHEME_IS_SIPS(from))
-    {
-        pjsip_sip_uri *sipFrom = (pjsip_sip_uri *)pjsip_uri_get_uri(from);
-        callerName = std::string(pj_strbuf(&sipFrom->user), pj_strlen(&sipFrom->user));
-        lg(Debug) << "Got caller name " << callerName;
-    }
-    SipEndpointPtr caller = mEndpointFactory->findByName(callerName);
-    if (caller == 0)
-    {
-        lg(Warning) << "Unknown calling endpoint " << callerName;
-        pjsip_inv_end_session(inv_session, 403, NULL, &tdata);
-        pjsip_inv_send_msg(inv_session, tdata);
-        return;
-    }
-    SipEndpointConfig &config = caller->getConfig();
-    if (config.sessionConfig.callDirection != BOTH && config.sessionConfig.callDirection != INBOUND)
-    {
-        lg(Warning) << "Caller " << callerName << " does not have permission to make inbound calls.";
-        pjsip_inv_end_session(inv_session, 403, NULL, &tdata);
-        pjsip_inv_send_msg(inv_session, tdata);
-        return;
-    }
-
-    //We've created our calling endpoint. Now we need to look up the destination.
-    pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
-    std::string destination("");
-    if (PJSIP_URI_SCHEME_IS_SIP(ruri) || PJSIP_URI_SCHEME_IS_SIPS(ruri))
-    {
-        pjsip_sip_uri *sipRuri = (pjsip_sip_uri *)pjsip_uri_get_uri(ruri);
-        //For now, we only know about destination "100" so we'll
-        //grab that from the URI to pass to the locator.
-        destination = std::string(pj_strbuf(&sipRuri->user), pj_strlen(&sipRuri->user));
-        lg(Debug) << "Call is destined for " << destination;
-    }
-
-    SipSessionPtr session;
-    try
-    {
-        session = caller->createSession(destination);
-    }
-    catch (const Ice::Exception& ex)
-    {
-        lg(Error) << "Exception caught while trying to create SIP session\n" << ex.what();
-        pjsip_inv_end_session(inv_session, 500, NULL, &tdata);
-        pjsip_inv_send_msg(inv_session, tdata);
-        return;
-    }
-    session->setInviteSession(inv_session);
-    session->setDialog(dlg);
-    PJSipSessionModInfo *session_mod_info = new PJSipSessionModInfo(inv_session, session);
-    dlg_mod_info->mDialogState->mSessionId = session_mod_info->mSessionState->mSessionId;
-    tsx_mod_info->mTransactionState->mSessionId = session_mod_info->mSessionState->mSessionId;
-
-    inv_session->mod_data[mModule.id] = (void *)session_mod_info;
-    dlg->mod_data[mModule.id] = (void *)dlg_mod_info;
-
-    lg(Debug) << "Replicating state on reception of new SIP INVITE.";
-    replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
-    try
-    {
-        if (replaced_dlg)
-        {
-            // For attended transfers we need to contact the routing service which should then (hopefully) replace the
-            // other session
-        }
-        else
-        {
-            // If this is not an attended transfer we can just route the session as normally
-            std::string operationId = ::IceUtil::generateUUID();
-            RouteSessionCallbackPtr cb = new RouteSessionCallback(inv_session, tdata, session, destination, operationId);
-            Ice::CallbackPtr d = Ice::newCallback(cb, &RouteSessionCallback::callback);
-            mSessionRouter->begin_routeSession(operationId, session->getSessionProxy(), destination, d);
-        }
-    }
-    catch (const Ice::CommunicatorDestroyedException &)
-    {
-        // Everything else doesn't really map so they just become internal server errors
-        pjsip_inv_end_session(inv_session, 500, NULL, &tdata);
-        pjsip_inv_send_msg(inv_session, tdata);
-        return;
-    }
-}
-
-void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdata)
-{
-    const pj_str_t str_refer_to = { (char*)"Refer-To", 8 };
-    pjsip_generic_string_hdr *refer_to =
-        static_cast<pjsip_generic_string_hdr *>(pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL));
-
-    lg(Debug) << "Handling a REFER";
-    if (!refer_to)
-    {
-        // Uh... so they didn't tell us where to REFER this to... yeah no
-        lg(Debug) << "handleRefer() sending 400 due to no refer_to. ";
-        pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
-        return;
-    }
-
-    // TODO: Add support for subscription
-
-    // TODO: Provide method to send back suitable response
-
-    // Now parse the URI to get the actual target they want to refer to
-    pjsip_uri *target_uri = static_cast<pjsip_uri *>(pjsip_parse_uri(inv->dlg->pool, refer_to->hvalue.ptr, refer_to->hvalue.slen, 0));
-
-    // We only support SIP URIs, anything else is rubbish to us
-    if (!PJSIP_URI_SCHEME_IS_SIP(target_uri) && !PJSIP_URI_SCHEME_IS_SIPS(target_uri))
-    {
-        // TODO: Place proper response code in here
-        lg(Debug) << "handleRefer() sending 400 due to non-SIP URI. ";
-        pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
-        return;
-    }
-
-    pjsip_sip_uri *target_sip_uri = (pjsip_sip_uri *)pjsip_uri_get_uri(target_uri);
-
-    // Determine if this is a blind transfer or an attended transfer
-    pj_str_t replaces = pj_str((char*)"Replaces");
-    pjsip_param *replaces_param = pjsip_param_find(&target_sip_uri->other_param, &replaces);
-
-    if (!replaces_param)
-    {
-        replaces_param = pjsip_param_find(&target_sip_uri->header_param, &replaces);
-    }
-
-    if (replaces_param)
-    {
-        pj_str_t to_tag = pj_str((char*)"To-tag");
-        pj_str_t from_tag = pj_str((char*)"From-tag");
-        pjsip_param *to_tag_param = pjsip_param_find(&target_sip_uri->other_param, &to_tag);
-        pjsip_param *from_tag_param = pjsip_param_find(&target_sip_uri->other_param, &from_tag);
-        pjsip_dialog *other_dlg = NULL;
-
-        if (to_tag_param && from_tag_param)
-        {
-            other_dlg = pjsip_ua_find_dialog(&replaces_param->value, &to_tag_param->value, &from_tag_param->value,
-                    PJ_TRUE);
-        }
-        else
-        {
-            // It is possible for the to and from tag value to be present within the Replaces parameter value, so try to
-            // parse it out
-            std::string replaces_value_tmp = std::string(pj_strbuf(&replaces_param->value),
-                    pj_strlen(&replaces_param->value));
-            size_t from_tag_pos = replaces_value_tmp.find(";from-tag=");
-            size_t to_tag_pos = replaces_value_tmp.find(";to-tag=");
-
-            if (from_tag_pos == std::string::npos || to_tag_pos == std::string::npos)
-            {
-                lg(Debug) << "handleRefer() sending 400 due to From or To missing. ";
-                pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
-                return;
-            }
-
-            std::string to_tag_value = replaces_value_tmp.substr(to_tag_pos + 8, from_tag_pos - to_tag_pos - 8);
-            std::string from_tag_value = replaces_value_tmp.substr(from_tag_pos + 10);
-            std::string replaces_value = replaces_value_tmp.substr(0, to_tag_pos);
-
-            pj_str_t to_tag_str = pj_str((char*)to_tag_value.c_str());
-            pj_str_t from_tag_str = pj_str((char*)from_tag_value.c_str());
-            pj_str_t replaces_tag_str = pj_str((char*)replaces_value.c_str());
-
-            other_dlg = pjsip_ua_find_dialog(&replaces_tag_str, &to_tag_str, &from_tag_str, PJ_TRUE);
-        }
-
-        if (!other_dlg)
-        {
-            lg(Debug) << "handleRefer() sending PJSIP_SC_CALL_TSX_DOES_NOT_EXIST due to no other_dlg. ";
-            pjsip_dlg_respond(inv->dlg, rdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL, NULL, NULL);
-            return;
-        }
-
-        pjsip_inv_session *other_inv = pjsip_dlg_get_inv_session(other_dlg);
-
-        if (!other_inv)
-        {
-            lg(Debug) << "handleRefer() sending PJSIP_SC_CALL_TSX_DOES_NOT_EXIST due to no other_inv. ";
-            pjsip_dlg_respond(inv->dlg, rdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL, NULL, NULL);
-            pjsip_dlg_dec_lock(other_dlg);
-            return;
-        }
-
-        if (other_inv->state >= PJSIP_INV_STATE_DISCONNECTED)
-        {
-            lg(Debug) << "handleRefer() sending PJSIP_SC_DECLINE due to state > PJSIP_INV_STATE_DISCONNECTED. ";
-
-            pjsip_dlg_respond(inv->dlg, rdata, PJSIP_SC_DECLINE, NULL, NULL, NULL);
-            pjsip_dlg_dec_lock(other_dlg);
-            return;
-        }
-
-        if (other_inv->state <= PJSIP_INV_STATE_EARLY && other_inv->role != PJSIP_ROLE_UAC)
-        {
-            lg(Debug) << "handleRefer() sending PJSIP_SC_CALL_TSX_DOES_NOT_EXIST due to other_inv->state < PJSIP_INV_STATE_EARLY and role not UAC. ";
-
-            pjsip_dlg_respond(inv->dlg, rdata, PJSIP_SC_CALL_TSX_DOES_NOT_EXIST, NULL, NULL, NULL);
-            pjsip_dlg_dec_lock(other_dlg);
-            return;
-        }
-
-        PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
-        SipSessionPtr session = session_mod_info->getSessionPtr();
-
-        PJSipSessionModInfo *other_session_mod_info = (PJSipSessionModInfo*)other_inv->mod_data[mModule.id];
-        SipSessionPtr other_session = other_session_mod_info->getSessionPtr();
-
-        try
-        {
-            pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
-            pjsip_tx_data *tdata;
-            pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata);
-            std::string operationId = ::IceUtil::generateUUID();
-            ConnectBridgedSessionsCallbackPtr cb(new ConnectBridgedSessionsCallback(inv, tdata, tsx, session, other_session, operationId));
-            Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsCallback::callback);
-
-            lg(Debug) << "handleRefer() calling router connectBridgedSessions(). ";
-            mSessionRouter->begin_connectBridgedSessions(operationId, session->getSessionProxy(), other_session->getSessionProxy(), d);
-        }
-        catch (const Ice::CommunicatorDestroyedException &)
-        {
-            lg(Debug) << "handleRefer() sending 503 due to communicator destruction";
-            pjsip_dlg_respond(inv->dlg, rdata, 503, NULL, NULL, NULL);
-            return;
-        }
-        pjsip_dlg_dec_lock(other_dlg);
-    }
-    else
-    {
-        std::string target = std::string(pj_strbuf(&target_sip_uri->user), pj_strlen(&target_sip_uri->user));
-
-        // Now that we have the target user we can pass this into routing and go on our marry way
-        try
-        {
-            std::string operationId = ::IceUtil::generateUUID();
-            PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
-            SipSessionPtr session = session_mod_info->getSessionPtr();
-            pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
-            pjsip_tx_data *tdata;
-            pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata);
-            ConnectBridgedSessionsWithDestinationCallbackPtr cb(
-                    new ConnectBridgedSessionsWithDestinationCallback(inv, tdata, tsx, session, target, operationId));
-            Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsWithDestinationCallback::callback);
-
-            lg(Debug) << "handleRefer() calling router connectBridgedSessionsWithDestination(). ";
-            mSessionRouter->begin_connectBridgedSessionsWithDestination(operationId, session->getSessionProxy(), target, d);
-        }
-        catch (const Ice::CommunicatorDestroyedException &)
-        {
-            lg(Debug) << "handleRefer() sending 503 due to communicator destruction";
-            pjsip_dlg_respond(inv->dlg, rdata, 503, NULL, NULL, NULL);
-            return;
-        }
-    }
-}
-
-pj_bool_t PJSipSessionModule::on_rx_request(pjsip_rx_data *rdata)
-{
-    pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
-    switch (rdata->msg_info.msg->line.req.method.id)
-    {
-    case PJSIP_ACK_METHOD:
-	return PJ_FALSE;
-    case PJSIP_INVITE_METHOD:
-        if (dlg == NULL)
-        {
-            handleNewInvite(rdata);
-        }
-        else
-        {
-            lg(Warning) << "on_rx_request called back in mid-dialog?";
-        }
-        break;
-    case PJSIP_OTHER_METHOD:
-        if (dlg && !pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, pjsip_get_refer_method()))
-        {
-            // We are essentially stopping the pjsip code from sending a 500 here, but this will actually be handled
-            // within the transaction code
-            break;
-        }
-    default:
-	pjsip_endpt_respond_stateless(mEndpoint, rdata, 405, NULL, NULL, NULL);
-	break;
-    }
-
-    return PJ_TRUE;
-}
-
-/* The following four member functions are all stubbed out because they
- * are either unused at the moment or will never be called due to the use
- * of PJSIP's INVITE session module.
- *
- * Linking errors abound if these member functions are not defined, though.
- */
-pj_bool_t PJSipSessionModule::on_rx_response(pjsip_rx_data*)
-{
-    return PJ_FALSE;
-}
-pj_status_t PJSipSessionModule::on_tx_request(pjsip_tx_data*)
-{
-    return PJ_SUCCESS;
-}
-pj_status_t PJSipSessionModule::on_tx_response(pjsip_tx_data*)
-{
-    return PJ_SUCCESS;
-}
-void PJSipSessionModule::on_tsx_state(pjsip_transaction*, pjsip_event*)
-{
-    return;
-}
-
-void PJSipSessionModule::handleInviteResponse(pjsip_inv_session* inv,
-    pjsip_rx_data* rdata, pjsip_dialog*)
-{
-    int respCode = rdata->msg_info.msg->line.status.code;
-    PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
-    SipSessionPtr session = session_mod_info->getSessionPtr();
-    //Commented because they are currently unused. They
-    //will be once the individual cases are mapped out.
-    //pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
-    //pjsip_module *module = pjsip_ua_instance();
-    //
-    //XXX There are a BUNCH of response codes we need
-    //to add code to handle.
-
-    //Treat all 1XX messages we don't recognize the same as a 180
-    if (respCode > 100 && respCode < 200 && respCode != 183)
-    {
-        respCode = 180;
-    }
-    if (respCode == 100)
-    {
-        //Not sure if PJSIP even bothers passing these up
-        lg(Debug) << "Got 100 response";
-    }
-    else if (respCode == 180)
-    {
-        lg(Debug) << "Got 180 response";
-        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
-        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
-        lg(Debug) << "Relating ringing state to " << listeners.size() << " listeners";
-        for (listener = listeners.begin(); listener != listeners.end(); ++listener)
-        {
-            try
-            {
-                ListenerCallbackPtr cb(new ListenerCallback(RingingCallbackName));
-                Callback_SessionListener_indicatedPtr ringingCB =
-                    newCallback_SessionListener_indicated(cb, &ListenerCallback::failure);
-                (*listener)->begin_indicated(session->getSessionProxy(), new RingingIndication(), ringingCB);
-            }
-            catch (const Ice::Exception &ex)
-            {
-                lg(Error) << "Ice exception when attempting to relate ringing state: " << ex.what();
-            }
-        }
-    }
-    else if (respCode == 183)
-    {
-        lg(Debug) << "Got 183 response";
-        AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response = new AsteriskSCF::SessionCommunications::V1::ResponseCode();
-        response->isdnCode = 42;
-        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
-        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
-        lg(Debug) << "Relating progressing state to " << listeners.size() << " listeners";
-        for (listener = listeners.begin(); listener != listeners.end(); ++listener)
-        {
-            try
-            {
-                ListenerCallbackPtr cb(new ListenerCallback(ProgressingCallbackName));
-                Callback_SessionListener_indicatedPtr progressingCB =
-                    newCallback_SessionListener_indicated(cb, &ListenerCallback::failure);
-		ProgressingIndicationPtr progressing(new ProgressingIndication());
-		progressing->response = response;
-                (*listener)->begin_indicated(session->getSessionProxy(), progressing, progressingCB);
-            }
-            catch (const Ice::Exception &ex)
-            {
-                lg(Error) << "Ice exception when attempting to relate progressing state: " << ex.what();
-            }
-        }
-    }
-    else if (respCode == 200)
-    {
-        lg(Debug) << "Got 200 response";
-        if (inv->state != PJSIP_INV_STATE_DISCONNECTED)
-        {
-            std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
-            std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
-            lg(Debug) << "Relating connected state to " << listeners.size() << " listeners";
-            for (listener = listeners.begin(); listener != listeners.end(); ++listener)
-            {
-                try
-                {
-                    ListenerCallbackPtr cb(new ListenerCallback(ConnectedCallbackName));
-                    Callback_SessionListener_indicatedPtr connectedCB =
-                        newCallback_SessionListener_indicated(cb, &ListenerCallback::failure);
-                    (*listener)->begin_indicated(session->getSessionProxy(), new ConnectedIndication(), connectedCB);
-                }
-                catch (const Ice::Exception &ex)
-                {
-                    lg(Error) << "Ice exception when attempting to relate connected state: " << ex.what();
-                }
-            }
-        }
-    }
-}
-
-void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *event)
-{
-    if ((inv->state == PJSIP_INV_STATE_EARLY || inv->state == PJSIP_INV_STATE_CONNECTING) &&
-        event->type == PJSIP_EVENT_TSX_STATE &&
-        inv->role == PJSIP_ROLE_UAC)
-    {
-        //Received a 1XX or 2XX message in response to our initial outgoing INVITE.
-        handleInviteResponse(inv, event->body.tsx_state.src.rdata, inv->dlg);
-    }
-    if (inv->state == PJSIP_INV_STATE_DISCONNECTED)
-    {
-        PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
-        if (session_mod_info == 0)
-        {
-            return;
-        }
-        SipSessionPtr session = session_mod_info->getSessionPtr();
-        AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response =
-            new AsteriskSCF::SessionCommunications::V1::ResponseCode();
-        if (inv->cause == 486)
-        {
-            response->isdnCode = 17;
-        }
-        else if (PJSIP_IS_STATUS_IN_CLASS(inv->cause, 500))
-        {
-            response->isdnCode = 34;
-        }
-        else
-        {
-            // TODO: See what cause is on a normal call completion
-            response->isdnCode = 0;
-        }
-        std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
-        lg(Debug) << "Relating stopped state to " << listeners.size() << " listeners";
-	AsteriskSCF::SessionCommunications::V1::StoppedIndicationPtr stopped(new AsteriskSCF::SessionCommunications::V1::StoppedIndication());
-	stopped->response = response;
-        for (std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::iterator listener =
-                 listeners.begin();
-             listener != listeners.end();
-             ++listener)
-        {
-            try
-            {
-                (*listener)->indicated(session->getSessionProxy(), stopped);
-            }
-            catch (const Ice::Exception &ex)
-            {
-                lg(Error) << "Ice exception when attempting to relate stopped state: " << ex.what();
-            }
-        }
-        session_mod_info->mNeedsRemoval = true;
-        pjsip_dialog *dlg = inv->dlg;
-        PJSipDialogModInfo *dlg_mod_info = (PJSipDialogModInfo*) dlg->mod_data[mModule.id];
-	if (dlg_mod_info)
-	{
-	    dlg_mod_info->mNeedsRemoval = true;
-	}
-        lg(Debug) << "Replicating state on DISCONNECTED inv_state.";
-        replicateState(dlg_mod_info, NULL, session_mod_info);
-        delete session_mod_info;
-	inv->mod_data[mModule.id] = 0;
-	if (dlg_mod_info)
-	{
-	    delete dlg_mod_info;
-	    dlg->mod_data[mModule.id] = 0;
-	}
-    }
-    if (event->type == PJSIP_EVENT_RX_MSG && inv->state == PJSIP_INV_STATE_CONFIRMED)
-    {
-        //We received an ACK for our 2XX response.
-        //See comment in invOnTransactionStateChanged() for explanation of this.
-
-        PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(inv->mod_data[mModule.id]);
-        if (session_mod_info)
-        {
-            session_mod_info->updateSessionState(inv);
-        }
-        replicateState(NULL, NULL, session_mod_info);
-
-        //Compare branches to see if this got handled by the transaction layer.
-        if (inv->invite_tsx &&
-                pj_strcmp(&event->body.rx_msg.rdata->msg_info.via->branch_param, &inv->invite_tsx->branch) != 0)
-        {
-            //Mismatched branch!
-            invOnTsxStateChanged(inv, inv->invite_tsx, event);
-        }
-    }
-    if (event->type == PJSIP_EVENT_TSX_STATE && inv->state == PJSIP_INV_STATE_CALLING && inv->role == PJSIP_ROLE_UAC)
-    {
-        //We have sent an INVITE out. We need to set up the transaction and dialog structures
-        //to have the appropriate mod_data and initiate some state replication here as well.
-        //The inv_session's mod_info was set up in SipSession::start() because we had the SipSession
-        //information there.
-        PJSipDialogModInfo *dlg_mod_info = new PJSipDialogModInfo(inv->dlg);
-        PJSipTransactionModInfo *tsx_mod_info = new PJSipTransactionModInfo(inv->invite_tsx);
-        PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo *>(inv->mod_data[mModule.id]);
-        inv->invite_tsx->mod_data[mModule.id] = (void *) tsx_mod_info;
-        inv->dlg->mod_data[mModule.id] = (void *) dlg_mod_info;
-        dlg_mod_info->mDialogState->mSessionId = session_mod_info->mSessionState->mSessionId;
-        tsx_mod_info->mTransactionState->mSessionId = session_mod_info->mSessionState->mSessionId;
-        lg(Debug) << "Replicating state on new outbound INVITE.";
-        replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
-    }
-}
-
-void PJSipSessionModule::invOnNewSession(pjsip_inv_session*, pjsip_event*)
-{
-    //stub
-}
-
-void PJSipSessionModule::invOnTsxStateChanged(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e)
-{
-    if (tsx->role == PJSIP_ROLE_UAS && tsx->state == PJSIP_TSX_STATE_TRYING &&
-            !pjsip_method_cmp(&tsx->method, pjsip_get_refer_method()))
-    {
-        handleRefer(inv, e->body.tsx_state.src.rdata);
-    }
-    //This will be our key point for updating transaction state.  This function will not be called until after a module
-    //has registered itself as the transaction user, so this won't be called on the initial INVITE we receive.
-    //
-    //Having taken a look at the pjsip inv_session code, the transaction state changed callback is called *after* the
-    //inv_state_changed callback. This means that on both reception and transmission of requests, this is called last,
-    //meaning this is the prime spot to do state replication of dialogs, transactions, sessions.
-    //
-    //There is one exception. If we receive an ACK for an INVITE transaction and the ACK has a different Via branch
-    //parameter than the INVITE and its response, then this callback will not be called at all, and we will need to
-    //perform the proper state replication in the invOnStateChanged function. This can be done simply by calling this
-    //function from there.
-
-    PJSipTransactionModInfo *tsx_mod_info = static_cast<PJSipTransactionModInfo *> (tsx->mod_data[mModule.id]);
-    // TODO: Determine if this is perfectly acceptable, since it occurs when the call is going bye bye
-    if (!tsx_mod_info)
-    {
-        return;
-    }
-    if (tsx->state != PJSIP_TSX_STATE_DESTROYED)
-    {
-        tsx_mod_info->updateTransactionState(tsx);
-    }
-    else
-    {
-        tsx_mod_info->mNeedsRemoval = true;
-    }
-    if (e->type == PJSIP_EVENT_TSX_STATE)
-    {
-        pjsip_dialog *dlg = pjsip_tsx_get_dlg(tsx);
-        PJSipDialogModInfo *dlg_mod_info = NULL;
-        if (dlg)
-        {
-            dlg_mod_info = static_cast<PJSipDialogModInfo*>(dlg->mod_data[mModule.id]);
-            if (dlg_mod_info)
-            {
-                dlg_mod_info->updateDialogState(dlg);
-            }
-        }
-        PJSipSessionModInfo *session_mod_info = static_cast<PJSipSessionModInfo*>(inv->mod_data[mModule.id]);
-        if (session_mod_info)
-        {
-            session_mod_info->updateSessionState(inv);
-        }
-        lg(Debug) << "Replicating state on transaction state change to " << tsx->state;
-        replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
-    }
-    else if (e->type == PJSIP_EVENT_TIMER)
-    {
-        lg(Debug) << "Replicating state on transaction state change to " << tsx->state;
-        replicateState(NULL, tsx_mod_info, NULL);
-    }
-}
-
-void PJSipSessionModule::invOnRxOffer(pjsip_inv_session* inv, const pjmedia_sdp_session*)
-{
-    PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
-    pjsip_inv_set_sdp_answer(inv, session_mod_info->getSessionPtr()->createSDPOffer());
-}
-
-void PJSipSessionModule::invOnCreateOffer(pjsip_inv_session*, pjmedia_sdp_session**)
-{
-    //stub
-}
-
-void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t status)
-{
-    if (status != PJ_SUCCESS)
-    {
-        // We have nothing, zip, nada, kablamo, in common.
-        return;
-    }
-
-    const pjmedia_sdp_session *remote_sdp;
-    if ((status = pjmedia_sdp_neg_get_active_remote(inv->neg, &remote_sdp)) != PJ_SUCCESS)
-    {
-        // TODO: What happens if we can't get negotiated SDP?
-        return;
-    }
-
-    const pjmedia_sdp_conn *remote_conn = remote_sdp->media[0]->conn ? remote_sdp->media[0]->conn : remote_sdp->conn;
-
-    PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
-    SipSessionPtr session = session_mod_info->getSessionPtr();
-    std::string destination(pj_strbuf(&remote_conn->addr), pj_strlen(&remote_conn->addr));
-    session->setRemoteDetails(destination, remote_sdp->media[0]->desc.port);
-
-    // Each stream has its own set of formats, so go to that granularity
-    for (unsigned int stream = 0; stream < remote_sdp->media_count; stream++)
-    {
-        // We should have the parsing of the connection information here
-
-        // We should have the parsing of the rtcp attribute here
-
-        FormatSeq formats;
-
-        // Next step is to see what formats exist on this stream
-        for (unsigned int format = 0; format < remote_sdp->media[stream]->desc.fmt_count; format++)
-        {
-            FormatDiscoverySDPPtr params = new FormatDiscoverySDP();
-            params->category = "media_format";
-            std::stringstream(pj_strbuf(&remote_sdp->media[stream]->desc.fmt[format])) >> params->payload;
-            params->type = std::string(pj_strbuf(&remote_sdp->media[stream]->desc.media),
-                    pj_strlen(&remote_sdp->media[stream]->desc.media));
-
... 1866 lines suppressed ...


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list