summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-01-16 17:52:29 +0100
committerJoão Abecasis <joao.abecasis@nokia.com>2012-01-16 17:53:41 +0100
commit5b250d497fd798c476765b22a2906e1c0ff1e432 (patch)
treefd4215ca375cc2402e536bf670c2977cf64ae2ef /src/network
parent2c52e9a5c1d6ef6cbf4577430e14027375465c96 (diff)
parent7a0099183a1c107126bda3b59a47651aac612426 (diff)
Merge remote-tracking branch 'gerrit/master' into containers
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/access.pri6
-rw-r--r--src/network/access/qabstractnetworkcache.cpp2
-rw-r--r--src/network/access/qabstractnetworkcache.h2
-rw-r--r--src/network/access/qabstractnetworkcache_p.h2
-rw-r--r--src/network/access/qftp.cpp55
-rw-r--r--src/network/access/qftp_p.h (renamed from src/network/access/qftp.h)15
-rw-r--r--src/network/access/qhttp.cpp3150
-rw-r--r--src/network/access/qhttp.h311
-rw-r--r--src/network/access/qhttpheader.cpp770
-rw-r--r--src/network/access/qhttpheader_p.h147
-rw-r--r--src/network/access/qhttpmultipart.cpp2
-rw-r--r--src/network/access/qhttpmultipart.h2
-rw-r--r--src/network/access/qhttpmultipart_p.h2
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp84
-rw-r--r--src/network/access/qhttpnetworkconnection_p.h7
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp26
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel_p.h4
-rw-r--r--src/network/access/qhttpnetworkheader.cpp2
-rw-r--r--src/network/access/qhttpnetworkheader_p.h2
-rw-r--r--src/network/access/qhttpnetworkreply.cpp2
-rw-r--r--src/network/access/qhttpnetworkreply_p.h2
-rw-r--r--src/network/access/qhttpnetworkrequest.cpp2
-rw-r--r--src/network/access/qhttpnetworkrequest_p.h2
-rw-r--r--src/network/access/qhttpthreaddelegate.cpp6
-rw-r--r--src/network/access/qhttpthreaddelegate_p.h2
-rw-r--r--src/network/access/qnetworkaccessauthenticationmanager.cpp14
-rw-r--r--src/network/access/qnetworkaccessauthenticationmanager_p.h4
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp2
-rw-r--r--src/network/access/qnetworkaccessbackend_p.h2
-rw-r--r--src/network/access/qnetworkaccesscache.cpp2
-rw-r--r--src/network/access/qnetworkaccesscache_p.h2
-rw-r--r--src/network/access/qnetworkaccesscachebackend.cpp2
-rw-r--r--src/network/access/qnetworkaccesscachebackend_p.h2
-rw-r--r--src/network/access/qnetworkaccessdebugpipebackend.cpp2
-rw-r--r--src/network/access/qnetworkaccessdebugpipebackend_p.h2
-rw-r--r--src/network/access/qnetworkaccessfilebackend.cpp2
-rw-r--r--src/network/access/qnetworkaccessfilebackend_p.h2
-rw-r--r--src/network/access/qnetworkaccessftpbackend.cpp2
-rw-r--r--src/network/access/qnetworkaccessftpbackend_p.h4
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp22
-rw-r--r--src/network/access/qnetworkaccessmanager.h2
-rw-r--r--src/network/access/qnetworkaccessmanager_p.h2
-rw-r--r--src/network/access/qnetworkcookie.cpp2
-rw-r--r--src/network/access/qnetworkcookie.h5
-rw-r--r--src/network/access/qnetworkcookie_p.h2
-rw-r--r--src/network/access/qnetworkcookiejar.cpp2
-rw-r--r--src/network/access/qnetworkcookiejar.h7
-rw-r--r--src/network/access/qnetworkcookiejar_p.h2
-rw-r--r--src/network/access/qnetworkdiskcache.cpp2
-rw-r--r--src/network/access/qnetworkdiskcache.h2
-rw-r--r--src/network/access/qnetworkdiskcache_p.h2
-rw-r--r--src/network/access/qnetworkreply.cpp71
-rw-r--r--src/network/access/qnetworkreply.h6
-rw-r--r--src/network/access/qnetworkreply_p.h2
-rw-r--r--src/network/access/qnetworkreplydataimpl.cpp16
-rw-r--r--src/network/access/qnetworkreplydataimpl_p.h3
-rw-r--r--src/network/access/qnetworkreplyfileimpl.cpp2
-rw-r--r--src/network/access/qnetworkreplyfileimpl_p.h2
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp15
-rw-r--r--src/network/access/qnetworkreplyhttpimpl_p.h21
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp11
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h17
-rw-r--r--src/network/access/qnetworkrequest.cpp2
-rw-r--r--src/network/access/qnetworkrequest.h2
-rw-r--r--src/network/access/qnetworkrequest_p.h2
-rw-r--r--src/network/bearer/qbearerengine.cpp2
-rw-r--r--src/network/bearer/qbearerengine_p.h2
-rw-r--r--src/network/bearer/qbearerplugin.cpp2
-rw-r--r--src/network/bearer/qbearerplugin_p.h2
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp2
-rw-r--r--src/network/bearer/qnetworkconfigmanager.h2
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp2
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.h2
-rw-r--r--src/network/bearer/qnetworkconfiguration.cpp2
-rw-r--r--src/network/bearer/qnetworkconfiguration.h2
-rw-r--r--src/network/bearer/qnetworkconfiguration_p.h2
-rw-r--r--src/network/bearer/qnetworksession.cpp2
-rw-r--r--src/network/bearer/qnetworksession.h2
-rw-r--r--src/network/bearer/qnetworksession_p.h2
-rw-r--r--src/network/bearer/qsharednetworksession.cpp2
-rw-r--r--src/network/bearer/qsharednetworksession_p.h2
-rw-r--r--src/network/kernel/qauthenticator.cpp26
-rw-r--r--src/network/kernel/qauthenticator.h2
-rw-r--r--src/network/kernel/qauthenticator_p.h3
-rw-r--r--src/network/kernel/qhostaddress.cpp2
-rw-r--r--src/network/kernel/qhostaddress.h2
-rw-r--r--src/network/kernel/qhostaddress_p.h2
-rw-r--r--src/network/kernel/qhostinfo.cpp4
-rw-r--r--src/network/kernel/qhostinfo.h2
-rw-r--r--src/network/kernel/qhostinfo_p.h4
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp6
-rw-r--r--src/network/kernel/qhostinfo_win.cpp2
-rw-r--r--src/network/kernel/qnetworkinterface.cpp2
-rw-r--r--src/network/kernel/qnetworkinterface.h2
-rw-r--r--src/network/kernel/qnetworkinterface_p.h2
-rw-r--r--src/network/kernel/qnetworkinterface_unix.cpp2
-rw-r--r--src/network/kernel/qnetworkinterface_win.cpp26
-rw-r--r--src/network/kernel/qnetworkinterface_win_p.h2
-rw-r--r--src/network/kernel/qnetworkproxy.cpp9
-rw-r--r--src/network/kernel/qnetworkproxy.h2
-rw-r--r--src/network/kernel/qnetworkproxy_generic.cpp2
-rw-r--r--src/network/kernel/qnetworkproxy_mac.cpp2
-rw-r--r--src/network/kernel/qnetworkproxy_win.cpp2
-rw-r--r--src/network/kernel/qurlinfo.cpp2
-rw-r--r--src/network/kernel/qurlinfo.h2
-rw-r--r--src/network/socket/qabstractsocket.cpp96
-rw-r--r--src/network/socket/qabstractsocket.h21
-rw-r--r--src/network/socket/qabstractsocket_p.h4
-rw-r--r--src/network/socket/qabstractsocketengine.cpp4
-rw-r--r--src/network/socket/qabstractsocketengine_p.h13
-rw-r--r--src/network/socket/qhttpsocketengine.cpp30
-rw-r--r--src/network/socket/qhttpsocketengine_p.h9
-rw-r--r--src/network/socket/qlocalserver.cpp2
-rw-r--r--src/network/socket/qlocalserver.h2
-rw-r--r--src/network/socket/qlocalserver_p.h2
-rw-r--r--src/network/socket/qlocalserver_tcp.cpp2
-rw-r--r--src/network/socket/qlocalserver_unix.cpp2
-rw-r--r--src/network/socket/qlocalserver_win.cpp2
-rw-r--r--src/network/socket/qlocalsocket.cpp8
-rw-r--r--src/network/socket/qlocalsocket.h12
-rw-r--r--src/network/socket/qlocalsocket_p.h21
-rw-r--r--src/network/socket/qlocalsocket_tcp.cpp9
-rw-r--r--src/network/socket/qlocalsocket_unix.cpp16
-rw-r--r--src/network/socket/qlocalsocket_win.cpp341
-rw-r--r--src/network/socket/qnativesocketengine.cpp8
-rw-r--r--src/network/socket/qnativesocketengine_p.h8
-rw-r--r--src/network/socket/qnativesocketengine_unix.cpp14
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp12
-rw-r--r--src/network/socket/qnet_unix_p.h2
-rw-r--r--src/network/socket/qsocks5socketengine.cpp22
-rw-r--r--src/network/socket/qsocks5socketengine_p.h10
-rw-r--r--src/network/socket/qtcpserver.cpp8
-rw-r--r--src/network/socket/qtcpserver.h8
-rw-r--r--src/network/socket/qtcpsocket.cpp4
-rw-r--r--src/network/socket/qtcpsocket.h2
-rw-r--r--src/network/socket/qtcpsocket_p.h2
-rw-r--r--src/network/socket/qudpsocket.cpp2
-rw-r--r--src/network/socket/qudpsocket.h2
-rw-r--r--src/network/ssl/qssl.cpp2
-rw-r--r--src/network/ssl/qssl.h2
-rw-r--r--src/network/ssl/qsslcertificate.cpp4
-rw-r--r--src/network/ssl/qsslcertificate.h6
-rw-r--r--src/network/ssl/qsslcertificate_p.h2
-rw-r--r--src/network/ssl/qsslcertificateextension.h4
-rw-r--r--src/network/ssl/qsslcipher.cpp2
-rw-r--r--src/network/ssl/qsslcipher.h6
-rw-r--r--src/network/ssl/qsslcipher_p.h2
-rw-r--r--src/network/ssl/qsslconfiguration.cpp2
-rw-r--r--src/network/ssl/qsslconfiguration.h6
-rw-r--r--src/network/ssl/qsslconfiguration_p.h2
-rw-r--r--src/network/ssl/qsslerror.cpp2
-rw-r--r--src/network/ssl/qsslerror.h6
-rw-r--r--src/network/ssl/qsslkey.cpp2
-rw-r--r--src/network/ssl/qsslkey.h6
-rw-r--r--src/network/ssl/qsslkey_p.h2
-rw-r--r--src/network/ssl/qsslsocket.cpp14
-rw-r--r--src/network/ssl/qsslsocket.h18
-rw-r--r--src/network/ssl/qsslsocket_openssl.cpp42
-rw-r--r--src/network/ssl/qsslsocket_openssl_p.h4
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols.cpp6
-rw-r--r--src/network/ssl/qsslsocket_openssl_symbols_p.h10
-rw-r--r--src/network/ssl/qsslsocket_p.h2
162 files changed, 1672 insertions, 4201 deletions
diff --git a/src/network/access/access.pri b/src/network/access/access.pri
index 3d5558d334..0047084eb1 100644
--- a/src/network/access/access.pri
+++ b/src/network/access/access.pri
@@ -1,8 +1,8 @@
# Qt network access module
HEADERS += \
- access/qftp.h \
- access/qhttp.h \
+ access/qftp_p.h \
+ access/qhttpheader_p.h \
access/qhttpnetworkheader_p.h \
access/qhttpnetworkrequest_p.h \
access/qhttpnetworkreply_p.h \
@@ -39,7 +39,7 @@ HEADERS += \
SOURCES += \
access/qftp.cpp \
- access/qhttp.cpp \
+ access/qhttpheader.cpp \
access/qhttpnetworkheader.cpp \
access/qhttpnetworkrequest.cpp \
access/qhttpnetworkreply.cpp \
diff --git a/src/network/access/qabstractnetworkcache.cpp b/src/network/access/qabstractnetworkcache.cpp
index c15337a0e5..638e93be53 100644
--- a/src/network/access/qabstractnetworkcache.cpp
+++ b/src/network/access/qabstractnetworkcache.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qabstractnetworkcache.h b/src/network/access/qabstractnetworkcache.h
index 3fff74cb5b..5d03756957 100644
--- a/src/network/access/qabstractnetworkcache.h
+++ b/src/network/access/qabstractnetworkcache.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qabstractnetworkcache_p.h b/src/network/access/qabstractnetworkcache_p.h
index 9b0628f829..162422f8c0 100644
--- a/src/network/access/qabstractnetworkcache_p.h
+++ b/src/network/access/qabstractnetworkcache_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index eaed4dff5a..6fafff0f56 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -42,7 +42,7 @@
//#define QFTPPI_DEBUG
//#define QFTPDTP_DEBUG
-#include "qftp.h"
+#include "private/qftp_p.h"
#include "qabstractsocket.h"
#ifndef QT_NO_FTP
@@ -825,6 +825,8 @@ void QFtpPI::connectToHost(const QString &host, quint16 port)
}
/*
+ \internal
+
Sends the sequence of commands \a cmds to the FTP server. When the commands
are all done the finished() signal is emitted. When an error occurs, the
error() signal is emitted.
@@ -970,6 +972,8 @@ void QFtpPI::readyRead()
}
/*
+ \internal
+
Process a reply from the FTP server.
Returns true if the reply was processed or false if the reply has to be
@@ -1150,6 +1154,8 @@ bool QFtpPI::processReply()
}
/*
+ \internal
+
Starts next pending command. Returns false if there are no pending commands,
otherwise it returns true.
*/
@@ -1306,6 +1312,7 @@ int QFtpPrivate::addCommand(QFtpCommand *cmd)
*
*********************************************************************/
/*!
+ \internal
\class QFtp
\brief The QFtp class provides an implementation of the client side of FTP protocol.
@@ -1409,6 +1416,7 @@ int QFtpPrivate::addCommand(QFtpCommand *cmd)
/*!
+ \internal
Constructs a QFtp object with the given \a parent.
*/
QFtp::QFtp(QObject *parent)
@@ -1435,6 +1443,7 @@ QFtp::QFtp(QObject *parent)
}
/*!
+ \internal
\enum QFtp::State
This enum defines the connection state:
@@ -1451,6 +1460,7 @@ QFtp::QFtp(QObject *parent)
\sa stateChanged() state()
*/
/*!
+ \internal
\enum QFtp::TransferMode
FTP works with two socket connections; one for commands and
@@ -1468,6 +1478,7 @@ QFtp::QFtp(QObject *parent)
data.
*/
/*!
+ \internal
\enum QFtp::TransferType
This enum identifies the data transfer type used with get and
@@ -1479,6 +1490,7 @@ QFtp::QFtp(QObject *parent)
characters will be converted to the local format.
*/
/*!
+ \internal
\enum QFtp::Error
This enum identifies the error that occurred.
@@ -1495,6 +1507,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\enum QFtp::Command
This enum is used as the return value for the currentCommand() function.
@@ -1524,6 +1537,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::stateChanged(int state)
This signal is emitted when the state of the connection changes.
@@ -1538,6 +1552,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::listInfo(const QUrlInfo &i);
This signal is emitted for each directory entry the list() command
@@ -1547,6 +1562,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::commandStarted(int id)
This signal is emitted when processing the command identified by
@@ -1556,6 +1572,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::commandFinished(int id, bool error)
This signal is emitted when processing the command identified by
@@ -1566,6 +1583,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::done(bool error)
This signal is emitted when the last pending command has finished;
@@ -1577,6 +1595,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::readyRead()
This signal is emitted in response to a get() command when there
@@ -1597,6 +1616,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::dataTransferProgress(qint64 done, qint64 total)
This signal is emitted in response to a get() or put() request to
@@ -1617,6 +1637,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
\fn void QFtp::rawCommandReply(int replyCode, const QString &detail);
This signal is emitted in response to the rawCommand() function.
@@ -1627,6 +1648,7 @@ QFtp::QFtp(QObject *parent)
*/
/*!
+ \internal
Connects to the FTP server \a host using port \a port.
The stateChanged() signal is emitted when the state of the
@@ -1655,6 +1677,7 @@ int QFtp::connectToHost(const QString &host, quint16 port)
}
/*!
+ \internal
Logs in to the FTP server with the username \a user and the
password \a password.
@@ -1681,6 +1704,7 @@ int QFtp::login(const QString &user, const QString &password)
}
/*!
+ \internal
Closes the connection to the FTP server.
The stateChanged() signal is emitted when the state of the
@@ -1704,6 +1728,7 @@ int QFtp::close()
}
/*!
+ \internal
Sets the current FTP transfer mode to \a mode. The default is QFtp::Passive.
\sa QFtp::TransferMode
@@ -1717,6 +1742,7 @@ int QFtp::setTransferMode(TransferMode mode)
}
/*!
+ \internal
Enables use of the FTP proxy on host \a host and port \a
port. Calling this function with \a host empty disables proxying.
@@ -1731,6 +1757,7 @@ int QFtp::setProxy(const QString &host, quint16 port)
}
/*!
+ \internal
Lists the contents of directory \a dir on the FTP server. If \a
dir is empty, it lists the contents of the current directory.
@@ -1760,6 +1787,7 @@ int QFtp::list(const QString &dir)
}
/*!
+ \internal
Changes the working directory of the server to \a dir.
The function does not block and returns immediately. The command
@@ -1779,6 +1807,7 @@ int QFtp::cd(const QString &dir)
}
/*!
+ \internal
Downloads the file \a file from the server.
If \a dev is 0, then the readyRead() signal is emitted when there
@@ -1832,6 +1861,7 @@ int QFtp::get(const QString &file, QIODevice *dev, TransferType type)
}
/*!
+ \internal
\overload
Writes a copy of the given \a data to the file called \a file on
@@ -1869,6 +1899,7 @@ int QFtp::put(const QByteArray &data, const QString &file, TransferType type)
}
/*!
+ \internal
Reads the data from the IO device \a dev, and writes it to the
file called \a file on the server. The data is read in chunks from
the IO device, so this overload allows you to transmit large
@@ -1897,6 +1928,7 @@ int QFtp::put(QIODevice *dev, const QString &file, TransferType type)
}
/*!
+ \internal
Deletes the file called \a file from the server.
The function does not block and returns immediately. The command
@@ -1916,6 +1948,7 @@ int QFtp::remove(const QString &file)
}
/*!
+ \internal
Creates a directory called \a dir on the server.
The function does not block and returns immediately. The command
@@ -1935,6 +1968,7 @@ int QFtp::mkdir(const QString &dir)
}
/*!
+ \internal
Removes the directory called \a dir from the server.
The function does not block and returns immediately. The command
@@ -1954,6 +1988,7 @@ int QFtp::rmdir(const QString &dir)
}
/*!
+ \internal
Renames the file called \a oldname to \a newname on the server.
The function does not block and returns immediately. The command
@@ -1976,6 +2011,7 @@ int QFtp::rename(const QString &oldname, const QString &newname)
}
/*!
+ \internal
Sends the raw FTP command \a command to the FTP server. This is
useful for low-level FTP access. If the operation you wish to
perform has an equivalent QFtp function, we recommend using the
@@ -2000,6 +2036,7 @@ int QFtp::rawCommand(const QString &command)
}
/*!
+ \internal
Returns the number of bytes that can be read from the data socket
at the moment.
@@ -2011,6 +2048,7 @@ qint64 QFtp::bytesAvailable() const
}
/*!
+ \internal
Reads \a maxlen bytes from the data socket into \a data and
returns the number of bytes read. Returns -1 if an error occurred.
@@ -2022,6 +2060,7 @@ qint64 QFtp::read(char *data, qint64 maxlen)
}
/*!
+ \internal
Reads all the bytes available from the data socket and returns
them.
@@ -2033,6 +2072,7 @@ QByteArray QFtp::readAll()
}
/*!
+ \internal
Aborts the current command and deletes all scheduled commands.
If there is an unfinished command (i.e. a command for which the
@@ -2071,6 +2111,7 @@ void QFtp::abort()
}
/*!
+ \internal
Returns the identifier of the FTP command that is being executed
or 0 if there is no command being executed.
@@ -2084,6 +2125,7 @@ int QFtp::currentId() const
}
/*!
+ \internal
Returns the command type of the FTP command being executed or \c
None if there is no command being executed.
@@ -2097,6 +2139,7 @@ QFtp::Command QFtp::currentCommand() const
}
/*!
+ \internal
Returns the QIODevice pointer that is used by the FTP command to read data
from or store data to. If there is no current FTP command being executed or
if the command does not use an IO device, this function returns 0.
@@ -2117,6 +2160,7 @@ QIODevice* QFtp::currentDevice() const
}
/*!
+ \internal
Returns true if there are any commands scheduled that have not yet
been executed; otherwise returns false.
@@ -2131,6 +2175,7 @@ bool QFtp::hasPendingCommands() const
}
/*!
+ \internal
Deletes all pending commands from the list of scheduled commands.
This does not affect the command that is being executed. If you
want to stop this as well, use abort().
@@ -2145,6 +2190,7 @@ void QFtp::clearPendingCommands()
}
/*!
+ \internal
Returns the current state of the object. When the state changes,
the stateChanged() signal is emitted.
@@ -2156,6 +2202,7 @@ QFtp::State QFtp::state() const
}
/*!
+ \internal
Returns the last error that occurred. This is useful to find out
what went wrong when receiving a commandFinished() or a done()
signal with the \c error argument set to \c true.
@@ -2168,6 +2215,7 @@ QFtp::Error QFtp::error() const
}
/*!
+ \internal
Returns a human-readable description of the last error that
occurred. This is useful for presenting a error message to the
user when receiving a commandFinished() or a done() signal with
@@ -2385,6 +2433,7 @@ void QFtpPrivate::_q_piFtpReply(int code, const QString &text)
}
/*!
+ \internal
Destructor.
*/
QFtp::~QFtp()
@@ -2397,6 +2446,6 @@ QT_END_NAMESPACE
#include "qftp.moc"
-#include "moc_qftp.cpp"
+#include "moc_qftp_p.cpp"
#endif // QT_NO_FTP
diff --git a/src/network/access/qftp.h b/src/network/access/qftp_p.h
index 671b9ba7c7..0dc6a2006f 100644
--- a/src/network/access/qftp.h
+++ b/src/network/access/qftp_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -39,6 +39,17 @@
**
****************************************************************************/
+//
+// 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.
+//
+
#ifndef QFTP_H
#define QFTP_H
@@ -56,7 +67,7 @@ QT_MODULE(Network)
class QFtpPrivate;
-class Q_NETWORK_EXPORT QFtp : public QObject
+class Q_AUTOTEST_EXPORT QFtp : public QObject
{
Q_OBJECT
diff --git a/src/network/access/qhttp.cpp b/src/network/access/qhttp.cpp
deleted file mode 100644
index f2b24221fe..0000000000
--- a/src/network/access/qhttp.cpp
+++ /dev/null
@@ -1,3150 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtNetwork module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** 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.1, 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//#define QHTTP_DEBUG
-
-#include <qplatformdefs.h>
-#include "qhttp.h"
-
-#ifndef QT_NO_HTTP
-# include "private/qobject_p.h"
-# include "qtcpsocket.h"
-# include "qsslsocket.h"
-# include "qtextstream.h"
-# include "qmap.h"
-# include "qlist.h"
-# include "qstring.h"
-# include "qstringlist.h"
-# include "qbuffer.h"
-# include "private/qringbuffer_p.h"
-# include "qcoreevent.h"
-# include "qurl.h"
-# include "qnetworkproxy.h"
-# include "qauthenticator.h"
-# include "qauthenticator_p.h"
-# include "qdebug.h"
-# include "qtimer.h"
-#endif
-
-#ifndef QT_NO_HTTP
-
-QT_BEGIN_NAMESPACE
-
-class QHttpNormalRequest;
-class QHttpRequest
-{
-public:
- QHttpRequest() : finished(false)
- { id = idCounter.fetchAndAddRelaxed(1); }
- virtual ~QHttpRequest()
- { }
-
- virtual void start(QHttp *) = 0;
- virtual bool hasRequestHeader();
- virtual QHttpRequestHeader requestHeader();
-
- virtual QIODevice *sourceDevice() = 0;
- virtual QIODevice *destinationDevice() = 0;
-
- int id;
- bool finished;
-
-private:
- static QBasicAtomicInt idCounter;
-};
-
-class QHttpPrivate : public QObjectPrivate
-{
-public:
- Q_DECLARE_PUBLIC(QHttp)
-
- inline QHttpPrivate()
- : socket(0), reconnectAttempts(2),
- deleteSocket(0), state(QHttp::Unconnected),
- error(QHttp::NoError), port(0), mode(QHttp::ConnectionModeHttp),
- toDevice(0), postDevice(0), bytesDone(0), chunkedSize(-1),
- repost(false), pendingPost(false)
- {
- }
-
- inline ~QHttpPrivate()
- {
- while (!pending.isEmpty())
- delete pending.takeFirst();
-
- if (deleteSocket)
- delete socket;
- }
-
- // private slots
- void _q_startNextRequest();
- void _q_slotReadyRead();
- void _q_slotConnected();
- void _q_slotError(QAbstractSocket::SocketError);
- void _q_slotClosed();
- void _q_slotBytesWritten(qint64 numBytes);
-#ifndef QT_NO_OPENSSL
- void _q_slotEncryptedBytesWritten(qint64 numBytes);
-#endif
- void _q_slotDoFinished();
- void _q_slotSendRequest();
- void _q_continuePost();
-
- int addRequest(QHttpNormalRequest *);
- int addRequest(QHttpRequest *);
- void finishedWithSuccess();
- void finishedWithError(const QString &detail, int errorCode);
-
- void init();
- void setState(int);
- void closeConn();
- void setSock(QTcpSocket *sock);
-
- void postMoreData();
-
- QTcpSocket *socket;
- int reconnectAttempts;
- bool deleteSocket;
- QList<QHttpRequest *> pending;
-
- QHttp::State state;
- QHttp::Error error;
- QString errorString;
-
- QString hostName;
- quint16 port;
- QHttp::ConnectionMode mode;
-
- QByteArray buffer;
- QIODevice *toDevice;
- QIODevice *postDevice;
-
- qint64 bytesDone;
- qint64 bytesTotal;
- qint64 chunkedSize;
-
- QHttpRequestHeader header;
-
- bool readHeader;
- QString headerStr;
- QHttpResponseHeader response;
-
- QRingBuffer rba;
-
-#ifndef QT_NO_NETWORKPROXY
- QNetworkProxy proxy;
- QAuthenticator proxyAuthenticator;
-#endif
- QAuthenticator authenticator;
- bool repost;
- bool hasFinishedWithError;
- bool pendingPost;
- QTimer post100ContinueTimer;
-};
-
-QBasicAtomicInt QHttpRequest::idCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
-
-bool QHttpRequest::hasRequestHeader()
-{
- return false;
-}
-
-QHttpRequestHeader QHttpRequest::requestHeader()
-{
- return QHttpRequestHeader();
-}
-
-/****************************************************
- *
- * QHttpNormalRequest
- *
- ****************************************************/
-
-class QHttpNormalRequest : public QHttpRequest
-{
-public:
- QHttpNormalRequest(const QHttpRequestHeader &h, QIODevice *d, QIODevice *t) :
- header(h), to(t)
- {
- is_ba = false;
- data.dev = d;
- }
-
- QHttpNormalRequest(const QHttpRequestHeader &h, QByteArray *d, QIODevice *t) :
- header(h), to(t)
- {
- is_ba = true;
- data.ba = d;
- }
-
- ~QHttpNormalRequest()
- {
- if (is_ba)
- delete data.ba;
- }
-
- void start(QHttp *);
- bool hasRequestHeader();
- QHttpRequestHeader requestHeader();
- inline void setRequestHeader(const QHttpRequestHeader &h) { header = h; }
-
- QIODevice *sourceDevice();
- QIODevice *destinationDevice();
-
-protected:
- QHttpRequestHeader header;
-
-private:
- union {
- QByteArray *ba;
- QIODevice *dev;
- } data;
- bool is_ba;
- QIODevice *to;
-};
-
-void QHttpNormalRequest::start(QHttp *http)
-{
- if (!http->d_func()->socket)
- http->d_func()->setSock(0);
- http->d_func()->header = header;
-
- if (is_ba) {
- http->d_func()->buffer = *data.ba;
- if (http->d_func()->buffer.size() >= 0)
- http->d_func()->header.setContentLength(http->d_func()->buffer.size());
-
- http->d_func()->postDevice = 0;
- } else {
- http->d_func()->buffer = QByteArray();
-
- if (data.dev && (data.dev->isOpen() || data.dev->open(QIODevice::ReadOnly))) {
- http->d_func()->postDevice = data.dev;
- if (http->d_func()->postDevice->size() >= 0)
- http->d_func()->header.setContentLength(http->d_func()->postDevice->size());
- } else {
- http->d_func()->postDevice = 0;
- }
- }
-
- if (to && (to->isOpen() || to->open(QIODevice::WriteOnly)))
- http->d_func()->toDevice = to;
- else
- http->d_func()->toDevice = 0;
-
- http->d_func()->reconnectAttempts = 2;
- http->d_func()->_q_slotSendRequest();
-}
-
-bool QHttpNormalRequest::hasRequestHeader()
-{
- return true;
-}
-
-QHttpRequestHeader QHttpNormalRequest::requestHeader()
-{
- return header;
-}
-
-QIODevice *QHttpNormalRequest::sourceDevice()
-{
- if (is_ba)
- return 0;
- return data.dev;
-}
-
-QIODevice *QHttpNormalRequest::destinationDevice()
-{
- return to;
-}
-
-/****************************************************
- *
- * QHttpPGHRequest
- * (like a QHttpNormalRequest, but for the convenience
- * functions put(), get() and head() -- i.e. set the
- * host header field correctly before sending the
- * request)
- *
- ****************************************************/
-
-class QHttpPGHRequest : public QHttpNormalRequest
-{
-public:
- QHttpPGHRequest(const QHttpRequestHeader &h, QIODevice *d, QIODevice *t) :
- QHttpNormalRequest(h, d, t)
- { }
-
- QHttpPGHRequest(const QHttpRequestHeader &h, QByteArray *d, QIODevice *t) :
- QHttpNormalRequest(h, d, t)
- { }
-
- ~QHttpPGHRequest()
- { }
-
- void start(QHttp *);
-};
-
-void QHttpPGHRequest::start(QHttp *http)
-{
- if (http->d_func()->port && http->d_func()->port != 80)
- header.setValue(QLatin1String("Host"), http->d_func()->hostName + QLatin1Char(':') + QString::number(http->d_func()->port));
- else
- header.setValue(QLatin1String("Host"), http->d_func()->hostName);
- QHttpNormalRequest::start(http);
-}
-
-/****************************************************
- *
- * QHttpSetHostRequest
- *
- ****************************************************/
-
-class QHttpSetHostRequest : public QHttpRequest
-{
-public:
- QHttpSetHostRequest(const QString &h, quint16 p, QHttp::ConnectionMode m)
- : hostName(h), port(p), mode(m)
- { }
-
- void start(QHttp *);
-
- QIODevice *sourceDevice()
- { return 0; }
- QIODevice *destinationDevice()
- { return 0; }
-
-private:
- QString hostName;
- quint16 port;
- QHttp::ConnectionMode mode;
-};
-
-void QHttpSetHostRequest::start(QHttp *http)
-{
- http->d_func()->hostName = hostName;
- http->d_func()->port = port;
- http->d_func()->mode = mode;
-
-#ifdef QT_NO_OPENSSL
- if (mode == QHttp::ConnectionModeHttps) {
- // SSL requested but no SSL support compiled in
- http->d_func()->finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "HTTPS connection requested but SSL support not compiled in")),
- QHttp::UnknownError);
- return;
- }
-#endif
-
- http->d_func()->finishedWithSuccess();
-}
-
-/****************************************************
- *
- * QHttpSetUserRequest
- *
- ****************************************************/
-
-class QHttpSetUserRequest : public QHttpRequest
-{
-public:
- QHttpSetUserRequest(const QString &userName, const QString &password) :
- user(userName), pass(password)
- { }
-
- void start(QHttp *);
-
- QIODevice *sourceDevice()
- { return 0; }
- QIODevice *destinationDevice()
- { return 0; }
-
-private:
- QString user;
- QString pass;
-};
-
-void QHttpSetUserRequest::start(QHttp *http)
-{
- http->d_func()->authenticator.setUser(user);
- http->d_func()->authenticator.setPassword(pass);
- http->d_func()->finishedWithSuccess();
-}
-
-#ifndef QT_NO_NETWORKPROXY
-
-/****************************************************
- *
- * QHttpSetProxyRequest
- *
- ****************************************************/
-
-class QHttpSetProxyRequest : public QHttpRequest
-{
-public:
- inline QHttpSetProxyRequest(const QNetworkProxy &proxy)
- {
- this->proxy = proxy;
- }
-
- inline void start(QHttp *http)
- {
- http->d_func()->proxy = proxy;
- QString user = proxy.user();
- if (!user.isEmpty())
- http->d_func()->proxyAuthenticator.setUser(user);
- QString password = proxy.password();
- if (!password.isEmpty())
- http->d_func()->proxyAuthenticator.setPassword(password);
- http->d_func()->finishedWithSuccess();
- }
-
- inline QIODevice *sourceDevice()
- { return 0; }
- inline QIODevice *destinationDevice()
- { return 0; }
-private:
- QNetworkProxy proxy;
-};
-
-#endif // QT_NO_NETWORKPROXY
-
-/****************************************************
- *
- * QHttpSetSocketRequest
- *
- ****************************************************/
-
-class QHttpSetSocketRequest : public QHttpRequest
-{
-public:
- QHttpSetSocketRequest(QTcpSocket *s) : socket(s)
- { }
-
- void start(QHttp *);
-
- QIODevice *sourceDevice()
- { return 0; }
- QIODevice *destinationDevice()
- { return 0; }
-
-private:
- QTcpSocket *socket;
-};
-
-void QHttpSetSocketRequest::start(QHttp *http)
-{
- http->d_func()->setSock(socket);
- http->d_func()->finishedWithSuccess();
-}
-
-/****************************************************
- *
- * QHttpCloseRequest
- *
- ****************************************************/
-
-class QHttpCloseRequest : public QHttpRequest
-{
-public:
- QHttpCloseRequest()
- { }
- void start(QHttp *);
-
- QIODevice *sourceDevice()
- { return 0; }
- QIODevice *destinationDevice()
- { return 0; }
-};
-
-void QHttpCloseRequest::start(QHttp *http)
-{
- http->d_func()->closeConn();
-}
-
-class QHttpHeaderPrivate
-{
- Q_DECLARE_PUBLIC(QHttpHeader)
-public:
- inline virtual ~QHttpHeaderPrivate() {}
-
- QList<QPair<QString, QString> > values;
- bool valid;
- QHttpHeader *q_ptr;
-};
-
-/****************************************************
- *
- * QHttpHeader
- *
- ****************************************************/
-
-/*!
- \class QHttpHeader
- \obsolete
- \brief The QHttpHeader class contains header information for HTTP.
-
- \ingroup network
- \inmodule QtNetwork
-
- In most cases you should use the more specialized derivatives of
- this class, QHttpResponseHeader and QHttpRequestHeader, rather
- than directly using QHttpHeader.
-
- QHttpHeader provides the HTTP header fields. A HTTP header field
- consists of a name followed by a colon, a single space, and the
- field value. (See RFC 1945.) Field names are case-insensitive. A
- typical header field looks like this:
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 0
-
- In the API the header field name is called the "key" and the
- content is called the "value". You can get and set a header
- field's value by using its key with value() and setValue(), e.g.
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 1
-
- Some fields are so common that getters and setters are provided
- for them as a convenient alternative to using \l value() and
- \l setValue(), e.g. contentLength() and contentType(),
- setContentLength() and setContentType().
-
- Each header key has a \e single value associated with it. If you
- set the value for a key which already exists the previous value
- will be discarded.
-
- \sa QHttpRequestHeader QHttpResponseHeader
-*/
-
-/*!
- \fn int QHttpHeader::majorVersion() const
-
- Returns the major protocol-version of the HTTP header.
-*/
-
-/*!
- \fn int QHttpHeader::minorVersion() const
-
- Returns the minor protocol-version of the HTTP header.
-*/
-
-/*!
- Constructs an empty HTTP header.
-*/
-QHttpHeader::QHttpHeader()
- : d_ptr(new QHttpHeaderPrivate)
-{
- Q_D(QHttpHeader);
- d->q_ptr = this;
- d->valid = true;
-}
-
-/*!
- Constructs a copy of \a header.
-*/
-QHttpHeader::QHttpHeader(const QHttpHeader &header)
- : d_ptr(new QHttpHeaderPrivate)
-{
- Q_D(QHttpHeader);
- d->q_ptr = this;
- d->valid = header.d_func()->valid;
- d->values = header.d_func()->values;
-}
-
-/*!
- Constructs a HTTP header for \a str.
-
- This constructor parses the string \a str for header fields and
- adds this information. The \a str should consist of one or more
- "\r\n" delimited lines; each of these lines should have the format
- key, colon, space, value.
-*/
-QHttpHeader::QHttpHeader(const QString &str)
- : d_ptr(new QHttpHeaderPrivate)
-{
- Q_D(QHttpHeader);
- d->q_ptr = this;
- d->valid = true;
- parse(str);
-}
-
-/*! \internal
- */
-QHttpHeader::QHttpHeader(QHttpHeaderPrivate &dd, const QString &str)
- : d_ptr(&dd)
-{
- Q_D(QHttpHeader);
- d->q_ptr = this;
- d->valid = true;
- if (!str.isEmpty())
- parse(str);
-}
-
-/*! \internal
- */
-QHttpHeader::QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header)
- : d_ptr(&dd)
-{
- Q_D(QHttpHeader);
- d->q_ptr = this;
- d->valid = header.d_func()->valid;
- d->values = header.d_func()->values;
-}
-/*!
- Destructor.
-*/
-QHttpHeader::~QHttpHeader()
-{
-}
-
-/*!
- Assigns \a h and returns a reference to this http header.
-*/
-QHttpHeader &QHttpHeader::operator=(const QHttpHeader &h)
-{
- Q_D(QHttpHeader);
- d->values = h.d_func()->values;
- d->valid = h.d_func()->valid;
- return *this;
-}
-
-/*!
- Returns true if the HTTP header is valid; otherwise returns false.
-
- A QHttpHeader is invalid if it was created by parsing a malformed string.
-*/
-bool QHttpHeader::isValid() const
-{
- Q_D(const QHttpHeader);
- return d->valid;
-}
-
-/*! \internal
- Parses the HTTP header string \a str for header fields and adds
- the keys/values it finds. If the string is not parsed successfully
- the QHttpHeader becomes \link isValid() invalid\endlink.
-
- Returns true if \a str was successfully parsed; otherwise returns false.
-
- \sa toString()
-*/
-bool QHttpHeader::parse(const QString &str)
-{
- Q_D(QHttpHeader);
- QStringList lst;
- int pos = str.indexOf(QLatin1Char('\n'));
- if (pos > 0 && str.at(pos - 1) == QLatin1Char('\r'))
- lst = str.trimmed().split(QLatin1String("\r\n"));
- else
- lst = str.trimmed().split(QLatin1String("\n"));
- lst.removeAll(QString()); // No empties
-
- if (lst.isEmpty())
- return true;
-
- QStringList lines;
- QStringList::Iterator it = lst.begin();
- for (; it != lst.end(); ++it) {
- if (!(*it).isEmpty()) {
- if ((*it)[0].isSpace()) {
- if (!lines.isEmpty()) {
- lines.last() += QLatin1Char(' ');
- lines.last() += (*it).trimmed();
- }
- } else {
- lines.append((*it));
- }
- }
- }
-
- int number = 0;
- it = lines.begin();
- for (; it != lines.end(); ++it) {
- if (!parseLine(*it, number++)) {
- d->valid = false;
- return false;
- }
- }
- return true;
-}
-
-/*! \internal
-*/
-void QHttpHeader::setValid(bool v)
-{
- Q_D(QHttpHeader);
- d->valid = v;
-}
-
-/*!
- Returns the first value for the entry with the given \a key. If no entry
- has this \a key, an empty string is returned.
-
- \sa setValue() removeValue() hasKey() keys()
-*/
-QString QHttpHeader::value(const QString &key) const
-{
- Q_D(const QHttpHeader);
- QString lowercaseKey = key.toLower();
- QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
- while (it != d->values.constEnd()) {
- if ((*it).first.toLower() == lowercaseKey)
- return (*it).second;
- ++it;
- }
- return QString();
-}
-
-/*!
- Returns all the entries with the given \a key. If no entry
- has this \a key, an empty string list is returned.
-*/
-QStringList QHttpHeader::allValues(const QString &key) const
-{
- Q_D(const QHttpHeader);
- QString lowercaseKey = key.toLower();
- QStringList valueList;
- QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
- while (it != d->values.constEnd()) {
- if ((*it).first.toLower() == lowercaseKey)
- valueList.append((*it).second);
- ++it;
- }
- return valueList;
-}
-
-/*!
- Returns a list of the keys in the HTTP header.
-
- \sa hasKey()
-*/
-QStringList QHttpHeader::keys() const
-{
- Q_D(const QHttpHeader);
- QStringList keyList;
- QSet<QString> seenKeys;
- QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
- while (it != d->values.constEnd()) {
- const QString &key = (*it).first;
- QString lowercaseKey = key.toLower();
- if (!seenKeys.contains(lowercaseKey)) {
- keyList.append(key);
- seenKeys.insert(lowercaseKey);
- }
- ++it;
- }
- return keyList;
-}
-
-/*!
- Returns true if the HTTP header has an entry with the given \a
- key; otherwise returns false.
-
- \sa value() setValue() keys()
-*/
-bool QHttpHeader::hasKey(const QString &key) const
-{
- Q_D(const QHttpHeader);
- QString lowercaseKey = key.toLower();
- QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
- while (it != d->values.constEnd()) {
- if ((*it).first.toLower() == lowercaseKey)
- return true;
- ++it;
- }
- return false;
-}
-
-/*!
- Sets the value of the entry with the \a key to \a value.
-
- If no entry with \a key exists, a new entry with the given \a key
- and \a value is created. If an entry with the \a key already
- exists, the first value is discarded and replaced with the given
- \a value.
-
- \sa value() hasKey() removeValue()
-*/
-void QHttpHeader::setValue(const QString &key, const QString &value)
-{
- Q_D(QHttpHeader);
- QString lowercaseKey = key.toLower();
- QList<QPair<QString, QString> >::Iterator it = d->values.begin();
- while (it != d->values.end()) {
- if ((*it).first.toLower() == lowercaseKey) {
- (*it).second = value;
- return;
- }
- ++it;
- }
- // not found so add
- addValue(key, value);
-}
-
-/*!
- Sets the header entries to be the list of key value pairs in \a values.
-*/
-void QHttpHeader::setValues(const QList<QPair<QString, QString> > &values)
-{
- Q_D(QHttpHeader);
- d->values = values;
-}
-
-/*!
- Adds a new entry with the \a key and \a value.
-*/
-void QHttpHeader::addValue(const QString &key, const QString &value)
-{
- Q_D(QHttpHeader);
- d->values.append(qMakePair(key, value));
-}
-
-/*!
- Returns all the entries in the header.
-*/
-QList<QPair<QString, QString> > QHttpHeader::values() const
-{
- Q_D(const QHttpHeader);
- return d->values;
-}
-
-/*!
- Removes the entry with the key \a key from the HTTP header.
-
- \sa value() setValue()
-*/
-void QHttpHeader::removeValue(const QString &key)
-{
- Q_D(QHttpHeader);
- QString lowercaseKey = key.toLower();
- QList<QPair<QString, QString> >::Iterator it = d->values.begin();
- while (it != d->values.end()) {
- if ((*it).first.toLower() == lowercaseKey) {
- d->values.erase(it);
- return;
- }
- ++it;
- }
-}
-
-/*!
- Removes all the entries with the key \a key from the HTTP header.
-*/
-void QHttpHeader::removeAllValues(const QString &key)
-{
- Q_D(QHttpHeader);
- QString lowercaseKey = key.toLower();
- QList<QPair<QString, QString> >::Iterator it = d->values.begin();
- while (it != d->values.end()) {
- if ((*it).first.toLower() == lowercaseKey) {
- it = d->values.erase(it);
- continue;
- }
- ++it;
- }
-}
-
-/*! \internal
- Parses the single HTTP header line \a line which has the format
- key, colon, space, value, and adds key/value to the headers. The
- linenumber is \a number. Returns true if the line was successfully
- parsed and the key/value added; otherwise returns false.
-
- \sa parse()
-*/
-bool QHttpHeader::parseLine(const QString &line, int)
-{
- int i = line.indexOf(QLatin1Char(':'));
- if (i == -1)
- return false;
-
- addValue(line.left(i).trimmed(), line.mid(i + 1).trimmed());
-
- return true;
-}
-
-/*!
- Returns a string representation of the HTTP header.
-
- The string is suitable for use by the constructor that takes a
- QString. It consists of lines with the format: key, colon, space,
- value, "\r\n".
-*/
-QString QHttpHeader::toString() const
-{
- Q_D(const QHttpHeader);
- if (!isValid())
- return QLatin1String("");
-
- QString ret = QLatin1String("");
-
- QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
- while (it != d->values.constEnd()) {
- ret += (*it).first + QLatin1String(": ") + (*it).second + QLatin1String("\r\n");
- ++it;
- }
- return ret;
-}
-
-/*!
- Returns true if the header has an entry for the special HTTP
- header field \c content-length; otherwise returns false.
-
- \sa contentLength() setContentLength()
-*/
-bool QHttpHeader::hasContentLength() const
-{
- return hasKey(QLatin1String("content-length"));
-}
-
-/*!
- Returns the value of the special HTTP header field \c
- content-length.
-
- \sa setContentLength() hasContentLength()
-*/
-uint QHttpHeader::contentLength() const
-{
- return value(QLatin1String("content-length")).toUInt();
-}
-
-/*!
- Sets the value of the special HTTP header field \c content-length
- to \a len.
-
- \sa contentLength() hasContentLength()
-*/
-void QHttpHeader::setContentLength(int len)
-{
- setValue(QLatin1String("content-length"), QString::number(len));
-}
-
-/*!
- Returns true if the header has an entry for the special HTTP
- header field \c content-type; otherwise returns false.
-
- \sa contentType() setContentType()
-*/
-bool QHttpHeader::hasContentType() const
-{
- return hasKey(QLatin1String("content-type"));
-}
-
-/*!
- Returns the value of the special HTTP header field \c content-type.
-
- \sa setContentType() hasContentType()
-*/
-QString QHttpHeader::contentType() const
-{
- QString type = value(QLatin1String("content-type"));
- if (type.isEmpty())
- return QString();
-
- int pos = type.indexOf(QLatin1Char(';'));
- if (pos == -1)
- return type;
-
- return type.left(pos).trimmed();
-}
-
-/*!
- Sets the value of the special HTTP header field \c content-type to
- \a type.
-
- \sa contentType() hasContentType()
-*/
-void QHttpHeader::setContentType(const QString &type)
-{
- setValue(QLatin1String("content-type"), type);
-}
-
-class QHttpResponseHeaderPrivate : public QHttpHeaderPrivate
-{
- Q_DECLARE_PUBLIC(QHttpResponseHeader)
-public:
- int statCode;
- QString reasonPhr;
- int majVer;
- int minVer;
-};
-
-/****************************************************
- *
- * QHttpResponseHeader
- *
- ****************************************************/
-
-/*!
- \class QHttpResponseHeader
- \obsolete
- \brief The QHttpResponseHeader class contains response header information for HTTP.
-
- \ingroup network
- \inmodule QtNetwork
-
- This class is used by the QHttp class to report the header
- information that the client received from the server.
-
- HTTP responses have a status code that indicates the status of the
- response. This code is a 3-digit integer result code (for details
- see to RFC 1945). In addition to the status code, you can also
- specify a human-readable text that describes the reason for the
- code ("reason phrase"). This class allows you to get the status
- code and the reason phrase.
-
- \sa QHttpRequestHeader, QHttp, {HTTP Example}
-*/
-
-/*!
- Constructs an empty HTTP response header.
-*/
-QHttpResponseHeader::QHttpResponseHeader()
- : QHttpHeader(*new QHttpResponseHeaderPrivate)
-{
- setValid(false);
-}
-
-/*!
- Constructs a copy of \a header.
-*/
-QHttpResponseHeader::QHttpResponseHeader(const QHttpResponseHeader &header)
- : QHttpHeader(*new QHttpResponseHeaderPrivate, header)
-{
- Q_D(QHttpResponseHeader);
- d->statCode = header.d_func()->statCode;
- d->reasonPhr = header.d_func()->reasonPhr;
- d->majVer = header.d_func()->majVer;
- d->minVer = header.d_func()->minVer;
-}
-
-/*!
- Copies the contents of \a header into this QHttpResponseHeader.
-*/
-QHttpResponseHeader &QHttpResponseHeader::operator=(const QHttpResponseHeader &header)
-{
- Q_D(QHttpResponseHeader);
- QHttpHeader::operator=(header);
- d->statCode = header.d_func()->statCode;
- d->reasonPhr = header.d_func()->reasonPhr;
- d->majVer = header.d_func()->majVer;
- d->minVer = header.d_func()->minVer;
- return *this;
-}
-
-/*!
- Constructs a HTTP response header from the string \a str. The
- string is parsed and the information is set. The \a str should
- consist of one or more "\r\n" delimited lines; the first line should be the
- status-line (format: HTTP-version, space, status-code, space,
- reason-phrase); each of remaining lines should have the format key, colon,
- space, value.
-*/
-QHttpResponseHeader::QHttpResponseHeader(const QString &str)
- : QHttpHeader(*new QHttpResponseHeaderPrivate)
-{
- parse(str);
-}
-
-/*!
- \since 4.1
-
- Constructs a QHttpResponseHeader, setting the status code to \a code, the
- reason phrase to \a text and the protocol-version to \a majorVer and \a
- minorVer.
-
- \sa statusCode() reasonPhrase() majorVersion() minorVersion()
-*/
-QHttpResponseHeader::QHttpResponseHeader(int code, const QString &text, int majorVer, int minorVer)
- : QHttpHeader(*new QHttpResponseHeaderPrivate)
-{
- setStatusLine(code, text, majorVer, minorVer);
-}
-
-/*!
- \since 4.1
-
- Sets the status code to \a code, the reason phrase to \a text and
- the protocol-version to \a majorVer and \a minorVer.
-
- \sa statusCode() reasonPhrase() majorVersion() minorVersion()
-*/
-void QHttpResponseHeader::setStatusLine(int code, const QString &text, int majorVer, int minorVer)
-{
- Q_D(QHttpResponseHeader);
- setValid(true);
- d->statCode = code;
- d->reasonPhr = text;
- d->majVer = majorVer;
- d->minVer = minorVer;
-}
-
-/*!
- Returns the status code of the HTTP response header.
-
- \sa reasonPhrase() majorVersion() minorVersion()
-*/
-int QHttpResponseHeader::statusCode() const
-{
- Q_D(const QHttpResponseHeader);
- return d->statCode;
-}
-
-/*!
- Returns the reason phrase of the HTTP response header.
-
- \sa statusCode() majorVersion() minorVersion()
-*/
-QString QHttpResponseHeader::reasonPhrase() const
-{
- Q_D(const QHttpResponseHeader);
- return d->reasonPhr;
-}
-
-/*!
- Returns the major protocol-version of the HTTP response header.
-
- \sa minorVersion() statusCode() reasonPhrase()
-*/
-int QHttpResponseHeader::majorVersion() const
-{
- Q_D(const QHttpResponseHeader);
- return d->majVer;
-}
-
-/*!
- Returns the minor protocol-version of the HTTP response header.
-
- \sa majorVersion() statusCode() reasonPhrase()
-*/
-int QHttpResponseHeader::minorVersion() const
-{
- Q_D(const QHttpResponseHeader);
- return d->minVer;
-}
-
-/*! \internal
-*/
-bool QHttpResponseHeader::parseLine(const QString &line, int number)
-{
- Q_D(QHttpResponseHeader);
- if (number != 0)
- return QHttpHeader::parseLine(line, number);
-
- QString l = line.simplified();
- if (l.length() < 10)
- return false;
-
- if (l.left(5) == QLatin1String("HTTP/") && l[5].isDigit() && l[6] == QLatin1Char('.') &&
- l[7].isDigit() && l[8] == QLatin1Char(' ') && l[9].isDigit()) {
- d->majVer = l[5].toLatin1() - '0';
- d->minVer = l[7].toLatin1() - '0';
-
- int pos = l.indexOf(QLatin1Char(' '), 9);
- if (pos != -1) {
- d->reasonPhr = l.mid(pos + 1);
- d->statCode = l.mid(9, pos - 9).toInt();
- } else {
- d->statCode = l.mid(9).toInt();
- d->reasonPhr.clear();
- }
- } else {
- return false;
- }
-
- return true;
-}
-
-/*! \reimp
-*/
-QString QHttpResponseHeader::toString() const
-{
- Q_D(const QHttpResponseHeader);
- QString ret(QLatin1String("HTTP/%1.%2 %3 %4\r\n%5\r\n"));
- return ret.arg(d->majVer).arg(d->minVer).arg(d->statCode).arg(d->reasonPhr).arg(QHttpHeader::toString());
-}
-
-class QHttpRequestHeaderPrivate : public QHttpHeaderPrivate
-{
- Q_DECLARE_PUBLIC(QHttpRequestHeader)
-public:
- QString m;
- QString p;
- int majVer;
- int minVer;
-};
-
-/****************************************************
- *
- * QHttpRequestHeader
- *
- ****************************************************/
-
-/*!
- \class QHttpRequestHeader
- \obsolete
- \brief The QHttpRequestHeader class contains request header information for HTTP.
-
- \ingroup network
- \inmodule QtNetwork
-
- This class is used in the QHttp class to report the header
- information if the client requests something from the server.
-
- HTTP requests have a method which describes the request's action.
- The most common requests are "GET" and "POST". In addition to the
- request method the header also includes a request-URI to specify
- the location for the method to use.
-
- The method, request-URI and protocol-version can be set using a
- constructor or later using setRequest(). The values can be
- obtained using method(), path(), majorVersion() and
- minorVersion().
-
- Note that the request-URI must be in the format expected by the
- HTTP server. That is, all reserved characters must be encoded in
- %HH (where HH are two hexadecimal digits). See
- QUrl::toPercentEncoding() for more information.
-
- Important inherited functions: setValue() and value().
-
- \sa QHttpResponseHeader QHttp
-*/
-
-/*!
- Constructs an empty HTTP request header.
-*/
-QHttpRequestHeader::QHttpRequestHeader()
- : QHttpHeader(*new QHttpRequestHeaderPrivate)
-{
- setValid(false);
-}
-
-/*!
- Constructs a HTTP request header for the method \a method, the
- request-URI \a path and the protocol-version \a majorVer and \a
- minorVer. The \a path argument must be properly encoded for an
- HTTP request.
-*/
-QHttpRequestHeader::QHttpRequestHeader(const QString &method, const QString &path, int majorVer, int minorVer)
- : QHttpHeader(*new QHttpRequestHeaderPrivate)
-{
- Q_D(QHttpRequestHeader);
- d->m = method;
- d->p = path;
- d->majVer = majorVer;
- d->minVer = minorVer;
-}
-
-/*!
- Constructs a copy of \a header.
-*/
-QHttpRequestHeader::QHttpRequestHeader(const QHttpRequestHeader &header)
- : QHttpHeader(*new QHttpRequestHeaderPrivate, header)
-{
- Q_D(QHttpRequestHeader);
- d->m = header.d_func()->m;
- d->p = header.d_func()->p;
- d->majVer = header.d_func()->majVer;
- d->minVer = header.d_func()->minVer;
-}
-
-/*!
- Copies the content of \a header into this QHttpRequestHeader
-*/
-QHttpRequestHeader &QHttpRequestHeader::operator=(const QHttpRequestHeader &header)
-{
- Q_D(QHttpRequestHeader);
- QHttpHeader::operator=(header);
- d->m = header.d_func()->m;
- d->p = header.d_func()->p;
- d->majVer = header.d_func()->majVer;
- d->minVer = header.d_func()->minVer;
- return *this;
-}
-
-/*!
- Constructs a HTTP request header from the string \a str. The \a
- str should consist of one or more "\r\n" delimited lines; the first line
- should be the request-line (format: method, space, request-URI, space
- HTTP-version); each of the remaining lines should have the format key,
- colon, space, value.
-*/
-QHttpRequestHeader::QHttpRequestHeader(const QString &str)
- : QHttpHeader(*new QHttpRequestHeaderPrivate)
-{
- parse(str);
-}
-
-/*!
- This function sets the request method to \a method, the
- request-URI to \a path and the protocol-version to \a majorVer and
- \a minorVer. The \a path argument must be properly encoded for an
- HTTP request.
-
- \sa method() path() majorVersion() minorVersion()
-*/
-void QHttpRequestHeader::setRequest(const QString &method, const QString &path, int majorVer, int minorVer)
-{
- Q_D(QHttpRequestHeader);
- setValid(true);
- d->m = method;
- d->p = path;
- d->majVer = majorVer;
- d->minVer = minorVer;
-}
-
-/*!
- Returns the method of the HTTP request header.
-
- \sa path() majorVersion() minorVersion() setRequest()
-*/
-QString QHttpRequestHeader::method() const
-{
- Q_D(const QHttpRequestHeader);
- return d->m;
-}
-
-/*!
- Returns the request-URI of the HTTP request header.
-
- \sa method() majorVersion() minorVersion() setRequest()
-*/
-QString QHttpRequestHeader::path() const
-{
- Q_D(const QHttpRequestHeader);
- return d->p;
-}
-
-/*!
- Returns the major protocol-version of the HTTP request header.
-
- \sa minorVersion() method() path() setRequest()
-*/
-int QHttpRequestHeader::majorVersion() const
-{
- Q_D(const QHttpRequestHeader);
- return d->majVer;
-}
-
-/*!
- Returns the minor protocol-version of the HTTP request header.
-
- \sa majorVersion() method() path() setRequest()
-*/
-int QHttpRequestHeader::minorVersion() const
-{
- Q_D(const QHttpRequestHeader);
- return d->minVer;
-}
-
-/*! \internal
-*/
-bool QHttpRequestHeader::parseLine(const QString &line, int number)
-{
- Q_D(QHttpRequestHeader);
- if (number != 0)
- return QHttpHeader::parseLine(line, number);
-
- QStringList lst = line.simplified().split(QLatin1String(" "));
- if (lst.count() > 0) {
- d->m = lst[0];
- if (lst.count() > 1) {
- d->p = lst[1];
- if (lst.count() > 2) {
- QString v = lst[2];
- if (v.length() >= 8 && v.left(5) == QLatin1String("HTTP/") &&
- v[5].isDigit() && v[6] == QLatin1Char('.') && v[7].isDigit()) {
- d->majVer = v[5].toLatin1() - '0';
- d->minVer = v[7].toLatin1() - '0';
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-/*! \reimp
-*/
-QString QHttpRequestHeader::toString() const
-{
- Q_D(const QHttpRequestHeader);
- QString first(QLatin1String("%1 %2"));
- QString last(QLatin1String(" HTTP/%3.%4\r\n%5\r\n"));
- return first.arg(d->m).arg(d->p) +
- last.arg(d->majVer).arg(d->minVer).arg(QHttpHeader::toString());
-}
-
-
-/****************************************************
- *
- * QHttp
- *
- ****************************************************/
-/*!
- \class QHttp
- \obsolete
- \reentrant
-
- \brief The QHttp class provides an implementation of the HTTP protocol.
-
- \ingroup network
- \inmodule QtNetwork
-
-
- This class provides a direct interface to HTTP that allows you to
- download and upload data with the HTTP protocol.
- However, for new applications, it is
- recommended to use QNetworkAccessManager and QNetworkReply, as
- those classes possess a simpler, yet more powerful API
- and a more modern protocol implementation.
-
- The class works asynchronously, so there are no blocking
- functions. If an operation cannot be executed immediately, the
- function will still return straight away and the operation will be
- scheduled for later execution. The results of scheduled operations
- are reported via signals. This approach depends on the event loop
- being in operation.
-
- The operations that can be scheduled (they are called "requests"
- in the rest of the documentation) are the following: setHost(),
- get(), post(), head() and request().
-
- All of these requests return a unique identifier that allows you
- to keep track of the request that is currently executed. When the
- execution of a request starts, the requestStarted() signal with
- the identifier is emitted and when the request is finished, the
- requestFinished() signal is emitted with the identifier and a bool
- that indicates if the request finished with an error.
-
- To make an HTTP request you must set up suitable HTTP headers. The
- following example demonstrates how to request the main HTML page
- from the Qt website (i.e., the URL \c http://qt.nokia.com/index.html):
-
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 2
-
- For the common HTTP requests \c GET, \c POST and \c HEAD, QHttp
- provides the convenience functions get(), post() and head(). They
- already use a reasonable header and if you don't have to set
- special header fields, they are easier to use. The above example
- can also be written as:
-
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 3
-
- For this example the following sequence of signals is emitted
- (with small variations, depending on network traffic, etc.):
-
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 4
-
- The dataSendProgress() and dataReadProgress() signals in the above
- example are useful if you want to show a \link QProgressBar
- progress bar\endlink to inform the user about the progress of the
- download. The second argument is the total size of data. In
- certain cases it is not possible to know the total amount in
- advance, in which case the second argument is 0. (If you connect
- to a QProgressBar a total of 0 results in a busy indicator.)
-
- When the response header is read, it is reported with the
- responseHeaderReceived() signal.
-
- The readyRead() signal tells you that there is data ready to be
- read. The amount of data can then be queried with the
- bytesAvailable() function and it can be read with the read()
- or readAll() functions.
-
- If an error occurs during the execution of one of the commands in
- a sequence of commands, all the pending commands (i.e. scheduled,
- but not yet executed commands) are cleared and no signals are
- emitted for them.
-
- For example, if you have the following sequence of requests
-
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 5
-
- and the get() request fails because the host lookup fails, then
- the post() request is never executed and the signals would look
- like this:
-
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 6
-
- You can then get details about the error with the error() and
- errorString() functions. Note that only unexpected behavior, like
- network failure is considered as an error. If the server response
- contains an error status, like a 404 response, this is reported as
- a normal response case. So you should always check the \link
- QHttpResponseHeader::statusCode() status code \endlink of the
- response header.
-
- The functions currentId() and currentRequest() provide more
- information about the currently executing request.
-
- The functions hasPendingRequests() and clearPendingRequests()
- allow you to query and clear the list of pending requests.
-
- \sa QFtp, QNetworkAccessManager, QNetworkRequest, QNetworkReply,
- {HTTP Example}, {Torrent Example}
-*/
-
-/*!
- Constructs a QHttp object. The \a parent parameter is passed on
- to the QObject constructor.
-*/
-QHttp::QHttp(QObject *parent)
- : QObject(*new QHttpPrivate, parent)
-{
- Q_D(QHttp);
- d->init();
-}
-
-/*!
- Constructs a QHttp object. Subsequent requests are done by
- connecting to the server \a hostName on port \a port.
-
- The \a parent parameter is passed on to the QObject constructor.
-
- \sa setHost()
-*/
-QHttp::QHttp(const QString &hostName, quint16 port, QObject *parent)
- : QObject(*new QHttpPrivate, parent)
-{
- Q_D(QHttp);
- d->init();
-
- d->hostName = hostName;
- d->port = port;
-}
-
-/*!
- Constructs a QHttp object. Subsequent requests are done by
- connecting to the server \a hostName on port \a port using the
- connection mode \a mode.
-
- If port is 0, it will use the default port for the \a mode used
- (80 for Http and 443 for Https).
-
- The \a parent parameter is passed on to the QObject constructor.
-
- \sa setHost()
-*/
-QHttp::QHttp(const QString &hostName, ConnectionMode mode, quint16 port, QObject *parent)
- : QObject(*new QHttpPrivate, parent)
-{
- Q_D(QHttp);
- d->init();
-
- d->hostName = hostName;
- if (port == 0)
- port = (mode == ConnectionModeHttp) ? 80 : 443;
- d->port = port;
- d->mode = mode;
-}
-
-void QHttpPrivate::init()
-{
- Q_Q(QHttp);
- errorString = QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown error"));
- QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
- post100ContinueTimer.setSingleShot(true);
- QObject::connect(&post100ContinueTimer, SIGNAL(timeout()), q, SLOT(_q_continuePost()));
-}
-
-/*!
- Destroys the QHttp object. If there is an open connection, it is
- closed.
-*/
-QHttp::~QHttp()
-{
- abort();
-}
-
-/*!
- \enum QHttp::ConnectionMode
- \since 4.3
-
- This enum is used to specify the mode of connection to use:
-
- \value ConnectionModeHttp The connection is a regular HTTP connection to the server
- \value ConnectionModeHttps The HTTPS protocol is used and the connection is encrypted using SSL.
-
- When using the HTTPS mode, care should be taken to connect to the sslErrors signal, and
- handle possible SSL errors.
-
- \sa QSslSocket
-*/
-
-/*!
- \enum QHttp::State
-
- This enum is used to specify the state the client is in:
-
- \value Unconnected There is no connection to the host.
- \value HostLookup A host name lookup is in progress.
- \value Connecting An attempt to connect to the host is in progress.
- \value Sending The client is sending its request to the server.
- \value Reading The client's request has been sent and the client
- is reading the server's response.
- \value Connected The connection to the host is open, but the client is
- neither sending a request, nor waiting for a response.
- \value Closing The connection is closing down, but is not yet
- closed. (The state will be \c Unconnected when the connection is
- closed.)
-
- \sa stateChanged() state()
-*/
-
-/*! \enum QHttp::Error
-
- This enum identifies the error that occurred.
-
- \value NoError No error occurred.
- \value HostNotFound The host name lookup failed.
- \value ConnectionRefused The server refused the connection.
- \value UnexpectedClose The server closed the connection unexpectedly.
- \value InvalidResponseHeader The server sent an invalid response header.
- \value WrongContentLength The client could not read the content correctly
- because an error with respect to the content length occurred.
- \value Aborted The request was aborted with abort().
- \value ProxyAuthenticationRequiredError QHttp is using a proxy, and the
- proxy server requires authentication to establish a connection.
- \value AuthenticationRequiredError The web server requires authentication
- to complete the request.
- \value UnknownError An error other than those specified above
- occurred.
-
- \sa error()
-*/
-
-/*!
- \fn void QHttp::stateChanged(int state)
-
- This signal is emitted when the state of the QHttp object changes.
- The argument \a state is the new state of the connection; it is
- one of the \l State values.
-
- This usually happens when a request is started, but it can also
- happen when the server closes the connection or when a call to
- close() succeeded.
-
- \sa get() post() head() request() close() state() State
-*/
-
-/*!
- \fn void QHttp::responseHeaderReceived(const QHttpResponseHeader &resp);
-
- This signal is emitted when the HTTP header of a server response
- is available. The header is passed in \a resp.
-
- \sa get() post() head() request() readyRead()
-*/
-
-/*!
- \fn void QHttp::readyRead(const QHttpResponseHeader &resp)
-
- This signal is emitted when there is new response data to read.
-
- If you specified a device in the request where the data should be
- written to, then this signal is \e not emitted; instead the data
- is written directly to the device.
-
- The response header is passed in \a resp.
-
- You can read the data with the readAll() or read() functions
-
- This signal is useful if you want to process the data in chunks as
- soon as it becomes available. If you are only interested in the
- complete data, just connect to the requestFinished() signal and
- read the data then instead.
-
- \sa get() post() request() readAll() read() bytesAvailable()
-*/
-
-/*!
- \fn void QHttp::dataSendProgress(int done, int total)
-
- This signal is emitted when this object sends data to a HTTP
- server to inform it about the progress of the upload.
-
- \a done is the amount of data that has already arrived and \a
- total is the total amount of data. It is possible that the total
- amount of data that should be transferred cannot be determined, in
- which case \a total is 0.(If you connect to a QProgressBar, the
- progress bar shows a busy indicator if the total is 0).
-
- \warning \a done and \a total are not necessarily the size in
- bytes, since for large files these values might need to be
- "scaled" to avoid overflow.
-
- \sa dataReadProgress(), post(), request(), QProgressBar
-*/
-
-/*!
- \fn void QHttp::dataReadProgress(int done, int total)
-
- This signal is emitted when this object reads data from a HTTP
- server to indicate the current progress of the download.
-
- \a done is the amount of data that has already arrived and \a
- total is the total amount of data. It is possible that the total
- amount of data that should be transferred cannot be determined, in
- which case \a total is 0.(If you connect to a QProgressBar, the
- progress bar shows a busy indicator if the total is 0).
-
- \warning \a done and \a total are not necessarily the size in
- bytes, since for large files these values might need to be
- "scaled" to avoid overflow.
-
- \sa dataSendProgress() get() post() request() QProgressBar
-*/
-
-/*!
- \fn void QHttp::requestStarted(int id)
-
- This signal is emitted when processing the request identified by
- \a id starts.
-
- \sa requestFinished() done()
-*/
-
-/*!
- \fn void QHttp::requestFinished(int id, bool error)
-
- This signal is emitted when processing the request identified by
- \a id has finished. \a error is true if an error occurred during
- the processing; otherwise \a error is false.
-
- \sa requestStarted() done() error() errorString()
-*/
-
-/*!
- \fn void QHttp::done(bool error)
-
- This signal is emitted when the last pending request has finished;
- (it is emitted after the last request's requestFinished() signal).
- \a error is true if an error occurred during the processing;
- otherwise \a error is false.
-
- \sa requestFinished() error() errorString()
-*/
-
-#ifndef QT_NO_NETWORKPROXY
-
-/*!
- \fn void QHttp::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
- \since 4.3
-
- This signal can be emitted when a \a proxy that requires
- authentication is used. The \a authenticator object can then be
- filled in with the required details to allow authentication and
- continue the connection.
-
- \note It is not possible to use a QueuedConnection to connect to
- this signal, as the connection will fail if the authenticator has
- not been filled in with new information when the signal returns.
-
- \sa QAuthenticator, QNetworkProxy
-*/
-
-#endif
-
-/*!
- \fn void QHttp::authenticationRequired(const QString &hostname, quint16 port, QAuthenticator *authenticator)
- \since 4.3
-
- This signal can be emitted when a web server on a given \a hostname and \a
- port requires authentication. The \a authenticator object can then be
- filled in with the required details to allow authentication and continue
- the connection.
-
- \note It is not possible to use a QueuedConnection to connect to
- this signal, as the connection will fail if the authenticator has
- not been filled in with new information when the signal returns.
-
- \sa QAuthenticator, QNetworkProxy
-*/
-
-/*!
- \fn void QHttp::sslErrors(const QList<QSslError> &errors)
- \since 4.3
-
- Forwards the sslErrors signal from the QSslSocket used in QHttp. \a errors
- is the list of errors that occurred during the SSL handshake. Unless you
- call ignoreSslErrors() from within a slot connected to this signal when an
- error occurs, QHttp will tear down the connection immediately after
- emitting the signal.
-
- \sa QSslSocket QSslSocket::ignoreSslErrors()
-*/
-
-/*!
- Aborts the current request and deletes all scheduled requests.
-
- For the current request, the requestFinished() signal with the \c
- error argument \c true is emitted. For all other requests that are
- affected by the abort(), no signals are emitted.
-
- Since this slot also deletes the scheduled requests, there are no
- requests left and the done() signal is emitted (with the \c error
- argument \c true).
-
- \sa clearPendingRequests()
-*/
-void QHttp::abort()
-{
- Q_D(QHttp);
- if (d->pending.isEmpty())
- return;
-
- d->finishedWithError(tr("Request aborted"), Aborted);
- clearPendingRequests();
- if (d->socket)
- d->socket->abort();
- d->closeConn();
-}
-
-/*!
- Returns the number of bytes that can be read from the response
- content at the moment.
-
- \sa get() post() request() readyRead() read() readAll()
-*/
-qint64 QHttp::bytesAvailable() const
-{
- Q_D(const QHttp);
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp::bytesAvailable(): %d bytes", (int)d->rba.size());
-#endif
- return qint64(d->rba.size());
-}
-
-/*!
- Reads \a maxlen bytes from the response content into \a data and
- returns the number of bytes read. Returns -1 if an error occurred.
-
- \sa get() post() request() readyRead() bytesAvailable() readAll()
-*/
-qint64 QHttp::read(char *data, qint64 maxlen)
-{
- Q_D(QHttp);
- if (data == 0 && maxlen != 0) {
- qWarning("QHttp::read: Null pointer error");
- return -1;
- }
- if (maxlen >= d->rba.size())
- maxlen = d->rba.size();
- int readSoFar = 0;
- while (!d->rba.isEmpty() && readSoFar < maxlen) {
- int nextBlockSize = d->rba.nextDataBlockSize();
- int bytesToRead = qMin<qint64>(maxlen - readSoFar, nextBlockSize);
- memcpy(data + readSoFar, d->rba.readPointer(), bytesToRead);
- d->rba.free(bytesToRead);
- readSoFar += bytesToRead;
- }
-
- d->bytesDone += maxlen;
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp::read(): read %lld bytes (%lld bytes done)", maxlen, d->bytesDone);
-#endif
- return maxlen;
-}
-
-/*!
- Reads all the bytes from the response content and returns them.
-
- \sa get() post() request() readyRead() bytesAvailable() read()
-*/
-QByteArray QHttp::readAll()
-{
- qint64 avail = bytesAvailable();
- QByteArray tmp;
- tmp.resize(int(avail));
- qint64 got = read(tmp.data(), int(avail));
- tmp.resize(got);
- return tmp;
-}
-
-/*!
- Returns the identifier of the HTTP request being executed or 0 if
- there is no request being executed (i.e. they've all finished).
-
- \sa currentRequest()
-*/
-int QHttp::currentId() const
-{
- Q_D(const QHttp);
- if (d->pending.isEmpty())
- return 0;
- return d->pending.first()->id;
-}
-
-/*!
- Returns the request header of the HTTP request being executed. If
- the request is one issued by setHost() or close(), it
- returns an invalid request header, i.e.
- QHttpRequestHeader::isValid() returns false.
-
- \sa currentId()
-*/
-QHttpRequestHeader QHttp::currentRequest() const
-{
- Q_D(const QHttp);
- if (!d->pending.isEmpty()) {
- QHttpRequest *r = d->pending.first();
- if (r->hasRequestHeader())
- return r->requestHeader();
- }
- return QHttpRequestHeader();
-}
-
-/*!
- Returns the received response header of the most recently finished HTTP
- request. If no response has yet been received
- QHttpResponseHeader::isValid() will return false.
-
- \sa currentRequest()
-*/
-QHttpResponseHeader QHttp::lastResponse() const
-{
- Q_D(const QHttp);
- return d->response;
-}
-
-/*!
- Returns the QIODevice pointer that is used as the data source of the HTTP
- request being executed. If there is no current request or if the request
- does not use an IO device as the data source, this function returns 0.
-
- This function can be used to delete the QIODevice in the slot connected to
- the requestFinished() signal.
-
- \sa currentDestinationDevice() post() request()
-*/
-QIODevice *QHttp::currentSourceDevice() const
-{
- Q_D(const QHttp);
- if (d->pending.isEmpty())
- return 0;
- return d->pending.first()->sourceDevice();
-}
-
-/*!
- Returns the QIODevice pointer that is used as to store the data of the HTTP
- request being executed. If there is no current request or if the request
- does not store the data to an IO device, this function returns 0.
-
- This function can be used to delete the QIODevice in the slot connected to
- the requestFinished() signal.
-
- \sa currentSourceDevice() get() post() request()
-*/
-QIODevice *QHttp::currentDestinationDevice() const
-{
- Q_D(const QHttp);
- if (d->pending.isEmpty())
- return 0;
- return d->pending.first()->destinationDevice();
-}
-
-/*!
- Returns true if there are any requests scheduled that have not yet
- been executed; otherwise returns false.
-
- The request that is being executed is \e not considered as a
- scheduled request.
-
- \sa clearPendingRequests() currentId() currentRequest()
-*/
-bool QHttp::hasPendingRequests() const
-{
- Q_D(const QHttp);
- return d->pending.count() > 1;
-}
-
-/*!
- Deletes all pending requests from the list of scheduled requests.
- This does not affect the request that is being executed. If
- you want to stop this as well, use abort().
-
- \sa hasPendingRequests() abort()
-*/
-void QHttp::clearPendingRequests()
-{
- Q_D(QHttp);
- // delete all entires except the first one
- while (d->pending.count() > 1)
- delete d->pending.takeLast();
-}
-
-/*!
- Sets the HTTP server that is used for requests to \a hostName on
- port \a port.
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- \sa get() post() head() request() requestStarted() requestFinished() done()
-*/
-int QHttp::setHost(const QString &hostName, quint16 port)
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpSetHostRequest(hostName, port, ConnectionModeHttp));
-}
-
-/*!
- Sets the HTTP server that is used for requests to \a hostName on
- port \a port using the connection mode \a mode.
-
- If port is 0, it will use the default port for the \a mode used
- (80 for HTTP and 443 for HTTPS).
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- \sa get() post() head() request() requestStarted() requestFinished() done()
-*/
-int QHttp::setHost(const QString &hostName, ConnectionMode mode, quint16 port)
-{
-#ifdef QT_NO_OPENSSL
- if (mode == ConnectionModeHttps)
- qWarning("QHttp::setHost: HTTPS connection requested but SSL support not compiled in");
-#endif
- Q_D(QHttp);
- if (port == 0)
- port = (mode == ConnectionModeHttp) ? 80 : 443;
- return d->addRequest(new QHttpSetHostRequest(hostName, port, mode));
-}
-
-/*!
- Replaces the internal QTcpSocket that QHttp uses with \a
- socket. This is useful if you want to use your own custom QTcpSocket
- subclass instead of the plain QTcpSocket that QHttp uses by default.
- QHttp does not take ownership of the socket, and will not delete \a
- socket when destroyed.
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- Note: If QHttp is used in a non-GUI thread that runs its own event
- loop, you must move \a socket to that thread before calling setSocket().
-
- \sa QObject::moveToThread(), {Thread Support in Qt}
-*/
-int QHttp::setSocket(QTcpSocket *socket)
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpSetSocketRequest(socket));
-}
-
-/*!
- This function sets the user name \a userName and password \a
- password for web pages that require authentication.
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-*/
-int QHttp::setUser(const QString &userName, const QString &password)
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpSetUserRequest(userName, password));
-}
-
-#ifndef QT_NO_NETWORKPROXY
-
-/*!
- Enables HTTP proxy support, using the proxy server \a host on port \a
- port. \a username and \a password can be provided if the proxy server
- requires authentication.
-
- Example:
-
- \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 7
-
- QHttp supports non-transparent web proxy servers only, such as the Squid
- Web proxy cache server (from \l http://www.squid.org/). For transparent
- proxying, such as SOCKS5, use QNetworkProxy instead.
-
- \note setProxy() has to be called before setHost() for it to take effect.
- If setProxy() is called after setHost(), then it will not apply until after
- setHost() is called again.
-
- \sa QFtp::setProxy()
-*/
-int QHttp::setProxy(const QString &host, int port,
- const QString &username, const QString &password)
-{
- Q_D(QHttp);
- QNetworkProxy proxy(QNetworkProxy::HttpProxy, host, port, username, password);
- return d->addRequest(new QHttpSetProxyRequest(proxy));
-}
-
-/*!
- \overload
-
- Enables HTTP proxy support using the proxy settings from \a
- proxy. If \a proxy is a transparent proxy, QHttp will call
- QAbstractSocket::setProxy() on the underlying socket. If the type
- is QNetworkProxy::HttpCachingProxy, QHttp will behave like the
- previous function.
-
- \note for compatibility with Qt 4.3, if the proxy type is
- QNetworkProxy::HttpProxy and the request type is unencrypted (that
- is, ConnectionModeHttp), QHttp will treat the proxy as a caching
- proxy.
-*/
-int QHttp::setProxy(const QNetworkProxy &proxy)
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpSetProxyRequest(proxy));
-}
-
-#endif
-
-/*!
- Sends a get request for \a path to the server set by setHost() or
- as specified in the constructor.
-
- \a path must be a absolute path like \c /index.html or an
- absolute URI like \c http://example.com/index.html and
- must be encoded with either QUrl::toPercentEncoding() or
- QUrl::encodedPath().
-
- If the IO device \a to is 0 the readyRead() signal is emitted
- every time new content data is available to read.
-
- If the IO device \a to is not 0, the content data of the response
- is written directly to the device. Make sure that the \a to
- pointer is valid for the duration of the operation (it is safe to
- delete it when the requestFinished() signal is emitted).
-
- \section1 Request Processing
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- \sa setHost(), post(), head(), request(), requestStarted(),
- requestFinished(), done()
-*/
-int QHttp::get(const QString &path, QIODevice *to)
-{
- Q_D(QHttp);
- QHttpRequestHeader header(QLatin1String("GET"), path);
- header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
- return d->addRequest(new QHttpPGHRequest(header, (QIODevice *) 0, to));
-}
-
-/*!
- Sends a post request for \a path to the server set by setHost() or
- as specified in the constructor.
-
- \a path must be an absolute path like \c /index.html or an
- absolute URI like \c http://example.com/index.html and
- must be encoded with either QUrl::toPercentEncoding() or
- QUrl::encodedPath().
-
- The incoming data comes via the \a data IO device.
-
- If the IO device \a to is 0 the readyRead() signal is emitted
- every time new content data is available to read.
-
- If the IO device \a to is not 0, the content data of the response
- is written directly to the device. Make sure that the \a to
- pointer is valid for the duration of the operation (it is safe to
- delete it when the requestFinished() signal is emitted).
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- \sa setHost() get() head() request() requestStarted() requestFinished() done()
-*/
-int QHttp::post(const QString &path, QIODevice *data, QIODevice *to )
-{
- Q_D(QHttp);
- QHttpRequestHeader header(QLatin1String("POST"), path);
- header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
- return d->addRequest(new QHttpPGHRequest(header, data, to));
-}
-
-/*!
- \overload
-
- \a data is used as the content data of the HTTP request.
-*/
-int QHttp::post(const QString &path, const QByteArray &data, QIODevice *to)
-{
- Q_D(QHttp);
- QHttpRequestHeader header(QLatin1String("POST"), path);
- header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
- return d->addRequest(new QHttpPGHRequest(header, new QByteArray(data), to));
-}
-
-/*!
- Sends a header request for \a path to the server set by setHost()
- or as specified in the constructor.
-
- \a path must be an absolute path like \c /index.html or an
- absolute URI like \c http://example.com/index.html.
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- \sa setHost() get() post() request() requestStarted() requestFinished() done()
-*/
-int QHttp::head(const QString &path)
-{
- Q_D(QHttp);
- QHttpRequestHeader header(QLatin1String("HEAD"), path);
- header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
- return d->addRequest(new QHttpPGHRequest(header, (QIODevice*)0, 0));
-}
-
-/*!
- Sends a request to the server set by setHost() or as specified in
- the constructor. Uses the \a header as the HTTP request header.
- You are responsible for setting up a header that is appropriate
- for your request.
-
- The incoming data comes via the \a data IO device.
-
- If the IO device \a to is 0 the readyRead() signal is emitted
- every time new content data is available to read.
-
- If the IO device \a to is not 0, the content data of the response
- is written directly to the device. Make sure that the \a to
- pointer is valid for the duration of the operation (it is safe to
- delete it when the requestFinished() signal is emitted).
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- \sa setHost() get() post() head() requestStarted() requestFinished() done()
-*/
-int QHttp::request(const QHttpRequestHeader &header, QIODevice *data, QIODevice *to)
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpNormalRequest(header, data, to));
-}
-
-/*!
- \overload
-
- \a data is used as the content data of the HTTP request.
-*/
-int QHttp::request(const QHttpRequestHeader &header, const QByteArray &data, QIODevice *to )
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpNormalRequest(header, new QByteArray(data), to));
-}
-
-/*!
- Closes the connection; this is useful if you have a keep-alive
- connection and want to close it.
-
- For the requests issued with get(), post() and head(), QHttp sets
- the connection to be keep-alive. You can also do this using the
- header you pass to the request() function. QHttp only closes the
- connection to the HTTP server if the response header requires it
- to do so.
-
- The function does not block; instead, it returns immediately. The request
- is scheduled, and its execution is performed asynchronously. The
- function returns a unique identifier which is passed by
- requestStarted() and requestFinished().
-
- When the request is started the requestStarted() signal is
- emitted. When it is finished the requestFinished() signal is
- emitted.
-
- If you want to close the connection immediately, you have to use
- abort() instead.
-
- \sa stateChanged() abort() requestStarted() requestFinished() done()
-*/
-int QHttp::close()
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpCloseRequest());
-}
-
-/*!
- \obsolete
-
- Behaves the same as close().
-*/
-int QHttp::closeConnection()
-{
- Q_D(QHttp);
- return d->addRequest(new QHttpCloseRequest());
-}
-
-int QHttpPrivate::addRequest(QHttpNormalRequest *req)
-{
- QHttpRequestHeader h = req->requestHeader();
- if (h.path().isEmpty()) {
- // note: the following qWarning is autotested. If you change it, change the test too.
- qWarning("QHttp: empty path requested is invalid -- using '/'");
- h.setRequest(h.method(), QLatin1String("/"), h.majorVersion(), h.minorVersion());
- req->setRequestHeader(h);
- }
-
- // contine below
- return addRequest(static_cast<QHttpRequest *>(req));
-}
-
-int QHttpPrivate::addRequest(QHttpRequest *req)
-{
- Q_Q(QHttp);
- pending.append(req);
-
- if (pending.count() == 1) {
- // don't emit the requestStarted() signal before the id is returned
- QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
- }
- return req->id;
-}
-
-void QHttpPrivate::_q_startNextRequest()
-{
- Q_Q(QHttp);
- if (pending.isEmpty())
- return;
- QHttpRequest *r = pending.first();
-
- error = QHttp::NoError;
- errorString = QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown error"));
-
- if (q->bytesAvailable() != 0)
- q->readAll(); // clear the data
- emit q->requestStarted(r->id);
- r->start(q);
-}
-
-void QHttpPrivate::_q_slotSendRequest()
-{
- if (hostName.isNull()) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "No server set to connect to")),
- QHttp::UnknownError);
- return;
- }
-
- QString connectionHost = hostName;
- int connectionPort = port;
- bool sslInUse = false;
-
-#ifndef QT_NO_OPENSSL
- QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
- if (mode == QHttp::ConnectionModeHttps || (sslSocket && sslSocket->isEncrypted()))
- sslInUse = true;
-#endif
-
-#ifndef QT_NO_NETWORKPROXY
- bool cachingProxyInUse = false;
- bool transparentProxyInUse = false;
- if (proxy.type() == QNetworkProxy::DefaultProxy)
- proxy = QNetworkProxy::applicationProxy();
-
- if (proxy.type() == QNetworkProxy::HttpCachingProxy) {
- if (proxy.hostName().isEmpty())
- proxy.setType(QNetworkProxy::NoProxy);
- else
- cachingProxyInUse = true;
- } else if (proxy.type() == QNetworkProxy::HttpProxy) {
- // Compatibility behaviour: HttpProxy can be used to mean both
- // transparent and caching proxy
- if (proxy.hostName().isEmpty()) {
- proxy.setType(QNetworkProxy::NoProxy);
- } else if (sslInUse) {
- // Disallow use of caching proxy with HTTPS; instead fall back to
- // transparent HTTP CONNECT proxying.
- transparentProxyInUse = true;
- } else {
- proxy.setType(QNetworkProxy::HttpCachingProxy);
- cachingProxyInUse = true;
- }
- }
-
- // Proxy support. Insert the Proxy-Authorization item into the
- // header before it's sent off to the proxy.
- if (cachingProxyInUse) {
- QUrl proxyUrl;
- proxyUrl.setScheme(QLatin1String("http"));
- proxyUrl.setHost(hostName);
- if (port && port != 80)
- proxyUrl.setPort(port);
- QString request = QString::fromAscii(proxyUrl.resolved(QUrl::fromEncoded(header.path().toLatin1())).toEncoded());
-
- header.setRequest(header.method(), request, header.majorVersion(), header.minorVersion());
- header.setValue(QLatin1String("Proxy-Connection"), QLatin1String("keep-alive"));
-
- QAuthenticatorPrivate *auth = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
- if (auth && auth->method != QAuthenticatorPrivate::None) {
- QByteArray response = auth->calculateResponse(header.method().toLatin1(), header.path().toLatin1());
- header.setValue(QLatin1String("Proxy-Authorization"), QString::fromLatin1(response));
- }
-
- connectionHost = proxy.hostName();
- connectionPort = proxy.port();
- }
-
- if (transparentProxyInUse || sslInUse) {
- socket->setProxy(proxy);
- }
-#endif
-
- // Username support. Insert the user and password into the query
- // string.
- QAuthenticatorPrivate *auth = QAuthenticatorPrivate::getPrivate(authenticator);
- if (auth && auth->method != QAuthenticatorPrivate::None) {
- QByteArray response = auth->calculateResponse(header.method().toLatin1(), header.path().toLatin1());
- header.setValue(QLatin1String("Authorization"), QString::fromLatin1(response));
- }
-
- // Do we need to setup a new connection or can we reuse an
- // existing one?
- if (socket->peerName() != connectionHost || socket->peerPort() != connectionPort
- || socket->state() != QTcpSocket::ConnectedState
-#ifndef QT_NO_OPENSSL
- || (sslSocket && sslSocket->isEncrypted() != (mode == QHttp::ConnectionModeHttps))
-#endif
- ) {
- socket->blockSignals(true);
- socket->abort();
- socket->blockSignals(false);
-
- setState(QHttp::Connecting);
-#ifndef QT_NO_OPENSSL
- if (sslSocket && mode == QHttp::ConnectionModeHttps) {
- sslSocket->connectToHostEncrypted(hostName, port);
- } else
-#endif
- {
- socket->connectToHost(connectionHost, connectionPort);
- }
- } else {
- _q_slotConnected();
- }
-
-}
-
-void QHttpPrivate::finishedWithSuccess()
-{
- Q_Q(QHttp);
- if (pending.isEmpty())
- return;
- QHttpRequest *r = pending.first();
-
- // did we recurse?
- if (r->finished)
- return;
- r->finished = true;
- hasFinishedWithError = false;
-
- emit q->requestFinished(r->id, false);
- if (hasFinishedWithError) {
- // we recursed and changed into an error. The finishedWithError function
- // below has emitted the done(bool) signal and cleared the queue by now.
- return;
- }
-
- pending.removeFirst();
- delete r;
-
- if (pending.isEmpty()) {
- emit q->done(false);
- } else {
- _q_startNextRequest();
- }
-}
-
-void QHttpPrivate::finishedWithError(const QString &detail, int errorCode)
-{
- Q_Q(QHttp);
- if (pending.isEmpty())
- return;
- QHttpRequest *r = pending.first();
- hasFinishedWithError = true;
-
- error = QHttp::Error(errorCode);
- errorString = detail;
-
- // did we recurse?
- if (!r->finished) {
- r->finished = true;
- emit q->requestFinished(r->id, true);
- }
-
- while (!pending.isEmpty())
- delete pending.takeFirst();
- emit q->done(hasFinishedWithError);
-}
-
-void QHttpPrivate::_q_slotClosed()
-{
- Q_Q(QHttp);
-
- if (state == QHttp::Reading) {
- if (response.hasKey(QLatin1String("content-length"))) {
- // We got Content-Length, so did we get all bytes?
- if (bytesDone + q->bytesAvailable() != response.contentLength()) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Wrong content length")), QHttp::WrongContentLength);
- }
- }
- } else if (state == QHttp::Connecting || state == QHttp::Sending) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Server closed connection unexpectedly")), QHttp::UnexpectedClose);
- }
-
- postDevice = 0;
- if (state != QHttp::Closing)
- setState(QHttp::Closing);
- QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
-}
-
-void QHttpPrivate::_q_continuePost()
-{
- if (pendingPost) {
- pendingPost = false;
- setState(QHttp::Sending);
- _q_slotBytesWritten(0);
- }
-}
-
-void QHttpPrivate::_q_slotConnected()
-{
- if (state != QHttp::Sending) {
- bytesDone = 0;
- setState(QHttp::Sending);
- }
-
- QString str = header.toString();
- bytesTotal = str.length();
- socket->write(str.toLatin1(), bytesTotal);
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp: write request header %p:\n---{\n%s}---", &header, str.toLatin1().constData());
-#endif
-
- if (postDevice) {
- postDevice->seek(0); // reposition the device
- bytesTotal += postDevice->size();
- //check for 100-continue
- if (header.value(QLatin1String("expect")).contains(QLatin1String("100-continue"), Qt::CaseInsensitive)) {
- //create a time out for 2 secs.
- pendingPost = true;
- post100ContinueTimer.start(2000);
- }
- } else {
- bytesTotal += buffer.size();
- socket->write(buffer, buffer.size());
- }
-}
-
-void QHttpPrivate::_q_slotError(QAbstractSocket::SocketError err)
-{
- Q_Q(QHttp);
- postDevice = 0;
-
- if (state == QHttp::Connecting || state == QHttp::Reading || state == QHttp::Sending) {
- switch (err) {
- case QTcpSocket::ConnectionRefusedError:
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Connection refused (or timed out)")), QHttp::ConnectionRefused);
- break;
- case QTcpSocket::HostNotFoundError:
- finishedWithError(QString::fromLatin1(QT_TRANSLATE_NOOP("QHttp", "Host %1 not found"))
- .arg(socket->peerName()), QHttp::HostNotFound);
- break;
- case QTcpSocket::RemoteHostClosedError:
- if (state == QHttp::Sending && reconnectAttempts--) {
- setState(QHttp::Closing);
- setState(QHttp::Unconnected);
- socket->blockSignals(true);
- socket->abort();
- socket->blockSignals(false);
- QMetaObject::invokeMethod(q, "_q_slotSendRequest", Qt::QueuedConnection);
- return;
- }
- break;
-#ifndef QT_NO_NETWORKPROXY
- case QTcpSocket::ProxyAuthenticationRequiredError:
- finishedWithError(socket->errorString(), QHttp::ProxyAuthenticationRequiredError);
- break;
-#endif
- default:
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "HTTP request failed")), QHttp::UnknownError);
- break;
- }
- }
-
- closeConn();
-}
-
-#ifndef QT_NO_OPENSSL
-void QHttpPrivate::_q_slotEncryptedBytesWritten(qint64 written)
-{
- Q_UNUSED(written);
- postMoreData();
-}
-#endif
-
-void QHttpPrivate::_q_slotBytesWritten(qint64 written)
-{
- Q_Q(QHttp);
- bytesDone += written;
- emit q->dataSendProgress(bytesDone, bytesTotal);
- postMoreData();
-}
-
-// Send the POST data
-void QHttpPrivate::postMoreData()
-{
- if (pendingPost)
- return;
-
- if (!postDevice)
- return;
-
- // the following is backported code from Qt 4.6 QNetworkAccessManager.
- // We also have to check the encryptedBytesToWrite() if it is an SSL socket.
-#ifndef QT_NO_OPENSSL
- QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
- // if it is really an ssl socket, check more than just bytesToWrite()
- if ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) == 0) {
-#else
- if (socket->bytesToWrite() == 0) {
-#endif
- int max = qMin<qint64>(4096, postDevice->size() - postDevice->pos());
- QByteArray arr;
- arr.resize(max);
-
- int n = postDevice->read(arr.data(), max);
- if (n < 0) {
- qWarning("Could not read enough bytes from the device");
- closeConn();
- return;
- }
- if (postDevice->atEnd()) {
- postDevice = 0;
- }
-
- socket->write(arr, n);
- }
-}
-
-void QHttpPrivate::_q_slotReadyRead()
-{
- Q_Q(QHttp);
- QHttp::State oldState = state;
- if (state != QHttp::Reading) {
- setState(QHttp::Reading);
- readHeader = true;
- headerStr = QLatin1String("");
- bytesDone = 0;
- chunkedSize = -1;
- repost = false;
- }
-
- while (readHeader) {
- bool end = false;
- QString tmp;
- while (!end && socket->canReadLine()) {
- tmp = QString::fromAscii(socket->readLine());
- if (tmp == QLatin1String("\r\n") || tmp == QLatin1String("\n") || tmp.isEmpty())
- end = true;
- else
- headerStr += tmp;
- }
-
- if (!end)
- return;
-
- response = QHttpResponseHeader(headerStr);
- headerStr = QLatin1String("");
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp: read response header:\n---{\n%s}---", response.toString().toLatin1().constData());
-#endif
- // Check header
- if (!response.isValid()) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP response header")),
- QHttp::InvalidResponseHeader);
- closeConn();
- return;
- }
-
- int statusCode = response.statusCode();
- if (statusCode == 401 || statusCode == 407) { // (Proxy) Authentication required
- QAuthenticator *auth =
-#ifndef QT_NO_NETWORKPROXY
- statusCode == 407
- ? &proxyAuthenticator :
-#endif
- &authenticator;
- if (auth->isNull())
- auth->detach();
- QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*auth);
- priv->parseHttpResponse(response, (statusCode == 407));
- if (priv->phase == QAuthenticatorPrivate::Done) {
- socket->blockSignals(true);
-#ifndef QT_NO_NETWORKPROXY
- if (statusCode == 407)
- emit q->proxyAuthenticationRequired(proxy, auth);
- else
-#endif
- emit q->authenticationRequired(hostName, port, auth);
- socket->blockSignals(false);
- } else if (priv->phase == QAuthenticatorPrivate::Invalid) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Unknown authentication method")),
- QHttp::AuthenticationRequiredError);
- closeConn();
- return;
- }
-
- // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above.
- if (priv->phase == QAuthenticatorPrivate::Done) {
-#ifndef QT_NO_NETWORKPROXY
- if (statusCode == 407)
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Proxy authentication required")),
- QHttp::ProxyAuthenticationRequiredError);
- else
-#endif
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Authentication required")),
- QHttp::AuthenticationRequiredError);
- closeConn();
- return;
- } else {
- // close the connection if it isn't already and reconnect using the chosen authentication method
- bool willClose = (response.value(QLatin1String("proxy-connection")).toLower() == QLatin1String("close"))
- || (response.value(QLatin1String("connection")).toLower() == QLatin1String("close"));
- if (willClose) {
- if (socket) {
- setState(QHttp::Closing);
- socket->blockSignals(true);
- socket->close();
- socket->blockSignals(false);
- socket->readAll();
- }
- _q_slotSendRequest();
- return;
- } else {
- repost = true;
- }
- }
- } else {
- buffer.clear();
- }
-
- if (response.statusCode() == 100 && pendingPost) {
- // if we have pending POST, start sending data otherwise ignore
- post100ContinueTimer.stop();
- QMetaObject::invokeMethod(q, "_q_continuePost", Qt::QueuedConnection);
- return;
- }
-
- // The 100-continue header is ignored (in case of no 'expect:100-continue' header),
- // because when using the POST method, we send both the request header and data in
- // one chunk.
- if (response.statusCode() != 100) {
- post100ContinueTimer.stop();
- pendingPost = false;
- readHeader = false;
- if (response.hasKey(QLatin1String("transfer-encoding")) &&
- response.value(QLatin1String("transfer-encoding")).toLower().contains(QLatin1String("chunked")))
- chunkedSize = 0;
-
- if (!repost)
- emit q->responseHeaderReceived(response);
- if (state == QHttp::Unconnected || state == QHttp::Closing)
- return;
- } else {
- // Restore the state, the next incoming data will be treated as if
- // we never say the 100 response.
- state = oldState;
- }
- }
-
- bool everythingRead = false;
-
- if (q->currentRequest().method() == QLatin1String("HEAD") ||
- response.statusCode() == 304 || response.statusCode() == 204 ||
- response.statusCode() == 205) {
- // HEAD requests have only headers as replies
- // These status codes never have a body:
- // 304 Not Modified
- // 204 No Content
- // 205 Reset Content
- everythingRead = true;
- } else {
- qint64 n = socket->bytesAvailable();
- QByteArray *arr = 0;
- if (chunkedSize != -1) {
- // transfer-encoding is chunked
- for (;;) {
- // get chunk size
- if (chunkedSize == 0) {
- if (!socket->canReadLine())
- break;
- QString sizeString = QString::fromAscii(socket->readLine());
- int tPos = sizeString.indexOf(QLatin1Char(';'));
- if (tPos != -1)
- sizeString.truncate(tPos);
- bool ok;
- chunkedSize = sizeString.toInt(&ok, 16);
- if (!ok) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP chunked body")),
- QHttp::WrongContentLength);
- closeConn();
- delete arr;
- return;
- }
- if (chunkedSize == 0) // last-chunk
- chunkedSize = -2;
- }
-
- // read trailer
- while (chunkedSize == -2 && socket->canReadLine()) {
- QString read = QString::fromAscii(socket->readLine());
- if (read == QLatin1String("\r\n") || read == QLatin1String("\n"))
- chunkedSize = -1;
- }
- if (chunkedSize == -1) {
- everythingRead = true;
- break;
- }
-
- // make sure that you can read the terminating CRLF,
- // otherwise wait until next time...
- n = socket->bytesAvailable();
- if (n == 0)
- break;
- if (n == chunkedSize || n == chunkedSize+1) {
- n = chunkedSize - 1;
- if (n == 0)
- break;
- }
-
- // read data
- qint64 toRead = chunkedSize < 0 ? n : qMin(n, chunkedSize);
- if (!arr)
- arr = new QByteArray;
- uint oldArrSize = arr->size();
- arr->resize(oldArrSize + toRead);
- qint64 read = socket->read(arr->data()+oldArrSize, toRead);
- arr->resize(oldArrSize + read);
-
- chunkedSize -= read;
-
- if (chunkedSize == 0 && n - read >= 2) {
- // read terminating CRLF
- char tmp[2];
- socket->read(tmp, 2);
- if (tmp[0] != '\r' || tmp[1] != '\n') {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Invalid HTTP chunked body")),
- QHttp::WrongContentLength);
- closeConn();
- delete arr;
- return;
- }
- }
- }
- } else if (response.hasContentLength()) {
- if (repost && (n < response.contentLength())) {
- // wait for the content to be available fully
- // if repost is required, the content is ignored
- return;
- }
- n = qMin(qint64(response.contentLength() - bytesDone), n);
- if (n > 0) {
- arr = new QByteArray;
- arr->resize(n);
- qint64 read = socket->read(arr->data(), n);
- arr->resize(read);
- }
- if (bytesDone + q->bytesAvailable() + n == response.contentLength())
- everythingRead = true;
- } else if (n > 0) {
- // workaround for VC++ bug
- QByteArray temp = socket->readAll();
- arr = new QByteArray(temp);
- }
-
- if (arr && !repost) {
- n = arr->size();
- if (toDevice) {
- qint64 bytesWritten;
- bytesWritten = toDevice->write(*arr, n);
- delete arr;
- arr = 0;
- // if writing to the device does not succeed, quit with error
- if (bytesWritten == -1 || bytesWritten < n) {
- finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "Error writing response to device")), QHttp::UnknownError);
- } else {
- bytesDone += bytesWritten;
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp::_q_slotReadyRead(): read %lld bytes (%lld bytes done)", n, bytesDone);
-#endif
- }
- if (response.hasContentLength())
- emit q->dataReadProgress(bytesDone, response.contentLength());
- else
- emit q->dataReadProgress(bytesDone, 0);
- } else {
- char *ptr = rba.reserve(arr->size());
- memcpy(ptr, arr->data(), arr->size());
- delete arr;
- arr = 0;
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp::_q_slotReadyRead(): read %lld bytes (%lld bytes done)", n, bytesDone + q->bytesAvailable());
-#endif
- if (response.hasContentLength())
- emit q->dataReadProgress(bytesDone + q->bytesAvailable(), response.contentLength());
- else
- emit q->dataReadProgress(bytesDone + q->bytesAvailable(), 0);
- emit q->readyRead(response);
- }
- }
-
- delete arr;
- }
-
- if (everythingRead) {
- if (repost) {
- _q_slotSendRequest();
- return;
- }
- // Handle "Connection: close"
- if (response.value(QLatin1String("connection")).toLower() == QLatin1String("close")) {
- closeConn();
- } else {
- setState(QHttp::Connected);
- // Start a timer, so that we emit the keep alive signal
- // "after" this method returned.
- QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
- }
- }
-}
-
-void QHttpPrivate::_q_slotDoFinished()
-{
- if (state == QHttp::Connected) {
- finishedWithSuccess();
- } else if (state != QHttp::Unconnected) {
- setState(QHttp::Unconnected);
- finishedWithSuccess();
- }
-}
-
-
-/*!
- Returns the current state of the object. When the state changes,
- the stateChanged() signal is emitted.
-
- \sa State stateChanged()
-*/
-QHttp::State QHttp::state() const
-{
- Q_D(const QHttp);
- return d->state;
-}
-
-/*!
- Returns the last error that occurred. This is useful to find out
- what happened when receiving a requestFinished() or a done()
- signal with the \c error argument \c true.
-
- If you start a new request, the error status is reset to \c NoError.
-*/
-QHttp::Error QHttp::error() const
-{
- Q_D(const QHttp);
- return d->error;
-}
-
-/*!
- Returns a human-readable description of the last error that
- occurred. This is useful to present a error message to the user
- when receiving a requestFinished() or a done() signal with the \c
- error argument \c true.
-*/
-QString QHttp::errorString() const
-{
- Q_D(const QHttp);
- return d->errorString;
-}
-
-void QHttpPrivate::setState(int s)
-{
- Q_Q(QHttp);
-#if defined(QHTTP_DEBUG)
- qDebug("QHttp state changed %d -> %d", state, s);
-#endif
- state = QHttp::State(s);
- emit q->stateChanged(s);
-}
-
-void QHttpPrivate::closeConn()
-{
- Q_Q(QHttp);
- // If no connection is open -> ignore
- if (state == QHttp::Closing || state == QHttp::Unconnected)
- return;
-
- postDevice = 0;
- setState(QHttp::Closing);
-
- // Already closed ?
- if (!socket || !socket->isOpen()) {
- QMetaObject::invokeMethod(q, "_q_slotDoFinished", Qt::QueuedConnection);
- } else {
- // Close now.
- socket->close();
- }
-}
-
-void QHttpPrivate::setSock(QTcpSocket *sock)
-{
- Q_Q(const QHttp);
-
- // disconnect all existing signals
- if (socket)
- socket->disconnect();
- if (deleteSocket)
- delete socket;
-
- // use the new QTcpSocket socket, or create one if socket is 0.
- deleteSocket = (sock == 0);
- socket = sock;
- if (!socket) {
-#ifndef QT_NO_OPENSSL
- if (QSslSocket::supportsSsl())
- socket = new QSslSocket();
- else
-#endif
- socket = new QTcpSocket();
- }
-
- // connect all signals
- QObject::connect(socket, SIGNAL(connected()), q, SLOT(_q_slotConnected()));
- QObject::connect(socket, SIGNAL(disconnected()), q, SLOT(_q_slotClosed()));
- QObject::connect(socket, SIGNAL(readyRead()), q, SLOT(_q_slotReadyRead()));
- QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), q, SLOT(_q_slotError(QAbstractSocket::SocketError)));
- QObject::connect(socket, SIGNAL(bytesWritten(qint64)),
- q, SLOT(_q_slotBytesWritten(qint64)));
-#ifndef QT_NO_NETWORKPROXY
- QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
- q, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
-#endif
-
-#ifndef QT_NO_OPENSSL
- if (qobject_cast<QSslSocket *>(socket)) {
- QObject::connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
- q, SIGNAL(sslErrors(QList<QSslError>)));
- QObject::connect(socket, SIGNAL(encryptedBytesWritten(qint64)),
- q, SLOT(_q_slotEncryptedBytesWritten(qint64)));
- }
-#endif
-}
-
-/*!
- Tells the QSslSocket used for the Http connection to ignore the errors
- reported in the sslErrors() signal.
-
- Note that this function must be called from within a slot connected to the
- sslErrors() signal to have any effect.
-
- \sa QSslSocket QSslSocket::sslErrors()
-*/
-#ifndef QT_NO_OPENSSL
-void QHttp::ignoreSslErrors()
-{
- Q_D(QHttp);
- QSslSocket *sslSocket = qobject_cast<QSslSocket *>(d->socket);
- if (sslSocket)
- sslSocket->ignoreSslErrors();
-}
-#endif
-
-QT_END_NAMESPACE
-
-#include "moc_qhttp.cpp"
-
-#endif
diff --git a/src/network/access/qhttp.h b/src/network/access/qhttp.h
deleted file mode 100644
index 83b23f85f9..0000000000
--- a/src/network/access/qhttp.h
+++ /dev/null
@@ -1,311 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtNetwork module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** 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.1, 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.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QHTTP_H
-#define QHTTP_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qmap.h>
-#include <QtCore/qpair.h>
-#include <QtCore/qscopedpointer.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Network)
-
-#ifndef QT_NO_HTTP
-
-class QTcpSocket;
-class QTimerEvent;
-class QIODevice;
-class QAuthenticator;
-class QNetworkProxy;
-class QSslError;
-
-class QHttpPrivate;
-
-class QHttpHeaderPrivate;
-class Q_NETWORK_EXPORT QHttpHeader
-{
-public:
- QHttpHeader();
- QHttpHeader(const QHttpHeader &header);
- QHttpHeader(const QString &str);
- virtual ~QHttpHeader();
-
- QHttpHeader &operator=(const QHttpHeader &h);
-
- void setValue(const QString &key, const QString &value);
- void setValues(const QList<QPair<QString, QString> > &values);
- void addValue(const QString &key, const QString &value);
- QList<QPair<QString, QString> > values() const;
- bool hasKey(const QString &key) const;
- QStringList keys() const;
- QString value(const QString &key) const;
- QStringList allValues(const QString &key) const;
- void removeValue(const QString &key);
- void removeAllValues(const QString &key);
-
- // ### Qt 5: change to qint64
- bool hasContentLength() const;
- uint contentLength() const;
- void setContentLength(int len);
-
- bool hasContentType() const;
- QString contentType() const;
- void setContentType(const QString &type);
-
- virtual QString toString() const;
- bool isValid() const;
-
- virtual int majorVersion() const = 0;
- virtual int minorVersion() const = 0;
-
-protected:
- virtual bool parseLine(const QString &line, int number);
- bool parse(const QString &str);
- void setValid(bool);
-
- QHttpHeader(QHttpHeaderPrivate &dd, const QString &str = QString());
- QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header);
- QScopedPointer<QHttpHeaderPrivate> d_ptr;
-
-private:
- Q_DECLARE_PRIVATE(QHttpHeader)
-};
-
-class QHttpResponseHeaderPrivate;
-class Q_NETWORK_EXPORT QHttpResponseHeader : public QHttpHeader
-{
-public:
- QHttpResponseHeader();
- QHttpResponseHeader(const QHttpResponseHeader &header);
- QHttpResponseHeader(const QString &str);
- QHttpResponseHeader(int code, const QString &text = QString(), int majorVer = 1, int minorVer = 1);
- QHttpResponseHeader &operator=(const QHttpResponseHeader &header);
-
- void setStatusLine(int code, const QString &text = QString(), int majorVer = 1, int minorVer = 1);
-
- int statusCode() const;
- QString reasonPhrase() const;
-
- int majorVersion() const;
- int minorVersion() const;
-
- QString toString() const;
-
-protected:
- bool parseLine(const QString &line, int number);
-
-private:
- Q_DECLARE_PRIVATE(QHttpResponseHeader)
- friend class QHttpPrivate;
-};
-
-class QHttpRequestHeaderPrivate;
-class Q_NETWORK_EXPORT QHttpRequestHeader : public QHttpHeader
-{
-public:
- QHttpRequestHeader();
- QHttpRequestHeader(const QString &method, const QString &path, int majorVer = 1, int minorVer = 1);
- QHttpRequestHeader(const QHttpRequestHeader &header);
- QHttpRequestHeader(const QString &str);
- QHttpRequestHeader &operator=(const QHttpRequestHeader &header);
-
- void setRequest(const QString &method, const QString &path, int majorVer = 1, int minorVer = 1);
-
- QString method() const;
- QString path() const;
-
- int majorVersion() const;
- int minorVersion() const;
-
- QString toString() const;
-
-protected:
- bool parseLine(const QString &line, int number);
-
-private:
- Q_DECLARE_PRIVATE(QHttpRequestHeader)
-};
-
-class Q_NETWORK_EXPORT QHttp : public QObject
-{
- Q_OBJECT
-
-public:
- enum ConnectionMode {
- ConnectionModeHttp,
- ConnectionModeHttps
- };
-
- explicit QHttp(QObject *parent = 0);
- QHttp(const QString &hostname, quint16 port = 80, QObject *parent = 0);
- QHttp(const QString &hostname, ConnectionMode mode, quint16 port = 0, QObject *parent = 0);
- virtual ~QHttp();
-
- enum State {
- Unconnected,
- HostLookup,
- Connecting,
- Sending,
- Reading,
- Connected,
- Closing
- };
- enum Error {
- NoError,
- UnknownError,
- HostNotFound,
- ConnectionRefused,
- UnexpectedClose,
- InvalidResponseHeader,
- WrongContentLength,
- Aborted,
- AuthenticationRequiredError,
- ProxyAuthenticationRequiredError
- };
-
- int setHost(const QString &hostname, quint16 port = 80);
- int setHost(const QString &hostname, ConnectionMode mode, quint16 port = 0);
-
- int setSocket(QTcpSocket *socket);
- int setUser(const QString &username, const QString &password = QString());
-
-#ifndef QT_NO_NETWORKPROXY
- int setProxy(const QString &host, int port,
- const QString &username = QString(),
- const QString &password = QString());
- int setProxy(const QNetworkProxy &proxy);
-#endif
-
- int get(const QString &path, QIODevice *to=0);
- int post(const QString &path, QIODevice *data, QIODevice *to=0 );
- int post(const QString &path, const QByteArray &data, QIODevice *to=0);
- int head(const QString &path);
- int request(const QHttpRequestHeader &header, QIODevice *device=0, QIODevice *to=0);
- int request(const QHttpRequestHeader &header, const QByteArray &data, QIODevice *to=0);
-
- int closeConnection();
- int close();
-
- qint64 bytesAvailable() const;
- qint64 read(char *data, qint64 maxlen);
- QByteArray readAll();
-
- int currentId() const;
- QIODevice *currentSourceDevice() const;
- QIODevice *currentDestinationDevice() const;
- QHttpRequestHeader currentRequest() const;
- QHttpResponseHeader lastResponse() const;
- bool hasPendingRequests() const;
- void clearPendingRequests();
-
- State state() const;
-
- Error error() const;
- QString errorString() const;
-
-public Q_SLOTS:
- void abort();
-
-#ifndef QT_NO_OPENSSL
- void ignoreSslErrors();
-#endif
-
-Q_SIGNALS:
- void stateChanged(int);
- void responseHeaderReceived(const QHttpResponseHeader &resp);
- void readyRead(const QHttpResponseHeader &resp);
-
- // ### Qt 5: change to qint64
- void dataSendProgress(int, int);
- void dataReadProgress(int, int);
-
- void requestStarted(int);
- void requestFinished(int, bool);
- void done(bool);
-
-#ifndef QT_NO_NETWORKPROXY
- void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *);
-#endif
- void authenticationRequired(const QString &hostname, quint16 port, QAuthenticator *);
-
-#ifndef QT_NO_OPENSSL
- void sslErrors(const QList<QSslError> &errors);
-#endif
-
-private:
- Q_DISABLE_COPY(QHttp)
- Q_DECLARE_PRIVATE(QHttp)
-
- Q_PRIVATE_SLOT(d_func(), void _q_startNextRequest())
- Q_PRIVATE_SLOT(d_func(), void _q_slotReadyRead())
- Q_PRIVATE_SLOT(d_func(), void _q_slotConnected())
- Q_PRIVATE_SLOT(d_func(), void _q_slotError(QAbstractSocket::SocketError))
- Q_PRIVATE_SLOT(d_func(), void _q_slotClosed())
- Q_PRIVATE_SLOT(d_func(), void _q_slotBytesWritten(qint64 numBytes))
-#ifndef QT_NO_OPENSSL
- Q_PRIVATE_SLOT(d_func(), void _q_slotEncryptedBytesWritten(qint64 numBytes))
-#endif
- Q_PRIVATE_SLOT(d_func(), void _q_slotDoFinished())
- Q_PRIVATE_SLOT(d_func(), void _q_slotSendRequest())
- Q_PRIVATE_SLOT(d_func(), void _q_continuePost())
-
- friend class QHttpNormalRequest;
- friend class QHttpSetHostRequest;
- friend class QHttpSetSocketRequest;
- friend class QHttpSetUserRequest;
- friend class QHttpSetProxyRequest;
- friend class QHttpCloseRequest;
- friend class QHttpPGHRequest;
-};
-
-#endif // QT_NO_HTTP
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QHTTP_H
diff --git a/src/network/access/qhttpheader.cpp b/src/network/access/qhttpheader.cpp
new file mode 100644
index 0000000000..6e87a05c6b
--- /dev/null
+++ b/src/network/access/qhttpheader.cpp
@@ -0,0 +1,770 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//#define QHTTP_DEBUG
+
+#include <qplatformdefs.h>
+#include "qhttpheader_p.h"
+
+#ifndef QT_NO_HTTP
+# include "private/qobject_p.h"
+# include "qtcpsocket.h"
+# include "qsslsocket.h"
+# include "qtextstream.h"
+# include "qmap.h"
+# include "qlist.h"
+# include "qstring.h"
+# include "qstringlist.h"
+# include "qbuffer.h"
+# include "private/qringbuffer_p.h"
+# include "qcoreevent.h"
+# include "qurl.h"
+# include "qnetworkproxy.h"
+# include "qauthenticator.h"
+# include "qauthenticator_p.h"
+# include "qdebug.h"
+# include "qtimer.h"
+#endif
+
+#ifndef QT_NO_HTTP
+
+QT_BEGIN_NAMESPACE
+
+class QHttpHeaderPrivate
+{
+ Q_DECLARE_PUBLIC(QHttpHeader)
+public:
+ inline virtual ~QHttpHeaderPrivate() {}
+
+ QList<QPair<QString, QString> > values;
+ bool valid;
+ QHttpHeader *q_ptr;
+};
+
+/****************************************************
+ *
+ * QHttpHeader
+ *
+ ****************************************************/
+
+/*!
+ \class QHttpHeader
+ \obsolete
+ \brief The QHttpHeader class contains header information for HTTP.
+
+ \ingroup network
+ \inmodule QtNetwork
+
+ In most cases you should use the more specialized derivatives of
+ this class, QHttpResponseHeader and QHttpRequestHeader, rather
+ than directly using QHttpHeader.
+
+ QHttpHeader provides the HTTP header fields. A HTTP header field
+ consists of a name followed by a colon, a single space, and the
+ field value. (See RFC 1945.) Field names are case-insensitive. A
+ typical header field looks like this:
+ \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 0
+
+ In the API the header field name is called the "key" and the
+ content is called the "value". You can get and set a header
+ field's value by using its key with value() and setValue(), e.g.
+ \snippet doc/src/snippets/code/src_network_access_qhttp.cpp 1
+
+ Some fields are so common that getters and setters are provided
+ for them as a convenient alternative to using \l value() and
+ \l setValue(), e.g. contentLength() and contentType(),
+ setContentLength() and setContentType().
+
+ Each header key has a \e single value associated with it. If you
+ set the value for a key which already exists the previous value
+ will be discarded.
+
+ \sa QHttpRequestHeader QHttpResponseHeader
+*/
+
+/*!
+ \fn int QHttpHeader::majorVersion() const
+
+ Returns the major protocol-version of the HTTP header.
+*/
+
+/*!
+ \fn int QHttpHeader::minorVersion() const
+
+ Returns the minor protocol-version of the HTTP header.
+*/
+
+/*!
+ Constructs an empty HTTP header.
+*/
+QHttpHeader::QHttpHeader()
+ : d_ptr(new QHttpHeaderPrivate)
+{
+ Q_D(QHttpHeader);
+ d->q_ptr = this;
+ d->valid = true;
+}
+
+/*!
+ Constructs a copy of \a header.
+*/
+QHttpHeader::QHttpHeader(const QHttpHeader &header)
+ : d_ptr(new QHttpHeaderPrivate)
+{
+ Q_D(QHttpHeader);
+ d->q_ptr = this;
+ d->valid = header.d_func()->valid;
+ d->values = header.d_func()->values;
+}
+
+/*!
+ Constructs a HTTP header for \a str.
+
+ This constructor parses the string \a str for header fields and
+ adds this information. The \a str should consist of one or more
+ "\r\n" delimited lines; each of these lines should have the format
+ key, colon, space, value.
+*/
+QHttpHeader::QHttpHeader(const QString &str)
+ : d_ptr(new QHttpHeaderPrivate)
+{
+ Q_D(QHttpHeader);
+ d->q_ptr = this;
+ d->valid = true;
+ parse(str);
+}
+
+/*! \internal
+ */
+QHttpHeader::QHttpHeader(QHttpHeaderPrivate &dd, const QString &str)
+ : d_ptr(&dd)
+{
+ Q_D(QHttpHeader);
+ d->q_ptr = this;
+ d->valid = true;
+ if (!str.isEmpty())
+ parse(str);
+}
+
+/*! \internal
+ */
+QHttpHeader::QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header)
+ : d_ptr(&dd)
+{
+ Q_D(QHttpHeader);
+ d->q_ptr = this;
+ d->valid = header.d_func()->valid;
+ d->values = header.d_func()->values;
+}
+/*!
+ Destructor.
+*/
+QHttpHeader::~QHttpHeader()
+{
+}
+
+/*!
+ Assigns \a h and returns a reference to this http header.
+*/
+QHttpHeader &QHttpHeader::operator=(const QHttpHeader &h)
+{
+ Q_D(QHttpHeader);
+ d->values = h.d_func()->values;
+ d->valid = h.d_func()->valid;
+ return *this;
+}
+
+/*!
+ Returns true if the HTTP header is valid; otherwise returns false.
+
+ A QHttpHeader is invalid if it was created by parsing a malformed string.
+*/
+bool QHttpHeader::isValid() const
+{
+ Q_D(const QHttpHeader);
+ return d->valid;
+}
+
+/*! \internal
+ Parses the HTTP header string \a str for header fields and adds
+ the keys/values it finds. If the string is not parsed successfully
+ the QHttpHeader becomes \link isValid() invalid\endlink.
+
+ Returns true if \a str was successfully parsed; otherwise returns false.
+
+ \sa toString()
+*/
+bool QHttpHeader::parse(const QString &str)
+{
+ Q_D(QHttpHeader);
+ QStringList lst;
+ int pos = str.indexOf(QLatin1Char('\n'));
+ if (pos > 0 && str.at(pos - 1) == QLatin1Char('\r'))
+ lst = str.trimmed().split(QLatin1String("\r\n"));
+ else
+ lst = str.trimmed().split(QLatin1String("\n"));
+ lst.removeAll(QString()); // No empties
+
+ if (lst.isEmpty())
+ return true;
+
+ QStringList lines;
+ QStringList::Iterator it = lst.begin();
+ for (; it != lst.end(); ++it) {
+ if (!(*it).isEmpty()) {
+ if ((*it)[0].isSpace()) {
+ if (!lines.isEmpty()) {
+ lines.last() += QLatin1Char(' ');
+ lines.last() += (*it).trimmed();
+ }
+ } else {
+ lines.append((*it));
+ }
+ }
+ }
+
+ int number = 0;
+ it = lines.begin();
+ for (; it != lines.end(); ++it) {
+ if (!parseLine(*it, number++)) {
+ d->valid = false;
+ return false;
+ }
+ }
+ return true;
+}
+
+/*! \internal
+*/
+void QHttpHeader::setValid(bool v)
+{
+ Q_D(QHttpHeader);
+ d->valid = v;
+}
+
+/*!
+ Returns the first value for the entry with the given \a key. If no entry
+ has this \a key, an empty string is returned.
+
+ \sa setValue() removeValue() hasKey() keys()
+*/
+QString QHttpHeader::value(const QString &key) const
+{
+ Q_D(const QHttpHeader);
+ QString lowercaseKey = key.toLower();
+ QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
+ while (it != d->values.constEnd()) {
+ if ((*it).first.toLower() == lowercaseKey)
+ return (*it).second;
+ ++it;
+ }
+ return QString();
+}
+
+/*!
+ Returns all the entries with the given \a key. If no entry
+ has this \a key, an empty string list is returned.
+*/
+QStringList QHttpHeader::allValues(const QString &key) const
+{
+ Q_D(const QHttpHeader);
+ QString lowercaseKey = key.toLower();
+ QStringList valueList;
+ QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
+ while (it != d->values.constEnd()) {
+ if ((*it).first.toLower() == lowercaseKey)
+ valueList.append((*it).second);
+ ++it;
+ }
+ return valueList;
+}
+
+/*!
+ Returns a list of the keys in the HTTP header.
+
+ \sa hasKey()
+*/
+QStringList QHttpHeader::keys() const
+{
+ Q_D(const QHttpHeader);
+ QStringList keyList;
+ QSet<QString> seenKeys;
+ QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
+ while (it != d->values.constEnd()) {
+ const QString &key = (*it).first;
+ QString lowercaseKey = key.toLower();
+ if (!seenKeys.contains(lowercaseKey)) {
+ keyList.append(key);
+ seenKeys.insert(lowercaseKey);
+ }
+ ++it;
+ }
+ return keyList;
+}
+
+/*!
+ Returns true if the HTTP header has an entry with the given \a
+ key; otherwise returns false.
+
+ \sa value() setValue() keys()
+*/
+bool QHttpHeader::hasKey(const QString &key) const
+{
+ Q_D(const QHttpHeader);
+ QString lowercaseKey = key.toLower();
+ QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
+ while (it != d->values.constEnd()) {
+ if ((*it).first.toLower() == lowercaseKey)
+ return true;
+ ++it;
+ }
+ return false;
+}
+
+/*!
+ Sets the value of the entry with the \a key to \a value.
+
+ If no entry with \a key exists, a new entry with the given \a key
+ and \a value is created. If an entry with the \a key already
+ exists, the first value is discarded and replaced with the given
+ \a value.
+
+ \sa value() hasKey() removeValue()
+*/
+void QHttpHeader::setValue(const QString &key, const QString &value)
+{
+ Q_D(QHttpHeader);
+ QString lowercaseKey = key.toLower();
+ QList<QPair<QString, QString> >::Iterator it = d->values.begin();
+ while (it != d->values.end()) {
+ if ((*it).first.toLower() == lowercaseKey) {
+ (*it).second = value;
+ return;
+ }
+ ++it;
+ }
+ // not found so add
+ addValue(key, value);
+}
+
+/*!
+ Sets the header entries to be the list of key value pairs in \a values.
+*/
+void QHttpHeader::setValues(const QList<QPair<QString, QString> > &values)
+{
+ Q_D(QHttpHeader);
+ d->values = values;
+}
+
+/*!
+ Adds a new entry with the \a key and \a value.
+*/
+void QHttpHeader::addValue(const QString &key, const QString &value)
+{
+ Q_D(QHttpHeader);
+ d->values.append(qMakePair(key, value));
+}
+
+/*!
+ Returns all the entries in the header.
+*/
+QList<QPair<QString, QString> > QHttpHeader::values() const
+{
+ Q_D(const QHttpHeader);
+ return d->values;
+}
+
+/*!
+ Removes the entry with the key \a key from the HTTP header.
+
+ \sa value() setValue()
+*/
+void QHttpHeader::removeValue(const QString &key)
+{
+ Q_D(QHttpHeader);
+ QString lowercaseKey = key.toLower();
+ QList<QPair<QString, QString> >::Iterator it = d->values.begin();
+ while (it != d->values.end()) {
+ if ((*it).first.toLower() == lowercaseKey) {
+ d->values.erase(it);
+ return;
+ }
+ ++it;
+ }
+}
+
+/*!
+ Removes all the entries with the key \a key from the HTTP header.
+*/
+void QHttpHeader::removeAllValues(const QString &key)
+{
+ Q_D(QHttpHeader);
+ QString lowercaseKey = key.toLower();
+ QList<QPair<QString, QString> >::Iterator it = d->values.begin();
+ while (it != d->values.end()) {
+ if ((*it).first.toLower() == lowercaseKey) {
+ it = d->values.erase(it);
+ continue;
+ }
+ ++it;
+ }
+}
+
+/*! \internal
+ Parses the single HTTP header line \a line which has the format
+ key, colon, space, value, and adds key/value to the headers. The
+ linenumber is \a number. Returns true if the line was successfully
+ parsed and the key/value added; otherwise returns false.
+
+ \sa parse()
+*/
+bool QHttpHeader::parseLine(const QString &line, int)
+{
+ int i = line.indexOf(QLatin1Char(':'));
+ if (i == -1)
+ return false;
+
+ addValue(line.left(i).trimmed(), line.mid(i + 1).trimmed());
+
+ return true;
+}
+
+/*!
+ Returns a string representation of the HTTP header.
+
+ The string is suitable for use by the constructor that takes a
+ QString. It consists of lines with the format: key, colon, space,
+ value, "\r\n".
+*/
+QString QHttpHeader::toString() const
+{
+ Q_D(const QHttpHeader);
+ if (!isValid())
+ return QLatin1String("");
+
+ QString ret = QLatin1String("");
+
+ QList<QPair<QString, QString> >::ConstIterator it = d->values.constBegin();
+ while (it != d->values.constEnd()) {
+ ret += (*it).first + QLatin1String(": ") + (*it).second + QLatin1String("\r\n");
+ ++it;
+ }
+ return ret;
+}
+
+/*!
+ Returns true if the header has an entry for the special HTTP
+ header field \c content-length; otherwise returns false.
+
+ \sa contentLength() setContentLength()
+*/
+bool QHttpHeader::hasContentLength() const
+{
+ return hasKey(QLatin1String("content-length"));
+}
+
+/*!
+ Returns the value of the special HTTP header field \c
+ content-length.
+
+ \sa setContentLength() hasContentLength()
+*/
+uint QHttpHeader::contentLength() const
+{
+ return value(QLatin1String("content-length")).toUInt();
+}
+
+/*!
+ Sets the value of the special HTTP header field \c content-length
+ to \a len.
+
+ \sa contentLength() hasContentLength()
+*/
+void QHttpHeader::setContentLength(int len)
+{
+ setValue(QLatin1String("content-length"), QString::number(len));
+}
+
+/*!
+ Returns true if the header has an entry for the special HTTP
+ header field \c content-type; otherwise returns false.
+
+ \sa contentType() setContentType()
+*/
+bool QHttpHeader::hasContentType() const
+{
+ return hasKey(QLatin1String("content-type"));
+}
+
+/*!
+ Returns the value of the special HTTP header field \c content-type.
+
+ \sa setContentType() hasContentType()
+*/
+QString QHttpHeader::contentType() const
+{
+ QString type = value(QLatin1String("content-type"));
+ if (type.isEmpty())
+ return QString();
+
+ int pos = type.indexOf(QLatin1Char(';'));
+ if (pos == -1)
+ return type;
+
+ return type.left(pos).trimmed();
+}
+
+/*!
+ Sets the value of the special HTTP header field \c content-type to
+ \a type.
+
+ \sa contentType() hasContentType()
+*/
+void QHttpHeader::setContentType(const QString &type)
+{
+ setValue(QLatin1String("content-type"), type);
+}
+
+class QHttpResponseHeaderPrivate : public QHttpHeaderPrivate
+{
+ Q_DECLARE_PUBLIC(QHttpResponseHeader)
+public:
+ int statCode;
+ QString reasonPhr;
+ int majVer;
+ int minVer;
+};
+
+/****************************************************
+ *
+ * QHttpResponseHeader
+ *
+ ****************************************************/
+
+/*!
+ \class QHttpResponseHeader
+ \obsolete
+ \brief The QHttpResponseHeader class contains response header information for HTTP.
+
+ \ingroup network
+ \inmodule QtNetwork
+
+ HTTP responses have a status code that indicates the status of the
+ response. This code is a 3-digit integer result code (for details
+ see to RFC 1945). In addition to the status code, you can also
+ specify a human-readable text that describes the reason for the
+ code ("reason phrase"). This class allows you to get the status
+ code and the reason phrase.
+
+ \sa QHttpRequestHeader, {HTTP Example}
+*/
+
+/*!
+ Constructs an empty HTTP response header.
+*/
+QHttpResponseHeader::QHttpResponseHeader()
+ : QHttpHeader(*new QHttpResponseHeaderPrivate)
+{
+ setValid(false);
+}
+
+/*!
+ Constructs a copy of \a header.
+*/
+QHttpResponseHeader::QHttpResponseHeader(const QHttpResponseHeader &header)
+ : QHttpHeader(*new QHttpResponseHeaderPrivate, header)
+{
+ Q_D(QHttpResponseHeader);
+ d->statCode = header.d_func()->statCode;
+ d->reasonPhr = header.d_func()->reasonPhr;
+ d->majVer = header.d_func()->majVer;
+ d->minVer = header.d_func()->minVer;
+}
+
+/*!
+ Copies the contents of \a header into this QHttpResponseHeader.
+*/
+QHttpResponseHeader &QHttpResponseHeader::operator=(const QHttpResponseHeader &header)
+{
+ Q_D(QHttpResponseHeader);
+ QHttpHeader::operator=(header);
+ d->statCode = header.d_func()->statCode;
+ d->reasonPhr = header.d_func()->reasonPhr;
+ d->majVer = header.d_func()->majVer;
+ d->minVer = header.d_func()->minVer;
+ return *this;
+}
+
+/*!
+ Constructs a HTTP response header from the string \a str. The
+ string is parsed and the information is set. The \a str should
+ consist of one or more "\r\n" delimited lines; the first line should be the
+ status-line (format: HTTP-version, space, status-code, space,
+ reason-phrase); each of remaining lines should have the format key, colon,
+ space, value.
+*/
+QHttpResponseHeader::QHttpResponseHeader(const QString &str)
+ : QHttpHeader(*new QHttpResponseHeaderPrivate)
+{
+ parse(str);
+}
+
+/*!
+ \since 4.1
+
+ Constructs a QHttpResponseHeader, setting the status code to \a code, the
+ reason phrase to \a text and the protocol-version to \a majorVer and \a
+ minorVer.
+
+ \sa statusCode() reasonPhrase() majorVersion() minorVersion()
+*/
+QHttpResponseHeader::QHttpResponseHeader(int code, const QString &text, int majorVer, int minorVer)
+ : QHttpHeader(*new QHttpResponseHeaderPrivate)
+{
+ setStatusLine(code, text, majorVer, minorVer);
+}
+
+/*!
+ \since 4.1
+
+ Sets the status code to \a code, the reason phrase to \a text and
+ the protocol-version to \a majorVer and \a minorVer.
+
+ \sa statusCode() reasonPhrase() majorVersion() minorVersion()
+*/
+void QHttpResponseHeader::setStatusLine(int code, const QString &text, int majorVer, int minorVer)
+{
+ Q_D(QHttpResponseHeader);
+ setValid(true);
+ d->statCode = code;
+ d->reasonPhr = text;
+ d->majVer = majorVer;
+ d->minVer = minorVer;
+}
+
+/*!
+ Returns the status code of the HTTP response header.
+
+ \sa reasonPhrase() majorVersion() minorVersion()
+*/
+int QHttpResponseHeader::statusCode() const
+{
+ Q_D(const QHttpResponseHeader);
+ return d->statCode;
+}
+
+/*!
+ Returns the reason phrase of the HTTP response header.
+
+ \sa statusCode() majorVersion() minorVersion()
+*/
+QString QHttpResponseHeader::reasonPhrase() const
+{
+ Q_D(const QHttpResponseHeader);
+ return d->reasonPhr;
+}
+
+/*!
+ Returns the major protocol-version of the HTTP response header.
+
+ \sa minorVersion() statusCode() reasonPhrase()
+*/
+int QHttpResponseHeader::majorVersion() const
+{
+ Q_D(const QHttpResponseHeader);
+ return d->majVer;
+}
+
+/*!
+ Returns the minor protocol-version of the HTTP response header.
+
+ \sa majorVersion() statusCode() reasonPhrase()
+*/
+int QHttpResponseHeader::minorVersion() const
+{
+ Q_D(const QHttpResponseHeader);
+ return d->minVer;
+}
+
+/*! \internal
+*/
+bool QHttpResponseHeader::parseLine(const QString &line, int number)
+{
+ Q_D(QHttpResponseHeader);
+ if (number != 0)
+ return QHttpHeader::parseLine(line, number);
+
+ QString l = line.simplified();
+ if (l.length() < 10)
+ return false;
+
+ if (l.left(5) == QLatin1String("HTTP/") && l[5].isDigit() && l[6] == QLatin1Char('.') &&
+ l[7].isDigit() && l[8] == QLatin1Char(' ') && l[9].isDigit()) {
+ d->majVer = l[5].toLatin1() - '0';
+ d->minVer = l[7].toLatin1() - '0';
+
+ int pos = l.indexOf(QLatin1Char(' '), 9);
+ if (pos != -1) {
+ d->reasonPhr = l.mid(pos + 1);
+ d->statCode = l.mid(9, pos - 9).toInt();
+ } else {
+ d->statCode = l.mid(9).toInt();
+ d->reasonPhr.clear();
+ }
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+/*! \reimp
+*/
+QString QHttpResponseHeader::toString() const
+{
+ Q_D(const QHttpResponseHeader);
+ QString ret(QLatin1String("HTTP/%1.%2 %3 %4\r\n%5\r\n"));
+ return ret.arg(d->majVer).arg(d->minVer).arg(d->statCode).arg(d->reasonPhr).arg(QHttpHeader::toString());
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/network/access/qhttpheader_p.h b/src/network/access/qhttpheader_p.h
new file mode 100644
index 0000000000..fec7da4f92
--- /dev/null
+++ b/src/network/access/qhttpheader_p.h
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QHTTP_H
+#define QHTTP_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qstringlist.h>
+#include <QtCore/qmap.h>
+#include <QtCore/qpair.h>
+#include <QtCore/qscopedpointer.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Network)
+
+#ifndef QT_NO_HTTP
+
+#if 0
+#pragma qt_class(QHttp)
+#endif
+
+class QHttpHeaderPrivate;
+class QHttpHeader
+{
+public:
+ QHttpHeader();
+ QHttpHeader(const QHttpHeader &header);
+ QHttpHeader(const QString &str);
+ virtual ~QHttpHeader();
+
+ QHttpHeader &operator=(const QHttpHeader &h);
+
+ void setValue(const QString &key, const QString &value);
+ void setValues(const QList<QPair<QString, QString> > &values);
+ void addValue(const QString &key, const QString &value);
+ QList<QPair<QString, QString> > values() const;
+ bool hasKey(const QString &key) const;
+ QStringList keys() const;
+ QString value(const QString &key) const;
+ QStringList allValues(const QString &key) const;
+ void removeValue(const QString &key);
+ void removeAllValues(const QString &key);
+
+ // ### Qt 5: change to qint64
+ bool hasContentLength() const;
+ uint contentLength() const;
+ void setContentLength(int len);
+
+ bool hasContentType() const;
+ QString contentType() const;
+ void setContentType(const QString &type);
+
+ virtual QString toString() const;
+ bool isValid() const;
+
+ virtual int majorVersion() const = 0;
+ virtual int minorVersion() const = 0;
+
+protected:
+ virtual bool parseLine(const QString &line, int number);
+ bool parse(const QString &str);
+ void setValid(bool);
+
+ QHttpHeader(QHttpHeaderPrivate &dd, const QString &str = QString());
+ QHttpHeader(QHttpHeaderPrivate &dd, const QHttpHeader &header);
+ QScopedPointer<QHttpHeaderPrivate> d_ptr;
+
+private:
+ Q_DECLARE_PRIVATE(QHttpHeader)
+};
+
+class QHttpResponseHeaderPrivate;
+class QHttpResponseHeader : public QHttpHeader
+{
+public:
+ QHttpResponseHeader();
+ QHttpResponseHeader(const QHttpResponseHeader &header);
+ QHttpResponseHeader(const QString &str);
+ QHttpResponseHeader(int code, const QString &text = QString(), int majorVer = 1, int minorVer = 1);
+ QHttpResponseHeader &operator=(const QHttpResponseHeader &header);
+
+ void setStatusLine(int code, const QString &text = QString(), int majorVer = 1, int minorVer = 1);
+
+ int statusCode() const;
+ QString reasonPhrase() const;
+
+ int majorVersion() const;
+ int minorVersion() const;
+
+ QString toString() const;
+
+protected:
+ bool parseLine(const QString &line, int number);
+
+private:
+ Q_DECLARE_PRIVATE(QHttpResponseHeader)
+ friend class QHttpPrivate;
+};
+
+#endif // QT_NO_HTTP
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QHTTP_H
diff --git a/src/network/access/qhttpmultipart.cpp b/src/network/access/qhttpmultipart.cpp
index 75456581f8..6de7a807e4 100644
--- a/src/network/access/qhttpmultipart.cpp
+++ b/src/network/access/qhttpmultipart.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpmultipart.h b/src/network/access/qhttpmultipart.h
index 76e8e14b8a..317b068e3d 100644
--- a/src/network/access/qhttpmultipart.h
+++ b/src/network/access/qhttpmultipart.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpmultipart_p.h b/src/network/access/qhttpmultipart_p.h
index f57b0eb8a2..0ab2fa1d7f 100644
--- a/src/network/access/qhttpmultipart_p.h
+++ b/src/network/access/qhttpmultipart_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index fca3d5999e..104a21f591 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -53,7 +53,6 @@
#include <qbuffer.h>
#include <qpair.h>
-#include <qhttp.h>
#include <qdebug.h>
#ifndef QT_NO_HTTP
@@ -81,7 +80,7 @@ const int QHttpNetworkConnectionPrivate::defaultRePipelineLength = 2;
QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &hostName, quint16 port, bool encrypt)
: state(RunningState),
networkLayerState(Unknown),
- hostName(hostName), port(port), encrypt(encrypt),
+ hostName(hostName), port(port), encrypt(encrypt), delayIpv4(true),
channelCount(defaultChannelCount)
#ifndef QT_NO_NETWORKPROXY
, networkProxy(QNetworkProxy::NoProxy)
@@ -92,7 +91,7 @@ QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &host
QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, quint16 port, bool encrypt)
: state(RunningState), networkLayerState(Unknown),
- hostName(hostName), port(port), encrypt(encrypt),
+ hostName(hostName), port(port), encrypt(encrypt), delayIpv4(true),
channelCount(channelCount)
#ifndef QT_NO_NETWORKPROXY
, networkProxy(QNetworkProxy::NoProxy)
@@ -116,6 +115,7 @@ QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate()
void QHttpNetworkConnectionPrivate::init()
{
+ Q_Q(QHttpNetworkConnection);
for (int i = 0; i < channelCount; i++) {
channels[i].setConnection(this->q_func());
channels[i].ssl = encrypt;
@@ -125,6 +125,8 @@ void QHttpNetworkConnectionPrivate::init()
#endif
channels[i].init();
}
+ delayedConnectionTimer.setSingleShot(true);
+ QObject::connect(&delayedConnectionTimer, SIGNAL(timeout()), q, SLOT(_q_connectDelayedChannel()));
}
void QHttpNetworkConnectionPrivate::pauseConnection()
@@ -185,6 +187,12 @@ bool QHttpNetworkConnectionPrivate::shouldEmitChannelError(QAbstractSocket *sock
int i = indexOf(socket);
int otherSocket = (i == 0 ? 1 : 0);
+ // If the IPv4 connection still isn't started we need to start it now.
+ if (delayedConnectionTimer.isActive()) {
+ delayedConnectionTimer.stop();
+ channels[otherSocket].ensureConnection();
+ }
+
if (channelCount == 1) {
if (networkLayerState == QHttpNetworkConnectionPrivate::InProgress)
networkLayerState = QHttpNetworkConnectionPrivate::Unknown;
@@ -419,9 +427,23 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket
if (priv->phase == QAuthenticatorPrivate::Done) {
pauseConnection();
if (!isProxy) {
+ if (channels[i].authenticationCredentialsSent) {
+ auth->detach();
+ priv = QAuthenticatorPrivate::getPrivate(*auth);
+ priv->hasFailed = true;
+ priv->phase = QAuthenticatorPrivate::Done;
+ channels[i].authenticationCredentialsSent = false;
+ }
emit reply->authenticationRequired(reply->request(), auth);
#ifndef QT_NO_NETWORKPROXY
} else {
+ if (channels[i].proxyCredentialsSent) {
+ auth->detach();
+ priv = QAuthenticatorPrivate::getPrivate(*auth);
+ priv->hasFailed = true;
+ priv->phase = QAuthenticatorPrivate::Done;
+ channels[i].proxyCredentialsSent = false;
+ }
emit reply->proxyAuthenticationRequired(networkProxy, auth);
#endif
}
@@ -459,7 +481,6 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket
reply->d_func()->errorString = errorDetail(errorCode, socket);
emit reply->finishedWithError(errorCode, reply->d_func()->errorString);
// ### at this point the reply could be deleted
- socket->close();
return true;
}
//resend the request
@@ -482,6 +503,7 @@ void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket,
if (priv && priv->method != QAuthenticatorPrivate::None) {
QByteArray response = priv->calculateResponse(request.d->methodName(), request.d->uri(false));
request.setHeaderField("Authorization", response);
+ channels[i].authenticationCredentialsSent = true;
}
}
}
@@ -493,6 +515,7 @@ void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket,
if (priv && priv->method != QAuthenticatorPrivate::None) {
QByteArray response = priv->calculateResponse(request.d->methodName(), request.d->uri(false));
request.setHeaderField("Proxy-Authorization", response);
+ channels[i].proxyCredentialsSent = true;
}
}
}
@@ -632,9 +655,13 @@ void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket)
// we do not like authentication stuff
// ### make sure to be OK with this in later releases
- if (!channels[i].authenticator.isNull() || !channels[i].authenticator.user().isEmpty())
+ if (!channels[i].authenticator.isNull()
+ && (!channels[i].authenticator.user().isEmpty()
+ || !channels[i].authenticator.password().isEmpty()))
return;
- if (!channels[i].proxyAuthenticator.isNull() || !channels[i].proxyAuthenticator.user().isEmpty())
+ if (!channels[i].proxyAuthenticator.isNull()
+ && (!channels[i].proxyAuthenticator.user().isEmpty()
+ || !channels[i].proxyAuthenticator.password().isEmpty()))
return;
// must be in ReadingState or WaitingState
@@ -965,12 +992,22 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(QHostInfo info)
{
bool bIpv4 = false;
bool bIpv6 = false;
+ bool foundAddress = false;
- foreach (QHostAddress address, info.addresses()) {
- if (address.protocol() == QAbstractSocket::IPv4Protocol)
+ foreach (const QHostAddress &address, info.addresses()) {
+ if (address.protocol() == QAbstractSocket::IPv4Protocol) {
+ if (!foundAddress) {
+ foundAddress = true;
+ delayIpv4 = false;
+ }
bIpv4 = true;
- else if (address.protocol() == QAbstractSocket::IPv6Protocol)
+ } else if (address.protocol() == QAbstractSocket::IPv6Protocol) {
+ if (!foundAddress) {
+ foundAddress = true;
+ delayIpv4 = true;
+ }
bIpv6 = true;
+ }
}
if (bIpv4 && bIpv6)
@@ -1010,8 +1047,24 @@ void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup()
channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol;
channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol;
- channels[0].ensureConnection(); // Possibly delay this one..
- channels[1].ensureConnection();
+ int timeout = 300;
+#ifndef QT_NO_BEARERMANAGEMENT
+ if (networkSession) {
+ if (networkSession->configuration().bearerType() == QNetworkConfiguration::Bearer2G)
+ timeout = 800;
+ else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerCDMA2000)
+ timeout = 500;
+ else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerWCDMA)
+ timeout = 500;
+ else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerHSPA)
+ timeout = 400;
+ }
+#endif
+ delayedConnectionTimer.start(timeout);
+ if (delayIpv4)
+ channels[1].ensureConnection();
+ else
+ channels[0].ensureConnection();
} else {
networkLayerState = InProgress;
channels[0].networkLayerPreference = QAbstractSocket::AnyIPProtocol;
@@ -1019,6 +1072,13 @@ void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup()
}
}
+void QHttpNetworkConnectionPrivate::_q_connectDelayedChannel()
+{
+ if (delayIpv4)
+ channels[0].ensureConnection();
+ else
+ channels[1].ensureConnection();
+}
#ifndef QT_NO_BEARERMANAGEMENT
QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, QObject *parent, QSharedPointer<QNetworkSession> networkSession)
diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h
index 70b9cf3754..8ce9bf24fe 100644
--- a/src/network/access/qhttpnetworkconnection_p.h
+++ b/src/network/access/qhttpnetworkconnection_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -61,6 +61,7 @@
#include <qauthenticator.h>
#include <qnetworkproxy.h>
#include <qbuffer.h>
+#include <qtimer.h>
#include <private/qhttpnetworkheader_p.h>
#include <private/qhttpnetworkrequest_p.h>
@@ -134,6 +135,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_startNextRequest())
Q_PRIVATE_SLOT(d_func(), void _q_hostLookupFinished(QHostInfo))
+ Q_PRIVATE_SLOT(d_func(), void _q_connectDelayedChannel())
};
@@ -196,6 +198,7 @@ public:
void _q_startNextRequest(); // send the next request from the queue
void _q_hostLookupFinished(QHostInfo info);
+ void _q_connectDelayedChannel();
void createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request);
@@ -207,8 +210,10 @@ public:
QString hostName;
quint16 port;
bool encrypt;
+ bool delayIpv4;
const int channelCount;
+ QTimer delayedConnectionTimer;
QHttpNetworkConnectionChannel *channels; // parallel connections to the server
bool shouldEmitChannelError(QAbstractSocket *socket);
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index 072648cf62..3acfe54ef7 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -75,6 +75,8 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
, reconnectAttempts(2)
, authMethod(QAuthenticatorPrivate::None)
, proxyAuthMethod(QAuthenticatorPrivate::None)
+ , authenticationCredentialsSent(false)
+ , proxyCredentialsSent(false)
#ifndef QT_NO_OPENSSL
, ignoreAllSslErrors(false)
#endif
@@ -549,6 +551,14 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
// reset state
pipeliningSupported = PipeliningSupportUnknown;
+ authenticationCredentialsSent = false;
+ proxyCredentialsSent = false;
+ authenticator.detach();
+ QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator);
+ priv->hasFailed = false;
+ proxyAuthenticator.detach();
+ priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
+ priv->hasFailed = false;
// This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done"
// is the usual criteria for emitting authentication signals. The "phase" is set to "Done" when the
@@ -556,7 +566,7 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
// check the "phase" for generating the Authorization header. NTLM authentication is a two stage
// process & needs the "phase". To make sure the QAuthenticator uses the current username/password
// the phase is reset to Start.
- QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator);
+ priv = QAuthenticatorPrivate::getPrivate(authenticator);
if (priv && priv->phase == QAuthenticatorPrivate::Done)
priv->phase = QAuthenticatorPrivate::Start;
priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator);
@@ -580,8 +590,11 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
value = connection->d_func()->predictNextRequest().headerField("user-agent");
else
value = request.headerField("user-agent");
- if (!value.isEmpty())
- socket->proxy().setRawHeader("User-Agent", value);
+ if (!value.isEmpty()) {
+ QNetworkProxy proxy(socket->proxy());
+ proxy.setRawHeader("User-Agent", value); //detaches
+ socket->setProxy(proxy);
+ }
}
#endif
if (ssl) {
@@ -780,6 +793,9 @@ void QHttpNetworkConnectionChannel::handleStatus()
closeAndResendCurrentRequest();
QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
}
+ } else {
+ //authentication cancelled, close the channel.
+ close();
}
} else {
emit reply->headerChanged();
@@ -951,6 +967,8 @@ void QHttpNetworkConnectionChannel::_q_connected()
// For the Happy Eyeballs we need to check if this is the first channel to connect.
if (!pendingEncrypt) {
if (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::InProgress) {
+ if (connection->d_func()->delayedConnectionTimer.isActive())
+ connection->d_func()->delayedConnectionTimer.stop();
if (networkLayerPreference == QAbstractSocket::IPv4Protocol)
connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4;
else if (networkLayerPreference == QAbstractSocket::IPv6Protocol)
diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h
index 7a4dd07db1..d5a0925f7d 100644
--- a/src/network/access/qhttpnetworkconnectionchannel_p.h
+++ b/src/network/access/qhttpnetworkconnectionchannel_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -113,6 +113,8 @@ public:
QAuthenticatorPrivate::Method proxyAuthMethod;
QAuthenticator authenticator;
QAuthenticator proxyAuthenticator;
+ bool authenticationCredentialsSent;
+ bool proxyCredentialsSent;
#ifndef QT_NO_OPENSSL
bool ignoreAllSslErrors;
QList<QSslError> ignoreSslErrorsList;
diff --git a/src/network/access/qhttpnetworkheader.cpp b/src/network/access/qhttpnetworkheader.cpp
index 1d457b90a7..531afe92e0 100644
--- a/src/network/access/qhttpnetworkheader.cpp
+++ b/src/network/access/qhttpnetworkheader.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpnetworkheader_p.h b/src/network/access/qhttpnetworkheader_p.h
index 38db0506b9..00393b5e92 100644
--- a/src/network/access/qhttpnetworkheader_p.h
+++ b/src/network/access/qhttpnetworkheader_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index e6d0d3238c..a9ba5d2b24 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h
index a6bf3fcc8e..1bb0832d19 100644
--- a/src/network/access/qhttpnetworkreply_p.h
+++ b/src/network/access/qhttpnetworkreply_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp
index cbc0d97e12..e39faaeaa8 100644
--- a/src/network/access/qhttpnetworkrequest.cpp
+++ b/src/network/access/qhttpnetworkrequest.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpnetworkrequest_p.h b/src/network/access/qhttpnetworkrequest_p.h
index 4000ecad87..71e09eba06 100644
--- a/src/network/access/qhttpnetworkrequest_p.h
+++ b/src/network/access/qhttpnetworkrequest_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp
index f0755337fc..39a7e8ed08 100644
--- a/src/network/access/qhttpthreaddelegate.cpp
+++ b/src/network/access/qhttpthreaddelegate.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -364,7 +364,7 @@ void QHttpThreadDelegate::readyReadSlot()
void QHttpThreadDelegate::finishedSlot()
{
if (!httpReply) {
- qWarning() << "QHttpThreadDelegate::finishedSlot: HTTP reply had already been deleted, internal problem. Please report.";
+ qWarning("QHttpThreadDelegate::finishedSlot: HTTP reply had already been deleted, internal problem. Please report.");
return;
}
#ifdef QHTTPTHREADDELEGATE_DEBUG
@@ -420,7 +420,7 @@ void QHttpThreadDelegate::synchronousFinishedSlot()
void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail)
{
if (!httpReply) {
- qWarning() << "QHttpThreadDelegate::finishedWithErrorSlot: HTTP reply had already been deleted, internal problem. Please report.";
+ qWarning("QHttpThreadDelegate::finishedWithErrorSlot: HTTP reply had already been deleted, internal problem. Please report.");
return;
}
#ifdef QHTTPTHREADDELEGATE_DEBUG
diff --git a/src/network/access/qhttpthreaddelegate_p.h b/src/network/access/qhttpthreaddelegate_p.h
index d97193d7c7..366d3bcc60 100644
--- a/src/network/access/qhttpthreaddelegate_p.h
+++ b/src/network/access/qhttpthreaddelegate_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessauthenticationmanager.cpp b/src/network/access/qnetworkaccessauthenticationmanager.cpp
index 1b15cf9cdf..30e3174f25 100644
--- a/src/network/access/qnetworkaccessauthenticationmanager.cpp
+++ b/src/network/access/qnetworkaccessauthenticationmanager.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -159,6 +159,11 @@ void QNetworkAccessAuthenticationManager::cacheProxyCredentials(const QNetworkPr
QString realm = authenticator->realm();
QNetworkProxy proxy = p;
proxy.setUser(authenticator->user());
+
+ // don't cache null passwords, empty password may be valid though
+ if (authenticator->password().isNull())
+ return;
+
// Set two credentials: one with the username and one without
do {
// Set two credentials actually: one with and one without the realm
@@ -283,9 +288,12 @@ QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url,
QNetworkAuthenticationCache *auth =
static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey));
- QNetworkAuthenticationCredential cred = *auth->findClosestMatch(url.path());
+ QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path());
+ QNetworkAuthenticationCredential ret;
+ if (cred)
+ ret = *cred;
authenticationCache.releaseEntry(cacheKey);
- return cred;
+ return ret;
}
void QNetworkAccessAuthenticationManager::clearCache()
diff --git a/src/network/access/qnetworkaccessauthenticationmanager_p.h b/src/network/access/qnetworkaccessauthenticationmanager_p.h
index ddfc11606d..7e7be8ca8a 100644
--- a/src/network/access/qnetworkaccessauthenticationmanager_p.h
+++ b/src/network/access/qnetworkaccessauthenticationmanager_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -73,7 +73,7 @@ public:
QString user;
QString password;
bool isNull() {
- return domain.isNull();
+ return domain.isNull() && user.isNull() && password.isNull();
}
};
Q_DECLARE_TYPEINFO(QNetworkAuthenticationCredential, Q_MOVABLE_TYPE);
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index 8dfcb33282..6647c58f8d 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h
index 7f6aff9b79..f9563da4a7 100644
--- a/src/network/access/qnetworkaccessbackend_p.h
+++ b/src/network/access/qnetworkaccessbackend_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccesscache.cpp b/src/network/access/qnetworkaccesscache.cpp
index 0458a59e22..2594e53949 100644
--- a/src/network/access/qnetworkaccesscache.cpp
+++ b/src/network/access/qnetworkaccesscache.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccesscache_p.h b/src/network/access/qnetworkaccesscache_p.h
index b9f468e767..813ba3c35f 100644
--- a/src/network/access/qnetworkaccesscache_p.h
+++ b/src/network/access/qnetworkaccesscache_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccesscachebackend.cpp b/src/network/access/qnetworkaccesscachebackend.cpp
index 1881dac126..baf6292124 100644
--- a/src/network/access/qnetworkaccesscachebackend.cpp
+++ b/src/network/access/qnetworkaccesscachebackend.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccesscachebackend_p.h b/src/network/access/qnetworkaccesscachebackend_p.h
index be0f2fb84a..5444703793 100644
--- a/src/network/access/qnetworkaccesscachebackend_p.h
+++ b/src/network/access/qnetworkaccesscachebackend_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessdebugpipebackend.cpp b/src/network/access/qnetworkaccessdebugpipebackend.cpp
index 6a59bad2bd..678d6e404e 100644
--- a/src/network/access/qnetworkaccessdebugpipebackend.cpp
+++ b/src/network/access/qnetworkaccessdebugpipebackend.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessdebugpipebackend_p.h b/src/network/access/qnetworkaccessdebugpipebackend_p.h
index d22acf7c9f..411c38b3ba 100644
--- a/src/network/access/qnetworkaccessdebugpipebackend_p.h
+++ b/src/network/access/qnetworkaccessdebugpipebackend_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessfilebackend.cpp b/src/network/access/qnetworkaccessfilebackend.cpp
index 6a8f0993a0..0080e23a8f 100644
--- a/src/network/access/qnetworkaccessfilebackend.cpp
+++ b/src/network/access/qnetworkaccessfilebackend.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessfilebackend_p.h b/src/network/access/qnetworkaccessfilebackend_p.h
index 795d4b9d25..2fbf806851 100644
--- a/src/network/access/qnetworkaccessfilebackend_p.h
+++ b/src/network/access/qnetworkaccessfilebackend_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp
index 0461da284b..7b7ebb5e46 100644
--- a/src/network/access/qnetworkaccessftpbackend.cpp
+++ b/src/network/access/qnetworkaccessftpbackend.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessftpbackend_p.h b/src/network/access/qnetworkaccessftpbackend_p.h
index 2dc3c1becf..7338121493 100644
--- a/src/network/access/qnetworkaccessftpbackend_p.h
+++ b/src/network/access/qnetworkaccessftpbackend_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -57,7 +57,7 @@
#include "qnetworkaccesscache_p.h"
#include "qnetworkrequest.h"
#include "qnetworkreply.h"
-#include "QtNetwork/qftp.h"
+#include "private/qftp_p.h"
#include "QtCore/qpointer.h"
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 3978bd6c85..3a80b9ed92 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -45,6 +45,7 @@
#include "qnetworkreply.h"
#include "qnetworkreply_p.h"
#include "qnetworkcookie.h"
+#include "qnetworkcookiejar.h"
#include "qabstractnetworkcache.h"
#include "QtNetwork/qnetworksession.h"
@@ -60,7 +61,7 @@
#include "QtCore/qbuffer.h"
#include "QtCore/qurl.h"
#include "QtCore/qvector.h"
-#include "QtNetwork/qauthenticator.h"
+#include "QtNetwork/private/qauthenticator_p.h"
#include "QtNetwork/qsslconfiguration.h"
#include "QtNetwork/qnetworkconfigmanager.h"
#include "QtNetwork/qhttpmultipart.h"
@@ -285,11 +286,16 @@ static void ensureInitialized()
again, without emitting the authenticationRequired() signal. If it
rejects the credentials, this signal will be emitted again.
+ \note To have the request not send credentials you must not call
+ setUser() or setPassword() on the \a authenticator object. This
+ will result in the the \l finished() signal being emitted with a
+ \l QNetworkReply with error \l AuthenticationRequiredError.
+
\note It is not possible to use a QueuedConnection to connect to
this signal, as the connection will fail if the authenticator has
not been filled in with new information when the signal returns.
- \sa proxyAuthenticationRequired()
+ \sa proxyAuthenticationRequired(), QAuthenticator::setUser(), QAuthenticator::setPassword()
*/
/*!
@@ -1115,14 +1121,8 @@ void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QNetworkPro
QNetworkProxy *lastProxyAuthentication)
{
Q_Q(QNetworkAccessManager);
- // ### FIXME Tracking of successful authentications
- // This code is a bit broken right now for SOCKS authentication
- // first request: proxyAuthenticationRequired gets emitted, credentials gets saved
- // second request: (proxy != backend->reply->lastProxyAuthentication) does not evaluate to true,
- // proxyAuthenticationRequired gets emitted again
- // possible solution: some tracking inside the authenticator
- // or a new function proxyAuthenticationSucceeded(true|false)
- if (proxy != *lastProxyAuthentication) {
+ QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*authenticator);
+ if (proxy != *lastProxyAuthentication && (!priv || !priv->hasFailed)) {
QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedProxyCredentials(proxy);
if (!cred.isNull()) {
authenticator->setUser(cred.user);
diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h
index c707243ec6..72fd86c5a5 100644
--- a/src/network/access/qnetworkaccessmanager.h
+++ b/src/network/access/qnetworkaccessmanager.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
index 39a9874acc..bc8df575a0 100644
--- a/src/network/access/qnetworkaccessmanager_p.h
+++ b/src/network/access/qnetworkaccessmanager_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp
index 06707385fb..a5c4fb516c 100644
--- a/src/network/access/qnetworkcookie.cpp
+++ b/src/network/access/qnetworkcookie.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkcookie.h b/src/network/access/qnetworkcookie.h
index 0f7690c174..fd9c825ddc 100644
--- a/src/network/access/qnetworkcookie.h
+++ b/src/network/access/qnetworkcookie.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -113,9 +113,6 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QNetworkCookie &);
QT_END_NAMESPACE
-// ### Qt5 remove this include
-#include <QtNetwork/QNetworkCookieJar>
-
Q_DECLARE_METATYPE(QNetworkCookie)
Q_DECLARE_METATYPE(QList<QNetworkCookie>)
diff --git a/src/network/access/qnetworkcookie_p.h b/src/network/access/qnetworkcookie_p.h
index a059a7abbd..7e45219fce 100644
--- a/src/network/access/qnetworkcookie_p.h
+++ b/src/network/access/qnetworkcookie_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp
index a2fa689256..54c2ccfaba 100644
--- a/src/network/access/qnetworkcookiejar.cpp
+++ b/src/network/access/qnetworkcookiejar.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkcookiejar.h b/src/network/access/qnetworkcookiejar.h
index 006d58eafe..4ff27d8cf0 100644
--- a/src/network/access/qnetworkcookiejar.h
+++ b/src/network/access/qnetworkcookiejar.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -45,15 +45,14 @@
#include <QtCore/QObject>
#include <QtCore/QUrl>
-// ### Qt5 remove this include
-#include <QtNetwork/QNetworkCookie>
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Network)
+class QNetworkCookie;
+
class QNetworkCookieJarPrivate;
class Q_NETWORK_EXPORT QNetworkCookieJar: public QObject
{
diff --git a/src/network/access/qnetworkcookiejar_p.h b/src/network/access/qnetworkcookiejar_p.h
index 34858d9c92..32fdecdb50 100644
--- a/src/network/access/qnetworkcookiejar_p.h
+++ b/src/network/access/qnetworkcookiejar_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index 1c515c2ac7..8dd2033a35 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkdiskcache.h b/src/network/access/qnetworkdiskcache.h
index 5492a02d29..b8f1de5930 100644
--- a/src/network/access/qnetworkdiskcache.h
+++ b/src/network/access/qnetworkdiskcache.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkdiskcache_p.h b/src/network/access/qnetworkdiskcache_p.h
index ceb300d08c..d8f386e9eb 100644
--- a/src/network/access/qnetworkdiskcache_p.h
+++ b/src/network/access/qnetworkdiskcache_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp
index 1ce7e8fce5..db62f2935a 100644
--- a/src/network/access/qnetworkreply.cpp
+++ b/src/network/access/qnetworkreply.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -586,13 +586,7 @@ QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const
QSslConfiguration QNetworkReply::sslConfiguration() const
{
QSslConfiguration config;
-
- // determine if we support this extension
- int id = metaObject()->indexOfMethod("sslConfigurationImplementation()");
- if (id != -1) {
- void *arr[] = { &config, 0 };
- const_cast<QNetworkReply *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
- }
+ sslConfigurationImplementation(config);
return config;
}
@@ -602,15 +596,7 @@ QSslConfiguration QNetworkReply::sslConfiguration() const
*/
void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
{
- if (config.isNull())
- return;
-
- int id = metaObject()->indexOfMethod("setSslConfigurationImplementation(QSslConfiguration)");
- if (id != -1) {
- QSslConfiguration copy(config);
- void *arr[] = { 0, &copy };
- qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
- }
+ setSslConfigurationImplementation(config);
}
/*!
@@ -635,18 +621,53 @@ void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
*/
void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
{
- // do this cryptic trick, because we could not add a virtual method to this class later on
- // since that breaks binary compatibility
- int id = metaObject()->indexOfMethod("ignoreSslErrorsImplementation(QList<QSslError>)");
- if (id != -1) {
- QList<QSslError> copy(errors);
- void *arr[] = { 0, &copy };
- qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
- }
+ ignoreSslErrorsImplementation(errors);
}
#endif
/*!
+ \fn void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &configuration) const
+ \since 5.0
+
+ This virtual method is provided to enable overriding the behavior of
+ sslConfiguration(). sslConfiguration() is a public wrapper for this method.
+ The configuration will be returned in \a configuration.
+
+ \sa sslConfiguration()
+*/
+void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &) const
+{
+}
+
+/*!
+ \fn void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &configuration)
+ \since 5.0
+
+ This virtual method is provided to enable overriding the behavior of
+ setSslConfiguration(). setSslConfiguration() is a public wrapper for this method.
+ If you override this method use \a configuration to set the SSL configuration.
+
+ \sa sslConfigurationImplementation(), setSslConfiguration()
+*/
+void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &)
+{
+}
+
+/*!
+ \fn void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &errors)
+ \since 5.0
+
+ This virtual method is provided to enable overriding the behavior of
+ ignoreSslErrors(). ignoreSslErrors() is a public wrapper for this method.
+ \a errors contains the errors the user wishes ignored.
+
+ \sa ignoreSslErrors()
+*/
+void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &)
+{
+}
+
+/*!
If this function is called, SSL errors related to network
connection will be ignored, including certificate validation
errors.
diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h
index f8352a2dfe..492336bbf6 100644
--- a/src/network/access/qnetworkreply.h
+++ b/src/network/access/qnetworkreply.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -169,6 +169,10 @@ protected:
void setRawHeader(const QByteArray &headerName, const QByteArray &value);
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
+ virtual void sslConfigurationImplementation(QSslConfiguration &) const;
+ virtual void setSslConfigurationImplementation(const QSslConfiguration &);
+ virtual void ignoreSslErrorsImplementation(const QList<QSslError> &);
+
private:
Q_DECLARE_PRIVATE(QNetworkReply)
};
diff --git a/src/network/access/qnetworkreply_p.h b/src/network/access/qnetworkreply_p.h
index 687e65252e..b725a11520 100644
--- a/src/network/access/qnetworkreply_p.h
+++ b/src/network/access/qnetworkreply_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkreplydataimpl.cpp b/src/network/access/qnetworkreplydataimpl.cpp
index 0cd10ce13b..22f40b2420 100644
--- a/src/network/access/qnetworkreplydataimpl.cpp
+++ b/src/network/access/qnetworkreplydataimpl.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -70,19 +70,15 @@ QNetworkReplyDataImpl::QNetworkReplyDataImpl(QObject *parent, const QNetworkRequ
QNetworkReply::open(QIODevice::ReadOnly);
QUrl url = req.url();
-
- // FIXME qDecodeDataUrl should instead be rewritten to have the QByteArray
- // and the mime type as an output parameter and return a bool instead
- d->decodeDataUrlResult = qDecodeDataUrl(url);
-
- if (! d->decodeDataUrlResult.first.isNull()) {
- QString &mimeType = d->decodeDataUrlResult.first;
- qint64 size = d->decodeDataUrlResult.second.size();
+ QString mimeType;
+ QByteArray payload;
+ if (qDecodeDataUrl(url, mimeType, payload)) {
+ qint64 size = payload.size();
setHeader(QNetworkRequest::ContentTypeHeader, mimeType);
setHeader(QNetworkRequest::ContentLengthHeader, size);
QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
- d->decodedData.setBuffer(&d->decodeDataUrlResult.second);
+ d->decodedData.setData(payload);
d->decodedData.open(QIODevice::ReadOnly);
QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
diff --git a/src/network/access/qnetworkreplydataimpl_p.h b/src/network/access/qnetworkreplydataimpl_p.h
index a63c4b1eec..0b47bbbb34 100644
--- a/src/network/access/qnetworkreplydataimpl_p.h
+++ b/src/network/access/qnetworkreplydataimpl_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -87,7 +87,6 @@ public:
QNetworkReplyDataImplPrivate();
~QNetworkReplyDataImplPrivate();
- QPair<QString, QByteArray> decodeDataUrlResult;
QBuffer decodedData;
Q_DECLARE_PUBLIC(QNetworkReplyDataImpl)
diff --git a/src/network/access/qnetworkreplyfileimpl.cpp b/src/network/access/qnetworkreplyfileimpl.cpp
index 7a0c5c7fcc..0b4c89987c 100644
--- a/src/network/access/qnetworkreplyfileimpl.cpp
+++ b/src/network/access/qnetworkreplyfileimpl.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkreplyfileimpl_p.h b/src/network/access/qnetworkreplyfileimpl_p.h
index c9f5def12a..c097fedb68 100644
--- a/src/network/access/qnetworkreplyfileimpl_p.h
+++ b/src/network/access/qnetworkreplyfileimpl_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index 2df18b24d9..2c1ad95ea8 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -48,6 +48,7 @@
#include "qnetworkrequest.h"
#include "qnetworkreply.h"
#include "qnetworkrequest_p.h"
+#include "qnetworkcookie.h"
#include "qnetworkcookie_p.h"
#include "QtCore/qdatetime.h"
#include "QtCore/qelapsedtimer.h"
@@ -410,10 +411,10 @@ void QNetworkReplyHttpImpl::setSslConfigurationImplementation(const QSslConfigur
Q_UNUSED(newconfig);
}
-QSslConfiguration QNetworkReplyHttpImpl::sslConfigurationImplementation() const
+void QNetworkReplyHttpImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const
{
Q_D(const QNetworkReplyHttpImpl);
- return d->sslConfiguration;
+ configuration = d->sslConfiguration;
}
#endif
@@ -1496,10 +1497,12 @@ void QNetworkReplyHttpImplPrivate::setResumeOffset(quint64 offset)
*/
bool QNetworkReplyHttpImplPrivate::start()
{
+#ifndef QT_NO_BEARERMANAGEMENT
if (!managerPrivate->networkSession) {
postRequest();
return true;
}
+#endif
// This is not ideal.
const QString host = url.host();
@@ -1510,11 +1513,13 @@ bool QNetworkReplyHttpImplPrivate::start()
return true;
}
+#ifndef QT_NO_BEARERMANAGEMENT
if (managerPrivate->networkSession->isOpen() &&
managerPrivate->networkSession->state() == QNetworkSession::Connected) {
postRequest();
return true;
}
+#endif
return false;
}
@@ -1846,7 +1851,7 @@ void QNetworkReplyHttpImplPrivate::error(QNetworkReplyImpl::NetworkError code, c
Q_Q(QNetworkReplyHttpImpl);
// Can't set and emit multiple errors.
if (errorCode != QNetworkReply::NoError) {
- qWarning() << "QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.";
+ qWarning("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.");
return;
}
@@ -1959,7 +1964,7 @@ void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable)
if (enable) {
if (bytesDownloaded) {
- qDebug() << "x" << bytesDownloaded;
+ qDebug("setCachingEnabled: %d bytesDownloaded", bytesDownloaded);
// refuse to enable in this case
qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");
return;
diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h
index 0c6721b646..432b769add 100644
--- a/src/network/access/qnetworkreplyhttpimpl_p.h
+++ b/src/network/access/qnetworkreplyhttpimpl_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -94,16 +94,6 @@ public:
void setReadBufferSize(qint64 size);
bool canReadLine () const;
-#ifndef QT_NO_OPENSSL
- void ignoreSslErrors();
- // ### Qt5 Add proper virtual
- Q_INVOKABLE void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
- // ### Qt5 Add proper virtual
- Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration);
- // ### Qt5 Add proper virtual
- Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const;
-#endif
-
Q_DECLARE_PRIVATE(QNetworkReplyHttpImpl)
Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
Q_PRIVATE_SLOT(d_func(), void _q_cacheLoadReadyRead())
@@ -135,6 +125,13 @@ public:
Q_PRIVATE_SLOT(d_func(), void emitReplyUploadProgress(qint64, qint64))
+#ifndef QT_NO_OPENSSL
+protected:
+ void ignoreSslErrors();
+ void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
+ void setSslConfigurationImplementation(const QSslConfiguration &configuration);
+ void sslConfigurationImplementation(QSslConfiguration &configuration) const;
+#endif
signals:
// To HTTP thread:
@@ -193,8 +190,6 @@ public:
// incoming from user
QNetworkAccessManager *manager;
QNetworkAccessManagerPrivate *managerPrivate;
- QNetworkRequest request;
- QNetworkAccessManager::Operation operation; // FIXME already in replyprivate?
QHttpNetworkRequest httpRequest; // There is also a copy in the HTTP thread
bool synchronous;
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 46cc364172..1f9efa6ed9 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -42,6 +42,7 @@
#include "qnetworkreplyimpl_p.h"
#include "qnetworkaccessbackend_p.h"
#include "qnetworkcookie.h"
+#include "qnetworkcookiejar.h"
#include "qabstractnetworkcache.h"
#include "QtCore/qcoreapplication.h"
#include "QtCore/qdatetime.h"
@@ -780,7 +781,7 @@ void QNetworkReplyImplPrivate::error(QNetworkReplyImpl::NetworkError code, const
Q_Q(QNetworkReplyImpl);
// Can't set and emit multiple errors.
if (errorCode != QNetworkReply::NoError) {
- qWarning() << "QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.";
+ qWarning( "QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.");
return;
}
@@ -930,13 +931,11 @@ void QNetworkReplyImpl::setReadBufferSize(qint64 size)
}
#ifndef QT_NO_OPENSSL
-QSslConfiguration QNetworkReplyImpl::sslConfigurationImplementation() const
+void QNetworkReplyImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const
{
Q_D(const QNetworkReplyImpl);
- QSslConfiguration config;
if (d->backend)
- d->backend->fetchSslConfiguration(config);
- return config;
+ d->backend->fetchSslConfiguration(configuration);
}
void QNetworkReplyImpl::setSslConfigurationImplementation(const QSslConfiguration &config)
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 089c87e693..0b7664acc6 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -87,13 +87,6 @@ public:
virtual qint64 readData(char *data, qint64 maxlen);
virtual bool event(QEvent *);
-#ifndef QT_NO_OPENSSL
- Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const;
- Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration);
- virtual void ignoreSslErrors();
- Q_INVOKABLE virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
-#endif
-
Q_DECLARE_PRIVATE(QNetworkReplyImpl)
Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead())
@@ -104,6 +97,14 @@ public:
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed())
#endif
+
+#ifndef QT_NO_OPENSSL
+protected:
+ void sslConfigurationImplementation(QSslConfiguration &configuration) const;
+ void setSslConfigurationImplementation(const QSslConfiguration &configuration);
+ virtual void ignoreSslErrors();
+ virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
+#endif
};
class QNetworkReplyImplPrivate: public QNetworkReplyPrivate
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 608aaa5eec..c909ce2fea 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index aa86007127..66bfcf5942 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/access/qnetworkrequest_p.h b/src/network/access/qnetworkrequest_p.h
index 54251c82a7..eb61f092f1 100644
--- a/src/network/access/qnetworkrequest_p.h
+++ b/src/network/access/qnetworkrequest_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp
index b761eb2e9b..5cf52af744 100644
--- a/src/network/bearer/qbearerengine.cpp
+++ b/src/network/bearer/qbearerengine.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qbearerengine_p.h b/src/network/bearer/qbearerengine_p.h
index 64af68a520..42481fcd15 100644
--- a/src/network/bearer/qbearerengine_p.h
+++ b/src/network/bearer/qbearerengine_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp
index bea7116451..02f6e36807 100644
--- a/src/network/bearer/qbearerplugin.cpp
+++ b/src/network/bearer/qbearerplugin.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qbearerplugin_p.h b/src/network/bearer/qbearerplugin_p.h
index 424dfe1edd..6533cebf4f 100644
--- a/src/network/bearer/qbearerplugin_p.h
+++ b/src/network/bearer/qbearerplugin_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp
index 28bbafab36..1a96ba77a9 100644
--- a/src/network/bearer/qnetworkconfigmanager.cpp
+++ b/src/network/bearer/qnetworkconfigmanager.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h
index e317cdfb44..5f4e64b957 100644
--- a/src/network/bearer/qnetworkconfigmanager.h
+++ b/src/network/bearer/qnetworkconfigmanager.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 54cd898c67..5f8f0dff53 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h
index e73e9bb399..dcd736cc6e 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.h
+++ b/src/network/bearer/qnetworkconfigmanager_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp
index e207feb97c..150e1cf715 100644
--- a/src/network/bearer/qnetworkconfiguration.cpp
+++ b/src/network/bearer/qnetworkconfiguration.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h
index 4839b7b809..5b650d0303 100644
--- a/src/network/bearer/qnetworkconfiguration.h
+++ b/src/network/bearer/qnetworkconfiguration.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h
index edb7105e6e..9acda9210b 100644
--- a/src/network/bearer/qnetworkconfiguration_p.h
+++ b/src/network/bearer/qnetworkconfiguration_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp
index f63298dba1..7f76fde4f0 100644
--- a/src/network/bearer/qnetworksession.cpp
+++ b/src/network/bearer/qnetworksession.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h
index 1eeea02ae1..5321875078 100644
--- a/src/network/bearer/qnetworksession.h
+++ b/src/network/bearer/qnetworksession.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h
index ddf0428b52..c43762136d 100644
--- a/src/network/bearer/qnetworksession_p.h
+++ b/src/network/bearer/qnetworksession_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qsharednetworksession.cpp b/src/network/bearer/qsharednetworksession.cpp
index f10eaaa489..358bc95377 100644
--- a/src/network/bearer/qsharednetworksession.cpp
+++ b/src/network/bearer/qsharednetworksession.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/bearer/qsharednetworksession_p.h b/src/network/bearer/qsharednetworksession_p.h
index 31b61b53ec..86946955a1 100644
--- a/src/network/bearer/qsharednetworksession_p.h
+++ b/src/network/bearer/qsharednetworksession_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp
index 8e64968346..0a3dddbe28 100644
--- a/src/network/kernel/qauthenticator.cpp
+++ b/src/network/kernel/qauthenticator.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -45,7 +45,7 @@
#include <qhash.h>
#include <qbytearray.h>
#include <qcryptographichash.h>
-#include <qhttp.h>
+#include <private/qhttpheader_p.h>
#include <qiodevice.h>
#include <qdatastream.h>
#include <qendian.h>
@@ -206,6 +206,8 @@ QString QAuthenticator::user() const
/*!
Sets the \a user used for authentication.
+
+ \sa QNetworkAccessManager::authenticationRequired()
*/
void QAuthenticator::setUser(const QString &user)
{
@@ -220,12 +222,6 @@ void QAuthenticator::setUser(const QString &user)
d->userDomain = user.left(separatorPosn);
d->extractedUser = user.mid(separatorPosn + 1);
d->user = user;
- } else if((separatorPosn = user.indexOf(QLatin1String("@"))) != -1) {
- //domain name is present
- d->realm.clear();
- d->userDomain = user.mid(separatorPosn + 1);
- d->extractedUser = user.left(separatorPosn);
- d->user = user;
} else {
d->extractedUser = user;
d->user = user;
@@ -250,6 +246,8 @@ QString QAuthenticator::password() const
/*!
Sets the \a password used for authentication.
+
+ \sa QNetworkAccessManager::authenticationRequired()
*/
void QAuthenticator::setPassword(const QString &password)
{
@@ -332,6 +330,7 @@ bool QAuthenticator::isNull() const
QAuthenticatorPrivate::QAuthenticatorPrivate()
: ref(0)
, method(None)
+ , hasFailed(false)
, phase(Start)
, nonceCount(0)
{
@@ -393,8 +392,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QList<QPair<QByteArray, QByt
switch(method) {
case Basic:
- if(realm.isEmpty())
- this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));
+ this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));
if (user.isEmpty() && password.isEmpty())
phase = Done;
break;
@@ -402,8 +400,7 @@ void QAuthenticatorPrivate::parseHttpResponse(const QList<QPair<QByteArray, QByt
// #### extract from header
break;
case DigestMd5: {
- if(realm.isEmpty())
- this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));
+ this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));
if (options.value("stale").toLower() == "true")
phase = Start;
if (user.isEmpty() && password.isEmpty())
@@ -1381,8 +1378,9 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas
int offset = QNtlmPhase3BlockBase::Size;
Q_ASSERT(QNtlmPhase3BlockBase::Size == sizeof(QNtlmPhase3BlockBase));
-
- if(ctx->userDomain.isEmpty()) {
+
+ // for kerberos style user@domain logins, NTLM domain string should be left empty
+ if (ctx->userDomain.isEmpty() && !ctx->extractedUser.contains(QLatin1Char('@'))) {
offset = qEncodeNtlmString(pb.domain, offset, ch.targetNameStr, unicode);
pb.domainStr = ch.targetNameStr;
} else {
diff --git a/src/network/kernel/qauthenticator.h b/src/network/kernel/qauthenticator.h
index 37649e905b..958532e9dc 100644
--- a/src/network/kernel/qauthenticator.h
+++ b/src/network/kernel/qauthenticator.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qauthenticator_p.h b/src/network/kernel/qauthenticator_p.h
index 88a30511b1..4b79202d92 100644
--- a/src/network/kernel/qauthenticator_p.h
+++ b/src/network/kernel/qauthenticator_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -77,6 +77,7 @@ public:
Method method;
QString realm;
QByteArray challenge;
+ bool hasFailed; //credentials have been tried but rejected by server.
enum Phase {
Start,
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index b662a1d610..3bda5410d0 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qhostaddress.h b/src/network/kernel/qhostaddress.h
index 83e8a7ce3c..4747499e38 100644
--- a/src/network/kernel/qhostaddress.h
+++ b/src/network/kernel/qhostaddress.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qhostaddress_p.h b/src/network/kernel/qhostaddress_p.h
index 255d706858..bc863a8562 100644
--- a/src/network/kernel/qhostaddress_p.h
+++ b/src/network/kernel/qhostaddress_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index 465345c085..45073f6ad1 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -248,10 +248,12 @@ QHostInfo QHostInfoPrivate::fromName(const QString &name, QSharedPointer<QNetwor
}
#endif
+#ifndef QT_NO_BEARERMANAGEMENT
QHostInfo QHostInfoAgent::fromName(const QString &hostName, QSharedPointer<QNetworkSession>)
{
return QHostInfoAgent::fromName(hostName);
}
+#endif
/*!
diff --git a/src/network/kernel/qhostinfo.h b/src/network/kernel/qhostinfo.h
index 80e39573ed..d84d6d72fa 100644
--- a/src/network/kernel/qhostinfo.h
+++ b/src/network/kernel/qhostinfo.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h
index fb7ae37c53..35de89c1e9 100644
--- a/src/network/kernel/qhostinfo_p.h
+++ b/src/network/kernel/qhostinfo_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -95,7 +95,9 @@ class QHostInfoAgent : public QObject
Q_OBJECT
public:
static QHostInfo fromName(const QString &hostName);
+#ifndef QT_NO_BEARERMANAGEMENT
static QHostInfo fromName(const QString &hostName, QSharedPointer<QNetworkSession> networkSession);
+#endif
};
class QHostInfoPrivate
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index 37444ae2d9..73882dd54f 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -329,7 +329,7 @@ QString QHostInfo::localDomainName()
resolveLibrary();
if (local_res_ninit) {
// using thread-safe version
- res_state_ptr state = res_state_ptr(qMalloc(sizeof(*state)));
+ res_state_ptr state = res_state_ptr(malloc(sizeof(*state)));
Q_CHECK_PTR(state);
memset(state, 0, sizeof(*state));
local_res_ninit(state);
@@ -337,7 +337,7 @@ QString QHostInfo::localDomainName()
if (domainName.isEmpty())
domainName = QUrl::fromAce(state->dnsrch[0]);
local_res_nclose(state);
- qFree(state);
+ free(state);
return domainName;
}
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index 10528634db..fc3724f879 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkinterface.cpp b/src/network/kernel/qnetworkinterface.cpp
index ed479b2b3f..1f69d9fa1b 100644
--- a/src/network/kernel/qnetworkinterface.cpp
+++ b/src/network/kernel/qnetworkinterface.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkinterface.h b/src/network/kernel/qnetworkinterface.h
index a749e53250..17a8e09cee 100644
--- a/src/network/kernel/qnetworkinterface.h
+++ b/src/network/kernel/qnetworkinterface.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkinterface_p.h b/src/network/kernel/qnetworkinterface_p.h
index d58909eb6a..a964f9bc54 100644
--- a/src/network/kernel/qnetworkinterface_p.h
+++ b/src/network/kernel/qnetworkinterface_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp
index 528e195ef6..8bd7e32766 100644
--- a/src/network/kernel/qnetworkinterface_unix.cpp
+++ b/src/network/kernel/qnetworkinterface_unix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp
index e8b96f6c47..da9fa80efc 100644
--- a/src/network/kernel/qnetworkinterface_win.cpp
+++ b/src/network/kernel/qnetworkinterface_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -110,12 +110,12 @@ static QHash<QHostAddress, QHostAddress> ipv4Netmasks()
DWORD retval = ptrGetAdaptersInfo(pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
- pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize);
+ pAdapter = (IP_ADAPTER_INFO *)malloc(bufSize);
if (!pAdapter)
return ipv4netmasks;
// try again
if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) {
- qFree(pAdapter);
+ free(pAdapter);
return ipv4netmasks;
}
} else if (retval != ERROR_SUCCESS) {
@@ -132,7 +132,7 @@ static QHash<QHostAddress, QHostAddress> ipv4Netmasks()
}
}
if (pAdapter != staticBuf)
- qFree(pAdapter);
+ free(pAdapter);
return ipv4netmasks;
@@ -153,12 +153,12 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
ULONG retval = ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
- pAdapter = (IP_ADAPTER_ADDRESSES *)qMalloc(bufSize);
+ pAdapter = (IP_ADAPTER_ADDRESSES *)malloc(bufSize);
if (!pAdapter)
return interfaces;
// try again
if (ptrGetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAdapter, &bufSize) != ERROR_SUCCESS) {
- qFree(pAdapter);
+ free(pAdapter);
return interfaces;
}
} else if (retval != ERROR_SUCCESS) {
@@ -219,7 +219,7 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWinXP()
}
if (pAdapter != staticBuf)
- qFree(pAdapter);
+ free(pAdapter);
return interfaces;
}
@@ -234,12 +234,12 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWin2k()
DWORD retval = ptrGetAdaptersInfo(pAdapter, &bufSize);
if (retval == ERROR_BUFFER_OVERFLOW) {
// need more memory
- pAdapter = (IP_ADAPTER_INFO *)qMalloc(bufSize);
+ pAdapter = (IP_ADAPTER_INFO *)malloc(bufSize);
if (!pAdapter)
return interfaces;
// try again
if (ptrGetAdaptersInfo(pAdapter, &bufSize) != ERROR_SUCCESS) {
- qFree(pAdapter);
+ free(pAdapter);
return interfaces;
}
} else if (retval != ERROR_SUCCESS) {
@@ -273,7 +273,7 @@ static QList<QNetworkInterfacePrivate *> interfaceListingWin2k()
}
if (pAdapter != staticBuf)
- qFree(pAdapter);
+ free(pAdapter);
return interfaces;
}
@@ -305,12 +305,12 @@ QString QHostInfo::localDomainName()
ULONG bufSize = sizeof info;
pinfo = &info;
if (ptrGetNetworkParams(pinfo, &bufSize) == ERROR_BUFFER_OVERFLOW) {
- pinfo = (FIXED_INFO *)qMalloc(bufSize);
+ pinfo = (FIXED_INFO *)malloc(bufSize);
if (!pinfo)
return QString();
// try again
if (ptrGetNetworkParams(pinfo, &bufSize) != ERROR_SUCCESS) {
- qFree(pinfo);
+ free(pinfo);
return QString(); // error
}
}
@@ -318,7 +318,7 @@ QString QHostInfo::localDomainName()
QString domainName = QUrl::fromAce(pinfo->DomainName);
if (pinfo != &info)
- qFree(pinfo);
+ free(pinfo);
return domainName;
}
diff --git a/src/network/kernel/qnetworkinterface_win_p.h b/src/network/kernel/qnetworkinterface_win_p.h
index f56d103a5f..0445e512d2 100644
--- a/src/network/kernel/qnetworkinterface_win_p.h
+++ b/src/network/kernel/qnetworkinterface_win_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp
index 19cf67feec..a8873d3be9 100644
--- a/src/network/kernel/qnetworkproxy.cpp
+++ b/src/network/kernel/qnetworkproxy.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -53,8 +53,8 @@
QNetworkProxy provides the method for configuring network layer
proxy support to the Qt network classes. The currently supported
- classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer,
- QNetworkAccessManager and QFtp. The proxy support is designed to
+ classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer
+ and QNetworkAccessManager. The proxy support is designed to
be as transparent as possible. This means that existing
network-enabled applications that you have written should
automatically support network proxy using the following code.
@@ -166,8 +166,7 @@
\row
\o Caching FTP
\o Implemented using an FTP proxy, it is useful only in the
- context of FTP requests (see QFtp,
- QNetworkAccessManager)
+ context of FTP requests (see QNetworkAccessManager)
\o CachingCapability, HostNameLookupCapability
\endtable
diff --git a/src/network/kernel/qnetworkproxy.h b/src/network/kernel/qnetworkproxy.h
index 07da51e5ec..472c220e62 100644
--- a/src/network/kernel/qnetworkproxy.h
+++ b/src/network/kernel/qnetworkproxy.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkproxy_generic.cpp b/src/network/kernel/qnetworkproxy_generic.cpp
index f78f63d561..9328eb379a 100644
--- a/src/network/kernel/qnetworkproxy_generic.cpp
+++ b/src/network/kernel/qnetworkproxy_generic.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkproxy_mac.cpp b/src/network/kernel/qnetworkproxy_mac.cpp
index 56c25d66f5..a994976860 100644
--- a/src/network/kernel/qnetworkproxy_mac.cpp
+++ b/src/network/kernel/qnetworkproxy_mac.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp
index 84112867e0..84b2b79c11 100644
--- a/src/network/kernel/qnetworkproxy_win.cpp
+++ b/src/network/kernel/qnetworkproxy_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qurlinfo.cpp b/src/network/kernel/qurlinfo.cpp
index fed954d30a..8b320a9e03 100644
--- a/src/network/kernel/qurlinfo.cpp
+++ b/src/network/kernel/qurlinfo.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/kernel/qurlinfo.h b/src/network/kernel/qurlinfo.h
index bd460867be..3bcdff6a9c 100644
--- a/src/network/kernel/qurlinfo.h
+++ b/src/network/kernel/qurlinfo.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp
index d74a717d93..e1a2449593 100644
--- a/src/network/socket/qabstractsocket.cpp
+++ b/src/network/socket/qabstractsocket.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -163,7 +163,7 @@
issue to be aware of, though: You must make sure that enough data
is available before attempting to read it using operator>>().
- \sa QFtp, QNetworkAccessManager, QTcpServer
+ \sa QNetworkAccessManager, QTcpServer
*/
/*!
@@ -315,6 +315,8 @@
proxy) was not found.
\value ProxyProtocolError The connection negotiation with the proxy server
because the response from the proxy server could not be understood.
+ \value OperationError An operation was attempted while the socket was in a state that
+ did not permit it.
\value UnknownSocketError An unidentified error occurred.
\sa QAbstractSocket::error()
@@ -347,18 +349,40 @@
\enum QAbstractSocket::SocketOption
\since 4.6
- This enum represents the options that can be set on a socket.
- If desired, they can be set after having received the connected() signal from
- the socket or after having received a new socket from a QTcpServer.
+ This enum represents the options that can be set on a socket. If
+ desired, they can be set after having received the connected()
+ signal from the socket or after having received a new socket from
+ a QTcpServer.
- \value LowDelayOption Try to optimize the socket for low latency. For a QTcpSocket
- this would set the TCP_NODELAY option and disable Nagle's algorithm. Set this to 1
- to enable.
- \value KeepAliveOption Set this to 1 to enable the SO_KEEPALIVE socket option
+ \value LowDelayOption Try to optimize the socket for low
+ latency. For a QTcpSocket this would set the TCP_NODELAY option
+ and disable Nagle's algorithm. Set this to 1 to enable.
- \value MulticastTtlOption Set this to an integer value to set IP_MULTICAST_TTL (TTL for multicast datagrams) socket option.
+ \value KeepAliveOption Set this to 1 to enable the SO_KEEPALIVE
+ socket option
- \value MulticastLoopbackOption Set this to 1 to enable the IP_MULTICAST_LOOP (multicast loopback) socket option.
+ \value MulticastTtlOption Set this to an integer value to set
+ IP_MULTICAST_TTL (TTL for multicast datagrams) socket option.
+
+ \value MulticastLoopbackOption Set this to 1 to enable the
+ IP_MULTICAST_LOOP (multicast loopback) socket option.
+
+ \value TypeOfServiceOption This option is not supported on
+ Windows. This maps to to the IP_TOS socket option.
+
+ Possible values for the \e{TypeOfServiceOption} are:
+
+ \table
+ \header \o Value \o Description
+ \row \o 224 \o Network control
+ \row \o 192 \o Internetwork control
+ \row \o 160 \o CRITIC/ECP
+ \row \o 128 \o Flash override
+ \row \o 96 \o Flash
+ \row \o 64 \o Immediate
+ \row \o 32 \o Priority
+ \row \o 0 \o Routine
+ \endtable
\sa QAbstractSocket::setSocketOption(), QAbstractSocket::socketOption()
*/
@@ -939,7 +963,7 @@ void QAbstractSocketPrivate::_q_startConnecting(const QHostInfo &hostInfo)
if (preferredNetworkLayerProtocol == QAbstractSocket::UnknownNetworkLayerProtocol || preferredNetworkLayerProtocol == QAbstractSocket::AnyIPProtocol) {
addresses = hostInfo.addresses();
} else {
- foreach (QHostAddress address, hostInfo.addresses())
+ foreach (const QHostAddress &address, hostInfo.addresses())
if (address.protocol() == preferredNetworkLayerProtocol)
addresses += address;
}
@@ -1455,27 +1479,6 @@ void QAbstractSocket::connectToHost(const QString &hostName, quint16 port,
NetworkLayerProtocol protocol)
{
Q_D(QAbstractSocket);
- d->preferredNetworkLayerProtocol = protocol;
-
- QMetaObject::invokeMethod(this, "connectToHostImplementation",
- Qt::DirectConnection,
- Q_ARG(QString, hostName),
- Q_ARG(quint16, port),
- Q_ARG(OpenMode, openMode));
-}
-
-/*!
- \since 4.1
-
- Contains the implementation of connectToHost().
-
- Attempts to make a connection to \a hostName on the given \a
- port. The socket is opened in the given \a openMode.
-*/
-void QAbstractSocket::connectToHostImplementation(const QString &hostName, quint16 port,
- OpenMode openMode)
-{
- Q_D(QAbstractSocket);
#if defined(QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocket::connectToHost(\"%s\", %i, %i)...", qPrintable(hostName), port,
(int) openMode);
@@ -1484,9 +1487,13 @@ void QAbstractSocket::connectToHostImplementation(const QString &hostName, quint
if (d->state == ConnectedState || d->state == ConnectingState
|| d->state == ClosingState || d->state == HostLookupState) {
qWarning("QAbstractSocket::connectToHost() called when already looking up or connecting/connected to \"%s\"", qPrintable(hostName));
+ d->socketError = QAbstractSocket::OperationError;
+ setErrorString(QAbstractSocket::tr("Trying to connect while connection is in progress"));
+ emit error(d->socketError);
return;
}
+ d->preferredNetworkLayerProtocol = protocol;
d->hostName = hostName;
d->port = port;
d->state = UnconnectedState;
@@ -1705,7 +1712,7 @@ bool QAbstractSocket::canReadLine() const
\sa setSocketDescriptor()
*/
-int QAbstractSocket::socketDescriptor() const
+qintptr QAbstractSocket::socketDescriptor() const
{
Q_D(const QAbstractSocket);
return d->cachedSocketDescriptor;
@@ -1723,7 +1730,7 @@ int QAbstractSocket::socketDescriptor() const
\sa socketDescriptor()
*/
-bool QAbstractSocket::setSocketDescriptor(int socketDescriptor, SocketState socketState,
+bool QAbstractSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState socketState,
OpenMode openMode)
{
Q_D(QAbstractSocket);
@@ -1805,6 +1812,10 @@ void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, cons
case MulticastLoopbackOption:
d_func()->socketEngine->setOption(QAbstractSocketEngine::MulticastLoopbackOption, value.toInt());
break;
+
+ case TypeOfServiceOption:
+ d_func()->socketEngine->setOption(QAbstractSocketEngine::TypeOfServiceOption, value.toInt());
+ break;
}
}
@@ -1841,6 +1852,10 @@ QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option)
case MulticastLoopbackOption:
ret = d_func()->socketEngine->option(QAbstractSocketEngine::MulticastLoopbackOption);
break;
+
+ case TypeOfServiceOption:
+ ret = d_func()->socketEngine->option(QAbstractSocketEngine::TypeOfServiceOption);
+ break;
}
if (ret == -1)
return QVariant();
@@ -2595,17 +2610,6 @@ void QAbstractSocket::close()
*/
void QAbstractSocket::disconnectFromHost()
{
- QMetaObject::invokeMethod(this, "disconnectFromHostImplementation",
- Qt::DirectConnection);
-}
-
-/*!
- \since 4.1
-
- Contains the implementation of disconnectFromHost().
-*/
-void QAbstractSocket::disconnectFromHostImplementation()
-{
Q_D(QAbstractSocket);
#if defined(QABSTRACTSOCKET_DEBUG)
qDebug("QAbstractSocket::disconnectFromHost()");
diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h
index ee910e3b33..e821f3ddb2 100644
--- a/src/network/socket/qabstractsocket.h
+++ b/src/network/socket/qabstractsocket.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -97,6 +97,7 @@ public:
ProxyConnectionTimeoutError,
ProxyNotFoundError,
ProxyProtocolError,
+ OperationError,
UnknownSocketError = -1
};
@@ -113,7 +114,8 @@ public:
LowDelayOption, // TCP_NODELAY
KeepAliveOption, // SO_KEEPALIVE
MulticastTtlOption, // IP_MULTICAST_TTL
- MulticastLoopbackOption // IP_MULTICAST_LOOPBACK
+ MulticastLoopbackOption, // IP_MULTICAST_LOOPBACK
+ TypeOfServiceOption //IP_TOS
};
enum BindFlag {
DefaultForPlatform = 0x0,
@@ -129,10 +131,9 @@ public:
bool bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform);
bool bind(quint16 port = 0, BindMode mode = DefaultForPlatform);
- // ### Qt 5: Make connectToHost() and disconnectFromHost() virtual.
- void connectToHost(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
- void connectToHost(const QHostAddress &address, quint16 port, OpenMode mode = ReadWrite);
- void disconnectFromHost();
+ virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
+ virtual void connectToHost(const QHostAddress &address, quint16 port, OpenMode mode = ReadWrite);
+ virtual void disconnectFromHost();
bool isValid() const;
@@ -154,8 +155,8 @@ public:
void abort();
// ### Qt 5: Make socketDescriptor() and setSocketDescriptor() virtual.
- int socketDescriptor() const;
- bool setSocketDescriptor(int socketDescriptor, SocketState state = ConnectedState,
+ qintptr socketDescriptor() const;
+ bool setSocketDescriptor(qintptr socketDescriptor, SocketState state = ConnectedState,
OpenMode openMode = ReadWrite);
// ### Qt 5: Make virtual?
@@ -194,10 +195,6 @@ Q_SIGNALS:
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
#endif
-protected Q_SLOTS:
- void connectToHostImplementation(const QString &hostName, quint16 port, OpenMode mode = ReadWrite);
- void disconnectFromHostImplementation();
-
protected:
qint64 readData(char *data, qint64 maxlen);
qint64 readLineData(char *data, qint64 maxlen);
diff --git a/src/network/socket/qabstractsocket_p.h b/src/network/socket/qabstractsocket_p.h
index 978fb1433a..49e7c82e21 100644
--- a/src/network/socket/qabstractsocket_p.h
+++ b/src/network/socket/qabstractsocket_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -118,7 +118,7 @@ public:
QString peerName;
QAbstractSocketEngine *socketEngine;
- int cachedSocketDescriptor;
+ qintptr cachedSocketDescriptor;
#ifndef QT_NO_NETWORKPROXY
QNetworkProxy proxy;
diff --git a/src/network/socket/qabstractsocketengine.cpp b/src/network/socket/qabstractsocketengine.cpp
index 7fc0ea3993..8c1ee88ce1 100644
--- a/src/network/socket/qabstractsocketengine.cpp
+++ b/src/network/socket/qabstractsocketengine.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -118,7 +118,7 @@ QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(QAbstractSocket
return new QNativeSocketEngine(parent);
}
-QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(int socketDescripter, QObject *parent)
+QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(qintptr socketDescripter, QObject *parent)
{
QMutexLocker locker(&socketHandlers()->mutex);
for (int i = 0; i < socketHandlers()->size(); i++) {
diff --git a/src/network/socket/qabstractsocketengine_p.h b/src/network/socket/qabstractsocketengine_p.h
index a8be98a0cf..e365eb8b5e 100644
--- a/src/network/socket/qabstractsocketengine_p.h
+++ b/src/network/socket/qabstractsocketengine_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -84,7 +84,7 @@ class Q_AUTOTEST_EXPORT QAbstractSocketEngine : public QObject
public:
static QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent);
- static QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
+ static QAbstractSocketEngine *createSocketEngine(qintptr socketDescriptor, QObject *parent);
QAbstractSocketEngine(QObject *parent = 0);
@@ -99,14 +99,15 @@ public:
LowDelayOption,
KeepAliveOption,
MulticastTtlOption,
- MulticastLoopbackOption
+ MulticastLoopbackOption,
+ TypeOfServiceOption
};
virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) = 0;
- virtual bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) = 0;
+ virtual bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) = 0;
- virtual int socketDescriptor() const = 0;
+ virtual qintptr socketDescriptor() const = 0;
virtual bool isValid() const = 0;
@@ -224,7 +225,7 @@ protected:
virtual ~QSocketEngineHandler();
virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
const QNetworkProxy &, QObject *parent) = 0;
- virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent) = 0;
+ virtual QAbstractSocketEngine *createSocketEngine(qintptr socketDescriptor, QObject *parent) = 0;
private:
friend class QAbstractSocketEngine;
diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp
index fd0119b8fd..e882f77dcd 100644
--- a/src/network/socket/qhttpsocketengine.cpp
+++ b/src/network/socket/qhttpsocketengine.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -43,7 +43,7 @@
#include "qtcpsocket.h"
#include "qhostaddress.h"
#include "qurl.h"
-#include "qhttp.h"
+#include "private/qhttpheader_p.h"
#include "qelapsedtimer.h"
#include "qnetworkinterface.h"
@@ -103,7 +103,7 @@ bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSo
return true;
}
-bool QHttpSocketEngine::initialize(int, QAbstractSocket::SocketState)
+bool QHttpSocketEngine::initialize(qintptr, QAbstractSocket::SocketState)
{
return false;
}
@@ -120,7 +120,7 @@ void QHttpSocketEngine::setProxy(const QNetworkProxy &proxy)
d->authenticator.setPassword(password);
}
-int QHttpSocketEngine::socketDescriptor() const
+qintptr QHttpSocketEngine::socketDescriptor() const
{
Q_D(const QHttpSocketEngine);
return d->socket ? d->socket->socketDescriptor() : 0;
@@ -136,6 +136,8 @@ bool QHttpSocketEngine::connectInternal()
{
Q_D(QHttpSocketEngine);
+ d->credentialsSent = false;
+
// If the handshake is done, enter ConnectedState state and return true.
if (d->state == Connected) {
qWarning("QHttpSocketEngine::connectToHost: called when already connected");
@@ -512,6 +514,7 @@ void QHttpSocketEngine::slotSocketConnected()
QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
//qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1);
if (priv && priv->method != QAuthenticatorPrivate::None) {
+ d->credentialsSent = true;
data += "Proxy-Authorization: " + priv->calculateResponse(method, path);
data += "\r\n";
}
@@ -589,15 +592,26 @@ void QHttpSocketEngine::slotSocketReadNotification()
d->readBuffer.clear(); // we parsed the proxy protocol response. from now on direct socket reading will be done
int statusCode = responseHeader.statusCode();
+ QAuthenticatorPrivate *priv = 0;
if (statusCode == 200) {
d->state = Connected;
setLocalAddress(d->socket->localAddress());
setLocalPort(d->socket->localPort());
setState(QAbstractSocket::ConnectedState);
+ d->authenticator.detach();
+ priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
+ priv->hasFailed = false;
} else if (statusCode == 407) {
- if (d->authenticator.isNull())
+ if (d->credentialsSent) {
+ //407 response again means the provided username/password were invalid.
+ d->authenticator = QAuthenticator(); //this is needed otherwise parseHttpResponse won't set the state, and then signal isn't emitted.
+ d->authenticator.detach();
+ priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
+ priv->hasFailed = true;
+ }
+ else if (d->authenticator.isNull())
d->authenticator.detach();
- QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
+ priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
priv->parseHttpResponse(responseHeader, true);
@@ -637,7 +651,6 @@ void QHttpSocketEngine::slotSocketReadNotification()
if (priv->phase == QAuthenticatorPrivate::Done)
emit proxyAuthenticationRequired(d->proxy, &d->authenticator);
-
// priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above.
if (priv->phase == QAuthenticatorPrivate::Done) {
setError(QAbstractSocket::ProxyAuthenticationRequiredError, tr("Authentication required"));
@@ -794,6 +807,7 @@ QHttpSocketEnginePrivate::QHttpSocketEnginePrivate()
, readNotificationPending(false)
, writeNotificationPending(false)
, connectionNotificationPending(false)
+ , credentialsSent(false)
, pendingResponseData(0)
{
socket = 0;
@@ -824,7 +838,7 @@ QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSoc
return engine;
}
-QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(int, QObject *)
+QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(qintptr, QObject *)
{
return 0;
}
diff --git a/src/network/socket/qhttpsocketengine_p.h b/src/network/socket/qhttpsocketengine_p.h
index d7cc7c1604..1a93956bd2 100644
--- a/src/network/socket/qhttpsocketengine_p.h
+++ b/src/network/socket/qhttpsocketengine_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -80,11 +80,11 @@ public:
~QHttpSocketEngine();
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol);
- bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
+ bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
void setProxy(const QNetworkProxy &networkProxy);
- int socketDescriptor() const;
+ qintptr socketDescriptor() const;
bool isValid() const;
@@ -182,6 +182,7 @@ public:
bool readNotificationPending;
bool writeNotificationPending;
bool connectionNotificationPending;
+ bool credentialsSent;
uint pendingResponseData;
};
@@ -190,7 +191,7 @@ class Q_AUTOTEST_EXPORT QHttpSocketEngineHandler : public QSocketEngineHandler
public:
virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
const QNetworkProxy &, QObject *parent);
- virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
+ virtual QAbstractSocketEngine *createSocketEngine(qintptr socketDescripter, QObject *parent);
};
#endif
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index ffd87aa946..fc5fe3443e 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qlocalserver.h b/src/network/socket/qlocalserver.h
index 4468bf90e3..6887c16056 100644
--- a/src/network/socket/qlocalserver.h
+++ b/src/network/socket/qlocalserver.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qlocalserver_p.h b/src/network/socket/qlocalserver_p.h
index ed699fc1d5..d762818692 100644
--- a/src/network/socket/qlocalserver_p.h
+++ b/src/network/socket/qlocalserver_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qlocalserver_tcp.cpp b/src/network/socket/qlocalserver_tcp.cpp
index 47c4204802..cb4ee53f6a 100644
--- a/src/network/socket/qlocalserver_tcp.cpp
+++ b/src/network/socket/qlocalserver_tcp.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qlocalserver_unix.cpp b/src/network/socket/qlocalserver_unix.cpp
index e0115de8d2..5859ab0080 100644
--- a/src/network/socket/qlocalserver_unix.cpp
+++ b/src/network/socket/qlocalserver_unix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qlocalserver_win.cpp b/src/network/socket/qlocalserver_win.cpp
index 8e6bbc6deb..bdbe4d74f1 100644
--- a/src/network/socket/qlocalserver_win.cpp
+++ b/src/network/socket/qlocalserver_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qlocalsocket.cpp b/src/network/socket/qlocalsocket.cpp
index 219d2aa8ad..e311f6a060 100644
--- a/src/network/socket/qlocalsocket.cpp
+++ b/src/network/socket/qlocalsocket.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -94,7 +94,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
+ \fn bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
LocalSocketState socketState, OpenMode openMode)
Initializes QLocalSocket with the native socket descriptor
@@ -110,7 +110,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn quintptr QLocalSocket::socketDescriptor() const
+ \fn qintptr QLocalSocket::socketDescriptor() const
Returns the native socket descriptor of the QLocalSocket object if
this is available; otherwise returns -1.
@@ -419,6 +419,8 @@ bool QLocalSocket::isSequential() const
\value ConnectionError An error occurred with the connection.
\value UnsupportedSocketOperationError The requested socket operation
is not supported by the local operating system.
+ \value OperationError An operation was attempted while the socket was in a state that
+ did not permit it.
\value UnknownSocketError An unidentified error occurred.
*/
diff --git a/src/network/socket/qlocalsocket.h b/src/network/socket/qlocalsocket.h
index 698c06377b..bb39b0f4c8 100644
--- a/src/network/socket/qlocalsocket.h
+++ b/src/network/socket/qlocalsocket.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -72,7 +72,8 @@ public:
DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError,
ConnectionError = QAbstractSocket::NetworkError,
UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError,
- UnknownSocketError = QAbstractSocket::UnknownSocketError
+ UnknownSocketError = QAbstractSocket::UnknownSocketError,
+ OperationError = QAbstractSocket::OperationError
};
enum LocalSocketState
@@ -104,10 +105,10 @@ public:
qint64 readBufferSize() const;
void setReadBufferSize(qint64 size);
- bool setSocketDescriptor(quintptr socketDescriptor,
+ bool setSocketDescriptor(qintptr socketDescriptor,
LocalSocketState socketState = ConnectedState,
OpenMode openMode = ReadWrite);
- quintptr socketDescriptor() const;
+ qintptr socketDescriptor() const;
LocalSocketState state() const;
bool waitForBytesWritten(int msecs = 30000);
@@ -131,10 +132,9 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
#elif defined(Q_OS_WIN)
- Q_PRIVATE_SLOT(d_func(), void _q_notified())
Q_PRIVATE_SLOT(d_func(), void _q_canWrite())
Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed())
- Q_PRIVATE_SLOT(d_func(), void _q_emitReadyRead())
+ Q_PRIVATE_SLOT(d_func(), void _q_winError(ulong, const QString &))
#else
Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
diff --git a/src/network/socket/qlocalsocket_p.h b/src/network/socket/qlocalsocket_p.h
index a0749fd35f..3541d950e8 100644
--- a/src/network/socket/qlocalsocket_p.h
+++ b/src/network/socket/qlocalsocket_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -63,8 +63,8 @@
#if defined(QT_LOCALSOCKET_TCP)
# include "qtcpsocket.h"
#elif defined(Q_OS_WIN)
+# include "private/qwindowspipereader_p.h"
# include "private/qwindowspipewriter_p.h"
-# include "private/qringbuffer_p.h"
# include <qwineventnotifier.h>
#else
# include "private/qabstractsocketengine_p.h"
@@ -131,26 +131,13 @@ public:
~QLocalSocketPrivate();
void destroyPipeHandles();
void setErrorString(const QString &function);
- void _q_notified();
void _q_canWrite();
void _q_pipeClosed();
- void _q_emitReadyRead();
- DWORD checkPipeState();
- void startAsyncRead();
- bool completeAsyncRead();
- void checkReadyRead();
+ void _q_winError(ulong windowsError, const QString &function);
HANDLE handle;
- OVERLAPPED overlapped;
QWindowsPipeWriter *pipeWriter;
- qint64 readBufferMaxSize;
- QRingBuffer readBuffer;
- int actualReadBufferSize;
- QWinEventNotifier *dataReadNotifier;
+ QWindowsPipeReader *pipeReader;
QLocalSocket::LocalSocketError error;
- bool readSequenceStarted;
- bool pendingReadyRead;
- bool pipeClosed;
- static const qint64 initialReadBufferSize = 4096;
#else
QLocalUnixSocket unixSocket;
QString generateErrorString(QLocalSocket::LocalSocketError, const QString &function) const;
diff --git a/src/network/socket/qlocalsocket_tcp.cpp b/src/network/socket/qlocalsocket_tcp.cpp
index 38d2b627b1..3b83d0ee01 100644
--- a/src/network/socket/qlocalsocket_tcp.cpp
+++ b/src/network/socket/qlocalsocket_tcp.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -155,6 +155,9 @@ QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError
case QLocalSocket::UnsupportedSocketOperationError:
errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
break;
+ case QLocalSocket::OperationError:
+ errorString = QLocalSocket::tr("%1: Operation not permitted when socket is in this state").arg(function);
+ break;
case QLocalSocket::UnknownSocketError:
default:
errorString = QLocalSocket::tr("%1: Unknown error").arg(function);
@@ -247,7 +250,7 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
QIODevice::open(openMode);
}
-bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
+bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
LocalSocketState socketState, OpenMode openMode)
{
Q_D(QLocalSocket);
@@ -287,7 +290,7 @@ bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
newSocketState, openMode);
}
-quintptr QLocalSocket::socketDescriptor() const
+qintptr QLocalSocket::socketDescriptor() const
{
Q_D(const QLocalSocket);
return d->tcpSocket->socketDescriptor();
diff --git a/src/network/socket/qlocalsocket_unix.cpp b/src/network/socket/qlocalsocket_unix.cpp
index 1bdf604eb1..5bd929d477 100644
--- a/src/network/socket/qlocalsocket_unix.cpp
+++ b/src/network/socket/qlocalsocket_unix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -162,6 +162,9 @@ QString QLocalSocketPrivate::generateErrorString(QLocalSocket::LocalSocketError
case QLocalSocket::UnsupportedSocketOperationError:
errorString = QLocalSocket::tr("%1: The socket operation is not supported").arg(function);
break;
+ case QLocalSocket::OperationError:
+ errorString = QLocalSocket::tr("%1: Operation not permitted when socket is in this state").arg(function);
+ break;
case QLocalSocket::UnknownSocketError:
default:
errorString = QLocalSocket::tr("%1: Unknown error %2").arg(function).arg(errno);
@@ -221,9 +224,12 @@ void QLocalSocketPrivate::errorOccurred(QLocalSocket::LocalSocketError error, co
void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
{
Q_D(QLocalSocket);
- if (state() == ConnectedState
- || state() == ConnectingState)
+ if (state() == ConnectedState || state() == ConnectingState) {
+ QString errorString = d->generateErrorString(QLocalSocket::OperationError, QLatin1String("QLocalSocket::connectToserver"));
+ setErrorString(errorString);
+ emit error(QLocalSocket::OperationError);
return;
+ }
d->errorString.clear();
d->unixSocket.setSocketState(QAbstractSocket::ConnectingState);
@@ -343,7 +349,7 @@ void QLocalSocketPrivate::_q_connectToSocket()
connectingOpenMode = 0;
}
-bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
+bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
LocalSocketState socketState, OpenMode openMode)
{
Q_D(QLocalSocket);
@@ -386,7 +392,7 @@ void QLocalSocketPrivate::cancelDelayedConnect()
}
}
-quintptr QLocalSocket::socketDescriptor() const
+qintptr QLocalSocket::socketDescriptor() const
{
Q_D(const QLocalSocket);
return d->unixSocket.socketDescriptor();
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index f595ba72ae..99942a6138 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -50,16 +50,21 @@ QT_BEGIN_NAMESPACE
void QLocalSocketPrivate::init()
{
Q_Q(QLocalSocket);
- memset(&overlapped, 0, sizeof(overlapped));
- overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- dataReadNotifier = new QWinEventNotifier(overlapped.hEvent, q);
- q->connect(dataReadNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_notified()));
+ pipeReader = new QWindowsPipeReader(q);
+ q->connect(pipeReader, SIGNAL(readyRead()), SIGNAL(readyRead()));
+ q->connect(pipeReader, SIGNAL(pipeClosed()), SLOT(_q_pipeClosed()), Qt::QueuedConnection);
+ q->connect(pipeReader, SIGNAL(winError(ulong, const QString &)), SLOT(_q_winError(ulong, const QString &)));
}
void QLocalSocketPrivate::setErrorString(const QString &function)
{
+ DWORD windowsError = GetLastError();
+ _q_winError(windowsError, function);
+}
+
+void QLocalSocketPrivate::_q_winError(ulong windowsError, const QString &function)
+{
Q_Q(QLocalSocket);
- BOOL windowsError = GetLastError();
QLocalSocket::LocalSocketState currentState = state;
// If the connectToServer fails due to WaitNamedPipe() time-out, assume ConnectionError
@@ -95,7 +100,7 @@ void QLocalSocketPrivate::setErrorString(const QString &function)
if (currentState != state) {
q->emit stateChanged(state);
- if (state == QLocalSocket::UnconnectedState)
+ if (state == QLocalSocket::UnconnectedState && currentState != QLocalSocket::ConnectingState)
q->emit disconnected();
}
emit q->error(error);
@@ -103,13 +108,9 @@ void QLocalSocketPrivate::setErrorString(const QString &function)
QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
handle(INVALID_HANDLE_VALUE),
+ pipeReader(0),
pipeWriter(0),
- readBufferMaxSize(0),
- actualReadBufferSize(0),
error(QLocalSocket::UnknownSocketError),
- readSequenceStarted(false),
- pendingReadyRead(false),
- pipeClosed(false),
state(QLocalSocket::UnconnectedState)
{
}
@@ -117,7 +118,6 @@ QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(),
QLocalSocketPrivate::~QLocalSocketPrivate()
{
destroyPipeHandles();
- CloseHandle(overlapped.hEvent);
}
void QLocalSocketPrivate::destroyPipeHandles()
@@ -131,8 +131,11 @@ void QLocalSocketPrivate::destroyPipeHandles()
void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
{
Q_D(QLocalSocket);
- if (state() == ConnectedState || state() == ConnectingState)
+ if (state() == ConnectedState || state() == ConnectingState) {
+ setErrorString(tr("Trying to connect while connection is in progress"));
+ emit error(QLocalSocket::OperationError);
return;
+ }
d->error = QLocalSocket::UnknownSocketError;
d->errorString = QString();
@@ -186,7 +189,7 @@ void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
// we have a valid handle
d->serverName = name;
- if (setSocketDescriptor((quintptr)localSocket, ConnectedState, openMode)) {
+ if (setSocketDescriptor((qintptr)localSocket, ConnectedState, openMode)) {
d->handle = localSocket;
emit connected();
}
@@ -197,146 +200,7 @@ qint64 QLocalSocket::readData(char *data, qint64 maxSize)
{
Q_D(QLocalSocket);
- if (d->pipeClosed && d->actualReadBufferSize == 0)
- return -1; // signal EOF
-
- qint64 readSoFar;
- // If startAsyncRead() read data, copy it to its destination.
- if (maxSize == 1 && d->actualReadBufferSize > 0) {
- *data = d->readBuffer.getChar();
- d->actualReadBufferSize--;
- readSoFar = 1;
- } else {
- qint64 bytesToRead = qMin(qint64(d->actualReadBufferSize), maxSize);
- readSoFar = 0;
- while (readSoFar < bytesToRead) {
- const char *ptr = d->readBuffer.readPointer();
- int bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar,
- qint64(d->readBuffer.nextDataBlockSize()));
- memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
- readSoFar += bytesToReadFromThisBlock;
- d->readBuffer.free(bytesToReadFromThisBlock);
- d->actualReadBufferSize -= bytesToReadFromThisBlock;
- }
- }
-
- if (d->pipeClosed) {
- if (d->actualReadBufferSize == 0)
- QTimer::singleShot(0, this, SLOT(_q_pipeClosed()));
- } else {
- if (!d->readSequenceStarted)
- d->startAsyncRead();
- d->checkReadyRead();
- }
-
- return readSoFar;
-}
-
-/*!
- \internal
- Schedules or cancels a readyRead() emission depending on actual data availability
- */
-void QLocalSocketPrivate::checkReadyRead()
-{
- if (actualReadBufferSize > 0) {
- if (!pendingReadyRead) {
- Q_Q(QLocalSocket);
- QTimer::singleShot(0, q, SLOT(_q_emitReadyRead()));
- pendingReadyRead = true;
- }
- } else {
- pendingReadyRead = false;
- }
-}
-
-/*!
- \internal
- Reads data from the socket into the readbuffer
- */
-void QLocalSocketPrivate::startAsyncRead()
-{
- do {
- DWORD bytesToRead = checkPipeState();
- if (pipeClosed)
- return;
-
- if (bytesToRead == 0) {
- // There are no bytes in the pipe but we need to
- // start the overlapped read with some buffer size.
- bytesToRead = initialReadBufferSize;
- }
-
- if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - readBuffer.size())) {
- bytesToRead = readBufferMaxSize - readBuffer.size();
- if (bytesToRead == 0) {
- // Buffer is full. User must read data from the buffer
- // before we can read more from the pipe.
- return;
- }
- }
-
- char *ptr = readBuffer.reserve(bytesToRead);
-
- readSequenceStarted = true;
- if (ReadFile(handle, ptr, bytesToRead, NULL, &overlapped)) {
- completeAsyncRead();
- } else {
- switch (GetLastError()) {
- case ERROR_IO_PENDING:
- // This is not an error. We're getting notified, when data arrives.
- return;
- case ERROR_MORE_DATA:
- // This is not an error. The synchronous read succeeded.
- // We're connected to a message mode pipe and the message
- // didn't fit into the pipe's system buffer.
- completeAsyncRead();
- break;
- case ERROR_PIPE_NOT_CONNECTED:
- {
- // It may happen, that the other side closes the connection directly
- // after writing data. Then we must set the appropriate socket state.
- pipeClosed = true;
- Q_Q(QLocalSocket);
- emit q->readChannelFinished();
- return;
- }
- default:
- setErrorString(QLatin1String("QLocalSocketPrivate::startAsyncRead"));
- return;
- }
- }
- } while (!readSequenceStarted);
-}
-
-/*!
- \internal
- Sets the correct size of the read buffer after a read operation.
- Returns false, if an error occurred or the connection dropped.
- */
-bool QLocalSocketPrivate::completeAsyncRead()
-{
- ResetEvent(overlapped.hEvent);
- readSequenceStarted = false;
-
- DWORD bytesRead;
- if (!GetOverlappedResult(handle, &overlapped, &bytesRead, TRUE)) {
- switch (GetLastError()) {
- case ERROR_MORE_DATA:
- // This is not an error. We're connected to a message mode
- // pipe and the message didn't fit into the pipe's system
- // buffer. We will read the remaining data in the next call.
- break;
- case ERROR_PIPE_NOT_CONNECTED:
- return false;
- default:
- setErrorString(QLatin1String("QLocalSocketPrivate::completeAsyncRead"));
- return false;
- }
- }
-
- actualReadBufferSize += bytesRead;
- readBuffer.truncate(actualReadBufferSize);
- return true;
+ return d->pipeReader->read(data, maxSize);
}
qint64 QLocalSocket::writeData(const char *data, qint64 maxSize)
@@ -361,39 +225,38 @@ void QLocalSocket::abort()
close();
}
-/*!
- \internal
- Returns the number of available bytes in the pipe.
- Sets QLocalSocketPrivate::pipeClosed to true if the connection is broken.
- */
-DWORD QLocalSocketPrivate::checkPipeState()
+void QLocalSocketPrivate::_q_pipeClosed()
{
Q_Q(QLocalSocket);
- DWORD bytes;
- if (PeekNamedPipe(handle, NULL, 0, NULL, &bytes, NULL)) {
- return bytes;
- } else {
- if (!pipeClosed) {
- pipeClosed = true;
- emit q->readChannelFinished();
- if (actualReadBufferSize == 0)
- QTimer::singleShot(0, q, SLOT(_q_pipeClosed()));
- }
+ if (state == QLocalSocket::UnconnectedState)
+ return;
+
+ emit q->readChannelFinished();
+ if (state != QLocalSocket::ClosingState) {
+ state = QLocalSocket::ClosingState;
+ emit q->stateChanged(state);
+ if (state != QLocalSocket::ClosingState)
+ return;
}
- return 0;
-}
+ state = QLocalSocket::UnconnectedState;
+ emit q->stateChanged(state);
+ emit q->disconnected();
-void QLocalSocketPrivate::_q_pipeClosed()
-{
- Q_Q(QLocalSocket);
- q->close();
+ pipeReader->stop();
+ destroyPipeHandles();
+ handle = INVALID_HANDLE_VALUE;
+
+ if (pipeWriter) {
+ delete pipeWriter;
+ pipeWriter = 0;
+ }
}
qint64 QLocalSocket::bytesAvailable() const
{
Q_D(const QLocalSocket);
qint64 available = QIODevice::bytesAvailable();
- available += (qint64) d->actualReadBufferSize;
+ available += d->pipeReader->bytesAvailable();
return available;
}
@@ -406,42 +269,26 @@ qint64 QLocalSocket::bytesToWrite() const
bool QLocalSocket::canReadLine() const
{
Q_D(const QLocalSocket);
- if (state() != ConnectedState)
- return false;
- return (QIODevice::canReadLine()
- || d->readBuffer.indexOf('\n', d->actualReadBufferSize) != -1);
+ return QIODevice::canReadLine() || d->pipeReader->canReadLine();
}
void QLocalSocket::close()
{
Q_D(QLocalSocket);
- if (state() == UnconnectedState)
+ if (openMode() == NotOpen)
return;
QIODevice::close();
- d->state = ClosingState;
- emit stateChanged(d->state);
- if (!d->pipeClosed)
- emit readChannelFinished();
d->serverName = QString();
d->fullServerName = QString();
- if (state() != UnconnectedState && bytesToWrite() > 0) {
- disconnectFromServer();
- return;
- }
- d->readSequenceStarted = false;
- d->pendingReadyRead = false;
- d->pipeClosed = false;
- d->destroyPipeHandles();
- d->handle = INVALID_HANDLE_VALUE;
- ResetEvent(d->overlapped.hEvent);
- d->state = UnconnectedState;
- emit stateChanged(d->state);
- emit disconnected();
- if (d->pipeWriter) {
- delete d->pipeWriter;
- d->pipeWriter = 0;
+ if (state() != UnconnectedState) {
+ if (bytesToWrite() > 0) {
+ disconnectFromServer();
+ return;
+ }
+
+ d->_q_pipeClosed();
}
}
@@ -480,20 +327,18 @@ QLocalSocket::LocalSocketError QLocalSocket::error() const
return d->error;
}
-bool QLocalSocket::setSocketDescriptor(quintptr socketDescriptor,
+bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor,
LocalSocketState socketState, OpenMode openMode)
{
Q_D(QLocalSocket);
- d->readBuffer.clear();
- d->actualReadBufferSize = 0;
- QIODevice::open(openMode);
- d->handle = (int*)socketDescriptor;
+ d->pipeReader->stop();
+ d->handle = reinterpret_cast<HANDLE>(socketDescriptor);
d->state = socketState;
+ d->pipeReader->setHandle(d->handle);
+ QIODevice::open(openMode);
emit stateChanged(d->state);
- if (d->state == ConnectedState && openMode.testFlag(QIODevice::ReadOnly)) {
- d->startAsyncRead();
- d->checkReadyRead();
- }
+ if (d->state == ConnectedState && openMode.testFlag(QIODevice::ReadOnly))
+ d->pipeReader->startAsyncRead();
return true;
}
@@ -504,46 +349,22 @@ void QLocalSocketPrivate::_q_canWrite()
q->close();
}
-void QLocalSocketPrivate::_q_notified()
-{
- Q_Q(QLocalSocket);
- if (!completeAsyncRead()) {
- pipeClosed = true;
- emit q->readChannelFinished();
- if (actualReadBufferSize == 0)
- QTimer::singleShot(0, q, SLOT(_q_pipeClosed()));
- return;
- }
- startAsyncRead();
- pendingReadyRead = false;
- emit q->readyRead();
-}
-
-void QLocalSocketPrivate::_q_emitReadyRead()
-{
- if (pendingReadyRead) {
- Q_Q(QLocalSocket);
- pendingReadyRead = false;
- emit q->readyRead();
- }
-}
-
-quintptr QLocalSocket::socketDescriptor() const
+qintptr QLocalSocket::socketDescriptor() const
{
Q_D(const QLocalSocket);
- return (quintptr)d->handle;
+ return (qintptr)d->handle;
}
qint64 QLocalSocket::readBufferSize() const
{
Q_D(const QLocalSocket);
- return d->readBufferMaxSize;
+ return d->pipeReader->maxReadBufferSize();
}
void QLocalSocket::setReadBufferSize(qint64 size)
{
Q_D(QLocalSocket);
- d->readBufferMaxSize = size;
+ d->pipeReader->setMaxReadBufferSize(size);
}
bool QLocalSocket::waitForConnected(int msecs)
@@ -561,18 +382,10 @@ bool QLocalSocket::waitForDisconnected(int msecs)
qWarning("QLocalSocket::waitForDisconnected isn't supported for write only pipes.");
return false;
}
- QIncrementalSleepTimer timer(msecs);
- forever {
- d->checkPipeState();
- if (d->pipeClosed)
- close();
- if (state() == UnconnectedState)
- return true;
- Sleep(timer.nextSleepTime());
- if (timer.hasTimedOut())
- break;
+ if (d->pipeReader->waitForPipeClosed(msecs)) {
+ d->_q_pipeClosed();
+ return true;
}
-
return false;
}
@@ -593,28 +406,18 @@ bool QLocalSocket::waitForReadyRead(int msecs)
return false;
// We already know that the pipe is gone, but did not enter the event loop yet.
- if (d->pipeClosed) {
- close();
+ if (d->pipeReader->isPipeClosed()) {
+ d->_q_pipeClosed();
return false;
}
- Q_ASSERT(d->readSequenceStarted);
- DWORD result = WaitForSingleObject(d->overlapped.hEvent, msecs == -1 ? INFINITE : msecs);
- switch (result) {
- case WAIT_OBJECT_0:
- d->_q_notified();
- // We just noticed that the pipe is gone.
- if (d->pipeClosed) {
- close();
- return false;
- }
- return true;
- case WAIT_TIMEOUT:
- return false;
- }
+ bool result = d->pipeReader->waitForReadyRead(msecs);
- qWarning("QLocalSocket::waitForReadyRead WaitForSingleObject failed with error code %d.", int(GetLastError()));
- return false;
+ // We just noticed that the pipe is gone.
+ if (d->pipeReader->isPipeClosed())
+ d->_q_pipeClosed();
+
+ return result;
}
bool QLocalSocket::waitForBytesWritten(int msecs)
diff --git a/src/network/socket/qnativesocketengine.cpp b/src/network/socket/qnativesocketengine.cpp
index 5e3e22a23e..cae2469328 100644
--- a/src/network/socket/qnativesocketengine.cpp
+++ b/src/network/socket/qnativesocketengine.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -414,7 +414,7 @@ bool QNativeSocketEngine::initialize(QAbstractSocket::SocketType socketType, QAb
If the socket type is either TCP or UDP, it is made non-blocking.
UDP sockets are also broadcast enabled.
*/
-bool QNativeSocketEngine::initialize(int socketDescriptor, QAbstractSocket::SocketState socketState)
+bool QNativeSocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState)
{
Q_D(QNativeSocketEngine);
@@ -471,7 +471,7 @@ bool QNativeSocketEngine::isValid() const
Returns the native socket descriptor. Any use of this descriptor
stands the risk of being non-portable.
*/
-int QNativeSocketEngine::socketDescriptor() const
+qintptr QNativeSocketEngine::socketDescriptor() const
{
Q_D(const QNativeSocketEngine);
return d->socketDescriptor;
@@ -1114,7 +1114,7 @@ bool QNativeSocketEngine::isReadNotificationEnabled() const
class QReadNotifier : public QSocketNotifier
{
public:
- QReadNotifier(int fd, QNativeSocketEngine *parent)
+ QReadNotifier(qintptr fd, QNativeSocketEngine *parent)
: QSocketNotifier(fd, QSocketNotifier::Read, parent)
{ engine = parent; }
diff --git a/src/network/socket/qnativesocketengine_p.h b/src/network/socket/qnativesocketengine_p.h
index a024cd42d1..60c13c1258 100644
--- a/src/network/socket/qnativesocketengine_p.h
+++ b/src/network/socket/qnativesocketengine_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -113,9 +113,9 @@ public:
~QNativeSocketEngine();
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol);
- bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
+ bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
- int socketDescriptor() const;
+ qintptr socketDescriptor() const;
bool isValid() const;
@@ -199,7 +199,7 @@ public:
QNativeSocketEnginePrivate();
~QNativeSocketEnginePrivate();
- int socketDescriptor;
+ qintptr socketDescriptor;
QSocketNotifier *readNotifier, *writeNotifier, *exceptNotifier;
diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp
index 09aed255d6..324705d998 100644
--- a/src/network/socket/qnativesocketengine_unix.cpp
+++ b/src/network/socket/qnativesocketengine_unix.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -251,6 +251,12 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co
n = IP_MULTICAST_LOOP;
}
break;
+ case QNativeSocketEngine::TypeOfServiceOption:
+ if (socketProtocol == QAbstractSocket::IPv4Protocol) {
+ level = IPPROTO_IP;
+ n = IP_TOS;
+ }
+ break;
}
int v = -1;
@@ -352,6 +358,12 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt
n = IP_MULTICAST_LOOP;
}
break;
+ case QNativeSocketEngine::TypeOfServiceOption:
+ if (socketProtocol == QAbstractSocket::IPv4Protocol) {
+ level = IPPROTO_IP;
+ n = IP_TOS;
+ }
+ break;
}
return ::setsockopt(socketDescriptor, level, n, (char *) &v, sizeof(v)) == 0;
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 247de01072..ee15702b76 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -229,7 +229,7 @@ void QNativeSocketEnginePrivate::setPortAndAddress(sockaddr_in * sockAddrIPv4, q
/*! \internal
*/
-static inline QAbstractSocket::SocketType qt_socket_getType(int socketDescriptor)
+static inline QAbstractSocket::SocketType qt_socket_getType(qintptr socketDescriptor)
{
int value = 0;
QT_SOCKLEN_T valueSize = sizeof(value);
@@ -247,7 +247,7 @@ static inline QAbstractSocket::SocketType qt_socket_getType(int socketDescriptor
/*! \internal
*/
-static inline int qt_socket_getMaxMsgSize(int socketDescriptor)
+static inline int qt_socket_getMaxMsgSize(qintptr socketDescriptor)
{
int value = 0;
QT_SOCKLEN_T valueSize = sizeof(value);
@@ -422,6 +422,9 @@ int QNativeSocketEnginePrivate::option(QNativeSocketEngine::SocketOption opt) co
n = IP_MULTICAST_LOOP;
}
break;
+ case QNativeSocketEngine::TypeOfServiceOption:
+ return -1;
+ break;
}
int v = -1;
@@ -502,6 +505,9 @@ bool QNativeSocketEnginePrivate::setOption(QNativeSocketEngine::SocketOption opt
n = IP_MULTICAST_LOOP;
}
break;
+ case QNativeSocketEngine::TypeOfServiceOption:
+ return false;
+ break;
}
if (::setsockopt(socketDescriptor, level, n, (char*)&v, sizeof(v)) != 0) {
diff --git a/src/network/socket/qnet_unix_p.h b/src/network/socket/qnet_unix_p.h
index fe22c329e4..7b2ba54648 100644
--- a/src/network/socket/qnet_unix_p.h
+++ b/src/network/socket/qnet_unix_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp
index 5f510fa84b..919bdea2e0 100644
--- a/src/network/socket/qsocks5socketengine.cpp
+++ b/src/network/socket/qsocks5socketengine.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -332,9 +332,9 @@ public:
QSocks5BindStore();
~QSocks5BindStore();
- void add(int socketDescriptor, QSocks5BindData *bindData);
- bool contains(int socketDescriptor);
- QSocks5BindData *retrieve(int socketDescriptor);
+ void add(qintptr socketDescriptor, QSocks5BindData *bindData);
+ bool contains(qintptr socketDescriptor);
+ QSocks5BindData *retrieve(qintptr socketDescriptor);
protected:
void timerEvent(QTimerEvent * event);
@@ -360,7 +360,7 @@ QSocks5BindStore::~QSocks5BindStore()
{
}
-void QSocks5BindStore::add(int socketDescriptor, QSocks5BindData *bindData)
+void QSocks5BindStore::add(qintptr socketDescriptor, QSocks5BindData *bindData)
{
QMutexLocker lock(&mutex);
if (store.contains(socketDescriptor)) {
@@ -373,13 +373,13 @@ void QSocks5BindStore::add(int socketDescriptor, QSocks5BindData *bindData)
sweepTimerId = startTimer(60000);
}
-bool QSocks5BindStore::contains(int socketDescriptor)
+bool QSocks5BindStore::contains(qintptr socketDescriptor)
{
QMutexLocker lock(&mutex);
return store.contains(socketDescriptor);
}
-QSocks5BindData *QSocks5BindStore::retrieve(int socketDescriptor)
+QSocks5BindData *QSocks5BindStore::retrieve(qintptr socketDescriptor)
{
QMutexLocker lock(&mutex);
if (!store.contains(socketDescriptor))
@@ -1018,7 +1018,7 @@ bool QSocks5SocketEngine::initialize(QAbstractSocket::SocketType type, QAbstract
return true;
}
-bool QSocks5SocketEngine::initialize(int socketDescriptor, QAbstractSocket::SocketState socketState)
+bool QSocks5SocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState)
{
Q_D(QSocks5SocketEngine);
@@ -1080,7 +1080,7 @@ void QSocks5SocketEngine::setProxy(const QNetworkProxy &networkProxy)
d->proxyInfo = networkProxy;
}
-int QSocks5SocketEngine::socketDescriptor() const
+qintptr QSocks5SocketEngine::socketDescriptor() const
{
Q_D(const QSocks5SocketEngine);
return d->socketDescriptor;
@@ -1448,7 +1448,7 @@ int QSocks5SocketEngine::accept()
d->data->controlSocket->setParent(0);
d->bindData->localAddress = d->localAddress;
d->bindData->localPort = d->localPort;
- int sd = d->socketDescriptor;
+ qintptr sd = d->socketDescriptor;
socks5BindStore()->add(sd, d->bindData);
d->data = 0;
d->bindData = 0;
@@ -1917,7 +1917,7 @@ QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socke
return engine.take();
}
-QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(int socketDescriptor, QObject *parent)
+QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(qintptr socketDescriptor, QObject *parent)
{
QSOCKS5_DEBUG << "createSocketEngine" << socketDescriptor;
if (socks5BindStore()->contains(socketDescriptor)) {
diff --git a/src/network/socket/qsocks5socketengine_p.h b/src/network/socket/qsocks5socketengine_p.h
index 9b2f6e3ade..386e4856a1 100644
--- a/src/network/socket/qsocks5socketengine_p.h
+++ b/src/network/socket/qsocks5socketengine_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -70,11 +70,11 @@ public:
~QSocks5SocketEngine();
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol);
- bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
+ bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
void setProxy(const QNetworkProxy &networkProxy);
- int socketDescriptor() const;
+ qintptr socketDescriptor() const;
bool isValid() const;
@@ -261,7 +261,7 @@ public:
bool readNotificationEnabled, writeNotificationEnabled, exceptNotificationEnabled;
- int socketDescriptor;
+ qintptr socketDescriptor;
QSocks5Data *data;
QSocks5ConnectData *connectData;
@@ -290,7 +290,7 @@ class Q_AUTOTEST_EXPORT QSocks5SocketEngineHandler : public QSocketEngineHandler
public:
virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
const QNetworkProxy &, QObject *parent);
- virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
+ virtual QAbstractSocketEngine *createSocketEngine(qintptr socketDescriptor, QObject *parent);
};
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 500d383e0f..857827facc 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -378,7 +378,7 @@ void QTcpServer::close()
\sa setSocketDescriptor(), isListening()
*/
-int QTcpServer::socketDescriptor() const
+qintptr QTcpServer::socketDescriptor() const
{
Q_D(const QTcpServer);
Q_CHECK_SOCKETENGINE(-1);
@@ -394,7 +394,7 @@ int QTcpServer::socketDescriptor() const
\sa socketDescriptor(), isListening()
*/
-bool QTcpServer::setSocketDescriptor(int socketDescriptor)
+bool QTcpServer::setSocketDescriptor(qintptr socketDescriptor)
{
Q_D(QTcpServer);
if (isListening()) {
@@ -566,7 +566,7 @@ QTcpSocket *QTcpServer::nextPendingConnection()
\sa newConnection(), nextPendingConnection(), addPendingConnection()
*/
-void QTcpServer::incomingConnection(int socketDescriptor)
+void QTcpServer::incomingConnection(qintptr socketDescriptor)
{
#if defined (QTCPSERVER_DEBUG)
qDebug("QTcpServer::incomingConnection(%i)", socketDescriptor);
diff --git a/src/network/socket/qtcpserver.h b/src/network/socket/qtcpserver.h
index 2fe090af32..a322294f58 100644
--- a/src/network/socket/qtcpserver.h
+++ b/src/network/socket/qtcpserver.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -76,8 +76,8 @@ public:
quint16 serverPort() const;
QHostAddress serverAddress() const;
- int socketDescriptor() const;
- bool setSocketDescriptor(int socketDescriptor);
+ qintptr socketDescriptor() const;
+ bool setSocketDescriptor(qintptr socketDescriptor);
bool waitForNewConnection(int msec = 0, bool *timedOut = 0);
virtual bool hasPendingConnections() const;
@@ -92,7 +92,7 @@ public:
#endif
protected:
- virtual void incomingConnection(int handle);
+ virtual void incomingConnection(qintptr handle);
void addPendingConnection(QTcpSocket* socket);
Q_SIGNALS:
diff --git a/src/network/socket/qtcpsocket.cpp b/src/network/socket/qtcpsocket.cpp
index 78fb4cd050..f900ca752c 100644
--- a/src/network/socket/qtcpsocket.cpp
+++ b/src/network/socket/qtcpsocket.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -60,7 +60,7 @@
\bold{Note:} TCP sockets cannot be opened in QIODevice::Unbuffered mode.
- \sa QTcpServer, QUdpSocket, QFtp, QNetworkAccessManager,
+ \sa QTcpServer, QUdpSocket, QNetworkAccessManager,
{Fortune Server Example}, {Fortune Client Example},
{Threaded Fortune Server Example}, {Blocking Fortune Client Example},
{Loopback Example}, {Torrent Example}
diff --git a/src/network/socket/qtcpsocket.h b/src/network/socket/qtcpsocket.h
index 8323836a54..aa2e89d840 100644
--- a/src/network/socket/qtcpsocket.h
+++ b/src/network/socket/qtcpsocket.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qtcpsocket_p.h b/src/network/socket/qtcpsocket_p.h
index 1ecc274fcd..33672539cc 100644
--- a/src/network/socket/qtcpsocket_p.h
+++ b/src/network/socket/qtcpsocket_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp
index e12034d86b..f378fea7b9 100644
--- a/src/network/socket/qudpsocket.cpp
+++ b/src/network/socket/qudpsocket.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/socket/qudpsocket.h b/src/network/socket/qudpsocket.h
index 068c20b9c4..ed5f539732 100644
--- a/src/network/socket/qudpsocket.h
+++ b/src/network/socket/qudpsocket.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qssl.cpp b/src/network/ssl/qssl.cpp
index d0d7584ff1..7bb68956ee 100644
--- a/src/network/ssl/qssl.cpp
+++ b/src/network/ssl/qssl.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qssl.h b/src/network/ssl/qssl.h
index 0793a84671..7da5a78c56 100644
--- a/src/network/ssl/qssl.h
+++ b/src/network/ssl/qssl.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
index d1624faaea..5a4702d992 100644
--- a/src/network/ssl/qsslcertificate.cpp
+++ b/src/network/ssl/qsslcertificate.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -1177,7 +1177,7 @@ QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
<< ',' << certificate.issuerInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectAlternativeNames()
-#ifndef QT_NO_TEXTSTREAM
+#ifndef QT_NO_DATESTRING
<< ',' << certificate.effectiveDate()
<< ',' << certificate.expiryDate()
#endif
diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h
index dcc7f64aa4..3aa7075eb3 100644
--- a/src/network/ssl/qsslcertificate.h
+++ b/src/network/ssl/qsslcertificate.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
class QDateTime;
class QIODevice;
@@ -152,7 +152,7 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslCertificate &certific
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo info);
#endif
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslcertificate_p.h b/src/network/ssl/qsslcertificate_p.h
index c4a833460a..031165b267 100644
--- a/src/network/ssl/qsslcertificate_p.h
+++ b/src/network/ssl/qsslcertificate_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslcertificateextension.h b/src/network/ssl/qsslcertificateextension.h
index 200ae3e091..6c1d219a3b 100644
--- a/src/network/ssl/qsslcertificateextension.h
+++ b/src/network/ssl/qsslcertificateextension.h
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
class QSslCertificateExtensionPrivate;
@@ -78,7 +78,7 @@ private:
QSharedDataPointer<QSslCertificateExtensionPrivate> d;
};
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslcipher.cpp b/src/network/ssl/qsslcipher.cpp
index a583257a88..3c59a8ebf9 100644
--- a/src/network/ssl/qsslcipher.cpp
+++ b/src/network/ssl/qsslcipher.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslcipher.h b/src/network/ssl/qsslcipher.h
index d9d3b9b31e..8d58fa50ba 100644
--- a/src/network/ssl/qsslcipher.h
+++ b/src/network/ssl/qsslcipher.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
class QSslCipherPrivate;
class Q_NETWORK_EXPORT QSslCipher
@@ -88,7 +88,7 @@ class QDebug;
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslCipher &cipher);
#endif
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslcipher_p.h b/src/network/ssl/qsslcipher_p.h
index a47c159ade..d4117abe3a 100644
--- a/src/network/ssl/qsslcipher_p.h
+++ b/src/network/ssl/qsslcipher_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslconfiguration.cpp b/src/network/ssl/qsslconfiguration.cpp
index 0e9eb5db62..f29bb02813 100644
--- a/src/network/ssl/qsslconfiguration.cpp
+++ b/src/network/ssl/qsslconfiguration.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslconfiguration.h b/src/network/ssl/qsslconfiguration.h
index ff8c8fc4b4..37df073ae9 100644
--- a/src/network/ssl/qsslconfiguration.h
+++ b/src/network/ssl/qsslconfiguration.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -67,7 +67,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
template<typename T> class QList;
class QSslCertificate;
@@ -132,7 +132,7 @@ private:
QSharedDataPointer<QSslConfigurationPrivate> d;
};
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslconfiguration_p.h b/src/network/ssl/qsslconfiguration_p.h
index 59078ae7cc..d9f41d6351 100644
--- a/src/network/ssl/qsslconfiguration_p.h
+++ b/src/network/ssl/qsslconfiguration_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp
index 5091ed27a4..39e6d6114e 100644
--- a/src/network/ssl/qsslerror.cpp
+++ b/src/network/ssl/qsslerror.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslerror.h b/src/network/ssl/qsslerror.h
index 451c95f180..0bdc230b2e 100644
--- a/src/network/ssl/qsslerror.h
+++ b/src/network/ssl/qsslerror.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
class QSslErrorPrivate;
class Q_NETWORK_EXPORT QSslError
@@ -115,7 +115,7 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError &error);
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError::SslError &error);
#endif
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslkey.cpp b/src/network/ssl/qsslkey.cpp
index 580b71bca9..cb038d726f 100644
--- a/src/network/ssl/qsslkey.cpp
+++ b/src/network/ssl/qsslkey.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslkey.h b/src/network/ssl/qsslkey.h
index 7064d22eb4..d7d52fa992 100644
--- a/src/network/ssl/qsslkey.h
+++ b/src/network/ssl/qsslkey.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
template <typename A, typename B> struct QPair;
@@ -103,7 +103,7 @@ class QDebug;
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslKey &key);
#endif
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslkey_p.h b/src/network/ssl/qsslkey_p.h
index 14075ecad0..1beb2a608a 100644
--- a/src/network/ssl/qsslkey_p.h
+++ b/src/network/ssl/qsslkey_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index e3dd6ae0c5..b428316a77 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -455,7 +455,7 @@ void QSslSocket::connectToHostEncrypted(const QString &hostName, quint16 port,
\sa socketDescriptor()
*/
-bool QSslSocket::setSocketDescriptor(int socketDescriptor, SocketState state, OpenMode openMode)
+bool QSslSocket::setSocketDescriptor(qintptr socketDescriptor, SocketState state, OpenMode openMode)
{
Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG
@@ -1733,16 +1733,16 @@ void QSslSocket::ignoreSslErrors(const QList<QSslError> &errors)
/*!
\internal
*/
-void QSslSocket::connectToHostImplementation(const QString &hostName, quint16 port,
- OpenMode openMode)
+void QSslSocket::connectToHost(const QString &hostName, quint16 port, OpenMode openMode, NetworkLayerProtocol protocol)
{
Q_D(QSslSocket);
+ d->preferredNetworkLayerProtocol = protocol;
if (!d->initialized)
d->init();
d->initialized = false;
#ifdef QSSLSOCKET_DEBUG
- qDebug() << "QSslSocket::connectToHostImplementation("
+ qDebug() << "QSslSocket::connectToHost("
<< hostName << ',' << port << ',' << openMode << ')';
#endif
if (!d->plainSocket) {
@@ -1762,11 +1762,11 @@ void QSslSocket::connectToHostImplementation(const QString &hostName, quint16 po
/*!
\internal
*/
-void QSslSocket::disconnectFromHostImplementation()
+void QSslSocket::disconnectFromHost()
{
Q_D(QSslSocket);
#ifdef QSSLSOCKET_DEBUG
- qDebug() << "QSslSocket::disconnectFromHostImplementation()";
+ qDebug() << "QSslSocket::disconnectFromHost()";
#endif
if (!d->plainSocket)
return;
diff --git a/src/network/ssl/qsslsocket.h b/src/network/ssl/qsslsocket.h
index 803e79e0c4..936f27905a 100644
--- a/src/network/ssl/qsslsocket.h
+++ b/src/network/ssl/qsslsocket.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -45,7 +45,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qregexp.h>
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
# include <QtNetwork/qtcpsocket.h>
# include <QtNetwork/qsslerror.h>
#endif
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Network)
-#ifndef QT_NO_OPENSSL
+#ifndef QT_NO_SSL
class QDir;
class QSslCipher;
@@ -87,9 +87,12 @@ public:
// Autostarting the SSL client handshake.
void connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
void connectToHostEncrypted(const QString &hostName, quint16 port, const QString &sslPeerName, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
- bool setSocketDescriptor(int socketDescriptor, SocketState state = ConnectedState,
+ bool setSocketDescriptor(qintptr socketDescriptor, SocketState state = ConnectedState,
OpenMode openMode = ReadWrite);
+ void connectToHost(const QString &hostName, quint16 port, OpenMode openMode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol);
+ void disconnectFromHost();
+
// ### Qt 5: Make virtual
void setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value);
QVariant socketOption(QAbstractSocket::SocketOption option);
@@ -193,11 +196,6 @@ Q_SIGNALS:
void modeChanged(QSslSocket::SslMode newMode);
void encryptedBytesWritten(qint64 totalBytes);
-protected Q_SLOTS:
- void connectToHostImplementation(const QString &hostName, quint16 port,
- OpenMode openMode);
- void disconnectFromHostImplementation();
-
protected:
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
@@ -217,7 +215,7 @@ private:
friend class QSslSocketBackendPrivate;
};
-#endif // QT_NO_OPENSSL
+#endif // QT_NO_SSL
QT_END_NAMESPACE
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp
index f70b4217bd..96b2c8170b 100644
--- a/src/network/ssl/qsslsocket_openssl.cpp
+++ b/src/network/ssl/qsslsocket_openssl.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -225,6 +225,27 @@ static int q_X509Callback(int ok, X509_STORE_CTX *ctx)
if (!ok) {
// Store the error and at which depth the error was detected.
_q_sslErrorList()->errors << qMakePair<int, int>(ctx->error, ctx->error_depth);
+#ifdef QSSLSOCKET_DEBUG
+ qDebug() << "verification error: dumping bad certificate";
+ qDebug() << QSslCertificatePrivate::QSslCertificate_from_X509(ctx->current_cert).toPem();
+ qDebug() << "dumping chain";
+ foreach (QSslCertificate cert, QSslSocketBackendPrivate::STACKOFX509_to_QSslCertificates(ctx->chain)) {
+ QString certFormat(QStringLiteral("O=%1 CN=%2 L=%3 OU=%4 C=%5 ST=%6"));
+ qDebug() << "Issuer:" << "O=" << cert.issuerInfo(QSslCertificate::Organization)
+ << "CN=" << cert.issuerInfo(QSslCertificate::CommonName)
+ << "L=" << cert.issuerInfo(QSslCertificate::LocalityName)
+ << "OU=" << cert.issuerInfo(QSslCertificate::OrganizationalUnitName)
+ << "C=" << cert.issuerInfo(QSslCertificate::CountryName)
+ << "ST=" << cert.issuerInfo(QSslCertificate::StateOrProvinceName);
+ qDebug() << "Subject:" << "O=" << cert.subjectInfo(QSslCertificate::Organization)
+ << "CN=" << cert.subjectInfo(QSslCertificate::CommonName)
+ << "L=" << cert.subjectInfo(QSslCertificate::LocalityName)
+ << "OU=" << cert.subjectInfo(QSslCertificate::OrganizationalUnitName)
+ << "C=" << cert.subjectInfo(QSslCertificate::CountryName)
+ << "ST=" << cert.subjectInfo(QSslCertificate::StateOrProvinceName);
+ qDebug() << "Valid:" << cert.effectiveDate() << "-" << cert.expiryDate();
+ }
+#endif
}
// Always return OK to allow verification to continue. We're handle the
// errors gracefully after collecting all errors, after verification has
@@ -343,7 +364,7 @@ init_context:
foreach (const QSslCertificate &caCertificate, q->caCertificates()) {
// add expired certs later, so that the
// valid ones are used before the expired ones
- if (caCertificate.expiryDate() > QDateTime::currentDateTime()) {
+ if (caCertificate.expiryDate() < QDateTime::currentDateTime()) {
expiredCerts.append(caCertificate);
} else {
q_X509_STORE_add_cert(ctx->cert_store, reinterpret_cast<X509 *>(caCertificate.handle()));
@@ -453,11 +474,7 @@ init_context:
if (!ace.isEmpty()
&& !QHostAddress().setAddress(tlsHostName)
&& !(configuration.sslOptions & QSsl::SslOptionDisableServerNameIndication)) {
-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.data()))
-#else
- if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.constData()))
-#endif
qWarning("could not set SSL_CTRL_SET_TLSEXT_HOSTNAME, Server Name Indication disabled");
}
}
@@ -874,10 +891,17 @@ void QSslSocketBackendPrivate::transmit()
int encryptedBytesRead = q_BIO_read(writeBio, data.data(), pendingBytes);
// Write encrypted data from the buffer to the socket.
- plainSocket->write(data.constData(), encryptedBytesRead);
+ qint64 actualWritten = plainSocket->write(data.constData(), encryptedBytesRead);
#ifdef QSSLSOCKET_DEBUG
- qDebug() << "QSslSocketBackendPrivate::transmit: wrote" << encryptedBytesRead << "encrypted bytes to the socket";
+ qDebug() << "QSslSocketBackendPrivate::transmit: wrote" << encryptedBytesRead << "encrypted bytes to the socket" << actualWritten << "actual.";
#endif
+ if (actualWritten < 0) {
+ //plain socket write fails if it was in the pending close state.
+ q->setErrorString(plainSocket->errorString());
+ q->setSocketError(plainSocket->error());
+ emit q->error(plainSocket->error());
+ return;
+ }
transmitting = true;
}
@@ -1351,7 +1375,7 @@ QList<QSslError> QSslSocketBackendPrivate::verify(QList<QSslCertificate> certifi
foreach (const QSslCertificate &caCertificate, QSslSocket::defaultCaCertificates()) {
// add expired certs later, so that the
// valid ones are used before the expired ones
- if (caCertificate.expiryDate() > QDateTime::currentDateTime()) {
+ if (caCertificate.expiryDate() < QDateTime::currentDateTime()) {
expiredCerts.append(caCertificate);
} else {
q_X509_STORE_add_cert(certStore, reinterpret_cast<X509 *>(caCertificate.handle()));
diff --git a/src/network/ssl/qsslsocket_openssl_p.h b/src/network/ssl/qsslsocket_openssl_p.h
index ef00b0998d..4d1ed9e681 100644
--- a/src/network/ssl/qsslsocket_openssl_p.h
+++ b/src/network/ssl/qsslsocket_openssl_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -105,8 +105,6 @@ public:
BIO *readBio;
BIO *writeBio;
SSL_SESSION *session;
- X509_STORE *certificateStore;
- X509_STORE_CTX *certificateStoreCtx;
QList<QPair<int, int> > errorList;
// Platform specific functions
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp
index cd27c31456..c3bee3edd2 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols.cpp
+++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -218,11 +218,7 @@ DEFINEFUNC(int, SSL_library_init, void, DUMMYARG, return -1, return)
DEFINEFUNC(void, SSL_load_error_strings, void, DUMMYARG, return, DUMMYARG)
DEFINEFUNC(SSL *, SSL_new, SSL_CTX *a, a, return 0, return)
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
DEFINEFUNC4(long, SSL_ctrl, SSL *a, a, int cmd, cmd, long larg, larg, void *parg, parg, return -1, return)
-#else
-DEFINEFUNC4(long, SSL_ctrl, SSL *a, a, int cmd, cmd, long larg, larg, const void *parg, parg, return -1, return)
-#endif
#endif
DEFINEFUNC3(int, SSL_read, SSL *a, a, void *b, b, int c, c, return -1, return)
DEFINEFUNC3(void, SSL_set_bio, SSL *a, a, BIO *b, b, BIO *c, c, return, DUMMYARG)
diff --git a/src/network/ssl/qsslsocket_openssl_symbols_p.h b/src/network/ssl/qsslsocket_openssl_symbols_p.h
index ad7a0a7557..1f1e842c13 100644
--- a/src/network/ssl/qsslsocket_openssl_symbols_p.h
+++ b/src/network/ssl/qsslsocket_openssl_symbols_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -325,11 +325,7 @@ int q_SSL_library_init();
void q_SSL_load_error_strings();
SSL *q_SSL_new(SSL_CTX *a);
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
long q_SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg);
-#else
-long q_SSL_ctrl(SSL *ssl,int cmd, long larg, const void *parg);
-#endif
#endif
int q_SSL_read(SSL *a, void *b, int c);
void q_SSL_set_bio(SSL *a, BIO *b, BIO *c);
@@ -431,11 +427,7 @@ DSA *q_d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length);
(char *)(rsa))
#define q_EVP_PKEY_assign_DSA(pkey,dsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
(char *)(dsa))
-#ifdef OPENSSL_LOAD_CONF
#define q_OpenSSL_add_all_algorithms() q_OPENSSL_add_all_algorithms_conf()
-#else
-#define q_OpenSSL_add_all_algorithms() q_OPENSSL_add_all_algorithms_noconf()
-#endif
void q_OPENSSL_add_all_algorithms_noconf();
void q_OPENSSL_add_all_algorithms_conf();
int q_SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, const char *CApath);
diff --git a/src/network/ssl/qsslsocket_p.h b/src/network/ssl/qsslsocket_p.h
index b1dc656e88..6fa443d0c7 100644
--- a/src/network/ssl/qsslsocket_p.h
+++ b/src/network/ssl/qsslsocket_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**