Kea: tcp_stream_msg.h Source File

| Kea 3.2.0-git

tcp_stream_msg.h
Go to the documentation of this file.
1// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef TCP_STREAM_MSG_H
8#define TCP_STREAM_MSG_H
9
10#include <tcp/tcp_connection.h>
11#include <boost/shared_ptr.hpp>
12
13#include <array>
14#include <functional>
15#include <string>
16
17namespace isc {
18namespace tcp {
19
25 class TcpStreamRequest : public TcpRequest {
26public:
28 TcpStreamRequest() : expected_size_(0) {
29 }
30
32 virtual ~TcpStreamRequest() {
33 }
34
40 virtual size_t postBuffer(const void* buf, const size_t nbytes);
41
45 virtual bool needData() const;
46
52 virtual std::string logFormatRequest(const size_t limit = 0) const;
53
55 virtual void unpack();
56
58 size_t getRequestSize() const {
59 return (request_.size());
60 }
61
66 const uint8_t* getRequest() const {
67 if (request_.empty()) {
68 isc_throw(InvalidOperation, "TcpStreamRequest::getRequest()"
69 " - cannot access empty request");
70 }
71
72 return (request_.data());
73 }
74
78 std::string getRequestString() const {
79 return (std::string(request_.begin(), request_.end()));
80 };
81
82protected:
84 std::vector<uint8_t> request_;
85
86private:
88 size_t expected_size_;
89};
90
92 typedef boost::shared_ptr<TcpStreamRequest> TcpStreamRequestPtr;
93
99 class TcpStreamResponse : public TcpResponse {
100public:
102 TcpStreamResponse() {};
103
105 virtual ~TcpStreamResponse() {};
106
111 virtual void setResponseData(const uint8_t* data, size_t length);
112
117 virtual void appendResponseData(const uint8_t* data, size_t length);
118
122 virtual void setResponseData(const std::string& str);
123
127 virtual void appendResponseData(const std::string& str);
128
130 virtual void pack();
131
135 std::string getResponseString() const {
136 return (std::string(response_.begin(), response_.end()));
137 };
138
139private:
141 std::vector<uint8_t> response_;
142
143};
144
146 typedef boost::shared_ptr<TcpStreamResponse> TcpStreamResponsePtr;
147
148} // end of namespace isc::tcp
149} // end of namespace isc
150
151#endif // TCP_STREAM_MSG_H
isc::InvalidOperation
A generic exception that is thrown if a function is called in a prohibited way.
Definition exceptions/exceptions.h:143
isc::tcp::TcpRequest
Abstract class used to receive an inbound message.
Definition tcp_connection.h:58
isc::tcp::TcpResponse::TcpResponse
TcpResponse()
Constructor.
Definition tcp_connection.h:102
isc::tcp::TcpStreamRequest::getRequestString
std::string getRequestString() const
Fetches the unpacked request as a string.
Definition tcp_stream_msg.h:78
isc::tcp::TcpStreamRequest::getRequest
const uint8_t * getRequest() const
Returns pointer to the first byte of the unpacked request data.
Definition tcp_stream_msg.h:66
isc::tcp::TcpStreamRequest::logFormatRequest
virtual std::string logFormatRequest(const size_t limit=0) const
Returns request contents formatted for log output.
Definition tcp_stream_msg.cc:69
isc::tcp::TcpStreamRequest::unpack
virtual void unpack()
Unpacks the wire data into a string request.
Definition tcp_stream_msg.cc:84
isc::tcp::TcpStreamRequest::postBuffer
virtual size_t postBuffer(const void *buf, const size_t nbytes)
Adds data to an incomplete request.
Definition tcp_stream_msg.cc:25
isc::tcp::TcpStreamRequest::needData
virtual bool needData() const
Returns true if the request is incomplete.
Definition tcp_stream_msg.cc:20
isc::tcp::TcpStreamRequest::TcpStreamRequest
TcpStreamRequest()
Constructor.
Definition tcp_stream_msg.h:28
isc::tcp::TcpStreamRequest::getRequestSize
size_t getRequestSize() const
Returns size of the unpacked request.
Definition tcp_stream_msg.h:58
isc::tcp::TcpStreamRequest::request_
std::vector< uint8_t > request_
Unpacked request content.
Definition tcp_stream_msg.h:84
isc::tcp::TcpStreamRequest::~TcpStreamRequest
virtual ~TcpStreamRequest()
Destructor.
Definition tcp_stream_msg.h:32
isc::tcp::TcpStreamResponse::appendResponseData
virtual void appendResponseData(const uint8_t *data, size_t length)
Appends a data to the response content.
Definition tcp_stream_msg.cc:102
isc::tcp::TcpStreamResponse::~TcpStreamResponse
virtual ~TcpStreamResponse()
Destructor.
Definition tcp_stream_msg.h:105
isc::tcp::TcpStreamResponse::setResponseData
virtual void setResponseData(const uint8_t *data, size_t length)
Replaces the response content .
Definition tcp_stream_msg.cc:97
isc::tcp::TcpStreamResponse::getResponseString
std::string getResponseString() const
Fetches the unpacked response as a string.
Definition tcp_stream_msg.h:135
isc::tcp::TcpStreamResponse::pack
virtual void pack()
Packs the response content into wire data buffer.
Definition tcp_stream_msg.cc:117
isc::tcp::TcpStreamResponse::TcpStreamResponse
TcpStreamResponse()
Constructor.
Definition tcp_stream_msg.h:102
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::data
Definition base_stamped_element.cc:12
isc::tcp
Definition mt_tcp_listener_mgr.cc:23
isc::tcp::TcpStreamResponsePtr
boost::shared_ptr< TcpStreamResponse > TcpStreamResponsePtr
Pointer to a TcpStreamResponse.
Definition tcp_stream_msg.h:146
isc::tcp::TcpStreamRequestPtr
boost::shared_ptr< TcpStreamRequest > TcpStreamRequestPtr
Pointer to a TcpStreamRequest.
Definition tcp_stream_msg.h:92
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
tcp_connection.h