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; }
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 }
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()
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; }
//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)) ; } }
virtual bool execute(const HttpRequestContext& requestContext, ///< request context UtlSList& params, ///< request param list void* userData, ///< user data XmlRpcResponse& response, ///< request response ExecutionStatus& status ) { UtlString* dbName = dynamic_cast<UtlString*>(params.at(0)); if (dbName && !dbName->isNull()) { OsReadLock lock(*ConfigRPC::spDatabaseLock); ConfigRPC* db = ConfigRPC::find(*dbName); if (db) { status = db->mCallback->accessAllowed(requestContext, ConfigRPC_Callback::Version); if ( XmlRpcMethod::OK == status ) { response.setResponse(&db->mVersion); } else { UtlString faultMsg("Access Denied"); response.setFault(XmlRpcMethod::FAILED, faultMsg.data()); } } else { UtlString faultMsg; faultMsg.append("db lookup failed for '"); faultMsg.append(*dbName); faultMsg.append("'"); response.setFault( XmlRpcResponse::UnregisteredMethod, faultMsg.data()); status = XmlRpcMethod::FAILED; } } else { response.setFault( XmlRpcResponse::EmptyParameterValue ,"'dbname' parameter is missing or invalid type" ); status = XmlRpcMethod::FAILED; } return true; }
/*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()
bool ProvisioningAgentXmlRpcAction::execute(const HttpRequestContext& rContext, UtlSList& rParameters, void* pProvisioningAgentInstance, XmlRpcResponse& rResponse, XmlRpcMethod::ExecutionStatus& rStatus) { rStatus = XmlRpcMethod::OK; // Extract the request argument structure from the head of the SList. UtlContainable *pRequestArgs = rParameters.at(0); // Verify that a parameter list was given if (pRequestArgs != NULL) { // Verify that the parameter list is a structure ("UtlHashMap"). if (UtlString(pRequestArgs->getContainableType()) == "UtlHashMap") { // Now call the Provisioning Agent. ProvisioningAttrList requestAttributes(dynamic_cast<UtlHashMap*>(pRequestArgs)); ProvisioningAttrList* pResponseAttributes; pResponseAttributes = ((ProvisioningAgent*)pProvisioningAgentInstance)->Action(requestAttributes); if (pResponseAttributes == NULL) { // Method failure. Report error back to client rResponse.setFault(METHOD_DISPATCH_FAULT_CODE, METHOD_DISPATCH_FAULT_STRING); } else { // Encode the response rResponse.setResponse(dynamic_cast<UtlContainable*>(pResponseAttributes->getData())); // and clean up the responsettributes list. delete pResponseAttributes; } } else { // Missing parameter list. Report error back to client rResponse.setFault(EXPECTED_STRUCT_FAULT_CODE, EXPECTED_STRUCT_FAULT_STRING); } } else { // Bad parameter list. Report error back to client rResponse.setFault(EXPECTED_STRUCT_FAULT_CODE, EXPECTED_STRUCT_FAULT_STRING); } return true; }
/*!a! Test case to verify insertAt(size_t, UtlContainable*) for an * empty list. * The test data for this test are * a) Insert a UtlString to the 0th location, * b) Insert a UtlInt to the 0th location, * c) Insert any UtlContainable object to a 'non-zero' location */ void testInsertAt_EmptyList() { const int testCount = 3 ; const char* prefix = "Test insert(n, Collectable*) for an empty list; "\ "where Collectable is " ; const char* Msgs[] = { \ "a UtlString and n = 0", \ "a UtlInt and n = 0", \ "a UtlContainableXXX and n > 0" \ }; const char* suffix1 = " :- Verify return value" ; const char* suffix2 = " :- Verify value is appended" ; UtlInt testInt(102) ; UtlString testString("Test String") ; UtlString testNegative("This should not get added") ; UtlContainable* itemToAdd[] = { &testString, &testInt, &testNegative } ; UtlContainable* expectedValue[] = { &testString, &testInt, NULL} ; int insertLocation[] = { 0, 0, 1} ; for (int i = 0 ; i < testCount ; i++) { UtlSList testList ; string msg ; // insertAt now returns void. Retain this block of comment in case // we (I think we should return a Collectable / bool) decide to return // a collectable. UtlContainable* result = testList.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], result) ; testList.insertAt(insertLocation[i], itemToAdd[i]) ; // verify that the value is inserted TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix2) ; CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValue[i], testList.at(0)) ; } }//testInsertAt_EmptyList
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; }
virtual bool execute(const HttpRequestContext& requestContext, ///< request context UtlSList& params, ///< request param list void* userData, ///< user data XmlRpcResponse& response, ///< request response ExecutionStatus& status ) { UtlString* dbName = dynamic_cast<UtlString*>(params.at(0)); if (dbName && !dbName->isNull()) { OsReadLock lock(*ConfigRPC::spDatabaseLock); // find the dataset registered with this name ConfigRPC* db = ConfigRPC::find(*dbName); if (db) { // check with the application to see if this request is authorized on this dataset status = db->mCallback->accessAllowed(requestContext, ConfigRPC_Callback::Get); if ( XmlRpcMethod::OK == status ) { // read in the dataset OsConfigDb dataset; OsStatus datasetStatus = db->load(dataset); if ( OS_SUCCESS == datasetStatus ) { // get the list of names that the request is asking for UtlContainable* secondParam = params.at(1); if ( secondParam ) { UtlSList* nameList = dynamic_cast<UtlSList*>(secondParam); if (nameList) { /* * Iterate over the requested names * - All must be present or the request is an error * - For each name found, add the name and value to the * selectedParams hash to be returned in a success response. */ UtlHashMap selectedParams; UtlSListIterator requestedNames(*nameList); UtlString* requestedName = NULL; bool allNamesFound = true; while ( allNamesFound && (requestedName = dynamic_cast<UtlString*>(requestedNames())) ) { UtlString* paramValue = new UtlString(); if ( OS_SUCCESS == dataset.get(*requestedName, *paramValue) ) { UtlString* paramName = new UtlString(*requestedName); // put it into the results selectedParams.insertKeyAndValue(paramName, paramValue); } else { allNamesFound = false; delete paramValue; } } if (allNamesFound) { // all were found - return the name/value pairs response.setResponse(&selectedParams); } else { // at least one name was not found - return an error. UtlString faultMsg; faultMsg.append("parameter name '"); faultMsg.append(*requestedName); faultMsg.append("' not found"); response.setFault(ConfigRPC::nameNotFound, faultMsg.data()); status = XmlRpcMethod::FAILED; } selectedParams.destroyAll(); } else { // The second parameter was not a list response.setFault( ConfigRPC::invalidType ,"namelist parameter is not an array" ); status = XmlRpcMethod::FAILED; } } else // no parameter names specified { // return all names UtlHashMap allParams; UtlString lastKey; OsStatus iterateStatus; UtlString* paramName; UtlString* paramValue; bool notEmpty = false; for ( ( paramName = new UtlString() ,paramValue = new UtlString() ,iterateStatus = dataset.getNext(lastKey, *paramName, *paramValue) ); OS_SUCCESS == iterateStatus; ( lastKey = *paramName ,paramName = new UtlString() ,paramValue = new UtlString() ,iterateStatus = dataset.getNext(lastKey, *paramName, *paramValue) ) ) { notEmpty = true; // got at least one parameter // put it into the result array allParams.insertKeyAndValue(paramName, paramValue); } // on the final iteration these were not used delete paramName; delete paramValue; if (notEmpty) { response.setResponse(&allParams); allParams.destroyAll(); } else { // there is no way to send a well-formed but empty response, // so a 'get all' on an empty dataset returns a fault. UtlString faultMsg; faultMsg.append("dataset '"); faultMsg.append(*dbName); faultMsg.append("' has no parameters"); response.setFault(ConfigRPC::emptyDataset, faultMsg); status = XmlRpcMethod::FAILED; } } } else { UtlString faultMsg("dataset load failed"); response.setFault(ConfigRPC::loadFailed, faultMsg); status = XmlRpcMethod::FAILED; } } else { UtlString faultMsg("Access Denied"); response.setFault(XmlRpcMethod::FAILED, faultMsg.data()); } } else { UtlString faultMsg; faultMsg.append("db lookup failed for '"); faultMsg.append(*dbName); faultMsg.append("'"); response.setFault( XmlRpcResponse::UnregisteredMethod, faultMsg.data()); status = XmlRpcMethod::FAILED; } } else { response.setFault( XmlRpcResponse::EmptyParameterValue ,"'dbname' parameter is missing or invalid type" ); status = XmlRpcMethod::FAILED; } return true; }
virtual bool execute(const HttpRequestContext& requestContext, ///< request context UtlSList& params, ///< request param list void* userData, ///< user data XmlRpcResponse& response, ///< request response ExecutionStatus& status ) { UtlString* dbName = dynamic_cast<UtlString*>(params.at(0)); if (dbName && !dbName->isNull()) { OsReadLock lock(*ConfigRPC::spDatabaseLock); ConfigRPC* db = ConfigRPC::find(*dbName); if (db) { status = db->mCallback->accessAllowed(requestContext, ConfigRPC_Callback::Set); if ( XmlRpcMethod::OK == status ) { // read in the dataset OsConfigDb dataset; OsStatus datasetStatus = db->load(dataset); if ( OS_SUCCESS == datasetStatus ) { // get the list of names that the request is asking for UtlContainable* secondParam = params.at(1); if ( secondParam ) { UtlHashMap* paramList = dynamic_cast<UtlHashMap*>(secondParam); if (paramList) { /* * Iterate over the requested name/value pairs */ UtlHashMapIterator params(*paramList); UtlContainable* nextParam = NULL; size_t paramsSet = 0; while ( XmlRpcMethod::OK == status && (nextParam = params()) ) { UtlString* name = dynamic_cast<UtlString*>(params.key()); if ( name ) { UtlString* value = dynamic_cast<UtlString*>(params.value()); if (value) { dataset.set(*name, *value); paramsSet++; } else { UtlString faultMsg; faultMsg.append("parameter name '"); faultMsg.append(*name); faultMsg.append("' value is not a string"); response.setFault(ConfigRPC::invalidType, faultMsg.data()); status = XmlRpcMethod::FAILED; } } else { UtlString faultMsg; faultMsg.append("parameter number "); char paramIndex[10]; sprintf(paramIndex,"%zu", paramsSet + 1); faultMsg.append(paramIndex); faultMsg.append(" name is not a string"); response.setFault(ConfigRPC::invalidType, faultMsg.data()); status = XmlRpcMethod::FAILED; } } if ( XmlRpcMethod::OK == status ) { if (OS_SUCCESS == db->store(dataset)) { UtlInt numberSet(paramList->entries()); response.setResponse(&numberSet); } else { response.setFault( ConfigRPC::storeFailed ,"error storing dataset" ); status = XmlRpcMethod::FAILED; } } } else { // The second parameter was not a list response.setFault( ConfigRPC::invalidType ,"second parameter is not a struct" ); status = XmlRpcMethod::FAILED; } } else // no parameter names specified { // No second parameter response.setFault( ConfigRPC::invalidType ,"no second parameter of name/value pairs" ); status = XmlRpcMethod::FAILED; } } else { UtlString faultMsg("dataset load failed"); response.setFault(ConfigRPC::loadFailed, faultMsg); status = XmlRpcMethod::FAILED; } } else { UtlString faultMsg("Access Denied"); response.setFault(XmlRpcMethod::FAILED, faultMsg.data()); } } else { UtlString faultMsg; faultMsg.append("db lookup failed for '"); faultMsg.append(*dbName); faultMsg.append("'"); response.setFault( XmlRpcResponse::UnregisteredMethod, faultMsg.data()); status = XmlRpcMethod::FAILED; } } else { response.setFault( XmlRpcResponse::EmptyParameterValue ,"'dbname' parameter is missing or invalid type" ); status = XmlRpcMethod::FAILED; } return true; }
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; }
virtual bool execute(const HttpRequestContext& requestContext, ///< request context UtlSList& params, ///< request param list void* userData, ///< user data XmlRpcResponse& response, ///< request response ExecutionStatus& status ) { UtlString* dbName = dynamic_cast<UtlString*>(params.at(0)); if (dbName && !dbName->isNull()) { OsReadLock lock(*ConfigRPC::spDatabaseLock); ConfigRPC* db = ConfigRPC::find(*dbName); if (db) { status = db->mCallback->accessAllowed(requestContext, ConfigRPC_Callback::Set); if ( XmlRpcMethod::OK == status ) { // read in the dataset OsConfigDb dataset; OsStatus datasetStatus = db->load(dataset); if ( OS_SUCCESS == datasetStatus ) { // get the list of names that the request is trying to delete UtlContainable* secondParam = params.at(1); if ( secondParam ) { UtlSList* nameList = dynamic_cast<UtlSList*>(secondParam); if (nameList) { /* * Iterate over the names * - For each name found, delete it from the dataset and count it */ UtlSListIterator deleteNames(*nameList); UtlString* deleteName = NULL; size_t deleted = 0; while ((deleteName = dynamic_cast<UtlString*>(deleteNames()))) { if (OS_SUCCESS == dataset.remove(*deleteName)) { deleted++; } } if (OS_SUCCESS == db->store(dataset)) { status = XmlRpcMethod::OK; UtlInt deletedCount(deleted); response.setResponse(&deletedCount); } else { response.setFault( ConfigRPC::storeFailed ,"error storing dataset" ); status = XmlRpcMethod::FAILED; } } else { // The second parameter was not a list response.setFault( ConfigRPC::invalidType ,"namelist parameter is not an array" ); status = XmlRpcMethod::FAILED; } } else // No second parameter { response.setFault( ConfigRPC::invalidType ,"no second parameter list of names to delete" ); status = XmlRpcMethod::FAILED; } } else { UtlString faultMsg("dataset load failed"); response.setFault(ConfigRPC::loadFailed, faultMsg); status = XmlRpcMethod::FAILED; } } else { UtlString faultMsg("Access Denied"); response.setFault(XmlRpcMethod::FAILED, faultMsg.data()); } } else { UtlString faultMsg; faultMsg.append("db lookup failed for '"); faultMsg.append(*dbName); faultMsg.append("'"); response.setFault( XmlRpcResponse::UnregisteredMethod, faultMsg.data()); status = XmlRpcMethod::FAILED; } } else { response.setFault( XmlRpcResponse::EmptyParameterValue ,"'dbname' parameter is missing or invalid type" ); status = XmlRpcMethod::FAILED; } return true; }
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; }
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 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; }
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; }
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; }
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