Reorganize directory structure about virtual-table 90/239490/1
authorSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 27 Jul 2020 05:58:55 +0000 (14:58 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Mon, 27 Jul 2020 05:58:55 +0000 (14:58 +0900)
Change-Id: I22a067aa48666157dfe9af37fe370aecc0b18f31
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
48 files changed:
CMakeLists.txt
plugins/bluetooth/CMakeLists.txt [deleted file]
plugins/bluetooth/bluetooth-test.cpp [deleted file]
plugins/bluetooth/bluetooth.cpp [deleted file]
plugins/bluetooth/bluetooth.hpp [deleted file]
plugins/sample/CMakeLists.txt [deleted file]
plugins/sample/sample.cpp [deleted file]
plugins/test-util.hpp [deleted file]
plugins/tests.cpp [deleted file]
plugins/usb/CMakeLists.txt [deleted file]
plugins/usb/usb.cpp [deleted file]
plugins/wifi/CMakeLists.txt [deleted file]
plugins/wifi/wifi-test.cpp [deleted file]
plugins/wifi/wifi.cpp [deleted file]
plugins/wifi/wifi.hpp [deleted file]
src/CMakeLists.txt
src/vist/service/CMakeLists.txt
src/vist/service/vistd.cpp
src/vist/table/CMakeLists.txt
src/vist/table/policy/bluetooth/CMakeLists.txt [deleted file]
src/vist/table/policy/bluetooth/policy.cpp [deleted file]
src/vist/table/policy/bluetooth/policy.hpp [deleted file]
src/vist/table/policy/bluetooth/table.cpp [deleted file]
src/vist/table/policy/bluetooth/table.hpp [deleted file]
src/vist/table/policy/bluetooth/tests/bluetooth.cpp [deleted file]
src/vist/table/policy/policy-admin.cpp [deleted file]
src/vist/table/policy/policy-admin.hpp [deleted file]
src/vist/table/policy/policy.cpp [deleted file]
src/vist/table/policy/policy.hpp [deleted file]
src/vist/table/policy/sample/CMakeLists.txt [deleted file]
src/vist/table/policy/sample/policy.hpp [deleted file]
src/vist/table/policy/sample/table.cpp [deleted file]
src/vist/table/policy/sample/table.hpp [deleted file]
tables/CMakeLists.txt [new file with mode: 0644]
tables/built-in/policy-admin.cpp [new file with mode: 0644]
tables/built-in/policy-admin.hpp [new file with mode: 0644]
tables/built-in/policy.cpp [new file with mode: 0644]
tables/built-in/policy.hpp [new file with mode: 0644]
tables/policy/bluetooth/CMakeLists.txt [new file with mode: 0644]
tables/policy/bluetooth/policy.cpp [new file with mode: 0644]
tables/policy/bluetooth/policy.hpp [new file with mode: 0644]
tables/policy/bluetooth/table.cpp [new file with mode: 0644]
tables/policy/bluetooth/table.hpp [new file with mode: 0644]
tables/policy/bluetooth/tests/bluetooth.cpp [new file with mode: 0644]
tables/policy/sample/CMakeLists.txt [new file with mode: 0644]
tables/policy/sample/policy.hpp [new file with mode: 0644]
tables/policy/sample/table.cpp [new file with mode: 0644]
tables/policy/sample/table.hpp [new file with mode: 0644]

index 995e690c7f865b3731703894ba7b85a64445f39f..0fd59d2ad814bda2d7e9fc077cbea4e9b3a8f380 100644 (file)
@@ -39,8 +39,18 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++1z -O2 -DNDEBUG")
 SET(CMAKE_SHARED_LINKER_FLAGS  "-Wl,--as-needed")
 SET(CMAKE_EXE_LINKER_FLAGS     "-Wl,--as-needed")
 
+SET(VIST_SRCS        ${CMAKE_SOURCE_DIR}/src/vist)
+SET(VIST_TABLES_SRCS ${CMAKE_SOURCE_DIR}/tables)
+
+SET(TARGET_OSQUERY_LIB osquery)
+SET(TARGET_VIST_CLIENT_LIB vist-client)
+SET(TARGET_VIST_COMMON_LIB vist-common)
+SET(TARGET_VIST_LIB vist)
+SET(TARGET_VIST_POLICY_LIB vist-policy)
+
 ADD_DEFINITIONS("-fPIC")
 
+INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}")
 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src")
 # Suppresse SYSTEM header's warnings:
 INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_SOURCE_DIR}/src/osquery/include")
@@ -50,6 +60,7 @@ ENABLE_TESTING()
 
 ADD_SUBDIRECTORY(data)
 ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tables)
 
 IF(DEFINED GBS_BUILD)
        ADD_SUBDIRECTORY(systemd)
diff --git a/plugins/bluetooth/CMakeLists.txt b/plugins/bluetooth/CMakeLists.txt
deleted file mode 100644 (file)
index 07a2346..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET "vist-plugin-bluetooth")
-SET(TARGET_TEST ${TARGET}-test)
-
-SET(PLUGIN_SOURCES "bluetooth.cpp")
-
-SET(DEPENDENCY bluetooth-api
-                          capi-network-bluetooth)
-
-PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
-
-INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS})
-
-ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES})
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES}
-                                                               vist-common)
-
-INSTALL(FILES libvist-plugin-bluetooth.so
-               RENAME bluetooth
-               DESTINATION ${PLUGIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${TARGET_TEST} ../tests.cpp
-                                                         bluetooth.cpp
-                                                         bluetooth-test.cpp)
-TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES}
-                                                                        vist-common
-                                                                        vist-client
-                                                                        gtest
-                                                                        pthread)
-INSTALL(TARGETS ${TARGET_TEST}
-               DESTINATION ${CMAKE_INSTALL_BINDIR}
-               PERMISSIONS OWNER_READ
-                                       OWNER_WRITE
-                                       OWNER_EXECUTE
-                                       GROUP_READ
-                                       GROUP_EXECUTE
-                                       WORLD_READ
-                                       WORLD_EXECUTE)
diff --git a/plugins/bluetooth/bluetooth-test.cpp b/plugins/bluetooth/bluetooth-test.cpp
deleted file mode 100644 (file)
index 1c282a8..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "bluetooth.hpp"
-#include "../test-util.hpp"
-
-#include <vist/client/query.hpp>
-#include <vist/schema/bluetooth.hpp>
-#include <vist/exception.hpp>
-
-#include <iostream>
-
-#include <gtest/gtest.h>
-
-using namespace vist;
-
-TEST(BluetoothTests, change_policy_state)
-{
-       using namespace vist::policy::plugin;
-
-       try {
-               test::change_policy_state<BluetoothState>();
-               test::change_policy_state<DesktopConnectivity>();
-               test::change_policy_state<Pairing>();
-               test::change_policy_state<Tethering>();
-       } catch(const vist::Exception<ErrCode>& e) {
-               EXPECT_TRUE(false) << e.what();
-       }
-}
-
-TEST(BluetoothTests, get_policies)
-{
-       auto rows = Query::Execute("SELECT * FROM bluetooth");
-
-       EXPECT_TRUE(rows.size() == 1);
-}
-
-TEST(BluetoothTests, set_policies)
-{
-       Query::Execute("INSERT INTO policy_admin (name) VALUES ('vist-plugin-bluetooth-test')");
-
-       Query::Execute("UPDATE bluetooth SET desktopConnectivity = 3, state = 7");
-       Query::Execute("UPDATE bluetooth SET pairing = 2, tethering = 9");
-
-       auto rows = Query::Execute("SELECT * FROM bluetooth");
-       if (rows.size() == 1) {
-               EXPECT_EQ(rows[0]["state"], "7");
-               EXPECT_EQ(rows[0]["desktopConnectivity"], "3");
-               EXPECT_EQ(rows[0]["pairing"], "2");
-               EXPECT_EQ(rows[0]["tethering"], "9");
-       } else {
-               EXPECT_TRUE(false);
-       }
-
-       Query::Execute("DELETE FROM policy_admin WHERE name = 'vist-plugin-bluetooth-test'");
-}
-
-TEST(BluetoothTest, query_builder)
-{
-       using namespace vist::schema;
-
-       std::string query = BluetoothTable.selectAll();
-       EXPECT_EQ(query, "SELECT * FROM bluetooth");
-
-       query = BluetoothTable.update(Bluetooth::DesktopConnectivity = 3, Bluetooth::State = 7);
-       EXPECT_EQ(query, "UPDATE bluetooth SET desktopConnectivity = 3, state = 7");
-
-       query = BluetoothTable.update(Bluetooth::Pairing = 2, Bluetooth::Tethering = 9);
-       EXPECT_EQ(query, "UPDATE bluetooth SET pairing = 2, tethering = 9");
-}
diff --git a/plugins/bluetooth/bluetooth.cpp b/plugins/bluetooth/bluetooth.cpp
deleted file mode 100644 (file)
index 26b3c41..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "bluetooth.hpp"
-
-#include <bluetooth.h>
-#include <bluetooth-api.h>
-#include <bluetooth_internal.h>
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
-
-#include <memory>
-
-namespace vist {
-namespace policy {
-namespace plugin {
-
-namespace {
-
-bool failed(auto value)
-{
-       return value == BLUETOOTH_DPM_RESULT_ACCESS_DENIED || value == BLUETOOTH_DPM_RESULT_FAIL;
-}
-
-auto allowed(int value)
-{
-       return value ? BLUETOOTH_DPM_ALLOWED : BLUETOOTH_DPM_RESTRICTED;
-}
-
-auto bt_allowed(int value)
-{
-       return value ? BLUETOOTH_DPM_BT_ALLOWED : BLUETOOTH_DPM_BT_RESTRICTED;
-}
-
-} // anonymous namespace
-
-void BluetoothState::onChanged(const PolicyValue& value)
-{
-       auto enable = bt_allowed(value);
-       auto ret = ::bluetooth_dpm_set_allow_mode(enable);
-       if (failed(ret))
-               THROW(ErrCode::RuntimeError) << "Failed to change bluetooth state: " << ret;
-
-       INFO(VIST_PLUGIN) << "Bluetooth state is changed to " << enable;
-}
-
-void DesktopConnectivity::onChanged(const PolicyValue& value)
-{
-       auto enable = allowed(value);
-       auto ret = ::bluetooth_dpm_set_desktop_connectivity_state(enable);
-       if (failed(ret))
-               THROW(ErrCode::RuntimeError) << "Failed to change bt_desktop_connectivity: " << ret;
-
-       INFO(VIST_PLUGIN) << "Bluetooth desktop connectivity state is changed to " << enable;
-}
-
-void Pairing::onChanged(const PolicyValue& value)
-{
-       auto enable = allowed(value);
-       auto ret = ::bluetooth_dpm_set_pairing_state(enable);
-       if (failed(ret))
-               THROW(ErrCode::RuntimeError) << "Failed to change bluetooth pairing: " << ret;
-
-       INFO(VIST_PLUGIN) << "Bluetooth pairing state is changed to " << enable;
-}
-
-void Tethering::onChanged(const PolicyValue& value)
-{
-       auto enable = value;
-       INFO(VIST_PLUGIN) << "Bluetooth tethering state is changed to " << enable;
-}
-
-Bluetooth::Bluetooth(const std::string& name) : PolicyProvider(name)
-{
-       if (::bt_initialize() != BT_ERROR_NONE)
-               THROW(ErrCode::RuntimeError) << "Failed to init bluetooth provider.";
-}
-
-Bluetooth::~Bluetooth()
-{
-       ::bt_deinitialize();
-}
-
-// TODO(Sangwan): Add privilege to provider
-#define PRIVILEGE "http://tizen.org/privilege/dpm.bluetooth"
-
-extern "C" PolicyProvider* PolicyFactory()
-{
-       INFO(VIST_PLUGIN) << "Bluetooth plugin loaded.";
-       Bluetooth* provider = new Bluetooth("bluetooth");
-       provider->add(std::make_shared<BluetoothState>());
-       provider->add(std::make_shared<DesktopConnectivity>());
-       provider->add(std::make_shared<Pairing>());
-       provider->add(std::make_shared<Tethering>());
-
-       return provider;
-}
-
-} // namespace plugin
-} // namespace policy
-} // namespace vist
diff --git a/plugins/bluetooth/bluetooth.hpp b/plugins/bluetooth/bluetooth.hpp
deleted file mode 100644 (file)
index b32bf66..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#pragma once
-
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-provider.hpp>
-#include <vist/sdk/policy-value.hpp>
-
-namespace vist {
-namespace policy {
-namespace plugin {
-
-class BluetoothState : public PolicyModel {
-public:
-       BluetoothState() : PolicyModel("bluetooth", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class DesktopConnectivity : public PolicyModel {
-public:
-       DesktopConnectivity() : PolicyModel("bluetooth-desktop-connectivity", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class Pairing: public PolicyModel {
-public:
-       Pairing() : PolicyModel("bluetooth-pairing", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class Tethering: public PolicyModel {
-public:
-       Tethering() : PolicyModel("bluetooth-tethering", PolicyValue(1)) {}
-       void onChanged(const PolicyValue&);
-};
-
-class Bluetooth final : public PolicyProvider {
-public:
-       Bluetooth(const std::string& name);
-       ~Bluetooth();
-};
-
-} // namespace plugin
-} // namespace policy
-} // namespace vist
diff --git a/plugins/sample/CMakeLists.txt b/plugins/sample/CMakeLists.txt
deleted file mode 100644 (file)
index 439fa43..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET "vist-plugin-sample")
-
-INCLUDE_DIRECTORIES(SYSTEM)
-
-ADD_LIBRARY(${TARGET} SHARED sample.cpp)
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-TARGET_LINK_LIBRARIES(${TARGET} vist-common)
-
-IF(DEFINED GBS_BUILD)
-       INSTALL(FILES libvist-plugin-sample.so
-                       RENAME sample
-                       DESTINATION ${PLUGIN_INSTALL_DIR})
-ELSE(DEFINED GBS_BUILD)
-       INSTALL(TARGETS ${TARGET}
-                       RENAME sample
-                       DESTINATION ${PLUGIN_INSTALL_DIR})
-ENDIF(DEFINED GBS_BUILD)
diff --git a/plugins/sample/sample.cpp b/plugins/sample/sample.cpp
deleted file mode 100644 (file)
index 5327fb1..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-value.hpp>
-#include <vist/sdk/policy-provider.hpp>
-
-#include <vist/logger.hpp>
-
-#include <memory>
-#include <string>
-
-using namespace vist;
-using namespace vist::policy;
-
-class SampleIntPolicy : public PolicyModel {
-public:
-       SampleIntPolicy() : PolicyModel("sample-int-policy", PolicyValue(7))
-       {
-       }
-
-       void onChanged(const PolicyValue& value) override
-       {
-               INFO(VIST_PLUGIN) << "sample-int-policy is changed to "
-                                                 << static_cast<int>(value);
-       }
-};
-
-class SampleStrPolicy : public PolicyModel {
-public:
-       SampleStrPolicy() : PolicyModel("sample-str-policy", PolicyValue("TEST"))
-       {
-       }
-
-       void onChanged(const PolicyValue& value) override
-       {
-               INFO(VIST_PLUGIN) << "sample-str-policy is changed to "
-                                                 << static_cast<std::string>(value);
-       }
-
-       int compare(const PolicyValue& lhs, const PolicyValue& rhs) const override
-       {
-               std::string lvalue = lhs;
-               std::string rvalue = rhs;
-
-               INFO(VIST_PLUGIN) << "Custom compare method is called with [" << lvalue
-                                                 << "], [" << rvalue << "]";
-
-               return lvalue.compare(rvalue);
-       }
-};
-
-class Sample : public PolicyProvider {
-public:
-       Sample(const std::string& name) : PolicyProvider(name)
-       {
-       }
-
-       ~Sample()
-       {
-       }
-};
-
-extern "C" PolicyProvider* PolicyFactory()
-{
-       INFO(VIST_PLUGIN) << "Sample plugin loaded.";
-       Sample* provider = new Sample("sample");
-       provider->add(std::make_shared<SampleIntPolicy>());
-       provider->add(std::make_shared<SampleStrPolicy>());
-
-       return provider;
-}
diff --git a/plugins/test-util.hpp b/plugins/test-util.hpp
deleted file mode 100644 (file)
index 06a278e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#pragma once
-
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-value.hpp>
-
-#include <memory>
-
-namespace vist {
-namespace test {
-
-using namespace vist::policy;
-
-template <typename T>
-void change_policy_state()
-{
-       std::shared_ptr<PolicyModel> policy = std::make_shared<T>();
-       /// enable policy
-       policy->onChanged(PolicyValue(1));
-       /// disable policy
-       policy->onChanged(PolicyValue(0));
-}
-
-} // namespace test
-} // namespace vist
diff --git a/plugins/tests.cpp b/plugins/tests.cpp
deleted file mode 100644 (file)
index 0fcfc89..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include <gtest/gtest.h>
-
-int main(int argc, char* argv[]) {
-       testing::InitGoogleTest(&argc, argv);
-       return RUN_ALL_TESTS();
-}
diff --git a/plugins/usb/CMakeLists.txt b/plugins/usb/CMakeLists.txt
deleted file mode 100644 (file)
index cfc1c3f..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET "dpm-plugin-usb")
-
-SET(PLUGIN_SOURCES "usb.cpp")
-
-SET(DEPENDENCY klay)
-
-PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
-
-SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
-
-ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES})
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES})
-
-INSTALL(FILES libdpm-plugin-usb.so
-        RENAME usb
-        DESTINATION ${PLUGIN_INSTALL_DIR})
diff --git a/plugins/usb/usb.cpp b/plugins/usb/usb.cpp
deleted file mode 100644 (file)
index 82dac70..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include <policyd/pil/policy-context.h>
-#include <policyd/pil/policy-model.h>
-#include <policyd/pil/policy-storage.h>
-#include <policyd/pil/policy-event.h>
-#include <policyd/pil/app-bundle.h>
-#include <policyd/pil/launchpad.h>
-
-#include <klay/auth/user.h>
-#include <klay/dbus/variant.h>
-#include <klay/dbus/connection.h>
-
-#include <tzplatform_config.h>
-
-#include "../dlog.h"
-
-#define DEVICED_SYSNOTI_INTERFACE              \
-       "org.tizen.system.deviced",                             \
-       "/Org/Tizen/System/DeviceD/SysNoti",    \
-       "org.tizen.system.deviced.SysNoti",                     \
-       "control"
-
-class DebuggingMode : public GlobalPolicy<DataSetInt> {
-public:
-       DebuggingMode() : GlobalPolicy("usb-debugging")
-       {
-               PolicyEventNotifier::create("usb_debugging");
-       }
-
-       bool apply(const DataType& value)
-       {
-               int enable = value;
-               PolicyEventNotifier::emit("usb_debugging", enable ? "allowed" : "disallowed");
-               return true;
-       }
-};
-
-class Tethering : public GlobalPolicy<DataSetInt> {
-public:
-       Tethering() : GlobalPolicy("usb-tethering")
-       {
-               PolicyEventNotifier::create("usb_tethering");
-       }
-
-       bool apply(const DataType& value)
-       {
-               int enable = value;
-               PolicyEventNotifier::emit("usb_tethering", enable ? "allowed" : "disallowed");
-               return true;
-       }
-};
-
-class Client : public GlobalPolicy<DataSetInt> {
-public:
-       Client() : GlobalPolicy("usb-client")
-       {
-               PolicyEventNotifier::create("usb_client");
-               sendDbusSignal();
-       }
-
-       bool apply(const DataType& value)
-       {
-               int ret;
-               int enable = value;
-
-               try {
-                       std::string pid(std::to_string(::getpid()));
-                       std::string state(std::to_string(enable));
-                       dbus::Connection &systemDBus = dbus::Connection::getSystem();
-                       systemDBus.methodcall(DEVICED_SYSNOTI_INTERFACE,
-                                                                               -1, "(i)", "(sisss)",
-                                                                               "control", 3, pid.c_str(), "1", state.c_str()).get("(i)", &ret);
-               } catch(runtime::Exception& e) {
-                       ERROR(PLUGINS, "Failed to enforce usb client");
-                       return false;
-               }
-
-               if (ret == 0) {
-                       PolicyEventNotifier::emit("usb_client", enable ? "allowed" : "disallowed");
-                       return true;
-               }
-
-               return false;
-       }
-
-       void sendDbusSignal(void)
-       {
-               int ret;
-               int enable = get().value;
-
-               try {
-                       std::string pid(std::to_string(::getpid()));
-                       std::string state(std::to_string(enable));
-                       dbus::Connection &systemDBus = dbus::Connection::getSystem();
-                       systemDBus.methodcall(DEVICED_SYSNOTI_INTERFACE,
-                                                                               -1, "(i)", "(sisss)",
-                                                                               "control", 3, pid.c_str(), "1", state.c_str()).get("(i)", &ret);
-               } catch(runtime::Exception& e) {
-                       ERROR(PLUGINS, "Failed to enforce usb client");
-               }
-       }
-};
-
-class Usb : public AbstractPolicyProvider {
-public:
-       int setDebuggingState(bool enable);
-       bool getDebuggingState();
-
-       int setTetheringState(bool enable);
-       bool getTetheringState();
-
-       int setClientState(bool enable);
-       bool getClientState();
-
-private:
-       DebuggingMode debugging;
-       Tethering tethering;
-       Client client;
-};
-
-int Usb::setDebuggingState(bool enable)
-{
-       try {
-               debugging.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Usb::getDebuggingState()
-{
-       return debugging.get();
-}
-
-int Usb::setTetheringState(bool enable)
-{
-       try {
-               tethering.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Usb::getTetheringState()
-{
-       return tethering.get();
-}
-
-int Usb::setClientState(bool enable)
-{
-       try {
-               client.set(enable);
-       } catch (runtime::Exception& e) {
-               ERROR(PLUGINS, e.what());
-               return -1;
-       }
-
-       return 0;
-}
-
-bool Usb::getClientState()
-{
-       return client.get();
-}
-
-extern "C" {
-
-#define PRIVILEGE_USB       "http://tizen.org/privilege/dpm.usb"
-#define PRIVILEGE_DEBUGGING "http://tizen.org/privilege/dpm.debugging"
-
-AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context)
-{
-       INFO(PLUGINS, "Usb plugin loaded");
-       Usb *policy = new Usb();
-
-       context.expose(policy, PRIVILEGE_DEBUGGING, (int)(Usb::setDebuggingState)(bool));
-       context.expose(policy, PRIVILEGE_USB, (int)(Usb::setTetheringState)(bool));
-       context.expose(policy, PRIVILEGE_USB, (int)(Usb::setClientState)(bool));
-
-       context.expose(policy, "", (bool)(Usb::getDebuggingState)());
-       context.expose(policy, "", (bool)(Usb::getTetheringState)());
-       context.expose(policy, "", (bool)(Usb::getClientState)());
-
-       return policy;
-}
-
-} // extern "C"
diff --git a/plugins/wifi/CMakeLists.txt b/plugins/wifi/CMakeLists.txt
deleted file mode 100644 (file)
index 4a70348..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET "vist-plugin-wifi")
-SET(TARGET_TEST ${TARGET}-test)
-
-SET(PLUGIN_SOURCES "wifi.cpp")
-
-SET(DEPENDENCY klay
-                          capi-network-wifi-manager
-                          capi-network-connection)
-
-PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
-
-INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS})
-
-ADD_LIBRARY(${TARGET} SHARED ${PLUGIN_SOURCES})
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS "-fvisibility=default")
-TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES}
-                                                               vist-common)
-INSTALL(FILES libvist-plugin-wifi.so
-               RENAME wifi
-               DESTINATION ${PLUGIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${TARGET_TEST} ../tests.cpp
-                                                         wifi.cpp
-                                                         wifi-test.cpp)
-TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES}
-                                                                        vist-common
-                                                                        gtest
-                                                                        pthread)
-INSTALL(TARGETS ${TARGET_TEST}
-               DESTINATION ${CMAKE_INSTALL_BINDIR}
-               PERMISSIONS OWNER_READ
-                                       OWNER_WRITE
-                                       OWNER_EXECUTE
-                                       GROUP_READ
-                                       GROUP_EXECUTE
-                                       WORLD_READ
-                                       WORLD_EXECUTE)
diff --git a/plugins/wifi/wifi-test.cpp b/plugins/wifi/wifi-test.cpp
deleted file mode 100644 (file)
index ca048fd..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "wifi.hpp"
-#include "../test-util.hpp"
-
-#include <vist/exception.hpp>
-
-#include <gtest/gtest.h>
-
-using namespace vist;
-using namespace vist::policy::plugin;
-
-TEST(WifiTests, change_policy_state)
-{
-       try {
-               test::change_policy_state<WifiState>();
-               test::change_policy_state<ProfileChange>();
-               test::change_policy_state<Hotspot>();
-               test::change_policy_state<SsidRestriction>();
-       } catch(const vist::Exception<ErrCode>& e) {
-               EXPECT_TRUE(false) << e.what();
-       }
-}
diff --git a/plugins/wifi/wifi.cpp b/plugins/wifi/wifi.cpp
deleted file mode 100644 (file)
index cb169d4..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "wifi.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
-
-#include <klay/dbus/connection.h>
-
-#include <memory>
-
-#define NETCONFIG_INTERFACE            \
-       "net.netconfig",                        \
-       "/net/netconfig/network",       \
-       "net.netconfig.network"
-
-namespace vist {
-namespace policy {
-namespace plugin {
-
-void WifiState::onChanged(const PolicyValue& value)
-{
-       int enable = value;
-       INFO(VIST_PLUGIN) << "Wifi state is changed to " << enable;
-       klay::dbus::Connection &systemDBus = klay::dbus::Connection::getSystem();
-       systemDBus.methodcall(NETCONFIG_INTERFACE,
-                                                 "DevicePolicySetWifi",
-                                                 -1,
-                                                 "",
-                                                 "(i)",
-                                                 enable);
-}
-
-void ProfileChange::onChanged(const PolicyValue& value)
-{
-       int enable = value;
-       INFO(VIST_PLUGIN) << "Wifi profile change state is changed to " << enable;
-       dbus::Connection &systemDBus = dbus::Connection::getSystem();
-       systemDBus.methodcall(NETCONFIG_INTERFACE,
-                                                 "DevicePolicySetWifiProfile",
-                                                 -1,
-                                                 "",
-                                                 "(i)",
-                                                 enable);
-}
-
-void Hotspot::onChanged(const PolicyValue& value)
-{
-       int enable = value;
-       INFO(VIST_PLUGIN) << "Wifi hotspot change state is changed to " << enable;
-}
-
-void SsidRestriction::onChanged(const PolicyValue& value)
-{
-       int enable = value;
-       INFO(VIST_PLUGIN) << "Wifi ssid restriction change state is changed to " << enable;
-}
-
-Wifi::Wifi(const std::string& name) : PolicyProvider(name)
-{
-       int ret = ::wifi_manager_initialize(&handle);
-       if (ret != WIFI_MANAGER_ERROR_NONE) {
-               if (ret == WIFI_MANAGER_ERROR_NOT_SUPPORTED)
-                       ERROR("Wifi manager is not supported.");
-
-               THROW(ErrCode::RuntimeError) << "Failed to init WiFi Manager.";
-       }
-}
-
-Wifi::~Wifi()
-{
-       ::wifi_manager_deinitialize(handle);
-}
-
-// TODO(Sangwan): Add privilege to provider
-#define PRIVILEGE "http://tizen.org/privilege/dpm.wifi"
-
-extern "C" PolicyProvider* PolicyFactory()
-{
-       INFO(VIST_PLUGIN) << "Wifi plugin loaded.";
-       Wifi* provider = new Wifi("wifi");
-       provider->add(std::make_shared<WifiState>());
-       provider->add(std::make_shared<ProfileChange>());
-       provider->add(std::make_shared<Hotspot>());
-       provider->add(std::make_shared<SsidRestriction>());
-
-       return provider;
-}
-
-} // namespace plugin
-} // namespace policy
-} // namespace vist
diff --git a/plugins/wifi/wifi.hpp b/plugins/wifi/wifi.hpp
deleted file mode 100644 (file)
index b076cbb..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#pragma once
-
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-provider.hpp>
-#include <vist/sdk/policy-value.hpp>
-
-#include <wifi-manager.h>
-
-namespace vist {
-namespace policy {
-namespace plugin {
-
-struct WifiState : public PolicyModel {
-       WifiState() : PolicyModel("wifi", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-struct ProfileChange : public PolicyModel {
-       ProfileChange() : PolicyModel("wifi-profile-change", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-struct Hotspot : public PolicyModel {
-       Hotspot() : PolicyModel("wifi-hotspot", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-struct SsidRestriction : public PolicyModel {
-       SsidRestriction() : PolicyModel("wifi-ssid-restriction", PolicyValue(0)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class Wifi final : public PolicyProvider {
-public:
-       Wifi(const std::string& name);
-       ~Wifi();
-
-private:
-       ::wifi_manager_h handle = nullptr;
-};
-
-} // namespace plugin
-} // namespace policy
-} // namespace vist
index b8168b566c6c024321ab234787afcfae779f4608..43477b5a490464382ff9b1edd1ac1fd34f474ca5 100644 (file)
@@ -1,4 +1,4 @@
-#  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+#  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
 #
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
 #  See the License for the specific language governing permissions and
 #  limitations under the License
 
-SET(TARGET_OSQUERY_LIB osquery)
-SET(TARGET_VIST_CLIENT_LIB vist-client)
-SET(TARGET_VIST_COMMON_LIB vist-common)
-SET(TARGET_VIST_LIB vist)
-SET(TARGET_VIST_POLICY_LIB vist-policy)
-
 ADD_SUBDIRECTORY(osquery)
 ADD_SUBDIRECTORY(vist)
index 983e1d2e4c0e5f6e46b218cdf5238b5a6bdce2c2..b11ed24995261753eca915097a440bed34adb087 100644 (file)
 #  See the License for the specific language governing permissions and
 #  limitations under the License
 
-ADD_VIST_LIBRARY(vist_core vistd.cpp)
+ADD_VIST_LIBRARY(vist_core vistd.cpp
+                                                  ${VIST_TABLES_SRCS}/built-in/policy-admin.cpp
+                                                  ${VIST_TABLES_SRCS}/built-in/policy.cpp)
+
 
 FILE(GLOB CORE_TESTS "tests/*.cpp")
 ADD_VIST_TEST(${CORE_TESTS})
index c2fffbbf5943f33f12b4a8240f1da3c3ce71eddc..f3a7fdd270a686facbfe140953f48d2d819ecda3 100644 (file)
 #include <vist/policy/api.hpp>
 #include <vist/policy/policy-manager.hpp>
 #include <vist/rmi/gateway.hpp>
-
 #include <vist/table/dynamic-table.hpp>
-#include <vist/table/policy/policy-admin.hpp>
-#include <vist/table/policy/policy.hpp>
+
+#include <tables/built-in/policy-admin.hpp>
+#include <tables/built-in/policy.hpp>
 
 #include <osquery/registry_interface.h>
 #include <osquery/sql.h>
index e17acc08ab2b2a66551911b195c96dedadf8e14e..354515aff8ec8b67e1a7c741b9d4395c2e2e000c 100644 (file)
 #  limitations under the License
 
 ## static virtual table
-ADD_VIST_LIBRARY(vist_table util.cpp
-                                                       policy/policy-admin.cpp
-                                                       policy/policy.cpp)
-
-## dynamic virtual table
-ADD_SUBDIRECTORY(policy/sample)
-
-IF(DEFINED GBS_BUILD)
-       ADD_SUBDIRECTORY(policy/bluetooth)
-ENDIF(DEFINED GBS_BUILD)
+ADD_VIST_LIBRARY(vist_table util.cpp)
diff --git a/src/vist/table/policy/bluetooth/CMakeLists.txt b/src/vist/table/policy/bluetooth/CMakeLists.txt
deleted file mode 100644 (file)
index 6f63912..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET "vist-bluetooth-policy")
-SET(TARGET_TEST ${TARGET}-test)
-
-SET(DEPENDENCY bluetooth-api
-                          capi-network-bluetooth)
-
-PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
-
-INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS})
-
-## LIB ###########################################
-ADD_LIBRARY(${TARGET} SHARED policy.cpp table.cpp)
-TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES}
-                                                               ${TARGET_VIST_COMMON_LIB}
-                                                               ${TARGET_VIST_POLICY_LIB})
-
-INSTALL(TARGETS ${TARGET} DESTINATION ${TABLE_INSTALL_DIR})
-
-## TEST #############################################
-ADD_EXECUTABLE(${TARGET_TEST} ../../../main/tests.cpp
-                                                         policy.cpp
-                                                         table.cpp
-                                                         tests/bluetooth.cpp)
-TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES}
-                                                                        ${TARGET_VIST_CLIENT_LIB}
-                                                                        ${TARGET_VIST_LIB}
-                                                                        gtest
-                                                                        pthread)
-INSTALL(TARGETS ${TARGET_TEST}
-               DESTINATION ${CMAKE_INSTALL_BINDIR}
-               PERMISSIONS OWNER_READ
-                                       OWNER_WRITE
-                                       OWNER_EXECUTE
-                                       GROUP_READ
-                                       GROUP_EXECUTE
-                                       WORLD_READ
-                                       WORLD_EXECUTE)
diff --git a/src/vist/table/policy/bluetooth/policy.cpp b/src/vist/table/policy/bluetooth/policy.cpp
deleted file mode 100644 (file)
index 49ba0b4..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "policy.hpp"
-
-#include <vist/logger.hpp>
-#include <vist/exception.hpp>
-
-#include <bluetooth.h>
-#include <bluetooth-api.h>
-#include <bluetooth_internal.h>
-
-namespace vist {
-namespace policy {
-
-namespace {
-
-bool failed(int value)
-{
-       return value == BLUETOOTH_DPM_RESULT_ACCESS_DENIED || value == BLUETOOTH_DPM_RESULT_FAIL;
-}
-
-auto allowed(int value)
-{
-       return value ? BLUETOOTH_DPM_ALLOWED : BLUETOOTH_DPM_RESTRICTED;
-}
-
-auto bt_allowed(int value)
-{
-       return value ? BLUETOOTH_DPM_BT_ALLOWED : BLUETOOTH_DPM_BT_RESTRICTED;
-}
-
-} // anonymous namespace
-
-void BluetoothState::onChanged(const PolicyValue& value)
-{
-       auto enable = bt_allowed(value);
-       auto ret = ::bluetooth_dpm_set_allow_mode(enable);
-       if (failed(ret))
-               THROW(ErrCode::RuntimeError) << "Failed to change bluetooth state: " << ret;
-
-       INFO(VIST_PLUGIN) << "Bluetooth state is changed to " << enable;
-}
-
-void DesktopConnectivity::onChanged(const PolicyValue& value)
-{
-       auto enable = allowed(value);
-       auto ret = ::bluetooth_dpm_set_desktop_connectivity_state(enable);
-       if (failed(ret))
-               THROW(ErrCode::RuntimeError) << "Failed to change bt_desktop_connectivity: " << ret;
-
-       INFO(VIST_PLUGIN) << "Bluetooth desktop connectivity state is changed to " << enable;
-}
-
-void Pairing::onChanged(const PolicyValue& value)
-{
-       auto enable = allowed(value);
-       auto ret = ::bluetooth_dpm_set_pairing_state(enable);
-       if (failed(ret))
-               THROW(ErrCode::RuntimeError) << "Failed to change bluetooth pairing: " << ret;
-
-       INFO(VIST_PLUGIN) << "Bluetooth pairing state is changed to " << enable;
-}
-
-void Tethering::onChanged(const PolicyValue& value)
-{
-       auto enable = value;
-       INFO(VIST_PLUGIN) << "Bluetooth tethering state is changed to " << enable;
-}
-
-Bluetooth::Bluetooth(const std::string& name) : PolicyProvider(name)
-{
-       if (::bt_initialize() != BT_ERROR_NONE)
-               THROW(ErrCode::RuntimeError) << "Failed to init bluetooth provider.";
-}
-
-Bluetooth::~Bluetooth()
-{
-       ::bt_deinitialize();
-}
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/table/policy/bluetooth/policy.hpp b/src/vist/table/policy/bluetooth/policy.hpp
deleted file mode 100644 (file)
index 3c927df..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#pragma once
-
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-provider.hpp>
-#include <vist/sdk/policy-value.hpp>
-
-namespace vist {
-namespace policy {
-
-class BluetoothState : public PolicyModel {
-public:
-       BluetoothState() : PolicyModel("bluetooth", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class DesktopConnectivity : public PolicyModel {
-public:
-       DesktopConnectivity() : PolicyModel("bluetooth-desktop-connectivity", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class Pairing: public PolicyModel {
-public:
-       Pairing() : PolicyModel("bluetooth-pairing", PolicyValue(1)) {}
-       void onChanged(const PolicyValue& value) override;
-};
-
-class Tethering: public PolicyModel {
-public:
-       Tethering() : PolicyModel("bluetooth-tethering", PolicyValue(1)) {}
-       void onChanged(const PolicyValue&);
-};
-
-class Bluetooth final : public PolicyProvider {
-public:
-       Bluetooth(const std::string& name);
-       ~Bluetooth();
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/table/policy/bluetooth/table.cpp b/src/vist/table/policy/bluetooth/table.cpp
deleted file mode 100644 (file)
index 6bedb72..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "policy.hpp"
-#include "table.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
-#include <vist/policy/api.hpp>
-#include <vist/table/builder.hpp>
-#include <vist/table/parser.hpp>
-#include <vist/table/util.hpp>
-
-extern "C" vist::table::DynamicTable* DynamicTableFactory()
-{
-       return new vist::table::BluetoothTable;
-}
-
-namespace vist {
-namespace table {
-
-namespace {
-
-std::map<std::string, std::string> ALIAS = {
-       { "state", "bluetooth" },
-       { "desktopConnectivity", "bluetooth-desktop-connectivity" },
-       { "pairing", "bluetooth-pairing" },
-       { "tethering", "bluetooth-tethering"}
-};
-
-void setPolicy(const std::string& name, int value)
-{
-       vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(value));
-}
-
-} // anonymous namespace
-
-void BluetoothTable::init()
-{
-       Builder::table<BluetoothTable>("bluetooth");
-
-       auto provider = std::make_shared<policy::Bluetooth>("bluetooth");
-       provider->add(std::make_shared<policy::BluetoothState>());
-       provider->add(std::make_shared<policy::DesktopConnectivity>());
-       provider->add(std::make_shared<policy::Pairing>());
-       provider->add(std::make_shared<policy::Tethering>());
-
-       policy::API::Admin::AddProvider(provider);
-
-       INFO(VIST_PLUGIN) << "Bluetooth plugin loaded.";
-}
-
-TableColumns BluetoothTable::columns() const
-{
-       return {
-               Builder::column<int>("state"),
-               Builder::column<int>("desktopConnectivity"),
-               Builder::column<int>("pairing"),
-               Builder::column<int>("tethering")
-       };
-}
-
-QueryData BluetoothTable::select(QueryContext&)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Select query about bluetooth table.";
-
-       Row row;
-       for (const auto& [schemaName, policyName] : ALIAS) {
-               int value = vist::policy::API::Get(policyName);
-               row[schemaName] = std::to_string(value);
-       }
-
-       QueryData results;
-       results.emplace_back(std::move(row));
-
-       return results;
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-QueryData BluetoothTable::update(QueryContext&, const PluginRequest& request)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Update query about bluetooth table.";
-
-       /// TODO(Sangwan): Sync vtab schema with policy definition
-       setPolicy("bluetooth", Parser::column<int>(request, 0));
-       setPolicy("bluetooth-desktop-connectivity", Parser::column<int>(request, 1));
-       setPolicy("bluetooth-pairing", Parser::column<int>(request, 2));
-       setPolicy("bluetooth-tethering", Parser::column<int>(request, 3));
-
-       return success();
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-} // namespace table
-} // namespace vist
diff --git a/src/vist/table/policy/bluetooth/table.hpp b/src/vist/table/policy/bluetooth/table.hpp
deleted file mode 100644 (file)
index 0acfde2..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-/*
- * Query example
- * - SELECT * FROM bluetooth
- * - UPDATE bluetooth SET state = 1 // enable
- * - UPDATE bluetooth SET state = 0 // disable
- */
-
-#include <vist/table/dynamic-table.hpp>
-
-namespace vist {
-namespace table {
-
-class BluetoothTable final : public DynamicTable {
-public:
-       void init();
-
-private:
-       TableColumns columns() const override;
-       QueryData select(QueryContext&) override;
-       QueryData update(QueryContext&, const PluginRequest& request) override;
-};
-
-} // namespace table
-} // namespace vist
diff --git a/src/vist/table/policy/bluetooth/tests/bluetooth.cpp b/src/vist/table/policy/bluetooth/tests/bluetooth.cpp
deleted file mode 100644 (file)
index d682805..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "../policy.hpp"
-
-#include <vist/client/query.hpp>
-#include <vist/exception.hpp>
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-value.hpp>
-
-#include <iostream>
-
-#include <gtest/gtest.h>
-
-using namespace vist;
-using namespace vist::policy;
-
-namespace {
-
-template <typename T>
-void change_policy_state()
-{
-       std::shared_ptr<PolicyModel> policy = std::make_shared<T>();
-       /// enable policy
-       policy->onChanged(PolicyValue(1));
-       /// disable policy
-       policy->onChanged(PolicyValue(0));
-}
-
-} // anonymous namespace
-
-TEST(BluetoothTests, change_policy_state)
-{
-       try {
-               change_policy_state<BluetoothState>();
-               change_policy_state<DesktopConnectivity>();
-               change_policy_state<Pairing>();
-               change_policy_state<Tethering>();
-       } catch(const vist::Exception<ErrCode>& e) {
-               EXPECT_TRUE(false) << e.what();
-       }
-}
-
-TEST(BluetoothTests, get_policies)
-{
-       auto rows = Query::Execute("SELECT * FROM bluetooth");
-
-       EXPECT_TRUE(rows.size() == 1);
-}
-
-TEST(BluetoothTests, set_policies)
-{
-       // Binany should be enrolled as admin to control policy.
-       Query::Execute("INSERT INTO policy_admin (name) VALUES ('vist-bluetooth-policy-test')");
-
-       Query::Execute("UPDATE bluetooth SET desktopConnectivity = 3, state = 7");
-       Query::Execute("UPDATE bluetooth SET pairing = 2, tethering = 9");
-
-       auto rows = Query::Execute("SELECT * FROM bluetooth");
-       if (rows.size() == 1) {
-               EXPECT_EQ(rows[0]["state"], "7");
-               EXPECT_EQ(rows[0]["desktopConnectivity"], "3");
-               EXPECT_EQ(rows[0]["pairing"], "2");
-               EXPECT_EQ(rows[0]["tethering"], "9");
-       } else {
-               EXPECT_TRUE(false);
-       }
-
-       Query::Execute("DELETE FROM policy_admin WHERE name = 'vist-bluetooth-policy-test'");
-}
diff --git a/src/vist/table/policy/policy-admin.cpp b/src/vist/table/policy/policy-admin.cpp
deleted file mode 100644 (file)
index 55179b4..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "policy-admin.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
-#include <vist/policy/api.hpp>
-#include <vist/table/builder.hpp>
-#include <vist/table/parser.hpp>
-#include <vist/table/util.hpp>
-
-namespace vist {
-namespace table {
-
-namespace {
-
-std::string removeAlias(std::string&& alias)
-{
-       auto pos = alias.find(";");
-       auto token = alias.substr(0, pos);
-
-       if (token == "name")
-               return alias.erase(0, pos + 1);
-       else
-               return std::string();
-}
-
-} // anonymous namespace
-
-void PolicyAdminTable::Init()
-{
-       Builder::table<PolicyAdminTable>("policy_admin");
-}
-
-TableColumns PolicyAdminTable::columns() const
-{
-       return {
-               Builder::column<std::string>("name"),
-               Builder::column<int>("activated"),
-       };
-}
-
-QueryData PolicyAdminTable::select(QueryContext& context)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Select query about policy-admin table.";
-
-       QueryData results;
-       auto admins = vist::policy::API::Admin::GetAll();
-
-       for (auto& admin : admins) {
-               if (context.constraints["name"].exists(EQUALS)) { /// where clause
-                       auto names = context.constraints["name"].getAll(EQUALS);
-                       for (const auto& name : names) {
-                               if (name == admin.first) {
-                                       Row row;
-                                       row["name"] = admin.first;
-                                       row["activated"] = std::to_string(admin.second);
-
-                                       DEBUG(VIST) << "Admin info [name]: " << row["name"]
-                                                               << ", [activated]:" << row["activated"];
-
-                                       results.emplace_back(std::move(row));
-                               }
-                       }
-               } else { /// select *;
-                       Row row;
-                       row["name"] = admin.first;
-                       row["activated"] = std::to_string(admin.second);
-
-                       DEBUG(VIST) << "Admin info [name]: " << row["name"]
-                                               << ", [activated]:" << row["activated"];
-                       results.emplace_back(std::move(row));
-               }
-       }
-
-       return results;
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-QueryData PolicyAdminTable::insert(QueryContext&, const PluginRequest& request)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Insert query about policy-admin table.";
-       auto admin = Parser::column<std::string>(request, 0);
-
-       DEBUG(VIST) << "Admin info [name]: " << admin;
-       vist::policy::API::Admin::Enroll(admin);
-
-       return success();
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-QueryData PolicyAdminTable::delete_(QueryContext&, const PluginRequest& request)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Delete query about policy-admin table.";
-       auto admin = removeAlias(Parser::column<std::string>(request, 0));
-
-       DEBUG(VIST) << "Admin info [name]: " << admin;
-       vist::policy::API::Admin::Disenroll(admin);
-
-       return success();
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-QueryData PolicyAdminTable::update(QueryContext&, const PluginRequest& request)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Update query about policy-admin table.";
-
-       auto name = Parser::column<std::string>(request, 0);
-       auto activated = Parser::column<int>(request, 1);
-
-       vist::policy::API::Admin::Activate(name, activated);
-
-       return success();
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-} // namespace tables
-} // namespace osquery
diff --git a/src/vist/table/policy/policy-admin.hpp b/src/vist/table/policy/policy-admin.hpp
deleted file mode 100644 (file)
index 6112f8c..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include <osquery/tables.h>
-
-namespace vist {
-namespace table {
-
-using namespace osquery;
-
-class PolicyAdminTable final : public TablePlugin {
-public:
-       static void Init();
-
-private:
-       TableColumns columns() const override;
-       QueryData select(QueryContext&) override;
-       QueryData delete_(QueryContext&, const PluginRequest& request) override;
-       QueryData insert(QueryContext&, const PluginRequest& request) override;
-       QueryData update(QueryContext&, const PluginRequest& request) override;
-};
-
-} // namespace table
-} // namespace vist
diff --git a/src/vist/table/policy/policy.cpp b/src/vist/table/policy/policy.cpp
deleted file mode 100644 (file)
index e3526a5..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "policy.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
-#include <vist/policy/api.hpp>
-#include <vist/table/builder.hpp>
-#include <vist/table/parser.hpp>
-#include <vist/table/util.hpp>
-
-#include <memory>
-#include <stdexcept>
-#include <string>
-
-namespace vist {
-namespace table {
-
-namespace {
-
-Row convert(const std::string& name, const vist::policy::PolicyValue& value)
-{
-       Row r;
-       r["name"] = name;
-       r["value"] = value.dump();
-
-       return r;
-}
-
-} // anonymous namespace
-
-void PolicyTable::Init()
-{
-       Builder::table<PolicyTable>("policy");
-}
-
-TableColumns PolicyTable::columns() const
-{
-       return {
-               Builder::column<std::string>("name"),
-               Builder::column<std::string>("value")
-       };
-}
-
-QueryData PolicyTable::select(QueryContext& context)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Select query about policy table.";
-
-       QueryData results;
-       if (context.constraints["name"].exists(EQUALS)) { /// where clause
-               auto names = context.constraints["name"].getAll(EQUALS);
-               for (const auto& name : names) {
-                       auto value = vist::policy::API::Get(name);
-                       auto row = convert(name, value);
-
-                       results.emplace_back(std::move(row));
-               }
-       } else { /// select *;
-               auto policies = vist::policy::API::GetAll();
-               for (auto& policy : policies) {
-                       auto row = convert(policy.first, policy.second);
-
-                       results.emplace_back(std::move(row));
-               }
-       }
-
-       return results;
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-QueryData PolicyTable::update(QueryContext&, const PluginRequest& request)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Update query about policy table.";
-
-       auto name = Parser::column<std::string>(request, 0);
-       auto dumpedValue = Parser::column<std::string>(request, 1);
-
-       vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(dumpedValue, true));
-
-       return success();
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-} // namespace table
-} // namespace vist
diff --git a/src/vist/table/policy/policy.hpp b/src/vist/table/policy/policy.hpp
deleted file mode 100644 (file)
index 7bdcd4f..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include <osquery/tables.h>
-
-namespace vist {
-namespace table {
-
-using namespace osquery;
-
-class PolicyTable final : public TablePlugin {
-public:
-       static void Init();
-
-private:
-       TableColumns columns() const override;
-       QueryData select(QueryContext&) override;
-       QueryData update(QueryContext&, const PluginRequest& request) override;
-};
-
-} // namespace table
-} // namespace vist
diff --git a/src/vist/table/policy/sample/CMakeLists.txt b/src/vist/table/policy/sample/CMakeLists.txt
deleted file mode 100644 (file)
index 9a1765a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-SET(TARGET "vist-table-sample")
-
-INCLUDE_DIRECTORIES(SYSTEM)
-
-ADD_LIBRARY(${TARGET} SHARED table.cpp)
-TARGET_LINK_LIBRARIES(${TARGET} vist-common ${TARGET_VIST_POLICY_LIB})
-
-INSTALL(TARGETS ${TARGET} DESTINATION ${TABLE_INSTALL_DIR})
diff --git a/src/vist/table/policy/sample/policy.hpp b/src/vist/table/policy/sample/policy.hpp
deleted file mode 100644 (file)
index b9c309f..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#pragma once
-
-#include <vist/logger.hpp>
-#include <vist/sdk/policy-model.hpp>
-#include <vist/sdk/policy-provider.hpp>
-#include <vist/sdk/policy-value.hpp>
-
-#include <memory>
-#include <string>
-
-namespace vist {
-namespace policy {
-
-class SampleIntPolicy : public PolicyModel {
-public:
-       SampleIntPolicy() : PolicyModel("sample_int_policy", PolicyValue(7))
-       {
-       }
-
-       void onChanged(const PolicyValue& value) override
-       {
-               INFO(VIST_PLUGIN) << "sample_int_policy is changed to "
-                                                 << static_cast<int>(value);
-       }
-};
-
-class SampleStrPolicy : public PolicyModel {
-public:
-       SampleStrPolicy() : PolicyModel("sample_str_policy", PolicyValue("TEST"))
-       {
-       }
-
-       void onChanged(const PolicyValue& value) override
-       {
-               INFO(VIST_PLUGIN) << "sample_str_policy is changed to "
-                                                 << static_cast<std::string>(value);
-       }
-
-       int compare(const PolicyValue& lhs, const PolicyValue& rhs) const override
-       {
-               std::string lvalue = lhs;
-               std::string rvalue = rhs;
-
-               INFO(VIST_PLUGIN) << "Custom compare method is called with [" << lvalue
-                                                 << "], [" << rvalue << "]";
-
-               return lvalue.compare(rvalue);
-       }
-};
-
-class SampleProvider : public PolicyProvider {
-public:
-       SampleProvider(const std::string& name) : PolicyProvider(name)
-       {
-       }
-
-       ~SampleProvider()
-       {
-       }
-};
-
-} // namespace policy
-} // namespace vist
diff --git a/src/vist/table/policy/sample/table.cpp b/src/vist/table/policy/sample/table.cpp
deleted file mode 100644 (file)
index cdab50c..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-
-#include "policy.hpp"
-#include "table.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
-#include <vist/policy/api.hpp>
-#include <vist/table/builder.hpp>
-#include <vist/table/parser.hpp>
-#include <vist/table/util.hpp>
-
-extern "C" vist::table::DynamicTable* DynamicTableFactory()
-{
-       return new vist::table::SamplePolicyTable;
-}
-
-namespace vist {
-namespace table {
-
-void SamplePolicyTable::init()
-{
-       Builder::table<SamplePolicyTable>("sample_policy");
-
-       // Register policy to policy-manager
-       using namespace policy;
-       auto provider = std::make_shared<SampleProvider>("sample-provider");
-       provider->add(std::make_shared<SampleIntPolicy>());
-       provider->add(std::make_shared<SampleStrPolicy>());
-
-       policy::API::Admin::AddProvider(std::move(provider));
-
-       INFO(VIST_PLUGIN) << "Sample plugin loaded.";
-}
-
-TableColumns SamplePolicyTable::columns() const
-{
-       return {
-               Builder::column<int>("sample_int_policy"),
-               Builder::column<std::string>("sample_str_policy")
-       };
-}
-
-QueryData SamplePolicyTable::select(QueryContext&)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Select query about sample-policy table.";
-
-       Row row;
-       int intPolicy = vist::policy::API::Get("sample_int_policy");
-       row["sample_int_policy"] = std::to_string(intPolicy);
-
-       std::string strPolicy = vist::policy::API::Get("sample_str_policy");
-       row["sample_str_policy"] = strPolicy;
-
-       QueryData results;
-       results.emplace_back(std::move(row));
-
-       return results;
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-QueryData SamplePolicyTable::update(QueryContext&, const PluginRequest& request)
-{
-       TABLE_EXCEPTION_GUARD_START
-
-       INFO(VIST) << "Update query about sample-policy table.";
-
-       auto intPolicy = Parser::column<int>(request, 0);
-       auto strPolicy = Parser::column<std::string>(request, 1);
-
-       policy::API::Admin::Set("sample_int_policy", policy::PolicyValue(intPolicy));
-       policy::API::Admin::Set("sample_str_policy", policy::PolicyValue(strPolicy));
-
-       return success();
-
-       TABLE_EXCEPTION_GUARD_END
-}
-
-} // namespace table
-} // namespace vist
diff --git a/src/vist/table/policy/sample/table.hpp b/src/vist/table/policy/sample/table.hpp
deleted file mode 100644 (file)
index e66e862..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License
- */
-/*
- * Query example
- * - SELECT * FROM sample_policy
- * - UPDATE sample_policy SET sample_int_policy = 99
- * - UPDATE sample_policy SET sample_str_policy = 'TEST_VALUE'
- */
-
-#include <vist/logger.hpp>
-#include <vist/table/dynamic-table.hpp>
-
-namespace vist {
-namespace table {
-
-class SamplePolicyTable final : public DynamicTable {
-public:
-       void init();
-
-private:
-       TableColumns columns() const override;
-       QueryData select(QueryContext&) override;
-       QueryData update(QueryContext&, const PluginRequest& request) override;
-};
-
-} // namespace table
-} // namespace vist
diff --git a/tables/CMakeLists.txt b/tables/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7430534
--- /dev/null
@@ -0,0 +1,21 @@
+#  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License
+
+ADD_SUBDIRECTORY(policy/sample)
+
+IF(DEFINED GBS_BUILD)
+       ADD_SUBDIRECTORY(policy/bluetooth)
+ENDIF(DEFINED GBS_BUILD)
+
+# TODO: Add built-in table's TC
diff --git a/tables/built-in/policy-admin.cpp b/tables/built-in/policy-admin.cpp
new file mode 100644 (file)
index 0000000..55179b4
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "policy-admin.hpp"
+
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
+#include <vist/policy/api.hpp>
+#include <vist/table/builder.hpp>
+#include <vist/table/parser.hpp>
+#include <vist/table/util.hpp>
+
+namespace vist {
+namespace table {
+
+namespace {
+
+std::string removeAlias(std::string&& alias)
+{
+       auto pos = alias.find(";");
+       auto token = alias.substr(0, pos);
+
+       if (token == "name")
+               return alias.erase(0, pos + 1);
+       else
+               return std::string();
+}
+
+} // anonymous namespace
+
+void PolicyAdminTable::Init()
+{
+       Builder::table<PolicyAdminTable>("policy_admin");
+}
+
+TableColumns PolicyAdminTable::columns() const
+{
+       return {
+               Builder::column<std::string>("name"),
+               Builder::column<int>("activated"),
+       };
+}
+
+QueryData PolicyAdminTable::select(QueryContext& context)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Select query about policy-admin table.";
+
+       QueryData results;
+       auto admins = vist::policy::API::Admin::GetAll();
+
+       for (auto& admin : admins) {
+               if (context.constraints["name"].exists(EQUALS)) { /// where clause
+                       auto names = context.constraints["name"].getAll(EQUALS);
+                       for (const auto& name : names) {
+                               if (name == admin.first) {
+                                       Row row;
+                                       row["name"] = admin.first;
+                                       row["activated"] = std::to_string(admin.second);
+
+                                       DEBUG(VIST) << "Admin info [name]: " << row["name"]
+                                                               << ", [activated]:" << row["activated"];
+
+                                       results.emplace_back(std::move(row));
+                               }
+                       }
+               } else { /// select *;
+                       Row row;
+                       row["name"] = admin.first;
+                       row["activated"] = std::to_string(admin.second);
+
+                       DEBUG(VIST) << "Admin info [name]: " << row["name"]
+                                               << ", [activated]:" << row["activated"];
+                       results.emplace_back(std::move(row));
+               }
+       }
+
+       return results;
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+QueryData PolicyAdminTable::insert(QueryContext&, const PluginRequest& request)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Insert query about policy-admin table.";
+       auto admin = Parser::column<std::string>(request, 0);
+
+       DEBUG(VIST) << "Admin info [name]: " << admin;
+       vist::policy::API::Admin::Enroll(admin);
+
+       return success();
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+QueryData PolicyAdminTable::delete_(QueryContext&, const PluginRequest& request)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Delete query about policy-admin table.";
+       auto admin = removeAlias(Parser::column<std::string>(request, 0));
+
+       DEBUG(VIST) << "Admin info [name]: " << admin;
+       vist::policy::API::Admin::Disenroll(admin);
+
+       return success();
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+QueryData PolicyAdminTable::update(QueryContext&, const PluginRequest& request)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Update query about policy-admin table.";
+
+       auto name = Parser::column<std::string>(request, 0);
+       auto activated = Parser::column<int>(request, 1);
+
+       vist::policy::API::Admin::Activate(name, activated);
+
+       return success();
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+} // namespace tables
+} // namespace osquery
diff --git a/tables/built-in/policy-admin.hpp b/tables/built-in/policy-admin.hpp
new file mode 100644 (file)
index 0000000..6112f8c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <osquery/tables.h>
+
+namespace vist {
+namespace table {
+
+using namespace osquery;
+
+class PolicyAdminTable final : public TablePlugin {
+public:
+       static void Init();
+
+private:
+       TableColumns columns() const override;
+       QueryData select(QueryContext&) override;
+       QueryData delete_(QueryContext&, const PluginRequest& request) override;
+       QueryData insert(QueryContext&, const PluginRequest& request) override;
+       QueryData update(QueryContext&, const PluginRequest& request) override;
+};
+
+} // namespace table
+} // namespace vist
diff --git a/tables/built-in/policy.cpp b/tables/built-in/policy.cpp
new file mode 100644 (file)
index 0000000..e3526a5
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "policy.hpp"
+
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
+#include <vist/policy/api.hpp>
+#include <vist/table/builder.hpp>
+#include <vist/table/parser.hpp>
+#include <vist/table/util.hpp>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+
+namespace vist {
+namespace table {
+
+namespace {
+
+Row convert(const std::string& name, const vist::policy::PolicyValue& value)
+{
+       Row r;
+       r["name"] = name;
+       r["value"] = value.dump();
+
+       return r;
+}
+
+} // anonymous namespace
+
+void PolicyTable::Init()
+{
+       Builder::table<PolicyTable>("policy");
+}
+
+TableColumns PolicyTable::columns() const
+{
+       return {
+               Builder::column<std::string>("name"),
+               Builder::column<std::string>("value")
+       };
+}
+
+QueryData PolicyTable::select(QueryContext& context)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Select query about policy table.";
+
+       QueryData results;
+       if (context.constraints["name"].exists(EQUALS)) { /// where clause
+               auto names = context.constraints["name"].getAll(EQUALS);
+               for (const auto& name : names) {
+                       auto value = vist::policy::API::Get(name);
+                       auto row = convert(name, value);
+
+                       results.emplace_back(std::move(row));
+               }
+       } else { /// select *;
+               auto policies = vist::policy::API::GetAll();
+               for (auto& policy : policies) {
+                       auto row = convert(policy.first, policy.second);
+
+                       results.emplace_back(std::move(row));
+               }
+       }
+
+       return results;
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+QueryData PolicyTable::update(QueryContext&, const PluginRequest& request)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Update query about policy table.";
+
+       auto name = Parser::column<std::string>(request, 0);
+       auto dumpedValue = Parser::column<std::string>(request, 1);
+
+       vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(dumpedValue, true));
+
+       return success();
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+} // namespace table
+} // namespace vist
diff --git a/tables/built-in/policy.hpp b/tables/built-in/policy.hpp
new file mode 100644 (file)
index 0000000..7bdcd4f
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <osquery/tables.h>
+
+namespace vist {
+namespace table {
+
+using namespace osquery;
+
+class PolicyTable final : public TablePlugin {
+public:
+       static void Init();
+
+private:
+       TableColumns columns() const override;
+       QueryData select(QueryContext&) override;
+       QueryData update(QueryContext&, const PluginRequest& request) override;
+};
+
+} // namespace table
+} // namespace vist
diff --git a/tables/policy/bluetooth/CMakeLists.txt b/tables/policy/bluetooth/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d5685bc
--- /dev/null
@@ -0,0 +1,51 @@
+# Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+SET(TARGET "vist-bluetooth-policy")
+SET(TARGET_TEST ${TARGET}-test)
+
+SET(DEPENDENCY bluetooth-api
+                          capi-network-bluetooth)
+
+PKG_CHECK_MODULES(PLUGIN_DEPS REQUIRED ${DEPENDENCY})
+
+INCLUDE_DIRECTORIES(SYSTEM ${PLUGIN_DEPS_INCLUDE_DIRS})
+
+## LIB ###########################################
+ADD_LIBRARY(${TARGET} SHARED policy.cpp table.cpp)
+TARGET_LINK_LIBRARIES(${TARGET} ${PLUGIN_DEPS_LIBRARIES}
+                                                               ${TARGET_VIST_COMMON_LIB}
+                                                               ${TARGET_VIST_POLICY_LIB})
+
+INSTALL(TARGETS ${TARGET} DESTINATION ${TABLE_INSTALL_DIR})
+
+## TEST #############################################
+ADD_EXECUTABLE(${TARGET_TEST} ${VIST_SRCS}/main/tests.cpp
+                                                         policy.cpp
+                                                         table.cpp
+                                                         tests/bluetooth.cpp)
+TARGET_LINK_LIBRARIES(${TARGET_TEST} ${PLUGIN_DEPS_LIBRARIES}
+                                                                        ${TARGET_VIST_CLIENT_LIB}
+                                                                        ${TARGET_VIST_LIB}
+                                                                        gtest
+                                                                        pthread)
+INSTALL(TARGETS ${TARGET_TEST}
+               DESTINATION ${CMAKE_INSTALL_BINDIR}
+               PERMISSIONS OWNER_READ
+                                       OWNER_WRITE
+                                       OWNER_EXECUTE
+                                       GROUP_READ
+                                       GROUP_EXECUTE
+                                       WORLD_READ
+                                       WORLD_EXECUTE)
diff --git a/tables/policy/bluetooth/policy.cpp b/tables/policy/bluetooth/policy.cpp
new file mode 100644 (file)
index 0000000..49ba0b4
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "policy.hpp"
+
+#include <vist/logger.hpp>
+#include <vist/exception.hpp>
+
+#include <bluetooth.h>
+#include <bluetooth-api.h>
+#include <bluetooth_internal.h>
+
+namespace vist {
+namespace policy {
+
+namespace {
+
+bool failed(int value)
+{
+       return value == BLUETOOTH_DPM_RESULT_ACCESS_DENIED || value == BLUETOOTH_DPM_RESULT_FAIL;
+}
+
+auto allowed(int value)
+{
+       return value ? BLUETOOTH_DPM_ALLOWED : BLUETOOTH_DPM_RESTRICTED;
+}
+
+auto bt_allowed(int value)
+{
+       return value ? BLUETOOTH_DPM_BT_ALLOWED : BLUETOOTH_DPM_BT_RESTRICTED;
+}
+
+} // anonymous namespace
+
+void BluetoothState::onChanged(const PolicyValue& value)
+{
+       auto enable = bt_allowed(value);
+       auto ret = ::bluetooth_dpm_set_allow_mode(enable);
+       if (failed(ret))
+               THROW(ErrCode::RuntimeError) << "Failed to change bluetooth state: " << ret;
+
+       INFO(VIST_PLUGIN) << "Bluetooth state is changed to " << enable;
+}
+
+void DesktopConnectivity::onChanged(const PolicyValue& value)
+{
+       auto enable = allowed(value);
+       auto ret = ::bluetooth_dpm_set_desktop_connectivity_state(enable);
+       if (failed(ret))
+               THROW(ErrCode::RuntimeError) << "Failed to change bt_desktop_connectivity: " << ret;
+
+       INFO(VIST_PLUGIN) << "Bluetooth desktop connectivity state is changed to " << enable;
+}
+
+void Pairing::onChanged(const PolicyValue& value)
+{
+       auto enable = allowed(value);
+       auto ret = ::bluetooth_dpm_set_pairing_state(enable);
+       if (failed(ret))
+               THROW(ErrCode::RuntimeError) << "Failed to change bluetooth pairing: " << ret;
+
+       INFO(VIST_PLUGIN) << "Bluetooth pairing state is changed to " << enable;
+}
+
+void Tethering::onChanged(const PolicyValue& value)
+{
+       auto enable = value;
+       INFO(VIST_PLUGIN) << "Bluetooth tethering state is changed to " << enable;
+}
+
+Bluetooth::Bluetooth(const std::string& name) : PolicyProvider(name)
+{
+       if (::bt_initialize() != BT_ERROR_NONE)
+               THROW(ErrCode::RuntimeError) << "Failed to init bluetooth provider.";
+}
+
+Bluetooth::~Bluetooth()
+{
+       ::bt_deinitialize();
+}
+
+} // namespace policy
+} // namespace vist
diff --git a/tables/policy/bluetooth/policy.hpp b/tables/policy/bluetooth/policy.hpp
new file mode 100644 (file)
index 0000000..3c927df
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#pragma once
+
+#include <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-provider.hpp>
+#include <vist/sdk/policy-value.hpp>
+
+namespace vist {
+namespace policy {
+
+class BluetoothState : public PolicyModel {
+public:
+       BluetoothState() : PolicyModel("bluetooth", PolicyValue(1)) {}
+       void onChanged(const PolicyValue& value) override;
+};
+
+class DesktopConnectivity : public PolicyModel {
+public:
+       DesktopConnectivity() : PolicyModel("bluetooth-desktop-connectivity", PolicyValue(1)) {}
+       void onChanged(const PolicyValue& value) override;
+};
+
+class Pairing: public PolicyModel {
+public:
+       Pairing() : PolicyModel("bluetooth-pairing", PolicyValue(1)) {}
+       void onChanged(const PolicyValue& value) override;
+};
+
+class Tethering: public PolicyModel {
+public:
+       Tethering() : PolicyModel("bluetooth-tethering", PolicyValue(1)) {}
+       void onChanged(const PolicyValue&);
+};
+
+class Bluetooth final : public PolicyProvider {
+public:
+       Bluetooth(const std::string& name);
+       ~Bluetooth();
+};
+
+} // namespace policy
+} // namespace vist
diff --git a/tables/policy/bluetooth/table.cpp b/tables/policy/bluetooth/table.cpp
new file mode 100644 (file)
index 0000000..6bedb72
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "policy.hpp"
+#include "table.hpp"
+
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
+#include <vist/policy/api.hpp>
+#include <vist/table/builder.hpp>
+#include <vist/table/parser.hpp>
+#include <vist/table/util.hpp>
+
+extern "C" vist::table::DynamicTable* DynamicTableFactory()
+{
+       return new vist::table::BluetoothTable;
+}
+
+namespace vist {
+namespace table {
+
+namespace {
+
+std::map<std::string, std::string> ALIAS = {
+       { "state", "bluetooth" },
+       { "desktopConnectivity", "bluetooth-desktop-connectivity" },
+       { "pairing", "bluetooth-pairing" },
+       { "tethering", "bluetooth-tethering"}
+};
+
+void setPolicy(const std::string& name, int value)
+{
+       vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(value));
+}
+
+} // anonymous namespace
+
+void BluetoothTable::init()
+{
+       Builder::table<BluetoothTable>("bluetooth");
+
+       auto provider = std::make_shared<policy::Bluetooth>("bluetooth");
+       provider->add(std::make_shared<policy::BluetoothState>());
+       provider->add(std::make_shared<policy::DesktopConnectivity>());
+       provider->add(std::make_shared<policy::Pairing>());
+       provider->add(std::make_shared<policy::Tethering>());
+
+       policy::API::Admin::AddProvider(provider);
+
+       INFO(VIST_PLUGIN) << "Bluetooth plugin loaded.";
+}
+
+TableColumns BluetoothTable::columns() const
+{
+       return {
+               Builder::column<int>("state"),
+               Builder::column<int>("desktopConnectivity"),
+               Builder::column<int>("pairing"),
+               Builder::column<int>("tethering")
+       };
+}
+
+QueryData BluetoothTable::select(QueryContext&)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Select query about bluetooth table.";
+
+       Row row;
+       for (const auto& [schemaName, policyName] : ALIAS) {
+               int value = vist::policy::API::Get(policyName);
+               row[schemaName] = std::to_string(value);
+       }
+
+       QueryData results;
+       results.emplace_back(std::move(row));
+
+       return results;
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+QueryData BluetoothTable::update(QueryContext&, const PluginRequest& request)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Update query about bluetooth table.";
+
+       /// TODO(Sangwan): Sync vtab schema with policy definition
+       setPolicy("bluetooth", Parser::column<int>(request, 0));
+       setPolicy("bluetooth-desktop-connectivity", Parser::column<int>(request, 1));
+       setPolicy("bluetooth-pairing", Parser::column<int>(request, 2));
+       setPolicy("bluetooth-tethering", Parser::column<int>(request, 3));
+
+       return success();
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+} // namespace table
+} // namespace vist
diff --git a/tables/policy/bluetooth/table.hpp b/tables/policy/bluetooth/table.hpp
new file mode 100644 (file)
index 0000000..0acfde2
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * Query example
+ * - SELECT * FROM bluetooth
+ * - UPDATE bluetooth SET state = 1 // enable
+ * - UPDATE bluetooth SET state = 0 // disable
+ */
+
+#include <vist/table/dynamic-table.hpp>
+
+namespace vist {
+namespace table {
+
+class BluetoothTable final : public DynamicTable {
+public:
+       void init();
+
+private:
+       TableColumns columns() const override;
+       QueryData select(QueryContext&) override;
+       QueryData update(QueryContext&, const PluginRequest& request) override;
+};
+
+} // namespace table
+} // namespace vist
diff --git a/tables/policy/bluetooth/tests/bluetooth.cpp b/tables/policy/bluetooth/tests/bluetooth.cpp
new file mode 100644 (file)
index 0000000..d682805
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "../policy.hpp"
+
+#include <vist/client/query.hpp>
+#include <vist/exception.hpp>
+#include <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-value.hpp>
+
+#include <iostream>
+
+#include <gtest/gtest.h>
+
+using namespace vist;
+using namespace vist::policy;
+
+namespace {
+
+template <typename T>
+void change_policy_state()
+{
+       std::shared_ptr<PolicyModel> policy = std::make_shared<T>();
+       /// enable policy
+       policy->onChanged(PolicyValue(1));
+       /// disable policy
+       policy->onChanged(PolicyValue(0));
+}
+
+} // anonymous namespace
+
+TEST(BluetoothTests, change_policy_state)
+{
+       try {
+               change_policy_state<BluetoothState>();
+               change_policy_state<DesktopConnectivity>();
+               change_policy_state<Pairing>();
+               change_policy_state<Tethering>();
+       } catch(const vist::Exception<ErrCode>& e) {
+               EXPECT_TRUE(false) << e.what();
+       }
+}
+
+TEST(BluetoothTests, get_policies)
+{
+       auto rows = Query::Execute("SELECT * FROM bluetooth");
+
+       EXPECT_TRUE(rows.size() == 1);
+}
+
+TEST(BluetoothTests, set_policies)
+{
+       // Binany should be enrolled as admin to control policy.
+       Query::Execute("INSERT INTO policy_admin (name) VALUES ('vist-bluetooth-policy-test')");
+
+       Query::Execute("UPDATE bluetooth SET desktopConnectivity = 3, state = 7");
+       Query::Execute("UPDATE bluetooth SET pairing = 2, tethering = 9");
+
+       auto rows = Query::Execute("SELECT * FROM bluetooth");
+       if (rows.size() == 1) {
+               EXPECT_EQ(rows[0]["state"], "7");
+               EXPECT_EQ(rows[0]["desktopConnectivity"], "3");
+               EXPECT_EQ(rows[0]["pairing"], "2");
+               EXPECT_EQ(rows[0]["tethering"], "9");
+       } else {
+               EXPECT_TRUE(false);
+       }
+
+       Query::Execute("DELETE FROM policy_admin WHERE name = 'vist-bluetooth-policy-test'");
+}
diff --git a/tables/policy/sample/CMakeLists.txt b/tables/policy/sample/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9a1765a
--- /dev/null
@@ -0,0 +1,22 @@
+# Copyright (c) 2019-present Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+SET(TARGET "vist-table-sample")
+
+INCLUDE_DIRECTORIES(SYSTEM)
+
+ADD_LIBRARY(${TARGET} SHARED table.cpp)
+TARGET_LINK_LIBRARIES(${TARGET} vist-common ${TARGET_VIST_POLICY_LIB})
+
+INSTALL(TARGETS ${TARGET} DESTINATION ${TABLE_INSTALL_DIR})
diff --git a/tables/policy/sample/policy.hpp b/tables/policy/sample/policy.hpp
new file mode 100644 (file)
index 0000000..b9c309f
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#pragma once
+
+#include <vist/logger.hpp>
+#include <vist/sdk/policy-model.hpp>
+#include <vist/sdk/policy-provider.hpp>
+#include <vist/sdk/policy-value.hpp>
+
+#include <memory>
+#include <string>
+
+namespace vist {
+namespace policy {
+
+class SampleIntPolicy : public PolicyModel {
+public:
+       SampleIntPolicy() : PolicyModel("sample_int_policy", PolicyValue(7))
+       {
+       }
+
+       void onChanged(const PolicyValue& value) override
+       {
+               INFO(VIST_PLUGIN) << "sample_int_policy is changed to "
+                                                 << static_cast<int>(value);
+       }
+};
+
+class SampleStrPolicy : public PolicyModel {
+public:
+       SampleStrPolicy() : PolicyModel("sample_str_policy", PolicyValue("TEST"))
+       {
+       }
+
+       void onChanged(const PolicyValue& value) override
+       {
+               INFO(VIST_PLUGIN) << "sample_str_policy is changed to "
+                                                 << static_cast<std::string>(value);
+       }
+
+       int compare(const PolicyValue& lhs, const PolicyValue& rhs) const override
+       {
+               std::string lvalue = lhs;
+               std::string rvalue = rhs;
+
+               INFO(VIST_PLUGIN) << "Custom compare method is called with [" << lvalue
+                                                 << "], [" << rvalue << "]";
+
+               return lvalue.compare(rvalue);
+       }
+};
+
+class SampleProvider : public PolicyProvider {
+public:
+       SampleProvider(const std::string& name) : PolicyProvider(name)
+       {
+       }
+
+       ~SampleProvider()
+       {
+       }
+};
+
+} // namespace policy
+} // namespace vist
diff --git a/tables/policy/sample/table.cpp b/tables/policy/sample/table.cpp
new file mode 100644 (file)
index 0000000..cdab50c
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "policy.hpp"
+#include "table.hpp"
+
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
+#include <vist/policy/api.hpp>
+#include <vist/table/builder.hpp>
+#include <vist/table/parser.hpp>
+#include <vist/table/util.hpp>
+
+extern "C" vist::table::DynamicTable* DynamicTableFactory()
+{
+       return new vist::table::SamplePolicyTable;
+}
+
+namespace vist {
+namespace table {
+
+void SamplePolicyTable::init()
+{
+       Builder::table<SamplePolicyTable>("sample_policy");
+
+       // Register policy to policy-manager
+       using namespace policy;
+       auto provider = std::make_shared<SampleProvider>("sample-provider");
+       provider->add(std::make_shared<SampleIntPolicy>());
+       provider->add(std::make_shared<SampleStrPolicy>());
+
+       policy::API::Admin::AddProvider(std::move(provider));
+
+       INFO(VIST_PLUGIN) << "Sample plugin loaded.";
+}
+
+TableColumns SamplePolicyTable::columns() const
+{
+       return {
+               Builder::column<int>("sample_int_policy"),
+               Builder::column<std::string>("sample_str_policy")
+       };
+}
+
+QueryData SamplePolicyTable::select(QueryContext&)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Select query about sample-policy table.";
+
+       Row row;
+       int intPolicy = vist::policy::API::Get("sample_int_policy");
+       row["sample_int_policy"] = std::to_string(intPolicy);
+
+       std::string strPolicy = vist::policy::API::Get("sample_str_policy");
+       row["sample_str_policy"] = strPolicy;
+
+       QueryData results;
+       results.emplace_back(std::move(row));
+
+       return results;
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+QueryData SamplePolicyTable::update(QueryContext&, const PluginRequest& request)
+{
+       TABLE_EXCEPTION_GUARD_START
+
+       INFO(VIST) << "Update query about sample-policy table.";
+
+       auto intPolicy = Parser::column<int>(request, 0);
+       auto strPolicy = Parser::column<std::string>(request, 1);
+
+       policy::API::Admin::Set("sample_int_policy", policy::PolicyValue(intPolicy));
+       policy::API::Admin::Set("sample_str_policy", policy::PolicyValue(strPolicy));
+
+       return success();
+
+       TABLE_EXCEPTION_GUARD_END
+}
+
+} // namespace table
+} // namespace vist
diff --git a/tables/policy/sample/table.hpp b/tables/policy/sample/table.hpp
new file mode 100644 (file)
index 0000000..e66e862
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+/*
+ * Query example
+ * - SELECT * FROM sample_policy
+ * - UPDATE sample_policy SET sample_int_policy = 99
+ * - UPDATE sample_policy SET sample_str_policy = 'TEST_VALUE'
+ */
+
+#include <vist/logger.hpp>
+#include <vist/table/dynamic-table.hpp>
+
+namespace vist {
+namespace table {
+
+class SamplePolicyTable final : public DynamicTable {
+public:
+       void init();
+
+private:
+       TableColumns columns() const override;
+       QueryData select(QueryContext&) override;
+       QueryData update(QueryContext&, const PluginRequest& request) override;
+};
+
+} // namespace table
+} // namespace vist