diff --git a/mozilla/network/cache/nu/public/makefile.win b/mozilla/network/cache/nu/public/makefile.win index ad141cc158a..8eeadb46cac 100644 --- a/mozilla/network/cache/nu/public/makefile.win +++ b/mozilla/network/cache/nu/public/makefile.win @@ -24,7 +24,8 @@ 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 \ + nsMonitorable.h nsStream.h nsFileStream.h \ + nsMemStream.h \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/network/cache/nu/public/nsCacheModule.h b/mozilla/network/cache/nu/public/nsCacheModule.h index 015fd250ce5..1175ef3fe3b 100644 --- a/mozilla/network/cache/nu/public/nsCacheModule.h +++ b/mozilla/network/cache/nu/public/nsCacheModule.h @@ -74,6 +74,9 @@ public: virtual nsCacheObject* GetObject(const PRUint32 i_index) const =0; + virtual + nsStream* GetStreamFor(const nsCacheObject* i_pObject)=0; + PRBool IsEnabled(void) const; /* Cant do additions, deletions, validations, expirations */ @@ -82,9 +85,6 @@ public: 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; @@ -106,9 +106,6 @@ public: const char* Trace(void) const; - virtual - PRUint32 Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len); - protected: virtual diff --git a/mozilla/network/cache/nu/public/nsCacheObject.h b/mozilla/network/cache/nu/public/nsCacheObject.h index e20a49bd4dd..7f20a0dec7e 100644 --- a/mozilla/network/cache/nu/public/nsCacheObject.h +++ b/mozilla/network/cache/nu/public/nsCacheObject.h @@ -28,6 +28,8 @@ static const PRUint32 kCACHE_VERSION = 5; +class nsStream; + class nsCacheObject //: public nsISupports { @@ -135,6 +137,7 @@ protected: PRUint32 m_PostDataLen; PRInt16 m_Module; PRUint32 m_Size; + nsStream* m_pStream; char* m_URL; diff --git a/mozilla/network/cache/nu/public/nsDiskModule.h b/mozilla/network/cache/nu/public/nsDiskModule.h index d741144a4f7..3e86b36a4cb 100644 --- a/mozilla/network/cache/nu/public/nsDiskModule.h +++ b/mozilla/network/cache/nu/public/nsDiskModule.h @@ -46,7 +46,7 @@ public: nsCacheObject* GetObject(const PRUint32 i_index) const; nsCacheObject* GetObject(const char* i_url) const; - PRUint32 Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len); + nsStream* GetStreamFor(const nsCacheObject* i_pObject); PRBool ReduceSizeTo(const PRUint32 i_NewSize); @@ -58,8 +58,6 @@ public: PRBool Revalidate(void); - PRUint32 Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len); - private: enum sync_frequency { diff --git a/mozilla/network/cache/nu/public/nsFileStream.h b/mozilla/network/cache/nu/public/nsFileStream.h new file mode 100644 index 00000000000..8001d10fcc8 --- /dev/null +++ b/mozilla/network/cache/nu/public/nsFileStream.h @@ -0,0 +1,52 @@ +/* -*- 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 nsFileStream_h__ +#define nsFileStream_h__ + +//#include "nsISupports.h" +#include "nsStream.h" +#include "xp.h" // Reqd. for xp_file.h +#include "xp_file.h" // Cuz we don't have a better choice, as yet + +class nsFileStream: public nsStream +{ + +public: + nsFileStream(XP_File* i_pFile); + virtual ~nsFileStream(); +/* + NS_IMETHOD QueryInterface(const nsIID& aIID, + void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); +*/ + PRInt32 Read(void* o_Buffer, PRUint32 i_Len); + PRInt32 Write(const void* i_Buffer, PRUint32 i_Len); + +protected: + +private: + nsFileStream(const nsFileStream& o); + nsFileStream& operator=(const nsFileStream& o); + XP_File* m_pFile; +}; + +#endif // nsFileStream_h__ + diff --git a/mozilla/network/cache/nu/public/nsMemModule.h b/mozilla/network/cache/nu/public/nsMemModule.h index ba302a63ffd..25c197895f9 100644 --- a/mozilla/network/cache/nu/public/nsMemModule.h +++ b/mozilla/network/cache/nu/public/nsMemModule.h @@ -62,7 +62,7 @@ public: nsCacheObject* GetObject(const PRUint32 i_index) const; nsCacheObject* GetObject(const char* i_url) const; - PRUint32 Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len); + nsStream* GetStreamFor(const nsCacheObject* i_pObject); PRBool ReduceSizeTo(const PRUint32 i_NewSize); @@ -73,7 +73,6 @@ public: 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 diff --git a/mozilla/network/cache/nu/public/nsMemStream.h b/mozilla/network/cache/nu/public/nsMemStream.h new file mode 100644 index 00000000000..54fe099ec34 --- /dev/null +++ b/mozilla/network/cache/nu/public/nsMemStream.h @@ -0,0 +1,52 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this Mem are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this Mem 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 nsMemStream_h__ +#define nsMemStream_h__ + +//#include "nsISupports.h" +#include "nsStream.h" + +class nsMemStream: public nsStream +{ + +public: + nsMemStream(); + virtual ~nsMemStream(); +/* + NS_IMETHOD QueryInterface(const nsIID& aIID, + void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); +*/ + PRInt32 Read(void* o_Buffer, PRUint32 i_Len); + PRInt32 Write(const void* i_Buffer, PRUint32 i_Len); + +protected: + +private: + nsMemStream(const nsMemStream& o); + nsMemStream& operator=(const nsMemStream& o); + void* m_pCurrent; + void* m_pStart; + PRUint32 m_Size; +}; + +#endif // nsMemStream_h__ + diff --git a/mozilla/network/cache/nu/public/nsStream.h b/mozilla/network/cache/nu/public/nsStream.h new file mode 100644 index 00000000000..5e193002e18 --- /dev/null +++ b/mozilla/network/cache/nu/public/nsStream.h @@ -0,0 +1,51 @@ +/* -*- 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 nsStream_h__ +#define nsStream_h__ + +//#include "nsISupports.h" + +#include "prtypes.h" + +class nsStream//: public nsISupports +{ + +public: + nsStream(); + virtual ~nsStream(); +/* + NS_IMETHOD QueryInterface(const nsIID& aIID, + void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); +*/ + virtual + PRInt32 Read(void* o_Buffer, PRUint32 i_Len) = 0; + virtual + PRInt32 Write(const void* i_Buffer, PRUint32 i_Len) = 0; +protected: + +private: + nsStream(const nsStream& o); + nsStream& operator=(const nsStream& o); +}; + +#endif // nsStream_h__ + diff --git a/mozilla/network/cache/nu/src/Makefile b/mozilla/network/cache/nu/src/Makefile index 2f5585ac050..74b5f520472 100644 --- a/mozilla/network/cache/nu/src/Makefile +++ b/mozilla/network/cache/nu/src/Makefile @@ -41,6 +41,8 @@ CPPSRCS = nsCacheObject.cpp \ nsBkgThread.cpp \ nsCacheBkgThd.cpp \ CacheStubs.cpp \ + nsFileStream.cpp \ + nsMemStream.cpp \ $(NULL) REQUIRES = dbm nspr pref xpcom diff --git a/mozilla/network/cache/nu/src/makefile.win b/mozilla/network/cache/nu/src/makefile.win index d52bd048254..1c2408fdb45 100644 --- a/mozilla/network/cache/nu/src/makefile.win +++ b/mozilla/network/cache/nu/src/makefile.win @@ -51,6 +51,8 @@ OBJS = \ .\$(OBJDIR)\nsBkgThread.obj \ .\$(OBJDIR)\nsCacheBkgThd.obj \ .\$(OBJDIR)\CacheStubs.obj \ + .\$(OBJDIR)\nsFileStream.obj \ + .\$(OBJDIR)\nsMemStream.obj \ $(NULL) # .\$(OBJDIR)\nsHash.obj \ diff --git a/mozilla/network/cache/nu/src/nsCacheObject.cpp b/mozilla/network/cache/nu/src/nsCacheObject.cpp index f3072310507..e007635574d 100644 --- a/mozilla/network/cache/nu/src/nsCacheObject.cpp +++ b/mozilla/network/cache/nu/src/nsCacheObject.cpp @@ -24,6 +24,8 @@ #include "nsCacheTrace.h" #include "nsCacheModule.h" #include "nsCacheManager.h" +#include "nsStream.h" + /* * nsCacheObject * @@ -152,6 +154,7 @@ nsCacheObject::nsCacheObject(): m_PageServicesURL(new char[1]), m_PostData(new char[1]), m_PostDataLen(0), + m_pStream(0), m_URL(new char[1]) { Init(); @@ -183,6 +186,8 @@ nsCacheObject::~nsCacheObject() delete[] m_PostData; if (m_URL) delete[] m_URL; + if (m_pStream) + delete m_pStream; } nsCacheObject::nsCacheObject(const nsCacheObject& another): @@ -196,6 +201,7 @@ nsCacheObject::nsCacheObject(const nsCacheObject& another): m_PostDataLen(another.m_PostDataLen), m_PostData(new char[another.m_PostDataLen+1]), m_URL(new char[PL_strlen(another.m_URL)+1]), + m_pStream(0), m_pInfo(0) /* Should this be copied as well? */ { PL_strncpy(m_Charset, another.m_Charset, PL_strlen(another.m_Charset)); @@ -226,6 +232,7 @@ nsCacheObject::nsCacheObject(const char* i_url): m_PostDataLen(0), m_URL(new char[PL_strlen(i_url)+1]), m_Module(-1), + m_pStream(0), m_pInfo(0) { Init(); @@ -510,16 +517,22 @@ void nsCacheObject::PostData(const char* i_data, const PRUint32 i_Len) PRUint32 nsCacheObject::Read(char* o_Buffer, PRUint32 len) { - PR_ASSERT(m_Module >=0); - if (0 <= m_Module) + if (!m_pStream) { - nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module); - if (pModule) + PR_ASSERT(m_Module >=0); + if (0 <= m_Module) { - return pModule->Read(this, o_Buffer, len); + nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module); + if (pModule) + { + m_pStream = pModule->GetStreamFor(this); + if (m_pStream) + return m_pStream->Read(o_Buffer, len); + } } + return 0; } - return 0; + return m_pStream->Read(o_Buffer, len); } #if 0 @@ -548,14 +561,20 @@ const char* nsCacheObject::Trace() const PRUint32 nsCacheObject::Write(const char* i_Buffer, const PRUint32 len) { - PR_ASSERT(m_Module >=0); - if (0 <= m_Module) + if (!m_pStream) { - nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module); - if (pModule) - { - return pModule->Write(this, i_Buffer, len); + PR_ASSERT(m_Module >=0); + if (0 <= m_Module) + { + nsCacheModule* pModule = nsCacheManager::GetInstance()->GetModule(m_Module); + if (pModule) + { + m_pStream = pModule->GetStreamFor(this); + if (m_pStream) + return m_pStream->Write(i_Buffer, len); + } } + return 0; } - return 0; + return m_pStream->Write(i_Buffer, len); } diff --git a/mozilla/network/cache/nu/src/nsDiskModule.cpp b/mozilla/network/cache/nu/src/nsDiskModule.cpp index b657d38ed39..be44c814474 100644 --- a/mozilla/network/cache/nu/src/nsDiskModule.cpp +++ b/mozilla/network/cache/nu/src/nsDiskModule.cpp @@ -63,7 +63,7 @@ nsDiskModule::~nsDiskModule() PRBool nsDiskModule::AddObject(nsCacheObject* io_pObject) { - ENSURE_INIT; + ENSURE_INIT; if (!m_pDB || !io_pObject) { @@ -73,7 +73,7 @@ PRBool nsDiskModule::AddObject(nsCacheObject* io_pObject) if (io_pObject->Address()) { - MonitorLocker ml(this); + MonitorLocker ml(this); // TODO optimize these further- make static - Gagan DBT* key = PR_NEW(DBT); DBT* data = PR_NEW(DBT); @@ -82,7 +82,7 @@ PRBool nsDiskModule::AddObject(nsCacheObject* io_pObject) key->data = (void*)io_pObject->Address(); - /* Later on change this to include post data- io_pObject->KeyData() */ + /* Later on change this to include post data- io_pObject->KeyData() */ key->size = PL_strlen(io_pObject->Address()); data->data = io_pObject->Info(); @@ -140,7 +140,7 @@ PRBool nsDiskModule::Contains(const char* i_url) const void nsDiskModule::GarbageCollect(void) { - MonitorLocker ml(this); + MonitorLocker ml(this); } nsCacheObject* nsDiskModule::GetObject(const PRUint32 i_index) const @@ -174,9 +174,15 @@ nsCacheObject* nsDiskModule::GetObject(const char* i_url) const return 0; } +nsStream* nsDiskModule::GetStreamFor(const nsCacheObject* i_pObject) +{ + ENSURE_INIT; + return 0; +} + PRBool nsDiskModule::InitDB(void) { - MonitorLocker ml(this); + MonitorLocker ml(this); if (m_pDB) return PR_TRUE; @@ -219,11 +225,6 @@ 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 @@ -267,10 +268,4 @@ void nsDiskModule::SetSize(const PRUint32 i_Size) } } -PRUint32 nsDiskModule::Write(nsCacheObject* pObject, const char* i_Buffer, PRUint32 len) -{ - ENSURE_INIT; - return 0; -} - #undef ENSURE_INIT diff --git a/mozilla/network/cache/nu/src/nsFileStream.cpp b/mozilla/network/cache/nu/src/nsFileStream.cpp new file mode 100644 index 00000000000..58ce98665d1 --- /dev/null +++ b/mozilla/network/cache/nu/src/nsFileStream.cpp @@ -0,0 +1,71 @@ +/* -*- 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. + */ + +#include "nsFileStream.h" + +nsFileStream::nsFileStream(XP_File* i_pFile):m_pFile(i_pFile) +{ + PR_ASSERT(m_pFile); +} + +nsFileStream::~nsFileStream() +{ +} + +/* +nsrefcnt nsFileStream::AddRef(void) +{ + return ++m_RefCnt; +} +nsrefcnt nsFileStream::Release(void) +{ + if (--m_RefCnt == 0) + { + delete this; + return 0; + } + return m_RefCnt; +} + +nsresult nsFileStream::QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + return NS_OK; +} +*/ + +PRInt32 nsFileStream::Read(void* o_Buffer, PRUint32 i_Len) +{ + if (m_pFile) + { + int status = XP_FileRead(o_Buffer, i_Len, *m_pFile); + return status; + } + return 0; +} + +PRInt32 nsFileStream::Write(const void* i_Buffer, PRUint32 i_Len) +{ + if (m_pFile) + { + int status = XP_FileWrite(i_Buffer, i_Len, *m_pFile); + return status; + } + return 0; +} \ No newline at end of file diff --git a/mozilla/network/cache/nu/src/nsMemModule.cpp b/mozilla/network/cache/nu/src/nsMemModule.cpp index c5544c91beb..283fe34c581 100644 --- a/mozilla/network/cache/nu/src/nsMemModule.cpp +++ b/mozilla/network/cache/nu/src/nsMemModule.cpp @@ -165,6 +165,12 @@ nsCacheObject* nsMemModule::GetObject(const char* i_url) const return 0; } +nsStream* nsMemModule::GetStreamFor(const nsCacheObject* i_pObject) +{ + MonitorLocker ml(this); + return 0; +} + nsMemCacheObject* nsMemModule::LastObject(void) const { MonitorLocker ml((nsMonitorable*)this); @@ -179,11 +185,6 @@ nsMemCacheObject* nsMemModule::LastObject(void) const return pLast; } -PRUint32 nsMemModule::Read(nsCacheObject* pObject, char* o_Buffer, PRUint32 len) -{ - return 0; -} - PRBool nsMemModule::ReduceSizeTo(const PRUint32 i_NewSize) { //TODO @@ -202,11 +203,6 @@ PRBool nsMemModule::Remove(const PRUint32 i_index) 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) { diff --git a/mozilla/network/cache/nu/src/nsMemStream.cpp b/mozilla/network/cache/nu/src/nsMemStream.cpp new file mode 100644 index 00000000000..3d0c04ad9be --- /dev/null +++ b/mozilla/network/cache/nu/src/nsMemStream.cpp @@ -0,0 +1,59 @@ +/* -*- 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. + */ + +#include "nsMemStream.h" + +nsMemStream::nsMemStream() +{ +} + +nsMemStream::~nsMemStream() +{ +} +/* +nsrefcnt nsMemStream::AddRef(void) +{ + return ++m_RefCnt; +} +nsrefcnt nsMemStream::Release(void) +{ + if (--m_RefCnt == 0) + { + delete this; + return 0; + } + return m_RefCnt; +} + +nsresult nsMemStream::QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + return NS_OK; +} +*/ + +PRInt32 nsMemStream::Read(void* o_Buffer, PRUint32 i_Len) +{ + return 0; +} + +PRInt32 nsMemStream::Write(const void* i_Buffer, PRUint32 i_Len) +{ + return 0; +} \ No newline at end of file