|
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 <SenXmlElement.h> // check if this include is needed(?) |
|
27 #include <SenXmlUtils.h> |
|
28 |
|
29 #include "idwsfsaslmessage.h" |
|
30 |
|
31 #include "sendebug.h" |
|
32 #include "senlogger.h" |
|
33 #include "senpasswordtransform.h" |
|
34 |
|
35 namespace |
|
36 { |
|
37 _LIT8(KContinue, "continue"); |
|
38 _LIT8(KAbort, "abort"); |
|
39 |
|
40 _LIT8(KPasswordTransformsName, "PasswordTransforms"); |
|
41 _LIT8(KTransformName, "Transform"); |
|
42 _LIT8(KParameterName, "Parameter"); |
|
43 |
|
44 _LIT8(KDataName, "Data"); |
|
45 _LIT8(KNameAttr, "name"); |
|
46 _LIT8(KAuthzIdName, "authzID"); |
|
47 _LIT8(KAdvisoryAuthnIdName, "advisoryAuthnID"); |
|
48 _LIT8(KServerMechanismName, "serverMechanism"); |
|
49 _LIT8(KMechanismName, "mechanism"); |
|
50 } |
|
51 |
|
52 CIdWsfSaslMessage* CIdWsfSaslMessage::NewL( |
|
53 MSenCoreServiceManager& aServiceManager) |
|
54 { |
|
55 CIdWsfSaslMessage* pNew = new (ELeave) CIdWsfSaslMessage(aServiceManager); |
|
56 CleanupStack::PushL(pNew); |
|
57 pNew->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return pNew; |
|
60 } |
|
61 |
|
62 CIdWsfSaslMessage* CIdWsfSaslMessage::NewL( |
|
63 MSenCoreServiceManager& aServiceManager, |
|
64 const TDesC8& aXmlns, |
|
65 const TDesC8& aLocalName, |
|
66 const TDesC8& aQName |
|
67 ) |
|
68 { |
|
69 CIdWsfSaslMessage* pNew = new (ELeave) CIdWsfSaslMessage(aServiceManager); |
|
70 CleanupStack::PushL(pNew); |
|
71 pNew->ConstructL(aXmlns, aLocalName, aQName); |
|
72 CleanupStack::Pop(); |
|
73 return pNew; |
|
74 } |
|
75 |
|
76 CIdWsfSaslMessage::CIdWsfSaslMessage(MSenCoreServiceManager& aServiceManager) |
|
77 : iServiceManager(aServiceManager), |
|
78 ipMechanism(NULL), |
|
79 ipParameterName(NULL) |
|
80 { |
|
81 } |
|
82 |
|
83 void CIdWsfSaslMessage::ConstructL() |
|
84 { |
|
85 BaseConstructL(KSaslXmlns, KSaslResponseName, KSaslResponseQName); |
|
86 } |
|
87 |
|
88 void CIdWsfSaslMessage::ConstructL( |
|
89 const TDesC8& aXmlns, |
|
90 const TDesC8& aLocalName, |
|
91 const TDesC8& aQName |
|
92 ) |
|
93 { |
|
94 BaseConstructL(aXmlns, aLocalName, aQName); |
|
95 } |
|
96 |
|
97 CIdWsfSaslMessage::~CIdWsfSaslMessage() |
|
98 { |
|
99 delete ipMechanism; |
|
100 delete ipParameterName; |
|
101 } |
|
102 |
|
103 TInt CIdWsfSaslMessage::ConstructInitRequestFromL( |
|
104 const TDesC8& aAllMechanismNames, |
|
105 CSenIdentityProvider& aAccount) |
|
106 { |
|
107 // fresh start |
|
108 delete ipMechanism; |
|
109 ipMechanism=NULL; |
|
110 delete ipParameterName; |
|
111 ipParameterName=NULL; |
|
112 |
|
113 MSenElement& element = AsElement(); |
|
114 element.AddAttrL(KMechanismName, aAllMechanismNames); |
|
115 |
|
116 TPtrC8 authzId = aAccount.AuthzID(); |
|
117 if (authzId.Length() > 0) |
|
118 { |
|
119 element.AddAttrL(KAuthzIdName, authzId); |
|
120 } |
|
121 |
|
122 TPtrC8 advisoryAuthnId = aAccount.AdvisoryAuthnID(); |
|
123 if (advisoryAuthnId.Length() > 0) |
|
124 { |
|
125 element.AddAttrL(KAdvisoryAuthnIdName, advisoryAuthnId); |
|
126 } |
|
127 return KErrNone; |
|
128 } |
|
129 |
|
130 TInt CIdWsfSaslMessage::ConstructRequestFromL( |
|
131 const TDesC8& aMech) |
|
132 { |
|
133 // fresh start |
|
134 delete ipMechanism; |
|
135 ipMechanism=NULL; |
|
136 delete ipParameterName; |
|
137 ipParameterName=NULL; |
|
138 |
|
139 AsElement().AddAttrL(KMechanismName, aMech); |
|
140 return KErrNone; |
|
141 } |
|
142 |
|
143 TInt CIdWsfSaslMessage::ConstructRequestFromL( |
|
144 const TDesC8& aMech, |
|
145 const TDesC8& aData |
|
146 ) |
|
147 { |
|
148 // fresh start |
|
149 delete ipMechanism; |
|
150 ipMechanism=NULL; |
|
151 delete ipParameterName; |
|
152 ipParameterName=NULL; |
|
153 |
|
154 TInt retVal = ConstructRequestFromL(aMech); |
|
155 HBufC8* pDataBase64 = iServiceManager.EncodeToBase64LC(aData); |
|
156 |
|
157 AsElement().AddElementL( |
|
158 AsElement().NamespaceURI(), KDataName).SetContentL(*pDataBase64); |
|
159 |
|
160 CleanupStack::PopAndDestroy(); // delete pDataBase64; |
|
161 return retVal; |
|
162 } |
|
163 |
|
164 TBool CIdWsfSaslMessage::IsContinue() |
|
165 { |
|
166 if(!ipStatus) |
|
167 { |
|
168 return EFalse; |
|
169 } |
|
170 else |
|
171 { |
|
172 return SenXmlUtils::EndsWith(*ipStatus, KContinue); |
|
173 } |
|
174 } |
|
175 |
|
176 TBool CIdWsfSaslMessage::IsAbort() |
|
177 { |
|
178 if (ipStatus == NULL) |
|
179 { |
|
180 return EFalse; |
|
181 } |
|
182 else |
|
183 { |
|
184 return SenXmlUtils::EndsWith(*ipStatus, KAbort); |
|
185 } |
|
186 } |
|
187 |
|
188 TPtrC8 CIdWsfSaslMessage::Mechanism() |
|
189 { |
|
190 if (!ipMechanism) |
|
191 { |
|
192 return KNullDesC8(); |
|
193 } |
|
194 else |
|
195 { |
|
196 return *ipMechanism; |
|
197 } |
|
198 } |
|
199 |
|
200 TPtrC8 CIdWsfSaslMessage::ParameterName() |
|
201 { |
|
202 if (!ipParameterName) |
|
203 { |
|
204 return KNullDesC8(); |
|
205 } |
|
206 else |
|
207 { |
|
208 return *ipParameterName; |
|
209 } |
|
210 } |
|
211 |
|
212 TPtrC8 CIdWsfSaslMessage::Data() |
|
213 { |
|
214 MSenElement* pDataElement = AsElement().Element(KDataName); |
|
215 if(pDataElement) |
|
216 { |
|
217 return pDataElement->Content(); |
|
218 } |
|
219 return KNullDesC8(); |
|
220 } |
|
221 |
|
222 // @return NULL if list is empty |
|
223 CSenPasswordTransform* CIdWsfSaslMessage::LastParsedPasswordTransform() |
|
224 { |
|
225 TInt count(iTransforms.Count()); |
|
226 if(count>0) |
|
227 { |
|
228 return iTransforms[count-1]; |
|
229 } |
|
230 else |
|
231 { |
|
232 return NULL; |
|
233 } |
|
234 } |
|
235 |
|
236 |
|
237 |
|
238 void CIdWsfSaslMessage::StartElementL( |
|
239 const TDesC8& aNsUri, |
|
240 const TDesC8& aLocalName, |
|
241 const TDesC8& aQName, |
|
242 const RAttributeArray& aAttributes ) |
|
243 { |
|
244 if (IsOk()) |
|
245 { |
|
246 CIdWsfDsQueryResponse::StartElementL(aNsUri, aLocalName, aQName, |
|
247 aAttributes); |
|
248 } |
|
249 else |
|
250 { |
|
251 switch (iState) |
|
252 { |
|
253 case KStateIgnore: |
|
254 { |
|
255 if (aLocalName == KSaslResponseName) |
|
256 { |
|
257 HBufC8* pNew = SenXmlUtils::AllocAttrValueL( |
|
258 aAttributes, |
|
259 KServerMechanismName |
|
260 ); |
|
261 delete ipMechanism; |
|
262 ipMechanism = pNew; |
|
263 } |
|
264 else if (aLocalName == KStatusName) |
|
265 { |
|
266 HBufC8* pNew = SenXmlUtils::AllocAttrValueL( |
|
267 aAttributes, |
|
268 KStatusCodeName |
|
269 ); |
|
270 delete ipStatus; |
|
271 ipStatus = pNew; |
|
272 } |
|
273 else if (aLocalName == KDataName) |
|
274 { |
|
275 DelegateParsingL(aNsUri, aLocalName, aQName, aAttributes); |
|
276 } |
|
277 else if (aLocalName == KPasswordTransformsName) |
|
278 { |
|
279 iTransforms.Reset(); // NOT owned.. |
|
280 iState = KStateParsingPwTransforms; |
|
281 } |
|
282 break; |
|
283 } |
|
284 case KStateParsingPwTransforms: |
|
285 { |
|
286 if (aLocalName == KTransformName) |
|
287 { |
|
288 |
|
289 TPtrC8 name = SenXmlUtils::AttrValue(aAttributes, |
|
290 KNameAttr); |
|
291 CSenPasswordTransform* pTransform = |
|
292 CSenPasswordTransform::NewL(name, iServiceManager); |
|
293 |
|
294 if(pTransform) |
|
295 { |
|
296 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel , |
|
297 _L8("CIdWsfSaslMessage::StartElementL - \ |
|
298 appending password transform: '%S'"), &name)); |
|
299 iTransforms.Append(pTransform); |
|
300 } |
|
301 } |
|
302 else if (aLocalName == KParameterName) |
|
303 { |
|
304 HBufC8* pNew = SenXmlUtils::AllocAttrValueL( |
|
305 aAttributes, |
|
306 KNameAttr |
|
307 ); |
|
308 delete ipParameterName; // free memory |
|
309 ipParameterName = pNew; |
|
310 TLSLOG_FORMAT((KSenCoreServiceManagerLogChannelBase , KMinLogLevel , |
|
311 _L("CIdWsfSaslMessage::StartElementL - \ |
|
312 parsing PasswordTransform parameter: '%S'"), |
|
313 ipParameterName)); |
|
314 ResetContentL(); |
|
315 } |
|
316 break; |
|
317 } |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 void CIdWsfSaslMessage::EndElementL( |
|
323 const TDesC8& aNsUri, |
|
324 const TDesC8& aLocalName, |
|
325 const TDesC8& aQName |
|
326 ) |
|
327 { |
|
328 if (IsOk()) |
|
329 { |
|
330 CIdWsfDsQueryResponse::EndElementL(aNsUri, aLocalName, aQName); |
|
331 } |
|
332 else |
|
333 { |
|
334 switch (iState) |
|
335 { |
|
336 case KStateParsingPwTransforms: |
|
337 { |
|
338 if (aLocalName == KParameterName) |
|
339 { |
|
340 CSenPasswordTransform* pLast = |
|
341 LastParsedPasswordTransform(); |
|
342 if(pLast) |
|
343 { |
|
344 pLast->SetParameterL(*ipParameterName, Content()); |
|
345 } |
|
346 } |
|
347 else if (aLocalName == KPasswordTransformsName) |
|
348 { |
|
349 ResetContentL(); |
|
350 iState = KStateIgnore; |
|
351 } |
|
352 break; |
|
353 } |
|
354 default: |
|
355 break; |
|
356 } |
|
357 } |
|
358 } |
|
359 |
|
360 RPointerArray<CSenPasswordTransform> CIdWsfSaslMessage::Transforms() |
|
361 { |
|
362 return iTransforms; |
|
363 } |
|
364 |
|
365 |
|
366 RFileLogger* CIdWsfSaslMessage::Log() const |
|
367 { |
|
368 return iServiceManager.Log(); |
|
369 } |
|
370 |
|
371 // End of File |
|
372 |