diff options
Diffstat (limited to 'src/software-dbus/sw-utils.c')
-rw-r--r-- | src/software-dbus/sw-utils.c | 123 |
1 files changed, 43 insertions, 80 deletions
diff --git a/src/software-dbus/sw-utils.c b/src/software-dbus/sw-utils.c index e523fd2..6b1424d 100644 --- a/src/software-dbus/sw-utils.c +++ b/src/software-dbus/sw-utils.c @@ -59,27 +59,27 @@ short create_sw_package_from_pk_pkg_id(const char *pk_pkg_id, SwPackage *sw_pkg) init_sw_package(sw_pkg); if (!pk_pkg_id || !*pk_pkg_id) { - warn("Empty package ID!"); + lmi_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); + lmi_warn("Invalid package ID: %s!", id); goto done; } if (!(name = split_id[PK_PACKAGE_ID_NAME])) { - warn("Package with ID: %s doesn't have name!", id); + lmi_warn("Package with ID: %s doesn't have name!", id); goto done; } if (!(ver = split_id[PK_PACKAGE_ID_VERSION])) { - warn("Package with ID: %s doesn't have version!", id); + lmi_warn("Package with ID: %s doesn't have version!", id); goto done; } if (!(arch = split_id[PK_PACKAGE_ID_ARCH])) { - warn("Package with ID: %s doesn't have architecture!", id); + lmi_warn("Package with ID: %s doesn't have architecture!", id); goto done; } @@ -99,13 +99,13 @@ short create_sw_package_from_pk_pkg_id(const char *pk_pkg_id, SwPackage *sw_pkg) } else { sw_pkg->version = strdup(ver); sw_pkg->release = strdup("0"); - warn("Package with ID: %s doesn't have release number! Using '0' instead.", + lmi_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."); + lmi_warn("Memory allocation failed."); goto done; } @@ -132,24 +132,24 @@ short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg) init_sw_package(sw_pkg); if (!elem_name || !*elem_name) { - warn("Empty element name."); + lmi_warn("Empty element name."); goto done; } if (!(en = strdup(elem_name))) { - warn("Memory allocation failed."); + lmi_warn("Memory allocation failed."); goto done; } if (!(delim = strrchr(en, '.'))) { - warn("Invalid element name of the package: %s", elem_name); + lmi_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); + lmi_warn("Invalid element name of the package: %s", elem_name); goto done; } sw_pkg->release = strdup(delim + 1); @@ -160,14 +160,14 @@ short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg) delim[0] = '\0'; if (!(delim = strrchr(en, '-'))) { - warn("Invalid element name of the package: %s", elem_name); + lmi_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); + lmi_warn("Invalid element name of the package: %s", elem_name); goto done; } sw_pkg->version = strdup(delim + 1); @@ -180,20 +180,20 @@ short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg) if (!sw_pkg->name || !sw_pkg->arch || !sw_pkg->epoch || !sw_pkg->version || !sw_pkg->release) { - warn("Memory allocation failed."); + lmi_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."); + lmi_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."); + lmi_warn("Memory allocation failed."); goto done; } } @@ -238,7 +238,7 @@ void get_pk_pkg_from_sw_pkg(const SwPackage *sw_pkg, PkBitfield filters, GError *gerror = NULL; gchar **values = NULL; unsigned i; - char error_msg[ERROR_MSG_LEN] = ""; + char error_msg[BUFLEN] = ""; task = pk_task_new(); @@ -247,8 +247,8 @@ void get_pk_pkg_from_sw_pkg(const SwPackage *sw_pkg, PkBitfield filters, results = pk_task_search_names_sync(task, filters, values, NULL, NULL, NULL, &gerror); if (check_and_create_error_msg(results, gerror, "Resolving package failed", - error_msg, ERROR_MSG_LEN)) { - warn(error_msg); + error_msg, BUFLEN)) { + lmi_warn(error_msg); goto done; } @@ -319,19 +319,19 @@ void create_instance_from_pkgkit_data(PkPackage *pk_pkg, PkDetails *pk_det, LMI_SoftwareIdentity *w) { const gchar *summary, *desc = NULL; - char elem_name[ELEM_NAME_LEN] = "", ver_str[VER_STR_LEN] = "", - instance_id[INSTANCE_ID_LEN] = ""; + char elem_name[BUFLEN] = "", ver_str[BUFLEN] = "", + instance_id[BUFLEN] = ""; summary = pk_package_get_summary(pk_pkg); if (pk_det) { desc = pk_details_get_description(pk_det); } - sw_pkg_get_element_name(sw_pkg, elem_name, ELEM_NAME_LEN); - sw_pkg_get_version_str(sw_pkg, ver_str, VER_STR_LEN); + sw_pkg_get_element_name(sw_pkg, elem_name, BUFLEN); + sw_pkg_get_version_str(sw_pkg, ver_str, BUFLEN); - create_instance_id(SW_IDENTITY_CLASS_NAME, elem_name, instance_id, - INSTANCE_ID_LEN); + create_instance_id(LMI_SoftwareIdentity_ClassName, elem_name, instance_id, + BUFLEN); LMI_SoftwareIdentity_Init(w, cb, ns); LMI_SoftwareIdentity_Set_InstanceID(w, instance_id); @@ -401,7 +401,7 @@ done: return; } -void get_pk_det_from_array(const char **values_p, GPtrArray **garray, +void get_pk_det_from_array(char **values_p, GPtrArray **garray, PkTask *task_p) { PkTask *task = NULL; @@ -410,10 +410,10 @@ void get_pk_det_from_array(const char **values_p, GPtrArray **garray, GError *gerror = NULL; gchar **values = NULL; unsigned i, j, values_p_count = 0; - char error_msg[ERROR_MSG_LEN] = ""; + char error_msg[BUFLEN] = ""; if (!values_p || !*values_p) { - warn("No package IDs given."); + lmi_warn("No package IDs given."); goto done; } @@ -444,8 +444,8 @@ void get_pk_det_from_array(const char **values_p, GPtrArray **garray, 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); + "Getting package details failed", error_msg, BUFLEN)) { + lmi_warn(error_msg); goto done; } @@ -491,7 +491,7 @@ void k_return_sw_identity_op_from_pkg_id(const char *pkg_id, const CMPIBroker *cb, const char *ns, const CMPIResult* cr) { SwPackage sw_pkg; - char elem_name[ELEM_NAME_LEN] = "", instance_id[INSTANCE_ID_LEN] = ""; + char elem_name[BUFLEN] = "", instance_id[BUFLEN] = ""; init_sw_package(&sw_pkg); @@ -499,10 +499,10 @@ void k_return_sw_identity_op_from_pkg_id(const char *pkg_id, goto done; } - sw_pkg_get_element_name(&sw_pkg, elem_name, ELEM_NAME_LEN); + sw_pkg_get_element_name(&sw_pkg, elem_name, BUFLEN); - create_instance_id(SW_IDENTITY_CLASS_NAME, elem_name, instance_id, - INSTANCE_ID_LEN); + create_instance_id(LMI_SoftwareIdentity_ClassName, elem_name, instance_id, + BUFLEN); LMI_SoftwareIdentityRef w; LMI_SoftwareIdentityRef_Init(&w, cb, ns); @@ -623,7 +623,7 @@ void get_pk_repo(const char *repo_id_p, PkRepoDetail **repo_p, char *error_msg, get_pk_repos(&array, error_msg, error_msg_len); if (!array) { - warn(error_msg); + lmi_warn(error_msg); goto done; } @@ -710,7 +710,7 @@ void get_repo_id_from_sw_pkg(const SwPackage *sw_pkg, gchar **repo_id_p, repo_id_pkg = pk_package_get_data(pk_pkg); if (!repo_id_pkg) { - warn("Invalid PackageKit package."); + lmi_warn("Invalid PackageKit package."); goto done; } @@ -748,7 +748,7 @@ void get_repo_id_from_sw_pkg(const SwPackage *sw_pkg, gchar **repo_id_p, continue; } if (!(*repo_id_p = g_strdup(pkg_id_parts[PK_PACKAGE_ID_DATA]))) { - warn("Memory allocation failed."); + lmi_warn("Memory allocation failed."); } goto done; } @@ -854,7 +854,7 @@ void gc_gobject_ptr_array_append(GPtrArray **a, const GPtrArray *b) guint i; if (!a || !b) { - warn("Received empty parameter."); + lmi_warn("Received empty parameter."); return; } @@ -874,18 +874,18 @@ void gc_gobject_ptr_array_append(GPtrArray **a, const GPtrArray *b) const char *get_elem_name_from_instance_id(const char *instance_id) { if (!instance_id || !*instance_id) { - warn("Empty InstanceID."); + lmi_warn("Empty InstanceID."); return ""; } if (strlen(instance_id) <= SW_IDENTITY_INSTANCE_ID_PREFIX_LEN) { - warn("Invalid InstanceID: %s", instance_id); + lmi_warn("Invalid InstanceID: %s", instance_id); return ""; } if (strncasecmp(instance_id, SW_IDENTITY_INSTANCE_ID_PREFIX, SW_IDENTITY_INSTANCE_ID_PREFIX_LEN) != 0) { - warn("Invalid InstanceID: %s", instance_id); + lmi_warn("Invalid InstanceID: %s", instance_id); return ""; } @@ -896,45 +896,8 @@ void create_instance_id(const char *class_name, const char *id, char *instance_id, const unsigned instance_id_len) { if (id) { - snprintf(instance_id, instance_id_len, ORGID ":" ORGID "_%s:%s", - class_name, id); + snprintf(instance_id, instance_id_len, LMI_ORGID ":%s:%s", class_name, id); } else { - snprintf(instance_id, instance_id_len, ORGID ":" ORGID "_%s", - class_name); + snprintf(instance_id, instance_id_len, LMI_ORGID ":%s", class_name); } } - -const char *get_str_property_from_op(const CMPIObjectPath *o, const char *prop) -{ - CMPIData d; - d = CMGetKey(o, prop, NULL); - return KChars(d.value.string); -} - -short cm_class_is_a(const CMPIBroker *cb, const char *ns, const char *cm_class, - const char *type) -{ - CMPIStatus st; - CMPIObjectPath *o = NULL; - short ret = 0; - - o = CMNewObjectPath(cb, ns, cm_class, &st); - if (!o) { - goto done; - } else if (st.rc != CMPI_RC_OK) { - goto done; - } - - if (type && !CMClassPathIsA(cb, o, type, &st)) { - goto done; - } - - ret = 1; - -done: - if (o) { - CMRelease(o); - } - - return ret; -} |