Commit fc957ae4 authored by Daniel Salzman's avatar Daniel Salzman

conf: split the configuration into the base and the interface

parent 2ecc4be6
......@@ -187,6 +187,8 @@ src/knot/common/ref.c
src/knot/common/ref.h
src/knot/common/time.h
src/knot/common/trim.h
src/knot/conf/base.c
src/knot/conf/base.h
src/knot/conf/conf.c
src/knot/conf/conf.h
src/knot/conf/confdb.c
......
......@@ -195,6 +195,8 @@ knot1to2_SOURCES = \
# static: server shared
libknotd_la_SOURCES = \
knot/conf/base.c \
knot/conf/base.h \
knot/conf/conf.c \
knot/conf/conf.h \
knot/conf/confdb.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
*
* Server configuration core.
*
* \addtogroup config
*
* @{
*/
#pragma once
#include "libknot/libknot.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/namedb/namedb.h"
#include "libknot/yparser/ypscheme.h"
#define CONF_XFERS 10
/*! Default template identifier. */
#define CONF_DEFAULT_ID ((uint8_t *)"\x08""default\0")
/*! Default configuration file. */
#define CONF_DEFAULT_FILE (CONFIG_DIR "/knot.conf")
/*! Default configuration database. */
#define CONF_DEFAULT_DBDIR (STORAGE_DIR "/confdb")
/*! Configuration context. */
typedef struct {
/*! Currently used namedb api. */
const struct namedb_api *api;
/*! Configuration scheme. */
yp_item_t *scheme;
/*! Memory context. */
mm_ctx_t *mm;
/*! Configuration database. */
namedb_t *db;
/*! Read-only transaction for config access. */
namedb_txn_t read_txn;
/*! Prearranged hostname string (for automatic NSID or CH ident value). */
char *hostname;
/*! Current config file (for reload if started with config file). */
char *filename;
/*! List of active query modules. */
list_t query_modules;
/*! Default query modules plan. */
struct query_plan *query_plan;
} conf_t;
/*!
* Returns the active configuration.
*/
conf_t* conf(void);
/*!
* Creates new or opens old configuration database.
*
* \param[out] conf Configuration.
* \param[in] scheme Configuration scheme.
* \param[in] db_dir Database path or NULL.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_new(
conf_t **conf,
const yp_item_t *scheme,
const char *db_dir
);
/*!
* Creates a partial copy of the active configuration.
*
* Shared objects: api, mm, db, filename.
*
* \param[out] conf Configuration.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_clone(
conf_t **conf
);
/*!
* Processes some additional operations and checks after configuration loading.
*
* \param[in] conf Configuration.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_post_open(
conf_t *conf
);
/*!
* Replaces the active configuration with the specified one.
*
* \param[in] conf New configuration.
*/
void conf_update(
conf_t *conf
);
/*!
* Removes the specified configuration.
*
* \param[in] conf Configuration.
* \param[in] is_clone Specifies if the configuration is a clone.
*/
void conf_free(
conf_t *conf,
bool is_clone
);
/*!
* Activates configured query modules for the specified zone or for all zones.
*
* \param[in] conf Configuration.
* \param[in] zone_name Zone name, NULL for all zones.
* \param[in] query_modules Destination query modules list.
* \param[in] query_plan Destination query plan.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_activate_modules(
conf_t *conf,
knot_dname_t *zone_name,
list_t *query_modules,
struct query_plan **query_plan
);
/*!
* Deactivates query modules list.
*
* \param[in] conf Configuration.
* \param[in] query_modules Destination query modules list.
* \param[in] query_plan Destination query plan.
*/
void conf_deactivate_modules(
conf_t *conf,
list_t *query_modules,
struct query_plan *query_plan
);
/*!
* Parses textual configuration from the string or from the file.
*
* This function is used for includes processing!
*
* \param[in] conf Configuration.
* \param[in] txn Transaction.
* \param[in] input Configuration string or filename.
* \param[in] is_file Specifies if the input is string or input filename.
* \param[in] incl_depth The current include depth counter.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_parse(
conf_t *conf,
namedb_txn_t *txn,
const char *input,
bool is_file,
size_t *incl_depth
);
/*!
* Imports textual configuration.
*
* \param[in] conf Configuration.
* \param[in] input Configuration string or input filename.
* \param[in] is_file Specifies if the input is string or filename.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_import(
conf_t *conf,
const char *input,
bool is_file
);
/*!
* Exports configuration to textual file.
*
* \param[in] conf Configuration.
* \param[in] input Output filename.
* \param[in] style Formatting style.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_export(
conf_t *conf,
const char *file_name,
yp_style_t style
);
/*! @} */
This diff is collapsed.
......@@ -16,7 +16,7 @@
/*!
* \file
*
* Server configuration and API.
* Server configuration interface.
*
* \addtogroup config
*
......@@ -25,131 +25,61 @@
#pragma once
#include <stdlib.h>
#include <sys/socket.h>
#include "knot/conf/base.h"
#include "knot/conf/scheme.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/namedb/namedb.h"
#include "libknot/rrtype/tsig.h"
#include "libknot/yparser/ypscheme.h"
#define CONF_XFERS 10
#define CONF_DEFAULT_ID ((uint8_t *)"\x08""default\0")
#define CONF_DEFAULT_FILE (CONFIG_DIR "/knot.conf")
//#define CONF_DEFAULT_DBDIR (STORAGE_DIR "/confdb")
typedef struct {
const struct namedb_api *api;
yp_item_t *scheme;
mm_ctx_t *mm;
namedb_t *db;
// Read-only transaction for config access.
namedb_txn_t read_txn;
// For automatic NSID or CH ident.
char *hostname;
// For reload if started with config file.
char *filename;
// List of active query modules.
list_t query_modules;
// Default query modules plan.
struct query_plan *query_plan;
} conf_t;
/*! Configuration remote getter output. */
typedef struct {
/*! Target socket address. */
struct sockaddr_storage addr;
/*! Local outgoing socket address. */
struct sockaddr_storage via;
/*! TSIG key. */
knot_tsig_key_t key;
} conf_remote_t;
/*! Configuration getter output. */
typedef struct {
/*! Item description. */
const yp_item_t *item;
/*! Whole data (can be array). */
const uint8_t *blob;
/*! Whole data length. */
size_t blob_len;
// Public items.
/*! Current single data. */
const uint8_t *data;
/*! Current single data length. */
size_t len;
int code; // Return code.
/*! Value getter return code. */
int code;
} conf_val_t;
/*! Configuration section iterator. */
typedef struct {
/*! Item description. */
const yp_item_t *item;
/*! Namedb iterator. */
namedb_iter_t *iter;
/*! Key0 database code. */
uint8_t key0_code;
// Public items.
int code; // Return code.
/*! Iterator return code. */
int code;
} conf_iter_t;
/*! Configuration module getter output. */
typedef struct {
/*! Module name. */
yp_name_t *name;
/*! Module id data. */
uint8_t *data;
/*! Module id data length. */
size_t len;
} conf_mod_id_t;
extern conf_t *s_conf;
static inline conf_t* conf(void) {
return s_conf;
}
int conf_new(
conf_t **conf,
const yp_item_t *scheme,
const char *db_dir
);
int conf_clone(
conf_t **conf
);
int conf_post_open(
conf_t *conf
);
void conf_update(
conf_t *conf
);
void conf_free(
conf_t *conf,
bool is_clone
);
int conf_activate_modules(
conf_t *conf,
knot_dname_t *zone_name,
list_t *query_modules,
struct query_plan **query_plan
);
void conf_deactivate_modules(
conf_t *conf,
list_t *query_modules,
struct query_plan *query_plan
);
int conf_parse(
conf_t *conf,
namedb_txn_t *txn,
const char *input,
bool is_file,
size_t *incl_depth
);
int conf_import(
conf_t *conf,
const char *input,
bool is_file
);
int conf_export(
conf_t *conf,
const char *file_name,
yp_style_t style
);
/*****************/
conf_val_t conf_get(
conf_t *conf,
const yp_name_t *key0_name,
......@@ -292,3 +222,5 @@ conf_remote_t conf_remote(
conf_t *conf,
conf_val_t *id
);
/*! @} */
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