version 1.147, 2007/01/11 16:21:54
|
version 1.154, 2008/01/30 18:56:21
|
|
|
#include "StrLit.h" | #include "StrLit.h" |
#include "LanguageParser.h" | #include "LanguageParser.h" |
#include "IDFactory.h" | #include "IDFactory.h" |
|
#include "StringConversion.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
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 |
|
|
{ | { |
if ( ((c < 0x20) && (c >= 0)) || (c == 0x7f) ) | if ( ((c < 0x20) && (c >= 0)) || (c == 0x7f) ) |
{ | { |
char charref[7]; |
char scratchBuffer[22]; |
sprintf(charref, "&#%u;", static_cast<Uint8>(c)); |
Uint32 outputLength; |
os << charref; |
const char * output = Uint8ToString(scratchBuffer, |
|
static_cast<Uint8>(c), |
|
outputLength); |
|
os << "&#" << output << ";"; |
} | } |
else | else |
{ | { |
|
|
_xmlWritter_appendSpecialChar(os, *str++); | _xmlWritter_appendSpecialChar(os, *str++); |
} | } |
| |
|
// On windows sprintf outputs 3 digit precision exponent prepending |
|
// zeros. Make it 2 digit precision if first digit is zero in the exponent. |
|
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
inline void _xmlWriter_normalizeRealValueString(char *str) |
|
{ |
|
// skip initial sign value... |
|
if (*str == '-' || *str == '+') |
|
{ |
|
++str; |
|
} |
|
while (*str && *str != '+' && *str != '-') |
|
{ |
|
++str; |
|
} |
|
if (*str && * ++str == '0') |
|
{ |
|
*str = *(str+1); |
|
*(str+1) = *(str+2); |
|
*(str+2) = 0; |
|
} |
|
} |
|
#endif |
|
|
void XmlWriter::append(Buffer& out, const Char16& x) | void XmlWriter::append(Buffer& out, const Char16& x) |
{ | { |
_xmlWritter_appendChar(out, x); | _xmlWritter_appendChar(out, x); |
|
|
| |
void XmlWriter::append(Buffer& out, Boolean x) | void XmlWriter::append(Buffer& out, Boolean x) |
{ | { |
append(out, (x ? "TRUE" : "FALSE")); |
if (x) |
|
out.append(STRLIT_ARGS("TRUE")); |
|
else |
|
out.append(STRLIT_ARGS("FALSE")); |
} | } |
| |
void XmlWriter::append(Buffer& out, Uint32 x) | void XmlWriter::append(Buffer& out, Uint32 x) |
{ | { |
char buffer[32]; |
Uint32 outputLength=0; |
sprintf(buffer, "%u", x); |
char buffer[22]; |
append(out, buffer); |
const char * output = Uint32ToString(buffer, x, outputLength); |
|
out.append(output, outputLength); |
} | } |
| |
void XmlWriter::append(Buffer& out, Sint32 x) | void XmlWriter::append(Buffer& out, Sint32 x) |
{ | { |
char buffer[32]; |
Uint32 outputLength=0; |
sprintf(buffer, "%d", x); |
char buffer[22]; |
append(out, buffer); |
const char * output = Sint32ToString(buffer, x, outputLength); |
|
out.append(output, outputLength); |
} | } |
| |
void XmlWriter::append(Buffer& out, Uint64 x) | void XmlWriter::append(Buffer& out, Uint64 x) |
{ | { |
char buffer[32]; // Should need 21 chars max |
Uint32 outputLength=0; |
sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x); |
char buffer[22]; |
append(out, buffer); |
const char * output = Uint64ToString(buffer, x, outputLength); |
|
out.append(output, outputLength); |
} | } |
| |
void XmlWriter::append(Buffer& out, Sint64 x) | void XmlWriter::append(Buffer& out, Sint64 x) |
{ | { |
char buffer[32]; // Should need 21 chars max |
Uint32 outputLength=0; |
sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d", x); |
char buffer[22]; |
append(out, buffer); |
const char * output = Sint64ToString(buffer, x, outputLength); |
|
out.append(output, outputLength); |
} | } |
| |
void XmlWriter::append(Buffer& out, Real32 x) | void XmlWriter::append(Buffer& out, Real32 x) |
|
|
// given in the CIM/XML spec, and the precision required by the CIM 2.2 spec | // given in the CIM/XML spec, and the precision required by the CIM 2.2 spec |
// (4 byte IEEE floating point) | // (4 byte IEEE floating point) |
sprintf(buffer, "%.7e", x); | sprintf(buffer, "%.7e", x); |
|
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
_xmlWriter_normalizeRealValueString(buffer); |
|
#endif |
append(out, buffer); | append(out, buffer); |
} | } |
| |
|
|
// with the format given in the CIM/XML spec, and the precision required | // with the format given in the CIM/XML spec, and the precision required |
// by the CIM 2.2 spec (8 byte IEEE floating point) | // by the CIM 2.2 spec (8 byte IEEE floating point) |
sprintf(buffer, "%.16e", x); | sprintf(buffer, "%.16e", x); |
|
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
_xmlWriter_normalizeRealValueString(buffer); |
|
#endif |
append(out, buffer); | append(out, buffer); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendValueElement(tmp, value); | appendValueElement(tmp, value); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendValueReferenceElement(tmp, reference, true); | appendValueReferenceElement(tmp, reference, true); |
tmp.append('\0'); |
|
indentedPrint(os, tmp.getData()); | indentedPrint(os, tmp.getData()); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstClass& cimclass) | const CIMConstClass& cimclass) |
{ | { |
cimclass._checkRep(); |
CheckRep(cimclass._rep); |
cimclass._rep->toXml(out); | cimclass._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendClassElement(tmp, cimclass); | appendClassElement(tmp, cimclass); |
tmp.append('\0'); |
|
indentedPrint(os, tmp.getData(), 4); | indentedPrint(os, tmp.getData(), 4); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstInstance& instance) | const CIMConstInstance& instance) |
{ | { |
instance._checkRep(); |
CheckRep(instance._rep); |
instance._rep->toXml(out); | instance._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendInstanceElement(tmp, instance); | appendInstanceElement(tmp, instance); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstProperty& property) | const CIMConstProperty& property) |
{ | { |
property._checkRep(); |
CheckRep(property._rep); |
property._rep->toXml(out); | property._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendPropertyElement(tmp, property); | appendPropertyElement(tmp, property); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstMethod& method) | const CIMConstMethod& method) |
{ | { |
method._checkRep(); |
CheckRep(method._rep); |
method._rep->toXml(out); | method._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendMethodElement(tmp, method); | appendMethodElement(tmp, method); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstParameter& parameter) | const CIMConstParameter& parameter) |
{ | { |
parameter._checkRep(); |
CheckRep(parameter._rep); |
parameter._rep->toXml(out); | parameter._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendParameterElement(tmp, parameter); | appendParameterElement(tmp, parameter); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMParamValue& paramValue) | const CIMParamValue& paramValue) |
{ | { |
paramValue._checkRep(); |
CheckRep(paramValue._rep); |
paramValue._rep->toXml(out); | paramValue._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendParamValueElement(tmp, paramValue); | appendParamValueElement(tmp, paramValue); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstQualifier& qualifier) | const CIMConstQualifier& qualifier) |
{ | { |
qualifier._checkRep(); |
CheckRep(qualifier._rep); |
qualifier._rep->toXml(out); | qualifier._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendQualifierElement(tmp, qualifier); | appendQualifierElement(tmp, qualifier); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
Buffer& out, | Buffer& out, |
const CIMConstQualifierDecl& qualifierDecl) | const CIMConstQualifierDecl& qualifierDecl) |
{ | { |
qualifierDecl._checkRep(); |
CheckRep(qualifierDecl._rep); |
qualifierDecl._rep->toXml(out); | qualifierDecl._rep->toXml(out); |
} | } |
| |
|
|
{ | { |
Buffer tmp; | Buffer tmp; |
appendQualifierDeclElement(tmp, qualifierDecl); | appendQualifierDeclElement(tmp, qualifierDecl); |
tmp.append('\0'); |
|
os << tmp.getData() << PEGASUS_STD(endl); | os << tmp.getData() << PEGASUS_STD(endl); |
} | } |
| |
|
|
const String& content) | const String& content) |
{ | { |
out << STRLIT("HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n"); | out << STRLIT("HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n"); |
|
Uint32 contentLength = 0; |
|
OUTPUT_CONTENTLENGTH; |
out << content << STRLIT("\r\n"); | out << content << STRLIT("\r\n"); |
out << STRLIT("\r\n"); | out << STRLIT("\r\n"); |
| |
|
|
out << STRLIT("/>"); | out << STRLIT("/>"); |
} | } |
| |
//------------------------------------------------------------------------------ |
//---------------------------------------------------------------------- |
// | // |
// appendReturnValueElement() |
// appendParmType |
// |
// Appends the Param type and EmbeddedObject Info |
// <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)> |
// to the buffer |
// <!ATTLIST RETURNVALUE |
|
// %EmbeddedObject; #IMPLIED | // %EmbeddedObject; #IMPLIED |
// %ParamType;> | // %ParamType;> |
// | // |
//------------------------------------------------------------------------------ |
//--------------------------------------------------------------------- |
|
void XmlWriter::appendParamTypeAndEmbeddedObjAttrib( |
void XmlWriter::appendReturnValueElement( |
|
Buffer& out, | Buffer& out, |
const CIMValue& value) |
const CIMType& type) |
{ | { |
out << STRLIT("<RETURNVALUE"); |
|
| |
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 |
// encode the property in CIM-XML as a string with the EmbeddedObject |
// attribute (there is not currently a CIM-XML "object" datatype) |
// attribute (there is not currently a CIM-XML "object" |
|
// datatype). |
|
// Because of an error in Pegasus we were earlier outputting |
|
// upper case "EMBEDDEDOBJECT" as the attribute name. The |
|
// spec calls for mixed case "EmbeddedObject. Fixed in |
|
// bug 7131 to output EmbeddedObject attribute in upper |
|
// case and mixed case. Receiver will ignore one or the |
|
// other. |
// else | // else |
// output the real type | // output the real type |
if (type == CIMTYPE_OBJECT) | if (type == CIMTYPE_OBJECT) |
{ | { |
|
|
out << STRLIT(" PARAMTYPE=\"string\""); | out << STRLIT(" PARAMTYPE=\"string\""); |
|
out << STRLIT(" EmbeddedObject=\"object\""); |
out << STRLIT(" EMBEDDEDOBJECT=\"object\""); | out << STRLIT(" EMBEDDEDOBJECT=\"object\""); |
} | } |
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT | #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
else if (type == CIMTYPE_INSTANCE) | else if (type == CIMTYPE_INSTANCE) |
{ | { |
out << STRLIT(" PARAMTYPE=\"string\""); | out << STRLIT(" PARAMTYPE=\"string\""); |
|
out << STRLIT(" EmbeddedObject=\"instance\""); |
out << STRLIT(" EMBEDDEDOBJECT=\"instance\""); | out << STRLIT(" EMBEDDEDOBJECT=\"instance\""); |
} | } |
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT | #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
|
out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type); | out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type); |
out.append('"'); | out.append('"'); |
} | } |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
|
// appendReturnValueElement() |
|
// |
|
// <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)> |
|
// <!ATTLIST RETURNVALUE |
|
// %EmbeddedObject; #IMPLIED |
|
// %ParamType;> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
|
|
void XmlWriter::appendReturnValueElement( |
|
Buffer& out, |
|
const CIMValue& value) |
|
{ |
|
out << STRLIT("<RETURNVALUE"); |
|
|
|
CIMType type = value.getType(); |
|
|
|
appendParamTypeAndEmbeddedObjAttrib(out, type); |
| |
out << STRLIT(">\n"); | out << STRLIT(">\n"); |
| |
|
|
httpMethod, | httpMethod, |
httpAcceptLanguages, | httpAcceptLanguages, |
httpContentLanguages, | httpContentLanguages, |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
tmp, | tmp, |
httpMethod, | httpMethod, |
cimException.getContentLanguages(), | cimException.getContentLanguages(), |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
httpMethod, | httpMethod, |
httpAcceptLanguages, | httpAcceptLanguages, |
httpContentLanguages, | httpContentLanguages, |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
appendMethodResponseHeader(tmp, | appendMethodResponseHeader(tmp, |
httpMethod, | httpMethod, |
cimException.getContentLanguages(), | cimException.getContentLanguages(), |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
authenticationHeader, | authenticationHeader, |
httpAcceptLanguages, | httpAcceptLanguages, |
httpContentLanguages, | httpContentLanguages, |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
appendEMethodResponseHeader(tmp, | appendEMethodResponseHeader(tmp, |
httpMethod, | httpMethod, |
httpContentLanguages, | httpContentLanguages, |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
tmp, | tmp, |
httpMethod, | httpMethod, |
cimException.getContentLanguages(), | cimException.getContentLanguages(), |
(Uint32)out.size()); |
out.size()); |
tmp << out; | tmp << out; |
| |
return tmp; | return tmp; |
|
|
| |
String XmlWriter::getNextMessageId() | String XmlWriter::getNextMessageId() |
{ | { |
char buffer[16]; |
char scratchBuffer[22]; |
sprintf(buffer, "%u", _messageIDFactory.getID()); |
Uint32 n; |
return buffer; |
const char * startP = Uint32ToString(scratchBuffer, |
|
_messageIDFactory.getID(), |
|
n); |
|
return String(startP, n); |
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |