QXmpp Version: 1.10.0
QXmppStreamManagement_p.h
1// SPDX-FileCopyrightText: 2017 Niels Ole Salscheider <niels_ole@salscheider-online.de>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPSTREAMMANAGEMENT_P_H
6#define QXMPPSTREAMMANAGEMENT_P_H
7
8#include "QXmppGlobal.h"
9#include "QXmppSendResult.h"
10#include "QXmppStanza.h"
11#include "QXmppTask.h"
12
13#include <QDomDocument>
14#include <QXmlStreamWriter>
15
16class QXmppPacket;
17
18namespace QXmpp::Private {
19class XmppSocket;
20}
21
22//
23// W A R N I N G
24// -------------
25//
26// This file is not part of the QXmpp API. It exists for the convenience
27// of the QXmppIncomingClient and QXmppOutgoingClient classes.
28//
29// This header file may change from version to version without notice,
30// or even be removed.
31//
32// We mean it.
33//
34
35namespace QXmpp::Private {
36
37struct SmEnable {
38 static std::optional<SmEnable> fromDom(const QDomElement &);
39 void toXml(QXmlStreamWriter *w) const;
40
41 bool resume = false;
42 quint64 max = 0;
43};
44
45struct SmEnabled {
46 static std::optional<SmEnabled> fromDom(const QDomElement &);
47 void toXml(QXmlStreamWriter *w) const;
48
49 bool resume = false;
50 QString id;
51 quint64 max = 0;
52 QString location;
53};
54
55struct SmResume {
56 static std::optional<SmResume> fromDom(const QDomElement &);
57 void toXml(QXmlStreamWriter *w) const;
58
59 quint32 h = 0;
60 QString previd;
61};
62
63struct SmResumed {
64 static std::optional<SmResumed> fromDom(const QDomElement &);
65 void toXml(QXmlStreamWriter *w) const;
66
67 quint32 h = 0;
68 QString previd;
69};
70
71struct SmFailed {
72 static std::optional<SmFailed> fromDom(const QDomElement &);
73 void toXml(QXmlStreamWriter *w) const;
74
75 std::optional<QXmppStanza::Error::Condition> error;
76};
77
78struct SmAck {
79 static std::optional<SmAck> fromDom(const QDomElement &);
80 void toXml(QXmlStreamWriter *w) const;
81
82 quint32 seqNo = 0;
83};
84
85struct SmRequest {
86 static std::optional<SmRequest> fromDom(const QDomElement &);
87 void toXml(QXmlStreamWriter *w) const;
88};
89
90//
91// This manager handles sending and receiving of stream management acks.
92// Enabling of stream management and stream resumption is done in the C2sStreamManager.
93//
94class StreamAckManager
95{
96public:
97 explicit StreamAckManager(XmppSocket &socket);
98
99 bool enabled() const { return m_enabled; }
100 unsigned int lastIncomingSequenceNumber() const { return m_lastIncomingSequenceNumber; }
101
102 void handlePacketSent(QXmppPacket &packet, bool sentData);
103 bool handleStanza(const QDomElement &stanza);
104 void onSessionClosed();
105
106 void resetCache();
107 void enableStreamManagement(bool resetSequenceNumber);
108 void setAcknowledgedSequenceNumber(unsigned int sequenceNumber);
109
110 QXmppTask<QXmpp::SendResult> send(QXmppPacket &&);
111 bool sendPacketCompat(QXmppPacket &&);
112 std::tuple<bool, QXmppTask<QXmpp::SendResult>> internalSend(QXmppPacket &&);
113
114 void sendAcknowledgementRequest();
115
116private:
117 void handleAcknowledgement(SmAck ack);
118
119 void sendAcknowledgement();
120
121 QXmpp::Private::XmppSocket &socket;
122
123 bool m_enabled = false;
124 QMap<unsigned int, QXmppPacket> m_unacknowledgedStanzas;
125 unsigned int m_lastOutgoingSequenceNumber = 0;
126 unsigned int m_lastIncomingSequenceNumber = 0;
127};
128
129} // namespace QXmpp::Private
130
131#endif
Definition: QXmppTask.h:62