remove circular dependency among directories 28/241928/1
authorYoungjae Shin <yj99.shin@samsung.com>
Fri, 21 Aug 2020 02:17:29 +0000 (11:17 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Fri, 21 Aug 2020 02:17:29 +0000 (11:17 +0900)
Change-Id: Ida62a9a5f96ca555a7f8d36e5d87659a8dd2db1c

85 files changed:
CMakeLists.txt
include/db/table-firewall.h
include/stc-counter.h
include/stc-db.h
include/stc-firewall.h
include/stc-gdbus.h
include/stc-helper-cgroup.h [new file with mode: 0644]
include/stc-helper-iptables.h [new file with mode: 0644]
include/stc-helper-net-cls.h [new file with mode: 0644]
include/stc-helper-nfacct-rule.h [new file with mode: 0644]
include/stc-helper-nl.h [new file with mode: 0644]
include/stc-helper-procfs.h [new file with mode: 0644]
include/stc-plugin-exception.h
include/stc-plugin-firewall.h
include/stc-plugin-iface-appstatus.h
include/stc-plugin-iface-exception.h
include/stc-plugin-iface-firewall.h
include/stc-plugin-iface-monitor.h
include/stc-plugin-iface-procfs.h
include/stc-plugin-iface-tether.h
include/stc-plugin-monitor.h
include/stc-plugin-tether.h
include/stc-restriction.h
include/stc-statistics.h [deleted file]
include/stc-util-inotify.h
include/stc-util.h
include/stc.h
manager/database/CMakeLists.txt
manager/database/db-guard.c
manager/database/db-internal.h
manager/helper/helper-cgroup.c
manager/helper/helper-cgroup.h
manager/helper/helper-file.c
manager/helper/helper-file.h
manager/helper/helper-firewall.h
manager/helper/helper-iptables.c
manager/helper/helper-iptables.h
manager/helper/helper-net-cls.c
manager/helper/helper-net-cls.h
manager/helper/helper-nfacct-rule.c
manager/helper/helper-nfacct-rule.h
manager/helper/helper-nl.h
manager/helper/helper-procfs.h
manager/stcmgr-firewall.c
manager/stcmgr-firewall.h [new file with mode: 0644]
manager/stcmgr-gdbus.c
manager/stcmgr-gdbus.h [new file with mode: 0644]
manager/stcmgr-pcap.c
manager/stcmgr-pcap.h [moved from include/stc-pcap.h with 97% similarity]
manager/stcmgr-plugin-appstatus.c
manager/stcmgr-plugin-appstatus.h [moved from include/stc-plugin-appstatus.h with 100% similarity]
manager/stcmgr-plugin-exception.c
manager/stcmgr-plugin-exception.h [new file with mode: 0644]
manager/stcmgr-plugin-firewall.c
manager/stcmgr-plugin-firewall.h [new file with mode: 0644]
manager/stcmgr-plugin-monitor.c
manager/stcmgr-plugin-monitor.h [new file with mode: 0644]
manager/stcmgr-plugin-pcap.c
manager/stcmgr-plugin-pcap.h [moved from include/stc-plugin-pcap.h with 100% similarity]
manager/stcmgr-plugin-procfs.c
manager/stcmgr-plugin-procfs.h [moved from include/stc-plugin-procfs.h with 100% similarity]
manager/stcmgr-plugin-tether.c
manager/stcmgr-plugin-tether.h [new file with mode: 0644]
manager/stcmgr-restriction.c
manager/stcmgr-restriction.h [new file with mode: 0644]
manager/stcmgr-statistics.c
manager/stcmgr-statistics.h [new file with mode: 0644]
manager/stcmgr.c
manager/stcmgr.h [new file with mode: 0644]
misc/net-cls-release.c
plugin/exception/stcplugin-exception.c
plugin/firewall/CMakeLists.txt
plugin/firewall/stcplugin-firewall.c
plugin/monitor/CMakeLists.txt
plugin/monitor/stcplugin-monitor-app.c
plugin/monitor/stcplugin-monitor-connection.c
plugin/monitor/stcplugin-monitor-ipt.h
plugin/monitor/stcplugin-monitor-proc.c
plugin/monitor/stcplugin-monitor-rstn.c
plugin/monitor/stcplugin-monitor.c
plugin/monitor/stcplugin-monitor.h [new file with mode: 0644]
plugin/pcap/stcplugin-pcap.h
plugin/procfs/CMakeLists.txt
plugin/procfs/stcplugin-procfs.c
plugin/tether/stcplugin-tether.c

index 15da9ef..09b9377 100644 (file)
@@ -5,8 +5,6 @@ INCLUDE(FindPkgConfig)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/dbus-interface)
 
-INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/manager/helper")
-
 SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}")
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11")
index 735320a..24608f1 100644 (file)
@@ -20,7 +20,6 @@
 #include <arpa/inet.h>
 #include <sqlite3.h>
 #include "stc-firewall.h"
-#include "helper-firewall.h"
 
 typedef stc_cb_ret_e
 (*firewall_chain_cb)(const firewall_chain_s *info, void *user_data);
index 95bc0ce..39c4bef 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __STC_DATAUSAGE_COUNTER_H__
 #define __STC_DATAUSAGE_COUNTER_H__
 
-#include "stc-db.h"
+#include "stc.h"
 
 struct counter_arg {
        int sock;
@@ -41,17 +41,4 @@ struct net_counter_opts {
        int app_stat[STC_IFACE_LAST_ELEM - 1];
 };
 
-/**
- * @desc Reschedule existing traffic counter function
- *  Rescheduling logic is following, we will postpone
- *  execution on delay seconds.
- */
-void reschedule_count_timer(const struct counter_arg *carg, const double delay);
-
-struct counter_arg *init_counter_arg(struct net_counter_opts *opts);
-
-void finalize_carg(struct counter_arg *carg);
-
-GTree *create_nfacct_tree(void);
-
 #endif /* __STC_DATAUSAGE_COUNTER_H__ */
index 45c0610..fd3721d 100644 (file)
@@ -76,11 +76,6 @@ typedef struct {
 } stc_db_classid_iftype_key;
 
 /**
- * @desc This function init db oversize erase timer.
- */
-stc_error_e stc_init_db_guard(void);
-
-/**
  * @desc This function deinit db oversize erase timer.
  */
 void stc_deinit_db_guard(void);
index f813d7a..56d115e 100644 (file)
 #ifndef __STC_FIREWALL_H__
 #define __STC_FIREWALL_H__
 
-#include <glib.h>
+#include <arpa/inet.h>
 #include "stc.h"
-#include "stc-gdbus.h"
-#include "db/table-firewall.h"
 
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
-
-/*****************************************************************************
- * Functions Declaration
- *****************************************************************************/
-
-gboolean handle_firewall_lock(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       void *user_data);
-
-gboolean handle_firewall_unlock(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       void *user_data);
-
-gboolean handle_firewall_get_lock(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       void *user_data);
-
-gboolean handle_firewall_add_chain(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       gchar *chain,
-                                       void *user_data);
-
-gboolean handle_firewall_remove_chain(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       gchar *chain,
-                                       void *user_data);
-
-gboolean handle_firewall_flush_chain(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       gchar *chain,
-                                       void *user_data);
-
-gboolean handle_firewall_get_all_chain(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       void *user_data);
-
-gboolean handle_firewall_set_chain(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       gchar *chain,
-                                       unsigned int target,
-                                       void *user_data);
-
-gboolean handle_firewall_unset_chain(StcFirewall *object,
-                                       GDBusMethodInvocation *invocation,
-                                       gchar *chain,
-                                       void *user_data);
-
-gboolean handle_firewall_add_rule(StcFirewall *object,
-                                  GDBusMethodInvocation *invocation,
-                                  GVariant *parameters,
-                                  void *user_data);
-
-gboolean handle_firewall_remove_rule(StcFirewall *object,
-                                  GDBusMethodInvocation *invocation,
-                                  GVariant *parameters,
-                                  void *user_data);
-
-gboolean handle_firewall_update_rule(StcFirewall *object,
-                                  GDBusMethodInvocation *invocation,
-                                  GVariant *parameters,
-                                  void *user_data);
-
-gboolean handle_firewall_get_all_rule(StcFirewall *object,
-                                  GDBusMethodInvocation *invocation,
-                                  void *user_data);
+#define FIREWALL_RULE_TARGET_ACCEPT  "ACCEPT"
+#define FIREWALL_RULE_TARGET_DROP    "DROP"
+#define FIREWALL_RULE_TARGET_LOG     "LOG"
+#define FIREWALL_RULE_TARGET_NFLOG   "NFLOG"
+
+#define RULE_CHAIN      "chain"
+#define RULE_DIRECTION  "direction"
+#define RULE_IFNAME     "ifname"
+#define RULE_PROTOCOL   "protocol"
+#define RULE_TARGET     "target"
+#define RULE_TARGETTYPE "target_type"
+
+#define RULE_FAMILY     "family"
+#define RULE_SIPTYPE    "s_ip_type"
+#define RULE_SIP1       "s_ip1"
+#define RULE_SIP2       "s_ip2"
+#define RULE_DIPTYPE    "d_ip_type"
+#define RULE_DIP1       "d_ip1"
+#define RULE_DIP2       "d_ip2"
+#define RULE_SPORTTYPE  "s_port_type"
+#define RULE_SPORT1     "s_port1"
+#define RULE_SPORT2     "s_port2"
+#define RULE_DPORTTYPE  "d_port_type"
+#define RULE_DPORT1     "d_port1"
+#define RULE_DPORT2     "d_port2"
+
+#define RULE_LOG_LEVEL       "log_level"
+#define RULE_LOG_PREFIX      "log_prefix"
+#define RULE_NFLOG_GROUP     "nflog_group"
+#define RULE_NFLOG_PREFIX    "nflog_prefix"
+#define RULE_NFLOG_RANGE     "nflog_range"
+#define RULE_NFLOG_THRESHOLD "nflog_threshold"
+
+typedef enum {
+       FIREWALL_UNKONWN,
+       FIREWALL_UNLOCKED,
+       FIREWALL_LOCKED
+} firewall_lock_e;
+
+typedef struct {
+       char *chain;
+       stc_fw_chain_target_e target;
+       guint priority;
+} firewall_chain_s;
+
+typedef union {
+       struct in_addr Ipv4;
+       struct in6_addr Ipv6;
+} ip_addr_u;
+
+typedef struct {
+       guint key;
+       char *chain;
+       stc_fw_direction_e direction;
+       stc_fw_ip_type_e s_ip_type;
+       stc_fw_ip_type_e d_ip_type;
+       stc_fw_port_type_e s_port_type;
+       stc_fw_port_type_e d_port_type;
+       stc_fw_protocol_type_e protocol;
+       stc_fw_family_type_e family;
+       ip_addr_u s_ip1;
+       ip_addr_u s_ip2;
+       ip_addr_u d_ip1;
+       ip_addr_u d_ip2;
+       guint s_port1;
+       guint s_port2;
+       guint d_port1;
+       guint d_port2;
+       char *ifname;
+       stc_fw_rule_target_e target;
+       char *target_str;
+       guchar log_level;
+       char *log_prefix;
+       guint nflog_group;
+       char *nflog_prefix;
+       guint nflog_range;
+       guint nflog_threshold;
+       char *identifier;
+} firewall_rule_s;
+
+stc_error_e firewall_chain_add(firewall_chain_s *chain);
+stc_error_e firewall_chain_remove(firewall_chain_s *chain);
+stc_error_e firewall_chain_set(firewall_chain_s *chain);
+stc_error_e firewall_chain_unset(firewall_chain_s *chain);
+
+stc_error_e firewall_rule_append(firewall_rule_s *rule);
 
 #endif /* __STC_FIREWALL_H__ */
index 6715b26..cd8546f 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#pragma once
 
-#ifndef __STC_MANAGER_GDBUS_H__
-#define __STC_MANAGER_GDBUS_H__
-
-#include "stc.h"
-#include "stc-generated-dbus.h"
+#include <gio/gio.h>
 
 #define STC_DBUS_SERVICE                   "net.stc"
 #define STC_DBUS_INTERFACE_RESTRICTION     STC_DBUS_SERVICE ".restriction"
-#define STC_DBUS_SERVICE_PATH              "/net/stc"
 #define STC_DBUS_SERVICE_STATISTICS_PATH   "/net/stc/statistics"
 #define STC_DBUS_SERVICE_RESTRICTION_PATH  "/net/stc/restriction"
 #define STC_DBUS_SERVICE_FIREWALL_PATH     "/net/stc/firewall"
 #define STC_DBUS_SERVICE_PCAP_PATH         "/net/stc/pcap"
 #define STC_DBUS_SERVICE_MANAGER_PATH      "/net/stc/manager"
 
-#define STC_DBUS_REPLY_ERROR_NONE(invocation) \
-       g_dbus_method_invocation_return_value((invocation), \
-                                             g_variant_new("(i)", \
-                                                           STC_ERROR_NONE));
-
-#define STC_DBUS_REPLY(invocation, parameters) \
-       g_dbus_method_invocation_return_value((invocation), parameters);
-
 #define DEBUG_PARAMS(parameters) do {\
        gchar *params_str = NULL;\
        if (parameters)\
@@ -55,8 +43,6 @@
 typedef void(*dbus_dict_cb)(const char *key, GVariant *value,
                            void *user_data);
 
-void stc_manager_gdbus_init(gpointer stc_manager);
-void stc_manager_gdbus_deinit(gpointer stc_manager);
 GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
                                      const char *dest, const char *path,
                                      const char *interface_name,
@@ -86,17 +72,3 @@ gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
                                      const gchar *interface_name,
                                      const gchar *signal_name,
                                      GVariant *parameters);
-
-gboolean handle_manager_stop(StcManager *object,
-                                         GDBusMethodInvocation *invocation);
-
-gboolean handle_manager_commit_iptables(StcManager *object,
-                                       GDBusMethodInvocation *invocation,
-                                       const gchar *option,
-                                       void *user_data);
-gboolean handle_manager_commit_ip6tables(StcManager *object,
-                                       GDBusMethodInvocation *invocation,
-                                       const gchar *option,
-                                       void *user_data);
-
-#endif /* __STC_MANAGER_GDBUS_H__ */
diff --git a/include/stc-helper-cgroup.h b/include/stc-helper-cgroup.h
new file mode 100644 (file)
index 0000000..270ed20
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+/**
+ * @desc this function sets release agent path into cgroup subsystem
+ * and enables this mechanism
+ * @param cgroup_sussys - cgroup subsystem name, it's relative path to cgroup,
+ * relativelly default cgroup path (DEFAULT_CGROUP)
+ * @param release_agent full path to release agent executable
+ * @return negative value if error
+ */
+int cgroup_set_release_agent(const char *cgroup_subsys,
+                            const char *release_agent);
+
+/**
+ * @desc initializes cgroups.
+ */
+void cgroup_init(void);
\ No newline at end of file
diff --git a/include/stc-helper-iptables.h b/include/stc-helper-iptables.h
new file mode 100644 (file)
index 0000000..4d93fb0
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "stc.h"
+
+stc_error_e iptables_flush_chains(void);
+stc_error_e iptables_init(void);
+stc_error_e iptables_deinit(void);
\ No newline at end of file
diff --git a/include/stc-helper-net-cls.h b/include/stc-helper-net-cls.h
new file mode 100644 (file)
index 0000000..31022e7
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <sys/types.h>
+#include <glib.h>
+
+#include "stc.h"
+
+stc_error_e init_current_classid(void);
+
+/**
+ * @desc take classid from net_cls cgroup by appid
+ *     This function converts appid to pkgname.
+ * @param pkg_name - name of the cgroup
+ * @param create - in case of true - create cgroup if it's not exists
+ * @return classid
+ */
+uint32_t get_classid_by_app_id(const char *app_id, int create);
+
+stc_error_e place_pids_to_net_cgroup(const int pid, const char *pkg_name);
\ No newline at end of file
diff --git a/include/stc-helper-nfacct-rule.h b/include/stc-helper-nfacct-rule.h
new file mode 100644 (file)
index 0000000..12cd5eb
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <stdbool.h>
+#include <glib.h>
+#include "stc-helper-nl.h"
+
+#define NFACCT_NAME_MAX 64
+
+typedef enum {
+       NFACCT_COUNTER_UNKNOWN,
+       NFACCT_COUNTER_IN = (1 << 1),
+       NFACCT_COUNTER_OUT = (1 << 2),
+       NFACCT_COUNTER_FORWARD = (1 << 3),
+       NFACCT_COUNTER_LAST_ELEM
+} nfacct_rule_direction;
+
+typedef enum {
+       NFACCT_ACTION_UNKNOWN,
+       NFACCT_ACTION_APPEND,
+       NFACCT_ACTION_DELETE,
+       NFACCT_ACTION_INSERT,
+       NFACCT_ACTION_LAST_ELEM,
+} nfacct_rule_action;
+
+typedef enum {
+       NFACCT_JUMP_UNKNOWN,
+       NFACCT_JUMP_ACCEPT,
+       NFACCT_JUMP_REJECT,
+       NFACCT_JUMP_LAST_ELEM,
+} nfacct_rule_jump;
+
+typedef enum {
+       NFACCT_COUNTER,
+       NFACCT_WARN,
+       NFACCT_BLOCK,
+       NFACCT_ALLOW,
+       NFACCT_TETH_COUNTER,
+       NFACCT_TETH_WARN,
+       NFACCT_TETH_BLOCK,
+       NFACCT_TETH_ALLOW,
+       NFACCT_RULE_LAST_ELEM,
+} nfacct_rule_intend;
+
+typedef enum {
+       NFACCT_TYPE_UNKNOWN,
+       NFACCT_TYPE_IPV4,
+       NFACCT_TYPE_IPV6,
+       NFACCT_TYPE_IPV4_IPV6,
+       NFACCT_TYPE_LAST_ELEM
+} nfacct_rule_iptype;
+
+typedef enum {
+       NFACCT_IPRANGE_TYPE_NONE,
+       NFACCT_IPRANGE_TYPE_SINGLE,
+       NFACCT_IPRANGE_TYPE_MASK,
+       NFACCT_IPRANGE_TYPE_RANGE,
+} nfacct_rule_iprange_type;
+
+/**
+ * it's better to have
+ * base nfacct_rule with following fields:
+ *  name, ifname, pid, classid, iftype, intend, carg, iptables_rule
+ *
+ *  and inherited nfacct_rule_counter and nfacct_rule_restriction
+ *  with additional field:
+ *     quota, quota_id, roaming, rstn_state
+ *
+ * But ANSI C doesn't support inheritance.
+ */
+struct nfacct_rule {
+       char name[NFACCT_NAME_MAX];
+       char ifname[MAX_IFACE_LENGTH];
+
+       pid_t pid;
+       uint32_t classid;
+       stc_iface_type_e iftype;
+       nfacct_rule_action action;
+       nfacct_rule_direction iotype;
+       nfacct_rule_intend intend;
+       nfacct_rule_jump jump; /* in most cases jump is evalutation based on intend, but not always */
+       stc_app_state_e app_state;
+       stc_rstn_state_e rstn_state;
+       nfacct_rule_iptype iptype;
+       nfacct_rule_iprange_type src_iprange_type;
+       nfacct_rule_iprange_type dst_iprange_type;
+       char *src_ip1;
+       char *src_ip2;
+       char *dst_ip1;
+       char *dst_ip2;
+
+       struct counter_arg *carg;
+       stc_error_e(*iptables_rule)(struct nfacct_rule *counter);
+       long long int quota;
+       int quota_id;
+       stc_roaming_type_e roaming;
+
+       long long int send_limit;
+       long long int rcv_limit;
+};
+
+typedef struct nfacct_rule nfacct_rule_s;
+
+bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *counter);
+stc_error_e nfacct_send_get_all(struct counter_arg *carg);
+stc_error_e produce_net_rule(nfacct_rule_s *rule);
+stc_error_e produce_net_list(GSList *rule_list,
+       nfacct_rule_iptype iptype, nfacct_rule_action action);
+netlink_serialization_command* netlink_create_command(struct netlink_serialization_params *params);
diff --git a/include/stc-helper-nl.h b/include/stc-helper-nl.h
new file mode 100644 (file)
index 0000000..bb1ece1
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <linux/netlink.h>
+#include <linux/genetlink.h>
+#include <linux/rtnetlink.h>
+
+#include "stc.h"
+
+#define NETLINK_BUF_SIZE 16536
+
+enum nfnl_acct_type {
+       NFACCT_UNSPEC,
+       NFACCT_NAME,
+       NFACCT_PKTS,
+       NFACCT_BYTES,
+       NFACCT_USE,
+       NFACCT_FLAGS,
+       NFACCT_QUOTA,
+       NFACCT_FILTER,
+       __NFACCT_MAX
+};
+
+struct genl {
+       struct nlmsghdr n;
+       struct genlmsghdr g;
+       char buf[NETLINK_BUF_SIZE];
+};
+
+struct netlink_serialization_params {
+       int direction;
+       struct genl *ans;
+       struct counter_arg *carg;
+       int (*eval_attr)(struct rtattr *attr_list[__NFACCT_MAX],
+                        void *user_data);
+       int (*post_eval_attr)(void *user_data);
+};
+
+typedef struct {
+       void (*deserialize_answer)(struct netlink_serialization_params *params);
+       void (*finalize)(struct netlink_serialization_params *params);
+       struct netlink_serialization_params params;
+} netlink_serialization_command;
+
+int create_netlink(int protocol, uint32_t groups);
+int read_netlink(int sock, void *buf, size_t len);
diff --git a/include/stc-helper-procfs.h b/include/stc-helper-procfs.h
new file mode 100644 (file)
index 0000000..5d1e3a7
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#pragma once
+
+#include <stdio.h>
+#include "stc-util.h"
+
+/**
+ * @desc get command line from /proc/{pid}/cmdline
+ * @return negative value if error
+ */
+int proc_get_cmdline(pid_t pid, char *cmdline);
+
+typedef bool (*proc_pid_cb)(pid_t pid, void *user_data);
+
+/**
+ * @desc find pid from /proc
+ */
+void proc_foreach_pid(proc_pid_cb cb, void *user_data);
+
+/**
+ * @desc get status from /proc/{pid}/status
+ * @return negative value if error
+ */
+int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX]);
index 028c030..792988f 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#ifndef __STC_MANAGER_PLUGIN_EXCEPTION_H__
-#define __STC_MANAGER_PLUGIN_EXCEPTION_H__
-
-#define STC_PLUGIN_EXCEPTION_FILEPATH          "/usr/lib/stc-plugin-exception.so"
-
-#include "stc-plugin-iface-exception.h"
-
-int stc_plugin_exception_init(void);
-int stc_plugin_exception_deinit(void);
+#pragma once
 
 int stc_plugin_fill_exception_list(void);
-int stc_plugin_update_exception_list(void);
 int stc_plugin_check_exception_by_cmdline(char *cmdline);
-
-#endif /* __STC_MANAGER_PLUGIN_EXCEPTION_H__ */
index b73e98a..2a97702 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#pragma once
 
-#ifndef __STC_MANAGER_PLUGIN_FIREWALL_H__
-#define __STC_MANAGER_PLUGIN_FIREWALL_H__
-
-#define STC_PLUGIN_FIREWALL_FILEPATH           "/usr/lib/stc-plugin-firewall.so"
-
-#include "stc-plugin-iface-firewall.h"
-
-int stc_plugin_firewall_init(void);
-int stc_plugin_firewall_deinit(void);
-
-int stc_plugin_firewall_lock(void);
-int stc_plugin_firewall_unlock(void);
-int stc_plugin_firewall_get_lock(int *state);
-int stc_plugin_firewall_update(void);
-
-int stc_plugin_firewall_add_chain(char *chain);
-int stc_plugin_firewall_remove_chain(char *chain);
-int stc_plugin_firewall_flush_chain(char *chain);
-int stc_plugin_firewall_get_all_chain(GVariantBuilder *builder);
-int stc_plugin_firewall_set_chain(char *chain, uint target);
-int stc_plugin_firewall_unset_chain(char *chain);
-
-int stc_plugin_firewall_add_rule(GVariant *params);
-int stc_plugin_firewall_remove_rule(GVariant *params);
-int stc_plugin_firewall_update_rule(GVariant *params);
-int stc_plugin_firewall_get_all_rule(GVariantBuilder *builder);
-
-#endif /* __STC_MANAGER_PLUGIN_FIREWALL_H__ */
+int stc_plugin_firewall_update(void);
\ No newline at end of file
index 2d8703b..0439121 100644 (file)
@@ -36,11 +36,4 @@ typedef struct {
        int (*deregister_state_changed_cb) (stc_s *stc);
 } stc_plugin_appstatus_s;
 
-int stc_plugin_popup_send_message(const char *content,
-               const char *type, const char *app_id, const char *iftype, const char *limit);
-
-int stc_plugin_appstatus_register_changed_cb(stc_s *stc,
-               stc_plugin_app_state_changed_cb cb, void *data);
-int stc_plugin_appstatus_deregister_changed_cb(stc_s *stc);
-
 #endif /* __STC_PLUGIN_APPSTATUS_H__ */
index 9bd0b27..1a9063b 100644 (file)
@@ -17,9 +17,6 @@
 #ifndef __STC_PLUGIN_EXCEPTION_H__
 #define __STC_PLUGIN_EXCEPTION_H__
 
-#include <glib.h>
-#include "stc.h"
-
 typedef struct {
        int (*initialize_plugin) (void);
        int (*deinitialize_plugin) (void);
@@ -29,10 +26,4 @@ typedef struct {
        int (*check_exception_by_cmdline) (char *cmdline);
 } stc_plugin_exception_s;
 
-int stc_plugin_exception_initialize(void);
-int stc_plugin_exception_deinitialize(void);
-int stc_plugin_exception_fill_list(void);
-int stc_plugin_exception_update_list(void);
-int stc_plugin_exception_check_by_cmdline(char *cmdline);
-
 #endif /* __STC_PLUGIN_EXCEPTION_H__ */
index b7740e6..38d5037 100644 (file)
 #ifndef __STC_PLUGIN_FIREWALL_H__
 #define __STC_PLUGIN_FIREWALL_H__
 
+#include <sys/types.h>
 #include <glib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <errno.h>
-
-#include "stc.h"
-#include "stc-gdbus.h"
-
-typedef struct {
-       stc_fw_chain_target_e target;
-       long long int priority;
-       GSList *rules;
-} stc_fw_data_s;
 
 typedef struct {
        int (*initialize_plugin) (void);
index 98cc8d5..2b0e65c 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#pragma once
 
-#ifndef __STC_PLUGIN_MONITOR_H__
-#define __STC_PLUGIN_MONITOR_H__
-
+#include <stdint.h>
 #include <glib.h>
 #include "stc.h"
-#include "helper-nl.h"
 #include "db/table-restrictions.h"
 
-/* 1 seconds */
-#define CONTR_TIMER_INTERVAL 1
-
-#ifndef VCONFKEY_STC_BACKGROUND_STATE
-#define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
-#endif
-
-#ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
-#define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
-#endif
-
 #define MAC_ADDRESS_LEN 18
 
 typedef void (*stc_manager_stop_cb)(void);
@@ -59,11 +46,11 @@ typedef struct {
        int (*deinitialize_plugin) (void);
 
        int (*add_application) (uint32_t classid,
-                               const char *app_id,
-                               const char *pkg_id,
-                               const stc_app_value_s value);
+               const char *app_id,
+               const char *pkg_id,
+               const stc_app_value_s value);
        int (*remove_application) (uint32_t classid,
-                               const char *app_id);
+               const char *app_id);
 
        int (*add_restriction) (const table_restrictions_info *info);
        int (*remove_restriction) (const table_restrictions_info *info);
@@ -73,37 +60,13 @@ typedef struct {
        int (*deinit_connection) (stc_s *stc);
 
        int (*add_process) (uint32_t classid,
-                               const char *app_id,
-                               const stc_proc_value_s value);
+               const char *app_id,
+               const stc_proc_value_s value);
        int (*remove_process) (uint32_t classid, pid_t pid);
        int (*move_process) (uint32_t from, uint32_t to);
        int (*update_process_ground) (uint32_t classid,
-                               const char *app_id,
-                               const stc_proc_value_s value);
+               const char *app_id,
+               const stc_proc_value_s value);
 
        int (*check_excn_by_cmdline) (char *cmdline);
 } stc_plugin_monitor_s;
-
-stc_error_e stc_plugin_monitor_initialize(stc_manager_stop_cb stop_cb);
-stc_error_e stc_plugin_monitor_deinitialize(void);
-
-GHashTable *stc_monitor_get_system_apps(void);
-GHashTable *stc_monitor_get_system_rstns(void);
-int stc_monitor_get_contr_sock(void);
-time_t stc_monitor_get_last_month_ts(void);
-void stc_monitor_set_last_month_ts(time_t time);
-time_t stc_monitor_get_last_week_ts(void);
-void stc_monitor_set_last_week_ts(time_t time);
-time_t stc_monitor_get_last_day_ts(void);
-void stc_monitor_set_last_day_ts(time_t time);
-void stc_monitor_set_rstns_updated(gboolean value);
-gboolean stc_monitor_get_rstns_updated(void);
-void stc_monitor_set_apps_updated(gboolean value);
-gboolean stc_monitor_get_apps_updated(void);
-void stc_monitor_set_background_state(gboolean value);
-gboolean stc_monitor_get_background_state(void);
-void stc_monitor_update_by_connection(void *data);
-void stc_monitor_add_by_connection(void *data);
-void stc_monitor_remove_by_connection(void *data);
-
-#endif /* __STC_PLUGIN_MONITOR_H__ */
index 0dc7f4b..0bc527c 100644 (file)
@@ -28,14 +28,4 @@ typedef struct {
                const gchar *app_id, const gchar *pkg_id, stc_app_type_e app_type);
 } stc_plugin_procfs_s;
 
-int stc_plugin_procfs_initialize(void);
-int stc_plugin_procfs_deinitialize(void);
-
-int stc_plugin_procfs_load(void);
-stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
-                                               pid_t pid,
-                                               const gchar *app_id,
-                                               const gchar *pkg_id,
-                                               stc_app_type_e app_type);
-
 #endif /* __STC_PLUGIN_PROCFS_H__ */
index d4dbcad..e5f4b81 100644 (file)
 
 #include <glib.h>
 #include <arpa/inet.h>
-#include "stc.h"
 
-#define TETHERING_SERVICE_INTERFACE   "org.tizen.tethering"
-#define SIGNAL_NAME_DHCP_STATUS       "dhcp_status"
 #define STATION_MAC_STR_LEN           18
 #define STATION_STR_HOSTNAME_LEN      33
 
@@ -42,9 +39,4 @@ typedef struct {
        int (*set_station_classid) (const char *mac, int classid);
 } stc_plugin_tether_s;
 
-int tether_init(void);
-void tether_deinit(void);
-stc_error_e tether_plugin_get_station_ip(const char *mac, char *ip);
-stc_error_e tether_plugin_get_station_by_classid(const int classid, char *mac);
-stc_error_e tether_plugin_set_station_classid(const char *mac, int classid);
 #endif /* __STC_PLUGIN_TETHER_H__ */
index cb9257e..cf01989 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#pragma once
 
-#ifndef __STC_MANAGER_PLUGIN_MONITOR_H__
-#define __STC_MANAGER_PLUGIN_MONITOR_H__
-
-#define STC_PLUGIN_MONITOR_FILEPATH            "/usr/lib/stc-plugin-monitor.so"
-
-#include "db/table-restrictions.h"
+#include <stdint.h>
 #include "stc-plugin-iface-monitor.h"
 
-int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb);
-int stc_plugin_monitor_deinit(void);
-
-int stc_plugin_monitor_add_app(uint32_t classid,
-                               const char *app_id,
-                               const char *pkg_id,
-                               const stc_app_value_s value);
-int stc_plugin_monitor_remove_app(uint32_t classid,
-                               const char *app_id);
+int stc_plugin_monitor_add_app(uint32_t classid, const char *app_id,
+               const char *pkg_id, const stc_app_value_s value);
+int stc_plugin_monitor_remove_app(uint32_t classid, const char *app_id);
 int stc_plugin_monitor_lookup_app(uint32_t classid);
-int stc_plugin_monitor_add_rstn(table_restrictions_info *info);
-int stc_plugin_monitor_remove_rstn(table_restrictions_info *info);
-int stc_plugin_monitor_init_connection(stc_s *stc);
-int stc_plugin_monitor_deinit_connection(stc_s *stc);
-int stc_plugin_monitor_add_proc(uint32_t classid,
-                       const char *app_id, const stc_proc_value_s value);
+int stc_plugin_monitor_add_proc(uint32_t classid, const char *app_id,
+       const stc_proc_value_s value);
 int stc_plugin_monitor_remove_proc(uint32_t classid, pid_t pid);
 int stc_plugin_monitor_move_proc(uint32_t from, uint32_t to);
-int stc_plugin_monitor_update_proc_ground(uint32_t classid,
-                       const char *app_id, const stc_proc_value_s value);
-
-#endif /* __STC_MANAGER_PLUGIN_MONITOR_H__ */
+int stc_plugin_monitor_update_proc_ground(uint32_t classid, const char *app_id,
+       const stc_proc_value_s value);
index 14bfb8c..f43d6a2 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#pragma once
 
-#ifndef __STC_MANAGER_PLUGIN_TETHER_H__
-#define __STC_MANAGER_PLUGIN_TETHER_H__
-
-#define STC_PLUGIN_TETHER_FILEPATH             "/usr/lib/stc-plugin-tether.so"
-
-#include "stc-plugin-iface-tether.h"
-
-int stc_plugin_tether_init(void);
-int stc_plugin_tether_deinit(void);
-stc_error_e stc_plugin_tether_load(void);
 int stc_plugin_tether_get_station_ip(const char *mac, char **ipaddr);
-int stc_plugin_tether_get_station_by_classid(const int classid, char **mac);
 int stc_plugin_tether_set_station_classid(const char *mac, int classid);
-#endif /* __STC_MANAGER_PLUGIN_TETHER_H__ */
+int stc_plugin_tether_get_station_by_classid(const int classid, char **mac);
\ No newline at end of file
index 63de665..f113dc1 100644 (file)
 #ifndef __STC_RESTRICTION_H__
 #define __STC_RESTRICTION_H__
 
-#include <glib.h>
 #include "stc.h"
-#include "stc-gdbus.h"
-#include "db/table-restrictions.h"
 #include "stc-transmission.h"
 
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
 typedef struct {
        stc_app_state_e rs_type;
        stc_iface_type_e iftype;
@@ -38,43 +32,4 @@ typedef struct {
        char *subscriber_id;
 } stc_restriction_s;
 
-/*****************************************************************************
- * Functions Declaration
- *****************************************************************************/
-
-gboolean handle_restriction_set(StcRestriction *object,
-                               GDBusMethodInvocation *invocation,
-                               GVariant *parameters,
-                               void *user_data);
-
-gboolean handle_restriction_unset(StcRestriction *object,
-                                  GDBusMethodInvocation *invocation,
-                                  GVariant *parameters,
-                                  void *user_data);
-
-gboolean handle_restriction_set_list(StcRestriction *object,
-                               GDBusMethodInvocation *invocation,
-                               GVariant *parameters,
-                               void *user_data);
-
-gboolean handle_restriction_unset_list(StcRestriction *object,
-                                  GDBusMethodInvocation *invocation,
-                                  GVariant *parameters,
-                                  void *user_data);
-
-gboolean handle_restriction_get(StcRestriction *object,
-                               GDBusMethodInvocation *invocation,
-                               const gchar *app_id,
-                               void *user_data);
-
-gboolean handle_restriction_get_all(StcRestriction *object,
-                                   GDBusMethodInvocation *invocation,
-                                   void *user_data);
-
-gboolean handle_restriction_get_type(StcRestriction *object,
-                                     GDBusMethodInvocation *invocation,
-                                     const gchar *app_id,
-                                     int iftype,
-                                     void *user_data);
-
 #endif /* __STC_RESTRICTION_H__ */
diff --git a/include/stc-statistics.h b/include/stc-statistics.h
deleted file mode 100644 (file)
index d619faa..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __STC_STATISTICS_H__
-#define __STC_STATISTICS_H__
-
-#include <glib.h>
-#include "stc.h"
-#include "stc-gdbus.h"
-
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
-
-/*****************************************************************************
- * Functions Declaration
- *****************************************************************************/
-
-gboolean handle_statistics_init(StcStatistics *object,
-                              GDBusMethodInvocation *invocation);
-
-gboolean handle_statistics_get_all(StcStatistics *object,
-                                  GDBusMethodInvocation *invocation,
-                                  GVariant *select_rule,
-                                  void *user_data);
-
-gboolean handle_statistics_get(StcStatistics *object,
-                              GDBusMethodInvocation *invocation,
-                              const gchar *app_id,
-                              GVariant *select_rule,
-                              void *user_data);
-
-gboolean handle_statistics_reset(StcStatistics *object,
-                                GDBusMethodInvocation *invocation,
-                                GVariant *reset_rule,
-                                void *user_data);
-
-#endif /* __STC_STATISTICS_H__ */
index aaadafc..7d7ea4a 100644 (file)
@@ -13,9 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#ifndef __STC_HELPER_INOTIFY_H__
-#define __STC_HELPER_INOTIFY_H__
+#pragma once
 
 #include <sys/inotify.h>
 
@@ -27,5 +25,3 @@ void inotify_deregister(const char *path);
 
 int inotify_initialize(void);
 void inotify_deinitialize(void);
-
-#endif  /*__STC_HELPER_INOTIFY_H__*/
index 3dd9b38..207c827 100644 (file)
@@ -24,9 +24,7 @@
 #include <stdbool.h>  /* bool */
 #include <stdint.h> /* uint32_t, uint63_t */
 #include <string.h>
-#include <sqlite3.h>  /* database handling */
 #include <time.h>  /* time function */
-#include <vconf/vconf.h>
 #include <unistd.h>
 
 #ifdef USE_DLOG
index 7d03d58..842354f 100644 (file)
@@ -13,9 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#ifndef __STC_MANAGER_H__
-#define __STC_MANAGER_H__
+#pragma once
 
 #include "stc-error.h"
 #include "stc-util.h"
@@ -256,8 +254,3 @@ typedef struct {
 } stc_s;
 
 stc_s *stc_get_manager(void);
-void stc_stop_manager(void);
-int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
-void stc_set_keep_alive(gboolean keep_alive);
-
-#endif /* __STC_MANAGER__ */
index b63ef69..5599a9b 100644 (file)
@@ -5,4 +5,3 @@ ADD_DEFINITIONS("-DDATABASE_BACKUP_PATH=\"${DATABASE_BACKUP_PATH}\"")
 
 ADD_LIBRARY(${DB_OBJ} OBJECT ${DB_SRCS})
 SET_TARGET_PROPERTIES(${DB_OBJ} PROPERTIES POSITION_INDEPENDENT_CODE ON)
-ADD_DEPENDENCIES(${DB_OBJ} GENERATED_DBUS_CODE)
index 43a4297..e319b94 100644 (file)
@@ -13,9 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 #include <errno.h>
 #include <sys/stat.h>
+#include <vconf.h>
 
 #include "stc-db.h"
 #include "db/table-statistics.h"
index 2b2daae..10997ef 100644 (file)
 #ifndef __STC_DB_INTERNAL_H__
 #define __STC_DB_INTERNAL_H__
 
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
-
 #define DB_ACTION(command) do { \
        if ((command) != SQLITE_OK) { \
                error_code = STC_ERROR_DB_FAILED; \
@@ -39,17 +31,12 @@ extern "C" {
        } \
 } while (0)
 
-/*****************************************************************************
- * Enumerations and Structures
- *****************************************************************************/
-
-void stc_db_finalize_statistics(void);
+/**
+ * @desc This function init db oversize erase timer.
+ */
+stc_error_e stc_init_db_guard(void);
 
 stc_error_e stc_db_initialize_once(void);
 sqlite3 *stc_db_get_database(void);
 
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
 #endif /* _STC_DB_INTERNAL_H_ */
index 5cd7a66..7793fb1 100644 (file)
 #define _GNU_SOURCE
 #include "helper-cgroup.h"
 
+#include <errno.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include "helper-file.h"
+
 #define RELEASE_AGENT  "release_agent"
 #define NOTIFY_ON_RELEASE  "notify_on_release"
 
 #define CGROUP_FILE_NAME "cgroup.procs"
-#define CLASSID_FILE_NAME "net_cls.classid"
 
 #define MAX_PATH_LENGTH 512
 
index 94030a8..ad0fb05 100644 (file)
 #ifndef __STC_HELPER_CGROUP_H__
 #define __STC_HELPER_CGROUP_H__
 
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <stdlib.h>
-
 #include "stc.h"
-#include "helper-file.h"
+#include "stc-helper-cgroup.h"
 
 #define DEFAULT_CGROUP                  "/sys/fs/cgroup"
 #define CGROUP_NETWORK                  DEFAULT_CGROUP "/net_cls"
@@ -112,12 +107,6 @@ int cgroup_set_release_agent(const char *cgroup_subsys,
                             const char *release_agent);
 
 /**
- * @desc get PIDs of processes in a certain cgroup, an allocated array must be provided
- * @return 0 if pids were read and array filled
- */
-int cgroup_get_pids(const char *name, GArray **pids);
-
-/**
  * @desc initializes cgroups.
  */
 void cgroup_init(void);
index d93741c..b78e0ff 100644 (file)
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 #define _GNU_SOURCE
+#include <assert.h>
+#include <errno.h>
+#include "stc.h"
 #include "helper-file.h"
 
 #define BUF_MAX                (BUFSIZ)
index 5a329dc..71838d0 100644 (file)
 #ifndef __STC_HELPER_FILE_H__
 #define __STC_HELPER_FILE_H__
 
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-
-#include "stc.h"
+#include <stdint.h>
 
 /**
  * @desc write string to the file
@@ -34,16 +28,6 @@ int fwrite_str(const char *path, const char *str);
 
 int fwrite_uint(const char *path, const uint32_t number);
 
-int fwrite_ulong(const char *path, const unsigned long number);
-
-int fread_str(const char *path, char **str);
-
 int fread_uint(const char *path, uint32_t *number);
 
-int fread_ulong(const char *path, unsigned long *number);
-
-int fwrite_array(const char *path, const void *array,
-                const size_t size_of_elem,
-                const size_t numb_of_elem);
-
 #endif  /*__STC_HELPER_FILE_H__*/
index 1c6b3e0..56b87c6 100644 (file)
 #ifndef __STC_HELPER_FIREWALL_H__
 #define __STC_HELPER_FIREWALL_H__
 
-#include <arpa/inet.h>
-
 #include "stc.h"
+#include "stc-firewall.h"
 
 #define FIREWALL_CHAIN_TARGET_IN     "INPUT"
 #define FIREWALL_CHAIN_TARGET_OUT    "OUTPUT"
 
-#define FIREWALL_RULE_TARGET_ACCEPT  "ACCEPT"
-#define FIREWALL_RULE_TARGET_DROP    "DROP"
-#define FIREWALL_RULE_TARGET_LOG     "LOG"
-#define FIREWALL_RULE_TARGET_NFLOG   "NFLOG"
-
-#define RULE_CHAIN      "chain"
-#define RULE_DIRECTION  "direction"
-#define RULE_IFNAME     "ifname"
-#define RULE_PROTOCOL   "protocol"
-#define RULE_TARGET     "target"
-#define RULE_TARGETTYPE "target_type"
-
-#define RULE_FAMILY     "family"
-#define RULE_SIPTYPE    "s_ip_type"
-#define RULE_SIP1       "s_ip1"
-#define RULE_SIP2       "s_ip2"
-#define RULE_DIPTYPE    "d_ip_type"
-#define RULE_DIP1       "d_ip1"
-#define RULE_DIP2       "d_ip2"
-#define RULE_SPORTTYPE  "s_port_type"
-#define RULE_SPORT1     "s_port1"
-#define RULE_SPORT2     "s_port2"
-#define RULE_DPORTTYPE  "d_port_type"
-#define RULE_DPORT1     "d_port1"
-#define RULE_DPORT2     "d_port2"
-
-#define RULE_LOG_LEVEL       "log_level"
-#define RULE_LOG_PREFIX      "log_prefix"
-#define RULE_NFLOG_GROUP     "nflog_group"
-#define RULE_NFLOG_PREFIX    "nflog_prefix"
-#define RULE_NFLOG_RANGE     "nflog_range"
-#define RULE_NFLOG_THRESHOLD "nflog_threshold"
-
-typedef enum {
-       FIREWALL_UNKONWN,
-       FIREWALL_UNLOCKED,
-       FIREWALL_LOCKED
-} firewall_lock_e;
-
-typedef union {
-       struct in_addr Ipv4;
-       struct in6_addr Ipv6;
-} ip_addr_u;
-
-typedef struct {
-       char *chain;
-       stc_fw_chain_target_e target;
-       guint priority;
-} firewall_chain_s;
-
-typedef struct {
-       guint key;
-       char *chain;
-       stc_fw_direction_e direction;
-       stc_fw_ip_type_e s_ip_type;
-       stc_fw_ip_type_e d_ip_type;
-       stc_fw_port_type_e s_port_type;
-       stc_fw_port_type_e d_port_type;
-       stc_fw_protocol_type_e protocol;
-       stc_fw_family_type_e family;
-       ip_addr_u s_ip1;
-       ip_addr_u s_ip2;
-       ip_addr_u d_ip1;
-       ip_addr_u d_ip2;
-       guint s_port1;
-       guint s_port2;
-       guint d_port1;
-       guint d_port2;
-       char *ifname;
-       stc_fw_rule_target_e target;
-       char *target_str;
-       guchar log_level;
-       char *log_prefix;
-       guint nflog_group;
-       char *nflog_prefix;
-       guint nflog_range;
-       guint nflog_threshold;
-       char *identifier;
-} firewall_rule_s;
-
-stc_error_e firewall_chain_add(firewall_chain_s *chain);
-stc_error_e firewall_chain_remove(firewall_chain_s *chain);
 stc_error_e firewall_chain_flush(firewall_chain_s *chain);
-stc_error_e firewall_chain_set(firewall_chain_s *chain);
-stc_error_e firewall_chain_unset(firewall_chain_s *chain);
 
-stc_error_e firewall_rule_append(firewall_rule_s *rule);
 stc_error_e firewall_rule_insert(firewall_rule_s *rule);
 stc_error_e firewall_rule_remove(firewall_rule_s *rule);
 
index feaf9b3..e68049d 100644 (file)
@@ -13,9 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "helper-iptables.h"
 
 #include "stc-gdbus.h"
-#include "helper-iptables.h"
 
 #define STC_IPTABLES_DBUS_SERVICE                    "net.stc.iptables"
 #define STC_IPTABLES_DBUS_RULE_INTERFACE             STC_IPTABLES_DBUS_SERVICE ".rule"
index b4bdb59..374b12a 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <arpa/inet.h>
 #include "stc.h"
+#include "stc-helper-iptables.h"
 
 #define STC_IN_CHAIN      "STC_IN"
 #define STC_OUT_CHAIN     "STC_OUT"
@@ -77,8 +78,5 @@ stc_error_e iptables_add(iptables_rule_s *rule, iptables_ip_type_e iptype);
 stc_error_e iptables_remove(iptables_rule_s *rule, iptables_ip_type_e iptype);
 stc_error_e iptables_add_list(GSList *iptables_list, iptables_ip_type_e iptype);
 stc_error_e iptables_remove_list(GSList *iptables_list, iptables_ip_type_e iptype);
-stc_error_e iptables_flush_chains(void);
-stc_error_e iptables_init(void);
-stc_error_e iptables_deinit(void);
 
 #endif /*__STC_HELPER_IPTABLES_H__*/
index 6ae6bac..294bca0 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/stat.h>
 
 #include "helper-cgroup.h"
 #include "stc-counter.h"
index 58d3cfd..ba04a03 100644 (file)
 
 #include <sys/types.h>
 #include <glib.h>
-#include <stdbool.h>
 
 #include "stc.h"
+#include "stc-helper-net-cls.h"
 
-#define PATH_TO_NET_CGROUP_DIR CGROUP_NETWORK
-
+//#define PATH_TO_NET_CGROUP_DIR CGROUP_NETWORK
+/*
 enum {
        ERROR_CANT_CREATE_NL_SOCKET = 1,
        ERROR_UPDATE_PID_LIST = 2,
        ERROR_UPDATE_CLASSIDS_LIST = 3,
 };
-
-typedef GArray int_array;
-
-stc_error_e init_current_classid(void);
-
-/**
- * @desc take classid from net_cls cgroup by appid
- *     This function converts appid to pkgname.
- * @param pkg_name - name of the cgroup
- * @param create - in case of true - create cgroup if it's not exists
- * @return classid
- */
-uint32_t get_classid_by_app_id(const char *app_id, int create);
-
+*/
 typedef gboolean(*check_classid_used_cb)(guint32 classid);
 
-stc_error_e place_pids_to_net_cgroup(const int pid, const char *pkg_name);
-
 #endif /*__STC_HELPER_NET_CLS_H__*/
index 109e385..d42cef5 100644 (file)
@@ -27,6 +27,7 @@
 #include "stc-counter.h"
 #include "helper-nfacct-rule.h"
 #include "helper-iptables.h"
+#include "helper-nl.h"
 
 #include "configure_stub.h"
 
index 5e09471..53b5f92 100644 (file)
 
 #include "stc-db.h"
 
-#include <stdbool.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "helper-nl.h"
-
-#define NFACCT_NAME_MAX 64
-
-typedef enum {
-       NFACCT_COUNTER_UNKNOWN,
-       NFACCT_COUNTER_IN = (1 << 1),
-       NFACCT_COUNTER_OUT = (1 << 2),
-       NFACCT_COUNTER_FORWARD = (1 << 3),
-       NFACCT_COUNTER_LAST_ELEM
-} nfacct_rule_direction;
-
-typedef enum {
-       NFACCT_ACTION_UNKNOWN,
-       NFACCT_ACTION_APPEND,
-       NFACCT_ACTION_DELETE,
-       NFACCT_ACTION_INSERT,
-       NFACCT_ACTION_LAST_ELEM,
-} nfacct_rule_action;
-
-typedef enum {
-       NFACCT_JUMP_UNKNOWN,
-       NFACCT_JUMP_ACCEPT,
-       NFACCT_JUMP_REJECT,
-       NFACCT_JUMP_LAST_ELEM,
-} nfacct_rule_jump;
-
-typedef enum {
-       NFACCT_COUNTER,
-       NFACCT_WARN,
-       NFACCT_BLOCK,
-       NFACCT_ALLOW,
-       NFACCT_TETH_COUNTER,
-       NFACCT_TETH_WARN,
-       NFACCT_TETH_BLOCK,
-       NFACCT_TETH_ALLOW,
-       NFACCT_RULE_LAST_ELEM,
-} nfacct_rule_intend;
-
-typedef enum {
-       NFACCT_TYPE_UNKNOWN,
-       NFACCT_TYPE_IPV4,
-       NFACCT_TYPE_IPV6,
-       NFACCT_TYPE_IPV4_IPV6,
-       NFACCT_TYPE_LAST_ELEM
-} nfacct_rule_iptype;
-
-typedef enum {
-       NFACCT_IPRANGE_TYPE_NONE,
-       NFACCT_IPRANGE_TYPE_SINGLE,
-       NFACCT_IPRANGE_TYPE_MASK,
-       NFACCT_IPRANGE_TYPE_RANGE,
-} nfacct_rule_iprange_type;
+#include "stc-helper-nfacct-rule.h"
 
 enum nfnl_acct_flags {
        NFACCT_F_QUOTA_PKTS     = (1 << 0),
@@ -83,61 +27,6 @@ enum nfnl_acct_flags {
        NFACCT_F_OVERQUOTA      = (1 << 2), /* can't be set from userspace */
 };
 
-/**
- * it's better to have
- * base nfacct_rule with following fields:
- *  name, ifname, pid, classid, iftype, intend, carg, iptables_rule
- *
- *  and inherited nfacct_rule_counter and nfacct_rule_restriction
- *  with additional field:
- *     quota, quota_id, roaming, rstn_state
- *
- * But ANSI C doesn't support inheritance.
- */
-struct nfacct_rule {
-       char name[NFACCT_NAME_MAX];
-       char ifname[MAX_IFACE_LENGTH];
-
-       pid_t pid;
-       uint32_t classid;
-       stc_iface_type_e iftype;
-       nfacct_rule_action action;
-       nfacct_rule_direction iotype;
-       nfacct_rule_intend intend;
-       nfacct_rule_jump jump; /* in most cases jump is evalutation based on intend, but not always */
-       stc_app_state_e app_state;
-       stc_rstn_state_e rstn_state;
-       nfacct_rule_iptype iptype;
-       nfacct_rule_iprange_type src_iprange_type;
-       nfacct_rule_iprange_type dst_iprange_type;
-       char *src_ip1;
-       char *src_ip2;
-       char *dst_ip1;
-       char *dst_ip2;
-
-       struct counter_arg *carg;
-       stc_error_e(*iptables_rule)(struct nfacct_rule *counter);
-       long long int quota;
-       int quota_id;
-       stc_roaming_type_e roaming;
-
-       long long int send_limit;
-       long long int rcv_limit;
-};
-
-typedef struct nfacct_rule nfacct_rule_s;
-
-struct counter_arg;
-
 void generate_counter_name(nfacct_rule_s *counter);
-bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *counter);
-
-stc_error_e nfacct_send_get_all(struct counter_arg *carg);
-stc_error_e produce_net_rule(nfacct_rule_s *rule);
-stc_error_e produce_net_list(GSList *rule_list,
-               nfacct_rule_iptype iptype, nfacct_rule_action action);
-
-netlink_serialization_command *
-netlink_create_command(struct netlink_serialization_params *params);
 
 #endif /* __STC_NFACCT_RULE_H__ */
index a34a589..4ec55b5 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/rtnetlink.h>
 
 #include "stc.h"
+#include "stc-helper-nl.h"
 
 #define NLA_BUF_MAX 65560      /*(65 * 1024) - used in tc_common,
                                  we'll do the same */
@@ -53,8 +54,6 @@ void put_attr(rt_param *arg, int type, const void *data, int data_len);
 #define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
 #define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
 
-#define NETLINK_BUF_SIZE 16536
-
 enum nfnl_acct_msg_types {
        NFNL_MSG_ACCT_NEW,
        NFNL_MSG_ACCT_GET,
@@ -63,18 +62,6 @@ enum nfnl_acct_msg_types {
        NFNL_MSG_ACCT_MAX
 };
 
-enum nfnl_acct_type {
-       NFACCT_UNSPEC,
-       NFACCT_NAME,
-       NFACCT_PKTS,
-       NFACCT_BYTES,
-       NFACCT_USE,
-       NFACCT_FLAGS,
-       NFACCT_QUOTA,
-       NFACCT_FILTER,
-       __NFACCT_MAX
-};
-
 enum nfnl_attr_filter_type {
        NFACCT_FILTER_ATTR_UNSPEC,
        NFACCT_FILTER_ATTR_MASK,
@@ -84,30 +71,6 @@ enum nfnl_attr_filter_type {
 
 #define NFACCT_MAX (__NFACCT_MAX - 1)
 
-struct genl {
-       struct nlmsghdr n;
-       struct genlmsghdr g;
-       char buf[NETLINK_BUF_SIZE];
-};
-
-struct netlink_serialization_params {
-       int direction;
-       struct genl *ans;
-       struct counter_arg *carg;
-       int (*eval_attr)(struct rtattr *attr_list[__NFACCT_MAX],
-                        void *user_data);
-       int (*post_eval_attr)(void *user_data);
-};
-
-typedef struct {
-       void (*deserialize_answer)(struct netlink_serialization_params *params);
-       void (*finalize)(struct netlink_serialization_params *params);
-       struct netlink_serialization_params params;
-} netlink_serialization_command;
-
-int create_netlink(int protocol, uint32_t groups);
-int read_netlink(int sock, void *buf, size_t len);
-
 void fill_attribute_list(struct rtattr **atb, const int max_len,
                         struct rtattr *rt_na, int rt_len);
 
index 26839c6..cae86c9 100644 (file)
 #ifndef __HELPER_PROCFS_H__
 #define __HELPER_PROCFS_H__
 
-#include <stdio.h>
-
-#define PROC_BUF_MAX 64
-
-typedef bool (*proc_pid_cb)(pid_t pid, void *user_data);
-
-/**
- * @desc get command line from /proc/{pid}/cmdline
- * @return negative value if error
- */
-int proc_get_cmdline(pid_t pid, char *cmdline);
+#include "stc-util.h"
+#include "stc-helper-procfs.h"
 
 /**
  * @desc find pid with /proc/{pid}/cmdline
@@ -38,11 +29,6 @@ int proc_get_cmdline(pid_t pid, char *cmdline);
 pid_t find_pid_from_cmdline(char *cmdline);
 
 /**
- * @desc find pid from /proc
- */
-void proc_foreach_pid(proc_pid_cb cb, void *user_data);
-
-/**
  * @desc get smack subject label from /proc/{pid}/attr/current
  * this label can indicate package name about child processes
  * @return negative value if error or pid doesn't exist
@@ -61,10 +47,4 @@ int proc_get_raw_cmdline(pid_t pid, char *buf, int len);
  */
 int proc_get_exepath(pid_t pid, char *buf, int len);
 
-/**
- * @desc get status from /proc/{pid}/status
- * @return negative value if error
- */
-int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX]);
-
 #endif /*__HELPER_PROCFS_H__*/
index a29e17c..db28450 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-firewall.h"
 
 #include "stc-db.h"
 #include "stc-firewall.h"
 #include "db/table-firewall.h"
-#include "helper-firewall.h"
-#include "stc-gdbus.h"
-#include "stc-plugin-firewall.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-firewall.h"
 
 #define FIREWALL_DBUS_ERROR_NAME "net.stc.firewall.Error.Failed"
 
diff --git a/manager/stcmgr-firewall.h b/manager/stcmgr-firewall.h
new file mode 100644 (file)
index 0000000..5293c67
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <glib.h>
+#include "stc-generated-dbus.h"
+
+gboolean handle_firewall_lock(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       void *user_data);
+
+gboolean handle_firewall_unlock(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       void *user_data);
+
+gboolean handle_firewall_get_lock(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       void *user_data);
+
+gboolean handle_firewall_add_chain(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       gchar *chain,
+       void *user_data);
+
+gboolean handle_firewall_remove_chain(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       gchar *chain,
+       void *user_data);
+
+gboolean handle_firewall_flush_chain(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       gchar *chain,
+       void *user_data);
+
+gboolean handle_firewall_get_all_chain(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       void *user_data);
+
+gboolean handle_firewall_set_chain(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       gchar *chain,
+       unsigned int target,
+       void *user_data);
+
+gboolean handle_firewall_unset_chain(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       gchar *chain,
+       void *user_data);
+
+gboolean handle_firewall_add_rule(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_firewall_remove_rule(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_firewall_update_rule(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_firewall_get_all_rule(StcFirewall *object,
+       GDBusMethodInvocation *invocation,
+       void *user_data);
index c564073..66d7cdc 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-gdbus.h"
 
 #include "stc.h"
-#include "stc-gdbus.h"
-#include "helper-iptables.h"
-#include "stc-statistics.h"
-#include "stc-restriction.h"
-#include "stc-firewall.h"
-#include "stc-pcap.h"
-#include "stc-plugin-appstatus.h"
-#include "stc-plugin-procfs.h"
-#include "stc-plugin-monitor.h"
-#include "stc-plugin-firewall.h"
+#include "stc-util.h"
+#include "stc-helper-iptables.h"
+#include "stcmgr.h"
+#include "stcmgr-statistics.h"
+#include "stcmgr-restriction.h"
+#include "stcmgr-firewall.h"
+#include "stcmgr-pcap.h"
+#include "stcmgr-plugin-appstatus.h"
+#include "stcmgr-plugin-procfs.h"
+#include "stcmgr-plugin-monitor.h"
+#include "stcmgr-plugin-firewall.h"
 
 #define MANAGER_DBUS_ERROR_NAME "net.stc.manager.Error.Failed"
 
@@ -286,6 +288,97 @@ static gboolean __stc_manager_gdbus_pcap_init(stc_s *stc)
        return ret;
 }
 
+static gboolean handle_manager_stop(StcManager *object,
+       GDBusMethodInvocation *invocation)
+{
+       __STC_LOG_FUNC_ENTER__;
+       GVariant *return_parameters = NULL;
+
+       stc_set_keep_alive(TRUE);
+
+       STC_LOGI("stc manager stop");
+
+       return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+       DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+       STC_DBUS_REPLY(invocation, return_parameters);
+
+       stc_stop_manager();
+
+       __STC_LOG_FUNC_EXIT__;
+       return TRUE;
+}
+
+static 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,};
+
+       stc_set_keep_alive(TRUE);
+
+       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;
+}
+
+static gboolean handle_manager_commit_ip6tables(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,};
+
+       stc_set_keep_alive(TRUE);
+
+       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_IP6TABLES, 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;
+}
+
 static gboolean __stc_manager_gdbus_manager_init(stc_s *stc)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -588,94 +681,3 @@ API gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
 
        return rv;
 }
-
-gboolean handle_manager_stop(StcManager *object,
-                              GDBusMethodInvocation *invocation)
-{
-       __STC_LOG_FUNC_ENTER__;
-       GVariant *return_parameters = NULL;
-
-       stc_set_keep_alive(TRUE);
-
-       STC_LOGI("stc manager stop");
-
-       return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
-
-       DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
-       STC_DBUS_REPLY(invocation, return_parameters);
-
-       stc_stop_manager();
-
-       __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, };
-
-       stc_set_keep_alive(TRUE);
-
-       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;
-}
-
-gboolean handle_manager_commit_ip6tables(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, };
-
-       stc_set_keep_alive(TRUE);
-
-       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_IP6TABLES, 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;
-}
diff --git a/manager/stcmgr-gdbus.h b/manager/stcmgr-gdbus.h
new file mode 100644 (file)
index 0000000..40d7e6d
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_MANAGER_GDBUS_H__
+#define __STC_MANAGER_GDBUS_H__
+
+#include "stc-gdbus.h"
+
+#define STC_DBUS_REPLY_ERROR_NONE(invocation) \
+       g_dbus_method_invocation_return_value((invocation), \
+                                             g_variant_new("(i)", \
+                                                           STC_ERROR_NONE));
+
+#define STC_DBUS_REPLY(invocation, parameters) \
+       g_dbus_method_invocation_return_value((invocation), parameters);
+
+void stc_manager_gdbus_init(gpointer stc_manager);
+void stc_manager_gdbus_deinit(gpointer stc_manager);
+
+#endif /* __STC_MANAGER_GDBUS_H__ */
index 44de950..374f376 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-pcap.h"
 
 #include "stc-db.h"
-#include "stc-pcap.h"
-#include "stc-plugin-pcap.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-pcap.h"
 
 #define PCAP_DBUS_ERROR_NAME "net.stc.pcap.Error.Failed"
 
similarity index 97%
rename from include/stc-pcap.h
rename to manager/stcmgr-pcap.h
index c250181..40a9be9 100644 (file)
@@ -18,8 +18,7 @@
 #define __STC_PCAP_H__
 
 #include <glib.h>
-#include "stc.h"
-#include "stc-gdbus.h"
+#include "stc-generated-dbus.h"
 
 /*****************************************************************************
  * Macros and Typedefs
index 48ac87a..f73d8ea 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-appstatus.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-appstatus.h"
 
 static gboolean stc_plugin_enabled = FALSE;
 static void *handle_plugin;
index 3f8e3e1..bd52050 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-exception.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-exception.h"
 
 static gboolean stc_plugin_enabled = FALSE;
 static void *handle_plugin;
 static stc_plugin_exception_s *stc_plugin;
 
 //LCOV_EXCL_START
-API int stc_plugin_exception_init(void)
+int stc_plugin_exception_init(void)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -50,7 +49,7 @@ API int stc_plugin_exception_init(void)
        return STC_ERROR_NONE;
 }
 
-API int stc_plugin_exception_deinit(void)
+int stc_plugin_exception_deinit(void)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -84,7 +83,7 @@ API int stc_plugin_fill_exception_list(void)
        return stc_plugin->fill_exception_list();
 }
 
-API int stc_plugin_update_exception_list(void)
+int stc_plugin_update_exception_list(void)
 {
        if (!stc_plugin_enabled) {
                if (STC_DEBUG_LOG)
diff --git a/manager/stcmgr-plugin-exception.h b/manager/stcmgr-plugin-exception.h
new file mode 100644 (file)
index 0000000..fa1e45f
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_MANAGER_PLUGIN_EXCEPTION_H__
+#define __STC_MANAGER_PLUGIN_EXCEPTION_H__
+
+#include "stc-plugin-exception.h"
+
+#define STC_PLUGIN_EXCEPTION_FILEPATH          "/usr/lib/stc-plugin-exception.so"
+
+#include "stc-plugin-iface-exception.h"
+
+int stc_plugin_exception_init(void);
+int stc_plugin_exception_deinit(void);
+
+int stc_plugin_update_exception_list(void);
+
+#endif /* __STC_MANAGER_PLUGIN_EXCEPTION_H__ */
index 026529e..6e612dc 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-firewall.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-firewall.h"
 
 static gboolean stc_plugin_enabled = FALSE;
 static void *handle_plugin;
diff --git a/manager/stcmgr-plugin-firewall.h b/manager/stcmgr-plugin-firewall.h
new file mode 100644 (file)
index 0000000..00b53bb
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_MANAGER_PLUGIN_FIREWALL_H__
+#define __STC_MANAGER_PLUGIN_FIREWALL_H__
+
+#include "stc-plugin-firewall.h"
+#include "stc-plugin-iface-firewall.h"
+
+#define STC_PLUGIN_FIREWALL_FILEPATH           "/usr/lib/stc-plugin-firewall.so"
+
+int stc_plugin_firewall_init(void);
+int stc_plugin_firewall_deinit(void);
+
+int stc_plugin_firewall_lock(void);
+int stc_plugin_firewall_unlock(void);
+int stc_plugin_firewall_get_lock(int *state);
+int stc_plugin_firewall_update(void);
+
+int stc_plugin_firewall_add_chain(char *chain);
+int stc_plugin_firewall_remove_chain(char *chain);
+int stc_plugin_firewall_flush_chain(char *chain);
+int stc_plugin_firewall_get_all_chain(GVariantBuilder *builder);
+int stc_plugin_firewall_set_chain(char *chain, uint target);
+int stc_plugin_firewall_unset_chain(char *chain);
+
+int stc_plugin_firewall_add_rule(GVariant *params);
+int stc_plugin_firewall_remove_rule(GVariant *params);
+int stc_plugin_firewall_update_rule(GVariant *params);
+int stc_plugin_firewall_get_all_rule(GVariantBuilder *builder);
+
+#endif /* __STC_MANAGER_PLUGIN_FIREWALL_H__ */
index 0ca5f48..2326049 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-monitor.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-monitor.h"
 
 static gboolean stc_plugin_enabled = FALSE;
 static void *handle_plugin;
 static stc_plugin_monitor_s *stc_plugin;
 
 //LCOV_EXCL_START
-API int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb)
+int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -50,7 +49,7 @@ API int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb)
        return STC_ERROR_NONE;
 }
 
-API int stc_plugin_monitor_deinit(void)
+int stc_plugin_monitor_deinit(void)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -120,7 +119,7 @@ API int stc_plugin_monitor_lookup_app(uint32_t classid)
        return stc_plugin->lookup_application(classid);
 }
 
-API int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
+int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
 {
        if (!stc_plugin_enabled) {
                if (STC_DEBUG_LOG)
@@ -137,7 +136,7 @@ API int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
        return stc_plugin->add_restriction(info);
 }
 
-API int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
+int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
 {
        if (!stc_plugin_enabled) {
                if (STC_DEBUG_LOG)
@@ -154,7 +153,7 @@ API int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
        return stc_plugin->remove_restriction(info);
 }
 
-API int stc_plugin_monitor_init_connection(stc_s *stc)
+int stc_plugin_monitor_init_connection(stc_s *stc)
 {
        if (!stc_plugin_enabled) {
                if (STC_DEBUG_LOG)
@@ -171,7 +170,7 @@ API int stc_plugin_monitor_init_connection(stc_s *stc)
        return stc_plugin->init_connection(stc);
 }
 
-API int stc_plugin_monitor_deinit_connection(stc_s *stc)
+int stc_plugin_monitor_deinit_connection(stc_s *stc)
 {
        if (!stc_plugin_enabled) {
                if (STC_DEBUG_LOG)
diff --git a/manager/stcmgr-plugin-monitor.h b/manager/stcmgr-plugin-monitor.h
new file mode 100644 (file)
index 0000000..758ffa9
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_MANAGER_PLUGIN_MONITOR_H__
+#define __STC_MANAGER_PLUGIN_MONITOR_H__
+
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-iface-monitor.h"
+
+#define STC_PLUGIN_MONITOR_FILEPATH            "/usr/lib/stc-plugin-monitor.so"
+
+int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb);
+int stc_plugin_monitor_deinit(void);
+
+int stc_plugin_monitor_add_rstn(table_restrictions_info *info);
+int stc_plugin_monitor_remove_rstn(table_restrictions_info *info);
+int stc_plugin_monitor_init_connection(stc_s *stc);
+int stc_plugin_monitor_deinit_connection(stc_s *stc);
+
+#endif /* __STC_MANAGER_PLUGIN_MONITOR_H__ */
index 9c69c00..a961bc8 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-pcap.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-pcap.h"
 
 static gboolean stc_plugin_enabled = FALSE;
 static void *handle_plugin;
index 0fab8bb..45cadc5 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-procfs.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-procfs.h"
 
 static gboolean stc_plugin_enabled = FALSE;
 static void *handle_plugin;
index 48d0609..2e797f0 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-plugin-tether.h"
 
 #include <dlfcn.h>
-
 #include "stc.h"
-#include "stc-plugin-tether.h"
 
 static gboolean stc_tether_plugin_enabled = FALSE;
 static void *tether_plugin_handle;
diff --git a/manager/stcmgr-plugin-tether.h b/manager/stcmgr-plugin-tether.h
new file mode 100644 (file)
index 0000000..d195521
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_MANAGER_PLUGIN_TETHER_H__
+#define __STC_MANAGER_PLUGIN_TETHER_H__
+
+#define STC_PLUGIN_TETHER_FILEPATH             "/usr/lib/stc-plugin-tether.so"
+
+#include "stc-plugin-tether.h"
+#include "stc-plugin-iface-tether.h"
+
+int stc_plugin_tether_init(void);
+int stc_plugin_tether_deinit(void);
+#endif /* __STC_MANAGER_PLUGIN_TETHER_H__ */
index c8e8249..e26f262 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-restriction.h"
 
 #include "stc-db.h"
 #include "stc-restriction.h"
 #include "db/table-restrictions.h"
-#include "stc-gdbus.h"
-#include "stc-plugin-monitor.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-monitor.h"
 
 #define RESTRICTION_DBUS_ERROR_NAME "net.stc.restriction.Error.Failed"
 
diff --git a/manager/stcmgr-restriction.h b/manager/stcmgr-restriction.h
new file mode 100644 (file)
index 0000000..b3738c1
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <glib.h>
+#include "stc-generated-dbus.h"
+
+gboolean handle_restriction_set(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_restriction_unset(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_restriction_set_list(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_restriction_unset_list(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *parameters,
+       void *user_data);
+
+gboolean handle_restriction_get(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       const gchar *app_id,
+       void *user_data);
+
+gboolean handle_restriction_get_all(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       void *user_data);
+
+gboolean handle_restriction_get_type(StcRestriction *object,
+       GDBusMethodInvocation *invocation,
+       const gchar *app_id,
+       int iftype,
+       void *user_data);
\ No newline at end of file
index 7ebdda5..dcb0dad 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcmgr-statistics.h"
 
 #include "stc-db.h"
-#include "stc-statistics.h"
 #include "db/table-statistics.h"
-#include "stc-gdbus.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
 
 #define STATISTICS_DBUS_ERROR_NAME "net.stc.statistics.Error.Failed"
 
diff --git a/manager/stcmgr-statistics.h b/manager/stcmgr-statistics.h
new file mode 100644 (file)
index 0000000..f199427
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <glib.h>
+#include "stc-generated-dbus.h"
+
+gboolean handle_statistics_init(StcStatistics *object,
+       GDBusMethodInvocation *invocation);
+
+gboolean handle_statistics_get_all(StcStatistics *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *select_rule,
+       void *user_data);
+
+gboolean handle_statistics_get(StcStatistics *object,
+       GDBusMethodInvocation *invocation,
+       const gchar *app_id,
+       GVariant *select_rule,
+       void *user_data);
+
+gboolean handle_statistics_reset(StcStatistics *object,
+       GDBusMethodInvocation *invocation,
+       GVariant *reset_rule,
+       void *user_data);
index baf3b6d..bfa7901 100644 (file)
  * limitations under the License.
  */
 #define _GNU_SOURCE
+#include "stcmgr.h"
+
 #include <signal.h>
 #include <errno.h>
 #include <sys/wait.h>
 #include "stc.h"
-#include "stc-gdbus.h"
 #include "stc-db.h"
+#include "stc-firewall.h"
 #include "stc-counter.h"
 #include "stc-util-inotify.h"
+#include "stc-helper-cgroup.h"
+#include "stc-helper-nfacct-rule.h"
+#include "stc-helper-iptables.h"
 #include "db/table-restrictions.h"
-#include "helper-cgroup.h"
-#include "helper-nfacct-rule.h"
-#include "helper-iptables.h"
-#include "stc-firewall.h"
-#include "stc-plugin-appstatus.h"
-#include "stc-plugin-exception.h"
-#include "stc-plugin-procfs.h"
-#include "stc-plugin-tether.h"
-#include "stc-plugin-pcap.h"
-#include "stc-plugin-monitor.h"
-#include "stc-plugin-firewall.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-appstatus.h"
+#include "stcmgr-plugin-exception.h"
+#include "stcmgr-plugin-procfs.h"
+#include "stcmgr-plugin-tether.h"
+#include "stcmgr-plugin-pcap.h"
+#include "stcmgr-plugin-monitor.h"
+#include "stcmgr-plugin-firewall.h"
 
 #define BUF_SIZE_FOR_ERR 100
 
@@ -257,8 +259,8 @@ gint32 main(gint32 argc, gchar *argv[])
 
        STC_LOGI("Smart Traffic Control Manager");
 
-#ifdef TIZEN_GTESTS
-       setenv("GCOV_PREFIX", "/tmp/daemon", 1);
+#ifdef TIZEN_TEST_GCOV
+       setenv("GCOV_PREFIX", "/opt/usr/daemon", 1);
 #endif
 
 /*
diff --git a/manager/stcmgr.h b/manager/stcmgr.h
new file mode 100644 (file)
index 0000000..d2dbfb6
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_MANAGER_H__
+#define __STC_MANAGER_H__
+
+#include "stc.h"
+
+void stc_stop_manager(void);
+int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
+void stc_set_keep_alive(gboolean keep_alive);
+
+#endif /* __STC_MANAGER__ */
index 7d41deb..afc7dd7 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
index 578cfa7..290e1ff 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syspopup_caller.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <dlog.h>
 #include <gio/gio.h>
 #include <pkgmgr-info.h>
 
@@ -141,12 +137,6 @@ static stc_cb_ret_e __insert_exception_cb(const stc_exceptions_info *info,
        return ret;
 }
 
-static gboolean __update_exceptions_app_list(void *user_data)
-{
-       stc_plugin_exception_update_list();
-       return TRUE;
-}
-
 static stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
                                       void *user_data)
 {
@@ -197,6 +187,23 @@ out:
        return err;
 }
 
+int stc_plugin_exception_update_list(void)
+{
+       __remove_exception_appall();
+       pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
+
+       if (STC_STAT_LOG)
+               __excn_hash_printall();
+
+       return STC_ERROR_NONE;
+}
+
+static gboolean __update_exceptions_app_list(void *user_data)
+{
+       stc_plugin_exception_update_list();
+       return TRUE;
+}
+
 static stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
                                       void *user_data)
 {
@@ -269,17 +276,6 @@ int stc_plugin_exception_fill_list(void)
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_exception_update_list(void)
-{
-       __remove_exception_appall();
-       pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
-
-       if (STC_STAT_LOG)
-               __excn_hash_printall();
-
-       return STC_ERROR_NONE;
-}
-
 int stc_plugin_exception_check_by_cmdline(char *cmdline)
 {
        char *exe_type = NULL;
index 7a9433c..18e6fb0 100644 (file)
@@ -5,6 +5,5 @@ ADD_LIBRARY(${STC_PI_FIREWALL} SHARED ${FIREWALL_SRCS})
 TARGET_LINK_LIBRARIES(${STC_PI_FIREWALL} ${plugin_pkgs_LIBRARIES})
 TARGET_COMPILE_OPTIONS(${STC_PI_FIREWALL} PUBLIC ${plugin_pkgs_CFLAGS_OTHER})
 SET_TARGET_PROPERTIES(${STC_PI_FIREWALL} PROPERTIES PREFIX "" OUTPUT_NAME ${STC_PI_FIREWALL})
-ADD_DEPENDENCIES(${STC_PI_FIREWALL} GENERATED_DBUS_CODE)
 
 INSTALL(TARGETS ${STC_PI_FIREWALL} DESTINATION ${LIB_INSTALL_DIR})
index a108a76..9f202ea 100644 (file)
  * limitations under the License.
  */
 #include "stc.h"
+#include "stc-gdbus.h"
+#include "stc-firewall.h"
 #include "stc-plugin-iface-firewall.h"
 #include "db/table-firewall.h"
-#include "helper-firewall.h"
 
 #define LOCK_NAME          "admin"
 
        } \
 } while (0)
 
+typedef struct {
+       stc_fw_chain_target_e target;
+       long long int priority;
+       GSList *rules;
+} stc_fw_data_s;
+
 static GHashTable *g_firewalls = NULL;
 static int g_lock_state = FIREWALL_UNKONWN;
 static int g_chain_priority = 0;
index abe818f..c2eabcd 100644 (file)
@@ -9,6 +9,5 @@ ADD_LIBRARY(${STC_PI_MONITOR} SHARED ${MONITOR_SRCS})
 TARGET_LINK_LIBRARIES(${STC_PI_MONITOR} ${plugin_pkgs_LIBRARIES} ${monitor_pkgs_LIBRARIES})
 TARGET_COMPILE_OPTIONS(${STC_PI_MONITOR} PUBLIC ${plugin_pkgs_CFLAGS_OTHER} ${monitor_pkgs_CFLAGS_OTHER})
 SET_TARGET_PROPERTIES(${STC_PI_MONITOR} PROPERTIES PREFIX "" OUTPUT_NAME ${STC_PI_MONITOR})
-ADD_DEPENDENCIES(${STC_PI_MONITOR} GENERATED_DBUS_CODE)
 
 INSTALL(TARGETS ${STC_PI_MONITOR} DESTINATION ${LIB_INSTALL_DIR})
index 1c4d997..a8433af 100644 (file)
@@ -20,8 +20,8 @@
 #include "stc-counter.h"
 #include "stc-plugin-tether.h"
 #include "db/table-statistics.h"
-#include "helper-net-cls.h"
-#include "stc-plugin-iface-monitor.h"
+#include "stc-helper-net-cls.h"
+#include "stcplugin-monitor.h"
 #include "stcplugin-monitor-rstn.h"
 #include "stcplugin-monitor-proc.h"
 #include "stcplugin-monitor-ipt.h"
index 7dc4eb5..7319ee1 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#include <vconf/vconf.h>
+#include <vconf.h>
 #include <openssl/sha.h>
 
 #include "stc-gdbus.h"
 #include "stc-firewall.h"
 #include "stc-plugin-firewall.h"
-#include "stc-plugin-monitor.h"
+#include "stcplugin-monitor.h"
 #include "stcplugin-monitor-connection.h"
 
 /* connman service dbus details */
index ab7286d..363a07c 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __STC_PLUGIN_MONITOR_IPT_H__
 #define __STC_PLUGIN_MONITOR_IPT_H__
 
-#include "helper-nfacct-rule.h"
+#include "stc-helper-nfacct-rule.h"
 
 stc_error_e stc_monitor_ipt_add_in(struct nfacct_rule *counter);
 stc_error_e stc_monitor_ipt_add_out(struct nfacct_rule *counter);
index 7545c48..9ca4f12 100644 (file)
@@ -14,9 +14,8 @@
  * limitations under the License.
  */
 
-#include "helper-net-cls.h"
-#include "db/table-restrictions.h"
-#include "stc-plugin-iface-monitor.h"
+#include "stc-helper-net-cls.h"
+#include "stcplugin-monitor.h"
 #include "stcplugin-monitor-proc.h"
 #include "stcplugin-monitor-app.h"
 #include "stcplugin-monitor-rstn.h"
index a5092c6..b6793ca 100644 (file)
 #include <bundle_internal.h>
 #include <syspopup_caller.h>
 
+#include "stc-gdbus.h"
 #include "stc-counter.h"
 #include "stc-plugin-tether.h"
 #include "db/table-counters.h"
 #include "db/table-restrictions.h"
 #include "db/table-statistics.h"
-#include "helper-net-cls.h"
-#include "stc-plugin-iface-monitor.h"
+#include "stc-helper-net-cls.h"
+#include "stcplugin-monitor.h"
 #include "stcplugin-monitor-rstn.h"
 #include "stcplugin-monitor-ipt.h"
 #include "stcplugin-monitor-time.h"
index c301683..5587e06 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "stcplugin-monitor.h"
 
 #include <linux/netlink.h>
 #include <vconf.h>
 #include <vconf-keys.h>
-
+#ifdef TIZEN_TEST_GCOV
+#include <gcov.h>
+#endif
 #include "stc-counter.h"
-#include "helper-nl.h"
-#include "helper-nfacct-rule.h"
-#include "helper-net-cls.h"
-#include "helper-cgroup.h"
-#include "helper-iptables.h"
+#include "stc-helper-nl.h"
+#include "stc-helper-nfacct-rule.h"
+#include "stc-helper-net-cls.h"
+#include "stc-helper-cgroup.h"
+#include "stc-helper-iptables.h"
 #include "db/table-statistics.h"
 #include "db/table-counters.h"
 #include "stc-plugin-exception.h"
@@ -267,8 +270,7 @@ static gboolean __process_contr_reply(GIOChannel *source,
        int ret;
        stc_s *stc = stc_get_manager();
 
-#ifdef TIZEN_GTESTS
-       void __gcov_flush(void);
+#ifdef TIZEN_TEST_GCOV
        __gcov_flush();
 #endif
 
@@ -326,8 +328,7 @@ static gboolean __update_contr_cb(void *user_data)
                stc->carg->sock = g_system->contr_sock;
        }
 
-#ifdef TIZEN_GTESTS
-       void __gcov_flush(void);
+#ifdef TIZEN_TEST_GCOV
        __gcov_flush();
 #endif
 
diff --git a/plugin/monitor/stcplugin-monitor.h b/plugin/monitor/stcplugin-monitor.h
new file mode 100644 (file)
index 0000000..7444ef2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_PLUGIN_MONITOR_H__
+#define __STC_PLUGIN_MONITOR_H__
+
+#include <glib.h>
+
+/* 1 seconds */
+#define CONTR_TIMER_INTERVAL 1
+
+#ifndef VCONFKEY_STC_BACKGROUND_STATE
+#define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
+#endif
+
+#ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
+#define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
+#endif
+
+GHashTable *stc_monitor_get_system_apps(void);
+GHashTable *stc_monitor_get_system_rstns(void);
+int stc_monitor_get_contr_sock(void);
+time_t stc_monitor_get_last_month_ts(void);
+void stc_monitor_set_last_month_ts(time_t time);
+time_t stc_monitor_get_last_week_ts(void);
+void stc_monitor_set_last_week_ts(time_t time);
+time_t stc_monitor_get_last_day_ts(void);
+void stc_monitor_set_last_day_ts(time_t time);
+void stc_monitor_set_rstns_updated(gboolean value);
+gboolean stc_monitor_get_rstns_updated(void);
+void stc_monitor_set_apps_updated(gboolean value);
+gboolean stc_monitor_get_apps_updated(void);
+void stc_monitor_set_background_state(gboolean value);
+gboolean stc_monitor_get_background_state(void);
+void stc_monitor_update_by_connection(void *data);
+void stc_monitor_add_by_connection(void *data);
+void stc_monitor_remove_by_connection(void *data);
+
+#endif /* __STC_PLUGIN_MONITOR_H__ */
index 0742b61..c0b331e 100644 (file)
 #ifndef __STC_PLUGIN_PCAP_INTERNAL_H__
 #define __STC_PLUGIN_PCAP_INTERNAL_H__
 
-#include <glib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <errno.h>
-#include <pcap.h>
-#include <pcap/nflog.h>
 #include <arpa/inet.h>
 #include <net/ethernet.h>
-#include <net/if_arp.h>
 #include <netinet/ether.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
 #include <netinet/ip_icmp.h>
+#include <netinet/ip6.h>
 #include <netinet/tcp.h>
 #include <netinet/udp.h>
+#include <glib.h>
+#include <pcap.h>
+#include <pcap/nflog.h>
 
 #include "stc.h"
 
index 2ea7fa7..5a4cd54 100644 (file)
@@ -6,6 +6,5 @@ ADD_LIBRARY(${STC_PI_PROCFS} SHARED ${PROCFS_SRCS})
 TARGET_LINK_LIBRARIES(${STC_PI_PROCFS} ${plugin_pkgs_LIBRARIES})
 TARGET_COMPILE_OPTIONS(${STC_PI_PROCFS} PUBLIC ${plugin_pkgs_CFLAGS_OTHER})
 SET_TARGET_PROPERTIES(${STC_PI_PROCFS} PROPERTIES PREFIX "" OUTPUT_NAME ${STC_PI_PROCFS})
-ADD_DEPENDENCIES(${STC_PI_PROCFS} GENERATED_DBUS_CODE)
 
 INSTALL(TARGETS ${STC_PI_PROCFS} DESTINATION ${LIB_INSTALL_DIR})
index f1255d0..11a5bd5 100644 (file)
@@ -28,8 +28,9 @@
 #include <glib.h>
 
 #include "stc-plugin-iface-procfs.h"
-#include "helper-net-cls.h"
-#include "helper-procfs.h"
+#include "stc-helper-net-cls.h"
+#include "stc-helper-procfs.h"
+#include "stc-helper-nl.h"
 #include "stc-plugin-monitor.h"
 #include "stc-plugin-exception.h"
 
@@ -148,6 +149,175 @@ static proc_value_s * __proc_tree_find_parent(proc_value_s *value)
        return parent;
 }
 
+stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
+       pid_t pid,
+       const gchar *app_id,
+       const gchar *pkg_id,
+       stc_app_type_e app_type)
+{
+       stc_error_e ret = STC_ERROR_NONE;
+
+       if ((pkg_id && app_id) && STC_STAT_LOG)
+               STC_LOGD("cmd[%d] pkgid[%s] appid[%s] pid[%d] type[%d]",
+                       cmd, pkg_id, app_id, pid, app_type);
+
+       switch (cmd) {
+       case STC_CMD_SET_FOREGRD:
+       {
+               uint32_t fg_classid = STC_UNKNOWN_CLASSID;
+               uint32_t bg_classid = STC_UNKNOWN_CLASSID;
+               char *bg_app_id = NULL;
+               stc_app_value_s app_value;
+               stc_proc_value_s proc_value;
+
+               memset(&app_value, 0, sizeof(stc_app_value_s));
+               memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+               bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+
+               app_value.type = app_type;
+               app_value.state = STC_APP_STATE_FOREGROUND;
+               app_value.processes = NULL;
+
+               proc_value.pid = pid;
+               proc_value.ground = STC_APP_STATE_FOREGROUND;
+
+               bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
+               fg_classid = get_classid_by_app_id(app_id, TRUE);
+
+               stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
+
+               stc_plugin_monitor_move_proc(bg_classid, fg_classid);
+
+               stc_plugin_monitor_add_proc(fg_classid, app_id, proc_value);
+               stc_plugin_monitor_update_proc_ground(fg_classid, app_id, proc_value);
+
+               FREE(bg_app_id);
+               break;
+       }
+       case STC_CMD_SET_BACKGRD:
+       {
+               uint32_t bg_classid = STC_UNKNOWN_CLASSID;
+               uint32_t fg_classid = STC_UNKNOWN_CLASSID;
+               char *bg_app_id = NULL;
+               stc_app_value_s app_value;
+               stc_proc_value_s proc_value;
+
+               memset(&app_value, 0, sizeof(stc_app_value_s));
+               memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+               bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+
+               app_value.type = app_type;
+               app_value.state = STC_APP_STATE_BACKGROUND;
+               app_value.processes = NULL;
+
+               proc_value.pid = pid;
+               proc_value.ground = STC_APP_STATE_BACKGROUND;
+
+               fg_classid = get_classid_by_app_id(app_id, FALSE);
+               bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
+
+               stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
+
+               stc_plugin_monitor_move_proc(fg_classid, bg_classid);
+
+               stc_plugin_monitor_add_proc(bg_classid, bg_app_id, proc_value);
+               stc_plugin_monitor_update_proc_ground(bg_classid, bg_app_id, proc_value);
+
+               FREE(bg_app_id);
+               break;
+       }
+       case STC_CMD_SET_APP_LAUNCHED:
+       {
+               uint32_t classid = STC_UNKNOWN_CLASSID;
+               stc_app_value_s app_value;
+               stc_proc_value_s proc_value;
+
+               memset(&app_value, 0, sizeof(stc_app_value_s));
+               memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+               classid = get_classid_by_app_id(app_id, FALSE);
+
+               app_value.type = app_type;
+               app_value.state = STC_APP_STATE_FOREGROUND;
+               app_value.processes = NULL;
+
+               proc_value.pid = pid;
+               proc_value.ground = STC_APP_STATE_FOREGROUND;
+
+               stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
+               stc_plugin_monitor_add_proc(classid, app_id, proc_value);
+
+               break;
+       }
+       case STC_CMD_SET_SERVICE_LAUNCHED:
+       {
+               uint32_t classid = STC_UNKNOWN_CLASSID;
+               char *bg_app_id = NULL;
+               stc_app_value_s app_value;
+               stc_proc_value_s proc_value;
+               gboolean is_exist;
+
+               memset(&app_value, 0, sizeof(stc_app_value_s));
+               memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+               classid = get_classid_by_app_id(app_id, FALSE);
+               is_exist = stc_plugin_monitor_lookup_app(classid);
+               if (is_exist) {
+                       app_value.type = app_type;
+                       app_value.state = STC_APP_STATE_FOREGROUND;
+                       app_value.processes = NULL;
+
+                       proc_value.pid = pid;
+                       proc_value.ground = STC_APP_STATE_FOREGROUND;
+
+                       stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
+                       stc_plugin_monitor_add_proc(classid, app_id, proc_value);
+               } else {
+                       bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+                       classid = get_classid_by_app_id(bg_app_id, TRUE);
+
+                       app_value.type = app_type;
+                       app_value.state = STC_APP_STATE_BACKGROUND;
+                       app_value.processes = NULL;
+
+                       proc_value.pid = pid;
+                       proc_value.ground = STC_APP_STATE_BACKGROUND;
+
+                       stc_plugin_monitor_add_app(classid, bg_app_id, pkg_id, app_value);
+                       stc_plugin_monitor_add_proc(classid, bg_app_id, proc_value);
+
+                       FREE(bg_app_id);
+               }
+               break;
+       }
+       case STC_CMD_SET_TERMINATED:
+       {
+               uint32_t classid = STC_UNKNOWN_CLASSID;
+               char *bg_app_id = NULL;
+
+               if (app_type == STC_APP_TYPE_NONE) {
+                       bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+                       classid = get_classid_by_app_id(bg_app_id, FALSE);
+               }
+
+               if (classid == STC_UNKNOWN_CLASSID)
+                       classid = get_classid_by_app_id(bg_app_id, FALSE);
+
+               stc_plugin_monitor_remove_proc(classid, pid);
+
+               FREE(bg_app_id);
+               break;
+       }
+       default:
+               STC_LOGE("Unhandled command");
+               ret = STC_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
 static void __proc_tree_add(proc_key_s *key, proc_value_s *value)
 {
        proc_value_s *lookup;
@@ -587,175 +757,6 @@ stc_error_e stc_plugin_procfs_load(void)
        return STC_ERROR_NONE;
 }
 
-stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
-                                               pid_t pid,
-                                               const gchar *app_id,
-                                               const gchar *pkg_id,
-                                               stc_app_type_e app_type)
-{
-       stc_error_e ret = STC_ERROR_NONE;
-
-       if ((pkg_id && app_id) && STC_STAT_LOG)
-               STC_LOGD("cmd[%d] pkgid[%s] appid[%s] pid[%d] type[%d]",
-                       cmd, pkg_id, app_id, pid, app_type);
-
-       switch (cmd) {
-       case STC_CMD_SET_FOREGRD:
-       {
-               uint32_t fg_classid = STC_UNKNOWN_CLASSID;
-               uint32_t bg_classid = STC_UNKNOWN_CLASSID;
-               char *bg_app_id = NULL;
-               stc_app_value_s app_value;
-               stc_proc_value_s proc_value;
-
-               memset(&app_value, 0, sizeof(stc_app_value_s));
-               memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
-               bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
-
-               app_value.type = app_type;
-               app_value.state = STC_APP_STATE_FOREGROUND;
-               app_value.processes = NULL;
-
-               proc_value.pid = pid;
-               proc_value.ground = STC_APP_STATE_FOREGROUND;
-
-               bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
-               fg_classid = get_classid_by_app_id(app_id, TRUE);
-
-               stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
-
-               stc_plugin_monitor_move_proc(bg_classid, fg_classid);
-
-               stc_plugin_monitor_add_proc(fg_classid, app_id, proc_value);
-               stc_plugin_monitor_update_proc_ground(fg_classid, app_id, proc_value);
-
-               FREE(bg_app_id);
-               break;
-       }
-       case STC_CMD_SET_BACKGRD:
-       {
-               uint32_t bg_classid = STC_UNKNOWN_CLASSID;
-               uint32_t fg_classid = STC_UNKNOWN_CLASSID;
-               char *bg_app_id = NULL;
-               stc_app_value_s app_value;
-               stc_proc_value_s proc_value;
-
-               memset(&app_value, 0, sizeof(stc_app_value_s));
-               memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
-               bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
-
-               app_value.type = app_type;
-               app_value.state = STC_APP_STATE_BACKGROUND;
-               app_value.processes = NULL;
-
-               proc_value.pid = pid;
-               proc_value.ground = STC_APP_STATE_BACKGROUND;
-
-               fg_classid = get_classid_by_app_id(app_id, FALSE);
-               bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
-
-               stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
-
-               stc_plugin_monitor_move_proc(fg_classid, bg_classid);
-
-               stc_plugin_monitor_add_proc(bg_classid, bg_app_id, proc_value);
-               stc_plugin_monitor_update_proc_ground(bg_classid, bg_app_id, proc_value);
-
-               FREE(bg_app_id);
-               break;
-       }
-       case STC_CMD_SET_APP_LAUNCHED:
-       {
-               uint32_t classid = STC_UNKNOWN_CLASSID;
-               stc_app_value_s app_value;
-               stc_proc_value_s proc_value;
-
-               memset(&app_value, 0, sizeof(stc_app_value_s));
-               memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
-               classid = get_classid_by_app_id(app_id, FALSE);
-
-               app_value.type = app_type;
-               app_value.state = STC_APP_STATE_FOREGROUND;
-               app_value.processes = NULL;
-
-               proc_value.pid = pid;
-               proc_value.ground = STC_APP_STATE_FOREGROUND;
-
-               stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
-               stc_plugin_monitor_add_proc(classid, app_id, proc_value);
-
-               break;
-       }
-       case STC_CMD_SET_SERVICE_LAUNCHED:
-       {
-               uint32_t classid = STC_UNKNOWN_CLASSID;
-               char *bg_app_id = NULL;
-               stc_app_value_s app_value;
-               stc_proc_value_s proc_value;
-               gboolean is_exist;
-
-               memset(&app_value, 0, sizeof(stc_app_value_s));
-               memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
-               classid = get_classid_by_app_id(app_id, FALSE);
-               is_exist = stc_plugin_monitor_lookup_app(classid);
-               if (is_exist) {
-                       app_value.type = app_type;
-                       app_value.state = STC_APP_STATE_FOREGROUND;
-                       app_value.processes = NULL;
-
-                       proc_value.pid = pid;
-                       proc_value.ground = STC_APP_STATE_FOREGROUND;
-
-                       stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
-                       stc_plugin_monitor_add_proc(classid, app_id, proc_value);
-               } else {
-                       bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
-                       classid = get_classid_by_app_id(bg_app_id, TRUE);
-
-                       app_value.type = app_type;
-                       app_value.state = STC_APP_STATE_BACKGROUND;
-                       app_value.processes = NULL;
-
-                       proc_value.pid = pid;
-                       proc_value.ground = STC_APP_STATE_BACKGROUND;
-
-                       stc_plugin_monitor_add_app(classid, bg_app_id, pkg_id, app_value);
-                       stc_plugin_monitor_add_proc(classid, bg_app_id, proc_value);
-
-                       FREE(bg_app_id);
-               }
-               break;
-       }
-       case STC_CMD_SET_TERMINATED:
-       {
-               uint32_t classid = STC_UNKNOWN_CLASSID;
-               char *bg_app_id = NULL;
-
-               if (app_type == STC_APP_TYPE_NONE) {
-                       bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
-                       classid = get_classid_by_app_id(bg_app_id, FALSE);
-               }
-
-               if (classid == STC_UNKNOWN_CLASSID)
-                       classid = get_classid_by_app_id(bg_app_id, FALSE);
-
-               stc_plugin_monitor_remove_proc(classid, pid);
-
-               FREE(bg_app_id);
-               break;
-       }
-       default:
-               STC_LOGE("Unhandled command");
-               ret = STC_ERROR_INVALID_PARAMETER;
-       }
-
-       return ret;
-}
-
 API stc_plugin_procfs_s stc_plugin_procfs = {
        .initialize_plugin =
                stc_plugin_procfs_initialize,
index 87e35c1..b382524 100644 (file)
@@ -26,6 +26,9 @@
 #include "stc-plugin-monitor.h"
 #include "stc-plugin-iface-tether.h"
 
+#define TETHERING_SERVICE_INTERFACE   "org.tizen.tethering"
+#define SIGNAL_NAME_DHCP_STATUS       "dhcp_status"
+
 static GSList *station_list = NULL;
 static GDBusConnection *connection = NULL;
 static GCancellable *cancellable = NULL;