(file) Return to XmlWriter.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/XmlWriter.cpp between version 1.147 and 1.154

version 1.147, 2007/01/11 16:21:54 version 1.154, 2008/01/30 18:56:21
Line 61 
Line 61 
 #include "StrLit.h" #include "StrLit.h"
 #include "LanguageParser.h" #include "LanguageParser.h"
 #include "IDFactory.h" #include "IDFactory.h"
   #include "StringConversion.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 92 
Line 93 
 struct SpecialChar struct SpecialChar
 { {
     const char* str;     const char* str;
     size_t size;      Uint32 size;
 }; };
  
 // Defines encodings of special characters. Just use a 7-bit ASCII character // Defines encodings of special characters. Just use a 7-bit ASCII character
Line 357 
Line 358 
 { {
     if ( ((c < 0x20) && (c >= 0)) || (c == 0x7f) )     if ( ((c < 0x20) && (c >= 0)) || (c == 0x7f) )
     {     {
         char charref[7];          char scratchBuffer[22];
         sprintf(charref, "&#%u;", static_cast<Uint8>(c));          Uint32 outputLength;
         os << charref;          const char * output = Uint8ToString(scratchBuffer,
                                               static_cast<Uint8>(c),
                                               outputLength);
           os << "&#" << output << ";";
     }     }
     else     else
     {     {
Line 420 
Line 424 
         _xmlWritter_appendSpecialChar(os, *str++);         _xmlWritter_appendSpecialChar(os, *str++);
 } }
  
   // On windows sprintf outputs 3 digit precision exponent prepending
   // zeros. Make it 2 digit precision if first digit is zero in the exponent.
   #ifdef PEGASUS_OS_TYPE_WINDOWS
   inline void _xmlWriter_normalizeRealValueString(char *str)
   {
       // skip initial sign value...
       if (*str == '-' || *str == '+')
       {
           ++str;
       }
       while (*str && *str != '+' && *str != '-')
       {
           ++str;
       }
       if (*str && * ++str == '0')
       {
           *str = *(str+1);
           *(str+1) = *(str+2);
           *(str+2) = 0;
       }
   }
   #endif
   
 void XmlWriter::append(Buffer& out, const Char16& x) void XmlWriter::append(Buffer& out, const Char16& x)
 { {
     _xmlWritter_appendChar(out, x);     _xmlWritter_appendChar(out, x);
Line 427 
Line 454 
  
 void XmlWriter::append(Buffer& out, Boolean x) void XmlWriter::append(Buffer& out, Boolean x)
 { {
     append(out, (x ? "TRUE" : "FALSE"));      if (x)
           out.append(STRLIT_ARGS("TRUE"));
       else
           out.append(STRLIT_ARGS("FALSE"));
 } }
  
 void XmlWriter::append(Buffer& out, Uint32 x) void XmlWriter::append(Buffer& out, Uint32 x)
 { {
     char buffer[32];      Uint32 outputLength=0;
     sprintf(buffer, "%u", x);      char buffer[22];
     append(out, buffer);      const char * output = Uint32ToString(buffer, x, outputLength);
       out.append(output, outputLength);
 } }
  
 void XmlWriter::append(Buffer& out, Sint32 x) void XmlWriter::append(Buffer& out, Sint32 x)
 { {
     char buffer[32];      Uint32 outputLength=0;
     sprintf(buffer, "%d", x);      char buffer[22];
     append(out, buffer);      const char * output = Sint32ToString(buffer, x, outputLength);
       out.append(output, outputLength);
 } }
  
 void XmlWriter::append(Buffer& out, Uint64 x) void XmlWriter::append(Buffer& out, Uint64 x)
 { {
     char buffer[32];  // Should need 21 chars max      Uint32 outputLength=0;
     sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);      char buffer[22];
     append(out, buffer);      const char * output = Uint64ToString(buffer, x, outputLength);
       out.append(output, outputLength);
 } }
  
 void XmlWriter::append(Buffer& out, Sint64 x) void XmlWriter::append(Buffer& out, Sint64 x)
 { {
     char buffer[32];  // Should need 21 chars max      Uint32 outputLength=0;
     sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);      char buffer[22];
     append(out, buffer);      const char * output = Sint64ToString(buffer, x, outputLength);
       out.append(output, outputLength);
 } }
  
 void XmlWriter::append(Buffer& out, Real32 x) void XmlWriter::append(Buffer& out, Real32 x)
Line 465 
Line 499 
     // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec     // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec
     // (4 byte IEEE floating point)     // (4 byte IEEE floating point)
     sprintf(buffer, "%.7e", x);     sprintf(buffer, "%.7e", x);
   #ifdef PEGASUS_OS_TYPE_WINDOWS
       _xmlWriter_normalizeRealValueString(buffer);
   #endif
     append(out, buffer);     append(out, buffer);
 } }
  
Line 475 
Line 512 
     // with the format given in the CIM/XML spec, and the precision required     // with the format given in the CIM/XML spec, and the precision required
     // by the CIM 2.2 spec (8 byte IEEE floating point)     // by the CIM 2.2 spec (8 byte IEEE floating point)
     sprintf(buffer, "%.16e", x);     sprintf(buffer, "%.16e", x);
   #ifdef PEGASUS_OS_TYPE_WINDOWS
       _xmlWriter_normalizeRealValueString(buffer);
   #endif
     append(out, buffer);     append(out, buffer);
 } }
  
Line 1377 
Line 1417 
 { {
     Buffer tmp;     Buffer tmp;
     appendValueElement(tmp, value);     appendValueElement(tmp, value);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1472 
Line 1511 
 { {
     Buffer tmp;     Buffer tmp;
     appendValueReferenceElement(tmp, reference, true);     appendValueReferenceElement(tmp, reference, true);
     tmp.append('\0');  
     indentedPrint(os, tmp.getData());     indentedPrint(os, tmp.getData());
 } }
  
Line 1512 
Line 1550 
     Buffer& out,     Buffer& out,
     const CIMConstClass& cimclass)     const CIMConstClass& cimclass)
 { {
     cimclass._checkRep();      CheckRep(cimclass._rep);
     cimclass._rep->toXml(out);     cimclass._rep->toXml(out);
 } }
  
Line 1522 
Line 1560 
 { {
     Buffer tmp;     Buffer tmp;
     appendClassElement(tmp, cimclass);     appendClassElement(tmp, cimclass);
     tmp.append('\0');  
     indentedPrint(os, tmp.getData(), 4);     indentedPrint(os, tmp.getData(), 4);
 } }
  
Line 1541 
Line 1578 
     Buffer& out,     Buffer& out,
     const CIMConstInstance& instance)     const CIMConstInstance& instance)
 { {
     instance._checkRep();      CheckRep(instance._rep);
     instance._rep->toXml(out);     instance._rep->toXml(out);
 } }
  
Line 1551 
Line 1588 
 { {
     Buffer tmp;     Buffer tmp;
     appendInstanceElement(tmp, instance);     appendInstanceElement(tmp, instance);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1612 
Line 1648 
     Buffer& out,     Buffer& out,
     const CIMConstProperty& property)     const CIMConstProperty& property)
 { {
     property._checkRep();      CheckRep(property._rep);
     property._rep->toXml(out);     property._rep->toXml(out);
 } }
  
Line 1622 
Line 1658 
 { {
     Buffer tmp;     Buffer tmp;
     appendPropertyElement(tmp, property);     appendPropertyElement(tmp, property);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1644 
Line 1679 
     Buffer& out,     Buffer& out,
     const CIMConstMethod& method)     const CIMConstMethod& method)
 { {
     method._checkRep();      CheckRep(method._rep);
     method._rep->toXml(out);     method._rep->toXml(out);
 } }
  
Line 1654 
Line 1689 
 { {
     Buffer tmp;     Buffer tmp;
     appendMethodElement(tmp, method);     appendMethodElement(tmp, method);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1690 
Line 1724 
     Buffer& out,     Buffer& out,
     const CIMConstParameter& parameter)     const CIMConstParameter& parameter)
 { {
     parameter._checkRep();      CheckRep(parameter._rep);
     parameter._rep->toXml(out);     parameter._rep->toXml(out);
 } }
  
Line 1700 
Line 1734 
 { {
     Buffer tmp;     Buffer tmp;
     appendParameterElement(tmp, parameter);     appendParameterElement(tmp, parameter);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1718 
Line 1751 
     Buffer& out,     Buffer& out,
     const CIMParamValue& paramValue)     const CIMParamValue& paramValue)
 { {
     paramValue._checkRep();      CheckRep(paramValue._rep);
     paramValue._rep->toXml(out);     paramValue._rep->toXml(out);
 } }
  
Line 1728 
Line 1761 
 { {
     Buffer tmp;     Buffer tmp;
     appendParamValueElement(tmp, paramValue);     appendParamValueElement(tmp, paramValue);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1749 
Line 1781 
     Buffer& out,     Buffer& out,
     const CIMConstQualifier& qualifier)     const CIMConstQualifier& qualifier)
 { {
     qualifier._checkRep();      CheckRep(qualifier._rep);
     qualifier._rep->toXml(out);     qualifier._rep->toXml(out);
 } }
  
Line 1759 
Line 1791 
 { {
     Buffer tmp;     Buffer tmp;
     appendQualifierElement(tmp, qualifier);     appendQualifierElement(tmp, qualifier);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 1781 
Line 1812 
     Buffer& out,     Buffer& out,
     const CIMConstQualifierDecl& qualifierDecl)     const CIMConstQualifierDecl& qualifierDecl)
 { {
     qualifierDecl._checkRep();      CheckRep(qualifierDecl._rep);
     qualifierDecl._rep->toXml(out);     qualifierDecl._rep->toXml(out);
 } }
  
Line 1791 
Line 1822 
 { {
     Buffer tmp;     Buffer tmp;
     appendQualifierDeclElement(tmp, qualifierDecl);     appendQualifierDeclElement(tmp, qualifierDecl);
     tmp.append('\0');  
     os << tmp.getData() << PEGASUS_STD(endl);     os << tmp.getData() << PEGASUS_STD(endl);
 } }
  
Line 2064 
Line 2094 
     const String& content)     const String& content)
 { {
     out << STRLIT("HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n");     out << STRLIT("HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n");
       Uint32 contentLength = 0;
       OUTPUT_CONTENTLENGTH;
     out << content << STRLIT("\r\n");     out << content << STRLIT("\r\n");
     out << STRLIT("\r\n");     out << STRLIT("\r\n");
  
Line 2349 
Line 2381 
         out << STRLIT("/>");         out << STRLIT("/>");
 } }
  
 //------------------------------------------------------------------------------  //----------------------------------------------------------------------
 // //
 // appendReturnValueElement()  // appendParmType
 //  // Appends the Param type and EmbeddedObject Info
 // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>  // to the buffer
 // <!ATTLIST RETURNVALUE  
 //     %EmbeddedObject; #IMPLIED //     %EmbeddedObject; #IMPLIED
 //     %ParamType;> //     %ParamType;>
 // //
 //------------------------------------------------------------------------------  //---------------------------------------------------------------------
   void XmlWriter::appendParamTypeAndEmbeddedObjAttrib(
 void XmlWriter::appendReturnValueElement(  
     Buffer& out,     Buffer& out,
     const CIMValue& value)      const CIMType& type)
 { {
     out << STRLIT("<RETURNVALUE");  
  
     CIMType type = value.getType();  
     // If the property type is CIMObject, then     // If the property type is CIMObject, then
     //   encode the property in CIM-XML as a string with the EMBEDDEDOBJECT      //   encode the property in CIM-XML as a string with the EmbeddedObject
     //   attribute (there is not currently a CIM-XML "object" datatype)      //   attribute (there is not currently a CIM-XML "object"
       //   datatype).
       //   Because of an error in Pegasus we were earlier outputting
       //   upper case "EMBEDDEDOBJECT" as the attribute name. The
       //   spec calls for mixed case "EmbeddedObject. Fixed in
       //   bug 7131 to output EmbeddedObject  attribute in upper
       //   case and mixed case. Receiver will ignore one or the
       //   other.
     // else     // else
     //   output the real type     //   output the real type
     if (type == CIMTYPE_OBJECT)     if (type == CIMTYPE_OBJECT)
     {     {
   
         out << STRLIT(" PARAMTYPE=\"string\"");         out << STRLIT(" PARAMTYPE=\"string\"");
           out << STRLIT(" EmbeddedObject=\"object\"");
         out << STRLIT(" EMBEDDEDOBJECT=\"object\"");         out << STRLIT(" EMBEDDEDOBJECT=\"object\"");
     }     }
 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
     else if (type == CIMTYPE_INSTANCE)     else if (type == CIMTYPE_INSTANCE)
     {     {
         out << STRLIT(" PARAMTYPE=\"string\"");         out << STRLIT(" PARAMTYPE=\"string\"");
           out << STRLIT(" EmbeddedObject=\"instance\"");
         out << STRLIT(" EMBEDDEDOBJECT=\"instance\"");         out << STRLIT(" EMBEDDEDOBJECT=\"instance\"");
     }     }
 #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
Line 2389 
Line 2427 
         out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type);         out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type);
         out.append('"');         out.append('"');
     }     }
   }
   
   //------------------------------------------------------------------------------
   //
   // appendReturnValueElement()
   //
   // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
   // <!ATTLIST RETURNVALUE
   //     %EmbeddedObject; #IMPLIED
   //     %ParamType;>
   //
   //------------------------------------------------------------------------------
   
   
   void XmlWriter::appendReturnValueElement(
       Buffer& out,
       const CIMValue& value)
   {
       out << STRLIT("<RETURNVALUE");
   
       CIMType type = value.getType();
   
       appendParamTypeAndEmbeddedObjAttrib(out, type);
  
     out << STRLIT(">\n");     out << STRLIT(">\n");
  
Line 2714 
Line 2775 
         httpMethod,         httpMethod,
         httpAcceptLanguages,         httpAcceptLanguages,
         httpContentLanguages,         httpContentLanguages,
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2787 
Line 2848 
         tmp,         tmp,
         httpMethod,         httpMethod,
         cimException.getContentLanguages(),         cimException.getContentLanguages(),
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2831 
Line 2892 
         httpMethod,         httpMethod,
         httpAcceptLanguages,         httpAcceptLanguages,
         httpContentLanguages,         httpContentLanguages,
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2919 
Line 2980 
     appendMethodResponseHeader(tmp,     appendMethodResponseHeader(tmp,
         httpMethod,         httpMethod,
         cimException.getContentLanguages(),         cimException.getContentLanguages(),
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 3212 
Line 3273 
         authenticationHeader,         authenticationHeader,
         httpAcceptLanguages,         httpAcceptLanguages,
         httpContentLanguages,         httpContentLanguages,
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 3245 
Line 3306 
     appendEMethodResponseHeader(tmp,     appendEMethodResponseHeader(tmp,
         httpMethod,         httpMethod,
         httpContentLanguages,         httpContentLanguages,
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 3278 
Line 3339 
         tmp,         tmp,
         httpMethod,         httpMethod,
         cimException.getContentLanguages(),         cimException.getContentLanguages(),
         (Uint32)out.size());          out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 3440 
Line 3501 
  
 String XmlWriter::getNextMessageId() String XmlWriter::getNextMessageId()
 { {
     char buffer[16];      char scratchBuffer[22];
     sprintf(buffer, "%u", _messageIDFactory.getID());      Uint32 n;
     return buffer;      const char * startP = Uint32ToString(scratchBuffer,
                                            _messageIDFactory.getID(),
                                            n);
       return String(startP, n);
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------


Legend:
Removed from v.1.147  
changed lines
  Added in v.1.154

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2