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 "pppsetting.h" |
8 | #include "pppsetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | NetworkManager::PppSettingPrivate::PppSettingPrivate() |
13 | : name(NM_SETTING_PPP_SETTING_NAME) |
14 | , noauth(true) |
15 | , refuseEap(false) |
16 | , refusePap(false) |
17 | , refuseChap(false) |
18 | , refuseMschap(false) |
19 | , refuseMschapv2(false) |
20 | , nobsdcomp(false) |
21 | , nodeflate(false) |
22 | , noVjComp(false) |
23 | , requireMppe(false) |
24 | , requireMppe128(false) |
25 | , mppeStateful(false) |
26 | , crtscts(false) |
27 | , baud(0) |
28 | , mru(0) |
29 | , mtu(0) |
30 | , lcpEchoFailure(0) |
31 | , lcpEchoInterval(0) |
32 | { |
33 | } |
34 | |
35 | NetworkManager::PppSetting::PppSetting() |
36 | : Setting(Setting::Ppp) |
37 | , d_ptr(new PppSettingPrivate()) |
38 | { |
39 | } |
40 | |
41 | NetworkManager::PppSetting::PppSetting(const Ptr &other) |
42 | : Setting(other) |
43 | , d_ptr(new PppSettingPrivate()) |
44 | { |
45 | setNoAuth(other->noAuth()); |
46 | setRefuseEap(other->refuseEap()); |
47 | setRefusePap(other->refusePap()); |
48 | setRefuseChap(other->refuseChap()); |
49 | setRefuseMschap(other->refuseMschap()); |
50 | setRefuseMschapv2(other->refuseMschapv2()); |
51 | setNoBsdComp(other->noBsdComp()); |
52 | setNoDeflate(other->noDeflate()); |
53 | setNoVjComp(other->noVjComp()); |
54 | setRequireMppe(other->requireMppe()); |
55 | setRequireMppe128(other->requireMppe128()); |
56 | setMppeStateful(other->mppeStateful()); |
57 | setCRtsCts(other->cRtsCts()); |
58 | setBaud(other->baud()); |
59 | setMru(other->mru()); |
60 | setMtu(other->mtu()); |
61 | setLcpEchoFailure(other->lcpEchoFailure()); |
62 | setLcpEchoInterval(other->lcpEchoInterval()); |
63 | } |
64 | |
65 | NetworkManager::PppSetting::~PppSetting() |
66 | { |
67 | delete d_ptr; |
68 | } |
69 | |
70 | QString NetworkManager::PppSetting::name() const |
71 | { |
72 | Q_D(const PppSetting); |
73 | |
74 | return d->name; |
75 | } |
76 | |
77 | void NetworkManager::PppSetting::setNoAuth(bool require) |
78 | { |
79 | Q_D(PppSetting); |
80 | |
81 | d->noauth = require; |
82 | } |
83 | |
84 | bool NetworkManager::PppSetting::noAuth() const |
85 | { |
86 | Q_D(const PppSetting); |
87 | |
88 | return d->noauth; |
89 | } |
90 | |
91 | void NetworkManager::PppSetting::setRefuseEap(bool refuse) |
92 | { |
93 | Q_D(PppSetting); |
94 | |
95 | d->refuseEap = refuse; |
96 | } |
97 | |
98 | bool NetworkManager::PppSetting::refuseEap() const |
99 | { |
100 | Q_D(const PppSetting); |
101 | |
102 | return d->refuseEap; |
103 | } |
104 | |
105 | void NetworkManager::PppSetting::setRefusePap(bool refuse) |
106 | { |
107 | Q_D(PppSetting); |
108 | |
109 | d->refusePap = refuse; |
110 | } |
111 | |
112 | bool NetworkManager::PppSetting::refusePap() const |
113 | { |
114 | Q_D(const PppSetting); |
115 | |
116 | return d->refusePap; |
117 | } |
118 | |
119 | void NetworkManager::PppSetting::setRefuseChap(bool refuse) |
120 | { |
121 | Q_D(PppSetting); |
122 | |
123 | d->refuseChap = refuse; |
124 | } |
125 | |
126 | bool NetworkManager::PppSetting::refuseChap() const |
127 | { |
128 | Q_D(const PppSetting); |
129 | |
130 | return d->refuseChap; |
131 | } |
132 | |
133 | void NetworkManager::PppSetting::setRefuseMschap(bool refuse) |
134 | { |
135 | Q_D(PppSetting); |
136 | |
137 | d->refuseMschap = refuse; |
138 | } |
139 | |
140 | bool NetworkManager::PppSetting::refuseMschap() const |
141 | { |
142 | Q_D(const PppSetting); |
143 | |
144 | return d->refuseMschap; |
145 | } |
146 | |
147 | void NetworkManager::PppSetting::setRefuseMschapv2(bool refuse) |
148 | { |
149 | Q_D(PppSetting); |
150 | |
151 | d->refuseMschapv2 = refuse; |
152 | } |
153 | |
154 | bool NetworkManager::PppSetting::refuseMschapv2() const |
155 | { |
156 | Q_D(const PppSetting); |
157 | |
158 | return d->refuseMschapv2; |
159 | } |
160 | |
161 | void NetworkManager::PppSetting::setNoBsdComp(bool require) |
162 | { |
163 | Q_D(PppSetting); |
164 | |
165 | d->nobsdcomp = require; |
166 | } |
167 | |
168 | bool NetworkManager::PppSetting::noBsdComp() const |
169 | { |
170 | Q_D(const PppSetting); |
171 | |
172 | return d->nobsdcomp; |
173 | } |
174 | |
175 | void NetworkManager::PppSetting::setNoDeflate(bool require) |
176 | { |
177 | Q_D(PppSetting); |
178 | |
179 | d->nodeflate = require; |
180 | } |
181 | |
182 | bool NetworkManager::PppSetting::noDeflate() const |
183 | { |
184 | Q_D(const PppSetting); |
185 | |
186 | return d->nodeflate; |
187 | } |
188 | |
189 | void NetworkManager::PppSetting::setNoVjComp(bool require) |
190 | { |
191 | Q_D(PppSetting); |
192 | |
193 | d->noVjComp = require; |
194 | } |
195 | |
196 | bool NetworkManager::PppSetting::noVjComp() const |
197 | { |
198 | Q_D(const PppSetting); |
199 | |
200 | return d->noVjComp; |
201 | } |
202 | |
203 | void NetworkManager::PppSetting::setRequireMppe(bool require) |
204 | { |
205 | Q_D(PppSetting); |
206 | |
207 | d->requireMppe = require; |
208 | } |
209 | |
210 | bool NetworkManager::PppSetting::requireMppe() const |
211 | { |
212 | Q_D(const PppSetting); |
213 | |
214 | return d->requireMppe; |
215 | } |
216 | |
217 | void NetworkManager::PppSetting::setRequireMppe128(bool require) |
218 | { |
219 | Q_D(PppSetting); |
220 | |
221 | d->requireMppe128 = require; |
222 | } |
223 | |
224 | bool NetworkManager::PppSetting::requireMppe128() const |
225 | { |
226 | Q_D(const PppSetting); |
227 | |
228 | return d->requireMppe128; |
229 | } |
230 | |
231 | void NetworkManager::PppSetting::setMppeStateful(bool used) |
232 | { |
233 | Q_D(PppSetting); |
234 | |
235 | d->mppeStateful = used; |
236 | } |
237 | |
238 | bool NetworkManager::PppSetting::mppeStateful() const |
239 | { |
240 | Q_D(const PppSetting); |
241 | |
242 | return d->mppeStateful; |
243 | } |
244 | |
245 | void NetworkManager::PppSetting::setCRtsCts(bool control) |
246 | { |
247 | Q_D(PppSetting); |
248 | |
249 | d->crtscts = control; |
250 | } |
251 | |
252 | bool NetworkManager::PppSetting::cRtsCts() const |
253 | { |
254 | Q_D(const PppSetting); |
255 | |
256 | return d->crtscts; |
257 | } |
258 | |
259 | void NetworkManager::PppSetting::setBaud(quint32 baud) |
260 | { |
261 | Q_D(PppSetting); |
262 | |
263 | d->baud = baud; |
264 | } |
265 | |
266 | quint32 NetworkManager::PppSetting::baud() const |
267 | { |
268 | Q_D(const PppSetting); |
269 | |
270 | return d->baud; |
271 | } |
272 | |
273 | void NetworkManager::PppSetting::setMru(quint32 mru) |
274 | { |
275 | Q_D(PppSetting); |
276 | |
277 | d->mru = mru; |
278 | } |
279 | |
280 | quint32 NetworkManager::PppSetting::mru() const |
281 | { |
282 | Q_D(const PppSetting); |
283 | |
284 | return d->mru; |
285 | } |
286 | |
287 | void NetworkManager::PppSetting::setMtu(quint32 mtu) |
288 | { |
289 | Q_D(PppSetting); |
290 | |
291 | d->mtu = mtu; |
292 | } |
293 | |
294 | quint32 NetworkManager::PppSetting::mtu() const |
295 | { |
296 | Q_D(const PppSetting); |
297 | |
298 | return d->mtu; |
299 | } |
300 | |
301 | void NetworkManager::PppSetting::setLcpEchoFailure(quint32 number) |
302 | { |
303 | Q_D(PppSetting); |
304 | |
305 | d->lcpEchoFailure = number; |
306 | } |
307 | |
308 | quint32 NetworkManager::PppSetting::lcpEchoFailure() const |
309 | { |
310 | Q_D(const PppSetting); |
311 | |
312 | return d->lcpEchoFailure; |
313 | } |
314 | |
315 | void NetworkManager::PppSetting::setLcpEchoInterval(quint32 interval) |
316 | { |
317 | Q_D(PppSetting); |
318 | |
319 | d->lcpEchoInterval = interval; |
320 | } |
321 | |
322 | quint32 NetworkManager::PppSetting::lcpEchoInterval() const |
323 | { |
324 | Q_D(const PppSetting); |
325 | |
326 | return d->lcpEchoInterval; |
327 | } |
328 | |
329 | void NetworkManager::PppSetting::fromMap(const QVariantMap &setting) |
330 | { |
331 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_NOAUTH))) { |
332 | setNoAuth(setting.value(key: QLatin1String(NM_SETTING_PPP_NOAUTH)).toBool()); |
333 | } |
334 | |
335 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REFUSE_EAP))) { |
336 | setRefuseEap(setting.value(key: QLatin1String(NM_SETTING_PPP_REFUSE_EAP)).toBool()); |
337 | } |
338 | |
339 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REFUSE_PAP))) { |
340 | setRefusePap(setting.value(key: QLatin1String(NM_SETTING_PPP_REFUSE_PAP)).toBool()); |
341 | } |
342 | |
343 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REFUSE_CHAP))) { |
344 | setRefuseChap(setting.value(key: QLatin1String(NM_SETTING_PPP_REFUSE_CHAP)).toBool()); |
345 | } |
346 | |
347 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP))) { |
348 | setRefuseMschap(setting.value(key: QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP)).toBool()); |
349 | } |
350 | |
351 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2))) { |
352 | setRefuseMschapv2(setting.value(key: QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2)).toBool()); |
353 | } |
354 | |
355 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_NOBSDCOMP))) { |
356 | setNoBsdComp(setting.value(key: QLatin1String(NM_SETTING_PPP_NOBSDCOMP)).toBool()); |
357 | } |
358 | |
359 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_NODEFLATE))) { |
360 | setNoDeflate(setting.value(key: QLatin1String(NM_SETTING_PPP_NODEFLATE)).toBool()); |
361 | } |
362 | |
363 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_NO_VJ_COMP))) { |
364 | setNoVjComp(setting.value(key: QLatin1String(NM_SETTING_PPP_NO_VJ_COMP)).toBool()); |
365 | } |
366 | |
367 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE))) { |
368 | setRequireMppe(setting.value(key: QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE)).toBool()); |
369 | } |
370 | |
371 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128))) { |
372 | setRequireMppe128(setting.value(key: QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128)).toBool()); |
373 | } |
374 | |
375 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL))) { |
376 | setMppeStateful(setting.value(key: QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL)).toBool()); |
377 | } |
378 | |
379 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_CRTSCTS))) { |
380 | setCRtsCts(setting.value(key: QLatin1String(NM_SETTING_PPP_CRTSCTS)).toBool()); |
381 | } |
382 | |
383 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_BAUD))) { |
384 | setBaud(setting.value(key: QLatin1String(NM_SETTING_PPP_BAUD)).toUInt()); |
385 | } |
386 | |
387 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_MRU))) { |
388 | setMru(setting.value(key: QLatin1String(NM_SETTING_PPP_MRU)).toUInt()); |
389 | } |
390 | |
391 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_MTU))) { |
392 | setMtu(setting.value(key: QLatin1String(NM_SETTING_PPP_MTU)).toUInt()); |
393 | } |
394 | |
395 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE))) { |
396 | setLcpEchoFailure(setting.value(key: QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE)).toUInt()); |
397 | } |
398 | |
399 | if (setting.contains(key: QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL))) { |
400 | setLcpEchoInterval(setting.value(key: QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL)).toUInt()); |
401 | } |
402 | } |
403 | |
404 | QVariantMap NetworkManager::PppSetting::toMap() const |
405 | { |
406 | QVariantMap setting; |
407 | |
408 | if (!noAuth()) { |
409 | setting.insert(key: QLatin1String(NM_SETTING_PPP_NOAUTH), value: noAuth()); |
410 | } |
411 | |
412 | if (refuseEap()) { |
413 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REFUSE_EAP), value: refuseEap()); |
414 | } |
415 | |
416 | if (refusePap()) { |
417 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REFUSE_PAP), value: refusePap()); |
418 | } |
419 | |
420 | if (refuseChap()) { |
421 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REFUSE_CHAP), value: refuseChap()); |
422 | } |
423 | |
424 | if (refuseMschap()) { |
425 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP), value: refuseMschap()); |
426 | } |
427 | |
428 | if (refuseMschapv2()) { |
429 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2), value: refuseMschapv2()); |
430 | } |
431 | |
432 | if (noBsdComp()) { |
433 | setting.insert(key: QLatin1String(NM_SETTING_PPP_NOBSDCOMP), value: noBsdComp()); |
434 | } |
435 | |
436 | if (noDeflate()) { |
437 | setting.insert(key: QLatin1String(NM_SETTING_PPP_NODEFLATE), value: noDeflate()); |
438 | } |
439 | |
440 | if (noVjComp()) { |
441 | setting.insert(key: QLatin1String(NM_SETTING_PPP_NO_VJ_COMP), value: noVjComp()); |
442 | } |
443 | |
444 | if (requireMppe()) { |
445 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE), value: requireMppe()); |
446 | } |
447 | |
448 | if (requireMppe128()) { |
449 | setting.insert(key: QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128), value: requireMppe128()); |
450 | } |
451 | |
452 | if (mppeStateful()) { |
453 | setting.insert(key: QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL), value: mppeStateful()); |
454 | } |
455 | |
456 | if (cRtsCts()) { |
457 | setting.insert(key: QLatin1String(NM_SETTING_PPP_CRTSCTS), value: cRtsCts()); |
458 | } |
459 | |
460 | if (baud()) { |
461 | setting.insert(key: QLatin1String(NM_SETTING_PPP_BAUD), value: baud()); |
462 | } |
463 | |
464 | if (mru()) { |
465 | setting.insert(key: QLatin1String(NM_SETTING_PPP_MRU), value: mru()); |
466 | } |
467 | |
468 | if (mtu()) { |
469 | setting.insert(key: QLatin1String(NM_SETTING_PPP_MTU), value: mtu()); |
470 | } |
471 | |
472 | if (lcpEchoFailure()) { |
473 | setting.insert(key: QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE), value: lcpEchoFailure()); |
474 | } |
475 | |
476 | if (lcpEchoInterval()) { |
477 | setting.insert(key: QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL), value: lcpEchoInterval()); |
478 | } |
479 | |
480 | return setting; |
481 | } |
482 | |
483 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::PppSetting &setting) |
484 | { |
485 | dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n'; |
486 | dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; |
487 | |
488 | dbg.nospace() << NM_SETTING_PPP_NOAUTH << ": " << setting.noAuth() << '\n'; |
489 | dbg.nospace() << NM_SETTING_PPP_REFUSE_EAP << ": " << setting.refuseEap() << '\n'; |
490 | dbg.nospace() << NM_SETTING_PPP_REFUSE_PAP << ": " << setting.refusePap() << '\n'; |
491 | dbg.nospace() << NM_SETTING_PPP_REFUSE_CHAP << ": " << setting.refuseChap() << '\n'; |
492 | dbg.nospace() << NM_SETTING_PPP_REFUSE_MSCHAP << ": " << setting.refuseMschap() << '\n'; |
493 | dbg.nospace() << NM_SETTING_PPP_REFUSE_MSCHAPV2 << ": " << setting.refuseMschapv2() << '\n'; |
494 | dbg.nospace() << NM_SETTING_PPP_NOBSDCOMP << ": " << setting.noBsdComp() << '\n'; |
495 | dbg.nospace() << NM_SETTING_PPP_NODEFLATE << ": " << setting.noDeflate() << '\n'; |
496 | dbg.nospace() << NM_SETTING_PPP_NO_VJ_COMP << ": " << setting.noVjComp() << '\n'; |
497 | dbg.nospace() << NM_SETTING_PPP_REQUIRE_MPPE << ": " << setting.requireMppe() << '\n'; |
498 | dbg.nospace() << NM_SETTING_PPP_REQUIRE_MPPE_128 << ": " << setting.requireMppe128() << '\n'; |
499 | dbg.nospace() << NM_SETTING_PPP_MPPE_STATEFUL << ": " << setting.mppeStateful() << '\n'; |
500 | dbg.nospace() << NM_SETTING_PPP_CRTSCTS << ": " << setting.cRtsCts() << '\n'; |
501 | dbg.nospace() << NM_SETTING_PPP_BAUD << ": " << setting.baud() << '\n'; |
502 | dbg.nospace() << NM_SETTING_PPP_MRU << ": " << setting.mru() << '\n'; |
503 | dbg.nospace() << NM_SETTING_PPP_MTU << ": " << setting.mtu() << '\n'; |
504 | dbg.nospace() << NM_SETTING_PPP_LCP_ECHO_FAILURE << ": " << setting.lcpEchoFailure() << '\n'; |
505 | dbg.nospace() << NM_SETTING_PPP_LCP_ECHO_INTERVAL << ": " << setting.lcpEchoInterval() << '\n'; |
506 | |
507 | return dbg.maybeSpace(); |
508 | } |
509 | |