summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2014-03-24 17:49:11 +0100
committerPeter Schiffer <pschiffe@redhat.com>2014-03-26 15:01:20 +0100
commit6560717c0211cd13949a5a2f1c5469cca103786c (patch)
tree1e73625e1f866ea493b76f9b4799cdb9d9628b93 /src
parenta7d7b281342b24146133f132867b3e1da276e923 (diff)
downloadopenlmi-providers-6560717c0211cd13949a5a2f1c5469cca103786c.tar.gz
openlmi-providers-6560717c0211cd13949a5a2f1c5469cca103786c.tar.xz
openlmi-providers-6560717c0211cd13949a5a2f1c5469cca103786c.zip
Software-dbus: Implemented SoftwareIdentity Provider
Implemented SoftwareIdentity Provider in Software-dbus using PackageKit.
Diffstat (limited to 'src')
-rw-r--r--src/software-dbus/CMakeLists.txt12
-rw-r--r--src/software-dbus/LMI_Software.h33
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityProvider.c208
-rw-r--r--src/software-dbus/sw-utils.c228
-rw-r--r--src/software-dbus/sw-utils.h116
5 files changed, 584 insertions, 13 deletions
diff --git a/src/software-dbus/CMakeLists.txt b/src/software-dbus/CMakeLists.txt
index 5febab2..5202c33 100644
--- a/src/software-dbus/CMakeLists.txt
+++ b/src/software-dbus/CMakeLists.txt
@@ -3,6 +3,10 @@ set(LIBRARY_NAME cmpiLMI_${PROVIDER_NAME})
set(MOF 60_LMI_Software.mof)
set(CIMPROVAGT_SCRIPT cmpiLMI_${PROVIDER_NAME}-cimprovagt)
+set(provider_SRCS
+ sw-utils.c
+)
+
konkretcmpi_generate(${MOF}
CIM_PROVIDERS
CIM_HEADERS
@@ -17,16 +21,15 @@ add_library(${LIBRARY_NAME} SHARED
${CIM_HEADERS}
)
-# Require libgio
-pkg_check_modules(GIO REQUIRED gio-2.0)
+pkg_check_modules(PACKAGEKIT REQUIRED packagekit-glib2)
include_directories(${CMAKE_CURRENT_BINARY_DIR}
${CMPI_INCLUDE_DIR}
- ${GIO_INCLUDE_DIRS})
+ ${PACKAGEKIT_INCLUDE_DIRS})
target_link_libraries(${LIBRARY_NAME}
openlmicommon
${KONKRETCMPI_LIBRARIES}
- ${GIO_LIBRARIES})
+ ${PACKAGEKIT_LIBRARIES})
# Create registration file
cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF} share/openlmi-providers)
@@ -37,4 +40,3 @@ profile_mof_generate("90_LMI_${PROVIDER_NAME}_Profile.mof.skel" "${TARGET_MOF}"
install(TARGETS ${LIBRARY_NAME} DESTINATION lib${LIB_SUFFIX}/cmpi)
install(PROGRAMS ${CIMPROVAGT_SCRIPT} DESTINATION libexec/pegasus)
install(FILES ${TARGET_MOF} DESTINATION share/openlmi-providers/)
-
diff --git a/src/software-dbus/LMI_Software.h b/src/software-dbus/LMI_Software.h
new file mode 100644
index 0000000..fff4714
--- /dev/null
+++ b/src/software-dbus/LMI_Software.h
@@ -0,0 +1,33 @@
+/*
+ * 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>
+ */
+
+#ifndef LMI_SOFTWARE_H_
+#define LMI_SOFTWARE_H_
+
+#include "sw-utils.h"
+
+#define VER_STR_LEN 256
+#define ELEM_NAME_LEN 256
+#define ERROR_MSG_LEN 512
+#define INSTANCE_ID_LEN 282
+
+#define SW_IDENTITY_CLASS_NAME "SoftwareIdentity"
+
+#endif /* LMI_SOFTWARE_H_ */
diff --git a/src/software-dbus/LMI_SoftwareIdentityProvider.c b/src/software-dbus/LMI_SoftwareIdentityProvider.c
index a2f6b1b..73a8ae5 100644
--- a/src/software-dbus/LMI_SoftwareIdentityProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityProvider.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_SoftwareIdentity.h"
+#include "LMI_Software.h"
static const CMPIBroker* _cb = NULL;
-static void LMI_SoftwareIdentityInitialize()
+static void LMI_SoftwareIdentityInitialize(const CMPIContext *ctx)
{
+ lmi_init(provider_name, _cb, ctx, provider_config_defaults);
}
static CMPIStatus LMI_SoftwareIdentityCleanup(
@@ -21,8 +43,60 @@ static CMPIStatus LMI_SoftwareIdentityEnumInstanceNames(
const CMPIResult* cr,
const CMPIObjectPath* cop)
{
- return KDefaultEnumerateInstanceNames(
- _cb, mi, cc, cr, cop);
+ PkTask *task = NULL;
+ PkResults *results = 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, NULL);
+ if (check_and_create_error_msg(results, "Getting list of packages failed",
+ error_msg, ERROR_MSG_LEN)) {
+ goto done;
+ }
+
+ array = pk_results_get_package_array(results);
+ 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:
+ 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(
@@ -32,7 +106,7 @@ static CMPIStatus LMI_SoftwareIdentityEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
- CMReturn(CMPI_RC_OK);
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
}
static CMPIStatus LMI_SoftwareIdentityGetInstance(
@@ -42,8 +116,126 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- return KDefaultGetInstance(
- _cb, mi, cc, cr, cop, properties);
+ PkTask *task = NULL;
+ PkPackage *pk_pkg = NULL;
+ PkDetails *pk_det = NULL;
+ PkResults *results = NULL, *results2 = NULL;
+ GPtrArray *array = NULL;
+ gchar **values = NULL;
+ SwPackage sw_pkg;
+ unsigned i, j;
+ short found = 0;
+ char error_msg[ERROR_MSG_LEN] = "", elem_name[ELEM_NAME_LEN] = "",
+ ver_str[VER_STR_LEN] = "";
+
+ init_sw_package(&sw_pkg);
+
+ LMI_SoftwareIdentity w;
+ LMI_SoftwareIdentity_InitFromObjectPath(&w, _cb, cop);
+
+ if (create_sw_package_from_elem_name(
+ w.InstanceID.chars + strlen(
+ ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"), &sw_pkg) != 0) {
+ snprintf(error_msg, ERROR_MSG_LEN, "Failed to parse instance ID: %s",
+ w.InstanceID.chars);
+ 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, NULL);
+ if (check_and_create_error_msg(results, "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;
+ }
+
+ sw_pkg_get_element_name(&sw_pkg, elem_name, ELEM_NAME_LEN);
+ sw_pkg_get_version_str(&sw_pkg, ver_str, VER_STR_LEN);
+
+ LMI_SoftwareIdentity_Init_Classifications(&w, 1);
+ LMI_SoftwareIdentity_Set_Classifications(&w, 0, 0);
+ LMI_SoftwareIdentity_Init_TargetTypes(&w, 2);
+ LMI_SoftwareIdentity_Set_TargetTypes(&w, 0, "rpm");
+ LMI_SoftwareIdentity_Set_TargetTypes(&w, 1, "yum");
+ LMI_SoftwareIdentity_Set_IsEntity(&w, 1);
+
+ LMI_SoftwareIdentity_Set_Architecture(&w, sw_pkg.arch);
+ LMI_SoftwareIdentity_Set_ElementName(&w, elem_name);
+ LMI_SoftwareIdentity_Set_Epoch(&w, atoi(sw_pkg.epoch));
+ LMI_SoftwareIdentity_Set_Name(&w, sw_pkg.name);
+ LMI_SoftwareIdentity_Set_Release(&w, sw_pkg.release);
+ LMI_SoftwareIdentity_Set_Version(&w, sw_pkg.version);
+ LMI_SoftwareIdentity_Set_VersionString(&w, ver_str);
+ LMI_SoftwareIdentity_Set_Caption(&w, pk_package_get_summary(pk_pkg));
+
+ 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, NULL);
+ if (check_and_create_error_msg(results2, "Getting package details failed",
+ error_msg, ERROR_MSG_LEN)) {
+ goto done;
+ }
+
+ g_ptr_array_unref(array);
+ array = pk_results_get_details_array(results2);
+ for (j = 0; j < array->len; j++) {
+ pk_det = g_ptr_array_index(array, j);
+ if (strcmp(pk_details_get_package_id(pk_det),
+ pk_package_get_id(pk_pkg)) == 0) {
+ LMI_SoftwareIdentity_Set_Description(&w,
+ pk_details_get_description(pk_det));
+ break;
+ }
+ }
+
+ KReturnInstance(cr, w);
+
+done:
+ free_sw_package(&sw_pkg);
+
+ g_strfreev(values);
+
+ 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 (*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(
@@ -91,7 +283,7 @@ CMInstanceMIStub(
LMI_SoftwareIdentity,
LMI_SoftwareIdentity,
_cb,
- LMI_SoftwareIdentityInitialize())
+ LMI_SoftwareIdentityInitialize(ctx))
static CMPIStatus LMI_SoftwareIdentityMethodCleanup(
CMPIMethodMI* mi,
@@ -118,7 +310,7 @@ CMMethodMIStub(
LMI_SoftwareIdentity,
LMI_SoftwareIdentity,
_cb,
- LMI_SoftwareIdentityInitialize())
+ LMI_SoftwareIdentityInitialize(ctx))
KONKRET_REGISTRATION(
"root/cimv2",
diff --git a/src/software-dbus/sw-utils.c b/src/software-dbus/sw-utils.c
new file mode 100644
index 0000000..f10d891
--- /dev/null
+++ b/src/software-dbus/sw-utils.c
@@ -0,0 +1,228 @@
+/*
+ * 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 "sw-utils.h"
+
+const char *provider_name = "software";
+const ConfigEntry *provider_config_defaults = NULL;
+
+void init_sw_package(SwPackage *pkg)
+{
+ pkg->name = NULL;
+ pkg->epoch = NULL;
+ pkg->version = NULL;
+ pkg->release = NULL;
+ pkg->arch = NULL;
+ pkg->pk_version = NULL;
+}
+
+void free_sw_package(SwPackage *pkg)
+{
+ free(pkg->name);
+ free(pkg->epoch);
+ free(pkg->version);
+ free(pkg->release);
+ free(pkg->arch);
+ free(pkg->pk_version);
+
+ init_sw_package(pkg);
+}
+
+short create_sw_package_from_pk_pkg(PkPackage *pk_pkg, SwPackage *sw_pkg)
+{
+ short ret = -1;
+ char *delim;
+ const char *id, *name, *arch, *ver;
+
+ init_sw_package(sw_pkg);
+
+ if (!(id = pk_package_get_id(pk_pkg))) {
+ warn("Package without ID!");
+ goto done;
+ }
+ if (!(name = pk_package_get_name(pk_pkg))) {
+ warn("Package with ID: %s doesn't have name!", id);
+ goto done;
+ }
+ if (!(ver = pk_package_get_version(pk_pkg))) {
+ warn("Package with ID: %s doesn't have version!", id);
+ goto done;
+ }
+ if (!(arch = pk_package_get_arch(pk_pkg))) {
+ warn("Package with ID: %s doesn't have architecture!", id);
+ goto done;
+ }
+
+ sw_pkg->name = strdup(name);
+ sw_pkg->arch = strdup(arch);
+ sw_pkg->pk_version = strdup(ver);
+
+ if ((delim = strchr(ver, ':'))) {
+ sw_pkg->epoch = strndup(ver, delim - ver);
+ ver = delim + 1;
+ } else {
+ sw_pkg->epoch = strdup("0");
+ }
+ if ((delim = strrchr(ver, '-'))) {
+ sw_pkg->version = strndup(ver, delim - ver);
+ sw_pkg->release = strdup(delim + 1);
+ } else {
+ sw_pkg->version = strdup(ver);
+ sw_pkg->release = strdup("0");
+ warn("Package with ID: %s doesn't have release number! Using '0' instead.",
+ id);
+ }
+
+ if (!sw_pkg->name || !sw_pkg->arch || !sw_pkg->epoch || !sw_pkg->version
+ || !sw_pkg->release || !sw_pkg->pk_version) {
+ warn("Memory allocation failed.");
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ if (ret != 0) {
+ free_sw_package(sw_pkg);
+ }
+
+ return ret;
+}
+
+short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg)
+{
+ short ret = -1;
+ char *en, *delim;
+
+ init_sw_package(sw_pkg);
+
+ if (!(en = strdup(elem_name))) {
+ warn("Memory allocation failed.");
+ goto done;
+ }
+
+ if (!(delim = strrchr(en, '.'))) {
+ warn("Invalid element name of the package: %s", elem_name);
+ goto done;
+ }
+ sw_pkg->arch = strdup(delim + 1);
+ delim[0] = '\0';
+
+ if (!(delim = strrchr(en, '-'))) {
+ warn("Invalid element name of the package: %s", elem_name);
+ goto done;
+ }
+ sw_pkg->release = strdup(delim + 1);
+ delim[0] = '\0';
+
+ if ((delim = strrchr(en, ':'))) {
+ sw_pkg->version = strdup(delim + 1);
+ delim[0] = '\0';
+
+ if (!(delim = strrchr(en, '-'))) {
+ warn("Invalid element name of the package: %s", elem_name);
+ goto done;
+ }
+ sw_pkg->epoch = strdup(delim + 1);
+ delim[0] = '\0';
+ } else {
+ if (!(delim = strrchr(en, '-'))) {
+ warn("Invalid element name of the package: %s", elem_name);
+ goto done;
+ }
+ sw_pkg->version = strdup(delim + 1);
+ delim[0] = '\0';
+
+ sw_pkg->epoch = strdup("0");
+ }
+
+ sw_pkg->name = strdup(en);
+
+ if (!sw_pkg->name || !sw_pkg->arch || !sw_pkg->epoch || !sw_pkg->version
+ || !sw_pkg->release) {
+ warn("Memory allocation failed.");
+ goto done;
+ }
+
+ if (strcmp(sw_pkg->epoch, "0") == 0) {
+ if (asprintf(&sw_pkg->pk_version, "%s-%s", sw_pkg->version,
+ sw_pkg->release) < 0) {
+ warn("Memory allocation failed.");
+ goto done;
+ }
+ } else {
+ if (asprintf(&sw_pkg->pk_version, "%s:%s-%s", sw_pkg->epoch,
+ sw_pkg->version, sw_pkg->release) < 0) {
+ warn("Memory allocation failed.");
+ goto done;
+ }
+ }
+
+ ret = 0;
+
+done:
+ free(en);
+
+ if (ret != 0) {
+ free_sw_package(sw_pkg);
+ }
+
+ return ret;
+}
+
+void sw_pkg_get_version_str(const SwPackage *pkg, char *ver_str,
+ const unsigned ver_str_len)
+{
+ snprintf(ver_str, ver_str_len, "%s:%s-%s.%s", pkg->epoch, pkg->version,
+ pkg->release, pkg->arch);
+}
+
+void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
+ const unsigned elem_name_len)
+{
+ snprintf(elem_name, elem_name_len, "%s-%s:%s-%s.%s", pkg->name, pkg->epoch,
+ pkg->version, pkg->release, pkg->arch);
+}
+
+short check_and_create_error_msg(PkResults *results, const char *custom_msg,
+ char *error_msg, const unsigned error_msg_len)
+{
+ short ret = 0;
+ PkError *error_code = NULL;
+
+ error_code = pk_results_get_error_code(results);
+ if (error_code) {
+ snprintf(error_msg, error_msg_len,
+ "%s: %s, %s", custom_msg,
+ pk_error_enum_to_string(pk_error_get_code(error_code)),
+ pk_error_get_details(error_code));
+ g_object_unref(error_code);
+ ret = 1;
+ }
+
+ return ret;
+}
+
+void create_instance_id(const char *class_name, const char *id,
+ char *instance_id, const unsigned instance_id_len)
+{
+ snprintf(instance_id, instance_id_len, ORGID ":" ORGID "_%s:%s",
+ class_name, id);
+}
diff --git a/src/software-dbus/sw-utils.h b/src/software-dbus/sw-utils.h
new file mode 100644
index 0000000..e5eb150
--- /dev/null
+++ b/src/software-dbus/sw-utils.h
@@ -0,0 +1,116 @@
+/*
+ * 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>
+ */
+
+#ifndef SW_UTILS_H_
+#define SW_UTILS_H_
+
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <packagekit-glib2/packagekit.h>
+
+#include "globals.h"
+
+const char *provider_name;
+const ConfigEntry *provider_config_defaults;
+
+/* Software Package */
+typedef struct _SwPackage {
+ char *name; /* Package name w/o anything else */
+ char *epoch; /* Epoch number */
+ char *version; /* Version number, w/o epoch or release */
+ char *release; /* Release number */
+ char *arch; /* Architecture */
+ char *pk_version; /* PackageKit style package version - (epoch:)?version-release */
+} SwPackage;
+
+/*
+ * Initialize SwPackage structure.
+ * @param pkg SwPackage
+ */
+void init_sw_package(SwPackage *pkg);
+
+/*
+ * Free SwPackage structure.
+ * @param pkg SwPackage
+ */
+void free_sw_package(SwPackage *pkg);
+
+/*
+ * Create SwPackage from PkPackage.
+ * @param pk_pkg source package
+ * @param sw_pkg output package
+ * @return 0 on success, negative value otherwise
+ */
+short create_sw_package_from_pk_pkg(PkPackage *pk_pkg, SwPackage *sw_pkg);
+
+/*
+ * Create SwPackage from element name.
+ * @param elem_name element name in format name-(epoch:)?version-release.arch
+ * @param sw_pkg output package
+ * @return 0 on success, negative value otherwise
+ */
+short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg);
+
+/*
+ * Construct version name in format epoch:version-release.arch for
+ * SwPackage structure.
+ * @param pkg SwPackage
+ * @param ver_str version string
+ * @param ver_str_len length of version string
+ */
+void sw_pkg_get_version_str(const SwPackage *pkg, char *ver_str,
+ const unsigned ver_str_len);
+
+/*
+ * Construct element name in format name-epoch:version-release.arch for
+ * SwPackage structure.
+ * @param pkg SwPackage
+ * @param elem_name element name string
+ * @param elem_name_len length of element name string
+ */
+void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
+ const unsigned elem_name_len);
+
+/*
+ * Analyze PkResults and construct error message if error occurred.
+ * @param results from package kit call
+ * @param custom_msg message preceding error message from package kit
+ * @param error_msg final error message
+ * @param error_msg_len length of error_msg
+ * @return 0 if no error occurred, positive value if error occurred
+ * and error_msg was modified
+ */
+short check_and_create_error_msg(PkResults *results, const char *custom_msg,
+ char *error_msg, const unsigned error_msg_len);
+
+/*
+ * Create standard instance ID based on class name and ID.
+ * @param class_name
+ * @param id
+ * @param instance_id output string
+ * @param instance_id_len length of output string
+ */
+void create_instance_id(const char *class_name, const char *id,
+ char *instance_id, const unsigned instance_id_len);
+
+#endif /* SW_UTILS_H_ */