summaryrefslogtreecommitdiff
path: root/config.h
blob: e461369f91ceb1c4099cefa17881268c85f8a355 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef CONFIG_H
#define CONFIG_H

#include <stddef.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. */
	char *sock_type;	/* Type of socket. */
	char *sock;		/* Socket address. */
	int port;		/* Listen port. */
	int merge_type;		/* Merge type. */
	char *pr_root;		/* Root of pull requests. */
	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_INT, 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},
};

extern config *parse_config(const char *filename);
extern void cleanup_config(config *conf);
#endif