|
1 /* |
|
2 * Copyright (c) 2002-2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 // INCLUDE FILES |
|
29 #include <e32std.h> |
|
30 #include <s32strm.h> |
|
31 |
|
32 //#include "SenDebug.h" |
|
33 |
|
34 #include <SenElement.h> |
|
35 #include <SenXmlUtils.h> |
|
36 |
|
37 #include "senpolicy.h" |
|
38 #include "SenIdentityProviderIdArray8.h" |
|
39 |
|
40 // ============================ LOCAL FUNCTIONS =============================== |
|
41 |
|
42 namespace |
|
43 { |
|
44 _LIT8(KPolicyLocalName, "Policy"); |
|
45 _LIT8(KTransportLocalName, "Transport"); |
|
46 _LIT8(KIapIdLocalName, "IapId"); |
|
47 _LIT8(KSnapIdLocalName, "SnapId"); |
|
48 _LIT8(KIdentityProviderIDsLocalName, "IdentityProviderIDs"); |
|
49 _LIT8(KIdentityProviderIDsStrictAttrName, "strict"); |
|
50 _LIT8(KIdentityProviderIDsStrictAttrTrue, "true"); |
|
51 _LIT8(KIdentityProviderIDLocalName, "IdentityProviderID"); |
|
52 } |
|
53 |
|
54 |
|
55 EXPORT_C CSenPolicy* CSenPolicy::NewL() |
|
56 { |
|
57 CSenPolicy* pNew = NewLC(); |
|
58 CleanupStack::Pop(); |
|
59 return(pNew) ; |
|
60 } |
|
61 |
|
62 EXPORT_C CSenPolicy* CSenPolicy::NewLC() |
|
63 { |
|
64 CSenPolicy* pNew = new (ELeave) CSenPolicy; |
|
65 CleanupStack::PushL(pNew); |
|
66 pNew->BaseConstructL(KPolicyLocalName()); |
|
67 return pNew; |
|
68 } |
|
69 |
|
70 |
|
71 EXPORT_C CSenPolicy* CSenPolicy::NewL(TUint32 aIapId) |
|
72 { |
|
73 CSenPolicy* pNew = NewLC(aIapId); |
|
74 CleanupStack::Pop(); |
|
75 return(pNew) ; |
|
76 } |
|
77 |
|
78 |
|
79 EXPORT_C CSenPolicy* CSenPolicy::NewLC(TUint32 aIapId) |
|
80 { |
|
81 CSenPolicy* pNew = new (ELeave) CSenPolicy; |
|
82 CleanupStack::PushL(pNew); |
|
83 pNew->BaseConstructL(KPolicyLocalName(), aIapId); |
|
84 return pNew; |
|
85 } |
|
86 |
|
87 EXPORT_C CSenPolicy* CSenPolicy::NewL(TUint32 aId, TBool aIsSnapId) |
|
88 { |
|
89 CSenPolicy* pNew = NewLC(aId, aIsSnapId); |
|
90 CleanupStack::Pop(); |
|
91 return(pNew) ; |
|
92 } |
|
93 |
|
94 |
|
95 EXPORT_C CSenPolicy* CSenPolicy::NewLC(TUint32 aId, TBool aIsSnapId) |
|
96 { |
|
97 CSenPolicy* pNew = new (ELeave) CSenPolicy; |
|
98 CleanupStack::PushL(pNew); |
|
99 pNew->BaseConstructL(KPolicyLocalName(), aId, aIsSnapId); |
|
100 return pNew; |
|
101 } |
|
102 |
|
103 |
|
104 CSenPolicy::CSenPolicy() |
|
105 : iIdpIdList(NULL) |
|
106 { |
|
107 } |
|
108 |
|
109 CSenPolicy::~CSenPolicy() |
|
110 { |
|
111 delete iIdpIdList; |
|
112 } |
|
113 |
|
114 EXPORT_C void CSenPolicy::BaseConstructL(const TDesC8& aPolicyLocalName) |
|
115 { |
|
116 CSenBaseFragment::BaseConstructL(aPolicyLocalName); |
|
117 } |
|
118 |
|
119 EXPORT_C void CSenPolicy::BaseConstructL(const TDesC8& aPolicyLocalName, |
|
120 TUint32 aIapId) |
|
121 { |
|
122 CSenBaseFragment::BaseConstructL(aPolicyLocalName); |
|
123 SetIapIdL(aIapId); |
|
124 } |
|
125 |
|
126 EXPORT_C void CSenPolicy::BaseConstructL(const TDesC8& aPolicyLocalName, |
|
127 TUint32 aId, TBool aIsSnapId) |
|
128 { |
|
129 CSenBaseFragment::BaseConstructL(aPolicyLocalName); |
|
130 if (aIsSnapId == EFalse) |
|
131 { |
|
132 SetIapIdL(aId); |
|
133 } |
|
134 else |
|
135 { |
|
136 SetSnapIdL(aId); |
|
137 } |
|
138 } |
|
139 |
|
140 EXPORT_C TBool CSenPolicy::Accepts(MSenPolicy& aPolicyPattern) |
|
141 { |
|
142 TBool retVal(ETrue); |
|
143 TRAPD(err, retVal = AcceptsL(aPolicyPattern)); |
|
144 if (err) return EFalse; |
|
145 return retVal; |
|
146 } |
|
147 |
|
148 TBool CSenPolicy::AcceptsL(MSenPolicy& aPolicyPattern) |
|
149 { |
|
150 TUint32 thisIapID(0); |
|
151 TUint32 patternIapID(0); |
|
152 |
|
153 if(aPolicyPattern.IapId(patternIapID) == KErrNone |
|
154 && (IapId(thisIapID) != KErrNone |
|
155 || patternIapID!=thisIapID)) |
|
156 { |
|
157 return EFalse; // policies do NOT match(!) |
|
158 } |
|
159 |
|
160 const CSenIdentityProviderIdArray8& patternIdps = |
|
161 aPolicyPattern.IdentityProviderIds8L(); |
|
162 if(patternIdps.IsStrict()) |
|
163 { |
|
164 const CSenIdentityProviderIdArray8& thisIdps = IdentityProviderIds8L(); |
|
165 TInt thisCount(thisIdps.Count()); |
|
166 TInt pos(-1); |
|
167 TBool matches(EFalse); |
|
168 for(TInt i=0; i<thisCount; i++) |
|
169 { |
|
170 if(patternIdps.Find(thisIdps[i], pos, ECmpNormal)==KErrNone) |
|
171 { |
|
172 matches = ETrue; |
|
173 break; |
|
174 } |
|
175 } |
|
176 return matches; |
|
177 } |
|
178 |
|
179 return ETrue; |
|
180 } |
|
181 |
|
182 |
|
183 // Setter for IAP ID |
|
184 EXPORT_C void CSenPolicy::SetIapIdL(TUint32 aIapId) |
|
185 { |
|
186 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
187 if(aIapId > 0) |
|
188 { |
|
189 if(!pTransportElement) |
|
190 { |
|
191 pTransportElement = &(AsElement().AddElementL(KTransportLocalName)); |
|
192 } |
|
193 CSenElement* pSnapIdElement = |
|
194 pTransportElement->Element(KSnapIdLocalName); |
|
195 |
|
196 if(pSnapIdElement) |
|
197 { |
|
198 pSnapIdElement = pTransportElement->RemoveElement(KSnapIdLocalName); |
|
199 } |
|
200 CSenElement* pIapIdElement = |
|
201 pTransportElement->Element(KIapIdLocalName); |
|
202 if(!pIapIdElement) |
|
203 { |
|
204 pIapIdElement = &(pTransportElement->AddElementL(KIapIdLocalName)); |
|
205 } |
|
206 TBuf8<128> buf; |
|
207 buf.AppendFormat(_L8("%u"), aIapId); |
|
208 pIapIdElement->SetContentL(buf); |
|
209 } |
|
210 else |
|
211 { |
|
212 if(pTransportElement) |
|
213 { |
|
214 CSenElement* pIapIdElement = |
|
215 pTransportElement->Element(KIapIdLocalName); |
|
216 |
|
217 if(pIapIdElement) |
|
218 { |
|
219 pIapIdElement = pTransportElement->RemoveElement(KIapIdLocalName); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 } |
|
226 |
|
227 // Getter for IAP ID |
|
228 EXPORT_C TInt CSenPolicy::IapId(TUint32& aCurrentIapId) |
|
229 { |
|
230 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
231 if(pTransportElement) |
|
232 { |
|
233 CSenElement* pIapIdElement = |
|
234 pTransportElement->Element(KIapIdLocalName); |
|
235 if(pIapIdElement && pIapIdElement->HasContent()) |
|
236 { |
|
237 //SENDEBUG((_L("CSenPolicy::IapIdL: content found"))); |
|
238 TPtrC8 content = pIapIdElement->Content(); |
|
239 TLex8 lex(content); |
|
240 |
|
241 TInt err = lex.Val(aCurrentIapId, EDecimal); |
|
242 return err; |
|
243 } |
|
244 //SENDEBUG((_L("CSenPolicy::IapIdL: <IapId> element not found"))); |
|
245 } |
|
246 //SENDEBUG((_L("CSenPolicy::IapIdL: <Transport> element not found"))); |
|
247 return KErrNotFound; |
|
248 } |
|
249 |
|
250 // Setter for SNAP ID |
|
251 EXPORT_C void CSenPolicy::SetSnapIdL(TUint32 aSnapId) |
|
252 { |
|
253 if(aSnapId > 0) |
|
254 { |
|
255 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
256 if(!pTransportElement) |
|
257 { |
|
258 pTransportElement = &(AsElement().AddElementL(KTransportLocalName)); |
|
259 } |
|
260 |
|
261 CSenElement* pIapIdElement = |
|
262 pTransportElement->Element(KIapIdLocalName); |
|
263 |
|
264 if(pIapIdElement) |
|
265 { |
|
266 pIapIdElement = pTransportElement->RemoveElement(KIapIdLocalName); |
|
267 } |
|
268 |
|
269 CSenElement* pSnapIdElement = |
|
270 pTransportElement->Element(KSnapIdLocalName); |
|
271 if(!pSnapIdElement) |
|
272 { |
|
273 pSnapIdElement = &(pTransportElement->AddElementL(KSnapIdLocalName)); |
|
274 } |
|
275 TBuf8<128> buf; |
|
276 buf.AppendFormat(_L8("%u"), aSnapId); |
|
277 pSnapIdElement->SetContentL(buf); |
|
278 } |
|
279 else |
|
280 { |
|
281 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
282 if(pTransportElement) |
|
283 { |
|
284 CSenElement* pSnapIdElement = |
|
285 pTransportElement->Element(KSnapIdLocalName); |
|
286 |
|
287 if(pSnapIdElement) |
|
288 { |
|
289 pSnapIdElement = pTransportElement->RemoveElement(KSnapIdLocalName); |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 } |
|
295 |
|
296 // Getter for SNAP ID |
|
297 EXPORT_C TInt CSenPolicy::SnapId(TUint32& aCurrentSnapId) |
|
298 { |
|
299 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
300 if(pTransportElement) |
|
301 { |
|
302 CSenElement* pSnapIdElement = |
|
303 pTransportElement->Element(KSnapIdLocalName); |
|
304 if(pSnapIdElement && pSnapIdElement->HasContent()) |
|
305 { |
|
306 //SENDEBUG((_L("CSenPolicy::SnapIdL: content found"))); |
|
307 TPtrC8 content = pSnapIdElement->Content(); |
|
308 TLex8 lex(content); |
|
309 |
|
310 TInt err = lex.Val(aCurrentSnapId, EDecimal); |
|
311 return err; |
|
312 } |
|
313 //SENDEBUG((_L("CSenPolicy::SnapIdL: <SnapId> element not found"))); |
|
314 } |
|
315 //SENDEBUG((_L("CSenPolicy::SnapIdL: <Transport> element not found"))); |
|
316 return KErrNotFound; |
|
317 } |
|
318 |
|
319 // Setter: overrides current values with the given values from the array |
|
320 EXPORT_C void CSenPolicy::SetIdentityProviderIdsL( |
|
321 CSenIdentityProviderIdArray8& aList) |
|
322 { |
|
323 CSenElement* pListElement = |
|
324 AsElement().Element(KIdentityProviderIDsLocalName); |
|
325 |
|
326 if(pListElement) |
|
327 { |
|
328 CSenElement* pRemoved = AsElement().RemoveElement(*pListElement); |
|
329 delete pRemoved; |
|
330 } |
|
331 |
|
332 TInt count(aList.Count()); |
|
333 if(count>0) |
|
334 { |
|
335 for(TInt i=0; i<count; i++) |
|
336 { |
|
337 TPtrC8 providerId = aList[i]; |
|
338 if(providerId.Length()>0) |
|
339 { |
|
340 AddIdentityProviderIdL(providerId); |
|
341 } |
|
342 } |
|
343 } |
|
344 } |
|
345 |
|
346 // Adder: adds a new IDP ID value at the end of the current list value(s) |
|
347 // Checks for duplicate (does not insert new ID elements with equal content) |
|
348 // @return KErrAlreadyExists, if a duplicate is tried to add |
|
349 // KErrArgument if a zero-length descriptor is tried |
|
350 // to add (aProviderId.Length() == 0) |
|
351 // |
|
352 // NOTE: allocates a copy of given aProviderId! |
|
353 // |
|
354 EXPORT_C TInt CSenPolicy::AddIdentityProviderIdL(const TDesC8& aProviderId) |
|
355 { |
|
356 if(aProviderId.Length()>0) |
|
357 { |
|
358 // there is something relevant to add.. |
|
359 |
|
360 // check next that <IdentityProviderIDs> element exists |
|
361 CSenElement* pListElement = |
|
362 AsElement().Element(KIdentityProviderIDsLocalName); |
|
363 |
|
364 // check if this policy is "empty" (no content yet) |
|
365 if(!pListElement) |
|
366 { |
|
367 // add the <IdentityProviderIDs> element.. |
|
368 pListElement = |
|
369 &AsElement().AddElementL(KIdentityProviderIDsLocalName); |
|
370 } |
|
371 else |
|
372 { |
|
373 // check if ID being inserted already exists |
|
374 // (prevent inserting a duplicate) |
|
375 |
|
376 RPointerArray<CSenElement>& children = pListElement->ElementsL(); |
|
377 TInt childCount(children.Count()); |
|
378 |
|
379 // loop through child elements and check their content |
|
380 for(TInt i=0; i<childCount; i++) |
|
381 { |
|
382 TPtrC8 content = children[i]->Content(); |
|
383 if(content == aProviderId) |
|
384 { |
|
385 // duplicate found(!) |
|
386 return KErrAlreadyExists; |
|
387 } |
|
388 } |
|
389 |
|
390 } |
|
391 |
|
392 CSenElement& added = |
|
393 pListElement->AddElementL(KIdentityProviderIDLocalName); |
|
394 |
|
395 added.SetContentL(aProviderId); |
|
396 // content set: ok |
|
397 return KErrNone; |
|
398 } |
|
399 else // tried to add zero length descriptor (aProviderId.Length() == 0) |
|
400 { |
|
401 // return argument error |
|
402 return KErrArgument; |
|
403 } |
|
404 } |
|
405 |
|
406 // sets (rebuilds) the IAP ID and IDP ID list values from template |
|
407 // @return - a error, if at least one addition of new contents has |
|
408 // failed OR KerrNone if every property was successfully reset |
|
409 EXPORT_C TInt CSenPolicy::RebuildFrom(MSenPolicy& aTemplate) |
|
410 { |
|
411 TInt retVal(KErrNone); |
|
412 TRAPD(err, retVal = RebuildFromL(aTemplate)); |
|
413 if (err != KErrNone) |
|
414 { |
|
415 retVal = err; |
|
416 } |
|
417 return retVal; |
|
418 } |
|
419 |
|
420 TInt CSenPolicy::RebuildFromL(MSenPolicy& aTemplate) |
|
421 { |
|
422 TInt retVal(KErrNone); |
|
423 // check for possible provider policy definition |
|
424 |
|
425 TUint32 iapId(0); |
|
426 TInt err = aTemplate.IapId(iapId); |
|
427 if(err==KErrNone) |
|
428 { |
|
429 // update the latest IAP "recommendation" |
|
430 SetIapIdL(iapId); |
|
431 } |
|
432 const CSenIdentityProviderIdArray8& ids = |
|
433 aTemplate.IdentityProviderIds8L(); |
|
434 TInt idsCount(ids.MdcaCount()); |
|
435 for(TInt j=0; j<idsCount; j++) |
|
436 { |
|
437 TPtrC8 value = ids[j]; |
|
438 if(value.Length()>0) |
|
439 { |
|
440 err = AddIdentityProviderIdL(value); |
|
441 if(err!=KErrNone) |
|
442 { |
|
443 retVal = err; // indicate that some IDP could not be added |
|
444 } |
|
445 } |
|
446 } |
|
447 return retVal; |
|
448 } |
|
449 |
|
450 // Getter: return an empty array if no IDP:s have been spesified |
|
451 // or a list of IDP arrays if such value(s) have been set. |
|
452 // |
|
453 // Ownership of the array remains within this class |
|
454 EXPORT_C const CSenIdentityProviderIdArray8& |
|
455 CSenPolicy::IdentityProviderIds8L() |
|
456 { |
|
457 // construct temporary array and fill it with the xml content |
|
458 CSenIdentityProviderIdArray8* pArray = |
|
459 CSenIdentityProviderIdArray8::NewLC(); |
|
460 |
|
461 // check next that <IdentityProviderIDs> element exists |
|
462 CSenElement* pListElement = |
|
463 AsElement().Element(KIdentityProviderIDsLocalName); |
|
464 if(pListElement) |
|
465 { |
|
466 // Check if strict attribute has "true" value. |
|
467 const TDesC8* pStrictValue = |
|
468 pListElement->AttrValue(KIdentityProviderIDsStrictAttrName); |
|
469 if(pStrictValue && *pStrictValue == KIdentityProviderIDsStrictAttrTrue) |
|
470 { |
|
471 pArray->SetStrict(ETrue); |
|
472 } |
|
473 |
|
474 // next check that child elements exist |
|
475 RPointerArray<CSenElement>& elements = pListElement->ElementsL(); |
|
476 TInt count(elements.Count()); |
|
477 for(TInt i=0; i<count; i++) |
|
478 { |
|
479 CSenElement* element = elements[i]; |
|
480 if(element && element->HasContent()) |
|
481 { |
|
482 pArray->AppendL(element->Content()); |
|
483 } |
|
484 } |
|
485 } |
|
486 |
|
487 delete iIdpIdList; |
|
488 iIdpIdList = pArray; |
|
489 CleanupStack::Pop(); // pArray |
|
490 return *iIdpIdList; |
|
491 } |
|
492 |
|
493 // End of file |