/* * 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_SoftwareIdentity.h" #include "LMI_Software.h" static const CMPIBroker* _cb = NULL; static void LMI_SoftwareIdentityInitialize(const CMPIContext *ctx) { lmi_init(provider_name, _cb, ctx, provider_config_defaults); } static CMPIStatus LMI_SoftwareIdentityCleanup( CMPIInstanceMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_SoftwareIdentityEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { 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] = ""; 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 w; LMI_SoftwareIdentityRef_Init(&w, _cb, KNameSpace(cop)); LMI_SoftwareIdentityRef_Set_InstanceID(&w, instance_id); KReturnObjectPath(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_SoftwareIdentityEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_SoftwareIdentityGetInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { LMI_SoftwareIdentity w; PkTask *task = NULL; PkPackage *pk_pkg = NULL; PkDetails *pk_det = NULL; PkResults *results = NULL, *results2 = NULL; GPtrArray *array = NULL, *array2 = NULL; GError *gerror = NULL; gchar **values = NULL; SwPackage sw_pkg; unsigned i, j; short found = 0, found2 = 0; char error_msg[ERROR_MSG_LEN] = ""; init_sw_package(&sw_pkg); if (create_sw_package_from_elem_name( get_str_property_from_op(cop, "InstanceID") + strlen( ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"), &sw_pkg) != 0) { snprintf(error_msg, ERROR_MSG_LEN, "Failed to parse instance ID: %s", get_str_property_from_op(cop, "InstanceID")); goto done; } task = pk_task_new(); values = g_new0(gchar*, 2); values[0] = g_strdup(sw_pkg.name); values[1] = NULL; results = pk_task_resolve_sync(task, 0, values, NULL, NULL, NULL, &gerror); if (check_and_create_error_msg(results, gerror, "Resolving package failed", error_msg, ERROR_MSG_LEN)) { goto done; } array = pk_results_get_package_array(results); for (i = 0; i < array->len; i++) { pk_pkg = g_ptr_array_index(array, i); if (strcmp(pk_package_get_name(pk_pkg), sw_pkg.name) == 0 && strcmp(pk_package_get_version(pk_pkg), sw_pkg.pk_version) == 0 && strcmp(pk_package_get_arch(pk_pkg), sw_pkg.arch) == 0) { found = 1; break; } } if (!found) { goto done; } g_free(values[0]); values[0] = g_strdup(pk_package_get_id(pk_pkg)); results2 = pk_task_get_details_sync(task, values, NULL, NULL, NULL, &gerror); if (check_and_create_error_msg(results2, gerror, "Getting package details failed", error_msg, ERROR_MSG_LEN)) { warn(error_msg); /* This is non-fatal problem. */ error_msg[0] = '\0'; } else { array2 = pk_results_get_details_array(results2); for (j = 0; j < array2->len; j++) { pk_det = g_ptr_array_index(array2, j); if (strcmp(pk_details_get_package_id(pk_det), pk_package_get_id(pk_pkg)) == 0) { found2 = 1; break; } } } if (!found2) { pk_det = NULL; } create_instance_from_pkgkit_data(pk_pkg, pk_det, &sw_pkg, _cb, KNameSpace(cop), &w); KReturnInstance(cr, w); done: free_sw_package(&sw_pkg); g_strfreev(values); g_clear_error(&gerror); if (task) { g_object_unref(task); } if (results) { g_object_unref(results); } if (results2) { g_object_unref(results2); } if (array) { g_ptr_array_unref(array); } if (array2) { g_ptr_array_unref(array2); } if (*error_msg) { KReturn2(_cb, ERR_FAILED, "%s", error_msg); } if (!found) { CMReturn(CMPI_RC_ERR_NOT_FOUND); } CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_SoftwareIdentityCreateInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_SoftwareIdentityModifyInstance( 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_SoftwareIdentityDeleteInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_SoftwareIdentityExecQuery( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* lang, const char* query) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } CMInstanceMIStub( LMI_SoftwareIdentity, LMI_SoftwareIdentity, _cb, LMI_SoftwareIdentityInitialize(ctx)) static CMPIStatus LMI_SoftwareIdentityMethodCleanup( CMPIMethodMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_SoftwareIdentityInvokeMethod( CMPIMethodMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* meth, const CMPIArgs* in, CMPIArgs* out) { return LMI_SoftwareIdentity_DispatchMethod( _cb, mi, cc, cr, cop, meth, in, out); } CMMethodMIStub( LMI_SoftwareIdentity, LMI_SoftwareIdentity, _cb, LMI_SoftwareIdentityInitialize(ctx)) KONKRET_REGISTRATION( "root/cimv2", "LMI_SoftwareIdentity", "LMI_SoftwareIdentity", "instance method")