Merge "Added dbus method to commit iptables" into tizen
[platform/core/connectivity/stc-manager.git] / src / stc-manager-gdbus.c
index 75b93b1..2abe2c1 100755 (executable)
 #include "stc-restriction.h"
 #include "stc-firewall.h"
 #include "stc-default-connection.h"
+#include "stc-manager-util.h"
 #include "stc-manager-plugin-appstatus.h"
 #include "stc-manager-plugin-procfs.h"
 #include "helper-iptables.h"
 
+#define MANAGER_DBUS_ERROR_NAME "net.stc.manager.Error.Failed"
+
+#define STC_MANAGER_DBUS_REPLY_ERROR(invocation, err_num) \
+       g_dbus_method_invocation_return_dbus_error((invocation), \
+                                                  MANAGER_DBUS_ERROR_NAME, \
+                                                  stc_err_strs[-(err_num)])
+
+static const gchar *stc_err_strs[] = {
+       "ERROR_NONE",
+       "FAIL",
+       "DB_FAILED",
+       "OUT_OF_MEMORY",
+       "INVALID_PARAMETER",
+       "NO_DATA",
+       "ALREADY_DATA",
+       "UNINITIALIZED",
+       "PERMISSION_DENIED",
+       "NOTIMPL"
+};
+
 static gboolean __stc_manager_gdbus_statistics_init(stc_s *stc)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -234,6 +255,9 @@ static gboolean __stc_manager_gdbus_manager_init(stc_s *stc)
        g_signal_connect(manager, "handle-stop",
                         G_CALLBACK(handle_manager_stop), stc);
 
+       g_signal_connect(manager, "handle-commit-iptables",
+                        G_CALLBACK(handle_manager_commit_iptables), stc);
+
        g_dbus_object_manager_server_export(stc->obj_mgr,
                                            G_DBUS_OBJECT_SKELETON(object));
        g_object_unref(object);
@@ -494,3 +518,36 @@ gboolean handle_manager_stop(StcManager *object,
        __STC_LOG_FUNC_EXIT__;
        return TRUE;
 }
+
+gboolean handle_manager_commit_iptables(StcManager *object,
+                                       GDBusMethodInvocation *invocation,
+                                       const gchar *option,
+                                       void *user_data)
+{
+       __STC_LOG_FUNC_ENTER__;
+       GVariant *return_parameters = NULL;
+       int ret = STC_ERROR_NONE;
+       int err_num = 0;
+       char *err_str = NULL;
+       char cmd[STC_CMD_SIZE] = { 0, };
+
+       if (option == NULL) {
+               STC_MANAGER_DBUS_REPLY_ERROR(invocation,
+                                                STC_ERROR_INVALID_PARAMETER);
+               __STC_LOG_FUNC_EXIT__;
+               return TRUE;
+       }
+
+       STC_LOGD("[%s]", option);
+       g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IPTABLES, option);
+
+       ret = stc_commit_iptables(cmd, &err_num, &err_str);
+
+       return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
+
+       DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+       STC_DBUS_REPLY(invocation, return_parameters);
+
+       __STC_LOG_FUNC_EXIT__;
+       return TRUE;
+}