[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "boostctl" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Dec 3 14:20:45 CST 2010
branch "boostctl" has been created
at 267521f2c19c59f84eb1e718a6e2b4b0522ac8d1 (commit)
- Log -----------------------------------------------------------------
commit 267521f2c19c59f84eb1e718a6e2b4b0522ac8d1
Author: Ken Hunt <ken.hunt at digium.com>
Date: Fri Dec 3 14:20:33 2010 -0600
Manage boost link options in CMake.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 15cb230..b264eb8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -41,7 +41,7 @@ asterisk_scf_component_add_file(SipSessionManager SipStateReplicator.h)
asterisk_scf_component_add_ice_libraries(SipSessionManager IceStorm)
-asterisk_scf_component_add_boost_libraries(SipSessionManager thread core)
+asterisk_scf_component_add_boost_libraries(SipSessionManager thread core date_time)
if(NOT logger_dir)
message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
@@ -81,7 +81,7 @@ asterisk_scf_component_add_file(SipStateReplicator SipStateReplicator.h)
#asterisk_scf_component_add_file(SipStateReplicator SipStateReplicator.cpp)
asterisk_scf_component_add_ice_libraries(SipStateReplicator IceStorm)
-asterisk_scf_component_add_boost_libraries(SipStateReplicator thread)
+asterisk_scf_component_add_boost_libraries(SipStateReplicator thread date_time)
asterisk_scf_component_build_icebox(SipStateReplicator)
target_link_libraries(SipStateReplicator logging-client)
commit 694d39c2f6d9bd8aac2a49263c24d12a7fd81300
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Mon Nov 15 18:06:22 2010 -0600
Fix up a few comments for accuracy.
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
index 239fa42..2d6c152 100644
--- a/src/SipSessionManagerApp.cpp
+++ b/src/SipSessionManagerApp.cpp
@@ -76,7 +76,8 @@ public:
mLocalAdapter = 0;
}
-public: // Overrides of IceBox::Service
+public:
+ // Overloads of IceBox::Service
virtual void start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args);
virtual void stop();
@@ -554,7 +555,7 @@ void SipSessionManager::initialize(const std::string appName, const Ice::Communi
}
/**
- * Overload of the Ice::Application::run method.
+ * Overload of the IceBox::Service::start method.
*/
void SipSessionManager::start(const string& name, const Ice::CommunicatorPtr& ic, const Ice::StringSeq& args)
{
@@ -588,6 +589,9 @@ void SipSessionManager::start(const string& name, const Ice::CommunicatorPtr& ic
}
}
+/**
+ * Overload of the IceBox::Service::stop method.
+ */
void SipSessionManager::stop()
{
// Remove our interfaces from the service locator.
commit 359f65acbf5d6fe09fe981994321bab50a1c94a6
Author: David M. Lee <dlee at digium.com>
Date: Mon Nov 15 14:03:38 2010 -0600
Updated indentation to match the style guide.
diff --git a/src/PJSipDummyModule.h b/src/PJSipDummyModule.h
index ebf7444..02b64fe 100644
--- a/src/PJSipDummyModule.h
+++ b/src/PJSipDummyModule.h
@@ -23,16 +23,16 @@ namespace SipChannelService
class PJSipDummyModule : public PJSipModule
{
public:
- PJSipDummyModule(pjsip_endpoint *endpt);
- pj_status_t load(pjsip_endpoint *endpoint);
- pj_status_t start();
- pj_status_t stop();
- pj_status_t unload();
- pj_bool_t on_rx_request(pjsip_rx_data *rdata);
- pj_bool_t on_rx_response(pjsip_rx_data *rdata);
- pj_status_t on_tx_request(pjsip_tx_data *tdata);
- pj_status_t on_tx_response(pjsip_tx_data *tdata);
- void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event);
+ PJSipDummyModule(pjsip_endpoint *endpt);
+ pj_status_t load(pjsip_endpoint *endpoint);
+ pj_status_t start();
+ pj_status_t stop();
+ pj_status_t unload();
+ pj_bool_t on_rx_request(pjsip_rx_data *rdata);
+ pj_bool_t on_rx_response(pjsip_rx_data *rdata);
+ pj_status_t on_tx_request(pjsip_tx_data *tdata);
+ pj_status_t on_tx_response(pjsip_tx_data *tdata);
+ void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event);
};
};
diff --git a/src/PJSipDummyModuleConstruction.cpp b/src/PJSipDummyModuleConstruction.cpp
index 81299c1..623b3bf 100644
--- a/src/PJSipDummyModuleConstruction.cpp
+++ b/src/PJSipDummyModuleConstruction.cpp
@@ -29,68 +29,68 @@ static PJSipDummyModule *dummyModule;
static pj_status_t dummyLoad(pjsip_endpoint *endpoint)
{
- return dummyModule->load(endpoint);
+ return dummyModule->load(endpoint);
}
static pj_status_t dummyStart()
{
- return dummyModule->unload();
+ return dummyModule->unload();
}
static pj_status_t dummyStop()
{
- return dummyModule->stop();
+ return dummyModule->stop();
}
static pj_status_t dummyUnload()
{
- return dummyModule->unload();
+ return dummyModule->unload();
}
static pj_bool_t dummyOnRxRequest(pjsip_rx_data *rdata)
{
- return dummyModule->on_rx_request(rdata);
+ return dummyModule->on_rx_request(rdata);
}
static pj_bool_t dummyOnRxResponse(pjsip_rx_data *rdata)
{
- return dummyModule->on_rx_response(rdata);
+ return dummyModule->on_rx_response(rdata);
}
static pj_bool_t dummyOnTxRequest(pjsip_tx_data *tdata)
{
- return dummyModule->on_tx_request(tdata);
+ return dummyModule->on_tx_request(tdata);
}
static pj_status_t dummyOnTxResponse(pjsip_tx_data *tdata)
{
- return dummyModule->on_tx_response(tdata);
+ return dummyModule->on_tx_response(tdata);
}
static void dummyOnTsxState(pjsip_transaction *tsx, pjsip_event *event)
{
- return dummyModule->on_tsx_state(tsx, event);
+ return dummyModule->on_tsx_state(tsx, event);
}
PJSipDummyModule::PJSipDummyModule(pjsip_endpoint *endpt)
{
- dummyModule = this;
- char name[] = "Dummy Module";
- mModule.name = pj_str(name);
- mModule.priority = PJSIP_MOD_PRIORITY_APPLICATION;
- /* Note that not all PJSIP module callbacks are required.
- * If you don't wish to have one defined, feel free to set
- * it NULL in this listing and remove the corresponding
- * static function above.
- */
- mModule.load = dummyLoad;
- mModule.start = dummyStart;
- mModule.stop = dummyStop;
- mModule.unload = dummyUnload;
- mModule.on_rx_request = dummyOnRxRequest;
- mModule.on_rx_response = dummyOnRxResponse;
- mModule.on_tx_request = dummyOnTxRequest;
- mModule.on_tx_response = dummyOnTxResponse;
- mModule.on_tsx_state = dummyOnTsxState;
- pjsip_endpt_register_module(endpt, &mModule);
+ dummyModule = this;
+ char name[] = "Dummy Module";
+ mModule.name = pj_str(name);
+ mModule.priority = PJSIP_MOD_PRIORITY_APPLICATION;
+ /* Note that not all PJSIP module callbacks are required.
+ * If you don't wish to have one defined, feel free to set
+ * it NULL in this listing and remove the corresponding
+ * static function above.
+ */
+ mModule.load = dummyLoad;
+ mModule.start = dummyStart;
+ mModule.stop = dummyStop;
+ mModule.unload = dummyUnload;
+ mModule.on_rx_request = dummyOnRxRequest;
+ mModule.on_rx_response = dummyOnRxResponse;
+ mModule.on_tx_request = dummyOnTxRequest;
+ mModule.on_tx_response = dummyOnTxResponse;
+ mModule.on_tsx_state = dummyOnTsxState;
+ pjsip_endpt_register_module(endpt, &mModule);
}
diff --git a/src/PJSipLoggingModule.cpp b/src/PJSipLoggingModule.cpp
index 74fae5b..f5f8b8b 100644
--- a/src/PJSipLoggingModule.cpp
+++ b/src/PJSipLoggingModule.cpp
@@ -32,50 +32,50 @@ namespace SipSessionManager
pj_status_t PJSipLoggingModule::load(pjsip_endpoint *endpt)
{
- return PJ_SUCCESS;
+ return PJ_SUCCESS;
}
pj_status_t PJSipLoggingModule::start()
{
- return PJ_SUCCESS;
+ return PJ_SUCCESS;
}
pj_status_t PJSipLoggingModule::stop()
{
- return PJ_SUCCESS;
+ return PJ_SUCCESS;
}
pj_status_t PJSipLoggingModule::unload()
{
- return PJ_SUCCESS;
+ return PJ_SUCCESS;
}
pj_bool_t PJSipLoggingModule::on_rx_request(pjsip_rx_data *rdata)
{
- lg(Debug) << "Incoming SIP request" << std::endl;
- lg(Debug) << rdata->pkt_info.packet << std::endl;
- return PJ_FALSE;
+ lg(Debug) << "Incoming SIP request" << std::endl;
+ lg(Debug) << rdata->pkt_info.packet << std::endl;
+ return PJ_FALSE;
}
pj_bool_t PJSipLoggingModule::on_rx_response(pjsip_rx_data *rdata)
{
- lg(Debug) << "Incoming SIP response" << std::endl;
- lg(Debug) << rdata->pkt_info.packet << std::endl;
- return PJ_FALSE;
+ lg(Debug) << "Incoming SIP response" << std::endl;
+ lg(Debug) << rdata->pkt_info.packet << std::endl;
+ return PJ_FALSE;
}
pj_status_t PJSipLoggingModule::on_tx_request(pjsip_tx_data *tdata)
{
- lg(Debug) << "Outgoing SIP request" << std::endl;
- lg(Debug) << tdata->buf.start << std::endl;
- return PJ_SUCCESS;
+ lg(Debug) << "Outgoing SIP request" << std::endl;
+ lg(Debug) << tdata->buf.start << std::endl;
+ return PJ_SUCCESS;
}
pj_status_t PJSipLoggingModule::on_tx_response(pjsip_tx_data *tdata)
{
- lg(Debug) << "Outgoing SIP response" << std::endl;
- lg(Debug) << tdata->buf.start << std::endl;
- return PJ_SUCCESS;
+ lg(Debug) << "Outgoing SIP response" << std::endl;
+ lg(Debug) << tdata->buf.start << std::endl;
+ return PJ_SUCCESS;
}
void PJSipLoggingModule::on_tsx_state(pjsip_transaction *tsx, pjsip_event *event)
diff --git a/src/PJSipLoggingModule.h b/src/PJSipLoggingModule.h
index dcfce4c..043187e 100644
--- a/src/PJSipLoggingModule.h
+++ b/src/PJSipLoggingModule.h
@@ -27,16 +27,16 @@ namespace SipSessionManager
class PJSipLoggingModule : public PJSipModule
{
public:
- PJSipLoggingModule(pjsip_endpoint *endpt);
- pj_status_t load(pjsip_endpoint *endpoint);
- pj_status_t start();
- pj_status_t stop();
- pj_status_t unload();
- pj_bool_t on_rx_request(pjsip_rx_data *rdata);
- pj_bool_t on_rx_response(pjsip_rx_data *rdata);
- pj_status_t on_tx_request(pjsip_tx_data *tdata);
- pj_status_t on_tx_response(pjsip_tx_data *tdata);
- void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event);
+ PJSipLoggingModule(pjsip_endpoint *endpt);
+ pj_status_t load(pjsip_endpoint *endpoint);
+ pj_status_t start();
+ pj_status_t stop();
+ pj_status_t unload();
+ pj_bool_t on_rx_request(pjsip_rx_data *rdata);
+ pj_bool_t on_rx_response(pjsip_rx_data *rdata);
+ pj_status_t on_tx_request(pjsip_tx_data *tdata);
+ pj_status_t on_tx_response(pjsip_tx_data *tdata);
+ void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event);
};
};
diff --git a/src/PJSipLoggingModuleConstruction.cpp b/src/PJSipLoggingModuleConstruction.cpp
index 06e5475..99960a3 100644
--- a/src/PJSipLoggingModuleConstruction.cpp
+++ b/src/PJSipLoggingModuleConstruction.cpp
@@ -26,70 +26,70 @@ static PJSipLoggingModule *loggingModule;
static pj_status_t loggingLoad(pjsip_endpoint *endpoint)
{
- return loggingModule->load(endpoint);
+ return loggingModule->load(endpoint);
}
static pj_status_t loggingStart()
{
- return loggingModule->unload();
+ return loggingModule->unload();
}
static pj_status_t loggingStop()
{
- return loggingModule->stop();
+ return loggingModule->stop();
}
static pj_status_t loggingUnload()
{
- return loggingModule->unload();
+ return loggingModule->unload();
}
static pj_bool_t loggingOnRxRequest(pjsip_rx_data *rdata)
{
- return loggingModule->on_rx_request(rdata);
+ return loggingModule->on_rx_request(rdata);
}
static pj_bool_t loggingOnRxResponse(pjsip_rx_data *rdata)
{
- return loggingModule->on_rx_response(rdata);
+ return loggingModule->on_rx_response(rdata);
}
static pj_bool_t loggingOnTxRequest(pjsip_tx_data *tdata)
{
- return loggingModule->on_tx_request(tdata);
+ return loggingModule->on_tx_request(tdata);
}
static pj_status_t loggingOnTxResponse(pjsip_tx_data *tdata)
{
- return loggingModule->on_tx_response(tdata);
+ return loggingModule->on_tx_response(tdata);
}
static void loggingOnTsxState(pjsip_transaction *tsx, pjsip_event *event)
{
- return loggingModule->on_tsx_state(tsx, event);
+ return loggingModule->on_tsx_state(tsx, event);
}
PJSipLoggingModule::PJSipLoggingModule(pjsip_endpoint *endpt)
{
- loggingModule = this;
- char name[] = "Logging Module";
- mModule.name = pj_str(name);
- // This is the highest priority module. We do this
- // so that on outgoing messages, the transport information
- // will have been filled in by the transport layer. This way
- // what we log is exactly the same as what goes out over the
- // wire.
- mModule.priority = 0;
- mModule.load = loggingLoad;
- mModule.start = loggingStart;
- mModule.stop = loggingStop;
- mModule.unload = loggingUnload;
- mModule.on_rx_request = loggingOnRxRequest;
- mModule.on_rx_response = loggingOnRxResponse;
- mModule.on_tx_request = loggingOnTxRequest;
- mModule.on_tx_response = loggingOnTxResponse;
- mModule.on_tsx_state = loggingOnTsxState;
- pjsip_endpt_register_module(endpt, &mModule);
+ loggingModule = this;
+ char name[] = "Logging Module";
+ mModule.name = pj_str(name);
+ // This is the highest priority module. We do this
+ // so that on outgoing messages, the transport information
+ // will have been filled in by the transport layer. This way
+ // what we log is exactly the same as what goes out over the
+ // wire.
+ mModule.priority = 0;
+ mModule.load = loggingLoad;
+ mModule.start = loggingStart;
+ mModule.stop = loggingStop;
+ mModule.unload = loggingUnload;
+ mModule.on_rx_request = loggingOnRxRequest;
+ mModule.on_rx_response = loggingOnRxResponse;
+ mModule.on_tx_request = loggingOnTxRequest;
+ mModule.on_tx_response = loggingOnTxResponse;
+ mModule.on_tsx_state = loggingOnTsxState;
+ pjsip_endpt_register_module(endpt, &mModule);
}
};
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 083911e..4270766 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -33,110 +33,110 @@ namespace SipSessionManager
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);
- }
-
- return 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;
}
PJSipManager::PJSipManager(Ice::PropertiesPtr props)
{
- pj_status_t status = pj_init();
- if (status != PJ_SUCCESS)
- {
- lg(Error) << "Failed to Initialize PJSIP";
- }
- // 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)
- {
- 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)
- {
- lg(Error) << "Failed to create SIP maintenance thread";
- }
+ pj_status_t status = pj_init();
+ if (status != PJ_SUCCESS)
+ {
+ lg(Error) << "Failed to Initialize PJSIP";
+ }
+ // 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)
+ {
+ 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)
+ {
+ lg(Error) << "Failed to create SIP maintenance thread";
+ }
}
void PJSipManager::registerSessionModule(pjsip_endpoint *endpt,
- boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
- AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
- AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
- AsteriskSCF::System::Component::V1::ReplicaPtr replica
- )
+ boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
+ AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
+ AsteriskSCF::ProxyWrapper::ProxyWrapper<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);
}
void PJSipManager::registerLoggingModule(pjsip_endpoint *endpt)
{
- mLoggingModule = new PJSipLoggingModule(endpt);
+ mLoggingModule = new PJSipLoggingModule(endpt);
}
pjsip_endpoint *PJSipManager::getEndpoint()
{
- return mEndpoint;
+ return mEndpoint;
}
PJSipSessionModule *PJSipManager::getSessionModule()
{
- return mSessionModule;
+ return mSessionModule;
}
PJSipLoggingModule *PJSipManager::getLoggingModule()
{
- return mLoggingModule;
+ return mLoggingModule;
}
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)
- {
- lg(Error) << "Failed to create IPv4 UDP transport. DANG!";
- }
- }
- else if (udpAddr.addr.sa_family == pj_AF_INET6())
- {
- status = pjsip_udp_transport_start6(endpoint, &udpAddr.ipv6, NULL, 2, &mUdpTransport);
- if (status != PJ_SUCCESS)
- {
- lg(Error) << "Failed to create IPv4 UDP transport. DANG!";
- }
- }
- //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)
+ {
+ lg(Error) << "Failed to create IPv4 UDP transport. DANG!";
+ }
+ }
+ else if (udpAddr.addr.sa_family == pj_AF_INET6())
+ {
+ status = pjsip_udp_transport_start6(endpoint, &udpAddr.ipv6, NULL, 2, &mUdpTransport);
+ if (status != PJ_SUCCESS)
+ {
+ lg(Error) << "Failed to create IPv4 UDP transport. DANG!";
+ }
+ }
+ //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 SipSessionManager
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index b9d1e5a..7cc5220 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -45,51 +45,51 @@ namespace SipSessionManager
class PJSipManager
{
public:
- PJSipManager(Ice::PropertiesPtr props);
- /**
- * Get a handle to the PJSipEndpoint for operations
- * that may require it
- */
- pjsip_endpoint *getEndpoint();
+ PJSipManager(Ice::PropertiesPtr props);
+ /**
+ * Get a handle to the PJSipEndpoint for operations
+ * that may require it
+ */
+ pjsip_endpoint *getEndpoint();
- /**
- * Get a reference to the PJSIP session module
- */
- PJSipSessionModule *getSessionModule();
+ /**
+ * Get a reference to the PJSIP session module
+ */
+ PJSipSessionModule *getSessionModule();
- /**
- * Get a reference to the PJSIP logging module
- */
- PJSipLoggingModule *getLoggingModule();
+ /**
+ * Get a reference to the PJSIP logging module
+ */
+ PJSipLoggingModule *getLoggingModule();
- /**
- * Register the PJSipSessionModule, responsible
- * for basic call handling
- */
- void registerSessionModule(pjsip_endpoint *endpt,
- boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
- AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
- AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
- AsteriskSCF::System::Component::V1::ReplicaPtr replica
- );
+ /**
+ * Register the PJSipSessionModule, responsible
+ * for basic call handling
+ */
+ void registerSessionModule(pjsip_endpoint *endpt,
+ boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
+ AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
+ AsteriskSCF::ProxyWrapper::ProxyWrapper<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
+ AsteriskSCF::System::Component::V1::ReplicaPtr replica
+ );
- /**
- * Register the PJSipLoggingModule, responsible
- * for logging incoming and outgoing SIP messages
- */
- void registerLoggingModule(pjsip_endpoint *endpt);
+ /**
+ * Register the PJSipLoggingModule, responsible
+ * for logging incoming and outgoing SIP messages
+ */
+ void registerLoggingModule(pjsip_endpoint *endpt);
private:
- static PJSipManager *mInstance;
- pjsip_endpoint *mEndpoint;
- PJSipSessionModule *mSessionModule;
- PJSipLoggingModule *mLoggingModule;
- pj_thread_t *mPjThread;
- pj_caching_pool mCachingPool;
- pj_pool_t *mMemoryPool;
- pjsip_transport *mUdpTransport;
+ static PJSipManager *mInstance;
+ pjsip_endpoint *mEndpoint;
+ PJSipSessionModule *mSessionModule;
+ PJSipLoggingModule *mLoggingModule;
+ pj_thread_t *mPjThread;
+ pj_caching_pool mCachingPool;
+ pj_pool_t *mMemoryPool;
+ pjsip_transport *mUdpTransport;
- bool setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr props);
+ bool setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr props);
};
}; //End namespace SipSessionManager
diff --git a/src/PJSipModule.cpp b/src/PJSipModule.cpp
index ba4de0a..0b92ec6 100644
--- a/src/PJSipModule.cpp
+++ b/src/PJSipModule.cpp
@@ -37,15 +37,15 @@ const int URI_SIZE = 64;
PJSipDialogModInfo::PJSipDialogModInfo(pjsip_dialog *dialog) : mDialogState(new SipDialogStateItem) , mNeedsReplication(true), mNeedsRemoval(false)
{
- //XXX Is there a way to tell ICE to make the default
- //constructor for SipStateItem set key?
- mDialogState->key = IceUtil::generateUUID();
- updateDialogState(dialog);
+ //XXX Is there a way to tell ICE to make the default
+ //constructor for SipStateItem set key?
+ mDialogState->key = IceUtil::generateUUID();
+ updateDialogState(dialog);
}
PJSipDialogModInfo::~PJSipDialogModInfo()
{
- mDialogState = 0;
+ mDialogState = 0;
}
/**
@@ -58,100 +58,100 @@ PJSipDialogModInfo::~PJSipDialogModInfo()
*/
void PJSipDialogModInfo::updateDialogState(pjsip_dialog *dialog)
{
- mDialogState->mCallId = std::string(pj_strbuf(&dialog->call_id->id), pj_strlen(&dialog->call_id->id));
- mDialogState->mIsDialogEstablished = dialog->state == PJSIP_DIALOG_STATE_ESTABLISHED ? true : false;
- mDialogState->mIsSecure = dialog->secure == PJ_TRUE ? true : false;
-
- mDialogState->mLocalCSeq = dialog->local.cseq;
- mDialogState->mLocalTag = std::string(pj_strbuf(&dialog->local.info->tag), pj_strlen(&dialog->local.info->tag));
- char localUri[URI_SIZE];
- pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, dialog->local.info->uri, localUri, sizeof(localUri));
- mDialogState->mLocalUri = localUri;
-
- mDialogState->mRemoteCSeq = dialog->remote.cseq;
- mDialogState->mRemoteTag = std::string(pj_strbuf(&dialog->remote.info->tag), pj_strlen(&dialog->remote.info->tag));
- char remoteUri[URI_SIZE];
- pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, dialog->remote.info->uri, remoteUri, sizeof(remoteUri));
- mDialogState->mRemoteUri = remoteUri;
-
- //This is a place where the whole "only change what you need" optimization
- //will come in super-handy since we have to erase and rebuild the route set
- //every time. My recollection is that the route set can only be established
- //in the first transaction of a dialog so this is purdy wasteful.
- 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));
-
- //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);
- }
- //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
- //other transports.
- mDialogState->mTransport = "UDP";
- mNeedsReplication = true;
+ mDialogState->mCallId = std::string(pj_strbuf(&dialog->call_id->id), pj_strlen(&dialog->call_id->id));
+ mDialogState->mIsDialogEstablished = dialog->state == PJSIP_DIALOG_STATE_ESTABLISHED ? true : false;
+ mDialogState->mIsSecure = dialog->secure == PJ_TRUE ? true : false;
+
+ mDialogState->mLocalCSeq = dialog->local.cseq;
+ mDialogState->mLocalTag = std::string(pj_strbuf(&dialog->local.info->tag), pj_strlen(&dialog->local.info->tag));
+ char localUri[URI_SIZE];
+ pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, dialog->local.info->uri, localUri, sizeof(localUri));
+ mDialogState->mLocalUri = localUri;
+
+ mDialogState->mRemoteCSeq = dialog->remote.cseq;
+ mDialogState->mRemoteTag = std::string(pj_strbuf(&dialog->remote.info->tag), pj_strlen(&dialog->remote.info->tag));
+ char remoteUri[URI_SIZE];
+ pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, dialog->remote.info->uri, remoteUri, sizeof(remoteUri));
+ mDialogState->mRemoteUri = remoteUri;
+
+ //This is a place where the whole "only change what you need" optimization
+ //will come in super-handy since we have to erase and rebuild the route set
+ //every time. My recollection is that the route set can only be established
+ //in the first transaction of a dialog so this is purdy wasteful.
+ 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));
+
+ //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);
+ }
+ //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
+ //other transports.
+ mDialogState->mTransport = "UDP";
+ mNeedsReplication = true;
}
PJSipTransactionModInfo::PJSipTransactionModInfo(pjsip_transaction *transaction) : mTransactionState(new SipTransactionStateItem), mNeedsReplication(true), mNeedsRemoval(false)
{
- mTransactionState->key = IceUtil::generateUUID();
- updateTransactionState(transaction);
+ mTransactionState->key = IceUtil::generateUUID();
+ updateTransactionState(transaction);
}
PJSipTransactionModInfo::~PJSipTransactionModInfo()
{
- mTransactionState = 0;
+ mTransactionState = 0;
}
void PJSipTransactionModInfo::updateTransactionState(pjsip_transaction *transaction)
{
- mTransactionState->mBranch = std::string(pj_strbuf(&transaction->branch), pj_strlen(&transaction->branch));
- mTransactionState->mIsClient = (transaction->role == PJSIP_ROLE_UAC || transaction->role == PJSIP_UAC_ROLE) ? true : false;
- mTransactionState->mCurrentState = transactionStateTranslate(transaction->state);
- mNeedsReplication = true;
+ mTransactionState->mBranch = std::string(pj_strbuf(&transaction->branch), pj_strlen(&transaction->branch));
+ mTransactionState->mIsClient = (transaction->role == PJSIP_ROLE_UAC || transaction->role == PJSIP_UAC_ROLE) ? true : false;
+ mTransactionState->mCurrentState = transactionStateTranslate(transaction->state);
+ mNeedsReplication = true;
}
TransactionState PJSipTransactionModInfo::transactionStateTranslate(pjsip_tsx_state_e state)
{
- TransactionState retState;
- switch (state)
- {
- case PJSIP_TSX_STATE_NULL:
- retState = TransactionStateNull;
- break;
- case PJSIP_TSX_STATE_CALLING:
- retState = TransactionStateCalling;
- break;
- case PJSIP_TSX_STATE_TRYING:
- retState = TransactionStateTrying;
- break;
- case PJSIP_TSX_STATE_PROCEEDING:
- retState = TransactionStateProceeding;
- break;
- case PJSIP_TSX_STATE_COMPLETED:
- retState = TransactionStateCompleted;
- break;
- case PJSIP_TSX_STATE_CONFIRMED:
- retState = TransactionStateConfirmed;
- break;
- case PJSIP_TSX_STATE_TERMINATED:
- retState = TransactionStateTerminated;
- break;
- case PJSIP_TSX_STATE_DESTROYED:
- retState = TransactionStateDestroyed;
- break;
- default:
- lg(Error) << "Unknown PJSIP Transaction state encountered: " << state;
- retState = TransactionStateNull;
- break;
- }
- return retState;
+ TransactionState retState;
+ switch (state)
+ {
+ case PJSIP_TSX_STATE_NULL:
+ retState = TransactionStateNull;
+ break;
+ case PJSIP_TSX_STATE_CALLING:
+ retState = TransactionStateCalling;
+ break;
+ case PJSIP_TSX_STATE_TRYING:
+ retState = TransactionStateTrying;
+ break;
+ case PJSIP_TSX_STATE_PROCEEDING:
+ retState = TransactionStateProceeding;
+ break;
+ case PJSIP_TSX_STATE_COMPLETED:
+ retState = TransactionStateCompleted;
+ break;
+ case PJSIP_TSX_STATE_CONFIRMED:
+ retState = TransactionStateConfirmed;
+ break;
+ case PJSIP_TSX_STATE_TERMINATED:
+ retState = TransactionStateTerminated;
+ break;
+ case PJSIP_TSX_STATE_DESTROYED:
+ retState = TransactionStateDestroyed;
+ break;
+ default:
+ lg(Error) << "Unknown PJSIP Transaction state encountered: " << state;
+ retState = TransactionStateNull;
+ break;
+ }
+ return retState;
}
};
diff --git a/src/PJSipModule.h b/src/PJSipModule.h
index d96aa76..c2d5034 100644
--- a/src/PJSipModule.h
+++ b/src/PJSipModule.h
@@ -35,45 +35,45 @@ using namespace AsteriskSCF::SIP::V1;
class PJSipModule
{
public:
- virtual pj_status_t load(pjsip_endpoint *endpoint) = 0;
- virtual pj_status_t start() = 0;
- virtual pj_status_t stop() = 0;
- virtual pj_status_t unload() = 0;
- virtual pj_bool_t on_rx_request(pjsip_rx_data *rdata) = 0;
- virtual pj_bool_t on_rx_response(pjsip_rx_data *rdata) = 0;
- virtual pj_status_t on_tx_request(pjsip_tx_data *tdata) = 0;
- virtual pj_status_t on_tx_response(pjsip_tx_data *tdata) = 0;
- virtual void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event) = 0;
- pjsip_module &getModule() { return mModule; };
+ virtual pj_status_t load(pjsip_endpoint *endpoint) = 0;
+ virtual pj_status_t start() = 0;
+ virtual pj_status_t stop() = 0;
+ virtual pj_status_t unload() = 0;
+ virtual pj_bool_t on_rx_request(pjsip_rx_data *rdata) = 0;
+ virtual pj_bool_t on_rx_response(pjsip_rx_data *rdata) = 0;
+ virtual pj_status_t on_tx_request(pjsip_tx_data *tdata) = 0;
+ virtual pj_status_t on_tx_response(pjsip_tx_data *tdata) = 0;
+ virtual void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event) = 0;
+ pjsip_module &getModule() { return mModule; };
protected:
- PJSipModule() { }
- pjsip_module mModule;
+ PJSipModule() { }
+ pjsip_module mModule;
private:
- const std::string mName;
+ const std::string mName;
};
class PJSipDialogModInfo
{
public:
- PJSipDialogModInfo(pjsip_dialog *dialog);
- ~PJSipDialogModInfo();
- void updateDialogState(pjsip_dialog *dialog);
- SipDialogStateItemPtr mDialogState;
- bool mNeedsReplication;
- bool mNeedsRemoval;
+ PJSipDialogModInfo(pjsip_dialog *dialog);
+ ~PJSipDialogModInfo();
+ void updateDialogState(pjsip_dialog *dialog);
+ SipDialogStateItemPtr mDialogState;
+ bool mNeedsReplication;
+ bool mNeedsRemoval;
};
class PJSipTransactionModInfo
{
public:
- PJSipTransactionModInfo(pjsip_transaction *transaction);
- ~PJSipTransactionModInfo();
- void updateTransactionState(pjsip_transaction *transaction);
- SipTransactionStateItemPtr mTransactionState;
- bool mNeedsReplication;
- bool mNeedsRemoval;
+ PJSipTransactionModInfo(pjsip_transaction *transaction);
+ ~PJSipTransactionModInfo();
+ void updateTransactionState(pjsip_transaction *transaction);
+ SipTransactionStateItemPtr mTransactionState;
+ bool mNeedsReplication;
+ bool mNeedsRemoval;
private:
- TransactionState transactionStateTranslate(pjsip_tsx_state_e state);
+ TransactionState transactionStateTranslate(pjsip_tsx_state_e state);
};
}; //end namespace SipSessionManager
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 64567d6..e770b81 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -48,603 +48,603 @@ 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)
+ 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);
+ 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;
- }
+ 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
- {
- Ice::Current current;
- mSessionState->mBridge = mSession->getBridge(current);
- }
- 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;
+ 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
+ {
+ Ice::Current current;
+ mSessionState->mBridge = mSession->getBridge(current);
+ }
+ 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;
+ return mSession;
}
void PJSipSessionModInfo::setSessionPtr(SipSessionPtr sessionPtr)
{
- mSession = 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;
+ 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)
+ 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." << std::endl;
- }
-
- 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." << std::endl;
- }
- }
-
- 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." << std::endl;
- }
-
- 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." << std::endl;
- }
- }
- }
+ 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." << std::endl;
+ }
+
+ 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." << std::endl;
+ }
+ }
+
+ 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." << std::endl;
+ }
+
+ 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." << std::endl;
+ }
+ }
+ }
}
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.
-
- //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.
-
- 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)
- {
- 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);
-
- 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 *)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 *)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 = 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;
-
- 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
- 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;
- }
+ //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 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)
+ {
+ 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);
+
+ 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 *)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 *)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 = 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;
+
+ 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
+ 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_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" << std::endl;
- 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
- {
- lg(Debug) << "handleRefer() calling router connectBridgedSessions(). " << std::endl;
- mSessionRouter->connectBridgedSessions(session->getSessionProxy(), other_session->getSessionProxy());
- pjsip_dlg_respond(inv->dlg, rdata, 200, NULL, NULL, NULL);
- Ice::Current current;
- lg(Debug) << "handleRefer() calling session->stop(). " << std::endl;
- session->stop(new ResponseCode(16), current);
- }
- catch (const std::exception& e)
- {
- lg(Debug) << "handleRefer() sending 400 due to exception: " << e.what() << std::endl;
- pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
- }
- 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
- {
- PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
- SipSessionPtr session = session_mod_info->getSessionPtr();
-
- lg(Debug) << "handleRefer() calling router connectBridgedSessionsWithDestination(). " << std::endl;
- mSessionRouter->connectBridgedSessionsWithDestination(session->getSessionProxy(), target);
- pjsip_dlg_respond(inv->dlg, rdata, 200, NULL, NULL, NULL);
- Ice::Current current;
-
- lg(Debug) << "handleRefer() calling session->stop(). " << std::endl;
- session->stop(new ResponseCode(16), current);
- }
- catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException&)
- {
- lg(Debug) << "handleRefer() sending 404 due to destination not found for target: " << target << std::endl;
-
- pjsip_dlg_respond(inv->dlg, rdata, 404, NULL, NULL, NULL);
- return;
- }
- catch (const std::exception& e)
- {
- lg(Debug) << "handleRefer() sending 400 due to exception: " << e.what() << std::endl;
- pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
- return;
- }
- }
+ 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" << std::endl;
+ 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)
+ {
... 44760 lines suppressed ...
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list