|
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 <SenDateUtils.h> |
|
27 #include <SenFacet.h> |
|
28 #include <SenXmlElement.h> // check if this include is needed(?) |
|
29 #include <SenXmlUtils.h> |
|
30 #include <SenCredential.h> |
|
31 |
|
32 #include "idwsfdsqueryresponse.h" |
|
33 #include "sendebug.h" |
|
34 |
|
35 |
|
36 namespace |
|
37 { |
|
38 _LIT8(KOkLowerCase, "ok"); |
|
39 _LIT8(KOkUpperCase, "OK"); |
|
40 |
|
41 _LIT8(KResourceIdName, "ResourceID"); |
|
42 _LIT8(KResourceOfferingName, "ResourceOffering"); |
|
43 _LIT8(KServiceInstanceName, "ServiceInstance"); |
|
44 _LIT8(KEncryptedResourceIdName, "EncryptedResourceID"); |
|
45 _LIT8(KProviderIdName, "ProviderID"); |
|
46 _LIT8(KCredentialRefName, "CredentialRef"); |
|
47 _LIT8(KServiceTypeName, "ServiceType"); |
|
48 _LIT8(KOptionName, "Option"); |
|
49 |
|
50 _LIT8(KVal_NotOnOrAfter, "NotOnOrAfter"); |
|
51 |
|
52 _LIT8(KDescriptionElementLocalName, "Description"); |
|
53 } |
|
54 |
|
55 CIdWsfDsQueryResponse* CIdWsfDsQueryResponse::NewL() |
|
56 { |
|
57 CIdWsfDsQueryResponse* pNew = NewLC(); |
|
58 CleanupStack::Pop(); // pNew; |
|
59 return pNew; |
|
60 } |
|
61 |
|
62 CIdWsfDsQueryResponse* CIdWsfDsQueryResponse::NewLC() |
|
63 { |
|
64 CIdWsfDsQueryResponse* pNew = new (ELeave) CIdWsfDsQueryResponse; |
|
65 CleanupStack::PushL(pNew); |
|
66 pNew->BaseConstructL(); |
|
67 return pNew; |
|
68 } |
|
69 |
|
70 |
|
71 CIdWsfDsQueryResponse* CIdWsfDsQueryResponse::NewL( |
|
72 const TDesC8& aNsUri, |
|
73 const TDesC8& aLocalName, |
|
74 const TDesC8& aQName |
|
75 ) |
|
76 { |
|
77 CIdWsfDsQueryResponse* pNew = NewLC( aNsUri, aLocalName, aQName ); |
|
78 CleanupStack::Pop(); // pNew; |
|
79 return pNew; |
|
80 } |
|
81 |
|
82 CIdWsfDsQueryResponse* CIdWsfDsQueryResponse::NewLC( |
|
83 const TDesC8& aNsUri, |
|
84 const TDesC8& aLocalName, |
|
85 const TDesC8& aQName |
|
86 ) |
|
87 { |
|
88 CIdWsfDsQueryResponse* pNew = new (ELeave) CIdWsfDsQueryResponse; |
|
89 CleanupStack::PushL(pNew); |
|
90 pNew->BaseConstructL(aNsUri, aLocalName, aQName); |
|
91 return pNew; |
|
92 } |
|
93 |
|
94 |
|
95 CIdWsfDsQueryResponse::CIdWsfDsQueryResponse() |
|
96 : ipResourceOffering(NULL), |
|
97 ipCredential(NULL), |
|
98 ipServiceInstance(NULL) |
|
99 { |
|
100 } |
|
101 |
|
102 void CIdWsfDsQueryResponse::BaseConstructL() |
|
103 { |
|
104 CSenBaseFragment::BaseConstructL( |
|
105 KQueryResponseXmlns, |
|
106 KQueryResponseName, |
|
107 KQueryResponseQName |
|
108 ); |
|
109 } |
|
110 |
|
111 void CIdWsfDsQueryResponse::BaseConstructL( |
|
112 const TDesC8& aNsUri, |
|
113 const TDesC8& aLocalName, |
|
114 const TDesC8& aQName |
|
115 ) |
|
116 { |
|
117 CSenBaseFragment::BaseConstructL(aNsUri, aLocalName, aQName); |
|
118 iNotOnOrAfter = Time::NullTTime(); |
|
119 } |
|
120 |
|
121 CIdWsfDsQueryResponse::~CIdWsfDsQueryResponse() |
|
122 { |
|
123 delete ipStatus; |
|
124 iResourceOfferings.ResetAndDestroy(); |
|
125 |
|
126 // should be NULL if appended to iResourceOfferings: |
|
127 delete ipResourceOffering; |
|
128 delete ipCredential; |
|
129 delete ipServiceInstance; |
|
130 } |
|
131 |
|
132 void CIdWsfDsQueryResponse::GetAllServicesL( |
|
133 RPointerArray<CIdWsfServiceInstance>& aDest ) |
|
134 { |
|
135 // Return all CIdWsfServiceInstance's |
|
136 for (TInt i = 0; i < iResourceOfferings.Count(); i++) |
|
137 { |
|
138 RPointerArray<CIdWsfServiceInstance>& services = |
|
139 iResourceOfferings[i]->ServicesL(); |
|
140 for (TInt j = 0; j < services.Count(); j++) |
|
141 { |
|
142 User::LeaveIfError(aDest.Append(services[j])); |
|
143 } |
|
144 } |
|
145 } |
|
146 |
|
147 void CIdWsfDsQueryResponse::StartElementL( |
|
148 const TDesC8& aNsUri, |
|
149 const TDesC8& aLocalName, |
|
150 const TDesC8& aQName, |
|
151 const RAttributeArray& aAttributes |
|
152 ) |
|
153 { |
|
154 switch (iState) |
|
155 { |
|
156 case KStateIgnore: |
|
157 { |
|
158 SaveNamespacesL(aAttributes, EFalse); |
|
159 |
|
160 // we are interested in the Status element |
|
161 if (aLocalName == KStatusName) |
|
162 { |
|
163 // we should save the status code |
|
164 HBufC8* pNew = |
|
165 SenXmlUtils::AllocAttrValueL(aAttributes, |
|
166 KStatusCodeName); |
|
167 delete ipStatus; |
|
168 ipStatus = pNew; |
|
169 } |
|
170 |
|
171 // we are interested in ResourceOffering |
|
172 else if (aLocalName == KResourceOfferingName) |
|
173 { |
|
174 // odd state: starts saving content |
|
175 iState = KStateParsingResourceOffering; |
|
176 ipResourceOffering = CIdWsfResourceOffering::NewL(); |
|
177 } |
|
178 |
|
179 //or in a Credentials |
|
180 else if (aLocalName == KCredentialsName) |
|
181 { |
|
182 iState = KStateParsingCredentials; |
|
183 TPtrC8 ptr = SenXmlUtils::AttrValue(aAttributes, |
|
184 KVal_NotOnOrAfter); |
|
185 if (ptr.Length()>0) |
|
186 { |
|
187 iNotOnOrAfter = SenDateUtils::FromXmlDateTimeL(ptr); |
|
188 } |
|
189 } |
|
190 break; |
|
191 } |
|
192 case KStateParsingResourceOffering: |
|
193 { |
|
194 // We clean the buffer so that we can save the element content |
|
195 // At endElement we will know what member of the resource offering |
|
196 // to set. |
|
197 ResetContentL(); |
|
198 // save namespace declarations and ensure that all local prefixes |
|
199 // are noted. |
|
200 SaveNamespacesL(aAttributes, ETrue); |
|
201 if (aLocalName == KServiceInstanceName) |
|
202 { |
|
203 // if this is second RO, delete the ipServiceInstance made |
|
204 // ready |
|
205 // previous RO's possible (but not encountered) next service |
|
206 // instance. |
|
207 // bugfix 2004-11-09 |
|
208 if(ipServiceInstance) |
|
209 { |
|
210 delete ipServiceInstance; |
|
211 ipServiceInstance = NULL; |
|
212 } |
|
213 |
|
214 ipServiceInstance = CIdWsfServiceInstance::NewL(); |
|
215 } |
|
216 if (aLocalName == KEncryptedResourceIdName) |
|
217 { |
|
218 iState = KStateParsingEncryptedResourceId; |
|
219 } |
|
220 break; |
|
221 } |
|
222 case KStateParsingEncryptedResourceId: |
|
223 { |
|
224 AllocContentSaverL(); |
|
225 WriteStartElementL(aNsUri, aLocalName, aQName, aAttributes); |
|
226 break; |
|
227 } |
|
228 case KStateParsingCredentials: |
|
229 { |
|
230 CSenCredential* pCredential = CSenCredential::NewL( |
|
231 aNsUri, aLocalName, aQName, aAttributes, AsElement()); |
|
232 |
|
233 CleanupStack::PushL(pCredential); // bugfix 2004-08-09 |
|
234 |
|
235 if (iNotOnOrAfter != Time::NullTTime()) |
|
236 { |
|
237 pCredential->SetValidUntil(iNotOnOrAfter); |
|
238 } |
|
239 |
|
240 delete ipCredential; |
|
241 ipCredential = pCredential; |
|
242 CleanupStack::Pop(); // class owns the pCredential now.. |
|
243 DelegateParsingL(*ipCredential); |
|
244 iState = KStateParsingSingleCredential; |
|
245 break; |
|
246 } |
|
247 default: |
|
248 { |
|
249 break; |
|
250 } |
|
251 } |
|
252 } |
|
253 |
|
254 void CIdWsfDsQueryResponse::EndElementL( |
|
255 const TDesC8& aNsUri, |
|
256 const TDesC8& aLocalName, |
|
257 const TDesC8& aQName) |
|
258 { |
|
259 switch(iState) |
|
260 { |
|
261 case KStateParsingResourceOffering: |
|
262 { |
|
263 if (aLocalName == KResourceOfferingName) |
|
264 { |
|
265 User::LeaveIfError( |
|
266 iResourceOfferings.Append(ipResourceOffering)); |
|
267 ipResourceOffering = NULL; |
|
268 iState = KStateIgnore; |
|
269 } |
|
270 else if (aLocalName == KResourceIdName || |
|
271 aLocalName == KEncryptedResourceIdName) |
|
272 { |
|
273 ipResourceOffering->SetResourceIdL(Content()); |
|
274 } |
|
275 |
|
276 else if (aLocalName == KDescriptionElementLocalName) |
|
277 { |
|
278 ipResourceOffering->AddServiceInstanceL(ipServiceInstance); |
|
279 |
|
280 // alloc new instance for the next parsing cycle |
|
281 ipServiceInstance = |
|
282 CIdWsfServiceInstance::NewL(*ipServiceInstance); |
|
283 break; |
|
284 } |
|
285 else |
|
286 { |
|
287 if (aLocalName == KProviderIdName) |
|
288 { |
|
289 ipServiceInstance->SetProviderIdL(Content()); |
|
290 break; |
|
291 } |
|
292 else if (aLocalName == KSecurityMechIdName) |
|
293 { |
|
294 ipServiceInstance->AddSecurityMechL(Content()); |
|
295 break; |
|
296 } |
|
297 else if (aLocalName == KCredentialRefName) |
|
298 { |
|
299 ipServiceInstance->AddCredentialRefL(Content()); |
|
300 break; |
|
301 } |
|
302 else if (aLocalName == KEndpointName) |
|
303 { |
|
304 ipServiceInstance->SetEndPointL(Content()); |
|
305 break; |
|
306 } |
|
307 else if (aLocalName == KServiceTypeName) |
|
308 { |
|
309 ipServiceInstance->SetServiceTypeL(Content()); |
|
310 break; |
|
311 } |
|
312 else if (aLocalName == KOptionName) |
|
313 { |
|
314 CSenFacet* pFacet = CSenFacet::NewL(); |
|
315 CleanupStack::PushL( pFacet ); |
|
316 pFacet->SetNameL(Content()); |
|
317 pFacet->SetTypeL(KDiscoOption); |
|
318 ipResourceOffering->SetFacetL(*pFacet); |
|
319 CleanupStack::PopAndDestroy( pFacet ); // SetFacetL does not take ownership but makes a copy of the facet insteadfs |
|
320 break; |
|
321 } |
|
322 } |
|
323 break; |
|
324 } |
|
325 case KStateParsingEncryptedResourceId: |
|
326 { |
|
327 if (aLocalName == KResourceIdName || |
|
328 aLocalName == KEncryptedResourceIdName) |
|
329 { |
|
330 ipResourceOffering->SetResourceIdL(Content()); |
|
331 iState = KStateParsingResourceOffering; |
|
332 } |
|
333 else WriteEndElementL(aNsUri, aLocalName, aQName); |
|
334 break; |
|
335 } |
|
336 case KStateParsingCredentials: |
|
337 { |
|
338 if (aLocalName == KCredentialsName) |
|
339 { |
|
340 iNotOnOrAfter = Time::NullTTime(); |
|
341 iState = KStateIgnore; |
|
342 } |
|
343 break; |
|
344 } |
|
345 case KStateParsingSingleCredential: |
|
346 { |
|
347 |
|
348 HBufC8* pAsXml = ipCredential->AsXmlL(); |
|
349 CleanupStack::PushL(pAsXml); |
|
350 const TDesC8& refId = ipCredential->Id(); |
|
351 |
|
352 if(pAsXml && refId.Length()>0) |
|
353 { |
|
354 ipCredential->DetachL(); |
|
355 |
|
356 TInt count(iResourceOfferings.Count()); |
|
357 for (TInt i = 0; i < count; i++) |
|
358 { |
|
359 iResourceOfferings[i]->AddCredentialL(*ipCredential); |
|
360 } |
|
361 delete ipCredential; |
|
362 } |
|
363 else |
|
364 delete ipCredential; // ownership was _not_ transferred(!), |
|
365 // forced to delete here |
|
366 |
|
367 CleanupStack::PopAndDestroy(); // pAsXml; |
|
368 |
|
369 ipCredential = NULL; |
|
370 iState = KStateParsingCredentials; |
|
371 break; |
|
372 } |
|
373 default: // corresponds with ref-impl (Java) having case |
|
374 // BaseFragment.IGNORE: break; |
|
375 { |
|
376 break; |
|
377 } |
|
378 } |
|
379 } |
|
380 |
|
381 TBool CIdWsfDsQueryResponse::IsOk() |
|
382 { |
|
383 if (!ipStatus) |
|
384 { |
|
385 return EFalse; |
|
386 } |
|
387 else |
|
388 { |
|
389 return (SenXmlUtils::EndsWith(*ipStatus, KOkLowerCase) || |
|
390 SenXmlUtils::EndsWith(*ipStatus, KOkUpperCase)); |
|
391 } |
|
392 } |
|
393 |
|
394 // returns the first one (oldest) added.. |
|
395 TPtrC8 CIdWsfDsQueryResponse::ResourceId() |
|
396 { |
|
397 if (iResourceOfferings.Count() > 0) |
|
398 { |
|
399 return iResourceOfferings[0]->ResourceId(); |
|
400 } |
|
401 else |
|
402 { |
|
403 return NULL; |
|
404 } |
|
405 } |
|
406 |
|
407 RPointerArray<CIdWsfResourceOffering>& |
|
408 CIdWsfDsQueryResponse::ResourceOfferingsL() |
|
409 { |
|
410 return iResourceOfferings; |
|
411 } |