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,9 @@ 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 ;
325
277
assert (n != NULL );
326
278
assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
327
279
assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -336,8 +288,8 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
336
288
return -1 ;
337
289
}
338
290
339
- int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , indexes , NULL ,
340
- MAX_CTL_QUERY_TYPE );
291
+ int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , size , indexes ,
292
+ extra_name , MAX_CTL_QUERY_TYPE );
341
293
ctl_query_cleanup_real_args (n , real_arg , source );
342
294
343
295
return ret ;
@@ -348,31 +300,31 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
348
300
*/
349
301
static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
350
302
umf_ctl_query_source_t source , void * arg ,
351
- umf_ctl_index_utlist_t * indexes ,
303
+ size_t size , umf_ctl_index_utlist_t * indexes ,
352
304
const char * extra_name ,
353
305
umf_ctl_query_type_t query_type ) {
354
- (void )extra_name , (void )query_type ;
355
306
assert (n != NULL );
356
307
assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
357
308
assert (MAX_CTL_QUERY_TYPE != query_type );
358
- return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , indexes , NULL ,
359
- MAX_CTL_QUERY_TYPE );
309
+ return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , size , indexes ,
310
+ extra_name , MAX_CTL_QUERY_TYPE );
360
311
}
361
312
362
313
static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
363
314
umf_ctl_query_source_t source , void * arg ,
364
- umf_ctl_index_utlist_t * indexes ,
315
+ size_t size , umf_ctl_index_utlist_t * indexes ,
365
316
const char * extra_name ,
366
317
umf_ctl_query_type_t query_type ) {
367
318
assert (n != NULL );
368
319
assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
369
320
assert (MAX_CTL_QUERY_TYPE != query_type );
370
- return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , indexes , extra_name ,
321
+ return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , size , indexes , extra_name ,
371
322
query_type );
372
323
}
373
324
374
325
typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
375
326
umf_ctl_query_source_t source , void * arg ,
327
+ size_t size ,
376
328
umf_ctl_index_utlist_t * indexes ,
377
329
const char * extra_name ,
378
330
umf_ctl_query_type_t query_type );
@@ -389,7 +341,8 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
389
341
* from the ctl tree
390
342
*/
391
343
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 ) {
344
+ const char * name , umf_ctl_query_type_t type , void * arg ,
345
+ size_t size ) {
393
346
if (name == NULL ) {
394
347
errno = EINVAL ;
395
348
return -1 ;
@@ -426,10 +379,9 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
426
379
goto out ;
427
380
}
428
381
429
- const char * extra_name = & name [0 ] + name_offset ;
430
382
ret =
431
383
ctl_exec_query [n -> type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type ](
432
- ctx , n , source , arg , indexes , extra_name , type );
384
+ ctx , n , source , arg , size , indexes , name + name_offset , type );
433
385
out :
434
386
ctl_delete_indexes (indexes );
435
387
@@ -496,7 +448,7 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
496
448
}
497
449
498
450
r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
499
- value );
451
+ value , 0 );
500
452
501
453
if (r < 0 && ctx != NULL ) {
502
454
return -1 ;
@@ -590,24 +542,6 @@ int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
590
542
}
591
543
#endif
592
544
593
- /*
594
- * ctl_new -- allocates and initializes ctl data structures
595
- */
596
- struct ctl * ctl_new (void ) {
597
- struct ctl * c = Zalloc (sizeof (struct ctl ));
598
- if (c == NULL ) {
599
- return NULL ;
600
- }
601
-
602
- c -> first_free = 0 ;
603
- return c ;
604
- }
605
-
606
- /*
607
- * ctl_delete -- deletes ctl
608
- */
609
- void ctl_delete (struct ctl * c ) { umf_ba_global_free (c ); }
610
-
611
545
/*
612
546
* ctl_parse_ll -- (internal) parses and returns a long long signed integer
613
547
*/
0 commit comments