Commit 96b10e16 authored by Daniel Salzman's avatar Daniel Salzman

conf: add dynamic interface

parent 01e26ce6
......@@ -197,6 +197,8 @@ src/knot/conf/conf.c
src/knot/conf/conf.h
src/knot/conf/confdb.c
src/knot/conf/confdb.h
src/knot/conf/confio.c
src/knot/conf/confio.h
src/knot/conf/scheme.c
src/knot/conf/scheme.h
src/knot/conf/tools.c
......
......@@ -213,6 +213,8 @@ libknotd_la_SOURCES = \
knot/conf/conf.h \
knot/conf/confdb.c \
knot/conf/confdb.h \
knot/conf/confio.c \
knot/conf/confio.h \
knot/conf/scheme.c \
knot/conf/scheme.h \
knot/conf/tools.c \
......
This diff is collapsed.
/* Copyright (C) 2015 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* Configuration interface.
*
* \addtogroup config
*
* @{
*/
#pragma once
#include "knot/conf/conf.h"
/*! Configuration interface output. */
typedef struct conf_io conf_io_t;
struct conf_io {
/*! Section. */
const yp_item_t *key0;
/*! Section item. */
const yp_item_t *key1;
/*! Section identifier. */
const uint8_t *id;
/*! Section identifier length. */
size_t id_len;
/*! Consider item identifier as item data. */
bool id_as_data;
enum {
/*! Default item state. */
NONE,
/*! New item indicator. */
NEW,
/*! Old item indicator. */
OLD
} type;
struct {
/*! Section item data (NULL if not used). */
conf_val_t *val;
/*! Index of data value to format (counted from 1, 0 means all). */
size_t index;
/*! Binary data value (NULL if not used). */
const uint8_t *bin;
/*! Length of the binary data value. */
size_t bin_len;
} data;
struct {
/*! Edit operation return code. */
int code;
/*! Edit operation return error message. */
const char *str;
} error;
/*! Optional processing callback. */
int (*fcn)(conf_io_t *);
/*! Miscellaneous data useful for the callback. */
void *misc;
};
/*!
* Starts new writing transaction.
*
* \param[in] child Nested transaction indicator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_begin(
bool child
);
/*!
* Commits the current writing transaction.
*
* \param[in] child Nested transaction indicator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_commit(
bool child
);
/*!
* Aborts the current writing transaction.
*
* \param[in] child Nested transaction indicator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_abort(
bool child
);
/*!
* Gets the configuration group item subsection list.
*
* \param[in] key0 Section name (NULL to get section list).
* \param[out] io Operation output.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_desc(
const char *key0,
conf_io_t *io
);
/*!
* Gets the configuration difference between the current configuration and
* the active transaction.
*
* \param[in] key0 Section name (NULL to diff all sections).
* \param[in] key1 Item name (NULL to diff all section items).
* \param[in] id Section identifier name (NULL to consider all section identifiers).
* \param[out] io Operation output.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_diff(
const char *key0,
const char *key1,
const char *id,
conf_io_t *io
);
/*!
* Gets the configuration item(s) value(s).
*
* \param[in] key0 Section name (NULL to get all sections).
* \param[in] key1 Item name (NULL to get all section items).
* \param[in] id Section identifier name (NULL to consider all section identifiers).
* \param[in] get_current The current configuration or the active transaction switch.
* \param[out] io Operation output.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_get(
const char *key0,
const char *key1,
const char *id,
bool get_current,
conf_io_t *io
);
/*!
* Sets the configuration item(s) value.
*
* \param[in] key0 Section name.
* \param[in] key1 Item name (NULL to add identifier only).
* \param[in] id Section identifier name (NULL to consider all section identifiers).
* \param[in] data Item data to set/add.
* \param[out] io Operation output (callback error output).
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_set(
const char *key0,
const char *key1,
const char *id,
const char *data,
conf_io_t *io
);
/*!
* Unsets the configuration item(s) value(s).
*
* \param[in] key0 Section name (NULL to unset all sections).
* \param[in] key1 Item name (NULL to unset the whole section).
* \param[in] id Section identifier name (NULL to consider all section identifiers).
* \param[in] data Item data (NULL to unset all data).
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_unset(
const char *key0,
const char *key1,
const char *id,
const char *data
);
/*!
* Checks the configuration database semantics in the current writing transaction.
*
* \param[out] io Operation output.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_io_check(
conf_io_t *io
);
/*!
* Returns textual item key part of the operation result.
*
* \note The result must be deallocated.
*
* \param[out] io Operation output.
*
* \return String or NULL.
*/
char *conf_io_txt_key(
conf_io_t *io
);
/*!
* Returns textual item data part of the operation result.
*
* \note The result must be deallocated.
*
* \param[out] io Operation output.
*
* \return String or NULL.
*/
char *conf_io_txt_data(
conf_io_t *io
);
/*! @} */
......@@ -482,7 +482,14 @@ int server_reload(server_t *server, const char *cf)
}
if (cf != NULL) {
// Check for no edit mode.
if (conf()->io.txn != NULL) {
log_warning("reload aborted due to active config DB transaction");
return KNOT_CONF_ETXN;
}
log_info("reloading configuration file '%s'", cf);
conf_t *new_conf = NULL;
int ret = conf_clone(&new_conf);
if (ret != KNOT_EOK) {
......
......@@ -133,9 +133,12 @@ static const struct error errors[] = {
{ KNOT_YP_ENOID, "missing identifier" },
/* Configuration errors. */
{ KNOT_CONF_EMPTY, "empty configuration database" },
{ KNOT_CONF_EVERSION, "invalid configuration database version" },
{ KNOT_CONF_EREDEFINE, "duplicate identifier" },
{ KNOT_CONF_EMPTY, "empty configuration database" },
{ KNOT_CONF_EVERSION, "invalid configuration database version" },
{ KNOT_CONF_EREDEFINE, "duplicate identifier" },
{ KNOT_CONF_ETXN, "failed to open another config DB transaction" },
{ KNOT_CONF_ENOTXN, "no active config DB transaction" },
{ KNOT_CONF_EMANYTXN, "too many nested config DB transactions" },
/* Processing errors. */
{ KNOT_LAYER_ERROR, "processing layer error" },
......
......@@ -140,6 +140,9 @@ enum knot_error {
KNOT_CONF_EMPTY,
KNOT_CONF_EVERSION,
KNOT_CONF_EREDEFINE,
KNOT_CONF_ETXN,
KNOT_CONF_ENOTXN,
KNOT_CONF_EMANYTXN,
/* Processing error. */
KNOT_LAYER_ERROR,
......
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