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 || arg == 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
@@ -287,10 +240,10 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
287240 */
288241static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
289242 umf_ctl_query_source_t source , void * arg ,
290- umf_ctl_index_utlist_t * indexes ,
243+ size_t size , umf_ctl_index_utlist_t * indexes ,
291244 const char * extra_name ,
292245 umf_ctl_query_type_t query_type ) {
293- (void )extra_name , ( void ) query_type ;
246+ (void )query_type ;
294247 assert (n != NULL );
295248 assert (n -> cb [CTL_QUERY_READ ] != NULL );
296249 assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -300,7 +253,7 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
300253 return -1 ;
301254 }
302255
303- return n -> cb [CTL_QUERY_READ ](ctx , source , arg , indexes , NULL ,
256+ return n -> cb [CTL_QUERY_READ ](ctx , source , arg , size , indexes , extra_name ,
304257 MAX_CTL_QUERY_TYPE );
305258}
306259
@@ -309,10 +262,10 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
309262 */
310263static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
311264 umf_ctl_query_source_t source , void * arg ,
312- umf_ctl_index_utlist_t * indexes ,
265+ size_t size , umf_ctl_index_utlist_t * indexes ,
313266 const char * extra_name ,
314267 umf_ctl_query_type_t query_type ) {
315- (void )extra_name , ( void ) query_type ;
268+ (void )query_type ;
316269 assert (n != NULL );
317270 assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
318271 assert (MAX_CTL_QUERY_TYPE != query_type );
@@ -327,8 +280,8 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
327280 return -1 ;
328281 }
329282
330- int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , indexes , NULL ,
331- MAX_CTL_QUERY_TYPE );
283+ int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , size , indexes ,
284+ extra_name , MAX_CTL_QUERY_TYPE );
332285 ctl_query_cleanup_real_args (n , real_arg , source );
333286
334287 return ret ;
@@ -339,31 +292,32 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
339292 */
340293static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
341294 umf_ctl_query_source_t source , void * arg ,
342- umf_ctl_index_utlist_t * indexes ,
295+ size_t size , umf_ctl_index_utlist_t * indexes ,
343296 const char * extra_name ,
344297 umf_ctl_query_type_t query_type ) {
345298 (void )extra_name , (void )query_type ;
346299 assert (n != NULL );
347300 assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
348301 assert (MAX_CTL_QUERY_TYPE != query_type );
349- return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , indexes , NULL ,
350- MAX_CTL_QUERY_TYPE );
302+ return n -> cb [CTL_QUERY_RUNNABLE ](ctx , source , arg , size , indexes ,
303+ extra_name , MAX_CTL_QUERY_TYPE );
351304}
352305
353306static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
354307 umf_ctl_query_source_t source , void * arg ,
355- umf_ctl_index_utlist_t * indexes ,
308+ size_t size , umf_ctl_index_utlist_t * indexes ,
356309 const char * extra_name ,
357310 umf_ctl_query_type_t query_type ) {
358311 assert (n != NULL );
359312 assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
360313 assert (MAX_CTL_QUERY_TYPE != query_type );
361- return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , indexes , extra_name ,
314+ return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , size , indexes , extra_name ,
362315 query_type );
363316}
364317
365318typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
366319 umf_ctl_query_source_t source , void * arg ,
320+ size_t size ,
367321 umf_ctl_index_utlist_t * indexes ,
368322 const char * extra_name ,
369323 umf_ctl_query_type_t query_type );
@@ -380,7 +334,8 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
380334 * from the ctl tree
381335 */
382336int 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 ) {
337+ const char * name , umf_ctl_query_type_t type , void * arg ,
338+ size_t size ) {
384339 if (name == NULL ) {
385340 errno = EINVAL ;
386341 return -1 ;
@@ -417,10 +372,9 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
417372 goto out ;
418373 }
419374
420- const char * extra_name = & name [0 ] + name_offset ;
421375 ret =
422376 ctl_exec_query [n -> type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type ](
423- ctx , n , source , arg , indexes , extra_name , type );
377+ ctx , n , source , arg , size , indexes , name + name_offset , type );
424378out :
425379 ctl_delete_indexes (indexes );
426380
@@ -487,7 +441,7 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
487441 }
488442
489443 r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
490- value );
444+ value , 0 );
491445
492446 if (r < 0 && ctx != NULL ) {
493447 return -1 ;
0 commit comments