From df6550dd264c1dbe186bd106d7239bb359e6491c Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Mon, 5 May 2014 10:59:04 +0200 Subject: [PATCH 1/2] Fixed bug in sending unencrypted messages. Sending unencrypted messages now adds the proper amount of quotes around the message. --- QPubNub.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/QPubNub.cpp b/QPubNub.cpp index 7378328..e6d5fca 100644 --- a/QPubNub.cpp +++ b/QPubNub.cpp @@ -132,6 +132,7 @@ void QPubNub::publish(const QString& channel, const QJsonValue& value) { } QByteArray message; + QString publishURL; #ifdef Q_PUBNUB_CRYPT if (!m_cipherKey.isEmpty()) { QPubNubCrypt crypt(m_cipherKey); @@ -143,14 +144,16 @@ void QPubNub::publish(const QString& channel, const QJsonValue& value) { emit error(errorString, errorCode); return; } + publishURL = publishUrl("\""+message+"\"", channel); } else { #endif // Q_PUBNUB_CRYPT message = toByteArray(value); + publishURL = publishUrl(message, channel); #ifdef Q_PUBNUB_CRYPT } #endif - QNetworkReply * reply = sendRequest(publishUrl("\""+message+"\"", channel)); + QNetworkReply * reply = sendRequest(publishURL); // This can't be connected using the new syntax, cause the signal and error property have the same name "error" connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError))); connect(reply, &QNetworkReply::finished, this, &QPubNub::publishFinished); From 36ba8efe22cd921bd372be216b831c41e34b50ba Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Wed, 7 May 2014 14:48:10 +0200 Subject: [PATCH 2/2] Fixed crash when only subsribed to one channel. Pubnub doesn't give you the channel list when subscribed to only one channel, so we're creating the list ourselves. Otherwise, when you receive more than 1 message per reply, it would crash. --- QPubNub.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/QPubNub.cpp b/QPubNub.cpp index e6d5fca..07436f9 100644 --- a/QPubNub.cpp +++ b/QPubNub.cpp @@ -228,12 +228,16 @@ void QPubNub::onSubscribeReadyRead() { m_timeToken = timeTokenElement.toString(); QJsonValue channelListString = response.at(2); QStringList channels; + QJsonArray messages = firstElement.toArray(); if (channelListString.isString()) { channels = channelListString.toString().split(','); } else { - channels << m_channelUrlPart; + int len = messages.isEmpty() ? 0 : messages.size(); + for (int i = 0; i < len; i++) + { + channels << m_channelUrlPart; + } } - QJsonArray messages = firstElement.toArray(); if (messages.isEmpty()) { emit connected(); } else {