1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 | // Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef TCP_STREAM_MSG_H
#define TCP_STREAM_MSG_H
#include <tcp/tcp_connection.h>
#include <boost/shared_ptr.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <array><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <functional><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
namespace isc {
namespace tcp {
/// @brief Implement a simple length:data input stream message.
///
/// This class can be used to receive a single message from a TCP
/// stream where the message consists of a 16-bit unsigned length (in
/// network order), followed by that number of bytes of data.
class TcpStreamRequest : public TcpRequest {
public:
/// @brief Constructor.
TcpStreamRequest() : expected_size_(0) {
}
/// @brief Destructor
virtual ~TcpStreamRequest() {<--- Destructor in derived class
}
/// @brief Adds data to an incomplete request
///
/// @param buf A pointer to the buffer holding the data.
/// @param nbytes Size of the data within the buffer.
/// @return number of bytes posted (consumed)
virtual size_t postBuffer(const void* buf, const size_t nbytes);<--- Function in derived class
/// @brief Returns true if the request is incomplete.
///
/// @return true if the request is incomplete.
virtual bool needData() const;<--- Function in derived class
/// @brief Returns request contents formatted for log output
///
/// @param limit Maximum length of the buffer to be output. If the limit
/// is 0, the length of the output is unlimited.
/// @return Textual representation of the input buffer.
virtual std::string logFormatRequest(const size_t limit = 0) const;<--- Function in derived class
/// @brief Unpacks the wire data into a string request.
virtual void unpack();<--- Function in derived class
/// @brief Returns size of the unpacked request.
size_t getRequestSize() const {
return (request_.size());
}
/// @brief Returns pointer to the first byte of the unpacked request data.
///
/// @return Constant raw pointer to the data.
/// @throw InvalidOperation if request data is empty (i.e. getRequestSize() == 0).
const uint8_t* getRequest() const {
if (request_.empty()) {
isc_throw(InvalidOperation, "TcpStreamRequest::getRequest()"
" - cannot access empty request");
}
return (request_.data());
}
/// @brief Fetches the unpacked request as a string.
///
/// @return String containing the unpacked contents.
std::string getRequestString() const {
return (std::string(request_.begin(), request_.end()));
};
protected:
/// @brief Unpacked request content
std::vector<uint8_t> request_;
private:
/// @brief Expected size of the current message.
size_t expected_size_;
};
/// @brief Pointer to a TcpStreamRequest.
typedef boost::shared_ptr<TcpStreamRequest> TcpStreamRequestPtr;
/// @brief Implements a simple length:data output stream message.
///
/// This class can be used to send a single message on a TCP
/// stream where the message consists of a 16-bit unsigned length (in
/// network order), followed by that number of bytes of data.
class TcpStreamResponse : public TcpResponse {
public:
/// @brief Constructor.
TcpStreamResponse() {};
/// @brief Destructor.
virtual ~TcpStreamResponse() {};<--- Destructor in derived class
/// @brief Replaces the response content .
///
/// @param data New contents for the output buffer.
/// @param length Length of the contents to add.
virtual void setResponseData(const uint8_t* data, size_t length);
/// @brief Appends a data to the response content.
///
/// @param data Data to append to the response.
/// @param length Length of the contents to add.
virtual void appendResponseData(const uint8_t* data, size_t length);
/// @brief Replaces the response content from a string.
///
/// @param str New contents for the output buffer.
virtual void setResponseData(const std::string& str);
/// @brief Appends a string to the response content.
///
/// @param str contents to add to the output buffer.
virtual void appendResponseData(const std::string& str);
/// @brief Packs the response content into wire data buffer.
virtual void pack();<--- Function in derived class
/// @brief Fetches the unpacked response as a string.
///
/// @return String containing the unpacked contents.
std::string getResponseString() const {
return (std::string(response_.begin(), response_.end()));
};
private:
/// @brief Unpacked response data to send.
std::vector<uint8_t> response_;
};
/// @brief Pointer to a TcpStreamResponse.
typedef boost::shared_ptr<TcpStreamResponse> TcpStreamResponsePtr;
} // end of namespace isc::tcp
} // end of namespace isc
#endif // TCP_STREAM_MSG_H
|