# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1204235749 28800
# Node ID e5e14ae1282c26c3ba16976bd239c36714162700
# Parent b07d295f167fe3d66377047b3f8e5c00ea6955be
[CU] Add set_int_property() function to EO parse.
Updates from set 1 to set 2:
-Cast value in _set_int_prop()
-Add (CMPIValue *) before unsigned_val/signed_val in CMSetProperty() call
-Remove comment and fix whitespace issues in eo_util_parser.y
This function attempts to find the appropriate property value type and then sets that
property value.
This change is needed to properly parse non 64 bit integer. If the property is a uint16
value, and CMPI_uint64 is passed CMSetProperty(), the call will fail.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r b07d295f167f -r e5e14ae1282c eo_parser.c
--- a/eo_parser.c Wed Feb 27 10:39:55 2008 -0500
+++ b/eo_parser.c Thu Feb 28 13:55:49 2008 -0800
@@ -107,6 +107,68 @@ int cu_parse_embedded_instance(const cha
}
}
+static int _set_int_prop(CMPISint64 value,
+ char *prop,
+ CMPIType type,
+ CMPIInstance *inst)
+{
+ CMPIStatus s;
+ uint64_t unsigned_val = 0;
+ int64_t signed_val = 0;
+
+ switch(type) {
+ case CMPI_uint64:
+ case CMPI_uint32:
+ case CMPI_uint16:
+ case CMPI_uint8:
+ unsigned_val = (uint64_t) value;
+ s = CMSetProperty(inst,
+ prop,
+ (CMPIValue *) &(unsigned_val),
+ type);
+ break;
+ case CMPI_sint64:
+ case CMPI_sint32:
+ case CMPI_sint16:
+ case CMPI_sint8:
+ default:
+ signed_val = (int64_t) value;
+ s = CMSetProperty(inst,
+ prop,
+ (CMPIValue *) &(signed_val),
+ type);
+ }
+
+ if (s.rc == CMPI_RC_OK)
+ return 1;
+
+ return 0;
+}
+
+CMPIType set_int_prop(CMPISint64 value,
+ char *prop,
+ CMPIInstance *inst)
+{
+ if (_set_int_prop(value, prop, CMPI_uint64, inst) == 1)
+ return CMPI_uint64;
+ else if (_set_int_prop(value, prop, CMPI_uint32, inst) == 1)
+ return CMPI_uint32;
+ else if (_set_int_prop(value, prop, CMPI_uint16, inst) == 1)
+ return CMPI_uint16;
+ else if (_set_int_prop(value, prop, CMPI_uint8, inst) == 1)
+ return CMPI_uint8;
+ else if (_set_int_prop(value, prop, CMPI_sint64, inst) == 1)
+ return CMPI_sint64;
+ else if (_set_int_prop(value, prop, CMPI_sint32, inst) == 1)
+ return CMPI_sint32;
+ else if (_set_int_prop(value, prop, CMPI_sint16, inst) == 1)
+ return CMPI_sint16;
+ else
+ _set_int_prop(value, prop, CMPI_sint8, inst);
+
+ return CMPI_sint8;
+}
+
/*
* Local Variables:
* mode: C
diff -r b07d295f167f -r e5e14ae1282c eo_parser_xml.h
--- a/eo_parser_xml.h Wed Feb 27 10:39:55 2008 -0500
+++ b/eo_parser_xml.h Thu Feb 28 13:55:49 2008 -0800
@@ -27,6 +27,10 @@ int cu_parse_ei_xml(const CMPIBroker *br
const char *xml,
CMPIInstance **instance);
+CMPIType set_int_prop(CMPISint64 value,
+ char *prop,
+ CMPIInstance *inst);
+
#endif
/*
diff -r b07d295f167f -r e5e14ae1282c eo_util_parser.y
--- a/eo_util_parser.y Wed Feb 27 10:39:55 2008 -0500
+++ b/eo_util_parser.y Thu Feb 28 13:55:49 2008 -0800
@@ -10,9 +10,12 @@
%{
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include "cmpidt.h"
#include "cmpift.h"
+
+#include "eo_parser_xml.h"
/* specify prototypes to get rid of warnings */
int eo_parse_lex (void);
@@ -103,13 +106,12 @@ property: PROPERTYNAME '=' STRING ';'
| PROPERTYNAME '=' INTEGER ';'
{
- EOTRACE("propertyname = %s"
- "\ttype = CMPI_sint64\n"
- "\tvalue = %lld\n",
- $1, $3);
- unsigned long long value = $3;
- CMSetProperty(*_INSTANCE, $1, &(value), CMPI_uint64);
- free($1);
+ EOTRACE("propertyname = %s\n", $1);
+ int rc;
+ CMPIType t = set_int_prop($3, $1, *_INSTANCE);
+ EOTRACE("\ttype = %d\n"
+ "\tvalue = %lld\n", t, $3);
+ free($1);
}
| PROPERTYNAME '=' BOOLEAN ';'