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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2