Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/core/cowbytearray.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ class CowByteArray {
friend CowByteArray operator+(const CowByteArray &lhs, const CowByteArray &rhs);
friend CowByteArray operator+(const CowByteArray &lhs, const char *rhs);
friend CowByteArray operator+(const char *lhs, const CowByteArray &rhs);
friend CowByteArray operator+(const CowByteArray &lhs, char rhs);
friend CowByteArray operator+(char lhs, const CowByteArray &rhs);
friend CowByteArray operator+(const CowByteArray &lhs, const QByteArray &rhs);
friend CowByteArray operator+(const QByteArray &lhs, const CowByteArray &rhs);

friend bool operator==(const CowByteArray &lhs, const CowByteArray &rhs);
friend bool operator==(const CowByteArray &lhs, const char *const &rhs);
friend bool operator==(const char *const &lhs, const CowByteArray &rhs);
friend bool operator==(const CowByteArray &lhs, const QByteArray &rhs);
friend bool operator==(const QByteArray &lhs, const CowByteArray &rhs);

private:
friend class CowByteArrayRef;
Expand All @@ -137,6 +143,14 @@ inline CowByteArray operator+(const CowByteArray &lhs, const CowByteArray &rhs)
}
inline CowByteArray operator+(const CowByteArray &lhs, const char *rhs) { return lhs.inner_ + rhs; }
inline CowByteArray operator+(const char *lhs, const CowByteArray &rhs) { return lhs + rhs.inner_; }
inline CowByteArray operator+(const CowByteArray &lhs, char rhs) { return lhs.inner_ + rhs; }
inline CowByteArray operator+(char lhs, const CowByteArray &rhs) { return lhs + rhs.inner_; }
inline CowByteArray operator+(const CowByteArray &lhs, const QByteArray &rhs) {
return lhs.inner_ + rhs;
}
inline CowByteArray operator+(const QByteArray &lhs, const CowByteArray &rhs) {
return lhs + rhs.inner_;
}

inline bool operator==(const CowByteArray &lhs, const CowByteArray &rhs) {
return lhs.inner_ == rhs.inner_;
Expand All @@ -147,9 +161,17 @@ inline bool operator==(const CowByteArray &lhs, const char *const &rhs) {
inline bool operator==(const char *const &lhs, const CowByteArray &rhs) {
return lhs == rhs.inner_;
}
inline bool operator==(const CowByteArray &lhs, const QByteArray &rhs) { return lhs.inner_ == rhs; }
inline bool operator==(const QByteArray &lhs, const CowByteArray &rhs) { return lhs == rhs.inner_; }
inline bool operator!=(const CowByteArray &lhs, const CowByteArray &rhs) { return !(lhs == rhs); }
inline bool operator!=(const CowByteArray &lhs, const char *const &rhs) { return !(lhs == rhs); }
inline bool operator!=(const char *const &lhs, const CowByteArray &rhs) { return !(lhs == rhs); }
inline bool operator!=(const CowByteArray &lhs, const QByteArray &rhs) { return !(lhs == rhs); }
inline bool operator!=(const QByteArray &lhs, const CowByteArray &rhs) { return !(lhs == rhs); }

inline size_t qHash(const CowByteArray &key, size_t seed = 0) noexcept {
return qHash(key.asQByteArray(), seed);
}

inline CowByteArray CowByteArrayConstRef::mid(ssize_t pos, ssize_t len) const {
return inner_.mid(pos, len);
Expand Down
8 changes: 4 additions & 4 deletions src/core/inspectdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#ifndef INSPECTDATA_H
#define INSPECTDATA_H

#include "cowbytearray.h"
#include "variant.h"
#include <QByteArray>

class InspectData {
public:
bool doProxy;
QByteArray sharingKey;
QByteArray sid;
QHash<QByteArray, QByteArray> lastIds;
CowByteArray sharingKey;
CowByteArray sid;
QHash<CowByteArray, CowByteArray> lastIds;
Variant userData;

InspectData() : doProxy(false) {}
Expand Down
2 changes: 1 addition & 1 deletion src/core/logutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void logVariantWithContent(int level, const Variant &data, const QString &conten
}

void logRequest(int level, const RequestData &data, const Config &config) {
QString msg = QString("%1 %2").arg(data.requestData.method,
QString msg = QString("%1 %2").arg(data.requestData.method.asQString(),
data.requestData.uri.toString(CowUrl::FullyEncoded));

if (!data.targetStr.isEmpty())
Expand Down
5 changes: 3 additions & 2 deletions src/core/packet/httprequestdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
#define HTTPREQUESTDATA_H

#include "../httpheaders.h"
#include "cowstring.h"
#include "cowurl.h"

class HttpRequestData {
public:
QString method;
CowString method;
CowUrl uri;
HttpHeaders headers;
QByteArray body;
CowByteArray body;
};

#endif
4 changes: 2 additions & 2 deletions src/core/packet/httpresponsedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
class HttpResponseData {
public:
int code;
QByteArray reason;
CowByteArray reason;
HttpHeaders headers;
QByteArray body;
CowByteArray body;

HttpResponseData() : code(-1) {}
};
Expand Down
20 changes: 10 additions & 10 deletions src/core/packet/retryrequestpacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Variant RetryRequestPacket::toVariant() const {
VariantHash vrequest;

VariantHash vrid;
vrid["sender"] = r.rid.first;
vrid["id"] = r.rid.second;
vrid["sender"] = r.rid.first.asQByteArray();
vrid["id"] = r.rid.second.asQByteArray();

vrequest["rid"] = vrid;

Expand All @@ -54,7 +54,7 @@ Variant RetryRequestPacket::toVariant() const {
vrequest["auto-cross-origin"] = true;

if (!r.jsonpCallback.isEmpty())
vrequest["jsonp-callback"] = r.jsonpCallback;
vrequest["jsonp-callback"] = r.jsonpCallback.asQByteArray();

if (r.jsonpExtendedResponse)
vrequest["jsonp-extended-response"] = true;
Expand All @@ -79,7 +79,7 @@ Variant RetryRequestPacket::toVariant() const {

VariantHash vrequestData;

vrequestData["method"] = requestData.method.toLatin1();
vrequestData["method"] = requestData.method.toUtf8().asQByteArray();
vrequestData["uri"] = requestData.uri.toEncoded();

VariantList vheaders;
Expand All @@ -91,7 +91,7 @@ Variant RetryRequestPacket::toVariant() const {
}
vrequestData["headers"] = vheaders;

vrequestData["body"] = requestData.body;
vrequestData["body"] = requestData.body.asQByteArray();

obj["request-data"] = vrequestData;

Expand All @@ -101,19 +101,19 @@ Variant RetryRequestPacket::toVariant() const {
vinspect["no-proxy"] = !inspectInfo.doProxy;

if (!inspectInfo.sharingKey.isEmpty())
vinspect["sharing-key"] = inspectInfo.sharingKey;
vinspect["sharing-key"] = inspectInfo.sharingKey.asQByteArray();

if (!inspectInfo.sid.isEmpty())
vinspect["sid"] = inspectInfo.sid;
vinspect["sid"] = inspectInfo.sid.asQByteArray();

if (!inspectInfo.lastIds.isEmpty()) {
VariantHash vlastIds;

QHashIterator<QByteArray, QByteArray> it(inspectInfo.lastIds);
QHashIterator<CowByteArray, CowByteArray> it(inspectInfo.lastIds);
while (it.hasNext()) {
it.next();

vlastIds[QString::fromUtf8(it.key())] = it.value();
vlastIds[QString::fromUtf8(it.key().asQByteArray())] = it.value().asQByteArray();
}

vinspect["last-ids"] = vlastIds;
Expand All @@ -126,7 +126,7 @@ Variant RetryRequestPacket::toVariant() const {
}

if (!route.isEmpty())
obj["route"] = route;
obj["route"] = route.asQByteArray();

if (retrySeq >= 0)
obj["retry-seq"] = retrySeq;
Expand Down
12 changes: 6 additions & 6 deletions src/core/packet/retryrequestpacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class RetryRequestPacket {
public:
typedef QPair<QByteArray, QByteArray> Rid;
typedef QPair<CowByteArray, CowByteArray> Rid;

class Request {
public:
Expand All @@ -39,7 +39,7 @@ class RetryRequestPacket {
QHostAddress peerAddress;
bool debug;
bool autoCrossOrigin;
QByteArray jsonpCallback;
CowByteArray jsonpCallback;
bool jsonpExtendedResponse;
int unreportedTime;

Expand All @@ -65,9 +65,9 @@ class RetryRequestPacket {
class InspectInfo {
public:
bool doProxy;
QByteArray sharingKey;
QByteArray sid;
QHash<QByteArray, QByteArray> lastIds;
CowByteArray sharingKey;
CowByteArray sid;
QHash<CowByteArray, CowByteArray> lastIds;
Variant userData;

InspectInfo() : doProxy(false) {}
Expand All @@ -79,7 +79,7 @@ class RetryRequestPacket {
bool haveInspectInfo;
InspectInfo inspectInfo;

QByteArray route;
CowByteArray route;
int retrySeq;

RetryRequestPacket();
Expand Down
18 changes: 9 additions & 9 deletions src/core/packet/statspacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ Variant StatsPacket::toVariant() const {
VariantHash obj;

if (!from.isEmpty())
obj["from"] = from;
obj["from"] = from.asQByteArray();

if (!route.isEmpty())
obj["route"] = route;
obj["route"] = route.asQByteArray();

if (type == Activity) {
int x = count;
if (x < 0)
x = 0;
obj["count"] = x;
} else if (type == Message) {
obj["channel"] = channel;
obj["channel"] = channel.asQByteArray();

if (!itemId.isNull())
obj["item-id"] = itemId;
obj["item-id"] = itemId.asQByteArray();

int x = count;
if (x < 0)
Expand All @@ -65,9 +65,9 @@ Variant StatsPacket::toVariant() const {
if (blocks >= 0)
obj["blocks"] = blocks;

obj["transport"] = transport;
obj["transport"] = transport.asQByteArray();
} else if (type == Connected || type == Disconnected) {
obj["id"] = connectionId;
obj["id"] = connectionId.asQByteArray();

if (type == Connected) {
if (connectionType == WebSocket)
Expand All @@ -87,8 +87,8 @@ Variant StatsPacket::toVariant() const {
obj["unavailable"] = true;
}
} else if (type == Subscribed || type == Unsubscribed) {
obj["mode"] = mode;
obj["channel"] = channel;
obj["mode"] = mode.asQByteArray();
obj["channel"] = channel.asQByteArray();

if (type == Subscribed) {
obj["ttl"] = ttl;
Expand Down Expand Up @@ -156,7 +156,7 @@ Variant StatsPacket::toVariant() const {
return obj;
}

bool StatsPacket::fromVariant(const QByteArray &_type, const Variant &in) {
bool StatsPacket::fromVariant(const CowByteArray &_type, const Variant &in) {
if (typeId(in) != VariantType::Hash)
return false;

Expand Down
18 changes: 9 additions & 9 deletions src/core/packet/statspacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#ifndef STATSPACKET_H
#define STATSPACKET_H

#include "cowbytearray.h"
#include "variant.h"
#include <QByteArray>
#include <QHostAddress>

class StatsPacket {
Expand All @@ -45,19 +45,19 @@ class StatsPacket {
enum ConnectionType { Http, WebSocket };

Type type;
QByteArray from;
QByteArray route;
CowByteArray from;
CowByteArray route;
int64_t retrySeq; // Connections max
int count; // Activity, message
QByteArray connectionId; // Connected, disconnected
CowByteArray connectionId; // Connected, disconnected
ConnectionType connectionType; // Connected
QHostAddress peerAddress; // Connected
bool ssl; // Connected
int ttl; // Connected, subscribed, connections max
QByteArray mode; // Subscribed, unsubscribed
QByteArray channel; // Message, subscribed, unsubscribed
QByteArray itemId; // Message
QByteArray transport; // Message
CowByteArray mode; // Subscribed, unsubscribed
CowByteArray channel; // Message, subscribed, unsubscribed
CowByteArray itemId; // Message
CowByteArray transport; // Message
int blocks; // Message
int subscribers; // Subscribed
int connectionsMax; // Report, connections max
Expand Down Expand Up @@ -114,7 +114,7 @@ class StatsPacket {
serverMessagesSent(-1) {}

Variant toVariant() const;
bool fromVariant(const QByteArray &type, const Variant &in);
bool fromVariant(const CowByteArray &type, const Variant &in);
};

#endif
Loading
Loading