void callbackODeliver(address sender, t_typ messageTyp, message *mp){ if (payloadSize(mp) != size) { fprintf(stderr, "Error in file %s:%d : Payload size is incorrect: it is %zu when it should be %d\n", __FILE__, __LINE__, payloadSize(mp), size); exit(EXIT_FAILURE); } }
bool QtsPesPacket::isAc3() const { // Payload must start with 0B 77 const quint8* pl = payload(); const int size = payloadSize(); return size > 2 && pl[0] == 0x0B && pl[1] == 0x77; }
QByteArray NetworkPackage::serialize() const { //Object -> QVariant //QVariantMap variant; //variant["id"] = mId; //variant["type"] = mType; //variant["body"] = mBody; QVariantMap variant = qobject2qvariant(this); if (hasPayload()) { //qCDebug(KDECONNECT_CORE) << "Serializing payloadTransferInfo"; variant[QStringLiteral("payloadSize")] = payloadSize(); variant[QStringLiteral("payloadTransferInfo")] = mPayloadTransferInfo; } //QVariant -> json auto jsonDocument = QJsonDocument::fromVariant(variant); QByteArray json = jsonDocument.toJson(QJsonDocument::Compact); if (json.isEmpty()) { qCDebug(KDECONNECT_CORE) << "Serialization error:"; } else { /*if (!isEncrypted()) { //qCDebug(KDECONNECT_CORE) << "Serialized package:" << json; }*/ json.append('\n'); } return json; }
const char * Frame::toString() const { static char str[3 * MaximalFramePayloadSize]; assert( _pImpl ); if ( _pImpl ) { for (size_t i = 0; i < payloadSize(); i++) { sprintf(str + (i * 3), "%02x ", _pImpl->payload[i]); } // Finish the string str[payloadSize() * 3] = '\0'; return str; } return NULL; }
/* Callback for messages to be O-delivered */ void callbackODeliver(address sender, t_typ messageTyp, message *mp){ char s[MAX_LEN_ADDRESS_AS_STR]; static int nbRecMsg = 0; if (payloadSize(mp) != size) { fprintf(stderr, "Error in file %s:%d : Payload size is incorrect: it is %zu when it should be %d\n", __FILE__, __LINE__, payloadSize(mp), size); exit(EXIT_FAILURE); } nbRecMsg++; if (verbose) printf("!!! %5d-ieme message (recu de %s / contenu = %5d)\n", nbRecMsg, addrToStr(s, sender), *((int*) (mp->payload))); }
bool QtsPesPacket::isMpeg2Video() const { // Must have a video stream_id and payload must start with 00 00 01 if (!qtsIsVideoPesStreamId(getStreamId())) { return false; } else { const quint8* pl = payload(); const int size = payloadSize(); return size >= 3 && pl[0] == 0x00 && pl[1] == 0x00 && pl[2] == 0x01; } }
Condition Ed25519::condition() const { Condition cc; cc.type = type(); cc.featureBitmask = features(); cc.maxFulfillmentLength = payloadSize(); std::memcpy ( cc.fingerprint.data(), payload_.data(), pubkey_size_); return cc; }
bool QtsPesPacket::isAvc() const { // Must have a video stream_id and payload must start with 00 00 00 [00...] 01 if (!qtsIsVideoPesStreamId(getStreamId())) { return false; } else { const quint8* pl = payload(); int size = payloadSize(); while(size > 0 && *pl == 0x00) { ++pl; --size; } return size > 0 && *pl == 0x01 && pl > payload() + 2; } }
Buffer RsaSha256::payload() const { Buffer b (payloadSize()); auto out = oer::encode_octetstring ( modulus_.size(), modulus_.data(), modulus_.data() + modulus_.size(), b.data()); oer::encode_octetstring ( signature_.size(), signature_.data(), signature_.data() + modulus_.size(), out); return b; }
Condition RsaSha256::condition() const { std::vector<std::uint8_t> m; m.reserve (1024); oer::encode_octetstring ( modulus_.size(), modulus_.data(), modulus_.data() + modulus_.size(), std::back_inserter(m)); sha256_hasher h; h (m.data(), m.size()); Condition cc; cc.type = type(); cc.featureBitmask = features(); cc.maxFulfillmentLength = payloadSize(); cc.fingerprint = static_cast<sha256_hasher::result_type>(h); return cc; }
bool RTMP::sendPacket(RTMPPacket& packet) { // Set the data size of the packet to send. RTMPHeader& hr = packet.header; hr.dataSize = payloadSize(packet); // This is the timestamp for our message. const std::uint32_t uptime = getUptime(); // Look at the previous packet on the channel. bool prev = hasPacket(CHANNELS_OUT, hr.channel); // The packet shall be large if it contains an absolute timestamp. // * This is necessary if there is no previous packet, or if the // timestamp is smaller than the last packet. // Else it shall be medium if data size and packet type are the same // It shall be small if ... // It shall be minimal if it is exactly the same as its predecessor. // All packets should start off as large. They will stay large if there // is no previous packet. assert(hr.headerType == RTMP_PACKET_SIZE_LARGE); if (!prev) { hr._timestamp = uptime; } else { const RTMPPacket& prevPacket = getPacket(CHANNELS_OUT, hr.channel); const RTMPHeader& oldh = prevPacket.header; const std::uint32_t prevTimestamp = oldh._timestamp; // If this timestamp is later than the other and the difference fits // in 3 bytes, encode a relative one. if (uptime >= oldh._timestamp && uptime - prevTimestamp < 0xffffff) { //log_debug("Shrinking to medium"); hr.headerType = RTMP_PACKET_SIZE_MEDIUM; hr._timestamp = uptime - prevTimestamp; // It can be still smaller if the data size is the same. if (oldh.dataSize == hr.dataSize && oldh.packetType == hr.packetType) { //log_debug("Shrinking to small"); hr.headerType = RTMP_PACKET_SIZE_SMALL; // If there is no timestamp difference, the minimum size // is possible. if (hr._timestamp == 0) { //log_debug("Shrinking to minimum"); hr.headerType = RTMP_PACKET_SIZE_MINIMUM; } } } else { // Otherwise we need an absolute one, so a large header. hr.headerType = RTMP_PACKET_SIZE_LARGE; hr._timestamp = uptime; } } assert (hr.headerType < 4); int nSize = packetSize[hr.headerType]; int hSize = nSize; std::uint8_t* header; std::uint8_t* hptr; std::uint8_t* hend; std::uint8_t c; // If there is a payload, the same buffer is used to write the header. // Otherwise a separate buffer is used. But as we write them separately // anyway, why do we do that? // Work out where the beginning of the header is. header = payloadData(packet) - nSize; hend = payloadData(packet); // The header size includes only a single channel/type. If we need more, // they have to be added on. const int channelSize = hr.channel > 319 ? 3 : hr.channel > 63 ? 1 : 0; header -= channelSize; hSize += channelSize; /// Add space for absolute timestamp if necessary. if (hr.headerType == RTMP_PACKET_SIZE_LARGE && hr._timestamp >= 0xffffff) { header -= 4; hSize += 4; } hptr = header; c = hr.headerType << 6; switch (channelSize) { case 0: c |= hr.channel; break; case 1: break; case 2: c |= 1; break; } *hptr++ = c; if (channelSize) { const int tmp = hr.channel - 64; *hptr++ = tmp & 0xff; if (channelSize == 2) *hptr++ = tmp >> 8; } if (hr.headerType == RTMP_PACKET_SIZE_LARGE && hr._timestamp >= 0xffffff) { // Signify that the extended timestamp field is present. const std::uint32_t t = 0xffffff; hptr = encodeInt24(hptr, hend, t); } else if (hr.headerType != RTMP_PACKET_SIZE_MINIMUM) { // Write absolute or relative timestamp. Only minimal packets have // no timestamp. hptr = encodeInt24(hptr, hend, hr._timestamp); } /// Encode dataSize and packet type for medium packets. if (nSize > 4) { hptr = encodeInt24(hptr, hend, hr.dataSize); *hptr++ = hr.packetType; } /// Encode streamID for large packets. if (hr.headerType == RTMP_PACKET_SIZE_LARGE) { hptr += encodeInt32LE(hptr, hr._streamID); } // Encode extended absolute timestamp if needed. if (hr.headerType == RTMP_PACKET_SIZE_LARGE && hr._timestamp >= 0xffffff) { hptr += encodeInt32LE(hptr, hr._timestamp); } nSize = hr.dataSize; std::uint8_t *buffer = payloadData(packet); int nChunkSize = _outChunkSize; std::string hx = hexify(header, payloadEnd(packet) - header, false); while (nSize + hSize) { if (nSize < nChunkSize) nChunkSize = nSize; // First write header. if (header) { const int chunk = nChunkSize + hSize; if (_socket.write(header, chunk) != chunk) { return false; } header = nullptr; hSize = 0; } else { // Then write data. if (_socket.write(buffer, nChunkSize) != nChunkSize) { return false; } } nSize -= nChunkSize; buffer += nChunkSize; if (nSize > 0) { header = buffer - 1; hSize = 1; if (channelSize) { header -= channelSize; hSize += channelSize; } *header = (0xc0 | c); if (channelSize) { int tmp = hr.channel - 64; header[1] = tmp & 0xff; if (channelSize == 2) header[2] = tmp >> 8; } } }
void RTMP::handlePacket(const RTMPPacket& packet) { const PacketType t = packet.header.packetType; log_debug("Received %s", t); switch (t) { case PACKET_TYPE_CHUNK_SIZE: handleChangeChunkSize(*this, packet); break; case PACKET_TYPE_BYTES_READ: break; case PACKET_TYPE_CONTROL: handleControl(*this, packet); break; case PACKET_TYPE_SERVERBW: handleServerBW(*this, packet); break; case PACKET_TYPE_CLIENTBW: handleClientBW(*this, packet); break; case PACKET_TYPE_AUDIO: if (!m_mediaChannel) m_mediaChannel = packet.header.channel; break; case PACKET_TYPE_VIDEO: if (!m_mediaChannel) m_mediaChannel = packet.header.channel; break; case PACKET_TYPE_FLEX_STREAM_SEND: LOG_ONCE(log_unimpl(_("unsupported packet received"))); break; case PACKET_TYPE_FLEX_SHARED_OBJECT: LOG_ONCE(log_unimpl(_("unsupported packet received"))); break; case PACKET_TYPE_FLEX_MESSAGE: { LOG_ONCE(log_unimpl(_("partially supported packet %s received"))); _messageQueue.push_back(packet.buffer); break; } case PACKET_TYPE_METADATA: handleMetadata(*this, payloadData(packet), payloadSize(packet)); break; case PACKET_TYPE_SHARED_OBJECT: LOG_ONCE(log_unimpl(_("packet %s received"))); break; case PACKET_TYPE_INVOKE: _messageQueue.push_back(packet.buffer); break; case PACKET_TYPE_FLV: _flvQueue.push_back(packet.buffer); break; default: log_error(_("Unknown packet %s received"), t); } }
FileTransferJob* NetworkPackage::createPayloadTransferJob(const QUrl &destination) const { return new FileTransferJob(payload(), payloadSize(), destination); }