Skip to content

Commit

Permalink
Merge branch '1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
lnjX committed Mar 17, 2023
2 parents d679ad1 + 1cf0a4a commit 55362b2
Show file tree
Hide file tree
Showing 15 changed files with 398 additions and 127 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ jobs:
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Install Qt
uses: jurplel/install-qt-action@v2
- name: Run tests
run: |
${env:PATH} += ";D:/a/qxmpp/qxmpp/src/Debug"
cmake . && cmake --build .
# ctest
# ctest --rerun-failed --output-on-failure
xmllint:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion src/base/QXmppMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ void QXmppMessage::serializeExtensions(QXmlStreamWriter *writer, QXmpp::SceMode
writer->writeStartElement(QStringLiteral("encryption"));
writer->writeDefaultNamespace(ns_eme);
writer->writeAttribute(QStringLiteral("namespace"), d->encryptionMethod);
helperToXmlAddAttribute(writer, QStringLiteral("name"), d->encryptionName);
helperToXmlAddAttribute(writer, QStringLiteral("name"), encryptionName());
writer->writeEndElement();
}

Expand Down
18 changes: 13 additions & 5 deletions src/base/QXmppStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ QXmppTask<QXmpp::SendResult> QXmppStream::send(QXmppPacket &&packet, bool &writt
///
/// \since QXmpp 1.5
///
QXmppTask<QXmppStream::IqResult> QXmppStream::sendIq(QXmppIq &&iq)
QXmppTask<QXmppStream::IqResult> QXmppStream::sendIq(QXmppIq &&iq, const QString &to)
{
using namespace QXmpp;

Expand All @@ -212,7 +212,7 @@ QXmppTask<QXmppStream::IqResult> QXmppStream::sendIq(QXmppIq &&iq)
iq.setId(QXmppUtils::generateStanzaUuid());
}

return sendIq(QXmppPacket(iq), iq.id(), iq.to());
return sendIq(QXmppPacket(iq), iq.id(), to);
}

///
Expand Down Expand Up @@ -466,10 +466,18 @@ bool QXmppStream::handleIqResponse(const QDomElement &stanza)
return false;
}

if (auto itr = d->runningIqs.find(stanza.attribute(QStringLiteral("id")));
const auto id = stanza.attribute(QStringLiteral("id"));
if (auto itr = d->runningIqs.find(id);
itr != d->runningIqs.end()) {
if (stanza.attribute("from") != itr.value().jid) {
warning(QStringLiteral("Received IQ response to one of our requests from wrong sender. Ignoring."));
const auto expectedFrom = itr.value().jid;
// Check that the sender of the response matches the recipient of the request.
// Stanzas coming from the server on behalf of the user's account must have no "from"
// attribute or have it set to the user's bare JID.
// If 'from' is empty, the IQ has been sent by the server. In this case we don't need to
// do the check as we trust the server anyways.
if (const auto from = stanza.attribute("from"); !from.isEmpty() && from != expectedFrom) {
warning(QStringLiteral("Ignored received IQ response to request '%1' because of wrong sender '%2' instead of expected sender '%3'")
.arg(id, from, expectedFrom));
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/base/QXmppStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class QXMPP_EXPORT QXmppStream : public QXmppLoggable
QXmppTask<QXmpp::SendResult> send(QXmppPacket &&);

using IqResult = std::variant<QDomElement, QXmppError>;
QXmppTask<IqResult> sendIq(QXmppIq &&);
QXmppTask<IqResult> sendIq(QXmppIq &&, const QString &to);
QXmppTask<IqResult> sendIq(QXmppPacket &&, const QString &id, const QString &to);
void cancelOngoingIqs();
bool hasIqId(const QString &id) const;
Expand Down
5 changes: 2 additions & 3 deletions src/client/QXmppCarbonManagerV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ using namespace QXmpp::Private;
class CarbonEnableIq : public QXmppIq
{
public:
CarbonEnableIq(const QString &jid)
CarbonEnableIq()
: QXmppIq()
{
setTo(jid);
setType(QXmppIq::Set);
}

Expand Down Expand Up @@ -165,7 +164,7 @@ void QXmppCarbonManagerV2::enableCarbons()
return;
}

client()->sendIq(CarbonEnableIq(client()->configuration().jidBare())).then(this, [this](QXmppClient::IqResult domResult) {
client()->sendIq(CarbonEnableIq()).then(this, [this](QXmppClient::IqResult domResult) {
if (auto err = parseIq(std::move(domResult))) {
warning("Could not enable message carbons: " % err->description);
} else {
Expand Down
10 changes: 4 additions & 6 deletions src/client/QXmppIqHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ namespace Private {
iq.parse(element);
iq.setE2eeMetadata(e2eeMetadata);

processHandleIqResult(
client,
iq.id(),
iq.from(),
e2eeMetadata,
invokeIqHandler(std::forward<Handler>(handler), std::move(iq)));
auto id = iq.id(), from = iq.from();

processHandleIqResult(client, id, from, e2eeMetadata,
invokeIqHandler(std::forward<Handler>(handler), std::move(iq)));
return true;
}
return false;
Expand Down
Loading

0 comments on commit 55362b2

Please sign in to comment.