|
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 // INCLUDE FILES |
|
26 #include <e32std.h> |
|
27 #include <s32strm.h> |
|
28 |
|
29 #include "senconsumerpolicy.h" |
|
30 #include "SenElement.h" |
|
31 #include "SenXmlUtils.h" |
|
32 |
|
33 #include "SenIdentityProviderIdArray8.h" |
|
34 |
|
35 |
|
36 |
|
37 // ============================ LOCAL FUNCTIONS =============================== |
|
38 |
|
39 namespace |
|
40 { |
|
41 _LIT8(KConsumerPolicyLocalName, "ConsumerPolicy"); |
|
42 } |
|
43 |
|
44 |
|
45 EXPORT_C CSenConsumerPolicy* CSenConsumerPolicy::NewL() |
|
46 { |
|
47 CSenConsumerPolicy* pNew = NewLC(); |
|
48 CleanupStack::Pop(); |
|
49 return(pNew) ; |
|
50 } |
|
51 |
|
52 EXPORT_C CSenConsumerPolicy* CSenConsumerPolicy::NewLC() |
|
53 { |
|
54 CSenConsumerPolicy* pNew = new (ELeave) CSenConsumerPolicy; |
|
55 CleanupStack::PushL(pNew); |
|
56 pNew->BaseConstructL(); |
|
57 return pNew; |
|
58 } |
|
59 |
|
60 |
|
61 EXPORT_C CSenConsumerPolicy* CSenConsumerPolicy::NewL(TUint32 aIapId) |
|
62 { |
|
63 CSenConsumerPolicy* pNew = NewLC(aIapId); |
|
64 CleanupStack::Pop(); |
|
65 return(pNew) ; |
|
66 } |
|
67 |
|
68 |
|
69 EXPORT_C CSenConsumerPolicy* CSenConsumerPolicy::NewLC(TUint32 aIapId) |
|
70 { |
|
71 CSenConsumerPolicy* pNew = new (ELeave) CSenConsumerPolicy; |
|
72 CleanupStack::PushL(pNew); |
|
73 pNew->BaseConstructL(aIapId); |
|
74 return pNew; |
|
75 } |
|
76 |
|
77 EXPORT_C CSenConsumerPolicy* CSenConsumerPolicy::NewL(TUint32 aId, TBool aIsSnapId) |
|
78 { |
|
79 CSenConsumerPolicy* pNew = NewLC(aId, aIsSnapId); |
|
80 CleanupStack::Pop(); |
|
81 return(pNew) ; |
|
82 } |
|
83 |
|
84 |
|
85 EXPORT_C CSenConsumerPolicy* CSenConsumerPolicy::NewLC(TUint32 aId, TBool aIsSnapId) |
|
86 { |
|
87 CSenConsumerPolicy* pNew = new (ELeave) CSenConsumerPolicy; |
|
88 CleanupStack::PushL(pNew); |
|
89 pNew->BaseConstructL(aId, aIsSnapId); |
|
90 return pNew; |
|
91 } |
|
92 |
|
93 CSenConsumerPolicy::CSenConsumerPolicy() |
|
94 { |
|
95 } |
|
96 |
|
97 CSenConsumerPolicy::~CSenConsumerPolicy() |
|
98 { |
|
99 } |
|
100 |
|
101 EXPORT_C void CSenConsumerPolicy::BaseConstructL() |
|
102 { |
|
103 CSenPolicy::BaseConstructL(KConsumerPolicyLocalName()); |
|
104 } |
|
105 |
|
106 EXPORT_C void CSenConsumerPolicy::BaseConstructL(TUint32 aIapId) |
|
107 { |
|
108 CSenPolicy::BaseConstructL(KConsumerPolicyLocalName()); |
|
109 SetIapIdL(aIapId); |
|
110 } |
|
111 |
|
112 EXPORT_C void CSenConsumerPolicy::BaseConstructL(TUint32 aId, TBool aIsSnapId) |
|
113 { |
|
114 CSenPolicy::BaseConstructL(KConsumerPolicyLocalName()); |
|
115 if (aIsSnapId == EFalse) |
|
116 { |
|
117 SetIapIdL(aId); |
|
118 } |
|
119 else |
|
120 { |
|
121 SetSnapIdL(aId); |
|
122 } |
|
123 } |
|
124 |
|
125 EXPORT_C TBool CSenConsumerPolicy::Accepts(MSenConsumerPolicy& aPolicyPattern) |
|
126 { |
|
127 TBool retVal(ETrue); |
|
128 TRAPD(err, retVal = AcceptsL(aPolicyPattern)); |
|
129 if (err) return retVal; |
|
130 return retVal; |
|
131 } |
|
132 |
|
133 TBool CSenConsumerPolicy::AcceptsL(MSenConsumerPolicy& aPolicyPattern) |
|
134 { |
|
135 TUint32 thisIapID(0); |
|
136 TUint32 patternIapID(0); |
|
137 |
|
138 if(aPolicyPattern.ConsumerIapId(patternIapID)==KErrNone |
|
139 && (IapId(thisIapID) != KErrNone |
|
140 || patternIapID!=thisIapID)) |
|
141 { |
|
142 return EFalse; // policies do NOT match(!) |
|
143 } |
|
144 |
|
145 const CSenIdentityProviderIdArray8& patternIdps = |
|
146 aPolicyPattern.ConsumerIdentityProviderIds8L(); |
|
147 if(patternIdps.IsStrict()) |
|
148 { |
|
149 const CSenIdentityProviderIdArray8& thisIdps = IdentityProviderIds8L(); |
|
150 TInt thisCount(thisIdps.Count()); |
|
151 TInt pos(KErrNotFound); |
|
152 TBool matches(EFalse); |
|
153 for(TInt i=0; i<thisCount; i++) |
|
154 { |
|
155 pos = KErrNotFound; |
|
156 if(patternIdps.Find(thisIdps[i], pos, ECmpNormal)==KErrNone) |
|
157 { |
|
158 matches = ETrue; |
|
159 break; |
|
160 } |
|
161 } |
|
162 return matches; |
|
163 } |
|
164 |
|
165 return ETrue; |
|
166 } |
|
167 |
|
168 EXPORT_C TInt CSenConsumerPolicy::RebuildFrom( |
|
169 MSenConsumerPolicy& aTemplate) |
|
170 { |
|
171 TInt retVal(KErrNone); |
|
172 TRAPD(err, retVal = RebuildFromL(aTemplate)); |
|
173 if (err != KErrNone) |
|
174 { |
|
175 retVal = err; |
|
176 } |
|
177 return retVal; |
|
178 } |
|
179 |
|
180 TInt CSenConsumerPolicy::RebuildFromL(MSenConsumerPolicy& aTemplate) |
|
181 { |
|
182 TInt retVal(KErrNone); |
|
183 // check for possible provider policy definition |
|
184 |
|
185 TUint32 iapId(0); |
|
186 TInt err = aTemplate.ConsumerIapId(iapId); |
|
187 if(err==KErrNone) |
|
188 { |
|
189 // update the latest IAP "recommendation" |
|
190 SetIapIdL(iapId); |
|
191 } |
|
192 const CSenIdentityProviderIdArray8& ids = |
|
193 aTemplate.ConsumerIdentityProviderIds8L(); |
|
194 TInt idsCount(ids.MdcaCount()); |
|
195 for(TInt j=0; j<idsCount; j++) |
|
196 { |
|
197 TPtrC8 value = ids[j]; |
|
198 if(value.Length()>0) |
|
199 { |
|
200 err = AddIdentityProviderIdL(value); |
|
201 if(err!=KErrNone) |
|
202 { |
|
203 retVal = err; // indicate that some IDP could not be added |
|
204 } |
|
205 } |
|
206 } |
|
207 return retVal; |
|
208 } |
|
209 |
|
210 // End of file |