-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyClientEvents.hpp
73 lines (66 loc) · 2.19 KB
/
MyClientEvents.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
63
64
65
66
67
68
69
70
71
72
73
#ifndef MY_CLIENT_EVENTS_H
#define MY_CLIENT_EVENTS_H
#include "OpenVPNClientBase.hpp"
#include <openvpn/common/rc.hpp>
#include <openvpn/common/count.hpp>
#include <openvpn/client/clievent.hpp>
namespace libopenvpn
{
using namespace openvpn;
class MyClientEvents : public ClientEvent::Queue
{
public:
typedef RCPtr<MyClientEvents> Ptr;
MyClientEvents(OpenVPNClientBase *parent_arg) : parent(parent_arg) {}
virtual void add_event(ClientEvent::Base::Ptr event) override
{
if (parent)
{
Event ev;
ev.name = event->name();
ev.info = event->render();
ev.error = event->is_error();
ev.fatal = event->is_fatal();
// save connected event
if (event->id() == ClientEvent::CONNECTED)
last_connected = std::move(event);
else if (event->id() == ClientEvent::DISCONNECTED)
parent->on_disconnect();
parent->event(ev);
}
}
void get_connection_info(ConnectionInfo &ci)
{
ClientEvent::Base::Ptr connected = last_connected;
if (connected)
{
const ClientEvent::Connected *c = connected->connected_cast();
if (c)
{
ci.user = c->user;
ci.serverHost = c->server_host;
ci.serverPort = c->server_port;
ci.serverProto = c->server_proto;
ci.serverIp = c->server_ip;
ci.vpnIp4 = c->vpn_ip4;
ci.vpnIp6 = c->vpn_ip6;
ci.gw4 = c->vpn_gw4;
ci.gw6 = c->vpn_gw6;
ci.clientIp = c->client_ip;
ci.tunName = c->tun_name;
ci.defined = true;
return;
}
}
ci.defined = false;
}
void detach_from_parent()
{
parent = nullptr;
}
private:
OpenVPNClientBase *parent;
ClientEvent::Base::Ptr last_connected;
};
} // namespace libopenvpn
#endif