/* * 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 */ #ifndef SW_UTILS_H_ #define SW_UTILS_H_ #define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE #define VER_STR_LEN 256 #define ELEM_NAME_LEN 256 #define INSTANCE_ID_LEN 282 #define ERROR_MSG_LEN 512 #define PK_DETAILS_LIMIT 4999 #define SW_IDENTITY_CLASS_NAME "SoftwareIdentity" #include #include #include #include #include #include "globals.h" #include "LMI_SoftwareIdentity.h" const char *provider_name; const ConfigEntry *provider_config_defaults; /******************************************************************************* * SwPackage & related functions ******************************************************************************/ /* 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); /******************************************************************************* * Functions related to single PkPackage ******************************************************************************/ /* * Get PkPackage according to the SwPackage. * @param sw_pkg SwPackage * @param pk_pkg PkPackage; needs to be passed to g_object_unref() when not needed */ void get_pk_pkg_from_sw_pkg(const SwPackage *sw_pkg, PkPackage **pk_pkg); /* * Get PkDetails from PkPackage. * @param pk_pkg PkPackage * @param pk_det PkDetails, needs to be passed to g_object_unref() when not needed */ void get_pk_det_from_pk_pkg(PkPackage *pk_pkg, PkDetails **pk_det); /* * Create LMI_SoftwareIdentity instance from data from PackageKit. * @param pk_pkg PkPackage * @param pk_det PkDetials; can be NULL * @param sw_pkg SwPackage * @param cb CMPI Broker * @param ns CMPI namespace * @param w LMI_SoftwareIdentity */ void create_instance_from_pkgkit_data(PkPackage *pk_pkg, PkDetails *pk_det, SwPackage *sw_pkg, const CMPIBroker *cb, const char *ns, LMI_SoftwareIdentity *w); /******************************************************************************* * Functions related to multiple PkPackages ******************************************************************************/ /* * Enumerate SoftwareIdentity instances. This function calls KReturnInstance(), * so instances are returned directly from within the function. * @param filters PackageKit filters * @param cb CMPI Broker * @param ns Namespace * @param cr CMPI Result * @param error_msg error message, if filled, problem occured * @param error_msg_len error message length * @param names if true, this function will enumerate only SoftwareIdentityRef * instances */ void enum_sw_identity_instances(PkBitfield filters, const CMPIBroker *cb, const char *ns, const CMPIResult* cr, char *error_msg, const unsigned error_msg_len, const short names); /******************************************************************************* * Functions related to PackageKit ******************************************************************************/ /* * 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, GError *gerror, const char *custom_msg, char *error_msg, const unsigned error_msg_len); /* * Compare two PkPackage packages according to the package 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_pkg_cmp(gpointer a, gpointer b); /* * Compare two PkDetails according to the package 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_det_cmp(gpointer a, gpointer b); /******************************************************************************* * Functions related to CMPI ******************************************************************************/ /* * Create standard instance ID based on class name and ID. * @param class_name * @param id, may by null * @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); /* * Get string property from Object Path. * @param o Object Path * @param prop property * @return string value of property */ const char *get_str_property_from_op(const CMPIObjectPath *o, const char *prop); /* * Check whether cm_class is type of type. Takes inheritance into account. * @param cb CMPI Broker * @param ns namespace * @param cm_class * @param type; can be NULL, in which case the comparison will succeed * @return 1 if cm_class is type of type, 0 otherwise */ short cm_class_is_a(const CMPIBroker *cb, const char *ns, const char *cm_class, const char *type); #endif /* SW_UTILS_H_ */