Add agent socket & dummy agent protocol 25/27925/10
authorAdam Malinowski <a.malinowsk2@partner.samsung.com>
Mon, 15 Sep 2014 12:47:22 +0000 (14:47 +0200)
committerAdam Malinowski <a.malinowsk2@partner.samsung.com>
Fri, 14 Nov 2014 19:53:46 +0000 (20:53 +0100)
This change introduces new systemd based socket and protocol for
communication with agents. Protocol does not contain any agent
specific frame information for now.

Change-Id: I83e2211a25fd93792a46a64c1df519efb1cedfed

packaging/cynara.spec
src/common/CMakeLists.txt
src/common/common.h
src/common/config/PathConfig.cpp
src/common/config/PathConfig.h
src/common/protocol/ProtocolAgent.cpp [new file with mode: 0644]
src/common/protocol/ProtocolAgent.h [new file with mode: 0644]
src/service/sockets/SocketManager.cpp
systemd/CMakeLists.txt
systemd/cynara-agent.socket [new file with mode: 0644]
systemd/cynara.service

index 743f2a7..8a3e298 100644 (file)
@@ -287,6 +287,7 @@ mkdir -p %{buildroot}/%{tests_dir}/empty_db
 cp -a db* %{buildroot}/%{tests_dir}
 ln -s ../cynara.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/cynara.socket
 ln -s ../cynara-admin.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/cynara-admin.socket
+ln -s ../cynara-agent.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/cynara-agent.socket
 
 %pre
 id -g %{group_name} > /dev/null 2>&1
@@ -425,6 +426,8 @@ fi
 %attr(-,root,root) /usr/lib/systemd/system/cynara.socket
 %attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/cynara-admin.socket
 %attr(-,root,root) /usr/lib/systemd/system/cynara-admin.socket
+%attr(-,root,root) /usr/lib/systemd/system/sockets.target.wants/cynara-agent.socket
+%attr(-,root,root) /usr/lib/systemd/system/cynara-agent.socket
 %dir %attr(700,cynara,cynara) %{state_path}
 
 %files -n libcynara-client
index 98f5133..72b7d7f 100644 (file)
@@ -31,6 +31,7 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/log/log.cpp
     ${COMMON_PATH}/plugin/PluginManager.cpp
     ${COMMON_PATH}/protocol/ProtocolAdmin.cpp
+    ${COMMON_PATH}/protocol/ProtocolAgent.cpp
     ${COMMON_PATH}/protocol/ProtocolClient.cpp
     ${COMMON_PATH}/protocol/ProtocolFrame.cpp
     ${COMMON_PATH}/protocol/ProtocolFrameHeader.cpp
index 5d93cdc..95ff89c 100644 (file)
@@ -32,5 +32,4 @@
 
 #include "types/PolicyTypeExtension.h"
 
-
 #endif /* COMMON_H */
index a5a603b..f2799a1 100644 (file)
@@ -47,6 +47,7 @@ const std::string clientPath("/run/cynara/");
 namespace SocketPath {
 const std::string client(clientPath + "cynara.socket");
 const std::string admin(clientPath + "cynara-admin.socket");
+const std::string agent(clientPath + "cynara-agent.socket");
 } // namespace SocketPath
 
 namespace StoragePath {
index 27b10c2..2f5836a 100644 (file)
@@ -35,6 +35,7 @@ extern const std::string clientPath;
 namespace SocketPath {
 extern const std::string client;
 extern const std::string admin;
+extern const std::string agent;
 } // namespace SocketPath
 
 namespace StoragePath {
diff --git a/src/common/protocol/ProtocolAgent.cpp b/src/common/protocol/ProtocolAgent.cpp
new file mode 100644 (file)
index 0000000..f4d26a1
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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        src/common/protocol/ProtocolAgent.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements protocol class for communication with agent
+ */
+
+#include <inttypes.h>
+#include <memory>
+
+#include <exceptions/InvalidProtocolException.h>
+#include <log/log.h>
+#include <protocol/ProtocolFrameSerializer.h>
+#include <protocol/ProtocolOpCode.h>
+#include <protocol/ProtocolSerialization.h>
+
+#include "ProtocolAgent.h"
+
+namespace Cynara {
+
+ProtocolAgent::ProtocolAgent() {
+}
+
+ProtocolAgent::~ProtocolAgent() {
+}
+
+ProtocolPtr ProtocolAgent::clone(void) {
+    return std::make_shared<ProtocolAgent>();
+}
+
+RequestPtr ProtocolAgent::extractRequestFromBuffer(BinaryQueuePtr bufferQueue) {
+    ProtocolFrameSerializer::deserializeHeader(m_frameHeader, bufferQueue);
+
+    if (m_frameHeader.isFrameComplete()) {
+        ProtocolOpCode opCode;
+
+        m_frameHeader.resetState();
+        ProtocolDeserialization::deserialize(m_frameHeader, opCode);
+        LOGD("Deserialized opCode [%" PRIu8 "]", opCode);
+        switch (opCode) {
+        default:
+            throw InvalidProtocolException(InvalidProtocolException::WrongOpCode);
+            break;
+        }
+    }
+
+    return nullptr;
+}
+
+ResponsePtr ProtocolAgent::extractResponseFromBuffer(BinaryQueuePtr bufferQueue) {
+    ProtocolFrameSerializer::deserializeHeader(m_frameHeader, bufferQueue);
+
+    if (m_frameHeader.isFrameComplete()) {
+        ProtocolOpCode opCode;
+
+        m_frameHeader.resetState();
+        ProtocolDeserialization::deserialize(m_frameHeader, opCode);
+        LOGD("Deserialized opCode [%" PRIu8 "]", opCode);
+        switch (opCode) {
+        default:
+            throw InvalidProtocolException(InvalidProtocolException::WrongOpCode);
+            break;
+        }
+    }
+
+    return nullptr;
+}
+
+} // namespace Cynara
diff --git a/src/common/protocol/ProtocolAgent.h b/src/common/protocol/ProtocolAgent.h
new file mode 100644 (file)
index 0000000..68baf46
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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        src/common/protocol/ProtocolAgent.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines protocol class for communication with agent
+ */
+
+#ifndef SRC_COMMON_PROTOCOL_PROTOCOLAGENT_H_
+#define SRC_COMMON_PROTOCOL_PROTOCOLAGENT_H_
+
+#include <protocol/ProtocolFrameHeader.h>
+#include <request/pointers.h>
+#include <response/pointers.h>
+
+#include "Protocol.h"
+
+namespace Cynara {
+
+class ProtocolAgent : public Protocol {
+public:
+    ProtocolAgent();
+    virtual ~ProtocolAgent();
+
+    virtual ProtocolPtr clone(void);
+
+    virtual RequestPtr extractRequestFromBuffer(BinaryQueuePtr bufferQueue);
+    virtual ResponsePtr extractResponseFromBuffer(BinaryQueuePtr bufferQueue);
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_PROTOCOL_PROTOCOLAGENT_H_ */
index 3161dc7..e454271 100644 (file)
@@ -45,6 +45,7 @@
 #include <logic/Logic.h>
 #include <main/Cynara.h>
 #include <protocol/ProtocolAdmin.h>
+#include <protocol/ProtocolAgent.h>
 #include <protocol/ProtocolClient.h>
 #include <protocol/ProtocolSignal.h>
 #include <request/pointers.h>
@@ -72,11 +73,14 @@ void SocketManager::init(void) {
     LOGI("SocketManger init start");
     const mode_t clientSocketUMask(0);
     const mode_t adminSocketUMask(0077);
+    const mode_t agentSocketUMask(0);
 
     createDomainSocket(std::make_shared<ProtocolClient>(), PathConfig::SocketPath::client,
                        clientSocketUMask, true);
     createDomainSocket(std::make_shared<ProtocolAdmin>(), PathConfig::SocketPath::admin,
                        adminSocketUMask, false);
+    createDomainSocket(std::make_shared<ProtocolAgent>(), PathConfig::SocketPath::agent,
+                       agentSocketUMask, false);
     createSignalSocket(std::make_shared<ProtocolSignal>());
     LOGI("SocketManger init done");
 }
index 8fc27e7..a540263 100644 (file)
@@ -21,6 +21,7 @@ INSTALL(FILES
     ${CMAKE_SOURCE_DIR}/systemd/cynara.target
     ${CMAKE_SOURCE_DIR}/systemd/cynara.socket
     ${CMAKE_SOURCE_DIR}/systemd/cynara-admin.socket
+    ${CMAKE_SOURCE_DIR}/systemd/cynara-agent.socket
     DESTINATION
     lib/systemd/system
 )
diff --git a/systemd/cynara-agent.socket b/systemd/cynara-agent.socket
new file mode 100644 (file)
index 0000000..96fc54a
--- /dev/null
@@ -0,0 +1,14 @@
+[Socket]
+ListenStream=/run/cynara/cynara-agent.socket
+SocketMode=0060
+SmackLabelIPIn=*
+SmackLabelIPOut=@
+
+Service=cynara.service
+
+[Unit]
+Wants=cynara.target
+Before=cynara.target
+
+[Install]
+WantedBy=sockets.target
index 847a294..99176fa 100644 (file)
@@ -12,6 +12,7 @@ Restart=always
 
 Sockets=cynara.socket
 Sockets=cynara-admin.socket
+Sockets=cynara-agent.socket
 
 UMask=0000
 User=cynara