more changes for moving creation of objects to the component manager and the news factory. a few nsCOMPtr changes. stop checking nsCOMPtrs against nsnull

This commit is contained in:
sspitzer%netscape.com 1999-06-03 18:09:54 +00:00
Родитель b6d916dddb
Коммит 4be3dd872f
18 изменённых файлов: 627 добавлений и 832 удалений

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

@ -77,4 +77,11 @@
{0x97, 0x3e, 0x00, 0x80, 0x5f, 0x91, 0x6f, 0xd3} \
}
#define NS_NNTPHOST_CID \
{ /* 339e5576-196a-11d3-929a-004005263078 */ \
0x339e5576, 0x196a, 0x11d3, \
{0x92, 0x9a, 0x00, 0x40, 0x05, 0x26, 0x30, 0x78} \
}
#endif // nsMsgNewsCID_h__

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

@ -39,6 +39,7 @@
#include "nsNNTPNewsgroupPost.h"
#include "nsNNTPNewsgroupList.h"
#include "nsNNTPArticleList.h"
#include "nsNNTPHost.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kNntpUrlCID, NS_NNTPURL_CID);
@ -51,6 +52,7 @@ static NS_DEFINE_CID(kNNTPNewsgroupCID, NS_NNTPNEWSGROUP_CID);
static NS_DEFINE_CID(kNNTPNewsgroupPostCID, NS_NNTPNEWSGROUPPOST_CID);
static NS_DEFINE_CID(kNNTPNewsgroupListCID, NS_NNTPNEWSGROUPLIST_CID);
static NS_DEFINE_CID(kNNTPArticleListCID, NS_NNTPARTICLELIST_CID);
static NS_DEFINE_CID(kNNTPHostCID, NS_NNTPHOST_CID);
static PRInt32 g_InstanceCount = 0;
static PRInt32 g_LockCount = 0;
@ -221,10 +223,28 @@ nsresult nsMsgNewsFactory::CreateInstance(nsISupports * /* aOuter */,
if (NS_FAILED(rv) && folder)
delete folder;
}
}
else if (mClassID.Equals(kNNTPHostCID))
{
nsNNTPHost *host = new nsNNTPHost();
if (host)
rv = host->QueryInterface(aIID, aResult);
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv) && host)
delete host;
}
else if (mClassID.Equals(kNntpIncomingServerCID))
{
rv = NS_NewNntpIncomingServer(nsISupports::GetIID(), aResult);
nsNntpIncomingServer *server = new nsNntpIncomingServer();
if (server)
rv = server->QueryInterface(aIID, aResult);
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv) && server)
delete server;
}
else if (mClassID.Equals(kNewsMessageResourceCID))
{
@ -292,8 +312,11 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kNntpUrlCID, nsnull, nsnull, path, PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(kNntpUrlCID,
"NNTP Url",
"component://netscape/messenger/nntpurl",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kNntpServiceCID, "NNTP Service",
@ -324,10 +347,6 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
#ifdef NS_DEBUG
printf("news registering from %s\n",path);
#endif
rv = compMgr->RegisterComponent(kNntpIncomingServerCID,
"Nntp Incoming Server",
"component://netscape/messenger/server&type=nntp",
@ -365,8 +384,12 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kNNTPHostCID,
"NNTP Host",
"component://netscape/messeneger/nntphost",
path, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
@ -411,6 +434,12 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* path)
rv = compMgr->UnregisterComponent(kNNTPNewsgroupListCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kNNTPArticleListCID, path);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kNNTPHostCID, path);
if (NS_FAILED(rv)) goto done;
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;

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

@ -1,29 +0,0 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsINNTPCategoryContainer.idl
*/
#ifndef __gen_nsINNTPCategoryContainer_h__
#define __gen_nsINNTPCategoryContainer_h__
#include "nsISupports.h" /* interface nsISupports */
#include "nsINNTPNewsgroup.h" /* interface nsINNTPNewsgroup */
#include "nsrootidl.h" /* interface nsrootidl */
/* starting interface: nsINNTPCategoryContainer */
/* {cb36d510-b249-11d2-b7ef-00805f05ffa5} */
#define NS_INNTPCATEGORYCONTAINER_IID_STR "cb36d510-b249-11d2-b7ef-00805f05ffa5"
#define NS_INNTPCATEGORYCONTAINER_IID \
{0xcb36d510, 0xb249, 0x11d2, \
{ 0xb7, 0xef, 0x00, 0x80, 0x5f, 0x05, 0xff, 0xa5 }}
class nsINNTPCategoryContainer : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_INNTPCATEGORYCONTAINER_IID)
/* attribute nsINNTPNewsgroup rootCategory; */
NS_IMETHOD GetRootCategory(nsINNTPNewsgroup * *aRootCategory) = 0;
NS_IMETHOD SetRootCategory(nsINNTPNewsgroup * aRootCategory) = 0;
};
#endif /* __gen_nsINNTPCategoryContainer_h__ */

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

@ -19,8 +19,12 @@
#include "nsISupports.idl"
#include "nsINNTPNewsgroup.idl"
interface nsINNTPNewsgroup;
[scriptable, uuid(cb36d510-b249-11d2-b7ef-00805f05ffa5)]
interface nsINNTPCategoryContainer : nsISupports {
attribute nsINNTPNewsgroup rootCategory;
void Initialize(in nsINNTPNewsgroup rootCategory);
};

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

@ -1,145 +0,0 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsINNTPHost.idl
*/
#ifndef __gen_nsINNTPHost_h__
#define __gen_nsINNTPHost_h__
#include "nsISupports.h" /* interface nsISupports */
#include "nsrootidl.h" /* interface nsrootidl */
#include "nsINNTPNewsgroup.h"
#include "nsINNTPNewsgroupList.h"
class nsINNTPNewsgroup; /* forward decl */
class nsINNTPNewsgroupList; /* forward decl */
/* starting interface: nsINNTPHost */
/* {6b128da0-d74f-11d2-b7f9-00805f05ffa5} */
#define NS_INNTPHOST_IID_STR "6b128da0-d74f-11d2-b7f9-00805f05ffa5"
#define NS_INNTPHOST_IID \
{0x6b128da0, 0xd74f, 0x11d2, \
{ 0xb7, 0xf9, 0x00, 0x80, 0x5f, 0x05, 0xff, 0xa5 }}
class nsINNTPHost : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_INNTPHOST_IID)
/* attribute boolean supportsExtensions; */
NS_IMETHOD GetSupportsExtensions(PRBool *aSupportsExtensions) = 0;
NS_IMETHOD SetSupportsExtensions(PRBool aSupportsExtensions) = 0;
/* void AddExtension (in string extension); */
NS_IMETHOD AddExtension(const char *extension) = 0;
/* boolean QueryExtension (in string extension); */
NS_IMETHOD QueryExtension(const char *extension, PRBool *_retval) = 0;
/* attribute boolean postingAllowed; */
NS_IMETHOD GetPostingAllowed(PRBool *aPostingAllowed) = 0;
NS_IMETHOD SetPostingAllowed(PRBool aPostingAllowed) = 0;
/* attribute boolean pushAuth; */
NS_IMETHOD GetPushAuth(PRBool *aPushAuth) = 0;
NS_IMETHOD SetPushAuth(PRBool aPushAuth) = 0;
/* attribute unsigned long lastUpdatedTime; */
NS_IMETHOD GetLastUpdatedTime(PRUint32 *aLastUpdatedTime) = 0;
NS_IMETHOD SetLastUpdatedTime(PRUint32 aLastUpdatedTime) = 0;
/* nsINNTPNewsgroupList GetNewsgroupList (in string name); */
NS_IMETHOD GetNewsgroupList(const char *name, nsINNTPNewsgroupList **_retval) = 0;
/* nsINNTPNewsgroup FindNewsgroup (in string name, in boolean create); */
NS_IMETHOD FindNewsgroup(const char *name, PRBool create, nsINNTPNewsgroup **_retval) = 0;
/* void AddPropertyForGet (in string name, in string value); */
NS_IMETHOD AddPropertyForGet(const char *name, const char *value) = 0;
/* string QueryPropertyForGet (in string name); */
NS_IMETHOD QueryPropertyForGet(const char *name, char **_retval) = 0;
/* void AddSearchableGroup (in string name); */
NS_IMETHOD AddSearchableGroup(const char *name) = 0;
/* boolean QuerySearchableGroup (in string name); */
NS_IMETHOD QuerySearchableGroup(const char *name, PRBool *_retval) = 0;
/* void AddVirtualGroup (in string responseText); */
NS_IMETHOD AddVirtualGroup(const char *responseText) = 0;
/* void SetIsVirtualGroup (in string name, in boolean isVirtual); */
NS_IMETHOD SetIsVirtualGroup(const char *name, PRBool isVirtual) = 0;
/* boolean GetIsVirtualGroup (in string name); */
NS_IMETHOD GetIsVirtualGroup(const char *name, PRBool *_retval) = 0;
/* void AddSearchableHeader (in string headerName); */
NS_IMETHOD AddSearchableHeader(const char *headerName) = 0;
/* boolean QuerySearchableHeader (in string headerName); */
NS_IMETHOD QuerySearchableHeader(const char *headerName, PRBool *_retval) = 0;
/* void GroupNotFound (in string group, in boolean opening); */
NS_IMETHOD GroupNotFound(const char *group, PRBool opening) = 0;
/* void AddNewNewsgroup (in string name, in long first, in long last, in string flags, in boolean xactiveFlags); */
NS_IMETHOD AddNewNewsgroup(const char *name, PRInt32 first, PRInt32 last, const char *flags, PRBool xactiveFlags) = 0;
/* long GetNumGroupsNeedingCounts (); */
NS_IMETHOD GetNumGroupsNeedingCounts(PRInt32 *_retval) = 0;
/* string GetFirstGroupNeedingCounts (); */
NS_IMETHOD GetFirstGroupNeedingCounts(char **_retval) = 0;
/* void DisplaySubscribedGroup (in string name, in long first_message, in long last_message, in long total_messages, in boolean visit_now); */
NS_IMETHOD DisplaySubscribedGroup(const char *name, PRInt32 first_message, PRInt32 last_message, PRInt32 total_messages, PRBool visit_now) = 0;
/* string GetFirstGroupNeedingExtraInfo (); */
NS_IMETHOD GetFirstGroupNeedingExtraInfo(char **_retval) = 0;
/* void SetGroupNeedsExtraInfo (in string name, in boolean needsExtraInfo); */
NS_IMETHOD SetGroupNeedsExtraInfo(const char *name, PRBool needsExtraInfo) = 0;
/* void GetNewsgroupAndNumberOfID (in string message_id, out nsINNTPNewsgroup group, out unsigned long message_number); */
NS_IMETHOD GetNewsgroupAndNumberOfID(const char *message_id, nsINNTPNewsgroup **group, PRUint32 *message_number) = 0;
/* void SetPrettyName (in string name, in string prettyName); */
NS_IMETHOD SetPrettyName(const char *name, const char *prettyName) = 0;
/* void LoadNewsrc (in string uri); */
NS_IMETHOD LoadNewsrc(const char *uri) = 0;
/* void WriteNewsrc (); */
NS_IMETHOD WriteNewsrc() = 0;
/* void WriteIfDirty (); */
NS_IMETHOD WriteIfDirty() = 0;
/* void MarkDirty (); */
NS_IMETHOD MarkDirty() = 0;
/* attribute string newsRCFilename; */
NS_IMETHOD GetNewsRCFilename(char * *aNewsRCFilename) = 0;
NS_IMETHOD SetNewsRCFilename(char * aNewsRCFilename) = 0;
/* nsINNTPNewsgroup FindGroup (in string name); */
NS_IMETHOD FindGroup(const char *name, nsINNTPNewsgroup **_retval) = 0;
/* nsINNTPNewsgroup AddGroup (in string name); */
NS_IMETHOD AddGroup(const char *name, nsINNTPNewsgroup **_retval) = 0;
/* void RemoveGroupByName (in string name); */
NS_IMETHOD RemoveGroupByName(const char *name) = 0;
/* void RemoveGroup (in nsINNTPNewsgroup group); */
NS_IMETHOD RemoveGroup(nsINNTPNewsgroup *group) = 0;
/* readonly attribute string dbDirName; */
NS_IMETHOD GetDbDirName(char * *aDbDirName) = 0;
/* string GetGroupList (); */
NS_IMETHOD GetGroupList(char **_retval) = 0;
};
#endif /* __gen_nsINNTPHost_h__ */

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

@ -29,6 +29,8 @@ interface nsINNTPNewsgroupList;
[scriptable, uuid(6b128da0-d74f-11d2-b7f9-00805f05ffa5)]
interface nsINNTPHost : nsISupports {
void Initialize(in string name, in long port);
attribute boolean supportsExtensions;
void AddExtension(in string extension);
boolean QueryExtension(in string extension);

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

@ -26,3 +26,5 @@ nsNewsFolder.h
nsNntpIncomingServer.h
nsNewsUtils.h
nsNNTPArticleList.h
nsNNTPHost.h
nsNNTPCategoryContainer.h

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

@ -38,6 +38,8 @@ EXPORTS = \
nsNntpIncomingServer.h \
nsNewsMessage.h \
nsNewsUtils.h \
nsNNTPHost.h \
nsNNTPCategoryContainer.h \
$(NULL)
CPPSRCS = \

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

@ -68,6 +68,8 @@ EXPORTS= nsNNTPProtocol.h \
nsNntpIncomingServer.h \
nsNewsMessage.h \
nsNewsUtils.h \
nsNNTPHost.h \
nsNNTPCategoryContainer.h \
$(NULL)
LINCS= \

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

@ -19,44 +19,23 @@
/* This is a stub event sink for a NNTP Newsgroup introduced by mscott to test
the NNTP protocol */
#include "nsISupports.h" /* interface nsISupports */
#include "nsINNTPCategoryContainer.h"
#include "nsINNTPNewsgroup.h" /* interface nsINNTPNewsgroup */
#include "nsNNTPCategoryContainer.h"
#include "nscore.h"
#include "plstr.h"
#include "prmem.h"
#include <stdio.h>
NS_IMPL_ISUPPORTS(nsNNTPCategoryContainer, nsINNTPCategoryContainer::GetIID());
class nsNNTPCategoryContainerStub : public nsISupports {
public:
nsNNTPCategoryContainerStub();
virtual ~nsNNTPCategoryContainerStub();
NS_DECL_ISUPPORTS
NS_IMETHOD GetRootCategory(nsINNTPNewsgroup * *aRootCategory);
NS_IMETHOD SetRootCategory(nsINNTPNewsgroup * aRootCategory);
protected:
nsINNTPNewsgroup * m_newsgroup;
};
NS_IMPL_ISUPPORTS(nsNNTPCategoryContainerStub, nsINNTPCategoryContainer::GetIID());
nsNNTPCategoryContainerStub::nsNNTPCategoryContainerStub()
nsNNTPCategoryContainer::nsNNTPCategoryContainer()
{
NS_INIT_REFCNT();
m_newsgroup = nsnull;
}
nsNNTPCategoryContainerStub::~nsNNTPCategoryContainerStub()
nsNNTPCategoryContainer::~nsNNTPCategoryContainer()
{
printf("Destroying category container. \n");
NS_IF_RELEASE(m_newsgroup);
}
nsresult nsNNTPCategoryContainerStub::GetRootCategory(nsINNTPNewsgroup * *aRootCategory)
nsresult nsNNTPCategoryContainer::GetRootCategory(nsINNTPNewsgroup * *aRootCategory)
{
if (aRootCategory)
{
@ -68,7 +47,13 @@ nsresult nsNNTPCategoryContainerStub::GetRootCategory(nsINNTPNewsgroup * *aRootC
}
nsresult nsNNTPCategoryContainerStub::SetRootCategory(nsINNTPNewsgroup * aRootCategory)
nsresult nsNNTPCategoryContainer::Initialize(nsINNTPNewsgroup * aRootCategory)
{
// for now, just set the root category.
return SetRootCategory(aRootCategory);
}
nsresult nsNNTPCategoryContainer::SetRootCategory(nsINNTPNewsgroup * aRootCategory)
{
if (aRootCategory)
{
@ -84,29 +69,3 @@ nsresult nsNNTPCategoryContainerStub::SetRootCategory(nsINNTPNewsgroup * aRootCa
}
extern "C" {
nsresult NS_NewCategoryContainerFromNewsgroup(nsINNTPCategoryContainer ** aInstancePtr, nsINNTPNewsgroup* group)
{
nsresult rv = NS_OK;
nsNNTPCategoryContainerStub * stub = nsnull;
if (aInstancePtr)
{
stub = new nsNNTPCategoryContainerStub();
if (stub) {
stub->SetRootCategory(group);
rv = stub->QueryInterface(nsINNTPCategoryContainer::GetIID(), (void **) aInstancePtr);
}
else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
if (NS_FAILED(rv) && stub) {
delete stub;
}
}
return rv;
}
}

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

@ -22,12 +22,25 @@
#include "nsINNTPCategoryContainer.h"
#include "nsINNTPNewsgroup.h"
NS_BEGIN_EXTERN_C
nsresult
NS_NewCategoryContainerFromNewsgroup(nsINNTPCategoryContainer **,
nsINNTPNewsgroup* );
#include "nsISupports.h" /* interface nsISupports */
#include "nscore.h"
#include "plstr.h"
#include "prmem.h"
//#include <stdio.h>
NS_END_EXTERN_C
class nsNNTPCategoryContainer : public nsISupports {
public:
nsNNTPCategoryContainer();
virtual ~nsNNTPCategoryContainer();
NS_DECL_ISUPPORTS
NS_IMETHOD GetRootCategory(nsINNTPNewsgroup * *aRootCategory);
NS_IMETHOD SetRootCategory(nsINNTPNewsgroup * aRootCategory);
NS_IMETHOD Initialize(nsINNTPNewsgroup * aRootCategory);
protected:
nsINNTPNewsgroup * m_newsgroup;
};
#endif

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

@ -16,52 +16,13 @@
* Reserved.
*/
#include "msgCore.h" // precompiled header...
#include "nsMsgFolderFlags.h"
#include "nntpCore.h"
#include "nsINNTPHost.h"
#include "nsINNTPCategory.h"
#include "nsINNTPCategoryContainer.h"
#include "nsNNTPCategoryContainer.h"
#include "nsNNTPHost.h"
#include "nsMsgKeySet.h"
#include "nsMsgGroupRecord.h"
#include "nsINNTPNewsgroup.h"
#include "nsNNTPNewsgroup.h"
#include "nsINNTPNewsgroupList.h"
#include "nsNNTPNewsgroupList.h"
#include "nsIMsgFolder.h"
#include "nsISupportsArray.h"
#include "nsIEnumerator.h"
#include "nsFileStream.h"
#include "nsNewsUtils.h"
#include "prprf.h"
#include "prmem.h"
#include "plstr.h"
#include "plhash.h"
#include "prio.h"
#include "nsCOMPtr.h"
#include "nsMsgNewsCID.h"
static NS_DEFINE_CID(kNNTPNewsgroupCID, NS_NNTPNEWSGROUP_CID);
static NS_DEFINE_CID(kNNTPNewsgroupListCID, NS_NNTPNEWSGROUPLIST_CID);
/* temporary hacks to test if this compiles */
typedef void MSG_GroupName;
#ifdef XP_UNIX
static const char LINEBREAK_START = '\012';
#else
@ -70,423 +31,25 @@ static const char LINEBREAK_START = '\015';
#define PROTOCOL_DEBUG
class nsNNTPHost : public nsINNTPHost {
public:
#ifdef HAVE_MASTER
nsNNTPHost(MSG_Master* master, const char* name,
PRInt32 port);
#else
nsNNTPHost(const char *name, PRInt32 port);
#endif
virtual ~nsNNTPHost();
NS_DECL_ISUPPORTS
// nsINNTPHost
NS_IMPL_CLASS_GETSET(SupportsExtensions, PRBool,
m_supportsExtensions);
NS_IMETHOD AddExtension (const char *ext);
NS_IMETHOD QueryExtension (const char *ext, PRBool *_retval);
NS_IMPL_CLASS_GETSET(PostingAllowed, PRBool, m_postingAllowed);
NS_IMPL_CLASS_GETTER(GetPushAuth, PRBool, m_pushAuth);
NS_IMETHOD SetPushAuth(PRBool value);
NS_IMPL_CLASS_GETSET(LastUpdatedTime, PRUint32, m_lastGroupUpdate);
NS_IMETHOD GetNewsgroupList(const char *name,nsINNTPNewsgroupList **_retval);
NS_IMETHOD GetNewsgroupAndNumberOfID(const char *message_id,
nsINNTPNewsgroup **group,
PRUint32 *messageNumber);
/* get this from MSG_Master::FindNewsFolder */
NS_IMETHOD FindNewsgroup(const char *name, PRBool create,
nsINNTPNewsgroup **_retval) { NS_ASSERTION(0, "unimplemented!"); return NS_OK;}
NS_IMETHOD AddPropertyForGet (const char *property, const char *value);
NS_IMETHOD QueryPropertyForGet (const char *property, char **_retval);
NS_IMETHOD AddSearchableGroup(const char *name);
// should these go into interfaces?
NS_IMETHOD QuerySearchableGroup (const char *group, PRBool *);
NS_IMETHOD QuerySearchableGroupCharsets(const char *group, char **);
// Virtual groups
NS_IMETHOD AddVirtualGroup(const char *responseText) { return NS_OK;}
NS_IMETHOD SetIsVirtualGroup(const char *name, PRBool isVirtual);
NS_IMETHOD SetIsVirtualGroup(const char *name, PRBool isVirtual,
nsMsgGroupRecord *inGroupRecord);
NS_IMETHOD GetIsVirtualGroup(const char *name, PRBool *_retval);
// custom/searchable headers
NS_IMETHOD AddSearchableHeader(const char *headerName);
NS_IMETHOD QuerySearchableHeader(const char *headerName, PRBool *_retval);
// Go load the newsrc for this host. Creates the subscribed hosts as
// children of the given nsIMsgFolder.
NS_IMETHOD LoadNewsrc(const char *uri);
// Write out the newsrc for this host right now. In general, either
// MarkDirty() or WriteIfDirty() should be called instead.
NS_IMETHOD WriteNewsrc();
// Write out the newsrc for this host right now, if anything has changed
// in it.
NS_IMETHOD WriteIfDirty();
// Note that something has changed, and we need to rewrite the newsrc file
// for this host at some point.
NS_IMETHOD MarkDirty();
/* the Setter implementation is a little more complex */
NS_IMPL_CLASS_GETTER(GetNewsRCFilename, char *, m_filename);
NS_IMETHOD SetNewsRCFilename(char *);
// helper for accessing the above accessors from within this class
// (this is what the pre-mozilla API looked like)
char *GetNewsrcFileName() { return m_filename; };
NS_IMETHOD FindGroup(const char* name, nsINNTPNewsgroup* *_retval);
NS_IMETHOD AddGroup(const char *name,
nsINNTPNewsgroup **_retval);
NS_IMETHOD AddGroup(const char *name,
nsMsgGroupRecord *groupRecord,
nsINNTPNewsgroup **_retval);
NS_IMETHOD RemoveGroupByName(const char *name);
NS_IMETHOD RemoveGroup(nsINNTPNewsgroup*);
NS_IMETHOD AddNewNewsgroup(const char *name,
PRInt32 first,
PRInt32 last,
const char *flags,
PRBool xactiveFlags);
/* Name of directory to store newsgroup
databases in. This needs to have
"/name" appended to it, and the
whole thing can be passed to the XP_File
stuff with a type of xpXoverCache. */
NS_IMETHOD GetDbDirName(char * *aDbDirName) {NS_ASSERTION(0, "unimplemented"); return NS_OK;};
/* helper for internal accesses - part of the Pre-Mozilla API) */
const char *GetDBDirName();
/* Returns a list of newsgroups. The result
must be free'd using PR_Free(); the
individual strings must not be free'd. */
NS_IMETHOD GetGroupList(char **_retval) { return NS_OK;}
NS_IMETHOD DisplaySubscribedGroup(const char *name,
PRInt32 first_message,
PRInt32 last_message,
PRInt32 total_messages,
PRBool visit_now);
// end of nsINNTPHost
private:
nsresult LoadNewsrcFileAndCreateNewsgroups(nsFileSpec &newsrcFile);
nsresult MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, nsFileSpec &newsrcFile);
nsresult GetNewsrcFile(char *newshostname, nsFileSpec &path, nsFileSpec &newsrcFile);
// simplify the QueryInterface calls
static nsIMsgFolder *getFolderFor(nsINNTPNewsgroup *group);
static nsIMsgFolder *getFolderFor(nsINNTPCategoryContainer *catContainer);
NS_METHOD CleanUp();
virtual PRBool IsNews () { return PR_TRUE; }
virtual nsINNTPHost *GetNewsHost() { return this; }
//
void addNew(MSG_GroupName* group);
void ClearNew();
virtual void dump();
virtual PRInt32 getPort();
// Return the name of this newshost.
const char* getStr();
// Returns the name of this newshost, possibly followed by ":<port>" if
// the port number for this newshost is not the default.
const char* getNameAndPort();
// Returns a fully descriptive name for this newshost, including the
// above ":<port>" and also possibly a trailing (and localized) property
virtual const char* getFullUIName();
// Get the nsIMsgFolder which represents this host; the children
// of this nsIMsgFolder are the groups in this host.
nsIMsgFolder* GetHostInfo() {return m_hostinfo;}
#ifdef HAVE_MASTER
MSG_Master* GetMaster() {
return m_master;
}
#endif
// GetNumGroupsNeedingCounts() returns how many newsgroups we have
// that we don't have an accurate count of unread/total articles.
NS_IMETHOD GetNumGroupsNeedingCounts(PRInt32 *);
// GetFirstGroupNeedingCounts() returns the name of the first newsgroup
// that does not have an accurate count of unread/total articles. The
// string must be free'd by the caller using PR_Free().
NS_IMETHOD GetFirstGroupNeedingCounts(char **);
// GetFirstGroupNeedingExtraInfo() returns the name of the first newsgroup
// that does not have extra info (xactive flags and prettyname). The
// string must be free'd by the caller using PR_Free().
NS_IMETHOD GetFirstGroupNeedingExtraInfo(char **);
void SetWantNewTotals(PRBool value); // Sets this bit on every newsgroup
// in this host.
PRBool NeedsExtension (const char *ext);
// Returns the base part of the URL for this newshost, in the
// form "news://hostname:port" or "snews://hostname:port".
// Note that no trailing slash is appended, and that the
// ":port" part will be omitted if this host uses the default
// port.
const char* GetURLBase();
PRBool GetEverExpanded() {return m_everexpanded;}
void SetEverExpanded(PRBool value) {m_everexpanded = value;}
PRBool GetCheckedForNew() {return m_checkedForNew;}
void SetCheckedForNew(PRBool value) {m_checkedForNew = value;}
void SetGroupSucceeded(PRBool value) {m_groupSucceeded = value;}
// Completely obliterate this news host. Remove all traces of it from
// disk and memory.
int RemoveHost();
int DeleteFiles();
// Returns the pretty name for the given group. The resulting string
// must be free'd using delete[].
char* GetPrettyName(char* name);
NS_IMETHOD SetPrettyName(const char* name, const char* prettyname);
PRTime GetAddTime(char* name);
// Returns a unique integer associated with this newsgroup. This is
// mostly used by Win16 to generate a 8.3 filename.
PRInt32 GetUniqueID(char* name);
PRBool IsCategory(char* name);
PRBool IsCategoryContainer(char* name);
int SetIsCategoryContainer(const char* name, PRBool value, nsMsgGroupRecord *inGroupRecord = NULL);
NS_IMETHOD SetGroupNeedsExtraInfo(const char *name, PRBool value);
// Finds the container newsgroup for this category (or NULL if this isn't
// a category). The resulting string must be free'd using delete[].
char* GetCategoryContainer(const char* name, nsMsgGroupRecord *inGroupRecord = NULL);
nsINNTPNewsgroup *GetCategoryContainerFolderInfo(const char *name);
// Get/Set whether this is a real group (as opposed to a container of
// other groups, like "mcom".)
PRBool IsGroup(char* name);
int SetIsGroup(char* name, PRBool value);
// Returns PR_TRUE if it's OK to post HTML in this group (either because the
// bit is on for this group, or one of this group's ancestor's has marked
// all of its descendents as being OK for HTML.)
PRBool IsHTMLOk(char* name);
// Get/Set if it's OK to post HTML in just this group.
PRBool IsHTMLOKGroup(char* name);
int SetIsHTMLOKGroup(char* name, PRBool value);
// Get/Set if it's OK to post HTML in this group and all of its subgroups.
PRBool IsHTMLOKTree(char* name);
int SetIsHTMLOKTree(char* name, PRBool value);
// Create the given group (if not already present). Returns 0 if the
// group is already present, 1 if we had to create it, negative on error.
// The given group will have the "isgroup" bit set on it (in other words,
// it is not to be just a container of other groups, like "mcom" is.)
int NoticeNewGroup(const char* name, nsMsgGroupRecord **outGroupRecord = NULL);
// Makes sure that we have records in memory for all known descendants
// of the given newsgroup.
int AssureAllDescendentsLoaded(nsMsgGroupRecord* group);
int SaveHostInfo();
// Suck the entire hostinfo file into memory. If force is PR_TRUE, then throw
// away whatever we had in memory first.
int Inhale(PRBool force = PR_FALSE);
// If we inhale'd, then write thing out to the file and free up the
// memory.
int Exhale();
// Inhale, but make believe the file is empty. In other words, set the
// inhaled bit, but empty out the memory.
int EmptyInhale();
nsMsgGroupRecord* GetGroupTree() {return m_groupTree;}
PRTime GetFirstNewDate() {return m_firstnewdate;}
NS_IMETHOD GroupNotFound(const char *name, PRBool opening);
int ReorderGroup (nsINNTPNewsgroup *groupToMove, nsINNTPNewsgroup *groupToMoveBefore, PRInt32 *newIdx);
protected:
void OpenGroupFile(const PRIntn = PR_WRONLY);
nsresult RememberLine(char* line);
static nsresult ProcessLine_s(char* line, PRUint32 line_size, void* closure);
nsresult ProcessLine(char* line, PRUint32 line_size);
static void WriteTimer(void* closure);
int CreateFileHeader();
int ReadInitialPart();
nsMsgGroupRecord* FindGroupInBlock(nsMsgGroupRecord* parent,
char* name,
PRInt32* comp);
nsMsgGroupRecord* LoadSingleEntry(nsMsgGroupRecord* parent,
char* name,
PRInt32 min, PRInt32 max);
static PRInt32 InhaleLine(char* line, PRUint32 length, void* closure);
nsMsgGroupRecord* FindOrCreateGroup(const char* name,
int* statusOfMakingGroup = NULL);
nsINNTPCategoryContainer *SwitchNewsToCategoryContainer(nsINNTPNewsgroup *newsInfo);
nsINNTPNewsgroup *SwitchCategoryContainerToNews(nsINNTPCategoryContainer *catContainerInfo);
char* m_hostname;
PRInt32 m_port;
char* m_nameAndPort;
char* m_fullUIName;
nsISupportsArray* m_groups; // List of nsINNTPNewsgroup* objects.
nsISupportsArray* m_newsgrouplists; // List of nsINNTPNewsgroupList* objects.
#ifdef HAVE_MASTER
MSG_Master* m_master;
#endif
nsIMsgFolder* m_hostinfo; // Object representing entire newshost in
// tree.
char* m_optionLines;
char* m_filename; /* The name of the newsrc file associated with
this host. This will be of the form:
"" meaning .newsrc or .snewsrc
HOST meaning .newsrc-HOST
HOST:PORT meaning .newsrc-HOST:PORT
Whether it begins with .newsrc or .snewsrc
depends on a special property slot
(we pass one of
the types xpNewsRC or xpSNewsRC to xp_file.)
The reason this is not simply derived from
the host_name and port slots is that it's
not a 1:1 mapping; if the user has a file
called "newsrc", we will use that for the
default host (the "" name.) Likewise,
".newsrc-H" and ".newsrc-H:119" are
ambiguous.
*/
char* m_dbfilename;
PRBool m_dirty;
PRBool m_supportsExtensions;
void* m_writetimer;
char* m_urlbase;
PRBool m_everexpanded; // Whether the user ever opened up this
// newshost this session.
PRBool m_checkedForNew; // Whether we've checked for new newgroups
// in this newshost this session.
PRBool m_groupSucceeded; // Whether a group command has succeeded this
// session, protect against server bustage
// where it says no group exists.
nsVoidArray m_supportedExtensions;
nsVoidArray m_searchableGroups;
nsVoidArray m_searchableHeaders;
// ### mwelch Added to determine what charsets can be used
// for each table.
PLHashTable * m_searchableGroupCharsets;
nsVoidArray m_propertiesForGet;
nsVoidArray m_valuesForGet;
PRBool m_postingAllowed;
PRBool m_pushAuth; // PR_TRUE if we should volunteer authentication without a
// challenge
PRUint32 m_lastGroupUpdate;
PRTime m_firstnewdate;
nsMsgGroupRecord* m_groupTree; // Tree of groups we're remembering.
PRBool m_inhaled; // Whether we inhaled the entire list of
// groups, or just some.
int m_groupTreeDirty; // Whether the group tree is dirty. If 0, then
// we don't need to write anything. If 1, then
// we can write things in place. If >1, then
// we need to rewrite the whole tree file.
char* m_hostinfofilename; // Filename of the hostinfo file.
static nsNNTPHost* M_FileOwner; // In an effort to save file descriptors,
// only one newshost ever has its
// hostinfo file opened. This is the
// one.
PRFileDesc * m_groupFile; // File handle to the hostinfo file.
char* m_groupFilePermissions; // Permissions used to create the above
// file handle.
char* m_block; // A block of text read from the hostinfo file.
PRInt32 m_blockSize; // How many bytes allocated in m_block.
PRInt32 m_blockStart; // Where in the file we read the data that is
// currently sitting in m_block.
PRInt32 m_fileStart; // Where in the file the actual newsgroup data
// starts.
PRInt32 m_fileSize; // Total number of bytes in the hostinfo file.
PRInt32 m_uniqueId; // Unique number assigned to each newsgroup.
};
nsNNTPHost * nsNNTPHost::M_FileOwner = NULL;
NS_IMPL_ISUPPORTS(nsNNTPHost, GetIID())
#ifdef HAVE_MASTER
nsNNTPHost::nsNNTPHost(MSG_Master* master, char* name,
PRInt32 port)
nsNNTPHost::nsNNTPHost()
{
m_master = master;
#else
nsNNTPHost::nsNNTPHost(const char *name, PRInt32 port)
{
#endif
NS_INIT_REFCNT();
m_hostname = new char [PL_strlen(name) + 1];
}
/* we're not supposed to implement this */
nsNNTPHost::~nsNNTPHost()
{
}
nsresult nsNNTPHost::Initialize(const char *name, PRInt32 port)
{
m_hostname = new char [PL_strlen(name) + 1];
PL_strcpy(m_hostname, name);
PR_ASSERT(port);
@ -512,12 +75,8 @@ nsNNTPHost::nsNNTPHost(const char *name, PRInt32 port)
m_groupTree = NULL;
m_inhaled = PR_FALSE;
m_uniqueId = 0;
}
/* we're not supposed to implement this */
nsNNTPHost::~nsNNTPHost()
{
return NS_OK;
}
nsresult
@ -2238,7 +1797,11 @@ nsNNTPHost::SwitchNewsToCategoryContainer(nsINNTPNewsgroup *newsInfo)
nsINNTPCategoryContainer *newCatCont = nsnull;
// formerly newsInfo->CloneIntoCategoryContainer();
#if 0 // not implemented yet
NS_NewCategoryContainerFromNewsgroup(&newCatCont, newsInfo);
rv = nsComponentManager::CreateInstance(kNNTPCategoryContainerCID, nsnull, nsINNTPCategoryContainer::GetIID(), getter_AddRefs(newCatCont));
if (NS_FAILED(rv)) return nsnull;
rv = newCatCont->Initialize(newsInfo);
if (NS_FAILED(rv)) return nsnull;
#endif
// slip the category container where the newsInfo was.
@ -2308,7 +1871,6 @@ nsNNTPHost::SwitchCategoryContainerToNews(nsINNTPCategoryContainer*
}
return retInfo;
}
nsresult
nsNNTPHost::RemoveGroup (nsINNTPNewsgroup *newsInfo)
{
@ -3688,18 +3250,7 @@ nsNNTPHost::getFolderFor(_type * _class) {\
MSG_IMPL_GETFOLDER(nsINNTPNewsgroup)
MSG_IMPL_GETFOLDER(nsINNTPCategoryContainer)
nsresult
NS_NewNNTPHost(nsINNTPHost **aNNTPHost, const char* name, PRUint32 port)
{
nsNNTPHost *aHost = new nsNNTPHost(name, port);
if (aHost) {
return aHost->QueryInterface(nsINNTPHost::GetIID(),
(void **)aNNTPHost);
}
else {
return NS_ERROR_OUT_OF_MEMORY;
}
}

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

@ -31,10 +31,441 @@
#endif /* XP_MAC || XP_WIN */
#endif /* XP_UNIX */
NS_BEGIN_EXTERN_C
#include "msgCore.h" // precompiled header...
nsresult NS_NewNNTPHost(nsINNTPHost **aInstancePtrResult, const char *name, PRUint32 port);
#include "nsMsgFolderFlags.h"
NS_END_EXTERN_C
#include "nntpCore.h"
#include "nsINNTPHost.h"
#include "nsINNTPCategory.h"
#include "nsINNTPCategoryContainer.h"
#include "nsNNTPCategoryContainer.h"
#include "nsNNTPHost.h"
#include "nsMsgKeySet.h"
#include "nsMsgGroupRecord.h"
#include "nsINNTPNewsgroup.h"
#include "nsNNTPNewsgroup.h"
#include "nsINNTPNewsgroupList.h"
#include "nsNNTPNewsgroupList.h"
#include "nsIMsgFolder.h"
#include "nsISupportsArray.h"
#include "nsIEnumerator.h"
#include "nsFileStream.h"
#include "nsNewsUtils.h"
#include "prprf.h"
#include "prmem.h"
#include "plstr.h"
#include "plhash.h"
#include "prio.h"
#include "nsCOMPtr.h"
/* temporary hacks to test if this compiles */
typedef void MSG_GroupName;
class nsNNTPHost : public nsINNTPHost {
public:
nsNNTPHost();
virtual ~nsNNTPHost();
NS_DECL_ISUPPORTS
// nsINNTPHost
NS_IMETHOD Initialize(const char *name, PRInt32 port);
NS_IMPL_CLASS_GETSET(SupportsExtensions, PRBool,
m_supportsExtensions);
NS_IMETHOD AddExtension (const char *ext);
NS_IMETHOD QueryExtension (const char *ext, PRBool *_retval);
NS_IMPL_CLASS_GETSET(PostingAllowed, PRBool, m_postingAllowed);
NS_IMPL_CLASS_GETTER(GetPushAuth, PRBool, m_pushAuth);
NS_IMETHOD SetPushAuth(PRBool value);
NS_IMPL_CLASS_GETSET(LastUpdatedTime, PRUint32, m_lastGroupUpdate);
NS_IMETHOD GetNewsgroupList(const char *name,nsINNTPNewsgroupList **_retval);
NS_IMETHOD GetNewsgroupAndNumberOfID(const char *message_id,
nsINNTPNewsgroup **group,
PRUint32 *messageNumber);
/* get this from MSG_Master::FindNewsFolder */
NS_IMETHOD FindNewsgroup(const char *name, PRBool create,
nsINNTPNewsgroup **_retval) { NS_ASSERTION(0, "unimplemented!"); return NS_OK;}
NS_IMETHOD AddPropertyForGet (const char *property, const char *value);
NS_IMETHOD QueryPropertyForGet (const char *property, char **_retval);
NS_IMETHOD AddSearchableGroup(const char *name);
// should these go into interfaces?
NS_IMETHOD QuerySearchableGroup (const char *group, PRBool *);
NS_IMETHOD QuerySearchableGroupCharsets(const char *group, char **);
// Virtual groups
NS_IMETHOD AddVirtualGroup(const char *responseText) { return NS_OK;}
NS_IMETHOD SetIsVirtualGroup(const char *name, PRBool isVirtual);
NS_IMETHOD SetIsVirtualGroup(const char *name, PRBool isVirtual,
nsMsgGroupRecord *inGroupRecord);
NS_IMETHOD GetIsVirtualGroup(const char *name, PRBool *_retval);
// custom/searchable headers
NS_IMETHOD AddSearchableHeader(const char *headerName);
NS_IMETHOD QuerySearchableHeader(const char *headerName, PRBool *_retval);
// Go load the newsrc for this host. Creates the subscribed hosts as
// children of the given nsIMsgFolder.
NS_IMETHOD LoadNewsrc(const char *uri);
// Write out the newsrc for this host right now. In general, either
// MarkDirty() or WriteIfDirty() should be called instead.
NS_IMETHOD WriteNewsrc();
// Write out the newsrc for this host right now, if anything has changed
// in it.
NS_IMETHOD WriteIfDirty();
// Note that something has changed, and we need to rewrite the newsrc file
// for this host at some point.
NS_IMETHOD MarkDirty();
/* the Setter implementation is a little more complex */
NS_IMPL_CLASS_GETTER(GetNewsRCFilename, char *, m_filename);
NS_IMETHOD SetNewsRCFilename(char *);
// helper for accessing the above accessors from within this class
// (this is what the pre-mozilla API looked like)
char *GetNewsrcFileName() { return m_filename; };
NS_IMETHOD FindGroup(const char* name, nsINNTPNewsgroup* *_retval);
NS_IMETHOD AddGroup(const char *name,
nsINNTPNewsgroup **_retval);
NS_IMETHOD AddGroup(const char *name,
nsMsgGroupRecord *groupRecord,
nsINNTPNewsgroup **_retval);
NS_IMETHOD RemoveGroupByName(const char *name);
NS_IMETHOD RemoveGroup(nsINNTPNewsgroup*);
NS_IMETHOD AddNewNewsgroup(const char *name,
PRInt32 first,
PRInt32 last,
const char *flags,
PRBool xactiveFlags);
/* Name of directory to store newsgroup
databases in. This needs to have
"/name" appended to it, and the
whole thing can be passed to the XP_File
stuff with a type of xpXoverCache. */
NS_IMETHOD GetDbDirName(char * *aDbDirName) {NS_ASSERTION(0, "unimplemented"); return NS_OK;};
/* helper for internal accesses - part of the Pre-Mozilla API) */
const char *GetDBDirName();
/* Returns a list of newsgroups. The result
must be free'd using PR_Free(); the
individual strings must not be free'd. */
NS_IMETHOD GetGroupList(char **_retval) { return NS_OK;}
NS_IMETHOD DisplaySubscribedGroup(const char *name,
PRInt32 first_message,
PRInt32 last_message,
PRInt32 total_messages,
PRBool visit_now);
// end of nsINNTPHost
private:
nsresult LoadNewsrcFileAndCreateNewsgroups(nsFileSpec &newsrcFile);
nsresult MapHostToNewsrcFile(char *newshostname, nsFileSpec &fatFile, nsFileSpec &newsrcFile);
nsresult GetNewsrcFile(char *newshostname, nsFileSpec &path, nsFileSpec &newsrcFile);
// simplify the QueryInterface calls
static nsIMsgFolder *getFolderFor(nsINNTPNewsgroup *group);
static nsIMsgFolder *getFolderFor(nsINNTPCategoryContainer *catContainer);
NS_METHOD CleanUp();
virtual PRBool IsNews () { return PR_TRUE; }
virtual nsINNTPHost *GetNewsHost() { return this; }
//
void addNew(MSG_GroupName* group);
void ClearNew();
virtual void dump();
virtual PRInt32 getPort();
// Return the name of this newshost.
const char* getStr();
// Returns the name of this newshost, possibly followed by ":<port>" if
// the port number for this newshost is not the default.
const char* getNameAndPort();
// Returns a fully descriptive name for this newshost, including the
// above ":<port>" and also possibly a trailing (and localized) property
virtual const char* getFullUIName();
// Get the nsIMsgFolder which represents this host; the children
// of this nsIMsgFolder are the groups in this host.
nsIMsgFolder* GetHostInfo() {return m_hostinfo;}
#ifdef HAVE_MASTER
MSG_Master* GetMaster() {
return m_master;
}
#endif
// GetNumGroupsNeedingCounts() returns how many newsgroups we have
// that we don't have an accurate count of unread/total articles.
NS_IMETHOD GetNumGroupsNeedingCounts(PRInt32 *);
// GetFirstGroupNeedingCounts() returns the name of the first newsgroup
// that does not have an accurate count of unread/total articles. The
// string must be free'd by the caller using PR_Free().
NS_IMETHOD GetFirstGroupNeedingCounts(char **);
// GetFirstGroupNeedingExtraInfo() returns the name of the first newsgroup
// that does not have extra info (xactive flags and prettyname). The
// string must be free'd by the caller using PR_Free().
NS_IMETHOD GetFirstGroupNeedingExtraInfo(char **);
void SetWantNewTotals(PRBool value); // Sets this bit on every newsgroup
// in this host.
PRBool NeedsExtension (const char *ext);
// Returns the base part of the URL for this newshost, in the
// form "news://hostname:port" or "snews://hostname:port".
// Note that no trailing slash is appended, and that the
// ":port" part will be omitted if this host uses the default
// port.
const char* GetURLBase();
PRBool GetEverExpanded() {return m_everexpanded;}
void SetEverExpanded(PRBool value) {m_everexpanded = value;}
PRBool GetCheckedForNew() {return m_checkedForNew;}
void SetCheckedForNew(PRBool value) {m_checkedForNew = value;}
void SetGroupSucceeded(PRBool value) {m_groupSucceeded = value;}
// Completely obliterate this news host. Remove all traces of it from
// disk and memory.
int RemoveHost();
int DeleteFiles();
// Returns the pretty name for the given group. The resulting string
// must be free'd using delete[].
char* GetPrettyName(char* name);
NS_IMETHOD SetPrettyName(const char* name, const char* prettyname);
PRTime GetAddTime(char* name);
// Returns a unique integer associated with this newsgroup. This is
// mostly used by Win16 to generate a 8.3 filename.
PRInt32 GetUniqueID(char* name);
PRBool IsCategory(char* name);
PRBool IsCategoryContainer(char* name);
int SetIsCategoryContainer(const char* name, PRBool value, nsMsgGroupRecord *inGroupRecord = NULL);
NS_IMETHOD SetGroupNeedsExtraInfo(const char *name, PRBool value);
// Finds the container newsgroup for this category (or NULL if this isn't
// a category). The resulting string must be free'd using delete[].
char* GetCategoryContainer(const char* name, nsMsgGroupRecord *inGroupRecord = NULL);
nsINNTPNewsgroup * GetCategoryContainerFolderInfo(const char *name);
// Get/Set whether this is a real group (as opposed to a container of
// other groups, like "mcom".)
PRBool IsGroup(char* name);
int SetIsGroup(char* name, PRBool value);
// Returns PR_TRUE if it's OK to post HTML in this group (either because the
// bit is on for this group, or one of this group's ancestor's has marked
// all of its descendents as being OK for HTML.)
PRBool IsHTMLOk(char* name);
// Get/Set if it's OK to post HTML in just this group.
PRBool IsHTMLOKGroup(char* name);
int SetIsHTMLOKGroup(char* name, PRBool value);
// Get/Set if it's OK to post HTML in this group and all of its subgroups.
PRBool IsHTMLOKTree(char* name);
int SetIsHTMLOKTree(char* name, PRBool value);
// Create the given group (if not already present). Returns 0 if the
// group is already present, 1 if we had to create it, negative on error.
// The given group will have the "isgroup" bit set on it (in other words,
// it is not to be just a container of other groups, like "mcom" is.)
int NoticeNewGroup(const char* name, nsMsgGroupRecord **outGroupRecord = NULL);
// Makes sure that we have records in memory for all known descendants
// of the given newsgroup.
int AssureAllDescendentsLoaded(nsMsgGroupRecord* group);
int SaveHostInfo();
// Suck the entire hostinfo file into memory. If force is PR_TRUE, then throw
// away whatever we had in memory first.
int Inhale(PRBool force = PR_FALSE);
// If we inhale'd, then write thing out to the file and free up the
// memory.
int Exhale();
// Inhale, but make believe the file is empty. In other words, set the
// inhaled bit, but empty out the memory.
int EmptyInhale();
nsMsgGroupRecord* GetGroupTree() {return m_groupTree;}
PRTime GetFirstNewDate() {return m_firstnewdate;}
NS_IMETHOD GroupNotFound(const char *name, PRBool opening);
int ReorderGroup (nsINNTPNewsgroup *groupToMove, nsINNTPNewsgroup *groupToMoveBefore, PRInt32 *newIdx);
protected:
void OpenGroupFile(const PRIntn = PR_WRONLY);
nsresult RememberLine(char* line);
static nsresult ProcessLine_s(char* line, PRUint32 line_size, void* closure);
nsresult ProcessLine(char* line, PRUint32 line_size);
static void WriteTimer(void* closure);
int CreateFileHeader();
int ReadInitialPart();
nsMsgGroupRecord* FindGroupInBlock(nsMsgGroupRecord* parent,
char* name,
PRInt32* comp);
nsMsgGroupRecord* LoadSingleEntry(nsMsgGroupRecord* parent,
char* name,
PRInt32 min, PRInt32 max);
static PRInt32 InhaleLine(char* line, PRUint32 length, void* closure);
nsMsgGroupRecord* FindOrCreateGroup(const char* name,
int* statusOfMakingGroup = NULL);
nsINNTPCategoryContainer *SwitchNewsToCategoryContainer(nsINNTPNewsgroup *newsInfo);
nsINNTPNewsgroup * SwitchCategoryContainerToNews(nsINNTPCategoryContainer *catContainerInfo);
char* m_hostname;
PRInt32 m_port;
char* m_nameAndPort;
char* m_fullUIName;
nsISupportsArray* m_groups; // List of nsINNTPNewsgroup* objects.
nsISupportsArray* m_newsgrouplists; // List of nsINNTPNewsgroupList* objects.
#ifdef HAVE_MASTER
MSG_Master* m_master;
#endif
nsIMsgFolder* m_hostinfo; // Object representing entire newshost in
// tree.
char* m_optionLines;
char* m_filename; /* The name of the newsrc file associated with
this host. This will be of the form:
"" meaning .newsrc or .snewsrc
HOST meaning .newsrc-HOST
HOST:PORT meaning .newsrc-HOST:PORT
Whether it begins with .newsrc or .snewsrc
depends on a special property slot
(we pass one of
the types xpNewsRC or xpSNewsRC to xp_file.)
The reason this is not simply derived from
the host_name and port slots is that it's
not a 1:1 mapping; if the user has a file
called "newsrc", we will use that for the
default host (the "" name.) Likewise,
".newsrc-H" and ".newsrc-H:119" are
ambiguous.
*/
char* m_dbfilename;
PRBool m_dirty;
PRBool m_supportsExtensions;
void* m_writetimer;
char* m_urlbase;
PRBool m_everexpanded; // Whether the user ever opened up this
// newshost this session.
PRBool m_checkedForNew; // Whether we've checked for new newgroups
// in this newshost this session.
PRBool m_groupSucceeded; // Whether a group command has succeeded this
// session, protect against server bustage
// where it says no group exists.
nsVoidArray m_supportedExtensions;
nsVoidArray m_searchableGroups;
nsVoidArray m_searchableHeaders;
// ### mwelch Added to determine what charsets can be used
// for each table.
PLHashTable * m_searchableGroupCharsets;
nsVoidArray m_propertiesForGet;
nsVoidArray m_valuesForGet;
PRBool m_postingAllowed;
PRBool m_pushAuth; // PR_TRUE if we should volunteer authentication without a
// challenge
PRUint32 m_lastGroupUpdate;
PRTime m_firstnewdate;
nsMsgGroupRecord* m_groupTree; // Tree of groups we're remembering.
PRBool m_inhaled; // Whether we inhaled the entire list of
// groups, or just some.
int m_groupTreeDirty; // Whether the group tree is dirty. If 0, then
// we don't need to write anything. If 1, then
// we can write things in place. If >1, then
// we need to rewrite the whole tree file.
char* m_hostinfofilename; // Filename of the hostinfo file.
static nsNNTPHost* M_FileOwner; // In an effort to save file descriptors,
// only one newshost ever has its
// hostinfo file opened. This is the
// one.
PRFileDesc * m_groupFile; // File handle to the hostinfo file.
char* m_groupFilePermissions; // Permissions used to create the above
// file handle.
char* m_block; // A block of text read from the hostinfo file.
PRInt32 m_blockSize; // How many bytes allocated in m_block.
PRInt32 m_blockStart; // Where in the file we read the data that is
// currently sitting in m_block.
PRInt32 m_fileStart; // Where in the file the actual newsgroup data
// starts.
PRInt32 m_fileSize; // Total number of bytes in the hostinfo file.
PRInt32 m_uniqueId; // Unique number assigned to each newsgroup.
};
#endif /* __msg_NewsHost__ */

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

@ -240,15 +240,3 @@ nsNNTPNewsgroupPost::GetPostMessageFile(nsFilePath ** aFileName)
return NS_ERROR_NULL_POINTER;
}
}
NS_BEGIN_EXTERN_C
nsresult NS_NewNewsgroupPost(nsINNTPNewsgroupPost **aPost)
{
if (!aPost) return NS_ERROR_NULL_POINTER;
nsNNTPNewsgroupPost *post = new nsNNTPNewsgroupPost();
return post->QueryInterface(nsINNTPNewsgroupPost::GetIID(),
(void **)aPost);
}
NS_END_EXTERN_C

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

@ -83,6 +83,7 @@ static NS_DEFINE_IID(kIWebShell, NS_IWEB_SHELL_IID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kCHeaderParserCID, NS_MSGHEADERPARSER_CID);
static NS_DEFINE_CID(kNNTPArticleListCID, NS_NNTPARTICLELIST_CID);
static NS_DEFINE_CID(kNNTPHostCID, NS_NNTPHOST_CID);
// quiet compiler warnings by defining these function prototypes
char *NET_ExplainErrorDetails (int code, ...);
@ -362,16 +363,6 @@ nsNNTPProtocol::nsNNTPProtocol() : m_tempArticleFile(ARTICLE_PATH)
nsNNTPProtocol::~nsNNTPProtocol()
{
// release all of our event sinks
if (m_newsgroupList)
NS_RELEASE(m_newsgroupList);
if (m_newsHost)
NS_RELEASE(m_newsHost);
if (m_newsgroup)
NS_RELEASE(m_newsgroup);
if (m_offlineNewsState)
NS_RELEASE(m_offlineNewsState);
NS_IF_RELEASE(m_outputStream);
NS_IF_RELEASE(m_outputConsumer);
NS_IF_RELEASE(m_transport);
@ -411,10 +402,7 @@ nsresult nsNNTPProtocol::Initialize(nsIURL * aURL, nsITransport * transportLayer
// query the URL for a nsINNTPUrl
m_runningURL = nsnull; // initialize to NULL
m_newsgroupList = nsnull;
m_newsHost = nsnull;
m_newsgroup = nsnull;
m_offlineNewsState = nsnull;
m_displayConsumer = nsnull;
if (aURL)
@ -424,11 +412,11 @@ nsresult nsNNTPProtocol::Initialize(nsIURL * aURL, nsITransport * transportLayer
{
// okay, now fill in our event sinks...Note that each getter ref counts before
// it returns the interface to us...we'll release when we are done
m_runningURL->GetNewsgroupList(&m_newsgroupList);
m_runningURL->GetNewsgroupList(getter_AddRefs(m_newsgroupList));
m_runningURL->GetNntpArticleList(getter_AddRefs(m_articleList));
m_runningURL->GetNntpHost(&m_newsHost);
m_runningURL->GetNewsgroup(&m_newsgroup);
m_runningURL->GetOfflineNewsState(&m_offlineNewsState);
m_runningURL->GetNntpHost(getter_AddRefs(m_newsHost));
m_runningURL->GetNewsgroup(getter_AddRefs(m_newsgroup));
m_runningURL->GetOfflineNewsState(getter_AddRefs(m_offlineNewsState));
}
else {
return rv;
@ -525,11 +513,11 @@ nsresult nsNNTPProtocol::LoadURL(nsIURL * aURL, nsISupports * aConsumer, PRInt32
// okay, now fill in our event sinks...Note that each getter ref counts before
// it returns the interface to us...we'll release when we are done
m_runningURL->GetNewsgroupList(&m_newsgroupList);
m_runningURL->GetNewsgroupList(getter_AddRefs(m_newsgroupList));
m_runningURL->GetNntpArticleList(getter_AddRefs(m_articleList));
m_runningURL->GetNntpHost(&m_newsHost);
m_runningURL->GetNewsgroup(&m_newsgroup);
m_runningURL->GetOfflineNewsState(&m_offlineNewsState);
m_runningURL->GetNntpHost(getter_AddRefs(m_newsHost));
m_runningURL->GetNewsgroup(getter_AddRefs(m_newsgroup));
m_runningURL->GetOfflineNewsState(getter_AddRefs(m_offlineNewsState));
}
else /* let rv fall through */
NS_ASSERTION(0, "Invalid url type passed into NNTP Protocol Handler");
@ -548,7 +536,7 @@ nsresult nsNNTPProtocol::LoadURL(nsIURL * aURL, nsISupports * aConsumer, PRInt32
goto FAIL;
// if we don't have a news host already, go get one...
if (m_newsHost == nsnull)
if (!m_newsHost)
{
char *colon = nsnull;
PRUint32 port = 0;
@ -557,16 +545,19 @@ nsresult nsNNTPProtocol::LoadURL(nsIURL * aURL, nsISupports * aConsumer, PRInt32
if (colon) {
*colon = '\0'; /* turn hostname:port into hostname */
port = (PRUint32) strtol(colon + 1, (char **)nsnull, 10 /* base 10 */);
}
rv = nsComponentManager::CreateInstance(kNNTPHostCID,
nsnull,
nsINNTPHost::GetIID(),
getter_AddRefs(m_newsHost));
if (NS_FAILED(rv) || (!m_newsHost)) {
*status = -1;
goto FAIL;
}
// at this point, hostAndPort is really just the hostname
// because we put a '\0' in for the colon, if there was one
rv = NS_NewNNTPHost(&m_newsHost, hostAndPort /* really just hostname */, port ? port : NEWS_PORT);
if (NS_FAILED(rv) || (m_newsHost == nsnull)) {
*status = -1;
goto FAIL;
}
m_newsHost->Initialize(hostAndPort /* really just hostname */, port ? port : NEWS_PORT);
// save it on our url for future use....
m_runningURL->SetNntpHost(m_newsHost);
@ -754,7 +745,7 @@ nsresult nsNNTPProtocol::LoadURL(nsIURL * aURL, nsISupports * aConsumer, PRInt32
#ifdef UNREADY_CODE
if (m_typeWanted == ARTICLE_WANTED)
{
uint32 number = 0;
PRUint32 number = 0;
nsresult rv;
PRBool articleIsOffline;
rv = m_newsgroup->IsOfflineArticle(number,&articleIsOffline);
@ -768,9 +759,18 @@ nsresult nsNNTPProtocol::LoadURL(nsIURL * aURL, nsISupports * aConsumer, PRInt32
if (!articleIsOffline)
ce->format_out = CLEAR_CACHE_BIT(ce->format_out);
NET_SetCallNetlibAllTheTime(ce->window_id,"mknews");
rv = NS_NewOfflineNewState(&cd->offline_state,
cd->newsgroup, number);
rv = nsComponentManager::CreateInstance(kMsgOfflineNewsStateCID,
nsnull,
nsIMsgOfflineNewsState::GetIID(),
getter_AddRefs(cd->offline_state));
if (NS_FAILED(rv) || ! cd->offline_state) {
goto FAIL;
}
rv = cd->offline_state->Initialize(cd->newsgroup, number);
if (NS_FAILED(rv)) goto FAIL;
}
}
if (cd->offline_state)
@ -1619,13 +1619,13 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
PRUint32 number = 0;
nsresult rv;
nsINNTPNewsgroup *newsgroup;
if (m_newsHost == nsnull) {
nsCOMPtr <nsINNTPNewsgroup> newsgroup;
if (!m_newsHost) {
printf("m_newsHost is null, panic!\n");
return -1;
}
rv = m_newsHost->GetNewsgroupAndNumberOfID(m_path,
&newsgroup,
getter_AddRefs(newsgroup),
&number);
if (NS_SUCCEEDED(rv) && newsgroup && number)
{
@ -1663,7 +1663,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
PRUint32 last_update;
nsresult rv;
if (m_newsHost == nsnull) {
if (!m_newsHost) {
printf("m_newsHost is null, panic!\n");
return -1;
}
@ -1700,7 +1700,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
ClearFlag(NNTP_USE_FANCY_NEWSGROUP);
PRUint32 last_update;
if (m_newsHost == nsnull) {
if (!m_newsHost) {
printf("m_newsHost is null, panic!\n");
return -1;
}
@ -1746,7 +1746,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
nsresult rv=NS_ERROR_NULL_POINTER;
NET_SACopy(&command, "GROUP ");
if (m_newsgroup == nsnull) {
if (!m_newsgroup) {
printf("m_newsgroup is null, panic!\n");
return -1;
}
@ -1769,7 +1769,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
{
nsresult rv;
PRBool searchable=PR_FALSE;
if (m_newsHost == nsnull) {
if (!m_newsHost) {
printf("m_newsHost is null, panic!\n");
return -1;
}
@ -1796,7 +1796,7 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCommand(nsIURL * url)
/* for XPAT, we have to GROUP into the group before searching */
NET_SACopy(&command, "GROUP ");
if (m_newsgroup == nsnull) {
if (!m_newsgroup) {
printf("m_newsgroup is null, panic!\n");
return -1;
}
@ -2562,7 +2562,7 @@ PRInt32 nsNNTPProtocol::ProcessNewsgroups(nsIInputStream * inputStream, PRUint32
rv = m_newsHost->GetFirstGroupNeedingExtraInfo(&groupName);
if (NS_SUCCEEDED(rv) && m_newsgroup)
{
rv = m_newsHost->FindGroup(groupName, &m_newsgroup);
rv = m_newsHost->FindGroup(groupName, getter_AddRefs(m_newsgroup));
PR_ASSERT(NS_SUCCEEDED(rv));
m_nextState = NNTP_LIST_XACTIVE;
#ifdef DEBUG_NEWS
@ -2800,13 +2800,13 @@ PRInt32 nsNNTPProtocol::FigureNextChunk()
rv = m_newsgroup->GetName(&groupName);
/* XXX - parse state stored in MSG_Pane cd->pane */
if (NS_SUCCEEDED(rv))
rv = m_newsHost->GetNewsgroupList(groupName, &m_newsgroupList);
rv = m_newsHost->GetNewsgroupList(groupName, getter_AddRefs(m_newsgroupList));
#ifdef DEBUG_NEWS
printf("add to known articles: %d - %d\n", m_firstArticle, m_lastArticle);
#endif
if (NS_SUCCEEDED(rv) && m_newsgroupList != nsnull) {
if (NS_SUCCEEDED(rv) && m_newsgroupList) {
rv = m_newsgroupList->AddToKnownArticles(m_firstArticle,
m_lastArticle);
}
@ -2828,13 +2828,13 @@ PRInt32 nsNNTPProtocol::FigureNextChunk()
char *groupName = nsnull;
if (m_newsgroupList == nsnull) {
if (!m_newsgroupList) {
rv = m_newsgroup->GetName(&groupName);
if (NS_SUCCEEDED(rv))
rv = m_newsHost->GetNewsgroupList(groupName, &m_newsgroupList);
rv = m_newsHost->GetNewsgroupList(groupName, getter_AddRefs(m_newsgroupList));
}
if (NS_SUCCEEDED(rv) && m_newsgroupList != nsnull) {
if (NS_SUCCEEDED(rv) && m_newsgroupList) {
rv = m_newsgroupList->GetRangeOfArtsToDownload(m_firstPossibleArticle,
m_lastPossibleArticle,
m_numArticlesWanted -
@ -2864,7 +2864,7 @@ PRInt32 nsNNTPProtocol::FigureNextChunk()
m_articleNumber = m_firstArticle;
/* was MSG_InitXOVER() */
if (m_newsgroupList != nsnull) {
if (m_newsgroupList) {
rv = m_newsgroupList->InitXOVER(m_firstArticle, m_lastArticle);
}
@ -3021,7 +3021,7 @@ PRInt32 nsNNTPProtocol::ProcessXover()
PRInt32 status = 0;
/* xover_parse_state stored in MSG_Pane cd->pane */
if (m_newsgroupList == nsnull) {
if (!m_newsgroupList) {
return NS_ERROR_NULL_POINTER;
}
@ -4043,18 +4043,17 @@ PRInt32 nsNNTPProtocol::ListXActiveResponse(nsIInputStream * inputStream, PRUint
if (m_typeWanted == NEW_GROUPS &&
NS_SUCCEEDED(rv) && xactive)
{
// todo: use nsCOMPtr
nsINNTPNewsgroup* old_newsgroup = m_newsgroup;
nsCOMPtr <nsINNTPNewsgroup> old_newsgroup;
old_newsgroup = m_newsgroup;
char *groupName;
m_newsHost->GetFirstGroupNeedingExtraInfo(&groupName);
m_newsHost->FindGroup(groupName, &m_newsgroup);
m_newsHost->FindGroup(groupName, getter_AddRefs(m_newsgroup));
// see if we got a different group
if (old_newsgroup && m_newsgroup &&
old_newsgroup != m_newsgroup)
(old_newsgroup != m_newsgroup))
/* make sure we're not stuck on the same group */
{
NS_RELEASE(old_newsgroup);
#ifdef DEBUG_NEWS
printf("listing xactive for %s\n", groupName);
#endif
@ -4064,9 +4063,9 @@ PRInt32 nsNNTPProtocol::ListXActiveResponse(nsIInputStream * inputStream, PRUint
return 0;
}
else
{
NS_RELEASE(old_newsgroup);
m_newsgroup = NULL;
{
printf("set nsCOMPtr to null?\n");
//m_newsgroup = NULL;
}
}
PRBool listpname;
@ -4697,15 +4696,13 @@ PRInt32 nsNNTPProtocol::CloseConnection()
something. So, tell libmsg there was an abnormal
exit so that it can free its data. */
if (m_newsgroupList != NULL)
if (m_newsgroupList)
{
int status;
nsresult rv;
/* XXX - how/when to Release() this? */
rv = m_newsgroupList->FinishXOVERLINE(status,&status);
PR_ASSERT(NS_SUCCEEDED(rv));
if (NS_SUCCEEDED(rv))
NS_RELEASE(m_newsgroupList);
if (NS_SUCCEEDED(rv) && status >= 0 && status < 0)
status = status;
}
@ -4724,8 +4721,6 @@ PRInt32 nsNNTPProtocol::CloseConnection()
PR_FREEIF(m_responseText);
PR_FREEIF(m_dataBuf);
NS_IF_RELEASE(m_newsgroup);
PR_FREEIF (m_cancelID);
PR_FREEIF (m_cancelFromHdr);
PR_FREEIF (m_cancelNewsgroups);

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

@ -211,12 +211,12 @@ private:
nsFileSpec m_tempArticleFile;
// News Event Sinks
nsINNTPNewsgroupList * m_newsgroupList;
nsCOMPtr <nsINNTPNewsgroupList> m_newsgroupList;
nsCOMPtr <nsINNTPArticleList> m_articleList;
nsINNTPHost * m_newsHost;
nsINNTPNewsgroup * m_newsgroup;
nsIMsgOfflineNewsState * m_offlineNewsState;
nsCOMPtr <nsINNTPHost> m_newsHost;
nsCOMPtr <nsINNTPNewsgroup> m_newsgroup;
nsCOMPtr <nsIMsgOfflineNewsState> m_offlineNewsState;
// Ouput stream for writing commands to the socket
nsITransport * m_transport;

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

@ -16,35 +16,7 @@
* Reserved.
*/
#include "nsINntpIncomingServer.h"
#include "nsNntpIncomingServer.h"
#include "nsMsgIncomingServer.h"
#include "nsIPref.h"
#include "prmem.h"
#include "plstr.h"
#include "prprf.h"
/* get some implementation from nsMsgIncomingServer */
class nsNntpIncomingServer : public nsMsgIncomingServer,
public nsINntpIncomingServer
{
public:
NS_DECL_ISUPPORTS_INHERITED
nsNntpIncomingServer();
virtual ~nsNntpIncomingServer();
NS_IMETHOD GetRootFolderPath(char **);
NS_IMETHOD SetRootFolderPath(char *);
NS_IMETHOD GetServerURI(char * *uri);
private:
char *m_rootFolderPath;
};
NS_IMPL_ISUPPORTS_INHERITED(nsNntpIncomingServer,
nsMsgIncomingServer,
@ -82,14 +54,5 @@ nsNntpIncomingServer::GetServerURI(char **uri)
return rv;
}
nsresult NS_NewNntpIncomingServer(const nsIID& iid,
void **result)
{
nsNntpIncomingServer *server;
if (!result) return NS_ERROR_NULL_POINTER;
server = new nsNntpIncomingServer();
return server->QueryInterface(iid, result);
}

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

@ -22,11 +22,32 @@
#include "nsINntpIncomingServer.h"
#include "nscore.h"
NS_BEGIN_EXTERN_C
#include "nsMsgIncomingServer.h"
nsresult
NS_NewNntpIncomingServer(const nsIID& iid, void **result);
#include "nsIPref.h"
NS_END_EXTERN_C
#include "prmem.h"
#include "plstr.h"
#include "prprf.h"
/* get some implementation from nsMsgIncomingServer */
class nsNntpIncomingServer : public nsMsgIncomingServer,
public nsINntpIncomingServer
{
public:
NS_DECL_ISUPPORTS_INHERITED
nsNntpIncomingServer();
virtual ~nsNntpIncomingServer();
NS_IMETHOD GetRootFolderPath(char **);
NS_IMETHOD SetRootFolderPath(char *);
NS_IMETHOD GetServerURI(char * *uri);
private:
char *m_rootFolderPath;
};
#endif