OpenVPN 3 Core Library
Loading...
Searching...
No Matches
macproxy.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/tun/proxy.hpp>
16
17namespace openvpn {
19{
20 public:
21 OPENVPN_EXCEPTION(macproxy_error);
22
24
25 class Info : public RC<thread_unsafe_refcount>
26 {
27 public:
29
30 Info(CF::DynamicStore &sc, const std::string &sname)
31 : ipv4(sc, sname, "State:/Network/Global/IPv4"),
32 info(sc, sname, "State:/Network/Service/" + sname + "/Info"),
33 proxy(sc, sname, proxies(ipv4.dict, info.dict))
34 {
35 }
36
37 std::string to_string() const
38 {
39 std::ostringstream os;
40 os << ipv4.to_string();
41 os << info.to_string();
42 os << proxy.to_string();
43 return os.str();
44 }
45
49
50 private:
51 static std::string proxies(const CF::Dict &ipv4, const CF::Dict &info)
52 {
53 std::string serv = CF::dict_get_str(ipv4, "PrimaryService");
54 if (serv.empty())
55 serv = CF::dict_get_str(info, "PrimaryService");
56 if (serv.empty())
57 throw macproxy_error("no primary service");
58 return "Setup:/Network/Service/" + serv + "/Proxies";
59 }
60 };
61
63 : ProxySettings(config_arg)
64 {
65 }
66
67 void set_proxy(bool del) override
68 {
69 if (!config.defined())
70 return;
71
72 CF::DynamicStore sc = DSDict::ds_create(sname);
73 Info::Ptr info(new Info(sc, sname));
74
75 info->proxy.will_modify();
76
77 if (!del)
78 {
79 info->proxy.backup_orig("ProxyAutoConfigEnable");
80 CF::dict_set_int(info->proxy.mod, "ProxyAutoConfigEnable", 1);
81
82 info->proxy.backup_orig("ProxyAutoConfigURLString");
83 CF::dict_set_str(info->proxy.mod, "ProxyAutoConfigURLString", config.to_string());
84 }
85 else
86 info->proxy.restore_orig();
87
88 info->proxy.push_to_store();
89
90 OPENVPN_LOG("MacProxy: set_proxy " << info->to_string());
91 }
92};
93} // namespace openvpn
bool push_to_store()
Definition dsdict.hpp:33
static CF::DynamicStore ds_create(const std::string &sname)
Definition dsdict.hpp:145
void will_modify()
Definition dsdict.hpp:66
std::string to_string() const
Definition dsdict.hpp:129
CF::MutableDict mod
Definition dsdict.hpp:164
void restore_orig()
Definition dsdict.hpp:97
void backup_orig(const std::string &key, const bool wipe_orig=true)
Definition dsdict.hpp:77
static std::string proxies(const CF::Dict &ipv4, const CF::Dict &info)
Definition macproxy.hpp:51
Info(CF::DynamicStore &sc, const std::string &sname)
Definition macproxy.hpp:30
std::string to_string() const
Definition macproxy.hpp:37
RCPtr< MacProxySettings > Ptr
Definition macproxy.hpp:23
MacProxySettings(const TunBuilderCapture::ProxyAutoConfigURL &config_arg)
Definition macproxy.hpp:62
OPENVPN_EXCEPTION(macproxy_error)
void set_proxy(bool del) override
Definition macproxy.hpp:67
const std::string sname
Definition proxy.hpp:74
TunBuilderCapture::ProxyAutoConfigURL config
Definition proxy.hpp:76
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
Class for handling Proxy Auto-Configuration (PAC) URLs.
Definition capture.hpp:403
bool defined() const
Checks if the URL is defined.
Definition capture.hpp:421
std::string to_string() const
Returns the URL as a string.
Definition capture.hpp:411
#define OPENVPN_LOG(args)
void dict_set_int(MutableDict &dict, const KEY &key, int value)
Definition cfhelper.hpp:173
void dict_set_str(MutableDict &dict, const KEY &key, const VALUE &value)
Definition cfhelper.hpp:163
std::string dict_get_str(const DICT &dict, const KEY &key)
Definition cfhelper.hpp:95
std::ostringstream os