
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1201551292 28800 # Node ID a6352980c902f4a0e3d60e97b4c2c9bc6c594674 # Parent 2948ecbed2674aee61a994b06468c2ce9c763bb3 [CU] Add embedded object parse functionality to std_invokemethod. 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@us.ibm.com> diff -r 2948ecbed267 -r a6352980c902 std_invokemethod.c --- a/std_invokemethod.c Tue Jan 15 12:54:04 2008 +0100 +++ b/std_invokemethod.c Mon Jan 28 12:14:52 2008 -0800 @@ -29,6 +29,154 @@ #include "std_invokemethod.h" #define STREQ(a,b) (strcmp(a, b) == 0) + +static int check_for_eo(CMPIType type, CMPIType exp_type, CMPIType *ret_type) +{ + if ((exp_type == CMPI_instance) && (type == CMPI_string)) { + *ret_type = CMPI_instance; + return 1; + } + + if ((exp_type == CMPI_instanceA) && (type == CMPI_stringA)) { + *ret_type = CMPI_instanceA; + return 1; + } + + *ret_type = -1; + return 0; +} + +static int parse_eo_inst_arg(CMPIInstance **inst, + const CMPIBroker *broker, + CMPIString *val, + const char *ns, + CMPIStatus *s) +{ + int ret; + const char *str; + + str = CMGetCharPtr(val); + + 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, + inst); + + /* cu_parse_embedded_instance() returns 0 on success */ + if ((ret != 0) || CMIsNullObject(inst)) { + CMSetStatus(s, CMPI_RC_ERR_FAILED); + CU_DEBUG("Unable to parse embedded object"); + return 0; + } + + return 1; +} + +static int parse_eo_array(CMPIArray **array, + const CMPIBroker *broker, + CMPIData data, + const char *ns, + int count, + CMPIStatus *s) +{ + int i; + int ret; + + if (CMIsNullValue(data) || CMIsNullObject(data.value.array)) { + CMSetStatus(s, CMPI_RC_ERR_INVALID_PARAMETER); + CU_DEBUG("Method parameter is NULL"); + return 0; + } + + for (i = 0; i < count; i++) { + CMPIData item; + CMPIInstance *inst; + + item = CMGetArrayElementAt(data.value.array, i, NULL); + + ret = parse_eo_inst_arg(&inst, + broker, + item.value.string, + ns, + s); + + if (ret != 1) { + CU_DEBUG("Parsing argument type %d failed", item.type); + return 0; + } + + CMSetArrayElementAt(*array, i, + (CMPIValue *)&inst, + CMPI_instance); + } + + return 1; +} + +static int parse_eo_param(CMPIArgs **args, + const CMPIBroker *broker, + CMPIData data, + CMPIType type, + const char *arg_name, + const char *ns, + CMPIStatus *s) +{ + CMPIArray *new_array; + CMPIInstance *inst; + int ret; + int count; + + if (type == CMPI_instance) { + ret = parse_eo_inst_arg(&inst, + broker, + data.value.string, + ns, + s); + + if (ret != 1) + return 0; + + *s = CMAddArg(*args, + arg_name, + &(inst), + CMPI_instance); + } else if (type == CMPI_instanceA) { + count = CMGetArrayCount(data.value.array, NULL); + + new_array = CMNewArray(broker, count, CMPI_instance, s); + + ret = parse_eo_array(&new_array, + broker, + data, + ns, + count, + s); + if (ret != 1) + return 0; + + *s = CMAddArg(*args, + arg_name, + &(new_array), + CMPI_instanceA); + } else { + CMSetStatus(s, CMPI_RC_ERR_FAILED); + CU_DEBUG("Unable to parse argument type %d", type); + return 0; + } + + 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,