|
1 /* |
|
2 * Copyright (c) 2008 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: XML SAX Parser for UPnP. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 // xml parser api |
|
25 #include <xml/parser.h> |
|
26 #include <xml/parserfeature.h> |
|
27 #include <xml/matchdata.h> |
|
28 #include <xml/xmlparsererrors.h> |
|
29 |
|
30 // upnp stack api |
|
31 #include "upnpstring.h" |
|
32 #include <upnpcontainer.h> |
|
33 #include <upnpitem.h> |
|
34 #include "upnpelement.h" |
|
35 #include "upnpxmlparser.h" |
|
36 |
|
37 // upnpframework / internal api's |
|
38 #include "upnpcdsreselementutility.h" |
|
39 |
|
40 // xmlparser internal |
|
41 #include "upnpobjectstack.h" |
|
42 #include "upnpitemtoxml.h" |
|
43 #include "upnpxmlstringutility.h" |
|
44 #include "upnpxmlparser.h" |
|
45 |
|
46 _LIT( KComponentLogfile, "upnpxmlparser.txt"); |
|
47 #include "upnplog.h" |
|
48 |
|
49 |
|
50 _LIT8( KXmlMimeType, "text/xml" ); |
|
51 _LIT8( KLIB2XML, "libxml2" ); |
|
52 |
|
53 _LIT8( KContainer, "container" ); |
|
54 _LIT8( KItem, "item" ); |
|
55 |
|
56 _LIT8( KTitle, "title" ); |
|
57 |
|
58 _LIT8( KClass, "class" ); |
|
59 _LIT8( KContentURI, "res" ); |
|
60 _LIT8( KId, "id" ); |
|
61 _LIT8( KParentId, "parentId" ); |
|
62 _LIT8( KRestricted, "restricted" ); |
|
63 _LIT8( KComma, ":" ); |
|
64 _LIT8( KTrue, "1" ); |
|
65 _LIT8( KDIDL, "DIDL-Lite" ); |
|
66 _LIT8( KDesc, "desc" ); |
|
67 _LIT8( KDlnaDoc, "X_DLNADOC" ); |
|
68 _LIT8( KSpace, " " ); |
|
69 _LIT8( KImportUri, "importUri" ); |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CUPnPXMLParser::CUPnPXMLParser() |
|
73 // See upnpxmlparser.h |
|
74 // -------------------------------------------------------------------------- |
|
75 CUPnPXMLParser::CUPnPXMLParser() |
|
76 { |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // CUPnPXMLParser::ConstructL |
|
81 // See upnpxmlparser.h |
|
82 // -------------------------------------------------------------------------- |
|
83 void CUPnPXMLParser::ConstructL() |
|
84 { |
|
85 __LOG( "CUPnPXMLParser::CostructL" ); |
|
86 iStack = CUPnPObjectStack::NewL(); |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CUPnPXMLParser::NewL |
|
91 // See upnpxmlparser.h |
|
92 // -------------------------------------------------------------------------- |
|
93 EXPORT_C CUPnPXMLParser* CUPnPXMLParser::NewL() |
|
94 { |
|
95 CUPnPXMLParser* self = CUPnPXMLParser::NewLC(); |
|
96 CleanupStack::Pop( self ); |
|
97 return self; |
|
98 } |
|
99 |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // CUPnPXMLParser::NewLC |
|
103 // See upnpxmlparser.h |
|
104 // -------------------------------------------------------------------------- |
|
105 EXPORT_C CUPnPXMLParser* CUPnPXMLParser::NewLC() |
|
106 { |
|
107 CUPnPXMLParser* self = new( ELeave ) CUPnPXMLParser(); |
|
108 CleanupStack::PushL( self ); |
|
109 self->ConstructL(); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CUPnPXMLParser::~CUPnPXMLParser |
|
115 // See upnpxmlparser.h |
|
116 // -------------------------------------------------------------------------- |
|
117 CUPnPXMLParser::~CUPnPXMLParser() |
|
118 { |
|
119 __LOG( "CUPnPXMLParser::~CUPnPXMLParser" ); |
|
120 if ( iStack ) |
|
121 { |
|
122 iStack->ResetAndDestroy(); |
|
123 delete iStack; |
|
124 } |
|
125 |
|
126 delete iElementValue; |
|
127 delete iNewElement; |
|
128 |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CUPnPXMLParser::ResetMember |
|
133 // See upnpxmlparser.h |
|
134 // -------------------------------------------------------------------------- |
|
135 void CUPnPXMLParser::ResetMember() |
|
136 { |
|
137 iResultRoot->ResetAndDestroy(); |
|
138 iResultRoot = NULL; |
|
139 iStack->ResetAndDestroy(); |
|
140 delete iStack; |
|
141 iStack = NULL; |
|
142 |
|
143 delete iElementValue; iElementValue = NULL; |
|
144 delete iNewElement; iNewElement = NULL; |
|
145 iTitle = 0; |
|
146 iObjectClass = 0; |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CUPnPXMLParser::ParseResultDataL |
|
151 // See upnpxmlparser.h |
|
152 // -------------------------------------------------------------------------- |
|
153 EXPORT_C void CUPnPXMLParser::ParseResultDataL( |
|
154 RPointerArray<CUpnpObject>& aResultArray, |
|
155 const TDesC8& aData ) |
|
156 { |
|
157 __LOG( "CUPnPXMLParser::ParseResultDataL, begin" ); |
|
158 |
|
159 if ( !aData.Length() ) |
|
160 { |
|
161 User::Leave( KErrArgument ); |
|
162 } |
|
163 |
|
164 iResultRoot = &aResultArray; |
|
165 |
|
166 // Create parser |
|
167 CMatchData* matchData = CMatchData::NewLC(); |
|
168 matchData->SetMimeTypeL( KXmlMimeType ); |
|
169 matchData->SetVariantL( KLIB2XML ); |
|
170 CParser* parser = CParser::NewLC( *matchData, *this ); |
|
171 parser->EnableFeature( Xml::EReportNamespaceMapping ); |
|
172 |
|
173 TRAPD( err, Xml::ParseL( *parser,aData ) ); |
|
174 // if the xml contained control character |
|
175 if( EXmlInvalidToken == err ) |
|
176 { |
|
177 __LOG1 ( "CUPnPXMLParser::ParseResultDataL Can not Parse \ |
|
178 error code %d " ,err ); |
|
179 HBufC8* FiltrateBuffer = |
|
180 UpnpXmlStringUtility::RemoveXmlControlCharactersL( aData ); |
|
181 //if remove some control characters. |
|
182 if( FiltrateBuffer ) |
|
183 { |
|
184 CleanupStack::PushL( FiltrateBuffer ); |
|
185 ResetMember(); |
|
186 |
|
187 iStack = CUPnPObjectStack::NewL(); |
|
188 iResultRoot = &aResultArray; |
|
189 |
|
190 Xml::ParseL( *parser, *FiltrateBuffer ); |
|
191 CleanupStack::PopAndDestroy( FiltrateBuffer ); |
|
192 } |
|
193 else |
|
194 { |
|
195 User::Leave( err ); |
|
196 } |
|
197 } |
|
198 else if ( KErrNone != err ) |
|
199 { |
|
200 User::Leave( err ); |
|
201 } |
|
202 CleanupStack::PopAndDestroy( parser ); |
|
203 CleanupStack::PopAndDestroy( matchData ); |
|
204 |
|
205 iResultRoot = NULL; |
|
206 __LOG( "CUPnPXMLParser::ParseResultDataL, end" ); |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CUPnPXMLParser::ItemAsXMLLC |
|
211 // See upnpxmlparser.h |
|
212 // -------------------------------------------------------------------------- |
|
213 EXPORT_C HBufC8* CUPnPXMLParser::ItemAsXmlLC( const CUpnpItem& aItem ) |
|
214 { |
|
215 CUpnpItemToXML* tmpXmlItem = CUpnpItemToXML::NewLC( aItem ); |
|
216 HBufC8* raw = tmpXmlItem->AsXmlL(); |
|
217 CleanupStack::PushL( raw ); |
|
218 |
|
219 HBufC8* encoded = UpnpString::EncodeXmlStringL( raw ); |
|
220 CleanupStack::PopAndDestroy( raw ); |
|
221 CleanupStack::PushL( encoded ); |
|
222 |
|
223 HBufC8* tagged = tmpXmlItem->CreateUnDecodedXmlL( *encoded ); |
|
224 CleanupStack::PopAndDestroy( encoded ); |
|
225 CleanupStack::PopAndDestroy( tmpXmlItem ); |
|
226 CleanupStack::PushL( tagged ); |
|
227 |
|
228 return tagged; |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------- |
|
232 // CUPnPXMLParser::XmlForCreateObjectLC |
|
233 // See upnpxmlparser.h |
|
234 // -------------------------------------------------------------------------- |
|
235 EXPORT_C HBufC8* CUPnPXMLParser::XmlForCreateObjectLC( |
|
236 const CUpnpItem& aItem ) |
|
237 { |
|
238 CUpnpItemToXML* tmpXmlItem = CUpnpItemToXML::NewLC( aItem ); |
|
239 HBufC8* tempXmlDataBlock = tmpXmlItem->AsResultArgumentL(); |
|
240 CleanupStack::PopAndDestroy( tmpXmlItem ); |
|
241 CleanupStack::PushL( tempXmlDataBlock ); |
|
242 |
|
243 return tempXmlDataBlock; |
|
244 } |
|
245 |
|
246 // -------------------------------------------------------------------------- |
|
247 // CUPnPXMLParser::ContainerToXmlLC |
|
248 // See upnpxmlparser.h |
|
249 // -------------------------------------------------------------------------- |
|
250 EXPORT_C HBufC8* CUPnPXMLParser::ContainerToXmlLC( |
|
251 const CUpnpContainer& /*aContainer*/ ) |
|
252 { |
|
253 // Not implemented |
|
254 User::Leave( KErrNotSupported ); |
|
255 |
|
256 return NULL; |
|
257 } |
|
258 |
|
259 // -------------------------------------------------------------------------- |
|
260 // CUPnPXMLParser::OnStartDocumentL |
|
261 // See upnpxmlparser.h |
|
262 // -------------------------------------------------------------------------- |
|
263 void CUPnPXMLParser::OnStartDocumentL( |
|
264 const RDocumentParameters& /*aDocParam*/, |
|
265 TInt /*aErrorCode*/ ) |
|
266 { |
|
267 // No implementation needed |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------- |
|
271 // CUPnPXMLParser::OnEndDocumentL |
|
272 // See upnpxmlparser.h |
|
273 // -------------------------------------------------------------------------- |
|
274 void CUPnPXMLParser::OnEndDocumentL( TInt /*aErrorCode*/ ) |
|
275 { |
|
276 // No implementation needed |
|
277 } |
|
278 |
|
279 // -------------------------------------------------------------------------- |
|
280 // CUPnPXMLParser::OnStartElementL |
|
281 // See upnpxmlparser.h |
|
282 // -------------------------------------------------------------------------- |
|
283 void CUPnPXMLParser::OnStartElementL( const RTagInfo& aElement, |
|
284 const RAttributeArray& aAttributes, |
|
285 TInt aErrorCode ) |
|
286 { |
|
287 __LOG1( "CUPnPXMLParser::OnStartElementL, error code: %d", aErrorCode ); |
|
288 if ( aErrorCode != KErrNone ) |
|
289 { |
|
290 return; |
|
291 } |
|
292 const TDesC8& desName = aElement.LocalName().DesC(); |
|
293 const TDesC8& prefix = aElement.Prefix().DesC(); |
|
294 |
|
295 // Delete content, since there may be some stuff between the elements |
|
296 // (comments, whitespace etc.) |
|
297 delete iElementValue; iElementValue = NULL; |
|
298 |
|
299 if ( !desName.CompareF( KContainer ) ) // Container element |
|
300 { |
|
301 CUpnpContainer* tmpContainer = CUpnpContainer::NewL(); |
|
302 CleanupStack::PushL( tmpContainer ); |
|
303 |
|
304 SetAttributesL( *tmpContainer, aAttributes ); |
|
305 //push into the stack, ownership is transferred |
|
306 iStack->PushL( tmpContainer ); |
|
307 |
|
308 CleanupStack::Pop( tmpContainer ); |
|
309 } |
|
310 else if ( !desName.CompareF( KItem ) ) // Item element |
|
311 { |
|
312 CUpnpItem* tmpItem = CUpnpItem::NewL(); |
|
313 CleanupStack::PushL( tmpItem ); |
|
314 |
|
315 SetAttributesL( *tmpItem, aAttributes ); |
|
316 //push into the stack, ownership is transferred |
|
317 iStack->PushL( tmpItem ); |
|
318 |
|
319 CleanupStack::Pop( tmpItem ); |
|
320 } |
|
321 else if( !desName.CompareF( KTitle ) ) // Title element |
|
322 { |
|
323 // check that we have item or container. cause leave if not |
|
324 if ( iStack->Count() == 0) |
|
325 { |
|
326 User::Leave( KErrArgument ); |
|
327 } |
|
328 // We should have an item or a container already! |
|
329 //__ASSERTD( iStack->Top(), __FILE__, __LINE__ ); |
|
330 iTitle = ETrue; |
|
331 } |
|
332 else if( !desName.CompareF( KClass ) ) // Object class element |
|
333 { |
|
334 // check that we have item or container. cause leave if not |
|
335 if ( iStack->Count() == 0) |
|
336 { |
|
337 User::Leave( KErrArgument ); |
|
338 } |
|
339 // We should have an item or a container already! |
|
340 // __ASSERTD( iStack->Top(), __FILE__, __LINE__ ); |
|
341 iObjectClass = ETrue; |
|
342 } |
|
343 // Ignore DIDL-Lite, desc and X_DLNADOC -elements (DLNA req) |
|
344 else if( desName.Compare( KDIDL ) == KErrNone || |
|
345 desName.Compare( KDesc ) == KErrNone || |
|
346 desName.Compare( KDlnaDoc ) == KErrNone |
|
347 ) |
|
348 { |
|
349 // Ignore |
|
350 } |
|
351 else |
|
352 { |
|
353 // check that we have item or container. cause leave if not |
|
354 if ( iStack->Count() == 0) |
|
355 { |
|
356 User::Leave( KErrArgument ); |
|
357 } |
|
358 |
|
359 // We should have an item or a container already! |
|
360 //__ASSERTD( iStack->Top(), __FILE__, __LINE__ ); |
|
361 |
|
362 if( prefix.Length() > 0 ) // If there is a namespace (upnp: etc) |
|
363 { |
|
364 HBufC8* name = HBufC8::NewLC( prefix.Length() + |
|
365 KComma().Length() + desName.Length() ) ; |
|
366 name->Des().Copy( prefix ); |
|
367 name->Des().Append( KComma ); |
|
368 name->Des().Append( desName ); |
|
369 |
|
370 // Create a new element |
|
371 __ASSERTD( !iNewElement, __FILE__, __LINE__ ); |
|
372 iNewElement = CUpnpElement::NewL( *name ); |
|
373 |
|
374 CleanupStack::PopAndDestroy( name ); |
|
375 } |
|
376 else |
|
377 { |
|
378 // Create a new element |
|
379 __ASSERTD( !iNewElement, __FILE__, __LINE__ ); |
|
380 iNewElement = CUpnpElement::NewL( desName ); |
|
381 } |
|
382 |
|
383 // Set attributes for element |
|
384 SetAttributesL( aAttributes ); |
|
385 } |
|
386 __LOG( "CUPnPXMLParser::OnEndElementL, end" ); |
|
387 } |
|
388 |
|
389 // -------------------------------------------------------------------------- |
|
390 // CUPnPXMLParser::OnEndElementL |
|
391 // See upnpxmlparser.h |
|
392 // -------------------------------------------------------------------------- |
|
393 void CUPnPXMLParser::OnEndElementL( const RTagInfo& aElement, |
|
394 TInt aErrorCode ) |
|
395 { |
|
396 __LOG( "CUPnPXMLSAXParser::OnEndElementL(), begin" ); |
|
397 if ( aErrorCode != KErrNone ) |
|
398 { |
|
399 return; |
|
400 } |
|
401 |
|
402 const TDesC8& desName = aElement.LocalName().DesC(); |
|
403 if ( !desName.CompareF( KContainer ) || !desName.CompareF( KItem ) ) |
|
404 { |
|
405 iResultRoot->AppendL( iStack->Top() ); |
|
406 iStack->Pop(); // Remove object from stack. |
|
407 } |
|
408 else if( KErrNone != desName.CompareF( KDIDL )) |
|
409 { |
|
410 CUpnpObject* obj = (CUpnpObject*)iStack->Top(); |
|
411 __ASSERTD( obj, __FILE__, __LINE__ ); |
|
412 |
|
413 if ( iElementValue ) |
|
414 { |
|
415 SetValueToElementL( *obj, *iElementValue ); |
|
416 } |
|
417 else |
|
418 { |
|
419 SetValueToElementL( *obj, KNullDesC8 ); |
|
420 } |
|
421 |
|
422 delete iElementValue; iElementValue = NULL; |
|
423 } |
|
424 __LOG( "CUPnPXMLSAXParser::OnEndElementL(), end" ); |
|
425 } |
|
426 |
|
427 // -------------------------------------------------------------------------- |
|
428 // CUPnPXMLParser::OnContentL |
|
429 // See upnpxmlparser.h |
|
430 // -------------------------------------------------------------------------- |
|
431 void CUPnPXMLParser::OnContentL( const TDesC8& aBytes, TInt aErrorCode ) |
|
432 { |
|
433 __LOG( "CUPnPXMLSAXParser::OnContentL(), begin" ); |
|
434 if ( !iStack->Count() || aErrorCode != KErrNone ) |
|
435 { |
|
436 return; |
|
437 } |
|
438 |
|
439 if( !iElementValue ) //if 1st time |
|
440 { |
|
441 iElementValue = HBufC8::NewL(aBytes.Length()); |
|
442 iElementValue->Des().Copy(aBytes); |
|
443 } |
|
444 else |
|
445 { |
|
446 HBufC8* previousValue = iElementValue; |
|
447 iElementValue = HBufC8::NewL( previousValue->Des().Length() + |
|
448 aBytes.Length() ); |
|
449 iElementValue->Des().Append( *previousValue ); |
|
450 iElementValue->Des().Append( aBytes ); |
|
451 delete previousValue; |
|
452 } |
|
453 __LOG( "CUPnPXMLSAXParser::OnContentL(), end" ); |
|
454 } |
|
455 |
|
456 // -------------------------------------------------------------------------- |
|
457 // CUPnPXMLParser::OnStartPrefixMappingL |
|
458 // See upnpxmlparser.h |
|
459 // -------------------------------------------------------------------------- |
|
460 void CUPnPXMLParser::OnStartPrefixMappingL( const RString& /*aPrefix*/, |
|
461 const RString& /*aUri*/, |
|
462 TInt /*aErrorCode*/ ) |
|
463 { |
|
464 // No implementation needed |
|
465 } |
|
466 |
|
467 // -------------------------------------------------------------------------- |
|
468 // CUPnPXMLParser::OnEndPrefixMappingL |
|
469 // See upnpxmlparser.h |
|
470 // -------------------------------------------------------------------------- |
|
471 void CUPnPXMLParser::OnEndPrefixMappingL( const RString& /*aPrefix*/, |
|
472 TInt /*aErrorCode*/ ) |
|
473 { |
|
474 // No implementation needed |
|
475 } |
|
476 |
|
477 // -------------------------------------------------------------------------- |
|
478 // CUPnPXMLParser::OnIgnorableWhiteSpaceL |
|
479 // See upnpxmlparser.h |
|
480 // -------------------------------------------------------------------------- |
|
481 void CUPnPXMLParser::OnIgnorableWhiteSpaceL( const TDesC8& /*aBytes*/, |
|
482 TInt /*aErrorCode*/ ) |
|
483 { |
|
484 // No implementation needed |
|
485 } |
|
486 |
|
487 // -------------------------------------------------------------------------- |
|
488 // CUPnPXMLParser::OnSkippedEntityL |
|
489 // See upnpxmlparser.h |
|
490 // -------------------------------------------------------------------------- |
|
491 void CUPnPXMLParser::OnSkippedEntityL( const RString& /*aName*/, |
|
492 TInt /*aErrorCode*/ ) |
|
493 { |
|
494 // No implementation needed |
|
495 } |
|
496 |
|
497 // -------------------------------------------------------------------------- |
|
498 // CUPnPXMLParser::OnProcessingInstructionL |
|
499 // See upnpxmlparser.h |
|
500 // -------------------------------------------------------------------------- |
|
501 void CUPnPXMLParser::OnProcessingInstructionL( const TDesC8& /*aTarget*/, |
|
502 const TDesC8& /*aData*/, |
|
503 TInt /*aErrorCode*/ ) |
|
504 { |
|
505 // No implementation needed |
|
506 } |
|
507 |
|
508 // -------------------------------------------------------------------------- |
|
509 // CUPnPXMLParser::OnError |
|
510 // See upnpxmlparser.h |
|
511 // -------------------------------------------------------------------------- |
|
512 void CUPnPXMLParser::OnError( TInt /*aErrorCode*/ ) |
|
513 { |
|
514 // No implementation needed |
|
515 } |
|
516 |
|
517 // -------------------------------------------------------------------------- |
|
518 // CUPnPXMLParser::GetExtendedInterface |
|
519 // See upnpxmlparser.h |
|
520 // -------------------------------------------------------------------------- |
|
521 TAny* CUPnPXMLParser::GetExtendedInterface( const TInt32 /*aUid*/ ) |
|
522 { |
|
523 // No implementation needed |
|
524 return NULL; |
|
525 } |
|
526 |
|
527 // -------------------------------------------------------------------------- |
|
528 // CUPnPXMLParser::SetAttributesL |
|
529 // See upnpxmlparser.h |
|
530 // -------------------------------------------------------------------------- |
|
531 void CUPnPXMLParser::SetAttributesL( CUpnpObject& aObject, |
|
532 const RAttributeArray& aAttributes ) |
|
533 { |
|
534 __LOG( "CUPnPXMLParser::SetAttributesL" ); |
|
535 |
|
536 if ( iStack->Count() ) |
|
537 { |
|
538 // Object has a parent. |
|
539 // Should not really happen, but implemented anyways |
|
540 __LOG( "Object has a parent!" ); |
|
541 |
|
542 if ( iStack->Top()->ObjectType() != EUPnPContainer ) |
|
543 { |
|
544 User::Leave( KErrArgument ); |
|
545 } |
|
546 CUpnpContainer* container = (CUpnpContainer*)iStack->Top(); |
|
547 container->AppendObjectL( aObject ); |
|
548 } |
|
549 |
|
550 RAttribute attribute; |
|
551 TInt count = aAttributes.Count(); |
|
552 for ( TInt i = 0 ; i < count; i++ ) // Read attributes. |
|
553 { |
|
554 attribute = aAttributes[ i ]; |
|
555 const TDesC8& name = attribute.Attribute().LocalName().DesC(); |
|
556 |
|
557 if( !name.CompareF( KId ) ) |
|
558 { |
|
559 aObject.SetIdL( attribute.Value().DesC() ); |
|
560 } |
|
561 if( !name.CompareF( KParentId ) ) |
|
562 { |
|
563 aObject.SetParentIdL( attribute.Value().DesC() ); |
|
564 } |
|
565 if( !name.CompareF( KRestricted ) ) |
|
566 { |
|
567 if ( !attribute.Value().DesC().CompareF( KTrue ) ) // restricted |
|
568 { |
|
569 aObject.SetRestricted( ETrue ); |
|
570 } |
|
571 else // no restriction |
|
572 { |
|
573 aObject.SetRestricted( EFalse ); |
|
574 } |
|
575 } |
|
576 } |
|
577 __LOG( "CUPnPXMLParser::SetAttributesL - End" ); |
|
578 } |
|
579 |
|
580 // -------------------------------------------------------------------------- |
|
581 // CUPnPXMLParser::SetValueToElementL |
|
582 // See upnpxmlparser.h |
|
583 // -------------------------------------------------------------------------- |
|
584 void CUPnPXMLParser::SetValueToElementL( CUpnpObject& aItem, |
|
585 const TDesC8& aValue ) |
|
586 { |
|
587 __LOG( "CUPnPXMLParser::SetValueToElementL()" ); |
|
588 |
|
589 if( iTitle ) |
|
590 { |
|
591 __LOG( "SetValueToElementL() - title element" ); |
|
592 aItem.SetTitleL( aValue ); |
|
593 iTitle = EFalse; |
|
594 } |
|
595 else if( iObjectClass ) |
|
596 { |
|
597 __LOG( "SetValueToElementL() - objectclass element" ); |
|
598 aItem.SetObjectClassL( aValue ); |
|
599 iObjectClass = EFalse; |
|
600 } |
|
601 // See if it's the res-element |
|
602 else if( iNewElement && // NULL Check |
|
603 iNewElement->Name().Compare( KContentURI ) == KErrNone ) |
|
604 { |
|
605 __LOG( "SetValueToElementL() - res element" ); |
|
606 |
|
607 // Check that uri is absolute |
|
608 if( UpnpCdsResElementUtility::IsUriAbsolute( aValue ) ) |
|
609 { |
|
610 __LOG( "valid res-element" ); |
|
611 iNewElement->SetValueL( aValue ); |
|
612 aItem.AddElementL( iNewElement ); // Ownership is transferred |
|
613 iNewElement = NULL; |
|
614 } |
|
615 else |
|
616 { |
|
617 // if CreateObjectResponse, there is importuri |
|
618 // no need to check res-element |
|
619 TInt found = EFalse; |
|
620 RUPnPAttributesArray elArray = iNewElement->GetAttributes(); |
|
621 TInt count = elArray.Count(); |
|
622 for( TInt i = 0; i < count; i++ ) |
|
623 { |
|
624 if( elArray[ i ]->Name() == KImportUri ) |
|
625 { |
|
626 i = count; |
|
627 found = ETrue; |
|
628 __LOG( "SetValueToElementL() - ImportUri found" ); |
|
629 } |
|
630 } |
|
631 |
|
632 if( found ) |
|
633 { |
|
634 __LOG( "no res-element but import uri found" ); |
|
635 iNewElement->SetValueL( KNullDesC8 ); |
|
636 aItem.AddElementL( iNewElement ); // Ownership is transferred |
|
637 iNewElement = NULL; |
|
638 } |
|
639 else |
|
640 { |
|
641 __LOG( "invalid res-element" ); |
|
642 delete iNewElement; |
|
643 iNewElement = NULL; |
|
644 } |
|
645 } |
|
646 |
|
647 } |
|
648 else |
|
649 { |
|
650 __LOG( "SetValueToElementL() - unknown element" ); |
|
651 if( iNewElement ) |
|
652 { |
|
653 // Check for empty values |
|
654 if( aValue == KNullDesC8 || aValue == KSpace ) |
|
655 { |
|
656 // Do not add empty values |
|
657 delete iNewElement; iNewElement = NULL; |
|
658 } |
|
659 else |
|
660 { |
|
661 iNewElement->SetValueL( aValue ); |
|
662 aItem.AddElementL( iNewElement ); // Ownership is transferred |
|
663 iNewElement = NULL; |
|
664 } |
|
665 } |
|
666 } |
|
667 |
|
668 __LOG( "CUPnPXMLParser::SetValueToElementL() End" ); |
|
669 } |
|
670 |
|
671 |
|
672 // -------------------------------------------------------------------------- |
|
673 // CUPnPXMLParser::SetAttributesL |
|
674 // See upnpxmlparser.h |
|
675 // -------------------------------------------------------------------------- |
|
676 void CUPnPXMLParser::SetAttributesL( const RAttributeArray& aAttributes ) |
|
677 { |
|
678 __LOG( "CUPnPXMLParser::SetAttributesL" ); |
|
679 |
|
680 RAttribute attribute; |
|
681 TInt count = aAttributes.Count(); |
|
682 for ( TInt i = 0; i < count ; i++ ) |
|
683 { |
|
684 attribute = aAttributes[i]; |
|
685 const TDesC8& name = attribute.Attribute().LocalName().DesC(); |
|
686 CUpnpAttribute* att = CUpnpAttribute::NewLC(); |
|
687 att->SetNameL( name ); |
|
688 att->SetValueL( attribute.Value().DesC() ); |
|
689 __ASSERTD( iNewElement, __FILE__, __LINE__ ); |
|
690 iNewElement->AddAttributeL( att ); |
|
691 CleanupStack::Pop( att ); |
|
692 } |
|
693 __LOG( "CUPnPXMLParser::SetAttributesL End" ); |
|
694 } |
|
695 |
|
696 // end of file |
|
697 |