@@ -247,50 +247,49 @@ static void ctl_query_cleanup_real_args(const umf_ctl_node_t *n, void *real_arg,
247
247
/*
248
248
* ctl_exec_query_read -- (internal) calls the read callback of a node
249
249
*/
250
- static int ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
251
- umf_ctl_query_source_t source , void * arg ,
252
- size_t size , umf_ctl_index_utlist_t * indexes ,
253
- const char * extra_name ,
254
- umf_ctl_query_type_t query_type ) {
250
+ static umf_result_t ctl_exec_query_read (void * ctx , const umf_ctl_node_t * n ,
251
+ umf_ctl_query_source_t source ,
252
+ void * arg , size_t size ,
253
+ umf_ctl_index_utlist_t * indexes ,
254
+ const char * extra_name ,
255
+ umf_ctl_query_type_t query_type ) {
255
256
(void )query_type ;
256
257
assert (n != NULL );
257
258
assert (n -> cb [CTL_QUERY_READ ] != NULL );
258
259
assert (MAX_CTL_QUERY_TYPE != query_type );
259
260
260
261
if (arg == NULL ) {
261
- errno = EINVAL ;
262
- return -1 ;
262
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
263
263
}
264
-
265
264
return n -> cb [CTL_QUERY_READ ](ctx , source , arg , size , indexes , extra_name ,
266
265
MAX_CTL_QUERY_TYPE );
267
266
}
268
267
269
268
/*
270
269
* ctl_exec_query_write -- (internal) calls the write callback of a node
271
270
*/
272
- static int ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
273
- umf_ctl_query_source_t source , void * arg ,
274
- size_t size , umf_ctl_index_utlist_t * indexes ,
275
- const char * extra_name ,
276
- umf_ctl_query_type_t query_type ) {
271
+ static umf_result_t ctl_exec_query_write (void * ctx , const umf_ctl_node_t * n ,
272
+ umf_ctl_query_source_t source ,
273
+ void * arg , size_t size ,
274
+ umf_ctl_index_utlist_t * indexes ,
275
+ const char * extra_name ,
276
+ umf_ctl_query_type_t query_type ) {
277
277
(void )query_type ;
278
278
assert (n != NULL );
279
279
assert (n -> cb [CTL_QUERY_WRITE ] != NULL );
280
280
assert (MAX_CTL_QUERY_TYPE != query_type );
281
281
282
282
if (arg == NULL ) {
283
- errno = EINVAL ;
284
- return -1 ;
283
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
285
284
}
286
285
287
286
void * real_arg = ctl_query_get_real_args (n , arg , source );
288
287
if (real_arg == NULL ) {
289
- return -1 ;
288
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
290
289
}
291
290
292
- int ret = n -> cb [CTL_QUERY_WRITE ](ctx , source , real_arg , size , indexes ,
293
- extra_name , MAX_CTL_QUERY_TYPE );
291
+ umf_result_t ret = n -> cb [CTL_QUERY_WRITE ](
292
+ ctx , source , real_arg , size , indexes , extra_name , MAX_CTL_QUERY_TYPE );
294
293
ctl_query_cleanup_real_args (n , real_arg , source );
295
294
296
295
return ret ;
@@ -299,11 +298,12 @@ static int ctl_exec_query_write(void *ctx, const umf_ctl_node_t *n,
299
298
/*
300
299
* ctl_exec_query_runnable -- (internal) calls the run callback of a node
301
300
*/
302
- static int ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
303
- umf_ctl_query_source_t source , void * arg ,
304
- size_t size , umf_ctl_index_utlist_t * indexes ,
305
- const char * extra_name ,
306
- umf_ctl_query_type_t query_type ) {
301
+ static umf_result_t ctl_exec_query_runnable (void * ctx , const umf_ctl_node_t * n ,
302
+ umf_ctl_query_source_t source ,
303
+ void * arg , size_t size ,
304
+ umf_ctl_index_utlist_t * indexes ,
305
+ const char * extra_name ,
306
+ umf_ctl_query_type_t query_type ) {
307
307
(void )query_type ;
308
308
assert (n != NULL );
309
309
assert (n -> cb [CTL_QUERY_RUNNABLE ] != NULL );
@@ -312,24 +312,25 @@ static int ctl_exec_query_runnable(void *ctx, const umf_ctl_node_t *n,
312
312
extra_name , MAX_CTL_QUERY_TYPE );
313
313
}
314
314
315
- static int ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
316
- umf_ctl_query_source_t source , void * arg ,
317
- size_t size , umf_ctl_index_utlist_t * indexes ,
318
- const char * extra_name ,
319
- umf_ctl_query_type_t query_type ) {
315
+ static umf_result_t ctl_exec_query_subtree (void * ctx , const umf_ctl_node_t * n ,
316
+ umf_ctl_query_source_t source ,
317
+ void * arg , size_t size ,
318
+ umf_ctl_index_utlist_t * indexes ,
319
+ const char * extra_name ,
320
+ umf_ctl_query_type_t query_type ) {
320
321
assert (n != NULL );
321
322
assert (n -> cb [CTL_QUERY_SUBTREE ] != NULL );
322
323
assert (MAX_CTL_QUERY_TYPE != query_type );
323
324
return n -> cb [CTL_QUERY_SUBTREE ](ctx , source , arg , size , indexes , extra_name ,
324
325
query_type );
325
326
}
326
327
327
- typedef int (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
328
- umf_ctl_query_source_t source , void * arg ,
329
- size_t size ,
330
- umf_ctl_index_utlist_t * indexes ,
331
- const char * extra_name ,
332
- umf_ctl_query_type_t query_type );
328
+ typedef umf_result_t (* umf_ctl_exec_query_t )(void * ctx , const umf_ctl_node_t * n ,
329
+ umf_ctl_query_source_t source ,
330
+ void * arg , size_t size ,
331
+ umf_ctl_index_utlist_t * indexes ,
332
+ const char * extra_name ,
333
+ umf_ctl_query_type_t query_type );
333
334
334
335
static umf_ctl_exec_query_t ctl_exec_query [MAX_CTL_QUERY_TYPE ] = {
335
336
ctl_exec_query_read ,
@@ -342,12 +343,11 @@ static umf_ctl_exec_query_t ctl_exec_query[MAX_CTL_QUERY_TYPE] = {
342
343
* ctl_query -- (internal) parses the name and calls the appropriate methods
343
344
* from the ctl tree
344
345
*/
345
- int ctl_query (struct ctl * ctl , void * ctx , umf_ctl_query_source_t source ,
346
- const char * name , umf_ctl_query_type_t type , void * arg ,
347
- size_t size ) {
346
+ umf_result_t ctl_query (struct ctl * ctl , void * ctx ,
347
+ umf_ctl_query_source_t source , const char * name ,
348
+ umf_ctl_query_type_t type , void * arg , size_t size ) {
348
349
if (name == NULL ) {
349
- errno = EINVAL ;
350
- return -1 ;
350
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
351
351
}
352
352
353
353
/*
@@ -358,10 +358,10 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
358
358
umf_ctl_index_utlist_t * indexes = NULL ;
359
359
indexes = Zalloc (sizeof (* indexes ));
360
360
if (!indexes ) {
361
- return -1 ;
361
+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
362
362
}
363
363
364
- int ret = -1 ;
364
+ umf_result_t ret = UMF_RESULT_ERROR_UNKNOWN ;
365
365
size_t name_offset = 0 ;
366
366
367
367
const umf_ctl_node_t * n =
@@ -377,7 +377,7 @@ int ctl_query(struct ctl *ctl, void *ctx, umf_ctl_query_source_t source,
377
377
if (n == NULL ||
378
378
(n -> type != CTL_NODE_LEAF && n -> type != CTL_NODE_SUBTREE ) ||
379
379
n -> cb [n -> type == CTL_NODE_SUBTREE ? CTL_QUERY_SUBTREE : type ] == NULL ) {
380
- errno = EINVAL ;
380
+ ret = UMF_RESULT_ERROR_INVALID_ARGUMENT ;
381
381
goto out ;
382
382
}
383
383
@@ -436,24 +436,24 @@ static int ctl_parse_query(char *qbuf, char **name, char **value) {
436
436
/*
437
437
* ctl_load_config -- executes the entire query collection from a provider
438
438
*/
439
- static int ctl_load_config (struct ctl * ctl , void * ctx , char * buf ) {
440
- int r = 0 ;
439
+ static umf_result_t ctl_load_config (struct ctl * ctl , void * ctx , char * buf ) {
440
+ umf_result_t ret = UMF_RESULT_SUCCESS ;
441
441
char * sptr = NULL ; /* for internal use of strtok */
442
442
char * name ;
443
443
char * value ;
444
444
char * qbuf = strtok_r (buf , CTL_STRING_QUERY_SEPARATOR , & sptr );
445
445
446
446
while (qbuf != NULL ) {
447
- r = ctl_parse_query (qbuf , & name , & value );
448
- if (r != 0 ) {
449
- return -1 ;
447
+ int parse_res = ctl_parse_query (qbuf , & name , & value );
448
+ if (parse_res != 0 ) {
449
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
450
450
}
451
451
452
- r = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
453
- value , 0 );
452
+ ret = ctl_query (ctl , ctx , CTL_QUERY_CONFIG_INPUT , name , CTL_QUERY_WRITE ,
453
+ value , 0 );
454
454
455
- if (r < 0 && ctx != NULL ) {
456
- return -1 ;
455
+ if (ret != UMF_RESULT_SUCCESS && ctx != NULL ) {
456
+ return ret ;
457
457
}
458
458
459
459
qbuf = strtok_r (NULL , CTL_STRING_QUERY_SEPARATOR , & sptr );
@@ -465,14 +465,14 @@ static int ctl_load_config(struct ctl *ctl, void *ctx, char *buf) {
465
465
/*
466
466
* ctl_load_config_from_string -- loads obj configuration from string
467
467
*/
468
- int ctl_load_config_from_string (struct ctl * ctl , void * ctx ,
469
- const char * cfg_string ) {
468
+ umf_result_t ctl_load_config_from_string (struct ctl * ctl , void * ctx ,
469
+ const char * cfg_string ) {
470
470
char * buf = Strdup (cfg_string );
471
471
if (buf == NULL ) {
472
- return -1 ;
472
+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
473
473
}
474
474
475
- int ret = ctl_load_config (ctl , ctx , buf );
475
+ umf_result_t ret = ctl_load_config (ctl , ctx , buf );
476
476
477
477
umf_ba_global_free (buf );
478
478
return ret ;
@@ -485,9 +485,9 @@ int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
485
485
* the size of the file, reads its content and sanitizes it for ctl_load_config.
486
486
*/
487
487
#ifndef _WIN32 // TODO: implement for Windows
488
- int ctl_load_config_from_file (struct ctl * ctl , void * ctx ,
489
- const char * cfg_file ) {
490
- int ret = -1 ;
488
+ umf_result_t ctl_load_config_from_file (struct ctl * ctl , void * ctx ,
489
+ const char * cfg_file ) {
490
+ umf_result_t ret = UMF_RESULT_ERROR_UNKNOWN ;
491
491
long fsize = 0 ;
492
492
char * buf = NULL ;
493
493
@@ -608,7 +608,6 @@ int ctl_arg_integer(const void *arg, void *dest, size_t dest_size) {
608
608
* (uint8_t * )dest = (uint8_t )val ;
609
609
break ;
610
610
default :
611
- errno = EINVAL ;
612
611
return -1 ;
613
612
}
614
613
0 commit comments