From aeb27fae2926cc941b8cee55a91a585bf0bfa958 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 7 Jun 2016 19:31:35 +0900 Subject: [PATCH] Implement pkgmgr_client_check_pkginfo_from_file Change-Id: I4dcbabe0b414321718c970e557d335d3727c32c0 Signed-off-by: Sangyoon Jang --- client/src/pkgmgr.c | 61 +++++++++++++++++++++++++++++++ client/src/pkgmgr_client_internal.c | 69 +++++++++++++++-------------------- types/include/package-manager-types.h | 1 + 3 files changed, 92 insertions(+), 39 deletions(-) diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index 34d13aa..fbca212 100644 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -2108,3 +2108,64 @@ API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode) { return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid()); } + +API pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path) +{ + int ret; + pkg_plugin_set *plugin_set; + package_manager_pkg_detail_info_t *info; + char *pkg_type; + + if (pkg_path == NULL) { + ERR("invalid parameter"); + return NULL; + } + + pkg_type = __get_type_from_path(pkg_path); + if (pkg_type == NULL) { + ERR("cannot get pkg type"); + return NULL; + } + + plugin_set = _package_manager_load_library(pkg_type); + if (plugin_set == NULL) { + ERR("failed to load library for %s", pkg_type); + free(pkg_type); + return NULL; + } + + info = calloc(1, sizeof(package_manager_pkg_detail_info_t)); + if (info == NULL) { + ERR("out of memory"); + free(pkg_type); + return NULL; + } + + ret = plugin_set->get_pkg_detail_info_from_package(pkg_path, info); + if (ret) { + ERR("get_pkg_detail_info_from_package failed"); + free(info); + free(pkg_type); + return NULL; + } + + free(pkg_type); + + return (pkgmgr_info *)info; +} + +API int pkgmgr_client_free_pkginfo(pkgmgr_info *info) +{ + package_manager_pkg_detail_info_t *pkg_info = + (package_manager_pkg_detail_info_t *)info; + + if (info == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; + } + + free(pkg_info->icon_buf); + free(pkg_info); + + return PKGMGR_R_OK; +} diff --git a/client/src/pkgmgr_client_internal.c b/client/src/pkgmgr_client_internal.c index 0712202..c7ecacf 100644 --- a/client/src/pkgmgr_client_internal.c +++ b/client/src/pkgmgr_client_internal.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -322,68 +323,58 @@ package_manager_pkg_info_t *_pkg_malloc_appinfo(int num) static pkg_plugin_set *plugin_set_list[24] = { 0, }; pkg_plugin_set *_pkg_plugin_load_library(const char *pkg_type, - const char *library_path) + const char *library_path) { - void *library_handle = NULL; - int i = 0; - - /* _pkg_plugin_on_load onload = NULL; */ - bool(*on_load) (pkg_plugin_set *plugin); + void *library_handle; + int i; + bool (*on_load)(pkg_plugin_set *plugin); if (library_path == NULL) { - ERR("pkg library path = [%s] \n", library_path); + ERR("pkg library path = [%s]", library_path); return NULL; } if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) { - ERR("dlopen is failed library_path[%s]\n", library_path); + ERR("dlopen is failed library_path[%s]", library_path); return NULL; } if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL || - dlerror() != NULL) { - ERR("can not find symbol \n"); + dlerror() != NULL) { + ERR("can not find symbol"); dlclose(library_handle); return NULL; } for (i = 0; plugin_set_list[i]; i++) { if (strcmp(plugin_set_list[i]->pkg_type, pkg_type) == 0) { - DBG("already loaded [%s] is done well \n", - library_path); - goto END; + DBG("already loaded [%s]", library_path); + return plugin_set_list[i]; } } - plugin_set_list[i] = (pkg_plugin_set *) malloc(sizeof(pkg_plugin_set)); + plugin_set_list[i] = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set)); if (plugin_set_list[i] == NULL) { - ERR("malloc of the plugin_set_list element is failed \n"); + ERR("malloc of the plugin_set_list element is failed"); dlclose(library_handle); return NULL; } - memset(plugin_set_list[i], 0x0, sizeof(pkg_plugin_set)); - if (on_load(plugin_set_list[i]) != 0) { - ERR("on_load is failed \n"); - - dlclose(library_handle); - + ERR("pkg_plugin_on_load failed"); free(plugin_set_list[i]); + dlclose(library_handle); plugin_set_list[i] = NULL; - return NULL; } plugin_set_list[i]->plugin_handle = library_handle; - strncpy(plugin_set_list[i]->pkg_type, pkg_type, - PKG_TYPE_STRING_LEN_MAX - 1); + snprintf(plugin_set_list[i]->pkg_type, + sizeof(plugin_set_list[i]->pkg_type), "%s", pkg_type); - DBG("load library [%s] is done well \n", library_path); + DBG("library [%s] is loaded", library_path); - END: return plugin_set_list[i]; - } int _pkg_plugin_get_library_path(const char *pkg_type, char *library_path) @@ -437,23 +428,23 @@ int _pkg_plugin_get_library_path(const char *pkg_type, char *library_path) pkg_plugin_set *_package_manager_load_library(const char *pkg_type) { - char package_path[1024] = { 0 }; - pkg_plugin_set *plugin_set = NULL; + char package_path[1024] = { 0, }; + pkg_plugin_set *plugin_set; if (pkg_type == NULL) { - ERR("can not load library - pkg_type is null\n"); + ERR("cannot load library - pkg_type is null"); return NULL; } - if (_pkg_plugin_get_library_path(pkg_type, package_path) == - PKGMGR_R_OK) { - plugin_set = _pkg_plugin_load_library(pkg_type, package_path); - if (plugin_set == NULL) { - ERR("can not load library \n"); - return NULL; - } - } else { - ERR("can not find path \n"); + if (_pkg_plugin_get_library_path(pkg_type, package_path) != + PKGMGR_R_OK) { + ERR("cannot find path"); + return NULL; + } + + plugin_set = _pkg_plugin_load_library(pkg_type, package_path); + if (plugin_set == NULL) { + ERR("cannot load library"); return NULL; } diff --git a/types/include/package-manager-types.h b/types/include/package-manager-types.h index b56f9fc..bcd16c6 100644 --- a/types/include/package-manager-types.h +++ b/types/include/package-manager-types.h @@ -101,6 +101,7 @@ typedef struct _package_manager_pkg_detail_info_t { char pkg_name[PKG_NAME_STRING_LEN_MAX]; char pkgid[PKG_NAME_STRING_LEN_MAX]; char version[PKG_VERSION_STRING_LEN_MAX]; + char api_version[PKG_VERSION_STRING_LEN_MAX]; char pkg_description[PKG_VALUE_STRING_LEN_MAX]; char min_platform_version[PKG_VERSION_STRING_LEN_MAX]; time_t installed_time; /* installed time it must be GMT+0 time */ -- 2.7.4