From: Sangwan Kwon Date: Mon, 13 Jan 2020 09:01:25 +0000 (+0900) Subject: Add ServiceType to rmi::Gateway X-Git-Tag: submit/tizen/20200810.073515~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06dc2a068b7b8fb06911d14340c74be3166935ed;p=platform%2Fcore%2Fsecurity%2Fvist.git Add ServiceType to rmi::Gateway Signed-off-by: Sangwan Kwon --- diff --git a/packaging/vist-plugins.manifest b/packaging/vist-plugins.manifest index 017d22d..97e8c31 100644 --- a/packaging/vist-plugins.manifest +++ b/packaging/vist-plugins.manifest @@ -1,5 +1,5 @@ - - - + + + diff --git a/packaging/vist-test.manifest b/packaging/vist-test.manifest new file mode 100644 index 0000000..d2c3009 --- /dev/null +++ b/packaging/vist-test.manifest @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/packaging/vist.manifest b/packaging/vist.manifest index 017d22d..97e8c31 100644 --- a/packaging/vist.manifest +++ b/packaging/vist.manifest @@ -1,5 +1,5 @@ - - - + + + diff --git a/packaging/vist.spec b/packaging/vist.spec index 9e0b2f8..2d31756 100644 --- a/packaging/vist.spec +++ b/packaging/vist.spec @@ -108,8 +108,8 @@ fi %license LICENSE-Apache-2.0 %license LICENSE-GPL-2.0 %license LICENSE-MIT -%{_bindir}/vist-cli -%{_bindir}/vistd +%attr(-, %{user_name}, %{group_name}) %{_bindir}/vist-cli +%attr(-, %{user_name}, %{group_name}) %{_bindir}/vistd %{_libdir}/libvist-rmi.so %{_unitdir}/vist.service %{_unitdir}/vist.socket @@ -130,11 +130,12 @@ Requires: gtest Provides internal testcases for ViST implementation. %files test +%manifest packaging/%{name}-test.manifest %{_bindir}/osquery-test -%{_bindir}/vist-test -%{vist_plugin_dir}/sample +%attr(4755 %{user_name}, %{group_name}) %{_bindir}/vist-test +%dir %attr(-, %{user_name}, %{group_name}) %{vist_plugin_dir}/sample -## ViST Plugins - ########################################################### +## ViST Plugins ############################################################# %package plugins Summary: Virtaul Security Table (policy modules) Group: Security/Other diff --git a/src/vist/CMakeLists.txt b/src/vist/CMakeLists.txt index 5bab769..b9055a3 100644 --- a/src/vist/CMakeLists.txt +++ b/src/vist/CMakeLists.txt @@ -62,7 +62,7 @@ IF(DEFINED GBS_BUILD) TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} ${VIST_COMMON_DEPS_LIBRARIES} pthread glog gflags boost_system) ELSE(DEFINED GBS_BUILD) - TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} pthread glog gflags boost_system) + TARGET_LINK_LIBRARIES(${TARGET_VIST_COMMON_LIB} pthread glog gflags boost_system systemd) ENDIF(DEFINED GBS_BUILD) ADD_LIBRARY(${TARGET_VIST_LIB} STATIC ${${TARGET_VIST_LIB}_SRCS}) diff --git a/src/vist/rmi/gateway.cpp b/src/vist/rmi/gateway.cpp index 801f6a5..5ecc9ec 100644 --- a/src/vist/rmi/gateway.cpp +++ b/src/vist/rmi/gateway.cpp @@ -19,12 +19,8 @@ #include #include #include - -#ifdef TIZEN -#include -#else #include -#endif +#include #include #include @@ -36,7 +32,7 @@ using namespace vist::rmi::impl; class Gateway::Impl { public: - explicit Impl(Gateway& gateway, const std::string& path) + explicit Impl(Gateway& gateway, const std::string& path, Gateway::ServiceType type) { auto dispatcher = [&gateway](auto& message) -> Message { std::string function = message.signature; @@ -55,11 +51,15 @@ public: return reply; }; -#ifdef TIZEN - this->server = std::make_unique(path, dispatcher); -#else - this->server = std::make_unique(path, dispatcher); -#endif + switch (type) { + case ServiceType::OnDemand: + this->server = std::make_unique(path, dispatcher); + break; + case ServiceType::General: /// fall through + default: + this->server = std::make_unique(path, dispatcher); + break; + } } inline void start(int timeout, std::function stopper) @@ -76,7 +76,8 @@ private: std::unique_ptr server; }; -Gateway::Gateway(const std::string& path) : pImpl(std::make_unique(*this, path)) +Gateway::Gateway(const std::string& path, ServiceType type) : + pImpl(std::make_unique(*this, path, type)) { } diff --git a/src/vist/rmi/gateway.hpp b/src/vist/rmi/gateway.hpp index bef6b19..d63a816 100644 --- a/src/vist/rmi/gateway.hpp +++ b/src/vist/rmi/gateway.hpp @@ -30,7 +30,12 @@ namespace rmi { class VIST_API Gateway final { public: - explicit Gateway(const std::string& path); + enum class ServiceType { + General, + OnDemand + }; + + explicit Gateway(const std::string& path, ServiceType type = ServiceType::General); ~Gateway(); Gateway(const Gateway&) = delete; diff --git a/src/vist/rmi/impl/general/tests/server-client.cpp b/src/vist/rmi/impl/general/tests/server-client.cpp index b8e0407..eae2494 100644 --- a/src/vist/rmi/impl/general/tests/server-client.cpp +++ b/src/vist/rmi/impl/general/tests/server-client.cpp @@ -45,6 +45,7 @@ std::string response3 = "response argument"; } // anonymous namespace +#ifndef TIZEN TEST(ServerClientTests, server) { std::string sockPath = "vist-test.sock"; @@ -100,3 +101,4 @@ TEST(ServerClientTests, server) if (serverThread.joinable()) serverThread.join(); } +#endif diff --git a/src/vist/rmi/impl/ondemand/server.hpp b/src/vist/rmi/impl/ondemand/server.hpp index 154bb10..9b90015 100644 --- a/src/vist/rmi/impl/ondemand/server.hpp +++ b/src/vist/rmi/impl/ondemand/server.hpp @@ -20,10 +20,7 @@ #include #include #include - -#ifdef TIZEN #include -#endif #include #include @@ -43,11 +40,7 @@ class Server : public interface::Server { public: Server(const std::string& path, const interface::Task& task) : interface::Server(path, task), -#ifdef TIZEN socket(SystemdSocket::Create(path)) -#else - socket(path) -#endif { this->accept(task); } diff --git a/src/vist/rmi/impl/ondemand/tests/server-client.cpp b/src/vist/rmi/impl/ondemand/tests/server-client.cpp deleted file mode 100644 index 664f8fd..0000000 --- a/src/vist/rmi/impl/ondemand/tests/server-client.cpp +++ /dev/null @@ -1,99 +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 -#include -#include - -#include -#include - -#include - -using namespace vist::rmi; -using namespace vist::rmi::impl::ondemand; - -namespace { - -/// Request variables -std::string requestSignature = "request signature"; -int request1 = 100; -bool request2 = true; -std::string request3 = "request argument"; - -/// Response variables -std::string responseSignature = "response signature"; -int response1 = 300; -bool response2 = false; -std::string response3 = "response argument"; - -} // anonymous namespace - -TEST(ServerClientTests, ondemand) -{ - std::string sockPath = "./vist-test.sock"; - - auto task = [&](Message& message) -> Message { - EXPECT_EQ(message.signature, requestSignature); - - int recv1; - bool recv2; - std::string recv3; - message.disclose(recv1, recv2, recv3); - EXPECT_EQ(request1, recv1); - EXPECT_EQ(request2, recv2); - EXPECT_EQ(request3, recv3); - - Message reply(Message::Type::Reply, responseSignature); - reply.enclose(response1, response2, response3); - return reply; - }; - - Server server(sockPath, task); - auto serverThread = std::thread([&]() { - server.run(); - }); - - { /// Client configuration - auto clientClosure = [&]() { - Client client(sockPath); - - Message message(Message::Type::MethodCall, requestSignature); - message.enclose(request1, request2, request3); - - for (int i = 0; i < 3; i++) { - auto reply = client.request(message); - EXPECT_EQ(reply.signature, responseSignature); - - int recv1; - bool recv2; - std::string recv3; - reply.disclose(recv1, recv2, recv3); - EXPECT_EQ(response1, recv1); - EXPECT_EQ(response2, recv2); - EXPECT_EQ(response3, recv3); - } - }; - - for (int i = 0; i < 3; i++) - clientClosure(); - } - - server.stop(); - - if (serverThread.joinable()) - serverThread.join(); -} diff --git a/src/vist/rmi/tests/rmi.cpp b/src/vist/rmi/tests/rmi.cpp index c5de56f..d39fb46 100644 --- a/src/vist/rmi/tests/rmi.cpp +++ b/src/vist/rmi/tests/rmi.cpp @@ -54,7 +54,7 @@ TEST(RmiTests, positive) std::string sockPath = ("/tmp/test-gateway"); // gateway-side - Gateway gateway(sockPath); + Gateway gateway(sockPath, Gateway::ServiceType::General); Foo foo; gateway.expose(foo, "Foo::setName", &Foo::setName); diff --git a/src/vist/service/vistd.cpp b/src/vist/service/vistd.cpp index d32a7bf..b078d97 100644 --- a/src/vist/service/vistd.cpp +++ b/src/vist/service/vistd.cpp @@ -39,7 +39,12 @@ void Vistd::start() { INFO(VIST) << "Vistd daemon starts."; - rmi::Gateway gateway(SOCK_ADDR); + rmi::Gateway::ServiceType type = rmi::Gateway::ServiceType::General; +#ifdef TIZEN + type = rmi::Gateway::ServiceType::OnDemand; +#endif + + rmi::Gateway gateway(SOCK_ADDR, type); EXPOSE(gateway, *this, &Vistd::query); auto& pm = policy::PolicyManager::Instance();