|
@@ -0,0 +1,98 @@
|
|
1
|
+//
|
|
2
|
+// Created by robin on 8/8/15.
|
|
3
|
+//
|
|
4
|
+
|
|
5
|
+#include <fstream>
|
|
6
|
+#include <iostream>
|
|
7
|
+#include "PdnsSlaveConfig.h"
|
|
8
|
+
|
|
9
|
+PdnsSlaveConfig::PdnsSlaveConfig(const std::string &filePath)
|
|
10
|
+ : _filePath(filePath)
|
|
11
|
+{
|
|
12
|
+}
|
|
13
|
+
|
|
14
|
+bool PdnsSlaveConfig::readConfig()
|
|
15
|
+{
|
|
16
|
+ std::ifstream file(_filePath);
|
|
17
|
+ if (!file)
|
|
18
|
+ return false;
|
|
19
|
+ try
|
|
20
|
+ {
|
|
21
|
+ Json::Value root;
|
|
22
|
+ file >> root;
|
|
23
|
+ file.close();
|
|
24
|
+ if (!readString(root, "dhcpd-file", _dhcpdFilePath))
|
|
25
|
+ return false;
|
|
26
|
+ if (!readString(root, "dhcpd-template", _dhcpdTemplatePath))
|
|
27
|
+ return false;
|
|
28
|
+ if (!readString(root, "hosts-file", _hostsPath))
|
|
29
|
+ return false;
|
|
30
|
+ if (!readSqlConfiguration(root, "master", _masterConfig))
|
|
31
|
+ return false;
|
|
32
|
+ if (!readSqlConfiguration(root, "slave", _slaveConfig))
|
|
33
|
+ return false;
|
|
34
|
+ }
|
|
35
|
+ catch (...)
|
|
36
|
+ {
|
|
37
|
+ file.close();
|
|
38
|
+ return false;
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ return true;
|
|
42
|
+}
|
|
43
|
+
|
|
44
|
+bool PdnsSlaveConfig::readSqlConfiguration(const Json::Value &value, const std::string &name, SqlConfiguration &sqlConfiguration)
|
|
45
|
+{
|
|
46
|
+ std::string str;
|
|
47
|
+ if (!readString(value, name + "-host", str))
|
|
48
|
+ return false;
|
|
49
|
+ sqlConfiguration.setHost(str);
|
|
50
|
+
|
|
51
|
+ if (!readString(value, name + "-user", str))
|
|
52
|
+ return false;
|
|
53
|
+ sqlConfiguration.setUser(str);
|
|
54
|
+
|
|
55
|
+ if (!readString(value, name + "-password", str))
|
|
56
|
+ return false;
|
|
57
|
+ sqlConfiguration.setPassword(str);
|
|
58
|
+
|
|
59
|
+ if (!readString(value, name + "-database", str))
|
|
60
|
+ return false;
|
|
61
|
+ sqlConfiguration.setDatabase(str);
|
|
62
|
+
|
|
63
|
+ return true;
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+bool PdnsSlaveConfig::readString(const Json::Value &value, const std::string &name, std::string &dest)
|
|
67
|
+{
|
|
68
|
+ auto v = value[name];
|
|
69
|
+ if (!v)
|
|
70
|
+ return false;
|
|
71
|
+ dest = v.asString();
|
|
72
|
+ return true;
|
|
73
|
+}
|
|
74
|
+
|
|
75
|
+const std::string &PdnsSlaveConfig::getDhcpdFilePath() const
|
|
76
|
+{
|
|
77
|
+ return _dhcpdFilePath;
|
|
78
|
+}
|
|
79
|
+
|
|
80
|
+const std::string &PdnsSlaveConfig::getDhcpdTemplatePath() const
|
|
81
|
+{
|
|
82
|
+ return _dhcpdTemplatePath;
|
|
83
|
+}
|
|
84
|
+
|
|
85
|
+const std::string &PdnsSlaveConfig::getHostsPath() const
|
|
86
|
+{
|
|
87
|
+ return _hostsPath;
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+const SqlConfiguration &PdnsSlaveConfig::getMasterConfig() const
|
|
91
|
+{
|
|
92
|
+ return _masterConfig;
|
|
93
|
+}
|
|
94
|
+
|
|
95
|
+const SqlConfiguration &PdnsSlaveConfig::getSlaveConfig() const
|
|
96
|
+{
|
|
97
|
+ return _slaveConfig;
|
|
98
|
+}
|