X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_private.c;h=d9f9dac33a58c7af3268ecee0fad3e56c6bb7776;hb=c1f2f8c153e5f5ee579119a1f429e1f0a606ccb6;hp=d2584a136cfaead7d85db3a46d1e53ef1d1c2727;hpb=52a9e4087f38c285d9e83a6647b6c13daedbdb7d;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_private.c b/src/pkgmgrinfo_private.c index d2584a1..d9f9dac 100644 --- a/src/pkgmgrinfo_private.c +++ b/src/pkgmgrinfo_private.c @@ -24,16 +24,19 @@ #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; @@ -48,7 +51,8 @@ static struct _pkginfo_str_map_t pkginfo_str_prop_map[] = { {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME}, {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL}, {E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF}, - {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE} + {E_PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE}, + {E_PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE, PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE} }; struct _pkginfo_int_map_t { @@ -74,7 +78,8 @@ static struct _pkginfo_bool_map_t pkginfo_bool_prop_map[] = { {E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING, PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING}, {E_PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE}, {E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, PMINFO_PKGINFO_PROP_PACKAGE_DISABLE}, - {E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE} + {E_PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE}, + {E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM, PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM} }; struct _appinfo_str_map_t { @@ -94,10 +99,9 @@ static struct _appinfo_str_map_t appinfo_str_prop_map[] = { {E_PMINFO_APPINFO_PROP_APP_CATEGORY, PMINFO_APPINFO_PROP_APP_CATEGORY}, {E_PMINFO_APPINFO_PROP_APP_HWACCELERATION, PMINFO_APPINFO_PROP_APP_HWACCELERATION}, {E_PMINFO_APPINFO_PROP_APP_SCREENREADER, PMINFO_APPINFO_PROP_APP_SCREENREADER}, - {E_PMINFO_APPINFO_PROP_APP_METADATA_KEY, PMINFO_APPINFO_PROP_APP_METADATA_KEY}, - {E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE, PMINFO_APPINFO_PROP_APP_METADATA_VALUE}, {E_PMINFO_APPINFO_PROP_APP_PACKAGE, PMINFO_APPINFO_PROP_APP_PACKAGE}, - {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE} + {E_PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE, PMINFO_APPINFO_PROP_APP_INSTALLED_STORAGE}, + {E_PMINFO_APPINFO_PROP_PRIVILEGE, PMINFO_APPINFO_PROP_PRIVILEGE} }; struct _appinfo_int_map_t { @@ -124,10 +128,11 @@ static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = { {E_PMINFO_APPINFO_PROP_APP_UI_GADGET, PMINFO_APPINFO_PROP_APP_UI_GADGET}, {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE}, {E_PMINFO_APPINFO_PROP_APP_DISABLE, PMINFO_APPINFO_PROP_APP_DISABLE}, - {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE} + {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, PMINFO_APPINFO_PROP_APP_CHECK_STORAGE}, + {E_PMINFO_APPINFO_PROP_PKG_DISABLE, PMINFO_APPINFO_PROP_PKG_DISABLE} }; -inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property) +API pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property) { int i = 0; int max = 0; @@ -145,7 +150,7 @@ inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(co return prop; } -inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property) +API pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(const char *property) { int i = 0; int max = 0; @@ -163,7 +168,7 @@ inline pkgmgrinfo_pkginfo_filter_prop_int _pminfo_pkginfo_convert_to_prop_int(co return prop; } -inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property) +API pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool(const char *property) { int i = 0; int max = 0; @@ -181,7 +186,7 @@ inline pkgmgrinfo_pkginfo_filter_prop_bool _pminfo_pkginfo_convert_to_prop_bool( return prop; } -inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property) +API pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(const char *property) { int i = 0; int max = 0; @@ -199,7 +204,7 @@ inline pkgmgrinfo_appinfo_filter_prop_str _pminfo_appinfo_convert_to_prop_str(co return prop; } -inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property) +API pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(const char *property) { int i = 0; int max = 0; @@ -217,7 +222,7 @@ inline pkgmgrinfo_appinfo_filter_prop_int _pminfo_appinfo_convert_to_prop_int(co return prop; } -inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property) +API pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool(const char *property) { int i = 0; int max = 0; @@ -235,11 +240,22 @@ inline pkgmgrinfo_appinfo_filter_prop_bool _pminfo_appinfo_convert_to_prop_bool( return prop; } -int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params) +void _pkgmgrinfo_node_destroy(pkgmgrinfo_node_x *node) +{ + if (node == NULL) + return; + + free(node->value); + free(node->key); + free(node); +} + +API int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **params) { pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data; char buf[MAX_QUERY_LEN] = {'\0'}; int flag = 0; + char *value; char *ptr = NULL; char *saveptr = NULL; @@ -297,9 +313,23 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p snprintf(buf, sizeof(buf), "pi.package_support_disable=? COLLATE NOCASE"); break; case E_PMINFO_PKGINFO_PROP_PACKAGE_DISABLE: - snprintf(buf, sizeof(buf), "pi.package_disable=? COLLATE NOCASE"); - break; - + return 0; + case E_PMINFO_PKGINFO_PROP_PACKAGE_SYSTEM: + snprintf(buf, sizeof(buf), "pi.package_system=? COLLATE NOCASE"); + break; + case E_PMINFO_PKGINFO_PROP_PACKAGE_RES_TYPE: + if (node->value == NULL || strlen(node->value) == 0) { + *condition = strdup("package_res_info.res_type IS NOT NULL COLLATE NOCASE"); + if (*condition == NULL) { + _LOGE("out of memeory"); + return 0; + } + return E_PMINFO_PKGINFO_JOIN_RES_INFO; + } else { + snprintf(buf, sizeof(buf), "package_res_info.res_type=? COLLATE NOCASE"); + flag = E_PMINFO_PKGINFO_JOIN_RES_INFO; + break; + } case E_PMINFO_APPINFO_PROP_APP_ID: snprintf(buf, sizeof(buf), "ai.app_id=?"); break; @@ -330,18 +360,26 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p break; case E_PMINFO_APPINFO_PROP_APP_CATEGORY: snprintf(buf, sizeof(buf), "package_app_app_category.category IN ("); - ptr = strtok_r(node->value, ",", &saveptr); - if (ptr == NULL) + value = strdup(node->value); + if (value == NULL) { + _LOGE("out of memeory"); + return 0; + } + ptr = strtok_r(value, ",", &saveptr); + if (ptr == NULL) { + free(value); return 0; - strncat(buf, "?", MAX_QUERY_LEN - 2); + } + strncat(buf, "?", sizeof(buf) - strlen(buf) - 1); *params = g_list_append(*params, strdup(ptr)); while ((ptr = strtok_r(NULL, ",", &saveptr))) { - strncat(buf, ", ?", MAX_QUERY_LEN - strlen(", ?") - 1); + strncat(buf, ", ?", sizeof(buf) - strlen(buf) - 1); *params = g_list_append(*params, strdup(ptr)); } - strncat(buf, ")", MAX_QUERY_LEN - 2); + strncat(buf, ")", sizeof(buf) - strlen(buf) - 1); *condition = strdup(buf); flag = E_PMINFO_APPINFO_JOIN_CATEGORY; + free(value); return flag; case E_PMINFO_APPINFO_PROP_APP_NODISPLAY: @@ -377,28 +415,15 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p case E_PMINFO_APPINFO_PROP_APP_UI_GADGET: snprintf(buf, sizeof(buf), "ai.app_ui_gadget=? COLLATE NOCASE"); break; - case E_PMINFO_APPINFO_PROP_APP_METADATA_KEY: - snprintf(buf, sizeof(buf), "package_app_app_metadata.md_key=?"); - flag = E_PMINFO_APPINFO_JOIN_METADATA; - break; - case E_PMINFO_APPINFO_PROP_APP_METADATA_VALUE: - snprintf(buf, sizeof(buf), "package_app_app_metadata.md_value=?"); - flag = E_PMINFO_APPINFO_JOIN_METADATA; - break; case E_PMINFO_APPINFO_PROP_APP_DISABLE: - if (strcasecmp(node->value, "true") == 0) - snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE OR " - "ai.app_id IN (SELECT app_id FROM package_app_info_for_uid " - "WHERE uid=%d AND is_disabled='true'))", uid); - else - snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE AND " - "ai.app_id NOT IN (SELECT app_id FROM package_app_info_for_uid " - "WHERE uid=%d AND is_disabled='true'))", uid); - flag = E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID; + return 0; break; case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE: snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE"); break; + case E_PMINFO_APPINFO_PROP_PKG_DISABLE: + return 0; + break; case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE: snprintf(buf, sizeof(buf), "ai.app_support_mode=?"); break; @@ -406,6 +431,10 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p case E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE: *condition = NULL; return 0; + case E_PMINFO_APPINFO_PROP_PRIVILEGE: + snprintf(buf, sizeof(buf), "package_privilege_info.privilege=?"); + flag = E_PMINFO_APPINFO_JOIN_PRIVILEGE; + break; default: _LOGE("Invalid Property Type\n"); *condition = NULL; @@ -416,7 +445,47 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p return flag; } -int _add_icon_info_into_list(const char *locale, char *value, GList **icon) +API int __get_pkg_metadata_filter_condition(gpointer data, char **condition, + GList **params) +{ + pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data; + char buf[MAX_QUERY_LEN]; + + snprintf(buf, sizeof(buf), "(package_metadata.md_key=?"); + if (node->value) + strncat(buf, " AND package_metadata.md_value=?", + sizeof(buf) - strlen(buf) - 1); + strncat(buf, ")", sizeof(buf) - strlen(buf) - 1); + + *condition = strdup(buf); + *params = g_list_append(*params, strdup(node->key)); + if (node->value) + *params = g_list_append(*params, strdup(node->value)); + + return E_PMINFO_PKGINFO_JOIN_METADATA; +} + +API int __get_metadata_filter_condition(gpointer data, char **condition, + GList **params) +{ + pkgmgrinfo_metadata_node_x *node = (pkgmgrinfo_metadata_node_x *)data; + char buf[MAX_QUERY_LEN]; + + snprintf(buf, sizeof(buf), "(package_app_app_metadata.md_key=?"); + if (node->value) + strncat(buf, " AND package_app_app_metadata.md_value=?", + sizeof(buf) - strlen(buf) - 1); + strncat(buf, ")", sizeof(buf) - strlen(buf) - 1); + + *condition = strdup(buf); + *params = g_list_append(*params, strdup(node->key)); + if (node->value) + *params = g_list_append(*params, strdup(node->value)); + + return E_PMINFO_APPINFO_JOIN_METADATA; +} + +API int _add_icon_info_into_list(const char *locale, char *value, GList **icon) { icon_x *info; @@ -427,12 +496,12 @@ int _add_icon_info_into_list(const char *locale, char *value, GList **icon) } info->text = value; info->lang = strdup(locale); - *icon = g_list_append(*icon, info); + *icon = g_list_prepend(*icon, info); return PMINFO_R_OK; } -int _add_label_info_into_list(const char *locale, char *value, GList **label) +API int _add_label_info_into_list(const char *locale, char *value, GList **label) { label_x *info; @@ -443,45 +512,12 @@ int _add_label_info_into_list(const char *locale, char *value, GList **label) } info->text = value; info->lang = strdup(locale); - *label = g_list_append(*label, info); + *label = g_list_prepend(*label, info); return PMINFO_R_OK; } -char *_get_system_locale(void) -{ - char *lang; - char *locale; - - lang = vconf_get_str(VCONFKEY_LANGSET); - if (lang == NULL) { - locale = strdup(DEFAULT_LOCALE); - if (locale == NULL) { - LOGE("out of memory"); - return NULL; - } - return locale; - } - - locale = malloc(sizeof(char) * 6); - if (locale == NULL) { - LOGE("out of memory"); - free(lang); - return NULL; - } - - strncpy(locale, lang, 2); - locale[2] = '-'; - locale[3] = tolower(lang[3]); - locale[4] = tolower(lang[4]); - locale[5] = '\0'; - - free(lang); - - return locale; -} - -int __pkginfo_check_installed_storage(package_x *pkginfo) +API int __pkginfo_check_installed_storage(package_x *pkginfo) { char buf[MAX_QUERY_LEN] = {'\0'}; int ret; @@ -502,7 +538,7 @@ int __pkginfo_check_installed_storage(package_x *pkginfo) return PMINFO_R_OK; } -int __appinfo_check_installed_storage(application_x *appinfo) +API int __appinfo_check_installed_storage(application_x *appinfo) { retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR, "installed_storage is NULL\n"); @@ -519,34 +555,143 @@ int __appinfo_check_installed_storage(application_x *appinfo) return PMINFO_R_OK; } -#define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */ -#define BUSY_WAITING_MAX 20 /* wait for max 1 sec */ -static int __db_busy_handler(void *data, int count) +struct type_map { + const char *manifest; + const char *type; +}; + +const struct type_map type_map[] = { + { "res/wgt/config.xml", "wgt" }, + { "config.xml", "wgt" }, + { "tizen-manifest.xml", "tpk" }, + { NULL, NULL} +}; + +API 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 void __get_library_path(const char *pkg_type, const char **path) { - if (count < BUSY_WAITING_MAX) { - usleep(BUSY_WAITING_USEC); - return 1; - } else { - /* sqlite3_prepare_v2 will return SQLITE_BUSY */ - return 0; + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so", + pkg_type); + + *path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf); +} + +API 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; + + __get_library_path(pkg_type, &library_path); + 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; + } + + library_handle = dlopen(library_path, RTLD_LAZY); + if (library_handle == NULL) { + _LOGE("dlopen is failed library_path[%s]", library_path); + return NULL; + } + + on_load = dlsym(library_handle, "pkg_plugin_on_load"); + if (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; } -int __open_db(const char *path, sqlite3 **db, int flags) +API void __unload_library(const char *pkg_type) { - int ret; + pkg_plugin_set *plugin_set; + + if (plugin_set_list == NULL) + return; - ret = sqlite3_open_v2(path, db, flags, NULL); - if (ret != SQLITE_OK) - return ret; + plugin_set = (pkg_plugin_set *)g_hash_table_lookup(plugin_set_list, + (gconstpointer)pkg_type); - ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL); - if (ret != SQLITE_OK) { - _LOGE("failed to register busy handler: %s", - sqlite3_errmsg(*db)); - sqlite3_close_v2(*db); - return ret; + if (plugin_set == NULL) { + _LOGE("pkg plugin for %s is not loaded", pkg_type); + return; } - return ret; + plugin_set->plugin_on_unload(); + dlclose(plugin_set->plugin_handle); + g_hash_table_remove(plugin_set_list, (gconstpointer)pkg_type); }