Commit 5a4b2161 authored by Daniel Salzman's avatar Daniel Salzman

modules: improve STR config item handling code

parent 5a7068ba
Pipeline #1761 passed with stages
in 4 minutes and 51 seconds
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -139,7 +139,7 @@ static void dump_to_file(FILE *fd, server_t *server)
// Get the server identity.
conf_val_t val = conf_get(conf(), C_SRV, C_IDENT);
const char *ident = conf_str(&val);
if (val.code != KNOT_EOK || ident[0] == '\0') {
if (ident == NULL || ident[0] == '\0') {
ident = conf()->hostname;
}
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -33,7 +33,7 @@
const yp_item_t scheme_mod_dnstap[] = {
{ C_ID, YP_TSTR, YP_VNONE },
{ MOD_SINK, YP_TSTR, YP_VNONE },
{ MOD_SINK, YP_TSTR, YP_VSTR = { "" } },
{ MOD_IDENTITY, YP_TSTR, YP_VNONE },
{ MOD_VERSION, YP_TSTR, YP_VSTR = { "Knot DNS " PACKAGE_VERSION } },
{ MOD_QUERIES, YP_TBOOL, YP_VBOOL = { true } },
......@@ -46,7 +46,7 @@ int check_mod_dnstap(conf_check_t *args)
{
conf_val_t sink = conf_rawid_get_txn(args->conf, args->txn, C_MOD_DNSTAP,
MOD_SINK, args->id, args->id_len);
if (sink.code != KNOT_EOK) {
if (conf_str(&sink)[0] == '\0') {
args->err_str = "no sink specified";
return KNOT_EINVAL;
}
......@@ -235,17 +235,19 @@ int dnstap_load(struct query_module *self)
/* Set identity. */
val = conf_mod_get(self->config, MOD_IDENTITY, self->id);
if (val.code == KNOT_EOK) {
ctx->identity = strdup(conf_str(&val));
const char *ident = conf_str(&val);
ctx->identity = (ident != NULL) ? strdup(ident) : NULL;
} else {
ctx->identity = sockaddr_hostname();
ctx->identity = strdup(self->config->hostname);
}
ctx->identity_len = (ctx->identity != NULL) ? strlen(ctx->identity) : 0;
/* Set version. */
val = conf_mod_get(self->config, MOD_VERSION, self->id);
ctx->version = strdup(conf_str(&val));
ctx->version = strdup(conf_str(&val)); // Default ensures != NULL.
ctx->version_len = strlen(ctx->version);
/* Set sink. */
val = conf_mod_get(self->config, MOD_SINK, self->id);
const char *sink = conf_str(&val);
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -27,7 +27,7 @@
const yp_item_t scheme_mod_rosedb[] = {
{ C_ID, YP_TSTR, YP_VNONE },
{ MOD_DBDIR, YP_TSTR, YP_VNONE },
{ MOD_DBDIR, YP_TSTR, YP_VSTR = { "" } },
{ C_COMMENT, YP_TSTR, YP_VNONE },
{ NULL }
};
......@@ -36,7 +36,7 @@ int check_mod_rosedb(conf_check_t *args)
{
conf_val_t dir = conf_rawid_get_txn(args->conf, args->txn, C_MOD_ROSEDB,
MOD_DBDIR, args->id, args->id_len);
if (dir.code != KNOT_EOK) {
if (conf_str(&dir)[0] == '\0') {
args->err_str = "no database directory specified";
return KNOT_EINVAL;
}
......@@ -468,11 +468,11 @@ static int rosedb_send_log(int sock, struct sockaddr_storage *dst_addr, knot_pkt
/* Host name / Component. */
conf_val_t val = conf_get(conf(), C_SRV, C_IDENT);
if (val.code != KNOT_EOK || val.len <= 1) {
STREAM_WRITE(stream, &maxlen, snprintf, "%s ", conf()->hostname);
} else {
STREAM_WRITE(stream, &maxlen, snprintf, "%s ", conf_str(&val));
const char *ident = conf_str(&val);
if (ident == NULL || ident[0] == '\0') {
ident = conf()->hostname;
}
STREAM_WRITE(stream, &maxlen, snprintf, "%s ", ident);
STREAM_WRITE(stream, &maxlen, snprintf, "%s[%lu]: ", PACKAGE_NAME, (unsigned long) getpid());
/* Prepare log message line. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment