OpenVPN 3 Core Library
Loading...
Searching...
No Matches
buflineiter.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
#pragma once
13
14
#include <
openvpn/buffer/buffer.hpp
>
15
16
namespace
openvpn
{
17
18
// Iterate over the lines in a buffer by returning
19
// a sub-buffer for each line. Zero-copy.
20
class
BufferLineIterator
21
{
22
public
:
23
BufferLineIterator
(
const
ConstBuffer
&buf)
24
:
src
(buf)
25
{
26
}
27
28
// Returns a zero-length buffer at end of iteration
29
ConstBuffer
next
()
30
{
31
return
src
.
read_alloc_buf
(
line_len
());
32
}
33
34
private
:
35
size_t
line_len
()
const
36
{
37
const
unsigned
char
*
const
data =
src
.
c_data
();
38
size_t
i = 0;
39
while
(i <
src
.
size
())
40
if
(data[i++] ==
'\n'
)
41
break
;
42
return
i;
43
}
44
45
ConstBuffer
src
;
46
};
47
48
}
// namespace openvpn
buffer.hpp
openvpn::BufferLineIterator
Definition
buflineiter.hpp:21
openvpn::BufferLineIterator::next
ConstBuffer next()
Definition
buflineiter.hpp:29
openvpn::BufferLineIterator::line_len
size_t line_len() const
Definition
buflineiter.hpp:35
openvpn::BufferLineIterator::src
ConstBuffer src
Definition
buflineiter.hpp:45
openvpn::BufferLineIterator::BufferLineIterator
BufferLineIterator(const ConstBuffer &buf)
Definition
buflineiter.hpp:23
openvpn::ConstBufferType< unsigned char >
openvpn::ConstBufferType::c_data
const T * c_data() const
Returns a const pointer to the start of the buffer.
Definition
buffer.hpp:1194
openvpn::ConstBufferType::read_alloc_buf
auto read_alloc_buf(const size_t size)
Allocate memory and read data from the buffer into the allocated memory.
Definition
buffer.hpp:1362
openvpn::ConstBufferType::size
size_t size() const
Returns the size of the buffer in T objects.
Definition
buffer.hpp:1242
openvpn
Definition
ovpncli.cpp:97
openvpn
buffer
buflineiter.hpp
Generated by
1.9.8