version 1.133, 2006/01/10 19:41:15
|
version 1.141, 2006/08/22 18:30:48
|
|
|
//%2005//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development | // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. | // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; | // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
// EMC Corporation; VERITAS Software Corporation; The Open Group. | // EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
#include "Buffer.h" | #include "Buffer.h" |
#include "StrLit.h" | #include "StrLit.h" |
#include "LanguageParser.h" | #include "LanguageParser.h" |
|
#include "IDFactory.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
static const int _isSpecialChar7[] = | static const int _isSpecialChar7[] = |
{ | { |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0, | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0, |
0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, |
0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0, |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, |
}; | }; |
|
|
void XmlWriter::appendSpecial(Buffer& out, const String& str) | void XmlWriter::appendSpecial(Buffer& out, const String& str) |
{ | { |
const Uint16* p = (const Uint16*)str.getChar16Data(); | const Uint16* p = (const Uint16*)str.getChar16Data(); |
size_t n = str.size(); |
// prevCharIsSpace is true when the last character written to the Buffer |
|
// is a space character (not a character reference). |
// Handle leading ASCII 7 characers in these next two loops (use unrolling). |
Boolean prevCharIsSpace = false; |
|
|
while (n >= 8) |
// If the first character is a space, use a character reference to avoid |
|
// space compression. |
|
if (*p == ' ') |
{ | { |
// The following condition is equivalent to this: |
out.append(STRLIT_ARGS(" ")); |
// (p[0] < 128 && p[1] < 128 && p[2] < 128 && p[3] < 128 && |
p++; |
// p[4] < 128 && p[5] < 128 && p[6] < 128 && p[7] < 128) |
} |
| |
if (((p[0]|p[1]|p[2]|p[3]|p[4]|p[5]|p[6]|p[7]) & 0xFF80) == 0) |
Uint16 c; |
|
while ((c = *p++) != 0) |
{ | { |
// Note: "|" is faster than "||" and achieves the same effect |
if (c < 128) |
// since p[i] is either 0 or 1. |
{ |
|
if (_isSpecialChar7[c]) |
if (_isSpecialChar7[p[0]] | _isSpecialChar7[p[1]] | |
|
_isSpecialChar7[p[2]] | _isSpecialChar7[p[3]] | |
|
_isSpecialChar7[p[4]] | _isSpecialChar7[p[5]] | |
|
_isSpecialChar7[p[6]] | _isSpecialChar7[p[7]]) |
|
{ | { |
// Rare case. |
// Write the character reference for the special character |
_appendSpecialChar7(out, p[0]); |
out.append( |
_appendSpecialChar7(out, p[1]); |
_specialChars[int(c)].str, _specialChars[int(c)].size); |
_appendSpecialChar7(out, p[2]); |
prevCharIsSpace = false; |
_appendSpecialChar7(out, p[3]); |
} |
_appendSpecialChar7(out, p[4]); |
else if (prevCharIsSpace && (c == ' ')) |
_appendSpecialChar7(out, p[5]); |
{ |
_appendSpecialChar7(out, p[6]); |
// Write the character reference for the space character, to |
_appendSpecialChar7(out, p[7]); |
// avoid compression |
|
out.append(STRLIT_ARGS(" ")); |
|
prevCharIsSpace = false; |
} | } |
else | else |
{ | { |
// Common case. |
out.append(c); |
out.append(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); |
prevCharIsSpace = (c == ' '); |
} | } |
p += 8; |
|
n -= 8; |
|
} | } |
else | else |
break; |
|
} |
|
|
|
while (n >= 4) |
|
{ | { |
// The following condition is equivalent to this: |
// Handle UTF8 case |
// (p[0] < 128 && p[1] < 128 && p[2] < 128 && p[3] < 128) |
|
| |
if (((p[0]|p[1]|p[2]|p[3]) & 0xFF80) == 0) |
if ((((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
{ |
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) && |
if (_isSpecialChar7[p[0]] | _isSpecialChar7[p[1]] | |
*p) |
_isSpecialChar7[p[2]] | _isSpecialChar7[p[3]]) |
|
{ | { |
// Rare case: |
_xmlWritter_appendSurrogatePair(out, c, *p++); |
_appendSpecialChar7(out, p[0]); |
|
_appendSpecialChar7(out, p[1]); |
|
_appendSpecialChar7(out, p[2]); |
|
_appendSpecialChar7(out, p[3]); |
|
} | } |
else | else |
{ | { |
// Common case: |
_xmlWritter_appendChar(out, c); |
out.append(p[0], p[1], p[2], p[3]); |
|
} | } |
| |
p += 4; |
prevCharIsSpace = false; |
n -= 4; |
|
} | } |
else |
|
break; |
|
} | } |
| |
// Process remaining characters. A UTF8 character must have been |
// If the last character is a space, use a character reference to avoid |
// encountered or this would have never been reached. |
// space compression. |
|
if (prevCharIsSpace) |
while (n--) |
|
{ |
|
Uint16 c = *p++; |
|
|
|
// Special processing for UTF8 case: |
|
|
|
if (c < 128) |
|
{ | { |
_appendSpecialChar7(out, c); |
out.remove(out.size() - 1); |
continue; |
out.append(STRLIT_ARGS(" ")); |
} |
|
|
|
// Hanlde UTF8 case (if reached). |
|
|
|
if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
|
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) |
|
{ |
|
Char16 highSurrogate = p[-1]; |
|
Char16 lowSurrogate = p[0]; |
|
p++; |
|
n--; |
|
|
|
_xmlWritter_appendSurrogatePair( |
|
out, Uint16(highSurrogate),Uint16(lowSurrogate)); |
|
} |
|
else |
|
{ |
|
_xmlWritter_appendSpecialChar(out, c); |
|
} |
|
} | } |
} | } |
| |
|
|
0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1, | 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1, |
}; | }; |
| |
|
// Perform the necessary URI encoding of characters in HTTP header values. |
|
// This is required by the HTTP/1.1 specification and the CIM/HTTP |
|
// Specification (section 3.3.2). |
static void _xmlWritter_encodeURIChar(String& outString, Sint8 char8) | static void _xmlWritter_encodeURIChar(String& outString, Sint8 char8) |
{ | { |
Uint8 c = (Uint8)char8; | Uint8 c = (Uint8)char8; |
|
|
| |
char* nameSpaceCopy = strdup(nameSpace.getString().getCString()); | char* nameSpaceCopy = strdup(nameSpace.getString().getCString()); |
| |
#if !defined(PEGASUS_COMPILER_MSVC) |
#if !defined(PEGASUS_COMPILER_MSVC) && !defined(PEGASUS_OS_ZOS) |
char *last; | char *last; |
for (const char* p = strtok_r(nameSpaceCopy, "/", &last); p; | for (const char* p = strtok_r(nameSpaceCopy, "/", &last); p; |
p = strtok_r(NULL, "/", &last)) | p = strtok_r(NULL, "/", &last)) |
|
|
| |
inline void _xmlWritter_appendValue(Buffer& out, const CIMDateTime& x) | inline void _xmlWritter_appendValue(Buffer& out, const CIMDateTime& x) |
{ | { |
out << x.toString(); //ATTN: append() method? |
// It is not necessary to use XmlWriter::appendSpecial(), because |
|
// CIMDateTime values do not contain special characters. |
|
out << x.toString(); |
} | } |
| |
inline void _xmlWritter_appendValue(Buffer& out, const CIMObjectPath& x) | inline void _xmlWritter_appendValue(Buffer& out, const CIMObjectPath& x) |
|
|
_xmlWritter_appendValueArray(out, a.getData(), a.size()); | _xmlWritter_appendValueArray(out, a.getData(), a.size()); |
break; | break; |
} | } |
|
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
case CIMTYPE_INSTANCE: |
|
{ |
|
Array<CIMInstance> a; |
|
value.get(a); |
|
_xmlWritter_appendValueArray(out, a.getData(), a.size()); |
|
break; |
|
} |
|
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
default: | default: |
PEGASUS_ASSERT(false); | PEGASUS_ASSERT(false); |
} | } |
|
|
_xmlWritter_appendValue(out, v); | _xmlWritter_appendValue(out, v); |
break; | break; |
} | } |
|
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
case CIMTYPE_INSTANCE: |
|
{ |
|
CIMInstance v; |
|
value.get(v); |
|
_xmlWritter_appendValue(out, v); |
|
break; |
|
} |
|
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
default: | default: |
PEGASUS_ASSERT(false); | PEGASUS_ASSERT(false); |
} | } |
|
|
{ | { |
char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' }; | char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' }; |
out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n"); | out << STRLIT("HTTP/1.1 " HTTP_STATUS_OK "\r\n"); |
STAT_SERVERTIME |
|
|
#ifndef PEGASUS_DISABLE_PERFINST |
|
if (StatisticalData::current()->copyGSD) |
|
{ |
|
out << STRLIT("WBEMServerResponseTime: ") << |
|
CIMValue(serverResponseTime).toString() << STRLIT("\r\n"); |
|
} |
|
#endif |
|
|
out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n"); | out << STRLIT("Content-Type: application/xml; charset=\"utf-8\"\r\n"); |
OUTPUT_CONTENTLENGTH; | OUTPUT_CONTENTLENGTH; |
| |
|
|
} | } |
if (errorDetail != String::EMPTY) | if (errorDetail != String::EMPTY) |
{ | { |
// ATTN-RK-P3-20020404: It is critical that this text not contain '\n' |
|
// ATTN-RK-P3-20020404: Need to encode this value properly. (See |
|
// CIM/HTTP Specification section 3.3.2 |
|
out << STRLIT(PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": ") | out << STRLIT(PEGASUS_HTTPHEADERTAG_ERRORDETAIL ": ") |
<< encodeURICharacters(errorDetail) << STRLIT("\r\n"); | << encodeURICharacters(errorDetail) << STRLIT("\r\n"); |
} | } |
|
|
out << STRLIT(" PARAMTYPE=\"string\""); | out << STRLIT(" PARAMTYPE=\"string\""); |
out << STRLIT(" EMBEDDEDOBJECT=\"object\""); | out << STRLIT(" EMBEDDEDOBJECT=\"object\""); |
} | } |
|
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
else if (type == CIMTYPE_INSTANCE) |
|
{ |
|
out << STRLIT(" PARAMTYPE=\"string\""); |
|
out << STRLIT(" EMBEDDEDOBJECT=\"instance\""); |
|
} |
|
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
else | else |
{ | { |
out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type); | out << STRLIT(" PARAMTYPE=\"") << cimTypeToString (type); |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// appendQualifierNameIParameter() |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
void XmlWriter::appendQualifierNameIParameter( |
|
Buffer& out, |
|
const char* name, |
|
const String& qualifierName) |
|
{ |
|
// <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE |
|
// |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION |
|
// |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?> |
|
// |
|
// ATTN: notice that there is really no way to pass a qualifier name |
|
// as an IPARAMVALUE element according to the spec (look above). So we |
|
// just pass it as a class name. An answer must be obtained later. |
|
|
|
_appendIParamValueElementBegin(out, name); |
|
appendClassNameElement(out, qualifierName); |
|
_appendIParamValueElementEnd(out); |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
|
// appendClassNameIParameter() | // appendClassNameIParameter() |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
case XmlEntry::CDATA: | case XmlEntry::CDATA: |
{ | { |
_xmlWritter_indent(os, stack.size(), indentChars); | _xmlWritter_indent(os, stack.size(), indentChars); |
os << "<![CDATA[...]]>"; |
os << "<![CDATA[" << entry.text << "]]>"; |
break; | break; |
} | } |
| |
|
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
|
static IDFactory _messageIDFactory(1000); |
|
|
String XmlWriter::getNextMessageId() | String XmlWriter::getNextMessageId() |
{ | { |
// ATTN: make thread-safe: |
|
static Uint32 messageId = 1000; |
|
|
|
messageId++; |
|
|
|
if (messageId < 1000) |
|
messageId = 1001; |
|
|
|
char buffer[16]; | char buffer[16]; |
sprintf(buffer, "%d", messageId); |
sprintf(buffer, "%u", _messageIDFactory.getID()); |
return buffer; | return buffer; |
} | } |
| |