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_plugin_firewall_lock();
52 STC_DBUS_REPLY_ERROR_NONE(invocation);
53 __STC_LOG_FUNC_EXIT__;
57 gboolean handle_firewall_unlock(StcFirewall *object,
58 GDBusMethodInvocation *invocation,
61 __STC_LOG_FUNC_ENTER__;
63 stc_plugin_firewall_unlock();
65 STC_DBUS_REPLY_ERROR_NONE(invocation);
66 __STC_LOG_FUNC_EXIT__;
70 gboolean handle_firewall_get_lock(StcFirewall *object,
71 GDBusMethodInvocation *invocation,
74 __STC_LOG_FUNC_ENTER__;
75 GVariant *return_parameters = NULL;
78 stc_plugin_firewall_get_lock(&state);
80 return_parameters = g_variant_new("(i)", state);
81 STC_DBUS_REPLY(invocation, return_parameters);
82 __STC_LOG_FUNC_EXIT__;
86 gboolean handle_firewall_add_chain(StcFirewall *object,
87 GDBusMethodInvocation *invocation,
91 __STC_LOG_FUNC_ENTER__;
92 int ret = STC_ERROR_NONE;
95 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
96 STC_ERROR_INVALID_PARAMETER);
97 __STC_LOG_FUNC_EXIT__;
101 ret = stc_plugin_firewall_add_chain(chain);
102 if (ret != STC_ERROR_NONE) {
103 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
104 __STC_LOG_FUNC_EXIT__;
108 STC_DBUS_REPLY_ERROR_NONE(invocation);
109 __STC_LOG_FUNC_EXIT__;
113 gboolean handle_firewall_remove_chain(StcFirewall *object,
114 GDBusMethodInvocation *invocation,
118 __STC_LOG_FUNC_ENTER__;
119 int ret = STC_ERROR_NONE;
122 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
123 STC_ERROR_INVALID_PARAMETER);
124 __STC_LOG_FUNC_EXIT__;
128 ret = stc_plugin_firewall_remove_chain(chain);
129 if (ret != STC_ERROR_NONE) {
130 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
131 __STC_LOG_FUNC_EXIT__;
135 STC_DBUS_REPLY_ERROR_NONE(invocation);
136 __STC_LOG_FUNC_EXIT__;
140 gboolean handle_firewall_flush_chain(StcFirewall *object,
141 GDBusMethodInvocation *invocation,
145 __STC_LOG_FUNC_ENTER__;
146 int ret = STC_ERROR_NONE;
149 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
150 STC_ERROR_INVALID_PARAMETER);
151 __STC_LOG_FUNC_EXIT__;
155 ret = stc_plugin_firewall_flush_chain(chain);
156 if (ret != STC_ERROR_NONE) {
157 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
158 __STC_LOG_FUNC_EXIT__;
162 STC_DBUS_REPLY_ERROR_NONE(invocation);
163 __STC_LOG_FUNC_EXIT__;
167 gboolean handle_firewall_get_all_chain(StcFirewall *object,
168 GDBusMethodInvocation *invocation,
171 __STC_LOG_FUNC_ENTER__;
172 GVariantBuilder *builder = NULL;
173 GVariant *return_parameters = NULL;
175 builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
177 stc_plugin_firewall_get_all_chain(builder);
179 return_parameters = g_variant_new("(aa{sv})", builder);
180 g_variant_builder_unref(builder);
182 DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
183 STC_DBUS_REPLY(invocation, return_parameters);
184 __STC_LOG_FUNC_EXIT__;
188 gboolean handle_firewall_set_chain(StcFirewall *object,
189 GDBusMethodInvocation *invocation,
194 __STC_LOG_FUNC_ENTER__;
195 int ret = STC_ERROR_NONE;
198 target >= STC_FW_CHAIN_TARGET_MAX) {
199 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
200 STC_ERROR_INVALID_PARAMETER);
201 __STC_LOG_FUNC_EXIT__;
205 ret = stc_plugin_firewall_set_chain(chain, target);
206 if (ret != STC_ERROR_NONE) {
207 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
208 __STC_LOG_FUNC_EXIT__;
212 STC_DBUS_REPLY_ERROR_NONE(invocation);
213 __STC_LOG_FUNC_EXIT__;
217 gboolean handle_firewall_unset_chain(StcFirewall *object,
218 GDBusMethodInvocation *invocation,
222 __STC_LOG_FUNC_ENTER__;
223 int ret = STC_ERROR_NONE;
226 STC_FIREWALL_DBUS_REPLY_ERROR(invocation,
227 STC_ERROR_INVALID_PARAMETER);
228 __STC_LOG_FUNC_EXIT__;
232 ret = stc_plugin_firewall_unset_chain(chain);
233 if (ret != STC_ERROR_NONE) {
234 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
235 __STC_LOG_FUNC_EXIT__;
239 STC_DBUS_REPLY_ERROR_NONE(invocation);
240 __STC_LOG_FUNC_EXIT__;
244 gboolean handle_firewall_add_rule(StcFirewall *object,
245 GDBusMethodInvocation *invocation,
246 GVariant *parameters,
249 __STC_LOG_FUNC_ENTER__;
250 int ret = STC_ERROR_NONE;
252 ret = stc_plugin_firewall_add_rule(parameters);
253 if (ret != STC_ERROR_NONE) {
254 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
255 __STC_LOG_FUNC_EXIT__;
259 STC_DBUS_REPLY_ERROR_NONE(invocation);
260 __STC_LOG_FUNC_EXIT__;
264 gboolean handle_firewall_remove_rule(StcFirewall *object,
265 GDBusMethodInvocation *invocation,
266 GVariant *parameters,
269 __STC_LOG_FUNC_ENTER__;
270 int ret = STC_ERROR_NONE;
272 ret = stc_plugin_firewall_remove_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_update_rule(StcFirewall *object,
285 GDBusMethodInvocation *invocation,
286 GVariant *parameters,
289 __STC_LOG_FUNC_ENTER__;
290 int ret = STC_ERROR_NONE;
292 ret = stc_plugin_firewall_update_rule(parameters);
293 if (ret != STC_ERROR_NONE) {
294 STC_FIREWALL_DBUS_REPLY_ERROR(invocation, ret);
295 __STC_LOG_FUNC_EXIT__;
299 STC_DBUS_REPLY_ERROR_NONE(invocation);
300 __STC_LOG_FUNC_EXIT__;
304 gboolean handle_firewall_get_all_rule(StcFirewall *object,
305 GDBusMethodInvocation *invocation,
308 __STC_LOG_FUNC_ENTER__;
309 GVariantBuilder *builder = NULL;
310 GVariant *return_parameters = NULL;
312 builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}"));
314 stc_plugin_firewall_get_all_rule(builder);
316 return_parameters = g_variant_new("(aa{sv})", builder);
317 g_variant_builder_unref(builder);
319 DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
320 STC_DBUS_REPLY(invocation, return_parameters);
321 __STC_LOG_FUNC_EXIT__;