summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qfilenetworkreply.cpp50
-rw-r--r--src/network/access/qfilenetworkreply_p.h7
-rw-r--r--src/network/access/qhttpnetworkheader.cpp2
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp2
-rw-r--r--src/network/access/qnetworkrequest.cpp2
-rw-r--r--src/network/kernel/qauthenticator.cpp4
-rw-r--r--src/network/kernel/qnetworkinterface.cpp4
-rw-r--r--src/network/socket/qlocalserver.cpp10
-rw-r--r--src/network/socket/qlocalsocket_tcp.cpp10
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp14
-rw-r--r--src/network/socket/qnativesocketengine.cpp8
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp2
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp8
-rw-r--r--src/network/ssl/qsslcertificate.cpp4
-rw-r--r--src/network/ssl/qsslsocket.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp2
16 files changed, 80 insertions, 51 deletions
diff --git a/src/network/access/qfilenetworkreply.cpp b/src/network/access/qfilenetworkreply.cpp
index 8c5065c..4ac9a8c 100644
--- a/src/network/access/qfilenetworkreply.cpp
+++ b/src/network/access/qfilenetworkreply.cpp
@@ -49,10 +49,15 @@
QT_BEGIN_NAMESPACE
QFileNetworkReplyPrivate::QFileNetworkReplyPrivate()
- : QNetworkReplyPrivate(), realFileSize(0)
+ : QNetworkReplyPrivate(), fileEngine(0), fileSize(0), filePos(0)
{
}
+QFileNetworkReplyPrivate::~QFileNetworkReplyPrivate()
+{
+ delete fileEngine;
+}
+
QFileNetworkReply::~QFileNetworkReply()
{
}
@@ -94,9 +99,8 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
if (fileName.isEmpty()) {
fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
}
- d->realFile.setFileName(fileName);
- QFileInfo fi(d->realFile);
+ QFileInfo fi(fileName);
if (fi.isDir()) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString());
setError(QNetworkReply::ContentOperationNotPermittedError, msg);
@@ -106,14 +110,15 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
return;
}
- bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
+ d->fileEngine = QAbstractFileEngine::create(fileName);
+ bool opened = d->fileEngine->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
// could we open the file?
if (!opened) {
QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")
- .arg(d->realFile.fileName(), d->realFile.errorString());
+ .arg(fileName, d->fileEngine->errorString());
- if (d->realFile.exists()) {
+ if (fi.exists()) {
setError(QNetworkReply::ContentAccessDenied, msg);
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied));
@@ -126,13 +131,13 @@ QFileNetworkReply::QFileNetworkReply(QObject *parent, const QNetworkRequest &req
return;
}
- d->realFileSize = fi.size();
+ d->fileSize = fi.size();
setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());
- setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize);
+ setHeader(QNetworkRequest::ContentLengthHeader, d->fileSize);
QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
- Q_ARG(qint64, d->realFileSize), Q_ARG(qint64, d->realFileSize));
+ Q_ARG(qint64, d->fileSize), Q_ARG(qint64, d->fileSize));
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
}
@@ -146,20 +151,25 @@ void QFileNetworkReply::close()
{
Q_D(QFileNetworkReply);
QNetworkReply::close();
- d->realFile.close();
+ if (d->fileEngine)
+ d->fileEngine->close();
}
void QFileNetworkReply::abort()
{
Q_D(QFileNetworkReply);
QNetworkReply::close();
- d->realFile.close();
+ if (d->fileEngine)
+ d->fileEngine->close();
}
qint64 QFileNetworkReply::bytesAvailable() const
{
Q_D(const QFileNetworkReply);
- return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
+ if (!d->fileEngine)
+ return 0;
+
+ return QNetworkReply::bytesAvailable() + d->fileSize - d->filePos;
}
bool QFileNetworkReply::isSequential () const
@@ -170,7 +180,7 @@ bool QFileNetworkReply::isSequential () const
qint64 QFileNetworkReply::size() const
{
Q_D(const QFileNetworkReply);
- return d->realFileSize;
+ return d->fileSize;
}
/*!
@@ -179,11 +189,17 @@ qint64 QFileNetworkReply::size() const
qint64 QFileNetworkReply::readData(char *data, qint64 maxlen)
{
Q_D(QFileNetworkReply);
- qint64 ret = d->realFile.read(data, maxlen);
- if (ret == 0 && bytesAvailable() == 0)
+ if (!d->fileEngine)
+ return -1;
+
+ qint64 ret = d->fileEngine->read(data, maxlen);
+ if (ret == 0 && bytesAvailable() == 0) {
return -1; // everything had been read
- else
- return ret;
+ } else if (ret > 0) {
+ d->filePos += ret;
+ }
+
+ return ret;
}
diff --git a/src/network/access/qfilenetworkreply_p.h b/src/network/access/qfilenetworkreply_p.h
index 125fa2e..710ec9f 100644
--- a/src/network/access/qfilenetworkreply_p.h
+++ b/src/network/access/qfilenetworkreply_p.h
@@ -57,6 +57,7 @@
#include "qnetworkreply_p.h"
#include "qnetworkaccessmanager.h"
#include <QFile>
+#include <QAbstractFileEngine>
QT_BEGIN_NAMESPACE
@@ -85,9 +86,11 @@ class QFileNetworkReplyPrivate: public QNetworkReplyPrivate
{
public:
QFileNetworkReplyPrivate();
+ ~QFileNetworkReplyPrivate();
- QFile realFile;
- qint64 realFileSize;
+ QAbstractFileEngine *fileEngine;
+ qint64 fileSize;
+ qint64 filePos;
virtual bool isFinished() const;
diff --git a/src/network/access/qhttpnetworkheader.cpp b/src/network/access/qhttpnetworkheader.cpp
index c2cc69c..669f9cf 100644
--- a/src/network/access/qhttpnetworkheader.cpp
+++ b/src/network/access/qhttpnetworkheader.cpp
@@ -80,7 +80,7 @@ QByteArray QHttpNetworkHeaderPrivate::headerField(const QByteArray &name, const
QByteArray result;
bool first = true;
- foreach (QByteArray value, allValues) {
+ foreach (const QByteArray &value, allValues) {
if (!first)
result += ", ";
first = false;
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index 58123b2..61a95fe 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -753,7 +753,7 @@ void QNetworkAccessHttpBackend::replyHeaderChanged()
QByteArray value = rawHeader(it->first);
if (!value.isEmpty()) {
if (qstricmp(it->first.constData(), "set-cookie") == 0)
- value += "\n";
+ value += '\n';
else
value += ", ";
}
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 6dcd05d..a2bef67 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -649,7 +649,7 @@ static QVariant parseCookieHeader(const QByteArray &raw)
{
QList<QNetworkCookie> result;
QList<QByteArray> cookieList = raw.split(';');
- foreach (QByteArray cookie, cookieList) {
+ foreach (const QByteArray &cookie, cookieList) {
QList<QNetworkCookie> parsed = QNetworkCookie::parseCookies(cookie.trimmed());
if (parsed.count() != 1)
return QVariant(); // invalid Cookie: header
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
index 193a043..e4023c8 100644
--- a/src/network/kernel/qauthenticator.cpp
+++ b/src/network/kernel/qauthenticator.cpp
@@ -270,7 +270,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header,
break;
case Ntlm:
// #### extract from header
- realm = QString();
+ realm.clear();
break;
case DigestMd5: {
realm = QString::fromLatin1(options.value("realm"));
@@ -281,7 +281,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header,
break;
}
default:
- realm = QString();
+ realm.clear();
challenge = QByteArray();
phase = Invalid;
}
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index 367e3c4..1115c63 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -541,7 +541,7 @@ QList<QNetworkInterface> QNetworkInterface::allInterfaces()
{
QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
QList<QNetworkInterface> result;
- foreach (QSharedDataPointer<QNetworkInterfacePrivate> p, privs) {
+ foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
QNetworkInterface item;
item.d = p;
result << item;
@@ -560,7 +560,7 @@ QList<QHostAddress> QNetworkInterface::allAddresses()
{
QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
QList<QHostAddress> result;
- foreach (const QSharedDataPointer<QNetworkInterfacePrivate> p, privs) {
+ foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
foreach (const QNetworkAddressEntry &entry, p->addressEntries)
result += entry.ip();
}
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index ede3c89..ef7fc02 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -122,9 +122,9 @@ void QLocalServer::close()
qDeleteAll(d->pendingConnections);
d->pendingConnections.clear();
d->closeServer();
- d->serverName = QString();
- d->fullServerName = QString();
- d->errorString = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
+ d->errorString.clear();
d->error = QAbstractSocket::UnknownSocketError;
}
@@ -226,8 +226,8 @@ bool QLocalServer::listen(const QString &name)
}
if (!d->listen(name)) {
- d->serverName = QString();
- d->fullServerName = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
return false;
}
diff --git a/src/network/socket/qlocalsocket_tcp.cpp b/src/network/socket/qlocalsocket_tcp.cpp
index 9f574d4..5b5e84f 100644
--- a/src/network/socket/qlocalsocket_tcp.cpp
+++ b/src/network/socket/qlocalsocket_tcp.cpp
@@ -102,8 +102,8 @@ void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
switch(newState) {
case QAbstractSocket::UnconnectedState:
state = QLocalSocket::UnconnectedState;
- serverName = QString();
- fullServerName = QString();
+ serverName.clear();
+ fullServerName.clear();
break;
case QAbstractSocket::ConnectingState:
state = QLocalSocket::ConnectingState;
@@ -218,7 +218,7 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|| state() == ConnectingState)
return;
- d->errorString = QString();
+ d->errorString.clear();
d->state = ConnectingState;
emit stateChanged(d->state);
@@ -333,8 +333,8 @@ void QLocalSocket::close()
{
Q_D(QLocalSocket);
d->tcpSocket->close();
- d->serverName = QString();
- d->fullServerName = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
QIODevice::close();
}
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index 73c2465..1ca11d8 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -109,8 +109,8 @@ void QLocalSocketPrivate::_q_stateChanged(QAbstractSocket::SocketState newState)
switch(newState) {
case QAbstractSocket::UnconnectedState:
state = QLocalSocket::UnconnectedState;
- serverName = QString();
- fullServerName = QString();
+ serverName.clear();
+ fullServerName.clear();
break;
case QAbstractSocket::ConnectingState:
state = QLocalSocket::ConnectingState;
@@ -225,7 +225,7 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
|| state() == ConnectingState)
return;
- d->errorString = QString();
+ d->errorString.clear();
d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
d->state = ConnectingState;
emit stateChanged(d->state);
@@ -341,7 +341,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
errorOccurred(QLocalSocket::UnknownSocketError, function);
}
connectingSocket = -1;
- connectingName = QString();
+ connectingName.clear();
connectingOpenMode = 0;
}
@@ -438,10 +438,10 @@ void QLocalSocket::close()
if (d->connectingSocket != -1)
::close(d->connectingSocket);
d->connectingSocket = -1;
- d->connectingName = QString();
+ d->connectingName.clear();
d->connectingOpenMode = 0;
- d->serverName = QString();
- d->fullServerName = QString();
+ d->serverName.clear();
+ d->fullServerName.clear();
QIODevice::close();
}
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index 6e1df93..a890b3b 100644
--- a/src/network/socket/qnativesocketengine.cpp
+++ b/src/network/socket/qnativesocketengine.cpp
@@ -778,6 +778,14 @@ qint64 QNativeSocketEngine::read(char *data, qint64 maxSize)
QNativeSocketEnginePrivate::RemoteHostClosedErrorString);
close();
return -1;
+ } else if (readBytes == -1) {
+ if (!d->hasSetSocketError) {
+ d->hasSetSocketError = true;
+ d->socketError = QAbstractSocket::NetworkError;
+ d->socketErrorString = qt_error_string();
+ }
+ close();
+ return -1;
}
return readBytes;
}
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index d3b0fe5..9a2c349 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -903,7 +903,7 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxSize)
case EBADF:
case EINVAL:
case EIO:
- setError(QAbstractSocket::NetworkError, ReadErrorString);
+ //error string is now set in read(), not here in nativeRead()
break;
#ifdef Q_OS_SYMBIAN
case EPIPE:
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 7088a57..8177b4f 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -1068,7 +1068,7 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxLength)
break;
case WSAEBADF:
case WSAEINVAL:
- setError(QAbstractSocket::NetworkError, ReadErrorString);
+ //error string is now set in read(), not here in nativeRead()
break;
case WSAECONNRESET:
case WSAECONNABORTED:
@@ -1199,8 +1199,10 @@ void QNativeSocketEnginePrivate::nativeClose()
#if defined (QTCPSOCKETENGINE_DEBUG)
qDebug("QNativeSocketEnginePrivate::nativeClose()");
#endif
- linger l = {1, 0};
- ::setsockopt(socketDescriptor, SOL_SOCKET, SO_DONTLINGER, (char*)&l, sizeof(l));
+ // We were doing a setsockopt here before with SO_DONTLINGER. (However with kind of wrong
+ // usage of parameters, it wants a BOOL but we used a struct and pretended it to be bool).
+ // We don't think setting this option should be done here, if a user wants it she/he can
+ // do it manually with socketDescriptor()/setSocketDescriptor();
::closesocket(socketDescriptor);
}
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index 9a9b1b5..fd647e2 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -634,11 +634,11 @@ QByteArray QSslCertificatePrivate::QByteArray_from_X509(X509 *x509, QSsl::Encodi
QByteArray tmp;
for (int i = 0; i <= array.size() - 64; i += 64) {
tmp += QByteArray::fromRawData(array.data() + i, 64);
- tmp += "\n";
+ tmp += '\n';
}
if (int remainder = array.size() % 64) {
tmp += QByteArray::fromRawData(array.data() + array.size() - remainder, remainder);
- tmp += "\n";
+ tmp += '\n';
}
return BEGINCERTSTRING "\n" + tmp + ENDCERTSTRING "\n";
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index 6947aa7..9623570 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -1109,7 +1109,7 @@ void QSslSocket::setCiphers(const QString &ciphers)
{
Q_D(QSslSocket);
d->configuration.ciphers.clear();
- foreach (QString cipherName, ciphers.split(QLatin1String(":"),QString::SkipEmptyParts)) {
+ foreach (const QString &cipherName, ciphers.split(QLatin1String(":"),QString::SkipEmptyParts)) {
for (int i = 0; i < 3; ++i) {
// ### Crude
QSslCipher cipher(cipherName, QSsl::SslProtocol(i));
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index 892d330..ce2aee1 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -818,7 +818,7 @@ bool QSslSocketBackendPrivate::startHandshake()
QRegExp regexp(commonName, Qt::CaseInsensitive, QRegExp::Wildcard);
if (!regexp.exactMatch(peerName)) {
bool matched = false;
- foreach (QString altName, configuration.peerCertificate
+ foreach (const QString &altName, configuration.peerCertificate
.alternateSubjectNames().values(QSsl::DnsEntry)) {
regexp.setPattern(altName);
if (regexp.exactMatch(peerName)) {