Kea  2.5.2
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 
17 namespace isc {
18 namespace tcp {
19 
25 class TcpStreamRequest : public TcpRequest {
26 public:
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 
82 protected:
84  std::vector<uint8_t> request_;
85 
86 private:
88  size_t expected_size_;
89 };
90 
92 typedef boost::shared_ptr<TcpStreamRequest> TcpStreamRequestPtr;
93 
100 public:
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 
139 private:
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
A generic exception that is thrown if a function is called in a prohibited way.
Abstract class used to receive an inbound message.
Abstract class used to create and send an outbound response.
Implement a simple length:data input stream message.
std::string getRequestString() const
Fetches the unpacked request as a string.
const uint8_t * getRequest() const
Returns pointer to the first byte of the unpacked request data.
virtual std::string logFormatRequest(const size_t limit=0) const
Returns request contents formatted for log output.
virtual void unpack()
Unpacks the wire data into a string request.
virtual size_t postBuffer(const void *buf, const size_t nbytes)
Adds data to an incomplete request.
virtual bool needData() const
Returns true if the request is incomplete.
TcpStreamRequest()
Constructor.
size_t getRequestSize() const
Returns size of the unpacked request.
std::vector< uint8_t > request_
Unpacked request content.
virtual ~TcpStreamRequest()
Destructor.
Implements a simple length:data output stream message.
virtual void appendResponseData(const uint8_t *data, size_t length)
Appends a data to the response content.
virtual ~TcpStreamResponse()
Destructor.
virtual void setResponseData(const uint8_t *data, size_t length)
Replaces the response content .
std::string getResponseString() const
Fetches the unpacked response as a string.
virtual void pack()
Packs the response content into wire data buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< TcpStreamResponse > TcpStreamResponsePtr
Pointer to a TcpStreamResponse.
boost::shared_ptr< TcpStreamRequest > TcpStreamRequestPtr
Pointer to a TcpStreamRequest.
Defines the logger used by the top-level component of kea-lfc.