lib_LTLIBRARIES = libkita.la
-libkita_la_SOURCES = comment.cpp comment.h thread.h thread.cpp qcp932codec.cpp qcp932codec.h board.h board.cpp bbs.h bbs.cpp category.h category.cpp favoritethreads.h favoritethreads.cpp k2ch_articlefile.h k2ch_articlefile.cpp kita_misc.cpp threadinfo.h threadinfo.cpp access.cpp
+libkita_la_SOURCES = comment.cpp comment.h thread.h thread.cpp qcp932codec.cpp qcp932codec.h board.h board.cpp bbs.h bbs.cpp category.h category.cpp favoritethreads.h favoritethreads.cpp k2ch_articlefile.h k2ch_articlefile.cpp kita_misc.cpp threadinfo.h threadinfo.cpp access.cpp cache.cpp
METASOURCES = AUTO
SUBDIRS = tests
-noinst_HEADERS = kita_misc.h access.h
+noinst_HEADERS = kita_misc.h access.h cache.h
#include "thread.h"
#include "qcp932codec.h"
+#include "cache.h"
#include <config.h>
using namespace Kita;
-QString Access::cacheDir( const KURL& url )
-{
- QString dir;
- if ( url.protocol() == "k2ch" ) {
- dir = KGlobal::dirs() ->saveLocation( "cache", "k2ch" );
- } else {
- dir = KProtocolManager::cacheDir();
- }
- if ( dir[ dir.length() - 1 ] != '/' )
- dir += "/";
-
- return dir;
-}
-
-QString Access::cacheSubDir( const QString& host )
-{
- int l = host.length();
- for ( int i = 0; i < l; i++ ) {
- if ( host[ i ].isLetter() && ( host[ i ] != 'w' ) ) {
- return QString( host[ i ] );
- }
- }
- return "0";
-}
-
-QString Access::hashString( const KURL& url )
-{
- unsigned long hash = 0x00000000;
- QCString u = url.url().latin1();
- for ( int i = u.length(); i--; ) {
- hash = ( hash * 12211 + u[ i ] ) % 2147483563;
- }
-
- QString ret;
- ret.sprintf( "%08lx", hash );
-
- return ret;
-}
-
-// copied from http.cc
-QString Access::getCachePath( const KURL& url )
-{
- QString path = url.path();
- path.replace( QChar( '/' ), QChar( '_' ) );
-
- QString host = url.host().lower();
-
- return cacheDir( url ) + cacheSubDir( host ) + "/" + host + path + '_' + hashString( url );
-}
-
bool Access::readCacheHeader( FILE* fs, const KURL& url )
{
QFile file;
// ¥¥ã¥Ã¥·¥å¤¬¤Ê¤¤¤È¤¤Ï0¤òÊÖ¤¹¡£
QCString Access::getCacheData( const KURL& url )
{
- QString cachePath = getCachePath( url );
+ QString cachePath = Kita::Cache::getPath( url );
FILE *fs = fopen( QFile::encodeName( cachePath ), "r" );
if ( !fs ) {
// partial data¤¬Æþ¤Ã¤Æ¤ë¤Î¤Ç¤½¤ì¤ò½ñ¤´¹¤¨¤ë¡£
void Access::writeCacheData( const KURL& url )
{
- QString cachePath = getCachePath( url );
+ QString cachePath = Kita::Cache::getPath( url );
FILE *fs = fopen( QFile::encodeName( cachePath ), "r+" );
if ( !fs ) {
m_orgData = getCacheData( m_thread->datURL() );
// copy original cache file
- QString cachePath = getCachePath( m_thread->datURL() );
+ QString cachePath = Kita::Cache::getPath( m_thread->datURL() );
QString backupPath = cachePath + ".kita_backup";
KIO::NetAccess::copy( cachePath, backupPath );
void Access::slotRedirection( KIO::Job *, const KURL & newURL )
{
// datÍî¤Á¤·¤Æ¤ë¤È»×¤ï¤ì¤ë¤Î¤Ç¥¥ã¥Ã¥·¥å¤ò¸µ¤ËÌ᤹
- QString cachePath = getCachePath( m_thread->datURL() );
+ QString cachePath = Kita::Cache::getPath( m_thread->datURL() );
QString backupPath = cachePath + ".kita_backup";
KIO::NetAccess::copy( backupPath, cachePath );
KIO::NetAccess::del( backupPath );
private:
void enter_loop();
- QString getCachePath( const KURL& url );
QCString getCacheData( const KURL& url );
void writeCacheData( const KURL& url );
int responseCode();
bool readCacheHeader( FILE* fs, const KURL& url );
- QString cacheDir( const KURL& url );
- QString cacheSubDir( const QString& host );
- QString hashString( const KURL& url );
const Thread* m_thread;
KIO::Job* m_currentJob;
--- /dev/null
+/***************************************************************************
+* Copyright (C) 2003 by Hideki Ikemoto *
+* ikemo@wakaba.jp *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#include "cache.h"
+
+#include <kurl.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <kprotocolmanager.h>
+
+using namespace Kita;
+
+QString Cache::baseDir( const KURL& url )
+{
+ QString dir;
+ if ( url.protocol() == "k2ch" ) {
+ dir = KGlobal::dirs() ->saveLocation( "cache", "k2ch" );
+ } else {
+ dir = KProtocolManager::cacheDir();
+ }
+ if ( dir[ dir.length() - 1 ] != '/' )
+ dir += "/";
+
+ return dir;
+}
+
+QString Cache::subDir( const QString& host )
+{
+ int l = host.length();
+ for ( int i = 0; i < l; i++ ) {
+ if ( host[ i ].isLetter() && ( host[ i ] != 'w' ) ) {
+ return QString( host[ i ] );
+ }
+ }
+ return "0";
+}
+
+QString Cache::hashString( const KURL& url )
+{
+ unsigned long hash = 0x00000000;
+ QCString u = url.url().latin1();
+ for ( int i = u.length(); i--; ) {
+ hash = ( hash * 12211 + u[ i ] ) % 2147483563;
+ }
+
+ QString ret;
+ ret.sprintf( "%08lx", hash );
+
+ return ret;
+}
+
+// original is in http.cc
+QString Cache::getPath( const KURL& url )
+{
+ QString path = url.path();
+ path.replace( QChar( '/' ), QChar( '_' ) );
+
+ QString host = url.host().lower();
+
+ return baseDir( url ) + subDir( host ) + "/" + host + path + '_' + hashString( url );
+}
--- /dev/null
+/***************************************************************************
+* Copyright (C) 2003 by Hideki Ikemoto *
+* ikemo@wakaba.jp *
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+***************************************************************************/
+#ifndef KITACACHE_H
+#define KITACACHE_H
+
+#include <qstring.h>
+
+class KURL;
+
+namespace Kita
+{
+
+ /**
+ @author Hideki Ikemoto
+ */
+ class Cache
+ {
+ static QString baseDir( const KURL& url );
+ static QString subDir( const QString& host );
+ static QString hashString( const KURL& url );
+ public:
+ static QString getPath( const KURL& url );
+ };
+
+};
+
+#endif