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

source code of qtcoap/src/coap/qcoapqudpconnection_p.h