2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * This file implements exceptions entity handler methods.
20 * @file stc-exception.c
23 #include <pkgmgr-info.h>
25 #include "stc-manager.h"
26 #include "stc-exception.h"
28 #define EXCEPTION_BUF_MAX 64
29 #define EXCEPTION_STORAGE "/var/lib/stc/exceptions"
31 #define INTERNET_PRIVILEGE "http://tizen.org/privilege/internet"
33 static GHashTable *g_pkginfo_filter_hash;
35 stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
38 __STC_LOG_FUNC_ENTER__;
40 stc_error_e error_code = STC_ERROR_NONE;
41 stc_exceptions_info data;
44 char buf[EXCEPTION_BUF_MAX] = {0, };
46 fp = fopen(EXCEPTION_STORAGE, "r");
47 ret_value_msg_if(!fp, STC_ERROR_FAIL, "Failed to open %s file");
49 while (fgets(buf, sizeof(buf), fp) != NULL) {
50 char *process_name, *exe_type;
51 char *save_ptr = NULL;
53 process_name = strtok_r(buf, ":", &save_ptr);
54 if (process_name != NULL)
55 data.process_name = process_name;
57 data.process_name = "none"; //LCOV_EXCL_LINE
59 exe_type = strtok_r(NULL, "\n", &save_ptr);
61 data.exe_type = exe_type;
63 data.exe_type = "none"; //LCOV_EXCL_LINE
65 if (exception_cb(&data, user_data) == STC_CANCEL)
70 __STC_LOG_FUNC_EXIT__;
74 static int __pkginfo_filter_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
79 ret = pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgname);
80 if (ret == PMINFO_R_OK) {
81 if (g_hash_table_insert(g_pkginfo_filter_hash,
82 g_strdup(pkgname), g_strdup(EXE_TYPE_APPLICATION)) != TRUE)
83 STC_LOGE("Failed to insert hash table"); //LCOV_EXCL_LINE
89 static int __pkginfo_pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
93 char *exe_type = NULL;
94 stc_exceptions_info data;
95 const stc_exceptions_info_cb excn_cb = user_data;
97 ret = pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgname);
98 if (ret == PMINFO_R_OK) {
99 exe_type = g_hash_table_lookup(g_pkginfo_filter_hash, pkgname);
103 data.process_name = pkgname;
104 data.exe_type = EXE_TYPE_APPLICATION;
106 if (excn_cb(&data, NULL) == STC_CANCEL)
107 STC_LOGE("Failed to insert hash table"); //LCOV_EXCL_LINE
113 stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
116 __STC_LOG_FUNC_ENTER__;
119 int err = STC_ERROR_NONE;
120 pkgmgrinfo_pkginfo_filter_h handle;
122 g_pkginfo_filter_hash = g_hash_table_new_full(g_str_hash,
123 g_str_equal, g_free, g_free);
125 ret = pkgmgrinfo_pkginfo_filter_create(&handle);
126 ret_value_msg_if(ret != PMINFO_R_OK, STC_ERROR_FAIL,
127 "Failed to create pkginfo filter");
129 ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
130 PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
132 if (ret != PMINFO_R_OK) {
133 STC_LOGE("Failed to add pkginfo filter string"); //LCOV_EXCL_LINE
134 err = STC_ERROR_FAIL; //LCOV_EXCL_LINE
135 goto out; //LCOV_EXCL_LINE
138 ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
139 __pkginfo_filter_list_cb, NULL);
140 if (ret != PMINFO_R_OK) {
141 STC_LOGE("Failed to foreach pkginfo filter"); //LCOV_EXCL_LINE
142 err = STC_ERROR_FAIL; //LCOV_EXCL_LINE
143 goto out; //LCOV_EXCL_LINE
146 ret = pkgmgrinfo_pkginfo_get_list(__pkginfo_pkg_list_cb, exception_cb);
147 if (ret != PMINFO_R_OK) {
148 STC_LOGE("Failed to get pkginfo list"); //LCOV_EXCL_LINE
149 err = STC_ERROR_FAIL; //LCOV_EXCL_LINE
150 goto out; //LCOV_EXCL_LINE
154 if (g_pkginfo_filter_hash) {
155 g_hash_table_destroy(g_pkginfo_filter_hash);
156 g_pkginfo_filter_hash = NULL;
160 pkgmgrinfo_pkginfo_filter_destroy(handle);
162 __STC_LOG_FUNC_EXIT__;