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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2