[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "nat-traversal" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Apr 25 10:44:43 CDT 2011
branch "nat-traversal" has been created
at e8979048bb3679d1332b9abfd7e59a89f345efa4 (commit)
- Log -----------------------------------------------------------------
commit e8979048bb3679d1332b9abfd7e59a89f345efa4
Author: Brent Eagles <beagles at digium.com>
Date: Mon Apr 25 13:13:28 2011 -0230
Adding missing unsliceable.
diff --git a/local-slice/SipStateReplicationIf.ice b/local-slice/SipStateReplicationIf.ice
index 80d9fae..c7d16d9 100644
--- a/local-slice/SipStateReplicationIf.ice
+++ b/local-slice/SipStateReplicationIf.ice
@@ -31,7 +31,7 @@ module V1
const string StateReplicatorComponentCategory = "SipStateReplicatorComponent";
const string StateReplicatorDiscoveryCategory = "SipStateReplicator";
- class SipStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
+ unsliceable class SipStateReplicatorParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
{
string mName;
};
commit 0f83f9f5fca5bc50b71b7fb529df74a279a21be6
Author: Brent Eagles <beagles at digium.com>
Date: Mon Mar 28 15:51:15 2011 -0230
In progress changes. Setup a PJNATH STUN based custom transport
that integrates with the SIP endpoint.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d03df8c..d50180c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -48,6 +48,7 @@ target_link_libraries(SipSessionManager logging-client)
pjproject_link(SipSessionManager pjsip)
pjproject_link(SipSessionManager pjmedia)
+pjproject_link(SipSessionManager pjnath)
pjproject_link(SipSessionManager pjlib-util)
pjproject_link(SipSessionManager pjlib)
diff --git a/src/DebugUtil.h b/src/DebugUtil.h
new file mode 100644
index 0000000..cf65974
--- /dev/null
+++ b/src/DebugUtil.h
@@ -0,0 +1,33 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+#pragma once
+
+#include <Ice/Ice.h>
+#include <boost/current_function.hpp>
+#include <string>
+
+namespace AsteriskSCF
+{
+
+#define FUNLOG \
+ __FILE__ << ':' << __LINE__ << '(' << BOOST_CURRENT_FUNCTION << ')'
+
+inline std::string objectIdFromCurrent(const Ice::Current& current)
+{
+ return current.adapter->getCommunicator()->identityToString(current.id);
+}
+
+} /* End of namespace AsteriskSCF */
diff --git a/src/PJSipLoggingModule.cpp b/src/PJSipLoggingModule.cpp
index 729aaf0..5b26d78 100644
--- a/src/PJSipLoggingModule.cpp
+++ b/src/PJSipLoggingModule.cpp
@@ -14,9 +14,8 @@
* at the top of the source tree.
*/
-#include <AsteriskSCF/logger.h>
-
#include "PJSipLoggingModule.h"
+#include <AsteriskSCF/logger.h>
using namespace AsteriskSCF::System::Logging;
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 8da907b..6160238 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -13,15 +13,29 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
+
+#include <pjlib.h>
#include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/System/ExceptionsIf.h>
#include "PJSipManager.h"
+#include "DebugUtil.h"
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/locks.hpp>
+#include <vector>
+
+#include <pjnath/stun_sock.h>
+#include <pjnath/stun_session.h>
+
using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::System::V1;
+using namespace std;
namespace
{
-Logger lg = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
+Logger logger = getLoggerFactory().getLogger("AsteriskSCF.SipSessionManager");
}
@@ -31,45 +45,562 @@ namespace AsteriskSCF
namespace SipSessionManager
{
+static bool success(pj_status_t r)
+{
+ return r == PJ_SUCCESS;
+}
+
+static bool fail(pj_status_t r)
+{
+ return !success(r);
+}
+
+class STUNModule
+{
+public:
+ //
+ // TODO: More configuration details!
+ //
+ STUNModule(pj_pool_t* pool, pj_caching_pool& cachingPool, const Ice::PropertiesPtr& props) :
+ mPool(pool)
+ {
+ logger(Debug) << FUNLOG << " : initializing STUN module";
+ pj_status_t status = pjnath_init();
+ if (fail(status))
+ {
+ const char* message = "Unable to initialize PJNATH library.";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
+ }
+ //
+ // We set the pool, queue, etc. to 0 because they are initialized later on.
+ // TODO: We may be able to use the main SIP ioqueue and timer heap. If so
+ // we can remove the poll method on this object.
+ //
+ pj_stun_config_init(&mConfig, &cachingPool.factory, 0, 0, 0);
+ status = pj_timer_heap_create(mPool,
+ props->getPropertyAsIntWithDefault("Sip.PJSip.TimerHeap.Size", 1000),
+ &mConfig.timer_heap);
+ if (fail(status))
+ {
+ const char* message = "Unable to initialize timer heap.";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
+ }
+ status = pj_ioqueue_create(mPool, props->getPropertyAsIntWithDefault("Sip.PJSip.IOQueue.MaxSize", 16),
+ &mConfig.ioqueue);
+ if (fail(status))
+ {
+ const char* message = "Unable to initialize IO queue.";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
+ }
+ }
+
+ void poll()
+ {
+ const pj_time_val delay = {0, 10};
+ pj_ioqueue_poll(mConfig.ioqueue, &delay);
+ pj_timer_heap_poll(mConfig.timer_heap, 0);
+ }
+
+ ~STUNModule()
+ {
+ pj_ioqueue_destroy(mConfig.ioqueue);
+ mConfig.ioqueue = 0;
+ pj_timer_heap_destroy(mConfig.timer_heap);
+ mConfig.timer_heap = 0;
+ }
+
+ /**
+ * This is "sketchy". There is no mutex protection, etc. While the shared pointer would prevent
+ * accessing memory that no longer exists (if it is *used*), this accessor is really only for
+ * use during initialization when there shouldn't be much going on.
+ **/
+ pj_stun_config* getConfig()
+ {
+ return &mConfig;
+ }
+
+ pj_pool_t* getPool()
+ {
+ return mPool;
+ }
+
+ //
+ // TODO: I think PJNATH takes care of all of the required cleanups via the pools, so there is nothing for a
+ // destructor to do. This code could just as easily be put inline, but I figured the PJSipManager might
+ // have to have other stuff added in later on, so compartamentalizing this code seemed good for organization.
+ // The presence of non-0 value in the member pointer also serves double duty as a flag that that STUN
+ // has been configured.
+ //
+
+private:
+ pj_stun_config mConfig;
+ pj_pool_t* mPool;
+};
+typedef boost::shared_ptr<STUNModule> STUNModulePtr;
+
+//
+// TODO: The Transport/TransportFactory classes could be extended to allow multiple transports to
+// be configured on this endpoint.
+//
+
+class UDPTransport : public Transport
+{
+public:
+ UDPTransport(pjsip_endpoint* endpoint, const Ice::PropertiesPtr& props)
+ {
+ logger(Debug) << FUNLOG << " : initializing UDP transport";
+ //
+ // TODO: const table for property names?
+ //
+ string bindAddr = props->getPropertyWithDefault("Sip.Transport.UdpBindAddr", "0.0.0.0:5060");
+
+ //
+ // UNSPEC family means "you figure out the address family, pjlib!"
+ //
+ pj_sockaddr udpAddr;
+ pj_str_t pjAddrStr;
+ pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&pjAddrStr, bindAddr.c_str()), &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.
+ //
+ pj_status_t status = pjsip_udp_transport_start(endpoint, &udpAddr.ipv4, NULL, 2, &mSocket);
+ if (fail(status))
+ {
+ const char* msg = "Failed to create IPv4 UDP transport.";
+ logger(Error) << msg;
+ throw InternalInitializationException(msg);
+ }
+ }
+ else if (udpAddr.addr.sa_family == pj_AF_INET6())
+ {
+ pj_status_t status = pjsip_udp_transport_start6(endpoint, &udpAddr.ipv6, NULL, 2, &mSocket);
+ if (fail(status))
+ {
+ const char* msg = "Failed to create IPv6 UDP transport.";
+ logger(Error) << msg;
+ throw InternalInitializationException(msg);
+ }
+ }
+ };
+
+ ~UDPTransport()
+ {
+ //
+ // We don't have to worry about cleaning up. PJSIP takes care of that.
+ //
+ mSocket = 0;
+ };
+
+private:
+ pjsip_transport* mSocket;
+};
+
+class STUNTransport : public Transport
+{
+private:
+ /**
+ * Callback methods for the STUN socket callback data structure.
+ **/
+ static pj_bool_t onRxData(pj_stun_sock* stunSock, void* packet, unsigned packetLength,
+ const pj_sockaddr_t* sourceAddress, unsigned addressLength)
+ {
+ STUNTransport* t = reinterpret_cast<STUNTransport*>(pj_stun_sock_get_user_data(stunSock));
+ t->dataReceived(packet, packetLength, sourceAddress, addressLength);
+ return PJ_TRUE;
+ }
+
+ static pj_bool_t onDataSent(pj_stun_sock* stunSock, pj_ioqueue_op_key_t* sendKey, pj_ssize_t sent)
+ {
+ //
+ // TODO. We could rig this up to allow asynchronous replies to the
+ // PJSIP transport manager.
+ //
+ return PJ_TRUE;
+ }
+
+ static pj_bool_t onStatus(pj_stun_sock* stunSock, pj_stun_sock_op operation, pj_status_t status)
+ {
+ //
+ // Respond to binding update.
+ // TODO: We should allow this to change over time, so we need to have some thread
+ // safety around initTransport.
+ //
+ if (operation == PJ_STUN_SOCK_BINDING_OP)
+ {
+ //
+ // NOTE: If you watch the PJNATH tracing, you will see binding requests occurring periodically, but
+ // it doesn't seem to enter here for each request. I suspect PJNATH checks to see if the mapped
+ // address has changed or not before firing a PJ_STUN_SOCK_BINDING_OP notification.
+ //
+ STUNTransport* t = reinterpret_cast<STUNTransport*>(pj_stun_sock_get_user_data(stunSock));
+ if (t)
+ {
+ t->updateBinding();
+ }
+ }
+ return PJ_TRUE;
+ }
+
+ //
+ // Integration methods for STUN transport.
+ //
+ static pj_status_t sendMsgImpl(pjsip_transport* transport, pjsip_tx_data* data, const pj_sockaddr_t* remoteAddress,
+ int remoteAddressLength, void* token, pjsip_transport_callback callback)
+ {
+ STUNTransport* t = reinterpret_cast<STUNTransport*>(transport->data);
+ return t->sendData(data, remoteAddress, remoteAddressLength, token, callback);
+ }
+
+ static pj_status_t shutdownImpl(pjsip_transport* transport)
+ {
+ //
+ // The STUN transport doesn't have a distinct shutdown.
+ //
+ return PJ_SUCCESS;
+ }
+
+ static pj_status_t destroyImpl(pjsip_transport* transport)
+ {
+ STUNTransport* t = reinterpret_cast<STUNTransport*>(transport->data);
+ t->destroy();
+ return PJ_SUCCESS;
+ }
+
+public:
+ STUNTransport(pjsip_endpoint* endpoint, const Ice::PropertiesPtr& props, const STUNModulePtr& stun) :
+ mDestroyed(false),
+ mEndpoint(endpoint),
+ mModule(stun),
+ mSocket(0)
+ {
+ assert(stun);
+ logger(Debug) << FUNLOG << " : initializing STUN transport";
+
+ //
+ // Get default configuration from library.
+ //
+ pj_stun_sock_cfg socketConfig;
+ pj_stun_sock_cfg_default(&socketConfig);
+
+ //
+ // Setup the callback structure. PJNATH will call these functions when the relevant events occur
+ // on the STUN socket. These are hooked up as basically NO-OPs for the moment. If it turns out
+ // that they are not necessary, the callbacks should be removed to reduce that slight bit of
+ // overhead.
+ //
+ pj_stun_sock_cb stunSockCB;
+ memset(&stunSockCB, 0, sizeof stunSockCB);
+ stunSockCB.on_status = &onStatus;
+ stunSockCB.on_rx_data = &onRxData;
+ stunSockCB.on_data_sent = &onDataSent;
+
+ //
+ // TODO: const table for property names, and allow for different bind addr for STUN enabled
+ // transports.
+ //
+ string bindAddr = props->getPropertyWithDefault("Sip.Transport.UdpBindAddr", "0.0.0.0:5060");
+ pj_sockaddr udpAddr;
+ pj_str_t pjAddrStr;
+ pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&pjAddrStr, bindAddr.c_str()), &udpAddr);
+
+ pj_status_t result = pj_stun_sock_create(mModule->getConfig(), 0, udpAddr.addr.sa_family, &stunSockCB,
+ &socketConfig, this, &mSocket);
+ if (fail(result))
+ {
+ const char* message = "Failed to initalize STUN socket.";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
+ //
+ // TODO: Throw!
+ //
+ }
+
+ string stunServerProperty = props->getProperty("Sip.Transport.STUN.Server");
+ auto_ptr<pj_str_t> stunServer;
+ if (!stunServerProperty.empty())
+ {
+ stunServer = auto_ptr<pj_str_t>(new pj_str_t);
+ pj_cstr(stunServer.get(), stunServerProperty.c_str());
+ logger(Debug) << FUNLOG << " proceeding with STUN server " << stunServerProperty;
+ }
+
+ pj_uint16_t port = props->getPropertyAsIntWithDefault("Sip.Transport.STUN.Port", PJ_STUN_PORT);
+ logger(Debug) << FUNLOG << " proceeding with STUN server " << stunServerProperty;
+
+ //
+ // TODO: More config! We may want to initialize and configure a resolver object.
+ //
+ result = pj_stun_sock_start(mSocket, stunServer.get(), port, 0);
+ if (fail(result))
+ {
+ const char* message = "Failed to start STUN socket.";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
+ }
+ pj_stun_sock_info socketInfo;
+ result = pj_stun_sock_get_info(mSocket, &socketInfo);
+ if (fail(result))
+ {
+ throw InternalInitializationException("get_info on STUN socket failed");
+ }
+ if (pj_sockaddr_has_addr(&socketInfo.mapped_addr))
+ {
+ updateBinding();
+ }
+ };
+
+ ~STUNTransport()
+ {
+ if (mSocket)
+ {
+ pj_stun_sock_destroy(mSocket);
+ }
+ };
+
+private:
+ boost::shared_mutex mLock;
+ bool mDestroyed;
+
+ pjsip_endpoint* mEndpoint;
+ STUNModulePtr mModule;
+ pj_stun_sock* mSocket;
+ boost::shared_ptr<pjsip_transport> mTransport;
+
+ void destroy()
+ {
+ bool doDestroy = false;
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ if (mSocket && !mDestroyed)
+ {
+ doDestroy = true;
+ mDestroyed = true;
+ }
+ }
+ if (doDestroy)
+ {
+ pj_status_t result = pj_stun_sock_destroy(mSocket);
+ if (fail(result))
+ {
+ logger(Error) << "unable to destroy STUN socket";
+ }
+ }
+ }
+
+ bool isRegistered()
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mTransport != 0;
+ }
+
+ boost::shared_ptr<pjsip_transport> getCurrentTransport()
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mLock);
+ return mTransport;
+ }
+
+ boost::shared_ptr<pjsip_transport> resetCurrentTransport(const boost::shared_ptr<pjsip_transport>& transport)
+ {
+ boost::unique_lock<boost::shared_mutex> lock(mLock);
+ boost::shared_ptr<pjsip_transport> current = mTransport;
+ mTransport = transport;
+ return current;
+ }
+
+ void updateBinding()
+ {
+ boost::shared_ptr<pjsip_transport> newTransport(new pjsip_transport);
+ initTransport(newTransport);
+ pj_status_t result = pjsip_transport_register(newTransport->tpmgr, newTransport.get());
+ if (fail(result))
+ {
+ logger(Error) << "Unable to register STUN enabled transport";
+ return;
+ }
+
+ //
+ // TODO: The order of register and destroy might have to be reversed for this to work properly.
+ //
+ boost::shared_ptr<pjsip_transport> oldTransport = resetCurrentTransport(newTransport);
+ if (oldTransport)
+ {
+ pjsip_transport_destroy(oldTransport.get());
+ }
+ }
+
+ void initTransport(const boost::shared_ptr<pjsip_transport>& transport)
+ {
+ assert(transport != 0);
+ memset(transport.get(), 0, sizeof *transport);
+ strcpy(transport->obj_name, "ASCF"); // TODO: proper name initialization.
+ transport->send_msg = &sendMsgImpl;
+ transport->do_shutdown = &shutdownImpl;
+ transport->destroy = &destroyImpl;
+ transport->endpt = mEndpoint;
+ transport->tpmgr = pjsip_endpt_get_tpmgr(mEndpoint);
+ transport->pool = mModule->getPool();
+ transport->data = this;
+
+ pj_status_t result = pj_atomic_create(transport->pool, 0, &transport->ref_cnt);
+ if (fail(result))
+ {
+ logger(Error) << "Unable to create reference count for STUN transport";
+ return;
+ }
+
+ result = pj_lock_create_recursive_mutex(transport->pool, transport->pool->obj_name, &transport->lock);
+ if (fail(result))
+ {
+ logger(Error) << "Unable to create mutex for STUN transport";
+ return;
+ }
+
+ transport->type_name = "ASCF_SIP_NAT";
+ transport->info = "Asterisk SCF PJNATH based SIP transport";
+ transport->remote_name.host = pj_str("0.0.0.0");
+ transport->remote_name.port = 0;
+
+ pj_stun_sock_info socketInfo;
+ result = pj_stun_sock_get_info(mSocket, &socketInfo);
+ if (fail(result))
+ {
+ logger(Error) << "Unable to get socket info for STUN transport";
+ return;
+ }
+
+ char buf[PJ_INET6_ADDRSTRLEN];
+ pj_strdup2(mModule->getPool(), &transport->local_name.host,
+ pj_sockaddr_print(&socketInfo.mapped_addr, buf, sizeof buf, 0));
+ transport->local_name.port = pj_sockaddr_get_port(&socketInfo.mapped_addr);
+ memcpy(&transport->local_addr, &socketInfo.bound_addr, sizeof &transport->local_addr);
+ transport->addr_len = sizeof transport->local_addr;
+ }
+
+ void dataReceived(void* packet, unsigned packetLength, const pj_sockaddr_t* sourceAddress, unsigned addressLength)
+ {
+ boost::shared_ptr<pjsip_transport> transport(getCurrentTransport());
+ pjsip_rx_data* data = reinterpret_cast<pjsip_rx_data*>(pj_pool_zalloc(mModule->getPool(), sizeof pjsip_rx_data));
+ data->tp_info.pool = mModule->getPool();
+ data->tp_info.transport = transport.get();
+ data->tp_info.tp_data = 0;
+ data->tp_info.op_key.rdata = data;
+ pj_ioqueue_op_key_init(&(data->tp_info.op_key.op_key), sizeof data->tp_info.op_key.op_key);
+
+
+ pj_gettimeofday(&data->pkt_info.timestamp);
+ if (packetLength > sizeof data->pkt_info.packet)
+ {
+ assert(false); // XXX houston, we have a problem.
+ }
+ data->pkt_info.len = packetLength;
+ data->pkt_info.zero = 0;
+ memcpy(data->pkt_info.packet, reinterpret_cast<const char*>(packet), data->pkt_info.len);
+ memcpy(&data->pkt_info.src_addr, reinterpret_cast<const pj_sockaddr*>(sourceAddress), addressLength);
+ data->pkt_info.src_addr_len = addressLength;
+ pj_sockaddr_print(&data->pkt_info.src_addr, data->pkt_info.src_name,
+ sizeof data->pkt_info.src_name, 0);
+ data->pkt_info.src_port = pj_sockaddr_get_port(&data->pkt_info.src_addr);
+ pj_size_t bytesReceived = pjsip_tpmgr_receive_packet(transport->tpmgr, data);
+ if (bytesReceived < 0)
+ {
+ assert(false);
+ }
+ }
+
+ pj_status_t sendData(pjsip_tx_data* data, const pj_sockaddr_t* remoteAddress, int remoteAddressLength,
+ void* token, pjsip_transport_callback callback)
+ {
+ return pj_stun_sock_sendto(mSocket, &data->op_key.key, &data->buf.start, data->buf.cur - data->buf.start, 0,
+ remoteAddress, remoteAddressLength);
+ }
+};
+
static void *monitorThread(void *endpt)
{
- pjsip_endpoint *endpoint = static_cast<pjsip_endpoint *> (endpt);
+ PJSipManager* endpoint = reinterpret_cast<PJSipManager*> (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);
+ endpoint->handleEvents();
}
return NULL;
}
-PJSipManager::PJSipManager(const Ice::PropertiesPtr& props)
+PJSipManager::PJSipManager(const Ice::PropertiesPtr& props) :
+ mEndpoint(0),
+ mSessionModule(0),
+ mLoggingModule(0),
+ mPjThread(0),
+ mMemoryPool(0)
{
+ memset(&mCachingPool, 0, sizeof(mCachingPool));
+
pj_status_t status = pj_init();
- if (status != PJ_SUCCESS)
+ if (fail(status))
{
- lg(Error) << "Failed to Initialize PJSIP";
+ const char* message = "Failed to Initialize PJSIP";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
}
// 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);
+
+
+ //
+ // Careful! This was after the setTransports call, so reordering it might cause issues.
+ //
mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
if (!mMemoryPool)
{
- lg(Error) << "Failed to create a memory pool";
+ const char* message = "Failed to create a memory pool";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
+ }
+
+ //
+ // Initialize the global STUN configuration if it is enabled.
+ //
+ if (props)
+ {
+ if (props->getPropertyAsIntWithDefault("Sip.Transport.STUN.Enable", 0) == 1)
+ {
+ mSTUN = boost::shared_ptr<STUNModule>(new STUNModule(mMemoryPool, mCachingPool, props));
+ }
+ mTransports.push_back(boost::shared_ptr<Transport>(new STUNTransport(mEndpoint, props, mSTUN)));
+ }
+ else
+ {
+ mTransports.push_back(boost::shared_ptr<Transport>(new UDPTransport(mEndpoint, props)));
}
+
status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
- mEndpoint, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &mPjThread);
- if (status != PJ_SUCCESS)
+ this, PJ_THREAD_DEFAULT_STACK_SIZE * 2, 0, &mPjThread);
+ if (fail(status))
{
- lg(Error) << "Failed to create SIP maintenance thread";
+ const char* message = "Failed to create SIP maintenance thread";
+ logger(Error) << message;
+ throw InternalInitializationException(message);
}
}
+PJSipManager::~PJSipManager()
+{
+ //
+ // TODO: Surely there are some cleanups required here.
+ //
+}
+
void PJSipManager::registerSessionModule(const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
const AsteriskSCF::SmartProxy::SmartProxy<
AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
@@ -87,6 +618,19 @@ void PJSipManager::registerLoggingModule()
mLoggingModule = new PJSipLoggingModule(mEndpoint);
}
+void PJSipManager::handleEvents()
+{
+ //
+ // XXX: The polling for the two pools should probably be occurring in separate threads.
+ //
+ if (mSTUN)
+ {
+ mSTUN->poll();
+ }
+ const pj_time_val delay = {0, 10};
+ pjsip_endpt_handle_events(mEndpoint, &delay);
+}
+
PJSipSessionModule *PJSipManager::getSessionModule()
{
return mSessionModule;
@@ -97,43 +641,6 @@ PJSipLoggingModule *PJSipManager::getLoggingModule()
return mLoggingModule;
}
-bool PJSipManager::setTransports(pjsip_endpoint *endpoint, const 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;
-}
-
}; //End namespace SipSessionManager
}; //End namespace AsteriskSCF
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 1dc7b02..3f08ae5 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -36,18 +36,33 @@ namespace AsteriskSCF
namespace SipSessionManager
{
+//
+// Forward declarations.
+//
+class STUNModule;
+
+/**
+ * Base class for transport objects allocated during SIP endpoint initialization. The PJSIP manager
+ * does not perform any operations on these objects at the moment.
+ **/
+class Transport
+{
+public:
+ virtual ~Transport() {}
+};
+
/**
- * This class is responsible for providing
- * access to the pjsip_endpt for the Asterisk
- * SCF SIP component.
+ * This class is responsible for providing access to the pjsip_endpoint for the Asterisk SCF SIP component.
*
- * In addition, it provides some common functions
- * that many SIP services will use.
+ * In addition, it provides some common functions that many SIP services will use.
*/
class PJSipManager
{
public:
PJSipManager(const Ice::PropertiesPtr& props);
+
+ ~PJSipManager();
+
/**
* Get a handle to the PJSipEndpoint for operations
* that may require it
@@ -81,17 +96,19 @@ public:
* for logging incoming and outgoing SIP messages
*/
void registerLoggingModule();
+
+ void handleEvents();
+
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;
- bool setTransports(pjsip_endpoint *endpoint, const Ice::PropertiesPtr& props);
+ boost::shared_ptr<STUNModule> mSTUN;
+ std::vector<boost::shared_ptr<Transport> > mTransports;
};
}; //End namespace SipSessionManager
diff --git a/src/PJSipModule.cpp b/src/PJSipModule.cpp
index 0465a50..4dabfc6 100644
--- a/src/PJSipModule.cpp
+++ b/src/PJSipModule.cpp
@@ -13,6 +13,8 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
+
+#include <pjlib.h>
#include <AsteriskSCF/logger.h>
#include <IceUtil/UUID.h>
diff --git a/src/PJSipModule.h b/src/PJSipModule.h
index df38f5a..706a582 100644
--- a/src/PJSipModule.h
+++ b/src/PJSipModule.h
@@ -15,12 +15,11 @@
*/
#pragma once
-
+#include <pjlib.h>
#include <string>
-
#include <pjsip.h>
#include <pjsip_ua.h>
-#include <pjlib.h>
+
#include <SipStateReplicationIf.h>
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 58a30c5..cc4f9c6 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -13,6 +13,7 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <IceUtil/UUID.h>
#include <AsteriskSCF/Core/Endpoint/EndpointIf.h>
@@ -64,7 +65,7 @@ public:
{
router->end_routeSession(r);
}
- catch (const DestinationNotFoundException &)
+ catch (const DestinationNotFoundException&)
{
pjsip_inv_end_session(mInvSession, 404, NULL, &mTData);
pjsip_inv_send_msg(mInvSession, mTData);
@@ -87,14 +88,14 @@ public:
ConnectBridgedSessionsCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata, const SipSessionPtr& session)
: mInvSession(inv_session), mRData(rdata), mSession(session) { }
- void callback(const Ice::AsyncResultPtr &r)
+ void callback(const Ice::AsyncResultPtr& r)
{
SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
try
{
router->end_connectBridgedSessions(r);
}
- catch (const std::exception &e)
+ catch (const std::exception& e)
{
lg(Debug) << "ConnectBridgedSessionsCallback sending 400 due to exception: " << e.what();
pjsip_dlg_respond(mInvSession->dlg, mRData, 400, NULL, NULL, NULL);
@@ -121,14 +122,14 @@ public:
const SipSessionPtr& session, const std::string& target)
: mInvSession(inv_session), mRData(rdata), mSession(session), mTarget(target) { }
- void callback(const Ice::AsyncResultPtr &r)
+ void callback(const Ice::AsyncResultPtr& r)
{
SessionRouterPrx router = SessionRouterPrx::uncheckedCast(r->getProxy());
try
{
router->end_connectBridgedSessions(r);
}
- catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException &)
+ catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException&)
{
lg(Debug) << "ConnectBridgedSessionsWithDestination sending 404 due to destination not found for target: "
<< mTarget;
@@ -136,7 +137,7 @@ public:
pjsip_dlg_respond(mInvSession->dlg, mRData, 404, NULL, NULL, NULL);
return;
}
- catch (const std::exception &e)
+ catch (const std::exception& e)
{
lg(Debug) << "ConnectBridgedSessionsWithDestination sending 400 due to exception: " << e.what();
pjsip_dlg_respond(mInvSession->dlg, mRData, 400, NULL, NULL, NULL);
@@ -525,7 +526,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
//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("");
+ std::string destination;
if (PJSIP_URI_SCHEME_IS_SIP(ruri) || PJSIP_URI_SCHEME_IS_SIPS(ruri))
{
pjsip_sip_uri *sipRuri = (pjsip_sip_uri *)pjsip_uri_get_uri(ruri);
@@ -562,7 +563,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
mSessionRouter->begin_routeSession(session->getSessionProxy(), destination, d);
}
}
- catch (const Ice::CommunicatorDestroyedException &)
+ catch (const Ice::CommunicatorDestroyedException&)
{
// Everything else doesn't really map so they just become internal server errors
pjsip_inv_end_session(inv_session, 500, NULL, &tdata);
@@ -703,7 +704,7 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
mSessionRouter->begin_connectBridgedSessions(session->getSessionProxy(),
other_session->getSessionProxy(), d);
}
- catch (const Ice::CommunicatorDestroyedException &)
+ catch (const Ice::CommunicatorDestroyedException&)
{
lg(Debug) << "handleRefer() sending 503 due to communicator destruction";
pjsip_dlg_respond(inv->dlg, rdata, 503, NULL, NULL, NULL);
@@ -727,7 +728,7 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
lg(Debug) << "handleRefer() calling router connectBridgedSessionsWithDestination(). ";
mSessionRouter->begin_connectBridgedSessionsWithDestination(session->getSessionProxy(), target, d);
}
- catch (const Ice::CommunicatorDestroyedException &)
+ catch (const Ice::CommunicatorDestroyedException&)
{
lg(Debug) << "handleRefer() sending 503 due to communicator destruction";
pjsip_dlg_respond(inv->dlg, rdata, 503, NULL, NULL, NULL);
@@ -827,7 +828,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
newCallback_SessionListener_ringing(cb, &ListenerCallback::failure);
(*listener)->begin_ringing(session->getSessionProxy(), ringingCB);
}
- catch (const Ice::Exception &ex)
+ catch (const Ice::Exception& ex)
{
lg(Error) << "Ice exception when attempting to relate ringing state: " << ex.what();
}
@@ -836,7 +837,8 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
else if (respCode == 183)
{
lg(Debug) << "Got 183 response";
- AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response = new AsteriskSCF::SessionCommunications::V1::ResponseCode();
+ 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;
@@ -850,7 +852,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
newCallback_SessionListener_progressing(cb, &ListenerCallback::failure);
(*listener)->begin_progressing(session->getSessionProxy(), response, progressingCB);
}
- catch (const Ice::Exception &ex)
+ catch (const Ice::Exception& ex)
{
lg(Error) << "Ice exception when attempting to relate progressing state: " << ex.what();
}
@@ -873,7 +875,7 @@ void PJSipSessionModule::handleInviteResponse(pjsip_inv_session *inv,
newCallback_SessionListener_connected(cb, &ListenerCallback::failure);
(*listener)->begin_connected(session->getSessionProxy(), connectedCB);
}
- catch (const Ice::Exception &ex)
+ catch (const Ice::Exception& ex)
{
lg(Error) << "Ice exception when attempting to relate connected state: " << ex.what();
}
@@ -925,7 +927,7 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
{
(*listener)->stopped(session->getSessionProxy(), response);
}
- catch (const Ice::Exception &ex)
+ catch (const Ice::Exception& ex)
{
lg(Error) << "Ice exception when attempting to relate stopped state: " << ex.what();
}
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 58e4ff6..ddfcaa5 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -13,7 +13,7 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
-
+#include <pjlib.h>
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index ea072c4..46791b3 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -14,6 +14,7 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include "SipEndpoint.h"
#include "SipEndpointFactory.h"
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index cd003e3..7d301f1 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -14,6 +14,8 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
+
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
@@ -272,41 +274,46 @@ AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx SipSession::getEndpoi
*/
AsteriskSCF::SessionCommunications::V1::SessionInfoPtr SipSession::getInfo(const Ice::Current&)
{
- AsteriskSCF::SessionCommunications::V1::SessionInfoPtr sessioninfo =
- new AsteriskSCF::SessionCommunications::V1::SessionInfo();
-
- /* TODO: Utilize locking so this becomes safe
- if (!mImplPriv->mInviteSession || mImplPriv->mInviteSession->state == PJSIP_INV_STATE_NULL)
- {
- sessioninfo->currentState = "ready";
- }
- else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CALLING)
- {
- sessioninfo->currentState = "outbound";
- }
- else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_INCOMING)
- {
- sessioninfo->currentState = "inbound";
- }
- else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_EARLY)
- {
- sessioninfo->currentState = "early";
- }
- else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CONNECTING)
- {
- sessioninfo->currentState = "connecting";
- }
- else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_CONFIRMED)
- {
- sessioninfo->currentState = "connected";
- }
- else if (mImplPriv->mInviteSession->state == PJSIP_INV_STATE_DISCONNECTED)
- {
- sessioninfo->currentState = "disconnected";
- }
- */
-
- return sessioninfo;
+
+ pjsip_inv_state state = PJSIP_INV_STATE_NULL;
+ {
+ boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+ if (mImplPriv->mInviteSession)
+ {
+ state = mImplPriv->mInviteSession->state;
+ }
+ }
+ std::string stateString;
+ switch(state)
+ {
+ case PJSIP_INV_STATE_NULL:
+ stateString = "ready";
+ break;
+ case PJSIP_INV_STATE_CALLING:
+ stateString = "outbound";
+ break;
+ case PJSIP_INV_STATE_INCOMING:
+ stateString = "inbound";
+ break;
+ case PJSIP_INV_STATE_EARLY:
+ stateString = "early";
+ break;
+ case PJSIP_INV_STATE_CONNECTING:
+ stateString = "connecting";
+ break;
+ case PJSIP_INV_STATE_CONFIRMED:
+ stateString = "connected";
+ break;
+ case PJSIP_INV_STATE_DISCONNECTED:
+ stateString = "disconnected";
+ break;
+ default:
+ stateString = "ready";
+ }
+ AsteriskSCF::SessionCommunications::V1::SessionInfoPtr sessionInfo
+ = new AsteriskSCF::SessionCommunications::V1::SessionInfo();
+ sessionInfo->currentState = stateString;
+ return sessionInfo;
}
/**
@@ -366,7 +373,6 @@ void SipSession::removeBridge(const AsteriskSCF::SessionCommunications::V1::Sess
}
setBridge(0);
-
removeListener(listener, current);
}
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
index 34d4128..6c6c068 100644
--- a/src/SipSessionManagerApp.cpp
+++ b/src/SipSessionManagerApp.cpp
@@ -14,6 +14,8 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
+
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
#include <IceBox/IceBox.h>
@@ -21,8 +23,6 @@
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
-#include <pjlib.h>
-
#include <AsteriskSCF/Core/Routing/RoutingIf.h>
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
diff --git a/src/SipSessionManagerEndpointLocator.cpp b/src/SipSessionManagerEndpointLocator.cpp
index ff2439c..ab5b998 100644
--- a/src/SipSessionManagerEndpointLocator.cpp
+++ b/src/SipSessionManagerEndpointLocator.cpp
@@ -14,6 +14,7 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
diff --git a/src/SipSessionManagerEventPublisher.cpp b/src/SipSessionManagerEventPublisher.cpp
index 794eb5b..231b2ac 100644
--- a/src/SipSessionManagerEventPublisher.cpp
+++ b/src/SipSessionManagerEventPublisher.cpp
@@ -14,6 +14,8 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
+
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
diff --git a/src/SipStateReplicatorApp.cpp b/src/SipStateReplicatorApp.cpp
index fae2b3b..e41c414 100644
--- a/src/SipStateReplicatorApp.cpp
+++ b/src/SipStateReplicatorApp.cpp
@@ -14,6 +14,7 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
#include <IceStorm/IceStorm.h>
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index 36c09e4..52b0c5a 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -14,6 +14,7 @@
* at the top of the source tree.
*/
+#include <pjlib.h>
#include <IceUtil/UUID.h>
#include <boost/thread.hpp>
@@ -38,7 +39,8 @@ public:
SipStateReplicatorItem() { }
~SipStateReplicatorItem()
{
- // Since we are acting in a standby fashion outside influences will not have caused our pjsip structures to go away so we must do it ourselves
+ // Since we are acting in a standby fashion outside influences will not have caused our pjsip structures to go
+ // away so we must do it ourselves
pjsip_inv_terminate(mSession->getInviteSession(), 500, PJ_FALSE);
// Now that pjsip is taken care of we can drop the session itself and consider life good
@@ -128,7 +130,8 @@ public:
// that we change them
pj_str_t localUri = pj_str((char*)dialog->mLocalUri.c_str());
pj_str_t remoteUri = pj_str((char*)dialog->mRemoteUri.c_str());
- if ((pjsip_dlg_create_uac(pjsip_ua_instance(), &localUri, &localUri, &remoteUri, &remoteUri, &localDialog)) != PJ_SUCCESS)
+ if ((pjsip_dlg_create_uac(pjsip_ua_instance(), &localUri, &localUri, &remoteUri, &remoteUri,
+ &localDialog)) != PJ_SUCCESS)
{
// For some reason we failed to create a dialog and can go no further ;(
continue;
commit 827fc662e122ea00689893d167e77a46adf47a15
Author: Brent Eagles <beagles at digium.com>
Date: Mon Mar 21 10:35:11 2011 -0230
* Update method signatures to pass smart pointers, references and proxies
by const ref.
* Split some long lines
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index 22b5955..8da907b 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -44,7 +44,7 @@ static void *monitorThread(void *endpt)
return NULL;
}
-PJSipManager::PJSipManager(Ice::PropertiesPtr props)
+PJSipManager::PJSipManager(const Ice::PropertiesPtr& props)
{
pj_status_t status = pj_init();
if (status != PJ_SUCCESS)
@@ -70,11 +70,12 @@ PJSipManager::PJSipManager(Ice::PropertiesPtr props)
}
}
-void PJSipManager::registerSessionModule(boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
- AsteriskSCF::System::Component::V1::ReplicaPtr replica
+void PJSipManager::registerSessionModule(const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
+ const AsteriskSCF::SmartProxy::SmartProxy<
+ AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica
)
{
mSessionModule = new PJSipSessionModule(mEndpoint, endpointFactoryPtr, sessionRouter,
@@ -96,7 +97,7 @@ PJSipLoggingModule *PJSipManager::getLoggingModule()
return mLoggingModule;
}
-bool PJSipManager::setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr props)
+bool PJSipManager::setTransports(pjsip_endpoint *endpoint, const Ice::PropertiesPtr& props)
{
//XXX We'll also want to allow for TCP and TLS-specific
//addresses to be specified.
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index eaedf0d..1dc7b02 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -47,7 +47,7 @@ namespace SipSessionManager
class PJSipManager
{
public:
- PJSipManager(Ice::PropertiesPtr props);
+ PJSipManager(const Ice::PropertiesPtr& props);
/**
* Get a handle to the PJSipEndpoint for operations
* that may require it
@@ -68,11 +68,12 @@ public:
* Register the PJSipSessionModule, responsible
* for basic call handling
*/
- void registerSessionModule(boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
- AsteriskSCF::System::Component::V1::ReplicaPtr replica
+ void registerSessionModule(const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
+ sessionRouter,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica
);
/**
@@ -90,7 +91,7 @@ private:
pj_pool_t *mMemoryPool;
pjsip_transport *mUdpTransport;
- bool setTransports(pjsip_endpoint *endpoint, Ice::PropertiesPtr props);
+ bool setTransports(pjsip_endpoint *endpoint, const Ice::PropertiesPtr& props);
};
}; //End namespace SipSessionManager
diff --git a/src/PJSipModule.cpp b/src/PJSipModule.cpp
index c53a60e..0465a50 100644
--- a/src/PJSipModule.cpp
+++ b/src/PJSipModule.cpp
@@ -35,7 +35,8 @@ namespace SipSessionManager
//to retrieve PJSIP URI strings.
const int URI_SIZE = 64;
-PJSipDialogModInfo::PJSipDialogModInfo(pjsip_dialog *dialog) : mDialogState(new SipDialogStateItem) , mNeedsReplication(true), mNeedsRemoval(false)
+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?
@@ -98,7 +99,8 @@ void PJSipDialogModInfo::updateDialogState(pjsip_dialog *dialog)
mNeedsReplication = true;
}
-PJSipTransactionModInfo::PJSipTransactionModInfo(pjsip_transaction *transaction) : mTransactionState(new SipTransactionStateItem), mNeedsReplication(true), mNeedsRemoval(false)
+PJSipTransactionModInfo::PJSipTransactionModInfo(pjsip_transaction *transaction) :
+ mTransactionState(new SipTransactionStateItem), mNeedsReplication(true), mNeedsRemoval(false)
{
mTransactionState->key = IceUtil::generateUUID();
updateTransactionState(transaction);
@@ -112,7 +114,8 @@ PJSipTransactionModInfo::~PJSipTransactionModInfo()
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->mIsClient =
+ (transaction->role == PJSIP_ROLE_UAC || transaction->role == PJSIP_UAC_ROLE) ? true : false;
mTransactionState->mCurrentState = transactionStateTranslate(transaction->state);
mNeedsReplication = true;
}
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 3080204..58a30c5 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -84,7 +84,7 @@ typedef IceUtil::Handle<RouteSessionCallback> RouteSessionCallbackPtr;
class ConnectBridgedSessionsCallback : public IceUtil::Shared
{
public:
- ConnectBridgedSessionsCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata, SipSessionPtr session)
+ ConnectBridgedSessionsCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata, const SipSessionPtr& session)
: mInvSession(inv_session), mRData(rdata), mSession(session) { }
void callback(const Ice::AsyncResultPtr &r)
@@ -117,7 +117,8 @@ typedef IceUtil::Handle<ConnectBridgedSessionsCallback> ConnectBridgedSessionsCa
class ConnectBridgedSessionsWithDestinationCallback : public IceUtil::Shared
{
public:
- ConnectBridgedSessionsWithDestinationCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata, SipSessionPtr session, std::string target)
+ ConnectBridgedSessionsWithDestinationCallback(pjsip_inv_session *inv_session, pjsip_rx_data *rdata,
+ const SipSessionPtr& session, const std::string& target)
: mInvSession(inv_session), mRData(rdata), mSession(session), mTarget(target) { }
void callback(const Ice::AsyncResultPtr &r)
@@ -129,7 +130,8 @@ public:
}
catch (const AsteriskSCF::Core::Routing::V1::DestinationNotFoundException &)
{
- lg(Debug) << "ConnectBridgedSessionsWithDestination sending 404 due to destination not found for target: "<< mTarget;
+ lg(Debug) << "ConnectBridgedSessionsWithDestination sending 404 due to destination not found for target: "
+ << mTarget;
pjsip_dlg_respond(mInvSession->dlg, mRData, 404, NULL, NULL, NULL);
return;
@@ -158,8 +160,8 @@ typedef IceUtil::Handle<ConnectBridgedSessionsWithDestinationCallback> ConnectBr
class ListenerCallback : public IceUtil::Shared
{
public:
- ListenerCallback(const std::string name) : mCallbackName(name) {}
- void failure(const Ice::Exception &ex)
+ ListenerCallback(const std::string& name) : mCallbackName(name) {}
+ void failure(const Ice::Exception& ex)
{
lg(Error) << "Ice exception when attempting to relate " << mCallbackName << " state: " << ex.what();
}
@@ -170,8 +172,7 @@ private:
typedef IceUtil::Handle<ListenerCallback> ListenerCallbackPtr;
PJSipSessionModInfo::PJSipSessionModInfo(pjsip_inv_session *inv_session,
- SipSessionPtr session)
- :
+ const SipSessionPtr& session) :
mSessionState(new SipSessionStateItem),
mInviteState(new SipInviteSessionStateItem),
mNeedsReplication(true),
@@ -233,7 +234,7 @@ SipSessionPtr PJSipSessionModInfo::getSessionPtr()
return mSession;
}
-void PJSipSessionModInfo::setSessionPtr(SipSessionPtr sessionPtr)
+void PJSipSessionModInfo::setSessionPtr(const SipSessionPtr& sessionPtr)
{
mSession = sessionPtr;
}
@@ -365,7 +366,8 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
lg(Error) << "No endpoint for oneway invocation of setState() for state replication.";
}
- AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator = AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(oneway);
+ AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator =
+ AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(oneway);
try
{
@@ -389,7 +391,8 @@ void PJSipSessionModule::replicateState(PJSipDialogModInfo *dlgInfo, PJSipTransa
lg(Error) << "No endpoint for oneway invocation of removeState() for state replication.";
}
- AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator = AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(oneway);
+ AsteriskSCF::SIP::V1::SipStateReplicatorPrx oneWayStateReplicator =
+ AsteriskSCF::SIP::V1::SipStateReplicatorPrx::uncheckedCast(oneway);
try
{
@@ -548,7 +551,8 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
{
if (replaced_dlg)
{
- // For attended transfers we need to contact the routing service which should then (hopefully) replace the other session
+ // For attended transfers we need to contact the routing service which should then (hopefully) replace the
+ // other session
}
else
{
@@ -570,7 +574,8 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
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));
+ pjsip_generic_string_hdr *refer_to =
+ static_cast<pjsip_generic_string_hdr *>(pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL));
lg(Debug) << "Handling a REFER";
if (!refer_to)
@@ -618,12 +623,15 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
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);
+ 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));
+ // 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=");
@@ -692,7 +700,8 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsCallback::callback);
lg(Debug) << "handleRefer() calling router connectBridgedSessions(). ";
- mSessionRouter->begin_connectBridgedSessions(session->getSessionProxy(), other_session->getSessionProxy(), d);
+ mSessionRouter->begin_connectBridgedSessions(session->getSessionProxy(),
+ other_session->getSessionProxy(), d);
}
catch (const Ice::CommunicatorDestroyedException &)
{
@@ -711,7 +720,8 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
{
PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)inv->mod_data[mModule.id];
SipSessionPtr session = session_mod_info->getSessionPtr();
- ConnectBridgedSessionsWithDestinationCallbackPtr cb(new ConnectBridgedSessionsWithDestinationCallback(inv, rdata, session, target));
+ ConnectBridgedSessionsWithDestinationCallbackPtr cb(
+ new ConnectBridgedSessionsWithDestinationCallback(inv, rdata, session, target));
Ice::CallbackPtr d = Ice::newCallback(cb, &ConnectBridgedSessionsWithDestinationCallback::callback);
lg(Debug) << "handleRefer() calling router connectBridgedSessionsWithDestination(). ";
@@ -744,7 +754,8 @@ pj_bool_t PJSipSessionModule::on_rx_request(pjsip_rx_data *rdata)
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
+ // We are essentially stopping the pjsip code from sending a 500 here, but this will actually be handled
+ // within the transaction code
break;
}
default:
@@ -888,7 +899,8 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
return;
}
SipSessionPtr session = session_mod_info->getSessionPtr();
- AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response = new AsteriskSCF::SessionCommunications::V1::ResponseCode();
+ AsteriskSCF::SessionCommunications::V1::ResponseCodePtr response =
+ new AsteriskSCF::SessionCommunications::V1::ResponseCode();
if (inv->cause == 486)
{
response->isdnCode = 17;
@@ -904,7 +916,8 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
}
std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx> listeners = session->getListeners();
lg(Debug) << "Relating stopped state to " << listeners.size() << " listeners";
- for (std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::iterator listener = listeners.begin();
+ for (std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>::iterator listener =
+ listeners.begin();
listener != listeners.end();
++listener)
{
@@ -941,7 +954,8 @@ void PJSipSessionModule::invOnStateChanged(pjsip_inv_session *inv, pjsip_event *
replicateState(NULL, NULL, session_mod_info);
//Compare branches to see if this got handled by the transaction layer.
- if (inv->invite_tsx && pj_strcmp(&event->body.rx_msg.rdata->msg_info.via->branch_param, &inv->invite_tsx->branch) != 0)
+ 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);
@@ -972,26 +986,22 @@ void PJSipSessionModule::invOnNewSession(pjsip_inv_session *inv, pjsip_event *ev
void PJSipSessionModule::invOnTsxStateChanged(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e)
{
- if (tsx->role == PJSIP_ROLE_UAS && tsx->state == PJSIP_TSX_STATE_TRYING && !pjsip_method_cmp(&tsx->method, pjsip_get_refer_method()))
+ if (tsx->role == PJSIP_ROLE_UAS && tsx->state == PJSIP_TSX_STATE_TRYING &&
+ !pjsip_method_cmp(&tsx->method, pjsip_get_refer_method()))
{
handleRefer(inv, e->body.tsx_state.src.rdata);
}
- //This will be our key point for updating transaction state.
- //This function will not be called until after a module has registered
- //itself as the transaction user, so this won't be called on the initial
- //INVITE we receive.
+ //This will be our key point for updating transaction state. This function will not be called until after a module
+ //has registered itself as the transaction user, so this won't be called on the initial INVITE we receive.
//
- //Having taken a look at the pjsip inv_session code, the transaction state
- //changed callback is called *after* the inv_state_changed callback. This
- //means that on both reception and transmission of requests, this is called
- //last, meaning this is the prime spot to do state replication of dialogs,
- //transactions, sessions.
+ //Having taken a look at the pjsip inv_session code, the transaction state changed callback is called *after* the
+ //inv_state_changed callback. This means that on both reception and transmission of requests, this is called last,
+ //meaning this is the prime spot to do state replication of dialogs, transactions, sessions.
//
- //There is one exception. If we receive an ACK for an INVITE transaction and
- //the ACK has a different Via branch parameter than the INVITE and its response,
- //then this callback will not be called at all, and we will need to perform the
- //proper state replication in the invOnStateChanged function. This can be
- //done simply by calling this function from there.
+ //There is one exception. If we receive an ACK for an INVITE transaction and the ACK has a different Via branch
+ //parameter than the INVITE and its response, then this callback will not be called at all, and we will need to
+ //perform the proper state replication in the invOnStateChanged function. This can be done simply by calling this
+ //function from there.
PJSipTransactionModInfo *tsx_mod_info = static_cast<PJSipTransactionModInfo *> (tsx->mod_data[mModule.id]);
// TODO: Determine if this is perfectly acceptable, since it occurs when the call is going bye bye
@@ -1082,11 +1092,14 @@ void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t st
FormatDiscoverySDPPtr params = new FormatDiscoverySDP();
params->category = "media_format";
params->payload = pj_strtoul(&remote_sdp->media[stream]->desc.fmt[format]);
- params->type = std::string(pj_strbuf(&remote_sdp->media[stream]->desc.media), pj_strlen(&remote_sdp->media[stream]->desc.media));
+ params->type = std::string(pj_strbuf(&remote_sdp->media[stream]->desc.media),
+ pj_strlen(&remote_sdp->media[stream]->desc.media));
- // Some devices rely solely on the payload for known formats (such as PCMU) so the following format parameters are optional
+ // Some devices rely solely on the payload for known formats (such as PCMU) so the following format
+ // parameters are optional
const pjmedia_sdp_attr *attr;
- if ((attr = pjmedia_sdp_media_find_attr2(remote_sdp->media[stream], "rtpmap", &remote_sdp->media[stream]->desc.fmt[format])))
+ if ((attr = pjmedia_sdp_media_find_attr2(remote_sdp->media[stream], "rtpmap",
+ &remote_sdp->media[stream]->desc.fmt[format])))
{
pjmedia_sdp_rtpmap *rtpmap;
if ((pjmedia_sdp_attr_to_rtpmap(inv->pool_active, attr, &rtpmap)) == PJ_SUCCESS)
@@ -1097,7 +1110,8 @@ void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t st
}
// Next we move on to the format specific parameters
- if ((attr = pjmedia_sdp_media_find_attr2(remote_sdp->media[stream], "fmtp", &remote_sdp->media[stream]->desc.fmt[format])))
+ if ((attr = pjmedia_sdp_media_find_attr2(remote_sdp->media[stream], "fmtp",
+ &remote_sdp->media[stream]->desc.fmt[format])))
{
pjmedia_sdp_fmtp fmtp;
if ((pjmedia_sdp_attr_get_fmtp(attr, &fmtp)) == PJ_SUCCESS)
@@ -1110,7 +1124,8 @@ void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t st
// Next up are attributes that are not specific to the format, such as ptime
for (unsigned int attribute = 0; attribute < remote_sdp->media[stream]->attr_count; attribute++)
{
- // Attributes we already touch above OR know aren't helpful to the media format component don't need to be given to it, obviously
+ // Attributes we already touch above OR know aren't helpful to the media format component don't need to
+ // be given to it, obviously
if (!pj_strcmp2(&remote_sdp->media[stream]->attr[attribute]->name, "rtpmap") ||
!pj_strcmp2(&remote_sdp->media[stream]->attr[attribute]->name, "fmtp") ||
!pj_strcmp2(&remote_sdp->media[stream]->attr[attribute]->name, "rtcp") ||
@@ -1121,8 +1136,10 @@ void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t st
continue;
}
- std::string parameter = std::string(pj_strbuf(&remote_sdp->media[stream]->attr[attribute]->name), pj_strlen(&remote_sdp->media[stream]->attr[attribute]->name)) + ':' +
- std::string(pj_strbuf(&remote_sdp->media[stream]->attr[attribute]->value), pj_strlen(&remote_sdp->media[stream]->attr[attribute]->value));
+ std::string parameter = std::string(pj_strbuf(&remote_sdp->media[stream]->attr[attribute]->name),
+ pj_strlen(&remote_sdp->media[stream]->attr[attribute]->name)) + ':' +
+ std::string(pj_strbuf(&remote_sdp->media[stream]->attr[attribute]->value),
+ pj_strlen(&remote_sdp->media[stream]->attr[attribute]->value));
params->parameters.push_back(parameter);
}
@@ -1130,7 +1147,8 @@ void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t st
{
MediaFormatServicePrx service = MediaFormatServicePrx::uncheckedCast(mServiceLocator->locate(params));
- // It is entirely possible for the service locator to not find a service that knows about this media format
+ // It is entirely possible for the service locator to not find a service that knows about this media
+ // format
if (service != 0)
{
FormatPtr format = FormatPtr::dynamicCast(service->getFormat(params));
@@ -1145,7 +1163,8 @@ void PJSipSessionModule::invOnMediaUpdate(pjsip_inv_session *inv, pj_status_t st
}
}
-pjsip_redirect_op PJSipSessionModule::invOnRedirected(pjsip_inv_session *inv, const pjsip_uri *target, const pjsip_event *e)
+pjsip_redirect_op PJSipSessionModule::invOnRedirected(pjsip_inv_session *inv, const pjsip_uri *target,
+ const pjsip_event *e)
{
//stub
return PJSIP_REDIRECT_REJECT;
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index 5569170..a1fdde3 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -39,11 +39,11 @@ namespace SipSessionManager
class PJSipSessionModInfo
{
public:
- PJSipSessionModInfo(pjsip_inv_session *inv_session, SipSessionPtr);
+ PJSipSessionModInfo(pjsip_inv_session *inv_session, const SipSessionPtr&);
~PJSipSessionModInfo();
void updateSessionState(pjsip_inv_session *inv_session);
SipSessionPtr getSessionPtr();
- void setSessionPtr(SipSessionPtr sessionPtr);
+ void setSessionPtr(const SipSessionPtr& sessionPtr);
SipSessionStateItemPtr mSessionState;
SipInviteSessionStateItemPtr mInviteState;
bool mNeedsReplication;
@@ -57,11 +57,12 @@ private:
class PJSipSessionModule : public PJSipModule
{
public:
- PJSipSessionModule(pjsip_endpoint *endpt, boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
- AsteriskSCF::System::Component::V1::ReplicaPtr replica);
+ PJSipSessionModule(pjsip_endpoint *endpt, const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>&
+ sessionRouter,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
pj_status_t load(pjsip_endpoint *endpoint);
pj_status_t start();
pj_status_t stop();
diff --git a/src/PJSipSessionModuleConstruction.cpp b/src/PJSipSessionModuleConstruction.cpp
index e6cebaf..c1da3a7 100644
--- a/src/PJSipSessionModuleConstruction.cpp
+++ b/src/PJSipSessionModuleConstruction.cpp
@@ -92,11 +92,11 @@ static pjsip_dialog *uaOnDialogForked(pjsip_dialog *first_set, pjsip_rx_data *rd
}
PJSipSessionModule::PJSipSessionModule(pjsip_endpoint *endpt,
- boost::shared_ptr<SipEndpointFactory> endpointFactoryPtr,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx> sessionRouter,
- AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx serviceLocator,
- AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx> stateReplicator,
- AsteriskSCF::System::Component::V1::ReplicaPtr replica)
+ const boost::shared_ptr<SipEndpointFactory>& endpointFactoryPtr,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SessionCommunications::V1::SessionRouterPrx>& sessionRouter,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::SmartProxy::SmartProxy<AsteriskSCF::SIP::V1::SipStateReplicatorPrx>& stateReplicator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
: mName(moduleName), mEndpointFactory(endpointFactoryPtr),
mSessionRouter(sessionRouter), mServiceLocator(serviceLocator),
mStateReplicator(stateReplicator), mReplica(replica)
diff --git a/src/SipEndpoint.cpp b/src/SipEndpoint.cpp
index 03f88b9..58e4ff6 100644
--- a/src/SipEndpoint.cpp
+++ b/src/SipEndpoint.cpp
@@ -45,9 +45,15 @@ public:
/**
* Constructor for the SipEndpointImplPriv class.
*/
- SipEndpointImplPriv(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, PJSipManager *manager,
- const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica) :
- mName(name), mAdapter(adapter), mEndpointFactory(factory), mManager(manager), mServiceLocator(serviceLocator), mReplica(replica) { };
+ SipEndpointImplPriv(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
+ const std::string& name, PJSipManager *manager,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica) :
+ mName(name), mAdapter(adapter), mEndpointFactory(factory), mManager(manager), mServiceLocator(serviceLocator),
+ mReplica(replica)
+ {
+ };
+
/**
* The name of the endpoint.
*/
@@ -97,18 +103,22 @@ public:
/**
* Default constructor.
*/
-SipEndpoint::SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, Ice::PropertyDict props, PJSipManager *manager,
- const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica)
+SipEndpoint::SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
+ const std::string& name, const Ice::PropertyDict& props, PJSipManager *manager,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica)
: mImplPriv(new SipEndpointImplPriv(adapter, factory, name, manager, serviceLocator, replica))
{
lg(Debug) << "Constructing SIP endpoint " << name;
- mImplPriv->mEndpointProxy = AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::uncheckedCast(mImplPriv->mAdapter->addWithUUID(this));
+ mImplPriv->mEndpointProxy =
+ AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx::uncheckedCast(
+ mImplPriv->mAdapter->addWithUUID(this));
setConfiguration(props);
}
-void SipEndpoint::setConfiguration(Ice::PropertyDict props)
+void SipEndpoint::setConfiguration(const Ice::PropertyDict& props)
{
setTransportConfiguration(props);
//setAuthConfiguration(props);
@@ -118,13 +128,13 @@ void SipEndpoint::setConfiguration(Ice::PropertyDict props)
//setSubscriptionConfiguration(props);
}
-void SipEndpoint::setTransportConfiguration(Ice::PropertyDict props)
+void SipEndpoint::setTransportConfiguration(const Ice::PropertyDict& props)
{
std::string prefix("Sip.Endpoint.");
prefix.append(mImplPriv->mName);
prefix.append(".Transport.");
// Got the basic prefix. Now get the known config options.
- Ice::PropertyDict::iterator IpAddress = props.find(prefix + "Address");
+ Ice::PropertyDict::const_iterator IpAddress = props.find(prefix + "Address");
if (IpAddress != props.end())
{
pj_str_t addr;
@@ -139,29 +149,29 @@ void SipEndpoint::setTransportConfiguration(Ice::PropertyDict props)
mImplPriv->mConfig.transportConfig.address = IpAddress->second;
}
}
- Ice::PropertyDict::iterator direction = props.find(prefix + "SecureTransport");
+ Ice::PropertyDict::const_iterator direction = props.find(prefix + "SecureTransport");
if (direction != props.end())
{
mImplPriv->mConfig.transportConfig.secureTransport = SipEndpointConfig::stringToDirection(direction->second);
}
- Ice::PropertyDict::iterator user = props.find(prefix + "User");
+ Ice::PropertyDict::const_iterator user = props.find(prefix + "User");
if (user != props.end())
{
mImplPriv->mConfig.transportConfig.user = user->second;
}
}
-void SipEndpoint::setSessionConfiguration(Ice::PropertyDict props)
+void SipEndpoint::setSessionConfiguration(const Ice::PropertyDict& props)
{
std::string prefix("Sip.Endpoint.");
prefix.append(mImplPriv->mName);
prefix.append(".Session.");
- Ice::PropertyDict::iterator direction = props.find(prefix + "CallDirection");
+ Ice::PropertyDict::const_iterator direction = props.find(prefix + "CallDirection");
if (direction != props.end())
{
mImplPriv->mConfig.sessionConfig.callDirection = SipEndpointConfig::stringToDirection(direction->second);
}
- Ice::PropertyDict::iterator address = props.find(prefix + "SourceAddress");
+ Ice::PropertyDict::const_iterator address = props.find(prefix + "SourceAddress");
if (address != props.end())
{
pj_str_t addr;
@@ -178,7 +188,7 @@ void SipEndpoint::setSessionConfiguration(Ice::PropertyDict props)
}
}
-Direction SipEndpointConfig::stringToDirection(std::string directionString)
+Direction SipEndpointConfig::stringToDirection(const std::string& directionString)
{
if (directionString == "Both")
{
@@ -213,47 +223,54 @@ std::string SipEndpoint::getId(const Ice::Current&)
return mImplPriv->mEndpointProxy->ice_getIdentity().name;
}
-AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(const std::string& destination, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current&)
+AsteriskSCF::SessionCommunications::V1::SessionPrx SipEndpoint::createSession(const std::string& destination,
+ const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx& listener, const Ice::Current&)
{
- if (mImplPriv->mConfig.sessionConfig.callDirection != BOTH && mImplPriv->mConfig.sessionConfig.callDirection != INBOUND)
+ if (mImplPriv->mConfig.sessionConfig.callDirection != BOTH &&
+ mImplPriv->mConfig.sessionConfig.callDirection != INBOUND)
{
// TODO: We should have an exception here
return 0;
}
- SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listener, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica);
+ SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, listener, mImplPriv->mManager,
+ mImplPriv->mServiceLocator, mImplPriv->mReplica);
mImplPriv->mSessions.push_back(session);
return session->getSessionProxy();
}
AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination)
{
- SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, 0, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica);
+ SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, 0, mImplPriv->mManager,
+ mImplPriv->mServiceLocator, mImplPriv->mReplica);
mImplPriv->mSessions.push_back(session);
return session;
}
-AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination, const Ice::Identity& sessionid,
- const Ice::Identity& mediaid, const AsteriskSCF::Media::V1::SessionPrx& mediasession,
- const AsteriskSCF::Media::V1::StreamSourceSeq& sources,
- const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
+AsteriskSCF::SipSessionManager::SipSessionPtr SipEndpoint::createSession(const std::string& destination,
+ const Ice::Identity& sessionid, const Ice::Identity& mediaid,
+ const AsteriskSCF::Media::V1::SessionPrx& mediasession, const AsteriskSCF::Media::V1::StreamSourceSeq& sources,
+ const AsteriskSCF::Media::V1::StreamSinkSeq& sinks)
{
- SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, sessionid, mediaid, mediasession, sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica);
+ SipSessionPtr session = new SipSession(mImplPriv->mAdapter, this, destination, sessionid, mediaid, mediasession,
+ sources, sinks, mImplPriv->mManager, mImplPriv->mServiceLocator, mImplPriv->mReplica);
mImplPriv->mSessions.push_back(session);
return session;
}
-void SipEndpoint::removeSession(AsteriskSCF::SessionCommunications::V1::SessionPtr session)
+void SipEndpoint::removeSession(const AsteriskSCF::SessionCommunications::V1::SessionPtr& session)
{
SipSessionPtr sipsession = SipSessionPtr::dynamicCast(session);
- mImplPriv->mSessions.erase(std::remove(mImplPriv->mSessions.begin(), mImplPriv->mSessions.end(), sipsession), mImplPriv->mSessions.end());
+ mImplPriv->mSessions.erase(std::remove(mImplPriv->mSessions.begin(), mImplPriv->mSessions.end(), sipsession),
+ mImplPriv->mSessions.end());
}
AsteriskSCF::SessionCommunications::V1::SessionSeq SipEndpoint::getSessions(const Ice::Current&)
{
AsteriskSCF::SessionCommunications::V1::SessionSeq sessions;
- for (std::vector<SipSessionPtr>::const_iterator session = mImplPriv->mSessions.begin(); session != mImplPriv->mSessions.end(); ++session)
+ for (std::vector<SipSessionPtr>::const_iterator session = mImplPriv->mSessions.begin();
+ session != mImplPriv->mSessions.end(); ++session)
{
sessions.push_back((*session)->getSessionProxy());
}
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index 63471f1..994554d 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -195,7 +195,7 @@ public:
/* Convert a specified direction string into its proper
* enumerated value.
*/
- static Direction stringToDirection(std::string directionString);
+ static Direction stringToDirection(const std::string& directionString);
private:
};
@@ -207,8 +207,10 @@ class SipEndpointImplPriv;
class SipEndpoint : public AsteriskSCF::SessionCommunications::V1::SessionEndpoint
{
public:
- SipEndpoint(Ice::ObjectAdapterPtr adapter, boost::shared_ptr<SipEndpointFactory> factory, std::string name, Ice::PropertyDict props, PJSipManager *manager,
- const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator, const AsteriskSCF::System::Component::V1::ReplicaPtr replica);
+ SipEndpoint(const Ice::ObjectAdapterPtr& adapter, const boost::shared_ptr<SipEndpointFactory>& factory,
+ const std::string& name, const Ice::PropertyDict& props, PJSipManager *manager,
+ const AsteriskSCF::Core::Discovery::V1::ServiceLocatorPrx& serviceLocator,
+ const AsteriskSCF::System::Component::V1::ReplicaPtr& replica);
bool operator==(const std::string &name) const;
@@ -216,7 +218,8 @@ public:
* Interface implementation.
*/
std::string getId(const Ice::Current&);
- AsteriskSCF::SessionCommunications::V1::SessionPrx createSession(const std::string&, const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const Ice::Current&);
+ AsteriskSCF::SessionCommunications::V1::SessionPrx createSession(const std::string&,
+ const AsteriskSCF::SessionCommunications::V1::SessionListenerPrx&, const Ice::Current&);
AsteriskSCF::SessionCommunications::V1::SessionSeq getSessions(const Ice::Current&);
/**
@@ -228,13 +231,16 @@ public:
AsteriskSCF::SessionCommunications::V1::SessionEndpointPrx getEndpointProxy();
- // TODO: Find a way to use SipSessionPtr here, right now trying to do so results in the world exploding due to dependency insanity
+ //
+ // TODO: Find a way to use SipSessionPtr here, right now trying to do so results in the world exploding due to
+ // dependency insanity
+ //
AsteriskSCF::SipSessionManager::SipSessionPtr createSession(const std::string&);
- AsteriskSCF::SipSessionManager::SipSessionPtr createSession(const std::string&, const Ice::Identity&, const Ice::Identity&,
- const AsteriskSCF::Media::V1::SessionPrx&, const AsteriskSCF::Media::V1::StreamSourceSeq&,
- const AsteriskSCF::Media::V1::StreamSinkSeq&);
+ AsteriskSCF::SipSessionManager::SipSessionPtr createSession(const std::string&, const Ice::Identity&,
+ const Ice::Identity&, const AsteriskSCF::Media::V1::SessionPrx&,
+ const AsteriskSCF::Media::V1::StreamSourceSeq&, const AsteriskSCF::Media::V1::StreamSinkSeq&);
- void removeSession(AsteriskSCF::SessionCommunications::V1::SessionPtr);
+ void removeSession(const AsteriskSCF::SessionCommunications::V1::SessionPtr&);
private:
/**
@@ -245,15 +251,15 @@ private:
/**
* Set up configuration for the endpoint
*/
- void setConfiguration(Ice::PropertyDict props);
+ void setConfiguration(const Ice::PropertyDict& props);
- void setTransportConfiguration(Ice::PropertyDict props);
+ void setTransportConfiguration(const Ice::PropertyDict& props);
- void setSessionConfiguration(Ice::PropertyDict props);
- void setRegistrationConfiguration(Ice::PropertyDict props);
- void setAuthConfiguration(Ice::PropertyDict props);
- void setMediaConfiguration(Ice::PropertyDict props);
- void setSubscriptionConfiguration(Ice::PropertyDict props);
+ void setSessionConfiguration(const Ice::PropertyDict& props);
+ void setRegistrationConfiguration(const Ice::PropertyDict& props);
+ void setAuthConfiguration(const Ice::PropertyDict& props);
+ void setMediaConfiguration(const Ice::PropertyDict& props);
+ void setSubscriptionConfiguration(const Ice::PropertyDict& props);
};
/**
diff --git a/src/SipEndpointFactory.cpp b/src/SipEndpointFactory.cpp
index 62d89cc..ea072c4 100644
--- a/src/SipEndpointFactory.cpp
+++ b/src/SipEndpointFactory.cpp
@@ -22,23 +22,24 @@ namespace AsteriskSCF
namespace SipSessionManager
{
-SipEndpointPtr SipEndpointFactory::createEndpoint(std::string destination, Ice::PropertiesPtr props)
+SipEndpointPtr SipEndpointFactory::createEndpoint(const std::string& destination, const Ice::PropertiesPtr& props)
{
std::string prefix("Sip.Endpoint.");
prefix.append(destination);
Ice::PropertyDict endpointProps = props->getPropertiesForPrefix(prefix);
- SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), destination, endpointProps, mManager, mServiceLocator, mReplica);
+ SipEndpointPtr endpoint = new SipEndpoint(mAdapter, shared_from_this(), destination, endpointProps, mManager,
+ mServiceLocator, mReplica);
mEndpoints.push_back(endpoint);
return endpoint;
}
-void SipEndpointFactory::remove(SipEndpointPtr endpoint)
+void SipEndpointFactory::remove(const SipEndpointPtr& endpoint)
{
// TODO: Do we even need to remove sip endpoints yet?
// mEndpoints.erase(std::remove(mEndpoints.begin(), mEndpoints.end(), endpoint), mEndpoints.end());
}
-SipEndpointPtr SipEndpointFactory::findByName(std::string endpointName)
+SipEndpointPtr SipEndpointFactory::findByName(const std::string& endpointName)
{
std::vector<SipEndpointPtr>::iterator iter;
for (iter = mEndpoints.begin(); iter != mEndpoints.end(); ++ iter)
diff --git a/src/SipEndpointFactory.h b/src/SipEndpointFactory.h
index 77a34fa..73c4d3a 100644
--- a/src/SipEndpointFactory.h
+++ b/src/SipEndpointFactory.h
... 794 lines suppressed ...
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list