41
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Wrapper for vpnapi
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <cmmanager.h>
|
|
19 |
#include <cmdestination.h>
|
|
20 |
#include <cmpluginvpndef.h>
|
|
21 |
#include "vpnapiwrapper.h"
|
|
22 |
|
|
23 |
#include "log_vpnmanagementui.h"
|
|
24 |
|
|
25 |
using namespace CMManager;
|
|
26 |
|
|
27 |
CVpnApiWrapper* CVpnApiWrapper::NewL()
|
|
28 |
{
|
|
29 |
CVpnApiWrapper* self = new (ELeave) CVpnApiWrapper();
|
|
30 |
CleanupStack::PushL(self);
|
|
31 |
self->ConstructL();
|
|
32 |
CleanupStack::Pop();
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
CVpnApiWrapper::CVpnApiWrapper() :
|
|
37 |
CActive(EPriorityNormal), iOngoingTask(ETaskNone)
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
CVpnApiWrapper::~CVpnApiWrapper()
|
|
42 |
{
|
|
43 |
LOG_("CVpnApiWrapper::~CVpnApiWrapper() called\n");
|
|
44 |
delete iPolicyList;
|
|
45 |
Cancel();
|
|
46 |
|
|
47 |
iVpnExtApi.Close();
|
|
48 |
}
|
|
49 |
|
|
50 |
void CVpnApiWrapper::DoCancel()
|
|
51 |
{
|
|
52 |
LOG_("CVpnApiWrapper::DoCancel() called\n");
|
|
53 |
|
|
54 |
TInt i=iVpnExtApi.CancelPolicyProvision();
|
|
55 |
|
|
56 |
iOngoingTask = ETaskNone;
|
|
57 |
}
|
|
58 |
|
|
59 |
void CVpnApiWrapper::RunL()
|
|
60 |
{
|
|
61 |
LOG_1("CVpnApiWrapper::RunL():%d", iStatus.Int());
|
|
62 |
|
|
63 |
if (iOngoingTask == ETaskSynchroniseServer)
|
|
64 |
{
|
|
65 |
iCaller->NotifySynchroniseServerCompleteL(iStatus.Int());
|
|
66 |
}
|
|
67 |
|
|
68 |
iOngoingTask = ETaskNone;
|
|
69 |
}
|
|
70 |
|
|
71 |
void CVpnApiWrapper::ConstructL()
|
|
72 |
{
|
|
73 |
LOG_("CVpnApiWrapper::ConstructL() - begin");
|
|
74 |
|
|
75 |
CActiveScheduler::Add(this);
|
|
76 |
|
|
77 |
User::LeaveIfError(iVpnExtApi.Connect());
|
|
78 |
LOG_("CVpnApiWrapper::ConstructL() - end");
|
|
79 |
}
|
|
80 |
|
|
81 |
CArrayFixFlat<TVpnPolicyInfo>* CVpnApiWrapper::PolicyListL()
|
|
82 |
{
|
|
83 |
BuildPolicyListL();
|
|
84 |
return iPolicyList;
|
|
85 |
}
|
|
86 |
|
|
87 |
void CVpnApiWrapper::BuildPolicyListL()
|
|
88 |
{
|
|
89 |
LOG_("CVpnApiWrapper::BuildPolicyListL() - begin");
|
|
90 |
|
|
91 |
delete iPolicyList;
|
|
92 |
iPolicyList = NULL;
|
|
93 |
|
|
94 |
iPolicyList = new (ELeave) CArrayFixFlat<TVpnPolicyInfo>(2);
|
|
95 |
|
|
96 |
User::LeaveIfError(iVpnExtApi.GetPolicyInfoList(iPolicyList));
|
|
97 |
|
|
98 |
TKeyArrayFix Key( _FOFF(TVpnPolicyInfo,iName), ECmpCollated );
|
|
99 |
Key.SetPtr( iPolicyList );
|
|
100 |
iPolicyList->Sort( Key );
|
|
101 |
|
|
102 |
LOG_("CVpnApiWrapper::BuildPolicyListL() - end");
|
|
103 |
}
|
|
104 |
|
|
105 |
void CVpnApiWrapper::DeletePolicyL(TInt aPolicyIndex)
|
|
106 |
{
|
|
107 |
LOG_("CVpnApiWrapper::DeletePolicyL() - begin");
|
|
108 |
|
|
109 |
TVpnPolicyId& policyToDelete = iPolicyList->At(aPolicyIndex).iId;
|
|
110 |
User::LeaveIfError(iVpnExtApi.DeletePolicy(policyToDelete));
|
|
111 |
|
|
112 |
//Delete all VPN APs pointing deleted policy
|
|
113 |
DeleteReferringVpnAps(policyToDelete);
|
|
114 |
|
|
115 |
LOG_("CVpnApiWrapper::DeletePolicyL() - end");
|
|
116 |
}
|
|
117 |
|
|
118 |
void CVpnApiWrapper::GetPolicyDetailsL(TInt aPolicyIndex, TVpnPolicyDetails& aPolicyDetails)
|
|
119 |
{
|
|
120 |
LOG_("CVpnApiWrapper::GetPolicyDetailsL() - begin");
|
|
121 |
|
|
122 |
TVpnPolicyId& policyOfInterest = iPolicyList->At(aPolicyIndex).iId;
|
|
123 |
User::LeaveIfError(iVpnExtApi.GetPolicyDetails(policyOfInterest, aPolicyDetails));
|
|
124 |
|
|
125 |
LOG_("CVpnApiWrapper::GetPolicyDetailsL() - end");
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
TInt CVpnApiWrapper::CreateServer( const TAgileProvisionApiServerSettings& aServerDetails)
|
|
131 |
{
|
|
132 |
|
|
133 |
iPolicyServer.iServerNameLocal = aServerDetails.iServerNameLocal;
|
|
134 |
iPolicyServer.iServerUrl = aServerDetails.iServerUrl;
|
|
135 |
iPolicyServer.iSelection = aServerDetails.iSelection;
|
|
136 |
|
|
137 |
return iVpnExtApi.CreateServer(iPolicyServer);
|
|
138 |
}
|
|
139 |
|
|
140 |
TAgileProvisionApiServerListElem& CVpnApiWrapper::ServerListL()
|
|
141 |
{
|
|
142 |
TInt err(iVpnExtApi.ServerListL( iVpnPolicyServerList ));
|
|
143 |
User::LeaveIfError( err );
|
|
144 |
|
|
145 |
return iVpnPolicyServerList;
|
|
146 |
|
|
147 |
}
|
|
148 |
|
|
149 |
void CVpnApiWrapper::GetServerDetailsL( TAgileProvisionApiServerSettings& aServerDetails )
|
|
150 |
{
|
|
151 |
User::LeaveIfError( iVpnExtApi.ServerDetails(aServerDetails));
|
|
152 |
}
|
|
153 |
|
|
154 |
TInt CVpnApiWrapper::DeleteServer()
|
|
155 |
{
|
|
156 |
|
|
157 |
return iVpnExtApi.DeleteServer();
|
|
158 |
|
|
159 |
}
|
|
160 |
|
|
161 |
void CVpnApiWrapper::SynchroniseServerL( MVpnApiWrapperCaller* aCaller )
|
|
162 |
{
|
|
163 |
iCaller=aCaller;
|
|
164 |
iVpnExtApi.SynchronizePolicyServer(iStatus);
|
|
165 |
SetActive();
|
|
166 |
iOngoingTask = ETaskSynchroniseServer;
|
|
167 |
}
|
|
168 |
|
|
169 |
void CVpnApiWrapper::CancelSynchronise()
|
|
170 |
{
|
|
171 |
|
|
172 |
Cancel();
|
|
173 |
|
|
174 |
}
|
|
175 |
|
|
176 |
void CVpnApiWrapper::DeleteReferringVpnAps(const TVpnPolicyId& aPolicyId) const
|
|
177 |
{
|
|
178 |
TRAP_IGNORE(DeleteReferringVpnApsL(aPolicyId));
|
|
179 |
}
|
|
180 |
|
|
181 |
void CVpnApiWrapper::DeleteReferringVpnApsL(const TVpnPolicyId& aPolicyId) const
|
|
182 |
{
|
|
183 |
RCmManager cmManager;
|
|
184 |
cmManager.OpenLC();
|
|
185 |
|
|
186 |
//First collect all VPN connection methods from destinations
|
|
187 |
RArray<TUint32> destinationArray;
|
|
188 |
cmManager.AllDestinationsL( destinationArray );
|
|
189 |
CleanupClosePushL(destinationArray);
|
|
190 |
|
|
191 |
for (TInt i = 0; i < destinationArray.Count(); ++i)
|
|
192 |
{
|
|
193 |
RCmDestination destination = cmManager.DestinationL( destinationArray[i] );
|
|
194 |
CleanupClosePushL(destination);
|
|
195 |
|
|
196 |
TInt connectionMethodCount = destination.ConnectionMethodCount();
|
|
197 |
for (TInt j = connectionMethodCount - 1; j >= 0; --j)
|
|
198 |
{
|
|
199 |
RCmConnectionMethod connectionMethod = destination.ConnectionMethodL( j );
|
|
200 |
CleanupClosePushL(connectionMethod);
|
|
201 |
|
|
202 |
if ( connectionMethod.GetBoolAttributeL(ECmVirtual) &&
|
|
203 |
connectionMethod.GetIntAttributeL( ECmBearerType ) == KPluginVPNBearerTypeUid)
|
|
204 |
{
|
|
205 |
HBufC* policyId = connectionMethod.GetStringAttributeL( EVpnServicePolicy );
|
|
206 |
CleanupStack::PushL(policyId);
|
|
207 |
if (policyId->Compare(aPolicyId) == 0)
|
|
208 |
{
|
|
209 |
destination.DeleteConnectionMethodL( connectionMethod );
|
|
210 |
destination.UpdateL();
|
|
211 |
}
|
|
212 |
CleanupStack::PopAndDestroy(policyId);
|
|
213 |
}
|
|
214 |
CleanupStack::PopAndDestroy(); //connectionMethod
|
|
215 |
}
|
|
216 |
|
|
217 |
CleanupStack::PopAndDestroy(); //destination
|
|
218 |
}
|
|
219 |
CleanupStack::PopAndDestroy(); //destinationArray
|
|
220 |
|
|
221 |
//Second collect VPN connection methods, which are not inside a destination.
|
|
222 |
RArray<TUint32> connectionMethodArray;
|
|
223 |
cmManager.ConnectionMethodL( connectionMethodArray );
|
|
224 |
CleanupClosePushL(connectionMethodArray);
|
|
225 |
|
|
226 |
for ( TInt i = 0; i < connectionMethodArray.Count(); ++i)
|
|
227 |
{
|
|
228 |
RCmConnectionMethod connectionMethod =
|
|
229 |
cmManager.ConnectionMethodL( connectionMethodArray[i] );
|
|
230 |
CleanupClosePushL(connectionMethod);
|
|
231 |
if ( connectionMethod.GetBoolAttributeL(ECmVirtual) &&
|
|
232 |
connectionMethod.GetIntAttributeL( ECmBearerType ) == KPluginVPNBearerTypeUid)
|
|
233 |
{
|
|
234 |
HBufC* policyId = connectionMethod.GetStringAttributeL( EVpnServicePolicy );
|
|
235 |
CleanupStack::PushL(policyId);
|
|
236 |
if (policyId->Compare(aPolicyId) == 0)
|
|
237 |
{
|
|
238 |
connectionMethod.DeleteL();
|
|
239 |
connectionMethod.UpdateL();
|
|
240 |
}
|
|
241 |
CleanupStack::PopAndDestroy(policyId);
|
|
242 |
}
|
|
243 |
|
|
244 |
CleanupStack::PopAndDestroy(); //connectionMethod
|
|
245 |
}
|
|
246 |
CleanupStack::PopAndDestroy(); //connectionMethodArray
|
|
247 |
|
|
248 |
CleanupStack::PopAndDestroy(); //cmManager
|
|
249 |
}
|
|
250 |
/***/
|