Add notification request and response 52/72852/6
authorOskar Świtalski <o.switalski@samsung.com>
Thu, 2 Jun 2016 10:42:07 +0000 (12:42 +0200)
committerOskar Świtalski <o.switalski@samsung.com>
Fri, 10 Jun 2016 13:19:22 +0000 (15:19 +0200)
Change-Id: I3130590540d118fec365176b95df2717a84e266a

src/common/translator/Translator.cpp
src/common/translator/Translator.h
src/common/types/NotificationRequest.h [new file with mode: 0644]
src/common/types/NotificationResponse.h [new file with mode: 0644]

index 9dc59dc..7033655 100644 (file)
@@ -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 <z.abramowska@samsung.com>
+ * @author      Oskar Świtalski <o.switalski@samsung.com>
  * @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<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
index 89140fe..3b8efdc 100644 (file)
@@ -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.
 /**
  * @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>
@@ -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 (file)
index 0000000..7447c52
--- /dev/null
@@ -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 <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
diff --git a/src/common/types/NotificationResponse.h b/src/common/types/NotificationResponse.h
new file mode 100644 (file)
index 0000000..2a81942
--- /dev/null
@@ -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 <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