Fix protocol errors and connection to UI. Make sure protocol handles nulls
This commit is contained in:
parent
56d7c58ac0
commit
aed3fca0bf
7 changed files with 57 additions and 31 deletions
|
@ -23,6 +23,7 @@ ApplicationWindow
|
||||||
connectionHandler.connected.connect(C.onConnected);
|
connectionHandler.connected.connect(C.onConnected);
|
||||||
connectionHandler.disconnected.connect(C.onDisconnected);
|
connectionHandler.disconnected.connect(C.onDisconnected);
|
||||||
connectionHandler.displayDebugData.connect(C.onDisplayDebugData);
|
connectionHandler.displayDebugData.connect(C.onDisplayDebugData);
|
||||||
|
connectionHandler.newEvent.connect(C.newEvent);
|
||||||
connectionHandler.sslError.connect(C.onSslError);
|
connectionHandler.sslError.connect(C.onSslError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,5 +31,3 @@ ApplicationWindow
|
||||||
id: connectionHandler
|
id: connectionHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,11 @@ function init(connectionHandler, pageStack) {
|
||||||
|
|
||||||
|
|
||||||
// Signal handlers for incoming data from connection
|
// Signal handlers for incoming data from connection
|
||||||
|
function newEvent(id, data) {
|
||||||
|
debugViewPage.display("Event received: " + id);
|
||||||
|
debugViewPage.display(JSON.stringify(data));
|
||||||
|
}
|
||||||
|
|
||||||
function onDisplayDebugData(str) {
|
function onDisplayDebugData(str) {
|
||||||
debugViewPage.display(str);
|
debugViewPage.display(str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,4 +184,5 @@ void ConnectionHandler::connectSignals()
|
||||||
|
|
||||||
QObject::connect(handler, &ProtocolHandler::debugData, this, &ConnectionHandler::handleDebugData);
|
QObject::connect(handler, &ProtocolHandler::debugData, this, &ConnectionHandler::handleDebugData);
|
||||||
QObject::connect(handler, &ProtocolHandler::sendData, connection, &RelayConnection::write);
|
QObject::connect(handler, &ProtocolHandler::sendData, connection, &RelayConnection::write);
|
||||||
|
QObject::connect(handler, SIGNAL(newEvent(QString,QVariant)), this, SIGNAL(newEvent(QString,QVariant)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ signals:
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
|
||||||
void displayDebugData(QString data);
|
void displayDebugData(QString data);
|
||||||
|
void newEvent(QString id, QVariant data);
|
||||||
void sslError(QString errorStrings, QString issuerInfo,
|
void sslError(QString errorStrings, QString issuerInfo,
|
||||||
QDateTime startDate, QDateTime expiryDate,
|
QDateTime startDate, QDateTime expiryDate,
|
||||||
QString digest);
|
QString digest);
|
||||||
|
|
|
@ -26,6 +26,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void debugData(QString hexString);
|
void debugData(QString hexString);
|
||||||
|
void newEvent(QString id, QVariant data);
|
||||||
|
|
||||||
// ProtocolHandler wants to send data to the associated network stream
|
// ProtocolHandler wants to send data to the associated network stream
|
||||||
void sendData(QByteArray data);
|
void sendData(QByteArray data);
|
||||||
|
|
|
@ -103,7 +103,7 @@ qint64 WeeChatProtocolHandler::handleLong(QDataStream* data)
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
if (current == 45) // ASCII '-'
|
if (current == '-')
|
||||||
{
|
{
|
||||||
magnitude = -1;
|
magnitude = -1;
|
||||||
}
|
}
|
||||||
|
@ -121,28 +121,26 @@ qint64 WeeChatProtocolHandler::handleLong(QDataStream* data)
|
||||||
|
|
||||||
QString WeeChatProtocolHandler::handleString(QDataStream* data)
|
QString WeeChatProtocolHandler::handleString(QDataStream* data)
|
||||||
{
|
{
|
||||||
// Strings are stored as length (4 bytes) + data (no \0)
|
// Strings are just buffers interpreted as string data
|
||||||
QString ret;
|
QByteArray bytes = handleBuffer(data);
|
||||||
quint32 length;
|
|
||||||
*data >> length;
|
|
||||||
|
|
||||||
quint8 current;
|
// Lovely WeeChat sends everything our way in UTF-8 <3
|
||||||
for (quint32 i = 0; i < length; ++i)
|
return QString::fromUtf8(bytes);
|
||||||
{
|
|
||||||
*data >> current;
|
|
||||||
ret.append(static_cast<char>(current));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray WeeChatProtocolHandler::handleBuffer(QDataStream* data)
|
QByteArray WeeChatProtocolHandler::handleBuffer(QDataStream* data)
|
||||||
{
|
{
|
||||||
// Buffer is the same as string, but just bytes
|
// Buffers consist of a length (4 bytes) + data
|
||||||
QByteArray ret;
|
QByteArray ret;
|
||||||
quint32 length;
|
quint32 length;
|
||||||
*data >> length;
|
*data >> length;
|
||||||
|
|
||||||
|
// If length is all 1s, the content is empty
|
||||||
|
if (length == 0xffffffff)
|
||||||
|
{
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
quint8 current;
|
quint8 current;
|
||||||
for (quint32 i = 0; i < length; ++i)
|
for (quint32 i = 0; i < length; ++i)
|
||||||
{
|
{
|
||||||
|
@ -160,13 +158,24 @@ QString WeeChatProtocolHandler::handlePointer(QDataStream* data)
|
||||||
quint8 length;
|
quint8 length;
|
||||||
*data >> length;
|
*data >> length;
|
||||||
|
|
||||||
|
qDebug() << "Pointer length: " << length;
|
||||||
|
|
||||||
quint8 current;
|
quint8 current;
|
||||||
for (quint8 i = 0; i < length; ++i)
|
for (quint8 i = 0; i < length; ++i)
|
||||||
{
|
{
|
||||||
*data >> current;
|
*data >> current;
|
||||||
|
|
||||||
|
// Convert 0 to '0' to handle null pointer
|
||||||
|
if (current == 0)
|
||||||
|
{
|
||||||
|
current = '0';
|
||||||
|
}
|
||||||
|
|
||||||
ret.append(static_cast<char>(current));
|
ret.append(static_cast<char>(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "Pointer data: " << ret;
|
||||||
|
|
||||||
return ret.prepend("0x");
|
return ret.prepend("0x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,13 +226,16 @@ QVariantHash WeeChatProtocolHandler::handleHdata(QDataStream* data)
|
||||||
* of parts in H-path
|
* of parts in H-path
|
||||||
* * List of objects, with the same keys and types as defined in Keys
|
* * List of objects, with the same keys and types as defined in Keys
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QVariantHash hdata;
|
QVariantHash hdata;
|
||||||
QVariantList objectSets;
|
QVariantList objectSets;
|
||||||
QVariantHash keys;
|
QVariantHash keys;
|
||||||
|
|
||||||
QString hPath = WeeChatProtocolHandler::handleString(data);
|
QString hPath = handleString(data);
|
||||||
|
qDebug() << "H-path: " << hPath;
|
||||||
|
|
||||||
QString keyString = WeeChatProtocolHandler::handleString(data);
|
QString keyString = handleString(data);
|
||||||
|
qDebug() << "Keystr: " << keyString;
|
||||||
QStringList keyList = keyString.split(",");
|
QStringList keyList = keyString.split(",");
|
||||||
QStringList orderedKeys;
|
QStringList orderedKeys;
|
||||||
|
|
||||||
|
@ -236,7 +248,7 @@ QVariantHash WeeChatProtocolHandler::handleHdata(QDataStream* data)
|
||||||
orderedKeys.append(keyName);
|
orderedKeys.append(keyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
qint32 objectSetCount = WeeChatProtocolHandler::handleInt(data);
|
qint32 objectSetCount = handleInt(data);
|
||||||
|
|
||||||
for (qint32 i = 0; i < objectSetCount; ++i)
|
for (qint32 i = 0; i < objectSetCount; ++i)
|
||||||
{
|
{
|
||||||
|
@ -246,9 +258,10 @@ QVariantHash WeeChatProtocolHandler::handleHdata(QDataStream* data)
|
||||||
// separated by /
|
// separated by /
|
||||||
QVariantList pointers;
|
QVariantList pointers;
|
||||||
int pointerCount = hPath.split("/").size();
|
int pointerCount = hPath.split("/").size();
|
||||||
|
qDebug() << "PointerCount: " << pointerCount;
|
||||||
for (int r = 0; r < pointerCount; ++r)
|
for (int r = 0; r < pointerCount; ++r)
|
||||||
{
|
{
|
||||||
pointers.append(WeeChatProtocolHandler::handlePointer(data));
|
pointers.append(handlePointer(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSet.insert(QString("__path"), pointers);
|
objectSet.insert(QString("__path"), pointers);
|
||||||
|
@ -256,7 +269,8 @@ QVariantHash WeeChatProtocolHandler::handleHdata(QDataStream* data)
|
||||||
for (QString keyName : orderedKeys)
|
for (QString keyName : orderedKeys)
|
||||||
{
|
{
|
||||||
Type type = stringToType(keys.value(keyName).toString());
|
Type type = stringToType(keys.value(keyName).toString());
|
||||||
objectSet.insert(keyName, WeeChatProtocolHandler::handleDynamicType(type, data));
|
qDebug() << "Handling key " << keyName;
|
||||||
|
objectSet.insert(keyName, handleDynamicType(type, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
objectSets.append(objectSet);
|
objectSets.append(objectSet);
|
||||||
|
@ -413,6 +427,10 @@ void WeeChatProtocolHandler::handleBody(QDataStream* data)
|
||||||
qDebug() << "ID: " << id;
|
qDebug() << "ID: " << id;
|
||||||
|
|
||||||
|
|
||||||
|
Type type = readType(data);
|
||||||
|
qDebug() << "Type: " << type;
|
||||||
|
|
||||||
|
|
||||||
// IDs for all event types
|
// IDs for all event types
|
||||||
|
|
||||||
if (id == "_pong")
|
if (id == "_pong")
|
||||||
|
@ -427,10 +445,12 @@ void WeeChatProtocolHandler::handleBody(QDataStream* data)
|
||||||
{
|
{
|
||||||
handleUpgradeEnded(id, data);
|
handleUpgradeEnded(id, data);
|
||||||
}
|
}
|
||||||
else
|
else if (type == HDATA) {
|
||||||
{
|
|
||||||
handleDefaultEvent(id, data);
|
handleDefaultEvent(id, data);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "Unknown type!";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
delete[] dataArr;
|
delete[] dataArr;
|
||||||
|
@ -442,27 +462,26 @@ void WeeChatProtocolHandler::handleBody(QDataStream* data)
|
||||||
|
|
||||||
void WeeChatProtocolHandler::handleDefaultEvent(QString id, QDataStream* data)
|
void WeeChatProtocolHandler::handleDefaultEvent(QString id, QDataStream* data)
|
||||||
{
|
{
|
||||||
// Type for default events is hda, so skip it
|
qDebug() << "Making hdata!";
|
||||||
readType(data);
|
|
||||||
|
|
||||||
QVariantHash hdata = handleHdata(data);
|
QVariantHash hdata = handleHdata(data);
|
||||||
emit event(id, hdata);
|
qDebug() << "Got hdata made!";
|
||||||
|
emit newEvent(id, hdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeeChatProtocolHandler::handlePong(QString id, QDataStream* data)
|
void WeeChatProtocolHandler::handlePong(QString id, QDataStream* data)
|
||||||
{
|
{
|
||||||
QString response = handleString(data);
|
QString response = handleString(data);
|
||||||
emit event(id, response);
|
emit newEvent(id, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeeChatProtocolHandler::handleUpgrade(QString id, QDataStream* data)
|
void WeeChatProtocolHandler::handleUpgrade(QString id, QDataStream* data)
|
||||||
{
|
{
|
||||||
// There is no data to read for this message
|
// There is no data to read for this message
|
||||||
emit event(id, QVariant());
|
emit newEvent(id, QVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeeChatProtocolHandler::handleUpgradeEnded(QString id, QDataStream* data)
|
void WeeChatProtocolHandler::handleUpgradeEnded(QString id, QDataStream* data)
|
||||||
{
|
{
|
||||||
// There is no data to read for this message
|
// There is no data to read for this message
|
||||||
emit event(id, QVariant());
|
emit newEvent(id, QVariant());
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
static Type stringToType(QString type);
|
static Type stringToType(QString type);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void event(QString id, QVariant data);
|
void newEvent(QString id, QVariant data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleNewData(RelayConnection* connection);
|
void handleNewData(RelayConnection* connection);
|
||||||
|
|
Loading…
Reference in a new issue