version 1.12, 2001/04/25 22:20:56
|
version 1.19, 2001/06/16 23:10:05
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// copy of this software and associated documentation files (the "Software"), |
// of this software and associated documentation files (the "Software"), to |
// to deal in the Software without restriction, including without limitation |
// deal in the Software without restriction, including without limitation the |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// and/or sell copies of the Software, and to permit persons to whom the |
// sell copies of the Software, and to permit persons to whom the Software is |
// Software is furnished to do so, subject to the following conditions: |
// furnished to do so, subject to the following conditions: |
// |
// |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// DEALINGS IN THE SOFTWARE. |
// 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. |
// | // |
//============================================================================== | //============================================================================== |
// | // |
|
|
out << "</LOCALNAMESPACEPATH>\n"; | out << "</LOCALNAMESPACEPATH>\n"; |
} | } |
| |
static inline void AppendSpecialChar(std::ostream& os, char c) |
static inline void AppendSpecialChar(PEGASUS_STD(ostream)& os, char c) |
{ | { |
switch (c) | switch (c) |
{ | { |
|
|
} | } |
} | } |
| |
static inline void AppendSpecial(std::ostream& os, const char* str) |
static inline void AppendSpecial(PEGASUS_STD(ostream)& os, const char* str) |
{ | { |
while (*str) | while (*str) |
AppendSpecialChar(os, *str++); | AppendSpecialChar(os, *str++); |
|
|
out << "M-POST /cimom HTTP/1.1\r\n"; | out << "M-POST /cimom HTTP/1.1\r\n"; |
out << "HOST: " << host << "\r\n"; | out << "HOST: " << host << "\r\n"; |
out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n"; | out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n"; |
out << "Content-Length: " << content.getSize() << "\r\n"; |
out << "Content-Length: " << content.size() << "\r\n"; |
out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns="; | out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns="; |
out << nn <<"\r\n"; | out << nn <<"\r\n"; |
out << nn << "-CIMOperation: " << cimOperation << "\r\n"; | out << nn << "-CIMOperation: " << cimOperation << "\r\n"; |
|
|
| |
out << "HTTP/1.1 200 OK\r\n"; | out << "HTTP/1.1 200 OK\r\n"; |
out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n"; | out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n"; |
out << "Content-Length: " << content.getSize() << "\r\n"; |
out << "Content-Length: " << content.size() << "\r\n"; |
out << "Ext:\r\n"; | out << "Ext:\r\n"; |
out << "Cache-Control: no-cache\r\n"; | out << "Cache-Control: no-cache\r\n"; |
out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns="; | out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns="; |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
Array<Sint8> XmlWriter::formatMessageElement( | Array<Sint8> XmlWriter::formatMessageElement( |
Uint32 messageId, |
const String& messageId, |
const Array<Sint8>& body) | const Array<Sint8>& body) |
{ | { |
Array<Sint8> out; | Array<Sint8> out; |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
static void _printAttributes( | static void _printAttributes( |
std::ostream& os, |
PEGASUS_STD(ostream)& os, |
const XmlAttribute* attributes, | const XmlAttribute* attributes, |
Uint32 attributeCount) | Uint32 attributeCount) |
{ | { |
|
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
static void _indent(std::ostream& os, Uint32 level, Uint32 indentChars) |
static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars) |
{ | { |
Uint32 n = level * indentChars; | Uint32 n = level * indentChars; |
| |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
void XmlWriter::indentedPrint( | void XmlWriter::indentedPrint( |
std::ostream& os, |
PEGASUS_STD(ostream)& os, |
const char* text, | const char* text, |
Uint32 indentChars) | Uint32 indentChars) |
{ | { |
|
|
{ | { |
case XmlEntry::XML_DECLARATION: | case XmlEntry::XML_DECLARATION: |
{ | { |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
| |
os << "<?" << entry.text << " "; | os << "<?" << entry.text << " "; |
_printAttributes(os, entry.attributes, entry.attributeCount); | _printAttributes(os, entry.attributes, entry.attributeCount); |
|
|
| |
case XmlEntry::START_TAG: | case XmlEntry::START_TAG: |
{ | { |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
| |
os << "<" << entry.text; | os << "<" << entry.text; |
| |
|
|
| |
case XmlEntry::EMPTY_TAG: | case XmlEntry::EMPTY_TAG: |
{ | { |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
| |
os << "<" << entry.text << " "; | os << "<" << entry.text << " "; |
_printAttributes(os, entry.attributes, entry.attributeCount); | _printAttributes(os, entry.attributes, entry.attributeCount); |
|
|
if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0) | if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0) |
stack.pop(); | stack.pop(); |
| |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
| |
os << "</" << entry.text << ">"; | os << "</" << entry.text << ">"; |
break; | break; |
|
|
case XmlEntry::COMMENT: | case XmlEntry::COMMENT: |
{ | { |
| |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
os << "<!--"; | os << "<!--"; |
AppendSpecial(os, entry.text); | AppendSpecial(os, entry.text); |
os << "-->"; | os << "-->"; |
|
|
| |
case XmlEntry::CONTENT: | case XmlEntry::CONTENT: |
{ | { |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
AppendSpecial(os, entry.text); | AppendSpecial(os, entry.text); |
break; | break; |
} | } |
| |
case XmlEntry::CDATA: | case XmlEntry::CDATA: |
{ | { |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
os << "<![CDATA[...]]>"; | os << "<![CDATA[...]]>"; |
break; | break; |
} | } |
| |
case XmlEntry::DOCTYPE: | case XmlEntry::DOCTYPE: |
{ | { |
_indent(os, stack.getSize(), indentChars); |
_indent(os, stack.size(), indentChars); |
os << "<!DOCTYPE...>"; | os << "<!DOCTYPE...>"; |
break; | break; |
} | } |
} | } |
| |
os << std::endl; |
os << PEGASUS_STD(endl); |
} | } |
| |
delete [] tmp; | delete [] tmp; |
|
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
Uint32 XmlWriter::getNextMessageId() |
String XmlWriter::getNextMessageId() |
{ | { |
// ATTN: make thread-safe: | // ATTN: make thread-safe: |
static Uint32 messageId = 1000; | static Uint32 messageId = 1000; |
|
|
if (messageId < 1000) | if (messageId < 1000) |
messageId = 1001; | messageId = 1001; |
| |
return messageId; |
char buffer[16]; |
|
sprintf(buffer, "%d", messageId); |
|
return buffer; |
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
| |
Array<Sint8> XmlWriter::formatSimpleRspMessage( | Array<Sint8> XmlWriter::formatSimpleRspMessage( |
const char* iMethodName, | const char* iMethodName, |
|
const String& messageId, |
const Array<Sint8>& body) | const Array<Sint8>& body) |
{ | { |
return XmlWriter::formatMethodResponseHeader( | return XmlWriter::formatMethodResponseHeader( |
XmlWriter::formatMessageElement( | XmlWriter::formatMessageElement( |
XmlWriter::getNextMessageId(), |
messageId, |
XmlWriter::formatSimpleRspElement( | XmlWriter::formatSimpleRspElement( |
XmlWriter::formatIMethodResponseElement( | XmlWriter::formatIMethodResponseElement( |
iMethodName, | iMethodName, |
XmlWriter::formatIReturnValueElement(body))))); | XmlWriter::formatIReturnValueElement(body))))); |
} | } |
| |
|
Array<Sint8>& operator<<(Array<Sint8>& out, const char* x) |
|
{ |
|
XmlWriter::append(out, x); |
|
return out; |
|
} |
|
|
|
Array<Sint8>& operator<<(Array<Sint8>& out, char x) |
|
{ |
|
XmlWriter::append(out, x); |
|
return out; |
|
} |
|
|
|
Array<Sint8>& operator<<(Array<Sint8>& out, Char16 x) |
|
{ |
|
XmlWriter::append(out, x); |
|
return out; |
|
} |
|
|
|
Array<Sint8>& operator<<(Array<Sint8>& out, const String& x) |
|
{ |
|
XmlWriter::append(out, x); |
|
return out; |
|
} |
|
|
|
Array<Sint8>& operator<<(Array<Sint8>& out, const Indentor& x) |
|
{ |
|
XmlWriter::append(out, x); |
|
return out; |
|
} |
|
|
|
Array<Sint8>& operator<<(Array<Sint8>& out, const Array<Sint8>& x) |
|
{ |
|
out.appendArray(x); |
|
return out; |
|
} |
|
|
|
Array<Sint8>& operator<<(Array<Sint8>& out, Uint32 x) |
|
{ |
|
XmlWriter::append(out, x); |
|
return out; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |