QXmpp Version: 1.5.6
Loading...
Searching...
No Matches
QXmppStream.h
1// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
2// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
6#ifndef QXMPPSTREAM_H
7#define QXMPPSTREAM_H
8
9#include "QXmppLogger.h"
10#include "QXmppSendResult.h"
11
12#include <memory>
13#include <variant>
14
15#include <QAbstractSocket>
16#include <QObject>
17
18class QDomElement;
19template<typename T>
20class QXmppTask;
21template<typename T>
22class QFuture;
23template<typename T>
24class QFutureInterface;
25class QSslSocket;
26class QXmppIq;
27class QXmppNonza;
28class QXmppPacket;
29class QXmppStanza;
30class QXmppStreamPrivate;
31
35class QXMPP_EXPORT QXmppStream : public QXmppLoggable
36{
37 Q_OBJECT
38
39public:
40 QXmppStream(QObject *parent);
41 ~QXmppStream() override;
42
43 virtual bool isConnected() const;
44
45 bool sendPacket(const QXmppNonza &);
47 QXmppTask<QXmpp::SendResult> send(QXmppPacket &&);
48
49 using IqResult = std::variant<QDomElement, QXmppError>;
50 QXmppTask<IqResult> sendIq(QXmppIq &&, const QString &to);
51 QXmppTask<IqResult> sendIq(QXmppPacket &&, const QString &id, const QString &to);
52 void cancelOngoingIqs();
53 bool hasIqId(const QString &id) const;
54
55 void resetPacketCache();
56
57Q_SIGNALS:
59 void connected();
60
63
64protected:
65 // Access to underlying socket
66 QSslSocket *socket() const;
67 void setSocket(QSslSocket *socket);
68
69 // Overridable methods
70 virtual void handleStart();
71
75 virtual void handleStanza(const QDomElement &element) = 0;
76
80 virtual void handleStream(const QDomElement &element) = 0;
81
82 // XEP-0198: Stream Management
83 void enableStreamManagement(bool resetSequenceNumber);
84 unsigned int lastIncomingSequenceNumber() const;
85 void setAcknowledgedSequenceNumber(unsigned int sequenceNumber);
86
87public Q_SLOTS:
88 virtual void disconnectFromHost();
89 virtual bool sendData(const QByteArray &);
90
91private Q_SLOTS:
92 void _q_socketConnected();
93 void _q_socketEncrypted();
94 void _q_socketError(QAbstractSocket::SocketError error);
95 void _q_socketReadyRead();
96
97private:
98 friend class QXmppStreamManager;
99 friend class tst_QXmppStream;
100 friend class TestClient;
101
102 QXmppTask<QXmpp::SendResult> send(QXmppPacket &&, bool &);
103 void processData(const QString &data);
104 bool handleIqResponse(const QDomElement &);
105
106 QXmppStreamPrivate *const d;
107};
108
109#endif // QXMPPSTREAM_H
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:105
Definition QXmppNonza.h:14
The QXmppStanza class is the base class for all XMPP stanzas.
Definition QXmppStanza.h:88
The QXmppStream class is the base class for all XMPP streams.
Definition QXmppStream.h:36
void connected()
This signal is emitted when the stream is connected.
std::variant< QDomElement, QXmppError > IqResult
Definition QXmppStream.h:49
void disconnected()
This signal is emitted when the stream is disconnected.
virtual void handleStream(const QDomElement &element)=0
virtual void handleStanza(const QDomElement &element)=0
Definition QXmppTask.h:62