/* * 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 */ #include #include "LMI_MemberOfSoftwareCollection.h" #include "LMI_Software.h" static const CMPIBroker* _cb; static void LMI_MemberOfSoftwareCollectionInitialize(const CMPIContext *ctx) { lmi_init(provider_name, _cb, ctx, provider_config_defaults); } static CMPIStatus LMI_MemberOfSoftwareCollectionCleanup( CMPIInstanceMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_MemberOfSoftwareCollectionEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { return KDefaultEnumerateInstanceNames( _cb, mi, cc, cr, cop); } static CMPIStatus LMI_MemberOfSoftwareCollectionEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { PkTask *task = NULL; PkResults *results = NULL; GError *gerror = NULL; GPtrArray *array = NULL; SwPackage sw_pkg; unsigned i; char error_msg[ERROR_MSG_LEN] = "", elem_name[ELEM_NAME_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; create_instance_id(SYSTEM_SW_COLLECTION_CLASS_NAME, NULL, instance_id, INSTANCE_ID_LEN); LMI_SystemSoftwareCollectionRef ssc; LMI_SystemSoftwareCollectionRef_Init(&ssc, _cb, KNameSpace(cop)); LMI_SystemSoftwareCollectionRef_Set_InstanceID(&ssc, instance_id); init_sw_package(&sw_pkg); task = pk_task_new(); results = pk_task_get_packages_sync(task, 0, NULL, NULL, NULL, &gerror); if (check_and_create_error_msg(results, gerror, "Getting list of packages failed", error_msg, ERROR_MSG_LEN)) { goto done; } array = pk_results_get_package_array(results); g_ptr_array_sort(array, (GCompareFunc) pk_pkg_cmp); 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, KNameSpace(cop)); LMI_SoftwareIdentityRef_Set_InstanceID(&si, instance_id); LMI_MemberOfSoftwareCollection w; LMI_MemberOfSoftwareCollection_Init(&w, _cb, KNameSpace(cop)); LMI_MemberOfSoftwareCollection_Set_Collection(&w, &ssc); LMI_MemberOfSoftwareCollection_Set_Member(&w, &si); KReturnInstance(cr, w); } done: g_clear_error(&gerror); if (task) { g_object_unref(task); } if (results) { g_object_unref(results); } if (array) { g_ptr_array_unref(array); } if (*error_msg) { KReturn2(_cb, ERR_FAILED, "%s", error_msg); } CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_MemberOfSoftwareCollectionGetInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { char instance_id[INSTANCE_ID_LEN] = ""; create_instance_id(SYSTEM_SW_COLLECTION_CLASS_NAME, NULL, instance_id, INSTANCE_ID_LEN); LMI_MemberOfSoftwareCollection w; LMI_MemberOfSoftwareCollection_InitFromObjectPath(&w, _cb, cop); if (strcmp(get_str_property_from_op(w.Collection.value, "InstanceID"), instance_id) != 0) { CMReturn(CMPI_RC_ERR_NOT_FOUND); } if (!is_valid_sw_pkg_elem_name(get_str_property_from_op(w.Member.value, "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"))) { CMReturn(CMPI_RC_ERR_NOT_FOUND); } KReturnInstance(cr, w); CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_MemberOfSoftwareCollectionCreateInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_MemberOfSoftwareCollectionModifyInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci, const char**properties) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_MemberOfSoftwareCollectionDeleteInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_MemberOfSoftwareCollectionExecQuery( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* lang, const char* query) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_MemberOfSoftwareCollectionAssociationCleanup( CMPIAssociationMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus associators( CMPIAssociationMI* mi, 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; CMPIInstance *ci; CMPIObjectPath *o; PkTask *task = NULL; PkResults *results = NULL; GError *gerror = NULL; GPtrArray *array = NULL; SwPackage sw_pkg; unsigned i; char error_msg[ERROR_MSG_LEN] = "", elem_name[ELEM_NAME_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; if (!cm_class_is_a(_cb, KNameSpace(cop), assocClass, ORGID "_" MEM_SW_COLL_CLASS_NAME)) { goto done; } if (CMClassPathIsA(_cb, cop, ORGID "_" SYSTEM_SW_COLLECTION_CLASS_NAME, &st)) { /* got SystemSoftwareCollection - Collection; * where listing only associators names is supported */ if (!names) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } if (cm_class_is_a(_cb, KNameSpace(cop), resultClass, ORGID "_" SW_IDENTITY_CLASS_NAME) != 0) { goto done; } if (role && strcmp(role, COLLECTION_ATTR) != 0) { goto done; } if (resultRole && strcmp(resultRole, MEMBER_ATTR) != 0) { goto done; } init_sw_package(&sw_pkg); task = pk_task_new(); results = pk_task_get_packages_sync(task, 0, NULL, NULL, NULL, &gerror); if (check_and_create_error_msg(results, gerror, "Getting list of packages failed", error_msg, ERROR_MSG_LEN)) { goto done; } array = pk_results_get_package_array(results); g_ptr_array_sort(array, (GCompareFunc) pk_pkg_cmp); 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, KNameSpace(cop)); LMI_SoftwareIdentityRef_Set_InstanceID(&si, instance_id); o = LMI_SoftwareIdentityRef_ToObjectPath(&si, &st); CMReturnObjectPath(cr, o); } } else if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_CLASS_NAME, &st)) { /* got SoftwareIdentity - Member */ if (cm_class_is_a(_cb, KNameSpace(cop), resultClass, ORGID "_" SYSTEM_SW_COLLECTION_CLASS_NAME) != 0) { goto done; } if (role && strcmp(role, MEMBER_ATTR) != 0) { goto done; } if (resultRole && strcmp(resultRole, COLLECTION_ATTR) != 0) { goto done; } create_instance_id(SYSTEM_SW_COLLECTION_CLASS_NAME, NULL, instance_id, INSTANCE_ID_LEN); LMI_SystemSoftwareCollectionRef ssc; LMI_SystemSoftwareCollectionRef_Init(&ssc, _cb, KNameSpace(cop)); LMI_SystemSoftwareCollectionRef_Set_InstanceID(&ssc, instance_id); o = LMI_SystemSoftwareCollectionRef_ToObjectPath(&ssc, &st); if (names) { CMReturnObjectPath(cr, o); } else { ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); CMReturnInstance(cr, ci); } } done: g_clear_error(&gerror); if (task) { g_object_unref(task); } if (results) { g_object_unref(results); } if (array) { g_ptr_array_unref(array); } if (*error_msg) { KReturn2(_cb, ERR_FAILED, "%s", error_msg); } CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_MemberOfSoftwareCollectionAssociators( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* resultClass, const char* role, const char* resultRole, const char** properties) { return associators(mi, cc, cr, cop, assocClass, resultClass, role, resultRole, properties, 0); } static CMPIStatus LMI_MemberOfSoftwareCollectionAssociatorNames( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* resultClass, const char* role, const char* resultRole) { return associators(mi, cc, cr, cop, assocClass, resultClass, role, resultRole, NULL, 1); } static CMPIStatus references( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role, const char** properties, const short names) { CMPIStatus st; CMPIObjectPath *o; PkTask *task = NULL; PkResults *results = NULL; GError *gerror = NULL; GPtrArray *array = NULL; SwPackage sw_pkg; unsigned i; char error_msg[ERROR_MSG_LEN] = "", elem_name[ELEM_NAME_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; if (!cm_class_is_a(_cb, KNameSpace(cop), assocClass, ORGID "_" MEM_SW_COLL_CLASS_NAME)) { goto done; } create_instance_id(SYSTEM_SW_COLLECTION_CLASS_NAME, NULL, instance_id, INSTANCE_ID_LEN); LMI_SystemSoftwareCollectionRef ssc; LMI_SystemSoftwareCollectionRef_Init(&ssc, _cb, KNameSpace(cop)); LMI_SystemSoftwareCollectionRef_Set_InstanceID(&ssc, instance_id); if (CMClassPathIsA(_cb, cop, ORGID "_" SYSTEM_SW_COLLECTION_CLASS_NAME, &st)) { /* got SystemSoftwareCollection - Collection */ if (role && strcmp(role, COLLECTION_ATTR) != 0) { goto done; } init_sw_package(&sw_pkg); task = pk_task_new(); results = pk_task_get_packages_sync(task, 0, NULL, NULL, NULL, &gerror); if (check_and_create_error_msg(results, gerror, "Getting list of packages failed", error_msg, ERROR_MSG_LEN)) { goto done; } array = pk_results_get_package_array(results); g_ptr_array_sort(array, (GCompareFunc) pk_pkg_cmp); 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, KNameSpace(cop)); LMI_SoftwareIdentityRef_Set_InstanceID(&si, instance_id); LMI_MemberOfSoftwareCollection w; LMI_MemberOfSoftwareCollection_Init(&w, _cb, KNameSpace(cop)); LMI_MemberOfSoftwareCollection_Set_Collection(&w, &ssc); LMI_MemberOfSoftwareCollection_Set_Member(&w, &si); if (names) { o = LMI_MemberOfSoftwareCollection_ToObjectPath(&w, &st); CMReturnObjectPath(cr, o); } else { KReturnInstance(cr, w); } } } else if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_CLASS_NAME, &st)) { /* got SoftwareIdentity - Member */ if (role && strcmp(role, MEMBER_ATTR) != 0) { goto done; } LMI_SoftwareIdentityRef si; LMI_SoftwareIdentityRef_InitFromObjectPath(&si, _cb, cop); LMI_MemberOfSoftwareCollection w; LMI_MemberOfSoftwareCollection_Init(&w, _cb, KNameSpace(cop)); LMI_MemberOfSoftwareCollection_Set_Collection(&w, &ssc); LMI_MemberOfSoftwareCollection_Set_Member(&w, &si); if (names) { o = LMI_MemberOfSoftwareCollection_ToObjectPath(&w, &st); CMReturnObjectPath(cr, o); } else { KReturnInstance(cr, w); } } done: g_clear_error(&gerror); if (task) { g_object_unref(task); } if (results) { g_object_unref(results); } if (array) { g_ptr_array_unref(array); } if (*error_msg) { KReturn2(_cb, ERR_FAILED, "%s", error_msg); } CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_MemberOfSoftwareCollectionReferences( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role, const char** properties) { return references(mi, cc, cr, cop, assocClass, role, properties, 0); } static CMPIStatus LMI_MemberOfSoftwareCollectionReferenceNames( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role) { return references(mi, cc, cr, cop, assocClass, role, NULL, 1); } CMInstanceMIStub( LMI_MemberOfSoftwareCollection, LMI_MemberOfSoftwareCollection, _cb, LMI_MemberOfSoftwareCollectionInitialize(ctx)) CMAssociationMIStub( LMI_MemberOfSoftwareCollection, LMI_MemberOfSoftwareCollection, _cb, LMI_MemberOfSoftwareCollectionInitialize(ctx)) KONKRET_REGISTRATION( "root/cimv2", "LMI_MemberOfSoftwareCollection", "LMI_MemberOfSoftwareCollection", "instance association")