diff --git a/src/irisnet/noncore/icelocaltransport.cpp b/src/irisnet/noncore/icelocaltransport.cpp index b0eb4870..9c69079d 100644 --- a/src/irisnet/noncore/icelocaltransport.cpp +++ b/src/irisnet/noncore/icelocaltransport.cpp @@ -434,7 +434,7 @@ private slots: QByteArray buf = sock->readDatagram(from); if (buf.isEmpty()) // it's weird we ever came here, but should relax static analyzer break; - qDebug("got packet from %s", qPrintable(from)); + // qDebug("got packet from %s", qPrintable(from)); if (from == stunBindAddr || from == stunRelayAddr) { bool haveData = processIncomingStun(buf, from, &dg); diff --git a/src/xmpp/xmpp-core/protocol.cpp b/src/xmpp/xmpp-core/protocol.cpp index 9cb3aca3..85e4cd71 100644 --- a/src/xmpp/xmpp-core/protocol.cpp +++ b/src/xmpp/xmpp-core/protocol.cpp @@ -34,6 +34,7 @@ using namespace XMPP; +#ifdef XMPP_TEST // printArray // // This function prints out an array of bytes as latin characters, converting @@ -52,6 +53,7 @@ static QString printArray(const QByteArray &a) } return s; } +#endif // firstChildElement // @@ -787,6 +789,8 @@ void CoreProtocol::stringSend(const QString &s) { #ifdef XMPP_TEST TD::outgoingTag(s); +#else + Q_UNUSED(s) #endif } @@ -794,6 +798,8 @@ void CoreProtocol::stringRecv(const QString &s) { #ifdef XMPP_TEST TD::incomingTag(s); +#else + Q_UNUSED(s) #endif } @@ -848,6 +854,8 @@ void CoreProtocol::elementSend(const QDomElement &e) { #ifdef XMPP_TEST TD::outgoingXml(e); +#else + Q_UNUSED(e) #endif } @@ -855,6 +863,8 @@ void CoreProtocol::elementRecv(const QDomElement &e) { #ifdef XMPP_TEST TD::incomingXml(e); +#else + Q_UNUSED(e) #endif } diff --git a/src/xmpp/xmpp-im/client.cpp b/src/xmpp/xmpp-im/client.cpp index 8b9b1792..4bcbb83f 100644 --- a/src/xmpp/xmpp-im/client.cpp +++ b/src/xmpp/xmpp-im/client.cpp @@ -525,7 +525,7 @@ void Client::streamReadyRead() debug(QString("Client: incoming: [\n%1]\n").arg(out)); emit xmlIncoming(out); - QDomElement x = s.element(); // oldStyleNS(s.element()); + QDomElement x = s.element(); distribute(x); } } diff --git a/src/xmpp/xmpp-im/jingle-connection.cpp b/src/xmpp/xmpp-im/jingle-connection.cpp index a030c890..3bdd7a96 100644 --- a/src/xmpp/xmpp-im/jingle-connection.cpp +++ b/src/xmpp/xmpp-im/jingle-connection.cpp @@ -23,14 +23,14 @@ namespace XMPP { namespace Jingle { bool Connection::hasPendingDatagrams() const { return false; } - NetworkDatagram Connection::readDatagram(qint64 maxSize) + QNetworkDatagram Connection::readDatagram(qint64 maxSize) { qCritical("Calling unimplemented function receiveDatagram"); Q_UNUSED(maxSize) - return NetworkDatagram(); + return QNetworkDatagram(); } - bool Connection::writeDatagram(const NetworkDatagram &) + bool Connection::writeDatagram(const QNetworkDatagram &) { qCritical("Calling unimplemented function sendDatagram"); return false; diff --git a/src/xmpp/xmpp-im/jingle-connection.h b/src/xmpp/xmpp-im/jingle-connection.h index 486026d1..6b5e9f5e 100644 --- a/src/xmpp/xmpp-im/jingle-connection.h +++ b/src/xmpp/xmpp-im/jingle-connection.h @@ -28,41 +28,17 @@ #include "iris/bytestream.h" #include "jingle.h" -#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) #include -#else -#include -#endif namespace XMPP { namespace Jingle { -#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0) - // stub implementation - class NetworkDatagram { - public: - bool _valid = false; - QByteArray _data; - inline NetworkDatagram(const QByteArray &data, const QHostAddress &destinationAddress = QHostAddress(), - quint16 port = 0) : _valid(true), _data(data) - { - Q_UNUSED(destinationAddress); - Q_UNUSED(port) - } - inline NetworkDatagram() { } - - inline bool isValid() const { return _valid; } - inline QByteArray data() const { return _data; } - }; -#else - typedef QNetworkDatagram NetworkDatagram; -#endif class Connection : public ByteStream { Q_OBJECT public: using Ptr = QSharedPointer; // will be shared between transport and application virtual bool hasPendingDatagrams() const; - virtual NetworkDatagram readDatagram(qint64 maxSize = -1); - virtual bool writeDatagram(const NetworkDatagram &data); + virtual QNetworkDatagram readDatagram(qint64 maxSize = -1); + virtual bool writeDatagram(const QNetworkDatagram &data); virtual size_t blockSize() const; virtual int component() const; virtual TransportFeatures features() const = 0; diff --git a/src/xmpp/xmpp-im/jingle-file.cpp b/src/xmpp/xmpp-im/jingle-file.cpp index 29724e3f..3cff1607 100644 --- a/src/xmpp/xmpp-im/jingle-file.cpp +++ b/src/xmpp/xmpp-im/jingle-file.cpp @@ -65,17 +65,16 @@ QDomElement Range::toXml(QDomDocument *doc) const //---------------------------------------------------------------------------- class File::Private : public QSharedData { public: - bool rangeSupported = false; - bool hasSize = false; - QDateTime date; - QString mediaType; - QString name; - QString desc; - std::uint64_t size = 0; - Range range; - QList hashes; - Thumbnail thumbnail; - QByteArray amplitudes; + bool rangeSupported = false; + QDateTime date; + QString mediaType; + QString name; + QString desc; + std::optional size = 0; + Range range; + QList hashes; + Thumbnail thumbnail; + QByteArray amplitudes; }; File::File() { } @@ -92,17 +91,16 @@ File::File(const File &other) : d(other.d) { } File::File(const QDomElement &file) { - QDateTime date; - QString mediaType; - QString name; - QString desc; - std::uint64_t size = 0; - bool rangeSupported = false; - bool hasSize = false; - Range range; - QList hashes; - Thumbnail thumbnail; - QByteArray amplitudes; + QDateTime date; + QString mediaType; + QString name; + QString desc; + std::optional size = 0; + bool rangeSupported = false; + Range range; + QList hashes; + Thumbnail thumbnail; + QByteArray amplitudes; bool ok; @@ -125,7 +123,6 @@ File::File(const QDomElement &file) if (!ok) { return; } - hasSize = true; } else if (ce.tagName() == RANGE_TAG) { if (ce.hasAttribute(QLatin1String("offset"))) { @@ -188,7 +185,6 @@ File::File(const QDomElement &file) p->desc = desc; p->size = size; p->rangeSupported = rangeSupported; - p->hasSize = hasSize; p->range = range; p->hashes = hashes; p->thumbnail = thumbnail; @@ -218,8 +214,8 @@ QDomElement File::toXml(QDomDocument *doc) const if (d->name.size()) { el.appendChild(XMLHelper::textTag(*doc, NAME_TAG, d->name)); } - if (d->hasSize) { - el.appendChild(XMLHelper::textTag(*doc, SIZE_TAG, qint64(d->size))); + if (d->size) { + el.appendChild(XMLHelper::textTag(*doc, SIZE_TAG, qint64(*d->size))); } if (d->rangeSupported || d->range.isValid()) { el.appendChild(d->range.toXml(doc)); @@ -261,8 +257,6 @@ bool File::hasComputedHashes() const return false; } -bool File::hasSize() const { return d->hasSize; } - QDateTime File::date() const { return d ? d->date : QDateTime(); } QString File::description() const { return d ? d->desc : QString(); } @@ -298,7 +292,7 @@ QString File::mediaType() const { return d ? d->mediaType : QString(); } QString File::name() const { return d ? d->name : QString(); } -std::uint64_t File::size() const { return d ? d->size : 0; } +std::optional File::size() const { return d ? d->size : std::optional {}; } Range File::range() const { return d ? d->range : Range(); } @@ -318,11 +312,7 @@ void File::setMediaType(const QString &mediaType) { ensureD()->mediaType = media void File::setName(const QString &name) { ensureD()->name = name; } -void File::setSize(std::uint64_t size) -{ - ensureD()->size = size; - d->hasSize = true; -} +void File::setSize(std::uint64_t size) { ensureD()->size = size; } void File::setRange(const Range &range) { diff --git a/src/xmpp/xmpp-im/jingle-file.h b/src/xmpp/xmpp-im/jingle-file.h index 9bcb0dfd..982c2b82 100644 --- a/src/xmpp/xmpp-im/jingle-file.h +++ b/src/xmpp/xmpp-im/jingle-file.h @@ -28,13 +28,13 @@ namespace XMPP::Jingle::FileTransfer { struct Range { - std::int64_t offset = 0; - std::int64_t length = 0; // 0 - from offset to the end of the file - QList hashes; + std::uint64_t offset = 0; // 0 - default value from spec even when not set. + std::uint64_t length = 0; // 0 - from offset to the end of the file + QList hashes; inline Range() { } - inline Range(std::int64_t offset, std::int64_t length) : offset(offset), length(length) { } - inline bool isValid() const { return hashes.size() || offset || length; } + inline Range(std::uint64_t offset, std::uint64_t length) : offset(offset), length(length) { } + inline bool isValid() const { return offset || length; } inline operator bool() const { return isValid(); } QDomElement toXml(QDomDocument *doc) const; }; @@ -50,19 +50,18 @@ class File { QDomElement toXml(QDomDocument *doc) const; bool merge(const File &other); bool hasComputedHashes() const; - bool hasSize() const; - QDateTime date() const; - QString description() const; - QList hashes() const; - QList computedHashes() const; - Hash hash(Hash::Type t = Hash::Unknown) const; - QString mediaType() const; - QString name() const; - uint64_t size() const; - Range range() const; - Thumbnail thumbnail() const; - QByteArray amplitudes() const; + QDateTime date() const; + QString description() const; + QList hashes() const; + QList computedHashes() const; + Hash hash(Hash::Type t = Hash::Unknown) const; + QString mediaType() const; + QString name() const; + std::optional size() const; + Range range() const; + Thumbnail thumbnail() const; + QByteArray amplitudes() const; void setDate(const QDateTime &date); void setDescription(const QString &desc); diff --git a/src/xmpp/xmpp-im/jingle-ft.cpp b/src/xmpp/xmpp-im/jingle-ft.cpp index b63a60b7..d1fcad9f 100644 --- a/src/xmpp/xmpp-im/jingle-ft.cpp +++ b/src/xmpp/xmpp-im/jingle-ft.cpp @@ -24,7 +24,6 @@ #include "xmpp_client.h" #include "xmpp_hash.h" #include "xmpp_thumbs.h" -#include "xmpp_xmlcommon.h" #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include @@ -37,8 +36,8 @@ #include #include #include + #include -#include #include using namespace std::chrono_literals; @@ -134,21 +133,21 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { Reason updateReason; // Action updateToSend = Action::NoAction; - bool closeDeviceOnFinish = true; - bool streamingMode = false; - bool endlessRange = false; // where range in accepted file doesn't have end - bool outgoingReceived = false; - File file; - File acceptFile; // as it comes with "accept" response - XMPP::Stanza::Error lastError; - Reason lastReason; - Connection::Ptr connection; - QIODevice *device = nullptr; - qint64 bytesLeft = 0; - QList outgoingChecksum; - QList incomingChecksum; - QTimer *finalizeTimer = nullptr; - FileHasher *hasher = nullptr; + bool closeDeviceOnFinish = true; + bool streamingMode = false; + // bool endlessRange = false; // where range in accepted file doesn't have end + bool outgoingReceived = false; + File file; + File acceptFile; // as it comes with "accept" response + XMPP::Stanza::Error lastError; + Reason lastReason; + Connection::Ptr connection; + QIODevice *device = nullptr; + std::optional bytesLeft; + QList outgoingChecksum; + QList incomingChecksum; + QTimer *finalizeTimer = nullptr; + FileHasher *hasher = nullptr; void setState(State s) { @@ -218,7 +217,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { void writeNextBlockToTransport() { - if (!(endlessRange || bytesLeft)) { + if (bytesLeft && *bytesLeft == 0) { if (hasher) { auto hash = hasher->result(); if (hash.isValid()) { @@ -232,8 +231,8 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { } auto sz = qint64(connection->blockSize()); sz = sz ? sz : 8192; - if (!endlessRange && sz > bytesLeft) { - sz = bytesLeft; + if (bytesLeft && sz > *bytesLeft) { + sz = *bytesLeft; } QByteArray data; if (device->isSequential()) { @@ -244,7 +243,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { data = device->read(sz); } if (data.isEmpty()) { - if (endlessRange) { + if (!bytesLeft) { lastReason = Reason(Reason::Condition::Success); if (hasher) { auto hash = hasher->result(); @@ -276,20 +275,23 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { } } emit q->progress(device->pos()); - bytesLeft -= data.size(); + if (bytesLeft) { + *bytesLeft -= data.size(); + } } void readNextBlockFromTransport() { qint64 bytesAvail; - while (bytesLeft && ((bytesAvail = connection->bytesAvailable()) || (connection->hasPendingDatagrams()))) { + while ((!bytesLeft || *bytesLeft > 0) + && ((bytesAvail = connection->bytesAvailable()) || (connection->hasPendingDatagrams()))) { QByteArray data; if (connection->features() & TransportFeature::MessageOriented) { data = connection->readDatagram().data(); } else { qint64 sz = 65536; // shall we respect transport->blockSize() ? - if (sz > bytesLeft) { - sz = bytesLeft; + if (bytesLeft && sz > *bytesLeft) { + sz = *bytesLeft; } if (sz > bytesAvail) { sz = bytesAvail; @@ -309,9 +311,11 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { return; } emit q->progress(device->pos()); - bytesLeft -= data.size(); + if (bytesLeft) { + *bytesLeft -= data.size(); + } } - if (!bytesLeft) { + if (bytesLeft && *bytesLeft == 0) { tryFinalizeIncoming(); } } @@ -321,18 +325,20 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { void onConnectionConnected(Connection::Ptr newConnection) { - qDebug("jingle-ft: connected. ready to send user data"); + qDebug("jingle-ft: connected. ready to transfer user data"); connection = newConnection; lastReason = Reason(); lastError.reset(); if (streamingMode) { + qDebug("streaming mode is active. giving up with handling on our own"); setState(State::Active); emit q->connectionReady(); return; } connect(connection.data(), &Connection::readyRead, q, [this]() { + qDebug("Connection::readyRead"); if (!device) { return; } @@ -343,6 +349,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { connect( connection.data(), &Connection::bytesWritten, q, [this](qint64 bytes) { + qDebug("Connection::bytesWritten"); Q_UNUSED(bytes) if (q->pad()->session()->role() == q->senders() && !connection->bytesToWrite()) { writeNextBlockToTransport(); @@ -356,9 +363,9 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { setState(State::Active); if (acceptFile.range().isValid()) { - bytesLeft = acceptFile.range().length; - if (!bytesLeft) - endlessRange = true; + if (acceptFile.range().length) { + bytesLeft = acceptFile.range().length; + } emit q->deviceRequested(acceptFile.range().offset, bytesLeft); } else { bytesLeft = acceptFile.size(); @@ -370,7 +377,7 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { { if (q->_state == State::Finished || outgoingReceived || streamingMode) return; - if (connection->isOpen() && bytesLeft) + if (connection->isOpen() && (!bytesLeft || *bytesLeft > 0)) return; // data read finished. check other stuff diff --git a/src/xmpp/xmpp-im/jingle-ft.h b/src/xmpp/xmpp-im/jingle-ft.h index 589622cb..c230f293 100644 --- a/src/xmpp/xmpp-im/jingle-ft.h +++ b/src/xmpp/xmpp-im/jingle-ft.h @@ -128,8 +128,8 @@ namespace XMPP { namespace Jingle { namespace FileTransfer { void connectionReady(); // streaming mode only // if size = 0 then it's reamaining part of the file (non-streaming mode only) - void deviceRequested(qint64 offset, qint64 size); - void progress(qint64 offset); + void deviceRequested(quint64 offset, std::optional size); + void progress(quint64 offset); private: class Private; diff --git a/src/xmpp/xmpp-im/jingle-ice.cpp b/src/xmpp/xmpp-im/jingle-ice.cpp index f60a49f4..0046d5c4 100644 --- a/src/xmpp/xmpp-im/jingle-ice.cpp +++ b/src/xmpp/xmpp-im/jingle-ice.cpp @@ -362,9 +362,9 @@ namespace XMPP { namespace Jingle { namespace ICE { enum DisconnectReason { None, DtlsClosed }; - QList datagrams; - DisconnectReason disconnectReason = None; - quint8 componentIndex = 0; + QList datagrams; + DisconnectReason disconnectReason = None; + quint8 componentIndex = 0; RawConnection(quint8 componentIndex) : componentIndex(componentIndex) {}; @@ -378,10 +378,10 @@ namespace XMPP { namespace Jingle { namespace ICE { bool hasPendingDatagrams() const override { return datagrams.size() > 0; } - NetworkDatagram readDatagram(qint64 maxSize = -1) override + QNetworkDatagram readDatagram(qint64 maxSize = -1) override { Q_UNUSED(maxSize) // TODO or not? - return datagrams.size() ? datagrams.takeFirst() : NetworkDatagram(); + return datagrams.size() ? datagrams.takeFirst() : QNetworkDatagram(); } qint64 bytesAvailable() const override { return 0; } @@ -412,7 +412,7 @@ namespace XMPP { namespace Jingle { namespace ICE { void enqueueIncomingUDP(const QByteArray &data) { - datagrams.append(NetworkDatagram { data }); + datagrams.append(QNetworkDatagram { data }); emit readyRead(); } }; @@ -523,7 +523,7 @@ namespace XMPP { namespace Jingle { namespace ICE { if (componentIndex == 0) { // for other components it's the same but we don't need multiple fingerprints dtls->connect( dtls, &Dtls::needRestart, q, - [this, componentIndex]() { + [this]() { pendingActions |= NewFingerprint; remoteAcceptedFingerprint = false; emit q->updated(); @@ -536,6 +536,7 @@ namespace XMPP { namespace Jingle { namespace ICE { auto d = component.dtls->readDatagram(); #ifdef JINGLE_SCTP if (component.sctp) { + // qDebug("sctp write incoming"); component.sctp->writeIncoming(d); } #endif @@ -544,6 +545,7 @@ namespace XMPP { namespace Jingle { namespace ICE { ice->writeDatagram(componentIndex, components[componentIndex].dtls->readOutgoingDatagram()); }); dtls->connect(dtls, &Dtls::connected, q, [this, componentIndex, dtls]() { + qDebug("Dtls::connected"); auto &c = components[componentIndex]; #ifdef JINGLE_SCTP if (c.sctp) { @@ -726,7 +728,6 @@ namespace XMPP { namespace Jingle { namespace ICE { }, Qt::QueuedConnection); // signal is not DOR-SS q->connect(ice, &Ice176::readyRead, q, [this](int componentIndex) { - // qDebug("ICE readyRead"); auto buf = ice->readDatagram(componentIndex); auto &component = components[componentIndex]; if (component.dtls) { diff --git a/src/xmpp/xmpp-im/jingle-s5b.cpp b/src/xmpp/xmpp-im/jingle-s5b.cpp index 929041bf..42df2809 100644 --- a/src/xmpp/xmpp-im/jingle-s5b.cpp +++ b/src/xmpp/xmpp-im/jingle-s5b.cpp @@ -50,9 +50,9 @@ namespace XMPP { namespace Jingle { namespace S5B { class Connection : public XMPP::Jingle::Connection { Q_OBJECT - QList datagrams; - SocksClient *client = nullptr; - Transport::Mode mode = Transport::Tcp; + QList datagrams; + SocksClient *client = nullptr; + Transport::Mode mode = Transport::Tcp; public: void setSocksClient(SocksClient *client, Transport::Mode mode) @@ -80,10 +80,10 @@ namespace XMPP { namespace Jingle { namespace S5B { bool hasPendingDatagrams() const { return datagrams.size() > 0; } - NetworkDatagram readDatagram(qint64 maxSize = -1) + QNetworkDatagram readDatagram(qint64 maxSize = -1) { Q_UNUSED(maxSize) // TODO or not? - return datagrams.size() ? datagrams.takeFirst() : NetworkDatagram(); + return datagrams.size() ? datagrams.takeFirst() : QNetworkDatagram(); } qint64 bytesAvailable() const @@ -128,7 +128,7 @@ namespace XMPP { namespace Jingle { namespace S5B { friend class Transport; void enqueueIncomingUDP(const QByteArray &data) { - datagrams.append(NetworkDatagram { data }); + datagrams.append(QNetworkDatagram { data }); emit readyRead(); } }; @@ -1561,7 +1561,7 @@ namespace XMPP { namespace Jingle { namespace S5B { tel.setAttribute(QStringLiteral("dstaddr"), dstaddr); } if (!candidatesToSend.isEmpty()) { - upd = makeUpdate(tel, false, [this, candidatesToSend, initial](Task *jt) mutable { + upd = makeUpdate(tel, false, [this, candidatesToSend](Task *jt) mutable { if (jt->success()) { for (auto &c : candidatesToSend) { if (c.state() == Candidate::Unacked) { diff --git a/src/xmpp/xmpp-im/jingle-sctp-association_p.cpp b/src/xmpp/xmpp-im/jingle-sctp-association_p.cpp index cba6c7f1..02be72dd 100644 --- a/src/xmpp/xmpp-im/jingle-sctp-association_p.cpp +++ b/src/xmpp/xmpp-im/jingle-sctp-association_p.cpp @@ -157,9 +157,8 @@ namespace XMPP { namespace Jingle { namespace SCTP { consumer.sctpParameters.maxPacketLifeTime = reliable == PartialTimers ? reliability : 0; consumer.sctpParameters.maxRetransmits = reliable == PartialRexmit ? reliability : 0; bool success; - assoc.SendSctpMessage( - &consumer, ppid, reinterpret_cast(data.data()), data.size(), - new std::function([this, &success](bool cb_success) { success = cb_success; })); + assoc.SendSctpMessage(&consumer, ppid, reinterpret_cast(data.data()), data.size(), + new std::function([&success](bool cb_success) { success = cb_success; })); return success; } diff --git a/src/xmpp/xmpp-im/jingle-transport.cpp b/src/xmpp/xmpp-im/jingle-transport.cpp index 434ebea6..938fd7d4 100644 --- a/src/xmpp/xmpp-im/jingle-transport.cpp +++ b/src/xmpp/xmpp-im/jingle-transport.cpp @@ -86,6 +86,7 @@ namespace XMPP { namespace Jingle { bool Transport::notifyIncomingConnection(Connection::Ptr connection) const { + qDebug("Transport::notifyIncomingConnection"); for (auto const &acceptor : _connectionAcceptors) { if ((connection->features() & acceptor.features) == acceptor.features && (acceptor.componentIndex < 0 || acceptor.componentIndex == connection->component()) diff --git a/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.cpp b/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.cpp index 501d641e..452baa72 100644 --- a/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.cpp +++ b/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.cpp @@ -108,13 +108,18 @@ namespace XMPP { namespace Jingle { namespace SCTP { bool WebRTCDataChannel::hasPendingDatagrams() const { return datagrams.size() > 0; } - NetworkDatagram WebRTCDataChannel::readDatagram(qint64 maxSize) + QNetworkDatagram WebRTCDataChannel::readDatagram(qint64 maxSize) { Q_UNUSED(maxSize) // TODO or not? - return datagrams.size() ? datagrams.takeFirst() : NetworkDatagram(); + if (datagrams.size()) { + auto dg = datagrams.takeFirst(); + _bytesAvailable -= dg.data().size(); + return dg; + } + return {}; } - bool WebRTCDataChannel::writeDatagram(const NetworkDatagram &data) + bool WebRTCDataChannel::writeDatagram(const QNetworkDatagram &data) { Q_ASSERT(bool(outgoingCallback)); outgoingBufSize += data.data().size(); @@ -122,10 +127,36 @@ namespace XMPP { namespace Jingle { namespace SCTP { return true; } - qint64 WebRTCDataChannel::bytesAvailable() const { return 0; } + qint64 WebRTCDataChannel::bytesAvailable() const { return _bytesAvailable; } qint64 WebRTCDataChannel::bytesToWrite() const { return 0; /*client->bytesToWrite();*/ } + qint64 WebRTCDataChannel::readData(char *buf, qint64 sz) + { + if (sz <= tail.size()) { + std::memcpy(buf, tail.data(), sz); + tail.remove(0, sz); + return sz; + } + sz -= tail.size(); + qint64 actualRet = tail.size(); + std::memcpy(buf, tail.data(), tail.size()); + while (sz > 0 && !datagrams.isEmpty()) { + auto dg = datagrams.takeFirst(); + auto data = dg.data(); + auto dataSz = std::min(sz, data.size()); + std::memcpy(buf + actualRet, data.data(), dataSz); + actualRet += dataSz; + data.remove(0, dataSz); + if (data.size()) { + tail = data; + return actualRet; + } + sz -= dataSz; + } + return actualRet; + } + void WebRTCDataChannel::close() { XMPP::Jingle::Connection::close(); } TransportFeatures WebRTCDataChannel::features() const @@ -172,7 +203,8 @@ namespace XMPP { namespace Jingle { namespace SCTP { return; } // check other PPIDs. - datagrams.append(NetworkDatagram { data }); + datagrams.append(QNetworkDatagram { data }); + _bytesAvailable += data.size(); emit readyRead(); } diff --git a/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.h b/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.h index 031d30c7..0560bd58 100644 --- a/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.h +++ b/src/xmpp/xmpp-im/jingle-webrtc-datachannel_p.h @@ -49,11 +49,15 @@ namespace XMPP { namespace Jingle { namespace SCTP { using OutgoingCallback = std::function; - AssociationPrivate *association; - QList datagrams; - DisconnectReason disconnectReason = ChannelClosed; - std::size_t outgoingBufSize = 0; - OutgoingCallback outgoingCallback; + AssociationPrivate *association; + + QList datagrams; + quint64 _bytesAvailable = 0; + QByteArray tail; + + DisconnectReason disconnectReason = ChannelClosed; + std::size_t outgoingBufSize = 0; + OutgoingCallback outgoingCallback; quint8 channelType = 0; quint32 reliability = 0; @@ -73,9 +77,10 @@ namespace XMPP { namespace Jingle { namespace SCTP { void setOutgoingCallback(OutgoingCallback &&callback); bool hasPendingDatagrams() const override; - NetworkDatagram readDatagram(qint64 maxSize = -1) override; - bool writeDatagram(const NetworkDatagram &data) override; + QNetworkDatagram readDatagram(qint64 maxSize = -1) override; + bool writeDatagram(const QNetworkDatagram &data) override; qint64 bytesAvailable() const override; + qint64 readData(char *buf, qint64 sz); qint64 bytesToWrite() const override; void close() override; TransportFeatures features() const override; diff --git a/src/xmpp/xmpp-im/types.cpp b/src/xmpp/xmpp-im/types.cpp index 09058f44..488d9d81 100644 --- a/src/xmpp/xmpp-im/types.cpp +++ b/src/xmpp/xmpp-im/types.cpp @@ -1054,7 +1054,7 @@ QString Message::mucPassword() const { return d ? d->mucPassword : QString(); } void Message::setMUCPassword(const QString &p) { MessageD()->mucPassword = p; } -bool Message::hasMUCUser() const { return d & d->hasMUCUser; } +bool Message::hasMUCUser() const { return d && d->hasMUCUser; } Message::StanzaId Message::stanzaId() const { return d ? d->stanzaId : StanzaId(); } diff --git a/src/xmpp/xmpp-im/xmpp_externalservicediscovery.cpp b/src/xmpp/xmpp-im/xmpp_externalservicediscovery.cpp index c598b9e6..c5354e41 100644 --- a/src/xmpp/xmpp-im/xmpp_externalservicediscovery.cpp +++ b/src/xmpp/xmpp-im/xmpp_externalservicediscovery.cpp @@ -194,8 +194,7 @@ void ExternalServiceDiscovery::services(QObject *ctx, ServicesCallback &&callbac } else { auto task = new JT_ExternalServiceDiscovery(client_->rootTask()); auto type = types[0]; - connect(task, &Task::finished, ctx, - [this, task, type, cb = std::move(callback)]() { cb(task->services()); }); + connect(task, &Task::finished, ctx, [task, type, cb = std::move(callback)]() { cb(task->services()); }); task->getServices(type); task->go(true); // in fact we can improve caching even more if start remembering specific repviously requested types, @@ -221,8 +220,7 @@ void ExternalServiceDiscovery::credentials(QObject *ctx, ServicesCallback &&call const QSet &ids) { auto task = new JT_ExternalServiceDiscovery(client_->rootTask()); - connect(task, &Task::finished, ctx ? ctx : this, - [this, task, cb = std::move(callback)]() { cb(task->services()); }); + connect(task, &Task::finished, ctx ? ctx : this, [task, cb = std::move(callback)]() { cb(task->services()); }); task->getCredentials(ids); task->go(true); } diff --git a/src/xmpp/xmpp-im/xmpp_hash.cpp b/src/xmpp/xmpp-im/xmpp_hash.cpp index decfb0e4..f820a251 100644 --- a/src/xmpp/xmpp-im/xmpp_hash.cpp +++ b/src/xmpp/xmpp-im/xmpp_hash.cpp @@ -278,7 +278,7 @@ Hash Hash::fastestHash(const Features &features) + QLatin1String(hashTypes[int(t)].text)); // REVIEW modify hashTypes with priority info instead? } - for (int i = 0; i < qcaAlgos.size(); i++) { + for (std::size_t i = 0; i < qcaAlgos.size(); i++) { if (QCA::isSupported(qcaAlgos[i]) && features.test(priorityFeatures[i])) { return Hash(qcaMap[i]); } diff --git a/src/xmpp/xmpp-im/xmpp_tasks.cpp b/src/xmpp/xmpp-im/xmpp_tasks.cpp index 608b3c4d..55ded37d 100644 --- a/src/xmpp/xmpp-im/xmpp_tasks.cpp +++ b/src/xmpp/xmpp-im/xmpp_tasks.cpp @@ -786,43 +786,6 @@ bool JT_PushPresence::take(const QDomElement &e) //---------------------------------------------------------------------------- // JT_Message //---------------------------------------------------------------------------- -static QDomElement oldStyleNS(const QDomElement &e) -{ - // find closest parent with a namespace - QDomNode par = e.parentNode(); - while (!par.isNull() && par.namespaceURI().isNull()) - par = par.parentNode(); - bool noShowNS = false; - if (!par.isNull() && par.namespaceURI() == e.namespaceURI()) - noShowNS = true; - - QDomElement i; - int x; - // if(noShowNS) - i = e.ownerDocument().createElement(e.tagName()); - // else - // i = e.ownerDocument().createElementNS(e.namespaceURI(), e.tagName()); - - // copy attributes - QDomNamedNodeMap al = e.attributes(); - for (x = 0; x < al.count(); ++x) - i.setAttributeNode(al.item(x).cloneNode().toAttr()); - - if (!noShowNS) - i.setAttribute("xmlns", e.namespaceURI()); - - // copy children - QDomNodeList nl = e.childNodes(); - for (x = 0; x < nl.count(); ++x) { - QDomNode n = nl.item(x); - if (n.isElement()) - i.appendChild(oldStyleNS(n.toElement())); - else - i.appendChild(n.cloneNode()); - } - return i; -} - JT_Message::JT_Message(Task *parent, Message &msg) : Task(parent), m(msg) { if (msg.id().isEmpty()) @@ -835,7 +798,7 @@ void JT_Message::onGo() { Stanza s = m.toStanza(&(client()->stream())); - QDomElement e = s.element(); // oldStyleNS(s.element()); + QDomElement e = s.element(); if (auto encryptionHandler = client()->encryptionHandler()) { Q_UNUSED(encryptionHandler->encryptMessageElement(e));