4 * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Junghyun Yeon <jungh.yeon@samsung.com>, Sangyoon Jang <jeremy.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include "pkgmgrinfo_private.h"
29 #include "pkgmgrinfo_debug.h"
30 #include "pkgmgr-info.h"
32 static void _free_plugin(gpointer data)
34 plugin_x *plugin = (plugin_x *)data;
38 free((void *)plugin->appid);
42 API int pkgmgrinfo_plugininfo_foreach_plugininfo(const char *pkgid,
43 const char *plugin_type, const char *plugin_name,
44 pkgmgrinfo_plugin_list_cb plugin_list_cb, void *user_data)
51 sqlite3_stmt *stmt = NULL;
53 GList *plugin_list = NULL;
56 static const char query[] =
58 "package_plugin_info WHERE pkgid=? AND "
59 "plugin_type=? AND plugin_name=?";
61 if (!pkgid || !plugin_type || !plugin_name || !plugin_list_cb) {
62 _LOGE("Invalid parameter");
63 return PMINFO_R_EINVAL;
66 dbpath = getUserPkgParserDBPathUID(_getuid());
68 _LOGE("Failed to get db path");
69 return PMINFO_R_ERROR;
72 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
73 if (ret != SQLITE_OK) {
74 _LOGD("failed to open db(%s): %d", dbpath, ret);
76 return PMINFO_R_ERROR;
80 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
81 if (ret != SQLITE_OK) {
82 LOGE("prepare failed: %s", sqlite3_errmsg(db));
87 ret = sqlite3_bind_text(stmt, ++idx, pkgid, -1, SQLITE_STATIC);
88 if (ret != SQLITE_OK) {
93 ret = sqlite3_bind_text(stmt, ++idx, plugin_type, -1, SQLITE_STATIC);
94 if (ret != SQLITE_OK) {
98 ret = sqlite3_bind_text(stmt, ++idx, plugin_name, -1, SQLITE_STATIC);
99 if (ret != SQLITE_OK) {
100 ret = PMINFO_R_ERROR;
104 while (sqlite3_step(stmt) == SQLITE_ROW) {
105 plugin = calloc(1, sizeof(plugin_x));
106 if (plugin == NULL) {
107 _LOGE("out of memory");
108 ret = PMINFO_R_ERROR;
112 appid = (const char *)sqlite3_column_text(stmt, idx++);
114 plugin->appid = strdup(appid);
116 plugin_list = g_list_append(plugin_list, plugin);
119 for (tmp_list = plugin_list; tmp_list != NULL; tmp_list = tmp_list->next) {
120 plugin = (plugin_x *)tmp_list->data;
123 ret = plugin_list_cb(pkgid, plugin->appid, plugin_type,
124 plugin_name, user_data);
128 g_list_free_full(plugin_list, _free_plugin);
131 sqlite3_finalize(stmt);
132 sqlite3_close_v2(db);