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

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