1 //%2006////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //==============================================================================
32 // Author: Mike Brasher (mbrasher@bmc.com)
35 // Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
36 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
37 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
38 // Carol Ann Krug Graves, Hewlett-Packard Company
39 // (carolann_graves@hp.com)
40 // Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase1
41 // Willis White (whiwill@us.ibm.com) PEP 127 and 128
42 // Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase2
43 // David Dillard, Symantec Corp. (david_dillard@symantec.com)
44 // Vijay Eli, vijayeli@in.ibm.com, fix for #2571
46 //%/////////////////////////////////////////////////////////////////////////////
48 #ifndef Pegasus_XmlWriter_h
49 #define Pegasus_XmlWriter_h
52 #include <Pegasus/Common/Config.h>
53 #include <Pegasus/Common/InternalException.h>
54 #include <Pegasus/Common/ArrayInternal.h>
55 #include <Pegasus/Common/String.h>
56 #include <Pegasus/Common/Indentor.h>
57 #include <Pegasus/Common/CIMObject.h>
58 #include <Pegasus/Common/CIMClass.h>
59 #include <Pegasus/Common/CIMInstance.h>
60 #include <Pegasus/Common/CIMProperty.h>
61 #include <Pegasus/Common/CIMMethod.h>
62 #include <Pegasus/Common/CIMParameter.h>
63 #include <Pegasus/Common/CIMQualifier.h>
64 #include <Pegasus/Common/CIMQualifierDecl.h>
65 #include <Pegasus/Common/CIMValue.h>
66 #include <Pegasus/Common/CIMObjectPath.h>
67 #include <Pegasus/Common/CIMPropertyList.h>
68 #include <Pegasus/Common/CIMParamValue.h>
69 #include <Pegasus/Common/Message.h>
70 #include <Pegasus/Common/Linkage.h>
71 #include <Pegasus/Common/ContentLanguageList.h>
72 #include <Pegasus/Common/AcceptLanguageList.h>
73 #include <Pegasus/Common/Buffer.h>
74 #include <Pegasus/Common/StrLit.h>
76 PEGASUS_NAMESPACE_BEGIN
78 // l10n - added accept language and content language support below
80 class PEGASUS_COMMON_LINKAGE XmlWriter
84 static void append(Buffer& out, const Char16& x);
86 static void append(Buffer& out, char x)
91 static void append(Buffer& out, Boolean x);
93 static void append(Buffer& out, Uint32 x);
95 static void append(Buffer& out, Sint32 x);
97 static void append(Buffer& out, Uint64 x);
99 static void append(Buffer& out, Sint64 x);
101 static void append(Buffer& out, Real32 x);
103 static void append(Buffer& out, Real64 x);
105 static void append(Buffer& out, const char* str);
107 static void append(Buffer& out, const String& str);
109 static void append(Buffer& out, const Indentor& x);
111 static void appendSpecial(Buffer& out, const Char16& x);
113 static void appendSpecial(Buffer& out, char x);
115 static void appendSpecial(Buffer& out, const char* str);
117 static void appendSpecial(Buffer& out, const String& str);
119 static String encodeURICharacters(const Buffer& uriString);
120 static String encodeURICharacters(const String& uriString);
122 static void appendLocalNameSpacePathElement(
124 const CIMNamespaceName& nameSpace);
126 static void appendNameSpacePathElement(
129 const CIMNamespaceName& nameSpace);
131 static void appendClassNameElement(
133 const CIMName& className);
135 static void appendInstanceNameElement(
137 const CIMObjectPath& instanceName);
139 static void appendClassPathElement(
141 const CIMObjectPath& classPath);
143 static void appendInstancePathElement(
145 const CIMObjectPath& instancePath);
147 static void appendLocalClassPathElement(
149 const CIMObjectPath& classPath);
151 static void appendLocalInstancePathElement(
153 const CIMObjectPath& instancePath);
155 static void appendLocalObjectPathElement(
157 const CIMObjectPath& objectPath);
159 static void appendValueElement(
161 const CIMValue& value);
163 static void printValueElement(
164 const CIMValue& value,
165 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
167 static void appendValueObjectWithPathElement(
169 const CIMObject& objectWithPath);
171 static void appendValueReferenceElement(
173 const CIMObjectPath& reference,
174 Boolean putValueWrapper);
176 static void printValueReferenceElement(
177 const CIMObjectPath& reference,
178 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
180 static void appendValueNamedInstanceElement(
182 const CIMInstance& namedInstance);
184 static void appendClassElement(
186 const CIMConstClass& cimclass);
188 static void printClassElement(
189 const CIMConstClass& cimclass,
190 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
192 static void appendInstanceElement(
194 const CIMConstInstance& instance);
196 static void printInstanceElement(
197 const CIMConstInstance& instance,
198 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
200 static void appendObjectElement(
202 const CIMConstObject& object);
204 static void appendPropertyElement(
206 const CIMConstProperty& property);
208 static void printPropertyElement(
209 const CIMConstProperty& property,
210 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
212 static void appendMethodElement(
214 const CIMConstMethod& method);
216 static void printMethodElement(
217 const CIMConstMethod& method,
218 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
220 static void appendParameterElement(
222 const CIMConstParameter& parameter);
224 static void printParameterElement(
225 const CIMConstParameter& parameter,
226 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
228 static void appendParamValueElement(
230 const CIMParamValue& paramValue);
232 static void printParamValueElement(
233 const CIMParamValue& paramValue,
234 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
236 static void appendQualifierElement(
238 const CIMConstQualifier& qualifier);
240 static void printQualifierElement(
241 const CIMConstQualifier& qualifier,
242 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
244 static void appendQualifierDeclElement(
246 const CIMConstQualifierDecl& qualifierDecl);
248 static void printQualifierDeclElement(
249 const CIMConstQualifierDecl& qualifierDecl,
250 PEGASUS_STD(ostream)& os=PEGASUS_STD(cout));
252 static void appendQualifierFlavorEntity(
254 const CIMFlavor & flavor);
256 static void appendScopeElement(
258 const CIMScope & scope);
260 static void appendMethodCallHeader(
263 const CIMName& cimMethod,
264 const String& cimObject,
265 const String& authenticationHeader,
266 HttpMethod httpMethod,
267 const AcceptLanguageList& acceptLanguages,
268 const ContentLanguageList& contentLanguages,
269 Uint32 contentLength);
271 // added to accommodate sending WBEMServerResponseTime PEP #128
272 static void appendMethodResponseHeader(
274 HttpMethod httpMethod,
275 const ContentLanguageList& contentLanguages,
276 Uint32 contentLength,
277 Uint64 serverResponseTime = 0);
279 static void appendHttpErrorResponseHeader(
281 const String& status,
282 const String& cimError = String::EMPTY,
283 const String& errorDetail = String::EMPTY);
285 static void appendUnauthorizedResponseHeader(
287 const String& content);
289 #ifdef PEGASUS_KERBEROS_AUTHENTICATION
290 static void appendOKResponseHeader(
292 const String& content);
295 static void appendReturnValueElement(
297 const CIMValue& value);
299 static void appendBooleanIParameter(
304 static void appendStringIParameter(
309 static void appendClassNameIParameter(
312 const CIMName& className);
314 static void appendInstanceNameIParameter(
317 const CIMObjectPath& instanceName);
319 static void appendObjectNameIParameter(
322 const CIMObjectPath& objectName);
324 static void appendClassIParameter(
327 const CIMConstClass& cimClass);
329 static void appendInstanceIParameter(
332 const CIMConstInstance& instance);
334 static void appendNamedInstanceIParameter(
337 const CIMInstance& namedInstance) ;
339 static void appendPropertyNameIParameter(
341 const CIMName& propertyName);
343 static void appendPropertyValueIParameter(
346 const CIMValue& value);
348 static void appendPropertyListIParameter(
350 const CIMPropertyList& propertyList);
352 static void appendQualifierDeclarationIParameter(
355 const CIMConstQualifierDecl& qualifierDecl);
357 static Buffer formatHttpErrorRspMessage(
358 const String& status,
359 const String& cimError = String::EMPTY,
360 const String& errorDetail = String::EMPTY);
362 static Buffer formatSimpleMethodReqMessage(
364 const CIMNamespaceName& nameSpace,
365 const CIMObjectPath& path,
366 const CIMName& methodName,
367 const Array<CIMParamValue>& parameters,
368 const String& messageId,
369 HttpMethod httpMethod,
370 const String& authenticationHeader,
371 const AcceptLanguageList& httpAcceptLanguages,
372 const ContentLanguageList& httpContentLanguages);
374 //PEP 128 - sending serverResponseTime (WBEMServerResponseTime) in respons header
375 static Buffer formatSimpleMethodRspMessage(
376 const CIMName& methodName,
377 const String& messageId,
378 HttpMethod httpMethod,
379 const ContentLanguageList& httpContentLanguages,
381 Uint64 serverResponseTime,
382 Boolean isFirst = true,
383 Boolean isLast = true);
385 static Buffer formatSimpleMethodErrorRspMessage(
386 const CIMName& methodName,
387 const String& messageId,
388 HttpMethod httpMethod,
389 const CIMException& cimException);
391 static Buffer formatSimpleIMethodReqMessage(
393 const CIMNamespaceName& nameSpace,
394 const CIMName& iMethodName,
395 const String& messageId,
396 HttpMethod httpMethod,
397 const String& authenticationHeader,
398 const AcceptLanguageList& httpAcceptLanguages,
399 const ContentLanguageList& httpContentLanguages,
402 //PEP 128 - sending serverResponseTime (WBEMServerResponseTime) in respons header
403 static Buffer formatSimpleIMethodRspMessage(
404 const CIMName& iMethodName,
405 const String& messageId,
406 HttpMethod httpMethod,
407 const ContentLanguageList& httpContentLanguages,
409 Uint64 serverResponseTime,
410 Boolean isFirst = true,
411 Boolean isLast = true);
413 static Buffer formatSimpleIMethodErrorRspMessage(
414 const CIMName& iMethodName,
415 const String& messageId,
416 HttpMethod httpMethod,
417 const CIMException& cimException);
419 static void appendInstanceEParameter(
422 const CIMInstance& instance);
424 static void appendEMethodRequestHeader(
426 const char* requestUri,
428 const CIMName& cimMethod,
429 HttpMethod httpMethod,
430 const String& authenticationHeader,
431 const AcceptLanguageList& acceptLanguages,
432 const ContentLanguageList& contentLanguages,
433 Uint32 contentLength);
435 static void appendEMethodResponseHeader(
437 HttpMethod httpMethod,
438 const ContentLanguageList& contentLanguages,
439 Uint32 contentLength);
441 static Buffer formatSimpleEMethodReqMessage(
442 const char* requestUri,
444 const CIMName& eMethodName,
445 const String& messageId,
446 HttpMethod httpMethod,
447 const String& authenticationHeader,
448 const AcceptLanguageList& httpAcceptLanguages,
449 const ContentLanguageList& httpContentLanguages,
452 static Buffer formatSimpleEMethodRspMessage(
453 const CIMName& eMethodName,
454 const String& messageId,
455 HttpMethod httpMethod,
456 const ContentLanguageList& httpContentLanguages,
459 static Buffer formatSimpleEMethodErrorRspMessage(
460 const CIMName& eMethodName,
461 const String& messageId,
462 HttpMethod httpMethod,
463 const CIMException& cimException);
465 static void indentedPrint(
466 PEGASUS_STD(ostream)& os,
468 Uint32 indentChars = 2);
470 static String getNextMessageId();
472 /** Converts the given CIMKeyBinding type to one of the following:
473 "boolean", "string", or "numeric"
475 static const char* keyBindingTypeToString (CIMKeyBinding::Type type);
479 static void _appendMessageElementBegin(
481 const String& messageId);
482 static void _appendMessageElementEnd(
485 static void _appendSimpleReqElementBegin(Buffer& out);
486 static void _appendSimpleReqElementEnd(Buffer& out);
488 static void _appendMethodCallElementBegin(
490 const CIMName& name);
492 static void _appendMethodCallElementEnd(
495 static void _appendIMethodCallElementBegin(
497 const CIMName& name);
498 static void _appendIMethodCallElementEnd(
501 static void _appendIParamValueElementBegin(
504 static void _appendIParamValueElementEnd(
507 static void _appendSimpleRspElementBegin(Buffer& out);
508 static void _appendSimpleRspElementEnd(Buffer& out);
510 static void _appendMethodResponseElementBegin(
512 const CIMName& name);
513 static void _appendMethodResponseElementEnd(
516 static void _appendIMethodResponseElementBegin(
518 const CIMName& name);
519 static void _appendIMethodResponseElementEnd(
522 static void _appendErrorElement(
524 const CIMException& cimException);
526 static void _appendIReturnValueElementBegin(Buffer& out);
527 static void _appendIReturnValueElementEnd(Buffer& out);
529 static void _appendSimpleExportReqElementBegin(Buffer& out);
530 static void _appendSimpleExportReqElementEnd(Buffer& out);
532 static void _appendEMethodCallElementBegin(
534 const CIMName& name);
536 static void _appendEMethodCallElementEnd(
539 static void _appendEParamValueElementBegin(
542 static void _appendEParamValueElementEnd(
545 static void _appendSimpleExportRspElementBegin(Buffer& out);
546 static void _appendSimpleExportRspElementEnd(Buffer& out);
548 static void _appendEMethodResponseElementBegin(
550 const CIMName& name);
552 static void _appendEMethodResponseElementEnd(
558 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
562 inline Buffer& operator<<(Buffer& out, char x)
568 inline Buffer& operator<<(Buffer& out, const char* s)
570 out.append(s, strlen(s));
574 PEGASUS_COMMON_LINKAGE Buffer& operator<<(Buffer& out, const Char16& x);
576 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
580 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
584 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
588 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
592 PEGASUS_COMMON_LINKAGE Buffer& operator<<(
594 const CIMName& name);
596 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
597 PEGASUS_STD(ostream)& os,
598 const CIMDateTime& x);
600 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
601 PEGASUS_STD(ostream)& os,
602 const CIMName& name);
604 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
605 PEGASUS_STD(ostream)& os,
606 const CIMNamespaceName& name);
608 PEGASUS_NAMESPACE_END
610 #endif /* Pegasus_XmlWriter_h */