|
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: This class represents the policy information, which has been |
|
15 * resolved in some way from the actual WSP. Currently applications |
|
16 * typically "just know", which policy WSP prefers, but in the |
|
17 * future this class may be used as a container for data |
|
18 * originating directly from a WSP (as the for example, when the |
|
19 * Liberty ID-WSF evolves). |
|
20 * To point out a single feature, lets go through the Identity |
|
21 * Provider ID list getter, setter and adder -methods; these are |
|
22 * meant to be used as a storing place for a the policy information |
|
23 * Typically the IDP ID list is just a recommendation, and rarely |
|
24 * a strict list. |
|
25 * |
|
26 */ |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 // INCLUDE FILES |
|
36 #include <e32std.h> |
|
37 #include <s32strm.h> |
|
38 |
|
39 #include "senproviderpolicy.h" |
|
40 #include "SenElement.h" |
|
41 #include "SenXmlUtils.h" |
|
42 |
|
43 #include "SenIdentityProviderIdArray8.h" |
|
44 |
|
45 namespace |
|
46 { |
|
47 _LIT8(KTransportLocalName, "Transport"); |
|
48 } |
|
49 // ============================= LOCAL FUNCTIONS =============================== |
|
50 |
|
51 namespace |
|
52 { |
|
53 _LIT8(KProviderPolicyLocalName, "ProviderPolicy"); |
|
54 } |
|
55 |
|
56 |
|
57 EXPORT_C CSenProviderPolicy* CSenProviderPolicy::NewL() |
|
58 { |
|
59 CSenProviderPolicy* pNew = NewLC(); |
|
60 CleanupStack::Pop(); |
|
61 return(pNew) ; |
|
62 } |
|
63 |
|
64 EXPORT_C CSenProviderPolicy* CSenProviderPolicy::NewLC() |
|
65 { |
|
66 CSenProviderPolicy* pNew = new (ELeave) CSenProviderPolicy; |
|
67 CleanupStack::PushL(pNew); |
|
68 pNew->BaseConstructL(); |
|
69 return pNew; |
|
70 } |
|
71 |
|
72 |
|
73 EXPORT_C CSenProviderPolicy* CSenProviderPolicy::NewL(TUint32 aIapId) |
|
74 { |
|
75 CSenProviderPolicy* pNew = NewLC(aIapId); |
|
76 CleanupStack::Pop(); |
|
77 return(pNew); |
|
78 } |
|
79 |
|
80 |
|
81 EXPORT_C CSenProviderPolicy* CSenProviderPolicy::NewLC(TUint32 aIapId) |
|
82 { |
|
83 CSenProviderPolicy* pNew = new (ELeave) CSenProviderPolicy; |
|
84 CleanupStack::PushL(pNew); |
|
85 pNew->BaseConstructL(aIapId); |
|
86 return pNew; |
|
87 } |
|
88 |
|
89 EXPORT_C CSenProviderPolicy* CSenProviderPolicy::NewL(TUint32 aId, TBool aIsSnapId) |
|
90 { |
|
91 CSenProviderPolicy* pNew = NewLC(aId, aIsSnapId); |
|
92 CleanupStack::Pop(); |
|
93 return(pNew); |
|
94 } |
|
95 |
|
96 |
|
97 EXPORT_C CSenProviderPolicy* CSenProviderPolicy::NewLC(TUint32 aId, TBool aIsSnapId) |
|
98 { |
|
99 CSenProviderPolicy* pNew = new (ELeave) CSenProviderPolicy; |
|
100 CleanupStack::PushL(pNew); |
|
101 pNew->BaseConstructL(aId, aIsSnapId); |
|
102 return pNew; |
|
103 } |
|
104 |
|
105 CSenProviderPolicy::CSenProviderPolicy() |
|
106 { |
|
107 } |
|
108 |
|
109 CSenProviderPolicy::~CSenProviderPolicy() |
|
110 { |
|
111 } |
|
112 |
|
113 EXPORT_C void CSenProviderPolicy::BaseConstructL() |
|
114 { |
|
115 CSenPolicy::BaseConstructL(KProviderPolicyLocalName()); |
|
116 } |
|
117 |
|
118 EXPORT_C void CSenProviderPolicy::BaseConstructL(TUint32 aIapId) |
|
119 { |
|
120 CSenPolicy::BaseConstructL(KProviderPolicyLocalName(), aIapId); |
|
121 } |
|
122 |
|
123 EXPORT_C void CSenProviderPolicy::BaseConstructL(TUint32 aId, TBool aIsSnapId) |
|
124 { |
|
125 CSenPolicy::BaseConstructL(KProviderPolicyLocalName(), aId, aIsSnapId); |
|
126 } |
|
127 |
|
128 EXPORT_C TBool CSenProviderPolicy::Accepts(MSenProviderPolicy& aPolicyPattern) |
|
129 { |
|
130 TBool retVal(ETrue); |
|
131 TRAPD(err, retVal = AcceptsL(aPolicyPattern)); |
|
132 if (err) return EFalse; |
|
133 return retVal; |
|
134 } |
|
135 |
|
136 TBool CSenProviderPolicy::AcceptsL(MSenProviderPolicy& aPolicyPattern) |
|
137 { |
|
138 TUint32 thisIapID(0); |
|
139 TUint32 patternIapID(0); |
|
140 |
|
141 if(aPolicyPattern.IapId(patternIapID)==KErrNone |
|
142 && (IapId(thisIapID) != KErrNone |
|
143 || patternIapID!=thisIapID)) |
|
144 { |
|
145 return EFalse; // policies do NOT match(!) |
|
146 } |
|
147 |
|
148 if(aPolicyPattern.SnapId(patternIapID)==KErrNone |
|
149 && (SnapId(thisIapID) != KErrNone |
|
150 || patternIapID!=thisIapID)) |
|
151 { |
|
152 return EFalse; // policies do NOT match(!) |
|
153 } |
|
154 |
|
155 const CSenIdentityProviderIdArray8& patternIdps = |
|
156 aPolicyPattern.IdentityProviderIds8L(); |
|
157 if(patternIdps.IsStrict()) |
|
158 { |
|
159 const CSenIdentityProviderIdArray8& thisIdps = IdentityProviderIds8L(); |
|
160 TInt thisCount(thisIdps.Count()); |
|
161 TInt pos(KErrNotFound); |
|
162 TBool matches(EFalse); |
|
163 for(TInt i=0; i<thisCount; i++) |
|
164 { |
|
165 pos = KErrNotFound; |
|
166 if(patternIdps.Find(thisIdps[i], pos, ECmpNormal) == KErrNone) |
|
167 { |
|
168 matches = ETrue; |
|
169 break; |
|
170 } |
|
171 } |
|
172 return matches; |
|
173 } |
|
174 |
|
175 return ETrue; |
|
176 } |
|
177 |
|
178 // sets (rebuilds) the IAP ID and IDP ID list values from template |
|
179 // @return - a error, if at least one addition of new contents has |
|
180 // failed OR KerrNone if every property was successfully reset |
|
181 EXPORT_C TInt CSenProviderPolicy::RebuildFrom(MSenProviderPolicy& aTemplate) |
|
182 { |
|
183 TInt retVal(KErrNone); |
|
184 TRAPD(err, retVal = RebuildFromL(aTemplate)); |
|
185 if (err != KErrNone) |
|
186 { |
|
187 retVal = err; |
|
188 } |
|
189 return retVal; |
|
190 } |
|
191 |
|
192 TInt CSenProviderPolicy::RebuildFromL(MSenProviderPolicy& aTemplate) |
|
193 { |
|
194 TInt retVal(KErrNone); |
|
195 // check for possible provider policy definition |
|
196 |
|
197 TUint32 iapId(0); |
|
198 TInt err = aTemplate.IapId(iapId); |
|
199 if(err==KErrNone) |
|
200 { |
|
201 // update the latest IAP "recommendation" |
|
202 SetIapIdL(iapId); |
|
203 } |
|
204 |
|
205 err = aTemplate.SnapId(iapId); |
|
206 if(err==KErrNone) |
|
207 { |
|
208 // update the latest SNAP "recommendation" |
|
209 SetSnapIdL(iapId); |
|
210 } |
|
211 const CSenIdentityProviderIdArray8& ids = |
|
212 aTemplate.IdentityProviderIds8L(); |
|
213 TInt idsCount(ids.MdcaCount()); |
|
214 for(TInt j=0; j<idsCount; j++) |
|
215 { |
|
216 TPtrC8 value = ids[j]; |
|
217 if(value.Length()>0) |
|
218 { |
|
219 err = AddIdentityProviderIdL(value); |
|
220 if(err!=KErrNone) |
|
221 { |
|
222 retVal = err; // indicate that some IDP could not be added |
|
223 } |
|
224 } |
|
225 } |
|
226 return retVal; |
|
227 } |
|
228 |
|
229 EXPORT_C TInt CSenProviderPolicy::SetTransportPropertiesL(const TDesC8& aProperties) |
|
230 { |
|
231 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
232 if(!pTransportElement) |
|
233 { |
|
234 pTransportElement = &(AsElement().AddElementL(KTransportLocalName)); |
|
235 } |
|
236 pTransportElement->SetContentL(aProperties); |
|
237 return KErrNone; |
|
238 } |
|
239 |
|
240 |
|
241 EXPORT_C TInt CSenProviderPolicy::TransportPropertiesL(HBufC8*& aProperties) |
|
242 { |
|
243 CSenElement* pTransportElement = AsElement().Element(KTransportLocalName); |
|
244 if(pTransportElement) |
|
245 { |
|
246 aProperties = pTransportElement->AsXmlL(); |
|
247 } |
|
248 return KErrNone; |
|
249 } |
|
250 |
|
251 // End of file |