GCC Code Coverage Report


Directory: src/gate/
File: src/gate/system/cxx_accounts.cpp
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 197 217 90.8%
Functions: 49 50 98.0%
Branches: 76 206 36.9%

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/system/accounts.hpp"
30 #include "gate/memalloc.hpp"
31 #include "gate/exceptions.hpp"
32 #include "gate/wrappers.hpp"
33
34 namespace gate
35 {
36 namespace sys
37 {
38
39 2 Accounts::User::User() noexcept
40 {
41 2 Mem::clear(this->impl);
42 2 this->impl.short_id = GATE_ACCOUNT_INVALID_SHORT_ID;
43 2 }
44
45 45 Accounts::User::User(gate_account_user_t const& user)
46 {
47 45 Mem::copy(this->impl, user);
48 45 }
49 38 Accounts::User::User(User const& src)
50 {
51 38 Mem::copy(this->impl, src.impl);
52 38 }
53 3 Accounts::User& Accounts::User::operator=(User const& src)
54 {
55
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (this != &src)
56 {
57 3 this->id_shadow = String();
58 3 this->name_shadow = String();
59 3 this->info_shadow = String();
60 3 this->descr_shadow = String();
61 3 Mem::copy(this->impl, src.impl);
62 }
63 3 return *this;
64 }
65
66 85 Accounts::User::~User() noexcept
67 {
68 85 Mem::clear(this->impl);
69 85 }
70
71 11 static String& shadow_update(char const* src, String& dst)
72 {
73
6/6
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 6 times.
11 if (dst.empty() && !gate_str_is_empty(src))
74 {
75 5 dst = String(src);
76 }
77 11 return dst;
78 }
79
80 2 String Accounts::User::Id()
81 {
82 2 return shadow_update(this->impl.id, this->id_shadow);
83 }
84 1 uint64_t Accounts::User::ShortId() const
85 {
86 1 return this->impl.short_id;
87 }
88 2 String Accounts::User::Name()
89 {
90 2 return shadow_update(this->impl.name, this->name_shadow);
91 }
92 1 String Accounts::User::Info()
93 {
94 1 return shadow_update(this->impl.info, this->info_shadow);
95 }
96 1 String Accounts::User::Description()
97 {
98 1 return shadow_update(this->impl.description, this->descr_shadow);
99 }
100 1 uint32_t Accounts::User::Flags() const
101 {
102 1 return this->impl.flags;
103 }
104 88 gate_account_user_t const* Accounts::User::c_impl() const
105 {
106 88 return &this->impl;
107 }
108
109 1 Accounts::Group::Group() noexcept
110 {
111 1 Mem::clear(this->impl);
112 1 }
113 127 Accounts::Group::Group(gate_account_group_t const& group)
114 {
115 127 Mem::copy(this->impl, group);
116 127 }
117 105 Accounts::Group::Group(Group const& src)
118 {
119 105 Mem::copy(this->impl, src.impl);
120 105 }
121 1 Accounts::Group& Accounts::Group::operator=(Group const& src)
122 {
123
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &src)
124 {
125 1 this->id_shadow = String();
126 1 this->name_shadow = String();
127 1 this->descr_shadow = String();
128 1 Mem::copy(this->impl, src.impl);
129 }
130 1 return *this;
131 }
132 233 Accounts::Group::~Group() noexcept
133 {
134 233 Mem::clear(this->impl);
135 233 }
136
137 2 String Accounts::Group::Id()
138 {
139 2 return shadow_update(this->impl.id, this->id_shadow);
140 }
141 1 uint64_t Accounts::Group::ShortId() const
142 {
143 1 return this->impl.short_id;
144 }
145 2 String Accounts::Group::Name()
146 {
147 2 return shadow_update(this->impl.name, this->name_shadow);
148 }
149 1 String Accounts::Group::Description()
150 {
151 1 return shadow_update(this->impl.description, this->descr_shadow);
152 }
153 1 uint32_t Accounts::Group::Flags() const
154 {
155 1 return this->impl.flags;
156 }
157 147 gate_account_group_t const* Accounts::Group::c_impl() const
158 {
159 147 return &this->impl;
160 }
161
162
163
164
165 struct GATE_API_LOCAL enumUsers_callback_dispatcher_param
166 {
167 Accounts::EnumUserCallback const* callback;
168 void* original_param;
169 Optional<Exception> error;
170
171 42 enumUsers_callback_dispatcher_param()
172 42 : callback(NULL), original_param(NULL)
173 {
174 42 }
175 };
176
177 21 static gate_bool_t GATE_CALL Accounts_enumUsers_callback_dispatcher(gate_account_user_t const* account_user, void* param)
178 {
179
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 if (account_user && param)
180 {
181 21 enumUsers_callback_dispatcher_param* disp_param = static_cast<enumUsers_callback_dispatcher_param*>(param);
182
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
21 ExceptionInfo xcptStatus;
183
2/8
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 7 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
21 GATEXX_TRY_CATCHINFO(xcptStatus, {
184 Accounts::User user(*account_user);
185 disp_param->callback->invoke(user, disp_param->original_param);
186 });
187
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
21 if (xcptStatus.failed())
188 {
189 disp_param->error.create(Exception(xcptStatus));
190 return false;
191 }
192 }
193 21 return true;
194 }
195
196 struct GATE_API_LOCAL enumGroups_callback_dispatcher_param
197 {
198 Accounts::EnumGroupCallback const* callback;
199 void* original_param;
200 Optional<Exception> error;
201
202 22 enumGroups_callback_dispatcher_param()
203 22 : callback(NULL), original_param(NULL)
204 {
205 22 }
206 };
207
208 62 static gate_bool_t GATE_CALL Accounts_enumGroups_callback_dispatcher(gate_account_group_t const* account_group, void* param)
209 {
210
2/4
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
62 if (account_group && param)
211 {
212 62 enumGroups_callback_dispatcher_param* disp_param = static_cast<enumGroups_callback_dispatcher_param*>(param);
213
1/2
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
62 ExceptionInfo xcptStatus;
214
2/8
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 62 times.
✗ Branch 7 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
62 GATEXX_TRY_CATCHINFO(xcptStatus, {
215 Accounts::Group group(*account_group);
216 disp_param->callback->invoke(group, disp_param->original_param);
217 });
218
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
62 if (xcptStatus.failed())
219 {
220 disp_param->error.create(Exception(xcptStatus));
221 return false;
222 }
223 }
224 62 return true;
225 }
226
227 21 static gate_bool_t GATE_CALL Accounts_listUsers_callback(gate_account_user_t const* account_user, void* param)
228 {
229
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 if (account_user && param)
230 {
231 21 ArrayList<Accounts::User>* list = static_cast<ArrayList<Accounts::User>*>(param);
232
1/2
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 GATEXX_TRY_IGNORE({
233 Accounts::User user(*account_user);
234 list->add(user);
235 });
236 }
237 21 return true;
238 }
239
240 62 static gate_bool_t GATE_CALL Accounts_listGroups_callback(gate_account_group_t const* account_group, void* param)
241 {
242
2/4
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
62 if (account_group && param)
243 {
244 62 ArrayList<Accounts::Group>* list = static_cast<ArrayList<Accounts::Group>*>(param);
245
1/2
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
62 GATEXX_TRY_IGNORE({
246 Accounts::Group user(*account_group);
247 list->add(user);
248 })
249 }
250 62 return true;
251 }
252 1 void Accounts::enumUsers(EnumUserCallback const& callback, void* param)
253 {
254
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 enumUsers_callback_dispatcher_param disp_param;
255 1 disp_param.callback = &callback;
256 1 disp_param.original_param = param;
257
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_account_enum_users(&Accounts_enumUsers_callback_dispatcher, &disp_param);
258
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
259
260
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!disp_param.error.empty())
261 {
262 if (disp_param.error->getResult() != results::Canceled)
263 {
264 Exception xcpt(*disp_param.error);
265 raise(xcpt);
266 }
267 }
268 1 }
269
270 1 Array<Accounts::User> Accounts::listUsers()
271 {
272
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 ArrayList<User> list(16);
273
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_account_enum_users(&Accounts_listUsers_callback, &list);
274
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
275
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return list.toArray();
276 }
277 1 Accounts::User Accounts::getUser(String const& id)
278 {
279 gate_account_user_t user;
280
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_account_get_user(id.c_impl(), &user);
281
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
282 2 return User(user);
283 }
284 2 Accounts::User Accounts::resolveUser(String const& name)
285 {
286 gate_account_user_t user;
287
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 result_t result = gate_account_resolve_user(name.c_impl(), &user);
288
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
289 4 return User(user);
290 }
291 1 void Accounts::createUser(String const& name, String const& password)
292 {
293
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_account_create_user(name.c_impl(), password.empty() ? NULL : password.c_impl());
294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
295 1 }
296 1 void Accounts::deleteUser(User const& user)
297 {
298 1 result_t result = gate_account_delete_user(user.c_impl());
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
300 1 }
301 21 void Accounts::enumUserMemberships(User const& user, EnumGroupCallback const& callback, void* param)
302 {
303
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
42 enumGroups_callback_dispatcher_param disp_param;
304 21 disp_param.callback = &callback;
305 21 disp_param.original_param = param;
306
1/2
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 result_t result = gate_account_enum_user_memberships(user.c_impl(), &Accounts_enumGroups_callback_dispatcher, &disp_param);
307
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
21 GATEXX_CHECK_EXCEPTION(result);
308
309
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
21 if (!disp_param.error.empty())
310 {
311 if (disp_param.error->getResult() != results::Canceled)
312 {
313 Exception xcpt(*disp_param.error);
314 raise(xcpt);
315 }
316 }
317 21 }
318 21 Array<Accounts::Group> Accounts::listUserMemberships(User const& user)
319 {
320
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
42 ArrayList<Group> list(16);
321
1/2
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
21 result_t result = gate_account_enum_user_memberships(user.c_impl(), &Accounts_listGroups_callback, &list);
322
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
21 GATEXX_CHECK_EXCEPTION(result);
323
1/2
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
42 return list.toArray();
324 }
325 21 Property Accounts::getUserProperties(User const& user)
326 {
327 21 Property prop;
328
2/4
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 21 times.
✗ Branch 6 not taken.
21 result_t result = gate_account_get_user_properties(user.c_impl(), prop.c_impl());
329
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
21 GATEXX_CHECK_EXCEPTION(result);
330 21 return prop;
331 }
332 void Accounts::setUserProperty(User const& user, String const& propName, Property const& propValue)
333 {
334 result_t result = gate_account_set_user_property(user.c_impl(), propName.c_impl(), propValue.c_impl());
335 GATEXX_CHECK_EXCEPTION(result);
336 }
337
338 1 void Accounts::enumGroups(EnumGroupCallback const& callback, void* param)
339 {
340
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 enumGroups_callback_dispatcher_param disp_param;
341 1 disp_param.callback = &callback;
342 1 disp_param.original_param = param;
343
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_account_enum_groups(&Accounts_enumGroups_callback_dispatcher, &disp_param);
344
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
345
346
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!disp_param.error.empty())
347 {
348 if (disp_param.error->getResult() != results::Canceled)
349 {
350 Exception xcpt(*disp_param.error);
351 raise(xcpt);
352 }
353 }
354
355 1 }
356 1 Array<Accounts::Group> Accounts::listGroups()
357 {
358
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 ArrayList<Group> list(16);
359
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_account_enum_groups(&Accounts_listGroups_callback, &list);
360
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
361
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return list.toArray();
362 }
363 1 Accounts::Group Accounts::getGroup(String const& id)
364 {
365 gate_account_group_t group;
366
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_account_get_group(id.c_impl(), &group);
367
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
368 2 return Group(group);
369 }
370 2 Accounts::Group Accounts::resolveGroup(String const& name)
371 {
372 gate_account_group_t group;
373
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 result_t result = gate_account_resolve_group(name.c_impl(), &group);
374
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
375 4 return Group(group);
376 }
377 1 void Accounts::createGroup(String const& name)
378 {
379 1 result_t result = gate_account_create_group(name.c_impl());
380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
381 1 }
382 1 void Accounts::deleteGroup(Group const& group)
383 {
384 1 result_t result = gate_account_delete_group(group.c_impl());
385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
386 1 }
387 41 void Accounts::enumGroupMembers(Group const& group, EnumUserCallback const& callback, void* param)
388 {
389
1/2
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
82 enumUsers_callback_dispatcher_param disp_param;
390 41 disp_param.callback = &callback;
391 41 disp_param.original_param = param;
392
1/2
✓ Branch 2 taken 41 times.
✗ Branch 3 not taken.
41 result_t result = gate_account_enum_group_members(group.c_impl(), &Accounts_enumUsers_callback_dispatcher, &disp_param);
393
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
41 GATEXX_CHECK_EXCEPTION(result);
394
395
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
41 if (!disp_param.error.empty())
396 {
397 if (disp_param.error->getResult() != results::Canceled)
398 {
399 Exception xcpt(*disp_param.error);
400 raise(xcpt);
401 }
402 }
403 41 }
404 41 Array<Accounts::User> Accounts::listGroupMembers(Group const& group)
405 {
406
1/2
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
82 ArrayList<User> list(16);
407
1/2
✓ Branch 2 taken 41 times.
✗ Branch 3 not taken.
41 result_t result = gate_account_enum_group_members(group.c_impl(), &Accounts_listUsers_callback, &list);
408
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
41 GATEXX_CHECK_EXCEPTION(result);
409
1/2
✓ Branch 1 taken 41 times.
✗ Branch 2 not taken.
82 return list.toArray();
410 }
411
412
413 1 void Accounts::addUserToGroup(User const& user, Group const& group)
414 {
415 1 result_t result = gate_account_add_user_to_group(user.c_impl(), group.c_impl());
416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
417 1 }
418 1 void Accounts::removeUserFromGroup(User const& user, Group const& group)
419 {
420 1 result_t result = gate_account_remove_user_from_group(user.c_impl(), group.c_impl());
421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
422 1 }
423
424 } // end of namespace sys
425 } // end of namespace gate
426