QXmpp  Version: 1.4.0
QXmppStream.h
1 /*
2  * Copyright (C) 2008-2021 The QXmpp developers
3  *
4  * Authors:
5  * Manjeet Dahiya
6  * Jeremy LainĂ©
7  *
8  * Source:
9  * https://github.com/qxmpp-project/qxmpp
10  *
11  * This file is a part of QXmpp library.
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  */
24 
25 #ifndef QXMPPSTREAM_H
26 #define QXMPPSTREAM_H
27 
28 #include "QXmppLogger.h"
29 
30 #include <QAbstractSocket>
31 #include <QObject>
32 
33 class QDomElement;
34 class QSslSocket;
35 class QXmppStanza;
36 class QXmppStreamPrivate;
37 
41 class QXMPP_EXPORT QXmppStream : public QXmppLoggable
42 {
43  Q_OBJECT
44 
45 public:
46  QXmppStream(QObject *parent);
47  ~QXmppStream() override;
48 
49  virtual bool isConnected() const;
50  bool sendPacket(const QXmppStanza &);
51 
52  void resetPacketCache();
53 
54 Q_SIGNALS:
56  void connected();
57 
59  void disconnected();
60 
61 protected:
62  // Access to underlying socket
63  QSslSocket *socket() const;
64  void setSocket(QSslSocket *socket);
65 
66  // Overridable methods
67  virtual void handleStart();
68 
72  virtual void handleStanza(const QDomElement &element) = 0;
73 
77  virtual void handleStream(const QDomElement &element) = 0;
78 
79  // XEP-0198: Stream Management
80  void enableStreamManagement(bool resetSequenceNumber);
81  unsigned int lastIncomingSequenceNumber() const;
82  void setAcknowledgedSequenceNumber(unsigned int sequenceNumber);
83 
84 public Q_SLOTS:
85  virtual void disconnectFromHost();
86  virtual bool sendData(const QByteArray &);
87 
88 private Q_SLOTS:
89  void _q_socketConnected();
90  void _q_socketEncrypted();
91  void _q_socketError(QAbstractSocket::SocketError error);
92  void _q_socketReadyRead();
93 
94 private:
95  void processData(const QString &data);
96 
97  friend class tst_QXmppStream;
98 
99  QXmppStreamPrivate *const d;
100 };
101 
102 #endif // QXMPPSTREAM_H
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:124
The QXmppStanza class is the base class for all XMPP stanzas.
Definition: QXmppStanza.h:100
The QXmppStream class is the base class for all XMPP streams.
Definition: QXmppStream.h:42
void connected()
This signal is emitted when the stream is connected.
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