version 1.141, 2006/08/22 18:30:48
|
version 1.148, 2007/02/13 19:21:44
|
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
|
// |
|
// Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com) |
|
// Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com) |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
|
// Amit K Arora, IBM (amita@in.ibm.com) for PEP#101 |
|
// Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase1 |
|
// Willis White (whiwill@us.ibm.com) PEP 127 and 128 |
|
// Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase2 |
|
// Dave Sudlik, IBM (dsudlik@us.ibm.com) |
|
// David Dillard, Symantec Corp. (david_dillard@symantec.com) |
|
// Vijay Eli, vijayeli@in.ibm.com, fix for #2571 |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
|
|
struct SpecialChar | struct SpecialChar |
{ | { |
const char* str; | const char* str; |
size_t size; |
Uint32 size; |
}; | }; |
| |
// Defines encodings of special characters. Just use a 7-bit ASCII character | // Defines encodings of special characters. Just use a 7-bit ASCII character |
|
|
} | } |
| |
| |
// l10n |
|
Buffer& operator<<(Buffer& out, const AcceptLanguageList& al) | Buffer& operator<<(Buffer& out, const AcceptLanguageList& al) |
{ | { |
XmlWriter::append(out, LanguageParser::buildAcceptLanguageHeader(al)); | XmlWriter::append(out, LanguageParser::buildAcceptLanguageHeader(al)); |
return out; | return out; |
} | } |
| |
// l10n |
|
Buffer& operator<<(Buffer& out, const ContentLanguageList& cl) | Buffer& operator<<(Buffer& out, const ContentLanguageList& cl) |
{ | { |
XmlWriter::append(out, LanguageParser::buildContentLanguageHeader(cl)); | XmlWriter::append(out, LanguageParser::buildContentLanguageHeader(cl)); |
|
|
Uint8 *strtgt = (Uint8 *)str; | Uint8 *strtgt = (Uint8 *)str; |
Uint8 *endtgt = (Uint8 *)&str[5]; | Uint8 *endtgt = (Uint8 *)&str[5]; |
| |
UTF16toUTF8(&strsrc, |
UTF16toUTF8( |
|
&strsrc, |
endsrc, | endsrc, |
&strtgt, | &strtgt, |
endtgt); | endtgt); |
|
|
Uint8 *strtgt = (Uint8 *)str; | Uint8 *strtgt = (Uint8 *)str; |
Uint8 *endtgt = (Uint8 *)&str[5]; | Uint8 *endtgt = (Uint8 *)&str[5]; |
| |
UTF16toUTF8(&strsrc, |
UTF16toUTF8( |
|
&strsrc, |
endsrc, | endsrc, |
&strtgt, | &strtgt, |
endtgt); | endtgt); |
|
|
void XmlWriter::append(Buffer& out, Real64 x) | void XmlWriter::append(Buffer& out, Real64 x) |
{ | { |
char buffer[128]; | char buffer[128]; |
// %.16e gives '[-]m.dddddddddddddddde+/-xx', which seems compatible with the format |
// %.16e gives '[-]m.dddddddddddddddde+/-xx', which seems compatible |
// given in the CIM/XML spec, and the precision required by the CIM 2.2 spec |
// with the format given in the CIM/XML spec, and the precision required |
// (8 byte IEEE floating point) |
// by the CIM 2.2 spec (8 byte IEEE floating point) |
sprintf(buffer, "%.16e", x); | sprintf(buffer, "%.16e", x); |
append(out, buffer); | append(out, buffer); |
} | } |
|
|
continue; | continue; |
} | } |
| |
// Hanlde UTF8 case (if reached). |
// Handle UTF8 case (if reached). |
| |
if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || | if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) | ((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) |
|
|
Char16 highSurrogate = uriString[i]; | Char16 highSurrogate = uriString[i]; |
Char16 lowSurrogate = uriString[++i]; | Char16 lowSurrogate = uriString[++i]; |
| |
_xmlWritter_appendSurrogatePair(utf8, Uint16(highSurrogate),Uint16(lowSurrogate)); |
_xmlWritter_appendSurrogatePair( |
|
utf8, Uint16(highSurrogate),Uint16(lowSurrogate)); |
} | } |
else | else |
{ | { |
|
|
CIMObjectPath ref = keyBindings[i].getValue(); | CIMObjectPath ref = keyBindings[i].getValue(); |
appendValueReferenceElement(out, ref, true); | appendValueReferenceElement(out, ref, true); |
} | } |
else { |
else |
|
{ |
out << STRLIT("<KEYVALUE VALUETYPE=\""); | out << STRLIT("<KEYVALUE VALUETYPE=\""); |
out << keyBindingTypeToString(keyBindings[i].getType()); | out << keyBindingTypeToString(keyBindings[i].getType()); |
out << STRLIT("\">"); | out << STRLIT("\">"); |
|
|
} | } |
if (contentLanguages.size() > 0) | if (contentLanguages.size() > 0) |
{ | { |
out << STRLIT("Content-Language: ") << contentLanguages << STRLIT("\r\n"); |
out << STRLIT("Content-Language: ") << contentLanguages << |
|
STRLIT("\r\n"); |
} | } |
| |
#ifdef PEGASUS_DEBUG | #ifdef PEGASUS_DEBUG |
|
|
| |
static const char *clientTransferEncodingOff = | static const char *clientTransferEncodingOff = |
getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST"); | getenv("PEGASUS_HTTP_TRANSFER_ENCODING_REQUEST"); |
|
|
if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0') | if (!clientTransferEncodingOff || *clientTransferEncodingOff != '0') |
#endif | #endif |
| |
|
|
else | else |
{ | { |
out << STRLIT("CIMOperation: MethodCall\r\n"); | out << STRLIT("CIMOperation: MethodCall\r\n"); |
out << STRLIT("CIMMethod: ") << encodeURICharacters(cimMethod.getString()) |
out << STRLIT("CIMMethod: ") |
|
<< encodeURICharacters(cimMethod.getString()) |
<< STRLIT("\r\n"); | << STRLIT("\r\n"); |
out << STRLIT("CIMObject: ") << encodeURICharacters(cimObject) | out << STRLIT("CIMObject: ") << encodeURICharacters(cimObject) |
<< STRLIT("\r\n"); | << STRLIT("\r\n"); |
|
|
| |
if (contentLanguages.size() > 0) | if (contentLanguages.size() > 0) |
{ | { |
out << STRLIT("Content-Language: ") << contentLanguages << STRLIT("\r\n"); |
out << STRLIT("Content-Language: ") << contentLanguages << |
|
STRLIT("\r\n"); |
} | } |
if (httpMethod == HTTP_METHOD_M_POST) | if (httpMethod == HTTP_METHOD_M_POST) |
{ | { |
|
|
out << STRLIT("<ERROR"); | out << STRLIT("<ERROR"); |
out << STRLIT(" CODE=\"") << Uint32(cimException.getCode()); | out << STRLIT(" CODE=\"") << Uint32(cimException.getCode()); |
out.append('"'); | out.append('"'); |
|
|
String description = TraceableCIMException(cimException).getDescription(); | String description = TraceableCIMException(cimException).getDescription(); |
|
|
if (description != String::EMPTY) | if (description != String::EMPTY) |
{ | { |
out << STRLIT(" DESCRIPTION=\""); | out << STRLIT(" DESCRIPTION=\""); |
appendSpecial(out, description); | appendSpecial(out, description); |
out.append('"'); | out.append('"'); |
} | } |
|
|
|
if (cimException.getErrorCount()) |
|
{ |
|
out << STRLIT(">"); |
|
|
|
for (Uint32 i = 0, n = cimException.getErrorCount(); i < n; i++) |
|
appendInstanceElement(out, cimException.getError(i)); |
|
|
|
out << STRLIT("</ERROR>"); |
|
} |
|
else |
out << STRLIT("/>"); | out << STRLIT("/>"); |
} | } |
| |
|
|
| |
CIMType type = value.getType(); | CIMType type = value.getType(); |
// If the property type is CIMObject, then | // If the property type is CIMObject, then |
// encode the property in CIM-XML as a string with the EMBEDDEDOBJECT attribute |
// encode the property in CIM-XML as a string with the EMBEDDEDOBJECT |
// (there is not currently a CIM-XML "object" datatype) |
// attribute (there is not currently a CIM-XML "object" datatype) |
// else | // else |
// output the real type | // output the real type |
if (type == CIMTYPE_OBJECT) | if (type == CIMTYPE_OBJECT) |
|
|
{ | { |
// NOTE: temporarily put zero for content length. the http code | // NOTE: temporarily put zero for content length. the http code |
// will later decide to fill in the length or remove it altogether | // will later decide to fill in the length or remove it altogether |
appendMethodResponseHeader(out, httpMethod, httpContentLanguages, 0, |
appendMethodResponseHeader( |
serverResponseTime); |
out, httpMethod, httpContentLanguages, 0, serverResponseTime); |
_appendMessageElementBegin(out, messageId); | _appendMessageElementBegin(out, messageId); |
_appendSimpleRspElementBegin(out); | _appendSimpleRspElementBegin(out); |
_appendMethodResponseElementBegin(out, methodName); | _appendMethodResponseElementBegin(out, methodName); |
|
|
} | } |
| |
| |
|
|
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// XmlWriter::formatSimpleMethodErrorRspMessage() | // XmlWriter::formatSimpleMethodErrorRspMessage() |
|
|
_appendSimpleRspElementEnd(out); | _appendSimpleRspElementEnd(out); |
_appendMessageElementEnd(out); | _appendMessageElementEnd(out); |
| |
// l10n |
appendMethodResponseHeader( |
appendMethodResponseHeader(tmp, |
tmp, |
httpMethod, | httpMethod, |
cimException.getContentLanguages(), | cimException.getContentLanguages(), |
out.size()); | out.size()); |
|
|
{ | { |
// NOTE: temporarily put zero for content length. the http code | // NOTE: temporarily put zero for content length. the http code |
// will later decide to fill in the length or remove it altogether | // will later decide to fill in the length or remove it altogether |
appendMethodResponseHeader(out, httpMethod, httpContentLanguages, 0, |
appendMethodResponseHeader( |
serverResponseTime); |
out, httpMethod, httpContentLanguages, 0, serverResponseTime); |
_appendMessageElementBegin(out, messageId); | _appendMessageElementBegin(out, messageId); |
_appendSimpleRspElementBegin(out); | _appendSimpleRspElementBegin(out); |
_appendIMethodResponseElementBegin(out, iMethodName); | _appendIMethodResponseElementBegin(out, iMethodName); |
| |
// output the start of the return tag. Test if there is response data by: |
// output the start of the return tag. Test if there is response data |
|
// by: |
// 1. there is data on the first chunk OR | // 1. there is data on the first chunk OR |
// 2. there is no data on the first chunk but isLast is false implying | // 2. there is no data on the first chunk but isLast is false implying |
// there is more non-empty data to come. If all subsequent chunks | // there is more non-empty data to come. If all subsequent chunks |
|
|
_appendSimpleRspElementEnd(out); | _appendSimpleRspElementEnd(out); |
_appendMessageElementEnd(out); | _appendMessageElementEnd(out); |
| |
// l10n |
|
appendMethodResponseHeader(tmp, | appendMethodResponseHeader(tmp, |
httpMethod, | httpMethod, |
cimException.getContentLanguages(), | cimException.getContentLanguages(), |
|
|
} | } |
if (contentLanguages.size() > 0) | if (contentLanguages.size() > 0) |
{ | { |
out << STRLIT("Content-Language: ") << contentLanguages << STRLIT("\r\n"); |
out << STRLIT("Content-Language: ") << contentLanguages << |
|
STRLIT("\r\n"); |
} | } |
| |
#ifdef PEGASUS_DEBUG | #ifdef PEGASUS_DEBUG |
|
|
out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns="); | out << STRLIT("Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns="); |
out << nn << STRLIT("\r\n"); | out << nn << STRLIT("\r\n"); |
out << nn << STRLIT("-CIMExport: MethodRequest\r\n"); | out << nn << STRLIT("-CIMExport: MethodRequest\r\n"); |
out << nn << STRLIT("-CIMExportMethod: ") << cimMethod << STRLIT("\r\n"); |
out << nn << STRLIT("-CIMExportMethod: ") << cimMethod << |
|
STRLIT("\r\n"); |
} | } |
else | else |
{ | { |
|
|
| |
if (contentLanguages.size() > 0) | if (contentLanguages.size() > 0) |
{ | { |
out << STRLIT("Content-Language: ") << contentLanguages << STRLIT("\r\n"); |
out << STRLIT("Content-Language: ") << contentLanguages << |
|
STRLIT("\r\n"); |
} | } |
if (httpMethod == HTTP_METHOD_M_POST) | if (httpMethod == HTTP_METHOD_M_POST) |
{ | { |
|
|
_appendSimpleExportRspElementEnd(out); | _appendSimpleExportRspElementEnd(out); |
_appendMessageElementEnd(out); | _appendMessageElementEnd(out); |
| |
// l10n |
appendEMethodResponseHeader( |
appendEMethodResponseHeader(tmp, |
tmp, |
httpMethod, | httpMethod, |
cimException.getContentLanguages(), | cimException.getContentLanguages(), |
out.size()); | out.size()); |
|
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
void _xmlWritter_indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars) |
void _xmlWritter_indent( |
|
PEGASUS_STD(ostream)& os, |
|
Uint32 level, |
|
Uint32 indentChars) |
{ | { |
Uint32 n = level * indentChars; | Uint32 n = level * indentChars; |
| |
|
|
_xmlWritter_indent(os, stack.size(), indentChars); | _xmlWritter_indent(os, stack.size(), indentChars); |
| |
os << "<?" << entry.text << " "; | os << "<?" << entry.text << " "; |
_xmlWritter_printAttributes(os, entry.attributes, entry.attributeCount); |
_xmlWritter_printAttributes( |
|
os, entry.attributes, entry.attributeCount); |
os << "?>"; | os << "?>"; |
break; | break; |
} | } |
|
|
if (entry.attributeCount) | if (entry.attributeCount) |
os << ' '; | os << ' '; |
| |
_xmlWritter_printAttributes(os, entry.attributes, entry.attributeCount); |
_xmlWritter_printAttributes( |
|
os, entry.attributes, entry.attributeCount); |
os << ">"; | os << ">"; |
stack.push(entry.text); | stack.push(entry.text); |
break; | break; |
|
|
_xmlWritter_indent(os, stack.size(), indentChars); | _xmlWritter_indent(os, stack.size(), indentChars); |
| |
os << "<" << entry.text << " "; | os << "<" << entry.text << " "; |
_xmlWritter_printAttributes(os, entry.attributes, entry.attributeCount); |
_xmlWritter_printAttributes( |
|
os, entry.attributes, entry.attributeCount); |
os << "/>"; | os << "/>"; |
break; | break; |
} | } |
|
|
| |
case XmlEntry::COMMENT: | case XmlEntry::COMMENT: |
{ | { |
|
|
_xmlWritter_indent(os, stack.size(), indentChars); | _xmlWritter_indent(os, stack.size(), indentChars); |
os << "<!--"; | os << "<!--"; |
_xmlWritter_appendSpecial(os, entry.text); | _xmlWritter_appendSpecial(os, entry.text); |
|
|
| |
os << PEGASUS_STD(endl); | os << PEGASUS_STD(endl); |
} | } |
|
|
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |