1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 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 The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef QNETWORKACCESSMANAGER_P_H 43 #define QNETWORKACCESSMANAGER_P_H 44 45 // 46 // W A R N I N G 47 // ------------- 48 // 49 // This file is not part of the Qt API. It exists for the convenience 50 // of the Network Access API. This header file may change from 51 // version to version without notice, or even be removed. 52 // 53 // We mean it. 54 // 55 56 #include "qnetworkaccessmanager.h" 57 #include "qnetworkaccesscache_p.h" 58 #include "qnetworkaccessbackend_p.h" 59 #include "private/qobject_p.h" 60 #include "QtNetwork/qnetworkproxy.h" 61 #include "QtNetwork/qnetworksession.h" 62 #include "qnetworkaccessauthenticationmanager_p.h" 63 64 QT_BEGIN_NAMESPACE 65 66 class QAuthenticator; 67 class QAbstractNetworkCache; 68 class QNetworkAuthenticationCredential; 69 class QNetworkCookieJar; 70 71 class QNetworkAccessManagerPrivate: public QObjectPrivate 72 { 73 public: QNetworkAccessManagerPrivate()74 QNetworkAccessManagerPrivate() 75 : networkCache(0), cookieJar(0), 76 httpThread(0), 77 #ifndef QT_NO_NETWORKPROXY 78 proxyFactory(0), 79 #endif 80 #ifndef QT_NO_BEARERMANAGEMENT 81 lastSessionState(QNetworkSession::Invalid), 82 networkAccessible(QNetworkAccessManager::Accessible), 83 activeReplyCount(0), 84 online(false), 85 initializeSession(true), 86 #endif 87 cookieJarCreated(false), 88 authenticationManager(new QNetworkAccessAuthenticationManager) 89 { } 90 ~QNetworkAccessManagerPrivate(); 91 92 void _q_replyFinished(); 93 void _q_replySslErrors(const QList<QSslError> &errors); 94 QNetworkReply *postProcess(QNetworkReply *reply); 95 void createCookieJar() const; 96 97 void authenticationRequired(QNetworkAccessBackend *backend, QAuthenticator *authenticator); 98 void cacheCredentials(const QUrl &url, const QAuthenticator *auth); 99 QNetworkAuthenticationCredential *fetchCachedCredentials(const QUrl &url, 100 const QAuthenticator *auth = 0); 101 102 #ifndef QT_NO_NETWORKPROXY 103 void proxyAuthenticationRequired(QNetworkAccessBackend *backend, const QNetworkProxy &proxy, 104 QAuthenticator *authenticator); 105 void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth); 106 QNetworkAuthenticationCredential *fetchCachedProxyCredentials(const QNetworkProxy &proxy, 107 const QAuthenticator *auth = 0); 108 QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query); 109 #endif 110 111 QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request); 112 113 #ifndef QT_NO_BEARERMANAGEMENT 114 void createSession(const QNetworkConfiguration &config); 115 QSharedPointer<QNetworkSession> getNetworkSession() const; 116 117 void _q_networkSessionClosed(); 118 void _q_networkSessionNewConfigurationActivated(); 119 void _q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &config, 120 bool isSeamless); 121 void _q_networkSessionStateChanged(QNetworkSession::State state); 122 #endif 123 124 QNetworkRequest prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart); 125 126 // this is the cache for storing downloaded files 127 QAbstractNetworkCache *networkCache; 128 129 QNetworkCookieJar *cookieJar; 130 131 QThread *httpThread; 132 133 134 #ifndef QT_NO_NETWORKPROXY 135 QNetworkProxy proxy; 136 QNetworkProxyFactory *proxyFactory; 137 #endif 138 139 #ifndef QT_NO_BEARERMANAGEMENT 140 QSharedPointer<QNetworkSession> networkSessionStrongRef; 141 QWeakPointer<QNetworkSession> networkSessionWeakRef; 142 QNetworkSession::State lastSessionState; 143 QString networkConfiguration; 144 QNetworkAccessManager::NetworkAccessibility networkAccessible; 145 int activeReplyCount; 146 bool online; 147 bool initializeSession; 148 #endif 149 150 bool cookieJarCreated; 151 152 // The cache with authorization data: 153 QSharedPointer<QNetworkAccessAuthenticationManager> authenticationManager; 154 155 // this cache can be used by individual backends to cache e.g. their TCP connections to a server 156 // and use the connections for multiple requests. 157 QNetworkAccessCache objectCache; getObjectCache(QNetworkAccessBackend * backend)158 static inline QNetworkAccessCache *getObjectCache(QNetworkAccessBackend *backend) 159 { return &backend->manager->objectCache; } 160 Q_AUTOTEST_EXPORT static void clearCache(QNetworkAccessManager *manager); 161 162 Q_DECLARE_PUBLIC(QNetworkAccessManager) 163 }; 164 165 QT_END_NAMESPACE 166 167 #endif 168