Change contact information to Mr Dongsun Lee
[platform/core/security/key-manager.git] / src / manager / main / generic-socket-manager.h
1 /*
2  *  Copyright (c) 2000-2019 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  *  Contact: Dongsun Lee <ds73.lee@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18 /*
19  * @file        generic-socket-manager.h
20  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
21  * @author      Zofia Abramowska (z.abramowska@samsung.com)
22  * @version     1.0
23  * @brief       Implementation of GenericSocketService and GenericSocketManager.
24  */
25
26 #ifndef _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_
27 #define _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_
28
29 #include <vector>
30 #include <string>
31
32 #include <sys/types.h>
33
34 #include <dpl/exception.h>
35 #include <generic-event.h>
36 #include <dpl/raw-buffer.h>
37 #include <ckm/ckm-type.h>
38 #include <credentials.h>
39 #include <service-messages.h>
40
41 extern "C" {
42         struct msghdr;
43 } // extern "C"
44
45 namespace CKM {
46
47 typedef int InterfaceID;
48
49 struct ConnectionID {
50         int sock;                                 // This is decriptor used for connection
51         int counter;                              // Unique handler per socket
52         inline bool operator<(const ConnectionID &second) const
53         {
54                 return counter < second.counter;
55         }
56 };
57
58 struct GenericSocketManager;
59
60 struct GenericSocketService {
61         typedef std::string ServiceHandlerPath;
62         struct ServiceDescription {
63                 ServiceDescription(const char *path,
64                                                    const char *privilege,
65                                                    InterfaceID interfaceID = 0,
66                                                    bool useSendMsg = false) :
67                         privilege(privilege),
68                         interfaceID(interfaceID),
69                         serviceHandlerPath(path),
70                         useSendMsg(useSendMsg) {}
71
72                 std::string privilege;
73
74                 // All data from serviceHandlerPath will be marked with this interfaceHandler
75                 InterfaceID interfaceID;
76
77                 // Path to file
78                 ServiceHandlerPath serviceHandlerPath;
79                 bool useSendMsg;
80         };
81
82         typedef std::vector<ServiceDescription> ServiceDescriptionVector;
83
84         struct AcceptEvent : public GenericEvent {
85                 ConnectionID connectionID;
86                 InterfaceID interfaceID;
87                 Credentials credentials;
88         };
89
90         struct WriteEvent : public GenericEvent {
91                 ConnectionID connectionID;
92                 size_t size;
93                 size_t left;
94         };
95
96         struct ReadEvent : public GenericEvent {
97                 ConnectionID connectionID;
98                 RawBuffer rawBuffer;
99         };
100
101         struct CloseEvent : public GenericEvent {
102                 ConnectionID connectionID;
103         };
104
105         struct SecurityEvent : public GenericEvent {
106                 ConnectionID connectionID;
107                 bool allowed;
108         };
109
110         virtual void SetSocketManager(GenericSocketManager *manager)
111         {
112                 m_serviceManager = manager;
113         }
114
115         virtual void SetCommManager(CommMgr *manager)
116         {
117                 m_commMgr = manager;
118         }
119
120         virtual ServiceDescriptionVector GetServiceDescription() = 0;
121         virtual void Event(const AcceptEvent &event) = 0;
122         virtual void Event(const WriteEvent &event) = 0;
123         virtual void Event(const ReadEvent &event) = 0;
124         virtual void Event(const CloseEvent &event) = 0;
125         virtual void Event(const SecurityEvent &event) = 0;
126
127         virtual void Start() = 0;
128         virtual void Stop() = 0;
129
130         GenericSocketService() : m_serviceManager(NULL), m_commMgr(NULL) {}
131         virtual ~GenericSocketService() {}
132
133 protected:
134         GenericSocketManager *m_serviceManager;
135         CommMgr *m_commMgr;
136 };
137
138 struct GenericSocketManager {
139         virtual void MainLoop() = 0;
140         virtual void MainLoopStop() = 0;
141         virtual void RegisterSocketService(GenericSocketService *ptr) = 0;
142         virtual void CynaraSocket(int oldFd, int newFd, bool isRW) = 0;
143         virtual void Close(ConnectionID connectionID) = 0;
144         virtual void Write(ConnectionID connectionID, const RawBuffer &rawBuffer) = 0;
145         virtual void SecurityCheck(ConnectionID connectionID) = 0;
146         virtual ~GenericSocketManager() {}
147 };
148
149 } // namespace CKM
150
151 #endif // _CENT_KEY_MNG_GENERIC_SERVICE_MANAGER_