Ejemplo n.º 1
0
// Remove any dialogs in the terminated state.
// This operates only on the parsed dialogs in mXmlDialogs, used to generate
// the consolidated state.  The RFC 4662 events are not affected, but
// presumably the resource is not allowing terminated dialogs to accumulate
// in the events it sends.
void ResourceInstance::purgeTerminatedDialogs()
{
   OsSysLog::add(FAC_RLS, PRI_DEBUG,
                 "ResourceInstance::purgeTerminatedDialogs mInstanceName = '%s'",
                 mInstanceName.data());

   // Iterate through all the <dialog> elements.
   UtlHashMapIterator itor(mXmlDialogs);
   UtlContainable* id;
   while ((id = itor()))
   {
      // Get the <state> element content.
      UtlVoidPtr* p = dynamic_cast <UtlVoidPtr*> (itor.value());
      TiXmlElement* dialog_element =
         static_cast <TiXmlElement*> (p->getValue());
      TiXmlNode* state_node = dialog_element->FirstChild("state");
      UtlString state;
      textContentShallow(state, state_node);

      if (state.compareTo("terminated") == 0)
      {
         // This dialog was terminated.  Remove it.
         delete dialog_element;
         mXmlDialogs.destroy(id);
      }
   }
   // Note that we do not have to publish this change, as the deletion
   // of these dialogs does not have to be sent to the subscribers
   // quickly.
}
Ejemplo n.º 2
0
UtlBoolean SipUdpServer::getStunAddress(UtlString* pIpAddress, int* pPort,
                                        const char* szLocalIp) 
{
    UtlBoolean bRet = false;
    OsStunDatagramSocket* pSocket = NULL;
    UtlVoidPtr* pSocketContainer = NULL;

    if (szLocalIp)
    {
        UtlString localIpKey(szLocalIp);
       
        pSocketContainer = (UtlVoidPtr*)this->mServerSocketMap.findValue(&localIpKey);
        if (pSocketContainer)
        {
            pSocket = (OsStunDatagramSocket*)pSocketContainer->getValue();
        }
    }
    else
    {
        // just use the default Socket in our collection
        UtlString defaultIpKey(mDefaultIp);
       
        pSocketContainer = (UtlVoidPtr*)mServerSocketMap.findValue(&defaultIpKey);
        if (pSocketContainer != NULL )
        {
            pSocket = (OsStunDatagramSocket*)pSocketContainer->getValue();
        }
    }
    
    if (pSocket)
    {
        bRet =  pSocket->getExternalIp(pIpAddress, pPort) ;
    }
    return bRet;
}
Ejemplo n.º 3
0
UtlBoolean sipxIsCallInFocus()
{
    UtlBoolean inFocus = false ;
    if (gpCallHandleMap->lock())
    {
        UtlHashMapIterator iter(*gpCallHandleMap);

        UtlInt* pIndex = NULL;
        UtlVoidPtr* pObj = NULL;
        SIPX_CALL hCall = 0 ;

        while (pIndex = dynamic_cast<UtlInt*>( iter() ) )
        {
            pObj = dynamic_cast<UtlVoidPtr*>(gpCallHandleMap->findValue(pIndex));
            SIPX_CALL_DATA* pData = NULL ;
            if (pObj)
            {
                pData = (SIPX_CALL_DATA*) pObj->getValue() ;
                if (pData->bInFocus)
                {
                    inFocus = true ;
                    break ;
                }
            }
        }

        gpCallHandleMap->unlock() ;
    }

    return inFocus ;
}
Ejemplo n.º 4
0
// Dump the object's internal state.
void ResourceInstance::dumpState()
{
   // indented 12

   OsSysLog::add(FAC_RLS, PRI_INFO,
                 "\t            ResourceInstance %p mInstanceName = '%s', "
                 "mSubscriptionState = '%s', mContentPresent = %d, mContent = '%s'",
                 this, mInstanceName.data(), mSubscriptionState.data(),
                 mContentPresent,
                 mContentPresent ? mContent.data() : "[invalid]");

   UtlHashMapIterator itor(mXmlDialogs);
   UtlString* dialog_id;
   while ((dialog_id = dynamic_cast <UtlString*> (itor())))
   {
      UtlVoidPtr* p = dynamic_cast <UtlVoidPtr*> (itor.value());
      TiXmlElement* dialog_element =
         static_cast <TiXmlElement*> (p->getValue());
      UtlString s;
      TiXmlUtlStringWriter writer(&s);
      writer <<*dialog_element;

      OsSysLog::add(FAC_RLS, PRI_INFO,
                    "\t              mXmlDialogs{'%s'} = '%s'",
                    dialog_id->data(), s.data());
   }
}
Ejemplo n.º 5
0
const void* SipXHandleMap::removeHandle(SIPXHANDLE handle) 
{
    const void* pRC = NULL ;
    
    if (lock())
    {
        releaseHandleRef(handle);
        
        UtlInt* pCount = static_cast<UtlInt*>(mLockCountHash.findValue(&UtlInt(handle))) ;
        
        if (pCount == NULL || pCount->getValue() < 1)
        {
            UtlInt key(handle) ;
            UtlVoidPtr* pValue ;
            
            pValue = (UtlVoidPtr*) findValue(&key) ;
            if (pValue != NULL)
            {
                pRC = pValue->getValue() ;                
                destroy(&key) ;
            }

            if (pCount)
            {
                mLockCountHash.destroy(&UtlInt(handle));
            }
        }
    
        unlock() ;
    }

    return pRC ;
}
Ejemplo n.º 6
0
// Report to all the notifiers in mStateChangeNotifiers a new event
// 'dialogEvent' for AOR 'contact'.
void SipDialogMonitor::notifyStateChange(UtlString& contact,
                                         StateChangeNotifier::Status status)
{
   OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange "
                 "AOR = '%s', status = %s",
                 contact.data(),
                 (status == StateChangeNotifier::ON_HOOK ? "ON_HOOK" :
                  status == StateChangeNotifier::OFF_HOOK ? "OFF_HOOK" :
                  "UNKNOWN"));
   Url contactUrl(contact);

   // Loop through the notifier list, reporting the status to the notifiers.
   UtlHashMapIterator iterator(mStateChangeNotifiers);
   UtlString* listUri;
   UtlVoidPtr* container;
   StateChangeNotifier* notifier;
   while ((listUri = dynamic_cast <UtlString *> (iterator())))
   {
      container = dynamic_cast <UtlVoidPtr *> (mStateChangeNotifiers.findValue(listUri));
      notifier = (StateChangeNotifier *) container->getValue();
      // Report the status to the notifier.
      notifier->setStatus(contactUrl, status);
      OsSysLog::add(FAC_SIP, PRI_DEBUG,
                    "SipDialogMonitor::notifyStateChange setting state to %d",
                    status);
   }
}
Ejemplo n.º 7
0
// Destructor
SipUdpServer::~SipUdpServer()
{
    waitUntilShutDown();
    
    SipClient* pServer = NULL;
    UtlHashMapIterator iterator(mServers);
    UtlVoidPtr* pServerContainer = NULL;
    UtlString* pKey = NULL;
    
    while (pKey = (UtlString*)iterator())
    {
        pServerContainer = (UtlVoidPtr*)iterator.value();
        if (pServerContainer)
        {
            pServer = (SipClient*)pServerContainer->getValue();
            pServer->requestShutdown();
            delete pServer;
        }
    }
    mServers.destroyAll();

    mServerPortMap.destroyAll();    

    mServerSocketMap.destroyAll();
    
}
Ejemplo n.º 8
0
UtlBoolean SipTlsServer::startListener()
{
    UtlBoolean bRet(FALSE);
#       ifdef TEST_PRINT
        osPrintf("SIP Server binding to port %d\n", serverPort);
#       endif

    // iterate over the SipServerBroker map and call start
    UtlHashMapIterator iterator(mServerBrokers);
    UtlVoidPtr* pBrokerContainer = NULL;
    SipServerBroker* pBroker = NULL;
    UtlString* pKey = NULL;
    
    while(pKey = (UtlString*)iterator())
    {
        pBrokerContainer = (UtlVoidPtr*) iterator.value();
        if (pBrokerContainer)
        {
            pBroker = (SipServerBroker*)pBrokerContainer->getValue();
            if (pBroker)
            {
                pBroker->start();
                bRet = TRUE;
            }
        }
    }
    return bRet;
}
Ejemplo n.º 9
0
void SipUdpServer::printStatus()
{
    SipClient* pServer = NULL;
    UtlHashMapIterator iterator(mServers);
    UtlVoidPtr* pServerContainer = NULL;
    UtlString* pKey = NULL;
    
    while (pKey = (UtlString*)iterator())
    {
        pServerContainer = (UtlVoidPtr*) iterator.value();
        if (pServerContainer)
        {
            pServer = (SipClient*)pServerContainer->getValue();
        }
        if (pServer)
        {
            UtlString clientNames;
            long clientTouchedTime = pServer->getLastTouchedTime();
            UtlBoolean clientOk = pServer->isOk();
            pServer->getClientNames(clientNames);
            osPrintf("UDP server %p last used: %ld ok: %d names: \n%s \n",
                this, clientTouchedTime, clientOk, clientNames.data());

            SipProtocolServerBase::printStatus();
        }
    }
}
Ejemplo n.º 10
0
// Destructor
SipTlsServer::~SipTlsServer()
{
    waitUntilShutDown();
    if (mpServerBrokerListener)
    {
        mpServerBrokerListener->requestShutdown();
        delete mpServerBrokerListener;
    }
    {
        SipServerBroker* pBroker = NULL;
        UtlHashMapIterator iterator(this->mServerBrokers);
        UtlVoidPtr* pBrokerContainer = NULL;
        UtlString* pKey = NULL;
        
        while (pKey = (UtlString*)iterator())
        {
            pBrokerContainer = (UtlVoidPtr*)iterator.value();
            if (pBrokerContainer)
            {
                pBroker = (SipServerBroker*)pBrokerContainer->getValue();
                if (pBroker)
                {
                    pBroker->requestShutdown();
                    delete pBroker;
                }
            }
        }
        mServerBrokers.destroyAll();
    }

/*
    {
        OsSocket* pSocket = NULL;
        UtlHashMapIterator iterator(mServerSocketMap);
        UtlVoidPtr* pSocketContainer = NULL;
        UtlString* pKey = NULL;
        
        while (pKey = (UtlString*)iterator())
        {
            pSocketContainer = (UtlVoidPtr*)iterator.value();
            if (pSocketContainer)
            {
                pSocket = (OsSocket*)pSocketContainer->getValue();
                if (pSocket)
                {
                    delete pSocket;
                }
            }
        }
        mServerSocketMap.destroyAll();
    }
*/
    mServerSocketMap.destroyAll();
    mServerPortMap.destroyAll();


}
Ejemplo n.º 11
0
UtlBoolean SipProtocolServerBase::startListener()
{
#       ifdef TEST_PRINT
        osPrintf("SIP Server binding to port %d\n", serverPort);
#       endif

    UtlHashMapIterator iter(mServerSocketMap);
    UtlVoidPtr* pSocketContainer = NULL;
    UtlString* pKey;
    while ((pKey =(UtlString*)iter()))
    {
        OsSocket* pSocket = NULL;
        SipClient* pServer = NULL;
        UtlVoidPtr* pServerContainer = NULL;

        UtlString localIp = *pKey;
        pSocketContainer = (UtlVoidPtr*)iter.value();
         
        if (pSocketContainer)
        {    
            pSocket = (OsSocket*)pSocketContainer->getValue();
        }
        
        pServerContainer = (UtlVoidPtr*)mServers.findValue(&localIp);
        if (!pServerContainer)
        {
            pServer = new SipClient(pSocket);

            // This used to be done at the end of this else statement
            // however there is a race and the userAgent must be set before
            // starting this client.  I think the race occurs if there is
            // immediately an incoming message on the socket.
            if(mSipUserAgent)
            {
                if (pServer)
                {
                    pServer->setUserAgent(mSipUserAgent);
                }
            }
            this->mServers.insertKeyAndValue(new UtlString(localIp), new UtlVoidPtr((void*)pServer));
            pServer->start();
        }
        else
        {
            pServer = (SipClient*) pServerContainer->getValue();
            if(mSipUserAgent)
            {
                if (pServer)
                {
                    pServer->setUserAgent(mSipUserAgent);
                }
            }
        }
    }
    return(TRUE);
}
Ejemplo n.º 12
0
void SipDialogMonitor::notifyStateChange(UtlString& contact, SipDialogEvent* dialogEvent)
{
   OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange contact = %s",
                 contact.data());

   // Loop through the notifier list
   UtlHashMapIterator iterator(mStateChangeNotifiers);
   UtlString* listUri;
   UtlVoidPtr* container;
   StateChangeNotifier* notifier;
   Url contactUrl(contact);
   mLock.acquire();
   while (listUri = dynamic_cast <UtlString *> (iterator()))
   {
      container = dynamic_cast <UtlVoidPtr *> (mStateChangeNotifiers.findValue(listUri));
      notifier = (StateChangeNotifier *) container->getValue();

      if (dialogEvent->isEmpty())
      {
         notifier->setStatus(contactUrl, StateChangeNotifier::ON_HOOK);
         OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange dialog is empty, setting state to on hook");
      }
      else
      {
         Dialog* dialog = dialogEvent->getFirstDialog();
            
         UtlString state, event, code;
         dialog->getState(state, event, code);
            
         OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange dialog state = %s",
                       state.data());
         if (state.compareTo(STATE_CONFIRMED) == 0)
         {
            notifier->setStatus(contactUrl, StateChangeNotifier::OFF_HOOK);
            OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange setting state to off hook");
         }
         else
         {     
            if (state.compareTo(STATE_TERMINATED) == 0)
            {
               notifier->setStatus(contactUrl, StateChangeNotifier::ON_HOOK);
               OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange setting state to on hook");
            }
            else
            {
               notifier->setStatus(contactUrl, StateChangeNotifier::RINGING);
               OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipDialogMonitor::notifyStateChange setting state to ringing");
            }
         }
      }
   }
   mLock.release();
}
Ejemplo n.º 13
0
void SipXHandleMap::dump() 
{
    UtlHashMapIterator itor(*this) ;
    UtlInt* pKey ;
    UtlVoidPtr* pValue ;
        
    while ((pKey = (UtlInt*) itor()))
    {
        pValue = (UtlVoidPtr*) findValue(pKey) ;
        printf("\tkey=%08X, value=%p\n", pKey->getValue(), 
                pValue ? pValue->getValue() : 0) ;                        
    }       
}
Ejemplo n.º 14
0
// Destroy the contents of mXmlDialogs.
void ResourceInstance::destroyXmlDialogs()
{
   // First, follow through the UtlVoidPtr's to get pointers to the
   // XML trees and delete them.
   UtlHashMapIterator itor(mXmlDialogs);
   UtlContainable* id;
   while ((id = itor()))
   {
      UtlVoidPtr* p = dynamic_cast <UtlVoidPtr*> (itor.value());
      delete static_cast <TiXmlElement*> (p->getValue());
   }
   // Now clear the hash map and its keys and the UtlVoidPtr's themselves.
   mXmlDialogs.destroyAll();
}
Ejemplo n.º 15
0
void* OsLockingList::pop()
{
        void* element = NULL;

        // Lock before accessing the list
        OsLock localLock(listMutex);

        if (list.entries())
        {
            UtlVoidPtr* elementContainer = dynamic_cast<UtlVoidPtr*>(list.last());
            list.removeReference(elementContainer);
            element = (void*) elementContainer->getValue();
            delete elementContainer;
        }

        return(element);
}
Ejemplo n.º 16
0
void SipUdpServer::shutdownListener()
{
    SipClient* pServer = NULL;
    UtlHashMapIterator iterator(mServers);
    UtlVoidPtr* pServerContainer = NULL;
    UtlString* pKey = NULL;
    
    while (pKey = (UtlString*)iterator())
    {
        pServerContainer = (UtlVoidPtr*) iterator.value();
        pServer = (SipClient*)pServerContainer->getValue();
        if (pServer)
        {
            pServer->requestShutdown();
        }
    }
}
Ejemplo n.º 17
0
void* OsLockingList::remove(int iteratorHandle)
{
        void* element = NULL;

        assertIterator(iteratorHandle);
   if (currentElement)
   {
      UtlVoidPtr* elementContainer = (UtlVoidPtr*)list.removeReference(currentElement);
      if(elementContainer)
      {
         element = (void*) elementContainer->getValue();
         delete elementContainer;
         currentElement=NULL;
      }
        }
        return(element);
}
Ejemplo n.º 18
0
void sipxLineObjectFree(const SIPX_LINE hLine)
{
    // First remove it from the HandleMap so no one else an find it
    SIPX_LINE_DATA* pData =
       (SIPX_LINE_DATA *)gpLineHandleMap->removeHandle(hLine) ;

    if (pData)
    {
        // Then lock it so anyone who was previously using it is known
        // to have released it
        if (pData->pMutex->acquireWrite() == OS_SUCCESS)
        {
            // Now it is safe to delete
            pData->pInst->pLock->acquire() ;
            pData->pInst->nLines-- ;
            assert(pData->pInst->nLines >= 0) ;
            pData->pInst->pLock->release() ;

            if (pData->lineURI)
            {
                delete pData->lineURI ;
            }

            if (pData->pMutex)
            {
                delete pData->pMutex ;
            }

            if (pData->pLineAliases)
            {
                UtlVoidPtr* pValue ;
                while (pValue = (UtlVoidPtr*) pData->pLineAliases->get())
                {
                    Url* pUri = (Url*) pValue->getValue() ;
                    if (pUri)
                    {
                        delete pUri ;
                    }
                    delete pValue ;
                }
            }

            delete pData ;
        }
    }
}
Ejemplo n.º 19
0
UtlBoolean HttpServer::findRequestProcessor(const char* fileUri,
                                            RequestProcessor* &requestProcessor
                                            )
{
    UtlString uriCollectable(fileUri);
    UtlVoidPtr* processorCollectable;

    requestProcessor = NULL;
    processorCollectable =
        (UtlVoidPtr*) mRequestProcessorMethods.findValue(&uriCollectable);
    if(processorCollectable)
    {
        requestProcessor = (RequestProcessor*)processorCollectable->getValue();
    }

    return(requestProcessor != NULL);
}
Ejemplo n.º 20
0
const void* SipXHandleMap::findHandle(SIPXHANDLE handle) 
{
    lock() ;

    const void* pRC = NULL ;
    UtlInt key(handle) ;
    UtlVoidPtr* pValue ;

    pValue = (UtlVoidPtr*) findValue(&key) ;
    if (pValue != NULL)
    {
        pRC = pValue->getValue() ;
    }

    unlock() ;

    return pRC ;
}
Ejemplo n.º 21
0
void SipXHandleMap::dumpCalls()
{
   UtlHashMapIterator itor(*this) ;
   UtlInt* pKey ;
   UtlVoidPtr* pValue ;

   while ((pKey = (UtlInt*) itor()))
   {
      pValue = (UtlVoidPtr*) findValue(pKey) ;
      assert(pValue != NULL);
      SIPX_CALL_DATA* pCallData = (SIPX_CALL_DATA*)pValue->getValue();
      printf("\tkey=%08d, value=0x%p, CallId=%s SessionCallId=%s\n",
         pKey->getValue(), 
         pValue->getValue(),
         pCallData->callId?pCallData->callId->data():"NULL",
         pCallData->sessionCallId?pCallData->sessionCallId->data():"NULL") ;
   }
}
Ejemplo n.º 22
0
SIPX_CALL sipxCallLookupHandle(const UtlString& callID, const void* pSrc)
{
    SIPX_CALL hCall = 0 ;

    if (gpCallHandleMap->lock())
    {
        UtlHashMapIterator iter(*gpCallHandleMap);

        UtlInt* pIndex = NULL;
        UtlVoidPtr* pObj = NULL;

        while ((pIndex = dynamic_cast<UtlInt*>( iter() )) )
        {
            pObj = dynamic_cast<UtlVoidPtr*>(gpCallHandleMap->findValue(pIndex));
            SIPX_CALL_DATA* pData = NULL ;
            if (pObj)
            {
                pData = (SIPX_CALL_DATA*) pObj->getValue() ;
            }

            if (pData &&
                    (pData->callId->compareTo(callID) == 0 ||
                    (pData->sessionCallId && (pData->sessionCallId->compareTo(callID) == 0)) ||
                    (pData->transferCallId && (pData->transferCallId->compareTo(callID) == 0))) &&
                    pData->pInst->pCallManager == pSrc)
            {
                hCall = pIndex->getValue() ;
#ifdef DUMP_CALLS
                OsSysLog::add(FAC_SIPXTAPI, PRI_DEBUG, "***************** LookupHandle ***\nhCall %d\n****callId %s\n***sessionCallId %s\n",
                hCall,
                pData->callId ? pData->callId->data() : NULL,
                pData->sessionCallId ? pData->sessionCallId->data() : NULL);
#endif
                break ;
            }
        }

        gpCallHandleMap->unlock() ;
    }

    return hCall;
}
Ejemplo n.º 23
0
SIPX_INSTANCE_DATA* findSessionByCallManager(const void* pCallManager)
{
    SIPX_INSTANCE_DATA *pInst = NULL ;

    UtlDListIterator iter(*gpSessionList);

    UtlVoidPtr* pObj = NULL;

    while ((pObj = dynamic_cast<UtlVoidPtr*>(iter())))
    {
        SIPX_INSTANCE_DATA* pTest = (SIPX_INSTANCE_DATA*) pObj->getValue() ;
        if ((pTest) && (pTest->pCallManager == pCallManager))
        {
            pInst = pTest ;
            break ;
        }
    }

    return pInst ;
}
Ejemplo n.º 24
0
// Retrieve the value associated with the specified key.
// If pValue is non-NULL, the value is returned via pValue.
// Return OS_SUCCESS if the lookup is successful, return OS_NOT_FOUND if
// there is no match for the specified key.
OsStatus OsNameDb::lookup(const UtlString& rKey,
                          void** pValue)
{
    OsReadLock  lock(mRWLock);
    OsStatus    result = OS_NOT_FOUND;
    UtlVoidPtr* pDictValue;

    pDictValue = (UtlVoidPtr*)
                 mDict.findValue(&rKey); // perform the lookup

    if (pDictValue != NULL)
    {
        if (pValue != NULL)       // if we have a valid pointer,
        {   //  return the corresponding value
            *pValue = pDictValue->getValue();
        }
        result = OS_SUCCESS;
    }

    return result;
}
Ejemplo n.º 25
0
void sipxDumpCalls()
{
    if (gpCallHandleMap->lock())
    {
        UtlHashMapIterator iter(*gpCallHandleMap);

        UtlInt* pIndex = NULL;
        UtlVoidPtr* pObj = NULL;
        SIPX_CALL hCall = 0 ;

        while (pIndex = dynamic_cast<UtlInt*>( iter() ) )
        {
            pObj = dynamic_cast<UtlVoidPtr*>(gpCallHandleMap->findValue(pIndex));
            SIPX_CALL_DATA* pData = NULL ;
            if (pObj)
            {
                pData = (SIPX_CALL_DATA*) pObj->getValue() ;
            }

            if (pData)
            {
                hCall = pIndex->getValue() ;
                OsSysLog::add(FAC_SIPXTAPI, PRI_DEBUG,
                              "***************** CallDump***\n"
                              "hCall %d\n"
                              "****callId %s\n"
                              "****ghostCallId %s\n"
                              "***bRemoveInsteadOfDrop %d\n"
                              "****lineUri %s\n",
                    hCall,
                    pData->callId ? pData->callId->data() : NULL,
                    pData->ghostCallId ? pData->ghostCallId->data() : NULL,
                    pData->bRemoveInsteadOfDrop,
                    pData->lineURI ? pData->lineURI->data() : NULL);

            }
        }
        gpCallHandleMap->unlock() ;
    }
}
Ejemplo n.º 26
0
const void* SipXHandleMap::removeHandle(SIPXHANDLE handle) 
{
    lock() ;

    releaseHandleRef(handle);
    const void* pRC = NULL ;
    UtlInt key(handle) ;
        
    UtlInt* pCount = static_cast<UtlInt*>(mLockCountHash.findValue(&key)) ;
        
    if (pCount == NULL || pCount->getValue() < 1)
    {
        UtlVoidPtr* pValue ;
            
        pValue = (UtlVoidPtr*) findValue(&key) ;
        if (pValue != NULL)
        {
            pRC = pValue->getValue() ;                
            if(! destroy(&key))
            {
                OsSysLog::add(FAC_SIPXTAPI, PRI_ERR,
                        "SipXHandleMap::removeHandle failed to destroy handle: %d",
                        handle);
            }
        }

        if (pCount)
        {
            if(! mLockCountHash.destroy(&key))
            {
                OsSysLog::add(FAC_SIPXTAPI, PRI_ERR,
                        "SipXHandleMap::removeHandle failed to destroy lock count for handle: %d",
                        handle);
            }
        }
    }
    
    unlock() ;
    return pRC ;
}
Ejemplo n.º 27
0
UtlBoolean SipUdpServer::sendTo(const SipMessage& message,
                               const char* address,
                               int port,
                               const char* szLocalSipIp)
{
    UtlBoolean sendOk;
    UtlVoidPtr* pServerContainer = NULL;
    SipClient* pServer = NULL;
    
    if (szLocalSipIp)
    {
        UtlString localKey(szLocalSipIp);
        pServerContainer = (UtlVoidPtr*)this->mServers.findValue(&localKey);
        if (pServerContainer)
        {
            pServer = (SipClient*) pServerContainer->getValue();
        }
    }
    else
    {
        // no local sip IP specified, so, use the default one
        UtlString defaultKey(mDefaultIp);
       
        pServerContainer = (UtlVoidPtr*) mServers.findValue(&defaultKey);
        if (pServerContainer)
        {
            pServer = (SipClient*) pServerContainer->getValue();
        }
    }
    
    if (pServer)
    {
        sendOk = pServer->sendTo(message, address, port);
    }
    else
    {
        sendOk = false;
    }
    return(sendOk);
}
Ejemplo n.º 28
0
    /** Test the setValue() method. 
    *
    *   The test data for this method is
    *      a) For a NULL  pointer set a different type
    *      a) Set the value from one Non-NULL to another Non-NULL
    *      d) set the value from Non-NULL to NULL 
    */
    void testSetValue() 
    {
        const char* prefix ; 
        const char* suffix1 = " : test return value" ; 
        const char* suffix2 = " : test that value has been set" ; 
        string Message ; 

        UtlVoidPtr testVoidObj ; 
        void* returnValue ; 
        void* newValue  ;
        void* oldValue = 0 ; 
 
        newValue = (void*)"Hello world" ; 
        returnValue = testVoidObj.setValue(newValue) ; 
        prefix = "For a VoidPtr object which is not NULL, test setValue(void* value) " \
            "where val is non NULL " ; 
        TestUtilities::createMessage(2, &Message, prefix, suffix1) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), (void*)oldValue, (void*)returnValue) ; 
        TestUtilities::createMessage(2, &Message, prefix, suffix2) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), (void*)newValue, \
            (void*)testVoidObj.getValue()) ; 

        oldValue = testVoidObj.getValue() ; 
        prefix = "Test setValue(void* value) where value is not NULL and the " \
           "existing object is not NULL" ; 
        newValue = (void*)"Hello again world" ; 
        returnValue = (void*)testVoidObj.setValue(newValue) ; 
        TestUtilities::createMessage(2, &Message, prefix, suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), (void*)oldValue, (void*)returnValue) ;  
        TestUtilities::createMessage(2, &Message, prefix, suffix2) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), (void*)newValue, \
            (void*)testVoidObj.getValue()) ; 

        oldValue = testVoidObj.getValue() ; 
        prefix = "Test setValue(void* value) where value = NULL and existing object is not" ; 
        newValue = 0 ; 
        returnValue = (void*)testVoidObj.setValue(newValue) ; 
        TestUtilities::createMessage(2, &Message, prefix, suffix1) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), (void*)oldValue, (void*)returnValue); 
        TestUtilities::createMessage(2, &Message, prefix, suffix1) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), (void*)newValue, \
            (void*)testVoidObj.getValue()) ; 

    } //testSetValue
Ejemplo n.º 29
0
// Remove the indicated key-value pair from the name database.
// If pValue is non-NULL, the value for the key-value pair is returned
// via pValue.
// Return OS_SUCCESS if the lookup is successful, return OS_NOT_FOUND
// if there is no match for the specified key.
OsStatus OsNameDb::remove(const UtlString& rKey,
                          void** pValue)
{
    OsWriteLock          lock(mRWLock);
    OsStatus   result = OS_NOT_FOUND;
    UtlString* pDictKey;
    UtlContainable* pDictValue;

    pDictKey = dynamic_cast<UtlString*>
               (mDict.removeKeyAndValue(&rKey, pDictValue));

    // If a value was found and removed ...
    if (pDictKey != NULL)
    {
        result =  OS_SUCCESS;

        // If the caller provided a pointer through which to return the
        // integer value, do so.
        if (pValue != NULL)
        {
            UtlVoidPtr* voidPtrValue = dynamic_cast<UtlVoidPtr*>(pDictValue);
            if (voidPtrValue)
            {
                *pValue = voidPtrValue->getValue();
            }
            else
            {
                result = OS_NOT_FOUND;
            }
        }

        // Delete the key and value objects.
        delete pDictKey;
        delete pDictValue;
    }

    //  Return success or failure as appropriate.
    return result;
}
Ejemplo n.º 30
0
//! Terminate the non-Terminated contents of mXmlDialogs.
void ResourceInstance::terminateXmlDialogs()
{
   OsSysLog::add(FAC_RLS, PRI_DEBUG,
                 "ResourceInstance::terminateXmlDialogs mInstanceName = '%s'",
                 mInstanceName.data());

   // Iterate through the contents.
   UtlHashMapIterator itor(mXmlDialogs);
   UtlContainable* id;
   while ((id = itor()))
   {
      // The XML document for a single dialog.
      UtlVoidPtr* value = dynamic_cast <UtlVoidPtr*> (itor.value());
      TiXmlElement* dialog_element = static_cast <TiXmlElement*> (value->getValue());
      if (NULL != dialog_element)
      {
         // Get the "state" XML node.
         TiXmlNode* state = dialog_element->FirstChild("state");
         // Destroy the dialog only if the state is not "terminated".
         UtlString stateText;
         textContentShallow(stateText, state); // textContentShallow allows state == NULL.

         // Check if the state is not terminated.
         if (0 != stateText.compareTo("terminated"))
         {
            TiXmlElement newstate = "state";
            TiXmlText newtext = "terminated";

            // Replace the old state element with a new state element indicating terminated.
            // The calling routine will then normally overwrite this with the actual (full) state.
            // Note that tinyxml will delete the old state element for us.
            newstate.InsertEndChild(newtext);
            dialog_element->ReplaceChild(state, newstate);
         }
      }
   }
}