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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Oct 8 08:45:50 CDT 2010


branch "master" has been updated
       via  d35013e16d1cb5439fb1995f39115c462d99ae93 (commit)
       via  bc1c1c3629ae4bac27f63d4461d8f439bb96d1b2 (commit)
       via  81bfa16e8f0890868e9d2839d6fbdf3270aa685a (commit)
      from  50459f2ed91c10efb5aa802126981cfdeb4beff8 (commit)

Summary of changes:
 .gitmodules                             |    3 +
 CMakeLists.txt                          |    3 +
 cmake                                   |    2 +-
 logger                                  |    1 +
 slice                                   |    2 +-
 src/CMakeLists.txt                      |   10 +
 src/PJSipManager.cpp                    |  158 +++---
 src/PJSipModule.cpp                     |   62 ++-
 src/PJSipSessionModule.cpp              |  914 ++++++++++++++++---------------
 src/SipChannelServiceApp.cpp            |  226 ++++----
 src/SipChannelServiceEventPublisher.cpp |   51 +-
 src/SipEndpoint.cpp                     |  194 ++++----
 src/SipSession.cpp                      |   10 +-
 src/SipStateReplicatorApp.cpp           |  132 +++--
 14 files changed, 930 insertions(+), 838 deletions(-)
 create mode 160000 logger


- Log -----------------------------------------------------------------
commit d35013e16d1cb5439fb1995f39115c462d99ae93
Author: David M. Lee <dlee at digium.com>
Date:   Wed Oct 6 09:00:55 2010 -0500

    Logger integration

diff --git a/.gitmodules b/.gitmodules
index 841f83c..a628faf 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,6 @@
 [submodule "slice"]
 	path = slice
 	url = ../../integration/slice
+[submodule "logger"]
+	path = logger
+	url = git at git.asterisk.org:asterisk-scf/integration/logger
diff --git a/CMakeLists.txt b/CMakeLists.txt
index efa5881..bc34139 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,6 +31,9 @@ if(NOT integrated_build STREQUAL "true")
    # Pull in the slice definitions
    add_subdirectory(slice)
 
+   # logger is integrated into our build
+   set(integrated_build true)
+   add_subdirectory(logger)
 endif()
 
 # Include the subdirectory information. This is separate so that
diff --git a/logger b/logger
new file mode 160000
index 0000000..a867306
--- /dev/null
+++ b/logger
@@ -0,0 +1 @@
+Subproject commit a867306cbc5dce5b0cd899094b3215921f0263d3
diff --git a/slice b/slice
index 36a57a4..0c62939 160000
--- a/slice
+++ b/slice
@@ -1 +1 @@
-Subproject commit 36a57a423c849ff5688d8c4f3569bf3639feed36
+Subproject commit 0c629393e2f05dc0ed43bcc6305880949df36289
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d08b85b..beabb3b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -40,8 +40,17 @@ hydra_component_add_file(SipChannelService SipStateReplicator.h)
 hydra_component_add_ice_libraries(SipChannelService IceStorm)
 
 hydra_component_add_boost_libraries(SipChannelService thread core)
+
+if(NOT logger_dir)
+   message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
+endif()
+include_directories(${logger_dir}/common)
+include_directories(${logger_dir}/client/src)
+
 hydra_component_build_icebox(SipChannelService)
 
+target_link_libraries(SipChannelService logging-client)
+
 pjproject_link(SipChannelService pjsip)
 pjproject_link(SipChannelService pjmedia)
 pjproject_link(SipChannelService pjlib-util)
@@ -71,5 +80,6 @@ hydra_component_add_file(SipStateReplicator SipStateReplicator.h)
 hydra_component_add_ice_libraries(SipStateReplicator IceStorm)
 
 hydra_component_build_icebox(SipStateReplicator)
+target_link_libraries(SipStateReplicator logging-client)
 
 #hydra_component_install(SipStateReplicator RUNTIME bin "Sip State Replicator" SipStateReplicator)
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 0f9bf44..ecc620f 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -5,9 +5,17 @@
  *
  * All rights reserved.
  */
-#include <iostream>
 
 #include "PJSipManager.h"
+#include "logger.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
+
 
 namespace AsteriskSCF
 {
@@ -33,7 +41,7 @@ PJSipManager::PJSipManager(Ice::PropertiesPtr props)
    pj_status_t status = pj_init();
    if (status != PJ_SUCCESS)
    {
-      std::cerr << "[ERROR] Failed to Initialize PJSIP" << std::endl;
+      lg(Error) << "Failed to Initialize PJSIP";
    }
    // The third parameter is just copied from
    // example code from PJLIB. This can be adjusted
@@ -44,13 +52,13 @@ PJSipManager::PJSipManager(Ice::PropertiesPtr props)
    mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
    if (!mMemoryPool)
    {
-      std::cerr << "[ERROR] Failed to create a memory pool" << std::endl;
+      lg(Error) << "Failed to create a memory pool";
    }
    status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
                              mEndpoint, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &mPjThread);
    if (status != PJ_SUCCESS)
    {
-      std::cerr << "[ERROR] Failed to create SIP maintenance thread" << std::endl;
+      lg(Error) << "Failed to create SIP maintenance thread";
    }
 }
 
@@ -97,7 +105,7 @@ bool PJSipManager::setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr pr
       status = pjsip_udp_transport_start(endpoint, &udpAddr.ipv4, NULL, 2, &mUdpTransport);
       if (status != PJ_SUCCESS)
       {
-         std::cerr << "[ERROR] Failed to create IPv4 UDP transport. DANG!" << std::endl;
+         lg(Error) << "Failed to create IPv4 UDP transport. DANG!";
       }
    }
    else if (udpAddr.addr.sa_family == pj_AF_INET6())
@@ -105,7 +113,7 @@ bool PJSipManager::setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr pr
       status = pjsip_udp_transport_start6(endpoint, &udpAddr.ipv6, NULL, 2, &mUdpTransport);
       if (status != PJ_SUCCESS)
       {
-         std::cerr << "[ERROR] Failed to create IPv4 UDP transport. DANG!" << std::endl;
+         lg(Error) << "Failed to create IPv4 UDP transport. DANG!";
       }
    }
    //XXX Note that TCP and TLS stuff should be done here. Also note that
diff --git a/src/PJSipModule.cpp b/src/PJSipModule.cpp
index e214aa5..1f39586 100644
--- a/src/PJSipModule.cpp
+++ b/src/PJSipModule.cpp
@@ -8,6 +8,14 @@
 
 #include <IceUtil/UUID.h>
 #include "PJSipModule.h"
+#include "logger.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
 
 namespace AsteriskSCF
 {
@@ -131,9 +139,9 @@ TransactionState PJSipTransactionModInfo::transactionStateTranslate(pjsip_tsx_st
          retState = TransactionStateDestroyed;
  	 break;
       default:
-         std::cerr << "[ERROR] Unknown PJSIP Transaction state encountered: " << state << std::endl;
- 	 retState = TransactionStateNull;
- 	 break;
+         lg(Error) << "Unknown PJSIP Transaction state encountered: " << state;
+         retState = TransactionStateNull;
+         break;
    }
    return retState;
 }
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 70e07da..08a7569 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -19,6 +19,14 @@
 #include "SipSession.h"
 #include "PJSipManager.h"
 #include "SipStateReplicator.h"
+#include "logger.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
 
 namespace AsteriskSCF
 {
@@ -119,7 +127,7 @@ InviteSessionState PJSipSessionModInfo::inviteStateTranslate(pjsip_inv_state sta
          retState = InviteSessionStateDisconnected;
          break;
       default:
-         std::cerr << "[WARNING] Unknwon PJSIP INVITE state encountered: " << state << std::endl;
+         lg(Warning) << "Unknwon PJSIP INVITE state encountered: " << state;
          retState = InviteSessionStateNull;
          break;
    }
@@ -132,63 +140,63 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
    SipStateItemSeq setItems;
    Ice::StringSeq removeItems;
 
-   std::cout << "========== Begin State Replication Dump ==========" << std::endl;
+   lg(Debug) << "========== Begin State Replication Dump ==========";
 
    if (dlgInfo)
    {
-      std::cout << "--- Begin Dialog " << dlgInfo->mDialogState->key << std::endl;
-      std::cout << "Callid: " << dlgInfo->mDialogState->mCallId << std::endl;
-      std::cout << "Is Dialog Established: " << dlgInfo->mDialogState->mIsDialogEstablished << std::endl;
-      std::cout << "Is Secure: " << dlgInfo->mDialogState->mIsSecure << std::endl;
-      std::cout << "Local CSeq: " << dlgInfo->mDialogState->mLocalCSeq << std::endl;
-      std::cout << "Local URI: " << dlgInfo->mDialogState->mLocalUri << std::endl;
-      std::cout << "Remote CSeq: " << dlgInfo->mDialogState->mRemoteCSeq << std::endl;
-      std::cout << "Remote URI: " << dlgInfo->mDialogState->mRemoteUri << std::endl;
-      std::cout << "Transport: " << dlgInfo->mDialogState->mTransport << std::endl;
-      std::cout << "UAC Has 2xx: " << dlgInfo->mDialogState->mUacHas2xx << std::endl;
-      std::cout << "Is Uac: " << dlgInfo->mDialogState->mIsUac << std::endl;
+      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)
       {
-         std::cout << "Removing dialog" << std::endl;
+         lg(Debug) << "Removing dialog";
          removeItems.push_back(dlgInfo->mDialogState->key);
       }
       else if (dlgInfo->mNeedsReplication == true)
       {
-         std::cout << "Replicating dialog" << std::endl;
+         lg(Debug) << "Replicating dialog";
          setItems.push_back(dlgInfo->mDialogState);
          dlgInfo->mNeedsReplication = false;
       }
-      std::cout << "--- End Dialog " << dlgInfo->mDialogState->key << std::endl;
+      lg(Debug) << "--- End Dialog " << dlgInfo->mDialogState->key;
    }
    if (sessionInfo)
    {
-      std::cout << "--- Begin Session " << sessionInfo->mSessionState->key << std::endl;
-      std::cout << "Endpoint name: " << sessionInfo->mSessionState->mEndpointName << std::endl;
-      std::cout << "Session object identity: " << sessionInfo->mSessionState->mSessionObjectId.name << std::endl;
-      std::cout << "Media session object identity: " << sessionInfo->mSessionState->mMediaSessionObjectId.name << std::endl;
-      std::cout << "Media session: " << sessionInfo->mSessionState->mMediaSession << std::endl;
-      std::cout << "--- Begin Invite Session " << sessionInfo->mInviteState->key << std::endl;
-      std::cout << "Current state: " << sessionInfo->mInviteState->mCurrentState << std::endl;
-      std::cout << "Cancelling: " << sessionInfo->mInviteState->mCancelling << std::endl;
-      std::cout << "Pending cancel: " << sessionInfo->mInviteState->mPendingCancel << std::endl;
-      std::cout << "Cause: " << sessionInfo->mInviteState->mCause << std::endl;
-      std::cout << "Cause text: " << sessionInfo->mInviteState->mCauseText << std::endl;
-      std::cout << "Notify: " << sessionInfo->mInviteState->mNotify << std::endl;
-      std::cout << "Last Ack CSeq: " << sessionInfo->mInviteState->mLastAckCseq << std::endl;
+      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) << "--- 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);
-         std::cout << "Removing session and invite session" << std::endl;
+         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;
-         std::cout << "Replicating session and invite session" << std::endl;
+         lg(Debug) << "Replicating session and invite session";
       }
-      std::cout << "--- End Session and Invite Session" << std::endl;
+      lg(Debug) << "--- End Session and Invite Session";
    }
    if (tsxInfo)
    {
@@ -202,7 +210,7 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
          tsxInfo->mNeedsReplication = false;
       }
    }
-   std::cout << "========== End State Replication Dump ==========" << std::endl;
+   lg(Debug) << "========== End State Replication Dump ==========";
    if (mReplica->isActive() == true)
    {
       if (setItems.size() != 0 && mStateReplicator)
@@ -270,7 +278,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
    //on the To header of the incoming Invite.
    if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS)
    {
-      std::cerr << "[WARNING] Unable to create UAS dialog on incoming INVITE" << std::endl;
+      lg(Warning) << "Unable to create UAS dialog on incoming INVITE";
       return;
    }
 
@@ -285,7 +293,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
    pjsip_inv_session *inv_session;
    if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS)
    {
-      std::cerr << "[WARNING] Unable to create INVITE session" << std::endl;
+      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);
@@ -297,14 +305,14 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
 
    if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
    {
-      std::cerr << "[WARNING] Failed to create 100 Trying response" << std::endl;
+      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)
    {
-      std::cerr << "[WARNING] Failed to send 100 Trying response" << std::endl;
+      lg(Warning) << "Failed to send 100 Trying response";
       pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
    }
 
@@ -314,12 +322,12 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
    {
       pjsip_sip_uri *sipFrom = (pjsip_sip_uri *)from;
       callerName = std::string(pj_strbuf(&sipFrom->user), pj_strlen(&sipFrom->user));
-      std::cerr << "[DEBUG] Got caller name " << callerName << std::endl;
+      lg(Debug) << "Got caller name " << callerName;
    }
    SipEndpointPtr caller = mEndpointFactory->findByName(callerName);
    if (caller == 0)
    {
-      std::cerr << "[WARNING] Unknown calling endpoint " << callerName << std::endl;
+      lg(Warning) << "Unknown calling endpoint " << callerName;
       pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
       pjsip_inv_send_msg(inv_session, tdata);
       return;
@@ -327,7 +335,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
    SipEndpointConfig &config = caller->getConfig();
    if (config.sessionConfig.callDirection != BOTH && config.sessionConfig.callDirection != INBOUND)
    {
-      std::cerr << "[WARNING] Caller " << callerName << " does not have permission to make inbound calls." << std::endl;
+      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;
@@ -342,7 +350,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
       //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));
-      std::cerr << "[DEBUG] Call is destined for " << destination << std::endl;
+      lg(Debug) << "Call is destined for " << destination;
    }
 
    SipSessionPtr session = caller->createSession(destination);
@@ -355,7 +363,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
    inv_session->mod_data[mModule.id] = (void *)session_mod_info;
    dlg->mod_data[mModule.id] = (void *)dlg_mod_info;
 
-   std::cerr << "[DEBUG] Replicating state on reception of new SIP INVITE." << std::endl;
+   lg(Debug) << "Replicating state on reception of new SIP INVITE.";
    replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
    try
    {
@@ -416,7 +424,7 @@ void PJSipSessionModule::handleRefer(pjsip_dialog *dlg, pjsip_rx_data *rdata)
    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
-   std::cout << "Doing a blind transfer to: " << target << std::endl;
+   lg(Debug) << "Doing a blind transfer to: " << target;
 
    // TODO: Actually... you know... do it
    pjsip_dlg_respond(dlg, rdata, 400, NULL, NULL, NULL);
@@ -434,7 +442,7 @@ pj_bool_t PJSipSessionModule::on_rx_request(pjsip_rx_data *rdata)
          }
          else
          {
-            std::cerr << "[WARNING] on_rx_request called back in mid-dialog?" << std::endl;
+            lg(Warning) << "on_rx_request called back in mid-dialog?";
          }
          break;
       case PJSIP_OTHER_METHOD:
@@ -495,11 +503,11 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
    if (respCode == 100)
    {
       //Not sure if PJSIP even bothers passing these up
-      std::cout << "[DEBUG] Got 100 response" << std::endl;
+      lg(Debug) << "Got 100 response";
    }
    else if (respCode == 180)
    {
-      std::cout << "[DEBUG] Got 180 response" << std::endl;
+      lg(Debug) << "Got 180 response";
       std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
       std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
       for (listener = listeners.begin(); listener != listeners.end(); ++listener)
@@ -509,7 +517,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
    }
    else if (respCode == 183)
    {
-      std::cout << "[DEBUG] Got 183 response" << std::endl;
+      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();
@@ -521,7 +529,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
    }
    else if (respCode == 200)
    {
-      std::cout << "[DEBUG] Got 200 response" << std::endl;
+      lg(Debug) << "Got 200 response";
       if (inv->state != PJSIP_INV_STATE_DISCONNECTED)
       {
          std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
@@ -576,7 +584,7 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
       pjsip_dialog *dlg = inv->dlg;
       PJSipDialogModInfo *dlg_mod_info = (PJSipDialogModInfo*) dlg->mod_data[mModule.id];
       dlg_mod_info->mNeedsRemoval = true;
-      std::cerr << "Replicating state on DISCONNECTED inv_state." << std::endl;
+      lg(Debug) << "Replicating state on DISCONNECTED inv_state.";
       replicateState(dlg_mod_info, NULL, session_mod_info);
       delete session_mod_info;
       delete dlg_mod_info;
@@ -608,7 +616,7 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
       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;
-      std::cerr << "Replicating state on new outbound INVITE." << std::endl;
+      lg(Debug) << "Replicating state on new outbound INVITE.";
       replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
    }
 }
@@ -672,12 +680,12 @@ void PJSipSessionModule::invOnTsxStateChanged(pjsip_inv_session *inv, pjsip_tran
       {
          session_mod_info->updateSessionState(inv);
       }
-      std::cerr << "[DEBUG] Replicating state on transaction state change to " << tsx->state << std::endl;
+      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)
    {
-      std::cerr << "[DEBUG] Replicating state on transaction state change to " << tsx->state << std::endl;
+      lg(Debug) << "Replicating state on transaction state change to " << tsx->state;
       replicateState(NULL, tsx_mod_info, NULL);
    }
 }
diff --git a/src/SipChannelServiceApp.cpp b/src/SipChannelServiceApp.cpp
index c9e86d1..6e2b107 100644
--- a/src/SipChannelServiceApp.cpp
+++ b/src/SipChannelServiceApp.cpp
@@ -21,6 +21,8 @@
 #include "BridgingIf.h"
 #include "SessionCommunicationsIf.h"
 #include "ReplicaIf.h"
+#include "IceLogger.h"
+#include "logger.h"
 
 #include "SipChannelServiceEventPublisher.h"
 #include "SipChannelServiceEndpointLocator.h"
@@ -36,8 +38,14 @@ using namespace AsteriskSCF::Core;
 using namespace AsteriskSCF::Core::Routing::V1;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::SessionCommunications;
 
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
+
 namespace AsteriskSCF
 {
 namespace SipChannelService
@@ -277,7 +285,7 @@ void SipChannelService::registerWithServiceLocator()
 
       if (mServiceLocatorManagement == 0)
       {
-         cout << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected." << endl;
+         lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected.";
          return;
       }
 
@@ -295,7 +303,7 @@ void SipChannelService::registerWithServiceLocator()
    }
    catch(...)
    {
-      cout << "Exception in " << mAppName << " registerWithServiceLocator()" << endl;
+      lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()";
    }
 }
 
@@ -366,7 +374,7 @@ void SipChannelService::locateStateReplicator()
    }
    catch (...)
    {
-      std::cout << "State replicator could not be found, operating without." << std::endl;
+      lg(Error) << "State replicator could not be found, operating without.";
    }
 }
 
@@ -419,7 +427,7 @@ void SipChannelService::deregisterFromServiceLocator()
    }
    catch(...)
    {
-      cout << "Had trouble in deregisterFromServiceLocator()." << endl;
+      lg(Error) << "Had trouble in deregisterFromServiceLocator().";
    }
 }
 
@@ -453,7 +461,7 @@ void SipChannelService::registerPJSipModules(pjsip_endpoint *endpt)
             mSessionRouter, mServiceLocator, mStateReplicator, mReplicaService);
       }
    }
-   std::cerr << "[DEBUG] Registered PJSIP modules" << std::endl;
+   lg(Debug) << "Registered PJSIP modules";
 }
 
 void SipChannelService::deregisterFromStateReplicator()
@@ -484,21 +492,21 @@ void SipChannelService::initialize(const std::string appName, const Ice::Communi
       id.properties = ic->getProperties();
 
       mCommunicator = Ice::initialize(id);
- 
+
       // Initialize PJSIP
       mPJSipManager = new PJSipManager(mCommunicator->getProperties());
-      std::cerr << "[DEBUG] Created PJSIP manager" << std::endl;
+      lg(Debug) << "Created PJSIP manager";
 
       // Create the global adapter.
       mGlobalAdapter = mCommunicator->createObjectAdapter("SipChannelServiceAdapter");
-      std::cerr << "[DEBUG] Created global object adapter" << std::endl;
+      lg(Debug) << "Created global object adapter";
 
       // Create the local adapter.
       mLocalAdapter = mCommunicator->createObjectAdapter("SipChannelServiceLocalAdapter");
-      std::cerr << "[DEBUG] Created local object adapter" << std::endl;
-     
+      lg(Debug) << "Created local object adapter";
+
       mEventPublisher.reset(new SipChannelServiceEventPublisher(mLocalAdapter));
-      std::cerr << "[DEBUG] Created SIP Channel Service event publisher" << std::endl;
+      lg(Debug) << "Created SIP Channel Service event publisher";
 
       // We're not actually registering with the service locator at this point, but
       // several components we create could really use the proxy, so we create
@@ -508,36 +516,36 @@ void SipChannelService::initialize(const std::string appName, const Ice::Communi
       // Create and publish our Replica interface support.
       mReplicaService = new ReplicaImpl(mLocalAdapter);
       mLocalAdapter->add(mReplicaService, mCommunicator->stringToIdentity(ReplicaServiceId));
-      std::cerr << "[DEBUG] Created SIP Replica Implementation" << std::endl;
+      lg(Debug) << "Created SIP Replica Implementation";
 
       mEndpointFactory.reset(new SipEndpointFactory(mGlobalAdapter, mPJSipManager, mServiceLocator, mReplicaService));
-      std::cerr << "[DEBUG] Created SIP endpoint factory" << std::endl;
+      lg(Debug) << "Created SIP endpoint factory";
 
       // Create and configure our Endpoint Locator.
       mEndpointLocator = new SipChannelServiceEndpointLocator(mEndpointFactory);
       mGlobalAdapter->add(mEndpointLocator, mCommunicator->stringToIdentity(EndpointLocatorObjectId));
-      std::cerr << "[DEBUG] Got proxy to endpoint locator" << std::endl;
+      lg(Debug) << "Got proxy to endpoint locator";
 
       // Create and publish our ComponentService interface support.
       mComponentService = new ComponentServiceImpl(*this);
       mLocalAdapter->add(mComponentService, mCommunicator->stringToIdentity(ComponentServiceId));
-      std::cerr << "[DEBUG] Added component service to object adapter" << std::endl;
+      lg(Debug) << "Added component service to object adapter";
 
       // Create and publish our state replicator listener interface.
       mReplicatorListener = new SipStateReplicatorListenerI(mEndpointFactory, mPJSipManager);
       mReplicatorListenerProxy = SipStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
-      std::cerr << "[DEBUG] Got proxy to SIP state replicator" << std::endl;
+      lg(Debug) << "Got proxy to SIP state replicator";
 
       mGlobalAdapter->activate();
       mLocalAdapter->activate();
-      std::cerr << "[DEBUG] Activated object adapters" << std::endl;
+      lg(Debug) << "Activated object adapters";
 
       configureEndpoints();
-      std::cerr << "[DEBUG] Endpoints configured" << std::endl;
+      lg(Debug) << "Endpoints configured";
    }
    catch(...)
    {
-      cout << "Major problems in " << mAppName << " initialization()" << endl;
+      lg(Critical) << "Major problems in " << mAppName << " initialization()";
    }
 }
 
diff --git a/src/SipChannelServiceEventPublisher.cpp b/src/SipChannelServiceEventPublisher.cpp
index 2a6010f..031f60b 100644
--- a/src/SipChannelServiceEventPublisher.cpp
+++ b/src/SipChannelServiceEventPublisher.cpp
@@ -10,9 +10,16 @@
 #include <IceStorm/IceStorm.h>
 
 #include "SipChannelServiceEventPublisher.h"
+#include "logger.h"
 
 using namespace ::std;
 using namespace ::AsteriskSCF::SIP::V1;
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
 
 namespace AsteriskSCF
 {
@@ -44,15 +51,15 @@ public:
 
          if(!topicManager)
          {
-            cerr <<  "Invalid proxy to IceStorm. Missing config for TopicManager.Proxy?" << endl;
+            lg(Error) <<  "Invalid proxy to IceStorm. Missing config for TopicManager.Proxy?";
             return;
          }
 
-         cout << "SipChannelServiceEventPublisher::initialize(): Got IceStorm proxy: TopicManager.Proxy" << endl;
+         lg(Debug) << "SipChannelServiceEventPublisher::initialize(): Got IceStorm proxy: TopicManager.Proxy";
       }
       catch(const IceUtil::Exception&)
       {
-         cout << "Can't get IceStorm TopicManager. Check config, and make sure IceStorm is running." << endl;
+         lg(Error) << "Can't get IceStorm TopicManager. Check config, and make sure IceStorm is running.";
          return;
       }
 
@@ -69,7 +76,7 @@ public:
          }
          catch(const IceStorm::TopicExists&)
          {
-            cerr << "Possible race condition creating IceStorm topic " << Event::TopicId << ". Suggest Restart!" << endl;
+            lg(Error) << "Possible race condition creating IceStorm topic " << Event::TopicId << ". Suggest Restart!";
             return;
          }
       }
@@ -87,7 +94,7 @@ public:
    {
       if (!mInitialized)
       {
-         cout << "Warning: Attempting to use SipChannelServiceEventPublisher in uninitialized state! IceStorm may be inaccessible." << endl;
+         lg(Error) << "Warning: Attempting to use SipChannelServiceEventPublisher in uninitialized state! IceStorm may be inaccessible.";
       }
 
       return mInitialized;
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 7f30a01..b8aedd5 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -14,6 +14,14 @@
 #include "PJSipManager.h"
 #include "SipEndpointFactory.h"
 #include "SipSession.h"
+#include "logger.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
 
 namespace AsteriskSCF
 {
@@ -85,7 +93,7 @@ SipEndpoint::SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEnd
    const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica)
    : mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replica))
 {
-   std::cout << "Constructing SIP endpoint " << name << std::endl;
+   lg(Debug) << "Constructing SIP endpoint " << name;
 
    mImplPriv->mEndpointProxy = AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::uncheckedCast(mImplPriv->mAdapter->addWithUUID(this));
 
@@ -116,7 +124,7 @@ void SipEndpoint::setTransportConfiguration(Ice::PropertyDict props)
       pj_cstr(&addr, IpAddress->second.c_str());
       if (pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &addr, &sockaddr) != PJ_SUCCESS)
       {
-         std::cerr << "[ERROR] Bad address specifier in transport configuration for SIP endpoint " << mImplPriv->mName << std::endl;
+         lg(Error) << "Bad address specifier in transport configuration for SIP endpoint " << mImplPriv->mName;
       }
       else
       {
@@ -153,7 +161,7 @@ void SipEndpoint::setSessionConfiguration(Ice::PropertyDict props)
       pj_cstr(&addr, address->second.c_str());
       if (pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &addr, &sockaddr) != PJ_SUCCESS)
       {
-         std::cerr << "[ERROR] Bad address specifier in session configuration for SIP endpoint " << mImplPriv->mName << std::endl;
+         lg(Error) << "Bad address specifier in session configuration for SIP endpoint " << mImplPriv->mName;
       }
       else
       {
@@ -182,7 +190,7 @@ Direction SipEndpointConfig::stringToDirection(std::string directionString)
    }
    else
    {
-      std::cerr << "[WARNING] Invalid direction " << directionString << " provided. Assuming 'None'" << std::endl;
+      lg(Warning) << "Invalid direction " << directionString << " provided. Assuming 'None'";
       return NONE;
    }
 }
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 2fe61d5..7e1ef67 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -13,6 +13,14 @@
 #include "SipEndpointFactory.h"
 #include "SipEndpoint.h"
 #include "SipSession.h"
+#include "logger.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
 
 namespace AsteriskSCF
 {
@@ -343,7 +351,7 @@ void SipSession::start(const Ice::Current&)
 		   userDefined ? "@" : "",
 		   config.transportConfig.address.c_str());
    remote_uri = pj_str(remote);
-   std::cerr << "[DEBUG] Sending new SIP INVITE to " << remote << std::endl;
+   lg(Debug) << "Sending new SIP INVITE to " << remote;
 
    // Create a UAC dialog for the outgoing call
    if ((pjsip_dlg_create_uac(pjsip_ua_instance(), &local_uri, &local_uri, &remote_uri, &remote_uri, &dialog)) != PJ_SUCCESS)
diff --git a/src/SipStateReplicatorApp.cpp b/src/SipStateReplicatorApp.cpp
index b64861b..369a5c0 100644
--- a/src/SipStateReplicatorApp.cpp
+++ b/src/SipStateReplicatorApp.cpp
@@ -15,13 +15,21 @@
 #include "ComponentServiceIf.h"
 #include "SipIf.h"
 #include "SipStateReplicator.h"
+#include "IceLogger.h"
+#include "logger.h"
 
 using namespace std;
 using namespace AsteriskSCF::Core;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::SipChannelService;
 
+namespace
+{
+Logger &lg = getLoggerFactory().getLogger("AsteriskSCF.SipChannelService");
+}
+
 class SipStateReplicatorService : public IceBox::Service
 {
 public:
@@ -44,6 +52,7 @@ private:
    ServiceLocatorManagementPrx mServiceLocatorManagement;
    Discovery::V1::ServiceManagementPrx mComponentServiceManagement;
    Discovery::V1::ServiceManagementPrx mStateReplicationManagement;
+   ConfiguredIceLoggerPtr mIceLogger;
    ComponentServicePtr mComponentService;
    SipStateReplicatorIPtr mStateReplicator;
 };
@@ -112,7 +121,7 @@ void SipStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
 
       if (mServiceLocatorManagement == 0)
       {
-         cout << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected." << endl;
+         lg(Error) << "Unable to obtain proxy to ServiceLocatorManagement interface. Check config file. This component can't be found until this is corrected." << endl;
          return;
       }
 
@@ -151,7 +160,7 @@ void SipStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
    }
    catch(...)
    {
-      cout << "Exception in " << mAppName << " registerWithServiceLocator()" << endl;
+      lg(Error) << "Exception in " << mAppName << " registerWithServiceLocator()" << endl;
    }
 }
 
@@ -168,13 +177,18 @@ void SipStateReplicatorService::deregisterFromServiceLocator()
    }
    catch(...)
    {
-      cout << "Had trouble in deregisterFromServiceLocator()." << endl;
+      lg(Error) << "Had trouble in deregisterFromServiceLocator()." << endl;
    }
 }
 
 void SipStateReplicatorService::initialize(const std::string appName, const Ice::CommunicatorPtr& ic)
 {
    mAdapter = ic->createObjectAdapter("SipStateReplicator");
+
+   // setup logging client
+   mIceLogger = createIceLogger(mAdapter);
+   getLoggerFactory().setLogOutput(mIceLogger->getLogger());
+
    mAppName = appName;
    // Create and publish our ComponentService interface support.
    mComponentService = new ComponentServiceImpl(*this);

commit bc1c1c3629ae4bac27f63d4461d8f439bb96d1b2
Author: David M. Lee <dlee at digium.com>
Date:   Wed Oct 6 08:58:21 2010 -0500

    Pretty-print

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 09edfba..0f9bf44 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -17,101 +17,101 @@ namespace SipChannelService
 
 static void *monitorThread(void *endpt)
 {
-	pjsip_endpoint *endpoint = static_cast<pjsip_endpoint *> (endpt);
-	for (;;)
-	{
-		// No timeout is a bad idea in the long run, but for now,
-		// let's just go with it.
-		pjsip_endpt_handle_events(endpoint, NULL);
-	}
+   pjsip_endpoint *endpoint = static_cast<pjsip_endpoint *> (endpt);
+   for (;;)
+   {
+      // No timeout is a bad idea in the long run, but for now,
+      // let's just go with it.
+      pjsip_endpt_handle_events(endpoint, NULL);
+   }
 
-	return NULL;
+   return NULL;
 }
 
 PJSipManager::PJSipManager(Ice::PropertiesPtr props)
 {
-	pj_status_t status = pj_init();
-	if (status != PJ_SUCCESS)
-	{
-		std::cerr << "[ERROR] Failed to Initialize PJSIP" << std::endl;
-	}
-	// The third parameter is just copied from
-	// example code from PJLIB. This can be adjusted
-	// if necessary.
-	pj_caching_pool_init(&mCachingPool, NULL, 1024 * 1024);
-	pjsip_endpt_create(&mCachingPool.factory, "SIP", &mEndpoint);
-	setTransports(mEndpoint, props);
-	mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
-	if (!mMemoryPool)
-	{
-		std::cerr << "[ERROR] Failed to create a memory pool" << std::endl;
-	}
-	status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
-			mEndpoint, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &mPjThread);
-	if (status != PJ_SUCCESS)
-	{
-		std::cerr << "[ERROR] Failed to create SIP maintenance thread" << std::endl;
-	}
+   pj_status_t status = pj_init();
+   if (status != PJ_SUCCESS)
+   {
+      std::cerr << "[ERROR] Failed to Initialize PJSIP" << std::endl;
+   }
+   // The third parameter is just copied from
+   // example code from PJLIB. This can be adjusted
+   // if necessary.
+   pj_caching_pool_init(&mCachingPool, NULL, 1024 * 1024);
+   pjsip_endpt_create(&mCachingPool.factory, "SIP", &mEndpoint);
+   setTransports(mEndpoint, props);
+   mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
+   if (!mMemoryPool)
+   {
+      std::cerr << "[ERROR] Failed to create a memory pool" << std::endl;
+   }
+   status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
+                             mEndpoint, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &mPjThread);
+   if (status != PJ_SUCCESS)
+   {
+      std::cerr << "[ERROR] Failed to create SIP maintenance thread" << std::endl;
+   }
 }
 
 void PJSipManager::registerSessionModule(pjsip_endpoint *endpt,
-	boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
-	AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouter,
-	AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
-	AsteriskSCF::SIP::V1::SipStateReplicatorPrx stateReplicator,
-	AsteriskSCF::System::Component::V1::ReplicaPtr replica
-	)
+   boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
+   AsteriskSCF::SessionCommunications::V1::SessionRouterPrx sessionRouter,
+   AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
+   AsteriskSCF::SIP::V1::SipStateReplicatorPrx stateReplicator,
+   AsteriskSCF::System::Component::V1::ReplicaPtr replica
+   )
 {
-	mSessionModule = new PJSipSessionModule(endpt, endpointFactoryPtr, sessionRouter,
-			serviceLocator, stateReplicator, replica);
+   mSessionModule = new PJSipSessionModule(endpt, endpointFactoryPtr, sessionRouter,
+      serviceLocator, stateReplicator, replica);
 }
 
 
 pjsip_endpoint *PJSipManager::getEndpoint()
 {
-	return mEndpoint;
+   return mEndpoint;
 }
 
 pjsip_module &PJSipManager::getSessionModule()
 {
-	return mSessionModule->getModule();
+   return mSessionModule->getModule();
 }
 
 bool PJSipManager::setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr props)
 {
-	//XXX We'll also want to allow for TCP and TLS-specific
-	//addresses to be specified.
-	pj_sockaddr udpAddr;
-	pj_status_t status;
-	std::string udpBindAddr = props->getPropertyWithDefault("Sip.Transport.UdpBindAddr", "0.0.0.0:5060");
-	pj_str_t udpString;
-	pj_cstr(&udpString, udpBindAddr.c_str());
-	//UNSPEC family means "you figure out the address family, pjlib!"
-	pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &udpString, &udpAddr);
-	if (udpAddr.addr.sa_family == pj_AF_INET())
-	{
-		//XXX The fourth parameter should probably be controlled through
-		//configuration. PJSIP reference says it should be the number of
-		//processors on the machine.
-		//
-		status = pjsip_udp_transport_start(endpoint, &udpAddr.ipv4, NULL, 2, &mUdpTransport);
-		if (status != PJ_SUCCESS)
-		{
-			std::cerr << "[ERROR] Failed to create IPv4 UDP transport. DANG!" << std::endl;
-		}
-	}
-	else if (udpAddr.addr.sa_family == pj_AF_INET6())
-	{
-		status = pjsip_udp_transport_start6(endpoint, &udpAddr.ipv6, NULL, 2, &mUdpTransport);
-		if (status != PJ_SUCCESS)
-		{
-			std::cerr << "[ERROR] Failed to create IPv4 UDP transport. DANG!" << std::endl;
-		}
-	}
-	//XXX Note that TCP and TLS stuff should be done here. Also note that
-	//currently PJSIP does not have functions for starting IPv6 TCP or
-	//TLS transports, so we'll have to modify the code to allow for it.
-	return true;
+   //XXX We'll also want to allow for TCP and TLS-specific
+   //addresses to be specified.
+   pj_sockaddr udpAddr;
+   pj_status_t status;
+   std::string udpBindAddr = props->getPropertyWithDefault("Sip.Transport.UdpBindAddr", "0.0.0.0:5060");
+   pj_str_t udpString;
+   pj_cstr(&udpString, udpBindAddr.c_str());
+   //UNSPEC family means "you figure out the address family, pjlib!"
+   pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &udpString, &udpAddr);
+   if (udpAddr.addr.sa_family == pj_AF_INET())
+   {
+      //XXX The fourth parameter should probably be controlled through
+      //configuration. PJSIP reference says it should be the number of
+      //processors on the machine.
+      //
+      status = pjsip_udp_transport_start(endpoint, &udpAddr.ipv4, NULL, 2, &mUdpTransport);
+      if (status != PJ_SUCCESS)
+      {
+         std::cerr << "[ERROR] Failed to create IPv4 UDP transport. DANG!" << std::endl;
+      }
+   }
+   else if (udpAddr.addr.sa_family == pj_AF_INET6())
+   {
+      status = pjsip_udp_transport_start6(endpoint, &udpAddr.ipv6, NULL, 2, &mUdpTransport);
+      if (status != PJ_SUCCESS)
+      {
+         std::cerr << "[ERROR] Failed to create IPv4 UDP transport. DANG!" << std::endl;
+      }
+   }
+   //XXX Note that TCP and TLS stuff should be done here. Also note that
+   //currently PJSIP does not have functions for starting IPv6 TCP or
+   //TLS transports, so we'll have to modify the code to allow for it.
+   return true;
 }
 
 }; //End namespace SipChannelService
diff --git a/src/PJSipModule.cpp b/src/PJSipModule.cpp
index 1d1a7ce..e214aa5 100644
--- a/src/PJSipModule.cpp
+++ b/src/PJSipModule.cpp
@@ -65,15 +65,15 @@ void PJSipDialogModInfo::updateDialogState(pjsip_dialog *dialog)
    mDialogState->mRouteSet.erase(mDialogState->mRouteSet.begin(), mDialogState->mRouteSet.end());
    for (pjsip_route_hdr *hdr_iter = dialog->route_set.next; hdr_iter != &dialog->route_set; hdr_iter = hdr_iter->next)
    {
- 	 char routeUri[URI_SIZE];
- 	 pjsip_uri_print(PJSIP_URI_IN_ROUTING_HDR, hdr_iter->name_addr.uri, routeUri, sizeof(routeUri));
+      char routeUri[URI_SIZE];
+      pjsip_uri_print(PJSIP_URI_IN_ROUTING_HDR, hdr_iter->name_addr.uri, routeUri, sizeof(routeUri));
 
       //XXX I need to see the order in which the route set is represented
- 	 //in a pjsip dialog. push_back could be completely incorrect here,
- 	 //or it may only be correct depending on whether we're the UAC or UAS.
- 	 //Also, for now we're ignoring the optional display name portion of URIs
- 	 //in the route set. They're not strictly necessary for routing calls correctly.
- 	 mDialogState->mRouteSet.push_back(routeUri);
+      //in a pjsip dialog. push_back could be completely incorrect here,
+      //or it may only be correct depending on whether we're the UAC or UAS.
+      //Also, for now we're ignoring the optional display name portion of URIs
+      //in the route set. They're not strictly necessary for routing calls correctly.
+      mDialogState->mRouteSet.push_back(routeUri);
    }
    //XXX I'm not 100% sure how to get the transport from a pjsip_dialog, so for now,
    //I'll just hardcode this as UDP until we start wanting to actually implement
@@ -106,32 +106,32 @@ TransactionState PJSipTransactionModInfo::transactionStateTranslate(pjsip_tsx_st
    TransactionState retState;
    switch (state)
    {
-   case PJSIP_TSX_STATE_NULL:
-      retState = TransactionStateNull;
+      case PJSIP_TSX_STATE_NULL:
+         retState = TransactionStateNull;
  	 break;
-   case PJSIP_TSX_STATE_CALLING:
-      retState = TransactionStateCalling;
+      case PJSIP_TSX_STATE_CALLING:
+         retState = TransactionStateCalling;
  	 break;
-   case PJSIP_TSX_STATE_TRYING:
-      retState = TransactionStateTrying;
+      case PJSIP_TSX_STATE_TRYING:
+         retState = TransactionStateTrying;
  	 break;
-   case PJSIP_TSX_STATE_PROCEEDING:
-      retState = TransactionStateProceeding;
+      case PJSIP_TSX_STATE_PROCEEDING:
+         retState = TransactionStateProceeding;
  	 break;
-   case PJSIP_TSX_STATE_COMPLETED:
-      retState = TransactionStateCompleted;
+      case PJSIP_TSX_STATE_COMPLETED:
+         retState = TransactionStateCompleted;
  	 break;
-   case PJSIP_TSX_STATE_CONFIRMED:
-      retState = TransactionStateConfirmed;
+      case PJSIP_TSX_STATE_CONFIRMED:
+         retState = TransactionStateConfirmed;
  	 break;
-   case PJSIP_TSX_STATE_TERMINATED:
-      retState = TransactionStateTerminated;
+      case PJSIP_TSX_STATE_TERMINATED:
+         retState = TransactionStateTerminated;
  	 break;
-   case PJSIP_TSX_STATE_DESTROYED:
-      retState = TransactionStateDestroyed;
+      case PJSIP_TSX_STATE_DESTROYED:
+         retState = TransactionStateDestroyed;
  	 break;
-   default:
-      std::cerr << "[ERROR] Unknown PJSIP Transaction state encountered: " << state << std::endl;
+      default:
+         std::cerr << "[ERROR] Unknown PJSIP Transaction state encountered: " << state << std::endl;
  	 retState = TransactionStateNull;
  	 break;
    }
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 66f3b3b..70e07da 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -33,8 +33,14 @@ using namespace AsteriskSCF::SessionCommunications::V1;
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::SIP::V1;
 
-PJSipSessionModInfo::PJSipSessionModInfo(pjsip_inv_session *inv_session, SipSessionPtr session) : mSessionState(new SipSessionStateItem), mInviteState(new SipInviteSessionStateItem), mNeedsReplication(true),
-									   mNeedsRemoval(false), mSession(session)
+PJSipSessionModInfo::PJSipSessionModInfo(pjsip_inv_session *inv_session,
+   SipSessionPtr session)
+   :
+   mSessionState(new SipSessionStateItem),
+   mInviteState(new SipInviteSessionStateItem),
+   mNeedsReplication(true),
+   mNeedsRemoval(false),
+   mSession(session)
 {
    mSessionState->key = IceUtil::generateUUID();
    mInviteState->key = IceUtil::generateUUID();
@@ -91,292 +97,292 @@ InviteSessionState PJSipSessionModInfo::inviteStateTranslate(pjsip_inv_state sta
    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:
-      std::cerr << "[WARNING] Unknwon PJSIP INVITE state encountered: " << state << std::endl;
-      retState = InviteSessionStateNull;
-      break;
+      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:
+         std::cerr << "[WARNING] Unknwon PJSIP INVITE state encountered: " << state << std::endl;
+         retState = InviteSessionStateNull;
+         break;
    }
    return retState;
 }
 
 void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransactionModInfo *tsxInfo,
-		PJSipSessionModInfo *sessionInfo)
+   PJSipSessionModInfo *sessionInfo)
 {
-	SipStateItemSeq setItems;
-	Ice::StringSeq removeItems;
-
-	std::cout << "========== Begin State Replication Dump ==========" << std::endl;
-
-	if (dlgInfo)
-	{
-		std::cout << "--- Begin Dialog " << dlgInfo->mDialogState->key << std::endl;
-		std::cout << "Callid: " << dlgInfo->mDialogState->mCallId << std::endl;
-		std::cout << "Is Dialog Established: " << dlgInfo->mDialogState->mIsDialogEstablished << std::endl;
-		std::cout << "Is Secure: " << dlgInfo->mDialogState->mIsSecure << std::endl;
-		std::cout << "Local CSeq: " << dlgInfo->mDialogState->mLocalCSeq << std::endl;
-		std::cout << "Local URI: " << dlgInfo->mDialogState->mLocalUri << std::endl;
-		std::cout << "Remote CSeq: " << dlgInfo->mDialogState->mRemoteCSeq << std::endl;
-		std::cout << "Remote URI: " << dlgInfo->mDialogState->mRemoteUri << std::endl;
-		std::cout << "Transport: " << dlgInfo->mDialogState->mTransport << std::endl;
-		std::cout << "UAC Has 2xx: " << dlgInfo->mDialogState->mUacHas2xx << std::endl;
-		std::cout << "Is Uac: " << dlgInfo->mDialogState->mIsUac << std::endl;
-		if (dlgInfo->mNeedsRemoval == true)
-		{
-			std::cout << "Removing dialog" << std::endl;
-			removeItems.push_back(dlgInfo->mDialogState->key);
-		}
-		else if (dlgInfo->mNeedsReplication == true)
-		{
-			std::cout << "Replicating dialog" << std::endl;
-			setItems.push_back(dlgInfo->mDialogState);
-			dlgInfo->mNeedsReplication = false;
-		}
-		std::cout << "--- End Dialog " << dlgInfo->mDialogState->key << std::endl;
-	}
-	if (sessionInfo)
-	{
-		std::cout << "--- Begin Session " << sessionInfo->mSessionState->key << std::endl;
-		std::cout << "Endpoint name: " << sessionInfo->mSessionState->mEndpointName << std::endl;
-		std::cout << "Session object identity: " << sessionInfo->mSessionState->mSessionObjectId.name << std::endl;
-		std::cout << "Media session object identity: " << sessionInfo->mSessionState->mMediaSessionObjectId.name << std::endl;
-		std::cout << "Media session: " << sessionInfo->mSessionState->mMediaSession << std::endl;
-		std::cout << "--- Begin Invite Session " << sessionInfo->mInviteState->key << std::endl;
-		std::cout << "Current state: " << sessionInfo->mInviteState->mCurrentState << std::endl;
-		std::cout << "Cancelling: " << sessionInfo->mInviteState->mCancelling << std::endl;
-		std::cout << "Pending cancel: " << sessionInfo->mInviteState->mPendingCancel << std::endl;
-		std::cout << "Cause: " << sessionInfo->mInviteState->mCause << std::endl;
-		std::cout << "Cause text: " << sessionInfo->mInviteState->mCauseText << std::endl;
-		std::cout << "Notify: " << sessionInfo->mInviteState->mNotify << std::endl;
-		std::cout << "Last Ack CSeq: " << sessionInfo->mInviteState->mLastAckCseq << std::endl;
-		if (sessionInfo->mNeedsRemoval == true)
-		{
-			removeItems.push_back(sessionInfo->mInviteState->key);
-			removeItems.push_back(sessionInfo->mSessionState->key);
-			std::cout << "Removing session and invite session" << std::endl;
-		}
-		else if (sessionInfo->mNeedsReplication == true)
-		{
-			setItems.push_back(sessionInfo->mInviteState);
-			setItems.insert(setItems.begin(), sessionInfo->mSessionState);
-			sessionInfo->mNeedsReplication = false;
-			std::cout << "Replicating session and invite session" << std::endl;
-		}
-		std::cout << "--- End Session and Invite Session" << std::endl;
-	}
-	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;
-		}
-	}
-	std::cout << "========== End State Replication Dump ==========" << std::endl;
-	if (mReplica->isActive() == true)
-	{
-	   if (setItems.size() != 0 && mStateReplicator)
-	   {
-	      mStateReplicator->setState(setItems);
-	   }
-	   if (removeItems.size() != 0 && mStateReplicator)
-	   {
-	      mStateReplicator->removeState(removeItems);
-	   }
-	}
+   SipStateItemSeq setItems;
+   Ice::StringSeq removeItems;
+
+   std::cout << "========== Begin State Replication Dump ==========" << std::endl;
+
+   if (dlgInfo)
+   {
+      std::cout << "--- Begin Dialog " << dlgInfo->mDialogState->key << std::endl;
+      std::cout << "Callid: " << dlgInfo->mDialogState->mCallId << std::endl;
+      std::cout << "Is Dialog Established: " << dlgInfo->mDialogState->mIsDialogEstablished << std::endl;
+      std::cout << "Is Secure: " << dlgInfo->mDialogState->mIsSecure << std::endl;
+      std::cout << "Local CSeq: " << dlgInfo->mDialogState->mLocalCSeq << std::endl;
+      std::cout << "Local URI: " << dlgInfo->mDialogState->mLocalUri << std::endl;
+      std::cout << "Remote CSeq: " << dlgInfo->mDialogState->mRemoteCSeq << std::endl;
+      std::cout << "Remote URI: " << dlgInfo->mDialogState->mRemoteUri << std::endl;
+      std::cout << "Transport: " << dlgInfo->mDialogState->mTransport << std::endl;
+      std::cout << "UAC Has 2xx: " << dlgInfo->mDialogState->mUacHas2xx << std::endl;
+      std::cout << "Is Uac: " << dlgInfo->mDialogState->mIsUac << std::endl;
+      if (dlgInfo->mNeedsRemoval == true)
+      {
+         std::cout << "Removing dialog" << std::endl;
+         removeItems.push_back(dlgInfo->mDialogState->key);
+      }
+      else if (dlgInfo->mNeedsReplication == true)
+      {
+         std::cout << "Replicating dialog" << std::endl;
+         setItems.push_back(dlgInfo->mDialogState);
+         dlgInfo->mNeedsReplication = false;
+      }
+      std::cout << "--- End Dialog " << dlgInfo->mDialogState->key << std::endl;
+   }
+   if (sessionInfo)
+   {
+      std::cout << "--- Begin Session " << sessionInfo->mSessionState->key << std::endl;
+      std::cout << "Endpoint name: " << sessionInfo->mSessionState->mEndpointName << std::endl;
+      std::cout << "Session object identity: " << sessionInfo->mSessionState->mSessionObjectId.name << std::endl;
+      std::cout << "Media session object identity: " << sessionInfo->mSessionState->mMediaSessionObjectId.name << std::endl;
+      std::cout << "Media session: " << sessionInfo->mSessionState->mMediaSession << std::endl;
+      std::cout << "--- Begin Invite Session " << sessionInfo->mInviteState->key << std::endl;
+      std::cout << "Current state: " << sessionInfo->mInviteState->mCurrentState << std::endl;
+      std::cout << "Cancelling: " << sessionInfo->mInviteState->mCancelling << std::endl;
+      std::cout << "Pending cancel: " << sessionInfo->mInviteState->mPendingCancel << std::endl;
+      std::cout << "Cause: " << sessionInfo->mInviteState->mCause << std::endl;
+      std::cout << "Cause text: " << sessionInfo->mInviteState->mCauseText << std::endl;
+      std::cout << "Notify: " << sessionInfo->mInviteState->mNotify << std::endl;
+      std::cout << "Last Ack CSeq: " << sessionInfo->mInviteState->mLastAckCseq << std::endl;
+      if (sessionInfo->mNeedsRemoval == true)
+      {
+         removeItems.push_back(sessionInfo->mInviteState->key);
+         removeItems.push_back(sessionInfo->mSessionState->key);
+         std::cout << "Removing session and invite session" << std::endl;
+      }
+      else if (sessionInfo->mNeedsReplication == true)
+      {
+         setItems.push_back(sessionInfo->mInviteState);
+         setItems.insert(setItems.begin(), sessionInfo->mSessionState);
+         sessionInfo->mNeedsReplication = false;
+         std::cout << "Replicating session and invite session" << std::endl;
+      }
+      std::cout << "--- End Session and Invite Session" << std::endl;
+   }
+   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;
+      }
+   }
+   std::cout << "========== End State Replication Dump ==========" << std::endl;
+   if (mReplica->isActive() == true)
+   {
+      if (setItems.size() != 0 && mStateReplicator)
+      {
+         mStateReplicator->setState(setItems);
+      }
+      if (removeItems.size() != 0 && mStateReplicator)
+      {
+         mStateReplicator->removeState(removeItems);
+      }
+   }
 }
 
 pj_status_t PJSipSessionModule::load(pjsip_endpoint *endpt)
 {
-	return PJ_SUCCESS;
+   return PJ_SUCCESS;
 }
 
 pj_status_t PJSipSessionModule::start()
 {
-	return PJ_SUCCESS;
+   return PJ_SUCCESS;
 }
 
 pj_status_t PJSipSessionModule::stop()
 {
-	return PJ_SUCCESS;
+   return PJ_SUCCESS;
 }
 
 pj_status_t PJSipSessionModule::unload()
 {
-	return PJ_SUCCESS;
+   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.
+   //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!
+   //XXX Put caller identification code in here!
 	
-	//XXX According to pjsip docs, we should call
-	//pjsip_inv_verify_request to be sure we can
-	//handle the request. For now, just plunge forward.
+   //XXX According to pjsip docs, we should call
+   //pjsip_inv_verify_request to be sure we can
+   //handle the request. For now, just plunge forward.
 	
-	pjsip_dialog *dlg, *replaced_dlg;
-	pjsip_tx_data *tdata;
-
-	// 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)
-	{
-	   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)
-	{
-		std::cerr << "[WARNING] Unable to create UAS dialog on incoming INVITE" << std::endl;
-		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)
-	{
-		std::cerr << "[WARNING] Unable to create INVITE session" << std::endl;
-		//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);
-
-	if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
-	{
-		std::cerr << "[WARNING] Failed to create 100 Trying response" << std::endl;
-		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
-		return;
-	}
-
-	if (pjsip_inv_send_msg(inv_session, tdata) != PJ_SUCCESS)
-	{
-		std::cerr << "[WARNING] Failed to send 100 Trying response" << std::endl;
-		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 *)from;
-		callerName = std::string(pj_strbuf(&sipFrom->user), pj_strlen(&sipFrom->user));
-		std::cerr << "[DEBUG] Got caller name " << callerName << std::endl;
-	}
-	SipEndpointPtr caller = mEndpointFactory->findByName(callerName);
-	if (caller == 0)
-	{
-		std::cerr << "[WARNING] Unknown calling endpoint " << callerName << std::endl;
-		pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
-		pjsip_inv_send_msg(inv_session, tdata);
-		return;
-	}
-	SipEndpointConfig &config = caller->getConfig();
-	if (config.sessionConfig.callDirection != BOTH && config.sessionConfig.callDirection != INBOUND)
-	{
-		std::cerr << "[WARNING] Caller " << callerName << " does not have permission to make inbound calls." << std::endl;
-		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 *)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));
-		std::cerr << "[DEBUG] Call is destined for " << destination << std::endl;
-	}
-
-	SipSessionPtr session = caller->createSession(destination);
-	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;
-
-	std::cerr << "[DEBUG] Replicating state on reception of new SIP INVITE." << std::endl;
-	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
-	      mSessionRouter->routeSession(session->getSessionProxy(), destination);
-	   }
-	}
-	catch (AsteriskSCF::Core::Routing::V1::DestinationNotFoundException&)
-	{
-	   // Destination not found is special since we can actually map it to a good response code, 404
-	   pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
-		pjsip_inv_send_msg(inv_session, tdata);
-	   return;
-	}
-	catch (...)
-	{
-	   // 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;
-	}
+   pjsip_dialog *dlg, *replaced_dlg;
+   pjsip_tx_data *tdata;
+
+   // 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)
+   {
+      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)
+   {
+      std::cerr << "[WARNING] Unable to create UAS dialog on incoming INVITE" << std::endl;
+      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)
+   {
+      std::cerr << "[WARNING] Unable to create INVITE session" << std::endl;
+      //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);
+
+   if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
+   {
+      std::cerr << "[WARNING] Failed to create 100 Trying response" << std::endl;
+      pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+      return;
+   }
+
+   if (pjsip_inv_send_msg(inv_session, tdata) != PJ_SUCCESS)
+   {
+      std::cerr << "[WARNING] Failed to send 100 Trying response" << std::endl;
+      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 *)from;
+      callerName = std::string(pj_strbuf(&sipFrom->user), pj_strlen(&sipFrom->user));
+      std::cerr << "[DEBUG] Got caller name " << callerName << std::endl;
+   }
+   SipEndpointPtr caller = mEndpointFactory->findByName(callerName);
+   if (caller == 0)
+   {
+      std::cerr << "[WARNING] Unknown calling endpoint " << callerName << std::endl;
+      pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
+      pjsip_inv_send_msg(inv_session, tdata);
+      return;
+   }
+   SipEndpointConfig &config = caller->getConfig();
+   if (config.sessionConfig.callDirection != BOTH && config.sessionConfig.callDirection != INBOUND)
+   {
+      std::cerr << "[WARNING] Caller " << callerName << " does not have permission to make inbound calls." << std::endl;
+      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 *)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));
+      std::cerr << "[DEBUG] Call is destined for " << destination << std::endl;
+   }
+
+   SipSessionPtr session = caller->createSession(destination);
+   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;
+
+   std::cerr << "[DEBUG] Replicating state on reception of new SIP INVITE." << std::endl;
+   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
+         mSessionRouter->routeSession(session->getSessionProxy(), destination);
+      }
+   }
+   catch (AsteriskSCF::Core::Routing::V1::DestinationNotFoundException&)
+   {
+      // Destination not found is special since we can actually map it to a good response code, 404
+      pjsip_inv_end_session(inv_session, 404, NULL, &tdata);
+      pjsip_inv_send_msg(inv_session, tdata);
+      return;
+   }
+   catch (...)
+   {
+      // 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_dialog *dlg, pjsip_rx_data *rdata)
@@ -418,30 +424,30 @@ void PJSipSessionModule::handleRefer(pjsip_dialog *dlg, pjsip_rx_data *rdata)
 
 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_INVITE_METHOD:
-		if (dlg == NULL)
-		{
-			handleNewInvite(rdata);
-		}
-		else
-		{
-			std::cerr << "[WARNING] on_rx_request called back in mid-dialog?" << std::endl;
-		}
-		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:
-		return PJ_FALSE;
-	}
-
-	return PJ_TRUE;
+   pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
+   switch (rdata->msg_info.msg->line.req.method.id)
+   {
+      case PJSIP_INVITE_METHOD:
+         if (dlg == NULL)
+         {
+            handleNewInvite(rdata);
+         }
+         else
+         {
+            std::cerr << "[WARNING] on_rx_request called back in mid-dialog?" << std::endl;
+         }
+         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:
+         return PJ_FALSE;
+   }
+
+   return PJ_TRUE;
 }
 
 /* The following four member functions are all stubbed out because they
@@ -452,164 +458,164 @@ pj_bool_t PJSipSessionModule::on_rx_request(pjsip_rx_data *rdata)
  */
 pj_bool_t PJSipSessionModule::on_rx_response(pjsip_rx_data *rdata)
 {
-	return PJ_FALSE;
+   return PJ_FALSE;
 }
 pj_status_t PJSipSessionModule::on_tx_request(pjsip_tx_data *tdata)
 {
-	return PJ_SUCCESS;
+   return PJ_SUCCESS;
 }
 pj_status_t PJSipSessionModule::on_tx_response(pjsip_tx_data *tdata)
 {
-	return PJ_SUCCESS;
+   return PJ_SUCCESS;
 }
 void PJSipSessionModule::on_tsx_state(pjsip_transaction *tsx, pjsip_event *e)
 {
-	return;
+   return;
 }
 
 void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
-		pjsip_rx_data *rdata, pjsip_dialog *dlg)
+   pjsip_rx_data *rdata, pjsip_dialog *dlg)
 {
-	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
-		std::cout << "[DEBUG] Got 100 response" << std::endl;
-	}
-	else if (respCode == 180)
-	{
-		std::cout << "[DEBUG] Got 180 response" << std::endl;
-		std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
-		std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
-		for (listener = listeners.begin(); listener != listeners.end(); ++listener)
-		{
-		   (*listener)->ringing(session->getSessionProxy());
-		}
-	}
-	else if (respCode == 183)
-	{
-		std::cout << "[DEBUG] Got 183 response" << std::endl;
-		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;
-		for (listener = listeners.begin(); listener != listeners.end(); ++listener)
-		{
-		   (*listener)->progressing(session->getSessionProxy(), response);
-		}
-	}
-	else if (respCode == 200)
-	{
-		std::cout << "[DEBUG] Got 200 response" << std::endl;
-		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;
-		   for (listener = listeners.begin(); listener != listeners.end(); ++listener)
-		   {
-		      (*listener)->connected(session->getSessionProxy());
-		   }
-		}
-	}
+   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
+      std::cout << "[DEBUG] Got 100 response" << std::endl;
+   }
+   else if (respCode == 180)
+   {
+      std::cout << "[DEBUG] Got 180 response" << std::endl;
+      std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>& listeners = session->getListeners();
+      std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::const_iterator listener;
+      for (listener = listeners.begin(); listener != listeners.end(); ++listener)
+      {
+         (*listener)->ringing(session->getSessionProxy());
+      }
+   }
+   else if (respCode == 183)
+   {
+      std::cout << "[DEBUG] Got 183 response" << std::endl;
+      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;
+      for (listener = listeners.begin(); listener != listeners.end(); ++listener)
+      {
+         (*listener)->progressing(session->getSessionProxy(), response);
+      }
+   }
+   else if (respCode == 200)
+   {
+      std::cout << "[DEBUG] Got 200 response" << std::endl;
+      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;
+         for (listener = listeners.begin(); listener != listeners.end(); ++listener)
+         {
+            (*listener)->connected(session->getSessionProxy());
+         }
+      }
+   }
 }
 
 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 &&
+      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);
+      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;
+         return;
       }
       SipSessionPtr session = session_mod_info->getSessionPtr();
       AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response = new AsteriskSCF::SessionCommunications::V1::ResponseCode();
       if (inv->cause == 486)
       {
-	 response->isdnCode = 17;
+         response->isdnCode = 17;
       }
       else if (PJSIP_IS_STATUS_IN_CLASS(inv->cause, 500))
       {
-	 response->isdnCode = 34;
+         response->isdnCode = 34;
       }
       else
       {
-	 // TODO: See what cause is on a normal call completion
-	 response->isdnCode = 0;
+         // TODO: See what cause is on a normal call completion
+         response->isdnCode = 0;
       }
       std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
       for (std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::iterator listener = listeners.begin();
-	   listener != listeners.end();
-	   ++listener)
+           listener != listeners.end();
+           ++listener)
       {
-	 (*listener)->stopped(session->getSessionProxy(), response);
+         (*listener)->stopped(session->getSessionProxy(), response);
       }
-	  session_mod_info->mNeedsRemoval = true;
-	  pjsip_dialog *dlg = inv->dlg;
-	  PJSipDialogModInfo *dlg_mod_info = (PJSipDialogModInfo*) dlg->mod_data[mModule.id];
-	  dlg_mod_info->mNeedsRemoval = true;
-	  std::cerr << "Replicating state on DISCONNECTED inv_state." << std::endl;
-	  replicateState(dlg_mod_info, NULL, session_mod_info);
+      session_mod_info->mNeedsRemoval = true;
+      pjsip_dialog *dlg = inv->dlg;
+      PJSipDialogModInfo *dlg_mod_info = (PJSipDialogModInfo*) dlg->mod_data[mModule.id];
+      dlg_mod_info->mNeedsRemoval = true;
+      std::cerr << "Replicating state on DISCONNECTED inv_state." << std::endl;
+      replicateState(dlg_mod_info, NULL, session_mod_info);
       delete session_mod_info;
-	  delete dlg_mod_info;
-	  dlg->mod_data[mModule.id] = 0;
-	  inv->mod_data[mModule.id] = 0;
+      delete dlg_mod_info;
+      dlg->mod_data[mModule.id] = 0;
+      inv->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.
+      //See comment in invOnTransactionStateChanged() for explanation of this.
 
-	  //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);
-	  }
+      //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;
-	  std::cerr << "Replicating state on new outbound INVITE." << std::endl;
-	  replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
+      //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;
+      std::cerr << "Replicating state on new outbound INVITE." << std::endl;
+      replicateState(dlg_mod_info, tsx_mod_info, session_mod_info);
    }
 }
 
 void PJSipSessionModule::invOnNewSession(pjsip_inv_session *inv, pjsip_event *event)
 {
-	//stub
+   //stub
... 1016 lines suppressed ...


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list