aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-18 23:21:46 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-18 23:21:46 +0200
commit108e294d6b132f1cc276ef45178c0cd9f48599d2 (patch)
tree8e0fa811ed16e2cb03b82796657c4e4b7c56ceb1
parent0b6026ae2a96c4757688af51d927261536cc2873 (diff)
downloaddns-108e294d6b132f1cc276ef45178c0cd9f48599d2.tar.gz
zonefile: first steps
-rw-r--r--src/zonefile.c57
-rw-r--r--src/zonefile.h15
2 files changed, 70 insertions, 2 deletions
diff --git a/src/zonefile.c b/src/zonefile.c
index 1dd3d2d..3f00212 100644
--- a/src/zonefile.c
+++ b/src/zonefile.c
@@ -6,7 +6,62 @@
#include "zonefile.h"
-int zonefile_parse_to_list (void** _list, char* _file) {
+int zonefile_parse_line(database_t *_database, char *_line) {
+ unsigned int i, o, start;
+ char *parts[5];
+
+ /* Does this work? */
+ memset(&parts, 0, sizeof(parts));
+
+ start = 0;
+ for ( i=0; i < 4; i++ ) {
+ for ( o=start; _line[o] && _line[o] != ' '; o++ );
+
+ parts[i] = &_line[start];
+
+ if(!_line[o])
+ break;
+
+ _line[o] = '\0';
+
+ start = o+1;
+ }
+
+ /* parts is the first 5 space-seperated parts of _line */
+
+ return -1;
+}
+
+int zonefile_to_database (database_t *_database, char* _file) {
+ FILE *zfile = NULL;
+ char *line = NULL;
+ ssize_t line_len = 0;
+ unsigned int line_cnt = 0;
+
+ zfile = fopen(_file, "r");
+ if (!zfile) {
+ LOGPRINTF(_LOG_ERRNO, "Could not open %s", _file);
+ return -1;
+ }
+
+ while(!feof(zfile)) {
+ line_cnt ++;
+ line_len = getline(&line, 0, zfile);
+
+ /* getline includes the line break. ONLY UNIX!! */
+ if( line[line_len - 2] == '\n' )
+ line[line_len - 2] = '\0';
+
+ if ( zonefile_parse_line(_database, line) < 0) {
+ LOGPRINTF(_LOG_ERROR, "Error is in line %u", line_cnt)
+ return -1;
+ }
+
+ free(line);
+ line = NULL;
+ }
+
+ fclose(zfile);
return -1;
}
diff --git a/src/zonefile.h b/src/zonefile.h
index 8c2dac3..98f1fa3 100644
--- a/src/zonefile.h
+++ b/src/zonefile.h
@@ -7,5 +7,18 @@
#pragma once
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "database.h"
+#include "log.h"
+
+/**
+ * NOT COMPATIBLE WITH STANDARD ZONEFILES!
+ * use FIXED format
+ * <name> <ttl> <class> <type> <value>
+ */
+int zonefile_to_database (database_t *_database, char* _file);
+
+int zonefile_parse_line(database_t *_database, char *_line);
-int zonefile_parse_to_list (void** _list, char* _file);