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