version 1.87, 2003/08/22 14:54:39
|
version 1.107, 2005/02/06 21:13:14
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2005//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// The Open Group, Tivoli Systems |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
|
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software 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 |
|
|
// (carolann_graves@hp.com) | // (carolann_graves@hp.com) |
// Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com) | // Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com) |
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) | // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <cctype> | #include <cctype> |
#include <cstdio> | #include <cstdio> |
#include <cstdlib> | #include <cstdlib> |
#if defined(PEGASUS_OS_TYPE_UNIX) |
#if defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS) |
#include <errno.h> | #include <errno.h> |
#endif | #endif |
#include "CIMName.h" | #include "CIMName.h" |
|
|
#include "CIMObject.h" | #include "CIMObject.h" |
#include "CIMParamValue.h" | #include "CIMParamValue.h" |
#include "System.h" | #include "System.h" |
|
#include "XmlConstants.h" |
#ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM | #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM |
#include "OS400ConvertChar.h" | #include "OS400ConvertChar.h" |
#endif | #endif |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
|
// testStartTagOrEmptyTag() |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::testStartTagOrEmptyTag( |
|
XmlParser& parser, |
|
XmlEntry& entry) |
|
{ |
|
if (!parser.next(entry) || |
|
(entry.type != XmlEntry::START_TAG && |
|
entry.type != XmlEntry::EMPTY_TAG)) |
|
{ |
|
parser.putBack(entry); |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
// testContentOrCData() | // testContentOrCData() |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
if (!entry.getAttributeValue("CLASSORIGIN", name)) | if (!entry.getAttributeValue("CLASSORIGIN", name)) |
return CIMName(); | return CIMName(); |
| |
// KS 200209 This may be temp but we are adding test for form |
|
// CLASSNAME = "" for Wbemservices interoperability. Returns same |
|
// as if attribute did not exist. |
|
if (name.size() == 0) |
|
return CIMName(); |
|
|
|
if (!CIMName::legal(name)) | if (!CIMName::legal(name)) |
{ | { |
// l10n | // l10n |
|
|
return true; | return true; |
} | } |
| |
inline Uint8 _hexCharToNumeric(const char c) |
inline Uint8 _xmlReader_hexCharToNumeric(const char c) |
{ | { |
Uint8 n; | Uint8 n; |
| |
|
|
} | } |
| |
// See http://www.ietf.org/rfc/rfc2396.txt section 2 | // See http://www.ietf.org/rfc/rfc2396.txt section 2 |
|
// |
|
// Also see the "CIM Operations over HTTP" spec, section 3.3.2 and |
|
// 3.3.3, for the treatment of non US-ASCII chars (UTF-8) |
String XmlReader::decodeURICharacters(String uriString) | String XmlReader::decodeURICharacters(String uriString) |
{ | { |
String decodedString; |
|
Uint32 i; | Uint32 i; |
| |
|
Array<Uint8> utf8Chars; |
|
|
for (i=0; i<uriString.size(); i++) | for (i=0; i<uriString.size(); i++) |
{ | { |
if (uriString[i] == '%') | if (uriString[i] == '%') |
|
|
| |
} | } |
| |
Uint8 digit1 = _hexCharToNumeric(char(uriString[++i])); |
Uint8 digit1 = _xmlReader_hexCharToNumeric(char(uriString[++i])); |
Uint8 digit2 = _hexCharToNumeric(char(uriString[++i])); |
Uint8 digit2 = _xmlReader_hexCharToNumeric(char(uriString[++i])); |
if ( (digit1 > 15) || (digit2 > 15) ) | if ( (digit1 > 15) || (digit2 > 15) ) |
{ | { |
// l10n | // l10n |
|
|
throw ParseError(MessageLoader::getMessage(mlParms)); | throw ParseError(MessageLoader::getMessage(mlParms)); |
} | } |
| |
// ATTN: Handle non-UTF-8 character sets |
|
Uint16 decodedChar = Uint16(digit1<<4) + Uint16(digit2); | Uint16 decodedChar = Uint16(digit1<<4) + Uint16(digit2); |
decodedString.append(Char16(decodedChar)); |
utf8Chars.append((Uint8)decodedChar); |
} | } |
else | else |
{ | { |
decodedString.append(uriString[i]); |
utf8Chars.append((Uint8)uriString[i]); |
} | } |
} | } |
| |
return decodedString; |
// If there was a string to decode... |
|
if (uriString.size() > 0) |
|
{ |
|
// Convert UTF-8 to UTF-16 and return the String |
|
utf8Chars.append('\0'); |
|
return String((char *)utf8Chars.getData()); |
|
} |
|
else |
|
{ |
|
return String(); |
|
} |
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
x = x << 4; | x = x << 4; |
| |
// Make sure we don't overflow when we add the next digit | // Make sure we don't overflow when we add the next digit |
Sint64 newDigit = Sint64(_hexCharToNumeric(*p++)); |
Sint64 newDigit = Sint64(_xmlReader_hexCharToNumeric(*p++)); |
if (PEGASUS_SINT64_MIN - x > -newDigit) | if (PEGASUS_SINT64_MIN - x > -newDigit) |
{ | { |
return false; | return false; |
|
|
x = x << 4; | x = x << 4; |
| |
// We can't overflow when we add the next digit | // We can't overflow when we add the next digit |
Uint64 newDigit = Uint64(_hexCharToNumeric(*p++)); |
Uint64 newDigit = Uint64(_xmlReader_hexCharToNumeric(*p++)); |
if (PEGASUS_UINT64_MAX - x < newDigit) | if (PEGASUS_UINT64_MAX - x < newDigit) |
{ | { |
return false; | return false; |
|
|
| |
case CIMTYPE_STRING: | case CIMTYPE_STRING: |
{ | { |
return CIMValue(String(valueString, STRING_FLAG_UTF8)); |
return CIMValue(String(valueString)); |
} | } |
| |
case CIMTYPE_CHAR16: | case CIMTYPE_CHAR16: |
{ | { |
|
|
|
// remove this test, utf-8 can be up to 6 bytes per char |
|
/* |
if (strlen(valueString) != 1) { | if (strlen(valueString) != 1) { |
|
// l10n |
|
|
|
// throw XmlSemanticError(lineNumber, "Invalid char16 value"); |
|
|
|
MessageLoaderParms mlParms("Common.XmlReader.INVALID_CHAR16_VALUE", |
|
"Invalid char16 value"); |
| |
|
throw XmlSemanticError(lineNumber, mlParms); |
|
} |
|
*/ |
|
// Converts UTF-8 to UTF-16 |
|
String tmp(valueString); |
|
if (tmp.size() != 1) |
|
{ |
// l10n | // l10n |
| |
// throw XmlSemanticError(lineNumber, "Invalid char16 value"); | // throw XmlSemanticError(lineNumber, "Invalid char16 value"); |
|
|
throw XmlSemanticError(lineNumber, mlParms); | throw XmlSemanticError(lineNumber, mlParms); |
} | } |
| |
return CIMValue(Char16(valueString[0])); |
return CIMValue(tmp[0]); |
} | } |
| |
case CIMTYPE_UINT8: | case CIMTYPE_UINT8: |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
|
// skipElement() |
|
// |
|
//------------------------------------------------------------------------------ |
|
void XmlReader::skipElement( |
|
XmlParser& parser, |
|
XmlEntry& entry) |
|
{ |
|
const char * tag_name = entry.text; |
|
|
|
if (entry.type == XmlEntry::EMPTY_TAG) |
|
{ |
|
return; |
|
} |
|
|
|
while (testStartTagOrEmptyTag(parser, entry)) |
|
{ |
|
skipElement(parser, entry); |
|
} |
|
|
|
if (testContentOrCData(parser, entry)) |
|
{ |
|
; // skip |
|
} |
|
|
|
expectEndTag(parser, tag_name); |
|
return; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
// getValueElement() | // getValueElement() |
// | // |
// <!ELEMENT VALUE (#PCDATA)> | // <!ELEMENT VALUE (#PCDATA)> |
|
|
expectEndTag(parser, "VALUE"); | expectEndTag(parser, "VALUE"); |
} | } |
| |
str = String(valueString,STRING_FLAG_UTF8); |
str = String(valueString); |
return true; | return true; |
} | } |
| |
|
|
// Get QUALIFIER element: | // Get QUALIFIER element: |
| |
XmlEntry entry; | XmlEntry entry; |
if (!testStartTag(parser, entry, "QUALIFIER")) |
if (!testStartTagOrEmptyTag(parser, entry, "QUALIFIER")) |
return false; | return false; |
| |
|
Boolean empty = entry.type == XmlEntry::EMPTY_TAG; |
|
|
// Get QUALIFIER.NAME attribute: | // Get QUALIFIER.NAME attribute: |
| |
CIMName name = getCimNameAttribute(parser.getLine(), entry, "QUALIFIER"); | CIMName name = getCimNameAttribute(parser.getLine(), entry, "QUALIFIER"); |
|
|
| |
CIMValue value; | CIMValue value; |
| |
|
if (empty) |
|
{ |
|
value.setNullValue(type, false); |
|
} |
|
else |
|
{ |
if (!getValueElement(parser, type, value) && | if (!getValueElement(parser, type, value) && |
!getValueArrayElement(parser, type, value)) | !getValueArrayElement(parser, type, value)) |
{ | { |
|
|
// Expect </QUALIFIER>: | // Expect </QUALIFIER>: |
| |
expectEndTag(parser, "QUALIFIER"); | expectEndTag(parser, "QUALIFIER"); |
|
} |
| |
// Build qualifier: | // Build qualifier: |
| |
|
|
throw XmlException(XmlException::UNCLOSED_TAGS, parser.getLine()); | throw XmlException(XmlException::UNCLOSED_TAGS, parser.getLine()); |
| |
if (entry.type == XmlEntry::CONTENT) | if (entry.type == XmlEntry::CONTENT) |
host = String(entry.text,STRING_FLAG_UTF8); |
host = String(entry.text); |
else | else |
{ | { |
parser.putBack(entry); | parser.putBack(entry); |
|
|
| |
} | } |
| |
host = String(entry.text,STRING_FLAG_UTF8); |
host = String(entry.text); |
#endif | #endif |
expectEndTag(parser, "HOST"); | expectEndTag(parser, "HOST"); |
return true; | return true; |
|
|
throw XmlException(XmlException::UNCLOSED_TAGS, parser.getLine()); | throw XmlException(XmlException::UNCLOSED_TAGS, parser.getLine()); |
| |
if (entry.type == XmlEntry::CONTENT) | if (entry.type == XmlEntry::CONTENT) |
value = String(entry.text,STRING_FLAG_UTF8); |
value = String(entry.text); |
else | else |
parser.putBack(entry); | parser.putBack(entry); |
| |
|
|
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
if (!testStartTag(parser, entry, "CLASS")) |
if (!testStartTagOrEmptyTag(parser, entry, "CLASS")) |
return false; | return false; |
| |
CIMName name = getCimNameAttribute(parser.getLine(), entry, "CLASS"); | CIMName name = getCimNameAttribute(parser.getLine(), entry, "CLASS"); |
|
|
| |
cimClass = CIMClass(name, superClass); | cimClass = CIMClass(name, superClass); |
| |
|
if(entry.type != XmlEntry::EMPTY_TAG) |
|
{ |
|
|
// Get QUALIFIER elements: | // Get QUALIFIER elements: |
| |
getQualifierElements(parser, cimClass); | getQualifierElements(parser, cimClass); |
|
|
// Get CLASS end tag: | // Get CLASS end tag: |
| |
expectEndTag(parser, "CLASS"); | expectEndTag(parser, "CLASS"); |
|
} |
| |
return true; | return true; |
} | } |
|
|
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
if (!testStartTag(parser, entry, "INSTANCE")) |
if (!testStartTagOrEmptyTag(parser, entry, "INSTANCE")) |
return false; | return false; |
| |
|
Boolean empty = entry.type == XmlEntry::EMPTY_TAG; |
|
|
String className = getClassNameAttribute( | String className = getClassNameAttribute( |
parser.getLine(), entry, "INSTANCE"); | parser.getLine(), entry, "INSTANCE"); |
| |
cimInstance = CIMInstance(className); | cimInstance = CIMInstance(className); |
| |
|
if (!empty) |
|
{ |
// Get QUALIFIER elements: | // Get QUALIFIER elements: |
|
|
getQualifierElements(parser, cimInstance); | getQualifierElements(parser, cimInstance); |
| |
// Get PROPERTY elements: | // Get PROPERTY elements: |
|
|
GetPropertyElements(parser, cimInstance); | GetPropertyElements(parser, cimInstance); |
| |
// Get INSTANCE end tag: | // Get INSTANCE end tag: |
|
|
expectEndTag(parser, "INSTANCE"); | expectEndTag(parser, "INSTANCE"); |
|
} |
| |
return true; | return true; |
} | } |
|
|
| |
Boolean XmlReader::getIMethodResponseStartTag( | Boolean XmlReader::getIMethodResponseStartTag( |
XmlParser& parser, | XmlParser& parser, |
const char*& name) |
const char*& name, |
|
Boolean& isEmptyTag) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
if (!testStartTag(parser, entry, "IMETHODRESPONSE")) |
if (!testStartTagOrEmptyTag(parser, entry, "IMETHODRESPONSE")) |
return false; | return false; |
| |
|
isEmptyTag = (entry.type == XmlEntry::EMPTY_TAG); |
|
|
// Get IMETHODRESPONSE.NAME attribute: | // Get IMETHODRESPONSE.NAME attribute: |
| |
if (!entry.getAttributeValue("NAME", name)) { | if (!entry.getAttributeValue("NAME", name)) { |
|
|
| |
Boolean XmlReader::getIParamValueTag( | Boolean XmlReader::getIParamValueTag( |
XmlParser& parser, | XmlParser& parser, |
const char*& name) |
const char*& name, |
|
Boolean& isEmptyTag) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
if (!testStartTag(parser, entry, "IPARAMVALUE")) |
if (!testStartTagOrEmptyTag(parser, entry, "IPARAMVALUE")) |
return false; | return false; |
| |
|
isEmptyTag = (entry.type == XmlEntry::EMPTY_TAG); |
|
|
// Get IPARAMVALUE.NAME attribute: | // Get IPARAMVALUE.NAME attribute: |
| |
if (!entry.getAttributeValue("NAME", name)) { | if (!entry.getAttributeValue("NAME", name)) { |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
|
// rejectNullIParamValue() |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
void XmlReader::rejectNullIParamValue( |
|
XmlParser& parser, |
|
Boolean isEmptyTag, |
|
const char* paramName) |
|
{ |
|
if (isEmptyTag) |
|
{ |
|
MessageLoaderParms mlParms("Common.XmlReader.INVALID_NULL_IPARAMVALUE", |
|
"A null value is not valid for IPARAMVALUE \"$0\".", |
|
paramName); |
|
throw XmlValidationError(parser.getLine(), mlParms); |
|
} |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
// getBooleanValueElement() | // getBooleanValueElement() |
// | // |
// Get an elements like: "<VALUE>FALSE</VALUE>" | // Get an elements like: "<VALUE>FALSE</VALUE>" |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// getErrorElement() |
// DMTF CR Pending |
// | // |
// <!ELEMENT ERROR EMPTY> |
// <!ELEMENT ERROR (INSTANCE*)> |
// <!ATTLIST ERROR | // <!ATTLIST ERROR |
// CODE CDATA #REQUIRED | // CODE CDATA #REQUIRED |
// DESCRIPTION CDATA #IMPLIED> | // DESCRIPTION CDATA #IMPLIED> |
|
|
entry.getAttributeValue("DESCRIPTION", tmpDescription); | entry.getAttributeValue("DESCRIPTION", tmpDescription); |
| |
if (!empty) | if (!empty) |
|
{ |
|
while (testStartTagOrEmptyTag(parser, entry)) |
|
{ |
|
skipElement(parser, entry); |
|
} |
|
|
expectEndTag(parser, "ERROR"); | expectEndTag(parser, "ERROR"); |
|
} |
| |
cimException = PEGASUS_CIM_EXCEPTION(CIMStatusCode(tmpCode), tmpDescription); | cimException = PEGASUS_CIM_EXCEPTION(CIMStatusCode(tmpCode), tmpDescription); |
return true; | return true; |
|
|
{ | { |
object = CIMObject(cimInstance); | object = CIMObject(cimInstance); |
} | } |
else if (!XmlReader::getClassElement(parser, cimClass)) |
else if (XmlReader::getClassElement(parser, cimClass)) |
{ | { |
object = CIMObject(cimClass); | object = CIMObject(cimClass); |
} | } |
|
|
else if (!XmlReader::getClassPathElement(parser, reference)) | else if (!XmlReader::getClassPathElement(parser, reference)) |
{ | { |
| |
// l10n |
// l10n 485 |
| |
// throw XmlValidationError(parser.getLine(), | // throw XmlValidationError(parser.getLine(), |
// "Expected INSTANCEPATH or CLASSPATH element"); | // "Expected INSTANCEPATH or CLASSPATH element"); |
| |
MessageLoaderParms mlParms("Common.XmlReader.EXPECTED_INSTANCEPATH_OR_CLASSPATH_ELEMENT", | MessageLoaderParms mlParms("Common.XmlReader.EXPECTED_INSTANCEPATH_OR_CLASSPATH_ELEMENT", |
"Expected INSTANCEPATH or CLASSPATH element", "INSTANCEPATH", "CLASSPATH"); |
"Expected INSTANCEPATH or CLASSPATH element"); |
| |
throw XmlValidationError(parser.getLine(), mlParms); | throw XmlValidationError(parser.getLine(), mlParms); |
} | } |
|
|
// throw XmlValidationError(parser.getLine(), | // throw XmlValidationError(parser.getLine(), |
// "Expected LOCALINSTANCEPATH or LOCALCLASSPATH element"); | // "Expected LOCALINSTANCEPATH or LOCALCLASSPATH element"); |
| |
MessageLoaderParms mlParms("Common.XmlReader.EXPECTED_LOCALINSTANCEPATH_OR_LOCALCLASSPATH_ELEMENT", |
//l10n updated |
"Expected LOCALINSTANCEPATH or LOCALCLASSPATH element"); |
MessageLoaderParms mlParms("Common.XmlConstants.MISSING_ELEMENT_LOCALPATH", |
|
MISSING_ELEMENT_LOCALPATH); |
| |
throw XmlValidationError(parser.getLine(), mlParms); | throw XmlValidationError(parser.getLine(), mlParms); |
| |
|
|
| |
Boolean XmlReader::getEMethodResponseStartTag( | Boolean XmlReader::getEMethodResponseStartTag( |
XmlParser& parser, | XmlParser& parser, |
const char*& name) |
const char*& name, |
|
Boolean& isEmptyTag) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
if (!testStartTag(parser, entry, "EXPMETHODRESPONSE")) |
if (!testStartTagOrEmptyTag(parser, entry, "EXPMETHODRESPONSE")) |
return false; | return false; |
| |
|
isEmptyTag = (entry.type == XmlEntry::EMPTY_TAG); |
|
|
// Get EXPMETHODRESPONSE.NAME attribute: | // Get EXPMETHODRESPONSE.NAME attribute: |
| |
| |
|
|
| |
Boolean XmlReader::getMethodResponseStartTag( | Boolean XmlReader::getMethodResponseStartTag( |
XmlParser& parser, | XmlParser& parser, |
const char*& name) |
const char*& name, |
|
Boolean& isEmptyTag) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
if (!testStartTag(parser, entry, "METHODRESPONSE")) |
if (!testStartTagOrEmptyTag(parser, entry, "METHODRESPONSE")) |
return false; | return false; |
| |
|
isEmptyTag = (entry.type == XmlEntry::EMPTY_TAG); |
|
|
// Get METHODRESPONSE.NAME attribute: | // Get METHODRESPONSE.NAME attribute: |
| |
| |
|
|
{ | { |
XmlEntry entry; | XmlEntry entry; |
const char* name; | const char* name; |
CIMType type; |
CIMType type=CIMTYPE_BOOLEAN; |
CIMValue value; | CIMValue value; |
| |
if (!testStartTagOrEmptyTag(parser, entry, "PARAMVALUE")) | if (!testStartTagOrEmptyTag(parser, entry, "PARAMVALUE")) |
|
|
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
|
|