remove parser context field from cfg_obj_t

cfg_obj_t doesn't store a pointer to its a parser context anymore,
and does not depend on the parser's lifecycle. Instead, it stores a
reference to its own memory context (and in principle, each node
could have different memory context). This also slightly simplifies
the _destroy API as there is no need to pass a context through it
anymore.
This commit is contained in:
Colin Vidal 2025-10-21 15:41:55 +02:00 committed by Evan Hunt
parent 0d8c4044ab
commit 7706f5acec
22 changed files with 182 additions and 155 deletions

View file

@ -745,7 +745,7 @@ main(int argc, char **argv) {
cleanup:
if (config != NULL) {
cfg_obj_destroy(parser, &config);
cfg_obj_destroy(&config);
}
if (parser != NULL) {

View file

@ -862,7 +862,7 @@ setup_dnsseckeys(dns_client_t *client, dns_view_t *toview) {
cleanup:
if (bindkeys != NULL) {
cfg_obj_destroy(parser, &bindkeys);
cfg_obj_destroy(&bindkeys);
}
if (parser != NULL) {
cfg_parser_destroy(&parser);

View file

@ -1119,7 +1119,7 @@ read_confkey(void) {
cleanup:
if (pctx != NULL) {
if (file != NULL) {
cfg_obj_destroy(pctx, &file);
cfg_obj_destroy(&file);
}
cfg_parser_destroy(&pctx);
}

View file

@ -1199,7 +1199,7 @@ main(int argc, char **argv) {
}
dns_kasp_detach(&kasp);
cfg_obj_destroy(parser, &config);
cfg_obj_destroy(&config);
cfg_parser_destroy(&parser);
}
} else {

View file

@ -187,7 +187,7 @@ getkasp(ksr_ctx_t *ksr, dns_kasp_t **kasp) {
if (ISC_LIST_EMPTY(dns_kasp_keys(*kasp))) {
fatal("dnssec-policy '%s' has no keys configured", ksr->policy);
}
cfg_obj_destroy(parser, &config);
cfg_obj_destroy(&config);
cfg_parser_destroy(&parser);
}

View file

@ -457,7 +457,7 @@ named_config_parsefile(cfg_parser_t *parser, cfg_obj_t **conf) {
cleanup:
if (*conf) {
cfg_obj_destroy(parser, conf);
cfg_obj_destroy(conf);
}
out:

View file

@ -861,7 +861,7 @@ cleanup:
free_controlkey(keyid, mctx);
}
if (config != NULL) {
cfg_obj_destroy(pctx, &config);
cfg_obj_destroy(&config);
}
if (pctx != NULL) {
cfg_parser_destroy(&pctx);

View file

@ -618,7 +618,7 @@ printversion(bool verbose) {
if (cfg_obj_isstring(obj)) {
printf(" geoip-directory: %s\n", cfg_obj_asstring(obj));
}
cfg_obj_destroy(parser, &config);
cfg_obj_destroy(&config);
cfg_parser_destroy(&parser);
isc_mem_detach(&geoip_mctx);
#endif /* HAVE_GEOIP2 */

View file

@ -2544,7 +2544,7 @@ cleanup:
dns_zone_detach(&zone);
}
if (zoneconf != NULL) {
cfg_obj_destroy(cfg->add_parser, &zoneconf);
cfg_obj_destroy(&zoneconf);
}
if (dnsforwarders != NULL) {
dns_forwarders_detach(&dnsforwarders);
@ -2783,7 +2783,7 @@ catz_reconfigure(dns_catz_entry_t *entry, void *arg1, void *arg2) {
cleanup:
if (zoneconf != NULL) {
cfg_obj_destroy(cfg->add_parser, &zoneconf);
cfg_obj_destroy(&zoneconf);
}
dns_zone_detach(&zone);
@ -7615,7 +7615,7 @@ data_to_cfg(dns_view_t *view, MDB_val *key, MDB_val *data, isc_buffer_t **text,
cleanup:
if (zoneconf != NULL) {
cfg_obj_destroy(named_g_addparser, &zoneconf);
cfg_obj_destroy(&zoneconf);
}
return result;
@ -7696,14 +7696,14 @@ for_all_newzone_cfgs(newzone_cfg_cb_t callback, cfg_obj_t *config,
/*
* Destroy the configuration object created in this iteration.
*/
cfg_obj_destroy(named_g_addparser, &zconfigobj);
cfg_obj_destroy(&zconfigobj);
}
if (text != NULL) {
isc_buffer_free(&text);
}
if (zconfigobj != NULL) {
cfg_obj_destroy(named_g_addparser, &zconfigobj);
cfg_obj_destroy(&zconfigobj);
}
mdb_cursor_close(cursor);
@ -7841,7 +7841,7 @@ cleanup:
UNLOCK(&view->new_zone_lock);
if (zoneconf != NULL) {
cfg_obj_destroy(named_g_addparser, &zoneconf);
cfg_obj_destroy(&zoneconf);
}
if (text != NULL) {
isc_buffer_free(&text);
@ -9348,10 +9348,10 @@ load_configuration(named_server_t *server, bool first_time) {
cleanup:
if (bindkeys != NULL) {
cfg_obj_destroy(parser, &bindkeys);
cfg_obj_destroy(&bindkeys);
}
if (config != NULL) {
cfg_obj_destroy(parser, &config);
cfg_obj_destroy(&config);
}
cfg_parser_destroy(&parser);
@ -9594,7 +9594,7 @@ shutdown_server(void *arg) {
cfg_aclconfctx_detach(&server->aclctx);
}
cfg_obj_destroy(named_g_parser, &named_g_defaultconfig);
cfg_obj_destroy(&named_g_defaultconfig);
cfg_parser_destroy(&named_g_parser);
cfg_parser_destroy(&named_g_addparser);
@ -13029,7 +13029,7 @@ cleanup:
}
if (nzf_config != NULL) {
cfg_obj_destroy(named_g_addparser, &nzf_config);
cfg_obj_destroy(&nzf_config);
}
return result;
@ -13153,7 +13153,7 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp,
cleanup:
if (zoneconf != NULL) {
cfg_obj_destroy(named_g_addparser, &zoneconf);
cfg_obj_destroy(&zoneconf);
}
if (view != NULL) {
dns_view_detach(&view);
@ -13197,7 +13197,7 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config,
e = UNCONST(elt);
ISC_LIST_UNLINK(*list, e, link);
cfg_obj_destroy(pctx, &e->obj);
cfg_obj_destroy(&e->obj);
isc_mem_put(pctx->mctx, e, sizeof(*e));
result = ISC_R_SUCCESS;
break;
@ -13721,7 +13721,7 @@ cleanup:
(void)putnull(text);
}
if (zoneconf != NULL) {
cfg_obj_destroy(named_g_addparser, &zoneconf);
cfg_obj_destroy(&zoneconf);
}
if (view != NULL) {
dns_view_detach(&view);
@ -14212,7 +14212,7 @@ named_server_showzone(named_server_t *server, isc_lex_t *lex,
cleanup:
#ifdef HAVE_LMDB
if (nzconfig != NULL) {
cfg_obj_destroy(named_g_addparser, &nzconfig);
cfg_obj_destroy(&nzconfig);
}
#endif /* HAVE_LMDB */
if (isc_buffer_usedlength(*text) > 0) {
@ -14232,16 +14232,16 @@ newzone_cfgctx_destroy(void **cfgp) {
if (cfg->conf_parser != NULL) {
if (cfg->config != NULL) {
cfg_obj_destroy(cfg->conf_parser, &cfg->config);
cfg_obj_destroy(&cfg->config);
}
if (cfg->vconfig != NULL) {
cfg_obj_destroy(cfg->conf_parser, &cfg->vconfig);
cfg_obj_destroy(&cfg->vconfig);
}
cfg_parser_destroy(&cfg->conf_parser);
}
if (cfg->add_parser != NULL) {
if (cfg->nzf_config != NULL) {
cfg_obj_destroy(cfg->add_parser, &cfg->nzf_config);
cfg_obj_destroy(&cfg->nzf_config);
}
cfg_parser_destroy(&cfg->add_parser);
}

View file

@ -604,7 +604,7 @@ read_sessionkey(isc_mem_t *mctx) {
cleanup:
if (pctx != NULL) {
if (sessionkey != NULL) {
cfg_obj_destroy(pctx, &sessionkey);
cfg_obj_destroy(&sessionkey);
}
cfg_parser_destroy(&pctx);
}

View file

@ -300,7 +300,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
cleanup:
if (param_obj != NULL) {
cfg_obj_destroy(parser, &param_obj);
cfg_obj_destroy(&param_obj);
}
if (parser != NULL) {
cfg_parser_destroy(&parser);
@ -383,7 +383,7 @@ plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
cleanup:
if (param_obj != NULL) {
cfg_obj_destroy(parser, &param_obj);
cfg_obj_destroy(&param_obj);
}
if (parser != NULL) {
cfg_parser_destroy(&parser);

View file

@ -303,7 +303,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
cleanup:
if (param_obj != NULL) {
cfg_obj_destroy(parser, &param_obj);
cfg_obj_destroy(&param_obj);
}
if (parser != NULL) {
cfg_parser_destroy(&parser);
@ -387,7 +387,7 @@ plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
cleanup:
if (param_obj != NULL) {
cfg_obj_destroy(parser, &param_obj);
cfg_obj_destroy(&param_obj);
}
if (parser != NULL) {
cfg_parser_destroy(&parser);

View file

@ -593,7 +593,7 @@ synthrecord_parseconfig(synthrecord_t *inst, const char *parameters,
cleanup:
if (synthrecordcfg != NULL) {
cfg_obj_destroy(parser, &synthrecordcfg);
cfg_obj_destroy(&synthrecordcfg);
}
if (parser != NULL) {

View file

@ -999,7 +999,7 @@ main(int argc, char **argv) {
isccc_ccmsg_invalidate(&rndc_ccmsg);
cfg_obj_destroy(pctx, &config);
cfg_obj_destroy(&config);
cfg_parser_destroy(&pctx);
isc_mem_put(isc_g_mctx, args, argslen);

View file

@ -217,7 +217,7 @@ cleanup:
}
if (syncplugincfg != NULL) {
cfg_obj_destroy(parser, &syncplugincfg);
cfg_obj_destroy(&syncplugincfg);
}
if (parser != NULL) {

View file

@ -146,7 +146,7 @@ main(int argc, char **argv) {
cfg_print(cfg, output, NULL);
cfg_obj_destroy(pctx, &cfg);
cfg_obj_destroy(&cfg);
cfg_parser_destroy(&pctx);
}

View file

@ -191,6 +191,13 @@ cfg_parser_destroy(cfg_parser_t **pctxp);
* more references.
*/
cfg_obj_t *
cfg_parser_currentfile(cfg_parser_t *pctx);
/*%<
* Returns the current file of a parser (as an cfg_obj_t qstring). NULL is non
* existent.
*/
bool
cfg_obj_isvoid(const cfg_obj_t *obj);
/*%<
@ -550,14 +557,14 @@ cfg_obj_attach(cfg_obj_t *src, cfg_obj_t **dest);
*/
void
cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **obj);
cfg_obj_destroy(cfg_obj_t **obj);
/*%<
* Delete a reference to a configuration object; destroy the object if
* there are no more references.
*
* Require:
* \li '*obj' is a valid cfg_obj_t.
* \li 'pctx' is a valid cfg_parser_t.
* \li 'mctx' is a valid isc_mem_t.
*/
void

View file

@ -102,7 +102,7 @@ typedef isc_result_t (*cfg_parsefunc_t)(cfg_parser_t *, const cfg_type_t *type,
cfg_obj_t **);
typedef void (*cfg_printfunc_t)(cfg_printer_t *, const cfg_obj_t *);
typedef void (*cfg_docfunc_t)(cfg_printer_t *, const cfg_type_t *);
typedef void (*cfg_freefunc_t)(cfg_parser_t *, cfg_obj_t *);
typedef void (*cfg_freefunc_t)(cfg_obj_t *);
/*
* Structure definitions
@ -180,6 +180,10 @@ struct cfg_rep {
*/
struct cfg_obj {
unsigned int magic;
isc_mem_t *mctx;
isc_refcount_t references;
const cfg_type_t *type;
union {
uint32_t uint32;
@ -197,10 +201,8 @@ struct cfg_obj {
cfg_netprefix_t netprefix;
isccfg_duration_t duration;
} value;
isc_refcount_t references; /*%< reference counter */
cfg_obj_t *file; /*%< refcounted string */
unsigned int line;
cfg_parser_t *pctx;
cfg_obj_t *file; /*%< separate string with its own refcount */
unsigned int line;
};
/*% A list element. */
@ -354,7 +356,8 @@ cfg_ungettoken(cfg_parser_t *pctx);
#define CFG_LEXOPT_QSTRING (ISC_LEXOPT_QSTRING | ISC_LEXOPT_QSTRINGMULTILINE)
isc_result_t
cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **objp);
cfg_create_obj(isc_mem_t *mctx, cfg_obj_t *file, size_t line,
const cfg_type_t *type, cfg_obj_t **ret);
void
cfg_print_rawuint(cfg_printer_t *pctx, unsigned int u);

View file

@ -42,10 +42,10 @@
} while (0)
/*% Clean up a configuration object if non-NULL. */
#define CLEANUP_OBJ(obj) \
do { \
if ((obj) != NULL) \
cfg_obj_destroy(pctx, &(obj)); \
#define CLEANUP_OBJ(obj) \
do { \
if ((obj) != NULL) \
cfg_obj_destroy(&(obj)); \
} while (0)
/*%
@ -414,7 +414,8 @@ parse_updatepolicy(cfg_parser_t *pctx, const cfg_type_t *type,
strcasecmp(TOKEN_STRING(pctx), "local") == 0)
{
cfg_obj_t *obj = NULL;
CHECK(cfg_create_obj(pctx, &cfg_type_ustring, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_ustring, &obj));
obj->value.string.length = strlen("local");
obj->value.string.base =
isc_mem_get(pctx->mctx, obj->value.string.length + 1);
@ -972,7 +973,8 @@ parse_qstringornone(cfg_parser_t *pctx, const cfg_type_t *type,
if (pctx->token.type == isc_tokentype_string &&
strcasecmp(TOKEN_STRING(pctx), "none") == 0)
{
return cfg_create_obj(pctx, &cfg_type_none, ret);
return cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_none, ret);
}
cfg_ungettoken(pctx);
return cfg_parse_qstring(pctx, type, ret);
@ -1014,7 +1016,8 @@ parse_boolorauto(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
if (pctx->token.type == isc_tokentype_string &&
strcasecmp(TOKEN_STRING(pctx), "auto") == 0)
{
return cfg_create_obj(pctx, &cfg_type_auto, ret);
return cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_auto, ret);
}
cfg_ungettoken(pctx);
return cfg_parse_boolean(pctx, type, ret);
@ -1068,12 +1071,15 @@ parse_serverid(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
if (pctx->token.type == isc_tokentype_string &&
strcasecmp(TOKEN_STRING(pctx), "none") == 0)
{
return cfg_create_obj(pctx, &cfg_type_none, ret);
return cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_none, ret);
}
if (pctx->token.type == isc_tokentype_string &&
strcasecmp(TOKEN_STRING(pctx), "hostname") == 0)
{
result = cfg_create_obj(pctx, &cfg_type_hostname, ret);
result = cfg_create_obj(pctx->mctx,
cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_hostname, ret);
if (result == ISC_R_SUCCESS) {
(*ret)->value.boolean = true;
}
@ -2814,7 +2820,8 @@ parse_sizeval(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
}
CHECK(parse_unitstring(TOKEN_STRING(pctx), &val));
CHECK(cfg_create_obj(pctx, &cfg_type_uint64, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_uint64, &obj));
obj->value.uint64 = val;
*ret = obj;
return ISC_R_SUCCESS;
@ -2845,13 +2852,15 @@ parse_sizeval_percent(cfg_parser_t *pctx, const cfg_type_t *type,
percent = strtoull(TOKEN_STRING(pctx), &endp, 10);
if (*endp == '%' && *(endp + 1) == 0) {
CHECK(cfg_create_obj(pctx, &cfg_type_percentage, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_percentage, &obj));
obj->value.uint32 = (uint32_t)percent;
*ret = obj;
return ISC_R_SUCCESS;
} else {
CHECK(parse_unitstring(TOKEN_STRING(pctx), &val));
CHECK(cfg_create_obj(pctx, &cfg_type_uint64, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_uint64, &obj));
obj->value.uint64 = val;
*ret = obj;
return ISC_R_SUCCESS;
@ -3278,7 +3287,8 @@ parse_querysource(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
strcasecmp(TOKEN_STRING(pctx), "none") == 0)
{
CHECK(cfg_gettoken(pctx, 0));
CHECK(cfg_create_obj(pctx, &cfg_type_none, ret));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_none, ret));
} else {
CHECK(cfg_parse_sockaddr_generic(pctx, &cfg_type_querysource,
type, ret));
@ -3479,7 +3489,9 @@ parse_logseverity(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
* This makes little sense, but we support it for
* compatibility with BIND 8.
*/
CHECK(cfg_create_obj(pctx, &cfg_type_uint32, ret));
CHECK(cfg_create_obj(
pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_uint32, ret));
(*ret)->value.uint32 = 1;
}
(*ret)->type = &cfg_type_debuglevel; /* XXX kludge */

View file

@ -88,18 +88,21 @@
} while (0)
/* Clean up a configuration object if non-NULL. */
#define CLEANUP_OBJ(obj) \
do { \
if ((obj) != NULL) \
cfg_obj_destroy(pctx, &(obj)); \
#define CLEANUP_OBJ(obj) \
do { \
if ((obj) != NULL) \
cfg_obj_destroy(&(obj)); \
} while (0)
/* cfg_obj_t magic number */
#define CFGOBJ_MAGIC ISC_MAGIC('c', 'f', 'g', 'o')
/*
* Forward declarations of static functions.
*/
static void
free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj);
free_tuple(cfg_obj_t *obj);
static isc_result_t
parse_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
@ -108,7 +111,7 @@ static void
print_list(cfg_printer_t *pctx, const cfg_obj_t *obj);
static void
free_list(cfg_parser_t *pctx, cfg_obj_t *obj);
free_list(cfg_obj_t *obj);
static isc_result_t
create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp);
@ -118,23 +121,23 @@ create_string(cfg_parser_t *pctx, const char *contents, const cfg_type_t *type,
cfg_obj_t **ret);
static void
free_string(cfg_parser_t *pctx, cfg_obj_t *obj);
free_string(cfg_obj_t *obj);
static void
free_sockaddrtls(cfg_parser_t *pctx, cfg_obj_t *obj);
free_sockaddrtls(cfg_obj_t *obj);
static isc_result_t
create_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **objp);
static void
free_map(cfg_parser_t *pctx, cfg_obj_t *obj);
free_map(cfg_obj_t *obj);
static isc_result_t
parse_symtab_elt(cfg_parser_t *pctx, const char *name, cfg_type_t *elttype,
isc_symtab_t *symtab, bool callback);
static void
free_noop(cfg_parser_t *pctx, cfg_obj_t *obj);
free_noop(cfg_obj_t *obj);
static isc_result_t
cfg_getstringtoken(cfg_parser_t *pctx);
@ -236,6 +239,25 @@ print_close(cfg_printer_t *pctx) {
cfg_print_cstr(pctx, "}");
}
cfg_obj_t *
cfg_parser_currentfile(cfg_parser_t *pctx) {
cfg_listelt_t *elt = NULL;
cfg_obj_t *fileobj = NULL;
if (pctx->open_files == NULL) {
return NULL;
}
elt = ISC_LIST_TAIL(pctx->open_files->value.list);
if (elt == NULL) {
return NULL;
}
fileobj = elt->obj;
INSIST(fileobj->type == &cfg_type_qstring);
return fileobj;
}
isc_result_t
cfg_parse_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_result_t result;
@ -299,7 +321,8 @@ cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
nfields++;
}
CHECK(cfg_create_obj(pctx, type, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, type, &obj));
obj->value.tuple = isc_mem_cget(pctx->mctx, nfields,
sizeof(cfg_obj_t *));
for (f = fields, i = 0; f->name != NULL; f++, i++) {
@ -386,7 +409,7 @@ cfg_doc_tuple(cfg_printer_t *pctx, const cfg_type_t *type) {
}
static void
free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj) {
free_tuple(cfg_obj_t *obj) {
unsigned int i;
const cfg_tuplefielddef_t *fields = obj->type->of;
const cfg_tuplefielddef_t *f;
@ -400,8 +423,7 @@ free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj) {
CLEANUP_OBJ(obj->value.tuple[i]);
nfields++;
}
isc_mem_cput(pctx->mctx, obj->value.tuple, nfields,
sizeof(cfg_obj_t *));
isc_mem_cput(obj->mctx, obj->value.tuple, nfields, sizeof(cfg_obj_t *));
}
bool
@ -746,7 +768,8 @@ cfg_parse_void(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
UNUSED(type);
return cfg_create_obj(pctx, &cfg_type_void, ret);
return cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_void, ret);
}
void
@ -804,7 +827,8 @@ cfg_parse_percentage(cfg_parser_t *pctx, const cfg_type_t *type,
return ISC_R_UNEXPECTEDTOKEN;
}
CHECK(cfg_create_obj(pctx, &cfg_type_percentage, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_percentage, &obj));
obj->value.uint32 = (uint32_t)percent;
*ret = obj;
@ -877,7 +901,8 @@ cfg_parse_fixedpoint(cfg_parser_t *pctx, const cfg_type_t *type,
return ISC_R_UNEXPECTEDTOKEN;
}
CHECK(cfg_create_obj(pctx, &cfg_type_fixedpoint, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_fixedpoint, &obj));
obj->value.uint32 = strtoul(p, NULL, 10) * 100;
switch (n3) {
@ -943,7 +968,8 @@ cfg_parse_uint32(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
return ISC_R_UNEXPECTEDTOKEN;
}
CHECK(cfg_create_obj(pctx, &cfg_type_uint32, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_uint32, &obj));
obj->value.uint32 = pctx->token.value.as_ulong;
*ret = obj;
@ -1164,7 +1190,8 @@ parse_duration(cfg_parser_t *pctx, cfg_obj_t **ret) {
goto cleanup;
}
CHECK(cfg_create_obj(pctx, &cfg_type_duration, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_duration, &obj));
obj->value.duration = duration;
*ret = obj;
@ -1219,7 +1246,8 @@ cfg_parse_duration_or_unlimited(cfg_parser_t *pctx, const cfg_type_t *type,
duration.iso8601 = false;
duration.unlimited = true;
CHECK(cfg_create_obj(pctx, &cfg_type_duration, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_duration, &obj));
obj->value.duration = duration;
*ret = obj;
return ISC_R_SUCCESS;
@ -1271,7 +1299,8 @@ create_string(cfg_parser_t *pctx, const char *contents, const cfg_type_t *type,
cfg_obj_t *obj = NULL;
int len;
CHECK(cfg_create_obj(pctx, type, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, type, &obj));
len = strlen(contents);
obj->value.string.length = len;
obj->value.string.base = isc_mem_get(pctx->mctx, len + 1);
@ -1543,16 +1572,16 @@ print_sstring(cfg_printer_t *pctx, const cfg_obj_t *obj) {
}
static void
free_string(cfg_parser_t *pctx, cfg_obj_t *obj) {
isc_mem_put(pctx->mctx, obj->value.string.base,
free_string(cfg_obj_t *obj) {
isc_mem_put(obj->mctx, obj->value.string.base,
obj->value.string.length + 1);
}
static void
free_sockaddrtls(cfg_parser_t *pctx, cfg_obj_t *obj) {
free_sockaddrtls(cfg_obj_t *obj) {
if (obj->value.sockaddrtls.tls.base != NULL) {
INSIST(obj->value.sockaddrtls.tls.length != 0);
isc_mem_put(pctx->mctx, obj->value.sockaddrtls.tls.base,
isc_mem_put(obj->mctx, obj->value.sockaddrtls.tls.base,
obj->value.sockaddrtls.tls.length + 1);
}
}
@ -1881,7 +1910,8 @@ cfg_parse_boolean(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
goto bad_boolean;
}
CHECK(cfg_create_obj(pctx, &cfg_type_boolean, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_boolean, &obj));
obj->value.boolean = value;
*ret = obj;
return result;
@ -1922,7 +1952,8 @@ cfg_create_list(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **obj) {
REQUIRE(type != NULL);
REQUIRE(obj != NULL && *obj == NULL);
CHECK(cfg_create_obj(pctx, type, obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, type, obj));
ISC_LIST_INIT((*obj)->value.list);
cleanup:
return result;
@ -1940,17 +1971,17 @@ create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) {
}
static void
free_listelt(cfg_parser_t *pctx, cfg_listelt_t *elt) {
free_listelt(isc_mem_t *mctx, cfg_listelt_t *elt) {
if (elt->obj != NULL) {
cfg_obj_destroy(pctx, &elt->obj);
cfg_obj_destroy(&elt->obj);
}
isc_mem_put(pctx->mctx, elt, sizeof(*elt));
isc_mem_put(mctx, elt, sizeof(*elt));
}
static void
free_list(cfg_parser_t *pctx, cfg_obj_t *obj) {
free_list(cfg_obj_t *obj) {
ISC_LIST_FOREACH(obj->value.list, elt, link) {
free_listelt(pctx, elt);
free_listelt(obj->mctx, elt);
}
}
@ -2012,7 +2043,7 @@ parse_list(cfg_parser_t *pctx, const cfg_type_t *listtype, cfg_obj_t **ret) {
cleanup:
if (elt != NULL) {
free_listelt(pctx, elt);
free_listelt(pctx->mctx, elt);
}
CLEANUP_OBJ(listobj);
return result;
@ -2274,7 +2305,7 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
CHECK(parser_openfile(pctx, g.gl_pathv[i]));
}
cfg_obj_destroy(pctx, &includename);
cfg_obj_destroy(&includename);
globfree(&g);
goto redo;
@ -2302,7 +2333,7 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
*/
CHECK(cfg_parse_obj(pctx, &cfg_type_unsupported,
&eltobj));
cfg_obj_destroy(pctx, &eltobj);
cfg_obj_destroy(&eltobj);
CHECK(parse_semicolon(pctx));
continue;
}
@ -2786,7 +2817,8 @@ parse_token(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
UNUSED(type);
CHECK(cfg_create_obj(pctx, &cfg_type_token, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_token, &obj));
CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
if (pctx->token.type == isc_tokentype_eof) {
cfg_ungettoken(pctx);
@ -3056,7 +3088,8 @@ parse_netaddr(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_netaddr_t netaddr;
unsigned int flags = *(const unsigned int *)type->of;
CHECK(cfg_create_obj(pctx, type, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, type, &obj));
CHECK(cfg_parse_rawaddr(pctx, flags, &netaddr));
isc_sockaddr_fromnetaddr(&obj->value.sockaddr, &netaddr, 0);
*ret = obj;
@ -3185,7 +3218,8 @@ cfg_parse_netprefix(cfg_parser_t *pctx, const cfg_type_t *type,
}
prefixlen = addrlen;
}
CHECK(cfg_create_obj(pctx, &cfg_type_netprefix, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, &cfg_type_netprefix, &obj));
obj->value.netprefix.address = netaddr;
obj->value.netprefix.prefixlen = prefixlen;
*ret = obj;
@ -3313,7 +3347,8 @@ parse_sockaddrsub(cfg_parser_t *pctx, const cfg_type_t *type, int flags,
goto cleanup;
}
CHECK(cfg_create_obj(pctx, type, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, type, &obj));
if (have_tls == 1) {
obj->value.sockaddrtls.tls = tls;
}
@ -3595,40 +3630,6 @@ cfg_parser_warning(cfg_parser_t *pctx, unsigned int flags, const char *fmt,
#define MAX_LOG_TOKEN 30 /* How much of a token to quote in log messages. */
static bool
have_current_file(cfg_parser_t *pctx) {
cfg_listelt_t *elt;
if (pctx->open_files == NULL) {
return false;
}
elt = ISC_LIST_TAIL(pctx->open_files->value.list);
if (elt == NULL) {
return false;
}
return true;
}
static cfg_obj_t *
current_file(cfg_parser_t *pctx) {
cfg_listelt_t *elt;
cfg_obj_t *fileobj;
if (!have_current_file(pctx)) {
return NULL;
}
elt = ISC_LIST_TAIL(pctx->open_files->value.list);
if (elt == NULL) { /* shouldn't be possible, but... */
return NULL;
}
fileobj = elt->obj;
INSIST(fileobj->type == &cfg_type_qstring);
return fileobj;
}
static void
parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags,
const char *format, va_list args) {
@ -3637,6 +3638,7 @@ parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags,
static char message[2048];
int level = ISC_LOG_ERROR;
const char *prep = "";
const cfg_obj_t *file = NULL;
size_t len;
if (is_warning) {
@ -3644,10 +3646,10 @@ parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags,
}
where[0] = '\0';
if (have_current_file(pctx)) {
file = cfg_parser_currentfile(pctx);
if (file != NULL) {
snprintf(where, sizeof(where),
"%s:%u: ", cfg_obj_asstring(current_file(pctx)),
pctx->line);
"%s:%u: ", cfg_obj_asstring(file), pctx->line);
} else if (pctx->buf_name != NULL) {
snprintf(where, sizeof(where), "%s: ", pctx->buf_name);
}
@ -3736,19 +3738,19 @@ cfg_obj_line(const cfg_obj_t *obj) {
}
isc_result_t
cfg_create_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
cfg_create_obj(isc_mem_t *mctx, cfg_obj_t *file, size_t line,
const cfg_type_t *type, cfg_obj_t **ret) {
cfg_obj_t *obj;
cfg_obj_t *file = NULL;
REQUIRE(pctx != NULL);
REQUIRE(mctx != NULL);
REQUIRE(type != NULL);
REQUIRE(ret != NULL && *ret == NULL);
obj = isc_mem_get(pctx->mctx, sizeof(cfg_obj_t));
*obj = (cfg_obj_t){ .type = type, .line = pctx->line, .pctx = pctx };
isc_refcount_init(&obj->references, 1);
obj = isc_mem_get(mctx, sizeof(cfg_obj_t));
*obj = (cfg_obj_t){ .magic = CFGOBJ_MAGIC, .type = type, .line = line };
file = current_file(pctx);
isc_refcount_init(&obj->references, 1);
isc_mem_attach(mctx, &obj->mctx);
if (file != NULL) {
cfg_obj_attach(file, &obj->file);
}
@ -3762,12 +3764,12 @@ static void
map_symtabitem_destroy(char *key, unsigned int type, isc_symvalue_t symval,
void *userarg) {
cfg_obj_t *obj = symval.as_pointer;
cfg_parser_t *pctx = (cfg_parser_t *)userarg;
UNUSED(key);
UNUSED(type);
UNUSED(userarg);
cfg_obj_destroy(pctx, &obj);
cfg_obj_destroy(&obj);
}
static isc_result_t
@ -3776,7 +3778,8 @@ create_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
isc_symtab_t *symtab = NULL;
cfg_obj_t *obj = NULL;
CHECK(cfg_create_obj(pctx, type, &obj));
CHECK(cfg_create_obj(pctx->mctx, cfg_parser_currentfile(pctx),
pctx->line, type, &obj));
isc_symtab_create(pctx->mctx, map_symtabitem_destroy, pctx, false,
&symtab);
obj->value.map.symtab = symtab;
@ -3793,7 +3796,7 @@ cleanup:
}
static void
free_map(cfg_parser_t *pctx, cfg_obj_t *obj) {
free_map(cfg_obj_t *obj) {
CLEANUP_OBJ(obj->value.map.id);
isc_symtab_destroy(&obj->value.map.symtab);
}
@ -3810,21 +3813,24 @@ cfg_obj_istype(const cfg_obj_t *obj, const cfg_type_t *type) {
* Destroy 'obj', a configuration object created in 'pctx'.
*/
void
cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **objp) {
cfg_obj_destroy(cfg_obj_t **objp) {
REQUIRE(objp != NULL && *objp != NULL);
REQUIRE(pctx != NULL);
REQUIRE((*objp)->magic == CFGOBJ_MAGIC);
cfg_obj_t *obj = *objp;
*objp = NULL;
if (isc_refcount_decrement(&obj->references) == 1) {
obj->magic = 0;
if (obj->file != NULL) {
cfg_obj_destroy(obj->file->pctx, &obj->file);
cfg_obj_destroy(&obj->file);
}
obj->type->rep->free(pctx, obj);
obj->type->rep->free(obj);
isc_refcount_destroy(&obj->references);
isc_mem_put(pctx->mctx, obj, sizeof(cfg_obj_t));
isc_mem_putanddetach(&obj->mctx, obj, sizeof(cfg_obj_t));
}
}
@ -3838,8 +3844,7 @@ cfg_obj_attach(cfg_obj_t *src, cfg_obj_t **dest) {
}
static void
free_noop(cfg_parser_t *pctx, cfg_obj_t *obj) {
UNUSED(pctx);
free_noop(cfg_obj_t *obj) {
UNUSED(obj);
}
@ -3943,7 +3948,7 @@ breakout:
cleanup:
if (elt != NULL) {
free_listelt(pctx, elt);
free_listelt(pctx->mctx, elt);
}
CLEANUP_OBJ(destobj);

View file

@ -192,7 +192,7 @@ ISC_RUN_TEST_IMPL(duration) {
assert_int_equal(cmp, 0);
}
cfg_obj_destroy(p1, &c1);
cfg_obj_destroy(&c1);
cfg_parser_destroy(&p1);
}
}

View file

@ -102,7 +102,7 @@ ISC_RUN_TEST_IMPL(addzoneconf) {
strlcat(buf, ";", sizeof(buf));
assert_string_equal(tests[i], buf);
cfg_obj_destroy(p, &conf);
cfg_obj_destroy(&conf);
cfg_parser_reset(p);
}
@ -141,8 +141,8 @@ ISC_RUN_TEST_IMPL(parse_buffer) {
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(p2->line, 104);
cfg_obj_destroy(p1, &c1);
cfg_obj_destroy(p2, &c2);
cfg_obj_destroy(&c1);
cfg_obj_destroy(&c2);
cfg_parser_destroy(&p1);
cfg_parser_destroy(&p2);