OpenVPN 3 Core Library
Loading...
Searching...
No Matches
proxyauth.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_PROXY_PROXYAUTH_H
13#define OPENVPN_PROXY_PROXYAUTH_H
14
15#include <vector>
16
17#include <openvpn/common/rc.hpp>
20
21namespace openvpn::HTTPProxy {
22
23// parse the Proxy-Authenticate HTTP header
24class ProxyAuthenticate : public RC<thread_unsafe_refcount>
25{
26 public:
28
29 ProxyAuthenticate() = default;
30
31 ProxyAuthenticate(const std::string &line)
32 {
33 do_parse(line);
34 }
35
36 void parse(const std::string &line)
37 {
38 method = "";
39 parms.clear();
40 do_parse(line);
41 }
42
43 std::string to_string() const
44 {
45 std::ostringstream out;
46 out << "Proxy-Authenticate header\n";
47 out << "method=" << method << '\n';
48 out << parms.to_string();
49 return out.str();
50 }
51
52 std::string method;
54
55 private:
56 void do_parse(const std::string &line)
57 {
58 std::vector<std::string> tuple = Split::by_char<std::vector<std::string>, StandardLex, Split::NullLimit>(line, ' ', 0, 1);
59 if (!tuple.empty())
60 method = tuple[0];
61 if (tuple.size() == 2)
62 {
63 std::vector<std::string> list = Split::by_char<std::vector<std::string>, StandardLex, Split::NullLimit>(tuple[1], ',', Split::TRIM_LEADING_SPACES | Split::TRIM_SPECIAL);
64 for (std::vector<std::string>::const_iterator i = list.begin(); i != list.end(); ++i)
65 {
66 std::vector<std::string> pair = Split::by_char<std::vector<std::string>, StandardLex, Split::NullLimit>(*i, '=', 0, 1);
67 if (pair.size() == 2)
68 parms.push_back(HTTP::Header(pair[0], pair[1]));
69 }
70 }
71 }
72};
73} // namespace openvpn::HTTPProxy
74
75#endif
void parse(const std::string &line)
Definition proxyauth.hpp:36
void do_parse(const std::string &line)
Definition proxyauth.hpp:56
ProxyAuthenticate(const std::string &line)
Definition proxyauth.hpp:31
The smart pointer class.
Definition rc.hpp:119
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
Definition rc.hpp:912
@ TRIM_LEADING_SPACES
Definition split.hpp:34
std::string to_string() const
Definition header.hpp:93
static std::stringstream out
Definition test_path.cpp:10