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 QCOAPINTERNALREQUEST_H
7#define QCOAPINTERNALREQUEST_H
8
9#include <private/qcoapinternalmessage_p.h>
10#include <private/qcoapnamespace_p.h>
11
12#include <QtCoap/qcoapglobal.h>
13#include <private/qcoapconnection_p.h>
14
15#include <QtCore/qglobal.h>
16#include <QtCore/qtimer.h>
17#include <QtCore/qurl.h>
18
19//
20// W A R N I N G
21// -------------
22//
23// This file is not part of the Qt API. It exists purely as an
24// implementation detail. This header file may change from version to
25// version without notice, or even be removed.
26//
27// We mean it.
28//
29
30QT_BEGIN_NAMESPACE
31
32class QCoapRequest;
33class QCoapInternalRequestPrivate;
34class Q_AUTOTEST_EXPORT QCoapInternalRequest : public QCoapInternalMessage
35{
36 Q_OBJECT
37public:
38 explicit QCoapInternalRequest(QObject *parent = nullptr);
39 explicit QCoapInternalRequest(const QCoapRequest &request, QObject *parent = nullptr);
40
41 bool isValid() const override;
42
43 void initEmptyMessage(quint16 messageId, QCoapMessage::Type type);
44
45 QByteArray toQByteArray() const;
46 void setMessageId(quint16);
47 void setToken(const QCoapToken&);
48 void setToRequestBlock(uint blockNumber, uint blockSize);
49 void setToSendBlock(uint blockNumber, uint blockSize);
50 bool checkBlockNumber(uint blockNumber);
51
52 using QCoapInternalMessage::addOption;
53 void addOption(const QCoapOption &option) override;
54 bool addUriOptions(QUrl uri, const QUrl &proxyUri = QUrl());
55
56 QCoapToken token() const;
57 QUrl targetUri() const;
58 QtCoap::Method method() const;
59 bool isObserve() const;
60 bool isObserveCancelled() const;
61 bool isMulticast() const;
62 QCoapConnection *connection() const;
63 uint retransmissionCounter() const;
64 void setMethod(QtCoap::Method method);
65 void setConnection(QCoapConnection *connection);
66 void setObserveCancelled();
67
68 void setTargetUri(QUrl targetUri);
69 void setTimeout(uint timeout);
70 void setMaxTransmissionWait(uint timeout);
71 void setMulticastTimeout(uint responseDelay);
72 void restartTransmission();
73 void startMulticastTransmission();
74 void stopTransmission();
75
76Q_SIGNALS:
77 void timeout(QCoapInternalRequest*);
78 void maxTransmissionSpanReached(QCoapInternalRequest*);
79 void multicastRequestExpired(QCoapInternalRequest*);
80
81protected:
82 QCoapOption uriHostOption(const QUrl &uri) const;
83 QCoapOption blockOption(QCoapOption::OptionName name, uint blockNumber, uint blockSize) const;
84
85private:
86 Q_DECLARE_PRIVATE(QCoapInternalRequest)
87};
88
89class Q_AUTOTEST_EXPORT QCoapInternalRequestPrivate : public QCoapInternalMessagePrivate
90{
91public:
92 QCoapInternalRequestPrivate() = default;
93
94 QUrl targetUri;
95 QtCoap::Method method = QtCoap::Method::Invalid;
96 QCoapConnection *connection = nullptr;
97 QByteArray fullPayload;
98
99 uint timeout = 0;
100 uint retransmissionCounter = 0;
101 QTimer *timeoutTimer = nullptr;
102 QTimer *maxTransmitWaitTimer = nullptr;
103 QTimer *multicastExpireTimer = nullptr;
104
105 bool observeCancelled = false;
106 bool transmissionInProgress = false;
107
108 Q_DECLARE_PUBLIC(QCoapInternalRequest)
109};
110
111QT_END_NAMESPACE
112
113#endif // QCOAPINTERNALREQUEST_H
114

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