summaryrefslogtreecommitdiff
path: root/src/websockets/qwebsocket_p.cpp
diff options
context:
space:
mode:
authorKurt Pattyn <pattyn.kurt@gmail.com>2013-11-01 13:12:28 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-01 13:13:35 +0100
commitd26e2ce1594af6e9088b176ccb31c4033e367839 (patch)
treea083044aa5ef67fddf3a57f67f4f1b5630468909 /src/websockets/qwebsocket_p.cpp
parent3501d4e9c315af97f0d7878d1af7f4300a815ea3 (diff)
downloadqtwebsockets-d26e2ce1594af6e9088b176ccb31c4033e367839.tar.gz
Add functionality to ignore ssl errors
Change-Id: I81248b9af104c0b3d37c9cfcef250a102f4b1d32 Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'src/websockets/qwebsocket_p.cpp')
-rw-r--r--src/websockets/qwebsocket_p.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index e47f4e6..f8e407a 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -48,6 +48,11 @@ const quint64 FRAME_SIZE_IN_BYTES = 512 * 512 * 2; //maximum size of a frame whe
QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::Version version, QWebSocket *pWebSocket, QObject *parent) :
QObject(parent),
q_ptr(pWebSocket),
+#ifndef QT_NO_SSL
+ m_sslConfiguration(),
+ m_ignoredSslErrors(),
+ m_ignoreSslErrors(false),
+#endif
m_pSocket(Q_NULLPTR),
m_errorString(),
m_version(version),
@@ -75,6 +80,11 @@ QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::
QWebSocketPrivate::QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QWebSocket *pWebSocket, QObject *parent) :
QObject(parent),
q_ptr(pWebSocket),
+#ifndef QT_NO_SSL
+ m_sslConfiguration(), //socket is already open, so we don't need to set the ssl configuration anymore
+ m_ignoredSslErrors(), //socket is already open, so we don't need to set the ignored errors anymore
+ m_ignoreSslErrors(false),
+#endif
m_pSocket(pTcpSocket),
m_errorString(pTcpSocket->errorString()),
m_version(version),
@@ -209,6 +219,14 @@ void QWebSocketPrivate::ignoreSslErrors(const QList<QSslError> &errors)
m_ignoredSslErrors = errors;
}
+/*!
+ * \internal
+ */
+void QWebSocketPrivate::ignoreSslErrors()
+{
+ m_ignoreSslErrors = true;
+}
+
#endif
/*!
@@ -301,10 +319,10 @@ void QWebSocketPrivate::open(const QUrl &url, bool mask)
{
if (!QSslSocket::supportsSsl())
{
- qWarning() << tr("SSL Sockets are not supported on this platform.");
- setErrorString(tr("SSL Sockets are not supported on this platform."));
+ const QString message = tr("SSL Sockets are not supported on this platform.");
+ qWarning() << message;
+ setErrorString(message);
emit q->error(QAbstractSocket::UnsupportedSocketOperationError);
- return;
}
else
{
@@ -316,12 +334,20 @@ void QWebSocketPrivate::open(const QUrl &url, bool mask)
setSocketState(QAbstractSocket::ConnectingState);
sslSocket->setSslConfiguration(m_sslConfiguration);
- sslSocket->ignoreSslErrors(m_ignoredSslErrors);
+ if (m_ignoreSslErrors)
+ {
+ sslSocket->ignoreSslErrors();
+ }
+ else
+ {
+ sslSocket->ignoreSslErrors(m_ignoredSslErrors);
+ }
sslSocket->connectToHostEncrypted(url.host(), url.port(443));
}
}
else
#endif
+ if (url.scheme() == QStringLiteral("ws"))
{
m_pSocket = new QTcpSocket(this);
@@ -330,6 +356,13 @@ void QWebSocketPrivate::open(const QUrl &url, bool mask)
setSocketState(QAbstractSocket::ConnectingState);
m_pSocket->connectToHost(url.host(), url.port(80));
}
+ else
+ {
+ const QString message = tr("Unsupported websockets scheme: %1").arg(url.scheme());
+ qWarning() << message;
+ setErrorString(message);
+ emit q->error(QAbstractSocket::UnsupportedSocketOperationError);
+ }
}
/*!