/*
- * 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.
/**
* @file Translator.cpp
* @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @author Oskar Świtalski <o.switalski@samsung.com>
* @brief Implementation of Translator methods
*/
}
} //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<char> 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
/*
- * 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.
/**
* @file Translator.h
* @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @author Oskar Świtalski <o.switalski@samsung.com>
* @brief Definition of Translator methods and TranslateErrorException class
*/
#pragma once
+#include <types/NotificationRequest.h>
+#include <types/NotificationResponse.h>
#include <types/RequestData.h>
#include <types/SupportedTypes.h>
#include <cynara-plugin.h>
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
--- /dev/null
+
+/*
+ * 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 <o.switalski@samsung.com>
+ * @brief Definition of common types and consts
+ */
+
+#pragma once
+
+#include <types/RequestId.h>
+#include <types/RequestData.h>
+
+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
--- /dev/null
+
+/*
+ * 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 <o.switalski@samsung.com>
+ * @brief Definition of common types and consts
+ */
+
+#pragma once
+
+#include <cynara-agent.h>
+#include <types/RequestId.h>
+
+namespace AskUser {
+
+enum class NResponseType
+{
+ Allow,
+ Deny,
+ Never,
+ Error,
+ None
+};
+
+struct NotificationResponse {
+ RequestId id;
+ NResponseType response;
+};
+
+} // namespace AskUser