GCC Code Coverage Report


Directory: src/gate/
File: src/gate/directories.c
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 359 403 89.1%
Functions: 56 57 98.2%
Branches: 91 160 56.9%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
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/directories.h"
30 #include "gate/debugging.h"
31 #include "gate/strings.h"
32 #include "gate/arrays.h"
33 #include "gate/utilities.h"
34
35 11 gate_directory_propertydef_t* gate_directory_propertydef_create(gate_directory_propertydef_t* propdef,
36 gate_type_id_t type,
37 gate_string_t const* name,
38 gate_enumint_t flags)
39 {
40 11 gate_mem_clear(propdef, sizeof(gate_directory_propertydef_t));
41
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (NULL == gate_string_duplicate(&propdef->name, name))
42 {
43 ✗ return NULL;
44 }
45 11 propdef->data_type = type;
46 11 propdef->flags = flags;
47 11 return propdef;
48 }
49
50 2 gate_directory_propertydef_t* gate_directory_propertydef_copy(
51 gate_directory_propertydef_t* dst_propdef,
52 gate_directory_propertydef_t const * src_propdef)
53 {
54 6 return gate_directory_propertydef_create(dst_propdef,
55 2 src_propdef->data_type,
56 &src_propdef->name,
57 src_propdef->flags);
58 }
59
60
61 12 void gate_directory_propertydef_release(gate_directory_propertydef_t* propdef)
62 {
63 12 gate_string_release(&propdef->name);
64 12 gate_mem_clear(propdef, sizeof(gate_directory_propertydef_t));
65 12 }
66
67 3 static gate_result_t GATE_CALL gate_directory_propertydef_cctor(void* dest, void const* src)
68 {
69 3 gate_directory_propertydef_t* ptr_dst = (gate_directory_propertydef_t*)dest;
70 3 gate_directory_propertydef_t const* ptr_src = (gate_directory_propertydef_t const*)src;
71 3 gate_directory_propertydef_t* ret = NULL;
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ptr_src == NULL)
73 {
74 static const gate_string_t empty_str = GATE_STRING_INIT_EMPTY;
75 ✗ ret = gate_directory_propertydef_create(ptr_dst, GATE_TYPE_EMPTY, &empty_str, 0);
76 }
77 else
78 {
79 3 ret = gate_directory_propertydef_create(ptr_dst, ptr_src->data_type, &ptr_src->name, ptr_src->flags);
80 }
81 return (NULL == ret)
82 ? GATE_RESULT_OUTOFMEMORY
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 : GATE_RESULT_OK;
84 }
85
86 1 static void GATE_CALL gate_directory_propertydef_dtor(void* dest)
87 {
88 1 gate_directory_propertydef_release((gate_directory_propertydef_t*)dest);
89 1 }
90
91
92 typedef struct dirclass
93 {
94 GATE_INTERFACE_VTBL(gate_directory_class) const* vtbl;
95
96 gate_atomic_int_t ref_counter;
97 gate_string_t uid;
98 gate_string_t name;
99 gate_enumint_t flags;
100 gate_array_t property_defs; /* array of gate_directory_propertydef_t */
101 gate_array_t superior_classes_uids; /* array of gate_string_t (uids) */
102 gate_array_t containment_classes_uids; /* array of gate_string_t (uids) */
103
104 } dirclass_t;
105
106 2 static char const* dirclass_get_interface_name(void* obj)
107 {
108 GATE_UNUSED_ARG(obj);
109 2 return GATE_INTERFACE_NAME_DIRECTORYCLASS;
110 }
111
112 1 static void dirclass_destroy(dirclass_t* self)
113 {
114 1 gate_string_release(&self->uid);
115 1 gate_string_release(&self->name);
116 1 gate_array_release(&self->property_defs);
117 1 gate_array_release(&self->superior_classes_uids);
118 1 gate_array_release(&self->containment_classes_uids);
119 1 gate_mem_dealloc(self);
120 1 }
121
122 8 static void dirclass_release(void* obj)
123 {
124 8 dirclass_t* const self = (dirclass_t*)obj;
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 GATE_DEBUG_ASSERT(self != NULL);
126
127
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 7 times.
8 if (gate_atomic_int_dec(&self->ref_counter) == 0)
128 {
129 1 dirclass_destroy(self);
130 }
131 8 }
132
133 7 static int dirclass_retain(void* obj)
134 {
135 7 dirclass_t* const self = (dirclass_t*)obj;
136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 GATE_DEBUG_ASSERT(self != NULL);
137 7 return gate_atomic_int_inc(&self->ref_counter);
138 }
139
140 2 static gate_result_t dirclass_uid(void* obj, gate_string_t* return_uid)
141 {
142 2 dirclass_t* const self = (dirclass_t*)obj;
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(self != NULL);
144 2 return NULL == gate_string_duplicate(return_uid, &self->uid)
145 ? GATE_RESULT_OUTOFMEMORY
146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 : GATE_RESULT_OK;
147 }
148 3 static gate_result_t dirclass_name(void* obj, gate_string_t* return_name)
149 {
150 3 dirclass_t* const self = (dirclass_t*)obj;
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATE_DEBUG_ASSERT(self != NULL);
152 3 return NULL == gate_string_duplicate(return_name, &self->name)
153 ? GATE_RESULT_OUTOFMEMORY
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 : GATE_RESULT_OK;
155 }
156 1 static gate_result_t dirclass_flags(void* obj, gate_enumint_t* return_flags)
157 {
158 1 dirclass_t* const self = (dirclass_t*)obj;
159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_ASSERT(self != NULL);
160 1 *return_flags = self->flags;
161 1 return GATE_RESULT_OK;
162 }
163
164 1 static gate_result_t dirclass_get_properties_count(void* obj, gate_size_t* return_count)
165 {
166 1 dirclass_t* const self = (dirclass_t*)obj;
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_ASSERT(self != NULL);
168 1 *return_count = gate_array_length(&self->property_defs);
169 1 return GATE_RESULT_OK;
170 }
171 2 static gate_result_t dirclass_get_property(void* obj, gate_size_t index, gate_directory_propertydef_t* return_prop_def)
172 {
173 2 dirclass_t* const self = (dirclass_t*)obj;
174 gate_directory_propertydef_t const* ptr_src;
175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(self != NULL);
176 2 ptr_src = gate_array_get(&self->property_defs, index);
177
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (NULL == ptr_src)
178 {
179 1 return GATE_RESULT_NOTAVAILABLE;
180 }
181 else
182 {
183 1 gate_directory_propertydef_t* def = gate_directory_propertydef_copy(return_prop_def, ptr_src);
184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 return def == NULL ? GATE_RESULT_OUTOFMEMORY : GATE_RESULT_OK;
185 }
186 }
187
188 2 static int find_propdef_name(void const* ptr_propdef, void const* ptr_str)
189 {
190 2 gate_directory_propertydef_t const* const propdef = (gate_directory_propertydef_t const*)ptr_propdef;
191 2 gate_string_t const* const ptr_name = (gate_string_t const*)ptr_str;
192 2 return gate_string_comp(&propdef->name, ptr_name);
193 }
194
195 2 static gate_result_t dirclass_find_property(void* obj, gate_string_t const* name, gate_directory_propertydef_t* return_prop_def)
196 {
197 2 dirclass_t* const self = (dirclass_t*)obj;
198 gate_size_t ndx;
199
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(self != NULL);
201 2 ndx = gate_array_find(&self->property_defs, find_propdef_name, name, 0);
202
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (ndx == GATE_ARRAY_NPOS)
203 {
204 1 return GATE_RESULT_NOMATCH;
205 }
206 else
207 {
208 1 gate_directory_propertydef_t const* src = gate_array_get(&self->property_defs, ndx);
209 1 return NULL == gate_directory_propertydef_copy(return_prop_def, src)
210 ? GATE_RESULT_OUTOFMEMORY
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
212 }
213 }
214
215 1 static gate_result_t dirclass_get_superior_classes_count(void* obj, gate_size_t * return_count)
216 {
217 1 dirclass_t* const self = (dirclass_t*)obj;
218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_ASSERT(self != NULL);
219 1 *return_count = gate_array_length(&self->superior_classes_uids);
220 1 return GATE_RESULT_OK;
221 }
222 2 static gate_result_t dirclass_get_superior_class_uid(void* obj, gate_size_t index, gate_string_t * return_class_uid)
223 {
224 2 dirclass_t* const self = (dirclass_t*)obj;
225 gate_string_t const* src;
226
227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(self != NULL);
228 2 src = (gate_string_t const*)gate_array_get(&self->superior_classes_uids, index);
229
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (src == NULL)
230 {
231 1 return GATE_RESULT_OUTOFBOUNDS;
232 }
233 else
234 {
235 1 return NULL == gate_string_duplicate(return_class_uid, src)
236 ? GATE_RESULT_OUTOFMEMORY
237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
238 }
239 }
240
241 1 static gate_result_t dirclass_get_containment_classes_count(void* obj, gate_size_t * return_count)
242 {
243 1 dirclass_t* const self = (dirclass_t*)obj;
244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_ASSERT(self != NULL);
245 1 *return_count = gate_array_length(&self->superior_classes_uids);
246 1 return GATE_RESULT_OK;
247 }
248 2 static gate_result_t dirclass_get_containment_class_uid(void* obj, gate_size_t index, gate_string_t* return_class_uid)
249 {
250 2 dirclass_t* const self = (dirclass_t*)obj;
251 gate_string_t const* src;
252
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATE_DEBUG_ASSERT(self != NULL);
254 2 src = (gate_string_t const*)gate_array_get(&self->containment_classes_uids, index);
255
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (src == NULL)
256 {
257 1 return GATE_RESULT_OUTOFBOUNDS;
258 }
259 else
260 {
261 1 return NULL == gate_string_duplicate(return_class_uid, src)
262 ? GATE_RESULT_OUTOFMEMORY
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
264 }
265 }
266
267 3 static GATE_INTERFACE_VTBL(gate_directory_class)* dirclass_vtbl()
268 {
269 static GATE_INTERFACE_VTBL(gate_directory_class) vtbl;
270
271
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (vtbl.get_interface_name == NULL)
272 {
273 1 GATE_INTERFACE_VTBL(gate_directory_class) local_vtbl =
274 {
275 &dirclass_get_interface_name,
276 &dirclass_release,
277 &dirclass_retain,
278
279 &dirclass_uid,
280 &dirclass_name,
281 &dirclass_flags,
282
283 &dirclass_get_properties_count,
284 &dirclass_get_property,
285 &dirclass_find_property,
286
287 &dirclass_get_superior_classes_count,
288 &dirclass_get_superior_class_uid,
289
290 &dirclass_get_containment_classes_count,
291 &dirclass_get_containment_class_uid
292 };
293 1 vtbl = local_vtbl;
294 }
295 3 return &vtbl;
296 }
297
298 3 gate_directory_class_t* gate_directory_class_create(
299 gate_string_t const* uid,
300 gate_string_t const* name,
301 gate_enumint_t flags,
302 gate_directory_propertydef_t const* prop_defs, gate_size_t prop_defs_count,
303 gate_string_t const* superiors, gate_size_t superiors_count,
304 gate_string_t const* containment, gate_size_t containment_count
305 )
306 {
307 3 gate_directory_class_t* ret = NULL;
308 3 dirclass_t* impl = NULL;
309 do
310 {
311 gate_arraylist_t arrlist;
312
313 3 impl = (dirclass_t*)gate_mem_alloc(sizeof(dirclass_t));
314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (impl == NULL)
315 {
316 ✗ break;
317 }
318 3 gate_mem_clear(impl, sizeof(dirclass_t));
319 3 impl->vtbl = dirclass_vtbl();
320 3 gate_atomic_int_init(&impl->ref_counter, 1);
321
322 3 gate_string_duplicate(&impl->uid, uid);
323 3 gate_string_duplicate(&impl->name, name);
324 3 impl->flags = flags;
325
326
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (NULL == gate_array_create_list(&impl->property_defs,
327 sizeof(gate_directory_propertydef_t), prop_defs, prop_defs_count,
328 &gate_directory_propertydef_cctor, &gate_directory_propertydef_dtor)
329
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 || NULL == gate_array_create_list(&impl->superior_classes_uids,
330 sizeof(gate_string_t), superiors, superiors_count,
331 &gate_string_duplicate_constructor, &gate_string_destructor)
332
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 || NULL == gate_array_create_list(&impl->containment_classes_uids,
333 sizeof(gate_string_t), containment, containment_count,
334 &gate_string_duplicate_constructor, &gate_string_destructor)
335 )
336 {
337 /* one allocation above has failed */
338 break;
339 }
340
341 /* success case */
342 3 ret = (gate_directory_class_t*)impl;
343 3 impl = NULL;
344 } while (0);
345
346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (impl != NULL)
347 {
348 ✗ dirclass_destroy(impl);
349 }
350 3 return ret;
351 }
352
353
354
355 typedef struct direntry
356 {
357 GATE_INTERFACE_VTBL(gate_directory_entry) const* vtbl;
358
359 gate_atomic_int_t ref_counter;
360 gate_directory_provider_t* provider;
361 gate_string_t entry_uid;
362 gate_string_t class_uid;
363 gate_string_t name;
364 gate_string_t path;
365 gate_string_t parent_path;
366 gate_map_t properties;
367 } direntry_t;
368
369 1 static char const* direntry_get_interface_name(void* obj)
370 {
371 GATE_UNUSED_ARG(obj);
372 1 return GATE_INTERFACE_NAME_DIRECTORYENTRY;
373 }
374 11 static void direntry_destroy(direntry_t* self)
375 {
376 11 gate_map_destroy(&self->properties);
377 11 gate_string_release(&self->parent_path);
378 11 gate_string_release(&self->name);
379 11 gate_string_release(&self->path);
380 11 gate_string_release(&self->class_uid);
381 11 gate_string_release(&self->entry_uid);
382
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if (NULL != self->provider)
383 {
384 8 gate_object_release(self->provider);
385 }
386 11 gate_mem_dealloc(self);
387 11 }
388 107 static void direntry_release(void* obj)
389 {
390 107 direntry_t* const self = (direntry_t*)obj;
391
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 96 times.
107 if (gate_atomic_int_dec(&self->ref_counter) == 0)
392 {
393 11 direntry_destroy(self);
394 }
395 107 }
396 96 static int direntry_retain(void* obj)
397 {
398 96 direntry_t* const self = (direntry_t*)obj;
399 96 return gate_atomic_int_inc(&self->ref_counter);
400 }
401
402 1 static gate_result_t direntry_entry_uid(void* obj, gate_string_t* return_entry_uid)
403 {
404 1 direntry_t* const self = (direntry_t*)obj;
405 1 return NULL == gate_string_duplicate(return_entry_uid, &self->entry_uid)
406 ? GATE_RESULT_OUTOFMEMORY
407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
408 }
409 1 static gate_result_t direntry_class_uid(void* obj, gate_string_t* return_class_uid)
410 {
411 1 direntry_t* const self = (direntry_t*)obj;
412 1 return NULL == gate_string_duplicate(return_class_uid, &self->class_uid)
413 ? GATE_RESULT_OUTOFMEMORY
414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
415 }
416
417 1 static gate_result_t direntry_path(void* obj, gate_string_t* return_path)
418 {
419 1 direntry_t* const self = (direntry_t*)obj;
420 1 return NULL == gate_string_duplicate(return_path, &self->path)
421 ? GATE_RESULT_OUTOFMEMORY
422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
423 }
424 1 static gate_result_t direntry_name(void* obj, gate_string_t* return_name)
425 {
426 1 direntry_t* const self = (direntry_t*)obj;
427 1 return NULL == gate_string_duplicate(return_name, &self->name)
428 ? GATE_RESULT_OUTOFMEMORY
429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
430 }
431 1 static gate_result_t direntry_parent_path(void* obj, gate_string_t * return_parent)
432 {
433 1 direntry_t* const self = (direntry_t*)obj;
434 1 return NULL == gate_string_duplicate(return_parent, &self->parent_path)
435 ? GATE_RESULT_OUTOFMEMORY
436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 : GATE_RESULT_OK;
437 }
438
439 3 static gate_result_t direntry_get_property(void* obj, gate_string_t const* prop_name, gate_value_t* return_value)
440 {
441 3 direntry_t* const self = (direntry_t*)obj;
442 3 gate_map_iterator_t iter = gate_map_get(&self->properties, prop_name);
443
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
3 if (gate_map_iterator_valid(iter))
444 {
445 2 gate_value_t const* ptr_value = (gate_value_t const*)gate_map_iterator_value(iter);
446
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (NULL == gate_value_clone(ptr_value, return_value))
447 {
448 ✗ return GATE_RESULT_OUTOFMEMORY;
449 }
450 2 return GATE_RESULT_OK;
451 }
452 else
453 {
454 1 return GATE_RESULT_NOMATCH;
455 }
456 }
457 1 static gate_result_t direntry_set_property(void* obj, gate_string_t const* prop_name, gate_value_t const* value)
458 {
459 1 direntry_t* const self = (direntry_t*)obj;
460 1 gate_result_t ret = GATE_RESULT_OK;
461 do
462 {
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (self->provider)
464 {
465 gate_map_t strvalue_map;
466 ✗ if (NULL == gate_util_stringvaluemap_create(&strvalue_map))
467 {
468 ✗ ret = GATE_RESULT_OUTOFMEMORY;
469 ✗ break;
470 }
471 ✗ gate_util_stringvaluemap_add_string(&strvalue_map,
472 ✗ prop_name, value->value_type, &value->content);
473
474 ✗ ret = self->provider->vtbl->write_properties(self->provider,
475 (gate_directory_entry_t*)self, &strvalue_map);
476 ✗ gate_map_destroy(&strvalue_map);
477 }
478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_BREAK_IF_FAILED(ret);
479 1 gate_util_stringvaluemap_add_string(&self->properties,
480 1 prop_name, value->value_type, &value->content);
481 } while (0);
482 1 return ret;
483 }
484 1 static gate_result_t direntry_refresh_properties(void* obj)
485 {
486 1 direntry_t* const self = (direntry_t*)obj;
487 gate_result_t ret;
488
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (self->provider == NULL)
489 {
490 1 ret = GATE_RESULT_NOTAVAILABLE;
491 }
492 else
493 {
494 ✗ gate_map_t strvalue_map = GATE_INIT_EMPTY;
495 ✗ gate_array_t const* ptr_requested_properties = NULL; /* <- request all */
496 ✗ ret = gate_directory_provider_read_properties(self->provider,
497 (gate_directory_entry_t*)self,
498 ptr_requested_properties,
499 &strvalue_map);
500 ✗ if (GATE_SUCCEEDED(ret))
501 {
502 ✗ gate_map_destroy(&self->properties);
503 ✗ gate_mem_copy(&self->properties, &strvalue_map, sizeof(strvalue_map));
504 }
505 }
506 1 return ret;
507 }
508
509
510 11 static GATE_INTERFACE_VTBL(gate_directory_entry)* direntry_vtbl()
511 {
512 static GATE_INTERFACE_VTBL(gate_directory_entry) vtbl;
513
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (vtbl.get_interface_name == NULL)
514 {
515 1 GATE_INTERFACE_VTBL(gate_directory_entry) local_vtbl =
516 {
517 &direntry_get_interface_name,
518 &direntry_release,
519 &direntry_retain,
520
521 &direntry_entry_uid,
522 &direntry_class_uid,
523
524 &direntry_path,
525 &direntry_name,
526 &direntry_parent_path,
527
528 &direntry_get_property,
529 &direntry_set_property,
530 &direntry_refresh_properties
531 };
532 1 vtbl = local_vtbl;
533 }
534 11 return &vtbl;
535 }
536
537 11 gate_directory_entry_t* gate_directory_entry_create(
538 gate_directory_provider_t* provider,
539 gate_string_t const* entry_uid,
540 gate_string_t const* class_uid,
541 gate_string_t const* name,
542 gate_string_t const* path,
543 gate_string_t const* parent_path,
544 gate_map_t const* properties
545 )
546 {
547 11 gate_directory_entry_t* ret = NULL;
548 11 direntry_t* impl = NULL;
549 do
550 {
551 11 impl = (direntry_t*)gate_mem_alloc(sizeof(direntry_t));
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (impl == NULL)
553 {
554 ✗ break;
555 }
556 11 gate_mem_clear(impl, sizeof(direntry_t));
557 11 impl->vtbl = direntry_vtbl();
558 11 gate_atomic_int_init(&impl->ref_counter, 1);
559 11 impl->provider = provider;
560
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if (impl->provider != NULL)
561 {
562 8 gate_object_retain(impl->provider);
563 }
564 11 gate_string_duplicate(&impl->entry_uid, entry_uid);
565 11 gate_string_duplicate(&impl->class_uid, class_uid);
566 11 gate_string_duplicate(&impl->name, name);
567 11 gate_string_duplicate(&impl->path, path);
568 11 gate_string_duplicate(&impl->parent_path, parent_path);
569
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (NULL == gate_map_copy(&impl->properties, properties))
570 {
571 ✗ break;
572 }
573
574 /* success case reached */
575 11 ret = (gate_directory_entry_t*)impl;
576 11 impl = NULL;
577 } while (0);
578
579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (impl != NULL)
580 {
581 ✗ direntry_destroy(impl);
582 }
583 11 return ret;
584 }
585
586
587
588
589
590 typedef struct baseprov
591 {
592 GATE_INTERFACE_VTBL(gate_directory_provider) const* vtbl;
593 gate_atomic_int_t ref_counter;
594
595 gate_string_t name;
596 gate_map_t classes;
597
598 gate_directory_base_callback_uninit_t uninit;
599 gate_directory_base_callback_entry_by_path_t entry_by_path;
600 gate_directory_base_callback_entry_by_uid_t entry_by_uid;
601 gate_directory_base_callback_search_t search;
602 gate_directory_base_callback_child_t get_child;
603 gate_directory_base_callback_create_t create;
604 gate_directory_base_callback_delete_t delete;
605 gate_directory_base_callback_copy_t copy;
606 gate_directory_base_callback_move_t move;
607 gate_directory_base_callback_readprops_t readprops;
608 gate_directory_base_callback_writeprops_t writeprops;
609 gate_directory_base_callback_open_t open;
610
611 gate_c_maxalign_t internal_data;
612
613 } baseprov_t;
614
615 2 static void baseprov_destroy(baseprov_t* self)
616 {
617
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (self->uninit != NULL)
618 {
619 2 self->uninit((gate_directory_provider_t*)self, &self->internal_data);
620 }
621 2 gate_string_release(&self->name);
622 2 gate_map_destroy(&self->classes);
623 2 gate_mem_dealloc(self);
624 2 }
625
626 ✗ static char const* baseprov_get_interface_name(void* obj)
627 {
628 GATE_UNUSED_ARG(obj);
629 ✗ return GATE_INTERFACE_NAME_DIRECTORYPROVIDER;
630 }
631 48 static void baseprov_release(void* obj)
632 {
633 48 baseprov_t* const self = (baseprov_t*)obj;
634
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 46 times.
48 if (gate_atomic_int_dec(&self->ref_counter) == 0)
635 {
636 2 baseprov_destroy(self);
637 }
638 48 }
639 46 static int baseprov_retain(void* obj)
640 {
641 46 baseprov_t* const self = (baseprov_t*)obj;
642 46 return gate_atomic_int_inc(&self->ref_counter);
643 }
644
645 1 static gate_result_t baseprov_provider_name(void* obj, gate_string_t* return_name)
646 {
647 1 baseprov_t* const self = (baseprov_t*)obj;
648 1 gate_string_duplicate(return_name, &self->name);
649 1 return GATE_RESULT_OK;
650 }
651 1 static gate_result_t baseprov_get_classes_count(void* obj, gate_size_t* return_count)
652 {
653 1 baseprov_t* const self = (baseprov_t*)obj;
654 1 *return_count = gate_map_count(&self->classes);
655 1 return GATE_RESULT_OK;
656 }
657 1 static gate_result_t baseprov_get_class(void* obj, gate_size_t index,
658 gate_directory_class_t** return_class_ptr)
659 {
660 1 baseprov_t* const self = (baseprov_t*)obj;
661 1 gate_map_iterator_t iter = gate_map_first(&self->classes);
662 gate_size_t n;
663
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 for (n = 0; gate_map_iterator_valid(iter); iter = gate_map_iterator_next(iter), ++n)
664 {
665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (n == index)
666 {
667
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (return_class_ptr != NULL)
668 {
669 1 *return_class_ptr = *(gate_directory_class_t**)gate_map_iterator_value(iter);
670 1 gate_object_retain(*return_class_ptr);
671 }
672 1 return GATE_RESULT_OK;
673 }
674 }
675 ✗ return GATE_RESULT_NOMATCH;
676 }
677 1 static gate_result_t baseprov_find_class(void* obj, gate_string_t const* class_uid,
678 gate_directory_class_t** return_class_ptr)
679 {
680 1 baseprov_t* const self = (baseprov_t*)obj;
681 1 gate_map_iterator_t iter = gate_map_get(&self->classes, class_uid);
682
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (gate_map_iterator_valid(iter))
683 {
684
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (return_class_ptr != NULL)
685 {
686 1 *return_class_ptr = *(gate_directory_class_t**)gate_map_iterator_value(iter);
687 1 gate_object_retain(*return_class_ptr);
688 }
689 1 return GATE_RESULT_OK;
690 }
691 ✗ return GATE_RESULT_NOMATCH;
692 }
693
694 2 static gate_result_t baseprov_get_entry_by_path(void* obj, gate_string_t const* path,
695 gate_directory_entry_t** return_entry_ptr)
696 {
697 2 baseprov_t* const self = (baseprov_t*)obj;
698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->entry_by_path == NULL)
699 {
700 ✗ return GATE_RESULT_NOTIMPLEMENTED;
701 }
702 else
703 {
704 2 return self->entry_by_path(
705 2 (gate_directory_provider_t*)self, &self->internal_data,
706 path, return_entry_ptr);
707 }
708 }
709
710 2 static gate_result_t baseprov_get_entry_by_uid(void* obj, gate_string_t const* uid,
711 gate_directory_entry_t** return_entry_ptr)
712 {
713 2 baseprov_t* const self = (baseprov_t*)obj;
714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->entry_by_uid == NULL)
715 {
716 ✗ return GATE_RESULT_NOTIMPLEMENTED;
717 }
718 else
719 {
720 2 return self->entry_by_uid(
721 2 (gate_directory_provider_t*)self, &self->internal_data,
722 uid, return_entry_ptr);
723 }
724 }
725
726 2 static gate_result_t baseprov_search_entries(void* obj, gate_directory_entry_t* search_root,
727 gate_string_t const* query, gate_enumint_t search_flags,
728 gate_directory_search_callback_t callback, void* callback_param)
729 {
730 2 baseprov_t* const self = (baseprov_t*)obj;
731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->search == NULL)
732 {
733 ✗ return GATE_RESULT_NOTIMPLEMENTED;
734 }
735 else
736 {
737 2 return self->search(
738 2 (gate_directory_provider_t*)self, &self->internal_data,
739 search_root, query, search_flags, callback, callback_param);
740 }
741 }
742
743 4 static gate_result_t baseprov_get_child_entry(void* obj, gate_directory_entry_t* parent,
744 gate_string_t const* class_uid, gate_string_t const* child_name,
745 gate_directory_entry_t** return_entry_ptr)
746 {
747 4 baseprov_t* const self = (baseprov_t*)obj;
748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (self->get_child == NULL)
749 {
750 ✗ return GATE_RESULT_NOTIMPLEMENTED;
751 }
752 else
753 {
754 4 return self->get_child(
755 4 (gate_directory_provider_t*)self, &self->internal_data,
756 parent, class_uid, child_name,
757 return_entry_ptr);
758 }
759 }
760
761 2 static gate_result_t baseprov_create_entry(void* obj, gate_directory_entry_t* parent,
762 gate_string_t const* class_uid, gate_string_t const* child_name,
763 gate_map_t const* propname_to_value_map, gate_stream_t* stream_to_copy,
764 gate_directory_entry_t** return_entry_ptr)
765 {
766 2 baseprov_t* const self = (baseprov_t*)obj;
767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->create == NULL)
768 {
769 ✗ return GATE_RESULT_NOTIMPLEMENTED;
770 }
771 else
772 {
773 2 return self->create(
774 2 (gate_directory_provider_t*)self, &self->internal_data,
775 parent, class_uid, child_name,
776 propname_to_value_map, stream_to_copy,
777 return_entry_ptr);
778 }
779 }
780
781 2 static gate_result_t baseprov_delete_entry(void* obj, gate_directory_entry_t* entry)
782 {
783 2 baseprov_t* const self = (baseprov_t*)obj;
784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->delete == NULL)
785 {
786 ✗ return GATE_RESULT_NOTIMPLEMENTED;
787 }
788 else
789 {
790 2 return self->delete(
791 2 (gate_directory_provider_t*)self, &self->internal_data,
792 entry);
793 }
794 }
795
796 2 static gate_result_t baseprov_copy_entry(void* obj,
797 gate_directory_entry_t* source, gate_directory_entry_t* target_container,
798 gate_string_t const* new_name, gate_enumint_t copy_flags,
799 gate_directory_entry_t** return_entry_ptr)
800 {
801 2 baseprov_t* const self = (baseprov_t*)obj;
802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->copy == NULL)
803 {
804 ✗ return GATE_RESULT_NOTIMPLEMENTED;
805 }
806 else
807 {
808 2 return self->copy(
809 2 (gate_directory_provider_t*)self, &self->internal_data,
810 source, target_container, new_name, copy_flags,
811 return_entry_ptr);
812 }
813 }
814
815 2 static gate_result_t baseprov_move_entry(void* obj,
816 gate_directory_entry_t* source, gate_directory_entry_t* target_container,
817 gate_string_t const* new_name, gate_enumint_t move_flags,
818 gate_directory_entry_t** return_entry_ptr)
819 {
820 2 baseprov_t* const self = (baseprov_t*)obj;
821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->move == NULL)
822 {
823 ✗ return GATE_RESULT_NOTIMPLEMENTED;
824 }
825 else
826 {
827 2 return self->move(
828 2 (gate_directory_provider_t*)self, &self->internal_data,
829 source, target_container, new_name, move_flags,
830 return_entry_ptr);
831 }
832 }
833
834 2 static gate_result_t baseprov_read_properties(void* obj,
835 gate_directory_entry_t* source, gate_array_t const* prop_names,
836 gate_map_t* return_str_value_map)
837 {
838 2 baseprov_t* const self = (baseprov_t*)obj;
839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->readprops == NULL)
840 {
841 ✗ return GATE_RESULT_NOTIMPLEMENTED;
842 }
843 else
844 {
845 2 return self->readprops(
846 2 (gate_directory_provider_t*)self, &self->internal_data,
847 source, prop_names, return_str_value_map);
848 }
849 }
850
851 2 static gate_result_t baseprov_write_properties(void* obj,
852 gate_directory_entry_t* source, gate_map_t const* str_value_map)
853 {
854 2 baseprov_t* const self = (baseprov_t*)obj;
855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->writeprops == NULL)
856 {
857 ✗ return GATE_RESULT_NOTIMPLEMENTED;
858 }
859 else
860 {
861 2 return self->writeprops(
862 2 (gate_directory_provider_t*)self, &self->internal_data,
863 source, str_value_map);
864 }
865 }
866
867 2 static gate_result_t baseprov_open_stream(void* obj,
868 gate_directory_entry_t* source, gate_string_t const* stream_name, gate_enumint_t open_flags,
869 gate_stream_t** return_stream)
870 {
871 2 baseprov_t* const self = (baseprov_t*)obj;
872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (self->open == NULL)
873 {
874 ✗ return GATE_RESULT_NOTIMPLEMENTED;
875 }
876 else
877 {
878 2 return self->open(
879 2 (gate_directory_provider_t*)self, &self->internal_data,
880 source, stream_name, open_flags, return_stream);
881 }
882 }
883
884
885
886 2 static GATE_INTERFACE_VTBL(gate_directory_provider)* baseprov_vtbl()
887 {
888 static GATE_INTERFACE_VTBL(gate_directory_provider) vtbl;
889
890
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (vtbl.get_interface_name == NULL)
891 {
892 1 GATE_INTERFACE_VTBL(gate_directory_provider) local_vtbl = {
893 &baseprov_get_interface_name,
894 &baseprov_release,
895 &baseprov_retain,
896
897 &baseprov_provider_name,
898 &baseprov_get_classes_count,
899 &baseprov_get_class,
900 &baseprov_find_class,
901 &baseprov_get_entry_by_path,
902 &baseprov_get_entry_by_uid,
903 &baseprov_search_entries,
904 &baseprov_get_child_entry,
905 &baseprov_create_entry,
906 &baseprov_delete_entry,
907 &baseprov_copy_entry,
908 &baseprov_move_entry,
909 &baseprov_read_properties,
910 &baseprov_write_properties,
911 &baseprov_open_stream
912 };
913 1 vtbl = local_vtbl;
914 }
915 2 return &vtbl;
916 }
917
918 2 gate_directory_provider_t* gate_directory_provider_base_create(
919 gate_string_t const* provider_name,
920 gate_directory_class_t* const* classes,
921 gate_size_t classes_count,
922 void* internal_data,
923 gate_size_t internal_data_size,
924 gate_directory_base_callback_init_t init_cb,
925 gate_directory_base_callback_uninit_t uninit_cb,
926 gate_directory_base_callback_entry_by_path_t entry_by_path_cb,
927 gate_directory_base_callback_entry_by_uid_t entry_by_uid_cb,
928 gate_directory_base_callback_search_t search_cb,
929 gate_directory_base_callback_child_t get_child_cb,
930 gate_directory_base_callback_create_t create_cb,
931 gate_directory_base_callback_delete_t delete_cb,
932 gate_directory_base_callback_copy_t copy_cb,
933 gate_directory_base_callback_move_t move_cb,
934 gate_directory_base_callback_readprops_t readprops_cb,
935 gate_directory_base_callback_writeprops_t writeprops_cb,
936 gate_directory_base_callback_open_t open_cb
937 )
938 {
939 2 gate_directory_provider_t* ret = NULL;
940 2 baseprov_t* impl = NULL;
941 do
942 {
943 2 gate_size_t const total_size = sizeof(baseprov_t) + internal_data_size;
944 2 impl = (baseprov_t*)gate_mem_alloc(total_size);
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (impl == NULL)
946 {
947 ✗ GATE_DEBUG_TRACE("directory-base-provider allocation failed");
948 ✗ break;
949 }
950 2 gate_mem_clear(impl, total_size);
951 2 impl->vtbl = baseprov_vtbl();
952 2 gate_atomic_int_init(&impl->ref_counter, 1);
953
954 2 gate_string_duplicate(&impl->name, provider_name);
955
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (NULL == gate_map_create(&impl->classes, &gate_compare_string,
956 sizeof(gate_string_t), &gate_string_duplicate_constructor, &gate_string_destructor,
957 sizeof(gate_object_ptr_t), &gate_object_ptr_copyctor, &gate_object_ptr_dtor))
958 {
959 ✗ GATE_DEBUG_TRACE("directory-base-provider-array allocation failed");
960 ✗ break;
961 }
962
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (; classes_count != 0; --classes_count, ++classes)
963 {
964 2 gate_string_t name = GATE_STRING_INIT_EMPTY;
965 2 gate_result_t result = gate_directory_class_name(*classes, &name);
966
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (GATE_SUCCEEDED(result))
967 {
968 2 gate_map_add(&impl->classes, &name, classes);
969 2 gate_string_release(&name);
970 }
971 }
972
973 2 impl->uninit = uninit_cb;
974 2 impl->entry_by_path = entry_by_path_cb;
975 2 impl->entry_by_uid = entry_by_uid_cb;
976 2 impl->search = search_cb;
977 2 impl->get_child = get_child_cb;
978 2 impl->create = create_cb;
979 2 impl->delete = delete_cb;
980 2 impl->copy = copy_cb;
981 2 impl->move = move_cb;
982 2 impl->readprops = readprops_cb;
983 2 impl->writeprops = writeprops_cb;
984 2 impl->open = open_cb;
985
986
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (internal_data != NULL && internal_data_size != 0)
987 {
988 2 gate_mem_copy(&impl->internal_data, internal_data, internal_data_size);
989 }
990
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (init_cb != NULL)
991 {
992 2 gate_result_t result = init_cb((gate_directory_provider_t*)impl, &impl->internal_data);
993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (GATE_FAILED(result))
994 {
995 ✗ GATE_DEBUG_TRACE_FAILED(result, "directory-base-provider init failed");
996 ✗ impl->uninit = NULL; /* disable uninit-call */
997 ✗ break;
998 }
999 }
1000
1001 /* success-case */
1002 2 ret = (gate_directory_provider_t*)impl;
1003 2 impl = NULL;
1004 } while (0);
1005
1006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (impl != NULL)
1007 {
1008 ✗ baseprov_destroy(impl);
1009 }
1010 2 return ret;
1011 }
1012