(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.80 and 1.111.2.1

version 1.80, 2002/09/13 21:40:42 version 1.111.2.1, 2004/11/12 17:48:28
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2003////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
 // The Open Group, Tivoli Systems  // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
   // IBM Corp.; EMC Corporation, The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 28 
Line 30 
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 //              Carol Ann Krug Graves, Hewlett-Packard Company //              Carol Ann Krug Graves, Hewlett-Packard Company
 //                  (carolann_graves@hp.com) //                  (carolann_graves@hp.com)
   //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
   //              Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase1
   //              Willis White (whiwill@us.ibm.com) PEP 127 and 128
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 35 
Line 40 
 #include <cstdlib> #include <cstdlib>
 #include <cstdio> #include <cstdio>
 #include "Constants.h" #include "Constants.h"
 #include "Destroyer.h"  
 #include "CIMClass.h" #include "CIMClass.h"
 #include "CIMClassRep.h" #include "CIMClassRep.h"
 #include "CIMInstance.h" #include "CIMInstance.h"
Line 57 
Line 61 
 #include "XmlParser.h" #include "XmlParser.h"
 #include "Tracer.h" #include "Tracer.h"
 #include <Pegasus/Common/StatisticalData.h> #include <Pegasus/Common/StatisticalData.h>
   #include "CommonUTF.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   // This is a shortcut macro for outputing content length. This
   // pads the output number to the max characters representing a Uint32 number
   // so that it can be overwritten easily with a transfer encoding line later
   // on in HTTPConnection if required. This is strictly for performance since
   // messages can be very large. This overwriting shortcut allows us to NOT have
   // to repackage a large message later.
   
   #define OUTPUT_CONTENTLENGTH                                  \
   {                                                            \
           char contentLengthP[11];                                   \
     sprintf(contentLengthP,"%.10u", contentLength);            \
     out << "content-length: " << contentLengthP << "\r\n";     \
   }
   
 Array<Sint8>& operator<<(Array<Sint8>& out, const char* x) Array<Sint8>& operator<<(Array<Sint8>& out, const char* x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
Line 108 
Line 127 
     return out;     return out;
 } }
  
   
   // l10n
   Array<Sint8>& operator<<(Array<Sint8>& out, const AcceptLanguages& al)
   {
       XmlWriter::append(out, al.toString ());
       return out;
   }
   
   // l10n
   Array<Sint8>& operator<<(Array<Sint8>& out, const ContentLanguages& cl)
   {
       XmlWriter::append(out, cl.toString ());
       return out;
   }
   
   
 PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMDateTime& x) PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMDateTime& x)
 { {
     return os << x.toString();     return os << x.toString();
Line 126 
Line 161 
     return os;     return os;
 } }
  
 inline void _appendChar(Array<Sint8>& out, const Char16& c)  inline void _xmlWritter_appendChar(Array<Sint8>& out, const Char16& c)
 { {
     out.append(Sint8(c));      // We need to convert the Char16 to UTF8 then append the UTF8
       // character into the array.
       // NOTE: The UTF8 character could be several bytes long.
       // WARNING: This function will put in replacement character for
       // all characters that have surogate pairs.
       Uint8 str[6];
       memset(str,0x00,sizeof(str));
       Uint8* charIN = (Uint8 *)&c;
   
       const Uint16 *strsrc = (Uint16 *)charIN;
       Uint16 *endsrc = (Uint16 *)&charIN[1];
   
       Uint8 *strtgt = (Uint8 *)str;
       Uint8 *endtgt = (Uint8 *)&str[5];
   
       UTF16toUTF8(&strsrc,
                   endsrc,
                   &strtgt,
                   endtgt);
   
       out.append((Sint8 *)str, UTF_8_COUNT_TRAIL_BYTES(str[0]) + 1);
   }
   
   inline void _xmlWritter_appendSpecialChar(Array<Sint8>& out, const Char16& c)
   {
       if ( ((c < Char16(0x20)) && (c >= Char16(0x00))) || (c == Char16(0x7f)) )
       {
           char charref[7];
           sprintf(charref, "&#%u;", (Uint16)c);
           out.append(charref, strlen(charref));
 } }
       else
       {
           switch (c)
           {
               case '&':
                   out.append("&amp;", 5);
                   break;
  
 inline void _appendSpecialChar(Array<Sint8>& out, const Char16& c)              case '<':
                   out.append("&lt;", 4);
                   break;
   
               case '>':
                   out.append("&gt;", 4);
                   break;
   
               case '"':
                   out.append("&quot;", 6);
                   break;
   
               case '\'':
                   out.append("&apos;", 6);
                   break;
   
               default:
 { {
     // ATTN-B: Only UTF-8 handled for now.                      // We need to convert the Char16 to UTF8 then append the UTF8
                       // character into the array.
                       // NOTE: The UTF8 character could be several bytes long.
                       // WARNING: This function will put in replacement character for
                       // all characters that have surogate pairs.
                       Uint8 str[6];
                       memset(str,0x00,sizeof(str));
                       Uint8* charIN = (Uint8 *)&c;
   
                       const Uint16 *strsrc = (Uint16 *)charIN;
                       Uint16 *endsrc = (Uint16 *)&charIN[1];
   
                       Uint8 *strtgt = (Uint8 *)str;
                       Uint8 *endtgt = (Uint8 *)&str[5];
   
                       UTF16toUTF8(&strsrc,
                                   endsrc,
                                   &strtgt,
                                   endtgt);
   
                       Uint32 number1 = UTF_8_COUNT_TRAIL_BYTES(str[0]) + 1;
  
                       out.append((Sint8 *)str,number1);
                   }
           }
       }
   }
   
   inline void _xmlWritter_appendSpecialChar(Array<Sint8>& out, char c)
   {
       if ( ((c < Char16(0x20)) && (c >= Char16(0x00))) || (c == Char16(0x7f)) )
       {
           char charref[7];
           sprintf(charref, "&#%u;", (Uint8)c);
           out.append(charref, strlen(charref));
       }
       else
       {
     switch (c)     switch (c)
     {     {
         case '&':         case '&':
Line 161 
Line 284 
             out.append(Sint8(c));             out.append(Sint8(c));
     }     }
 } }
   }
   
  
 static inline void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c)  inline void _xmlWritter_appendSpecialChar(PEGASUS_STD(ostream)& os, char c)
   {
       if ( (c < Char16(0x20)) || (c == Char16(0x7f)) )
       {
           char charref[7];
           sprintf(charref, "&#%u;", (Uint8)c);
           os << charref;
       }
       else
 { {
     switch (c)     switch (c)
     {     {
Line 190 
Line 323 
             os << c;             os << c;
     }     }
 } }
   }
   
   void _xmlWritter_appendSurrogatePair(Array<Sint8>& out, Uint16 high, Uint16 low)
   {
       Uint8 str[6];
       Uint8 charIN[5];
       memset(str,0x00,sizeof(str));
       memcpy(&charIN,&high,2);
       memcpy(&charIN[2],&low,2);
       const Uint16 *strsrc = (Uint16 *)charIN;
       Uint16 *endsrc = (Uint16 *)&charIN[3];
   
       Uint8 *strtgt = (Uint8 *)str;
       Uint8 *endtgt = (Uint8 *)&str[5];
   
       UTF16toUTF8(&strsrc,
                   endsrc,
                   &strtgt,
                   endtgt);
   
       Uint32 number1 = UTF_8_COUNT_TRAIL_BYTES(str[0]) + 1;
       out.append((Sint8 *)str,number1);
   }
  
 static inline void _appendSpecial(PEGASUS_STD(ostream)& os, const char* str)  inline void _xmlWritter_appendSpecial(PEGASUS_STD(ostream)& os, const char* str)
 { {
     while (*str)     while (*str)
         _appendSpecialChar(os, *str++);          _xmlWritter_appendSpecialChar(os, *str++);
 } }
  
 void XmlWriter::append(Array<Sint8>& out, const Char16& x) void XmlWriter::append(Array<Sint8>& out, const Char16& x)
 { {
     _appendChar(out, x);      _xmlWritter_appendChar(out, x);
 } }
  
 void XmlWriter::append(Array<Sint8>& out, Boolean x) void XmlWriter::append(Array<Sint8>& out, Boolean x)
Line 224 
Line 380 
 void XmlWriter::append(Array<Sint8>& out, Uint64 x) void XmlWriter::append(Array<Sint8>& out, Uint64 x)
 { {
     char buffer[32];  // Should need 21 chars max     char buffer[32];  // Should need 21 chars max
     // I know I shouldn't put platform flags here, but the other way is too hard      sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)  
     sprintf(buffer, "%I64u", x);  
 #else  
     sprintf(buffer, "%llu", x);  
 #endif  
     append(out, buffer);     append(out, buffer);
 } }
  
 void XmlWriter::append(Array<Sint8>& out, Sint64 x) void XmlWriter::append(Array<Sint8>& out, Sint64 x)
 { {
     char buffer[32];  // Should need 21 chars max     char buffer[32];  // Should need 21 chars max
     // I know I shouldn't put platform flags here, but the other way is too hard      sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);
 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)      append(out, buffer);
     sprintf(buffer, "%I64d", x);  }
 #else  
     sprintf(buffer, "%lld", x);  void XmlWriter::append(Array<Sint8>& out, Real32 x)
 #endif  {
       char buffer[128];
       // %.7e gives '[-]m.ddddddde+/-xx', which seems compatible with the format
       // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec
       // (4 byte IEEE floating point)
       sprintf(buffer, "%.7e", x);
     append(out, buffer);     append(out, buffer);
 } }
  
 void XmlWriter::append(Array<Sint8>& out, Real64 x) void XmlWriter::append(Array<Sint8>& out, Real64 x)
 { {
     char buffer[128];     char buffer[128];
     // %e gives '[-]m.dddddde+/-xx', which seems compatible with CIM/XML spec      // %.16e gives '[-]m.dddddddddddddddde+/-xx', which seems compatible with the format
     sprintf(buffer, "%e", x);      // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec
       // (8 byte IEEE floating point)
       sprintf(buffer, "%.16e", x);
     append(out, buffer);     append(out, buffer);
 } }
  
 void XmlWriter::append(Array<Sint8>& out, const char* str) void XmlWriter::append(Array<Sint8>& out, const char* str)
 { {
     while (*str)     while (*str)
         _appendChar(out, *str++);        XmlWriter::append(out, *str++);
 } }
  
 void XmlWriter::append(Array<Sint8>& out, const String& str) void XmlWriter::append(Array<Sint8>& out, const String& str)
 { {
     for (Uint32 i = 0; i < str.size(); i++)     for (Uint32 i = 0; i < str.size(); i++)
     {     {
         _appendChar(out, str[i]);          Uint16 c = str[i];
           if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
              ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))
           {
               Char16 highSurrogate = str[i];
               Char16 lowSurrogate = str[++i];
   
               _xmlWritter_appendSurrogatePair(out, Uint16(highSurrogate),Uint16(lowSurrogate));
           }
           else
           {
               _xmlWritter_appendChar(out, str[i]);
           }
     }     }
 } }
  
Line 275 
Line 445 
  
 void XmlWriter::appendSpecial(Array<Sint8>& out, const Char16& x) void XmlWriter::appendSpecial(Array<Sint8>& out, const Char16& x)
 { {
     _appendSpecialChar(out, x);      _xmlWritter_appendSpecialChar(out, x);
 } }
  
 void XmlWriter::appendSpecial(Array<Sint8>& out, char x) void XmlWriter::appendSpecial(Array<Sint8>& out, char x)
 { {
     _appendSpecialChar(out, Char16(x));      _xmlWritter_appendSpecialChar(out, x);
 } }
  
 void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str) void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str)
 { {
     while (*str)     while (*str)
         _appendSpecialChar(out, *str++);          _xmlWritter_appendSpecialChar(out, *str++);
 } }
  
 void XmlWriter::appendSpecial(Array<Sint8>& out, const String& str) void XmlWriter::appendSpecial(Array<Sint8>& out, const String& str)
 { {
     for (Uint32 i = 0; i < str.size(); i++)     for (Uint32 i = 0; i < str.size(); i++)
     {     {
         _appendSpecialChar(out, str[i]);          Uint16 c = str[i];
   
           if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
              ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))
           {
               Char16 highSurrogate = str[i];
               Char16 lowSurrogate = str[++i];
   
               _xmlWritter_appendSurrogatePair(out, Uint16(highSurrogate),Uint16(lowSurrogate));
           }
           else
           {
               _xmlWritter_appendSpecialChar(out, str[i]);
           }
       }
   }
   
   // See http://www.ietf.org/rfc/rfc2396.txt section 2
   // Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ','
   // Excluded characters:
   //   Control characters = 0x00-0x1f, 0x7f
   //   Space character = 0x20
   //   Delimiters = '<' '>' '#' '%' '"'
   //   Unwise = '{' '}' '|' '\\' '^' '[' ']' '`'
   //
   
   inline void _xmlWritter_encodeURIChar(String& outString, Sint8 char8)
   {
       Uint8 c = (Uint8)char8;
   
   #ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING
       if ( (c <= 0x20) ||                     // Control characters + space char
            ( (c >= 0x22) && (c <= 0x26) ) ||  // '"' '#' '$' '%' '&'
            (c == 0x2b) ||                     // '+'
            (c == 0x2c) ||                     // ','
            (c == 0x2f) ||                     // '/'
            ( (c >= 0x3a) && (c <= 0x40) ) ||  // ':' ';' '<' '=' '>' '?' '@'
            ( (c >= 0x5b) && (c <= 0x5e) ) ||  // '[' '\\' ']' '^'
            (c == 0x60) ||                     // '`'
            ( (c >= 0x7b) && (c <= 0x7d) ) ||  // '{' '|' '}'
            (c >= 0x7f) )                      // Control character or non US-ASCII (UTF-8)
       {
           char hexencoding[4];
   
           sprintf(hexencoding, "%%%X%X", c/16, c%16);
           outString.append(hexencoding);
       }
       else
   #endif
       {
           outString.append((Uint16)c);
       }
   }
   
   String XmlWriter::encodeURICharacters(Array<Sint8> uriString)
   {
       String encodedString;
   
       for (Uint32 i=0; i<uriString.size(); i++)
       {
           _xmlWritter_encodeURIChar(encodedString, uriString[i]);
       }
   
       return encodedString;
   }
   
   String XmlWriter::encodeURICharacters(String uriString)
   {
       String encodedString;
   
   /* i18n remove - did not handle surrogate pairs
       for (Uint32 i=0; i<uriString.size(); i++)
       {
           _xmlWritter_encodeURIChar(encodedString, uriString[i]);
       }
   */
   
       // See the "CIM Operations over HTTP" spec, section 3.3.2 and
       // 3.3.3, for the treatment of non US-ASCII (UTF-8) chars
   
       // First, convert to UTF-8 (include handling of surrogate pairs)
       Array<Sint8> utf8;
       for (Uint32 i = 0; i < uriString.size(); i++)
       {
           Uint16 c = uriString[i];
   
           if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
              ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))
           {
               Char16 highSurrogate = uriString[i];
               Char16 lowSurrogate = uriString[++i];
   
               _xmlWritter_appendSurrogatePair(utf8, Uint16(highSurrogate),Uint16(lowSurrogate));
           }
           else
           {
               _xmlWritter_appendChar(utf8, uriString[i]);
     }     }
 } }
  
       // Second, escape the non HTTP-safe chars
       for (Uint32 i=0; i<utf8.size(); i++)
       {
           _xmlWritter_encodeURIChar(encodedString, utf8[i]);
       }
   
       return encodedString;
   }
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // appendLocalNameSpacePathElement() // appendLocalNameSpacePathElement()
Line 312 
Line 587 
     out << "<LOCALNAMESPACEPATH>\n";     out << "<LOCALNAMESPACEPATH>\n";
  
     char* nameSpaceCopy = strdup(nameSpace.getString().getCString());     char* nameSpaceCopy = strdup(nameSpace.getString().getCString());
   
   #if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || \
       defined(PEGASUS_OS_HPUX) || \
       defined(PEGASUS_OS_LINUX)
       char *last;
       for (const char* p = strtok_r(nameSpaceCopy, "/", &last); p;
            p = strtok_r(NULL, "/", &last))
   #else
     for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/"))     for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/"))
   #endif
     {     {
         out << "<NAMESPACE NAME=\"" << p << "\"/>\n";         out << "<NAMESPACE NAME=\"" << p << "\"/>\n";
     }     }
     delete nameSpaceCopy;      free(nameSpaceCopy);
  
     out << "</LOCALNAMESPACEPATH>\n";     out << "</LOCALNAMESPACEPATH>\n";
 } }
Line 509 
Line 793 
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 inline void _appendValue(Array<Sint8>& out, Boolean x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Boolean x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, Uint8 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Uint8 x)
 { {
     XmlWriter::append(out, Uint32(x));     XmlWriter::append(out, Uint32(x));
 } }
  
 inline void _appendValue(Array<Sint8>& out, Sint8 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Sint8 x)
 { {
     XmlWriter::append(out, Sint32(x));     XmlWriter::append(out, Sint32(x));
 } }
  
 inline void _appendValue(Array<Sint8>& out, Uint16 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Uint16 x)
 { {
     XmlWriter::append(out, Uint32(x));     XmlWriter::append(out, Uint32(x));
 } }
  
 inline void _appendValue(Array<Sint8>& out, Sint16 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Sint16 x)
 { {
     XmlWriter::append(out, Sint32(x));     XmlWriter::append(out, Sint32(x));
 } }
  
 inline void _appendValue(Array<Sint8>& out, Uint32 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Uint32 x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, Sint32 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Sint32 x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, Uint64 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Uint64 x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, Sint64 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Sint64 x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, Real32 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Real32 x)
 { {
     XmlWriter::append(out, Real64(x));      XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, Real64 x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, Real64 x)
 { {
     XmlWriter::append(out, x);     XmlWriter::append(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, const Char16& x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, const Char16& x)
 { {
     XmlWriter::appendSpecial(out, x);     XmlWriter::appendSpecial(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, const String& x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, const String& x)
 { {
     XmlWriter::appendSpecial(out, x);     XmlWriter::appendSpecial(out, x);
 } }
  
 inline void _appendValue(Array<Sint8>& out, const CIMDateTime& x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, const CIMDateTime& x)
 { {
     out << x.toString();  //ATTN: append() method?     out << x.toString();  //ATTN: append() method?
 } }
  
 inline void _appendValue(Array<Sint8>& out, const CIMObjectPath& x)  inline void _xmlWritter_appendValue(Array<Sint8>& out, const CIMObjectPath& x)
 { {
     XmlWriter::appendValueReferenceElement(out, x, true);     XmlWriter::appendValueReferenceElement(out, x, true);
 } }
  
 void _appendValueArray(Array<Sint8>& out, const CIMObjectPath* p, Uint32 size)  // DJS -- temporary for testing until encode/decode issues resolved
   inline void _xmlWritter_appendValue(Array<Sint8>& out, const CIMObject& x)
   {
       out << x.toString();
   }
   
   void _xmlWritter_appendValueArray(Array<Sint8>& out, const CIMObjectPath* p, Uint32 size)
 { {
     out << "<VALUE.REFARRAY>\n";     out << "<VALUE.REFARRAY>\n";
     while (size--)     while (size--)
     {     {
         _appendValue(out, *p++);          _xmlWritter_appendValue(out, *p++);
     }     }
     out << "</VALUE.REFARRAY>\n";     out << "</VALUE.REFARRAY>\n";
 } }
  
 template<class T> template<class T>
 void _appendValueArray(Array<Sint8>& out, const T* p, Uint32 size)  void _xmlWritter_appendValueArray(Array<Sint8>& out, const T* p, Uint32 size)
 { {
     out << "<VALUE.ARRAY>\n";     out << "<VALUE.ARRAY>\n";
  
     while (size--)     while (size--)
     {     {
         out << "<VALUE>";         out << "<VALUE>";
         _appendValue(out, *p++);          _xmlWritter_appendValue(out, *p++);
         out << "</VALUE>\n";         out << "</VALUE>\n";
     }     }
  
Line 638 
Line 928 
             {             {
                 Array<Boolean> a;                 Array<Boolean> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 646 
Line 936 
             {             {
                 Array<Uint8> a;                 Array<Uint8> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 654 
Line 944 
             {             {
                 Array<Sint8> a;                 Array<Sint8> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 662 
Line 952 
             {             {
                 Array<Uint16> a;                 Array<Uint16> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 670 
Line 960 
             {             {
                 Array<Sint16> a;                 Array<Sint16> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 678 
Line 968 
             {             {
                 Array<Uint32> a;                 Array<Uint32> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 686 
Line 976 
             {             {
                 Array<Sint32> a;                 Array<Sint32> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 694 
Line 984 
             {             {
                 Array<Uint64> a;                 Array<Uint64> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 702 
Line 992 
             {             {
                 Array<Sint64> a;                 Array<Sint64> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 710 
Line 1000 
             {             {
                 Array<Real32> a;                 Array<Real32> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 718 
Line 1008 
             {             {
                 Array<Real64> a;                 Array<Real64> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 726 
Line 1016 
             {             {
                 Array<Char16> a;                 Array<Char16> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 734 
Line 1024 
             {             {
                 Array<String> a;                 Array<String> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 742 
Line 1032 
             {             {
                 Array<CIMDateTime> a;                 Array<CIMDateTime> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 750 
Line 1040 
             {             {
                 Array<CIMObjectPath> a;                 Array<CIMObjectPath> a;
                 value.get(a);                 value.get(a);
                 _appendValueArray(out, a.getData(), a.size());                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
                   break;
               }
   
               // DJS -- temporary for testing until encode/decode issues resolved
               case CIMTYPE_OBJECT:
               {
                   Array<CIMObject> a;
                   value.get(a);
                   _xmlWritter_appendValueArray(out, a.getData(), a.size());
                 break;                 break;
             }             }
  
Line 763 
Line 1062 
         // Has to be separate because it uses VALUE.REFERENCE tag         // Has to be separate because it uses VALUE.REFERENCE tag
         CIMObjectPath v;         CIMObjectPath v;
         value.get(v);         value.get(v);
         _appendValue(out, v);          _xmlWritter_appendValue(out, v);
     }     }
     else     else
     {     {
Line 775 
Line 1074 
             {             {
                 Boolean v;                 Boolean v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 783 
Line 1082 
             {             {
                 Uint8 v;                 Uint8 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 791 
Line 1090 
             {             {
                 Sint8 v;                 Sint8 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 799 
Line 1098 
             {             {
                 Uint16 v;                 Uint16 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 807 
Line 1106 
             {             {
                 Sint16 v;                 Sint16 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 815 
Line 1114 
             {             {
                 Uint32 v;                 Uint32 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 823 
Line 1122 
             {             {
                 Sint32 v;                 Sint32 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 831 
Line 1130 
             {             {
                 Uint64 v;                 Uint64 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 839 
Line 1138 
             {             {
                 Sint64 v;                 Sint64 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 847 
Line 1146 
             {             {
                 Real32 v;                 Real32 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 855 
Line 1154 
             {             {
                 Real64 v;                 Real64 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 863 
Line 1162 
             {             {
                 Char16 v;                 Char16 v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 871 
Line 1170 
             {             {
                 String v;                 String v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 879 
Line 1178 
             {             {
                 CIMDateTime v;                 CIMDateTime v;
                 value.get(v);                 value.get(v);
                 _appendValue(out, v);                  _xmlWritter_appendValue(out, v);
                   break;
               }
   
               // DJS -- temporary for testing until encode/decode issues resolved
               case CIMTYPE_OBJECT:
               {
                   CIMObject v;
                   value.get(v);
                   _xmlWritter_appendValue(out, v);
                 break;                 break;
             }             }
  
Line 1392 
Line 1700 
     }     }
 } }
  
   // l10n - added content language and accept language support to
   // the header methods below
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // appendMethodCallHeader() // appendMethodCallHeader()
Line 1406 
Line 1717 
     const CIMName& cimMethod,     const CIMName& cimMethod,
     const String& cimObject,     const String& cimObject,
     const String& authenticationHeader,     const String& authenticationHeader,
       HttpMethod httpMethod,
       const AcceptLanguages & acceptLanguages,
       const ContentLanguages & contentLanguages,
     Uint32 contentLength)     Uint32 contentLength)
 { {
     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
  
       // ATTN: KS 20020926 - Temporary change to issue only POST. This may
       // be changed in the DMTF CIM Operations standard in the future.
       // If we kept M-Post we would have to retry with Post. Does not
       // do that in client today. Permanent change is to retry until spec
       // updated. This change is temp to finish tests or until the retry
       // installed.  Required because of change to wbemservices cimom
       if (httpMethod == HTTP_METHOD_M_POST)
       {
     out << "M-POST /cimom HTTP/1.1\r\n";     out << "M-POST /cimom HTTP/1.1\r\n";
       }
       else
       {
           out << "POST /cimom HTTP/1.1\r\n";
       }
     out << "HOST: " << host << "\r\n";     out << "HOST: " << host << "\r\n";
     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
     out << "Content-Length: " << contentLength << "\r\n";                  OUTPUT_CONTENTLENGTH;
       if (acceptLanguages.size() > 0)
       {
           out << "Accept-Language: " << acceptLanguages << "\r\n";
       }
       if (contentLanguages.size() > 0)
       {
           out << "Content-Language: " << contentLanguages << "\r\n";
       }
   
                   // backdoor environment variable to turn OFF client requesting transfer
                   // encoding. The default is on. to turn off, set this variable to zero.
                   // This should be removed when stable. This should only be turned off in
                   // a debugging/testing environment.
   #ifdef PEGASUS_DEBUG
                   static const char *clientTransferEncodingOff =
                           getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST");
                   if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0')
   #endif
                           out << "TE: chunked, trailers" << "\r\n";
   
       if (httpMethod == HTTP_METHOD_M_POST)
       {
     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
     out << nn <<"\r\n";     out << nn <<"\r\n";
     out << nn << "-CIMOperation: MethodCall\r\n";     out << nn << "-CIMOperation: MethodCall\r\n";
     out << nn << "-CIMMethod: " << cimMethod << "\r\n";          out << nn << "-CIMMethod: "
     out << nn << "-CIMObject: " << cimObject << "\r\n";              << encodeURICharacters(cimMethod.getString()) << "\r\n";
           out << nn << "-CIMObject: " << encodeURICharacters(cimObject) << "\r\n";
       }
       else
       {
           out << "CIMOperation: MethodCall\r\n";
           out << "CIMMethod: " << encodeURICharacters(cimMethod.getString())
               << "\r\n";
           out << "CIMObject: " << encodeURICharacters(cimObject) << "\r\n";
       }
   
     if (authenticationHeader.size())     if (authenticationHeader.size())
     {     {
         out << authenticationHeader << "\r\n";         out << authenticationHeader << "\r\n";
     }     }
   
     out << "\r\n";     out << "\r\n";
 } }
  
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // appendMethodResponseHeader() // appendMethodResponseHeader()
Line 1436 
Line 1797 
  
 void XmlWriter::appendMethodResponseHeader( void XmlWriter::appendMethodResponseHeader(
     Array<Sint8>& out,     Array<Sint8>& out,
       HttpMethod httpMethod,
       const ContentLanguages & contentLanguages,
     Uint32 contentLength)     Uint32 contentLength)
 { {
     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
  
     out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";     out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";
       out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
                   OUTPUT_CONTENTLENGTH;
   
       if (contentLanguages.size() > 0)
       {
           out << "Content-Language: " << contentLanguages << "\r\n";
       }
       if (httpMethod == HTTP_METHOD_M_POST)
       {
           out << "Ext:\r\n";
           out << "Cache-Control: no-cache\r\n";
           out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
           out << nn <<"\r\n";
           out << nn << "-CIMOperation: MethodResponse\r\n\r\n";
       }
       else
       {
           out << "CIMOperation: MethodResponse\r\n\r\n";
       }
   }
   
   
    void XmlWriter::appendMethodResponseHeader(
        Array<Sint8>& out,
        HttpMethod httpMethod,
        const ContentLanguages & contentLanguages,
        Uint32 contentLength,
        Uint64 serverResponseTime)
    {
        char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
   
        out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";
     STAT_SERVERTIME     STAT_SERVERTIME
     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
     out << "Content-Length: " << contentLength << "\r\n";       OUTPUT_CONTENTLENGTH;
   
        if (contentLanguages.size() > 0)
        {
            out << "Content-Language: " << contentLanguages << "\r\n";
        }
        if (httpMethod == HTTP_METHOD_M_POST)
        {
     out << "Ext:\r\n";     out << "Ext:\r\n";
     out << "Cache-Control: no-cache\r\n";     out << "Cache-Control: no-cache\r\n";
     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
     out << nn <<"\r\n";     out << nn <<"\r\n";
     out << nn << "-CIMOperation: MethodResponse\r\n\r\n";     out << nn << "-CIMOperation: MethodResponse\r\n\r\n";
 } }
        else
        {
            out << "CIMOperation: MethodResponse\r\n\r\n";
        }
    }
   
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
Line 1481 
Line 1889 
         // ATTN-RK-P3-20020404: It is critical that this text not contain '\n'         // ATTN-RK-P3-20020404: It is critical that this text not contain '\n'
         // ATTN-RK-P3-20020404: Need to encode this value properly.  (See         // ATTN-RK-P3-20020404: Need to encode this value properly.  (See
         // CIM/HTTP Specification section 3.3.2         // CIM/HTTP Specification section 3.3.2
         out << PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": " << errorDetail << "\r\n";          out << PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": "
               << encodeURICharacters(errorDetail) << "\r\n";
     }     }
     out << "\r\n";     out << "\r\n";
 } }
Line 1523 
Line 1932 
 //    out << "</BODY></HTML>\r\n"; //    out << "</BODY></HTML>\r\n";
 } }
  
   #ifdef PEGASUS_KERBEROS_AUTHENTICATION
   //------------------------------------------------------------------------------
   //
   // appendOKResponseHeader()
   //
   //     Build HTTP authentication response header for unauthorized requests.
   //
   //     Returns OK message in the following format:
   //
   //        HTTP/1.1 200 OK
   //        Content-Length: 0
   //        WWW-Authenticate: Negotiate "token"
   //        <HTML><HEAD>
   //        <TITLE>200 OK</TITLE>
   //        </HEAD><BODY BGCOLOR="#99cc99">
   //        <H2>TEST200 OK</H2>
   //        <HR>
   //        </BODY></HTML>
   //
   //------------------------------------------------------------------------------
   
   void XmlWriter::appendOKResponseHeader(
       Array<Sint8>& out,
       const String& content)
   {
       out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";
       // Content-Length header needs to be added because 200 OK record
       // is usually intended to have content.  But, for Kerberos this
       // may not always be the case so we need to indicate that there
       // is no content
                   Uint32 contentLength = 0;
                   OUTPUT_CONTENTLENGTH;
       out << content << "\r\n";
       out << "\r\n";
   
   //ATTN: We may need to include the following line, so that the browsers
   //      can display the error message.
   //    out << "<HTML><HEAD>\r\n";
   //    out << "<TITLE>" << "200 OK" <<  "</TITLE>\r\n";
   //    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";
   //    out << "<H2>TEST" << "200 OK" << "</H2>\r\n";
   //    out << "<HR>\r\n";
   //    out << "</BODY></HTML>\r\n";
   }
   #endif
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // _appendMessageElementBegin() // _appendMessageElementBegin()
Line 1856 
Line 2311 
     const CIMName& className)     const CIMName& className)
 { {
     _appendIParamValueElementBegin(out, name);     _appendIParamValueElementBegin(out, name);
   
       //
       //  A NULL (unassigned) value for a parameter is specified by an
       //  <IPARAMVALUE> element with no subelement
       //
       if (!className.isNull ())
       {
     appendClassNameElement(out, className);     appendClassNameElement(out, className);
       }
   
     _appendIParamValueElementEnd(out);     _appendIParamValueElementEnd(out);
 } }
  
Line 1991 
Line 2455 
     Array<Sint8>& out,     Array<Sint8>& out,
     const CIMPropertyList& propertyList)     const CIMPropertyList& propertyList)
 { {
     // ATTN: P3 KS 4 Mar 2002 - As check shouldn't we check for null property list  
     _appendIParamValueElementBegin(out, "PropertyList");     _appendIParamValueElementBegin(out, "PropertyList");
  
       //
       //  A NULL (unassigned) value for a parameter is specified by an
       //  <IPARAMVALUE> element with no subelement
       //
       if (!propertyList.isNull ())
       {
     out << "<VALUE.ARRAY>\n";     out << "<VALUE.ARRAY>\n";
     for (Uint32 i = 0; i < propertyList.size(); i++)     for (Uint32 i = 0; i < propertyList.size(); i++)
     {     {
         out << "<VALUE>" << propertyList[i] << "</VALUE>\n";         out << "<VALUE>" << propertyList[i] << "</VALUE>\n";
     }     }
     out << "</VALUE.ARRAY>\n";     out << "</VALUE.ARRAY>\n";
       }
  
     _appendIParamValueElementEnd(out);     _appendIParamValueElementEnd(out);
 } }
Line 2038 
Line 2508 
     return out;     return out;
 } }
  
   // l10n - add content language support to the format methods below
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // XmlWriter::formatSimpleMethodReqMessage() // XmlWriter::formatSimpleMethodReqMessage()
Line 2052 
Line 2524 
     const CIMName& methodName,     const CIMName& methodName,
     const Array<CIMParamValue>& parameters,     const Array<CIMParamValue>& parameters,
     const String& messageId,     const String& messageId,
     const String& authenticationHeader)      HttpMethod httpMethod,
       const String& authenticationHeader,
       const AcceptLanguages& httpAcceptLanguages,
       const ContentLanguages& httpContentLanguages)
 { {
     Array<Sint8> out;     Array<Sint8> out;
     Array<Sint8> tmp;     Array<Sint8> tmp;
Line 2078 
Line 2553 
         methodName,         methodName,
         localObjectPath.toString(),         localObjectPath.toString(),
         authenticationHeader,         authenticationHeader,
           httpMethod,
           httpAcceptLanguages,
           httpContentLanguages,
         out.size());         out.size());
     tmp << out;     tmp << out;
  
Line 2087 
Line 2565 
 Array<Sint8> XmlWriter::formatSimpleMethodRspMessage( Array<Sint8> XmlWriter::formatSimpleMethodRspMessage(
     const CIMName& methodName,     const CIMName& methodName,
     const String& messageId,     const String& messageId,
     const Array<Sint8>& body)      HttpMethod httpMethod,
       const ContentLanguages & httpContentLanguages,
       const Array<Sint8>& body,
                   Boolean isFirst,
                   Boolean isLast)
 { {
     Array<Sint8> out;     Array<Sint8> out;
     Array<Sint8> tmp;  
  
           if (isFirst == true)
           {
                   // NOTE: temporarily put zero for content length. the http code
                   // will later decide to fill in the length or remove it altogether
                   appendMethodResponseHeader(out, httpMethod, httpContentLanguages, 0);
     _appendMessageElementBegin(out, messageId);     _appendMessageElementBegin(out, messageId);
     _appendSimpleRspElementBegin(out);     _appendSimpleRspElementBegin(out);
     _appendMethodResponseElementBegin(out, methodName);     _appendMethodResponseElementBegin(out, methodName);
           }
   
           if (body.size() != 0)
           {
     out << body;     out << body;
           }
   
           if (isLast == true)
           {
     _appendMethodResponseElementEnd(out);     _appendMethodResponseElementEnd(out);
     _appendSimpleRspElementEnd(out);     _appendSimpleRspElementEnd(out);
     _appendMessageElementEnd(out);     _appendMessageElementEnd(out);
           }
  
     appendMethodResponseHeader(tmp, out.size());          return out;
     tmp << out;  }
  
     return tmp;  
   //PEP 128 adding serverRsponseTime to header
   Array<Sint8> XmlWriter::formatSimpleMethodRspMessage(
       const CIMName& methodName,
       const String& messageId,
       HttpMethod httpMethod,
       const ContentLanguages & httpContentLanguages,
       const Array<Sint8>& body,
           Uint64 serverResponseTime,
                   Boolean isFirst,
                   Boolean isLast)
   {
           Array<Sint8> out;
   
           if (isFirst == true)
           {
                   // NOTE: temporarily put zero for content length. the http code
                   // will later decide to fill in the length or remove it altogether
                   appendMethodResponseHeader(out, httpMethod, httpContentLanguages, 0, serverResponseTime);
                   _appendMessageElementBegin(out, messageId);
                   _appendSimpleRspElementBegin(out);
                   _appendMethodResponseElementBegin(out, methodName);
           }
   
           if (body.size() != 0)
           {
                   out << body;
 } }
  
           if (isLast == true)
           {
                   _appendMethodResponseElementEnd(out);
                   _appendSimpleRspElementEnd(out);
                   _appendMessageElementEnd(out);
           }
   
           return out;
   }
   
   
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // XmlWriter::formatSimpleMethodErrorRspMessage() // XmlWriter::formatSimpleMethodErrorRspMessage()
Line 2115 
Line 2648 
 Array<Sint8> XmlWriter::formatSimpleMethodErrorRspMessage( Array<Sint8> XmlWriter::formatSimpleMethodErrorRspMessage(
     const CIMName& methodName,     const CIMName& methodName,
     const String& messageId,     const String& messageId,
       HttpMethod httpMethod,
     const CIMException& cimException)     const CIMException& cimException)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 2128 
Line 2662 
     _appendSimpleRspElementEnd(out);     _appendSimpleRspElementEnd(out);
     _appendMessageElementEnd(out);     _appendMessageElementEnd(out);
  
     appendMethodResponseHeader(tmp, out.size());  // l10n
       appendMethodResponseHeader(tmp,
           httpMethod,
           cimException.getContentLanguages(),
           out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2145 
Line 2683 
     const CIMNamespaceName& nameSpace,     const CIMNamespaceName& nameSpace,
     const CIMName& iMethodName,     const CIMName& iMethodName,
     const String& messageId,     const String& messageId,
       HttpMethod httpMethod,
     const String& authenticationHeader,     const String& authenticationHeader,
       const AcceptLanguages& httpAcceptLanguages,
       const ContentLanguages& httpContentLanguages,
     const Array<Sint8>& body)     const Array<Sint8>& body)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 2166 
Line 2707 
         iMethodName,         iMethodName,
         nameSpace.getString(),         nameSpace.getString(),
         authenticationHeader,         authenticationHeader,
           httpMethod,
           httpAcceptLanguages,
           httpContentLanguages,
         out.size());         out.size());
     tmp << out;     tmp << out;
  
Line 2181 
Line 2725 
 Array<Sint8> XmlWriter::formatSimpleIMethodRspMessage( Array<Sint8> XmlWriter::formatSimpleIMethodRspMessage(
     const CIMName& iMethodName,     const CIMName& iMethodName,
     const String& messageId,     const String& messageId,
     const Array<Sint8>& body)      HttpMethod httpMethod,
       const ContentLanguages & httpContentLanguages,
       const Array<Sint8>& body,
                   Boolean isFirst,
                   Boolean isLast)
 { {
     Array<Sint8> out;     Array<Sint8> out;
     Array<Sint8> tmp;  
  
                   if (isFirst == true)
                   {
                           // NOTE: temporarily put zero for content length. the http code
                           // will later decide to fill in the length or remove it altogether
                           appendMethodResponseHeader(out, httpMethod, httpContentLanguages, 0);
     _appendMessageElementBegin(out, messageId);     _appendMessageElementBegin(out, messageId);
     _appendSimpleRspElementBegin(out);     _appendSimpleRspElementBegin(out);
     _appendIMethodResponseElementBegin(out, iMethodName);     _appendIMethodResponseElementBegin(out, iMethodName);
     if (body.size() != 0)     if (body.size() != 0)
     {  
         _appendIReturnValueElementBegin(out);         _appendIReturnValueElementBegin(out);
                   }
   
       if (body.size() != 0)
       {
         out << body;         out << body;
         _appendIReturnValueElementEnd(out);  
     }     }
   
                   if (isLast == true)
                   {
                           if (body.size() != 0)
                                   _appendIReturnValueElementEnd(out);
     _appendIMethodResponseElementEnd(out);     _appendIMethodResponseElementEnd(out);
     _appendSimpleRspElementEnd(out);     _appendSimpleRspElementEnd(out);
     _appendMessageElementEnd(out);     _appendMessageElementEnd(out);
                   }
  
     appendMethodResponseHeader(tmp, out.size());      return out;
     tmp << out;  }
  
     return tmp;  
   
   Array<Sint8> XmlWriter::formatSimpleIMethodRspMessage(
       const CIMName& iMethodName,
       const String& messageId,
       HttpMethod httpMethod,
       const ContentLanguages & httpContentLanguages,
       const Array<Sint8>& body,
           Uint64 serverResponseTime,
                   Boolean isFirst,
                   Boolean isLast)
   {
       Array<Sint8> out;
   
                   if (isFirst == true)
                   {
                           // NOTE: temporarily put zero for content length. the http code
                           // will later decide to fill in the length or remove it altogether
                           appendMethodResponseHeader(out, httpMethod, httpContentLanguages, 0, serverResponseTime);
                           _appendMessageElementBegin(out, messageId);
                           _appendSimpleRspElementBegin(out);
                           _appendIMethodResponseElementBegin(out, iMethodName);
                           if (body.size() != 0)
                                   _appendIReturnValueElementBegin(out);
                   }
   
       if (body.size() != 0)
       {
                           out << body;
       }
   
                   if (isLast == true)
                   {
                           if (body.size() != 0)
                                   _appendIReturnValueElementEnd(out);
                           _appendIMethodResponseElementEnd(out);
                           _appendSimpleRspElementEnd(out);
                           _appendMessageElementEnd(out);
                   }
   
       return out;
 } }
  
   
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // XmlWriter::formatSimpleIMethodErrorRspMessage() // XmlWriter::formatSimpleIMethodErrorRspMessage()
Line 2214 
Line 2815 
 Array<Sint8> XmlWriter::formatSimpleIMethodErrorRspMessage( Array<Sint8> XmlWriter::formatSimpleIMethodErrorRspMessage(
     const CIMName& iMethodName,     const CIMName& iMethodName,
     const String& messageId,     const String& messageId,
       HttpMethod httpMethod,
     const CIMException& cimException)     const CIMException& cimException)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 2227 
Line 2829 
     _appendSimpleRspElementEnd(out);     _appendSimpleRspElementEnd(out);
     _appendMessageElementEnd(out);     _appendMessageElementEnd(out);
  
     appendMethodResponseHeader(tmp, out.size());  // l10n
       appendMethodResponseHeader(tmp,
            httpMethod,
            cimException.getContentLanguages(),
            out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2252 
Line 2858 
     const char* requestUri,     const char* requestUri,
     const char* host,     const char* host,
     const CIMName& cimMethod,     const CIMName& cimMethod,
       HttpMethod httpMethod,
     const String& authenticationHeader,     const String& authenticationHeader,
       const AcceptLanguages& acceptLanguages,
       const ContentLanguages& contentLanguages,
     Uint32 contentLength)     Uint32 contentLength)
 { {
     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
  
       if (httpMethod == HTTP_METHOD_M_POST)
       {
     out << "M-POST " << requestUri << " HTTP/1.1\r\n";     out << "M-POST " << requestUri << " HTTP/1.1\r\n";
       }
       else
       {
         out << "POST " << requestUri << " HTTP/1.1\r\n";
       }
     out << "HOST: " << host << "\r\n";     out << "HOST: " << host << "\r\n";
     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
     out << "Content-Length: " << contentLength << "\r\n";                  OUTPUT_CONTENTLENGTH;
     out << "Man: http://www.hp.com; ns=";  
       if (acceptLanguages.size() > 0)
       {
           out << "Accept-Language: " << acceptLanguages << "\r\n";
       }
       if (contentLanguages.size() > 0)
       {
           out << "Content-Language: " << contentLanguages << "\r\n";
       }
   
                   // backdoor environment variable to turn OFF client requesting transfer
                   // encoding. The default is on. to turn off, set this variable to zero.
                   // This should be removed when stable. This should only be turned off in
                   // a debugging/testing environment.
   #ifdef PEGASUS_DEBUG
                   static const char *clientTransferEncodingOff =
                           getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST");
                   if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0')
   #endif
                           out << "TE: chunked, trailers" << "\r\n";
   
       if (httpMethod == HTTP_METHOD_M_POST)
       {
           out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
     out << nn <<"\r\n";     out << nn <<"\r\n";
     out << nn << "-CIMExport: MethodRequest\r\n";     out << nn << "-CIMExport: MethodRequest\r\n";
     out << nn << "-CIMExportMethod: " << cimMethod << "\r\n";     out << nn << "-CIMExportMethod: " << cimMethod << "\r\n";
       }
       else
       {
           out << "CIMExport: MethodRequest\r\n";
           out << "CIMExportMethod: " << cimMethod << "\r\n";
       }
   
     if (authenticationHeader.size())     if (authenticationHeader.size())
     {     {
         out << authenticationHeader << "\r\n";         out << authenticationHeader << "\r\n";
     }     }
   
     out << "\r\n";     out << "\r\n";
 } }
  
Line 2282 
Line 2929 
  
 void XmlWriter::appendEMethodResponseHeader( void XmlWriter::appendEMethodResponseHeader(
     Array<Sint8>& out,     Array<Sint8>& out,
       HttpMethod httpMethod,
       const ContentLanguages& contentLanguages,
     Uint32 contentLength)     Uint32 contentLength)
 { {
     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };     char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
  
     out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";     out << "HTTP/1.1 " HTTP_STATUS_OK "\r\n";
     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";     out << "Content-Type: application/xml; charset=\"utf-8\"\r\n";
     out << "Content-Length: " << contentLength << "\r\n";                  OUTPUT_CONTENTLENGTH;
   
       if (contentLanguages.size() > 0)
       {
           out << "Content-Language: " << contentLanguages << "\r\n";
       }
       if (httpMethod == HTTP_METHOD_M_POST)
       {
     out << "Ext:\r\n";     out << "Ext:\r\n";
     out << "Cache-Control: no-cache\r\n";     out << "Cache-Control: no-cache\r\n";
     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
     out << nn <<"\r\n";     out << nn <<"\r\n";
     out << nn << "-CIMExport: MethodResponse\r\n\r\n";     out << nn << "-CIMExport: MethodResponse\r\n\r\n";
 } }
       else
       {
           out << "CIMExport: MethodResponse\r\n\r\n";
       }
   }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
Line 2342 
Line 3003 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
   // _appendEParamValueElementBegin()
   // _appendEParamValueElementEnd()
   //
   //     <!ELEMENT EXPPARAMVALUE (INSTANCE)>
   //     <!ATTLIST EXPPARAMVALUE
   //         %CIMName;>
   //
   //------------------------------------------------------------------------------
   
   void XmlWriter::_appendEParamValueElementBegin(
       Array<Sint8>& out,
       const char* name)
   {
       out << "<EXPPARAMVALUE NAME=\"" << name << "\">\n";
   }
   
   void XmlWriter::_appendEParamValueElementEnd(
       Array<Sint8>& out)
   {
       out << "</EXPPARAMVALUE>\n";
   }
   
   //------------------------------------------------------------------------------
   //
   // appendInstanceEParameter()
   //
   //------------------------------------------------------------------------------
   
   void XmlWriter::appendInstanceEParameter(
       Array<Sint8>& out,
       const char* name,
       const CIMInstance& instance)
   {
       _appendEParamValueElementBegin(out, name);
       appendInstanceElement(out, instance);
       _appendEParamValueElementEnd(out);
   }
   
   //------------------------------------------------------------------------------
   //
 // _appendSimpleExportRspElementBegin() // _appendSimpleExportRspElementBegin()
 // _appendSimpleExportRspElementEnd() // _appendSimpleExportRspElementEnd()
 // //
Line 2395 
Line 3096 
     const char* host,     const char* host,
     const CIMName& eMethodName,     const CIMName& eMethodName,
     const String& messageId,     const String& messageId,
       HttpMethod httpMethod,
     const String& authenticationHeader,     const String& authenticationHeader,
       const AcceptLanguages& httpAcceptLanguages,
       const ContentLanguages& httpContentLanguages,
     const Array<Sint8>& body)     const Array<Sint8>& body)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 2414 
Line 3118 
         requestUri,         requestUri,
         host,         host,
         eMethodName,         eMethodName,
           httpMethod,
         authenticationHeader,         authenticationHeader,
           httpAcceptLanguages,
           httpContentLanguages,
         out.size());         out.size());
     tmp << out;     tmp << out;
  
Line 2430 
Line 3137 
 Array<Sint8> XmlWriter::formatSimpleEMethodRspMessage( Array<Sint8> XmlWriter::formatSimpleEMethodRspMessage(
     const CIMName& eMethodName,     const CIMName& eMethodName,
     const String& messageId,     const String& messageId,
       HttpMethod httpMethod,
       const ContentLanguages& httpContentLanguages,
     const Array<Sint8>& body)     const Array<Sint8>& body)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 2443 
Line 3152 
     _appendSimpleExportRspElementEnd(out);     _appendSimpleExportRspElementEnd(out);
     _appendMessageElementEnd(out);     _appendMessageElementEnd(out);
  
     appendEMethodResponseHeader(tmp, out.size());      appendEMethodResponseHeader(tmp,
           httpMethod,
           httpContentLanguages,
           out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2458 
Line 3170 
 Array<Sint8> XmlWriter::formatSimpleEMethodErrorRspMessage( Array<Sint8> XmlWriter::formatSimpleEMethodErrorRspMessage(
     const CIMName& eMethodName,     const CIMName& eMethodName,
     const String& messageId,     const String& messageId,
       HttpMethod httpMethod,
     const CIMException& cimException)     const CIMException& cimException)
 { {
     Array<Sint8> out;     Array<Sint8> out;
Line 2471 
Line 3184 
     _appendSimpleExportRspElementEnd(out);     _appendSimpleExportRspElementEnd(out);
     _appendMessageElementEnd(out);     _appendMessageElementEnd(out);
  
     appendEMethodResponseHeader(tmp, out.size());  // l10n
       appendEMethodResponseHeader(tmp,
            httpMethod,
            cimException.getContentLanguages(),
                    out.size());
     tmp << out;     tmp << out;
  
     return tmp;     return tmp;
Line 2479 
Line 3196 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // _printAttributes()  // _xmlWritter_printAttributes()
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 static void _printAttributes(  void _xmlWritter_printAttributes(
     PEGASUS_STD(ostream)& os,     PEGASUS_STD(ostream)& os,
     const XmlAttribute* attributes,     const XmlAttribute* attributes,
     Uint32 attributeCount)     Uint32 attributeCount)
Line 2493 
Line 3210 
         os << attributes[i].name << "=";         os << attributes[i].name << "=";
  
         os << '"';         os << '"';
         _appendSpecial(os, attributes[i].value);          _xmlWritter_appendSpecial(os, attributes[i].value);
         os << '"';         os << '"';
  
         if (i + 1 != attributeCount)         if (i + 1 != attributeCount)
Line 2503 
Line 3220 
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
 // //
 // _indent()  // _xmlWritter_indent()
 // //
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
  
 static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars)  void _xmlWritter_indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars)
 { {
     Uint32 n = level * indentChars;     Uint32 n = level * indentChars;
  
Line 2526 
Line 3243 
     const char* text,     const char* text,
     Uint32 indentChars)     Uint32 indentChars)
 { {
     char* tmp = strcpy(new char[strlen(text) + 1], text);      AutoArrayPtr<char> tmp(strcpy(new char[strlen(text) + 1], text));
  
     XmlParser parser(tmp);      XmlParser parser(tmp.get());
     XmlEntry entry;     XmlEntry entry;
     Stack<const char*> stack;     Stack<const char*> stack;
  
Line 2538 
Line 3255 
         {         {
             case XmlEntry::XML_DECLARATION:             case XmlEntry::XML_DECLARATION:
             {             {
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
  
                 os << "<?" << entry.text << " ";                 os << "<?" << entry.text << " ";
                 _printAttributes(os, entry.attributes, entry.attributeCount);                  _xmlWritter_printAttributes(os, entry.attributes, entry.attributeCount);
                 os << "?>";                 os << "?>";
                 break;                 break;
             }             }
  
             case XmlEntry::START_TAG:             case XmlEntry::START_TAG:
             {             {
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
  
                 os << "<" << entry.text;                 os << "<" << entry.text;
  
                 if (entry.attributeCount)                 if (entry.attributeCount)
                     os << ' ';                     os << ' ';
  
                 _printAttributes(os, entry.attributes, entry.attributeCount);                  _xmlWritter_printAttributes(os, entry.attributes, entry.attributeCount);
                 os << ">";                 os << ">";
                 stack.push(entry.text);                 stack.push(entry.text);
                 break;                 break;
Line 2563 
Line 3280 
  
             case XmlEntry::EMPTY_TAG:             case XmlEntry::EMPTY_TAG:
             {             {
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
  
                 os << "<" << entry.text << " ";                 os << "<" << entry.text << " ";
                 _printAttributes(os, entry.attributes, entry.attributeCount);                  _xmlWritter_printAttributes(os, entry.attributes, entry.attributeCount);
                 os << "/>";                 os << "/>";
                 break;                 break;
             }             }
Line 2576 
Line 3293 
                 if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)                 if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
                     stack.pop();                     stack.pop();
  
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
  
                 os << "</" << entry.text << ">";                 os << "</" << entry.text << ">";
                 break;                 break;
Line 2585 
Line 3302 
             case XmlEntry::COMMENT:             case XmlEntry::COMMENT:
             {             {
  
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
                 os << "<!--";                 os << "<!--";
                 _appendSpecial(os, entry.text);                  _xmlWritter_appendSpecial(os, entry.text);
                 os << "-->";                 os << "-->";
                 break;                 break;
             }             }
  
             case XmlEntry::CONTENT:             case XmlEntry::CONTENT:
             {             {
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
                 _appendSpecial(os, entry.text);                  _xmlWritter_appendSpecial(os, entry.text);
                 break;                 break;
             }             }
  
             case XmlEntry::CDATA:             case XmlEntry::CDATA:
             {             {
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
                 os << "<![CDATA[...]]>";                 os << "<![CDATA[...]]>";
                 break;                 break;
             }             }
  
             case XmlEntry::DOCTYPE:             case XmlEntry::DOCTYPE:
             {             {
                 _indent(os, stack.size(), indentChars);                  _xmlWritter_indent(os, stack.size(), indentChars);
                 os << "<!DOCTYPE...>";                 os << "<!DOCTYPE...>";
                 break;                 break;
             }             }
Line 2617 
Line 3334 
         os << PEGASUS_STD(endl);         os << PEGASUS_STD(endl);
     }     }
  
     delete [] tmp;  
 } }
  
 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Line 2668 
Line 3384 
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
   
   


Legend:
Removed from v.1.80  
changed lines
  Added in v.1.111.2.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2