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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2