Qt 4.8
qnetworkaccessmanager.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qnetworkaccessmanager.h"
44 #include "qnetworkrequest.h"
45 #include "qnetworkreply.h"
46 #include "qnetworkreply_p.h"
47 #include "qnetworkcookie.h"
48 #include "qabstractnetworkcache.h"
49 
50 #include "QtNetwork/qnetworksession.h"
51 #include "QtNetwork/private/qsharednetworksession_p.h"
52 
60 
61 #include "QtCore/qbuffer.h"
62 #include "QtCore/qurl.h"
63 #include "QtCore/qvector.h"
64 #include "QtNetwork/private/qauthenticator_p.h"
65 #include "QtNetwork/qsslconfiguration.h"
66 #include "QtNetwork/qnetworkconfigmanager.h"
67 #include "QtNetwork/qhttpmultipart.h"
68 #include "qhttpmultipart_p.h"
69 
70 #include "qthread.h"
71 
73 
74 #ifndef QT_NO_HTTP
76 #endif // QT_NO_HTTP
78 #ifndef QT_NO_FTP
80 #endif // QT_NO_FTP
81 
82 #ifdef QT_BUILD_INTERNAL
83 Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend)
84 #endif
85 
86 static void ensureInitialized()
87 {
88 #ifndef QT_NO_HTTP
89  (void) httpBackend();
90 #endif // QT_NO_HTTP
91 
92 #ifndef QT_NO_FTP
93  (void) ftpBackend();
94 #endif
95 
96 #ifdef QT_BUILD_INTERNAL
97  (void) debugpipeBackend();
98 #endif
99 
100  // leave this one last since it will query the special QAbstractFileEngines
101  (void) fileBackend();
102 }
103 
376  : QObject(*new QNetworkAccessManagerPrivate, parent)
377 {
379 
380  qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
381 }
382 
391 {
392 #ifndef QT_NO_NETWORKPROXY
393  delete d_func()->proxyFactory;
394 #endif
395 
396  // Delete the QNetworkReply children first.
397  // Else a QAbstractNetworkCache might get deleted in ~QObject
398  // before a QNetworkReply that accesses the QAbstractNetworkCache
399  // object in its destructor.
400  qDeleteAll(findChildren<QNetworkReply *>());
401  // The other children will be deleted in this ~QObject
402  // FIXME instead of this "hack" make the QNetworkReplyImpl
403  // properly watch the cache deletion, e.g. via a QWeakPointer.
404 }
405 
406 #ifndef QT_NO_NETWORKPROXY
407 
415 {
416  return d_func()->proxy;
417 }
418 
434 {
436  delete d->proxyFactory;
437  d->proxy = proxy;
438  d->proxyFactory = 0;
439 }
440 
454 {
455  return d_func()->proxyFactory;
456 }
457 
491 {
493  delete d->proxyFactory;
494  d->proxyFactory = factory;
495  d->proxy = QNetworkProxy();
496 }
497 #endif
498 
510 {
511  Q_D(const QNetworkAccessManager);
512  return d->networkCache;
513 }
514 
535 {
537  if (d->networkCache != cache) {
538  delete d->networkCache;
539  d->networkCache = cache;
540  if (d->networkCache)
541  d->networkCache->setParent(this);
542  }
543 }
544 
553 {
554  Q_D(const QNetworkAccessManager);
555  if (!d->cookieJar)
556  d->createCookieJar();
557  return d->cookieJar;
558 }
559 
590 {
592  d->cookieJarCreated = true;
593  if (d->cookieJar != cookieJar) {
594  if (d->cookieJar && d->cookieJar->parent() == this)
595  delete d->cookieJar;
596  d->cookieJar = cookieJar;
597  if (thread() == cookieJar->thread())
598  d->cookieJar->setParent(this);
599  }
600 }
601 
609 {
610  return d_func()->postProcess(createRequest(QNetworkAccessManager::HeadOperation, request));
611 }
612 
624 {
625  return d_func()->postProcess(createRequest(QNetworkAccessManager::GetOperation, request));
626 }
627 
643 {
644  return d_func()->postProcess(createRequest(QNetworkAccessManager::PostOperation, request, data));
645 }
646 
657 {
658  QBuffer *buffer = new QBuffer;
659  buffer->setData(data);
660  buffer->open(QIODevice::ReadOnly);
661 
662  QNetworkReply *reply = post(request, buffer);
663  buffer->setParent(reply);
664  return reply;
665 }
666 
683 {
684  QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
685  QIODevice *device = multiPart->d_func()->device;
686  QNetworkReply *reply = post(newRequest, device);
687  return reply;
688 }
689 
706 {
707  QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
708  QIODevice *device = multiPart->d_func()->device;
709  QNetworkReply *reply = put(newRequest, device);
710  return reply;
711 }
712 
733 {
734  return d_func()->postProcess(createRequest(QNetworkAccessManager::PutOperation, request, data));
735 }
736 
747 {
748  QBuffer *buffer = new QBuffer;
749  buffer->setData(data);
750  buffer->open(QIODevice::ReadOnly);
751 
752  QNetworkReply *reply = put(request, buffer);
753  buffer->setParent(reply);
754  return reply;
755 }
756 
771 {
772  return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request));
773 }
774 
775 #ifndef QT_NO_BEARERMANAGEMENT
776 
804 {
805  d_func()->createSession(config);
806 }
807 
820 {
821  Q_D(const QNetworkAccessManager);
822 
823  QSharedPointer<QNetworkSession> session(d->getNetworkSession());
824  if (session)
825  return session->configuration();
826  else
827  return QNetworkConfiguration();
828 }
829 
849 {
850  Q_D(const QNetworkAccessManager);
851 
852  QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
853  if (networkSession) {
855 
856  return manager.configurationFromIdentifier(
857  networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString());
858  } else {
859  return QNetworkConfiguration();
860  }
861 }
862 
874 {
876 
877  if (d->networkAccessible != accessible) {
879  d->networkAccessible = accessible;
881  if (previous != current)
883  }
884 }
885 
895 {
896  Q_D(const QNetworkAccessManager);
897 
898  QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
899  if (networkSession) {
900  // d->online holds online/offline state of this network session.
901  if (d->online)
902  return d->networkAccessible;
903  else
904  return NotAccessible;
905  } else {
906  // Network accessibility is either disabled or unknown.
907  return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility;
908  }
909 }
910 
912 {
913  if (networkSessionStrongRef)
914  return networkSessionStrongRef;
915  return networkSessionWeakRef.toStrongRef();
916 }
917 
918 #endif // QT_NO_BEARERMANAGEMENT
919 
943 {
944  QNetworkRequest newRequest(request);
946  return d_func()->postProcess(createRequest(QNetworkAccessManager::CustomOperation, newRequest, data));
947 }
948 
963  const QNetworkRequest &req,
964  QIODevice *outgoingData)
965 {
967 
968  bool isLocalFile = req.url().isLocalFile();
969  QString scheme = req.url().scheme().toLower();
970 
971  // fast path for GET on file:// URLs
972  // The QNetworkAccessFileBackend will right now only be used for PUT
974  && (isLocalFile || scheme == QLatin1String("qrc"))) {
975  return new QNetworkReplyFileImpl(this, req, op);
976  }
977 
979  && scheme == QLatin1String("data")) {
980  return new QNetworkReplyDataImpl(this, req, op);
981  }
982 
983  // A request with QNetworkRequest::AlwaysCache does not need any bearer management
988  if (mode == QNetworkRequest::AlwaysCache
991  // FIXME Implement a QNetworkReplyCacheImpl instead, see QTBUG-15106
992  QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
993  QNetworkReplyImplPrivate *priv = reply->d_func();
994  priv->manager = this;
995  priv->backend = new QNetworkAccessCacheBackend();
996  priv->backend->manager = this->d_func();
997  priv->backend->setParent(reply);
998  priv->backend->reply = priv;
999  priv->setup(op, req, outgoingData);
1000  return reply;
1001  }
1002 
1003 #ifndef QT_NO_BEARERMANAGEMENT
1004  // Return a disabled network reply if network access is disabled.
1005  // Except if the scheme is empty or file://.
1006  if (!d->networkAccessible && !isLocalFile) {
1007  return new QDisabledNetworkReply(this, req, op);
1008  }
1009 
1010  if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.isEmpty())) {
1012  if (!d->networkConfiguration.isEmpty()) {
1013  d->createSession(manager.configurationFromIdentifier(d->networkConfiguration));
1014  } else {
1016  d->createSession(manager.defaultConfiguration());
1017  else
1018  d->initializeSession = false;
1019  }
1020  }
1021 #endif
1022 
1023  QNetworkRequest request = req;
1025  outgoingData && !outgoingData->isSequential()) {
1026  // request has no Content-Length
1027  // but the data that is outgoing is random-access
1028  request.setHeader(QNetworkRequest::ContentLengthHeader, outgoingData->size());
1029  }
1030 
1031  if (static_cast<QNetworkRequest::LoadControl>
1034  if (d->cookieJar) {
1035  QList<QNetworkCookie> cookies = d->cookieJar->cookiesForUrl(request.url());
1036  if (!cookies.isEmpty())
1038  }
1039  }
1040 
1041  // first step: create the reply
1042  QUrl url = request.url();
1043  QNetworkReplyImpl *reply = new QNetworkReplyImpl(this);
1044 #ifndef QT_NO_BEARERMANAGEMENT
1045  if (!isLocalFile) {
1047  reply, SLOT(_q_networkSessionConnected()));
1048  }
1049 #endif
1050  QNetworkReplyImplPrivate *priv = reply->d_func();
1051  priv->manager = this;
1052 
1053  // second step: fetch cached credentials
1054  // This is not done for the time being, we should use signal emissions to request
1055  // the credentials from cache.
1056 
1057  // third step: find a backend
1058  priv->backend = d->findBackend(op, request);
1059 
1060  if (priv->backend) {
1061  priv->backend->setParent(reply);
1062  priv->backend->reply = priv;
1063  }
1064 
1065 #ifndef QT_NO_OPENSSL
1066  reply->setSslConfiguration(request.sslConfiguration());
1067 #endif
1068 
1069  // fourth step: setup the reply
1070  priv->setup(op, request, outgoingData);
1071 
1072  return reply;
1073 }
1074 
1076 {
1078 
1079  QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
1080  if (reply)
1081  emit q->finished(reply);
1082 
1083 #ifndef QT_NO_BEARERMANAGEMENT
1084  // If there are no active requests, release our reference to the network session.
1085  // It will not be destroyed immediately, but rather when the connection cache is flushed
1086  // after 2 minutes.
1087  activeReplyCount--;
1088  if (networkSessionStrongRef && activeReplyCount == 0)
1089  networkSessionStrongRef.clear();
1090 #endif
1091 }
1092 
1094 {
1095 #ifndef QT_NO_OPENSSL
1097  QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
1098  if (reply)
1099  emit q->sslErrors(reply, errors);
1100 #else
1101  Q_UNUSED(errors);
1102 #endif
1103 }
1104 
1106 {
1109  q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished()));
1110 #ifndef QT_NO_OPENSSL
1111  /* In case we're compiled without SSL support, we don't have this signal and we need to
1112  * avoid getting a connection error. */
1113  q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>)));
1114 #endif
1115 #ifndef QT_NO_BEARERMANAGEMENT
1116  activeReplyCount++;
1117 #endif
1118 
1119  return reply;
1120 }
1121 
1123 {
1124  if (!cookieJarCreated) {
1125  // keep the ugly hack in here
1126  QNetworkAccessManagerPrivate *that = const_cast<QNetworkAccessManagerPrivate *>(this);
1127  that->cookieJar = new QNetworkCookieJar(that->q_func());
1128  that->cookieJarCreated = true;
1129  }
1130 }
1131 
1133  QAuthenticator *authenticator)
1134 {
1136 
1137  // FIXME: Add support for domains (i.e., the leading path)
1138  QUrl url = backend->reply->url;
1139 
1140  // don't try the cache for the same URL twice in a row
1141  // being called twice for the same URL means the authentication failed
1142  // also called when last URL is empty, e.g. on first call
1143  if ((static_cast<QNetworkRequest::LoadControl>
1145  && (backend->reply->urlForLastAuthentication.isEmpty()
1146  || url != backend->reply->urlForLastAuthentication)) {
1147  // if credentials are included in the url, then use them
1148  if (!url.userName().isEmpty()
1149  && !url.password().isEmpty()) {
1150  authenticator->setUser(url.userName());
1151  authenticator->setPassword(url.password());
1152  backend->reply->urlForLastAuthentication = url;
1153  authenticationManager->cacheCredentials(url, authenticator);
1154  return;
1155  }
1156 
1157  QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedCredentials(url, authenticator);
1158  if (!cred.isNull()) {
1159  authenticator->setUser(cred.user);
1160  authenticator->setPassword(cred.password);
1161  backend->reply->urlForLastAuthentication = url;
1162  return;
1163  }
1164  }
1165 
1166  // if we emit a signal here in synchronous mode, the user might spin
1167  // an event loop, which might recurse and lead to problems
1168  if (backend->isSynchronous())
1169  return;
1170 
1171  backend->reply->urlForLastAuthentication = url;
1172  emit q->authenticationRequired(backend->reply->q_func(), authenticator);
1173  authenticationManager->cacheCredentials(url, authenticator);
1174 }
1175 
1176 #ifndef QT_NO_NETWORKPROXY
1178  const QNetworkProxy &proxy,
1179  QAuthenticator *authenticator)
1180 {
1183  if (proxy != backend->reply->lastProxyAuthentication && (!priv || !priv->hasFailed)) {
1184  QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedProxyCredentials(proxy);
1185  if (!cred.isNull()) {
1186  authenticator->setUser(cred.user);
1187  authenticator->setPassword(cred.password);
1188  return;
1189  }
1190  }
1191 
1192  // if we emit a signal here in synchronous mode, the user might spin
1193  // an event loop, which might recurse and lead to problems
1194  if (backend->isSynchronous())
1195  return;
1196 
1197  backend->reply->lastProxyAuthentication = proxy;
1198  emit q->proxyAuthenticationRequired(proxy, authenticator);
1199  authenticationManager->cacheProxyCredentials(proxy, authenticator);
1200 }
1201 
1203 {
1204  QList<QNetworkProxy> proxies;
1205  if (proxyFactory) {
1206  proxies = proxyFactory->queryProxy(query);
1207  if (proxies.isEmpty()) {
1208  qWarning("QNetworkAccessManager: factory %p has returned an empty result set",
1209  proxyFactory);
1210  proxies << QNetworkProxy::NoProxy;
1211  }
1212  } else if (proxy.type() == QNetworkProxy::DefaultProxy) {
1213  // no proxy set, query the application
1215  } else {
1216  proxies << proxy;
1217  }
1218 
1219  return proxies;
1220 }
1221 #endif
1222 
1224 {
1225  manager->d_func()->objectCache.clear();
1226  manager->d_func()->authenticationManager->clearCache();
1227 
1228  if (manager->d_func()->httpThread) {
1229  // The thread will deleteLater() itself from its finished() signal
1230  manager->d_func()->httpThread->quit();
1231  manager->d_func()->httpThread->wait(5000);
1232  manager->d_func()->httpThread = 0;
1233  }
1234 }
1235 
1237 {
1238  if (httpThread) {
1239  // The thread will deleteLater() itself from its finished() signal
1240  httpThread->quit();
1241  httpThread->wait(5000);
1242  httpThread = 0;
1243  }
1244 }
1245 
1246 #ifndef QT_NO_BEARERMANAGEMENT
1248 {
1250 
1251  initializeSession = false;
1252 
1253  //resurrect weak ref if possible
1254  networkSessionStrongRef = networkSessionWeakRef.toStrongRef();
1255 
1257  if (config.isValid())
1258  newSession = QSharedNetworkSessionManager::getSession(config);
1259 
1260  if (networkSessionStrongRef) {
1261  //do nothing if new and old session are the same
1262  if (networkSessionStrongRef == newSession)
1263  return;
1264  //disconnect from old session
1265  QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
1266  QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
1267  QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)),
1268  q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
1269  }
1270 
1271  //switch to new session (null if config was invalid)
1272  networkSessionStrongRef = newSession;
1273  networkSessionWeakRef = networkSessionStrongRef.toWeakRef();
1274 
1275  if (!networkSessionStrongRef) {
1276  online = false;
1277 
1279  emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
1280  else
1281  emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);
1282 
1283  return;
1284  }
1285 
1286  //connect to new session
1287  QObject::connect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()), Qt::QueuedConnection);
1288  //QueuedConnection is used to avoid deleting the networkSession inside its closed signal
1289  QObject::connect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()), Qt::QueuedConnection);
1290  QObject::connect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)),
1291  q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), Qt::QueuedConnection);
1292 
1293  _q_networkSessionStateChanged(networkSessionStrongRef->state());
1294 }
1295 
1297 {
1299  QSharedPointer<QNetworkSession> networkSession(getNetworkSession());
1300  if (networkSession) {
1301  networkConfiguration = networkSession->configuration().identifier();
1302 
1303  //disconnect from old session
1304  QObject::disconnect(networkSession.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
1305  QObject::disconnect(networkSession.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
1306  QObject::disconnect(networkSession.data(), SIGNAL(stateChanged(QNetworkSession::State)),
1307  q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
1308  networkSessionStrongRef.clear();
1309  networkSessionWeakRef.clear();
1310  }
1311 }
1312 
1314 {
1316 
1317  //Do not emit the networkSessionConnected signal here, except for roaming -> connected
1318  //transition, otherwise it is emitted twice in a row when opening a connection.
1319  if (state == QNetworkSession::Connected && lastSessionState == QNetworkSession::Roaming)
1320  emit q->networkSessionConnected();
1321  lastSessionState = state;
1322 
1323  if (online) {
1324  if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
1325  online = false;
1326  emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
1327  }
1328  } else {
1329  if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
1330  online = true;
1331  emit q->networkAccessibleChanged(networkAccessible);
1332  }
1333  }
1334 }
1335 #endif // QT_NO_BEARERMANAGEMENT
1336 
1338 {
1339  // copy the request, we probably need to add some headers
1340  QNetworkRequest newRequest(request);
1341 
1342  // add Content-Type header if not there already
1344  QByteArray contentType;
1345  contentType.reserve(34 + multiPart->d_func()->boundary.count());
1346  contentType += "multipart/";
1347  switch (multiPart->d_func()->contentType) {
1349  contentType += "related";
1350  break;
1352  contentType += "form-data";
1353  break;
1355  contentType += "alternative";
1356  break;
1357  default:
1358  contentType += "mixed";
1359  break;
1360  }
1361  // putting the boundary into quotes, recommended in RFC 2046 section 5.1.1
1362  contentType += "; boundary=\"" + multiPart->d_func()->boundary + "\"";
1363  newRequest.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(contentType));
1364  }
1365 
1366  // add MIME-Version header if not there already (we must include the header
1367  // if the message conforms to RFC 2045, see section 4 of that RFC)
1368  QByteArray mimeHeader("MIME-Version");
1369  if (!request.hasRawHeader(mimeHeader))
1370  newRequest.setRawHeader(mimeHeader, QByteArray("1.0"));
1371 
1372  QIODevice *device = multiPart->d_func()->device;
1373  if (!device->isReadable()) {
1374  if (!device->isOpen()) {
1375  if (!device->open(QIODevice::ReadOnly))
1376  qWarning("could not open device for reading");
1377  } else {
1378  qWarning("device is not readable");
1379  }
1380  }
1381 
1382  return newRequest;
1383 }
1384 
1386 
1387 #include "moc_qnetworkaccessmanager.cpp"
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setCookieJar(QNetworkCookieJar *cookieJar)
Sets the manager&#39;s cookie jar to be the cookieJar specified.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
double d
Definition: qnumeric_p.h:62
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
void _q_replySslErrors(const QList< QSslError > &errors)
QNetworkAccessManager(QObject *parent=0)
Constructs a QNetworkAccessManager object that is the center of the Network Access API and sets paren...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QNetworkReply * head(const QNetworkRequest &request)
Posts a request to obtain the network headers for request and returns a new QNetworkReply object whic...
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the raw header headerName is present in this network request.
QSslConfiguration sslConfiguration() const
Returns this network request&#39;s SSL configuration.
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
Definition: qiodevice.cpp:544
void networkSessionConnected()
This signal is emitted when the status of the network session changes into a usable (Connected) state...
QNetworkReply * put(const QNetworkRequest &request, QIODevice *data)
Uploads the contents of data to the destination request and returnes a new QNetworkReply object that ...
~QNetworkAccessManager()
Destroys the QNetworkAccessManager object and frees up any resources.
QPointer< QNetworkAccessManager > manager
QNetworkProxyFactory * proxyFactory() const
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition: qbuffer.cpp:315
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
QNetworkProxy proxy() const
Returns the QNetworkProxy that the requests sent using this QNetworkAccessManager object will use...
#define SLOT(a)
Definition: qobjectdefs.h:226
void setConfiguration(const QNetworkConfiguration &config)
Sets the network configuration that will be used when creating the QNetworkSession{network session} t...
QNetworkReply * deleteResource(const QNetworkRequest &request)
Sends a request to delete the resource identified by the URL of request.
QWeakPointer< T > toWeakRef() const
Returns a weak reference object that shares the pointer referenced by this object.
virtual QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query=QNetworkProxyQuery())=0
This function takes the query request, query, examines the details of the type of socket or request a...
Operation
Indicates the operation this reply is processing.
State
This enum describes the connectivity state of the session.
void proxyAuthenticationRequired(QNetworkAccessBackend *backend, const QNetworkProxy &proxy, QAuthenticator *authenticator)
QNetworkConfiguration activeConfiguration() const
Returns the current active network configuration.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
NetworkAccessibility networkAccessible() const
QNetworkAccessBackend * backend
The QNetworkConfigurationManager class manages the network configurations provided by the system...
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QNetworkProxyFactory class provides fine-grained proxy selection.
void createSession(const QNetworkConfiguration &config)
void setUser(const QString &user)
Sets the user used for authentication.
QNetworkConfigurationManager::Capabilities capabilities() const
Returns the capabilities supported by the current platform.
QSharedPointer< QNetworkSession > getNetworkSession() const
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void finished(QNetworkReply *reply)
This signal is emitted whenever a pending network reply is finished.
#define Q_D(Class)
Definition: qglobal.h:2482
void setNetworkAccessible(NetworkAccessibility accessible)
Overrides the reported network accessibility.
static QList< QNetworkProxy > proxyForQuery(const QNetworkProxyQuery &query)
This function takes the query request, query, examines the details of the type of socket or request a...
QNetworkRequest prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart)
NetworkAccessibility
Indicates whether the network is accessible via this network access manager.
void setAttribute(Attribute code, const QVariant &value)
Sets the attribute associated with code code to be value value.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QUrl url() const
Returns the URL this network request is referring to.
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
#define Q_Q(Class)
Definition: qglobal.h:2483
QNetworkAccessManagerPrivate * manager
bool isLocalFile() const
Returns true if this URL is pointing to a local file path.
Definition: qurl.cpp:6453
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QByteArray boundary() const
returns the boundary.
QNetworkConfiguration configuration() const
Returns the QNetworkConfiguration that this network session object is based on.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool isValid() const
Returns true if this QNetworkConfiguration object is valid.
The QNetworkProxy class provides a network layer proxy.
void setProxyFactory(QNetworkProxyFactory *factory)
Sets the proxy factory for this class to be factory.
The QNetworkConfiguration class provides an abstraction of one or more access point configurations...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QNetworkReplyImplPrivate * reply
void setCache(QAbstractNetworkCache *cache)
Sets the manager&#39;s network cache to be the cache specified.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static void ensureInitialized()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QAbstractNetworkCache * cache() const
Returns the cache that is used to store data obtained from the network.
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers...
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
The QNetworkAccessManager class allows the application to send network requests and receive replies...
The QAuthenticator class provides an authentication object.
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
Definition: qnetworkproxy.h:60
T * data() const
Returns the value of the pointer referenced by this object.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.
QString userName() const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4667
static Q_AUTOTEST_EXPORT void clearCache(QNetworkAccessManager *manager)
void setSslConfiguration(const QSslConfiguration &configuration)
Sets the SSL configuration for the network connection associated with this request, if possible, to be that of config.
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QString identifier() const
Returns the unique and platform specific identifier for this network configuration; otherwise an empt...
QNetworkConfiguration defaultConfiguration() const
Returns the default configuration to be used.
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
QNetworkRequest request() const
static void setManager(QNetworkReply *reply, QNetworkAccessManager *manager)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QNetworkReply * postProcess(QNetworkReply *reply)
static const QMetaObjectPrivate * priv(const uint *data)
if(void) toggleToolbarShown
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP. ...
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
void authenticationRequired(QNetworkAccessBackend *backend, QAuthenticator *authenticator)
void setProxy(const QNetworkProxy &proxy)
Sets the proxy to be used in future requests to be proxy.
void _q_networkSessionStateChanged(QNetworkSession::State state)
QNetworkConfiguration configurationFromIdentifier(const QString &identifier) const
Returns the QNetworkConfiguration for identifier; otherwise returns an invalid QNetworkConfiguration...
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply ob...
CacheLoadControl
Controls the caching mechanism of QNetworkAccessManager.
void sslErrors(QNetworkReply *reply, const QList< QSslError > &errors)
This signal is emitted if the SSL/TLS session encountered errors during the set up, including certificate verification errors.
void setPassword(const QString &password)
Sets the password used for authentication.
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=0)
Returns a new QNetworkReply object to handle the operation op and request req.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query)
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
static QSharedPointer< QNetworkSession > getSession(QNetworkConfiguration config)
QNetworkConfiguration configuration() const
Returns the network configuration that will be used to create the QNetworkSession{network session} wh...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QNetworkReply * sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data=0)
Sends a custom request to the server identified by the URL of request.
QString password() const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4754
QNetworkCookieJar * cookieJar() const
Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cook...
void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible)
This signal is emitted when the value of the networkAccessible property changes.
The QAbstractNetworkCache class provides the interface for cache implementations. ...