|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: UpnpDomInterface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32def.h> |
|
21 #include <e32math.h> |
|
22 #include <f32file.h> |
|
23 #include <s32file.h> |
|
24 #include <e32std.h> |
|
25 |
|
26 #define KLogFile _L("DLNAWebServer.txt") |
|
27 |
|
28 #include "upnpdominterface.h" |
|
29 #include "upnpstring.h" |
|
30 #include "upnpcustomlog.h" |
|
31 |
|
32 |
|
33 #include <xmlengdom.h> |
|
34 #include <xmlengdocument.h> |
|
35 #include <xmlengserializationoptions.h> |
|
36 |
|
37 |
|
38 |
|
39 // ============================ MEMBER FUNCTIONS =============================== |
|
40 |
|
41 namespace UpnpDomInterface |
|
42 { |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // UpnpDomInterface::GetAttrValueL |
|
46 // Gets the element attribute's value |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C TPtrC8 GetAttrValueL( const TXmlEngElement& aElement, |
|
50 const TDesC8& aAttribute ) |
|
51 { |
|
52 if( aElement.NotNull() ) |
|
53 { |
|
54 |
|
55 TPtrC8 val = aElement.AttributeValueL( aAttribute ); |
|
56 |
|
57 if( val.Length() ) |
|
58 { |
|
59 // Cleanup |
|
60 return val; |
|
61 } |
|
62 |
|
63 // Cleanup |
|
64 return KNullDesC8(); |
|
65 |
|
66 } |
|
67 |
|
68 return KNullDesC8(); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // UpnpDomInterface::GetElementValueL |
|
73 // Gets value of the indicated element. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C TPtrC8 GetElementValueL( const TXmlEngElement& aElement ) |
|
77 { |
|
78 if( aElement.IsNull() ) |
|
79 User::Leave( KErrNotFound ); |
|
80 |
|
81 if( !aElement.Value().Length() ) |
|
82 return KNullDesC8(); |
|
83 |
|
84 return aElement.Value(); |
|
85 |
|
86 } |
|
87 |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // UpnpDomInterface::AllocElementValueL |
|
91 // Gets value of the indicated element and allocs it on heap. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C HBufC* AllocElementValueL( const TXmlEngElement& aElement ) |
|
95 { |
|
96 if( aElement.IsNull() ) |
|
97 User::Leave( KErrNotFound ); |
|
98 |
|
99 if( !aElement.Value().Length() ) |
|
100 return NULL; |
|
101 |
|
102 HBufC* ret = HBufC::NewL(aElement.Value().Length()); |
|
103 ret->Des().Copy(aElement.Value()); |
|
104 return ret; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // UpnpDomInterface::CheckTagL |
|
109 // Checks the element's tag |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C TBool CheckTagL( const TXmlEngElement& aElement, |
|
113 const TDesC8& aTag ) |
|
114 { |
|
115 |
|
116 // Check the local name against the wanted tag. |
|
117 TInt difference = aElement.Name().Compare( aTag ); |
|
118 |
|
119 // Check the name of the element, |
|
120 // if it equals to Tag (the wanted value) |
|
121 if ( difference == 0 ) |
|
122 return ETrue; |
|
123 else |
|
124 return EFalse; |
|
125 |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // UpnpDomInterface::CheckTagL |
|
130 // Checks the element's tag |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C TBool CheckTagL( const TXmlEngElement& aElement, |
|
134 const TDesC8& aTag, |
|
135 const TDesC8& aTagValue ) |
|
136 { |
|
137 |
|
138 // If tag name equals |
|
139 if( CheckTagL( aElement, aTag ) ) |
|
140 { |
|
141 |
|
142 TInt difference = aElement.Value().Compare( aTagValue ); |
|
143 |
|
144 // If value also equals then that's the tag |
|
145 // we're looking for |
|
146 if ( difference == 0 || ( !aElement.Value().Length() && !aTagValue.Length() ) ) |
|
147 return ETrue; |
|
148 |
|
149 } |
|
150 |
|
151 return EFalse; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // UpnpDomInterface::CheckSubTagL |
|
156 // Check tag. |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C TBool CheckSubTagL( const TXmlEngElement& aElement, |
|
160 const TDesC8& aTag ) |
|
161 { |
|
162 |
|
163 // Go through the elements of the current level. |
|
164 if ( aElement.NotNull() ) |
|
165 { |
|
166 |
|
167 RXmlEngNodeList<TXmlEngElement> childElements; |
|
168 CleanupClosePushL(childElements); |
|
169 aElement.GetChildElements( childElements ); |
|
170 |
|
171 while( childElements.HasNext() ) |
|
172 { |
|
173 |
|
174 // Check the name of the sub element, |
|
175 // if it equals to Tag (the wanted value) |
|
176 if ( CheckTagL( childElements.Next(), aTag ) ) |
|
177 { |
|
178 CleanupStack::PopAndDestroy(&childElements); |
|
179 return ETrue; |
|
180 } |
|
181 } |
|
182 CleanupStack::PopAndDestroy(&childElements); |
|
183 } |
|
184 |
|
185 return EFalse; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // UpnpDomInterface::CheckSubTagL |
|
190 // Check sub tag. |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C TBool CheckSubTagL( const TXmlEngElement& aElement, |
|
194 const TDesC8& aTag, |
|
195 const TDesC8& aTagValue ) |
|
196 { |
|
197 |
|
198 // Go through the elements of the current level. |
|
199 if ( aElement.NotNull() ) |
|
200 { |
|
201 |
|
202 RXmlEngNodeList<TXmlEngElement> childElements; |
|
203 CleanupClosePushL(childElements); |
|
204 aElement.GetChildElements( childElements ); |
|
205 |
|
206 while( childElements.HasNext() ) |
|
207 { |
|
208 |
|
209 // Get a single element of the current level |
|
210 TXmlEngElement sub = childElements.Next(); |
|
211 |
|
212 if( CheckTagL( sub, aTag, aTagValue ) ) |
|
213 { |
|
214 CleanupStack::PopAndDestroy(&childElements); |
|
215 return ETrue; |
|
216 } |
|
217 |
|
218 } |
|
219 CleanupStack::PopAndDestroy(&childElements); |
|
220 } |
|
221 |
|
222 return EFalse; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // UpnpDomInterface::CheckSubTagPrefixL |
|
227 // Check sub tag prefix. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 EXPORT_C TBool CheckSubTagPrefixL( const TXmlEngElement& aElement, |
|
231 const TDesC8& aNameSpacePrefix, |
|
232 const TDesC8& aTag, |
|
233 const TDesC8& aTagValue ) |
|
234 { |
|
235 |
|
236 // Go through the elements of the current level. |
|
237 if ( aElement.NotNull() ) |
|
238 { |
|
239 |
|
240 RXmlEngNodeList<TXmlEngElement> childElements; |
|
241 CleanupClosePushL(childElements); |
|
242 aElement.GetChildElements( childElements ); |
|
243 |
|
244 while( childElements.HasNext() ) |
|
245 { |
|
246 |
|
247 // Get a single element of the current level |
|
248 TXmlEngElement sub = childElements.Next(); |
|
249 |
|
250 if( CheckTagL( sub, aTag, aTagValue ) ) |
|
251 { |
|
252 |
|
253 TXmlEngNamespace ns = sub.LookupNamespaceByPrefixL( aNameSpacePrefix ); |
|
254 |
|
255 //Does the prefix match or is there is no prefix if empty string was passed |
|
256 if( ns.NotNull() || ( ns.IsNull() && aNameSpacePrefix.Length() == 0 ) ) |
|
257 { |
|
258 CleanupStack::PopAndDestroy(&childElements); |
|
259 return ETrue; |
|
260 } |
|
261 } |
|
262 } |
|
263 CleanupStack::PopAndDestroy(&childElements); |
|
264 } |
|
265 |
|
266 return EFalse; |
|
267 |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // UpnpDomInterface::CheckAttributeValueL |
|
272 // Check attribute value. |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C TBool CheckAttributeValueL( const TXmlEngElement& aElement, |
|
276 const TDesC8& aAttribute, |
|
277 const TDesC8& aValue ) |
|
278 { |
|
279 if ( aElement.NotNull() ) |
|
280 { |
|
281 |
|
282 // Check existence and value of the argument |
|
283 TInt difference = aElement.AttributeValueL( aAttribute ).Compare( aValue ); |
|
284 |
|
285 if(!difference) |
|
286 return ETrue; |
|
287 else |
|
288 return EFalse; |
|
289 |
|
290 } |
|
291 |
|
292 return EFalse; |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // UpnpDomInterface::DeleteElement |
|
297 // Delete DOM element from the tree. |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 EXPORT_C TXmlEngElement DeleteElement(TXmlEngElement& aElement) |
|
301 { |
|
302 |
|
303 if( aElement.IsNull() ) |
|
304 { |
|
305 TXmlEngElement nullElement; |
|
306 return nullElement; |
|
307 } |
|
308 |
|
309 TXmlEngElement parent = aElement.ParentNode().AsElement(); |
|
310 |
|
311 aElement.Remove(); |
|
312 |
|
313 return parent; |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // UpnpDomInterface::GetElementL |
|
318 // Get element. |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C TBool GetElementL( const TXmlEngElement& aElement, |
|
322 TXmlEngElement& aWanted, |
|
323 const TDesC8& aMainTag, |
|
324 TInt aDepth, |
|
325 TInt aCurrentDepth ) |
|
326 { |
|
327 |
|
328 if ( aElement.NotNull() ) |
|
329 { |
|
330 aCurrentDepth++; |
|
331 |
|
332 RXmlEngNodeList<TXmlEngElement> childElements; |
|
333 CleanupClosePushL(childElements); |
|
334 aElement.GetChildElements( childElements ); |
|
335 |
|
336 while( childElements.HasNext() ) |
|
337 { |
|
338 |
|
339 // Get a single element of the current level |
|
340 TXmlEngElement sub = childElements.Next(); |
|
341 |
|
342 // Check the name of the element, |
|
343 // if it equals to MainTag (the wanted value) |
|
344 if ( CheckTagL( sub, aMainTag ) ) |
|
345 { |
|
346 aWanted = sub; |
|
347 CleanupStack::PopAndDestroy(&childElements); |
|
348 return ETrue; |
|
349 } |
|
350 // Else go deeper into the tree. |
|
351 else if ( aDepth < 0 || aDepth > aCurrentDepth ) |
|
352 { |
|
353 |
|
354 if ( GetElementL( sub, |
|
355 aWanted, |
|
356 aMainTag, |
|
357 aDepth, |
|
358 aCurrentDepth ) |
|
359 == ( TBool ) ETrue ) |
|
360 |
|
361 { |
|
362 CleanupStack::PopAndDestroy(&childElements); |
|
363 return ETrue; |
|
364 } |
|
365 } |
|
366 else |
|
367 { |
|
368 } |
|
369 } |
|
370 CleanupStack::PopAndDestroy(&childElements); |
|
371 } |
|
372 |
|
373 return EFalse; |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // UpnpDomInterface::GetElementL |
|
378 // Get element. |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 EXPORT_C TBool GetElementL( const TXmlEngElement& aElement, |
|
382 TXmlEngElement& aWanted, |
|
383 const TDesC8& aMainTag, |
|
384 const TDesC8& aSubTag, |
|
385 TInt aDepth, |
|
386 TInt aCurrentDepth ) |
|
387 { |
|
388 |
|
389 if ( aElement.NotNull() ) |
|
390 { |
|
391 |
|
392 // Add one Depth level to the counter |
|
393 // (affects only current and deeper levels) |
|
394 aCurrentDepth++; |
|
395 |
|
396 RXmlEngNodeList<TXmlEngElement> childElements; |
|
397 CleanupClosePushL(childElements); |
|
398 aElement.GetChildElements( childElements ); |
|
399 |
|
400 while( childElements.HasNext() ) |
|
401 { |
|
402 |
|
403 // Get a single element of the current level |
|
404 TXmlEngElement sub = childElements.Next(); |
|
405 |
|
406 // Check the name of the element, |
|
407 // if it equals to MainTag (the wanted value) |
|
408 if ( CheckTagL( sub, aMainTag ) ) |
|
409 { |
|
410 |
|
411 // Check that it holds the wanted subtag |
|
412 // and that the subtags value is the wanted one. |
|
413 if ( CheckSubTagL( sub, aSubTag ) == ( TBool ) ETrue ) |
|
414 { |
|
415 aWanted = sub; |
|
416 CleanupStack::PopAndDestroy(&childElements); |
|
417 return ETrue; |
|
418 } |
|
419 } |
|
420 |
|
421 // Else go deeper into the tree. |
|
422 else |
|
423 { |
|
424 |
|
425 if ( aDepth < 0 || aDepth > aCurrentDepth ) |
|
426 { |
|
427 |
|
428 if ( GetElementL( sub, |
|
429 aWanted, |
|
430 aMainTag, |
|
431 aSubTag, |
|
432 aDepth, |
|
433 aCurrentDepth ) |
|
434 == ( TBool )ETrue ) |
|
435 { |
|
436 CleanupStack::PopAndDestroy(&childElements); |
|
437 return ETrue; |
|
438 } |
|
439 } |
|
440 } |
|
441 } |
|
442 CleanupStack::PopAndDestroy(&childElements); |
|
443 } |
|
444 |
|
445 return EFalse; |
|
446 } |
|
447 |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // UpnpDomInterface::GetElementL |
|
451 // Get element. |
|
452 // ----------------------------------------------------------------------------- |
|
453 // |
|
454 EXPORT_C TBool GetElementL( const TXmlEngElement& aElement, |
|
455 TXmlEngElement& aWanted, |
|
456 const TDesC8& aMainTag, |
|
457 const TDesC8& aSubTag, |
|
458 const TDesC8& aSubTagValue, |
|
459 TInt aDepth, TInt aCurrentDepth ) |
|
460 { |
|
461 |
|
462 if ( aElement.NotNull() ) |
|
463 { |
|
464 |
|
465 // Add one Depth level to the counter |
|
466 // (affects only current and deeper levels) |
|
467 aCurrentDepth++; |
|
468 |
|
469 RXmlEngNodeList<TXmlEngElement> childElements; |
|
470 CleanupClosePushL(childElements); |
|
471 aElement.GetChildElements( childElements ); |
|
472 CleanupStack::Check(&childElements); |
|
473 while( childElements.HasNext() ) |
|
474 { |
|
475 |
|
476 // Get a single element of the current level |
|
477 TXmlEngElement sub = childElements.Next(); |
|
478 |
|
479 // Check the name of the element, |
|
480 // if it equals to MainTag (the wanted value) |
|
481 if ( CheckTagL( sub, aMainTag ) ) |
|
482 { |
|
483 CleanupStack::Check(&childElements); |
|
484 // Check that it holds the wanted subtag and |
|
485 // that the subtags value is the wanted one. |
|
486 if ( CheckSubTagL( sub, |
|
487 aSubTag, |
|
488 aSubTagValue ) |
|
489 == ( TBool ) ETrue ) |
|
490 { |
|
491 aWanted = sub; |
|
492 CleanupStack::PopAndDestroy(&childElements); |
|
493 return ETrue; |
|
494 } |
|
495 } |
|
496 |
|
497 // Else go deeper into the tree. |
|
498 else |
|
499 { |
|
500 |
|
501 if ( aDepth < 0 || aDepth > aCurrentDepth ) |
|
502 { |
|
503 |
|
504 if ( GetElementL( sub, |
|
505 aWanted, |
|
506 aMainTag, |
|
507 aSubTag, |
|
508 aSubTagValue, |
|
509 aDepth, |
|
510 aCurrentDepth ) |
|
511 == ( TBool ) ETrue ) |
|
512 { |
|
513 CleanupStack::PopAndDestroy(&childElements); |
|
514 return ETrue; |
|
515 } |
|
516 } |
|
517 } |
|
518 } |
|
519 CleanupStack::PopAndDestroy(&childElements); |
|
520 } |
|
521 |
|
522 return EFalse; |
|
523 } |
|
524 |
|
525 |
|
526 // ----------------------------------------------------------------------------- |
|
527 // UpnpDomInterface::GetContentElementL |
|
528 // Get content element. |
|
529 // ----------------------------------------------------------------------------- |
|
530 // |
|
531 EXPORT_C TBool GetContentElementL( const TXmlEngElement& aElement, |
|
532 TXmlEngElement& aWanted, |
|
533 const TDesC8& aSubTag, |
|
534 const TDesC8& aSubTagValue, |
|
535 TInt aDepth, |
|
536 TInt aCurrentDepth ) |
|
537 { |
|
538 |
|
539 if ( aElement.NotNull() ) |
|
540 { |
|
541 |
|
542 // Add one Depth level to the counter |
|
543 // (affects only current and deeper levels) |
|
544 aCurrentDepth++; |
|
545 |
|
546 RXmlEngNodeList<TXmlEngElement> childElements; |
|
547 CleanupClosePushL(childElements); |
|
548 aElement.GetChildElements( childElements ); |
|
549 |
|
550 while( childElements.HasNext() ) |
|
551 { |
|
552 |
|
553 // Get a single element of the current level |
|
554 TXmlEngElement sub = childElements.Next(); |
|
555 |
|
556 if ( CheckTagL( sub, aSubTag, aSubTagValue ) ) |
|
557 { |
|
558 aWanted = sub; |
|
559 CleanupStack::PopAndDestroy(&childElements); |
|
560 return ETrue; |
|
561 } |
|
562 // Else go deeper into the tree. |
|
563 else if ( aDepth < 0 || aDepth > aCurrentDepth ) |
|
564 { |
|
565 |
|
566 if ( GetContentElementL( sub, |
|
567 aWanted, |
|
568 aSubTag, |
|
569 aSubTagValue, |
|
570 aDepth, |
|
571 aCurrentDepth ) |
|
572 == ( TBool ) ETrue ) |
|
573 { |
|
574 CleanupStack::PopAndDestroy(&childElements); |
|
575 return ETrue; |
|
576 } |
|
577 |
|
578 } |
|
579 else |
|
580 { |
|
581 } |
|
582 } |
|
583 CleanupStack::PopAndDestroy(&childElements); |
|
584 } |
|
585 |
|
586 return EFalse; |
|
587 } |
|
588 |
|
589 // ----------------------------------------------------------------------------- |
|
590 // UpnpDomInterface::GetDirectoryElementL |
|
591 // Get directory element. |
|
592 // ----------------------------------------------------------------------------- |
|
593 // |
|
594 EXPORT_C TBool GetDirectoryElementL( const TXmlEngElement& aElement, |
|
595 TXmlEngElement& aWanted, |
|
596 const TDesC8& aMainTag, |
|
597 const TDesC8& aAttribute, |
|
598 const TDesC8& aAttributeValue, |
|
599 TInt aDepth, |
|
600 TInt aCurrentDepth) |
|
601 |
|
602 { |
|
603 |
|
604 if ( aElement.NotNull() ) |
|
605 { |
|
606 |
|
607 // Add one Depth level to the counter |
|
608 // (affects only current and deeper levels) |
|
609 aCurrentDepth++; |
|
610 |
|
611 RXmlEngNodeList<TXmlEngElement> childElements; |
|
612 CleanupClosePushL(childElements); |
|
613 aElement.GetChildElements( childElements ); |
|
614 |
|
615 while( childElements.HasNext() ) |
|
616 { |
|
617 |
|
618 // Get a single element of the current level |
|
619 TXmlEngElement sub = childElements.Next(); |
|
620 |
|
621 if ( CheckTagL( sub, aMainTag ) ) |
|
622 { |
|
623 if ( CheckAttributeValueL( sub,aAttribute,aAttributeValue ) ) |
|
624 { |
|
625 aWanted = sub; |
|
626 CleanupStack::PopAndDestroy(&childElements); |
|
627 return ETrue; |
|
628 } |
|
629 |
|
630 } |
|
631 // Else go deeper into the tree. |
|
632 else |
|
633 { |
|
634 |
|
635 if ( aDepth < 0 || aDepth > aCurrentDepth ) |
|
636 { |
|
637 |
|
638 if ( GetDirectoryElementL( sub, |
|
639 aWanted, |
|
640 aMainTag, |
|
641 aAttribute, |
|
642 aAttributeValue, |
|
643 aDepth, |
|
644 aCurrentDepth ) == ( TBool ) ETrue ) |
|
645 { |
|
646 CleanupStack::PopAndDestroy(&childElements); |
|
647 return ETrue; |
|
648 } |
|
649 } |
|
650 } |
|
651 } |
|
652 CleanupStack::PopAndDestroy(&childElements); |
|
653 } |
|
654 |
|
655 return EFalse; |
|
656 } |
|
657 |
|
658 // ----------------------------------------------------------------------------- |
|
659 // UpnpDomInterface::GetDirectoryElementL |
|
660 // Get directory element. |
|
661 // ----------------------------------------------------------------------------- |
|
662 // |
|
663 EXPORT_C TBool GetDirectoryElementL( const TXmlEngElement& aElement, |
|
664 TXmlEngElement& aWanted, |
|
665 const TDesC8& aAttribute, |
|
666 const TDesC8& aAttributeValue, |
|
667 TInt aDepth, |
|
668 TInt aCurrentDepth) |
|
669 |
|
670 { |
|
671 |
|
672 if ( aElement.NotNull() ) |
|
673 { |
|
674 |
|
675 // Add one Depth level to the counter |
|
676 // (affects only current and deeper levels) |
|
677 aCurrentDepth++; |
|
678 |
|
679 RXmlEngNodeList<TXmlEngElement> childElements; |
|
680 CleanupClosePushL(childElements); |
|
681 aElement.GetChildElements( childElements ); |
|
682 |
|
683 while( childElements.HasNext() ) |
|
684 { |
|
685 |
|
686 // Get a single element of the current level |
|
687 TXmlEngElement sub = childElements.Next(); |
|
688 |
|
689 if ( CheckAttributeValueL( sub, |
|
690 aAttribute, |
|
691 aAttributeValue ) ==( TBool ) ETrue ) |
|
692 { |
|
693 aWanted = sub; |
|
694 CleanupStack::PopAndDestroy(&childElements); |
|
695 return ETrue; |
|
696 } |
|
697 |
|
698 if ( aDepth < 0 || aDepth > aCurrentDepth ) |
|
699 { |
|
700 |
|
701 if ( GetDirectoryElementL( sub, |
|
702 aWanted, |
|
703 aAttribute, |
|
704 aAttributeValue, |
|
705 aDepth, |
|
706 aCurrentDepth ) == ( TBool ) ETrue ) |
|
707 |
|
708 { |
|
709 CleanupStack::PopAndDestroy(&childElements); |
|
710 return ETrue; |
|
711 } |
|
712 } |
|
713 |
|
714 } |
|
715 CleanupStack::PopAndDestroy(&childElements); |
|
716 } |
|
717 |
|
718 return EFalse; |
|
719 } |
|
720 |
|
721 // ----------------------------------------------------------------------------- |
|
722 // UpnpDomInterface::GetElementListL |
|
723 // Get element list. |
|
724 // ----------------------------------------------------------------------------- |
|
725 // |
|
726 EXPORT_C TBool GetElementListL( const TXmlEngElement& aElement, |
|
727 RArray<TXmlEngElement>& aElementList, |
|
728 const TDesC8& aMainTag, |
|
729 TBool aSearchable ) |
|
730 { |
|
731 |
|
732 TBool status = EFalse; |
|
733 |
|
734 if ( aElement.NotNull() ) |
|
735 { |
|
736 |
|
737 RXmlEngNodeList<TXmlEngElement> childElements; |
|
738 CleanupClosePushL(childElements); |
|
739 aElement.GetChildElements( childElements ); |
|
740 |
|
741 while( childElements.HasNext() ) |
|
742 { |
|
743 |
|
744 // Get a single element of the current level |
|
745 TXmlEngElement sub = childElements.Next(); |
|
746 |
|
747 //Get "searchable" attribute value |
|
748 TPtrC8 searchable = GetAttrValueL( sub, KSearchable() ); |
|
749 |
|
750 // aSearchable == false || tag != "container" || aSearchable == true && searchable == "true" |
|
751 // check this "true" value |
|
752 if ( aSearchable == ( TBool ) EFalse |
|
753 || ( !CheckTagL( sub, KContainer() ) ) |
|
754 || ( aSearchable == ( TBool ) ETrue && searchable.Compare( KTrueVal() ) == 0 ) ) |
|
755 { |
|
756 |
|
757 if ( CheckTagL( sub, aMainTag ) ) |
|
758 { |
|
759 User::LeaveIfError(aElementList.Append( sub)); |
|
760 status = ETrue; |
|
761 } |
|
762 |
|
763 else |
|
764 { |
|
765 if ( status == ( TBool ) ETrue ) |
|
766 { |
|
767 GetElementListL( sub, |
|
768 aElementList, |
|
769 aMainTag, |
|
770 aSearchable ); |
|
771 } |
|
772 |
|
773 else |
|
774 { |
|
775 status = GetElementListL( sub, |
|
776 aElementList, |
|
777 aMainTag, |
|
778 aSearchable ); |
|
779 } |
|
780 } |
|
781 } |
|
782 } |
|
783 CleanupStack::PopAndDestroy(&childElements); |
|
784 } |
|
785 |
|
786 return status; |
|
787 } |
|
788 |
|
789 // ----------------------------------------------------------------------------- |
|
790 // UpnpDomInterface::GetElementListL |
|
791 // Get element list. |
|
792 // ----------------------------------------------------------------------------- |
|
793 // |
|
794 EXPORT_C TBool GetElementListL( const TXmlEngElement& aElement, |
|
795 RArray<TXmlEngElement>& aElementList, |
|
796 const TDesC8& aMainTag, |
|
797 const TDesC8& aSubTag, |
|
798 const TDesC8& aSubValue, |
|
799 TBool aSearchable ) |
|
800 { |
|
801 |
|
802 TBool status = EFalse; |
|
803 |
|
804 if ( aElement.NotNull() ) |
|
805 { |
|
806 |
|
807 RXmlEngNodeList<TXmlEngElement> childElements; |
|
808 CleanupClosePushL(childElements); |
|
809 aElement.GetChildElements( childElements ); |
|
810 |
|
811 while( childElements.HasNext() ) |
|
812 { |
|
813 |
|
814 // Get a single element of the current level |
|
815 TXmlEngElement sub = childElements.Next(); |
|
816 |
|
817 //Get "searchable" attribute value |
|
818 TPtrC8 searchable = GetAttrValueL( sub, KSearchable() ); |
|
819 |
|
820 // aSearchable == false || tag != "container" || aSearchable == true && searchable == "true" |
|
821 // check this "true" value |
|
822 if ( aSearchable == ( TBool ) EFalse |
|
823 || ( !CheckTagL( sub, KContainer() ) ) |
|
824 || ( aSearchable == ( TBool ) ETrue && searchable.Compare( KTrueVal() ) == 0 ) ) |
|
825 { |
|
826 |
|
827 if ( CheckTagL( sub, aMainTag ) ) |
|
828 { |
|
829 if ( CheckSubTagL( sub, aSubTag, aSubValue ) ) |
|
830 { |
|
831 User::LeaveIfError(aElementList.Append( sub)); |
|
832 status = ETrue; |
|
833 } |
|
834 } |
|
835 else |
|
836 { |
|
837 if ( status == ( TBool ) ETrue ) |
|
838 { |
|
839 GetElementListL( sub, |
|
840 aElementList, |
|
841 aMainTag, |
|
842 aSubTag, |
|
843 aSubValue, |
|
844 aSearchable ); |
|
845 |
|
846 } |
|
847 else |
|
848 { |
|
849 status = GetElementListL( sub, |
|
850 aElementList, |
|
851 aMainTag, |
|
852 aSubTag, |
|
853 aSubValue, |
|
854 aSearchable ); |
|
855 |
|
856 } |
|
857 } |
|
858 |
|
859 } |
|
860 } |
|
861 CleanupStack::PopAndDestroy(&childElements); |
|
862 } |
|
863 |
|
864 return status; |
|
865 } |
|
866 |
|
867 // ----------------------------------------------------------------------------- |
|
868 // UpnpDomInterface::GetElementListL |
|
869 // Get element list. |
|
870 // ----------------------------------------------------------------------------- |
|
871 // |
|
872 EXPORT_C TBool GetElementListL( const TXmlEngElement& aElement, |
|
873 RArray<TXmlEngElement>& aElementList, |
|
874 const TDesC8& aMainTag, |
|
875 const TDesC8& aSubTag, |
|
876 const TDesC8& aSubValue, |
|
877 const TDesC8& aNSPrefix, |
|
878 TBool aSearchable ) |
|
879 { |
|
880 TBool status = EFalse; |
|
881 |
|
882 if ( aElement.NotNull() ) |
|
883 { |
|
884 |
|
885 RXmlEngNodeList<TXmlEngElement> childElements; |
|
886 CleanupClosePushL(childElements); |
|
887 aElement.GetChildElements( childElements ); |
|
888 |
|
889 while( childElements.HasNext() ) |
|
890 { |
|
891 |
|
892 // Get a single element of the current level |
|
893 TXmlEngElement sub = childElements.Next(); |
|
894 |
|
895 //Get "searchable" attribute value |
|
896 TPtrC8 searchable = GetAttrValueL( sub, KSearchable() ); |
|
897 |
|
898 // aSearchable == false || tag != "container" || aSearchable == true && searchable == "true" |
|
899 // check this "true" value |
|
900 if ( aSearchable == ( TBool ) EFalse |
|
901 || ( !CheckTagL( sub, KContainer() ) ) |
|
902 || ( aSearchable == ( TBool ) ETrue && searchable.Compare( KTrueVal() ) == 0 ) ) |
|
903 { |
|
904 |
|
905 if ( CheckTagL( sub, aMainTag ) ) |
|
906 { |
|
907 if( CheckSubTagPrefixL( sub, |
|
908 aNSPrefix, |
|
909 aSubTag, |
|
910 aSubValue ) ) |
|
911 |
|
912 { |
|
913 User::LeaveIfError(aElementList.Append( sub)); |
|
914 status = ETrue; |
|
915 } |
|
916 } |
|
917 else |
|
918 { |
|
919 |
|
920 if ( status == ( TBool ) ETrue ) |
|
921 { |
|
922 GetElementListL( sub, |
|
923 aElementList, |
|
924 aMainTag, |
|
925 aSubTag, |
|
926 aSubValue, |
|
927 aNSPrefix, |
|
928 aSearchable ); |
|
929 |
|
930 } |
|
931 else |
|
932 { |
|
933 status = GetElementListL( sub, |
|
934 aElementList, |
|
935 aMainTag, |
|
936 aSubTag, |
|
937 aSubValue, |
|
938 aNSPrefix, |
|
939 aSearchable ); |
|
940 |
|
941 } |
|
942 } |
|
943 |
|
944 } |
|
945 } |
|
946 CleanupStack::PopAndDestroy(&childElements); |
|
947 } |
|
948 |
|
949 if ( status == ( TBool ) ETrue ) |
|
950 { |
|
951 return ETrue; |
|
952 } |
|
953 |
|
954 return EFalse; |
|
955 } |
|
956 |
|
957 // ----------------------------------------------------------------------------- |
|
958 // UpnpDomInterface::GetContentElementListL |
|
959 // Get content element list. |
|
960 // ----------------------------------------------------------------------------- |
|
961 // |
|
962 EXPORT_C TBool GetContentElementListL( const TXmlEngElement& aElement, |
|
963 RArray<TXmlEngElement>& aElementList, |
|
964 const TDesC8& aSubTag, |
|
965 const TDesC8& aSubValue, |
|
966 TBool aSearchable ) |
|
967 { |
|
968 // Operators: MainTag |
|
969 // Example: GetStateVariableList |
|
970 // MainTag = "stateVariableTable" |
|
971 |
|
972 |
|
973 if ( aElement.NotNull() ) |
|
974 { |
|
975 TBool status = EFalse; |
|
976 |
|
977 RXmlEngNodeList<TXmlEngElement> childElements; |
|
978 CleanupClosePushL(childElements); |
|
979 aElement.GetChildElements( childElements ); |
|
980 |
|
981 while( childElements.HasNext() ) |
|
982 { |
|
983 |
|
984 // Get a single element of the current level |
|
985 TXmlEngElement sub = childElements.Next(); |
|
986 |
|
987 //Get "searchable" attribute value |
|
988 TPtrC8 searchable = GetAttrValueL( sub, KSearchable() ); |
|
989 |
|
990 // aSearchable == false || tag != "container" || aSearchable == true && searchable == "true" |
|
991 // check this "true" value |
|
992 if ( aSearchable == ( TBool ) EFalse |
|
993 || ( !CheckTagL( sub, KContainer() ) ) |
|
994 || ( aSearchable == ( TBool ) ETrue && searchable.Compare( KTrueVal() ) == 0 ) ) |
|
995 { |
|
996 |
|
997 if( CheckTagL( sub, aSubTag, aSubValue ) ) |
|
998 { |
|
999 User::LeaveIfError(aElementList.Append( sub)); |
|
1000 status = ETrue; |
|
1001 } |
|
1002 else |
|
1003 { |
|
1004 |
|
1005 if(status == ( TBool ) ETrue ) |
|
1006 { |
|
1007 GetContentElementListL( sub, |
|
1008 aElementList, |
|
1009 aSubTag, |
|
1010 aSubValue, |
|
1011 aSearchable ); |
|
1012 } |
|
1013 |
|
1014 else |
|
1015 { |
|
1016 status = GetContentElementListL( sub, |
|
1017 aElementList, |
|
1018 aSubTag, |
|
1019 aSubValue, |
|
1020 aSearchable ); |
|
1021 } |
|
1022 } |
|
1023 } |
|
1024 } |
|
1025 CleanupStack::PopAndDestroy(&childElements); |
|
1026 return status; |
|
1027 } |
|
1028 |
|
1029 return EFalse; |
|
1030 } |
|
1031 |
|
1032 |
|
1033 |
|
1034 // ----------------------------------------------------------------------------- |
|
1035 // UpnpDomInterface::GetDirectoryElementListL |
|
1036 // Get directory element list. |
|
1037 // ----------------------------------------------------------------------------- |
|
1038 // |
|
1039 EXPORT_C TBool GetDirectoryElementListL( const TXmlEngElement& aElement, |
|
1040 RArray<TXmlEngElement>& aElementList, |
|
1041 const TDesC8& aAttrName, |
|
1042 const TDesC8& aAttrValue, |
|
1043 TBool aSearchable ) |
|
1044 { |
|
1045 TBool status = EFalse; |
|
1046 |
|
1047 if ( aElement.NotNull() ) |
|
1048 { |
|
1049 |
|
1050 RXmlEngNodeList<TXmlEngElement> childElements; |
|
1051 CleanupClosePushL(childElements); |
|
1052 aElement.GetChildElements( childElements ); |
|
1053 |
|
1054 while( childElements.HasNext() ) |
|
1055 { |
|
1056 |
|
1057 // Get a single element of the current level |
|
1058 TXmlEngElement sub = childElements.Next(); |
|
1059 |
|
1060 //Get "searchable" attribute value |
|
1061 TPtrC8 searchable = GetAttrValueL( sub, KSearchable() ); |
|
1062 |
|
1063 // aSearchable == false || tag != "container" || aSearchable == true && searchable == "true" |
|
1064 // check this "true" value |
|
1065 if ( aSearchable == ( TBool ) EFalse |
|
1066 || ( !CheckTagL( sub, KContainer() ) ) |
|
1067 || ( aSearchable == ( TBool ) ETrue && searchable.Compare( KTrueVal() ) == 0 ) ) |
|
1068 { |
|
1069 |
|
1070 if ( CheckAttributeValueL( sub, aAttrName, aAttrValue ) ) |
|
1071 { |
|
1072 |
|
1073 User::LeaveIfError(aElementList.Append( sub)); |
|
1074 status = ETrue; |
|
1075 } |
|
1076 |
|
1077 if ( status ) |
|
1078 { |
|
1079 GetDirectoryElementListL( sub, |
|
1080 aElementList, |
|
1081 aAttrName, |
|
1082 aAttrValue, |
|
1083 aSearchable ); |
|
1084 } |
|
1085 |
|
1086 else |
|
1087 { |
|
1088 status = GetDirectoryElementListL( sub, |
|
1089 aElementList, |
|
1090 aAttrName, |
|
1091 aAttrValue, |
|
1092 aSearchable ); |
|
1093 } |
|
1094 } |
|
1095 } |
|
1096 CleanupStack::PopAndDestroy(&childElements); |
|
1097 } |
|
1098 |
|
1099 return status; |
|
1100 } |
|
1101 |
|
1102 // ----------------------------------------------------------------------------- |
|
1103 // UpnpDomInterface::SaveToFileL |
|
1104 // Save to file. |
|
1105 // ----------------------------------------------------------------------------- |
|
1106 // |
|
1107 EXPORT_C TBool SaveToFileL( const TDesC16& aFileName, |
|
1108 const TXmlEngElement& aRoot ) |
|
1109 { |
|
1110 TBool result = EFalse; |
|
1111 // Check element |
|
1112 if ( aRoot.IsNull() ) |
|
1113 { |
|
1114 return result; |
|
1115 } |
|
1116 |
|
1117 // Get XML document handler from DOM tree root node and save it to the file |
|
1118 RXmlEngDocument doc = aRoot.OwnerDocument(); |
|
1119 |
|
1120 //Dump XML tree into buffer |
|
1121 RBuf8 xmlBuf; |
|
1122 TXmlEngSerializationOptions options(TXmlEngSerializationOptions::KOptionIndent | |
|
1123 TXmlEngSerializationOptions::KOptionEncoding); |
|
1124 |
|
1125 doc.SaveL( xmlBuf, aRoot, options); |
|
1126 CleanupClosePushL(xmlBuf); |
|
1127 result = SaveToFileL( aFileName, xmlBuf ); |
|
1128 CleanupStack::PopAndDestroy(&xmlBuf); |
|
1129 |
|
1130 return result; |
|
1131 } |
|
1132 |
|
1133 |
|
1134 // ----------------------------------------------------------------------------- |
|
1135 // UpnpDomInterface::SaveToFileL |
|
1136 // Save to file. |
|
1137 // ----------------------------------------------------------------------------- |
|
1138 // |
|
1139 EXPORT_C TBool SaveToFileL( const TDesC16& aFileName, |
|
1140 const TDesC8& aData ) |
|
1141 { |
|
1142 // Create file server session |
|
1143 RFs fs; |
|
1144 TInt error = fs.Connect(); |
|
1145 |
|
1146 if ( error != KErrNone ) |
|
1147 { |
|
1148 LOGS("SERVICE *** RFs::Connect() id 12 failed; ERROR"); |
|
1149 |
|
1150 return EFalse; |
|
1151 } |
|
1152 |
|
1153 RFile file; |
|
1154 |
|
1155 // Create or Replace the requested file, |
|
1156 // if operation does not succeed return EFalse |
|
1157 if ( file.Replace( fs, aFileName, EFileWrite ) == KErrNone ) |
|
1158 { |
|
1159 RFileWriteStream writeStream( file ); |
|
1160 CleanupClosePushL(fs); |
|
1161 CleanupClosePushL(file); |
|
1162 CleanupReleasePushL(writeStream); |
|
1163 writeStream.WriteL( aData ); |
|
1164 writeStream.CommitL(); |
|
1165 |
|
1166 |
|
1167 CleanupStack::PopAndDestroy(&writeStream); |
|
1168 CleanupStack::PopAndDestroy(&file); |
|
1169 CleanupStack::PopAndDestroy(&fs); |
|
1170 |
|
1171 return ETrue; |
|
1172 } |
|
1173 |
|
1174 else |
|
1175 { |
|
1176 LOGS("SERVICE *** RFile::Replace() id 12 failed; ERROR"); |
|
1177 fs.Close(); |
|
1178 return EFalse; |
|
1179 } |
|
1180 } |
|
1181 |
|
1182 } |
|
1183 |
|
1184 // End of File |