MessageContent* GroupLeaveMessageContent::fromPacketPayload(FullMessageHeader const& messageHeader, QByteArray const& payload) const { verifyPayloadMinSizeAndSignatureByte(PROTO_MESSAGE_SIGNATURE_GROUP_LEAVE, 1 + GroupId::getSizeOfGroupIdInBytes(), payload); GroupId const groupId(GroupId::fromData(payload.mid(1, GroupId::getSizeOfGroupIdInBytes()))); return new GroupLeaveMessageContent(groupId, messageHeader.getSender()); }
MessageContent* ContactTextMessageContent::fromPacketPayload(FullMessageHeader const& messageHeader, QByteArray const& payload) const { verifyPayloadMinSizeAndSignatureByte(PROTO_MESSAGE_SIGNATURE_CONTACT_TEXT, 2, payload); QString payloadText(QString::fromUtf8(payload.mid(1))); return new ContactTextMessageContent(payloadText); }
MessageContent* GroupTextMessageContent::fromPacketPayload(FullMessageHeader const& messageHeader, QByteArray const& payload) const { verifyPayloadMinSizeAndSignatureByte(PROTO_MESSAGE_SIGNATURE_GROUP_TEXT, 1 + GroupId::getSizeOfGroupIdInBytes() + 1, payload); GroupId const groupId(GroupId::fromData(payload.mid(1, GroupId::getSizeOfGroupIdInBytes()))); QString payloadText(QString::fromUtf8(payload.mid(1 + GroupId::getSizeOfGroupIdInBytes()))); return new GroupTextMessageContent(groupId, payloadText); }
MessageContent* GroupImageIdAndKeyMessageContent::fromPacketPayload(FullMessageHeader const& messageHeader, QByteArray const& payload) const { verifyPayloadMinSizeAndSignatureByte(PROTO_MESSAGE_SIGNATURE_GROUP_PICTURE, 1 + openmittsu::protocol::GroupId::getSizeOfGroupIdInBytes() + (PROTO_IMAGESERVER_ID_LENGTH_BYTES)+4 + openmittsu::crypto::EncryptionKey::getSizeOfEncryptionKeyInBytes(), payload, true); int startingPosition = 1; openmittsu::protocol::GroupId const group(openmittsu::protocol::GroupId::fromData(payload.mid(startingPosition, openmittsu::protocol::GroupId::getSizeOfGroupIdInBytes()))); startingPosition += openmittsu::protocol::GroupId::getSizeOfGroupIdInBytes(); QByteArray const id(payload.mid(startingPosition, PROTO_IMAGESERVER_ID_LENGTH_BYTES)); startingPosition += PROTO_IMAGESERVER_ID_LENGTH_BYTES; uint32_t const size = openmittsu::utility::ByteArrayConversions::convert4ByteQByteArrayToQuint32(payload.mid(startingPosition, 4)); startingPosition += 4; openmittsu::crypto::EncryptionKey const key(payload.mid(startingPosition, openmittsu::crypto::EncryptionKey::getSizeOfEncryptionKeyInBytes())); return new GroupImageIdAndKeyMessageContent(group, id, key, size); }
MessageContent* GroupLocationMessageContent::fromPacketPayload(FullMessageHeader const& messageHeader, QByteArray const& payload) const { verifyPayloadMinSizeAndSignatureByte(PROTO_MESSAGE_SIGNATURE_GROUP_LOCATION, 1 + GroupId::getSizeOfGroupIdInBytes() + 1, payload); GroupId const groupId(GroupId::fromData(payload.mid(1, GroupId::getSizeOfGroupIdInBytes()))); // Layout of remaining payload: // 51.719827,9.888894,0.000000\nSome Road 1234 QByteArray const remainingPayload(payload.mid(1 + GroupId::getSizeOfGroupIdInBytes())); int const positionOfNewLine = remainingPayload.indexOf('\n'); if (positionOfNewLine == -1) { throw ProtocolErrorException() << "Could not split payload of a GroupLocationMessage, it does not contain the 0x0A LF splitter."; } QString const positions = QString::fromUtf8(remainingPayload.left(positionOfNewLine)); QString const descriptionText = QString::fromUtf8(remainingPayload.mid(positionOfNewLine + 1)); QStringList splitPositions = positions.split(',', QString::SkipEmptyParts); if (splitPositions.size() != 3) { throw ProtocolErrorException() << "Could not split payload of a GroupLocationMessage, it contains " << splitPositions.size() << " instead of 3 positions. Input String: " << positions.toStdString(); } bool ok = false; double const lat = splitPositions.at(0).toDouble(&ok); if (!ok) { throw ProtocolErrorException() << "Could not convert position 1 to double. Input String: " << positions.toStdString(); } double const lon = splitPositions.at(1).toDouble(&ok); if (!ok) { throw ProtocolErrorException() << "Could not convert position 2 to double. Input String: " << positions.toStdString(); } double const hei = splitPositions.at(2).toDouble(&ok); if (!ok) { throw ProtocolErrorException() << "Could not convert position 3 to double. Input String: " << positions.toStdString(); } return new GroupLocationMessageContent(groupId, lat, lon, hei, descriptionText); }