void SipRedirectorMPT::writeMappings(UtlString* file_name, UtlHashMap* mapUserToContacts) { UtlString temp_file_name; FILE* f; temp_file_name = *file_name; temp_file_name.append(".new"); f = fopen(temp_file_name.data(), "w"); if (f == NULL) { OsSysLog::add(FAC_SIP, PRI_CRIT, "%s::writeMappings fopen('%s') failed, errno = %d '%s'", mLogName.data(), temp_file_name.data(), errno, strerror(errno)); } else { mMapLock.acquire(); fprintf(f, "<MPT>\n"); UtlHashMapIterator itor(*mapUserToContacts); UtlContainable* c; while ((c = itor())) { UtlString* k = dynamic_cast<UtlString*> (c); UtlString k_escaped; XmlEscape(k_escaped, *k); UtlString* v = dynamic_cast<UtlString*> (mapUserToContacts->findValue(c)); UtlString v_escaped; XmlEscape(v_escaped, *v); fprintf(f, " <map><user>%s</user><contacts>%s</contacts></map>\n", k_escaped.data(), v_escaped.data()); } fprintf(f, "</MPT>\n"); fclose(f); mMapsModified = FALSE; mMapLock.release(); if (rename(temp_file_name.data(), file_name->data()) != 0) { OsSysLog::add(FAC_SIP, PRI_CRIT, "%s::writeMappings rename('%s', '%s') failed, errno = %d '%s'", mLogName.data(), temp_file_name.data(), file_name->data(), errno, strerror(errno)); } } }
void SipRedirectorGateway::writeMappings(UtlString* file_name, UtlHashMap* mapUserToContacts) { UtlString temp_file_name; FILE* f; temp_file_name = *file_name; temp_file_name.append(".new"); f = fopen(temp_file_name.data(), "w"); if (f == NULL) { Os::Logger::instance().log(FAC_SIP, PRI_CRIT, "%s::writeMappings fopen('%s') failed, errno = %d", mLogName.data(), temp_file_name.data(), errno); } else { mMapLock.acquire(); fprintf(f, "<Gateway>\n"); UtlHashMapIterator itor(*mapUserToContacts); UtlContainable* c; while ((c = itor())) { UtlString* k = dynamic_cast<UtlString*> (c); UtlString k_escaped; XmlEscape(k_escaped, *k); UtlString* v = dynamic_cast<UtlString*> (mapUserToContacts->findValue(c)); UtlString v_escaped; XmlEscape(v_escaped, *v); fprintf(f, " <map><prefix>%s</prefix><hostpart>%s</hostpart></map>\n", k_escaped.data(), v_escaped.data()); } fprintf(f, "</Gateway>\n"); fclose(f); mMapsModified = FALSE; mMapLock.release(); if (rename(temp_file_name.data(), file_name->data()) != 0) { Os::Logger::instance().log(FAC_SIP, PRI_CRIT, "%s::writeMappings rename('%s', '%s') failed, errno = %d", mLogName.data(), temp_file_name.data(), file_name->data(), errno); } } }
/** * Requires: * - callRequestEvent * - addCallData (the toTag in the addCallRequest will be a null string) * - addEventVia (at least for via index zero) * - completeCallEvent */ void CallStateEventBuilder_XML::callRequestEvent(int sequenceNumber, const OsTime& timestamp, ///< obtain using getCurTime(OsTime) const UtlString& contact, const UtlString& references, const UtlString& branch_id, int via_count, const bool callerInternal ) { if (builderStateIsOk(CallRequestEvent)) { newEvent(sequenceNumber, timestamp, CallRequestElementStart); mLaterElement.append(ContactElementStart); XmlEscape(mLaterElement, contact); mLaterElement.append(ContactElementEnd); mEndElement = CallRequestElementEnd; } else { assert(false); OsSysLog::add(FAC_SIP, PRI_ERR, "CallStateEventBuilder_XML::callRequestEvent not allowed."); } }
/** * Requires: * - callFailureEvent * - addCallData * - addEventVia (at least for via index zero) * - completeCallEvent */ void CallStateEventBuilder_XML::callFailureEvent(int sequenceNumber, const OsTime& timestamp, ///< obtain using getCurTime(OsTime) const UtlString& branch_id, int via_count, int statusCode, const UtlString& statusMsg ) { if (builderStateIsOk(CallFailureEvent)) { newEvent(sequenceNumber, timestamp, CallFailureElementStart); mLaterElement.append(Response_Status_Start); char sc[11]; sprintf(sc, "%d", statusCode); mLaterElement.append(sc); mLaterElement.append(StatusEnd_ReasonStart); XmlEscape(mLaterElement, statusMsg); mLaterElement.append(Reason_Response_End); mEndElement = CallFailureElementEnd; } else { assert(false); OsSysLog::add(FAC_SIP, PRI_ERR, "CallStateEventBuilder_XML::callFailureEvent not allowed."); } }
//--------------------------------------------------------------------------- void TActionLog::AddMessages(const UnicodeString & Indent, TStrings * Messages) { for (intptr_t Index = 0; Index < Messages->GetCount(); ++Index) { AddIndented( FORMAT((Indent + L"<message>%s</message>").c_str(), XmlEscape(Messages->GetString(Index)).c_str())); } }
void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& result) { os << ">\n"; // close <test> element typedef DeferredTestResult::FailureVec::const_iterator FailureIterator; for (FailureIterator it = result.failures.begin(); it != result.failures.end(); ++it) { string const escapedMessage = XmlEscape(it->second); string const message = BuildFailureMessage(result.failureFile, it->first, escapedMessage); os << "\t\t<failure" << " message=\"" << message << "\"" << "/>\n"; } }
/// Add the dialog and call information for the event being built. void CallStateEventBuilder_XML::addCallData(const int cseqNumber, const UtlString& callId, const UtlString& fromTag, /// may be a null string const UtlString& toTag, /// may be a null string const UtlString& fromField, const UtlString& toField ) { if (builderStateIsOk(AddCallData)) { mCallInfo.append(Call_Dialog_CallId_Start); XmlEscape(mCallInfo, callId); mCallInfo.append(CallIdEnd); if (!fromTag.isNull()) { mCallInfo.append(FromTagStart); XmlEscape(mCallInfo, fromTag); mCallInfo.append(FromTagEnd); } if (!toTag.isNull()) { mCallInfo.append(ToTagStart); XmlEscape(mCallInfo, toTag); mCallInfo.append(ToTagEnd); } mCallInfo.append(DialogEnd_FromFieldStart); XmlEscape(mCallInfo, fromField); mCallInfo.append(FromFieldEnd_ToFieldStart); XmlEscape(mCallInfo, toField); mCallInfo.append(ToField_CallEnd); } else { assert(false); OsSysLog::add(FAC_SIP, PRI_ERR, "CallStateEventBuilder_XML::callEndEvent not allowed."); } }
void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& result) { os << ">"; // close <test> element for (DeferredTestResult::FailureVec::const_iterator it = result.failures.begin(); it != result.failures.end(); ++it) { string const escapedMessage = XmlEscape(it->second); string fileNoPath = extractFileName(result.failureFile); string const message = BuildFailureMessage(fileNoPath, it->first, escapedMessage); os << "<failure" << " message=\"" << message << "\"" << "/>"; } }
/** * Record a Via from the message for this event * Calls to this routine are in reverse cronological order - the last * call for an event should be the via added by the message originator */ void CallStateEventBuilder_XML::addEventVia(const UtlString& via ) { if (builderStateIsOk(AddVia)) { // construct the element locally UtlString viaElement; viaElement.append(ViaStart); XmlEscape(viaElement, via); viaElement.append(ViaEnd); // prepend it to the recorded vias so that the first one is first mViaHeader.prepend(viaElement); } else { assert(false); OsSysLog::add(FAC_SIP, PRI_ERR, "CallStateEventBuilder_XML::callEndEvent not allowed."); } }
void CallStateEventBuilder_XML::newEvent(int sequenceNumber, const OsTime& timestamp, ///< obtain using getCurTime(OsTime) const char* elementStart ) { // assemble the parts common to all events mCurrentEvent = CallEvent_Observer_Start; XmlEscape(mCurrentEvent, observerName); mCurrentEvent.append(ObserverEnd_ObsSeqStart); char sn[11]; sprintf(sn, "%d", sequenceNumber); mCurrentEvent.append(sn); mCurrentEvent.append(ObsSeqEnd_ObsTimeStart); OsDateTime timeValue(timestamp); UtlString timeString; timeValue.getIsoTimeStringZ(timeString); mCurrentEvent.append(timeString); // this format has nothing to escape mCurrentEvent.append(ObsTimeEnd); // add the start tag for the new element mCurrentEvent.append(elementStart); }
/** * Generate a metadata event. * This method generates a complete event - it does not require that the callEventComplete method be called. */ void CallStateEventBuilder_XML::observerEvent(int sequenceNumber, ///< for ObserverReset, this should be zero const OsTime& timestamp, ///< obtained using getCurTime(OsTime) ObserverEvent eventCode, const char* eventMsg ///< for human consumption ) { BuilderMethod eventMethod; switch (eventCode) { case ObserverReset: reset(); // because this event is ok any time, clear out any partial event. eventMethod = BuilderReset; break; default: assert(false); OsSysLog::add(FAC_SIP, PRI_ERR, "observerEvent: invalid eventCode %d", eventCode); eventMethod = InvalidEvent; break; } if (builderStateIsOk(eventMethod)) { newEvent(sequenceNumber, timestamp, ObsMsgStart); char ec[11]; sprintf(ec, "%d", eventCode); mCurrentEvent.append(ec); mCurrentEvent.append(ObsMsgMiddle); XmlEscape(mCurrentEvent, eventMsg); mCurrentEvent.append(ObsText_Schema_ObsMsg_End); mEventComplete = true; } else { assert(false); OsSysLog::add(FAC_SIP, PRI_ERR, "observerEvent: %d not allowed.", eventCode); } }
// Add to the HttpBody the current state of the resource. void ResourceCached::generateBody(UtlString& rlmi, HttpBody& body, UtlBoolean consolidated, const UtlString& nameXml, const UtlString& displayName) const { // Generate the preamble for the resource. rlmi += " <resource uri=\""; XmlEscape(rlmi, *(static_cast <const UtlString*> (this))); rlmi += "\">\r\n"; if (!nameXml.isNull()) { rlmi += " "; rlmi += nameXml; } if (consolidated) { // If consolidating resource instances, generate the XML for the // unified resource instance. rlmi += " <instance id=\"consolidated\" state=\"active\""; UtlString contentBodyPartCid; // Use the count of parts in 'body' to generate a unique identifier for // each part. contentBodyPartCid.appendNumber(body.getMultipartCount()); contentBodyPartCid += "@"; contentBodyPartCid += getResourceListServer()->getDomainName(); rlmi += " cid=\""; rlmi += contentBodyPartCid; rlmi += "\""; // Now add the <...> and use it in the header. contentBodyPartCid.prepend("<"); contentBodyPartCid.append(">"); // Create a single HttpBody to contain the unified dialog event. UtlString dialog_event; // XML declaration is optional, but Broadworks uses it. dialog_event += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; dialog_event += BEGIN_DIALOG_INFO; dialog_event += VERSION_EQUAL; dialog_event += "\""; // The consolidated dialog events need to have persistent // version numbers, as they all have the same instance id. // So we use a global version number in the ResourceListSet. dialog_event.appendNumber(getResourceListSet()->getVersion()); dialog_event += "\""; dialog_event += STATE_EQUAL; dialog_event += "\"full\""; dialog_event += ENTITY_EQUAL; dialog_event += "\""; dialog_event += *(static_cast <const UtlString*> (this)); dialog_event += "\">\r\n"; // Save the length of dialog_event, so we can tell later if // any <dialog>s have been added to it. unsigned int preamble_length = dialog_event.length(); // Call the ContactSet to generate the consolidated dialog event body. if (mContactSetP) { mContactSetP->generateBody(dialog_event, body, consolidated, displayName); } // If no <dialog>s have been added, we have to add a dummy // <dialog> to carry the display name. if (dialog_event.length() == preamble_length) { dialog_event += "<dialog id=\";\"><state>terminated</state><local><identity display=\""; XmlEscape(dialog_event, displayName); dialog_event += "\">"; XmlEscape(dialog_event, *(static_cast <const UtlString*> (this))); dialog_event += "</identity></local></dialog>\r\n"; } dialog_event += END_DIALOG_INFO; // Insert the consolidated dialog event body into the multiplart body. HttpBody content_body(dialog_event.data(), dialog_event.length(), DIALOG_EVENT_CONTENT_TYPE); UtlDList content_body_parameters; content_body_parameters.append( new NameValuePair(HTTP_CONTENT_ID_FIELD, contentBodyPartCid)); body.appendBodyPart(content_body, content_body_parameters); content_body_parameters.destroyAll(); // Finish the <instance> element. rlmi += "/>\r\n"; } else { // Call the ContactSet to do the work. if (mContactSetP) { mContactSetP->generateBody(rlmi, body, consolidated, displayName); } } // Generate the postamble for the resource. rlmi += " </resource>\r\n"; }
//! Generate the HttpBody for the current state of the resource list. HttpBody* ResourceList::generateRlmiBody(UtlBoolean consolidated, UtlBoolean fullRlmi, UtlSList& listToSend) { if (Os::Logger::instance().willLog(FAC_RLS, PRI_DEBUG)) { UtlString l; UtlSListIterator resourcesItor(listToSend); ResourceReference* resource; while ((resource = dynamic_cast <ResourceReference*> (resourcesItor()))) { l.append(*resource->getUri()); l.append(","); } if (!l.isNull()) { l.remove(l.length() - 1); } Os::Logger::instance().log(FAC_RLS, PRI_DEBUG, "ResourceList::generateRlmiBody cons=%d URI='%s' full=%d listToSend='%s'", consolidated, (consolidated ? mResourceListNameCons.data() : mResourceListName.data()), fullRlmi, l.data()); } // Construct the multipart body. // We add the <...> here, as they are used in all the contexts where // rlmiBodyPartCid appears. UtlString rlmiBodyPartCid; rlmiBodyPartCid += "<rlmi@"; rlmiBodyPartCid += getResourceListServer()->getDomainName(); rlmiBodyPartCid += ">"; UtlString content_type(CONTENT_TYPE_MULTIPART_RELATED ";type=\"" RLMI_CONTENT_TYPE "\"" ";start=\""); content_type += rlmiBodyPartCid; content_type += "\""; HttpBody* body = new HttpBodyMultipart(content_type); // This is the Resource List Meta-Information, XML describing the resources // and their instances. It is the main part of the NOTIFY body. UtlString rlmi; // Generate the initial part of the RLMI. rlmi += "<?xml version=\"1.0\"?>\r\n"; rlmi += "<list xmlns=\"" RLMI_XMLNS "\" uri=\""; XmlEscape(rlmi, consolidated ? mResourceListNameCons : mResourceListName); // Placeholder for version from SIP stack. rlmi += "\" version=\"" VERSION_PLACEHOLDER "\" "; // Generate either the full or the partial RLMI. if (fullRlmi) { rlmi += "fullState=\"true\">\r\n"; } else { rlmi += "fullState=\"false\">\r\n"; } // If we implemented names for resource lists, <name> elements would be added here. // Iterate through the resources. UtlSListIterator resourcesItor(listToSend); ResourceReference* resource; while ((resource = dynamic_cast <ResourceReference*> (resourcesItor()))) { // Add the content for the resource. resource->generateBody(rlmi, *body, consolidated); } // Generate the postamble for the resource list. rlmi += "</list>\r\n"; // Construct the RLMI body part. HttpBody rlmi_body(rlmi.data(), rlmi.length(), RLMI_CONTENT_TYPE); UtlDList rlmi_body_parameters; rlmi_body_parameters.append(new NameValuePair(HTTP_CONTENT_ID_FIELD, rlmiBodyPartCid)); // Attach the RLMI. body->appendBodyPart(rlmi_body, rlmi_body_parameters); // Clean up the parameter list. rlmi_body_parameters.destroyAll(); return body; }
OsStatus NotificationHelper::send ( const UtlString& rMailboxIdentity, const UtlString& rSMTPServer, const Url& mailboxServiceUrl, const UtlString& rContact, const UtlString& rFrom, const UtlString& rReplyTo, const UtlString& rDate, const UtlString& rDurationMSecs, const UtlString& wavFileName, const char* pAudioData, const int& rAudioDatasize, const UtlBoolean& rAttachmentEnabled) const { OsStatus status = OS_SUCCESS; // For forwarded messages, duration = aggregate of duration of different // messages that make up the forwarded message. // Skip duration for forwarded messages in this release (1.1). UtlString durationText = "" ; if( !wavFileName.contains("-FW") ) { durationText += "Duration " ; int iDuration = atoi(rDurationMSecs); if( iDuration > 0 ) { // Convert to seconds iDuration = iDuration / 1000; char temp[10]; if( iDuration >= 3600 ) { // Retrieve the hour. int hours = iDuration / 3600 ; iDuration = iDuration - (hours * 3600); sprintf( temp, "%02d", hours ); durationText = UtlString( temp ) + ":" ; } if( iDuration >= 60 ) { // Retrieve the hour. int mins = iDuration / 60 ; iDuration = iDuration - (mins * 60); sprintf( temp, "%02d", mins ); durationText += UtlString( temp ) + ":" ; } else { durationText += "00:" ; } // append the seconds sprintf( temp, "%02d", iDuration ); durationText += temp; } else { durationText = UtlString("00:00") ; } } UtlString strFrom = "Unknown" ; if( !rFrom.isNull() && rFrom.length() > 0) strFrom = rFrom ; UtlString subject = "New Voicemail from " + strFrom ; UtlString rawMessageId = wavFileName(0, wavFileName.first('-')); UtlString userId = rMailboxIdentity(0, rMailboxIdentity.first('@')); UtlString plainBodyText, htmlBodyText; MailMessage message ( "Voicemail Notification Service", rReplyTo, rSMTPServer ); UtlString baseMailboxLink = mailboxServiceUrl.toString(); baseMailboxLink.append("/").append(userId).append("/inbox"); UtlString playMessageLink = baseMailboxLink; playMessageLink.append("/").append(rawMessageId); UtlString deleteMessageLink = baseMailboxLink; deleteMessageLink.append("/").append(rawMessageId).append("/delete"); UtlString showMailboxLink = baseMailboxLink; plainBodyText += "On " + rDate + ", " + strFrom + " left new voicemail. " + durationText + "\n"; plainBodyText += "Listen to message " + playMessageLink + "\n"; plainBodyText += "Show Voicemail Inbox " + showMailboxLink + "\n"; plainBodyText += "Delete message " + deleteMessageLink + "\n"; UtlString playMessageLinkXml ; UtlString deleteMessageLinkXml; UtlString showMailboxLinkXml; XmlEscape(playMessageLinkXml, playMessageLink) ; XmlEscape(deleteMessageLinkXml, deleteMessageLink) ; XmlEscape(showMailboxLinkXml, showMailboxLink) ; // Format the html text if supported by the browser htmlBodyText = (UtlString)"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n" + " \"http://www.w3.org/TR/html4/strict.dtd\">\n" + "<HTML>\n" + "<HEAD>\n" + "<TITLE>Voicemail Notification</TITLE>\n" + "</HEAD>\n<BODY>\n"; htmlBodyText += "<p>On " + rDate + ", " + strFrom + " left new voicemail. " + durationText + "</p>\n"; htmlBodyText += "<p><a href=\"" + playMessageLinkXml + "\">Listen to message</a></p>\n"; htmlBodyText += "<p><a href=\"" + showMailboxLinkXml + "\">Show Voicemail Inbox</a></p>\n"; htmlBodyText += "<p><a href=\"" + deleteMessageLinkXml + "\">Delete message</a></p>\n"; htmlBodyText += (UtlString)"</BODY>\n" + "</HTML>\n"; if ( rAttachmentEnabled == TRUE ) { unsigned char* unsignedAudioData = (unsigned char*) pAudioData; message.Attach( unsignedAudioData, rAudioDatasize, wavFileName); } message.Body( plainBodyText , htmlBodyText ); message.Subject( subject ); message.To( rContact, rContact ); UtlString response = message.Send(); if ( !response.isNull() ) { if( response.length() > 0 ) { OsSysLog::add(FAC_MEDIASERVER_CGI, PRI_ERR, "NotificationHelper: " "Error sending e-mail to '%s' via SMTP server '%s'\n %s", rContact.data(), rSMTPServer.data(), response.data()); OsSysLog::flush(); } } return status; }
void SipDialogEvent::buildBody(int* version) const { UtlString dialogEvent; UtlString singleLine; // Construct the xml document of dialog event dialogEvent = UtlString(XML_VERSION_1_0); // Dialog Information Structure dialogEvent.append(BEGIN_DIALOG_INFO); if (version) { // Generate the body with the recorded version. char buffer[20]; sprintf(buffer, "%d", mVersion); dialogEvent.append(VERSION_EQUAL); singleLine = DOUBLE_QUOTE + UtlString(buffer) + DOUBLE_QUOTE; dialogEvent += singleLine; // Return the XML version. *version = mVersion; } else { // Generate the body with the substitution placeholder. dialogEvent.append(VERSION_EQUAL DOUBLE_QUOTE VERSION_PLACEHOLDER DOUBLE_QUOTE); } dialogEvent.append(STATE_EQUAL); singleLine = DOUBLE_QUOTE + mDialogState + DOUBLE_QUOTE; dialogEvent += singleLine; dialogEvent.append(ENTITY_EQUAL); singleLine = DOUBLE_QUOTE; XmlEscape(singleLine, mEntity); singleLine += DOUBLE_QUOTE; dialogEvent += singleLine; dialogEvent.append(END_LINE); // Take the lock (we will be modifying the state even though 'this' // is read-only). (const_cast <SipDialogEvent*> (this))->mLock.acquire(); // Dialog elements UtlSListIterator dialogIterator(mDialogs); Dialog* pDialog; while ((pDialog = (Dialog *) dialogIterator())) { UtlString b; ssize_t l; pDialog->getBytes(b, l); dialogEvent.append(b); } // End of dialog-info element dialogEvent.append(END_DIALOG_INFO); // Update body text (even though 'this' is read-only). (const_cast <SipDialogEvent*> (this))->mBody = dialogEvent; (const_cast <SipDialogEvent*> (this))->bodyLength = dialogEvent.length(); // mVersion is not updated, as that is used only to record // the version of parsed events. (const_cast <SipDialogEvent*> (this))->mLock.release(); Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipDialogEvent::buildBody Dialog content = \n%s", mBody.data()); }
void Dialog::getBytes(UtlString& b, ssize_t& l) { b.remove(0); b.append(BEGIN_DIALOG); UtlString singleLine; singleLine = DOUBLE_QUOTE; XmlEscape(singleLine, mId); singleLine += DOUBLE_QUOTE; b += singleLine; if (!mCallId.isNull()) { b.append(CALL_ID_EQUAL); singleLine = DOUBLE_QUOTE; XmlEscape(singleLine, mCallId); singleLine += DOUBLE_QUOTE; b += singleLine; } if (!mLocalTag.isNull()) { b.append(LOCAL_TAG_EQUAL); // mLocalTag is a token singleLine = DOUBLE_QUOTE + mLocalTag + DOUBLE_QUOTE; b += singleLine; } if (!mRemoteTag.isNull()) { b.append(REMOTE_TAG_EQUAL); // mRemoteTag is a token singleLine = DOUBLE_QUOTE + mRemoteTag + DOUBLE_QUOTE; b += singleLine; } if (!mDirection.isNull()) { b.append(DIRECTION_EQUAL); // mDirection is a token singleLine = DOUBLE_QUOTE + mDirection + DOUBLE_QUOTE; b += singleLine; } b.append(END_LINE); // State element b.append(BEGIN_STATE); if (!mEvent.isNull()) { b.append(EVENT_EQUAL); // mEvent is a token singleLine = DOUBLE_QUOTE + mEvent + DOUBLE_QUOTE; b += singleLine; } if (!mCode.isNull()) { b.append(CODE_EQUAL); // mCode is a token singleLine = DOUBLE_QUOTE + mCode + DOUBLE_QUOTE; b += singleLine; } // End of state element singleLine = END_BRACKET + mState + END_STATE; b += singleLine; // Duration element if (mDuration !=0) { b += BEGIN_DURATION; b.appendNumber((Int64) OsDateTime::getSecsSinceEpoch() - mDuration); b += END_DURATION; } // Local element b.append(BEGIN_LOCAL); if (!mLocalIdentity.isNull()) { b.append(BEGIN_IDENTITY); if (!mLocalDisplay.isNull()) { UtlString displayName = mLocalDisplay; NameValueTokenizer::frontBackTrim(&displayName, "\""); b.append(DISPLAY_EQUAL); singleLine = DOUBLE_QUOTE; XmlEscape(singleLine, displayName); singleLine += DOUBLE_QUOTE; b += singleLine; } singleLine = END_BRACKET; XmlEscape(singleLine, mLocalIdentity); singleLine += END_IDENTITY; b += singleLine; } if (!mLocalTarget.isNull() && mLocalTarget.compareTo("sip:") != 0) { singleLine = BEGIN_TARGET; XmlEscape(singleLine, mLocalTarget); singleLine += DOUBLE_QUOTE END_LINE; b += singleLine; // add optional parameters UtlDListIterator* iterator = getLocalParameterIterator(); NameValuePairInsensitive* nvp; while ((nvp = (NameValuePairInsensitive*) (*iterator)())) { singleLine = BEGIN_DIALOG_PARAM; singleLine += PNAME; XmlEscape(singleLine, nvp->data()); singleLine += PVALUE; XmlEscape(singleLine, nvp->getValue()); singleLine += END_DIALOG_PARAM; b += singleLine; } delete iterator; singleLine = END_TARGET; b += singleLine; } // End of local element b.append(END_LOCAL); // Remote element b.append(BEGIN_REMOTE); if (!mRemoteIdentity.isNull()) { b.append(BEGIN_IDENTITY); if (!mRemoteDisplay.isNull()) { UtlString displayName = mRemoteDisplay; NameValueTokenizer::frontBackTrim(&displayName, "\""); b.append(DISPLAY_EQUAL); singleLine = DOUBLE_QUOTE; XmlEscape(singleLine, displayName); singleLine += DOUBLE_QUOTE; b += singleLine; } singleLine = END_BRACKET; XmlEscape(singleLine, mRemoteIdentity); singleLine += END_IDENTITY; b += singleLine; } if (!mRemoteTarget.isNull() && mRemoteTarget.compareTo("sip:") != 0) { singleLine = BEGIN_TARGET; XmlEscape(singleLine, mRemoteTarget); singleLine += DOUBLE_QUOTE END_LINE; b += singleLine; // add optional parameters UtlDListIterator* iterator = getRemoteParameterIterator(); NameValuePairInsensitive* nvp; while ((nvp = (NameValuePairInsensitive*) (*iterator)())) { singleLine = BEGIN_DIALOG_PARAM; singleLine += PNAME; XmlEscape(singleLine, nvp->data()); singleLine += PVALUE; XmlEscape(singleLine, nvp->getValue()); singleLine += END_DIALOG_PARAM; b += singleLine; } delete iterator; singleLine = END_TARGET; b += singleLine; } // End of remote element b.append(END_REMOTE); // End of dialog element b.append(END_DIALOG); l = b.length(); }
// Add to the HttpBody the current state of the resource. void ResourceInstance::generateBody(UtlString& rlmi, HttpBody& body, UtlBoolean consolidated, const UtlString& displayName) const { OsSysLog::add(FAC_RLS, PRI_DEBUG, "ResourceInstance::generateBody mInstanceName = '%s', consolidated = %d, displayName = '%s', mContentPresent = %d", mInstanceName.data(), consolidated, displayName.data(), mContentPresent); if (consolidated) { if (mContentPresent) { // If this is a consolidated dialog event list, edit the // stored XML into the right form and append each dialog // to the resource list event notice. TiXmlUtlStringWriter writer(&rlmi); // Iterate through all the <dialog> elements. UtlHashMapIterator itor(mXmlDialogs); UtlContainable* id; while ((id = itor())) { UtlVoidPtr* p = dynamic_cast <UtlVoidPtr*> (itor.value()); TiXmlElement* dialog_element = static_cast <TiXmlElement*> (p->getValue()); // Now that we've got a <dialog> element, edit it to fit // into a consolidated event notice. // Get the display name right. // Find the <local> element, which we know exists due to // earlier processing. TiXmlNode* local = dialog_element->FirstChild("local"); // Find the <local><identity> element, which we know // exists due to earlier processing. TiXmlNode* identity = local->FirstChild("identity"); // Update the display attribute, as that is what will show // on the phone. identity->ToElement()-> SetAttribute("display", displayName); // Un-parse the dialog into the string for storage. writer << *dialog_element; writer << "\r\n"; } } } else { // Generate the XML for the instance. rlmi += " <instance id=\""; XmlEscape(rlmi, mInstanceName); rlmi += "\" state=\""; // Subscription states don't require escaping. rlmi += mSubscriptionState; rlmi += "\""; // Generate the body part for the instance, if necessary. if (mContentPresent) { UtlString contentBodyPartCid; // Use the count of parts in 'body' to generate a unique identifier for // each part. contentBodyPartCid.appendNumber(body.getMultipartCount()); contentBodyPartCid += "@"; contentBodyPartCid += getResourceListServer()->getDomainName(); rlmi += " cid=\""; rlmi += contentBodyPartCid; rlmi += "\""; // Now add the <...> and use it in the header. contentBodyPartCid.prepend("<"); contentBodyPartCid.append(">"); HttpBody content_body(mContent.data(), mContent.length(), getResourceListServer()->getContentType()); UtlDList content_body_parameters; content_body_parameters.append( new NameValuePair(HTTP_CONTENT_ID_FIELD, contentBodyPartCid)); body.appendBodyPart(content_body, content_body_parameters); content_body_parameters.destroyAll(); } rlmi += "/>\r\n"; } }