|
1 /* |
|
2 * Copyright (c) 2004 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 <SenXmlUtils.h> |
|
26 #include <SenCredential.h> |
|
27 #include <SenFacet.h> |
|
28 #include <SenServiceConnection.h> |
|
29 #include <SenXmlElement.h> |
|
30 |
|
31 #include "idwsfserviceinstance.h" |
|
32 |
|
33 namespace |
|
34 { |
|
35 const TInt KFLATBUF_SIZE = 128; |
|
36 } |
|
37 |
|
38 CIdWsfServiceInstance* CIdWsfServiceInstance::NewL() |
|
39 { |
|
40 CIdWsfServiceInstance* pNew = CIdWsfServiceInstance::NewLC(); |
|
41 CleanupStack::Pop(); // pNew |
|
42 return pNew; |
|
43 } |
|
44 |
|
45 CIdWsfServiceInstance* CIdWsfServiceInstance::NewLC() |
|
46 { |
|
47 CIdWsfServiceInstance* pNew = new (ELeave) CIdWsfServiceInstance; |
|
48 CleanupStack::PushL(pNew); |
|
49 pNew->ConstructL(KNullDesC8(), KNullDesC8()); |
|
50 return pNew; |
|
51 } |
|
52 |
|
53 CIdWsfServiceInstance* CIdWsfServiceInstance::NewL(const TDesC8& aUri) |
|
54 { |
|
55 CIdWsfServiceInstance* pNew = CIdWsfServiceInstance::NewLC(aUri); |
|
56 CleanupStack::Pop(); // pNew |
|
57 return pNew; |
|
58 } |
|
59 |
|
60 CIdWsfServiceInstance* CIdWsfServiceInstance::NewLC(const TDesC8& aUri) |
|
61 { |
|
62 CIdWsfServiceInstance* pNew = new (ELeave) CIdWsfServiceInstance; |
|
63 CleanupStack::PushL(pNew); |
|
64 pNew->ConstructL(aUri, KNullDesC8()); |
|
65 return pNew; |
|
66 } |
|
67 |
|
68 CIdWsfServiceInstance* CIdWsfServiceInstance::NewL( |
|
69 CIdWsfServiceInstance& aTemplate) |
|
70 { |
|
71 CIdWsfServiceInstance* pNew = CIdWsfServiceInstance::NewLC(aTemplate); |
|
72 CleanupStack::Pop(); // pNew |
|
73 return pNew; |
|
74 } |
|
75 |
|
76 CIdWsfServiceInstance* CIdWsfServiceInstance::NewLC( |
|
77 CIdWsfServiceInstance& aTemplate) |
|
78 { |
|
79 CIdWsfServiceInstance* pNew = new (ELeave) CIdWsfServiceInstance; |
|
80 CleanupStack::PushL(pNew); |
|
81 pNew->ConstructL(aTemplate.ServiceType(), aTemplate.ProviderId()); |
|
82 return pNew; |
|
83 } |
|
84 |
|
85 CIdWsfServiceInstance::CIdWsfServiceInstance() : |
|
86 CSenWSDescription( EIdWsfServiceInstance ), |
|
87 ipProviderId( NULL ), |
|
88 ipEndpoint( NULL ), |
|
89 ipServiceType( NULL ), |
|
90 ipResourceId( NULL ), |
|
91 ipMechanisms( NULL ), |
|
92 ipCredentialRefs( NULL ) |
|
93 { |
|
94 } |
|
95 |
|
96 void CIdWsfServiceInstance::ConstructL(const TDesC8& aUri, |
|
97 const TDesC8& aProviderId) |
|
98 { |
|
99 CSenDomFragment::BaseConstructL(NewElementName()); |
|
100 |
|
101 HBufC8* pNew = NULL; |
|
102 if (aUri != KNullDesC8) |
|
103 { |
|
104 pNew = aUri.AllocL(); |
|
105 } |
|
106 ipServiceType = pNew; |
|
107 SetProviderIdL(aProviderId); |
|
108 } |
|
109 |
|
110 CIdWsfServiceInstance::~CIdWsfServiceInstance() |
|
111 { |
|
112 delete ipProviderId; |
|
113 delete ipResourceId; |
|
114 delete ipEndpoint; |
|
115 |
|
116 delete ipServiceType; |
|
117 delete ipMechanisms; |
|
118 delete ipCredentialRefs; |
|
119 |
|
120 iCredentialList.ResetAndDestroy(); |
|
121 iFacets.ResetAndDestroy(); |
|
122 } |
|
123 |
|
124 TBool CIdWsfServiceInstance::Matches( |
|
125 MSenServiceDescription& aOtherServiceDescription) |
|
126 { |
|
127 TPtrC8 patternEndpoint = aOtherServiceDescription.Endpoint(); |
|
128 TPtrC8 thisEndpoint = Endpoint(); |
|
129 |
|
130 if(patternEndpoint.Length()>0) |
|
131 { |
|
132 if(!(thisEndpoint.Length()>0 && patternEndpoint == thisEndpoint)) |
|
133 { |
|
134 return EFalse; |
|
135 } |
|
136 } |
|
137 |
|
138 TPtrC8 patternContract = aOtherServiceDescription.Contract(); |
|
139 TPtrC8 thisContract = Contract(); |
|
140 |
|
141 if(patternContract.Length()>0) |
|
142 { |
|
143 if(!(thisContract.Length()>0 && patternContract == thisContract)) |
|
144 { |
|
145 return EFalse; |
|
146 } |
|
147 } |
|
148 return ETrue; |
|
149 } |
|
150 |
|
151 TBool CIdWsfServiceInstance::Matches( |
|
152 CIdWsfServiceInstance& aOtherServiceInstance) |
|
153 { |
|
154 if (!Matches((MSenServiceDescription&)aOtherServiceInstance)) return EFalse; |
|
155 |
|
156 TPtrC8 patternProvider = aOtherServiceInstance.ProviderId(); |
|
157 TPtrC8 thisProvider = ProviderId(); |
|
158 |
|
159 if(patternProvider.Length()>0) |
|
160 { |
|
161 if(!(thisProvider.Length()>0 && patternProvider == thisProvider)) |
|
162 return EFalse; |
|
163 } |
|
164 return ETrue; |
|
165 } |
|
166 |
|
167 |
|
168 TPtrC8 CIdWsfServiceInstance::Contract() |
|
169 { |
|
170 if (ipServiceType) |
|
171 return *ipServiceType; |
|
172 else |
|
173 return KNullDesC8(); |
|
174 } |
|
175 |
|
176 TPtrC8 CIdWsfServiceInstance::FrameworkId() |
|
177 { |
|
178 return KDefaultIdWsfFrameworkID(); |
|
179 } |
|
180 |
|
181 TPtrC8 CIdWsfServiceInstance::FrameworkVersion() |
|
182 { |
|
183 return KIdWsfFrameworkVersion(); |
|
184 } |
|
185 |
|
186 void CIdWsfServiceInstance::SetContractL(const TDesC8& aContract) |
|
187 { |
|
188 HBufC8* pNew = NULL; |
|
189 if(aContract.Length()>0) |
|
190 pNew = aContract.AllocL(); |
|
191 |
|
192 delete ipServiceType; |
|
193 ipServiceType = pNew; |
|
194 } |
|
195 |
|
196 void CIdWsfServiceInstance::WriteAsXMLToL(RWriteStream& /* aWriteStream */) |
|
197 { |
|
198 // Nothing to do, because for ID-WSF we never save ServiceInstances, |
|
199 // only sessions. |
|
200 return; |
|
201 } |
|
202 |
|
203 HBufC* CIdWsfServiceInstance::AsXmlUnicodeL() |
|
204 { |
|
205 // Nothing to do, because for ID-WSF we never save ServiceInstances, |
|
206 // only sessions. |
|
207 // note: could return NULL |
|
208 return KNullDesC().AllocL(); |
|
209 } |
|
210 |
|
211 HBufC8* CIdWsfServiceInstance::AsXmlL() |
|
212 { |
|
213 // Nothing to do, because for ID-WSF we never save ServiceInstances, |
|
214 // only sessions. |
|
215 // note: could return NULL |
|
216 return KNullDesC8().AllocL(); |
|
217 } |
|
218 |
|
219 TPtrC8 CIdWsfServiceInstance::ProviderId() |
|
220 { |
|
221 if(ipProviderId) |
|
222 return *ipProviderId; |
|
223 else |
|
224 return KNullDesC8(); |
|
225 } |
|
226 |
|
227 TPtrC8 CIdWsfServiceInstance::ResourceId() |
|
228 { |
|
229 if (ipResourceId) |
|
230 return *ipResourceId; |
|
231 else |
|
232 return KNullDesC8(); |
|
233 } |
|
234 |
|
235 TPtrC8 CIdWsfServiceInstance::Endpoint() |
|
236 { |
|
237 if (ipEndpoint) |
|
238 return *ipEndpoint; |
|
239 else |
|
240 return KNullDesC8(); |
|
241 } |
|
242 |
|
243 TPtrC8 CIdWsfServiceInstance::ServiceType() |
|
244 { |
|
245 if (ipServiceType) |
|
246 return *ipServiceType; |
|
247 else |
|
248 return KNullDesC8(); |
|
249 } |
|
250 |
|
251 TInt CIdWsfServiceInstance::SetProviderIdL( const TDesC8& aURI ) |
|
252 { |
|
253 TInt retVal( KErrNone ); |
|
254 HBufC8* pNew = NULL; |
|
255 if( aURI.Length() > 0 ) |
|
256 { |
|
257 pNew = aURI.AllocL(); |
|
258 } |
|
259 // else |
|
260 // { |
|
261 // retVal = KErrArgument; |
|
262 // } |
|
263 delete ipProviderId; |
|
264 ipProviderId = pNew; |
|
265 return retVal; |
|
266 } |
|
267 |
|
268 void CIdWsfServiceInstance::SetResourceIdL( const TDesC8& aURI ) |
|
269 { |
|
270 HBufC8* pNew = NULL; |
|
271 if(aURI.Length()>0) |
|
272 pNew = aURI.AllocL(); |
|
273 delete ipResourceId; |
|
274 ipResourceId = pNew; |
|
275 } |
|
276 |
|
277 void CIdWsfServiceInstance::SetEndPointL(const TDesC8& aURI) |
|
278 { |
|
279 HBufC8* pNew = NULL; |
|
280 if(aURI.Length()>0) |
|
281 pNew = aURI.AllocL(); |
|
282 delete ipEndpoint; |
|
283 ipEndpoint = pNew; |
|
284 } |
|
285 |
|
286 void CIdWsfServiceInstance::SetServiceTypeL(const TDesC8& aURI) |
|
287 { |
|
288 HBufC8* pNew = NULL; |
|
289 if(aURI.Length()>0) |
|
290 pNew = aURI.AllocL(); |
|
291 delete ipServiceType; |
|
292 ipServiceType = pNew; |
|
293 } |
|
294 |
|
295 CDesC8Array& CIdWsfServiceInstance::MechanismsL() |
|
296 { |
|
297 if(!ipMechanisms) |
|
298 { |
|
299 ipMechanisms = new (ELeave) CDesC8ArrayFlat(KFLATBUF_SIZE); |
|
300 } |
|
301 return *ipMechanisms; |
|
302 } |
|
303 |
|
304 CDesC8Array& CIdWsfServiceInstance::CredentialRefsL() |
|
305 { |
|
306 if(!ipCredentialRefs) |
|
307 { |
|
308 ipCredentialRefs = new (ELeave) CDesC8ArrayFlat(KFLATBUF_SIZE); |
|
309 } |
|
310 return *ipCredentialRefs; |
|
311 } |
|
312 |
|
313 TBool CIdWsfServiceInstance::SupportsMechanism(const TDesC8& aURI) |
|
314 { |
|
315 if (ipMechanisms) |
|
316 { |
|
317 TInt pos; |
|
318 return (ipMechanisms->Find(aURI, pos, ECmpNormal) == KErrNone); |
|
319 } |
|
320 return EFalse; |
|
321 } |
|
322 |
|
323 CSenCredential* CIdWsfServiceInstance::Credential() |
|
324 { |
|
325 CSenCredential* pCredential = NULL; |
|
326 TInt count(iCredentialList.Count()); |
|
327 for(TInt i=0; i<count && pCredential == NULL; i++) |
|
328 { |
|
329 pCredential = iCredentialList[i]; |
|
330 } |
|
331 return pCredential; |
|
332 } |
|
333 |
|
334 |
|
335 void CIdWsfServiceInstance::SetCredentialL(const TDesC8& aIdRef, |
|
336 const CSenCredential& aCredential) |
|
337 { |
|
338 TInt refCount(CredentialRefsL().Count()); |
|
339 for (TInt i = 0; i < refCount; i++) |
|
340 { |
|
341 // Remove IDREFs and add actual credential |
|
342 if (CredentialRefsL()[i] == aIdRef) |
|
343 { |
|
344 CSenCredential* pCredential = CSenCredential::NewL(aCredential); |
|
345 iCredentialList.Append(pCredential); |
|
346 ipCredentialRefs->Delete(i); |
|
347 break; |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 void CIdWsfServiceInstance::SetCredentialL(const CSenCredential& aCredential) |
|
353 { |
|
354 const TDesC8& idRef = ((CSenCredential&)aCredential).Id(); |
|
355 SetCredentialL(idRef, aCredential); |
|
356 } |
|
357 |
|
358 void CIdWsfServiceInstance::AddSecurityMechL(const TDesC8& aUri) |
|
359 { |
|
360 MechanismsL().AppendL(aUri); |
|
361 } |
|
362 |
|
363 void CIdWsfServiceInstance::AddCredentialRefL(const TDesC8& aIdRef) |
|
364 { |
|
365 CredentialRefsL().AppendL(aIdRef); |
|
366 } |
|
367 |
|
368 TInt CIdWsfServiceInstance::HasFacetL(const TDesC8& aURI, TBool& aHasFacet) |
|
369 { |
|
370 aHasFacet = EFalse; |
|
371 TInt count(iFacets.Count()); |
|
372 |
|
373 for (TInt i=0;i<count && !aHasFacet;i++) |
|
374 { |
|
375 if (iFacets[i]->Name() == aURI) |
|
376 { |
|
377 aHasFacet = ETrue; |
|
378 } |
|
379 } |
|
380 |
|
381 return KErrNone; |
|
382 } |
|
383 |
|
384 TInt CIdWsfServiceInstance::FacetValue(TDesC8& aURI, HBufC8*& aValueTo) |
|
385 { |
|
386 delete aValueTo; |
|
387 aValueTo = NULL; |
|
388 |
|
389 TInt retVal = KErrNotFound; |
|
390 TInt count(iFacets.Count()); |
|
391 |
|
392 for (TInt i=0;i<count && retVal == KErrNotFound;i++) |
|
393 { |
|
394 if (iFacets[i]->Name() == aURI) |
|
395 { |
|
396 aValueTo = iFacets[i]->Value().Alloc(); |
|
397 if (aValueTo == NULL) retVal = KErrNoMemory; |
|
398 else retVal = KErrNone; |
|
399 } |
|
400 } |
|
401 return retVal; |
|
402 } |
|
403 |
|
404 TInt CIdWsfServiceInstance::AddFacetL(const CSenFacet& aFacet) |
|
405 { |
|
406 return SetFacetL(aFacet); |
|
407 } |
|
408 |
|
409 TInt CIdWsfServiceInstance::SetFacetL(const CSenFacet& aFacet) |
|
410 { |
|
411 TBool hasFacet; |
|
412 HasFacetL(((CSenFacet&)aFacet).Name(),hasFacet); |
|
413 if (hasFacet) |
|
414 { |
|
415 RemoveFacet(((CSenFacet&)aFacet).Name()); |
|
416 } |
|
417 CSenFacet* pNewFacet = CSenFacet::NewL(((CSenFacet&)aFacet)); |
|
418 return iFacets.Append(pNewFacet); |
|
419 } |
|
420 |
|
421 TInt CIdWsfServiceInstance::RemoveFacet(const TDesC8& aURI) |
|
422 { |
|
423 TInt count(iFacets.Count()); |
|
424 |
|
425 for (TInt i=0;i<count;i++) |
|
426 { |
|
427 if (iFacets[i]->Name() == aURI) |
|
428 { |
|
429 delete iFacets[i]; |
|
430 iFacets.Remove(i); |
|
431 return KErrNone; |
|
432 } |
|
433 } |
|
434 |
|
435 return KErrNotFound; |
|
436 } |
|
437 |
|
438 TInt CIdWsfServiceInstance::FacetsL(RFacetArray& aFacetArray) |
|
439 { |
|
440 CSenFacet* pFacet = NULL; |
|
441 TInt count(iFacets.Count()); |
|
442 for (TInt i=0; i<count; i++) |
|
443 { |
|
444 pFacet = CSenFacet::NewL(*iFacets[i]); |
|
445 aFacetArray.Append(pFacet); |
|
446 } |
|
447 return KErrNone; |
|
448 } |
|
449 |
|
450 TInt CIdWsfServiceInstance::ScoreMatchL(MSenServiceDescription& aPattern) |
|
451 { |
|
452 TInt score(0); |
|
453 |
|
454 if ((aPattern.Endpoint().Length() > 0) && |
|
455 (aPattern.Endpoint() == Endpoint())) |
|
456 { |
|
457 score++; |
|
458 } |
|
459 if ((aPattern.Contract().Length() > 0) && |
|
460 (aPattern.Contract() == Contract())) |
|
461 { |
|
462 score++; |
|
463 } |
|
464 |
|
465 RFacetArray otherFacets; |
|
466 CleanupClosePushL(otherFacets); |
|
467 aPattern.FacetsL(otherFacets); |
|
468 |
|
469 HBufC8* pFacetValue = NULL; |
|
470 TPtrC8 facetName; |
|
471 |
|
472 TInt count(otherFacets.Count()); |
|
473 for (TInt i=0; i<count; i++) |
|
474 { |
|
475 facetName.Set(otherFacets[i]->Name()); |
|
476 FacetValue(facetName,pFacetValue); |
|
477 if (pFacetValue && *pFacetValue == otherFacets[i]->Value()) |
|
478 { |
|
479 score++; |
|
480 } |
|
481 delete pFacetValue; |
|
482 pFacetValue = NULL; |
|
483 } |
|
484 |
|
485 otherFacets.ResetAndDestroy(); |
|
486 CleanupStack::Pop(); // otherFacets |
|
487 |
|
488 return score; |
|
489 } |
|
490 |
|
491 // equals to CSenWSDescription implementation at the moment |
|
492 TBool CIdWsfServiceInstance::HasEqualPrimaryKeysL(MSenServiceDescription& aCandidate) |
|
493 { |
|
494 TBool retVal(EFalse); |
|
495 if(aCandidate.Endpoint() == Endpoint() && |
|
496 aCandidate.Contract() == Contract() && |
|
497 aCandidate.FrameworkId() == FrameworkId()) |
|
498 { |
|
499 retVal = ETrue; |
|
500 } |
|
501 return retVal; |
|
502 } |
|
503 |
|
504 |
|
505 TBool CIdWsfServiceInstance::HasSuperClass( TDescriptionClassType aType ) |
|
506 { |
|
507 if( aType == MSenServiceDescription::EWSDescription ) // direct superclass! |
|
508 { |
|
509 // If asked type is the know *direct* father/mother, return true: |
|
510 return ETrue; |
|
511 } |
|
512 else |
|
513 { |
|
514 // Otherwise, ask from superclass (chain, recursively) |
|
515 return CSenWSDescription::HasSuperClass( aType ); |
|
516 } |
|
517 } |
|
518 |
|
519 |
|
520 |
|
521 // End of File |