xdmprotocols/XcapProtocol/XcapCache/Server/src/XcapCacheSession.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     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:   CXcapCacheSession
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32std.h>
       
    23 #include <f32file.h>
       
    24 #include <badesca.h>
       
    25 #include "XcapCacheIndex.h"
       
    26 #include "XcapCacheSession.h"
       
    27 #include "XcapCacheIndexAdmin.h"
       
    28 #include "XcapCacheIndexEntry.h"
       
    29 #include "XcapCacheIndexTableEntry.h"
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 //
       
    33 
       
    34 // ----------------------------------------------------------
       
    35 // CXcapCacheSession::NewL
       
    36 // 
       
    37 // ----------------------------------------------------------
       
    38 //
       
    39 CXcapCacheSession* CXcapCacheSession::NewL( CXcapCacheServer* aServer )
       
    40     {
       
    41     CXcapCacheSession* self = new( ELeave ) CXcapCacheSession( aServer );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop();
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ----------------------------------------------------------
       
    49 // CXcapCacheSession::~CXcapCacheSession
       
    50 // 
       
    51 // ----------------------------------------------------------
       
    52 //
       
    53 CXcapCacheSession::~CXcapCacheSession()
       
    54     {
       
    55     delete iFileManager;
       
    56     //Reduce number of active clients within server
       
    57     if( iCacheServer )
       
    58         iCacheServer->DropSession();
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------
       
    62 // CXcapCacheSession::ServiceL
       
    63 // 
       
    64 // ----------------------------------------------------------
       
    65 //
       
    66 void CXcapCacheSession::ServiceL( const RMessage2& aMessage )
       
    67     {
       
    68     TInt ret = KErrNone;
       
    69     if( Capabilities( aMessage ) )
       
    70         {
       
    71         CheckTempBuffer();
       
    72         TRAPD( err, DispatchMessageL( aMessage ) );
       
    73         if( err != KErrNone )
       
    74             ret = err;
       
    75         }
       
    76     else ret = KErrPermissionDenied;
       
    77     aMessage.Complete( ret );
       
    78     #ifdef _DEBUG
       
    79         CXcapCacheServer::WriteToLog( _L8( "** Message completed - Error: %d" ), ret );
       
    80     #endif
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------
       
    84 // CXcapCacheSession::Capabilities
       
    85 // 
       
    86 // ----------------------------------------------------------
       
    87 //
       
    88 TBool CXcapCacheSession::Capabilities( const RMessage2& aMessage )
       
    89     {
       
    90     return aMessage.HasCapability( ECapabilityReadUserData ) &&
       
    91            aMessage.HasCapability( ECapabilityWriteUserData );
       
    92     }
       
    93     
       
    94 // ----------------------------------------------------------
       
    95 // CXcapCacheSession::CheckTempBuffer
       
    96 // 
       
    97 // ----------------------------------------------------------
       
    98 //
       
    99 void CXcapCacheSession::CheckTempBuffer()
       
   100     {
       
   101     if( iTempBuffer )
       
   102         {
       
   103         delete iTempBuffer;
       
   104         iTempBuffer = NULL;
       
   105         }
       
   106     }
       
   107     
       
   108 // ----------------------------------------------------------
       
   109 // CXcapCacheSession::CXcapCacheSession
       
   110 // 
       
   111 // ----------------------------------------------------------
       
   112 //
       
   113 CXcapCacheSession::CXcapCacheSession( CXcapCacheServer* aServer ) :
       
   114                                       iCacheServer( aServer ),
       
   115                                       iCacheIndex( *CXcapCacheServer::Index() ),
       
   116                                       iCacheIndexAdmin( *CXcapCacheServer::IndexAdmin() )
       
   117     {
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------
       
   121 // CXcapCacheSession::ConstructL
       
   122 // 
       
   123 // ----------------------------------------------------------
       
   124 //
       
   125 void CXcapCacheSession::ConstructL()
       
   126     {
       
   127     iCacheServer->AddSession();
       
   128     iFileManager = CFileMan::NewL( iCacheServer->FileSession() );
       
   129     #ifdef _DEBUG
       
   130         TInt count = 0;
       
   131         iCacheServer->CacheSize( count );
       
   132     #endif
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------
       
   136 // CXcapCacheSession::PanicClient
       
   137 // 
       
   138 // ----------------------------------------------------------
       
   139 //
       
   140 void CXcapCacheSession::PanicClient( TInt aPanic )
       
   141     {
       
   142     _LIT( KTxtSessionPanic,"Test Server Session panic");
       
   143     User::Panic( KTxtSessionPanic, aPanic );
       
   144     }
       
   145 
       
   146 // ----------------------------------------------------------
       
   147 // CXcapCacheSession::DispatchMessageL
       
   148 // 
       
   149 // ----------------------------------------------------------
       
   150 //
       
   151 void CXcapCacheSession::DispatchMessageL( const RMessage2& aMessage )
       
   152     {
       
   153     switch( aMessage.Function() )
       
   154         {
       
   155         case EXcapCacheFetchInfo:
       
   156             FetchDocumentInfoL( aMessage );
       
   157             break;
       
   158         case EXcapCacheFetchData:
       
   159             FetchDocumentContentsL( aMessage );
       
   160             break;
       
   161         case EXcapCacheStore:
       
   162             {
       
   163             TInt entryCount = 0;
       
   164             CacheXcapDataL( aMessage );
       
   165             TInt size = iCacheServer->CacheSize( entryCount );
       
   166             CheckUnindexedEntriesL( entryCount );
       
   167             //Recheck the size
       
   168             size = iCacheServer->CacheSize( entryCount );
       
   169             const TInt maxSize = iCacheServer->MaxCacheSize();
       
   170             //If there's only one document filling the
       
   171             //whole data area, there's not much to be done
       
   172             //NOTE: Index & pagefile are always there => 3
       
   173             if( size >= maxSize && entryCount > 3 )
       
   174                 {
       
   175                 #ifdef _DEBUG
       
   176                     CXcapCacheServer::WriteToLog( _L8( " Cache too large: %d bytes" ), size );
       
   177                 #endif
       
   178                 iCacheIndex.SortEntriesL();
       
   179                 const TInt compression( iCacheServer->MaxCacheSize() * KDefaultCompression );
       
   180                 //NOTE: Index & pagefile are always there -> 3
       
   181                 TBool ready = EFalse;
       
   182                 while( entryCount > 3 && size > compression && !ready )
       
   183                     {
       
   184                     //The entries have been sorted => FIFO
       
   185                     CXcapCacheIndexEntry* entry = iCacheIndex.Entry( 0 );
       
   186                     if( entry )
       
   187                     	{
       
   188                         DeleteFromStorageL( entry->FileName16L() );
       
   189                         iCacheIndex.RemoveEntry( 0 );
       
   190                         iCacheIndexAdmin.RemoveTableIndex( 0 );
       
   191                         FlushCacheDataL();
       
   192                         size = iCacheServer->CacheSize( entryCount );
       
   193                     	}
       
   194                     else ready = ETrue;
       
   195                     }
       
   196                 } 
       
   197             }  
       
   198             break;
       
   199         case EXcapCacheDelete:
       
   200             DeleteCacheDataL( aMessage );
       
   201             break;
       
   202         case EXcapCacheCheckValidity:
       
   203             CheckValidityL( aMessage );
       
   204             break;
       
   205         case EXcapCacheFlush:
       
   206             FlushCacheDataL();
       
   207             break;
       
   208         default:
       
   209             PanicClient( EBadRequest );
       
   210         }
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------
       
   214 // CXcapCacheSession::CheckUnindexedEntriesL
       
   215 // 
       
   216 // ----------------------------------------------------------
       
   217 //
       
   218 void CXcapCacheSession::CheckUnindexedEntriesL( TInt aTotalCount )
       
   219     {
       
   220     #ifdef _DEBUG
       
   221     	CXcapCacheServer::WriteToLog( _L8( "CXcapCacheSession::CheckUnindexedEntriesL()" ) );
       
   222         CXcapCacheServer::WriteToLog( _L8( "  Total count: %d" ), aTotalCount );
       
   223 	#endif
       
   224     const TInt indexed = iCacheIndex.EntryCount();
       
   225     #ifdef _DEBUG
       
   226         CXcapCacheServer::WriteToLog( _L8( "  Indexed entries: %d" ), indexed );
       
   227 	#endif
       
   228     if( aTotalCount > indexed + 2 )  //index + pagefile = 2
       
   229         {
       
   230         CDesC16ArraySeg* array = new ( ELeave ) CDesC16ArraySeg( indexed );
       
   231         CleanupStack::PushL( array );
       
   232         array->AppendL( KCacheServerIndexF() );
       
   233         array->AppendL( KCacheServerPageFileF() );
       
   234         for( TInt i = 0;i < indexed;i++ )
       
   235             {
       
   236             const TChar delimiter = 92;
       
   237             TPtrC temp( iCacheIndex.Entry( i )->FileName16L() );
       
   238             TPtrC entry( temp.Right( temp.LocateReverse( delimiter ) + 1 ) );
       
   239             array->AppendL( entry );
       
   240             }
       
   241         DeleteExcessL( *array );
       
   242         array->Reset();
       
   243         CleanupStack::PopAndDestroy();  //array
       
   244         }
       
   245     }
       
   246 
       
   247 // ----------------------------------------------------------
       
   248 // CXcapCacheSession::DeleteExcessL
       
   249 // 
       
   250 // ----------------------------------------------------------
       
   251 //
       
   252 void CXcapCacheSession::DeleteExcessL( const MDesC16Array& aIndexedEntries )
       
   253 	{
       
   254 	#ifdef _DEBUG
       
   255     	CXcapCacheServer::WriteToLog( _L8( "CXcapCacheSession::DeleteExcessL()" ) );
       
   256 	#endif
       
   257     CDir* directory = NULL;
       
   258     RFs& session = CXcapCacheServer::FileSession();
       
   259     User::LeaveIfError( session.GetDir( KCacheServerRoot, KEntryAttNormal,
       
   260     					ESortNone, directory ) );
       
   261     CleanupStack::PushL( directory );
       
   262     const TInt count = directory->Count();
       
   263     for( TInt i = 0;i < count;i++ )
       
   264     	{
       
   265     	TPtrC targetName( ( *directory )[i].iName );
       
   266     	if( !IsIndexed( aIndexedEntries, targetName ) )
       
   267     		{
       
   268         	HBufC* fileName = HBufC::NewLC( targetName.Length() + 
       
   269     						  KCacheServerRoot().Length() );
       
   270     		fileName->Des().Copy( KCacheServerRoot );
       
   271     		fileName->Des().Append( targetName );
       
   272     		TPtrC name( fileName->Des() );
       
   273     		User::LeaveIfError( iFileManager->Delete( name ) );
       
   274     		CleanupStack::PopAndDestroy();  //fileName
       
   275     		}
       
   276     	}
       
   277     CleanupStack::PopAndDestroy();  //directory
       
   278 	}
       
   279 
       
   280 // ----------------------------------------------------------
       
   281 // CXcapCacheSession::IsIndexed
       
   282 // 
       
   283 // ----------------------------------------------------------
       
   284 //
       
   285 TBool CXcapCacheSession::IsIndexed( const MDesC16Array& aIndexedEntries, const TDesC& aFileName )
       
   286     {
       
   287     #ifdef _DEBUG
       
   288         CXcapCacheServer::WriteToLog( _L8( "CXcapCacheSession::IsIndexed()" ) );
       
   289     #endif
       
   290     TBool indexed = EFalse;
       
   291     const TInt count = aIndexedEntries.MdcaCount();
       
   292     for( TInt i = 0;!indexed && i < count;i++ )
       
   293     	{
       
   294     	if( aIndexedEntries.MdcaPoint( i ).Compare( aFileName ) == 0 )
       
   295     		{
       
   296     		indexed = ETrue;
       
   297     		}
       
   298     	}
       
   299     return indexed;
       
   300     }
       
   301 
       
   302 // ----------------------------------------------------------
       
   303 // CXcapCacheSession::ReadMsgParamLC
       
   304 // 
       
   305 // ----------------------------------------------------------
       
   306 //
       
   307 HBufC* CXcapCacheSession::ReadMsgParam16LC( TInt aMsgIndex, const RMessage2& aMessage )
       
   308     {
       
   309     #ifdef _DEBUG
       
   310         CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::ReadMsgParam16LC()" ) );
       
   311     #endif
       
   312     TInt length = aMessage.GetDesLength( aMsgIndex );
       
   313     HBufC* buffer = HBufC::NewLC( length );
       
   314     TPtr descriptor( buffer->Des() );
       
   315     aMessage.ReadL( aMsgIndex, descriptor );
       
   316     return buffer;
       
   317     }
       
   318 
       
   319 // ----------------------------------------------------------
       
   320 // CXcapCacheSession::ReadMsgParam8LC
       
   321 // 
       
   322 // ----------------------------------------------------------
       
   323 //
       
   324 HBufC8* CXcapCacheSession::ReadMsgParam8LC( TInt aMsgIndex, const RMessage2& aMessage )
       
   325     {
       
   326     #ifdef _DEBUG
       
   327         CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::ReadMsgParam8LC()" ) );
       
   328     #endif
       
   329     TInt length = aMessage.GetDesLength( aMsgIndex );
       
   330     HBufC8* buffer = HBufC8::NewLC( length );
       
   331     TPtr8 descriptor( buffer->Des() );
       
   332     aMessage.ReadL( aMsgIndex, descriptor );
       
   333     return buffer;
       
   334     }
       
   335        
       
   336 // ----------------------------------------------------------
       
   337 // CXcapCacheSession::CheckValidityL
       
   338 // 
       
   339 // ----------------------------------------------------------
       
   340 //
       
   341 void CXcapCacheSession::CheckValidityL( const RMessage2& aMessage )
       
   342     {
       
   343     #ifdef _DEBUG
       
   344         CXcapCacheServer::WriteToLog( _L8( "** CXcapCacheServer::CheckValidityL()" ) );
       
   345     #endif
       
   346     TPtrC8 etag( ReadMsgParam8LC( 0, aMessage )->Des() );
       
   347     TPtrC name( ReadMsgParam16LC( 1, aMessage )->Des() );
       
   348     TPtrC8 root( ReadMsgParam8LC( 2, aMessage )->Des() );
       
   349     TInt tableIndex = KErrNotFound;
       
   350     CXcapCacheIndexTableEntry* tableEntry = iCacheIndexAdmin.FindL( tableIndex, root, name );
       
   351     if( tableEntry != NULL )
       
   352         {
       
   353         CXcapCacheIndexEntry* entry = iCacheIndex.Entry( tableEntry->Index() );
       
   354         User::Leave( entry->ETag().Compare( etag ) == 0 ? KErrNone : KErrGeneral );
       
   355         }
       
   356     else User::Leave( KErrNotFound );
       
   357     CleanupStack::PopAndDestroy( 3 );  //root, name, etag
       
   358     }
       
   359     
       
   360 // ----------------------------------------------------------
       
   361 // CXcapCacheSession::DeleteCacheDataL
       
   362 // 
       
   363 // ----------------------------------------------------------
       
   364 //
       
   365 void CXcapCacheSession::DeleteCacheDataL( const RMessage2& aMessage )
       
   366     {
       
   367     #ifdef _DEBUG
       
   368         CXcapCacheServer::WriteToLog( _L8( "** CXcapCacheServer::DeleteCacheDataL()" ) );
       
   369     #endif
       
   370     TCacheEntryInfo header;
       
   371     TPckg<TCacheEntryInfo> pack( header );
       
   372     aMessage.ReadL( 0, pack );
       
   373     TInt tableIndex = KErrNotFound;
       
   374     CXcapCacheIndexTableEntry* tableEntry =
       
   375         iCacheIndexAdmin.FindL( tableIndex, *header.iRootUri, *header.iDocumentUri );
       
   376     if( tableEntry )
       
   377         {
       
   378         TInt error = KErrNone;
       
   379         TInt index( tableEntry->Index() );
       
   380         CXcapCacheIndexEntry* entry = iCacheIndex.Entry( index );
       
   381         error = DeleteFromStorageL( entry->FileName16L() );
       
   382         #ifdef _DEBUG
       
   383             CXcapCacheServer::WriteToLog(
       
   384                     _L8( "CXcapCacheSession::DeleteCacheDataL() - error: %d"), error  );
       
   385         #endif
       
   386         iCacheIndex.RemoveEntry( index );
       
   387         iCacheIndexAdmin.RemoveTableIndex( tableIndex );
       
   388         FlushCacheDataL();
       
   389         }
       
   390     else User::Leave( KErrNotFound );
       
   391     }
       
   392     
       
   393 // ----------------------------------------------------------
       
   394 // CXcapCacheSession::FetchDocumentInfoL
       
   395 // 
       
   396 // ----------------------------------------------------------
       
   397 //
       
   398 void CXcapCacheSession::FetchDocumentInfoL( const RMessage2& aMessage )
       
   399     {
       
   400     #ifdef _DEBUG
       
   401         CXcapCacheServer::WriteToLog( _L8( "** CXcapCacheServer::FetchDocumentInfoL()" ) );
       
   402     #endif
       
   403     TInt error = KErrNone;
       
   404     //Read info header
       
   405     TCacheEntryInfo header;
       
   406     TPckg<TCacheEntryInfo> pack( header );
       
   407     aMessage.ReadL( 0, pack );
       
   408     TPtrC name( ReadMsgParam16LC( 2, aMessage )->Des() );
       
   409     TPtrC8 root( ReadMsgParam8LC( 3, aMessage )->Des() );
       
   410     TInt tableIndex = KErrNotFound;
       
   411     #ifdef _DEBUG
       
   412         HBufC8* temp = HBufC8::NewLC( name.Length() );
       
   413         TPtr8 tempDesc( temp->Des() );
       
   414         tempDesc.Copy( name );
       
   415         CXcapCacheServer::WriteToLog( _L8( "   Root:     %S" ), &root );
       
   416         CXcapCacheServer::WriteToLog( _L8( "   Document: %S" ), &tempDesc );
       
   417         CleanupStack::PopAndDestroy();  //temp
       
   418     #endif
       
   419     CXcapCacheIndexTableEntry* tableEntry = iCacheIndexAdmin.FindL( tableIndex, root, name );
       
   420     if( tableEntry != NULL )
       
   421         {
       
   422         TInt index = tableEntry->Index();
       
   423         CXcapCacheIndexEntry* entry = iCacheIndex.Entry( index );
       
   424         TPtrC8 eTag = entry->ETag();
       
   425         header.iDataLength = entry->XmlSize();
       
   426         header.iLastAccess = entry->LastAccess();
       
   427         header.iLastUpdate = entry->LastModified();
       
   428         TPckgC<TCacheEntryInfo> package( header );
       
   429         TRAP( error, aMessage.WriteL( 0, package ) );
       
   430         #ifdef _DEBUG
       
   431             CXcapCacheServer::WriteToLog( _L8( "  Write header: %d" ), error );
       
   432         #endif
       
   433         TRAP( error, aMessage.WriteL( 1, eTag ) );
       
   434         #ifdef _DEBUG
       
   435             CXcapCacheServer::WriteToLog( _L8( "  Write ETag:   %d" ), error );
       
   436         #endif
       
   437         }
       
   438     else User::Leave( KErrNotFound );
       
   439     CleanupStack::PopAndDestroy( 2 );  //root, name
       
   440     }
       
   441     
       
   442 // ----------------------------------------------------------
       
   443 // CXcapCacheSession::FetchDocumentContentsL
       
   444 // 
       
   445 // ----------------------------------------------------------
       
   446 //
       
   447 void CXcapCacheSession::FetchDocumentContentsL( const RMessage2& aMessage )
       
   448     {
       
   449     #ifdef _DEBUG
       
   450         CXcapCacheServer::WriteToLog( _L8( "** CXcapCacheServer::FetchDocumentContentsL()" ) );
       
   451     #endif
       
   452     TPtrC name( ReadMsgParam16LC( 0, aMessage )->Des() );
       
   453     TPtrC8 root( ReadMsgParam8LC( 1, aMessage )->Des() );
       
   454     #ifdef _DEBUG
       
   455         HBufC8* document = HBufC8::NewLC( name.Length() );
       
   456         TPtr8 docDesc( document->Des() );
       
   457         docDesc.Copy( name );
       
   458         CXcapCacheServer::WriteToLog( _L8( "  Document:    %S" ), &docDesc );
       
   459         CXcapCacheServer::WriteToLog( _L8( "  Root URI:    %S" ), &root );
       
   460         CleanupStack::PopAndDestroy();  //document
       
   461     #endif
       
   462     TInt tableIndex = KErrNotFound;
       
   463     CXcapCacheIndexTableEntry* tableEntry = iCacheIndexAdmin.FindL( tableIndex, root, name );
       
   464     if( tableEntry != NULL )
       
   465         {
       
   466         CXcapCacheIndexEntry* entry = iCacheIndex.Entry( tableEntry->Index() );
       
   467         iTempBuffer = ReadFromStorageL( entry->FileName16L() );
       
   468         TPtrC8 dataDesc = iTempBuffer->Des();
       
   469         aMessage.Write( 2, dataDesc );
       
   470         }
       
   471     else User::Leave( KErrNotFound );
       
   472     CleanupStack::PopAndDestroy( 2 );  //name, root
       
   473     }
       
   474     
       
   475 // ----------------------------------------------------------
       
   476 // CXcapCacheSession::CacheXcapData
       
   477 // 
       
   478 // ----------------------------------------------------------
       
   479 //
       
   480 void CXcapCacheSession::CacheXcapDataL( const RMessage2& aMessage )
       
   481     {
       
   482     #ifdef _DEBUG
       
   483         CXcapCacheServer::WriteToLog( _L8( "** CXcapCacheServer::CacheXcapDataL()" ) );
       
   484     #endif
       
   485     TPtrC doc( ReadMsgParam16LC( 0, aMessage )->Des() );
       
   486     TPtrC8 root( ReadMsgParam8LC( 1, aMessage )->Des() );
       
   487     TPtrC8 etag( ReadMsgParam8LC( 2, aMessage )->Des() );
       
   488     TPtrC8 data( ReadMsgParam8LC( 3, aMessage )->Des() );
       
   489     #ifdef _DEBUG
       
   490         HBufC8* document = HBufC8::NewLC( doc.Length() );
       
   491         TPtr8 docDesc( document->Des() );
       
   492         docDesc.Copy( doc );
       
   493         CXcapCacheServer::WriteToLog( _L8( "  Document:    %S" ), &docDesc );
       
   494         CXcapCacheServer::WriteToLog( _L8( "  ETag:        %S" ), &etag );
       
   495         CXcapCacheServer::WriteToLog( _L8( "  Root URI:    %S" ), &root );
       
   496         CXcapCacheServer::WriteToLog( _L8( "  Data:        %d bytes" ), data.Length() );
       
   497         CleanupStack::PopAndDestroy();  //document
       
   498     #endif
       
   499     TInt tableIndex = KErrNotFound;
       
   500     TCacheEntryInfo header;
       
   501     header.iEtag = &etag;
       
   502     header.iRootUri = &root;
       
   503     header.iRespData = &data;
       
   504     header.iDocumentUri = &doc;
       
   505     header.iDataLength = data.Length();
       
   506     CXcapCacheIndexTableEntry* tableEntry = iCacheIndexAdmin.FindL( tableIndex, root, doc );
       
   507     CXcapCacheIndexEntry* entry = NULL;
       
   508     if( tableEntry != NULL )
       
   509         {
       
   510         entry = iCacheIndex.Entry( tableEntry->Index() );
       
   511         entry->UpdateEntryL( &header );
       
   512         }
       
   513     else
       
   514         {
       
   515         entry = CXcapCacheIndexEntry::NewL( &header );
       
   516         CleanupStack::PushL( entry );
       
   517         TInt index = iCacheIndex.UpdateIndexL( entry );
       
   518         CleanupStack::Pop();  //entry
       
   519         iCacheIndexAdmin.UpdateIndexTableL( index, &header );
       
   520         }
       
   521     CleanupStack::PopAndDestroy( 4 );  //data, etag, root, name
       
   522     FlushCacheDataL();
       
   523     }
       
   524 
       
   525 // ----------------------------------------------------------
       
   526 // CXcapCacheSession::FlushCacheDataL
       
   527 // 
       
   528 // ----------------------------------------------------------
       
   529 //
       
   530 void CXcapCacheSession::FlushCacheDataL()
       
   531     {
       
   532     #ifdef _DEBUG
       
   533         CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::FlushCacheDataL()" ) );
       
   534     #endif
       
   535     iCacheIndex.StoreCacheDataL();
       
   536     iCacheIndexAdmin.StoreIndexTableL();
       
   537     }
       
   538 
       
   539 // ----------------------------------------------------------
       
   540 // CXcapCacheSession::DeleteFromStorageL
       
   541 // 
       
   542 // ----------------------------------------------------------
       
   543 //
       
   544 TInt CXcapCacheSession::DeleteFromStorageL( const TDesC& aFileName )
       
   545     {
       
   546     #ifdef _DEBUG
       
   547         HBufC8* name = HBufC8::NewLC( aFileName.Length() );
       
   548         TPtr8 nameDesc( name->Des() );
       
   549         nameDesc.Copy( aFileName );
       
   550         CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::DeleteFromStorageL() - Filename: %S" ), &nameDesc );
       
   551         CleanupStack::PopAndDestroy();  //name
       
   552     #endif
       
   553     TInt error = iFileManager->Delete( aFileName );
       
   554     return error;
       
   555     }
       
   556             
       
   557 // ----------------------------------------------------------
       
   558 // CXcapCacheSession::FlushCacheDataL
       
   559 // 
       
   560 // ----------------------------------------------------------
       
   561 //
       
   562 HBufC8* CXcapCacheSession::ReadFromStorageL( const TDesC& aFileName )
       
   563     {
       
   564     #ifdef _DEBUG
       
   565         HBufC8* name = HBufC8::NewLC( aFileName.Length() );
       
   566         TPtr8 nameDesc( name->Des() );
       
   567         nameDesc.Copy( aFileName );
       
   568         CXcapCacheServer::WriteToLog( _L8( "CXcapCacheServer::ReadFromStorageL() - Filename: %S" ), &nameDesc );
       
   569         CleanupStack::PopAndDestroy();  //name
       
   570     #endif
       
   571     RFile file;
       
   572     HBufC8* data = NULL;
       
   573     User::LeaveIfError( file.Open( CXcapCacheServer::FileSession(), aFileName, EFileRead ) );
       
   574     CleanupClosePushL( file );
       
   575     TInt size = 0;
       
   576     User::LeaveIfError( file.Size( size ) );
       
   577     data = HBufC8::NewL( size );
       
   578     TPtr8 pointer( data->Des() );
       
   579     file.Read( pointer );
       
   580     CleanupStack::PopAndDestroy();  //file
       
   581     return data;
       
   582     }
       
   583 
       
   584 
       
   585 
       
   586 
       
   587 
       
   588