From: hyunuktak Date: Thu, 29 Nov 2018 07:49:41 +0000 (+0900) Subject: Separate monitoring function plugin X-Git-Tag: accepted/tizen/unified/20181212.062514~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=f8e88a87a33763dbd5a58a29f8876b7254e6864d;p=platform%2Fcore%2Fconnectivity%2Fstc-manager.git Separate monitoring function plugin Change-Id: I9cab1ed4d30e78bd4489ea6a7f1083f7e5aa1326 Signed-off-by: hyunuktak --- diff --git a/include/stc-manager-plugin-monitor.h b/include/stc-manager-plugin-monitor.h new file mode 100755 index 0000000..3830608 --- /dev/null +++ b/include/stc-manager-plugin-monitor.h @@ -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__ */ diff --git a/include/stc-manager-util.h b/include/stc-manager-util.h index 4b2eb94..7440534 100755 --- a/include/stc-manager-util.h +++ b/include/stc-manager-util.h @@ -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) diff --git a/packaging/stc-manager.spec b/packaging/stc-manager.spec index b14ee3f..0d98483 100644 --- a/packaging/stc-manager.spec +++ b/packaging/stc-manager.spec @@ -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 diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt index 04c53b8..a56ee63 100644 --- a/plugin/CMakeLists.txt +++ b/plugin/CMakeLists.txt @@ -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) diff --git a/plugin/appstatus/stc-plugin-appstatus.c b/plugin/appstatus/stc-plugin-appstatus.c index 98fab81..5d5b653 100755 --- a/plugin/appstatus/stc-plugin-appstatus.c +++ b/plugin/appstatus/stc-plugin-appstatus.c @@ -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); diff --git a/plugin/exception/stc-plugin-exception.c b/plugin/exception/stc-plugin-exception.c index cdb47c4..ec4e2fd 100755 --- a/plugin/exception/stc-plugin-exception.c +++ b/plugin/exception/stc-plugin-exception.c @@ -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 index 0000000..c1658b1 --- /dev/null +++ b/plugin/monitor/CMakeLists.txt @@ -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/src/monitor/include/stc-monitor-app.h b/plugin/monitor/include/stc-plugin-monitor-app.h old mode 100644 new mode 100755 similarity index 83% rename from src/monitor/include/stc-monitor-app.h rename to plugin/monitor/include/stc-plugin-monitor-app.h index 3a312fb..cfd623f --- a/src/monitor/include/stc-monitor-app.h +++ b/plugin/monitor/include/stc-plugin-monitor-app.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __STC_MONITOR_APP_H__ -#define __STC_MONITOR_APP_H__ +#ifndef __STC_PLUGIN_MONITOR_APP_H__ +#define __STC_PLUGIN_MONITOR_APP_H__ #include #include "stc-error.h" #include "stc-manager.h" -#include "stc-monitor-context.h" -#include "stc-connection.h" +#include "stc-plugin-monitor-context.h" +#include "stc-plugin-monitor-connection.h" #define MAC_ADDRESS_LEN 18 #define SUBSCRIBERID_NONE "none_subid" @@ -39,40 +39,31 @@ typedef struct { 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, +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_add_by_iface(const char *app_id); +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); - -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__ */ +#endif /* __STC_PLUGIN_MONITOR_APP_H__ */ diff --git a/src/monitor/include/stc-connection.h b/plugin/monitor/include/stc-plugin-monitor-connection.h old mode 100644 new mode 100755 similarity index 86% rename from src/monitor/include/stc-connection.h rename to plugin/monitor/include/stc-plugin-monitor-connection.h index 85d27de..6454b2d --- a/src/monitor/include/stc-connection.h +++ b/plugin/monitor/include/stc-plugin-monitor-connection.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __STC_CONNECTION_H__ -#define __STC_CONNECTION_H__ +#ifndef __STC_PLUGIN_MONITOR_CONNECTION_H__ +#define __STC_PLUGIN_MONITOR_CONNECTION_H__ #include #include "stc-error.h" @@ -65,9 +65,11 @@ typedef struct { 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); + +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_CONNECTION_H__ */ +#endif /* __STC_PLUGIN_MONITOR_CONNECTION_H__ */ diff --git a/src/monitor/include/stc-monitor-context.h b/plugin/monitor/include/stc-plugin-monitor-context.h old mode 100644 new mode 100755 similarity index 92% rename from src/monitor/include/stc-monitor-context.h rename to plugin/monitor/include/stc-plugin-monitor-context.h index 82d15f7..b0d0075 --- a/src/monitor/include/stc-monitor-context.h +++ b/plugin/monitor/include/stc-plugin-monitor-context.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __STC_MONITOR_CONTEXT_H__ -#define __STC_MONITOR_CONTEXT_H__ +#ifndef __STC_PLUGIN_MONITOR_CONTEXT_H__ +#define __STC_PLUGIN_MONITOR_CONTEXT_H__ #include "stc-manager.h" @@ -52,4 +52,4 @@ typedef struct { int month_start_date; } stc_system_s; -#endif /* __STC_MONITOR_CONTEXT_H__ */ +#endif /* __STC_PLUGIN_MONITOR_CONTEXT_H__ */ diff --git a/src/monitor/include/stc-monitor-ipt.h b/plugin/monitor/include/stc-plugin-monitor-ipt.h old mode 100644 new mode 100755 similarity index 93% rename from src/monitor/include/stc-monitor-ipt.h rename to plugin/monitor/include/stc-plugin-monitor-ipt.h index ee38069..a104c10 --- a/src/monitor/include/stc-monitor-ipt.h +++ b/plugin/monitor/include/stc-plugin-monitor-ipt.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __STC_MONITOR_IPT_H__ -#define __STC_MONITOR_IPT_H__ +#ifndef __STC_PLUGIN_MONITOR_IPT_H__ +#define __STC_PLUGIN_MONITOR_IPT_H__ #include "helper-nfacct-rule.h" @@ -38,4 +38,4 @@ stc_error_e stc_monitor_tether_del_in(struct nfacct_rule *counter, stc_error_e stc_monitor_tether_del_out(struct nfacct_rule *counter, const gchar *ipaddr); -#endif /* __STC_MONITOR_IPT_H__ */ +#endif /* __STC_PLUGIN_MONITOR_IPT_H__ */ diff --git a/src/monitor/include/stc-monitor-proc.h b/plugin/monitor/include/stc-plugin-monitor-proc.h old mode 100644 new mode 100755 similarity index 71% rename from src/monitor/include/stc-monitor-proc.h rename to plugin/monitor/include/stc-plugin-monitor-proc.h index 602912b..22bb06a --- a/src/monitor/include/stc-monitor-proc.h +++ b/plugin/monitor/include/stc-plugin-monitor-proc.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __STC_MONITOR_PROC_H__ -#define __STC_MONITOR_PROC_H__ +#ifndef __STC_PLUGIN_MONITOR_PROC_H__ +#define __STC_PLUGIN_MONITOR_PROC_H__ #include @@ -33,18 +33,16 @@ typedef struct { gboolean entry_removed; } remove_pid_context_s; -stc_error_e stc_monitor_proc_update_ground(uint32_t classid, +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_monitor_proc_add(uint32_t classid, +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_monitor_proc_remove(uint32_t classid, - pid_t pid); +stc_error_e stc_plugin_monitor_proc_remove(uint32_t classid, pid_t pid); -stc_error_e stc_monitor_proc_move(uint32_t from, - uint32_t to); +stc_error_e stc_plugin_monitor_proc_move(uint32_t from, uint32_t to); -#endif /* __STC_MONITOR_PROC_H__ */ +#endif /* __STC_PLUGIN_MONITOR_PROC_H__ */ diff --git a/src/monitor/include/stc-monitor-rstn.h b/plugin/monitor/include/stc-plugin-monitor-rstn.h old mode 100644 new mode 100755 similarity index 87% rename from src/monitor/include/stc-monitor-rstn.h rename to plugin/monitor/include/stc-plugin-monitor-rstn.h index ecf404d..0c690c7 --- a/src/monitor/include/stc-monitor-rstn.h +++ b/plugin/monitor/include/stc-plugin-monitor-rstn.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef __STC_MONITOR_RSTN_H__ -#define __STC_MONITOR_RSTN_H__ +#ifndef __STC_PLUGIN_MONITOR_RSTN_H__ +#define __STC_PLUGIN_MONITOR_RSTN_H__ #include #include "stc-error.h" #include "stc-manager.h" -#include "stc-monitor-context.h" -#include "stc-connection.h" +#include "stc-plugin-monitor-context.h" +#include "stc-plugin-monitor-connection.h" #include "stc-restriction.h" #include "table-restrictions.h" @@ -81,33 +81,24 @@ typedef struct { int64_t daily_stat; } stc_rstn_cumulative_data_s; -void stc_monitor_rstn_reset_time_counters_if_required(void); +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); - -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__ */ +#endif /* __STC_PLUGIN_MONITOR_RSTN_H__ */ diff --git a/src/monitor/include/stc-time.h b/plugin/monitor/include/stc-plugin-monitor-time.h old mode 100644 new mode 100755 similarity index 86% rename from src/monitor/include/stc-time.h rename to plugin/monitor/include/stc-plugin-monitor-time.h index d331bce..0a7ca6f --- a/src/monitor/include/stc-time.h +++ b/plugin/monitor/include/stc-plugin-monitor-time.h @@ -14,11 +14,11 @@ * limitations under the License. */ -#ifndef __STC_MANAGER_TIME_H__ -#define __STC_MANAGER_TIME_H__ +#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_MANAGER_TIME_H__ */ +#endif /* __STC_PLUGIN_MANAGER_TIME_H__ */ diff --git a/src/monitor/include/stc-monitor.h b/plugin/monitor/include/stc-plugin-monitor.h old mode 100644 new mode 100755 similarity index 59% rename from src/monitor/include/stc-monitor.h rename to plugin/monitor/include/stc-plugin-monitor.h index 32404b0..35509c8 --- a/src/monitor/include/stc-monitor.h +++ b/plugin/monitor/include/stc-plugin-monitor.h @@ -14,17 +14,17 @@ * limitations under the License. */ -#ifndef __STC_MONITOR_H__ -#define __STC_MONITOR_H__ +#ifndef __STC_PLUGIN_MONITOR_H__ +#define __STC_PLUGIN_MONITOR_H__ #include #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 "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 */ @@ -38,52 +38,56 @@ #define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction" #endif -/** - * @brief initializes stc monitor module - */ -stc_error_e stc_monitor_init(void); +typedef struct { + int (*initialize_plugin) (void); + int (*deinitialize_plugin) (void); -/** - * @brief deinitializes stc monitor module - */ -stc_error_e stc_monitor_deinit(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); -GHashTable *stc_monitor_get_system_apps(void); + int (*add_restriction) (const table_restrictions_info *info); + int (*remove_restriction) (const table_restrictions_info *info); + int (*lookup_application) (uint32_t classid); -GHashTable *stc_monitor_get_system_rstns(void); + int (*init_connection) (stc_s *stc); + int (*deinit_connection) (stc_s *stc); -int stc_monitor_get_contr_sock(void); + 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); -time_t stc_monitor_get_last_month_ts(void); + int (*check_excn_by_cmdline) (char *cmdline); +} stc_plugin_monitor_s; -void stc_monitor_set_last_month_ts(time_t time); +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); -stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline); - -#endif /* __STC_MONITOR_H__ */ +#endif /* __STC_PLUGIN_MONITOR_H__ */ diff --git a/src/monitor/stc-monitor-app.c b/plugin/monitor/stc-plugin-monitor-app.c similarity index 97% rename from src/monitor/stc-monitor-app.c rename to plugin/monitor/stc-plugin-monitor-app.c index ceeb0b4..d7b3152 100755 --- a/src/monitor/stc-monitor-app.c +++ b/plugin/monitor/stc-plugin-monitor-app.c @@ -17,11 +17,11 @@ #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 "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" @@ -274,77 +274,7 @@ static void __app_update_counter(classid_bytes_context_s *context, } } -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, - ¤t_time); - - STC_LOGI("Flushed app stats to database"); - return G_SOURCE_REMOVE; -} - -API stc_error_e stc_monitor_app_add(uint32_t classid, +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) @@ -363,7 +293,7 @@ API stc_error_e stc_monitor_app_add(uint32_t classid, lookup_value = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (lookup_value) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + 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; @@ -371,7 +301,7 @@ API stc_error_e stc_monitor_app_add(uint32_t classid, app_value = MALLOC0(stc_app_value_s, 1); if (!app_value) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGE("Value allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -411,7 +341,7 @@ API stc_error_e stc_monitor_app_add(uint32_t classid, stc_monitor_rstn_add_for_app(classid); - if (STC_DEBUG_LOG && STC_STAT_LOG) { + 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); @@ -420,6 +350,137 @@ API stc_error_e stc_monitor_app_add(uint32_t 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, + ¤t_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; @@ -434,7 +495,7 @@ void stc_monitor_app_add_by_iface(const char *ifname) app_value.counter.in_bytes = 0; app_value.counter.out_bytes = 0; - stc_monitor_app_add(STC_UNKNOWN_CLASSID, ifname, ifname, app_value); + stc_plugin_monitor_app_add(STC_UNKNOWN_CLASSID, ifname, ifname, app_value); } void stc_monitor_app_add_monitor(gpointer key, @@ -557,47 +618,6 @@ void stc_monitor_app_add_accept(gpointer key, } } -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) { @@ -718,25 +738,6 @@ void stc_monitor_app_remove_accept(gpointer key, 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, diff --git a/src/monitor/stc-connection.c b/plugin/monitor/stc-plugin-monitor-connection.c old mode 100644 new mode 100755 similarity index 99% rename from src/monitor/stc-connection.c rename to plugin/monitor/stc-plugin-monitor-connection.c index fb16297..06c4c30 --- a/src/monitor/stc-connection.c +++ b/plugin/monitor/stc-plugin-monitor-connection.c @@ -17,10 +17,10 @@ #include #include -#include "stc-monitor.h" #include "stc-firewall.h" #include "stc-manager-gdbus.h" -#include "stc-connection.h" +#include "stc-plugin-monitor.h" +#include "stc-plugin-monitor-connection.h" /* connman service dbus details */ #define CONNMAN_SERVICE "net.connman" @@ -695,7 +695,7 @@ done: return; } -stc_error_e stc_connection_monitor_init(stc_s *stc) +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"); @@ -719,7 +719,7 @@ stc_error_e stc_connection_monitor_init(stc_s *stc) return STC_ERROR_NONE; } -stc_error_e stc_connection_monitor_deinit(stc_s *stc) +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"); diff --git a/src/monitor/stc-monitor-ipt.c b/plugin/monitor/stc-plugin-monitor-ipt.c old mode 100644 new mode 100755 similarity index 98% rename from src/monitor/stc-monitor-ipt.c rename to plugin/monitor/stc-plugin-monitor-ipt.c index 016ae04..c8fa882 --- a/src/monitor/stc-monitor-ipt.c +++ b/plugin/monitor/stc-plugin-monitor-ipt.c @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "stc-monitor-ipt.h" -#include "stc-monitor-context.h" +#include "stc-plugin-monitor-ipt.h" +#include "stc-plugin-monitor-context.h" static nfacct_rule_jump __get_jump_by_intend(struct nfacct_rule *counter) { diff --git a/src/monitor/stc-monitor-proc.c b/plugin/monitor/stc-plugin-monitor-proc.c similarity index 88% rename from src/monitor/stc-monitor-proc.c rename to plugin/monitor/stc-plugin-monitor-proc.c index be12dd1..12cfe65 100755 --- a/src/monitor/stc-monitor-proc.c +++ b/plugin/monitor/stc-plugin-monitor-proc.c @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "stc-monitor.h" -#include "stc-monitor-proc.h" -#include "stc-connection.h" +#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, @@ -42,7 +42,7 @@ static void __proc_remove_pid(gpointer key, gpointer value, if (!g_hash_table_remove(app_value->processes, GUINT_TO_POINTER(context->pid))) return; - if (STC_DEBUG_LOG && STC_STAT_LOG) { + 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); @@ -74,7 +74,7 @@ static void __proc_move_pid(gpointer key, gpointer value, 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, +API stc_error_e stc_plugin_monitor_proc_update_ground(uint32_t classid, const char *app_id, const stc_proc_value_s value) { @@ -91,7 +91,7 @@ API stc_error_e stc_monitor_proc_update_ground(uint32_t classid, app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (!app_lookup) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid); return STC_ERROR_NO_DATA; } @@ -99,7 +99,7 @@ API stc_error_e stc_monitor_proc_update_ground(uint32_t classid, proc_lookup = g_hash_table_lookup(app_lookup->processes, GUINT_TO_POINTER(value.pid)); if (!proc_lookup) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGD("Process not found [\033[1;33m%d\033[0;m]", value.pid); return STC_ERROR_NO_DATA; } @@ -112,7 +112,7 @@ API stc_error_e stc_monitor_proc_update_ground(uint32_t classid, return ret; } -API stc_error_e stc_monitor_proc_add(uint32_t classid, +API stc_error_e stc_plugin_monitor_proc_add(uint32_t classid, const char *app_id, const stc_proc_value_s value) { @@ -130,7 +130,7 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, app_lookup = g_hash_table_lookup(apps, GUINT_TO_POINTER(classid)); if (!app_lookup) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", classid); return STC_ERROR_NO_DATA; } @@ -138,14 +138,14 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, proc_lookup = g_hash_table_lookup(app_lookup->processes, GUINT_TO_POINTER(value.pid)); if (proc_lookup) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + 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_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGE("Value allocation failed"); return STC_ERROR_OUT_OF_MEMORY; } @@ -160,7 +160,7 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, /* add pid to application cgroup */ place_pids_to_net_cgroup(proc_value->pid, app_id); - if (STC_DEBUG_LOG && STC_STAT_LOG) { + 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); @@ -169,8 +169,7 @@ API stc_error_e stc_monitor_proc_add(uint32_t classid, return ret; } -API stc_error_e stc_monitor_proc_remove(uint32_t classid, - pid_t pid) +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; @@ -193,21 +192,21 @@ API stc_error_e stc_monitor_proc_remove(uint32_t classid, app_lookup = context.app_value; if (!app_lookup) { - if (STC_DEBUG_LOG && STC_STAT_LOG) + 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_DEBUG_LOG && STC_STAT_LOG) + 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_DEBUG_LOG && STC_STAT_LOG) { + 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); @@ -235,7 +234,7 @@ API stc_error_e stc_monitor_proc_remove(uint32_t classid, g_hash_table_remove(apps, GUINT_TO_POINTER(classid)); - if (STC_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGD("\033[1;31mApplication removed\033[0;m " "[\033[1;36m%d\033[0;m]", classid); } @@ -243,8 +242,7 @@ API stc_error_e stc_monitor_proc_remove(uint32_t classid, return ret; } -API stc_error_e stc_monitor_proc_move(uint32_t from, - uint32_t to) +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; @@ -259,14 +257,14 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, 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) + 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_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGD("Application not found [\033[1;36m%d\033[0;m]", to); return STC_ERROR_NO_DATA; } @@ -274,7 +272,7 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, g_hash_table_foreach(from_lookup->processes, __proc_move_pid, to_lookup); - if (STC_DEBUG_LOG && STC_STAT_LOG) { + 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]", @@ -283,7 +281,7 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, g_hash_table_remove_all(from_lookup->processes); - if (STC_DEBUG_LOG && STC_STAT_LOG) { + 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); @@ -303,7 +301,7 @@ API stc_error_e stc_monitor_proc_move(uint32_t from, g_hash_table_remove(apps, GUINT_TO_POINTER(from)); - if (STC_DEBUG_LOG && STC_STAT_LOG) + if (STC_STAT_LOG) STC_LOGD("\033[1;31mApplication removed\033[0;m " "[\033[1;36m%d\033[0;m]", from); } diff --git a/src/monitor/stc-monitor-rstn.c b/plugin/monitor/stc-plugin-monitor-rstn.c similarity index 99% rename from src/monitor/stc-monitor-rstn.c rename to plugin/monitor/stc-plugin-monitor-rstn.c index 31a05ab..75bc4e5 100755 --- a/src/monitor/stc-monitor-rstn.c +++ b/plugin/monitor/stc-plugin-monitor-rstn.c @@ -18,10 +18,10 @@ #include #include "counter.h" -#include "stc-monitor.h" -#include "stc-monitor-rstn.h" -#include "stc-monitor-ipt.h" -#include "stc-time.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" @@ -1079,6 +1079,67 @@ static void __reset_time_counter_foreach_rstn_value(gpointer key, __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; @@ -1332,45 +1393,6 @@ gboolean stc_monitor_rstn_flush_contr_to_db(gpointer user_data) 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; @@ -1400,28 +1422,6 @@ void stc_monitor_rstn_add_by_connection(stc_connection_s *conn) 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; diff --git a/src/monitor/stc-time.c b/plugin/monitor/stc-plugin-monitor-time.c old mode 100644 new mode 100755 similarity index 96% rename from src/monitor/stc-time.c rename to plugin/monitor/stc-plugin-monitor-time.c index e0f86e0..f3a17cc --- a/src/monitor/stc-time.c +++ b/plugin/monitor/stc-plugin-monitor-time.c @@ -26,6 +26,8 @@ time_t stc_time_get_day_start(time_t now) struct tm *res; res = localtime_r(&now, &curr); + if (!res) + return 0; curr.tm_sec = 0; curr.tm_min = 0; @@ -41,6 +43,8 @@ time_t stc_time_get_week_start(time_t now) int days; res = localtime_r(&now, &curr); + if (!res) + return 0; curr.tm_sec = 0; curr.tm_min = 0; @@ -61,6 +65,8 @@ time_t stc_time_get_month_start(time_t now, int month_start_date) bool is_leap_year; res = localtime_r(&now, &curr); + if (!res) + return 0; curr.tm_sec = 0; curr.tm_min = 0; diff --git a/src/monitor/stc-monitor.c b/plugin/monitor/stc-plugin-monitor.c old mode 100644 new mode 100755 similarity index 92% rename from src/monitor/stc-monitor.c rename to plugin/monitor/stc-plugin-monitor.c index 0bfc5a5..117036e --- a/src/monitor/stc-monitor.c +++ b/plugin/monitor/stc-plugin-monitor.c @@ -18,7 +18,6 @@ #include #include -#include "stc-connection.h" #include "helper-nl.h" #include "helper-nfacct-rule.h" #include "helper-net-cls.h" @@ -27,9 +26,10 @@ #include "counter.h" #include "table-statistics.h" #include "table-counters.h" -#include "stc-monitor.h" +#include "stc-plugin-monitor.h" +#include "stc-plugin-monitor-connection.h" +#include "stc-plugin-monitor-rstn.h" #include "stc-manager-plugin-exception.h" -#include "stc-manager-plugin-tether.h" static stc_system_s *g_system = NULL; @@ -325,8 +325,10 @@ static void __fill_exceptions_list(void) stc_plugin_fill_exception_list(); } -stc_error_e stc_monitor_init(void) +stc_error_e stc_plugin_monitor_initialize(void) { + __STC_LOG_FUNC_ENTER__; + stc_system_s *system = MALLOC0(stc_system_s, 1); GIOChannel *gio = NULL; @@ -365,7 +367,6 @@ stc_error_e stc_monitor_init(void) 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); @@ -385,10 +386,11 @@ stc_error_e stc_monitor_init(void) __fill_exceptions_list(); stc_monitor_rstns_load(); + __STC_LOG_FUNC_EXIT__; return STC_ERROR_NONE; } -stc_error_e stc_monitor_deinit(void) +stc_error_e stc_plugin_monitor_deinitialize(void) { ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!"); @@ -569,7 +571,31 @@ void stc_monitor_remove_by_connection(void *data) } } -API stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline) -{ - return stc_plugin_check_exception_by_cmdline(cmdline); -} +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 +}; diff --git a/plugin/pcap/stc-plugin-pcap.c b/plugin/pcap/stc-plugin-pcap.c index 22dddb7..fd03c4a 100755 --- a/plugin/pcap/stc-plugin-pcap.c +++ b/plugin/pcap/stc-plugin-pcap.c @@ -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; } diff --git a/plugin/procfs/CMakeLists.txt b/plugin/procfs/CMakeLists.txt index dc04ca8..17ab7f2 100644 --- a/plugin/procfs/CMakeLists.txt +++ b/plugin/procfs/CMakeLists.txt @@ -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") diff --git a/plugin/procfs/include/stc-plugin-procfs.h b/plugin/procfs/include/stc-plugin-procfs.h old mode 100644 new mode 100755 index d548c1f..53635ca --- a/plugin/procfs/include/stc-plugin-procfs.h +++ b/plugin/procfs/include/stc-plugin-procfs.h @@ -20,7 +20,6 @@ #include #include "stc-error.h" #include "stc-manager.h" -#include "stc-monitor.h" typedef struct { int (*initialize_plugin) (void); diff --git a/plugin/procfs/stc-plugin-procfs.c b/plugin/procfs/stc-plugin-procfs.c index 5a323a4..668f15c 100755 --- a/plugin/procfs/stc-plugin-procfs.c +++ b/plugin/procfs/stc-plugin-procfs.c @@ -28,9 +28,10 @@ #include #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; diff --git a/plugin/tether/CMakeLists.txt b/plugin/tether/CMakeLists.txt index 889f44a..b64cfbd 100644 --- a/plugin/tether/CMakeLists.txt +++ b/plugin/tether/CMakeLists.txt @@ -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") diff --git a/plugin/tether/stc-plugin-tether.c b/plugin/tether/stc-plugin-tether.c index 5270aed..4b1e0b8 100755 --- a/plugin/tether/stc-plugin-tether.c +++ b/plugin/tether/stc-plugin-tether.c @@ -23,8 +23,8 @@ #include #include -#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; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ec0178..d23adde 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/database/db-common.c b/src/database/db-common.c old mode 100644 new mode 100755 index 372eb03..a4c2a3d --- a/src/database/db-common.c +++ b/src/database/db-common.c @@ -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); diff --git a/src/database/tables/table-counters.c b/src/database/tables/table-counters.c old mode 100644 new mode 100755 index 9bd49a2..96c15c5 --- a/src/database/tables/table-counters.c +++ b/src/database/tables/table-counters.c @@ -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; diff --git a/src/database/tables/table-restrictions.c b/src/database/tables/table-restrictions.c old mode 100644 new mode 100755 index 929449d..debb04d --- a/src/database/tables/table-restrictions.c +++ b/src/database/tables/table-restrictions.c @@ -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__; diff --git a/src/database/tables/table-statistics.c b/src/database/tables/table-statistics.c index f8db77b..ffb4b97 100755 --- a/src/database/tables/table-statistics.c +++ b/src/database/tables/table-statistics.c @@ -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); diff --git a/src/helper/helper-cgroup.c b/src/helper/helper-cgroup.c index fbb0024..1d5ba2b 100755 --- a/src/helper/helper-cgroup.c +++ b/src/helper/helper-cgroup.c @@ -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); diff --git a/src/helper/helper-file.c b/src/helper/helper-file.c index 636ef5d..53dcad0 100755 --- a/src/helper/helper-file.c +++ b/src/helper/helper-file.c @@ -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; } diff --git a/src/helper/helper-iptables.c b/src/helper/helper-iptables.c old mode 100644 new mode 100755 index 9a2cde8..1e140b7 --- a/src/helper/helper-iptables.c +++ b/src/helper/helper-iptables.c @@ -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 diff --git a/src/helper/helper-net-cls.c b/src/helper/helper-net-cls.c index 3f460f7..350dfb6 100755 --- a/src/helper/helper-net-cls.c +++ b/src/helper/helper-net-cls.c @@ -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; diff --git a/src/helper/helper-nfacct-rule.c b/src/helper/helper-nfacct-rule.c index fbe17ca..1d6d0c6 100755 --- a/src/helper/helper-nfacct-rule.c +++ b/src/helper/helper-nfacct-rule.c @@ -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; diff --git a/src/helper/helper-nl.c b/src/helper/helper-nl.c old mode 100644 new mode 100755 index 2c3c8f9..ff9d1af --- a/src/helper/helper-nl.c +++ b/src/helper/helper-nl.c @@ -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/stc-firewall.c b/src/stc-firewall.c index f1adadb..64e7abb 100755 --- a/src/stc-firewall.c +++ b/src/stc-firewall.c @@ -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, diff --git a/src/stc-manager-gdbus.c b/src/stc-manager-gdbus.c index ef74b17..22d0375 100755 --- a/src/stc-manager-gdbus.c +++ b/src/stc-manager-gdbus.c @@ -20,10 +20,10 @@ #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, diff --git a/src/stc-manager-plugin-appstatus.c b/src/stc-manager-plugin-appstatus.c old mode 100644 new mode 100755 index cab52ad..a79bc93 --- a/src/stc-manager-plugin-appstatus.c +++ b/src/stc-manager-plugin-appstatus.c @@ -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 diff --git a/src/stc-manager-plugin-exception.c b/src/stc-manager-plugin-exception.c old mode 100644 new mode 100755 index bc0078d..ad1c092 --- a/src/stc-manager-plugin-exception.c +++ b/src/stc-manager-plugin-exception.c @@ -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 index 0000000..209b1a1 --- /dev/null +++ b/src/stc-manager-plugin-monitor.c @@ -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 + +#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 diff --git a/src/stc-manager-plugin-pcap.c b/src/stc-manager-plugin-pcap.c old mode 100644 new mode 100755 index c9432a2..395031c --- a/src/stc-manager-plugin-pcap.c +++ b/src/stc-manager-plugin-pcap.c @@ -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 diff --git a/src/stc-manager-plugin-tether.c b/src/stc-manager-plugin-tether.c old mode 100644 new mode 100755 index afb170d..4c5e528 --- a/src/stc-manager-plugin-tether.c +++ b/src/stc-manager-plugin-tether.c @@ -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; } diff --git a/src/stc-manager.c b/src/stc-manager.c index ba9356d..11fa7bb 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -26,13 +26,13 @@ #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; } diff --git a/src/stc-restriction.c b/src/stc-restriction.c old mode 100644 new mode 100755 index 6b207a5..ffe1a85 --- a/src/stc-restriction.c +++ b/src/stc-restriction.c @@ -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;