#include #include "sappeer.h" #include "endianhelpers.h" #include "webproxyconn.h" WebProxyConn::WebProxyConn(SAPConnection *conn, QObject *parent) : QObject(parent), _conn(conn), _in(conn->getSocket(501)), _out(conn->getSocket(502)) { connect(_conn, SIGNAL(disconnected()), SLOT(deleteLater())); Q_ASSERT(_in && _out); connect(_in, SIGNAL(messageReceived()), SLOT(handleMessageReceived())); } WebProxyConn::RequestMessage WebProxyConn::unpackRequestMessage(const QByteArray &data) { RequestMessage msg; int offset = 0; msg.command = read(data, offset); msg.subCommand = read(data, offset); msg.type = static_cast(read(data, offset)); msg.transactionId = read(data, offset); const quint32 len = read(data, offset); msg.payload = data.mid(offset, len); return msg; } void WebProxyConn::handleStartTransaction(const RequestMessage &msg) { QString req = QString::fromUtf8(msg.payload); qDebug() << req; } void WebProxyConn::handleCancelTransaction(const RequestMessage &msg) { } void WebProxyConn::handleMessageReceived() { QByteArray data = _in->receive(); RequestMessage req = unpackRequestMessage(data); if (req.command != 1 || req.subCommand != 1) { qWarning() << "Invalid command/subcommand: " << req.command << "/" << req.subCommand; return; } switch (req.type) { case RequestStartTransaction: handleStartTransaction(req); break; case RequestCancelTransaction: handleCancelTransaction(req); break; default: qWarning() << "Unknown request type" << req.type; } }