QXmpp Version: 1.10.0
XmppSocket.h
1// SPDX-FileCopyrightText: 2024 Linus Jahn <lnj@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef XMPPSOCKET_H
6#define XMPPSOCKET_H
7
8#include "QXmppLogger.h"
9
10class QDomElement;
11class QSslSocket;
12class TestStream;
13class tst_QXmppStream;
14
15namespace QXmpp::Private {
16
17struct ServerAddress {
18 enum ConnectionType {
19 Tcp,
20 Tls,
21 };
22
23 ConnectionType type;
24 QString host;
25 quint16 port;
26};
27
28class SendDataInterface
29{
30public:
31 virtual bool sendData(const QByteArray &) = 0;
32};
33
34class QXMPP_EXPORT XmppSocket : public QXmppLoggable, public SendDataInterface
35{
36 Q_OBJECT
37public:
38 XmppSocket(QObject *parent);
39 ~XmppSocket() override = default;
40
41 QSslSocket *socket() const { return m_socket; }
42 void setSocket(QSslSocket *socket);
43
44 bool isConnected() const;
45 void connectToHost(const ServerAddress &);
46 void disconnectFromHost();
47 bool sendData(const QByteArray &) override;
48
49 Q_SIGNAL void started();
50 Q_SIGNAL void stanzaReceived(const QDomElement &);
51 Q_SIGNAL void streamReceived(const QDomElement &);
52 Q_SIGNAL void streamClosed();
53
54private:
55 void processData(const QString &data);
56
57 friend class ::tst_QXmppStream;
58
59 QString m_dataBuffer;
60 bool m_directTls = false;
61 QSslSocket *m_socket = nullptr;
62
63 // incoming stream state
64 QString m_streamOpenElement;
65};
66
67} // namespace QXmpp::Private
68
69#endif // XMPPSOCKET_H
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110