version 1.90, 2003/08/02 18:59:53
|
version 1.95, 2003/08/26 20:46:28
|
|
|
#include "XmlParser.h" | #include "XmlParser.h" |
#include "Tracer.h" | #include "Tracer.h" |
#include <Pegasus/Common/StatisticalData.h> | #include <Pegasus/Common/StatisticalData.h> |
|
#include "CommonUTF.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
| |
inline void _appendChar(Array<Sint8>& out, const Char16& c) | inline void _appendChar(Array<Sint8>& out, const Char16& c) |
{ | { |
out.append(Sint8(c)); |
// We need to convert the Char16 to UTF8 then append the UTF8 |
|
// character into the array. |
|
// NOTE: The UTF8 character could be several bytes long. |
|
// WARNING: This function will put in replacement character for |
|
// all characters that have surogate pairs. |
|
Uint8 str[6]; |
|
memset(str,0x00,sizeof(str)); |
|
Uint8* charIN = (Uint8 *)&c; |
|
|
|
const Uint16 *strsrc = (Uint16 *)charIN; |
|
Uint16 *endsrc = (Uint16 *)&charIN[1]; |
|
|
|
Uint8 *strtgt = (Uint8 *)str; |
|
Uint8 *endtgt = (Uint8 *)&str[5]; |
|
|
|
UTF16toUTF8(&strsrc, |
|
endsrc, |
|
&strtgt, |
|
endtgt); |
|
|
|
out.append((Sint8 *)str,trailingBytesForUTF8[Uint32(str[0])]+1); |
} | } |
| |
inline void _appendSpecialChar(Array<Sint8>& out, const Char16& c) | inline void _appendSpecialChar(Array<Sint8>& out, const Char16& c) |
{ | { |
// ATTN-B: Only UTF-8 handled for now. |
if ( ((c < Char16(0x20)) && (c >= Char16(0x00))) || (c == Char16(0x7f)) ) |
|
|
if ( (c < Char16(0x20)) || (c == Char16(0x7f)) ) |
|
{ | { |
char charref[7]; | char charref[7]; |
sprintf(charref, "&#%u;", (Uint16)c); | sprintf(charref, "&#%u;", (Uint16)c); |
|
|
break; | break; |
| |
default: | default: |
|
{ |
|
// We need to convert the Char16 to UTF8 then append the UTF8 |
|
// character into the array. |
|
// NOTE: The UTF8 character could be several bytes long. |
|
// WARNING: This function will put in replacement character for |
|
// all characters that have surogate pairs. |
|
Uint8 str[6]; |
|
memset(str,0x00,sizeof(str)); |
|
Uint8* charIN = (Uint8 *)&c; |
|
|
|
const Uint16 *strsrc = (Uint16 *)charIN; |
|
Uint16 *endsrc = (Uint16 *)&charIN[1]; |
|
|
|
Uint8 *strtgt = (Uint8 *)str; |
|
Uint8 *endtgt = (Uint8 *)&str[5]; |
|
|
|
UTF16toUTF8(&strsrc, |
|
endsrc, |
|
&strtgt, |
|
endtgt); |
|
|
|
Uint32 number1 = trailingBytesForUTF8[Uint32(str[0])]+1; |
|
|
|
out.append((Sint8 *)str,number1); |
|
} |
|
} |
|
} |
|
} |
|
|
|
inline void _appendSpecialChar(Array<Sint8>& out, char c) |
|
{ |
|
if ( ((c < Char16(0x20)) && (c >= Char16(0x00))) || (c == Char16(0x7f)) ) |
|
{ |
|
char charref[7]; |
|
sprintf(charref, "&#%u;", (Uint8)c); |
|
out.append(charref, strlen(charref)); |
|
} |
|
else |
|
{ |
|
switch (c) |
|
{ |
|
case '&': |
|
out.append("&", 5); |
|
break; |
|
|
|
case '<': |
|
out.append("<", 4); |
|
break; |
|
|
|
case '>': |
|
out.append(">", 4); |
|
break; |
|
|
|
case '"': |
|
out.append(""", 6); |
|
break; |
|
|
|
case '\'': |
|
out.append("'", 6); |
|
break; |
|
|
|
default: |
out.append(Sint8(c)); | out.append(Sint8(c)); |
} | } |
} | } |
} | } |
| |
|
|
static inline void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c) | static inline void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c) |
{ | { |
if ( (c < Char16(0x20)) || (c == Char16(0x7f)) ) | if ( (c < Char16(0x20)) || (c == Char16(0x7f)) ) |
{ | { |
char charref[7]; | char charref[7]; |
sprintf(charref, "&#%u;", (Uint16)c); |
sprintf(charref, "&#%u;", (Uint8)c); |
os << charref; | os << charref; |
} | } |
else | else |
|
|
} | } |
} | } |
| |
|
void _appendSurrogatePair(Array<Sint8>& out, Uint16 high, Uint16 low) |
|
{ |
|
Uint8 str[6]; |
|
Uint8 charIN[5]; |
|
memset(str,0x00,sizeof(str)); |
|
memcpy(&charIN,&high,2); |
|
memcpy(&charIN[2],&low,2); |
|
const Uint16 *strsrc = (Uint16 *)charIN; |
|
Uint16 *endsrc = (Uint16 *)&charIN[3]; |
|
|
|
Uint8 *strtgt = (Uint8 *)str; |
|
Uint8 *endtgt = (Uint8 *)&str[5]; |
|
|
|
UTF16toUTF8(&strsrc, |
|
endsrc, |
|
&strtgt, |
|
endtgt); |
|
|
|
Uint32 number1 = trailingBytesForUTF8[Uint32(str[0])]+1; |
|
out.append((Sint8 *)str,number1); |
|
} |
|
|
static inline void _appendSpecial(PEGASUS_STD(ostream)& os, const char* str) | static inline void _appendSpecial(PEGASUS_STD(ostream)& os, const char* str) |
{ | { |
while (*str) | while (*str) |
|
|
{ | { |
for (Uint32 i = 0; i < str.size(); i++) | for (Uint32 i = 0; i < str.size(); i++) |
{ | { |
|
Uint16 c = str[i]; |
|
if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
|
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) |
|
{ |
|
Char16 highSurrogate = str[i]; |
|
Char16 lowSurrogate = str[++i]; |
|
|
|
_appendSurrogatePair(out, Uint16(highSurrogate),Uint16(lowSurrogate)); |
|
} |
|
else |
|
{ |
_appendChar(out, str[i]); | _appendChar(out, str[i]); |
} | } |
} | } |
|
} |
| |
void XmlWriter::append(Array<Sint8>& out, const Indentor& x) | void XmlWriter::append(Array<Sint8>& out, const Indentor& x) |
{ | { |
|
|
| |
void XmlWriter::appendSpecial(Array<Sint8>& out, char x) | void XmlWriter::appendSpecial(Array<Sint8>& out, char x) |
{ | { |
_appendSpecialChar(out, Char16(x)); |
_appendSpecialChar(out, x); |
} | } |
| |
void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str) | void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str) |
|
|
{ | { |
for (Uint32 i = 0; i < str.size(); i++) | for (Uint32 i = 0; i < str.size(); i++) |
{ | { |
|
Uint16 c = str[i]; |
|
|
|
if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
|
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) |
|
{ |
|
Char16 highSurrogate = str[i]; |
|
Char16 lowSurrogate = str[++i]; |
|
|
|
_appendSurrogatePair(out, Uint16(highSurrogate),Uint16(lowSurrogate)); |
|
} |
|
else |
|
{ |
_appendSpecialChar(out, str[i]); | _appendSpecialChar(out, str[i]); |
} | } |
} | } |
|
} |
|
|
|
// chuck start |
| |
// See http://www.ietf.org/rfc/rfc2396.txt section 2 | // See http://www.ietf.org/rfc/rfc2396.txt section 2 |
// Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ',' | // Reserved characters = ';' '/' '?' ':' '@' '&' '=' '+' '$' ',' |
|
|
// Space character = 0x20 | // Space character = 0x20 |
// Delimiters = '<' '>' '#' '%' '"' | // Delimiters = '<' '>' '#' '%' '"' |
// Unwise = '{' '}' '|' '\\' '^' '[' ']' '`' | // Unwise = '{' '}' '|' '\\' '^' '[' ']' '`' |
inline void _encodeURIChar(String& outString, Char16 char16) |
// |
|
|
|
inline void _encodeURIChar(String& outString, Sint8 char8) |
{ | { |
// ATTN: Handle non-UTF-8 character sets |
Uint8 c = (Uint8)char8; |
char c = char16 & 0x007f; |
|
| |
#ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING | #ifndef PEGASUS_DO_NOT_IMPLEMENT_URI_ENCODING |
if ( (c <= 0x20) || // Control characters + space char |
if ( ((c <= 0x20) && (c >= 0x00)) || // Control characters + space char |
( (c >= 0x22) && (c <= 0x26) ) || // '"' '#' '$' '%' '&' | ( (c >= 0x22) && (c <= 0x26) ) || // '"' '#' '$' '%' '&' |
(c == 0x2b) || // '+' | (c == 0x2b) || // '+' |
(c == 0x2c) || // ',' | (c == 0x2c) || // ',' |
|
|
( (c >= 0x5b) && (c <= 0x5e) ) || // '[' '\\' ']' '^' | ( (c >= 0x5b) && (c <= 0x5e) ) || // '[' '\\' ']' '^' |
(c == 0x60) || // '`' | (c == 0x60) || // '`' |
( (c >= 0x7b) && (c <= 0x7d) ) || // '{' '|' '}' | ( (c >= 0x7b) && (c <= 0x7d) ) || // '{' '|' '}' |
(c == 0x7f) ) // Control character |
// (c == 0x7f) ) // Control character |
|
(c >= 0x7f) ) // Control character or non US-ASCII (UTF-8) |
{ | { |
char hexencoding[4]; | char hexencoding[4]; |
| |
|
|
else | else |
#endif | #endif |
{ | { |
outString.append(c); |
outString.append((Uint16)c); |
} | } |
} | } |
| |
|
|
| |
for (Uint32 i=0; i<uriString.size(); i++) | for (Uint32 i=0; i<uriString.size(); i++) |
{ | { |
_encodeURIChar(encodedString, Char16(uriString[i])); |
_encodeURIChar(encodedString, uriString[i]); |
} | } |
| |
return encodedString; | return encodedString; |
|
|
{ | { |
String encodedString; | String encodedString; |
| |
|
/* i18n remove - did not handle surrogate pairs |
for (Uint32 i=0; i<uriString.size(); i++) | for (Uint32 i=0; i<uriString.size(); i++) |
{ | { |
_encodeURIChar(encodedString, uriString[i]); | _encodeURIChar(encodedString, uriString[i]); |
} | } |
|
*/ |
|
|
|
// See the "CIM Operations over HTTP" spec, section 3.3.2 and |
|
// 3.3.3, for the treatment of non US-ASCII (UTF-8) chars |
|
|
|
// First, convert to UTF-8 (include handling of surrogate pairs) |
|
Array<Sint8> utf8; |
|
for (Uint32 i = 0; i < uriString.size(); i++) |
|
{ |
|
Uint16 c = uriString[i]; |
|
|
|
if(((c >= FIRST_HIGH_SURROGATE) && (c <= LAST_HIGH_SURROGATE)) || |
|
((c >= FIRST_LOW_SURROGATE) && (c <= LAST_LOW_SURROGATE))) |
|
{ |
|
Char16 highSurrogate = uriString[i]; |
|
Char16 lowSurrogate = uriString[++i]; |
|
|
|
_appendSurrogatePair(utf8, Uint16(highSurrogate),Uint16(lowSurrogate)); |
|
} |
|
else |
|
{ |
|
_appendChar(utf8, uriString[i]); |
|
} |
|
} |
|
|
|
// Second, escape the non HTTP-safe chars |
|
for (Uint32 i=0; i<utf8.size(); i++) |
|
{ |
|
_encodeURIChar(encodedString, utf8[i]); |
|
} |
| |
return encodedString; | return encodedString; |
} | } |
|
|
{ | { |
out << "<LOCALNAMESPACEPATH>\n"; | out << "<LOCALNAMESPACEPATH>\n"; |
| |
char* nameSpaceCopy = strdup(nameSpace.getString().getCString()); |
char* nameSpaceCopy = strdup(nameSpace.getString().getCStringUTF8()); |
|
#if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || \ |
|
defined(PEGASUS_OS_HPUX) || \ |
|
defined(PEGASUS_OS_LINUX) |
|
char *last; |
|
for (const char* p = strtok_r(nameSpaceCopy, "/", &last); p; |
|
p = strtok_r(NULL, "/", &last)) |
|
#else |
for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/")) | for (const char* p = strtok(nameSpaceCopy, "/"); p; p = strtok(NULL, "/")) |
|
#endif |
{ | { |
out << "<NAMESPACE NAME=\"" << p << "\"/>\n"; | out << "<NAMESPACE NAME=\"" << p << "\"/>\n"; |
} | } |
|
|
// do that in client today. Permanent change is to retry until spec | // do that in client today. Permanent change is to retry until spec |
// updated. This change is temp to finish tests or until the retry | // updated. This change is temp to finish tests or until the retry |
// installed. Required because of change to wbemservices cimom | // installed. Required because of change to wbemservices cimom |
#ifdef PEGASUS_SNIA_INTEROP_TEST |
#if defined PEGASUS_SNIA_INTEROP_TEST || defined PEGASUS_FORCE_POST_METHOD |
out << "POST /cimom HTTP/1.1\r\n"; | out << "POST /cimom HTTP/1.1\r\n"; |
#else | #else |
if (httpMethod == HTTP_METHOD_M_POST) | if (httpMethod == HTTP_METHOD_M_POST) |