GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/sessionhub.hpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 11 0.0%
Functions: 0 3 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 /** @file
30 * @brief Session Hub
31 * @ingroup gatetech_cpp
32 */
33
34 #ifndef GATE_TECH_SESSIONHUB_H_INCLUDED
35 #define GATE_TECH_SESSIONHUB_H_INCLUDED
36
37 #include "gate/tech/gate_tech_api.hpp"
38 #include "gate/strings.hpp"
39 #include "gate/times.hpp"
40 #include "gate/arrays.hpp"
41 #include "gate/maps.hpp"
42 #include "gate/blobs.hpp"
43
44 /*
45 * data-dir
46 * |
47 * +--public
48 * | |
49 * | +--service_id
50 * | |
51 * | +--access.lock
52 * | +--service.json
53 * | +--channel_id
54 * | |
55 * | +--access.lock
56 * | +--channel.json
57 * | +--record_id.bin
58 * +--sessions
59 * | |
60 * | +--access.lock
61 * | +--logins.json
62 * | +--session_id
63 * | |
64 * | +--access.lock
65 * | +--session.json
66 * | +--users.json
67 * | +--service_id
68 * +--user
69 * |
70 * +--user_id
71 * |
72 * +--access.lock
73 * +--user.json
74 */
75
76 namespace gate
77 {
78 namespace tech
79 {
80
81 struct GATE_TECH_CPP_API SessionEntry
82 {
83 String session_id;
84 String join_token;
85 int64_t timeout_seconds; // seconds until session is canceled with no access attempts (0==disabled)
86 int64_t time_started_utc; // system date when session starts
87 int64_t time_started; // session-start time counter
88 int64_t time_last_access; // last-access time counter
89 int64_t time_expiration; // session expiration time count (0==disabled)
90
91 SessionEntry()
92 : timeout_seconds(0),
93 time_started_utc(0),
94 time_started(0),
95 time_last_access(0),
96 time_expiration(0)
97 {
98 }
99 };
100
101 struct GATE_TECH_CPP_API SessionLoginEntry
102 {
103 String login_id;
104 String session_login_token; // unique token representing the login to a session
105 String user_id;
106 String session_id;
107 uint64_t flags;
108
109 SessionLoginEntry()
110 : flags(0)
111 {
112 }
113 };
114
115 struct GATE_TECH_CPP_API SessionLogins
116 {
117 ArrayList<SessionLoginEntry> logins;
118 };
119
120 struct GATE_TECH_CPP_API SessionServiceEntry
121 {
122 String service_id;
123 String session_id;
124 String service_name;
125 };
126
127 struct GATE_TECH_CPP_API SessionChannelEntry
128 {
129 String channel_id;
130 String service_id;
131 String session_id;
132 uint32_t channel_type;
133 uint32_t max_backlog; // max stored previous updates
134 uint64_t update_id; // id increased on every update
135
136 SessionChannelEntry()
137 : channel_type(0),
138 max_backlog(0),
139 update_id(0)
140 {
141 }
142 };
143
144
145 class GATE_TECH_CPP_API SessionHub
146 {
147 public:
148 SessionHub(String const& storage);
149 virtual ~SessionHub() noexcept;
150
151 SessionEntry createSession();
152 SessionEntry getSession(String const& sessionId);
153 void deleteSession(String const& sessionId);
154
155 SessionLoginEntry createSessionLogin(String const& sessionId);
156 SessionLoginEntry getSessionLogin(String const& sessionLoginToken);
157 void deleteSessionLogin(String const& sessionLoginToken);
158
159 SessionServiceEntry createSessionService(String const& sessionId, String const& serviceId);
160 SessionServiceEntry getSessionService(String const& sessionId, String const& serviceId);
161 void deleteSessionService(String const& sessionId, String const& serviceId);
162
163 SessionChannelEntry createSessionChannel(String const& sessionId, String const& serviceId, String const& channelId);
164 SessionChannelEntry getSessionChannel(String const& sessionId, String const& serviceId, String const& channelId);
165 void deleteSessionChannel(String const& sessionId, String const& serviceId, String const& channelId);
166 void updateSessionChannel(String const& sessionId, String const& serviceId, String const& channelId, Blob const& data);
167 Array<Blob> readSessionChannel(String const& sessionId, String const& serviceId, String const& channelId,
168 uint64_t requestUpdateId, uint64_t& finalUpdateId);
169
170
171
172
173 protected:
174 virtual String getStorageRoot();
175 virtual String createNewSessionId();
176 virtual String createNewJoinToken();
177
178 private:
179 String storagePath;
180 String sessionsRootPath;
181 String sessionsLockPath;
182 String publicPath;
183 };
184
185 } // end of namespace tech
186
187 } // end of namespace gate
188
189 #endif
190