OpenVPN 3 Core Library
Loading...
Searching...
No Matches
pushlex.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
17
18namespace openvpn {
19
25{
26 public:
27 OPENVPN_EXCEPTION(pushlex_error);
28
36 PushLex(const ConstBuffer &buf, const bool discard_prefix)
37 : buf_(buf)
38 {
39 if (!discard_prefix || !defined())
40 return;
41 if (!string::starts_with(buf_, "PUSH_"))
42 throw pushlex_error("not a valid PUSH_x message [1]");
43 buf_.advance(5);
44 while (defined())
45 {
46 const char c = buf_.pop_front();
47 if (c == ',')
48 return;
49 if (c >= 'A' && c <= 'Z')
50 continue;
51 }
52 throw pushlex_error("not a valid PUSH_x message [2]");
53 }
54
61 bool defined() const
62 {
63 return !buf_.empty();
64 }
65
71 std::string next()
72 {
73 StandardLex lex;
74 std::string ret;
75 while (defined())
76 {
77 const char c = buf_.pop_front();
78 lex.put(c);
79 if (lex.get() == ',' && !(lex.in_quote() || lex.in_backslash()))
80 return ret;
81 ret += c;
82 }
83 return ret;
84 }
85
86 private:
88};
89
90} // namespace openvpn
void advance(const size_t delta)
Advances the buffer by the specified delta.
Definition buffer.hpp:1277
bool empty() const
Returns true if the buffer is empty.
Definition buffer.hpp:1236
T pop_front()
Removes and returns the first element from the buffer.
Definition buffer.hpp:1256
bool in_quote() const
Check if currently inside a quote.
Definition lex.hpp:45
PushLex(const ConstBuffer &buf, const bool discard_prefix)
Definition pushlex.hpp:36
bool defined() const
Definition pushlex.hpp:61
ConstBuffer buf_
Definition pushlex.hpp:87
OPENVPN_EXCEPTION(pushlex_error)
std::string next()
Definition pushlex.hpp:71
void put(char c)
Definition lex.hpp:86
bool in_backslash() const
Definition lex.hpp:120
int get() const
Definition lex.hpp:112
bool starts_with(const STRING &str, const std::string &prefix)
Definition string.hpp:79
std::string ret