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

   1 karl  1.135 //%2006////////////////////////////////////////////////////////////////////////
   2 mike  1.23  //
   3 karl  1.112 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   4             // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   5             // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   6 karl  1.100 // IBM Corp.; EMC Corporation, The Open Group.
   7 karl  1.112 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   8             // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   9 karl  1.116 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl  1.135 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12             // EMC Corporation; Symantec Corporation; The Open Group.
  13 mike  1.23  //
  14             // Permission is hereby granted, free of charge, to any person obtaining a copy
  15 kumpf 1.63  // of this software and associated documentation files (the "Software"), to
  16             // deal in the Software without restriction, including without limitation the
  17             // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18 mike  1.23  // sell copies of the Software, and to permit persons to whom the Software is
  19             // furnished to do so, subject to the following conditions:
  20 karl  1.135 // 
  21 kumpf 1.63  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22 mike  1.23  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23             // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24 kumpf 1.63  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25             // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26             // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27 mike  1.23  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28             // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29             //
  30             //==============================================================================
  31             //
  32             //%/////////////////////////////////////////////////////////////////////////////
  33             
  34 sage  1.49  #include <Pegasus/Common/Config.h>
  35 mike  1.23  #include <cstdlib>
  36             #include <cstdio>
  37 kumpf 1.46  #include "Constants.h"
  38 mike  1.23  #include "CIMClass.h"
  39 kumpf 1.55  #include "CIMClassRep.h"
  40 mike  1.23  #include "CIMInstance.h"
  41 kumpf 1.55  #include "CIMInstanceRep.h"
  42 kumpf 1.56  #include "CIMProperty.h"
  43             #include "CIMPropertyRep.h"
  44             #include "CIMMethod.h"
  45             #include "CIMMethodRep.h"
  46             #include "CIMParameter.h"
  47             #include "CIMParameterRep.h"
  48             #include "CIMParamValue.h"
  49             #include "CIMParamValueRep.h"
  50             #include "CIMQualifier.h"
  51             #include "CIMQualifierRep.h"
  52             #include "CIMQualifierDecl.h"
  53             #include "CIMQualifierDeclRep.h"
  54 kumpf 1.54  #include "CIMValue.h"
  55 mike  1.23  #include "XmlWriter.h"
  56             #include "XmlParser.h"
  57 kumpf 1.44  #include "Tracer.h"
  58 sage  1.49  #include <Pegasus/Common/StatisticalData.h>
  59 david 1.92  #include "CommonUTF.h"
  60 mike  1.125 #include "Buffer.h"
  61 mike  1.127 #include "StrLit.h"
  62 kumpf 1.132 #include "LanguageParser.h"
  63 mike  1.139 #include "IDFactory.h"
  64 mike  1.23  
  65             PEGASUS_NAMESPACE_BEGIN
  66             
  67 brian.campbell 1.107 // This is a shortcut macro for outputing content length. This
  68                      // pads the output number to the max characters representing a Uint32 number
  69                      // so that it can be overwritten easily with a transfer encoding line later
  70                      // on in HTTPConnection if required. This is strictly for performance since
  71                      // messages can be very large. This overwriting shortcut allows us to NOT have
  72                      // to repackage a large message later.
  73                      
  74 kumpf          1.146 #define OUTPUT_CONTENTLENGTH                                               \
  75                      {                                                                          \
  76                          char contentLengthP[11];                                               \
  77                          int n = sprintf(contentLengthP,"%.10u", contentLength);                \
  78                          out << STRLIT("content-length: ");                                     \
  79                          out.append(contentLengthP, n);                                         \
  80                          out << STRLIT("\r\n");                                                 \
  81 mike           1.126 }
  82                      
  83                      ////////////////////////////////////////////////////////////////////////////////
  84                      //
  85                      // SpecialChar and table.
  86                      //
  87                      ////////////////////////////////////////////////////////////////////////////////
  88                      
  89 david.dillard  1.130 // Note: we cannot use StrLit here since it has a constructur (forbits
  90 mike           1.127 // structure initialization).
  91                      
  92 mike           1.126 struct SpecialChar
  93                      {
  94                          const char* str;
  95 kumpf          1.148     Uint32 size;
  96 mike           1.126 };
  97                      
  98                      // Defines encodings of special characters. Just use a 7-bit ASCII character
  99                      // as an index into this array to retrieve its string encoding and encoding
 100                      // length in bytes.
 101                      static const SpecialChar _specialChars[] =
 102                      {
 103 mike           1.127     {STRLIT_ARGS("&#0;")},
 104                          {STRLIT_ARGS("&#1;")},
 105                          {STRLIT_ARGS("&#2;")},
 106                          {STRLIT_ARGS("&#3;")},
 107                          {STRLIT_ARGS("&#4;")},
 108                          {STRLIT_ARGS("&#5;")},
 109                          {STRLIT_ARGS("&#6;")},
 110                          {STRLIT_ARGS("&#7;")},
 111                          {STRLIT_ARGS("&#8;")},
 112                          {STRLIT_ARGS("&#9;")},
 113                          {STRLIT_ARGS("&#10;")},
 114                          {STRLIT_ARGS("&#11;")},
 115                          {STRLIT_ARGS("&#12;")},
 116                          {STRLIT_ARGS("&#13;")},
 117                          {STRLIT_ARGS("&#14;")},
 118                          {STRLIT_ARGS("&#15;")},
 119                          {STRLIT_ARGS("&#16;")},
 120                          {STRLIT_ARGS("&#17;")},
 121                          {STRLIT_ARGS("&#18;")},
 122                          {STRLIT_ARGS("&#19;")},
 123                          {STRLIT_ARGS("&#20;")},
 124 mike           1.127     {STRLIT_ARGS("&#21;")},
 125                          {STRLIT_ARGS("&#22;")},
 126                          {STRLIT_ARGS("&#23;")},
 127                          {STRLIT_ARGS("&#24;")},
 128                          {STRLIT_ARGS("&#25;")},
 129                          {STRLIT_ARGS("&#26;")},
 130                          {STRLIT_ARGS("&#27;")},
 131                          {STRLIT_ARGS("&#28;")},
 132                          {STRLIT_ARGS("&#29;")},
 133                          {STRLIT_ARGS("&#30;")},
 134                          {STRLIT_ARGS("&#31;")},
 135                          {STRLIT_ARGS(" ")},
 136                          {STRLIT_ARGS("!")},
 137                          {STRLIT_ARGS("&quot;")},
 138                          {STRLIT_ARGS("#")},
 139                          {STRLIT_ARGS("$")},
 140                          {STRLIT_ARGS("%")},
 141                          {STRLIT_ARGS("&amp;")},
 142                          {STRLIT_ARGS("&apos;")},
 143                          {STRLIT_ARGS("(")},
 144                          {STRLIT_ARGS(")")},
 145 mike           1.127     {STRLIT_ARGS("*")},
 146                          {STRLIT_ARGS("+")},
 147                          {STRLIT_ARGS(",")},
 148                          {STRLIT_ARGS("-")},
 149                          {STRLIT_ARGS(".")},
 150                          {STRLIT_ARGS("/")},
 151                          {STRLIT_ARGS("0")},
 152                          {STRLIT_ARGS("1")},
 153                          {STRLIT_ARGS("2")},
 154                          {STRLIT_ARGS("3")},
 155                          {STRLIT_ARGS("4")},
 156                          {STRLIT_ARGS("5")},
 157                          {STRLIT_ARGS("6")},
 158                          {STRLIT_ARGS("7")},
 159                          {STRLIT_ARGS("8")},
 160                          {STRLIT_ARGS("9")},
 161                          {STRLIT_ARGS(":")},
 162                          {STRLIT_ARGS(";")},
 163                          {STRLIT_ARGS("&lt;")},
 164                          {STRLIT_ARGS("=")},
 165                          {STRLIT_ARGS("&gt;")},
 166 mike           1.127     {STRLIT_ARGS("?")},
 167                          {STRLIT_ARGS("@")},
 168                          {STRLIT_ARGS("A")},
 169                          {STRLIT_ARGS("B")},
 170                          {STRLIT_ARGS("C")},
 171                          {STRLIT_ARGS("D")},
 172                          {STRLIT_ARGS("E")},
 173                          {STRLIT_ARGS("F")},
 174                          {STRLIT_ARGS("G")},
 175                          {STRLIT_ARGS("H")},
 176                          {STRLIT_ARGS("I")},
 177                          {STRLIT_ARGS("J")},
 178                          {STRLIT_ARGS("K")},
 179                          {STRLIT_ARGS("L")},
 180                          {STRLIT_ARGS("M")},
 181                          {STRLIT_ARGS("N")},
 182                          {STRLIT_ARGS("O")},
 183                          {STRLIT_ARGS("P")},
 184                          {STRLIT_ARGS("Q")},
 185                          {STRLIT_ARGS("R")},
 186                          {STRLIT_ARGS("S")},
 187 mike           1.127     {STRLIT_ARGS("T")},
 188                          {STRLIT_ARGS("U")},
 189                          {STRLIT_ARGS("V")},
 190                          {STRLIT_ARGS("W")},
 191                          {STRLIT_ARGS("X")},
 192                          {STRLIT_ARGS("Y")},
 193                          {STRLIT_ARGS("Z")},
 194                          {STRLIT_ARGS("[")},
 195                          {STRLIT_ARGS("\\")},
 196                          {STRLIT_ARGS("]")},
 197                          {STRLIT_ARGS("^")},
 198                          {STRLIT_ARGS("_")},
 199                          {STRLIT_ARGS("`")},
 200                          {STRLIT_ARGS("a")},
 201                          {STRLIT_ARGS("b")},
 202                          {STRLIT_ARGS("c")},
 203                          {STRLIT_ARGS("d")},
 204                          {STRLIT_ARGS("e")},
 205                          {STRLIT_ARGS("f")},
 206                          {STRLIT_ARGS("g")},
 207                          {STRLIT_ARGS("h")},
 208 mike           1.127     {STRLIT_ARGS("i")},
 209                          {STRLIT_ARGS("j")},
 210                          {STRLIT_ARGS("k")},
 211                          {STRLIT_ARGS("l")},
 212                          {STRLIT_ARGS("m")},
 213                          {STRLIT_ARGS("n")},
 214                          {STRLIT_ARGS("o")},
 215                          {STRLIT_ARGS("p")},
 216                          {STRLIT_ARGS("q")},
 217                          {STRLIT_ARGS("r")},
 218                          {STRLIT_ARGS("s")},
 219                          {STRLIT_ARGS("t")},
 220                          {STRLIT_ARGS("u")},
 221                          {STRLIT_ARGS("v")},
 222                          {STRLIT_ARGS("w")},
 223                          {STRLIT_ARGS("x")},
 224                          {STRLIT_ARGS("y")},
 225                          {STRLIT_ARGS("z")},
 226                          {STRLIT_ARGS("{")},
 227                          {STRLIT_ARGS("|")},
 228                          {STRLIT_ARGS("}")},
 229 mike           1.127     {STRLIT_ARGS("~")},
 230                          {STRLIT_ARGS("&#127;")},
 231 mike           1.126 };
 232                      
 233                      // If _isSpecialChar7[ch] is true, then ch is a special character, which must
 234                      // have a special encoding in XML. But only use 7-bit ASCII characters to
 235                      // index this array.
 236 david.dillard  1.130 static const int _isSpecialChar7[] =
 237 mike           1.126 {
 238                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,
 239 r.kieninger    1.138     0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
 240 mike           1.126     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 241                          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
 242                      };
 243                      
 244                      ////////////////////////////////////////////////////////////////////////////////
 245 brian.campbell 1.107 
 246 mike           1.125 Buffer& operator<<(Buffer& out, const Char16& x)
 247 kumpf          1.27  {
 248                          XmlWriter::append(out, x);
 249                          return out;
 250                      }
 251                      
 252 mike           1.125 Buffer& operator<<(Buffer& out, const String& x)
 253 kumpf          1.27  {
 254                          XmlWriter::append(out, x);
 255                          return out;
 256                      }
 257                      
 258 mike           1.125 Buffer& operator<<(Buffer& out, const Indentor& x)
 259 kumpf          1.27  {
 260                          XmlWriter::append(out, x);
 261                          return out;
 262                      }
 263                      
 264 mike           1.125 Buffer& operator<<(Buffer& out, const Buffer& x)
 265 kumpf          1.27  {
 266 mike           1.125     out.append(x.getData(), x.size());
 267 kumpf          1.27      return out;
 268                      }
 269                      
 270 mike           1.125 Buffer& operator<<(Buffer& out, Uint32 x)
 271 kumpf          1.27  {
 272                          XmlWriter::append(out, x);
 273                          return out;
 274                      }
 275                      
 276 mike           1.125 Buffer& operator<<(Buffer& out, const CIMName& name)
 277 kumpf          1.80  {
 278                          XmlWriter::append(out, name.getString ());
 279                          return out;
 280                      }
 281                      
 282 david.dillard  1.121 
 283 kumpf          1.133 Buffer& operator<<(Buffer& out, const AcceptLanguageList& al)
 284 chuck          1.89  {
 285 kumpf          1.132     XmlWriter::append(out, LanguageParser::buildAcceptLanguageHeader(al));
 286 chuck          1.89      return out;
 287                      }
 288                      
 289 kumpf          1.133 Buffer& operator<<(Buffer& out, const ContentLanguageList& cl)
 290 chuck          1.89  {
 291 kumpf          1.132     XmlWriter::append(out, LanguageParser::buildContentLanguageHeader(cl));
 292 chuck          1.89      return out;
 293                      }
 294                      
 295                      
 296 kumpf          1.72  PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMDateTime& x)
 297                      {
 298                          return os << x.toString();
 299                      }
 300                      
 301 kumpf          1.80  PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os, const CIMName& name)
 302                      {
 303                          os << name.getString();
 304                          return os;
 305                      }
 306                      
 307                      PEGASUS_STD(ostream)& operator<<(PEGASUS_STD(ostream)& os,
 308                          const CIMNamespaceName& name)
 309                      {
 310                          os << name.getString();
 311                          return os;
 312                      }
 313                      
 314 mike           1.126 static void _xmlWritter_appendChar(Buffer& out, const Char16& c)
 315 mike           1.23  {
 316 david          1.92      // We need to convert the Char16 to UTF8 then append the UTF8
 317                          // character into the array.
 318                          // NOTE: The UTF8 character could be several bytes long.
 319                          // WARNING: This function will put in replacement character for
 320                          // all characters that have surogate pairs.
 321 david.dillard  1.115     char str[6];
 322 david          1.92      memset(str,0x00,sizeof(str));
 323 chuck          1.94      Uint8* charIN = (Uint8 *)&c;
 324 david          1.92  
 325                          const Uint16 *strsrc = (Uint16 *)charIN;
 326                          Uint16 *endsrc = (Uint16 *)&charIN[1];
 327                      
 328                          Uint8 *strtgt = (Uint8 *)str;
 329                          Uint8 *endtgt = (Uint8 *)&str[5];
 330                      
 331 kumpf          1.146     UTF16toUTF8(
 332                              &strsrc,
 333                              endsrc,
 334                              &strtgt,
 335                              endtgt);
 336 david          1.92  
 337 david.dillard  1.115     out.append(str, UTF_8_COUNT_TRAIL_BYTES(str[0]) + 1);
 338 mike           1.23  }
 339                      
 340 mike           1.126 inline void _appendSpecialChar7(Buffer& out, char c)
 341 mike           1.23  {
 342 mike           1.126     if (_isSpecialChar7[int(c)])
 343 david.dillard  1.131         out.append(_specialChars[int(c)].str, _specialChars[int(c)].size);
 344 david          1.92      else
 345 david.dillard  1.131         out.append(c);
 346 david          1.92  }
 347 mike           1.23  
 348 mike           1.126 inline void _xmlWritter_appendSpecialChar(Buffer& out, const Char16& c)
 349 david          1.92  {
 350 mike           1.126     if (c < 128)
 351 david.dillard  1.131         _appendSpecialChar7(out, char(c));
 352 kumpf          1.87      else
 353 david.dillard  1.131         _xmlWritter_appendChar(out, c);
 354 mike           1.23  }
 355                      
 356 mike           1.126 static void _xmlWritter_appendSpecialChar(PEGASUS_STD(ostream)& os, char c)
 357 kumpf          1.27  {
 358 mateus.baur    1.119     if ( ((c < 0x20) && (c >= 0)) || (c == 0x7f) )
 359 kumpf          1.27      {
 360 kumpf          1.87          char charref[7];
 361 david.dillard  1.121         sprintf(charref, "&#%u;", static_cast<Uint8>(c));
 362 kumpf          1.87          os << charref;
 363                          }
 364                          else
 365                          {
 366                              switch (c)
 367                              {
 368                                  case '&':
 369                                      os << "&amp;";
 370                                      break;
 371                      
 372                                  case '<':
 373                                      os << "&lt;";
 374                                      break;
 375                      
 376                                  case '>':
 377                                      os << "&gt;";
 378                                      break;
 379                      
 380                                  case '"':
 381                                      os << "&quot;";
 382                                      break;
 383 kumpf          1.87  
 384                                  case '\'':
 385                                      os << "&apos;";
 386                                      break;
 387                      
 388                                  default:
 389                                      os << c;
 390                              }
 391 kumpf          1.27      }
 392                      }
 393                      
 394 mike           1.125 void _xmlWritter_appendSurrogatePair(Buffer& out, Uint16 high, Uint16 low)
 395 david          1.92  {
 396 david.dillard  1.115     char str[6];
 397 chuck          1.94      Uint8 charIN[5];
 398 david          1.92      memset(str,0x00,sizeof(str));
 399                          memcpy(&charIN,&high,2);
 400                          memcpy(&charIN[2],&low,2);
 401                          const Uint16 *strsrc = (Uint16 *)charIN;
 402                          Uint16 *endsrc = (Uint16 *)&charIN[3];
 403                      
 404                          Uint8 *strtgt = (Uint8 *)str;
 405                          Uint8 *endtgt = (Uint8 *)&str[5];
 406                      
 407 kumpf          1.146     UTF16toUTF8(
 408                              &strsrc,
 409                              endsrc,
 410                              &strtgt,
 411                              endtgt);
 412 david          1.92  
 413 chuck          1.104     Uint32 number1 = UTF_8_COUNT_TRAIL_BYTES(str[0]) + 1;
 414 david.dillard  1.115     out.append(str,number1);
 415 david          1.92  }
 416                      
 417 s.hills        1.99  inline void _xmlWritter_appendSpecial(PEGASUS_STD(ostream)& os, const char* str)
 418 kumpf          1.27  {
 419                          while (*str)
 420 david.dillard  1.131         _xmlWritter_appendSpecialChar(os, *str++);
 421 kumpf          1.27  }
 422                      
 423 venkat.puvvada 1.149 // On windows sprintf outputs 3 digit precision exponent prepending
 424                      // zeros. Make it 2 digit precision if first digit is zero in the exponent.
 425                      #ifdef PEGASUS_OS_TYPE_WINDOWS
 426                      inline void _xmlWriter_normalizeRealValueString(char *str)
 427                      {
 428                          // skip initial sign value...
 429                          if (*str == '-' || *str == '+')
 430                          {
 431                              ++str;
 432                          }
 433                          while (*str && *str != '+' && *str != '-')
 434                          {
 435                              ++str;
 436                          }
 437                          if (*str && * ++str == '0')
 438                          {
 439                              *str = *(str+1);
 440                              *(str+1) = *(str+2);
 441                              *(str+2) = 0;
 442                          }
 443                      }
 444 venkat.puvvada 1.149 #endif
 445                      
 446 mike           1.125 void XmlWriter::append(Buffer& out, const Char16& x)
 447 mike           1.23  {
 448 s.hills        1.99      _xmlWritter_appendChar(out, x);
 449 mike           1.23  }
 450                      
 451 mike           1.125 void XmlWriter::append(Buffer& out, Boolean x)
 452 kumpf          1.54  {
 453                          append(out, (x ? "TRUE" : "FALSE"));
 454                      }
 455                      
 456 mike           1.125 void XmlWriter::append(Buffer& out, Uint32 x)
 457 mike           1.23  {
 458                          char buffer[32];
 459 kumpf          1.54      sprintf(buffer, "%u", x);
 460                          append(out, buffer);
 461                      }
 462                      
 463 mike           1.125 void XmlWriter::append(Buffer& out, Sint32 x)
 464 kumpf          1.54  {
 465                          char buffer[32];
 466 mike           1.23      sprintf(buffer, "%d", x);
 467                          append(out, buffer);
 468                      }
 469                      
 470 mike           1.125 void XmlWriter::append(Buffer& out, Uint64 x)
 471 kumpf          1.54  {
 472                          char buffer[32];  // Should need 21 chars max
 473 kumpf          1.88      sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
 474 kumpf          1.54      append(out, buffer);
 475                      }
 476                      
 477 mike           1.125 void XmlWriter::append(Buffer& out, Sint64 x)
 478 kumpf          1.54  {
 479                          char buffer[32];  // Should need 21 chars max
 480 kumpf          1.88      sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x);
 481 kumpf          1.54      append(out, buffer);
 482                      }
 483                      
 484 mike           1.125 void XmlWriter::append(Buffer& out, Real32 x)
 485 chuck          1.102 {
 486                          char buffer[128];
 487                          // %.7e gives '[-]m.ddddddde+/-xx', which seems compatible with the format
 488                          // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec
 489                          // (4 byte IEEE floating point)
 490                          sprintf(buffer, "%.7e", x);
 491 venkat.puvvada 1.149 #ifdef PEGASUS_OS_TYPE_WINDOWS
 492                          _xmlWriter_normalizeRealValueString(buffer);
 493                      #endif
 494 chuck          1.102     append(out, buffer);
 495                      }
 496                      
 497 mike           1.125 void XmlWriter::append(Buffer& out, Real64 x)
 498 kumpf          1.54  {
 499                          char buffer[128];
 500 kumpf          1.146     // %.16e gives '[-]m.dddddddddddddddde+/-xx', which seems compatible
 501                          // with the format given in the CIM/XML spec, and the precision required
 502                          // by the CIM 2.2 spec (8 byte IEEE floating point)
 503 chuck          1.102     sprintf(buffer, "%.16e", x);
 504 venkat.puvvada 1.149 #ifdef PEGASUS_OS_TYPE_WINDOWS
 505                          _xmlWriter_normalizeRealValueString(buffer);
 506                      #endif
 507 kumpf          1.54      append(out, buffer);
 508                      }
 509                      
 510 mike           1.125 void XmlWriter::append(Buffer& out, const char* str)
 511 mike           1.23  {
 512 mike           1.126     size_t n = strlen(str);
 513                          out.append(str, n);
 514 kumpf          1.27  }
 515                      
 516 mike           1.125 void XmlWriter::append(Buffer& out, const String& str)
 517 kumpf          1.27  {
 518 mike           1.126     const Uint16* p = (const Uint16*)str.getChar16Data();
 519                          size_t n = str.size();
 520                      
 521                          // Handle leading ASCII 7 characers in these next two loops (use unrolling).
 522                      
 523                          while (n >= 8 && ((p[0]|p[1]|p[2]|p[3]|p[4]|p[5]|p[6]|p[7]) & 0xFF80) == 0)
 524                          {
 525 kumpf          1.146         out.append(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
 526                              p += 8;
 527                              n -= 8;
 528 mike           1.126     }
 529                      
 530                          while (n >= 4 && ((p[0]|p[1]|p[2]|p[3]) & 0xFF80) == 0)
 531 kumpf          1.64      {
 532 kumpf          1.146         out.append(p[0], p[1], p[2], p[3]);
 533                              p += 4;
 534                              n -= 4;
 535 mike           1.126     }
 536                      
 537                          while (n--)
 538                          {
 539 kumpf          1.146         Uint16 c = *p++;
 540                      
 541                              // Special processing for UTF8 case:
 542 mike           1.126 
 543 kumpf          1.146         if (c < 128)
 544                              {
 545                                  out.append(c);
 546                                  continue;
 547                              }
 548 mike           1.126 
 549 kumpf          1.146         // Handle UTF8 case (if reached).
 550                      
 551                              if (((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
 552                                  ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))
 553                              {
 554                                  Char16 highSurrogate = p[-1];
 555                                  Char16 lowSurrogate = p[0];
 556                                  p++;
 557                                  n--;
 558                      
 559                                  _xmlWritter_appendSurrogatePair(
 560                                      out, Uint16(highSurrogate),Uint16(lowSurrogate));
 561                              }
 562                              else
 563                              {
 564                                  _xmlWritter_appendChar(out, c);
 565                              }
 566 kumpf          1.64      }
 567 kumpf          1.27  }
 568                      
 569 mike           1.125 void XmlWriter::append(Buffer& out, const Indentor& x)
 570 kumpf          1.27  {
 571                          for (Uint32 i = 0; i < 4 * x.getLevel(); i++)
 572 kumpf          1.146         out.append(' ');
 573 mike           1.23  }
 574                      
 575 mike           1.125 void XmlWriter::appendSpecial(Buffer& out, const Char16& x)
 576 mike           1.23  {
 577 s.hills        1.99      _xmlWritter_appendSpecialChar(out, x);
 578 mike           1.23  }
 579                      
 580 mike           1.125 void XmlWriter::appendSpecial(Buffer& out, char x)
 581 mike           1.23  {
 582 mike           1.126     _appendSpecialChar7(out, x);
 583 mike           1.23  }
 584                      
 585 mike           1.125 void XmlWriter::appendSpecial(Buffer& out, const char* str)
 586 mike           1.23  {
 587                          while (*str)
 588 kumpf          1.146         _appendSpecialChar7(out, *str++);
 589 mike           1.23  }
 590                      
 591 mike           1.125 void XmlWriter::appendSpecial(Buffer& out, const String& str)
 592 mike           1.23  {
 593 mike           1.126     const Uint16* p = (const Uint16*)str.getChar16Data();
 594 kumpf          1.134     // prevCharIsSpace is true when the last character written to the Buffer
 595                          // is a space character (not a character reference).
 596                          Boolean prevCharIsSpace = false;
 597 mike           1.126 
 598 kumpf          1.134     // If the first character is a space, use a character reference to avoid
 599                          // space compression.
 600                          if (*p == ' ')
 601 mike           1.126     {
 602 kumpf          1.134         out.append(STRLIT_ARGS("&#32;"));
 603                              p++;
 604 mike           1.126     }
 605                      
 606 kumpf          1.134     Uint16 c;
 607                          while ((c = *p++) != 0)
 608 kumpf          1.64      {
 609 kumpf          1.134         if (c < 128)
 610                              {
 611 kumpf          1.146             if (_isSpecialChar7[c])
 612 kumpf          1.134             {
 613                                      // Write the character reference for the special character
 614                                      out.append(
 615                                          _specialChars[int(c)].str, _specialChars[int(c)].size);
 616                                      prevCharIsSpace = false;
 617                                  }
 618                                  else if (prevCharIsSpace && (c == ' '))
 619                                  {
 620                                      // Write the character reference for the space character, to
 621                                      // avoid compression
 622                                      out.append(STRLIT_ARGS("&#32;"));
 623                                      prevCharIsSpace = false;
 624                                  }
 625                                  else
 626                                  {
 627                                      out.append(c);
 628                                      prevCharIsSpace = (c == ' ');
 629                                  }
 630                              }
 631                              else
 632                              {
 633 kumpf          1.146             // Handle UTF8 case
 634 mike           1.126 
 635 kumpf          1.134             if ((((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
 636                                       ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) &&
 637                                      *p)
 638                                  {
 639                                      _xmlWritter_appendSurrogatePair(out, c, *p++);
 640                                  }
 641                                  else
 642                                  {
 643                                      _xmlWritter_appendChar(out, c);
 644                                  }
 645 mike           1.126 
 646 kumpf          1.134             prevCharIsSpace = false;
 647                              }
 648 mike           1.126     }
 649                      
 650 kumpf          1.134     // If the last character is a space, use a character reference to avoid
 651                          // space compression.
 652                          if (prevCharIsSpace)
 653 mike           1.126     {
 654 kumpf          1.134         out.remove(out.size() - 1);
 655                              out.append(STRLIT_ARGS("&#32;"));
 656 kumpf          1.64      }
 657 mike           1.23  }
 658                      
 659 kumpf          1.84  // See http://www.ietf.org/rfc/rfc2396.txt section 2
 660                      // Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ','
 661                      // Excluded characters:
 662                      //   Control characters = 0x00-0x1f, 0x7f
 663                      //   Space character = 0x20
 664                      //   Delimiters = '<' '>' '#' '%' '"'
 665                      //   Unwise = '{' '}' '|' '\\' '^' '[' ']' '`'
 666 chuck          1.94  //
 667 chuck          1.95  
 668 mike           1.126 static const char _is_uri[128] =
 669                      {
 670                          1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,
 671                          1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,
 672                          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 673                          0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,
 674 david.dillard  1.130 };
 675 mike           1.126 
 676 kumpf          1.136 // Perform the necessary URI encoding of characters in HTTP header values.
 677                      // This is required by the HTTP/1.1 specification and the CIM/HTTP
 678                      // Specification (section 3.3.2).
 679 mike           1.126 static void _xmlWritter_encodeURIChar(String& outString, Sint8 char8)
 680 kumpf          1.84  {
 681 chuck          1.95      Uint8 c = (Uint8)char8;
 682 david.dillard  1.121 
 683 kumpf          1.86  #ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING
 684 mike           1.126     if (c > 127 || _is_uri[int(c)])
 685 chuck          1.95      {
 686                              char hexencoding[4];
 687 mike           1.126         int n = sprintf(hexencoding, "%%%X%X", c/16, c%16);
 688                      #ifdef PEGASUS_USE_STRING_EXTENSIONS
 689                              outString.append(hexencoding, n);
 690                      #else /* PEGASUS_USE_STRING_EXTENSIONS */
 691 chuck          1.95          outString.append(hexencoding);
 692 mike           1.126 #endif /* PEGASUS_USE_STRING_EXTENSIONS */
 693 chuck          1.95      }
 694                          else
 695 kumpf          1.84  #endif
 696 chuck          1.95      {
 697                              outString.append((Uint16)c);
 698 kumpf          1.84      }
 699                      }
 700                      
 701 mike           1.125 String XmlWriter::encodeURICharacters(const Buffer& uriString)
 702 kumpf          1.84  {
 703                          String encodedString;
 704                      
 705                          for (Uint32 i=0; i<uriString.size(); i++)
 706                          {
 707 s.hills        1.99          _xmlWritter_encodeURIChar(encodedString, uriString[i]);
 708 kumpf          1.84      }
 709                      
 710                          return encodedString;
 711                      }
 712                      
 713 vijay.eli      1.118 String XmlWriter::encodeURICharacters(const String& uriString)
 714 kumpf          1.84  {
 715                          String encodedString;
 716                      
 717 chuck          1.95  /* i18n remove - did not handle surrogate pairs
 718 kumpf          1.84      for (Uint32 i=0; i<uriString.size(); i++)
 719                          {
 720 s.hills        1.99          _xmlWritter_encodeURIChar(encodedString, uriString[i]);
 721 chuck          1.95      }
 722                      */
 723                      
 724                          // See the "CIM Operations over HTTP" spec, section 3.3.2 and
 725                          // 3.3.3, for the treatment of non US-ASCII (UTF-8) chars
 726                      
 727                          // First, convert to UTF-8 (include handling of surrogate pairs)
 728 mike           1.125     Buffer utf8;
 729 chuck          1.95      for (Uint32 i = 0; i < uriString.size(); i++)
 730                          {
 731                              Uint16 c = uriString[i];
 732                      
 733 kumpf          1.146         if (((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) ||
 734                                  ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE)))
 735 david.dillard  1.131         {
 736                                  Char16 highSurrogate = uriString[i];
 737                                  Char16 lowSurrogate = uriString[++i];
 738 david.dillard  1.121 
 739 kumpf          1.146             _xmlWritter_appendSurrogatePair(
 740                                      utf8, Uint16(highSurrogate),Uint16(lowSurrogate));
 741 david.dillard  1.131         }
 742 chuck          1.95          else
 743                              {
 744 david.dillard  1.121             _xmlWritter_appendChar(utf8, uriString[i]);
 745 chuck          1.95          }
 746                          }
 747                      
 748                          // Second, escape the non HTTP-safe chars
 749                          for (Uint32 i=0; i<utf8.size(); i++)
 750                          {
 751 s.hills        1.99          _xmlWritter_encodeURIChar(encodedString, utf8[i]);
 752 kumpf          1.84      }
 753                      
 754                          return encodedString;
 755                      }
 756                      
 757 kumpf          1.29  //------------------------------------------------------------------------------
 758                      //
 759                      // appendLocalNameSpacePathElement()
 760                      //
 761                      //     <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>
 762                      //
 763                      //------------------------------------------------------------------------------
 764                      
 765                      void XmlWriter::appendLocalNameSpacePathElement(
 766 mike           1.125     Buffer& out,
 767 kumpf          1.80      const CIMNamespaceName& nameSpace)
 768 mike           1.23  {
 769 mike           1.126     out << STRLIT("<LOCALNAMESPACEPATH>\n");
 770 mike           1.23  
 771 david          1.103     char* nameSpaceCopy = strdup(nameSpace.getString().getCString());
 772 chuck          1.105 
 773 marek          1.140 #if !defined(PEGASUS_COMPILER_MSVC) && !defined(PEGASUS_OS_ZOS)
 774 keith.petley   1.91      char *last;
 775                          for (const char* p = strtok_r(nameSpaceCopy, "/", &last); p;
 776 kumpf          1.93           p = strtok_r(NULL, "/", &last))
 777 keith.petley   1.91  #else
 778 kumpf          1.76      for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/"))
 779 keith.petley   1.91  #endif
 780 mike           1.23      {
 781 david.dillard  1.131         out << STRLIT("<NAMESPACE NAME=\"") << p << STRLIT("\"/>\n");
 782 mike           1.23      }
 783 kumpf          1.96      free(nameSpaceCopy);
 784 mike           1.23  
 785 mike           1.126     out << STRLIT("</LOCALNAMESPACEPATH>\n");
 786 mike           1.23  }
 787                      
 788                      //------------------------------------------------------------------------------
 789                      //
 790 kumpf          1.29  // appendNameSpacePathElement()
 791                      //
 792                      //     <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)>
 793                      //
 794                      //------------------------------------------------------------------------------
 795                      
 796                      void XmlWriter::appendNameSpacePathElement(
 797 mike           1.125     Buffer& out,
 798 kumpf          1.29      const String& host,
 799 kumpf          1.80      const CIMNamespaceName& nameSpace)
 800 kumpf          1.29  {
 801 mike           1.126     out << STRLIT("<NAMESPACEPATH>\n");
 802                          out << STRLIT("<HOST>") << host << STRLIT("</HOST>\n");
 803 kumpf          1.29      appendLocalNameSpacePathElement(out, nameSpace);
 804 mike           1.126     out << STRLIT("</NAMESPACEPATH>\n");
 805 kumpf          1.29  }
 806                      
 807                      //------------------------------------------------------------------------------
 808                      //
 809                      // appendClassNameElement()
 810                      //
 811                      //     <!ELEMENT CLASSNAME EMPTY>
 812                      //     <!ATTLIST CLASSNAME
 813                      //              %CIMName;>
 814                      //
 815                      //------------------------------------------------------------------------------
 816                      
 817                      void XmlWriter::appendClassNameElement(
 818 mike           1.125     Buffer& out,
 819 kumpf          1.80      const CIMName& className)
 820 kumpf          1.29  {
 821 mike           1.126     out << STRLIT("<CLASSNAME NAME=\"") << className << STRLIT("\"/>\n");
 822 kumpf          1.29  }
 823                      
 824                      //------------------------------------------------------------------------------
 825                      //
 826                      // appendInstanceNameElement()
 827                      //
 828                      //    <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)>
 829                      //    <!ATTLIST INSTANCENAME
 830                      //              %ClassName;>
 831                      //
 832                      //------------------------------------------------------------------------------
 833                      
 834                      void XmlWriter::appendInstanceNameElement(
 835 mike           1.125     Buffer& out,
 836 kumpf          1.59      const CIMObjectPath& instanceName)
 837 kumpf          1.29  {
 838 mike           1.126     out << STRLIT("<INSTANCENAME CLASSNAME=\"");
 839                          out << instanceName.getClassName() << STRLIT("\">\n");
 840 kumpf          1.29  
 841 mike           1.126     const Array<CIMKeyBinding>& keyBindings = instanceName.getKeyBindings();
 842 kumpf          1.29      for (Uint32 i = 0, n = keyBindings.size(); i < n; i++)
 843                          {
 844 mike           1.126         out << STRLIT("<KEYBINDING NAME=\"");
 845 kumpf          1.146         out << keyBindings[i].getName() << STRLIT("\">\n");
 846 kumpf          1.29  
 847 kumpf          1.79          if (keyBindings[i].getType() == CIMKeyBinding::REFERENCE)
 848 kumpf          1.29          {
 849 kumpf          1.59              CIMObjectPath ref = keyBindings[i].getValue();
 850 kumpf          1.56              appendValueReferenceElement(out, ref, true);
 851 kumpf          1.29          }
 852 kumpf          1.146         else
 853                              {
 854 mike           1.126             out << STRLIT("<KEYVALUE VALUETYPE=\"");
 855 kumpf          1.68              out << keyBindingTypeToString(keyBindings[i].getType());
 856 mike           1.126             out << STRLIT("\">");
 857 kumpf          1.29  
 858                                  // fixed the special character problem - Markus
 859                      
 860                                  appendSpecial(out, keyBindings[i].getValue());
 861 mike           1.126             out << STRLIT("</KEYVALUE>\n");
 862 kumpf          1.29          }
 863 mike           1.126         out << STRLIT("</KEYBINDING>\n");
 864 kumpf          1.29      }
 865 mike           1.126     out << STRLIT("</INSTANCENAME>\n");
 866 kumpf          1.29  }
 867                      
 868                      //------------------------------------------------------------------------------
 869                      //
 870                      // appendClassPathElement()
 871                      //
 872                      //     <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)>
 873                      //
 874                      //------------------------------------------------------------------------------
 875                      
 876                      void XmlWriter::appendClassPathElement(
 877 mike           1.125     Buffer& out,
 878 kumpf          1.59      const CIMObjectPath& classPath)
 879 kumpf          1.29  {
 880 mike           1.126     out << STRLIT("<CLASSPATH>\n");
 881 kumpf          1.29      appendNameSpacePathElement(out,
 882                                                     classPath.getHost(),
 883                                                     classPath.getNameSpace());
 884                          appendClassNameElement(out, classPath.getClassName());
 885 mike           1.126     out << STRLIT("</CLASSPATH>\n");
 886 kumpf          1.29  }
 887                      
 888                      //------------------------------------------------------------------------------
 889                      //
 890                      // appendInstancePathElement()
 891                      //
 892                      //     <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>
 893                      //
 894                      //------------------------------------------------------------------------------
 895                      
 896                      void XmlWriter::appendInstancePathElement(
 897 mike           1.125     Buffer& out,
 898 kumpf          1.59      const CIMObjectPath& instancePath)
 899 kumpf          1.29  {
 900 mike           1.126     out << STRLIT("<INSTANCEPATH>\n");
 901 kumpf          1.29      appendNameSpacePathElement(out,
 902                                                     instancePath.getHost(),
 903                                                     instancePath.getNameSpace());
 904                          appendInstanceNameElement(out, instancePath);
 905 mike           1.126     out << STRLIT("</INSTANCEPATH>\n");
 906 kumpf          1.29  }
 907                      
 908                      //------------------------------------------------------------------------------
 909                      //
 910                      // appendLocalClassPathElement()
 911                      //
 912                      //     <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>
 913                      //
 914                      //------------------------------------------------------------------------------
 915                      
 916                      void XmlWriter::appendLocalClassPathElement(
 917 mike           1.125     Buffer& out,
 918 kumpf          1.59      const CIMObjectPath& classPath)
 919 kumpf          1.29  {
 920 mike           1.126     out << STRLIT("<LOCALCLASSPATH>\n");
 921 kumpf          1.29      appendLocalNameSpacePathElement(out, classPath.getNameSpace());
 922                          appendClassNameElement(out, classPath.getClassName());
 923 mike           1.126     out << STRLIT("</LOCALCLASSPATH>\n");
 924 kumpf          1.29  }
 925                      
 926                      //------------------------------------------------------------------------------
 927                      //
 928                      // appendLocalInstancePathElement()
 929                      //
 930                      //     <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>
 931                      //
 932                      //------------------------------------------------------------------------------
 933                      
 934                      void XmlWriter::appendLocalInstancePathElement(
 935 mike           1.125     Buffer& out,
 936 kumpf          1.59      const CIMObjectPath& instancePath)
 937 kumpf          1.29  {
 938 mike           1.126     out << STRLIT("<LOCALINSTANCEPATH>\n");
 939 kumpf          1.29      appendLocalNameSpacePathElement(out, instancePath.getNameSpace());
 940                          appendInstanceNameElement(out, instancePath);
 941 mike           1.126     out << STRLIT("</LOCALINSTANCEPATH>\n");
 942 kumpf          1.29  }
 943                      
 944                      //------------------------------------------------------------------------------
 945                      //
 946 kumpf          1.30  // appendLocalObjectPathElement()
 947                      //
 948 kumpf          1.31  //     If the reference refers to an instance, write a LOCALINSTANCEPATH;
 949                      //     otherwise write a LOCALCLASSPATH.
 950 kumpf          1.30  //
 951                      //------------------------------------------------------------------------------
 952                      
 953                      void XmlWriter::appendLocalObjectPathElement(
 954 mike           1.125     Buffer& out,
 955 kumpf          1.59      const CIMObjectPath& objectPath)
 956 kumpf          1.30  {
 957 kumpf          1.68      //
 958                          //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
 959                          //  distinguish instanceNames from classNames in every case
 960 david.dillard  1.121     //  The instanceName of a singleton instance of a keyless class has no
 961 kumpf          1.68      //  key bindings
 962                          //
 963                          if (objectPath.getKeyBindings ().size () != 0)
 964 kumpf          1.30      {
 965                              appendLocalInstancePathElement(out, objectPath);
 966                          }
 967                          else
 968                          {
 969                              appendLocalClassPathElement(out, objectPath);
 970                          }
 971                      }
 972                      
 973                      //------------------------------------------------------------------------------
 974                      //
 975 kumpf          1.54  // Helper functions for appendValueElement()
 976                      //
 977                      //------------------------------------------------------------------------------
 978                      
 979 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Boolean x)
 980 kumpf          1.54  {
 981                          XmlWriter::append(out, x);
 982                      }
 983                      
 984 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Uint8 x)
 985 kumpf          1.54  {
 986                          XmlWriter::append(out, Uint32(x));
 987                      }
 988                      
 989 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Sint8 x)
 990 kumpf          1.54  {
 991                          XmlWriter::append(out, Sint32(x));
 992                      }
 993                      
 994 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Uint16 x)
 995 kumpf          1.54  {
 996                          XmlWriter::append(out, Uint32(x));
 997                      }
 998                      
 999 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Sint16 x)
1000 kumpf          1.54  {
1001                          XmlWriter::append(out, Sint32(x));
1002                      }
1003                      
1004 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Uint32 x)
1005 kumpf          1.54  {
1006                          XmlWriter::append(out, x);
1007                      }
1008                      
1009 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Sint32 x)
1010 kumpf          1.54  {
1011                          XmlWriter::append(out, x);
1012                      }
1013                      
1014 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Uint64 x)
1015 kumpf          1.54  {
1016                          XmlWriter::append(out, x);
1017                      }
1018                      
1019 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Sint64 x)
1020 kumpf          1.54  {
1021                          XmlWriter::append(out, x);
1022                      }
1023                      
1024 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Real32 x)
1025 kumpf          1.54  {
1026 chuck          1.102     XmlWriter::append(out, x);
1027 kumpf          1.54  }
1028                      
1029 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, Real64 x)
1030 kumpf          1.54  {
1031                          XmlWriter::append(out, x);
1032                      }
1033                      
1034 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, const Char16& x)
1035 kumpf          1.54  {
1036                          XmlWriter::appendSpecial(out, x);
1037                      }
1038                      
1039 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, const String& x)
1040 kumpf          1.54  {
1041                          XmlWriter::appendSpecial(out, x);
1042                      }
1043                      
1044 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, const CIMDateTime& x)
1045 kumpf          1.54  {
1046 kumpf          1.136     // It is not necessary to use XmlWriter::appendSpecial(), because
1047                          // CIMDateTime values do not contain special characters.
1048                          out << x.toString();
1049 kumpf          1.54  }
1050                      
1051 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, const CIMObjectPath& x)
1052 kumpf          1.54  {
1053 kumpf          1.56      XmlWriter::appendValueReferenceElement(out, x, true);
1054 kumpf          1.54  }
1055                      
1056 mike           1.125 inline void _xmlWritter_appendValue(Buffer& out, const CIMObject& x)
1057 dave.sudlik    1.114 {
1058 dave.sudlik    1.120     String myStr = x.toString();
1059                          _xmlWritter_appendValue(out, myStr);
1060 dave.sudlik    1.114 }
1061                      
1062 mike           1.126 void _xmlWritter_appendValueArray(
1063                          Buffer& out, const CIMObjectPath* p, Uint32 size)
1064 kumpf          1.54  {
1065 mike           1.126     out << STRLIT("<VALUE.REFARRAY>\n");
1066 kumpf          1.54      while (size--)
1067                          {
1068 s.hills        1.99          _xmlWritter_appendValue(out, *p++);
1069 kumpf          1.54      }
1070 mike           1.126     out << STRLIT("</VALUE.REFARRAY>\n");
1071 kumpf          1.54  }
1072                      
1073                      template<class T>
1074 mike           1.125 void _xmlWritter_appendValueArray(Buffer& out, const T* p, Uint32 size)
1075 kumpf          1.54  {
1076 mike           1.126     out << STRLIT("<VALUE.ARRAY>\n");
1077 kumpf          1.54  
1078                          while (size--)
1079                          {
1080 mike           1.126         out << STRLIT("<VALUE>");
1081 s.hills        1.99          _xmlWritter_appendValue(out, *p++);
1082 mike           1.126         out << STRLIT("</VALUE>\n");
1083 kumpf          1.54      }
1084                      
1085 mike           1.126     out << STRLIT("</VALUE.ARRAY>\n");
1086 kumpf          1.54  }
1087                      
1088                      //------------------------------------------------------------------------------
1089                      //
1090                      // appendValueElement()
1091                      //
1092 kumpf          1.55  //    <!ELEMENT VALUE (#PCDATA)>
1093                      //    <!ELEMENT VALUE.ARRAY (VALUE*)>
1094                      //    <!ELEMENT VALUE.REFERENCE
1095                      //        (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|
1096                      //         INSTANCENAME)>
1097                      //    <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)>
1098                      //
1099 kumpf          1.54  //------------------------------------------------------------------------------
1100                      
1101                      void XmlWriter::appendValueElement(
1102 mike           1.125     Buffer& out,
1103 kumpf          1.54      const CIMValue& value)
1104                      {
1105                          if (value.isNull())
1106                          {
1107                              return;
1108                          }
1109                          if (value.isArray())
1110                          {
1111                              switch (value.getType())
1112                              {
1113 kumpf          1.66              case CIMTYPE_BOOLEAN:
1114 kumpf          1.54              {
1115                                      Array<Boolean> a;
1116                                      value.get(a);
1117 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1118 kumpf          1.54                  break;
1119                                  }
1120                      
1121 kumpf          1.66              case CIMTYPE_UINT8:
1122 kumpf          1.54              {
1123                                      Array<Uint8> a;
1124                                      value.get(a);
1125 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1126 kumpf          1.54                  break;
1127                                  }
1128                      
1129 kumpf          1.66              case CIMTYPE_SINT8:
1130 kumpf          1.54              {
1131                                      Array<Sint8> a;
1132                                      value.get(a);
1133 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1134 kumpf          1.54                  break;
1135                                  }
1136                      
1137 kumpf          1.66              case CIMTYPE_UINT16:
1138 kumpf          1.54              {
1139                                      Array<Uint16> a;
1140                                      value.get(a);
1141 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1142 kumpf          1.54                  break;
1143                                  }
1144                      
1145 kumpf          1.66              case CIMTYPE_SINT16:
1146 kumpf          1.54              {
1147                                      Array<Sint16> a;
1148                                      value.get(a);
1149 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1150 kumpf          1.54                  break;
1151                                  }
1152                      
1153 kumpf          1.66              case CIMTYPE_UINT32:
1154 kumpf          1.54              {
1155                                      Array<Uint32> a;
1156                                      value.get(a);
1157 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1158 kumpf          1.54                  break;
1159                                  }
1160                      
1161 kumpf          1.66              case CIMTYPE_SINT32:
1162 kumpf          1.54              {
1163                                      Array<Sint32> a;
1164                                      value.get(a);
1165 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1166 kumpf          1.54                  break;
1167                                  }
1168                      
1169 kumpf          1.66              case CIMTYPE_UINT64:
1170 kumpf          1.54              {
1171                                      Array<Uint64> a;
1172                                      value.get(a);
1173 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1174 kumpf          1.54                  break;
1175                                  }
1176                      
1177 kumpf          1.66              case CIMTYPE_SINT64:
1178 kumpf          1.54              {
1179                                      Array<Sint64> a;
1180                                      value.get(a);
1181 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1182 kumpf          1.54                  break;
1183                                  }
1184                      
1185 kumpf          1.66              case CIMTYPE_REAL32:
1186 kumpf          1.54              {
1187                                      Array<Real32> a;
1188                                      value.get(a);
1189 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1190 kumpf          1.54                  break;
1191                                  }
1192                      
1193 kumpf          1.66              case CIMTYPE_REAL64:
1194 kumpf          1.54              {
1195                                      Array<Real64> a;
1196                                      value.get(a);
1197 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1198 kumpf          1.54                  break;
1199                                  }
1200                      
1201 kumpf          1.66              case CIMTYPE_CHAR16:
1202 kumpf          1.54              {
1203                                      Array<Char16> a;
1204                                      value.get(a);
1205 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1206 kumpf          1.54                  break;
1207                                  }
1208                      
1209 kumpf          1.66              case CIMTYPE_STRING:
1210 kumpf          1.54              {
1211 kumpf          1.146                 const String* data;
1212                                      Uint32 size;
1213                                      value._get(data, size);
1214 mike           1.126                 _xmlWritter_appendValueArray(out, data, size);
1215 kumpf          1.54                  break;
1216                                  }
1217                      
1218 kumpf          1.66              case CIMTYPE_DATETIME:
1219 kumpf          1.54              {
1220                                      Array<CIMDateTime> a;
1221                                      value.get(a);
1222 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1223 kumpf          1.54                  break;
1224                                  }
1225                      
1226 kumpf          1.66              case CIMTYPE_REFERENCE:
1227 kumpf          1.54              {
1228 kumpf          1.59                  Array<CIMObjectPath> a;
1229 kumpf          1.54                  value.get(a);
1230 s.hills        1.99                  _xmlWritter_appendValueArray(out, a.getData(), a.size());
1231 kumpf          1.54                  break;
1232                                  }
1233                      
1234 dave.sudlik    1.114             case CIMTYPE_OBJECT:
1235                                  {
1236                                      Array<CIMObject> a;
1237                                      value.get(a);
1238                                      _xmlWritter_appendValueArray(out, a.getData(), a.size());
1239                                      break;
1240                                  }
1241 a.dunfey       1.137 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
1242                                  case CIMTYPE_INSTANCE:
1243                                  {
1244                                      Array<CIMInstance> a;
1245                                      value.get(a);
1246                                      _xmlWritter_appendValueArray(out, a.getData(), a.size());
1247                                      break;
1248                                  }
1249                      #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
1250 kumpf          1.54              default:
1251 kumpf          1.78                  PEGASUS_ASSERT(false);
1252 kumpf          1.54          }
1253                          }
1254 kumpf          1.66      else if (value.getType() == CIMTYPE_REFERENCE)
1255 kumpf          1.54      {
1256                              // Has to be separate because it uses VALUE.REFERENCE tag
1257 kumpf          1.59          CIMObjectPath v;
1258 kumpf          1.54          value.get(v);
1259 s.hills        1.99          _xmlWritter_appendValue(out, v);
1260 kumpf          1.54      }
1261                          else
1262                          {
1263 mike           1.126         out << STRLIT("<VALUE>");
1264 kumpf          1.54  
1265                              switch (value.getType())
1266                              {
1267 kumpf          1.66              case CIMTYPE_BOOLEAN:
1268 kumpf          1.54              {
1269                                      Boolean v;
1270                                      value.get(v);
1271 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1272 kumpf          1.54                  break;
1273                                  }
1274                      
1275 kumpf          1.66              case CIMTYPE_UINT8:
1276 kumpf          1.54              {
1277                                      Uint8 v;
1278                                      value.get(v);
1279 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1280 kumpf          1.54                  break;
1281                                  }
1282                      
1283 kumpf          1.66              case CIMTYPE_SINT8:
1284 kumpf          1.54              {
1285                                      Sint8 v;
1286                                      value.get(v);
1287 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1288 kumpf          1.54                  break;
1289                                  }
1290                      
1291 kumpf          1.66              case CIMTYPE_UINT16:
1292 kumpf          1.54              {
1293                                      Uint16 v;
1294                                      value.get(v);
1295 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1296 kumpf          1.54                  break;
1297                                  }
1298                      
1299 kumpf          1.66              case CIMTYPE_SINT16:
1300 kumpf          1.54              {
1301                                      Sint16 v;
1302                                      value.get(v);
1303 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1304 kumpf          1.54                  break;
1305                                  }
1306                      
1307 kumpf          1.66              case CIMTYPE_UINT32:
1308 kumpf          1.54              {
1309                                      Uint32 v;
1310                                      value.get(v);
1311 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1312 kumpf          1.54                  break;
1313                                  }
1314                      
1315 kumpf          1.66              case CIMTYPE_SINT32:
1316 kumpf          1.54              {
1317                                      Sint32 v;
1318                                      value.get(v);
1319 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1320 kumpf          1.54                  break;
1321                                  }
1322                      
1323 kumpf          1.66              case CIMTYPE_UINT64:
1324 kumpf          1.54              {
1325                                      Uint64 v;
1326                                      value.get(v);
1327 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1328 kumpf          1.54                  break;
1329                                  }
1330                      
1331 kumpf          1.66              case CIMTYPE_SINT64:
1332 kumpf          1.54              {
1333                                      Sint64 v;
1334                                      value.get(v);
1335 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1336 kumpf          1.54                  break;
1337                                  }
1338                      
1339 kumpf          1.66              case CIMTYPE_REAL32:
1340 kumpf          1.54              {
1341                                      Real32 v;
1342                                      value.get(v);
1343 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1344 kumpf          1.54                  break;
1345                                  }
1346                      
1347 kumpf          1.66              case CIMTYPE_REAL64:
1348 kumpf          1.54              {
1349                                      Real64 v;
1350                                      value.get(v);
1351 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1352 kumpf          1.54                  break;
1353                                  }
1354                      
1355 kumpf          1.66              case CIMTYPE_CHAR16:
1356 kumpf          1.54              {
1357                                      Char16 v;
1358                                      value.get(v);
1359 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1360 kumpf          1.54                  break;
1361                                  }
1362                      
1363 kumpf          1.66              case CIMTYPE_STRING:
1364 kumpf          1.54              {
1365                                      String v;
1366                                      value.get(v);
1367 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1368 kumpf          1.54                  break;
1369                                  }
1370                      
1371 kumpf          1.66              case CIMTYPE_DATETIME:
1372 kumpf          1.54              {
1373                                      CIMDateTime v;
1374                                      value.get(v);
1375 s.hills        1.99                  _xmlWritter_appendValue(out, v);
1376 kumpf          1.54                  break;
1377                                  }
1378                      
1379 dave.sudlik    1.114             case CIMTYPE_OBJECT:
1380                                  {
1381                                      CIMObject v;
1382                                      value.get(v);
1383                                      _xmlWritter_appendValue(out, v);
1384                                      break;
1385                                  }
1386 a.dunfey       1.137 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
1387                                  case CIMTYPE_INSTANCE:
1388                                  {
1389                                      CIMInstance v;
1390                                      value.get(v);
1391                                      _xmlWritter_appendValue(out, v);
1392                                      break;
1393                                  }
1394                      #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
1395 kumpf          1.54              default:
1396 kumpf          1.78                  PEGASUS_ASSERT(false);
1397 kumpf          1.54          }
1398                      
1399 mike           1.126         out << STRLIT("</VALUE>\n");
1400 kumpf          1.54      }
1401                      }
1402                      
1403                      void XmlWriter::printValueElement(
1404                          const CIMValue& value,
1405                          PEGASUS_STD(ostream)& os)
1406                      {
1407 mike           1.125     Buffer tmp;
1408 kumpf          1.54      appendValueElement(tmp, value);
1409                          os << tmp.getData() << PEGASUS_STD(endl);
1410                      }
1411                      
1412                      //------------------------------------------------------------------------------
1413                      //
1414 kumpf          1.56  // appendValueObjectWithPathElement()
1415                      //
1416                      //     <!ELEMENT VALUE.OBJECTWITHPATH
1417                      //         ((CLASSPATH,CLASS)|(INSTANCEPATH,INSTANCE))>
1418                      //
1419                      //------------------------------------------------------------------------------
1420                      
1421                      void XmlWriter::appendValueObjectWithPathElement(
1422 mike           1.125     Buffer& out,
1423 kumpf          1.62      const CIMObject& objectWithPath)
1424 kumpf          1.56  {
1425 mike           1.126     out << STRLIT("<VALUE.OBJECTWITHPATH>\n");
1426 kumpf          1.56  
1427 kumpf          1.62      appendValueReferenceElement(out, objectWithPath.getPath (), false);
1428                          appendObjectElement(out, objectWithPath);
1429 kumpf          1.56  
1430 mike           1.126     out << STRLIT("</VALUE.OBJECTWITHPATH>\n");
1431 kumpf          1.56  }
1432                      
1433                      //------------------------------------------------------------------------------
1434                      //
1435                      // appendValueReferenceElement()
1436                      //
1437                      //    <!ELEMENT VALUE.REFERENCE
1438                      //        (CLASSPATH|LOCALCLASSPATH|CLASSNAME|INSTANCEPATH|LOCALINSTANCEPATH|
1439                      //         INSTANCENAME)>
1440                      //
1441                      //------------------------------------------------------------------------------
1442                      
1443                      void XmlWriter::appendValueReferenceElement(
1444 mike           1.125     Buffer& out,
1445 kumpf          1.59      const CIMObjectPath& reference,
1446 kumpf          1.56      Boolean putValueWrapper)
1447                      {
1448                          if (putValueWrapper)
1449 mike           1.126         out << STRLIT("<VALUE.REFERENCE>\n");
1450 kumpf          1.56  
1451                          // See if it is a class or instance reference (instance references have
1452                          // key-bindings; class references do not).
1453 kumpf          1.68      //
1454                          //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
1455                          //  distinguish instanceNames from classNames in every case
1456                          //  The instanceName of a singleton instance of a keyless class has no
1457                          //  key bindings
1458                          //
1459 kumpf          1.56  
1460 mike           1.126     const Array<CIMKeyBinding>& kbs = reference.getKeyBindings();
1461 sage           1.60  
1462 kumpf          1.56      if (kbs.size())
1463                          {
1464                              if (reference.getHost().size())
1465                              {
1466                                  appendInstancePathElement(out, reference);
1467                              }
1468 kumpf          1.67          else if (!reference.getNameSpace().isNull())
1469 kumpf          1.56          {
1470                                  appendLocalInstancePathElement(out, reference);
1471                              }
1472                              else
1473                              {
1474                                  appendInstanceNameElement(out, reference);
1475                              }
1476                          }
1477                          else
1478                          {
1479                              if (reference.getHost().size())
1480                              {
1481                                  appendClassPathElement(out, reference);
1482                              }
1483 kumpf          1.67          else if (!reference.getNameSpace().isNull())
1484 kumpf          1.56          {
1485                                  appendLocalClassPathElement(out, reference);
1486                              }
1487                              else
1488                              {
1489                                  appendClassNameElement(out, reference.getClassName());
1490                              }
1491                          }
1492                      
1493                          if (putValueWrapper)
1494 mike           1.126         out << STRLIT("</VALUE.REFERENCE>\n");
1495 kumpf          1.56  }
1496                      
1497                      void XmlWriter::printValueReferenceElement(
1498 kumpf          1.59      const CIMObjectPath& reference,
1499 kumpf          1.56      PEGASUS_STD(ostream)& os)
1500                      {
1501 mike           1.125     Buffer tmp;
1502 kumpf          1.56      appendValueReferenceElement(tmp, reference, true);
1503                          indentedPrint(os, tmp.getData());
1504                      }
1505                      
1506                      //------------------------------------------------------------------------------
1507                      //
1508                      // appendValueNamedInstanceElement()
1509                      //
1510                      //     <!ELEMENT VALUE.NAMEDINSTANCE (INSTANCENAME,INSTANCE)>
1511                      //
1512                      //------------------------------------------------------------------------------
1513                      
1514                      void XmlWriter::appendValueNamedInstanceElement(
1515 mike           1.125     Buffer& out,
1516 kumpf          1.61      const CIMInstance& namedInstance)
1517 kumpf          1.56  {
1518 mike           1.126     out << STRLIT("<VALUE.NAMEDINSTANCE>\n");
1519 kumpf          1.56  
1520 kumpf          1.61      appendInstanceNameElement(out, namedInstance.getPath ());
1521                          appendInstanceElement(out, namedInstance);
1522 kumpf          1.56  
1523 mike           1.126     out << STRLIT("</VALUE.NAMEDINSTANCE>\n");
1524 kumpf          1.56  }
1525                      
1526                      //------------------------------------------------------------------------------
1527                      //
1528 kumpf          1.55  // appendClassElement()
1529                      //
1530                      //     <!ELEMENT CLASS
1531                      //         (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*,METHOD*)>
1532 kumpf          1.56  //     <!ATTLIST CLASS
1533 kumpf          1.55  //         %CIMName;
1534                      //         %SuperClass;>
1535                      //
1536                      //------------------------------------------------------------------------------
1537                      
1538                      void XmlWriter::appendClassElement(
1539 mike           1.125     Buffer& out,
1540 kumpf          1.55      const CIMConstClass& cimclass)
1541                      {
1542                          cimclass._checkRep();
1543                          cimclass._rep->toXml(out);
1544                      }
1545                      
1546                      void XmlWriter::printClassElement(
1547                          const CIMConstClass& cimclass,
1548                          PEGASUS_STD(ostream)& os)
1549                      {
1550 mike           1.125     Buffer tmp;
1551 kumpf          1.55      appendClassElement(tmp, cimclass);
1552                          indentedPrint(os, tmp.getData(), 4);
1553                      }
1554                      
1555                      //------------------------------------------------------------------------------
1556                      //
1557                      // appendInstanceElement()
1558                      //
1559                      //     <!ELEMENT INSTANCE
1560                      //         (QUALIFIER*,(PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE)*)>
1561                      //     <!ATTLIST INSTANCE
1562                      //         %ClassName;>
1563                      //
1564                      //------------------------------------------------------------------------------
1565                      
1566                      void XmlWriter::appendInstanceElement(
1567 mike           1.125     Buffer& out,
1568 kumpf          1.55      const CIMConstInstance& instance)
1569                      {
1570                          instance._checkRep();
1571                          instance._rep->toXml(out);
1572                      }
1573                      
1574                      void XmlWriter::printInstanceElement(
1575                          const CIMConstInstance& instance,
1576                          PEGASUS_STD(ostream)& os)
1577                      {
1578 mike           1.125     Buffer tmp;
1579 kumpf          1.55      appendInstanceElement(tmp, instance);
1580                          os << tmp.getData() << PEGASUS_STD(endl);
1581                      }
1582                      
1583                      //------------------------------------------------------------------------------
1584                      //
1585 kumpf          1.56  // appendObjectElement()
1586                      //
1587                      // May refer to a CLASS or an INSTANCE
1588                      //
1589                      //------------------------------------------------------------------------------
1590                      
1591                      void XmlWriter::appendObjectElement(
1592 mike           1.125     Buffer& out,
1593 kumpf          1.56      const CIMConstObject& object)
1594                      {
1595 kumpf          1.73      if (object.isClass())
1596 kumpf          1.56      {
1597                              CIMConstClass c(object);
1598                              appendClassElement(out, c);
1599                          }
1600 kumpf          1.73      else if (object.isInstance())
1601 kumpf          1.56      {
1602 kumpf          1.73          CIMConstInstance i(object);
1603                              appendInstanceElement(out, i);
1604 kumpf          1.56      }
1605 kumpf          1.73      // else PEGASUS_ASSERT(0);
1606 kumpf          1.56  }
1607                      
1608                      //------------------------------------------------------------------------------
1609                      //
1610                      // appendPropertyElement()
1611                      //
1612                      //     <!ELEMENT PROPERTY (QUALIFIER*,VALUE?)>
1613                      //     <!ATTLIST PROPERTY
1614                      //              %CIMName;
1615                      //              %CIMType;           #REQUIRED
1616                      //              %ClassOrigin;
1617                      //              %Propagated;>
1618                      //
1619                      //     <!ELEMENT PROPERTY.ARRAY (QUALIFIER*,VALUE.ARRAY?)>
1620                      //     <!ATTLIST PROPERTY.ARRAY
1621                      //              %CIMName;
1622                      //              %CIMType;           #REQUIRED
1623                      //              %ArraySize;
1624                      //              %ClassOrigin;
1625                      //              %Propagated;>
1626                      //
1627 kumpf          1.56  //     <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,VALUE.REFERENCE?)>
1628                      //     <!ATTLIST PROPERTY.REFERENCE
1629                      //              %CIMName;
1630                      //              %ReferenceClass;
1631                      //              %ClassOrigin;
1632                      //              %Propagated;>
1633                      //
1634                      //------------------------------------------------------------------------------
1635                      
1636                      void XmlWriter::appendPropertyElement(
1637 mike           1.125     Buffer& out,
1638 kumpf          1.56      const CIMConstProperty& property)
1639                      {
1640                          property._checkRep();
1641                          property._rep->toXml(out);
1642                      }
1643                      
1644                      void XmlWriter::printPropertyElement(
1645                          const CIMConstProperty& property,
1646                          PEGASUS_STD(ostream)& os)
1647                      {
1648 mike           1.125     Buffer tmp;
1649 kumpf          1.56      appendPropertyElement(tmp, property);
1650                          os << tmp.getData() << PEGASUS_STD(endl);
1651                      }
1652                      
1653                      //------------------------------------------------------------------------------
1654                      //
1655                      // appendMethodElement()
1656                      //
1657                      //     <!ELEMENT METHOD (QUALIFIER*,
1658                      //         (PARAMETER|PARAMETER.REFERENCE|PARAMETER.ARRAY|PARAMETER.REFARRAY)*)>
1659                      //     <!ATTLIST METHOD
1660                      //              %CIMName;
1661                      //              %CIMType;          #IMPLIED
1662                      //              %ClassOrigin;
1663                      //              %Propagated;>
1664                      //
1665                      //------------------------------------------------------------------------------
1666                      
1667                      void XmlWriter::appendMethodElement(
1668 mike           1.125     Buffer& out,
1669 kumpf          1.56      const CIMConstMethod& method)
1670                      {
1671                          method._checkRep();
1672                          method._rep->toXml(out);
1673                      }
1674                      
1675                      void XmlWriter::printMethodElement(
1676                          const CIMConstMethod& method,
1677                          PEGASUS_STD(ostream)& os)
1678                      {
1679 mike           1.125     Buffer tmp;
1680 kumpf          1.56      appendMethodElement(tmp, method);
1681                          os << tmp.getData() << PEGASUS_STD(endl);
1682                      }
1683                      
1684                      //------------------------------------------------------------------------------
1685                      //
1686                      // appendParameterElement()
1687                      //
1688                      //     <!ELEMENT PARAMETER (QUALIFIER*)>
1689                      //     <!ATTLIST PARAMETER
1690                      //              %CIMName;
1691                      //              %CIMType;      #REQUIRED>
1692                      //
1693                      //     <!ELEMENT PARAMETER.REFERENCE (QUALIFIER*)>
1694                      //     <!ATTLIST PARAMETER.REFERENCE
1695                      //              %CIMName;
1696                      //              %ReferenceClass;>
1697                      //
1698                      //     <!ELEMENT PARAMETER.ARRAY (QUALIFIER*)>
1699                      //     <!ATTLIST PARAMETER.ARRAY
1700                      //              %CIMName;
1701 kumpf          1.56  //              %CIMType;           #REQUIRED
1702                      //              %ArraySize;>
1703                      //
1704                      //     <!ELEMENT PARAMETER.REFARRAY (QUALIFIER*)>
1705                      //     <!ATTLIST PARAMETER.REFARRAY
1706                      //              %CIMName;
1707                      //              %ReferenceClass;
1708                      //              %ArraySize;>
1709                      //
1710                      //------------------------------------------------------------------------------
1711                      
1712                      void XmlWriter::appendParameterElement(
1713 mike           1.125     Buffer& out,
1714 kumpf          1.56      const CIMConstParameter& parameter)
1715                      {
1716                          parameter._checkRep();
1717                          parameter._rep->toXml(out);
1718                      }
1719                      
1720                      void XmlWriter::printParameterElement(
1721                          const CIMConstParameter& parameter,
1722                          PEGASUS_STD(ostream)& os)
1723                      {
1724 mike           1.125     Buffer tmp;
1725 kumpf          1.56      appendParameterElement(tmp, parameter);
1726                          os << tmp.getData() << PEGASUS_STD(endl);
1727                      }
1728                      
1729                      //------------------------------------------------------------------------------
1730                      //
1731                      // appendParamValueElement()
1732                      //
1733                      //     <!ELEMENT PARAMVALUE (VALUE|VALUE.REFERENCE|VALUE.ARRAY|VALUE.REFARRAY)?>
1734                      //     <!ATTLIST PARAMVALUE
1735                      //              %CIMName;>
1736                      //
1737                      //------------------------------------------------------------------------------
1738                      
1739                      void XmlWriter::appendParamValueElement(
1740 mike           1.125     Buffer& out,
1741 kumpf          1.56      const CIMParamValue& paramValue)
1742                      {
1743                          paramValue._checkRep();
1744                          paramValue._rep->toXml(out);
1745                      }
1746                      
1747                      void XmlWriter::printParamValueElement(
1748                          const CIMParamValue& paramValue,
1749                          PEGASUS_STD(ostream)& os)
1750                      {
1751 mike           1.125     Buffer tmp;
1752 kumpf          1.56      appendParamValueElement(tmp, paramValue);
1753                          os << tmp.getData() << PEGASUS_STD(endl);
1754                      }
1755                      
1756                      //------------------------------------------------------------------------------
1757                      //
1758                      // appendQualifierElement()
1759                      //
1760                      //     <!ELEMENT QUALIFIER (VALUE|VALUE.ARRAY)>
1761                      //     <!ATTLIST QUALIFIER
1762                      //              %CIMName;
1763                      //              %CIMType;               #REQUIRED
1764                      //              %Propagated;
1765                      //              %QualifierFlavor;>
1766                      //
1767                      //------------------------------------------------------------------------------
1768                      
1769                      void XmlWriter::appendQualifierElement(
1770 mike           1.125     Buffer& out,
1771 kumpf          1.56      const CIMConstQualifier& qualifier)
1772                      {
1773                          qualifier._checkRep();
1774                          qualifier._rep->toXml(out);
1775                      }
1776                      
1777                      void XmlWriter::printQualifierElement(
1778                          const CIMConstQualifier& qualifier,
1779                          PEGASUS_STD(ostream)& os)
1780                      {
1781 mike           1.125     Buffer tmp;
1782 kumpf          1.56      appendQualifierElement(tmp, qualifier);
1783                          os << tmp.getData() << PEGASUS_STD(endl);
1784                      }
1785                      
1786                      //------------------------------------------------------------------------------
1787                      //
1788                      // appendQualifierDeclElement()
1789                      //
1790                      //     <!ELEMENT QUALIFIER.DECLARATION (SCOPE?,(VALUE|VALUE.ARRAY)?)>
1791                      //     <!ATTLIST QUALIFIER.DECLARATION
1792                      //              %CIMName;
1793                      //              %CIMType;                       #REQUIRED
1794                      //              ISARRAY        (true|false)     #IMPLIED
1795                      //              %ArraySize;
1796                      //              %QualifierFlavor;>
1797                      //
1798                      //------------------------------------------------------------------------------
1799                      
1800                      void XmlWriter::appendQualifierDeclElement(
1801 mike           1.125     Buffer& out,
1802 kumpf          1.56      const CIMConstQualifierDecl& qualifierDecl)
1803                      {
1804                          qualifierDecl._checkRep();
1805                          qualifierDecl._rep->toXml(out);
1806                      }
1807                      
1808                      void XmlWriter::printQualifierDeclElement(
1809                          const CIMConstQualifierDecl& qualifierDecl,
1810                          PEGASUS_STD(ostream)& os)
1811                      {
1812 mike           1.125     Buffer tmp;
1813 kumpf          1.56      appendQualifierDeclElement(tmp, qualifierDecl);
1814                          os << tmp.getData() << PEGASUS_STD(endl);
1815                      }
1816                      
1817                      //------------------------------------------------------------------------------
1818                      //
1819 kumpf          1.57  // appendQualifierFlavorEntity()
1820                      //
1821                      //     <!ENTITY % QualifierFlavor "OVERRIDABLE  (true|false)   'true'
1822                      //                                 TOSUBCLASS   (true|false)   'true'
1823                      //                                 TOINSTANCE   (true|false)   'false'
1824                      //                                 TRANSLATABLE (true|false)   'false'">
1825                      //
1826                      //------------------------------------------------------------------------------
1827                      
1828                      void XmlWriter::appendQualifierFlavorEntity(
1829 mike           1.125     Buffer& out,
1830 kumpf          1.70      const CIMFlavor & flavor)
1831 kumpf          1.57  {
1832 kumpf          1.70      if (!(flavor.hasFlavor (CIMFlavor::OVERRIDABLE)))
1833 mike           1.126         out << STRLIT(" OVERRIDABLE=\"false\"");
1834 kumpf          1.57  
1835 kumpf          1.70      if (!(flavor.hasFlavor (CIMFlavor::TOSUBCLASS)))
1836 mike           1.126         out << STRLIT(" TOSUBCLASS=\"false\"");
1837 kumpf          1.57  
1838 kumpf          1.70      if (flavor.hasFlavor (CIMFlavor::TOINSTANCE))
1839 mike           1.126         out << STRLIT(" TOINSTANCE=\"true\"");
1840 kumpf          1.57  
1841 kumpf          1.70      if (flavor.hasFlavor (CIMFlavor::TRANSLATABLE))
1842 mike           1.126         out << STRLIT(" TRANSLATABLE=\"true\"");
1843 kumpf          1.57  }
1844                      
1845                      //------------------------------------------------------------------------------
1846                      //
1847 kumpf          1.58  // appendScopeElement()
1848                      //
1849                      //     <!ELEMENT SCOPE EMPTY>
1850                      //     <!ATTLIST SCOPE
1851                      //              CLASS        (true|false)      'false'
1852                      //              ASSOCIATION  (true|false)      'false'
1853                      //              REFERENCE    (true|false)      'false'
1854                      //              PROPERTY     (true|false)      'false'
1855                      //              METHOD       (true|false)      'false'
1856                      //              PARAMETER    (true|false)      'false'
1857                      //              INDICATION   (true|false)      'false'>
1858                      //
1859                      //------------------------------------------------------------------------------
1860                      
1861                      void XmlWriter::appendScopeElement(
1862 mike           1.125     Buffer& out,
1863 kumpf          1.69      const CIMScope & scope)
1864 kumpf          1.58  {
1865 kumpf          1.69      if (!(scope.equal (CIMScope ())))
1866 kumpf          1.58      {
1867 mike           1.126         out << STRLIT("<SCOPE");
1868 kumpf          1.58  
1869 kumpf          1.69          if (scope.hasScope (CIMScope::CLASS))
1870 mike           1.126             out << STRLIT(" CLASS=\"true\"");
1871 kumpf          1.58  
1872 kumpf          1.69          if (scope.hasScope (CIMScope::ASSOCIATION))
1873 mike           1.126             out << STRLIT(" ASSOCIATION=\"true\"");
1874 kumpf          1.58  
1875 kumpf          1.69          if (scope.hasScope (CIMScope::REFERENCE))
1876 mike           1.126             out << STRLIT(" REFERENCE=\"true\"");
1877 kumpf          1.58  
1878 kumpf          1.69          if (scope.hasScope (CIMScope::PROPERTY))
1879 mike           1.126             out << STRLIT(" PROPERTY=\"true\"");
1880 kumpf          1.58  
1881 kumpf          1.69          if (scope.hasScope (CIMScope::METHOD))
1882 mike           1.126             out << STRLIT(" METHOD=\"true\"");
1883 kumpf          1.58  
1884 kumpf          1.69          if (scope.hasScope (CIMScope::PARAMETER))
1885 mike           1.126             out << STRLIT(" PARAMETER=\"true\"");
1886 kumpf          1.58  
1887 kumpf          1.69          if (scope.hasScope (CIMScope::INDICATION))
1888 mike           1.126             out << STRLIT(" INDICATION=\"true\"");
1889 kumpf          1.58  
1890 mike           1.126         out << STRLIT("/>");
1891 kumpf          1.58      }
1892                      }
1893                      
1894 david.dillard  1.121 // l10n - added content language and accept language support to
1895 chuck          1.89  // the header methods below
1896                      
1897 kumpf          1.58  //------------------------------------------------------------------------------
1898                      //
1899 kumpf          1.27  // appendMethodCallHeader()
1900 mike           1.23  //
1901 kumpf          1.31  //     Build HTTP method call request header.
1902 mike           1.23  //
1903                      //------------------------------------------------------------------------------
1904                      
1905 kumpf          1.27  void XmlWriter::appendMethodCallHeader(
1906 mike           1.125     Buffer& out,
1907 mike           1.23      const char* host,
1908 kumpf          1.80      const CIMName& cimMethod,
1909 mike           1.23      const String& cimObject,
1910 mike           1.24      const String& authenticationHeader,
1911 kumpf          1.82      HttpMethod httpMethod,
1912 kumpf          1.133     const AcceptLanguageList& acceptLanguages,
1913                          const ContentLanguageList& contentLanguages,
1914 kumpf          1.27      Uint32 contentLength)
1915 mike           1.23  {
1916                          char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
1917                      
1918 karl           1.81      // ATTN: KS 20020926 - Temporary change to issue only POST. This may
1919                          // be changed in the DMTF CIM Operations standard in the future.
1920                          // If we kept M-Post we would have to retry with Post. Does not
1921                          // do that in client today. Permanent change is to retry until spec
1922                          // updated. This change is temp to finish tests or until the retry
1923                          // installed.  Required because of change to wbemservices cimom
1924 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
1925                          {
1926 mike           1.126         out << STRLIT("M-POST /cimom HTTP/1.1\r\n");
1927 kumpf          1.82      }
1928                          else
1929                          {
1930 mike           1.126         out << STRLIT("POST /cimom HTTP/1.1\r\n");
1931 kumpf          1.82      }
1932 mike           1.126     out << STRLIT("HOST: ") << host << STRLIT("\r\n");
1933                          out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");
1934                          OUTPUT_CONTENTLENGTH;
1935 chuck          1.89      if (acceptLanguages.size() > 0)
1936                          {
1937 kumpf          1.146         out << STRLIT("Accept-Language: ") << acceptLanguages << STRLIT("\r\n");
1938 chuck          1.89      }
1939                          if (contentLanguages.size() > 0)
1940                          {
1941 kumpf          1.146         out << STRLIT("Content-Language: ") << contentLanguages <<
1942                                  STRLIT("\r\n");
1943 david.dillard  1.121     }
1944 brian.campbell 1.107 
1945 brian.campbell 1.113 #ifdef PEGASUS_DEBUG
1946 kumpf          1.146     // backdoor environment variable to turn OFF client requesting transfer
1947                          // encoding. The default is on. to turn off, set this variable to zero.
1948                          // This should be removed when stable. This should only be turned off in
1949                          // a debugging/testing environment.
1950 brian.campbell 1.113 
1951 kumpf          1.146     static const char *clientTransferEncodingOff =
1952                              getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST");
1953 karl           1.142 
1954 kumpf          1.146     if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0')
1955 a.dunfey       1.110 #endif
1956 brian.campbell 1.113 
1957 kumpf          1.146     out << STRLIT("TE: chunked, trailers\r\n");
1958 brian.campbell 1.107 
1959 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
1960                          {
1961 mike           1.126         out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");
1962                              out << nn << STRLIT("\r\n");
1963                              out << nn << STRLIT("-CIMOperation: MethodCall\r\n");
1964                              out << nn << STRLIT("-CIMMethod: ")
1965                                  << encodeURICharacters(cimMethod.getString()) << STRLIT("\r\n");
1966 david.dillard  1.130         out << nn << STRLIT("-CIMObject: ") << encodeURICharacters(cimObject)
1967 kumpf          1.146             << STRLIT("\r\n");
1968 kumpf          1.82      }
1969 david.dillard  1.121     else
1970 kumpf          1.82      {
1971 mike           1.126         out << STRLIT("CIMOperation: MethodCall\r\n");
1972 kumpf          1.146         out << STRLIT("CIMMethod: ")
1973                                  << encodeURICharacters(cimMethod.getString())
1974 mike           1.126             << STRLIT("\r\n");
1975 david.dillard  1.130         out << STRLIT("CIMObject: ") << encodeURICharacters(cimObject)
1976 kumpf          1.146             << STRLIT("\r\n");
1977 kumpf          1.82      }
1978                      
1979 mike           1.24      if (authenticationHeader.size())
1980                          {
1981 mike           1.126         out << authenticationHeader << STRLIT("\r\n");
1982 mike           1.24      }
1983 brian.campbell 1.107 
1984 mike           1.126     out << STRLIT("\r\n");
1985 mike           1.23  }
1986                      
1987 chuck          1.89  
1988 kumpf          1.27  void XmlWriter::appendMethodResponseHeader(
1989 mike           1.125      Buffer& out,
1990 w.white        1.108      HttpMethod httpMethod,
1991 kumpf          1.133      const ContentLanguageList& contentLanguages,
1992 w.white        1.108      Uint32 contentLength,
1993 david.dillard  1.130      Uint64 serverResponseTime)
1994 brian.campbell 1.113 {
1995 w.white        1.108      char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
1996 mike           1.126      out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n");
1997 kumpf          1.141 
1998                      #ifndef PEGASUS_DISABLE_PERFINST
1999                           if (StatisticalData::current()->copyGSD)
2000                           {
2001                               out << STRLIT("WBEMServerResponseTime: ") <<
2002                                   CIMValue(serverResponseTime).toString() << STRLIT("\r\n");
2003                           }
2004                      #endif
2005                      
2006 mike           1.126      out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");
2007 w.white        1.108      OUTPUT_CONTENTLENGTH;
2008                      
2009                           if (contentLanguages.size() > 0)
2010                           {
2011 kumpf          1.146          out << STRLIT("Content-Language: ") << contentLanguages <<
2012                                   STRLIT("\r\n");
2013 w.white        1.108      }
2014                           if (httpMethod == HTTP_METHOD_M_POST)
2015                           {
2016 mike           1.126          out << STRLIT("Ext:\r\n");
2017                               out << STRLIT("Cache-Control: no-cache\r\n");
2018                               out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");
2019                               out << nn << STRLIT("\r\n");
2020                               out << nn << STRLIT("-CIMOperation: MethodResponse\r\n\r\n");
2021 w.white        1.108      }
2022                           else
2023                           {
2024 mike           1.126          out << STRLIT("CIMOperation: MethodResponse\r\n\r\n");
2025 w.white        1.108      }
2026 brian.campbell 1.113 }
2027 w.white        1.108 
2028                      
2029 mike           1.23  //------------------------------------------------------------------------------
2030                      //
2031 kumpf          1.40  // appendHttpErrorResponseHeader()
2032                      //
2033                      //     Build HTTP error response header.
2034                      //
2035                      //     Returns error response message in the following format:
2036                      //
2037 kumpf          1.41  //        HTTP/1.1 400 Bad Request       (using specified status code)
2038                      //        CIMError: <error type>         (if specified by caller)
2039                      //        PGErrorDetail: <error text>    (if specified by caller)
2040 kumpf          1.40  //
2041                      //------------------------------------------------------------------------------
2042                      
2043                      void XmlWriter::appendHttpErrorResponseHeader(
2044 mike           1.125     Buffer& out,
2045 kumpf          1.40      const String& status,
2046                          const String& cimError,
2047 kumpf          1.41      const String& errorDetail)
2048 kumpf          1.40  {
2049 mike           1.126     out << STRLIT("HTTP/1.1 ") << status << STRLIT("\r\n");
2050 kumpf          1.40      if (cimError != String::EMPTY)
2051                          {
2052 mike           1.126         out << STRLIT("CIMError: ") << cimError << STRLIT("\r\n");
2053 kumpf          1.40      }
2054 kumpf          1.41      if (errorDetail != String::EMPTY)
2055 kumpf          1.40      {
2056 mike           1.126         out << STRLIT(PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": ")
2057                                  << encodeURICharacters(errorDetail) << STRLIT("\r\n");
2058 kumpf          1.40      }
2059 mike           1.126     out << STRLIT("\r\n");
2060 kumpf          1.40  }
2061                      
2062                      //------------------------------------------------------------------------------
2063                      //
2064 kumpf          1.27  // appendUnauthorizedResponseHeader()
2065                      //
2066                      //     Build HTTP authentication response header for unauthorized requests.
2067                      //
2068                      //     Returns unauthorized message in the following format:
2069                      //
2070                      //        HTTP/1.1 401 Unauthorized
2071                      //        WWW-Authenticate: Basic "hostname:80"
2072                      //        <HTML><HEAD>
2073                      //        <TITLE>401 Unauthorized</TITLE>
2074                      //        </HEAD><BODY BGCOLOR="#99cc99">
2075                      //        <H2>TEST401 Unauthorized</H2>
2076                      //        <HR>
2077                      //        </BODY></HTML>
2078                      //
2079                      //------------------------------------------------------------------------------
2080                      
2081                      void XmlWriter::appendUnauthorizedResponseHeader(
2082 mike           1.125     Buffer& out,
2083 kumpf          1.27      const String& content)
2084                      {
2085 mike           1.126     out << STRLIT("HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n");
2086                          out << content << STRLIT("\r\n");
2087                          out << STRLIT("\r\n");
2088 kumpf          1.27  
2089                      //ATTN: We may need to include the following line, so that the browsers
2090                      //      can display the error message.
2091                      //    out << "<HTML><HEAD>\r\n";
2092                      //    out << "<TITLE>" << "401 Unauthorized" <<  "</TITLE>\r\n";
2093                      //    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";
2094                      //    out << "<H2>TEST" << "401 Unauthorized" << "</H2>\r\n";
2095                      //    out << "<HR>\r\n";
2096                      //    out << "</BODY></HTML>\r\n";
2097                      }
2098                      
2099 gerarda        1.90  #ifdef PEGASUS_KERBEROS_AUTHENTICATION
2100                      //------------------------------------------------------------------------------
2101                      //
2102                      // appendOKResponseHeader()
2103                      //
2104                      //     Build HTTP authentication response header for unauthorized requests.
2105                      //
2106                      //     Returns OK message in the following format:
2107                      //
2108                      //        HTTP/1.1 200 OK
2109 gerarda        1.101 //        Content-Length: 0
2110 gerarda        1.90  //        WWW-Authenticate: Negotiate "token"
2111                      //        <HTML><HEAD>
2112                      //        <TITLE>200 OK</TITLE>
2113                      //        </HEAD><BODY BGCOLOR="#99cc99">
2114                      //        <H2>TEST200 OK</H2>
2115                      //        <HR>
2116                      //        </BODY></HTML>
2117                      //
2118                      //------------------------------------------------------------------------------
2119                      
2120                      void XmlWriter::appendOKResponseHeader(
2121 mike           1.125     Buffer& out,
2122 gerarda        1.90      const String& content)
2123                      {
2124 mike           1.126     out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n");
2125 gerarda        1.101     // Content-Length header needs to be added because 200 OK record
2126                          // is usually intended to have content.  But, for Kerberos this
2127                          // may not always be the case so we need to indicate that there
2128                          // is no content
2129 kumpf          1.146     Uint32 contentLength = 0;
2130                          OUTPUT_CONTENTLENGTH;
2131 mike           1.126     out << content << STRLIT("\r\n");
2132                          out << STRLIT("\r\n");
2133 gerarda        1.90  
2134                      //ATTN: We may need to include the following line, so that the browsers
2135                      //      can display the error message.
2136                      //    out << "<HTML><HEAD>\r\n";
2137                      //    out << "<TITLE>" << "200 OK" <<  "</TITLE>\r\n";
2138                      //    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";
2139                      //    out << "<H2>TEST" << "200 OK" << "</H2>\r\n";
2140                      //    out << "<HR>\r\n";
2141                      //    out << "</BODY></HTML>\r\n";
2142                      }
2143                      #endif
2144                      
2145 kumpf          1.27  //------------------------------------------------------------------------------
2146                      //
2147 kumpf          1.29  // _appendMessageElementBegin()
2148                      // _appendMessageElementEnd()
2149 mike           1.23  //
2150                      //     <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP)>
2151                      //     <!ATTLIST MESSAGE
2152                      //         ID CDATA #REQUIRED
2153                      //         PROTOCOLVERSION CDATA #REQUIRED>
2154                      //
2155                      //------------------------------------------------------------------------------
2156                      
2157 kumpf          1.29  void XmlWriter::_appendMessageElementBegin(
2158 mike           1.125     Buffer& out,
2159 kumpf          1.27      const String& messageId)
2160 mike           1.23  {
2161 mike           1.126     out << STRLIT("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
2162                          out << STRLIT("<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">\n");
2163                          out << STRLIT("<MESSAGE ID=\"") << messageId;
2164                          out << STRLIT("\" PROTOCOLVERSION=\"1.0\">\n");
2165 kumpf          1.27  }
2166                      
2167 kumpf          1.29  void XmlWriter::_appendMessageElementEnd(
2168 mike           1.125     Buffer& out)
2169 kumpf          1.27  {
2170 mike           1.126     out << STRLIT("</MESSAGE>\n");
2171                          out << STRLIT("</CIM>\n");
2172 mike           1.23  }
2173                      
2174                      //------------------------------------------------------------------------------
2175                      //
2176 kumpf          1.29  // _appendSimpleReqElementBegin()
2177                      // _appendSimpleReqElementEnd()
2178 mike           1.23  //
2179                      //     <!ELEMENT SIMPLEREQ (IMETHODCALL|METHODCALL)>
2180                      //
2181                      //------------------------------------------------------------------------------
2182                      
2183 kumpf          1.29  void XmlWriter::_appendSimpleReqElementBegin(
2184 mike           1.125     Buffer& out)
2185 kumpf          1.27  {
2186 mike           1.126     out << STRLIT("<SIMPLEREQ>\n");
2187 kumpf          1.27  }
2188                      
2189 kumpf          1.29  void XmlWriter::_appendSimpleReqElementEnd(
2190 mike           1.125     Buffer& out)
2191 mike           1.23  {
2192 mike           1.126     out << STRLIT("</SIMPLEREQ>\n");
2193 mike           1.23  }
2194                      
2195                      //------------------------------------------------------------------------------
2196                      //
2197 kumpf          1.29  // _appendMethodCallElementBegin()
2198                      // _appendMethodCallElementEnd()
2199 mike           1.23  //
2200 kumpf          1.27  //     <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)>
2201                      //     <!ATTLIST METHODCALL %CIMName;>
2202 mike           1.23  //
2203                      //------------------------------------------------------------------------------
2204                      
2205 kumpf          1.29  void XmlWriter::_appendMethodCallElementBegin(
2206 mike           1.125     Buffer& out,
2207 kumpf          1.80      const CIMName& name)
2208 kumpf          1.27  {
2209 mike           1.126     out << STRLIT("<METHODCALL NAME=\"") << name << STRLIT("\">\n");
2210 kumpf          1.27  }
2211                      
2212 kumpf          1.29  void XmlWriter::_appendMethodCallElementEnd(
2213 mike           1.125     Buffer& out)
2214 mike           1.23  {
2215 mike           1.126     out << STRLIT("</METHODCALL>\n");
2216 mike           1.23  }
2217                      
2218                      //------------------------------------------------------------------------------
2219                      //
2220 kumpf          1.29  // _appendIMethodCallElementBegin()
2221                      // _appendIMethodCallElementEnd()
2222 mike           1.23  //
2223                      //     <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)>
2224                      //     <!ATTLIST IMETHODCALL %CIMName;>
2225                      //
2226                      //------------------------------------------------------------------------------
2227                      
2228 kumpf          1.29  void XmlWriter::_appendIMethodCallElementBegin(
2229 mike           1.125     Buffer& out,
2230 kumpf          1.80      const CIMName& name)
2231 mike           1.23  {
2232 mike           1.126     out << STRLIT("<IMETHODCALL NAME=\"") << name << STRLIT("\">\n");
2233 kumpf          1.27  }
2234                      
2235 kumpf          1.29  void XmlWriter::_appendIMethodCallElementEnd(
2236 mike           1.125     Buffer& out)
2237 kumpf          1.27  {
2238 mike           1.126     out << STRLIT("</IMETHODCALL>\n");
2239 mike           1.23  }
2240                      
2241                      //------------------------------------------------------------------------------
2242                      //
2243 kumpf          1.29  // _appendIParamValueElementBegin()
2244                      // _appendIParamValueElementEnd()
2245 mike           1.23  //
2246 kumpf          1.27  //     <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
2247                      //         |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
2248                      //         |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
2249                      //     <!ATTLIST IPARAMVALUE %CIMName;>
2250 mike           1.23  //
2251                      //------------------------------------------------------------------------------
2252                      
2253 kumpf          1.29  void XmlWriter::_appendIParamValueElementBegin(
2254 mike           1.125     Buffer& out,
2255 kumpf          1.27      const char* name)
2256                      {
2257 mike           1.126     out << STRLIT("<IPARAMVALUE NAME=\"") << name << STRLIT("\">\n");
2258 kumpf          1.27  }
2259                      
2260 kumpf          1.29  void XmlWriter::_appendIParamValueElementEnd(
2261 mike           1.125     Buffer& out)
2262 mike           1.23  {
2263 mike           1.126     out << STRLIT("</IPARAMVALUE>\n");
2264 mike           1.23  }
2265                      
2266                      //------------------------------------------------------------------------------
2267                      //
2268 kumpf          1.29  // _appendSimpleRspElementBegin()
2269                      // _appendSimpleRspElementEnd()
2270 mike           1.23  //
2271 kumpf          1.27  //     <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)>
2272 mike           1.23  //
2273                      //------------------------------------------------------------------------------
2274                      
2275 kumpf          1.29  void XmlWriter::_appendSimpleRspElementBegin(
2276 mike           1.125     Buffer& out)
2277 kumpf          1.27  {
2278 mike           1.126     out << STRLIT("<SIMPLERSP>\n");
2279 kumpf          1.27  }
2280                      
2281 kumpf          1.29  void XmlWriter::_appendSimpleRspElementEnd(
2282 mike           1.125     Buffer& out)
2283 mike           1.23  {
2284 mike           1.126     out << STRLIT("</SIMPLERSP>\n");
2285 mike           1.23  }
2286                      
2287                      //------------------------------------------------------------------------------
2288                      //
2289 kumpf          1.29  // _appendMethodResponseElementBegin()
2290                      // _appendMethodResponseElementEnd()
2291 mike           1.23  //
2292 kumpf          1.27  //     <!ELEMENT METHODRESPONSE (ERROR|IRETURNVALUE?)>
2293                      //     <!ATTLIST METHODRESPONSE %CIMName;>
2294 mike           1.23  //
2295                      //------------------------------------------------------------------------------
2296                      
2297 kumpf          1.29  void XmlWriter::_appendMethodResponseElementBegin(
2298 mike           1.125     Buffer& out,
2299 kumpf          1.80      const CIMName& name)
2300 kumpf          1.27  {
2301 mike           1.126     out << STRLIT("<METHODRESPONSE NAME=\"") << name << STRLIT("\">\n");
2302 kumpf          1.27  }
2303                      
2304 kumpf          1.29  void XmlWriter::_appendMethodResponseElementEnd(
2305 mike           1.125     Buffer& out)
2306 mike           1.23  {
2307 mike           1.126     out << STRLIT("</METHODRESPONSE>\n");
2308 kumpf          1.27  }
2309                      
2310                      //------------------------------------------------------------------------------
2311                      //
2312 kumpf          1.29  // _appendIMethodResponseElementBegin()
2313                      // _appendIMethodResponseElementEnd()
2314 kumpf          1.27  //
2315                      //     <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)>
2316                      //     <!ATTLIST IMETHODRESPONSE %CIMName;>
2317                      //
2318                      //------------------------------------------------------------------------------
2319                      
2320 kumpf          1.29  void XmlWriter::_appendIMethodResponseElementBegin(
2321 mike           1.125     Buffer& out,
2322 kumpf          1.80      const CIMName& name)
2323 kumpf          1.27  {
2324 mike           1.126     out << STRLIT("<IMETHODRESPONSE NAME=\"") << name << STRLIT("\">\n");
2325 kumpf          1.27  }
2326                      
2327 kumpf          1.29  void XmlWriter::_appendIMethodResponseElementEnd(
2328 mike           1.125     Buffer& out)
2329 kumpf          1.27  {
2330 mike           1.126     out << STRLIT("</IMETHODRESPONSE>\n");
2331 mike           1.23  }
2332                      
2333                      //------------------------------------------------------------------------------
2334                      //
2335 kumpf          1.29  // _appendErrorElement()
2336 mike           1.23  //
2337                      //------------------------------------------------------------------------------
2338                      
2339 kumpf          1.29  void XmlWriter::_appendErrorElement(
2340 mike           1.125     Buffer& out,
2341 kumpf          1.42      const CIMException& cimException)
2342 mike           1.23  {
2343 kumpf          1.71      Tracer::traceCIMException(TRC_XML_WRITER, Tracer::LEVEL2, cimException);
2344 kumpf          1.44  
2345 mike           1.126     out << STRLIT("<ERROR");
2346                          out << STRLIT(" CODE=\"") << Uint32(cimException.getCode());
2347 karl           1.145     out.append('"');
2348 karl           1.142 
2349 kumpf          1.71      String description = TraceableCIMException(cimException).getDescription();
2350 karl           1.145 
2351 kumpf          1.51      if (description != String::EMPTY)
2352 kumpf          1.42      {
2353 mike           1.126         out << STRLIT(" DESCRIPTION=\"");
2354 kumpf          1.51          appendSpecial(out, description);
2355 kumpf          1.146         out.append('"');
2356 kumpf          1.42      }
2357 karl           1.142 
2358 karl           1.145     if (cimException.getErrorCount())
2359 karl           1.142     {
2360 karl           1.145         out << STRLIT(">");
2361                      
2362                              for (Uint32 i = 0, n = cimException.getErrorCount(); i < n; i++)
2363                                  appendInstanceElement(out, cimException.getError(i));
2364                      
2365                              out << STRLIT("</ERROR>");
2366 karl           1.142     }
2367 karl           1.145     else
2368                              out << STRLIT("/>");
2369 mike           1.23  }
2370                      
2371                      //------------------------------------------------------------------------------
2372                      //
2373 kumpf          1.27  // appendReturnValueElement()
2374                      //
2375                      // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
2376                      // <!ATTLIST RETURNVALUE
2377 dave.sudlik    1.117 //     %EmbeddedObject; #IMPLIED
2378 kumpf          1.27  //     %ParamType;>
2379 mike           1.23  //
2380                      //------------------------------------------------------------------------------
2381                      
2382 kumpf          1.27  void XmlWriter::appendReturnValueElement(
2383 mike           1.125     Buffer& out,
2384 kumpf          1.27      const CIMValue& value)
2385                      {
2386 mike           1.126     out << STRLIT("<RETURNVALUE");
2387 kumpf          1.27  
2388                          CIMType type = value.getType();
2389 david.dillard  1.121     // If the property type is CIMObject, then
2390 kumpf          1.146     //   encode the property in CIM-XML as a string with the EMBEDDEDOBJECT
2391                          //   attribute (there is not currently a CIM-XML "object" datatype)
2392 dave.sudlik    1.117     // else
2393                          //   output the real type
2394                          if (type == CIMTYPE_OBJECT)
2395                          {
2396 mike           1.126         out << STRLIT(" PARAMTYPE=\"string\"");
2397                              out << STRLIT(" EMBEDDEDOBJECT=\"object\"");
2398 dave.sudlik    1.117     }
2399 a.dunfey       1.137 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
2400                          else if (type == CIMTYPE_INSTANCE)
2401                          {
2402                              out << STRLIT(" PARAMTYPE=\"string\"");
2403                              out << STRLIT(" EMBEDDEDOBJECT=\"instance\"");
2404                          }
2405                      #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
2406 dave.sudlik    1.117     else
2407                          {
2408 mike           1.126         out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type);
2409 kumpf          1.146         out.append('"');
2410 dave.sudlik    1.117     }
2411 kumpf          1.27  
2412 mike           1.126     out << STRLIT(">\n");
2413 karl           1.37  
2414 kumpf          1.54      // Add value.
2415                          appendValueElement(out, value);
2416 mike           1.126     out << STRLIT("</RETURNVALUE>\n");
2417 kumpf          1.27  }
2418                      
2419                      //------------------------------------------------------------------------------
2420                      //
2421 kumpf          1.29  // _appendIReturnValueElementBegin()
2422                      // _appendIReturnValueElementEnd()
2423 kumpf          1.27  //
2424                      //      <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|
2425                      //          VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*|VALUE.OBJECT*|
2426                      //          OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|
2427                      //          CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)>
2428                      //
2429                      //------------------------------------------------------------------------------
2430                      
2431 kumpf          1.29  void XmlWriter::_appendIReturnValueElementBegin(
2432 mike           1.125     Buffer& out)
2433 kumpf          1.27  {
2434 mike           1.126     out << STRLIT("<IRETURNVALUE>\n");
2435 kumpf          1.27  }
2436                      
2437 kumpf          1.29  void XmlWriter::_appendIReturnValueElementEnd(
2438 mike           1.125     Buffer& out)
2439 mike           1.23  {
2440 mike           1.126     out << STRLIT("</IRETURNVALUE>\n");
2441 mike           1.23  }
2442                      
2443                      //------------------------------------------------------------------------------
2444                      //
2445 kumpf          1.27  // appendBooleanIParameter()
2446 mike           1.23  //
2447                      //------------------------------------------------------------------------------
2448                      
2449 kumpf          1.27  void XmlWriter::appendBooleanIParameter(
2450 mike           1.125     Buffer& out,
2451 mike           1.23      const char* name,
2452 kumpf          1.27      Boolean flag)
2453 mike           1.23  {
2454 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2455 mike           1.126     out << STRLIT("<VALUE>");
2456 kumpf          1.54      append(out, flag);
2457 mike           1.126     out << STRLIT("</VALUE>\n");
2458 kumpf          1.29      _appendIParamValueElementEnd(out);
2459 mike           1.23  }
2460                      
2461                      //------------------------------------------------------------------------------
2462                      //
2463 kumpf          1.27  // appendStringIParameter()
2464 mike           1.23  //
2465                      //------------------------------------------------------------------------------
2466                      
2467 kumpf          1.27  void XmlWriter::appendStringIParameter(
2468 mike           1.125     Buffer& out,
2469 mike           1.23      const char* name,
2470 kumpf          1.27      const String& str)
2471 mike           1.23  {
2472 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2473 mike           1.126     out << STRLIT("<VALUE>");
2474 kumpf          1.27      appendSpecial(out, str);
2475 mike           1.126     out << STRLIT("</VALUE>\n");
2476 kumpf          1.29      _appendIParamValueElementEnd(out);
2477 mike           1.23  }
2478                      
2479                      //------------------------------------------------------------------------------
2480                      //
2481 kumpf          1.27  // appendClassNameIParameter()
2482 mike           1.23  //
2483                      //------------------------------------------------------------------------------
2484                      
2485 kumpf          1.27  void XmlWriter::appendClassNameIParameter(
2486 mike           1.125     Buffer& out,
2487 kumpf          1.27      const char* name,
2488 kumpf          1.80      const CIMName& className)
2489 mike           1.23  {
2490 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2491 kumpf          1.83  
2492                          //
2493 david.dillard  1.121     //  A NULL (unassigned) value for a parameter is specified by an
2494 kumpf          1.83      //  <IPARAMVALUE> element with no subelement
2495                          //
2496                          if (!className.isNull ())
2497                          {
2498                              appendClassNameElement(out, className);
2499                          }
2500                      
2501 kumpf          1.29      _appendIParamValueElementEnd(out);
2502 mike           1.23  }
2503                      
2504                      //------------------------------------------------------------------------------
2505                      //
2506 kumpf          1.27  // appendInstanceNameIParameter()
2507 mike           1.23  //
2508                      //------------------------------------------------------------------------------
2509                      
2510 kumpf          1.27  void XmlWriter::appendInstanceNameIParameter(
2511 mike           1.125     Buffer& out,
2512 kumpf          1.27      const char* name,
2513 kumpf          1.59      const CIMObjectPath& instanceName)
2514 mike           1.23  {
2515 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2516                          appendInstanceNameElement(out, instanceName);
2517                          _appendIParamValueElementEnd(out);
2518 kumpf          1.27  }
2519                      
2520                      void XmlWriter::appendObjectNameIParameter(
2521 mike           1.125     Buffer& out,
2522 kumpf          1.27      const char* name,
2523 kumpf          1.59      const CIMObjectPath& objectName)
2524 kumpf          1.27  {
2525 kumpf          1.68      //
2526                          //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2527                          //  distinguish instanceNames from classNames in every case
2528 david.dillard  1.121     //  The instanceName of a singleton instance of a keyless class also
2529 kumpf          1.68      //  has no key bindings
2530                          //
2531                          if (objectName.getKeyBindings ().size () == 0)
2532 kumpf          1.27      {
2533 kumpf          1.146         XmlWriter::appendClassNameIParameter(
2534                                  out, name, objectName.getClassName());
2535 kumpf          1.27      }
2536                          else
2537                          {
2538 kumpf          1.146         XmlWriter::appendInstanceNameIParameter(
2539                                  out, name, objectName);
2540 kumpf          1.27      }
2541                      }
2542                      
2543                      //------------------------------------------------------------------------------
2544                      //
2545                      // appendClassIParameter()
2546                      //
2547                      //------------------------------------------------------------------------------
2548                      
2549                      void XmlWriter::appendClassIParameter(
2550 mike           1.125     Buffer& out,
2551 kumpf          1.27      const char* name,
2552                          const CIMConstClass& cimClass)
2553                      {
2554 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2555 kumpf          1.55      appendClassElement(out, cimClass);
2556 kumpf          1.29      _appendIParamValueElementEnd(out);
2557 mike           1.23  }
2558                      
2559                      //------------------------------------------------------------------------------
2560                      //
2561 kumpf          1.27  // appendInstanceIParameter()
2562 mike           1.23  //
2563                      //------------------------------------------------------------------------------
2564                      
2565 kumpf          1.27  void XmlWriter::appendInstanceIParameter(
2566 mike           1.125     Buffer& out,
2567 kumpf          1.27      const char* name,
2568 mike           1.23      const CIMConstInstance& instance)
2569                      {
2570 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2571 kumpf          1.55      appendInstanceElement(out, instance);
2572 kumpf          1.29      _appendIParamValueElementEnd(out);
2573 mike           1.23  }
2574                      
2575 mike           1.24  //------------------------------------------------------------------------------
2576                      //
2577 kumpf          1.27  // appendNamedInstanceIParameter()
2578 mike           1.24  //
2579                      //------------------------------------------------------------------------------
2580                      
2581 kumpf          1.27  void XmlWriter::appendNamedInstanceIParameter(
2582 mike           1.125     Buffer& out,
2583 kumpf          1.27      const char* name,
2584 kumpf          1.61      const CIMInstance& namedInstance)
2585 mike           1.24  {
2586 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2587 kumpf          1.56      appendValueNamedInstanceElement(out, namedInstance);
2588 kumpf          1.29      _appendIParamValueElementEnd(out);
2589 mike           1.24  }
2590                      
2591 mike           1.23  //----------------------------------------------------------
2592                      //
2593 kumpf          1.27  //  appendPropertyNameIParameter()
2594 david.dillard  1.121 //
2595 mike           1.23  //     </IPARAMVALUE>
2596                      //     <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE>
2597                      //
2598                      //     USE: Create parameter for getProperty operation
2599 brian.campbell 1.113 //==========================================================
2600 kumpf          1.27  void XmlWriter::appendPropertyNameIParameter(
2601 mike           1.125     Buffer& out,
2602 kumpf          1.80      const CIMName& propertyName)
2603 mike           1.23  {
2604 kumpf          1.29      _appendIParamValueElementBegin(out, "PropertyName");
2605 mike           1.126     out << STRLIT("<VALUE>") << propertyName << STRLIT("</VALUE>\n");
2606 kumpf          1.29      _appendIParamValueElementEnd(out);
2607 kumpf          1.27  }
2608 mike           1.23  
2609                      //------------------------------------------------------------------------------
2610                      //
2611 kumpf          1.27  // appendPropertyValueIParameter()
2612 mike           1.24  //
2613                      //------------------------------------------------------------------------------
2614                      
2615 kumpf          1.27  void XmlWriter::appendPropertyValueIParameter(
2616 mike           1.125     Buffer& out,
2617 kumpf          1.27      const char* name,
2618 mike           1.24      const CIMValue& value)
2619                      {
2620 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2621 kumpf          1.54      appendValueElement(out, value);
2622 kumpf          1.29      _appendIParamValueElementEnd(out);
2623 mike           1.24  }
2624                      
2625                      //------------------------------------------------------------------------------
2626                      //
2627 kumpf          1.27  // appendPropertyListIParameter()
2628 mike           1.24  //
2629                      //------------------------------------------------------------------------------
2630                      
2631 kumpf          1.27  void XmlWriter::appendPropertyListIParameter(
2632 mike           1.125     Buffer& out,
2633 mike           1.24      const CIMPropertyList& propertyList)
2634                      {
2635 kumpf          1.29      _appendIParamValueElementBegin(out, "PropertyList");
2636 mike           1.24  
2637 kumpf          1.83      //
2638 david.dillard  1.121     //  A NULL (unassigned) value for a parameter is specified by an
2639 kumpf          1.83      //  <IPARAMVALUE> element with no subelement
2640                          //
2641                          if (!propertyList.isNull ())
2642 mike           1.24      {
2643 mike           1.126         out << STRLIT("<VALUE.ARRAY>\n");
2644 kumpf          1.83          for (Uint32 i = 0; i < propertyList.size(); i++)
2645                              {
2646 mike           1.126             out << STRLIT("<VALUE>") << propertyList[i] << STRLIT("</VALUE>\n");
2647 kumpf          1.83          }
2648 mike           1.126         out << STRLIT("</VALUE.ARRAY>\n");
2649 mike           1.24      }
2650 kumpf          1.27  
2651 kumpf          1.29      _appendIParamValueElementEnd(out);
2652 mike           1.24  }
2653                      
2654                      //------------------------------------------------------------------------------
2655                      //
2656 kumpf          1.27  // appendQualifierDeclarationIParameter()
2657 mike           1.23  //
2658                      //------------------------------------------------------------------------------
2659                      
2660 kumpf          1.27  void XmlWriter::appendQualifierDeclarationIParameter(
2661 mike           1.125     Buffer& out,
2662 kumpf          1.27      const char* name,
2663 mike           1.23      const CIMConstQualifierDecl& qualifierDecl)
2664                      {
2665 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2666 kumpf          1.56      appendQualifierDeclElement(out, qualifierDecl);
2667 kumpf          1.29      _appendIParamValueElementEnd(out);
2668 kumpf          1.40  }
2669                      
2670                      //------------------------------------------------------------------------------
2671                      //
2672                      // XmlWriter::formatHttpErrorRspMessage()
2673                      //
2674                      //------------------------------------------------------------------------------
2675                      
2676 mike           1.125 Buffer XmlWriter::formatHttpErrorRspMessage(
2677 kumpf          1.40      const String& status,
2678                          const String& cimError,
2679 kumpf          1.41      const String& errorDetail)
2680 kumpf          1.40  {
2681 mike           1.125     Buffer out;
2682 kumpf          1.40  
2683 kumpf          1.41      appendHttpErrorResponseHeader(out, status, cimError, errorDetail);
2684 kumpf          1.40  
2685 kumpf          1.41      return out;
2686 mike           1.23  }
2687                      
2688 chuck          1.89  // l10n - add content language support to the format methods below
2689                      
2690 mike           1.23  //------------------------------------------------------------------------------
2691                      //
2692 kumpf          1.27  // XmlWriter::formatSimpleMethodReqMessage()
2693 mike           1.23  //
2694                      //------------------------------------------------------------------------------
2695                      
2696 kumpf          1.27  // ATTN-RK-P1-20020228: Need to complete copy elimination optimization
2697 mike           1.125 Buffer XmlWriter::formatSimpleMethodReqMessage(
2698 kumpf          1.27      const char* host,
2699 kumpf          1.80      const CIMNamespaceName& nameSpace,
2700 kumpf          1.59      const CIMObjectPath& path,
2701 kumpf          1.80      const CIMName& methodName,
2702 kumpf          1.30      const Array<CIMParamValue>& parameters,
2703 kumpf          1.27      const String& messageId,
2704 kumpf          1.82      HttpMethod httpMethod,
2705 chuck          1.89      const String& authenticationHeader,
2706 kumpf          1.133     const AcceptLanguageList& httpAcceptLanguages,
2707                          const ContentLanguageList& httpContentLanguages)
2708 kumpf          1.27  {
2709 mike           1.125     Buffer out;
2710                          Buffer tmp;
2711 kumpf          1.59      CIMObjectPath localObjectPath = path;
2712 kumpf          1.80      localObjectPath.setNameSpace(nameSpace.getString());
2713 kumpf          1.77      localObjectPath.setHost(String::EMPTY);
2714 kumpf          1.27  
2715 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2716                          _appendSimpleReqElementBegin(out);
2717                          _appendMethodCallElementBegin(out, methodName);
2718 kumpf          1.38      appendLocalObjectPathElement(out, localObjectPath);
2719 kumpf          1.30      for (Uint32 i=0; i < parameters.size(); i++)
2720 kumpf          1.29      {
2721 kumpf          1.56          appendParamValueElement(out, parameters[i]);
2722 kumpf          1.29      }
2723                          _appendMethodCallElementEnd(out);
2724                          _appendSimpleReqElementEnd(out);
2725                          _appendMessageElementEnd(out);
2726 kumpf          1.27  
2727                          appendMethodCallHeader(
2728 kumpf          1.146         tmp,
2729                              host,
2730                              methodName,
2731                              localObjectPath.toString(),
2732 kumpf          1.27          authenticationHeader,
2733 kumpf          1.82          httpMethod,
2734 chuck          1.89          httpAcceptLanguages,
2735                              httpContentLanguages,
2736 kumpf          1.148         out.size());
2737 kumpf          1.27      tmp << out;
2738                      
2739                          return tmp;
2740                      }
2741                      
2742 w.white        1.108 //PEP 128 adding serverRsponseTime to header
2743 mike           1.125 Buffer XmlWriter::formatSimpleMethodRspMessage(
2744 w.white        1.108     const CIMName& methodName,
2745                          const String& messageId,
2746                          HttpMethod httpMethod,
2747 kumpf          1.133     const ContentLanguageList& httpContentLanguages,
2748 mike           1.125     const Buffer& body,
2749 kumpf          1.146     Uint64 serverResponseTime,
2750                          Boolean isFirst,
2751                          Boolean isLast)
2752                      {
2753                          Buffer out;
2754                      
2755                          if (isFirst == true)
2756                          {
2757                              // NOTE: temporarily put zero for content length. the http code
2758                              // will later decide to fill in the length or remove it altogether
2759                              appendMethodResponseHeader(
2760                                  out, httpMethod, httpContentLanguages, 0, serverResponseTime);
2761                              _appendMessageElementBegin(out, messageId);
2762                              _appendSimpleRspElementBegin(out);
2763                              _appendMethodResponseElementBegin(out, methodName);
2764                          }
2765                      
2766                          if (body.size() != 0)
2767                          {
2768                              out << body;
2769                          }
2770 kumpf          1.146 
2771                          if (isLast == true)
2772                          {
2773                              _appendMethodResponseElementEnd(out);
2774                              _appendSimpleRspElementEnd(out);
2775                              _appendMessageElementEnd(out);
2776                          }
2777 david.dillard  1.121 
2778 kumpf          1.146     return out;
2779 w.white        1.108 }
2780                      
2781                      
2782 mike           1.23  //------------------------------------------------------------------------------
2783                      //
2784 kumpf          1.28  // XmlWriter::formatSimpleMethodErrorRspMessage()
2785                      //
2786                      //------------------------------------------------------------------------------
2787                      
2788 mike           1.125 Buffer XmlWriter::formatSimpleMethodErrorRspMessage(
2789 kumpf          1.80      const CIMName& methodName,
2790 kumpf          1.28      const String& messageId,
2791 kumpf          1.82      HttpMethod httpMethod,
2792 kumpf          1.42      const CIMException& cimException)
2793 kumpf          1.28  {
2794 mike           1.125     Buffer out;
2795                          Buffer tmp;
2796 kumpf          1.28  
2797 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2798                          _appendSimpleRspElementBegin(out);
2799 kumpf          1.80      _appendMethodResponseElementBegin(out, methodName);
2800 kumpf          1.42      _appendErrorElement(out, cimException);
2801 kumpf          1.29      _appendMethodResponseElementEnd(out);
2802                          _appendSimpleRspElementEnd(out);
2803                          _appendMessageElementEnd(out);
2804 kumpf          1.28  
2805 kumpf          1.146     appendMethodResponseHeader(
2806                              tmp,
2807                              httpMethod,
2808                              cimException.getContentLanguages(),
2809 kumpf          1.148         out.size());
2810 kumpf          1.28      tmp << out;
2811                      
2812                          return tmp;
2813                      }
2814                      
2815                      //------------------------------------------------------------------------------
2816                      //
2817 kumpf          1.27  // XmlWriter::formatSimpleIMethodReqMessage()
2818 mike           1.23  //
2819                      //------------------------------------------------------------------------------
2820                      
2821 mike           1.125 Buffer XmlWriter::formatSimpleIMethodReqMessage(
2822 kumpf          1.27      const char* host,
2823 kumpf          1.80      const CIMNamespaceName& nameSpace,
2824                          const CIMName& iMethodName,
2825 kumpf          1.27      const String& messageId,
2826 kumpf          1.82      HttpMethod httpMethod,
2827 kumpf          1.27      const String& authenticationHeader,
2828 kumpf          1.133     const AcceptLanguageList& httpAcceptLanguages,
2829                          const ContentLanguageList& httpContentLanguages,
2830 mike           1.125     const Buffer& body)
2831 mike           1.23  {
2832 mike           1.125     Buffer out;
2833                          Buffer tmp;
2834 kumpf          1.27  
2835 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2836                          _appendSimpleReqElementBegin(out);
2837                          _appendIMethodCallElementBegin(out, iMethodName);
2838 kumpf          1.80      appendLocalNameSpacePathElement(out, nameSpace.getString());
2839 kumpf          1.27      out << body;
2840 kumpf          1.29      _appendIMethodCallElementEnd(out);
2841                          _appendSimpleReqElementEnd(out);
2842                          _appendMessageElementEnd(out);
2843 kumpf          1.27  
2844                          appendMethodCallHeader(
2845 kumpf          1.146         tmp,
2846                              host,
2847                              iMethodName,
2848                              nameSpace.getString(),
2849 kumpf          1.27          authenticationHeader,
2850 kumpf          1.82          httpMethod,
2851 chuck          1.89          httpAcceptLanguages,
2852                              httpContentLanguages,
2853 kumpf          1.148         out.size());
2854 kumpf          1.27      tmp << out;
2855 mike           1.23  
2856 kumpf          1.27      return tmp;
2857 mike           1.23  }
2858                      
2859                      //------------------------------------------------------------------------------
2860                      //
2861 kumpf          1.27  // XmlWriter::formatSimpleIMethodRspMessage()
2862 mike           1.23  //
2863                      //------------------------------------------------------------------------------
2864                      
2865 mike           1.125 Buffer XmlWriter::formatSimpleIMethodRspMessage(
2866 kumpf          1.80      const CIMName& iMethodName,
2867 kumpf          1.27      const String& messageId,
2868 kumpf          1.82      HttpMethod httpMethod,
2869 kumpf          1.133     const ContentLanguageList& httpContentLanguages,
2870 mike           1.125     const Buffer& body,
2871 david.dillard  1.130     Uint64 serverResponseTime,
2872 david.dillard  1.121     Boolean isFirst,
2873                          Boolean isLast)
2874 mike           1.23  {
2875 mike           1.125     Buffer out;
2876 mike           1.23  
2877 kumpf          1.146     if (isFirst == true)
2878                          {
2879                              // NOTE: temporarily put zero for content length. the http code
2880                              // will later decide to fill in the length or remove it altogether
2881                              appendMethodResponseHeader(
2882                                  out, httpMethod, httpContentLanguages, 0, serverResponseTime);
2883                              _appendMessageElementBegin(out, messageId);
2884                              _appendSimpleRspElementBegin(out);
2885                              _appendIMethodResponseElementBegin(out, iMethodName);
2886                      
2887                              // output the start of the return tag. Test if there is response data
2888                              // by:
2889                              // 1. there is data on the first chunk OR
2890                              // 2. there is no data on the first chunk but isLast is false implying
2891                              //    there is more non-empty data to come. If all subsequent chunks
2892                              //    are empty, then this generates and empty response.
2893                              if (body.size() != 0 || isLast == false)
2894                                  _appendIReturnValueElementBegin(out);
2895                          }
2896 w.white        1.108 
2897                          if (body.size() != 0)
2898                          {
2899 kumpf          1.146         out << body;
2900 w.white        1.108     }
2901                      
2902 kumpf          1.146     if (isLast == true)
2903                          {
2904                              if (body.size() != 0 || isFirst == false)
2905                                  _appendIReturnValueElementEnd(out);
2906                              _appendIMethodResponseElementEnd(out);
2907                              _appendSimpleRspElementEnd(out);
2908                              _appendMessageElementEnd(out);
2909                          }
2910 w.white        1.108 
2911                          return out;
2912                      }
2913                      
2914                      
2915 kumpf          1.28  //------------------------------------------------------------------------------
2916                      //
2917                      // XmlWriter::formatSimpleIMethodErrorRspMessage()
2918                      //
2919                      //------------------------------------------------------------------------------
2920                      
2921 mike           1.125 Buffer XmlWriter::formatSimpleIMethodErrorRspMessage(
2922 kumpf          1.80      const CIMName& iMethodName,
2923 kumpf          1.28      const String& messageId,
2924 kumpf          1.82      HttpMethod httpMethod,
2925 kumpf          1.42      const CIMException& cimException)
2926 kumpf          1.28  {
2927 mike           1.125     Buffer out;
2928                          Buffer tmp;
2929 kumpf          1.28  
2930 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2931                          _appendSimpleRspElementBegin(out);
2932 kumpf          1.80      _appendIMethodResponseElementBegin(out, iMethodName);
2933 kumpf          1.42      _appendErrorElement(out, cimException);
2934 kumpf          1.29      _appendIMethodResponseElementEnd(out);
2935                          _appendSimpleRspElementEnd(out);
2936                          _appendMessageElementEnd(out);
2937 kumpf          1.28  
2938 chuck          1.89      appendMethodResponseHeader(tmp,
2939 kumpf          1.146         httpMethod,
2940                              cimException.getContentLanguages(),
2941 kumpf          1.148         out.size());
2942 kumpf          1.28      tmp << out;
2943                      
2944                          return tmp;
2945                      }
2946                      
2947 kumpf          1.27  //******************************************************************************
2948                      //
2949                      // Export Messages (used for indications)
2950                      //
2951                      //******************************************************************************
2952 mike           1.23  
2953 kumpf          1.27  //------------------------------------------------------------------------------
2954                      //
2955                      // appendEMethodRequestHeader()
2956                      //
2957                      //     Build HTTP request header for export operation.
2958                      //
2959                      //------------------------------------------------------------------------------
2960 mike           1.23  
2961 kumpf          1.27  void XmlWriter::appendEMethodRequestHeader(
2962 mike           1.125     Buffer& out,
2963 kumpf          1.50      const char* requestUri,
2964 kumpf          1.27      const char* host,
2965 kumpf          1.80      const CIMName& cimMethod,
2966 kumpf          1.82      HttpMethod httpMethod,
2967 kumpf          1.27      const String& authenticationHeader,
2968 kumpf          1.133     const AcceptLanguageList& acceptLanguages,
2969                          const ContentLanguageList& contentLanguages,
2970 kumpf          1.27      Uint32 contentLength)
2971                      {
2972                          char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
2973 mike           1.23  
2974 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
2975                          {
2976 mike           1.126       out << STRLIT("M-POST ") << requestUri << STRLIT(" HTTP/1.1\r\n");
2977 kumpf          1.82      }
2978                          else
2979                          {
2980 mike           1.126       out << STRLIT("POST ") << requestUri << STRLIT(" HTTP/1.1\r\n");
2981 kumpf          1.82      }
2982 mike           1.126     out << STRLIT("HOST: ") << host << STRLIT("\r\n");
2983                          out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");
2984                          OUTPUT_CONTENTLENGTH;
2985 brian.campbell 1.107 
2986 chuck          1.89      if (acceptLanguages.size() > 0)
2987                          {
2988 kumpf          1.146         out << STRLIT("Accept-Language: ") << acceptLanguages << STRLIT("\r\n");
2989 chuck          1.89      }
2990                          if (contentLanguages.size() > 0)
2991                          {
2992 kumpf          1.146         out << STRLIT("Content-Language: ") << contentLanguages <<
2993                                  STRLIT("\r\n");
2994 david.dillard  1.121     }
2995 brian.campbell 1.107 
2996 brian.campbell 1.113 #ifdef PEGASUS_DEBUG
2997 kumpf          1.146     // backdoor environment variable to turn OFF client requesting transfer
2998                          // encoding. The default is on. to turn off, set this variable to zero.
2999                          // This should be removed when stable. This should only be turned off in
3000                          // a debugging/testing environment.
3001                      
3002                          static const char *clientTransferEncodingOff =
3003                              getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST");
3004                          if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0')
3005 a.dunfey       1.110 #endif
3006 kumpf          1.146     out << STRLIT("TE: chunked, trailers\r\n");
3007 brian.campbell 1.107 
3008 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
3009                          {
3010 kumpf          1.146         out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");
3011 mike           1.126         out << nn << STRLIT("\r\n");
3012                              out << nn << STRLIT("-CIMExport: MethodRequest\r\n");
3013 kumpf          1.146         out << nn << STRLIT("-CIMExportMethod: ") << cimMethod <<
3014                                  STRLIT("\r\n");
3015 kumpf          1.82      }
3016                          else
3017                          {
3018 mike           1.126         out << STRLIT("CIMExport: MethodRequest\r\n");
3019                              out << STRLIT("CIMExportMethod: ") << cimMethod << STRLIT("\r\n");
3020 kumpf          1.82      }
3021                      
3022 kumpf          1.27      if (authenticationHeader.size())
3023                          {
3024 mike           1.126         out << authenticationHeader << STRLIT("\r\n");
3025 kumpf          1.27      }
3026 brian.campbell 1.107 
3027 mike           1.126     out << STRLIT("\r\n");
3028 kumpf          1.27  }
3029 mike           1.23  
3030 kumpf          1.27  //------------------------------------------------------------------------------
3031                      //
3032                      // appendEMethodResponseHeader()
3033                      //
3034                      //     Build HTTP response header for export operation.
3035                      //
3036                      //------------------------------------------------------------------------------
3037 mike           1.23  
3038 kumpf          1.27  void XmlWriter::appendEMethodResponseHeader(
3039 mike           1.125     Buffer& out,
3040 kumpf          1.82      HttpMethod httpMethod,
3041 kumpf          1.133     const ContentLanguageList& contentLanguages,
3042 kumpf          1.27      Uint32 contentLength)
3043                      {
3044                          char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
3045 mike           1.23  
3046 mike           1.126     out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n");
3047                          out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");
3048                          OUTPUT_CONTENTLENGTH;
3049 brian.campbell 1.107 
3050 chuck          1.89      if (contentLanguages.size() > 0)
3051                          {
3052 kumpf          1.146         out << STRLIT("Content-Language: ") << contentLanguages <<
3053                                  STRLIT("\r\n");
3054 david.dillard  1.121     }
3055 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
3056                          {
3057 mike           1.126         out << STRLIT("Ext:\r\n");
3058                              out << STRLIT("Cache-Control: no-cache\r\n");
3059                              out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");
3060                              out << nn << STRLIT("\r\n");
3061                              out << nn << STRLIT("-CIMExport: MethodResponse\r\n\r\n");
3062 kumpf          1.82      }
3063                          else
3064                          {
3065 mike           1.126         out << STRLIT("CIMExport: MethodResponse\r\n\r\n");
3066 kumpf          1.82      }
3067 mike           1.23  }
3068                      
3069                      //------------------------------------------------------------------------------
3070                      //
3071 kumpf          1.29  // _appendSimpleExportReqElementBegin()
3072                      // _appendSimpleExportReqElementEnd()
3073 kumpf          1.27  //
3074                      //     <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)>
3075 mike           1.23  //
3076                      //------------------------------------------------------------------------------
3077                      
3078 kumpf          1.29  void XmlWriter::_appendSimpleExportReqElementBegin(
3079 mike           1.125     Buffer& out)
3080 mike           1.23  {
3081 mike           1.126     out << STRLIT("<SIMPLEEXPREQ>\n");
3082 kumpf          1.27  }
3083 mike           1.23  
3084 kumpf          1.29  void XmlWriter::_appendSimpleExportReqElementEnd(
3085 mike           1.125     Buffer& out)
3086 kumpf          1.27  {
3087 mike           1.126     out << STRLIT("</SIMPLEEXPREQ>\n");
3088 mike           1.23  }
3089                      
3090                      //------------------------------------------------------------------------------
3091                      //
3092 kumpf          1.29  // _appendEMethodCallElementBegin()
3093                      // _appendEMethodCallElementEnd()
3094 kumpf          1.27  //
3095                      //     <!ELEMENT EXPMETHODCALL (IPARAMVALUE*)>
3096                      //     <!ATTLIST EXPMETHODCALL %CIMName;>
3097 mike           1.23  //
3098                      //------------------------------------------------------------------------------
3099                      
3100 kumpf          1.29  void XmlWriter::_appendEMethodCallElementBegin(
3101 mike           1.125     Buffer& out,
3102 kumpf          1.80      const CIMName& name)
3103 mike           1.23  {
3104 mike           1.126     out << STRLIT("<EXPMETHODCALL NAME=\"") << name << STRLIT("\">\n");
3105 mike           1.24  }
3106                      
3107 kumpf          1.29  void XmlWriter::_appendEMethodCallElementEnd(
3108 mike           1.125     Buffer& out)
3109 mike           1.24  {
3110 mike           1.126     out << STRLIT("</EXPMETHODCALL>\n");
3111 mike           1.24  }
3112                      
3113                      //------------------------------------------------------------------------------
3114                      //
3115 kumpf          1.85  // _appendEParamValueElementBegin()
3116                      // _appendEParamValueElementEnd()
3117                      //
3118 david.dillard  1.121 //     <!ELEMENT EXPPARAMVALUE (INSTANCE)>
3119                      //     <!ATTLIST EXPPARAMVALUE
3120 kumpf          1.85  //         %CIMName;>
3121                      //
3122                      //------------------------------------------------------------------------------
3123                      
3124                      void XmlWriter::_appendEParamValueElementBegin(
3125 mike           1.125     Buffer& out,
3126 kumpf          1.85      const char* name)
3127                      {
3128 mike           1.126     out << STRLIT("<EXPPARAMVALUE NAME=\"") << name << STRLIT("\">\n");
3129 kumpf          1.85  }
3130                      
3131                      void XmlWriter::_appendEParamValueElementEnd(
3132 mike           1.125     Buffer& out)
3133 kumpf          1.85  {
3134 mike           1.126     out << STRLIT("</EXPPARAMVALUE>\n");
3135 kumpf          1.85  }
3136                      
3137                      //------------------------------------------------------------------------------
3138                      //
3139                      // appendInstanceEParameter()
3140                      //
3141                      //------------------------------------------------------------------------------
3142                      
3143                      void XmlWriter::appendInstanceEParameter(
3144 mike           1.125     Buffer& out,
3145 kumpf          1.85      const char* name,
3146                          const CIMInstance& instance)
3147                      {
3148                          _appendEParamValueElementBegin(out, name);
3149                          appendInstanceElement(out, instance);
3150                          _appendEParamValueElementEnd(out);
3151                      }
3152                      
3153                      //------------------------------------------------------------------------------
3154                      //
3155 kumpf          1.29  // _appendSimpleExportRspElementBegin()
3156                      // _appendSimpleExportRspElementEnd()
3157 mike           1.24  //
3158 kumpf          1.27  //     <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)>
3159 mike           1.24  //
3160                      //------------------------------------------------------------------------------
3161                      
3162 kumpf          1.29  void XmlWriter::_appendSimpleExportRspElementBegin(
3163 mike           1.125     Buffer& out)
3164 kumpf          1.27  {
3165 mike           1.126     out << STRLIT("<SIMPLEEXPRSP>\n");
3166 kumpf          1.27  }
3167                      
3168 kumpf          1.29  void XmlWriter::_appendSimpleExportRspElementEnd(
3169 mike           1.125     Buffer& out)
3170 mike           1.24  {
3171 mike           1.126     out << STRLIT("</SIMPLEEXPRSP>\n");
3172 mike           1.24  }
3173                      
3174                      //------------------------------------------------------------------------------
3175                      //
3176 kumpf          1.29  // _appendEMethodResponseElementBegin()
3177                      // _appendEMethodResponseElementEnd()
3178 mike           1.24  //
3179                      //     <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)>
3180                      //     <!ATTLIST EXPMETHODRESPONSE %CIMName;>
3181                      //
3182                      //------------------------------------------------------------------------------
3183                      
3184 kumpf          1.29  void XmlWriter::_appendEMethodResponseElementBegin(
3185 mike           1.125     Buffer& out,
3186 kumpf          1.80      const CIMName& name)
3187 mike           1.24  {
3188 mike           1.126     out << STRLIT("<EXPMETHODRESPONSE NAME=\"") << name << STRLIT("\">\n");
3189 kumpf          1.27  }
3190                      
3191 kumpf          1.29  void XmlWriter::_appendEMethodResponseElementEnd(
3192 mike           1.125     Buffer& out)
3193 kumpf          1.27  {
3194 mike           1.126     out << STRLIT("</EXPMETHODRESPONSE>\n");
3195 mike           1.24  }
3196                      
3197                      //------------------------------------------------------------------------------
3198                      //
3199 kumpf          1.27  // XmlWriter::formatSimpleEMethodReqMessage()
3200 mike           1.24  //
3201                      //------------------------------------------------------------------------------
3202                      
3203 mike           1.125 Buffer XmlWriter::formatSimpleEMethodReqMessage(
3204 kumpf          1.50      const char* requestUri,
3205 kumpf          1.27      const char* host,
3206 kumpf          1.80      const CIMName& eMethodName,
3207 kumpf          1.27      const String& messageId,
3208 kumpf          1.82      HttpMethod httpMethod,
3209 kumpf          1.27      const String& authenticationHeader,
3210 kumpf          1.133     const AcceptLanguageList& httpAcceptLanguages,
3211                          const ContentLanguageList& httpContentLanguages,
3212 mike           1.125     const Buffer& body)
3213 mike           1.24  {
3214 mike           1.125     Buffer out;
3215                          Buffer tmp;
3216 kumpf          1.27  
3217 kumpf          1.29      _appendMessageElementBegin(out, messageId);
3218                          _appendSimpleExportReqElementBegin(out);
3219                          _appendEMethodCallElementBegin(out, eMethodName);
3220 kumpf          1.27      out << body;
3221 kumpf          1.29      _appendEMethodCallElementEnd(out);
3222                          _appendSimpleExportReqElementEnd(out);
3223                          _appendMessageElementEnd(out);
3224 kumpf          1.27  
3225                          appendEMethodRequestHeader(
3226                              tmp,
3227 kumpf          1.50          requestUri,
3228 kumpf          1.27          host,
3229                              eMethodName,
3230 kumpf          1.82          httpMethod,
3231 kumpf          1.27          authenticationHeader,
3232 chuck          1.89          httpAcceptLanguages,
3233                              httpContentLanguages,
3234 kumpf          1.148         out.size());
3235 kumpf          1.27      tmp << out;
3236 mike           1.24  
3237 kumpf          1.50      return tmp;
3238 mike           1.24  }
3239                      
3240                      //------------------------------------------------------------------------------
3241                      //
3242 kumpf          1.27  // XmlWriter::formatSimpleEMethodRspMessage()
3243 mike           1.24  //
3244                      //------------------------------------------------------------------------------
3245                      
3246 mike           1.125 Buffer XmlWriter::formatSimpleEMethodRspMessage(
3247 kumpf          1.80      const CIMName& eMethodName,
3248 mike           1.24      const String& messageId,
3249 kumpf          1.82      HttpMethod httpMethod,
3250 kumpf          1.133     const ContentLanguageList& httpContentLanguages,
3251 mike           1.125     const Buffer& body)
3252 mike           1.24  {
3253 mike           1.125     Buffer out;
3254                          Buffer tmp;
3255 kumpf          1.27  
3256 kumpf          1.29      _appendMessageElementBegin(out, messageId);
3257                          _appendSimpleExportRspElementBegin(out);
3258                          _appendEMethodResponseElementBegin(out, eMethodName);
3259 kumpf          1.27      out << body;
3260 kumpf          1.29      _appendEMethodResponseElementEnd(out);
3261                          _appendSimpleExportRspElementEnd(out);
3262                          _appendMessageElementEnd(out);
3263 kumpf          1.28  
3264 david.dillard  1.121     appendEMethodResponseHeader(tmp,
3265 kumpf          1.146         httpMethod,
3266                              httpContentLanguages,
3267 kumpf          1.148         out.size());
3268 kumpf          1.28      tmp << out;
3269                      
3270                          return tmp;
3271                      }
3272                      
3273                      //------------------------------------------------------------------------------
3274                      //
3275                      // XmlWriter::formatSimpleEMethodErrorRspMessage()
3276                      //
3277                      //------------------------------------------------------------------------------
3278                      
3279 mike           1.125 Buffer XmlWriter::formatSimpleEMethodErrorRspMessage(
3280 kumpf          1.80      const CIMName& eMethodName,
3281 kumpf          1.28      const String& messageId,
3282 kumpf          1.82      HttpMethod httpMethod,
3283 kumpf          1.42      const CIMException& cimException)
3284 kumpf          1.28  {
3285 mike           1.125     Buffer out;
3286                          Buffer tmp;
3287 kumpf          1.28  
3288 kumpf          1.29      _appendMessageElementBegin(out, messageId);
3289                          _appendSimpleExportRspElementBegin(out);
3290 kumpf          1.80      _appendEMethodResponseElementBegin(out, eMethodName);
3291 kumpf          1.42      _appendErrorElement(out, cimException);
3292 kumpf          1.29      _appendEMethodResponseElementEnd(out);
3293                          _appendSimpleExportRspElementEnd(out);
3294                          _appendMessageElementEnd(out);
3295 kumpf          1.27  
3296 kumpf          1.146     appendEMethodResponseHeader(
3297                              tmp,
3298                              httpMethod,
3299                              cimException.getContentLanguages(),
3300 kumpf          1.148         out.size());
3301 kumpf          1.27      tmp << out;
3302                      
3303                          return tmp;
3304 mike           1.24  }
3305                      
3306                      //------------------------------------------------------------------------------
3307                      //
3308 s.hills        1.99  // _xmlWritter_printAttributes()
3309 mike           1.24  //
3310                      //------------------------------------------------------------------------------
3311                      
3312 s.hills        1.99  void _xmlWritter_printAttributes(
3313 kumpf          1.27      PEGASUS_STD(ostream)& os,
3314                          const XmlAttribute* attributes,
3315                          Uint32 attributeCount)
3316 mike           1.24  {
3317 kumpf          1.27      for (Uint32 i = 0; i < attributeCount; i++)
3318                          {
3319 kumpf          1.146         os << attributes[i].name << "=";
3320 kumpf          1.27  
3321 kumpf          1.146         os << '"';
3322                              _xmlWritter_appendSpecial(os, attributes[i].value);
3323                              os << '"';
3324 mike           1.24  
3325 kumpf          1.146         if (i + 1 != attributeCount)
3326                                  os << ' ';
3327 kumpf          1.27      }
3328 mike           1.24  }
3329                      
3330                      //------------------------------------------------------------------------------
3331                      //
3332 s.hills        1.99  // _xmlWritter_indent()
3333 mike           1.24  //
3334                      //------------------------------------------------------------------------------
3335                      
3336 kumpf          1.146 void _xmlWritter_indent(
3337                          PEGASUS_STD(ostream)& os,
3338                          Uint32 level,
3339                          Uint32 indentChars)
3340 mike           1.24  {
3341 kumpf          1.27      Uint32 n = level * indentChars;
3342                      
3343                          for (Uint32 i = 0; i < n; i++)
3344 kumpf          1.146         os << ' ';
3345 mike           1.24  }
3346                      
3347                      //------------------------------------------------------------------------------
3348                      //
3349 kumpf          1.27  // indentedPrint()
3350 mike           1.24  //
3351                      //------------------------------------------------------------------------------
3352                      
3353 kumpf          1.27  void XmlWriter::indentedPrint(
3354 david.dillard  1.121     PEGASUS_STD(ostream)& os,
3355                          const char* text,
3356 kumpf          1.27      Uint32 indentChars)
3357 mike           1.24  {
3358 a.arora        1.106     AutoArrayPtr<char> tmp(strcpy(new char[strlen(text) + 1], text));
3359 kumpf          1.27  
3360 a.arora        1.106     XmlParser parser(tmp.get());
3361 kumpf          1.27      XmlEntry entry;
3362                          Stack<const char*> stack;
3363 kumpf          1.26  
3364 kumpf          1.27      while (parser.next(entry))
3365 kumpf          1.26      {
3366 kumpf          1.146         switch (entry.type)
3367                              {
3368                                  case XmlEntry::XML_DECLARATION:
3369                                  {
3370                                      _xmlWritter_indent(os, stack.size(), indentChars);
3371                      
3372                                      os << "<?" << entry.text << " ";
3373                                      _xmlWritter_printAttributes(
3374                                          os, entry.attributes, entry.attributeCount);
3375                                      os << "?>";
3376                                      break;
3377                                  }
3378                      
3379                                  case XmlEntry::START_TAG:
3380                                  {
3381                                      _xmlWritter_indent(os, stack.size(), indentChars);
3382                      
3383                                      os << "<" << entry.text;
3384                      
3385                                      if (entry.attributeCount)
3386                                          os << ' ';
3387 kumpf          1.146 
3388                                      _xmlWritter_printAttributes(
3389                                          os, entry.attributes, entry.attributeCount);
3390                                      os << ">";
3391                                      stack.push(entry.text);
3392                                      break;
3393                                  }
3394                      
3395                                  case XmlEntry::EMPTY_TAG:
3396                                  {
3397                                      _xmlWritter_indent(os, stack.size(), indentChars);
3398                      
3399                                      os << "<" << entry.text << " ";
3400                                      _xmlWritter_printAttributes(
3401                                          os, entry.attributes, entry.attributeCount);
3402                                      os << "/>";
3403                                      break;
3404                                  }
3405 kumpf          1.27  
3406 kumpf          1.146             case XmlEntry::END_TAG:
3407                                  {
3408                                      if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
3409                                          stack.pop();
3410                      
3411                                      _xmlWritter_indent(os, stack.size(), indentChars);
3412                      
3413                                      os << "</" << entry.text << ">";
3414                                      break;
3415                                  }
3416                      
3417                                  case XmlEntry::COMMENT:
3418                                  {
3419                                      _xmlWritter_indent(os, stack.size(), indentChars);
3420                                      os << "<!--";
3421                                      _xmlWritter_appendSpecial(os, entry.text);
3422                                      os << "-->";
3423                                      break;
3424                                  }
3425                      
3426                                  case XmlEntry::CONTENT:
3427 kumpf          1.146             {
3428                                      _xmlWritter_indent(os, stack.size(), indentChars);
3429                                      _xmlWritter_appendSpecial(os, entry.text);
3430                                      break;
3431                                  }
3432                      
3433                                  case XmlEntry::CDATA:
3434                                  {
3435                                      _xmlWritter_indent(os, stack.size(), indentChars);
3436                                      os << "<![CDATA[" << entry.text << "]]>";
3437                                      break;
3438                                  }
3439                      
3440                                  case XmlEntry::DOCTYPE:
3441                                  {
3442                                      _xmlWritter_indent(os, stack.size(), indentChars);
3443                                      os << "<!DOCTYPE...>";
3444                                      break;
3445                                  }
3446                              }
3447                      
3448 kumpf          1.146         os << PEGASUS_STD(endl);
3449 kumpf          1.26      }
3450 mike           1.24  }
3451                      
3452                      //------------------------------------------------------------------------------
3453                      //
3454 kumpf          1.27  // XmlWriter::getNextMessageId()
3455 mike           1.24  //
3456                      //------------------------------------------------------------------------------
3457                      
3458 mike           1.139 static IDFactory _messageIDFactory(1000);
3459                      
3460 kumpf          1.27  String XmlWriter::getNextMessageId()
3461 mike           1.24  {
3462 kumpf          1.27      char buffer[16];
3463 mike           1.139     sprintf(buffer, "%u", _messageIDFactory.getID());
3464 kumpf          1.27      return buffer;
3465 kumpf          1.68  }
3466                      
3467                      //------------------------------------------------------------------------------
3468                      //
3469                      // XmlWriter::keyBindingTypeToString
3470                      //
3471                      //------------------------------------------------------------------------------
3472 kumpf          1.79  const char* XmlWriter::keyBindingTypeToString (CIMKeyBinding::Type type)
3473 kumpf          1.68  {
3474                          switch (type)
3475                          {
3476 kumpf          1.79          case CIMKeyBinding::BOOLEAN:
3477 kumpf          1.68              return "boolean";
3478                      
3479 kumpf          1.79          case CIMKeyBinding::STRING:
3480 kumpf          1.68              return "string";
3481                      
3482 kumpf          1.79          case CIMKeyBinding::NUMERIC:
3483 kumpf          1.68              return "numeric";
3484                      
3485 kumpf          1.79          case CIMKeyBinding::REFERENCE:
3486 kumpf          1.68          default:
3487                                  PEGASUS_ASSERT(false);
3488                          }
3489                      
3490 gs.keenan      1.124     return "unknown";
3491 mike           1.23  }
3492                      
3493                      PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2