*
* Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Junghyun Yeon <jungh.yeon@samsung.com>, Sangyoon Jang <jeremy.jang@samsung.com>
+ * Contact: Junghyun Yeon <jungh.yeon@samsung.com>,
+ * Sangyoon Jang <jeremy.jang@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <stdlib.h>
#include <stdbool.h>
-#include <sqlite3.h>
+#include "manager/pkginfo_manager.h"
#include "pkgmgrinfo_private.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgr-info.h"
-static void _free_plugin(gpointer data)
-{
- plugin_x *plugin = (plugin_x *)data;
- if (plugin == NULL)
- return;
- if (plugin->appid)
- free((void *)plugin->appid);
- free((void *)plugin);
-}
-
API int pkgmgrinfo_plugininfo_foreach_plugininfo(const char *pkgid,
const char *plugin_type, const char *plugin_name,
pkgmgrinfo_plugin_list_cb plugin_list_cb, void *user_data)
{
int ret;
- int idx = 0;
- char *dbpath;
const char *appid;
- sqlite3 *db;
- sqlite3_stmt *stmt = NULL;
- plugin_x *plugin;
- GList *plugin_list = NULL;
+ GList *appid_list = NULL;
GList *tmp_list;
- static const char query[] =
- "SELECT appid FROM "
- "package_plugin_info WHERE pkgid=? AND "
- "plugin_type=? AND plugin_name=?";
-
if (!pkgid || !plugin_type || !plugin_name || !plugin_list_cb) {
_LOGE("Invalid parameter");
return PMINFO_R_EINVAL;
}
- dbpath = getUserPkgParserDBPathUID(_getuid());
- if (dbpath == NULL) {
- _LOGE("Failed to get db path");
- 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);
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(db));
- ret = PMINFO_R_ERROR;
- goto catch;
+ ret = _plugininfo_get_appids(pkgid, plugin_type, plugin_name,
+ &appid_list);
+ if (ret != PMINFO_R_OK) {
+ _LOGE("Fail to get plugininfo");
+ return ret;
}
- ret = sqlite3_bind_text(stmt, ++idx, pkgid, -1, SQLITE_STATIC);
- if (ret != SQLITE_OK) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
-
- ret = sqlite3_bind_text(stmt, ++idx, plugin_type, -1, SQLITE_STATIC);
- if (ret != SQLITE_OK) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- ret = sqlite3_bind_text(stmt, ++idx, plugin_name, -1, SQLITE_STATIC);
- if (ret != SQLITE_OK) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
-
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- plugin = calloc(1, sizeof(plugin_x));
- if (plugin == NULL) {
- _LOGE("out of memory");
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- idx = 0;
- appid = (const char *)sqlite3_column_text(stmt, idx++);
- if (appid) {
- plugin->appid = strdup(appid);
- }
- plugin_list = g_list_prepend(plugin_list, plugin);
- }
-
- for (tmp_list = plugin_list; tmp_list != NULL; tmp_list = tmp_list->next) {
- plugin = (plugin_x *)tmp_list->data;
- if (!plugin)
+ for (tmp_list = appid_list; tmp_list != NULL;
+ tmp_list = tmp_list->next) {
+ appid = (char *)tmp_list->data;
+ if (!appid)
continue;
- ret = plugin_list_cb(pkgid, plugin->appid, plugin_type,
- plugin_name, user_data);
+ ret = plugin_list_cb(pkgid, appid, plugin_type,
+ plugin_name, user_data);
if (ret != 0)
break;
}
-catch:
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- g_list_free_full(plugin_list, _free_plugin);
+ g_list_free_full(appid_list, free);
return ret;
-}
\ No newline at end of file
+}