upnpavcontrolpoint/avcpengine/src/upnppathresolver.cpp
changeset 0 7f85d04be362
child 25 52826dcbed74
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  CUpnpPathResolver
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "upnppathresolver.h"
       
    22 #include    "upnppathelement.h"
       
    23 #include    "upnpresolvehandler.h"
       
    24 #include    "upnpavcpmanager.h"
       
    25 
       
    26 #include "upnpavcpenginecommon.h"
       
    27 #include "upnpavcpenginehelper.h"
       
    28 using namespace UpnpAVCPEngine;
       
    29 
       
    30 #include "upnpstring.h"
       
    31 
       
    32 #include <xmlengdom.h>
       
    33 #include <xmlengdomparser.h>
       
    34 
       
    35 #include "upnpdominterface.h"
       
    36 
       
    37 _LIT8(KIndexFormat, "(%d)");
       
    38 
       
    39 const static TInt KMaxElementsLimit = 1000;
       
    40         			    	    
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CUpnpPathResolver::CUpnpPathResolver
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CUpnpPathResolver::CUpnpPathResolver(CUpnpAVCPManager& aManager):
       
    51     iManager(aManager), iUptodate(ETrue)
       
    52     {
       
    53     iSystemId = -1;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CUpnpPathResolver::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CUpnpPathResolver::ConstructL(const TDesC8& aUUID)
       
    62     {
       
    63     iUUID = aUUID.AllocL();
       
    64     iDOMImpl.OpenL();
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CUpnpPathResolver::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CUpnpPathResolver* CUpnpPathResolver::NewL(CUpnpAVCPManager& aManager, const TDesC8& aUUID)
       
    73     {
       
    74     CUpnpPathResolver* self = new( ELeave ) CUpnpPathResolver(aManager);
       
    75     
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL(aUUID);
       
    78     CleanupStack::Pop( self );
       
    79 
       
    80     return self;
       
    81     }
       
    82 
       
    83  
       
    84 // -----------------------------------------------------------------------------
       
    85 // CUpnpPathResolver::~CUpnpPathResolver
       
    86 // Destructor
       
    87 // -----------------------------------------------------------------------------
       
    88 //   
       
    89 CUpnpPathResolver::~CUpnpPathResolver()
       
    90     {
       
    91 	delete iUUID;
       
    92 	iAVCPSessions.Reset();
       
    93 	iPathElements.ResetAndDestroy(); 
       
    94 	iResolveHandlers.ResetAndDestroy(); 
       
    95 	iDOMImpl.Close();
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CUpnpPathResolver::UUID
       
   100 // -----------------------------------------------------------------------------
       
   101 //   
       
   102 const TDesC8& CUpnpPathResolver::UUID() const
       
   103     {
       
   104 	return *iUUID;                
       
   105     }
       
   106     
       
   107 // -----------------------------------------------------------------------------
       
   108 // CUpnpPathResolver::Match
       
   109 // -----------------------------------------------------------------------------
       
   110 //   
       
   111 TBool CUpnpPathResolver::Match(const CUpnpPathResolver& aElement1, const CUpnpPathResolver& aElement2) 
       
   112 	{
       
   113 	return   (aElement1.UUID().Compare(aElement2.UUID()) == 0); 
       
   114 	}    
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CUpnpPathResolver::RegisterSession
       
   118 // -----------------------------------------------------------------------------
       
   119 //   
       
   120 void CUpnpPathResolver::RegisterSession(CUpnpAVCPEngineSession* aSession) 
       
   121 	{    
       
   122 	TInt index = iAVCPSessions.Find(aSession); 
       
   123     if (index == KErrNotFound) 
       
   124 	    {
       
   125 	    iAVCPSessions.Append(aSession); 
       
   126 	    }
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CUpnpPathResolver::UnregisterSession
       
   131 // -----------------------------------------------------------------------------
       
   132 //   
       
   133 TInt CUpnpPathResolver::UnregisterSession(CUpnpAVCPEngineSession* aSession) 
       
   134 	{
       
   135   	TInt index = iAVCPSessions.Find(aSession); 
       
   136     if (index != KErrNotFound) 
       
   137 	    {
       
   138 	    iAVCPSessions.Remove(index); 
       
   139 	    }  
       
   140     return iAVCPSessions.Count();
       
   141 	}
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CUpnpPathResolver::AddElementL
       
   145 // -----------------------------------------------------------------------------
       
   146 //   
       
   147 const TDesC8& CUpnpPathResolver::AddElementL(const TDesC8& aParentId, const TDesC8& aId, const TDesC8& aName, const TDesC8& aImportURI) 
       
   148 	{
       
   149 	// if we exceed max capacity for our cache, set to destroy all elements
       
   150 	if (iPathElements.Count() > KMaxElementsLimit)
       
   151 		iUptodate = EFalse;		
       
   152 		
       
   153 	
       
   154     CUpnpPathElement* elem = CUpnpPathElement::NewL();
       
   155     CleanupStack::PushL(elem);
       
   156     elem->SetParentIdL(aParentId);
       
   157     elem->SetIdL(aId);
       
   158     elem->SetNameL(aName);
       
   159     
       
   160     TIdentityRelation<CUpnpPathElement> matcher( CUpnpPathElement::MatchAll );
       
   161     // check if exist the same element
       
   162 	TInt idx = iPathElements.Find( elem, matcher ); 
       
   163 	
       
   164 	if (idx != KErrNotFound)   
       
   165 		{
       
   166 		if(aImportURI != KNullDesC8())
       
   167 			{
       
   168 			iPathElements[idx]->SetImportURIL(aImportURI);
       
   169 			}
       
   170 	    CleanupStack::PopAndDestroy(elem);
       
   171 	    return iPathElements[idx]->Name();
       
   172 		}
       
   173 	else 
       
   174 		{
       
   175 		// check name duplication
       
   176 		TIdentityRelation<CUpnpPathElement> matcherName( CUpnpPathElement::MatchName );
       
   177 	    TInt index = 0;
       
   178 	    TInt dupIndex = iPathElements.Find( elem, matcherName ); 
       
   179 	    
       
   180 	    while (dupIndex != KErrNotFound)
       
   181 	    	{
       
   182 	    	HBufC8* newName = HBufC8::NewLC(aName.Length() + 10 /*integer*/);
       
   183 	    	*newName = aName;
       
   184            	newName->Des().AppendFormat(KIndexFormat, ++index ); 	
       
   185            	// change to new name
       
   186            	elem->SetNameL(*newName); 
       
   187            	CleanupStack::PopAndDestroy( newName );
       
   188            	dupIndex = iPathElements.Find( elem, matcherName );
       
   189            	// check if exists the same element
       
   190            	idx = iPathElements.Find( elem, matcher ); 
       
   191            	if (idx != KErrNotFound)   
       
   192 				{
       
   193 				if(aImportURI != KNullDesC8())
       
   194 					{
       
   195 					iPathElements[idx]->SetImportURIL(aImportURI);
       
   196 					}
       
   197 	    		CleanupStack::PopAndDestroy(elem);
       
   198 	    		return iPathElements[idx]->Name();
       
   199 				}
       
   200 	    	} 
       
   201 	    if(aImportURI != KNullDesC8())
       
   202 			{
       
   203 			elem->SetImportURIL(aImportURI);
       
   204 			}
       
   205 	    CleanupStack::Pop(elem);
       
   206         iPathElements.Append(elem);
       
   207         return elem->Name();
       
   208 		}
       
   209 	  
       
   210 	}
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CUpnpPathResolver::GetElementId
       
   214 // -----------------------------------------------------------------------------
       
   215 //   
       
   216 CUpnpPathElement*  CUpnpPathResolver::GetElementL(const TDesC8& aParentId, const TDesC8& aName) const 
       
   217 	{
       
   218     CUpnpPathElement* elem = CUpnpPathElement::NewL();
       
   219     CleanupStack::PushL(elem);
       
   220     elem->SetNameL(aName);
       
   221     elem->SetParentIdL(aParentId);
       
   222     TIdentityRelation<CUpnpPathElement> matcher( CUpnpPathElement::MatchName );
       
   223 	TInt idx = iPathElements.Find( elem, matcher ); 
       
   224 	CleanupStack::PopAndDestroy(elem);	
       
   225 	if (idx != KErrNotFound)   
       
   226 		{
       
   227 	   	return  iPathElements[idx];   
       
   228 		}
       
   229 	else 
       
   230 		{
       
   231 	    return NULL;
       
   232 		}  
       
   233 	}
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CUpnpPathResolver::RemoveElement
       
   237 // -----------------------------------------------------------------------------
       
   238 //   
       
   239 void CUpnpPathResolver::RemoveElementD(CUpnpPathElement* aElement)  
       
   240 	{
       
   241 	TInt index = iPathElements.Find(aElement);
       
   242 	if (index != KErrNotFound)   
       
   243 		{
       
   244 		iPathElements.Remove(index);
       
   245 		delete aElement;
       
   246 		} 
       
   247 	}
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CUpnpPathResolver::ResolveIdL
       
   251 // -----------------------------------------------------------------------------
       
   252 //   
       
   253 void CUpnpPathResolver::ResolveIdL(const TDesC8& aPath, MUpnpResolverObserver& aObserver) 
       
   254 	{
       
   255 	CUpnpResolveHandler* handler = CUpnpResolveHandler::NewL(iManager,*this, aObserver);	
       
   256 	CleanupStack::PushL(handler);
       
   257 	iResolveHandlers.Append(handler);
       
   258 	handler->ResolveL(aPath);	
       
   259 	CleanupStack::Pop(handler);	
       
   260 	}
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CUpnpPathResolver::RemoveHandler
       
   264 // -----------------------------------------------------------------------------
       
   265 //   
       
   266 void CUpnpPathResolver::RemoveHandler(CUpnpResolveHandler* aHandler) 
       
   267 	{
       
   268 	TInt index = iResolveHandlers.Find(aHandler); 
       
   269     if (index != KErrNotFound) 
       
   270     	{
       
   271         iResolveHandlers.Remove(index); 
       
   272     	}
       
   273 	}
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CUpnpPathResolver::LockReset
       
   277 // -----------------------------------------------------------------------------
       
   278 //  
       
   279 void CUpnpPathResolver::LockReset() 
       
   280 	{
       
   281 	DEBUGSTRING8(("-> Obtain lock for resets")); 
       
   282 	iLocked = ETrue;	
       
   283 	}
       
   284 
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CUpnpPathResolver::UnlockReset
       
   288 // -----------------------------------------------------------------------------
       
   289 //  
       
   290 void CUpnpPathResolver::UnlockReset() 	
       
   291 	{
       
   292 	DEBUGSTRING8(("<- Release lock for resets")); 
       
   293 	iLocked = EFalse;
       
   294 	if (!iUptodate) 
       
   295 		{
       
   296  		DEBUGSTRING8(("Remove all path elements"));        	
       
   297        	iPathElements.ResetAndDestroy();  				
       
   298        	iUptodate = ETrue;
       
   299 		}	
       
   300 	}
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CUpnpPathResolver::StateChangedL
       
   304 // -----------------------------------------------------------------------------
       
   305 //   
       
   306 void CUpnpPathResolver::StateChangedL(const TDesC8& aSystemId) 
       
   307 	{
       
   308 	
       
   309     TLex8 updateidLex( aSystemId );
       
   310     TInt systemUpdate;
       
   311     TInt err = updateidLex.Val( systemUpdate );
       
   312     if (err == KErrNone) 
       
   313     	{
       
   314     	DEBUGSTRING8(("StateChangedL (old: %d)->(new: %d) ", iSystemId,systemUpdate));  
       
   315         if (iSystemId != -1 && iSystemId != systemUpdate) 
       
   316         	{
       
   317         	if (!iLocked) 
       
   318         		{
       
   319 	     		DEBUGSTRING8(("Remove all path elements"));        	
       
   320     	       	iPathElements.ResetAndDestroy();        		
       
   321         		}
       
   322         	else 
       
   323         		{        		
       
   324         		iUptodate = EFalse;
       
   325         		}
       
   326         	}
       
   327         iSystemId =  systemUpdate;
       
   328     	}            
       
   329 	}
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CUpnpPathResolver::SetModifiedTimeL
       
   333 // -----------------------------------------------------------------------------
       
   334 //   
       
   335 void CUpnpPathResolver::SetModifiedTimeL(TXmlEngElement& aDateElement, TFileInfo& aEntry) 
       
   336 	{	
       
   337 	if (aDateElement.Value().Length())
       
   338 		{
       
   339 		HBufC8* date = aDateElement.Value().AllocLC(); 
       
   340 				
       
   341 		TPtrC8 datePtr =  date->Des();
       
   342 		
       
   343 		TInt position = datePtr.Locate('-');
       
   344 		TInt step = 0;
       
   345 		TInt dateParts[3];
       
   346 		while (position != KErrNotFound && step <3) 
       
   347 			{
       
   348 			TLex8 lex(datePtr.Left(position));
       
   349 			TInt value(0) ;
       
   350 			lex.Val(value);
       
   351 			
       
   352 			dateParts[step] = value;
       
   353 			step++;					
       
   354 		
       
   355 			
       
   356 			datePtr.Set(datePtr.Mid(position+1));							   	
       
   357 		   	position = datePtr.Locate('-');
       
   358 			}
       
   359 		
       
   360 		TLex8 lex(datePtr);
       
   361 		TInt value(0) ;
       
   362 		lex.Val(value);
       
   363 		
       
   364 		dateParts[step] = value;
       
   365 		
       
   366 		// implement data validation	
       
   367 	    aEntry.iModified = TDateTime(dateParts[0], TMonth(dateParts[1] -1), dateParts[2] -1, 0, 0, 0, 0); 
       
   368 	   	CleanupStack::PopAndDestroy(date);
       
   369 		}
       
   370 	}
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CUpnpPathResolver::ParseBrowseResponse
       
   374 // -----------------------------------------------------------------------------
       
   375 //   
       
   376 void CUpnpPathResolver::ParseBrowseResponseL(const TDesC8& aResponse, RArray<TFileInfo>* aDirList, const TDesC8& aObjectId, HBufC8** aResUri) 
       
   377 	{           
       
   378 	
       
   379 	RXmlEngDocument doc = ParseXmlL(aResponse);	
       
   380         	
       
   381 	// Does return resorce URI?
       
   382 	TBool isReturnUri = aObjectId.Compare(KNullDesC8) != 0;
       
   383 	//Start browsing document tree
       
   384 	TXmlEngElement root = doc.DocumentElement();
       
   385 	CleanupClosePushL( doc );
       
   386 		
       
   387 	if(root.NotNull())
       
   388 		{		
       
   389 		
       
   390 	    RArray<TXmlEngElement> elements;
       
   391 		CleanupClosePushL( elements );
       
   392 		// get list of containers	    
       
   393         UpnpDomInterface::GetElementListL(root, elements, KContainer, EFalse);  
       
   394         // get list of items
       
   395         UpnpDomInterface::GetElementListL(root, elements, KItem, EFalse);
       
   396                     
       
   397         for (TInt i = 0; i < elements.Count(); i++) 
       
   398         	{
       
   399             TXmlEngElement objElem = elements[i];   
       
   400             TXmlEngElement titleElem;
       
   401             // check title
       
   402             if ( UpnpDomInterface::GetElementL(objElem, titleElem, KTitle ) &&
       
   403             	titleElem.Value().Length()) 
       
   404             	{
       
   405             	// check if it's item or container
       
   406                 TBool isItem = UpnpDomInterface::CheckTagL(objElem, KItem);
       
   407                 
       
   408                 TPtrC8 id = UpnpDomInterface::GetAttrValueL( objElem, KId);
       
   409                 TPtrC8 parentId = UpnpDomInterface::GetAttrValueL( objElem, KParentId);
       
   410                 TPtrC8 title = titleElem.Value();                    			    			    
       
   411 			    
       
   412 				// try to add new path element, if name is taken, new name will be given
       
   413 				const TDesC8& newTitle = AddElementL(parentId, id, title);                       
       
   414 				// check if return dir list
       
   415                 if (aDirList) 
       
   416                 	{                        
       
   417                     TFileInfo entry;   
       
   418                     // set name                                                                             
       
   419 			        entry.iName = newTitle;			        
       
   420 			        
       
   421 					// set date			        		        
       
   422 			        TXmlEngElement dateElem;
       
   423 			        if (UpnpDomInterface::GetElementL(objElem, dateElem, KDate ) )
       
   424 			        	{
       
   425 			        	SetModifiedTimeL(dateElem, entry);    			        
       
   426 			        	}
       
   427 			  
       
   428 			        if (isItem) // for items
       
   429 			        	{
       
   430 			            entry.iAtt |= KEntryAttNormal;  
       
   431 			            // get size from res if exist 
       
   432 			            RArray<TXmlEngElement> resElements;
       
   433 						CleanupClosePushL( resElements );			            
       
   434 			            if (UpnpDomInterface::GetElementListL(objElem, resElements, KRes, EFalse)) 
       
   435 			            	{
       
   436 			            	// get prefer resource
       
   437     	    				TXmlEngElement res = GetPreferResourceL(resElements);			            	
       
   438 			            	// maybe res URI should be returned
       
   439 			                if (isReturnUri && UpnpDomInterface::CheckAttributeValueL(objElem, KId, aObjectId)) 
       
   440 			                	{
       
   441 			                	if (res.NotNull() && res.Value().Length()) 
       
   442 			                		{
       
   443 			                		*aResUri = res.Value().AllocL();
       
   444 			                		}			                    
       
   445 			                	}			             
       
   446     			            // set size base on res@size
       
   447     			    	    TPtrC8 size = UpnpDomInterface::GetAttrValueL( res, KSize);	        			    	        			    	
       
   448     			    	    TLex8 intLex( size );                			    	
       
   449     			    	    intLex.Val( entry.iSize );
       
   450     			    	    
       
   451     			    	    //TPtrC8 importUri = UpnpDomInterface::GetAttrValueL( res, KImportUri);	
       
   452     			    	    TPtrC8 restricted = UpnpDomInterface::GetAttrValueL( objElem, KRestricted);	
       
   453 							// check if read-only flag should be set
       
   454     			    	    if (restricted.Compare(KOne) == 0 || restricted.CompareF(KTrue) == 0)
       
   455     			    	    	{
       
   456     			    	    	entry.iAtt |= KEntryAttReadOnly;
       
   457     			    	    	}
       
   458     			    	    
       
   459 			            	}
       
   460 						CleanupStack::PopAndDestroy(&resElements);	    			    	    			            	
       
   461 			        	}
       
   462 			        else // for containers
       
   463 			        	{
       
   464 			            entry.iAtt |= KEntryAttDir;  
       
   465 			        	}
       
   466 			            			    				   				   			        			    				    
       
   467 			        // add to dir result
       
   468 			        aDirList->Append(entry);
       
   469                 	}                    
       
   470             	}
       
   471         	}            
       
   472 		CleanupStack::PopAndDestroy(&elements);	        
       
   473 		}			
       
   474 	
       
   475 	//Cleanup
       
   476 	CleanupStack::PopAndDestroy(&doc);
       
   477 	}
       
   478 
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CUpnpPathResolver::GetResUri
       
   482 // -----------------------------------------------------------------------------
       
   483 //   
       
   484 TBool CUpnpPathResolver::GetResUriL(const TDesC8& aResponse, const TDesC8& aId, HBufC8*& aResUri) 
       
   485 	{
       
   486     TInt found(EFalse);
       
   487     delete aResUri;
       
   488     aResUri = NULL;
       
   489         
       
   490 	RXmlEngDocument doc = ParseXmlL(aResponse);				
       
   491 	CleanupClosePushL( doc );
       
   492 				
       
   493 	//Start browsing document tree
       
   494 	TXmlEngElement root = doc.DocumentElement();
       
   495 	
       
   496 	if(root.NotNull())
       
   497 		{		    	
       
   498         TXmlEngElement item;
       
   499         if ( UpnpDomInterface::GetDirectoryElementL(root, item, KItem, KId, aId) )
       
   500         	{
       
   501     	    RArray<TXmlEngElement> resElements;
       
   502     	    CleanupClosePushL(resElements);
       
   503     	    if (UpnpDomInterface::GetElementListL(item, resElements, KRes, EFalse) ) 
       
   504     	    	{
       
   505     	    	TXmlEngElement res = GetPreferResourceL(resElements);
       
   506                 
       
   507                 if (res.Value().Length()) 
       
   508                 	{
       
   509 	                found = ETrue;	               
       
   510     	            aResUri = res.Value().AllocL();                	
       
   511                 	}                
       
   512     	    	}		
       
   513     	    CleanupStack::PopAndDestroy(&resElements);		  				    
       
   514         	}	              
       
   515 		}				
       
   516 
       
   517 	CleanupStack::PopAndDestroy(&doc);
       
   518 
       
   519 	return found;	
       
   520 	}
       
   521 // -----------------------------------------------------------------------------
       
   522 // CUpnpPathResolver::BrowseCreateObjectL
       
   523 // -----------------------------------------------------------------------------
       
   524 //   
       
   525 TBool CUpnpPathResolver::BrowseCreateObjectL(const TDesC8& aResponse) 
       
   526 	{
       
   527     TInt found(EFalse);   
       
   528 	RXmlEngDocument doc = ParseXmlL(aResponse);			
       
   529 	CleanupClosePushL( doc );
       
   530 	//Start browsing document tree
       
   531 	TXmlEngElement root = doc.DocumentElement();
       
   532 	
       
   533 	if(root.NotNull())
       
   534 		{		
       
   535         TXmlEngElement item;
       
   536         if ( UpnpDomInterface::GetElementL(root, item, KItem) )
       
   537             {    	    
       
   538     	    
       
   539     	    TPtrC8 id = UpnpDomInterface::GetAttrValueL( item, KId);
       
   540             TPtrC8 parentid = UpnpDomInterface::GetAttrValueL( item, KParentId);    
       
   541                     
       
   542     	    if (id.Length() && parentid.Length()) 
       
   543         	    {        	    	        	    	
       
   544                     RArray<TXmlEngElement> resElements;
       
   545     	    		CleanupClosePushL(resElements);
       
   546                     
       
   547                     if(UpnpDomInterface::GetElementListL(item, resElements, KRes, EFalse)) 
       
   548                     	{
       
   549                     	TPtrC8 import;
       
   550                     	TXmlEngElement resElement = GetResourceWithImportURIL(resElements, import);
       
   551 		                
       
   552 		                
       
   553 		                if(import.Length())
       
   554 		                	{
       
   555 		             
       
   556 		    				TXmlEngElement titleElem;
       
   557 		    				
       
   558 		    				if(UpnpDomInterface::GetElementL(item, titleElem, KTitle))
       
   559 		    					{
       
   560 		    					if ( titleElem.Value().Length()) 
       
   561 		                        	{
       
   562 		                        	found = ETrue;   
       
   563 		                        	TPtrC8 title = titleElem.Value();                         	                       	
       
   564 		                        	AddElementL(parentid, id, title, import);                    	
       
   565 		                        	}
       
   566 		    					} 
       
   567 		                	}		                
       
   568 							
       
   569 						CleanupStack::PopAndDestroy(&resElements);	                   	                                          
       
   570 
       
   571                     	}
       
   572         	    }				  				        	    
       
   573             }                         			    	      
       
   574 		}			
       
   575 	
       
   576 
       
   577 	//Cleanup
       
   578 	CleanupStack::PopAndDestroy(&doc);
       
   579 	
       
   580     return found;	
       
   581 	}
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CUpnpPathResolver::GetItemL
       
   585 // -----------------------------------------------------------------------------
       
   586 //   
       
   587 TBool CUpnpPathResolver::GetItemL(const TDesC8& aResponse, const TDesC8& aId) 
       
   588 	{
       
   589     TInt found(EFalse);    
       
   590 
       
   591 	RXmlEngDocument doc = ParseXmlL(aResponse);			
       
   592 	CleanupClosePushL( doc );
       
   593 	//Start browsing document tree
       
   594 	TXmlEngElement root = doc.DocumentElement();
       
   595 	
       
   596 	if(root.NotNull())
       
   597 		{		
       
   598         TXmlEngElement item;
       
   599         if ( UpnpDomInterface::GetDirectoryElementL(root, item, KItem, KId, aId) )
       
   600             {
       
   601     	    RArray<TXmlEngElement> resElements;
       
   602     	    CleanupClosePushL(resElements);
       
   603     	    if (UpnpDomInterface::GetElementListL(item, resElements, KRes, EFalse) ) 
       
   604         	    {        	    	
       
   605                 found = ETrue;                       
       
   606         	    }				  				    
       
   607     	    CleanupStack::PopAndDestroy(&resElements);	
       
   608             }                         			    	      
       
   609 		}				
       
   610 
       
   611 	//Cleanup
       
   612 	CleanupStack::PopAndDestroy(&doc);
       
   613 	
       
   614     return found;	
       
   615 	}
       
   616 	
       
   617 // -----------------------------------------------------------------------------
       
   618 // CUpnpPathResolver::ParseXmlL
       
   619 // -----------------------------------------------------------------------------
       
   620 //   
       
   621 RXmlEngDocument CUpnpPathResolver::ParseXmlL(const TDesC8& aXml) 	
       
   622 	{
       
   623 		
       
   624 	//Create a parser
       
   625 	RXmlEngDOMParser parser;
       
   626 	User::LeaveIfError( parser.Open(iDOMImpl) );
       
   627 	CleanupClosePushL(parser);
       
   628 		
       
   629 	//Handler to the parsed document
       
   630 	RXmlEngDocument doc;				
       
   631 		
       
   632 	doc = parser.ParseL(aXml);	
       
   633 	CleanupClosePushL( doc );	
       
   634         	
       
   635 	if(doc.IsNull()) 
       
   636 		{
       
   637 		User::Leave(KErrUnknown);
       
   638 		}
       
   639 		
       
   640 	CleanupStack::Pop(&doc);
       
   641 	CleanupStack::PopAndDestroy(&parser);			
       
   642 	return doc;		
       
   643 	}
       
   644 	
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // CUpnpPathResolver::GetPreferResource
       
   648 // -----------------------------------------------------------------------------
       
   649 //   
       
   650 TXmlEngElement CUpnpPathResolver::GetPreferResourceL(const RArray<TXmlEngElement>& aElements) 	
       
   651 	{
       
   652 	//DEBUGSTRING8(("GetPreferResource "));   
       
   653 	if (aElements.Count() > 0)	
       
   654 		{
       
   655 		for (TInt i = 0; i < aElements.Count(); i++) 
       
   656 			{
       
   657 			TXmlEngElement elem = aElements[i];
       
   658 			TPtrC8 protocol = UpnpDomInterface::GetAttrValueL(elem, KProtocolInfo);
       
   659 			if (protocol.Left(KProtocolInfoBegin().Length()).Compare(KProtocolInfoBegin) == 0) 
       
   660 				{				
       
   661 				return elem;
       
   662 				}
       
   663 			}
       
   664 		DEBUGSTRING8(("GetPreferResource:   Return empty element (no http-get elements) "));   			
       
   665 		}
       
   666 	else 
       
   667 		{
       
   668 		DEBUGSTRING8(("GetPreferResource:   Return empty element (size of list = 0) "));   		
       
   669 		}
       
   670 	return TXmlEngElement();		
       
   671 	}
       
   672 // -----------------------------------------------------------------------------
       
   673 // CUpnpPathResolver::GetResourceWithImportURIL
       
   674 // -----------------------------------------------------------------------------
       
   675 //   
       
   676 TXmlEngElement CUpnpPathResolver::GetResourceWithImportURIL(const RArray<TXmlEngElement>& aElements, TPtrC8& aImportURI) 	
       
   677 	{	
       
   678 	aImportURI.Set(KNullDesC8);
       
   679 	
       
   680 	if (aElements.Count() > 0)	
       
   681 		{
       
   682 		for (TInt i = 0; i < aElements.Count(); i++) 
       
   683 			{
       
   684 			TXmlEngElement elem = aElements[i];
       
   685 			
       
   686 			aImportURI.Set(UpnpDomInterface::GetAttrValueL(elem, KImportUri));
       
   687 			if (aImportURI != KNullDesC8) 
       
   688 				{				
       
   689 				return elem;
       
   690 				}
       
   691 			}
       
   692 		}
       
   693 	return TXmlEngElement();		
       
   694 	}	
       
   695 //  End of File