version 1.81, 2006/11/10 18:14:59
|
version 1.92.4.1, 2011/01/15 21:26:53
|
|
|
//%2006//////////////////////////////////////////////////////////////////////// |
//%LICENSE//////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Licensed to The Open Group (TOG) under one or more contributor license |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; |
// this work for additional information regarding copyright ownership. |
// IBM Corp.; EMC Corporation, The Open Group. |
// Each contributor licenses this file to you under the OpenPegasus Open |
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
// Source License; you may not use this file except in compliance with the |
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// License. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
|
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// Permission is hereby granted, free of charge, to any person obtaining a |
// of this software and associated documentation files (the "Software"), to |
// copy of this software and associated documentation files (the "Software"), |
// deal in the Software without restriction, including without limitation the |
// to deal in the Software without restriction, including without limitation |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// sell copies of the Software, and to permit persons to whom the Software is |
// and/or sell copies of the Software, and to permit persons to whom the |
// furnished to do so, subject to the following conditions: |
// Software is furnished to do so, subject to the following conditions: |
// | // |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// The above copyright notice and this permission notice shall be included |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// in all copies or substantial portions of the Software. |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
|
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
|
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
// | // |
//============================================================================== |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
// |
|
////////////////////////////////////////////////////////////////////////// |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#include <Pegasus/Common/InternalException.h> | #include <Pegasus/Common/InternalException.h> |
#include <Pegasus/Common/ArrayInternal.h> | #include <Pegasus/Common/ArrayInternal.h> |
#include <Pegasus/Common/String.h> | #include <Pegasus/Common/String.h> |
#include <Pegasus/Common/Indentor.h> |
|
#include <Pegasus/Common/CIMObject.h> | #include <Pegasus/Common/CIMObject.h> |
#include <Pegasus/Common/CIMClass.h> | #include <Pegasus/Common/CIMClass.h> |
#include <Pegasus/Common/CIMInstance.h> | #include <Pegasus/Common/CIMInstance.h> |
|
|
#include <Pegasus/Common/CIMObjectPath.h> | #include <Pegasus/Common/CIMObjectPath.h> |
#include <Pegasus/Common/CIMPropertyList.h> | #include <Pegasus/Common/CIMPropertyList.h> |
#include <Pegasus/Common/CIMParamValue.h> | #include <Pegasus/Common/CIMParamValue.h> |
|
#include <Pegasus/Common/CommonUTF.h> |
#include <Pegasus/Common/Message.h> | #include <Pegasus/Common/Message.h> |
#include <Pegasus/Common/Linkage.h> | #include <Pegasus/Common/Linkage.h> |
#include <Pegasus/Common/ContentLanguageList.h> | #include <Pegasus/Common/ContentLanguageList.h> |
#include <Pegasus/Common/AcceptLanguageList.h> | #include <Pegasus/Common/AcceptLanguageList.h> |
#include <Pegasus/Common/Buffer.h> | #include <Pegasus/Common/Buffer.h> |
#include <Pegasus/Common/StrLit.h> | #include <Pegasus/Common/StrLit.h> |
|
#include <Pegasus/Common/XmlGenerator.h> |
|
#include <Pegasus/Common/NumericArg.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
// l10n - added accept language and content language support below |
class PEGASUS_COMMON_LINKAGE XmlWriter : public XmlGenerator |
|
|
class PEGASUS_COMMON_LINKAGE XmlWriter |
|
{ | { |
public: | public: |
| |
static void append(Buffer& out, const Char16& x); |
|
|
|
static void append(Buffer& out, char x) |
|
{ |
|
out.append(x); |
|
} |
|
|
|
static void append(Buffer& out, Boolean x); |
|
|
|
static void append(Buffer& out, Uint32 x); |
|
|
|
static void append(Buffer& out, Sint32 x); |
|
|
|
static void append(Buffer& out, Uint64 x); |
|
|
|
static void append(Buffer& out, Sint64 x); |
|
|
|
static void append(Buffer& out, Real32 x); |
|
|
|
static void append(Buffer& out, Real64 x); |
|
|
|
static void append(Buffer& out, const char* str); |
|
|
|
static void append(Buffer& out, const String& str); |
|
|
|
static void append(Buffer& out, const Indentor& x); |
|
|
|
static void appendSpecial(Buffer& out, const Char16& x); |
|
|
|
static void appendSpecial(Buffer& out, char x); |
|
|
|
static void appendSpecial(Buffer& out, const char* str); |
|
|
|
static void appendSpecial(Buffer& out, const String& str); |
|
|
|
static String encodeURICharacters(const Buffer& uriString); |
|
static String encodeURICharacters(const String& uriString); |
|
|
|
static void appendLocalNameSpacePathElement( | static void appendLocalNameSpacePathElement( |
Buffer& out, | Buffer& out, |
const CIMNamespaceName& nameSpace); | const CIMNamespaceName& nameSpace); |
|
|
Buffer& out, | Buffer& out, |
const CIMInstance& namedInstance); | const CIMInstance& namedInstance); |
| |
|
//EXP_PULL |
|
static void appendValueInstanceWithPathElement( |
|
Buffer& out, |
|
const CIMInstance& namedInstance); |
|
//EXP_PULL_END |
static void appendClassElement( | static void appendClassElement( |
Buffer& out, | Buffer& out, |
const CIMConstClass& cimclass); | const CIMConstClass& cimclass); |
|
|
HttpMethod httpMethod, | HttpMethod httpMethod, |
const AcceptLanguageList& acceptLanguages, | const AcceptLanguageList& acceptLanguages, |
const ContentLanguageList& contentLanguages, | const ContentLanguageList& contentLanguages, |
Uint32 contentLength); |
Uint32 contentLength, |
|
bool binaryRequest = false, |
|
bool binaryResponse = false); |
| |
// added to accommodate sending WBEMServerResponseTime PEP #128 |
|
static void appendMethodResponseHeader( | static void appendMethodResponseHeader( |
Buffer& out, | Buffer& out, |
HttpMethod httpMethod, | HttpMethod httpMethod, |
const ContentLanguageList& contentLanguages, | const ContentLanguageList& contentLanguages, |
Uint32 contentLength, | Uint32 contentLength, |
Uint64 serverResponseTime = 0); |
Uint64 serverResponseTime = 0, |
|
bool binaryResponse = false); |
| |
static void appendHttpErrorResponseHeader( | static void appendHttpErrorResponseHeader( |
Buffer& out, | Buffer& out, |
|
|
const String& content); | const String& content); |
#endif | #endif |
| |
|
static void appendParamTypeAndEmbeddedObjAttrib( |
|
Buffer& out, |
|
const CIMType& type); |
|
|
static void appendReturnValueElement( | static void appendReturnValueElement( |
Buffer& out, | Buffer& out, |
const CIMValue& value); | const CIMValue& value); |
|
|
const char* name, | const char* name, |
Boolean flag); | Boolean flag); |
| |
|
static void appendBooleanParameter( |
|
Buffer& out, |
|
const char* name, |
|
Boolean flag); |
|
|
|
static void appendBooleanIReturnValue( |
|
Buffer& out, |
|
const char* name, |
|
Boolean flag); |
|
|
|
static void appendUint32IParameter( |
|
Buffer& out, |
|
const char* name, |
|
const Uint32Arg& val, |
|
const Boolean required); |
|
/* KS_PULL DELETE |
|
static void appendUint64Parameter( |
|
Buffer& out, |
|
const char* name, |
|
const Uint64 val); |
|
*/ |
|
static void appendUint64ReturnValue( |
|
Buffer& out, |
|
const char* name, |
|
const Uint64Arg& val); |
|
|
static void appendStringIParameter( | static void appendStringIParameter( |
Buffer& out, | Buffer& out, |
const char* name, | const char* name, |
const String& str); | const String& str); |
| |
|
//EXP_PULL |
|
static void appendStringIParameterIfNotEmpty( |
|
Buffer& out, |
|
const char* name, |
|
const String& str); |
|
|
|
static void appendStringParameter( |
|
Buffer& out, |
|
const char* name, |
|
const String& str); |
|
static void appendStringIReturnValue( |
|
Buffer& out, |
|
const char* name, |
|
const String& str); |
|
//EXP_PULL_END |
static void appendClassNameIParameter( | static void appendClassNameIParameter( |
Buffer& out, | Buffer& out, |
const char* name, | const char* name, |
|
|
HttpMethod httpMethod, | HttpMethod httpMethod, |
const String& authenticationHeader, | const String& authenticationHeader, |
const AcceptLanguageList& httpAcceptLanguages, | const AcceptLanguageList& httpAcceptLanguages, |
const ContentLanguageList& httpContentLanguages); |
const ContentLanguageList& httpContentLanguages, |
|
bool binaryResponse); |
| |
// PEP 128 - sending serverResponseTime (WBEMServerResponseTime) in |
|
// response header |
|
static Buffer formatSimpleMethodRspMessage( | static Buffer formatSimpleMethodRspMessage( |
const CIMName& methodName, | const CIMName& methodName, |
const String& messageId, | const String& messageId, |
HttpMethod httpMethod, | HttpMethod httpMethod, |
const ContentLanguageList& httpContentLanguages, | const ContentLanguageList& httpContentLanguages, |
|
const Buffer& bodyParams, |
const Buffer& body, | const Buffer& body, |
Uint64 serverResponseTime, | Uint64 serverResponseTime, |
Boolean isFirst = true, | Boolean isFirst = true, |
|
|
const String& authenticationHeader, | const String& authenticationHeader, |
const AcceptLanguageList& httpAcceptLanguages, | const AcceptLanguageList& httpAcceptLanguages, |
const ContentLanguageList& httpContentLanguages, | const ContentLanguageList& httpContentLanguages, |
const Buffer& body); |
const Buffer& body, |
|
bool binaryResponse); |
| |
// PEP 128 - sending serverResponseTime (WBEMServerResponseTime) in |
|
// response header |
|
static Buffer formatSimpleIMethodRspMessage( | static Buffer formatSimpleIMethodRspMessage( |
const CIMName& iMethodName, | const CIMName& iMethodName, |
const String& messageId, | const String& messageId, |
HttpMethod httpMethod, | HttpMethod httpMethod, |
const ContentLanguageList& httpContentLanguages, | const ContentLanguageList& httpContentLanguages, |
|
const Buffer& rtnParams, |
const Buffer& body, | const Buffer& body, |
Uint64 serverResponseTime, | Uint64 serverResponseTime, |
Boolean isFirst = true, | Boolean isFirst = true, |
Boolean isLast = true); | Boolean isLast = true); |
| |
|
|
static Buffer formatSimpleIMethodErrorRspMessage( | static Buffer formatSimpleIMethodErrorRspMessage( |
const CIMName& iMethodName, | const CIMName& iMethodName, |
const String& messageId, | const String& messageId, |
|
|
HttpMethod httpMethod, | HttpMethod httpMethod, |
const CIMException& cimException); | const CIMException& cimException); |
| |
static void indentedPrint( |
|
PEGASUS_STD(ostream)& os, |
|
const char* text, |
|
Uint32 indentChars = 2); |
|
|
|
static String getNextMessageId(); | static String getNextMessageId(); |
| |
/** Converts the given CIMKeyBinding type to one of the following: | /** Converts the given CIMKeyBinding type to one of the following: |
"boolean", "string", or "numeric" | "boolean", "string", or "numeric" |
*/ | */ |
static const char* keyBindingTypeToString (CIMKeyBinding::Type type); |
static const StrLit keyBindingTypeToString (CIMKeyBinding::Type type); |
| |
private: | private: |
| |
|
|
static void _appendIMethodCallElementEnd( | static void _appendIMethodCallElementEnd( |
Buffer& out); | Buffer& out); |
| |
|
static void _appendParamValueElementBegin( |
|
Buffer& out, |
|
const char* name); |
|
|
|
static void _appendParamValueElementEnd( |
|
Buffer& out); |
|
|
static void _appendIParamValueElementBegin( | static void _appendIParamValueElementBegin( |
Buffer& out, | Buffer& out, |
const char* name); | const char* name); |
|
|
static void _appendIParamValueElementEnd( | static void _appendIParamValueElementEnd( |
Buffer& out); | Buffer& out); |
| |
|
|
static void _appendIReturnValueElementBegin(Buffer& out); | static void _appendIReturnValueElementBegin(Buffer& out); |
static void _appendIReturnValueElementEnd(Buffer& out); | static void _appendIReturnValueElementEnd(Buffer& out); |
| |
|
//EXP_PULL |
|
|
|
static void _appendIReturnValueElementWithNameBegin( |
|
Buffer& out, |
|
const char* name); |
|
// EXP_PULL_END |
static void _appendSimpleExportReqElementBegin(Buffer& out); | static void _appendSimpleExportReqElementBegin(Buffer& out); |
static void _appendSimpleExportReqElementEnd(Buffer& out); | static void _appendSimpleExportReqElementEnd(Buffer& out); |
| |
|
|
static void _appendEMethodResponseElementEnd( | static void _appendEMethodResponseElementEnd( |
Buffer& out); | Buffer& out); |
| |
XmlWriter() { } |
XmlWriter(); |
}; | }; |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<( |
//============================================================================== |
Buffer& out, |
// |
const char* x); |
// _toString() routines: |
|
// |
|
//============================================================================== |
| |
inline Buffer& operator<<(Buffer& out, char x) |
inline void _toString(Buffer& out, Boolean x) |
{ | { |
out.append(x); |
XmlWriter::append(out, x); |
return out; |
|
} | } |
| |
inline Buffer& operator<<(Buffer& out, const char* s) |
inline void _toString(Buffer& out, Uint8 x) |
{ | { |
out.append(s, strlen(s)); |
XmlWriter::append(out, Uint32(x)); |
return out; |
|
} | } |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<(Buffer& out, const Char16& x); |
inline void _toString(Buffer& out, Sint8 x) |
|
{ |
|
XmlWriter::append(out, Sint32(x)); |
|
} |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<( |
inline void _toString(Buffer& out, Uint16 x) |
Buffer& out, |
{ |
const String& x); |
XmlWriter::append(out, Uint32(x)); |
|
} |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<( |
inline void _toString(Buffer& out, Sint16 x) |
Buffer& out, |
{ |
const Indentor& x); |
XmlWriter::append(out, Sint32(x)); |
|
} |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<( |
inline void _toString(Buffer& out, Uint32 x) |
Buffer& out, |
{ |
const Buffer& x); |
XmlWriter::append(out, x); |
|
} |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<( |
inline void _toString(Buffer& out, Sint32 x) |
Buffer& out, |
{ |
Uint32 x); |
XmlWriter::append(out, x); |
|
} |
| |
PEGASUS_COMMON_LINKAGE Buffer& operator<<( |
inline void _toString(Buffer& out, Uint64 x) |
Buffer& out, |
{ |
const CIMName& name); |
XmlWriter::append(out, x); |
|
} |
| |
PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( |
inline void _toString(Buffer& out, Sint64 x) |
PEGASUS_STD(ostream)& os, |
{ |
const CIMDateTime& x); |
XmlWriter::append(out, x); |
|
} |
| |
PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( |
inline void _toString(Buffer& out, Real32 x) |
PEGASUS_STD(ostream)& os, |
{ |
const CIMName& name); |
XmlWriter::append(out, Real64(x)); |
|
} |
|
|
|
inline void _toString(Buffer& out, Real64 x) |
|
{ |
|
XmlWriter::append(out, x); |
|
} |
|
|
|
inline void _toString(Buffer& out, Char16 x) |
|
{ |
|
// We need to convert the Char16 to UTF8 then append the UTF8 |
|
// character into the array. |
|
// NOTE: The UTF8 character could be several bytes long. |
|
// WARNING: This function will put in replacement character for |
|
// all characters that have surogate pairs. |
|
|
|
char str[6]; |
|
memset(str,0x00,sizeof(str)); |
|
char* charIN = (char *)&x; |
|
|
|
const Uint16 *strsrc = (Uint16 *)charIN; |
|
Uint16 *endsrc = (Uint16 *)&charIN[1]; |
|
|
|
Uint8 *strtgt = (Uint8 *)str; |
|
Uint8 *endtgt = (Uint8 *)&str[5]; |
|
|
|
UTF16toUTF8(&strsrc, endsrc, &strtgt, endtgt); |
|
out.append(str, UTF_8_COUNT_TRAIL_BYTES(str[0]) +1); |
|
} |
|
|
|
inline void _toString(Buffer& out, const String& x) |
|
{ |
|
out << x; |
|
} |
| |
PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( |
inline void _toString(Buffer& out, const CIMDateTime& x) |
PEGASUS_STD(ostream)& os, |
{ |
const CIMNamespaceName& name); |
out << x.toString(); |
|
} |
|
|
|
inline void _toString(Buffer& out, const CIMObjectPath& x) |
|
{ |
|
out << x.toString(); |
|
} |
|
|
|
inline void _toString(Buffer& out, const CIMObject& x) |
|
{ |
|
out << x.toString(); |
|
} |
|
inline void _toString(Buffer& out, const CIMInstance& x) |
|
{ |
|
out << CIMObject(x).toString(); |
|
} |
|
|
|
template<class T> |
|
void _toString(Buffer& out, const T* p, Uint32 size) |
|
{ |
|
while (size--) |
|
{ |
|
_toString(out, *p++); |
|
out.append(' '); |
|
} |
|
} |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |