GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/cxx_sessionhub.cpp
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 0 60 0.0%
Functions: 0 21 0.0%
Branches: 0 34 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, 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 #include "gate/tech/sessionhub.hpp"
30 #include "gate/structs.hpp"
31 #include "gate/arrays.hpp"
32 #include "gate/files.hpp"
33
34 namespace gate
35 {
36
37 // specialization must be done in gate namespace!
38 template<>
39 struct StructDescriptor<tech::SessionEntry> : public DynStructDescriptorBase<tech::SessionEntry>
40 {
41 StructDescriptor()
42 : DynStructDescriptorBase<tech::SessionEntry>("SessionEntry")
43 {
44 this->addMember(&struct_type_t::session_id, "session_id");
45 this->addMember(&struct_type_t::join_token, "join_token");
46 this->addMember(&struct_type_t::timeout_seconds, "timeout_seconds");
47 this->addMember(&struct_type_t::time_started_utc, "time_started_utc");
48 this->addMember(&struct_type_t::time_started, "time_started");
49 this->addMember(&struct_type_t::time_last_access, "time_last_access");
50 this->addMember(&struct_type_t::time_expiration, "time_expiration");
51 this->updateDescriptor();
52 }
53 };
54
55 namespace tech
56 {
57
58 class LockFileMutex
59 {
60 public:
61 explicit LockFileMutex(String const& lockfilepath);
62 ~LockFileMutex() noexcept;
63
64 private:
65 LockFileMutex(LockFileMutex const&);
66 LockFileMutex& operator=(LockFileMutex const&);
67
68 gate_file_t fileHandle;
69 };
70
71 LockFileMutex::LockFileMutex(String const& lockfilepath)
72 {
73 result_t result = gate_file_open(
74 lockfilepath.c_impl(),
75 GATE_STREAM_OPEN_READWRITE | GATE_FILE_OPEN_SHARED,
76 &this->fileHandle);
77 GATEXX_CHECK_EXCEPTION(result);
78
79 result = gate_file_lock(this->fileHandle, true);
80 if (GATE_FAILED(result))
81 {
82 gate_file_close(this->fileHandle);
83 GATEXX_RAISE_EXCEPTION(results::Failed, "Could not lock file", 1);
84 }
85 }
86
87 LockFileMutex::~LockFileMutex() noexcept
88 {
89 gate_file_close(this->fileHandle);
90 }
91
92 typedef Struct<SessionEntry> SessionEntryRecord;
93
94 static StaticString const accessLockFile = "access.loc";
95
96
97 SessionHub::SessionHub(String const& storage)
98 : storagePath(storage)
99 {
100 // ensure storage path exists:
101 if (!File::isDirectory(this->storagePath))
102 {
103 File::createDirectory(this->storagePath);
104 }
105
106 // create sessions root path:
107 static StaticString const sessionsSubDir = "sessions";
108 this->sessionsRootPath = File::buildPath(this->storagePath, sessionsSubDir);
109 if (!File::isDirectory(this->sessionsRootPath))
110 {
111 File::createDirectory(this->sessionsRootPath);
112 }
113
114 this->sessionsLockPath = File::buildPath(this->sessionsRootPath, accessLockFile);
115 if (!File::exists(this->sessionsLockPath))
116 {
117 File::setContent(this->sessionsLockPath, String());
118 }
119
120 static StaticString const publicSubDir = "public";
121 }
122
123 SessionHub::~SessionHub() noexcept
124 {
125 }
126
127 SessionEntry SessionHub::createSession()
128 {
129 return SessionEntry();
130 }
131
132 SessionEntry SessionHub::getSession(String const& sessionId)
133 {
134 return SessionEntry();
135 }
136
137 void SessionHub::deleteSession(String const& sessionId)
138 {
139 }
140
141 SessionLoginEntry SessionHub::createSessionLogin(String const& sessionId)
142 {
143 return SessionLoginEntry();
144 }
145
146 SessionLoginEntry SessionHub::getSessionLogin(String const& sessionLoginToken)
147 {
148 return SessionLoginEntry();
149 }
150
151 void SessionHub::deleteSessionLogin(String const& sessionLoginToken)
152 {
153 }
154
155 SessionServiceEntry SessionHub::createSessionService(String const& sessionId, String const& serviceId)
156 {
157 return SessionServiceEntry();
158 }
159
160 SessionServiceEntry SessionHub::getSessionService(String const& sessionId, String const& serviceId)
161 {
162 return SessionServiceEntry();
163 }
164
165 void SessionHub::deleteSessionService(String const& sessionId, String const& serviceId)
166 {
167
168 }
169
170 SessionChannelEntry SessionHub::createSessionChannel(String const& sessionId, String const& serviceId, String const& channelId)
171 {
172 return SessionChannelEntry();
173 }
174
175 SessionChannelEntry SessionHub::getSessionChannel(String const& sessionId, String const& serviceId, String const& channelId)
176 {
177 return SessionChannelEntry();
178 }
179
180 void SessionHub::deleteSessionChannel(String const& sessionId, String const& serviceId, String const& channelId)
181 {
182
183 }
184
185 void SessionHub::updateSessionChannel(String const& sessionId, String const& serviceId, String const& channelId, Blob const& data)
186 {
187
188 }
189
190 Array<Blob> SessionHub::readSessionChannel(String const& sessionId, String const& serviceId, String const& channelId,
191 uint64_t requestUpdateId, uint64_t& finalUpdateId)
192 {
193 return Array<Blob>();
194 }
195
196
197 String SessionHub::getStorageRoot()
198 {
199 // TODO
200 return String();
201 }
202
203 String SessionHub::createNewSessionId()
204 {
205 // TODO
206 return String();
207 }
208
209 String SessionHub::createNewJoinToken()
210 {
211 // TODO
212 return String();
213 }
214
215
216
217 } // end of namespace tech
218 } // end of namespace gate
219