From: Krzysztof Jackiewicz Date: Thu, 21 Sep 2017 12:16:35 +0000 (+0200) Subject: Refactor client and server side contexts X-Git-Tag: submit/tizen_4.0/20171018.042033~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7229a4829484266e1f5b06400967bf8682a3db46;p=platform%2Fcore%2Fsecurity%2Fode.git Refactor client and server side contexts - Get rid of files and typedefs with identical names - Simplify client & server side context Change-Id: Ib6580b228fd6b9d8771eb81adc06d2b2fef2775b --- diff --git a/lib/client.cpp b/lib/client.cpp index 25d8cb2..a548f1a 100644 --- a/lib/client.cpp +++ b/lib/client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -18,8 +18,8 @@ namespace { -const std::string SUBSCRIBER_REGISTER = "Server::registerNotificationSubscriber"; -const std::string SUBSCRIBER_UNREGISTER = "Server::unregisterNotificationSubscriber"; +const std::string SUBSCRIBER_REGISTER = "ServerContext::registerNotificationSubscriber"; +const std::string SUBSCRIBER_UNREGISTER = "ServerContext::unregisterNotificationSubscriber"; const std::string ODE_MANAGER_ADDRESS = "/tmp/.ode.sock"; @@ -27,16 +27,16 @@ const std::string ODE_MANAGER_ADDRESS = "/tmp/.ode.sock"; } // namespace -ODEContext::ODEContext() noexcept +ClientContext::ClientContext() noexcept { } -ODEContext::~ODEContext() noexcept +ClientContext::~ClientContext() noexcept { disconnect(); } -int ODEContext::connect(const std::string& address) noexcept +int ClientContext::connect(const std::string& address) noexcept { try { client.reset(new rmi::Client(address)); @@ -48,17 +48,17 @@ int ODEContext::connect(const std::string& address) noexcept return 0; } -int ODEContext::connect() noexcept +int ClientContext::connect() noexcept { return connect(ODE_MANAGER_ADDRESS); } -void ODEContext::disconnect() noexcept +void ClientContext::disconnect() noexcept { client.reset(); } -int ODEContext::subscribeSignal(const std::string& name, +int ClientContext::subscribeSignal(const std::string& name, const SignalListener& listener, void* data) { @@ -75,7 +75,7 @@ int ODEContext::subscribeSignal(const std::string& name, } } -int ODEContext::unsubscribeSignal(int subscriberId) +int ClientContext::unsubscribeSignal(int subscriberId) { return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId); } diff --git a/lib/client.h b/lib/client.h index 70d7369..7da3a6e 100644 --- a/lib/client.h +++ b/lib/client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -25,12 +25,12 @@ typedef std::function SignalListener; -class ODEContext final { -public: - typedef std::unique_ptr ODEControlContext; +typedef std::unique_ptr RmiClientPtr; - ODEContext() noexcept; - ~ODEContext() noexcept; +class ClientContext final { +public: + ClientContext() noexcept; + ~ClientContext() noexcept; int connect() noexcept; int connect(const std::string& address) noexcept; @@ -42,17 +42,11 @@ public: template Interface createInterface(Args&&... args) noexcept { - return Interface(getODEControlContext(), std::forward(args)...); + return Interface(client, std::forward(args)...); } private: - ODEControlContext& getODEControlContext() - { - return client; - } - - ODEControlContext client; + RmiClientPtr client; }; -ODEContext& GetODEContext(void* handle); #endif //__ODE_CLIENT_H__ diff --git a/lib/context.h b/lib/context.h deleted file mode 100644 index a1bc546..0000000 --- a/lib/context.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015 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 - */ - -#ifndef __ODE_CONTEXT__ -#define __ODE_CONTEXT__ - -#include "client.h" - -using ODEControlContext = ::ODEContext::ODEControlContext; - -#endif //!__ODE_CONTEXT__ diff --git a/lib/extension-encryption.cpp b/lib/extension-encryption.cpp index 40c399a..9ab36da 100644 --- a/lib/extension-encryption.cpp +++ b/lib/extension-encryption.cpp @@ -17,7 +17,7 @@ namespace ode { -ExtensionEncryptionClient::ExtensionEncryptionClient(ODEControlContext& ctx) : +ExtensionEncryptionClient::ExtensionEncryptionClient(RmiClientPtr& ctx) : context(ctx) { } diff --git a/lib/extension-encryption.h b/lib/extension-encryption.h index 328f683..7c3cdd5 100644 --- a/lib/extension-encryption.h +++ b/lib/extension-encryption.h @@ -20,13 +20,13 @@ #include #include "rmi/extension-encryption.h" -#include "context.h" +#include "client.h" namespace ode { class ExtensionEncryptionClient final: public ExtensionEncryption { public: - ExtensionEncryptionClient(ODEControlContext& ctxt); + ExtensionEncryptionClient(RmiClientPtr& ctxt); ~ExtensionEncryptionClient(); int setMountPassword(const std::string& password); @@ -45,7 +45,7 @@ public: int getState(); private: - ODEControlContext& context; + RmiClientPtr& context; }; } // namespace ode diff --git a/lib/external-encryption.cpp b/lib/external-encryption.cpp index 08b89cd..9870b8c 100644 --- a/lib/external-encryption.cpp +++ b/lib/external-encryption.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -17,7 +17,7 @@ namespace ode { -ExternalEncryptionClient::ExternalEncryptionClient(ODEControlContext& ctx) : +ExternalEncryptionClient::ExternalEncryptionClient(RmiClientPtr& ctx) : context(ctx) { } diff --git a/lib/external-encryption.h b/lib/external-encryption.h index e50f60b..705b740 100644 --- a/lib/external-encryption.h +++ b/lib/external-encryption.h @@ -20,13 +20,13 @@ #include #include "rmi/external-encryption.h" -#include "context.h" +#include "client.h" namespace ode { class ExternalEncryptionClient final: public ExternalEncryption { public: - ExternalEncryptionClient(ODEControlContext& ctxt); + ExternalEncryptionClient(RmiClientPtr& ctxt); ~ExternalEncryptionClient(); int setMountPassword(const std::string& password); @@ -50,7 +50,7 @@ public: unsigned int getSupportedOptions(); private: - ODEControlContext& context; + RmiClientPtr& context; }; } // namespace ode diff --git a/lib/internal-encryption.cpp b/lib/internal-encryption.cpp index 77d556a..614e023 100644 --- a/lib/internal-encryption.cpp +++ b/lib/internal-encryption.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -17,7 +17,7 @@ namespace ode { -InternalEncryptionClient::InternalEncryptionClient(ODEControlContext& ctx) : +InternalEncryptionClient::InternalEncryptionClient(RmiClientPtr& ctx) : context(ctx) { } diff --git a/lib/internal-encryption.h b/lib/internal-encryption.h index 1cff276..fe68ee5 100644 --- a/lib/internal-encryption.h +++ b/lib/internal-encryption.h @@ -20,13 +20,13 @@ #include #include "rmi/internal-encryption.h" -#include "context.h" +#include "client.h" namespace ode { class InternalEncryptionClient final: public InternalEncryption { public: - InternalEncryptionClient(ODEControlContext& ctxt); + InternalEncryptionClient(RmiClientPtr& ctxt); ~InternalEncryptionClient(); int setMountPassword(const std::string& password); @@ -50,7 +50,7 @@ public: unsigned int getSupportedOptions(); private: - ODEControlContext& context; + RmiClientPtr& context; }; } // namespace ode diff --git a/lib/ode/extension-encryption.cpp b/lib/ode/extension-encryption.cpp index abaf4c5..39ac413 100644 --- a/lib/ode/extension-encryption.cpp +++ b/lib/ode/extension-encryption.cpp @@ -26,7 +26,7 @@ int ode_extension_encryption_set_mount_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -35,7 +35,7 @@ int ode_extension_encryption_set_mount_password(const char* password) int ode_extension_encryption_mount() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -44,7 +44,7 @@ int ode_extension_encryption_mount() int ode_extension_encryption_umount() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -55,7 +55,7 @@ int ode_extension_encryption_format(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -66,7 +66,7 @@ int ode_extension_encryption_is_password_initialized(bool* result) { RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); int ret = extension.isPasswordInitialized(); @@ -81,7 +81,7 @@ int ode_extension_encryption_init_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -92,7 +92,7 @@ int ode_extension_encryption_clean_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -105,7 +105,7 @@ int ode_extension_encryption_change_password(const char* old_password, RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); @@ -117,7 +117,7 @@ int ode_extension_encryption_verify_password(const char* password, bool* result) RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); int ret = extension.verifyPassword(password); @@ -132,7 +132,7 @@ int ode_extension_encryption_get_state(int* state) { RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExtensionEncryptionClient extension = client.createInterface(); int ret = extension.getState(); @@ -143,13 +143,13 @@ int ode_extension_encryption_get_state(int* state) return ODE_ERROR_NONE; } -static std::unique_ptr mountEventCallbackContext; +static std::unique_ptr mountEventCallbackContext; int ode_extension_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data) { RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER); - mountEventCallbackContext.reset(new ODEContext); + mountEventCallbackContext.reset(new ClientContext); RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED); int ret = mountEventCallbackContext->subscribeSignal("ExtensionEncryption::mount", callback, user_data); diff --git a/lib/ode/external-encryption.cpp b/lib/ode/external-encryption.cpp index 7a4c014..f10b7e8 100644 --- a/lib/ode/external-encryption.cpp +++ b/lib/ode/external-encryption.cpp @@ -26,7 +26,7 @@ int ode_external_encryption_set_mount_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -35,7 +35,7 @@ int ode_external_encryption_set_mount_password(const char* password) int ode_external_encryption_mount() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -44,7 +44,7 @@ int ode_external_encryption_mount() int ode_external_encryption_umount() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -55,7 +55,7 @@ int ode_external_encryption_encrypt(const char* password, unsigned int options) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -66,7 +66,7 @@ int ode_external_encryption_decrypt(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -75,7 +75,7 @@ int ode_external_encryption_decrypt(const char* password) int ode_external_encryption_recovery() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -86,7 +86,7 @@ int ode_external_encryption_is_password_initialized(bool* result) { RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); int ret = external.isPasswordInitialized(); @@ -101,7 +101,7 @@ int ode_external_encryption_init_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -112,7 +112,7 @@ int ode_external_encryption_clean_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -125,7 +125,7 @@ int ode_external_encryption_change_password(const char* old_password, RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); @@ -137,7 +137,7 @@ int ode_external_encryption_verify_password(const char* password, bool* result) RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); int ret = external.verifyPassword(password); @@ -152,7 +152,7 @@ int ode_external_encryption_get_state(int* state) { RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); int ret = external.getState(); @@ -167,20 +167,20 @@ int ode_external_encryption_get_supported_options(unsigned int* options) { RET_ON_FAILURE(options, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); ExternalEncryptionClient external = client.createInterface(); *options = external.getSupportedOptions(); return ODE_ERROR_NONE; } -static std::unique_ptr mountEventCallbackContext; +static std::unique_ptr mountEventCallbackContext; int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data) { RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER); - mountEventCallbackContext.reset(new ODEContext); + mountEventCallbackContext.reset(new ClientContext); RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED); int ret = mountEventCallbackContext->subscribeSignal("ExternalEncryption::mount", callback, user_data); diff --git a/lib/ode/internal-encryption.cpp b/lib/ode/internal-encryption.cpp index 624b269..8364cbf 100644 --- a/lib/ode/internal-encryption.cpp +++ b/lib/ode/internal-encryption.cpp @@ -26,7 +26,7 @@ int ode_internal_encryption_set_mount_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -35,7 +35,7 @@ int ode_internal_encryption_set_mount_password(const char* password) int ode_internal_encryption_mount() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -44,7 +44,7 @@ int ode_internal_encryption_mount() int ode_internal_encryption_umount() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -55,7 +55,7 @@ int ode_internal_encryption_encrypt(const char* password, unsigned int options) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -66,7 +66,7 @@ int ode_internal_encryption_decrypt(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -75,7 +75,7 @@ int ode_internal_encryption_decrypt(const char* password) int ode_internal_encryption_recovery() { - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -86,7 +86,7 @@ int ode_internal_encryption_is_password_initialized(bool* result) { RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); int ret = internal.isPasswordInitialized(); @@ -101,7 +101,7 @@ int ode_internal_encryption_init_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -112,7 +112,7 @@ int ode_internal_encryption_clean_password(const char* password) { RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -125,7 +125,7 @@ int ode_internal_encryption_change_password(const char* old_password, RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); @@ -137,7 +137,7 @@ int ode_internal_encryption_verify_password(const char* password, bool* result) RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); int ret = internal.verifyPassword(password); @@ -152,7 +152,7 @@ int ode_internal_encryption_get_state(int* state) { RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); int ret = internal.getState(); @@ -167,20 +167,20 @@ int ode_internal_encryption_get_supported_options(unsigned int* options) { RET_ON_FAILURE(options, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); InternalEncryptionClient internal = client.createInterface(); *options = internal.getSupportedOptions(); return ODE_ERROR_NONE; } -static std::unique_ptr mountEventCallbackContext; +static std::unique_ptr mountEventCallbackContext; int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data) { RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER); - mountEventCallbackContext.reset(new ODEContext); + mountEventCallbackContext.reset(new ClientContext); RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED); int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data); diff --git a/lib/ode/secure-erase.cpp b/lib/ode/secure-erase.cpp index 5bda353..64d97f8 100644 --- a/lib/ode/secure-erase.cpp +++ b/lib/ode/secure-erase.cpp @@ -26,7 +26,7 @@ int ode_secure_clean(const char* name) { RET_ON_FAILURE(name, ODE_ERROR_INVALID_PARAMETER); - ODEContext client; + ClientContext client; RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED); SecureEraseClient secure = client.createInterface(); diff --git a/lib/secure-erase.cpp b/lib/secure-erase.cpp index 579437e..f582efa 100644 --- a/lib/secure-erase.cpp +++ b/lib/secure-erase.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -17,7 +17,7 @@ namespace ode { -SecureEraseClient::SecureEraseClient(ODEControlContext& ctx) : +SecureEraseClient::SecureEraseClient(RmiClientPtr& ctx) : context(ctx) { } diff --git a/lib/secure-erase.h b/lib/secure-erase.h index 0434a51..e4fa918 100644 --- a/lib/secure-erase.h +++ b/lib/secure-erase.h @@ -20,19 +20,19 @@ #include #include "rmi/secure-erase.h" -#include "context.h" +#include "client.h" namespace ode { class SecureEraseClient final: public SecureErase { public: - SecureEraseClient(ODEControlContext& ctxt); + SecureEraseClient(RmiClientPtr& ctxt); ~SecureEraseClient(); int clean(const std::string& name); private: - ODEControlContext& context; + RmiClientPtr& context; }; } // namespace ode diff --git a/server/context.h b/server/context.h deleted file mode 100644 index 718bbab..0000000 --- a/server/context.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015 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 - */ - -#ifndef __ODE_CONTEXT_H__ -#define __ODE_CONTEXT_H__ - -#include "server.h" - -using ODEControlContext = Server; - -#endif //__ODE_CONTEXT_H__ diff --git a/server/extension-encryption.cpp b/server/extension-encryption.cpp index e085d05..3f091fc 100644 --- a/server/extension-encryption.cpp +++ b/server/extension-encryption.cpp @@ -73,22 +73,22 @@ bool findKillAndUmount(const std::string &devPath) } // namsepace -ExtensionEncryptionServer::ExtensionEncryptionServer(ODEControlContext &ctx) : - context(ctx), +ExtensionEncryptionServer::ExtensionEncryptionServer(ServerContext &srv) : + server(srv), currentReq(Request::NONE) { - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::setMountPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::mount)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::umount)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::format)(std::string)); - context.expose(this, "", (int)(ExtensionEncryptionServer::isPasswordInitialized)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::initPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::cleanPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::changePassword)(std::string, std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::verifyPassword)(std::string)); - context.expose(this, "", (int)(ExtensionEncryptionServer::getState)()); - - context.createNotification("ExtensionEncryptionServer::mount"); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::setMountPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::mount)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::umount)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::format)(std::string)); + server.expose(this, "", (int)(ExtensionEncryptionServer::isPasswordInitialized)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::initPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::cleanPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::changePassword)(std::string, std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::verifyPassword)(std::string)); + server.expose(this, "", (int)(ExtensionEncryptionServer::getState)()); + + server.createNotification("ExtensionEncryptionServer::mount"); // TODO: think about handling more than one card / more than one engine // it would require global API change to select which card is handled atm @@ -165,7 +165,7 @@ int ExtensionEncryptionServer::mount() } } - context.notify("ExtensionEncryptionServer::mount"); + server.notify("ExtensionEncryptionServer::mount"); return 0; } diff --git a/server/extension-encryption.h b/server/extension-encryption.h index 5f2a08f..ede4249 100644 --- a/server/extension-encryption.h +++ b/server/extension-encryption.h @@ -22,10 +22,10 @@ #include #include -#include "context.h" #include "rmi/extension-encryption.h" #include "key-manager/key-manager.h" #include "engine/encryption/cryptsetup-engine.h" +#include "server.h" namespace ode { @@ -33,7 +33,7 @@ typedef CryptsetupEngine EXTENSION_ENGINE; class ExtensionEncryptionServer final: public ExtensionEncryption { public: - ExtensionEncryptionServer(ODEControlContext& ctxt); + ExtensionEncryptionServer(ServerContext& srv); ~ExtensionEncryptionServer(); int setMountPassword(const std::string& password); @@ -110,7 +110,7 @@ private: bool isOpened() const; bool isMounted() const; - ODEControlContext& context; + ServerContext& server; // currently inserted card information, empty if no card: DevInfo info[DEVICE_MAX]; diff --git a/server/external-encryption.cpp b/server/external-encryption.cpp index 41648a7..886ce6b 100644 --- a/server/external-encryption.cpp +++ b/server/external-encryption.cpp @@ -188,23 +188,23 @@ void setOptions(unsigned int options) } // namsepace -ExternalEncryptionServer::ExternalEncryptionServer(ODEControlContext &ctx) : - context(ctx) +ExternalEncryptionServer::ExternalEncryptionServer(ServerContext &srv) : + server(srv) { - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::setMountPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::mount)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::umount)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::encrypt)(std::string, unsigned int)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::decrypt)(std::string)); - context.expose(this, "", (int)(ExternalEncryptionServer::isPasswordInitialized)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::initPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::cleanPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::changePassword)(std::string, std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::verifyPassword)(std::string)); - context.expose(this, "", (int)(ExternalEncryptionServer::getState)()); - context.expose(this, "", (unsigned int)(ExternalEncryptionServer::getSupportedOptions)()); - - context.createNotification("ExternalEncryptionServer::mount"); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::setMountPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::mount)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::umount)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::encrypt)(std::string, unsigned int)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::decrypt)(std::string)); + server.expose(this, "", (int)(ExternalEncryptionServer::isPasswordInitialized)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::initPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::cleanPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::changePassword)(std::string, std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::verifyPassword)(std::string)); + server.expose(this, "", (int)(ExternalEncryptionServer::getState)()); + server.expose(this, "", (unsigned int)(ExternalEncryptionServer::getSupportedOptions)()); + + server.createNotification("ExternalEncryptionServer::mount"); engine.reset(new EXTERNAL_ENGINE( EXTERNAL_PATH, EXTERNAL_PATH, @@ -255,7 +255,7 @@ int ExternalEncryptionServer::mount() return -3; } - context.notify("ExternalEncryptionServer::mount"); + server.notify("ExternalEncryptionServer::mount"); return 0; } @@ -307,7 +307,7 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int setOptions(options & getSupportedOptions()); INFO(SINK, "Encryption completed"); ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted"); - context.notify("ExternalEncryptionServer::mount"); + server.notify("ExternalEncryptionServer::mount"); INFO(SINK, "Sync disk..."); sync(); } catch (runtime::Exception &e) { diff --git a/server/external-encryption.h b/server/external-encryption.h index 0ec5dd4..15ba976 100644 --- a/server/external-encryption.h +++ b/server/external-encryption.h @@ -23,10 +23,10 @@ #include -#include "context.h" #include "rmi/external-encryption.h" #include "key-manager/key-manager.h" #include "engine/encryption/ecryptfs-engine.h" +#include "server.h" namespace ode { @@ -34,7 +34,7 @@ typedef EcryptfsEngine EXTERNAL_ENGINE; class ExternalEncryptionServer final: public ExternalEncryption { public: - ExternalEncryptionServer(ODEControlContext& ctxt); + ExternalEncryptionServer(ServerContext& srv); ~ExternalEncryptionServer(); int setMountPassword(const std::string& password); @@ -58,7 +58,7 @@ public: unsigned int getSupportedOptions(); private: - ODEControlContext& context; + ServerContext& server; std::unique_ptr engine; KeyManager::data mountKey; diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index 30ff4a0..f03b006 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -228,23 +228,23 @@ void setOptions(unsigned int options) } -InternalEncryptionServer::InternalEncryptionServer(ODEControlContext& ctx) : - context(ctx) +InternalEncryptionServer::InternalEncryptionServer(ServerContext& srv) : + server(srv) { - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::setMountPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::mount)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::umount)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::encrypt)(std::string, unsigned int)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::decrypt)(std::string)); - context.expose(this, "", (int)(InternalEncryptionServer::isPasswordInitialized)()); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::initPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::cleanPassword)(std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::changePassword)(std::string, std::string)); - context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::verifyPassword)(std::string)); - context.expose(this, "", (int)(InternalEncryptionServer::getState)()); - context.expose(this, "", (unsigned int)(InternalEncryptionServer::getSupportedOptions)()); - - context.createNotification("InternalEncryptionServer::mount"); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::setMountPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::mount)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::umount)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::encrypt)(std::string, unsigned int)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::decrypt)(std::string)); + server.expose(this, "", (int)(InternalEncryptionServer::isPasswordInitialized)()); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::initPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::cleanPassword)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::changePassword)(std::string, std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::verifyPassword)(std::string)); + server.expose(this, "", (int)(InternalEncryptionServer::getState)()); + server.expose(this, "", (unsigned int)(InternalEncryptionServer::getSupportedOptions)()); + + server.createNotification("InternalEncryptionServer::mount"); std::string source = findDevPath(); @@ -290,7 +290,7 @@ int InternalEncryptionServer::mount() engine->mount(mountKey, getOptions()); mountKey.clear(); - context.notify("InternalEncryptionServer::mount"); + server.notify("InternalEncryptionServer::mount"); runtime::File("/tmp/.lazy_mount").create(O_WRONLY); runtime::File("/tmp/.unlock_mnt").create(O_WRONLY); @@ -371,7 +371,7 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int INFO(SINK, "Encryption completed"); ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "encrypted"); - context.notify("InternalEncryptionServer::mount"); + server.notify("InternalEncryptionServer::mount"); INFO(SINK, "Syncing disk and rebooting..."); ::sync(); diff --git a/server/internal-encryption.h b/server/internal-encryption.h index ea48de3..57de876 100644 --- a/server/internal-encryption.h +++ b/server/internal-encryption.h @@ -20,10 +20,10 @@ #include #include -#include "context.h" #include "rmi/internal-encryption.h" #include "key-manager/key-manager.h" #include "engine/encryption/dmcrypt-engine.h" +#include "server.h" namespace ode { @@ -31,7 +31,7 @@ typedef DMCryptEngine INTERNAL_ENGINE; class InternalEncryptionServer final: public InternalEncryption { public: - InternalEncryptionServer(ODEControlContext& ctxt); + InternalEncryptionServer(ServerContext& srv); ~InternalEncryptionServer(); int setMountPassword(const std::string& password); @@ -55,7 +55,7 @@ public: unsigned int getSupportedOptions(); private: - ODEControlContext& context; + ServerContext& server; std::unique_ptr engine; KeyManager::data mountKey; diff --git a/server/main.cpp b/server/main.cpp index 8c15275..1a85a3c 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -42,8 +42,8 @@ int main(int argc, char *argv[]) try { ScopedGMainLoop gmainloop; - Server server; - server.run(); + ode::ServerContext server; + server.start(); } catch (std::exception &e) { std::cerr << e.what() << std::endl; return 1; diff --git a/server/secure-erase.cpp b/server/secure-erase.cpp index f4d036e..d11af7e 100644 --- a/server/secure-erase.cpp +++ b/server/secure-erase.cpp @@ -19,7 +19,6 @@ #include #include -#include "ext4-tool.h" #include "secure-erase.h" namespace ode { @@ -47,10 +46,10 @@ std::string findDevPath(const std::string &mntPath) } } /* namespace */ -SecureEraseServer::SecureEraseServer(ODEControlContext &ctx) : - context(ctx) +SecureEraseServer::SecureEraseServer(ServerContext &srv) : + server(srv) { - context.expose(this, PRIVILEGE_PLATFORM, (int)(SecureEraseServer::clean)(std::string)); + server.expose(this, PRIVILEGE_PLATFORM, (int)(SecureEraseServer::clean)(std::string)); engine.reset(new ERASE_ENGINE(ProgressBar([](int v) { ::vconf_set_str(VCONFKEY_ODE_ERASE_PROGRESS, std::to_string(v).c_str()); diff --git a/server/secure-erase.h b/server/secure-erase.h index acfd91f..339dbbf 100644 --- a/server/secure-erase.h +++ b/server/secure-erase.h @@ -20,9 +20,9 @@ #include #include -#include "context.h" #include "rmi/secure-erase.h" #include "engine/erase/mmc-engine.h" +#include "server.h" namespace ode { @@ -30,14 +30,14 @@ typedef MMCEraseEngine ERASE_ENGINE; class SecureEraseServer final: public SecureErase { public: - SecureEraseServer(ODEControlContext& ctxt); + SecureEraseServer(ServerContext& srv); ~SecureEraseServer(); int erase(const std::string& name); int clean(const std::string& name); private: - ODEControlContext& context; + ServerContext& server; std::unique_ptr engine; }; diff --git a/server/server.cpp b/server/server.cpp index 5baf9f7..2d60439 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -24,64 +24,49 @@ #include "external-encryption.h" #include "extension-encryption.h" #include "key-manager/key-generator.h" - #include "server.h" using namespace std::placeholders; +audit::LogSink *SINK = nullptr; + +namespace ode { + namespace { const std::string ODE_MANAGER_ADDRESS = "/tmp/.ode.sock"; - -std::unique_ptr secureErase; -std::unique_ptr internalEncryption; -std::unique_ptr externalEncryption; -std::unique_ptr extensionEncryption; std::unique_ptr _sink = nullptr; } // namespace audit::LogSink *SINK = nullptr; -Server::Server() +ServerContext::ServerContext() : rmi::Service(ODE_MANAGER_ADDRESS) { _sink.reset(new audit::DlogLogSink("ODE")); - SINK = dynamic_cast((_sink).get()); + SINK = _sink.get(); INFO(SINK, "ODE server starting."); - service.reset(new rmi::Service(ODE_MANAGER_ADDRESS)); - - service->setPrivilegeChecker(std::bind(&Server::checkPeerPrivilege, this, _1, _2)); + setPrivilegeChecker(std::bind(&ServerContext::checkPeerPrivilege, this, _1, _2)); - service->expose(this, "", (runtime::FileDescriptor)(Server::registerNotificationSubscriber)(std::string)); - service->expose(this, "", (int)(Server::unregisterNotificationSubscriber)(std::string, int)); + expose(this, "", (runtime::FileDescriptor)(ServerContext::registerNotificationSubscriber)(std::string)); + expose(this, "", (int)(ServerContext::unregisterNotificationSubscriber)(std::string, int)); - secureErase.reset(new ode::SecureEraseServer(*this)); - internalEncryption.reset(new ode::InternalEncryptionServer(*this)); - externalEncryption.reset(new ode::ExternalEncryptionServer(*this)); - extensionEncryption.reset(new ode::ExtensionEncryptionServer(*this)); + secureErase.reset(new SecureEraseServer(*this)); + internalEncryption.reset(new InternalEncryptionServer(*this)); + externalEncryption.reset(new ExternalEncryptionServer(*this)); + extensionEncryption.reset(new ExtensionEncryptionServer(*this)); - ode::KeyGenerator::init(); + KeyGenerator::init(); } -Server::~Server() +ServerContext::~ServerContext() { - ode::KeyGenerator::cleanup(); + KeyGenerator::cleanup(); } -void Server::run() -{ - // Prepare execution environment - service->start(); -} - -void Server::terminate() -{ - service->stop(); -} - -bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege) +bool ServerContext::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege) { cynara *p_cynara; @@ -107,14 +92,16 @@ bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& return true; } -runtime::FileDescriptor Server::registerNotificationSubscriber(const std::string& name) +runtime::FileDescriptor ServerContext::registerNotificationSubscriber(const std::string& name) { INFO(SINK, "registerNotificationSubscriber"); INFO(SINK, name); - return runtime::FileDescriptor(service->subscribeNotification(name), true); + return runtime::FileDescriptor(subscribeNotification(name), true); } -int Server::unregisterNotificationSubscriber(const std::string& name, int id) +int ServerContext::unregisterNotificationSubscriber(const std::string& name, int id) { - return service->unsubscribeNotification(name, id); + return unsubscribeNotification(name, id); } + +} // namespace ode diff --git a/server/server.h b/server/server.h index d7a439d..fb12ab0 100644 --- a/server/server.h +++ b/server/server.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2017 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. @@ -20,60 +20,33 @@ #include #include -#include #include #include -class Server final { -public: - Server(); - ~Server(); - - void run(); - void terminate(); - - template - void setMethodHandler(const std::string& privilege, const std::string& method, - const typename rmi::MethodHandler::type& handler) - { - service->setMethodHandler(privilege, method, handler); - } - - template - void notify(const std::string& name, Args&&... args) - { - service->notify(name, std::forward(args)...); - } - - uid_t getPeerUid() const - { - return service->getPeerUid(); - } +namespace ode { - gid_t getPeerGid() const - { - return service->getPeerGid(); - } +class SecureEraseServer; +class InternalEncryptionServer; +class ExternalEncryptionServer; +class ExtensionEncryptionServer; - pid_t getPeerPid() const - { - return service->getPeerPid(); - } +class ServerContext final: public rmi::Service { +public: + ServerContext(); + ~ServerContext(); bool checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege); - - void createNotification(const std::string& name) - { - service->createNotification(name); - } - runtime::FileDescriptor registerNotificationSubscriber(const std::string& name); int unregisterNotificationSubscriber(const std::string& name, int id); private: - std::string securityLabel; - std::unique_ptr service; + std::unique_ptr secureErase; + std::unique_ptr internalEncryption; + std::unique_ptr externalEncryption; + std::unique_ptr extensionEncryption; }; +} // namespace ode + #endif //__ODE_SERVER_H__