mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 20:49:27 +00:00
New modular cache files.
This commit is contained in:
parent
b4e6ab5c73
commit
ff6bbf1d84
26
network/cache/nu/Makefile
vendored
Normal file
26
network/cache/nu/Makefile
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
DIRS = public include src tests
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
24
network/cache/nu/include/Makefile
vendored
Normal file
24
network/cache/nu/include/Makefile
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
|
||||
DEPTH = ../../..
|
||||
|
||||
MODULE = cache
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
18
network/cache/nu/include/makefile.win
vendored
Normal file
18
network/cache/nu/include/makefile.win
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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 $(MOZ_SRC)\ns\config\rules.mak
|
77
network/cache/nu/include/nsCacheTrace.h
vendored
Normal file
77
network/cache/nu/include/nsCacheTrace.h
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/* -*- 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 _nsCacheTrace_H_
|
||||
#define _nsCacheTrace_H_
|
||||
/*
|
||||
* nsCacheTrace
|
||||
*
|
||||
* Gagan Saksena
|
||||
* 02/02/98
|
||||
*
|
||||
*/
|
||||
#ifndef CRLF
|
||||
# define CRLF "\r\n"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define APPEND(x) \
|
||||
if (total) { \
|
||||
total = (char*) realloc (total, strlen(total) + strlen(x) +1); \
|
||||
if (total == 0) \
|
||||
return 0; \
|
||||
strcat(total, x); \
|
||||
} \
|
||||
else { \
|
||||
total = (char*) malloc (strlen(x)+1); \
|
||||
if (total == 0) \
|
||||
return 0; \
|
||||
strcpy(total, x); }
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class nsCacheTrace
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static void Trace(const char* msg);
|
||||
static void Traceln(const char* msg);
|
||||
static void Use(char* buffer);
|
||||
static char* m_TraceBuffer;
|
||||
private:
|
||||
nsCacheTrace();
|
||||
};
|
||||
|
||||
inline void nsCacheTrace::Trace(const char* msg)
|
||||
{
|
||||
printf(msg);
|
||||
}
|
||||
|
||||
inline void nsCacheTrace::Traceln(const char* msg)
|
||||
{
|
||||
Trace(msg);
|
||||
Trace(CRLF);
|
||||
}
|
||||
|
||||
inline void nsCacheTrace::Use(char* buffer)
|
||||
{
|
||||
m_TraceBuffer = buffer;
|
||||
}
|
||||
#endif
|
22
network/cache/nu/makefile.win
vendored
Normal file
22
network/cache/nu/makefile.win
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
49
network/cache/nu/nsGeneric.cpp
vendored
Normal file
49
network/cache/nu/nsGeneric.cpp
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/* -*- 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 "nsGeneric.h"
|
||||
|
||||
nsGeneric::nsGeneric()
|
||||
{
|
||||
}
|
||||
|
||||
nsGeneric::~nsGeneric()
|
||||
{
|
||||
}
|
||||
|
||||
nsrefcnt nsGeneric::AddRef(void)
|
||||
{
|
||||
return ++m_RefCnt;
|
||||
}
|
||||
nsrefcnt nsGeneric::Release(void)
|
||||
{
|
||||
if (--m_RefCnt == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return m_RefCnt;
|
||||
}
|
||||
|
||||
nsresult nsGeneric::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsGeneric::
|
43
network/cache/nu/nsGeneric.h
vendored
Normal file
43
network/cache/nu/nsGeneric.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- 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 nsGeneric_h__
|
||||
#define nsGeneric_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsGeneric: public nsISupports
|
||||
{
|
||||
|
||||
public:
|
||||
nsGeneric();
|
||||
virtual ~nsGeneric();
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
nsGeneric(const nsGeneric& o);
|
||||
nsGeneric& operator=(const nsGeneric& o);
|
||||
}
|
||||
#endif // nsGeneric_h__
|
||||
|
28
network/cache/nu/public/Makefile
vendored
Normal file
28
network/cache/nu/public/Makefile
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=../../..
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheObject.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = cache
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
27
network/cache/nu/public/makefile.win
vendored
Normal file
27
network/cache/nu/public/makefile.win
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
MODULE=cache
|
||||
|
||||
EXPORTS=nsCacheObject.h nsMemModule.h nsCacheManager.h \
|
||||
nsDiskModule.h nsCacheModule.h nsMemCacheObject.h
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
65
network/cache/nu/public/nsCacheManager.h
vendored
Normal file
65
network/cache/nu/public/nsCacheManager.h
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/* -*- 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 _CacheManager_H_
|
||||
#define _CacheManager_H_
|
||||
/*
|
||||
* nsCacheManager
|
||||
*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include "nsISupports.h"
|
||||
#endif
|
||||
|
||||
#include "nsCacheModule.h"
|
||||
#include "nsCacheObject.h"
|
||||
|
||||
class nsCacheManager //: public nsISupports
|
||||
{
|
||||
|
||||
public:
|
||||
nsCacheManager();
|
||||
~nsCacheManager();
|
||||
|
||||
int AddModule(nsCacheModule* i_cacheModule);
|
||||
int Contains(const char* i_url) const;
|
||||
int Entries() const;
|
||||
/* Singleton */
|
||||
static nsCacheManager*
|
||||
GetInstance();
|
||||
nsCacheObject* GetObject(const char* i_url) const;
|
||||
nsCacheModule* GetModule(int i_index) const;
|
||||
const char* Trace() const;
|
||||
/* Performance measure- TODO change to microsec PR_ */
|
||||
int WorstCaseTime() const;
|
||||
protected:
|
||||
nsCacheModule*
|
||||
LastModule() const;
|
||||
|
||||
|
||||
private:
|
||||
nsCacheModule* m_pFirstModule;
|
||||
|
||||
nsCacheManager(const nsCacheManager& cm);
|
||||
nsCacheManager& operator=(const nsCacheManager& cm);
|
||||
};
|
||||
|
||||
#endif
|
128
network/cache/nu/public/nsCacheModule.h
vendored
Normal file
128
network/cache/nu/public/nsCacheModule.h
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
/* -*- 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 nsCacheModule_h__
|
||||
#define nsCacheModule_h__
|
||||
|
||||
/*
|
||||
* nsCacheModule
|
||||
*
|
||||
* Gagan Saksena 02/03/98
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsCacheObject.h"
|
||||
//class nsCacheObject;
|
||||
/* Why the hell is forward decl. not working? */
|
||||
|
||||
class nsCacheModule
|
||||
{
|
||||
|
||||
public:
|
||||
nsCacheModule();
|
||||
nsCacheModule(const long i_size);
|
||||
|
||||
virtual
|
||||
~nsCacheModule();
|
||||
|
||||
virtual
|
||||
int AddObject(nsCacheObject* i_pObject)=0;
|
||||
virtual
|
||||
int Contains(const char* i_url) const=0;
|
||||
virtual
|
||||
int Contains(nsCacheObject* i_pObject) const=0;
|
||||
void Enable(int i_Enable);
|
||||
const int Entries() const;
|
||||
nsCacheObject* GetFirstObject() const ;
|
||||
|
||||
virtual
|
||||
nsCacheObject* GetObject(const char* i_url) const=0;
|
||||
|
||||
virtual
|
||||
nsCacheObject* GetObject(long i_index) const =0;
|
||||
|
||||
int IsEnabled() const;
|
||||
nsCacheModule* Next() const;
|
||||
void Next(nsCacheModule*);
|
||||
const long Size() const;
|
||||
const char* Trace() const;
|
||||
|
||||
protected:
|
||||
|
||||
void Size(const long i_size);
|
||||
|
||||
int m_Entries;
|
||||
long m_Size;
|
||||
int m_Enabled;
|
||||
|
||||
nsCacheModule* m_pNext;
|
||||
|
||||
private:
|
||||
nsCacheModule(const nsCacheModule& cm);
|
||||
nsCacheModule& operator=(const nsCacheModule& cm);
|
||||
|
||||
};
|
||||
|
||||
#if 0 // XXX remove
|
||||
inline int nsCacheModule::Contains(nsCacheObject* i_pObject) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void nsCacheModule::Enable(int i_Enable)
|
||||
{
|
||||
m_Enabled = (i_Enable > 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
inline int nsCacheModule::IsEnabled() const
|
||||
{
|
||||
return m_Enabled;
|
||||
}
|
||||
|
||||
inline const int nsCacheModule::Entries() const
|
||||
{
|
||||
return m_Entries;
|
||||
}
|
||||
|
||||
inline nsCacheObject* nsCacheModule::GetFirstObject() const
|
||||
{
|
||||
return this->GetObject((long)0);
|
||||
}
|
||||
|
||||
inline nsCacheModule* nsCacheModule::Next() const
|
||||
{
|
||||
return m_pNext;
|
||||
}
|
||||
|
||||
inline void nsCacheModule::Next(nsCacheModule* pNext)
|
||||
{
|
||||
m_pNext = pNext;
|
||||
}
|
||||
|
||||
inline const long nsCacheModule::Size() const
|
||||
{
|
||||
return m_Size;
|
||||
}
|
||||
|
||||
inline void nsCacheModule::Size(const long size)
|
||||
{
|
||||
m_Size = size;
|
||||
}
|
||||
|
||||
#endif // nsCacheModule_h__
|
156
network/cache/nu/public/nsCacheObject.h
vendored
Normal file
156
network/cache/nu/public/nsCacheObject.h
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
/* -*- 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 nsCacheObject_h__
|
||||
#define nsCacheObject_h__
|
||||
|
||||
#if 0
|
||||
#include "nsISupports.h"
|
||||
#endif
|
||||
|
||||
class nsCacheObject //: public nsISupports
|
||||
{
|
||||
|
||||
public:
|
||||
enum state_flags
|
||||
{
|
||||
INIT=0x000000,
|
||||
PARTIAL=0x000001
|
||||
};
|
||||
|
||||
nsCacheObject();
|
||||
nsCacheObject(const nsCacheObject& another);
|
||||
nsCacheObject(const char* i_url);
|
||||
|
||||
virtual ~nsCacheObject();
|
||||
|
||||
/*
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
*/
|
||||
|
||||
void Address(const char* i_url);
|
||||
const char* Address(void) const;
|
||||
|
||||
void Etag(const char* i_etag);
|
||||
const char* Etag(void) const;
|
||||
|
||||
long Expires(void) const;
|
||||
void Expires(long i_Expires);
|
||||
|
||||
int Hits(void) const;
|
||||
int IsExpired(void) const;
|
||||
int IsPartial(void) const;
|
||||
long LastAccessed(void) const;
|
||||
|
||||
long LastModified(void) const;
|
||||
void LastModified(long i_lastModified);
|
||||
|
||||
long Size(void) const;
|
||||
void Size(long s);
|
||||
|
||||
const char* Trace() const;
|
||||
|
||||
// virtual void getReadStream();
|
||||
// virtual void getWriteStream();
|
||||
|
||||
protected:
|
||||
|
||||
void Init();
|
||||
|
||||
char* m_Etag;
|
||||
long m_Expires;
|
||||
int m_Flags;
|
||||
int m_Hits;
|
||||
long m_LastAccessed;
|
||||
long m_LastModified;
|
||||
long m_Size;
|
||||
char* m_Url;
|
||||
|
||||
private:
|
||||
nsCacheObject& operator=(const nsCacheObject& x);
|
||||
};
|
||||
|
||||
inline const char* nsCacheObject::Address(void) const
|
||||
{
|
||||
return m_Url;
|
||||
}
|
||||
|
||||
inline const char* nsCacheObject::Etag(void) const
|
||||
{
|
||||
return m_Etag;
|
||||
}
|
||||
|
||||
inline long nsCacheObject::Expires(void) const
|
||||
{
|
||||
return m_Expires;
|
||||
};
|
||||
|
||||
inline void nsCacheObject::Expires(long i_Expires)
|
||||
{
|
||||
m_Expires = i_Expires;
|
||||
}
|
||||
|
||||
inline int nsCacheObject::Hits(void) const
|
||||
{
|
||||
return m_Hits;
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
inline int nsCacheObject::IsExpired(void) const
|
||||
{
|
||||
time_t now = time();
|
||||
return (m_Expires <= now) ? 1 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline int nsCacheObject::IsPartial(void) const
|
||||
{
|
||||
return (m_Flags & nsCacheObject::PARTIAL) ? 1 : 0;
|
||||
}
|
||||
|
||||
inline long nsCacheObject::LastAccessed(void) const
|
||||
{
|
||||
return m_LastAccessed;
|
||||
}
|
||||
|
||||
inline long nsCacheObject::LastModified(void) const
|
||||
{
|
||||
return m_LastModified;
|
||||
}
|
||||
|
||||
inline void nsCacheObject::LastModified(long i_LastModified)
|
||||
{
|
||||
m_LastModified = i_LastModified;
|
||||
}
|
||||
|
||||
inline long nsCacheObject::Size(void) const
|
||||
{
|
||||
return m_Size;
|
||||
}
|
||||
|
||||
inline void nsCacheObject::Size(long i_Size)
|
||||
{
|
||||
m_Size = i_Size;
|
||||
}
|
||||
|
||||
#endif // nsCacheObject_h__
|
||||
|
43
network/cache/nu/public/nsDiskModule.h
vendored
Normal file
43
network/cache/nu/public/nsDiskModule.h
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- 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 _nsDiskModule_H_
|
||||
#define _nsDiskModule_H_
|
||||
/*
|
||||
* nsDiskModule
|
||||
*
|
||||
* Gagan Saksena 02/03/98
|
||||
*
|
||||
*/
|
||||
#include "nsCacheModule.h"
|
||||
|
||||
class nsDiskModule : public nsCacheModule
|
||||
{
|
||||
|
||||
public:
|
||||
nsDiskModule();
|
||||
~nsDiskModule();
|
||||
int AddObject(nsCacheObject* i_pObject);
|
||||
nsCacheObject* GetObject(long i_index) const;
|
||||
|
||||
private:
|
||||
nsDiskModule(const nsDiskModule& dm);
|
||||
nsDiskModule& operator=(const nsDiskModule& dm);
|
||||
};
|
||||
|
||||
#endif
|
62
network/cache/nu/public/nsMemCacheObject.h
vendored
Normal file
62
network/cache/nu/public/nsMemCacheObject.h
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
/* -*- 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 _nsMemCacheObject_h_
|
||||
#define _nsMemCacheObject_h_
|
||||
|
||||
#include "nsCacheObject.h"
|
||||
|
||||
class nsMemCacheObject : public nsCacheObject
|
||||
{
|
||||
public:
|
||||
nsMemCacheObject(void);
|
||||
nsMemCacheObject(const nsCacheObject&);
|
||||
nsMemCacheObject(const char* i_url);
|
||||
~nsMemCacheObject();
|
||||
|
||||
void Next(nsCacheObject* pObject);
|
||||
nsMemCacheObject* Next(void) const;
|
||||
|
||||
private:
|
||||
nsMemCacheObject* m_pNextObject;
|
||||
/* The actual data of this cache object */
|
||||
char* m_pData;
|
||||
|
||||
nsMemCacheObject& operator=(const nsMemCacheObject& lco);
|
||||
|
||||
};
|
||||
|
||||
inline nsMemCacheObject::nsMemCacheObject(void):
|
||||
nsCacheObject(),
|
||||
m_pNextObject(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline nsMemCacheObject::nsMemCacheObject(const nsCacheObject& another):
|
||||
nsCacheObject(another),
|
||||
m_pNextObject(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline nsMemCacheObject::nsMemCacheObject(const char* i_url):
|
||||
nsCacheObject(i_url),
|
||||
m_pNextObject(0)
|
||||
{
|
||||
}
|
||||
|
||||
#endif //_nsMemCacheObject_h_
|
57
network/cache/nu/public/nsMemModule.h
vendored
Normal file
57
network/cache/nu/public/nsMemModule.h
vendored
Normal file
@ -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 _nsMemModule_H_
|
||||
#define _nsMemModule_H_
|
||||
/*
|
||||
* nsMemModule
|
||||
*
|
||||
* Gagan Saksena
|
||||
* 02/03/98
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsCacheModule.h"
|
||||
#include "nsMemCacheObject.h"
|
||||
|
||||
class nsMemModule : public nsCacheModule
|
||||
{
|
||||
|
||||
public:
|
||||
nsMemModule();
|
||||
nsMemModule(const long size);
|
||||
~nsMemModule();
|
||||
|
||||
int AddObject(nsCacheObject* i_pObject);
|
||||
int Contains(nsCacheObject* i_pObject) const;
|
||||
int Contains(const char* i_url) const;
|
||||
nsCacheObject* GetObject(long i_index) const;
|
||||
nsCacheObject* GetObject(const char* i_url) const;
|
||||
|
||||
// Start of nsMemModule specific stuff...
|
||||
// Here is a sample implementation using linked list
|
||||
protected:
|
||||
nsMemCacheObject* LastObject(void) const;
|
||||
|
||||
private:
|
||||
nsMemCacheObject* m_pFirstObject;
|
||||
|
||||
nsMemModule(const nsMemModule& mm);
|
||||
nsMemModule& operator=(const nsMemModule& mm);
|
||||
};
|
||||
|
||||
#endif
|
6
network/cache/nu/public/todo
vendored
Normal file
6
network/cache/nu/public/todo
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
move the following files here-
|
||||
|
||||
nsCacheManager.h
|
||||
nsCacheModule.h
|
||||
nsMemModule.h not if memmodule is being made in nsCacheManager
|
24
network/cache/nu/src/Makefile
vendored
Normal file
24
network/cache/nu/src/Makefile
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=../../..
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
TARGET = $(LIBRARY)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
67
network/cache/nu/src/makefile.win
vendored
Normal file
67
network/cache/nu/src/makefile.win
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = cachelib
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
LIBRARY_NAME=cachelib
|
||||
|
||||
MISCDEP = \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(LIBNSPR) \
|
||||
$(NULL)
|
||||
|
||||
MODULE = cache
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsCacheObject.obj \
|
||||
.\$(OBJDIR)\nsCacheModule.obj \
|
||||
.\$(OBJDIR)\nsMemModule.obj \
|
||||
.\$(OBJDIR)\nsDiskModule.obj \
|
||||
.\$(OBJDIR)\nsCacheTrace.obj \
|
||||
.\$(OBJDIR)\nsCacheManager.obj \
|
||||
.\$(OBJDIR)\nsMemCacheObject.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS = \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I..\public \
|
||||
-I..\include \
|
||||
$(NULL)
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
-DNS_DLLNAME=$(DLLNAME).dll \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(LIBNSPR) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
|
160
network/cache/nu/src/nsCacheManager.cpp
vendored
Normal file
160
network/cache/nu/src/nsCacheManager.cpp
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsCacheManager.h"
|
||||
#include "nsCacheTrace.h"
|
||||
#include "nsCacheModule.h"
|
||||
|
||||
#include <assert.h> // TODO change
|
||||
#include <time.h> //TODO change to PR_
|
||||
|
||||
static nsCacheManager TheManager;
|
||||
|
||||
nsCacheManager::nsCacheManager(): m_pFirstModule(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsCacheManager::~nsCacheManager()
|
||||
{
|
||||
#if 0
|
||||
// this is crashing!?!
|
||||
if (m_pFirstModule)
|
||||
delete m_pFirstModule;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsCacheManager* nsCacheManager::GetInstance()
|
||||
{
|
||||
return &TheManager;
|
||||
}
|
||||
|
||||
const char* nsCacheManager::Trace() const
|
||||
{
|
||||
|
||||
char linebuffer[128];
|
||||
char* total = 0;
|
||||
|
||||
sprintf(linebuffer, "nsCacheManager: Modules = %d\n", Entries());
|
||||
APPEND(linebuffer);
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
int nsCacheManager::AddModule(nsCacheModule* pModule)
|
||||
{
|
||||
if (pModule)
|
||||
{
|
||||
if (m_pFirstModule)
|
||||
LastModule()->Next(pModule);
|
||||
else
|
||||
m_pFirstModule = pModule;
|
||||
|
||||
return Entries()-1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int nsCacheManager::Contains(const char* i_url) const
|
||||
{
|
||||
if (m_pFirstModule)
|
||||
{
|
||||
nsCacheModule* pModule = m_pFirstModule;
|
||||
while (pModule)
|
||||
{
|
||||
if (pModule->Contains(i_url))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
pModule = pModule->Next();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCacheObject* nsCacheManager::GetObject(const char* i_url) const
|
||||
{
|
||||
if (m_pFirstModule)
|
||||
{
|
||||
nsCacheModule* pModule = m_pFirstModule;
|
||||
nsCacheObject* obj = 0;
|
||||
while (pModule)
|
||||
{
|
||||
obj = pModule->GetObject(i_url);
|
||||
if (obj)
|
||||
return obj;
|
||||
pModule = pModule->Next();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsCacheManager::Entries() const
|
||||
{
|
||||
if (m_pFirstModule)
|
||||
{
|
||||
int count=1;
|
||||
nsCacheModule* pModule = m_pFirstModule;
|
||||
while (pModule = pModule->Next())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCacheModule* nsCacheManager::GetModule(int i_index) const
|
||||
{
|
||||
if ((i_index < 0) || (i_index >= Entries()))
|
||||
return 0;
|
||||
nsCacheModule* pModule = m_pFirstModule;
|
||||
for (int i=0; i<=i_index; pModule = pModule->Next())
|
||||
i++;
|
||||
#ifdef DEBUG
|
||||
assert(pModule);
|
||||
#endif
|
||||
return pModule;
|
||||
}
|
||||
|
||||
nsCacheModule* nsCacheManager::LastModule() const
|
||||
{
|
||||
if (m_pFirstModule)
|
||||
{
|
||||
nsCacheModule* pModule = m_pFirstModule;
|
||||
while(pModule->Next()) {
|
||||
pModule = pModule->Next();
|
||||
}
|
||||
return pModule;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsCacheManager::WorstCaseTime() const
|
||||
{
|
||||
long delta = time(0);
|
||||
while (this->Contains("a vague string that should not be in any of the modules"));
|
||||
delta -= time(0);
|
||||
return delta*(-1);
|
||||
|
||||
}
|
64
network/cache/nu/src/nsCacheModule.cpp
vendored
Normal file
64
network/cache/nu/src/nsCacheModule.cpp
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
/* -*- 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 "nsCacheModule.h"
|
||||
#include "nsCacheTrace.h"
|
||||
|
||||
/*
|
||||
* nsCacheModule
|
||||
*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define DEFAULT_SIZE 10*0x100000L
|
||||
|
||||
nsCacheModule::nsCacheModule():
|
||||
m_Size(DEFAULT_SIZE),
|
||||
m_pNext(0),
|
||||
m_Entries(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsCacheModule::nsCacheModule(const long i_size):
|
||||
m_Size(i_size),
|
||||
m_pNext(0),
|
||||
m_Entries(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsCacheModule::~nsCacheModule()
|
||||
{
|
||||
if (m_pNext)
|
||||
{
|
||||
delete m_pNext;
|
||||
m_pNext = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char* nsCacheModule::Trace() const
|
||||
{
|
||||
char linebuffer[128];
|
||||
char* total = 0;
|
||||
|
||||
sprintf(linebuffer, "CacheModule: Objects = %d\n", Entries());
|
||||
APPEND(linebuffer);
|
||||
|
||||
return total;
|
||||
}
|
123
network/cache/nu/src/nsCacheObject.cpp
vendored
Normal file
123
network/cache/nu/src/nsCacheObject.cpp
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
/* -*- 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 <string.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "nsCacheObject.h"
|
||||
#include "nsCacheTrace.h"
|
||||
|
||||
/*
|
||||
* nsCacheObject
|
||||
*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
const int DEFAULT_EXPIRES = 86400;
|
||||
|
||||
nsCacheObject::nsCacheObject():
|
||||
m_Flags(INIT),
|
||||
m_Url(new char[1]),
|
||||
m_Etag(new char[1])
|
||||
{
|
||||
Init();
|
||||
*m_Url = '\0';
|
||||
*m_Etag = '\0';
|
||||
}
|
||||
|
||||
nsCacheObject::~nsCacheObject()
|
||||
{
|
||||
delete[] m_Url;
|
||||
delete[] m_Etag;
|
||||
}
|
||||
|
||||
nsCacheObject::nsCacheObject(const nsCacheObject& another):
|
||||
m_Flags(another.m_Flags),
|
||||
m_Url(new char[strlen(another.m_Url)+1]),
|
||||
m_Etag(new char[strlen(another.m_Etag)+1])
|
||||
{
|
||||
|
||||
strcpy(m_Url, another.m_Url);
|
||||
strcpy(m_Etag, another.m_Etag);
|
||||
|
||||
m_Hits = another.m_Hits;
|
||||
m_LastAccessed = another.m_LastAccessed;
|
||||
m_LastModified = another.m_LastModified;
|
||||
m_Size = another.m_Size;
|
||||
}
|
||||
|
||||
nsCacheObject::nsCacheObject(const char* i_url):
|
||||
m_Flags(INIT),
|
||||
m_Url(new char[strlen(i_url)+1]),
|
||||
m_Etag(new char[1])
|
||||
{
|
||||
Init();
|
||||
assert(i_url);
|
||||
strcpy(m_Url, i_url);
|
||||
}
|
||||
|
||||
void nsCacheObject::Address(const char* i_url)
|
||||
{
|
||||
assert(i_url);
|
||||
if (m_Url)
|
||||
delete[] m_Url;
|
||||
m_Url = new char[strlen(i_url) + 1];
|
||||
strcpy(m_Url, i_url);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
int nsCacheObject::IsExpired(void) const
|
||||
{
|
||||
time_t now = time(0);
|
||||
return (m_Expires > now) ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsCacheObject::Etag(const char* i_etag)
|
||||
{
|
||||
assert(i_etag && *i_etag);
|
||||
if (m_Etag)
|
||||
delete[] m_Etag;
|
||||
m_Etag = new char[strlen(i_etag) + 1];
|
||||
strcpy(m_Etag, i_etag);
|
||||
}
|
||||
|
||||
void nsCacheObject::Init()
|
||||
{
|
||||
time_t now = time(0);
|
||||
m_Expires = now + DEFAULT_EXPIRES;
|
||||
}
|
||||
|
||||
const char* nsCacheObject::Trace() const
|
||||
{
|
||||
char linebuffer[256];
|
||||
char* total = 0;
|
||||
|
||||
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,
|
||||
m_LastAccessed,
|
||||
m_Expires,
|
||||
m_Hits);
|
||||
APPEND(linebuffer);
|
||||
|
||||
return total;
|
||||
}
|
31
network/cache/nu/src/nsCacheTrace.cpp
vendored
Normal file
31
network/cache/nu/src/nsCacheTrace.cpp
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* nsCacheTrace
|
||||
*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsCacheTrace.h"
|
||||
|
||||
nsCacheTrace::nsCacheTrace()
|
||||
{
|
||||
|
||||
}
|
49
network/cache/nu/src/nsDiskModule.cpp
vendored
Normal file
49
network/cache/nu/src/nsDiskModule.cpp
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* nsDiskModule
|
||||
*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsDiskModule.h"
|
||||
#include "nsCacheObject.h"
|
||||
//
|
||||
// Constructor: nsDiskModule
|
||||
//
|
||||
nsDiskModule::nsDiskModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsDiskModule::~nsDiskModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsCacheObject* nsDiskModule::GetObject(long i_index) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsDiskModule::AddObject(nsCacheObject* i_pObject)
|
||||
{
|
||||
return 0;
|
||||
}
|
45
network/cache/nu/src/nsMemCacheObject.cpp
vendored
Normal file
45
network/cache/nu/src/nsMemCacheObject.cpp
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* nsMemCacheObject
|
||||
*
|
||||
* Gagan Saksena 04/22/98
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsMemCacheObject.h"
|
||||
|
||||
nsMemCacheObject::~nsMemCacheObject()
|
||||
{
|
||||
if (m_pNextObject)
|
||||
{
|
||||
delete m_pNextObject;
|
||||
m_pNextObject = 0;
|
||||
}
|
||||
}
|
||||
|
||||
nsMemCacheObject* nsMemCacheObject::Next(void) const
|
||||
{
|
||||
return m_pNextObject;
|
||||
}
|
||||
|
||||
void nsMemCacheObject::Next(nsCacheObject* pObject)
|
||||
{
|
||||
m_pNextObject = (nsMemCacheObject*) pObject;
|
||||
}
|
151
network/cache/nu/src/nsMemModule.cpp
vendored
Normal file
151
network/cache/nu/src/nsMemModule.cpp
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
/* -*- 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 "nsMemModule.h"
|
||||
#include "nsMemCacheObject.h"
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* nsMemModule
|
||||
*
|
||||
* Gagan Saksena 02/02/98
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
const long DEFAULT_SIZE = 5*1024*1024;
|
||||
|
||||
nsMemModule::nsMemModule():m_pFirstObject(0)
|
||||
{
|
||||
//Size(DEFAULT_SIZE);
|
||||
}
|
||||
|
||||
nsMemModule::nsMemModule(const long size):m_pFirstObject(0)
|
||||
{
|
||||
Size(size);
|
||||
}
|
||||
|
||||
nsMemModule::~nsMemModule()
|
||||
{
|
||||
if (m_pFirstObject) {
|
||||
delete m_pFirstObject;
|
||||
m_pFirstObject = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int nsMemModule::AddObject(nsCacheObject* i_pObject)
|
||||
{
|
||||
if (i_pObject)
|
||||
{
|
||||
if (m_pFirstObject)
|
||||
{
|
||||
LastObject()->Next(new nsMemCacheObject(*i_pObject));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pFirstObject = new nsMemCacheObject(*i_pObject);
|
||||
}
|
||||
m_Entries++;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int 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 1;
|
||||
pObj = pObj->Next();
|
||||
}
|
||||
while (pObj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsMemModule::Contains(nsCacheObject* i_pObject) const
|
||||
{
|
||||
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(long i_index) const
|
||||
{
|
||||
nsMemCacheObject* pNth = 0;
|
||||
if (m_pFirstObject)
|
||||
{
|
||||
int index = 0;
|
||||
pNth = m_pFirstObject;
|
||||
while (pNth->Next() && (index++ != i_index ))
|
||||
{
|
||||
pNth = pNth->Next();
|
||||
}
|
||||
}
|
||||
return pNth;
|
||||
}
|
||||
|
||||
nsCacheObject* nsMemModule::GetObject(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 pObj;
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user