return PMINFO_R_OK;
}
+static int _pkginfo_get_plugin_execution_info(sqlite3 *db, const char *pkgid,
+ GList **plugins)
+{
+ static const char query_raw[] =
+ "SELECT appid, plugin_type, plugin_name FROM package_plugin_info "
+ "WHERE pkgid=%Q";
+ int ret;
+ char *query;
+ sqlite3_stmt *stmt;
+ plugin_x *plugin;
+
+ query = sqlite3_mprintf(query_raw, pkgid);
+ if (query == NULL) {
+ LOGE("out of memory");
+ return PMINFO_R_ERROR;
+ }
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query),
+ &stmt, NULL);
+ sqlite3_free(query);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ plugin = calloc(1, sizeof(plugin_x));
+ if (!plugin) {
+ LOGE("out of memory");
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+ plugin->pkgid = strdup(pkgid);
+ _save_column_str(stmt, 0, &plugin->appid);
+ _save_column_str(stmt, 1, &plugin->plugin_type);
+ _save_column_str(stmt, 2, &plugin->plugin_name);
+ *plugins = g_list_append(*plugins,
+ (gpointer)plugin);
+ }
+
+ sqlite3_finalize(stmt);
+
+ return PMINFO_R_OK;
+}
+
static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
GList **privileges)
{
return PMINFO_R_OK;
}
+static int _pkginfo_get_dependency(sqlite3 *db, const char *pkgid,
+ GList **dependencies)
+{
+ static const char query[] =
+ "SELECT DISTINCT depends_on, type, required_version "
+ "FROM package_dependency_info WHERE package=?";
+ int ret;
+ sqlite3_stmt *stmt;
+ dependency_x *dependency;
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ dependency = calloc(1, sizeof(dependency_x));
+ if (!dependency) {
+ LOGE("failed to alloc memory");
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+ _save_column_str(stmt, 0, &dependency->depends_on);
+ _save_column_str(stmt, 1, &dependency->type);
+ _save_column_str(stmt, 2, &dependency->required_version);
+ *dependencies = g_list_append(*dependencies,
+ (gpointer)dependency);
+ }
+
+ sqlite3_finalize(stmt);
+
+ return PMINFO_R_OK;
+}
+
static const char join_localized_info[] =
" LEFT OUTER JOIN package_localized_info"
" ON pi.package=package_localized_info.package"
info->for_all_users =
strdup((uid != global_user_uid) ? "false" : "true");
+ if (_pkginfo_get_plugin_execution_info(db, info->package, &info->plugin)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+
if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
/* TODO : author should be retrieved at package_localized_info */
author = calloc(1, sizeof(author_x));
}
}
+ if (flag & PMINFO_PKGINFO_GET_DEPENDENCY) {
+ if (_pkginfo_get_dependency(db, info->package,
+ &info->dependencies)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }
+
if (is_check_storage &&
__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
ret = PMINFO_R_ERROR;
ret = PMINFO_R_OK;
catch:
+ sqlite3_finalize(stmt);
+ sqlite3_close_v2(db);
+
if (constraints)
free(constraints);
pkgmgrinfo_pkginfo_filter_destroy(tmp_filter);
g_list_free_full(bind_params, free);
- sqlite3_close_v2(db);
- if (stmt)
- sqlite3_finalize(stmt);
return ret;
}
return PMINFO_R_OK;
}
+API int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_plugin_list_cb plugin_func, void *user_data)
+{
+ retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
+ retvm_if(plugin_func == NULL, PMINFO_R_EINVAL,
+ "Callback function is NULL");
+ int ret;
+ plugin_x *plugin;
+ GList *tmp;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (tmp = info->pkg_info->plugin; tmp; tmp = tmp->next) {
+ plugin = (plugin_x *)tmp->data;
+ if (plugin == NULL)
+ continue;
+ ret = plugin_func(plugin->pkgid, plugin->appid,
+ plugin->plugin_type, plugin->plugin_name, user_data);
+ if (ret < 0)
+ return PMINFO_R_OK;
+ }
+
+ return PMINFO_R_OK;
+}
+
API int pkgmgrinfo_pkginfo_foreach_appdefined_privilege(
pkgmgrinfo_pkginfo_h handle,
pkgmgrinfo_pkg_appdefined_privilege_list_cb privilege_func,
return PMINFO_R_OK;
}
+API int pkgmgrinfo_pkginfo_foreach_dependency(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
+ void *user_data)
+{
+ int ret;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ GList *tmp;
+ dependency_x *dependency;
+
+ if (handle == NULL || dependency_cb == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ if (info->pkg_info == NULL)
+ return PMINFO_R_ERROR;
+
+ for (tmp = info->pkg_info->dependencies; tmp; tmp = tmp->next) {
+ dependency = (dependency_x *)tmp->data;
+ if (dependency == NULL)
+ continue;
+ ret = dependency_cb(dependency->depends_on, dependency->type,
+ dependency->required_version, user_data);
+ if (ret < 0)
+ break;
+ }
+
+ return PMINFO_R_OK;
+}
+
+struct required_by {
+ char *pkgid;
+ char *type;
+ char *version;
+};
+
+static int _get_required_by(sqlite3 *db, const char *pkgid, GQueue **queue,
+ GHashTable **table, GList **pkg_list)
+{
+ static const char query[] =
+ "SELECT package, type, required_version "
+ "FROM package_dependency_info WHERE depends_on=?";
+ int ret;
+ sqlite3_stmt *stmt;
+ struct required_by *req;
+
+ /* already checked */
+ if (!g_hash_table_insert(*table, strdup(pkgid), GINT_TO_POINTER(1)))
+ return PMINFO_R_OK;
+
+ ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("prepare failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ ret = sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
+ if (ret != SQLITE_OK) {
+ LOGE("bind failed: %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ req = calloc(1, sizeof(struct required_by));
+ if (req == NULL) {
+ LOGE("out of memory");
+ sqlite3_finalize(stmt);
+ return PMINFO_R_ERROR;
+ }
+ _save_column_str(stmt, 0, &req->pkgid);
+ _save_column_str(stmt, 1, &req->type);
+ _save_column_str(stmt, 2, &req->version);
+
+ *pkg_list = g_list_append(*pkg_list, req);
+ g_queue_push_tail(*queue, strdup(req->pkgid));
+ }
+
+ sqlite3_finalize(stmt);
+
+ return PMINFO_R_OK;
+}
+
+static int _pkginfo_foreach_required_by(uid_t uid, const char *pkgid,
+ GList **pkg_list)
+{
+ int ret;
+ char *dbpath;
+ sqlite3 *db;
+ GQueue *queue;
+ GHashTable *table;
+ char *item;
+
+ dbpath = getUserPkgParserDBPathUID(uid);
+ if (dbpath == NULL)
+ return PMINFO_R_ERROR;
+
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+ if (ret != SQLITE_OK) {
+ LOGD("failed to open db(%s): %d", dbpath, ret);
+ free(dbpath);
+ return PMINFO_R_ERROR;
+ }
+ free(dbpath);
+
+ queue = g_queue_new();
+ if (queue == NULL) {
+ LOGE("out of memory");
+ sqlite3_close_v2(db);
+ return PMINFO_R_ERROR;
+ }
+
+ table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+
+ g_queue_push_tail(queue, strdup(pkgid));
+ while (!g_queue_is_empty(queue)) {
+ item = g_queue_pop_head(queue);
+ ret = _get_required_by(db, item, &queue, &table, pkg_list);
+ free(item);
+ if (ret != PMINFO_R_OK) {
+ LOGE("failed to get required by pkgs");
+ g_hash_table_destroy(table);
+ g_queue_free_full(queue, free);
+ sqlite3_close_v2(db);
+ return PMINFO_R_ERROR;
+ }
+ }
+
+ g_hash_table_destroy(table);
+ g_queue_free_full(queue, free);
+ sqlite3_close_v2(db);
+
+ return PMINFO_R_OK;
+}
+
+static void __free_required_by(gpointer data)
+{
+ struct required_by *req = (struct required_by *)data;
+
+ free(req->pkgid);
+ free(req->type);
+ free(req->version);
+ free(req);
+}
+
+API int pkgmgrinfo_pkginfo_foreach_required_by(pkgmgrinfo_pkginfo_h handle,
+ pkgmgrinfo_pkg_dependency_list_cb dependency_cb,
+ void *user_data)
+{
+ int ret;
+ pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+ GList *pkg_list = NULL;
+ GList *l;
+ struct required_by *req;
+
+ if (handle == NULL || dependency_cb == NULL || info->pkg_info == NULL) {
+ LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
+ }
+
+ ret = _pkginfo_foreach_required_by(info->uid, info->pkg_info->package,
+ &pkg_list);
+ if (ret == PMINFO_R_OK && info->uid != GLOBAL_USER)
+ ret = _pkginfo_foreach_required_by(GLOBAL_USER,
+ info->pkg_info->package, &pkg_list);
+
+ if (ret != PMINFO_R_OK) {
+ g_list_free_full(pkg_list, __free_required_by);
+ return ret;
+ }
+
+ for (l = pkg_list; l != NULL; l = l->next) {
+ req = (struct required_by *)l->data;
+ ret = dependency_cb(req->pkgid, req->type, req->version,
+ user_data);
+ if (ret < 0)
+ break;
+ }
+
+ g_list_free_full(pkg_list, __free_required_by);
+
+ return PMINFO_R_OK;
+}
+
int __compare_package_version(const char *version, int *major,
int *minor, int *macro, int *nano)
{