QXmpp  Version: 1.7.1
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 
10 class QDomElement;
11 class QSslSocket;
12 class TestStream;
13 
14 namespace QXmpp::Private {
15 
16 class SendDataInterface
17 {
18 public:
19  virtual bool sendData(const QByteArray &) = 0;
20 };
21 
22 class QXMPP_EXPORT XmppSocket : public QXmppLoggable, public SendDataInterface
23 {
24  Q_OBJECT
25 public:
26  XmppSocket(QObject *parent);
27  ~XmppSocket() override = default;
28 
29  QSslSocket *socket() const { return m_socket; }
30  void setSocket(QSslSocket *socket);
31 
32  bool isConnected() const;
33  void disconnectFromHost();
34  bool sendData(const QByteArray &) override;
35 
36  Q_SIGNAL void started();
37  Q_SIGNAL void stanzaReceived(const QDomElement &);
38  Q_SIGNAL void streamReceived(const QDomElement &);
39  Q_SIGNAL void streamClosed();
40 
41 private:
42  void processData(const QString &data);
43 
44  friend class ::TestStream;
45 
46  QString m_dataBuffer;
47  QSslSocket *m_socket = nullptr;
48 
49  // incoming stream state
50  QString m_streamOpenElement;
51 };
52 
53 } // namespace QXmpp::Private
54 
55 #endif // XMPPSOCKET_H
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110