50 #include "QtNetwork/qnetworksession.h" 51 #include "QtNetwork/private/qsharednetworksession_p.h" 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" 82 #ifdef QT_BUILD_INTERNAL 83 Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend)
96 #ifdef QT_BUILD_INTERNAL 97 (void) debugpipeBackend();
101 (void) fileBackend();
380 qRegisterMetaType<QNetworkReply::NetworkError>(
"QNetworkReply::NetworkError");
392 #ifndef QT_NO_NETWORKPROXY 393 delete d_func()->proxyFactory;
406 #ifndef QT_NO_NETWORKPROXY 416 return d_func()->proxy;
436 delete d->proxyFactory;
455 return d_func()->proxyFactory;
493 delete d->proxyFactory;
494 d->proxyFactory = factory;
512 return d->networkCache;
537 if (
d->networkCache != cache) {
538 delete d->networkCache;
541 d->networkCache->setParent(
this);
556 d->createCookieJar();
592 d->cookieJarCreated =
true;
593 if (
d->cookieJar != cookieJar) {
594 if (
d->cookieJar &&
d->cookieJar->parent() ==
this)
596 d->cookieJar = cookieJar;
598 d->cookieJar->setParent(
this);
684 QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
685 QIODevice *device = multiPart->d_func()->device;
707 QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
708 QIODevice *device = multiPart->d_func()->device;
775 #ifndef QT_NO_BEARERMANAGEMENT 805 d_func()->createSession(config);
853 if (networkSession) {
857 networkSession->sessionProperty(
QLatin1String(
"ActiveConfiguration")).toString());
877 if (
d->networkAccessible != accessible) {
879 d->networkAccessible = accessible;
881 if (previous != current)
899 if (networkSession) {
902 return d->networkAccessible;
913 if (networkSessionStrongRef)
914 return networkSessionStrongRef;
915 return networkSessionWeakRef.toStrongRef();
918 #endif // QT_NO_BEARERMANAGEMENT 999 priv->
setup(op, req, outgoingData);
1003 #ifndef QT_NO_BEARERMANAGEMENT 1006 if (!
d->networkAccessible && !isLocalFile) {
1010 if (!
d->networkSessionStrongRef && (
d->initializeSession || !
d->networkConfiguration.isEmpty())) {
1012 if (!
d->networkConfiguration.isEmpty()) {
1018 d->initializeSession =
false;
1031 if (static_cast<QNetworkRequest::LoadControl>
1044 #ifndef QT_NO_BEARERMANAGEMENT 1047 reply,
SLOT(_q_networkSessionConnected()));
1058 priv->
backend =
d->findBackend(op, request);
1065 #ifndef QT_NO_OPENSSL 1070 priv->
setup(op, request, outgoingData);
1081 emit q->finished(reply);
1083 #ifndef QT_NO_BEARERMANAGEMENT 1088 if (networkSessionStrongRef && activeReplyCount == 0)
1089 networkSessionStrongRef.clear();
1095 #ifndef QT_NO_OPENSSL 1099 emit q->sslErrors(reply, errors);
1110 #ifndef QT_NO_OPENSSL 1115 #ifndef QT_NO_BEARERMANAGEMENT 1124 if (!cookieJarCreated) {
1143 if ((static_cast<QNetworkRequest::LoadControl>
1153 authenticationManager->cacheCredentials(url, authenticator);
1172 emit q->authenticationRequired(backend->
reply->q_func(), authenticator);
1173 authenticationManager->cacheCredentials(url, authenticator);
1176 #ifndef QT_NO_NETWORKPROXY 1198 emit q->proxyAuthenticationRequired(proxy, authenticator);
1199 authenticationManager->cacheProxyCredentials(proxy, authenticator);
1208 qWarning(
"QNetworkAccessManager: factory %p has returned an empty result set",
1225 manager->d_func()->objectCache.clear();
1226 manager->d_func()->authenticationManager->clearCache();
1228 if (manager->d_func()->httpThread) {
1230 manager->d_func()->httpThread->quit();
1231 manager->d_func()->httpThread->wait(5000);
1232 manager->d_func()->httpThread = 0;
1241 httpThread->wait(5000);
1246 #ifndef QT_NO_BEARERMANAGEMENT 1251 initializeSession =
false;
1254 networkSessionStrongRef = networkSessionWeakRef.toStrongRef();
1260 if (networkSessionStrongRef) {
1262 if (networkSessionStrongRef == newSession)
1272 networkSessionStrongRef = newSession;
1273 networkSessionWeakRef = networkSessionStrongRef.
toWeakRef();
1275 if (!networkSessionStrongRef) {
1293 _q_networkSessionStateChanged(networkSessionStrongRef->state());
1300 if (networkSession) {
1308 networkSessionStrongRef.clear();
1309 networkSessionWeakRef.clear();
1320 emit q->networkSessionConnected();
1321 lastSessionState = state;
1335 #endif // QT_NO_BEARERMANAGEMENT 1346 contentType +=
"multipart/";
1347 switch (multiPart->d_func()->contentType) {
1349 contentType +=
"related";
1352 contentType +=
"form-data";
1355 contentType +=
"alternative";
1358 contentType +=
"mixed";
1362 contentType +=
"; boundary=\"" + multiPart->d_func()->
boundary +
"\"";
1372 QIODevice *device = multiPart->d_func()->device;
1376 qWarning(
"could not open device for reading");
1378 qWarning(
"device is not readable");
1387 #include "moc_qnetworkaccessmanager.cpp" The QVariant class acts like a union for the most common Qt data types.
void setCookieJar(QNetworkCookieJar *cookieJar)
Sets the manager's cookie jar to be the cookieJar specified.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
void createCookieJar() const
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
void _q_replySslErrors(const QList< QSslError > &errors)
void _q_networkSessionClosed()
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.
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's SSL configuration.
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
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.
bool open(OpenMode openMode)
Reimplemented Function
QNetworkProxy lastProxyAuthentication
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
The QByteArray class provides an array of bytes.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
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...
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.
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
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.
void finished(QNetworkReply *reply)
This signal is emitted whenever a pending network reply is finished.
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.
QUrl url() const
Returns the URL this network request is referring to.
void setParent(QObject *)
Makes the object a child of parent.
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
QNetworkAccessManagerPrivate * manager
bool isLocalFile() const
Returns true if this URL is pointing to a local file path.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
QByteArray boundary() const
returns the boundary.
QNetworkConfiguration configuration() const
Returns the QNetworkConfiguration that this network session object is based on.
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.
QNetworkReplyImplPrivate * reply
void setCache(QAbstractNetworkCache *cache)
Sets the manager's network cache to be the cache specified.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
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...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
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...
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.
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.
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
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.
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.
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.
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.
QNetworkReply * postProcess(QNetworkReply *reply)
QUrl urlForLastAuthentication
if(void) toggleToolbarShown
~QNetworkAccessManagerPrivate()
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP. ...
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QNetworkCookieJar * cookieJar
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
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.
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...
QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query)
void reserve(int size)
Attempts to allocate memory for at least size bytes.
The QIODevice class is the base interface class of all I/O devices in Qt.
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...
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
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.
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. ...