From 1a30093457b4f50a5c28fd8923007fc0e657ba09 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sun, 19 Sep 2021 16:20:12 +0200 Subject: zonefile --- src/zonefile.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/zonefile.c') diff --git a/src/zonefile.c b/src/zonefile.c index 3f00212..13a2a34 100644 --- a/src/zonefile.c +++ b/src/zonefile.c @@ -6,27 +6,39 @@ #include "zonefile.h" -int zonefile_parse_line(database_t *_database, char *_line) { +int zonefile_string_split(char* _parts[], ssize_t _max, char* _str, char _delim) { 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++ ); + for ( i=0; i < _max; i++ ) { + for ( o=start; _str[o] && _str[o] != ' '; o++ ); - parts[i] = &_line[start]; + _parts[i] = &_str[start]; - if(!_line[o]) + if(!_str[o]) break; - _line[o] = '\0'; + _str[o] = '\0'; start = o+1; } + return (int)i + 1; +} + +int zonefile_parse_line(database_t *_database, char *_line) { + char *parts[5]; + int parts_len; + + /* Does this work? */ + memset(&parts, 0, sizeof(parts)); + + parts_len = zonefile_string_split(parts, 4, _line, ' '); + if (parts_len != 4) { + LOGPRINTF(_LOG_ERROR, "Incomplete"); + return -1; + } + /* parts is the first 5 space-seperated parts of _line */ return -1; @@ -44,11 +56,13 @@ int zonefile_to_database (database_t *_database, char* _file) { return -1; } + DEBUG("Parsing zonefile %s", _file) + while(!feof(zfile)) { line_cnt ++; line_len = getline(&line, 0, zfile); - /* getline includes the line break. ONLY UNIX!! */ + /* getline includes the line break. ONLY UNIX ENDINGS!! */ if( line[line_len - 2] == '\n' ) line[line_len - 2] = '\0'; -- cgit v1.2.3