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

   1 mike  1.23 //%/////////////////////////////////////////////////////////////////////////////
   2            //
   3 mike  1.24 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
   4            // The Open Group, Tivoli Systems
   5 mike  1.23 //
   6            // Permission is hereby granted, free of charge, to any person obtaining a copy
   7            // 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            // 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            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
  14            // 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            // 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            // 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 mike  1.23 //
  30            //%/////////////////////////////////////////////////////////////////////////////
  31            
  32            #include <cstdlib>
  33            #include <cstdio>
  34 kumpf 1.28 #include "Destroyer.h"
  35 mike  1.23 #include "CIMClass.h"
  36            #include "CIMInstance.h"
  37            #include "CIMQualifierDecl.h"
  38            #include "XmlWriter.h"
  39            #include "XmlParser.h"
  40            
  41            PEGASUS_NAMESPACE_BEGIN
  42            
  43 kumpf 1.27 Array<Sint8>& operator<<(Array<Sint8>& out, const char* x)
  44            {
  45                XmlWriter::append(out, x);
  46                return out;
  47            }
  48            
  49            Array<Sint8>& operator<<(Array<Sint8>& out, char x)
  50            {
  51                XmlWriter::append(out, x);
  52                return out;
  53            }
  54            
  55            Array<Sint8>& operator<<(Array<Sint8>& out, Char16 x)
  56            {
  57                XmlWriter::append(out, x);
  58                return out;
  59            }
  60            
  61            Array<Sint8>& operator<<(Array<Sint8>& out, const String& x)
  62            {
  63                XmlWriter::append(out, x);
  64 kumpf 1.27     return out;
  65            }
  66            
  67            Array<Sint8>& operator<<(Array<Sint8>& out, const Indentor& x)
  68            {
  69                XmlWriter::append(out, x);
  70                return out;
  71            }
  72            
  73            Array<Sint8>& operator<<(Array<Sint8>& out, const Array<Sint8>& x)
  74            {
  75                out.appendArray(x);
  76                return out;
  77            }
  78            
  79            Array<Sint8>& operator<<(Array<Sint8>& out, Uint32 x)
  80            {
  81                XmlWriter::append(out, x);
  82                return out;
  83            }
  84            
  85 kumpf 1.27 inline void _appendChar(Array<Sint8>& out, Char16 c)
  86 mike  1.23 {
  87                out.append(Sint8(c));
  88            }
  89            
  90 kumpf 1.27 inline void _appendSpecialChar(Array<Sint8>& out, Char16 c)
  91 mike  1.23 {
  92                // ATTN-B: Only UTF-8 handled for now.
  93            
  94                switch (c)
  95                {
  96            	case '&':
  97            	    out.append("&amp;", 5);
  98            	    break;
  99            
 100            	case '<':
 101            	    out.append("&lt;", 4);
 102            	    break;
 103            
 104            	case '>':
 105            	    out.append("&gt;", 4);
 106            	    break;
 107            
 108            	case '"':
 109            	    out.append("&quot;", 6);
 110            	    break;
 111            
 112 mike  1.23 	case '\'':
 113            	    out.append("&apos;", 6);
 114            	    break;
 115            
 116            	default:
 117            	    out.append(Sint8(c));
 118                }
 119            }
 120            
 121 kumpf 1.27 static inline void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c)
 122            {
 123                switch (c)
 124                {
 125            	case '&':
 126            	    os << "&amp;";
 127            	    break;
 128            
 129            	case '<':
 130            	    os << "&lt;";
 131            	    break;
 132            
 133            	case '>':
 134            	    os << "&gt;";
 135            	    break;
 136            
 137            	case '"':
 138            	    os << "&quot;";
 139            	    break;
 140            
 141            	case '\'':
 142 kumpf 1.27 	    os << "&apos;";
 143            	    break;
 144            
 145            	default:
 146            	    os << c;
 147                }
 148            }
 149            
 150            static inline void _appendSpecial(PEGASUS_STD(ostream)& os, const char* str)
 151            {
 152                while (*str)
 153            	_appendSpecialChar(os, *str++);
 154            }
 155            
 156 mike  1.23 void XmlWriter::append(Array<Sint8>& out, Char16 x)
 157            {
 158 kumpf 1.27     _appendChar(out, x);
 159 mike  1.23 }
 160            
 161            void XmlWriter::append(Array<Sint8>& out, Uint32 x)
 162            {
 163                char buffer[32];
 164                sprintf(buffer, "%d", x);
 165                append(out, buffer);
 166            }
 167            
 168            void XmlWriter::append(Array<Sint8>& out, const char* str)
 169            {
 170                while (*str)
 171 kumpf 1.27 	_appendChar(out, *str++);
 172            }
 173            
 174            void XmlWriter::append(Array<Sint8>& out, const String& str)
 175            {
 176                const Char16* tmp = str.getData();
 177            
 178                while (*tmp)
 179            	_appendChar(out, *tmp++);
 180            }
 181            
 182            void XmlWriter::append(Array<Sint8>& out, const Indentor& x)
 183            {
 184                for (Uint32 i = 0; i < 4 * x.getLevel(); i++)
 185            	out.append(' ');
 186 mike  1.23 }
 187            
 188            void XmlWriter::appendSpecial(Array<Sint8>& out, Char16 x)
 189            {
 190 kumpf 1.27     _appendSpecialChar(out, x);
 191 mike  1.23 }
 192            
 193            void XmlWriter::appendSpecial(Array<Sint8>& out, char x)
 194            {
 195 kumpf 1.27     _appendSpecialChar(out, Char16(x));
 196 mike  1.23 }
 197            
 198            void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str)
 199            {
 200                while (*str)
 201 kumpf 1.27 	_appendSpecialChar(out, *str++);
 202 mike  1.23 }
 203            
 204            void XmlWriter::appendSpecial(Array<Sint8>& out, const String& str)
 205            {
 206                const Char16* tmp = str.getData();
 207            
 208                while (*tmp)
 209 kumpf 1.27 	_appendSpecialChar(out, *tmp++);
 210 mike  1.23 }
 211            
 212 kumpf 1.29 //------------------------------------------------------------------------------
 213            //
 214            // appendLocalNameSpacePathElement()
 215            //
 216            //     <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>
 217            //
 218            //------------------------------------------------------------------------------
 219            
 220            void XmlWriter::appendLocalNameSpacePathElement(
 221                Array<Sint8>& out,
 222 mike  1.23     const String& nameSpace)
 223            {
 224                out << "<LOCALNAMESPACEPATH>\n";
 225            
 226                char* tmp = nameSpace.allocateCString();
 227            
 228                for (char* p = strtok(tmp, "/"); p; p = strtok(NULL, "/"))
 229                {
 230            	out << "<NAMESPACE NAME=\"" << p << "\"/>\n";
 231                }
 232            
 233                delete [] tmp;
 234            
 235                out << "</LOCALNAMESPACEPATH>\n";
 236            }
 237            
 238            //------------------------------------------------------------------------------
 239            //
 240 kumpf 1.29 // appendNameSpacePathElement()
 241            //
 242            //     <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)>
 243            //
 244            //------------------------------------------------------------------------------
 245            
 246            void XmlWriter::appendNameSpacePathElement(
 247                Array<Sint8>& out,
 248                const String& host,
 249                const String& nameSpace)
 250            {
 251                out << "<NAMESPACEPATH>\n";
 252                out << "<HOST>" << host << "</HOST>\n";
 253                appendLocalNameSpacePathElement(out, nameSpace);
 254                out << "</NAMESPACEPATH>\n";
 255            }
 256            
 257            //------------------------------------------------------------------------------
 258            //
 259            // appendClassNameElement()
 260            //
 261 kumpf 1.29 //     <!ELEMENT CLASSNAME EMPTY>
 262            //     <!ATTLIST CLASSNAME
 263            //              %CIMName;>
 264            //
 265            //------------------------------------------------------------------------------
 266            
 267            void XmlWriter::appendClassNameElement(
 268                Array<Sint8>& out,
 269                const String& className)
 270            {
 271                out << "<CLASSNAME NAME=\"" << className << "\"/>\n";
 272            }
 273            
 274            //------------------------------------------------------------------------------
 275            //
 276            // appendInstanceNameElement()
 277            //
 278            //    <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)>
 279            //    <!ATTLIST INSTANCENAME
 280            //              %ClassName;>
 281            //
 282 kumpf 1.29 //------------------------------------------------------------------------------
 283            
 284            void XmlWriter::appendInstanceNameElement(
 285                Array<Sint8>& out,
 286                const CIMReference& instanceName)
 287            {
 288                out << "<INSTANCENAME CLASSNAME=\"" << instanceName.getClassName() << "\">\n";
 289            
 290                Array<KeyBinding> keyBindings = instanceName.getKeyBindings();
 291                for (Uint32 i = 0, n = keyBindings.size(); i < n; i++)
 292                {
 293                    out << "<KEYBINDING NAME=\"" << keyBindings[i].getName() << "\">\n";
 294            
 295                    if (keyBindings[i].getType() == KeyBinding::REFERENCE)
 296                    {
 297                        CIMReference ref = keyBindings[i].getValue();
 298                        ref.toXml(out, true);
 299                    }
 300                    else {
 301                        out << "<KEYVALUE VALUETYPE=\"";
 302                        out << KeyBinding::typeToString(keyBindings[i].getType());
 303 kumpf 1.29             out << "\">";
 304            
 305                        // fixed the special character problem - Markus
 306            
 307                        appendSpecial(out, keyBindings[i].getValue());
 308                        out << "</KEYVALUE>\n";
 309                    }
 310                    out << "</KEYBINDING>\n";
 311                }
 312                out << "</INSTANCENAME>\n";
 313            }
 314            
 315            //------------------------------------------------------------------------------
 316            //
 317            // appendClassPathElement()
 318            //
 319            //     <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)>
 320            //
 321            //------------------------------------------------------------------------------
 322            
 323            void XmlWriter::appendClassPathElement(
 324 kumpf 1.29     Array<Sint8>& out, 
 325                const CIMReference& classPath)
 326            {
 327                out << "<CLASSPATH>\n";
 328                appendNameSpacePathElement(out,
 329                                           classPath.getHost(),
 330                                           classPath.getNameSpace());
 331                appendClassNameElement(out, classPath.getClassName());
 332                out << "</CLASSPATH>\n";
 333            }
 334            
 335            //------------------------------------------------------------------------------
 336            //
 337            // appendInstancePathElement()
 338            //
 339            //     <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>
 340            //
 341            //------------------------------------------------------------------------------
 342            
 343            void XmlWriter::appendInstancePathElement(
 344                Array<Sint8>& out, 
 345 kumpf 1.29     const CIMReference& instancePath)
 346            {
 347                out << "<INSTANCEPATH>\n";
 348                appendNameSpacePathElement(out,
 349                                           instancePath.getHost(),
 350                                           instancePath.getNameSpace());
 351                appendInstanceNameElement(out, instancePath);
 352                out << "</INSTANCEPATH>\n";
 353            }
 354            
 355            //------------------------------------------------------------------------------
 356            //
 357            // appendLocalClassPathElement()
 358            //
 359            //     <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>
 360            //
 361            //------------------------------------------------------------------------------
 362            
 363            void XmlWriter::appendLocalClassPathElement(
 364                Array<Sint8>& out, 
 365                const CIMReference& classPath)
 366 kumpf 1.29 {
 367                out << "<LOCALCLASSPATH>\n";
 368                appendLocalNameSpacePathElement(out, classPath.getNameSpace());
 369                appendClassNameElement(out, classPath.getClassName());
 370                out << "</LOCALCLASSPATH>\n";
 371            }
 372            
 373            //------------------------------------------------------------------------------
 374            //
 375            // appendLocalInstancePathElement()
 376            //
 377            //     <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>
 378            //
 379            //------------------------------------------------------------------------------
 380            
 381            void XmlWriter::appendLocalInstancePathElement(
 382                Array<Sint8>& out, 
 383                const CIMReference& instancePath)
 384            {
 385                out << "<LOCALINSTANCEPATH>\n";
 386                appendLocalNameSpacePathElement(out, instancePath.getNameSpace());
 387 kumpf 1.29     appendInstanceNameElement(out, instancePath);
 388                out << "</LOCALINSTANCEPATH>\n";
 389            }
 390            
 391            //------------------------------------------------------------------------------
 392            //
 393 kumpf 1.30 // appendLocalObjectPathElement()
 394            //
 395 kumpf 1.31 //     If the reference refers to an instance, write a LOCALINSTANCEPATH;
 396            //     otherwise write a LOCALCLASSPATH.
 397 kumpf 1.30 //
 398            //------------------------------------------------------------------------------
 399            
 400            void XmlWriter::appendLocalObjectPathElement(
 401                Array<Sint8>& out, 
 402                const CIMReference& objectPath)
 403            {
 404 kumpf 1.31     if (objectPath.isInstanceName())
 405 kumpf 1.30     {
 406                    appendLocalInstancePathElement(out, objectPath);
 407                }
 408                else
 409                {
 410                    appendLocalClassPathElement(out, objectPath);
 411                }
 412            }
 413            
 414            //------------------------------------------------------------------------------
 415            //
 416 kumpf 1.27 // appendMethodCallHeader()
 417 mike  1.23 //
 418 kumpf 1.31 //     Build HTTP method call request header.
 419 mike  1.23 //
 420            //------------------------------------------------------------------------------
 421            
 422 kumpf 1.27 void XmlWriter::appendMethodCallHeader(
 423                Array<Sint8>& out,
 424 mike  1.23     const char* host,
 425                const char* cimMethod,
 426                const String& cimObject,
 427 mike  1.24     const String& authenticationHeader,
 428 kumpf 1.27     Uint32 contentLength)
 429 mike  1.23 {
 430                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
 431            
 432                out << "M-POST /cimom HTTP/1.1\r\n";
 433                out << "HOST: " << host << "\r\n";
 434                out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
 435 kumpf 1.27     out << "Content-Length: " << contentLength << "\r\n";
 436 mike  1.23     out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
 437                out << nn <<"\r\n";
 438 kumpf 1.27     out << nn << "-CIMOperation: MethodCall\r\n";
 439 mike  1.23     out << nn << "-CIMMethod: " << cimMethod << "\r\n";
 440 mike  1.24     out << nn << "-CIMObject: " << cimObject << "\r\n";
 441                if (authenticationHeader.size())
 442                {
 443                    out << authenticationHeader << "\r\n";
 444                }
 445                out << "\r\n";
 446 mike  1.23 }
 447            
 448            //------------------------------------------------------------------------------
 449            //
 450 kumpf 1.27 // appendMethodResponseHeader()
 451 mike  1.23 //
 452            //     Build HTTP response header.
 453            //
 454            //------------------------------------------------------------------------------
 455            
 456 kumpf 1.27 void XmlWriter::appendMethodResponseHeader(
 457                Array<Sint8>& out,
 458                Uint32 contentLength)
 459 mike  1.23 {
 460                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
 461            
 462                out << "HTTP/1.1 200 OK\r\n";
 463                out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
 464 kumpf 1.27     out << "Content-Length: " << contentLength << "\r\n";
 465 mike  1.23     out << "Ext:\r\n";
 466                out << "Cache-Control: no-cache\r\n";
 467                out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
 468                out << nn <<"\r\n";
 469                out << nn << "-CIMOperation: MethodResponse\r\n\r\n";
 470            }
 471            
 472            //------------------------------------------------------------------------------
 473            //
 474 kumpf 1.27 // appendUnauthorizedResponseHeader()
 475            //
 476            //     Build HTTP authentication response header for unauthorized requests.
 477            //
 478            //     Returns unauthorized message in the following format:
 479            //
 480            //        HTTP/1.1 401 Unauthorized
 481            //        WWW-Authenticate: Basic "hostname:80"
 482            //        <HTML><HEAD>
 483            //        <TITLE>401 Unauthorized</TITLE>
 484            //        </HEAD><BODY BGCOLOR="#99cc99">
 485            //        <H2>TEST401 Unauthorized</H2>
 486            //        <HR>
 487            //        </BODY></HTML>
 488            //
 489            //------------------------------------------------------------------------------
 490            
 491            void XmlWriter::appendUnauthorizedResponseHeader(
 492                Array<Sint8>& out,
 493                const String& content)
 494            {
 495 kumpf 1.27     out << "HTTP/1.1 401 Unauthorized\r\n";
 496                out << content << "\r\n";
 497                out << "\r\n";
 498            
 499            //ATTN: We may need to include the following line, so that the browsers
 500            //      can display the error message.
 501            //    out << "<HTML><HEAD>\r\n";
 502            //    out << "<TITLE>" << "401 Unauthorized" <<  "</TITLE>\r\n";
 503            //    out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";
 504            //    out << "<H2>TEST" << "401 Unauthorized" << "</H2>\r\n";
 505            //    out << "<HR>\r\n";
 506            //    out << "</BODY></HTML>\r\n";
 507            }
 508            
 509            //------------------------------------------------------------------------------
 510            //
 511 kumpf 1.29 // _appendMessageElementBegin()
 512            // _appendMessageElementEnd()
 513 mike  1.23 //
 514            //     <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP)>
 515            //     <!ATTLIST MESSAGE
 516            //         ID CDATA #REQUIRED
 517            //         PROTOCOLVERSION CDATA #REQUIRED>
 518            //
 519            //------------------------------------------------------------------------------
 520            
 521 kumpf 1.29 void XmlWriter::_appendMessageElementBegin(
 522 kumpf 1.27     Array<Sint8>& out,
 523                const String& messageId)
 524 mike  1.23 {
 525                out << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
 526                out << "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">\n";
 527                out << "<MESSAGE ID=\"" << messageId << "\" PROTOCOLVERSION=\"1.0\">\n";
 528 kumpf 1.27 }
 529            
 530 kumpf 1.29 void XmlWriter::_appendMessageElementEnd(
 531 kumpf 1.27     Array<Sint8>& out)
 532            {
 533 mike  1.23     out << "</MESSAGE>\n";
 534                out << "</CIM>\n";
 535            }
 536            
 537            //------------------------------------------------------------------------------
 538            //
 539 kumpf 1.29 // _appendSimpleReqElementBegin()
 540            // _appendSimpleReqElementEnd()
 541 mike  1.23 //
 542            //     <!ELEMENT SIMPLEREQ (IMETHODCALL|METHODCALL)>
 543            //
 544            //------------------------------------------------------------------------------
 545            
 546 kumpf 1.29 void XmlWriter::_appendSimpleReqElementBegin(
 547 kumpf 1.27     Array<Sint8>& out)
 548            {
 549                out << "<SIMPLEREQ>\n";
 550            }
 551            
 552 kumpf 1.29 void XmlWriter::_appendSimpleReqElementEnd(
 553 kumpf 1.27     Array<Sint8>& out)
 554 mike  1.23 {
 555 kumpf 1.27     out << "</SIMPLEREQ>\n";
 556 mike  1.23 }
 557            
 558            //------------------------------------------------------------------------------
 559            //
 560 kumpf 1.29 // _appendMethodCallElementBegin()
 561            // _appendMethodCallElementEnd()
 562 mike  1.23 //
 563 kumpf 1.27 //     <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)>
 564            //     <!ATTLIST METHODCALL %CIMName;>
 565 mike  1.23 //
 566            //------------------------------------------------------------------------------
 567            
 568 kumpf 1.29 void XmlWriter::_appendMethodCallElementBegin(
 569 kumpf 1.27     Array<Sint8>& out,
 570                const char* name)
 571            {
 572                out << "<METHODCALL NAME=\"" << name << "\">\n";
 573            }
 574            
 575 kumpf 1.29 void XmlWriter::_appendMethodCallElementEnd(
 576 kumpf 1.27     Array<Sint8>& out)
 577 mike  1.23 {
 578 kumpf 1.27     out << "</METHODCALL>\n";
 579 mike  1.23 }
 580            
 581            //------------------------------------------------------------------------------
 582            //
 583 kumpf 1.29 // _appendIMethodCallElementBegin()
 584            // _appendIMethodCallElementEnd()
 585 mike  1.23 //
 586            //     <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)>
 587            //     <!ATTLIST IMETHODCALL %CIMName;>
 588            //
 589            //------------------------------------------------------------------------------
 590            
 591 kumpf 1.29 void XmlWriter::_appendIMethodCallElementBegin(
 592 kumpf 1.27     Array<Sint8>& out,
 593                const char* name)
 594 mike  1.23 {
 595                out << "<IMETHODCALL NAME=\"" << name << "\">\n";
 596 kumpf 1.27 }
 597            
 598 kumpf 1.29 void XmlWriter::_appendIMethodCallElementEnd(
 599 kumpf 1.27     Array<Sint8>& out)
 600            {
 601 mike  1.23     out << "</IMETHODCALL>\n";
 602            }
 603            
 604            //------------------------------------------------------------------------------
 605            //
 606 kumpf 1.29 // _appendIParamValueElementBegin()
 607            // _appendIParamValueElementEnd()
 608 mike  1.23 //
 609 kumpf 1.27 //     <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
 610            //         |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
 611            //         |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
 612            //     <!ATTLIST IPARAMVALUE %CIMName;>
 613 mike  1.23 //
 614            //------------------------------------------------------------------------------
 615            
 616 kumpf 1.29 void XmlWriter::_appendIParamValueElementBegin(
 617 kumpf 1.27     Array<Sint8>& out,
 618                const char* name)
 619            {
 620                out << "<IPARAMVALUE NAME=\"" << name << "\">\n";
 621            }
 622            
 623 kumpf 1.29 void XmlWriter::_appendIParamValueElementEnd(
 624 kumpf 1.27     Array<Sint8>& out)
 625 mike  1.23 {
 626 kumpf 1.27     out << "</IPARAMVALUE>\n";
 627 mike  1.23 }
 628            
 629            //------------------------------------------------------------------------------
 630            //
 631 kumpf 1.29 // _appendSimpleRspElementBegin()
 632            // _appendSimpleRspElementEnd()
 633 mike  1.23 //
 634 kumpf 1.27 //     <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)>
 635 mike  1.23 //
 636            //------------------------------------------------------------------------------
 637            
 638 kumpf 1.29 void XmlWriter::_appendSimpleRspElementBegin(
 639 kumpf 1.27     Array<Sint8>& out)
 640            {
 641                out << "<SIMPLERSP>\n";
 642            }
 643            
 644 kumpf 1.29 void XmlWriter::_appendSimpleRspElementEnd(
 645 kumpf 1.27     Array<Sint8>& out)
 646 mike  1.23 {
 647 kumpf 1.27     out << "</SIMPLERSP>\n";
 648 mike  1.23 }
 649            
 650            //------------------------------------------------------------------------------
 651            //
 652 kumpf 1.29 // _appendMethodResponseElementBegin()
 653            // _appendMethodResponseElementEnd()
 654 mike  1.23 //
 655 kumpf 1.27 //     <!ELEMENT METHODRESPONSE (ERROR|IRETURNVALUE?)>
 656            //     <!ATTLIST METHODRESPONSE %CIMName;>
 657 mike  1.23 //
 658            //------------------------------------------------------------------------------
 659            
 660 kumpf 1.29 void XmlWriter::_appendMethodResponseElementBegin(
 661 mike  1.23     Array<Sint8>& out,
 662 kumpf 1.27     const char* name)
 663            {
 664                out << "<METHODRESPONSE NAME=\"" << name << "\">\n";
 665            }
 666            
 667 kumpf 1.29 void XmlWriter::_appendMethodResponseElementEnd(
 668 kumpf 1.27     Array<Sint8>& out)
 669 mike  1.23 {
 670 kumpf 1.27     out << "</METHODRESPONSE>\n";
 671            }
 672            
 673            //------------------------------------------------------------------------------
 674            //
 675 kumpf 1.29 // _appendIMethodResponseElementBegin()
 676            // _appendIMethodResponseElementEnd()
 677 kumpf 1.27 //
 678            //     <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)>
 679            //     <!ATTLIST IMETHODRESPONSE %CIMName;>
 680            //
 681            //------------------------------------------------------------------------------
 682            
 683 kumpf 1.29 void XmlWriter::_appendIMethodResponseElementBegin(
 684 kumpf 1.27     Array<Sint8>& out,
 685                const char* name)
 686            {
 687                out << "<IMETHODRESPONSE NAME=\"" << name << "\">\n";
 688            }
 689            
 690 kumpf 1.29 void XmlWriter::_appendIMethodResponseElementEnd(
 691 kumpf 1.27     Array<Sint8>& out)
 692            {
 693                out << "</IMETHODRESPONSE>\n";
 694 mike  1.23 }
 695            
 696            //------------------------------------------------------------------------------
 697            //
 698 kumpf 1.29 // _appendErrorElement()
 699 mike  1.23 //
 700            //------------------------------------------------------------------------------
 701            
 702 kumpf 1.29 void XmlWriter::_appendErrorElement(
 703 kumpf 1.27     Array<Sint8>& out,
 704 mike  1.23     CIMStatusCode code,
 705                const char* description)
 706            {
 707                out << "<ERROR";
 708                out << " CODE=\"" << Uint32(code) << "\"";
 709                out << " DESCRIPTION=\"";
 710                appendSpecial(out, description);
 711                out << "\"/>";
 712            }
 713            
 714            //------------------------------------------------------------------------------
 715            //
 716 kumpf 1.27 // appendReturnValueElement()
 717            //
 718            // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
 719            // <!ATTLIST RETURNVALUE
 720            //     %ParamType;>
 721 mike  1.23 //
 722            //------------------------------------------------------------------------------
 723            
 724 kumpf 1.27 void XmlWriter::appendReturnValueElement(
 725 mike  1.23     Array<Sint8>& out,
 726 kumpf 1.27     const CIMValue& value)
 727            {
 728                out << "<RETURNVALUE";
 729            
 730                CIMType type = value.getType();
 731                if (type != CIMType::NONE)
 732                {
 733                    out << " PARAMTYPE=\"" << TypeToString(type) << "\"";
 734                }
 735            
 736                out << ">\n";
 737                value.toXml(out);
 738                out << "</RETURNVALUE>\n";
 739            }
 740            
 741            //------------------------------------------------------------------------------
 742            //
 743 kumpf 1.29 // _appendIReturnValueElementBegin()
 744            // _appendIReturnValueElementEnd()
 745 kumpf 1.27 //
 746            //      <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|
 747            //          VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*|VALUE.OBJECT*|
 748            //          OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|
 749            //          CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)>
 750            //
 751            //------------------------------------------------------------------------------
 752            
 753 kumpf 1.29 void XmlWriter::_appendIReturnValueElementBegin(
 754 kumpf 1.27     Array<Sint8>& out)
 755            {
 756                out << "<IRETURNVALUE>\n";
 757            }
 758            
 759 kumpf 1.29 void XmlWriter::_appendIReturnValueElementEnd(
 760 kumpf 1.27     Array<Sint8>& out)
 761 mike  1.23 {
 762 kumpf 1.27     out << "</IRETURNVALUE>\n";
 763 mike  1.23 }
 764            
 765            //------------------------------------------------------------------------------
 766            //
 767 kumpf 1.27 // appendBooleanIParameter()
 768 mike  1.23 //
 769            //------------------------------------------------------------------------------
 770            
 771 kumpf 1.27 void XmlWriter::appendBooleanIParameter(
 772 mike  1.23     Array<Sint8>& out,
 773                const char* name,
 774 kumpf 1.27     Boolean flag)
 775 mike  1.23 {
 776 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 777 kumpf 1.27     out << "<VALUE>" << (flag ? "TRUE" : "FALSE") << "</VALUE>\n";
 778 kumpf 1.29     _appendIParamValueElementEnd(out);
 779 mike  1.23 }
 780            
 781            //------------------------------------------------------------------------------
 782            //
 783 kumpf 1.27 // appendStringIParameter()
 784 mike  1.23 //
 785            //------------------------------------------------------------------------------
 786            
 787 kumpf 1.27 void XmlWriter::appendStringIParameter(
 788 mike  1.23     Array<Sint8>& out,
 789                const char* name,
 790 kumpf 1.27     const String& str)
 791 mike  1.23 {
 792 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 793 kumpf 1.27     out << "<VALUE>";
 794                appendSpecial(out, str);
 795                out << "</VALUE>\n";
 796 kumpf 1.29     _appendIParamValueElementEnd(out);
 797 mike  1.23 }
 798            
 799            //------------------------------------------------------------------------------
 800            //
 801 kumpf 1.27 // appendQualifierNameIParameter()
 802 mike  1.23 //
 803            //------------------------------------------------------------------------------
 804            
 805 kumpf 1.27 void XmlWriter::appendQualifierNameIParameter(
 806 mike  1.23     Array<Sint8>& out,
 807                const char* name,
 808                const String& qualifierName)
 809            {
 810                // <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
 811                //     |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
 812                //     |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
 813                //
 814                // ATTN: notice that there is really no way to pass a qualifier name
 815                // as an IPARAMVALUE element according to the spec (look above). So we
 816                // just pass it as a class name. An answer must be obtained later.
 817                
 818 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 819 kumpf 1.27     appendClassNameElement(out, qualifierName);
 820 kumpf 1.29     _appendIParamValueElementEnd(out);
 821 mike  1.23 }
 822            
 823            //------------------------------------------------------------------------------
 824            //
 825 kumpf 1.27 // appendClassNameIParameter()
 826 mike  1.23 //
 827            //------------------------------------------------------------------------------
 828            
 829 kumpf 1.27 void XmlWriter::appendClassNameIParameter(
 830 mike  1.23     Array<Sint8>& out,
 831 kumpf 1.27     const char* name,
 832                const String& className)
 833 mike  1.23 {
 834 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 835 kumpf 1.27     appendClassNameElement(out, className);
 836 kumpf 1.29     _appendIParamValueElementEnd(out);
 837 mike  1.23 }
 838            
 839            //------------------------------------------------------------------------------
 840            //
 841 kumpf 1.27 // appendInstanceNameIParameter()
 842 mike  1.23 //
 843            //------------------------------------------------------------------------------
 844            
 845 kumpf 1.27 void XmlWriter::appendInstanceNameIParameter(
 846 mike  1.23     Array<Sint8>& out,
 847 kumpf 1.27     const char* name,
 848 mike  1.23     const CIMReference& instanceName)
 849            {
 850 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 851                appendInstanceNameElement(out, instanceName);
 852                _appendIParamValueElementEnd(out);
 853 kumpf 1.27 }
 854            
 855            void XmlWriter::appendObjectNameIParameter(
 856                Array<Sint8>& out,
 857                const char* name,
 858                const CIMReference& objectName)
 859            {
 860                if (objectName.isClassName())
 861                {
 862            	XmlWriter::appendClassNameIParameter(
 863            	    out, name, objectName.getClassName());
 864                }
 865                else
 866                {
 867            	XmlWriter::appendInstanceNameIParameter(
 868            	    out, name, objectName);
 869                }
 870            }
 871            
 872            //------------------------------------------------------------------------------
 873            //
 874 kumpf 1.27 // appendClassIParameter()
 875            //
 876            //------------------------------------------------------------------------------
 877            
 878            void XmlWriter::appendClassIParameter(
 879                Array<Sint8>& out,
 880                const char* name,
 881                const CIMConstClass& cimClass)
 882            {
 883 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 884 kumpf 1.27     cimClass.toXml(out);
 885 kumpf 1.29     _appendIParamValueElementEnd(out);
 886 mike  1.23 }
 887            
 888            //------------------------------------------------------------------------------
 889            //
 890 kumpf 1.27 // appendInstanceIParameter()
 891 mike  1.23 //
 892            //------------------------------------------------------------------------------
 893            
 894 kumpf 1.27 void XmlWriter::appendInstanceIParameter(
 895 mike  1.23     Array<Sint8>& out,
 896 kumpf 1.27     const char* name,
 897 mike  1.23     const CIMConstInstance& instance)
 898            {
 899 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 900 kumpf 1.27     instance.toXml(out);
 901 kumpf 1.29     _appendIParamValueElementEnd(out);
 902 mike  1.23 }
 903            
 904 mike  1.24 //------------------------------------------------------------------------------
 905            //
 906 kumpf 1.27 // appendNamedInstanceIParameter()
 907 mike  1.24 //
 908            //------------------------------------------------------------------------------
 909            
 910 kumpf 1.27 void XmlWriter::appendNamedInstanceIParameter(
 911 mike  1.24     Array<Sint8>& out,
 912 kumpf 1.27     const char* name,
 913 mike  1.24     const CIMNamedInstance& namedInstance)
 914            {
 915 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 916 kumpf 1.27     namedInstance.toXml(out);
 917 kumpf 1.29     _appendIParamValueElementEnd(out);
 918 mike  1.24 }
 919            
 920 mike  1.23 //----------------------------------------------------------
 921            //
 922 kumpf 1.27 //  appendPropertyNameIParameter()
 923 mike  1.23 //   	
 924            //     </IPARAMVALUE>
 925            //     <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE>
 926            //
 927            //     USE: Create parameter for getProperty operation
 928            //==========================================================
 929 kumpf 1.27 void XmlWriter::appendPropertyNameIParameter(
 930 mike  1.23     Array<Sint8>& out,
 931                const String& propertyName)
 932            {
 933 kumpf 1.29     _appendIParamValueElementBegin(out, "PropertyName");
 934 kumpf 1.27     out << "<VALUE>" << propertyName << "</VALUE>\n"; 
 935 kumpf 1.29     _appendIParamValueElementEnd(out);
 936 kumpf 1.27 }
 937 mike  1.23 
 938            //------------------------------------------------------------------------------
 939            //
 940 kumpf 1.27 // appendPropertyValueIParameter()
 941 mike  1.24 //
 942            //------------------------------------------------------------------------------
 943            
 944 kumpf 1.27 void XmlWriter::appendPropertyValueIParameter(
 945 mike  1.24     Array<Sint8>& out,
 946 kumpf 1.27     const char* name,
 947 mike  1.24     const CIMValue& value)
 948            {
 949 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 950 kumpf 1.27     value.toXml(out);
 951 kumpf 1.29     _appendIParamValueElementEnd(out);
 952 mike  1.24 }
 953            
 954            //------------------------------------------------------------------------------
 955            //
 956 kumpf 1.27 // appendPropertyListIParameter()
 957 mike  1.24 //
 958            //------------------------------------------------------------------------------
 959            
 960 kumpf 1.27 void XmlWriter::appendPropertyListIParameter(
 961 mike  1.24     Array<Sint8>& out,
 962                const CIMPropertyList& propertyList)
 963            {
 964 kumpf 1.29     _appendIParamValueElementBegin(out, "PropertyList");
 965 mike  1.24 
 966 kumpf 1.27     out << "<VALUE.ARRAY>\n";
 967 mike  1.24     for (Uint32 i = 0; i < propertyList.getNumProperties(); i++)
 968                {
 969 kumpf 1.27         out << "<VALUE>" << propertyList.getPropertyName(i) << "</VALUE>\n"; 
 970 mike  1.24     }
 971 kumpf 1.27     out << "</VALUE.ARRAY>\n";
 972            
 973 kumpf 1.29     _appendIParamValueElementEnd(out);
 974 mike  1.24 }
 975            
 976            //------------------------------------------------------------------------------
 977            //
 978 kumpf 1.27 // appendQualifierDeclarationIParameter()
 979 mike  1.23 //
 980            //------------------------------------------------------------------------------
 981            
 982 kumpf 1.27 void XmlWriter::appendQualifierDeclarationIParameter(
 983 mike  1.23     Array<Sint8>& out,
 984 kumpf 1.27     const char* name,
 985 mike  1.23     const CIMConstQualifierDecl& qualifierDecl)
 986            {
 987 kumpf 1.29     _appendIParamValueElementBegin(out, name);
 988 kumpf 1.27     qualifierDecl.toXml(out);
 989 kumpf 1.29     _appendIParamValueElementEnd(out);
 990 mike  1.23 }
 991            
 992            //------------------------------------------------------------------------------
 993            //
 994 kumpf 1.27 // XmlWriter::formatSimpleMethodReqMessage()
 995 mike  1.23 //
 996            //------------------------------------------------------------------------------
 997            
 998 kumpf 1.27 // ATTN-RK-P1-20020228: Need to complete copy elimination optimization
 999            Array<Sint8> XmlWriter::formatSimpleMethodReqMessage(
1000                const char* host,
1001 kumpf 1.29     const CIMReference& path,
1002 kumpf 1.27     const char* methodName,
1003 kumpf 1.30     const Array<CIMParamValue>& parameters,
1004 kumpf 1.27     const String& messageId,
1005 kumpf 1.30     const String& authenticationHeader)
1006 kumpf 1.27 {
1007                Array<Sint8> out;
1008                Array<Sint8> tmp;
1009            
1010 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1011                _appendSimpleReqElementBegin(out);
1012                _appendMethodCallElementBegin(out, methodName);
1013 kumpf 1.30     appendLocalObjectPathElement(out, path);
1014                for (Uint32 i=0; i < parameters.size(); i++)
1015 kumpf 1.29     {
1016 kumpf 1.30         parameters[i].toXml(out);
1017 kumpf 1.29     }
1018                _appendMethodCallElementEnd(out);
1019                _appendSimpleReqElementEnd(out);
1020                _appendMessageElementEnd(out);
1021 kumpf 1.27 
1022                appendMethodCallHeader(
1023            	tmp,
1024            	host,
1025            	methodName,
1026 kumpf 1.31 	path.toString(false),
1027 kumpf 1.27         authenticationHeader,
1028            	out.size());
1029                tmp << out;
1030            
1031                return tmp;
1032            }
1033            
1034            Array<Sint8> XmlWriter::formatSimpleMethodRspMessage(
1035                const char* methodName,
1036                const String& messageId,
1037                const Array<Sint8>& body)
1038 mike  1.23 {
1039 kumpf 1.27     Array<Sint8> out;
1040                Array<Sint8> tmp;
1041            
1042 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1043                _appendSimpleRspElementBegin(out);
1044                _appendMethodResponseElementBegin(out, methodName);
1045 kumpf 1.27     out << body;
1046 kumpf 1.29     _appendMethodResponseElementEnd(out);
1047                _appendSimpleRspElementEnd(out);
1048                _appendMessageElementEnd(out);
1049 mike  1.23 
1050 kumpf 1.27     appendMethodResponseHeader(tmp, out.size());
1051                tmp << out;
1052 mike  1.23 
1053 kumpf 1.27     return tmp;
1054 mike  1.23 }
1055            
1056            //------------------------------------------------------------------------------
1057            //
1058 kumpf 1.28 // XmlWriter::formatSimpleMethodErrorRspMessage()
1059            //
1060            //------------------------------------------------------------------------------
1061            
1062            Array<Sint8> XmlWriter::formatSimpleMethodErrorRspMessage(
1063                const String& methodName,
1064                const String& messageId,
1065                CIMStatusCode code,
1066                const String& description)
1067            {
1068                ArrayDestroyer<char> tmp1(methodName.allocateCString());
1069                ArrayDestroyer<char> tmp2(description.allocateCString());
1070                Array<Sint8> out;
1071                Array<Sint8> tmp;
1072            
1073 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1074                _appendSimpleRspElementBegin(out);
1075                _appendMethodResponseElementBegin(out, tmp1.getPointer());
1076                _appendErrorElement(out, code, tmp2.getPointer());
1077                _appendMethodResponseElementEnd(out);
1078                _appendSimpleRspElementEnd(out);
1079                _appendMessageElementEnd(out);
1080 kumpf 1.28 
1081                appendMethodResponseHeader(tmp, out.size());
1082                tmp << out;
1083            
1084                return tmp;
1085            }
1086            
1087            //------------------------------------------------------------------------------
1088            //
1089 kumpf 1.27 // XmlWriter::formatSimpleIMethodReqMessage()
1090 mike  1.23 //
1091            //------------------------------------------------------------------------------
1092            
1093 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleIMethodReqMessage(
1094                const char* host,
1095                const String& nameSpace,
1096                const char* iMethodName,
1097                const String& messageId,
1098                const String& authenticationHeader,
1099                const Array<Sint8>& body)
1100 mike  1.23 {
1101 kumpf 1.27     Array<Sint8> out;
1102                Array<Sint8> tmp;
1103            
1104 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1105                _appendSimpleReqElementBegin(out);
1106                _appendIMethodCallElementBegin(out, iMethodName);
1107                appendLocalNameSpacePathElement(out, nameSpace);
1108 kumpf 1.27     out << body;
1109 kumpf 1.29     _appendIMethodCallElementEnd(out);
1110                _appendSimpleReqElementEnd(out);
1111                _appendMessageElementEnd(out);
1112 kumpf 1.27 
1113                appendMethodCallHeader(
1114            	tmp,
1115            	host,
1116            	iMethodName,
1117            	nameSpace,
1118                    authenticationHeader,
1119            	out.size());
1120                tmp << out;
1121 mike  1.23 
1122 kumpf 1.27     return tmp;
1123 mike  1.23 }
1124            
1125            //------------------------------------------------------------------------------
1126            //
1127 kumpf 1.27 // XmlWriter::formatSimpleIMethodRspMessage()
1128 mike  1.23 //
1129            //------------------------------------------------------------------------------
1130            
1131 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleIMethodRspMessage(
1132                const char* iMethodName,
1133                const String& messageId,
1134                const Array<Sint8>& body)
1135 mike  1.23 {
1136 kumpf 1.27     Array<Sint8> out;
1137                Array<Sint8> tmp;
1138 mike  1.23 
1139 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1140                _appendSimpleRspElementBegin(out);
1141                _appendIMethodResponseElementBegin(out, iMethodName);
1142                _appendIReturnValueElementBegin(out);
1143 kumpf 1.27     out << body;
1144 kumpf 1.29     _appendIReturnValueElementEnd(out);
1145                _appendIMethodResponseElementEnd(out);
1146                _appendSimpleRspElementEnd(out);
1147                _appendMessageElementEnd(out);
1148 mike  1.23 
1149 kumpf 1.27     appendMethodResponseHeader(tmp, out.size());
1150                tmp << out;
1151 mike  1.23 
1152 kumpf 1.27     return tmp;
1153            }
1154 mike  1.23 
1155 kumpf 1.28 //------------------------------------------------------------------------------
1156            //
1157            // XmlWriter::formatSimpleIMethodErrorRspMessage()
1158            //
1159            //------------------------------------------------------------------------------
1160            
1161            Array<Sint8> XmlWriter::formatSimpleIMethodErrorRspMessage(
1162                const String& iMethodName,
1163                const String& messageId,
1164                CIMStatusCode code,
1165                const String& description)
1166            {
1167                ArrayDestroyer<char> tmp1(iMethodName.allocateCString());
1168                ArrayDestroyer<char> tmp2(description.allocateCString());
1169                Array<Sint8> out;
1170                Array<Sint8> tmp;
1171            
1172 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1173                _appendSimpleRspElementBegin(out);
1174                _appendIMethodResponseElementBegin(out, tmp1.getPointer());
1175                _appendErrorElement(out, code, tmp2.getPointer());
1176                _appendIMethodResponseElementEnd(out);
1177                _appendSimpleRspElementEnd(out);
1178                _appendMessageElementEnd(out);
1179 kumpf 1.28 
1180                appendMethodResponseHeader(tmp, out.size());
1181                tmp << out;
1182            
1183                return tmp;
1184            }
1185            
1186 kumpf 1.27 //******************************************************************************
1187            //
1188            // Export Messages (used for indications)
1189            //
1190            //******************************************************************************
1191 mike  1.23 
1192 kumpf 1.27 //------------------------------------------------------------------------------
1193            //
1194            // appendEMethodRequestHeader()
1195            //
1196            //     Build HTTP request header for export operation.
1197            //
1198            //------------------------------------------------------------------------------
1199 mike  1.23 
1200 kumpf 1.27 void XmlWriter::appendEMethodRequestHeader(
1201                Array<Sint8>& out,
1202                const char* host,
1203                const char* cimMethod,
1204                const String& authenticationHeader,
1205                Uint32 contentLength)
1206            {
1207                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
1208 mike  1.23 
1209 kumpf 1.27     out << "M-POST /cimom HTTP/1.1\r\n";
1210                out << "HOST: " << host << "\r\n";
1211                out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
1212                out << "Content-Length: " << contentLength << "\r\n";
1213                out << "Man: http://www.hp.com; ns=";
1214                out << nn <<"\r\n";
1215 kumpf 1.32     out << nn << "-CIMExport: MethodRequest\r\n";
1216 kumpf 1.27     out << nn << "-CIMExportMethod: " << cimMethod << "\r\n";
1217                if (authenticationHeader.size())
1218                {
1219                    out << authenticationHeader << "\r\n";
1220                }
1221                out << "\r\n";
1222            }
1223 mike  1.23 
1224 kumpf 1.27 //------------------------------------------------------------------------------
1225            //
1226            // appendEMethodResponseHeader()
1227            //
1228            //     Build HTTP response header for export operation.
1229            //
1230            //------------------------------------------------------------------------------
1231 mike  1.23 
1232 kumpf 1.27 void XmlWriter::appendEMethodResponseHeader(
1233                Array<Sint8>& out,
1234                Uint32 contentLength)
1235            {
1236                char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
1237 mike  1.23 
1238 kumpf 1.27     out << "HTTP/1.1 200 OK\r\n";
1239                out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
1240                out << "Content-Length: " << contentLength << "\r\n";
1241                out << "Ext:\r\n";
1242                out << "Cache-Control: no-cache\r\n";
1243                out << "Man:  http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
1244                out << nn <<"\r\n";
1245                out << nn << "-CIMExport: MethodResponse\r\n\r\n";
1246 mike  1.23 }
1247            
1248            //------------------------------------------------------------------------------
1249            //
1250 kumpf 1.29 // _appendSimpleExportReqElementBegin()
1251            // _appendSimpleExportReqElementEnd()
1252 kumpf 1.27 //
1253            //     <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)>
1254 mike  1.23 //
1255            //------------------------------------------------------------------------------
1256            
1257 kumpf 1.29 void XmlWriter::_appendSimpleExportReqElementBegin(
1258 kumpf 1.27     Array<Sint8>& out)
1259 mike  1.23 {
1260 kumpf 1.27     out << "<SIMPLEEXPREQ>\n";
1261            }
1262 mike  1.23 
1263 kumpf 1.29 void XmlWriter::_appendSimpleExportReqElementEnd(
1264 kumpf 1.27     Array<Sint8>& out)
1265            {
1266                out << "</SIMPLEEXPREQ>\n";
1267 mike  1.23 }
1268            
1269            //------------------------------------------------------------------------------
1270            //
1271 kumpf 1.29 // _appendEMethodCallElementBegin()
1272            // _appendEMethodCallElementEnd()
1273 kumpf 1.27 //
1274            //     <!ELEMENT EXPMETHODCALL (IPARAMVALUE*)>
1275            //     <!ATTLIST EXPMETHODCALL %CIMName;>
1276 mike  1.23 //
1277            //------------------------------------------------------------------------------
1278            
1279 kumpf 1.29 void XmlWriter::_appendEMethodCallElementBegin(
1280 mike  1.23     Array<Sint8>& out,
1281 kumpf 1.27     const char* name)
1282 mike  1.23 {
1283 kumpf 1.27     out << "<EXPMETHODCALL NAME=\"" << name << "\">\n";
1284 mike  1.24 }
1285            
1286 kumpf 1.29 void XmlWriter::_appendEMethodCallElementEnd(
1287 kumpf 1.27     Array<Sint8>& out)
1288 mike  1.24 {
1289                out << "</EXPMETHODCALL>\n";
1290            }
1291            
1292            //------------------------------------------------------------------------------
1293            //
1294 kumpf 1.29 // _appendSimpleExportRspElementBegin()
1295            // _appendSimpleExportRspElementEnd()
1296 mike  1.24 //
1297 kumpf 1.27 //     <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)>
1298 mike  1.24 //
1299            //------------------------------------------------------------------------------
1300            
1301 kumpf 1.29 void XmlWriter::_appendSimpleExportRspElementBegin(
1302 kumpf 1.27     Array<Sint8>& out)
1303            {
1304                out << "<SIMPLEEXPRSP>\n";
1305            }
1306            
1307 kumpf 1.29 void XmlWriter::_appendSimpleExportRspElementEnd(
1308 kumpf 1.27     Array<Sint8>& out)
1309 mike  1.24 {
1310 kumpf 1.27     out << "</SIMPLEEXPRSP>\n";
1311 mike  1.24 }
1312            
1313            //------------------------------------------------------------------------------
1314            //
1315 kumpf 1.29 // _appendEMethodResponseElementBegin()
1316            // _appendEMethodResponseElementEnd()
1317 mike  1.24 //
1318            //     <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)>
1319            //     <!ATTLIST EXPMETHODRESPONSE %CIMName;>
1320            //
1321            //------------------------------------------------------------------------------
1322            
1323 kumpf 1.29 void XmlWriter::_appendEMethodResponseElementBegin(
1324 kumpf 1.27     Array<Sint8>& out,
1325                const char* name)
1326 mike  1.24 {
1327                out << "<EXPMETHODRESPONSE NAME=\"" << name << "\">\n";
1328 kumpf 1.27 }
1329            
1330 kumpf 1.29 void XmlWriter::_appendEMethodResponseElementEnd(
1331 kumpf 1.27     Array<Sint8>& out)
1332            {
1333 mike  1.24     out << "</EXPMETHODRESPONSE>\n";
1334            }
1335            
1336            //------------------------------------------------------------------------------
1337            //
1338 kumpf 1.27 // XmlWriter::formatSimpleEMethodReqMessage()
1339 mike  1.24 //
1340            //------------------------------------------------------------------------------
1341            
1342 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleEMethodReqMessage(
1343                const char* host,
1344                const char* eMethodName,
1345                const String& messageId,
1346                const String& authenticationHeader,
1347                const Array<Sint8>& body)
1348 mike  1.24 {
1349                Array<Sint8> out;
1350 kumpf 1.27     Array<Sint8> tmp;
1351            
1352 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1353                _appendSimpleExportReqElementBegin(out);
1354                _appendEMethodCallElementBegin(out, eMethodName);
1355 kumpf 1.27     out << body;
1356 kumpf 1.29     _appendEMethodCallElementEnd(out);
1357                _appendSimpleExportReqElementEnd(out);
1358                _appendMessageElementEnd(out);
1359 kumpf 1.27 
1360                appendEMethodRequestHeader(
1361                    tmp,
1362                    host,
1363                    eMethodName,
1364                    authenticationHeader,
1365            	out.size());
1366                tmp << out;
1367 mike  1.24 
1368                return out;
1369            }
1370            
1371            //------------------------------------------------------------------------------
1372            //
1373 kumpf 1.27 // XmlWriter::formatSimpleEMethodRspMessage()
1374 mike  1.24 //
1375            //------------------------------------------------------------------------------
1376            
1377 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleEMethodRspMessage(
1378                const char* eMethodName,
1379 mike  1.24     const String& messageId,
1380                const Array<Sint8>& body)
1381            {
1382 kumpf 1.27     Array<Sint8> out;
1383                Array<Sint8> tmp;
1384            
1385 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1386                _appendSimpleExportRspElementBegin(out);
1387                _appendEMethodResponseElementBegin(out, eMethodName);
1388 kumpf 1.27     out << body;
1389 kumpf 1.29     _appendEMethodResponseElementEnd(out);
1390                _appendSimpleExportRspElementEnd(out);
1391                _appendMessageElementEnd(out);
1392 kumpf 1.28 
1393                appendEMethodResponseHeader(tmp, out.size());
1394                tmp << out;
1395            
1396                return tmp;
1397            }
1398            
1399            //------------------------------------------------------------------------------
1400            //
1401            // XmlWriter::formatSimpleEMethodErrorRspMessage()
1402            //
1403            //------------------------------------------------------------------------------
1404            
1405            Array<Sint8> XmlWriter::formatSimpleEMethodErrorRspMessage(
1406                const String& eMethodName,
1407                const String& messageId,
1408                CIMStatusCode code,
1409                const String& description)
1410            {
1411                ArrayDestroyer<char> tmp1(eMethodName.allocateCString());
1412                ArrayDestroyer<char> tmp2(description.allocateCString());
1413 kumpf 1.28     Array<Sint8> out;
1414                Array<Sint8> tmp;
1415            
1416 kumpf 1.29     _appendMessageElementBegin(out, messageId);
1417                _appendSimpleExportRspElementBegin(out);
1418                _appendEMethodResponseElementBegin(out, tmp1.getPointer());
1419                _appendErrorElement(out, code, tmp2.getPointer());
1420                _appendEMethodResponseElementEnd(out);
1421                _appendSimpleExportRspElementEnd(out);
1422                _appendMessageElementEnd(out);
1423 kumpf 1.27 
1424                appendEMethodResponseHeader(tmp, out.size());
1425                tmp << out;
1426            
1427                return tmp;
1428 mike  1.24 }
1429            
1430            //------------------------------------------------------------------------------
1431            //
1432 kumpf 1.27 // _printAttributes()
1433 mike  1.24 //
1434            //------------------------------------------------------------------------------
1435            
1436 kumpf 1.27 static void _printAttributes(
1437                PEGASUS_STD(ostream)& os,
1438                const XmlAttribute* attributes,
1439                Uint32 attributeCount)
1440 mike  1.24 {
1441 kumpf 1.27     for (Uint32 i = 0; i < attributeCount; i++)
1442                {
1443            	os << attributes[i].name << "=";
1444            
1445            	os << '"';
1446            	_appendSpecial(os, attributes[i].value);
1447            	os << '"';
1448 mike  1.24 
1449 kumpf 1.27 	if (i + 1 != attributeCount)
1450            	    os << ' ';
1451                }
1452 mike  1.24 }
1453            
1454            //------------------------------------------------------------------------------
1455            //
1456 kumpf 1.27 // _indent()
1457 mike  1.24 //
1458            //------------------------------------------------------------------------------
1459            
1460 kumpf 1.27 static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars)
1461 mike  1.24 {
1462 kumpf 1.27     Uint32 n = level * indentChars;
1463            
1464                for (Uint32 i = 0; i < n; i++)
1465            	os << ' ';
1466 mike  1.24 }
1467            
1468            //------------------------------------------------------------------------------
1469            //
1470 kumpf 1.27 // indentedPrint()
1471 mike  1.24 //
1472            //------------------------------------------------------------------------------
1473            
1474 kumpf 1.27 void XmlWriter::indentedPrint(
1475                PEGASUS_STD(ostream)& os, 
1476                const char* text, 
1477                Uint32 indentChars)
1478 mike  1.24 {
1479 kumpf 1.27     char* tmp = strcpy(new char[strlen(text) + 1], text);
1480            
1481                XmlParser parser(tmp);
1482                XmlEntry entry;
1483                Stack<const char*> stack;
1484 kumpf 1.26 
1485 kumpf 1.27     while (parser.next(entry))
1486 kumpf 1.26     {
1487 kumpf 1.27 	switch (entry.type)
1488            	{
1489            	    case XmlEntry::XML_DECLARATION:
1490            	    {
1491            		_indent(os, stack.size(), indentChars);
1492            
1493            		os << "<?" << entry.text << " ";
1494            		_printAttributes(os, entry.attributes, entry.attributeCount);
1495            		os << "?>";
1496            		break;
1497            	    }
1498            
1499            	    case XmlEntry::START_TAG:
1500            	    {
1501            		_indent(os, stack.size(), indentChars);
1502            
1503            		os << "<" << entry.text;
1504            
1505            		if (entry.attributeCount)
1506            		    os << ' ';
1507            
1508 kumpf 1.27 		_printAttributes(os, entry.attributes, entry.attributeCount);
1509            		os << ">";
1510            		stack.push(entry.text);
1511            		break;
1512            	    }
1513            
1514            	    case XmlEntry::EMPTY_TAG:
1515            	    {
1516            		_indent(os, stack.size(), indentChars);
1517            
1518            		os << "<" << entry.text << " ";
1519            		_printAttributes(os, entry.attributes, entry.attributeCount);
1520            		os << "/>";
1521            		break;
1522            	    }
1523            
1524            	    case XmlEntry::END_TAG:
1525            	    {
1526            		if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
1527            		    stack.pop();
1528            
1529 kumpf 1.27 		_indent(os, stack.size(), indentChars);
1530            
1531            		os << "</" << entry.text << ">";
1532            		break;
1533            	    }
1534            
1535            	    case XmlEntry::COMMENT:
1536            	    {
1537            
1538            		_indent(os, stack.size(), indentChars);
1539            		os << "<!--";
1540            		_appendSpecial(os, entry.text);
1541            		os << "-->";
1542            		break;
1543            	    }
1544            
1545            	    case XmlEntry::CONTENT:
1546            	    {
1547            		_indent(os, stack.size(), indentChars);
1548            		_appendSpecial(os, entry.text);
1549            		break;
1550 kumpf 1.27 	    }
1551            
1552            	    case XmlEntry::CDATA:
1553            	    {
1554            		_indent(os, stack.size(), indentChars);
1555            		os << "<![CDATA[...]]>";
1556            		break;
1557            	    }
1558            
1559            	    case XmlEntry::DOCTYPE:
1560            	    {
1561            		_indent(os, stack.size(), indentChars);
1562            		os << "<!DOCTYPE...>";
1563            		break;
1564            	    }
1565            	}
1566            
1567            	os << PEGASUS_STD(endl);
1568 kumpf 1.26     }
1569            
1570 kumpf 1.27     delete [] tmp;
1571 mike  1.24 }
1572            
1573            //------------------------------------------------------------------------------
1574            //
1575 kumpf 1.27 // XmlWriter::getNextMessageId()
1576 mike  1.24 //
1577            //------------------------------------------------------------------------------
1578            
1579 kumpf 1.27 String XmlWriter::getNextMessageId()
1580 mike  1.24 {
1581 kumpf 1.27     // ATTN: make thread-safe:
1582                static Uint32 messageId = 1000;
1583 mike  1.24 
1584 kumpf 1.27     messageId++;
1585 mike  1.24 
1586 kumpf 1.27     if (messageId < 1000)
1587            	messageId = 1001;
1588 mike  1.23 
1589 kumpf 1.27     char buffer[16];
1590                sprintf(buffer, "%d", messageId);
1591                return buffer;
1592 mike  1.23 }
1593            
1594            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2