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,22 +64,23 @@ char *Strdup(const char *s) {
8164 return p ;
8265}
8366
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 ) {
8568 if (name == NULL || arg == NULL || ctx == NULL ) {
8669 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
8770 }
8871 return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name , CTL_QUERY_READ ,
89- arg )
72+ arg , size )
9073 ? UMF_RESULT_ERROR_UNKNOWN
9174 : UMF_RESULT_SUCCESS ;
9275}
9376
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 ) {
9680 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
9781 }
9882 return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name , CTL_QUERY_WRITE ,
99- arg )
83+ arg , size )
10084 ? UMF_RESULT_ERROR_UNKNOWN
10185 : UMF_RESULT_SUCCESS ;
10286}
@@ -106,7 +90,7 @@ umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) {
10690 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
10791 }
10892 return ctl_query (NULL , ctx , CTL_QUERY_PROGRAMMATIC , name ,
109- CTL_QUERY_RUNNABLE , arg )
93+ CTL_QUERY_RUNNABLE , arg , 0 )
11094 ? UMF_RESULT_ERROR_UNKNOWN
11195 : UMF_RESULT_SUCCESS ;
11296}
@@ -287,10 +271,10 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
287271 */
288272static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
289273 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 ,
291275 const char * extra_name ,
292276 umf_ctl_query_type_t query_type ) {
293- (void )extra_name , (void )query_type ;
277+ (void )extra_name , (void )query_type , ( void ) size ;
294278 assert (n != NULL );
295279 assert (n -> cb [CTL_QUERY_READ ] != NULL );
296280 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,
300284 return -1 ;
301285 }
302286
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 ,
304288 MAX_CTL_QUERY_TYPE );
305289}
306290
@@ -309,10 +293,10 @@ static int ctl_exec_query_read(void *ctx, const umf_ctl_node_t *n,
309293 */
310294static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
311295 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 ,
313297 const char * extra_name ,
314298 umf_ctl_query_type_t query_type ) {
315- (void )extra_name , (void )query_type ;
299+ (void )extra_name , (void )query_type , ( void ) size ;
316300 assert (n != NULL );
317301 assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
318302 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,
327311 return -1 ;
328312 }
329313
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 );
332316 ctl_query_cleanup_real_args (n , real_arg , source );
333317
334318 return ret ;
@@ -339,31 +323,32 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
339323 */
340324static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
341325 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 ,
343327 const char * extra_name ,
344328 umf_ctl_query_type_t query_type ) {
345329 (void )extra_name , (void )query_type ;
346330 assert (n != NULL );
347331 assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
348332 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 );
351335}
352336
353337static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
354338 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 ,
356340 const char * extra_name ,
357341 umf_ctl_query_type_t query_type ) {
358342 assert (n != NULL );
359343 assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
360344 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 ,
362346 query_type );
363347}
364348
365349typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
366350 umf_ctl_query_source_t source , void * arg ,
351+ size_t size ,
367352 umf_ctl_index_utlist_t * indexes ,
368353 const char * extra_name ,
369354 umf_ctl_query_type_t query_type );
@@ -380,7 +365,8 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
380365 * from the ctl tree
381366 */
382367int 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 ) {
384370 if (name == NULL ) {
385371 errno = EINVAL ;
386372 return -1 ;
@@ -416,11 +402,14 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
416402 errno = EINVAL ;
417403 goto out ;
418404 }
405+ const char * extra_name = & name [0 ];
406+ if (strstr (extra_name , "by_handle" ) != NULL ) {
407+ extra_name = & name [0 ] + name_offset ;
408+ }
419409
420- const char * extra_name = & name [0 ] + name_offset ;
421410 ret =
422411 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 );
424413out :
425414 ctl_delete_indexes (indexes );
426415
@@ -487,7 +476,7 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
487476 }
488477
489478 r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
490- value );
479+ value , 0 );
491480
492481 if (r < 0 && ctx != NULL ) {
493482 return -1 ;
0 commit comments