void MpRtpInputAudioConnection::handleStartReceiveRtp(UtlSList& codecList, OsSocket& rRtpSocket, OsSocket& rRtcpSocket) { m_bAudioReceived = FALSE; m_inactiveFrameCount = 0; if (codecList.entries() > 0) { // if RFC2833 DTMF is disabled if (!m_bRFC2833DTMFEnabled) { UtlSListIterator itor(codecList); SdpCodec* pCodec = NULL; // go through all codecs, if you find telephone event, remove it while (itor()) { pCodec = dynamic_cast<SdpCodec*>(itor.item()); if (pCodec && pCodec->getCodecType() == SdpCodec::SDP_CODEC_TONES) { codecList.destroy(pCodec); } } } // continue only if numCodecs is still greater than 0 if (codecList.entries() > 0) { // initialize jitter buffers for all codecs mpDejitter->initJitterBuffers(codecList); mpDecode->selectCodecs(codecList); } } // No need to synchronize as the decoder is not part of the // flowgraph. It is part of this connection/resource //mpFlowGraph->synchronize(); prepareStartReceiveRtp(rRtpSocket, rRtcpSocket); // No need to synchronize as the decoder is not part of the // flowgraph. It is part of this connection/resource //mpFlowGraph->synchronize(); if (codecList.entries() > 0) { mpDecode->enable(); if (mpDtmfDetector) { mpDtmfDetector->enable(); } } sendConnectionNotification(MP_NOTIFICATION_START_RTP_RECEIVE, 0); }
/*!a Test case for the get() method. * * The test data for this test is :- * 1) The first entry is a CollectableString * 2) The first entry is a CollectableInt * 3) The List has only one entry * 4) The List has no entries */ void testGet() { const int testCount = 4 ; const char* prefix = "Verify the get() method for a list when " ; const char* Msgs[] = { \ "the first entry is a CollectableString", \ "the first entry is a CollectableInt", \ "when the list has only one entry", \ "when the list is empty" \ } ; const char* suffix1 = ":- verify return value" ; const char* suffix2 = ":- verify the number of entries in the list" ; UtlSList testList ; testList.append(&commonString1) ; testList.append(&commonInt1) ; testList.append(&commonString2) ; UtlContainable* expectedValue[] = { \ &commonString1 , &commonInt1, &commonString2, NULL \ } ; int entryCount[] = { 2, 1, 0, 0 } ; for (int i = 0 ; i < testCount ; i++) { UtlContainable* actual = testList.get() ; string msg ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], actual) ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entryCount[i], (int)testList.entries()) ; } } //testGet()
// Stores a list of strings to the configuration datadase using the // designated prefix as the base for the list items. void OsConfigDb::addList(const UtlString& rPrefix, UtlSList& rList) { OsWriteLock lock(mRWMutex); size_t iNumEntries ; UtlString key ; UtlString* pValue ; // First remove all items start with the specified prefix removeByPrefix(rPrefix) ; // Next add all of the new items iNumEntries = rList.entries() ; if (iNumEntries > 0) { key = rPrefix ; key.append(".COUNT") ; set(key, iNumEntries) ; UtlSListIterator itor(rList) ; int iCount = 1 ; char cTemp[64] ; while ((pValue = (UtlString*) itor())) { sprintf(cTemp, "%d", iCount++); key = rPrefix ; key.append(".") ; key.append(cTemp) ; set(key, *pValue) ; } } }
/*!a Test case to test the destroyAll() * method. */ void testClearAndDestroy() { const char* prefix = "test the destroyAll() method " ; const char* suffix1 = ":- Verify that all entries are removed" ; const char* suffix2 = ":- The objects are deleted" ; UtlContainableTestStub* uStub ; UtlContainableTestStub* uStubPtr ; uStub = new UtlContainableTestStub(0) ; uStubPtr = new UtlContainableTestStub(1) ; emptyList.append(uStub) ; emptyList.append(uStubPtr) ; emptyList.destroyAll() ; int cCountAfter = UtlContainableTestStub::getCount() ; string msg ; TestUtilities::createMessage(2, &msg, prefix, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ; // Since the TestStub has been implemented such that destructor // decrements the static counter, to verify that the objects have // been deleted, verify that the static counter has been decremented. TestUtilities::createMessage(2, &msg, prefix, suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ; } //testClearAndDestroy
void runCommand() { FileTestContext testContext(TEST_DATA_DIR "commandDef", TEST_WORK_DIR "commandDef"); // copy test files into testContext structure testContext.inputFile("goodcommand.xml"); testContext.inputFile("goodcommand.sh"); UtlString exePath; testContext.workingFilePath("goodcommand.sh", exePath); chmod(exePath.data(), S_IREAD | S_IWRITE | S_IEXEC); testContext.setSipxDir(SipXecsService::VarDirType, "var"); testContext.setSipxDir(SipXecsService::LogDirType); UtlString path; SipxCommand* command1; testContext.inputFilePath("goodcommand.xml", path); CPPUNIT_ASSERT((command1 = SipxCommand::createFromDefinition(path))); ASSERT_STR_EQUAL("Good", command1->data()); UtlSList msgs; command1->getCommandMessages(msgs); CPPUNIT_ASSERT(0 == msgs.entries()); command1->execute(); OsTask::delay(500); // give task some time to get up and running CPPUNIT_ASSERT(true == command1->isRunning()); OsTask::delay(1000); // give task some time to finish CPPUNIT_ASSERT(false == command1->isRunning()); command1->getCommandMessages(msgs); CPPUNIT_ASSERT(3 == msgs.entries()); ASSERT_STR_EQUAL("stdout.msg-1: goodprocess.sh" , ((UtlString*)msgs.at(0))->data()); ASSERT_STR_EQUAL("return.code: 11" , ((UtlString*)msgs.at(2))->data()); msgs.destroyAll(); delete command1; OsTask::delay(1000); // give task some time to shutdown }
/*a! This test is more of a sanity check to verify that * the basic append(), entries() and at() methods work as expected. * All future tests will depend heavily on the at() method * and the most common way of having something in the list is * by means of the append() method. * */ void checkSanity_Append_Entries_And_At() { for (int i = 0 ; i < commonEntriesCount; i++) { UtlContainable* ucExpected = commonContainables[i] ; UtlContainable* ucActual = commonList.at(i) ; string msg ; char strItr[33] ; sprintf(strItr, "%d", i); TestUtilities::createMessage(3, &msg, "Verify that the at(n) method, where n = ", \ strItr, " ;") ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), ucExpected, ucActual) ; } CPPUNIT_ASSERT_EQUAL_MESSAGE("Verify that the entries() for an empty list returns 0", \ (int)emptyList.entries(), 0) ; CPPUNIT_ASSERT_EQUAL_MESSAGE("Verify the entries() method for a list", \ (int)commonList.entries(), commonEntriesCount) ; }// checkSanity_Append_And_At()
void doListOperations() { UtlSList testList; // fill the list appendCountItems(testList, NUM_PERFORMANCE_STRINGS); // take the first half off the front if (!testList.isEmpty()) { getCountItems(testList, NUM_PERFORMANCE_STRINGS / 2); } // take the rest off the end by reference if (!testList.isEmpty()) { UtlContainable* lastItem = testList.last(); delete dynamic_cast<UtlString*>(testList.removeReference(lastItem)); } // fill the list appendCountItems(testList, NUM_PERFORMANCE_STRINGS); // search the list for each item by value UtlString target; int targetIndex; for (targetIndex = 0; targetIndex < NUM_PERFORMANCE_STRINGS; targetIndex += 1) { target = string[targetIndex]; UtlString* found = dynamic_cast<UtlString*>(testList.find(&target)); if (found) { externalForSideEffects = found->length(); } } // get the object in the middle of the list by index, and remove it by value while(!testList.isEmpty()) { int numberLeft = testList.entries(); UtlString* middle = dynamic_cast<UtlString*>(testList.at((numberLeft / 2))); delete dynamic_cast<UtlString*>(testList.remove(middle)); } // fill the list appendCountItems(testList, NUM_PERFORMANCE_STRINGS); // iterate over each item in the list UtlSListIterator iterate(testList); UtlString* item; while ((item = dynamic_cast<UtlString*>(iterate()))) { externalForSideEffects = item->length(); delete item; } }
UtlBoolean DialByNameDB::insertRow ( const Url& contact ) const { UtlBoolean result = FALSE; if ( m_pFastDB != NULL ) { // Fetch the display name UtlString identity, displayName, contactString; contact.getIdentity( identity ); contact.getDisplayName( displayName ); contact.toString( contactString ); // Make sure that the contact URL is valid and contains // a contactIdentity and a contactDisplayName if ( !identity.isNull() && !displayName.isNull() ) { UtlSList dtmfStrings; getDigitStrings ( displayName, dtmfStrings ); if ( !dtmfStrings.isEmpty() ) { // Thread Local Storage m_pFastDB->attach(); // Search for a matching row before deciding to update or insert dbCursor< DialByNameRow > cursor(dbCursorForUpdate); DialByNameRow row; dbQuery query; // Primary Key is identity query="np_identity=",identity; // Purge all existing entries associated with this identity if ( cursor.select( query ) > 0 ) { cursor.removeAllSelected(); } // insert all dtmf combinations for this user unsigned int i; for (i=0; i<dtmfStrings.entries(); i++) { UtlString* digits = (UtlString*)dtmfStrings.at(i); row.np_contact = contactString; row.np_identity = identity; row.np_digits = digits->data(); insert (row); } // Commit rows to memory - multiprocess workaround m_pFastDB->detach(0); } } } return result; }
/*!a Test case to verify insertAt(size_t, UtlContainable*) for a * list that is not empty. * The test data for this test are * a) Insert any UtlContainable to the 0th location, * b) Insert a UtlInt to a 'mid' location, * c) Insert any UtlString object to a 'mid' location * d) Insert any UtlContainable object to the last location */ void testInsertAt_NonEmptyList() { const int testCount = 4 ; const char* prefix = "Test insert(n, Collectable*) for a list that is not empty; "\ "where Collectable is " ; const char* Msgs[] = { \ "a UtlContainableXXX and n = 0", \ "a UtlString and n > 0 && n < size", \ "a UtlInt and n > 0 && n < size", \ "a UtlContainableXXX where n = size-1" \ }; const char* suffix1 = " :- Verify return value" ; const char* suffix2 = " :- Verify value is appended" ; const char* suffix3 = " :- Verify new list size" ; UtlString testFirst("First Entry") ; UtlInt testInt(102) ; UtlString testString("Test String") ; UtlInt testLast(99999) ; UtlContainable* itemToAdd[] = { &testFirst, &testInt, &testString, &testLast } ; UtlContainable* expectedValue[] = { &testFirst, &testInt, &testString, &testLast} ; int insertLocation[] = { 0, 2, 3, commonEntriesCount+3} ; int tmpCount = commonEntriesCount ; int expectedEntries[] = {++tmpCount, ++tmpCount, ++tmpCount, ++tmpCount} ; for (int i = 0 ; i < testCount ; i++) { UtlContainable* uActual ; string msg ; // comment out for now. Uncomment if implementation returns Collectable uActual = commonList.insertAt(insertLocation[i], itemToAdd[i]); //verify that the right value is returned. TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], uActual) ; //`commonList.insertAt(insertLocation[i], itemToAdd[i]); // verify that the value is inserted TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; uActual = commonList.at(insertLocation[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], uActual) ; //verify that the total number of entries has incremented by one. TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix3) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedEntries[i], \ (int)commonList.entries()) ; } }//testInsertAt_NonEmptyList()
//deep copy of aliases void SipLine::copyAliases(UtlSList& dest, const UtlSList& source) const { // Clear dest list if (!dest.isEmpty()) { dest.destroyAll() ; } // Copy maintaining order int length = source.entries() ; for (int i=0; i<length; i++) { UtlString* pEntry = (UtlString*) source.at(i) ; dest.append(new UtlString(*pEntry)) ; } }
bool AlarmRpcGetAlarmCount::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { bool result = false; status = XmlRpcMethod::FAILED; 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 (1 != params.entries()) { handleExtraExecuteParam(name(), response, status); } else { SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData); if(validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name())) { OsSysLog::add(FAC_ALARM, PRI_INFO, "AlarmRpc::getAlarmCount: host %s requested alarm count", pCallingHostname->data() ); // Get the count of alarms since last restart UtlInt alarm_count; alarm_count = UtlInt(cAlarmServer::getInstance()->getAlarmCount()); // Construct and set the response. response.setResponse(&alarm_count); status = XmlRpcMethod::OK; result = true; } } } return result; }
/*!a Test case for the () operator. * * The test data for this test is :- * 1) The next entry is a UtlString * 2) The next entry is a UtlInt * 3) The next entry is the last entry * 4) All entries have been read */ void testAdvancingOperator() { struct TestAdvancingOperatorStruct { const char* testDescription ; const UtlContainable* expectedValue ; } ; const int testCount = 4 ; const char* prefix = "Verify the () operator for an iterator when " ; const char* suffix1 = " :- verify return value" ; const char* suffix2 = " :- verify number of entries in the list" ; UtlSList testList ; testList.append(&commonString1) ; testList.append(&commonInt1) ; testList.append(&commonString2) ; UtlSListIterator iter(testList) ; TestAdvancingOperatorStruct testData[] = { \ { "the first entry is a UtlString", &commonString1 }, \ { "the first entry is a UtlInt", &commonInt1 }, \ { "when the list has only one entry", &commonString2 }, \ { "when the list is empty", NULL } \ } ; int expectedEntries = 3 ; for (int i = 0 ; i < testCount ; i++) { string msg ; TestUtilities::createMessage(3, &msg, prefix, \ testData[i].testDescription, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[i].expectedValue, \ (void*)iter()) ; TestUtilities::createMessage(3, &msg, prefix, testData[i].testDescription, \ suffix2); CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedEntries, \ (int)testList.entries()) ; } // Test the () operator for an empty list UtlSListIterator emptyIter(emptyList) ; CPPUNIT_ASSERT_EQUAL_MESSAGE("Test the () operator for an empty list iterator" , \ (void*)NULL, (void*)emptyIter()) ; } //testAdvancingOperator()
bool UnifiedPresenceChangedMethod::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { status = XmlRpcMethod::FAILED; if( params.entries() == 6 ) { // According to set XML-RPC i/f definition: //param[0] = XMPP Presence //param[1] = Jabber ID; //param[2] = SIP AOR; //param[3] = SIP State; //param[4] = Unified Presence; //param[5] = XMPP Status Message; UnifiedPresence* pUp = new UnifiedPresence( ((UtlString*)params.at(2))->data() ); pUp->setXmppPresence ( ((UtlString*)params.at(0))->data() ); pUp->setXmppStatusMessage( ((UtlString*)params.at(5))->data() ); pUp->setSipState ( ((UtlString*)params.at(3))->data() ); pUp->setUnifiedPresence ( ((UtlString*)params.at(4))->data() ); UtlString* pAor = new UtlString( ((UtlString*)params.at(2))->data() ); // make sure that the SIP AOR really has a domain part; if not, add it. if( pAor->index('@') == UTL_NOT_FOUND ) { pAor->append( '@' ); pAor->append( SipRedirectorPresenceRouting::getLocalDomainName() ); } UnifiedPresenceContainer::getInstance()->insert( pAor, pUp ); } UtlString responseString = "ok"; response.setResponse( &responseString ); status = XmlRpcMethod::OK; return true; }
bool AddExtension::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, XmlRpcMethod::ExecutionStatus& status) { bool result = false; int totalParams = params.entries(); if (totalParams > 2) { response.setFault(TOO_MANY_PARAMS_FAULT_CODE, TOO_MANY_PARAMS_FAULT_STRING); result = false; } else { UtlString groupName; UtlString extension; for (int index = 0; index < totalParams; index++) { UtlContainable *value = params.at(index); if (index == 0 || index == 1) { UtlString paramType(value->getContainableType()); if (paramType.compareTo("UtlString") == 0) { if (index == 0) { groupName = *((UtlString *)value); } else { extension = *((UtlString *)value); } result = true; } else { response.setFault(ILLEGAL_PARAM_FAULT_CODE, ILLEGAL_PARAM_FAULT_STRING); result = false; } } } if (result) { SipDialogMonitor* dialogMonitor = (SipDialogMonitor *) userData; Url extensionUrl(extension); dialogMonitor->addExtension(groupName, extensionUrl); status = XmlRpcMethod::OK; // Construct the response UtlString responseText("method call \"addExtension\" successful"); response.setResponse(&responseText); } } return true; }
int SipLine::getAliases(UtlSList& list) const { copyAliases(list, mAliases) ; return list.entries() ; }
bool SwAdminRpcSnapshot::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { bool result = false; status = XmlRpcMethod::FAILED; if (2 != 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)); SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData); if (!params.at(1) || !params.at(1)->isInstanceOf(UtlSList::TYPE)) { handleMissingExecuteParam(name(), PARAM_NAME_COMMAND, response, status); } else { if (validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name())) { UtlSList* pArgsList = dynamic_cast<UtlSList*>(params.at(1)); UtlSListIterator argsListIterator( *pArgsList ); UtlString * pArg; // Make sure that there is no other instance running. if (! duplicateProcess(SwAdminSnapshot, response, status)) { UtlBool method_result(true); UtlString arguments[pArgsList->entries()+2]; UtlString subCommand; OsPath mWorkingDirectory = "."; OsPath mExec = SipXecsService::Path(SipXecsService::BinDirType, SwAdminSnapshot); UtlString mStdOutFile(SwAdminSnapshot_cmd); UtlString mStdErrFile(SwAdminSnapshot_cmd); mStdOutFile.append(SwAdminStdOut_filetype); mStdErrFile.append(SwAdminStdErr_filetype); // Construct and set the response. OsPath mStdOutPath = OsPath(SipXecsService::Path(SipXecsService::LogDirType, mStdOutFile.data())); OsPath mStdErrPath = OsPath(SipXecsService::Path(SipXecsService::LogDirType, mStdErrFile.data())); OsPath processOutPath = OsPath(SipXecsService::Path(SipXecsService::TmpDirType, OUTPUT_FILENAME)); for (int i = 0; (pArg = dynamic_cast<UtlString*>(argsListIterator())); i++) { XmlUnEscape(arguments[i], *pArg); } arguments[pArgsList->entries()] = processOutPath.data(); arguments[pArgsList->entries()+1] = NULL; // execute the command and return whether or not the launch was successful. OsProcess* swCheck = new OsProcess(); // Setup the Standard Output and Standard Error files. OsPath mStdInFile; // Blank int rc; rc = swCheck->setIORedirect(mStdInFile, mStdOutPath, mStdErrPath); // Launch the process but tell the parent to ignore the child's signals (especially on shutdown). // It will let the system handle it to avoid a defunct process. if ( (rc=swCheck->launch(mExec, &arguments[0], mWorkingDirectory, swCheck->NormalPriorityClass, FALSE, TRUE)) // Parent to ignore child signals. == OS_SUCCESS ) { // Add the file resources to Supervisor Process so they can be retrieved FileResource::logFileResource( mStdOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); FileResource::logFileResource( mStdErrPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); FileResource::logFileResource( processOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); UtlString outputFilename = processOutPath; // Construct and set the response. UtlSList outputPaths; outputPaths.insert(&outputFilename); outputPaths.insert(&mStdOutPath); outputPaths.insert(&mStdErrPath); response.setResponse(&outputPaths); status = XmlRpcMethod::OK; result = true; } // launch else { // Failed to launch the command, send a fault. response.setFault(SwAdminRpcMethod::FailureToLaunch, "Failure to launch command"); status = XmlRpcMethod::FAILED; } delete swCheck; } // duplicateProcess } // validcaller else { status = XmlRpcMethod::FAILED; } } // param 1 okay } // param 0 okay } //number of parms check return result; }
bool ZoneAdminRpcExec::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { bool result = false; status = XmlRpcMethod::FAILED; if (2 != 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 { if (!params.at(1) || !params.at(1)->isInstanceOf(UtlString::TYPE)) { handleMissingExecuteParam(name(), PARAM_NAME_COMMAND, response, status); } else { UtlString* pCallingHostname = dynamic_cast<UtlString*>(params.at(0)); SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData); if(validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name())) { UtlBool method_result(true); UtlString arguments[3]; OsPath mWorkingDirectory = "."; OsPath mExec = SipXecsService::Path(SipXecsService::LibExecDirType,"sipxzoneadmin"); UtlString mStdOutFile; UtlString mStdErrFile; UtlString* pSubCommand = dynamic_cast<UtlString*>(params.at(1)); if ( !buildOutputFiles(*pSubCommand, mStdOutFile, mStdErrFile)) { // Invalid request. Set a Fault. response.setFault(ZoneAdminRpcMethod::FailureToLaunch, "Invalid command"); status = XmlRpcMethod::FAILED; return result; } OsPath mStdOutPath = SipXecsService::Path(SipXecsService::LogDirType, mStdOutFile.data()); OsPath mStdErrPath = SipXecsService::Path(SipXecsService::LogDirType, mStdErrFile.data()); // Pass the argumenst to sipx-zoneadmin.sh arguments[0] = "-n"; // non-interactive arguments[1] = pSubCommand->data(); // string "<primary server> -o <secondary server>" // Make sure that there is no other instance running. if (! duplicateProcess(ZoneAdminExec, response, status)) { // execute the command and return whether or not the launch was successful. OsProcess* zoneCheck = new OsProcess(); // Setup the Standard Output and Standard Error files. OsPath mStdInFile; // Blank int rc; rc = zoneCheck->setIORedirect(mStdInFile, mStdOutPath, mStdErrPath); // Launch the process but tell the parent to ignore the child's signals (especially on shutdown). // It will let the system handle it to avoid a defunct process. if ( (rc=zoneCheck->launch(mExec, &arguments[0], mWorkingDirectory, zoneCheck->NormalPriorityClass, FALSE, TRUE)) // Parent to ignore child signals. == OS_SUCCESS ) { // Construct and set the response. UtlSList outputPaths; outputPaths.insert(&mStdOutPath); outputPaths.insert(&mStdErrPath); // Add the file resources to Supervisor Process so they can be retrieved FileResource::logFileResource( mStdOutPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); FileResource::logFileResource( mStdErrPath, SipxProcessManager::getInstance()->findProcess(SUPERVISOR_PROCESS_NAME)); response.setResponse(&outputPaths); status = XmlRpcMethod::OK; result = true; } // launch else { // Failed to launch the command, send a fault. response.setFault(ZoneAdminRpcMethod::FailureToLaunch, "Failure to launch command"); status = XmlRpcMethod::FAILED; } delete zoneCheck; } // duplicateProcess } // validcaller else { status = XmlRpcMethod::FAILED; } } // param 1 okay } // param 0 okay } //number of parms check return result; }
bool SwAdminRpcExecStatus::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { bool result = false; status = XmlRpcMethod::FAILED; if (2 != 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)); SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData); if (!params.at(1) || !params.at(1)->isInstanceOf(UtlString::TYPE)) { handleMissingExecuteParam(name(), PARAM_NAME_COMMAND, response, status); } else { if (validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name())) { UtlString* query = dynamic_cast<UtlString*>(params.at(1)); UtlString processName; // Make sure that the query is valid if (isQueryValid(*query, processName)) { UtlString stat; if (isProcessActive(processName)) { stat = PROCESS_RUNNING; } else { stat = PROCESS_NOT_RUNNING; } response.setResponse(&stat); status = XmlRpcMethod::OK; result = true; } // wrong Query String else { // Failed to launch the command, send a fault. response.setFault(SwAdminRpcMethod::FailureToLaunch, "Invalid query"); status = XmlRpcMethod::FAILED; } } // validcaller else { status = XmlRpcMethod::FAILED; } } // param 1 okay } // param 0 okay } //number of parms check return result; }
void utlTestRemove(RemoveType type) { int testCount = 5 ; const char* prefix = ""; if (type == TEST_REMOVE) { prefix = "test the remove(UtlContainable* c) method where c" ; } else if (type == TEST_REMOVE_REF) { prefix = "test the removeReference(UtlContainable* c) where c" ; } const char* Msgs[] = { \ "is the first entry's reference ", \ "is the last entry' reference ", \ "is the mid entry's value(not reference) ", \ "is the first of multiple matches and is the value match ", \ "has no match at all " \ } ; const char* suffix1 = " :- Verify returned value" ; const char* suffix2 = " :- Verify total entries" ; commonList.insertAt(2, commonContainables_Clone[4]) ; UtlString notExistCollectable("This cannot and willnot exist"); UtlContainable* itemToRemove[] = { \ commonContainables[0], commonContainables[commonEntriesCount -1 ], \ commonContainables_Clone[2], commonContainables[4], \ ¬ExistCollectable \ } ; int totalEnt = commonEntriesCount + 1; UtlContainable* expectedValue[] = { \ commonContainables[0], commonContainables[commonEntriesCount -1 ], \ commonContainables[2], commonContainables_Clone[4], \ NULL \ }; int entriesValue[] = { --totalEnt, --totalEnt, --totalEnt, --totalEnt, totalEnt } ; totalEnt = commonEntriesCount + 1; UtlContainable* expectedRef[] = { \ commonContainables[0], commonContainables[commonEntriesCount -1 ], \ NULL, commonContainables[4], \ NULL \ }; int entriesRef[] = { --totalEnt, --totalEnt, totalEnt, --totalEnt, totalEnt } ; for (int i = 0 ; i < testCount ; i++) { string msg ; if (type == TEST_REMOVE) { TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix1) ; UtlContainable* retValue = commonList.remove(itemToRemove[i]) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], retValue) ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entriesValue[i], (int)commonList.entries()) ; } else if (type == TEST_REMOVE_REF) { UtlContainable* uRemoved = commonList.removeReference(itemToRemove[i]) ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedRef[i], uRemoved) ; TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), entriesRef[i], (int)commonList.entries()) ; } } } //utlRemove
void utlTestAppend_Insert(TestInsertOrAppend type) { int testCount = 2 ; const char* prefix = ""; UtlInt testInt(1234) ; UtlString testString("Test String") ; if (type == TEST_APPEND) { commonList.append(&testInt) ; commonList.append(&testString) ; prefix = "Test the append(UtlContainable*) method for a non empty list" ; } else if (type == TEST_INSERT) { commonList.insert(&testInt) ; commonList.insert(&testString) ; prefix = "Test the insert(UtlContainable*) method for a non empty list" ; } int expectedCount = commonEntriesCount + testCount ; UtlContainable* uActual ; UtlContainable* uExpected ; string msg ; // Verify that the number of entries has increased accordingly TestUtilities::createMessage(2, &msg, prefix, " :- Verify the number of entries") ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedCount, \ (int)commonList.entries()) ; // Verify that the first entry has still not changed. uActual = commonList.at(0) ; uExpected = commonContainables[0] ; TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify that the first entry is not changed") ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ; // Verify the entry at the previous last position TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify that the previous last entry is intact") ; // Verify that the number of entries has increased accordingly TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify the number of entries") ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedCount, \ (int)commonList.entries()) ; // Verify that the first entry has still not changed. uActual = commonList.at(0) ; uExpected = commonContainables[0] ; TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify that the first entry is not changed") ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ; // Verify the entry at the previous last position TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify that the previous last entry is intact") ; uActual = commonList.at(commonEntriesCount-1) ; uExpected = commonContainables[commonEntriesCount-1] ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ; // Verify that the two new entries are added. TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify that the Collectable Integer has been added") ; uActual = commonList.at(commonEntriesCount) ; uExpected = &testInt ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ; TestUtilities::createMessage(2, &msg, prefix, \ " :- Verify that the Collectable String has been added") ; uActual = commonList.at(commonEntriesCount + 1) ; uExpected = &testString ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uActual, uExpected) ; } //testAppend
// Factory method that parses a 'directory' resource description element. bool DirectoryResource::parse(const TiXmlDocument& directoryDefinitionDoc, ///< process definition document TiXmlElement* resourceElement, // 'directory' element SipxProcess* currentProcess // whose resources are being read. ) { /* * This is called by SipxResource::parse with any 'directory' child of * the 'resources' element in a process definition. * * @returns NULL if the element was in any way invalid. */ UtlString errorMsg; bool resourceIsValid = true; bool validResourceParm; TiXmlElement* dbElement; UtlString path; UtlSList resources; // holding list for resources until we're done DirectoryResource* dirWithoutPatternResource = NULL; DirectoryResource* directoryResource = NULL; DirectoryResourceManager* directoryManager = DirectoryResourceManager::getInstance(); dbElement = resourceElement->FirstChildElement(); if (dbElement) { if (0 == strcmp("path",dbElement->Value())) { validResourceParm = textContent(path, dbElement); if (validResourceParm && !path.isNull()) { // Initialize the resource for the directory path name alone (null pattern) // used for 'required' processing. if (!(directoryResource = directoryManager->find(path, ""))) // does this combination exist? { directoryResource = new DirectoryResource(path, "", ""); } // get the attribute values for the directory for ( const TiXmlAttribute* attribute = resourceElement->FirstAttribute(); resourceIsValid && attribute; attribute = attribute->Next() ) { if (!(resourceIsValid = directoryResource->SipxResource::parseAttribute(directoryDefinitionDoc, attribute, currentProcess) )) { Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "invalid attribute '%s': directory path '%s' ignored", attribute->Name(), path.data()); } } // end of attribute loop if (resourceIsValid) { dirWithoutPatternResource = directoryResource; resources.append(directoryResource); // save until parsing is complete directoryResource = NULL; } // advance to the next element, if any. dbElement = dbElement->NextSiblingElement(); } else { resourceIsValid = false; XmlErrorMsg(directoryDefinitionDoc, errorMsg); Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "'path' element is empty or invalid %s", errorMsg.data() ); } } else { // first child is not 'path' resourceIsValid = false; XmlErrorMsg(directoryDefinitionDoc, errorMsg); Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "expected path element, found %s", dbElement->Value() ); } } else { resourceIsValid = false; XmlErrorMsg(directoryDefinitionDoc, errorMsg); Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "no elements are present: path element is required %s", errorMsg.data() ); } /* * Loop over all filePattern elements, creating a DirectoryResource for each, * and saving them on the 'resources' list. */ while (resourceIsValid && dbElement) { if (0 == strcmp("filePattern", dbElement->Value())) { TiXmlElement* filePatternDocElement = dbElement; UtlString pattern; validResourceParm = textContent(pattern, dbElement); if (validResourceParm && !pattern.isNull()) { if (!(directoryResource = directoryManager->find(path, pattern))) // does this combination exist? { // No - this is a new path/pattern combination // Convert the file pattern into a regular expression UtlString patternExpression; if ( pattern2RegEx(pattern, patternExpression) ) { directoryResource = new DirectoryResource(path, pattern, patternExpression); for ( const TiXmlAttribute* attribute = filePatternDocElement->FirstAttribute(); resourceIsValid && attribute; attribute = attribute->Next() ) { if (directoryResource-> SipxResource::isAttribute(attribute, SipxResource::RequiredAttributeName)) { resourceIsValid = false ; Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "invalid attribute '%s' on filePattern '%s'", attribute->Name(), path.data()) ; } else if (!(resourceIsValid = directoryResource-> SipxResource::parseAttribute(directoryDefinitionDoc, attribute, currentProcess) )) { Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "invalid attribute '%s': filePattern '%s' ignored", attribute->Name(), pattern.data()); } } if (resourceIsValid) { if (directoryResource->mImplicitAccess) { directoryResource->mImplicitAccess = dirWithoutPatternResource->mImplicitAccess; directoryResource->mAccess = dirWithoutPatternResource->mAccess; } } else { delete directoryResource; } } else { resourceIsValid = false; Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "path '%s' " "filePattern '%s' did not translate to a regular expression", path.data(), pattern.data() ); } } else { // existing path/pattern combination // parse the attributes so that the required and access attributes are set correctly for ( const TiXmlAttribute* attribute = filePatternDocElement->FirstAttribute(); resourceIsValid && attribute; attribute = attribute->Next() ) { if (directoryResource-> SipxResource::isAttribute(attribute, SipxResource::RequiredAttributeName)) { resourceIsValid = false ; Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "invalid attribute '%s' on filePattern '%s'", attribute->Name(), path.data()) ; } else if (!(resourceIsValid = directoryResource-> SipxResource::parseAttribute(directoryDefinitionDoc, attribute, currentProcess) )) { Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "invalid attribute '%s': filePattern '%s' ignored", attribute->Name(), pattern.data()); } } if (resourceIsValid) { if (directoryResource->mImplicitAccess) { directoryResource->mImplicitAccess = dirWithoutPatternResource->mImplicitAccess; directoryResource->mAccess = dirWithoutPatternResource->mAccess; } Os::Logger::instance().log(FAC_SUPERVISOR, PRI_INFO, "DirectoryResource::parse " "shared directory '%s' pattern '%s'", path.data(), pattern.data() ); } } // advance to the next element, if any. dbElement = dbElement->NextSiblingElement(); } else { resourceIsValid = false; XmlErrorMsg(directoryDefinitionDoc, errorMsg); Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "'filePattern' element is empty" ); } } else { resourceIsValid = false; XmlErrorMsg(directoryDefinitionDoc, errorMsg); Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "expected 'filePattern' element; found '%s'", dbElement->Value() ); } if (resourceIsValid) { resources.append(directoryResource); } directoryResource = NULL; } // while loop over filePattern elements if (resourceIsValid && resources.entries() < 2) // no filePattern elements were found { // the directory resource was created, but no filePattern elements resourceIsValid = false; Os::Logger::instance().log(FAC_SUPERVISOR, PRI_ERR, "DirectoryResource::parse " "no 'filePattern' elements found for path '%s'", path.data() ); } if (resourceIsValid) // have all elements been parsed successfully? { // everything was valid - so transfer the resulting resources to the DirectoryResourceManager while ((directoryResource=dynamic_cast<DirectoryResource*>(resources.get()))) { directoryResource->usedBy(currentProcess); if (! directoryResource->mFilePattern.isNull()) { // pattern resources are not allowed to be required currentProcess->resourceIsOptional(directoryResource); } if (directoryResource->mFirstDefinition) { directoryResource->mFirstDefinition = false; directoryManager->save(directoryResource); UtlString description; directoryResource->appendDescription(description); Os::Logger::instance().log(FAC_SUPERVISOR, PRI_INFO, "DirectoryResource::parse add %s", description.data() ); } } } else { /* * Something was invalid - discard any of these resources that are not shared * * Note: this could still have modified the access of some shared resources, * but that's too difficult to fix. */ while ((directoryResource=dynamic_cast<DirectoryResource*>(resources.get()))) { if (directoryResource->mFirstDefinition) { delete directoryResource; } } } return resourceIsValid; }
UtlBoolean DialByNameDB::getDigitStrings ( const UtlString& displayName, UtlSList& rDTMFStrings ) const { UtlString lowerString = displayName; lowerString.toLower(); lowerString = lowerString.strip(UtlString::both, '"'); UtlTokenizer next( lowerString ); UtlString token; UtlSList names; // Parse the Display name into a list of names // The algorithm for breaking up the string is as follows // if the string has > 2 tokens (forget about , separators) // create multiple entries in the IMDB for the all combinations // so for example // John Peter Smith Jr would result in DTMF entries for // PeterSmithJrJohn, SmithJrJohnPeter and JrJohnPeterSmith // @JC Added - separator for MIT's Avery-Smith example while (next.next(token, "\t\n,- ")) { names.insert ( new UtlString ( token ) ); } size_t numNames = names.entries(); if ( numNames > 0 ) { UtlString reorderedString; unsigned int splitPosition = 1; do { unsigned int i; UtlString firstNames; for ( i=0; i<splitPosition; i++ ) { firstNames += *(UtlString*)names.at(i); } UtlString lastNames; for ( i = splitPosition; i<numNames; i++) { lastNames += *(UtlString*)names.at(i); } // add the new string reorderedString = lastNames + firstNames; unsigned int len = reorderedString.length(); // calculate thd DTMF digits for the display name // firstly strip all , 's and spaces UtlString digitString; for ( i = 0; i<len; i++ ) { int offset = (int) ( reorderedString(i) - 'a' ); // filter out white space and comma separators if ( (offset >= 0) && (offset < 26) ) digitString += digitmap[ offset ]; } rDTMFStrings.insert ( new UtlString (digitString) ); splitPosition++; } while ( splitPosition<numNames ); } // call the desctuctors on all the temp strings names.destroyAll(); return TRUE; }
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; }
/*!a Test case for the insertAfterPoint() method. * * The test data is :- * a) Insert when the iterator is the starting position * b) Insert when the iterator is at mid position * c) Insert when the iterator is at the last position * d) Insert to an empty Iterator. */ void testInsertAfterPoint() { struct TestInsertAfterStruct { const char* testDescription; UtlContainable* insertValue ; UtlContainable* oldValue ; }; const char* prefix = "Test the insertAfterPoint() method when " ; const char* suffix1 = ":- Verify return value" ; const char* suffix2 = ":- Verify value is inserted" ; const char* suffix3 = ":- Verify that previous value is not lost" ; string msg ; UtlSListIterator iter(commonList) ; UtlString newColString1("Insert at starting position") ; UtlInt newColInt2(101) ; UtlString newColString3 ("Insert at last position") ; TestInsertAfterStruct testData[] = { \ { "the iterator is the starting position " , &newColString1, \ commonContainables[0] }, \ { "the iterator is at mid-position ", &newColInt2, commonContainables[1] }, \ { "the iterator is at the last position ", &newColString3, \ commonContainables[5] } \ }; const UtlContainable* uReturn ; UtlContainable* uAppended ; UtlContainable* originalValue ; // Since this test requires different steps for the different test data, // steps are executed individually rather than the regular technique of // iterating through the test-array loop //Test#1 - Verify the case when the iterator has been reset int ti = 0 ; iter.reset() ; uReturn = iter.insertAfterPoint(testData[ti].insertValue) ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE (msg.data(), (void*)testData[ti].insertValue, \ (void*)uReturn) ; // The item is inserted at first position // old[0] is now @ pos1. old[1] is now @ pos2 iter.reset() ; uAppended = iter() ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[ti].insertValue, \ (void*)uAppended) ; // Verify that the original item is still retained. originalValue = iter() ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[ti].oldValue, \ (void*)originalValue) ; //Test#2 - inserting at mid position ti = 1; iter.reset() ; iter() ; //moves cursor to 0 iter() ; //moves cursor to 1 iter() ; //moves cursor to 2 // Value is now inserted after pos2 (to pos3) // old[1] stays at pos2 uReturn = iter.insertAfterPoint(testData[ti].insertValue) ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE (msg.data(), (void*)testData[ti].insertValue, \ (void*)uReturn) ; iter.reset() ; iter() ; // moves cursor to 0 iter() ; // moves cursor to 1 // Verify that the original item is still retained. originalValue = iter() ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[ti].oldValue, \ (void*)originalValue) ; // The item is inserted just after the position. uAppended = iter() ; //moves cursor to pos3 and returns item at pos2 TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix3) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[ti].insertValue, \ (void*)uAppended) ; // Test#3 - Now verify when the cursor is at the last position. ti = 2 ; iter.reset() ; iter.toLast() ; uReturn = iter.insertAfterPoint(testData[ti].insertValue) ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix1) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[ti].insertValue, \ (void*)uReturn) ; iter.reset() ; // now move the cursor all the way to the penultimate position for (size_t i = 0 ; i < commonList.entries() - 1; i++) { originalValue = iter() ; } // verify original is still retained. TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix3) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)testData[ti].oldValue, \ (void*)originalValue) ; uAppended = iter() ; TestUtilities::createMessage(3, &msg, prefix, testData[ti].testDescription, suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE( msg.data(), (void*)testData[ti].insertValue, \ (void*)uAppended) ; } //testInsertAfterPoint
bool AlarmRpcRaiseAlarm::execute(const HttpRequestContext& requestContext, UtlSList& params, void* userData, XmlRpcResponse& response, ExecutionStatus& status) { bool result = false; status = XmlRpcMethod::FAILED; if (params.entries() > 3) { 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_ALARM_ID, response, status); } else { UtlString* pAlarmId = dynamic_cast<UtlString*>(params.at(1)); if (!params.at(2) || !params.at(2)->isInstanceOf(UtlSList::TYPE)) { handleMissingExecuteParam(name(), PARAM_NAME_ALARM_PARAMS, response, status); } else { UtlSList* pAlarmParams = dynamic_cast<UtlSList*>(params.at(2)); UtlBool method_result(false); SipxRpc* pSipxRpcImpl = ((SipxRpc *)userData); if (validCaller(requestContext, *pCallingHostname, response, *pSipxRpcImpl, name())) { OsSysLog::add(FAC_ALARM, PRI_DEBUG, "AlarmRpc::raiseAlarm: host %s requested alarm '%s'", pCallingHostname->data(), pAlarmId->data() ); method_result = cAlarmServer::getInstance()->handleAlarm(*pCallingHostname, *pAlarmId, *pAlarmParams); // Construct and set the response. response.setResponse(&method_result); status = XmlRpcMethod::OK; result = true; } } } } } return result; }