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
15
16namespace openvpn {
17
18// Iterate over the lines in a buffer by returning
19// a sub-buffer for each line. Zero-copy.
21{
22 public:
24 : src(buf)
25 {
26 }
27
28 // Returns a zero-length buffer at end of iteration
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
46};
47
48} // namespace openvpn
BufferLineIterator(const ConstBuffer &buf)
const T * c_data() const
Returns a const pointer to the start of the buffer.
Definition buffer.hpp:1194
auto read_alloc_buf(const size_t size)
Allocate memory and read data from the buffer into the allocated memory.
Definition buffer.hpp:1362
size_t size() const
Returns the size of the buffer in T objects.
Definition buffer.hpp:1242