diff options
-rw-r--r-- | saprotocol.cc | 73 | ||||
-rw-r--r-- | saprotocol.h | 21 |
2 files changed, 93 insertions, 1 deletions
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<quint8>(data, offset); + frame.acceptorId = read<quint8>(data, offset); + frame.initiatorId = read<quint8>(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<quint8>(data, frame.messageType); + append<quint16>(data, frame.acceptorId); + append<quint16>(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<quint8>(data, offset); + frame.acceptorId = read<quint8>(data, offset); + frame.initiatorId = read<quint8>(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<quint8>(data, offset); + + return frame; +} + +QByteArray SAProtocol::packServiceTerminationResponseFrame(const ServiceTerminationResponseFrame &frame) +{ + QByteArray data; + + append<quint8>(data, frame.messageType); + append<quint16>(data, frame.acceptorId); + append<quint16>(data, frame.initiatorId); + + data.append(frame.profile.toUtf8()); + data.append(';'); + + append<quint8>(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; |