Skip to content

Commit db5aafb

Browse files
committed
genericCMPClient_util.{c,h}: add source parameter to CONF_read_check_options() and internalize CONF_read_options()
1 parent f315442 commit db5aafb

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

include/genericCMPClient_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ typedef struct opt_t
140140
#define OPT_END { NULL, OPT_BOOL, {.bit = false}, {NULL}, NULL}
141141
CONF *CONF_load_config(OPTIONAL ossl_unused uta_ctx *ctx, const char *file);
142142
bool CONF_entry_in_sections(const CONF *conf, const char *sections, const char *entry);
143-
bool CONF_read_options(const CONF *conf, const char *sections, const opt_t *opt);
144-
bool CONF_read_check_options(const CONF *conf, const char *sections, const opt_t *opts);
143+
bool CONF_read_check_options(const CONF *conf, const char *source,
144+
const char *sections, const opt_t *opts);
145145

146146

147147
/* credentials.h: */

src/genericCMPClient_util.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ static bool conf_get_number_e(const CONF *conf, const char *sections,
441441
return str == NULL ? false : parse_long(str, p_result);
442442
}
443443

444-
bool CONF_read_options(const CONF *conf, const char *sections, const opt_t *opt)
444+
static bool CONF_read_options_ex(const CONF *conf, const char *source,
445+
const char *sections, const opt_t *opt)
445446
{
446447
const char *str;
447448
long val = 0;
@@ -492,13 +493,13 @@ bool CONF_read_options(const CONF *conf, const char *sections, const opt_t *opt)
492493
if (!conf_get_number_e(conf, sections, opt->name, &val))
493494
return false;
494495
if (val > INT_MAX) {
495-
LOG(FL_ERR, "section(s) '%s' option '%s' value %ld is too large, can be at most %d",
496-
sections, opt->name, val, INT_MAX);
496+
LOG(FL_ERR, "Config '%s' section(s) [%s] option '%s' value %ld is too large, can be at most %d",
497+
source, sections, opt->name, val, INT_MAX);
497498
return false;
498499
}
499500
if (bare_type == OPT_POS_INT && val <= 0) {
500-
LOG(FL_ERR, "section(s) '%s' option '%s' value %ld must be positive (> 0)",
501-
sections, opt->name, val);
501+
LOG(FL_ERR, "Config '%s' section(s) [%s] option '%s' value %ld must be positive (> 0)",
502+
source, sections, opt->name, val);
502503
return false;
503504
}
504505
*opt->varref_u.int1 = (int)val;
@@ -517,8 +518,8 @@ bool CONF_read_options(const CONF *conf, const char *sections, const opt_t *opt)
517518
if (!conf_get_number_e(conf, sections, opt->name, &val))
518519
return false;
519520
if (val < 0 || val > 1) {
520-
LOG(FL_ERR, "section(s) '%s' option '%s' value %ld is out of range for Boolean; must be 0 or 1",
521-
sections, opt->name, val);
521+
LOG(FL_ERR, "Config '%s' section(s) [%s] option '%s' value %ld is out of range for Boolean; must be 0 or 1",
522+
source, sections, opt->name, val);
522523
return false;
523524
}
524525
*opt->varref_u.bit = (bool)val;
@@ -527,8 +528,8 @@ bool CONF_read_options(const CONF *conf, const char *sections, const opt_t *opt)
527528
}
528529
break;
529530
default:
530-
LOG(FL_ERR, "internal: section(s) '%' option '%s': unsupported type '%d'",
531-
sections, opt->name, opt->type);
531+
LOG(FL_ERR, "internal: Config '%s' section(s) [%s] option '%s': unsupported type '0x%x'",
532+
source, sections, opt->name, opt->type);
532533
return false;
533534
break;
534535
}
@@ -538,15 +539,17 @@ bool CONF_read_options(const CONF *conf, const char *sections, const opt_t *opt)
538539
}
539540

540541

541-
bool CONF_read_check_options(const CONF *conf, const char *sections, const opt_t *opts)
542+
bool CONF_read_check_options(const CONF *conf, const char *source,
543+
const char *sections, const opt_t *opts)
542544
{
543545
STACK_OF(CONF_VALUE) *sk;
544546
int i;
545547
const opt_t *opt;
546548
bool ok = true;
547549

548-
if (!CONF_read_options((CONF *)conf, sections, opts)) {
549-
LOG(FL_ERR, "Failed reading and parsing [%s] section", sections);
550+
if (!CONF_read_options_ex((CONF *)conf, source, sections, opts)) {
551+
LOG(FL_ERR, "Failed reading and parsing [%s] section(s) of %s",
552+
sections, source);
550553
return false;
551554
}
552555

@@ -563,8 +566,8 @@ bool CONF_read_check_options(const CONF *conf, const char *sections, const opt_t
563566
}
564567
}
565568
if (!known) {
566-
LOG(FL_WARN, "Ignoring unknown entry '%s' configured in section [%s]\n",
567-
cv->name, sections);
569+
LOG(FL_WARN, "Config '%s' section(s) [%s]: ignoring unknown option '%s'\n",
570+
source, sections, cv->name);
568571
}
569572
}
570573

@@ -574,13 +577,13 @@ bool CONF_read_check_options(const CONF *conf, const char *sections, const opt_t
574577
const char *val = conf_get_string(conf, sections, opt->name);
575578

576579
if (!conf_entry_in_sections_or_default(conf, sections, opt->name)) {
577-
LOG(FL_ERR, "Missing required entry '%s' in section(s): %s\n",
578-
opt->name, sections);
580+
LOG(FL_ERR, "Config '%s' section(s) [%s]: missing required option '%s'\n",
581+
source, sections, opt->name);
579582
ok = false;
580583
} else if ((opt->type & OPT_EMPTY_OK) == 0 &&
581584
val != NULL && val[0] == '\0') {
582-
LOG(FL_ERR, "Empty value given for required entry '%s' in section(s) %s\n",
583-
opt->name, sections);
585+
LOG(FL_ERR, "Config '%s' section(s) [%s]: empty value given for required option '%s'\n",
586+
source, sections, opt->name);
584587
ok = false;
585588
}
586589
}

0 commit comments

Comments
 (0)