initial entry, not part of build

This commit is contained in:
bienvenu%netscape.com 1999-07-15 02:57:37 +00:00
Родитель 994107ca5c
Коммит 002f013a17
6 изменённых файлов: 567 добавлений и 0 удалений

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

@ -0,0 +1,31 @@
/* -*- Mode: IDL; 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 "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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
interface nsIFileSpec;
interface nsIMsgFolderCacheElement;
[scriptable, uuid(d8a130f0-397d-11d3-8d76-00805f8a6617)]
interface nsIMsgFolderCache : nsISupports
{
void Init(in nsIFileSpec fileSpec);
nsIMsgFolderCacheElement GetCacheElement(in string uri, in boolean createIfMissing);
void Close();
};

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

@ -0,0 +1,30 @@
/* -*- Mode: IDL; 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 "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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
[scriptable, uuid(c3096590-3983-11d3-8d76-00805f8a6617)]
interface nsIMsgFolderCacheElement : nsISupports
{
attribute string URI;
string GetStringProperty(in string propertyName);
long GetInt32Property(in string propertyName);
void SetStringProperty(in string propertyName, in string propertyValue);
void SetInt32Property(in string propertyName, in long propertyValue);
};

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

@ -0,0 +1,309 @@
/* -*- 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 "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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "msgCore.h"
#include "nsMsgFolderCacheElement.h"
#include "nsMsgFolderCache.h"
#include "nsMorkCID.h"
#include "nsIMdbFactoryFactory.h"
#include "nsFileStream.h"
#include "nsXPIDLString.h"
static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
const char *kFoldersScope = "ns:msg:db:row:scope:folders:all"; // scope for all folders table
const char *kFoldersTableKind = "ns:msg:db:table:kind:folders";
nsMsgFolderCache::nsMsgFolderCache()
{
m_mdbEnv = nsnull;
m_mdbStore = nsnull;
m_mdbAllFoldersTable = nsnull;
}
// should this, could this be an nsCOMPtr ?
static nsIMdbFactory *gMDBFactory = nsnull;
nsMsgFolderCache::~nsMsgFolderCache()
{
NS_IF_RELEASE(gMDBFactory);
gMDBFactory = nsnull;
}
NS_IMPL_ISUPPORTS(nsMsgFolderCache, GetIID());
/* static */ nsIMdbFactory *nsMsgFolderCache::GetMDBFactory()
{
if (!gMDBFactory)
{
nsresult rv;
rv = nsComponentManager::CreateInstance(kCMorkFactory, nsnull, nsIMdbFactoryFactory::GetIID(), (void **) &gMDBFactory);
}
return gMDBFactory;
}
// initialize the various tokens and tables in our db's env
nsresult nsMsgFolderCache::InitMDBInfo()
{
nsresult err = NS_OK;
if (GetStore())
{
err = GetStore()->StringToToken(GetEnv(), kFoldersScope, &m_folderRowScopeToken);
if (err == NS_OK)
{
err = GetStore()->StringToToken(GetEnv(), kFoldersTableKind, &m_folderTableKindToken);
if (err == NS_OK)
{
// The table of all message hdrs will have table id 1.
m_allFoldersTableOID.mOid_Scope = m_folderRowScopeToken;
m_allFoldersTableOID.mOid_Id = 1;
}
}
}
return err;
}
// set up empty tables, dbFolderInfo, etc.
nsresult nsMsgFolderCache::InitNewDB()
{
nsresult err = NS_OK;
err = InitMDBInfo();
if (err == NS_OK)
{
nsIMdbStore *store = GetStore();
// create the unique table for the dbFolderInfo.
mdb_err mdberr;
mdberr = (nsresult) store->NewTable(GetEnv(), m_folderRowScopeToken,
m_folderTableKindToken, PR_FALSE, nsnull, &m_mdbAllFoldersTable);
}
return err;
}
nsresult nsMsgFolderCache::InitExistingDB()
{
nsresult err = NS_OK;
err = InitMDBInfo();
if (err == NS_OK)
{
err = GetStore()->GetTable(GetEnv(), &m_allFoldersTableOID, &m_mdbAllFoldersTable);
}
return err;
}
nsresult nsMsgFolderCache::OpenMDB(const char *dbName, PRBool create)
{
nsresult ret;
nsIMdbFactory *myMDBFactory = GetMDBFactory();
if (myMDBFactory)
{
ret = myMDBFactory->MakeEnv(NULL, &m_mdbEnv);
if (NS_SUCCEEDED(ret))
{
nsIMdbThumb *thumb = nsnull;
char *nativeFileName = nsCRT::strdup(dbName);
if (!nativeFileName)
return NS_ERROR_OUT_OF_MEMORY;
if (m_mdbEnv)
m_mdbEnv->SetAutoClear(PR_TRUE);
m_dbName = dbName;
#if defined(XP_PC) || defined(XP_MAC)
// UnixToNative(nativeFileName);
#endif
{
mdbOpenPolicy inOpenPolicy;
mdb_bool canOpen;
mdbYarn outFormatVersion;
char bufFirst512Bytes[512];
mdbYarn first512Bytes;
first512Bytes.mYarn_Buf = bufFirst512Bytes;
first512Bytes.mYarn_Size = 512;
first512Bytes.mYarn_Fill = 512;
first512Bytes.mYarn_Form = 0; // what to do with this? we're storing csid in the msg hdr...
{
nsIOFileStream *dbStream = new nsIOFileStream(nsFileSpec(dbName));
if (dbStream)
{
PRInt32 bytesRead = dbStream->read(bufFirst512Bytes, sizeof(bufFirst512Bytes));
first512Bytes.mYarn_Fill = bytesRead;
dbStream->close();
delete dbStream;
}
else
return NS_ERROR_OUT_OF_MEMORY;
}
ret = myMDBFactory->CanOpenFilePort(m_mdbEnv, nativeFileName, // the file to investigate
&first512Bytes, &canOpen, &outFormatVersion);
if (ret == 0 && canOpen)
{
inOpenPolicy.mOpenPolicy_ScopePlan.mScopeStringSet_Count = 0;
inOpenPolicy.mOpenPolicy_MinMemory = 0;
inOpenPolicy.mOpenPolicy_MaxLazy = 0;
ret = myMDBFactory->OpenFileStore(m_mdbEnv, NULL, nativeFileName, &inOpenPolicy,
&thumb);
}
else
ret = NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE;
}
if (NS_SUCCEEDED(ret) && thumb)
{
mdb_count outTotal; // total somethings to do in operation
mdb_count outCurrent; // subportion of total completed so far
mdb_bool outDone = PR_FALSE; // is operation finished?
mdb_bool outBroken; // is operation irreparably dead and broken?
do
{
ret = thumb->DoMore(m_mdbEnv, &outTotal, &outCurrent, &outDone, &outBroken);
if (ret != 0)
{// mork isn't really doing NS erorrs yet.
outDone = PR_TRUE;
break;
}
}
while (NS_SUCCEEDED(ret) && !outBroken && !outDone);
// m_mdbEnv->ClearErrors(); // ### temporary...
if (NS_SUCCEEDED(ret) && outDone)
{
ret = myMDBFactory->ThumbToOpenStore(m_mdbEnv, thumb, &m_mdbStore);
if (ret == NS_OK && m_mdbStore)
ret = InitExistingDB();
}
#ifdef DEBUG_bienvenu1
DumpContents();
#endif
}
else if (create) // ### need error code saying why open file store failed
{
mdbOpenPolicy inOpenPolicy;
inOpenPolicy.mOpenPolicy_ScopePlan.mScopeStringSet_Count = 0;
inOpenPolicy.mOpenPolicy_MinMemory = 0;
inOpenPolicy.mOpenPolicy_MaxLazy = 0;
ret = myMDBFactory->CreateNewFileStore(m_mdbEnv, NULL, dbName, &inOpenPolicy, &m_mdbStore);
if (ret == NS_OK)
ret = InitNewDB();
}
if(thumb)
{
thumb->CutStrongRef(m_mdbEnv);
}
nsCRT::free(nativeFileName);
}
}
return ret;
}
NS_IMETHODIMP nsMsgFolderCache::Init(nsIFileSpec *dbFileSpec)
{
if (!dbFileSpec)
return NS_ERROR_NULL_POINTER;
nsresult rv = NS_NewISupportsArray(getter_AddRefs(m_cacheElements));
if (NS_SUCCEEDED(rv))
{
rv = dbFileSpec->GetFileSpec(&m_dbFileSpec);
if (NS_SUCCEEDED(rv))
{
// if (!m_dbFileSpec->Exists())
}
}
return rv;
}
typedef struct _findCacheElementByURIEntry {
const char *m_uri;
nsIMsgFolderCacheElement *m_cacheElement;
} findCacheElementByURIEntry;
NS_IMETHODIMP nsMsgFolderCache::GetCacheElement(char *uri, PRBool createIfMissing,
nsIMsgFolderCacheElement **result)
{
if (!result || !uri)
return NS_ERROR_NULL_POINTER;
findCacheElementByURIEntry findEntry;
findEntry.m_uri = uri;
findEntry.m_cacheElement = nsnull;
m_cacheElements->EnumerateForwards(FindCacheElementByURI, (void *)&findEntry);
if (findEntry.m_cacheElement)
{
*result = findEntry.m_cacheElement;
NS_ADDREF(*result);
return NS_OK;
}
else if (createIfMissing)
{
*result = new nsMsgFolderCacheElement;
if (*result)
{
(*result)->SetURI(uri);
nsCOMPtr<nsISupports> supports(do_QueryInterface(*result));
if(supports)
m_cacheElements->AppendElement(supports);
return NS_OK;
}
}
return NS_COMFALSE;
}
NS_IMETHODIMP nsMsgFolderCache::Close()
{
return NS_OK;
}
PRBool
nsMsgFolderCache::FindCacheElementByURI(nsISupports *aElement, void *data)
{
nsresult rv;
nsCOMPtr<nsIMsgFolderCacheElement> cacheElement = do_QueryInterface(aElement, &rv);
if (NS_FAILED(rv)) return PR_TRUE;
findCacheElementByURIEntry *entry = (findCacheElementByURIEntry *) data;
nsXPIDLCString key;
rv = cacheElement->GetURI(getter_Copies(key));
if (NS_FAILED(rv)) return rv;
if (entry && entry->m_uri && !PL_strcmp(key, entry->m_uri ))
{
entry->m_cacheElement = cacheElement;
NS_ADDREF(entry->m_cacheElement);
return PR_FALSE;
}
return PR_TRUE;
}

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

@ -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 "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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsMsgFolderCache_H
#define nsMsgFolderCache_H
#include "nsIMsgFolderCache.h"
#include "nsIMsgFolderCacheElement.h"
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "mdb.h"
class nsMsgFolderCache : public nsIMsgFolderCache
{
public:
nsMsgFolderCache();
virtual ~nsMsgFolderCache();
NS_DECL_ISUPPORTS
//nsMsgFolderCache
NS_IMETHOD Init(nsIFileSpec *dbFileSpec);
NS_IMETHOD GetCacheElement(char *uri, PRBool createIfMissing,
nsIMsgFolderCacheElement **result);
NS_IMETHOD Close();
protected:
static PRBool FindCacheElementByURI(nsISupports *aElement, void *data);
static nsIMdbFactory *GetMDBFactory();
nsresult InitMDBInfo();
nsresult InitNewDB();
nsresult InitExistingDB();
nsresult OpenMDB(const char *dbName, PRBool create);
nsIMdbEnv *GetEnv() {return m_mdbEnv;}
nsIMdbStore *GetStore() {return m_mdbStore;}
nsFileSpec m_dbFileSpec;
nsCOMPtr <nsISupportsArray> m_cacheElements;
nsString2 m_dbName;
// mdb stuff
nsIMdbEnv *m_mdbEnv; // to be used in all the db calls.
nsIMdbStore *m_mdbStore;
nsIMdbTable *m_mdbAllFoldersTable;
mdb_token m_folderRowScopeToken;
mdb_token m_folderTableKindToken;
struct mdbOid m_allFoldersTableOID;
};
#endif

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

@ -0,0 +1,70 @@
/* -*- 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 "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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "msgCore.h"
#include "nsMsgFolderCacheElement.h"
nsMsgFolderCacheElement::nsMsgFolderCacheElement()
{
m_mdbRow = nsnull;
m_owningCache = nsnull;
m_folderURI = nsnull;
}
nsMsgFolderCacheElement::~nsMsgFolderCacheElement()
{
NS_IF_RELEASE(m_mdbRow);
NS_IF_RELEASE(m_owningCache);
PR_FREEIF(m_folderURI);
}
NS_IMPL_ISUPPORTS(nsMsgFolderCacheElement, GetIID());
NS_IMPL_GETTER_STR(nsMsgFolderCacheElement::GetURI, m_folderURI)
NS_IMPL_SETTER_STR(nsMsgFolderCacheElement::SetURI, m_folderURI)
NS_IMETHODIMP nsMsgFolderCacheElement::GetStringProperty(const char *propertyName, char **result)
{
if (!propertyName || !result || !m_mdbRow)
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgFolderCacheElement::GetInt32Property(const char *propertyName, PRInt32 *result)
{
if (!propertyName || !result || !m_mdbRow)
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgFolderCacheElement::SetStringProperty(const char *propertyName, const char *propertyValue)
{
if (!propertyName || !m_mdbRow)
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsMsgFolderCacheElement::SetInt32Property(const char *propertyName, PRInt32 propertyValue)
{
if (!propertyName || !m_mdbRow)
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -0,0 +1,56 @@
/* -*- 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 "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) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsMsgFolderCacheElement_H
#define nsMsgFolderCacheElement_H
#include "nsIMsgFolderCacheElement.h"
#include "nsMsgFolderCache.h"
#include "mdb.h"
class nsMsgFolderCacheElement : public nsIMsgFolderCacheElement
{
public:
nsMsgFolderCacheElement();
virtual ~nsMsgFolderCacheElement();
NS_DECL_ISUPPORTS
//nsMsgFolderCacheElement
NS_IMETHOD GetStringProperty(const char *propertyName, char **result);
NS_IMETHOD GetInt32Property(const char *propertyName, PRInt32 *result);
NS_IMETHOD SetStringProperty(const char *propertyName, const char *propertyValue);
NS_IMETHOD SetInt32Property(const char *propertyName, PRInt32 propertyValue);
/* readonly attribute string URI; */
NS_IMETHOD GetURI(char * *aURI);
NS_IMETHOD SetURI(char *aURI);
protected:
nsIMdbRow *m_mdbRow;
nsMsgFolderCache *m_owningCache; // this will be ref-counted. Is this going to be a problem?
// I want to avoid circular references, but since this is
// scriptable, I think I have to ref-count it.
char *m_folderURI;
};
#endif