OpenVPN 3 Core Library
Loading...
Searching...
No Matches
bufstream.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_BUFFER_BUFSTREAM_H
13#define OPENVPN_BUFFER_BUFSTREAM_H
14
15#include <streambuf>
16
18
19namespace openvpn {
20
21class BufferStream : public std::streambuf
22{
23 public:
25 : buf(buffer)
26 {
27 }
28
29 protected:
30#if 0 // not implemented yet
31 // input
32 std::streamsize showmanyc() override;
33 std::streamsize xsgetn(char* s, std::streamsize n) override;
34 int underflow() override;
35 int uflow() override;
36 int pbackfail(int c = EOF) override;
37#endif
38
39 // output
40 std::streamsize xsputn(const char *s, std::streamsize n) override
41 {
42 buf.write((unsigned char *)s, (size_t)n);
43 return n;
44 }
45
46 int overflow(int c = EOF) override
47 {
48 if (c != EOF)
49 {
50 unsigned char uc = (unsigned char)c;
51 buf.push_back(uc);
52 }
53 return c;
54 }
55
56 private:
58};
59
60class BufferStreamOut : public std::ostream
61{
62 public:
64 : std::ostream(new BufferStream(buffer))
65 {
66 }
67
69 {
70 delete rdbuf();
71 }
72};
73
74} // namespace openvpn
75
76#endif
BufferStreamOut(Buffer &buffer)
Definition bufstream.hpp:63
int overflow(int c=EOF) override
Definition bufstream.hpp:46
std::streamsize xsputn(const char *s, std::streamsize n) override
Definition bufstream.hpp:40
BufferStream(Buffer &buffer)
Definition bufstream.hpp:24
void push_back(const T &value)
Append a T object to the end of the array, resizing the array if necessary.
Definition buffer.hpp:1482
void write(const T *data, const size_t size)
Write data to the buffer.
Definition buffer.hpp:1563