]> git.sesse.net Git - cubemap/blob - config.h
Fix some duplicated IP address parsing code.
[cubemap] / config.h
1 #ifndef _CONFIG_H
2 #define _CONFIG_H
3
4 // Various routines that deal with parsing the configuration file.
5
6 #include <arpa/inet.h>
7 #include <netinet/in.h>
8 #include <stddef.h>
9 #include <string>
10 #include <vector>
11
12 struct MarkPoolConfig {
13         int from, to;
14 };
15
16 struct StreamConfig {
17         std::string url;  // As seen by the client.
18         std::string src;  // Can be empty.
19         size_t backlog_size;
20         int mark_pool;  // -1 for none.
21         uint32_t pacing_rate;  // In bytes per second. Default is ~0U (no limit).
22         enum { STREAM_ENCODING_RAW = 0, STREAM_ENCODING_METACUBE } encoding;
23 };
24
25 struct UDPStreamConfig {
26         sockaddr_in6 dst;
27         std::string src;  // Can be empty.
28         int mark_pool;  // -1 for none.
29         uint32_t pacing_rate;  // In bytes per second. Default is ~0U (no limit).
30 };
31
32 struct AcceptorConfig {
33         sockaddr_in6 addr;
34 };
35
36 struct LogConfig {
37         enum { LOG_TYPE_FILE, LOG_TYPE_CONSOLE, LOG_TYPE_SYSLOG } type;
38         std::string filename;
39 };
40
41 struct Config {
42         bool daemonize;
43         int num_servers;
44         std::vector<MarkPoolConfig> mark_pools;
45         std::vector<StreamConfig> streams;
46         std::vector<UDPStreamConfig> udpstreams;
47         std::vector<AcceptorConfig> acceptors;
48         std::vector<LogConfig> log_destinations;
49
50         std::string stats_file;  // Empty means no stats file.
51         int stats_interval;
52
53         std::string input_stats_file;  // Empty means no input stats file.
54         int input_stats_interval;
55
56         std::string access_log_file;  // Empty means no accses_log file.
57 };
58
59 // Parse and validate configuration. Returns false on error.
60 // <config> is taken to be empty (uninitialized) on entry.
61 bool parse_config(const std::string &filename, Config *config);
62
63 #endif  // !defined(_CONFIG_H)