diff options
Diffstat (limited to 'src/software-dbus')
-rw-r--r-- | src/software-dbus/LMI_ResourceForSoftwareIdentityProvider.c | 602 | ||||
-rw-r--r-- | src/software-dbus/LMI_SoftwareIdentityProvider.c | 2 | ||||
-rw-r--r-- | src/software-dbus/LMI_SoftwareIdentityResourceProvider.c | 19 | ||||
-rw-r--r-- | src/software-dbus/sw-utils.c | 476 | ||||
-rw-r--r-- | src/software-dbus/sw-utils.h | 91 |
5 files changed, 1013 insertions, 177 deletions
diff --git a/src/software-dbus/LMI_ResourceForSoftwareIdentityProvider.c b/src/software-dbus/LMI_ResourceForSoftwareIdentityProvider.c index 9332f62..d1681ff 100644 --- a/src/software-dbus/LMI_ResourceForSoftwareIdentityProvider.c +++ b/src/software-dbus/LMI_ResourceForSoftwareIdentityProvider.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_ResourceForSoftwareIdentity.h" +#include "sw-utils.h" static const CMPIBroker* _cb; -static void LMI_ResourceForSoftwareIdentityInitialize() +static void LMI_ResourceForSoftwareIdentityInitialize(const CMPIContext *ctx) { + lmi_init(provider_name, _cb, ctx, provider_config_defaults); } static CMPIStatus LMI_ResourceForSoftwareIdentityCleanup( @@ -15,14 +37,187 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityCleanup( CMReturn(CMPI_RC_OK); } +static void k_return_rfsi(const gchar *pkg_id, + const LMI_SoftwareIdentityResourceRef *sir, const CMPIResult *cr, + const char *ns, const short names) +{ + SwPackage sw_pkg; + char elem_name[ELEM_NAME_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; + + init_sw_package(&sw_pkg); + + if (create_sw_package_from_pk_pkg_id(pkg_id, &sw_pkg) != 0) { + goto done; + } + + 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); + + LMI_SoftwareIdentityRef si; + LMI_SoftwareIdentityRef_Init(&si, _cb, ns); + LMI_SoftwareIdentityRef_Set_InstanceID(&si, instance_id); + + LMI_ResourceForSoftwareIdentity rfsi; + LMI_ResourceForSoftwareIdentity_Init(&rfsi, _cb, ns); + LMI_ResourceForSoftwareIdentity_Set_AvailableSAP(&rfsi, sir); + LMI_ResourceForSoftwareIdentity_Set_ManagedElement(&rfsi, &si); + + if (names) { + KReturnObjectPath(cr, rfsi); + } else { + KReturnInstance(cr, rfsi); + } + +done: + free_sw_package(&sw_pkg); + + return; +} + +static CMPIStatus enum_instances(const CMPIResult *cr, const char *ns, + const short names, const char *repo_id_p) +{ + LMI_SoftwareIdentityResourceRef *sir; + PkPackage *pkg = NULL; + GPtrArray *pkg_array = NULL, *det_array = NULL, *array = NULL; + GHashTable *repo_hash = NULL; + GHashTableIter iter; + gchar *repo_id = NULL, *pkg_id = NULL, **values = NULL, + **pk_det_id_split = NULL; + const gchar *pkg_id_c = NULL; + unsigned i, j; + char error_msg[ERROR_MSG_LEN] = ""; + + /* Get all available repos, create LMI_SoftwareIdentityResourceRef for + * all of them and store it in hash table. */ + get_pk_repos(&array, error_msg, ERROR_MSG_LEN); + if (!array) { + goto done; + } + + repo_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + + for (i = 0; i < array->len; i++) { + g_object_get(g_ptr_array_index(array, i), "repo-id", &repo_id, NULL); + + sir = g_new0(LMI_SoftwareIdentityResourceRef, 1); + LMI_SoftwareIdentityResourceRef_Init(sir, _cb, ns); + LMI_SoftwareIdentityResourceRef_Set_SystemName(sir, get_system_name()); + LMI_SoftwareIdentityResourceRef_Set_CreationClassName(sir, + ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME); + LMI_SoftwareIdentityResourceRef_Set_SystemCreationClassName(sir, + get_system_creation_class_name()); + LMI_SoftwareIdentityResourceRef_Set_Name(sir, repo_id); + + g_hash_table_insert(repo_hash, repo_id, sir); + } + g_ptr_array_unref(array); + array = NULL; + + /* Get all packages and check their repo. If found in hash table, return + * the LMI_ResourceForSoftwareIdentity instance. If not, save the package + * in array for next processing. */ + get_pk_packages(0, &pkg_array, error_msg, ERROR_MSG_LEN); + if (!pkg_array) { + goto done; + } + + /* Lets assume that there is about EST_OF_INSTD_PKGS installed packages + * (to avoid too many allocations) */ + array = g_ptr_array_new_full(EST_OF_INSTD_PKGS, g_object_unref); + + for (i = 0; i < pkg_array->len; i++) { + pkg = g_ptr_array_index(pkg_array, i); + + sir = (LMI_SoftwareIdentityResourceRef *) g_hash_table_lookup(repo_hash, + pk_package_get_data(pkg)); + + if (sir) { + if (!repo_id_p || strcmp(repo_id_p, pk_package_get_data(pkg)) == 0) { + k_return_rfsi(pk_package_get_id(pkg), sir, cr, ns, names); + } + } else { + g_ptr_array_add(array, g_object_ref(pkg)); + } + } + g_ptr_array_unref(pkg_array); + pkg_array = NULL; + + /* For all saved packages, create package ID with every available repo. + * Then, get package details for all those package IDs. Package details + * are returned only for valid package IDs... */ + j = 0; + if (!repo_id_p) { + values = g_new0(gchar*, array->len * g_hash_table_size(repo_hash) + 1); + } else { + values = g_new0(gchar*, array->len + 1); + } + for (i = 0; i < array->len; i++) { + pkg = g_ptr_array_index(array, i); + if (!repo_id_p) { + g_hash_table_iter_init(&iter, repo_hash); + while (g_hash_table_iter_next(&iter, (gpointer *) &repo_id, NULL)) { + pkg_id = pk_package_id_build(pk_package_get_name(pkg), + pk_package_get_version(pkg), pk_package_get_arch(pkg), + repo_id); + values[j++] = pkg_id; + } + } else { + pkg_id = pk_package_id_build(pk_package_get_name(pkg), + pk_package_get_version(pkg), pk_package_get_arch(pkg), + repo_id_p); + values[j++] = pkg_id; + } + } + g_ptr_array_unref(array); + array = NULL; + + get_pk_det_from_array(values, &det_array, NULL); + g_strfreev(values); + values = NULL; + + if (det_array && det_array->len > 0) { + for (i = 0; i < det_array->len; i++) { + pkg_id_c = pk_details_get_package_id(g_ptr_array_index(det_array, i)); + pk_det_id_split = pk_package_id_split(pkg_id_c); + if (!pk_det_id_split) { + continue; + } + + sir = (LMI_SoftwareIdentityResourceRef *) g_hash_table_lookup( + repo_hash, pk_det_id_split[PK_PACKAGE_ID_DATA]); + g_strfreev(pk_det_id_split); + pk_det_id_split = NULL; + + if (sir) { + k_return_rfsi(pkg_id_c, sir, cr, ns, names); + } + } + g_ptr_array_unref(det_array); + det_array = NULL; + } + +done: + if (repo_hash) { + g_hash_table_destroy(repo_hash); + } + + if (*error_msg) { + KReturn2(_cb, ERR_FAILED, "%s", error_msg); + } + + CMReturn(CMPI_RC_OK); +} + static CMPIStatus LMI_ResourceForSoftwareIdentityEnumInstanceNames( 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, NULL); } static CMPIStatus LMI_ResourceForSoftwareIdentityEnumInstances( @@ -32,7 +227,7 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityEnumInstances( const CMPIObjectPath* cop, const char** properties) { - CMReturn(CMPI_RC_OK); + return enum_instances(cr, KNameSpace(cop), 0, NULL); } static CMPIStatus LMI_ResourceForSoftwareIdentityGetInstance( @@ -42,8 +237,86 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityGetInstance( const CMPIObjectPath* cop, const char** properties) { - return KDefaultGetInstance( - _cb, mi, cc, cr, cop, properties); + const char *repo_id = NULL; + gchar *pkg_id = NULL, **values = NULL; + GPtrArray *array = NULL; + PkRepoDetail *pk_repo = NULL; + PkPackage *pk_pkg = NULL; + SwPackage sw_pkg; + CMPIrc rc_stat = CMPI_RC_ERR_NOT_FOUND; + char error_msg[ERROR_MSG_LEN] = ""; + + init_sw_package(&sw_pkg); + + LMI_ResourceForSoftwareIdentity w; + LMI_ResourceForSoftwareIdentity_InitFromObjectPath(&w, _cb, cop); + + /* Check repo */ + if (strcmp(get_str_property_from_op(w.AvailableSAP.value, "CreationClassName"), + ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME) != 0) { + goto done; + } + if (strcmp(get_str_property_from_op(w.AvailableSAP.value, "SystemCreationClassName"), + get_system_creation_class_name()) != 0) { + goto done; + } + if (strcmp(get_str_property_from_op(w.AvailableSAP.value, "SystemName"), + get_system_name()) != 0) { + goto done; + } + repo_id = get_str_property_from_op(w.AvailableSAP.value, "Name"); + get_pk_repo(repo_id, &pk_repo, error_msg, ERROR_MSG_LEN); + if (!pk_repo) { + goto done; + } + + /* Check package */ + if (get_sw_pkg_from_sw_identity_op(w.ManagedElement.value, &sw_pkg) != 0) { + goto done; + } + get_pk_pkg_from_sw_pkg(&sw_pkg, 0, &pk_pkg); + if (!pk_pkg) { + goto done; + } + + /* Is this package from this repo? */ + if (strcmp(pk_package_get_data(pk_pkg), repo_id) != 0) { + pkg_id = pk_package_id_build(pk_package_get_name(pk_pkg), + pk_package_get_version(pk_pkg), pk_package_get_arch(pk_pkg), + repo_id); + values = g_new0(gchar*, 2); + values[0] = pkg_id; + get_pk_det_from_array(values, &array, NULL); + if (!array || array->len < 1) { + goto done; + } + } + + KReturnInstance(cr, w); + + rc_stat = CMPI_RC_OK; + +done: + free_sw_package(&sw_pkg); + + if (values) { + g_strfreev(values); + } + if (array) { + g_ptr_array_unref(array); + } + if (pk_repo) { + g_object_unref(pk_repo); + } + if (pk_pkg) { + g_object_unref(pk_pkg); + } + + if (*error_msg) { + KReturn2(_cb, ERR_FAILED, "%s", error_msg); + } + + CMReturn(rc_stat); } static CMPIStatus LMI_ResourceForSoftwareIdentityCreateInstance( @@ -95,6 +368,190 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityAssociationCleanup( CMReturn(CMPI_RC_OK); } +static void enum_sw_instance_names_for_repo(const char *repo_id_p, + const CMPIResult *cr, const char *ns, char *error_msg, + const unsigned error_msg_len) +{ + PkPackage *pkg = NULL; + GPtrArray *pkg_array = NULL, *det_array = NULL, *repo_array = NULL, + *array = NULL; + gchar *repo_id = NULL, *pkg_id = NULL, **values = NULL; + const gchar *pkg_id_c = NULL; + short found; + unsigned i, j; + + /* Get all repos and packages. */ + get_pk_repos(&repo_array, error_msg, error_msg_len); + if (!repo_array) { + goto done; + } + + get_pk_packages(0, &pkg_array, error_msg, error_msg_len); + if (!pkg_array) { + goto done; + } + + /* Lets assume that there is about EST_OF_INSTD_PKGS installed packages + * (to avoid too many allocations) */ + array = g_ptr_array_new_full(EST_OF_INSTD_PKGS, g_object_unref); + + /* For every package, check repo. If found, and it is required repo, return + * SwIdentityRef instance. If repo for pkg is not found, save the pkg + * for next processing. */ + for (i = 0; i < pkg_array->len; i++) { + pkg = g_ptr_array_index(pkg_array, i); + found = 0; + for (j = 0; j < repo_array->len; j++) { + g_object_get(g_ptr_array_index(repo_array, j), "repo-id", &repo_id, + NULL); + if (strcmp(repo_id, pk_package_get_data(pkg)) == 0) { + found = 1; + if (strcmp(repo_id, repo_id_p) == 0) { + k_return_sw_identity_op_from_pkg_id(pk_package_get_id(pkg), + _cb, ns, cr); + } + break; + } + } + if (!found) { + g_ptr_array_add(array, g_object_ref(pkg)); + } + } + g_ptr_array_unref(pkg_array); + pkg_array = NULL; + g_ptr_array_unref(repo_array); + repo_array = NULL; + + /* For all saved packages, create package ID with required repo. + * Then, get package details for all those package IDs. Package details + * are returned only for valid package IDs... */ + j = 0; + values = g_new0(gchar*, array->len + 1); + for (i = 0; i < array->len; i++) { + pkg = g_ptr_array_index(array, i); + pkg_id = pk_package_id_build(pk_package_get_name(pkg), + pk_package_get_version(pkg), pk_package_get_arch(pkg), + repo_id_p); + values[j++] = pkg_id; + } + g_ptr_array_unref(array); + array = NULL; + + get_pk_det_from_array(values, &det_array, NULL); + g_strfreev(values); + values = NULL; + + if (det_array && det_array->len > 0) { + for (i = 0; i < det_array->len; i++) { + pkg_id_c = pk_details_get_package_id(g_ptr_array_index(det_array, i)); + k_return_sw_identity_op_from_pkg_id(pkg_id_c, _cb, ns, cr); + } + g_ptr_array_unref(det_array); + det_array = NULL; + } + +done: + return; +} + +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] = ""; + + if (!cm_class_is_a(_cb, KNameSpace(cop), assocClass, + ORGID "_" RESOURCE_FOR_SW_IDENTITY_CLASS_NAME)) { + goto done; + } + + if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME, &st)) { + /* got SoftwareIdentityResource - AvailableSAP; + * 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, AVAIL_SAP_ATTR) != 0) { + goto done; + } + if (resultRole && strcmp(resultRole, MNGD_ELEM_ATTR) != 0) { + goto done; + } + + enum_sw_instance_names_for_repo(get_str_property_from_op(cop, "Name"), + cr, KNameSpace(cop), error_msg, ERROR_MSG_LEN); + } else if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_CLASS_NAME, &st)) { + /* got SoftwareIdentity - ManagedElement */ + SwPackage sw_pkg; + gchar *repo_id = NULL; + + if (cm_class_is_a(_cb, KNameSpace(cop), resultClass, + ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME) != 0) { + goto done; + } + if (role && strcmp(role, MNGD_ELEM_ATTR) != 0) { + goto done; + } + if (resultRole && strcmp(resultRole, AVAIL_SAP_ATTR) != 0) { + goto done; + } + + init_sw_package(&sw_pkg); + get_sw_pkg_from_sw_identity_op(cop, &sw_pkg); + get_repo_id_from_sw_pkg(&sw_pkg, &repo_id, error_msg, ERROR_MSG_LEN); + free_sw_package(&sw_pkg); + + if (*error_msg) { + goto done; + } + if (!repo_id) { + /* We don't know the repository - package can be installed from + * local source, etc.. I don't think this is an error. */ + goto done; + } + + LMI_SoftwareIdentityResourceRef sir; + LMI_SoftwareIdentityResourceRef_Init(&sir, _cb, KNameSpace(cop)); + LMI_SoftwareIdentityResourceRef_Set_SystemName(&sir, get_system_name()); + LMI_SoftwareIdentityResourceRef_Set_CreationClassName(&sir, + ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME); + LMI_SoftwareIdentityResourceRef_Set_SystemCreationClassName(&sir, + get_system_creation_class_name()); + LMI_SoftwareIdentityResourceRef_Set_Name(&sir, repo_id); + + g_free(repo_id); + repo_id = NULL; + + if (names) { + KReturnObjectPath(cr, sir); + } else { + CMPIObjectPath *o = LMI_SoftwareIdentityResourceRef_ToObjectPath(&sir, &st); + 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_ResourceForSoftwareIdentityAssociators( CMPIAssociationMI* mi, const CMPIContext* cc, @@ -106,18 +563,8 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityAssociators( const char* resultRole, const char** properties) { - return KDefaultAssociators( - _cb, - mi, - cc, - cr, - cop, - LMI_ResourceForSoftwareIdentity_ClassName, - assocClass, - resultClass, - role, - resultRole, - properties); + return associators(cc, cr, cop, assocClass, resultClass, role, + resultRole, properties, 0); } static CMPIStatus LMI_ResourceForSoftwareIdentityAssociatorNames( @@ -130,17 +577,89 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityAssociatorNames( const char* role, const char* resultRole) { - return KDefaultAssociatorNames( - _cb, - mi, - cc, - cr, - cop, - LMI_ResourceForSoftwareIdentity_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; + char error_msg[ERROR_MSG_LEN] = ""; + + if (!cm_class_is_a(_cb, KNameSpace(cop), assocClass, + ORGID "_" RESOURCE_FOR_SW_IDENTITY_CLASS_NAME)) { + goto done; + } + + if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME, &st)) { + /* got SoftwareIdentityResource - AvailableSAP */ + if (role && strcmp(role, AVAIL_SAP_ATTR) != 0) { + goto done; + } + + return enum_instances(cr, KNameSpace(cop), names, + get_str_property_from_op(cop, "Name")); + } else if (CMClassPathIsA(_cb, cop, ORGID "_" SW_IDENTITY_CLASS_NAME, &st)) { + /* got SoftwareIdentity - ManagedElement */ + SwPackage sw_pkg; + gchar *repo_id = NULL; + + if (role && strcmp(role, MNGD_ELEM_ATTR) != 0) { + goto done; + } + + init_sw_package(&sw_pkg); + get_sw_pkg_from_sw_identity_op(cop, &sw_pkg); + get_repo_id_from_sw_pkg(&sw_pkg, &repo_id, error_msg, ERROR_MSG_LEN); + free_sw_package(&sw_pkg); + + if (*error_msg) { + goto done; + } + if (!repo_id) { + /* We don't know the repository - package can be installed from + * local source, etc.. I don't think this is an error. */ + goto done; + } + + LMI_SoftwareIdentityResourceRef sir; + LMI_SoftwareIdentityResourceRef_Init(&sir, _cb, KNameSpace(cop)); + LMI_SoftwareIdentityResourceRef_Set_SystemName(&sir, get_system_name()); + LMI_SoftwareIdentityResourceRef_Set_CreationClassName(&sir, + ORGID "_" SW_IDENTITY_RESOURCE_CLASS_NAME); + LMI_SoftwareIdentityResourceRef_Set_SystemCreationClassName(&sir, + get_system_creation_class_name()); + LMI_SoftwareIdentityResourceRef_Set_Name(&sir, repo_id); + + g_free(repo_id); + repo_id = NULL; + + LMI_SoftwareIdentityRef si; + LMI_SoftwareIdentityRef_InitFromObjectPath(&si, _cb, cop); + + LMI_ResourceForSoftwareIdentity rfsi; + LMI_ResourceForSoftwareIdentity_Init(&rfsi, _cb, KNameSpace(cop)); + LMI_ResourceForSoftwareIdentity_Set_AvailableSAP(&rfsi, &sir); + LMI_ResourceForSoftwareIdentity_Set_ManagedElement(&rfsi, &si); + + if (names) { + KReturnObjectPath(cr, rfsi); + } else { + KReturnInstance(cr, rfsi); + } + } + +done: + if (*error_msg) { + KReturn2(_cb, ERR_FAILED, "%s", error_msg); + } + + CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_ResourceForSoftwareIdentityReferences( @@ -152,16 +671,7 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityReferences( const char* role, const char** properties) { - return KDefaultReferences( - _cb, - mi, - cc, - cr, - cop, - LMI_ResourceForSoftwareIdentity_ClassName, - assocClass, - role, - properties); + return references(cr, cop, assocClass, role, 0); } static CMPIStatus LMI_ResourceForSoftwareIdentityReferenceNames( @@ -172,28 +682,20 @@ static CMPIStatus LMI_ResourceForSoftwareIdentityReferenceNames( const char* assocClass, const char* role) { - return KDefaultReferenceNames( - _cb, - mi, - cc, - cr, - cop, - LMI_ResourceForSoftwareIdentity_ClassName, - assocClass, - role); + return references(cr, cop, assocClass, role, 1); } CMInstanceMIStub( LMI_ResourceForSoftwareIdentity, LMI_ResourceForSoftwareIdentity, _cb, - LMI_ResourceForSoftwareIdentityInitialize()) + LMI_ResourceForSoftwareIdentityInitialize(ctx)) CMAssociationMIStub( LMI_ResourceForSoftwareIdentity, LMI_ResourceForSoftwareIdentity, _cb, - LMI_ResourceForSoftwareIdentityInitialize()) + LMI_ResourceForSoftwareIdentityInitialize(ctx)) KONKRET_REGISTRATION( "root/cimv2", diff --git a/src/software-dbus/LMI_SoftwareIdentityProvider.c b/src/software-dbus/LMI_SoftwareIdentityProvider.c index 7e03bad..2936555 100644 --- a/src/software-dbus/LMI_SoftwareIdentityProvider.c +++ b/src/software-dbus/LMI_SoftwareIdentityProvider.c @@ -89,7 +89,7 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance( goto done; } - get_pk_det_from_pk_pkg(pk_pkg, &pk_det); + get_pk_det_from_pk_pkg(pk_pkg, &pk_det, NULL); create_instance_from_pkgkit_data(pk_pkg, pk_det, &sw_pkg, _cb, KNameSpace(cop), &w); diff --git a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c index d321b30..4c77bf5 100644 --- a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c +++ b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c @@ -56,9 +56,6 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances( const CMPIObjectPath* cop, const char** properties) { - PkTask *task = NULL; - PkResults *results = NULL; - GError *gerror = NULL; GPtrArray *array = NULL; gboolean repo_enabled; gchar *repo_id = NULL, *repo_desc = NULL; @@ -66,15 +63,11 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances( char error_msg[ERROR_MSG_LEN] = "", dsc[DSC_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; - task = pk_task_new(); - - results = pk_task_get_repo_list_sync(task, 0, NULL, NULL, NULL, &gerror); - if (check_and_create_error_msg(results, gerror, - "Getting list of repositories failed", error_msg, ERROR_MSG_LEN)) { + get_pk_repos(&array, error_msg, ERROR_MSG_LEN); + if (!array) { goto done; } - array = pk_results_get_repo_detail_array(results); for (i = 0; i < array->len; i++) { g_object_get(g_ptr_array_index(array, i), "repo-id", &repo_id, "description", &repo_desc, "enabled", &repo_enabled, NULL); @@ -134,17 +127,9 @@ static CMPIStatus LMI_SoftwareIdentityResourceEnumInstances( } done: - g_clear_error(&gerror); - if (array) { g_ptr_array_unref(array); } - if (results) { - g_object_unref(results); - } - if (task) { - g_object_unref(task); - } if (repo_id) { g_free(repo_id); } diff --git a/src/software-dbus/sw-utils.c b/src/software-dbus/sw-utils.c index 76ca58b..e523fd2 100644 --- a/src/software-dbus/sw-utils.c +++ b/src/software-dbus/sw-utils.c @@ -49,27 +49,36 @@ void free_sw_package(SwPackage *pkg) init_sw_package(pkg); } -short create_sw_package_from_pk_pkg(PkPackage *pk_pkg, SwPackage *sw_pkg) +short create_sw_package_from_pk_pkg_id(const char *pk_pkg_id, SwPackage *sw_pkg) { short ret = -1; char *delim; - const char *id, *name, *arch, *ver; + const gchar *id, *name, *arch, *ver; + gchar **split_id = NULL; init_sw_package(sw_pkg); - if (!(id = pk_package_get_id(pk_pkg))) { - warn("Package without ID!"); + if (!pk_pkg_id || !*pk_pkg_id) { + warn("Empty package ID!"); + goto done; + } + + id = pk_pkg_id; + split_id = pk_package_id_split(id); + if (!split_id) { + warn("Invalid package ID: %s!", id); goto done; } - if (!(name = pk_package_get_name(pk_pkg))) { + + if (!(name = split_id[PK_PACKAGE_ID_NAME])) { warn("Package with ID: %s doesn't have name!", id); goto done; } - if (!(ver = pk_package_get_version(pk_pkg))) { + if (!(ver = split_id[PK_PACKAGE_ID_VERSION])) { warn("Package with ID: %s doesn't have version!", id); goto done; } - if (!(arch = pk_package_get_arch(pk_pkg))) { + if (!(arch = split_id[PK_PACKAGE_ID_ARCH])) { warn("Package with ID: %s doesn't have architecture!", id); goto done; } @@ -110,6 +119,11 @@ done: return ret; } +short create_sw_package_from_pk_pkg(PkPackage *pk_pkg, SwPackage *sw_pkg) +{ + return create_sw_package_from_pk_pkg_id(pk_package_get_id(pk_pkg), sw_pkg); +} + short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg) { short ret = -1; @@ -266,30 +280,21 @@ done: return; } -void get_pk_det_from_pk_pkg(PkPackage *pk_pkg, PkDetails **pk_det) +void get_pk_det_from_pk_pkg(PkPackage *pk_pkg, PkDetails **pk_det, PkTask *task_p) { - PkTask *task = NULL; PkDetails *item = NULL; - PkResults *results = NULL; GPtrArray *array = NULL; - GError *gerror = NULL; gchar **values = NULL; unsigned i; - char error_msg[ERROR_MSG_LEN] = ""; - - task = pk_task_new(); values = g_new0(gchar*, 2); values[0] = g_strdup(pk_package_get_id(pk_pkg)); - results = pk_task_get_details_sync(task, values, NULL, NULL, NULL, &gerror); - if (check_and_create_error_msg(results, gerror, - "Getting package details failed", error_msg, ERROR_MSG_LEN)) { - warn(error_msg); + get_pk_det_from_array(values, &array, task_p); + if (!array) { goto done; } - array = pk_results_get_details_array(results); for (i = 0; i < array->len; i++) { item = g_ptr_array_index(array, i); if (strcmp(pk_details_get_package_id(item), @@ -301,17 +306,10 @@ void get_pk_det_from_pk_pkg(PkPackage *pk_pkg, PkDetails **pk_det) done: g_strfreev(values); - g_clear_error(&gerror); if (array) { g_ptr_array_unref(array); } - if (results) { - g_object_unref(results); - } - if (task) { - g_object_unref(task); - } return; } @@ -403,39 +401,133 @@ done: return; } -void enum_sw_identity_instance_names(PkBitfield filters, const CMPIBroker *cb, - const char *ns, const CMPIResult* cr, char *error_msg, - const unsigned error_msg_len) +void get_pk_det_from_array(const char **values_p, GPtrArray **garray, + PkTask *task_p) +{ + PkTask *task = NULL; + PkResults *results = NULL; + GPtrArray *array = NULL, *array2 = NULL; + GError *gerror = NULL; + gchar **values = NULL; + unsigned i, j, values_p_count = 0; + char error_msg[ERROR_MSG_LEN] = ""; + + if (!values_p || !*values_p) { + warn("No package IDs given."); + goto done; + } + + while (values_p[++values_p_count]); + + if (task_p) { + task = task_p; + } else { + task = pk_task_new(); + } + + if (values_p_count < PK_DETAILS_LIMIT) { + values = g_new0(gchar*, values_p_count + 1); + } else { + values = g_new0(gchar*, PK_DETAILS_LIMIT + 1); + } + + for (i = 0; i < values_p_count / PK_DETAILS_LIMIT + 1; i++) { + j = 0; + while (values[j]) { + values[j++] = NULL; + } + + for (j = i * PK_DETAILS_LIMIT; + j < (i + 1) * PK_DETAILS_LIMIT && j < values_p_count; j++) { + values[j - i * PK_DETAILS_LIMIT] = values_p[j]; + } + + results = pk_task_get_details_sync(task, values, NULL, NULL, NULL, &gerror); + if (check_and_create_error_msg(results, gerror, + "Getting package details failed", error_msg, ERROR_MSG_LEN)) { + warn(error_msg); + goto done; + } + + array = pk_results_get_details_array(results); + gc_gobject_ptr_array_append(&array2, array); + + if (results) { + g_object_unref(results); + results = NULL; + } + if (array) { + g_ptr_array_unref(array); + array = NULL; + } + } + + g_ptr_array_sort(array2, (GCompareFunc) pk_det_cmp); + *garray = g_ptr_array_ref(array2); + +done: + g_clear_error(&gerror); + + if (values) { + g_free(values); + } + if (array) { + g_ptr_array_unref(array); + } + if (array2) { + g_ptr_array_unref(array2); + } + if (results) { + g_object_unref(results); + } + if (!task_p && task) { + g_object_unref(task); + } + + return; +} + +void k_return_sw_identity_op_from_pkg_id(const char *pkg_id, + const CMPIBroker *cb, const char *ns, const CMPIResult* cr) { - GPtrArray *array = NULL; SwPackage sw_pkg; - unsigned i; char elem_name[ELEM_NAME_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; init_sw_package(&sw_pkg); - get_pk_packages(filters, &array, error_msg, error_msg_len); - if (!array) { + if (create_sw_package_from_pk_pkg_id(pkg_id, &sw_pkg) != 0) { 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); - 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); - create_instance_id(SW_IDENTITY_CLASS_NAME, elem_name, instance_id, - INSTANCE_ID_LEN); + LMI_SoftwareIdentityRef w; + LMI_SoftwareIdentityRef_Init(&w, cb, ns); + LMI_SoftwareIdentityRef_Set_InstanceID(&w, instance_id); + KReturnObjectPath(cr, w); - free_sw_package(&sw_pkg); +done: + free_sw_package(&sw_pkg); +} + +void enum_sw_identity_instance_names(PkBitfield filters, const CMPIBroker *cb, + const char *ns, const CMPIResult* cr, char *error_msg, + const unsigned error_msg_len) +{ + GPtrArray *array = NULL; + unsigned i; + + get_pk_packages(filters, &array, error_msg, error_msg_len); + if (!array) { + goto done; + } - LMI_SoftwareIdentityRef w; - LMI_SoftwareIdentityRef_Init(&w, cb, ns); - LMI_SoftwareIdentityRef_Set_InstanceID(&w, instance_id); - KReturnObjectPath(cr, w); + for (i = 0; i < array->len; i++) { + k_return_sw_identity_op_from_pkg_id( + pk_package_get_id(g_ptr_array_index(array, i)), cb, ns, cr); } done: @@ -451,99 +543,145 @@ void enum_sw_identity_instances(PkBitfield filters, const CMPIBroker *cb, const unsigned error_msg_len) { LMI_SoftwareIdentity w; - PkTask *task = NULL; PkPackage *pk_pkg = NULL; PkDetails *pk_det = NULL; - PkResults *results = NULL; - GPtrArray *array = NULL, *array2 = NULL; - GError *gerror = NULL; + GPtrArray *pkg_array = NULL, *det_array = NULL; gchar **values = NULL; SwPackage sw_pkg; int cmpres; - unsigned i, j, a2i; + unsigned i, det_a_i = 0; init_sw_package(&sw_pkg); - get_pk_packages(filters, &array, error_msg, error_msg_len); - if (!array) { + get_pk_packages(filters, &pkg_array, error_msg, error_msg_len); + if (!pkg_array) { goto done; } - task = pk_task_new(); - - for (i = 0; i < array->len / PK_DETAILS_LIMIT + 1; i++) { - values = g_new0(gchar*, PK_DETAILS_LIMIT + 1); + values = g_new0(gchar*, pkg_array->len + 1); + for (i = 0; i < pkg_array->len; i++) { + values[i] = g_strdup(pk_package_get_id(g_ptr_array_index(pkg_array, i))); + } + get_pk_det_from_array(values, &det_array, NULL); + g_strfreev(values); + values = NULL; - for (j = i * PK_DETAILS_LIMIT; - j < (i + 1) * PK_DETAILS_LIMIT && j < array->len; j++) { - values[j - i * PK_DETAILS_LIMIT] = g_strdup(pk_package_get_id( - g_ptr_array_index(array, j))); + for (i = 0; i < pkg_array->len; i++) { + pk_pkg = g_ptr_array_index(pkg_array, i); + if (create_sw_package_from_pk_pkg(pk_pkg, &sw_pkg) != 0) { + continue; } - results = pk_task_get_details_sync(task, values, NULL, NULL, NULL, &gerror); - if (check_and_create_error_msg(results, 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(results); - g_ptr_array_sort(array2, (GCompareFunc) pk_det_cmp); + cmpres = -1; + if (det_array) { + while (cmpres < 0 && det_a_i < det_array->len) { + pk_det = g_ptr_array_index(det_array, det_a_i); + cmpres = strcmp(pk_details_get_package_id(pk_det), + pk_package_get_id(pk_pkg)); + if (cmpres < 0) { + /* this should not happen - + * we have spare unmatched package details */ + det_a_i++; + } else if (cmpres > 0) { + /* no matching package details for current pk_pkg */ + pk_det = NULL; + } else { + /* found a match */ + det_a_i++; + } + } } - g_strfreev(values); - values = NULL; + create_instance_from_pkgkit_data(pk_pkg, pk_det, &sw_pkg, cb, ns, &w); + KReturnInstance(cr, w); - a2i = 0; - for (j = i * PK_DETAILS_LIMIT; - j < (i + 1) * PK_DETAILS_LIMIT && j < array->len; j++) { - pk_pkg = g_ptr_array_index(array, j); - if (create_sw_package_from_pk_pkg(pk_pkg, &sw_pkg) != 0) { - continue; - } + free_sw_package(&sw_pkg); + } - cmpres = -1; - if (array2) { - while (cmpres < 0 && a2i < array2->len) { - pk_det = g_ptr_array_index(array2, a2i); - cmpres = strcmp(pk_details_get_package_id(pk_det), - pk_package_get_id(pk_pkg)); - if (cmpres < 0) { - /* this should not happen - - * we have spare unmatched package details */ - a2i++; - } else if (cmpres > 0) { - /* no matching package details for current pk_pkg */ - pk_det = NULL; - } else { - /* found a match */ - a2i++; - } - } - } +done: + if (det_array) { + g_ptr_array_unref(det_array); + } + if (pkg_array) { + g_ptr_array_unref(pkg_array); + } - create_instance_from_pkgkit_data(pk_pkg, pk_det, &sw_pkg, cb, ns, &w); - KReturnInstance(cr, w); + return; +} - free_sw_package(&sw_pkg); - } +/******************************************************************************* + * Functions related to PkRepos + ******************************************************************************/ - if (results) { - g_object_unref(results); - results = NULL; +void get_pk_repo(const char *repo_id_p, PkRepoDetail **repo_p, char *error_msg, + const unsigned error_msg_len) +{ + guint i; + gchar *repo_id = NULL; + PkRepoDetail *r; + GPtrArray *array = NULL; + + get_pk_repos(&array, error_msg, error_msg_len); + if (!array) { + warn(error_msg); + goto done; + } + + for (i = 0; i < array->len; i++) { + r = g_ptr_array_index(array, i); + g_object_get(r, "repo-id", &repo_id, NULL); + if (!repo_id) { + continue; } - if (array2) { - g_ptr_array_unref(array2); - array2 = NULL; + if (strcmp(repo_id, repo_id_p) == 0) { + *repo_p = g_object_ref(r); + break; } + g_free(repo_id); + repo_id = NULL; + } + +done: + if (repo_id) { + g_free(repo_id); + } + + if (array) { + g_ptr_array_unref(array); + } + + return; +} + +void get_pk_repos(GPtrArray **garray, char *error_msg, + const unsigned error_msg_len) +{ + PkTask *task = NULL; + PkResults *results = NULL; + GError *gerror = NULL; + GPtrArray *array = NULL; + + task = pk_task_new(); + + results = pk_task_get_repo_list_sync(task, 0, NULL, NULL, NULL, &gerror); + if (check_and_create_error_msg(results, gerror, + "Getting list of repositories failed", error_msg, error_msg_len)) { + goto done; } + array = pk_results_get_repo_detail_array(results); + g_ptr_array_sort(array, (GCompareFunc) pk_repo_cmp); + *garray = g_ptr_array_ref(array); + done: g_clear_error(&gerror); if (array) { g_ptr_array_unref(array); } + if (results) { + g_object_unref(results); + } if (task) { g_object_unref(task); } @@ -551,6 +689,88 @@ done: return; } +void get_repo_id_from_sw_pkg(const SwPackage *sw_pkg, gchar **repo_id_p, + char *error_msg, const unsigned error_msg_len) +{ + PkPackage *pk_pkg = NULL; + GPtrArray *repos = NULL, *det_array = NULL; + gchar *repo_id = NULL, *pkg_id = NULL, **values = NULL, **pkg_id_parts = NULL; + const gchar *repo_id_pkg = NULL, *pkg_id_c = NULL; + unsigned i, j; + + get_pk_repos(&repos, error_msg, error_msg_len); + if (!repos) { + goto done; + } + + get_pk_pkg_from_sw_pkg(sw_pkg, 0, &pk_pkg); + if (!pk_pkg) { + goto done; + } + + repo_id_pkg = pk_package_get_data(pk_pkg); + if (!repo_id_pkg) { + warn("Invalid PackageKit package."); + goto done; + } + + for (i = 0; i < repos->len; i++) { + g_object_get(g_ptr_array_index(repos, i), "repo_id", &repo_id, NULL); + if (strcmp(repo_id, repo_id_pkg) == 0) { + *repo_id_p = repo_id; + goto done; + } + g_free(repo_id); + repo_id = NULL; + } + + /* We didn't find the match - package is probably installed.. */ + j = 0; + values = g_new0(gchar*, repos->len + 1); + for (i = 0; i < repos->len; i++) { + g_object_get(g_ptr_array_index(repos, i), "repo_id", &repo_id, NULL); + pkg_id = pk_package_id_build(pk_package_get_name(pk_pkg), + pk_package_get_version(pk_pkg), pk_package_get_arch(pk_pkg), + repo_id); + values[j++] = pkg_id; + + g_free(repo_id); + repo_id = NULL; + } + + get_pk_det_from_array(values, &det_array, NULL); + + if (det_array && det_array->len > 0) { + for (i = 0; i < det_array->len; i++) { + pkg_id_c = pk_details_get_package_id(g_ptr_array_index(det_array, i)); + pkg_id_parts = pk_package_id_split(pkg_id_c); + if (!pkg_id_parts) { + continue; + } + if (!(*repo_id_p = g_strdup(pkg_id_parts[PK_PACKAGE_ID_DATA]))) { + warn("Memory allocation failed."); + } + goto done; + } + } + +done: + g_strfreev(values); + g_strfreev(pkg_id_parts); + + if (pk_pkg) { + g_object_unref(pk_pkg); + } + if (repos) { + g_ptr_array_unref(repos); + } + if (det_array) { + g_ptr_array_unref(det_array); + } + + return; +} + /******************************************************************************* * Functions related to PackageKit ******************************************************************************/ @@ -607,6 +827,46 @@ gint pk_det_cmp(gpointer a, gpointer b) return (gint) strcmp(pk_details_get_package_id(al), pk_details_get_package_id(bl)); } +gint pk_repo_cmp(gpointer a, gpointer b) +{ + gint res; + PkRepoDetail *al = *(PkRepoDetail **) a; + PkRepoDetail *bl = *(PkRepoDetail **) b; + gchar *repo_id_a = NULL, *repo_id_b = NULL; + + g_object_get(al, "repo-id", &repo_id_a, NULL); + g_object_get(bl, "repo-id", &repo_id_b, NULL); + + res = (gint) strcmp(repo_id_a, repo_id_b); + + g_free(repo_id_a); + g_free(repo_id_b); + + return res; +} + +/******************************************************************************* + * Functions related to Glib + ******************************************************************************/ + +void gc_gobject_ptr_array_append(GPtrArray **a, const GPtrArray *b) +{ + guint i; + + if (!a || !b) { + warn("Received empty parameter."); + return; + } + + if (!*a) { + *a = g_ptr_array_new_full(b->len, g_object_unref); + } + + for (i = 0; i < b->len; i++) { + g_ptr_array_add(*a, g_object_ref(g_ptr_array_index(b, i))); + } +} + /******************************************************************************* * Functions related to CMPI ******************************************************************************/ diff --git a/src/software-dbus/sw-utils.h b/src/software-dbus/sw-utils.h index 16e6ca1..a8a6565 100644 --- a/src/software-dbus/sw-utils.h +++ b/src/software-dbus/sw-utils.h @@ -39,16 +39,21 @@ #define PK_DETAILS_LIMIT 4999 +#define EST_OF_INSTD_PKGS 1000 + #define SW_IDENTITY_CLASS_NAME "SoftwareIdentity" #define SYSTEM_SW_COLLECTION_CLASS_NAME "SystemSoftwareCollection" #define SW_IDENTITY_RESOURCE_CLASS_NAME "SoftwareIdentityResource" #define MEM_SW_COLL_CLASS_NAME "MemberOfSoftwareCollection" #define INST_SW_IDENTITY_CLASS_NAME "InstalledSoftwareIdentity" +#define RESOURCE_FOR_SW_IDENTITY_CLASS_NAME "ResourceForSoftwareIdentity" #define COLLECTION_ATTR "Collection" #define MEMBER_ATTR "Member" #define SYSTEM_ATTR "System" #define INST_SW_ATTR "InstalledSoftware" +#define AVAIL_SAP_ATTR "AvailableSAP" +#define MNGD_ELEM_ATTR "ManagedElement" #define SW_IDENTITY_INSTANCE_ID_PREFIX ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":" #define SW_IDENTITY_INSTANCE_ID_PREFIX_LEN 25 @@ -86,6 +91,14 @@ void init_sw_package(SwPackage *pkg); void free_sw_package(SwPackage *pkg); /* + * Create SwPackage from PkPackage ID. + * @param pk_pkg PkPackage ID + * @param sw_pkg output package + * @return 0 on success, negative value otherwise + */ +short create_sw_package_from_pk_pkg_id(const char *pk_pkg_id, SwPackage *sw_pkg); + +/* * Create SwPackage from PkPackage. * @param pk_pkg source package * @param sw_pkg output package @@ -137,8 +150,10 @@ void get_pk_pkg_from_sw_pkg(const SwPackage *sw_pkg, PkBitfield filters, * Get PkDetails from PkPackage. * @param pk_pkg PkPackage * @param pk_det PkDetails, needs to be passed to g_object_unref() when not needed + * @param task_p if supplied, this task will be used when querying PackageKit; + * performance optimization, can be NULL */ -void get_pk_det_from_pk_pkg(PkPackage *pk_pkg, PkDetails **pk_det); +void get_pk_det_from_pk_pkg(PkPackage *pk_pkg, PkDetails **pk_det, PkTask *task_p); /* * Create LMI_SoftwareIdentity instance from data from PackageKit. @@ -168,6 +183,28 @@ void get_pk_packages(PkBitfield filters, GPtrArray **garray, char *error_msg, const unsigned error_msg_len); /* + * Get PkDetails for multiple package IDs. + * @param values_p array containing package IDs + * @param garray out array containing PkDetails; needs to be passed + * to g_ptr_array_unref() when not needed + * @param task_p if supplied, this task will be used when querying PackageKit; + * performance optimization, can be NULL + */ +void get_pk_det_from_array(const char **values_p, GPtrArray **garray, + PkTask *task_p); + +/* + * Return single SoftwareIdentityRef instance. This function calls KReturnInstance(), + * so instance is returned directly from within the function. + * @param pkg_id PkPackage ID + * @param cb CMPI Broker + * @param ns Namespace + * @param cr CMPI Result + */ +void k_return_sw_identity_op_from_pkg_id(const char *pkg_id, + const CMPIBroker *cb, const char *ns, const CMPIResult* cr); + +/* * Enumerate SoftwareIdentityRef instances. This function calls KReturnInstance(), * so instances are returned directly from within the function. * @param filters PackageKit filters @@ -196,6 +233,38 @@ void enum_sw_identity_instances(PkBitfield filters, const CMPIBroker *cb, const unsigned error_msg_len); /******************************************************************************* + * Functions related to PkRepos + ******************************************************************************/ +/* + * Get PkRepoDetail object according to repo ID. + * @param repo_id_p repo ID + * @param repo_p PkRepoDetail + * @param error_msg error message + * @param error_msg_len error message length + */ +void get_pk_repo(const char *repo_id_p, PkRepoDetail **repo_p, char *error_msg, + const unsigned error_msg_len); + +/* + * Get repositories from PackageKit. Output array is sorted. + * @param garray; needs to be passed to g_ptr_array_unref() when not needed + * @param error_msg error message + * @param error_msg_len error message length + */ +void get_pk_repos(GPtrArray **garray, char *error_msg, + const unsigned error_msg_len); + +/* + * Get repo ID from SwPackage. + * @param sw_pkg SwPackage + * @param repo_id; needs to be passed to free() when not needed + * @param error_msg error message + * @param error_msg_len error message length + */ +void get_repo_id_from_sw_pkg(const SwPackage *sw_pkg, gchar **repo_id, + char *error_msg, const unsigned error_msg_len); + +/******************************************************************************* * Functions related to PackageKit ******************************************************************************/ /* @@ -230,6 +299,26 @@ gint pk_pkg_cmp(gpointer a, gpointer b); */ gint pk_det_cmp(gpointer a, gpointer b); +/* + * Compare two PkRepoDetails according to the repo ID. + * @param a + * @param b + * @return negative integer if the a comes before the b, + * 0 if they are equal, + * or a positive integer if the a comes after the b + */ +gint pk_repo_cmp(gpointer a, gpointer b); + +/******************************************************************************* + * Functions related to Glib + ******************************************************************************/ +/* + * Append array b to the array a. a may be NULL. Works with GObjects only. + * @param a first array, may be NULL + * @param b second array + */ +void gc_gobject_ptr_array_append(GPtrArray **a, const GPtrArray *b); + /******************************************************************************* * Functions related to CMPI ******************************************************************************/ |