Skip to content
Snippets Groups Projects
Commit 3b95ade6 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Implemented logging for zone data.

parent 012e3147
No related branches found
No related tags found
No related merge requests found
......@@ -51,4 +51,20 @@ int print_msg(int level, const char* msg, ...) __attribute__((format (printf, 2,
#define debug_sm_hex(data, len)
#endif
#ifdef ZDB_DEBUG
#define debug_zdb(msg...) log_msg(LOG_DEBUG, msg)
#define debug_zdb_hex(data, len) hex_print((data), (len))
#else
#define debug_zdb(msg...)
#define debug_zdb_hex(data, len)
#endif
#ifdef ZP_DEBUG
#define debug_zp(msg...) log_msg(LOG_DEBUG, msg)
#define debug_zp_hex(data, len) hex_print((data), (len))
#else
#define debug_zp(msg...)
#define debug_zp_hex(data, len)
#endif
#endif // __print_h__
......@@ -5,8 +5,6 @@
#include <assert.h>
#include <stdio.h>
//#define ZDS_DEBUG
/*----------------------------------------------------------------------------*/
zds_zone *zds_create( uint item_count )
......@@ -37,9 +35,7 @@ zn_node *zds_find( zds_zone *zone, dnss_dname_wire owner )
return NULL;
}
#ifdef ZDS_DEBUG
printf("Item found\n");
#endif
debug_zdb("Item found\n");
return item->value;
}
......@@ -48,7 +44,7 @@ zn_node *zds_find( zds_zone *zone, dnss_dname_wire owner )
int zds_remove( zds_zone *zone, dnss_dname_wire owner )
{
printf("zds_remove(): Not implemented.\n");
log_error("%s fixme: Not implemented.\n", __func__);
return -1;
}
......
......@@ -4,8 +4,6 @@
#include <stdio.h>
#include <assert.h>
//#define ZDB_DEBUG
/*----------------------------------------------------------------------------*/
zdb_database *zdb_create()
......@@ -13,7 +11,7 @@ zdb_database *zdb_create()
zdb_database *db = malloc(sizeof(zdb_database));
if (db == NULL) {
fprintf(stderr, "zdb_create(): Allocation failed.\n");
ERR_ALLOC_FAILED;
return NULL;
}
......@@ -29,14 +27,14 @@ int zdb_create_zone( zdb_database *database, dnss_dname_wire zone_name,
zdb_zone *zone = malloc(sizeof(zdb_zone));
if (zone == NULL) {
fprintf(stderr, "zdb_create_zone(): Allocation failed.\n");
ERR_ALLOC_FAILED;
return -1;
}
zone->zone_name = dnss_dname_wire_copy(zone_name);
if (zone->zone_name == NULL) {
fprintf(stderr, "zdb_create_zone(): Allocation failed.\n");
ERR_ALLOC_FAILED;
free(zone);
return -1;
}
......@@ -44,7 +42,7 @@ int zdb_create_zone( zdb_database *database, dnss_dname_wire zone_name,
zone->zone = zds_create(items);
if (zone->zone == NULL) {
fprintf(stderr, "zdb_create_zone(): Allocation failed.\n");
ERR_ALLOC_FAILED;
free(zone->zone_name);
free(zone);
return -1;
......@@ -80,9 +78,7 @@ int zdb_remove_zone( zdb_database *database, dnss_dname_wire zone_name )
zdb_find_zone(database, zone_name, &z, &zp);
if (z == NULL) {
#ifdef ZDB_DEBUG
printf("Zone not found!\n");
#endif
debug_zdb("Zone not found!\n");
return -1;
}
......@@ -112,15 +108,12 @@ int zdb_insert_name( zdb_database *database, dnss_dname_wire zone_name,
zdb_find_zone(database, zone_name, &z, &zp);
if (z == NULL) {
#ifdef ZDB_DEBUG
printf("Zone not found!\n");
#endif
debug_zdb("Zone not found!\n");
return -1;
}
#ifdef ZDB_DEBUG
printf("Found zone: ");
hex_print(z->zone_name, strlen(z->zone_name) + 1);
#endif
debug_zdb("Found zone: ");
debug_zdb_hex(z->zone_name, strlen(z->zone_name) + 1);
return zds_insert(z->zone, dname, node);
}
......@@ -152,15 +145,12 @@ const zn_node *zdb_find_name( zdb_database *database, dnss_dname_wire dname )
zdb_zone *z = zdb_find_zone_for_name(database, dname);
if (z == NULL) {
#ifdef ZDB_DEBUG
printf("Zone not found!\n");
#endif
debug_zdb("Zone not found!\n");
return NULL;
}
#ifdef ZDB_DEBUG
printf("Found zone: ");
hex_print(z->zone_name, strlen(z->zone_name) + 1);
#endif
debug_zdb("Found zone: ");
debug_zdb_hex(z->zone_name, strlen(z->zone_name) + 1);
return zds_find(z->zone, dname);
}
......
......@@ -6,9 +6,6 @@
/*----------------------------------------------------------------------------*/
//#define ZP_DEBUG
//#define ZP_PARSE_DEBUG
#if defined(ZP_DEBUG) || defined(ZP_PARSE_DEBUG)
#include "cuckoo-test.h"
#endif
......@@ -21,8 +18,8 @@ static const int ERR_ALLOC = -4;
static const int ERR_COUNT = -5;
static const int ERR_ZONE_CREATE = -6;
#define ERR_ZONE_CREATE_FAILED fprintf(stderr, "Zone could not be created.\n")
#define ERR_PARSING_FAILED fprintf(stderr, "Zone parsing failed.\n")
#define ERR_ZONE_CREATE_FAILED log_error("Zone could not be created.\n")
#define ERR_PARSING_FAILED log_error("Zone parsing failed.\n")
/*----------------------------------------------------------------------------*/
......@@ -51,7 +48,7 @@ int zp_resize_buffer( char **buffer, uint *buf_size, int new_size,
new_buf = realloc((void *)(*buffer), (new_size * item_size));
// if error
if (new_buf == NULL) {
fprintf(stderr, "Allocation failed.\n");
ERR_ALLOC_FAILED;
return -1;
}
*buffer = new_buf;
......@@ -64,22 +61,16 @@ int zp_resize_buffer( char **buffer, uint *buf_size, int new_size,
int zp_test_count_domain_names( FILE *file, uint *names )
{
#ifdef ZP_DEBUG
printf("Counting lines..");
#endif
debug_zp("Counting lines..");
*names = zp_get_line_count(file);
#ifdef ZP_DEBUG
printf("%u\n", *names);
#endif
debug_zp("%u\n", *names);
if (*names == -1) {
fprintf(stderr, "Error reading domain names from file.\n");
log_error("Error reading domain names from file.\n");
return -1;
}
#ifdef ZP_DEBUG
printf("Domains read: %d.\n", *names);
#endif
debug_zp("Domains read: %d.\n", *names);
return 0;
}
......@@ -228,18 +219,15 @@ int zp_test_parse_zone( const char *filename, zdb_database *database )
char *DEFAULT_ZONE_NAME = "cz";
// open the zone file
#ifdef ZP_DEBUG
printf("Opening file...\n");
#endif
debug_zp("Opening file...\n");
FILE *file = fopen(filename, "r");
if (file == NULL) {
fprintf(stderr, "Can't open file: %s.\n", filename);
return ERR_FILE_OPEN;
}
#ifdef ZP_DEBUG
printf("Done.\n");
#endif
debug_zp("Done.\n");
// determine name of the zone (and later other things)
// for now lets assume there is only one zone and use the default name (cz)
......@@ -255,9 +243,7 @@ int zp_test_parse_zone( const char *filename, zdb_database *database )
int res = dnss_dname_to_wire(DEFAULT_ZONE_NAME, zone_name, name_size);
assert(res == 0);
#ifdef ZP_DEBUG
printf("Counting domain names in the file...\n");
#endif
debug_zp("Counting domain names in the file...\n");
uint names;
// count distinct domain names in the zone file
if ((res = zp_test_count_domain_names(file, &names)) != 0) {
......@@ -265,13 +251,10 @@ int zp_test_parse_zone( const char *filename, zdb_database *database )
free(zone_name);
return ERR_COUNT;
}
#ifdef ZP_DEBUG
printf("Done.\n");
#endif
#ifdef ZP_DEBUG
printf("Creating new zone with name '%s'...\n", zone_name);
#endif
debug_zp("Done.\n");
debug_zp("Creating new zone with name '%s'...\n", zone_name);
// create a new zone in the zone database
if ((res = zdb_create_zone(database, zone_name, names)) != 0) {
fclose(file);
......@@ -279,15 +262,11 @@ int zp_test_parse_zone( const char *filename, zdb_database *database )
ERR_ZONE_CREATE_FAILED;
return ERR_ZONE_CREATE;
}
#ifdef ZP_DEBUG
printf("Done.\n");
#endif
debug_zp("Done.\n");
fseek(file, 0, SEEK_SET);
debug_zp("Parsing the zone file...\n");
#ifdef ZP_DEBUG
printf("Parsing the zone file...\n");
#endif
// parse the zone file and fill in the zone
if ((res = zp_test_parse_file(database, &zone_name, file)) != 0) {
// is this necessary?
......@@ -297,14 +276,12 @@ int zp_test_parse_zone( const char *filename, zdb_database *database )
ERR_PARSING_FAILED;
return ERR_PARSE;
}
#ifdef ZP_DEBUG
printf("Done.\n");
#endif
debug_zp("Done.\n");
free(zone_name);
#ifdef ZP_DEBUG
printf("\nTesting lookup..\n");
debug_zp("\nTesting lookup..\n");
test_lookup_from_file(database->head->zone, file);
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment