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

Basic zone text dump

- Move text zone dump to knot.
- Separate rrset dump and leave it in libknot.
- Add auxiliary function for text dump.

refs @2138
parent 5ce9dc56
......@@ -13,6 +13,8 @@ src/libknot/dname.h
src/libknot/dname.c
src/libknot/rrset.h
src/libknot/rrset.c
src/libknot/rrset-dump.h
src/libknot/rrset-dump.c
src/libknot/edns.h
src/libknot/edns.c
src/libknot/nsec3.h
......@@ -56,8 +58,6 @@ src/libknot/zone/zone.h
src/libknot/zone/zone.c
src/libknot/zone/zone-contents.c
src/libknot/zone/zone-contents.h
src/libknot/zone/zone-dump.h
src/libknot/zone/zone-dump.c
src/libknot/zone/zone-tree.h
src/libknot/zone/zone-tree.c
src/Makefile.am
......@@ -160,6 +160,8 @@ src/knot/conf/conf.c
src/knot/conf/conf.h
src/knot/conf/logconf.c
src/knot/conf/logconf.h
src/knot/zone/zone-dump.c
src/knot/zone/zone-dump.h
src/knot/zone/zone-load.c
src/knot/zone/zone-load.h
src/tests/unittests_main.c
......
......@@ -99,8 +99,6 @@ libknot_la_SOURCES = \
libknot/zone/node.c \
libknot/zone/zone-diff.h \
libknot/zone/zone-diff.c \
libknot/zone/zone-dump.h \
libknot/zone/zone-dump.c \
libknot/hash/hash-functions.c \
libknot/hash/cuckoo-hash-table.c \
libknot/hash/universal-system.c \
......@@ -115,16 +113,18 @@ libknot_la_SOURCES = \
libknot/updates/xfr-in.c \
libknot/updates/ddns.h \
libknot/updates/ddns.c \
libknot/edns.c \
libknot/rrset.c \
libknot/dname.c \
libknot/nsec3.c \
libknot/consts.h \
libknot/dname.h \
libknot/dname.c \
libknot/edns.h \
libknot/edns.c \
libknot/libknot.h \
libknot/dname.h \
libknot/rrset.h \
libknot/nsec3.h \
libknot/nsec3.c \
libknot/rrset.h \
libknot/rrset.c \
libknot/rrset-dump.h \
libknot/rrset-dump.c \
libknot/tsig.h \
libknot/tsig.c \
libknot/tsig-op.h \
......@@ -228,6 +228,8 @@ libknotd_la_SOURCES = \
knot/server/zones.h \
knot/zone/semantic-check.c \
knot/zone/semantic-check.h \
knot/zone/zone-dump.h \
knot/zone/zone-dump.c \
knot/zone/zone-load.h \
knot/zone/zone-load.c \
knot/server/server.h
......
......@@ -21,7 +21,7 @@
#include "common/prng.h"
#include "libknot/dname.h"
#include "libknot/util/wire.h"
#include "libknot/zone/zone-dump.h"
#include "knot/zone/zone-dump.h"
#include "knot/zone/zone-load.h"
#include "libknot/zone/zone.h"
#include "libknot/zone/zonedb.h"
......
/* Copyright (C) 2011 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/>.
*/
#include "knot/zone/zone-dump.h"
#include <config.h>
#include "common/descriptor_new.h"
#include "libknot/libknot.h"
#define DUMP_BUF_LEN (70 * 1024)
typedef struct {
int ret;
FILE *file;
char *buf;
size_t buflen;
const knot_dname_t *origin;
} dump_params_t;
static void apex_node_dump_text(knot_node_t *node, dump_params_t *params)
{
knot_rrset_t *rr = knot_node_get_rrset(node, KNOT_RRTYPE_SOA);
int ret = knot_rrset_txt_dump(rr, params->buf, params->buflen);
if (ret < 0) {
params->ret = KNOT_ENOMEM;
return;
}
fprintf(params->file, "%s", params->buf);
const knot_rrset_t **rrsets = knot_node_rrsets(node);
for (int i = 0; i < node->rrset_count; i++) {
if (rrsets[i]->type != KNOT_RRTYPE_SOA) {
ret = knot_rrset_txt_dump(rrsets[i], params->buf,
params->buflen);
if (ret < 0) {
free(rrsets);
params->ret = KNOT_ENOMEM;
return;
}
fprintf(params->file, "%s", params->buf);
}
}
free(rrsets);
params->ret = KNOT_EOK;
}
void node_dump_text(knot_node_t *node, void *data)
{
dump_params_t *params = (dump_params_t *)data;
if (node->owner == params->origin) {
apex_node_dump_text(node, params);
return;
}
const knot_rrset_t **rrsets = knot_node_rrsets(node);
int ret;
for (int i = 0; i < node->rrset_count; i++) {
ret = knot_rrset_txt_dump(rrsets[i], params->buf, params->buflen);
if (ret < 0) {
params->ret = KNOT_ENOMEM;
return;
}
}
free(rrsets);
params->ret = KNOT_EOK;
}
int zone_dump_text(knot_zone_contents_t *zone, FILE *file)
{
if (zone == NULL || file == NULL) {
return KNOT_EINVAL;
}
char *buf = malloc(DUMP_BUF_LEN);
if (buf == NULL) {
return KNOT_ENOMEM;
}
fprintf(file, ";Dumped using %s v. %s\n", PACKAGE_NAME, PACKAGE_VERSION);
dump_params_t params;
params.ret = KNOT_ERROR;
params.file = file;
params.buf = buf;
params.buflen = DUMP_BUF_LEN;
params.origin = knot_node_owner(knot_zone_contents_apex(zone));
knot_zone_contents_tree_apply_inorder(zone, node_dump_text, &params);
if (params.ret != KNOT_EOK) {
return params.ret;
}
knot_zone_contents_nsec3_apply_inorder(zone, node_dump_text, &params);
if (params.ret != KNOT_EOK) {
return params.ret;
}
return KNOT_EOK;
}
......@@ -20,26 +20,26 @@
*
* \brief Zone text dump facility.
*
* \addtogroup libknot
* \addtogroup zone-load-dump
* @{
*/
#ifndef _KNOT_ZONE_DUMP_H_
#define _KNOT_ZONE_DUMP_H_
#ifndef _KNOTD_ZONEDUMP_H_
#define _KNOTD_ZONEDUMP_H_
#include "libknot/zone/zone.h"
/*!
* \brief Dumps given zone to text (BIND-like) file.
* \brief Dumps given zone to text file.
*
* \param zone Zone to be saved.
* \param File file to write to.
* \param file File to write to.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL if the specified file is not valid for writing.
* \retval < 0 if error.
*/
int zone_dump_text(knot_zone_contents_t *zone, FILE *f);
int zone_dump_text(knot_zone_contents_t *zone, FILE *file);
#endif // _KNOT_ZONE_DUMP_H_
#endif // _KNOTD_ZONEDUMP_H_
/*! @} */
......@@ -36,6 +36,7 @@
#include "util/wire.h"
#include "packet/response.h"
#include "rrset.h"
#include "rrset-dump.h"
#include "util/tolower.h"
#include "util/utils.h"
#include "zone/zone.h"
......
This diff is collapsed.
/* Copyright (C) 2011 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 rrset-dump.h
*
* \author Daniel Salzman <daniel.salzman@nic.cz>
*
* \brief RRset text dump facility.
*
* \addtogroup libknot
* @{
*/
#ifndef _KNOT_RRSETDUMP_H_
#define _KNOT_RRSETDUMP_H_
//#include <std>
#include "libknot/rrset.h"
int knot_rrset_txt_dump(const knot_rrset_t *rrset, char *dst, const size_t maxlen);
#endif // _KNOT_RRSETDUMP_H_
/*! @} */
This diff is collapsed.
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