diff options
Diffstat (limited to 'src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c')
-rw-r--r-- | src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c | 330 |
1 files changed, 280 insertions, 50 deletions
diff --git a/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c b/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c index 6f7a25d..849e8f6 100644 --- a/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c +++ b/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c @@ -1,10 +1,32 @@ +/* + * Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Peter Schiffer <pschiffe@redhat.com> + */ + #include <konkret/konkret.h> #include "LMI_InstalledSoftwareIdentity.h" +#include "LMI_Software.h" static const CMPIBroker* _cb; -static void LMI_InstalledSoftwareIdentityInitialize() +static void LMI_InstalledSoftwareIdentityInitialize(const CMPIContext *ctx) { + lmi_init(provider_name, _cb, ctx, provider_config_defaults); } static CMPIStatus LMI_InstalledSoftwareIdentityCleanup( @@ -15,14 +37,72 @@ static CMPIStatus LMI_InstalledSoftwareIdentityCleanup( CMReturn(CMPI_RC_OK); } +static CMPIStatus enum_instances(const CMPIResult *cr, const char *ns, + const short names) +{ + GPtrArray *array = NULL; + SwPackage sw_pkg; + unsigned i; + char error_msg[ERROR_MSG_LEN] = "", elem_name[ELEM_NAME_LEN] = "", + instance_id[INSTANCE_ID_LEN] = ""; + + init_sw_package(&sw_pkg); + + get_pk_packages(pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), &array, + error_msg, ERROR_MSG_LEN); + if (!array) { + goto done; + } + + for (i = 0; i < array->len; i++) { + if (create_sw_package_from_pk_pkg(g_ptr_array_index(array, i), + &sw_pkg) != 0) { + continue; + } + + sw_pkg_get_element_name(&sw_pkg, elem_name, ELEM_NAME_LEN); + + create_instance_id(SW_IDENTITY_CLASS_NAME, elem_name, instance_id, + INSTANCE_ID_LEN); + + free_sw_package(&sw_pkg); + + LMI_SoftwareIdentityRef si; + LMI_SoftwareIdentityRef_Init(&si, _cb, ns); + LMI_SoftwareIdentityRef_Set_InstanceID(&si, instance_id); + + LMI_InstalledSoftwareIdentity w; + LMI_InstalledSoftwareIdentity_Init(&w, _cb, ns); + LMI_InstalledSoftwareIdentity_SetObjectPath_System(&w, + lmi_get_computer_system()); + LMI_InstalledSoftwareIdentity_Set_InstalledSoftware(&w, &si); + + if (names) { + KReturnObjectPath(cr, w); + } else { + KReturnInstance(cr, w); + } + } + +done: + if (array) { + g_ptr_array_unref(array); + } + + if (*error_msg) { + KReturn2(_cb, ERR_FAILED, "%s", error_msg); + } + + CMReturn(CMPI_RC_OK); +} + static CMPIStatus LMI_InstalledSoftwareIdentityEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { - return KDefaultEnumerateInstanceNames( - _cb, mi, cc, cr, cop); + return enum_instances(cr, KNameSpace(cop), 1); } static CMPIStatus LMI_InstalledSoftwareIdentityEnumInstances( @@ -32,7 +112,7 @@ static CMPIStatus LMI_InstalledSoftwareIdentityEnumInstances( const CMPIObjectPath* cop, const char** properties) { - CMReturn(CMPI_RC_OK); + return enum_instances(cr, KNameSpace(cop), 0); } static CMPIStatus LMI_InstalledSoftwareIdentityGetInstance( @@ -42,8 +122,30 @@ static CMPIStatus LMI_InstalledSoftwareIdentityGetInstance( const CMPIObjectPath* cop, const char** properties) { - return KDefaultGetInstance( - _cb, mi, cc, cr, cop, properties); + PkPackage *pk_pkg = NULL; + SwPackage sw_pkg; + + init_sw_package(&sw_pkg); + + LMI_InstalledSoftwareIdentity w; + LMI_InstalledSoftwareIdentity_InitFromObjectPath(&w, _cb, cop); + + if (create_sw_package_from_elem_name(get_str_property_from_op(w.InstalledSoftware.value, + "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"), + &sw_pkg) != 0) { + CMReturn(CMPI_RC_ERR_NOT_FOUND); + } + + get_pk_pkg_from_sw_pkg(&sw_pkg, pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), + &pk_pkg); + free_sw_package(&sw_pkg); + if (!pk_pkg) { + CMReturn(CMPI_RC_ERR_NOT_FOUND); + } + g_object_unref(pk_pkg); + + KReturnInstance(cr, w); + CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_InstalledSoftwareIdentityCreateInstance( @@ -95,6 +197,100 @@ static CMPIStatus LMI_InstalledSoftwareIdentityAssociationCleanup( CMReturn(CMPI_RC_OK); } +static CMPIStatus associators( + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* resultClass, + const char* role, + const char* resultRole, + const char** properties, + const short names) +{ + CMPIStatus st; + char error_msg[ERROR_MSG_LEN] = ""; + const char *computer_system_name; + + computer_system_name = get_str_property_from_op(lmi_get_computer_system(), + "CreationClassName"); + + if (!cm_class_is_a(_cb, KNameSpace(cop), assocClass, + ORGID "_" INST_SW_IDENTITY_CLASS_NAME)) { + goto done; + } + + if (CMClassPathIsA(_cb, cop, computer_system_name, &st)) { + /* got PG_ComputerSystem - System */ + if (cm_class_is_a(_cb, KNameSpace(cop), resultClass, + ORGID "_" SW_IDENTITY_CLASS_NAME) != 0) { + goto done; + } + if (role && strcmp(role, SYSTEM_ATTR) != 0) { + goto done; + } + if (resultRole && strcmp(resultRole, INST_SW_ATTR) != 0) { + goto done; + } + + if (names) { + enum_sw_identity_instance_names( + pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), _cb, + KNameSpace(cop), cr, error_msg, ERROR_MSG_LEN); + } else { + enum_sw_identity_instances( + pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), _cb, + KNameSpace(cop), cr, error_msg, ERROR_MSG_LEN); + } + } else if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_CLASS_NAME, &st)) { + /* got SoftwareIdentity - InstalledSoftware */ + PkPackage *pk_pkg = NULL; + SwPackage sw_pkg; + + init_sw_package(&sw_pkg); + + if (cm_class_is_a(_cb, KNameSpace(cop), resultClass, + computer_system_name) != 0) { + goto done; + } + if (role && strcmp(role, INST_SW_ATTR) != 0) { + goto done; + } + if (resultRole && strcmp(resultRole, SYSTEM_ATTR) != 0) { + goto done; + } + + /* Is this SwIdentity installed? */ + if (create_sw_package_from_elem_name(get_str_property_from_op(cop, + "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"), + &sw_pkg) != 0) { + goto done; + } + get_pk_pkg_from_sw_pkg(&sw_pkg, pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), + &pk_pkg); + free_sw_package(&sw_pkg); + if (!pk_pkg) { + goto done; + } + g_object_unref(pk_pkg); + + if (names) { + CMReturnObjectPath(cr, lmi_get_computer_system()); + } else { + CMPIObjectPath *o = lmi_get_computer_system(); + CMPIInstance *ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); + CMReturnInstance(cr, ci); + } + } + +done: + if (*error_msg) { + KReturn2(_cb, ERR_FAILED, "%s", error_msg); + } + + CMReturn(CMPI_RC_OK); +} + static CMPIStatus LMI_InstalledSoftwareIdentityAssociators( CMPIAssociationMI* mi, const CMPIContext* cc, @@ -106,18 +302,8 @@ static CMPIStatus LMI_InstalledSoftwareIdentityAssociators( const char* resultRole, const char** properties) { - return KDefaultAssociators( - _cb, - mi, - cc, - cr, - cop, - LMI_InstalledSoftwareIdentity_ClassName, - assocClass, - resultClass, - role, - resultRole, - properties); + return associators(cc, cr, cop, assocClass, resultClass, role, + resultRole, properties, 0); } static CMPIStatus LMI_InstalledSoftwareIdentityAssociatorNames( @@ -130,17 +316,78 @@ static CMPIStatus LMI_InstalledSoftwareIdentityAssociatorNames( const char* role, const char* resultRole) { - return KDefaultAssociatorNames( - _cb, - mi, - cc, - cr, - cop, - LMI_InstalledSoftwareIdentity_ClassName, - assocClass, - resultClass, - role, - resultRole); + return associators(cc, cr, cop, assocClass, resultClass, role, + resultRole, NULL, 1); +} + +static CMPIStatus references( + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* role, + const short names) +{ + CMPIStatus st; + const char *computer_system_name; + + computer_system_name = get_str_property_from_op(lmi_get_computer_system(), + "CreationClassName"); + + if (!cm_class_is_a(_cb, KNameSpace(cop), assocClass, + ORGID "_" INST_SW_IDENTITY_CLASS_NAME)) { + goto done; + } + + if (CMClassPathIsA(_cb, cop, computer_system_name, &st)) { + /* got PG_ComputerSystem - System */ + if (role && strcmp(role, SYSTEM_ATTR) != 0) { + goto done; + } + + return enum_instances(cr, KNameSpace(cop), names); + } else if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_CLASS_NAME, &st)) { + /* got SoftwareIdentity - InstalledSoftware */ + PkPackage *pk_pkg = NULL; + SwPackage sw_pkg; + + init_sw_package(&sw_pkg); + + if (role && strcmp(role, INST_SW_ATTR) != 0) { + goto done; + } + + /* Is this SwIdentity installed? */ + if (create_sw_package_from_elem_name(get_str_property_from_op(cop, + "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"), + &sw_pkg) != 0) { + goto done; + } + get_pk_pkg_from_sw_pkg(&sw_pkg, pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), + &pk_pkg); + free_sw_package(&sw_pkg); + if (!pk_pkg) { + goto done; + } + g_object_unref(pk_pkg); + + LMI_SoftwareIdentityRef si; + LMI_SoftwareIdentityRef_InitFromObjectPath(&si, _cb, cop); + + LMI_InstalledSoftwareIdentity w; + LMI_InstalledSoftwareIdentity_Init(&w, _cb, KNameSpace(cop)); + LMI_InstalledSoftwareIdentity_SetObjectPath_System(&w, + lmi_get_computer_system()); + LMI_InstalledSoftwareIdentity_Set_InstalledSoftware(&w, &si); + + if (names) { + KReturnObjectPath(cr, w); + } else { + KReturnInstance(cr, w); + } + } + +done: + CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_InstalledSoftwareIdentityReferences( @@ -152,16 +399,7 @@ static CMPIStatus LMI_InstalledSoftwareIdentityReferences( const char* role, const char** properties) { - return KDefaultReferences( - _cb, - mi, - cc, - cr, - cop, - LMI_InstalledSoftwareIdentity_ClassName, - assocClass, - role, - properties); + return references(cr, cop, assocClass, role, 0); } static CMPIStatus LMI_InstalledSoftwareIdentityReferenceNames( @@ -172,28 +410,20 @@ static CMPIStatus LMI_InstalledSoftwareIdentityReferenceNames( const char* assocClass, const char* role) { - return KDefaultReferenceNames( - _cb, - mi, - cc, - cr, - cop, - LMI_InstalledSoftwareIdentity_ClassName, - assocClass, - role); + return references(cr, cop, assocClass, role, 1); } CMInstanceMIStub( LMI_InstalledSoftwareIdentity, LMI_InstalledSoftwareIdentity, _cb, - LMI_InstalledSoftwareIdentityInitialize()) + LMI_InstalledSoftwareIdentityInitialize(ctx)) CMAssociationMIStub( LMI_InstalledSoftwareIdentity, LMI_InstalledSoftwareIdentity, _cb, - LMI_InstalledSoftwareIdentityInitialize()) + LMI_InstalledSoftwareIdentityInitialize(ctx)) KONKRET_REGISTRATION( "root/cimv2", |