Added firewall feature
[platform/core/connectivity/stc-manager.git] / src / stc-manager-plugin-appstatus.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dlfcn.h>
18
19 #include "stc-manager.h"
20 #include "stc-manager-plugin-appstatus.h"
21
22 static gboolean stc_plugin_enabled = FALSE;
23 static void *handle_plugin;
24 static stc_plugin_appstatus_s *stc_plugin;
25
26 //LCOV_EXCL_START
27 int stc_plugin_appstatus_init(void)
28 {
29         __STC_LOG_FUNC_ENTER__;
30
31         handle_plugin = dlopen(STC_PLUGIN_APPSTATUS_FILEPATH, RTLD_NOW);
32         if (!handle_plugin) {
33                 STC_LOGE("Can't load %s: %s", STC_PLUGIN_APPSTATUS_FILEPATH, dlerror());
34                 __STC_LOG_FUNC_EXIT__;
35                 return STC_ERROR_UNINITIALIZED;
36         }
37
38         stc_plugin = dlsym(handle_plugin, "stc_plugin_appstatus");
39         if (!stc_plugin) {
40                 STC_LOGE("Can't load symbol: %s", dlerror());
41                 dlclose(handle_plugin);
42                 __STC_LOG_FUNC_EXIT__;
43                 return STC_ERROR_UNINITIALIZED;
44         }
45
46         stc_plugin_enabled = TRUE;
47
48         __STC_LOG_FUNC_EXIT__;
49         return STC_ERROR_NONE;
50 }
51
52 int stc_plugin_appstatus_deinit(void)
53 {
54         __STC_LOG_FUNC_ENTER__;
55
56         if (!stc_plugin_enabled) {
57                 __STC_LOG_FUNC_EXIT__;
58                 return STC_ERROR_UNINITIALIZED;
59         }
60
61         stc_plugin_enabled = FALSE;
62         dlclose(handle_plugin);
63         __STC_LOG_FUNC_EXIT__;
64         return STC_ERROR_NONE;
65 }
66
67 int stc_plugin_appstatus_send_warn_message(const char *content,
68                 const char *type, const char *app_id, const char *iftype, const char *warn)
69 {
70         __STC_LOG_FUNC_ENTER__;
71
72         if (!stc_plugin_enabled) {
73                 STC_LOGE("Plugin wasn't enabled");
74                 __STC_LOG_FUNC_EXIT__;
75                 return STC_ERROR_UNINITIALIZED;
76         }
77
78         if (!stc_plugin) {
79                 STC_LOGE("Plugin wasn't loaded");
80                 __STC_LOG_FUNC_EXIT__;
81                 return STC_ERROR_UNINITIALIZED;
82         }
83
84         __STC_LOG_FUNC_EXIT__;
85         return stc_plugin->send_warn_message_to_net_popup(content,
86                                                         type, app_id, iftype, warn);
87 }
88
89 int stc_plugin_appstatus_send_restriction_message(const char *content,
90                 const char *type, const char *app_id, const char *iftype, const char *limit)
91 {
92         __STC_LOG_FUNC_ENTER__;
93
94         if (!stc_plugin_enabled) {
95                 STC_LOGE("Plugin wasn't enabled");
96                 __STC_LOG_FUNC_EXIT__;
97                 return STC_ERROR_UNINITIALIZED;
98         }
99
100         if (!stc_plugin) {
101                 STC_LOGE("Plugin wasn't loaded");
102                 __STC_LOG_FUNC_EXIT__;
103                 return STC_ERROR_UNINITIALIZED;
104         }
105
106         __STC_LOG_FUNC_EXIT__;
107         return stc_plugin->send_restriction_message_to_net_popup(content,
108                                                         type, app_id, iftype, limit);
109 }
110
111 int stc_plugin_appstatus_register_state_changed_cb(stc_s *stc,
112                 stc_plugin_app_state_changed_cb cb, void *data)
113 {
114         __STC_LOG_FUNC_ENTER__;
115
116         if (!stc_plugin_enabled) {
117                 STC_LOGE("Plugin wasn't enabled");
118                 __STC_LOG_FUNC_EXIT__;
119                 return STC_ERROR_UNINITIALIZED;
120         }
121
122         if (!stc_plugin) {
123                 STC_LOGE("Plugin wasn't loaded");
124                 __STC_LOG_FUNC_EXIT__;
125                 return STC_ERROR_UNINITIALIZED;
126         }
127
128         __STC_LOG_FUNC_EXIT__;
129         return stc_plugin->register_state_changed_cb(stc, cb, data);
130 }
131
132 int stc_plugin_appstatus_deregister_state_changed_cb(stc_s *stc)
133 {
134         __STC_LOG_FUNC_ENTER__;
135
136         if (!stc_plugin_enabled) {
137                 STC_LOGE("Plugin wasn't enabled");
138                 __STC_LOG_FUNC_EXIT__;
139                 return STC_ERROR_UNINITIALIZED;
140         }
141
142         if (!stc_plugin) {
143                 STC_LOGE("Plugin wasn't loaded");
144                 __STC_LOG_FUNC_EXIT__;
145                 return STC_ERROR_UNINITIALIZED;
146         }
147
148         __STC_LOG_FUNC_EXIT__;
149         return stc_plugin->deregister_state_changed_cb(stc);
150 }
151 //LCOV_EXCL_STOP