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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2