7#ifndef QXMPPOUTGOINGCLIENT_H
8#define QXMPPOUTGOINGCLIENT_H
10#include "QXmppAuthenticationError.h"
11#include "QXmppBindError.h"
12#include "QXmppClient.h"
13#include "QXmppPromise.h"
14#include "QXmppStanza.h"
15#include "QXmppStreamError.h"
17#include <QAbstractSocket>
28class QXmppOutgoingClientPrivate;
31namespace QXmpp::Private {
32class C2sStreamManager;
35class OutgoingIqManager;
37class SendDataInterface;
38class StreamAckManager;
45struct StreamErrorElement;
47enum HandleElementResult {
53enum class AuthenticationMethod {
63 bool fastTokenChanged;
64 AuthenticationMethod authenticationMethod;
72namespace QXmpp::Private::Sasl2 {
84 using IqResult = std::variant<QDomElement, QXmppError>;
85 using ConnectionError = std::variant<QAbstractSocket::SocketError, QXmpp::TimeoutError, QXmpp::StreamError, QXmpp::AuthenticationError, QXmpp::BindError>;
87 explicit QXmppOutgoingClient(QObject *parent);
88 ~QXmppOutgoingClient()
override;
91 void disconnectFromHost();
92 bool isAuthenticated()
const;
93 bool isConnected()
const;
97 QSslSocket *socket()
const;
102 QXmpp::Private::XmppSocket &xmppSocket()
const;
103 QXmpp::Private::StreamAckManager &streamAckManager()
const;
104 QXmpp::Private::OutgoingIqManager &iqManager()
const;
105 QXmpp::Private::C2sStreamManager &c2sStreamManager()
const;
106 QXmpp::Private::CarbonManager &carbonManager()
const;
107 QXmpp::Private::CsiManager &csiManager()
const;
110 Q_SIGNAL
void connected(
const QXmpp::Private::SessionBegin &);
113 Q_SIGNAL
void disconnected(
const QXmpp::Private::SessionEnd &);
116 Q_SIGNAL
void errorOccurred(
const QString &text,
const QXmppOutgoingClient::ConnectionError &details,
QXmppClient::Error oldError);
119 Q_SIGNAL
void elementReceived(
const QDomElement &element,
bool &handled);
129 Q_SIGNAL
void iqReceived(
const QXmppIq &);
132 Q_SIGNAL
void sslErrors(
const QList<QSslError> &errors);
136 void handleStream(
const QDomElement &element);
137 void handlePacketReceived(
const QDomElement &element);
138 QXmpp::Private::HandleElementResult handleElement(
const QDomElement &nodeRecv);
140 void handleStreamError(
const QXmpp::Private::StreamErrorElement &streamError);
141 bool handleStanza(
const QDomElement &);
144 void _q_socketDisconnected();
145 void socketError(QAbstractSocket::SocketError);
146 void socketSslErrors(
const QList<QSslError> &);
148 void startSasl2Auth(
const QXmpp::Private::Sasl2::StreamFeature &sasl2Feature);
149 void startNonSaslAuth();
150 void startSmResume();
151 void startSmEnable();
152 void startResourceBinding();
155 void setError(
const QString &text, ConnectionError &&details);
156 void throwKeepAliveError();
159 void enableStreamManagement(
bool resetSequenceNumber);
160 bool handleIqResponse(
const QDomElement &);
162 friend class QXmppOutgoingClientPrivate;
163 friend class QXmpp::Private::PingManager;
164 friend class QXmpp::Private::C2sStreamManager;
166 friend class TestClient;
168 const std::unique_ptr<QXmppOutgoingClientPrivate> d;
171namespace QXmpp::Private {
173class C2sStreamManager
176 using Result = std::variant<Success, QXmppError>;
178 explicit C2sStreamManager(QXmppOutgoingClient *q);
180 HandleElementResult handleElement(
const QDomElement &);
181 bool hasResumeAddress()
const {
return m_canResume && !m_resumeHost.isEmpty() && m_resumePort; }
182 std::pair<QString, quint16> resumeAddress()
const {
return { m_resumeHost, m_resumePort }; }
183 void onStreamStart();
185 void onStreamClosed();
186 void onSasl2Authenticate(Sasl2::Authenticate &auth,
const Sasl2::StreamFeature &feature);
187 void onSasl2Success(
const Sasl2::Success &success);
188 void onBind2Request(Bind2Request &request,
const std::vector<QString> &bind2Features);
189 void onBind2Bound(
const Bind2Bound &);
190 bool canResume()
const {
return m_canResume; }
191 bool enabled()
const {
return m_enabled; }
192 bool streamResumed()
const {
return m_streamResumed; }
193 bool canRequestResume()
const {
return m_smAvailable && !m_enabled && m_canResume; }
195 bool canRequestEnable()
const {
return m_smAvailable && !m_enabled; }
199 friend class ::TestClient;
201 void onEnabled(
const SmEnabled &enabled);
202 void onEnableFailed(
const SmFailed &failed);
203 void onResumed(
const SmResumed &resumed);
204 void onResumeFailed(
const SmFailed &failed);
205 bool setResumeAddress(
const QString &address);
206 void setEnabled(
bool enabled) { m_enabled = enabled; }
207 void setResumed(
bool resumed) { m_streamResumed = resumed; }
209 struct NoRequest { };
210 struct ResumeRequest {
213 struct EnableRequest {
217 QXmppOutgoingClient *q;
219 std::variant<NoRequest, ResumeRequest, EnableRequest> m_request;
220 bool m_smAvailable =
false;
222 bool m_canResume =
false;
223 QString m_resumeHost;
224 quint16 m_resumePort = 0;
225 bool m_enabled =
false;
226 bool m_streamResumed =
false;
233 void setEnableViaBind2(
bool enable) { m_enableViaBind2 = enable; }
234 bool enabled()
const {
return m_enabled; }
235 void onBind2Request(Bind2Request &request,
const std::vector<QString> &bind2Features);
236 void onSessionOpened(
const SessionBegin &session);
240 bool m_enableViaBind2 =
false;
242 bool m_enabled =
false;
243 bool m_requested =
false;
255 explicit CsiManager(QXmppOutgoingClient *client);
257 State state()
const {
return m_state; }
258 void setState(State);
259 void onSessionOpened(
const SessionBegin &);
261 void onBind2Request(Bind2Request &request,
const std::vector<QString> &bind2Features);
266 QXmppOutgoingClient *m_client;
267 State m_state = Active;
268 bool m_synced =
true;
269 bool m_featureAvailable =
false;
270 bool m_bind2InactiveSet =
false;
Error
Definition: QXmppClient.h:76
The QXmppConfiguration class holds configuration options.
Definition: QXmppConfiguration.h:37
The QXmppIq class is the base class for all IQs.
Definition: QXmppIq.h:23
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:64
The QXmppPresence class represents an XMPP presence stanza.
Definition: QXmppPresence.h:22
The QXmppRegistrationManager class manages in-band registration and account management tasks like cha...
Definition: QXmppRegistrationManager.h:225
Condition
A detailed condition of the error.
Definition: QXmppStanza.h:110
The QXmppStreamFeatures class represents the features returned by an XMPP server or client.
Definition: QXmppStreamFeatures.h:23
Definition: QXmppTask.h:62