NetworkManagerQt

setting.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "setting.h"
8
9#undef signals
10#include <nm-version.h>
11#define signals Q_SIGNALS
12
13#include <QDebug>
14
15#if !NM_CHECK_VERSION(1, 16, 0)
16#define NM_SETTING_WIREGUARD_SETTING_NAME "wireguard"
17#endif
18
19#if !NM_CHECK_VERSION(1, 14, 0)
20#define NM_SETTING_MATCH_SETTING_NAME "match"
21#endif
22
23#if !NM_CHECK_VERSION(1, 10, 0)
24#define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge"
25#define NM_SETTING_OVS_INTERFACE_SETTING_NAME "ovs-interface"
26#define NM_SETTING_OVS_PATCH_SETTING_NAME "ovs-patch"
27#define NM_SETTING_OVS_PORT_SETTING_NAME "ovs-port"
28#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc"
29#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port"
30#endif
31
32#if !NM_CHECK_VERSION(1, 8, 0)
33#define NM_SETTING_USER_SETTING_NAME "user"
34#endif
35
36#if !NM_CHECK_VERSION(1, 6, 0)
37#define NM_SETTING_MACSEC_SETTING_NAME "macsec"
38#define NM_SETTING_PROXY_SETTING_NAME "proxy"
39#endif
40
41namespace NetworkManager
42{
43class SettingPrivate
44{
45public:
46 SettingPrivate();
47
48 Setting::SettingType type;
49 bool initialized;
50};
51
52QDebug operator<<(QDebug dbg, const Setting &setting)
53{
54 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
55 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
56 return dbg.maybeSpace();
57}
58
59}
60
61NetworkManager::SettingPrivate::SettingPrivate()
62 : type(Setting::Wired)
63 , initialized(false)
64{
65}
66
67QString NetworkManager::Setting::typeAsString(NetworkManager::Setting::SettingType type)
68{
69 QString typeString;
70
71 switch (type) {
72 case Cdma:
73 typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME);
74 break;
75 case Gsm:
76 typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME);
77 break;
78 case Bluetooth:
79 typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME);
80 break;
81 case Ipv4:
82 typeString = QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME);
83 break;
84 case Ipv6:
85 typeString = QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME);
86 break;
87 case Ppp:
88 typeString = QLatin1String(NM_SETTING_PPP_SETTING_NAME);
89 break;
90 case Pppoe:
91 typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME);
92 break;
93 case Security8021x:
94 typeString = QLatin1String(NM_SETTING_802_1X_SETTING_NAME);
95 break;
96 case Serial:
97 typeString = QLatin1String(NM_SETTING_SERIAL_SETTING_NAME);
98 break;
99 case Vpn:
100 typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME);
101 break;
102 case Wired:
103 typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME);
104 break;
105 case Wireless:
106 typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME);
107 break;
108 case WirelessSecurity:
109 typeString = QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
110 break;
111 case OlpcMesh:
112 typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME);
113 break;
114 case Vlan:
115 typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME);
116 break;
117 case Wimax:
118 typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME);
119 break;
120 case Bond:
121 typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME);
122 break;
123 case Bridge:
124 typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME);
125 break;
126 case Team:
127 typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME);
128 break;
129 case Vxlan:
130 typeString = QLatin1String(NM_SETTING_VXLAN_SETTING_NAME);
131 break;
132 case IpTunnel:
133 typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME);
134 break;
135 case Proxy:
136 typeString = QLatin1String(NM_SETTING_PROXY_SETTING_NAME);
137 break;
138 case User:
139 typeString = QLatin1String(NM_SETTING_USER_SETTING_NAME);
140 break;
141 case OvsInterface:
142 typeString = QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME);
143 break;
144 case OvsBridge:
145 typeString = QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME);
146 break;
147 case OvsPatch:
148 typeString = QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME);
149 break;
150 case OvsPort:
151 typeString = QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME);
152 break;
153 case Match:
154 typeString = QLatin1String(NM_SETTING_MATCH_SETTING_NAME);
155 break;
156 case Tc:
157 typeString = QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME);
158 break;
159 case TeamPort:
160 typeString = QLatin1String(NM_SETTING_TEAM_PORT_SETTING_NAME);
161 break;
162 case Macsec:
163 typeString = QLatin1String(NM_SETTING_MACSEC_SETTING_NAME);
164 break;
165 case Dcb:
166 typeString = QLatin1String(NM_SETTING_DCB_SETTING_NAME);
167 break;
168 case NetworkManager::Setting::WireGuard:
169 typeString = QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME);
170 break;
171 case NetworkManager::Setting::Generic:
172 typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME);
173 break;
174 default:
175 break;
176 }
177
178 return typeString;
179}
180
181NetworkManager::Setting::SettingType NetworkManager::Setting::typeFromString(const QString &typeString)
182{
183 SettingType type = Wired;
184
185 if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) {
186 type = Cdma;
187 } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) {
188 type = Gsm;
189 } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) {
190 type = Bluetooth;
191 } else if (typeString == QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME)) {
192 type = Ipv4;
193 } else if (typeString == QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME)) {
194 type = Ipv6;
195 } else if (typeString == QLatin1String(NM_SETTING_PPP_SETTING_NAME)) {
196 type = Ppp;
197 } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) {
198 type = Pppoe;
199 } else if (typeString == QLatin1String(NM_SETTING_SERIAL_SETTING_NAME)) {
200 type = Serial;
201 } else if (typeString == QLatin1String(NM_SETTING_802_1X_SETTING_NAME)) {
202 type = Security8021x;
203 } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) {
204 type = Vpn;
205 } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) {
206 type = Wired;
207 } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) {
208 type = Wireless;
209 } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) {
210 type = WirelessSecurity;
211 } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) {
212 type = OlpcMesh;
213 } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) {
214 type = Vlan;
215 } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) {
216 type = Wimax;
217 } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) {
218 type = Bond;
219 } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) {
220 type = Bridge;
221 } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) {
222 type = Team;
223 } else if (typeString == QLatin1String(NM_SETTING_VXLAN_SETTING_NAME)) {
224 type = Vxlan;
225 } else if (typeString == QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME)) {
226 type = IpTunnel;
227 } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) {
228 type = Generic;
229 } else if (typeString == QLatin1String(NM_SETTING_USER_SETTING_NAME)) {
230 type = User;
231 } else if (typeString == QLatin1String(NM_SETTING_PROXY_SETTING_NAME)) {
232 type = Proxy;
233 } else if (typeString == QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME)) {
234 type = OvsInterface;
235 } else if (typeString == QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME)) {
236 type = OvsBridge;
237 } else if (typeString == QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME)) {
238 type = OvsPatch;
239 } else if (typeString == QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME)) {
240 type = OvsPort;
241 } else if (typeString == QLatin1String(NM_SETTING_MATCH_SETTING_NAME)) {
242 type = Match;
243 } else if (typeString == QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME)) {
244 type = Tc;
245 } else if (typeString == QLatin1String(NM_SETTING_TEAM_PORT_SETTING_NAME)) {
246 type = TeamPort;
247 } else if (typeString == QLatin1String(NM_SETTING_MACSEC_SETTING_NAME)) {
248 type = Macsec;
249 } else if (typeString == QLatin1String(NM_SETTING_DCB_SETTING_NAME)) {
250 type = Dcb;
251 } else if (typeString == QLatin1String(NM_SETTING_WIREGUARD_SETTING_NAME)) {
252 type = WireGuard;
253 }
254
255 return type;
256}
257
258NetworkManager::Setting::Setting(SettingType type)
259 : d_ptr(new SettingPrivate())
260{
261 setType(type);
262}
263
264NetworkManager::Setting::Setting(const NetworkManager::Setting::Ptr &setting)
265 : d_ptr(new SettingPrivate())
266{
267 setInitialized(!setting->isNull());
268 setType(setting->type());
269}
270
271NetworkManager::Setting::~Setting()
272{
273 delete d_ptr;
274}
275
276void NetworkManager::Setting::fromMap(const QVariantMap &map)
277{
278 Q_UNUSED(map);
279}
280
282{
283 return QVariantMap();
284}
285
286QStringList NetworkManager::Setting::needSecrets(bool requestNew) const
287{
288 Q_UNUSED(requestNew);
289 return QStringList();
290}
291
293{
294 return QString();
295}
296
297void NetworkManager::Setting::secretsFromMap(const QVariantMap &map)
298{
299 Q_UNUSED(map);
300}
301
303{
304 QVariantMap secretsMap;
305 NMStringMap::ConstIterator i = map.constBegin();
306 while (i != map.constEnd()) {
307 secretsMap.insert(i.key(), i.value());
308 ++i;
309 }
310 secretsFromMap(secretsMap);
311}
312
313QVariantMap NetworkManager::Setting::secretsToMap() const
314{
315 return QVariantMap();
316}
317
319{
320 NMStringMap ret;
321 QVariantMap secretsMap = secretsToMap();
322 QVariantMap::ConstIterator i = secretsMap.constBegin();
323 while (i != secretsMap.constEnd()) {
324 ret.insert(i.key(), i.value().toString());
325 ++i;
326 }
327
328 return ret;
329}
330
331void NetworkManager::Setting::setInitialized(bool initialized)
332{
333 Q_D(Setting);
334
335 d->initialized = initialized;
336}
337
338bool NetworkManager::Setting::isNull() const
339{
340 Q_D(const Setting);
341
342 return !d->initialized;
343}
344
345void NetworkManager::Setting::setType(NetworkManager::Setting::SettingType type)
346{
347 Q_D(Setting);
348
349 d->type = type;
350}
351
352NetworkManager::Setting::SettingType NetworkManager::Setting::type() const
353{
354 Q_D(const Setting);
355
356 return d->type;
357}
Base class for all kinds of setting.
Definition setting.h:30
virtual NMStringMap secretsToStringMap() const
secretsToStringMap is a convenience function to get the secrets to map of strings.
Definition setting.cpp:318
virtual void secretsFromStringMap(const NMStringMap &map)
secretsFromStringMap is a convenience function to set the secrets from a map of strings.
Definition setting.cpp:302
virtual void fromMap(const QVariantMap &map)
Must be reimplemented, default implementation does nothing.
Definition setting.cpp:276
virtual QString name() const
Must be reimplemented, default implementationd does nothing.
Definition setting.cpp:292
virtual QVariantMap toMap() const
Must be reimplemented, default implementationd does nothing.
Definition setting.cpp:281
Type type(const QSqlDatabase &db)
KTEXTEDITOR_EXPORT QDebug operator<<(QDebug s, const MovingCursor &cursor)
This class allows querying the underlying system to discover the available network interfaces and rea...
Definition accesspoint.h:21
QDebug & maybeSpace()
QDebug & nospace()
iterator insert(const Key &key, const T &value)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:52:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.