-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyRemoveOverride.hpp
62 lines (58 loc) · 1.88 KB
/
MyRemoveOverride.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef MY_REMOTE_OVERRIDE
#define MY_REMOTE_OVERRIDE
#include "OpenVPNClientBase.hpp"
#include <openvpn/client/remotelist.hpp>
#include <openvpn/common/hostport.hpp>
namespace libopenvpn
{
using namespace openvpn;
class MyRemoteOverride : public RemoteList::RemoteOverride
{
public:
void set_parent(OpenVPNClientBase *parent_arg)
{
parent = parent_arg;
}
void detach_from_parent()
{
parent = nullptr;
}
virtual RemoteList::Item::Ptr get() override
{
if (parent)
{
const std::string title = "remote-override";
libopenvpn::RemoteOverride ro;
try
{
parent->remote_override(ro);
}
catch (const std::exception &e)
{
ro.error = e.what();
}
RemoteList::Item::Ptr ri(new RemoteList::Item);
if (ro.error.empty())
{
if (!ro.ip.empty())
ri->set_ip_addr(IP::Addr(ro.ip, title));
if (ro.host.empty())
ro.host = ro.ip;
HostPort::validate_host(ro.host, title);
HostPort::validate_port(ro.port, title);
ri->server_host = std::move(ro.host);
ri->server_port = std::move(ro.port);
ri->transport_protocol = Protocol::parse(ro.proto, Protocol::CLIENT_SUFFIX, title.c_str());
}
else
throw Exception("remote override exception: " + ro.error);
return ri;
}
else
return RemoteList::Item::Ptr();
}
private:
OpenVPNClientBase *parent = nullptr;
};
} // namespace openvpn
#endif