From: Michael Tremer Date: Mon, 11 May 2026 14:44:26 +0000 (+0000) Subject: main: Add a convenience function to parse dns_name_t from string X-Git-Url: http://git.ipfire.org/index.cgi?a=commitdiff_plain;h=360ee65a478eb1316d2cb79009004821612e822c;p=zone-sync.git main: Add a convenience function to parse dns_name_t from string Signed-off-by: Michael Tremer --- diff --git a/main.c b/main.c index 157e4f6..3dcbbe6 100644 --- a/main.c +++ b/main.c @@ -81,6 +81,8 @@ static ctx_t ctx = { .path = DEFAULT_PATH, }; +static dns_fixedname_t fixed = {}; + static void logger(int priority, const char* format, ...) { char buffer[4096]; FILE* f = NULL; @@ -160,6 +162,32 @@ static void setup_logging(void) { isc_log_setcontext(ctx.log); } +static isc_result_t dns_name_from_string(dns_name_t** name, const char *text) { + isc_buffer_t buffer = {}; + dns_name_t* n = NULL; + int r; + + // Allocate some memory + n = dns_fixedname_initname(&fixed); + + // Determine the length of the input + size_t l = strlen(text); + + // Add the name to the buffer + isc_buffer_constinit(&buffer, text, l); + isc_buffer_add(&buffer, l); + + // Create a new dns_name_t object from the buffer + r = dns_name_fromtext(n, &buffer, dns_rootname, 0, NULL); + if (r) + return r; + + // Return the name + *name = n; + + return 0; +} + static void zone_done(dns_zone_t* zone) { // Release the zone from the manager dns_zonemgr_releasezone(ctx.zonemgr, zone); @@ -265,10 +293,8 @@ ERROR: } static void do_zone(const char* name) { - dns_fixedname_t fixed = {}; dns_name_t* origin = NULL; dns_zone_t* zone = NULL; - isc_buffer_t buffer; char path[PATH_MAX]; int r; @@ -276,12 +302,9 @@ static void do_zone(const char* name) { ctx.running++; // Create the origin - origin = dns_fixedname_initname(&fixed); - - isc_buffer_constinit(&buffer, name, strlen(name)); - isc_buffer_add(&buffer, strlen(name)); - - dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL); + r = dns_name_from_string(&origin, name); + if (r) + goto ERROR; DEBUG("Processing zone %s\n", name);