diff options
Diffstat (limited to 'config.h')
-rw-r--r-- | config.h | 48 |
1 files changed, 14 insertions, 34 deletions
@@ -2,20 +2,9 @@ #define CONFIG_H #include <stddef.h> +#include "keyword.h" typedef struct config config; -typedef struct config_opt config_opt; -typedef union config_val config_val; -typedef enum config_type config_type; - -enum config_type { - TYPE_NONE, - TYPE_INT, - TYPE_STRING, - TYPE_FLOAT, - TYPE_BOOL, - TYPE_COUNT, -}; struct config { char *git_root; /* Root of git server. */ @@ -27,29 +16,20 @@ struct config { char *key_path; /* Path to maintainer authentication key file. */ }; -struct config_opt { - const char *name; /* Name of the config option. */ - const char *desc; /* Description of the config option. */ - config_type type; /* Datatype of the config option. */ - size_t offset; /* Offset of the member of the config option in the config struct. */ -}; - -union config_val { - int i; /* Integer. */ - char *str; /* String. */ - float f; /* Float. */ -}; - -static const config_opt config_opts[] = { - {"git-root", "Root of git server (can also be a url).", TYPE_STRING, offsetof(config, git_root)}, - {"socket-type", "Socket type to use (options: unix, network. default: network).", TYPE_STRING, offsetof(config, sock_type)}, - {"socket", "Path, IP address, or domain name of socket.", TYPE_STRING, offsetof(config, sock)}, - {"port", "Port to listen on (network socket only).", TYPE_STRING, offsetof(config, port)}, - {"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", TYPE_INT, offsetof(config, merge_type)}, - {"pr-root", "Directory to store pull requests in.", TYPE_STRING, offsetof(config, pr_root)}, - {"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", TYPE_STRING, offsetof(config, key_path)}, - {NULL, NULL, TYPE_NONE, -1}, +int check_port(void *ctx, void *ret, const keyword *key, keyword_val val); + +#define offset_list(...) (size_t []){__VA_ARGS__, -1} +static const keyword *config_keywords[] = { + &(const keyword){"git-root", "Root of git server (can also be a url).", NULL, TYPE_STRING, offset_list(offsetof(config, git_root)), NULL}, + &(const keyword){"socket-type", "Socket type to use (options: unix, network. default: network).", NULL, TYPE_STRING, offset_list(offsetof(config, sock_type)), NULL}, + &(const keyword){"socket", "Path, IP address, or domain name of socket.", NULL, TYPE_STRING, offset_list(offsetof(config, sock)), NULL}, + &(const keyword){"port", "Port to listen on (network socket only).", NULL, TYPE_STRING, offset_list(offsetof(config, port)), check_port}, + &(const keyword){"merge-type", "Type of merge (options: 0 = Merge individually, 1 = Merge into one).", NULL, TYPE_INT, offset_list(offsetof(config, merge_type)), NULL}, + &(const keyword){"pr-root", "Directory to store pull requests in.", NULL, TYPE_STRING, offset_list(offsetof(config, pr_root)), NULL}, + &(const keyword){"key-file", "Path to file containing gpg/pgp public keys of each maintainer.", NULL, TYPE_STRING, offset_list(offsetof(config, key_path)), NULL}, + NULL, }; +#undef offset_list extern config *parse_config(const char *filename); extern void cleanup_config(config *conf); |