version 1.10, 2001/04/13 18:20:51
|
version 1.16, 2001/05/20 20:34:01
|
|
|
//BEGIN_LICENSE |
//%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM | // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// | // |
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// DEALINGS IN THE SOFTWARE. | // DEALINGS IN THE SOFTWARE. |
// | // |
//END_LICENSE |
//============================================================================== |
//BEGIN_HISTORY |
|
// | // |
// Author: |
// Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// $Log$ |
// Modified By: |
// Revision 1.10 2001/04/13 18:20:51 mike |
|
// Ported so Solaris. |
|
// Fixed memory leaks. |
|
// | // |
// Revision 1.9 2001/04/08 01:13:22 mike |
//%///////////////////////////////////////////////////////////////////////////// |
// Changed "ConstCIM" to "CIMConst" |
|
// |
|
// Revision 1.7 2001/02/20 07:25:57 mike |
|
// Added basic create-instance in repository and in client. |
|
// |
|
// Revision 1.6 2001/02/19 01:47:17 mike |
|
// Renamed names of the form CIMConst to CIMConst. |
|
// |
|
// Revision 1.5 2001/02/18 03:56:01 mike |
|
// Changed more class names (e.g., ConstClassDecl -> CIMConstClass) |
|
// |
|
// Revision 1.4 2001/02/16 02:06:07 mike |
|
// Renamed many classes and headers. |
|
// |
|
// Revision 1.3 2001/01/31 08:20:51 mike |
|
// Added dispatcher framework. |
|
// Added enumerateInstanceNames. |
|
// |
|
// Revision 1.2 2001/01/29 02:23:44 mike |
|
// Added support for GetInstance operation |
|
// |
|
// Revision 1.1.1.1 2001/01/14 19:53:36 mike |
|
// Pegasus import |
|
// |
|
// |
|
//END_HISTORY |
|
| |
#include <cstdlib> | #include <cstdlib> |
#include <cstdio> | #include <cstdio> |
|
|
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="; |
|
|
return formatIParamValueElement(out, parameterName, tmp); | return formatIParamValueElement(out, parameterName, tmp); |
} | } |
| |
|
//---------------------------------------------------------- |
|
// |
|
// appendPropertyNameParameter() |
|
// |
|
// </IPARAMVALUE> |
|
// <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE> |
|
// |
|
// USE: Create parameter for getProperty operation |
|
//========================================================== |
|
Array<Sint8>& XmlWriter::appendPropertyNameParameter( |
|
Array<Sint8>& out, |
|
const String& propertyName) |
|
{ |
|
Array<Sint8> tmp; |
|
tmp << "<VALUE>" << propertyName << "</VALUE>\n"; |
|
return formatIParamValueElement(out,"PropertyName", tmp);} |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// appendClassParameter() | // appendClassParameter() |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
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; |
|
|
| |
Array<Sint8> XmlWriter::formatSimpleRspMessage( | Array<Sint8> XmlWriter::formatSimpleRspMessage( |
const char* iMethodName, | const char* iMethodName, |
|
const Uint32 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 |