[PATCH 0 of 2] #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. Diff to patch set 1: - removed namespace from get_profile() signature, as dynamic configuration is not used at the moment

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1205488933 -3600 # Node ID a16bf3b5d0b964739a92ddbba418ab02709be59b # Parent 311b85abee28e75975e4758b6bc0a5974d3de937 RegisteredProfile: adopt common look and feel of interfaces Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 311b85abee28 -r a16bf3b5d0b9 src/Virt_RegisteredProfile.c --- a/src/Virt_RegisteredProfile.c Thu Mar 13 08:06:29 2008 -0700 +++ b/src/Virt_RegisteredProfile.c Fri Mar 14 11:02:13 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,20 @@ 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* 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); + CIM_INTEROP_NS); if (instance == NULL) { cu_statusf(broker, &s, @@ -63,10 +64,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 +79,120 @@ 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, + 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, + pfx_from_conn(conn), + profiles[i], + &inst); + + if (s.rc != CMPI_RC_OK) + continue; + + inst_list_add(list, inst); } out: @@ -124,50 +201,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 +231,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 +240,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 +249,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 311b85abee28 -r a16bf3b5d0b9 src/Virt_RegisteredProfile.h --- a/src/Virt_RegisteredProfile.h Thu Mar 13 08:06:29 2008 -0700 +++ b/src/Virt_RegisteredProfile.h Fri Mar 14 11:02:13 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,28 @@ #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* 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 311b85abee28 -r a16bf3b5d0b9 src/profiles.h --- a/src/profiles.h Thu Mar 13 08:06:29 2008 -0700 +++ b/src/profiles.h Fri Mar 14 11:02:13 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" };

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1205488995 -3600 # Node ID 59f38ff0007af1489c4946672f6caa5b5fe196ce # Parent a16bf3b5d0b964739a92ddbba418ab02709be59b 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 a16bf3b5d0b9 -r 59f38ff0007a src/Virt_ElementConformsToProfile.c --- a/src/Virt_ElementConformsToProfile.c Fri Mar 14 11:02:13 2008 +0100 +++ b/src/Virt_ElementConformsToProfile.c Fri Mar 14 11:03:15 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,18 @@ 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, + pfx_from_conn(conn), + profiles[i], + &instance); + if (s.rc != CMPI_RC_OK) goto out; - } - + inst_list_add(list, instance); }
participants (1)
-
Heidi Eckhart