From e1ba63180fb42c403a686cd25a6ace4c2ca75dac Mon Sep 17 00:00:00 2001 From: "kipp%netscape.com" Date: Thu, 30 Sep 1999 01:53:31 +0000 Subject: [PATCH] new git-svn-id: svn://10.0.0.236/trunk@49389 18797224-902f-48f8-a5cc-f745e15eee43 --- .../modules/libjar/nsJARProtocolModule.cpp | 240 ++++++++++++ mozilla/netwerk/build/nsNetModule.cpp | 360 ++++++++++++++++++ .../about/src/nsAboutProtocolModule.cpp | 253 ++++++++++++ .../protocol/data/src/nsDataModule.cpp | 238 ++++++++++++ .../file/src/nsFileProtocolModule.cpp | 241 ++++++++++++ .../netwerk/protocol/ftp/src/nsFtpModule.cpp | 240 ++++++++++++ .../protocol/http/src/nsHTTPHandlerModule.cpp | 248 ++++++++++++ .../protocol/jar/src/nsJARProtocolModule.cpp | 240 ++++++++++++ .../resource/src/nsResourceProtocolModule.cpp | 239 ++++++++++++ 9 files changed, 2299 insertions(+) create mode 100644 mozilla/modules/libjar/nsJARProtocolModule.cpp create mode 100644 mozilla/netwerk/build/nsNetModule.cpp create mode 100644 mozilla/netwerk/protocol/about/src/nsAboutProtocolModule.cpp create mode 100644 mozilla/netwerk/protocol/data/src/nsDataModule.cpp create mode 100644 mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp create mode 100644 mozilla/netwerk/protocol/ftp/src/nsFtpModule.cpp create mode 100644 mozilla/netwerk/protocol/http/src/nsHTTPHandlerModule.cpp create mode 100644 mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp create mode 100644 mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp diff --git a/mozilla/modules/libjar/nsJARProtocolModule.cpp b/mozilla/modules/libjar/nsJARProtocolModule.cpp new file mode 100644 index 00000000000..048f442f04f --- /dev/null +++ b/mozilla/modules/libjar/nsJARProtocolModule.cpp @@ -0,0 +1,240 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsJARProtocolHandler.h" +#include "nscore.h" + +static NS_DEFINE_CID(kJARProtocolHandlerCID, NS_JARPROTOCOLHANDLER_CID); + +/////////////////////////////////////////////////////////////////////////////// + +class nsJARProtocolModule : public nsIModule +{ +public: + nsJARProtocolModule(); + virtual ~nsJARProtocolModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsJARProtocolModule::nsJARProtocolModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsJARProtocolModule::~nsJARProtocolModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsJARProtocolModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsJARProtocolModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsJARProtocolModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsJARProtocolModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kJARProtocolHandlerCID)) { + if (!mFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFactory), + nsJARProtocolHandler::Create); + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsJARProtocolModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "JAR Protocol Handler", &kJARProtocolHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "JAR", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsJARProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering jar: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsJARProtocolModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsJARProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering jar: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsJARProtocolModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsJARProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsJARProtocolModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsJARProtocolModule: Module already created."); + + // Create and initialize the module instance + nsJARProtocolModule *m = new nsJARProtocolModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/build/nsNetModule.cpp b/mozilla/netwerk/build/nsNetModule.cpp new file mode 100644 index 00000000000..877adf9cffb --- /dev/null +++ b/mozilla/netwerk/build/nsNetModule.cpp @@ -0,0 +1,360 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsIOService.h" +#include "nsNetModuleMgr.h" +#include "nsFileTransportService.h" +#include "nsSocketTransportService.h" +#include "nsSocketProviderService.h" +#include "nscore.h" +#include "nsStdURL.h" +#include "nsSimpleURI.h" +#include "nsDnsService.h" +#include "nsLoadGroup.h" +#include "nsInputStreamChannel.h" + +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); +static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); +static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); +static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); +static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); +static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID); +static NS_DEFINE_CID(kExternalModuleManagerCID, NS_NETMODULEMGR_CID); +static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID); +static NS_DEFINE_CID(kLoadGroupCID, NS_LOADGROUP_CID); +static NS_DEFINE_CID(kInputStreamChannelCID, NS_INPUTSTREAMCHANNEL_CID); + +/////////////////////////////////////////////////////////////////////////////// + +// Module implementation for the net library +class nsNetModule : public nsIModule +{ +public: + nsNetModule(); + virtual ~nsNetModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mIOServiceFactory; + nsCOMPtr mFileTransportServiceFactory; + nsCOMPtr mSocketTransportServiceFactory; + nsCOMPtr mSocketProviderServiceFactory; + nsCOMPtr mDNSServiceFactory; + nsCOMPtr mStandardURLFactory; + nsCOMPtr mSimpleURIFactory; + nsCOMPtr mExternalModuleManagerFactory; + nsCOMPtr mLoadGroupFactory; + nsCOMPtr mInputStreamChannelFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsNetModule::nsNetModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsNetModule::~nsNetModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsNetModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsNetModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsNetModule::Shutdown() +{ + // Release the factory objects + mIOServiceFactory = nsnull; + mFileTransportServiceFactory = nsnull; + mSocketTransportServiceFactory = nsnull; + mSocketProviderServiceFactory = nsnull; + mDNSServiceFactory = nsnull; + mStandardURLFactory = nsnull; + mSimpleURIFactory = nsnull; + mExternalModuleManagerFactory = nsnull; + mLoadGroupFactory = nsnull; + mInputStreamChannelFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsNetModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kIOServiceCID)) { + if (!mIOServiceFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mIOServiceFactory), + nsIOService::Create); + } + fact = mIOServiceFactory; + } + else if (aClass.Equals(kFileTransportServiceCID)) { + if (!mFileTransportServiceFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFileTransportServiceFactory), + nsFileTransportService::Create); + } + fact = mFileTransportServiceFactory; + } + else if (aClass.Equals(kSocketTransportServiceCID)) { + if (!mSocketTransportServiceFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mSocketTransportServiceFactory), + nsSocketTransportService::Create); + } + fact = mSocketTransportServiceFactory; + } + else if (aClass.Equals(kSocketProviderServiceCID)) { + if (!mSocketProviderServiceFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mSocketProviderServiceFactory), + nsSocketProviderService::Create); + } + fact = mSocketProviderServiceFactory; + } + else if (aClass.Equals(kDNSServiceCID)) { + if (!mDNSServiceFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mDNSServiceFactory), + nsDNSService::Create); + } + fact = mDNSServiceFactory; + } + else if (aClass.Equals(kStandardURLCID)) { + if (!mStandardURLFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mStandardURLFactory), + nsStdURL::Create); + } + fact = mStandardURLFactory; + } + else if (aClass.Equals(kSimpleURICID)) { + if (!mSimpleURIFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mSimpleURIFactory), + nsSimpleURI::Create); + } + fact = mSimpleURIFactory; + } + else if (aClass.Equals(kExternalModuleManagerCID)) { + if (!mExternalModuleManagerFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mExternalModuleManagerFactory), + nsNetModuleMgr::Create); + } + fact = mExternalModuleManagerFactory; + } +// XXX not registered! +#if 1 + else if (aClass.Equals(kLoadGroupCID)) { + if (!mLoadGroupFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mLoadGroupFactory), + nsLoadGroup::Create); + } + fact = mLoadGroupFactory; + } +#endif + else if (aClass.Equals(kInputStreamChannelCID)) { + if (!mInputStreamChannelFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mInputStreamChannelFactory), + nsInputStreamChannel::Create); + } + fact = mInputStreamChannelFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsNetModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "Network Service", &kIOServiceCID, + "component://netscape/network/net-service", }, + { "File Transport Service", &kFileTransportServiceCID, + "component://netscape/network/file-transport-service", }, + { "Socket Transport Service", &kSocketTransportServiceCID, + "component://netscape/network/socket-transport-service", }, + { "Socket Provider Service", &kSocketProviderServiceCID, + "component://netscape/network/socket-provider-service", }, + { "DNS Service", &kDNSServiceCID, + "component://netscape/network/dns-service", }, + { "Standard URL Implementation", &kStandardURLCID, + "component://netscape/network/standard-url", }, + { "Simple URI Implementation", &kSimpleURICID, + "component://netscape/network/simple-uri", }, + { "External Module Manager", &kExternalModuleManagerCID, + "component://netscape/network/net-extern-mod", }, + { "Input Stream Channel", &kInputStreamChannelCID, + "component://netscape/network/input-stream-channel", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsNetModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering net components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsNetModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsNetModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering net components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsNetModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsNetModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsNetModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsNetModule: Module already created."); + + // Create and initialize the module instance + nsNetModule *m = new nsNetModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/about/src/nsAboutProtocolModule.cpp b/mozilla/netwerk/protocol/about/src/nsAboutProtocolModule.cpp new file mode 100644 index 00000000000..da983018487 --- /dev/null +++ b/mozilla/netwerk/protocol/about/src/nsAboutProtocolModule.cpp @@ -0,0 +1,253 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsAboutProtocolHandler.h" +#include "nsAboutBlank.h" +#include "nscore.h" + +static NS_DEFINE_CID(kAboutProtocolHandlerCID, NS_ABOUTPROTOCOLHANDLER_CID); +static NS_DEFINE_CID(kAboutBlankModuleCID, NS_ABOUT_BLANK_MODULE_CID); + +/////////////////////////////////////////////////////////////////////////////// + +class nsAboutProtocolModule : public nsIModule +{ +public: + nsAboutProtocolModule(); + virtual ~nsAboutProtocolModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mAboutProtocolFactory; + nsCOMPtr mAboutBlankFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsAboutProtocolModule::nsAboutProtocolModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsAboutProtocolModule::~nsAboutProtocolModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsAboutProtocolModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsAboutProtocolModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsAboutProtocolModule::Shutdown() +{ + // Release the factory objects + mAboutProtocolFactory = nsnull; + mAboutBlankFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsAboutProtocolModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kAboutProtocolHandlerCID)) { + if (!mAboutProtocolFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mAboutProtocolFactory), + nsAboutProtocolHandler::Create); + } + fact = mAboutProtocolFactory; + } + else if (aClass.Equals(kAboutBlankModuleCID)) { + if (!mAboutBlankFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mAboutBlankFactory), + nsAboutBlank::Create); + } + fact = mAboutBlankFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsAboutProtocolModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "About Protocol Handler", &kAboutProtocolHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "about", }, + { "about:blank", &kAboutBlankModuleCID, + NS_ABOUT_MODULE_PROGID_PREFIX "blank", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsAboutProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering about: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsAboutProtocolModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsAboutProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering about: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsAboutProtocolModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsAboutProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsAboutProtocolModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsAboutProtocolModule: Module already created."); + + // Create and initialize the module instance + nsAboutProtocolModule *m = new nsAboutProtocolModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/data/src/nsDataModule.cpp b/mozilla/netwerk/protocol/data/src/nsDataModule.cpp new file mode 100644 index 00000000000..6a4d11df2fa --- /dev/null +++ b/mozilla/netwerk/protocol/data/src/nsDataModule.cpp @@ -0,0 +1,238 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsDataHandler.h" +#include "nscore.h" + +static NS_DEFINE_CID(kDataHandlerCID, NS_DATAHANDLER_CID); + +class nsDataProtocolModule : public nsIModule +{ +public: + nsDataProtocolModule(); + virtual ~nsDataProtocolModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsDataProtocolModule::nsDataProtocolModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsDataProtocolModule::~nsDataProtocolModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsDataProtocolModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsDataProtocolModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsDataProtocolModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsDataProtocolModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kDataHandlerCID)) { + if (!mFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFactory), + nsDataHandler::Create); + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsDataProtocolModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "Data Protocol Handler", &kDataHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "data", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsDataProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering data: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsDataProtocolModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsDataProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering data: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsDataProtocolModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDataProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsDataProtocolModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsDataProtocolModule: Module already created."); + + // Create and initialize the module instance + nsDataProtocolModule *m = new nsDataProtocolModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp b/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp new file mode 100644 index 00000000000..3d8b820e73e --- /dev/null +++ b/mozilla/netwerk/protocol/file/src/nsFileProtocolModule.cpp @@ -0,0 +1,241 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsFileProtocolHandler.h" +#include "nscore.h" + +static NS_DEFINE_CID(kFileProtocolHandlerCID, NS_FILEPROTOCOLHANDLER_CID); + +//////////////////////////////////////////////////////////////////////////////// + +// Module implementation +class nsFileProtocolModule : public nsIModule +{ +public: + nsFileProtocolModule(); + virtual ~nsFileProtocolModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsFileProtocolModule::nsFileProtocolModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsFileProtocolModule::~nsFileProtocolModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsFileProtocolModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsFileProtocolModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsFileProtocolModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsFileProtocolModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kFileProtocolHandlerCID)) { + if (!mFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFactory), + nsFileProtocolHandler::Create); + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsFileProtocolModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "File Protocol Handler", &kFileProtocolHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "file", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsFileProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering file: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsFileProtocolModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsFileProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering file: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsFileProtocolModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsFileProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsFileProtocolModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsFileProtocolModule: Module already created."); + + // Create and initialize the module instance + nsFileProtocolModule *m = new nsFileProtocolModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpModule.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpModule.cpp new file mode 100644 index 00000000000..5f695b89d6b --- /dev/null +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpModule.cpp @@ -0,0 +1,240 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsFtpProtocolHandler.h" +#include "nscore.h" + +static NS_DEFINE_CID(kFtpProtocolHandlerCID, NS_FTPPROTOCOLHANDLER_CID); + +/////////////////////////////////////////////////////////////////////////////// + +class nsFTPModule : public nsIModule +{ +public: + nsFTPModule(); + virtual ~nsFTPModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsFTPModule::nsFTPModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsFTPModule::~nsFTPModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsFTPModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsFTPModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsFTPModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsFTPModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kFtpProtocolHandlerCID)) { + if (!mFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFactory), + nsFtpProtocolHandler::Create); + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsFTPModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "FTP Protocol Handler", &kFtpProtocolHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "ftp", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsFTPModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering ftp: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsFTPModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsFTPModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering ftp: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsFTPModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsFTPModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsFTPModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsFTPModule: Module already created."); + + // Create and initialize the module instance + nsFTPModule *m = new nsFTPModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPHandlerModule.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPHandlerModule.cpp new file mode 100644 index 00000000000..b4040bb0201 --- /dev/null +++ b/mozilla/netwerk/protocol/http/src/nsHTTPHandlerModule.cpp @@ -0,0 +1,248 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nscore.h" +#include "nsIHTTPProtocolHandler.h" +#include "nsHTTPCID.h" +#include "nsHTTPHandlerFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsXPComFactory.h" +#include "nsIProtocolHandler.h" // for NS_NETWORK_PROTOCOL_PROGID_PREFIX + +static NS_DEFINE_CID(kHTTPHandlerCID, NS_HTTP_HANDLER_FACTORY_CID); + +//////////////////////////////////////////////////////////////////////// + +class nsHTTPHandlerModule : public nsIModule +{ +public: + nsHTTPHandlerModule(); + virtual ~nsHTTPHandlerModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsHTTPHandlerModule::nsHTTPHandlerModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsHTTPHandlerModule::~nsHTTPHandlerModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsHTTPHandlerModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsHTTPHandlerModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsHTTPHandlerModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsHTTPHandlerModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kHTTPHandlerCID)) { + if (!mFactory) { + nsHTTPHandlerFactory* factory = new nsHTTPHandlerFactory(aClass); + if (!factory) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + else { + mFactory = factory; + } + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsHTTPHandlerModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "HTTP Handler", &kHTTPHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "http", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsHTTPHandlerModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering http: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsHTTPHandlerModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsHTTPHandlerModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering http: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsHTTPHandlerModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsHTTPHandlerModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsHTTPHandlerModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsHTTPHandlerModule: Module already created."); + + // Create and initialize the module instance + nsHTTPHandlerModule *m = new nsHTTPHandlerModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp b/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp new file mode 100644 index 00000000000..048f442f04f --- /dev/null +++ b/mozilla/netwerk/protocol/jar/src/nsJARProtocolModule.cpp @@ -0,0 +1,240 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsJARProtocolHandler.h" +#include "nscore.h" + +static NS_DEFINE_CID(kJARProtocolHandlerCID, NS_JARPROTOCOLHANDLER_CID); + +/////////////////////////////////////////////////////////////////////////////// + +class nsJARProtocolModule : public nsIModule +{ +public: + nsJARProtocolModule(); + virtual ~nsJARProtocolModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsJARProtocolModule::nsJARProtocolModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsJARProtocolModule::~nsJARProtocolModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsJARProtocolModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsJARProtocolModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsJARProtocolModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsJARProtocolModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kJARProtocolHandlerCID)) { + if (!mFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFactory), + nsJARProtocolHandler::Create); + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsJARProtocolModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "JAR Protocol Handler", &kJARProtocolHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "JAR", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsJARProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering jar: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsJARProtocolModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsJARProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering jar: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsJARProtocolModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsJARProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsJARProtocolModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsJARProtocolModule: Module already created."); + + // Create and initialize the module instance + nsJARProtocolModule *m = new nsJARProtocolModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +} diff --git a/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp b/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp new file mode 100644 index 00000000000..b087fb9ab23 --- /dev/null +++ b/mozilla/netwerk/protocol/resource/src/nsResourceProtocolModule.cpp @@ -0,0 +1,239 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsCOMPtr.h" +#include "nsIModule.h" +#include "nsIGenericFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsResourceProtocolHandler.h" +#include "nscore.h" + +static NS_DEFINE_CID(kResourceProtocolHandlerCID, NS_RESOURCEPROTOCOLHANDLER_CID); + +// Module implementation for the resource protocol library +class nsResourceProtocolModule : public nsIModule +{ +public: + nsResourceProtocolModule(); + virtual ~nsResourceProtocolModule(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIMODULE + +protected: + nsresult Initialize(); + + void Shutdown(); + + PRBool mInitialized; + nsCOMPtr mFactory; +}; + +static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID); + +nsResourceProtocolModule::nsResourceProtocolModule() + : mInitialized(PR_FALSE) +{ + NS_INIT_ISUPPORTS(); +} + +nsResourceProtocolModule::~nsResourceProtocolModule() +{ + Shutdown(); +} + +NS_IMPL_ISUPPORTS(nsResourceProtocolModule, kIModuleIID) + +// Perform our one-time intialization for this module +nsresult +nsResourceProtocolModule::Initialize() +{ + if (mInitialized) { + return NS_OK; + } + mInitialized = PR_TRUE; + return NS_OK; +} + +// Shutdown this module, releasing all of the module resources +void +nsResourceProtocolModule::Shutdown() +{ + // Release the factory object + mFactory = nsnull; +} + +// Create a factory object for creating instances of aClass. +NS_IMETHODIMP +nsResourceProtocolModule::GetClassObject(nsIComponentManager *aCompMgr, + const nsCID& aClass, + const nsIID& aIID, + void** r_classObj) +{ + nsresult rv; + + // Defensive programming: Initialize *r_classObj in case of error below + if (!r_classObj) { + return NS_ERROR_INVALID_POINTER; + } + *r_classObj = NULL; + + // Do one-time-only initialization if necessary + if (!mInitialized) { + rv = Initialize(); + if (NS_FAILED(rv)) { + // Initialization failed! yikes! + return rv; + } + } + + // Choose the appropriate factory, based on the desired instance + // class type (aClass). + nsCOMPtr fact; + if (aClass.Equals(kResourceProtocolHandlerCID)) { + if (!mFactory) { + rv = NS_NewGenericFactory(getter_AddRefs(mFactory), + nsResourceProtocolHandler::Create); + } + fact = mFactory; + } + else { + rv = NS_ERROR_FACTORY_NOT_REGISTERED; +#ifdef DEBUG + char* cs = aClass.ToString(); + printf("+++ nsResourceProtocolModule: unable to create factory for %s\n", cs); + nsCRT::free(cs); +#endif + } + + if (fact) { + rv = fact->QueryInterface(aIID, r_classObj); + } + + return rv; +} + +//---------------------------------------- + +struct Components { + const char* mDescription; + const nsID* mCID; + const char* mProgID; +}; + +// The list of components we register +static Components gComponents[] = { + { "Resource Protocol Handler", &kResourceProtocolHandlerCID, + NS_NETWORK_PROTOCOL_PROGID_PREFIX "resource", }, +}; +#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) + +NS_IMETHODIMP +nsResourceProtocolModule::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation, + const char* componentType) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG + printf("*** Registering resource: components\n"); +#endif + + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription, + cp->mProgID, aPath, PR_TRUE, + PR_TRUE); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsResourceProtocolModule: unable to register %s component => %x\n", + cp->mDescription, rv); +#endif + break; + } + cp++; + } + + return rv; +} + +NS_IMETHODIMP +nsResourceProtocolModule::UnregisterSelf(nsIComponentManager* aCompMgr, + nsIFileSpec* aPath, + const char* registryLocation) +{ +#ifdef DEBUG + printf("*** Unregistering resource: components\n"); +#endif + Components* cp = gComponents; + Components* end = cp + NUM_COMPONENTS; + while (cp < end) { + nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath); + if (NS_FAILED(rv)) { +#ifdef DEBUG + printf("nsResourceProtocolModule: unable to unregister %s component => %x\n", + cp->mDescription, rv); +#endif + } + cp++; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsResourceProtocolModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload) +{ + if (!okToUnload) { + return NS_ERROR_INVALID_POINTER; + } + *okToUnload = PR_FALSE; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------------------- + +static nsResourceProtocolModule *gModule = NULL; + +extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, + nsIFileSpec* location, + nsIModule** return_cobj) +{ + nsresult rv = NS_OK; + + NS_ASSERTION(return_cobj, "Null argument"); + NS_ASSERTION(gModule == NULL, "nsResourceProtocolModule: Module already created."); + + // Create and initialize the module instance + nsResourceProtocolModule *m = new nsResourceProtocolModule(); + if (!m) { + return NS_ERROR_OUT_OF_MEMORY; + } + + // Increase refcnt and store away nsIModule interface to m in return_cobj + rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj); + if (NS_FAILED(rv)) { + delete m; + m = nsnull; + } + gModule = m; // WARNING: Weak Reference + return rv; +}