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,36 +64,6 @@ 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 ) {
85
- if (name == NULL || arg == NULL || ctx == NULL ) {
86
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
87
- }
88
- return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name , CTL_QUERY_READ ,
89
- arg )
90
- ? UMF_RESULT_ERROR_UNKNOWN
91
- : UMF_RESULT_SUCCESS ;
92
- }
93
-
94
- umf_result_t umfCtlSet (const char * name , void * ctx , void * arg ) {
95
- if (name == NULL || arg == NULL || ctx == NULL ) {
96
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
97
- }
98
- return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name , CTL_QUERY_WRITE ,
99
- arg )
100
- ? UMF_RESULT_ERROR_UNKNOWN
101
- : UMF_RESULT_SUCCESS ;
102
- }
103
-
104
- umf_result_t umfCtlExec (const char * name , void * ctx , void * arg ) {
105
- if (name == NULL || ctx == NULL ) {
106
- return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
107
- }
108
- return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name ,
109
- CTL_QUERY_RUNNABLE , arg )
110
- ? UMF_RESULT_ERROR_UNKNOWN
111
- : UMF_RESULT_SUCCESS ;
112
- }
113
-
114
67
/*
115
68
* ctl_find_node -- (internal) searches for a matching entry point in the
116
69
* provided nodes
@@ -296,10 +249,10 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
296
249
*/
297
250
static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
298
251
umf_ctl_query_source_t source , void * arg ,
299
- umf_ctl_index_utlist_t * indexes ,
252
+ size_t size , umf_ctl_index_utlist_t * indexes ,
300
253
const char * extra_name ,
301
254
umf_ctl_query_type_t query_type ) {
302
- (void )extra_name , ( void ) query_type ;
255
+ (void )query_type ;
303
256
assert (n != NULL );
304
257
assert (n -> cb [CTL_QUERY_READ ] != NULL );
305
258
assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -309,7 +262,7 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
309
262
return -1 ;
310
263
}
311
264
312
- return n -> cb [CTL_QUERY_READ ](ctx , source , arg , indexes , NULL ,
265
+ return n -> cb [CTL_QUERY_READ ](ctx , source , arg , size , indexes , extra_name ,
313
266
MAX_CTL_QUERY_TYPE );
314
267
}
315
268
@@ -318,10 +271,10 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
318
271
*/
319
272
static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
320
273
umf_ctl_query_source_t source , void * arg ,
321
- umf_ctl_index_utlist_t * indexes ,
274
+ size_t size , umf_ctl_index_utlist_t * indexes ,
322
275
const char * extra_name ,
323
276
umf_ctl_query_type_t query_type ) {
324
- (void )extra_name , ( void ) query_type ;
277
+ (void )query_type ;
325
278
assert (n != NULL );
326
279
assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
327
280
assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -336,8 +289,8 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
336
289
return -1 ;
337
290
}
338
291
339
- int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , indexes , NULL ,
340
- MAX_CTL_QUERY_TYPE );
292
+ int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , size , indexes ,
293
+ extra_name , MAX_CTL_QUERY_TYPE );
341
294
ctl_query_cleanup_real_args (n , real_arg , source );
342
295
343
296
return ret ;
@@ -348,31 +301,32 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
348
301
*/
349
302
static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
350
303
umf_ctl_query_source_t source , void * arg ,
351
- umf_ctl_index_utlist_t * indexes ,
304
+ size_t size , umf_ctl_index_utlist_t * indexes ,
352
305
const char * extra_name ,
353
306
umf_ctl_query_type_t query_type ) {
354
307
(void )extra_name , (void )query_type ;
355
308
assert (n != NULL );
356
309
assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
357
310
assert (MAX_CTL_QUERY_TYPE != query_type );
358
- return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , indexes , NULL ,
359
- MAX_CTL_QUERY_TYPE );
311
+ return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , size , indexes ,
312
+ extra_name , MAX_CTL_QUERY_TYPE );
360
313
}
361
314
362
315
static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
363
316
umf_ctl_query_source_t source , void * arg ,
364
- umf_ctl_index_utlist_t * indexes ,
317
+ size_t size , umf_ctl_index_utlist_t * indexes ,
365
318
const char * extra_name ,
366
319
umf_ctl_query_type_t query_type ) {
367
320
assert (n != NULL );
368
321
assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
369
322
assert (MAX_CTL_QUERY_TYPE != query_type );
370
- return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , indexes , extra_name ,
323
+ return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , size , indexes , extra_name ,
371
324
query_type );
372
325
}
373
326
374
327
typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
375
328
umf_ctl_query_source_t source , void * arg ,
329
+ size_t size ,
376
330
umf_ctl_index_utlist_t * indexes ,
377
331
const char * extra_name ,
378
332
umf_ctl_query_type_t query_type );
@@ -389,7 +343,8 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
389
343
* from the ctl tree
390
344
*/
391
345
int ctl_query (struct ctl * ctl , void * ctx , umf_ctl_query_source_t source ,
392
- const char * name , umf_ctl_query_type_t type , void * arg ) {
346
+ const char * name , umf_ctl_query_type_t type , void * arg ,
347
+ size_t size ) {
393
348
if (name == NULL ) {
394
349
errno = EINVAL ;
395
350
return -1 ;
@@ -426,10 +381,9 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
426
381
goto out ;
427
382
}
428
383
429
- const char * extra_name = & name [0 ] + name_offset ;
430
384
ret =
431
385
ctl_exec_query [n -> type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type ](
432
- ctx , n , source , arg , indexes , extra_name , type );
386
+ ctx , n , source , arg , size , indexes , name + name_offset , type );
433
387
out :
434
388
ctl_delete_indexes (indexes );
435
389
@@ -496,7 +450,7 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
496
450
}
497
451
498
452
r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
499
- value );
453
+ value , 0 );
500
454
501
455
if (r < 0 && ctx != NULL ) {
502
456
return -1 ;
0 commit comments