From 97c93d800287a21b971b763d58c1eebb30ece071 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Dec 2015 05:50:18 +0100 Subject: fix broken decoding of multiple-channel connection requests --- sappeer.cc | 4 +++- saprotocol.cc | 31 +++++++++++++++++++++++++------ webproxyagent.cc | 11 +++++++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/sappeer.cc b/sappeer.cc index 60e7660..b9f0136 100644 --- a/sappeer.cc +++ b/sappeer.cc @@ -233,6 +233,7 @@ void SAPPeer::handleDefaultSessionMessage(const QByteArray &message) } if (!ok) { + // Send a negative status code message back SAProtocol::ServiceConnectionResponseFrame resp; resp.messageType = SAProtocol::ServiceConnectionResponse; resp.acceptorId = req.acceptorId; @@ -256,7 +257,8 @@ void SAPPeer::handleDefaultSessionMessage(const QByteArray &message) // TODO set socket QoS parameters conn->setSocket(s.channelId, socket); - qDebug() << " opening channel" << s.sessionId << s.channelId << "payload=" << s.payloadType; + qDebug() << " opening channel" << s.channelId << "as session" << s.sessionId; + qDebug() << " payload=" << s.payloadType << "qos=" << s.qosType << "prio=" << s.qosPriority << "rate=" << s.qosDataRate; _sessions.insert(s.sessionId, socket); } diff --git a/saprotocol.cc b/saprotocol.cc index 541f0af..c580f12 100644 --- a/saprotocol.cc +++ b/saprotocol.cc @@ -247,20 +247,30 @@ SAProtocol::ServiceConnectionRequestFrame SAProtocol::unpackServiceConnectionReq frame.profile = QString::fromUtf8(&data.constData()[offset], marker - offset); offset = marker + 1; - int num_sessions = read(data, offset); + const int num_sessions = read(data, offset); + frame.sessions.reserve(num_sessions); - while (num_sessions > 0) { + for (int i = 0; i < num_sessions; i++) { ServiceConnectionRequestSession session; session.sessionId = read(data, offset); + frame.sessions.append(session); + } + + for (int i = 0; i < num_sessions; i++) { + ServiceConnectionRequestSession &session = frame.sessions[i]; session.channelId = read(data, offset); + } + + for (int i = 0; i < num_sessions; i++) { + ServiceConnectionRequestSession &session = frame.sessions[i]; session.qosType = read(data, offset); session.qosDataRate = read(data, offset); session.qosPriority = read(data, offset); - session.payloadType = read(data, offset); - - frame.sessions.append(session); + } - num_sessions--; + for (int i = 0; i < num_sessions; i++) { + ServiceConnectionRequestSession &session = frame.sessions[i]; + session.payloadType = read(data, offset); } return frame; @@ -281,10 +291,19 @@ QByteArray SAProtocol::packServiceConnectionRequestFrame(const ServiceConnection foreach (const ServiceConnectionRequestSession &session, frame.sessions) { append(data, session.sessionId); + } + + foreach (const ServiceConnectionRequestSession &session, frame.sessions) { append(data, session.channelId); + } + + foreach (const ServiceConnectionRequestSession &session, frame.sessions) { append(data, session.qosType); append(data, session.qosDataRate); append(data, session.qosPriority); + } + + foreach (const ServiceConnectionRequestSession &session, frame.sessions) { append(data, session.payloadType); } diff --git a/webproxyagent.cc b/webproxyagent.cc index 186912f..126cd75 100644 --- a/webproxyagent.cc +++ b/webproxyagent.cc @@ -46,11 +46,18 @@ void WebProxyAgent::registerServices(SAPManager *manager) service.setVersion(2, 0); service.setConnectionTimeout(0); + channel.setChannelId(501); + channel.setPayloadType(SAPChannelInfo::PayloadBinary); + channel.setQoSType(SAPChannelInfo::QoSReliabilityEnable); + channel.setQoSDataRate(SAPChannelInfo::QoSDataRateLow); + channel.setQoSPriority(SAPChannelInfo::QoSPriorityLow); + service.addChannel(channel); + channel.setChannelId(502); channel.setPayloadType(SAPChannelInfo::PayloadBinary); - channel.setQoSType(SAPChannelInfo::QoSRestricted); + channel.setQoSType(SAPChannelInfo::QoSReliabilityEnable); channel.setQoSDataRate(SAPChannelInfo::QoSDataRateLow); - channel.setQoSPriority(SAPChannelInfo::QoSPriorityHigh); + channel.setQoSPriority(SAPChannelInfo::QoSPriorityLow); service.addChannel(channel); manager->registerServiceAgent(service, instance()); -- cgit v1.2.3