1 /* |
|
2 * Copyright (c) 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: CXcapIetfPresRulesUsage |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "XcapIetfPresRulesUsage.h" |
|
22 #include "XdmDocumentNode.h" |
|
23 #include "XdmNodeAttribute.h" |
|
24 #include "XdmErrors.h" |
|
25 |
|
26 // Used specification |
|
27 // draft-ietf-simple-presence-rules-03, 18 July 2005 |
|
28 // expires 19 January, 2006 |
|
29 // draft-ietf-simple-presence-rules-05, 06 March 2006 |
|
30 // expires 07 September, 2006 |
|
31 |
|
32 // ---------------------------------------------------- |
|
33 // CXcapIetfPresRulesUsage::CXcapIetfPresRulesUsage |
|
34 // |
|
35 // ---------------------------------------------------- |
|
36 // |
|
37 CXcapIetfPresRulesUsage::CXcapIetfPresRulesUsage( const CXdmEngine& aXdmEngine ) : |
|
38 CXcapAppUsage( aXdmEngine ), |
|
39 iIetfCommonPolicy( NULL ) |
|
40 { |
|
41 } |
|
42 |
|
43 // ---------------------------------------------------- |
|
44 // CXcapIetfPresRulesUsage::NewL |
|
45 // |
|
46 // ---------------------------------------------------- |
|
47 // |
|
48 CXcapIetfPresRulesUsage* CXcapIetfPresRulesUsage::NewL( const TXcapAppUsageParams& aParameters ) |
|
49 { |
|
50 CXcapIetfPresRulesUsage* self = new ( ELeave ) CXcapIetfPresRulesUsage( aParameters.iXdmEngine ); |
|
51 CleanupStack::PushL( self ); // << self |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop( self ); // >> self |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------- |
|
58 // CXcapIetfPresRulesUsage::~CXcapIetfPresRulesUsage |
|
59 // |
|
60 // ---------------------------------------------------- |
|
61 // |
|
62 CXcapIetfPresRulesUsage::~CXcapIetfPresRulesUsage() |
|
63 { |
|
64 delete iIetfCommonPolicy; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------- |
|
68 // CXcapIetfPresRulesUsage::ConstructL |
|
69 // |
|
70 // ---------------------------------------------------- |
|
71 // |
|
72 void CXcapIetfPresRulesUsage::ConstructL() |
|
73 { |
|
74 iIetfCommonPolicy = CXcapAppUsage::NewL( iXdmEngine, KXdmIetfCommonPolicyUsageUid ); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------- |
|
78 // CXcapIetfPresRulesUsage::AUID |
|
79 // |
|
80 // ---------------------------------------------------- |
|
81 // |
|
82 TPtrC8 CXcapIetfPresRulesUsage::AUID() const |
|
83 { |
|
84 return TPtrC8( KXdmIetfPresRulesUsageAUID ); |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------- |
|
88 // CXcapIetfPresRulesUsage::ContentType |
|
89 // |
|
90 // ---------------------------------------------------- |
|
91 // |
|
92 TPtrC8 CXcapIetfPresRulesUsage::ContentType() const |
|
93 { |
|
94 return TPtrC8( KXdmIetfPresRulesUsageContType ); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------- |
|
98 // CXcapIetfPresRulesUsage::DefaultNamespace |
|
99 // |
|
100 // ---------------------------------------------------- |
|
101 // |
|
102 TPtrC8 CXcapIetfPresRulesUsage::DefaultNamespace() const |
|
103 { |
|
104 return TPtrC8( KXdmIetfPresRulesNamespace ); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------- |
|
108 // CXcapIetfPresRulesUsage::ValidateL |
|
109 // |
|
110 // ---------------------------------------------------- |
|
111 // |
|
112 TBool CXcapIetfPresRulesUsage::ValidateNodeL( CXdmDocumentNode& aXdmNode ) |
|
113 { |
|
114 // This method is called by base class for each element |
|
115 // in document, here we have to declare every element, check element |
|
116 // datatype, restrictions for values and also do all checking that concerns |
|
117 // the structure of the element. If the datatype is some of |
|
118 // the common datatypes defined in xcapappusage.h, the node |
|
119 // can pe passed to the base class for value validation. |
|
120 // If the node belongs to this namespace, the return value |
|
121 // should be true, false otherwise. |
|
122 |
|
123 TBool found ( EFalse ); |
|
124 TDataType dataType ( EDataTypeUndefined ); |
|
125 TPtrC element = aXdmNode.NodeName(); |
|
126 |
|
127 // <service-uri-scheme> |
|
128 if ( Match( element, KXdmServiceUriScheme ) ) |
|
129 { |
|
130 dataType = EDataTypeToken; |
|
131 found = ETrue; |
|
132 } |
|
133 // <class> |
|
134 else if ( Match( element, KXdmClass ) ) |
|
135 { |
|
136 dataType = EDataTypeToken; |
|
137 found = ETrue; |
|
138 } |
|
139 // <occurence-id> |
|
140 else if ( Match( element, KXdmOccurenceId ) ) |
|
141 { |
|
142 dataType = EDataTypeToken; |
|
143 found = ETrue; |
|
144 } |
|
145 // <service-uri> |
|
146 else if ( Match( element, KXdmServiceUri ) ) |
|
147 { |
|
148 dataType = EDataTypeAnyURI; |
|
149 found = ETrue; |
|
150 } |
|
151 // <all-services> |
|
152 else if ( Match( element, KXdmAllServices ) ) |
|
153 { |
|
154 found = ETrue; |
|
155 } |
|
156 // <provide-services> |
|
157 else if ( Match( element, KXdmProvideServices ) ) |
|
158 { |
|
159 // type = provideServicePermissions |
|
160 // here we should have either <all-services> |
|
161 // or sequence of other elements |
|
162 TBool allServices( EFalse ); |
|
163 TBool sequence( EFalse ); |
|
164 TBool serviceUri( EFalse ); |
|
165 TBool serviceUriScheme( EFalse ); |
|
166 TBool occurenceId( EFalse ); |
|
167 TBool prclass( EFalse ); |
|
168 TInt count( aXdmNode.NodeCount() ); |
|
169 for ( TInt i(0); i < count; i++ ) |
|
170 { |
|
171 TPtrC childName = aXdmNode.ChileNode(i)->NodeName(); |
|
172 if ( Match( childName, KXdmAllServices ) ) |
|
173 { |
|
174 allServices = ETrue; |
|
175 } |
|
176 else |
|
177 { |
|
178 sequence = ETrue; |
|
179 // in sequence should be either <service-uri>, |
|
180 // <service-uri-scheme>, <occurence-id> or <class> |
|
181 if ( Match( childName, KXdmServiceUri ) ) |
|
182 { |
|
183 serviceUri = ETrue; |
|
184 } |
|
185 else if ( Match( childName, KXdmServiceUriScheme ) ) |
|
186 { |
|
187 serviceUriScheme = ETrue; |
|
188 } |
|
189 else if ( Match( childName, KXdmOccurenceId ) ) |
|
190 { |
|
191 occurenceId = ETrue; |
|
192 } |
|
193 else if ( Match( childName, KXdmClass ) ) |
|
194 { |
|
195 prclass = ETrue; |
|
196 } |
|
197 } |
|
198 } |
|
199 if ( allServices && sequence ) |
|
200 { |
|
201 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
202 } |
|
203 if ( sequence ) |
|
204 { |
|
205 if ( serviceUri && ( serviceUriScheme || occurenceId || prclass ) ) |
|
206 { |
|
207 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
208 } |
|
209 if ( serviceUriScheme && ( occurenceId || prclass ) ) |
|
210 { |
|
211 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
212 } |
|
213 if ( occurenceId && prclass ) |
|
214 { |
|
215 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
216 } |
|
217 } |
|
218 found = ETrue; |
|
219 } |
|
220 // used in presence-rules-03 |
|
221 // <device-id> |
|
222 else if ( Match( element, KXdmDeviceId ) ) |
|
223 { |
|
224 dataType = EDataTypeAnyURI; |
|
225 found = ETrue; |
|
226 } |
|
227 // used in presence-rules-05 |
|
228 // <deviceID> |
|
229 else if ( Match( element, KXdmDeviceID ) ) |
|
230 { |
|
231 dataType = EDataTypeAnyURI; |
|
232 found = ETrue; |
|
233 } |
|
234 // <all-devices> |
|
235 else if ( Match( element, KXdmAllDevices ) ) |
|
236 { |
|
237 found = ETrue; |
|
238 } |
|
239 // <provide-devices> |
|
240 else if ( Match( element, KXdmProvideDevices ) ) |
|
241 { |
|
242 // type = provideDevicePermissions |
|
243 // here we should have either <all-devices> |
|
244 // or sequence of other elements |
|
245 TBool allDevices( EFalse ); |
|
246 TBool sequence( EFalse ); |
|
247 TBool deviceId( EFalse ); |
|
248 TBool occurenceId( EFalse ); |
|
249 TBool prclass( EFalse ); |
|
250 TInt count( aXdmNode.NodeCount() ); |
|
251 for ( TInt i(0); i < count; i++ ) |
|
252 { |
|
253 TPtrC childName = aXdmNode.ChileNode(i)->NodeName(); |
|
254 if ( Match( childName, KXdmAllDevices ) ) |
|
255 { |
|
256 allDevices = ETrue; |
|
257 } |
|
258 else |
|
259 { |
|
260 sequence = ETrue; |
|
261 // in sequence should be either pres-rules-03 <device-id> pres-rules-05 <deviceID>, |
|
262 // <occurence-id> or <class> |
|
263 if ( Match( childName, KXdmDeviceId ) |
|
264 || Match( childName, KXdmDeviceID ) ) |
|
265 { |
|
266 deviceId = ETrue; |
|
267 } |
|
268 else if ( Match( childName, KXdmOccurenceId ) ) |
|
269 { |
|
270 occurenceId = ETrue; |
|
271 } |
|
272 else if ( Match( childName, KXdmClass ) ) |
|
273 { |
|
274 prclass = ETrue; |
|
275 } |
|
276 } |
|
277 } |
|
278 if ( allDevices && sequence ) |
|
279 { |
|
280 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
281 } |
|
282 if ( sequence ) |
|
283 { |
|
284 if ( deviceId && ( occurenceId || prclass ) ) |
|
285 { |
|
286 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
287 } |
|
288 if ( occurenceId && prclass ) |
|
289 { |
|
290 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
291 } |
|
292 } |
|
293 found = ETrue; |
|
294 } |
|
295 // <all-persons> |
|
296 else if ( Match( element, KXdmAllPersons ) ) |
|
297 { |
|
298 found = ETrue; |
|
299 } |
|
300 // <provide-persons> |
|
301 else if ( !element.CompareF( KXdmProvidePersons ) ) |
|
302 { |
|
303 // type = providePersonPermissions |
|
304 // here we should have either <all-devices> |
|
305 // or sequence of other elements |
|
306 TBool allPersons( EFalse ); |
|
307 TBool sequence( EFalse ); |
|
308 TBool occurenceId( EFalse ); |
|
309 TBool prclass( EFalse ); |
|
310 TInt count( aXdmNode.NodeCount() ); |
|
311 for ( TInt i(0); i < count; i++ ) |
|
312 { |
|
313 TPtrC childName = aXdmNode.ChileNode(i)->NodeName(); |
|
314 if ( Match( childName, KXdmAllPersons ) ) |
|
315 { |
|
316 allPersons = ETrue; |
|
317 } |
|
318 else |
|
319 { |
|
320 sequence = ETrue; |
|
321 // in sequence should be either |
|
322 // <occurence-id> or <class> |
|
323 if ( Match( childName, KXdmOccurenceId ) ) |
|
324 { |
|
325 occurenceId = ETrue; |
|
326 } |
|
327 else if ( Match( childName, KXdmClass ) ) |
|
328 { |
|
329 prclass = ETrue; |
|
330 } |
|
331 } |
|
332 } |
|
333 if ( allPersons && sequence ) |
|
334 { |
|
335 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
336 } |
|
337 if ( sequence ) |
|
338 { |
|
339 if ( occurenceId && prclass ) |
|
340 { |
|
341 LeaveWithErrorL( KXcapErrorSchemaViolation ); |
|
342 } |
|
343 } |
|
344 found = ETrue; |
|
345 } |
|
346 // <provide-activities> |
|
347 else if ( Match( element, KXdmProvideActivities ) ) |
|
348 { |
|
349 dataType = EDataTypeBoolean; |
|
350 found = ETrue; |
|
351 } |
|
352 // <provide-class> |
|
353 else if ( Match( element, KXdmProvideClass ) ) |
|
354 { |
|
355 dataType = EDataTypeBoolean; |
|
356 found = ETrue; |
|
357 } |
|
358 // <provide-device-id> |
|
359 else if ( Match( element, KXdmProvideDeviceId ) ) |
|
360 { |
|
361 dataType = EDataTypeBoolean; |
|
362 found = ETrue; |
|
363 } |
|
364 // <provide-mood> |
|
365 else if ( Match( element, KXdmProvideMood ) ) |
|
366 { |
|
367 dataType = EDataTypeBoolean; |
|
368 found = ETrue; |
|
369 } |
|
370 // <provide-place-is> |
|
371 else if ( Match( element, KXdmProvidePlaceIs ) ) |
|
372 { |
|
373 dataType = EDataTypeBoolean; |
|
374 found = ETrue; |
|
375 } |
|
376 // <provide-place-type> |
|
377 else if ( Match( element, KXdmProvidePlaceType ) ) |
|
378 { |
|
379 dataType = EDataTypeBoolean; |
|
380 found = ETrue; |
|
381 } |
|
382 // <provide-privacy> |
|
383 else if ( Match( element, KXdmProvidePrivacy ) ) |
|
384 { |
|
385 dataType = EDataTypeBoolean; |
|
386 found = ETrue; |
|
387 } |
|
388 // <provide-relationship> |
|
389 else if ( Match( element, KXdmProvideRelationship ) ) |
|
390 { |
|
391 dataType = EDataTypeBoolean; |
|
392 found = ETrue; |
|
393 } |
|
394 // <provide-status-icon> |
|
395 else if ( Match( element, KXdmProvideStatusIcon ) ) |
|
396 { |
|
397 dataType = EDataTypeBoolean; |
|
398 found = ETrue; |
|
399 } |
|
400 // <provide-sphere> |
|
401 else if ( Match( element, KXdmProvideSphere ) ) |
|
402 { |
|
403 dataType = EDataTypeBoolean; |
|
404 found = ETrue; |
|
405 } |
|
406 // <provide-time-offset> |
|
407 else if ( Match( element, KXdmProvideTimeOffset ) ) |
|
408 { |
|
409 dataType = EDataTypeBoolean; |
|
410 found = ETrue; |
|
411 } |
|
412 // <provide-user-input> |
|
413 else if ( Match( element, KXdmProvideUserInput ) ) |
|
414 { |
|
415 // value is restricted, allowed values |
|
416 // are "false", "bare", "thresholds" and "full" |
|
417 TPtrC8 data = aXdmNode.LeafNodeContent(); |
|
418 if ( data.CompareF( KXdmFalse ) |
|
419 && data.CompareF( KXdmBare ) |
|
420 && data.CompareF( KXdmThresholds ) |
|
421 && data.CompareF( KXdmFull ) ) |
|
422 { |
|
423 LeaveWithErrorL( KXcapErrorEnumerationRule ); |
|
424 } |
|
425 found = ETrue; |
|
426 } |
|
427 // <provide-note> |
|
428 else if ( Match( element, KXdmProvideNote ) ) |
|
429 { |
|
430 dataType = EDataTypeBoolean; |
|
431 found = ETrue; |
|
432 } |
|
433 // <provide-unknown-attribute> |
|
434 else if ( Match( element, KXdmProvideUnknownAttribute ) ) |
|
435 { |
|
436 // required attribute name |
|
437 if ( !aXdmNode.HasAttribute( KXdmName ) ) |
|
438 { |
|
439 LeaveWithErrorL( KXcapErrorMissingRequiredAttribute ); |
|
440 } |
|
441 found = ETrue; |
|
442 } |
|
443 // <provide-all-attributes> |
|
444 else if ( Match( element, KXdmProvideAllAttributes ) ) |
|
445 { |
|
446 found = ETrue; |
|
447 } |
|
448 // <sub-handling> |
|
449 else if ( Match( element, KXdmSubHandling ) ) |
|
450 { |
|
451 found = ETrue; |
|
452 // value is restricted, allowed values |
|
453 // are "block", "confirm", "polite-block" and "allow" |
|
454 TPtrC8 data = aXdmNode.LeafNodeContent(); |
|
455 if ( data.CompareF( KXdmBlock ) |
|
456 && data.CompareF( KXdmConfirm ) |
|
457 && data.CompareF( KXdmPoliteBlock ) |
|
458 && data.CompareF( KXdmAllow ) ) |
|
459 { |
|
460 LeaveWithErrorL( KXcapErrorEnumerationRule ); |
|
461 } |
|
462 } |
|
463 // urn:ietf:params:xml:ns:common-policy |
|
464 if ( !found ) |
|
465 { |
|
466 found = iIetfCommonPolicy->ValidateNodeL( aXdmNode ); |
|
467 if ( found ) |
|
468 { |
|
469 SetPrefixL( aXdmNode, KXdmIetfCommonPolicyNsPrefix ); |
|
470 } |
|
471 } |
|
472 |
|
473 if ( dataType != EDataTypeUndefined ) |
|
474 { |
|
475 // pass to the base class for data validation |
|
476 ValidateDataL( dataType, aXdmNode ); |
|
477 } |
|
478 return found; |
|
479 } |
|
480 |
|
481 // ---------------------------------------------------- |
|
482 // CXcapIetfPresRulesUsage::ValidateAttributeL |
|
483 // |
|
484 // ---------------------------------------------------- |
|
485 // |
|
486 void CXcapIetfPresRulesUsage::ValidateAttributeL( const CXdmNodeAttribute& aXdmNodeAttr ) |
|
487 { |
|
488 // This method is called by base class for each attribute |
|
489 // in document, here we have to define data types |
|
490 // for attributes, and pass them to the base class |
|
491 // for the actual data checking. |
|
492 |
|
493 // name |
|
494 if ( Match( aXdmNodeAttr.NodeName(), KXdmName ) ) |
|
495 { |
|
496 // pass to base class for data validation |
|
497 ValidateDataL( EDataTypeString, aXdmNodeAttr ); |
|
498 } |
|
499 // the rest are from urn:ietf:params:xml:ns:common-policy |
|
500 else |
|
501 { |
|
502 iIetfCommonPolicy->ValidateAttributeL( aXdmNodeAttr ); |
|
503 } |
|
504 } |
|
505 |
|
506 // ---------------------------------------------------- |
|
507 // CXcapIetfPresRulesUsage::AddNamespaceInformationL |
|
508 // |
|
509 // ---------------------------------------------------- |
|
510 // |
|
511 void CXcapIetfPresRulesUsage::AddNamespaceInformationL( CXdmDocument& aXdmDocument ) |
|
512 { |
|
513 aXdmDocument.AppendNamespaceL( KXdmIetfPresRulesNamespace, KNullDesC8 ); |
|
514 aXdmDocument.AppendNamespaceL( KXdmIetfPresRulesNamespace, KXdmIetfPresRulesNsPrefix ); // ESTI-7AY95P |
|
515 aXdmDocument.AppendNamespaceL( KXdmIetfCommonPolicyNamespace, KXdmIetfCommonPolicyNsPrefix ); // ESTI-7AY95P |
|
516 } |
|
517 |
|
518 |
|
519 // End of File |
|
520 |
|