return CEF;
}
-// copied from http.cc
-// ¥¥ã¥Ã¥·¥å¤¬¤¢¤ë¤È¤¤Ï¤½¤ÎÆâÍƤòmalloc¤·¤¿Îΰè¤Ë¥³¥Ô¡¼¤·¤ÆÊÖ¤¹¡£
-// ¥¥ã¥Ã¥·¥å¤¬¤Ê¤¤¤È¤¤Ï0¤òÊÖ¤¹¡£
-char* ThreadAccess::getCacheData( const KURL& url )
+bool ThreadAccess::readCacheHeader( FILE* fs, const KURL& url )
{
- QString cachePath = getCachePath( url );
-
- FILE *fs = fopen( QFile::encodeName( cachePath ), "r" );
- if ( !fs ) {
- return 0;
- }
-
char buffer[ 401 ];
- bool ok = true;
// CacheRevision
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
- if ( ok && ( strcmp( buffer, "7\n" ) != 0 ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
+ if ( strcmp( buffer, "7\n" ) != 0 ) {
+ return false;
+ }
// URL
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
- if ( ok ) {
- int l = strlen( buffer );
- if ( l > 0 )
- buffer[ l - 1 ] = 0; // Strip newline
- if ( url.url() != buffer ) {
- ok = false; // Hash collision
- }
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
+
+ int l = strlen( buffer );
+ if ( l > 0 ) {
+ buffer[ l - 1 ] = 0; // Strip newline
+ }
+
+ if ( url.url() != buffer ) {
+ return false; // Hash collision
}
// Creation Date
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
// Expiration Date
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
// ETag
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
// Last-Modified
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
// Mime-Type
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
// Charset
- if ( ok && ( !fgets( buffer, 400, fs ) ) )
- ok = false;
+ if ( !fgets( buffer, 400, fs ) ) {
+ return false;
+ }
- if ( ok ) {
+ return true;
+}
+
+// copied from http.cc
+// ¥¥ã¥Ã¥·¥å¤¬¤¢¤ë¤È¤¤Ï¤½¤ÎÆâÍƤòmalloc¤·¤¿Îΰè¤Ë¥³¥Ô¡¼¤·¤ÆÊÖ¤¹¡£
+// ¥¥ã¥Ã¥·¥å¤¬¤Ê¤¤¤È¤¤Ï0¤òÊÖ¤¹¡£
+char* ThreadAccess::getCacheData( const KURL& url )
+{
+ QString cachePath = getCachePath( url );
+
+ FILE *fs = fopen( QFile::encodeName( cachePath ), "r" );
+ if ( !fs ) {
+ return 0;
+ }
+
+ if ( readCacheHeader( fs, url ) ) {
struct stat buf;
::stat( QFile::encodeName( cachePath ), &buf );
int pos = ftell( fs );