From: Sangyoon Jang Date: Tue, 11 Apr 2017 05:05:57 +0000 (+0900) Subject: Implement pkgmgrinfo_archiveinfo features X-Git-Tag: accepted/tizen/3.0/common/20170605.123910~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=70b49cd5a704484edbce70ce75483b5ed0258ee6;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Implement pkgmgrinfo_archiveinfo features These features are came from slp-pkgmgr repository. Change-Id: Ibcfc2f7188ae0e662c8988f58910c8d5fec1aed7 Signed-off-by: Sangyoon Jang (cherry picked from commit 9cbdda4a8e804a747a5ddc5a863b230234553043) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cfdce9..203d872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ FOREACH(flag ${pkgs_CFLAGS}) ENDFOREACH(flag) -pkg_check_modules(libpkgs REQUIRED glib-2.0 dlog vconf sqlite3 db-util libtzplatform-config libsmack bundle capi-system-info) +pkg_check_modules(libpkgs REQUIRED glib-2.0 dlog vconf sqlite3 db-util libtzplatform-config libsmack bundle capi-system-info minizip) FOREACH(flag ${libpkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/include/pkgmgr-info.h b/include/pkgmgr-info.h index 471c881..8b7ebc5 100644 --- a/include/pkgmgr-info.h +++ b/include/pkgmgr-info.h @@ -5860,6 +5860,27 @@ int pkgmgrinfo_appinfo_get_usr_installed_list_full( int pkgmgrinfo_appinfo_get_installed_list_full( pkgmgrinfo_app_list_cb app_func, int flag, void *user_data); + +int pkgmgrinfo_archiveinfo_get_archiveinfo(const char *path, + pkgmgrinfo_archiveinfo_h *handle); +int pkgmgrinfo_archiveinfo_destroy_archiveinfo(pkgmgrinfo_archiveinfo_h handle); +int pkgmgrinfo_archiveinfo_get_pkgid(pkgmgrinfo_archiveinfo_h handle, + const char **pkgid); +int pkgmgrinfo_archiveinfo_get_type(pkgmgrinfo_archiveinfo_h handle, + const char **type); +int pkgmgrinfo_archiveinfo_get_version(pkgmgrinfo_archiveinfo_h handle, + const char **version); +int pkgmgrinfo_archiveinfo_get_api_version(pkgmgrinfo_archiveinfo_h handle, + const char **api_version); +int pkgmgrinfo_archiveinfo_get_description(pkgmgrinfo_archiveinfo_h handle, + const char **description); +int pkgmgrinfo_archiveinfo_get_label(pkgmgrinfo_archiveinfo_h handle, + const char **label); +int pkgmgrinfo_archiveinfo_get_author(pkgmgrinfo_archiveinfo_h handle, + const char **author); +int pkgmgrinfo_archiveinfo_get_icon(pkgmgrinfo_archiveinfo_h handle, + const unsigned char **icon, size_t *size); + /** * @pkgmgrinfo client API end **/ diff --git a/include/pkgmgrinfo_type.h b/include/pkgmgrinfo_type.h index 4bb96b9..72ff3ec 100644 --- a/include/pkgmgrinfo_type.h +++ b/include/pkgmgrinfo_type.h @@ -191,6 +191,11 @@ typedef void *pkgmgrinfo_appinfo_metadata_filter_h; typedef void *pkgmgrinfo_appcontrol_h; /** + * @brief A handle to get package archive information + */ +typedef void *pkgmgrinfo_archiveinfo_h; + +/** * @brief type definition. */ typedef void pkgmgrinfo_client; diff --git a/packaging/pkgmgr-info.spec b/packaging/pkgmgr-info.spec index 34fd9db..3d8282b 100644 --- a/packaging/pkgmgr-info.spec +++ b/packaging/pkgmgr-info.spec @@ -16,6 +16,7 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(minizip) %description Packager Manager infomation api for packaging diff --git a/src/pkgmgrinfo_archiveinfo.c b/src/pkgmgrinfo_archiveinfo.c new file mode 100644 index 0000000..0a8c2b8 --- /dev/null +++ b/src/pkgmgrinfo_archiveinfo.c @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "pkgmgrinfo_type.h" +#include "pkgmgrinfo_private.h" +#include "pkgmgrinfo_debug.h" + +API int pkgmgrinfo_archiveinfo_get_archiveinfo(const char *path, + pkgmgrinfo_archiveinfo_h *handle) +{ + char *pkg_type; + pkg_plugin_set *plugin_set; + package_manager_pkg_detail_info_t *info; + + if (path == NULL || handle == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + pkg_type = __get_type_from_path(path); + if (pkg_type == NULL) { + _LOGE("cannot get pkg type"); + return PMINFO_R_ERROR; + } + + plugin_set = __load_library(pkg_type); + if (plugin_set == NULL) { + _LOGE("failed to load library for %s", pkg_type); + free(pkg_type); + return PMINFO_R_ERROR; + } + + info = calloc(1, sizeof(package_manager_pkg_detail_info_t)); + if (info == NULL) { + _LOGE("out of memory"); + __unload_library(pkg_type); + free(pkg_type); + return PMINFO_R_ERROR; + } + + if (plugin_set->get_pkg_detail_info_from_package(path, info)) { + _LOGE("failed to get archive info of %s", path); + free(info); + __unload_library(pkg_type); + free(pkg_type); + return PMINFO_R_ERROR; + } + + *handle = info; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_destroy_archiveinfo( + pkgmgrinfo_archiveinfo_h handle) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + free(info->icon_buf); + free(info); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_pkgid(pkgmgrinfo_archiveinfo_h handle, + const char **pkgid) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL || strlen(info->pkgid)) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *pkgid = info->pkgid; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_type(pkgmgrinfo_archiveinfo_h handle, + const char **type) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL || strlen(info->pkg_type)) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *type = info->pkg_type; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_version(pkgmgrinfo_archiveinfo_h handle, + const char **version) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL || strlen(info->version)) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *version = info->version; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_api_version(pkgmgrinfo_archiveinfo_h handle, + const char **api_version) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL || strlen(info->api_version)) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *api_version = info->api_version; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_description(pkgmgrinfo_archiveinfo_h handle, + const char **description) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (strlen(info->pkg_description) == 0) + return PMINFO_R_ENOENT; + + *description = info->pkg_description; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_label(pkgmgrinfo_archiveinfo_h handle, + const char **label) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (strlen(info->label) == 0) + return PMINFO_R_ENOENT; + + *label = info->label; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_author(pkgmgrinfo_archiveinfo_h handle, + const char **author) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (strlen(info->author) == 0) + return PMINFO_R_ENOENT; + + *author = info->author; + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_archiveinfo_get_icon(pkgmgrinfo_archiveinfo_h handle, + const unsigned char **icon, size_t *size) +{ + package_manager_pkg_detail_info_t *info = + (package_manager_pkg_detail_info_t *)handle; + + if (info == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->icon_buf == NULL) + return PMINFO_R_ENOENT; + + *icon = info->icon_buf; + *size = info->icon_size; + + return PMINFO_R_OK; +} diff --git a/src/pkgmgrinfo_private.c b/src/pkgmgrinfo_private.c index 4fa7551..b7809f8 100644 --- a/src/pkgmgrinfo_private.c +++ b/src/pkgmgrinfo_private.c @@ -24,16 +24,20 @@ #include #include #include +#include #include #include #include +#include #include "pkgmgr-info.h" #include "pkgmgrinfo_debug.h" #include "pkgmgrinfo_private.h" #include "pkgmgr_parser.h" +static GHashTable *plugin_set_list; + struct _pkginfo_str_map_t { pkgmgrinfo_pkginfo_filter_prop_str prop; const char *property; @@ -578,3 +582,145 @@ int __open_db(const char *path, sqlite3 **db, int flags) return ret; } + +struct type_map { + const char *manifest; + const char *type; +}; + +struct type_map type_map[] = { + { "res/wgt/config.xml", "wgt" }, + { "config.xml", "wgt" }, + { "tizen-manifest.xml", "tpk" }, + { NULL, NULL} +}; + +char *__get_type_from_path(const char *pkg_path) +{ + const char *type = NULL; + unzFile uf; + int i; + + uf = unzOpen(pkg_path); + if (uf == NULL) { + _LOGE("failed to open zip file %s", pkg_path); + return NULL; + } + + for (i = 0; type_map[i].manifest != NULL; i++) { + if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) { + _LOGD("pkgtype of %s: [%s]", pkg_path, + type_map[i].type); + type = type_map[i].type; + break; + } + } + unzClose(uf); + + if (type == NULL) { + _LOGE("cannot get pkg type of file %s", pkg_path); + return NULL; + } + + return strdup(type); +} + +static const char *__get_library_path(const char *pkg_type) +{ + char buf[64]; + const char *path; + + snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so", + pkg_type); + path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf); + + return path; +} + +pkg_plugin_set *__load_library(const char *pkg_type) +{ + void *library_handle; + pkg_plugin_set *plugin_set; + bool (*on_load)(pkg_plugin_set *plugin); + const char *library_path; + + library_path = __get_library_path(pkg_type); + if (library_path == NULL) { + _LOGE("cannot get library path for %s", pkg_type); + return NULL; + } + + if (plugin_set_list == NULL) { + plugin_set_list = g_hash_table_new_full(g_str_hash, + g_str_equal, free, free); + if (plugin_set_list == NULL) { + _LOGE("out of memory"); + return NULL; + } + } + + plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list, + (gconstpointer)pkg_type); + if (plugin_set) { + _LOGD("already loaded [%s]", library_path); + return plugin_set; + } + + if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) { + _LOGE("dlopen is failed library_path[%s]", library_path); + return NULL; + } + + if ((on_load = dlsym(library_handle, "pkg_plugin_on_load")) == NULL || + dlerror() != NULL) { + _LOGE("cannot find symbol"); + dlclose(library_handle); + return NULL; + } + + plugin_set = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set)); + if (plugin_set == NULL) { + _LOGE("out of memory"); + dlclose(library_handle); + return NULL; + } + + if (on_load(plugin_set) != 0) { + _LOGE("pkg_plugin_on_load failed"); + free(plugin_set); + dlclose(library_handle); + plugin_set = NULL; + return NULL; + } + + plugin_set->plugin_handle = library_handle; + snprintf(plugin_set->pkg_type, + sizeof(plugin_set->pkg_type), "%s", pkg_type); + + g_hash_table_insert(plugin_set_list, (gpointer)strdup(pkg_type), + (gpointer)plugin_set); + + _LOGD("library [%s] is loaded", library_path); + + return plugin_set; +} + +void __unload_library(const char *pkg_type) +{ + pkg_plugin_set *plugin_set; + + if (plugin_set_list == NULL) + return; + + plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list, + (gconstpointer)pkg_type); + + if (plugin_set == NULL) { + _LOGE("pkg plugin for %s is not loaded", pkg_type); + return; + } + + plugin_set->plugin_on_unload(); + dlclose(plugin_set->plugin_handle); + g_hash_table_remove(plugin_set_list, (gconstpointer)pkg_type); +} diff --git a/src/pkgmgrinfo_private.h b/src/pkgmgrinfo_private.h index 7bc8a40..628becd 100644 --- a/src/pkgmgrinfo_private.h +++ b/src/pkgmgrinfo_private.h @@ -224,6 +224,66 @@ typedef struct _db_handle { int ref; } db_handle; +/* TODO: refine below structures */ +#define PKG_TYPE_STRING_LEN_MAX 128 +#define PKG_NAME_STRING_LEN_MAX 128 +#define PKG_VERSION_STRING_LEN_MAX 128 +#define PKG_VALUE_STRING_LEN_MAX 512 +#define PKG_URL_STRING_LEN_MAX 1024 +#define PKG_LABEL_STRING_LEN_MAX 128 +#define PKG_PATH_STRING_LEN_MAX 512 + +typedef struct _package_manager_pkg_info_t { + char pkg_type[PKG_TYPE_STRING_LEN_MAX]; + char pkg_name[PKG_NAME_STRING_LEN_MAX]; + char pkgid[PKG_NAME_STRING_LEN_MAX]; + char version[PKG_VERSION_STRING_LEN_MAX]; + struct _package_manager_pkg_info_t *next; +} package_manager_pkg_info_t; + +typedef struct _package_manager_pkg_detail_info_t { + char pkg_type[PKG_TYPE_STRING_LEN_MAX]; + 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 */ + int installed_size; /* installed total size */ + int app_size; /* installed app size */ + int data_size; /* data size which is made on run time */ + char optional_id[PKG_NAME_STRING_LEN_MAX]; /*package ID if exists */ + void *pkg_optional_info; + char label[PKG_LABEL_STRING_LEN_MAX]; + char author[PKG_VALUE_STRING_LEN_MAX]; + char *icon_buf; + int icon_size; + GList *privilege_list; +} package_manager_pkg_detail_info_t; + +typedef void (*_pkg_plugin_unload)(void); +typedef int (*_pkg_plugin_pkg_is_installed) (const char *pkgid); +typedef int (*_pkg_plugin_get_installed_pkg_list)( + const char *category, const char *option, + package_manager_pkg_info_t **list, int *count); +typedef int (*_pkg_plugin_get_pkg_detail_info)(const char *pkgid, + package_manager_pkg_detail_info_t *pkg_detail_info); +typedef int (*_pkg_plugin_get_pkg_detail_info_from_package)( + const char *pkg_path, + package_manager_pkg_detail_info_t *pkg_detail_info); + +typedef struct _pkg_plugin_set { + char pkg_type[PKG_TYPE_STRING_LEN_MAX]; + void *plugin_handle; + _pkg_plugin_unload plugin_on_unload; + _pkg_plugin_pkg_is_installed pkg_is_installed; + _pkg_plugin_get_installed_pkg_list get_installed_pkg_list; + _pkg_plugin_get_pkg_detail_info get_pkg_detail_info; + _pkg_plugin_get_pkg_detail_info_from_package + get_pkg_detail_info_from_package; +} pkg_plugin_set; + extern __thread db_handle manifest_db; extern __thread db_handle cert_db; @@ -252,6 +312,8 @@ int _add_label_info_into_list(const char *locale, char *value, GList **label); int __pkginfo_check_installed_storage(package_x *pkginfo); int __appinfo_check_installed_storage(application_x *appinfo); int __open_db(const char *path, sqlite3 **db, int flags); +char *__get_type_from_path(const char *pkg_path); +pkg_plugin_set *__load_library(const char *pkg_type); #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define REGULAR_USER 5000