diff --git a/mozilla/network/cache/nu/include/nsCachePref.h b/mozilla/network/cache/nu/include/nsCachePref.h new file mode 100644 index 00000000000..f280692e272 --- /dev/null +++ b/mozilla/network/cache/nu/include/nsCachePref.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsCachePref_h__ +#define nsCachePref_h__ + +//#include "nsISupports.h" +#include + +class nsCachePref //: public nsISupports +{ + +public: + enum Refresh + { + NEVER, + ONCE, + ALWAYS + } r; + nsCachePref(); + + PRUint32 MemCacheSize() const; + PRUint32 DiskCacheSize() const; + const char* DiskCacheFolder() const; + nsCachePref::Refresh + Frequency() const; + +/* + NS_IMETHOD QueryInterface(const nsIID& aIID, + void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); +*/ +protected: + +private: + nsCachePref(const nsCachePref& o); + nsCachePref& operator=(const nsCachePref& o); +}; + +#endif // nsCachePref_h__ + diff --git a/mozilla/network/cache/nu/public/nsCacheModule.h b/mozilla/network/cache/nu/public/nsCacheModule.h index 722cd9c1bdf..492f31b73f6 100644 --- a/mozilla/network/cache/nu/public/nsCacheModule.h +++ b/mozilla/network/cache/nu/public/nsCacheModule.h @@ -25,100 +25,106 @@ * Gagan Saksena 02/03/98 * */ - +//#include #include "nsCacheObject.h" -//class nsCacheObject; -/* Why the hell is forward decl. not working? */ -class nsCacheModule +/* Why the hell is forward decl. not working? */ +//class nsCacheObject; + +/* +// {5D51B24F-E6C2-11d1-AFE5-006097BFC036} +static const NS_CACHEMODULE_ID = +{ 0x5d51b24f, 0xe6c2, 0x11d1, { 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } }; +*/ + +class nsCacheModule /*: public nsISupports */ { public: - nsCacheModule(); - nsCacheModule(const PRUint32 i_size); + nsCacheModule(const PRUint32 i_size /*= DEFAULT_SIZE */); - virtual - ~nsCacheModule(); - - virtual - PRBool AddObject(nsCacheObject* i_pObject)=0; virtual + ~nsCacheModule(); + + virtual + PRBool AddObject(nsCacheObject* i_pObject)=0; + virtual PRBool Contains(const char* i_url) const=0; - virtual - PRBool Contains(nsCacheObject* i_pObject) const=0; - void Enable(PRBool i_Enable); - const PRUint32 Entries() const; + virtual + PRBool Contains(nsCacheObject* i_pObject) const=0; + void Enable(PRBool i_Enable); + const PRUint32 Entries() const; - nsCacheObject* GetFirstObject() const ;//TODO-?/ + nsCacheObject* GetFirstObject() const ;//TODO-?/ virtual - nsCacheObject* GetObject(const char* i_url) const=0; + nsCacheObject* GetObject(const char* i_url) const=0; virtual - nsCacheObject* GetObject(PRUint32 i_index) const =0; + nsCacheObject* GetObject(const PRUint32 i_index) const =0; - PRBool IsEnabled() const; + PRBool IsEnabled() const; - nsCacheModule* Next() const; - void Next(nsCacheModule*); + nsCacheModule* Next() const; + void Next(nsCacheModule*); - const PRUint32 Size() const; - void Size(const PRUint32 i_size); + const PRUint32 Size() const; + void Size(const PRUint32 i_size); - const char* Trace() const; + const char* Trace() const; protected: - PRUint32 m_Entries; - PRUint32 m_Size; - PRBool m_Enabled; + PRUint32 m_Entries; + PRUint32 m_Size; + PRBool m_Enabled; - nsCacheModule* m_pNext; + nsCacheModule* m_pNext; private: - nsCacheModule(const nsCacheModule& cm); - nsCacheModule& operator=(const nsCacheModule& cm); + nsCacheModule(const nsCacheModule& cm); + nsCacheModule& operator=(const nsCacheModule& cm); }; inline void nsCacheModule::Enable(PRBool i_Enable) { - m_Enabled = i_Enable; + m_Enabled = i_Enable; } inline PRBool nsCacheModule::IsEnabled() const { - return m_Enabled; + return m_Enabled; } inline const PRUint32 nsCacheModule::Entries() const { - return m_Entries; + return m_Entries; } inline nsCacheObject* nsCacheModule::GetFirstObject() const { - return this->GetObject((PRUint32)0); + return this->GetObject((PRUint32)0); } inline nsCacheModule* nsCacheModule::Next() const { - return m_pNext; + return m_pNext; } inline void nsCacheModule::Next(nsCacheModule* pNext) { - m_pNext = pNext; + m_pNext = pNext; } inline const PRUint32 nsCacheModule::Size() const { - return m_Size; + return m_Size; } inline void nsCacheModule::Size(const PRUint32 size) { - m_Size = size; + m_Size = size; } #endif // nsCacheModule_h__ diff --git a/mozilla/network/cache/nu/public/nsCacheObject.h b/mozilla/network/cache/nu/public/nsCacheObject.h index 7e4cca9073f..fd1009e8abd 100644 --- a/mozilla/network/cache/nu/public/nsCacheObject.h +++ b/mozilla/network/cache/nu/public/nsCacheObject.h @@ -105,12 +105,12 @@ private: inline const char* nsCacheObject::Address(void) const { return m_Url; -} +}; inline const char* nsCacheObject::Etag(void) const { return m_Etag; -} +}; inline PRIntervalTime nsCacheObject::Expires(void) const { @@ -120,58 +120,58 @@ inline PRIntervalTime nsCacheObject::Expires(void) const inline void nsCacheObject::Expires(PRIntervalTime i_Expires) { m_Expires = i_Expires; -} +}; inline PRUint16 nsCacheObject::Hits(void) const { return m_Hits; -} +}; inline PRBool nsCacheObject::IsExpired(void) const { PRIntervalTime now = PR_IntervalNow(); return (m_Expires <= now); -} +}; inline PRBool nsCacheObject::IsPartial(void) const { return (m_Flags & nsCacheObject::PARTIAL); -} +}; inline PRIntervalTime nsCacheObject::LastAccessed(void) const { return m_LastAccessed; -} +}; inline PRIntervalTime nsCacheObject::LastModified(void) const { return m_LastModified; -} +}; inline void nsCacheObject::LastModified(PRIntervalTime i_LastModified) { m_LastModified = i_LastModified; -} +}; inline PRInt16 nsCacheObject::Module(void) const { return m_Module; -} +}; inline void nsCacheObject::Module(PRUint16 i_Module) { m_Module = i_Module; -} +}; inline PRUint32 nsCacheObject::Size(void) const { return m_Size; -} +}; inline void nsCacheObject::Size(PRUint32 i_Size) { m_Size = i_Size; -} +}; #endif // nsCacheObject_h__ diff --git a/mozilla/network/cache/nu/public/nsDiskModule.h b/mozilla/network/cache/nu/public/nsDiskModule.h index 5eada988b8f..65426c1930c 100644 --- a/mozilla/network/cache/nu/public/nsDiskModule.h +++ b/mozilla/network/cache/nu/public/nsDiskModule.h @@ -30,14 +30,14 @@ class nsDiskModule : public nsCacheModule { public: - nsDiskModule(); - ~nsDiskModule(); - PRBool AddObject(nsCacheObject* i_pObject); - nsCacheObject* GetObject(PRUint32 i_index) const; + nsDiskModule(const PRUint32 size); + ~nsDiskModule(); + PRBool AddObject(nsCacheObject* i_pObject); + nsCacheObject* GetObject(PRUint32 i_index) const; private: - nsDiskModule(const nsDiskModule& dm); - nsDiskModule& operator=(const nsDiskModule& dm); + nsDiskModule(const nsDiskModule& dm); + nsDiskModule& operator=(const nsDiskModule& dm); }; #endif diff --git a/mozilla/network/cache/nu/public/nsMemCacheObject.h b/mozilla/network/cache/nu/public/nsMemCacheObject.h index bbaec45d4f0..fae883c1650 100644 --- a/mozilla/network/cache/nu/public/nsMemCacheObject.h +++ b/mozilla/network/cache/nu/public/nsMemCacheObject.h @@ -19,44 +19,83 @@ #ifndef _nsMemCacheObject_h_ #define _nsMemCacheObject_h_ +#include + #include "nsCacheObject.h" -class nsMemCacheObject : public nsCacheObject +class nsMemCacheObject { public: - nsMemCacheObject(void); - nsMemCacheObject(const nsCacheObject&); + + nsMemCacheObject(void); + nsMemCacheObject(nsCacheObject* io_pObject); nsMemCacheObject(const char* i_url); ~nsMemCacheObject(); - void Next(nsCacheObject* pObject); - nsMemCacheObject* Next(void) const; - + 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; - /* The actual data of this cache object */ - char* m_pData; + nsCacheObject* m_pObject; + void* m_pData; - nsMemCacheObject& operator=(const nsMemCacheObject& lco); + nsMemCacheObject& operator=(const nsMemCacheObject& mco); + nsMemCacheObject(const nsMemCacheObject&); }; inline nsMemCacheObject::nsMemCacheObject(void): - nsCacheObject(), - m_pNextObject(0) + m_pObject(new nsCacheObject()), + m_pNextObject(0), + m_pData(0) { } -inline nsMemCacheObject::nsMemCacheObject(const nsCacheObject& another): - nsCacheObject(another), - m_pNextObject(0) +inline nsMemCacheObject::nsMemCacheObject(nsCacheObject* io_pObject): + m_pObject(io_pObject), + m_pNextObject(0), + m_pData(0) { } inline nsMemCacheObject::nsMemCacheObject(const char* i_url): - nsCacheObject(i_url), - m_pNextObject(0) + m_pObject(new nsCacheObject(i_url)), + m_pNextObject(0), + m_pData(0) { } +inline void* nsMemCacheObject::Data(void) const +{ +// PR_ASSERT(m_pData); + return m_pData; +} + +inline nsMemCacheObject* nsMemCacheObject::Next(void) const +{ + return m_pNextObject; +} + +inline void nsMemCacheObject::Next(nsMemCacheObject* pObject) +{ + m_pNextObject = pObject; +} + +inline void nsMemCacheObject::Next(nsCacheObject* pObject) +{ + m_pNextObject = new nsMemCacheObject(pObject); +} + +inline nsCacheObject* nsMemCacheObject::ThisObject(void) const +{ + return m_pObject; +} + #endif //_nsMemCacheObject_h_ diff --git a/mozilla/network/cache/nu/public/nsMemModule.h b/mozilla/network/cache/nu/public/nsMemModule.h index d6eb2318c23..fe0439b11d8 100644 --- a/mozilla/network/cache/nu/public/nsMemModule.h +++ b/mozilla/network/cache/nu/public/nsMemModule.h @@ -28,30 +28,59 @@ #include "nsCacheModule.h" #include "nsMemCacheObject.h" +//#include +/* +// {5D51B250-E6C2-11d1-AFE5-006097BFC036} +static const NS_MEMMODULE_IID = +{ 0x5d51b250, 0xe6c2, 0x11d1, { 0xaf, 0xe5, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } }; +*/ + +static const PRUint32 DEFAULT_SIZE= 5*1024*1024; + class nsMemModule : public nsCacheModule { public: - nsMemModule(); - nsMemModule(const PRUint32 size); - ~nsMemModule(); + nsMemModule(const PRUint32 size=DEFAULT_SIZE); + ~nsMemModule(); - PRBool AddObject(nsCacheObject* i_pObject); - PRBool Contains(nsCacheObject* i_pObject) const; +/* + NS_IMETHOD QueryInterface(const nsIID& aIID, + void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + +*/ + PRBool AddObject(nsCacheObject* io_pObject); + PRBool Contains(nsCacheObject* io_pObject) const; PRBool Contains(const char* i_url) const; - nsCacheObject* GetObject(PRUint32 i_index) const; + nsCacheObject* GetObject(const PRUint32 i_index) const; nsCacheObject* GetObject(const char* i_url) const; - // Start of nsMemModule specific stuff... - // Here is a sample implementation using linked list + // Start of nsMemModule specific stuff... + // Here is a sample implementation using linked list protected: - nsMemCacheObject* LastObject(void) const; + nsMemCacheObject* LastObject(void) const; private: - nsMemCacheObject* m_pFirstObject; + nsMemCacheObject* m_pFirstObject; - nsMemModule(const nsMemModule& mm); - nsMemModule& operator=(const nsMemModule& mm); +// nsHashtable m_ht; + //Optimization + nsMemCacheObject* m_pLastObject; + + nsMemModule(const nsMemModule& mm); + nsMemModule& operator=(const nsMemModule& mm); + + /* + class nsMemKey : public nsHashKey + { + public: + PRUint32 HashValue(); + PRBool Equals(nsHashKey *aKey); + nsHashKey *Clone(); + }; + */ }; #endif diff --git a/mozilla/network/cache/nu/src/makefile.win b/mozilla/network/cache/nu/src/makefile.win index 89b66ed8876..63b06679ebf 100644 --- a/mozilla/network/cache/nu/src/makefile.win +++ b/mozilla/network/cache/nu/src/makefile.win @@ -20,19 +20,16 @@ IGNORE_MANIFEST = 1 DEPTH=..\..\..\.. MAKE_OBJ_TYPE = DLL -DLLNAME = cachelib -DLL = .\$(OBJDIR)\$(DLLNAME).dll + +LIBNAME = .\$(OBJDIR)\cachelib + +DLL = $(LIBNAME).dll LIBRARY_NAME=cachelib -MISCDEP = \ - $(LIBNSPR) \ - $(DIST)\lib\xpcom32.lib \ - $(NULL) - MODULE = cache -OBJS = \ +CPP_OBJS = \ .\$(OBJDIR)\nsCacheObject.obj \ .\$(OBJDIR)\nsCacheModule.obj \ .\$(OBJDIR)\nsMemModule.obj \ @@ -53,18 +50,21 @@ LCFLAGS = \ $(LCFLAGS) \ -DNS_DLLNAME=$(DLLNAME).dll \ $(NULL) - + +# Remember to change libplc21 to $whatever it is... LLIBS = \ - $(DIST)\lib\xpcom32.lib \ $(LIBNSPR) \ + $(DIST)\lib\libplc21.lib \ + $(DIST)\lib\xpcom32.lib \ $(NULL) include <$(DEPTH)\config\rules.mak> install:: $(DLL) - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib + $(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin + $(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib clobber:: - rm -f $(DIST)\bin\$(DLLNAME).dll + rm -f $(DIST)\bin\$(DLLNAME).$(DLL_SUFFIX) + rm -f $(DIST)\lib\$(DLLNAME).$(LIB_SUFFIX) diff --git a/mozilla/network/cache/nu/src/nsCacheManager.cpp b/mozilla/network/cache/nu/src/nsCacheManager.cpp index df7f861564d..c5b8cb17d58 100644 --- a/mozilla/network/cache/nu/src/nsCacheManager.cpp +++ b/mozilla/network/cache/nu/src/nsCacheManager.cpp @@ -44,11 +44,8 @@ nsCacheManager::nsCacheManager(): m_pFirstModule(0), m_pPref(new nsCachePref()) nsCacheManager::~nsCacheManager() { -#if 0 - // this is crashing!?! if (m_pFirstModule) delete m_pFirstModule; -#endif delete m_pPref; } diff --git a/mozilla/network/cache/nu/src/nsCacheModule.cpp b/mozilla/network/cache/nu/src/nsCacheModule.cpp index f66c245f6b4..a9940ca4545 100644 --- a/mozilla/network/cache/nu/src/nsCacheModule.cpp +++ b/mozilla/network/cache/nu/src/nsCacheModule.cpp @@ -33,38 +33,31 @@ #define DEFAULT_SIZE 10*0x100000L -nsCacheModule::nsCacheModule(): - m_Size(DEFAULT_SIZE), - m_pNext(0), - m_Entries(0) -{ -} - -nsCacheModule::nsCacheModule(const PRUint32 i_size): - m_Size(i_size), - m_pNext(0), - m_Entries(0) +nsCacheModule::nsCacheModule(const PRUint32 i_size=DEFAULT_SIZE): + m_Size(i_size), + m_pNext(0), + m_Entries(0) { } nsCacheModule::~nsCacheModule() { - if (m_pNext) - { - delete m_pNext; - m_pNext = 0; - } + if (m_pNext) + { + delete m_pNext; + m_pNext = 0; + } } const char* nsCacheModule::Trace() const { - char linebuffer[128]; - char* total; + char linebuffer[128]; + char* total; + + sprintf(linebuffer, "nsCacheModule: Objects = %d\n", Entries()); - sprintf(linebuffer, "nsCacheModule: Objects = %d\n", Entries()); - total = new char[strlen(linebuffer) + 1]; strcpy(total, linebuffer); - return total; + return total; } \ No newline at end of file diff --git a/mozilla/network/cache/nu/src/nsCachePref.cpp b/mozilla/network/cache/nu/src/nsCachePref.cpp new file mode 100644 index 00000000000..455e39c3891 --- /dev/null +++ b/mozilla/network/cache/nu/src/nsCachePref.cpp @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsCachePref.h" + +static const PRUint32 MEM_CACHE_SIZE_DEFAULT = 1024*1024; +static const PRUint32 DISK_CACHE_SIZE_DEFAULT = 5*MEM_CACHE_SIZE_DEFAULT; + +nsCachePref::nsCachePref() +{ +} + +nsCachePref::~nsCachePref() +{ +} + +PRUint32 nsCachePref::MemCacheSize() const +{ + return MEM_CACHE_SIZE_DEFAULT; +} + +PRUint32 nsCachePref::DiskCacheSize() const +{ + return DISK_CACHE_SIZE_DEFAULT; +} + +/* +nsrefcnt nsCachePref::AddRef(void) +{ + return ++m_RefCnt; +} +nsrefcnt nsCachePref::Release(void) +{ + if (--m_RefCnt == 0) + { + delete this; + return 0; + } + return m_RefCnt; +} + +nsresult nsCachePref::QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + return NS_OK; +} +*/ + diff --git a/mozilla/network/cache/nu/src/nsDiskModule.cpp b/mozilla/network/cache/nu/src/nsDiskModule.cpp index 85a832f4824..0242743cd79 100644 --- a/mozilla/network/cache/nu/src/nsDiskModule.cpp +++ b/mozilla/network/cache/nu/src/nsDiskModule.cpp @@ -29,7 +29,8 @@ // // Constructor: nsDiskModule // -nsDiskModule::nsDiskModule() +nsDiskModule::nsDiskModule(const PRUint32 size): + nsCacheModule(size) { } @@ -41,10 +42,10 @@ nsDiskModule::~nsDiskModule() nsCacheObject* nsDiskModule::GetObject(PRUint32 i_index) const { - return 0; + return 0; } PRBool nsDiskModule::AddObject(nsCacheObject* i_pObject) { - return PR_FALSE; + return PR_FALSE; } diff --git a/mozilla/network/cache/nu/src/nsMemCacheObject.cpp b/mozilla/network/cache/nu/src/nsMemCacheObject.cpp index e45be7828cf..924c2eedc18 100644 --- a/mozilla/network/cache/nu/src/nsMemCacheObject.cpp +++ b/mozilla/network/cache/nu/src/nsMemCacheObject.cpp @@ -32,14 +32,13 @@ nsMemCacheObject::~nsMemCacheObject() delete m_pNextObject; m_pNextObject = 0; } -} -nsMemCacheObject* nsMemCacheObject::Next(void) const -{ - return m_pNextObject; -} + if (m_pObject) + { + delete m_pObject; + m_pObject = 0; + } + + // Free the void* if allocated - TODO -void nsMemCacheObject::Next(nsCacheObject* pObject) -{ - m_pNextObject = (nsMemCacheObject*) pObject; } diff --git a/mozilla/network/cache/nu/src/nsMemModule.cpp b/mozilla/network/cache/nu/src/nsMemModule.cpp index af14e7ac3f7..98300fe8cd8 100644 --- a/mozilla/network/cache/nu/src/nsMemModule.cpp +++ b/mozilla/network/cache/nu/src/nsMemModule.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "nsMemModule.h" #include "nsMemCacheObject.h" @@ -29,15 +30,11 @@ * */ +//NS_DEFINE_IID(kMemModuleIID, NS_MEMMODULE_IID); -static const PRUint32 DEFAULT_SIZE = 5*1024*1024; - -nsMemModule::nsMemModule():m_pFirstObject(0) -{ - Size(DEFAULT_SIZE); -} - -nsMemModule::nsMemModule(const PRUint32 size): m_pFirstObject(0) +nsMemModule::nsMemModule(const PRUint32 size): + m_pFirstObject(0), + nsCacheModule(size) { Size(size); } @@ -50,18 +47,26 @@ nsMemModule::~nsMemModule() } } -/* TODO dont make copies */ PRBool nsMemModule::AddObject(nsCacheObject* i_pObject) { - if (i_pObject) + +#if 0 + if (i_pObject) + { + m_ht.Put( + } + return PR_FALSE; +#endif + + if (i_pObject) { if (m_pFirstObject) { - LastObject()->Next(new nsMemCacheObject(*i_pObject)); + LastObject()->Next(new nsMemCacheObject(i_pObject)); } else { - m_pFirstObject = new nsMemCacheObject(*i_pObject); + m_pFirstObject = new nsMemCacheObject(i_pObject); } m_Entries++; return PR_TRUE; @@ -71,45 +76,31 @@ PRBool nsMemModule::AddObject(nsCacheObject* i_pObject) PRBool nsMemModule::Contains(const char* i_url) const { - if (m_pFirstObject && i_url && *i_url) - { - nsMemCacheObject* pObj = m_pFirstObject; - int inlen = strlen(i_url); - do - { - if (0 == _strnicmp(pObj->Address(), i_url, inlen)) - return PR_TRUE; - pObj = pObj->Next(); - } - while (pObj); - } - return PR_FALSE; + if (m_pFirstObject && i_url && *i_url) + { + nsMemCacheObject* pObj = m_pFirstObject; + PRUint32 inlen = PL_strlen(i_url); + do + { + if (0 == PL_strncasecmp(pObj->ThisObject()->Address(), i_url, inlen)) + return PR_TRUE; + pObj = pObj->Next(); + } + while (pObj); + } + return PR_FALSE; } PRBool nsMemModule::Contains(nsCacheObject* i_pObject) const { - if (i_pObject && i_pObject->Address()) + if (i_pObject && *i_pObject->Address()) { return this->Contains(i_pObject->Address()); } return 0; - /* //XXX Think! - if (m_pFirstObject && i_pObject) - { - nsMemCacheObject* pNext = m_pFirstObject; - do - { - if (pNext == i_pObject) // Equality operator ? - return 1; - pNext = pNext->Next(); - } - while (pNext); - } - return 0; - */ } -nsCacheObject* nsMemModule::GetObject(PRUint32 i_index) const +nsCacheObject* nsMemModule::GetObject(const PRUint32 i_index) const { nsMemCacheObject* pNth = 0; if (m_pFirstObject) @@ -121,7 +112,7 @@ nsCacheObject* nsMemModule::GetObject(PRUint32 i_index) const pNth = pNth->Next(); } } - return pNth; + return pNth->ThisObject(); } nsCacheObject* nsMemModule::GetObject(const char* i_url) const @@ -132,8 +123,8 @@ nsCacheObject* nsMemModule::GetObject(const char* i_url) const int inlen = strlen(i_url); do { - if (0 == _strnicmp(pObj->Address(), i_url, inlen)) - return pObj; + if (0 == _strnicmp(pObj->ThisObject()->Address(), i_url, inlen)) + return pObj->ThisObject(); pObj = pObj->Next(); } while (pObj); @@ -151,4 +142,36 @@ nsMemCacheObject* nsMemModule::LastObject(void) const pLast = pLast->Next(); } return pLast; -} \ No newline at end of file +} + +/* +NS_IMETHOD nsMemModule::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + +} +NS_IMETHOD_(nsrefcnt) nsMemModule::AddRef(void) +{ + +} + +NS_IMETHOD_(nsrefcnt) nsMemModule::Release(void) +{ + +} +*/ + +/* +PRUint32 nsMemModule::nsMemKey::HashValue() +{ + return 0; +} +PRBool nsMemModule::nsMemKey::Equals(nsHashKey *aKey) +{ + return PR_FALSE; +} + +nsHashKey* nsMemModule::nsMemKey::Clone() +{ + return new nsMemModule::nsMemKey(); +} +*/ diff --git a/mozilla/network/cache/nu/tests/cb/cbView.cpp b/mozilla/network/cache/nu/tests/cb/cbView.cpp index 2751b56d2f1..63152d83354 100644 --- a/mozilla/network/cache/nu/tests/cb/cbView.cpp +++ b/mozilla/network/cache/nu/tests/cb/cbView.cpp @@ -122,40 +122,28 @@ void CCbView::OnInitialUpdate() pCO->LastModified(time(0)); pMM->AddObject(pCO); - pCO->Address("http://www.microsnot.com/"); - pCO->Size(1230); - pCO->Etag("Another"); - - int j = 1000; + int j = 10000; char tmpBuff[10]; while (j--) { + pCO = new nsCacheObject(itoa(j,tmpBuff,10)); pMM->AddObject(pCO); - pCO->Address(itoa(j,tmpBuff,10)); } - if (pMM->AddObject(pCO)) - { - char buffer[10]; - m_Mesg += itoa(pMM->Entries(), buffer, 10); - m_Mesg += " nsCacheObject(s) added successfully.\n"; - } - else - m_Mesg += "Failed to add a cache object!\n"; + m_Mesg += itoa(pMM->Entries(), tmpBuff, 10); + m_Mesg += " nsCacheObject(s) added.\n"; + + char* traceBuff = (char*) pCM->Trace(); + m_Mesg += "-----------------\n"; + m_Mesg += traceBuff; + delete[] traceBuff; + traceBuff = (char*) pMM->Trace(); + m_Mesg += traceBuff; + delete[] traceBuff; m_Mesg += "-----------------\n"; - m_Mesg += pCM->Trace(); - m_Mesg += pMM->Trace(); - m_Mesg += "-----------------\n"; - /* - for (int i = pMM->Entries(); i>0 ; i--) - { - m_Mesg += pMM->GetObject(i-1)->Trace(); - } - m_Mesg += "-----------------\n"; - */ - char buffer[10]; + char buffer[10]; m_Mesg += "Worst case time= "; m_Mesg += itoa(pCM->WorstCaseTime(), buffer, 10); m_Mesg += " microsec.\n"; @@ -171,9 +159,9 @@ void CCbView::OnInitialUpdate() m_Mesg += itoa(t, buffer, 10); m_Mesg += " microsec.\n"; - delete pMM; - pMM = 0; - delete pCO; +// delete pMM; +// pMM = 0; + CView::OnInitialUpdate(); }