blob: 37dd3f9202475c9e722a05cfbb16c74bd604b4e0 (
plain) (
blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/**
* @class InterfaceConfiguration
*
* @brief reads and stores a interface configuration.
*
* reads and stores a interface configuration.
* the config file has already to exist. It is created by the cdhcpcd client process.
*
*/
#include "interfaceconfiguration.h"
#include <log4cxx/logger.h>
#include "qlog4cxx.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
LoggerPtr ndifLogger(Logger::getLogger("fbgui.nd.ifconf"));
InterfaceConfiguration::InterfaceConfiguration() {
}
InterfaceConfiguration::~InterfaceConfiguration() {
// TODO Auto-generated destructor stub
}
/**
* This method reads the configuration values out of a file.
*
* This method reads the configuration values out of a file.
* The file has to be created before by the customdhcpcd QProcess.
* (Overwrites the old values if they are already present.)
*
* @param pathToConfig
* contains the path to the configuration file.
*/
bool InterfaceConfiguration::readConfigOutOfFile(QString pathToConfig) {
QFile file(pathToConfig);
if (file.exists()) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
LOG4CXX_DEBUG(ndifLogger, "Couldn't open file:" << pathToConfig);
return false;
}
LOG4CXX_DEBUG(ndifLogger, "read config file");
while (!file.atEnd()) {
QString line(file.readLine());
QStringList splitedLine = line.split("=");
QString name = splitedLine.first().trimmed();
splitedLine.removeFirst();
QString values = splitedLine.first().trimmed();
values.remove(QChar('\''));
if (name.compare("IPADDR") == 0) {
this->ipAddress = values;
} else if (name.compare("NETMASK") == 0) {
this->netmask = values;
} else if (name.compare("NETWORK") == 0) {
this->network = values;
} else if (name.compare("BROADCAST") == 0) {
this->broadcast = values;
} else if (name.compare("ROUTES") == 0) {
this->routes = values;
} else if (name.compare("GATEWAYS") == 0) {
this->gateways = values;
this->gateway = this->gateways.split(" ").first().trimmed();
} else if (name.compare("HOSTNAME") == 0) {
this->hostname = values;
} else if (name.compare("DNSSEARCH") == 0) {
this->dnssearch = values;
} else if (name.compare("DNSSERVERS") == 0) {
this->dnsservers = values;
} else if (name.compare("DHCPSID") == 0) {
this->dhcpsid = values;
} else if (name.compare("INTERFACE") == 0) {
this->interface = values;
} else if (name.compare("CLIENTID") == 0) {
this->clientid = values;
} else if (name.compare("DHCPCHADDR") == 0) {
this->dhcpchaddr = values;
} else {
LOG4CXX_DEBUG(ndifLogger, "read unknown name" << name << values);
}
}
} else {
LOG4CXX_DEBUG(ndifLogger, "file doesn't exist:" << pathToConfig);
return false;
}
return true;
}
QString InterfaceConfiguration::getBroadcast() {
return broadcast;
}
QString InterfaceConfiguration::getClientid() {
return clientid;
}
QString InterfaceConfiguration::getDhcpchaddr() {
return dhcpchaddr;
}
QString InterfaceConfiguration::getDhcpsid() {
return dhcpsid;
}
QString InterfaceConfiguration::getDnssearch() {
return dnssearch;
}
QString InterfaceConfiguration::getDnsservers() {
return dnsservers;
}
QString InterfaceConfiguration::getGateways() {
return gateways;
}
QString InterfaceConfiguration::getGateway() {
return gateway;
}
QString InterfaceConfiguration::getHostname() {
return hostname;
}
QString InterfaceConfiguration::getInterface() {
return interface;
}
QString InterfaceConfiguration::getIpAddress() {
return ipAddress;
}
QString InterfaceConfiguration::getNetmask() {
return netmask;
}
QString InterfaceConfiguration::getNetwork() {
return network;
}
QString InterfaceConfiguration::getRoutes() {
return routes;
}
|