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 #include "table-firewall.h"
19 #include "helper-firewall.h"
20 #include "stc-firewall.h"
21 #include "stc-manager-gdbus.h"
22 #include "stc-manager-plugin-firewall.h"
24 #define FIREWALL_DBUS_ERROR_NAME "net.stc.firewall.Error.Failed"
26 #define STC_FIREWALL_DBUS_REPLY_ERROR(invocation, err_num) \
27 g_dbus_method_invocation_return_dbus_error((invocation), \
28 FIREWALL_DBUS_ERROR_NAME, \
29 stc_err_strs[-(err_num)])
31 static const gchar *stc_err_strs[] = {
44 gboolean handle_firewall_lock(StcFirewall *object,
45 GDBusMethodInvocation *invocation,
48 __STC_LOG_FUNC_ENTER__;
50 stc_set_keep_alive(TRUE);
52 stc_plugin_firewall_lock();
54 STC_DBUS_REPLY_ERROR_NONE(invocation);
55 __STC_LOG_FUNC_EXIT__;
59 gboolean handle_firewall_unlock(StcFirewall *object,
60 GDBusMethodInvocation *invocation,
63 __STC_LOG_FUNC_ENTER__;
65 stc_set_keep_alive(TRUE);
67 stc_plugin_firewall_unlock();
69 STC_DBUS_REPLY_ERROR_NONE(invocation);
70 __STC_LOG_FUNC_EXIT__;
74 gboolean handle_firewall_get_lock(StcFirewall *object,
75 GDBusMethodInvocation *invocation,
78 __STC_LOG_FUNC_ENTER__;
79 GVariant *return_parameters = NULL;
82 stc_set_keep_alive(TRUE);
84 stc_plugin_firewall_get_lock(&state);
86 return_parameters = g_variant_new("(i)", state);
87 STC_DBUS_REPLY(invocation, return_parameters);
88 __STC_LOG_FUNC_EXIT__;
92 gboolean handle_firewall_add_chain(StcFirewall *object,
93 GDBusMethodInvocation *invocation,
97 __STC_LOG_FUNC_ENTER__;
98 int ret = STC_ERROR_NONE;
100 stc_set_keep_alive(TRUE);
103 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
104 STC_ERROR_INVALID_PARAMETER);
105 __STC_LOG_FUNC_EXIT__;
109 ret = stc_plugin_firewall_add_chain(chain);
110 if (ret != STC_ERROR_NONE) {
111 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
112 __STC_LOG_FUNC_EXIT__;
116 STC_DBUS_REPLY_ERROR_NONE(invocation);
117 __STC_LOG_FUNC_EXIT__;
121 gboolean handle_firewall_remove_chain(StcFirewall *object,
122 GDBusMethodInvocation *invocation,
126 __STC_LOG_FUNC_ENTER__;
127 int ret = STC_ERROR_NONE;
129 stc_set_keep_alive(TRUE);
132 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
133 STC_ERROR_INVALID_PARAMETER);
134 __STC_LOG_FUNC_EXIT__;
138 ret = stc_plugin_firewall_remove_chain(chain);
139 if (ret != STC_ERROR_NONE) {
140 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
141 __STC_LOG_FUNC_EXIT__;
145 STC_DBUS_REPLY_ERROR_NONE(invocation);
146 __STC_LOG_FUNC_EXIT__;
150 gboolean handle_firewall_flush_chain(StcFirewall *object,
151 GDBusMethodInvocation *invocation,
155 __STC_LOG_FUNC_ENTER__;
156 int ret = STC_ERROR_NONE;
158 stc_set_keep_alive(TRUE);
161 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
162 STC_ERROR_INVALID_PARAMETER);
163 __STC_LOG_FUNC_EXIT__;
167 ret = stc_plugin_firewall_flush_chain(chain);
168 if (ret != STC_ERROR_NONE) {
169 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
170 __STC_LOG_FUNC_EXIT__;
174 STC_DBUS_REPLY_ERROR_NONE(invocation);
175 __STC_LOG_FUNC_EXIT__;
179 gboolean handle_firewall_get_all_chain(StcFirewall *object,
180 GDBusMethodInvocation *invocation,
183 __STC_LOG_FUNC_ENTER__;
184 GVariantBuilder *builder = NULL;
185 GVariant *return_parameters = NULL;
187 stc_set_keep_alive(TRUE);
189 builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
191 stc_plugin_firewall_get_all_chain(builder);
193 return_parameters = g_variant_new("(aa{sv})", builder);
194 g_variant_builder_unref(builder);
196 DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
197 STC_DBUS_REPLY(invocation, return_parameters);
198 __STC_LOG_FUNC_EXIT__;
202 gboolean handle_firewall_set_chain(StcFirewall *object,
203 GDBusMethodInvocation *invocation,
208 __STC_LOG_FUNC_ENTER__;
209 int ret = STC_ERROR_NONE;
211 stc_set_keep_alive(TRUE);
214 target >= STC_FW_CHAIN_TARGET_MAX) {
215 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
216 STC_ERROR_INVALID_PARAMETER);
217 __STC_LOG_FUNC_EXIT__;
221 ret = stc_plugin_firewall_set_chain(chain, target);
222 if (ret != STC_ERROR_NONE) {
223 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
224 __STC_LOG_FUNC_EXIT__;
228 STC_DBUS_REPLY_ERROR_NONE(invocation);
229 __STC_LOG_FUNC_EXIT__;
233 gboolean handle_firewall_unset_chain(StcFirewall *object,
234 GDBusMethodInvocation *invocation,
238 __STC_LOG_FUNC_ENTER__;
239 int ret = STC_ERROR_NONE;
241 stc_set_keep_alive(TRUE);
244 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
245 STC_ERROR_INVALID_PARAMETER);
246 __STC_LOG_FUNC_EXIT__;
250 ret = stc_plugin_firewall_unset_chain(chain);
251 if (ret != STC_ERROR_NONE) {
252 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
253 __STC_LOG_FUNC_EXIT__;
257 STC_DBUS_REPLY_ERROR_NONE(invocation);
258 __STC_LOG_FUNC_EXIT__;
262 gboolean handle_firewall_add_rule(StcFirewall *object,
263 GDBusMethodInvocation *invocation,
264 GVariant *parameters,
267 __STC_LOG_FUNC_ENTER__;
268 int ret = STC_ERROR_NONE;
270 stc_set_keep_alive(TRUE);
272 ret = stc_plugin_firewall_add_rule(parameters);
273 if (ret != STC_ERROR_NONE) {
274 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
275 __STC_LOG_FUNC_EXIT__;
279 STC_DBUS_REPLY_ERROR_NONE(invocation);
280 __STC_LOG_FUNC_EXIT__;
284 gboolean handle_firewall_remove_rule(StcFirewall *object,
285 GDBusMethodInvocation *invocation,
286 GVariant *parameters,
289 __STC_LOG_FUNC_ENTER__;
290 int ret = STC_ERROR_NONE;
292 stc_set_keep_alive(TRUE);
294 ret = stc_plugin_firewall_remove_rule(parameters);
295 if (ret != STC_ERROR_NONE) {
296 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
297 __STC_LOG_FUNC_EXIT__;
301 STC_DBUS_REPLY_ERROR_NONE(invocation);
302 __STC_LOG_FUNC_EXIT__;
306 gboolean handle_firewall_update_rule(StcFirewall *object,
307 GDBusMethodInvocation *invocation,
308 GVariant *parameters,
311 __STC_LOG_FUNC_ENTER__;
312 int ret = STC_ERROR_NONE;
314 stc_set_keep_alive(TRUE);
316 ret = stc_plugin_firewall_update_rule(parameters);
317 if (ret != STC_ERROR_NONE) {
318 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
319 __STC_LOG_FUNC_EXIT__;
323 STC_DBUS_REPLY_ERROR_NONE(invocation);
324 __STC_LOG_FUNC_EXIT__;
328 gboolean handle_firewall_get_all_rule(StcFirewall *object,
329 GDBusMethodInvocation *invocation,
332 __STC_LOG_FUNC_ENTER__;
333 GVariantBuilder *builder = NULL;
334 GVariant *return_parameters = NULL;
336 stc_set_keep_alive(TRUE);
338 builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
340 stc_plugin_firewall_get_all_rule(builder);
342 return_parameters = g_variant_new("(aa{sv})", builder);
343 g_variant_builder_unref(builder);
345 DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
346 STC_DBUS_REPLY(invocation, return_parameters);
347 __STC_LOG_FUNC_EXIT__;