# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1201635822 28800
# Node ID fbf396e9c8c2328b646c1d7e6b85fb73d50eac93
# Parent 2948ecbed2674aee61a994b06468c2ce9c763bb3
[CU] Add embedded object parse functionality to std_invokemethod.
Updated from set 3 to 4:
-Allocate CMPIArray in parse_eo_array().
Updates from set 2 to set 3:
-Fixed pointer silliness - changed CMPIArgs param in parse_eo_param() to a single
pointer.
Updates from set 1 to set 2:
-Change return type check_for_eo() to CMPIType and return CMPI_null incase of error.
-Updated parse_eo_array() to take an array arg instead of a CMPIData arg.
-Fixed argument lists of parse_eo_inst_arg() and parse_eo_array() so that the arg order
is similar between the two.
-parse_eo_param() - made the AddArg call generic enough to work with both CMPI_instance
and CMPI_instanceA
This adds 3 functions:
-check_for_eo(): Determine whether the argument is an embedded object that needs to be
parsed.
-parse_eo_inst_arg(): Calls cu_parse_embedded_instance() to parse the arg.
-parse_eo_array(): Calls parse_eo_inst_arg() for each item in the arry.
-parse_eo_param(): If argument is an array, walks through the array calling
parse_eo_inst_arg(), otherwise call parse_eo_inst_arg() directly.
parse_eo_inst_arg() and parse_eo_param() are based on the EO parsing pieces in
Virt_VirtualSystemManagementService.
The style of these changes matches the style in the rest of the file - return 0 for
failure, return 1 for success.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 2948ecbed267 -r fbf396e9c8c2 std_invokemethod.c
--- a/std_invokemethod.c Tue Jan 15 12:54:04 2008 +0100
+++ b/std_invokemethod.c Tue Jan 29 11:43:42 2008 -0800
@@ -29,6 +29,144 @@
#include "std_invokemethod.h"
#define STREQ(a,b) (strcmp(a, b) == 0)
+
+static CMPIType check_for_eo(CMPIType type, CMPIType exp_type)
+{
+ if ((exp_type == CMPI_instance) && (type == CMPI_string)) {
+ return CMPI_instance;
+ }
+
+ if ((exp_type == CMPI_instanceA) && (type == CMPI_stringA)) {
+ return CMPI_instanceA;
+ }
+
+ return CMPI_null;
+}
+
+static int parse_eo_inst_arg(CMPIString *string_in,
+ CMPIInstance **instance_out,
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *s)
+{
+ int ret;
+ const char *str;
+
+ str = CMGetCharPtr(string_in);
+
+ if (str == NULL) {
+ CMSetStatus(s, CMPI_RC_ERR_INVALID_PARAMETER);
+ CU_DEBUG("Method parameter value is NULL");
+ return 0;
+ }
+
+ ret = cu_parse_embedded_instance(str,
+ broker,
+ ns,
+ instance_out);
+
+ /* cu_parse_embedded_instance() returns 0 on success */
+ if ((ret != 0) || CMIsNullObject(instance_out)) {
+ CMSetStatus(s, CMPI_RC_ERR_FAILED);
+ CU_DEBUG("Unable to parse embedded object");
+ return 0;
+ }
+
+ return 1;
+}
+
+static int parse_eo_array(CMPIArray *strings_in,
+ CMPIArray **instances_out,
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *s)
+{
+ int i;
+ int ret;
+ int count;
+
+ if (CMIsNullObject(strings_in)) {
+ CMSetStatus(s, CMPI_RC_ERR_INVALID_PARAMETER);
+ CU_DEBUG("Method parameter is NULL");
+ return 0;
+ }
+
+ count = CMGetArrayCount(strings_in, NULL);
+
+ *instances_out = CMNewArray(broker,
+ count,
+ CMPI_instance,
+ s);
+
+ for (i = 0; i < count; i++) {
+ CMPIData item;
+ CMPIInstance *inst;
+
+ item = CMGetArrayElementAt(strings_in, i, NULL);
+
+ ret = parse_eo_inst_arg(item.value.string,
+ &inst,
+ broker,
+ ns,
+ s);
+
+ if (ret != 1) {
+ CU_DEBUG("Parsing argument type %d failed",
item.type);
+ return 0;
+ }
+
+ CMSetArrayElementAt(*instances_out, i,
+ (CMPIValue *)&inst,
+ CMPI_instance);
+ }
+
+ return 1;
+}
+
+static int parse_eo_param(CMPIArgs *args,
+ CMPIData data,
+ CMPIType type,
+ const char *arg_name,
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *s)
+{
+ CMPIData newdata;
+ int ret = 0;
+
+ if (type == CMPI_instance) {
+ ret = parse_eo_inst_arg(data.value.string,
+ &newdata.value.inst,
+ broker,
+ ns,
+ s);
+ } else if (type == CMPI_instanceA) {
+ ret = parse_eo_array(data.value.array,
+ &newdata.value.array,
+ broker,
+ ns,
+ s);
+ } else {
+ CMSetStatus(s, CMPI_RC_ERR_FAILED);
+ CU_DEBUG("Unable to parse argument type %d", type);
+ }
+
+ if (ret != 1)
+ return 0;
+
+
+ *s = CMAddArg(args,
+ arg_name,
+ &(newdata.value),
+ type);
+
+ if (s->rc != CMPI_RC_OK) {
+ CU_DEBUG("Unable to update method argument");
+ return 0;
+ }
+
+ return 1;
+}
static int validate_arg_type(struct method_arg *arg,
const CMPIArgs *args,