1999-03-18 04:09:50 +03:00
|
|
|
/* -*- 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 "msgCore.h" // for pre-compiled headers...
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsISupports.h"
|
1999-03-31 09:16:38 +04:00
|
|
|
#include "nsIMAPHostSessionList.h"
|
1999-04-08 06:48:56 +04:00
|
|
|
#include "nsImapIncomingServer.h"
|
|
|
|
#include "nsImapService.h"
|
1999-03-18 04:09:50 +03:00
|
|
|
#include "pratom.h"
|
|
|
|
#include "nsCOMPtr.h"
|
1999-04-21 09:18:56 +04:00
|
|
|
#include "nsImapMailFolder.h"
|
1999-04-25 00:46:07 +04:00
|
|
|
#include "nsImapMessage.h"
|
1999-03-18 04:09:50 +03:00
|
|
|
|
|
|
|
// include files for components this factory creates...
|
|
|
|
#include "nsImapUrl.h"
|
|
|
|
#include "nsImapProtocol.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kCImapUrl, NS_IMAPURL_CID);
|
|
|
|
static NS_DEFINE_CID(kCImapProtocol, NS_IMAPPROTOCOL_CID);
|
1999-03-31 09:16:38 +04:00
|
|
|
static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID);
|
1999-04-08 06:48:56 +04:00
|
|
|
static NS_DEFINE_CID(kCImapIncomingServer, NS_IMAPINCOMINGSERVER_CID);
|
|
|
|
static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID);
|
1999-04-21 09:18:56 +04:00
|
|
|
static NS_DEFINE_CID(kCImapResource, NS_IMAPRESOURCE_CID);
|
1999-04-25 00:46:07 +04:00
|
|
|
static NS_DEFINE_CID(kCImapMessageResource, NS_IMAPMESSAGERESOURCE_CID);
|
|
|
|
|
1999-03-18 04:09:50 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
static PRInt32 g_InstanceCount = 0;
|
|
|
|
static PRInt32 g_LockCount = 0;
|
|
|
|
|
|
|
|
class nsImapFactory : public nsIFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports methods
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsImapFactory(const nsCID &aClass, const char* aClassName, const char* aProgID);
|
|
|
|
|
|
|
|
// nsIFactory methods
|
|
|
|
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult);
|
|
|
|
NS_IMETHOD LockFactory(PRBool aLock);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsImapFactory();
|
|
|
|
|
|
|
|
nsCID mClassID;
|
|
|
|
char* mClassName;
|
|
|
|
char* mProgID;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsImapFactory::nsImapFactory(const nsCID &aClass, const char* aClassName, const char* aProgID)
|
|
|
|
: mClassID(aClass), mClassName(nsCRT::strdup(aClassName)), mProgID(nsCRT::strdup(aProgID))
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImapFactory::~nsImapFactory()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
1999-05-07 04:13:10 +04:00
|
|
|
nsCRT::free(mClassName);
|
|
|
|
nsCRT::free(mProgID);
|
1999-03-18 04:09:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsImapFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
|
|
|
{
|
|
|
|
if (aResult == NULL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Always NULL result, in case of failure
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
// we support two interfaces....nsISupports and nsFactory.....
|
|
|
|
if (aIID.Equals(::nsISupports::GetIID()))
|
|
|
|
*aResult = (void *)(nsISupports*)this;
|
|
|
|
else if (aIID.Equals(nsIFactory::GetIID()))
|
|
|
|
*aResult = (void *)(nsIFactory*)this;
|
|
|
|
|
|
|
|
if (*aResult == NULL)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
AddRef(); // Increase reference count for caller
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsImapFactory)
|
|
|
|
NS_IMPL_RELEASE(nsImapFactory)
|
|
|
|
|
|
|
|
nsresult nsImapFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (aResult == NULL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
nsISupports *inst = nsnull;
|
|
|
|
|
|
|
|
// ClassID check happens here
|
|
|
|
// Whenever you add a new class that supports an interface, plug it in here!!!
|
|
|
|
|
|
|
|
// do they want a local datasource ?
|
|
|
|
if (mClassID.Equals(kCImapUrl))
|
|
|
|
{
|
|
|
|
inst = NS_STATIC_CAST(nsIImapUrl*, new nsImapUrl());
|
|
|
|
}
|
1999-04-08 06:48:56 +04:00
|
|
|
else if (mClassID.Equals(kCImapProtocol))
|
1999-03-18 04:09:50 +03:00
|
|
|
{
|
|
|
|
inst = NS_STATIC_CAST(nsIImapProtocol *, new nsImapProtocol());
|
|
|
|
}
|
1999-04-08 06:48:56 +04:00
|
|
|
else if (mClassID.Equals(kCImapHostSessionList))
|
1999-03-31 09:16:38 +04:00
|
|
|
{
|
|
|
|
inst = NS_STATIC_CAST(nsIImapHostSessionList *, new nsIMAPHostSessionList());
|
|
|
|
}
|
1999-04-08 06:48:56 +04:00
|
|
|
else if (mClassID.Equals(kCImapIncomingServer))
|
|
|
|
{
|
|
|
|
return NS_NewImapIncomingServer(aIID, aResult);
|
|
|
|
}
|
|
|
|
else if (mClassID.Equals(kCImapService))
|
|
|
|
{
|
|
|
|
inst = NS_STATIC_CAST(nsIImapService *, new nsImapService());
|
|
|
|
}
|
1999-04-22 01:08:00 +04:00
|
|
|
else if (mClassID.Equals(kCImapResource))
|
|
|
|
{
|
|
|
|
inst = NS_STATIC_CAST(nsIMsgImapMailFolder *, new nsImapMailFolder());
|
|
|
|
}
|
1999-04-26 01:51:39 +04:00
|
|
|
else if (mClassID.Equals(kCImapMessageResource))
|
|
|
|
{
|
|
|
|
nsImapMessage * imapMessage = new nsImapMessage();
|
|
|
|
if (imapMessage)
|
|
|
|
rv = imapMessage->QueryInterface(aIID, aResult);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (NS_FAILED(rv) && imapMessage)
|
|
|
|
delete imapMessage;
|
|
|
|
return rv;
|
|
|
|
}
|
1999-03-18 04:09:50 +03:00
|
|
|
if (inst == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
delete inst;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsImapFactory::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
if (aLock)
|
|
|
|
PR_AtomicIncrement(&g_LockCount);
|
|
|
|
else
|
|
|
|
PR_AtomicDecrement(&g_LockCount);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the proper factory to the caller.
|
|
|
|
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
|
|
|
|
const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
|
|
|
if (nsnull == aFactory)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aFactory = new nsImapFactory(aClass, aClassName, aProgID);
|
|
|
|
|
|
|
|
if (aFactory)
|
|
|
|
return (*aFactory)->QueryInterface(nsIFactory::GetIID(), (void**)aFactory); // they want a Factory Interface so give it to them
|
|
|
|
else
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
|
|
|
|
{
|
|
|
|
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT nsresult
|
|
|
|
NSRegisterSelf(nsISupports* aServMgr, const char* path)
|
|
|
|
{
|
1999-06-05 04:06:05 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsresult finalResult = NS_OK;
|
1999-03-18 04:09:50 +03:00
|
|
|
|
1999-06-09 10:40:48 +04:00
|
|
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
|
1999-03-18 04:09:50 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCImapUrl, nsnull, nsnull,
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-18 04:09:50 +03:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCImapProtocol, nsnull, nsnull,
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-18 04:09:50 +03:00
|
|
|
|
1999-03-31 09:16:38 +04:00
|
|
|
rv = compMgr->RegisterComponent(kCImapHostSessionList, nsnull, nsnull,
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-31 09:16:38 +04:00
|
|
|
|
1999-04-08 06:48:56 +04:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCImapIncomingServer,
|
|
|
|
"Imap Incoming Server",
|
|
|
|
"component://netscape/messenger/server&type=imap",
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
|
|
|
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-08 06:48:56 +04:00
|
|
|
|
1999-04-26 01:51:39 +04:00
|
|
|
// register our RDF resource factories:
|
|
|
|
rv = compMgr->RegisterComponent(kCImapResource,
|
|
|
|
"Mail/News Imap Resource Factory",
|
|
|
|
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap",
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-23 05:33:52 +04:00
|
|
|
|
1999-04-26 01:51:39 +04:00
|
|
|
rv = compMgr->RegisterComponent(kCImapService, nsnull,
|
|
|
|
"component://netscape/messenger/messageservice;type=imap_message",
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-21 09:18:56 +04:00
|
|
|
|
1999-04-08 06:48:56 +04:00
|
|
|
rv = compMgr->RegisterComponent(kCImapService, nsnull, nsnull,
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-08 06:48:56 +04:00
|
|
|
|
1999-06-05 04:06:05 +04:00
|
|
|
rv = compMgr->RegisterComponent(kCImapMessageResource,
|
1999-04-26 01:51:39 +04:00
|
|
|
"Imap Message Resource Factory",
|
|
|
|
NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX "imap_message",
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
|
|
|
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-26 01:51:39 +04:00
|
|
|
|
1999-06-05 04:06:05 +04:00
|
|
|
return finalResult;
|
1999-03-18 04:09:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT nsresult
|
|
|
|
NSUnregisterSelf(nsISupports* aServMgr, const char* path)
|
|
|
|
{
|
1999-06-05 04:06:05 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsresult finalResult = NS_OK;
|
1999-03-18 04:09:50 +03:00
|
|
|
|
1999-06-09 10:40:48 +04:00
|
|
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
|
1999-03-18 04:09:50 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-05-06 05:37:04 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapUrl, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-18 04:09:50 +03:00
|
|
|
|
1999-05-06 05:37:04 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapProtocol, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-18 04:09:50 +03:00
|
|
|
|
1999-05-06 05:37:04 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapHostSessionList, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-31 09:16:38 +04:00
|
|
|
|
1999-05-06 05:37:04 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapIncomingServer, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv))finalResult = rv;
|
1999-04-08 06:48:56 +04:00
|
|
|
|
1999-05-06 05:37:04 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapService, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-08 06:48:56 +04:00
|
|
|
|
1999-04-25 00:46:07 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapMessageResource, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-25 00:46:07 +04:00
|
|
|
|
1999-05-06 05:37:04 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCImapResource, path);
|
1999-06-05 04:06:05 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-04-22 01:08:00 +04:00
|
|
|
|
1999-06-05 04:06:05 +04:00
|
|
|
return finalResult;
|
1999-03-18 04:09:50 +03:00
|
|
|
}
|