From: Oskar Świtalski Date: Thu, 2 Jun 2016 10:42:07 +0000 (+0200) Subject: Add notification request and response X-Git-Tag: accepted/tizen/common/20160610.183543~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc7354e90eb0a69cfd48e9a6d4e05ca4db95285e;p=platform%2Fcore%2Fsecurity%2Faskuser.git Add notification request and response Change-Id: I3130590540d118fec365176b95df2717a84e266a --- diff --git a/src/common/translator/Translator.cpp b/src/common/translator/Translator.cpp index 9dc59dc..7033655 100644 --- a/src/common/translator/Translator.cpp +++ b/src/common/translator/Translator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co. + * Copyright (c) 2014-2016 Samsung Electronics Co. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ /** * @file Translator.cpp * @author Zofia Abramowska + * @author Oskar Świtalski * @brief Implementation of Translator methods */ @@ -91,5 +92,58 @@ Cynara::PluginData requestToData(const std::string &client, } } //namespace Plugin + +namespace Gui { +std::string responseToString(NResponseType response) +{ + switch (response) { + case NResponseType::Allow: + return "Allow"; + case NResponseType::Deny: + return "Deny once"; + case NResponseType::Never: + return "Deny"; + case NResponseType::Error: + return "Error"; + default: + return "None"; + } +} + +NotificationRequest dataToNotificationRequest(const std::string &data) { + std::stringstream stream(data); + std::size_t strSize; + char separator; + + cynara_agent_req_id id; + std::string members[2]; + + stream >> id; + stream.read(&separator, 1); + + for (auto &member : members) { + stream >> strSize; + std::vector buffer(strSize, '\0'); + char separator; + //Consume separator + stream.read(&separator, 1); + stream.read(buffer.data(), strSize); + //read doesn't append null + member.assign(buffer.begin(), buffer.end()); + } + + return NotificationRequest({id, std::move(members[0]), "", std::move(members[1])}); +} + +std::string notificationRequestToData(RequestId id, const std::string &client, + const std::string &privilege) +{ + const char separator = ' '; + return std::to_string(id) + separator + + std::to_string(client.length()) + separator + client + separator + + std::to_string(privilege.length()) + separator + privilege + separator + separator; +} + +} //namespace Gui } //namespace Translator } //namespace AskUser diff --git a/src/common/translator/Translator.h b/src/common/translator/Translator.h index 89140fe..3b8efdc 100644 --- a/src/common/translator/Translator.h +++ b/src/common/translator/Translator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co. + * Copyright (c) 2014-2016 Samsung Electronics Co. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,14 @@ /** * @file Translator.h * @author Zofia Abramowska + * @author Oskar Świtalski * @brief Definition of Translator methods and TranslateErrorException class */ #pragma once +#include +#include #include #include #include @@ -53,6 +56,13 @@ namespace Plugin { const std::string &privilege); } // namespace Plugin +namespace Gui { + +std::string responseToString(NResponseType response); +NotificationRequest dataToNotificationRequest(const std::string &data); +std::string notificationRequestToData(RequestId id, const std::string &client, + const std::string &privilege); +} // namespace Gui } // namespace Translator } // namespace AskUser diff --git a/src/common/types/NotificationRequest.h b/src/common/types/NotificationRequest.h new file mode 100644 index 0000000..7447c52 --- /dev/null +++ b/src/common/types/NotificationRequest.h @@ -0,0 +1,40 @@ + +/* + * Copyright (c) 2016 Samsung Electronics Co. + * + * 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 src/common/types/NotificationResponse.h + * @author Oskar Świtalski + * @brief Definition of common types and consts + */ + +#pragma once + +#include +#include + +namespace AskUser { + +struct NotificationRequest { + NotificationRequest(RequestId id_) : id(id_) {}; + NotificationRequest(RequestId id_, std::string client, std::string user, std::string privilege) + : id(id_), + data{std::move(client), std::move(user), std::move(privilege)} + {} + RequestId id; + RequestData data; +}; + +} // namespace AskUser diff --git a/src/common/types/NotificationResponse.h b/src/common/types/NotificationResponse.h new file mode 100644 index 0000000..2a81942 --- /dev/null +++ b/src/common/types/NotificationResponse.h @@ -0,0 +1,44 @@ + +/* + * Copyright (c) 2016 Samsung Electronics Co. + * + * 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 src/common/types/NotificationResponse.h + * @author Oskar Świtalski + * @brief Definition of common types and consts + */ + +#pragma once + +#include +#include + +namespace AskUser { + +enum class NResponseType +{ + Allow, + Deny, + Never, + Error, + None +}; + +struct NotificationResponse { + RequestId id; + NResponseType response; +}; + +} // namespace AskUser