forked from emqx/qmqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request emqx#119 from ejvr/emqtt
Support for websockets & minor changes
- Loading branch information
Showing
16 changed files
with
414 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#ifdef QT_WEBSOCKETS_LIB | ||
|
||
#include <QNetworkRequest> | ||
#include <QUrl> | ||
#include "qmqtt_websocket_p.h" | ||
|
||
QMQTT::WebSocket::WebSocket(const QString& origin, QWebSocketProtocol::Version version, | ||
bool ignoreSelfSigned, QObject* parent) | ||
: SocketInterface(parent) | ||
, _socket(new QWebSocket(origin, version, this)) | ||
, _ioDevice(new WebSocketIODevice(_socket, this)) | ||
, _ignoreSelfSigned(ignoreSelfSigned) | ||
{ | ||
connect(_socket, &QWebSocket::connected, this, &WebSocket::connected); | ||
connect(_socket, &QWebSocket::disconnected, this, &WebSocket::disconnected); | ||
connect(_socket, | ||
static_cast<void (QWebSocket::*)(QAbstractSocket::SocketError)>(&QWebSocket::error), | ||
this, | ||
static_cast<void (SocketInterface::*)(QAbstractSocket::SocketError)>(&SocketInterface::error)); | ||
connect(_socket, &QWebSocket::sslErrors, this, &WebSocket::sslErrors); | ||
} | ||
|
||
QMQTT::WebSocket::~WebSocket() | ||
{ | ||
} | ||
|
||
void QMQTT::WebSocket::connectToHost(const QHostAddress& address, quint16 port) | ||
{ | ||
Q_UNUSED(address) | ||
Q_UNUSED(port) | ||
qFatal("No supported"); | ||
} | ||
|
||
void QMQTT::WebSocket::connectToHost(const QString& hostName, quint16 port) | ||
{ | ||
Q_UNUSED(port) | ||
QUrl url(hostName); | ||
QNetworkRequest request(url); | ||
request.setRawHeader("Sec-WebSocket-Protocol", "mqtt"); | ||
_ioDevice->connectToHost(request); | ||
} | ||
|
||
void QMQTT::WebSocket::disconnectFromHost() | ||
{ | ||
_socket->disconnect(); | ||
} | ||
|
||
QAbstractSocket::SocketState QMQTT::WebSocket::state() const | ||
{ | ||
return _socket->state(); | ||
} | ||
|
||
QAbstractSocket::SocketError QMQTT::WebSocket::error() const | ||
{ | ||
return _socket->error(); | ||
} | ||
|
||
void QMQTT::WebSocket::sslErrors(const QList<QSslError> &errors) | ||
{ | ||
if (!_ignoreSelfSigned) | ||
return; | ||
foreach (QSslError error, errors) | ||
{ | ||
if (error.error() != QSslError::SelfSignedCertificate && | ||
error.error() != QSslError::SelfSignedCertificateInChain) | ||
{ | ||
return; | ||
} | ||
} | ||
_socket->ignoreSslErrors(); | ||
} | ||
|
||
#endif // QT_WEBSOCKETS_LIB |
Oops, something went wrong.