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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2