From 5b3a37455bf718025606001c8b0dc4c47648a41d Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Mon, 10 Jun 2013 14:30:22 +0200
Subject: [PATCH] zscanner: move error handling from common to zscanner

---
 src/Makefile.am                   |   2 +
 src/common/errcode.c              |  68 +-----------------
 src/common/errcode.h              |  69 +------------------
 src/knot/server/zones.c           |   2 +-
 src/zscanner/error.c              | 111 ++++++++++++++++++++++++++++++
 src/zscanner/error.h              | 108 +++++++++++++++++++++++++++++
 src/zscanner/file_loader.c        |   4 +-
 src/zscanner/file_loader.h        |   2 +-
 src/zscanner/scanner.c            |   8 +--
 src/zscanner/scanner.rl           |   2 +-
 src/zscanner/scanner_body.rl      |   6 +-
 src/zscanner/scanner_functions.c  |   6 +-
 src/zscanner/scanner_functions.h  |   2 +-
 src/zscanner/test/processing.c    |   6 +-
 src/zscanner/test/zscanner-tool.c |   6 +-
 15 files changed, 245 insertions(+), 157 deletions(-)
 create mode 100644 src/zscanner/error.c
 create mode 100644 src/zscanner/error.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 141856ade0..790e552cfc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -294,6 +294,8 @@ zscanner_tool_SOURCES =				\
 	zscanner/test/processing.c
 
 libzscanner_la_SOURCES =			\
+	zscanner/error.h			\
+	zscanner/error.c			\
 	zscanner/file_loader.h			\
 	zscanner/file_loader.c			\
 	zscanner/scanner.h			\
diff --git a/src/common/errcode.c b/src/common/errcode.c
index 238639b732..fcd22e336b 100644
--- a/src/common/errcode.c
+++ b/src/common/errcode.c
@@ -74,6 +74,7 @@ const error_table_t knot_error_msgs[] = {
 	{ KNOT_ENOTSIG, "expected a TSIG or SIG(0)" },
 	{ KNOT_ESTOP, "Stop." },
 	{ KNOT_ELIMIT, "Exceeded response rate limit." },
+	{ KNOT_EWRITABLE, "File is not writable." },
 
 	/* Network errors. */
 	{ KNOT_NET_EADDR, "Bad address or host name." },
@@ -83,73 +84,6 @@ const error_table_t knot_error_msgs[] = {
 	{ KNOT_NET_ERECV, "Can't receive data." },
 	{ KNOT_NET_ETIMEOUT, "Network timeout." },
 
-	/* Zone file loader errors. */
-	{ FLOADER_EFSTAT, "Fstat error." },
-	{ FLOADER_EDIRECTORY, "Zone file is a directory." },
-	{ FLOADER_EEMPTY, "Empty zone file." },
-	{ FLOADER_EDEFAULTS, "Zone defaults processing error." },
-	{ FLOADER_EMMAP, "Mmap error." },
-	{ FLOADER_EMUNMAP, "Munmap error." },
-	{ FLOADER_ESCANNER, "Zone processing error." },
-
-	/* Zone scanner errors. */
-	{ ZSCANNER_UNCOVERED_STATE, "General scanner error." },
-	{ ZSCANNER_ELEFT_PARENTHESIS, "Too many left parentheses." },
-	{ ZSCANNER_ERIGHT_PARENTHESIS, "Too many right parentheses." },
-	{ ZSCANNER_EUNSUPPORTED_TYPE, "Unsupported record type." },
-	{ ZSCANNER_EBAD_PREVIOUS_OWNER, "Previous owner is invalid." },
-	{ ZSCANNER_EBAD_DNAME_CHAR, "Bad domain name character." },
-	{ ZSCANNER_EBAD_OWNER, "Owner is invalid." },
-	{ ZSCANNER_ELABEL_OVERFLOW, "Maximal domain name label length has exceeded." },
-	{ ZSCANNER_EDNAME_OVERFLOW, "Maximal domain name length has exceeded." },
-	{ ZSCANNER_EBAD_NUMBER, "Bad number." },
-	{ ZSCANNER_ENUMBER64_OVERFLOW, "Number is too big." },
-	{ ZSCANNER_ENUMBER32_OVERFLOW, "Number is bigger than 32 bits." },
-	{ ZSCANNER_ENUMBER16_OVERFLOW, "Number is bigger than 16 bits." },
-	{ ZSCANNER_ENUMBER8_OVERFLOW, "Number is bigger than 8 bits." },
-	{ ZSCANNER_EFLOAT_OVERFLOW, "Float number overflow." },
-	{ ZSCANNER_ERDATA_OVERFLOW, "Maximal record data length has exceeded." },
-	{ ZSCANNER_EITEM_OVERFLOW, "Maximal item length has exceeded." },
-	{ ZSCANNER_EBAD_ADDRESS_CHAR, "Bad address character." },
-	{ ZSCANNER_EBAD_IPV4, "Bad IPv4 address." },
-	{ ZSCANNER_EBAD_IPV6, "Bad IPv6 address." },
-	{ ZSCANNER_EBAD_GATEWAY, "Bad gateway." },
-	{ ZSCANNER_EBAD_GATEWAY_KEY, "Bad gateway key." },
-	{ ZSCANNER_EBAD_APL, "Bad adress prefix list." },
-	{ ZSCANNER_EBAD_RDATA, "Bad record data." },
-	{ ZSCANNER_EBAD_HEX_RDATA, "Bad record data in hex format." },
-	{ ZSCANNER_EBAD_HEX_CHAR, "Bad hexadecimal character." },
-	{ ZSCANNER_EBAD_BASE64_CHAR, "Bad Base64 character." },
-	{ ZSCANNER_EBAD_BASE32HEX_CHAR, "Bad Base32hex character." },
-	{ ZSCANNER_EBAD_REST, "Unexpected data." },
-	{ ZSCANNER_EBAD_TIMESTAMP_CHAR, "Bad timestamp character." },
-	{ ZSCANNER_EBAD_TIMESTAMP_LENGTH, "Bad timestamp length." },
-	{ ZSCANNER_EBAD_TIMESTAMP, "Bad timestamp." },
-	{ ZSCANNER_EBAD_DATE, "Bad date." },
-	{ ZSCANNER_EBAD_TIME, "Bad time." },
-	{ ZSCANNER_EBAD_TIME_UNIT, "Bad time unit." },
-	{ ZSCANNER_EBAD_BITMAP, "Bad bitmap." },
-	{ ZSCANNER_ETEXT_OVERFLOW, "Text is too long." },
-	{ ZSCANNER_EBAD_TEXT_CHAR, "Bad text character." },
-	{ ZSCANNER_EBAD_TEXT, "Bad text string." },
-	{ ZSCANNER_EBAD_DIRECTIVE, "Bad directive." },
-	{ ZSCANNER_EBAD_TTL, "Bad zone TTL." },
-	{ ZSCANNER_EBAD_ORIGIN, "Bad zone origin." },
-	{ ZSCANNER_EBAD_INCLUDE_FILENAME, "Bad filename in include directive." },
-	{ ZSCANNER_EBAD_INCLUDE_ORIGIN, "Bad origin in include directive." },
-	{ ZSCANNER_EUNPROCESSED_INCLUDE, "Include file processing error." },
-	{ ZSCANNER_EUNOPENED_INCLUDE, "Include file opening error." },
-	{ ZSCANNER_EBAD_RDATA_LENGTH, "The rdata length statement is incorrect." },
-	{ ZSCANNER_ECANNOT_TEXT_DATA, "Unable to process text form for this type." },
-	{ ZSCANNER_EBAD_LOC_DATA, "Bad zone location data." },
-	{ ZSCANNER_EUNKNOWN_BLOCK, "Unknown rdata block." },
-	{ ZSCANNER_EBAD_ALGORITHM, "Bad algorithm." },
-	{ ZSCANNER_EBAD_CERT_TYPE, "Bad certificate type." },
-	{ ZSCANNER_EBAD_EUI_LENGTH, "Bad EUI length." },
-	{ ZSCANNER_EBAD_L64_LENGTH, "Bad 64-bit locator." },
-	{ ZSCANNER_EBAD_CHAR_COLON, "Missing colon character." },
-	{ ZSCANNER_EBAD_CHAR_DASH, "Missing dash character." },
-
 	/* Encoding errors. */
 	{ KNOT_BASE64_ESIZE, "Invalid base64 string length." },
 	{ KNOT_BASE64_ECHAR, "Invalid base64 character." },
diff --git a/src/common/errcode.h b/src/common/errcode.h
index b85f6cb492..5128031cae 100644
--- a/src/common/errcode.h
+++ b/src/common/errcode.h
@@ -87,6 +87,7 @@ enum knot_error {
 	KNOT_ENOTSIG,         /*!< Expected a TSIG or SIG(0). */
 	KNOT_ESTOP,           /*!< Stop doing something. */
 	KNOT_ELIMIT,          /*!< Exceeded response rate limit. */
+	KNOT_EWRITABLE,       /*!< File is not writable. */
 
 	/* Network errors. */
 	KNOT_NET_EADDR,
@@ -96,74 +97,6 @@ enum knot_error {
 	KNOT_NET_ERECV,
 	KNOT_NET_ETIMEOUT,
 
-	/* Zone file loader errors. */
-	FLOADER_EFSTAT,
-	FLOADER_EDIRECTORY,
-	FLOADER_EWRITABLE,
-	FLOADER_EEMPTY,
-	FLOADER_EDEFAULTS,
-	FLOADER_EMMAP,
-	FLOADER_EMUNMAP,
-	FLOADER_ESCANNER,
-
-	/* Zone scanner errors. */
-	ZSCANNER_UNCOVERED_STATE,
-	ZSCANNER_ELEFT_PARENTHESIS,
-	ZSCANNER_ERIGHT_PARENTHESIS,
-	ZSCANNER_EUNSUPPORTED_TYPE,
-	ZSCANNER_EBAD_PREVIOUS_OWNER,
-	ZSCANNER_EBAD_DNAME_CHAR,
-	ZSCANNER_EBAD_OWNER,
-	ZSCANNER_ELABEL_OVERFLOW,
-	ZSCANNER_EDNAME_OVERFLOW,
-	ZSCANNER_EBAD_NUMBER,
-	ZSCANNER_ENUMBER64_OVERFLOW,
-	ZSCANNER_ENUMBER32_OVERFLOW,
-	ZSCANNER_ENUMBER16_OVERFLOW,
-	ZSCANNER_ENUMBER8_OVERFLOW,
-	ZSCANNER_EFLOAT_OVERFLOW,
-	ZSCANNER_ERDATA_OVERFLOW,
-	ZSCANNER_EITEM_OVERFLOW,
-	ZSCANNER_EBAD_ADDRESS_CHAR,
-	ZSCANNER_EBAD_IPV4,
-	ZSCANNER_EBAD_IPV6,
-	ZSCANNER_EBAD_GATEWAY,
-	ZSCANNER_EBAD_GATEWAY_KEY,
-	ZSCANNER_EBAD_APL,
-	ZSCANNER_EBAD_RDATA,
-	ZSCANNER_EBAD_HEX_RDATA,
-	ZSCANNER_EBAD_HEX_CHAR,
-	ZSCANNER_EBAD_BASE64_CHAR,
-	ZSCANNER_EBAD_BASE32HEX_CHAR,
-	ZSCANNER_EBAD_REST,
-	ZSCANNER_EBAD_TIMESTAMP_CHAR,
-	ZSCANNER_EBAD_TIMESTAMP_LENGTH,
-	ZSCANNER_EBAD_TIMESTAMP,
-	ZSCANNER_EBAD_DATE,
-	ZSCANNER_EBAD_TIME,
-	ZSCANNER_EBAD_TIME_UNIT,
-	ZSCANNER_EBAD_BITMAP,
-	ZSCANNER_ETEXT_OVERFLOW,
-	ZSCANNER_EBAD_TEXT_CHAR,
-	ZSCANNER_EBAD_TEXT,
-	ZSCANNER_EBAD_DIRECTIVE,
-	ZSCANNER_EBAD_TTL,
-	ZSCANNER_EBAD_ORIGIN,
-	ZSCANNER_EBAD_INCLUDE_FILENAME,
-	ZSCANNER_EBAD_INCLUDE_ORIGIN,
-	ZSCANNER_EUNPROCESSED_INCLUDE,
-	ZSCANNER_EUNOPENED_INCLUDE,
-	ZSCANNER_EBAD_RDATA_LENGTH,
-	ZSCANNER_ECANNOT_TEXT_DATA,
-	ZSCANNER_EBAD_LOC_DATA,
-	ZSCANNER_EUNKNOWN_BLOCK,
-	ZSCANNER_EBAD_ALGORITHM,
-	ZSCANNER_EBAD_CERT_TYPE,
-	ZSCANNER_EBAD_EUI_LENGTH,
-	ZSCANNER_EBAD_L64_LENGTH,
-	ZSCANNER_EBAD_CHAR_COLON,
-	ZSCANNER_EBAD_CHAR_DASH,
-
 	/* Encoding errors. */
 	KNOT_BASE64_ESIZE,
 	KNOT_BASE64_ECHAR,
diff --git a/src/knot/server/zones.c b/src/knot/server/zones.c
index e5ecf5455c..af479b8683 100644
--- a/src/knot/server/zones.c
+++ b/src/knot/server/zones.c
@@ -2603,7 +2603,7 @@ static int zones_dump_zone_text(knot_zone_contents_t *zone, const char *fname)
 	char *new_fname = NULL;
 	int fd = zones_open_free_filename(fname, &new_fname);
 	if (fd < 0) {
-		return FLOADER_EWRITABLE;
+		return KNOT_EWRITABLE;
 	}
 
 	FILE *f = fdopen(fd, "w");
diff --git a/src/zscanner/error.c b/src/zscanner/error.c
new file mode 100644
index 0000000000..3be37c8fae
--- /dev/null
+++ b/src/zscanner/error.c
@@ -0,0 +1,111 @@
+/*  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 <config.h>
+#include "zscanner/error.h"
+#include <stdlib.h>	// NULL
+
+typedef struct {
+	int        code;
+	const char *name;
+} err_table_t;
+
+const err_table_t err_msgs[] = {
+	{ ZSCANNER_OK, "OK" },
+
+	/* Zone file loader errors. */
+	{ FLOADER_EFSTAT, "Fstat error." },
+	{ FLOADER_EDIRECTORY, "Zone file is a directory." },
+	{ FLOADER_EEMPTY, "Empty zone file." },
+	{ FLOADER_EDEFAULTS, "Zone defaults processing error." },
+	{ FLOADER_EMMAP, "Mmap error." },
+	{ FLOADER_EMUNMAP, "Munmap error." },
+	{ FLOADER_ESCANNER, "Zone processing error." },
+
+	/* Zone scanner errors. */
+	{ ZSCANNER_UNCOVERED_STATE, "General scanner error." },
+	{ ZSCANNER_ELEFT_PARENTHESIS, "Too many left parentheses." },
+	{ ZSCANNER_ERIGHT_PARENTHESIS, "Too many right parentheses." },
+	{ ZSCANNER_EUNSUPPORTED_TYPE, "Unsupported record type." },
+	{ ZSCANNER_EBAD_PREVIOUS_OWNER, "Previous owner is invalid." },
+	{ ZSCANNER_EBAD_DNAME_CHAR, "Bad domain name character." },
+	{ ZSCANNER_EBAD_OWNER, "Owner is invalid." },
+	{ ZSCANNER_ELABEL_OVERFLOW, "Maximal domain name label length has exceeded." },
+	{ ZSCANNER_EDNAME_OVERFLOW, "Maximal domain name length has exceeded." },
+	{ ZSCANNER_EBAD_NUMBER, "Bad number." },
+	{ ZSCANNER_ENUMBER64_OVERFLOW, "Number is too big." },
+	{ ZSCANNER_ENUMBER32_OVERFLOW, "Number is bigger than 32 bits." },
+	{ ZSCANNER_ENUMBER16_OVERFLOW, "Number is bigger than 16 bits." },
+	{ ZSCANNER_ENUMBER8_OVERFLOW, "Number is bigger than 8 bits." },
+	{ ZSCANNER_EFLOAT_OVERFLOW, "Float number overflow." },
+	{ ZSCANNER_ERDATA_OVERFLOW, "Maximal record data length has exceeded." },
+	{ ZSCANNER_EITEM_OVERFLOW, "Maximal item length has exceeded." },
+	{ ZSCANNER_EBAD_ADDRESS_CHAR, "Bad address character." },
+	{ ZSCANNER_EBAD_IPV4, "Bad IPv4 address." },
+	{ ZSCANNER_EBAD_IPV6, "Bad IPv6 address." },
+	{ ZSCANNER_EBAD_GATEWAY, "Bad gateway." },
+	{ ZSCANNER_EBAD_GATEWAY_KEY, "Bad gateway key." },
+	{ ZSCANNER_EBAD_APL, "Bad adress prefix list." },
+	{ ZSCANNER_EBAD_RDATA, "Bad record data." },
+	{ ZSCANNER_EBAD_HEX_RDATA, "Bad record data in hex format." },
+	{ ZSCANNER_EBAD_HEX_CHAR, "Bad hexadecimal character." },
+	{ ZSCANNER_EBAD_BASE64_CHAR, "Bad Base64 character." },
+	{ ZSCANNER_EBAD_BASE32HEX_CHAR, "Bad Base32hex character." },
+	{ ZSCANNER_EBAD_REST, "Unexpected data." },
+	{ ZSCANNER_EBAD_TIMESTAMP_CHAR, "Bad timestamp character." },
+	{ ZSCANNER_EBAD_TIMESTAMP_LENGTH, "Bad timestamp length." },
+	{ ZSCANNER_EBAD_TIMESTAMP, "Bad timestamp." },
+	{ ZSCANNER_EBAD_DATE, "Bad date." },
+	{ ZSCANNER_EBAD_TIME, "Bad time." },
+	{ ZSCANNER_EBAD_TIME_UNIT, "Bad time unit." },
+	{ ZSCANNER_EBAD_BITMAP, "Bad bitmap." },
+	{ ZSCANNER_ETEXT_OVERFLOW, "Text is too long." },
+	{ ZSCANNER_EBAD_TEXT_CHAR, "Bad text character." },
+	{ ZSCANNER_EBAD_TEXT, "Bad text string." },
+	{ ZSCANNER_EBAD_DIRECTIVE, "Bad directive." },
+	{ ZSCANNER_EBAD_TTL, "Bad zone TTL." },
+	{ ZSCANNER_EBAD_ORIGIN, "Bad zone origin." },
+	{ ZSCANNER_EBAD_INCLUDE_FILENAME, "Bad filename in include directive." },
+	{ ZSCANNER_EBAD_INCLUDE_ORIGIN, "Bad origin in include directive." },
+	{ ZSCANNER_EUNPROCESSED_INCLUDE, "Include file processing error." },
+	{ ZSCANNER_EUNOPENED_INCLUDE, "Include file opening error." },
+	{ ZSCANNER_EBAD_RDATA_LENGTH, "The rdata length statement is incorrect." },
+	{ ZSCANNER_ECANNOT_TEXT_DATA, "Unable to process text form for this type." },
+	{ ZSCANNER_EBAD_LOC_DATA, "Bad zone location data." },
+	{ ZSCANNER_EUNKNOWN_BLOCK, "Unknown rdata block." },
+	{ ZSCANNER_EBAD_ALGORITHM, "Bad algorithm." },
+	{ ZSCANNER_EBAD_CERT_TYPE, "Bad certificate type." },
+	{ ZSCANNER_EBAD_EUI_LENGTH, "Bad EUI length." },
+	{ ZSCANNER_EBAD_L64_LENGTH, "Bad 64-bit locator." },
+	{ ZSCANNER_EBAD_CHAR_COLON, "Missing colon character." },
+	{ ZSCANNER_EBAD_CHAR_DASH, "Missing dash character." },
+
+	{ 0, NULL } // Terminator
+};
+
+const char* zscanner_strerror(const int code)
+{
+	const err_table_t *err = err_msgs;
+
+	while (err->name != NULL) {
+		if (err->code == code) {
+			return err->name;
+		}
+		err++;
+	}
+
+	return NULL;
+}
diff --git a/src/zscanner/error.h b/src/zscanner/error.h
new file mode 100644
index 0000000000..c5c9f34054
--- /dev/null
+++ b/src/zscanner/error.h
@@ -0,0 +1,108 @@
+/*  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 error.h
+ *
+ * \author Daniel Salzman <daniel.salzman@nic.cz>
+ *
+ * \brief Error codes and handling.
+ * @{
+ */
+
+#ifndef _ZSCANNER__ERROR_H_
+#define _ZSCANNER__ERROR_H_
+
+enum err_codes {
+	ZSCANNER_OK = 0,
+
+	FLOADER_EFSTAT = -1000,
+	FLOADER_EDIRECTORY,
+	FLOADER_EEMPTY,
+	FLOADER_EDEFAULTS,
+	FLOADER_EMMAP,
+	FLOADER_EMUNMAP,
+	FLOADER_ESCANNER,
+
+	ZSCANNER_UNCOVERED_STATE,
+	ZSCANNER_ELEFT_PARENTHESIS,
+	ZSCANNER_ERIGHT_PARENTHESIS,
+	ZSCANNER_EUNSUPPORTED_TYPE,
+	ZSCANNER_EBAD_PREVIOUS_OWNER,
+	ZSCANNER_EBAD_DNAME_CHAR,
+	ZSCANNER_EBAD_OWNER,
+	ZSCANNER_ELABEL_OVERFLOW,
+	ZSCANNER_EDNAME_OVERFLOW,
+	ZSCANNER_EBAD_NUMBER,
+	ZSCANNER_ENUMBER64_OVERFLOW,
+	ZSCANNER_ENUMBER32_OVERFLOW,
+	ZSCANNER_ENUMBER16_OVERFLOW,
+	ZSCANNER_ENUMBER8_OVERFLOW,
+	ZSCANNER_EFLOAT_OVERFLOW,
+	ZSCANNER_ERDATA_OVERFLOW,
+	ZSCANNER_EITEM_OVERFLOW,
+	ZSCANNER_EBAD_ADDRESS_CHAR,
+	ZSCANNER_EBAD_IPV4,
+	ZSCANNER_EBAD_IPV6,
+	ZSCANNER_EBAD_GATEWAY,
+	ZSCANNER_EBAD_GATEWAY_KEY,
+	ZSCANNER_EBAD_APL,
+	ZSCANNER_EBAD_RDATA,
+	ZSCANNER_EBAD_HEX_RDATA,
+	ZSCANNER_EBAD_HEX_CHAR,
+	ZSCANNER_EBAD_BASE64_CHAR,
+	ZSCANNER_EBAD_BASE32HEX_CHAR,
+	ZSCANNER_EBAD_REST,
+	ZSCANNER_EBAD_TIMESTAMP_CHAR,
+	ZSCANNER_EBAD_TIMESTAMP_LENGTH,
+	ZSCANNER_EBAD_TIMESTAMP,
+	ZSCANNER_EBAD_DATE,
+	ZSCANNER_EBAD_TIME,
+	ZSCANNER_EBAD_TIME_UNIT,
+	ZSCANNER_EBAD_BITMAP,
+	ZSCANNER_ETEXT_OVERFLOW,
+	ZSCANNER_EBAD_TEXT_CHAR,
+	ZSCANNER_EBAD_TEXT,
+	ZSCANNER_EBAD_DIRECTIVE,
+	ZSCANNER_EBAD_TTL,
+	ZSCANNER_EBAD_ORIGIN,
+	ZSCANNER_EBAD_INCLUDE_FILENAME,
+	ZSCANNER_EBAD_INCLUDE_ORIGIN,
+	ZSCANNER_EUNPROCESSED_INCLUDE,
+	ZSCANNER_EUNOPENED_INCLUDE,
+	ZSCANNER_EBAD_RDATA_LENGTH,
+	ZSCANNER_ECANNOT_TEXT_DATA,
+	ZSCANNER_EBAD_LOC_DATA,
+	ZSCANNER_EUNKNOWN_BLOCK,
+	ZSCANNER_EBAD_ALGORITHM,
+	ZSCANNER_EBAD_CERT_TYPE,
+	ZSCANNER_EBAD_EUI_LENGTH,
+	ZSCANNER_EBAD_L64_LENGTH,
+	ZSCANNER_EBAD_CHAR_COLON,
+	ZSCANNER_EBAD_CHAR_DASH
+};
+
+/*!
+ * \brief Returns error message for the given error code.
+ *
+ * \param code Error code.
+ *
+ * \return String containing the error message.
+ */
+const char* zscanner_strerror(const int code);
+
+#endif // _ZSCANNER__ERROR_H_
+
+/*! @} */
diff --git a/src/zscanner/file_loader.c b/src/zscanner/file_loader.c
index ce44dbea38..c104a850ef 100644
--- a/src/zscanner/file_loader.c
+++ b/src/zscanner/file_loader.c
@@ -27,7 +27,7 @@
 #include <sys/stat.h>			// fstat
 #include <sys/mman.h>			// mmap
 
-#include "common/errcode.h"		// error codes
+#include "zscanner/error.h"		// error codes
 
 /*! \brief Mmap block size in bytes. */
 #define BLOCK_SIZE      30000000
@@ -251,5 +251,5 @@ int file_loader_process(file_loader_t *fl)
 		return FLOADER_ESCANNER;
 	}
 
-	return KNOT_EOK;
+	return ZSCANNER_OK;
 }
diff --git a/src/zscanner/file_loader.h b/src/zscanner/file_loader.h
index 6bca297b2a..1748552dcd 100644
--- a/src/zscanner/file_loader.h
+++ b/src/zscanner/file_loader.h
@@ -94,7 +94,7 @@ void file_loader_free(file_loader_t *file_loader);
  *
  * \param file_loader	File loader structure.
  *
- * \retval KNOT_EOK	if success.
+ * \retval ZSCANNER_OK	if success.
  * \retval error_code   if error.
  */
 int file_loader_process(file_loader_t *file_loader);
diff --git a/src/zscanner/scanner.c b/src/zscanner/scanner.c
index 4236ad4c80..71ca074e59 100644
--- a/src/zscanner/scanner.c
+++ b/src/zscanner/scanner.c
@@ -30,7 +30,7 @@
 #include <netinet/in.h>			// in_addr (BSD)
 #include <arpa/inet.h>			// inet_pton
 
-#include "common/errcode.h"		// error codes
+#include "zscanner/error.h"		// error codes
 #include "common/descriptor.h"		// KNOT_RRTYPE_A
 #include "zscanner/file_loader.h"	// file_loader
 #include "zscanner/scanner_functions.h"	// Base64
@@ -5297,7 +5297,7 @@ _match:
 		s->process_error(s);
 
 		// Reset.
-		s->error_code = KNOT_EOK;
+		s->error_code = ZSCANNER_OK;
 		s->multiline = false;
 
 		// In case of serious error, stop scanner.
@@ -5712,7 +5712,7 @@ _match:
 		if (s->buffer_length == 14) { // Date; 14 = len("YYYYMMDDHHmmSS").
 			ret = date_to_timestamp(s->buffer, &timestamp);
 
-			if (ret == KNOT_EOK) {
+			if (ret == ZSCANNER_OK) {
 				*((uint32_t *)rdata_tail) = htonl(timestamp);
 				rdata_tail += 4;
 			} else {
@@ -6204,7 +6204,7 @@ _match:
 		}
 
 		ret = find_rdata_blocks(s);
-		if (ret != KNOT_EOK) {
+		if (ret != ZSCANNER_OK) {
 			SCANNER_WARNING(ret);
 			p--; {cs = 247; goto _again;}
 		}
diff --git a/src/zscanner/scanner.rl b/src/zscanner/scanner.rl
index 833e043973..4373ec10c8 100644
--- a/src/zscanner/scanner.rl
+++ b/src/zscanner/scanner.rl
@@ -28,7 +28,7 @@
 #include <netinet/in.h>			// in_addr (BSD)
 #include <arpa/inet.h>			// inet_pton
 
-#include "common/errcode.h"		// error codes
+#include "zscanner/error.h"		// error codes
 #include "common/descriptor.h"		// KNOT_RRTYPE_A
 #include "zscanner/file_loader.h"	// file_loader
 #include "zscanner/scanner_functions.h"	// Base64
diff --git a/src/zscanner/scanner_body.rl b/src/zscanner/scanner_body.rl
index ea76c5487e..db4c8f6aa5 100644
--- a/src/zscanner/scanner_body.rl
+++ b/src/zscanner/scanner_body.rl
@@ -86,7 +86,7 @@
 		s->process_error(s);
 
 		// Reset.
-		s->error_code = KNOT_EOK;
+		s->error_code = ZSCANNER_OK;
 		s->multiline = false;
 
 		// In case of serious error, stop scanner.
@@ -459,7 +459,7 @@
 		if (s->buffer_length == 14) { // Date; 14 = len("YYYYMMDDHHmmSS").
 			ret = date_to_timestamp(s->buffer, &timestamp);
 
-			if (ret == KNOT_EOK) {
+			if (ret == ZSCANNER_OK) {
 				*((uint32_t *)rdata_tail) = htonl(timestamp);
 				rdata_tail += 4;
 			} else {
@@ -923,7 +923,7 @@
 		}
 
 		ret = find_rdata_blocks(s);
-		if (ret != KNOT_EOK) {
+		if (ret != ZSCANNER_OK) {
 			SCANNER_WARNING(ret);
 			fhold; fgoto err_line;
 		}
diff --git a/src/zscanner/scanner_functions.c b/src/zscanner/scanner_functions.c
index 94a42dac36..f44d45d5de 100644
--- a/src/zscanner/scanner_functions.c
+++ b/src/zscanner/scanner_functions.c
@@ -20,7 +20,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 
-#include "common/errcode.h"
+#include "zscanner/error.h"
 #include "common/descriptor.h"
 #include "zscanner/scanner.h"
 
@@ -770,7 +770,7 @@ int date_to_timestamp(uint8_t *buff, uint32_t *timestamp)
 		     days_across_months[month] +
 		     day - 1 + leap_day) * 86400;
 
-	return KNOT_EOK;
+	return ZSCANNER_OK;
 }
 
 void wire_dname_to_str(const uint8_t  *data,
@@ -980,6 +980,6 @@ int find_rdata_blocks(scanner_t *s)
 		return ZSCANNER_EBAD_HEX_RDATA;
 	}
 	else {
-		return KNOT_EOK;
+		return ZSCANNER_OK;
 	}
 }
diff --git a/src/zscanner/scanner_functions.h b/src/zscanner/scanner_functions.h
index 5d219d7143..f20219f38e 100644
--- a/src/zscanner/scanner_functions.h
+++ b/src/zscanner/scanner_functions.h
@@ -117,7 +117,7 @@ uint8_t loc64to8(uint64_t number);
  *
  * \param s		Zone scanner.
  *
- * \retval KNOT_EOK	if success.
+ * \retval ZSCANNER_OK	if success.
  * \retval error_code	if error.
  */
 int find_rdata_blocks(scanner_t *s);
diff --git a/src/zscanner/test/processing.c b/src/zscanner/test/processing.c
index b9319d599a..d0de11b0ba 100644
--- a/src/zscanner/test/processing.c
+++ b/src/zscanner/test/processing.c
@@ -20,7 +20,7 @@
 #include <inttypes.h>			// PRIu64
 #include <stdio.h>			// printf
 
-#include "common/errcode.h"		// knot_strerror
+#include "zscanner/error.h"		// knot_strerror
 #include "common/descriptor.h"		// knot_rrtype_to_string
 #include "zscanner/scanner.h"		// scanner_t
 
@@ -112,13 +112,13 @@ void debug_process_error(const scanner_t *s)
 	if (s->stop == true) {
 		printf("LINE(%03"PRIu64") ERROR(%s) FILE(%s) NEAR(%s)\n",
 		       s->line_counter,
-		       knot_strerror(s->error_code),
+		       zscanner_strerror(s->error_code),
 		       s->file_name,
 		       s->buffer);
 	} else {
 		printf("LINE(%03"PRIu64") WARNING(%s) FILE(%s) NEAR(%s)\n",
 		       s->line_counter,
-		       knot_strerror(s->error_code),
+		       zscanner_strerror(s->error_code),
 		       s->file_name,
 		       s->buffer);
 	}
diff --git a/src/zscanner/test/zscanner-tool.c b/src/zscanner/test/zscanner-tool.c
index c6a728d06d..fcb2c3ec41 100644
--- a/src/zscanner/test/zscanner-tool.c
+++ b/src/zscanner/test/zscanner-tool.c
@@ -20,7 +20,7 @@
 #include <stdlib.h>			// atoi
 #include <getopt.h>			// getopt
 
-#include "common/errcode.h"		// knot_strerror
+#include "zscanner/error.h"		// knot_strerror
 #include "zscanner/file_loader.h"	// file_loader
 #include "zscanner/test/processing.h"	// processing functions
 #include "zscanner/test/tests.h"	// test functions
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
 			ret = file_loader_process(fl);
 
 			switch (ret) {
-			case KNOT_EOK:
+			case ZSCANNER_OK:
 				if (mode == DEFAULT_MODE) {
 					printf("Zone file has been processed "
 					       "successfully\n");
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
 
 			default:
 				if (mode == DEFAULT_MODE) {
-					printf("%s\n", knot_strerror(ret));
+					printf("%s\n", zscanner_strerror(ret));
 				}
 				file_loader_free(fl);
 				return EXIT_FAILURE;
-- 
GitLab