From ce8a092a235c8d59f01631c80786f920eb6a777b Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Dec 2015 20:36:52 +0100 Subject: Add terminate connection frame structs --- saprotocol.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ saprotocol.h | 21 ++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/saprotocol.cc b/saprotocol.cc index c580f12..9f25613 100644 --- a/saprotocol.cc +++ b/saprotocol.cc @@ -364,6 +364,79 @@ QByteArray SAProtocol::packServiceConnectionResponseFrame(const ServiceConnectio return data; } +SAProtocol::ServiceTerminationRequestFrame SAProtocol::unpackServiceTerminationRequestFrame(const QByteArray &data) +{ + ServiceTerminationRequestFrame frame; + int offset = 0; + + frame.messageType = read(data, offset); + frame.acceptorId = read(data, offset); + frame.initiatorId = read(data, offset); + + int marker = data.indexOf(';', offset); + if (marker == -1) { + qWarning() << "No profile in termination request"; + return frame; + } + + frame.profile = QString::fromUtf8(&data.constData()[offset], marker - offset); + + return frame; +} + +QByteArray SAProtocol::packServiceTerminationRequestFrame(const ServiceTerminationRequestFrame &frame) +{ + QByteArray data; + + append(data, frame.messageType); + append(data, frame.acceptorId); + append(data, frame.initiatorId); + + data.append(frame.profile.toUtf8()); + data.append(';'); + + return data; +} + +SAProtocol::ServiceTerminationResponseFrame SAProtocol::unpackServiceTerminationResponseFrame(const QByteArray &data) +{ + ServiceTerminationResponseFrame frame; + int offset = 0; + + frame.messageType = read(data, offset); + frame.acceptorId = read(data, offset); + frame.initiatorId = read(data, offset); + + int marker = data.indexOf(';', offset); + if (marker == -1) { + qWarning() << "No profile in termination response"; + return frame; + } + + frame.profile = QString::fromUtf8(&data.constData()[offset], marker - offset); + offset = marker + 1; + + frame.statusCode = read(data, offset); + + return frame; +} + +QByteArray SAProtocol::packServiceTerminationResponseFrame(const ServiceTerminationResponseFrame &frame) +{ + QByteArray data; + + append(data, frame.messageType); + append(data, frame.acceptorId); + append(data, frame.initiatorId); + + data.append(frame.profile.toUtf8()); + data.append(';'); + + append(data, frame.statusCode); + + return data; +} + SAProtocol::CapabilityDiscoveryQuery SAProtocol::unpackCapabilityDiscoveryQuery(const QByteArray &data) { CapabilityDiscoveryQuery msg; diff --git a/saprotocol.h b/saprotocol.h index a9f5ac0..443206b 100644 --- a/saprotocol.h +++ b/saprotocol.h @@ -135,7 +135,26 @@ public: static ServiceConnectionResponseFrame unpackServiceConnectionResponseFrame(const QByteArray &data); static QByteArray packServiceConnectionResponseFrame(const ServiceConnectionResponseFrame &frame); - // TODO service conn termination request. probably trivial. + struct ServiceTerminationRequestFrame { + quint8 messageType; + quint16 acceptorId; + quint16 initiatorId; + QString profile; + }; + + static ServiceTerminationRequestFrame unpackServiceTerminationRequestFrame(const QByteArray &data); + static QByteArray packServiceTerminationRequestFrame(const ServiceTerminationRequestFrame &frame); + + struct ServiceTerminationResponseFrame { + quint8 messageType; + quint16 acceptorId; + quint16 initiatorId; + QString profile; + quint8 statusCode; + }; + + static ServiceTerminationResponseFrame unpackServiceTerminationResponseFrame(const QByteArray &data); + static QByteArray packServiceTerminationResponseFrame(const ServiceTerminationResponseFrame &frame); static const QLatin1String capabilityDiscoveryProfile; static const quint16 capabilityDiscoveryChannel = 255; -- cgit v1.2.3