Changeset View
Changeset View
Standalone View
Standalone View
src/dnsconfiguration.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2018 Aleksander Morgado <aleksander@aleksander.es> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "ipconfig.h" | ||||
22 | | ||||
23 | #include <arpa/inet.h> | ||||
24 | | ||||
25 | #include "dnsconfiguration.h" | ||||
26 | | ||||
27 | namespace NetworkManager | ||||
28 | { | ||||
29 | | ||||
30 | class NetworkManager::DnsConfiguration::Private | ||||
31 | { | ||||
32 | public: | ||||
33 | Private(const QStringList &theSearches, | ||||
34 | const QStringList &theOptions, | ||||
35 | const QList<DnsDomain> theDomains) | ||||
36 | : searches(theSearches) | ||||
37 | , options(theOptions) | ||||
38 | , domains(theDomains) | ||||
39 | {} | ||||
40 | Private() | ||||
41 | {} | ||||
42 | QStringList searches; | ||||
43 | QStringList options; | ||||
44 | QList<DnsDomain> domains; | ||||
45 | }; | ||||
46 | | ||||
47 | } | ||||
48 | | ||||
49 | NetworkManager::DnsConfiguration::DnsConfiguration(const QStringList &searches, | ||||
50 | const QStringList &options, | ||||
51 | const QList<DnsDomain> domains) | ||||
52 | : d(new Private(searches, options, domains)) | ||||
53 | { | ||||
54 | } | ||||
55 | | ||||
56 | NetworkManager::DnsConfiguration::DnsConfiguration() | ||||
57 | : d(new Private()) | ||||
58 | { | ||||
59 | } | ||||
60 | | ||||
61 | NetworkManager::DnsConfiguration::DnsConfiguration(const DnsConfiguration &other) | ||||
62 | : d(new Private) | ||||
63 | { | ||||
64 | *this = other; | ||||
65 | } | ||||
66 | | ||||
67 | NetworkManager::DnsConfiguration::~DnsConfiguration() | ||||
68 | { | ||||
69 | delete d; | ||||
70 | } | ||||
71 | | ||||
72 | QStringList NetworkManager::DnsConfiguration::searches() const | ||||
73 | { | ||||
74 | return d->searches; | ||||
75 | } | ||||
76 | | ||||
77 | void NetworkManager::DnsConfiguration::setSearches(const QStringList &searches) | ||||
78 | { | ||||
79 | d->searches = searches; | ||||
80 | } | ||||
81 | | ||||
82 | QStringList NetworkManager::DnsConfiguration::options() const | ||||
83 | { | ||||
84 | return d->options; | ||||
85 | } | ||||
86 | | ||||
87 | void NetworkManager::DnsConfiguration::setOptions(const QStringList &options) | ||||
88 | { | ||||
89 | d->options = options; | ||||
90 | } | ||||
91 | | ||||
92 | QList<NetworkManager::DnsDomain> NetworkManager::DnsConfiguration::domains() const | ||||
93 | { | ||||
94 | return d->domains; | ||||
95 | } | ||||
96 | | ||||
97 | void NetworkManager::DnsConfiguration::setDomains(const QList<NetworkManager::DnsDomain> &domains) | ||||
98 | { | ||||
99 | d->domains = domains; | ||||
100 | } | ||||
101 | | ||||
102 | QVariantMap NetworkManager::DnsConfiguration::toMap() const | ||||
103 | { | ||||
104 | QVariantMap map; | ||||
105 | | ||||
106 | map["searches"] = d->searches; | ||||
107 | map["options"] = d->options; | ||||
108 | | ||||
109 | QVariantMap domains; | ||||
110 | Q_FOREACH (const NetworkManager::DnsDomain &domain, d->domains) { | ||||
111 | QVariantMap contents; | ||||
112 | QStringList serversList; | ||||
113 | Q_FOREACH (const QHostAddress &address, domain.servers()) | ||||
114 | serversList.append(address.toString()); | ||||
115 | contents["servers"] = serversList; | ||||
116 | contents["options"] = domain.options(); | ||||
117 | domains[domain.name()] = contents; | ||||
118 | } | ||||
119 | map["domains"] = domains; | ||||
120 | | ||||
121 | return map; | ||||
122 | } | ||||
123 | | ||||
124 | void NetworkManager::DnsConfiguration::fromMap (const QVariantMap &map) | ||||
125 | { | ||||
126 | d->searches = map["searches"].toStringList(); | ||||
127 | d->options = map["options"].toStringList(); | ||||
128 | d->domains = QList<NetworkManager::DnsDomain>(); | ||||
129 | | ||||
130 | QVariantMap domains = map["domains"].toMap(); | ||||
131 | QVariantMap::const_iterator i = domains.constBegin(); | ||||
132 | while (i != domains.constEnd()) { | ||||
133 | QVariantMap contents = i.value().toMap(); | ||||
134 | QList<QHostAddress> addressList; | ||||
135 | Q_FOREACH (const QString &server, contents["servers"].toStringList()) | ||||
136 | addressList.append(QHostAddress(server)); | ||||
137 | NetworkManager::DnsDomain domain(i.key(), | ||||
138 | addressList, | ||||
139 | contents["options"].toStringList()); | ||||
140 | d->domains.append(domain); | ||||
141 | ++i; | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | NetworkManager::DnsConfiguration &NetworkManager::DnsConfiguration::operator=(const DnsConfiguration &other) | ||||
146 | { | ||||
147 | if (this == &other) { | ||||
148 | return *this; | ||||
149 | } | ||||
150 | | ||||
151 | *d = *other.d; | ||||
152 | return *this; | ||||
153 | } |