aboutsummaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-05-01 15:12:09 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-05-01 15:12:09 +0200
commit009dc3ba991290de19f0a5e4e4a25a33e82689cc (patch)
tree8207ae9b3d72525029088d2cef31460f9daa24f0 /src/database.c
parentbd8e73aad283611c096f07e0fc16aa4985f9f2eb (diff)
downloaddns-009dc3ba991290de19f0a5e4e4a25a33e82689cc.tar.gz
improved logging
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/database.c b/src/database.c
index a684cff..ddb3519 100644
--- a/src/database.c
+++ b/src/database.c
@@ -26,8 +26,10 @@ int database_populate (
struct database* _database,
char* _zonefile
) {
- if ( database_init( _database ) )
+ if ( database_init( _database ) ) {
+ LOGPRINTF(_LOG_ERROR, "Failed to initialize database.");
return 1;
+ }
// TODO parsing
@@ -46,6 +48,8 @@ int database_populate (
tree_insert( &_database->zone[0][0], qname, data );
+ LOGPRINTF(_LOG_NOTE, "Database initialized and populated");
+
return 0;
}
@@ -80,11 +84,15 @@ int database_query (
// _qtype and _qclass start at 1, so they are invalid when 0.
- if ( !_rdata || !_database || !_qname || !_qtype || !_qclass || _qname_len <= 0 )
+ if ( !_rdata || !_database || !_qname || !_qtype || !_qclass || _qname_len <= 0 ) {
+ LOGPRINTF(_LOG_ERROR, "Invalid arguments");
return 1;
+ }
- if ( _qtype >= DB_RR_LEN || _qclass >= DB_RR_LEN )
+ if ( _qtype >= DB_RR_LEN || _qclass >= DB_RR_LEN ) {
+ LOGPRINTF(_LOG_DEBUG, "Invalid qtype/qclass");
return 1;
+ }
_rdata->ttl = 0;
_rdata->rdlen = 0;
@@ -95,8 +103,10 @@ int database_query (
void* data = tree_get( &_database->zone[class][type], _qname );
- if ( !data )
+ if ( !data ) {
+ LOGPRINTF(_LOG_DEBUG, "No matching RR found");
return 2;
+ }
_rdata->ttl = *( (uint32_t*) data );
_rdata->rdlen = *( (uint16_t*)(data + 4) );