1999-02-11 04:01:47 +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.
|
|
|
|
*/
|
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
#include "msgCore.h"
|
|
|
|
|
1999-02-11 04:01:47 +03:00
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsISupports.h"
|
1999-02-23 04:02:49 +03:00
|
|
|
#include "pratom.h"
|
1999-02-11 04:01:47 +03:00
|
|
|
#include "nsMsgCompCID.h"
|
|
|
|
|
|
|
|
/* Include all of the interfaces our factory can generate components for */
|
1999-02-23 04:02:49 +03:00
|
|
|
#include "nsISmtpService.h"
|
|
|
|
#include "nsSmtpService.h"
|
1999-03-11 04:41:25 +03:00
|
|
|
#include "nsComposer.h"
|
|
|
|
#include "nsComposeAppCore.h"
|
1999-02-11 04:01:47 +03:00
|
|
|
#include "nsMsgComposeFact.h"
|
|
|
|
#include "nsMsgCompFieldsFact.h"
|
1999-02-17 22:38:44 +03:00
|
|
|
#include "nsMsgSendFact.h"
|
1999-06-07 22:48:32 +04:00
|
|
|
#include "nsMsgSendLaterFact.h"
|
1999-03-09 12:52:30 +03:00
|
|
|
#include "nsIServiceManager.h"
|
1999-03-09 16:07:15 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-02-11 04:01:47 +03:00
|
|
|
|
1999-03-09 12:52:30 +03:00
|
|
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
1999-02-17 22:38:44 +03:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
1999-02-13 13:39:59 +03:00
|
|
|
static NS_DEFINE_CID(kCMsgComposeCID, NS_MSGCOMPOSE_CID);
|
|
|
|
static NS_DEFINE_CID(kCMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID);
|
1999-02-17 22:38:44 +03:00
|
|
|
static NS_DEFINE_CID(kCMsgSendCID, NS_MSGSEND_CID);
|
1999-06-07 22:48:32 +04:00
|
|
|
static NS_DEFINE_CID(kCMsgSendLaterCID, NS_MSGSENDLATER_CID);
|
1999-02-23 04:02:49 +03:00
|
|
|
static NS_DEFINE_CID(kCSmtpServiceCID, NS_SMTPSERVICE_CID);
|
1999-03-11 04:41:25 +03:00
|
|
|
static NS_DEFINE_CID(kCComposeAppCoreCID, NS_COMPOSEAPPCORE_CID);
|
|
|
|
static NS_DEFINE_CID(kCComposerBootstrapCID, NS_COMPOSERBOOTSTRAP_CID);
|
|
|
|
static NS_DEFINE_CID(kCComposerCID, NS_COMPOSER_CID);
|
|
|
|
|
|
|
|
|
1999-02-11 04:01:47 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////
|
1999-02-23 04:02:49 +03:00
|
|
|
static PRInt32 g_InstanceCount = 0;
|
|
|
|
static PRInt32 g_LockCount = 0;
|
1999-02-11 04:01:47 +03:00
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
class nsMsgComposeFactory : public nsIFactory
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports methods
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
nsMsgComposeFactory(const nsCID &aClass,
|
|
|
|
const char* aClassName,
|
|
|
|
const char* aProgID,
|
|
|
|
nsISupports*);
|
1999-02-11 04:01:47 +03:00
|
|
|
|
|
|
|
// nsIFactory methods
|
|
|
|
NS_IMETHOD CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult);
|
|
|
|
NS_IMETHOD LockFactory(PRBool aLock);
|
|
|
|
|
|
|
|
protected:
|
1999-02-23 04:02:49 +03:00
|
|
|
virtual ~nsMsgComposeFactory();
|
1999-02-11 04:01:47 +03:00
|
|
|
|
|
|
|
private:
|
1999-03-11 04:41:25 +03:00
|
|
|
nsCID mClassID;
|
|
|
|
char* mClassName;
|
|
|
|
char* mProgID;
|
|
|
|
nsIServiceManager* mServiceManager;
|
1999-02-11 04:01:47 +03:00
|
|
|
};
|
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
nsMsgComposeFactory::nsMsgComposeFactory(const nsCID &aClass,
|
|
|
|
const char* aClassName,
|
|
|
|
const char* aProgID,
|
|
|
|
nsISupports *compMgrSupports)
|
|
|
|
: mClassID(aClass),
|
|
|
|
mClassName(nsCRT::strdup(aClassName)),
|
|
|
|
mProgID(nsCRT::strdup(aProgID))
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
// store a copy of the
|
|
|
|
compMgrSupports->QueryInterface(nsIServiceManager::GetIID(),
|
|
|
|
(void **)&mServiceManager);
|
1999-02-11 04:01:47 +03:00
|
|
|
}
|
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
nsMsgComposeFactory::~nsMsgComposeFactory()
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mServiceManager);
|
1999-03-30 06:24:18 +04:00
|
|
|
PL_strfree(mClassName);
|
|
|
|
PL_strfree(mProgID);
|
1999-02-11 04:01:47 +03:00
|
|
|
}
|
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
nsresult nsMsgComposeFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
|
|
|
if (aResult == NULL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Always NULL result, in case of failure
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
// we support two interfaces....nsISupports and nsFactory.....
|
1999-03-04 03:57:51 +03:00
|
|
|
if (aIID.Equals(::nsISupports::GetIID()))
|
1999-02-11 04:01:47 +03:00
|
|
|
*aResult = (void *)(nsISupports*)this;
|
1999-03-04 03:57:51 +03:00
|
|
|
else if (aIID.Equals(nsIFactory::GetIID()))
|
1999-02-11 04:01:47 +03:00
|
|
|
*aResult = (void *)(nsIFactory*)this;
|
|
|
|
|
|
|
|
if (*aResult == NULL)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
AddRef(); // Increase reference count for caller
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
NS_IMPL_ADDREF(nsMsgComposeFactory)
|
|
|
|
NS_IMPL_RELEASE(nsMsgComposeFactory)
|
1999-02-11 04:01:47 +03:00
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
nsresult nsMsgComposeFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult)
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
|
|
|
if (aResult == NULL)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
// ClassID check happens here
|
|
|
|
// Whenever you add a new class that supports an interface, plug it in here!!!
|
1999-02-23 04:02:49 +03:00
|
|
|
|
|
|
|
// mscott --> I've noticed that all of the "convience" functions (NS_*) used to
|
|
|
|
// create components are adding a ref count to the returned component...then at the end of
|
|
|
|
// CreateInstance we ref count again when we query interface for the desired interface.
|
|
|
|
// That's why we need to be careful and make sure we release the first ref count before returning...
|
|
|
|
// So, if you add a component here and it doesn't ref count when you create it then you might
|
|
|
|
// have a problem....
|
1999-02-11 04:01:47 +03:00
|
|
|
|
1999-04-06 07:24:04 +04:00
|
|
|
if (mClassID.Equals(kCSmtpServiceCID))
|
|
|
|
{
|
1999-02-23 04:02:49 +03:00
|
|
|
nsSmtpService * smtpService = new nsSmtpService();
|
|
|
|
// okay now turn around and give inst a handle on it....
|
1999-04-06 07:24:04 +04:00
|
|
|
return smtpService->QueryInterface(kISupportsIID, aResult);
|
1999-02-23 04:02:49 +03:00
|
|
|
}
|
1999-04-16 00:21:03 +04:00
|
|
|
// do they want a Message Compose interface ?
|
1999-06-07 22:48:32 +04:00
|
|
|
// RICHIE - not any more else if (mClassID.Equals(kCMsgComposeCID))
|
|
|
|
// RICHIE - not any more {
|
|
|
|
// RICHIE - not any more return NS_NewMsgCompose(aIID, aResult);
|
|
|
|
// RICHIE - not any more }
|
1999-02-11 04:01:47 +03:00
|
|
|
|
1999-04-16 00:21:03 +04:00
|
|
|
// do they want a Message Compose Fields interface ?
|
1999-04-06 07:24:04 +04:00
|
|
|
else if (mClassID.Equals(kCMsgCompFieldsCID))
|
|
|
|
{
|
|
|
|
return NS_NewMsgCompFields(aIID, aResult);
|
1999-02-11 04:01:47 +03:00
|
|
|
}
|
|
|
|
|
1999-04-16 00:21:03 +04:00
|
|
|
// do they want a Message Send interface ?
|
1999-04-06 07:24:04 +04:00
|
|
|
else if (mClassID.Equals(kCMsgSendCID))
|
|
|
|
{
|
|
|
|
return NS_NewMsgSend(aIID, aResult);
|
1999-02-17 22:38:44 +03:00
|
|
|
}
|
1999-06-07 22:48:32 +04:00
|
|
|
// do they want a Message Send Later interface ?
|
|
|
|
else if (mClassID.Equals(kCMsgSendLaterCID))
|
|
|
|
{
|
|
|
|
return NS_NewMsgSendLater(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
1999-04-16 00:21:03 +04:00
|
|
|
// do they want a Compose AppCore interface ?
|
1999-04-06 07:24:04 +04:00
|
|
|
else if (mClassID.Equals(kCComposeAppCoreCID))
|
|
|
|
{
|
|
|
|
return NS_NewComposeAppCore(aIID, aResult);
|
1999-03-11 04:41:25 +03:00
|
|
|
}
|
|
|
|
else if (mClassID.Equals(kCComposerBootstrapCID))
|
|
|
|
{
|
1999-04-06 07:24:04 +04:00
|
|
|
return NS_NewComposerBootstrap(aIID, aResult, mServiceManager);
|
1999-03-11 04:41:25 +03:00
|
|
|
}
|
|
|
|
else if (mClassID.Equals(kCComposerCID))
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
1999-04-06 07:24:04 +04:00
|
|
|
return NS_NewComposer(aIID, aResult);
|
1999-03-11 04:41:25 +03:00
|
|
|
}
|
|
|
|
|
1999-04-06 07:24:04 +04:00
|
|
|
return NS_NOINTERFACE;
|
1999-02-11 04:01:47 +03:00
|
|
|
}
|
|
|
|
|
1999-02-23 04:02:49 +03:00
|
|
|
nsresult nsMsgComposeFactory::LockFactory(PRBool aLock)
|
1999-02-11 04:01:47 +03:00
|
|
|
{
|
1999-02-23 04:02:49 +03:00
|
|
|
if (aLock)
|
|
|
|
PR_AtomicIncrement(&g_LockCount);
|
|
|
|
else
|
|
|
|
PR_AtomicDecrement(&g_LockCount);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-11 04:01:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// return the proper factory to the caller.
|
1999-03-09 12:52:30 +03:00
|
|
|
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
|
1999-02-26 15:24:22 +03:00
|
|
|
const nsCID &aClass,
|
|
|
|
const char *aClassName,
|
|
|
|
const char *aProgID,
|
1999-02-11 04:01:47 +03:00
|
|
|
nsIFactory **aFactory)
|
|
|
|
{
|
|
|
|
if (nsnull == aFactory)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
*aFactory = new nsMsgComposeFactory(aClass, aClassName, aProgID, aServMgr);
|
1999-02-11 04:01:47 +03:00
|
|
|
if (aFactory)
|
1999-03-11 04:41:25 +03:00
|
|
|
return (*aFactory)->QueryInterface(nsIFactory::GetIID(),
|
|
|
|
(void**)aFactory);
|
|
|
|
else
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-02-11 04:01:47 +03:00
|
|
|
}
|
|
|
|
|
1999-03-09 12:52:30 +03:00
|
|
|
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr)
|
1999-02-23 04:02:49 +03:00
|
|
|
{
|
|
|
|
return PRBool(g_InstanceCount == 0 && g_LockCount == 0);
|
|
|
|
}
|
|
|
|
|
1999-03-09 12:52:30 +03:00
|
|
|
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char* path)
|
1999-02-23 04:02:49 +03:00
|
|
|
{
|
1999-06-05 03:56:20 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsresult finalResult = NS_OK;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
1999-06-09 10:40:48 +04:00
|
|
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
|
1999-03-11 04:41:25 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// register the message compose factory
|
|
|
|
rv = compMgr->RegisterComponent(kCSmtpServiceCID,
|
|
|
|
"SMTP Service", nsnull,
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCMsgCompFieldsCID,
|
|
|
|
"Compose Fields",
|
|
|
|
nsnull, path, PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCMsgSendCID,
|
|
|
|
"Message Send",
|
|
|
|
nsnull, path, PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
1999-06-07 22:48:32 +04:00
|
|
|
rv = compMgr->RegisterComponent(kCMsgSendLaterCID,
|
|
|
|
"Message Send Later",
|
|
|
|
nsnull, path, PR_TRUE, PR_TRUE);
|
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
rv = compMgr->RegisterComponent(kCMsgComposeCID,
|
|
|
|
"Message Compose",
|
|
|
|
nsnull,
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCComposerCID,
|
|
|
|
"Message Composer",
|
|
|
|
"component://netscape/composer/application",
|
|
|
|
path, PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCComposerBootstrapCID,
|
|
|
|
"Netscape Composer Bootstrapper",
|
|
|
|
"component://netscape/composer",
|
|
|
|
path,
|
|
|
|
PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
rv = compMgr->RegisterComponent(kCComposeAppCoreCID,
|
|
|
|
"Composer AppCore",
|
|
|
|
"component://netscape/appcores/composer",
|
|
|
|
path,
|
|
|
|
PR_TRUE, PR_TRUE);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
printf("composer registering from %s\n",path);
|
|
|
|
#endif
|
1999-03-09 15:29:08 +03:00
|
|
|
|
1999-06-05 03:56:20 +04:00
|
|
|
return finalResult;
|
1999-02-23 04:02:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT nsresult
|
1999-03-09 12:52:30 +03:00
|
|
|
NSUnregisterSelf(nsISupports* aServMgr, const char* path)
|
1999-02-23 04:02:49 +03:00
|
|
|
{
|
1999-06-05 03:56:20 +04:00
|
|
|
nsresult finalResult = NS_OK;
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
1999-06-09 10:40:48 +04:00
|
|
|
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServMgr, kComponentManagerCID, &rv);
|
1999-03-11 04:41:25 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = compMgr->UnregisterComponent(kCComposeAppCoreCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-09 15:29:08 +03:00
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
rv = compMgr->UnregisterComponent(kCComposerBootstrapCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-09 12:52:30 +03:00
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
rv = compMgr->UnregisterComponent(kCComposerCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-09 15:29:08 +03:00
|
|
|
|
|
|
|
rv = compMgr->UnregisterComponent(kCMsgComposeCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv))finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
1999-03-09 12:52:30 +03:00
|
|
|
rv = compMgr->UnregisterComponent(kCMsgSendCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-09 15:29:08 +03:00
|
|
|
|
1999-06-07 22:48:32 +04:00
|
|
|
rv = compMgr->UnregisterComponent(kCMsgSendLaterCID, path);
|
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
|
|
|
|
1999-03-11 04:41:25 +03:00
|
|
|
rv = compMgr->UnregisterComponent(kCMsgCompFieldsCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
|
|
|
rv = compMgr->UnregisterComponent(kCSmtpServiceCID, path);
|
1999-06-05 03:56:20 +04:00
|
|
|
if (NS_FAILED(rv)) finalResult = rv;
|
1999-03-11 04:41:25 +03:00
|
|
|
|
1999-06-05 03:56:20 +04:00
|
|
|
return finalResult;
|
1999-02-26 15:24:22 +03:00
|
|
|
}
|