| 1 | // Copyright (C) 2017 Witekio. |
|---|---|
| 2 | // Copyright (C) 2018 The Qt Company Ltd. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 4 | |
| 5 | #ifndef QCOAPQUDPCONNECTION_P_H |
| 6 | #define QCOAPQUDPCONNECTION_P_H |
| 7 | |
| 8 | #include <QtCoap/qcoapsecurityconfiguration.h> |
| 9 | #include <private/qcoapconnection_p.h> |
| 10 | |
| 11 | #include <QtNetwork/qudpsocket.h> |
| 12 | |
| 13 | #include <QtCore/qpointer.h> |
| 14 | #include <QtCore/qqueue.h> |
| 15 | |
| 16 | // |
| 17 | // W A R N I N G |
| 18 | // ------------- |
| 19 | // |
| 20 | // This file is not part of the Qt API. It exists purely as an |
| 21 | // implementation detail. This header file may change from version to |
| 22 | // version without notice, or even be removed. |
| 23 | // |
| 24 | // We mean it. |
| 25 | // |
| 26 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class QDtls; |
| 30 | class QSslPreSharedKeyAuthenticator; |
| 31 | class QCoapQUdpConnectionPrivate; |
| 32 | class Q_AUTOTEST_EXPORT QCoapQUdpConnection : public QCoapConnection |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | public: |
| 37 | explicit QCoapQUdpConnection(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSecurity, |
| 38 | QObject *parent = nullptr); |
| 39 | |
| 40 | ~QCoapQUdpConnection() override = default; |
| 41 | |
| 42 | QUdpSocket *socket() const; |
| 43 | |
| 44 | public Q_SLOTS: |
| 45 | void setSocketOption(QAbstractSocket::SocketOption, const QVariant &value); |
| 46 | |
| 47 | #if QT_CONFIG(dtls) |
| 48 | private Q_SLOTS: |
| 49 | void pskRequired(QSslPreSharedKeyAuthenticator *authenticator); |
| 50 | void handshakeTimeout(); |
| 51 | #endif |
| 52 | |
| 53 | protected: |
| 54 | explicit QCoapQUdpConnection(QCoapQUdpConnectionPrivate &dd, QObject *parent = nullptr); |
| 55 | |
| 56 | void bind(const QString &host, quint16 port) override; |
| 57 | void writeData(const QByteArray &data, const QString &host, quint16 port) override; |
| 58 | void close() override; |
| 59 | |
| 60 | void createSocket(); |
| 61 | |
| 62 | Q_DECLARE_PRIVATE(QCoapQUdpConnection) |
| 63 | }; |
| 64 | |
| 65 | class Q_AUTOTEST_EXPORT QCoapQUdpConnectionPrivate : public QCoapConnectionPrivate |
| 66 | { |
| 67 | public: |
| 68 | QCoapQUdpConnectionPrivate(QtCoap::SecurityMode security = QtCoap::SecurityMode::NoSecurity); |
| 69 | ~QCoapQUdpConnectionPrivate() override; |
| 70 | |
| 71 | virtual bool bind(); |
| 72 | |
| 73 | void bindSocket(); |
| 74 | void writeToSocket(const QByteArray &data, const QString &host, quint16 port); |
| 75 | QUdpSocket* socket() const { return udpSocket; } |
| 76 | void socketReadyRead(); |
| 77 | |
| 78 | void setSecurityConfiguration(const QCoapSecurityConfiguration &configuration); |
| 79 | |
| 80 | #if QT_CONFIG(dtls) |
| 81 | QNetworkDatagram receiveDatagramDecrypted() const; |
| 82 | void handleEncryptedDatagram(); |
| 83 | |
| 84 | QPointer<QDtls> dtls; |
| 85 | #endif |
| 86 | QPointer<QUdpSocket> udpSocket; |
| 87 | |
| 88 | Q_DECLARE_PUBLIC(QCoapQUdpConnection) |
| 89 | }; |
| 90 | |
| 91 | QT_END_NAMESPACE |
| 92 | |
| 93 | #endif // QCOAPQUDPCONNECTION_P_H |
| 94 |
