void testDoubleRoute() { const char* message = "INVITE sip:[email protected] SIP/2.0\r\n" "Route: <sip:[email protected];lr>, <sip:[email protected];lr>\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); Url requestUri; UtlSList removedRoutes; testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes); UtlString normalizedMsg; int msgLen; testMsg.getBytes(&normalizedMsg, &msgLen); const char* expectedMessage = // route header removed, uri swapped "INVITE sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; ASSERT_STR_EQUAL(expectedMessage, normalizedMsg.data()); UtlString requestUriResult; requestUri.toString(requestUriResult); ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data()); UtlString* removedRoute; CPPUNIT_ASSERT( removedRoute = static_cast<UtlString*>(removedRoutes.get())); ASSERT_STR_EQUAL("<sip:[email protected];lr>", removedRoute->data()); delete removedRoute; CPPUNIT_ASSERT( removedRoute = static_cast<UtlString*>(removedRoutes.get())); ASSERT_STR_EQUAL("<sip:[email protected];lr>", removedRoute->data()); delete removedRoute; CPPUNIT_ASSERT(removedRoutes.isEmpty()); }
/*!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()
void XmlRpcResponse::cleanUp(UtlContainable* value) { if (value) { if (value->isInstanceOf(UtlHashMap::TYPE)) { UtlHashMap* map = dynamic_cast<UtlHashMap*>(value); UtlHashMapIterator iterator(*map); UtlString* key; while ((key = dynamic_cast<UtlString*>(iterator()))) { UtlContainable *pName; UtlContainable *member; pName = map->removeKeyAndValue(key, member); delete pName; cleanUp(member); } } else if (value->isInstanceOf(UtlSList::TYPE)) { UtlSList* array = dynamic_cast<UtlSList*>(value); UtlContainable *element; while ((element = array->get()/* pop */)) { cleanUp(element); } } delete value; } }
void getCountItems(UtlSList& list, size_t itemsToPop) { assert(itemsToPop); for (; !list.isEmpty() && itemsToPop; itemsToPop--) { delete dynamic_cast<UtlString*>(list.get()); } }
void testTwoRoutesOneLocal() { const char* message = "INVITE sip:[email protected] SIP/2.0\r\n" "Route: <sip:example.com;lr>, <sip:proxy.somewhere.com;lr>\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); Url requestUri; UtlSList removedRoutes; testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes); UtlString normalizedMsg; int msgLen; testMsg.getBytes(&normalizedMsg, &msgLen); UtlString requestUriResult; requestUri.toString(requestUriResult); ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data()); UtlString* removedRoute; CPPUNIT_ASSERT( removedRoute = dynamic_cast<UtlString*>(removedRoutes.get())); ASSERT_STR_EQUAL("<sip:example.com;lr>", removedRoute->data()); delete removedRoute; CPPUNIT_ASSERT(removedRoutes.isEmpty()); UtlString route; /* "Route: <sip:proxy.somewhere.com;lr>\r\n" */ CPPUNIT_ASSERT(getNormalRoute(testMsg, 0, route)); ASSERT_STR_EQUAL("<sip:proxy.somewhere.com;lr>", route.data()); CPPUNIT_ASSERT(!getNormalRoute(testMsg, 1, route)); }
// Constructor SipxRpc::SipxRpc(XmlRpcDispatch* dispatcher, UtlSList& allowedPeers) : mpXmlRpcDispatch(dispatcher) { // Take ownership of the UtlString object memory. UtlContainable* peer; while((peer = allowedPeers.get())) { mAllowedPeers.insert(peer); } // Make sure the localhost is among the allowed peers. UtlString myName; OsSocket::getHostName(&myName); if (!mAllowedPeers.contains(&myName)) { mAllowedPeers.insert(new UtlString(myName)); } // Register the XML-RPC methods. ProcMgmtRpcGetStateAll::registerSelf(*this); ProcMgmtRpcGetStatusMessage::registerSelf(*this); ProcMgmtRpcStart::registerSelf(*this); ProcMgmtRpcStop::registerSelf(*this); ProcMgmtRpcRestart::registerSelf(*this); ProcMgmtRpcGetConfigVersion::registerSelf(*this); ProcMgmtRpcSetConfigVersion::registerSelf(*this); ProcMgmtRpcRunConfigtest::registerSelf(*this); ProcMgmtRpcGetConfigtestMessages::registerSelf(*this); ImdbRpcReplaceTable::registerSelf(*this); ImdbRpcRetrieveTable::registerSelf(*this); ImdbRpcAddTableRecords::registerSelf(*this); ImdbRpcDeleteTableRecords::registerSelf(*this); FileRpcReplaceFile::registerSelf(*this); AlarmRpcGetAlarmCount::registerSelf(*this); AlarmRpcRaiseAlarm::registerSelf(*this); AlarmRpcReloadAlarms::registerSelf(*this); SwAdminRpcExec::registerSelf(*this); }
// 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; }