[PATCH 0 of 2] #4 [CU] Add EO parsing functionality to libcmpiutil.

During the validate method arguments call, ensure embedded objects have been parsed if the CIMOM hasn't done so already.

# HG changeset patch # User Kaitlin Rupert <karupert@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@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,

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1201635824 28800 # Node ID f21b78b847919e032a7c1bbc33958c242d9b30c5 # Parent fbf396e9c8c2328b646c1d7e6b85fb73d50eac93 [CU] Add parse_inst_arg() to validate_args() call in std_invokemethod. Updates from set 2 to set 3: -Fixed pointer silliness - changed CMPIArgs param in validate_arg_type() to a single pointer. Updates from set 1 to set 2: -check_for_eo() return type changed from int to CMPIType Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r fbf396e9c8c2 -r f21b78b84791 std_invokemethod.c --- a/std_invokemethod.c Tue Jan 29 11:43:42 2008 -0800 +++ b/std_invokemethod.c Tue Jan 29 11:43:44 2008 -0800 @@ -170,9 +170,14 @@ static int parse_eo_param(CMPIArgs *args static int validate_arg_type(struct method_arg *arg, const CMPIArgs *args, + const CMPIBroker *broker, + const char *ns, + CMPIArgs *new_args, CMPIStatus *s) { CMPIData argdata; + CMPIType type; + int ret; argdata = CMGetArg(args, arg->name, s); if ((s->rc != CMPI_RC_OK) || (CMIsNullValue(argdata))) { @@ -183,10 +188,34 @@ static int validate_arg_type(struct meth } if (argdata.type != arg->type) { - CMSetStatus(s, CMPI_RC_ERR_TYPE_MISMATCH); - CU_DEBUG("Method parameter `%s' type check failed", - arg->name); - return 0; + type = check_for_eo(argdata.type, arg->type); + if (type != CMPI_null) { + ret = parse_eo_param(new_args, + argdata, + type, + arg->name, + broker, + ns, + s); + + if (ret != 1) + return 0; + } else { + CMSetStatus(s, CMPI_RC_ERR_TYPE_MISMATCH); + CU_DEBUG("Method parameter `%s' type check failed", + arg->name); + return 0; + } + } else { + *s = CMAddArg(new_args, + arg->name, + &(argdata.value), + argdata.type); + + if (s->rc != CMPI_RC_OK) { + CU_DEBUG("Unable to update method argument"); + return 0; + } } CU_DEBUG("Method parameter `%s' validated type 0x%x", @@ -197,19 +226,31 @@ static int validate_arg_type(struct meth } static int validate_args(struct method_handler *h, - const CMPIArgs *args, + const CMPIArgs **args, + const CMPIObjectPath *ref, + const CMPIBroker *broker, CMPIStatus *s) { + CMPIArgs *new_args; int i; + + new_args = CMNewArgs(broker, s); for (i = 0; h->args[i].name; i++) { int ret; struct method_arg *arg = &h->args[i]; - ret = validate_arg_type(arg, args, s); + ret = validate_arg_type(arg, + *args, + broker, + NAMESPACE(ref), + new_args, + s); if (!ret) return 0; } + + *args = new_args; return 1; } @@ -244,7 +285,11 @@ CMPIStatus _std_invokemethod(CMPIMethodM goto exit; } - ret = validate_args(h, argsin, &s); + ret = validate_args(h, + &argsin, + reference, + ctx->broker, + &s); if (!ret) goto exit;

Okay, I'm happy with this set now. I'll hold off to apply it to libcu until we have a comprehensive change to VSMS to fix up all the EO parsing to match. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert