Separate monitoring function plugin 27/194127/2
authorhyunuktak <hyunuk.tak@samsung.com>
Thu, 29 Nov 2018 07:49:41 +0000 (16:49 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Thu, 29 Nov 2018 07:53:05 +0000 (16:53 +0900)
Change-Id: I9cab1ed4d30e78bd4489ea6a7f1083f7e5aa1326
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
63 files changed:
include/stc-manager-plugin-monitor.h [new file with mode: 0755]
include/stc-manager-util.h
packaging/stc-manager.spec
plugin/CMakeLists.txt
plugin/appstatus/stc-plugin-appstatus.c
plugin/exception/stc-plugin-exception.c
plugin/monitor/CMakeLists.txt [new file with mode: 0644]
plugin/monitor/include/stc-plugin-monitor-app.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor-connection.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor-context.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor-ipt.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor-proc.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor-rstn.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor-time.h [new file with mode: 0755]
plugin/monitor/include/stc-plugin-monitor.h [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor-app.c [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor-connection.c [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor-ipt.c [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor-proc.c [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor-rstn.c [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor-time.c [new file with mode: 0755]
plugin/monitor/stc-plugin-monitor.c [new file with mode: 0755]
plugin/pcap/stc-plugin-pcap.c
plugin/procfs/CMakeLists.txt
plugin/procfs/include/stc-plugin-procfs.h [changed mode: 0644->0755]
plugin/procfs/stc-plugin-procfs.c
plugin/tether/CMakeLists.txt
plugin/tether/stc-plugin-tether.c
src/CMakeLists.txt
src/database/db-common.c [changed mode: 0644->0755]
src/database/tables/table-counters.c [changed mode: 0644->0755]
src/database/tables/table-restrictions.c [changed mode: 0644->0755]
src/database/tables/table-statistics.c
src/helper/helper-cgroup.c
src/helper/helper-file.c
src/helper/helper-iptables.c [changed mode: 0644->0755]
src/helper/helper-net-cls.c
src/helper/helper-nfacct-rule.c
src/helper/helper-nl.c [changed mode: 0644->0755]
src/monitor/include/stc-connection.h [deleted file]
src/monitor/include/stc-monitor-app.h [deleted file]
src/monitor/include/stc-monitor-context.h [deleted file]
src/monitor/include/stc-monitor-ipt.h [deleted file]
src/monitor/include/stc-monitor-proc.h [deleted file]
src/monitor/include/stc-monitor-rstn.h [deleted file]
src/monitor/include/stc-monitor.h [deleted file]
src/monitor/include/stc-time.h [deleted file]
src/monitor/stc-connection.c [deleted file]
src/monitor/stc-monitor-app.c [deleted file]
src/monitor/stc-monitor-ipt.c [deleted file]
src/monitor/stc-monitor-proc.c [deleted file]
src/monitor/stc-monitor-rstn.c [deleted file]
src/monitor/stc-monitor.c [deleted file]
src/monitor/stc-time.c [deleted file]
src/stc-firewall.c
src/stc-manager-gdbus.c
src/stc-manager-plugin-appstatus.c [changed mode: 0644->0755]
src/stc-manager-plugin-exception.c [changed mode: 0644->0755]
src/stc-manager-plugin-monitor.c [new file with mode: 0755]
src/stc-manager-plugin-pcap.c [changed mode: 0644->0755]
src/stc-manager-plugin-tether.c [changed mode: 0644->0755]
src/stc-manager.c
src/stc-restriction.c [changed mode: 0644->0755]

diff --git a/include/stc-manager-plugin-monitor.h b/include/stc-manager-plugin-monitor.h
new file mode 100755 (executable)
index 0000000..3830608
--- /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_MONITOR_H__
+#define __STC_MANAGER_PLUGIN_MONITOR_H__
+
+#define STC_PLUGIN_MONITOR_FILEPATH            "/usr/lib/stc-plugin-monitor.so"
+
+#include "stc-plugin-monitor.h"
+
+int stc_plugin_monitor_init(void);
+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_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_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__ */
index 4b2eb94aacdee9425c0c03bf900ee7e87ea3c68d..744053457085eecb9bb9a24e7ac0edc91dc09dd5 100755 (executable)
@@ -260,14 +260,14 @@ static inline bool strstart_with(const char *str, const char *with)
 
 #define ret_value_if(expr, val) do {                                   \
        if (expr) {                                                     \
-               STC_LOGE("(%s) -> %s():%d return", #expr, __FUNCTION__, __LINE__); \
                return (val);                                           \
        }                                                               \
 } while (0)
 
 #define ret_value_msg_if(expr, val, fmt, arg...) do {  \
        if (expr) {                                     \
-               STC_LOGE(fmt, ##arg);                   \
+               if (STC_DEBUG_LOG)                              \
+                       STC_LOGE(fmt, ##arg);                   \
                return val;                             \
        }                                               \
 } while (0)
index b14ee3fa868952dbaf037ee4df428d94ea229919..0d98483ba20bd01e8110b98530e2f23c4b6d77e7 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.82
+Version:    0.0.83
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
@@ -70,6 +70,12 @@ Summary: Tethering plugin for data usage of tethering clients
 %description plugin-tether
 A smart traffic control manager extension for tethering client data usage plugin
 
+%package plugin-monitor
+Summary: Monitor plugin for data usage of clients
+
+%description plugin-monitor
+A smart traffic control manager extension for monitoring client data usage plugin
+
 %prep
 %setup -q
 chmod 644 %{SOURCE0}
@@ -168,3 +174,7 @@ cp resources/dbus/stc-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/st
 %files plugin-tether
 %manifest %{name}.manifest
 %attr(500,root,root) %{_libdir}/stc-plugin-tether.so
+
+%files plugin-monitor
+%manifest %{name}.manifest
+%attr(500,root,root) %{_libdir}/stc-plugin-monitor.so
index 04c53b8b59e68cd16433d6d69fd6bc6b67e1c039..a56ee639ccba91e6dc95917bcbbec39db1a675be 100644 (file)
@@ -1,7 +1,6 @@
 SET(SOURCE_DIR               ${CMAKE_SOURCE_DIR}/src)
 SET(HELPER_SOURCE_DIR        ${SOURCE_DIR}/helper)
 SET(DATABASE_SOURCE_DIR      ${SOURCE_DIR}/database)
-SET(MONITOR_SOURCE_DIR       ${SOURCE_DIR}/monitor)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/interfaces)
@@ -12,11 +11,9 @@ INCLUDE_DIRECTORIES(${HELPER_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${DATABASE_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${DATABASE_SOURCE_DIR}/include)
 
-INCLUDE_DIRECTORIES(${MONITOR_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${MONITOR_SOURCE_DIR}/include)
-
 ADD_SUBDIRECTORY(appstatus)
 ADD_SUBDIRECTORY(exception)
 ADD_SUBDIRECTORY(procfs)
 ADD_SUBDIRECTORY(pcap)
 ADD_SUBDIRECTORY(tether)
+ADD_SUBDIRECTORY(monitor)
index 98fab81c526ed06ec5283e7870696e20acdd86cf..5d5b6539bc123d9e2fc1f191dca22109c1082c3c 100755 (executable)
@@ -87,7 +87,7 @@ static void __stc_gdbus_handle_aul_changestate(GDBusConnection *connection,
        else
                apptype = STC_APP_TYPE_GUI;
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG) {
+       if (STC_STAT_LOG) {
                STC_LOGD("\033[1;34mAPP STATUS\033[0;m: PkgID[\033[0;34m%s\033[0;m] "
                        "AppID[\033[0;32m%s\033[0;m] PID[\033[1;33m%d\033[0;m] Status[%s] Type[%s]",
                        pkgid, appid, pid, statstr, pkgtype);
index cdb47c4df62169c3a1042319ad070538690bf7b9..ec4e2fdfee539e790e0b1ff09166d6ee469d96b7 100755 (executable)
@@ -99,7 +99,7 @@ static void __excn_hash_foreach_print(gpointer key, gpointer value,
        const char *process_name = key;
        const char *exe_type = value;
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGI("Process_name[%s] exe_type[%s]",
                        process_name, exe_type);
 }
@@ -258,7 +258,7 @@ int stc_plugin_exception_fill_list(void)
        table_exceptions_foreach(__insert_exception_cb, NULL);
        pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                __excn_hash_printall();
 
        g_excns_timer_id = g_timeout_add_seconds(EXCNS_TIMER_INTERVAL,
@@ -273,7 +273,7 @@ int stc_plugin_exception_update_list(void)
        __remove_exception_appall();
        pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                __excn_hash_printall();
 
        return STC_ERROR_NONE;
diff --git a/plugin/monitor/CMakeLists.txt b/plugin/monitor/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c1658b1
--- /dev/null
@@ -0,0 +1,48 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(stc-plugin-monitor C)
+
+# Set required packages
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(monitor_plugin REQUIRED
+       dlog
+       gio-2.0
+       gio-unix-2.0
+       glib-2.0
+       vconf
+       openssl
+       )
+
+FOREACH(flag ${monitor_plugin_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/configure/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugin/tether/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugin/exception/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugin/appstatus/include)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror -fvisibility=hidden")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
+
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(SRCS_PLUGIN
+       stc-plugin-monitor.c
+       stc-plugin-monitor-proc.c
+       stc-plugin-monitor-connection.c
+       stc-plugin-monitor-rstn.c
+       stc-plugin-monitor-app.c
+       stc-plugin-monitor-ipt.c
+       stc-plugin-monitor-time.c
+       )
+
+# library build
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS_PLUGIN})
+ADD_DEPENDENCIES(${PROJECT_NAME} GENERATED_DBUS_CODE)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${monitor_plugin_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME})
+
+# install
+INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIBDIR})
diff --git a/plugin/monitor/include/stc-plugin-monitor-app.h b/plugin/monitor/include/stc-plugin-monitor-app.h
new file mode 100755 (executable)
index 0000000..cfd623f
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2017 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_APP_H__
+#define __STC_PLUGIN_MONITOR_APP_H__
+
+#include <glib.h>
+
+#include "stc-error.h"
+#include "stc-manager.h"
+#include "stc-plugin-monitor-context.h"
+#include "stc-plugin-monitor-connection.h"
+
+#define MAC_ADDRESS_LEN 18
+#define SUBSCRIBERID_NONE "none_subid"
+
+typedef struct {
+       uint32_t classid;  /**< classid for a package */
+       gchar *pkg_id;  /**< package id */
+       gchar *app_id;  /**< application id */
+       stc_app_type_e type;  /**< type of application */
+       stc_app_state_e state;
+       stc_data_counter_s data_usage;
+       stc_data_counter_s counter;
+       GHashTable *processes;  /**< applications instances */
+       char mac[MAC_ADDRESS_LEN+1]; /**< application mac address */
+} stc_app_value_s;
+
+
+stc_error_e stc_plugin_monitor_app_add(uint32_t classid,
+                               const char *app_id,
+                               const char *pkg_id,
+                               const stc_app_value_s value);
+stc_error_e stc_plugin_monitor_app_remove(uint32_t classid,
+                               const char *app_id);
+gboolean stc_plugin_monitor_app_lookup(uint32_t classid);
+
+
+void stc_monitor_app_update_counter(stc_app_value_s *value,
+                                classid_bytes_context_s *context);
+void stc_monitor_app_update_iface_counter(classid_bytes_context_s *context);
+gboolean stc_monitor_app_flush_stats_to_db(gpointer user_data);
+void stc_monitor_app_add_by_iface(const char *app_id);
+void stc_monitor_app_add_monitor(gpointer key,
+                               gpointer value, gpointer data);
+void stc_monitor_app_add_by_connection(stc_connection_s *conn);
+void stc_monitor_app_add_accept(gpointer key,
+                               gpointer value, gpointer data);
+void stc_monitor_app_remove_monitor(gpointer key,
+                               gpointer value, gpointer data);
+void stc_monitor_app_remove_by_connection(stc_connection_s *conn);
+void stc_monitor_app_remove_accept(gpointer key,
+                               gpointer value, gpointer data);
+GHashTable *stc_monitor_apps_init(void);
+
+#endif /* __STC_PLUGIN_MONITOR_APP_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor-connection.h b/plugin/monitor/include/stc-plugin-monitor-connection.h
new file mode 100755 (executable)
index 0000000..6454b2d
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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_CONNECTION_H__
+#define __STC_PLUGIN_MONITOR_CONNECTION_H__
+
+#include <glib.h>
+#include "stc-error.h"
+#include "stc-manager.h"
+#include "stc-manager-util.h"
+
+#define IMSI_LENGTH 16
+#define SHA256_DIGEST_LENGTH 32
+
+#define TETHERING_USB_IF   "usb0"
+#define TETHERING_WIFI_IF  "wlan0"
+#define TETHERING_BT_IF    "bnep0"
+#define TETHERING_P2P_IF   "p2p0"
+
+/**
+ * @brief Tethering interface info
+ */
+typedef struct {
+       gchar *ifname;
+       stc_iface_type_e type;
+} tether_iface_s;
+
+/**
+ * @brief connection information will be fetched from connman
+ */
+typedef struct {
+       /* to identify each connection uniquely */
+       gchar *path;
+
+       /* profile info */
+       stc_iface_type_e type;
+       gchar *ifname;
+
+       /* cellular profile only else it is always false */
+       gboolean roaming;
+
+       /* only present when default profile is cellular */
+       char subscriber_id[SHA256_DIGEST_LENGTH * 2 + 1];
+
+       /* hardware network protocol type */
+       stc_hw_net_protocol_type_e hw_net_protocol_type;
+
+       /* tethering status */
+       gboolean tether_state;
+
+       /* tethering interface */
+       tether_iface_s tether_iface;
+} stc_connection_s;
+
+
+stc_error_e stc_plugin_monitor_connection_init(stc_s *stc);
+stc_error_e stc_plugin_monitor_connection_deinit(stc_s *stc);
+
+
+GSList *stc_get_connection_list(void);
+
+#endif /* __STC_PLUGIN_MONITOR_CONNECTION_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor-context.h b/plugin/monitor/include/stc-plugin-monitor-context.h
new file mode 100755 (executable)
index 0000000..b0d0075
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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_CONTEXT_H__
+#define __STC_PLUGIN_MONITOR_CONTEXT_H__
+
+#include "stc-manager.h"
+
+typedef struct {
+       time_t now;
+       time_t month_start_ts;
+       time_t week_start_ts;
+       time_t day_start_ts;
+       int is_updated;
+} reset_time_limits_context_s;
+
+typedef struct {
+       struct nfacct_rule *counter;
+       int64_t bytes;
+       gboolean data_limit_exceeded;
+} classid_bytes_context_s;
+
+/**
+ * @brief structure to store system info
+ */
+typedef struct {
+       int contr_sock;  /**< socket used for getting kernel counters */
+       guint contr_timer_id;  /**< timer id for periodically getting kernel counters */
+       guint contr_gsource_id;
+       stc_data_counter_s du_curr;  /**< current data usage */
+       GHashTable *rstns;  /**< restriction rules */
+       gboolean rstns_updated;
+       GHashTable *apps;  /**< monitored applications */
+       gboolean apps_updated;
+       gboolean background_state;
+       time_t last_month_ts;
+       time_t last_week_ts;
+       time_t last_day_ts;
+       int month_start_date;
+} stc_system_s;
+
+#endif /* __STC_PLUGIN_MONITOR_CONTEXT_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor-ipt.h b/plugin/monitor/include/stc-plugin-monitor-ipt.h
new file mode 100755 (executable)
index 0000000..a104c10
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017 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_IPT_H__
+#define __STC_PLUGIN_MONITOR_IPT_H__
+
+#include "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);
+stc_error_e stc_monitor_ipt_del_in(struct nfacct_rule *counter);
+stc_error_e stc_monitor_ipt_del_out(struct nfacct_rule *counter);
+
+stc_error_e stc_monitor_ip6t_add_in(struct nfacct_rule *counter);
+stc_error_e stc_monitor_ip6t_add_out(struct nfacct_rule *counter);
+stc_error_e stc_monitor_ip6t_del_in(struct nfacct_rule *counter);
+stc_error_e stc_monitor_ip6t_del_out(struct nfacct_rule *counter);
+
+stc_error_e stc_monitor_tether_add_in(struct nfacct_rule *counter,
+               const gchar *ipaddr);
+stc_error_e stc_monitor_tether_add_out(struct nfacct_rule *counter,
+               const gchar *ipaddr);
+stc_error_e stc_monitor_tether_del_in(struct nfacct_rule *counter,
+               const gchar *ipaddr);
+stc_error_e stc_monitor_tether_del_out(struct nfacct_rule *counter,
+               const gchar *ipaddr);
+
+#endif /* __STC_PLUGIN_MONITOR_IPT_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor-proc.h b/plugin/monitor/include/stc-plugin-monitor-proc.h
new file mode 100755 (executable)
index 0000000..22bb06a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 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_PROC_H__
+#define __STC_PLUGIN_MONITOR_PROC_H__
+
+#include <glib.h>
+
+#include "stc-error.h"
+#include "stc-manager.h"
+
+typedef struct {
+       pid_t pid;
+       stc_app_state_e ground;
+} stc_proc_value_s;
+
+typedef struct {
+       pid_t pid;
+       stc_app_value_s *app_value;
+       gboolean entry_removed;
+} remove_pid_context_s;
+
+stc_error_e stc_plugin_monitor_proc_update_ground(uint32_t classid,
+                                               const char *app_id,
+                                               const stc_proc_value_s value);
+
+stc_error_e stc_plugin_monitor_proc_add(uint32_t classid,
+                                               const char *app_id,
+                                               const stc_proc_value_s value);
+
+stc_error_e stc_plugin_monitor_proc_remove(uint32_t classid, pid_t pid);
+
+stc_error_e stc_plugin_monitor_proc_move(uint32_t from, uint32_t to);
+
+#endif /* __STC_PLUGIN_MONITOR_PROC_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor-rstn.h b/plugin/monitor/include/stc-plugin-monitor-rstn.h
new file mode 100755 (executable)
index 0000000..0c690c7
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017 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_RSTN_H__
+#define __STC_PLUGIN_MONITOR_RSTN_H__
+
+#include <glib.h>
+
+#include "stc-error.h"
+#include "stc-manager.h"
+#include "stc-plugin-monitor-context.h"
+#include "stc-plugin-monitor-connection.h"
+#include "stc-restriction.h"
+#include "table-restrictions.h"
+
+#define GRANULARITY 10
+
+#define MAX_INT_LENGTH 128
+#define MAX_KEY_LENGTH 128
+
+typedef enum {
+       STC_RSTN_LIMIT_TYPE_DATA_WARN,
+       STC_RSTN_LIMIT_TYPE_DATA,
+       STC_RSTN_LIMIT_TYPE_MONTHLY,
+       STC_RSTN_LIMIT_TYPE_WEEKLY,
+       STC_RSTN_LIMIT_TYPE_DAILY,
+       STC_RSTN_LIMIT_TYPE_MAX
+} stc_rstn_limit_type_e;
+
+typedef enum {
+       STC_RSTN_STATE_INIT = -1,
+       STC_RSTN_STATE_UNSET,
+       STC_RSTN_STATE_SET,
+} stc_rstn_noti_state_e;
+
+typedef struct {
+       uint32_t classid;
+       char *app_id;
+       stc_iface_type_e iftype;
+       char *ifname;
+       char *subscriber_id;
+       stc_roaming_type_e roaming;
+       char *mac;
+
+       uint64_t restriction_id;
+       stc_rstn_state_e rstn_state;
+       stc_rstn_type_e rstn_type;
+
+       int64_t counter[STC_RSTN_LIMIT_TYPE_MAX];
+       int64_t limit[STC_RSTN_LIMIT_TYPE_MAX];
+       int32_t limit_exceeded;
+       int32_t limit_notified;
+
+       int month_start_date;
+       time_t month_start_ts;
+} stc_rstn_data_s;
+
+typedef struct {
+       GSList *rules;
+} stc_rstn_value_s;
+
+typedef struct {
+       time_t month_start_ts;
+       time_t week_start_ts;
+       time_t day_start_ts;
+       int64_t monthly_stat;
+       int64_t weekly_stat;
+       int64_t daily_stat;
+} stc_rstn_cumulative_data_s;
+
+
+stc_error_e stc_plugin_monitor_rstn_add(const table_restrictions_info *info);
+stc_error_e stc_plugin_monitor_rstn_remove(const table_restrictions_info *info);
+
+
+void stc_monitor_rstn_reset_time_counters_if_required(void);
+void stc_monitor_rstn_update_counter(gpointer data,
+                                       gpointer user_data);
+void stc_monitor_rstn_update_iface_counter(classid_bytes_context_s *context);
+void stc_monitor_rstn_action_when_limit_exceeded(stc_rstn_limit_type_e limit_type,
+                                               stc_rstn_data_s *rstn_data,
+                                               classid_bytes_context_s *context);
+gboolean stc_monitor_rstn_flush_contr_to_db(gpointer user_data);
+void stc_monitor_rstn_add_for_app(uint32_t classid);
+void stc_monitor_rstn_add_by_connection(stc_connection_s *conn);
+void stc_monitor_rstn_remove_for_app(uint32_t classid);
+void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn);
+void stc_monitor_rstns_load(void);
+GHashTable *stc_monitor_rstns_init(void);
+
+#endif /* __STC_PLUGIN_MONITOR_RSTN_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor-time.h b/plugin/monitor/include/stc-plugin-monitor-time.h
new file mode 100755 (executable)
index 0000000..0a7ca6f
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 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_MANAGER_TIME_H__
+#define __STC_PLUGIN_MANAGER_TIME_H__
+
+time_t stc_time_get_day_start(time_t now);
+time_t stc_time_get_week_start(time_t now);
+time_t stc_time_get_month_start(time_t now, int month_start_date);
+
+#endif /* __STC_PLUGIN_MANAGER_TIME_H__ */
diff --git a/plugin/monitor/include/stc-plugin-monitor.h b/plugin/monitor/include/stc-plugin-monitor.h
new file mode 100755 (executable)
index 0000000..35509c8
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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>
+#include "stc-error.h"
+#include "stc-manager.h"
+#include "stc-manager-util.h"
+#include "stc-plugin-monitor-context.h"
+#include "stc-plugin-monitor-app.h"
+#include "stc-plugin-monitor-proc.h"
+#include "stc-plugin-monitor-rstn.h"
+#include "helper-nl.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
+
+typedef struct {
+       int (*initialize_plugin) (void);
+       int (*deinitialize_plugin) (void);
+
+       int (*add_application) (uint32_t classid,
+                               const char *app_id,
+                               const char *pkg_id,
+                               const stc_app_value_s value);
+       int (*remove_application) (uint32_t classid,
+                               const char *app_id);
+
+       int (*add_restriction) (const table_restrictions_info *info);
+       int (*remove_restriction) (const table_restrictions_info *info);
+       int (*lookup_application) (uint32_t classid);
+
+       int (*init_connection) (stc_s *stc);
+       int (*deinit_connection) (stc_s *stc);
+
+       int (*add_process) (uint32_t classid,
+                               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);
+
+       int (*check_excn_by_cmdline) (char *cmdline);
+} stc_plugin_monitor_s;
+
+stc_error_e stc_plugin_monitor_initialize(void);
+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__ */
diff --git a/plugin/monitor/stc-plugin-monitor-app.c b/plugin/monitor/stc-plugin-monitor-app.c
new file mode 100755 (executable)
index 0000000..d7b3152
--- /dev/null
@@ -0,0 +1,745 @@
+/*
+ * 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.
+ */
+
+#include "stc-db.h"
+#include "counter.h"
+#include "stc-manager.h"
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-monitor-app.h"
+#include "stc-plugin-monitor-rstn.h"
+#include "stc-plugin-monitor-proc.h"
+#include "stc-plugin-monitor-ipt.h"
+#include "table-statistics.h"
+#include "helper-net-cls.h"
+#include "stc-manager-plugin-tether.h"
+
+static void __print_app(gpointer key, gpointer value,
+                                         gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+
+       STC_LOGD("PkgID[%s] AppID[\033[0;32m%s\033[0;m] "
+               "type[%d] state[%d] classid[\033[1;36m%d\033[0;m] "
+               "counter[in(%lld) out(%lld)]",
+                app_value->pkg_id, app_value->app_id,
+                app_value->type, app_value->state,
+                app_value->classid,
+                app_value->data_usage.in_bytes,
+                app_value->data_usage.out_bytes);
+}
+
+static void __app_update_statistics(gpointer key,
+                                       gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       time_t *touch_time = (time_t *)data;
+       GSList *conn_list = stc_get_connection_list();
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+               stc_db_classid_iftype_key stat_key;
+               stc_db_app_stats stat;
+
+               memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
+               memset(&stat, 0 , sizeof(stc_db_app_stats));
+
+               if (conn == NULL)
+                       return;
+
+               /* Do not update statistics for Tethering
+                * if tethering is in-active found */
+               if (conn && conn->tether_state == FALSE &&
+                       !strcmp(app_value->app_id, STC_TOTAL_TETHERING))
+                       return;
+
+               /* Do not update statistics for Wi-Fi
+                * if tethering is active on wlan0 iface */
+               if (conn && conn->tether_state &&
+                       conn->tether_iface.type == STC_IFACE_WIFI &&
+                       !strcmp(app_value->app_id, STC_TOTAL_WIFI))
+                       return;
+
+               stat_key.classid = app_value->classid;
+
+               if (app_value->classid == STC_TETHERING_APP_CLASSID &&
+                       conn->tether_state == TRUE)
+                       stat_key.iftype = conn->tether_iface.type;
+               else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
+                       stat_key.iftype = conn->tether_iface.type;
+               else
+                       stat_key.iftype = conn->type;
+
+               if (STC_IFACE_DATACALL == stat_key.iftype)
+                       stat_key.subscriber_id = g_strdup(conn->subscriber_id);
+               else
+                       stat_key.subscriber_id = g_strdup(SUBSCRIBERID_NONE);
+
+               if (app_value->classid == STC_TETHERING_APP_CLASSID &&
+                       conn->tether_state == TRUE)
+                       g_strlcpy(stat_key.ifname, conn->tether_iface.ifname,
+                                 MAX_IFACE_LENGTH);
+               else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
+                       g_strlcpy(stat_key.ifname, conn->tether_iface.ifname,
+                                 MAX_IFACE_LENGTH);
+               else
+                       g_strlcpy(stat_key.ifname, conn->ifname,
+                                 MAX_IFACE_LENGTH);
+
+               stat.app_id = g_strdup(app_value->app_id);
+               stat.snd_count = app_value->counter.out_bytes;
+               stat.rcv_count = app_value->counter.in_bytes;
+               stat.is_roaming = conn->roaming;
+
+               if (strstr(stat.app_id, "_BACKGROUND")) {
+                       stat.ground = STC_APP_STATE_BACKGROUND;
+               } else {
+                       if (strstr(stat.app_id, "TOTAL_"))
+                               stat.ground = STC_APP_STATE_UNKNOWN;
+                       else
+                               stat.ground = STC_APP_STATE_FOREGROUND;
+               }
+
+               table_statistics_insert(&stat_key, &stat, *touch_time);
+
+               app_value->counter.out_bytes = 0;
+               app_value->counter.in_bytes = 0;
+
+               FREE(stat.app_id);
+               FREE(stat_key.subscriber_id);
+       }
+
+       return;
+}
+
+static gboolean __add_app_monitor_for_tethering(gpointer key,
+                                   gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       stc_connection_s *connection = (stc_connection_s *)data;
+       stc_s *stc = stc_get_manager();
+       struct nfacct_rule counter;
+       char *ipaddr = NULL;
+       int ret;
+
+       STC_LOGI("Add appid(%s) classid(%d)", app_value->app_id,
+                       app_value->classid);
+
+       if (stc == NULL || connection == NULL)
+               return FALSE;
+
+       if (!stc->carg) {
+               stc->carg = MALLOC0(counter_arg_s, 1);
+               if (stc->carg == NULL)
+                       return FALSE;
+
+               stc->carg->sock = stc_monitor_get_contr_sock();
+       }
+
+       memset(&counter, 0, sizeof(struct nfacct_rule));
+
+       counter.carg = stc->carg;
+       counter.classid = app_value->classid;
+       counter.intend = NFACCT_TETH_COUNTER;
+
+       if (connection->tether_state != TRUE ||
+                       connection->tether_iface.ifname == NULL)
+               return FALSE;
+
+       counter.iftype = connection->tether_iface.type;
+       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+
+       /* get the ip address of the station based on its mac address */
+       ret = stc_plugin_tether_get_station_ip(app_value->mac, &ipaddr);
+       if (ret != STC_ERROR_NONE)
+               return FALSE;
+
+       /* tethering iptables rule */
+       stc_monitor_tether_add_in(&counter, ipaddr);
+       stc_monitor_tether_add_out(&counter, ipaddr);
+
+       g_free(ipaddr);
+       return FALSE;
+}
+
+static gboolean __remove_app_monitor_for_tethering(gpointer key,
+                               gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       stc_connection_s *connection = (stc_connection_s *)data;
+       stc_s *stc = stc_get_manager();
+       struct nfacct_rule counter;
+       char *ipaddr = NULL;
+       int ret;
+
+       STC_LOGI("Remove appid(%s) classid(%d)", app_value->app_id,
+                       app_value->classid);
+
+       if (stc == NULL || connection == NULL)
+               return FALSE;
+
+       if (!stc->carg) {
+               stc->carg = MALLOC0(counter_arg_s, 1);
+               if (stc->carg == NULL)
+                       return FALSE;
+
+               stc->carg->sock = stc_monitor_get_contr_sock();
+       }
+
+       memset(&counter, 0, sizeof(struct nfacct_rule));
+
+       counter.carg = stc->carg;
+       counter.classid = app_value->classid;
+       counter.intend = NFACCT_TETH_COUNTER;
+
+       if (connection->tether_state != TRUE ||
+                       connection->tether_iface.ifname == NULL)
+               return FALSE;
+
+       counter.iftype = connection->tether_iface.type;
+       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+
+       /* get the ip address of the station based on its mac address */
+       ret = stc_plugin_tether_get_station_ip(app_value->mac, &ipaddr);
+       if (ret != STC_ERROR_NONE)
+               return FALSE;
+
+       stc_monitor_tether_del_in(&counter, ipaddr);
+       stc_monitor_tether_del_out(&counter, ipaddr);
+
+       g_free(ipaddr);
+       return FALSE;
+}
+
+static void __app_value_destroy(gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)data;
+
+       FREE(app_value->pkg_id);
+       FREE(app_value->app_id);
+       g_hash_table_destroy(app_value->processes);
+       app_value->processes = NULL;
+
+       FREE(app_value);
+}
+
+static void __check_rstn_limit_exceeded(gpointer data,
+                               gpointer user_data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+       int32_t *limit_exceeded = (int32_t *)user_data;
+
+       if (rstn_data->limit_exceeded != 0)
+               *limit_exceeded = rstn_data->limit_exceeded;
+}
+
+static void __app_update_counter(classid_bytes_context_s *context,
+                               uint32_t classid)
+{
+       stc_app_value_s *lookup_app;
+       stc_rstn_value_s *lookup_rstn;
+       GHashTable *apps = stc_monitor_get_system_apps();
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!apps)
+               return;
+
+       lookup_app = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+       if (lookup_app)
+               stc_monitor_app_update_counter(lookup_app, context);
+
+       if (!rstns)
+               return;
+
+       lookup_rstn = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
+       if (lookup_rstn) {
+               int32_t limit_exceeded = 0;
+               g_slist_foreach(lookup_rstn->rules,
+                       __check_rstn_limit_exceeded, &limit_exceeded);
+
+               if (limit_exceeded != 0)
+                       return;
+       }
+}
+
+API stc_error_e stc_plugin_monitor_app_add(uint32_t classid,
+                               const char *app_id,
+                               const char *pkg_id,
+                               const stc_app_value_s value)
+{
+       stc_app_value_s *app_value;
+       stc_app_value_s *lookup_value;
+
+       GHashTable *apps = stc_monitor_get_system_apps();
+       GSList *conn_list = stc_get_connection_list();
+
+       if (!apps)
+               return STC_ERROR_NO_DATA;
+
+       if (classid == STC_UNKNOWN_CLASSID)
+               classid = get_classid_by_app_id(app_id, TRUE);
+
+       lookup_value = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+       if (lookup_value) {
+               if (STC_STAT_LOG)
+                       STC_LOGE("Already exists [\033[1;36m%d\033[0;m:"
+                                               "\033[0;32m%s\033[0;m]", classid, app_id);
+               return STC_ERROR_NONE;
+       }
+
+       app_value = MALLOC0(stc_app_value_s, 1);
+       if (!app_value) {
+               if (STC_STAT_LOG)
+                       STC_LOGE("Value allocation failed");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
+
+       /* create cgroup and update classid */
+       app_value->classid = classid;
+
+       app_value->app_id = g_strdup(app_id);
+       app_value->pkg_id = g_strdup(pkg_id);
+
+       app_value->type = value.type;
+       app_value->state = value.state;
+       app_value->data_usage.in_bytes = value.data_usage.in_bytes;
+       app_value->data_usage.out_bytes = value.data_usage.out_bytes;
+       g_strlcpy(app_value->mac, value.mac, MAC_ADDRESS_LEN);
+
+       app_value->processes = g_hash_table_new_full(g_direct_hash,
+                                                               g_direct_equal, NULL, NULL);
+
+       /* update classid for tethering station based on its mac address */
+       if (g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX) &&
+                               classid != STC_TETHERING_APP_CLASSID)
+               stc_plugin_tether_set_station_classid(app_value->mac, classid);
+
+       g_hash_table_insert(apps, GUINT_TO_POINTER(classid), app_value);
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+               /* add nfacct rule for this classid */
+               stc_monitor_app_add_monitor(GUINT_TO_POINTER(classid),
+                                       app_value, conn);
+
+               if (app_value->state == STC_APP_STATE_FOREGROUND)
+                       stc_monitor_app_add_accept(GUINT_TO_POINTER(classid),
+                                       app_value, conn);
+       }
+
+       stc_monitor_rstn_add_for_app(classid);
+
+       if (STC_STAT_LOG) {
+               __print_app(GUINT_TO_POINTER(classid), app_value, NULL);
+               STC_LOGD("\033[1;32mApplication added\033[0;m "
+                       "[\033[1;36m%d\033[0;m]", classid);
+       }
+
+       return STC_ERROR_NONE;
+}
+
+API stc_error_e stc_plugin_monitor_app_remove(uint32_t classid,
+                               const char *app_id)
+{
+       stc_app_value_s *app_lookup;
+       GHashTable *apps = stc_monitor_get_system_apps();
+       GSList *conn_list = stc_get_connection_list();
+
+       if (!apps)
+               return STC_ERROR_NO_DATA;
+
+       classid = get_classid_by_app_id(app_id, FALSE);
+
+       app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+       if (!app_lookup) {
+               if (STC_STAT_LOG)
+                       STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid);
+               return STC_ERROR_FAIL;
+       }
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+               /* remove nfacct rule for this classid */
+               stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
+                                       app_lookup, conn);
+
+               if (app_lookup->state == STC_APP_STATE_FOREGROUND)
+                       stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
+                                               app_lookup, conn);
+       }
+
+       /* remove ristrictions if any */
+       stc_monitor_rstn_remove_for_app(classid);
+
+       if (STC_STAT_LOG)
+               __print_app(GUINT_TO_POINTER(classid), app_lookup, NULL);
+
+       /* remove app_key from the stc-manager */
+       g_hash_table_remove(apps, GUINT_TO_POINTER(classid));
+
+       return STC_ERROR_NONE;
+}
+
+API gboolean stc_plugin_monitor_app_lookup(uint32_t classid)
+{
+       stc_app_value_s *lookup_value;
+
+       GHashTable *apps = stc_monitor_get_system_apps();
+
+       if (!apps)
+               return FALSE;
+
+       if (classid == STC_UNKNOWN_CLASSID)
+               return FALSE;
+
+       lookup_value = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+       if (lookup_value)
+               return TRUE;
+
+       return FALSE;
+}
+
+void stc_monitor_app_update_counter(stc_app_value_s *value,
+                                classid_bytes_context_s *context)
+{
+       switch (context->counter->iotype) {
+       case NFACCT_COUNTER_IN:
+               value->data_usage.in_bytes += context->bytes;
+               value->counter.in_bytes = context->bytes;
+               stc_monitor_set_apps_updated(TRUE);
+
+               break;
+       case NFACCT_COUNTER_OUT:
+               value->data_usage.out_bytes += context->bytes;
+               value->counter.out_bytes = context->bytes;
+               stc_monitor_set_apps_updated(TRUE);
+
+               break;
+       default:
+               STC_LOGE("Unknown iotype");
+       }
+}
+
+void stc_monitor_app_update_iface_counter(classid_bytes_context_s *context)
+{
+       switch (context->counter->iftype) {
+       case STC_IFACE_DATACALL:
+               __app_update_counter(context, STC_TOTAL_DATACALL_CLASSID);
+               break;
+       case STC_IFACE_WIFI:
+               __app_update_counter(context, STC_TOTAL_WIFI_CLASSID);
+               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       case STC_IFACE_BLUETOOTH:
+               __app_update_counter(context, STC_TOTAL_BLUETOOTH_CLASSID);
+               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       case STC_IFACE_USB:
+               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       case STC_IFACE_P2P:
+               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       default:
+               break;
+       }
+}
+
+gboolean stc_monitor_app_flush_stats_to_db(gpointer user_data)
+{
+       time_t current_time = 0;
+       stc_s *stc = stc_get_manager();
+       GHashTable *apps = stc_monitor_get_system_apps();
+       gboolean apps_updated = stc_monitor_get_apps_updated();
+
+       if (stc && stc->carg)
+               current_time = stc->carg->last_run_time;
+
+       if (apps_updated == FALSE)
+               return G_SOURCE_REMOVE;
+
+       stc_monitor_set_apps_updated(FALSE);
+
+       if (apps)
+               g_hash_table_foreach(apps,
+                                       __app_update_statistics,
+                                       &current_time);
+
+       STC_LOGI("Flushed app stats to database");
+       return G_SOURCE_REMOVE;
+}
+
+void stc_monitor_app_add_by_iface(const char *ifname)
+{
+       stc_app_value_s app_value;
+
+       if (ifname == NULL)
+               return;
+
+       memset(&app_value, 0, sizeof(stc_app_value_s));
+
+       app_value.type = STC_APP_TYPE_NONE;
+       app_value.processes = NULL;
+       app_value.counter.in_bytes = 0;
+       app_value.counter.out_bytes = 0;
+
+       stc_plugin_monitor_app_add(STC_UNKNOWN_CLASSID, ifname, ifname, app_value);
+}
+
+void stc_monitor_app_add_monitor(gpointer key,
+                               gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       stc_connection_s *connection = (stc_connection_s *)data;
+       stc_s *stc = stc_get_manager();
+
+       if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
+           app_value->classid == STC_TOTAL_WIFI_CLASSID ||
+           app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
+               return;
+
+       if (stc && connection && connection->ifname) {
+               struct nfacct_rule counter;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = app_value->classid;
+               counter.app_state = app_value->state;
+               counter.intend = NFACCT_COUNTER;
+
+               if (connection->tether_state == TRUE &&
+                       connection->tether_iface.ifname != NULL &&
+                       app_value->classid == STC_TETHERING_APP_CLASSID) {
+                       counter.iftype = connection->tether_iface.type;
+                       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+               } else {
+                       counter.iftype = connection->type;
+                       g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
+               }
+
+               if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX) &&
+                               app_value->classid != STC_TETHERING_APP_CLASSID) {
+                       __add_app_monitor_for_tethering(key, value, data);
+               } else if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
+                       stc_monitor_ipt_add_in(&counter);
+                       stc_monitor_ipt_add_out(&counter);
+               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
+                       stc_monitor_ip6t_add_in(&counter);
+                       stc_monitor_ip6t_add_out(&counter);
+               } else {
+                       stc_monitor_ipt_add_in(&counter);
+                       stc_monitor_ipt_add_out(&counter);
+                       stc_monitor_ip6t_add_in(&counter);
+                       stc_monitor_ip6t_add_out(&counter);
+               }
+       }
+}
+
+void stc_monitor_app_add_by_connection(stc_connection_s *conn)
+{
+       GHashTable *apps = stc_monitor_get_system_apps();
+
+       if (!apps)
+               return;
+
+       g_hash_table_foreach(apps, stc_monitor_app_add_monitor, conn);
+       g_hash_table_foreach(apps, stc_monitor_app_add_accept, conn);
+}
+
+void stc_monitor_app_add_accept(gpointer key,
+                               gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       stc_connection_s *connection = (stc_connection_s *)data;
+       stc_s *stc = stc_get_manager();
+
+       if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
+           app_value->classid == STC_TOTAL_WIFI_CLASSID ||
+           app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
+               return;
+
+       if (app_value->state != STC_APP_STATE_FOREGROUND)
+               return;
+
+       if (stc && connection && connection->ifname) {
+               struct nfacct_rule counter;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = app_value->classid;
+               counter.app_state = app_value->state;
+               counter.intend = NFACCT_ALLOW;
+
+               counter.iftype = connection->type;
+               g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
+
+               if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
+                       stc_monitor_ipt_add_in(&counter);
+                       stc_monitor_ipt_add_out(&counter);
+               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
+                       stc_monitor_ip6t_add_in(&counter);
+                       stc_monitor_ip6t_add_out(&counter);
+               } else {
+                       stc_monitor_ipt_add_in(&counter);
+                       stc_monitor_ipt_add_out(&counter);
+                       stc_monitor_ip6t_add_in(&counter);
+                       stc_monitor_ip6t_add_out(&counter);
+               }
+       }
+}
+
+void stc_monitor_app_remove_monitor(gpointer key,
+                               gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       stc_connection_s *connection = (stc_connection_s *)data;
+       stc_s *stc = stc_get_manager();
+
+       if (stc && connection && connection->ifname) {
+               struct nfacct_rule counter;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = app_value->classid;
+               counter.app_state = app_value->state;
+               counter.intend = NFACCT_COUNTER;
+
+               if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX) &&
+                               app_value->classid != STC_TETHERING_APP_CLASSID) {
+                       __remove_app_monitor_for_tethering(key, value, data);
+                       return;
+               } else if (connection->tether_state == FALSE &&
+                       connection->tether_iface.ifname != NULL &&
+                       app_value->classid == STC_TETHERING_APP_CLASSID) {
+                       counter.iftype = connection->tether_iface.type;
+                       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+               } else {
+                       counter.iftype = connection->type;
+                       g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
+               }
+
+               if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
+                       stc_monitor_ipt_del_in(&counter);
+                       stc_monitor_ipt_del_out(&counter);
+               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
+                       stc_monitor_ip6t_del_in(&counter);
+                       stc_monitor_ip6t_del_out(&counter);
+               } else {
+                       stc_monitor_ipt_del_in(&counter);
+                       stc_monitor_ipt_del_out(&counter);
+                       stc_monitor_ip6t_del_in(&counter);
+                       stc_monitor_ip6t_del_out(&counter);
+               }
+       }
+
+       return;
+}
+
+void stc_monitor_app_remove_by_connection(stc_connection_s *conn)
+{
+       GHashTable *apps = stc_monitor_get_system_apps();
+
+       if (!apps)
+               return;
+
+       g_hash_table_foreach(apps, stc_monitor_app_remove_monitor, conn);
+       g_hash_table_foreach(apps, stc_monitor_app_remove_accept, conn);
+}
+
+void stc_monitor_app_remove_accept(gpointer key,
+                               gpointer value, gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       stc_connection_s *connection = (stc_connection_s *)data;
+       stc_s *stc = stc_get_manager();
+
+       if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
+           app_value->classid == STC_TOTAL_WIFI_CLASSID ||
+           app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
+               return;
+
+       if (app_value->state != STC_APP_STATE_FOREGROUND)
+               return;
+
+       if (stc && connection && connection->ifname) {
+               struct nfacct_rule counter;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = app_value->classid;
+               counter.app_state = app_value->state;
+               counter.intend = NFACCT_ALLOW;
+
+               counter.iftype = connection->type;
+               g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
+
+               if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
+                       stc_monitor_ipt_del_in(&counter);
+                       stc_monitor_ipt_del_out(&counter);
+               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
+                       stc_monitor_ip6t_del_in(&counter);
+                       stc_monitor_ip6t_del_out(&counter);
+               } else {
+                       stc_monitor_ipt_del_in(&counter);
+                       stc_monitor_ipt_del_out(&counter);
+                       stc_monitor_ip6t_del_in(&counter);
+                       stc_monitor_ip6t_del_out(&counter);
+               }
+       }
+
+       return;
+}
+
+GHashTable *stc_monitor_apps_init(void)
+{
+       return g_hash_table_new_full(g_direct_hash, g_direct_equal,
+                                       NULL, __app_value_destroy);
+}
diff --git a/plugin/monitor/stc-plugin-monitor-connection.c b/plugin/monitor/stc-plugin-monitor-connection.c
new file mode 100755 (executable)
index 0000000..06c4c30
--- /dev/null
@@ -0,0 +1,737 @@
+/*
+ * 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.
+ */
+
+#include <vconf/vconf.h>
+#include <openssl/sha.h>
+
+#include "stc-firewall.h"
+#include "stc-manager-gdbus.h"
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-monitor-connection.h"
+
+/* connman service dbus details */
+#define CONNMAN_SERVICE                          "net.connman"
+#define CONNMAN_PATH                             "/net/connman"
+
+#define CONNMAN_MANAGER_PATH                     "/"
+#define CONNMAN_MANAGER_INTERFACE                CONNMAN_SERVICE ".Manager"
+#define CONNMAN_SERVICE_INTERFACE                CONNMAN_SERVICE ".Service"
+
+#define CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX  CONNMAN_PATH "/service/cellular_"
+#define CONNMAN_WIFI_SERVICE_PROFILE_PREFIX      CONNMAN_PATH "/service/wifi_"
+#define CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX  CONNMAN_PATH "/service/ethernet_"
+#define CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/bluetooth_"
+
+#define CONNMAN_SIGNAL_PROPERTY_CHANGED          "PropertyChanged"
+
+/* telephony service dbus details */
+#define TELEPHONY_SERVICE                        "org.tizen.telephony"
+#define TELEPHONY_DEFAULT_PATH                   "/org/tizen/telephony"
+
+#define TELEPHONY_SERVICE_MANAGER                TELEPHONY_SERVICE".Manager"
+#define TELEPHONY_SIM_INTERFACE                  TELEPHONY_SERVICE".Sim"
+
+#define TELEPHONY_GET_MODEMS                     "GetModems"
+#define TELEPHONY_GET_IMSI                       "GetIMSI"
+
+#define SIM_SLOT_SINGLE 1
+
+#define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE     "db/telephony/dualsim/default_data_service"
+
+stc_connection_s *g_default_connection = NULL;
+GSList *g_connection_list = NULL;
+guint g_connection_sub_id = 0;
+
+static void __conn_list_free(gpointer value)
+{
+       stc_connection_s *conn = (stc_connection_s *)value;
+
+       FREE(conn->path);
+       FREE(conn->ifname);
+       FREE(conn->tether_iface.ifname);
+       FREE(conn);
+}
+
+static gint __conn_list_comp(gconstpointer a, gconstpointer b)
+{
+       stc_connection_s *conn = (stc_connection_s *)a;
+       char *path = (char *)b;
+
+       if (g_strcmp0(conn->path, path) == 0)
+               return 0;
+
+       return -1;
+}
+
+static void __update_monitor_by_conn(gpointer data, gpointer user_data)
+{
+       stc_connection_s *conn = (stc_connection_s *)data;
+
+       stc_monitor_update_by_connection(conn);
+}
+
+static int __telephony_get_current_sim(void)
+{
+       int sim_slot_count = 0;
+       int current_sim = 0;
+
+       if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) {
+               STC_LOGD("failed to get sim slot count"); //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
+       }
+
+       if (sim_slot_count == SIM_SLOT_SINGLE) {
+              STC_LOGD("It's single sim model"); //LCOV_EXCL_LINE
+              return current_sim; //LCOV_EXCL_LINE
+       }
+
+       if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &current_sim) != 0) {
+               STC_LOGD("failed to get default data service = %d\n", //LCOV_EXCL_LINE
+                        current_sim);
+               return -1; //LCOV_EXCL_LINE
+       }
+
+       return current_sim;
+}
+
+static void __make_imsi_to_subscriber_id(stc_connection_s *conn, char *imsi)
+{
+       int i = 0;
+       SHA256_CTX ctx;
+       unsigned char md[SHA256_DIGEST_LENGTH];
+
+       SHA256_Init(&ctx);
+       SHA256_Update(&ctx, imsi, strlen(imsi));
+       SHA256_Final(md, &ctx);
+
+       for (i = 0; i < SHA256_DIGEST_LENGTH; ++i)
+               snprintf(conn->subscriber_id + (i * 2), 3, "%02x", md[i]);
+}
+
+static void __telephony_get_modem_subscriber_id(GDBusConnection *connection,
+                               stc_connection_s *conn, const char *default_modem_name)
+{
+       GVariant *message = NULL;
+       char tel_path[MAX_PATH_LENGTH];
+       char imsi[IMSI_LENGTH];
+       const char *plmn = NULL;
+       int plmn_len = 0;
+       const char *msin = NULL;
+       int msin_len = 0;
+
+       snprintf(tel_path, sizeof(tel_path), "%s/%s", TELEPHONY_DEFAULT_PATH,
+                default_modem_name);
+       message = stc_manager_gdbus_call_sync(connection,
+                                             TELEPHONY_SERVICE,
+                                             tel_path,
+                                             TELEPHONY_SIM_INTERFACE,
+                                             TELEPHONY_GET_IMSI,
+                                             NULL);
+       if (message == NULL) {
+               STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+               goto done; //LCOV_EXCL_LINE
+       }
+
+       DEBUG_PARAMS(message);
+       DEBUG_PARAM_TYPE(message);
+       g_variant_get(message, "(&s&s)", &plmn, &msin);
+       if (plmn)
+               plmn_len = strlen(plmn);
+       if (msin)
+               msin_len = strlen(msin);
+
+       if (msin_len + plmn_len >= IMSI_LENGTH) {
+               STC_LOGD("Incorrect length of mobile subscriber identifier + net id"); //LCOV_EXCL_LINE
+               goto done; //LCOV_EXCL_LINE
+       }
+
+       snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin);
+       __make_imsi_to_subscriber_id(conn, imsi);
+
+done:
+       g_variant_unref(message);
+       return;
+}
+
+static void __telephony_update_default_modem_subscriber_id(GDBusConnection *connection,
+                               stc_connection_s *conn)
+{
+       GVariant *message = NULL;
+       GVariantIter *iter = NULL;
+       gchar *default_modem_name = NULL;
+       gchar *modem_name = NULL;
+       int current_sim = __telephony_get_current_sim();
+
+       if (current_sim < 0) {
+               STC_LOGI("Sim not found"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
+       }
+
+       message = stc_manager_gdbus_call_sync(connection,
+                                             TELEPHONY_SERVICE,
+                                             TELEPHONY_DEFAULT_PATH,
+                                             TELEPHONY_SERVICE_MANAGER,
+                                             TELEPHONY_GET_MODEMS,
+                                             NULL);
+       if (message == NULL) {
+               STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
+       }
+
+       g_variant_get(message, "(as)", &iter);
+       DEBUG_PARAMS(message);
+       DEBUG_PARAM_TYPE(message);
+       while (g_variant_iter_loop(iter, "s", &modem_name)) {
+               if (current_sim == 0) {
+                       default_modem_name = g_strdup(modem_name);
+                       FREE(modem_name);
+                       break;
+               }
+               current_sim--; //LCOV_EXCL_LINE
+       }
+
+       __telephony_get_modem_subscriber_id(connection, conn, default_modem_name);
+
+       FREE(default_modem_name);
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+       return;
+}
+
+static void __print_connection_info(stc_connection_s *conn)
+{
+       STC_LOGI("============= connection info ============");
+       STC_LOGI("path    [%s]", conn->path);
+       STC_LOGI("type    [%d]", conn->type);
+       STC_LOGI("ifname  [%s]", conn->ifname);
+       STC_LOGI("roaming [%u]", conn->roaming ? TRUE : FALSE);
+       if (conn->type == STC_IFACE_DATACALL)
+               STC_LOGI("sub_id  [%s]", conn->subscriber_id);
+       STC_LOGI("==================================================");
+}
+
+static void __print_tether_connection_info(void)
+{
+       STC_LOGI("============= tethering connection info ============");
+       STC_LOGI("mode    [%u]", g_default_connection->tether_state ? TRUE : FALSE);
+       STC_LOGI("type    [%d]", g_default_connection->tether_iface.type);
+       STC_LOGI("ifname  [%s]", g_default_connection->tether_iface.ifname);
+       STC_LOGI("====================================================");
+}
+
+static gboolean __is_cellular_internet_profile(const char *profile)
+{
+       const char internet_suffix[] = "_1";
+
+       if (profile == NULL)
+               return FALSE;
+
+       if (g_str_has_prefix(profile, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX)
+           == TRUE) {
+               char *suffix = strrchr(profile, '_');
+               if (g_strcmp0(suffix, internet_suffix) == 0)
+                       return TRUE;
+       }
+
+       return FALSE;
+}
+
+static gboolean __is_cellular_profile(const char *profile)
+{
+       if (profile == NULL)
+               return FALSE;
+
+       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
+                               CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX);
+}
+
+static gboolean __is_wifi_profile(const char *profile)
+{
+       if (profile == NULL)
+               return FALSE;
+
+       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
+                               CONNMAN_WIFI_SERVICE_PROFILE_PREFIX);
+}
+
+static gboolean __is_ethernet_profile(const char *profile)
+{
+       if (profile == NULL)
+               return FALSE;
+
+       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
+                               CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX);
+}
+
+static gboolean __is_bluetooth_profile(const char *profile)
+{
+       if (profile == NULL)
+               return FALSE;
+
+       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
+                               CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX);
+}
+
+static gboolean __is_connected(GVariantIter *array)
+{
+       gboolean is_connected = FALSE;
+       GVariant *variant = NULL;
+       gchar *key = NULL;
+
+       while (g_variant_iter_loop(array, "{sv}", &key, &variant)) {
+               if (g_strcmp0(key, "State") != 0)
+                       continue;
+
+               if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
+                       const gchar *state = NULL;
+
+                       state = g_variant_get_string(variant, NULL);
+                       if (g_strcmp0(state, "ready") == 0 ||
+                           g_strcmp0(state, "online") == 0)
+                               is_connected = TRUE;
+               }
+
+               g_free(key);
+               g_variant_unref(variant);
+               break;
+       }
+
+       return is_connected;
+}
+
+static void __get_connection_info(GDBusConnection *connection,
+                               stc_connection_s *conn, const char *object_path)
+{
+       GVariant *message = NULL;
+       GVariantIter *iter = NULL;
+       GVariant *variant = NULL;
+       gchar *key = NULL;
+
+       if (object_path == NULL) {
+               STC_LOGI("Object path is NULL, so information not available.");
+               return;
+       }
+
+       message = stc_manager_gdbus_call_sync(connection,
+                                             CONNMAN_SERVICE,
+                                             object_path,
+                                             CONNMAN_SERVICE_INTERFACE,
+                                             "GetProperties", NULL);
+       if (message == NULL) {
+               STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
+               goto done; //LCOV_EXCL_LINE
+       }
+
+       g_variant_get(message, "(a{sv})", &iter);
+       if (iter == NULL) {
+               STC_LOGE("Profile %s doesn't exist", object_path); //LCOV_EXCL_LINE
+               goto done; //LCOV_EXCL_LINE
+       }
+
+       while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
+               if (g_strcmp0(key, "Ethernet") == 0) {
+                       GVariantIter *iter1 = NULL;
+                       GVariant *variant1 = NULL;
+                       gchar *key1 = NULL;
+
+                       g_variant_get(variant, "a{sv}", &iter1);
+                       if (iter1 == NULL)
+                               continue; //LCOV_EXCL_LINE
+
+                       while (g_variant_iter_loop(iter1, "{sv}", &key1,
+                                                  &variant1)) {
+                               if (g_strcmp0(key1, "Interface") == 0) {
+                                       const gchar *value =
+                                               g_variant_get_string(variant1,
+                                                                    NULL);
+                                       conn->ifname = g_strdup(value);
+                               }
+                       }
+
+                       g_variant_iter_free(iter1);
+
+               } else if (g_strcmp0(key, "Roaming") == 0) {
+                       gboolean roaming = 0;
+
+                       if (g_variant_is_of_type(variant,
+                                                G_VARIANT_TYPE_BOOLEAN)) {
+                               roaming = g_variant_get_boolean(variant);
+                               conn->roaming = roaming;
+                       }
+               }
+       }
+
+done:
+       if (iter)
+               g_variant_iter_free(iter);
+
+       if (message)
+               g_variant_unref(message);
+
+       return;
+}
+
+static stc_error_e __get_connected_profiles(GDBusConnection *connection)
+{
+       GVariant *message = NULL;
+       GVariantIter *iter = NULL;
+       GVariantIter *next;
+       gchar *object_path;
+       stc_connection_s *conn;
+       gboolean default_conn = TRUE;
+
+       message = stc_manager_gdbus_call_sync(connection,
+                                             CONNMAN_SERVICE,
+                                             CONNMAN_MANAGER_PATH,
+                                             CONNMAN_MANAGER_INTERFACE,
+                                             "GetServices", NULL);
+       if (message == NULL) {
+               STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
+               return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+       }
+
+       g_slist_free_full(g_connection_list, __conn_list_free);
+
+       g_variant_get(message, "(a(oa{sv}))", &iter);
+       while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
+               if (object_path == NULL)
+                       continue; //LCOV_EXCL_LINE
+
+               if (__is_cellular_profile(object_path) &&
+                   !__is_cellular_internet_profile(object_path))
+                       continue;
+
+               if (__is_connected(next) == TRUE) {
+                       conn = MALLOC0(stc_connection_s, 1);
+                       if (conn == NULL)
+                               continue;
+
+                       conn->path = g_strdup(object_path);
+                       conn->roaming = FALSE;
+
+                       if (__is_cellular_profile(conn->path)) {
+                               conn->type = STC_IFACE_DATACALL;
+                               __telephony_update_default_modem_subscriber_id(connection, conn);
+                       } else if (__is_wifi_profile(conn->path)) {
+                               conn->type = STC_IFACE_WIFI;
+                       } else if (__is_ethernet_profile(conn->path)) {
+                               conn->type = STC_IFACE_WIRED;
+                       } else if (__is_bluetooth_profile(conn->path)) {
+                               conn->type = STC_IFACE_BLUETOOTH;
+                       } else {
+                               conn->type = STC_IFACE_UNKNOWN;
+                       }
+
+                       __get_connection_info(connection, conn, conn->path);
+                       __print_connection_info(conn);
+
+                       if (default_conn == TRUE) {
+                               g_default_connection = conn;
+                               default_conn = FALSE;
+                       }
+
+                       g_connection_list = g_slist_append(g_connection_list, conn);
+
+                       g_free(object_path);
+                       g_variant_iter_free(next);
+                       continue;
+               }
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       g_slist_foreach(g_connection_list, __update_monitor_by_conn, NULL);
+       stc_firewall_update();
+
+       return STC_ERROR_NONE;
+}
+
+static stc_error_e __get_default_connection(GDBusConnection *connection)
+{
+       GVariant *message = NULL;
+       GVariantIter *iter = NULL;
+       GVariantIter *next;
+       gchar *object_path;
+
+       message = stc_manager_gdbus_call_sync(connection,
+                                             CONNMAN_SERVICE,
+                                             CONNMAN_MANAGER_PATH,
+                                             CONNMAN_MANAGER_INTERFACE,
+                                             "GetServices", NULL);
+       if (message == NULL) {
+               STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
+               return STC_ERROR_FAIL; //LCOV_EXCL_LINE
+       }
+
+       g_variant_get(message, "(a(oa{sv}))", &iter);
+       while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
+               if (object_path == NULL)
+                       continue; //LCOV_EXCL_LINE
+
+               if (__is_cellular_profile(object_path) &&
+                   !__is_cellular_internet_profile(object_path))
+                       continue;
+
+               if (__is_connected(next) == TRUE) {
+                       GSList *comp = g_slist_find_custom(g_connection_list,
+                                                               object_path, __conn_list_comp);
+                       if (comp && comp->data)
+                               g_default_connection = comp->data;
+
+                       break;
+               }
+       }
+
+       g_variant_iter_free(iter);
+       g_variant_unref(message);
+
+       return STC_ERROR_NONE;
+}
+
+static void __append_connected_profile(GDBusConnection *connection,
+                               const char *path)
+{
+       stc_connection_s *conn;
+
+       conn = MALLOC0(stc_connection_s, 1);
+       if (conn == NULL)
+               return;
+
+       conn->path = g_strdup(path);
+       conn->roaming = FALSE;
+
+       if (__is_cellular_profile(conn->path)) {
+               conn->type = STC_IFACE_DATACALL;
+               __telephony_update_default_modem_subscriber_id(connection, conn);
+       } else if (__is_wifi_profile(conn->path)) {
+               conn->type = STC_IFACE_WIFI;
+       } else if (__is_ethernet_profile(conn->path)) {
+               conn->type = STC_IFACE_WIRED;
+       } else if (__is_bluetooth_profile(conn->path)) {
+               conn->type = STC_IFACE_BLUETOOTH;
+       } else {
+               conn->type = STC_IFACE_UNKNOWN;
+       }
+
+       __get_connection_info(connection, conn, conn->path);
+       __print_connection_info(conn);
+
+       g_connection_list = g_slist_append(g_connection_list, conn);
+
+       stc_monitor_add_by_connection(conn);
+       stc_firewall_update();
+
+       __get_default_connection(connection);
+}
+
+static void __remove_disconnected_profile(GDBusConnection *connection,
+                               stc_connection_s *conn)
+{
+       __print_connection_info(conn);
+
+       stc_monitor_remove_by_connection(conn);
+
+       g_connection_list = g_slist_remove(g_connection_list, conn);
+
+       __get_default_connection(connection);
+
+       FREE(conn->path);
+       FREE(conn->ifname);
+       FREE(conn->tether_iface.ifname);
+       FREE(conn);
+}
+
+static void __vconf_key_callback(keynode_t *node, void *user_data)
+{
+       int vconf_key;
+
+       if (node == NULL) {
+               STC_LOGE("Invalid parameter");
+               return;
+       }
+
+       if (g_default_connection == NULL)
+               return;
+
+       if (vconf_keynode_get_type(node) != VCONF_TYPE_INT) {
+               STC_LOGE("Invalid vconf key type");
+               return;
+       }
+
+       vconf_key = vconf_keynode_get_int(node);
+
+       /* Check the tethering type */
+       switch (vconf_key) {
+       case VCONFKEY_MOBILE_HOTSPOT_MODE_USB:
+               STC_LOGI("Hotspot mode USB type !");
+               g_default_connection->tether_state = TRUE;
+               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_USB_IF);
+               g_default_connection->tether_iface.type = STC_IFACE_USB;
+               break;
+       case VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI:
+               STC_LOGI("Hotspot mode Wi-Fi type !");
+               g_default_connection->tether_state = TRUE;
+               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_WIFI_IF);
+               g_default_connection->tether_iface.type = STC_IFACE_WIFI;
+               break;
+       case VCONFKEY_MOBILE_HOTSPOT_MODE_BT:
+               STC_LOGI("Hotspot mode Bluetooth type !");
+               g_default_connection->tether_state = TRUE;
+               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_BT_IF);
+               g_default_connection->tether_iface.type = STC_IFACE_BLUETOOTH;
+               break;
+       case VCONFKEY_MOBILE_HOTSPOT_MODE_P2P:
+               STC_LOGI("Hotspot mode P2P type !");
+               g_default_connection->tether_state = TRUE;
+               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_P2P_IF);
+               g_default_connection->tether_iface.type = STC_IFACE_P2P;
+               break;
+       case VCONFKEY_MOBILE_HOTSPOT_MODE_NONE:
+               STC_LOGI("Hotspot mode none");
+               g_default_connection->tether_state = FALSE;
+               break;
+       default:
+               STC_LOGE("Unknown Hotspot mode type !");
+               break;
+       }
+
+       /* add monitoring for tethering if active found */
+       if (g_default_connection->tether_state == TRUE && g_default_connection->tether_iface.ifname) {
+               __print_tether_connection_info();
+               stc_monitor_update_by_connection(&g_default_connection);
+               stc_firewall_update();
+               STC_LOGI("Data monitoring started for tethering iface !");
+               return;
+       }
+
+       /* remove monitoring for tethering if in-active found */
+       if (g_default_connection->tether_state == FALSE && g_default_connection->tether_iface.ifname) {
+               stc_monitor_update_by_connection(&g_default_connection);
+               g_free(g_default_connection->tether_iface.ifname);
+               g_default_connection->tether_iface.ifname = NULL;
+               g_default_connection->tether_iface.type = STC_IFACE_UNKNOWN;
+               STC_LOGI("Data monitoring stopped for tethering iface !");
+               return;
+       }
+}
+
+static void _service_signal_cb(GDBusConnection *connection,
+                              const gchar *name, const gchar *path,
+                              const gchar *interface, const gchar *sig,
+                              GVariant *param, gpointer user_data)
+{
+       gchar *sigvalue = NULL;
+       GVariant *variant = NULL;
+       stc_s *stc = (stc_s *)stc_get_manager();
+       ret_msg_if(stc == NULL, "failed to get stc data");
+
+       if (path == NULL || param == NULL)
+               goto done;
+
+       g_variant_get(param, "(sv)", &sigvalue, &variant);
+       if (sigvalue == NULL)
+               goto done;
+
+       if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
+               goto done;
+
+       if (g_strcmp0(sigvalue, "State") == 0 &&
+           g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
+               const gchar *state = NULL;
+
+               state = g_variant_get_string(variant, NULL);
+               if (g_strcmp0(state, "ready") == 0 ||
+                   g_strcmp0(state, "online") == 0) {
+                       GSList *comp = g_slist_find_custom(g_connection_list,
+                                                               path, __conn_list_comp);
+                       if (!comp)
+                               __append_connected_profile(stc->connection, path);
+               } else if (g_strcmp0(state, "idle") == 0 ||
+                       g_strcmp0(state, "disconnect") == 0) {
+                       GSList *comp = g_slist_find_custom(g_connection_list,
+                                                               path, __conn_list_comp);
+                       if (comp && comp->data)
+                               __remove_disconnected_profile(stc->connection, comp->data);
+               }
+       } else if (g_strcmp0(sigvalue, "Roaming") == 0) {
+               //LCOV_EXCL_START
+               GSList *comp = g_slist_find_custom(g_connection_list,
+                                                       path, __conn_list_comp);
+
+               if (comp) {
+                       stc_connection_s *conn = comp->data;
+                       gboolean roaming = 0;
+
+                       if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
+                               roaming = g_variant_get_boolean(variant);
+                               conn->roaming = roaming;
+                       }
+               }
+               //LCOV_EXCL_STOP
+       } else {
+               ;//Do nothing
+       }
+done:
+       if (sigvalue)
+               g_free(sigvalue);
+
+       if (variant)
+               g_variant_unref(variant);
+
+       return;
+}
+
+stc_error_e stc_plugin_monitor_connection_init(stc_s *stc)
+{
+       int ret;
+       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
+
+       __get_connected_profiles(stc->connection);
+       g_connection_sub_id =
+               stc_manager_gdbus_subscribe_signal(stc->connection,
+                                                  CONNMAN_SERVICE,
+                                                  CONNMAN_SERVICE_INTERFACE,
+                                                  CONNMAN_SIGNAL_PROPERTY_CHANGED,
+                                                  NULL, NULL,
+                                                  G_DBUS_SIGNAL_FLAGS_NONE,
+                                                  _service_signal_cb,
+                                                  NULL, NULL);
+
+       ret = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, __vconf_key_callback, NULL);
+       if (ret < 0)
+               STC_LOGE("vconf_notify_key_changed failed: %d", ret);
+
+       STC_LOGI("Successfully subscribed connman [%s] signal", CONNMAN_SIGNAL_PROPERTY_CHANGED);
+       return STC_ERROR_NONE;
+}
+
+stc_error_e stc_plugin_monitor_connection_deinit(stc_s *stc)
+{
+       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
+
+       stc_manager_gdbus_unsubscribe_signal(stc->connection,
+                                            g_connection_sub_id);
+
+       g_slist_free_full(g_connection_list, __conn_list_free);
+
+       return STC_ERROR_NONE;
+}
+
+GSList *stc_get_connection_list(void)
+{
+       return g_connection_list;
+}
diff --git a/plugin/monitor/stc-plugin-monitor-ipt.c b/plugin/monitor/stc-plugin-monitor-ipt.c
new file mode 100755 (executable)
index 0000000..c8fa882
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * 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.
+ */
+
+#include "stc-plugin-monitor-ipt.h"
+#include "stc-plugin-monitor-context.h"
+
+static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter)
+{
+       if (counter->intend == NFACCT_WARN)
+               return NFACCT_JUMP_ACCEPT;
+       else if (counter->intend == NFACCT_BLOCK)
+               return NFACCT_JUMP_REJECT;
+       else if (counter->intend == NFACCT_ALLOW)
+               return NFACCT_JUMP_ACCEPT;
+       else if (counter->intend == NFACCT_TETH_BLOCK)
+               return NFACCT_JUMP_REJECT;
+       else if (counter->intend == NFACCT_TETH_ALLOW)
+               return NFACCT_JUMP_ACCEPT;
+
+       return NFACCT_JUMP_UNKNOWN;
+}
+
+stc_error_e stc_monitor_ipt_add_in(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_INSERT;
+       counter->iotype = NFACCT_COUNTER_IN;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ipt_add_out(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_INSERT;
+       counter->iotype = NFACCT_COUNTER_OUT;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ipt_del_in(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_DELETE;
+       counter->iotype = NFACCT_COUNTER_IN;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ipt_del_out(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_DELETE;
+       counter->iotype = NFACCT_COUNTER_OUT;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ip6t_add_in(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_INSERT;
+       counter->iotype = NFACCT_COUNTER_IN;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV6;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ip6t_add_out(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_INSERT;
+       counter->iotype = NFACCT_COUNTER_OUT;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV6;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ip6t_del_in(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_DELETE;
+       counter->iotype = NFACCT_COUNTER_IN;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV6;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_ip6t_del_out(struct nfacct_rule *counter)
+{
+       if (counter == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_DELETE;
+       counter->iotype = NFACCT_COUNTER_OUT;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV6;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+
+       return produce_net_rule(counter);
+}
+
+stc_error_e stc_monitor_tether_add_in(struct nfacct_rule *counter,
+               const gchar *ipaddr)
+{
+       int ret;
+
+       if (counter == NULL || ipaddr == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_INSERT;
+       counter->iotype = NFACCT_COUNTER_IN;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
+       counter->src_ip1 = g_strdup(ipaddr);
+
+       ret = produce_net_rule(counter);
+
+       FREE(counter->src_ip1);
+       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
+       return ret;
+}
+
+stc_error_e stc_monitor_tether_add_out(struct nfacct_rule *counter,
+               const gchar *ipaddr)
+{
+       int ret;
+
+       if (counter == NULL || ipaddr == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_INSERT;
+       counter->iotype = NFACCT_COUNTER_OUT;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
+       counter->dst_ip1 = g_strdup(ipaddr);
+
+       ret = produce_net_rule(counter);
+
+       FREE(counter->dst_ip1);
+       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
+       return ret;
+}
+
+stc_error_e stc_monitor_tether_del_in(struct nfacct_rule *counter,
+               const gchar *ipaddr)
+{
+       int ret;
+
+       if (counter == NULL || ipaddr == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_DELETE;
+       counter->iotype = NFACCT_COUNTER_IN;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
+       counter->src_ip1 = g_strdup(ipaddr);
+
+       ret = produce_net_rule(counter);
+
+       FREE(counter->src_ip1);
+       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
+       return ret;
+}
+
+stc_error_e stc_monitor_tether_del_out(struct nfacct_rule *counter,
+               const gchar *ipaddr)
+{
+       int ret;
+
+       if (counter == NULL || ipaddr == NULL)
+               return STC_ERROR_INVALID_PARAMETER;
+
+       counter->action = NFACCT_ACTION_DELETE;
+       counter->iotype = NFACCT_COUNTER_OUT;
+       counter->jump = __get_jump_by_intend(counter);
+       counter->iptype = NFACCT_TYPE_IPV4;
+       counter->send_limit = 0;
+       counter->rcv_limit = 0;
+       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
+       counter->dst_ip1 = g_strdup(ipaddr);
+
+       ret = produce_net_rule(counter);
+
+       FREE(counter->dst_ip1);
+       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
+       return ret;
+}
diff --git a/plugin/monitor/stc-plugin-monitor-proc.c b/plugin/monitor/stc-plugin-monitor-proc.c
new file mode 100755 (executable)
index 0000000..12cfe65
--- /dev/null
@@ -0,0 +1,310 @@
+/*
+ * 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.
+ */
+
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-monitor-proc.h"
+#include "stc-plugin-monitor-connection.h"
+#include "helper-net-cls.h"
+
+static void __print_proc(gpointer key, gpointer value,
+                               gpointer data)
+{
+       stc_proc_value_s *proc_value = (stc_proc_value_s *)value;
+
+       STC_LOGD("pid[\033[1;33m%d\033[0;m] ground[%d]",
+                proc_value->pid, proc_value->ground);
+}
+
+static void __print_proc_all(GHashTable *procs)
+{
+       g_hash_table_foreach(procs, __print_proc, NULL);
+}
+
+static void __proc_remove_pid(gpointer key, gpointer value,
+                               gpointer data)
+{
+       stc_app_value_s *app_value = (stc_app_value_s *)value;
+       remove_pid_context_s *context = (remove_pid_context_s *)data;
+
+       if (!g_hash_table_remove(app_value->processes, GUINT_TO_POINTER(context->pid)))
+               return;
+
+       if (STC_STAT_LOG) {
+               __print_proc_all(app_value->processes);
+               STC_LOGD("\033[1;31mProcess removed\033[0;m "
+                       "[\033[1;33m%d\033[0;m]", context->pid);
+       }
+
+       context->entry_removed = TRUE;
+       context->app_value = app_value;
+}
+
+static void __proc_move_pid(gpointer key, gpointer value,
+                               gpointer data)
+{
+       stc_proc_value_s *from_value = (stc_proc_value_s *)value;
+       stc_app_value_s *to_app_value = (stc_app_value_s *)data;
+       stc_proc_value_s *to_value;
+
+       to_value = MALLOC0(stc_proc_value_s, 1);
+       if (!to_value)
+               return;
+
+       to_value->pid = from_value->pid;
+       to_value->ground = to_app_value->state;
+
+       g_hash_table_insert(to_app_value->processes,
+                       GUINT_TO_POINTER(to_value->pid),
+                       to_value);
+
+       /* add pid to application cgroup */
+       place_pids_to_net_cgroup(to_value->pid, to_app_value->app_id);
+}
+
+API stc_error_e stc_plugin_monitor_proc_update_ground(uint32_t classid,
+                                               const char *app_id,
+                                               const stc_proc_value_s value)
+{
+       stc_error_e ret = STC_ERROR_NONE;
+       stc_app_value_s *app_lookup;
+       stc_proc_value_s *proc_lookup;
+       GHashTable *apps = stc_monitor_get_system_apps();
+
+       if (!apps)
+               return STC_ERROR_NO_DATA;
+
+       if (classid == STC_UNKNOWN_CLASSID)
+               classid = get_classid_by_app_id(app_id, TRUE);
+
+       app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+       if (!app_lookup) {
+               if (STC_STAT_LOG)
+                       STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid);
+               return STC_ERROR_NO_DATA;
+       }
+
+       proc_lookup = g_hash_table_lookup(app_lookup->processes,
+                                       GUINT_TO_POINTER(value.pid));
+       if (!proc_lookup) {
+               if (STC_STAT_LOG)
+                       STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", value.pid);
+               return STC_ERROR_NO_DATA;
+       }
+
+       if (proc_lookup->ground != value.ground)
+               proc_lookup->ground = value.ground;
+
+       place_pids_to_net_cgroup(value.pid, app_id);
+
+       return ret;
+}
+
+API stc_error_e stc_plugin_monitor_proc_add(uint32_t classid,
+                                       const char *app_id,
+                                       const stc_proc_value_s value)
+{
+       stc_error_e ret = STC_ERROR_NONE;
+       stc_app_value_s *app_lookup;
+       stc_proc_value_s *proc_lookup;
+       stc_proc_value_s *proc_value;
+       GHashTable *apps = stc_monitor_get_system_apps();
+
+       if (!apps)
+               return STC_ERROR_NO_DATA;
+
+       if (classid == STC_UNKNOWN_CLASSID)
+               classid = get_classid_by_app_id(app_id, TRUE);
+
+       app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+       if (!app_lookup) {
+               if (STC_STAT_LOG)
+                       STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid);
+               return STC_ERROR_NO_DATA;
+       }
+
+       proc_lookup = g_hash_table_lookup(app_lookup->processes,
+                                       GUINT_TO_POINTER(value.pid));
+       if (proc_lookup) {
+               if (STC_STAT_LOG)
+                       STC_LOGE("Already exists [\033[1;36m%d\033[0;m]", value.pid);
+               return STC_ERROR_NONE;
+       }
+
+       proc_value = MALLOC0(stc_proc_value_s, 1);
+       if (!proc_value) {
+               if (STC_STAT_LOG)
+                       STC_LOGE("Value allocation failed");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
+
+       proc_value->pid = value.pid;
+       proc_value->ground = value.ground;
+
+       g_hash_table_insert(app_lookup->processes,
+                       GUINT_TO_POINTER(proc_value->pid),
+                       proc_value);
+
+       /* add pid to application cgroup */
+       place_pids_to_net_cgroup(proc_value->pid, app_id);
+
+       if (STC_STAT_LOG) {
+               __print_proc_all(app_lookup->processes);
+               STC_LOGD("\033[1;32mProcess added\033[0;m "
+                       "[\033[1;33m%d\033[0;m]", proc_value->pid);
+       }
+
+       return ret;
+}
+
+API stc_error_e stc_plugin_monitor_proc_remove(uint32_t classid, pid_t pid)
+{
+       stc_error_e ret = STC_ERROR_NONE;
+       stc_app_value_s *app_lookup = NULL;
+       guint pid_count = 0;
+       GHashTable *apps = stc_monitor_get_system_apps();
+       GSList *conn_list = stc_get_connection_list();
+       remove_pid_context_s context = {
+               .pid = pid,
+               .app_value = NULL,
+               .entry_removed = FALSE,
+       };
+
+       if (!apps)
+               return STC_ERROR_NO_DATA;
+
+       if (classid == STC_UNKNOWN_CLASSID) {
+               g_hash_table_foreach(apps, __proc_remove_pid, &context);
+
+               if (context.entry_removed)
+                       app_lookup = context.app_value;
+
+               if (!app_lookup) {
+                       if (STC_STAT_LOG)
+                               STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", pid);
+                       return STC_ERROR_NO_DATA;
+               }
+       } else {
+               app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
+               if (!app_lookup) {
+                       if (STC_STAT_LOG)
+                               STC_LOGD("Application not found [\033[1;36m%d\033[0;m]",
+                                                       classid);
+                       return STC_ERROR_NO_DATA;
+               }
+
+               if (g_hash_table_remove(app_lookup->processes, GUINT_TO_POINTER(pid))) {
+                       if (STC_STAT_LOG) {
+                               __print_proc_all(app_lookup->processes);
+                               STC_LOGD("\033[1;31mProcess removed\033[0;m "
+                                       "[\033[1;33m%d\033[0;m]", pid);
+                       }
+               } else {
+                       STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", pid);
+               }
+       }
+
+       pid_count = g_hash_table_size(app_lookup->processes);
+
+       if (!pid_count) {
+               for (; conn_list != NULL; conn_list = conn_list->next) {
+                       stc_connection_s *conn = conn_list->data;
+                       /* remove nfacct rule for this classid */
+                       stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
+                                               app_lookup, conn);
+
+                       if (app_lookup->state == STC_APP_STATE_FOREGROUND)
+                               stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
+                                               app_lookup, conn);
+               }
+
+               stc_monitor_rstn_remove_for_app(classid);
+
+               g_hash_table_remove(apps, GUINT_TO_POINTER(classid));
+
+               if (STC_STAT_LOG)
+                       STC_LOGD("\033[1;31mApplication removed\033[0;m "
+                               "[\033[1;36m%d\033[0;m]", classid);
+       }
+
+       return ret;
+}
+
+API stc_error_e stc_plugin_monitor_proc_move(uint32_t from, uint32_t to)
+{
+       stc_error_e ret = STC_ERROR_NONE;
+       stc_app_value_s *from_lookup = NULL;
+       stc_app_value_s *to_lookup = NULL;
+       GSList *conn_list = stc_get_connection_list();
+       GHashTable *apps = stc_monitor_get_system_apps();
+
+       if (!apps)
+               return STC_ERROR_NO_DATA;
+
+       if (from != STC_UNKNOWN_CLASSID &&
+               to != STC_UNKNOWN_CLASSID) {
+               from_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(from));
+               if (!from_lookup) {
+                       if (STC_STAT_LOG)
+                               STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", from);
+                       return STC_ERROR_NO_DATA;
+               }
+
+               to_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(to));
+               if (!to_lookup) {
+                       if (STC_STAT_LOG)
+                               STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", to);
+                       return STC_ERROR_NO_DATA;
+               }
+
+               g_hash_table_foreach(from_lookup->processes,
+                               __proc_move_pid, to_lookup);
+
+               if (STC_STAT_LOG) {
+                       __print_proc_all(to_lookup->processes);
+                       STC_LOGD("\033[1;34mProcesses moved\033[0;m "
+                               "[\033[1;36m%d\033[0;m] -> [\033[1;36m%d\033[0;m]",
+                               from, to);
+               }
+
+               g_hash_table_remove_all(from_lookup->processes);
+
+               if (STC_STAT_LOG) {
+                       __print_proc_all(from_lookup->processes);
+                       STC_LOGD("\033[1;31mProcesses removed\033[0;m "
+                               "[\033[1;36m%d\033[0;m]", from);
+               }
+
+               for (; conn_list != NULL; conn_list = conn_list->next) {
+                       stc_connection_s *conn = conn_list->data;
+                       stc_monitor_app_remove_monitor(GUINT_TO_POINTER(from),
+                                               from_lookup, conn);
+
+                       if (from_lookup->state == STC_APP_STATE_FOREGROUND)
+                               stc_monitor_app_remove_accept(GUINT_TO_POINTER(from),
+                                               from_lookup, conn);
+               }
+
+               stc_monitor_rstn_remove_for_app(from);
+
+               g_hash_table_remove(apps, GUINT_TO_POINTER(from));
+
+               if (STC_STAT_LOG)
+                       STC_LOGD("\033[1;31mApplication removed\033[0;m "
+                               "[\033[1;36m%d\033[0;m]", from);
+       }
+
+       return ret;
+}
diff --git a/plugin/monitor/stc-plugin-monitor-rstn.c b/plugin/monitor/stc-plugin-monitor-rstn.c
new file mode 100755 (executable)
index 0000000..75bc4e5
--- /dev/null
@@ -0,0 +1,1465 @@
+/*
+ * 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.
+ */
+
+#include <vconf.h>
+#include <vconf-keys.h>
+
+#include "counter.h"
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-monitor-rstn.h"
+#include "stc-plugin-monitor-ipt.h"
+#include "stc-plugin-monitor-time.h"
+#include "table-counters.h"
+#include "table-restrictions.h"
+#include "table-statistics.h"
+#include "helper-net-cls.h"
+#include "stc-manager-plugin-appstatus.h"
+#include "stc-manager-plugin-tether.h"
+
+static void __print_rstn(stc_rstn_data_s *rstn_data)
+{
+       STC_LOGI("RstnID[%llu] AppID[%s] classid[%u] "
+               "iftype[%d] ifname[%s] rstn_state[%d] "
+               "rstn_type[%d] roaming[%d] subscriber_id[%s]",
+                rstn_data->restriction_id,
+                rstn_data->app_id, rstn_data->classid,
+                rstn_data->iftype, rstn_data->ifname,
+                rstn_data->rstn_state, rstn_data->rstn_type,
+                rstn_data->roaming, rstn_data->subscriber_id);
+       STC_LOGI("month_start_date[%d] limit[%lld] "
+               "warn_limit[%lld] monthly_limit[%lld] "
+               "weekly_limit[%lld] daily_limit[%lld] ",
+               rstn_data->month_start_date,
+               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA],
+               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN],
+               rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY],
+               rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY],
+               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY]);
+       STC_LOGI("data_counter[%lld] warn_counter[%lld] "
+               "monthly_counter[%lld] weekly_counter[%lld] "
+               "daily_counter[%lld]",
+               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA],
+               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN],
+               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY],
+               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY],
+               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY]);
+}
+
+static int __vconf_get_int(const char *key, int *value)
+{
+       int ret = 0;
+
+       ret = vconf_get_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to get vconfkey [%s] value", key);
+               return -1;
+       }
+
+       return 0;
+}
+
+static int __vconf_set_int(const char *key, int value)
+{
+       int ret = 0;
+
+       ret = vconf_set_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to set vconfkey [%s] value", key);
+               return -1;
+       }
+
+       return 0;
+}
+
+static stc_cb_ret_e __statistics_info_cb(const table_statistics_info *info,
+                                       void *user_data)
+{
+       stc_rstn_cumulative_data_s *stat = (stc_rstn_cumulative_data_s *)user_data;
+       int64_t counters = 0;
+
+       counters = info->cnt.in_bytes + info->cnt.out_bytes;
+
+       stat->monthly_stat += counters;
+       if (stat->week_start_ts <= info->interval->from)
+               stat->weekly_stat += counters;
+       if (stat->day_start_ts <= info->interval->from)
+               stat->daily_stat += counters;
+
+       return STC_CONTINUE;
+}
+
+static void __rstn_add_tether_rule(int64_t classid, gchar *mac,
+               nfacct_rule_intend intend, stc_iface_type_e iftype)
+{
+       GSList *conn_list = stc_get_connection_list();
+       struct nfacct_rule counter;
+       stc_s *stc = stc_get_manager();
+       char *ipaddr = NULL;
+       int ret;
+
+       if (!stc || !mac)
+               return;
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = classid;
+               counter.intend = intend;
+
+               if (conn->tether_state != TRUE ||
+                       conn->tether_iface.ifname == NULL)
+                       return;
+
+               counter.iftype = conn->tether_iface.type;
+               g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+
+               /* get connected station ip based on its mac */
+               ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
+               if (ret != STC_ERROR_NONE)
+                       return;
+
+               /* tethering iptables rule */
+               stc_monitor_tether_add_in(&counter, ipaddr);
+               stc_monitor_tether_add_out(&counter, ipaddr);
+               g_free(ipaddr);
+       }
+}
+
+static void __rstn_del_tether_rule(int64_t classid, gchar *mac,
+               nfacct_rule_intend intend, stc_iface_type_e iftype)
+{
+       GSList *conn_list = stc_get_connection_list();
+       struct nfacct_rule counter;
+       stc_s *stc = stc_get_manager();
+       char *ipaddr = NULL;
+       int ret;
+
+       if (!stc || !mac)
+               return;
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = classid;
+               counter.intend = intend;
+
+               if (conn->tether_state != TRUE ||
+                       conn->tether_iface.ifname == NULL)
+                       return;
+
+               counter.iftype = conn->tether_iface.type;
+               g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+
+               /* get connected station ip based on its mac */
+               ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
+               if (ret != STC_ERROR_NONE) {
+                       STC_LOGE("Error: no IP found for station mac(%s)", mac);
+                       return;
+               }
+
+               /* tethering iptables rule */
+               stc_monitor_tether_del_in(&counter, ipaddr);
+               stc_monitor_tether_del_out(&counter, ipaddr);
+               g_free(ipaddr);
+       }
+}
+
+static void __rstn_add_ipt_rule(int64_t classid, nfacct_rule_intend intend,
+                               stc_iface_type_e iftype)
+{
+       GSList *conn_list = stc_get_connection_list();
+       struct nfacct_rule counter;
+       stc_s *stc = stc_get_manager();
+
+       if (!stc)
+               return;
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+
+               if (conn == NULL)
+                       return;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = classid;
+               counter.intend = intend;
+
+               if (conn && conn->tether_iface.ifname != NULL &&
+                       classid == STC_TETHERING_APP_CLASSID) {
+                       counter.iftype = conn->tether_iface.type;
+                       g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+               } else {
+                       counter.iftype = iftype;
+                       g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
+               }
+
+               /* iptables rule */
+               stc_monitor_ipt_add_in(&counter);
+               stc_monitor_ipt_add_out(&counter);
+
+               /* ip6tables rule */
+               stc_monitor_ip6t_add_in(&counter);
+               stc_monitor_ip6t_add_out(&counter);
+       }
+}
+
+static void __rstn_del_ipt_rule(int64_t classid, nfacct_rule_intend intend,
+                               stc_iface_type_e iftype)
+{
+       GSList *conn_list = stc_get_connection_list();
+       struct nfacct_rule counter;
+       stc_s *stc = stc_get_manager();
+
+       if (!stc)
+               return;
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+
+               if (conn == NULL)
+                       return;
+
+               if (!stc->carg) {
+                       stc->carg = MALLOC0(counter_arg_s, 1);
+                       if (stc->carg == NULL)
+                               return;
+
+                       stc->carg->sock = stc_monitor_get_contr_sock();
+               }
+
+               memset(&counter, 0, sizeof(struct nfacct_rule));
+
+               counter.carg = stc->carg;
+               counter.classid = classid;
+               counter.intend = intend;
+
+               if (conn && conn->tether_iface.ifname != NULL &&
+                       classid == STC_TETHERING_APP_CLASSID) {
+                       counter.iftype = conn->tether_iface.type;
+                       g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
+               } else {
+                       counter.iftype = iftype;
+                       g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
+               }
+
+               /* iptables rule */
+               stc_monitor_ipt_del_in(&counter);
+               stc_monitor_ipt_del_out(&counter);
+
+               /* ip6tables rule */
+               stc_monitor_ip6t_del_in(&counter);
+               stc_monitor_ip6t_del_out(&counter);
+       }
+}
+
+static void __rstn_set_noti_state(int value)
+{
+       int state = STC_RSTN_STATE_INIT;
+
+       if (__vconf_get_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, &state))
+               return;
+
+       if (state == value) {
+               STC_LOGI("No need to change a restriction status: %d", state);
+               return;
+       }
+
+       __vconf_set_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, value);
+}
+
+static void __rstn_tethering_process(enum traffic_restriction_type rstn_type,
+                               char *app_id, stc_rstn_data_s *rstn_data, void *data)
+{
+       stc_connection_s *old_connection = (stc_connection_s *)data;
+       stc_connection_s *connection = NULL;
+       char *mac_str = NULL;
+
+       if (old_connection != NULL) {
+               connection = old_connection;
+               if (connection->tether_state == FALSE)
+                       return;
+
+               /* rstn not applicable for this interface */
+               if (rstn_data->ifname != NULL &&
+                       g_strcmp0("", rstn_data->ifname) != 0 &&
+                       g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0)
+                       return;
+       } else {
+               GSList *conn_list = stc_get_connection_list();
+               for (; conn_list != NULL; conn_list = conn_list->next) {
+                       stc_connection_s *conn = conn_list->data;
+                       if (conn->tether_state == FALSE)
+                               continue;
+
+                       if (rstn_data->ifname != NULL &&
+                               g_strcmp0(rstn_data->ifname, "") != 0 &&
+                               g_strcmp0(conn->tether_iface.ifname, rstn_data->ifname) == 0)
+                               connection = conn;
+               }
+
+               if (connection == NULL)
+                       return;
+       }
+
+       /* in case appid not a tethering app */
+       if (!g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX))
+               return;
+
+       /* Ignore TOTAL_TETHERING,
+        * Process only station appids */
+       if (rstn_data->classid == STC_TETHERING_APP_CLASSID)
+               return;
+
+       /* get the station mac based on classid */
+       stc_plugin_tether_get_station_by_classid(rstn_data->classid, &mac_str);
+       if (!mac_str) {
+               STC_LOGE("Station not found for classid(%d)", rstn_data->classid);
+               return;
+       }
+
+       switch (rstn_type) {
+       case RST_SET:
+       {
+               int i;
+               table_counters_info info;
+               int64_t effective_limit[STC_RSTN_LIMIT_TYPE_MAX] = { 0, };
+
+                       memset(&info, 0, sizeof(table_counters_info));
+                       rstn_data->limit_exceeded = 0;
+
+                       if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
+                                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
+                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
+                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
+                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
+                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
+                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
+                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
+                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
+                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
+                               table_counters_get(rstn_data->restriction_id, &info);
+
+                               time_t current_time = 0;
+                               stc_rstn_cumulative_data_s stat;
+                               table_statistics_select_rule rule;
+                               time_t last_week_ts = stc_monitor_get_last_week_ts();
+                               time_t last_day_ts = stc_monitor_get_last_day_ts();
+
+                               memset(&stat, 0, sizeof(stc_rstn_cumulative_data_s));
+                               stat.month_start_ts = rstn_data->month_start_ts;
+                               stat.week_start_ts = last_week_ts;
+                               stat.day_start_ts = last_day_ts;
+
+                               memset(&rule, 0, sizeof(table_statistics_select_rule));
+                               rule.from = rstn_data->month_start_ts;
+                               time(&current_time);
+                               rule.to = current_time;
+                               rule.iftype = rstn_data->iftype;
+                               rule.granularity = GRANULARITY;
+
+                               table_statistics_per_app(app_id, &rule, __statistics_info_cb, &stat);
+
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter + stat.monthly_stat;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter + stat.weekly_stat;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter + stat.daily_stat;
+                       }
+
+                       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
+                               if (rstn_data->limit[i] >= 0) {
+                                       effective_limit[i] = rstn_data->limit[i] - rstn_data->counter[i];
+
+                                       if (effective_limit[i] < 0)
+                                               rstn_data->limit_exceeded |= (1 << i);
+                               }
+                       }
+
+                       STC_LOGD("Rstn_id[%llu] datausage[%lld]bytes",
+                                       rstn_data->restriction_id, info.data_counter);
+
+                       if (rstn_data->limit_exceeded != 0 &&
+                                       rstn_data->limit_exceeded != (1 << STC_RSTN_LIMIT_TYPE_DATA_WARN)) {
+                               __rstn_add_tether_rule(rstn_data->classid, mac_str,
+                                               NFACCT_TETH_BLOCK, rstn_data->iftype);
+                       }
+
+                       rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
+       }
+       break;
+       case RST_EXCLUDE:
+       {
+               __rstn_add_tether_rule(rstn_data->classid, mac_str,
+                                       NFACCT_TETH_ALLOW, rstn_data->iftype);
+
+                       rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
+                       rstn_data->limit_exceeded = 0;
+                       rstn_data->limit_notified = 0;
+       }
+       break;
+       case RST_UNSET:
+       {
+                       int i;
+                       __rstn_del_tether_rule(rstn_data->classid, mac_str,
+                                       NFACCT_TETH_BLOCK, rstn_data->iftype);
+
+                       rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
+                       rstn_data->limit_exceeded = 0;
+                       rstn_data->limit_notified = 0;
+
+                       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++)
+                               if (rstn_data->limit[i] >= 0)
+                                       rstn_data->counter[i] = 0;
+       }
+       break;
+       default:
+               break;
+       }
+       FREE(mac_str);
+}
+
+static void __rstn_process(enum traffic_restriction_type rstn_type,
+                                 char *app_id, stc_rstn_data_s *rstn_data, void *data)
+{
+       stc_connection_s *old_connection = (stc_connection_s *)data;
+       stc_connection_s *connection = NULL;
+
+       if (old_connection != NULL) {
+               connection = old_connection;
+               if (connection->ifname == NULL)
+                       return;
+
+               /* rstn not applicable for this interface */
+               if (rstn_data->ifname != NULL &&
+                       g_strcmp0(rstn_data->ifname, "") != 0 &&
+                   g_strcmp0(connection->ifname, rstn_data->ifname) != 0 &&
+                   g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0)
+                   return;
+       } else {
+               GSList *conn_list = stc_get_connection_list();
+               for (; conn_list != NULL; conn_list = conn_list->next) {
+                       stc_connection_s *conn = conn_list->data;
+                       if (conn == NULL || conn->ifname == NULL)
+                               continue;
+
+                       if (rstn_data->ifname != NULL &&
+                               g_strcmp0(rstn_data->ifname, "") != 0 &&
+                               g_strcmp0(conn->ifname, rstn_data->ifname) == 0 &&
+                               g_strcmp0(conn->tether_iface.ifname, rstn_data->ifname) == 0)
+                               connection = conn;
+               }
+
+               if (connection == NULL)
+                       return;
+       }
+
+       /* classid is invalid */
+       if (rstn_data->classid <= STC_UNKNOWN_CLASSID)
+               return;
+
+       /* Do not proceed for tethering station appid if found here,
+        * for tethering station apps __rstn_tethering_process() call
+        * will handle it */
+       if (g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX) &&
+                       rstn_data->classid != STC_TETHERING_APP_CLASSID)
+               return;
+
+       switch (rstn_type) {
+       case RST_SET:
+       {
+               int i;
+               table_counters_info info;
+               int64_t effective_limit[STC_RSTN_LIMIT_TYPE_MAX] = { 0, };
+
+               memset(&info, 0, sizeof(table_counters_info));
+               rstn_data->limit_exceeded = 0;
+
+               if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
+                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
+                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
+                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
+                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
+                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
+                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
+                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
+                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
+                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
+                       table_counters_get(rstn_data->restriction_id, &info);
+
+                       time_t current_time = 0;
+                       stc_rstn_cumulative_data_s stat;
+                       table_statistics_select_rule rule;
+                       time_t last_week_ts = stc_monitor_get_last_week_ts();
+                       time_t last_day_ts = stc_monitor_get_last_day_ts();
+
+                       memset(&stat, 0, sizeof(stc_rstn_cumulative_data_s));
+                       stat.month_start_ts = rstn_data->month_start_ts;
+                       stat.week_start_ts = last_week_ts;
+                       stat.day_start_ts = last_day_ts;
+
+                       memset(&rule, 0, sizeof(table_statistics_select_rule));
+                       rule.from = rstn_data->month_start_ts;
+                       time(&current_time);
+                       rule.to = current_time;
+                       rule.iftype = rstn_data->iftype;
+                       rule.granularity = GRANULARITY;
+
+                       table_statistics_per_app(rstn_data->app_id, &rule, __statistics_info_cb, &stat);
+
+                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
+                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
+                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter + stat.monthly_stat;
+                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter + stat.weekly_stat;
+                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter + stat.daily_stat;
+
+                       if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                               STC_LOGD("Rstn counter data[%lld] warn[%lld] "
+                               "monthly[%lld] weekly[%lld] daily[%lld]",
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA],
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN],
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY],
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY],
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY]);
+               }
+
+               for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
+                       if (rstn_data->limit[i] >= 0) {
+                               effective_limit[i] = rstn_data->limit[i] - rstn_data->counter[i];
+
+                               if (effective_limit[i] < 0)
+                                       rstn_data->limit_exceeded |= (1 << i);
+                       }
+               }
+
+               STC_LOGD("Rstn_id[%llu] limit[%lld] datausage[%lld]",
+                                       rstn_data->restriction_id,
+                                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA],
+                                       info.data_counter);
+
+               if (rstn_data->limit_exceeded != 0 &&
+                       rstn_data->limit_exceeded != (1 << STC_RSTN_LIMIT_TYPE_DATA_WARN)) {
+                       __rstn_add_ipt_rule(rstn_data->classid, NFACCT_BLOCK, rstn_data->iftype);
+               }
+
+               if (rstn_data->classid == STC_BACKGROUND_APP_CLASSID)
+                       __rstn_add_ipt_rule(rstn_data->classid, NFACCT_BLOCK, rstn_data->iftype);
+
+               rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
+
+               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
+                       STC_LOGD("Restriction activated "
+                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                               rstn_data->classid, rstn_data->restriction_id);
+               }
+       }
+       break;
+       case RST_EXCLUDE:
+               __rstn_add_ipt_rule(rstn_data->classid, NFACCT_ALLOW,
+                                   rstn_data->iftype);
+
+               rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
+               rstn_data->limit_exceeded = 0;
+               rstn_data->limit_notified = 0;
+
+               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
+                       STC_LOGD("Restriction activated "
+                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                               rstn_data->classid, rstn_data->restriction_id);
+               }
+               break;
+       case RST_UNSET:
+       {
+               int i;
+
+               if (rstn_data->classid == STC_TETHERING_APP_CLASSID)
+                       __rstn_del_ipt_rule(rstn_data->classid, NFACCT_BLOCK,
+                                           rstn_data->iftype);
+               else
+                       __rstn_del_ipt_rule(rstn_data->classid, rstn_data->rstn_type,
+                                           rstn_data->iftype);
+
+               rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
+               rstn_data->limit_exceeded = 0;
+               rstn_data->limit_notified = 0;
+
+               for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++)
+                       if (rstn_data->limit[i] >= 0)
+                               rstn_data->counter[i] = 0;
+
+               __rstn_set_noti_state(STC_RSTN_STATE_UNSET);
+
+               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
+                       STC_LOGD("Restriction deactivated "
+                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                               rstn_data->classid, rstn_data->restriction_id);
+               }
+       }
+       break;
+       default:
+               break;
+       }
+}
+
+static void __rstn_add(gpointer data, gpointer user_data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+
+       /* rstn rule is activated */
+       if (rstn_data->rstn_state == STC_RSTN_STATE_ACTIVATED) {
+               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
+                       STC_LOGD("Restriction already activated "
+                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                               rstn_data->classid, rstn_data->restriction_id);
+               }
+               return;
+       }
+
+       if (rstn_data->rstn_type == STC_RSTN_TYPE_ACCEPT) {
+               __rstn_process(RST_EXCLUDE,
+                       rstn_data->app_id, rstn_data, user_data);
+               __rstn_tethering_process(RST_EXCLUDE,
+                       rstn_data->app_id, rstn_data, user_data);
+       } else {
+               __rstn_process(RST_SET,
+                       rstn_data->app_id, rstn_data, user_data);
+               __rstn_tethering_process(RST_SET,
+                       rstn_data->app_id, rstn_data, user_data);
+       }
+
+       if (STC_DEBUG_LOG && STC_RSTN_LOG) {
+               __print_rstn(rstn_data);
+               STC_LOGD("\033[1;32mRestriction added\033[0;m "
+                       "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                       rstn_data->classid, rstn_data->restriction_id);
+       }
+}
+
+static void __rstn_add_by_connection(gpointer key,
+                                       gpointer value, gpointer data)
+{
+       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
+
+       g_slist_foreach(rstn_value->rules, __rstn_add, data);
+}
+
+static void __rstn_remove(gpointer data, gpointer user_data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+
+       if (rstn_data->rstn_state == STC_RSTN_STATE_DEACTIVATED) {
+               STC_LOGD("\033[1;31mRestriction already deactivated\033[0;m "
+                       "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                       rstn_data->classid, rstn_data->restriction_id);
+               return;
+       }
+
+       __rstn_process(RST_UNSET,
+               rstn_data->app_id, rstn_data, user_data);
+       __rstn_tethering_process(RST_UNSET,
+               rstn_data->app_id, rstn_data, user_data);
+
+       if (STC_DEBUG_LOG && STC_RSTN_LOG) {
+               __print_rstn(rstn_data);
+               STC_LOGD("\033[1;31mRestriction removed\033[0;m "
+                       "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
+                       rstn_data->classid, rstn_data->restriction_id);
+       }
+}
+
+static void __rstn_remove_by_connection(gpointer key,
+                                       gpointer value, gpointer data)
+{
+       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
+
+       g_slist_foreach(rstn_value->rules, __rstn_remove, data);
+}
+
+static void __rstn_update_counter_data(gpointer data,
+                                               gpointer user_data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+
+       table_counters_info info = {
+               .restriction_id = rstn_data->restriction_id,
+               .data_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA],
+               .warn_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN],
+               .monthly_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY],
+               .weekly_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY],
+               .daily_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY]
+       };
+
+       table_counters_update_counters(&info);
+}
+
+static void __rstn_update_counter_value(gpointer key,
+                                               gpointer value, gpointer data)
+{
+       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
+
+       g_slist_foreach(rstn_value->rules, __rstn_update_counter_data, NULL);
+}
+
+static void __rstn_data_destroy(gpointer data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+
+       FREE(rstn_data->app_id);
+       FREE(rstn_data->ifname);
+       FREE(rstn_data->subscriber_id);
+       FREE(rstn_data->mac);
+
+       FREE(rstn_data);
+}
+
+static gint __rstn_data_comp(gconstpointer a, gconstpointer b)
+{
+       stc_rstn_data_s *da = (stc_rstn_data_s *)a;
+       stc_rstn_data_s *db = (stc_rstn_data_s *)b;
+
+       if ((da->iftype == db->iftype) &&
+               (g_strcmp0(da->ifname, db->ifname) == 0) &&
+               (g_strcmp0(da->subscriber_id, db->subscriber_id) == 0) &&
+               (da->roaming == db->roaming))
+               return 0;
+
+       return -1;
+}
+
+static stc_error_e __rstn_data_remove(stc_rstn_data_s *data)
+{
+       stc_rstn_value_s *lookup_value;
+       GSList *lookup_list;
+       stc_rstn_data_s *lookup_data;
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return STC_ERROR_NO_DATA;
+
+       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(data->classid));
+       if (!lookup_value) {
+               if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                       STC_LOGE("Restriction not found [\033[1;36m%d\033[0;m]",
+                                               data->classid);
+               return STC_ERROR_NO_DATA;
+       }
+
+       lookup_list = g_slist_find_custom(lookup_value->rules,
+                                       data, __rstn_data_comp);
+       if (!lookup_list) {
+               if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                       STC_LOGE("Restriction not found [%d:%s:%s:%d]",
+                               data->iftype, data->ifname,
+                               data->subscriber_id, data->roaming);
+               return STC_ERROR_NO_DATA;
+       }
+
+       lookup_data = lookup_list->data;
+
+       /* remove counter also */
+       table_counters_delete(lookup_data->restriction_id);
+       __rstn_remove(lookup_data, NULL);
+
+       lookup_value->rules = g_slist_remove(lookup_value->rules,
+                                                       lookup_data);
+       __rstn_data_destroy(lookup_data);
+
+       if (!lookup_value->rules)
+               g_hash_table_remove(rstns, GUINT_TO_POINTER(data->classid));
+
+       return STC_ERROR_NONE;
+}
+
+static stc_error_e __rstn_data_add(stc_rstn_data_s *data)
+{
+       int i;
+       stc_rstn_value_s *lookup_value;
+       stc_rstn_value_s *rstn_value;
+       stc_rstn_data_s *rstn_data;
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return STC_ERROR_NO_DATA;
+
+       rstn_data = MALLOC0(stc_rstn_data_s, 1);
+       if (!rstn_data) {
+               if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                       STC_LOGE("Rstn_data allocation failed");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
+
+       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(data->classid));
+       if (!lookup_value) {
+               rstn_value = MALLOC0(stc_rstn_value_s, 1);
+               if (!rstn_value) {
+                       if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                               STC_LOGE("Rstn_value allocation failed");
+                       FREE(rstn_data);
+                       return STC_ERROR_OUT_OF_MEMORY;
+               }
+
+               g_hash_table_insert(rstns, GUINT_TO_POINTER(data->classid),
+                       rstn_value);
+       } else {
+               rstn_value = lookup_value;
+       }
+
+       rstn_data->classid = data->classid;
+       rstn_data->app_id = g_strdup(data->app_id);
+       rstn_data->iftype = data->iftype;
+       rstn_data->ifname = g_strdup(data->ifname);
+       rstn_data->subscriber_id = g_strdup(data->subscriber_id);
+       rstn_data->roaming = data->roaming;
+       rstn_data->mac = g_strdup(data->mac);
+
+       rstn_data->restriction_id = data->restriction_id;
+       rstn_data->rstn_state = data->rstn_state;
+       rstn_data->rstn_type = data->rstn_type;
+
+       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
+               rstn_data->limit[i] = data->limit[i];
+               rstn_data->counter[i] = 0;
+       }
+
+       rstn_data->limit_exceeded = 0;
+       rstn_data->limit_notified = 0;
+       rstn_data->month_start_date = data->month_start_date;
+       rstn_data->month_start_ts = data->month_start_ts;
+
+       __rstn_data_remove(rstn_data);
+       rstn_value->rules = g_slist_append(rstn_value->rules, rstn_data);
+
+       __rstn_add(rstn_data, NULL);
+
+       return STC_ERROR_NONE;
+}
+
+static void __rstn_value_destroy(gpointer data)
+{
+       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)data;
+
+       g_slist_free_full(rstn_value->rules, __rstn_data_destroy);
+
+       FREE(rstn_value);
+}
+
+static stc_cb_ret_e __rstn_insert_cb(const table_restrictions_info *info,
+                                           void *user_data)
+{
+       stc_cb_ret_e ret = STC_CONTINUE;
+       stc_rstn_data_s data;
+
+       memset(&data, 0, sizeof(stc_rstn_data_s));
+
+       if (info->app_id) {
+               data.classid = get_classid_by_app_id(info->app_id, TRUE);
+               data.app_id = info->app_id;
+       } else
+               data.classid = STC_UNKNOWN_CLASSID;
+
+       data.iftype = info->iftype;
+       data.ifname = info->ifname;
+       data.subscriber_id = info->subscriber_id;
+       data.roaming = info->roaming;
+
+       data.rstn_type = info->rstn_type;
+       data.rstn_state = STC_RSTN_STATE_UNKNOWN;
+       data.restriction_id = info->restriction_id;
+
+       data.limit[STC_RSTN_LIMIT_TYPE_DATA] = info->data_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info->data_warn_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_MONTHLY] = info->monthly_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_WEEKLY] = info->weekly_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_DAILY] = info->daily_limit;
+
+       if (__rstn_data_add(&data) != STC_ERROR_NONE)
+               ret = STC_CANCEL;
+
+       return ret;
+}
+
+static void __rstn_update_counter(classid_bytes_context_s *context,
+                               uint32_t classid)
+{
+       stc_rstn_value_s *lookup;
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return;
+
+       lookup = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
+       if (lookup) {
+               context->counter->classid = classid;
+               g_slist_foreach(lookup->rules,
+                       stc_monitor_rstn_update_counter,
+                       context);
+       }
+}
+
+static void __rstn_action_when_limit_exceeded_tethering(stc_rstn_data_s *rstn_data,
+                                       classid_bytes_context_s *context)
+{
+       char *mac_str = NULL;
+       struct nfacct_rule *counter = context->counter;
+
+       /* get the station mac based on classid */
+       stc_plugin_tether_get_station_by_classid(counter->classid, &mac_str);
+       if (!mac_str) {
+               STC_LOGE("Station not found for classid(%d)", counter->classid);
+               return;
+       }
+
+       STC_LOGI("Station mac[%s] classid[%u] iftype[%u] iotype[%d] "
+                       "intend[%d] ifname[%s] bytes[%lld]", mac_str,
+                       counter->classid, counter->iftype, counter->iotype,
+                       counter->intend, counter->ifname, context->bytes);
+
+       /* Block tethering station immediately */
+       counter->intend = NFACCT_TETH_BLOCK;
+       __rstn_del_tether_rule(counter->classid, mac_str,
+                       NFACCT_TETH_BLOCK, rstn_data->iftype);
+
+       __rstn_add_tether_rule(counter->classid, mac_str,
+                       NFACCT_TETH_BLOCK, rstn_data->iftype);
+       counter->intend = NFACCT_TETH_COUNTER;
+
+       g_free(mac_str);
+}
+
+static void __reset_time_counter_foreach_rstn_data(gpointer data,
+                                                 gpointer user_data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+       reset_time_limits_context_s *context =
+               (reset_time_limits_context_s *)user_data;
+       int i;
+       time_t now_month_start_ts;
+
+       if (rstn_data->month_start_date == 0) {
+               table_counters_info info;
+               memset(&info, 0, sizeof(table_counters_info));
+               table_counters_get_timestamps(rstn_data->restriction_id, &info);
+
+               if (info.month_start_date == 0)
+                       rstn_data->month_start_date = 1;
+               else
+                       rstn_data->month_start_date = info.month_start_date;
+               rstn_data->month_start_ts = info.month_start_ts;
+       }
+
+       now_month_start_ts =
+               stc_time_get_month_start(context->now,
+                                        rstn_data->month_start_date);
+
+       if (rstn_data->month_start_ts != now_month_start_ts) {
+               rstn_data->month_start_ts = now_month_start_ts;
+               context->month_start_ts = now_month_start_ts;
+               context->is_updated |= (1 << STC_RSTN_LIMIT_TYPE_MONTHLY);
+       }
+
+       if (context->is_updated) {
+               table_counters_info info;
+               memset(&info, 0, sizeof(table_counters_info));
+
+               info.restriction_id = rstn_data->restriction_id;
+               info.month_start_date = rstn_data->month_start_date;
+               info.month_start_ts = rstn_data->month_start_ts;
+               info.week_start_ts = context->week_start_ts;
+               info.day_start_ts = context->day_start_ts;
+
+               table_counters_update_timestamps(&info);
+       }
+
+       for (i = STC_RSTN_LIMIT_TYPE_MONTHLY; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
+
+               if ((context->is_updated) & (1 << i)) {
+                       /* reset limit */
+                       rstn_data->counter[i] = 0;
+
+                       if (rstn_data->limit_exceeded & (1 << i)) {
+                               /* remove iptables rule */
+                               GSList *conn_list = stc_get_connection_list();
+                               struct nfacct_rule counter;
+                               stc_s *stc = stc_get_manager();
+                               if (stc == NULL) {
+                                       STC_LOGE("Can't get stc data");
+                                       goto try_next_callback;
+                               }
+
+                               if (!stc->carg) {
+                                       stc->carg = MALLOC0(counter_arg_s, 1);
+                                       if (stc->carg == NULL) {
+                                               goto try_next_callback;
+                                       }
+
+                                       stc->carg->sock = stc_monitor_get_contr_sock();
+                               }
+
+                               for (; conn_list != NULL; conn_list = conn_list->next) {
+                                       stc_connection_s *conn = conn_list->data;
+
+                                       memset(&counter, 0, sizeof(struct nfacct_rule));
+
+                                       counter.carg = stc->carg;
+                                       counter.classid = rstn_data->classid;
+                                       counter.intend = NFACCT_BLOCK;
+                                       counter.iftype = rstn_data->iftype;
+                                       g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
+
+                                       /* iptables rule */
+                                       stc_monitor_ipt_del_in(&counter);
+                                       stc_monitor_ipt_del_out(&counter);
+
+                                       /* ip6tables rule */
+                                       stc_monitor_ip6t_del_in(&counter);
+                                       stc_monitor_ip6t_del_out(&counter);
+
+                                       rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
+                                       rstn_data->limit_exceeded &= ~(1 << i);
+                                       rstn_data->limit_notified &= ~(1 << i);
+                               }
+                       }
+               }
+       }
+
+try_next_callback:
+       return;
+}
+
+static void __reset_time_counter_foreach_rstn_value(gpointer key,
+                                                 gpointer value,
+                                                 gpointer data)
+{
+       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
+       g_slist_foreach(rstn_value->rules,
+               __reset_time_counter_foreach_rstn_data, data);
+}
+
+API stc_error_e stc_plugin_monitor_rstn_add(const table_restrictions_info *info)
+{
+       stc_rstn_data_s data;
+
+       memset(&data, 0, sizeof(stc_rstn_data_s));
+
+       if (info->app_id) {
+               data.classid = get_classid_by_app_id(info->app_id, TRUE);
+               data.app_id = info->app_id;
+       } else
+               data.classid = STC_UNKNOWN_CLASSID;
+
+       if (data.classid == STC_BACKGROUND_APP_CLASSID) {
+               stc_monitor_set_background_state(TRUE);
+               __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, TRUE);
+       }
+
+       data.iftype = info->iftype;
+       data.ifname = info->ifname;
+       data.subscriber_id = info->subscriber_id;
+       data.roaming = info->roaming;
+       data.mac = info->mac;
+
+       data.rstn_type = info->rstn_type;
+       data.rstn_state = STC_RSTN_STATE_UNKNOWN;
+       data.restriction_id = info->restriction_id;
+
+       data.limit[STC_RSTN_LIMIT_TYPE_DATA] = info->data_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info->data_warn_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_MONTHLY] = info->monthly_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_WEEKLY] = info->weekly_limit;
+       data.limit[STC_RSTN_LIMIT_TYPE_DAILY] = info->daily_limit;
+       data.month_start_date = info->month_start_date;
+       data.month_start_ts = stc_time_get_month_start(time(NULL),
+                                                                               info->month_start_date);
+
+       return __rstn_data_add(&data);
+}
+
+API stc_error_e stc_plugin_monitor_rstn_remove(const table_restrictions_info *info)
+{
+       stc_rstn_data_s data;
+
+       memset(&data, 0, sizeof(stc_rstn_data_s));
+
+       data.classid = get_classid_by_app_id(info->app_id, TRUE);
+       data.app_id = info->app_id;
+
+       data.iftype = info->iftype;
+       data.ifname = info->ifname;
+       data.subscriber_id = info->subscriber_id;
+       data.roaming = info->roaming;
+
+       if (g_strcmp0(info->app_id, STC_TOTAL_BACKGROUND) == 0) {
+               stc_monitor_set_background_state(FALSE);
+               __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, FALSE);
+       }
+
+       return __rstn_data_remove(&data);
+}
+
+void stc_monitor_rstn_reset_time_counters_if_required(void)
+{
+       reset_time_limits_context_s context;
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+       time_t last_week_ts = stc_monitor_get_last_week_ts();
+       time_t last_day_ts = stc_monitor_get_last_day_ts();
+
+       context.now = time(NULL);
+       context.week_start_ts = stc_time_get_week_start(context.now);
+       context.day_start_ts = stc_time_get_day_start(context.now);
+       context.is_updated = 0;
+
+       if (last_week_ts != context.week_start_ts) {
+               stc_monitor_set_last_week_ts(context.week_start_ts);
+               context.is_updated |= (1 << STC_RSTN_LIMIT_TYPE_WEEKLY);
+       }
+
+       if (last_day_ts != context.day_start_ts) {
+               stc_monitor_set_last_day_ts(context.day_start_ts);
+               context.is_updated |= (1 << STC_RSTN_LIMIT_TYPE_DAILY);
+       }
+
+       if (rstns) {
+               g_hash_table_foreach(rstns,
+                              __reset_time_counter_foreach_rstn_value,
+                              &context);
+
+               if (context.is_updated)
+                       STC_LOGD("Counter reset completed month_start[%ld] "
+                               "week_start[%ld] day_start[%ld]",
+                               context.month_start_ts, last_week_ts, last_day_ts);
+       }
+}
+
+void stc_monitor_rstn_update_counter(gpointer data,
+                                       gpointer user_data)
+{
+       int i;
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+       classid_bytes_context_s *context = (classid_bytes_context_s *)user_data;
+       GSList *conn_list = stc_get_connection_list();
+
+       for (; conn_list != NULL; conn_list = conn_list->next) {
+               stc_connection_s *conn = conn_list->data;
+
+               if (rstn_data->iftype != context->counter->iftype)
+                       return;
+
+               if (rstn_data->ifname != NULL &&
+                       g_strcmp0(rstn_data->ifname, "") &&
+                       g_strcmp0(rstn_data->ifname, context->counter->ifname) != 0)
+                       return;
+
+               if (rstn_data->subscriber_id != NULL &&
+                       g_strcmp0(rstn_data->subscriber_id, "") &&
+                       g_strcmp0(rstn_data->subscriber_id, conn->subscriber_id) != 0)
+                       return;
+
+               if (rstn_data->roaming != conn->roaming)
+                       return;
+
+               if (rstn_data->limit_exceeded != 0) {
+                       context->data_limit_exceeded = TRUE;
+                       return;
+               }
+
+               switch (context->counter->iotype) {
+               case NFACCT_COUNTER_IN:
+               case NFACCT_COUNTER_OUT:
+                       if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
+                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
+                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
+                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
+                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
+                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
+                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
+                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
+                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
+                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
+                               table_counters_info info;
+                               memset(&info, 0, sizeof(table_counters_info));
+                               table_counters_get(rstn_data->restriction_id, &info);
+
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter;
+                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter;
+                       }
+
+                       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
+                               if (rstn_data->limit[i] >= 0 &&
+                                       !(rstn_data->limit_notified & (1 << i))) {
+                                       rstn_data->counter[i] += context->bytes;
+                                       if (rstn_data->limit[i] <= rstn_data->counter[i])
+                                               stc_monitor_rstn_action_when_limit_exceeded(i,
+                                                                                       rstn_data,
+                                                                                       context);
+                               }
+                       }
+
+                       stc_monitor_set_rstns_updated(TRUE);
+                       __print_rstn(rstn_data);
+                       break;
+               default:
+                       STC_LOGE("Unknown iotype");
+               }
+       }
+}
+
+void stc_monitor_rstn_update_iface_counter(classid_bytes_context_s *context)
+{
+       switch (context->counter->iftype) {
+       case STC_IFACE_DATACALL:
+               __rstn_update_counter(context, STC_TOTAL_DATACALL_CLASSID);
+               break;
+       case STC_IFACE_WIFI:
+               __rstn_update_counter(context, STC_TOTAL_WIFI_CLASSID);
+               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       case STC_IFACE_BLUETOOTH:
+               __rstn_update_counter(context, STC_TOTAL_BLUETOOTH_CLASSID);
+               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       case STC_IFACE_USB:
+               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       case STC_IFACE_P2P:
+               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
+               break;
+       default:
+               break;
+       }
+}
+
+void stc_monitor_rstn_action_when_limit_exceeded(stc_rstn_limit_type_e limit_type,
+                                               stc_rstn_data_s *rstn_data,
+                                               classid_bytes_context_s *context)
+{
+       gboolean rv;
+       char iftype[MAX_INT_LENGTH] = { 0, };
+       char byte[MAX_INT_LENGTH] = { 0, };
+       const char *signal_name = NULL;
+       const char *net_popup_content = NULL;
+       const char *net_popup_type = NULL;
+       stc_s *stc = (stc_s *)stc_get_manager();
+
+       if (stc == NULL) {
+               STC_LOGE("Failed to get stc data");
+               return;
+       }
+
+       switch (limit_type) {
+       case STC_RSTN_LIMIT_TYPE_DATA_WARN:
+       {
+               signal_name = "WarnThresholdCrossed";
+               net_popup_content = "warn threshold crossed";
+               net_popup_type = "warning_noti";
+       }
+       break;
+       case STC_RSTN_LIMIT_TYPE_DATA:
+       case STC_RSTN_LIMIT_TYPE_MONTHLY:
+       case STC_RSTN_LIMIT_TYPE_WEEKLY:
+       case STC_RSTN_LIMIT_TYPE_DAILY:
+       {
+               signal_name = "RestrictionThresholdCrossed";
+               net_popup_content = "restriction threshold crossed";
+               net_popup_type = "restriction_noti";
+
+               /* Apply restriction for tethering apps if app_id is of tethering client
+                * otherwise do the normal iptables rule */
+               if (context->counter->intend == NFACCT_TETH_COUNTER) {
+
+                       if (g_str_has_suffix(rstn_data->app_id, STC_TETHERING_APP_SUFFIX) &&
+                                       rstn_data->classid != STC_TETHERING_APP_CLASSID) {
+                               __rstn_action_when_limit_exceeded_tethering(rstn_data,
+                                               context);
+                       }
+
+               } else {
+                       /* block immediately */
+                       context->counter->intend = NFACCT_BLOCK;
+                       stc_monitor_ipt_del_in(context->counter);
+                       stc_monitor_ipt_del_out(context->counter);
+                       stc_monitor_ipt_add_in(context->counter);
+                       stc_monitor_ipt_add_out(context->counter);
+
+                       stc_monitor_ip6t_del_in(context->counter);
+                       stc_monitor_ip6t_del_out(context->counter);
+                       stc_monitor_ip6t_add_in(context->counter);
+                       stc_monitor_ip6t_add_out(context->counter);
+                       context->counter->intend = NFACCT_COUNTER;
+               }
+
+               rstn_data->limit_exceeded |= (1 << limit_type);
+               __rstn_set_noti_state(STC_RSTN_STATE_SET);
+       }
+       break;
+       default:
+               break;
+       }
+
+       if (signal_name == NULL) {
+               STC_LOGE("Invalid parameter: limit_type");
+               return;
+       }
+
+       /* emit signal */
+       rv = stc_manager_dbus_emit_signal(stc->connection,
+                                                 STC_DBUS_SERVICE_RESTRICTION_PATH,
+                                                 STC_DBUS_INTERFACE_RESTRICTION,
+                                                 signal_name,
+                                                 g_variant_new("(si)",
+                                                 rstn_data->app_id,
+                                                 rstn_data->iftype));
+
+       if (rv == TRUE)
+               rstn_data->limit_notified |= (1 << limit_type);
+
+       snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_data->iftype);
+       snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_data->limit[limit_type]);
+       stc_plugin_appstatus_send_message(net_popup_content,
+                       net_popup_type, rstn_data->app_id, iftype, byte);
+
+       if (STC_DEBUG_LOG && STC_RSTN_LOG)
+               STC_LOGD("Limit exceeded [\033[0;31m%s\033[0;m:%d]",
+                                       net_popup_content, limit_type);
+}
+
+gboolean stc_monitor_rstn_flush_contr_to_db(gpointer user_data)
+{
+       time_t current_time = 0;
+       stc_s *stc = stc_get_manager();
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+       gboolean rstns_updated = stc_monitor_get_rstns_updated();
+
+       if (stc && stc->carg)
+               current_time = stc->carg->last_run_time;
+
+       if (rstns_updated == FALSE)
+               return G_SOURCE_REMOVE;
+
+       stc_monitor_set_rstns_updated(FALSE);
+
+       if (rstns)
+               g_hash_table_foreach(rstns,
+                              __rstn_update_counter_value,
+                              &current_time);
+
+       STC_LOGI("Flushed rstns counters to database");
+       return G_SOURCE_REMOVE;
+}
+
+void stc_monitor_rstn_add_for_app(uint32_t classid)
+{
+       stc_rstn_value_s *lookup_value;
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return;
+
+       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
+       if (!lookup_value) {
+               if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                       STC_LOGD("Restriction not found [\033[1;36m%d\033[0;m]",
+                                               classid);
+               return;
+       }
+
+       g_slist_foreach(lookup_value->rules, __rstn_add, NULL);
+}
+
+void stc_monitor_rstn_add_by_connection(stc_connection_s *conn)
+{
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return;
+
+       g_hash_table_foreach(rstns, __rstn_add_by_connection, conn);
+}
+
+void stc_monitor_rstn_remove_for_app(uint32_t classid)
+{
+       stc_rstn_value_s *lookup_value;
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return;
+
+       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
+       if (!lookup_value) {
+               if (STC_DEBUG_LOG && STC_RSTN_LOG)
+                       STC_LOGD("Restriction not found [\033[1;36m%d\033[0;m]",
+                                               classid);
+               return;
+       }
+
+       g_slist_foreach(lookup_value->rules, __rstn_remove, NULL);
+}
+
+void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn)
+{
+       GHashTable *rstns = stc_monitor_get_system_rstns();
+
+       if (!rstns)
+               return;
+
+       g_hash_table_foreach(rstns, __rstn_remove_by_connection, conn);
+}
+
+void stc_monitor_rstns_load(void)
+{
+       table_restrictions_foreach(__rstn_insert_cb, NULL);
+
+       /* __rstn_tree_printall(); */
+}
+
+GHashTable *stc_monitor_rstns_init(void)
+{
+       return g_hash_table_new_full(g_direct_hash, g_direct_equal,
+                                       NULL, __rstn_value_destroy);
+}
diff --git a/plugin/monitor/stc-plugin-monitor-time.c b/plugin/monitor/stc-plugin-monitor-time.c
new file mode 100755 (executable)
index 0000000..f3a17cc
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+
+#include <time.h>
+#include <stdbool.h>
+
+#define SEC_IN_DAY 24 * 60 * 60
+#define SEC_IN_WEEK 7 * SEC_IN_DAY
+
+time_t stc_time_get_day_start(time_t now)
+{
+       struct tm curr;
+       struct tm *res;
+
+       res = localtime_r(&now, &curr);
+       if (!res)
+               return 0;
+
+       curr.tm_sec = 0;
+       curr.tm_min = 0;
+       curr.tm_hour = 0;
+
+       return mktime(&curr);
+}
+
+time_t stc_time_get_week_start(time_t now)
+{
+       struct tm curr;
+       struct tm *res;
+       int days;
+
+       res = localtime_r(&now, &curr);
+       if (!res)
+               return 0;
+
+       curr.tm_sec = 0;
+       curr.tm_min = 0;
+       curr.tm_hour = 0;
+
+       if (curr.tm_wday > 1)
+               days = curr.tm_wday - 1;
+       else
+               days = 1 - curr.tm_wday;
+
+       return (mktime(&curr) - (days * SEC_IN_DAY));
+}
+
+time_t stc_time_get_month_start(time_t now, int month_start_date)
+{
+       struct tm curr;
+       struct tm *res;
+       bool is_leap_year;
+
+       res = localtime_r(&now, &curr);
+       if (!res)
+               return 0;
+
+       curr.tm_sec = 0;
+       curr.tm_min = 0;
+       curr.tm_hour = 0;
+
+       if (curr.tm_mday < month_start_date) {
+               curr.tm_mon--;
+               if (curr.tm_mon < 0) {
+                       curr.tm_mon = 11;
+                       curr.tm_year--;
+               }
+       }
+
+       is_leap_year = ((curr.tm_year + 1900) % 4 ? 0 : 1);
+       curr.tm_mday = month_start_date;
+
+       switch (month_start_date) {
+       case 29:
+       case 30:
+               if (curr.tm_mon == 1 && !is_leap_year)
+                       curr.tm_mday = 28;
+
+               else if (curr.tm_mon == 1 && is_leap_year)
+                       curr.tm_mday = 29;
+
+               break;
+       case 31:
+               if (curr.tm_mon == 1 && !is_leap_year)
+                       curr.tm_mday = 28;
+
+               else if (curr.tm_mon == 1 && is_leap_year)
+                       curr.tm_mday = 29;
+
+               else if (curr.tm_mon == 3 || curr.tm_mon == 5 ||
+                        curr.tm_mon == 8 || curr.tm_mon == 10)
+                       curr.tm_mday = 30;
+
+               break;
+       default:
+               ;//Do Nothing
+       };
+
+       return mktime(&curr);
+}
diff --git a/plugin/monitor/stc-plugin-monitor.c b/plugin/monitor/stc-plugin-monitor.c
new file mode 100755 (executable)
index 0000000..117036e
--- /dev/null
@@ -0,0 +1,601 @@
+/*
+ * 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.
+ */
+
+#include <linux/netlink.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+
+#include "helper-nl.h"
+#include "helper-nfacct-rule.h"
+#include "helper-net-cls.h"
+#include "helper-cgroup.h"
+#include "helper-iptables.h"
+#include "counter.h"
+#include "table-statistics.h"
+#include "table-counters.h"
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-monitor-connection.h"
+#include "stc-plugin-monitor-rstn.h"
+#include "stc-manager-plugin-exception.h"
+
+static stc_system_s *g_system = NULL;
+
+static int __vconf_get_int(const char *key, int *value)
+{
+       int ret = 0;
+
+       ret = vconf_get_int(key, value);
+       if (ret != VCONF_OK) {
+               STC_LOGE("Failed to get vconfkey [%s] value", key);
+               return -1;
+       }
+
+       return 0;
+}
+
+static stc_error_e __close_contr_sock(stc_system_s *system)
+{
+       ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
+
+       /* close netlink socket for updating kernel counters */
+       if (system->contr_sock != -1) {
+               close(system->contr_sock);
+               system->contr_sock = -1;
+       }
+
+       if (system->contr_gsource_id != 0) {
+               g_source_remove(system->contr_gsource_id);
+               system->contr_gsource_id = 0;
+       }
+
+       return STC_ERROR_NONE;
+}
+
+static gboolean __process_contr_reply(GIOChannel *source,
+                                     GIOCondition condition,
+                                     gpointer user_data);
+
+static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
+{
+       GIOChannel *gio = NULL;
+       ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
+
+       /* close netlink socket for updating kernel counters */
+       if (system->contr_sock != -1) {
+               close(system->contr_sock);
+               system->contr_sock = -1;
+       }
+
+       if (system->contr_gsource_id != 0) {
+               g_source_remove(system->contr_gsource_id);
+               system->contr_gsource_id = 0;
+       }
+
+       /* create netlink socket for updating kernel counters */
+       system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
+       if (system->contr_sock < 0) {
+               STC_LOGE("failed to open socket");
+               FREE(system);
+               return STC_ERROR_FAIL;
+       }
+
+       gio = g_io_channel_unix_new(system->contr_sock);
+       system->contr_gsource_id =
+               g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
+                              (GIOFunc) __process_contr_reply,
+                              NULL);
+       g_io_channel_unref(gio);
+
+       return STC_ERROR_NONE;
+}
+
+static void __check_rstn_limit_exceeded(gpointer data,
+                               gpointer user_data)
+{
+       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
+       int32_t *limit_exceeded = (int32_t *)user_data;
+
+       if (rstn_data->limit_exceeded != 0)
+               *limit_exceeded = rstn_data->limit_exceeded;
+}
+
+static void __fill_nfacct_result(char *cnt_name, int64_t bytes,
+                               struct counter_arg *carg)
+{
+       stc_monitor_rstn_reset_time_counters_if_required();
+
+       struct nfacct_rule counter = {
+               .carg = carg,
+               .name = {0},
+               .ifname = {0},
+               0
+       };
+
+       classid_bytes_context_s context = {
+               .counter = &counter,
+               .bytes = bytes,
+               .data_limit_exceeded = FALSE,
+       };
+
+       if (!recreate_counter_by_name(cnt_name, &counter)) {
+               STC_LOGE("Can't parse counter name %s", cnt_name);
+               return;
+       }
+
+       if (STC_DEBUG_LOG)
+               STC_LOGI("classid[\033[1;36m%u\033[0;m] iftype[%u] "
+                       "iotype[%d] intend[%d] ifname[%s] bytes[%lld]",
+                       context.counter->classid, context.counter->iftype,
+                       context.counter->iotype, context.counter->intend,
+                       context.counter->ifname, context.bytes);
+
+       if (context.counter->intend == NFACCT_COUNTER ||
+               context.counter->intend == NFACCT_TETH_COUNTER) {
+               if (g_system->apps) {
+                       stc_app_value_s *lookup_app;
+                       stc_rstn_value_s *lookup_rstn;
+
+                       stc_monitor_app_update_iface_counter(&context);
+
+                       lookup_app = g_hash_table_lookup(g_system->apps,
+                                               GUINT_TO_POINTER(context.counter->classid));
+                       if (lookup_app)
+                               stc_monitor_app_update_counter(lookup_app, &context);
+
+                       lookup_rstn = g_hash_table_lookup(g_system->rstns,
+                                               GUINT_TO_POINTER(context.counter->classid));
+                       if (lookup_rstn) {
+                               int32_t limit_exceeded = 0;
+                               g_slist_foreach(lookup_rstn->rules,
+                                       __check_rstn_limit_exceeded, &limit_exceeded);
+
+                               if (limit_exceeded != 0)
+                                       return;
+                       }
+               }
+
+               if (g_system->rstns) {
+                       stc_rstn_value_s *lookup_value;
+                       uint32_t classid = context.counter->classid;
+
+                       stc_monitor_rstn_update_iface_counter(&context);
+                       context.counter->classid = classid;
+
+                       lookup_value = g_hash_table_lookup(g_system->rstns,
+                                                       GUINT_TO_POINTER(classid));
+                       if (lookup_value) {
+                               g_slist_foreach(lookup_value->rules,
+                                       stc_monitor_rstn_update_counter,
+                                       &context);
+                       }
+               }
+       }
+}
+
+static int __fill_counters(struct rtattr *attr_list[__NFACCT_MAX],
+                          void *user_data)
+{
+       struct counter_arg *carg = user_data;
+       char *cnt_name = (char *)RTA_DATA(attr_list[NFACCT_NAME]);
+       if (carg->initiate) {
+               /**
+                * TODO: this will be used when daemon starts to update existing
+                * counter data if present.
+                *
+                populate_counters(cnt_name, carg);
+                */
+       } else {
+               int64_t *bytes_p =
+                       (int64_t *)RTA_DATA(attr_list[NFACCT_BYTES]);
+               int bytes = be64toh(*bytes_p);
+               if (bytes) {
+                       ++carg->serialized_counters;
+                       __fill_nfacct_result(cnt_name, bytes, carg);
+               }
+       }
+
+       return 0;
+}
+
+static int __post_fill_counters(void *user_data)
+{
+       struct counter_arg *carg = user_data;
+
+       if (carg->initiate)
+               carg->initiate = 0;
+
+       return 0;
+}
+
+static void __process_network_counter(struct genl *ans,
+                                     struct counter_arg *carg)
+{
+       struct netlink_serialization_params ser_params = {
+               .carg = carg,
+               .ans = ans,
+               .eval_attr = __fill_counters,
+               .post_eval_attr = __post_fill_counters,
+       };
+
+       netlink_serialization_command *netlink =
+               netlink_create_command(&ser_params);
+       if (!netlink) {
+               STC_LOGE("Can not create command");
+               return;
+       }
+
+       netlink->deserialize_answer(&(netlink->params));
+}
+
+static gboolean __process_contr_reply(GIOChannel *source,
+                                     GIOCondition condition,
+                                     gpointer user_data)
+{
+       int sock = g_io_channel_unix_get_fd(source);
+       struct genl *ans;
+       int ret;
+       stc_s *stc = stc_get_manager();
+
+#ifdef TIZEN_GTESTS
+       void __gcov_flush(void);
+       __gcov_flush();
+#endif
+
+       if ((condition & G_IO_ERR) || (condition & G_IO_HUP) ||
+           (condition & G_IO_NVAL)) {
+               /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
+
+               STC_LOGE("Counter socket received G_IO event, closing socket."
+                        "G_IO_ERR [%u], G_IO_HUP [%u], G_IO_NVAL [%u]",
+                        (condition & G_IO_ERR), (condition & G_IO_HUP),
+                        (condition & G_IO_NVAL));
+               __close_and_reopen_contr_sock(g_system);
+               return FALSE;
+       }
+
+       ans = MALLOC0(struct genl, 1);
+       if (ans == NULL) {
+               STC_LOGE("Failed allocate memory to genl reply message");
+               return TRUE;
+       }
+
+       if (stc == NULL) {
+               STC_LOGE("Can't get stc data");
+               goto out;
+       }
+
+       ret = read_netlink(sock, ans, sizeof(struct genl));
+
+       if (ret == 0)
+               goto out;
+
+       stc->carg->ans_len = ret;
+       stc->carg->last_run_time = time(NULL);
+
+       __process_network_counter(ans, stc->carg);
+
+       g_idle_add(stc_monitor_app_flush_stats_to_db, NULL);
+       g_idle_add(stc_monitor_rstn_flush_contr_to_db, NULL);
+out:
+
+       FREE(ans);
+       return TRUE;
+}
+
+static gboolean __update_contr_cb(void *user_data)
+{
+       /* Here we just sent command, answer we receive in another callback */
+       stc_s *stc = stc_get_manager();
+       ret_value_msg_if(stc == NULL, STC_ERROR_FAIL, "Can't get stc data");
+       if (!stc->carg) {
+               stc->carg = MALLOC0(counter_arg_s, 1);
+               if (stc->carg == NULL)
+                       return TRUE;  /* we need to continue the timer */
+
+               stc->carg->sock = g_system->contr_sock;
+       }
+
+#ifdef TIZEN_GTESTS
+       void __gcov_flush(void);
+       __gcov_flush();
+#endif
+
+       /* STC_LOGD("Get all counters"); */
+       nfacct_send_get_all(stc->carg);
+
+       /* we need to continue the timer */
+       return TRUE;
+}
+
+static void __fill_exceptions_list(void)
+{
+       stc_plugin_fill_exception_list();
+}
+
+stc_error_e stc_plugin_monitor_initialize(void)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       stc_system_s *system = MALLOC0(stc_system_s, 1);
+       GIOChannel *gio = NULL;
+
+       ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY,
+                               "stc_system_s malloc fail!");
+
+       /* initializing current classid */
+       init_current_classid();
+
+       /* initializing cgroups */
+       cgroup_init();
+
+       /* creating monitored application tree */
+       system->apps = stc_monitor_apps_init();
+       system->rstns = stc_monitor_rstns_init();
+
+       /* create netlink socket for updating kernel counters */
+       system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
+       if (system->contr_sock < 0) {
+               STC_LOGE("failed to open socket");
+               FREE(system);
+               return STC_ERROR_FAIL;
+       }
+
+       gio = g_io_channel_unix_new(system->contr_sock);
+       system->contr_gsource_id =
+               g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
+                              (GIOFunc) __process_contr_reply,
+                              NULL);
+       g_io_channel_unref(gio);
+
+       g_system = system;
+
+       stc_monitor_app_add_by_iface(STC_TOTAL_DATACALL);
+       stc_monitor_app_add_by_iface(STC_TOTAL_WIFI);
+       stc_monitor_app_add_by_iface(STC_TOTAL_BLUETOOTH);
+       stc_monitor_app_add_by_iface(STC_TOTAL_IPV4);
+       stc_monitor_app_add_by_iface(STC_TOTAL_IPV6);
+
+       __update_contr_cb(NULL);
+
+       /* registering periodic kernel counters update callback */
+       g_system->contr_timer_id = g_timeout_add_seconds(CONTR_TIMER_INTERVAL,
+                                                        __update_contr_cb,
+                                                        NULL);
+       if (g_system->contr_timer_id == 0) {
+               STC_LOGE("Failed to register kernel counters update timer");
+               __close_contr_sock(g_system);
+               return STC_ERROR_FAIL;
+       }
+
+       __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
+                       (int *)&g_system->background_state);
+
+       __fill_exceptions_list();
+       stc_monitor_rstns_load();
+
+       __STC_LOG_FUNC_EXIT__;
+       return STC_ERROR_NONE;
+}
+
+stc_error_e stc_plugin_monitor_deinitialize(void)
+{
+       ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
+
+       /* close netlink socket for updating kernel counters */
+       __close_contr_sock(g_system);
+
+       /* remove kernel counters update timer */
+       if (g_system->contr_timer_id > 0) {
+               g_source_remove(g_system->contr_timer_id);
+               g_system->contr_timer_id = 0;
+       }
+
+       /* destroy monitored application tree */
+       g_hash_table_destroy(g_system->apps);
+       g_system->apps = NULL;
+
+       /* destroy restriction rules tree */
+       g_hash_table_destroy(g_system->rstns);
+       g_system->rstns = NULL;
+
+       FREE(g_system);
+
+       return STC_ERROR_NONE;
+}
+
+GHashTable *stc_monitor_get_system_apps(void)
+{
+       ret_value_msg_if(g_system == NULL, NULL,
+                               "stc monitor not initialized!");
+
+       ret_value_msg_if(g_system->apps == NULL, NULL,
+                               "apps is null!");
+
+       return g_system->apps;
+}
+
+GHashTable *stc_monitor_get_system_rstns(void)
+{
+       ret_value_msg_if(g_system == NULL, NULL,
+                               "stc monitor not initialized!");
+
+       ret_value_msg_if(g_system->rstns == NULL, NULL,
+                               "rstns is null!");
+
+       return g_system->rstns;
+}
+
+int stc_monitor_get_contr_sock(void)
+{
+       ret_value_msg_if(g_system == NULL, 0,
+                               "stc monitor not initialized!");
+
+       return g_system->contr_sock;
+}
+
+time_t stc_monitor_get_last_month_ts(void)
+{
+       ret_value_msg_if(g_system == NULL, 0,
+                               "stc monitor not initialized!");
+
+       return g_system->last_month_ts;
+}
+
+void stc_monitor_set_last_month_ts(time_t time)
+{
+       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
+
+       g_system->last_month_ts = time;
+}
+
+time_t stc_monitor_get_last_week_ts(void)
+{
+       ret_value_msg_if(g_system == NULL, 0,
+                               "stc monitor not initialized!");
+
+       return g_system->last_week_ts;
+}
+
+void stc_monitor_set_last_week_ts(time_t time)
+{
+       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
+
+       g_system->last_week_ts = time;
+}
+
+time_t stc_monitor_get_last_day_ts(void)
+{
+       ret_value_msg_if(g_system == NULL, 0,
+                               "stc monitor not initialized!");
+
+       return g_system->last_day_ts;
+}
+
+void stc_monitor_set_last_day_ts(time_t time)
+{
+       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
+
+       g_system->last_day_ts = time;
+}
+
+void stc_monitor_set_rstns_updated(gboolean value)
+{
+       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
+
+       g_system->rstns_updated = value;
+}
+
+gboolean stc_monitor_get_rstns_updated(void)
+{
+       ret_value_msg_if(g_system == NULL, FALSE,
+                               "stc monitor not initialized!");
+
+       return g_system->rstns_updated;
+}
+
+void stc_monitor_set_apps_updated(gboolean value)
+{
+       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
+
+       g_system->apps_updated = value;
+}
+
+gboolean stc_monitor_get_apps_updated(void)
+{
+       ret_value_msg_if(g_system == NULL, FALSE,
+                               "stc monitor not initialized!");
+
+       return g_system->apps_updated;
+}
+
+void stc_monitor_set_background_state(gboolean value)
+{
+       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
+
+       g_system->background_state = value;
+}
+
+gboolean stc_monitor_get_background_state(void)
+{
+       ret_value_msg_if(g_system == NULL, FALSE,
+                               "stc monitor not initialized!");
+
+       return g_system->background_state;
+}
+
+void stc_monitor_update_by_connection(void *data)
+{
+       stc_connection_s *connection = (stc_connection_s *)data;
+
+       if (connection != NULL && connection->path != NULL) {
+               stc_monitor_app_remove_by_connection(connection);
+               stc_monitor_rstn_remove_by_connection(connection);
+
+               iptables_flush_chains();
+
+               stc_monitor_app_add_by_connection(connection);
+               stc_monitor_rstn_add_by_connection(connection);
+       }
+}
+
+void stc_monitor_add_by_connection(void *data)
+{
+       stc_connection_s *connection = (stc_connection_s *)data;
+
+       if (connection != NULL && connection->path != NULL) {
+               stc_monitor_app_add_by_connection(connection);
+               stc_monitor_rstn_add_by_connection(connection);
+       }
+}
+
+void stc_monitor_remove_by_connection(void *data)
+{
+       stc_connection_s *connection = (stc_connection_s *)data;
+
+       if (connection != NULL && connection->path != NULL) {
+               stc_monitor_app_remove_by_connection(connection);
+               stc_monitor_rstn_remove_by_connection(connection);
+       }
+}
+
+API stc_plugin_monitor_s stc_plugin_monitor = {
+       .initialize_plugin =
+               stc_plugin_monitor_initialize,
+       .deinitialize_plugin =
+               stc_plugin_monitor_deinitialize,
+       .add_application =
+               stc_plugin_monitor_app_add,
+       .remove_application =
+               stc_plugin_monitor_app_remove,
+       .lookup_application =
+               stc_plugin_monitor_app_lookup,
+       .add_restriction =
+               stc_plugin_monitor_rstn_add,
+       .remove_restriction =
+               stc_plugin_monitor_rstn_remove,
+       .init_connection =
+               stc_plugin_monitor_connection_init,
+       .deinit_connection =
+               stc_plugin_monitor_connection_deinit,
+       .add_process =
+               stc_plugin_monitor_proc_add,
+       .remove_process =
+               stc_plugin_monitor_proc_remove,
+       .move_process =
+               stc_plugin_monitor_proc_move,
+       .update_process_ground =
+               stc_plugin_monitor_proc_update_ground
+};
index 22dddb70d57439d1f8e8bd89814334e351e46695..fd03c4a62d2cf74c2e52a6a37c8b04e910c94bc9 100755 (executable)
@@ -49,7 +49,7 @@ static void __pcap_data_info(const u_char *packet, int len)
 
 static void __pcap_ntp_time_info(uint32_t s, char *time)
 {
-       time_t seconds; 
+       time_t seconds;
        char *curr = NULL;
        int len = 0;
        uint32_t sec = ntohl(s);
@@ -775,7 +775,7 @@ static void __pcap_udp_info(const u_char *packet)
                IS_SRC_OR_DST_PORT(PORT_BOOTP_S))
                __pcap_bootp_info(packet);
        else if (IS_SRC_OR_DST_PORT(PORT_NTP))
-               __pcap_ntp_info(packet);        
+               __pcap_ntp_info(packet);
 }
 
 static const char *__pcap_eth_type_info(u_int16_t type)
@@ -1142,7 +1142,7 @@ thread_exit:
        g_source_attach(source, context);
 
        g_source_unref(source);
-       
+
        __STC_LOG_FUNC_EXIT__;
        return NULL;
 }
@@ -1173,28 +1173,22 @@ int stc_plugin_pcap_deinitialize(void)
 
 int stc_plugin_pcap_lookup_dev(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        char *dev = NULL;
        char errbuf[PCAP_ERRBUF_SIZE];
 
        dev = pcap_lookupdev(errbuf);
        if (dev == NULL) {
                STC_LOGE("Failed to look up dev [%s]", errbuf);
-               __STC_LOG_FUNC_EXIT__;
                return STC_ERROR_FAIL;
        }
 
        STC_LOGD("Dev [%s]", dev);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
 int stc_plugin_pcap_lookup_net(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        char *dev = NULL;
        char net[BUFF_SIZE_IP];
        char mask[BUFF_SIZE_IP];
@@ -1206,7 +1200,6 @@ int stc_plugin_pcap_lookup_net(void)
        dev = pcap_lookupdev(errbuf);
        if (dev == NULL) {
                STC_LOGE("Failed to look up dev [%s]", errbuf);
-               __STC_LOG_FUNC_EXIT__;
                return STC_ERROR_FAIL;
        }
 
@@ -1215,7 +1208,6 @@ int stc_plugin_pcap_lookup_net(void)
        ret = pcap_lookupnet(dev, &netp, &maskp, errbuf);
        if (ret == -1) {
                STC_LOGE("Failed to look up net [%s]", errbuf);
-               __STC_LOG_FUNC_EXIT__;
                return STC_ERROR_FAIL;
        }
 
@@ -1225,14 +1217,11 @@ int stc_plugin_pcap_lookup_net(void)
        inet_ntop(AF_INET, &maskp, mask, BUFF_SIZE_IP);
        STC_LOGD("Mask [%s]", mask);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
 int stc_plugin_pcap_find_alldevs(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        char net[BUFF_SIZE_IP];
        char mask[BUFF_SIZE_IP];
        char errbuf[PCAP_ERRBUF_SIZE];
@@ -1244,7 +1233,6 @@ int stc_plugin_pcap_find_alldevs(void)
        if (pcap_findalldevs(&alldevs, errbuf) < 0 ||
                alldevs == NULL) {
                STC_LOGE("Failed to find all devs [%s]", errbuf);
-               __STC_LOG_FUNC_EXIT__;
                return STC_ERROR_FAIL;
        }
 
@@ -1268,15 +1256,12 @@ int stc_plugin_pcap_find_alldevs(void)
 
        pcap_freealldevs(alldevs);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
 int stc_plugin_pcap_register_loop_pcap(const char *ifname,
                        int group)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        stc_pcap_data_s *data;
        stc_pcap_data_s *lookup;
        char buf[MAX_IFACE_LENGTH];
@@ -1294,14 +1279,12 @@ int stc_plugin_pcap_register_loop_pcap(const char *ifname,
        lookup = g_hash_table_lookup(g_pcap_tables, buf);
        if (lookup) {
                STC_LOGD("pcap loop already present");
-               __STC_LOG_FUNC_EXIT__;
                return STC_ERROR_ALREADY_DATA;
        }
 
        data = MALLOC0(stc_pcap_data_s, 1);
        if (!data) {
                STC_LOGE("data allocation failed");
-               __STC_LOG_FUNC_EXIT__;
                return STC_ERROR_OUT_OF_MEMORY;
        }
 
@@ -1312,15 +1295,12 @@ int stc_plugin_pcap_register_loop_pcap(const char *ifname,
        g_hash_table_insert(g_pcap_tables, g_strdup(buf), data);
        STC_LOGD("Successfully added pcap loop [%s]", buf);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
 int stc_plugin_pcap_unregister_loop_pcap(const char *ifname,
                        int group)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        stc_pcap_data_s *lookup;
        char buf[MAX_IFACE_LENGTH];
 
@@ -1343,7 +1323,6 @@ int stc_plugin_pcap_unregister_loop_pcap(const char *ifname,
 
        pcap_breakloop(lookup->handle);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
index dc04ca8c608d87c32751649f7c001d60d6e69927..17ab7f2d1aceb9878ec50815c96acf791f148ed7 100644 (file)
@@ -15,6 +15,8 @@ FOREACH(flag ${procfs_plugin_CFLAGS})
 ENDFOREACH(flag)
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugin/monitor/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugin/exception/include)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror -fvisibility=hidden")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
old mode 100644 (file)
new mode 100755 (executable)
index d548c1f..53635ca
@@ -20,7 +20,6 @@
 #include <glib.h>
 #include "stc-error.h"
 #include "stc-manager.h"
-#include "stc-monitor.h"
 
 typedef struct {
        int (*initialize_plugin) (void);
index 5a323a48f59a85a857616800d34b684fcac1eb31..668f15c1257f30da7349fb3e28240d0c582deec0 100755 (executable)
 #include <glib.h>
 
 #include "stc-plugin-procfs.h"
-#include "stc-monitor.h"
 #include "helper-net-cls.h"
 #include "helper-procfs.h"
+#include "stc-manager-plugin-monitor.h"
+#include "stc-manager-plugin-exception.h"
 
 //LCOV_EXCL_START
 typedef struct {
@@ -135,7 +136,7 @@ static proc_value_s * __proc_tree_find_parent(proc_value_s *value)
                        parent = lookup;
        } while (lookup);
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG) {
+       if (STC_STAT_LOG) {
                if (parent != NULL)
                        STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] "
                                "pid[%s] ppid[%s] cmdline[\033[0;34m%s\033[0;m] name[%s]",
@@ -158,7 +159,7 @@ static void __proc_tree_add(proc_key_s *key, proc_value_s *value)
        }
 
        if (key == NULL || value == NULL) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
+               if (STC_STAT_LOG)
                        STC_LOGE("invalid parameters");
                return;
        }
@@ -223,7 +224,7 @@ static gboolean __check_excn(char *cmdline)
        if (cmdline[0] == '(')
                return TRUE;
 
-       ret = stc_monitor_check_excn_by_cmdline(cmdline);
+       ret = stc_plugin_check_exception_by_cmdline(cmdline);
        if (ret == STC_ERROR_UNINITIALIZED ||
                ret == STC_ERROR_NO_DATA)
                return FALSE;
@@ -318,7 +319,7 @@ static void __process_event_fork(int tgid, int pid)
                        g_strlcpy(value.status[i], status[i], sizeof(value.status[i]));
                g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline));
 
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
+               if (STC_STAT_LOG)
                        STC_LOGD("\033[1;32mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] "
                        "ppid=[%s] cmdline[\033[0;34m%s\033[0;m] pid[%d]",
                        tgid, status[PROC_STATUS_PPID], cmdline, pid);
@@ -357,7 +358,7 @@ static void __process_event_exec(int tgid, int pid)
                                  sizeof(value.status[i]));
                g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline));
 
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
+               if (STC_STAT_LOG)
                        STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] "
                        "ppid[%s] cmdline[\033[0;34m%s\033[0;m] pid[%d]",
                        tgid, status[PROC_STATUS_PPID], cmdline, pid);
@@ -379,7 +380,7 @@ static void __process_event_exit(int tgid, int pid, int exit_code)
        if (lookup == NULL) /* unmonitored process */
                return;
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] "
                        "cmdline[\033[0;34m%s\033[0;m] pid[%d] exitcode[%d]",
                        tgid, lookup->cmdline, pid, exit_code);
@@ -591,7 +592,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
 {
        stc_error_e ret = STC_ERROR_NONE;
 
-       if ((pkg_id && app_id) && STC_DEBUG_LOG && STC_STAT_LOG)
+       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);
 
@@ -619,12 +620,12 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
                fg_classid = get_classid_by_app_id(app_id, TRUE);
 
-               stc_monitor_app_add(fg_classid, app_id, pkg_id, app_value);
+               stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
 
-               stc_monitor_proc_move(bg_classid, fg_classid);
+               stc_plugin_monitor_move_proc(bg_classid, fg_classid);
 
-               stc_monitor_proc_add(fg_classid, app_id, proc_value);
-               stc_monitor_proc_update_ground(fg_classid, app_id, proc_value);
+               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;
@@ -652,12 +653,12 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                fg_classid = get_classid_by_app_id(app_id, FALSE);
                bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
 
-               stc_monitor_app_add(bg_classid, bg_app_id, pkg_id, app_value);
+               stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
 
-               stc_monitor_proc_move(fg_classid, bg_classid);
+               stc_plugin_monitor_move_proc(fg_classid, bg_classid);
 
-               stc_monitor_proc_add(bg_classid, bg_app_id, proc_value);
-               stc_monitor_proc_update_ground(bg_classid, bg_app_id, proc_value);
+               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;
@@ -674,7 +675,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                memset(&proc_value, 0, sizeof(stc_proc_value_s));
 
                classid = get_classid_by_app_id(app_id, FALSE);
-               is_exist = stc_monitor_app_lookup(classid);
+               is_exist = stc_plugin_monitor_lookup_app(classid);
                if (is_exist) {
                        app_value.type = app_type;
                        app_value.state = STC_APP_STATE_FOREGROUND;
@@ -683,8 +684,8 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                        proc_value.pid = pid;
                        proc_value.ground = STC_APP_STATE_FOREGROUND;
 
-                       stc_monitor_app_add(classid, app_id, pkg_id, app_value);
-                       stc_monitor_proc_add(classid, app_id, proc_value);
+                       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);
@@ -696,8 +697,8 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                        proc_value.pid = pid;
                        proc_value.ground = STC_APP_STATE_BACKGROUND;
 
-                       stc_monitor_app_add(classid, bg_app_id, pkg_id, app_value);
-                       stc_monitor_proc_add(classid, bg_app_id, proc_value);
+                       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);
                }
@@ -714,7 +715,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                if (classid == STC_UNKNOWN_CLASSID)
                        classid = get_classid_by_app_id(app_id, FALSE);
 
-               stc_monitor_proc_remove(classid, pid);
+               stc_plugin_monitor_remove_proc(classid, pid);
 
                FREE(bg_app_id);
                break;
index 889f44a217b1c17a086faaf7f03c5a967741c239..b64cfbda3aecc21c7caee6e9d112980e89404466 100644 (file)
@@ -15,6 +15,7 @@ FOREACH(flag ${tether_plugin_CFLAGS})
 ENDFOREACH(flag)
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/plugin/monitor/include)
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Werror -fvisibility=hidden")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
index 5270aed9d2dc5d5bf00e16c29c487a24696b7ab2..4b1e0b8acb275353344118b5727f9e9d2e68af9c 100755 (executable)
@@ -23,8 +23,8 @@
 #include <errno.h>
 #include <glib.h>
 
-#include "stc-monitor.h"
 #include "stc-plugin-tether.h"
+#include "stc-manager-plugin-monitor.h"
 
 static GSList *station_list = NULL;
 static GDBusConnection *connection = NULL;
@@ -49,7 +49,7 @@ static stc_error_e add_station_monitor(gchar *pkg_id, gchar *app_id,
        app_value.processes = NULL;
        g_strlcpy(app_value.mac, mac, STATION_MAC_STR_LEN);
 
-       ret = stc_monitor_app_add(STC_UNKNOWN_CLASSID, app_id, pkg_id, app_value);
+       ret = stc_plugin_monitor_add_app(STC_UNKNOWN_CLASSID, app_id, pkg_id, app_value);
        FREE(app_value.pkg_id);
        FREE(app_value.app_id);
        return ret;
@@ -67,7 +67,7 @@ static stc_error_e remove_station_monitor(gchar *pkg_id, gchar *app_id)
 
        sta_app_id = g_strconcat(app_id, STC_TETHERING_APP_SUFFIX, NULL);
 
-       ret = stc_monitor_app_remove(STC_UNKNOWN_CLASSID, sta_app_id);
+       ret = stc_plugin_monitor_remove_app(STC_UNKNOWN_CLASSID, sta_app_id);
 
        FREE(sta_app_id);
        return ret;
@@ -281,7 +281,7 @@ int tether_plugin_init(void)
                                                   _mobileap_signal_cb,
                                                   NULL, NULL);
 
-       STC_LOGI("tether plugin initialised");
+       STC_LOGI("tether plugin initialized");
        return 0;
 }
 
index 2ec01789eea0fc506bf27208b37c57bbd1268ea9..d23addecb5e472749c1916483906ea95f8dfb42c 100644 (file)
@@ -24,7 +24,6 @@ ENDFOREACH(flag)
 SET(SOURCE_DIR                  ${CMAKE_SOURCE_DIR}/src)
 SET(HELPER_SOURCE_DIR           ${SOURCE_DIR}/helper)
 SET(DATABASE_SOURCE_DIR         ${SOURCE_DIR}/database)
-SET(MONITOR_SOURCE_DIR          ${SOURCE_DIR}/monitor)
 SET(CONFIGURE_SOURCE_DIR        ${SOURCE_DIR}/configure)
 SET(LIMITATION_SOURCE_DIR       ${SOURCE_DIR}/limitation)
 SET(PLUGIN_DIR                  ${CMAKE_SOURCE_DIR}/plugin)
@@ -33,6 +32,7 @@ SET(EXCEPTION_SOURCE_DIR        ${PLUGIN_DIR}/exception)
 SET(PROCFS_SOURCE_DIR           ${PLUGIN_DIR}/procfs)
 SET(PCAP_SOURCE_DIR             ${PLUGIN_DIR}/pcap)
 SET(TETHER_SOURCE_DIR           ${PLUGIN_DIR}/tether)
+SET(MONITOR_SOURCE_DIR          ${PLUGIN_DIR}/monitor)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/interfaces)
@@ -43,9 +43,6 @@ INCLUDE_DIRECTORIES(${HELPER_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${DATABASE_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${DATABASE_SOURCE_DIR}/include)
 
-INCLUDE_DIRECTORIES(${MONITOR_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${MONITOR_SOURCE_DIR}/include)
-
 INCLUDE_DIRECTORIES(${CONFIGURE_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${CONFIGURE_SOURCE_DIR}/include)
 
@@ -57,14 +54,14 @@ INCLUDE_DIRECTORIES(${EXCEPTION_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${PROCFS_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${PCAP_SOURCE_DIR}/include)
 INCLUDE_DIRECTORIES(${TETHER_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${MONITOR_SOURCE_DIR}/include)
 
 FILE(GLOB SOURCE_SRCS        ${SOURCE_DIR}/*.c)
 FILE(GLOB HELPER_SRCS        ${HELPER_SOURCE_DIR}/*.c)
-FILE(GLOB MONITOR_SRCS       ${MONITOR_SOURCE_DIR}/*.c)
 FILE(GLOB CONFIGURE_SRCS     ${CONFIGURE_SOURCE_DIR}/*.c)
 FILE(GLOB LIMITATION_SRCS    ${LIMITATION_SOURCE_DIR}/*.c)
 
-SET(SRCS ${SRCS} ${SOURCE_SRCS} ${HELPER_SRCS} ${MONITOR_SRCS} ${CONFIGURE_SRCS} ${LIMITATION_SRCS})
+SET(SRCS ${SRCS} ${SOURCE_SRCS} ${HELPER_SRCS} ${CONFIGURE_SRCS} ${LIMITATION_SRCS})
 
 IF("${ENABLE_DATABASE}" STREQUAL "YES")
        FILE(GLOB DATABASE_SRCS           ${DATABASE_SOURCE_DIR}/*.c)
old mode 100644 (file)
new mode 100755 (executable)
index 372eb03..a4c2a3d
@@ -109,11 +109,9 @@ stc_error_e stc_db_initialize(void)
 
        stc_db_initialize_once();
 
-#ifndef TIZEN_TV_EXT
        EXEC(STC_ERROR_NONE, table_statistics_prepare(database));
        EXEC(STC_ERROR_NONE, table_restrictions_prepare(database));
        EXEC(STC_ERROR_NONE, table_counters_prepare(database));
-#endif
        EXEC(STC_ERROR_NONE, table_firewall_prepare(database));
        EXEC(STC_ERROR_NONE, stc_init_db_guard());
 
@@ -134,11 +132,9 @@ gboolean stc_db_deinitialize(void)
                return TRUE; //LCOV_EXCL_LINE
        }
 
-#ifndef TIZEN_TV_EXT
        table_statistics_finalize();
        table_restrictions_finalize();
        table_counters_finalize();
-#endif
        table_firewall_finalize();
        sqlite3_close(database);
 
old mode 100644 (file)
new mode 100755 (executable)
index 9bd49a2..96c15c5
@@ -271,7 +271,7 @@ handle_error:
        return ret;
 }
 
-stc_error_e table_counters_get(uint64_t restriction_id,
+API stc_error_e table_counters_get(uint64_t restriction_id,
                               table_counters_info *info)
 {
        stc_error_e error_code = STC_ERROR_NONE;
@@ -322,7 +322,7 @@ handle_error:
 }
 
 //LCOV_EXCL_START
-stc_error_e table_counters_update_counters(const table_counters_info *info)
+API stc_error_e table_counters_update_counters(const table_counters_info *info)
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = update_counter;
@@ -359,7 +359,7 @@ handle_error:
 }
 //LCOV_EXCL_STOP
 
-stc_error_e table_counters_get_timestamps(uint64_t restriction_id,
+API stc_error_e table_counters_get_timestamps(uint64_t restriction_id,
                                                                                table_counters_info *info)
 {
        stc_error_e error_code = STC_ERROR_NONE;
@@ -411,7 +411,7 @@ handle_error:
 }
 
 //LCOV_EXCL_START
-stc_error_e table_counters_update_timestamps(const table_counters_info *info)
+API stc_error_e table_counters_update_timestamps(const table_counters_info *info)
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = update_timestamp;
@@ -443,7 +443,7 @@ handle_error:
 //LCOV_EXCL_STOP
 
 
-stc_error_e table_counters_delete(uint64_t restriction_id)
+API stc_error_e table_counters_delete(uint64_t restriction_id)
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = delete_counter;
old mode 100644 (file)
new mode 100755 (executable)
index 929449d..debb04d
@@ -320,7 +320,7 @@ handle_error:
        return error_code;
 }
 
-stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
+API stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
                                       void *user_data)
 {
        __STC_LOG_FUNC_ENTER__;
index f8db77b660d9ce06de76753d03792a1abfb24dfb..ffb4b97fca63e3042342f6602cd033fa87f20420 100755 (executable)
@@ -500,7 +500,7 @@ handle_error:
        return error_code;
 }
 
-stc_error_e table_statistics_per_app(const char *app_id,
+API stc_error_e table_statistics_per_app(const char *app_id,
                                     table_statistics_select_rule *rule,
                                     table_statistics_info_cb info_cb,
                                     void *user_data)
@@ -578,7 +578,7 @@ handle_error:
        return error_code;
 }
 
-stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
+API stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                                    stc_db_app_stats *stat,
                                    time_t last_touch_time)
 {
@@ -621,7 +621,7 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                goto handle_error; //LCOV_EXCL_LINE
        }
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGD("App stat recorded [\033[0;34m%s\033[0;m] "
                        "rcv[%lld] snd[%lld]", stat->app_id, rcv, snd);
 
index fbb0024842e50f221aefabc86a7893baecf3aeb8..1d5ba2b7e6f4ec3fab2d1d7e60d7621bf75cf545 100755 (executable)
@@ -119,7 +119,7 @@ int cgroup_write_node_uint32(const char *cgroup_name,
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGD("cgroup_buf %s, value %d\n", buf, value); //LCOV_EXCL_LINE
 
        return fwrite_uint(buf, value);
@@ -131,7 +131,7 @@ int cgroup_write_node_str(const char *cgroup_name,
        char buf[MAX_PATH_LENGTH];
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGD("cgroup_buf %s, string %s\n", buf, string); //LCOV_EXCL_LINE
 
        return fwrite_str(buf, string);
@@ -145,7 +145,7 @@ int cgroup_read_node_uint32(const char *cgroup_name,
        snprintf(buf, sizeof(buf), "%s/%s", cgroup_name, file_name);
        ret = fread_uint(buf, value);
 
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
+       if (STC_STAT_LOG)
                STC_LOGD("cgroup_buf %s, value %d\n", buf, *value); //LCOV_EXCL_LINE
 
        return ret;
@@ -222,7 +222,7 @@ int cgroup_set_release_agent(const char *cgroup_subsys,
        return cgroup_write_node_str(buf, NOTIFY_ON_RELEASE, "1");
 }
 
-void cgroup_init(void)
+API void cgroup_init(void)
 {
        /* create stc cgroup directory */
        cgroup_make_subdir(CGROUP_NETWORK, STC_CGROUP_NAME, NULL);
index 636ef5da3b8aa6ebaeb54e0947d078a6d483659c..53dcad05431dfeb690fa2ebc15a5f72ebba71afa 100755 (executable)
@@ -29,17 +29,14 @@ int fwrite_str(const char *path, const char *str)
        assert(str);
 
        t = realpath(path, NULL);
-       ret_value_errno_msg_if(!t, -errno,
-                              "Fail to get realpath %s", path);
+       ret_value_if(!t, -errno);
        free(t);
 
        f = fopen(path, "w");
-       ret_value_errno_msg_if(!f, -errno,
-                              "Fail to open file %s", path);
+       ret_value_if(!f, -errno);
 
        ret = fputs(str, f);
-       ret_value_errno_msg_if(ret == EOF, errno ? -errno : -EIO,
-                              "Fail to write file");
+       ret_value_if(ret == EOF, errno ? -errno : -EIO);
 
        return STC_ERROR_NONE;
 }
@@ -50,8 +47,7 @@ int fwrite_uint(const char *path, const uint32_t number)
        int ret;
 
        ret = asprintf(&digit_buf, "%d", number);
-       ret_value_errno_msg_if(ret < 0, -ENOMEM,
-                              "sprintf failed\n");
+       ret_value_if(ret < 0, -ENOMEM);
 
        return fwrite_str(path, digit_buf);
 }
@@ -62,12 +58,10 @@ int fread_uint(const char *path, uint32_t *number)
        int ret;
 
        f = fopen(path, "r");
-       ret_value_errno_msg_if(!f, -errno,
-                              "Fail to open %s file.", path);
+       ret_value_if(!f, -errno);
 
        ret = fscanf(f, "%u", number);
-       ret_value_errno_msg_if(ret == EOF, -errno,
-                              "Fail to read file\n");
+       ret_value_if(ret == EOF, -errno);
 
        return STC_ERROR_NONE;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 9a2cde8..1e140b7
@@ -891,7 +891,7 @@ done:
        return ret;
 }
 
-stc_error_e iptables_flush_chains(void)
+API stc_error_e iptables_flush_chains(void)
 {
        stc_error_e ret = STC_ERROR_NONE;
        stc_s *stc = stc_get_manager();
@@ -982,6 +982,12 @@ stc_error_e iptables_init(void)
                goto done; //LCOV_EXCL_LINE
        }
 
+       ret = __ip6tables_add_chain(stc->connection, STC_TETHER_CHAIN);
+       if (ret != STC_ERROR_NONE) {
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               goto done; //LCOV_EXCL_LINE
+       }
+
        ret = _iptables_add_in_chain_jump_rule();
        if (ret != STC_ERROR_NONE) {
                __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
index 3f460f7caf52be5cd7830dfaff5a6a019a37a8ed..350dfb676eaa4058c21cbc2f0c93c387410670a7 100755 (executable)
@@ -87,7 +87,7 @@ static stc_error_e __get_classid_from_cgroup(const char *cgroup,
        return STC_ERROR_NONE;
 }
 
-stc_error_e init_current_classid(void)
+API stc_error_e init_current_classid(void)
 {
        int ret = 0;
        struct stat stat_buf;
@@ -172,12 +172,12 @@ API uint32_t get_classid_by_app_id(const char *app_id, int create)
        return classid;
 
 handle_error:
-
-       STC_LOGE("error_code: [%d]", ret); //LCOV_EXCL_LINE
+       if (STC_DEBUG_LOG)
+               STC_LOGE("error_code: [%d]", ret); //LCOV_EXCL_LINE
        return STC_UNKNOWN_CLASSID; //LCOV_EXCL_LINE
 }
 
-stc_error_e place_pids_to_net_cgroup(const int pid, const char *app_id)
+API stc_error_e place_pids_to_net_cgroup(const int pid, const char *app_id)
 {
        char child_buf[21 + MAX_DEC_SIZE(int) + MAX_DEC_SIZE(int) + 1];
        const char *path_to_net_cgroup_dir = NULL;
index fbe17ca37c264f955767674f5fd381d59e88196d..1d6d0c690fcf49043e29aa95cceae47b42d2c6ba 100755 (executable)
@@ -223,7 +223,7 @@ stc_error_e nfacct_send_get_quotas(struct counter_arg *carg, const char *name)
                                        NFACCT_F_QUOTA_BYTES);
 }
 
-stc_error_e nfacct_send_get_all(struct counter_arg *carg)
+API stc_error_e nfacct_send_get_all(struct counter_arg *carg)
 {
        /* get and reset everything, used when quiting */
        return internal_nfacct_send_get(carg, NFNL_MSG_ACCT_GET_CTRZERO, NULL,
@@ -252,7 +252,7 @@ static stc_iface_type_e convert_to_iftype(int type)
                        type > STC_IFACE_UNKNOWN) ? type : STC_IFACE_UNKNOWN;
 }
 
-bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt)
+API bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt)
 {
        char *iftype_part;
        char *classid_part;
@@ -396,7 +396,7 @@ next:
                params->post_eval_attr(carg);
 }
 
-netlink_serialization_command *
+API netlink_serialization_command *
 netlink_create_command(struct netlink_serialization_params *params)
 {
        static netlink_serialization_command command = {0,};
@@ -803,7 +803,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule)
        return STC_ERROR_NONE;
 }
 
-stc_error_e produce_net_rule(nfacct_rule_s *rule)
+API stc_error_e produce_net_rule(nfacct_rule_s *rule)
 {
        stc_error_e ret = STC_ERROR_NONE;
 
old mode 100644 (file)
new mode 100755 (executable)
index 2c3c8f9..ff9d1af
@@ -67,7 +67,7 @@ void fill_attribute_list(struct rtattr **atb, const int max_len,
 /* read netlink message from socket
  * return opaque pointer to genl structure
  */
-int read_netlink(int sock, void *buf, size_t len)
+API int read_netlink(int sock, void *buf, size_t len)
 {
        ssize_t ret;
        struct sockaddr_nl addr;
diff --git a/src/monitor/include/stc-connection.h b/src/monitor/include/stc-connection.h
deleted file mode 100644 (file)
index 85d27de..0000000
+++ /dev/null
@@ -1,73 +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_CONNECTION_H__
-#define __STC_CONNECTION_H__
-
-#include <glib.h>
-#include "stc-error.h"
-#include "stc-manager.h"
-#include "stc-manager-util.h"
-
-#define IMSI_LENGTH 16
-#define SHA256_DIGEST_LENGTH 32
-
-#define TETHERING_USB_IF   "usb0"
-#define TETHERING_WIFI_IF  "wlan0"
-#define TETHERING_BT_IF    "bnep0"
-#define TETHERING_P2P_IF   "p2p0"
-
-/**
- * @brief Tethering interface info
- */
-typedef struct {
-       gchar *ifname;
-       stc_iface_type_e type;
-} tether_iface_s;
-
-/**
- * @brief connection information will be fetched from connman
- */
-typedef struct {
-       /* to identify each connection uniquely */
-       gchar *path;
-
-       /* profile info */
-       stc_iface_type_e type;
-       gchar *ifname;
-
-       /* cellular profile only else it is always false */
-       gboolean roaming;
-
-       /* only present when default profile is cellular */
-       char subscriber_id[SHA256_DIGEST_LENGTH * 2 + 1];
-
-       /* hardware network protocol type */
-       stc_hw_net_protocol_type_e hw_net_protocol_type;
-
-       /* tethering status */
-       gboolean tether_state;
-
-       /* tethering interface */
-       tether_iface_s tether_iface;
-} stc_connection_s;
-
-stc_error_e stc_connection_monitor_init(stc_s *stc);
-stc_error_e stc_connection_monitor_deinit(stc_s *stc);
-
-GSList *stc_get_connection_list(void);
-
-#endif /* __STC_CONNECTION_H__ */
diff --git a/src/monitor/include/stc-monitor-app.h b/src/monitor/include/stc-monitor-app.h
deleted file mode 100644 (file)
index 3a312fb..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2017 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_MONITOR_APP_H__
-#define __STC_MONITOR_APP_H__
-
-#include <glib.h>
-
-#include "stc-error.h"
-#include "stc-manager.h"
-#include "stc-monitor-context.h"
-#include "stc-connection.h"
-
-#define MAC_ADDRESS_LEN 18
-#define SUBSCRIBERID_NONE "none_subid"
-
-typedef struct {
-       uint32_t classid;  /**< classid for a package */
-       gchar *pkg_id;  /**< package id */
-       gchar *app_id;  /**< application id */
-       stc_app_type_e type;  /**< type of application */
-       stc_app_state_e state;
-       stc_data_counter_s data_usage;
-       stc_data_counter_s counter;
-       GHashTable *processes;  /**< applications instances */
-       char mac[MAC_ADDRESS_LEN+1]; /**< application mac address */
-} stc_app_value_s;
-
-void stc_monitor_app_update_counter(stc_app_value_s *value,
-                                classid_bytes_context_s *context);
-
-void stc_monitor_app_update_iface_counter(classid_bytes_context_s *context);
-
-gboolean stc_monitor_app_flush_stats_to_db(gpointer user_data);
-
-stc_error_e stc_monitor_app_add(uint32_t classid,
-                               const char *app_id,
-                               const char *pkg_id,
-                               const stc_app_value_s value);
-
-void stc_monitor_app_add_by_iface(const char *app_id);
-
-void stc_monitor_app_add_monitor(gpointer key,
-                               gpointer value, gpointer data);
-
-void stc_monitor_app_add_by_connection(stc_connection_s *conn);
-
-void stc_monitor_app_add_accept(gpointer key,
-                               gpointer value, gpointer data);
-
-stc_error_e stc_monitor_app_remove(uint32_t classid, const char *app_id);
-
-void stc_monitor_app_remove_monitor(gpointer key,
-                               gpointer value, gpointer data);
-
-void stc_monitor_app_remove_by_connection(stc_connection_s *conn);
-
-void stc_monitor_app_remove_accept(gpointer key,
-                               gpointer value, gpointer data);
-
-gboolean stc_monitor_app_lookup(uint32_t classid);
-
-GHashTable *stc_monitor_apps_init(void);
-
-#endif /* __STC_MONITOR_APP_H__ */
diff --git a/src/monitor/include/stc-monitor-context.h b/src/monitor/include/stc-monitor-context.h
deleted file mode 100644 (file)
index 82d15f7..0000000
+++ /dev/null
@@ -1,55 +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_MONITOR_CONTEXT_H__
-#define __STC_MONITOR_CONTEXT_H__
-
-#include "stc-manager.h"
-
-typedef struct {
-       time_t now;
-       time_t month_start_ts;
-       time_t week_start_ts;
-       time_t day_start_ts;
-       int is_updated;
-} reset_time_limits_context_s;
-
-typedef struct {
-       struct nfacct_rule *counter;
-       int64_t bytes;
-       gboolean data_limit_exceeded;
-} classid_bytes_context_s;
-
-/**
- * @brief structure to store system info
- */
-typedef struct {
-       int contr_sock;  /**< socket used for getting kernel counters */
-       guint contr_timer_id;  /**< timer id for periodically getting kernel counters */
-       guint contr_gsource_id;
-       stc_data_counter_s du_curr;  /**< current data usage */
-       GHashTable *rstns;  /**< restriction rules */
-       gboolean rstns_updated;
-       GHashTable *apps;  /**< monitored applications */
-       gboolean apps_updated;
-       gboolean background_state;
-       time_t last_month_ts;
-       time_t last_week_ts;
-       time_t last_day_ts;
-       int month_start_date;
-} stc_system_s;
-
-#endif /* __STC_MONITOR_CONTEXT_H__ */
diff --git a/src/monitor/include/stc-monitor-ipt.h b/src/monitor/include/stc-monitor-ipt.h
deleted file mode 100644 (file)
index ee38069..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2017 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_MONITOR_IPT_H__
-#define __STC_MONITOR_IPT_H__
-
-#include "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);
-stc_error_e stc_monitor_ipt_del_in(struct nfacct_rule *counter);
-stc_error_e stc_monitor_ipt_del_out(struct nfacct_rule *counter);
-
-stc_error_e stc_monitor_ip6t_add_in(struct nfacct_rule *counter);
-stc_error_e stc_monitor_ip6t_add_out(struct nfacct_rule *counter);
-stc_error_e stc_monitor_ip6t_del_in(struct nfacct_rule *counter);
-stc_error_e stc_monitor_ip6t_del_out(struct nfacct_rule *counter);
-
-stc_error_e stc_monitor_tether_add_in(struct nfacct_rule *counter,
-               const gchar *ipaddr);
-stc_error_e stc_monitor_tether_add_out(struct nfacct_rule *counter,
-               const gchar *ipaddr);
-stc_error_e stc_monitor_tether_del_in(struct nfacct_rule *counter,
-               const gchar *ipaddr);
-stc_error_e stc_monitor_tether_del_out(struct nfacct_rule *counter,
-               const gchar *ipaddr);
-
-#endif /* __STC_MONITOR_IPT_H__ */
diff --git a/src/monitor/include/stc-monitor-proc.h b/src/monitor/include/stc-monitor-proc.h
deleted file mode 100644 (file)
index 602912b..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2017 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_MONITOR_PROC_H__
-#define __STC_MONITOR_PROC_H__
-
-#include <glib.h>
-
-#include "stc-error.h"
-#include "stc-manager.h"
-
-typedef struct {
-       pid_t pid;
-       stc_app_state_e ground;
-} stc_proc_value_s;
-
-typedef struct {
-       pid_t pid;
-       stc_app_value_s *app_value;
-       gboolean entry_removed;
-} remove_pid_context_s;
-
-stc_error_e stc_monitor_proc_update_ground(uint32_t classid,
-                                               const char *app_id,
-                                               const stc_proc_value_s value);
-
-stc_error_e stc_monitor_proc_add(uint32_t classid,
-                                               const char *app_id,
-                                               const stc_proc_value_s value);
-
-stc_error_e stc_monitor_proc_remove(uint32_t classid,
-                                               pid_t pid);
-
-stc_error_e stc_monitor_proc_move(uint32_t from,
-                                               uint32_t to);
-
-#endif /* __STC_MONITOR_PROC_H__ */
diff --git a/src/monitor/include/stc-monitor-rstn.h b/src/monitor/include/stc-monitor-rstn.h
deleted file mode 100644 (file)
index ecf404d..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2017 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_MONITOR_RSTN_H__
-#define __STC_MONITOR_RSTN_H__
-
-#include <glib.h>
-
-#include "stc-error.h"
-#include "stc-manager.h"
-#include "stc-monitor-context.h"
-#include "stc-connection.h"
-#include "stc-restriction.h"
-#include "table-restrictions.h"
-
-#define GRANULARITY 10
-
-#define MAX_INT_LENGTH 128
-#define MAX_KEY_LENGTH 128
-
-typedef enum {
-       STC_RSTN_LIMIT_TYPE_DATA_WARN,
-       STC_RSTN_LIMIT_TYPE_DATA,
-       STC_RSTN_LIMIT_TYPE_MONTHLY,
-       STC_RSTN_LIMIT_TYPE_WEEKLY,
-       STC_RSTN_LIMIT_TYPE_DAILY,
-       STC_RSTN_LIMIT_TYPE_MAX
-} stc_rstn_limit_type_e;
-
-typedef enum {
-       STC_RSTN_STATE_INIT = -1,
-       STC_RSTN_STATE_UNSET,
-       STC_RSTN_STATE_SET,
-} stc_rstn_noti_state_e;
-
-typedef struct {
-       uint32_t classid;
-       char *app_id;
-       stc_iface_type_e iftype;
-       char *ifname;
-       char *subscriber_id;
-       stc_roaming_type_e roaming;
-       char *mac;
-
-       uint64_t restriction_id;
-       stc_rstn_state_e rstn_state;
-       stc_rstn_type_e rstn_type;
-
-       int64_t counter[STC_RSTN_LIMIT_TYPE_MAX];
-       int64_t limit[STC_RSTN_LIMIT_TYPE_MAX];
-       int32_t limit_exceeded;
-       int32_t limit_notified;
-
-       int month_start_date;
-       time_t month_start_ts;
-} stc_rstn_data_s;
-
-typedef struct {
-       GSList *rules;
-} stc_rstn_value_s;
-
-typedef struct {
-       time_t month_start_ts;
-       time_t week_start_ts;
-       time_t day_start_ts;
-       int64_t monthly_stat;
-       int64_t weekly_stat;
-       int64_t daily_stat;
-} stc_rstn_cumulative_data_s;
-
-void stc_monitor_rstn_reset_time_counters_if_required(void);
-
-void stc_monitor_rstn_update_counter(gpointer data,
-                                       gpointer user_data);
-
-void stc_monitor_rstn_update_iface_counter(classid_bytes_context_s *context);
-
-void stc_monitor_rstn_action_when_limit_exceeded(stc_rstn_limit_type_e limit_type,
-                                               stc_rstn_data_s *rstn_data,
-                                               classid_bytes_context_s *context);
-
-gboolean stc_monitor_rstn_flush_contr_to_db(gpointer user_data);
-
-stc_error_e stc_monitor_rstn_add(const table_restrictions_info *info);
-
-void stc_monitor_rstn_add_for_app(uint32_t classid);
-
-void stc_monitor_rstn_add_by_connection(stc_connection_s *conn);
-
-stc_error_e stc_monitor_rstn_remove(const table_restrictions_info *info);
-
-void stc_monitor_rstn_remove_for_app(uint32_t classid);
-
-void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn);
-
-void stc_monitor_rstns_load(void);
-
-GHashTable *stc_monitor_rstns_init(void);
-
-#endif /* __STC_MONITOR_RSTN_H__ */
diff --git a/src/monitor/include/stc-monitor.h b/src/monitor/include/stc-monitor.h
deleted file mode 100644 (file)
index 32404b0..0000000
+++ /dev/null
@@ -1,89 +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_MONITOR_H__
-#define __STC_MONITOR_H__
-
-#include <glib.h>
-#include "stc-error.h"
-#include "stc-manager.h"
-#include "stc-manager-util.h"
-#include "stc-monitor-context.h"
-#include "stc-monitor-app.h"
-#include "stc-monitor-proc.h"
-#include "stc-monitor-rstn.h"
-#include "helper-nl.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
-
-/**
- * @brief initializes stc monitor module
- */
-stc_error_e stc_monitor_init(void);
-
-/**
- * @brief deinitializes stc monitor module
- */
-stc_error_e stc_monitor_deinit(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);
-
-stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline);
-
-#endif /* __STC_MONITOR_H__ */
diff --git a/src/monitor/include/stc-time.h b/src/monitor/include/stc-time.h
deleted file mode 100644 (file)
index d331bce..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2017 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_TIME_H__
-#define __STC_MANAGER_TIME_H__
-
-time_t stc_time_get_day_start(time_t now);
-time_t stc_time_get_week_start(time_t now);
-time_t stc_time_get_month_start(time_t now, int month_start_date);
-
-#endif /* __STC_MANAGER_TIME_H__ */
diff --git a/src/monitor/stc-connection.c b/src/monitor/stc-connection.c
deleted file mode 100644 (file)
index fb16297..0000000
+++ /dev/null
@@ -1,737 +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.
- */
-
-#include <vconf/vconf.h>
-#include <openssl/sha.h>
-
-#include "stc-monitor.h"
-#include "stc-firewall.h"
-#include "stc-manager-gdbus.h"
-#include "stc-connection.h"
-
-/* connman service dbus details */
-#define CONNMAN_SERVICE                          "net.connman"
-#define CONNMAN_PATH                             "/net/connman"
-
-#define CONNMAN_MANAGER_PATH                     "/"
-#define CONNMAN_MANAGER_INTERFACE                CONNMAN_SERVICE ".Manager"
-#define CONNMAN_SERVICE_INTERFACE                CONNMAN_SERVICE ".Service"
-
-#define CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX  CONNMAN_PATH "/service/cellular_"
-#define CONNMAN_WIFI_SERVICE_PROFILE_PREFIX      CONNMAN_PATH "/service/wifi_"
-#define CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX  CONNMAN_PATH "/service/ethernet_"
-#define CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/bluetooth_"
-
-#define CONNMAN_SIGNAL_PROPERTY_CHANGED          "PropertyChanged"
-
-/* telephony service dbus details */
-#define TELEPHONY_SERVICE                        "org.tizen.telephony"
-#define TELEPHONY_DEFAULT_PATH                   "/org/tizen/telephony"
-
-#define TELEPHONY_SERVICE_MANAGER                TELEPHONY_SERVICE".Manager"
-#define TELEPHONY_SIM_INTERFACE                  TELEPHONY_SERVICE".Sim"
-
-#define TELEPHONY_GET_MODEMS                     "GetModems"
-#define TELEPHONY_GET_IMSI                       "GetIMSI"
-
-#define SIM_SLOT_SINGLE 1
-
-#define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE     "db/telephony/dualsim/default_data_service"
-
-stc_connection_s *g_default_connection = NULL;
-GSList *g_connection_list = NULL;
-guint g_connection_sub_id = 0;
-
-static void __conn_list_free(gpointer value)
-{
-       stc_connection_s *conn = (stc_connection_s *)value;
-
-       FREE(conn->path);
-       FREE(conn->ifname);
-       FREE(conn->tether_iface.ifname);
-       FREE(conn);
-}
-
-static gint __conn_list_comp(gconstpointer a, gconstpointer b)
-{
-       stc_connection_s *conn = (stc_connection_s *)a;
-       char *path = (char *)b;
-
-       if (g_strcmp0(conn->path, path) == 0)
-               return 0;
-
-       return -1;
-}
-
-static void __update_monitor_by_conn(gpointer data, gpointer user_data)
-{
-       stc_connection_s *conn = (stc_connection_s *)data;
-
-       stc_monitor_update_by_connection(conn);
-}
-
-static int __telephony_get_current_sim(void)
-{
-       int sim_slot_count = 0;
-       int current_sim = 0;
-
-       if (vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT_COUNT, &sim_slot_count) != 0) {
-               STC_LOGD("failed to get sim slot count"); //LCOV_EXCL_LINE
-               return -1; //LCOV_EXCL_LINE
-       }
-
-       if (sim_slot_count == SIM_SLOT_SINGLE) {
-              STC_LOGD("It's single sim model"); //LCOV_EXCL_LINE
-              return current_sim; //LCOV_EXCL_LINE
-       }
-
-       if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &current_sim) != 0) {
-               STC_LOGD("failed to get default data service = %d\n", //LCOV_EXCL_LINE
-                        current_sim);
-               return -1; //LCOV_EXCL_LINE
-       }
-
-       return current_sim;
-}
-
-static void __make_imsi_to_subscriber_id(stc_connection_s *conn, char *imsi)
-{
-       int i = 0;
-       SHA256_CTX ctx;
-       unsigned char md[SHA256_DIGEST_LENGTH];
-
-       SHA256_Init(&ctx);
-       SHA256_Update(&ctx, imsi, strlen(imsi));
-       SHA256_Final(md, &ctx);
-
-       for (i = 0; i < SHA256_DIGEST_LENGTH; ++i)
-               snprintf(conn->subscriber_id + (i * 2), 3, "%02x", md[i]);
-}
-
-static void __telephony_get_modem_subscriber_id(GDBusConnection *connection,
-                               stc_connection_s *conn, const char *default_modem_name)
-{
-       GVariant *message = NULL;
-       char tel_path[MAX_PATH_LENGTH];
-       char imsi[IMSI_LENGTH];
-       const char *plmn = NULL;
-       int plmn_len = 0;
-       const char *msin = NULL;
-       int msin_len = 0;
-
-       snprintf(tel_path, sizeof(tel_path), "%s/%s", TELEPHONY_DEFAULT_PATH,
-                default_modem_name);
-       message = stc_manager_gdbus_call_sync(connection,
-                                             TELEPHONY_SERVICE,
-                                             tel_path,
-                                             TELEPHONY_SIM_INTERFACE,
-                                             TELEPHONY_GET_IMSI,
-                                             NULL);
-       if (message == NULL) {
-               STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
-               goto done; //LCOV_EXCL_LINE
-       }
-
-       DEBUG_PARAMS(message);
-       DEBUG_PARAM_TYPE(message);
-       g_variant_get(message, "(&s&s)", &plmn, &msin);
-       if (plmn)
-               plmn_len = strlen(plmn);
-       if (msin)
-               msin_len = strlen(msin);
-
-       if (msin_len + plmn_len >= IMSI_LENGTH) {
-               STC_LOGD("Incorrect length of mobile subscriber identifier + net id"); //LCOV_EXCL_LINE
-               goto done; //LCOV_EXCL_LINE
-       }
-
-       snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin);
-       __make_imsi_to_subscriber_id(conn, imsi);
-
-done:
-       g_variant_unref(message);
-       return;
-}
-
-static void __telephony_update_default_modem_subscriber_id(GDBusConnection *connection,
-                               stc_connection_s *conn)
-{
-       GVariant *message = NULL;
-       GVariantIter *iter = NULL;
-       gchar *default_modem_name = NULL;
-       gchar *modem_name = NULL;
-       int current_sim = __telephony_get_current_sim();
-
-       if (current_sim < 0) {
-               STC_LOGI("Sim not found"); //LCOV_EXCL_LINE
-               return; //LCOV_EXCL_LINE
-       }
-
-       message = stc_manager_gdbus_call_sync(connection,
-                                             TELEPHONY_SERVICE,
-                                             TELEPHONY_DEFAULT_PATH,
-                                             TELEPHONY_SERVICE_MANAGER,
-                                             TELEPHONY_GET_MODEMS,
-                                             NULL);
-       if (message == NULL) {
-               STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
-               return; //LCOV_EXCL_LINE
-       }
-
-       g_variant_get(message, "(as)", &iter);
-       DEBUG_PARAMS(message);
-       DEBUG_PARAM_TYPE(message);
-       while (g_variant_iter_loop(iter, "s", &modem_name)) {
-               if (current_sim == 0) {
-                       default_modem_name = g_strdup(modem_name);
-                       FREE(modem_name);
-                       break;
-               }
-               current_sim--; //LCOV_EXCL_LINE
-       }
-
-       __telephony_get_modem_subscriber_id(connection, conn, default_modem_name);
-
-       FREE(default_modem_name);
-       g_variant_iter_free(iter);
-       g_variant_unref(message);
-       return;
-}
-
-static void __print_connection_info(stc_connection_s *conn)
-{
-       STC_LOGI("============= connection info ============");
-       STC_LOGI("path    [%s]", conn->path);
-       STC_LOGI("type    [%d]", conn->type);
-       STC_LOGI("ifname  [%s]", conn->ifname);
-       STC_LOGI("roaming [%u]", conn->roaming ? TRUE : FALSE);
-       if (conn->type == STC_IFACE_DATACALL)
-               STC_LOGI("sub_id  [%s]", conn->subscriber_id);
-       STC_LOGI("==================================================");
-}
-
-static void __print_tether_connection_info(void)
-{
-       STC_LOGI("============= tethering connection info ============");
-       STC_LOGI("mode    [%u]", g_default_connection->tether_state ? TRUE : FALSE);
-       STC_LOGI("type    [%d]", g_default_connection->tether_iface.type);
-       STC_LOGI("ifname  [%s]", g_default_connection->tether_iface.ifname);
-       STC_LOGI("====================================================");
-}
-
-static gboolean __is_cellular_internet_profile(const char *profile)
-{
-       const char internet_suffix[] = "_1";
-
-       if (profile == NULL)
-               return FALSE;
-
-       if (g_str_has_prefix(profile, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX)
-           == TRUE) {
-               char *suffix = strrchr(profile, '_');
-               if (g_strcmp0(suffix, internet_suffix) == 0)
-                       return TRUE;
-       }
-
-       return FALSE;
-}
-
-static gboolean __is_cellular_profile(const char *profile)
-{
-       if (profile == NULL)
-               return FALSE;
-
-       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
-                               CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX);
-}
-
-static gboolean __is_wifi_profile(const char *profile)
-{
-       if (profile == NULL)
-               return FALSE;
-
-       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
-                               CONNMAN_WIFI_SERVICE_PROFILE_PREFIX);
-}
-
-static gboolean __is_ethernet_profile(const char *profile)
-{
-       if (profile == NULL)
-               return FALSE;
-
-       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
-                               CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX);
-}
-
-static gboolean __is_bluetooth_profile(const char *profile)
-{
-       if (profile == NULL)
-               return FALSE;
-
-       return g_str_has_prefix(profile, //LCOV_EXCL_LINE
-                               CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX);
-}
-
-static gboolean __is_connected(GVariantIter *array)
-{
-       gboolean is_connected = FALSE;
-       GVariant *variant = NULL;
-       gchar *key = NULL;
-
-       while (g_variant_iter_loop(array, "{sv}", &key, &variant)) {
-               if (g_strcmp0(key, "State") != 0)
-                       continue;
-
-               if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
-                       const gchar *state = NULL;
-
-                       state = g_variant_get_string(variant, NULL);
-                       if (g_strcmp0(state, "ready") == 0 ||
-                           g_strcmp0(state, "online") == 0)
-                               is_connected = TRUE;
-               }
-
-               g_free(key);
-               g_variant_unref(variant);
-               break;
-       }
-
-       return is_connected;
-}
-
-static void __get_connection_info(GDBusConnection *connection,
-                               stc_connection_s *conn, const char *object_path)
-{
-       GVariant *message = NULL;
-       GVariantIter *iter = NULL;
-       GVariant *variant = NULL;
-       gchar *key = NULL;
-
-       if (object_path == NULL) {
-               STC_LOGI("Object path is NULL, so information not available.");
-               return;
-       }
-
-       message = stc_manager_gdbus_call_sync(connection,
-                                             CONNMAN_SERVICE,
-                                             object_path,
-                                             CONNMAN_SERVICE_INTERFACE,
-                                             "GetProperties", NULL);
-       if (message == NULL) {
-               STC_LOGE("Failed to get services informations"); //LCOV_EXCL_LINE
-               goto done; //LCOV_EXCL_LINE
-       }
-
-       g_variant_get(message, "(a{sv})", &iter);
-       if (iter == NULL) {
-               STC_LOGE("Profile %s doesn't exist", object_path); //LCOV_EXCL_LINE
-               goto done; //LCOV_EXCL_LINE
-       }
-
-       while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
-               if (g_strcmp0(key, "Ethernet") == 0) {
-                       GVariantIter *iter1 = NULL;
-                       GVariant *variant1 = NULL;
-                       gchar *key1 = NULL;
-
-                       g_variant_get(variant, "a{sv}", &iter1);
-                       if (iter1 == NULL)
-                               continue; //LCOV_EXCL_LINE
-
-                       while (g_variant_iter_loop(iter1, "{sv}", &key1,
-                                                  &variant1)) {
-                               if (g_strcmp0(key1, "Interface") == 0) {
-                                       const gchar *value =
-                                               g_variant_get_string(variant1,
-                                                                    NULL);
-                                       conn->ifname = g_strdup(value);
-                               }
-                       }
-
-                       g_variant_iter_free(iter1);
-
-               } else if (g_strcmp0(key, "Roaming") == 0) {
-                       gboolean roaming = 0;
-
-                       if (g_variant_is_of_type(variant,
-                                                G_VARIANT_TYPE_BOOLEAN)) {
-                               roaming = g_variant_get_boolean(variant);
-                               conn->roaming = roaming;
-                       }
-               }
-       }
-
-done:
-       if (iter)
-               g_variant_iter_free(iter);
-
-       if (message)
-               g_variant_unref(message);
-
-       return;
-}
-
-static stc_error_e __get_connected_profiles(GDBusConnection *connection)
-{
-       GVariant *message = NULL;
-       GVariantIter *iter = NULL;
-       GVariantIter *next;
-       gchar *object_path;
-       stc_connection_s *conn;
-       gboolean default_conn = TRUE;
-
-       message = stc_manager_gdbus_call_sync(connection,
-                                             CONNMAN_SERVICE,
-                                             CONNMAN_MANAGER_PATH,
-                                             CONNMAN_MANAGER_INTERFACE,
-                                             "GetServices", NULL);
-       if (message == NULL) {
-               STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
-               return STC_ERROR_FAIL; //LCOV_EXCL_LINE
-       }
-
-       g_slist_free_full(g_connection_list, __conn_list_free);
-
-       g_variant_get(message, "(a(oa{sv}))", &iter);
-       while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
-               if (object_path == NULL)
-                       continue; //LCOV_EXCL_LINE
-
-               if (__is_cellular_profile(object_path) &&
-                   !__is_cellular_internet_profile(object_path))
-                       continue;
-
-               if (__is_connected(next) == TRUE) {
-                       conn = MALLOC0(stc_connection_s, 1);
-                       if (conn == NULL)
-                               continue;
-
-                       conn->path = g_strdup(object_path);
-                       conn->roaming = FALSE;
-
-                       if (__is_cellular_profile(conn->path)) {
-                               conn->type = STC_IFACE_DATACALL;
-                               __telephony_update_default_modem_subscriber_id(connection, conn);
-                       } else if (__is_wifi_profile(conn->path)) {
-                               conn->type = STC_IFACE_WIFI;
-                       } else if (__is_ethernet_profile(conn->path)) {
-                               conn->type = STC_IFACE_WIRED;
-                       } else if (__is_bluetooth_profile(conn->path)) {
-                               conn->type = STC_IFACE_BLUETOOTH;
-                       } else {
-                               conn->type = STC_IFACE_UNKNOWN;
-                       }
-
-                       __get_connection_info(connection, conn, conn->path);
-                       __print_connection_info(conn);
-
-                       if (default_conn == TRUE) {
-                               g_default_connection = conn;
-                               default_conn = FALSE;
-                       }
-
-                       g_connection_list = g_slist_append(g_connection_list, conn);
-
-                       g_free(object_path);
-                       g_variant_iter_free(next);
-                       continue;
-               }
-       }
-
-       g_variant_iter_free(iter);
-       g_variant_unref(message);
-
-       g_slist_foreach(g_connection_list, __update_monitor_by_conn, NULL);
-       stc_firewall_update();
-
-       return STC_ERROR_NONE;
-}
-
-static stc_error_e __get_default_connection(GDBusConnection *connection)
-{
-       GVariant *message = NULL;
-       GVariantIter *iter = NULL;
-       GVariantIter *next;
-       gchar *object_path;
-
-       message = stc_manager_gdbus_call_sync(connection,
-                                             CONNMAN_SERVICE,
-                                             CONNMAN_MANAGER_PATH,
-                                             CONNMAN_MANAGER_INTERFACE,
-                                             "GetServices", NULL);
-       if (message == NULL) {
-               STC_LOGE("Failed to get profiles"); //LCOV_EXCL_LINE
-               return STC_ERROR_FAIL; //LCOV_EXCL_LINE
-       }
-
-       g_variant_get(message, "(a(oa{sv}))", &iter);
-       while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
-               if (object_path == NULL)
-                       continue; //LCOV_EXCL_LINE
-
-               if (__is_cellular_profile(object_path) &&
-                   !__is_cellular_internet_profile(object_path))
-                       continue;
-
-               if (__is_connected(next) == TRUE) {
-                       GSList *comp = g_slist_find_custom(g_connection_list,
-                                                               object_path, __conn_list_comp);
-                       if (comp && comp->data)
-                               g_default_connection = comp->data;
-
-                       break;
-               }
-       }
-
-       g_variant_iter_free(iter);
-       g_variant_unref(message);
-
-       return STC_ERROR_NONE;
-}
-
-static void __append_connected_profile(GDBusConnection *connection,
-                               const char *path)
-{
-       stc_connection_s *conn;
-
-       conn = MALLOC0(stc_connection_s, 1);
-       if (conn == NULL)
-               return;
-
-       conn->path = g_strdup(path);
-       conn->roaming = FALSE;
-
-       if (__is_cellular_profile(conn->path)) {
-               conn->type = STC_IFACE_DATACALL;
-               __telephony_update_default_modem_subscriber_id(connection, conn);
-       } else if (__is_wifi_profile(conn->path)) {
-               conn->type = STC_IFACE_WIFI;
-       } else if (__is_ethernet_profile(conn->path)) {
-               conn->type = STC_IFACE_WIRED;
-       } else if (__is_bluetooth_profile(conn->path)) {
-               conn->type = STC_IFACE_BLUETOOTH;
-       } else {
-               conn->type = STC_IFACE_UNKNOWN;
-       }
-
-       __get_connection_info(connection, conn, conn->path);
-       __print_connection_info(conn);
-
-       g_connection_list = g_slist_append(g_connection_list, conn);
-
-       stc_monitor_add_by_connection(conn);
-       stc_firewall_update();
-
-       __get_default_connection(connection);
-}
-
-static void __remove_disconnected_profile(GDBusConnection *connection,
-                               stc_connection_s *conn)
-{
-       __print_connection_info(conn);
-
-       stc_monitor_remove_by_connection(conn);
-
-       g_connection_list = g_slist_remove(g_connection_list, conn);
-
-       __get_default_connection(connection);
-
-       FREE(conn->path);
-       FREE(conn->ifname);
-       FREE(conn->tether_iface.ifname);
-       FREE(conn);
-}
-
-static void __vconf_key_callback(keynode_t *node, void *user_data)
-{
-       int vconf_key;
-
-       if (node == NULL) {
-               STC_LOGE("Invalid parameter");
-               return;
-       }
-
-       if (g_default_connection == NULL)
-               return;
-
-       if (vconf_keynode_get_type(node) != VCONF_TYPE_INT) {
-               STC_LOGE("Invalid vconf key type");
-               return;
-       }
-
-       vconf_key = vconf_keynode_get_int(node);
-
-       /* Check the tethering type */
-       switch (vconf_key) {
-       case VCONFKEY_MOBILE_HOTSPOT_MODE_USB:
-               STC_LOGI("Hotspot mode USB type !");
-               g_default_connection->tether_state = TRUE;
-               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_USB_IF);
-               g_default_connection->tether_iface.type = STC_IFACE_USB;
-               break;
-       case VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI:
-               STC_LOGI("Hotspot mode Wi-Fi type !");
-               g_default_connection->tether_state = TRUE;
-               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_WIFI_IF);
-               g_default_connection->tether_iface.type = STC_IFACE_WIFI;
-               break;
-       case VCONFKEY_MOBILE_HOTSPOT_MODE_BT:
-               STC_LOGI("Hotspot mode Bluetooth type !");
-               g_default_connection->tether_state = TRUE;
-               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_BT_IF);
-               g_default_connection->tether_iface.type = STC_IFACE_BLUETOOTH;
-               break;
-       case VCONFKEY_MOBILE_HOTSPOT_MODE_P2P:
-               STC_LOGI("Hotspot mode P2P type !");
-               g_default_connection->tether_state = TRUE;
-               g_default_connection->tether_iface.ifname = g_strdup(TETHERING_P2P_IF);
-               g_default_connection->tether_iface.type = STC_IFACE_P2P;
-               break;
-       case VCONFKEY_MOBILE_HOTSPOT_MODE_NONE:
-               STC_LOGI("Hotspot mode none");
-               g_default_connection->tether_state = FALSE;
-               break;
-       default:
-               STC_LOGE("Unknown Hotspot mode type !");
-               break;
-       }
-
-       /* add monitoring for tethering if active found */
-       if (g_default_connection->tether_state == TRUE && g_default_connection->tether_iface.ifname) {
-               __print_tether_connection_info();
-               stc_monitor_update_by_connection(&g_default_connection);
-               stc_firewall_update();
-               STC_LOGI("Data monitoring started for tethering iface !");
-               return;
-       }
-
-       /* remove monitoring for tethering if in-active found */
-       if (g_default_connection->tether_state == FALSE && g_default_connection->tether_iface.ifname) {
-               stc_monitor_update_by_connection(&g_default_connection);
-               g_free(g_default_connection->tether_iface.ifname);
-               g_default_connection->tether_iface.ifname = NULL;
-               g_default_connection->tether_iface.type = STC_IFACE_UNKNOWN;
-               STC_LOGI("Data monitoring stopped for tethering iface !");
-               return;
-       }
-}
-
-static void _service_signal_cb(GDBusConnection *connection,
-                              const gchar *name, const gchar *path,
-                              const gchar *interface, const gchar *sig,
-                              GVariant *param, gpointer user_data)
-{
-       gchar *sigvalue = NULL;
-       GVariant *variant = NULL;
-       stc_s *stc = (stc_s *)stc_get_manager();
-       ret_msg_if(stc == NULL, "failed to get stc data");
-
-       if (path == NULL || param == NULL)
-               goto done;
-
-       g_variant_get(param, "(sv)", &sigvalue, &variant);
-       if (sigvalue == NULL)
-               goto done;
-
-       if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
-               goto done;
-
-       if (g_strcmp0(sigvalue, "State") == 0 &&
-           g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
-               const gchar *state = NULL;
-
-               state = g_variant_get_string(variant, NULL);
-               if (g_strcmp0(state, "ready") == 0 ||
-                   g_strcmp0(state, "online") == 0) {
-                       GSList *comp = g_slist_find_custom(g_connection_list,
-                                                               path, __conn_list_comp);
-                       if (!comp)
-                               __append_connected_profile(stc->connection, path);
-               } else if (g_strcmp0(state, "idle") == 0 ||
-                       g_strcmp0(state, "disconnect") == 0) {
-                       GSList *comp = g_slist_find_custom(g_connection_list,
-                                                               path, __conn_list_comp);
-                       if (comp && comp->data)
-                               __remove_disconnected_profile(stc->connection, comp->data);
-               }
-       } else if (g_strcmp0(sigvalue, "Roaming") == 0) {
-               //LCOV_EXCL_START
-               GSList *comp = g_slist_find_custom(g_connection_list,
-                                                       path, __conn_list_comp);
-
-               if (comp) {
-                       stc_connection_s *conn = comp->data;
-                       gboolean roaming = 0;
-
-                       if (g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)) {
-                               roaming = g_variant_get_boolean(variant);
-                               conn->roaming = roaming;
-                       }
-               }
-               //LCOV_EXCL_STOP
-       } else {
-               ;//Do nothing
-       }
-done:
-       if (sigvalue)
-               g_free(sigvalue);
-
-       if (variant)
-               g_variant_unref(variant);
-
-       return;
-}
-
-stc_error_e stc_connection_monitor_init(stc_s *stc)
-{
-       int ret;
-       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-
-       __get_connected_profiles(stc->connection);
-       g_connection_sub_id =
-               stc_manager_gdbus_subscribe_signal(stc->connection,
-                                                  CONNMAN_SERVICE,
-                                                  CONNMAN_SERVICE_INTERFACE,
-                                                  CONNMAN_SIGNAL_PROPERTY_CHANGED,
-                                                  NULL, NULL,
-                                                  G_DBUS_SIGNAL_FLAGS_NONE,
-                                                  _service_signal_cb,
-                                                  NULL, NULL);
-
-       ret = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, __vconf_key_callback, NULL);
-       if (ret < 0)
-               STC_LOGE("vconf_notify_key_changed failed: %d", ret);
-
-       STC_LOGI("Successfully subscribed connman [%s] signal", CONNMAN_SIGNAL_PROPERTY_CHANGED);
-       return STC_ERROR_NONE;
-}
-
-stc_error_e stc_connection_monitor_deinit(stc_s *stc)
-{
-       ret_value_msg_if(stc == NULL, STC_ERROR_INVALID_PARAMETER, "failed to get stc data");
-
-       stc_manager_gdbus_unsubscribe_signal(stc->connection,
-                                            g_connection_sub_id);
-
-       g_slist_free_full(g_connection_list, __conn_list_free);
-
-       return STC_ERROR_NONE;
-}
-
-GSList *stc_get_connection_list(void)
-{
-       return g_connection_list;
-}
diff --git a/src/monitor/stc-monitor-app.c b/src/monitor/stc-monitor-app.c
deleted file mode 100755 (executable)
index ceeb0b4..0000000
+++ /dev/null
@@ -1,744 +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.
- */
-
-#include "stc-db.h"
-#include "counter.h"
-#include "stc-manager.h"
-#include "stc-monitor.h"
-#include "stc-monitor-app.h"
-#include "stc-monitor-rstn.h"
-#include "stc-monitor-proc.h"
-#include "stc-monitor-ipt.h"
-#include "table-statistics.h"
-#include "helper-net-cls.h"
-#include "stc-manager-plugin-tether.h"
-
-static void __print_app(gpointer key, gpointer value,
-                                         gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-
-       STC_LOGD("PkgID[%s] AppID[\033[0;32m%s\033[0;m] "
-               "type[%d] state[%d] classid[\033[1;36m%d\033[0;m] "
-               "counter[in(%lld) out(%lld)]",
-                app_value->pkg_id, app_value->app_id,
-                app_value->type, app_value->state,
-                app_value->classid,
-                app_value->data_usage.in_bytes,
-                app_value->data_usage.out_bytes);
-}
-
-static void __app_update_statistics(gpointer key,
-                                       gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       time_t *touch_time = (time_t *)data;
-       GSList *conn_list = stc_get_connection_list();
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-               stc_db_classid_iftype_key stat_key;
-               stc_db_app_stats stat;
-
-               memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
-               memset(&stat, 0 , sizeof(stc_db_app_stats));
-
-               if (conn == NULL)
-                       return;
-
-               /* Do not update statistics for Tethering
-                * if tethering is in-active found */
-               if (conn && conn->tether_state == FALSE &&
-                       !strcmp(app_value->app_id, STC_TOTAL_TETHERING))
-                       return;
-
-               /* Do not update statistics for Wi-Fi
-                * if tethering is active on wlan0 iface */
-               if (conn && conn->tether_state &&
-                       conn->tether_iface.type == STC_IFACE_WIFI &&
-                       !strcmp(app_value->app_id, STC_TOTAL_WIFI))
-                       return;
-
-               stat_key.classid = app_value->classid;
-
-               if (app_value->classid == STC_TETHERING_APP_CLASSID &&
-                       conn->tether_state == TRUE)
-                       stat_key.iftype = conn->tether_iface.type;
-               else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
-                       stat_key.iftype = conn->tether_iface.type;
-               else
-                       stat_key.iftype = conn->type;
-
-               if (STC_IFACE_DATACALL == stat_key.iftype)
-                       stat_key.subscriber_id = g_strdup(conn->subscriber_id);
-               else
-                       stat_key.subscriber_id = g_strdup(SUBSCRIBERID_NONE);
-
-               if (app_value->classid == STC_TETHERING_APP_CLASSID &&
-                       conn->tether_state == TRUE)
-                       g_strlcpy(stat_key.ifname, conn->tether_iface.ifname,
-                                 MAX_IFACE_LENGTH);
-               else if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX))
-                       g_strlcpy(stat_key.ifname, conn->tether_iface.ifname,
-                                 MAX_IFACE_LENGTH);
-               else
-                       g_strlcpy(stat_key.ifname, conn->ifname,
-                                 MAX_IFACE_LENGTH);
-
-               stat.app_id = g_strdup(app_value->app_id);
-               stat.snd_count = app_value->counter.out_bytes;
-               stat.rcv_count = app_value->counter.in_bytes;
-               stat.is_roaming = conn->roaming;
-
-               if (strstr(stat.app_id, "_BACKGROUND")) {
-                       stat.ground = STC_APP_STATE_BACKGROUND;
-               } else {
-                       if (strstr(stat.app_id, "TOTAL_"))
-                               stat.ground = STC_APP_STATE_UNKNOWN;
-                       else
-                               stat.ground = STC_APP_STATE_FOREGROUND;
-               }
-
-               table_statistics_insert(&stat_key, &stat, *touch_time);
-
-               app_value->counter.out_bytes = 0;
-               app_value->counter.in_bytes = 0;
-
-               FREE(stat.app_id);
-               FREE(stat_key.subscriber_id);
-       }
-
-       return;
-}
-
-static gboolean __add_app_monitor_for_tethering(gpointer key,
-                                   gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       stc_connection_s *connection = (stc_connection_s *)data;
-       stc_s *stc = stc_get_manager();
-       struct nfacct_rule counter;
-       char *ipaddr = NULL;
-       int ret;
-
-       STC_LOGI("Add appid(%s) classid(%d)", app_value->app_id,
-                       app_value->classid);
-
-       if (stc == NULL || connection == NULL)
-               return FALSE;
-
-       if (!stc->carg) {
-               stc->carg = MALLOC0(counter_arg_s, 1);
-               if (stc->carg == NULL)
-                       return FALSE;
-
-               stc->carg->sock = stc_monitor_get_contr_sock();
-       }
-
-       memset(&counter, 0, sizeof(struct nfacct_rule));
-
-       counter.carg = stc->carg;
-       counter.classid = app_value->classid;
-       counter.intend = NFACCT_TETH_COUNTER;
-
-       if (connection->tether_state != TRUE ||
-                       connection->tether_iface.ifname == NULL)
-               return FALSE;
-
-       counter.iftype = connection->tether_iface.type;
-       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
-
-       /* get the ip address of the station based on its mac address */
-       ret = stc_plugin_tether_get_station_ip(app_value->mac, &ipaddr);
-       if (ret != STC_ERROR_NONE)
-               return FALSE;
-
-       /* tethering iptables rule */
-       stc_monitor_tether_add_in(&counter, ipaddr);
-       stc_monitor_tether_add_out(&counter, ipaddr);
-
-       g_free(ipaddr);
-       return FALSE;
-}
-
-static gboolean __remove_app_monitor_for_tethering(gpointer key,
-                               gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       stc_connection_s *connection = (stc_connection_s *)data;
-       stc_s *stc = stc_get_manager();
-       struct nfacct_rule counter;
-       char *ipaddr = NULL;
-       int ret;
-
-       STC_LOGI("Remove appid(%s) classid(%d)", app_value->app_id,
-                       app_value->classid);
-
-       if (stc == NULL || connection == NULL)
-               return FALSE;
-
-       if (!stc->carg) {
-               stc->carg = MALLOC0(counter_arg_s, 1);
-               if (stc->carg == NULL)
-                       return FALSE;
-
-               stc->carg->sock = stc_monitor_get_contr_sock();
-       }
-
-       memset(&counter, 0, sizeof(struct nfacct_rule));
-
-       counter.carg = stc->carg;
-       counter.classid = app_value->classid;
-       counter.intend = NFACCT_TETH_COUNTER;
-
-       if (connection->tether_state != TRUE ||
-                       connection->tether_iface.ifname == NULL)
-               return FALSE;
-
-       counter.iftype = connection->tether_iface.type;
-       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
-
-       /* get the ip address of the station based on its mac address */
-       ret = stc_plugin_tether_get_station_ip(app_value->mac, &ipaddr);
-       if (ret != STC_ERROR_NONE)
-               return FALSE;
-
-       stc_monitor_tether_del_in(&counter, ipaddr);
-       stc_monitor_tether_del_out(&counter, ipaddr);
-
-       g_free(ipaddr);
-       return FALSE;
-}
-
-static void __app_value_destroy(gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)data;
-
-       FREE(app_value->pkg_id);
-       FREE(app_value->app_id);
-       g_hash_table_destroy(app_value->processes);
-       app_value->processes = NULL;
-
-       FREE(app_value);
-}
-
-static void __check_rstn_limit_exceeded(gpointer data,
-                               gpointer user_data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-       int32_t *limit_exceeded = (int32_t *)user_data;
-
-       if (rstn_data->limit_exceeded != 0)
-               *limit_exceeded = rstn_data->limit_exceeded;
-}
-
-static void __app_update_counter(classid_bytes_context_s *context,
-                               uint32_t classid)
-{
-       stc_app_value_s *lookup_app;
-       stc_rstn_value_s *lookup_rstn;
-       GHashTable *apps = stc_monitor_get_system_apps();
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!apps)
-               return;
-
-       lookup_app = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-       if (lookup_app)
-               stc_monitor_app_update_counter(lookup_app, context);
-
-       if (!rstns)
-               return;
-
-       lookup_rstn = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
-       if (lookup_rstn) {
-               int32_t limit_exceeded = 0;
-               g_slist_foreach(lookup_rstn->rules,
-                       __check_rstn_limit_exceeded, &limit_exceeded);
-
-               if (limit_exceeded != 0)
-                       return;
-       }
-}
-
-void stc_monitor_app_update_counter(stc_app_value_s *value,
-                                classid_bytes_context_s *context)
-{
-       switch (context->counter->iotype) {
-       case NFACCT_COUNTER_IN:
-               value->data_usage.in_bytes += context->bytes;
-               value->counter.in_bytes = context->bytes;
-               stc_monitor_set_apps_updated(TRUE);
-
-               break;
-       case NFACCT_COUNTER_OUT:
-               value->data_usage.out_bytes += context->bytes;
-               value->counter.out_bytes = context->bytes;
-               stc_monitor_set_apps_updated(TRUE);
-
-               break;
-       default:
-               STC_LOGE("Unknown iotype");
-       }
-}
-
-void stc_monitor_app_update_iface_counter(classid_bytes_context_s *context)
-{
-       switch (context->counter->iftype) {
-       case STC_IFACE_DATACALL:
-               __app_update_counter(context, STC_TOTAL_DATACALL_CLASSID);
-               break;
-       case STC_IFACE_WIFI:
-               __app_update_counter(context, STC_TOTAL_WIFI_CLASSID);
-               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       case STC_IFACE_BLUETOOTH:
-               __app_update_counter(context, STC_TOTAL_BLUETOOTH_CLASSID);
-               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       case STC_IFACE_USB:
-               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       case STC_IFACE_P2P:
-               __app_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       default:
-               break;
-       }
-}
-
-gboolean stc_monitor_app_flush_stats_to_db(gpointer user_data)
-{
-       time_t current_time = 0;
-       stc_s *stc = stc_get_manager();
-       GHashTable *apps = stc_monitor_get_system_apps();
-       gboolean apps_updated = stc_monitor_get_apps_updated();
-
-       if (stc && stc->carg)
-               current_time = stc->carg->last_run_time;
-
-       if (apps_updated == FALSE)
-               return G_SOURCE_REMOVE;
-
-       stc_monitor_set_apps_updated(FALSE);
-
-       if (apps)
-               g_hash_table_foreach(apps,
-                                       __app_update_statistics,
-                                       &current_time);
-
-       STC_LOGI("Flushed app stats to database");
-       return G_SOURCE_REMOVE;
-}
-
-API stc_error_e stc_monitor_app_add(uint32_t classid,
-                               const char *app_id,
-                               const char *pkg_id,
-                               const stc_app_value_s value)
-{
-       stc_app_value_s *app_value;
-       stc_app_value_s *lookup_value;
-
-       GHashTable *apps = stc_monitor_get_system_apps();
-       GSList *conn_list = stc_get_connection_list();
-
-       if (!apps)
-               return STC_ERROR_NO_DATA;
-
-       if (classid == STC_UNKNOWN_CLASSID)
-               classid = get_classid_by_app_id(app_id, TRUE);
-
-       lookup_value = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-       if (lookup_value) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGE("Already exists [\033[1;36m%d\033[0;m:"
-                                               "\033[0;32m%s\033[0;m]", classid, app_id);
-               return STC_ERROR_NONE;
-       }
-
-       app_value = MALLOC0(stc_app_value_s, 1);
-       if (!app_value) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGE("Value allocation failed");
-               return STC_ERROR_OUT_OF_MEMORY;
-       }
-
-       /* create cgroup and update classid */
-       app_value->classid = classid;
-
-       app_value->app_id = g_strdup(app_id);
-       app_value->pkg_id = g_strdup(pkg_id);
-
-       app_value->type = value.type;
-       app_value->state = value.state;
-       app_value->data_usage.in_bytes = value.data_usage.in_bytes;
-       app_value->data_usage.out_bytes = value.data_usage.out_bytes;
-       g_strlcpy(app_value->mac, value.mac, MAC_ADDRESS_LEN);
-
-       app_value->processes = g_hash_table_new_full(g_direct_hash,
-                                                               g_direct_equal, NULL, NULL);
-
-       /* update classid for tethering station based on its mac address */
-       if (g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX) &&
-                               classid != STC_TETHERING_APP_CLASSID)
-               stc_plugin_tether_set_station_classid(app_value->mac, classid);
-
-       g_hash_table_insert(apps, GUINT_TO_POINTER(classid), app_value);
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-               /* add nfacct rule for this classid */
-               stc_monitor_app_add_monitor(GUINT_TO_POINTER(classid),
-                                       app_value, conn);
-
-               if (app_value->state == STC_APP_STATE_FOREGROUND)
-                       stc_monitor_app_add_accept(GUINT_TO_POINTER(classid),
-                                       app_value, conn);
-       }
-
-       stc_monitor_rstn_add_for_app(classid);
-
-       if (STC_DEBUG_LOG && STC_STAT_LOG) {
-               __print_app(GUINT_TO_POINTER(classid), app_value, NULL);
-               STC_LOGD("\033[1;32mApplication added\033[0;m "
-                       "[\033[1;36m%d\033[0;m]", classid);
-       }
-
-       return STC_ERROR_NONE;
-}
-
-void stc_monitor_app_add_by_iface(const char *ifname)
-{
-       stc_app_value_s app_value;
-
-       if (ifname == NULL)
-               return;
-
-       memset(&app_value, 0, sizeof(stc_app_value_s));
-
-       app_value.type = STC_APP_TYPE_NONE;
-       app_value.processes = NULL;
-       app_value.counter.in_bytes = 0;
-       app_value.counter.out_bytes = 0;
-
-       stc_monitor_app_add(STC_UNKNOWN_CLASSID, ifname, ifname, app_value);
-}
-
-void stc_monitor_app_add_monitor(gpointer key,
-                               gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       stc_connection_s *connection = (stc_connection_s *)data;
-       stc_s *stc = stc_get_manager();
-
-       if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
-           app_value->classid == STC_TOTAL_WIFI_CLASSID ||
-           app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
-               return;
-
-       if (stc && connection && connection->ifname) {
-               struct nfacct_rule counter;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = app_value->classid;
-               counter.app_state = app_value->state;
-               counter.intend = NFACCT_COUNTER;
-
-               if (connection->tether_state == TRUE &&
-                       connection->tether_iface.ifname != NULL &&
-                       app_value->classid == STC_TETHERING_APP_CLASSID) {
-                       counter.iftype = connection->tether_iface.type;
-                       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
-               } else {
-                       counter.iftype = connection->type;
-                       g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
-               }
-
-               if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX) &&
-                               app_value->classid != STC_TETHERING_APP_CLASSID) {
-                       __add_app_monitor_for_tethering(key, value, data);
-               } else if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
-                       stc_monitor_ipt_add_in(&counter);
-                       stc_monitor_ipt_add_out(&counter);
-               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
-                       stc_monitor_ip6t_add_in(&counter);
-                       stc_monitor_ip6t_add_out(&counter);
-               } else {
-                       stc_monitor_ipt_add_in(&counter);
-                       stc_monitor_ipt_add_out(&counter);
-                       stc_monitor_ip6t_add_in(&counter);
-                       stc_monitor_ip6t_add_out(&counter);
-               }
-       }
-}
-
-void stc_monitor_app_add_by_connection(stc_connection_s *conn)
-{
-       GHashTable *apps = stc_monitor_get_system_apps();
-
-       if (!apps)
-               return;
-
-       g_hash_table_foreach(apps, stc_monitor_app_add_monitor, conn);
-       g_hash_table_foreach(apps, stc_monitor_app_add_accept, conn);
-}
-
-void stc_monitor_app_add_accept(gpointer key,
-                               gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       stc_connection_s *connection = (stc_connection_s *)data;
-       stc_s *stc = stc_get_manager();
-
-       if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
-           app_value->classid == STC_TOTAL_WIFI_CLASSID ||
-           app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
-               return;
-
-       if (app_value->state != STC_APP_STATE_FOREGROUND)
-               return;
-
-       if (stc && connection && connection->ifname) {
-               struct nfacct_rule counter;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = app_value->classid;
-               counter.app_state = app_value->state;
-               counter.intend = NFACCT_ALLOW;
-
-               counter.iftype = connection->type;
-               g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
-
-               if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
-                       stc_monitor_ipt_add_in(&counter);
-                       stc_monitor_ipt_add_out(&counter);
-               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
-                       stc_monitor_ip6t_add_in(&counter);
-                       stc_monitor_ip6t_add_out(&counter);
-               } else {
-                       stc_monitor_ipt_add_in(&counter);
-                       stc_monitor_ipt_add_out(&counter);
-                       stc_monitor_ip6t_add_in(&counter);
-                       stc_monitor_ip6t_add_out(&counter);
-               }
-       }
-}
-
-API stc_error_e stc_monitor_app_remove(uint32_t classid, const char *app_id)
-{
-       stc_app_value_s *app_lookup;
-       GHashTable *apps = stc_monitor_get_system_apps();
-       GSList *conn_list = stc_get_connection_list();
-
-       if (!apps)
-               return STC_ERROR_NO_DATA;
-
-       classid = get_classid_by_app_id(app_id, FALSE);
-
-       app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-       if (!app_lookup) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid);
-               return STC_ERROR_FAIL;
-       }
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-               /* remove nfacct rule for this classid */
-               stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
-                                       app_lookup, conn);
-
-               if (app_lookup->state == STC_APP_STATE_FOREGROUND)
-                       stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
-                                               app_lookup, conn);
-       }
-
-       /* remove ristrictions if any */
-       stc_monitor_rstn_remove_for_app(classid);
-
-       if (STC_DEBUG_LOG && STC_STAT_LOG)
-               __print_app(GUINT_TO_POINTER(classid), app_lookup, NULL);
-
-       /* remove app_key from the stc-manager */
-       g_hash_table_remove(apps, GUINT_TO_POINTER(classid));
-
-       return STC_ERROR_NONE;
-}
-
-void stc_monitor_app_remove_monitor(gpointer key,
-                               gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       stc_connection_s *connection = (stc_connection_s *)data;
-       stc_s *stc = stc_get_manager();
-
-       if (stc && connection && connection->ifname) {
-               struct nfacct_rule counter;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = app_value->classid;
-               counter.app_state = app_value->state;
-               counter.intend = NFACCT_COUNTER;
-
-               if (g_str_has_suffix(app_value->app_id, STC_TETHERING_APP_SUFFIX) &&
-                               app_value->classid != STC_TETHERING_APP_CLASSID) {
-                       __remove_app_monitor_for_tethering(key, value, data);
-                       return;
-               } else if (connection->tether_state == FALSE &&
-                       connection->tether_iface.ifname != NULL &&
-                       app_value->classid == STC_TETHERING_APP_CLASSID) {
-                       counter.iftype = connection->tether_iface.type;
-                       g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
-               } else {
-                       counter.iftype = connection->type;
-                       g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
-               }
-
-               if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
-                       stc_monitor_ipt_del_in(&counter);
-                       stc_monitor_ipt_del_out(&counter);
-               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
-                       stc_monitor_ip6t_del_in(&counter);
-                       stc_monitor_ip6t_del_out(&counter);
-               } else {
-                       stc_monitor_ipt_del_in(&counter);
-                       stc_monitor_ipt_del_out(&counter);
-                       stc_monitor_ip6t_del_in(&counter);
-                       stc_monitor_ip6t_del_out(&counter);
-               }
-       }
-
-       return;
-}
-
-void stc_monitor_app_remove_by_connection(stc_connection_s *conn)
-{
-       GHashTable *apps = stc_monitor_get_system_apps();
-
-       if (!apps)
-               return;
-
-       g_hash_table_foreach(apps, stc_monitor_app_remove_monitor, conn);
-       g_hash_table_foreach(apps, stc_monitor_app_remove_accept, conn);
-}
-
-void stc_monitor_app_remove_accept(gpointer key,
-                               gpointer value, gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       stc_connection_s *connection = (stc_connection_s *)data;
-       stc_s *stc = stc_get_manager();
-
-       if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
-           app_value->classid == STC_TOTAL_WIFI_CLASSID ||
-           app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
-               return;
-
-       if (app_value->state != STC_APP_STATE_FOREGROUND)
-               return;
-
-       if (stc && connection && connection->ifname) {
-               struct nfacct_rule counter;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = app_value->classid;
-               counter.app_state = app_value->state;
-               counter.intend = NFACCT_ALLOW;
-
-               counter.iftype = connection->type;
-               g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
-
-               if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
-                       stc_monitor_ipt_del_in(&counter);
-                       stc_monitor_ipt_del_out(&counter);
-               } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
-                       stc_monitor_ip6t_del_in(&counter);
-                       stc_monitor_ip6t_del_out(&counter);
-               } else {
-                       stc_monitor_ipt_del_in(&counter);
-                       stc_monitor_ipt_del_out(&counter);
-                       stc_monitor_ip6t_del_in(&counter);
-                       stc_monitor_ip6t_del_out(&counter);
-               }
-       }
-
-       return;
-}
-
-API gboolean stc_monitor_app_lookup(uint32_t classid)
-{
-       stc_app_value_s *lookup_value;
-
-       GHashTable *apps = stc_monitor_get_system_apps();
-
-       if (!apps)
-               return FALSE;
-
-       if (classid == STC_UNKNOWN_CLASSID)
-               return FALSE;
-
-       lookup_value = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-       if (lookup_value)
-               return TRUE;
-
-       return FALSE;
-}
-
-GHashTable *stc_monitor_apps_init(void)
-{
-       return g_hash_table_new_full(g_direct_hash, g_direct_equal,
-                                       NULL, __app_value_destroy);
-}
diff --git a/src/monitor/stc-monitor-ipt.c b/src/monitor/stc-monitor-ipt.c
deleted file mode 100644 (file)
index 016ae04..0000000
+++ /dev/null
@@ -1,250 +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.
- */
-
-#include "stc-monitor-ipt.h"
-#include "stc-monitor-context.h"
-
-static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter)
-{
-       if (counter->intend == NFACCT_WARN)
-               return NFACCT_JUMP_ACCEPT;
-       else if (counter->intend == NFACCT_BLOCK)
-               return NFACCT_JUMP_REJECT;
-       else if (counter->intend == NFACCT_ALLOW)
-               return NFACCT_JUMP_ACCEPT;
-       else if (counter->intend == NFACCT_TETH_BLOCK)
-               return NFACCT_JUMP_REJECT;
-       else if (counter->intend == NFACCT_TETH_ALLOW)
-               return NFACCT_JUMP_ACCEPT;
-
-       return NFACCT_JUMP_UNKNOWN;
-}
-
-stc_error_e stc_monitor_ipt_add_in(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_INSERT;
-       counter->iotype = NFACCT_COUNTER_IN;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ipt_add_out(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_INSERT;
-       counter->iotype = NFACCT_COUNTER_OUT;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ipt_del_in(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_DELETE;
-       counter->iotype = NFACCT_COUNTER_IN;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ipt_del_out(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_DELETE;
-       counter->iotype = NFACCT_COUNTER_OUT;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ip6t_add_in(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_INSERT;
-       counter->iotype = NFACCT_COUNTER_IN;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV6;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ip6t_add_out(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_INSERT;
-       counter->iotype = NFACCT_COUNTER_OUT;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV6;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ip6t_del_in(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_DELETE;
-       counter->iotype = NFACCT_COUNTER_IN;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV6;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_ip6t_del_out(struct nfacct_rule *counter)
-{
-       if (counter == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_DELETE;
-       counter->iotype = NFACCT_COUNTER_OUT;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV6;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-
-       return produce_net_rule(counter);
-}
-
-stc_error_e stc_monitor_tether_add_in(struct nfacct_rule *counter,
-               const gchar *ipaddr)
-{
-       int ret;
-
-       if (counter == NULL || ipaddr == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_INSERT;
-       counter->iotype = NFACCT_COUNTER_IN;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
-       counter->src_ip1 = g_strdup(ipaddr);
-
-       ret = produce_net_rule(counter);
-
-       FREE(counter->src_ip1);
-       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
-       return ret;
-}
-
-stc_error_e stc_monitor_tether_add_out(struct nfacct_rule *counter,
-               const gchar *ipaddr)
-{
-       int ret;
-
-       if (counter == NULL || ipaddr == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_INSERT;
-       counter->iotype = NFACCT_COUNTER_OUT;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
-       counter->dst_ip1 = g_strdup(ipaddr);
-
-       ret = produce_net_rule(counter);
-
-       FREE(counter->dst_ip1);
-       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
-       return ret;
-}
-
-stc_error_e stc_monitor_tether_del_in(struct nfacct_rule *counter,
-               const gchar *ipaddr)
-{
-       int ret;
-
-       if (counter == NULL || ipaddr == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_DELETE;
-       counter->iotype = NFACCT_COUNTER_IN;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
-       counter->src_ip1 = g_strdup(ipaddr);
-
-       ret = produce_net_rule(counter);
-
-       FREE(counter->src_ip1);
-       counter->src_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
-       return ret;
-}
-
-stc_error_e stc_monitor_tether_del_out(struct nfacct_rule *counter,
-               const gchar *ipaddr)
-{
-       int ret;
-
-       if (counter == NULL || ipaddr == NULL)
-               return STC_ERROR_INVALID_PARAMETER;
-
-       counter->action = NFACCT_ACTION_DELETE;
-       counter->iotype = NFACCT_COUNTER_OUT;
-       counter->jump = __get_jump_by_intend(counter);
-       counter->iptype = NFACCT_TYPE_IPV4;
-       counter->send_limit = 0;
-       counter->rcv_limit = 0;
-       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_SINGLE;
-       counter->dst_ip1 = g_strdup(ipaddr);
-
-       ret = produce_net_rule(counter);
-
-       FREE(counter->dst_ip1);
-       counter->dst_iprange_type = NFACCT_IPRANGE_TYPE_NONE;
-       return ret;
-}
diff --git a/src/monitor/stc-monitor-proc.c b/src/monitor/stc-monitor-proc.c
deleted file mode 100755 (executable)
index be12dd1..0000000
+++ /dev/null
@@ -1,312 +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.
- */
-
-#include "stc-monitor.h"
-#include "stc-monitor-proc.h"
-#include "stc-connection.h"
-#include "helper-net-cls.h"
-
-static void __print_proc(gpointer key, gpointer value,
-                               gpointer data)
-{
-       stc_proc_value_s *proc_value = (stc_proc_value_s *)value;
-
-       STC_LOGD("pid[\033[1;33m%d\033[0;m] ground[%d]",
-                proc_value->pid, proc_value->ground);
-}
-
-static void __print_proc_all(GHashTable *procs)
-{
-       g_hash_table_foreach(procs, __print_proc, NULL);
-}
-
-static void __proc_remove_pid(gpointer key, gpointer value,
-                               gpointer data)
-{
-       stc_app_value_s *app_value = (stc_app_value_s *)value;
-       remove_pid_context_s *context = (remove_pid_context_s *)data;
-
-       if (!g_hash_table_remove(app_value->processes, GUINT_TO_POINTER(context->pid)))
-               return;
-
-       if (STC_DEBUG_LOG && STC_STAT_LOG) {
-               __print_proc_all(app_value->processes);
-               STC_LOGD("\033[1;31mProcess removed\033[0;m "
-                       "[\033[1;33m%d\033[0;m]", context->pid);
-       }
-
-       context->entry_removed = TRUE;
-       context->app_value = app_value;
-}
-
-static void __proc_move_pid(gpointer key, gpointer value,
-                               gpointer data)
-{
-       stc_proc_value_s *from_value = (stc_proc_value_s *)value;
-       stc_app_value_s *to_app_value = (stc_app_value_s *)data;
-       stc_proc_value_s *to_value;
-
-       to_value = MALLOC0(stc_proc_value_s, 1);
-       if (!to_value)
-               return;
-
-       to_value->pid = from_value->pid;
-       to_value->ground = to_app_value->state;
-
-       g_hash_table_insert(to_app_value->processes,
-                       GUINT_TO_POINTER(to_value->pid),
-                       to_value);
-
-       /* add pid to application cgroup */
-       place_pids_to_net_cgroup(to_value->pid, to_app_value->app_id);
-}
-
-API stc_error_e stc_monitor_proc_update_ground(uint32_t classid,
-                                               const char *app_id,
-                                               const stc_proc_value_s value)
-{
-       stc_error_e ret = STC_ERROR_NONE;
-       stc_app_value_s *app_lookup;
-       stc_proc_value_s *proc_lookup;
-       GHashTable *apps = stc_monitor_get_system_apps();
-
-       if (!apps)
-               return STC_ERROR_NO_DATA;
-
-       if (classid == STC_UNKNOWN_CLASSID)
-               classid = get_classid_by_app_id(app_id, TRUE);
-
-       app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-       if (!app_lookup) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid);
-               return STC_ERROR_NO_DATA;
-       }
-
-       proc_lookup = g_hash_table_lookup(app_lookup->processes,
-                                       GUINT_TO_POINTER(value.pid));
-       if (!proc_lookup) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", value.pid);
-               return STC_ERROR_NO_DATA;
-       }
-
-       if (proc_lookup->ground != value.ground)
-               proc_lookup->ground = value.ground;
-
-       place_pids_to_net_cgroup(value.pid, app_id);
-
-       return ret;
-}
-
-API stc_error_e stc_monitor_proc_add(uint32_t classid,
-                                       const char *app_id,
-                                       const stc_proc_value_s value)
-{
-       stc_error_e ret = STC_ERROR_NONE;
-       stc_app_value_s *app_lookup;
-       stc_proc_value_s *proc_lookup;
-       stc_proc_value_s *proc_value;
-       GHashTable *apps = stc_monitor_get_system_apps();
-
-       if (!apps)
-               return STC_ERROR_NO_DATA;
-
-       if (classid == STC_UNKNOWN_CLASSID)
-               classid = get_classid_by_app_id(app_id, TRUE);
-
-       app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-       if (!app_lookup) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid);
-               return STC_ERROR_NO_DATA;
-       }
-
-       proc_lookup = g_hash_table_lookup(app_lookup->processes,
-                                       GUINT_TO_POINTER(value.pid));
-       if (proc_lookup) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGE("Already exists [\033[1;36m%d\033[0;m]", value.pid);
-               return STC_ERROR_NONE;
-       }
-
-       proc_value = MALLOC0(stc_proc_value_s, 1);
-       if (!proc_value) {
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGE("Value allocation failed");
-               return STC_ERROR_OUT_OF_MEMORY;
-       }
-
-       proc_value->pid = value.pid;
-       proc_value->ground = value.ground;
-
-       g_hash_table_insert(app_lookup->processes,
-                       GUINT_TO_POINTER(proc_value->pid),
-                       proc_value);
-
-       /* add pid to application cgroup */
-       place_pids_to_net_cgroup(proc_value->pid, app_id);
-
-       if (STC_DEBUG_LOG && STC_STAT_LOG) {
-               __print_proc_all(app_lookup->processes);
-               STC_LOGD("\033[1;32mProcess added\033[0;m "
-                       "[\033[1;33m%d\033[0;m]", proc_value->pid);
-       }
-
-       return ret;
-}
-
-API stc_error_e stc_monitor_proc_remove(uint32_t classid,
-                                               pid_t pid)
-{
-       stc_error_e ret = STC_ERROR_NONE;
-       stc_app_value_s *app_lookup = NULL;
-       guint pid_count = 0;
-       GHashTable *apps = stc_monitor_get_system_apps();
-       GSList *conn_list = stc_get_connection_list();
-       remove_pid_context_s context = {
-               .pid = pid,
-               .app_value = NULL,
-               .entry_removed = FALSE,
-       };
-
-       if (!apps)
-               return STC_ERROR_NO_DATA;
-
-       if (classid == STC_UNKNOWN_CLASSID) {
-               g_hash_table_foreach(apps, __proc_remove_pid, &context);
-
-               if (context.entry_removed)
-                       app_lookup = context.app_value;
-
-               if (!app_lookup) {
-                       if (STC_DEBUG_LOG && STC_STAT_LOG)
-                               STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", pid);
-                       return STC_ERROR_NO_DATA;
-               }
-       } else {
-               app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid));
-               if (!app_lookup) {
-                       if (STC_DEBUG_LOG && STC_STAT_LOG)
-                               STC_LOGD("Application not found [\033[1;36m%d\033[0;m]",
-                                                       classid);
-                       return STC_ERROR_NO_DATA;
-               }
-
-               if (g_hash_table_remove(app_lookup->processes, GUINT_TO_POINTER(pid))) {
-                       if (STC_DEBUG_LOG && STC_STAT_LOG) {
-                               __print_proc_all(app_lookup->processes);
-                               STC_LOGD("\033[1;31mProcess removed\033[0;m "
-                                       "[\033[1;33m%d\033[0;m]", pid);
-                       }
-               } else {
-                       STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", pid);
-               }
-       }
-
-       pid_count = g_hash_table_size(app_lookup->processes);
-
-       if (!pid_count) {
-               for (; conn_list != NULL; conn_list = conn_list->next) {
-                       stc_connection_s *conn = conn_list->data;
-                       /* remove nfacct rule for this classid */
-                       stc_monitor_app_remove_monitor(GUINT_TO_POINTER(classid),
-                                               app_lookup, conn);
-
-                       if (app_lookup->state == STC_APP_STATE_FOREGROUND)
-                               stc_monitor_app_remove_accept(GUINT_TO_POINTER(classid),
-                                               app_lookup, conn);
-               }
-
-               stc_monitor_rstn_remove_for_app(classid);
-
-               g_hash_table_remove(apps, GUINT_TO_POINTER(classid));
-
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGD("\033[1;31mApplication removed\033[0;m "
-                               "[\033[1;36m%d\033[0;m]", classid);
-       }
-
-       return ret;
-}
-
-API stc_error_e stc_monitor_proc_move(uint32_t from,
-                                               uint32_t to)
-{
-       stc_error_e ret = STC_ERROR_NONE;
-       stc_app_value_s *from_lookup = NULL;
-       stc_app_value_s *to_lookup = NULL;
-       GSList *conn_list = stc_get_connection_list();
-       GHashTable *apps = stc_monitor_get_system_apps();
-
-       if (!apps)
-               return STC_ERROR_NO_DATA;
-
-       if (from != STC_UNKNOWN_CLASSID &&
-               to != STC_UNKNOWN_CLASSID) {
-               from_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(from));
-               if (!from_lookup) {
-                       if (STC_DEBUG_LOG && STC_STAT_LOG)
-                               STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", from);
-                       return STC_ERROR_NO_DATA;
-               }
-
-               to_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(to));
-               if (!to_lookup) {
-                       if (STC_DEBUG_LOG && STC_STAT_LOG)
-                               STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", to);
-                       return STC_ERROR_NO_DATA;
-               }
-
-               g_hash_table_foreach(from_lookup->processes,
-                               __proc_move_pid, to_lookup);
-
-               if (STC_DEBUG_LOG && STC_STAT_LOG) {
-                       __print_proc_all(to_lookup->processes);
-                       STC_LOGD("\033[1;34mProcesses moved\033[0;m "
-                               "[\033[1;36m%d\033[0;m] -> [\033[1;36m%d\033[0;m]",
-                               from, to);
-               }
-
-               g_hash_table_remove_all(from_lookup->processes);
-
-               if (STC_DEBUG_LOG && STC_STAT_LOG) {
-                       __print_proc_all(from_lookup->processes);
-                       STC_LOGD("\033[1;31mProcesses removed\033[0;m "
-                               "[\033[1;36m%d\033[0;m]", from);
-               }
-
-               for (; conn_list != NULL; conn_list = conn_list->next) {
-                       stc_connection_s *conn = conn_list->data;
-                       stc_monitor_app_remove_monitor(GUINT_TO_POINTER(from),
-                                               from_lookup, conn);
-
-                       if (from_lookup->state == STC_APP_STATE_FOREGROUND)
-                               stc_monitor_app_remove_accept(GUINT_TO_POINTER(from),
-                                               from_lookup, conn);
-               }
-
-               stc_monitor_rstn_remove_for_app(from);
-
-               g_hash_table_remove(apps, GUINT_TO_POINTER(from));
-
-               if (STC_DEBUG_LOG && STC_STAT_LOG)
-                       STC_LOGD("\033[1;31mApplication removed\033[0;m "
-                               "[\033[1;36m%d\033[0;m]", from);
-       }
-
-       return ret;
-}
diff --git a/src/monitor/stc-monitor-rstn.c b/src/monitor/stc-monitor-rstn.c
deleted file mode 100755 (executable)
index 31a05ab..0000000
+++ /dev/null
@@ -1,1465 +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.
- */
-
-#include <vconf.h>
-#include <vconf-keys.h>
-
-#include "counter.h"
-#include "stc-monitor.h"
-#include "stc-monitor-rstn.h"
-#include "stc-monitor-ipt.h"
-#include "stc-time.h"
-#include "table-counters.h"
-#include "table-restrictions.h"
-#include "table-statistics.h"
-#include "helper-net-cls.h"
-#include "stc-manager-plugin-appstatus.h"
-#include "stc-manager-plugin-tether.h"
-
-static void __print_rstn(stc_rstn_data_s *rstn_data)
-{
-       STC_LOGI("RstnID[%llu] AppID[%s] classid[%u] "
-               "iftype[%d] ifname[%s] rstn_state[%d] "
-               "rstn_type[%d] roaming[%d] subscriber_id[%s]",
-                rstn_data->restriction_id,
-                rstn_data->app_id, rstn_data->classid,
-                rstn_data->iftype, rstn_data->ifname,
-                rstn_data->rstn_state, rstn_data->rstn_type,
-                rstn_data->roaming, rstn_data->subscriber_id);
-       STC_LOGI("month_start_date[%d] limit[%lld] "
-               "warn_limit[%lld] monthly_limit[%lld] "
-               "weekly_limit[%lld] daily_limit[%lld] ",
-               rstn_data->month_start_date,
-               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA],
-               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN],
-               rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY],
-               rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY],
-               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY]);
-       STC_LOGI("data_counter[%lld] warn_counter[%lld] "
-               "monthly_counter[%lld] weekly_counter[%lld] "
-               "daily_counter[%lld]",
-               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA],
-               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN],
-               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY],
-               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY],
-               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY]);
-}
-
-static int __vconf_get_int(const char *key, int *value)
-{
-       int ret = 0;
-
-       ret = vconf_get_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to get vconfkey [%s] value", key);
-               return -1;
-       }
-
-       return 0;
-}
-
-static int __vconf_set_int(const char *key, int value)
-{
-       int ret = 0;
-
-       ret = vconf_set_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to set vconfkey [%s] value", key);
-               return -1;
-       }
-
-       return 0;
-}
-
-static stc_cb_ret_e __statistics_info_cb(const table_statistics_info *info,
-                                       void *user_data)
-{
-       stc_rstn_cumulative_data_s *stat = (stc_rstn_cumulative_data_s *)user_data;
-       int64_t counters = 0;
-
-       counters = info->cnt.in_bytes + info->cnt.out_bytes;
-
-       stat->monthly_stat += counters;
-       if (stat->week_start_ts <= info->interval->from)
-               stat->weekly_stat += counters;
-       if (stat->day_start_ts <= info->interval->from)
-               stat->daily_stat += counters;
-
-       return STC_CONTINUE;
-}
-
-static void __rstn_add_tether_rule(int64_t classid, gchar *mac,
-               nfacct_rule_intend intend, stc_iface_type_e iftype)
-{
-       GSList *conn_list = stc_get_connection_list();
-       struct nfacct_rule counter;
-       stc_s *stc = stc_get_manager();
-       char *ipaddr = NULL;
-       int ret;
-
-       if (!stc || !mac)
-               return;
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = classid;
-               counter.intend = intend;
-
-               if (conn->tether_state != TRUE ||
-                       conn->tether_iface.ifname == NULL)
-                       return;
-
-               counter.iftype = conn->tether_iface.type;
-               g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
-
-               /* get connected station ip based on its mac */
-               ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
-               if (ret != STC_ERROR_NONE)
-                       return;
-
-               /* tethering iptables rule */
-               stc_monitor_tether_add_in(&counter, ipaddr);
-               stc_monitor_tether_add_out(&counter, ipaddr);
-               g_free(ipaddr);
-       }
-}
-
-static void __rstn_del_tether_rule(int64_t classid, gchar *mac,
-               nfacct_rule_intend intend, stc_iface_type_e iftype)
-{
-       GSList *conn_list = stc_get_connection_list();
-       struct nfacct_rule counter;
-       stc_s *stc = stc_get_manager();
-       char *ipaddr = NULL;
-       int ret;
-
-       if (!stc || !mac)
-               return;
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = classid;
-               counter.intend = intend;
-
-               if (conn->tether_state != TRUE ||
-                       conn->tether_iface.ifname == NULL)
-                       return;
-
-               counter.iftype = conn->tether_iface.type;
-               g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
-
-               /* get connected station ip based on its mac */
-               ret = stc_plugin_tether_get_station_ip(mac, &ipaddr);
-               if (ret != STC_ERROR_NONE) {
-                       STC_LOGE("Error: no IP found for station mac(%s)", mac);
-                       return;
-               }
-
-               /* tethering iptables rule */
-               stc_monitor_tether_del_in(&counter, ipaddr);
-               stc_monitor_tether_del_out(&counter, ipaddr);
-               g_free(ipaddr);
-       }
-}
-
-static void __rstn_add_ipt_rule(int64_t classid, nfacct_rule_intend intend,
-                               stc_iface_type_e iftype)
-{
-       GSList *conn_list = stc_get_connection_list();
-       struct nfacct_rule counter;
-       stc_s *stc = stc_get_manager();
-
-       if (!stc)
-               return;
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-
-               if (conn == NULL)
-                       return;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = classid;
-               counter.intend = intend;
-
-               if (conn && conn->tether_iface.ifname != NULL &&
-                       classid == STC_TETHERING_APP_CLASSID) {
-                       counter.iftype = conn->tether_iface.type;
-                       g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
-               } else {
-                       counter.iftype = iftype;
-                       g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
-               }
-
-               /* iptables rule */
-               stc_monitor_ipt_add_in(&counter);
-               stc_monitor_ipt_add_out(&counter);
-
-               /* ip6tables rule */
-               stc_monitor_ip6t_add_in(&counter);
-               stc_monitor_ip6t_add_out(&counter);
-       }
-}
-
-static void __rstn_del_ipt_rule(int64_t classid, nfacct_rule_intend intend,
-                               stc_iface_type_e iftype)
-{
-       GSList *conn_list = stc_get_connection_list();
-       struct nfacct_rule counter;
-       stc_s *stc = stc_get_manager();
-
-       if (!stc)
-               return;
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-
-               if (conn == NULL)
-                       return;
-
-               if (!stc->carg) {
-                       stc->carg = MALLOC0(counter_arg_s, 1);
-                       if (stc->carg == NULL)
-                               return;
-
-                       stc->carg->sock = stc_monitor_get_contr_sock();
-               }
-
-               memset(&counter, 0, sizeof(struct nfacct_rule));
-
-               counter.carg = stc->carg;
-               counter.classid = classid;
-               counter.intend = intend;
-
-               if (conn && conn->tether_iface.ifname != NULL &&
-                       classid == STC_TETHERING_APP_CLASSID) {
-                       counter.iftype = conn->tether_iface.type;
-                       g_strlcpy(counter.ifname, conn->tether_iface.ifname, MAX_IFACE_LENGTH);
-               } else {
-                       counter.iftype = iftype;
-                       g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
-               }
-
-               /* iptables rule */
-               stc_monitor_ipt_del_in(&counter);
-               stc_monitor_ipt_del_out(&counter);
-
-               /* ip6tables rule */
-               stc_monitor_ip6t_del_in(&counter);
-               stc_monitor_ip6t_del_out(&counter);
-       }
-}
-
-static void __rstn_set_noti_state(int value)
-{
-       int state = STC_RSTN_STATE_INIT;
-
-       if (__vconf_get_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, &state))
-               return;
-
-       if (state == value) {
-               STC_LOGI("No need to change a restriction status: %d", state);
-               return;
-       }
-
-       __vconf_set_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, value);
-}
-
-static void __rstn_tethering_process(enum traffic_restriction_type rstn_type,
-                               char *app_id, stc_rstn_data_s *rstn_data, void *data)
-{
-       stc_connection_s *old_connection = (stc_connection_s *)data;
-       stc_connection_s *connection = NULL;
-       char *mac_str = NULL;
-
-       if (old_connection != NULL) {
-               connection = old_connection;
-               if (connection->tether_state == FALSE)
-                       return;
-
-               /* rstn not applicable for this interface */
-               if (rstn_data->ifname != NULL &&
-                       g_strcmp0("", rstn_data->ifname) != 0 &&
-                       g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0)
-                       return;
-       } else {
-               GSList *conn_list = stc_get_connection_list();
-               for (; conn_list != NULL; conn_list = conn_list->next) {
-                       stc_connection_s *conn = conn_list->data;
-                       if (conn->tether_state == FALSE)
-                               continue;
-
-                       if (rstn_data->ifname != NULL &&
-                               g_strcmp0(rstn_data->ifname, "") != 0 &&
-                               g_strcmp0(conn->tether_iface.ifname, rstn_data->ifname) == 0)
-                               connection = conn;
-               }
-
-               if (connection == NULL)
-                       return;
-       }
-
-       /* in case appid not a tethering app */
-       if (!g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX))
-               return;
-
-       /* Ignore TOTAL_TETHERING,
-        * Process only station appids */
-       if (rstn_data->classid == STC_TETHERING_APP_CLASSID)
-               return;
-
-       /* get the station mac based on classid */
-       stc_plugin_tether_get_station_by_classid(rstn_data->classid, &mac_str);
-       if (!mac_str) {
-               STC_LOGE("Station not found for classid(%d)", rstn_data->classid);
-               return;
-       }
-
-       switch (rstn_type) {
-       case RST_SET:
-       {
-               int i;
-               table_counters_info info;
-               int64_t effective_limit[STC_RSTN_LIMIT_TYPE_MAX] = { 0, };
-
-                       memset(&info, 0, sizeof(table_counters_info));
-                       rstn_data->limit_exceeded = 0;
-
-                       if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
-                                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
-                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
-                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
-                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
-                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
-                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
-                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
-                                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
-                                        rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
-                               table_counters_get(rstn_data->restriction_id, &info);
-
-                               time_t current_time = 0;
-                               stc_rstn_cumulative_data_s stat;
-                               table_statistics_select_rule rule;
-                               time_t last_week_ts = stc_monitor_get_last_week_ts();
-                               time_t last_day_ts = stc_monitor_get_last_day_ts();
-
-                               memset(&stat, 0, sizeof(stc_rstn_cumulative_data_s));
-                               stat.month_start_ts = rstn_data->month_start_ts;
-                               stat.week_start_ts = last_week_ts;
-                               stat.day_start_ts = last_day_ts;
-
-                               memset(&rule, 0, sizeof(table_statistics_select_rule));
-                               rule.from = rstn_data->month_start_ts;
-                               time(&current_time);
-                               rule.to = current_time;
-                               rule.iftype = rstn_data->iftype;
-                               rule.granularity = GRANULARITY;
-
-                               table_statistics_per_app(app_id, &rule, __statistics_info_cb, &stat);
-
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter + stat.monthly_stat;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter + stat.weekly_stat;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter + stat.daily_stat;
-                       }
-
-                       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
-                               if (rstn_data->limit[i] >= 0) {
-                                       effective_limit[i] = rstn_data->limit[i] - rstn_data->counter[i];
-
-                                       if (effective_limit[i] < 0)
-                                               rstn_data->limit_exceeded |= (1 << i);
-                               }
-                       }
-
-                       STC_LOGD("Rstn_id[%llu] datausage[%lld]bytes",
-                                       rstn_data->restriction_id, info.data_counter);
-
-                       if (rstn_data->limit_exceeded != 0 &&
-                                       rstn_data->limit_exceeded != (1 << STC_RSTN_LIMIT_TYPE_DATA_WARN)) {
-                               __rstn_add_tether_rule(rstn_data->classid, mac_str,
-                                               NFACCT_TETH_BLOCK, rstn_data->iftype);
-                       }
-
-                       rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
-       }
-       break;
-       case RST_EXCLUDE:
-       {
-               __rstn_add_tether_rule(rstn_data->classid, mac_str,
-                                       NFACCT_TETH_ALLOW, rstn_data->iftype);
-
-                       rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
-                       rstn_data->limit_exceeded = 0;
-                       rstn_data->limit_notified = 0;
-       }
-       break;
-       case RST_UNSET:
-       {
-                       int i;
-                       __rstn_del_tether_rule(rstn_data->classid, mac_str,
-                                       NFACCT_TETH_BLOCK, rstn_data->iftype);
-
-                       rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
-                       rstn_data->limit_exceeded = 0;
-                       rstn_data->limit_notified = 0;
-
-                       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++)
-                               if (rstn_data->limit[i] >= 0)
-                                       rstn_data->counter[i] = 0;
-       }
-       break;
-       default:
-               break;
-       }
-       FREE(mac_str);
-}
-
-static void __rstn_process(enum traffic_restriction_type rstn_type,
-                                 char *app_id, stc_rstn_data_s *rstn_data, void *data)
-{
-       stc_connection_s *old_connection = (stc_connection_s *)data;
-       stc_connection_s *connection = NULL;
-
-       if (old_connection != NULL) {
-               connection = old_connection;
-               if (connection->ifname == NULL)
-                       return;
-
-               /* rstn not applicable for this interface */
-               if (rstn_data->ifname != NULL &&
-                       g_strcmp0(rstn_data->ifname, "") != 0 &&
-                   g_strcmp0(connection->ifname, rstn_data->ifname) != 0 &&
-                   g_strcmp0(connection->tether_iface.ifname, rstn_data->ifname) != 0)
-                   return;
-       } else {
-               GSList *conn_list = stc_get_connection_list();
-               for (; conn_list != NULL; conn_list = conn_list->next) {
-                       stc_connection_s *conn = conn_list->data;
-                       if (conn == NULL || conn->ifname == NULL)
-                               continue;
-
-                       if (rstn_data->ifname != NULL &&
-                               g_strcmp0(rstn_data->ifname, "") != 0 &&
-                               g_strcmp0(conn->ifname, rstn_data->ifname) == 0 &&
-                               g_strcmp0(conn->tether_iface.ifname, rstn_data->ifname) == 0)
-                               connection = conn;
-               }
-
-               if (connection == NULL)
-                       return;
-       }
-
-       /* classid is invalid */
-       if (rstn_data->classid <= STC_UNKNOWN_CLASSID)
-               return;
-
-       /* Do not proceed for tethering station appid if found here,
-        * for tethering station apps __rstn_tethering_process() call
-        * will handle it */
-       if (g_str_has_suffix(app_id, STC_TETHERING_APP_SUFFIX) &&
-                       rstn_data->classid != STC_TETHERING_APP_CLASSID)
-               return;
-
-       switch (rstn_type) {
-       case RST_SET:
-       {
-               int i;
-               table_counters_info info;
-               int64_t effective_limit[STC_RSTN_LIMIT_TYPE_MAX] = { 0, };
-
-               memset(&info, 0, sizeof(table_counters_info));
-               rstn_data->limit_exceeded = 0;
-
-               if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
-                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
-                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
-                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
-                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
-                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
-                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
-                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
-                       (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
-                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
-                       table_counters_get(rstn_data->restriction_id, &info);
-
-                       time_t current_time = 0;
-                       stc_rstn_cumulative_data_s stat;
-                       table_statistics_select_rule rule;
-                       time_t last_week_ts = stc_monitor_get_last_week_ts();
-                       time_t last_day_ts = stc_monitor_get_last_day_ts();
-
-                       memset(&stat, 0, sizeof(stc_rstn_cumulative_data_s));
-                       stat.month_start_ts = rstn_data->month_start_ts;
-                       stat.week_start_ts = last_week_ts;
-                       stat.day_start_ts = last_day_ts;
-
-                       memset(&rule, 0, sizeof(table_statistics_select_rule));
-                       rule.from = rstn_data->month_start_ts;
-                       time(&current_time);
-                       rule.to = current_time;
-                       rule.iftype = rstn_data->iftype;
-                       rule.granularity = GRANULARITY;
-
-                       table_statistics_per_app(rstn_data->app_id, &rule, __statistics_info_cb, &stat);
-
-                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
-                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
-                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter + stat.monthly_stat;
-                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter + stat.weekly_stat;
-                       rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter + stat.daily_stat;
-
-                       if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                               STC_LOGD("Rstn counter data[%lld] warn[%lld] "
-                               "monthly[%lld] weekly[%lld] daily[%lld]",
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA],
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN],
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY],
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY],
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY]);
-               }
-
-               for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
-                       if (rstn_data->limit[i] >= 0) {
-                               effective_limit[i] = rstn_data->limit[i] - rstn_data->counter[i];
-
-                               if (effective_limit[i] < 0)
-                                       rstn_data->limit_exceeded |= (1 << i);
-                       }
-               }
-
-               STC_LOGD("Rstn_id[%llu] limit[%lld] datausage[%lld]",
-                                       rstn_data->restriction_id,
-                                       rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA],
-                                       info.data_counter);
-
-               if (rstn_data->limit_exceeded != 0 &&
-                       rstn_data->limit_exceeded != (1 << STC_RSTN_LIMIT_TYPE_DATA_WARN)) {
-                       __rstn_add_ipt_rule(rstn_data->classid, NFACCT_BLOCK, rstn_data->iftype);
-               }
-
-               if (rstn_data->classid == STC_BACKGROUND_APP_CLASSID)
-                       __rstn_add_ipt_rule(rstn_data->classid, NFACCT_BLOCK, rstn_data->iftype);
-
-               rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
-
-               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
-                       STC_LOGD("Restriction activated "
-                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                               rstn_data->classid, rstn_data->restriction_id);
-               }
-       }
-       break;
-       case RST_EXCLUDE:
-               __rstn_add_ipt_rule(rstn_data->classid, NFACCT_ALLOW,
-                                   rstn_data->iftype);
-
-               rstn_data->rstn_state = STC_RSTN_STATE_ACTIVATED;
-               rstn_data->limit_exceeded = 0;
-               rstn_data->limit_notified = 0;
-
-               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
-                       STC_LOGD("Restriction activated "
-                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                               rstn_data->classid, rstn_data->restriction_id);
-               }
-               break;
-       case RST_UNSET:
-       {
-               int i;
-
-               if (rstn_data->classid == STC_TETHERING_APP_CLASSID)
-                       __rstn_del_ipt_rule(rstn_data->classid, NFACCT_BLOCK,
-                                           rstn_data->iftype);
-               else
-                       __rstn_del_ipt_rule(rstn_data->classid, rstn_data->rstn_type,
-                                           rstn_data->iftype);
-
-               rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
-               rstn_data->limit_exceeded = 0;
-               rstn_data->limit_notified = 0;
-
-               for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++)
-                       if (rstn_data->limit[i] >= 0)
-                               rstn_data->counter[i] = 0;
-
-               __rstn_set_noti_state(STC_RSTN_STATE_UNSET);
-
-               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
-                       STC_LOGD("Restriction deactivated "
-                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                               rstn_data->classid, rstn_data->restriction_id);
-               }
-       }
-       break;
-       default:
-               break;
-       }
-}
-
-static void __rstn_add(gpointer data, gpointer user_data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-
-       /* rstn rule is activated */
-       if (rstn_data->rstn_state == STC_RSTN_STATE_ACTIVATED) {
-               if (STC_DEBUG_LOG && STC_RSTN_LOG) {
-                       STC_LOGD("Restriction already activated "
-                               "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                               rstn_data->classid, rstn_data->restriction_id);
-               }
-               return;
-       }
-
-       if (rstn_data->rstn_type == STC_RSTN_TYPE_ACCEPT) {
-               __rstn_process(RST_EXCLUDE,
-                       rstn_data->app_id, rstn_data, user_data);
-               __rstn_tethering_process(RST_EXCLUDE,
-                       rstn_data->app_id, rstn_data, user_data);
-       } else {
-               __rstn_process(RST_SET,
-                       rstn_data->app_id, rstn_data, user_data);
-               __rstn_tethering_process(RST_SET,
-                       rstn_data->app_id, rstn_data, user_data);
-       }
-
-       if (STC_DEBUG_LOG && STC_RSTN_LOG) {
-               __print_rstn(rstn_data);
-               STC_LOGD("\033[1;32mRestriction added\033[0;m "
-                       "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                       rstn_data->classid, rstn_data->restriction_id);
-       }
-}
-
-static void __rstn_add_by_connection(gpointer key,
-                                       gpointer value, gpointer data)
-{
-       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
-
-       g_slist_foreach(rstn_value->rules, __rstn_add, data);
-}
-
-static void __rstn_remove(gpointer data, gpointer user_data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-
-       if (rstn_data->rstn_state == STC_RSTN_STATE_DEACTIVATED) {
-               STC_LOGD("\033[1;31mRestriction already deactivated\033[0;m "
-                       "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                       rstn_data->classid, rstn_data->restriction_id);
-               return;
-       }
-
-       __rstn_process(RST_UNSET,
-               rstn_data->app_id, rstn_data, user_data);
-       __rstn_tethering_process(RST_UNSET,
-               rstn_data->app_id, rstn_data, user_data);
-
-       if (STC_DEBUG_LOG && STC_RSTN_LOG) {
-               __print_rstn(rstn_data);
-               STC_LOGD("\033[1;31mRestriction removed\033[0;m "
-                       "[\033[1;36m%d\033[0;m:\033[1;35m%d\033[0;m]",
-                       rstn_data->classid, rstn_data->restriction_id);
-       }
-}
-
-static void __rstn_remove_by_connection(gpointer key,
-                                       gpointer value, gpointer data)
-{
-       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
-
-       g_slist_foreach(rstn_value->rules, __rstn_remove, data);
-}
-
-static void __rstn_update_counter_data(gpointer data,
-                                               gpointer user_data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-
-       table_counters_info info = {
-               .restriction_id = rstn_data->restriction_id,
-               .data_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA],
-               .warn_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN],
-               .monthly_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY],
-               .weekly_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY],
-               .daily_counter = rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY]
-       };
-
-       table_counters_update_counters(&info);
-}
-
-static void __rstn_update_counter_value(gpointer key,
-                                               gpointer value, gpointer data)
-{
-       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
-
-       g_slist_foreach(rstn_value->rules, __rstn_update_counter_data, NULL);
-}
-
-static void __rstn_data_destroy(gpointer data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-
-       FREE(rstn_data->app_id);
-       FREE(rstn_data->ifname);
-       FREE(rstn_data->subscriber_id);
-       FREE(rstn_data->mac);
-
-       FREE(rstn_data);
-}
-
-static gint __rstn_data_comp(gconstpointer a, gconstpointer b)
-{
-       stc_rstn_data_s *da = (stc_rstn_data_s *)a;
-       stc_rstn_data_s *db = (stc_rstn_data_s *)b;
-
-       if ((da->iftype == db->iftype) &&
-               (g_strcmp0(da->ifname, db->ifname) == 0) &&
-               (g_strcmp0(da->subscriber_id, db->subscriber_id) == 0) &&
-               (da->roaming == db->roaming))
-               return 0;
-
-       return -1;
-}
-
-static stc_error_e __rstn_data_remove(stc_rstn_data_s *data)
-{
-       stc_rstn_value_s *lookup_value;
-       GSList *lookup_list;
-       stc_rstn_data_s *lookup_data;
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return STC_ERROR_NO_DATA;
-
-       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(data->classid));
-       if (!lookup_value) {
-               if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                       STC_LOGE("Restriction not found [\033[1;36m%d\033[0;m]",
-                                               data->classid);
-               return STC_ERROR_NO_DATA;
-       }
-
-       lookup_list = g_slist_find_custom(lookup_value->rules,
-                                       data, __rstn_data_comp);
-       if (!lookup_list) {
-               if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                       STC_LOGE("Restriction not found [%d:%s:%s:%d]",
-                               data->iftype, data->ifname,
-                               data->subscriber_id, data->roaming);
-               return STC_ERROR_NO_DATA;
-       }
-
-       lookup_data = lookup_list->data;
-
-       /* remove counter also */
-       table_counters_delete(lookup_data->restriction_id);
-       __rstn_remove(lookup_data, NULL);
-
-       lookup_value->rules = g_slist_remove(lookup_value->rules,
-                                                       lookup_data);
-       __rstn_data_destroy(lookup_data);
-
-       if (!lookup_value->rules)
-               g_hash_table_remove(rstns, GUINT_TO_POINTER(data->classid));
-
-       return STC_ERROR_NONE;
-}
-
-static stc_error_e __rstn_data_add(stc_rstn_data_s *data)
-{
-       int i;
-       stc_rstn_value_s *lookup_value;
-       stc_rstn_value_s *rstn_value;
-       stc_rstn_data_s *rstn_data;
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return STC_ERROR_NO_DATA;
-
-       rstn_data = MALLOC0(stc_rstn_data_s, 1);
-       if (!rstn_data) {
-               if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                       STC_LOGE("Rstn_data allocation failed");
-               return STC_ERROR_OUT_OF_MEMORY;
-       }
-
-       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(data->classid));
-       if (!lookup_value) {
-               rstn_value = MALLOC0(stc_rstn_value_s, 1);
-               if (!rstn_value) {
-                       if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                               STC_LOGE("Rstn_value allocation failed");
-                       FREE(rstn_data);
-                       return STC_ERROR_OUT_OF_MEMORY;
-               }
-
-               g_hash_table_insert(rstns, GUINT_TO_POINTER(data->classid),
-                       rstn_value);
-       } else {
-               rstn_value = lookup_value;
-       }
-
-       rstn_data->classid = data->classid;
-       rstn_data->app_id = g_strdup(data->app_id);
-       rstn_data->iftype = data->iftype;
-       rstn_data->ifname = g_strdup(data->ifname);
-       rstn_data->subscriber_id = g_strdup(data->subscriber_id);
-       rstn_data->roaming = data->roaming;
-       rstn_data->mac = g_strdup(data->mac);
-
-       rstn_data->restriction_id = data->restriction_id;
-       rstn_data->rstn_state = data->rstn_state;
-       rstn_data->rstn_type = data->rstn_type;
-
-       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
-               rstn_data->limit[i] = data->limit[i];
-               rstn_data->counter[i] = 0;
-       }
-
-       rstn_data->limit_exceeded = 0;
-       rstn_data->limit_notified = 0;
-       rstn_data->month_start_date = data->month_start_date;
-       rstn_data->month_start_ts = data->month_start_ts;
-
-       __rstn_data_remove(rstn_data);
-       rstn_value->rules = g_slist_append(rstn_value->rules, rstn_data);
-
-       __rstn_add(rstn_data, NULL);
-
-       return STC_ERROR_NONE;
-}
-
-static void __rstn_value_destroy(gpointer data)
-{
-       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)data;
-
-       g_slist_free_full(rstn_value->rules, __rstn_data_destroy);
-
-       FREE(rstn_value);
-}
-
-static stc_cb_ret_e __rstn_insert_cb(const table_restrictions_info *info,
-                                           void *user_data)
-{
-       stc_cb_ret_e ret = STC_CONTINUE;
-       stc_rstn_data_s data;
-
-       memset(&data, 0, sizeof(stc_rstn_data_s));
-
-       if (info->app_id) {
-               data.classid = get_classid_by_app_id(info->app_id, TRUE);
-               data.app_id = info->app_id;
-       } else
-               data.classid = STC_UNKNOWN_CLASSID;
-
-       data.iftype = info->iftype;
-       data.ifname = info->ifname;
-       data.subscriber_id = info->subscriber_id;
-       data.roaming = info->roaming;
-
-       data.rstn_type = info->rstn_type;
-       data.rstn_state = STC_RSTN_STATE_UNKNOWN;
-       data.restriction_id = info->restriction_id;
-
-       data.limit[STC_RSTN_LIMIT_TYPE_DATA] = info->data_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info->data_warn_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_MONTHLY] = info->monthly_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_WEEKLY] = info->weekly_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_DAILY] = info->daily_limit;
-
-       if (__rstn_data_add(&data) != STC_ERROR_NONE)
-               ret = STC_CANCEL;
-
-       return ret;
-}
-
-static void __rstn_update_counter(classid_bytes_context_s *context,
-                               uint32_t classid)
-{
-       stc_rstn_value_s *lookup;
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return;
-
-       lookup = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
-       if (lookup) {
-               context->counter->classid = classid;
-               g_slist_foreach(lookup->rules,
-                       stc_monitor_rstn_update_counter,
-                       context);
-       }
-}
-
-static void __rstn_action_when_limit_exceeded_tethering(stc_rstn_data_s *rstn_data,
-                                       classid_bytes_context_s *context)
-{
-       char *mac_str = NULL;
-       struct nfacct_rule *counter = context->counter;
-
-       /* get the station mac based on classid */
-       stc_plugin_tether_get_station_by_classid(counter->classid, &mac_str);
-       if (!mac_str) {
-               STC_LOGE("Station not found for classid(%d)", counter->classid);
-               return;
-       }
-
-       STC_LOGI("Station mac[%s] classid[%u] iftype[%u] iotype[%d] "
-                       "intend[%d] ifname[%s] bytes[%lld]", mac_str,
-                       counter->classid, counter->iftype, counter->iotype,
-                       counter->intend, counter->ifname, context->bytes);
-
-       /* Block tethering station immediately */
-       counter->intend = NFACCT_TETH_BLOCK;
-       __rstn_del_tether_rule(counter->classid, mac_str,
-                       NFACCT_TETH_BLOCK, rstn_data->iftype);
-
-       __rstn_add_tether_rule(counter->classid, mac_str,
-                       NFACCT_TETH_BLOCK, rstn_data->iftype);
-       counter->intend = NFACCT_TETH_COUNTER;
-
-       g_free(mac_str);
-}
-
-static void __reset_time_counter_foreach_rstn_data(gpointer data,
-                                                 gpointer user_data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-       reset_time_limits_context_s *context =
-               (reset_time_limits_context_s *)user_data;
-       int i;
-       time_t now_month_start_ts;
-
-       if (rstn_data->month_start_date == 0) {
-               table_counters_info info;
-               memset(&info, 0, sizeof(table_counters_info));
-               table_counters_get_timestamps(rstn_data->restriction_id, &info);
-
-               if (info.month_start_date == 0)
-                       rstn_data->month_start_date = 1;
-               else
-                       rstn_data->month_start_date = info.month_start_date;
-               rstn_data->month_start_ts = info.month_start_ts;
-       }
-
-       now_month_start_ts =
-               stc_time_get_month_start(context->now,
-                                        rstn_data->month_start_date);
-
-       if (rstn_data->month_start_ts != now_month_start_ts) {
-               rstn_data->month_start_ts = now_month_start_ts;
-               context->month_start_ts = now_month_start_ts;
-               context->is_updated |= (1 << STC_RSTN_LIMIT_TYPE_MONTHLY);
-       }
-
-       if (context->is_updated) {
-               table_counters_info info;
-               memset(&info, 0, sizeof(table_counters_info));
-
-               info.restriction_id = rstn_data->restriction_id;
-               info.month_start_date = rstn_data->month_start_date;
-               info.month_start_ts = rstn_data->month_start_ts;
-               info.week_start_ts = context->week_start_ts;
-               info.day_start_ts = context->day_start_ts;
-
-               table_counters_update_timestamps(&info);
-       }
-
-       for (i = STC_RSTN_LIMIT_TYPE_MONTHLY; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
-
-               if ((context->is_updated) & (1 << i)) {
-                       /* reset limit */
-                       rstn_data->counter[i] = 0;
-
-                       if (rstn_data->limit_exceeded & (1 << i)) {
-                               /* remove iptables rule */
-                               GSList *conn_list = stc_get_connection_list();
-                               struct nfacct_rule counter;
-                               stc_s *stc = stc_get_manager();
-                               if (stc == NULL) {
-                                       STC_LOGE("Can't get stc data");
-                                       goto try_next_callback;
-                               }
-
-                               if (!stc->carg) {
-                                       stc->carg = MALLOC0(counter_arg_s, 1);
-                                       if (stc->carg == NULL) {
-                                               goto try_next_callback;
-                                       }
-
-                                       stc->carg->sock = stc_monitor_get_contr_sock();
-                               }
-
-                               for (; conn_list != NULL; conn_list = conn_list->next) {
-                                       stc_connection_s *conn = conn_list->data;
-
-                                       memset(&counter, 0, sizeof(struct nfacct_rule));
-
-                                       counter.carg = stc->carg;
-                                       counter.classid = rstn_data->classid;
-                                       counter.intend = NFACCT_BLOCK;
-                                       counter.iftype = rstn_data->iftype;
-                                       g_strlcpy(counter.ifname, conn->ifname, MAX_IFACE_LENGTH);
-
-                                       /* iptables rule */
-                                       stc_monitor_ipt_del_in(&counter);
-                                       stc_monitor_ipt_del_out(&counter);
-
-                                       /* ip6tables rule */
-                                       stc_monitor_ip6t_del_in(&counter);
-                                       stc_monitor_ip6t_del_out(&counter);
-
-                                       rstn_data->rstn_state = STC_RSTN_STATE_DEACTIVATED;
-                                       rstn_data->limit_exceeded &= ~(1 << i);
-                                       rstn_data->limit_notified &= ~(1 << i);
-                               }
-                       }
-               }
-       }
-
-try_next_callback:
-       return;
-}
-
-static void __reset_time_counter_foreach_rstn_value(gpointer key,
-                                                 gpointer value,
-                                                 gpointer data)
-{
-       stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
-       g_slist_foreach(rstn_value->rules,
-               __reset_time_counter_foreach_rstn_data, data);
-}
-
-void stc_monitor_rstn_reset_time_counters_if_required(void)
-{
-       reset_time_limits_context_s context;
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-       time_t last_week_ts = stc_monitor_get_last_week_ts();
-       time_t last_day_ts = stc_monitor_get_last_day_ts();
-
-       context.now = time(NULL);
-       context.week_start_ts = stc_time_get_week_start(context.now);
-       context.day_start_ts = stc_time_get_day_start(context.now);
-       context.is_updated = 0;
-
-       if (last_week_ts != context.week_start_ts) {
-               stc_monitor_set_last_week_ts(context.week_start_ts);
-               context.is_updated |= (1 << STC_RSTN_LIMIT_TYPE_WEEKLY);
-       }
-
-       if (last_day_ts != context.day_start_ts) {
-               stc_monitor_set_last_day_ts(context.day_start_ts);
-               context.is_updated |= (1 << STC_RSTN_LIMIT_TYPE_DAILY);
-       }
-
-       if (rstns) {
-               g_hash_table_foreach(rstns,
-                              __reset_time_counter_foreach_rstn_value,
-                              &context);
-
-               if (context.is_updated)
-                       STC_LOGD("Counter reset completed month_start[%ld] "
-                               "week_start[%ld] day_start[%ld]",
-                               context.month_start_ts, last_week_ts, last_day_ts);
-       }
-}
-
-void stc_monitor_rstn_update_counter(gpointer data,
-                                       gpointer user_data)
-{
-       int i;
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-       classid_bytes_context_s *context = (classid_bytes_context_s *)user_data;
-       GSList *conn_list = stc_get_connection_list();
-
-       for (; conn_list != NULL; conn_list = conn_list->next) {
-               stc_connection_s *conn = conn_list->data;
-
-               if (rstn_data->iftype != context->counter->iftype)
-                       return;
-
-               if (rstn_data->ifname != NULL &&
-                       g_strcmp0(rstn_data->ifname, "") &&
-                       g_strcmp0(rstn_data->ifname, context->counter->ifname) != 0)
-                       return;
-
-               if (rstn_data->subscriber_id != NULL &&
-                       g_strcmp0(rstn_data->subscriber_id, "") &&
-                       g_strcmp0(rstn_data->subscriber_id, conn->subscriber_id) != 0)
-                       return;
-
-               if (rstn_data->roaming != conn->roaming)
-                       return;
-
-               if (rstn_data->limit_exceeded != 0) {
-                       context->data_limit_exceeded = TRUE;
-                       return;
-               }
-
-               switch (context->counter->iotype) {
-               case NFACCT_COUNTER_IN:
-               case NFACCT_COUNTER_OUT:
-                       if ((rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] == 0 &&
-                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA] >= 0) ||
-                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] == 0 &&
-                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] >= 0) ||
-                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] == 0 &&
-                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_MONTHLY] >= 0) ||
-                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] == 0 &&
-                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_WEEKLY] >= 0) ||
-                               (rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] == 0 &&
-                               rstn_data->limit[STC_RSTN_LIMIT_TYPE_DAILY] >= 0)) {
-                               table_counters_info info;
-                               memset(&info, 0, sizeof(table_counters_info));
-                               table_counters_get(rstn_data->restriction_id, &info);
-
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA] = info.data_counter;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info.warn_counter;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_MONTHLY] = info.monthly_counter;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_WEEKLY] = info.weekly_counter;
-                               rstn_data->counter[STC_RSTN_LIMIT_TYPE_DAILY] = info.daily_counter;
-                       }
-
-                       for (i = 0; i < STC_RSTN_LIMIT_TYPE_MAX; i++) {
-                               if (rstn_data->limit[i] >= 0 &&
-                                       !(rstn_data->limit_notified & (1 << i))) {
-                                       rstn_data->counter[i] += context->bytes;
-                                       if (rstn_data->limit[i] <= rstn_data->counter[i])
-                                               stc_monitor_rstn_action_when_limit_exceeded(i,
-                                                                                       rstn_data,
-                                                                                       context);
-                               }
-                       }
-
-                       stc_monitor_set_rstns_updated(TRUE);
-                       __print_rstn(rstn_data);
-                       break;
-               default:
-                       STC_LOGE("Unknown iotype");
-               }
-       }
-}
-
-void stc_monitor_rstn_update_iface_counter(classid_bytes_context_s *context)
-{
-       switch (context->counter->iftype) {
-       case STC_IFACE_DATACALL:
-               __rstn_update_counter(context, STC_TOTAL_DATACALL_CLASSID);
-               break;
-       case STC_IFACE_WIFI:
-               __rstn_update_counter(context, STC_TOTAL_WIFI_CLASSID);
-               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       case STC_IFACE_BLUETOOTH:
-               __rstn_update_counter(context, STC_TOTAL_BLUETOOTH_CLASSID);
-               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       case STC_IFACE_USB:
-               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       case STC_IFACE_P2P:
-               __rstn_update_counter(context, STC_TETHERING_APP_CLASSID);
-               break;
-       default:
-               break;
-       }
-}
-
-void stc_monitor_rstn_action_when_limit_exceeded(stc_rstn_limit_type_e limit_type,
-                                               stc_rstn_data_s *rstn_data,
-                                               classid_bytes_context_s *context)
-{
-       gboolean rv;
-       char iftype[MAX_INT_LENGTH] = { 0, };
-       char byte[MAX_INT_LENGTH] = { 0, };
-       const char *signal_name = NULL;
-       const char *net_popup_content = NULL;
-       const char *net_popup_type = NULL;
-       stc_s *stc = (stc_s *)stc_get_manager();
-
-       if (stc == NULL) {
-               STC_LOGE("Failed to get stc data");
-               return;
-       }
-
-       switch (limit_type) {
-       case STC_RSTN_LIMIT_TYPE_DATA_WARN:
-       {
-               signal_name = "WarnThresholdCrossed";
-               net_popup_content = "warn threshold crossed";
-               net_popup_type = "warning_noti";
-       }
-       break;
-       case STC_RSTN_LIMIT_TYPE_DATA:
-       case STC_RSTN_LIMIT_TYPE_MONTHLY:
-       case STC_RSTN_LIMIT_TYPE_WEEKLY:
-       case STC_RSTN_LIMIT_TYPE_DAILY:
-       {
-               signal_name = "RestrictionThresholdCrossed";
-               net_popup_content = "restriction threshold crossed";
-               net_popup_type = "restriction_noti";
-
-               /* Apply restriction for tethering apps if app_id is of tethering client
-                * otherwise do the normal iptables rule */
-               if (context->counter->intend == NFACCT_TETH_COUNTER) {
-
-                       if (g_str_has_suffix(rstn_data->app_id, STC_TETHERING_APP_SUFFIX) &&
-                                       rstn_data->classid != STC_TETHERING_APP_CLASSID) {
-                               __rstn_action_when_limit_exceeded_tethering(rstn_data,
-                                               context);
-                       }
-
-               } else {
-                       /* block immediately */
-                       context->counter->intend = NFACCT_BLOCK;
-                       stc_monitor_ipt_del_in(context->counter);
-                       stc_monitor_ipt_del_out(context->counter);
-                       stc_monitor_ipt_add_in(context->counter);
-                       stc_monitor_ipt_add_out(context->counter);
-
-                       stc_monitor_ip6t_del_in(context->counter);
-                       stc_monitor_ip6t_del_out(context->counter);
-                       stc_monitor_ip6t_add_in(context->counter);
-                       stc_monitor_ip6t_add_out(context->counter);
-                       context->counter->intend = NFACCT_COUNTER;
-               }
-
-               rstn_data->limit_exceeded |= (1 << limit_type);
-               __rstn_set_noti_state(STC_RSTN_STATE_SET);
-       }
-       break;
-       default:
-               break;
-       }
-
-       if (signal_name == NULL) {
-               STC_LOGE("Invalid parameter: limit_type");
-               return;
-       }
-
-       /* emit signal */
-       rv = stc_manager_dbus_emit_signal(stc->connection,
-                                                 STC_DBUS_SERVICE_RESTRICTION_PATH,
-                                                 STC_DBUS_INTERFACE_RESTRICTION,
-                                                 signal_name,
-                                                 g_variant_new("(si)",
-                                                 rstn_data->app_id,
-                                                 rstn_data->iftype));
-
-       if (rv == TRUE)
-               rstn_data->limit_notified |= (1 << limit_type);
-
-       snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_data->iftype);
-       snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_data->limit[limit_type]);
-       stc_plugin_appstatus_send_message(net_popup_content,
-                       net_popup_type, rstn_data->app_id, iftype, byte);
-
-       if (STC_DEBUG_LOG && STC_RSTN_LOG)
-               STC_LOGD("Limit exceeded [\033[0;31m%s\033[0;m:%d]",
-                                       net_popup_content, limit_type);
-}
-
-gboolean stc_monitor_rstn_flush_contr_to_db(gpointer user_data)
-{
-       time_t current_time = 0;
-       stc_s *stc = stc_get_manager();
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-       gboolean rstns_updated = stc_monitor_get_rstns_updated();
-
-       if (stc && stc->carg)
-               current_time = stc->carg->last_run_time;
-
-       if (rstns_updated == FALSE)
-               return G_SOURCE_REMOVE;
-
-       stc_monitor_set_rstns_updated(FALSE);
-
-       if (rstns)
-               g_hash_table_foreach(rstns,
-                              __rstn_update_counter_value,
-                              &current_time);
-
-       STC_LOGI("Flushed rstns counters to database");
-       return G_SOURCE_REMOVE;
-}
-
-stc_error_e stc_monitor_rstn_add(const table_restrictions_info *info)
-{
-       stc_rstn_data_s data;
-
-       memset(&data, 0, sizeof(stc_rstn_data_s));
-
-       if (info->app_id) {
-               data.classid = get_classid_by_app_id(info->app_id, TRUE);
-               data.app_id = info->app_id;
-       } else
-               data.classid = STC_UNKNOWN_CLASSID;
-
-       if (data.classid == STC_BACKGROUND_APP_CLASSID) {
-               stc_monitor_set_background_state(TRUE);
-               __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, TRUE);
-       }
-
-       data.iftype = info->iftype;
-       data.ifname = info->ifname;
-       data.subscriber_id = info->subscriber_id;
-       data.roaming = info->roaming;
-       data.mac = info->mac;
-
-       data.rstn_type = info->rstn_type;
-       data.rstn_state = STC_RSTN_STATE_UNKNOWN;
-       data.restriction_id = info->restriction_id;
-
-       data.limit[STC_RSTN_LIMIT_TYPE_DATA] = info->data_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_DATA_WARN] = info->data_warn_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_MONTHLY] = info->monthly_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_WEEKLY] = info->weekly_limit;
-       data.limit[STC_RSTN_LIMIT_TYPE_DAILY] = info->daily_limit;
-       data.month_start_date = info->month_start_date;
-       data.month_start_ts = stc_time_get_month_start(time(NULL),
-                                                                               info->month_start_date);
-
-       return __rstn_data_add(&data);
-}
-
-void stc_monitor_rstn_add_for_app(uint32_t classid)
-{
-       stc_rstn_value_s *lookup_value;
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return;
-
-       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
-       if (!lookup_value) {
-               if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                       STC_LOGD("Restriction not found [\033[1;36m%d\033[0;m]",
-                                               classid);
-               return;
-       }
-
-       g_slist_foreach(lookup_value->rules, __rstn_add, NULL);
-}
-
-void stc_monitor_rstn_add_by_connection(stc_connection_s *conn)
-{
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return;
-
-       g_hash_table_foreach(rstns, __rstn_add_by_connection, conn);
-}
-
-stc_error_e stc_monitor_rstn_remove(const table_restrictions_info *info)
-{
-       stc_rstn_data_s data;
-
-       memset(&data, 0, sizeof(stc_rstn_data_s));
-
-       data.classid = get_classid_by_app_id(info->app_id, TRUE);
-       data.app_id = info->app_id;
-
-       data.iftype = info->iftype;
-       data.ifname = info->ifname;
-       data.subscriber_id = info->subscriber_id;
-       data.roaming = info->roaming;
-
-       if (g_strcmp0(info->app_id, STC_TOTAL_BACKGROUND) == 0) {
-               stc_monitor_set_background_state(FALSE);
-               __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, FALSE);
-       }
-
-       return __rstn_data_remove(&data);
-}
-
-void stc_monitor_rstn_remove_for_app(uint32_t classid)
-{
-       stc_rstn_value_s *lookup_value;
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return;
-
-       lookup_value = g_hash_table_lookup(rstns, GUINT_TO_POINTER(classid));
-       if (!lookup_value) {
-               if (STC_DEBUG_LOG && STC_RSTN_LOG)
-                       STC_LOGD("Restriction not found [\033[1;36m%d\033[0;m]",
-                                               classid);
-               return;
-       }
-
-       g_slist_foreach(lookup_value->rules, __rstn_remove, NULL);
-}
-
-void stc_monitor_rstn_remove_by_connection(stc_connection_s *conn)
-{
-       GHashTable *rstns = stc_monitor_get_system_rstns();
-
-       if (!rstns)
-               return;
-
-       g_hash_table_foreach(rstns, __rstn_remove_by_connection, conn);
-}
-
-void stc_monitor_rstns_load(void)
-{
-       table_restrictions_foreach(__rstn_insert_cb, NULL);
-
-       /* __rstn_tree_printall(); */
-}
-
-GHashTable *stc_monitor_rstns_init(void)
-{
-       return g_hash_table_new_full(g_direct_hash, g_direct_equal,
-                                       NULL, __rstn_value_destroy);
-}
diff --git a/src/monitor/stc-monitor.c b/src/monitor/stc-monitor.c
deleted file mode 100644 (file)
index 0bfc5a5..0000000
+++ /dev/null
@@ -1,575 +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.
- */
-
-#include <linux/netlink.h>
-#include <vconf.h>
-#include <vconf-keys.h>
-
-#include "stc-connection.h"
-#include "helper-nl.h"
-#include "helper-nfacct-rule.h"
-#include "helper-net-cls.h"
-#include "helper-cgroup.h"
-#include "helper-iptables.h"
-#include "counter.h"
-#include "table-statistics.h"
-#include "table-counters.h"
-#include "stc-monitor.h"
-#include "stc-manager-plugin-exception.h"
-#include "stc-manager-plugin-tether.h"
-
-static stc_system_s *g_system = NULL;
-
-static int __vconf_get_int(const char *key, int *value)
-{
-       int ret = 0;
-
-       ret = vconf_get_int(key, value);
-       if (ret != VCONF_OK) {
-               STC_LOGE("Failed to get vconfkey [%s] value", key);
-               return -1;
-       }
-
-       return 0;
-}
-
-static stc_error_e __close_contr_sock(stc_system_s *system)
-{
-       ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
-
-       /* close netlink socket for updating kernel counters */
-       if (system->contr_sock != -1) {
-               close(system->contr_sock);
-               system->contr_sock = -1;
-       }
-
-       if (system->contr_gsource_id != 0) {
-               g_source_remove(system->contr_gsource_id);
-               system->contr_gsource_id = 0;
-       }
-
-       return STC_ERROR_NONE;
-}
-
-static gboolean __process_contr_reply(GIOChannel *source,
-                                     GIOCondition condition,
-                                     gpointer user_data);
-
-static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
-{
-       GIOChannel *gio = NULL;
-       ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
-
-       /* close netlink socket for updating kernel counters */
-       if (system->contr_sock != -1) {
-               close(system->contr_sock);
-               system->contr_sock = -1;
-       }
-
-       if (system->contr_gsource_id != 0) {
-               g_source_remove(system->contr_gsource_id);
-               system->contr_gsource_id = 0;
-       }
-
-       /* create netlink socket for updating kernel counters */
-       system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
-       if (system->contr_sock < 0) {
-               STC_LOGE("failed to open socket");
-               FREE(system);
-               return STC_ERROR_FAIL;
-       }
-
-       gio = g_io_channel_unix_new(system->contr_sock);
-       system->contr_gsource_id =
-               g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
-                              (GIOFunc) __process_contr_reply,
-                              NULL);
-       g_io_channel_unref(gio);
-
-       return STC_ERROR_NONE;
-}
-
-static void __check_rstn_limit_exceeded(gpointer data,
-                               gpointer user_data)
-{
-       stc_rstn_data_s *rstn_data = (stc_rstn_data_s *)data;
-       int32_t *limit_exceeded = (int32_t *)user_data;
-
-       if (rstn_data->limit_exceeded != 0)
-               *limit_exceeded = rstn_data->limit_exceeded;
-}
-
-static void __fill_nfacct_result(char *cnt_name, int64_t bytes,
-                               struct counter_arg *carg)
-{
-       stc_monitor_rstn_reset_time_counters_if_required();
-
-       struct nfacct_rule counter = {
-               .carg = carg,
-               .name = {0},
-               .ifname = {0},
-               0
-       };
-
-       classid_bytes_context_s context = {
-               .counter = &counter,
-               .bytes = bytes,
-               .data_limit_exceeded = FALSE,
-       };
-
-       if (!recreate_counter_by_name(cnt_name, &counter)) {
-               STC_LOGE("Can't parse counter name %s", cnt_name);
-               return;
-       }
-
-       if (STC_DEBUG_LOG)
-               STC_LOGI("classid[\033[1;36m%u\033[0;m] iftype[%u] "
-                       "iotype[%d] intend[%d] ifname[%s] bytes[%lld]",
-                       context.counter->classid, context.counter->iftype,
-                       context.counter->iotype, context.counter->intend,
-                       context.counter->ifname, context.bytes);
-
-       if (context.counter->intend == NFACCT_COUNTER ||
-               context.counter->intend == NFACCT_TETH_COUNTER) {
-               if (g_system->apps) {
-                       stc_app_value_s *lookup_app;
-                       stc_rstn_value_s *lookup_rstn;
-
-                       stc_monitor_app_update_iface_counter(&context);
-
-                       lookup_app = g_hash_table_lookup(g_system->apps,
-                                               GUINT_TO_POINTER(context.counter->classid));
-                       if (lookup_app)
-                               stc_monitor_app_update_counter(lookup_app, &context);
-
-                       lookup_rstn = g_hash_table_lookup(g_system->rstns,
-                                               GUINT_TO_POINTER(context.counter->classid));
-                       if (lookup_rstn) {
-                               int32_t limit_exceeded = 0;
-                               g_slist_foreach(lookup_rstn->rules,
-                                       __check_rstn_limit_exceeded, &limit_exceeded);
-
-                               if (limit_exceeded != 0)
-                                       return;
-                       }
-               }
-
-               if (g_system->rstns) {
-                       stc_rstn_value_s *lookup_value;
-                       uint32_t classid = context.counter->classid;
-
-                       stc_monitor_rstn_update_iface_counter(&context);
-                       context.counter->classid = classid;
-
-                       lookup_value = g_hash_table_lookup(g_system->rstns,
-                                                       GUINT_TO_POINTER(classid));
-                       if (lookup_value) {
-                               g_slist_foreach(lookup_value->rules,
-                                       stc_monitor_rstn_update_counter,
-                                       &context);
-                       }
-               }
-       }
-}
-
-static int __fill_counters(struct rtattr *attr_list[__NFACCT_MAX],
-                          void *user_data)
-{
-       struct counter_arg *carg = user_data;
-       char *cnt_name = (char *)RTA_DATA(attr_list[NFACCT_NAME]);
-       if (carg->initiate) {
-               /**
-                * TODO: this will be used when daemon starts to update existing
-                * counter data if present.
-                *
-                populate_counters(cnt_name, carg);
-                */
-       } else {
-               int64_t *bytes_p =
-                       (int64_t *)RTA_DATA(attr_list[NFACCT_BYTES]);
-               int bytes = be64toh(*bytes_p);
-               if (bytes) {
-                       ++carg->serialized_counters;
-                       __fill_nfacct_result(cnt_name, bytes, carg);
-               }
-       }
-
-       return 0;
-}
-
-static int __post_fill_counters(void *user_data)
-{
-       struct counter_arg *carg = user_data;
-
-       if (carg->initiate)
-               carg->initiate = 0;
-
-       return 0;
-}
-
-static void __process_network_counter(struct genl *ans,
-                                     struct counter_arg *carg)
-{
-       struct netlink_serialization_params ser_params = {
-               .carg = carg,
-               .ans = ans,
-               .eval_attr = __fill_counters,
-               .post_eval_attr = __post_fill_counters,
-       };
-
-       netlink_serialization_command *netlink =
-               netlink_create_command(&ser_params);
-       if (!netlink) {
-               STC_LOGE("Can not create command");
-               return;
-       }
-
-       netlink->deserialize_answer(&(netlink->params));
-}
-
-static gboolean __process_contr_reply(GIOChannel *source,
-                                     GIOCondition condition,
-                                     gpointer user_data)
-{
-       int sock = g_io_channel_unix_get_fd(source);
-       struct genl *ans;
-       int ret;
-       stc_s *stc = stc_get_manager();
-
-#ifdef TIZEN_GTESTS
-       void __gcov_flush(void);
-       __gcov_flush();
-#endif
-
-       if ((condition & G_IO_ERR) || (condition & G_IO_HUP) ||
-           (condition & G_IO_NVAL)) {
-               /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
-
-               STC_LOGE("Counter socket received G_IO event, closing socket."
-                        "G_IO_ERR [%u], G_IO_HUP [%u], G_IO_NVAL [%u]",
-                        (condition & G_IO_ERR), (condition & G_IO_HUP),
-                        (condition & G_IO_NVAL));
-               __close_and_reopen_contr_sock(g_system);
-               return FALSE;
-       }
-
-       ans = MALLOC0(struct genl, 1);
-       if (ans == NULL) {
-               STC_LOGE("Failed allocate memory to genl reply message");
-               return TRUE;
-       }
-
-       if (stc == NULL) {
-               STC_LOGE("Can't get stc data");
-               goto out;
-       }
-
-       ret = read_netlink(sock, ans, sizeof(struct genl));
-
-       if (ret == 0)
-               goto out;
-
-       stc->carg->ans_len = ret;
-       stc->carg->last_run_time = time(NULL);
-
-       __process_network_counter(ans, stc->carg);
-
-       g_idle_add(stc_monitor_app_flush_stats_to_db, NULL);
-       g_idle_add(stc_monitor_rstn_flush_contr_to_db, NULL);
-out:
-
-       FREE(ans);
-       return TRUE;
-}
-
-static gboolean __update_contr_cb(void *user_data)
-{
-       /* Here we just sent command, answer we receive in another callback */
-       stc_s *stc = stc_get_manager();
-       ret_value_msg_if(stc == NULL, STC_ERROR_FAIL, "Can't get stc data");
-       if (!stc->carg) {
-               stc->carg = MALLOC0(counter_arg_s, 1);
-               if (stc->carg == NULL)
-                       return TRUE;  /* we need to continue the timer */
-
-               stc->carg->sock = g_system->contr_sock;
-       }
-
-#ifdef TIZEN_GTESTS
-       void __gcov_flush(void);
-       __gcov_flush();
-#endif
-
-       /* STC_LOGD("Get all counters"); */
-       nfacct_send_get_all(stc->carg);
-
-       /* we need to continue the timer */
-       return TRUE;
-}
-
-static void __fill_exceptions_list(void)
-{
-       stc_plugin_fill_exception_list();
-}
-
-stc_error_e stc_monitor_init(void)
-{
-       stc_system_s *system = MALLOC0(stc_system_s, 1);
-       GIOChannel *gio = NULL;
-
-       ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY,
-                               "stc_system_s malloc fail!");
-
-       /* initializing current classid */
-       init_current_classid();
-
-       /* initializing cgroups */
-       cgroup_init();
-
-       /* creating monitored application tree */
-       system->apps = stc_monitor_apps_init();
-       system->rstns = stc_monitor_rstns_init();
-
-       /* create netlink socket for updating kernel counters */
-       system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
-       if (system->contr_sock < 0) {
-               STC_LOGE("failed to open socket");
-               FREE(system);
-               return STC_ERROR_FAIL;
-       }
-
-       gio = g_io_channel_unix_new(system->contr_sock);
-       system->contr_gsource_id =
-               g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
-                              (GIOFunc) __process_contr_reply,
-                              NULL);
-       g_io_channel_unref(gio);
-
-       g_system = system;
-
-       stc_monitor_app_add_by_iface(STC_TOTAL_DATACALL);
-       stc_monitor_app_add_by_iface(STC_TOTAL_WIFI);
-       stc_monitor_app_add_by_iface(STC_TOTAL_BLUETOOTH);
-       stc_monitor_app_add_by_iface(STC_TOTAL_IPV4);
-       stc_monitor_app_add_by_iface(STC_TOTAL_IPV6);
-       /* stc_monitor_app_add_by_iface(STC_TOTAL_TETHERING); */
-
-       __update_contr_cb(NULL);
-
-       /* registering periodic kernel counters update callback */
-       g_system->contr_timer_id = g_timeout_add_seconds(CONTR_TIMER_INTERVAL,
-                                                        __update_contr_cb,
-                                                        NULL);
-       if (g_system->contr_timer_id == 0) {
-               STC_LOGE("Failed to register kernel counters update timer");
-               __close_contr_sock(g_system);
-               return STC_ERROR_FAIL;
-       }
-
-       __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
-                       (int *)&g_system->background_state);
-
-       __fill_exceptions_list();
-       stc_monitor_rstns_load();
-
-       return STC_ERROR_NONE;
-}
-
-stc_error_e stc_monitor_deinit(void)
-{
-       ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
-
-       /* close netlink socket for updating kernel counters */
-       __close_contr_sock(g_system);
-
-       /* remove kernel counters update timer */
-       if (g_system->contr_timer_id > 0) {
-               g_source_remove(g_system->contr_timer_id);
-               g_system->contr_timer_id = 0;
-       }
-
-       /* destroy monitored application tree */
-       g_hash_table_destroy(g_system->apps);
-       g_system->apps = NULL;
-
-       /* destroy restriction rules tree */
-       g_hash_table_destroy(g_system->rstns);
-       g_system->rstns = NULL;
-
-       FREE(g_system);
-
-       return STC_ERROR_NONE;
-}
-
-GHashTable *stc_monitor_get_system_apps(void)
-{
-       ret_value_msg_if(g_system == NULL, NULL,
-                               "stc monitor not initialized!");
-
-       ret_value_msg_if(g_system->apps == NULL, NULL,
-                               "apps is null!");
-
-       return g_system->apps;
-}
-
-GHashTable *stc_monitor_get_system_rstns(void)
-{
-       ret_value_msg_if(g_system == NULL, NULL,
-                               "stc monitor not initialized!");
-
-       ret_value_msg_if(g_system->rstns == NULL, NULL,
-                               "rstns is null!");
-
-       return g_system->rstns;
-}
-
-int stc_monitor_get_contr_sock(void)
-{
-       ret_value_msg_if(g_system == NULL, 0,
-                               "stc monitor not initialized!");
-
-       return g_system->contr_sock;
-}
-
-time_t stc_monitor_get_last_month_ts(void)
-{
-       ret_value_msg_if(g_system == NULL, 0,
-                               "stc monitor not initialized!");
-
-       return g_system->last_month_ts;
-}
-
-void stc_monitor_set_last_month_ts(time_t time)
-{
-       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
-
-       g_system->last_month_ts = time;
-}
-
-time_t stc_monitor_get_last_week_ts(void)
-{
-       ret_value_msg_if(g_system == NULL, 0,
-                               "stc monitor not initialized!");
-
-       return g_system->last_week_ts;
-}
-
-void stc_monitor_set_last_week_ts(time_t time)
-{
-       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
-
-       g_system->last_week_ts = time;
-}
-
-time_t stc_monitor_get_last_day_ts(void)
-{
-       ret_value_msg_if(g_system == NULL, 0,
-                               "stc monitor not initialized!");
-
-       return g_system->last_day_ts;
-}
-
-void stc_monitor_set_last_day_ts(time_t time)
-{
-       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
-
-       g_system->last_day_ts = time;
-}
-
-void stc_monitor_set_rstns_updated(gboolean value)
-{
-       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
-
-       g_system->rstns_updated = value;
-}
-
-gboolean stc_monitor_get_rstns_updated(void)
-{
-       ret_value_msg_if(g_system == NULL, FALSE,
-                               "stc monitor not initialized!");
-
-       return g_system->rstns_updated;
-}
-
-void stc_monitor_set_apps_updated(gboolean value)
-{
-       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
-
-       g_system->apps_updated = value;
-}
-
-gboolean stc_monitor_get_apps_updated(void)
-{
-       ret_value_msg_if(g_system == NULL, FALSE,
-                               "stc monitor not initialized!");
-
-       return g_system->apps_updated;
-}
-
-void stc_monitor_set_background_state(gboolean value)
-{
-       ret_msg_if(g_system == NULL, "stc monitor not initialized!");
-
-       g_system->background_state = value;
-}
-
-gboolean stc_monitor_get_background_state(void)
-{
-       ret_value_msg_if(g_system == NULL, FALSE,
-                               "stc monitor not initialized!");
-
-       return g_system->background_state;
-}
-
-void stc_monitor_update_by_connection(void *data)
-{
-       stc_connection_s *connection = (stc_connection_s *)data;
-
-       if (connection != NULL && connection->path != NULL) {
-               stc_monitor_app_remove_by_connection(connection);
-               stc_monitor_rstn_remove_by_connection(connection);
-
-               iptables_flush_chains();
-
-               stc_monitor_app_add_by_connection(connection);
-               stc_monitor_rstn_add_by_connection(connection);
-       }
-}
-
-void stc_monitor_add_by_connection(void *data)
-{
-       stc_connection_s *connection = (stc_connection_s *)data;
-
-       if (connection != NULL && connection->path != NULL) {
-               stc_monitor_app_add_by_connection(connection);
-               stc_monitor_rstn_add_by_connection(connection);
-       }
-}
-
-void stc_monitor_remove_by_connection(void *data)
-{
-       stc_connection_s *connection = (stc_connection_s *)data;
-
-       if (connection != NULL && connection->path != NULL) {
-               stc_monitor_app_remove_by_connection(connection);
-               stc_monitor_rstn_remove_by_connection(connection);
-       }
-}
-
-API stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline)
-{
-       return stc_plugin_check_exception_by_cmdline(cmdline);
-}
diff --git a/src/monitor/stc-time.c b/src/monitor/stc-time.c
deleted file mode 100644 (file)
index e0f86e0..0000000
+++ /dev/null
@@ -1,107 +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.
- */
-
-#include <time.h>
-#include <stdbool.h>
-
-#define SEC_IN_DAY 24 * 60 * 60
-#define SEC_IN_WEEK 7 * SEC_IN_DAY
-
-time_t stc_time_get_day_start(time_t now)
-{
-       struct tm curr;
-       struct tm *res;
-
-       res = localtime_r(&now, &curr);
-
-       curr.tm_sec = 0;
-       curr.tm_min = 0;
-       curr.tm_hour = 0;
-
-       return mktime(&curr);
-}
-
-time_t stc_time_get_week_start(time_t now)
-{
-       struct tm curr;
-       struct tm *res;
-       int days;
-
-       res = localtime_r(&now, &curr);
-
-       curr.tm_sec = 0;
-       curr.tm_min = 0;
-       curr.tm_hour = 0;
-
-       if (curr.tm_wday > 1)
-               days = curr.tm_wday - 1;
-       else
-               days = 1 - curr.tm_wday;
-
-       return (mktime(&curr) - (days * SEC_IN_DAY));
-}
-
-time_t stc_time_get_month_start(time_t now, int month_start_date)
-{
-       struct tm curr;
-       struct tm *res;
-       bool is_leap_year;
-
-       res = localtime_r(&now, &curr);
-
-       curr.tm_sec = 0;
-       curr.tm_min = 0;
-       curr.tm_hour = 0;
-
-       if (curr.tm_mday < month_start_date) {
-               curr.tm_mon--;
-               if (curr.tm_mon < 0) {
-                       curr.tm_mon = 11;
-                       curr.tm_year--;
-               }
-       }
-
-       is_leap_year = ((curr.tm_year + 1900) % 4 ? 0 : 1);
-       curr.tm_mday = month_start_date;
-
-       switch (month_start_date) {
-       case 29:
-       case 30:
-               if (curr.tm_mon == 1 && !is_leap_year)
-                       curr.tm_mday = 28;
-
-               else if (curr.tm_mon == 1 && is_leap_year)
-                       curr.tm_mday = 29;
-
-               break;
-       case 31:
-               if (curr.tm_mon == 1 && !is_leap_year)
-                       curr.tm_mday = 28;
-
-               else if (curr.tm_mon == 1 && is_leap_year)
-                       curr.tm_mday = 29;
-
-               else if (curr.tm_mon == 3 || curr.tm_mon == 5 ||
-                        curr.tm_mon == 8 || curr.tm_mon == 10)
-                       curr.tm_mday = 30;
-
-               break;
-       default:
-               ;//Do Nothing
-       };
-
-       return mktime(&curr);
-}
index f1adadb6ea5afa89dd81db702a2c987fde5ce3b7..64e7abb1681d051abf1221294887f8275d671880 100755 (executable)
@@ -1216,6 +1216,8 @@ gboolean __validate_fw_rule(firewall_rule_s *rule)
 
 void stc_firewall_init(void)
 {
+       __STC_LOG_FUNC_ENTER__;
+
        int ret = STC_ERROR_NONE;
 
        g_firewalls = g_hash_table_new_full(g_str_hash,
@@ -1230,21 +1232,31 @@ void stc_firewall_init(void)
 
        table_firewall_foreach_chain(__fw_table_chain_info_cb, NULL);
        table_firewall_foreach_rule(__fw_table_rule_info_cb, NULL);
+
+       __STC_LOG_FUNC_EXIT__;
 }
 
-void stc_firewall_update(void)
+API void stc_firewall_update(void)
 {
+       __STC_LOG_FUNC_ENTER__;
+
        __fw_chain_foreach(__fw_foreach_to_add_chain, NULL);
        __fw_chain_foreach(__fw_foreach_to_set_rule_to_chain, NULL);
        __fw_chain_foreach(__fw_foreach_to_set_chain, NULL);
+
+       __STC_LOG_FUNC_EXIT__;
 }
 
 void stc_firewall_deinit(void)
 {
+       __STC_LOG_FUNC_ENTER__;
+
        if (g_firewalls) {
                g_hash_table_destroy(g_firewalls);
                g_firewalls = NULL;
        }
+
+       __STC_LOG_FUNC_EXIT__;
 }
 
 gboolean handle_firewall_lock(StcFirewall *object,
index ef74b176cf924454eaeea1e7ff6702223ed463d1..22d0375bbc914d3e8f272a9d5cc974b088597b15 100755 (executable)
 #include "stc-restriction.h"
 #include "stc-firewall.h"
 #include "stc-pcap.h"
-#include "stc-connection.h"
 #include "stc-manager-util.h"
 #include "stc-manager-plugin-appstatus.h"
 #include "stc-manager-plugin-procfs.h"
+#include "stc-manager-plugin-monitor.h"
 #include "helper-iptables.h"
 
 #define MANAGER_DBUS_ERROR_NAME "net.stc.manager.Error.Failed"
@@ -351,12 +351,11 @@ static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection,
                                                    stc->connection);
 
        iptables_init();
-#ifndef TIZEN_TV_EXT
-       stc_connection_monitor_init(stc);
+       stc_firewall_update();
+       stc_plugin_monitor_init_connection(stc);
 
        stc_plugin_appstatus_register_state_changed_cb(stc,
                        stc_plugin_procfs_app_status_changed, NULL);
-#endif
 
        __STC_LOG_FUNC_EXIT__;
 }
@@ -400,7 +399,7 @@ void stc_manager_gdbus_deinit(gpointer stc_data)
        stc_s *stc = (stc_s *)stc_data;
 
        stc_plugin_appstatus_deregister_state_changed_cb(stc);
-       stc_connection_monitor_deinit(stc);
+       stc_plugin_monitor_deinit_connection(stc);
 
        g_bus_unown_name(stc->gdbus_owner_id);
 
@@ -412,7 +411,7 @@ void stc_manager_gdbus_deinit(gpointer stc_data)
        __STC_LOG_FUNC_EXIT__;
 }
 
-GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
+API GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
                                      const char *dest, const char *path,
                                      const char *interface_name,
                                      const char *method, GVariant *params)
@@ -452,7 +451,7 @@ GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
        return reply;
 }
 
-guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection,
+API guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection,
                                         const gchar *sender,
                                         const gchar *interface_name,
                                         const gchar *member,
@@ -480,7 +479,7 @@ guint stc_manager_gdbus_subscribe_signal(GDBusConnection *connection,
                                                  user_data_free_func);
 }
 
-void stc_manager_gdbus_unsubscribe_signal(GDBusConnection *connection,
+API void stc_manager_gdbus_unsubscribe_signal(GDBusConnection *connection,
                                          guint subscription_id)
 {
        if (connection == NULL) {
@@ -513,7 +512,7 @@ void stc_manager_gdbus_dict_foreach(GVariantIter *iter, dbus_dict_cb cb,
        __STC_LOG_FUNC_EXIT__;
 }
 
-gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
+API gboolean stc_manager_dbus_emit_signal(GDBusConnection *connection,
                                      const gchar *object_path,
                                      const gchar *interface_name,
                                      const gchar *signal_name,
old mode 100644 (file)
new mode 100755 (executable)
index cab52ad..a79bc93
@@ -64,24 +64,21 @@ int stc_plugin_appstatus_deinit(void)
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_appstatus_send_message(const char *content,
+API int stc_plugin_appstatus_send_message(const char *content,
                const char *type, const char *app_id, const char *iftype, const char *limit)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->send_message_to_net_popup(content,
                                                type, app_id, iftype, limit);
 }
@@ -89,41 +86,35 @@ int stc_plugin_appstatus_send_message(const char *content,
 int stc_plugin_appstatus_register_state_changed_cb(stc_s *stc,
                stc_plugin_app_state_changed_cb cb, void *data)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->register_state_changed_cb(stc, cb, data);
 }
 
 int stc_plugin_appstatus_deregister_state_changed_cb(stc_s *stc)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->deregister_state_changed_cb(stc);
 }
 //LCOV_EXCL_STOP
old mode 100644 (file)
new mode 100755 (executable)
index bc0078d..ad1c092
@@ -24,7 +24,7 @@ static void *handle_plugin;
 static stc_plugin_exception_s *stc_plugin;
 
 //LCOV_EXCL_START
-int stc_plugin_exception_init(void)
+API int stc_plugin_exception_init(void)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -50,7 +50,7 @@ int stc_plugin_exception_init(void)
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_exception_deinit(void)
+API int stc_plugin_exception_deinit(void)
 {
        __STC_LOG_FUNC_ENTER__;
 
@@ -67,47 +67,41 @@ int stc_plugin_exception_deinit(void)
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_fill_exception_list(void)
+API int stc_plugin_fill_exception_list(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->fill_exception_list();
 }
 
-int stc_plugin_update_exception_list(void)
+API int stc_plugin_update_exception_list(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->update_exception_list();
 }
 
-int stc_plugin_check_exception_by_cmdline(char *cmdline)
+API int stc_plugin_check_exception_by_cmdline(char *cmdline)
 {
        if (!stc_plugin_enabled)
                return STC_ERROR_UNINITIALIZED;
diff --git a/src/stc-manager-plugin-monitor.c b/src/stc-manager-plugin-monitor.c
new file mode 100755 (executable)
index 0000000..209b1a1
--- /dev/null
@@ -0,0 +1,259 @@
+/*
+ * 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.
+ */
+
+#include <dlfcn.h>
+
+#include "stc-manager.h"
+#include "stc-manager-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(void)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       handle_plugin = dlopen(STC_PLUGIN_MONITOR_FILEPATH, RTLD_NOW);
+       if (!handle_plugin) {
+               STC_LOGE("Can't load %s: %s", STC_PLUGIN_MONITOR_FILEPATH, dlerror());
+               __STC_LOG_FUNC_EXIT__;
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       stc_plugin = dlsym(handle_plugin, "stc_plugin_monitor");
+       if (!stc_plugin) {
+               STC_LOGE("Can't load symbol: %s", dlerror());
+               dlclose(handle_plugin);
+               __STC_LOG_FUNC_EXIT__;
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       stc_plugin->initialize_plugin();
+       stc_plugin_enabled = TRUE;
+
+       __STC_LOG_FUNC_EXIT__;
+       return STC_ERROR_NONE;
+}
+
+API int stc_plugin_monitor_deinit(void)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       if (!stc_plugin_enabled)
+               return STC_ERROR_UNINITIALIZED;
+
+       stc_plugin->deinitialize_plugin();
+       stc_plugin_enabled = FALSE;
+       dlclose(handle_plugin);
+
+       __STC_LOG_FUNC_EXIT__;
+       return STC_ERROR_NONE;
+}
+
+API int stc_plugin_monitor_add_app(uint32_t classid,
+                               const char *app_id,
+                               const char *pkg_id,
+                               const stc_app_value_s value)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->add_application(classid, app_id, pkg_id, value);
+}
+
+API int stc_plugin_monitor_remove_app(uint32_t classid,
+                               const char *app_id)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->remove_application(classid, app_id);
+}
+
+API int stc_plugin_monitor_lookup_app(uint32_t classid)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->lookup_application(classid);
+}
+
+API int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->add_restriction(info);
+}
+
+API int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->remove_restriction(info);
+}
+
+API int stc_plugin_monitor_init_connection(stc_s *stc)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->init_connection(stc);
+}
+
+API int stc_plugin_monitor_deinit_connection(stc_s *stc)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->deinit_connection(stc);
+}
+
+API int stc_plugin_monitor_add_proc(uint32_t classid,
+                       const char *app_id, const stc_proc_value_s value)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->add_process(classid, app_id, value);
+}
+
+API int stc_plugin_monitor_remove_proc(uint32_t classid, pid_t pid)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->remove_process(classid, pid);
+}
+
+API int stc_plugin_monitor_move_proc(uint32_t from, uint32_t to)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->move_process(from, to);
+}
+
+API int stc_plugin_monitor_update_proc_ground(uint32_t classid,
+                       const char *app_id, const stc_proc_value_s value)
+{
+       if (!stc_plugin_enabled) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       if (!stc_plugin) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
+               return STC_ERROR_UNINITIALIZED;
+       }
+
+       return stc_plugin->update_process_ground(classid, app_id, value);
+}
+//LCOV_EXCL_STOP
old mode 100644 (file)
new mode 100755 (executable)
index c9432a2..395031c
@@ -69,103 +69,88 @@ int stc_plugin_pcap_deinit(void)
 
 int stc_plugin_pcap_lookup_dev(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->lookup_dev();
 }
 
 int stc_plugin_pcap_lookup_net(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->lookup_net();
 }
 
 int stc_plugin_pcap_find_alldevs(void)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->find_alldevs();
 }
 
 int stc_plugin_pcap_register_loop_pcap(const char *ifname,
                        int group)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->register_loop_pcap(ifname, group);
 }
 
 int stc_plugin_pcap_unregister_loop_pcap(const char *ifname,
                        int group)
 {
-       __STC_LOG_FUNC_ENTER__;
-
        if (!stc_plugin_enabled) {
-               STC_LOGE("Plugin wasn't enabled");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't enabled");
                return STC_ERROR_UNINITIALIZED;
        }
 
        if (!stc_plugin) {
-               STC_LOGE("Plugin wasn't loaded");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("Plugin wasn't loaded");
                return STC_ERROR_UNINITIALIZED;
        }
 
-       __STC_LOG_FUNC_EXIT__;
        return stc_plugin->unregister_loop_pcap(ifname, group);
 }
 //LCOV_EXCL_STOP
old mode 100644 (file)
new mode 100755 (executable)
index afb170d..4c5e528
@@ -66,15 +66,14 @@ int stc_plugin_tether_deinit(void)
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_tether_get_station_ip(const char *mac, char **ipaddr)
+API int stc_plugin_tether_get_station_ip(const char *mac, char **ipaddr)
 {
-       __STC_LOG_FUNC_ENTER__;
        char ip[INET_ADDRSTRLEN+1];
 
        if (!stc_tether_plugin_enabled ||
-                       mac == NULL || ipaddr == NULL) {
-               STC_LOGE("invalid args");
-               __STC_LOG_FUNC_EXIT__;
+               mac == NULL || ipaddr == NULL) {
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("invalid args");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
@@ -86,18 +85,17 @@ int stc_plugin_tether_get_station_ip(const char *mac, char **ipaddr)
        *ipaddr = g_strdup(ip);
        STC_LOGI("station ip(%s)", *ipaddr);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_tether_get_station_by_classid(const int classid, char **mac)
+API int stc_plugin_tether_get_station_by_classid(const int classid, char **mac)
 {
        __STC_LOG_FUNC_ENTER__;
        char mac_addr[STATION_MAC_STR_LEN+1];
 
        if (!stc_tether_plugin_enabled || mac == NULL) {
-               STC_LOGE("invalid args");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("invalid args");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
@@ -109,17 +107,16 @@ int stc_plugin_tether_get_station_by_classid(const int classid, char **mac)
        *mac = g_strdup(mac_addr);
        STC_LOGI("station mac(%s)", *mac);
 
-       __STC_LOG_FUNC_EXIT__;
        return STC_ERROR_NONE;
 }
 
-int stc_plugin_tether_set_station_classid(const char *mac, int classid)
+API int stc_plugin_tether_set_station_classid(const char *mac, int classid)
 {
        __STC_LOG_FUNC_ENTER__;
 
        if (!stc_tether_plugin_enabled || mac == NULL) {
-               STC_LOGE("invalid args");
-               __STC_LOG_FUNC_EXIT__;
+               if (STC_DEBUG_LOG)
+                       STC_LOGE("invalid args");
                return STC_ERROR_INVALID_PARAMETER;
        }
 
@@ -128,6 +125,6 @@ int stc_plugin_tether_set_station_classid(const char *mac, int classid)
 
        STC_LOGI("classid(%d) for station mac(%s) is set successfully",
                        classid, mac);
-       __STC_LOG_FUNC_EXIT__;
+
        return STC_ERROR_NONE;
 }
index ba9356da8e573fbe1475411b3427f0b6ecf4be90..11fa7bbf41f80028815d6e184bfff5a21efe5c7a 100755 (executable)
 #include "helper-nfacct-rule.h"
 #include "helper-iptables.h"
 #include "helper-inotify.h"
-#include "stc-monitor.h"
 #include "stc-firewall.h"
 #include "stc-manager-plugin-appstatus.h"
 #include "stc-manager-plugin-exception.h"
 #include "stc-manager-plugin-procfs.h"
 #include "stc-manager-plugin-tether.h"
 #include "stc-manager-plugin-pcap.h"
+#include "stc-manager-plugin-monitor.h"
 
 #define BUF_SIZE_FOR_ERR 100
 
@@ -75,7 +75,7 @@ static void __stc_manager_deinit(void)
                return;
        }
 
-       stc_monitor_deinit();
+       stc_plugin_monitor_deinit();
        stc_deinit_db_guard();
        stc_db_deinitialize();
 
@@ -118,9 +118,7 @@ static stc_s *__stc_manager_init(void)
        inotify_initialize();
        inotify_register(INFO_STORAGE_DIR, __stc_inotify_handler);
 
-#ifndef TIZEN_TV_EXT
        cgroup_set_release_agent(NET_CLS_SUBSYS, NET_RELEASE_AGENT);
-#endif
 
        err = stc_db_initialize();
        if (err != STC_ERROR_NONE) {
@@ -128,25 +126,16 @@ static stc_s *__stc_manager_init(void)
                return NULL; //LCOV_EXCL_LINE
        }
 
-#ifndef TIZEN_TV_EXT
        stc_plugin_appstatus_init();
        stc_plugin_exception_init();
        stc_plugin_procfs_init();
        stc_plugin_tether_init();
        stc_plugin_pcap_init();
-#endif
+       stc_plugin_monitor_init();
 
        stc_firewall_init();
 
-#ifndef TIZEN_TV_EXT
-       err = stc_monitor_init();
-       if (err != STC_ERROR_NONE) {
-               STC_LOGD("Failed to initialize stc manager"); //LCOV_EXCL_LINE
-               return NULL; //LCOV_EXCL_LINE
-       }
-
        stc_plugin_procfs_load_pid();
-#endif
 
        stc_manager_gdbus_init((gpointer)stc);
 
@@ -155,7 +144,7 @@ static stc_s *__stc_manager_init(void)
        return stc;
 }
 
-stc_s *stc_get_manager(void)
+API stc_s *stc_get_manager(void)
 {
        return g_stc;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 6b207a5..ffe1a85
@@ -18,7 +18,7 @@
 #include "table-restrictions.h"
 #include "stc-restriction.h"
 #include "stc-manager-gdbus.h"
-#include "stc-monitor.h"
+#include "stc-manager-plugin-monitor.h"
 
 #define RESTRICTION_DBUS_ERROR_NAME "net.stc.restriction.Error.Failed"
 
@@ -295,7 +295,7 @@ gboolean handle_restriction_set(StcRestriction *object,
                return TRUE;
        }
 
-       stc_monitor_rstn_add(&rule);
+       stc_plugin_monitor_add_rstn(&rule);
        STC_DBUS_REPLY_ERROR_NONE(invocation);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;
@@ -338,7 +338,7 @@ gboolean handle_restriction_unset(StcRestriction *object,
                return TRUE;
        }
 
-       stc_monitor_rstn_remove(&rule);
+       stc_plugin_monitor_remove_rstn(&rule);
        STC_DBUS_REPLY_ERROR_NONE(invocation);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;