void Connection::setRingingTimer(int seconds) { UtlString callId; mpCall->getCallId(callId); UtlString remoteAddr; getRemoteAddress(&remoteAddr); CpMultiStringMessage* offeringExpiredMessage = new CpMultiStringMessage(CpCallManager::CP_RINGING_EXPIRED, callId.data(), remoteAddr.data()); OsTimer* timer = new OsTimer((mpCallManager->getMessageQueue()), offeringExpiredMessage); #ifdef TEST_PRINT osPrintf("Setting ringing timeout in %d seconds\n", seconds); #endif OsTime timerTime(seconds, 0); timer->oneshotAfter(timerTime); #ifdef TEST_PRINT osPrintf("Connection::setRingingTimer message type: %d %d", OsMsg::PHONE_APP, CpCallManager::CP_RINGING_EXPIRED); #endif callId.remove(0); remoteAddr.remove(0); }
void Connection::setOfferingTimer(int milliSeconds) { UtlString callId; SipSession session ; Url urlTo ; UtlString remoteAddr; getSession(session) ; session.getCallId(callId) ; session.getToUrl(urlTo) ; urlTo.toString(remoteAddr) ; CpMultiStringMessage* offeringExpiredMessage = new CpMultiStringMessage(CpCallManager::CP_OFFERING_EXPIRED, callId.data(), remoteAddr.data()); OsTimer* timer = new OsTimer((mpCallManager->getMessageQueue()), offeringExpiredMessage); // Convert from mSeconds to uSeconds OsTime timerTime(milliSeconds / 1000, milliSeconds % 1000); timer->oneshotAfter(timerTime); #ifdef TEST_PRINT osPrintf("Connection::setOfferingTimer message type: %d %d", OsMsg::PHONE_APP, CpCallManager::CP_OFFERING_EXPIRED); #endif callId.remove(0); remoteAddr.remove(0); }
void SipTransactionList::toStringWithRelations(UtlString& string, SipMessage& message, UtlBoolean isOutGoing) { lock(); string.remove(0); UtlHashBagIterator iterator(mTransactions); SipTransaction* transactionFound = NULL; UtlString oneTransactionString; SipTransaction::messageRelationship relation; UtlString relationString; while((transactionFound = (SipTransaction*) iterator())) { relation = transactionFound->whatRelation(message, isOutGoing); SipTransaction::getRelationshipString(relation, relationString); string.append(relationString); string.append(" "); transactionFound->toString(oneTransactionString, FALSE); string.append(oneTransactionString); oneTransactionString.remove(0); string.append("\n"); } unlock(); }
// Copy constructor SipRequestContext::SipRequestContext(const SipRequestContext& rSipRequestContext) { // delete the old values in the UtlDList if(!mVariableList.isEmpty()) { mVariableList.destroyAll(); } //copy mVariableList memebers individually UtlDListIterator iterator((UtlDList&)rSipRequestContext.mVariableList); NameValuePair* nameValuePair = NULL; UtlString value; UtlString name; int index = 0; do { nameValuePair = (NameValuePair*)iterator(); if(nameValuePair) { name.append(*nameValuePair); value.append(nameValuePair->getValue()); NameValuePair* newNvPair = new NameValuePair(name, value); mVariableList.insertAt(index, newNvPair); index ++; name.remove(0); value.remove(0); } } while (nameValuePair != NULL); }
void testUtl2Utl() { UtlString encoded; UtlString decoded; char msg[2048]; for (unsigned int test = 0; test < (sizeof(tests)/sizeof(TestData)); test++) { UtlString input(tests[test].inputData, tests[test].inputSize); encoded.remove(0); NetBase64Codec::encode(input, encoded); sprintf(msg, "\n test case %d encoding" "\n expected size %d data '%s'" "\n actual size %d data '%s'", test, strlen(tests[test].output), tests[test].output, encoded.length(), encoded.data() ); CPPUNIT_ASSERT_MESSAGE(msg, ( (encoded.length() == strlen(tests[test].output)) && (encoded.compareTo(tests[test].output) == 0) )); decoded.remove(0); bool decodedOk; decodedOk = NetBase64Codec::decode(encoded, decoded); sprintf(msg, "\n test case %d decoding %s" "\n expected size %d data '%s'" "\n actual size %d data '%s'", test, decodedOk ? "ok" : "failed", tests[test].inputSize, tests[test].inputData, decoded.length(), decoded.data() ); CPPUNIT_ASSERT_MESSAGE(msg, ( decodedOk && (decoded.length() == tests[test].inputSize) && (memcmp(tests[test].inputData, decoded.data(), tests[test].inputSize ) == 0) )); } }
bool ZoneAdminRpcMethod::buildOutputFiles(const UtlString& command, UtlString& stdoutfn, UtlString& stderrfn ) { bool result = true; stdoutfn.remove(0); stderrfn.remove(0); stdoutfn.append(ZoneAdminGenerate_cmd); stderrfn.append(ZoneAdminGenerate_cmd); stderrfn.append(ZoneAdminStdErr_filetype); stdoutfn.append(ZoneAdminStdOut_filetype); return result; }
OsStatus ForwardRules::getRouteTo(UtlString& RouteToString, bool& authRequired, TiXmlNode* nodeWithRouteToChild) { OsStatus currentStatus = OS_FAILED; nodeWithRouteToChild->ToElement(); TiXmlNode* routeToNode = NULL; TiXmlNode* routeToText = NULL; //get the user text value from it routeToNode = nodeWithRouteToChild->FirstChild(XML_TAG_ROUTETO); if(routeToNode) { if(routeToNode && routeToNode->Type() != TiXmlNode::ELEMENT) { return currentStatus; } TiXmlElement* routeToElement = routeToNode->ToElement(); const char* authRequiredPtr = routeToElement->Attribute(XML_ATT_AUTHREQUIRED); //set the authRequired attribute authRequired=getYN(authRequiredPtr, false) ; //defaults to false RouteToString.remove(0); routeToText = routeToElement->FirstChild(); if(routeToText && routeToText->Type() == TiXmlNode::TEXT) { TiXmlText* routeTo = routeToText->ToText(); if (routeTo) { RouteToString.append(routeTo->Value()); } } // TinyXML compresses white space, so an all white space element becomes // zero length, but just in case, let's strip it ourselves. RouteToString.strip(UtlString::both); if (RouteToString.length() > 0) { // The route is not empty. Declare success currentStatus = OS_SUCCESS; } else if (authRequired) { // The Route can be empty, as long as authRequired is set. // This means just route to the authProxy. currentStatus = OS_SUCCESS; } else { // Empty or missing route, and no authRequired...that's not allowed. currentStatus = OS_FAILED; } } return currentStatus; }
OsStatus OsFileBase::readLine(UtlString &str) { #ifdef DEBUG_FS pthread_t nTaskId = 0; OsTask* pTask = OsTask::getCurrentTask(); if (pTask) pTask->id(nTaskId); Os::Logger::instance().log(FAC_KERNEL, PRI_DEBUG, "OsFileBase::readLine ENTER threadid=%ld\n", nTaskId); #endif char buf[2]; size_t bytesRead; OsStatus retstat = OS_INVALID; buf[1] = '\0'; str.remove(0); do { retstat = read(buf, 1, bytesRead); if (retstat == OS_SUCCESS && (*buf != '\n' && *buf != '\r')) { str.append(buf, 1); } } while (retstat == OS_SUCCESS && bytesRead == 1 && *buf != '\n'); #ifdef DEBUG_FS Os::Logger::instance().log(FAC_KERNEL, PRI_DEBUG, "OsFileBase::readLine EXIT threadid=%ld\n", nTaskId); #endif return retstat; }
OsStatus CpPhoneMediaInterface::playAudio(const char* url, UtlBoolean repeat, UtlBoolean local, UtlBoolean remote) { OsStatus returnCode = OS_NOT_FOUND; UtlString urlString; if(url) urlString.append(url); int fileIndex = urlString.index("file://"); if(fileIndex == 0) urlString.remove(0, 6); if(mpFlowGraph && !urlString.isNull()) { // Start playing the audio file returnCode = mpFlowGraph->playFile(urlString.data(), repeat, remote ? MpCallFlowGraph::TONE_TO_NET : MpCallFlowGraph::TONE_TO_SPKR); } if(returnCode != OS_SUCCESS) { osPrintf("Cannot play audio file: %s\n", urlString.data()); } return(returnCode); }
bool SessionContext::getMediaRelayAddressToUseInSdp( UtlString& mediaRelayAddressToUse, EndpointRole endpointRole ) const { bool bUseNativeMediaRelayIpAddress = false; mediaRelayAddressToUse.remove( 0 ); if( mpMediaRelay->isPartOfsipXLocalPrivateNetwork() ) { // if both the receiver of the SDP and the media relay are located with the // same network, use the media relay's native IP address in the SDP, otherwise // use its public. EndpointDescriptor* pSdpRecipient = ( endpointRole == CALLER ? mpCallee : mpCaller ); if( pSdpRecipient->getLocationCode() == LOCAL_NATED ) { mediaRelayAddressToUse = mpMediaRelay->getNativeAddress(); bUseNativeMediaRelayIpAddress = true; } else { mediaRelayAddressToUse = mpMediaRelay->getPublicAddress(); } } else { mediaRelayAddressToUse = mpMediaRelay->getPublicAddress(); } return bUseNativeMediaRelayIpAddress; }
bool NatTraversalRules::StunClient::getPublicIpAddress( UtlString& discoveredPublicIpAddress ) { bool rc = false; // Not yet resolved the STUN server to a valid IP address, try again in case // network conditions have cleared. if( !mbStunServerIsValid ) { mbStunServerIsValid = stunQueryAgent.setServer( mStunServerName ); } if( mbStunServerIsValid ) { UtlString mappedAddress; int mappedPort; OsTime timeout( STUN_QUERY_TIMEOUT_IN_MILLISECS ); rc = stunQueryAgent.getMappedAddress( &mSocket, mappedAddress, mappedPort, 0, timeout ); if( rc ) { discoveredPublicIpAddress = mappedAddress; Os::Logger::instance().log(FAC_NAT,PRI_INFO,"StunClient::getPublicIpAddress obtained public IP address %s from server %s", mappedAddress.data(), mStunServerName.data() ); } else { discoveredPublicIpAddress.remove( 0 ); Os::Logger::instance().log(FAC_NAT,PRI_ERR,"StunClient::getPublicIpAddress failed to obtain mapping from server %s", mStunServerName.data() ); } } return rc; }
void testChar2Utl() { UtlString encoded; char msg[2048]; for (unsigned int test = 0; test < (sizeof(tests)/sizeof(TestData)); test++) { encoded.remove(0); NetBase64Codec::encode(tests[test].inputSize, tests[test].inputData, encoded ); sprintf(msg, "\n test case %d encoding" "\n expected size %d data '%s'" "\n actual size %d data '%s'", test, strlen(tests[test].output), tests[test].output, encoded.length(), encoded.data() ); CPPUNIT_ASSERT_MESSAGE(msg, ( (encoded.length() == strlen(tests[test].output)) && (encoded.compareTo(tests[test].output) == 0) )); } }
int OsDatagramSocket::read(char* buffer, int bufferLength) { int bytesRead; // If the remote end is not "connected" we cannot use recv if(mSimulatedConnect || !portIsValid(remoteHostPort) || remoteHostName.isNull()) { #ifdef GETFROMINFO /* [ */ if (GETFROMINFO) { int fromPort; UtlString fromAddress; bytesRead = OsSocket::read(buffer, bufferLength, &fromAddress, &fromPort); fromAddress.remove(0); } else #endif /* GETFROMINFO ] */ { bytesRead = OsSocket::read(buffer, bufferLength, (struct in_addr*) NULL, NULL); } } else { bytesRead = OsSocket::read(buffer, bufferLength); } return(bytesRead); }
void CommandProcessor::parseCommandLine(const char* commandLine, int* argc, char*** argv) { UtlString arg; int argIndex = 0; // Hard code length for now; *argv = new char*[1024]; *argc = 0; if(commandLine) { //printf("creating tokenizer\n"); UtlTokenizer tokenizer(commandLine); do { arg.remove(0); tokenizer.next(arg, " \t\n"); //printf("arg[%d]=\"%s\"\n", argIndex, arg.data()); if(!arg.isNull()) { (*argv)[argIndex] = new char[strlen(arg.data()) + 1]; strcpy((*argv)[argIndex], arg.data()); argIndex++; } } while(!arg.isNull()); } *argc = argIndex; }
void sipXTabbedCodecPage::OnSelect(wxCommandEvent &event) { wxArrayInt selections; UtlString s; int index; if (!mbCodecByName) { int numSels = mpCodecList->GetSelections(selections); if (numSels) { mCodecName = ""; for (int i=0; i<numSels; i++) { s = mpCodecList->GetString(selections[i]); if ((index = s.index(" ")) != UTL_NOT_FOUND) { // Only get name up to first space s = s.remove(index, s.length() - index); } mCodecName = mCodecName + s + " "; } mbCodecByName = true; mpCodecPref->Append("By name:"); mpCodecPref->SetSelection(3); mCodecPref = 3; sipXmgr::getInstance().setAudioCodecByName((const char *)mCodecName.data()); rebuildCodecList(0); } } }
void CallId::getNewCallId(const char* callIdPrefix, UtlString& callId) { // Lock to protect common variables. OsLock lock(sCallIdMutex); // Increment the call number. sCallNum += 1; // callID prefix shouldn't contain an @. if (strchr(callIdPrefix, '@') != NULL) { OsSysLog::add(FAC_SIP, PRI_ERR, "CallId::getNewCallId callIdPrefix='%s' contains '@'", callIdPrefix); } // Compute the next value. nextValue(""); // Compose the new Call-Id. char buffer[256]; sprintf(buffer, "%s-%.*s-%d", callIdPrefix, CALL_ID_CHAIN_VALUE_REVEALED, sChainValue.data(), sCallNum); // Copy it to the destination. callId.remove(0); callId.append(buffer); }
/// Copies the element into the provided UtlString bool CallStateEventBuilder_XML::finishElement(UtlString& event) /**< * @returns * - true if the returned element is validly constructed * - false if not (a caller error) */ { bool isComplete = mEventComplete; event.remove(0); if (isComplete) { event.append(mCurrentEvent); event.append(mCallInfo); event.append(mLaterElement); event.append(mViaHeader); event.append(mEndElement); event.append(CallEventElementEnd); event.append('\n'); reset(); } return isComplete; }
/// Copies the element into the provided UtlString bool CallStateEventBuilder_DB::finishElement(UtlString& event) /**< * @returns * - true if the returned element is validly constructed * - false if not (a caller error) */ { bool isComplete = mEventComplete; event.remove(0); if (isComplete) { event.append(mCurrentEvent); event.append(mCallInfo); event.append(mContactElement); event.append(mReferElement); event.append(mFailureElement); event.append(mRequestUri); event.append(mReferences); event.append(mCallerInternal); event.append(mCalleeRoute); event.append(mBranchId); event.append(mViaCount); event.append(");"); reset(); } return isComplete; }
UtlBoolean SipLine::matchesUserId(const char* szUserId) const { UtlString matchUserId(szUserId) ; UtlString lineUserId ; UtlString host ; UtlBoolean bMatch = false ; // First, try identify mIdentity.getUserId(lineUserId); mIdentity.getHostAddress(host) ; // if host is empty, assume invalid line if (!host.isNull() && matchUserId.compareTo(lineUserId) == 0) // Case sensitive { bMatch = true ; } else { // Next, try preferred contact lineUserId.remove(0) ; mPreferredContactUri.getUserId(lineUserId) ; host.remove(0); mPreferredContactUri.getHostAddress(host) ; // if host is empty, assume invalid line if (!host.isNull() && matchUserId.compareTo(lineUserId) == 0) // Case sensitive { bMatch = true ; } } // Finally, try aliases for (size_t i=0; !bMatch && i<mAliases.entries(); i++) { UtlString* pAlias = (UtlString*) mAliases.at(i) ; assert(pAlias != NULL) ; if (pAlias != NULL) { Url aliasUrl(pAlias->data()) ; lineUserId.remove(0) ; aliasUrl.getUserId(lineUserId) ; host.remove(0); aliasUrl.getHostAddress(host) ; // if host is empty, assume invalid line if (!host.isNull() && matchUserId.compareTo(lineUserId) == 0) // Case sensitive { bMatch = true ; } } } return bMatch; }
bool SwAdminRpcMethod::buildOutputFiles(const UtlString& command, UtlString& stdoutfn, UtlString& stderrfn ) { bool result = true; stdoutfn.remove(0); stderrfn.remove(0); if ( command.compareTo(SwAdminVersion_cmd, UtlString::ignoreCase) == 0) { stdoutfn.append(SwAdminVersion_cmd); stderrfn.append(SwAdminVersion_cmd); } else if ( command.compareTo(SwAdminCheckUpdate_cmd, UtlString::ignoreCase) == 0) { stdoutfn.append(SwAdminCheckUpdate_cmd); stderrfn.append(SwAdminCheckUpdate_cmd); } else if ( command.compareTo(SwAdminUpdate_cmd, UtlString::ignoreCase) == 0) { stdoutfn.append(SwAdminUpdate_cmd); stderrfn.append(SwAdminUpdate_cmd); } else if ( command.compareTo(SwAdminRestart_cmd, UtlString::ignoreCase) == 0) { stdoutfn.append(SwAdminRestart_cmd); stderrfn.append(SwAdminRestart_cmd); } else if ( command.compareTo(SwAdminReboot_cmd, UtlString::ignoreCase) == 0) { stdoutfn.append(SwAdminReboot_cmd); stderrfn.append(SwAdminReboot_cmd); } else { return false; } stderrfn.append(SwAdminStdErr_filetype); stdoutfn.append(SwAdminStdOut_filetype); return result; }
UtlBoolean HttpRequestContext::getCgiVariable(int index, UtlString& name, UtlString& value) const { NameValuePair* nameValuePair = NULL; name.remove(0); value.remove(0); if((int)(mCgiVariableList.entries()) > index && index >= 0) { nameValuePair = (NameValuePair*)mCgiVariableList.at(index); if(nameValuePair) { name = *nameValuePair; value.append(nameValuePair->getValue()); } } return(nameValuePair != NULL); }
void HttpRequestContext::extractPostCgiVariables(const HttpBody& body) { int length; UtlString bodyBytes; body.getBytes(&bodyBytes, &length); parseCgiVariables(bodyBytes.data()); bodyBytes.remove(0); }
//: Dumps the log out using osPrintf void OsTimeLog::dumpLog() const { UtlString log; getLogString(log); osPrintf("%s", log.data()); log.remove(0); }
/// Set to the unique library name void TestPlugin::pluginName(UtlString& name) const { assert(mConfigured); name.remove(0); name.append(LibraryName); name.append("::"); name.append(mInstanceName); }
void SipRedirectorJoin::textContentDeep(UtlString& string, TiXmlElement *element) { // Clear the string. string.remove(0); // Recurse into the XML. textContentDeepRecursive(string, element); }
OsStatus SipRedirectorFallback::determineCallerLocationFromProvisionedUserLocation( const SipMessage& message, UtlString& callerLocation ) { OsStatus result = OS_FAILED; callerLocation.remove( 0 ); // First, determine the identity of the caller. This is done by looking for // a properly signed P-Asserted identity in the request message. // If the request contains a P-Asserted-Identity header and is not signed, // we will not trust it the returned location will be blank. UtlString matchedIdentityHeader; SipXauthIdentity sipxIdentity; Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipRedirectorFallback:: unbound entities allowing: %s", mAllowUnbound ? "TRUE" : "FALSE"); if (!mAllowUnbound) { SipXauthIdentity sipxIdentity( message, matchedIdentityHeader, false ); } else { SipXauthIdentity sipxIdentity( message, matchedIdentityHeader, false, SipXauthIdentity::allowUnbound); } if( !matchedIdentityHeader.isNull() ) { UtlString authenticatedUserIdentity; bool bRequestIsAuthenticated; bRequestIsAuthenticated = sipxIdentity.getIdentity( authenticatedUserIdentity ); if( bRequestIsAuthenticated ) { // we now have the autheticated identity of the caller. Look up the user location // database to find out the location that is mapped to it. //ResultSet userLocationsResult; // Check in User Location database if user has locations //mpUserLocationDbInstance->getLocations( authenticatedUserIdentity, userLocationsResult ); // Get the caller's site location. Only the first returned location is used. // This is not a problem given that a user should only belong to one location. EntityRecord entity; EntityDB* entityDb = SipRegistrar::getInstance(NULL)->getEntityDB(); if (entityDb->findByIdentity(authenticatedUserIdentity.str(), entity)) { callerLocation = entity.location().c_str(); result = OS_SUCCESS; Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::determineCallerLocationFromProvisionedUserLocation mapped user '%s' taken from header '%s' to location '%s' based on its provisioned location", mLogName.data(), authenticatedUserIdentity.data(), authenticatedUserIdentity.data(), entity.location().c_str() ); } } } return result; }
/// Translate a file pattern into a regular expression bool DirectoryResource::pattern2RegEx(const UtlString& pattern, UtlString& patternExpression) { patternExpression.remove(0); RegEx regularExpressionSpecial(RegularExpressionSpecial); ssize_t patternPosition = 0; ssize_t nextSpecialPosition; while ( regularExpressionSpecial.SearchAt(pattern, patternPosition) ) { nextSpecialPosition = regularExpressionSpecial.MatchStart(0); char nextSpecial = pattern(nextSpecialPosition); if ( nextSpecialPosition == patternPosition ) { if ( nextSpecial == '*' ) { patternExpression.append( (patternPosition == 0) ? InitialWildcardRegexp : InsideWildcardRegexp ); patternPosition++; } else { // all other characters that are significant in a regexp are escaped patternExpression.append("\\"); patternExpression.append(nextSpecial); patternPosition++; } } else { ssize_t fixedPartLength = nextSpecialPosition - patternPosition; patternExpression.append(pattern, patternPosition, fixedPartLength); patternPosition += fixedPartLength; /* * We have not incremented past the special, so we will match it again on * the next iteration; this avoids having to duplicate the checks for * whether it is '*' or some other regular expression character here */ } } // append any fixed part that follows the last wildcard if ((size_t)patternPosition < pattern.length()) { patternExpression.append( pattern, patternPosition, UTLSTRING_TO_END ); } Os::Logger::instance().log(FAC_SUPERVISOR, PRI_DEBUG, "DirectoryResource::patternRegEx( '%s' ) -> '%s'", pattern.data(), patternExpression.data() ); return ! patternExpression.isNull(); }
//! Get the information from resource in a resource list specified // by its position in the list. void ResourceList::getResourceInfoAt(size_t at, UtlString& uri, UtlString& nameXml, UtlString& display_name) { uri.remove(0); nameXml.remove(0); display_name.remove(0); ResourceReference* resource = dynamic_cast <ResourceReference*> (mResourcesList.at(at)); if (resource) { uri = *resource->getUri(); nameXml = *resource->getNameXml(); display_name = *resource->getDisplayName(); } }
TaoStatus TaoEvent::getStringData(UtlString& data) { if (!mStringData.isNull()) { data.remove(0); data.append(mStringData.data()); } return TAO_SUCCESS; }
void SipTransactionList::toString(UtlString& string) { lock(); string.remove(0); UtlHashBagIterator iterator(mTransactions); SipTransaction* transactionFound = NULL; UtlString oneTransactionString; while((transactionFound = (SipTransaction*) iterator())) { transactionFound->toString(oneTransactionString, FALSE); string.append(oneTransactionString); oneTransactionString.remove(0); } unlock(); }