|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of CDmAdStore. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "DmAdStore.h" |
|
21 #include "DmAdRtNodeData.h" |
|
22 #include "dmadutil.h" |
|
23 #include "vpnlogger.h" |
|
24 |
|
25 #include <vpnlogmessages.rsg> |
|
26 |
|
27 CDmAdStore* CDmAdStore::NewL(void) |
|
28 { |
|
29 TRACE("CDmAdStore::NewL"); |
|
30 |
|
31 CDmAdStore *self = new (ELeave) CDmAdStore(); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(); // self |
|
35 return self; |
|
36 } |
|
37 |
|
38 void CDmAdStore::ConstructL(void) |
|
39 { |
|
40 TRACE("CDmAdStore::ConstructL"); |
|
41 |
|
42 INIT_EVENT_LOGGER; |
|
43 |
|
44 User::LeaveIfError(iVpnApi.Connect()); |
|
45 iVpnAp = CVpnAp::NewL(); |
|
46 } |
|
47 |
|
48 CDmAdStore::CDmAdStore() |
|
49 { |
|
50 } |
|
51 |
|
52 CDmAdStore::~CDmAdStore() |
|
53 { |
|
54 TRACE("CDmAdStore::~CDmAdStore"); |
|
55 |
|
56 iVpnApi.Close(); |
|
57 delete iVpnAp; |
|
58 |
|
59 RELEASE_EVENT_LOGGER; |
|
60 } |
|
61 |
|
62 TBool CDmAdStore::FindRtNodeL(const TDesC8& aLuid, const TDesC8& aUri) |
|
63 { |
|
64 TRACE("CDmAdStore::FindRtNodeL"); |
|
65 |
|
66 TDmAdUriType uriType = CDmAdRtNodeData::UriTypeL(aUri); |
|
67 switch (uriType) |
|
68 { |
|
69 case EDmAdUriTypeVpnAp: |
|
70 return VpnApFindRtNodeL(aLuid, aUri); |
|
71 case EDmAdUriTypePolicy: |
|
72 return PolicyFindRtNodeL(aLuid, aUri); |
|
73 default: |
|
74 DEBUG_LOG(_L("Unknown URI type")); |
|
75 User::Leave(KErrGeneral); |
|
76 return EFalse; |
|
77 } |
|
78 } |
|
79 |
|
80 void CDmAdStore::LuidListL(const TDesC8& aUri, const TDesC8& /*aLuid*/, RPointerArray<HBufC8>& aLuidList) |
|
81 { |
|
82 TDmAdUriType uriType = CDmAdRtNodeData::UriTypeL(aUri); |
|
83 switch (uriType) |
|
84 { |
|
85 case EDmAdUriTypeVpnAp: |
|
86 VpnApLuidListL(aLuidList); |
|
87 break; |
|
88 case EDmAdUriTypePolicy: |
|
89 PolicyLuidListL(aLuidList); |
|
90 break; |
|
91 default: |
|
92 DEBUG_LOG(_L("Unknown URI type")); |
|
93 User::Leave(KErrGeneral); |
|
94 break; |
|
95 } |
|
96 } |
|
97 |
|
98 void CDmAdStore::FetchRtNodeL(CDmAdRtNode& aRtNode) |
|
99 { |
|
100 TRACE("CDmAdStore::FetchRtNodeL"); |
|
101 |
|
102 TDmAdUriType uriType = aRtNode.Data()->UriType(); |
|
103 switch (uriType) |
|
104 { |
|
105 case EDmAdUriTypeVpnAp: |
|
106 VpnApFetchRtNodeL(aRtNode); |
|
107 break; |
|
108 case EDmAdUriTypePolicy: |
|
109 PolicyFetchRtNodeL(aRtNode); |
|
110 break; |
|
111 default: |
|
112 DEBUG_LOG(_L("Unknown URI type")); |
|
113 User::Leave(KErrGeneral); |
|
114 break; |
|
115 } |
|
116 } |
|
117 |
|
118 void CDmAdStore::SaveTopLevelRtNodeL(CDmAdRtNode& aRtNode, CArrayPtr<CDmAdRtNode>& aChildRtNodes) |
|
119 { |
|
120 TRACE("CDmAdStore::SaveTopLevelRtNodeL"); |
|
121 |
|
122 TDmAdUriType uriType = aRtNode.Data()->UriType(); |
|
123 switch (uriType) |
|
124 { |
|
125 case EDmAdUriTypeVpnAp: |
|
126 VpnApSaveTopLevelRtNodeL(aRtNode, aChildRtNodes); |
|
127 break; |
|
128 case EDmAdUriTypePolicy: |
|
129 PolicySaveTopLevelRtNodeL(aRtNode, aChildRtNodes); |
|
130 break; |
|
131 default: |
|
132 DEBUG_LOG(_L("Unknown URI type")); |
|
133 User::Leave(KErrGeneral); |
|
134 break; |
|
135 } |
|
136 } |
|
137 |
|
138 void CDmAdStore::SaveChildLevelRtNodeL(CDmAdRtNode& /*aRtNode*/) |
|
139 { |
|
140 TRACE("CDmAdStore::SaveChildLevelRtNodeL"); |
|
141 User::Leave(KErrGeneral); |
|
142 } |
|
143 |
|
144 |
|
145 void CDmAdStore::DeleteRtNodeL(const TDesC8& aLuid, const TDesC8& aUri) |
|
146 { |
|
147 TRACE("CDmAdStore::DeleteRtNodeL"); |
|
148 |
|
149 TDmAdUriType uriType = CDmAdRtNodeData::UriTypeL(aUri); |
|
150 switch (uriType) |
|
151 { |
|
152 case EDmAdUriTypeVpnAp: |
|
153 VpnApDeleteRtNodeL(aLuid); |
|
154 break; |
|
155 case EDmAdUriTypePolicy: |
|
156 PolicyDeleteRtNodeL(aLuid); |
|
157 break; |
|
158 default: |
|
159 DEBUG_LOG(_L("Unknown URI type")); |
|
160 User::Leave(KErrGeneral); |
|
161 break; |
|
162 } |
|
163 } |
|
164 |
|
165 //========================================================================= |
|
166 //========================================================================= |
|
167 |
|
168 TBool CDmAdStore::VpnApFindRtNodeL(const TDesC8& aLuid, const TDesC8& aUri) |
|
169 { |
|
170 TRACE("CDmAdStore::VpnApFindRtNodeL"); |
|
171 |
|
172 (void)aUri; |
|
173 TBool ret = EFalse; |
|
174 if (aLuid.Length() > 0) |
|
175 { |
|
176 if (iVpnAp->FindVpnApL(TDmAdUtil::DesToInt(aLuid))) |
|
177 { |
|
178 ret = ETrue; |
|
179 } |
|
180 } |
|
181 return ret; |
|
182 } |
|
183 |
|
184 void CDmAdStore::VpnApLuidListL(RPointerArray<HBufC8>& aLuidList) |
|
185 { |
|
186 |
|
187 TRACE("CDmAdStore::VpnApLuidListL"); |
|
188 |
|
189 RArray<TVpnApCommsId> idArray; |
|
190 CleanupClosePushL(idArray); |
|
191 iVpnAp->ListVpnApsL(idArray); |
|
192 |
|
193 for (TInt i=0; i<idArray.Count(); ++i) |
|
194 { |
|
195 HBufC8* luid = TDmAdUtil::IntToDes8LC(idArray[i]); |
|
196 aLuidList.AppendL(luid); |
|
197 CleanupStack::Pop(); //luid |
|
198 } |
|
199 |
|
200 CleanupStack::PopAndDestroy(); //idArray |
|
201 } |
|
202 |
|
203 void CDmAdStore::VpnApFetchRtNodeL(CDmAdRtNode& aRtNode) |
|
204 { |
|
205 TRACE("CDmAdStore::VpnApFetchRtNodeL"); |
|
206 |
|
207 TPtrC8 luid(aRtNode.Luid()); |
|
208 if (luid.Length() == 0) |
|
209 { |
|
210 DEBUG_LOG(_L("Luid length is 0")); |
|
211 User::Leave(KErrNotFound); |
|
212 } |
|
213 |
|
214 CDmAdVpnApData* data = aRtNode.Data()->VpnApData(); |
|
215 TVpnApParms* vpnApParms = new (ELeave) TVpnApParms(); |
|
216 CleanupStack::PushL(vpnApParms); |
|
217 iVpnAp->GetVpnApL(TDmAdUtil::DesToInt(luid), *vpnApParms); |
|
218 data->RestoreL(*vpnApParms); |
|
219 CleanupStack::PopAndDestroy(); //vpnApParms |
|
220 } |
|
221 |
|
222 void CDmAdStore::VpnApSaveTopLevelRtNodeL(CDmAdRtNode& aRtNode, CArrayPtr<CDmAdRtNode>& aChildRtNodes) |
|
223 { |
|
224 TRACE("CDmAdStore::VpnApSaveTopLevelRtNodeL"); |
|
225 |
|
226 if (aChildRtNodes.Count() > 0) |
|
227 { |
|
228 DEBUG_LOG(_L("aChildRtNodes.Count() > 0")); |
|
229 User::Leave(KErrGeneral); |
|
230 } |
|
231 |
|
232 if (aRtNode.IsJustFetched()) |
|
233 { |
|
234 return; |
|
235 } |
|
236 |
|
237 CDmAdVpnApData* data = aRtNode.Data()->VpnApData(); |
|
238 |
|
239 TVpnApParms* vpnApParms = new (ELeave) TVpnApParms(); |
|
240 CleanupStack::PushL(vpnApParms); |
|
241 data->ToStoreL(*vpnApParms); |
|
242 |
|
243 |
|
244 //Check the policy existence. |
|
245 //It is possible to set the policyId to be empty, but |
|
246 //if the policyId is set it has to be found. |
|
247 if ( vpnApParms->iPolicyId.Length() > 0) |
|
248 { |
|
249 CArrayFixFlat<TVpnPolicyInfo>* policyInfoList = new (ELeave) CArrayFixFlat<TVpnPolicyInfo>(2); |
|
250 CleanupStack::PushL(policyInfoList); |
|
251 User::LeaveIfError(iVpnApi.GetPolicyInfoList(policyInfoList)); |
|
252 |
|
253 TBool policyFound = EFalse; |
|
254 for (TInt i = 0; i < policyInfoList->Count(); ++i) |
|
255 { |
|
256 const TVpnPolicyInfo& info = (*policyInfoList)[i]; |
|
257 if (info.iId.Compare(vpnApParms->iPolicyId) == 0) |
|
258 { |
|
259 policyFound = ETrue; |
|
260 break; |
|
261 } |
|
262 } |
|
263 CleanupStack::PopAndDestroy(policyInfoList); |
|
264 if (!policyFound) |
|
265 { |
|
266 DEBUG_LOG1(_L("Policy with id %S not found"), &(vpnApParms->iPolicyId)); |
|
267 User::Leave(KErrGeneral); |
|
268 } |
|
269 } |
|
270 |
|
271 if (aRtNode.IsSomeLeafAddedToRtNode()) |
|
272 { |
|
273 |
|
274 TUint32 id = iVpnAp->AddVpnApL(*vpnApParms); |
|
275 |
|
276 TBuf<KVpnApSvrMaxFieldLength> buf; |
|
277 buf.Copy(vpnApParms->iPolicyId); |
|
278 |
|
279 if (vpnApParms->iRealConnRefType == TVpnApParms::EIapRealConnRef) |
|
280 { |
|
281 LOG_EVENT(iVpnApi, R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_AP, &buf, |
|
282 id, vpnApParms->iRealConnRef); |
|
283 } |
|
284 else //Connection type is SNAP |
|
285 { |
|
286 __ASSERT_DEBUG(vpnApParms->iRealConnRefType == TVpnApParms::ESnapRealConnRef, User::Invariant()); |
|
287 LOG_EVENT(iVpnApi, R_VPN_MSG_CREATED_VPN_ACCESS_POINT_WITH_SNAP, &buf, |
|
288 id, vpnApParms->iRealConnRef); |
|
289 |
|
290 } |
|
291 |
|
292 HBufC8* luid = TDmAdUtil::IntToDes8LC(id); |
|
293 aRtNode.SetLuidL(*luid); |
|
294 CleanupStack::PopAndDestroy(); //luid |
|
295 } |
|
296 else |
|
297 { |
|
298 TPtrC8 luid(aRtNode.Luid()); |
|
299 iVpnAp->UpdateVpnApL(TDmAdUtil::DesToInt(luid), *vpnApParms); |
|
300 } |
|
301 |
|
302 CleanupStack::PopAndDestroy(); //vpnApParms |
|
303 } |
|
304 |
|
305 |
|
306 void CDmAdStore::VpnApDeleteRtNodeL(const TDesC8& aLuid) |
|
307 { |
|
308 TRACE("CDmAdStore::VpnApDeleteRtNodeL"); |
|
309 |
|
310 if (aLuid.Length() == 0) |
|
311 { |
|
312 DEBUG_LOG(_L("aLuid length is 0")); |
|
313 User::Leave(KErrNotFound); |
|
314 } |
|
315 |
|
316 iVpnAp->DeleteVpnApL(TDmAdUtil::DesToInt(aLuid)); |
|
317 } |
|
318 |
|
319 //========================================================================= |
|
320 //========================================================================= |
|
321 |
|
322 TPtrC8 CDmAdStore::PolicyRefToLuid(const TDesC& aPolicyRef) |
|
323 { |
|
324 TRACE("CDmAdStore::PolicyRefToLuid"); |
|
325 |
|
326 TPtrC8 ret((const TUint8*)aPolicyRef.Ptr(), aPolicyRef.Length() * 2); |
|
327 return ret; |
|
328 } |
|
329 |
|
330 TPtrC CDmAdStore::LuidToPolicyRef(const TDesC8& aLuid) |
|
331 { |
|
332 TRACE("CDmAdStore::LuidToPolicyRef"); |
|
333 |
|
334 TPtrC ret((const TUint16*)aLuid.Ptr(), aLuid.Length() / 2); |
|
335 return ret; |
|
336 } |
|
337 |
|
338 TBool CDmAdStore::PolicyFindRtNodeL(const TDesC8& aLuid, const TDesC8& /*aUri*/) |
|
339 { |
|
340 TRACE("CDmAdStore::PolicyFindRtNodeL"); |
|
341 |
|
342 TBool ret = EFalse; |
|
343 if (aLuid.Length() > 0) |
|
344 { |
|
345 TVpnPolicyDetails* details = new (ELeave) TVpnPolicyDetails(); |
|
346 if (iVpnApi.GetPolicyDetails(LuidToPolicyRef(aLuid), *details) == KErrNone) |
|
347 { |
|
348 ret = ETrue; |
|
349 } |
|
350 delete details; |
|
351 } |
|
352 return ret; |
|
353 } |
|
354 |
|
355 |
|
356 void CDmAdStore::PolicyLuidListL(RPointerArray<HBufC8>& aLuidList) |
|
357 { |
|
358 |
|
359 TRACE("CDmAdStore::PolicyLuidListL"); |
|
360 |
|
361 CArrayFixFlat<TVpnPolicyInfo>* policyList; |
|
362 policyList = new (ELeave) CArrayFixFlat<TVpnPolicyInfo>(2); |
|
363 CleanupStack::PushL(policyList); |
|
364 |
|
365 User::LeaveIfError(iVpnApi.GetPolicyInfoList(policyList)); |
|
366 |
|
367 for (TInt i=0; i<policyList->Count(); ++i) |
|
368 { |
|
369 HBufC8* luidElem = PolicyRefToLuid(policyList->At(i).iId).AllocLC(); |
|
370 aLuidList.AppendL(luidElem); |
|
371 CleanupStack::Pop(); // luidElem |
|
372 } |
|
373 |
|
374 CleanupStack::PopAndDestroy(); //policyList |
|
375 } |
|
376 |
|
377 |
|
378 void CDmAdStore::PolicyFetchRtNodeL(CDmAdRtNode& aRtNode) |
|
379 { |
|
380 TRACE("CDmAdStore::PolicyFetchRtNodeL"); |
|
381 |
|
382 TPtrC policyRef(LuidToPolicyRef(aRtNode.Luid())); |
|
383 |
|
384 if (policyRef.Length() == 0) |
|
385 { |
|
386 DEBUG_LOG(_L("policyRef length is 0")); |
|
387 User::Leave(KErrNotFound); |
|
388 } |
|
389 |
|
390 CDmAdPolicyData* data = aRtNode.Data()->PolicyData(); |
|
391 |
|
392 TVpnPolicyDetails* details = new (ELeave) TVpnPolicyDetails(); |
|
393 CleanupStack::PushL(details); |
|
394 if (iVpnApi.GetPolicyDetails(policyRef, *details) != KErrNone) |
|
395 { |
|
396 DEBUG_LOG(_L("Details not found")); |
|
397 User::Leave(KErrNotFound); |
|
398 } |
|
399 data->DetailsRestoreL(*details); |
|
400 CleanupStack::PopAndDestroy(); //details |
|
401 |
|
402 HBufC8* policyData; |
|
403 if (iVpnApi.GetPolicyData(policyRef, policyData) != KErrNone) |
|
404 { |
|
405 DEBUG_LOG(_L("Policy data not found")); |
|
406 User::Leave(KErrNotFound); |
|
407 } |
|
408 CleanupStack::PushL(policyData); |
|
409 data->ContentRestoreL(*policyData); |
|
410 CleanupStack::PopAndDestroy(); //policyData |
|
411 } |
|
412 |
|
413 void CDmAdStore::PolicySaveTopLevelRtNodeL(CDmAdRtNode& aRtNode, CArrayPtr<CDmAdRtNode>& aChildRtNodes) |
|
414 { |
|
415 TRACE("CDmAdStore::PolicySaveTopLevelRtNodeL"); |
|
416 |
|
417 if (aChildRtNodes.Count() > 0) |
|
418 { |
|
419 DEBUG_LOG(_L("aChildRtNodes.Count() is more than 0")); |
|
420 User::Leave(KErrGeneral); |
|
421 } |
|
422 |
|
423 if (aRtNode.IsJustFetched()) |
|
424 { |
|
425 return; |
|
426 } |
|
427 |
|
428 CDmAdPolicyData* data = aRtNode.Data()->PolicyData(); |
|
429 |
|
430 TVpnPolicyDetails* details = new (ELeave) TVpnPolicyDetails(); |
|
431 CleanupStack::PushL(details); |
|
432 data->DetailsToStoreL(*details); |
|
433 |
|
434 TInt err; |
|
435 if (aRtNode.IsSomeLeafAddedToRtNode()) |
|
436 { |
|
437 if ((err = iVpnApi.AddPolicy(*details, data->ContentToStore())) != KErrNone) |
|
438 { |
|
439 DEBUG_LOG1(_L("iVpnApi.AddPolicy failed with %d"), err); |
|
440 User::Leave(err); |
|
441 } |
|
442 aRtNode.SetLuidL(PolicyRefToLuid(details->iId)); |
|
443 } |
|
444 else |
|
445 { |
|
446 TPtrC policyRef(LuidToPolicyRef(aRtNode.Luid())); |
|
447 if (policyRef.Compare(details->iId) != 0) |
|
448 { |
|
449 DEBUG_LOG(_L("Details Id doesn't match")); |
|
450 User::Leave(KErrGeneral); |
|
451 } |
|
452 if ((err = iVpnApi.UpdatePolicyDetails(*details)) != KErrNone) |
|
453 { |
|
454 DEBUG_LOG1(_L("iVpnApi.UpdatePolicyDetails failed with %d"), err); |
|
455 User::Leave(err); |
|
456 } |
|
457 if ((err = iVpnApi.UpdatePolicyData(details->iId, data->ContentToStore())) != KErrNone) |
|
458 { |
|
459 DEBUG_LOG1(_L("iVpnApi.UpdatePolicyData failed with %d"), err); |
|
460 User::Leave(err); |
|
461 } |
|
462 } |
|
463 |
|
464 CleanupStack::PopAndDestroy(); //details |
|
465 } |
|
466 |
|
467 |
|
468 void CDmAdStore::PolicyDeleteRtNodeL(const TDesC8& aLuid) |
|
469 { |
|
470 TRACE("CDmAdStore::PolicyDeleteRtNodeL"); |
|
471 |
|
472 if (aLuid.Length() == 0) |
|
473 { |
|
474 DEBUG_LOG(_L("aLuid length is 0")); |
|
475 User::Leave(KErrNotFound); |
|
476 } |
|
477 |
|
478 User::LeaveIfError(iVpnApi.DeletePolicy(LuidToPolicyRef(aLuid))); |
|
479 } |