1 /*
2   networksupport.cpp
3 
4   This file is part of GammaRay, the Qt application inspection and
5   manipulation tool.
6 
7   Copyright (C) 2016-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8   Author: Volker Krause <volker.krause@kdab.com>
9 
10   Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11   accordance with GammaRay Commercial License Agreement provided with the Software.
12 
13   Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 
15   This program is free software; you can redistribute it and/or modify
16   it under the terms of the GNU General Public License as published by
17   the Free Software Foundation, either version 2 of the License, or
18   (at your option) any later version.
19 
20   This program is distributed in the hope that it will be useful,
21   but WITHOUT ANY WARRANTY; without even the implied warranty of
22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   GNU General Public License for more details.
24 
25   You should have received a copy of the GNU General Public License
26   along with this program.  If not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 #include "networksupport.h"
30 #include "networkinterfacemodel.h"
31 #include "networkconfigurationmodel.h"
32 #include "networkreplymodel.h"
33 #include "cookies/cookieextension.h"
34 
35 #include <core/enumrepositoryserver.h>
36 #include <core/metaenum.h>
37 #include <core/metaobject.h>
38 #include <core/metaobjectrepository.h>
39 #include <core/propertycontroller.h>
40 #include <core/remote/serverproxymodel.h>
41 #include <core/varianthandler.h>
42 
43 #include <QAbstractNetworkCache>
44 #include <QHostAddress>
45 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
46 #include <QHstsPolicy>
47 #endif
48 #include <QLocalSocket>
49 #include <QNetworkAccessManager>
50 #include <QNetworkConfiguration>
51 #include <QNetworkConfigurationManager>
52 #include <QNetworkCookieJar>
53 #include <QNetworkProxy>
54 #include <QNetworkSession>
55 #include <QSocketNotifier>
56 #include <QSslCertificateExtension>
57 #include <QSslCipher>
58 #include <QSslKey>
59 #include <QSslSocket>
60 #include <QTcpServer>
61 #include <QTcpSocket>
62 #include <QDateTime>
63 
64 #include <functional>
65 
66 using namespace GammaRay;
67 
68 Q_DECLARE_METATYPE(QAbstractSocket::PauseModes)
Q_DECLARE_METATYPE(QHostAddress)69 Q_DECLARE_METATYPE(QHostAddress)
70 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
71 Q_DECLARE_METATYPE(QHstsPolicy)
72 #endif
73 Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
74 Q_DECLARE_METATYPE(QLocalSocket::LocalSocketState)
75 Q_DECLARE_METATYPE(QNetworkAccessManager::NetworkAccessibility)
76 #if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
77 Q_DECLARE_METATYPE(QNetworkAddressEntry)
78 #endif
79 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
80 Q_DECLARE_METATYPE(QNetworkAddressEntry::DnsEligibilityStatus)
81 #endif
82 Q_DECLARE_METATYPE(QNetworkConfiguration::BearerType)
83 Q_DECLARE_METATYPE(QNetworkConfigurationManager::Capabilities)
84 #if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
85 Q_DECLARE_METATYPE(QNetworkInterface)
86 #endif
87 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
88 Q_DECLARE_METATYPE(QNetworkInterface::InterfaceFlags)
89 #endif
90 Q_DECLARE_METATYPE(QNetworkProxy::Capabilities)
91 Q_DECLARE_METATYPE(QNetworkProxy::ProxyType)
92 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
93 Q_DECLARE_METATYPE(QSocketNotifier::Type)
94 #endif
95 #ifndef QT_NO_SSL
96 Q_DECLARE_METATYPE(QSsl::KeyAlgorithm)
97 Q_DECLARE_METATYPE(QSsl::KeyType)
98 Q_DECLARE_METATYPE(QSsl::SslProtocol)
99 Q_DECLARE_METATYPE(QSslCertificateExtension)
100 Q_DECLARE_METATYPE(QSslCipher)
101 Q_DECLARE_METATYPE(QSslConfiguration::NextProtocolNegotiationStatus)
102 Q_DECLARE_METATYPE(QSslError)
103 Q_DECLARE_METATYPE(QSslKey)
104 Q_DECLARE_METATYPE(QSslSocket::PeerVerifyMode)
105 Q_DECLARE_METATYPE(QSslSocket::SslMode)
106 #endif // QT_NO_SSL
107 
108 NetworkSupport::NetworkSupport(Probe *probe, QObject *parent)
109     : QObject(parent)
110 {
111     registerMetaTypes();
112     registerVariantHandler();
113 
114     probe->registerModel(QStringLiteral("com.kdab.GammaRay.NetworkInterfaceModel"), new NetworkInterfaceModel(this));
115 
116     auto configProxy = new ServerProxyModel<QSortFilterProxyModel>(this);
117     configProxy->setSourceModel(new NetworkConfigurationModel(this));
118     configProxy->addRole(NetworkConfigurationModelRoles::DefaultConfigRole);
119     probe->registerModel(QStringLiteral("com.kdab.GammaRay.NetworkConfigurationModel"), configProxy);
120 
121     auto replyModel = new NetworkReplyModel(this);
122     connect(probe, &Probe::objectCreated, replyModel, &NetworkReplyModel::objectCreated);
123     probe->registerModel(QStringLiteral("com.kdab.GammaRay.NetworkReplyModel"), replyModel);
124 
125     PropertyController::registerExtension<CookieExtension>();
126 }
127 
128 NetworkSupport::~NetworkSupport() = default;
129 
registerMetaTypes()130 void NetworkSupport::registerMetaTypes()
131 {
132     MetaObject *mo = nullptr;
133     MO_ADD_METAOBJECT1(QAbstractSocket, QIODevice);
134     MO_ADD_PROPERTY_RO(QAbstractSocket, isValid);
135     MO_ADD_PROPERTY_RO(QAbstractSocket, localPort);
136     MO_ADD_PROPERTY_RO(QAbstractSocket, localAddress);
137     MO_ADD_PROPERTY_RO(QAbstractSocket, peerPort);
138     MO_ADD_PROPERTY_RO(QAbstractSocket, peerAddress);
139     MO_ADD_PROPERTY_RO(QAbstractSocket, peerName);
140     MO_ADD_PROPERTY(QAbstractSocket, readBufferSize, setReadBufferSize);
141     MO_ADD_PROPERTY(QAbstractSocket, pauseMode, setPauseMode);
142     MO_ADD_PROPERTY_RO(QAbstractSocket, socketDescriptor);
143     MO_ADD_PROPERTY_RO(QAbstractSocket, socketType);
144     MO_ADD_PROPERTY_RO(QAbstractSocket, state);
145     MO_ADD_PROPERTY_RO(QAbstractSocket, error);
146 #ifndef QT_NO_NETWORKPROXY
147     MO_ADD_PROPERTY_RO(QAbstractSocket, proxy);
148 #endif
149     // FIXME: QAbstractSocket::setSocketOption() would be nice to have
150     // FIXME: QQAbstractSocket::socketOption() would be nice to have
151 
152     MO_ADD_METAOBJECT0(QHostAddress);
153     MO_ADD_PROPERTY_RO(QHostAddress, isLoopback);
154 #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
155     MO_ADD_PROPERTY_RO(QHostAddress, isMulticast);
156 #endif
157     MO_ADD_PROPERTY_RO(QHostAddress, isNull);
158     MO_ADD_PROPERTY_RO(QHostAddress, protocol);
159     MO_ADD_PROPERTY(QHostAddress, scopeId, setScopeId);
160 
161 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
162     MO_ADD_METAOBJECT0(QHstsPolicy);
163     MO_ADD_PROPERTY   (QHstsPolicy, expiry, setExpiry);
164     MO_ADD_PROPERTY_LD(QHstsPolicy, host, [](QHstsPolicy *policy) { return policy->host(); });
165     MO_ADD_PROPERTY   (QHstsPolicy, includesSubDomains, setIncludesSubDomains);
166 #endif
167 
168     MO_ADD_METAOBJECT1(QLocalSocket, QIODevice);
169     MO_ADD_PROPERTY_RO(QLocalSocket, error);
170     MO_ADD_PROPERTY_RO(QLocalSocket, fullServerName);
171     MO_ADD_PROPERTY_RO(QLocalSocket, isValid);
172     MO_ADD_PROPERTY_RO(QLocalSocket, serverName);
173     MO_ADD_PROPERTY_RO(QLocalSocket, socketDescriptor);
174     MO_ADD_PROPERTY_RO(QLocalSocket, state);
175 
176     MO_ADD_METAOBJECT1(QNetworkAccessManager, QObject);
177     MO_ADD_PROPERTY_RO(QNetworkAccessManager, activeConfiguration);
178     MO_ADD_PROPERTY_RO(QNetworkAccessManager, cache);
179     MO_ADD_PROPERTY   (QNetworkAccessManager, configuration, setConfiguration);
180     MO_ADD_PROPERTY_RO(QNetworkAccessManager, cookieJar);
181 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
182     MO_ADD_PROPERTY   (QNetworkAccessManager, isStrictTransportSecurityEnabled, setStrictTransportSecurityEnabled);
183 #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
184     MO_ADD_PROPERTY_RO(QNetworkAccessManager, isStrictTransportSecurityStoreEnabled);
185 #endif
186     MO_ADD_PROPERTY   (QNetworkAccessManager, proxy, setProxy);
187     MO_ADD_PROPERTY   (QNetworkAccessManager, redirectPolicy, setRedirectPolicy);
188     MO_ADD_PROPERTY_RO(QNetworkAccessManager, strictTransportSecurityHosts);
189 #endif
190     MO_ADD_PROPERTY_RO(QNetworkAccessManager, supportedSchemes);
191 
192 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
193     MO_ADD_METAOBJECT0(QNetworkAddressEntry);
194     MO_ADD_PROPERTY   (QNetworkAddressEntry, broadcast, setBroadcast);
195     MO_ADD_PROPERTY   (QNetworkAddressEntry, dnsEligibility, setDnsEligibility);
196     MO_ADD_PROPERTY   (QNetworkAddressEntry, ip, setIp);
197     MO_ADD_PROPERTY_RO(QNetworkAddressEntry, isLifetimeKnown);
198     MO_ADD_PROPERTY_RO(QNetworkAddressEntry, isPermanent);
199     MO_ADD_PROPERTY_RO(QNetworkAddressEntry, isTemporary);
200     MO_ADD_PROPERTY   (QNetworkAddressEntry, netmask, setNetmask);
201     //MO_ADD_PROPERTY_RO(QNetworkAddressEntry, preferredLifetime);
202     MO_ADD_PROPERTY   (QNetworkAddressEntry, prefixLength, setPrefixLength);
203     //MO_ADD_PROPERTY_RO(QNetworkAddressEntry, validityLifetime);
204 #endif
205 
206     MO_ADD_METAOBJECT0(QNetworkConfiguration);
207     MO_ADD_PROPERTY_RO(QNetworkConfiguration, bearerType);
208     MO_ADD_PROPERTY_RO(QNetworkConfiguration, bearerTypeFamily);
209     MO_ADD_PROPERTY_RO(QNetworkConfiguration, bearerTypeName);
210     MO_ADD_PROPERTY_RO(QNetworkConfiguration, children);
211 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
212     MO_ADD_PROPERTY_RO(QNetworkConfiguration, connectTimeout);
213 #endif
214     MO_ADD_PROPERTY_RO(QNetworkConfiguration, identifier);
215     MO_ADD_PROPERTY_RO(QNetworkConfiguration, isRoamingAvailable);
216     MO_ADD_PROPERTY_RO(QNetworkConfiguration, isValid);
217     MO_ADD_PROPERTY_RO(QNetworkConfiguration, name);
218     MO_ADD_PROPERTY_RO(QNetworkConfiguration, purpose);
219     MO_ADD_PROPERTY_RO(QNetworkConfiguration, state);
220     MO_ADD_PROPERTY_RO(QNetworkConfiguration, type);
221 
222     MO_ADD_METAOBJECT1(QNetworkConfigurationManager, QObject);
223     MO_ADD_PROPERTY_RO(QNetworkConfigurationManager, capabilities);
224     MO_ADD_PROPERTY_RO(QNetworkConfigurationManager, isOnline);
225 
226     MO_ADD_METAOBJECT0(QNetworkInterface);
227     MO_ADD_PROPERTY_RO(QNetworkInterface, addressEntries);
228     MO_ADD_PROPERTY_ST(QNetworkInterface, allAddresses);
229     MO_ADD_PROPERTY_ST(QNetworkInterface, allInterfaces);
230     MO_ADD_PROPERTY_RO(QNetworkInterface, flags);
231     MO_ADD_PROPERTY_RO(QNetworkInterface, hardwareAddress);
232     MO_ADD_PROPERTY_RO(QNetworkInterface, index);
233     MO_ADD_PROPERTY_RO(QNetworkInterface, isValid);
234 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
235     MO_ADD_PROPERTY_RO(QNetworkInterface, maximumTransmissionUnit);
236 #endif
237     MO_ADD_PROPERTY_RO(QNetworkInterface, name);
238 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
239     MO_ADD_PROPERTY_RO(QNetworkInterface, type);
240 #endif
241 
242     MO_ADD_METAOBJECT0(QNetworkProxy);
243     MO_ADD_PROPERTY_ST(QNetworkProxy, applicationProxy);
244     MO_ADD_PROPERTY   (QNetworkProxy, capabilities, setCapabilities);
245     MO_ADD_PROPERTY   (QNetworkProxy, hostName, setHostName);
246     MO_ADD_PROPERTY_RO(QNetworkProxy, isCachingProxy);
247     MO_ADD_PROPERTY_RO(QNetworkProxy, isTransparentProxy);
248     MO_ADD_PROPERTY   (QNetworkProxy, password, setPassword);
249     MO_ADD_PROPERTY   (QNetworkProxy, port, setPort);
250     //MO_ADD_PROPERTY_RO(QNetworkProxy, rawHeaderList);
251     MO_ADD_PROPERTY   (QNetworkProxy, type, setType);
252     MO_ADD_PROPERTY   (QNetworkProxy, user, setUser);
253 
254     MO_ADD_METAOBJECT1(QNetworkSession, QObject);
255     MO_ADD_PROPERTY_RO(QNetworkSession, activeTime);
256     MO_ADD_PROPERTY_RO(QNetworkSession, bytesReceived);
257     MO_ADD_PROPERTY_RO(QNetworkSession, bytesWritten);
258     MO_ADD_PROPERTY_RO(QNetworkSession, configuration);
259     MO_ADD_PROPERTY_RO(QNetworkSession, error);
260     MO_ADD_PROPERTY_RO(QNetworkSession, errorString);
261     MO_ADD_PROPERTY_RO(QNetworkSession, interface);
262     MO_ADD_PROPERTY_RO(QNetworkSession, isOpen);
263     MO_ADD_PROPERTY_RO(QNetworkSession, state);
264     MO_ADD_PROPERTY_RO(QNetworkSession, usagePolicies);
265 
266     MO_ADD_METAOBJECT1(QTcpServer, QObject);
267     MO_ADD_PROPERTY_RO(QTcpServer, isListening);
268     MO_ADD_PROPERTY(QTcpServer, maxPendingConnections, setMaxPendingConnections);
269     MO_ADD_PROPERTY_RO(QTcpServer, serverPort);
270     MO_ADD_PROPERTY_RO(QTcpServer, serverAddress);
271     MO_ADD_PROPERTY_RO(QTcpServer, socketDescriptor);
272     MO_ADD_PROPERTY_RO(QTcpServer, hasPendingConnections);
273     MO_ADD_PROPERTY_RO(QTcpServer, serverError);
274     MO_ADD_PROPERTY_RO(QTcpServer, errorString);
275 #ifndef QT_NO_NETWORKPROXY
276     MO_ADD_PROPERTY_RO(QTcpServer, proxy);
277 #endif
278 
279     MO_ADD_METAOBJECT1(QTcpSocket, QAbstractSocket);
280 
281 #ifndef QT_NO_SSL
282     MO_ADD_METAOBJECT0(QSslCertificate);
283     MO_ADD_PROPERTY_RO(QSslCertificate, effectiveDate);
284     MO_ADD_PROPERTY_RO(QSslCertificate, expiryDate);
285     MO_ADD_PROPERTY_RO(QSslCertificate, extensions);
286     MO_ADD_PROPERTY_RO(QSslCertificate, isBlacklisted);
287     MO_ADD_PROPERTY_RO(QSslCertificate, isNull);
288     MO_ADD_PROPERTY_RO(QSslCertificate, isSelfSigned);
289     MO_ADD_PROPERTY_RO(QSslCertificate, issuerInfoAttributes);
290     MO_ADD_PROPERTY_RO(QSslCertificate, publicKey);
291     MO_ADD_PROPERTY_RO(QSslCertificate, serialNumber);
292     MO_ADD_PROPERTY_RO(QSslCertificate, subjectInfoAttributes);
293     MO_ADD_PROPERTY_RO(QSslCertificate, version);
294 
295     MO_ADD_METAOBJECT0(QSslCertificateExtension);
296     MO_ADD_PROPERTY_RO(QSslCertificateExtension, isCritical);
297     MO_ADD_PROPERTY_RO(QSslCertificateExtension, isSupported);
298     MO_ADD_PROPERTY_RO(QSslCertificateExtension, name);
299     MO_ADD_PROPERTY_RO(QSslCertificateExtension, oid);
300     MO_ADD_PROPERTY_RO(QSslCertificateExtension, value);
301 
302     MO_ADD_METAOBJECT0(QSslCipher);
303     MO_ADD_PROPERTY_RO(QSslCipher, authenticationMethod);
304     MO_ADD_PROPERTY_RO(QSslCipher, encryptionMethod);
305     MO_ADD_PROPERTY_RO(QSslCipher, isNull);
306     MO_ADD_PROPERTY_RO(QSslCipher, keyExchangeMethod);
307     MO_ADD_PROPERTY_RO(QSslCipher, name);
308     MO_ADD_PROPERTY_RO(QSslCipher, protocol);
309     MO_ADD_PROPERTY_RO(QSslCipher, protocolString);
310     MO_ADD_PROPERTY_RO(QSslCipher, usedBits);
311 
312     MO_ADD_METAOBJECT0(QSslConfiguration);
313     MO_ADD_PROPERTY(QSslConfiguration, allowedNextProtocols, setAllowedNextProtocols);
314     MO_ADD_PROPERTY(QSslConfiguration, caCertificates, setCaCertificates);
315     MO_ADD_PROPERTY(QSslConfiguration, ciphers, setCiphers);
316     // TODO 5.5 ellipticCurves
317 #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
318     MO_ADD_PROPERTY_RO(QSslConfiguration, ephemeralServerKey);
319 #endif
320     MO_ADD_PROPERTY_RO(QSslConfiguration, isNull);
321     MO_ADD_PROPERTY(QSslConfiguration, localCertificate, setLocalCertificate);
322     MO_ADD_PROPERTY(QSslConfiguration, localCertificateChain, setLocalCertificateChain);
323     MO_ADD_PROPERTY_RO(QSslConfiguration, nextNegotiatedProtocol);
324     MO_ADD_PROPERTY_RO(QSslConfiguration, nextProtocolNegotiationStatus); // TODO enum lookup table
325     MO_ADD_PROPERTY_RO(QSslConfiguration, peerCertificate);
326     MO_ADD_PROPERTY_RO(QSslConfiguration, peerCertificateChain);
327     MO_ADD_PROPERTY(QSslConfiguration, peerVerifyDepth, setPeerVerifyDepth);
328     MO_ADD_PROPERTY(QSslConfiguration, peerVerifyMode, setPeerVerifyMode);
329     MO_ADD_PROPERTY(QSslConfiguration, privateKey, setPrivateKey);
330     MO_ADD_PROPERTY(QSslConfiguration, protocol, setProtocol);
331     MO_ADD_PROPERTY_RO(QSslConfiguration, sessionCipher);
332     MO_ADD_PROPERTY_RO(QSslConfiguration, sessionProtocol);
333     MO_ADD_PROPERTY(QSslConfiguration, sessionTicket, setSessionTicket);
334     MO_ADD_PROPERTY_RO(QSslConfiguration, sessionTicketLifeTimeHint);
335     MO_ADD_PROPERTY_ST(QSslConfiguration, systemCaCertificates);
336 
337     MO_ADD_METAOBJECT0(QSslKey);
338     MO_ADD_PROPERTY_RO(QSslKey, algorithm);
339     MO_ADD_PROPERTY_RO(QSslKey, isNull);
340     MO_ADD_PROPERTY_RO(QSslKey, length);
341     MO_ADD_PROPERTY_RO(QSslKey, type);
342 
343     MO_ADD_METAOBJECT1(QSslSocket, QTcpSocket);
344     MO_ADD_PROPERTY_RO(QSslSocket, isEncrypted);
345     MO_ADD_PROPERTY_RO(QSslSocket, localCertificate);
346     MO_ADD_PROPERTY_RO(QSslSocket, localCertificateChain);
347     MO_ADD_PROPERTY_RO(QSslSocket, mode);
348     MO_ADD_PROPERTY_RO(QSslSocket, peerCertificate);
349     MO_ADD_PROPERTY_RO(QSslSocket, peerCertificateChain);
350     MO_ADD_PROPERTY(QSslSocket, peerVerifyDepth, setPeerVerifyDepth);
351     MO_ADD_PROPERTY(QSslSocket, peerVerifyMode, setPeerVerifyMode);
352     MO_ADD_PROPERTY(QSslSocket, peerVerifyName, setPeerVerifyName);
353     MO_ADD_PROPERTY(QSslSocket, privateKey, setPrivateKey);
354     MO_ADD_PROPERTY_RO(QSslSocket, protocol);
355     MO_ADD_PROPERTY_RO(QSslSocket, sessionProtocol);
356     MO_ADD_PROPERTY_RO(QSslSocket, sessionCipher);
357     MO_ADD_PROPERTY(QSslSocket, sslConfiguration, setSslConfiguration);
358     MO_ADD_PROPERTY_RO(QSslSocket, sslErrors);
359 #endif // QT_NO_SSL
360 
361     MO_ADD_METAOBJECT1(QSocketNotifier, QObject);
362     MO_ADD_PROPERTY_RO(QSocketNotifier, socket);
363     MO_ADD_PROPERTY_RO(QSocketNotifier, type);
364     MO_ADD_PROPERTY(QSocketNotifier, isEnabled, setEnabled);
365 }
366 
367 #define E(x) { QAbstractSocket:: x, #x }
368 static const MetaEnum::Value<QAbstractSocket::PauseMode> socket_pause_mode_table[] = {
369     E(PauseNever),
370     E(PauseOnSslErrors),
371 };
372 #undef E
373 
374 #define E(x) { QNetworkAccessManager:: x, #x }
375 static const MetaEnum::Value<QNetworkAccessManager::NetworkAccessibility>
376 network_accessibility_table[] = {
377     E(UnknownAccessibility),
378     E(NotAccessible),
379     E(Accessible)
380 };
381 #undef E
382 
383 #ifndef QT_NO_SSL
384 #define E(x) { QSslSocket:: x, #x }
385 static const MetaEnum::Value<QSslSocket::SslMode> ssl_mode_table[] = {
386     E(UnencryptedMode),
387     E(SslClientMode),
388     E(SslServerMode)
389 };
390 #undef E
391 
392 #define E(x) { QSslSocket:: x, #x }
393 static const MetaEnum::Value<QSslSocket::PeerVerifyMode> ssl_peer_verify_mode_table[] = {
394     E(VerifyNone),
395     E(QueryPeer),
396     E(VerifyPeer),
397     E(AutoVerifyPeer)
398 };
399 #undef E
400 
401 #define E(x) { QSsl:: x, #x }
402 static const MetaEnum::Value<QSsl::KeyAlgorithm> ssl_key_algorithm_table[] = {
403     E(Opaque),
404     E(Rsa),
405     E(Dsa),
406     E(Ec)
407 };
408 #undef E
409 
410 #define E(x) { QSsl:: x, #x }
411 static const MetaEnum::Value<QSsl::KeyType> ssl_key_type_table[] = {
412     E(PrivateKey),
413     E(PublicKey)
414 };
415 #undef E
416 
417 #define E(x) { QSsl:: x, #x }
418 static const MetaEnum::Value<QSsl::SslProtocol> ssl_protocol_table[] = {
419     E(SslV3),
420     E(SslV2),
421     E(TlsV1_0),
422     E(TlsV1_1),
423     E(TlsV1_2),
424     E(AnyProtocol),
425     E(TlsV1SslV3),
426     E(SecureProtocols),
427     E(TlsV1_0OrLater),
428     E(TlsV1_1OrLater),
429     E(TlsV1_2OrLater),
430     E(UnknownProtocol)
431 };
432 #undef E
433 
sslCertificateToString(const QSslCertificate & cert)434 static QString sslCertificateToString(const QSslCertificate &cert)
435 {
436     if (cert.isNull())
437         return QStringLiteral("<null>");
438     return cert.digest().toHex();
439 }
440 
441 #endif // QT_NO_SSL
442 
443 #define E(x) { QNetworkConfiguration:: x, #x }
444 static const MetaEnum::Value<QNetworkConfiguration::BearerType> network_config_bearer_type_table[] = {
445     E(BearerUnknown),
446     E(BearerEthernet),
447     E(BearerWLAN),
448     E(Bearer2G),
449     E(Bearer3G),
450     E(Bearer4G),
451     E(BearerCDMA2000),
452     E(BearerWCDMA),
453     E(BearerHSPA),
454     E(BearerBluetooth),
455     E(BearerWiMAX),
456     E(BearerEVDO),
457     E(BearerLTE)
458 };
459 
460 static const MetaEnum::Value<QNetworkConfiguration::Purpose> network_config_purpose_table[] = {
461     E(UnknownPurpose),
462     E(PublicPurpose),
463     E(PrivatePurpose),
464     E(ServiceSpecificPurpose)
465 };
466 
467 static const MetaEnum::Value<QNetworkConfiguration::StateFlag> network_config_state_table[] = {
468     E(Undefined),
469     E(Defined),
470     E(Discovered),
471     E(Active)
472 };
473 
474 static const MetaEnum::Value<QNetworkConfiguration::Type> network_config_type_table[] = {
475     E(InternetAccessPoint),
476     E(ServiceNetwork),
477     E(UserChoice),
478     E(Invalid)
479 };
480 #undef E
481 
482 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
483 #define E(x) { QNetworkAddressEntry:: x, #x }
484 static const MetaEnum::Value<QNetworkAddressEntry::DnsEligibilityStatus> network_address_entry_dns_eligibility_table[] = {
485     E(DnsEligibilityUnknown),
486     E(DnsEligible),
487     E(DnsIneligible)
488 };
489 #undef E
490 #endif
491 
492 #define E(x) { QNetworkConfigurationManager:: x, #x }
493 static const MetaEnum::Value<QNetworkConfigurationManager::Capabilities> network_config_manager_capabilities_table[] = {
494     E(CanStartAndStopInterfaces),
495     E(DirectConnectionRouting),
496     E(SystemSessionSupport),
497     E(ApplicationLevelRoaming),
498     E(ForcedRoaming),
499     E(DataStatistics),
500     E(NetworkSessionRequired)
501 };
502 #undef E
503 
504 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
505 #define E(x) { QNetworkRequest:: x, #x }
506 static const MetaEnum::Value<QNetworkRequest::RedirectPolicy> network_redirect_policy_table[] = {
507     E(ManualRedirectPolicy),
508     E(NoLessSafeRedirectPolicy),
509     E(SameOriginRedirectPolicy),
510     E(UserVerifiedRedirectPolicy)
511 };
512 #undef E
513 #endif
514 
515 #define E(x) { QNetworkProxy:: x, #x }
516 static const MetaEnum::Value<QNetworkProxy::Capability> network_proxy_capabilitiy_table[] = {
517     E(TunnelingCapability),
518     E(ListeningCapability),
519     E(UdpTunnelingCapability),
520     E(CachingCapability),
521     E(HostNameLookupCapability),
522 #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
523     E(SctpTunnelingCapability),
524     E(SctpListeningCapability)
525 #endif
526 };
527 
528 static const MetaEnum::Value<QNetworkProxy::ProxyType> network_proxy_type_table[] = {
529     E(NoProxy),
530     E(DefaultProxy),
531     E(Socks5Proxy),
532     E(HttpProxy),
533     E(HttpCachingProxy),
534     E(FtpCachingProxy)
535 };
536 #undef E
537 
538 #define E(x) { QNetworkSession:: x, #x }
539 static const MetaEnum::Value<QNetworkSession::SessionError> network_session_error_table[] = {
540     E(UnknownSessionError),
541     E(SessionAbortedError),
542     E(RoamingError),
543     E(OperationNotSupportedError),
544     E(InvalidConfigurationError)
545 };
546 
547 static const MetaEnum::Value<QNetworkSession::State> network_session_state_table[] = {
548     E(Invalid),
549     E(NotAvailable),
550     E(Connecting),
551     E(Connected),
552     E(Closing),
553     E(Disconnected),
554     E(Roaming)
555 };
556 
557 static const MetaEnum::Value<QNetworkSession::UsagePolicies> network_session_usage_policy_table[] = {
558     E(NoPolicy),
559     E(NoBackgroundTrafficPolicy)
560 };
561 #undef E
562 
proxyToString(const QNetworkProxy & proxy)563 static QString proxyToString(const QNetworkProxy &proxy)
564 {
565     return VariantHandler::displayString(proxy.type());
566 }
567 
registerVariantHandler()568 void NetworkSupport::registerVariantHandler()
569 {
570     ER_REGISTER_FLAGS(QAbstractSocket, PauseModes, socket_pause_mode_table);
571     VariantHandler::registerStringConverter<QHostAddress>(std::mem_fn(&QHostAddress::toString));
572     ER_REGISTER_ENUM(QNetworkAccessManager, NetworkAccessibility, network_accessibility_table);
573 #ifndef QT_NO_SSL
574     ER_REGISTER_ENUM(QSslSocket, PeerVerifyMode, ssl_peer_verify_mode_table);
575     ER_REGISTER_ENUM(QSslSocket, SslMode, ssl_mode_table);
576     ER_REGISTER_ENUM(QSsl, KeyAlgorithm, ssl_key_algorithm_table);
577     ER_REGISTER_ENUM(QSsl, KeyType, ssl_key_type_table);
578     ER_REGISTER_ENUM(QSsl, SslProtocol, ssl_protocol_table);
579     VariantHandler::registerStringConverter<QSslCertificate>(sslCertificateToString);
580     VariantHandler::registerStringConverter<QSslCertificateExtension>(std::mem_fn(&QSslCertificateExtension::name));
581     VariantHandler::registerStringConverter<QSslCipher>(std::mem_fn(&QSslCipher::name));
582     VariantHandler::registerStringConverter<QSslError>(std::mem_fn(&QSslError::errorString));
583 #endif
584 
585 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
586     ER_REGISTER_ENUM(QNetworkAddressEntry, DnsEligibilityStatus, network_address_entry_dns_eligibility_table);
587 #endif
588 
589     ER_REGISTER_ENUM(QNetworkConfiguration, BearerType, network_config_bearer_type_table);
590     ER_REGISTER_ENUM(QNetworkConfiguration, Purpose, network_config_purpose_table);
591     ER_REGISTER_FLAGS(QNetworkConfiguration, StateFlags, network_config_state_table);
592     ER_REGISTER_ENUM(QNetworkConfiguration, Type, network_config_type_table);
593     VariantHandler::registerStringConverter<QNetworkConfiguration>(std::mem_fn(&QNetworkConfiguration::name));
594     ER_REGISTER_FLAGS(QNetworkConfigurationManager, Capabilities, network_config_manager_capabilities_table);
595 
596     VariantHandler::registerStringConverter<QNetworkInterface>(std::mem_fn(&QNetworkInterface::name));
597 
598 #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
599     ER_REGISTER_ENUM(QNetworkRequest, RedirectPolicy, network_redirect_policy_table);
600 #endif
601 
602     ER_REGISTER_FLAGS(QNetworkProxy, Capabilities, network_proxy_capabilitiy_table);
603     ER_REGISTER_ENUM(QNetworkProxy, ProxyType, network_proxy_type_table);
604     VariantHandler::registerStringConverter<QNetworkProxy>(proxyToString);
605 
606     ER_REGISTER_ENUM(QNetworkSession, SessionError, network_session_error_table);
607     ER_REGISTER_ENUM(QNetworkSession, State, network_session_state_table);
608     ER_REGISTER_FLAGS(QNetworkSession, UsagePolicies, network_session_usage_policy_table);
609 }
610 
NetworkSupportFactory(QObject * parent)611 NetworkSupportFactory::NetworkSupportFactory(QObject *parent)
612     : QObject(parent)
613 {
614 }
615