diff options
author | Zofia Abramowska <z.abramowska@samsung.com> | 2017-01-13 14:36:31 +0100 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2017-03-28 00:38:06 -0700 |
commit | 46182728efe31b9e301521f43e12531a34f18a55 (patch) | |
tree | bc2e44a9c68450789d82920cb7cdc6fb8abdd13c | |
parent | 1caf0f27271c22a0c1d884d7388219a2a6d50f64 (diff) | |
download | security-manager-46182728efe31b9e301521f43e12531a34f18a55.tar.gz security-manager-46182728efe31b9e301521f43e12531a34f18a55.tar.bz2 security-manager-46182728efe31b9e301521f43e12531a34f18a55.zip |
Clean up cynara classes members names
Start member names with "m_" prefix and static member names with "s_".
Change-Id: I39c0e08981e797a188edd841c2c32c89f694d20c
-rw-r--r-- | src/common/cynara.cpp | 76 | ||||
-rw-r--r-- | src/common/include/cynara.h | 21 |
2 files changed, 47 insertions, 50 deletions
diff --git a/src/common/cynara.cpp b/src/common/cynara.cpp index fd18f212..ad714f56 100644 --- a/src/common/cynara.cpp +++ b/src/common/cynara.cpp @@ -269,20 +269,20 @@ static bool checkCynaraError(int result, const std::string &msg) } } -CynaraAdmin::TypeToDescriptionMap CynaraAdmin::TypeToDescription; -CynaraAdmin::DescriptionToTypeMap CynaraAdmin::DescriptionToType; +CynaraAdmin::TypeToDescriptionMap CynaraAdmin::s_typeToDescription; +CynaraAdmin::DescriptionToTypeMap CynaraAdmin::s_descriptionToType; CynaraAdmin::CynaraAdmin() : m_policyDescriptionsInitialized(false) { checkCynaraError( - cynara_admin_initialize(&m_CynaraAdmin), + cynara_admin_initialize(&m_cynaraAdmin), "Cannot connect to Cynara administrative interface."); } CynaraAdmin::~CynaraAdmin() { - cynara_admin_finish(m_CynaraAdmin); + cynara_admin_finish(m_cynaraAdmin); } void CynaraAdmin::SetPolicies(const std::vector<CynaraAdminPolicy> &policies) @@ -309,7 +309,7 @@ void CynaraAdmin::SetPolicies(const std::vector<CynaraAdminPolicy> &policies) pp_policies[policies.size()] = nullptr; checkCynaraError( - cynara_admin_set_policies(m_CynaraAdmin, pp_policies.data()), + cynara_admin_set_policies(m_cynaraAdmin, pp_policies.data()), "Error while updating Cynara policy."); } @@ -546,7 +546,7 @@ void CynaraAdmin::ListPolicies( struct cynara_admin_policy ** pp_policies = nullptr; checkCynaraError( - cynara_admin_list_policies(m_CynaraAdmin, bucket.c_str(), label.c_str(), + cynara_admin_list_policies(m_cynaraAdmin, bucket.c_str(), label.c_str(), user.c_str(), privilege.c_str(), &pp_policies), "Error while getting list of policies for bucket: " + bucket); @@ -564,7 +564,7 @@ void CynaraAdmin::EmptyBucket(const std::string &bucketName, bool recursive, con const std::string &user, const std::string &privilege) { checkCynaraError( - cynara_admin_erase(m_CynaraAdmin, bucketName.c_str(), static_cast<int>(recursive), + cynara_admin_erase(m_cynaraAdmin, bucketName.c_str(), static_cast<int>(recursive), client.c_str(), user.c_str(), privilege.c_str()), "Error while emptying bucket: " + bucketName + ", filter (C, U, P): " + client + ", " + user + ", " + privilege); @@ -579,7 +579,7 @@ void CynaraAdmin::FetchCynaraPolicyDescriptions(bool forceRefresh) // fetch checkCynaraError( - cynara_admin_list_policies_descriptions(m_CynaraAdmin, &descriptions), + cynara_admin_list_policies_descriptions(m_cynaraAdmin, &descriptions), "Error while getting list of policies descriptions from Cynara."); if (descriptions[0] == nullptr) { @@ -590,15 +590,15 @@ void CynaraAdmin::FetchCynaraPolicyDescriptions(bool forceRefresh) // reset the state m_policyDescriptionsInitialized = false; - DescriptionToType.clear(); - TypeToDescription.clear(); + s_descriptionToType.clear(); + s_typeToDescription.clear(); // extract strings for (int i = 0; descriptions[i] != nullptr; i++) { std::string descriptionName(descriptions[i]->name); - DescriptionToType[descriptionName] = descriptions[i]->result; - TypeToDescription[descriptions[i]->result] = std::move(descriptionName); + s_descriptionToType[descriptionName] = descriptions[i]->result; + s_typeToDescription[descriptions[i]->result] = std::move(descriptionName); free(descriptions[i]->name); free(descriptions[i]); @@ -646,7 +646,7 @@ void CynaraAdmin::ListPoliciesDescriptions(std::vector<std::string> &policiesDes { FetchCynaraPolicyDescriptions(false); - for (const auto &it : TypeToDescription) + for (const auto &it : s_typeToDescription) policiesDescriptions.push_back(it.second); } @@ -654,14 +654,14 @@ std::string CynaraAdmin::convertToPolicyDescription(const int policyType, bool f { FetchCynaraPolicyDescriptions(forceRefresh); - return TypeToDescription.at(policyType); + return s_typeToDescription.at(policyType); } int CynaraAdmin::convertToPolicyType(const std::string &policy, bool forceRefresh) { FetchCynaraPolicyDescriptions(forceRefresh); - return DescriptionToType.at(policy); + return s_descriptionToType.at(policy); } void CynaraAdmin::Check(const std::string &label, const std::string &user, const std::string &privilege, @@ -670,7 +670,7 @@ void CynaraAdmin::Check(const std::string &label, const std::string &user, const char *resultExtraCstr = nullptr; checkCynaraError( - cynara_admin_check(m_CynaraAdmin, bucket.c_str(), recursive, label.c_str(), + cynara_admin_check(m_cynaraAdmin, bucket.c_str(), recursive, label.c_str(), user.c_str(), privilege.c_str(), &result, &resultExtraCstr), "Error while asking cynara admin API for permission for app label: " + label + ", user: " + user + " privilege: " + privilege + " bucket: " + bucket); @@ -705,9 +705,9 @@ int CynaraAdmin::GetPrivilegeManagerMaxLevel(const std::string &label, const std return result; } -Cynara::Cynara() : eventFd(eventfd(0, 0)), cynaraFd(eventFd), cynaraFdEvents(0), terminate(false) +Cynara::Cynara() : m_eventFd(eventfd(0, 0)), m_cynaraFd(m_eventFd), m_cynaraFdEvents(0), m_terminate(false) { - if (eventFd == -1) { + if (m_eventFd == -1) { LogError("Error while creating eventfd: " << GetErrnoString(errno)); ThrowMsg(CynaraException::UnknownError, "Error while creating eventfd"); } @@ -720,27 +720,27 @@ Cynara::Cynara() : eventFd(eventfd(0, 0)), cynaraFd(eventFd), cynaraFdEvents(0), checkCynaraError(cynara_async_configuration_set_cache_size(p_conf, CACHE_SIZE), "Cannot set cynara async configuration cache size"); checkCynaraError( - cynara_async_initialize(&cynara, p_conf, &Cynara::statusCallback, this), + cynara_async_initialize(&m_cynara, p_conf, &Cynara::statusCallback, this), "Cannot connect to Cynara policy interface."); - thread = std::thread(&Cynara::run, this); + m_thread = std::thread(&Cynara::run, this); } Cynara::~Cynara() { LogDebug("Sending terminate event to Cynara thread"); - terminate = true; + m_terminate = true; threadNotifyPut(); - thread.join(); + m_thread.join(); // Critical section - std::lock_guard<std::mutex> guard(mutex); - cynara_async_finish(cynara); + std::lock_guard<std::mutex> guard(m_mutex); + cynara_async_finish(m_cynara); } void Cynara::threadNotifyPut() { - int ret = eventfd_write(eventFd, 1); + int ret = eventfd_write(m_eventFd, 1); if (ret == -1) LogError("Unexpected error while writing to eventfd: " << GetErrnoString(errno)); } @@ -748,7 +748,7 @@ void Cynara::threadNotifyPut() void Cynara::threadNotifyGet() { eventfd_t value; - int ret = eventfd_read(eventFd, &value); + int ret = eventfd_read(m_eventFd, &value); if (ret == -1) LogError("Unexpected error while reading from eventfd: " << GetErrnoString(errno)); } @@ -759,17 +759,15 @@ void Cynara::statusCallback(int oldFd, int newFd, cynara_async_status status) "Status = " << status << ", oldFd = " << oldFd << ", newFd = " << newFd); if (newFd == -1) { - cynaraFdEvents = 0; + m_cynaraFdEvents = 0; } else { - - cynaraFd = newFd; + m_cynaraFd = newFd; switch (status) { case CYNARA_STATUS_FOR_READ: - cynaraFdEvents = POLLIN; + m_cynaraFdEvents = POLLIN; break; - case CYNARA_STATUS_FOR_RW: - cynaraFdEvents = POLLIN | POLLOUT; + m_cynaraFdEvents = POLLIN | POLLOUT; break; } } @@ -825,7 +823,7 @@ void Cynara::run() LogInfo("Cynara thread started"); while (true) { std::atomic_thread_fence(std::memory_order_acquire); - struct pollfd pollFds[2] = {{eventFd, POLLIN, 0}, {cynaraFd, cynaraFdEvents, 0}}; + struct pollfd pollFds[2] = {{m_eventFd, POLLIN, 0}, {m_cynaraFd, m_cynaraFdEvents, 0}}; int ret = poll(pollFds, 2, -1); if (ret == -1) { @@ -837,7 +835,7 @@ void Cynara::run() // Check eventfd for termination signal if (pollFds[0].revents) { threadNotifyGet(); - if (terminate) { + if (m_terminate) { LogInfo("Cynara thread terminated"); return; } @@ -847,9 +845,9 @@ void Cynara::run() if (pollFds[1].revents) { try { // Critical section - std::lock_guard<std::mutex> guard(mutex); + std::lock_guard<std::mutex> guard(m_mutex); - checkCynaraError(cynara_async_process(cynara), + checkCynaraError(cynara_async_process(m_cynara), "Unexpected error returned by cynara_async_process"); } catch (const CynaraException::Base &e) { LogError("Error while processing Cynara events: " << e.DumpToString()); @@ -869,9 +867,9 @@ bool Cynara::check(const std::string &label, const std::string &privilege, // Critical section { - std::lock_guard<std::mutex> guard(mutex); + std::lock_guard<std::mutex> guard(m_mutex); - int ret = cynara_async_check_cache(cynara, + int ret = cynara_async_check_cache(m_cynara, label.c_str(), session.c_str(), user.c_str(), privilege.c_str()); if (ret != CYNARA_API_CACHE_MISS) @@ -881,7 +879,7 @@ bool Cynara::check(const std::string &label, const std::string &privilege, cynara_check_id check_id; checkCynaraError( - cynara_async_create_request(cynara, + cynara_async_create_request(m_cynara, label.c_str(), session.c_str(), user.c_str(), privilege.c_str(), &check_id, &Cynara::responseCallback, &promise), "Cannot check permission with Cynara."); diff --git a/src/common/include/cynara.h b/src/common/include/cynara.h index 5be7344e..f2643fd5 100644 --- a/src/common/include/cynara.h +++ b/src/common/include/cynara.h @@ -320,10 +320,10 @@ private: const std::string &bucket, int policyToSet, std::vector<CynaraAdminPolicy> &policies); - struct cynara_admin *m_CynaraAdmin; + static TypeToDescriptionMap s_typeToDescription; + static DescriptionToTypeMap s_descriptionToType; - static TypeToDescriptionMap TypeToDescription; - static DescriptionToTypeMap DescriptionToType; + struct cynara_admin *m_cynaraAdmin; bool m_policyDescriptionsInitialized; }; @@ -361,15 +361,14 @@ private: void threadNotifyPut(); void threadNotifyGet(); - cynara_async *cynara; - struct pollfd pollFds[2]; - std::mutex mutex; - std::thread thread; + cynara_async *m_cynara; + std::mutex m_mutex; + std::thread m_thread; - const int eventFd; - std::atomic<int> cynaraFd; - std::atomic<short> cynaraFdEvents; - std::atomic<bool> terminate; + const int m_eventFd; + std::atomic<int> m_cynaraFd; + std::atomic<short> m_cynaraFdEvents; + std::atomic<bool> m_terminate; }; } // namespace SecurityManager |