예제 #1
0
int SipUdpServer::getServerPort(const char* szLocalIp) 
{
    int port = PORT_NONE;

    char szLocalIpForPortLookup[256];
    memset((void*)szLocalIpForPortLookup, 0, sizeof(szLocalIpForPortLookup));
    
    if (NULL == szLocalIp)
    {
        strcpy(szLocalIpForPortLookup, mDefaultIp);
    }
    else
    {
        strcpy(szLocalIpForPortLookup, szLocalIp);
    }
    
    UtlString localIpKey(szLocalIpForPortLookup);
    
    UtlInt* pUtlPort;
    pUtlPort = (UtlInt*)this->mServerPortMap.findValue(&localIpKey);
    if (pUtlPort)
    {
       port = pUtlPort->getValue();
    }
    
    return port ;
}
예제 #2
0
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  NAME:        ACDCallManager::removeCallFromMap
//
//  SYNOPSIS:    delete the ACDCall reference from the given HashMap
//
//  DESCRIPTION:
//
//  RETURNS:     None.
//
//  ERRORS:      None.
//
//  CAVEATS:     None.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
void ACDCallManager::removeCallFromMap(ACDCall *pCallRef,
   UtlHashMap *pMap, char *mapName)
{
   mLock.acquire();

   UtlHashMapIterator mapIterator(*pMap);
   ACDCall* pACDCall = NULL;
   UtlInt* pTemp = NULL;
   UtlContainable* pKey;

   while ((pTemp = (UtlInt*)mapIterator()) != NULL) {
      pACDCall = (ACDCall*)pMap->findValue(pTemp);
      if(pACDCall == pCallRef ) {
         OsSysLog::add(FAC_ACD, gACD_DEBUG,
            "ACDCallManager::removeCallFromMap(%s) - removed ACDCall(%p) matching hCall=%" PRIdPTR,
               mapName, pACDCall, pTemp->getValue());
         pKey = pMap->removeReference(pTemp);
         if (pKey != NULL) {
            if (pMap != &mDeadCallHandleMap) {
               // Add it to the "dead" list so we know to ignore messages
               // from it Yet can tell it isn't "unknown".
               addDeadCallToMap(pTemp->getValue(), pCallRef) ;
            }
            delete pKey ;
         }
      }
   }
   mLock.release();
}
예제 #3
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 ;
}
예제 #4
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) ;                        
    }       
}
예제 #5
0
void SipXHandleMap::releaseHandleRef(SIPXHANDLE hHandle)
{
    lock();
    UtlInt* pCount = static_cast<UtlInt*>(mLockCountHash.findValue(&UtlInt(hHandle))) ;
    if (pCount == NULL)
    {
        mLockCountHash.insertKeyAndValue(new UtlInt(hHandle), new UtlInt(0));
    }
    else
    {
        pCount->setValue(pCount->getValue() - 1);
    }
    unlock();
}
예제 #6
0
void SipXHandleMap::addHandleRef(SIPXHANDLE hHandle)
{
    mLock.acquire();

    mLockCountHash.findValue(&UtlInt(hHandle));
    UtlInt* count = static_cast<UtlInt*>(mLockCountHash.findValue(&UtlInt(hHandle))) ;
    if (count == NULL)
    {
        mLockCountHash.insertKeyAndValue(new UtlInt(hHandle), new UtlInt(1));
    }
    else
    {
        count->setValue(count->getValue() + 1);
    }
    mLock.release();
}
예제 #7
0
/**
 * Cancel a suspended redirection.
 *
 * Caller must hold mRedirectorMutex.
 *
 * containableSeqNo - UtlInt containing the sequence number.
 *
 * suspendObject - pointer to the suspense object.
 */
void SipRedirectServer::cancelRedirect(UtlInt& containableSeqNo,
                                       RedirectSuspend* suspendObject)
{
   RedirectPlugin::RequestSeqNo seqNo = containableSeqNo.getValue();

   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                 "SipRedirectServer::cancelRedirect "
                 "Canceling suspense of request %d", seqNo);
   // Call cancel for redirectors that need it.
   PluginIterator iterator(mRedirectPlugins);
   RedirectPlugin* redirector;
   int i;                       // Iterator sequence number.
   for (i = 0; (redirector = static_cast <RedirectPlugin*> (iterator.next()));
        i++)
   {
      if (mpConfiguredRedirectors[i].bActive &&
          suspendObject->mRedirectors[i].needsCancel)
      {
         Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                       "SipRedirectServer::cancelRedirect "
                       "Calling cancel(%d) for redirector %d", seqNo, i);
         redirector->cancel(seqNo);
      }
   }
   // Remove the entry from mSuspendList.
   // Also deletes the suspend object.
   // Deleting the suspend object frees the array of information about
   // the redirectors, and the private storage for each redirector.
   // (See RedirectSuspend::~RedirectSuspend().)
   mSuspendList.destroy(&containableSeqNo);
}
예제 #8
0
TaoStatus TaoObjectMap::findValue(const char* key, TaoObjHandle& objValue)
{
    UtlString* pLookupKey;
    UtlInt*    pDictValue;

    pLookupKey = new UtlString(key);
    pDictValue = (UtlInt*)
                mDict.findValue(pLookupKey); // perform the lookup
    delete pLookupKey;

    if (pDictValue == NULL)
      return TAO_NOT_FOUND;   // did not find the specified key

    objValue = pDictValue->getValue();

    return TAO_SUCCESS;
}
예제 #9
0
void requestDelete(Url& url, UtlSList& names)
{
    XmlRpcRequest* request;
    XmlRpcResponse response;
    
    request = new XmlRpcRequest(url, "configurationParameter.delete");
    request->addParam(&DataSet); 
        
    if (!names.isEmpty())
    {
        request->addParam(&names);
    }
      
    if (!request->execute(response/*, &pSocket*/))
    {
        exitFault(response);
    }
    else
    {
        UtlContainable* value;
        if (response.getResponse(value))
        {
            UtlInt* deletedCount = dynamic_cast<UtlInt*>(value);
            if (deletedCount)
            {
                if (Verbose == Feedback)
                {
                   printf("deleted %d parameters.\n", (int)deletedCount->getValue());
                }
            }
            else
            {
                fprintf(stderr, "Incorrect type returned.\n");
                exit(1);
            }
        }
        else
        {
            fprintf(stderr, "No value returned.\n");
            exit(1);
        }
    }    
    delete request;
    request = NULL;
}
예제 #10
0
UtlBoolean TaoObjectMap::findValue(TaoObjHandle value)
{
    UtlHashMapIterator iter(mDict);
    UtlContainable*    next;
    UtlInt* cvalue;

    iter.reset();
    while ((next = iter()))
    {
        cvalue = (UtlInt*) iter.value();
        if (value == (TaoObjHandle) cvalue->getValue())
        {
            return TRUE;
        }
    }

    return FALSE;
}
예제 #11
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") ;
   }
}
예제 #12
0
    /** Test the constructor
    *
    *    The test data for this test case is :-
    *     a) int = 0
    *     b) int = +ve integer
    *     c) int = -ve integer
    *     d) int = max +ve integer
    *     e) int = max -ve integer.
    *     The above set of data will be referred to as the
    *     Common Data Set henceforth! The common data set has been defined
    *     as a static const array of integers and a short description about
    *     the data is in a const array of char*
    *
    */
    void testConstructor()
    {
        // First test the default constructor
        UtlInt testInt ;
        const char* msg0 = "Test the default constructor" ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg0, (intptr_t)0, testInt.getValue()) ;

        //Now test the single argument constructor for each of
        // the common test data type
        const char* prefix = "Test UtlInt(int value), where value = " ;
        for (int i = 0  ;i < commonTestSetLength; i++)
        {
            string msg ;
            TestUtilities::createMessage(2, &msg, prefix, commonTestSet[i].message) ;
            UtlInt testInt(commonTestSet[i].input) ;
            int actualValue = testInt.getValue() ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), commonTestSet[i].expectedValue, actualValue) ;
        }
    }
예제 #13
0
bool SipXHandleMap::releaseHandleRef(SIPXHANDLE hHandle)
{
    bool bRC = false ;

    if (lock())
    {
        UtlInt* pCount = static_cast<UtlInt*>(mLockCountHash.findValue(&UtlInt(hHandle))) ;
        if (pCount == NULL)
        {
            mLockCountHash.insertKeyAndValue(new UtlInt(hHandle), new UtlInt(0));
        }
        else
        {
            pCount->setValue(pCount->getValue() - 1);
        }
        bRC = unlock();
    }
    return bRC ;
}
예제 #14
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;
}
예제 #15
0
// Get an array of pointers to the TaoObjHandles that are currently active.
// The caller provides an array that can hold up to "size" TaoObjHandle
// pointers. This method will fill in the "active Objects" array with
// up to "size" TaoObjHandle. The method returns the number of TaoObjHandle
// in the array that were actually filled in.
int TaoObjectMap::getActiveObjects(TaoObjHandle activeObjects[], int size)
{
   UtlHashMapIterator iter(mDict);
   UtlContainable*    next;
   UtlInt* value;
   int      i;

   iter.reset();
   i = 0;
   while ((next = iter()))
   {
      if (i >= size) break;

      value = (UtlInt*) iter.value();
      activeObjects[i] = (TaoObjHandle) value->getValue();
      i++;
   }

   return i;
}
예제 #16
0
// Get an array of pointers to the Rscs that are currently active.
// The caller provides an array that can hold up to "size" OsRsc
// pointers. This method will fill in the "activeRscs" array with
// up to "size" pointers. The method returns the number of pointers
// in the array that were actually filled in.
int UtlRscStore::getActiveRscs(char* activeRscs[], int size)
{
   UtlHashMapIterator iter(mDict);
   UtlContainable*    next;
   UtlInt* value;
   int      i;

   iter.reset();
   i = 0;
   while (next = iter())
   {
      if (i >= size) break;

      value = (UtlInt*) iter.value();
      activeRscs[i] = (char*) value->value();
      i++;
   }

   return i;
}
예제 #17
0
void requestSet(Url& url, UtlHashMap& parameters)
{
    XmlRpcRequest* request;
    XmlRpcResponse response;
    
    request = new XmlRpcRequest(url, "configurationParameter.set");
    request->addParam(&DataSet); 
    request->addParam(&parameters);
     
    if (request->execute(response /*, &pSocket*/))
    {
        UtlContainable* value;
        if (response.getResponse(value))
        {
            UtlInt* numberSet = dynamic_cast<UtlInt*>(value);
            if (numberSet)
            {
                if (Verbose == Feedback)
                {
                    printf("set %d name/value pairs.\n", (int)numberSet->getValue());
                }
            }
            else
            {
                fprintf(stderr, "Incorrect type returned.\n");
                exit(1);
            }
        }
        else
        {
            fprintf(stderr, "No value returned.\n");
            exit(1);
         }
    }
    else
    {
        exitFault(response);
    }
    delete request;
    request = NULL;
}
예제 #18
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 ;
}
예제 #19
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() ;
    }
}
예제 #20
0
int MpTopologyGraph::removeVirtualOutputs(MpResourceTopology& resourceTopology,
                                          UtlBoolean replaceNumInName,
                                          int resourceNum)
{
   int portsDestroyed = 0;
   MpResourceTopology::VirtualPortIterator portIter;
   UtlString realResourceName;
   int realPortIdx;
   UtlString virtualResourceName;
   int virtualPortIdx;
   UtlInt keyPortIdx;
   UtlContainablePair keyPair(&virtualResourceName, &keyPortIdx);

   resourceTopology.initVirtualOutputIterator(portIter);
   while (resourceTopology.getNextVirtualOutput(portIter,
                                               realResourceName, realPortIdx,
                                               virtualResourceName, virtualPortIdx)
          == OS_SUCCESS)
   {
      if(replaceNumInName)
      {
         MpResourceTopology::replaceNumInName(virtualResourceName, resourceNum);
      }

      // Destroy entry in the virtual ports map.
      keyPortIdx.setValue(virtualPortIdx);
      if (mVirtualOutputs.destroy(&keyPair))
      {
         portsDestroyed++;
      }
   }
   resourceTopology.freeVirtualOutputIterator(portIter);

   // Prevent deletion of stack objects.
   keyPair.setFirst(NULL);
   keyPair.setSecond(NULL);

   return portsDestroyed;
}
예제 #21
0
TaoStatus TaoObjectMap::removeByValue(TaoObjHandle value)
{
    UtlHashMapIterator iter(mDict);
    UtlContainable*    next;
    UtlInt* cvalue;
    TaoStatus status = TAO_NOT_FOUND;

    while ((next = iter()))
    {
        cvalue = (UtlInt*) iter.value();
        if (value == (TaoObjHandle) cvalue->getValue())
        {
            mDict.destroy(next);
            status = TAO_SUCCESS;
            mNumRemoves++;
//          osPrintf("<** %d removeByValue: cvalue 0x%08x, next 0x%08x **>\n", (int)value, (int)cvalue, (int)next);
            break;
        }
    }

    return status;
}
예제 #22
0
bool SipXHandleMap::addHandleRef(SIPXHANDLE hHandle)
{
    bool bRC = false ;

    if (lock())
    {
        mLockCountHash.findValue(&UtlInt(hHandle));
        UtlInt* count = static_cast<UtlInt*>(mLockCountHash.findValue(&UtlInt(hHandle))) ;
        if (count == NULL)
        {
            mLockCountHash.insertKeyAndValue(new UtlInt(hHandle), new UtlInt(1));
        }
        else
        {
            count->setValue(count->getValue() + 1);
        }
    
        bRC = unlock() ;
    }

    return bRC ;
}
예제 #23
0
// Dump the object's internal state.
void PublishContentContainer::dumpState()
{
    // indented 8 and 10

    OsSysLog::add(FAC_RLS, PRI_INFO,
                  "\t        PublishContentContainer %p UtlString = '%s'",
                  this, data());

    int index = 0;
    UtlSListIterator content_itor(mEventContent);
    UtlSListIterator version_itor(mEventVersion);
    HttpBody* body;
    while ((body = dynamic_cast <HttpBody*> (content_itor())))
    {
        UtlInt* version = dynamic_cast <UtlInt*> (version_itor());
        OsSysLog::add(FAC_RLS, PRI_INFO,
                      "\t          mEventVersion[%d] = %" PRIdPTR ", "
                      "mEventContent[%d] = '%s':'%s'",
                      index, version->getValue(),
                      index, body->data(), body->getBytes());
        index++;
    }
}
예제 #24
0
ACDCall* ACDCallManager::getAcdCallByCallId(UtlString callId) {
   UtlHashMapIterator mapIterator(mCallHandleMap);
   ACDCall* pACDCall = NULL;
   UtlInt* pTemp = NULL;

   while ((pTemp = (UtlInt*)mapIterator()) != NULL) {
      OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::getAcdCallByCallId - looking at call handle=%d",pTemp->getValue());
      pACDCall = (ACDCall*)mCallHandleMap.findValue(pTemp);

      if(pACDCall && pACDCall->getCallId() == callId ) {
         OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::getAcdCallByCallId - found ACDCall matching callid=%s",callId.data());
         return pACDCall;
      }
   }

   OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::getAcdCallByCallId - could not find ACDCall matching callid=%s",callId.data());
   return NULL;
}
예제 #25
0
int MpTopologyGraph::linkTopologyResources(MpResourceTopology& resourceTopology,
                                           UtlHashBag& newResources,
                                           UtlBoolean replaceNumInName,
                                           int resourceNum)
{
    // Link the resources
    int connectionIndex = 0;
    UtlString outputResourceName;
    UtlString inputResourceName;
    int outputResourcePortIndex;
    int inputResourcePortIndex;
    MpResource* outputResource = NULL;
    MpResource* inputResource = NULL;
    OsStatus result;
    UtlHashMap newConnectionIds;

#ifdef TEST_PRINT
    osPrintf("%d new resources in the list\n", newResources.entries());
    UtlHashBagIterator iterator(newResources);
    MpResource* containerResource = NULL;
    while(containerResource = (MpResource*) iterator())
    {
        osPrintf("found list resource: \"%s\" value: \"%s\"\n",
                 containerResource->getName().data(), containerResource->data());
    }
#endif

    while(resourceTopology.getConnection(connectionIndex,
                                         outputResourceName,
                                         outputResourcePortIndex,
                                         inputResourceName,
                                         inputResourcePortIndex) == OS_SUCCESS)
    {
        if(replaceNumInName)
        {
            resourceTopology.replaceNumInName(outputResourceName, resourceNum);
            resourceTopology.replaceNumInName(inputResourceName, resourceNum);
        }

        // Look in the container of new resources first as this is more 
        // efficient and new resources are not added immediately to a running
        // flowgraph
        outputResource = (MpResource*) newResources.find(&outputResourceName);
        if(outputResource == NULL)
        {
            result = lookupResource(outputResourceName, outputResource);
            if(result != OS_SUCCESS)
            {
                int virtPortIdx = outputResourcePortIndex>=0?outputResourcePortIndex:-1;
                int realPortIdx;
                result = lookupVirtualOutput(outputResourceName, virtPortIdx,
                                             outputResource, realPortIdx);
                if (result == OS_SUCCESS && outputResourcePortIndex>=0)
                {
                   outputResourcePortIndex = realPortIdx;
                }
            }
            assert(result == OS_SUCCESS);
        }
        inputResource = (MpResource*) newResources.find(&inputResourceName);
        if(inputResource == NULL)
        {
            result = lookupResource(inputResourceName, inputResource);
            if(result != OS_SUCCESS)
            {
                int virtPortIdx = inputResourcePortIndex>=0?inputResourcePortIndex:-1;
                int realPortIdx;
                result = lookupVirtualInput(inputResourceName, virtPortIdx,
                                            inputResource, realPortIdx);
                if (result == OS_SUCCESS && inputResourcePortIndex>=0)
                {
                   inputResourcePortIndex = realPortIdx;
                }
            }
            assert(result == OS_SUCCESS);
        }
        assert(outputResource);
        assert(inputResource);

        if(outputResource && inputResource)
        {
            if(outputResourcePortIndex == MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT)
            {
                outputResourcePortIndex = outputResource->reserveFirstUnconnectedOutput();
                assert(outputResourcePortIndex >= 0);
            }
            else if(outputResourcePortIndex < MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT)
            {
                // First see if a real port is already in the dictionary
                UtlInt searchKey(outputResourcePortIndex);
                UtlInt* foundValue = NULL;
                if((foundValue = (UtlInt*) newConnectionIds.findValue(&searchKey)))
                {
                    // Use the mapped index
                    outputResourcePortIndex = foundValue->getValue();
                }
                else
                {
                    // Find an available port and add it to the map
                    int realPortNum = outputResource->reserveFirstUnconnectedOutput();
                    assert(realPortNum >= 0);
                    UtlInt* portKey = new UtlInt(outputResourcePortIndex);
                    UtlInt* portValue = new UtlInt(realPortNum);
                    newConnectionIds.insertKeyAndValue(portKey, portValue);
                    outputResourcePortIndex = realPortNum;
                }
            }

            if(inputResourcePortIndex == MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT)
            {
                inputResourcePortIndex = inputResource->reserveFirstUnconnectedInput();
                assert(inputResourcePortIndex >= 0);
            }
            else if(inputResourcePortIndex < MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT)
            {
                // First see if a real port is already in the dictionary
                UtlInt searchKey(inputResourcePortIndex);
                UtlInt* foundValue = NULL;
                if((foundValue = (UtlInt*) newConnectionIds.findValue(&searchKey)))
                {
                    // Use the mapped index
                    inputResourcePortIndex = foundValue->getValue();
                }
                else
                {
                    // Find an available port and add it to the map
                    int realPortNum = inputResource->reserveFirstUnconnectedInput();
                    assert(realPortNum >= 0);
                    UtlInt* portKey = new UtlInt(inputResourcePortIndex);
                    UtlInt* portValue = new UtlInt(realPortNum);
                    newConnectionIds.insertKeyAndValue(portKey, portValue);
                    inputResourcePortIndex = realPortNum;
                }
            }


            result = addLink(*outputResource, outputResourcePortIndex, *inputResource, inputResourcePortIndex);
            assert(result == OS_SUCCESS);
        }
        connectionIndex++;
    }

    newConnectionIds.destroyAll();
    return(connectionIndex);
}
예제 #26
0
SIPX_LINE sipxLineLookupHandleByURI(SIPX_INSTANCE_DATA* pInst,
                                    const char* szURI)
{
    SIPX_LINE hLine = 0 ;
    Url urlLine(szURI) ;

    // Use the line manager to find identity if available
    if (pInst && pInst->pLineManager)
    {
        SipLine* pLine = pInst->pLineManager->findLineByURL(urlLine, "unknown") ;
        if (pLine)
            urlLine = pLine->getIdentity() ;
    }

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

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

        while (pIndex = dynamic_cast<UtlInt*>( iter() ) )
        {
            pObj = dynamic_cast<UtlVoidPtr*>(gpLineHandleMap->findValue(pIndex));
            SIPX_LINE_DATA* pData = NULL ;
            if (pObj)
            {
                pData = (SIPX_LINE_DATA*) pObj->getValue() ;
                if (pData)
                {
                    // Check main line definition
                    if (urlLine.isUserHostPortEqual(*pData->lineURI))
                    {
                        hLine = pIndex->getValue() ;
                        break ;
                    }

                    // Check for line aliases
                    if (pData->pLineAliases)
                    {
                        UtlVoidPtr* pValue ;
                        Url* pUrl ;
                        UtlSListIterator iterator(*pData->pLineAliases) ;

                        while (pValue = (UtlVoidPtr*) iterator())
                        {
                            pUrl = (Url*) pValue->getValue() ;

                            if (urlLine.isUserHostPortEqual(*pUrl))
                            {
                                hLine = pIndex->getValue() ;
                                break ;
                            }
                        }
                    }
                }
            }
        }

        gpLineHandleMap->unlock() ;
    }

    return hLine;
}
예제 #27
0
bool FileRpcReplaceFile::execute(const HttpRequestContext& requestContext,
                                 UtlSList&                 params,
                                 void*                     userData,
                                 XmlRpcResponse&           response,
                                 ExecutionStatus&          status)
{

   const int  minPermissions = 0100;
   const int  maxPermissions = 0777;

   bool result = false;
   status = XmlRpcMethod::FAILED;

   if (4 != params.entries())
   {
      handleExtraExecuteParam(name(), response, status);
   }
   else
   {
      if (!params.at(0) || !params.at(0)->isInstanceOf(UtlString::TYPE))
      {
         handleMissingExecuteParam(name(), PARAM_NAME_CALLING_HOST, response, status);
      }
      else
      {
         UtlString* pCallingHostname = dynamic_cast<UtlString*>(params.at(0));

         if (!params.at(1) || !params.at(1)->isInstanceOf(UtlString::TYPE))
         {
            handleMissingExecuteParam(name(), PARAM_NAME_FILE_NAME, response, status);
         }
         else
         {
            UtlString* pfileName = dynamic_cast<UtlString*>(params.at(1));

            if (!params.at(2) || !params.at(2)->isInstanceOf(UtlInt::TYPE))
            {
               handleMissingExecuteParam(name(), PARAM_NAME_FILE_PERMISSIONS, response, status);
            }
            else
            {
               UtlInt* pfilePermissions = dynamic_cast<UtlInt*>(params.at(2));
           
               if (!params.at(3) || !params.at(3)->isInstanceOf(UtlString::TYPE))
               {
                  handleMissingExecuteParam(name(), PARAM_NAME_FILE_DATA, response, status);
               }
               else
               {
                  UtlBool method_result(true);
                  SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData);

                  if(validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name()))
                  {
                     // Check the resource permissions.  To be added when available.
                     FileResource* fileResource =
                        FileResourceManager::getInstance()->find(pfileName->data());
                     if (!fileResource)
                     {
                        UtlString faultMsg;
                        faultMsg.append("File '");
                        faultMsg.append(*pfileName);
                        faultMsg.append("' not declared as a resource by any sipXecs process");
                        OsSysLog::add(FAC_SUPERVISOR, PRI_ERR, "FileRpc::replaceFile %s",
                                      faultMsg.data());
                        result=false;
                        response.setFault(FileRpcMethod::InvalidParameter, faultMsg);
                     }
                     else if (!fileResource->isWriteable())
                     {
                        UtlString faultMsg;
                        faultMsg.append("File '");
                        faultMsg.append(*pfileName);
                        faultMsg.append("' is not writeable (configAccess='read-only')");
                        OsSysLog::add(FAC_SUPERVISOR, PRI_ERR, "FileRpc::replaceFile %s",
                                      faultMsg.data());
                        result=false;
                        response.setFault(FileRpcMethod::InvalidParameter, faultMsg);
                     }
                     else if (   ( pfilePermissions->getValue() <= minPermissions )
                              || ( pfilePermissions->getValue() > maxPermissions ))
                     {
                        UtlString faultMsg;
                        faultMsg.appendNumber(pfilePermissions->getValue(),"File permissions %04o");
                        faultMsg.appendNumber(minPermissions,"not within valid range (%04o - ");
                        faultMsg.appendNumber(maxPermissions,"%04o)");
                        OsSysLog::add(FAC_SUPERVISOR, PRI_ERR, "FileRpc::replaceFile %s",
                                      faultMsg.data());
                        result = false;
                        response.setFault(FileRpcMethod::InvalidParameter, faultMsg);
                     }
                     else
                     {
                        // Write out the file.
                        UtlString* pfileData = dynamic_cast<UtlString*>(params.at(3));
                        UtlString faultMsg;
                        if((result=replicateFile(*pfileName,*pfilePermissions,*pfileData,faultMsg )))
                        {
                           // Construct and set the response.
                           response.setResponse(&method_result);
                           status = XmlRpcMethod::OK;

                           // Tell anyone who cares that this changed
                           fileResource->modified();
                        }
                        else
                        {
                           // Replication failed.
                           response.setFault(FileRpcMethod::InvalidParameter, faultMsg);
                        }
                     }
                  }
               }
            }
         }
      }
   }

   return result;
}
예제 #28
0
UtlBoolean SipPublishContentMgr::getContent(const char* resourceId,
        const char* eventTypeKey,
        const char* eventType,
        const char* acceptHeaderValue,
        HttpBody*& content,
        int& version,
        UtlBoolean& isDefaultContent,
        UtlBoolean fullState)
{
    UtlBoolean foundContent = FALSE;
    UtlString key(resourceId);

    key.append(eventTypeKey);
    PublishContentContainer* container = NULL;
    isDefaultContent = FALSE;

    // Turn acceptHeaderValue into a HashBag of its components.
    // acceptedTypesGiven = FALSE if there are no components.
    UtlHashBag contentTypes;
    UtlBoolean acceptedTypesGiven =
        buildContentTypesContainer(acceptHeaderValue, contentTypes);

    lock();

    UtlHashBag* pContent;
    if (fullState)
    {
        // Full content (this is the usual case)
        pContent = &mContentEntries;
    }
    else
    {
        // Partial content (used for partial dialog events)
        pContent = &mPartialContentEntries;
    }

    // See if resource-specific content exists
    container =
        dynamic_cast <PublishContentContainer*> (pContent->find(&key));

    // There is no resource-specific content.  Check if the default
    // constructor exists.
    if (container == NULL)
    {
        // Construct the key for the default data.
        UtlString default_key(eventTypeKey);

        // Look up the constructor.

        SipPublishContentMgrDefaultConstructor* constructor =
            dynamic_cast <SipPublishContentMgrDefaultConstructor*>
            (mDefaultContentConstructors.findValue(&default_key));
        // If it exists, call it to publish content for this resource/event.
        if (constructor)
        {
            constructor->generateDefaultContent(this, resourceId,
                                                eventTypeKey, eventType);
        }

        // See if resource specific content exists now.
        container =
            dynamic_cast <PublishContentContainer*> (pContent->find(&key));

        // If content was found, still mark it as default content.
        if (container)
        {
            isDefaultContent = TRUE;
        }
        // If still no content was found, check if the default exists.
        else
        {
            container =
                dynamic_cast <PublishContentContainer*>
                (mDefaultContentEntries.find(&default_key));
            if(container)
            {
                isDefaultContent = TRUE;
            }
        }
    }

    // Within the container, find the content of the right MIME type.
    if (container)
    {
        if (acceptedTypesGiven)
        {
            UtlString base_mime_type;

            // Search for the first content in the container whose
            // MIME type is in the acceptable list.
            UtlSListIterator contentIterator(container->mEventContent);
            HttpBody* bodyPtr;
            UtlSListIterator versionIterator(container->mEventVersion);
            UtlInt* versionPtr;
            while (!foundContent &&
                    (bodyPtr = dynamic_cast <HttpBody*> (contentIterator())) &&
                    (versionPtr = dynamic_cast <UtlInt*> (versionIterator())))
            {
                // Test if ';' is present in *bodyPtr's MIME type.
                // (Remember that an HttpBody considered as a UtlString has
                // the value of its content type.)
                ssize_t i = bodyPtr->index(';');

                // The 'if expression' is TRUE if the MIME type of *bodyPtr
                // is found in in contentTypes.  This is messy, because
                // *bodyPtr's MIME type may have parameters, which have
                // to be removed before searching contentTypes.
                if (contentTypes.find(i == UTL_NOT_FOUND ?
                                      bodyPtr :
                                      ( base_mime_type.remove(0),
                                        base_mime_type.append(*bodyPtr, 0, i),
                                        &base_mime_type)))
                {
                    content = bodyPtr->copy();
                    version = versionPtr->getValue();
                    foundContent = TRUE;
                }
            }
            if (!foundContent)
            {
                // No content was found that matched the required MIME types.
                OsSysLog::add(FAC_SIP, PRI_WARNING,
                              "SipPublishContentMgr::getContent no content found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s'",
                              key.data(),
                              acceptHeaderValue ? acceptHeaderValue : "[none]",
                              resourceId ? resourceId : "[none]",
                              eventTypeKey, eventType);
            }
        }
        else
        {
            // No MIME types were specified, take the first content in the list.
            HttpBody* bodyPtr =
                dynamic_cast <HttpBody*> (container->mEventContent.first());
            UtlInt* versionPtr =
                dynamic_cast <UtlInt*> (container->mEventVersion.first());
            if (bodyPtr)
            {
                content = bodyPtr->copy();
                version = versionPtr->getValue();
                foundContent = TRUE;
            }
            else
            {
                // No content was found (at all).
                OsSysLog::add(FAC_SIP, PRI_WARNING,
                              "SipPublishContentMgr::getContent no content found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s'",
                              key.data(),
                              acceptHeaderValue ? acceptHeaderValue : "[none]",
                              resourceId ? resourceId : "[none]",
                              eventTypeKey, eventType);
            }
        }
    }
    else
    {
        // No container found for this resource and event.
        OsSysLog::add(FAC_SIP, PRI_WARNING,
                      "SipPublishContentMgr::getContent no container found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s', fullState = %d",
                      key.data(),
                      acceptHeaderValue ? acceptHeaderValue : "[none]",
                      resourceId ? resourceId : "[none]",
                      eventTypeKey, eventType,
                      fullState);
    }

    unlock();

    contentTypes.destroyAll();
    return (foundContent);
}
예제 #29
0
bool FileRpcReplaceFile::replicateFile(UtlString& path_and_name,
                                       UtlInt&    file_permissions,
                                       UtlString& file_content,
                                       UtlString& errorMsg
                                       )
{
   OsStatus rc;
   bool     result = false;
   errorMsg.remove(0);

   UtlString temporaryLocation(path_and_name);
   temporaryLocation += ".new";
   OsFile temporaryFile(temporaryLocation);

   // create a new file with the specified path and file name except with a .new extension.
   if (temporaryFile.open(OsFile::CREATE) == OS_SUCCESS)
   {
      UtlString     pdecodedData;
      size_t bytesRead;

      if ( !NetBase64Codec::decode( file_content, pdecodedData ))
      {
         // Write failed.
         errorMsg.append("Failed to decode file data from base64 for '");
         errorMsg.append(path_and_name);
         errorMsg.append("'");
         OsSysLog::add(FAC_SUPERVISOR, PRI_INFO, "FileRpcReplaceFile::replicateFile %s",
                       errorMsg.data());
      }
      else
      {
         rc = temporaryFile.write(pdecodedData.data(), pdecodedData.length(), bytesRead);
         temporaryFile.close();
         if (rc == OS_SUCCESS)
         {
            rc = temporaryFile.rename(path_and_name);
            if (rc == OS_SUCCESS)
            {
               int int_rc;
               OsSysLog::add(FAC_SUPERVISOR, PRI_INFO, "FileRpcReplaceFile::replicateFile"
                                   " updated file '%s'", path_and_name.data());
               rc = temporaryFile.remove(TRUE);

               // Change the permissions on the file as indicated.
               int_rc = chmod( path_and_name.data(), file_permissions.getValue() ); 
               result = true;
            }
            else
            {
               // Write succeeded, but rename failed.
               errorMsg.append("Failed to rename temporary file from '");
               errorMsg.append(temporaryLocation);
               errorMsg.append("' to '");
               errorMsg.append(path_and_name);
               errorMsg.append("'");
               OsSysLog::add(FAC_SUPERVISOR, PRI_INFO, "FileRpcReplaceFile::replicateFile %s",
                             errorMsg.data());
            }
         }
         else
         {
            // Write failed.
            errorMsg.append("Failed to write to temporary file '");
            errorMsg.append(temporaryLocation);
            errorMsg.append("'");
            OsSysLog::add(FAC_SUPERVISOR, PRI_INFO, "FileRpcReplaceFile::replicateFile %s",
                          errorMsg.data());
         }
      }
   }
   else
   {
      // Open failed.
      errorMsg.append("Failed to create temporary file '");
      errorMsg.append(temporaryLocation);
      errorMsg.append("'");
      OsSysLog::add(FAC_SUPERVISOR, PRI_INFO, "FileRpcReplaceFile::replicateFile %s",
                    errorMsg.data());
   }

   return result;
}