]> git.ipfire.org Git - zone-sync.git/commitdiff
main: Store and process all zones
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 09:23:53 +0000 (09:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 09:27:34 +0000 (09:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
main.c

diff --git a/main.c b/main.c
index 4dbaf42dfee3721a22ea0f44779a579de8de3280..0a4e274e99cf8e333356676afcf536f2892231d9 100644 (file)
--- a/main.c
+++ b/main.c
 typedef struct ctx {
        int log_level;
 
+       // Zones
+       const char** zones;
+       unsigned int num_zones;
+
        // Memory Context
        isc_mem_t* memctx;
 
@@ -80,10 +84,21 @@ static void logger(ctx_t* ctx, int priority, const char* format, ...) {
 #define ERROR(ctx, ...) logger(ctx, LOG_ERR, __VA_ARGS__)
 #define DEBUG(ctx, ...) logger(ctx, LOG_DEBUG, __VA_ARGS__)
 
+static void do_zone(ctx_t* ctx, const char* name) {
+       DEBUG(ctx, "Processing zone %s\n", name);
+
+       // XXX TODO
+}
+
 static void run_loop(void* data) {
        ctx_t* ctx = data;
 
        DEBUG(ctx, "Event loop started\n");
+
+       // Process all zones
+       for (unsigned int i = 0; i < ctx->num_zones; i++) {
+               do_zone(ctx, ctx->zones[i]);
+       }
 }
 
 const char* argp_program_version = PACKAGE_VERSION;
@@ -101,12 +116,33 @@ static struct argp_option options[] = {
 
 static error_t parse(int key, char* arg, struct argp_state* state) {
        ctx_t* ctx = state->input;
+       const char** zones = NULL;
 
        switch (key) {
                case OPT_DEBUG:
                        ctx->log_level = LOG_DEBUG;
                        break;
 
+               case ARGP_KEY_ARG:
+                       zones = reallocarray(ctx->zones, ctx->num_zones + 1, sizeof(*ctx->zones));
+                       if (!zones) {
+                               argp_failure(state, EXIT_FAILURE, 0, "%m");
+                               return ARGP_ERR_UNKNOWN;
+                       }
+
+                       // Store the pointer to the argument
+                       zones[ctx->num_zones++] = arg;
+
+                       ctx->zones = zones;
+                       break;
+
+               case ARGP_KEY_SUCCESS:
+                       // Fail if we don't have any zones
+                       if (!ctx->zones) {
+                               argp_failure(state, EXIT_FAILURE, 0, "You must pass a zone");
+                       }
+                       break;
+
                // Ignore these
                case ARGP_KEY_END:
                case ARGP_KEY_ERROR:
@@ -159,5 +195,8 @@ ERROR:
        isc_netmgr_destroy(&ctx.netmgr);
        isc_loopmgr_destroy(&ctx.loopmgr);
 
+       if (ctx.zones)
+               free(ctx.zones);
+
        return 0;
 }