diff -r 10e98eab6f85 -r a359256acfc6 webengine/osswebengine/cache/src/HttpCacheUtil.cpp --- a/webengine/osswebengine/cache/src/HttpCacheUtil.cpp Fri Jul 03 15:54:40 2009 +0100 +++ b/webengine/osswebengine/cache/src/HttpCacheUtil.cpp Thu Aug 27 07:44:59 2009 +0300 @@ -653,35 +653,43 @@ // ----------------------------------------------------------------------------- // TBool HttpCacheUtil::VSSCacheContent( const TDesC8& aUrl, const HBufC8* aWhiteList ) - { + { TBool found( EFalse ); - if( aWhiteList ) - { - TUint8* bufPtr = (TUint8* ) aWhiteList->Ptr(); - TUint8* startBufPtr = bufPtr; - TUint len = aWhiteList->Length(); - TInt i, startUri, uriLen; - TPtrC8 uri ( aUrl ); - for(i=0; i < len; i++) - { - startUri = i; - for( ;( ( *bufPtr != ';' ) && ( iPtr(); + TUint8* startBufPtr = bufPtr; + TUint len = aWhiteList->Length(); + TInt i, startUri, uriLen; + TPtrC8 uri ( aUrl ); + for ( i=0; i < len; i++ ) + { + startUri = i; + + for ( ;( ( *bufPtr != ';' ) && ( i expires) { return EFalse; } - + if( err == KErrNone || maxAge > 0 ) { hasExplicitCache = ETrue; @@ -1150,6 +1155,45 @@ } // ----------------------------------------------------------------------------- +// HttpCacheUtil::WriteFormatLog +// +// ----------------------------------------------------------------------------- +// +void HttpCacheUtil::WriteFormatLog( + TInt aLogLevel, + TRefByValue aBuf, ... ) + { +#ifdef __CACHELOG__ + TBool log( aLogLevel <= KCurrentLogLevel ); + TPtrC fileName( KHttpCacheGeneralFileName ); + + if ( aLogLevel == 1 ) + { + // write logging to hash.txt + fileName.Set( KHttpCacheHashFileName ); + log = ETrue; + } + + if ( log ) + { + VA_LIST args; + VA_START(args, aBuf); + // Be careful of string length when debugging + TBuf16<1024> string; + // TDes16OverflowIgnore, not supported in 3.2.3 + // TDes16OverflowIgnore overflow; + // string.AppendFormatList(aBuf, args, &overflow); + string.AppendFormatList(aBuf, args); + RFileLogger::WriteFormat(_L("Browser"), fileName, EFileLoggingModeAppend, string); + VA_END(args); + } +#else // __CACHELOG__ + (void)aLogLevel; + (void)aBuf; +#endif // __CACHELOG__ + } + +// ----------------------------------------------------------------------------- // HttpCacheUtil::WriteLogFilenameAndUrl // // ----------------------------------------------------------------------------- @@ -1170,7 +1214,7 @@ TInt tmpLen( aMethodName.Length() + aFilename.Length() + 3*KColonSpace().Length() + aUrl.Length() + itemTypeStringLen ); HBufC* tmp = HBufC::New( tmpLen ); - + if ( tmp ) { TPtr tmpPtr( tmp->Des() ); tmpPtr.Copy( aMethodName ); @@ -1198,17 +1242,17 @@ tmpPtr.Append( KColonSpace ); } } - + // Append the bucketIndex, lookup table pos, etc... switch ( aItemType ) { case ELogItemTypeNone: break; - + case ELogBucketIndex: tmpPtr.Append( _L("bucketIndex =") ); break; - + case ELogEntrySize: tmpPtr.Append( _L("entrySize =") ); break; @@ -1321,28 +1365,33 @@ // ----------------------------------------------------------------------------- // HttpCacheUtil::GenerateNameLC -// Given a URL, generates fully qualified Symbian path for storing HTTP response. -// The format is + + . -// Caller must free the returned HBufC* when done. +// Given a URL, generates fully qualified Symbian path for storing HTTP response. +// The format is + + . +// Caller must free the returned HBufC* when done. // ----------------------------------------------------------------------------- -HBufC* HttpCacheUtil::GenerateNameLC( - const TDesC8& aUrl, const TDesC& aBaseDir) +HBufC* HttpCacheUtil::GenerateNameLC( const TDesC8& aUrl, const TDesC& aBaseDir ) { - TUint32 crc (0); - - //use the entire URL for CRC calculation: maximizes source entropy/avoids collisions - Mem::Crc32(crc, aUrl.Ptr(), aUrl.Size()); - TUint32 nibble (crc & (KCacheSubdirCount-1)); // extract least significant 4 bits (nibble) for subdirectory - - HBufC* fileName = HBufC::NewLC( KMaxPath ); // e.g E\078AFEFE - _LIT(KFormat,"%S%x%c%08x"); // Note the %08x : a 32-bit value can represented as 0xFFFFFFFF + + // Use the entire URL for CRC calculation: maximizes source + // entropy/avoids collisions. Returns 8 char hex filename, use + // KMaxFilenameLength to internalize/externalize. + Mem::Crc32(crc, aUrl.Ptr(), aUrl.Size()); + + // extract least significant 4 bits (nibble) for subdirectory + TUint32 nibble( crc & (KCacheSubdirCount-1) ); + + // filename has full path, drive:\directory\sub-directory\8-char filename + // e.g. c:\system\cache\E\078AFEFE, where E is calculated by nibble() + // and 078AFEFE is calculated by crc32() + HBufC* fileName = HBufC::NewLC( KMaxPath ); + // Note in KFormat, the %08x : a 32-bit value can represented as 0xFFFFFFFF + _LIT(KFormat,"%S%x%c%08x"); fileName->Des().Format(KFormat, &aBaseDir, nibble, KPathDelimiter, crc); + return fileName; - } - // ----------------------------------------------------------------------------- // HttpCacheUtil::Freshness // @@ -1368,7 +1417,7 @@ // Get the date from the headers fieldName = aStrP.StringF( HTTP::EDate, RHTTPSession::GetTable() ); err = aHeaders.GetField( fieldName, 0, hdrValue ); - if( err == KErrNotFound || hdrValue.Type() != THTTPHdrVal::KDateVal ) + if ( err == KErrNotFound || hdrValue.Type() != THTTPHdrVal::KDateVal ) { date = aResponseTime; } @@ -1379,12 +1428,12 @@ // Get useful cache-control directives status = GetCacheControls( aHeaders, &maxAge, NULL, NULL, NULL, NULL, NULL, aStrP ); - if( status == KErrNone ) + if ( status == KErrNone ) { // max-age is in delta-seconds. Convert it to micro seconds. // All our calculations are in micro-seconds // If maxAge is present, use it - if( maxAge != -1 ) + if ( maxAge != -1 ) { freshness = maxAge * 1000 * 1000; @@ -1394,7 +1443,7 @@ // Get the expires from the headers fieldName = aStrP.StringF( HTTP::EExpires, RHTTPSession::GetTable() ); err = aHeaders.GetField( fieldName, 0, hdrValue ); - if( err == KErrNotFound || hdrValue.Type() != THTTPHdrVal::KDateVal ) + if ( err == KErrNotFound || hdrValue.Type() != THTTPHdrVal::KDateVal ) { expires = 0; } @@ -1404,7 +1453,7 @@ } // Otherwise, if the expires is present use it - if( err != KErrNotFound ) + if ( err != KErrNotFound ) { freshness = expires.Int64() - date.Int64(); return freshness; @@ -1423,7 +1472,7 @@ } // Otherwise, if last-modified is present use it - if( err != KErrNotFound ) + if ( err != KErrNotFound ) { if( aResponseTime > lastModified ) {