41d929d55f70d74237e6e8da780fa00b766203ab
[platform/core/connectivity/stc-iptables.git] / include / stc-iptables-util.h
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 2 as
6  *  published by the Free Software Foundation.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17
18 #ifndef __STC_IPTABLES_UTIL_H__
19 #define __STC_IPTABLES_UTIL_H__
20
21 #include <glib.h>
22 #include <gio/gio.h>
23 #include <stdio.h>
24
25 #include "stc-iptables-gdbus.h"
26 #include "helper-log.h"
27
28 #define MALLOC0(t, n) ((t*) g_try_malloc0((n) * sizeof(t)))
29 #define FREE(p) do { \
30         if (p) { \
31                 g_free(p); \
32                 p = NULL; \
33         } \
34 } while (0)
35
36 #define STC_DEBUG_GDBUS_VARIANT(str, parameters) do { \
37                 gchar *params_str = NULL; \
38                 if (parameters) { \
39                         params_str = g_variant_print(parameters, \
40                                                          TRUE); \
41                 } \
42                 STC_LOGD("%s[%s]", str, \
43                          params_str ? params_str : "NULL"); \
44                 g_free(params_str); \
45         } while (0)
46
47 #define STC_DEBUG_GDBUS_KEY_VALUE(key, value) do { \
48                         if (key) { \
49                                 STC_LOGD("Key : [%s]", key); \
50                         } \
51                         if (value) { \
52                                 STC_DEBUG_GDBUS_VARIANT("Value: ", value); \
53                         } \
54                 } while (0)
55
56 gboolean handle_iptables_stop(StcManager *object,
57                                    GDBusMethodInvocation *invocation);
58
59 /* iptables */
60 gboolean handle_iptables_add_rule(StcRule *object,
61                                GDBusMethodInvocation *invocation,
62                                GVariant *rule,
63                                void *user_data);
64
65 gboolean handle_iptables_insert_rule(StcRule *object,
66                                GDBusMethodInvocation *invocation,
67                                GVariant *rule,
68                                void *user_data);
69
70 gboolean handle_iptables_remove_rule(StcRule *object,
71                                GDBusMethodInvocation *invocation,
72                                GVariant *rule,
73                                void *user_data);
74
75 gboolean handle_iptables_add_chain(StcChain *object,
76                                GDBusMethodInvocation *invocation,
77                                const gchar *chain,
78                                void *user_data);
79
80 gboolean handle_iptables_remove_chain(StcChain *object,
81                                GDBusMethodInvocation *invocation,
82                                const gchar *chain,
83                                void *user_data);
84
85 gboolean handle_iptables_flush_chain(StcChain *object,
86                                GDBusMethodInvocation *invocation,
87                                const gchar *chain,
88                                void *user_data);
89
90 /* ip6tables */
91 gboolean handle_ip6tables_add_rule(StcRule *object,
92                                GDBusMethodInvocation *invocation,
93                                GVariant *rule,
94                                void *user_data);
95
96 gboolean handle_ip6tables_insert_rule(StcRule *object,
97                                GDBusMethodInvocation *invocation,
98                                GVariant *rule,
99                                void *user_data);
100
101 gboolean handle_ip6tables_remove_rule(StcRule *object,
102                                GDBusMethodInvocation *invocation,
103                                GVariant *rule,
104                                void *user_data);
105
106 gboolean handle_ip6tables_add_chain(StcChain *object,
107                                GDBusMethodInvocation *invocation,
108                                const gchar *chain,
109                                void *user_data);
110
111 gboolean handle_ip6tables_remove_chain(StcChain *object,
112                                GDBusMethodInvocation *invocation,
113                                const gchar *chain,
114                                void *user_data);
115
116 gboolean handle_ip6tables_flush_chain(StcChain *object,
117                                GDBusMethodInvocation *invocation,
118                                const gchar *chain,
119                                void *user_data);
120
121 #endif /* __STC_IPTABLES_UTIL_H__ */