configfileparser.h
1.68 KB
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
57
58
59
#ifndef CONFIGFILEPARSER_H
#define CONFIGFILEPARSER_H
#include <string>
#include <set>
#include <unordered_map>
#include <vector>
#include <memory>
#include "sslctxmanager.h"
struct mosquitto_auth_opt
{
char *key = nullptr;
char *value = nullptr;
mosquitto_auth_opt(const std::string &key, const std::string &value);
mosquitto_auth_opt(mosquitto_auth_opt &&other);
mosquitto_auth_opt(const mosquitto_auth_opt &other) = delete;
~mosquitto_auth_opt();
};
struct AuthOptCompatWrap
{
std::vector<struct mosquitto_auth_opt> optArray;
AuthOptCompatWrap(const std::unordered_map<std::string, std::string> &authOpts);
AuthOptCompatWrap(const AuthOptCompatWrap &other) = delete;
AuthOptCompatWrap(AuthOptCompatWrap &&other) = delete;
struct mosquitto_auth_opt *head() { return &optArray[0]; }
int size() { return optArray.size(); }
};
class ConfigFileParser
{
const std::string path;
std::set<std::string> validKeys;
std::unordered_map<std::string, std::string> authOpts;
std::unique_ptr<AuthOptCompatWrap> authOptCompatWrap;
void checkFileAccess(const std::string &key, const std::string &pathToCheck) const;
void testSsl(const std::string &fullchain, const std::string &privkey, uint portNr) const;
public:
ConfigFileParser(const std::string &path);
void loadFile(bool test);
AuthOptCompatWrap &getAuthOptsCompat();
// Actual config options with their defaults. Just making them public, I can retrain myself misuing them.
std::string authPluginPath;
std::string logPath;
std::string sslFullchain;
std::string sslPrivkey;
uint listenPort = 1883;
uint sslListenPort = 0;
};
#endif // CONFIGFILEPARSER_H