Merge from NuCache_BRANCH. Will not affect the build process.

This commit is contained in:
gagan%netscape.com 1998-08-26 18:35:28 +00:00
Родитель 8269f347ba
Коммит 6ba394a95f
38 изменённых файлов: 1264 добавлений и 414 удалений

24
network/cache/nu/include/nsCacheTrace.h поставляемый
Просмотреть файл

@ -35,29 +35,17 @@ class nsCacheTrace
{
public:
nsCacheTrace(void);
static void Enable(PRBool bEnable);
static PRBool IsEnabled(void);
static void Trace(const char* msg);
static void Traceln(const char* msg);
static void Use(char* buffer);
static char* m_TraceBuffer;
static void Trace(const char* msg);
static void Traceln(const char* msg);
static void Use(char* buffer);
static char* m_TraceBuffer;
private:
nsCacheTrace();
static PRBool m_bEnabled;
PRBool m_bEnabled;
};
inline
void nsCacheTrace::Enable(PRBool bEnable)
{
m_bEnabled = bEnable;
}
inline
PRBool nsCacheTrace::IsEnabled(void)
{
return m_bEnabled;
}
inline void nsCacheTrace::Trace(const char* msg)
{
PR_ASSERT(msg);

2
network/cache/nu/include/nsFFObject.h поставляемый
Просмотреть файл

@ -19,7 +19,7 @@
#ifndef nsFFObject_h__
#define nsFFObject_h__
#include <prtypes.h>
#include "prtypes.h"
class nsFFObject
{

4
network/cache/nu/include/nsFlatFile.h поставляемый
Просмотреть файл

@ -19,8 +19,8 @@
#ifndef nsFlatFile_h__
#define nsFlatFile_h__
#include <prtypes.h>
#include <prio.h>
#include "prtypes.h"
#include "prio.h"
//#include "nsISupports.h"

4
network/cache/nu/include/nsTimeIt.h поставляемый
Просмотреть файл

@ -1,7 +1,7 @@
/* A class to time excursion events */
/* declare an object of this class within the scope to be timed. */
#include <prtypes.h>
#include <prinrval.h>
#include "prtypes.h"
#include "prinrval.h"
class nsTimeIt
{

43
network/cache/nu/public/CacheStubs.h поставляемый
Просмотреть файл

@ -27,45 +27,76 @@
#ifndef CacheStubs_h__
#define CacheStubs_h__
#include <prtypes.h>
#include <prinrval.h>
#include "prtypes.h"
#include "prinrval.h"
#define MEM_MODULE_ID 0
#define DISK_MODULE_ID 1
PR_BEGIN_EXTERN_C
/* General mapped functions which resolve to a bunch of internal calls. */
extern void Cache_Init(void);
extern void Cache_Shutdown(void);
/* Cache Manager stub functions
Does not include some functions not required in the current
design like AddModule etc... If you need to these functions, try
accessing them directly thru the C++ api or let me know.
Check nsCacheManager.h for details on these functions.*/
extern PRBool CacheManager_Contains(const char* i_url);
extern PRUint32 CacheManager_Entries(void);
extern PRInt16 CacheManager_Entries(void);
extern void* CacheManager_GetObject(const char* i_url);
extern PRBool CacheManager_IsOffline(void);
extern void CacheManager_Offline(PRBool bSet);
extern PRBool CacheManager_Remove(const char* i_url);
extern PRUint32 CacheManager_WorstCaseTime(void);
/* Cache Object- check nsCacheObject.h for details on these functions */
extern void* CacheObject_Create(const char* i_url);
extern void CacheObject_Destroy(void* pThis);
extern const char* CacheObject_GetAddress(const void* pThis);
extern const char* CacheObject_GetCharset(void* pThis);
extern const char* CacheObject_GetContentEncoding(void* pThis);
extern PRUint32 CacheObject_GetContentLength(void* pThis);
extern const char* CacheObject_GetContentType(void* pThis);
extern const char* CacheObject_GetEtag(const void* pThis);
extern PRIntervalTime CacheObject_GetExpires(const void* pThis);
extern const char* CacheObject_GetFilename(const void* pThis);
extern PRIntervalTime CacheObject_GetLastAccessed(const void* pThis);
extern PRIntervalTime CacheObject_GetLastModified(const void* pThis);
extern PRInt16 CacheObject_GetModule(const void* pThis);
extern const char* CacheObject_GetPageServicesURL(void* pThis);
extern const char* CacheObject_GetPostData(const void* pThis);
extern PRUint32 CacheObject_GetPostDataLen(const void* pThis);
extern PRUint32 CacheObject_GetSize(const void* pThis);
extern PRUint32 CacheObject_Hits(const void* pThis);
extern PRBool CacheObject_IsExpired(const void* pThis);
extern PRBool CacheObject_IsPartial(const void* pThis);
extern PRUint32 CacheObject_Read(const void* pThis, char* o_Destination, PRUint32 i_Len);
extern void CacheObject_SetAddress(void* pThis, const char* i_Address);
extern void CacheObject_SetCharset(void* pThis, const char* i_CharSet);
extern void CacheObject_SetContentEncoding(void* pThis, const char* i_Encoding);
extern void CacheObject_SetContentLength(void* pThis, PRUint32 i_Len);
extern void CacheObject_SetContentType(void* pThis, const char* i_Type);
extern void CacheObject_SetEtag(void* pThis, const char* i_Etag);
extern void CacheObject_SetExpires(void *pThis, const PRIntervalTime i_Time);
extern void CacheObject_SetFilename(void *pThis, const char* i_Filename);
extern void CacheObject_SetLastModified(void* pThis, const PRIntervalTime i_Time);
extern void CacheObject_SetModule(void* pThis, const PRInt16 i_Module);
extern void CacheObject_SetPageServicesURL(void* pThis, const char* i_Url);
extern void CacheObject_SetPostData(void* pThis, const char* i_PostData, const PRUint32 i_Len);
extern void CacheObject_SetSize(void* pThis, const PRUint32 i_Size);
extern void CacheObject_Destroy(void* pThis);
extern PRBool CacheObject_Synch(void* pThis);
extern PRUint32 CacheObject_Write(void* pThis, const char* i_buffer, const PRUint32 i_length);
/* Cache Prefs- check nsCachePref.h for details on these functions */
extern PRUint32 CachePref_DiskCacheSize(void);
extern PRUint32 CachePref_GetDiskCacheSize(void);
extern PRBool CachePref_GetDiskCacheSSL(void);
extern PRUint32 CachePref_MemCacheSize(void);
extern PRUint32 CachePref_GetMemCacheSize(void);
extern void CachePref_SetDiskCacheSize(const PRUint32 i_Size);
extern void CachePref_SetDiskCacheSSL(PRBool bSet);
extern void CachePref_SetMemCacheSize(const PRUint32 i_Size);
/* Cache Trace- Check nsCacheTrace.h for details on these functions */
extern void CacheTrace_Enable(PRBool bEnable);

1
network/cache/nu/public/Makefile поставляемый
Просмотреть файл

@ -18,6 +18,7 @@
DEPTH=../../../..
EXPORTS = \
nsMonitorable.h \
nsMemModule.h \
nsCacheManager.h \
nsDiskModule.h \

1
network/cache/nu/public/makefile.win поставляемый
Просмотреть файл

@ -24,6 +24,7 @@ EXPORTS=nsCacheObject.h nsMemModule.h nsCacheManager.h \
nsDiskModule.h nsCacheModule.h nsMemCacheObject.h \
nsCachePref.h nsCacheBkgThd.h nsBkgThread.h \
CacheStubs.h nsCacheIterator.h nsIterator.h \
nsMonitorable.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>

4
network/cache/nu/public/nsBkgThread.h поставляемый
Просмотреть файл

@ -20,8 +20,8 @@
#define nsBkgThread_h__
//#include "nsISupports.h"
#include <prthread.h>
#include <prinrval.h>
#include "prthread.h"
#include "prinrval.h"
/*
Creates a background thread that maintains odd

5
network/cache/nu/public/nsCacheIterator.h поставляемый
Просмотреть файл

@ -45,6 +45,11 @@ nsCacheIterator::nsCacheIterator(nsCacheModule* i_pModule): m_pModule(i_pModule)
{
}
inline
nsCacheIterator::~nsCacheIterator()
{
}
inline
PRBool nsCacheIterator::IsDone(void) const
{

89
network/cache/nu/public/nsCacheManager.h поставляемый
Просмотреть файл

@ -29,8 +29,9 @@
# include "nsISupports.h"
#endif
#include <prlog.h>
#include "prlog.h"
#include "nsMonitorable.h"
#include "nsCacheModule.h"
#include "nsCacheObject.h"
@ -39,7 +40,7 @@ class nsDiskModule;
class nsCachePref;
class nsCacheBkgThd;
class nsCacheManager //: public nsISupports
class nsCacheManager : public nsMonitorable //: public nsISupports
{
public:
@ -54,39 +55,58 @@ public:
nsCacheManager();
~nsCacheManager();
PRInt32 AddModule(nsCacheModule* i_cacheModule);
PRBool Contains(const char* i_url) const;
PRInt32 AddModule(nsCacheModule* i_cacheModule);
// InsertModule
PRBool Contains(const char* i_url) const;
/* Number of modules in the cache manager */
PRInt32 Entries() const;
PRInt16 Entries() const;
/* Singleton */
static nsCacheManager*
GetInstance();
static nsCacheManager* GetInstance();
nsCacheObject* GetObject(const char* i_url) const;
nsCacheModule* GetModule(PRInt32 i_index) const;
nsCacheObject* GetObj(const char* i_url) const;
nsMemModule* GetMemModule() const;
nsDiskModule* GetDiskModule() const;
nsCacheModule* GetModule(PRInt16 i_index) const;
PRBool IsOffline(void) const;
nsMemModule* GetMemModule() const;
nsDiskModule* GetDiskModule() const;
void Offline(PRBool bSet);
PRBool IsOffline(void) const;
const char* Trace() const;
void Offline(PRBool bSet);
PRBool Remove(const char* i_url);
const char* Trace() const;
/* Performance measure- microseconds */
PRUint32 WorstCaseTime(void) const;
PRUint32 WorstCaseTime(void) const;
protected:
void Init();
nsCacheModule*
LastModule() const;
PRBool ContainsExactly(const char* i_url) const;
void Init();
nsCacheModule* LastModule() const;
//PRBool Lock(void);
//void Unlock(void);
/*
class MgrMonitor
{
public:
MgrMonitor() { nsCacheManager::GetInstance()->Lock();}
~MgrMonitor() { nsCacheManager::GetInstance()->Unlock();}
};
friend MgrMonitor;
*/
private:
nsCacheModule* m_pFirstModule;
nsCacheModule* m_pFirstModule;
PRMonitor* m_pMonitor;
nsCacheManager(const nsCacheManager& cm);
nsCacheManager& operator=(const nsCacheManager& cm);
@ -97,8 +117,8 @@ private:
inline
nsDiskModule* nsCacheManager::GetDiskModule() const
{
PR_ASSERT(m_pFirstModule && m_pFirstModule->Next());
return (m_pFirstModule) ? (nsDiskModule*) m_pFirstModule->Next() : NULL;
PR_ASSERT(m_pFirstModule && m_pFirstModule->NextModule());
return (m_pFirstModule) ? (nsDiskModule*) m_pFirstModule->NextModule() : NULL;
}
inline
@ -114,10 +134,35 @@ PRBool nsCacheManager::IsOffline(void) const
return m_bOffline;
}
/*
inline
PRBool nsCacheManager::Lock(void)
{
if (!m_pMonitor)
{
m_pMonitor = PR_NewMonitor();
if (!m_pMonitor)
return PR_FALSE;
}
PR_EnterMonitor(m_pMonitor);
return PR_TRUE;
}
*/
inline
void nsCacheManager::Offline(PRBool i_bSet)
{
m_bOffline = i_bSet;
}
/*
inline
void nsCacheManager::Unlock(void)
{
PR_ASSERT(m_pMonitor);
if (m_pMonitor)
PR_ExitMonitor(m_pMonitor);
}
*/
#endif

39
network/cache/nu/public/nsCacheModule.h поставляемый
Просмотреть файл

@ -28,8 +28,9 @@
//#include <nsISupports.h>
#include "nsCacheObject.h"
#include "nsEnumeration.h"
#include "nsMonitorable.h"
/* Why the hell is forward decl. not working? */
/* Why in the world is forward decl. not working? */
//class nsCacheObject;
/*
@ -39,7 +40,7 @@ static const NS_CACHEMODULE_ID =
*/
class nsCacheIterator;
class nsCacheModule /*: public nsISupports */
class nsCacheModule : public nsMonitorable /*: public nsISupports */
{
public:
@ -61,6 +62,7 @@ public:
const PRUint32 Entries(void) const;
nsEnumeration* Enumeration(void) const;
/* Enumerations wiht a function pointer - TODO */
//TODO move to own interface for both Garbage Collection and Revalidation
virtual
@ -77,8 +79,11 @@ public:
/* Cant do additions, deletions, validations, expirations */
PRBool IsReadOnly(void) const;
nsCacheModule* Next(void) const;
void Next(nsCacheModule*);
nsCacheModule* NextModule(void) const;
void NextModule(nsCacheModule*);
virtual
PRUint32 Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len);
virtual
PRBool Remove(const char* i_url) = 0;
@ -93,14 +98,22 @@ public:
PRBool Revalidate(void) = 0;
const PRUint32 Size(void) const;
void Size(const PRUint32 i_size);
virtual
void SetSize(const PRUint32 i_size);
PRUint32 SizeInUse(void) const;
const char* Trace(void) const;
virtual
PRUint32 Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len);
protected:
virtual
PRBool ReduceSizeTo(const PRUint32 i_NewSize);
PRUint32 m_Entries;
PRUint32 m_Size;
PRUint32 m_SizeInUse;
@ -112,7 +125,6 @@ protected:
private:
nsCacheModule(const nsCacheModule& cm);
nsCacheModule& operator=(const nsCacheModule& cm);
};
inline void nsCacheModule::Enable(PRBool i_Enable)
@ -128,6 +140,7 @@ inline const PRUint32 nsCacheModule::Entries() const
inline
nsEnumeration* nsCacheModule::Enumeration(void) const
{
MonitorLocker ml((nsMonitorable*)this);
if (!m_pEnumeration)
{
PR_ASSERT(m_pIterator);
@ -148,13 +161,21 @@ inline PRBool nsCacheModule::IsReadOnly(void) const
return PR_FALSE;
}
inline nsCacheModule* nsCacheModule::Next(void) const
inline nsCacheModule* nsCacheModule::NextModule(void) const
{
return m_pNext;
}
inline void nsCacheModule::Next(nsCacheModule* pNext)
inline void nsCacheModule::NextModule(nsCacheModule* pNext)
{
/* No overwriting */
PR_ASSERT(m_pNext == 0);
if (m_pNext)
{
/* ERROR */
delete m_pNext; //Worst case.
}
m_pNext = pNext;
}
@ -163,7 +184,7 @@ inline const PRUint32 nsCacheModule::Size() const
return m_Size;
}
inline void nsCacheModule::Size(const PRUint32 size)
inline void nsCacheModule::SetSize(const PRUint32 size)
{
m_Size = size;
}

210
network/cache/nu/public/nsCacheObject.h поставляемый
Просмотреть файл

@ -23,8 +23,8 @@
#include "nsISupports.h"
#endif
#include <prtypes.h>
#include <prinrval.h>
#include "prtypes.h"
#include "prinrval.h"
static const PRUint32 kCACHE_VERSION = 5;
@ -53,140 +53,230 @@ public:
*/
void Address(const char* i_url);
const char* Address(void) const;
void Address(const char* i_url);
const char* Address(void) const;
void Etag(const char* i_etag);
const char* Etag(void) const;
void Charset(const char* i_Charset);
const char* Charset(void) const;
PRIntervalTime
Expires(void) const;
void Expires(PRIntervalTime i_Expires);
void ContentEncoding(const char* i_Encoding);
const char* ContentEncoding(void) const;
PRUint16 Hits(void) const;
void ContentLength(PRUint32 i_len);
PRUint32 ContentLength(void) const;
void ContentType(const char* i_Type);
const char* ContentType(void) const;
void Etag(const char* i_etag);
const char* Etag(void) const;
void Expires(PRIntervalTime i_Expires);
PRIntervalTime Expires(void) const;
void Filename(const char* i_Filename);
const char* Filename(void) const;
PRUint16 Hits(void) const;
/* Read and write info about this cache object */
void* Info(void) const;
PRBool Info(void*);
void* Info(void) const;
PRBool Info(void* /*, PRUint32 len */);
PRUint32 InfoSize(void) const;
PRUint32 InfoSize(void) const;
PRBool IsExpired(void) const;
PRBool IsExpired(void) const;
PRBool IsPartial(void) const;
PRBool IsPartial(void) const;
PRIntervalTime
LastAccessed(void) const;
PRIntervalTime LastAccessed(void) const;
PRIntervalTime
LastModified(void) const;
void LastModified(PRIntervalTime i_lastModified);
PRIntervalTime LastModified(void) const;
void LastModified(const PRIntervalTime i_lastModified);
PRInt16 Module(void) const;
void Module(PRUint16 i_m);
PRInt16 Module(void) const;
void Module(PRUint16 i_m);
const char* PostData(void) const;
void PostData(const char* i_data, PRUint32 i_Len);
void PageServicesURL(const char* i_Url);
const char* PageServicesURL(void) const;
PRUint32 Size(void) const;
void Size(PRUint32 s);
const char* PostData(void) const;
void PostData(const char* i_data, const PRUint32 i_Len);
const char*
Trace() const;
PRUint32 PostDataLen(void) const;
// virtual void getReadStream();
// virtual void getWriteStream();
PRUint32 Read(char* o_Buffer, PRUint32 len);
PRUint32 Size(void) const;
void Size(PRUint32 i_Size);
const char* Trace() const;
PRUint32 Write(const char* i_Buffer, const PRUint32 len);
protected:
void Init();
void Init();
char* m_Etag;
PRIntervalTime
m_Expires;
int m_Flags;
PRUint16 m_Hits;
PRIntervalTime
m_LastAccessed, m_LastModified;
PRUint32 m_Size;
char* m_Url;
PRInt16 m_Module;
void* m_pInfo;
PRUint32 m_info_size;
char* m_Charset;
char* m_ContentEncoding;
PRUint32 m_ContentLength;
char* m_ContentType;
char* m_Etag;
PRIntervalTime m_Expires;
int m_Flags;
char* m_Filename;
PRUint16 m_Hits;
PRUint32 m_info_size;
PRIntervalTime m_LastAccessed, m_LastModified;
void* m_pInfo;
char* m_PageServicesURL;
char* m_PostData;
PRUint32 m_PostDataLen;
PRInt16 m_Module;
PRUint32 m_Size;
char* m_URL;
private:
nsCacheObject& operator=(const nsCacheObject& x);
};
inline const char* nsCacheObject::Address(void) const
inline
const char* nsCacheObject::Address(void) const
{
return m_Url;
return m_URL;
};
inline const char* nsCacheObject::Etag(void) const
inline
const char* nsCacheObject::Charset(void) const
{
return m_Charset;
}
inline
const char* nsCacheObject::ContentEncoding(void) const
{
return m_ContentEncoding;
}
inline
PRUint32 nsCacheObject::ContentLength(void) const
{
return m_ContentLength;
};
inline
void nsCacheObject::ContentLength(PRUint32 i_Size)
{
m_ContentLength = i_Size;
};
inline
const char* nsCacheObject::ContentType(void) const
{
return m_ContentType;
};
inline
const char* nsCacheObject::Etag(void) const
{
return m_Etag;
};
inline PRIntervalTime nsCacheObject::Expires(void) const
inline
PRIntervalTime nsCacheObject::Expires(void) const
{
return m_Expires;
};
inline void nsCacheObject::Expires(PRIntervalTime i_Expires)
inline
void nsCacheObject::Expires(PRIntervalTime i_Expires)
{
m_Expires = i_Expires;
};
inline PRUint16 nsCacheObject::Hits(void) const
inline
const char* nsCacheObject::Filename(void) const
{
return m_Filename;
}
inline
PRUint16 nsCacheObject::Hits(void) const
{
return m_Hits;
};
inline PRBool nsCacheObject::IsExpired(void) const
inline
PRBool nsCacheObject::IsExpired(void) const
{
PRIntervalTime now = PR_IntervalNow();
return (m_Expires <= now);
};
inline PRBool nsCacheObject::IsPartial(void) const
inline
PRBool nsCacheObject::IsPartial(void) const
{
return (m_Flags & nsCacheObject::PARTIAL);
};
inline PRIntervalTime nsCacheObject::LastAccessed(void) const
inline
PRIntervalTime nsCacheObject::LastAccessed(void) const
{
return m_LastAccessed;
};
inline PRIntervalTime nsCacheObject::LastModified(void) const
inline
PRIntervalTime nsCacheObject::LastModified(void) const
{
return m_LastModified;
};
inline void nsCacheObject::LastModified(PRIntervalTime i_LastModified)
inline
void nsCacheObject::LastModified(const PRIntervalTime i_LastModified)
{
m_LastModified = i_LastModified;
};
inline PRInt16 nsCacheObject::Module(void) const
inline
PRInt16 nsCacheObject::Module(void) const
{
return m_Module;
};
inline void nsCacheObject::Module(PRUint16 i_Module)
inline
void nsCacheObject::Module(PRUint16 i_Module)
{
m_Module = i_Module;
};
inline PRUint32 nsCacheObject::Size(void) const
inline
const char* nsCacheObject::PageServicesURL(void) const
{
return m_PageServicesURL;
}
inline
const char* nsCacheObject::PostData(void) const
{
return m_PostData;
}
inline
PRUint32 nsCacheObject::PostDataLen(void) const
{
return m_PostDataLen;
}
inline
PRUint32 nsCacheObject::Size(void) const
{
return m_Size;
};
inline void nsCacheObject::Size(PRUint32 i_Size)
inline
void nsCacheObject::Size(PRUint32 i_Size)
{
m_Size = i_Size;
};

23
network/cache/nu/public/nsCachePref.h поставляемый
Просмотреть файл

@ -20,7 +20,7 @@
#define nsCachePref_h__
//#include "nsISupports.h"
#include <prtypes.h>
#include "prtypes.h"
class nsCachePref //: public nsISupports
{
@ -38,24 +38,27 @@ public:
ALWAYS
} r;
static const PRUint32 BkgSleepTime(void);
const PRUint32 BkgSleepTime(void);
static const char* DiskCacheDBFilename(void); /* like Fat.db */
static const char* DiskCacheFolder(void); /* Cache dir */
const char* DiskCacheDBFilename(void); /* like Fat.db */
const char* DiskCacheFolder(void); /* Cache dir */
static PRBool DiskCacheSSL(void);
static void DiskCacheSSL(PRBool bSet);
PRBool DiskCacheSSL(void);
void DiskCacheSSL(PRBool bSet);
static PRUint32 DiskCacheSize(void);
static PRUint32 MemCacheSize(void);
PRUint32 DiskCacheSize(void);
void DiskCacheSize(const PRUint32 i_Size);
static nsCachePref::Refresh
PRUint32 MemCacheSize(void);
void MemCacheSize(const PRUint32 i_Size);
nsCachePref::Refresh
Frequency(void);
/* Revalidating in background, makes IMS calls in the bkg thread to
update cache entries. TODO, this should be at a bigger time period
than the cache cleanup routine */
static PRBool RevalidateInBkg(void);
PRBool RevalidateInBkg(void);
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,

13
network/cache/nu/public/nsDiskModule.h поставляемый
Просмотреть файл

@ -32,7 +32,7 @@ class nsDiskModule : public nsCacheModule
{
public:
nsDiskModule(const PRUint32 size = nsCachePref::DiskCacheSize());
nsDiskModule(const PRUint32 size = nsCachePref::GetInstance()->DiskCacheSize());
~nsDiskModule();
// Cache module interface
@ -46,11 +46,20 @@ public:
nsCacheObject* GetObject(const PRUint32 i_index) const;
nsCacheObject* GetObject(const char* i_url) const;
PRUint32 Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len);
PRBool ReduceSizeTo(const PRUint32 i_NewSize);
PRBool Remove(const char* i_url);
PRBool Remove(const PRUint32 i_index);
// To do cleanup set size to zero. Else initialize disk cache
void SetSize(const PRUint32 i_size);
PRBool Revalidate(void);
PRUint32 Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len);
private:
enum sync_frequency
{

5
network/cache/nu/public/nsEnumeration.h поставляемый
Просмотреть файл

@ -55,6 +55,11 @@ nsEnumeration::nsEnumeration(nsIterator* iter):m_pIter(iter)
m_pIter->First();
}
inline
nsEnumeration::~nsEnumeration()
{
}
inline
PRBool nsEnumeration::HasMoreElements(void)
{

2
network/cache/nu/public/nsHash.h поставляемый
Просмотреть файл

@ -19,7 +19,7 @@
#ifndef nsHash_h__
#define nsHash_h__
#include <plhash.h>
#include "plhash.h"
class nsHashKey {
protected:

5
network/cache/nu/public/nsIterator.h поставляемый
Просмотреть файл

@ -58,5 +58,10 @@ void nsIterator::Next(void)
++m_Index;
}
inline
void* nsIterator::CurrentItem(void) const
{
return 0;
}
#endif // nsIterator_h__

30
network/cache/nu/public/nsMemCacheObject.h поставляемый
Просмотреть файл

@ -19,7 +19,7 @@
#ifndef _nsMemCacheObject_h_
#define _nsMemCacheObject_h_
#include <prtypes.h>
#include "prtypes.h"
#include "nsCacheObject.h"
@ -29,45 +29,45 @@ public:
nsMemCacheObject(void);
nsMemCacheObject(nsCacheObject* io_pObject);
nsMemCacheObject(const char* i_url);
~nsMemCacheObject();
nsMemCacheObject(const char* i_url);
~nsMemCacheObject();
void* Data(void) const;
void Next(nsMemCacheObject* pObject);
void Next(nsCacheObject* io_pObject);
nsMemCacheObject* Next(void) const;
nsCacheObject* ThisObject(void) const;
private:
nsMemCacheObject* m_pNextObject;
nsMemCacheObject* m_pNextObject;
nsCacheObject* m_pObject;
void* m_pData;
void* m_pData;
nsMemCacheObject& operator=(const nsMemCacheObject& mco);
nsMemCacheObject(const nsMemCacheObject&);
nsMemCacheObject& operator=(const nsMemCacheObject& mco);
nsMemCacheObject(const nsMemCacheObject&);
};
inline nsMemCacheObject::nsMemCacheObject(void):
m_pObject(new nsCacheObject()),
m_pNextObject(0),
m_pObject(new nsCacheObject()),
m_pNextObject(0),
m_pData(0)
{
}
inline nsMemCacheObject::nsMemCacheObject(nsCacheObject* io_pObject):
m_pObject(io_pObject),
m_pNextObject(0),
m_pObject(io_pObject),
m_pNextObject(0),
m_pData(0)
{
}
inline nsMemCacheObject::nsMemCacheObject(const char* i_url):
m_pObject(new nsCacheObject(i_url)),
m_pNextObject(0),
m_pObject(new nsCacheObject(i_url)),
m_pNextObject(0),
m_pData(0)
{
}

12
network/cache/nu/public/nsMemModule.h поставляемый
Просмотреть файл

@ -31,7 +31,7 @@
//#include "nsHash.h" // TODO - replace with nsHashtable when the XPCOM_BRANCH merges
//#include <nsHashtable.h>
//#include "nsHashtable.h"
/*
// {5D51B250-E6C2-11d1-AFE5-006097BFC036}
static const NS_MEMMODULE_IID =
@ -42,7 +42,7 @@ class nsMemModule : public nsCacheModule
{
public:
nsMemModule(const PRUint32 size=nsCachePref::MemCacheSize());
nsMemModule(const PRUint32 size=nsCachePref::GetInstance()->MemCacheSize());
~nsMemModule();
/*
@ -62,11 +62,19 @@ public:
nsCacheObject* GetObject(const PRUint32 i_index) const;
nsCacheObject* GetObject(const char* i_url) const;
PRUint32 Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len);
PRBool ReduceSizeTo(const PRUint32 i_NewSize);
PRBool Remove(const char* i_url);
PRBool Remove(const PRUint32 i_index);
// PRBool RemoveAll(void);
PRBool Revalidate(void);
PRUint32 Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len);
// Start of nsMemModule specific stuff...
// Here is a sample implementation using linked list
protected:

106
network/cache/nu/public/nsMonitorable.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,106 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsMonitorable_h__
#define nsMonitorable_h__
//#include "nsISupports.h"
#include "prmon.h"
class nsMonitorable//: public nsISupports
{
public:
nsMonitorable();
virtual ~nsMonitorable();
/*
NS_IMETHOD QueryInterface(const nsIID& aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
*/
PRBool Lock(void);
void Unlock(void);
protected:
class MonitorLocker
{
public:
MonitorLocker(nsMonitorable* i_pThis):
m_pMonitorable(i_pThis)
{
if (m_pMonitorable) m_pMonitorable->Lock();
}
~MonitorLocker()
{
if (m_pMonitorable) m_pMonitorable->Unlock();
}
private:
nsMonitorable* m_pMonitorable;
};
PRMonitor* m_pMonitor;
private:
nsMonitorable(const nsMonitorable& o);
nsMonitorable& operator=(const nsMonitorable& o);
};
inline
nsMonitorable::nsMonitorable(void):m_pMonitor(PR_NewMonitor())
{
}
inline
nsMonitorable::~nsMonitorable()
{
if (m_pMonitor)
{
PR_DestroyMonitor(m_pMonitor);
m_pMonitor = 0;
}
}
inline
PRBool nsMonitorable::Lock(void)
{
if (!m_pMonitor)
{
m_pMonitor = PR_NewMonitor();
if (!m_pMonitor)
return PR_FALSE;
}
PR_EnterMonitor(m_pMonitor);
return PR_TRUE;
}
inline
void nsMonitorable::Unlock(void)
{
PR_ASSERT(m_pMonitor);
if (m_pMonitor)
PR_ExitMonitor(m_pMonitor);
}
#endif // nsMonitorable_h__

259
network/cache/nu/src/CacheStubs.cpp поставляемый
Просмотреть файл

@ -24,44 +24,64 @@
#include "nsDiskModule.h"
#include "nsMemModule.h"
#include "nsCacheTrace.h"
#include "prlog.h"
#define CM nsCacheManager::GetInstance()
#define CACHEMGR nsCacheManager::GetInstance()
void
Cache_Init(void)
{
/* Most of the initilization gets done in the constructor for the
* nsCacheManager class. */
}
void
Cache_Shutdown(void)
{
/* todo- Should the destructor for nsCacheManager object be forced here?*/
}
/* CacheManager functions */
PRBool
CacheManager_Contains(const char* i_url)
{
return CM->Entries();
return CACHEMGR->Contains(i_url);
}
PRUint32
PRInt16
CacheManager_Entries()
{
return CM->Entries();
return CACHEMGR->Entries();
}
void*
CacheManager_GetObject(const char* i_url)
{
return CM->GetObject(i_url);
return CACHEMGR->GetObj(i_url);
}
PRBool
CacheManager_IsOffline(void)
{
return CM->IsOffline();
return CACHEMGR->IsOffline();
}
void
CacheManager_Offline(PRBool bSet)
{
CM->Offline(bSet);
CACHEMGR->Offline(bSet);
}
PRBool
CacheManager_Remove(const char* i_url)
{
return CACHEMGR->Remove(i_url);
}
PRUint32
CacheManager_WorstCaseTime(void)
{
return CM->WorstCaseTime();
return CACHEMGR->WorstCaseTime();
}
/* CacheObject functions */
@ -77,6 +97,30 @@ CacheObject_GetAddress(const void* pThis)
return pThis ? ((nsCacheObject*)pThis)->Address() : 0;
}
const char*
CacheObject_GetCharset(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Charset() : 0;
}
const char*
CacheObject_GetContentEncoding(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->ContentEncoding() : 0;
}
PRUint32
CacheObject_GetContentLength(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->ContentLength() : 0;
}
const char*
CacheObject_GetContentType(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->ContentType() : 0;
}
const char*
CacheObject_GetEtag(const void* pThis)
{
@ -89,6 +133,12 @@ CacheObject_GetExpires(const void* pThis)
return pThis ? ((nsCacheObject*)pThis)->Expires() : 0;
}
const char*
CacheObject_GetFilename(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Filename() : 0;
}
PRIntervalTime
CacheObject_GetLastAccessed(const void* pThis)
{
@ -101,6 +151,30 @@ CacheObject_GetLastModified(const void* pThis)
return pThis ? ((nsCacheObject*)pThis)->LastModified() : 0;
}
PRInt16
CacheObject_GetModule(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->Module() : -1;
}
const char*
CacheObject_GetPageServicesURL(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->PageServicesURL() : 0;
}
const char*
CacheObject_GetPostData(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->PostData() : 0;
}
PRUint32
CacheObject_GetPostDataLen(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->PostDataLen() : 0;
}
PRUint32
CacheObject_GetSize(const void* pThis)
{
@ -119,53 +193,125 @@ CacheObject_IsExpired(const void* pThis)
return pThis ? ((nsCacheObject*)pThis)->IsExpired() : PR_FALSE;
}
PRBool
CacheObject_IsPartial(const void* pThis)
{
return pThis ? ((nsCacheObject*)pThis)->IsPartial() : PR_FALSE;
}
PRUint32
CacheObject_Read(const void* pThis, char* o_Buffer, PRUint32 i_Len)
{
return pThis ? ((nsCacheObject*)pThis)->Read(o_Buffer, i_Len) : 0;
}
void
CacheObject_SetAddress(void* pThis, const char* i_Address)
{
if (pThis)
{
((nsCacheObject*)pThis)->Address(i_Address);
}
}
void
CacheObject_SetCharset(void* pThis, const char* i_Charset)
{
if (pThis)
((nsCacheObject*)pThis)->Charset(i_Charset);
}
void
CacheObject_SetContentEncoding(void* pThis, const char* i_Encoding)
{
if (pThis)
((nsCacheObject*)pThis)->ContentEncoding(i_Encoding);
}
void
CacheObject_SetContentLength(void* pThis, PRUint32 i_ContentLen)
{
if (pThis)
((nsCacheObject*)pThis)->ContentLength(i_ContentLen);
}
void
CacheObject_SetContentType(void* pThis, const char* i_ContentType)
{
if (pThis)
((nsCacheObject*)pThis)->ContentType(i_ContentType);
}
void
CacheObject_SetEtag(void* pThis, const char* i_Etag)
{
if (pThis)
{
((nsCacheObject*)pThis)->Etag(i_Etag);
}
}
void
CacheObject_SetExpires(void *pThis, const PRIntervalTime i_Time)
{
if (pThis)
{
((nsCacheObject*)pThis)->Expires(i_Time);
}
}
void
CacheObject_SetFilename(void* pThis, const char* i_Filename)
{
if (pThis)
((nsCacheObject*)pThis)->Filename(i_Filename);
}
void
CacheObject_SetLastModified(void* pThis, const PRIntervalTime i_Time)
{
if (pThis)
{
((nsCacheObject*)pThis)->LastModified(i_Time);
}
((nsCacheObject*)pThis)->LastModified(i_Time);
}
void
CacheObject_SetModule(void* pThis, const PRInt16 i_Module)
{
if (pThis)
((nsCacheObject*)pThis)->Module(i_Module);
}
void
CacheObject_SetPageServicesURL(void* pThis, const char* i_Url)
{
if (pThis)
((nsCacheObject*)pThis)->PageServicesURL(i_Url);
}
void
CacheObject_SetPostData(void* pThis, const char* i_PostData, const PRUint32 i_Len)
{
if (pThis)
((nsCacheObject*)pThis)->PostData(i_PostData, i_Len);
}
void
CacheObject_SetSize(void* pThis, const PRUint32 i_Size)
{
if (pThis)
{
((nsCacheObject*)pThis)->Size(i_Size);
}
PRBool
CacheObject_Synch(void* pThis)
{
if (pThis)
{
nsCacheObject* pObj = (nsCacheObject*) pThis;
PRBool bStatus = CACHEMGR->GetModule(pObj->Module())->AddObject(pObj);
return bStatus;
}
return PR_FALSE;
}
PRUint32
CacheObject_Write(void* pThis, const char* i_buffer, const PRUint32 i_length)
{
return i_length;
}
void
@ -176,32 +322,43 @@ CacheObject_Destroy(void* pThis)
((nsCacheObject*)pThis)->~nsCacheObject();
pThis = 0;
}
}
/* CachePref functions */
PRUint32
CachePref_DiskCacheSize(void)
CachePref_GetDiskCacheSize(void)
{
return nsCachePref::DiskCacheSize();
return nsCachePref::GetInstance()->DiskCacheSize();
}
PRBool
CachePref_GetDiskCacheSSL(void)
{
return nsCachePref::DiskCacheSSL();
return nsCachePref::GetInstance()->DiskCacheSSL();
}
PRUint32
CachePref_MemCacheSize(void)
CachePref_GetMemCacheSize(void)
{
return nsCachePref::MemCacheSize();
return nsCachePref::GetInstance()->MemCacheSize();
}
void
CachePref_SetDiskCacheSize(const PRUint32 i_Size)
{
nsCachePref::GetInstance()->DiskCacheSize(i_Size);
}
void
CachePref_SetDiskCacheSSL(PRBool bSet)
{
nsCachePref::DiskCacheSSL(bSet);
nsCachePref::GetInstance()->DiskCacheSSL(bSet);
}
void
CachePref_SetMemCacheSize(const PRUint32 i_Size)
{
nsCachePref::GetInstance()->MemCacheSize(i_Size);
}
/* CacheTrace functions */
@ -218,115 +375,119 @@ CacheTrace_IsEnabled(void)
}
/* DiskModule functions */
#define DM nsCacheManager::GetInstance()->GetDiskModule()
#define DISKMOD nsCacheManager::GetInstance()->GetDiskModule()
PRBool
DiskModule_AddObject(void* pObject)
{
return DM->AddObject((nsCacheObject*)pObject);
return DISKMOD->AddObject((nsCacheObject*)pObject);
}
PRBool
DiskModule_Contains(const char* i_url)
{
return DM->Contains(i_url);
return DISKMOD->Contains(i_url);
}
PRUint32
DiskModule_Entries(void)
{
return DM->Entries();
return DISKMOD->Entries();
}
PRUint32
DiskModule_GetSize(void)
{
return DM->Size();
return DISKMOD->Size();
}
PRUint32
DiskModule_GetSizeInUse(void)
{
return DM->SizeInUse();
return DISKMOD->SizeInUse();
}
PRBool
DiskModule_IsEnabled(void)
{
return DM->IsEnabled();
return DISKMOD->IsEnabled();
}
PRBool
DiskModule_Remove(const char* i_url)
{
return DM->Remove(i_url);
return DISKMOD->Remove(i_url);
}
PRBool
DiskModule_RemoveAll(void)
{
return DM->RemoveAll();
return DISKMOD->RemoveAll();
}
void
DiskModule_SetSize(PRUint32 i_Size)
{
DM->Size(i_Size);
DISKMOD->SetSize(i_Size);
}
/* MemModule functions */
#define MM nsCacheManager::GetInstance()->GetMemModule()
#define MEMMOD nsCacheManager::GetInstance()->GetMemModule()
PRBool
MemModule_AddObject(void* pObject)
{
return MM->AddObject((nsCacheObject*)pObject);
return MEMMOD->AddObject((nsCacheObject*)pObject);
}
PRBool
MemModule_Contains(const char* i_url)
{
return MM->Contains(i_url);
return MEMMOD->Contains(i_url);
}
PRUint32
MemModule_Entries(void)
{
return MM->Entries();
return MEMMOD->Entries();
}
PRUint32
MemModule_GetSize(void)
{
return MM->Size();
return MEMMOD->Size();
}
PRUint32
MemModule_GetSizeInUse(void)
{
return MM->SizeInUse() ;
return MEMMOD->SizeInUse() ;
}
PRBool
MemModule_IsEnabled(void)
{
return MM->IsEnabled();
return MEMMOD->IsEnabled();
}
PRBool
MemModule_Remove(const char* i_url)
{
return MM->Remove(i_url);
return MEMMOD->Remove(i_url);
}
PRBool
MemModule_RemoveAll(void)
{
return MM->RemoveAll();
return MEMMOD->RemoveAll();
}
void
MemModule_SetSize(PRUint32 i_Size)
{
MM->Size(i_Size);
MEMMOD->SetSize(i_Size);
}
#undef MEMMOD
#undef DISKMOD
#undef CACHEMGR

11
network/cache/nu/src/Makefile поставляемый
Просмотреть файл

@ -23,6 +23,8 @@ LIBRARY_NAME=cachelib
MISCDEP = \
$(LIBNSPR) \
$(DIST)/lib/dbm32.lib \
$(DIST)/lib/libplc21.lib \
$(DIST)/lib/xpcom32.lib \
$(NULL)
@ -36,13 +38,18 @@ CPPSRCS = nsCacheObject.cpp \
nsCacheTrace.cpp \
nsCachePref.cpp \
nsMemCacheObject.cpp \
nsBkgThread.cpp \
nsCacheBkgThd.cpp \
CacheStubs.cpp \
$(NULL)
REQUIRES = dbm nspr pref xpcom
LLIBS = \
$(DIST)/lib/xpcom32.lib \
$(LIBNSPR) \
$(DIST)/lib/dbm32.lib \
$(DIST)/lib/libplc21.lib \
$(DIST)/lib/xpcom32.lib \
$(LIBNSPR) \
$(NULL)
include $(DEPTH)/config/rules.mk

2
network/cache/nu/src/nsBkgThread.cpp поставляемый
Просмотреть файл

@ -17,7 +17,7 @@
*/
#include "nsBkgThread.h"
#include <prlog.h>
#include "prlog.h"
static void PR_CALLBACK RunFunction(void* arg);

6
network/cache/nu/src/nsCacheBkgThd.cpp поставляемый
Просмотреть файл

@ -16,7 +16,7 @@
* Reserved.
*/
#include <prlog.h>
#include "prlog.h"
#include "nsCacheBkgThd.h"
#include "nsCacheManager.h"
#include "nsCacheModule.h"
@ -60,7 +60,7 @@ void nsCacheBkgThd::Run(void)
PR_ASSERT(pCM);
if (pCM->IsOffline())
return; /* Dont update entries if offline */
PRUint32 i = pCM->Entries();
PRInt16 i = pCM->Entries();
while (i>0)
{
nsCacheModule* pModule = pCM->GetModule(--i);
@ -69,7 +69,7 @@ void nsCacheBkgThd::Run(void)
if (!pModule->IsReadOnly())
{
pModule->GarbageCollect();
if (nsCachePref::RevalidateInBkg())
if (nsCachePref::GetInstance()->RevalidateInBkg())
{
pModule->Revalidate();
}

111
network/cache/nu/src/nsCacheManager.cpp поставляемый
Просмотреть файл

@ -21,12 +21,8 @@
*
*/
#include <prtypes.h>
#include <prinrval.h>
#include <xp_core.h>
#include <xpassert.h>
#include <xp_str.h>
#include "prtypes.h"
#include "prinrval.h"
#include "nsCacheManager.h"
#include "nsCacheTrace.h"
@ -36,6 +32,7 @@
#include "nsDiskModule.h"
#include "nsCacheBkgThd.h"
/* TODO move this to InitNetLib */
static nsCacheManager TheManager;
nsCacheManager::nsCacheManager(): m_pFirstModule(0), m_bOffline(PR_FALSE)
@ -49,9 +46,13 @@ nsCacheManager::~nsCacheManager()
{
m_pBkgThd->Stop();
delete m_pBkgThd;
m_pBkgThd = 0;
}
if (m_pFirstModule)
{
delete m_pFirstModule;
m_pFirstModule = 0;
}
}
nsCacheManager*
@ -60,6 +61,7 @@ nsCacheManager::GetInstance()
return &TheManager;
}
#if 0
/* Caller must free returned char* */
const char*
nsCacheManager::Trace() const
@ -74,18 +76,20 @@ nsCacheManager::Trace() const
strcpy(total, linebuffer);
return total;
}
#endif
PRInt32
nsCacheManager::AddModule(nsCacheModule* pModule)
{
MonitorLocker ml(this);
if (pModule)
{
if (m_pFirstModule)
LastModule()->Next(pModule);
else
m_pFirstModule = pModule;
if (m_pFirstModule)
LastModule()->NextModule(pModule);
else
m_pFirstModule = pModule;
return Entries()-1;
return Entries()-1;
}
else
return -1;
@ -93,6 +97,24 @@ nsCacheManager::AddModule(nsCacheModule* pModule)
PRBool
nsCacheManager::Contains(const char* i_url) const
{
MonitorLocker ml((nsMonitorable*)this);
// Add logic to check for IMAP type URLs, byteranges, and search with / appended as well...
// TODO
PRBool bStatus = ContainsExactly(i_url);
if (!bStatus)
{
// try alternate stuff
/*
char* extraBytes;
char extraBytesSeparator;
*/
}
return bStatus;
}
PRBool
nsCacheManager::ContainsExactly(const char* i_url) const
{
if (m_pFirstModule)
{
@ -103,15 +125,16 @@ nsCacheManager::Contains(const char* i_url) const
{
return PR_TRUE;
}
pModule = pModule->Next();
pModule = pModule->NextModule();
}
}
return PR_FALSE;
}
nsCacheObject*
nsCacheManager::GetObject(const char* i_url) const
nsCacheManager::GetObj(const char* i_url) const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
@ -121,20 +144,21 @@ nsCacheManager::GetObject(const char* i_url) const
obj = pModule->GetObject(i_url);
if (obj)
return obj;
pModule = pModule->Next();
pModule = pModule->NextModule();
}
}
return 0;
}
PRInt32
PRInt16
nsCacheManager::Entries() const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstModule)
{
PRInt32 count=1;
PRInt16 count=1;
nsCacheModule* pModule = m_pFirstModule;
while (pModule = pModule->Next())
while (pModule = pModule->NextModule())
{
count++;
}
@ -144,13 +168,14 @@ nsCacheManager::Entries() const
}
nsCacheModule*
nsCacheManager::GetModule(PRInt32 i_index) const
nsCacheManager::GetModule(PRInt16 i_index) const
{
MonitorLocker ml((nsMonitorable*)this);
if ((i_index < 0) || (i_index >= Entries()))
return 0;
nsCacheModule* pModule = m_pFirstModule;
PR_ASSERT(pModule);
for (PRInt32 i=0; i<i_index; pModule = pModule->Next())
for (PRInt16 i=0; i<i_index; pModule = pModule->NextModule())
{
i++;
PR_ASSERT(pModule);
@ -161,36 +186,64 @@ nsCacheManager::GetModule(PRInt32 i_index) const
void
nsCacheManager::Init()
{
MonitorLocker ml(this);
if (m_pFirstModule)
delete m_pFirstModule;
m_pFirstModule = new nsMemModule(nsCachePref::MemCacheSize());
m_pFirstModule = new nsMemModule(nsCachePref::GetInstance()->MemCacheSize());
PR_ASSERT(m_pFirstModule);
nsDiskModule* pTemp = new nsDiskModule(nsCachePref::DiskCacheSize());
PR_ASSERT(pTemp);
m_pFirstModule->Next(pTemp);
m_pBkgThd = new nsCacheBkgThd(PR_SecondsToInterval(nsCachePref::BkgSleepTime()));
PR_ASSERT(m_pBkgThd);
if (m_pFirstModule)
{
nsDiskModule* pTemp = new nsDiskModule(nsCachePref::GetInstance()->DiskCacheSize());
PR_ASSERT(pTemp);
m_pFirstModule->NextModule(pTemp);
m_pBkgThd = new nsCacheBkgThd(PR_SecondsToInterval(nsCachePref::GetInstance()->BkgSleepTime()));
PR_ASSERT(m_pBkgThd);
}
}
nsCacheModule*
nsCacheManager::LastModule() const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
while(pModule->Next()) {
pModule = pModule->Next();
while(pModule->NextModule()) {
pModule = pModule->NextModule();
}
return pModule;
}
return 0;
}
PRBool
nsCacheManager::Remove(const char* i_url)
{
MonitorLocker ml(this);
PRBool bStatus = PR_FALSE;
if (m_pFirstModule)
{
nsCacheModule* pModule = m_pFirstModule;
bStatus |= pModule->Remove(i_url);
if (bStatus)
return bStatus;
while(pModule->NextModule()) {
pModule = pModule->NextModule();
if (bStatus)
return bStatus;
}
}
return bStatus;
}
PRUint32
nsCacheManager::WorstCaseTime(void) const
{
PRIntervalTime start = PR_IntervalNow();
while (this->Contains("a vague string that should not be in any of the modules"));
if (this->Contains("a vague string that should not be in any of the modules"))
{
PR_ASSERT(0);
}
return PR_IntervalToMicroseconds(PR_IntervalNow() - start);
}
}

21
network/cache/nu/src/nsCacheModule.cpp поставляемый
Просмотреть файл

@ -16,9 +16,6 @@
* Reserved.
*/
#include <xp_core.h>
#include <xp_str.h>
#include "nsCacheModule.h"
#include "nsCacheTrace.h"
#include "nsCacheIterator.h"
@ -35,6 +32,7 @@
nsCacheModule::nsCacheModule(const PRUint32 i_size=DEFAULT_SIZE):
m_Size(i_size),
m_pEnumeration(0),
m_pNext(0),
m_Entries(0)
{
@ -64,8 +62,16 @@ void nsCacheModule::GarbageCollect(void)
{
}
PRBool nsCacheModule::ReduceSizeTo(const PRUint32 i_NewSize)
{
MonitorLocker ml(this);
//TODO
return PR_TRUE;
}
PRBool nsCacheModule::RemoveAll(void)
{
MonitorLocker ml(this);
PRBool status = PR_TRUE;
while (m_Entries > 0)
{
@ -74,15 +80,18 @@ PRBool nsCacheModule::RemoveAll(void)
return status;
}
#if 0
// Caller must free this
const char* nsCacheModule::Trace() const
{
char linebuffer[128];
char* total;
sprintf(linebuffer, "nsCacheModule: Objects = %d\n", Entries());
PR_sprintf(linebuffer, "nsCacheModule: Objects = %d\n", Entries());
total = new char[strlen(linebuffer) + 1];
total = new char[PR_strlen(linebuffer) + 1];
strcpy(total, linebuffer);
return total;
}
}
#endif

312
network/cache/nu/src/nsCacheObject.cpp поставляемый
Просмотреть файл

@ -15,17 +15,15 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <xp_core.h>
#include <xp_str.h>
#include <xpassert.h>
#include <prmem.h>
#include <prprf.h>
#include <plstr.h>
#include <memory.h>
#include "prmem.h"
#include "prprf.h"
#include "plstr.h"
#include "nsCacheObject.h"
#include "nsCacheTrace.h"
#include "nsCacheModule.h"
#include "nsCacheManager.h"
/*
* nsCacheObject
*
@ -35,10 +33,6 @@
static const PRIntervalTime DEFAULT_EXPIRES = PR_SecondsToInterval(86400);
// m_Etag, m_Expires, m_Flags, m_Hits, m_LastAccessed, m_LastModified, m_Module, m_Size, m_Url
#define READ_WRITE_FORMAT "%s,%d,%d,%d,%d,%d,%d,%d,%s"
#define READ_WRITE_ELEMENTS m_Etag,m_Expires,m_Flags,m_Hits,m_LastAccessed,m_LastModified,m_Module,m_Size,m_Url
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
ERROR! Must have a byte order
#endif
@ -107,7 +101,7 @@ ERROR! Must have a byte order
{ \
return PR_FALSE; \
} \
string = (char*)PR_Malloc(len); \
string = new char[len]; \
if(!string) \
{ \
return PR_FALSE; \
@ -144,32 +138,74 @@ ERROR! Must have a byte order
cur_ptr += sizeof(char); \
}
/* TODO- Further optimization, initialize these to null,
but that will add more work on copy constructor which is ok */
nsCacheObject::nsCacheObject():
m_Flags(INIT),
m_Url(new char[1]),
m_Charset(new char[1]),
m_ContentEncoding(new char[1]),
m_ContentType(new char[1]),
m_Etag(new char[1]),
m_Filename(new char[1]),
m_Flags(INIT),
m_Module(-1),
m_pInfo(0)
m_pInfo(0),
m_PageServicesURL(new char[1]),
m_PostData(new char[1]),
m_PostDataLen(0),
m_URL(new char[1])
{
Init();
*m_Url = '\0';
*m_Charset = '\0';
*m_ContentEncoding = '\0';
*m_ContentType = '\0';
*m_Etag = '\0';
*m_Filename = '\0';
*m_PageServicesURL = '\0';
*m_PostData = '\0';
*m_URL = '\0';
}
nsCacheObject::~nsCacheObject()
{
delete[] m_Url;
delete[] m_Etag;
if (m_Charset)
delete[] m_Charset;
if (m_ContentEncoding)
delete[] m_ContentEncoding;
if (m_ContentType)
delete[] m_ContentType;
if (m_Etag)
delete[] m_Etag;
if (m_Filename)
delete[] m_Filename;
if (m_PageServicesURL)
delete[] m_PageServicesURL;
if (m_PostData)
delete[] m_PostData;
if (m_URL)
delete[] m_URL;
}
nsCacheObject::nsCacheObject(const nsCacheObject& another):
m_Flags(another.m_Flags),
m_Url(new char[PL_strlen(another.m_Url)+1]),
m_Charset(new char[PL_strlen(another.m_Charset)+1]),
m_ContentEncoding(new char[PL_strlen(another.m_ContentEncoding)+1]),
m_ContentType(new char[PL_strlen(another.m_ContentType)+1]),
m_Etag(new char[PL_strlen(another.m_Etag)+1]),
m_pInfo(0)
m_Filename(new char[PL_strlen(another.m_Filename)+1]),
m_Flags(another.m_Flags),
m_PageServicesURL(new char[PL_strlen(another.m_PageServicesURL)+1]),
m_PostDataLen(another.m_PostDataLen),
m_PostData(new char[another.m_PostDataLen+1]),
m_URL(new char[PL_strlen(another.m_URL)+1]),
m_pInfo(0) /* Should this be copied as well? */
{
strcpy(m_Url, another.m_Url);
strcpy(m_Etag, another.m_Etag);
PL_strncpy(m_Charset, another.m_Charset, PL_strlen(another.m_Charset));
PL_strncpy(m_ContentEncoding, another.m_ContentEncoding, PL_strlen(another.m_ContentEncoding));
PL_strncpy(m_ContentType, another.m_ContentType, PL_strlen(another.m_ContentType));
PL_strncpy(m_Etag, another.m_Etag, PL_strlen(another.m_Etag));
PL_strncpy(m_Filename, another.m_Filename, PL_strlen(another.m_Filename));
PL_strncpy(m_PageServicesURL, another.m_PageServicesURL, PL_strlen(another.m_PageServicesURL));
PL_strncpy(m_PostData, another.m_PostData, another.m_PostDataLen);
PL_strncpy(m_URL, another.m_URL, PL_strlen(another.m_URL));
m_Hits = another.m_Hits;
m_LastAccessed = another.m_LastAccessed;
@ -179,34 +215,99 @@ nsCacheObject::nsCacheObject(const nsCacheObject& another):
}
nsCacheObject::nsCacheObject(const char* i_url):
m_Flags(INIT),
m_Url(new char[strlen(i_url)+1]),
m_Charset(new char[1]),
m_ContentEncoding(new char[1]),
m_ContentType(new char[1]),
m_Etag(new char[1]),
m_Filename(new char[1]),
m_Flags(INIT),
m_PageServicesURL(new char[1]),
m_PostData(new char[1]),
m_PostDataLen(0),
m_URL(new char[PL_strlen(i_url)+1]),
m_Module(-1),
m_pInfo(0)
{
Init();
PR_ASSERT(i_url);
strcpy(m_Url, i_url);
PL_strncpy(m_URL, i_url, PL_strlen(i_url));
*m_Charset = '\0';
*m_ContentEncoding = '\0';
*m_ContentType = '\0';
*m_Etag = '\0';
*m_Filename = '\0';
*m_PageServicesURL = '\0';
*m_PostData = '\0';
}
void nsCacheObject::Address(const char* i_url)
{
PR_ASSERT(i_url && *i_url);
if (m_Url)
delete[] m_Url;
m_Url = new char[strlen(i_url) + 1];
strcpy(m_Url, i_url);
if (!i_url)
return;
if (m_URL)
delete[] m_URL;
m_URL = new char[PL_strlen(i_url) + 1];
PL_strncpy(m_URL, i_url, PL_strlen(i_url));
}
void nsCacheObject::Charset(const char* i_Charset)
{
// PR_ASSERT(i_Charset && *i_Charset);
if (!i_Charset)
return;
if (m_Charset)
delete[] m_Charset;
m_URL = new char[PL_strlen(i_Charset) + 1];
PL_strncpy(m_Charset, i_Charset, PL_strlen(i_Charset));
}
void nsCacheObject::ContentEncoding(const char* i_Encoding)
{
// PR_ASSERT(i_Encoding && *i_Encoding);
if (!i_Encoding)
return;
if (m_ContentEncoding)
delete[] m_ContentEncoding;
m_ContentEncoding = new char[PL_strlen(i_Encoding) + 1];
PL_strncpy(m_ContentEncoding, i_Encoding, PL_strlen(i_Encoding));
}
void nsCacheObject::ContentType(const char* i_Type)
{
// PR_ASSERT(i_Type && *i_Type);
if (!i_Type)
{
/* Reset to empty */ // TODO ??
return;
}
if (m_ContentType)
delete[] m_ContentType;
m_ContentType = new char[PL_strlen(i_Type) + 1];
PL_strncpy(m_ContentType, i_Type, PL_strlen(i_Type));
}
void nsCacheObject::Etag(const char* i_etag)
{
PR_ASSERT(i_etag && *i_etag);
// PR_ASSERT(i_etag && *i_etag);
if (!i_etag)
return;
if (m_Etag)
delete[] m_Etag;
m_Etag = new char[strlen(i_etag) + 1];
strcpy(m_Etag, i_etag);
m_Etag = new char[PL_strlen(i_etag) + 1];
PL_strncpy(m_Etag, i_etag, PL_strlen(i_etag));
}
void nsCacheObject::Filename(const char* i_Filename)
{
// PR_ASSERT(i_Filename && *i_Filename);
if (!i_Filename)
return;
if (m_Filename)
delete[] m_Filename;
m_Filename = new char[PL_strlen(i_Filename) +1];
PL_strncpy(m_Filename, i_Filename, PL_strlen(i_Filename));
}
void* nsCacheObject::Info(void) const
@ -215,25 +316,27 @@ void* nsCacheObject::Info(void) const
return m_pInfo;
nsCacheObject* pThis = (nsCacheObject*) this;
if (m_Url){
/*
char* tmpBuff = PR_smprintf(READ_WRITE_FORMAT, READ_WRITE_ELEMENTS);
int tmpLen = PL_strlen(tmpBuff);
pThis->m_pInfo = PR_Malloc(tmpLen);
memcpy(pThis->m_pInfo, tmpBuff, tmpLen);
PR_Free(tmpBuff);
*/
if (m_URL){
pThis->m_info_size = sizeof(nsCacheObject);
pThis->m_info_size -= sizeof(void*); //m_info is not being serialized
pThis->m_info_size -= sizeof(void*); // m_info itself is not being serialized
pThis->m_info_size -= sizeof(char*); // And neither is PostData
//Add the strings sizes
pThis->m_info_size += PL_strlen(m_Charset)+1;
pThis->m_info_size += PL_strlen(m_ContentEncoding)+1;
pThis->m_info_size += PL_strlen(m_ContentType)+1;
pThis->m_info_size += PL_strlen(m_Etag)+1;
pThis->m_info_size += PL_strlen(m_Url)+1;
pThis->m_info_size += PL_strlen(m_Filename)+1;
pThis->m_info_size += PL_strlen(m_PageServicesURL)+1;
pThis->m_info_size += PL_strlen(m_URL)+1;
void* new_obj = PR_Malloc(m_info_size * sizeof(char));
memset(new_obj, 0, m_info_size *sizeof(char));
//Add the Postdata len
pThis->m_info_size += m_PostDataLen+1;
void* new_obj = PR_Calloc(1, m_info_size * sizeof(char));
if (!new_obj)
{
PR_Free(new_obj);
@ -258,17 +361,33 @@ void* nsCacheObject::Info(void) const
COPY_INT32((void *)cur_ptr, &kCACHE_VERSION);
cur_ptr += sizeof(PRUint32);
STUFF_STRING(m_Charset);
STUFF_STRING(m_ContentEncoding);
STUFF_NUMBER(m_ContentLength);
STUFF_STRING(m_ContentType);
STUFF_STRING(m_Etag);
STUFF_TIME(m_Expires);
STUFF_STRING(m_Filename);
STUFF_NUMBER(m_Flags);
STUFF_NUMBER(m_Hits);
STUFF_TIME(m_LastAccessed);
STUFF_TIME(m_LastModified);
STUFF_NUMBER(m_Module);
STUFF_STRING(m_PageServicesURL);
STUFF_NUMBER(m_PostDataLen);
/* There is a possibility of it not being a string! */
if (m_PostData)
{
memcpy(cur_ptr, m_PostData, m_PostDataLen+1);
cur_ptr += m_PostDataLen+1;
}
STUFF_NUMBER(m_Size);
STUFF_STRING(m_Url);
STUFF_STRING(m_URL);
// Important Assertion. Dont remove!
// If this fails then you or somebody has added a variable to the
// nsCacheObject class and a decision on its "cacheability" has
// not yet been made.
PR_ASSERT(cur_ptr == (char*) new_obj + m_info_size);
pThis->m_pInfo = new_obj;
}
@ -285,6 +404,26 @@ PRBool nsCacheObject::Info(void* i_data)
//Reset the m_pInfo;
PR_FREEIF(m_pInfo);
//Reset all strings
if (m_Charset)
delete[] m_Charset;
if (m_ContentEncoding)
delete[] m_ContentEncoding;
if (m_ContentType)
delete[] m_ContentType;
if (m_Etag)
delete[] m_Etag;
if (m_Filename)
delete[] m_Filename;
if (m_PageServicesURL)
delete[] m_PageServicesURL;
if (m_URL)
delete[] m_URL;
if (m_PostData)
delete[] m_PostData;
m_PostDataLen = 0;
COPY_INT32(&m_info_size, cur_ptr);
char* max_ptr = cur_ptr + m_info_size;
cur_ptr += sizeof(PRUint32);
@ -301,16 +440,31 @@ PRBool nsCacheObject::Info(void* i_data)
}
PRUint32 len;
//m_Etag,m_Expires,m_Flags,m_Hits,m_LastAccessed,m_LastModified,m_Module,m_Size,m_Url
RETRIEVE_STRING(m_Charset);
RETRIEVE_STRING(m_ContentEncoding);
RETRIEVE_NUMBER(m_ContentLength);
RETRIEVE_STRING(m_ContentType);
RETRIEVE_STRING(m_Etag);
RETRIEVE_TIME(m_Expires);
RETRIEVE_STRING(m_Filename);
RETRIEVE_NUMBER(m_Flags);
RETRIEVE_NUMBER(m_Hits);
RETRIEVE_TIME(m_LastAccessed);
RETRIEVE_TIME(m_LastModified);
RETRIEVE_NUMBER(m_Module);
RETRIEVE_STRING(m_PageServicesURL);
RETRIEVE_NUMBER(m_PostDataLen);
// Special case-
m_PostData = new char[m_PostDataLen + 1];
if (m_PostData)
{
memcpy(m_PostData, cur_ptr, m_PostDataLen+1);
}
cur_ptr += m_PostDataLen +1;
RETRIEVE_NUMBER(m_Size);
RETRIEVE_STRING(m_Url);
RETRIEVE_STRING(m_URL);
// Most important assertion! Don't ever remove!
PR_ASSERT(cur_ptr == max_ptr);
@ -332,6 +486,43 @@ void nsCacheObject::Init()
m_Hits = 0;
}
void nsCacheObject::PageServicesURL(const char* i_Url)
{
// PR_ASSERT(i_Url && *i_Url);
if (!i_Url)
return;
if (m_PageServicesURL)
delete[] m_PageServicesURL;
m_PageServicesURL = new char[PL_strlen(i_Url) + 1];
PL_strncpy(m_PageServicesURL, i_Url, PL_strlen(i_Url));
}
void nsCacheObject::PostData(const char* i_data, const PRUint32 i_Len)
{
if (!i_data || (0 ==i_Len))
return;
if (m_PostData)
delete[] m_PostData;
m_PostData = new char[i_Len+1];
PL_strncpy(m_PostData, i_data, i_Len);
m_PostDataLen = i_Len;
}
PRUint32 nsCacheObject::Read(char* o_Buffer, PRUint32 len)
{
PR_ASSERT(m_Module >=0);
if (0 <= m_Module)
{
nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module);
if (pModule)
{
return pModule->Read(this, o_Buffer, len);
}
}
return 0;
}
#if 0
/* Caller must free returned string */
// TODO change to use PR_stuff...
const char* nsCacheObject::Trace() const
@ -339,8 +530,8 @@ const char* nsCacheObject::Trace() const
char linebuffer[256];
char* total;
sprintf(linebuffer, "nsCacheObject:URL=%s,SIZE=%d,ET=%s,\n\tLM=%d,LA=%d,EXP=%d,HITS=%d\n",
m_Url,
PR_Sprintf(linebuffer, "nsCacheObject:URL=%s,SIZE=%d,ET=%s,\n\tLM=%d,LA=%d,EXP=%d,HITS=%d\n",
m_URL,
m_Size,
m_Etag,
m_LastModified,
@ -349,7 +540,22 @@ const char* nsCacheObject::Trace() const
m_Hits);
total = new char[PL_strlen(linebuffer) +1];
strcpy(total, linebuffer);
PL_strcpy(total, linebuffer);
return total;
}
#endif
PRUint32 nsCacheObject::Write(const char* i_Buffer, const PRUint32 len)
{
PR_ASSERT(m_Module >=0);
if (0 <= m_Module)
{
nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module);
if (pModule)
{
return pModule->Write(this, i_Buffer, len);
}
}
return 0;
}

27
network/cache/nu/src/nsCachePref.cpp поставляемый
Просмотреть файл

@ -22,6 +22,11 @@
static const PRUint32 MEM_CACHE_SIZE_DEFAULT = 1024*1024;
static const PRUint32 DISK_CACHE_SIZE_DEFAULT = 5*MEM_CACHE_SIZE_DEFAULT;
static const PRUint32 BKG_THREAD_SLEEP = 15*60; /*in seconds, 15 minutes */
static const PRUint16 BUGS_FOUND_SO_FAR = 0;
/* Find a bug in NU_CACHE, get these many chocolates */
static const PRUint16 CHOCOLATES_PER_BUG_FOUND = 2^BUGS_FOUND_SO_FAR;
/* TODO move this to InitNetLib */
static nsCachePref ThePrefs;
nsCachePref::nsCachePref(void):
@ -46,22 +51,27 @@ nsCachePref::~nsCachePref()
const PRUint32
nsCachePref::BkgSleepTime(void)
{
return ThePrefs.m_BkgSleepTime;
return BKG_THREAD_SLEEP;
}
PRUint32 nsCachePref::DiskCacheSize()
{
return ThePrefs.m_DiskCacheSize;
return m_DiskCacheSize;
}
void nsCachePref::DiskCacheSize(const PRUint32 i_Size)
{
m_DiskCacheSize = i_Size;
}
PRBool nsCachePref::DiskCacheSSL(void)
{
return ThePrefs.m_bDiskCacheSSL;
return m_bDiskCacheSSL;
}
void nsCachePref::DiskCacheSSL(PRBool bSet)
{
ThePrefs.m_bDiskCacheSSL = bSet;
m_bDiskCacheSSL = bSet;
}
const char* nsCachePref::DiskCacheDBFilename(void)
@ -81,12 +91,17 @@ nsCachePref* nsCachePref::GetInstance()
PRUint32 nsCachePref::MemCacheSize()
{
return ThePrefs.m_MemCacheSize;
return m_MemCacheSize;
}
void nsCachePref::MemCacheSize(const PRUint32 i_Size)
{
m_MemCacheSize = i_Size;
}
PRBool nsCachePref::RevalidateInBkg(void)
{
return ThePrefs.m_bRevalidateInBkg;
return m_bRevalidateInBkg;
}
/*

15
network/cache/nu/src/nsCacheTrace.cpp поставляемый
Просмотреть файл

@ -25,7 +25,20 @@
#include "nsCacheTrace.h"
nsCacheTrace::nsCacheTrace()
static nsCacheTrace TheTrace;
nsCacheTrace::nsCacheTrace():m_bEnabled(PR_FALSE)
{
}
void nsCacheTrace::Enable(PRBool bEnable)
{
TheTrace.m_bEnabled = bEnable;
}
PRBool nsCacheTrace::IsEnabled(void)
{
return TheTrace.m_bEnabled;
}

99
network/cache/nu/src/nsDiskModule.cpp поставляемый
Просмотреть файл

@ -23,10 +23,10 @@
*
*/
#include <prtypes.h>
#include <prmem.h>
#include <plstr.h>
#include <prlog.h>
#include "prtypes.h"
#include "prmem.h"
#include "plstr.h"
#include "prlog.h"
#include "nsDiskModule.h"
#include "nsCacheObject.h"
@ -34,11 +34,12 @@
#include "mcom_db.h"
#define CHECK_INIT \
#define ENSURE_INIT \
if (!m_pDB) \
{ \
nsDiskModule* pThis = (nsDiskModule*) this; \
PR_ASSERT(pThis->InitDB()); \
PRBool res = pThis->InitDB(); \
PR_ASSERT(res); \
}
//
@ -62,33 +63,39 @@ nsDiskModule::~nsDiskModule()
PRBool nsDiskModule::AddObject(nsCacheObject* io_pObject)
{
if (!InitDB())
ENSURE_INIT;
if (!m_pDB || !io_pObject)
{
// Set some error state TODO
return PR_FALSE;
}
if (io_pObject && io_pObject->Address())
if (io_pObject->Address())
{
static DBT key,data;
MonitorLocker ml(this);
// TODO optimize these further- make static - Gagan
DBT* key = PR_NEW(DBT);
DBT* data = PR_NEW(DBT);
io_pObject->Module(nsCacheManager::DISK);
PR_FREEIF(key.data);
PR_FREEIF(data.data);
key->data = (void*)io_pObject->Address();
/* Later on change this to include post data- io_pObject->KeyData() */
key->size = PL_strlen(io_pObject->Address());
key.data = (void*)io_pObject->Address(); /* Later on change this to include post data- io_pObject->KeyData() */
key.size = PL_strlen(io_pObject->Address());
data->data = io_pObject->Info();
data->size = io_pObject->InfoSize();
data.data = io_pObject->Info();
data.size = io_pObject->InfoSize();
int status = (*m_pDB->put)(m_pDB, &key, &data, 0);
int status = (*m_pDB->put)(m_pDB, key, data, 0);
if (status == 0)
{
// if (m_Sync == EVERYTIME)
status = (*m_pDB->sync)(m_pDB, 0);
}
PR_Free(key);
PR_Free(data);
return (status == 0);
}
return PR_FALSE;
@ -96,15 +103,17 @@ PRBool nsDiskModule::AddObject(nsCacheObject* io_pObject)
PRBool nsDiskModule::Contains(nsCacheObject* io_pObject) const
{
//return Contains(io_oObject->Address());
ENSURE_INIT;
CHECK_INIT;
if (!m_pDB || !io_pObject)
return PR_FALSE;
nsCacheObject* pTemp = GetObject(io_pObject->Address());
if (pTemp)
{
io_pObject = pTemp;
io_pObject = pTemp; /*bug */
return PR_TRUE;
}
return PR_FALSE;
@ -113,7 +122,7 @@ PRBool nsDiskModule::Contains(nsCacheObject* io_pObject) const
PRBool nsDiskModule::Contains(const char* i_url) const
{
CHECK_INIT;
ENSURE_INIT;
if (!m_pDB || !i_url || !*i_url)
return PR_FALSE;
@ -131,22 +140,21 @@ PRBool nsDiskModule::Contains(const char* i_url) const
void nsDiskModule::GarbageCollect(void)
{
PR_ASSERT(PR_TRUE);
MonitorLocker ml(this);
}
nsCacheObject* nsDiskModule::GetObject(const PRUint32 i_index) const
{
CHECK_INIT;
ENSURE_INIT;
if (!m_pDB)
return 0;
//todo
return 0;
}
nsCacheObject* nsDiskModule::GetObject(const char* i_url) const
{
CHECK_INIT;
ENSURE_INIT;
if (!m_pDB || !i_url || !*i_url)
return 0;
@ -168,6 +176,7 @@ nsCacheObject* nsDiskModule::GetObject(const char* i_url) const
PRBool nsDiskModule::InitDB(void)
{
MonitorLocker ml(this);
if (m_pDB)
return PR_TRUE;
@ -181,7 +190,7 @@ PRBool nsDiskModule::InitDB(void)
0}; /* byte order */
m_pDB = dbopen(
nsCachePref::DiskCacheDBFilename(),
nsCachePref::GetInstance()->DiskCacheDBFilename(),
O_RDWR | O_CREAT,
0600,
DB_HASH,
@ -210,9 +219,20 @@ PRBool nsDiskModule::InitDB(void)
return PR_TRUE;
}
PRUint32 nsDiskModule::Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len)
{
return 0;
}
PRBool nsDiskModule::ReduceSizeTo(const PRUint32 i_NewSize)
{
//TODO
return PR_TRUE;
}
PRBool nsDiskModule::Remove(const char* i_url)
{
CHECK_INIT;
ENSURE_INIT;
//TODO
// Also remove the file corresponding to this item.
return PR_FALSE;
@ -220,7 +240,7 @@ PRBool nsDiskModule::Remove(const char* i_url)
PRBool nsDiskModule::Remove(const PRUint32 i_index)
{
CHECK_INIT;
ENSURE_INIT;
//TODO
// Also remove the file corresponding to this item.
return PR_FALSE;
@ -228,8 +248,29 @@ PRBool nsDiskModule::Remove(const PRUint32 i_index)
PRBool nsDiskModule::Revalidate(void)
{
CHECK_INIT;
ENSURE_INIT;
//TODO - This will add a dependency on HTTP lib
return PR_FALSE;
}
void nsDiskModule::SetSize(const PRUint32 i_Size)
{
MonitorLocker ml(this);
m_Size = i_Size;
if (m_Size >0)
{
ReduceSizeTo(m_Size);
}
else
{
RemoveAll();
}
}
PRUint32 nsDiskModule::Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len)
{
ENSURE_INIT;
return 0;
}
#undef ENSURE_INIT

4
network/cache/nu/src/nsFFEntry.cpp поставляемый
Просмотреть файл

@ -17,8 +17,8 @@
*/
#include "nsFFEntry.h"
#include <prmem.h>
#include <prlog.h>
#include "prmem.h"
#include "prlog.h"
nsFFEntry::nsFFEntry():
m_ID(0),

2
network/cache/nu/src/nsFFObject.cpp поставляемый
Просмотреть файл

@ -17,7 +17,7 @@
*/
#include "nsFFObject.h"
#include <prlog.h>
#include "prlog.h"
nsFFObject::nsFFObject(PRUint32 i_ID, PRUint32 i_Offset, PRUint32 i_Size):
m_ID(i_ID),

6
network/cache/nu/src/nsFlatFile.cpp поставляемый
Просмотреть файл

@ -17,9 +17,9 @@
*/
#include "nsFlatFile.h"
#include <plstr.h>
#include <prmem.h>
#include <memory.h>
#include "plstr.h"
#include "prmem.h"
#include "memory.h"
static const PRUint32 kFLAT_FILE_VERSION = 1;
static const PRUint32 kMAGIC_NUMBER = 3739142906; // Facede de //TODO

2
network/cache/nu/src/nsHash.cpp поставляемый
Просмотреть файл

@ -16,7 +16,7 @@
* Reserved.
*/
#include <prmem.h>
#include "prmem.h"
#include "nsHash.h"
//

2
network/cache/nu/src/nsMemCacheObject.cpp поставляемый
Просмотреть файл

@ -22,7 +22,7 @@
* Gagan Saksena 04/22/98
*
*/
#include <prtypes.h>
#include "prtypes.h"
#include "nsMemCacheObject.h"
nsMemCacheObject::~nsMemCacheObject()

171
network/cache/nu/src/nsMemModule.cpp поставляемый
Просмотреть файл

@ -16,9 +16,9 @@
* Reserved.
*/
#include <prtypes.h>
#include <plstr.h>
#include <prlog.h>
#include "prtypes.h"
#include "plstr.h"
#include "prlog.h"
#include "nsMemModule.h"
#include "nsMemCacheObject.h"
@ -37,7 +37,7 @@ nsMemModule::nsMemModule(const PRUint32 size):
m_pFirstObject(0),
nsCacheModule(size)
{
Size(size);
SetSize(size);
}
nsMemModule::~nsMemModule()
@ -60,26 +60,29 @@ PRBool nsMemModule::AddObject(nsCacheObject* io_pObject)
#endif
if (io_pObject)
{
if (m_pFirstObject)
{
LastObject()->Next(new nsMemCacheObject(io_pObject));
}
else
{
m_pFirstObject = new nsMemCacheObject(io_pObject);
}
m_Entries++;
{
MonitorLocker ml(this);
if (m_pFirstObject)
{
LastObject()->Next(new nsMemCacheObject(io_pObject));
}
else
{
m_pFirstObject = new nsMemCacheObject(io_pObject);
}
m_Entries++;
io_pObject->Module(nsCacheManager::MEM);
return PR_TRUE;
}
return PR_FALSE;
}
return PR_FALSE;
}
PRBool nsMemModule::Contains(const char* i_url) const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstObject && i_url && *i_url)
{
nsMemCacheObject* pObj = m_pFirstObject;
@ -97,6 +100,8 @@ PRBool nsMemModule::Contains(const char* i_url) const
PRBool nsMemModule::Contains(nsCacheObject* i_pObject) const
{
MonitorLocker ml((nsMonitorable*)this);
if (i_pObject && *i_pObject->Address())
{
return this->Contains(i_pObject->Address());
@ -104,64 +109,10 @@ PRBool nsMemModule::Contains(nsCacheObject* i_pObject) const
return 0;
}
nsCacheObject* nsMemModule::GetObject(const PRUint32 i_index) const
{
nsMemCacheObject* pNth = 0;
if (m_pFirstObject)
{
PRUint32 index = 0;
pNth = m_pFirstObject;
while (pNth->Next() && (index++ != i_index ))
{
pNth = pNth->Next();
}
}
return pNth->ThisObject();
}
nsCacheObject* nsMemModule::GetObject(const char* i_url) const
{
if (m_pFirstObject && i_url && *i_url)
{
nsMemCacheObject* pObj = m_pFirstObject;
int inlen = PL_strlen(i_url);
do
{
if (0 == PL_strncasecmp(pObj->ThisObject()->Address(), i_url, inlen))
return pObj->ThisObject();
pObj = pObj->Next();
}
while (pObj);
}
return 0;
}
nsMemCacheObject* nsMemModule::LastObject(void) const
{
nsMemCacheObject* pLast = 0;
if (m_pFirstObject)
{
pLast = m_pFirstObject;
while (pLast->Next())
pLast = pLast->Next();
}
return pLast;
}
PRBool nsMemModule::Remove(const char* i_url)
{
//TODO
return PR_FALSE;
}
PRBool nsMemModule::Remove(const PRUint32 i_index)
{
//TODO
return PR_FALSE;
}
void nsMemModule::GarbageCollect(void)
{
MonitorLocker ml(this);
if (m_Entries > 0)
{
nsEnumeration* pEnum = Enumeration();
@ -180,6 +131,82 @@ void nsMemModule::GarbageCollect(void)
}
}
nsCacheObject* nsMemModule::GetObject(const PRUint32 i_index) const
{
MonitorLocker ml((nsMonitorable*)this);
nsMemCacheObject* pNth = 0;
if (m_pFirstObject)
{
PRUint32 index = 0;
pNth = m_pFirstObject;
while (pNth->Next() && (index++ != i_index ))
{
pNth = pNth->Next();
}
}
return pNth->ThisObject();
}
nsCacheObject* nsMemModule::GetObject(const char* i_url) const
{
MonitorLocker ml((nsMonitorable*)this);
if (m_pFirstObject && i_url && *i_url)
{
nsMemCacheObject* pObj = m_pFirstObject;
int inlen = PL_strlen(i_url);
do
{
if (0 == PL_strncasecmp(pObj->ThisObject()->Address(), i_url, inlen))
return pObj->ThisObject();
pObj = pObj->Next();
}
while (pObj);
}
return 0;
}
nsMemCacheObject* nsMemModule::LastObject(void) const
{
MonitorLocker ml((nsMonitorable*)this);
nsMemCacheObject* pLast = 0;
if (m_pFirstObject)
{
pLast = m_pFirstObject;
while (pLast->Next())
pLast = pLast->Next();
}
return pLast;
}
PRUint32 nsMemModule::Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len)
{
return 0;
}
PRBool nsMemModule::ReduceSizeTo(const PRUint32 i_NewSize)
{
//TODO
return PR_TRUE;
}
PRBool nsMemModule::Remove(const char* i_url)
{
//TODO
return PR_FALSE;
}
PRBool nsMemModule::Remove(const PRUint32 i_index)
{
//TODO
return PR_FALSE;
}
PRUint32 nsMemModule::Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len)
{
return 0;
}
/*
NS_IMETHOD nsMemModule::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{

6
network/cache/nu/src/nsTOC.cpp поставляемый
Просмотреть файл

@ -17,9 +17,9 @@
*/
#include "nsTOC.h"
#include <plstr.h>
#include <memory.h>
#include <prlog.h>
#include "plstr.h"
#include "memory.h"
#include "prlog.h"
static const PRUint32 kTOC_FLAT_FILE_VERSION = 1;
static const PRUint32 kTOC_MAGIC_NUMBER = 19712809;

Просмотреть файл