/*
 * Creator: Naman Dixit
 * Notice: © Copyright 2020 Naman Dixit
 */

typedef struct Configuration {
    Char *kafka_address;

    U64 grunt_response_wait_time;
    Sint message_read_gap;
    Sint grunt_time_to_die;
} Configuration;

# if defined(COMPILER_CLANG)
#  pragma clang diagnostic push
#   pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
# endif

internal_function
Sint confCallback (void* user, const Char *section,
                   const Char *name, const Char *value)
{
    Configuration* conf = (Configuration*)user;

    if (stringEqual(section, "Arbiter")) {
        if (stringEqual(name, "MessageReadGap")) {
            conf->message_read_gap = atoi(value);
        } else if (stringEqual(name, "GruntTimeToDie")) {
            conf->grunt_time_to_die = atoi(value);
        } else if (stringEqual(name, "GruntResponseWaitTime")) {
            conf->grunt_response_wait_time = strtoul(value, NULL, 10);
        } else {
            return 0;  /* unknown section/name, error */
        }
    } else if (stringEqual(section, "Kafka")) {
        if (stringEqual(name, "Address")) {
            conf->kafka_address = strdup(value);
        } else {
            return 0;  /* unknown section/name, error */
        }
    }

    return 1;
}

# if defined(COMPILER_CLANG)
#  pragma clang diagnostic pop
# endif
