X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_pkginfo.c;h=b72c63d6fdf40c78e4d91156d33500d443a8ff4a;hb=134582f3a1d24ed811633a6fd0db447b667b5f12;hp=6931b408074466a297a9f4d5732840c17824d04f;hpb=e72f14b003ee2ad65823d72a0bde0ee9f92149c2;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_pkginfo.c b/src/pkgmgrinfo_pkginfo.c index 6931b40..b72c63d 100644 --- a/src/pkgmgrinfo_pkginfo.c +++ b/src/pkgmgrinfo_pkginfo.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -70,22 +69,6 @@ static gint __pkg_disable_chk_func(gconstpointer data1, gconstpointer data2) return 1; } -static void __destroy_each_node(gpointer data, gpointer user_data) -{ - ret_if(data == NULL); - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data; - if (node->value) { - free(node->value); - node->value = NULL; - } - if (node->key) { - free(node->key); - node->key = NULL; - } - free(node); - node = NULL; -} - static void __destroy_metadata_node(gpointer data) { pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data; @@ -199,7 +182,7 @@ static int _pkgmgrinfo_get_pkginfo(const char *pkgid, uid_t uid, return ret; } - if (!g_hash_table_size(list)) { + if (!g_hash_table_size(list) || !g_hash_table_lookup(list, pkgid)) { _LOGD("pkginfo for [%s] is not existed for user [%d]", pkgid, uid); g_hash_table_destroy(list); @@ -901,6 +884,65 @@ API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path return PMINFO_R_OK; } +API int pkgmgrinfo_pkginfo_get_res_type(pkgmgrinfo_pkginfo_h handle, + char **res_type) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(res_type == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->res_type == NULL) + return PMINFO_R_ENOENT; + + *res_type = (char *)info->pkg_info->res_type; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_get_res_version(pkgmgrinfo_pkginfo_h handle, + char **res_version) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(res_version == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->res_version == NULL) + return PMINFO_R_ENOENT; + + *res_version = (char *)info->pkg_info->res_version; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_get_light_user_switch_mode(pkgmgrinfo_pkginfo_h handle, char **mode) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(mode == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + if (info->pkg_info->light_user_switch_mode == NULL) + return PMINFO_R_ERROR; + + *mode = (char *)info->pkg_info->light_user_switch_mode; + + return PMINFO_R_OK; +} + API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); @@ -1107,6 +1149,22 @@ API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *f return pkgmgrinfo_pkginfo_is_global(handle, for_all_users); } +API int pkgmgrinfo_pkginfo_is_lib(pkgmgrinfo_pkginfo_h handle, bool *lib) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n"); + retvm_if(lib == NULL, PMINFO_R_EINVAL, + "Argument supplied to hold return value is NULL\n"); + + if (info->pkg_info == NULL || info->pkg_info->lib == NULL) + return PMINFO_R_ERROR; + + *lib = _get_bool_value(info->pkg_info->lib); + + return PMINFO_R_OK; +} + API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle) { pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; @@ -1141,12 +1199,16 @@ API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle) retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n"); - if (filter->list) { - g_slist_foreach(filter->list, __destroy_each_node, NULL); - g_slist_free(filter->list); - } + if (filter->list) + g_slist_free_full(filter->list, + (GDestroyNotify)_pkgmgrinfo_node_destroy); - g_slist_free_full(filter->list_metadata, __destroy_metadata_node); + if (filter->list_metadata) + g_slist_free_full(filter->list_metadata, + __destroy_metadata_node); + if (filter->list_pkg_metadata) + g_slist_free_full(filter->list_pkg_metadata, + __destroy_metadata_node); free(filter); @@ -1189,8 +1251,10 @@ API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle, /*If API is called multiple times for same property, we should override the previous values. Last value set will be used for filtering.*/ link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); - if (link) + if (link) { + _pkgmgrinfo_node_destroy(link->data); filter->list = g_slist_delete_link(filter->list, link); + } filter->list = g_slist_append(filter->list, (gpointer)node); return PMINFO_R_OK; @@ -1233,8 +1297,10 @@ API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle, /*If API is called multiple times for same property, we should override the previous values. Last value set will be used for filtering.*/ link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); - if (link) + if (link) { + _pkgmgrinfo_node_destroy(link->data); filter->list = g_slist_delete_link(filter->list, link); + } filter->list = g_slist_append(filter->list, (gpointer)node); return PMINFO_R_OK; @@ -1286,8 +1352,10 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle, /*If API is called multiple times for same property, we should override the previous values. Last value set will be used for filtering.*/ link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func); - if (link) + if (link) { + _pkgmgrinfo_node_destroy(link->data); filter->list = g_slist_delete_link(filter->list, link); + } filter->list = g_slist_append(filter->list, (gpointer)node); return PMINFO_R_OK; @@ -1479,22 +1547,22 @@ static void __free_depends_on(gpointer data) pkgmgrinfo_basic_free_dependency(dep); } -API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle, +/* This API is not exported at the header file */ +API int pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid(const char *pkgid, pkgmgrinfo_pkg_dependency_list_cb dependency_cb, - void *user_data) + void *user_data, uid_t uid) { int ret; - pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; GList *pkg_list = NULL; GList *l; dependency_x *dep; - if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) { + if (pkgid == NULL || dependency_cb == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - ret = _pkginfo_get_depends_on(info->uid, info->pkg_info->package, &pkg_list); + ret = _pkginfo_get_depends_on(uid, pkgid, &pkg_list); if (ret != PMINFO_R_OK) return PMINFO_R_ERROR; @@ -1510,6 +1578,79 @@ API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle, return PMINFO_R_OK; } +API int pkgmgrinfo_pkginfo_foreach_depends_on(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_dependency_list_cb dependency_cb, + void *user_data) +{ + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + return pkgmgrinfo_pkginfo_foreach_depends_on_by_pkgid( + info->pkg_info->package, dependency_cb, user_data, + info->uid); +} + +API int pkgmgrinfo_pkginfo_foreach_res_allowed_package( + pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_res_allowed_package_list_cb res_allowed_package_cb, + void *user_data) +{ + int ret; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + GList *res_pkgs; + res_allowed_package_x *res_allowed_package; + + if (handle == NULL || res_allowed_package_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + for (res_pkgs = info->pkg_info->res_allowed_packages; res_pkgs; + res_pkgs = res_pkgs->next) { + res_allowed_package = (res_allowed_package_x *)res_pkgs->data; + if (res_allowed_package == NULL) + continue; + + ret = res_allowed_package_cb( + res_allowed_package->allowed_package, + res_allowed_package->required_privileges, + user_data); + if (ret < 0) + return PMINFO_R_OK; + } + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_foreach_required_privilege( + required_privilege_h handle, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, + void *user_data) +{ + int ret; + GList *privs; + + if (privilege_func == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + for (privs = (GList *)handle; privs; privs = privs->next) { + ret = privilege_func((char *)privs->data, user_data); + if (ret < 0) + return PMINFO_R_OK; + } + + return PMINFO_R_OK; +} + int __compare_package_version(const char *version, int *major, int *minor, int *macro, int *nano) { @@ -1632,3 +1773,134 @@ API int pkgmgrinfo_compare_package_version(const char *current_version, return PMINFO_R_OK; } + +API int pkgmgrinfo_pkginfo_foreach_metadata(pkgmgrinfo_pkginfo_h handle, + pkgmgrinfo_pkg_metadata_list_cb metadata_func, void *user_data) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL"); + retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, + "Callback function is NULL"); + int ret = -1; + metadata_x *ptr; + GList *tmp; + pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle; + + if (info->pkg_info == NULL) + return PMINFO_R_ERROR; + + for (tmp = info->pkg_info->metadata; tmp; tmp = tmp->next) { + ptr = (metadata_x *)tmp->data; + if (ptr == NULL) + continue; + if (ptr->key) { + ret = metadata_func(ptr->key, ptr->value ? + ptr->value : "", user_data); + if (ret < 0) + break; + } + } + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_metadata_filter_create( + pkgmgrinfo_pkginfo_metadata_filter_h *handle) +{ + return pkgmgrinfo_pkginfo_filter_create(handle); +} + +API int pkgmgrinfo_pkginfo_metadata_filter_destroy( + pkgmgrinfo_pkginfo_metadata_filter_h handle) +{ + return pkgmgrinfo_pkginfo_filter_destroy(handle); +} + +API int pkgmgrinfo_pkginfo_metadata_filter_add( + pkgmgrinfo_pkginfo_metadata_filter_h handle, + const char *key, const char *value) +{ + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_metadata_node_x *node; + + /* value can be NULL. + * In that case all pkgs with specified key should be displayed + */ + if (handle == NULL || key == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x)); + if (node == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + node->key = strdup(key); + if (value && strlen(value)) + node->value = strdup(value); + + filter->list_pkg_metadata = g_slist_append(filter->list_pkg_metadata, + (gpointer)node); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_pkginfo_usr_metadata_filter_foreach( + pkgmgrinfo_pkginfo_metadata_filter_h handle, + pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid) +{ + if (handle == NULL || pkg_cb == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + + if (pkgmgrinfo_pkginfo_filter_add_bool(filter, + PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false)) + return PMINFO_R_ERROR; + + return _pkginfo_get_filtered_foreach_pkginfo(uid, handle, + PMINFO_PKGINFO_GET_ALL, pkg_cb, + user_data); +} + +API int pkgmgrinfo_pkginfo_metadata_filter_foreach( + pkgmgrinfo_pkginfo_metadata_filter_h handle, + pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data) +{ + 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; +}