Commit 6e8438bf authored by Jan Kadlec's avatar Jan Kadlec

Initial crc implementation. Some tests. Not usable yet.

Refs #707
parent ad86bc92
......@@ -32,6 +32,8 @@ src/common/evqueue.c
src/common/evqueue.h
src/common/errors.h
src/common/errors.c
src/common/crc.c
src/common/crc.h
src/dnslib/dnslib-common.h
src/dnslib/dname.h
src/dnslib/dname.c
......
......@@ -34,15 +34,15 @@ CLEANFILES = \
knotc_SOURCES = \
knot/ctl/knotc_main.c
knot_zcompile_SOURCES = \
zcompile/zcompile_main.c \
knot_zcompile_SOURCES = \
zcompile/zcompile_main.c \
zcompile/zcompile-error.c \
zcompile/parser-util.h \
zcompile/parser-util.h \
zcompile/parser-descriptor.h \
zcompile/zparser.y \
zcompile/zlexer.l \
zcompile/zcompile.c \
zcompile/parser-util.c \
zcompile/parser-util.c \
zcompile/parser-descriptor.c
unittests_SOURCES = \
......@@ -66,14 +66,14 @@ unittests_dnslib_SOURCES = \
dnslib/tests/dnslib/zonedb_tests.c \
dnslib/tests/unittests_dnslib.c
unittests_zcompile_SOURCES = \
zcompile/parser-util.h \
unittests_zcompile_SOURCES = \
zcompile/parser-util.h \
zcompile/parser-descriptor.h \
zcompile/zcompile-error.c \
zcompile/zparser.y \
zcompile/zlexer.l \
zcompile/zcompile.c \
zcompile/parser-util.c \
zcompile/parser-util.c \
zcompile/parser-descriptor.c \
zcompile/tests/unittests_zp_main.c
......@@ -89,35 +89,37 @@ knotd_SOURCES = \
noinst_LTLIBRARIES = libknot.la
libknot_la_SOURCES = \
common/slab/slab.c \
common/slab/malloc.c \
common/slab/slab.h \
common/slab/malloc.h \
common/slab/slab.c \
common/slab/malloc.c \
common/slab/slab.h \
common/slab/malloc.h \
common/libtap/tap.c \
common/libtap/tap.h \
common/tap_unit.h \
common/lists.c \
common/lists.c \
common/base32.c \
common/lists.h \
common/lists.h \
common/base32.h \
common/print.c \
common/print.h \
common/dynamic-array.c \
common/skip-list.c \
common/base32hex.c \
common/skip-list.h \
common/skip-list.c \
common/base32hex.c \
common/skip-list.h \
common/dynamic-array.h \
common/tree.h \
common/base32hex.h \
common/evqueue.h \
common/evqueue.c \
common/errors.h \
common/errors.c \
knot/stat/gatherer.c \
knot/stat/stat.c \
knot/stat/gatherer.h \
knot/stat/stat.h \
dnslib/edns.c \
common/base32hex.h \
common/evqueue.h \
common/evqueue.c \
common/errors.h \
common/errors.c \
common/crc.h \
common/crc.c \
knot/stat/gatherer.c \
knot/stat/stat.c \
knot/stat/gatherer.h \
knot/stat/stat.h \
dnslib/edns.c \
dnslib/utils.c \
dnslib/rrset.c \
dnslib/dname.c \
......@@ -133,12 +135,12 @@ libknot_la_SOURCES = \
dnslib/descriptor.c \
dnslib/nsec3.c \
dnslib/dname-table.c \
dnslib/hash/hash-functions.c \
dnslib/hash/hash-functions.c \
dnslib/hash/cuckoo-hash-table.c \
dnslib/hash/universal-system.c \
dnslib/hash/universal-system.h \
dnslib/hash/universal-system.c \
dnslib/hash/universal-system.h \
dnslib/hash/cuckoo-hash-table.h \
dnslib/hash/hash-functions.h \
dnslib/hash/hash-functions.h \
dnslib/zonedb.h \
dnslib/consts.h \
dnslib/node.h \
......@@ -160,32 +162,32 @@ libknot_la_SOURCES = \
dnslib/nsec3.h \
dnslib/dname-table.h \
knot/common.h \
knot/other/log.c \
knot/other/log.h \
knot/other/log.c \
knot/other/log.h \
knot/other/debug.h \
knot/other/error.h \
knot/other/error.c \
knot/conf/cf-parse.y \
knot/conf/cf-lex.l \
knot/conf/conf.c \
knot/conf/logconf.c \
knot/conf/logconf.h \
knot/conf/conf.h \
knot/ctl/process.c \
knot/ctl/process.h \
knot/conf/cf-parse.y \
knot/conf/cf-lex.l \
knot/conf/conf.c \
knot/conf/logconf.c \
knot/conf/logconf.h \
knot/conf/conf.h \
knot/ctl/process.c \
knot/ctl/process.h \
knot/server/dthreads.c \
knot/server/socket.c \
knot/server/name-server.c \
knot/server/server.c \
knot/server/udp-handler.c \
knot/server/tcp-handler.c \
knot/server/zones.c \
knot/server/socket.h \
knot/server/name-server.h \
knot/server/udp-handler.h \
knot/server/tcp-handler.h \
knot/server/socket.c \
knot/server/name-server.c \
knot/server/server.c \
knot/server/udp-handler.c \
knot/server/tcp-handler.c \
knot/server/zones.c \
knot/server/socket.h \
knot/server/name-server.h \
knot/server/udp-handler.h \
knot/server/tcp-handler.h \
knot/server/dthreads.h \
knot/server/zones.h \
knot/server/zones.h \
knot/server/server.h
libknot_la_LIBADD = @LIBOBJS@
......
This diff is collapsed.
......@@ -8,6 +8,7 @@
#include <sys/stat.h>
#include <time.h>
#include "common/crc.h"
#include "dnslib/dnslib-common.h"
#include "dnslib/zone-load.h"
#include "dnslib/zone-dump.h"
......@@ -48,6 +49,8 @@ static int timespec_cmp(struct timespec *x, struct timespec *y)
return -1;
}
static crc_t dnslib_load_crc;
/*!
* \brief Safe wrapper around fread.
*
......@@ -67,6 +70,12 @@ static inline int fread_safe(void *dst, size_t size, size_t n, FILE *fp)
n);
}
/* if (size * n > 0) {
dnslib_load_crc =
crc_update(dnslib_load_crc, (unsigned char *)dst,
size * n);
} */
return rc == n;
}
......@@ -530,6 +539,7 @@ zloader_t *dnslib_zload_open(const char *filename)
return NULL;
}
/* Open file for binary read. */
FILE *f = fopen(filename, "rb");
if (unlikely(!f)) {
......@@ -539,6 +549,20 @@ zloader_t *dnslib_zload_open(const char *filename)
return NULL;
}
/* Initialize CRC value. */
dnslib_load_crc = crc_init();
fseek(f, 0L, SEEK_END);
size_t file_size = ftell(f);
fseek(f, 0L, SEEK_SET);
printf("size is: %d\n", file_size);
/* just a test */
unsigned char *tmp = malloc(sizeof(unsigned char) * file_size);
fread(tmp, sizeof(unsigned char), file_size, f);
dnslib_load_crc = crc_update(dnslib_load_crc, tmp, file_size);
getchar();
fseek(f, 0L, SEEK_SET);
/* Check magic sequence. */
static const uint8_t MAGIC[MAGIC_LENGTH] = MAGIC_BYTES;
if (!dnslib_check_magic(f, MAGIC, MAGIC_LENGTH)) {
......@@ -553,7 +577,7 @@ zloader_t *dnslib_zload_open(const char *filename)
/* Read source file length. */
uint32_t sflen = 0;
if (fread(&sflen, 1, sizeof(uint32_t), f) != sizeof(uint32_t)) {
if (!fread_safe(&sflen, 1, sizeof(uint32_t), f)) {
debug_dnslib_zload("dnslib_zload_open: failed to read "
"sfile length\n");
fclose(f);
......@@ -570,7 +594,7 @@ zloader_t *dnslib_zload_open(const char *filename)
errno = ENOMEM; // Not enough space.
return NULL;
}
if (fread(sfile, 1, sflen, f) < sflen) {
if (!fread_safe(sfile, 1, sflen, f)) {
debug_dnslib_zload("dnslib_zload_open: failed to read %uB "
"source file\n",
sflen);
......@@ -926,6 +950,9 @@ dnslib_zone_t *dnslib_zload_load(zloader_t *loader)
/* ID array is now useless */
free(id_array);
dnslib_load_crc = crc_finalize(dnslib_load_crc);
printf("0x%lx\n", (unsigned long)dnslib_load_crc);
return zone;
}
......
......@@ -1897,6 +1897,8 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
/* This is *almost* unnecessary */
dnslib_zone_deep_free(&(parser->current_zone), 0);
dnslib_zone_t *some_zone= dnslib_zload_load(dnslib_zload_open(outfile));
/* dnslib_zone_t *new_zone = dnslib_zload_load(dnslib_zload_open(outfile));
dnslib_zdump_binary(new_zone, "testttt", 0, zonefile);
dnslib_zone_deep_free(&new_zone, 0);
......
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