36
36
#include <stdio.h>
37
37
#endif
38
38
39
- #define CTL_MAX_ENTRIES 100
40
-
41
39
#define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */
42
40
43
41
#define CTL_STRING_QUERY_SEPARATOR ";"
49
47
static int ctl_global_first_free = 0 ;
50
48
static umf_ctl_node_t CTL_NODE (global )[CTL_MAX_ENTRIES ];
51
49
52
- /*
53
- * This is the top level node of the ctl tree structure. Each node can contain
54
- * children and leaf nodes.
55
- *
56
- * Internal nodes simply create a new path in the tree whereas child nodes are
57
- * the ones providing the read/write functionality by the means of callbacks.
58
- *
59
- * Each tree node must be NULL-terminated, CTL_NODE_END macro is provided for
60
- * convenience.
61
- */
62
- struct ctl {
63
- umf_ctl_node_t root [CTL_MAX_ENTRIES ];
64
- int first_free ;
65
- };
66
-
67
50
void * Zalloc (size_t sz ) {
68
51
void * ptr = umf_ba_global_alloc (sz );
69
52
if (ptr ) {
@@ -81,22 +64,23 @@ char *Strdup(const char *s) {
81
64
return p ;
82
65
}
83
66
84
- umf_result_t umfCtlGet (const char * name , void * ctx , void * arg ) {
67
+ umf_result_t umfCtlGet (const char * name , void * ctx , void * arg , size_t size ) {
85
68
if (name == NULL || arg == NULL || ctx == NULL ) {
86
69
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
87
70
}
88
71
return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name , CTL_QUERY_READ ,
89
- arg )
72
+ arg , size )
90
73
? UMF_RESULT_ERROR_UNKNOWN
91
74
: UMF_RESULT_SUCCESS ;
92
75
}
93
76
94
- umf_result_t umfCtlSet (const char * name , void * ctx , void * arg ) {
95
- if (name == NULL || arg == NULL || ctx == NULL ) {
77
+ umf_result_t umfCtlSet (const char * name , void * ctx , void * arg , size_t size ) {
78
+ // Context can be NULL when setting defaults
79
+ if (name == NULL || arg == NULL || size == 0 ) {
96
80
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
97
81
}
98
82
return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name , CTL_QUERY_WRITE ,
99
- arg )
83
+ arg , size )
100
84
? UMF_RESULT_ERROR_UNKNOWN
101
85
: UMF_RESULT_SUCCESS ;
102
86
}
@@ -106,7 +90,7 @@ umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) {
106
90
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
107
91
}
108
92
return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name ,
109
- CTL_QUERY_RUNNABLE , arg )
93
+ CTL_QUERY_RUNNABLE , arg , 0 )
110
94
? UMF_RESULT_ERROR_UNKNOWN
111
95
: UMF_RESULT_SUCCESS ;
112
96
}
@@ -287,10 +271,10 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
287
271
*/
288
272
static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
289
273
umf_ctl_query_source_t source , void * arg ,
290
- umf_ctl_index_utlist_t * indexes ,
274
+ size_t size , umf_ctl_index_utlist_t * indexes ,
291
275
const char * extra_name ,
292
276
umf_ctl_query_type_t query_type ) {
293
- (void )extra_name , (void )query_type ;
277
+ (void )extra_name , (void )query_type , ( void ) size ;
294
278
assert (n != NULL );
295
279
assert (n -> cb [CTL_QUERY_READ ] != NULL );
296
280
assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -300,7 +284,7 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
300
284
return -1 ;
301
285
}
302
286
303
- return n -> cb [CTL_QUERY_READ ](ctx , source , arg , indexes , NULL ,
287
+ return n -> cb [CTL_QUERY_READ ](ctx , source , arg , size , indexes , extra_name ,
304
288
MAX_CTL_QUERY_TYPE );
305
289
}
306
290
@@ -309,10 +293,10 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
309
293
*/
310
294
static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
311
295
umf_ctl_query_source_t source , void * arg ,
312
- umf_ctl_index_utlist_t * indexes ,
296
+ size_t size , umf_ctl_index_utlist_t * indexes ,
313
297
const char * extra_name ,
314
298
umf_ctl_query_type_t query_type ) {
315
- (void )extra_name , (void )query_type ;
299
+ (void )extra_name , (void )query_type , ( void ) size ;
316
300
assert (n != NULL );
317
301
assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
318
302
assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -327,8 +311,8 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
327
311
return -1 ;
328
312
}
329
313
330
- int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , indexes , NULL ,
331
- MAX_CTL_QUERY_TYPE );
314
+ int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , size , indexes ,
315
+ extra_name , MAX_CTL_QUERY_TYPE );
332
316
ctl_query_cleanup_real_args (n , real_arg , source );
333
317
334
318
return ret ;
@@ -339,31 +323,32 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
339
323
*/
340
324
static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
341
325
umf_ctl_query_source_t source , void * arg ,
342
- umf_ctl_index_utlist_t * indexes ,
326
+ size_t size , umf_ctl_index_utlist_t * indexes ,
343
327
const char * extra_name ,
344
328
umf_ctl_query_type_t query_type ) {
345
329
(void )extra_name , (void )query_type ;
346
330
assert (n != NULL );
347
331
assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
348
332
assert (MAX_CTL_QUERY_TYPE != query_type );
349
- return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , indexes , NULL ,
350
- MAX_CTL_QUERY_TYPE );
333
+ return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , size , indexes ,
334
+ extra_name , MAX_CTL_QUERY_TYPE );
351
335
}
352
336
353
337
static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
354
338
umf_ctl_query_source_t source , void * arg ,
355
- umf_ctl_index_utlist_t * indexes ,
339
+ size_t size , umf_ctl_index_utlist_t * indexes ,
356
340
const char * extra_name ,
357
341
umf_ctl_query_type_t query_type ) {
358
342
assert (n != NULL );
359
343
assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
360
344
assert (MAX_CTL_QUERY_TYPE != query_type );
361
- return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , indexes , extra_name ,
345
+ return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , size , indexes , extra_name ,
362
346
query_type );
363
347
}
364
348
365
349
typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
366
350
umf_ctl_query_source_t source , void * arg ,
351
+ size_t size ,
367
352
umf_ctl_index_utlist_t * indexes ,
368
353
const char * extra_name ,
369
354
umf_ctl_query_type_t query_type );
@@ -380,7 +365,8 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
380
365
* from the ctl tree
381
366
*/
382
367
int ctl_query (struct ctl * ctl , void * ctx , umf_ctl_query_source_t source ,
383
- const char * name , umf_ctl_query_type_t type , void * arg ) {
368
+ const char * name , umf_ctl_query_type_t type , void * arg ,
369
+ size_t size ) {
384
370
if (name == NULL ) {
385
371
errno = EINVAL ;
386
372
return -1 ;
@@ -416,11 +402,14 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
416
402
errno = EINVAL ;
417
403
goto out ;
418
404
}
405
+ const char * extra_name = & name [0 ];
406
+ if (strstr (extra_name , "by_handle" ) != NULL ) {
407
+ extra_name = & name [0 ] + name_offset ;
408
+ }
419
409
420
- const char * extra_name = & name [0 ] + name_offset ;
421
410
ret =
422
411
ctl_exec_query [n -> type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type ](
423
- ctx , n , source , arg , indexes , extra_name , type );
412
+ ctx , n , source , arg , size , indexes , extra_name , type );
424
413
out :
425
414
ctl_delete_indexes (indexes );
426
415
@@ -487,7 +476,7 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
487
476
}
488
477
489
478
r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
490
- value );
479
+ value , 0 );
491
480
492
481
if (r < 0 && ctx != NULL ) {
493
482
return -1 ;
0 commit comments