typedef struct ctx {
int log_level;
+ // Zones
+ const char** zones;
+ unsigned int num_zones;
+
// Memory Context
isc_mem_t* memctx;
#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;
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:
isc_netmgr_destroy(&ctx.netmgr);
isc_loopmgr_destroy(&ctx.loopmgr);
+ if (ctx.zones)
+ free(ctx.zones);
+
return 0;
}