示例#1
0
// 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";
}
示例#2
0
// 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";
   }
}