From 4048a09d307ff55977ab8b1e582002e1f571a684 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 26 Aug 2014 13:17:40 +0200 Subject: [PATCH] Add ClientSession type Change-Id: Ia62dac02a652c2f252708ed05320eb66ea5506b1 --- src/client/api/ApiInterface.h | 4 +++- src/client/cache/CacheInterface.h | 5 +++-- src/client/cache/CapacityCache.cpp | 4 ++-- src/client/cache/CapacityCache.h | 6 +++--- src/client/logic/Logic.cpp | 2 +- src/client/logic/Logic.h | 2 +- src/common/types/ClientSession.h | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/common/types/ClientSession.h diff --git a/src/client/api/ApiInterface.h b/src/client/api/ApiInterface.h index 73bcec5..656cc1d 100644 --- a/src/client/api/ApiInterface.h +++ b/src/client/api/ApiInterface.h @@ -24,7 +24,9 @@ #define SRC_CLIENT_API_APIINTERFACE_H_ #include + #include +#include namespace Cynara { @@ -33,7 +35,7 @@ public: ApiInterface() = default; virtual ~ApiInterface() {}; - virtual int check(const std::string &client, const std::string &session, + virtual int check(const std::string &client, const ClientSession &session, const std::string &user, const std::string &privilege) = 0; }; diff --git a/src/client/cache/CacheInterface.h b/src/client/cache/CacheInterface.h index ec76a2e..ee2b27d 100644 --- a/src/client/cache/CacheInterface.h +++ b/src/client/cache/CacheInterface.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -62,8 +63,8 @@ public: class PluginCache { public: PluginCache() {} - virtual int get(const std::string &session, const PolicyKey &key) = 0; - virtual int update(const std::string &session, + virtual int get(const ClientSession &session, const PolicyKey &key) = 0; + virtual int update(const ClientSession &session, const PolicyKey &key, const PolicyResult &result) = 0; diff --git a/src/client/cache/CapacityCache.cpp b/src/client/cache/CapacityCache.cpp index 412d231..1d2c658 100644 --- a/src/client/cache/CapacityCache.cpp +++ b/src/client/cache/CapacityCache.cpp @@ -29,7 +29,7 @@ namespace Cynara { -int CapacityCache::get(const std::string &session, const PolicyKey &key) { +int CapacityCache::get(const ClientSession &session, const PolicyKey &key) { //This can be very time heavy. This part is welcomed to be optimized. if (session != m_session) { LOGD("Session changed from %s to %s.", m_session.c_str(), session.c_str()); @@ -100,7 +100,7 @@ void CapacityCache::evict(void) { m_keyValue.erase(value_it); } -int CapacityCache::update(const std::string &session, +int CapacityCache::update(const ClientSession &session, const PolicyKey &key, const PolicyResult &result) { //This can be very time heavy. This part is welcomed to be optimized. diff --git a/src/client/cache/CapacityCache.h b/src/client/cache/CapacityCache.h index 921a16b..6fe9c83 100644 --- a/src/client/cache/CapacityCache.h +++ b/src/client/cache/CapacityCache.h @@ -37,8 +37,8 @@ public: CapacityCache(std::size_t capacity = CACHE_DEFAULT_CAPACITY) : m_capacity(capacity) {} - int get(const std::string &session, const PolicyKey &key); - int update(const std::string& session, + int get(const ClientSession &session, const PolicyKey &key); + int update(const ClientSession& session, const PolicyKey &key, const PolicyResult &result); void clear(void); @@ -54,7 +54,7 @@ private: std::size_t m_capacity; - std::string m_session; + ClientSession m_session; KeyUsageList m_keyUsage; KeyValueMap m_keyValue; diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index 0c8ffc9..a609314 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -47,7 +47,7 @@ Logic::Logic() { m_cache->registerPlugin(PredefinedPolicyType::BUCKET, naiveInterpreter); } -int Logic::check(const std::string &client, const std::string &session, const std::string &user, +int Logic::check(const std::string &client, const ClientSession &session, const std::string &user, const std::string &privilege) noexcept { if (!m_socket->isConnected()){ diff --git a/src/client/logic/Logic.h b/src/client/logic/Logic.h index 3d2ee95..daab6f4 100644 --- a/src/client/logic/Logic.h +++ b/src/client/logic/Logic.h @@ -44,7 +44,7 @@ public: Logic(); virtual ~Logic() {}; - virtual int check(const std::string &client, const std::string &session, + virtual int check(const std::string &client, const ClientSession &session, const std::string &user, const std::string &privilege) noexcept; }; diff --git a/src/common/types/ClientSession.h b/src/common/types/ClientSession.h new file mode 100644 index 0000000..a848137 --- /dev/null +++ b/src/common/types/ClientSession.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014 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. + */ +/* + * @file ClientSession.h + * @author Zofia Abramowska + * @version 1.0 + * @brief Description of user defined session type + */ + +#ifndef SRC_COMMON_TYPES_CLIENTSESSION_H_ +#define SRC_COMMON_TYPES_CLIENTSESSION_H_ + +#include + +namespace Cynara { + +typedef std::string ClientSession; + +} // namespace Cynara + +#endif /* SRC_COMMON_TYPES_CLIENTSESSION_H_ */ -- 2.7.4