summaryrefslogtreecommitdiffstats
path: root/knetworkmanager-0.8/src/knetworkmanager-vpn_plugin.cpp
blob: f56b22113b4d766967b38657c3b59f802301ade6 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *
 * knetworkmanager-vpn_plugin.cpp - A NetworkManager frontend for KDE 
 *
 * Copyright (C) 2005, 2006 Novell, Inc.
 *
 * Author: Helmut Schaa <hschaa@suse.de>, <Helmut.Schaa@gmx.de>
 * Author: Timothy Pearson <kb9vqf@pearsoncomputing.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/

// KDE includes
#include <kdebug.h>

// TQt includes
#include <tqhostaddress.h>

// TQT_DBus includes
#include <tqdbuserror.h>
#include <tqdbusconnection.h>
#include <tqdbusobjectpath.h>

// NM includes
#include <NetworkManager.h>
#include <NetworkManagerVPN.h>

// KNM includes
#include "knetworkmanager.h"
#include "knetworkmanager-tray.h"
#include "knetworkmanager-vpn_plugin.h"
#include "dbus/vpnpluginproxy.h"
#include "knetworkmanager-hal_device_proxy.h"
#include "knetworkmanager-nm_proxy.h"

#if !defined(NM_CHECK_VERSION)
#define NM_CHECK_VERSION(x,y,z) 0
#endif

unsigned int current_vpn_state = 0;
extern NMDeviceState nm_device_state_global;
extern TQT_DBusObjectPath vpn_attempt_this_conn;
unsigned char vpn_new_credentials_needed = 0;

class VPNDBUSPluginPrivate
{
public:
	VPNDBUSPluginPrivate(TQString service, TQString obj_path)
		: nmVPNDBUS(service, obj_path)
	{}
	~VPNDBUSPluginPrivate() {}

	DBus::VPNPluginProxy nmVPNDBUS;
};

TQ_UINT32 VPNDBUSPlugin::getState()
{
	TQT_DBusError err;
	return d->nmVPNDBUS.getState(err);
}

void VPNDBUSPlugin::slotStateChanged(TQ_UINT32 state)
{
	current_vpn_state = state+1;
	Tray* tray = Tray::getInstance();
	tray->slotUpdateDeviceState(nm_device_state_global);
	//emit StateChanged((NMDeviceState)state);
}

void VPNDBUSPlugin::slotLoginBanner(const TQString& banner)
{
	Tray* tray = Tray::getInstance();
	tray->slotVPNBannerShow(banner);
}

void VPNDBUSPlugin::slotFailure(TQ_UINT32 failure_reason)
{
	printf("VPN failure code %d\n\r", failure_reason);

	if ((failure_reason == 0) || (failure_reason == 1) || (failure_reason == 2)) {
		// Try to connect again using cached information; request new login though
		printf("Reactivate VPN connection on default device\n\r");
		vpn_new_credentials_needed = 1;
		int id;
		TQT_DBusError err;
		NMProxy* nm = NMProxy::getInstance();
		TQT_DBusObjectPath act_conn = nm->getDefaultActiveConnection();
		TQT_DBusObjectPath device   = nm->getDeviceForActiveConnection(act_conn);
#if NM_CHECK_VERSION(0,8,992)
		nm->ActivateConnectionAsync(id,"org.freedesktop.NetworkManagerUserSettings", vpn_attempt_this_conn, device, act_conn, err);
#else
		nm->ActivateConnectionAsync(id,NM_DBUS_SERVICE_USER_SETTINGS, vpn_attempt_this_conn, device, act_conn, err);
#endif
	}
}

VPNDBUSPlugin::VPNDBUSPlugin ()
	: TQObject()
{
	d = new VPNDBUSPluginPrivate(NM_VPN_DBUS_PLUGIN_INTERFACE, NM_VPN_DBUS_PLUGIN_PATH);
	d->nmVPNDBUS.setConnection(TQT_DBusConnection::systemBus());

	// Connect the state changed signal to the handler
	connect(&(d->nmVPNDBUS), TQT_SIGNAL(StateChanged(TQ_UINT32)), this, TQT_SLOT(slotStateChanged(TQ_UINT32)));

	// Connect the failure signal to the handler
	connect(&(d->nmVPNDBUS), TQT_SIGNAL(Failure(TQ_UINT32)), this, TQT_SLOT(slotFailure(TQ_UINT32)));

	// And the banner signal
	connect(&(d->nmVPNDBUS), TQT_SIGNAL(LoginBanner(const TQString&)), this, TQT_SLOT(slotLoginBanner(const TQString&)));
}

VPNDBUSPlugin::~VPNDBUSPlugin ()
{
	delete d;
}


#include "knetworkmanager-vpn_plugin.moc"