version 1.147, 2007/01/11 16:21:54
|
version 1.153.2.1, 2008/02/07 18:46:11
|
|
|
#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"); |
| |
|
|
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; |
|
|
| |
void _xmlWritter_printAttributes( | void _xmlWritter_printAttributes( |
PEGASUS_STD(ostream)& os, | PEGASUS_STD(ostream)& os, |
const XmlAttribute* attributes, |
const Array<XmlAttribute>& attributes, |
Uint32 attributeCount) | Uint32 attributeCount) |
{ | { |
for (Uint32 i = 0; i < attributeCount; i++) | for (Uint32 i = 0; i < attributeCount; i++) |
|
|
| |
os << "<?" << entry.text << " "; | os << "<?" << entry.text << " "; |
_xmlWritter_printAttributes( | _xmlWritter_printAttributes( |
os, entry.attributes, entry.attributeCount); |
os, entry.attributes, entry.attributes.size()); |
os << "?>"; | os << "?>"; |
break; | break; |
} | } |
|
|
| |
os << "<" << entry.text; | os << "<" << entry.text; |
| |
if (entry.attributeCount) |
if (entry.attributes.size()) |
os << ' '; | os << ' '; |
| |
_xmlWritter_printAttributes( | _xmlWritter_printAttributes( |
os, entry.attributes, entry.attributeCount); |
os, entry.attributes, entry.attributes.size()); |
os << ">"; | os << ">"; |
stack.push(entry.text); | stack.push(entry.text); |
break; | break; |
|
|
| |
os << "<" << entry.text << " "; | os << "<" << entry.text << " "; |
_xmlWritter_printAttributes( | _xmlWritter_printAttributes( |
os, entry.attributes, entry.attributeCount); |
os, entry.attributes, entry.attributes.size()); |
os << "/>"; | os << "/>"; |
break; | break; |
} | } |
|
|
| |
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); |
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |