3636#include <stdio.h>
3737#endif
3838
39- #define CTL_MAX_ENTRIES 100
40-
4139#define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */
4240
4341#define CTL_STRING_QUERY_SEPARATOR ";"
4947static int ctl_global_first_free = 0 ;
5048static umf_ctl_node_t CTL_NODE (global )[CTL_MAX_ENTRIES ];
5149
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-
6750void * Zalloc (size_t sz ) {
6851 void * ptr = umf_ba_global_alloc (sz );
6952 if (ptr ) {
@@ -81,36 +64,6 @@ char *Strdup(const char *s) {
8164 return p ;
8265}
8366
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-
11467/*
11568 * ctl_find_node -- (internal) searches for a matching entry point in the
11669 * provided nodes
@@ -296,10 +249,10 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
296249 */
297250static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
298251 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 ,
300253 const char * extra_name ,
301254 umf_ctl_query_type_t query_type ) {
302- (void )extra_name , ( void ) query_type ;
255+ (void )query_type ;
303256 assert (n != NULL );
304257 assert (n -> cb [CTL_QUERY_READ ] != NULL );
305258 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,
309262 return -1 ;
310263 }
311264
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 ,
313266 MAX_CTL_QUERY_TYPE );
314267}
315268
@@ -318,10 +271,10 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
318271 */
319272static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
320273 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 ,
322275 const char * extra_name ,
323276 umf_ctl_query_type_t query_type ) {
324- (void )extra_name , ( void ) query_type ;
277+ (void )query_type ;
325278 assert (n != NULL );
326279 assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
327280 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,
336289 return -1 ;
337290 }
338291
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 );
341294 ctl_query_cleanup_real_args (n , real_arg , source );
342295
343296 return ret ;
@@ -348,31 +301,32 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
348301 */
349302static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
350303 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 ,
352305 const char * extra_name ,
353306 umf_ctl_query_type_t query_type ) {
354- (void )extra_name , ( void ) query_type ;
307+ (void )query_type ;
355308 assert (n != NULL );
356309 assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
357310 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 );
360313}
361314
362315static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
363316 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 ,
365318 const char * extra_name ,
366319 umf_ctl_query_type_t query_type ) {
367320 assert (n != NULL );
368321 assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
369322 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 ,
371324 query_type );
372325}
373326
374327typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
375328 umf_ctl_query_source_t source , void * arg ,
329+ size_t size ,
376330 umf_ctl_index_utlist_t * indexes ,
377331 const char * extra_name ,
378332 umf_ctl_query_type_t query_type );
@@ -389,7 +343,8 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
389343 * from the ctl tree
390344 */
391345int 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 ) {
393348 if (name == NULL ) {
394349 errno = EINVAL ;
395350 return -1 ;
@@ -426,10 +381,9 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
426381 goto out ;
427382 }
428383
429- const char * extra_name = & name [0 ] + name_offset ;
430384 ret =
431385 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 );
433387out :
434388 ctl_delete_indexes (indexes );
435389
@@ -496,7 +450,7 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
496450 }
497451
498452 r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
499- value );
453+ value , 0 );
500454
501455 if (r < 0 && ctx != NULL ) {
502456 return -1 ;
@@ -590,24 +544,6 @@ int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
590544}
591545#endif
592546
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-
611547/*
612548 * ctl_parse_ll -- (internal) parses and returns a long long signed integer
613549 */
0 commit comments