[PATCH 0 of 2] RegisteredProfile adopt common look and feel of interfaces and adopt interface to ECTP

This patch set adopts the common look and feel of the instance provider to RegisteredProfile. The changes are then adopted to ECTP. This fixes ECTP's validation of the client submitted object path.

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1205412087 -3600 # Node ID c54f01516458be69a914427668857951fb94e278 # Parent b739fc9b13320e07a39f3932396c8411c2d4ad75 RegisteredProfile: adopt common look and feel of interfaces Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r b739fc9b1332 -r c54f01516458 src/Virt_RegisteredProfile.c --- a/src/Virt_RegisteredProfile.c Tue Mar 11 13:28:04 2008 -0700 +++ b/src/Virt_RegisteredProfile.c Thu Mar 13 13:41:27 2008 +0100 @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2007 + * Copyright IBM Corp. 2007, 2008 * * Authors: * Dan Smith <danms@us.ibm.com> @@ -40,19 +40,21 @@ const static CMPIBroker *_BROKER; -CMPIInstance *reg_prof_instance(const CMPIBroker *broker, - const char *namespace, - const char **properties, - virConnectPtr conn, - struct reg_prof *profile) +CMPIStatus get_profile(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char **properties, + const char* interop_namespace, + const char* pfx, + struct reg_prof *profile, + CMPIInstance **_inst) { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *instance = NULL; - + instance = get_typed_instance(broker, - pfx_from_conn(conn), + pfx, "RegisteredProfile", - namespace); + interop_namespace); if (instance == NULL) { cu_statusf(broker, &s, @@ -63,10 +65,7 @@ CMPIInstance *reg_prof_instance(const CM if (properties) { const char *keys[] = {"InstanceID", NULL}; - s = CMSetPropertyFilter(instance, properties, keys); - if (s.rc != CMPI_RC_OK) { - goto out; - } + CMSetPropertyFilter(instance, properties, keys); } CMSetProperty(instance, "InstanceID", @@ -81,41 +80,122 @@ CMPIInstance *reg_prof_instance(const CM CMSetProperty(instance, "RegisteredVersion", (CMPIValue *)profile->reg_version, CMPI_chars); + *_inst = instance; + out: - return instance; + + return s; } -static CMPIStatus enum_profs(const CMPIObjectPath *ref, - const CMPIResult *results, - const char **properties, - bool names_only) +CMPIStatus get_profile_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + const char **properties, + CMPIInstance **_inst) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *instance; + virConnectPtr conn = NULL; + int i; + bool found = false; + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); + if (conn == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance"); + goto out; + } + + for (i = 0; profiles[i] != NULL; i++) { + if(STREQ(name, profiles[i]->reg_id)) { + CMPIInstance *inst = NULL; + + s = get_profile(broker, + reference, + properties, + CIM_INTEROP_NS, + pfx_from_conn(conn), + profiles[i], + &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + found = true; + break; + } + } + + if (found == false) + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + + out: + virConnectClose(conn); + + return s; +} + +CMPIStatus get_profile_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char **properties, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + const char *name = NULL; + + if (cu_get_str_path(reference, "InstanceID", &name) != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No InstanceID specified"); + goto out; + } + + s = get_profile_by_name(broker, reference, name, properties, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + s = cu_validate_ref(broker, reference, inst); + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + + out: + return s; +} + +CMPIStatus enum_profiles(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char **properties, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn = NULL; int i; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + conn = connect_by_classname(broker, CLASSNAME(reference), &s); if (conn == NULL) - return s; + goto out; for (i = 0; profiles[i] != NULL; i++) { - instance = reg_prof_instance(_BROKER, - NAMESPACE(ref), - properties, - conn, - profiles[i]); - if (instance == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Can't create profile instance"); - goto out; - } + CMPIInstance *inst = NULL; - if (names_only) - cu_return_instance_name(results, instance); - else - CMReturnInstance(results, instance); + s = get_profile(broker, + reference, + properties, + CIM_INTEROP_NS, + pfx_from_conn(conn), + profiles[i], + &inst); + + if (s.rc != CMPI_RC_OK) + continue; + + inst_list_add(list, inst); } out: @@ -124,50 +204,27 @@ static CMPIStatus enum_profs(const CMPIO return s; } -static CMPIStatus get_prof(const CMPIObjectPath *ref, - const CMPIResult *results, - const char **properties) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *instance = NULL; - virConnectPtr conn = NULL; - const char* id; - int i; +static CMPIStatus return_enum_profiles(const CMPIObjectPath *reference, + const CMPIResult *results, + const char **properties, + const bool names_only) +{ + struct inst_list list; + CMPIStatus s; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such instance"); + inst_list_init(&list); + + s = enum_profiles(_BROKER, reference, properties, &list); + if (s.rc != CMPI_RC_OK) goto out; - } - if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No InstanceID specified"); - goto out; - } + if (names_only) + cu_return_instance_names(results, &list); + else + cu_return_instances(results, &list); - for (i = 0; profiles[i] != NULL; i++) { - if(STREQ(id, profiles[i]->reg_id)) { - instance = reg_prof_instance(_BROKER, - NAMESPACE(ref), - properties, - conn, - profiles[i]); - break; - } - } - - if(instance) - CMReturnInstance(results, instance); - else - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_NOT_FOUND, - "Profile instance not found"); out: - virConnectClose(conn); + inst_list_free(&list); return s; } @@ -177,7 +234,7 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return enum_profs(reference, results, NULL, true); + return return_enum_profiles(reference, results, NULL, true); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -186,7 +243,7 @@ static CMPIStatus EnumInstances(CMPIInst const CMPIObjectPath *reference, const char **properties) { - return enum_profs(reference, results, properties, false); + return return_enum_profiles(reference, results, properties, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, @@ -195,7 +252,17 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - return get_prof(reference, results, properties); + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + + s = get_profile_by_ref(_BROKER, reference, properties, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + CMReturnInstance(results, inst); + + out: + return s; } DEFAULT_CI(); diff -r b739fc9b1332 -r c54f01516458 src/Virt_RegisteredProfile.h --- a/src/Virt_RegisteredProfile.h Tue Mar 11 13:28:04 2008 -0700 +++ b/src/Virt_RegisteredProfile.h Thu Mar 13 13:41:27 2008 +0100 @@ -1,5 +1,5 @@ /* - * Copyright IBM Corp. 2007 + * Copyright IBM Corp. 2007, 2008 * * Authors: * Heidi Eckhart <heidieck@linux.vnet.ibm.com> @@ -21,11 +21,29 @@ #ifndef __VIRT_REGISTERED_PROFILE_H #define __VIRT_REGISTERED_PROFILE_H -CMPIInstance *reg_prof_instance(const CMPIBroker *broker, - const char *namespace, - const char **properties, - virConnectPtr conn, - struct reg_prof *profile); +CMPIStatus enum_profiles(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char **properties, + struct inst_list *list); + +CMPIStatus get_profile(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char **properties, + const char* interop_namespace, + const char* pfx, + struct reg_prof *profile, + CMPIInstance **_inst); + +CMPIStatus get_profile_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + const char **properties, + CMPIInstance **_inst); + +CMPIStatus get_profile_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char **properties, + CMPIInstance **_inst); #endif diff -r b739fc9b1332 -r c54f01516458 src/profiles.h --- a/src/profiles.h Tue Mar 11 13:28:04 2008 -0700 +++ b/src/profiles.h Thu Mar 13 13:41:27 2008 +0100 @@ -1,8 +1,9 @@ /* - * Copyright IBM Corp. 2007 + * Copyright IBM Corp. 2007, 2008 * * Authors: * Jay Gagnon <grendel@linux.vnet.ibm.com> + * Heidi Eckhart <heidieck@linux.vnet.ibm.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,6 +19,10 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Interop Namespace */ +#define CIM_INTEROP_NS "root/interop" + struct reg_prof { uint16_t reg_org; // Valid: 1 = Other, 2 = DMTF char *reg_id; @@ -26,7 +31,7 @@ struct reg_prof { int ad_types; char *other_reg_org; char *ad_type_descriptions; - char *provider_name; + char *scoping_class; }; struct reg_prof SystemVirtualization = { @@ -34,7 +39,7 @@ struct reg_prof SystemVirtualization = { .reg_id = "CIM:DSP1042-SystemVirtualization-1.0.0", .reg_name = "System Virtualization", .reg_version = "1.0.0", - .provider_name = "HostSystem" + .scoping_class = "HostSystem" }; struct reg_prof VirtualSystem = { @@ -42,7 +47,7 @@ struct reg_prof VirtualSystem = { .reg_id = "CIM:DSP1057-VirtualSystem-1.0.0a", .reg_name = "Virtual System Profile", .reg_version = "1.0.0a", - .provider_name = "ComputerSystem" + .scoping_class = "ComputerSystem" };

HE> +CMPIStatus get_profile(const CMPIBroker *broker, HE> + const CMPIObjectPath *reference, HE> + const char **properties, HE> + const char* interop_namespace, HE> + const char* pfx, HE> + struct reg_prof *profile, HE> + CMPIInstance **_inst) This is a really long function signature. You seem to call it with a constant for "interop_namespace". Is there any reason to keep it variable, instead of just assuming the constant inside the function? HE> CMPIStatus s = {CMPI_RC_OK, NULL}; HE> CMPIInstance *instance = NULL; HE> - HE> + You add whitespace here. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
HE> +CMPIStatus get_profile(const CMPIBroker *broker, HE> + const CMPIObjectPath *reference, HE> + const char **properties, HE> + const char* interop_namespace, HE> + const char* pfx, HE> + struct reg_prof *profile, HE> + CMPIInstance **_inst)
This is a really long function signature. You seem to call it with a constant for "interop_namespace". Is there any reason to keep it variable, instead of just assuming the constant inside the function?
As this is only a preparation for the case that "who ever" would force us to also work with Pegasus' root/PG_InterOp namespace ... what would definitely mean, that we had to update the provider anyway ... I'm also fine with removing this currently not-used-future-outlook parameter.
HE> CMPIStatus s = {CMPI_RC_OK, NULL}; HE> CMPIInstance *instance = NULL; HE> - HE> +
You add whitespace here.
Oops ... will fix it -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1205412134 -3600 # Node ID 32a472f243e4f4a94e5c79a1f7393f1764e5cba8 # Parent c54f01516458be69a914427668857951fb94e278 ECTP: adopt interface changes of RegisteredProfile wbemain -ac CIM_ElementConformsToProfile 'http://localhost/root/virt:KVM_HostSystem.CreationClassName="KVM_HostSystem",Name="wrong"' is returning localhost:5988/root/virt:KVM_RegisteredProfile.InstanceID="CIM:DSP1042-SystemVirtualization-1.0.0" instead of NOT_FOUND Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r c54f01516458 -r 32a472f243e4 src/Virt_ElementConformsToProfile.c --- a/src/Virt_ElementConformsToProfile.c Thu Mar 13 13:41:27 2008 +0100 +++ b/src/Virt_ElementConformsToProfile.c Thu Mar 13 13:42:14 2008 +0100 @@ -60,7 +60,7 @@ static CMPIStatus elem_instances(const C char *classname; classname = get_typed_class(pfx_from_conn(conn), - profile->provider_name); + profile->scoping_class); if (classname == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, @@ -72,7 +72,7 @@ static CMPIStatus elem_instances(const C if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) goto out; - en = CBEnumInstances(_BROKER, info->context , op, NULL, &s); + en = CBEnumInstances(_BROKER, info->context , op, info->properties, &s); if (en == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, @@ -103,12 +103,17 @@ static CMPIStatus prof_to_elem(const CMP struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; virConnectPtr conn = NULL; const char *id; int i; if (!match_hypervisor_prefix(ref, info)) return s; + + s = get_profile_by_ref(_BROKER, ref, info->properties, &instance); + if (s.rc != CMPI_RC_OK) + goto out; conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); if (conn == NULL) @@ -122,11 +127,12 @@ static CMPIStatus prof_to_elem(const CMP } for (i = 0; profiles[i] != NULL; i++) { - if (STREQ(id, profiles[i]->reg_id)) { - s = elem_instances(ref, info, list, - profiles[i], conn); - if ((s.rc != CMPI_RC_OK)) - goto out; + if (STREQC(id, profiles[i]->reg_id)) { + s = elem_instances(ref, + info, + list, + profiles[i], + conn); break; } } @@ -142,13 +148,20 @@ static CMPIStatus elem_to_prof(const CMP struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *instance; + CMPIInstance *instance = NULL; virConnectPtr conn = NULL; char *classname; - struct reg_prof *candidate; int i; if (!match_hypervisor_prefix(ref, info)) + return s; + + instance = CBGetInstance(_BROKER, + info->context, + ref, + NULL, + &s); + if (s.rc != CMPI_RC_OK) return s; conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); @@ -164,22 +177,19 @@ static CMPIStatus elem_to_prof(const CMP } for (i = 0; profiles[i] != NULL; i++) { - candidate = profiles[i]; - if (!STREQC(candidate->provider_name, classname)) + if (!STREQC(profiles[i]->scoping_class, classname)) continue; - instance = reg_prof_instance(_BROKER, - "root/interop", - NULL, - conn, - candidate); - if (instance == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Can't create profile instance"); + s = get_profile(_BROKER, + ref, + info->properties, + CIM_INTEROP_NS, + pfx_from_conn(conn), + profiles[i], + &instance); + if (s.rc != CMPI_RC_OK) goto out; - } - + inst_list_add(list, instance); }
participants (2)
-
Dan Smith
-
Heidi Eckhart