diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/access.pri | 5 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 71 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection_p.h | 43 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel.cpp | 64 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel_p.h | 129 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 7 | ||||
-rw-r--r-- | src/network/access/qnetworkcookie.cpp | 255 | ||||
-rw-r--r-- | src/network/access/qnetworkcookie.h | 21 | ||||
-rw-r--r-- | src/network/access/qnetworkcookiejar.cpp | 296 | ||||
-rw-r--r-- | src/network/access/qnetworkcookiejar.h | 81 | ||||
-rw-r--r-- | src/network/access/qnetworkcookiejar_p.h | 71 | ||||
-rw-r--r-- | src/network/access/qnetworkreply.cpp | 9 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_unix.cpp | 11 | ||||
-rw-r--r-- | src/network/socket/qlocalserver_unix.cpp | 4 | ||||
-rw-r--r-- | src/network/socket/qlocalsocket_unix.cpp | 4 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine_p.h | 4 | ||||
-rw-r--r-- | src/network/socket/qnativesocketengine_unix.cpp | 22 | ||||
-rw-r--r-- | src/network/socket/qnet_unix_p.h | 26 |
18 files changed, 761 insertions, 362 deletions
diff --git a/src/network/access/access.pri b/src/network/access/access.pri index 3269b2e..ab7b3a7 100644 --- a/src/network/access/access.pri +++ b/src/network/access/access.pri @@ -6,6 +6,7 @@ HEADERS += access/qftp.h \ access/qhttpnetworkrequest_p.h \ access/qhttpnetworkreply_p.h \ access/qhttpnetworkconnection_p.h \ + access/qhttpnetworkconnectionchannel_p.h \ access/qnetworkaccessmanager.h \ access/qnetworkaccessmanager_p.h \ access/qnetworkaccesscache_p.h \ @@ -18,6 +19,8 @@ HEADERS += access/qftp.h \ access/qnetworkaccessftpbackend_p.h \ access/qnetworkcookie.h \ access/qnetworkcookie_p.h \ + access/qnetworkcookiejar.h \ + access/qnetworkcookiejar_p.h \ access/qnetworkrequest.h \ access/qnetworkrequest_p.h \ access/qnetworkreply.h \ @@ -34,6 +37,7 @@ SOURCES += access/qftp.cpp \ access/qhttpnetworkrequest.cpp \ access/qhttpnetworkreply.cpp \ access/qhttpnetworkconnection.cpp \ + access/qhttpnetworkconnectionchannel.cpp \ access/qnetworkaccessmanager.cpp \ access/qnetworkaccesscache.cpp \ access/qnetworkaccessbackend.cpp \ @@ -44,6 +48,7 @@ SOURCES += access/qftp.cpp \ access/qnetworkaccessftpbackend.cpp \ access/qnetworkaccesshttpbackend.cpp \ access/qnetworkcookie.cpp \ + access/qnetworkcookiejar.cpp \ access/qnetworkrequest.cpp \ access/qnetworkreply.cpp \ access/qnetworkreplyimpl.cpp \ diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index e32c975..20e4802 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qhttpnetworkconnection_p.h" +#include "qhttpnetworkconnectionchannel_p.h" #include "private/qnoncontiguousbytedevice_p.h" #include <private/qnetworkrequest_p.h> #include <private/qobject_p.h> @@ -74,7 +75,7 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host #endif { - channels = new Channel[channelCount]; + channels = new QHttpNetworkConnectionChannel[channelCount]; } QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() @@ -156,25 +157,25 @@ int QHttpNetworkConnectionPrivate::indexOf(QAbstractSocket *socket) const bool QHttpNetworkConnectionPrivate::isSocketBusy(QAbstractSocket *socket) const { int i = indexOf(socket); - return (channels[i].state & BusyState); + return (channels[i].state & QHttpNetworkConnectionChannel::BusyState); } bool QHttpNetworkConnectionPrivate::isSocketWriting(QAbstractSocket *socket) const { int i = indexOf(socket); - return (i != -1 && (channels[i].state & WritingState)); + return (i != -1 && (channels[i].state & QHttpNetworkConnectionChannel::WritingState)); } bool QHttpNetworkConnectionPrivate::isSocketWaiting(QAbstractSocket *socket) const { int i = indexOf(socket); - return (i != -1 && (channels[i].state & WaitingState)); + return (i != -1 && (channels[i].state & QHttpNetworkConnectionChannel::WaitingState)); } bool QHttpNetworkConnectionPrivate::isSocketReading(QAbstractSocket *socket) const { int i = indexOf(socket); - return (i != -1 && (channels[i].state & ReadingState)); + return (i != -1 && (channels[i].state & QHttpNetworkConnectionChannel::ReadingState)); } void QHttpNetworkConnectionPrivate::appendUncompressedData(QHttpNetworkReply &reply, QByteArray &qba) @@ -312,7 +313,7 @@ bool QHttpNetworkConnectionPrivate::ensureConnection(QAbstractSocket *socket) channels[index].resendCurrent = true; return false; } - channels[index].state = ConnectingState; + channels[index].state = QHttpNetworkConnectionChannel::ConnectingState; channels[index].pendingEncrypt = encrypt; // This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done" @@ -363,7 +364,7 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) int i = indexOf(socket); switch (channels[i].state) { - case IdleState: { // write the header + case QHttpNetworkConnectionChannel::IdleState: { // write the header if (!ensureConnection(socket)) { // wait for the connection (and encryption) to be done // sendRequest will be called again from either @@ -377,7 +378,7 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) channels[i].reply->d_func()->connection = q; channels[i].reply->d_func()->autoDecompress = channels[i].request.d->autoDecompress; } - channels[i].state = WritingState; + channels[i].state = QHttpNetworkConnectionChannel::WritingState; channels[i].pendingEncrypt = false; // if the url contains authentication parameters, use the new ones // both channels will use the new authentication parameters @@ -412,20 +413,20 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) channels[i].bytesTotal = channels[i].request.contentLength(); } else { socket->flush(); // ### Remove this when pipelining is implemented. We want less TCP packets! - channels[i].state = WaitingState; + channels[i].state = QHttpNetworkConnectionChannel::WaitingState; break; } // write the initial chunk together with the headers // fall through } - case WritingState: + case QHttpNetworkConnectionChannel::WritingState: { // write the data QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); if (!uploadByteDevice || channels[i].bytesTotal == channels[i].written) { if (uploadByteDevice) emit channels[i].reply->dataSendProgress(channels[i].written, channels[i].bytesTotal); - channels[i].state = WaitingState; // now wait for response + channels[i].state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response sendRequest(socket); break; } @@ -472,7 +473,7 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) if (channels[i].written == channels[i].bytesTotal) { // make sure this function is called once again - channels[i].state = WaitingState; + channels[i].state = QHttpNetworkConnectionChannel::WaitingState; sendRequest(socket); break; } @@ -482,7 +483,7 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) break; } - case WaitingState: + case QHttpNetworkConnectionChannel::WaitingState: { QNonContiguousByteDevice* uploadByteDevice = channels[i].request.uploadByteDevice(); if (uploadByteDevice) { @@ -494,8 +495,8 @@ bool QHttpNetworkConnectionPrivate::sendRequest(QAbstractSocket *socket) receiveReply(socket, channels[i].reply); break; } - case ReadingState: - case Wait4AuthState: + case QHttpNetworkConnectionChannel::ReadingState: + case QHttpNetworkConnectionChannel::Wait4AuthState: // ignore _q_bytesWritten in these states // fall through default: @@ -603,7 +604,7 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN if (!socket->bytesAvailable()) { if (reply && reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; allDone(socket, reply); } else { // try to reconnect/resend before sending an error. @@ -654,7 +655,7 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN emit reply->headerChanged(); if (!expectContent(reply)) { reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; allDone(socket, reply); return; } @@ -717,7 +718,7 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN // everything done, fall through } case QHttpNetworkReplyPrivate::AllDoneState: - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; allDone(socket, reply); break; default: @@ -866,11 +867,11 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket eraseData(channels[i].reply); closeChannel(i); channels[i].lastStatus = 0; - channels[i].state = Wait4AuthState; + channels[i].state = QHttpNetworkConnectionChannel::Wait4AuthState; return false; } // cannot use this socket until the slot returns - channels[i].state = WaitingState; + channels[i].state = QHttpNetworkConnectionChannel::WaitingState; socket->blockSignals(true); if (!isProxy) { pendingAuthSignal = true; @@ -885,7 +886,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket } socket->blockSignals(false); // socket free to use - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; if (priv->phase != QAuthenticatorPrivate::Done) { // send any pending requests copyCredentials(i, auth, isProxy); @@ -908,8 +909,8 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket socket->close(); // remove pending request on the other channels for (int j = 0; j < channelCount; ++j) { - if (j != i && channels[j].state == Wait4AuthState) - channels[j].state = IdleState; + if (j != i && channels[j].state == QHttpNetworkConnectionChannel::Wait4AuthState) + channels[j].state = QHttpNetworkConnectionChannel::IdleState; } return true; } @@ -1009,7 +1010,7 @@ void QHttpNetworkConnectionPrivate::closeChannel(int channel) socket->blockSignals(true); socket->close(); socket->blockSignals(false); - channels[channel].state = IdleState; + channels[channel].state = QHttpNetworkConnectionChannel::IdleState; } void QHttpNetworkConnectionPrivate::resendCurrentRequest(QAbstractSocket *socket) @@ -1112,7 +1113,7 @@ void QHttpNetworkConnectionPrivate::_q_readyRead() return; // ### error if (isSocketWaiting(socket) || isSocketReading(socket)) { int i = indexOf(socket); - channels[i].state = ReadingState; + channels[i].state = QHttpNetworkConnectionChannel::ReadingState; if (channels[i].reply) receiveReply(socket, channels[i].reply); } @@ -1141,14 +1142,14 @@ void QHttpNetworkConnectionPrivate::_q_disconnected() // read the available data before closing int i = indexOf(socket); if (isSocketWaiting(socket) || isSocketReading(socket)) { - channels[i].state = ReadingState; + channels[i].state = QHttpNetworkConnectionChannel::ReadingState; if (channels[i].reply) receiveReply(socket, channels[i].reply); - } else if (channels[i].state == IdleState && channels[i].resendCurrent) { + } else if (channels[i].state == QHttpNetworkConnectionChannel::IdleState && channels[i].resendCurrent) { // re-sending request because the socket was in ClosingState QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); } - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; } void QHttpNetworkConnectionPrivate::_q_startNextRequest() @@ -1157,7 +1158,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() for (int i = 0; i < channelCount; ++i) { if (channels[i].resendCurrent) { channels[i].resendCurrent = false; - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; if (channels[i].reply) sendRequest(channels[i].socket); } @@ -1181,8 +1182,8 @@ void QHttpNetworkConnectionPrivate::_q_restartAuthPendingRequests() // send the request using the idle socket for (int i = 0 ; i < channelCount; ++i) { QAbstractSocket *socket = channels[i].socket; - if (channels[i].state == Wait4AuthState) { - channels[i].state = IdleState; + if (channels[i].state == QHttpNetworkConnectionChannel::Wait4AuthState) { + channels[i].state = QHttpNetworkConnectionChannel::IdleState; if (channels[i].reply) sendRequest(socket); } @@ -1203,7 +1204,7 @@ void QHttpNetworkConnectionPrivate::_q_connected() // ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again! //channels[i].reconnectAttempts = 2; if (!channels[i].pendingEncrypt) { - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; if (channels[i].reply) sendRequest(socket); else @@ -1232,7 +1233,7 @@ void QHttpNetworkConnectionPrivate::_q_error(QAbstractSocket::SocketError socket case QAbstractSocket::RemoteHostClosedError: // try to reconnect/resend before sending an error. // while "Reading" the _q_disconnected() will handle this. - if (channels[i].state != IdleState && channels[i].state != ReadingState) { + if (channels[i].state != QHttpNetworkConnectionChannel::IdleState && channels[i].state != QHttpNetworkConnectionChannel::ReadingState) { if (channels[i].reconnectAttempts-- > 0) { resendCurrentRequest(socket); return; @@ -1246,7 +1247,7 @@ void QHttpNetworkConnectionPrivate::_q_error(QAbstractSocket::SocketError socket break; case QAbstractSocket::SocketTimeoutError: // try to reconnect/resend before sending an error. - if (channels[i].state == WritingState && (channels[i].reconnectAttempts-- > 0)) { + if (channels[i].state == QHttpNetworkConnectionChannel::WritingState && (channels[i].reconnectAttempts-- > 0)) { resendCurrentRequest(socket); return; } @@ -1405,7 +1406,7 @@ void QHttpNetworkConnectionPrivate::_q_encrypted() if (!socket) return; // ### error int i = indexOf(socket); - channels[i].state = IdleState; + channels[i].state = QHttpNetworkConnectionChannel::IdleState; sendRequest(socket); } diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 52a73a7..db6a140 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -65,6 +65,7 @@ #include <private/qhttpnetworkrequest_p.h> #include <private/qhttpnetworkreply_p.h> +#include "qhttpnetworkconnectionchannel_p.h" #ifndef QT_NO_HTTP @@ -157,8 +158,6 @@ private: }; - - // private classes typedef QPair<QHttpNetworkRequest, QHttpNetworkReply*> HttpMessagePair; @@ -172,16 +171,6 @@ public: void init(); void connectSignals(QAbstractSocket *socket); - enum SocketState { - IdleState = 0, // ready to send request - ConnectingState = 1, // connecting to host - WritingState = 2, // writing the data - WaitingState = 4, // waiting for reply - ReadingState = 8, // reading the reply - Wait4AuthState = 0x10, // blocked for send till the current authentication slot is done - BusyState = (ConnectingState|WritingState|WaitingState|ReadingState|Wait4AuthState) - }; - enum { ChunkSize = 4096 }; int indexOf(QAbstractSocket *socket) const; @@ -226,35 +215,9 @@ public: quint16 port; bool encrypt; - struct Channel { - QAbstractSocket *socket; - SocketState state; - QHttpNetworkRequest request; // current request - QHttpNetworkReply *reply; // current reply for this request - qint64 written; - qint64 bytesTotal; - bool resendCurrent; - int lastStatus; // last status received on this channel - bool pendingEncrypt; // for https (send after encrypted) - int reconnectAttempts; // maximum 2 reconnection attempts - QAuthenticatorPrivate::Method authMehtod; - QAuthenticatorPrivate::Method proxyAuthMehtod; - QAuthenticator authenticator; - QAuthenticator proxyAuthenticator; -#ifndef QT_NO_OPENSSL - bool ignoreAllSslErrors; - QList<QSslError> ignoreSslErrorsList; -#endif - Channel() : socket(0), state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false), - lastStatus(0), pendingEncrypt(false), reconnectAttempts(2), - authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None) -#ifndef QT_NO_OPENSSL - , ignoreAllSslErrors(false) -#endif - {} - }; static const int channelCount; - Channel *channels; // parallel connections to the server + QHttpNetworkConnectionChannel *channels; // parallel connections to the server + bool pendingAuthSignal; // there is an incomplete authentication signal bool pendingProxyAuthSignal; // there is an incomplete proxy authentication signal diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp new file mode 100644 index 0000000..a04b530 --- /dev/null +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qhttpnetworkconnection_p.h" +#include "qhttpnetworkconnectionchannel_p.h" + +#include <qpair.h> +#include <qdebug.h> + +#ifndef QT_NO_HTTP + +#ifndef QT_NO_OPENSSL +# include <QtNetwork/qsslkey.h> +# include <QtNetwork/qsslcipher.h> +# include <QtNetwork/qsslconfiguration.h> +#endif + +QT_BEGIN_NAMESPACE + +// TODO: Put channel specific stuff here so it does not polute qhttpnetworkconnection.cpp + +QT_END_NAMESPACE + +#include "moc_qhttpnetworkconnectionchannel_p.cpp" + +#endif // QT_NO_HTTP diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h new file mode 100644 index 0000000..cbabc67 --- /dev/null +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QHTTPNETWORKCONNECTIONCHANNEL_H +#define QHTTPNETWORKCONNECTIONCHANNEL_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the Network Access API. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// +#include <QtNetwork/qnetworkrequest.h> +#include <QtNetwork/qnetworkreply.h> +#include <QtNetwork/qabstractsocket.h> + +#include <private/qobject_p.h> +#include <qauthenticator.h> +#include <qnetworkproxy.h> +#include <qbuffer.h> + +#include <private/qhttpnetworkheader_p.h> +#include <private/qhttpnetworkrequest_p.h> +#include <private/qhttpnetworkreply_p.h> + + +#ifndef QT_NO_HTTP + +#ifndef QT_NO_OPENSSL +# include <QtNetwork/qsslsocket.h> +# include <QtNetwork/qsslerror.h> +#else +# include <QtNetwork/qtcpsocket.h> +#endif + +QT_BEGIN_NAMESPACE + +class QHttpNetworkRequest; +class QHttpNetworkReply; +class QByteArray; + +class QHttpNetworkConnectionChannel : public QObject { + Q_OBJECT +public: + enum ChannelState { + IdleState = 0, // ready to send request + ConnectingState = 1, // connecting to host + WritingState = 2, // writing the data + WaitingState = 4, // waiting for reply + ReadingState = 8, // reading the reply + Wait4AuthState = 0x10, // blocked for send till the current authentication slot is done + BusyState = (ConnectingState|WritingState|WaitingState|ReadingState|Wait4AuthState) + }; + QAbstractSocket *socket; + ChannelState state; + QHttpNetworkRequest request; // current request + QHttpNetworkReply *reply; // current reply for this request + qint64 written; + qint64 bytesTotal; + bool resendCurrent; + int lastStatus; // last status received on this channel + bool pendingEncrypt; // for https (send after encrypted) + int reconnectAttempts; // maximum 2 reconnection attempts + QAuthenticatorPrivate::Method authMehtod; + QAuthenticatorPrivate::Method proxyAuthMehtod; + QAuthenticator authenticator; + QAuthenticator proxyAuthenticator; +#ifndef QT_NO_OPENSSL + bool ignoreAllSslErrors; + QList<QSslError> ignoreSslErrorsList; +#endif + QHttpNetworkConnectionChannel() : socket(0), state(IdleState), reply(0), written(0), bytesTotal(0), resendCurrent(false), + lastStatus(0), pendingEncrypt(false), reconnectAttempts(2), + authMehtod(QAuthenticatorPrivate::None), proxyAuthMehtod(QAuthenticatorPrivate::None) +#ifndef QT_NO_OPENSSL + , ignoreAllSslErrors(false) +#endif + {} +}; + + + +QT_END_NAMESPACE + +#endif // QT_NO_HTTP + +#endif diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 802e603..8569ecd 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -121,7 +121,9 @@ static void ensureInitialized() as well as meta-data (headers, etc.). \note After the request has finished, it is the responsibility of the user - to delete the QNetworkReply object at an appropriate time. + to delete the QNetworkReply object at an appropriate time. Do not directly + delete it inside the slot connected to finished(). You can use the + deleteLater() function. A more involved example, assuming the manager is already existent, can be: @@ -202,6 +204,9 @@ static void ensureInitialized() See QNetworkReply::finished() for information on the status that the object will be in. + \note Do not delete the \a reply object in the slot connected to this + signal. Use deleteLater(). + \sa QNetworkReply::finished(), QNetworkReply::error() */ diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index c039703..dd5edb0 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -1068,259 +1068,4 @@ QDebug operator<<(QDebug s, const QNetworkCookie &cookie) } #endif - - -class QNetworkCookieJarPrivate: public QObjectPrivate -{ -public: - QList<QNetworkCookie> allCookies; - - Q_DECLARE_PUBLIC(QNetworkCookieJar) -}; - -/*! - \class QNetworkCookieJar - \brief The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects - \since 4.4 - - Cookies are small bits of information that stateless protocols - like HTTP use to maintain some persistent information across - requests. - - A cookie is set by a remote server when it replies to a request - and it expects the same cookie to be sent back when further - requests are sent. - - The cookie jar is the object that holds all cookies set in - previous requests. Web browsers save their cookie jars to disk in - order to conserve permanent cookies across invocations of the - application. - - QNetworkCookieJar does not implement permanent storage: it only - keeps the cookies in memory. Once the QNetworkCookieJar object is - deleted, all cookies it held will be discarded as well. If you - want to save the cookies, you should derive from this class and - implement the saving to disk to your own storage format. - - This class implements only the basic security recommended by the - cookie specifications and does not implement any cookie acceptance - policy (it accepts all cookies set by any requests). In order to - override those rules, you should reimplement the - cookiesForUrl() and setCookiesFromUrl() virtual - functions. They are called by QNetworkReply and - QNetworkAccessManager when they detect new cookies and when they - require cookies. - - \sa QNetworkCookie, QNetworkAccessManager, QNetworkReply, - QNetworkRequest, QNetworkAccessManager::setCookieJar() -*/ - -/*! - Creates a QNetworkCookieJar object and sets the parent object to - be \a parent. - - The cookie jar is initialized to empty. -*/ -QNetworkCookieJar::QNetworkCookieJar(QObject *parent) - : QObject(*new QNetworkCookieJarPrivate, parent) -{ -} - -/*! - Destroys this cookie jar object and discards all cookies stored in - it. Cookies are not saved to disk in the QNetworkCookieJar default - implementation. - - If you need to save the cookies to disk, you have to derive from - QNetworkCookieJar and save the cookies to disk yourself. -*/ -QNetworkCookieJar::~QNetworkCookieJar() -{ -} - -/*! - Returns all cookies stored in this cookie jar. This function is - suitable for derived classes to save cookies to disk, as well as - to implement cookie expiration and other policies. - - \sa setAllCookies(), cookiesForUrl() -*/ -QList<QNetworkCookie> QNetworkCookieJar::allCookies() const -{ - return d_func()->allCookies; -} - -/*! - Sets the internal list of cookies held by this cookie jar to be \a - cookieList. This function is suitable for derived classes to - implement loading cookies from permanent storage, or their own - cookie acceptance policies by reimplementing - setCookiesFromUrl(). - - \sa allCookies(), setCookiesFromUrl() -*/ -void QNetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList) -{ - Q_D(QNetworkCookieJar); - d->allCookies = cookieList; -} - -static inline bool isParentPath(QString path, QString reference) -{ - if (!path.endsWith(QLatin1Char('/'))) - path += QLatin1Char('/'); - if (!reference.endsWith(QLatin1Char('/'))) - reference += QLatin1Char('/'); - return path.startsWith(reference); -} - -static inline bool isParentDomain(QString domain, QString reference) -{ - if (!reference.startsWith(QLatin1Char('.'))) - return domain == reference; - - return domain.endsWith(reference) || domain == reference.mid(1); -} - -/*! - Adds the cookies in the list \a cookieList to this cookie - jar. Default values for path and domain are taken from the \a - url object. - - Returns true if one or more cookes are set for url otherwise false. - - If a cookie already exists in the cookie jar, it will be - overridden by those in \a cookieList. - - The default QNetworkCookieJar class implements only a very basic - security policy (it makes sure that the cookies' domain and path - match the reply's). To enhance the security policy with your own - algorithms, override setCookiesFromUrl(). - - Also, QNetworkCookieJar does not have a maximum cookie jar - size. Reimplement this function to discard older cookies to create - room for new ones. - - \sa cookiesForUrl(), QNetworkAccessManager::setCookieJar() -*/ -bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, - const QUrl &url) -{ - Q_D(QNetworkCookieJar); - QString defaultDomain = url.host(); - QString pathAndFileName = url.path(); - QString defaultPath = pathAndFileName.left(pathAndFileName.lastIndexOf(QLatin1Char('/'))+1); - if (defaultPath.isEmpty()) - defaultPath = QLatin1Char('/'); - - int added = 0; - QDateTime now = QDateTime::currentDateTime(); - foreach (QNetworkCookie cookie, cookieList) { - bool isDeletion = !cookie.isSessionCookie() && - cookie.expirationDate() < now; - - // validate the cookie & set the defaults if unset - if (cookie.path().isEmpty()) - cookie.setPath(defaultPath); - else if (!isParentPath(pathAndFileName, cookie.path())) - continue; // not accepted - - if (cookie.domain().isEmpty()) { - cookie.setDomain(defaultDomain); - } else { - QString domain = cookie.domain(); - if (!(isParentDomain(domain, defaultDomain) - || isParentDomain(defaultDomain, domain))) { - continue; // not accepted - } - - // reject if domain is like ".com" - // (i.e., reject if domain does not contain embedded dots, see RFC 2109 section 4.3.2) - // this is just a rudimentary check and does not cover all cases - if (domain.lastIndexOf(QLatin1Char('.')) == 0) - continue; // not accepted - - } - - QList<QNetworkCookie>::Iterator it = d->allCookies.begin(), - end = d->allCookies.end(); - for ( ; it != end; ++it) - // does this cookie already exist? - if (cookie.name() == it->name() && - cookie.domain() == it->domain() && - cookie.path() == it->path()) { - // found a match - d->allCookies.erase(it); - break; - } - - // did not find a match - if (!isDeletion) { - d->allCookies += cookie; - ++added; - } - } - return (added > 0); -} - -/*! - Returns the cookies to be added to when a request is sent to - \a url. This function is called by the default - QNetworkAccessManager::createRequest(), which adds the - cookies returned by this function to the request being sent. - - If more than one cookie with the same name is found, but with - differing paths, the one with longer path is returned before the - one with shorter path. In other words, this function returns - cookies sorted by path length. - - The default QNetworkCookieJar class implements only a very basic - security policy (it makes sure that the cookies' domain and path - match the reply's). To enhance the security policy with your own - algorithms, override cookiesForUrl(). - - \sa setCookiesFromUrl(), QNetworkAccessManager::setCookieJar() -*/ -QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const -{ -// \b Warning! This is only a dumb implementation! -// It does NOT follow all of the recommendations from -// http://wp.netscape.com/newsref/std/cookie_spec.html -// It does not implement a very good cross-domain verification yet. - - Q_D(const QNetworkCookieJar); - QDateTime now = QDateTime::currentDateTime(); - QList<QNetworkCookie> result; - - // scan our cookies for something that matches - QList<QNetworkCookie>::ConstIterator it = d->allCookies.constBegin(), - end = d->allCookies.constEnd(); - for ( ; it != end; ++it) { - if (!isParentDomain(url.host(), it->domain())) - continue; - if (!isParentPath(url.path(), it->path())) - continue; - if (!(*it).isSessionCookie() && (*it).expirationDate() < now) - continue; - - // insert this cookie into result, sorted by path - QList<QNetworkCookie>::Iterator insertIt = result.begin(); - while (insertIt != result.end()) { - if (insertIt->path().length() < it->path().length()) { - // insert here - insertIt = result.insert(insertIt, *it); - break; - } else { - ++insertIt; - } - } - - // this is the shortest path yet, just append - if (insertIt == result.end()) - result += *it; - } - - return result; -} - QT_END_NAMESPACE diff --git a/src/network/access/qnetworkcookie.h b/src/network/access/qnetworkcookie.h index c5f03fb..922a6f5 100644 --- a/src/network/access/qnetworkcookie.h +++ b/src/network/access/qnetworkcookie.h @@ -108,25 +108,8 @@ private: }; Q_DECLARE_TYPEINFO(QNetworkCookie, Q_MOVABLE_TYPE); -class QNetworkCookieJarPrivate; -class Q_NETWORK_EXPORT QNetworkCookieJar: public QObject -{ - Q_OBJECT -public: - QNetworkCookieJar(QObject *parent = 0); - virtual ~QNetworkCookieJar(); - - virtual QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const; - virtual bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url); - -protected: - QList<QNetworkCookie> allCookies() const; - void setAllCookies(const QList<QNetworkCookie> &cookieList); - -private: - Q_DECLARE_PRIVATE(QNetworkCookieJar) - Q_DISABLE_COPY(QNetworkCookieJar) -}; +// ### Qt5 remove this include +#include "qnetworkcookiejar.h" #ifndef QT_NO_DEBUG_STREAM class QDebug; diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp new file mode 100644 index 0000000..03f7427 --- /dev/null +++ b/src/network/access/qnetworkcookiejar.cpp @@ -0,0 +1,296 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkcookiejar.h" +#include "qnetworkcookiejar_p.h" + +#include "QtNetwork/qnetworkcookie.h" +#include "QtCore/qurl.h" +#include "QtCore/qdatetime.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QNetworkCookieJar + \brief The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects + \since 4.4 + + Cookies are small bits of information that stateless protocols + like HTTP use to maintain some persistent information across + requests. + + A cookie is set by a remote server when it replies to a request + and it expects the same cookie to be sent back when further + requests are sent. + + The cookie jar is the object that holds all cookies set in + previous requests. Web browsers save their cookie jars to disk in + order to conserve permanent cookies across invocations of the + application. + + QNetworkCookieJar does not implement permanent storage: it only + keeps the cookies in memory. Once the QNetworkCookieJar object is + deleted, all cookies it held will be discarded as well. If you + want to save the cookies, you should derive from this class and + implement the saving to disk to your own storage format. + + This class implements only the basic security recommended by the + cookie specifications and does not implement any cookie acceptance + policy (it accepts all cookies set by any requests). In order to + override those rules, you should reimplement the + cookiesForUrl() and setCookiesFromUrl() virtual + functions. They are called by QNetworkReply and + QNetworkAccessManager when they detect new cookies and when they + require cookies. + + \sa QNetworkCookie, QNetworkAccessManager, QNetworkReply, + QNetworkRequest, QNetworkAccessManager::setCookieJar() +*/ + +/*! + Creates a QNetworkCookieJar object and sets the parent object to + be \a parent. + + The cookie jar is initialized to empty. +*/ +QNetworkCookieJar::QNetworkCookieJar(QObject *parent) + : QObject(*new QNetworkCookieJarPrivate, parent) +{ +} + +/*! + Destroys this cookie jar object and discards all cookies stored in + it. Cookies are not saved to disk in the QNetworkCookieJar default + implementation. + + If you need to save the cookies to disk, you have to derive from + QNetworkCookieJar and save the cookies to disk yourself. +*/ +QNetworkCookieJar::~QNetworkCookieJar() +{ +} + +/*! + Returns all cookies stored in this cookie jar. This function is + suitable for derived classes to save cookies to disk, as well as + to implement cookie expiration and other policies. + + \sa setAllCookies(), cookiesForUrl() +*/ +QList<QNetworkCookie> QNetworkCookieJar::allCookies() const +{ + return d_func()->allCookies; +} + +/*! + Sets the internal list of cookies held by this cookie jar to be \a + cookieList. This function is suitable for derived classes to + implement loading cookies from permanent storage, or their own + cookie acceptance policies by reimplementing + setCookiesFromUrl(). + + \sa allCookies(), setCookiesFromUrl() +*/ +void QNetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList) +{ + Q_D(QNetworkCookieJar); + d->allCookies = cookieList; +} + +static inline bool isParentPath(QString path, QString reference) +{ + if (!path.endsWith(QLatin1Char('/'))) + path += QLatin1Char('/'); + if (!reference.endsWith(QLatin1Char('/'))) + reference += QLatin1Char('/'); + return path.startsWith(reference); +} + +static inline bool isParentDomain(QString domain, QString reference) +{ + if (!reference.startsWith(QLatin1Char('.'))) + return domain == reference; + + return domain.endsWith(reference) || domain == reference.mid(1); +} + +/*! + Adds the cookies in the list \a cookieList to this cookie + jar. Default values for path and domain are taken from the \a + url object. + + Returns true if one or more cookes are set for url otherwise false. + + If a cookie already exists in the cookie jar, it will be + overridden by those in \a cookieList. + + The default QNetworkCookieJar class implements only a very basic + security policy (it makes sure that the cookies' domain and path + match the reply's). To enhance the security policy with your own + algorithms, override setCookiesFromUrl(). + + Also, QNetworkCookieJar does not have a maximum cookie jar + size. Reimplement this function to discard older cookies to create + room for new ones. + + \sa cookiesForUrl(), QNetworkAccessManager::setCookieJar() +*/ +bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, + const QUrl &url) +{ + Q_D(QNetworkCookieJar); + QString defaultDomain = url.host(); + QString pathAndFileName = url.path(); + QString defaultPath = pathAndFileName.left(pathAndFileName.lastIndexOf(QLatin1Char('/'))+1); + if (defaultPath.isEmpty()) + defaultPath = QLatin1Char('/'); + + int added = 0; + QDateTime now = QDateTime::currentDateTime(); + foreach (QNetworkCookie cookie, cookieList) { + bool isDeletion = !cookie.isSessionCookie() && + cookie.expirationDate() < now; + + // validate the cookie & set the defaults if unset + if (cookie.path().isEmpty()) + cookie.setPath(defaultPath); + else if (!isParentPath(pathAndFileName, cookie.path())) + continue; // not accepted + + if (cookie.domain().isEmpty()) { + cookie.setDomain(defaultDomain); + } else { + QString domain = cookie.domain(); + if (!(isParentDomain(domain, defaultDomain) + || isParentDomain(defaultDomain, domain))) { + continue; // not accepted + } + + // reject if domain is like ".com" + // (i.e., reject if domain does not contain embedded dots, see RFC 2109 section 4.3.2) + // this is just a rudimentary check and does not cover all cases + if (domain.lastIndexOf(QLatin1Char('.')) == 0) + continue; // not accepted + + } + + QList<QNetworkCookie>::Iterator it = d->allCookies.begin(), + end = d->allCookies.end(); + for ( ; it != end; ++it) + // does this cookie already exist? + if (cookie.name() == it->name() && + cookie.domain() == it->domain() && + cookie.path() == it->path()) { + // found a match + d->allCookies.erase(it); + break; + } + + // did not find a match + if (!isDeletion) { + d->allCookies += cookie; + ++added; + } + } + return (added > 0); +} + +/*! + Returns the cookies to be added to when a request is sent to + \a url. This function is called by the default + QNetworkAccessManager::createRequest(), which adds the + cookies returned by this function to the request being sent. + + If more than one cookie with the same name is found, but with + differing paths, the one with longer path is returned before the + one with shorter path. In other words, this function returns + cookies sorted by path length. + + The default QNetworkCookieJar class implements only a very basic + security policy (it makes sure that the cookies' domain and path + match the reply's). To enhance the security policy with your own + algorithms, override cookiesForUrl(). + + \sa setCookiesFromUrl(), QNetworkAccessManager::setCookieJar() +*/ +QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const +{ +// \b Warning! This is only a dumb implementation! +// It does NOT follow all of the recommendations from +// http://wp.netscape.com/newsref/std/cookie_spec.html +// It does not implement a very good cross-domain verification yet. + + Q_D(const QNetworkCookieJar); + QDateTime now = QDateTime::currentDateTime(); + QList<QNetworkCookie> result; + + // scan our cookies for something that matches + QList<QNetworkCookie>::ConstIterator it = d->allCookies.constBegin(), + end = d->allCookies.constEnd(); + for ( ; it != end; ++it) { + if (!isParentDomain(url.host(), it->domain())) + continue; + if (!isParentPath(url.path(), it->path())) + continue; + if (!(*it).isSessionCookie() && (*it).expirationDate() < now) + continue; + + // insert this cookie into result, sorted by path + QList<QNetworkCookie>::Iterator insertIt = result.begin(); + while (insertIt != result.end()) { + if (insertIt->path().length() < it->path().length()) { + // insert here + insertIt = result.insert(insertIt, *it); + break; + } else { + ++insertIt; + } + } + + // this is the shortest path yet, just append + if (insertIt == result.end()) + result += *it; + } + + return result; +} + +QT_END_NAMESPACE diff --git a/src/network/access/qnetworkcookiejar.h b/src/network/access/qnetworkcookiejar.h new file mode 100644 index 0000000..fae0857 --- /dev/null +++ b/src/network/access/qnetworkcookiejar.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCOOKIEJAR_H +#define QNETWORKCOOKIEJAR_H + +#include <QtCore/QObject> +#include <QtCore/QUrl> + +// ### Qt5 remove this include +#include "qnetworkcookie.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Network) + +class QNetworkCookieJarPrivate; +class Q_NETWORK_EXPORT QNetworkCookieJar: public QObject +{ + Q_OBJECT +public: + QNetworkCookieJar(QObject *parent = 0); + virtual ~QNetworkCookieJar(); + + virtual QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const; + virtual bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url); + +protected: + QList<QNetworkCookie> allCookies() const; + void setAllCookies(const QList<QNetworkCookie> &cookieList); + +private: + Q_DECLARE_PRIVATE(QNetworkCookieJar) + Q_DISABLE_COPY(QNetworkCookieJar) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/network/access/qnetworkcookiejar_p.h b/src/network/access/qnetworkcookiejar_p.h new file mode 100644 index 0000000..eea7eee --- /dev/null +++ b/src/network/access/qnetworkcookiejar_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKCOOKIEJAR_P_H +#define QNETWORKCOOKIEJAR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the Network Access framework. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include "private/qobject_p.h" +#include "qnetworkcookie.h" + +QT_BEGIN_NAMESPACE + +class QNetworkCookieJarPrivate: public QObjectPrivate +{ +public: + QList<QNetworkCookie> allCookies; + + Q_DECLARE_PUBLIC(QNetworkCookieJar) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index 3abf927..f6649b6 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -87,6 +87,9 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() indicates the progress of the upload for operations that have such content. + \note Do not delete the object in the slot connected to the + error() or finished() signal. Use deleteLater(). + \sa QNetworkRequest, QNetworkAccessManager */ @@ -232,6 +235,9 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() QNetworkAccessManager::finished() where that signal's reply parameter is this object. + \note Do not delete the object in the slot connected to this + signal. Use deleteLater(). + \sa QNetworkAccessManager::finished() */ @@ -246,6 +252,9 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() detected. Call errorString() to obtain a textual representation of the error condition. + \note Do not delete the object in the slot connected to this + signal. Use deleteLater(). + \sa error(), errorString() */ diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index af1eaf2..a63659e 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -55,7 +55,11 @@ #include <sys/types.h> #include <netdb.h> #include <arpa/inet.h> -#include <resolv.h> +#if defined(Q_OS_VXWORKS) +# include <hostLib.h> +#else +# include <resolv.h> +#endif #if defined (QT_NO_GETADDRINFO) #include <qmutex.h> @@ -273,10 +277,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) results.setError(QHostInfo::UnknownError); results.setErrorString(tr("Unknown address type")); } +#if !defined(Q_OS_VXWORKS) } else if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA || h_errno == NO_ADDRESS) { results.setError(QHostInfo::HostNotFound); results.setErrorString(tr("Host not found")); +#endif } else { results.setError(QHostInfo::UnknownError); results.setErrorString(tr("Unknown error")); @@ -313,6 +319,7 @@ QString QHostInfo::localHostName() QString QHostInfo::localDomainName() { +#if !defined(Q_OS_VXWORKS) resolveLibrary(); if (local_res_ninit) { // using thread-safe version @@ -343,7 +350,7 @@ QString QHostInfo::localDomainName() domainName = QUrl::fromAce(local_res->dnsrch[0]); return domainName; } - +#endif // nothing worked, try doing it by ourselves: QFile resolvconf; #if defined(_PATH_RESCONF) diff --git a/src/network/socket/qlocalserver_unix.cpp b/src/network/socket/qlocalserver_unix.cpp index 01732e4..14a0c78 100644 --- a/src/network/socket/qlocalserver_unix.cpp +++ b/src/network/socket/qlocalserver_unix.cpp @@ -54,6 +54,10 @@ #include <qdir.h> #include <qdatetime.h> +#ifdef Q_OS_VXWORKS +# include <selectLib.h> +#endif + QT_BEGIN_NAMESPACE void QLocalServerPrivate::init() diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp index 9f39bef..835b922 100644 --- a/src/network/socket/qlocalsocket_unix.cpp +++ b/src/network/socket/qlocalsocket_unix.cpp @@ -56,6 +56,10 @@ #include <qdir.h> #include <qdebug.h> +#ifdef Q_OS_VXWORKS +# include <selectLib.h> +#endif + #define QT_CONNECT_TIMEOUT 30000 QT_BEGIN_NAMESPACE diff --git a/src/network/socket/qnativesocketengine_p.h b/src/network/socket/qnativesocketengine_p.h index 9136faa..0a5c19d 100644 --- a/src/network/socket/qnativesocketengine_p.h +++ b/src/network/socket/qnativesocketengine_p.h @@ -55,9 +55,9 @@ #include "QtNetwork/qhostaddress.h" #include "private/qabstractsocketengine_p.h" #ifndef Q_OS_WIN -# include "qplatformdefs.h" +# include "qplatformdefs.h" #else -# include <winsock2.h> +# include <winsock2.h> #endif #ifdef Q_OS_SYMBIAN diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index 67a6fdf..7584357 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -282,6 +282,7 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt break; case QNativeSocketEngine::NonBlockingSocketOption: { // Make the socket nonblocking. +#if !defined(Q_OS_VXWORKS) int flags = qt_socket_fcntl(socketDescriptor, F_GETFL, 0); if (flags == -1) { #ifdef QNATIVESOCKETENGINE_DEBUG @@ -295,7 +296,15 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt #endif return false; } - +#else // Q_OS_VXWORKS + int onoff = 1; + if (qt_safe_ioctl(socketDescriptor, FIONBIO, &onoff) < 0) { +#ifdef QNATIVESOCKETENGINE_DEBUG + perror("QNativeSocketEnginePrivate::setOption(): ioctl(FIONBIO, 1) failed"); +#endif + return false; + } +#endif // Q_OS_VXWORKS return true; } case QNativeSocketEngine::AddressReusable: @@ -690,11 +699,8 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l // ignore the SIGPIPE signal qt_ignore_sigpipe(); - ssize_t sentBytes; - do { - sentBytes = qt_safe_sendto(socketDescriptor, data, len, - 0, sockAddrPtr, sockAddrSize); - } while (sentBytes == -1 && errno == EINTR); + ssize_t sentBytes = qt_safe_sendto(socketDescriptor, data, len, + 0, sockAddrPtr, sockAddrSize); if (sentBytes < 0) { switch (errno) { @@ -806,6 +812,7 @@ qint64 QNativeSocketEnginePrivate::nativeWrite(const char *data, qint64 len) ssize_t writtenBytes; do { writtenBytes = qt_socket_write(socketDescriptor, data, len); + // writtenBytes = QT_WRITE(socketDescriptor, data, len); ### TODO S60: Should this line be removed or the one above it? } while (writtenBytes < 0 && errno == EINTR); if (writtenBytes < 0) { @@ -869,6 +876,9 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxSize) case EPIPE: #endif case ECONNRESET: +#if defined(Q_OS_VXWORKS) + case ESHUTDOWN: +#endif r = 0; break; default: diff --git a/src/network/socket/qnet_unix_p.h b/src/network/socket/qnet_unix_p.h index 03ed3b4..f38c2fc 100644 --- a/src/network/socket/qnet_unix_p.h +++ b/src/network/socket/qnet_unix_p.h @@ -59,11 +59,18 @@ #include <sys/socket.h> #include <netinet/in.h> +#if defined(Q_OS_VXWORKS) +# include <sockLib.h> +#endif + // for inet_addr #include <netdb.h> #include <arpa/inet.h> -#include <resolv.h> - +#if defined(Q_OS_VXWORKS) +# include <hostLib.h> +#else +# include <resolv.h> +#endif QT_BEGIN_NAMESPACE @@ -155,17 +162,28 @@ static inline int qt_safe_connect(int sockfd, const struct sockaddr *addr, QT_SO # undef listen #endif +// VxWorks' headers specify 'int' instead of '...' for the 3rd ioctl() parameter. template <typename T> static inline int qt_safe_ioctl(int sockfd, int request, T arg) { +#ifdef Q_OS_VXWORKS + return ::ioctl(sockfd, request, (int) arg); +#else return ::ioctl(sockfd, request, arg); +#endif } +// VxWorks' headers do not specify any const modifiers static inline in_addr_t qt_safe_inet_addr(const char *cp) { +#ifdef Q_OS_VXWORKS + return ::inet_addr((char *) cp); +#else return ::inet_addr(cp); +#endif } +// VxWorks' headers do not specify any const modifiers static inline int qt_safe_sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *to, QT_SOCKLEN_T tolen) { #ifdef MSG_NOSIGNAL @@ -173,7 +191,11 @@ static inline int qt_safe_sendto(int sockfd, const void *buf, size_t len, int fl #endif register int ret; +#ifdef Q_OS_VXWORKS + EINTR_LOOP(ret, ::sendto(sockfd, (char *) buf, len, flags, (struct sockaddr *) to, tolen)); +#else EINTR_LOOP(ret, ::sendto(sockfd, buf, len, flags, to, tolen)); +#endif return ret; } |