Commit 66818adc authored by Jan Včelák's avatar Jan Včelák 🚀

Merge branch 'conf_zone_name' into 'master'

- '%s' zone file name formatter always removes trailing dot
- 'reload' event is renamed to 'load' event
parents 30b216cf 5cbef80e
......@@ -568,7 +568,7 @@ If the label is not available, the formatter has no effect.
\fB%s\fP – means the current zone name in the textual representation (beware
of special characters which are escaped or encoded in the \eDDD form where
DDD is corresponding decimal ASCII code). The zone name doesn\(aqt include the
terminating dot, except for the root zone.
terminating dot (the result for the root zone is the empty string!).
.IP \(bu 2
\fB%%\fP – means the \fB%\fP character
.UNINDENT
......
......@@ -651,7 +651,7 @@ A path to the zone file. Non absolute path is relative to
- ``%s`` – means the current zone name in the textual representation (beware
of special characters which are escaped or encoded in the \\DDD form where
DDD is corresponding decimal ASCII code). The zone name doesn't include the
terminating dot, except for the root zone.
terminating dot (the result for the root zone is the empty string!).
- ``%%`` – means the ``%`` character
*Default:* :ref:`storage<zone_storage>`/``%s``\ .zone
......
......@@ -773,11 +773,10 @@ static int str_char(
return KNOT_EINVAL;
}
// Remove the trailing dot if not root zone.
// Remove the trailing dot.
size_t zone_len = strlen(buff);
if (zone_len > 1) {
buff[zone_len--] = '\0';
}
assert(zone_len > 0);
buff[zone_len--] = '\0';
// Get the block length.
size_t len = index2 - index1 + 1;
......
......@@ -783,8 +783,9 @@ static int cmd_checkzone(cmd_args_t *args)
}
/* Create zone loader context. */
zone_contents_t *contents = zone_load_contents(conf(), conf_dname(&id));
if (contents == NULL) {
zone_contents_t *contents;
int ret = zone_load_contents(conf(), conf_dname(&id), &contents);
if (ret != KNOT_EOK) {
rc = 1;
continue;
}
......
......@@ -219,7 +219,7 @@ static int remote_zone_reload(zone_t *zone, remote_cmdargs_t *a)
return KNOT_EOK;
}
zone_events_schedule(zone, ZONE_EVENT_RELOAD, ZONE_EVENT_NOW);
zone_events_schedule(zone, ZONE_EVENT_LOAD, ZONE_EVENT_NOW);
return KNOT_EOK;
}
......
......@@ -43,7 +43,7 @@ typedef struct event_info {
} event_info_t;
static const event_info_t EVENT_INFO[] = {
{ ZONE_EVENT_RELOAD, event_reload, "reload" },
{ ZONE_EVENT_LOAD, event_load, "load" },
{ ZONE_EVENT_REFRESH, event_refresh, "refresh" },
{ ZONE_EVENT_XFER, event_xfer, "transfer" },
{ ZONE_EVENT_UPDATE, event_update, "update" },
......
......@@ -33,7 +33,7 @@ struct server;
typedef enum zone_event_type {
ZONE_EVENT_INVALID = -1,
// supported event types
ZONE_EVENT_RELOAD = 0,
ZONE_EVENT_LOAD = 0,
ZONE_EVENT_REFRESH,
ZONE_EVENT_XFER,
ZONE_EVENT_UPDATE,
......
......@@ -311,7 +311,7 @@ static void start_expire_timer(zone_t *zone, const knot_rdataset_t *soa)
/* -- zone events handling callbacks --------------------------------------- */
int event_reload(zone_t *zone)
int event_load(zone_t *zone)
{
assert(zone);
......@@ -320,35 +320,37 @@ int event_reload(zone_t *zone)
time_t mtime = zonefile_mtime(filename);
free(filename);
uint32_t dnssec_refresh = time(NULL);
zone_contents_t *contents = zone_load_contents(conf(), zone->name);
if (!contents) {
return KNOT_ERROR;
zone_contents_t *contents;
int ret = zone_load_contents(conf(), zone->name, &contents);
if (ret != KNOT_EOK) {
return ret;
}
/* Store zonefile serial and apply changes from the journal. */
zone->zonefile_serial = zone_contents_serial(contents);
int result = zone_load_journal(conf(), zone, contents);
if (result != KNOT_EOK) {
ret = zone_load_journal(conf(), zone, contents);
if (ret != KNOT_EOK) {
goto fail;
}
/* Post load actions - calculate delta, sign with DNSSEC... */
/*! \todo issue #242 dnssec signing should occur in the special event */
result = zone_load_post(conf(), contents, zone, &dnssec_refresh);
if (result != KNOT_EOK) {
if (result == KNOT_ESPACE) {
ret = zone_load_post(conf(), contents, zone, &dnssec_refresh);
if (ret != KNOT_EOK) {
if (ret == KNOT_ESPACE) {
log_zone_error(zone->name, "journal size is too small "
"to fit the changes");
} else {
log_zone_error(zone->name, "failed to store changes into "
"journal (%s)", knot_strerror(result));
"journal (%s)", knot_strerror(ret));
}
goto fail;
}
/* Check zone contents consistency. */
result = zone_load_check(conf(), contents);
if (result != KNOT_EOK) {
ret = zone_load_check(conf(), contents);
if (ret != KNOT_EOK) {
goto fail;
}
......@@ -392,7 +394,7 @@ int event_reload(zone_t *zone)
fail:
zone_contents_deep_free(&contents);
return result;
return ret;
}
static int try_refresh(zone_t *zone, const conf_remote_t *master, void *ctx)
......
......@@ -18,8 +18,8 @@
#include "knot/zone/events/events.h"
/*! \brief Reloads the potentially changed zone. */
int event_reload(zone_t *zone);
/*! \brief Loads or reloads potentially changed zone. */
int event_load(zone_t *zone);
/*! \brief Sends a SOA query to master. */
int event_refresh(zone_t *zone);
/*! \brief Initiates transfer with master. */
......
......@@ -24,10 +24,12 @@
#include "knot/updates/apply.h"
#include "libknot/libknot.h"
zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name)
int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
zone_contents_t **contents)
{
assert(conf);
assert(zone_name);
assert(contents);
zloader_t zl;
char *zonefile = conf_zonefile(conf, zone_name);
......@@ -35,7 +37,7 @@ zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name)
int ret = zonefile_open(&zl, zonefile, zone_name, conf_bool(&val));
free(zonefile);
if (ret != KNOT_EOK) {
return NULL;
return ret;
}
/* Set the zone type (master/slave). If zone has no master set, we
......@@ -43,13 +45,13 @@ zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name)
*/
zl.creator->master = !zone_load_can_bootstrap(conf, zone_name);
zone_contents_t *zone_contents = zonefile_load(&zl);
*contents = zonefile_load(&zl);
zonefile_close(&zl);
if (zone_contents == NULL) {
return NULL;
if (*contents == NULL) {
return KNOT_ERROR;
}
return zone_contents;
return KNOT_EOK;
}
/*! \brief Check zone configuration constraints. */
......
......@@ -26,9 +26,11 @@
*
* \param conf
* \param zone_name
* \return new zone contents or NULL
* \param contents
* \return KNOT_EOK or an error
*/
zone_contents_t *zone_load_contents(conf_t *conf, const knot_dname_t *zone_name);
int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
zone_contents_t **contents);
/*!
* \brief Check loaded zone contents validity.
......
......@@ -151,7 +151,7 @@ static zone_t *create_zone_reload(conf_t *conf, const knot_dname_t *name,
switch (zstatus) {
case ZONE_STATUS_FOUND_UPDATED:
/* Enqueueing makes the first zone load waitable. */
zone_events_enqueue(zone, ZONE_EVENT_RELOAD);
zone_events_enqueue(zone, ZONE_EVENT_LOAD);
/* Replan DDNS processing if there are pending updates. */
zone_events_replan_ddns(zone, old_zone);
break;
......@@ -229,7 +229,7 @@ static zone_t *create_zone_new(conf_t * conf, const knot_dname_t *name,
switch (zstatus) {
case ZONE_STATUS_FOUND_NEW:
/* Enqueueing makes the first zone load waitable. */
zone_events_enqueue(zone, ZONE_EVENT_RELOAD);
zone_events_enqueue(zone, ZONE_EVENT_LOAD);
break;
case ZONE_STATUS_BOOSTRAP:
if (zone_events_get_time(zone, ZONE_EVENT_REFRESH) == 0) {
......
......@@ -223,7 +223,14 @@ int zonefile_open(zloader_t *loader, const char *source,
zs_deinit(&loader->scanner);
free(origin_str);
free(zc);
return KNOT_ERROR;
switch (loader->scanner.error.code) {
case ZS_FILE_OPEN:
case ZS_FILE_INVALID:
return KNOT_EFILE;
default:
return KNOT_EOK;
}
}
free(origin_str);
......
......@@ -77,7 +77,7 @@ static void test_get_filename(void)
check_name(zone, "/%c[4]", "/");
zone = ".";
check_name(zone, "/%c[0]", "/.");
check_name(zone, "/%c[0]", "/");
check_name(zone, "/%c[1]", "/");
// Label formatter.
......
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