(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 karl           1.154 //---------------------------------------------------------------------- 
2385                      // 
2386                      // appendParmType
2387                      // Appends the Param type and EmbeddedObject Info
2388                      // to the buffer
2389                      // %EmbeddedObject; #IMPLIED
2390                      // %ParamType;>
2391                      // 
2392                      //---------------------------------------------------------------------
2393                      void XmlWriter::appendParamTypeAndEmbeddedObjAttrib(
2394 mike           1.125     Buffer& out,
2395 karl           1.154     const CIMType& type)
2396 kumpf          1.27  {
2397                      
2398 david.dillard  1.121     // If the property type is CIMObject, then
2399 karl           1.154     //   encode the property in CIM-XML as a string with the EmbeddedObject
2400                          //   attribute (there is not currently a CIM-XML "object"
2401                          //   datatype).
2402                          //   Because of an error in Pegasus we were earlier outputting
2403                          //   upper case "EMBEDDEDOBJECT" as the attribute name. The
2404                          //   spec calls for mixed case "EmbeddedObject. Fixed in
2405                          //   bug 7131 to output EmbeddedObject  attribute in upper
2406                          //   case and mixed case. Receiver will ignore one or the
2407                          //   other.
2408                          //else
2409                          //      output the real type
2410 dave.sudlik    1.117     if (type == CIMTYPE_OBJECT)
2411                          {
2412 karl           1.154 
2413 mike           1.126         out << STRLIT(" PARAMTYPE=\"string\"");
2414 karl           1.154         out << STRLIT(" EmbeddedObject=\"object\"");
2415 mike           1.126         out << STRLIT(" EMBEDDEDOBJECT=\"object\"");
2416 dave.sudlik    1.117     }
2417 a.dunfey       1.137 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
2418                          else if (type == CIMTYPE_INSTANCE)
2419                          {
2420                              out << STRLIT(" PARAMTYPE=\"string\"");
2421 karl           1.154         out << STRLIT(" EmbeddedObject=\"instance\"");
2422 a.dunfey       1.137         out << STRLIT(" EMBEDDEDOBJECT=\"instance\"");
2423                          }
2424                      #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
2425 dave.sudlik    1.117     else
2426                          {
2427 mike           1.126         out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type);
2428 kumpf          1.146         out.append('"');
2429 dave.sudlik    1.117     }
2430 karl           1.154 }
2431                      
2432                      //------------------------------------------------------------------------------
2433                      //
2434                      // appendReturnValueElement()
2435                      //
2436                      // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
2437                      // <!ATTLIST RETURNVALUE
2438                      //     %EmbeddedObject; #IMPLIED
2439                      //     %ParamType;>
2440                      //
2441                      //------------------------------------------------------------------------------
2442                      
2443                      
2444                      void XmlWriter::appendReturnValueElement(
2445                          Buffer& out,
2446                          const CIMValue& value)
2447                      {
2448                          out << STRLIT("<RETURNVALUE");
2449                      
2450                          CIMType type = value.getType();
2451 karl           1.154 
2452                          appendParamTypeAndEmbeddedObjAttrib(out, type);
2453 kumpf          1.27  
2454 mike           1.126     out << STRLIT(">\n");
2455 karl           1.37  
2456 kumpf          1.54      // Add value.
2457                          appendValueElement(out, value);
2458 mike           1.126     out << STRLIT("</RETURNVALUE>\n");
2459 kumpf          1.27  }
2460                      
2461                      //------------------------------------------------------------------------------
2462                      //
2463 kumpf          1.29  // _appendIReturnValueElementBegin()
2464                      // _appendIReturnValueElementEnd()
2465 kumpf          1.27  //
2466                      //      <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|
2467                      //          VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*|VALUE.OBJECT*|
2468                      //          OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|
2469                      //          CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)>
2470                      //
2471                      //------------------------------------------------------------------------------
2472                      
2473 kumpf          1.29  void XmlWriter::_appendIReturnValueElementBegin(
2474 mike           1.125     Buffer& out)
2475 kumpf          1.27  {
2476 mike           1.126     out << STRLIT("<IRETURNVALUE>\n");
2477 kumpf          1.27  }
2478                      
2479 kumpf          1.29  void XmlWriter::_appendIReturnValueElementEnd(
2480 mike           1.125     Buffer& out)
2481 mike           1.23  {
2482 mike           1.126     out << STRLIT("</IRETURNVALUE>\n");
2483 mike           1.23  }
2484                      
2485                      //------------------------------------------------------------------------------
2486                      //
2487 kumpf          1.27  // appendBooleanIParameter()
2488 mike           1.23  //
2489                      //------------------------------------------------------------------------------
2490                      
2491 kumpf          1.27  void XmlWriter::appendBooleanIParameter(
2492 mike           1.125     Buffer& out,
2493 mike           1.23      const char* name,
2494 kumpf          1.27      Boolean flag)
2495 mike           1.23  {
2496 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2497 mike           1.126     out << STRLIT("<VALUE>");
2498 kumpf          1.54      append(out, flag);
2499 mike           1.126     out << STRLIT("</VALUE>\n");
2500 kumpf          1.29      _appendIParamValueElementEnd(out);
2501 mike           1.23  }
2502                      
2503                      //------------------------------------------------------------------------------
2504                      //
2505 kumpf          1.27  // appendStringIParameter()
2506 mike           1.23  //
2507                      //------------------------------------------------------------------------------
2508                      
2509 kumpf          1.27  void XmlWriter::appendStringIParameter(
2510 mike           1.125     Buffer& out,
2511 mike           1.23      const char* name,
2512 kumpf          1.27      const String& str)
2513 mike           1.23  {
2514 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2515 mike           1.126     out << STRLIT("<VALUE>");
2516 kumpf          1.27      appendSpecial(out, str);
2517 mike           1.126     out << STRLIT("</VALUE>\n");
2518 kumpf          1.29      _appendIParamValueElementEnd(out);
2519 mike           1.23  }
2520                      
2521                      //------------------------------------------------------------------------------
2522                      //
2523 kumpf          1.27  // appendClassNameIParameter()
2524 mike           1.23  //
2525                      //------------------------------------------------------------------------------
2526                      
2527 kumpf          1.27  void XmlWriter::appendClassNameIParameter(
2528 mike           1.125     Buffer& out,
2529 kumpf          1.27      const char* name,
2530 kumpf          1.80      const CIMName& className)
2531 mike           1.23  {
2532 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2533 kumpf          1.83  
2534                          //
2535 david.dillard  1.121     //  A NULL (unassigned) value for a parameter is specified by an
2536 kumpf          1.83      //  <IPARAMVALUE> element with no subelement
2537                          //
2538                          if (!className.isNull ())
2539                          {
2540                              appendClassNameElement(out, className);
2541                          }
2542                      
2543 kumpf          1.29      _appendIParamValueElementEnd(out);
2544 mike           1.23  }
2545                      
2546                      //------------------------------------------------------------------------------
2547                      //
2548 kumpf          1.27  // appendInstanceNameIParameter()
2549 mike           1.23  //
2550                      //------------------------------------------------------------------------------
2551                      
2552 kumpf          1.27  void XmlWriter::appendInstanceNameIParameter(
2553 mike           1.125     Buffer& out,
2554 kumpf          1.27      const char* name,
2555 kumpf          1.59      const CIMObjectPath& instanceName)
2556 mike           1.23  {
2557 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2558                          appendInstanceNameElement(out, instanceName);
2559                          _appendIParamValueElementEnd(out);
2560 kumpf          1.27  }
2561                      
2562                      void XmlWriter::appendObjectNameIParameter(
2563 mike           1.125     Buffer& out,
2564 kumpf          1.27      const char* name,
2565 kumpf          1.59      const CIMObjectPath& objectName)
2566 kumpf          1.27  {
2567 kumpf          1.68      //
2568                          //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2569                          //  distinguish instanceNames from classNames in every case
2570 david.dillard  1.121     //  The instanceName of a singleton instance of a keyless class also
2571 kumpf          1.68      //  has no key bindings
2572                          //
2573                          if (objectName.getKeyBindings ().size () == 0)
2574 kumpf          1.27      {
2575 kumpf          1.146         XmlWriter::appendClassNameIParameter(
2576                                  out, name, objectName.getClassName());
2577 kumpf          1.27      }
2578                          else
2579                          {
2580 kumpf          1.146         XmlWriter::appendInstanceNameIParameter(
2581                                  out, name, objectName);
2582 kumpf          1.27      }
2583                      }
2584                      
2585                      //------------------------------------------------------------------------------
2586                      //
2587                      // appendClassIParameter()
2588                      //
2589                      //------------------------------------------------------------------------------
2590                      
2591                      void XmlWriter::appendClassIParameter(
2592 mike           1.125     Buffer& out,
2593 kumpf          1.27      const char* name,
2594                          const CIMConstClass& cimClass)
2595                      {
2596 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2597 kumpf          1.55      appendClassElement(out, cimClass);
2598 kumpf          1.29      _appendIParamValueElementEnd(out);
2599 mike           1.23  }
2600                      
2601                      //------------------------------------------------------------------------------
2602                      //
2603 kumpf          1.27  // appendInstanceIParameter()
2604 mike           1.23  //
2605                      //------------------------------------------------------------------------------
2606                      
2607 kumpf          1.27  void XmlWriter::appendInstanceIParameter(
2608 mike           1.125     Buffer& out,
2609 kumpf          1.27      const char* name,
2610 mike           1.23      const CIMConstInstance& instance)
2611                      {
2612 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2613 kumpf          1.55      appendInstanceElement(out, instance);
2614 kumpf          1.29      _appendIParamValueElementEnd(out);
2615 mike           1.23  }
2616                      
2617 mike           1.24  //------------------------------------------------------------------------------
2618                      //
2619 kumpf          1.27  // appendNamedInstanceIParameter()
2620 mike           1.24  //
2621                      //------------------------------------------------------------------------------
2622                      
2623 kumpf          1.27  void XmlWriter::appendNamedInstanceIParameter(
2624 mike           1.125     Buffer& out,
2625 kumpf          1.27      const char* name,
2626 kumpf          1.61      const CIMInstance& namedInstance)
2627 mike           1.24  {
2628 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2629 kumpf          1.56      appendValueNamedInstanceElement(out, namedInstance);
2630 kumpf          1.29      _appendIParamValueElementEnd(out);
2631 mike           1.24  }
2632                      
2633 mike           1.23  //----------------------------------------------------------
2634                      //
2635 kumpf          1.27  //  appendPropertyNameIParameter()
2636 david.dillard  1.121 //
2637 mike           1.23  //     </IPARAMVALUE>
2638                      //     <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE>
2639                      //
2640                      //     USE: Create parameter for getProperty operation
2641 brian.campbell 1.113 //==========================================================
2642 kumpf          1.27  void XmlWriter::appendPropertyNameIParameter(
2643 mike           1.125     Buffer& out,
2644 kumpf          1.80      const CIMName& propertyName)
2645 mike           1.23  {
2646 kumpf          1.29      _appendIParamValueElementBegin(out, "PropertyName");
2647 mike           1.126     out << STRLIT("<VALUE>") << propertyName << STRLIT("</VALUE>\n");
2648 kumpf          1.29      _appendIParamValueElementEnd(out);
2649 kumpf          1.27  }
2650 mike           1.23  
2651                      //------------------------------------------------------------------------------
2652                      //
2653 kumpf          1.27  // appendPropertyValueIParameter()
2654 mike           1.24  //
2655                      //------------------------------------------------------------------------------
2656                      
2657 kumpf          1.27  void XmlWriter::appendPropertyValueIParameter(
2658 mike           1.125     Buffer& out,
2659 kumpf          1.27      const char* name,
2660 mike           1.24      const CIMValue& value)
2661                      {
2662 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2663 kumpf          1.54      appendValueElement(out, value);
2664 kumpf          1.29      _appendIParamValueElementEnd(out);
2665 mike           1.24  }
2666                      
2667                      //------------------------------------------------------------------------------
2668                      //
2669 kumpf          1.27  // appendPropertyListIParameter()
2670 mike           1.24  //
2671                      //------------------------------------------------------------------------------
2672                      
2673 kumpf          1.27  void XmlWriter::appendPropertyListIParameter(
2674 mike           1.125     Buffer& out,
2675 mike           1.24      const CIMPropertyList& propertyList)
2676                      {
2677 kumpf          1.29      _appendIParamValueElementBegin(out, "PropertyList");
2678 mike           1.24  
2679 kumpf          1.83      //
2680 david.dillard  1.121     //  A NULL (unassigned) value for a parameter is specified by an
2681 kumpf          1.83      //  <IPARAMVALUE> element with no subelement
2682                          //
2683                          if (!propertyList.isNull ())
2684 mike           1.24      {
2685 mike           1.126         out << STRLIT("<VALUE.ARRAY>\n");
2686 kumpf          1.83          for (Uint32 i = 0; i < propertyList.size(); i++)
2687                              {
2688 mike           1.126             out << STRLIT("<VALUE>") << propertyList[i] << STRLIT("</VALUE>\n");
2689 kumpf          1.83          }
2690 mike           1.126         out << STRLIT("</VALUE.ARRAY>\n");
2691 mike           1.24      }
2692 kumpf          1.27  
2693 kumpf          1.29      _appendIParamValueElementEnd(out);
2694 mike           1.24  }
2695                      
2696                      //------------------------------------------------------------------------------
2697                      //
2698 kumpf          1.27  // appendQualifierDeclarationIParameter()
2699 mike           1.23  //
2700                      //------------------------------------------------------------------------------
2701                      
2702 kumpf          1.27  void XmlWriter::appendQualifierDeclarationIParameter(
2703 mike           1.125     Buffer& out,
2704 kumpf          1.27      const char* name,
2705 mike           1.23      const CIMConstQualifierDecl& qualifierDecl)
2706                      {
2707 kumpf          1.29      _appendIParamValueElementBegin(out, name);
2708 kumpf          1.56      appendQualifierDeclElement(out, qualifierDecl);
2709 kumpf          1.29      _appendIParamValueElementEnd(out);
2710 kumpf          1.40  }
2711                      
2712                      //------------------------------------------------------------------------------
2713                      //
2714                      // XmlWriter::formatHttpErrorRspMessage()
2715                      //
2716                      //------------------------------------------------------------------------------
2717                      
2718 mike           1.125 Buffer XmlWriter::formatHttpErrorRspMessage(
2719 kumpf          1.40      const String& status,
2720                          const String& cimError,
2721 kumpf          1.41      const String& errorDetail)
2722 kumpf          1.40  {
2723 mike           1.125     Buffer out;
2724 kumpf          1.40  
2725 kumpf          1.41      appendHttpErrorResponseHeader(out, status, cimError, errorDetail);
2726 kumpf          1.40  
2727 kumpf          1.41      return out;
2728 mike           1.23  }
2729                      
2730 chuck          1.89  // l10n - add content language support to the format methods below
2731                      
2732 mike           1.23  //------------------------------------------------------------------------------
2733                      //
2734 kumpf          1.27  // XmlWriter::formatSimpleMethodReqMessage()
2735 mike           1.23  //
2736                      //------------------------------------------------------------------------------
2737                      
2738 kumpf          1.27  // ATTN-RK-P1-20020228: Need to complete copy elimination optimization
2739 mike           1.125 Buffer XmlWriter::formatSimpleMethodReqMessage(
2740 kumpf          1.27      const char* host,
2741 kumpf          1.80      const CIMNamespaceName& nameSpace,
2742 kumpf          1.59      const CIMObjectPath& path,
2743 kumpf          1.80      const CIMName& methodName,
2744 kumpf          1.30      const Array<CIMParamValue>& parameters,
2745 kumpf          1.27      const String& messageId,
2746 kumpf          1.82      HttpMethod httpMethod,
2747 chuck          1.89      const String& authenticationHeader,
2748 kumpf          1.133     const AcceptLanguageList& httpAcceptLanguages,
2749                          const ContentLanguageList& httpContentLanguages)
2750 kumpf          1.27  {
2751 mike           1.125     Buffer out;
2752                          Buffer tmp;
2753 kumpf          1.59      CIMObjectPath localObjectPath = path;
2754 kumpf          1.80      localObjectPath.setNameSpace(nameSpace.getString());
2755 kumpf          1.77      localObjectPath.setHost(String::EMPTY);
2756 kumpf          1.27  
2757 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2758                          _appendSimpleReqElementBegin(out);
2759                          _appendMethodCallElementBegin(out, methodName);
2760 kumpf          1.38      appendLocalObjectPathElement(out, localObjectPath);
2761 kumpf          1.30      for (Uint32 i=0; i < parameters.size(); i++)
2762 kumpf          1.29      {
2763 kumpf          1.56          appendParamValueElement(out, parameters[i]);
2764 kumpf          1.29      }
2765                          _appendMethodCallElementEnd(out);
2766                          _appendSimpleReqElementEnd(out);
2767                          _appendMessageElementEnd(out);
2768 kumpf          1.27  
2769                          appendMethodCallHeader(
2770 kumpf          1.146         tmp,
2771                              host,
2772                              methodName,
2773                              localObjectPath.toString(),
2774 kumpf          1.27          authenticationHeader,
2775 kumpf          1.82          httpMethod,
2776 chuck          1.89          httpAcceptLanguages,
2777                              httpContentLanguages,
2778 kumpf          1.148         out.size());
2779 kumpf          1.27      tmp << out;
2780                      
2781                          return tmp;
2782                      }
2783                      
2784 w.white        1.108 //PEP 128 adding serverRsponseTime to header
2785 mike           1.125 Buffer XmlWriter::formatSimpleMethodRspMessage(
2786 w.white        1.108     const CIMName& methodName,
2787                          const String& messageId,
2788                          HttpMethod httpMethod,
2789 kumpf          1.133     const ContentLanguageList& httpContentLanguages,
2790 mike           1.125     const Buffer& body,
2791 kumpf          1.146     Uint64 serverResponseTime,
2792                          Boolean isFirst,
2793                          Boolean isLast)
2794                      {
2795                          Buffer out;
2796                      
2797                          if (isFirst == true)
2798                          {
2799                              // NOTE: temporarily put zero for content length. the http code
2800                              // will later decide to fill in the length or remove it altogether
2801                              appendMethodResponseHeader(
2802                                  out, httpMethod, httpContentLanguages, 0, serverResponseTime);
2803                              _appendMessageElementBegin(out, messageId);
2804                              _appendSimpleRspElementBegin(out);
2805                              _appendMethodResponseElementBegin(out, methodName);
2806                          }
2807                      
2808                          if (body.size() != 0)
2809                          {
2810                              out << body;
2811                          }
2812 kumpf          1.146 
2813                          if (isLast == true)
2814                          {
2815                              _appendMethodResponseElementEnd(out);
2816                              _appendSimpleRspElementEnd(out);
2817                              _appendMessageElementEnd(out);
2818                          }
2819 david.dillard  1.121 
2820 kumpf          1.146     return out;
2821 w.white        1.108 }
2822                      
2823                      
2824 mike           1.23  //------------------------------------------------------------------------------
2825                      //
2826 kumpf          1.28  // XmlWriter::formatSimpleMethodErrorRspMessage()
2827                      //
2828                      //------------------------------------------------------------------------------
2829                      
2830 mike           1.125 Buffer XmlWriter::formatSimpleMethodErrorRspMessage(
2831 kumpf          1.80      const CIMName& methodName,
2832 kumpf          1.28      const String& messageId,
2833 kumpf          1.82      HttpMethod httpMethod,
2834 kumpf          1.42      const CIMException& cimException)
2835 kumpf          1.28  {
2836 mike           1.125     Buffer out;
2837                          Buffer tmp;
2838 kumpf          1.28  
2839 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2840                          _appendSimpleRspElementBegin(out);
2841 kumpf          1.80      _appendMethodResponseElementBegin(out, methodName);
2842 kumpf          1.42      _appendErrorElement(out, cimException);
2843 kumpf          1.29      _appendMethodResponseElementEnd(out);
2844                          _appendSimpleRspElementEnd(out);
2845                          _appendMessageElementEnd(out);
2846 kumpf          1.28  
2847 kumpf          1.146     appendMethodResponseHeader(
2848                              tmp,
2849                              httpMethod,
2850                              cimException.getContentLanguages(),
2851 kumpf          1.148         out.size());
2852 kumpf          1.28      tmp << out;
2853                      
2854                          return tmp;
2855                      }
2856                      
2857                      //------------------------------------------------------------------------------
2858                      //
2859 kumpf          1.27  // XmlWriter::formatSimpleIMethodReqMessage()
2860 mike           1.23  //
2861                      //------------------------------------------------------------------------------
2862                      
2863 mike           1.125 Buffer XmlWriter::formatSimpleIMethodReqMessage(
2864 kumpf          1.27      const char* host,
2865 kumpf          1.80      const CIMNamespaceName& nameSpace,
2866                          const CIMName& iMethodName,
2867 kumpf          1.27      const String& messageId,
2868 kumpf          1.82      HttpMethod httpMethod,
2869 kumpf          1.27      const String& authenticationHeader,
2870 kumpf          1.133     const AcceptLanguageList& httpAcceptLanguages,
2871                          const ContentLanguageList& httpContentLanguages,
2872 mike           1.125     const Buffer& body)
2873 mike           1.23  {
2874 mike           1.125     Buffer out;
2875                          Buffer tmp;
2876 kumpf          1.27  
2877 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2878                          _appendSimpleReqElementBegin(out);
2879                          _appendIMethodCallElementBegin(out, iMethodName);
2880 kumpf          1.80      appendLocalNameSpacePathElement(out, nameSpace.getString());
2881 kumpf          1.27      out << body;
2882 kumpf          1.29      _appendIMethodCallElementEnd(out);
2883                          _appendSimpleReqElementEnd(out);
2884                          _appendMessageElementEnd(out);
2885 kumpf          1.27  
2886                          appendMethodCallHeader(
2887 kumpf          1.146         tmp,
2888                              host,
2889                              iMethodName,
2890                              nameSpace.getString(),
2891 kumpf          1.27          authenticationHeader,
2892 kumpf          1.82          httpMethod,
2893 chuck          1.89          httpAcceptLanguages,
2894                              httpContentLanguages,
2895 kumpf          1.148         out.size());
2896 kumpf          1.27      tmp << out;
2897 mike           1.23  
2898 kumpf          1.27      return tmp;
2899 mike           1.23  }
2900                      
2901                      //------------------------------------------------------------------------------
2902                      //
2903 kumpf          1.27  // XmlWriter::formatSimpleIMethodRspMessage()
2904 mike           1.23  //
2905                      //------------------------------------------------------------------------------
2906                      
2907 mike           1.125 Buffer XmlWriter::formatSimpleIMethodRspMessage(
2908 kumpf          1.80      const CIMName& iMethodName,
2909 kumpf          1.27      const String& messageId,
2910 kumpf          1.82      HttpMethod httpMethod,
2911 kumpf          1.133     const ContentLanguageList& httpContentLanguages,
2912 mike           1.125     const Buffer& body,
2913 david.dillard  1.130     Uint64 serverResponseTime,
2914 david.dillard  1.121     Boolean isFirst,
2915                          Boolean isLast)
2916 mike           1.23  {
2917 mike           1.125     Buffer out;
2918 mike           1.23  
2919 kumpf          1.146     if (isFirst == true)
2920                          {
2921                              // NOTE: temporarily put zero for content length. the http code
2922                              // will later decide to fill in the length or remove it altogether
2923                              appendMethodResponseHeader(
2924                                  out, httpMethod, httpContentLanguages, 0, serverResponseTime);
2925                              _appendMessageElementBegin(out, messageId);
2926                              _appendSimpleRspElementBegin(out);
2927                              _appendIMethodResponseElementBegin(out, iMethodName);
2928                      
2929                              // output the start of the return tag. Test if there is response data
2930                              // by:
2931                              // 1. there is data on the first chunk OR
2932                              // 2. there is no data on the first chunk but isLast is false implying
2933                              //    there is more non-empty data to come. If all subsequent chunks
2934                              //    are empty, then this generates and empty response.
2935                              if (body.size() != 0 || isLast == false)
2936                                  _appendIReturnValueElementBegin(out);
2937                          }
2938 w.white        1.108 
2939                          if (body.size() != 0)
2940                          {
2941 kumpf          1.146         out << body;
2942 w.white        1.108     }
2943                      
2944 kumpf          1.146     if (isLast == true)
2945                          {
2946                              if (body.size() != 0 || isFirst == false)
2947                                  _appendIReturnValueElementEnd(out);
2948                              _appendIMethodResponseElementEnd(out);
2949                              _appendSimpleRspElementEnd(out);
2950                              _appendMessageElementEnd(out);
2951                          }
2952 w.white        1.108 
2953                          return out;
2954                      }
2955                      
2956                      
2957 kumpf          1.28  //------------------------------------------------------------------------------
2958                      //
2959                      // XmlWriter::formatSimpleIMethodErrorRspMessage()
2960                      //
2961                      //------------------------------------------------------------------------------
2962                      
2963 mike           1.125 Buffer XmlWriter::formatSimpleIMethodErrorRspMessage(
2964 kumpf          1.80      const CIMName& iMethodName,
2965 kumpf          1.28      const String& messageId,
2966 kumpf          1.82      HttpMethod httpMethod,
2967 kumpf          1.42      const CIMException& cimException)
2968 kumpf          1.28  {
2969 mike           1.125     Buffer out;
2970                          Buffer tmp;
2971 kumpf          1.28  
2972 kumpf          1.29      _appendMessageElementBegin(out, messageId);
2973                          _appendSimpleRspElementBegin(out);
2974 kumpf          1.80      _appendIMethodResponseElementBegin(out, iMethodName);
2975 kumpf          1.42      _appendErrorElement(out, cimException);
2976 kumpf          1.29      _appendIMethodResponseElementEnd(out);
2977                          _appendSimpleRspElementEnd(out);
2978                          _appendMessageElementEnd(out);
2979 kumpf          1.28  
2980 chuck          1.89      appendMethodResponseHeader(tmp,
2981 kumpf          1.146         httpMethod,
2982                              cimException.getContentLanguages(),
2983 kumpf          1.148         out.size());
2984 kumpf          1.28      tmp << out;
2985                      
2986                          return tmp;
2987                      }
2988                      
2989 kumpf          1.27  //******************************************************************************
2990                      //
2991                      // Export Messages (used for indications)
2992                      //
2993                      //******************************************************************************
2994 mike           1.23  
2995 kumpf          1.27  //------------------------------------------------------------------------------
2996                      //
2997                      // appendEMethodRequestHeader()
2998                      //
2999                      //     Build HTTP request header for export operation.
3000                      //
3001                      //------------------------------------------------------------------------------
3002 mike           1.23  
3003 kumpf          1.27  void XmlWriter::appendEMethodRequestHeader(
3004 mike           1.125     Buffer& out,
3005 kumpf          1.50      const char* requestUri,
3006 kumpf          1.27      const char* host,
3007 kumpf          1.80      const CIMName& cimMethod,
3008 kumpf          1.82      HttpMethod httpMethod,
3009 kumpf          1.27      const String& authenticationHeader,
3010 kumpf          1.133     const AcceptLanguageList& acceptLanguages,
3011                          const ContentLanguageList& contentLanguages,
3012 kumpf          1.27      Uint32 contentLength)
3013                      {
3014                          char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
3015 mike           1.23  
3016 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
3017                          {
3018 mike           1.126       out << STRLIT("M-POST ") << requestUri << STRLIT(" HTTP/1.1\r\n");
3019 kumpf          1.82      }
3020                          else
3021                          {
3022 mike           1.126       out << STRLIT("POST ") << requestUri << STRLIT(" HTTP/1.1\r\n");
3023 kumpf          1.82      }
3024 mike           1.126     out << STRLIT("HOST: ") << host << STRLIT("\r\n");
3025                          out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");
3026                          OUTPUT_CONTENTLENGTH;
3027 brian.campbell 1.107 
3028 chuck          1.89      if (acceptLanguages.size() > 0)
3029                          {
3030 kumpf          1.146         out << STRLIT("Accept-Language: ") << acceptLanguages << STRLIT("\r\n");
3031 chuck          1.89      }
3032                          if (contentLanguages.size() > 0)
3033                          {
3034 kumpf          1.146         out << STRLIT("Content-Language: ") << contentLanguages <<
3035                                  STRLIT("\r\n");
3036 david.dillard  1.121     }
3037 brian.campbell 1.107 
3038 brian.campbell 1.113 #ifdef PEGASUS_DEBUG
3039 kumpf          1.146     // backdoor environment variable to turn OFF client requesting transfer
3040                          // encoding. The default is on. to turn off, set this variable to zero.
3041                          // This should be removed when stable. This should only be turned off in
3042                          // a debugging/testing environment.
3043                      
3044                          static const char *clientTransferEncodingOff =
3045                              getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST");
3046                          if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0')
3047 a.dunfey       1.110 #endif
3048 kumpf          1.146     out << STRLIT("TE: chunked, trailers\r\n");
3049 brian.campbell 1.107 
3050 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
3051                          {
3052 kumpf          1.146         out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");
3053 mike           1.126         out << nn << STRLIT("\r\n");
3054                              out << nn << STRLIT("-CIMExport: MethodRequest\r\n");
3055 kumpf          1.146         out << nn << STRLIT("-CIMExportMethod: ") << cimMethod <<
3056                                  STRLIT("\r\n");
3057 kumpf          1.82      }
3058                          else
3059                          {
3060 mike           1.126         out << STRLIT("CIMExport: MethodRequest\r\n");
3061                              out << STRLIT("CIMExportMethod: ") << cimMethod << STRLIT("\r\n");
3062 kumpf          1.82      }
3063                      
3064 kumpf          1.27      if (authenticationHeader.size())
3065                          {
3066 mike           1.126         out << authenticationHeader << STRLIT("\r\n");
3067 kumpf          1.27      }
3068 brian.campbell 1.107 
3069 mike           1.126     out << STRLIT("\r\n");
3070 kumpf          1.27  }
3071 mike           1.23  
3072 kumpf          1.27  //------------------------------------------------------------------------------
3073                      //
3074                      // appendEMethodResponseHeader()
3075                      //
3076                      //     Build HTTP response header for export operation.
3077                      //
3078                      //------------------------------------------------------------------------------
3079 mike           1.23  
3080 kumpf          1.27  void XmlWriter::appendEMethodResponseHeader(
3081 mike           1.125     Buffer& out,
3082 kumpf          1.82      HttpMethod httpMethod,
3083 kumpf          1.133     const ContentLanguageList& contentLanguages,
3084 kumpf          1.27      Uint32 contentLength)
3085                      {
3086                          char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
3087 mike           1.23  
3088 mike           1.126     out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n");
3089                          out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n");
3090                          OUTPUT_CONTENTLENGTH;
3091 brian.campbell 1.107 
3092 chuck          1.89      if (contentLanguages.size() > 0)
3093                          {
3094 kumpf          1.146         out << STRLIT("Content-Language: ") << contentLanguages <<
3095                                  STRLIT("\r\n");
3096 david.dillard  1.121     }
3097 kumpf          1.82      if (httpMethod == HTTP_METHOD_M_POST)
3098                          {
3099 mike           1.126         out << STRLIT("Ext:\r\n");
3100                              out << STRLIT("Cache-Control: no-cache\r\n");
3101                              out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=");
3102                              out << nn << STRLIT("\r\n");
3103                              out << nn << STRLIT("-CIMExport: MethodResponse\r\n\r\n");
3104 kumpf          1.82      }
3105                          else
3106                          {
3107 mike           1.126         out << STRLIT("CIMExport: MethodResponse\r\n\r\n");
3108 kumpf          1.82      }
3109 mike           1.23  }
3110                      
3111                      //------------------------------------------------------------------------------
3112                      //
3113 kumpf          1.29  // _appendSimpleExportReqElementBegin()
3114                      // _appendSimpleExportReqElementEnd()
3115 kumpf          1.27  //
3116                      //     <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)>
3117 mike           1.23  //
3118                      //------------------------------------------------------------------------------
3119                      
3120 kumpf          1.29  void XmlWriter::_appendSimpleExportReqElementBegin(
3121 mike           1.125     Buffer& out)
3122 mike           1.23  {
3123 mike           1.126     out << STRLIT("<SIMPLEEXPREQ>\n");
3124 kumpf          1.27  }
3125 mike           1.23  
3126 kumpf          1.29  void XmlWriter::_appendSimpleExportReqElementEnd(
3127 mike           1.125     Buffer& out)
3128 kumpf          1.27  {
3129 mike           1.126     out << STRLIT("</SIMPLEEXPREQ>\n");
3130 mike           1.23  }
3131                      
3132                      //------------------------------------------------------------------------------
3133                      //
3134 kumpf          1.29  // _appendEMethodCallElementBegin()
3135                      // _appendEMethodCallElementEnd()
3136 kumpf          1.27  //
3137                      //     <!ELEMENT EXPMETHODCALL (IPARAMVALUE*)>
3138                      //     <!ATTLIST EXPMETHODCALL %CIMName;>
3139 mike           1.23  //
3140                      //------------------------------------------------------------------------------
3141                      
3142 kumpf          1.29  void XmlWriter::_appendEMethodCallElementBegin(
3143 mike           1.125     Buffer& out,
3144 kumpf          1.80      const CIMName& name)
3145 mike           1.23  {
3146 mike           1.126     out << STRLIT("<EXPMETHODCALL NAME=\"") << name << STRLIT("\">\n");
3147 mike           1.24  }
3148                      
3149 kumpf          1.29  void XmlWriter::_appendEMethodCallElementEnd(
3150 mike           1.125     Buffer& out)
3151 mike           1.24  {
3152 mike           1.126     out << STRLIT("</EXPMETHODCALL>\n");
3153 mike           1.24  }
3154                      
3155                      //------------------------------------------------------------------------------
3156                      //
3157 kumpf          1.85  // _appendEParamValueElementBegin()
3158                      // _appendEParamValueElementEnd()
3159                      //
3160 david.dillard  1.121 //     <!ELEMENT EXPPARAMVALUE (INSTANCE)>
3161                      //     <!ATTLIST EXPPARAMVALUE
3162 kumpf          1.85  //         %CIMName;>
3163                      //
3164                      //------------------------------------------------------------------------------
3165                      
3166                      void XmlWriter::_appendEParamValueElementBegin(
3167 mike           1.125     Buffer& out,
3168 kumpf          1.85      const char* name)
3169                      {
3170 mike           1.126     out << STRLIT("<EXPPARAMVALUE NAME=\"") << name << STRLIT("\">\n");
3171 kumpf          1.85  }
3172                      
3173                      void XmlWriter::_appendEParamValueElementEnd(
3174 mike           1.125     Buffer& out)
3175 kumpf          1.85  {
3176 mike           1.126     out << STRLIT("</EXPPARAMVALUE>\n");
3177 kumpf          1.85  }
3178                      
3179                      //------------------------------------------------------------------------------
3180                      //
3181                      // appendInstanceEParameter()
3182                      //
3183                      //------------------------------------------------------------------------------
3184                      
3185                      void XmlWriter::appendInstanceEParameter(
3186 mike           1.125     Buffer& out,
3187 kumpf          1.85      const char* name,
3188                          const CIMInstance& instance)
3189                      {
3190                          _appendEParamValueElementBegin(out, name);
3191                          appendInstanceElement(out, instance);
3192                          _appendEParamValueElementEnd(out);
3193                      }
3194                      
3195                      //------------------------------------------------------------------------------
3196                      //
3197 kumpf          1.29  // _appendSimpleExportRspElementBegin()
3198                      // _appendSimpleExportRspElementEnd()
3199 mike           1.24  //
3200 kumpf          1.27  //     <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)>
3201 mike           1.24  //
3202                      //------------------------------------------------------------------------------
3203                      
3204 kumpf          1.29  void XmlWriter::_appendSimpleExportRspElementBegin(
3205 mike           1.125     Buffer& out)
3206 kumpf          1.27  {
3207 mike           1.126     out << STRLIT("<SIMPLEEXPRSP>\n");
3208 kumpf          1.27  }
3209                      
3210 kumpf          1.29  void XmlWriter::_appendSimpleExportRspElementEnd(
3211 mike           1.125     Buffer& out)
3212 mike           1.24  {
3213 mike           1.126     out << STRLIT("</SIMPLEEXPRSP>\n");
3214 mike           1.24  }
3215                      
3216                      //------------------------------------------------------------------------------
3217                      //
3218 kumpf          1.29  // _appendEMethodResponseElementBegin()
3219                      // _appendEMethodResponseElementEnd()
3220 mike           1.24  //
3221                      //     <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)>
3222                      //     <!ATTLIST EXPMETHODRESPONSE %CIMName;>
3223                      //
3224                      //------------------------------------------------------------------------------
3225                      
3226 kumpf          1.29  void XmlWriter::_appendEMethodResponseElementBegin(
3227 mike           1.125     Buffer& out,
3228 kumpf          1.80      const CIMName& name)
3229 mike           1.24  {
3230 mike           1.126     out << STRLIT("<EXPMETHODRESPONSE NAME=\"") << name << STRLIT("\">\n");
3231 kumpf          1.27  }
3232                      
3233 kumpf          1.29  void XmlWriter::_appendEMethodResponseElementEnd(
3234 mike           1.125     Buffer& out)
3235 kumpf          1.27  {
3236 mike           1.126     out << STRLIT("</EXPMETHODRESPONSE>\n");
3237 mike           1.24  }
3238                      
3239                      //------------------------------------------------------------------------------
3240                      //
3241 kumpf          1.27  // XmlWriter::formatSimpleEMethodReqMessage()
3242 mike           1.24  //
3243                      //------------------------------------------------------------------------------
3244                      
3245 mike           1.125 Buffer XmlWriter::formatSimpleEMethodReqMessage(
3246 kumpf          1.50      const char* requestUri,
3247 kumpf          1.27      const char* host,
3248 kumpf          1.80      const CIMName& eMethodName,
3249 kumpf          1.27      const String& messageId,
3250 kumpf          1.82      HttpMethod httpMethod,
3251 kumpf          1.27      const String& authenticationHeader,
3252 kumpf          1.133     const AcceptLanguageList& httpAcceptLanguages,
3253                          const ContentLanguageList& httpContentLanguages,
3254 mike           1.125     const Buffer& body)
3255 mike           1.24  {
3256 mike           1.125     Buffer out;
3257                          Buffer tmp;
3258 kumpf          1.27  
3259 kumpf          1.29      _appendMessageElementBegin(out, messageId);
3260                          _appendSimpleExportReqElementBegin(out);
3261                          _appendEMethodCallElementBegin(out, eMethodName);
3262 kumpf          1.27      out << body;
3263 kumpf          1.29      _appendEMethodCallElementEnd(out);
3264                          _appendSimpleExportReqElementEnd(out);
3265                          _appendMessageElementEnd(out);
3266 kumpf          1.27  
3267                          appendEMethodRequestHeader(
3268                              tmp,
3269 kumpf          1.50          requestUri,
3270 kumpf          1.27          host,
3271                              eMethodName,
3272 kumpf          1.82          httpMethod,
3273 kumpf          1.27          authenticationHeader,
3274 chuck          1.89          httpAcceptLanguages,
3275                              httpContentLanguages,
3276 kumpf          1.148         out.size());
3277 kumpf          1.27      tmp << out;
3278 mike           1.24  
3279 kumpf          1.50      return tmp;
3280 mike           1.24  }
3281                      
3282                      //------------------------------------------------------------------------------
3283                      //
3284 kumpf          1.27  // XmlWriter::formatSimpleEMethodRspMessage()
3285 mike           1.24  //
3286                      //------------------------------------------------------------------------------
3287                      
3288 mike           1.125 Buffer XmlWriter::formatSimpleEMethodRspMessage(
3289 kumpf          1.80      const CIMName& eMethodName,
3290 mike           1.24      const String& messageId,
3291 kumpf          1.82      HttpMethod httpMethod,
3292 kumpf          1.133     const ContentLanguageList& httpContentLanguages,
3293 mike           1.125     const Buffer& body)
3294 mike           1.24  {
3295 mike           1.125     Buffer out;
3296                          Buffer tmp;
3297 kumpf          1.27  
3298 kumpf          1.29      _appendMessageElementBegin(out, messageId);
3299                          _appendSimpleExportRspElementBegin(out);
3300                          _appendEMethodResponseElementBegin(out, eMethodName);
3301 kumpf          1.27      out << body;
3302 kumpf          1.29      _appendEMethodResponseElementEnd(out);
3303                          _appendSimpleExportRspElementEnd(out);
3304                          _appendMessageElementEnd(out);
3305 kumpf          1.28  
3306 david.dillard  1.121     appendEMethodResponseHeader(tmp,
3307 kumpf          1.146         httpMethod,
3308                              httpContentLanguages,
3309 kumpf          1.148         out.size());
3310 kumpf          1.28      tmp << out;
3311                      
3312                          return tmp;
3313                      }
3314                      
3315                      //------------------------------------------------------------------------------
3316                      //
3317                      // XmlWriter::formatSimpleEMethodErrorRspMessage()
3318                      //
3319                      //------------------------------------------------------------------------------
3320                      
3321 mike           1.125 Buffer XmlWriter::formatSimpleEMethodErrorRspMessage(
3322 kumpf          1.80      const CIMName& eMethodName,
3323 kumpf          1.28      const String& messageId,
3324 kumpf          1.82      HttpMethod httpMethod,
3325 kumpf          1.42      const CIMException& cimException)
3326 kumpf          1.28  {
3327 mike           1.125     Buffer out;
3328                          Buffer tmp;
3329 kumpf          1.28  
3330 kumpf          1.29      _appendMessageElementBegin(out, messageId);
3331                          _appendSimpleExportRspElementBegin(out);
3332 kumpf          1.80      _appendEMethodResponseElementBegin(out, eMethodName);
3333 kumpf          1.42      _appendErrorElement(out, cimException);
3334 kumpf          1.29      _appendEMethodResponseElementEnd(out);
3335                          _appendSimpleExportRspElementEnd(out);
3336                          _appendMessageElementEnd(out);
3337 kumpf          1.27  
3338 kumpf          1.146     appendEMethodResponseHeader(
3339                              tmp,
3340                              httpMethod,
3341                              cimException.getContentLanguages(),
3342 kumpf          1.148         out.size());
3343 kumpf          1.27      tmp << out;
3344                      
3345                          return tmp;
3346 mike           1.24  }
3347                      
3348                      //------------------------------------------------------------------------------
3349                      //
3350 s.hills        1.99  // _xmlWritter_printAttributes()
3351 mike           1.24  //
3352                      //------------------------------------------------------------------------------
3353                      
3354 s.hills        1.99  void _xmlWritter_printAttributes(
3355 kumpf          1.27      PEGASUS_STD(ostream)& os,
3356                          const XmlAttribute* attributes,
3357                          Uint32 attributeCount)
3358 mike           1.24  {
3359 kumpf          1.27      for (Uint32 i = 0; i < attributeCount; i++)
3360                          {
3361 kumpf          1.146         os << attributes[i].name << "=";
3362 kumpf          1.27  
3363 kumpf          1.146         os << '"';
3364                              _xmlWritter_appendSpecial(os, attributes[i].value);
3365                              os << '"';
3366 mike           1.24  
3367 kumpf          1.146         if (i + 1 != attributeCount)
3368                                  os << ' ';
3369 kumpf          1.27      }
3370 mike           1.24  }
3371                      
3372                      //------------------------------------------------------------------------------
3373                      //
3374 s.hills        1.99  // _xmlWritter_indent()
3375 mike           1.24  //
3376                      //------------------------------------------------------------------------------
3377                      
3378 kumpf          1.146 void _xmlWritter_indent(
3379                          PEGASUS_STD(ostream)& os,
3380                          Uint32 level,
3381                          Uint32 indentChars)
3382 mike           1.24  {
3383 kumpf          1.27      Uint32 n = level * indentChars;
3384                      
3385                          for (Uint32 i = 0; i < n; i++)
3386 kumpf          1.146         os << ' ';
3387 mike           1.24  }
3388                      
3389                      //------------------------------------------------------------------------------
3390                      //
3391 kumpf          1.27  // indentedPrint()
3392 mike           1.24  //
3393                      //------------------------------------------------------------------------------
3394                      
3395 kumpf          1.27  void XmlWriter::indentedPrint(
3396 david.dillard  1.121     PEGASUS_STD(ostream)& os,
3397                          const char* text,
3398 kumpf          1.27      Uint32 indentChars)
3399 mike           1.24  {
3400 a.arora        1.106     AutoArrayPtr<char> tmp(strcpy(new char[strlen(text) + 1], text));
3401 kumpf          1.27  
3402 a.arora        1.106     XmlParser parser(tmp.get());
3403 kumpf          1.27      XmlEntry entry;
3404                          Stack<const char*> stack;
3405 kumpf          1.26  
3406 kumpf          1.27      while (parser.next(entry))
3407 kumpf          1.26      {
3408 kumpf          1.146         switch (entry.type)
3409                              {
3410                                  case XmlEntry::XML_DECLARATION:
3411                                  {
3412                                      _xmlWritter_indent(os, stack.size(), indentChars);
3413                      
3414                                      os << "<?" << entry.text << " ";
3415                                      _xmlWritter_printAttributes(
3416                                          os, entry.attributes, entry.attributeCount);
3417                                      os << "?>";
3418                                      break;
3419                                  }
3420                      
3421                                  case XmlEntry::START_TAG:
3422                                  {
3423                                      _xmlWritter_indent(os, stack.size(), indentChars);
3424                      
3425                                      os << "<" << entry.text;
3426                      
3427                                      if (entry.attributeCount)
3428                                          os << ' ';
3429 kumpf          1.146 
3430                                      _xmlWritter_printAttributes(
3431                                          os, entry.attributes, entry.attributeCount);
3432                                      os << ">";
3433                                      stack.push(entry.text);
3434                                      break;
3435                                  }
3436                      
3437                                  case XmlEntry::EMPTY_TAG:
3438                                  {
3439                                      _xmlWritter_indent(os, stack.size(), indentChars);
3440                      
3441                                      os << "<" << entry.text << " ";
3442                                      _xmlWritter_printAttributes(
3443                                          os, entry.attributes, entry.attributeCount);
3444                                      os << "/>";
3445                                      break;
3446                                  }
3447 kumpf          1.27  
3448 kumpf          1.146             case XmlEntry::END_TAG:
3449                                  {
3450                                      if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
3451                                          stack.pop();
3452                      
3453                                      _xmlWritter_indent(os, stack.size(), indentChars);
3454                      
3455                                      os << "</" << entry.text << ">";
3456                                      break;
3457                                  }
3458                      
3459                                  case XmlEntry::COMMENT:
3460                                  {
3461                                      _xmlWritter_indent(os, stack.size(), indentChars);
3462                                      os << "<!--";
3463                                      _xmlWritter_appendSpecial(os, entry.text);
3464                                      os << "-->";
3465                                      break;
3466                                  }
3467                      
3468                                  case XmlEntry::CONTENT:
3469 kumpf          1.146             {
3470                                      _xmlWritter_indent(os, stack.size(), indentChars);
3471                                      _xmlWritter_appendSpecial(os, entry.text);
3472                                      break;
3473                                  }
3474                      
3475                                  case XmlEntry::CDATA:
3476                                  {
3477                                      _xmlWritter_indent(os, stack.size(), indentChars);
3478                                      os << "<![CDATA[" << entry.text << "]]>";
3479                                      break;
3480                                  }
3481                      
3482                                  case XmlEntry::DOCTYPE:
3483                                  {
3484                                      _xmlWritter_indent(os, stack.size(), indentChars);
3485                                      os << "<!DOCTYPE...>";
3486                                      break;
3487                                  }
3488                              }
3489                      
3490 kumpf          1.146         os << PEGASUS_STD(endl);
3491 kumpf          1.26      }
3492 mike           1.24  }
3493                      
3494                      //------------------------------------------------------------------------------
3495                      //
3496 kumpf          1.27  // XmlWriter::getNextMessageId()
3497 mike           1.24  //
3498                      //------------------------------------------------------------------------------
3499                      
3500 mike           1.139 static IDFactory _messageIDFactory(1000);
3501                      
3502 kumpf          1.27  String XmlWriter::getNextMessageId()
3503 mike           1.24  {
3504 marek          1.151     char scratchBuffer[22];
3505                          Uint32 n;
3506                          const char * startP = Uint32ToString(scratchBuffer, 
3507                                                               _messageIDFactory.getID(),
3508                                                               n);
3509                          return String(startP, n);
3510 kumpf          1.68  }
3511                      
3512                      //------------------------------------------------------------------------------
3513                      //
3514                      // XmlWriter::keyBindingTypeToString
3515                      //
3516                      //------------------------------------------------------------------------------
3517 kumpf          1.79  const char* XmlWriter::keyBindingTypeToString (CIMKeyBinding::Type type)
3518 kumpf          1.68  {
3519                          switch (type)
3520                          {
3521 kumpf          1.79          case CIMKeyBinding::BOOLEAN:
3522 kumpf          1.68              return "boolean";
3523                      
3524 kumpf          1.79          case CIMKeyBinding::STRING:
3525 kumpf          1.68              return "string";
3526                      
3527 kumpf          1.79          case CIMKeyBinding::NUMERIC:
3528 kumpf          1.68              return "numeric";
3529                      
3530 kumpf          1.79          case CIMKeyBinding::REFERENCE:
3531 kumpf          1.68          default:
3532                                  PEGASUS_ASSERT(false);
3533                          }
3534                      
3535 gs.keenan      1.124     return "unknown";
3536 mike           1.23  }
3537                      
3538                      PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2