|
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 "seninternalwspolicy.h" |
|
27 #include "SenFacet.h" |
|
28 #include <SenXmlElement.h> |
|
29 #include <SenXmlUtils.h> |
|
30 #include "senwsdescription.h" |
|
31 #include "SenDateUtils.h" |
|
32 #include "senservicepolicy.h" |
|
33 #include "wspolicyutils.h" |
|
34 |
|
35 |
|
36 #ifdef SYMBIAN_SECURE_ECOM |
|
37 // for S60 FP3 (2.8) platform or newer (3.0 and above) |
|
38 #include <xml/attribute.h> // needed for RAttributeArray |
|
39 //#else // for S60 FP2 platform (2.6) or older |
|
40 //#include "Attribute.h" |
|
41 #endif |
|
42 |
|
43 #include <xmlengnodelist.h> |
|
44 using namespace Xml; |
|
45 using namespace SenWSInternalPolicy; |
|
46 namespace |
|
47 { |
|
48 const TInt KFlatBufSize = 128; |
|
49 } |
|
50 CSenInternalWsPolicy* CSenInternalWsPolicy::NewL() |
|
51 { |
|
52 CSenInternalWsPolicy* pNew = NewLC(); |
|
53 CleanupStack::Pop(); // pNew; |
|
54 return pNew; |
|
55 } |
|
56 |
|
57 CSenInternalWsPolicy* CSenInternalWsPolicy::NewLC() |
|
58 { |
|
59 CSenInternalWsPolicy* pNew = new (ELeave) CSenInternalWsPolicy; |
|
60 CleanupStack::PushL(pNew); |
|
61 pNew->ConstructL(KSenWSPolicyMetadata); |
|
62 return pNew; |
|
63 } |
|
64 |
|
65 CSenInternalWsPolicy* CSenInternalWsPolicy::NewL( |
|
66 const TDesC8& aNsUri, |
|
67 const TDesC8& aLocalName, |
|
68 const TDesC8& aQName, |
|
69 const RAttributeArray& aAttributes) |
|
70 { |
|
71 CSenInternalWsPolicy* pNew = NewLC(aNsUri, aLocalName, aQName, aAttributes); |
|
72 CleanupStack::Pop(); // pNew; |
|
73 return pNew; |
|
74 } |
|
75 |
|
76 CSenInternalWsPolicy* CSenInternalWsPolicy::NewLC( |
|
77 const TDesC8& aNsUri, |
|
78 const TDesC8& aLocalName, |
|
79 const TDesC8& aQName, |
|
80 const RAttributeArray& aAttributes) |
|
81 { |
|
82 CSenInternalWsPolicy* pNew = new (ELeave) CSenInternalWsPolicy; |
|
83 CleanupStack::PushL(pNew); |
|
84 pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttributes); |
|
85 return pNew; |
|
86 } |
|
87 |
|
88 CSenInternalWsPolicy* CSenInternalWsPolicy::NewL( |
|
89 const TDesC8& aNsUri, |
|
90 const TDesC8& aLocalName, |
|
91 const TDesC8& aQName, |
|
92 const RAttributeArray& aAttributes, |
|
93 CSenElement& aParent) |
|
94 { |
|
95 CSenInternalWsPolicy* pNew = NewLC(aNsUri, aLocalName, |
|
96 aQName, aAttributes, aParent); |
|
97 CleanupStack::Pop(); // pNew; |
|
98 return pNew; |
|
99 } |
|
100 |
|
101 CSenInternalWsPolicy* CSenInternalWsPolicy::NewLC( |
|
102 const TDesC8& aNsUri, |
|
103 const TDesC8& aLocalName, |
|
104 const TDesC8& aQName, |
|
105 const RAttributeArray& aAttributes, |
|
106 CSenElement& aParent) |
|
107 { |
|
108 CSenInternalWsPolicy* pNew = new (ELeave) CSenInternalWsPolicy; |
|
109 CleanupStack::PushL(pNew); |
|
110 pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttributes, aParent); |
|
111 return pNew; |
|
112 } |
|
113 void CSenInternalWsPolicy::ConstructL(const TDesC8& aNsUri, |
|
114 const TDesC8& aLocalName, |
|
115 const TDesC8& aQName, |
|
116 const RAttributeArray& aAttributes, |
|
117 CSenElement& aParent) |
|
118 { |
|
119 BaseConstructL(aNsUri, aLocalName, aQName, aAttributes, aParent); |
|
120 } |
|
121 void CSenInternalWsPolicy::ConstructL(const TDesC8& aNsUri, |
|
122 const TDesC8& aLocalName, |
|
123 const TDesC8& aQName, |
|
124 const RAttributeArray& aAttributes) |
|
125 { |
|
126 BaseConstructL(aNsUri, aLocalName, aQName, aAttributes); |
|
127 } |
|
128 |
|
129 void CSenInternalWsPolicy::ConstructL(const TDesC8& aLocalName) |
|
130 { |
|
131 CSenBaseFragment::BaseConstructL(aLocalName); |
|
132 } |
|
133 |
|
134 CSenInternalWsPolicy::CSenInternalWsPolicy() |
|
135 { |
|
136 } |
|
137 |
|
138 CSenInternalWsPolicy::~CSenInternalWsPolicy() |
|
139 { |
|
140 delete ipIdentifier; |
|
141 } |
|
142 |
|
143 TBool CSenInternalWsPolicy::IsApplicableL(CSenWSDescription& aPattern) |
|
144 { |
|
145 TPtrC8 value; |
|
146 CSenElement& patternElement = ((CSenWSDescription&)aPattern).AsElement(); |
|
147 CSenWSPolicyIdentifier& identifier = IdentifierL(); |
|
148 |
|
149 TPtrC8 contract = aPattern.Contract(); |
|
150 TPtrC8 endpoint = aPattern.Endpoint(); |
|
151 CSenElement* providerId = aPattern.AsElement().Element(KProviderIdLocalName); |
|
152 if(providerId && providerId->HasContent()) |
|
153 { |
|
154 TPtrC8 provider = providerId->Content(); |
|
155 TPtrC8 valProviderId = identifier.ProviderIdL(); |
|
156 TPtrC8 valEndpoint = identifier.EndpointL(); |
|
157 TPtrC8 valContract = identifier.ContractL(); |
|
158 |
|
159 if(contract == valContract && |
|
160 endpoint == valEndpoint && |
|
161 provider == valProviderId) |
|
162 { |
|
163 return ETrue; |
|
164 } |
|
165 } |
|
166 return EFalse; |
|
167 } |
|
168 |
|
169 TBool CSenInternalWsPolicy::IsApplicableL(const TDesC8& aPolicyEndpoint) |
|
170 { |
|
171 CSenWSPolicyIdentifier& identifier = IdentifierL(); |
|
172 |
|
173 TPtrC8 valEndpoint = identifier.MetadataEndpointL(); |
|
174 if(valEndpoint == aPolicyEndpoint) |
|
175 { |
|
176 return ETrue; |
|
177 } |
|
178 return EFalse; |
|
179 } |
|
180 |
|
181 TBool CSenInternalWsPolicy::IsApplicableL(CSenInternalWsPolicy* aInternalPolicy) |
|
182 { |
|
183 CSenWSPolicyIdentifier& identifier = IdentifierL(); |
|
184 CSenWSPolicyIdentifier& id = aInternalPolicy->IdentifierL(); |
|
185 |
|
186 TPtrC8 valmetaEndpoint = identifier.MetadataEndpointL(); |
|
187 TPtrC8 metaendpoint = id.MetadataEndpointL(); |
|
188 TPtrC8 valEndpoint = identifier.EndpointL(); |
|
189 TPtrC8 endpoint = id.EndpointL(); |
|
190 TPtrC8 valcontract = identifier.ContractL(); |
|
191 TPtrC8 contract = id.ContractL(); |
|
192 |
|
193 if(valmetaEndpoint == metaendpoint && |
|
194 valEndpoint == endpoint && |
|
195 valcontract == contract) |
|
196 { |
|
197 return ETrue; |
|
198 } |
|
199 return EFalse; |
|
200 |
|
201 } |
|
202 TInt CSenInternalWsPolicy::PolicyCountL() |
|
203 { |
|
204 TInt count = 0; |
|
205 CSenElement& element = AsElement(); |
|
206 RPointerArray<CSenElement> list = element.ElementsL(); |
|
207 CleanupClosePushL(list); |
|
208 count = list.Count(); |
|
209 CleanupStack::PopAndDestroy(&list); // Close() |
|
210 return count; |
|
211 |
|
212 } |
|
213 TBool CSenInternalWsPolicy::UpdateMetadataEndpointL(CSenInternalWsPolicy* aInternalPolicy, TInt& aExist) |
|
214 { |
|
215 //see if the New policy is in database |
|
216 //&aPolicy is new Policy |
|
217 //if the new policy is present and newer then the current -- we have to replace it |
|
218 //if the new policy is present and same then the current -- check expiry - if same then no replace |
|
219 //if the new policy dont have a policy then get the policy from here |
|
220 //if the new policy is same (from expiry time) |
|
221 |
|
222 CSenWSPolicyIdentifier& newId = aInternalPolicy->IdentifierL(); |
|
223 CSenWSPolicyIdentifier& id = IdentifierL(); |
|
224 |
|
225 if (IsApplicableL(aInternalPolicy)) |
|
226 { |
|
227 aExist = KErrNone; |
|
228 id.UpdateMetadataEndpointL(newId); |
|
229 return ETrue; |
|
230 } |
|
231 return EFalse; |
|
232 |
|
233 } |
|
234 |
|
235 void CSenInternalWsPolicy::SetIdentifier(CSenWSPolicyIdentifier* aIdentifier) |
|
236 { |
|
237 if ( ipIdentifier ) |
|
238 { |
|
239 delete ipIdentifier; |
|
240 } |
|
241 |
|
242 ipIdentifier = aIdentifier; |
|
243 } |
|
244 |
|
245 CSenWSPolicyIdentifier& CSenInternalWsPolicy::IdentifierL() |
|
246 { |
|
247 if ( !ipIdentifier ) |
|
248 { |
|
249 ipIdentifier = CSenWSPolicyIdentifier::NewL(); |
|
250 } |
|
251 |
|
252 return *ipIdentifier; |
|
253 } |
|
254 |
|
255 |
|
256 void CSenInternalWsPolicy::SetSession(CSenServiceSession& aSession) |
|
257 { |
|
258 ipSession = &aSession; |
|
259 } |
|
260 |
|
261 CSenServiceSession* CSenInternalWsPolicy::Session() |
|
262 { |
|
263 return ipSession; |
|
264 } |
|
265 |
|
266 TPtrC8 CSenInternalWsPolicy::ExpiryTimeL(CSenElement* aElement) |
|
267 { |
|
268 if(CSenWSPolicyIdentifier::HasAttributeL(aElement, KSenWSPolicyValidUntil)) |
|
269 { |
|
270 return IdentifierL().ElementAttribValueL(aElement, KSenWSPolicyValidUntil); |
|
271 } |
|
272 |
|
273 return KNullDesC8(); |
|
274 |
|
275 } |
|
276 TInt CSenInternalWsPolicy::AddMetadataPolicyL(CSenElement* aElement) |
|
277 { |
|
278 if(aElement == NULL) |
|
279 return KErrArgument; |
|
280 |
|
281 TInt retVal(KErrNotFound); |
|
282 TPtrC8 metaendpoint = CWSPolicyUtils::PolicyUriL(aElement); |
|
283 TPtrC8 expiry = ExpiryTimeL(aElement); |
|
284 |
|
285 CSenElement& ele = AsElement(); |
|
286 CSenElement* metaEndPointEle= IdentifierL().MetadataEndpointElementL(); |
|
287 if (metaEndPointEle) |
|
288 { |
|
289 //confirm if the expiry time is greater then current time |
|
290 TTime now; |
|
291 now.UniversalTime(); |
|
292 TTime validuntil = SenDateUtils::FromXmlDateTimeL(expiry); |
|
293 if(validuntil > now) |
|
294 { |
|
295 SenXmlUtils::AddAttributeL(*metaEndPointEle, KSenWSPolicyValidUntil,expiry); |
|
296 //Have to copy incase for multiple SDs have same policy |
|
297 //we cannot give ownership of Policy here so create a copy and dont take ownership |
|
298 |
|
299 CSenElement* copy = CSenXmlElement::NewL(aElement->LocalName()); |
|
300 copy->CopyFromL(*aElement); |
|
301 ele.AddElementL(*copy); |
|
302 retVal = KErrNone; |
|
303 } |
|
304 } |
|
305 |
|
306 return retVal; |
|
307 } |
|
308 TInt CSenInternalWsPolicy::UpdateMetadataPolicyL(CSenElement* aElement) |
|
309 { |
|
310 |
|
311 TInt retVal(KErrNotFound); |
|
312 TPtrC8 metaendpoint = CWSPolicyUtils::PolicyUriL(aElement); |
|
313 TPtrC8 newExpiry = ExpiryTimeL(aElement); |
|
314 |
|
315 CSenElement* metaEndPointEle= IdentifierL().MetadataEndpointElementL(); |
|
316 |
|
317 CSenElement& ele = AsElement(); |
|
318 RPointerArray<CSenElement>& policyList = ele.ElementsL(); |
|
319 |
|
320 TInt count2(policyList.Count()); //Now check for WSDL or wsp:Policy |
|
321 for(TInt i = 0; i < count2; i++) |
|
322 { |
|
323 CSenElement* docElement = policyList[i]; |
|
324 TPtrC8 currentExpiry = ExpiryTimeL(docElement); |
|
325 TPtrC8 eleName = docElement->LocalName(); |
|
326 TPtrC8 eleNs = docElement->NsPrefix(); |
|
327 |
|
328 if(eleName == KWsdlDocument && eleNs == KWsdlNsPrefix) |
|
329 { |
|
330 } |
|
331 else if (eleName == KPolicyDocument && eleNs == KPolicyNsPrefix) |
|
332 { |
|
333 TPtrC8 doc_metaendpoint = CWSPolicyUtils::PolicyUriL(docElement); |
|
334 |
|
335 TTime now; |
|
336 now.UniversalTime(); |
|
337 TBuf8<SenDateUtils::KXmlDateTimeMaxLength> nowtime; |
|
338 TRAPD(error, SenDateUtils::ToXmlDateTimeUtf82L(nowtime, now);) |
|
339 |
|
340 if(error == KErrNone && metaEndPointEle && doc_metaendpoint == metaendpoint && |
|
341 newExpiry > currentExpiry && |
|
342 newExpiry > nowtime) |
|
343 { |
|
344 CSenElement* removed = ele.RemoveElement(*docElement); |
|
345 delete removed; |
|
346 removed = NULL; |
|
347 |
|
348 SenXmlUtils::AddAttributeL(*metaEndPointEle, KSenWSPolicyValidUntil,newExpiry); |
|
349 //Have to copy incase for multiple SDs have same policy |
|
350 //we cannot give ownership of Policy here so create a copy and dont take ownership |
|
351 CSenElement* copy = CSenXmlElement::NewL(aElement->LocalName()); |
|
352 copy->CopyFromL(*aElement); |
|
353 ele.AddElementL(*copy); |
|
354 |
|
355 retVal = KErrNone; |
|
356 return retVal; |
|
357 } |
|
358 |
|
359 } |
|
360 } |
|
361 |
|
362 |
|
363 |
|
364 return retVal; |
|
365 } |
|
366 TInt CSenInternalWsPolicy::RemoveMetadataPolicyL(const TDesC8& aUri) |
|
367 { |
|
368 TInt retVal(KErrNotFound); |
|
369 CSenElement& ele = AsElement(); |
|
370 TPtrC8 endpoint = IdentifierL().MetadataEndpointL(); |
|
371 if(endpoint != aUri) |
|
372 { |
|
373 return retVal; |
|
374 } |
|
375 |
|
376 CSenElement* metadataendpoint = IdentifierL().MetadataEndpointElementL(); |
|
377 if (metadataendpoint) |
|
378 { |
|
379 RPointerArray<CSenElement>& policyList = ele.ElementsL(); |
|
380 TInt policyCount(policyList.Count()); |
|
381 for(TInt i = 0; i< policyCount; i++) |
|
382 { |
|
383 CSenElement* policy = policyList[i]; |
|
384 TPtrC8 metaendpoint = CWSPolicyUtils::PolicyUriL(policy); |
|
385 if(metaendpoint == aUri) |
|
386 { |
|
387 CSenElement* removed = ele.RemoveElement(*policy); |
|
388 delete removed; |
|
389 removed = NULL; |
|
390 |
|
391 retVal = KErrNone; |
|
392 return retVal; |
|
393 } |
|
394 } |
|
395 } |
|
396 retVal = KErrNotFound; |
|
397 return retVal; |
|
398 |
|
399 } |
|
400 CSenElement* CSenInternalWsPolicy::WsPolicyByUriL(const TDesC8& aUri) |
|
401 { |
|
402 CSenElement& ele = AsElement(); |
|
403 TPtrC8 uri = IdentifierL().MetadataEndpointL(); |
|
404 if(uri != aUri) |
|
405 { |
|
406 return NULL; |
|
407 } |
|
408 |
|
409 RPointerArray<CSenElement>& policyList = ele.ElementsL(); |
|
410 TInt policyCount(policyList.Count()); |
|
411 for(TInt i = 0; i< policyCount; i++) |
|
412 { |
|
413 CSenElement* policy = policyList[i]; |
|
414 TPtrC8 metaendpoint = CWSPolicyUtils::PolicyUriL(policy); |
|
415 if(metaendpoint == aUri) |
|
416 { |
|
417 |
|
418 return policy; |
|
419 } |
|
420 } |
|
421 return NULL; |
|
422 |
|
423 } |
|
424 CSenElement* CSenInternalWsPolicy::WsPolicyByName(const TDesC8& /*aName*/) |
|
425 { |
|
426 /* |
|
427 CSenElement& ele = AsElement(); |
|
428 RPointerArray<CSenElement> list; |
|
429 CleanupClosePushL(list); |
|
430 TInt retVal = Identifier().MetadataEndpoint(list, aUri); |
|
431 if (retVal == KErrNone) |
|
432 { |
|
433 TInt count(list.Count()); //we should al3ways have count "1" |
|
434 if(count ==1) |
|
435 { |
|
436 RPointerArray<CSenElement>& policyList = ele.ElementsL(); |
|
437 TInt policyCount(policyList.Count()); |
|
438 for(TInt i = 0; i< policyCount; i++) |
|
439 { |
|
440 CSenElement* policy = policyList[i]; |
|
441 TPtrC8 name = CWSPolicyUtils::PolicyNameL(policy); |
|
442 if(name == aName) |
|
443 { |
|
444 CleanupStack::PopAndDestroy(&list); |
|
445 return policy; |
|
446 } |
|
447 |
|
448 } |
|
449 |
|
450 } |
|
451 } |
|
452 CleanupStack::PopAndDestroy(&list); |
|
453 */ |
|
454 return NULL; |
|
455 |
|
456 } |
|
457 TTime CSenInternalWsPolicy::ValidUntilL(const TDesC8& aUri) |
|
458 { |
|
459 TTime retTime = Time::NullTTime(); |
|
460 TInt retVal(KErrGeneral); |
|
461 |
|
462 CSenElement& ele = AsElement(); |
|
463 TPtrC8 uri = IdentifierL().MetadataEndpointL(); |
|
464 if(uri != aUri) |
|
465 { |
|
466 return retTime; |
|
467 } |
|
468 |
|
469 CSenElement* metaEndPointEle = IdentifierL().MetadataEndpointElementL(); |
|
470 if(metaEndPointEle) |
|
471 { |
|
472 TPtrC8 expiry = ExpiryTimeL(metaEndPointEle); |
|
473 if(expiry.Length() > 0) |
|
474 TRAP (retVal, retTime = SenDateUtils::FromXmlDateTimeL(expiry)); |
|
475 } |
|
476 |
|
477 |
|
478 if(retVal != KErrNone) |
|
479 retTime = Time::NullTTime(); |
|
480 |
|
481 return retTime; |
|
482 |
|
483 } |
|
484 |
|
485 |
|
486 /////////////////////////////////////////////////////////////////////////////// |
|
487 /////////////////////////////////////////////////////////////////////////////// |
|
488 /////////////////////////////////////////////////////////////////////////////// |
|
489 /////////////////////////////////////////////////////////////////////////////// |
|
490 |
|
491 |
|
492 |
|
493 CSenWSPolicyProperties* CSenWSPolicyProperties::NewL() |
|
494 { |
|
495 CSenWSPolicyProperties* pNew = NewLC(); |
|
496 CleanupStack::Pop(pNew); |
|
497 return pNew; |
|
498 } |
|
499 |
|
500 CSenWSPolicyProperties* CSenWSPolicyProperties::NewLC() |
|
501 { |
|
502 CSenWSPolicyProperties* pNew = new (ELeave) CSenWSPolicyProperties; |
|
503 CleanupStack::PushL(pNew); |
|
504 pNew->BaseConstructL(KSenWsPolicyProperteisLocalname); |
|
505 return pNew; |
|
506 } |
|
507 |
|
508 CSenWSPolicyProperties* CSenWSPolicyProperties::NewL( |
|
509 const TDesC8& aNsUri, |
|
510 const TDesC8& aLocalName, |
|
511 const TDesC8& aQName, |
|
512 const RAttributeArray& aAttributes) |
|
513 { |
|
514 CSenWSPolicyProperties* pNew = NewLC(aNsUri, aLocalName, aQName, aAttributes); |
|
515 CleanupStack::Pop(); // pNew; |
|
516 return pNew; |
|
517 } |
|
518 |
|
519 CSenWSPolicyProperties* CSenWSPolicyProperties::NewLC( |
|
520 const TDesC8& aNsUri, |
|
521 const TDesC8& aLocalName, |
|
522 const TDesC8& aQName, |
|
523 const RAttributeArray& aAttributes) |
|
524 { |
|
525 CSenWSPolicyProperties* pNew = new (ELeave) CSenWSPolicyProperties; |
|
526 CleanupStack::PushL(pNew); |
|
527 pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttributes); |
|
528 return pNew; |
|
529 } |
|
530 |
|
531 CSenWSPolicyProperties* CSenWSPolicyProperties::NewL( |
|
532 const TDesC8& aNsUri, |
|
533 const TDesC8& aLocalName, |
|
534 const TDesC8& aQName, |
|
535 const RAttributeArray& aAttributes, |
|
536 CSenElement& aParent) |
|
537 { |
|
538 CSenWSPolicyProperties* pNew = NewLC(aNsUri, aLocalName, |
|
539 aQName, aAttributes, aParent); |
|
540 CleanupStack::Pop(); // pNew; |
|
541 return pNew; |
|
542 } |
|
543 |
|
544 CSenWSPolicyProperties* CSenWSPolicyProperties::NewLC( |
|
545 const TDesC8& aNsUri, |
|
546 const TDesC8& aLocalName, |
|
547 const TDesC8& aQName, |
|
548 const RAttributeArray& aAttributes, |
|
549 CSenElement& aParent) |
|
550 { |
|
551 CSenWSPolicyProperties* pNew = new (ELeave) CSenWSPolicyProperties; |
|
552 CleanupStack::PushL(pNew); |
|
553 pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttributes, aParent); |
|
554 return pNew; |
|
555 } |
|
556 |
|
557 CSenWSPolicyProperties::~CSenWSPolicyProperties() |
|
558 { |
|
559 } |
|
560 |
|
561 CSenWSPolicyProperties::CSenWSPolicyProperties() |
|
562 { |
|
563 } |
|
564 |
|
565 TInt CSenWSPolicyProperties::SetPropertyL(const TDesC8& aName, |
|
566 const TDesC8& aValue) |
|
567 { |
|
568 CSenElement& element = AsElement(); |
|
569 RPointerArray<CSenElement> list; |
|
570 CleanupClosePushL(list); |
|
571 |
|
572 element.ElementsL(list, aName); |
|
573 |
|
574 if ( list.Count() > 0 ) |
|
575 { |
|
576 CSenElement* firstElement = list[0]; |
|
577 firstElement->SetContentL(aValue); |
|
578 CleanupStack::PopAndDestroy(&list); |
|
579 |
|
580 return KErrNone; |
|
581 } |
|
582 CleanupStack::PopAndDestroy(&list); |
|
583 |
|
584 CSenElement& newElement = element.AddElementL(aName); |
|
585 newElement.SetContentL(aValue); |
|
586 return KErrNone; |
|
587 } |
|
588 |
|
589 TInt CSenWSPolicyProperties::PropertyL(const TDesC8& aName, TPtrC8& aValue) |
|
590 { |
|
591 TInt retVal(KErrNone); |
|
592 |
|
593 CSenElement& element = AsElement(); |
|
594 RPointerArray<CSenElement> list; |
|
595 CleanupClosePushL(list); |
|
596 |
|
597 element.ElementsL(list, aName); |
|
598 |
|
599 if ( list.Count() > 0 ) |
|
600 { |
|
601 CSenElement* firstElement = list[0]; |
|
602 if(firstElement->HasContent()) |
|
603 aValue.Set(firstElement->Content()); |
|
604 } |
|
605 else |
|
606 { |
|
607 retVal = KErrNotFound; |
|
608 } |
|
609 |
|
610 CleanupStack::PopAndDestroy(&list); |
|
611 return retVal; |
|
612 } |
|
613 |
|
614 /////////////////////////////////////////////////////////////////////////////// |
|
615 /////////////////////////////////////////////////////////////////////////////// |
|
616 /////////////////////////////////////////////////////////////////////////////// |
|
617 /////////////////////////////////////////////////////////////////////////////// |
|
618 |
|
619 CSenWSPolicyIdentifier* CSenWSPolicyIdentifier::NewL() |
|
620 { |
|
621 CSenWSPolicyIdentifier* pNew = NewLC(); |
|
622 CleanupStack::Pop(pNew); |
|
623 return pNew; |
|
624 } |
|
625 |
|
626 CSenWSPolicyIdentifier* CSenWSPolicyIdentifier::NewLC() |
|
627 { |
|
628 CSenWSPolicyIdentifier* pNew = new (ELeave) CSenWSPolicyIdentifier; |
|
629 CleanupStack::PushL(pNew); |
|
630 pNew->BaseConstructL(KSenWsPolicyIdentifierLocalname); |
|
631 return pNew; |
|
632 } |
|
633 |
|
634 CSenWSPolicyIdentifier* CSenWSPolicyIdentifier::NewL( |
|
635 const TDesC8& aNsUri, |
|
636 const TDesC8& aLocalName, |
|
637 const TDesC8& aQName, |
|
638 const RAttributeArray& aAttributes) |
|
639 { |
|
640 CSenWSPolicyIdentifier* pNew = NewLC(aNsUri, aLocalName, aQName, aAttributes); |
|
641 CleanupStack::Pop(); // pNew; |
|
642 return pNew; |
|
643 } |
|
644 |
|
645 CSenWSPolicyIdentifier* CSenWSPolicyIdentifier::NewLC( |
|
646 const TDesC8& aNsUri, |
|
647 const TDesC8& aLocalName, |
|
648 const TDesC8& aQName, |
|
649 const RAttributeArray& aAttributes) |
|
650 { |
|
651 CSenWSPolicyIdentifier* pNew = new (ELeave) CSenWSPolicyIdentifier; |
|
652 CleanupStack::PushL(pNew); |
|
653 pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttributes); |
|
654 return pNew; |
|
655 } |
|
656 |
|
657 CSenWSPolicyIdentifier* CSenWSPolicyIdentifier::NewL( |
|
658 const TDesC8& aNsUri, |
|
659 const TDesC8& aLocalName, |
|
660 const TDesC8& aQName, |
|
661 const RAttributeArray& aAttributes, |
|
662 CSenElement& aParent) |
|
663 { |
|
664 CSenWSPolicyIdentifier* pNew = NewLC(aNsUri, aLocalName, |
|
665 aQName, aAttributes, aParent); |
|
666 CleanupStack::Pop(); // pNew; |
|
667 return pNew; |
|
668 } |
|
669 |
|
670 CSenWSPolicyIdentifier* CSenWSPolicyIdentifier::NewLC( |
|
671 const TDesC8& aNsUri, |
|
672 const TDesC8& aLocalName, |
|
673 const TDesC8& aQName, |
|
674 const RAttributeArray& aAttributes, |
|
675 CSenElement& aParent) |
|
676 { |
|
677 CSenWSPolicyIdentifier* pNew = new (ELeave) CSenWSPolicyIdentifier; |
|
678 CleanupStack::PushL(pNew); |
|
679 pNew->BaseConstructL(aNsUri, aLocalName, aQName, aAttributes, aParent); |
|
680 return pNew; |
|
681 } |
|
682 |
|
683 CSenWSPolicyIdentifier::~CSenWSPolicyIdentifier() |
|
684 { |
|
685 } |
|
686 |
|
687 CSenWSPolicyIdentifier::CSenWSPolicyIdentifier() |
|
688 { |
|
689 } |
|
690 |
|
691 void CSenWSPolicyIdentifier::SetIdL(TInt aId) |
|
692 { |
|
693 CSenElement& element = AsElement(); |
|
694 RPointerArray<CSenElement> list; |
|
695 CleanupClosePushL(list); |
|
696 |
|
697 element.ElementsL(list, KSenWSPolicyId); |
|
698 |
|
699 CSenElement* idElement; |
|
700 if ( list.Count() > 0 ) |
|
701 { |
|
702 idElement = list[0]; |
|
703 } |
|
704 else |
|
705 { |
|
706 idElement = &element.AddElementL(KSenWSPolicyId); |
|
707 } |
|
708 |
|
709 TBuf8<KFlatBufSize> buffer; |
|
710 buffer.Num(aId); |
|
711 idElement->SetContentL(buffer); |
|
712 |
|
713 CleanupStack::PopAndDestroy(&list); |
|
714 } |
|
715 |
|
716 TInt CSenWSPolicyIdentifier::IdL() |
|
717 { |
|
718 TInt retVal(KErrNotFound); |
|
719 |
|
720 CSenElement& element = AsElement(); |
|
721 RPointerArray<CSenElement> list; |
|
722 CleanupClosePushL(list); |
|
723 |
|
724 element.ElementsL(list, KSenWSPolicyId); |
|
725 |
|
726 if ( list.Count() > 0 ) |
|
727 { |
|
728 CSenElement* idElement = list[0]; |
|
729 if(idElement->HasContent()) |
|
730 { |
|
731 TLex8 lex; |
|
732 lex.Assign(idElement->Content()); |
|
733 lex.Val( retVal ); |
|
734 } |
|
735 } |
|
736 |
|
737 CleanupStack::PopAndDestroy(&list); |
|
738 |
|
739 return retVal; |
|
740 } |
|
741 TPtrC8 CSenWSPolicyIdentifier::ContractL() |
|
742 { |
|
743 CSenElement& element = AsElement(); |
|
744 RPointerArray<CSenElement> list; |
|
745 CleanupClosePushL(list); |
|
746 |
|
747 element.ElementsL(list, KContractLocalname); |
|
748 |
|
749 if ( list.Count() > 0 ) |
|
750 { |
|
751 CSenElement* idElement = list[0]; |
|
752 CleanupStack::PopAndDestroy(&list); |
|
753 if(idElement->HasContent()) |
|
754 return idElement->Content(); |
|
755 else |
|
756 return KNullDesC8(); |
|
757 |
|
758 } |
|
759 |
|
760 CleanupStack::PopAndDestroy(&list); |
|
761 |
|
762 return KNullDesC8(); |
|
763 |
|
764 } |
|
765 TPtrC8 CSenWSPolicyIdentifier::EndpointL() |
|
766 { |
|
767 |
|
768 CSenElement& element = AsElement(); |
|
769 RPointerArray<CSenElement> list; |
|
770 CleanupClosePushL(list); |
|
771 |
|
772 element.ElementsL(list, KEndpointLocalname); |
|
773 |
|
774 if ( list.Count() > 0 ) |
|
775 { |
|
776 CSenElement* idElement = list[0]; |
|
777 CleanupStack::PopAndDestroy(&list); |
|
778 if(idElement->HasContent()) |
|
779 return idElement->Content(); |
|
780 else |
|
781 return KNullDesC8(); |
|
782 |
|
783 } |
|
784 |
|
785 CleanupStack::PopAndDestroy(&list); |
|
786 |
|
787 return KNullDesC8(); |
|
788 |
|
789 } |
|
790 TPtrC8 CSenWSPolicyIdentifier::MetadataEndpointL() |
|
791 { |
|
792 |
|
793 CSenElement& element = AsElement(); |
|
794 RPointerArray<CSenElement> list; |
|
795 CleanupClosePushL(list); |
|
796 |
|
797 element.ElementsL(list, KMetadataEndpointLocalname); |
|
798 |
|
799 if ( list.Count() > 0 ) |
|
800 { |
|
801 CSenElement* idElement = list[0]; |
|
802 CleanupStack::PopAndDestroy(&list); |
|
803 if(idElement->HasContent()) |
|
804 return idElement->Content(); |
|
805 else |
|
806 return KNullDesC8(); |
|
807 |
|
808 } |
|
809 |
|
810 CleanupStack::PopAndDestroy(&list); |
|
811 |
|
812 return KNullDesC8(); |
|
813 |
|
814 } |
|
815 CSenElement* CSenWSPolicyIdentifier::MetadataEndpointElementL() |
|
816 { |
|
817 |
|
818 CSenElement& element = AsElement(); |
|
819 RPointerArray<CSenElement> list; |
|
820 CleanupClosePushL(list); |
|
821 |
|
822 element.ElementsL(list, KMetadataEndpointLocalname); |
|
823 |
|
824 if ( list.Count() > 0 ) |
|
825 { |
|
826 CSenElement* idElement = list[0]; |
|
827 CleanupStack::PopAndDestroy(&list); |
|
828 if(idElement->HasContent()) |
|
829 return idElement; |
|
830 else |
|
831 return NULL; |
|
832 |
|
833 } |
|
834 |
|
835 CleanupStack::PopAndDestroy(&list); |
|
836 |
|
837 return NULL; |
|
838 |
|
839 } |
|
840 |
|
841 TPtrC8 CSenWSPolicyIdentifier::ProviderIdL() |
|
842 { |
|
843 |
|
844 CSenElement& element = AsElement(); |
|
845 RPointerArray<CSenElement> list; |
|
846 CleanupClosePushL(list); |
|
847 |
|
848 element.ElementsL(list, KProviderIdLocalName); |
|
849 |
|
850 if ( list.Count() > 0 ) |
|
851 { |
|
852 CSenElement* idElement = list[0]; |
|
853 CleanupStack::PopAndDestroy(&list); |
|
854 if(idElement->HasContent()) |
|
855 return idElement->Content(); |
|
856 else |
|
857 return KNullDesC8(); |
|
858 |
|
859 } |
|
860 |
|
861 CleanupStack::PopAndDestroy(&list); |
|
862 |
|
863 return KNullDesC8(); |
|
864 } |
|
865 TPtrC8 CSenWSPolicyIdentifier::ElementAttribValueL(CSenElement* aElement, const TDesC8& aName) |
|
866 { |
|
867 |
|
868 if(aElement == NULL || aName.Length() == NULL) { return KNullDesC8(); } |
|
869 |
|
870 RPointerArray<CSenBaseAttribute>& attrs = aElement->AttributesL(); |
|
871 |
|
872 CSenBaseAttribute* bs = NULL; |
|
873 TInt ele_count = attrs.Count(); |
|
874 |
|
875 for (TInt j=0; j < ele_count; j++) |
|
876 { |
|
877 |
|
878 bs = (attrs)[j]; |
|
879 if(bs) |
|
880 { |
|
881 if(bs->Name().Compare(aName) == 0) |
|
882 { |
|
883 return bs->Value(); |
|
884 } |
|
885 } |
|
886 |
|
887 |
|
888 } |
|
889 return KNullDesC8(); |
|
890 } |
|
891 TBool CSenWSPolicyIdentifier::HasAttributeL(CSenElement* aElement, const TDesC8& aName) |
|
892 { |
|
893 if(aElement == NULL || aName.Length() == NULL) { return EFalse; } |
|
894 |
|
895 RPointerArray<CSenBaseAttribute>& attrs = aElement->AttributesL(); |
|
896 |
|
897 CSenBaseAttribute* bs = NULL; |
|
898 TInt ele_count = attrs.Count(); |
|
899 |
|
900 for (TInt j=0; j < ele_count; j++) |
|
901 { |
|
902 |
|
903 bs = (attrs)[j]; |
|
904 if(bs) |
|
905 { |
|
906 if(bs->Name().Compare(aName) == 0) |
|
907 { |
|
908 return ETrue; |
|
909 } |
|
910 } |
|
911 |
|
912 |
|
913 } |
|
914 return EFalse; |
|
915 |
|
916 } |
|
917 |
|
918 TInt CSenWSPolicyIdentifier::AddMetadataEndpointL(CSenElement* aElement) |
|
919 { |
|
920 |
|
921 if(aElement == NULL || aElement->HasContent() == EFalse) |
|
922 return KErrArgument; |
|
923 |
|
924 //get the method |
|
925 TPtrC8 ptrMethod = ElementAttribValueL(aElement, KMetadataMethodLocalname); |
|
926 //now compare the two Metadata endpoints |
|
927 CSenElement& element = AsElement(); |
|
928 RPointerArray<CSenElement> list; |
|
929 CleanupClosePushL(list); |
|
930 element.ElementsL(list, aElement->LocalName()); |
|
931 TInt count = list.Count(); |
|
932 |
|
933 if(count == 0) |
|
934 { |
|
935 CSenElement& newElement = element.AddElementL(aElement->LocalName()); |
|
936 newElement.SetContentL(aElement->Content()); |
|
937 if(ptrMethod.Length() > 0) |
|
938 SenXmlUtils::AddAttributeL(newElement, KMetadataMethodLocalname, ptrMethod); |
|
939 CleanupStack::PopAndDestroy(&list); |
|
940 return KErrNone; |
|
941 } |
|
942 |
|
943 for(TInt i = 0; i < count; i++) |
|
944 { |
|
945 CSenElement* firstElement = list[i]; |
|
946 if(firstElement->Content() == aElement->Content()) |
|
947 { |
|
948 |
|
949 TPtrC8 firstMethod = ElementAttribValueL(firstElement, KMetadataMethodLocalname); |
|
950 if (ptrMethod.Compare(firstMethod) == 0 ) |
|
951 { |
|
952 CleanupStack::PopAndDestroy(&list); // Close() |
|
953 //exactly Same so no need to add again |
|
954 return KErrNone; |
|
955 } |
|
956 } |
|
957 |
|
958 } |
|
959 |
|
960 CleanupStack::PopAndDestroy(&list); |
|
961 |
|
962 CSenElement& newElement = element.AddElementL(aElement->LocalName()); |
|
963 newElement.SetContentL(aElement->Content()); |
|
964 if(ptrMethod.Length() > 0) |
|
965 SenXmlUtils::AddAttributeL(newElement, KMetadataMethodLocalname, ptrMethod); |
|
966 |
|
967 return KErrNone; |
|
968 |
|
969 |
|
970 } |
|
971 |
|
972 TInt CSenWSPolicyIdentifier::UpdateMetadataEndpointL(CSenWSPolicyIdentifier& aIdentifier) |
|
973 { |
|
974 |
|
975 //now compare contents and then compare attributes |
|
976 TInt retVal = KErrNotFound; |
|
977 TPtrC8 endpoint = MetadataEndpointL(); |
|
978 TPtrC8 canEndPoint = aIdentifier.MetadataEndpointL(); |
|
979 if(endpoint == canEndPoint) |
|
980 { |
|
981 CSenElement* ele1 = MetadataEndpointElementL(); |
|
982 CSenElement* ele2 = aIdentifier.MetadataEndpointElementL(); |
|
983 |
|
984 if(ele1 && ele2 && ele1->HasContent()) //&& ele2->HasContent()) |
|
985 //no need to verify this as important thing is that new content has Contents |
|
986 { |
|
987 //if Endpoint URi is same |
|
988 if(ele1->Content() == ele2->Content()) |
|
989 { |
|
990 if(HasAttributeL(ele1, KMetadataMethodLocalname)) |
|
991 { |
|
992 TPtrC8 val1 = ElementAttribValueL(ele1, KMetadataMethodLocalname); |
|
993 |
|
994 if(HasAttributeL(ele2, KMetadataMethodLocalname)) |
|
995 { |
|
996 TPtrC8 val2 = ElementAttribValueL(ele2, KMetadataMethodLocalname) ; |
|
997 if(val1.Compare(val2) != 0) |
|
998 { |
|
999 //replace the Attribute with a newer Value |
|
1000 ele2->AddAttrL(KMetadataMethodLocalname,val1); |
|
1001 retVal = KErrNone; |
|
1002 } |
|
1003 } |
|
1004 } |
|
1005 } |
|
1006 } |
|
1007 } |
|
1008 return retVal; |
|
1009 } |
|
1010 |
|
1011 |
|
1012 /////////////////////////////////////////////////////////////////////////////// |
|
1013 /////////////////////////////////////////////////////////////////////////////// |
|
1014 /////////////////////////////////////////////////////////////////////////////// |
|
1015 /////////////////////////////////////////////////////////////////////////////// |
|
1016 |
|
1017 |
|
1018 |
|
1019 void RSenWSPolicyPtr::OpenL(CSenInternalWsPolicy* apPolicy) |
|
1020 { |
|
1021 ipPolicyData = new (ELeave) TSenWsPolicyData; |
|
1022 ipPolicyData->iCounter = 1; |
|
1023 ipPolicyData->ipPolicy = apPolicy; |
|
1024 } |
|
1025 |
|
1026 CSenInternalWsPolicy* RSenWSPolicyPtr::Policy() |
|
1027 { |
|
1028 if ( ipPolicyData ) |
|
1029 { |
|
1030 return ipPolicyData->ipPolicy; |
|
1031 } |
|
1032 else |
|
1033 { |
|
1034 return NULL; |
|
1035 } |
|
1036 } |
|
1037 |
|
1038 void RSenWSPolicyPtr::SetPolicy(CSenInternalWsPolicy* apPolicy) |
|
1039 { |
|
1040 if ( ipPolicyData ) |
|
1041 { |
|
1042 delete ipPolicyData->ipPolicy; |
|
1043 ipPolicyData->ipPolicy = apPolicy; |
|
1044 } |
|
1045 } |
|
1046 |
|
1047 RSenWSPolicyPtr RSenWSPolicyPtr::Clone() |
|
1048 { |
|
1049 if ( ipPolicyData ) |
|
1050 { |
|
1051 (ipPolicyData->iCounter)++; |
|
1052 } |
|
1053 return *this; |
|
1054 } |
|
1055 |
|
1056 void RSenWSPolicyPtr::Close() |
|
1057 { |
|
1058 if ( ipPolicyData ) |
|
1059 { |
|
1060 |
|
1061 (ipPolicyData->iCounter)--; |
|
1062 if ( ipPolicyData->iCounter == 0 ) |
|
1063 { |
|
1064 TRAP_IGNORE( ipPolicyData->ipPolicy->IdentifierL().ExtractElement(); ) |
|
1065 ipPolicyData->ipPolicy->ExtractElement(); |
|
1066 delete ipPolicyData->ipPolicy; |
|
1067 delete ipPolicyData; |
|
1068 } |
|
1069 |
|
1070 ipPolicyData = NULL; |
|
1071 } |
|
1072 } |
|
1073 |
|
1074 void RSenWSPolicyPtr::CloseAndDestroyPolicy() |
|
1075 { |
|
1076 if ( ipPolicyData ) |
|
1077 { |
|
1078 TRAP_IGNORE( ipPolicyData->ipPolicy->IdentifierL().ExtractElement(); ) |
|
1079 ipPolicyData->ipPolicy->ExtractElement(); |
|
1080 delete ipPolicyData->ipPolicy; |
|
1081 ipPolicyData->ipPolicy = NULL; |
|
1082 |
|
1083 (ipPolicyData->iCounter)--; |
|
1084 if ( ipPolicyData->iCounter == 0 ) |
|
1085 { |
|
1086 delete ipPolicyData; |
|
1087 } |
|
1088 |
|
1089 ipPolicyData = NULL; |
|
1090 } |
|
1091 } |
|
1092 |
|
1093 RSenWSPolicyPtr::RSenWSPolicyPtr() |
|
1094 : ipPolicyData(NULL) |
|
1095 { |
|
1096 } |
|
1097 |
|
1098 // END OF FILE |