aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-05-07 19:53:51 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-05-07 19:53:51 +0200
commitc0e1c65491f9d6726b16f107c25f2e5787e7e2ec (patch)
treef5bb3e414d47c49e4c555e5fc221c83ab00fcbf3
parentdb227f3f975bb4be122711658efc8b03909851eb (diff)
download0tdns-c0e1c65491f9d6726b16f107c25f2e5787e7e2ec.tar.gz
0tdns-c0e1c65491f9d6726b16f107c25f2e5787e7e2ec.zip
add mock of our logging facility
-rw-r--r--Makefile2
-rw-r--r--include/log.h17
-rw-r--r--src/0tDNS.c12
3 files changed, 29 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 6bfef8f..11152b9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CC ?= gcc
-CFLAGS = -std=c99 -Wall -Werror
+CFLAGS = -std=c99 -Wall -Werror -I include
0tDNS : build/0tDNS.o
$(CC) $^ -lunbound -o $@
diff --git a/include/log.h b/include/log.h
new file mode 100644
index 0000000..91d968f
--- /dev/null
+++ b/include/log.h
@@ -0,0 +1,17 @@
+#ifndef ZTDNS_LOG_H
+#define ZTDNS_LOG_H
+
+#include <stdio.h>
+
+#define ERROR 1
+#define WARN 2
+#define INFO 3
+#define DEBUG 4
+
+/* This function will change later - it's just a "mock", so that every1 can
+ * already write code with ztdns_log() :)
+ * Use like ztdns_log(DEBUG, "something wrong happened! %s", errorstring);
+ */
+#define ztdns_log(level, printfargs...) printf(printfargs)
+
+#endif /* ZTDNS_LOG_H */
diff --git a/src/0tDNS.c b/src/0tDNS.c
index b4bbf42..fbd3a78 100644
--- a/src/0tDNS.c
+++ b/src/0tDNS.c
@@ -26,6 +26,11 @@
#include <stdbool.h>
#include <unbound.h>
+#include "log.h"
+
+/* To specify when creating unbound context - has nothing to do with
+ * out logging facility
+ */
#define DEFAULT_DEBUGLEVEL 0
/*
@@ -234,8 +239,13 @@ struct ztdns_instance *ztdns_create_instance(int argc, char **argv)
struct ztdns_resolver *tmp;
ztdns = malloc(sizeof(struct ztdns_instance));
- if (!ztdns)
+ if (!ztdns) {
+ /* This is an example of how rest of the code shold be
+ * written/rewritten to use our logging facility.
+ */
+ ztdns_log(ERROR, "No memory, no fun :(\n");
return NULL;
+ }
/* Create context for performing full resolution */
ztdns->ctx_full =