SET(PACKAGE ${PROJECT_NAME})
SET(INTERFACES "${CMAKE_SOURCE_DIR}/interfaces")
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(LIBDIR ${PREFIX}/${LIB_PATH})
SET(DATA_DIR ${CMAKE_SOURCE_DIR}/data)
ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(plugin)
--- /dev/null
+/*
+ * 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_H__
+#define __STC_MANAGER_PLUGIN_H__
+
+#define STC_PLUGIN_FILEPATH "/usr/lib/stc-manager-plugin.so"
+
+void stc_manager_plugin_init(void);
+void stc_manager_plugin_deinit(void);
+
+int stc_send_warn_message_to_net_popup(const char *content,
+ const char *type, const char *app_id, const char *iftype, const char *warn);
+int stc_send_restriction_message_to_net_popup(const char *content,
+ const char *type, const char *app_id, const char *iftype, const char *limit);
+
+#endif /* __STC_MANAGER_PLUGIN_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __STC_PLUGIN_H__
+#define __STC_PLUGIN_H__
+
+#include <glib.h>
+
+typedef struct {
+ int(*send_restriction_message_to_net_popup) (const char *,
+ const char *, const char *, const char *, const char *);
+ int(*send_warn_message_to_net_popup) (const char *,
+ const char *, const char *, const char *, const char *);
+} stc_plugin_s;
+
+#endif /* __STC_PLUGIN_H__ */
%description
A smart traffic control manager to manage traffic counting and bandwidth limitation
+%package plugin
+Summary: STC manager plugin
+BuildRequires: pkgconfig(bundle)
+BuildRequires: pkgconfig(syspopup-caller)
+
+%description plugin
+A smart traffic control manager extension for plugin
+
%prep
%setup -q
chmod 644 %{SOURCE0}
%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DBIN_DIR=%{_bindir} \
+ -DLIB_PATH=%{_lib} \
-DENABLE_DATABASE=%{enable_database} \
-DDATABASE_FULL_PATH=%{database_full_path} \
-DENABLE_STATISTICS=%{enable_statistics} \
%config(noreplace) %attr(660, root, root) %{database_full_path}
%config(noreplace) %attr(660, root, root) %{database_full_path}-journal
%endif
+
+%files plugin
+%manifest %{name}.manifest
+%attr(500,root,root) %{_libdir}/stc-manager-plugin.so
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(stc-manager-plugin C)
+
+# Set required packages
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(pkgs_plugin REQUIRED
+ dlog
+ gio-2.0
+ gio-unix-2.0
+ glib-2.0
+ bundle
+ syspopup-caller
+ )
+
+FOREACH(flag ${pkgs_plugin_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+# INCLUDE_DIRECTORIES(SRCS 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")
+
+SET(SRCS_PLUGIN
+ stc-plugin.c
+ )
+
+# library build
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS_PLUGIN})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_plugin_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "" OUTPUT_NAME ${PROJECT_NAME})
+
+# install
+INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${LIBDIR})
--- /dev/null
+/*
+ * 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 <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syspopup_caller.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <dlog.h>
+
+#include "stc-plugin.h"
+
+#ifdef USE_DLOG
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "STC_MANAGER"
+
+#define STC_LOGD(format, args...) LOGD(format, ##args)
+#define STC_LOGI(format, args...) LOGI(format, ##args)
+#define STC_LOGW(format, args...) LOGW(format, ##args)
+#define STC_LOGE(format, args...) LOGE(format, ##args)
+
+#define __STC_LOG_FUNC_ENTER__ LOGD("Enter")
+#define __STC_LOG_FUNC_EXIT__ LOGD("Quit")
+
+#else /* USE_DLOG */
+
+#define STC_LOGD(format, args...)
+#define STC_LOGI(format, args...)
+#define STC_LOGW(format, args...)
+#define STC_LOGE(format, args...)
+
+#define __STC_LOG_FUNC_ENTER__
+#define __STC_LOG_FUNC_EXIT__
+
+#endif /* USE_DLOG */
+
+static int __stc_send_warn_message_to_net_popup(const char *content,
+ const char *type, const char *app_id, const char *iftype, const char *warn)
+{
+ int ret = 0;
+ bundle *b = bundle_create();
+
+ STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] limit[%s]",
+ title, content, type, app_id, limit);
+
+ bundle_add(b, "_SYSPOPUP_CONTENT_", content);
+ bundle_add(b, "_SYSPOPUP_TYPE_", type);
+ bundle_add(b, "_APP_ID_", app_id);
+ bundle_add(b, "_IF_TYPE_", iftype);
+ bundle_add(b, "_WARN_LIMIT_", warn);
+
+ ret = syspopup_launch("net-popup", b);
+
+ bundle_free(b);
+
+ return ret;
+}
+
+static int __stc_send_restriction_message_to_net_popup(const char *content,
+ const char *type, const char *app_id, const char *iftype, const char *limit)
+{
+ int ret = 0;
+ bundle *b = bundle_create();
+
+ STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]",
+ title, content, type, app_id);
+
+ bundle_add(b, "_SYSPOPUP_CONTENT_", content);
+ bundle_add(b, "_SYSPOPUP_TYPE_", type);
+ bundle_add(b, "_APP_ID_", app_id);
+ bundle_add(b, "_IF_TYPE_", iftype);
+ bundle_add(b, "_RESTRICTION_LIMIT_", limit);
+
+ ret = syspopup_launch("net-popup", b);
+
+ bundle_free(b);
+
+ return ret;
+}
+
+
+API stc_plugin_s stc_plugin = {
+ .send_warn_message_to_net_popup =
+ __stc_send_warn_message_to_net_popup,
+ .send_restriction_message_to_net_popup =
+ __stc_send_restriction_message_to_net_popup
+};
+
#include "table-statistics.h"
#include "table-counters.h"
#include "stc-monitor.h"
+#include "stc-manager-plugin.h"
+
+#define MAX_INT_LENGTH 128
typedef struct {
stc_app_key_s *app_key;
if (rstn_value->counter.in_bytes >= rstn_value->warn_limit.in_bytes
&& rstn_value->warn_limit_crossed_notified == FALSE) {
gboolean rv = FALSE;
+ char iftype[MAX_INT_LENGTH];
+ char byte[MAX_INT_LENGTH];
stc_s *stc = (stc_s *)stc_get_manager();
ret_value_msg_if(stc == NULL, FALSE, "failed to get stc data");
g_variant_new("(s)", rstn_key->app_id));
if (rv == TRUE)
rstn_value->warn_limit_crossed_notified = TRUE;
+
+ snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype);
+ snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit.in_bytes);
+ stc_send_warn_message_to_net_popup("warn threshold crossed",
+ "warning_noti", rstn_key->app_id, iftype, byte);
}
/* block immediately */
if (rstn_value->rstn_limit_crossed_notified == FALSE) {
gboolean rv = FALSE;
+ int ret = 0;
+ char iftype[MAX_INT_LENGTH];
+ char byte[MAX_INT_LENGTH];
stc_s *stc = (stc_s *)stc_get_manager();
ret_value_msg_if(stc == NULL, FALSE, "failed to get stc data");
g_variant_new("(s)", rstn_key->app_id));
if (rv == TRUE)
rstn_value->rstn_limit_crossed_notified = TRUE;
+
+ snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype);
+ snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit.in_bytes);
+ stc_send_restriction_message_to_net_popup("restriction threshold crossed",
+ "restriction_noti", rstn_key->app_id, iftype, byte);
}
}
if (rstn_value->counter.out_bytes >= rstn_value->limit.out_bytes
&& rstn_value->warn_limit_crossed_notified == FALSE) {
gboolean rv = FALSE;
+ char iftype[MAX_INT_LENGTH];
+ char byte[MAX_INT_LENGTH];
stc_s *stc = (stc_s *)stc_get_manager();
ret_value_msg_if(stc == NULL, FALSE, "failed to get stc data");
g_variant_new("(s)", rstn_key->app_id));
if (rv == TRUE)
rstn_value->warn_limit_crossed_notified = TRUE;
+
+ snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype);
+ snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit.out_bytes);
+ stc_send_warn_message_to_net_popup("warn threshold crossed",
+ "warning_noti", rstn_key->app_id, iftype, byte);
}
/* block immediately */
if (rstn_value->rstn_limit_crossed_notified == FALSE) {
gboolean rv = FALSE;
+ char iftype[MAX_INT_LENGTH];
+ char byte[MAX_INT_LENGTH];
stc_s *stc = (stc_s *)stc_get_manager();
ret_value_msg_if(stc == NULL, FALSE, "failed to get stc data");
g_variant_new("(s)", rstn_key->app_id));
if (rv == TRUE)
rstn_value->rstn_limit_crossed_notified = TRUE;
+
+ snprintf(iftype, MAX_INT_LENGTH, "%d", rstn_key->iftype);
+ snprintf(byte, MAX_INT_LENGTH, "%lld", rstn_value->limit.out_bytes);
+ stc_send_restriction_message_to_net_popup("restriction threshold crossed",
+ "restriction_noti", rstn_key->app_id, iftype, byte);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlfcn.h>
+
+#include "stc-manager.h"
+#include "stc-plugin.h"
+#include "stc-manager-plugin.h"
+
+static gboolean stc_plugin_enabled = FALSE;
+static void *handle_plugin;
+static stc_plugin_s *stc_plugin;
+
+void stc_manager_plugin_init(void)
+{
+ __STC_LOG_FUNC_ENTER__;
+
+ handle_plugin = dlopen(STC_PLUGIN_FILEPATH, RTLD_NOW);
+ if (!handle_plugin) {
+ STC_LOGE("Can't load %s: %s", STC_PLUGIN_FILEPATH, dlerror());
+ return;
+ }
+
+ stc_plugin = dlsym(handle_plugin, "stc_plugin");
+ if (!stc_plugin) {
+ STC_LOGE("Can't load symbol: %s", dlerror());
+ dlclose(handle_plugin);
+ return;
+ }
+
+ stc_plugin_enabled = TRUE;
+
+ __STC_LOG_FUNC_EXIT__;
+}
+
+void stc_manager_plugin_deinit(void)
+{
+ __STC_LOG_FUNC_ENTER__;
+
+ if (!stc_plugin_enabled)
+ return;
+
+ stc_plugin_enabled = FALSE;
+ dlclose(handle_plugin);
+
+ __STC_LOG_FUNC_EXIT__;
+}
+
+int stc_send_warn_message_to_net_popup(const char *content,
+ const char *type, const char *app_id, const char *iftype, const char *warn)
+{
+ __STC_LOG_FUNC_ENTER__;
+
+ if (!stc_plugin_enabled) {
+ STC_LOGE("Plugin wasn't enabled");
+ return 0;
+ }
+
+ if (!stc_plugin) {
+ STC_LOGE("Plugin wasn't loaded");
+ return 0;
+ }
+
+ return stc_plugin->send_warn_message_to_net_popup(content, type, app_id, iftype, warn);
+}
+
+int stc_send_restriction_message_to_net_popup(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");
+ return 0;
+ }
+
+ if (!stc_plugin) {
+ STC_LOGE("Plugin wasn't loaded");
+ return 0;
+ }
+
+ return stc_plugin->send_restriction_message_to_net_popup(content, type, app_id, iftype, limit);
+}
+
#include "helper-cgroup.h"
#include "helper-nfacct-rule.h"
#include "stc-monitor.h"
+#include "stc-manager-plugin.h"
static stc_s *g_stc = NULL;
stc_deinit_db_guard();
stc_db_deinitialize();
stc_manager_gdbus_deinit((gpointer)g_stc);
+ stc_manager_plugin_deinit();
STC_LOGI("stc manager deinitialized");
FREE(g_stc);
stc_monitor_init();
stc_manager_gdbus_init((gpointer)stc);
+ stc_manager_plugin_init();
STC_LOGI("stc manager initialized");
__STC_LOG_FUNC_EXIT__;