From b1d9f7a8b7a870f8e210ce45728c85fdb2e79d23 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Wed, 31 Jan 2024 13:14:20 +0900 Subject: [PATCH] Add pkgmgrinfo_pkginfo_get_metadata_value() Change-Id: I412a0aeb60248bd31f332e4877daf85dcab92edb Signed-off-by: Sangyoon Jang --- include/pkgmgr-info.h | 36 ++++++++++++++++++++++++++++++++++++ src/pkgmgrinfo_pkginfo.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/include/pkgmgr-info.h b/include/pkgmgr-info.h index ee8cb74..d0eea1a 100644 --- a/include/pkgmgr-info.h +++ b/include/pkgmgr-info.h @@ -1794,6 +1794,42 @@ static int get_support_mode(const char *pkgid) int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode); /** + * @fn int pkgmgrinfo_pkginfo_get_metadata_value(pkgmgrinfo_pkginfo_h handle, const char *metadata_key, char **metadata_value) + * @brief This API gets metadata value by given metadata key + * + * @par Sync (or) Async : Synchronous API + * + * @param[in] handle pointer to the package info handle + * @param[in] metadata_key metadata key + * @param[out] metadata_value pointer to hold metadata value + * @return 0 if success, error code(<0) if fail + * @retval PMINFO_R_OK success + * @retval PMINFO_R_EINVAL invalid argument + * @code +static int get_metadata_value(const char *pkgid, const char *metadata_key) +{ + int ret = 0; + pkgmgrinfo_pkginfo_h handle = NULL; + char *metadata_value = NULL; + + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); + if (ret != PMINFO_R_OK) + return -1; + + ret = pkgmgrinfo_pkginfo_get_metadata_value(handle, metadata_key, &metadata_value); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return -1; + } + + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return 0; +} + * @endcode + */ +int pkgmgrinfo_pkginfo_get_metadata_value(pkgmgrinfo_pkginfo_h handle, const char *metadata_key, char **metadata_value); + +/** * @fn int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, pkgmgrinfo_cert_compare_result_type_e *compare_result) * @brief This API compare the cert information from given package id * diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index 8d7a8a3..b72c63d 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -1872,3 +1872,35 @@ API int pkgmgrinfo_pkginfo_metadata_filter_foreach( return pkgmgrinfo_pkginfo_usr_metadata_filter_foreach(handle, pkg_cb, user_data, _getuid()); } + +API int pkgmgrinfo_pkginfo_get_metadata_value( + pkgmgrinfo_pkginfo_h handle, const char *metadata_key, + char **metadata_value) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL"); + retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL"); + retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, + "metadata_value is NULL"); + + GList *list_md = NULL; + metadata_x *metadata = NULL; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + list_md = info->pkg_info->metadata; + + for (; list_md; list_md = list_md->next) { + metadata = (metadata_x *)list_md->data; + if (metadata && metadata->key) { + if (strcasecmp(metadata->key, metadata_key) == 0) { + if (metadata->value == NULL) + *metadata_value = ""; + else + *metadata_value = + (char *)metadata->value; + return PMINFO_R_OK; + } + } + } + + return PMINFO_R_EINVAL; +} -- 2.7.4