version 1.27, 2002/02/20 23:14:19
|
version 1.39, 2002/03/20 19:13:40
|
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
// testCimStartTag() |
// getCimStartTag() |
// | // |
// <!ELEMENT CIM (MESSAGE|DECLARATION)> | // <!ELEMENT CIM (MESSAGE|DECLARATION)> |
// <!ATTRLIST CIM | // <!ATTRLIST CIM |
|
|
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
void XmlReader::testCimStartTag(XmlParser& parser) |
void XmlReader::getCimStartTag( |
|
XmlParser& parser, |
|
const char*& cimVersion, |
|
const char*& dtdVersion) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
XmlReader::expectStartTag(parser, entry, "CIM"); | XmlReader::expectStartTag(parser, entry, "CIM"); |
| |
const char* cimVersion; |
|
|
|
if (!entry.getAttributeValue("CIMVERSION", cimVersion)) | if (!entry.getAttributeValue("CIMVERSION", cimVersion)) |
throw XmlValidationError( | throw XmlValidationError( |
parser.getLine(), "missing CIM.CIMVERSION attribute"); | parser.getLine(), "missing CIM.CIMVERSION attribute"); |
| |
if (strcmp(cimVersion, "2.0") != 0) |
|
throw XmlValidationError(parser.getLine(), |
|
"CIM.CIMVERSION attribute must be \"2.0\""); |
|
|
|
const char* dtdVersion; |
|
|
|
if (!entry.getAttributeValue("DTDVERSION", dtdVersion)) | if (!entry.getAttributeValue("DTDVERSION", dtdVersion)) |
throw XmlValidationError( | throw XmlValidationError( |
parser.getLine(), "missing CIM.DTDVERSION attribute"); | parser.getLine(), "missing CIM.DTDVERSION attribute"); |
|
|
if (strcmp(dtdVersion, "2.0") != 0) |
|
throw XmlValidationError(parser.getLine(), |
|
"CIM.DTDVERSION attribute must be \"2.0\""); |
|
} | } |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
| |
const char* last = p; | const char* last = p; |
| |
|
// Build the Sint64 as a negative number, regardless of the eventual sign |
|
x = -(*first++ - '0'); |
|
|
while (first != last) | while (first != last) |
x = 10 * x + (*first++ - '0'); |
{ |
|
if (x < PEGASUS_LLONG_MIN/10) |
|
{ |
|
return false; |
|
} |
|
x = 10 * x; |
|
Sint64 newDigit = (*first++ - '0'); |
|
if (PEGASUS_LLONG_MIN - x > -newDigit) |
|
{ |
|
return false; |
|
} |
|
x = x - newDigit; |
|
} |
| |
if (negative) |
if (!negative) |
|
{ |
|
if (x == PEGASUS_LLONG_MIN) |
|
{ |
|
return false; |
|
} |
x = -x; | x = -x; |
|
} |
return true; | return true; |
} | } |
| |
|
|
// | // |
// stringToUnsignedInteger | // stringToUnsignedInteger |
// | // |
// [ "+" | "-" ] ( positiveDecimalDigit *decimalDigit | "0" ) |
// [ "+" ] ( positiveDecimalDigit *decimalDigit | "0" ) |
// | // |
// ATTN-B: handle conversion from hexadecimal. | // ATTN-B: handle conversion from hexadecimal. |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
const char* last = p; | const char* last = p; |
| |
while (first != last) | while (first != last) |
x = 10 * x + (*first++ - '0'); |
{ |
|
if (x > PEGASUS_ULLONG_MAX/10) |
|
{ |
|
return false; |
|
} |
|
x = 10 * x; |
|
Uint64 newDigit = (*first++ - '0'); |
|
if (PEGASUS_ULLONG_MAX - x < newDigit) |
|
{ |
|
return false; |
|
} |
|
x = x + newDigit; |
|
} |
| |
return true; | return true; |
} | } |
|
|
// | // |
// stringToValue() | // stringToValue() |
// | // |
// ATTN-C: note that integers are truncated without warning. What should be |
// Return: CIMValue. If the string input is zero length creates a CIMValue |
// done in this case? In C they are truncated without warning by design. |
// with value defined by the type. Else the value is inserted. |
|
// |
|
// Note that this does not set the CIMValue Null if the string is empty. |
// | // |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
|
|
{ | { |
// ATTN-B: accepting only UTF-8 for now! (affects string and char16): | // ATTN-B: accepting only UTF-8 for now! (affects string and char16): |
| |
|
// If strlen == 0, set to default value for type |
|
|
if (strlen(valueString)==0) | if (strlen(valueString)==0) |
{ | { |
switch (type) | switch (type) |
|
|
} | } |
} | } |
| |
|
// Create value per type |
switch (type) | switch (type) |
{ | { |
case CIMType::BOOLEAN: | case CIMType::BOOLEAN: |
|
|
| |
switch (type) | switch (type) |
{ | { |
case CIMType::UINT8: return CIMValue(Uint8(x)); |
case CIMType::UINT8: |
case CIMType::UINT16: return CIMValue(Uint16(x)); |
{ |
case CIMType::UINT32: return CIMValue(Uint32(x)); |
if (x >= (Uint64(1)<<8)) |
|
{ |
|
throw XmlSemanticError( |
|
lineNumber, "Uint8 value out of range"); |
|
} |
|
return CIMValue(Uint8(x)); |
|
} |
|
case CIMType::UINT16: |
|
{ |
|
if (x >= (Uint64(1)<<16)) |
|
{ |
|
throw XmlSemanticError( |
|
lineNumber, "Uint16 value out of range"); |
|
} |
|
return CIMValue(Uint16(x)); |
|
} |
|
case CIMType::UINT32: |
|
{ |
|
if (x >= (Uint64(1)<<32)) |
|
{ |
|
throw XmlSemanticError( |
|
lineNumber, "Uint32 value out of range"); |
|
} |
|
return CIMValue(Uint32(x)); |
|
} |
case CIMType::UINT64: return CIMValue(Uint64(x)); | case CIMType::UINT64: return CIMValue(Uint64(x)); |
default: break; | default: break; |
} | } |
|
|
| |
switch (type) | switch (type) |
{ | { |
case CIMType::SINT8: return CIMValue(Sint8(x)); |
case CIMType::SINT8: |
case CIMType::SINT16: return CIMValue(Sint16(x)); |
{ |
case CIMType::SINT32: return CIMValue(Sint32(x)); |
if( (x >= (Sint64(1)<<7)) || (x < (-(Sint64(1)<<7))) ) |
|
{ |
|
throw XmlSemanticError( |
|
lineNumber, "Sint8 value out of range"); |
|
} |
|
return CIMValue(Sint8(x)); |
|
} |
|
case CIMType::SINT16: |
|
{ |
|
if( (x >= (Sint64(1)<<15)) || (x < (-(Sint64(1)<<15))) ) |
|
{ |
|
throw XmlSemanticError( |
|
lineNumber, "Sint16 value out of range"); |
|
} |
|
return CIMValue(Sint16(x)); |
|
} |
|
case CIMType::SINT32: |
|
{ |
|
if( (x >= (Sint64(1)<<31)) || (x < (-(Sint64(1)<<31))) ) |
|
{ |
|
throw XmlSemanticError( |
|
lineNumber, "Sint32 value out of range"); |
|
} |
|
return CIMValue(Sint32(x)); |
|
} |
case CIMType::SINT64: return CIMValue(Sint64(x)); | case CIMType::SINT64: return CIMValue(Sint64(x)); |
default: break; | default: break; |
} | } |
|
|
if (!stringToReal(valueString, x)) | if (!stringToReal(valueString, x)) |
throw XmlSemanticError(lineNumber, "Bad real value"); | throw XmlSemanticError(lineNumber, "Bad real value"); |
| |
|
// ATTN-RK-P3-20010319: This value gets truncated. |
return CIMValue(Real32(x)); | return CIMValue(Real32(x)); |
} | } |
| |
|
|
// | // |
// <!ELEMENT VALUE (#PCDATA)> | // <!ELEMENT VALUE (#PCDATA)> |
// | // |
|
// Return: false if no value element. |
|
// |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
Boolean XmlReader::getValueElement( | Boolean XmlReader::getValueElement( |
|
|
CIMType type, | CIMType type, |
CIMValue& value) | CIMValue& value) |
{ | { |
// Get VALUE start tag: |
// Get VALUE start tag: Return false if no VALUE start Tag |
| |
XmlEntry entry; | XmlEntry entry; |
if (!testStartTagOrEmptyTag(parser, entry, "VALUE")) | if (!testStartTagOrEmptyTag(parser, entry, "VALUE")) |
|
|
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- |
// | // |
// getPropertyValue | // getPropertyValue |
// Use: Decode property value from getPropertyResponse |
// Use: Decode property value from SetProperty request and |
// Expect (ERROR|IRETURNVALUE).!ELEMENT VALUE (#PCDATA)> |
// GetProperty response. |
|
// |
|
// PropertyValue is one of: |
// | // |
// PropertyValue: |
|
// <!ELEMENT VALUE> |
|
// | // |
// <!ELEMENT VALUE.ARRAY (VALUE*)> | // <!ELEMENT VALUE.ARRAY (VALUE*)> |
// | // |
// <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME| | // <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME| |
|
// <!ELEMENT VALUE.ARRAY (VALUE*)> |
|
// |
|
// <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME| |
// INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)> | // INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)> |
// | // |
|
// <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)> |
|
// |
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- |
Boolean XmlReader::getPropertyValue( | Boolean XmlReader::getPropertyValue( |
XmlParser& parser, | XmlParser& parser, |
CIMValue& cimValue) | CIMValue& cimValue) |
{ | { |
//ATTN: Test for Element value type |
// Can not test for value type, so assume String |
CIMType type = CIMType::STRING; |
const CIMType type = CIMType::STRING; |
| |
|
// Test for VALUE element |
if (XmlReader::getValueElement(parser, type, cimValue)) | if (XmlReader::getValueElement(parser, type, cimValue)) |
{ | { |
//cout << "DEBUG xmlReader::getPropertyValue " << __LINE__ |
|
// << " CimValue = " << cimValue.toString << endl; |
|
return true; | return true; |
} | } |
| |
//Test for Element.array value |
// Test for VALUE.ARRAY element |
if(XmlReader::getValueArrayElement(parser, type, cimValue)) | if(XmlReader::getValueArrayElement(parser, type, cimValue)) |
|
{ |
return true; | return true; |
|
} |
| |
// Test for Value.reference type |
// Test for VALUE.REFERENCE element |
CIMReference reference; | CIMReference reference; |
if(XmlReader::getValueReferenceElement(parser, reference)) | if(XmlReader::getValueReferenceElement(parser, reference)) |
{ | { |
|
|
return true; | return true; |
} | } |
| |
|
// Test for VALUE.REFARRAY element |
|
if (XmlReader::getValueReferenceArrayElement(parser, cimValue)) |
|
{ |
|
return true; |
|
} |
|
|
return false; | return false; |
} | } |
| |
|
|
// | // |
// <!ELEMENT VALUE.ARRAY (VALUE*)> | // <!ELEMENT VALUE.ARRAY (VALUE*)> |
// | // |
|
// Return: Boolean. Returns false if there is no VALUE.ARRAY start element |
|
// |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
| |
Boolean XmlReader::getValueArrayElement( | Boolean XmlReader::getValueArrayElement( |
|
|
CIMType type, | CIMType type, |
CIMValue& value) | CIMValue& value) |
{ | { |
|
// Clears any values from the Array. Assumes this is array CIMValue |
value.clear(); | value.clear(); |
| |
// Get VALUE.ARRAY open tag: | // Get VALUE.ARRAY open tag: |
| |
XmlEntry entry; | XmlEntry entry; |
|
Array<const char*> stringArray; |
| |
|
// If no VALUE.ARRAY start tag, return false |
if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY")) | if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY")) |
return false; | return false; |
| |
|
//ATTN: P1 KS KSTESTNULL - Need to relook at this one. |
if (entry.type == XmlEntry::EMPTY_TAG) | if (entry.type == XmlEntry::EMPTY_TAG) |
return true; | return true; |
| |
|
if (entry.type != XmlEntry::EMPTY_TAG) |
|
{ |
// For each VALUE element: | // For each VALUE element: |
| |
Array<const char*> stringArray; |
|
|
|
while (testStartTagOrEmptyTag(parser, entry, "VALUE")) | while (testStartTagOrEmptyTag(parser, entry, "VALUE")) |
{ | { |
if (entry.type == XmlEntry::EMPTY_TAG) | if (entry.type == XmlEntry::EMPTY_TAG) |
|
|
} | } |
| |
expectEndTag(parser, "VALUE.ARRAY"); | expectEndTag(parser, "VALUE.ARRAY"); |
|
} |
| |
value = stringArrayToValue(parser.getLine(), stringArray, type); | value = stringArrayToValue(parser.getLine(), stringArray, type); |
return true; | return true; |
|
|
Boolean translatable = getCimBooleanAttribute( | Boolean translatable = getCimBooleanAttribute( |
lineNumber, entry, tagName, "TRANSLATABLE", false, false); | lineNumber, entry, tagName, "TRANSLATABLE", false, false); |
| |
Uint32 flavor = 0; |
// ATTN: KS P1 5 Mar 2002 Should this not be CIMFlavor::DEFAULTS?? |
|
//Uint32 flavor = CIMFlavor::DEFAULTS; |
|
// ATTN-RK-P1-20020307: No, Karl. If you initialize to the defaults, |
|
// you have to unset the default flavors that don't apply. The code |
|
// below only adds qualifiers. |
|
Uint32 flavor = CIMFlavor::NONE; |
| |
if (overridable) | if (overridable) |
flavor |= CIMFlavor::OVERRIDABLE; | flavor |= CIMFlavor::OVERRIDABLE; |
|
|
| |
// Get VALUE or VALUE.ARRAY element: | // Get VALUE or VALUE.ARRAY element: |
| |
|
// ATTN: KS P1 4 March 2002 - Requires either value or array element or |
|
// generates exception. Correct for spec but means no NULL values on qualifier |
|
// values. Alternative is to set NULL value and continue |
|
|
CIMValue value; | CIMValue value; |
| |
if (!getValueElement(parser, type, value) && | if (!getValueElement(parser, type, value) && |
|
|
| |
CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PROPERTY"); | CIMType type = getCimTypeAttribute(parser.getLine(), entry, "PROPERTY"); |
| |
// Create property: |
// Create property: Sets type and !isarray |
|
// ATTN: KS P1 change to use the correct constructor |
| |
CIMValue value; | CIMValue value; |
value.setNullValue(type, false); | value.setNullValue(type, false); |
|
|
| |
getQualifierElements(parser, property); | getQualifierElements(parser, property); |
| |
// Get value: |
// Get value: Insert value if getValueElement exists (returns True) |
| |
if (getValueElement(parser, type, value)) | if (getValueElement(parser, type, value)) |
property.setValue(value); | property.setValue(value); |
|
|
| |
// Create property: | // Create property: |
| |
|
// ATTN: KS P1 4 March 2002 Change to use correct constructor. |
|
// ATTN: KS P3 4 March 2002. Why create extra value. Use same one. |
|
|
CIMValue nullValue; | CIMValue nullValue; |
nullValue.setNullValue(type, true, arraySize); | nullValue.setNullValue(type, true, arraySize); |
property = CIMProperty( | property = CIMProperty( |
|
|
| |
// Get value: | // Get value: |
| |
|
// ATTN: KS P1 4 March 2002. Does not set array type into value. |
|
// ATTN: Thus, if it returns false, the CIMValue is nothing. |
CIMValue value; | CIMValue value; |
| |
if (getValueArrayElement(parser, type, value)) | if (getValueArrayElement(parser, type, value)) |
|
|
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
// | // |
|
// getValueReferenceArrayElement() |
|
// |
|
// <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)> |
|
// |
|
//------------------------------------------------------------------------------ |
|
|
|
Boolean XmlReader::getValueReferenceArrayElement( |
|
XmlParser& parser, |
|
CIMValue& value) |
|
{ |
|
XmlEntry entry; |
|
Array<CIMReference> referenceArray; |
|
CIMReference reference; |
|
|
|
value.clear(); |
|
|
|
// Get VALUE.REFARRAY open tag: |
|
|
|
if (!testStartTagOrEmptyTag(parser, entry, "VALUE.REFARRAY")) |
|
return false; |
|
|
|
if (entry.type != XmlEntry::EMPTY_TAG) |
|
{ |
|
// For each VALUE.REFERENCE element: |
|
|
|
while (getValueReferenceElement(parser, reference)) |
|
{ |
|
referenceArray.append(reference); |
|
} |
|
|
|
expectEndTag(parser, "VALUE.REFARRAY"); |
|
} |
|
|
|
value.set(referenceArray); |
|
return true; |
|
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// |
// getPropertyReferenceElement() | // getPropertyReferenceElement() |
// | // |
// <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,(VALUE.REFERENCE)?)> | // <!ELEMENT PROPERTY.REFERENCE (QUALIFIER*,(VALUE.REFERENCE)?)> |
|
|
Boolean XmlReader::getMessageStartTag( | Boolean XmlReader::getMessageStartTag( |
XmlParser& parser, | XmlParser& parser, |
String& id, | String& id, |
const char*& protocolVersion) |
String& protocolVersion) |
{ | { |
XmlEntry entry; | XmlEntry entry; |
| |
|
|
value.set(reference); | value.set(reference); |
type = CIMType::REFERENCE; | type = CIMType::REFERENCE; |
} | } |
// ATTN-RK-P2-20010219: This method does not exist. CIMValue does |
else if (XmlReader::getValueReferenceArrayElement(parser, value)) |
// not currently allow for an array of CIMReferences. |
{ |
//else if (XmlReader::getValueReferenceArrayElement(parser, value)) |
type = CIMType::REFERENCE; |
//{ |
} |
// type = CIMType::REFERENCE; |
|
//} |
|
// If type==reference but no VALUE.REFERENCE found, use null value | // If type==reference but no VALUE.REFERENCE found, use null value |
} | } |
| |
|
|
expectEndTag(parser, "PARAMVALUE"); | expectEndTag(parser, "PARAMVALUE"); |
} | } |
| |
paramValue = CIMParamValue(CIMParameter(name, type), value); |
paramValue = CIMParamValue(name, value, Boolean(type!=CIMType::NONE)); |
| |
return true; | return true; |
} | } |