reSIProcate/stack  9694
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
resip::SipStack Class Reference

This is the primary point of interaction between the app-layer and the stack. More...

#include <SipStack.hxx>

Inheritance diagram for resip::SipStack:
Inheritance graph
[legend]
Collaboration diagram for resip::SipStack:
Collaboration graph
[legend]

List of all members.

Classes

class  Exception
 thrown when the stack is unable to function. More...

Public Member Functions

 SipStack (const SipStackOptions &options)
 Constructor.
 SipStack (Security *security=0, const DnsStub::NameserverList &additional=DnsStub::EmptyNameserverList, AsyncProcessHandler *handler=0, bool stateless=false, AfterSocketCreationFuncPtr socketFunc=0, Compression *compression=0, FdPollGrp *pollGrp=0)
 Constructor.
virtual ~SipStack ()
void run ()
 Causes this SipStack object to create and run threads for carrying out processing.
void shutdown ()
 perform orderly shutdown
void shutdownAndJoinThreads ()
 Shutdown and join any threads that the SipStack is running.
TransportaddTransport (TransportType protocol, int port, IpVersion version=V4, StunSetting stun=StunDisabled, const Data &ipInterface=Data::Empty, const Data &sipDomainname=Data::Empty, const Data &privateKeyPassPhrase=Data::Empty, SecurityTypes::SSLType sslType=SecurityTypes::TLSv1, unsigned transportFlags=0, SecurityTypes::TlsClientVerificationMode cvm=SecurityTypes::None, bool useEmailAsSIP=false)
 Used by the application to add in a new built-in transport.
void addTransport (std::auto_ptr< Transport > transport)
 Used to plug-in custom transports.
Fifo< TransactionMessage > & stateMacFifo ()
 Returns the fifo that subclasses of Transport should use for the rxFifo cons.
void addAlias (const Data &domain, int port)
 add an alias for this sip element
bool isMyDomain (const Data &domain, int port) const
 Returns true if domain is handled by this stack.
bool isMyPort (int port) const
 Returns true if port is handled by this stack.
const UrigetUri () const
 Get one of the domains/ports that are handled by this stack in Uri form.
void send (const SipMessage &msg, TransactionUser *tu=0)
 allows a TU to send a message
void send (std::auto_ptr< SipMessage > msg, TransactionUser *tu=0)
void sendTo (std::auto_ptr< SipMessage > msg, const Uri &uri, TransactionUser *tu=0)
 this is only if you want to send to a destination not in the route.
void sendTo (std::auto_ptr< SipMessage > msg, const Tuple &tuple, TransactionUser *tu=0)
 this is only if you want to send to a destination not in the route.
void sendTo (const SipMessage &msg, const Uri &uri, TransactionUser *tu=0)
 send a message to a destination not in the route
void sendTo (const SipMessage &msg, const Tuple &tuple, TransactionUser *tu=0)
 send a message to a destination not in the route
void sendOverExistingConnection (const SipMessage &msg, const Tuple &tuple, TransactionUser *tu=0)
 force the a message out over an existing connection
void post (std::auto_ptr< ApplicationMessage > message, unsigned int secondsLater, TransactionUser *tu=0)
 Makes the message available to the TU at some later time, specified in seconds.
void postMS (const std::auto_ptr< ApplicationMessage > message, unsigned int ms, TransactionUser *tu=0)
 Makes the message available to the TU at some later time, specified in milli-seconds.
void post (std::auto_ptr< ApplicationMessage > message)
 Makes the message available to the TU later.
void post (const ApplicationMessage &message)
 Makes the message available to the TU later.
void post (const ApplicationMessage &message, unsigned int secondsLater, TransactionUser *tu=0)
 Makes the message available to the TU at some later time, specified in seconds.
void postMS (const ApplicationMessage &message, unsigned int ms, TransactionUser *tu=0)
 Makes the message available to the TU at some later time, specified in milli-seconds.
void abandonServerTransaction (const Data &tid)
 Tells the stack that the TU has abandoned a server transaction.
void cancelClientInviteTransaction (const Data &tid)
 Tells the stack that the TU wishes to CANCEL an INVITE request.
bool hasMessage () const
 does the stack have new messages for the TU?
SipMessagereceive ()
 retrieve a SipMessage off the old TuFifo
MessagereceiveAny ()
 retrieve a message off the old TuFifo
void setFallbackPostNotify (AsyncProcessHandler *handler)
virtual RESIP_DEPRECATED void buildFdSet (FdSet &fdset)
 Build the FD set to use in a select to find out when process(FdSet&) must be called again.
virtual RESIP_DEPRECATED void process (FdSet &fdset)
 This allows the executive to give processing time to stack components.
bool process (unsigned int timeoutMs)
 Give processing time to the SipStack components, when operating in single-threaded mode.
FdPollGrpgetPollGrp ()
virtual unsigned int getTimeTillNextProcessMS ()
 Returns time in milliseconds when process next needs to be called.
virtual void processTimers ()
 Check all timers.
void setStatisticsInterval (unsigned long seconds)
 Sets the interval that determines the time between Statistics messages.
void zeroOutStatistics ()
 Resets all of the cumulative statistics counters.
bool pollStatistics ()
 Immediately polls for statistics to be logged and sent to external handlers, instead of waiting for next statistics interval.
void setExternalStatsHandler (ExternalStatsHandler *handler)
 Installs a handler for the stacks internal StatisticsManager.
EncodeStreamdump (EncodeStream &strm) const
 output current state of the stack - for debug
SecuritygetSecurity () const
 Returns a pointer to the embedded Security object, 0 if not set.
void registerTransactionUser (TransactionUser &)
 add a TU to the TU selection chain
void requestTransactionUserShutdown (TransactionUser &)
 Queue a shutdown request to the specified TU.
void unregisterTransactionUser (TransactionUser &)
 Removes a TU from the TU selection chain.
void registerMarkListener (MarkListener *listener)
 Register a handler with the DNS Interface for notifications of when a Dns Resource Record has been blacklisted.
void unregisterMarkListener (MarkListener *listener)
 Removed a registered BlacklistListener handler from the DNS Interface for a particualr Resource Record type and handler pointer.
DnsStubgetDnsStub () const
void setEnumSuffixes (const std::vector< Data > &suffixes)
 Specify which enum domains will be searched when sending.
void clearDnsCache ()
 Clear the DNS Cache.
void logDnsCache ()
 Log the DNS Cache to WarningLog for Debugging.
void getDnsCacheDump (std::pair< unsigned long, unsigned long > key, GetDnsCacheDumpHandler *handler)
 Get a string representation of the DNS Cache.
volatile bool & statisticsManagerEnabled ()
 Enable Statistics Manager.
const bool statisticsManagerEnabled () const
bool getFixBadDialogIdentifiers () const
 Returns whether the stack is fixing corrupted/changed dialog identifiers (ie, Call-Id and tags) in responses from the wire.
void setFixBadDialogIdentifiers (bool pFixBadDialogIdentifiers)
 Specify whether the stack should fix corrupted/changed dialog identifiers (ie, Call-Id and tags) in responses from the wire.
bool getFixBadCSeqNumbers () const
void setFixBadCSeqNumbers (bool pFixBadCSeqNumbers)
void setContentLengthChecking (bool check)
 Used to enable/disable content-length checking on datagram-based transports.
void setCongestionManager (CongestionManager *manager)
 Sets the CongestionManager used by the stack.
CongestionManagergetCongestionManager ()
 Accessor for the CongestionManager object the stack is using.
CompressiongetCompression ()
 Accessor for the Compression object the stack is using.
void terminateFlow (const resip::Tuple &flow)
void enableFlowTimer (const resip::Tuple &flow)

Static Public Member Functions

static Data getHostname ()
 Get one of the names for this host (calls through to gethostbyname) and is not threadsafe.
static Data getHostAddress ()
 Get one of the IP address for this host (calls through to gethostbyname) and is not threadsafe.

Private Member Functions

void init (const SipStackOptions &options)
 Performs bulk of work of constructor.
void checkAsyncProcessHandler ()
 Notify an async process handler - if one has been registered.
 SipStack (const SipStack &copy)
 Disallow copy, by not implementing.
SipStackoperator= (const SipStack &rhs)
 Disallow assignment, by not implementing.

Private Attributes

FdPollGrpmPollGrp
bool mPollGrpIsMine
SecuritymSecurity
 if this object exists, it manages advanced security featues
DnsStubmDnsStub
DnsThreadmDnsThread
CompressionmCompression
 If this object exists, it manages compression parameters.
AsyncProcessHandlermAsyncProcessHandler
 if this object exists, it gets notified when messages are posted to any of the various fifos in the stack.
bool mInterruptorIsMine
TimeLimitFifo< MessagemTUFifo
 fifo used to communicate between the TU (TransactionUser) and stack
CongestionManagermCongestionManager
TuSelector mTuSelector
 Responsible for routing messages to the correct TU based on installed rules.
Mutex mAppTimerMutex
 Protection for AppTimerQueue.
TuSelectorTimerQueue mAppTimers
StatisticsManager mStatsManager
 Used to Track stack statistics.
TransactionControllermTransactionController
 All aspects of the Transaction State Machine / DNS resolver.
std::auto_ptr
< ProducerFifoBuffer
< TransactionMessage > > 
mStateMacFifoBuffer
TransactionControllerThreadmTransactionControllerThread
TransportSelectorThreadmTransportSelectorThread
bool mRunning
std::set< DatamDomains
 store all domains that this stack is responsible for.
std::set< int > mPorts
 store all ports that this stack is lisenting on.
Uri mUri
bool mShuttingDown
Mutex mShutdownMutex
volatile bool mStatisticsManagerEnabled
AfterSocketCreationFuncPtr mSocketFunc

Friends

class Executive
class StatelessHandler
class StatisticsManager
class TestDnsResolver
class TestFSM
class TransactionState
class TransactionController
class TuSelector

Detailed Description

This is the primary point of interaction between the app-layer and the stack.

For a SipStack to be usable, transports must be added by calling the addTransport() method.

The useful work done by SipStack occurs when SipStack::process(unsigned int) is called. A separate thread (such as EventStackThread) can be dedicated to this task, or it can be called from within a loop in the main thread of the executable.

Graceful shutdown is accomplished by advising the SipStack to begin shutdown procedures via the shutdown() method. The SipStack should continue to be serviced through the process(unsigned int) method until the Transaction User is informed by receiving a ShutdownMessage that the requested shutdown is complete.

Note:
Previously, buildFdSet(FdSet&), FdSet::select(), and process(FdSet&) were the canonical way of giving the SipStack cycles. Because of shortcomings of the fd_set approach, these have been deprecated.

Definition at line 142 of file SipStack.hxx.


Constructor & Destructor Documentation

SipStack::SipStack ( const SipStackOptions options)

Constructor.

First instantiate SipStackOptions, then set any values special to your application, then call this constructor. The {options} instance is not referenced after construction (i.e., the SipStack doesn't keep a reference to it). However, it does copy each individual value, and takes ownership of several of the objects.

Definition at line 53 of file SipStack.cxx.

References init(), mTUFifo, and resip::FifoStatsInterface::setDescription().

                                                 :
        mTUFifo(TransactionController::MaxTUFifoTimeDepthSecs,
                TransactionController::MaxTUFifoSize),
        mTuSelector(mTUFifo),
        mAppTimers(mTuSelector),
        mStatsManager(*this)
{
   // WARNING - don't forget to add new member initialization to the init() method
   init(options);
   mTUFifo.setDescription("SipStack::mTUFifo");
}

Here is the call graph for this function:

SipStack::SipStack ( Security security = 0,
const DnsStub::NameserverList additional = DnsStub::EmptyNameserverList,
AsyncProcessHandler handler = 0,
bool  stateless = false,
AfterSocketCreationFuncPtr  socketFunc = 0,
Compression compression = 0,
FdPollGrp pollGrp = 0 
)

Constructor.

This constructor is obsolete. The SipStackOptions-based constructor should be used instead.

Parameters:
securitySecurity Object required by the stack for TLS, DTLS, SMIME and Identity-draft compliance. If 0 is passed in the stack will not support these advanced security features. The compile flag USE_SSL is also required. The security object will be owned by the SipStack and deleted in the SipStack destructor. Default is 0.
handlerAsyncProcessHandler that will be invoked when Messages are posted to the stack. For example: SelectInterruptor. Default is 0.
statelessThis parameter does not appear to be used.
socketFuncA pointer to a function that will be called after a socket in the DNS or SIP transport layers of the stack has been created. This callback can be used to control low level socket options, such as Quality-of-Service/DSCP. Note: For SIP TCP sockets there is one call for the listen socket, and one (or two) calls for each connection created afterwards. For each inbound TCP connection the first callback is called immediately before the socket is connected, and if configured it is called again after the connect call has completed and before the first data is sent out. On some OS's you cannot set QOS until the socket is successfully connected. To enable this behavior call: Connection::setEnablePostConnectSocketFuncCall();
compressionCompression configuration object required for SigComp. If set to 0, then SigComp compression will be disabled.
pollGrpPolling group to support file-io callbacks; if one is not passed, one will be created. Ownership is not taken.

Definition at line 66 of file SipStack.cxx.

References resip::Timer::getTimeMs(), init(), resip::Random::initialize(), resip::initNetwork(), mAppTimers, resip::TransactionController::MaxTUFifoSize, resip::TransactionController::MaxTUFifoTimeDepthSecs, resip::SipStackOptions::mCompression, resip::SipStackOptions::mExtraNameserverList, resip::SipStackOptions::mPollGrp, mPollGrp, resip::SipStackOptions::mSecurity, resip::SipStackOptions::mSocketFunc, resip::SipStackOptions::mStateless, mStatsManager, mTransactionController, mTUFifo, mTuSelector, resip::Security::preload(), resip::FifoStatsInterface::setDescription(), resip::TransportSelector::setPollGrp(), and resip::TransactionController::transportSelector().

                                       :
   mPollGrp(pollGrp?pollGrp:FdPollGrp::create()),
   mPollGrpIsMine(!pollGrp),
#ifdef USE_SSL
   mSecurity( pSecurity ? pSecurity : new Security()),
#else
   mSecurity(0),
#endif
   mDnsStub(new DnsStub(additional, socketFunc, handler, mPollGrp)),
   mDnsThread(0),
   mCompression(compression ? compression : new Compression(Compression::NONE)),
   mAsyncProcessHandler(handler ? handler : new SelectInterruptor),
   mInterruptorIsMine(!handler),
   mTUFifo(TransactionController::MaxTUFifoTimeDepthSecs,
           TransactionController::MaxTUFifoSize),
   mCongestionManager(0),
   mTuSelector(mTUFifo),
   mAppTimers(mTuSelector),
   mStatsManager(*this),
   mTransactionController(new TransactionController(*this, mAsyncProcessHandler)),
   mTransactionControllerThread(0),
   mTransportSelectorThread(0),
   mRunning(false),
   mShuttingDown(false),
   mStatisticsManagerEnabled(true),
   mSocketFunc(socketFunc)
{
   Timer::getTimeMs(); // initalize time offsets
   Random::initialize();
   initNetwork();
   if (pSecurity)
   {
#ifdef USE_SSL
      pSecurity->preload();
#else
      assert(0);
#endif
   }
   
   mTUFifo.setDescription("SipStack::mTUFifo");
   mTransactionController->transportSelector().setPollGrp(mPollGrp);

#if 0
  // .kw. originally tried to share common init() for the two
  // constructors, but too much risk for changing sequencing,
  // first prove out new constructor before merging (or obsoleting)
        mTUFifo(TransactionController::MaxTUFifoTimeDepthSecs,
           TransactionController::MaxTUFifoSize),
        mTuSelector(mTUFifo),
        mAppTimers(mTuSelector),
        mStatsManager(*this)
{
   SipStackOptions options;
   options.mSecurity = pSecurity;
   options.mExtraNameserverList = &additional;
   options.mStateless = stateless;
   options.mSocketFunc = socketFunc;
   options.mCompression = compression;
   options.mPollGrp = pollGrp;
   init(options);
#endif
}

Here is the call graph for this function:

SipStack::~SipStack ( ) [virtual]
resip::SipStack::SipStack ( const SipStack copy) [private]

Disallow copy, by not implementing.


Member Function Documentation

void SipStack::abandonServerTransaction ( const Data tid)

Tells the stack that the TU has abandoned a server transaction.

This is provided to allow better behavior in cases where an exception is thrown due to garbage in the request, and the code catching the exception has no way of telling whether the original request is still around. This frees the TU of the obligation to respond to the request.

Parameters:
tidThe transaction identifier for the server transaction.
Note:
This function is distinct from cancelClientInviteTransaction().

Definition at line 704 of file SipStack.cxx.

References resip::TransactionController::abandonServerTransaction(), and mTransactionController.

Here is the call graph for this function:

void SipStack::addAlias ( const Data domain,
int  port 
)

add an alias for this sip element

Used to add an alias for this sip element. e.g. foobar.com and boo.com are both handled by this stack. Not threadsafe. Alias is added to internal list of Domains and can be checked with isMyDomain.

Parameters:
domainDomain name that this stack is responsible for.
portPort for domain that this stack is responsible for.

Definition at line 433 of file SipStack.cxx.

References DebugLog, resip::Symbols::DefaultSipPort, resip::Data::empty(), resip::Uri::host(), mDomains, mShuttingDown, and mUri.

Referenced by addTransport().

{
   int portToUse = (port == 0) ? Symbols::DefaultSipPort : port;

   DebugLog (<< "Adding domain alias: " << domain << ":" << portToUse);
   assert(!mShuttingDown);
   mDomains.insert(domain + ":" + Data(portToUse));


   if(mUri.host().empty())
   {
      mUri.host()=*mDomains.begin();
   }

}

Here is the call graph for this function:

Transport * SipStack::addTransport ( TransportType  protocol,
int  port,
IpVersion  version = V4,
StunSetting  stun = StunDisabled,
const Data ipInterface = Data::Empty,
const Data sipDomainname = Data::Empty,
const Data privateKeyPassPhrase = Data::Empty,
SecurityTypes::SSLType  sslType = SecurityTypes::TLSv1,
unsigned  transportFlags = 0,
SecurityTypes::TlsClientVerificationMode  cvm = SecurityTypes::None,
bool  useEmailAsSIP = false 
)

Used by the application to add in a new built-in transport.

The transport is created and then added to the Transport Selector.

Exceptions:
Transport::ExceptionIf the transport couldn't be added, usually because the port was already bound.
Parameters:
protocolTCP, UDP, TLS, DTLS, etc.
portSpecifies which port to bind to.
versionProtocol Version: V4 or V6
stunSpecifies whether STUN is enabled.
ipInterfaceSpecifies which ethernet interface to bind to. If set to Data::Empty, bind to all interfaces. Binding to all interfaces can impose a performance penalty, however, so it is recommended that you bind to specific interfaces when using in high-throughput deployments. Note: Interfaces must be identified via IP address.
sipDomainnameOnly allow messages to be sent as the specified domain. For default case, you can pass in domainname = DnsUtil::getLocalDomainName().
privateKeyPassPhrasePrivate key pass phrase used to decrypt private key certificates. Note: For now this parameter is not used we are loading PKCS7 keys, so a pass phrase is not required.
sslTypeVersion of the TLS specification to use: SSLv23 or TLSv1
cvmSSL verify mode for the peer (whether we accept and/or insist on a client certificate from the peer)
useEmailAsSIPIf true, we will accept the email address in a client's subjectAltName as if it were a SIP URI. This is convenient because many commercial CAs offer email certificates but not sip: certificates. For reasons of standards compliance, it is disabled by default.

Definition at line 293 of file SipStack.cxx.

References resip::Data::c_str(), CritLog, resip::DTLS, resip::Data::empty(), ErrLog, resip::DnsUtil::isIpV4Address(), resip::DnsUtil::isIpV6Address(), mCompression, mSecurity, mShuttingDown, mSocketFunc, mTransactionController, resip::TransportSelector::stateMacFifo(), stateMacFifo(), resip::TCP, resip::TLS, resip::Tuple::toData(), resip::TransactionController::transportSelector(), resip::UDP, resip::V4, and resip::V6.

Referenced by main(), and myMain().

{
   assert(!mShuttingDown);

   // If address is specified, ensure it is valid
   if(!ipInterface.empty())
   {
      if(version == V6)
      {
         if(!DnsUtil::isIpV6Address(ipInterface))
         {
            ErrLog(<< "Failed to create transport, invalid ipInterface specified (IP address required): V6 "
                   << Tuple::toData(protocol) << " " << port << " on "
                   << ipInterface.c_str());
            throw Transport::Exception("Invalid ipInterface specified (IP address required)", __FILE__,__LINE__);
         }
      }
      else // V4
      {
         if(!DnsUtil::isIpV4Address(ipInterface))
         {
            ErrLog(<< "Failed to create transport, invalid ipInterface specified (IP address required): V4 "
                   << Tuple::toData(protocol) << " " << port << " on "
                   << ipInterface.c_str());
            throw Transport::Exception("Invalid ipInterface specified (IP address required)", __FILE__,__LINE__);
         }
      }
   }

   InternalTransport* transport=0;
   Fifo<TransactionMessage>& stateMacFifo = mTransactionController->transportSelector().stateMacFifo();
   try
   {
      switch (protocol)
      {
         case UDP:
            transport = new UdpTransport(stateMacFifo, port, version, stun, ipInterface, mSocketFunc, *mCompression, transportFlags);
            break;
         case TCP:
            transport = new TcpTransport(stateMacFifo, port, version, ipInterface, mSocketFunc, *mCompression, transportFlags);
            break;
         case TLS:
#if defined( USE_SSL )
            transport = new TlsTransport(stateMacFifo,
                                         port,
                                         version,
                                         ipInterface,
                                         *mSecurity,
                                         sipDomainname,
                                         sslType,
                                         mSocketFunc,
                                         *mCompression,
                                         transportFlags,
                                         cvm,
                                         useEmailAsSIP);
#else
            CritLog (<< "TLS not supported in this stack. You don't have openssl");
            assert(0);
#endif
            break;
         case DTLS:
#if defined( USE_DTLS )
            transport = new DtlsTransport(stateMacFifo,
                                          port,
                                          version, // !jf! stun
                                          ipInterface,
                                          *mSecurity,
                                          sipDomainname,
                                          mSocketFunc,
                                          *mCompression);
#else
            CritLog (<< "DTLS not supported in this stack.");
            assert(0);
#endif
            break;
         default:
            assert(0);
            break;
      }
   }
   catch (BaseException& e)
   {
      ErrLog(<< "Failed to create transport: "
             << (version == V4 ? "V4" : "V6") << " "
             << Tuple::toData(protocol) << " " << port << " on "
             << (ipInterface.empty() ? "ANY" : ipInterface.c_str()) 
             << ": " << e);
      throw;
   }
   addTransport(std::auto_ptr<Transport>(transport));
   return transport;
}

Here is the call graph for this function:

void SipStack::addTransport ( std::auto_ptr< Transport transport)

Used to plug-in custom transports.

Adds the transport to the Transport Selector.

Parameters:
transportPointer to an externally created transport. SipStack assumes ownership.

Definition at line 397 of file SipStack.cxx.

References addAlias(), resip::TransportSelector::addTransport(), resip::DnsUtil::getInterfaces(), resip::DnsUtil::isIpV4Address(), mPorts, mTransactionController, resip::TransactionController::transportSelector(), and resip::V4.

{
   //.dcm. once addTransport starts throwing, need to back out alias
   if (!transport->interfaceName().empty())
   {
      addAlias(transport->interfaceName(), transport->port());
   }
   else
   {
      // Using INADDR_ANY, get all IP interfaces
      std::list<std::pair<Data, Data> > ipIfs(DnsUtil::getInterfaces());
      if(transport->ipVersion()==V4)
      {
         ipIfs.push_back(std::make_pair<Data,Data>("lo0","127.0.0.1"));
      }
      while(!ipIfs.empty())
      {
         if(DnsUtil::isIpV4Address(ipIfs.back().second)==
                                             (transport->ipVersion()==V4))
         {
            addAlias(ipIfs.back().second, transport->port());
         }
         ipIfs.pop_back();
      }
   }
   mPorts.insert(transport->port());
   mTransactionController->transportSelector().addTransport(transport,true);
}

Here is the call graph for this function:

void SipStack::buildFdSet ( FdSet fdset) [virtual]

Build the FD set to use in a select to find out when process(FdSet&) must be called again.

Parameters:
fdsetan empty or partially populated fdset, fd's are added to the fdset on return
Note:
This must be called prior to calling process.
select() must also be called on the fdset prior to process.
Deprecated:
Because of serious shortcomings in fd_set (most notably the inability to store FDs whose value exceeds a relatively small number; ~1000), we are deprecating the FdSet-based process loop.
See also:
EventStackThread for an alternative, or if you wish to drive the SipStack yourself,
process(unsigned int). On platforms that do not support epoll, fd_set ends up being used anyway since there is no other choice, but this is hidden from the app.

Implements resip::FdSetIOObserver.

Definition at line 847 of file SipStack.cxx.

References resip::FdPollGrp::buildFdSet(), and mPollGrp.

Referenced by main(), poller(), processTimeouts(), resip::StackThread::thread(), and resip::InterruptableStackThread::thread().

{
   mPollGrp->buildFdSet(fdset);
}

Here is the call graph for this function:

void SipStack::cancelClientInviteTransaction ( const Data tid)

Tells the stack that the TU wishes to CANCEL an INVITE request.

This frees the TU of the obligation to keep state on whether a 1xx has come in yet before actually sending a CANCEL request, and also the obligation of forming the CANCEL request itself. This _does_ _not_ free the TU of the obligation to handle any INVITE/200 that come in (usually by sending an ACK to the 200, and then a BYE).

Parameters:
tidThe transaction identifier of the INVITE request sent.

Definition at line 710 of file SipStack.cxx.

References resip::TransactionController::cancelClientInviteTransaction(), and mTransactionController.

Here is the call graph for this function:

void SipStack::checkAsyncProcessHandler ( ) [private]

Notify an async process handler - if one has been registered.

Definition at line 635 of file SipStack.cxx.

References resip::AsyncProcessHandler::handleProcessNotification(), and mAsyncProcessHandler.

Referenced by postMS(), requestTransactionUserShutdown(), and unregisterTransactionUser().

Here is the call graph for this function:

void SipStack::clearDnsCache ( )

Clear the DNS Cache.

Definition at line 929 of file SipStack.cxx.

References resip::DnsStub::clearDnsCache(), and mDnsStub.

Here is the call graph for this function:

EncodeStream & SipStack::dump ( EncodeStream strm) const

output current state of the stack - for debug

Definition at line 959 of file SipStack.cxx.

References resip::Inserter(), resip::TransportSelector::mAnyInterfaceTransports, mAppTimerMutex, mAppTimers, resip::TransactionController::mClientTransactionMap, mDomains, resip::TransportSelector::mExactTransports, mSecurity, resip::TransactionController::mServerTransactionMap, resip::TransactionController::mTimers, mTransactionController, resip::TransactionController::mTransportSelector, mTUFifo, resip::AbstractFifo< T >::size(), resip::TransactionMap::size(), and resip::TimerQueue< T >::size().

{
   Lock lock(mAppTimerMutex);
   strm << "SipStack: " << (this->mSecurity ? "with security " : "without security ")
        << std::endl
        << "domains: " << Inserter(this->mDomains)
        << std::endl
        << " TUFifo size=" << this->mTUFifo.size() << std::endl
        << " Timers size=" << this->mTransactionController->mTimers.size() << std::endl
        << " AppTimers size=" << this->mAppTimers.size() << std::endl
        << " ServerTransactionMap size=" << this->mTransactionController->mServerTransactionMap.size() << std::endl
        << " ClientTransactionMap size=" << this->mTransactionController->mClientTransactionMap.size() << std::endl
        << " Exact Transports=" << Inserter(this->mTransactionController->mTransportSelector.mExactTransports) << std::endl
        << " Any Transports=" << Inserter(this->mTransactionController->mTransportSelector.mAnyInterfaceTransports) << std::endl;
   return strm;
}

Here is the call graph for this function:

void SipStack::enableFlowTimer ( const resip::Tuple flow)

Definition at line 990 of file SipStack.cxx.

References resip::TransactionController::enableFlowTimer(), and mTransactionController.

Here is the call graph for this function:

Compression& resip::SipStack::getCompression ( ) [inline]

Accessor for the Compression object the stack is using.

Returns:
The Compression object being used.
Note:
If no Compression object was set on construction, this will be initialized to a null-implementation, so this function will be safe to call.

Definition at line 978 of file SipStack.hxx.

References mCompression.

{ return *mCompression; }
CongestionManager* resip::SipStack::getCongestionManager ( ) [inline]

Accessor for the CongestionManager object the stack is using.

Returns:
The CongestionManager object being used.
Note:
If no Compression object was set on construction, this will return null.

Definition at line 968 of file SipStack.hxx.

References mCongestionManager.

{ return mCongestionManager; }
void SipStack::getDnsCacheDump ( std::pair< unsigned long, unsigned long >  key,
GetDnsCacheDumpHandler handler 
)

Get a string representation of the DNS Cache.

Parameters:
key- a pair representing the request key, can be used by the callback handler to identify the originating request
handler- pointer to a class that implements the handler method: onDnsCacheRetrieved

Definition at line 941 of file SipStack.cxx.

References resip::DnsStub::getDnsCacheDump(), and mDnsStub.

{
   mDnsStub->getDnsCacheDump(key, handler);
}

Here is the call graph for this function:

DnsStub & SipStack::getDnsStub ( ) const

Definition at line 917 of file SipStack.cxx.

References mDnsStub.

{
   return *mDnsStub;
}
bool resip::SipStack::getFixBadCSeqNumbers ( ) const [inline]

Definition at line 874 of file SipStack.hxx.

References resip::TransactionController::getFixBadCSeqNumbers(), and mTransactionController.

      {
         return mTransactionController->getFixBadCSeqNumbers();
      }

Here is the call graph for this function:

bool resip::SipStack::getFixBadDialogIdentifiers ( ) const [inline]

Returns whether the stack is fixing corrupted/changed dialog identifiers (ie, Call-Id and tags) in responses from the wire.

Returns:
Denotes whether the stack is fixing corrupted/changed dialog identifiers.
See also:
getFixBadDialogIdentifiers()

Definition at line 851 of file SipStack.hxx.

References resip::TransactionController::mFixBadDialogIdentifiers, and mTransactionController.

      {
         return mTransactionController->mFixBadDialogIdentifiers;
      }
Data SipStack::getHostAddress ( ) [static]

Get one of the IP address for this host (calls through to gethostbyname) and is not threadsafe.

Definition at line 487 of file SipStack.cxx.

References ErrLog.

{
   // if you change this, please #def old version for windows
   char hostName[1024];
   int err =  gethostname( hostName, sizeof(hostName) );
   if(err != 0)
   {
      ErrLog(<< "gethostname failed with return " << err << " Returning "
            "\"127.0.0.1\"");
      assert(0);
      return "127.0.0.1";
   }
   
   struct hostent* hostEnt = gethostbyname( hostName );
   if(!hostEnt)
   {
      ErrLog(<< "gethostbyname failed, returning \"127.0.0.1\"");
      assert(0);
      return "127.0.0.1";
   }
   
   struct in_addr* addr = (struct in_addr*) hostEnt->h_addr_list[0];
   if( !addr )
   {
      ErrLog(<< "gethostbyname returned a hostent* with an empty h_addr_list,"
               " returning \"127.0.0.1\"");
      assert(0);
      return "127.0.0.1";
   }
   
   // if you change this, please #def old version for windows 
   char* addrA = inet_ntoa( *addr );
   Data ret(addrA);

   //Data retHost( hostEnt->h_name );

   return ret;
}
Data SipStack::getHostname ( ) [static]

Get one of the names for this host (calls through to gethostbyname) and is not threadsafe.

Definition at line 450 of file SipStack.cxx.

References ErrLog.

Referenced by main(), myMain(), and Server::thread().

{
   // if you change this, please #def old version for windows
   char hostName[1024];
   int err =  gethostname( hostName, sizeof(hostName) );
   if(err != 0)
   {
      ErrLog(<< "gethostname failed with return " << err << " Returning "
            "\"localhost\"");
      assert(0);
      return "localhost";
   }
   
   struct hostent* hostEnt = gethostbyname( hostName );
   if ( !hostEnt )
   {
      // this can fail when there is no name server
      // !cj! - need to decided what error to return
      ErrLog( << "gethostbyname failed - name server is probably down" );
      return "localhost";
   }
   assert( hostEnt );

   struct in_addr* addr = (struct in_addr*) hostEnt->h_addr_list[0];
   assert( addr );

   // if you change this, please #def old version for windows
   char* addrA = inet_ntoa( *addr );
   Data ret(addrA);

   Data retHost( hostEnt->h_name );

   return retHost;
}
FdPollGrp* resip::SipStack::getPollGrp ( ) [inline]

Definition at line 701 of file SipStack.hxx.

References mPollGrp.

Referenced by myMain().

{return mPollGrp;} 
Security * SipStack::getSecurity ( ) const

Returns a pointer to the embedded Security object, 0 if not set.

Definition at line 853 of file SipStack.cxx.

References mSecurity.

Referenced by resip::TuIM::haveCerts(), myMain(), resip::TuIM::processMessageRequest(), resip::TuIM::processSipFrag(), and resip::TuIM::sendPage().

{
    return mSecurity;
}
unsigned int SipStack::getTimeTillNextProcessMS ( ) [virtual]

Returns time in milliseconds when process next needs to be called.

returns time in milliseconds when process next needs to be called

Returns:
The maximum time in ms that whatever is giving the SipStack processing cycles should wait before calling either process(unsigned int) or process(FdSet&). In most circumstances, this is simply when the next timer (either an app timer, or a SIP transaction timer) is scheduled to fire. However, in cases where there is processing work to be done (in the form of messages in a fifo somewhere), this will return 0.

Implements resip::FdSetIOObserver.

Definition at line 829 of file SipStack.cxx.

References resip::Timer::getMaxSystemTimeWaitMs(), resip::DnsStub::getTimeTillNextProcessMS(), resip::TransactionController::getTimeTillNextProcessMS(), resip::TuSelector::getTimeTillNextProcessMS(), resip::TransportSelector::getTimeTillNextProcessMS(), mAppTimerMutex, mAppTimers, mDnsStub, mDnsThread, resip::TimerQueue< T >::msTillNextTimer(), mTransactionController, mTransactionControllerThread, mTransportSelectorThread, mTuSelector, resip::resipMin(), and resip::TransactionController::transportSelector().

Referenced by process(), resip::StackThread::thread(), resip::InterruptableStackThread::thread(), and resip::EventStackThread::thread().

{
   Lock lock(mAppTimerMutex);

   unsigned int dnsNextProcess = (mDnsThread ? 
                           INT_MAX : mDnsStub->getTimeTillNextProcessMS());
   unsigned int tcNextProcess = mTransactionControllerThread ? INT_MAX : 
                           mTransactionController->getTimeTillNextProcessMS();
   unsigned int tsNextProcess = mTransportSelectorThread ? INT_MAX : mTransactionController->transportSelector().getTimeTillNextProcessMS();

   return resipMin(Timer::getMaxSystemTimeWaitMs(),
            resipMin(dnsNextProcess,
               resipMin(tcNextProcess,
                  resipMin(tsNextProcess,
                     resipMin(mTuSelector.getTimeTillNextProcessMS(), mAppTimers.msTillNextTimer())))));
}

Here is the call graph for this function:

const Uri & SipStack::getUri ( ) const

Get one of the domains/ports that are handled by this stack in Uri form.

"sip:" scheme is assumed.

Definition at line 540 of file SipStack.cxx.

References CritLog, resip::Data::empty(), resip::Uri::host(), and mUri.

{
   if(mUri.host().empty())
   {
      CritLog(<< "There are no associated transports");
      throw Exception("No associated transports", __FILE__, __LINE__);
   }

   return mUri;
}

Here is the call graph for this function:

bool SipStack::hasMessage ( ) const

does the stack have new messages for the TU?

Returns:
return true if the stack has new messages for the TU.
Deprecated:
Since the addition of TransactionUsers, this method is deprecated. This only looks into the old TuFifo that is not associated with any TransactionUser.

Definition at line 716 of file SipStack.cxx.

References resip::AbstractFifo< T >::messageAvailable(), and mTUFifo.

Referenced by StackThreadPair::wait().

{
   return mTUFifo.messageAvailable();
}

Here is the call graph for this function:

void SipStack::init ( const SipStackOptions options) [private]

Performs bulk of work of constructor.

Definition at line 136 of file SipStack.cxx.

References resip::FdPollGrp::create(), resip::DnsStub::EmptyNameserverList, resip::Timer::getTimeMs(), resip::Random::initialize(), resip::initNetwork(), resip::SipStackOptions::mAsyncProcessHandler, mAsyncProcessHandler, resip::SipStackOptions::mCompression, mCompression, mCongestionManager, mDnsStub, mDnsThread, resip::SipStackOptions::mExtraNameserverList, mInterruptorIsMine, resip::SipStackOptions::mPollGrp, mPollGrp, mPollGrpIsMine, mRunning, resip::SipStackOptions::mSecurity, mSecurity, mShuttingDown, resip::SipStackOptions::mSocketFunc, mSocketFunc, mStatisticsManagerEnabled, mTransactionController, mTransactionControllerThread, mTransportSelectorThread, resip::Compression::NONE, resip::Security::preload(), resip::TransportSelector::setPollGrp(), TransactionController, and resip::TransactionController::transportSelector().

Referenced by SipStack().

{
   mPollGrpIsMine=false;
   if ( options.mPollGrp )
   {
      mPollGrp = options.mPollGrp;
   }
   else
   {
      mPollGrp = FdPollGrp::create();
      mPollGrpIsMine=true;
   }

#ifdef USE_SSL
   mSecurity = options.mSecurity ? options.mSecurity : new Security();
   mSecurity->preload();
#else
   mSecurity = 0;
   assert(options.mSecurity==0);
#endif

   if(options.mAsyncProcessHandler)
   {
      mAsyncProcessHandler = options.mAsyncProcessHandler;
      mInterruptorIsMine = false;
   }
   else
   {
      mInterruptorIsMine = true;
      mAsyncProcessHandler = new SelectInterruptor;
   }

   mDnsStub = new DnsStub(
         options.mExtraNameserverList
                ? *options.mExtraNameserverList : DnsStub::EmptyNameserverList,
         options.mSocketFunc,
         mAsyncProcessHandler,
         mPollGrp);
   mDnsThread = 0;

   mCompression = options.mCompression
         ? options.mCompression : new Compression(Compression::NONE);

   mCongestionManager = 0;

   // WATCHOUT: the transaction controller constructor will
   // grab the security, DnsStub, compression and statsManager
   mTransactionController = new TransactionController(*this, mAsyncProcessHandler);
   mTransactionController->transportSelector().setPollGrp(mPollGrp);
   mTransactionControllerThread = 0;
   mTransportSelectorThread = 0;

   mRunning = false;
   mShuttingDown = false;
   mStatisticsManagerEnabled = true;
   mSocketFunc = options.mSocketFunc;

   // .kw. note that stats manager has already called getTimeMs()
   Timer::getTimeMs(); // initalize time offsets
   Random::initialize();
   initNetwork();
}

Here is the call graph for this function:

bool SipStack::isMyDomain ( const Data domain,
int  port 
) const

Returns true if domain is handled by this stack.

Convenience for Transaction Users.

Parameters:
domainDomain name to check.
portPort number to check.

Definition at line 527 of file SipStack.cxx.

References resip::Symbols::DefaultSipPort, and mDomains.

{
   return (mDomains.count(domain + ":" +
                          Data(port == 0 ? Symbols::DefaultSipPort : port)) != 0);
}
bool SipStack::isMyPort ( int  port) const

Returns true if port is handled by this stack.

Convenience for Transaction Users.

Parameters:
portPort number to check.

Definition at line 534 of file SipStack.cxx.

References mPorts.

{
   return mPorts.count(port) != 0;
}
void SipStack::logDnsCache ( )

Log the DNS Cache to WarningLog for Debugging.

Definition at line 935 of file SipStack.cxx.

References resip::DnsStub::logDnsCache(), and mDnsStub.

Here is the call graph for this function:

SipStack& resip::SipStack::operator= ( const SipStack rhs) [private]

Disallow assignment, by not implementing.

bool SipStack::pollStatistics ( )

Immediately polls for statistics to be logged and sent to external handlers, instead of waiting for next statistics interval.

Returns false if statistics manager is not enabled.

Definition at line 874 of file SipStack.cxx.

References mTransactionController, resip::TransactionController::pollStatistics(), and statisticsManagerEnabled().

{
   if(statisticsManagerEnabled())
   {
      mTransactionController->pollStatistics();
      return true;
   }
   return false;
}

Here is the call graph for this function:

void SipStack::post ( std::auto_ptr< ApplicationMessage message,
unsigned int  secondsLater,
TransactionUser tu = 0 
)

Makes the message available to the TU at some later time, specified in seconds.

Note:
TransactionUser subclasses can just post to themselves.
Parameters:
messageApplicationMessage to post
secondsLaterNumber of seconds before message is to be posted.
tuTransactionUser to post to.

Definition at line 681 of file SipStack.cxx.

References postMS().

Referenced by resip::StatisticsManager::poll().

{
   postMS(message, secondsLater*1000, tu);
}

Here is the call graph for this function:

void SipStack::post ( std::auto_ptr< ApplicationMessage message)

Makes the message available to the TU later.

Note:
TranasctionUser subclasses can just post to themselves.
Parameters:
messageApplicationMessage to post

Definition at line 644 of file SipStack.cxx.

References resip::TuSelector::add(), mShuttingDown, and mTuSelector.

Here is the call graph for this function:

void SipStack::post ( const ApplicationMessage message)

Makes the message available to the TU later.

Note:
Makes a copy of the Message. Caller is responsible for deleting the memory and may do so as soon as it returns.
TranasctionUser subclasses can just post to themselves.
Parameters:
messageApplicationMessage to post

Definition at line 651 of file SipStack.cxx.

References resip::TuSelector::add(), resip::Message::clone(), mShuttingDown, and mTuSelector.

Here is the call graph for this function:

void SipStack::post ( const ApplicationMessage message,
unsigned int  secondsLater,
TransactionUser tu = 0 
)

Makes the message available to the TU at some later time, specified in seconds.

Note:
Makes a copy of the ApplicationMessage. Caller is responsible for deleting the memory and may do so as soon as it returns.
TranasctionUser subclasses can just post to themselves.
Parameters:
messageApplicationMessage to post.
secondsLaterNumber of seconds before message is to be posted.
tuTransactionUser to post to.

Definition at line 659 of file SipStack.cxx.

References mShuttingDown, and postMS().

{
   assert(!mShuttingDown);
   postMS(message, secondsLater*1000, tu);
}

Here is the call graph for this function:

void SipStack::postMS ( const std::auto_ptr< ApplicationMessage message,
unsigned int  ms,
TransactionUser tu = 0 
)

Makes the message available to the TU at some later time, specified in milli-seconds.

Note:
TransactionUser subclasses can just post to themselves.
Parameters:
messageApplicationMessage to post
msNumber of milli-seconds before message is to be posted.
tuTransactionUser to post to.

Definition at line 690 of file SipStack.cxx.

References resip::TuSelectorTimerQueue::add(), checkAsyncProcessHandler(), mAppTimerMutex, mAppTimers, and mShuttingDown.

Referenced by post().

{
   assert(!mShuttingDown);
   if (tu) message->setTransactionUser(tu);
   Lock lock(mAppTimerMutex);
   mAppTimers.add(ms, message.release());
   //.dcm. timer update rather than process cycle...optimize by checking if sooner
   //than current timeTillNextProcess?
   checkAsyncProcessHandler();
}

Here is the call graph for this function:

void SipStack::postMS ( const ApplicationMessage message,
unsigned int  ms,
TransactionUser tu = 0 
)

Makes the message available to the TU at some later time, specified in milli-seconds.

Note:
Makes a copy of the ApplicationMessage. Caller is responsible for deleting the memory and may do so as soon as it returns.
TranasctionUser subclasses can just post to themselves.
Parameters:
messageApplicationMessage to post
msNumber of milli-seconds before message is to be posted.
tuTransactionUser to post to.

Definition at line 667 of file SipStack.cxx.

References resip::TuSelectorTimerQueue::add(), checkAsyncProcessHandler(), resip::Message::clone(), mAppTimerMutex, mAppTimers, mShuttingDown, and resip::Message::setTransactionUser().

{
   assert(!mShuttingDown);
   Message* toPost = message.clone();
   if (tu) toPost->setTransactionUser(tu);
   Lock lock(mAppTimerMutex);
   mAppTimers.add(ms,toPost);
   //.dcm. timer update rather than process cycle...optimize by checking if sooner
   //than current timeTillNextProcess?
   checkAsyncProcessHandler();
}

Here is the call graph for this function:

void SipStack::process ( FdSet fdset) [virtual]

This allows the executive to give processing time to stack components.

Note:
Must call buildFdSet and select before calling this.
The transports are serviced, and then timers are serviced.
Parameters:
fdseta populated and 'select'ed fdset
Deprecated:
Because of serious shortcomings in fd_set (most notably the inability to store FDs whose value exceeds a relatively small number; ~1000), we are deprecating the FdSet-based process loop.
See also:
EventStackThread for an alternative, or if you wish to drive the SipStack yourself,
process(unsigned int). On platforms that do not support epoll, fd_set ends up being used anyway since there is no other choice, but this is hidden from the app.

Implements resip::FdSetIOObserver.

Definition at line 810 of file SipStack.cxx.

References mPollGrp, resip::FdPollGrp::processFdSet(), and processTimers().

Referenced by doit(), main(), myMain(), poller(), processTimeouts(), resip::StackThread::thread(), and resip::InterruptableStackThread::thread().

Here is the call graph for this function:

bool SipStack::process ( unsigned int  timeoutMs)

Give processing time to the SipStack components, when operating in single-threaded mode.

This call will allow all the components in the SipStack a chance to perform processing. This includes:

  • Transaction processing (handling of SIP messages and timers)
  • DNS processing (includes DNS network IO and 3263 logic)
  • Transport processing (network IO for raw SIP traffic)
  • Application timers

To give the SipStack cycles, it is sufficient to simply call this function repeatedly.

Parameters:
timeoutMsThe maximum time, in milliseconds, we will wait for IO in this call. We will not necessarily wait this long if no IO occurs; if timers are scheduled to fire before this duration elapses, our timeout value will be adjusted accordingly. Similarly, if there is work waiting in fifos when this call is made, no timeout will be used. Lower values will cause higher CPU utilization when idle, higher values may result in processing delays of messages from the TU sent during the call to process(unsigned int) (eg; you call process(50), then immediately schedule an app timer to fire in 25ms, or send a SipMessage to the stack, it could be 50ms before either of these are processed). You can work around these caveats by creating a SelectInterruptor, adding its FD to the SipStack's FdPollGrp, and calling SelectInterruptor::interrupt() to cause process(unsigned int) to be interrupted. The best approach will vary, based on your performance needs.
Note:
If you wish to add an FD that will interrupt this call if it becomes ready (either because it has IO you are interested in, or merely to interrupt this call to carry out some unrelated task, see getPollGrp())
Returns:
Whether any work was done as a result of this call.

Definition at line 817 of file SipStack.cxx.

References getTimeTillNextProcessMS(), mPollGrp, processTimers(), resip::resipMin(), and resip::FdPollGrp::waitAndProcess().

{
   // Go ahead and do this first. Should cut down on how frequently we call 
   // waitAndProcess() with a timeout of 0, which should improve efficiency 
   // somewhat.
   processTimers();
   bool result=mPollGrp->waitAndProcess(resipMin(timeoutMs, getTimeTillNextProcessMS()));
   return result;
}

Here is the call graph for this function:

void SipStack::processTimers ( ) [virtual]
SipMessage * SipStack::receive ( )

retrieve a SipMessage off the old TuFifo

Retrieve a SipMessage off the old TuFifo. Caller now owns the memory. Returns 0 if nothing there. Since the addition of TransactionUsers, this method is deprecated. This only looks into the old TuFifo that is not associated with any TransactionUser.

Note:
Applications posting non-sip messages must use receive any. If non SipMessages are on the Fifo, then they are just deleted.
Deprecated:
Returns:
pointer to received SipMessage, 0 if nothing there.

Definition at line 722 of file SipStack.cxx.

References resip::Message::brief(), DebugLog, resip::TimeLimitFifo< Msg >::getNext(), resip::AbstractFifo< T >::messageAvailable(), and mTUFifo.

Referenced by main(), poller(), resip::TuIM::process(), and processTimeouts().

{
   // Check to see if a message is available and if it is return the
   // waiting message. Otherwise, return 0
   if (mTUFifo.messageAvailable())
   {
      // we should only ever have SIP messages on the TU Fifo
      // unless we've registered for termination messages.
      Message* msg = mTUFifo.getNext();
      SipMessage* sip = dynamic_cast<SipMessage*>(msg);
      if (sip)
      {
         DebugLog (<< "RECV: " << sip->brief());
         return sip;
      }
      else
      {
         // assert(0); // !CJ! removed the assert - happens 1 minute after
         // stack starts up
         delete msg;
         return 0;
      }
   }
   else
   {
      return 0;
   }
}

Here is the call graph for this function:

Message * SipStack::receiveAny ( )

retrieve a message off the old TuFifo

Retrieve a Message off the old TuFifo. Caller now owns the memory. Returns 0 if nothing there. Since the addition of TransactionUsers, this method is deprecated. This only looks into the old TuFifo that is not associated with any TransactionUser.

Note:
Applications posting non-sip messages must use receive any. If non SipMessages are on the Fifo, then they are just deleted.
Deprecated:
Returns:
pointer to received Message, 0 if nothing there. May return TransactionTerminated*, TimerMessage*, SipMessage* or derived ApplicationMessage*

Definition at line 752 of file SipStack.cxx.

References resip::Message::brief(), DebugLog, resip::TimeLimitFifo< Msg >::getNext(), resip::AbstractFifo< T >::messageAvailable(), and mTUFifo.

{
   // Check to see if a message is available and if it is return the
   // waiting message. Otherwise, return 0
   if (mTUFifo.messageAvailable())
   {
      // application messages can flow through
      Message* msg = mTUFifo.getNext();
      SipMessage* sip=dynamic_cast<SipMessage*>(msg);
      if (sip)
      {
         DebugLog (<< "RECV: " << sip->brief());
      }
      return msg;
   }
   else
   {
      return 0;
   }
}

Here is the call graph for this function:

void SipStack::registerMarkListener ( MarkListener listener)

Register a handler with the DNS Interface for notifications of when a Dns Resource Record has been blacklisted.

Parameters:
listenerClass implementing the onMark() callback event sink defined in MarkListener

Definition at line 905 of file SipStack.cxx.

References mTransactionController, and resip::TransactionController::registerMarkListener().

Here is the call graph for this function:

void SipStack::registerTransactionUser ( TransactionUser tu)

add a TU to the TU selection chain

Adds a TU to the TU selection chain. Tu's do not call receive or receiveAny, the SipStack will call postToTu on the appropriate Tu. Messages not associated with a registered TU go into SipStack::mTuFifo.

Definition at line 885 of file SipStack.cxx.

References mTuSelector, and resip::TuSelector::registerTransactionUser().

Here is the call graph for this function:

void SipStack::requestTransactionUserShutdown ( TransactionUser tu)

Queue a shutdown request to the specified TU.

Definition at line 891 of file SipStack.cxx.

References checkAsyncProcessHandler(), mTuSelector, and resip::TuSelector::requestTransactionUserShutdown().

Here is the call graph for this function:

void SipStack::run ( )

Causes this SipStack object to create and run threads for carrying out processing.

This includes a thread for DNS lookups, a thread for transaction processing, and a thread for transport processing (individual Transport objects may be registered as having their own thread; these are not serviced by the thread spawned by this call). This function is intended to be used in addition to the normal method/s of giving the SipStack cycles (eg; EventStackThread, StackThread, etc); these are still necessary to give the SipStack cycles for handling application timers, statistics logging, and shutdown logic.

Definition at line 234 of file SipStack.cxx.

References mDnsStub, mDnsThread, mRunning, mTransactionController, mTransactionControllerThread, mTransportSelectorThread, resip::ThreadIf::run(), and resip::TransactionController::transportSelector().

Here is the call graph for this function:

void SipStack::send ( const SipMessage msg,
TransactionUser tu = 0 
)

allows a TU to send a message

Interface for the TU to send a message. Makes a copy of the SipMessage. Caller is responsible for deleting the memory and may do so as soon as it returns. Loose Routing processing as per RFC3261 must be done before calling send by the TU. See Helper::processStrictRoute

Parameters:
msgSipMessage to send.
tuTransactionUser to send from.
See also:
TransactionUser

Definition at line 552 of file SipStack.cxx.

References resip::Message::brief(), resip::SipMessage::clone(), DebugLog, mTransactionController, resip::TransactionController::send(), and resip::Message::setTransactionUser().

Referenced by doit(), main(), poller(), resip::TuIM::process(), processInject(), resip::TuIM::processMessageRequest(), resip::TuIM::processNotifyRequest(), resip::TuIM::processRegisterRequest(), resip::TuIM::processRegisterResponse(), resip::TuIM::processRequest(), resip::TuIM::processSubscribeRequest(), resip::TuIM::registerAor(), resip::TuIM::sendNotify(), resip::TuIM::sendPage(), resip::TuIM::sendPublish(), and resip::TuIM::subscribeBuddy().

{
   DebugLog (<< "SEND: " << msg.brief());
   //DebugLog (<< msg);
   //assert(!mShuttingDown);

   SipMessage* toSend = static_cast<SipMessage*>(msg.clone());
   if (tu)
   {
      toSend->setTransactionUser(tu);
   }
   toSend->setFromTU();

   mTransactionController->send(toSend);
}

Here is the call graph for this function:

void SipStack::send ( std::auto_ptr< SipMessage msg,
TransactionUser tu = 0 
)

Definition at line 569 of file SipStack.cxx.

References DebugLog, mTransactionController, and resip::TransactionController::send().

{
   DebugLog (<< "SEND: " << msg->brief());

   if (tu)
   {
      msg->setTransactionUser(tu);
   }
   msg->setFromTU();

   mTransactionController->send(msg.release());
}

Here is the call graph for this function:

void resip::SipStack::sendOverExistingConnection ( const SipMessage msg,
const Tuple tuple,
TransactionUser tu = 0 
) [inline]

force the a message out over an existing connection

This is only if you want to force send to only send over an existing connection. If there is no connection, then it will try the next tuple. If there are no more Tuples to try, then a 503 is sent to the TU. Makes a copy of the SipMessage. Caller is responsible for deleting the memory and may do so as soon as it returns.

Parameters:
msgSipMessage to send.
tupleDestination to send to, specified as a Tuple. A connection to this destination must exist.
tuTransactionUser to send from.

Definition at line 1077 of file SipStack.hxx.

References resip::Tuple::mFlowKey, resip::Tuple::onlyUseExistingConnection, and sendTo().

{
   assert(tuple.mFlowKey);
   Tuple tup(tuple);
   tup.onlyUseExistingConnection = true;
   sendTo(msg, tuple, tu);
}

Here is the call graph for this function:

void SipStack::sendTo ( std::auto_ptr< SipMessage msg,
const Uri uri,
TransactionUser tu = 0 
)

this is only if you want to send to a destination not in the route.

Note:
You probably don't want to use it.

Definition at line 583 of file SipStack.cxx.

References mTransactionController, and resip::TransactionController::send().

Referenced by sendOverExistingConnection().

{
   if (tu) msg->setTransactionUser(tu);
   msg->setForceTarget(uri);
   msg->setFromTU();

   mTransactionController->send(msg.release());
}

Here is the call graph for this function:

void SipStack::sendTo ( std::auto_ptr< SipMessage msg,
const Tuple tuple,
TransactionUser tu = 0 
)

this is only if you want to send to a destination not in the route.

Note:
You probably don't want to use it.

Definition at line 593 of file SipStack.cxx.

References mShuttingDown, mTransactionController, and resip::TransactionController::send().

{
   assert(!mShuttingDown);

   if (tu) msg->setTransactionUser(tu);
   msg->setDestination(destination);
   msg->setFromTU();

   mTransactionController->send(msg.release());
}

Here is the call graph for this function:

void SipStack::sendTo ( const SipMessage msg,
const Uri uri,
TransactionUser tu = 0 
)

send a message to a destination not in the route

This is only if you want to send to a destination not in the route. Useful for implementing Outbound Proxy use. Makes a copy of the SipMessage. Caller is responsible for deleting the memory and may do so as soon as it returns.

Parameters:
msgSipMessage to send.
uriDestination to send to, specified as a Uri.
tuTransactionUser to send from.

Definition at line 607 of file SipStack.cxx.

References resip::SipMessage::clone(), mTransactionController, resip::TransactionController::send(), resip::SipMessage::setForceTarget(), resip::SipMessage::setFromTU(), and resip::Message::setTransactionUser().

{
   //assert(!mShuttingDown);

   SipMessage* toSend = static_cast<SipMessage*>(msg.clone());
   if (tu) toSend->setTransactionUser(tu);
   toSend->setForceTarget(uri);
   toSend->setFromTU();

   mTransactionController->send(toSend);
}

Here is the call graph for this function:

void SipStack::sendTo ( const SipMessage msg,
const Tuple tuple,
TransactionUser tu = 0 
)

send a message to a destination not in the route

This is only if you want to send to a destination not in the route. Useful for implementing Outbound Proxy use. Makes a copy of the SipMessage. Caller is responsible for deleting the memory and may do so as soon as it returns.

Parameters:
msgSipMessage to send.
tupleDestination to send to, specified as a Tuple.
tuTransactionUser to send from.

Definition at line 622 of file SipStack.cxx.

References resip::SipMessage::clone(), mShuttingDown, mTransactionController, resip::TransactionController::send(), resip::SipMessage::setDestination(), resip::SipMessage::setFromTU(), and resip::Message::setTransactionUser().

{
   assert(!mShuttingDown);

   SipMessage* toSend = static_cast<SipMessage*>(msg.clone());
   if (tu) toSend->setTransactionUser(tu);
   toSend->setDestination(destination);
   toSend->setFromTU();

   mTransactionController->send(toSend);
}

Here is the call graph for this function:

void resip::SipStack::setCongestionManager ( CongestionManager manager) [inline]

Sets the CongestionManager used by the stack.

In order to use a congestion-manager, you will need to create one and pass it to the SipStack, like so:

          MyCongestionManager* mCM = new MyCongestionManager;
          mStack.setCongestionManager(mCM);

This will cause the SipStack to register all its fifos with the congestion manager, and will also call TransactionUser::setCongestionManager() for every currently registered TransactionUser. This means that, if you are working with such a TransactionUser, you must have registered the TransactionUser with the SipStack before making this call.

If you are using the SipStack directly by implementing your own subclass of TransactionUser, you can override TransactionUser::setCongestionManager() to register additional fifos (the default implementation registers TransactionUser::mFifo), like so

         MyTransactionUser::setCongestionManager(CongestionManager* cm)
         {
          TransactionUser::setCongestionManager(cm);
          if(mCongestionManager)
          {
             mCongestionManager->unregisterFifo(&mExtraFifo);
          }
          mCongestionManager=cm;
          if(mCongestionManager)
          {
             mCongestionManager->registerFifo(&mExtraFifo);
          }
         }
Parameters:
managerThe CongestionManager to use. Ownership is not taken.

Definition at line 946 of file SipStack.hxx.

References mCongestionManager, mTransactionController, mTUFifo, mTuSelector, resip::CongestionManager::registerFifo(), resip::TuSelector::setCongestionManager(), resip::TransactionController::setCongestionManager(), and resip::CongestionManager::unregisterFifo().

Referenced by SipStackAndThread::setCongestionManager().

      {
         mTransactionController->setCongestionManager(manager);
         mTuSelector.setCongestionManager(manager);
         if(mCongestionManager)
         {
            mCongestionManager->unregisterFifo(&mTUFifo);
         }
         mCongestionManager=manager;
         if(mCongestionManager)
         {
            mCongestionManager->registerFifo(&mTUFifo);
         }
      }

Here is the call graph for this function:

void resip::SipStack::setContentLengthChecking ( bool  check) [inline]

Used to enable/disable content-length checking on datagram-based transports.

Todo:
should this be fixed to work with other applicable transports? []

Used to enable/disable content-length checking on datagram-based transports. If disabled, the stack will ignore the value of the Content-Length header, and assume that the end of the payload is at the end of the datagram (and not before). If enabled, it will take the Content-Length seriously, log a warning if the Content-Length is too short, and reject the message if the Content-Length is too long.

Parameters:
checkDenotes whether we should check Content-Length.
Note:
By default, Content-Length checking is enabled.
only works on UDP at this time

Definition at line 900 of file SipStack.hxx.

References resip::SipMessage::checkContentLength.

void SipStack::setEnumSuffixes ( const std::vector< Data > &  suffixes)

Specify which enum domains will be searched when sending.

Specify which enum domains will be searched when sending to URIs that return true to Uri::isEnumSearchable(). An enum query will be done for each suffix in parallel.

Definition at line 923 of file SipStack.cxx.

References mDnsStub, and resip::DnsStub::setEnumSuffixes().

{
   mDnsStub->setEnumSuffixes(suffixes);
}

Here is the call graph for this function:

void resip::SipStack::setExternalStatsHandler ( ExternalStatsHandler handler) [inline]

Installs a handler for the stacks internal StatisticsManager.

This handler is called before the default behavior.

Definition at line 750 of file SipStack.hxx.

References mStatsManager, and resip::StatisticsManager::setExternalStatsHandler().

      {
         mStatsManager.setExternalStatsHandler(handler);
      }

Here is the call graph for this function:

void SipStack::setFallbackPostNotify ( AsyncProcessHandler handler)

Definition at line 774 of file SipStack.cxx.

References mTuSelector, and resip::TuSelector::setFallbackPostNotify().

Referenced by SipStackAndThread::SipStackAndThread().

Here is the call graph for this function:

void resip::SipStack::setFixBadCSeqNumbers ( bool  pFixBadCSeqNumbers) [inline]

Definition at line 879 of file SipStack.hxx.

References mTransactionController, and resip::TransactionController::setFixBadCSeqNumbers().

      {
         mTransactionController->setFixBadCSeqNumbers(pFixBadCSeqNumbers);
      }

Here is the call graph for this function:

void resip::SipStack::setFixBadDialogIdentifiers ( bool  pFixBadDialogIdentifiers) [inline]

Specify whether the stack should fix corrupted/changed dialog identifiers (ie, Call-Id and tags) in responses from the wire.

This is intended to help TransactionUsers that assume responses will come back with the same dialog identifiers that the request had (excepting of course the remote tag for dialog-forming requests).

Parameters:
pFixBadDialogIdentifiersDenotes whether the stack should fix corrupted/changed dialog identifiers.
Note:
This is enabled by default, and is recommended for dialog-stateful TransactionUsers.

Definition at line 869 of file SipStack.hxx.

References resip::TransactionController::mFixBadDialogIdentifiers, and mTransactionController.

      {
         mTransactionController->mFixBadDialogIdentifiers = pFixBadDialogIdentifiers;
      }
void SipStack::setStatisticsInterval ( unsigned long  seconds)

Sets the interval that determines the time between Statistics messages.

Definition at line 859 of file SipStack.cxx.

References mStatsManager, and resip::StatisticsManager::setInterval().

Referenced by main().

{
   mStatsManager.setInterval(seconds);
}

Here is the call graph for this function:

void SipStack::shutdown ( )

perform orderly shutdown

Inform the transaction state machine processor that it should not create any new transactions and to perform an orderly shutdown. When the transactions are all terminated, return a ShutdownMessage to the TU.

Note:
If the SipStack is running in multithreaded mode, this function DOES NOT shut down the threads. This is what shutdownAndJoinThreads() is for. (Shutting down threads in this call would prevent orderly shutdown from working; outstanding transactions would be dropped on the floor)

Definition at line 256 of file SipStack.cxx.

References InfoLog, mShutdownMutex, mShuttingDown, mTransactionController, and resip::TransactionController::shutdown().

{
   InfoLog (<< "Shutting down sip stack " << this);

   {
      Lock lock(mShutdownMutex);
      assert(!mShuttingDown);
      mShuttingDown = true;
   }

   mTransactionController->shutdown();
}

Here is the call graph for this function:

void SipStack::shutdownAndJoinThreads ( )
Fifo< TransactionMessage > & SipStack::stateMacFifo ( )

Returns the fifo that subclasses of Transport should use for the rxFifo cons.

param.

Returns:
A fifo of TransactionMessage's

Definition at line 427 of file SipStack.cxx.

References mTransactionController, resip::TransportSelector::stateMacFifo(), and resip::TransactionController::transportSelector().

Referenced by addTransport().

Here is the call graph for this function:

volatile bool & SipStack::statisticsManagerEnabled ( )

Enable Statistics Manager.

Todo:
is this documented correctly? [!]

Enable Statistics Manager. SIP Statistics will be collected and dispatched periodically via a StatisticsMessage.

Note:
By default the Statistics Manager is enabled.

Definition at line 947 of file SipStack.cxx.

References mStatisticsManagerEnabled.

Referenced by pollStatistics(), resip::TransactionState::process(), resip::TransactionState::sendCurrentToWire(), and zeroOutStatistics().

const bool SipStack::statisticsManagerEnabled ( ) const

Definition at line 953 of file SipStack.cxx.

References mStatisticsManagerEnabled.

void SipStack::terminateFlow ( const resip::Tuple flow)

Definition at line 984 of file SipStack.cxx.

References mTransactionController, and resip::TransactionController::terminateFlow().

Here is the call graph for this function:

void SipStack::unregisterMarkListener ( MarkListener listener)

Removed a registered BlacklistListener handler from the DNS Interface for a particualr Resource Record type and handler pointer.

Parameters:
listenerClass implementing the onMark() callback event sink defined in MarkListener

Definition at line 911 of file SipStack.cxx.

References mTransactionController, and resip::TransactionController::unregisterMarkListener().

Here is the call graph for this function:

void SipStack::unregisterTransactionUser ( TransactionUser tu)

Removes a TU from the TU selection chain.

Definition at line 898 of file SipStack.cxx.

References checkAsyncProcessHandler(), mTuSelector, and resip::TuSelector::unregisterTransactionUser().

Here is the call graph for this function:

void SipStack::zeroOutStatistics ( )

Resets all of the cumulative statistics counters.

Definition at line 865 of file SipStack.cxx.

References mTransactionController, statisticsManagerEnabled(), and resip::TransactionController::zeroOutStatistics().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Executive [friend]

Definition at line 1064 of file SipStack.hxx.

friend class StatelessHandler [friend]

Definition at line 1065 of file SipStack.hxx.

friend class StatisticsManager [friend]

Definition at line 1066 of file SipStack.hxx.

friend class TestDnsResolver [friend]

Definition at line 1067 of file SipStack.hxx.

friend class TestFSM [friend]

Definition at line 1068 of file SipStack.hxx.

friend class TransactionController [friend]

Definition at line 1070 of file SipStack.hxx.

Referenced by init().

friend class TransactionState [friend]

Definition at line 1069 of file SipStack.hxx.

friend class TuSelector [friend]

Definition at line 1071 of file SipStack.hxx.


Member Data Documentation

Protection for AppTimerQueue.

Definition at line 1031 of file SipStack.hxx.

Referenced by dump(), getTimeTillNextProcessMS(), postMS(), and processTimers().

timers associated with the application. When a timer fires, it is placed in the mTUFifo (if there is not associated TU), or it is placed on the fifo of the appropriate TU

Definition at line 1036 of file SipStack.hxx.

Referenced by dump(), getTimeTillNextProcessMS(), postMS(), processTimers(), and SipStack().

if this object exists, it gets notified when messages are posted to any of the various fifos in the stack.

Note:
When running in multithreaded mode, this is only invoked when either app timers are scheduled, shutdown has been requested, or a TransactionUser has unregistered. The other fifos in the system are associated with their own AsyncProcessHandlers, since they are being processed by different threads.

Definition at line 1012 of file SipStack.hxx.

Referenced by checkAsyncProcessHandler(), init(), and ~SipStack().

If this object exists, it manages compression parameters.

Definition at line 1001 of file SipStack.hxx.

Referenced by addTransport(), getCompression(), init(), and ~SipStack().

std::set<Data> resip::SipStack::mDomains [private]

store all domains that this stack is responsible for.

Note:
Controlled by addAlias and addTransport interface and checks can be made with isMyDomain()

Definition at line 1051 of file SipStack.hxx.

Referenced by addAlias(), dump(), and isMyDomain().

Definition at line 1013 of file SipStack.hxx.

Referenced by init(), and ~SipStack().

Definition at line 991 of file SipStack.hxx.

Referenced by buildFdSet(), getPollGrp(), init(), process(), SipStack(), and ~SipStack().

Definition at line 992 of file SipStack.hxx.

Referenced by init(), and ~SipStack().

std::set<int> resip::SipStack::mPorts [private]

store all ports that this stack is lisenting on.

Controlled by addTransport and checks can be made with isMyPort()

Definition at line 1055 of file SipStack.hxx.

Referenced by addTransport(), and isMyPort().

bool resip::SipStack::mRunning [private]

Definition at line 1047 of file SipStack.hxx.

Referenced by init(), run(), and shutdownAndJoinThreads().

if this object exists, it manages advanced security featues

Definition at line 995 of file SipStack.hxx.

Referenced by addTransport(), dump(), getSecurity(), init(), and ~SipStack().

Definition at line 1059 of file SipStack.hxx.

Referenced by shutdown().

Definition at line 1058 of file SipStack.hxx.

Referenced by addAlias(), addTransport(), init(), post(), postMS(), processTimers(), sendTo(), and shutdown().

Definition at line 1062 of file SipStack.hxx.

Referenced by addTransport(), and init().

Definition at line 1043 of file SipStack.hxx.

Definition at line 1060 of file SipStack.hxx.

Referenced by init(), processTimers(), and statisticsManagerEnabled().

Used to Track stack statistics.

Definition at line 1039 of file SipStack.hxx.

Referenced by processTimers(), setExternalStatsHandler(), setStatisticsInterval(), and SipStack().

fifo used to communicate between the TU (TransactionUser) and stack

Note:
since the introduction of multiple TU's this Fifo should no longer be used by most applications - each TU now owns it's own Fifo.

Definition at line 1024 of file SipStack.hxx.

Referenced by dump(), hasMessage(), resip::TransactionController::process(), receive(), receiveAny(), setCongestionManager(), and SipStack().

Responsible for routing messages to the correct TU based on installed rules.

Definition at line 1028 of file SipStack.hxx.

Referenced by getTimeTillNextProcessMS(), post(), processTimers(), registerTransactionUser(), requestTransactionUserShutdown(), setCongestionManager(), setFallbackPostNotify(), SipStack(), and unregisterTransactionUser().

Definition at line 1057 of file SipStack.hxx.

Referenced by addAlias(), and getUri().


The documentation for this class was generated from the following files: