diff options
Diffstat (limited to 'src/software-dbus/LMI_SoftwareIdentityProvider.c')
-rw-r--r-- | src/software-dbus/LMI_SoftwareIdentityProvider.c | 145 |
1 files changed, 16 insertions, 129 deletions
diff --git a/src/software-dbus/LMI_SoftwareIdentityProvider.c b/src/software-dbus/LMI_SoftwareIdentityProvider.c index 3806584..696c65e 100644 --- a/src/software-dbus/LMI_SoftwareIdentityProvider.c +++ b/src/software-dbus/LMI_SoftwareIdentityProvider.c @@ -43,58 +43,10 @@ static CMPIStatus LMI_SoftwareIdentityEnumInstanceNames( 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); + char error_msg[ERROR_MSG_LEN] = ""; - if (task) { - g_object_unref(task); - } - if (results) { - g_object_unref(results); - } - if (array) { - g_ptr_array_unref(array); - } + enum_sw_identity_instances(0, _cb, KNameSpace(cop), cr, + error_msg, ERROR_MSG_LEN, 1); if (*error_msg) { KReturn2(_cb, ERR_FAILED, "%s", error_msg); @@ -121,106 +73,41 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance( 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] = ""; + short found = 0; 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_search_names_sync(task, 0, values, NULL, NULL, NULL, &gerror); - if (check_and_create_error_msg(results, gerror, "Resolving package failed", - error_msg, ERROR_MSG_LEN)) { + 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; } - 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) { + get_pk_pkg_from_sw_pkg(&sw_pkg, &pk_pkg); + if (!pk_pkg) { 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; - } + get_pk_det_from_pk_pkg(pk_pkg, &pk_det); create_instance_from_pkgkit_data(pk_pkg, pk_det, &sw_pkg, _cb, KNameSpace(cop), &w); KReturnInstance(cr, w); + found = 1; + 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 (pk_det) { + g_object_unref(pk_det); } - if (array2) { - g_ptr_array_unref(array2); - } - - if (*error_msg) { - KReturn2(_cb, ERR_FAILED, "%s", error_msg); + if (pk_pkg) { + g_object_unref(pk_pkg); } if (!found) { |