From e35294dadfd57b924c747b63292bfced6232c35b Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Tue, 4 May 1999 17:55:40 +0000 Subject: [PATCH] part of mailnews audit --> Conversion to NS_WITH_SERVICE --- .../base/src/nsCopyMessageStreamListener.cpp | 8 ++---- mailnews/base/src/nsMessenger.cpp | 14 +++++----- mailnews/compose/src/msgCompGlue.cpp | 13 +++------ mailnews/compose/src/nsComposer.cpp | 13 ++++----- mailnews/compose/src/nsMsgCompPrefs.cpp | 6 +---- mailnews/mime/src/comi18n.cpp | 27 +++++-------------- 6 files changed, 24 insertions(+), 57 deletions(-) diff --git a/mailnews/base/src/nsCopyMessageStreamListener.cpp b/mailnews/base/src/nsCopyMessageStreamListener.cpp index 6d50ea914ad..c5be94f03df 100644 --- a/mailnews/base/src/nsCopyMessageStreamListener.cpp +++ b/mailnews/base/src/nsCopyMessageStreamListener.cpp @@ -49,11 +49,8 @@ static nsresult GetMessage(nsIURL *aURL, nsIMessage **message) if(NS_FAILED(rv)) return rv; - nsIRDFService *rdfService; - - if(NS_SUCCEEDED(rv = nsServiceManager::GetService(kRDFServiceCID, - nsIRDFService::GetIID(), - (nsISupports**) &rdfService))) + NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv); + if(NS_SUCCEEDED(rv)) { nsIRDFResource *messageResource; if(NS_SUCCEEDED(rdfService->GetResource(uri, &messageResource))) @@ -61,7 +58,6 @@ static nsresult GetMessage(nsIURL *aURL, nsIMessage **message) messageResource->QueryInterface(nsIMessage::GetIID(), (void**)message); NS_RELEASE(messageResource); } - nsServiceManager::ReleaseService(kRDFServiceCID, rdfService); } delete[] uri; diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 40fb0fe2ae5..15267159dc0 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -94,19 +94,17 @@ nsMessengerBootstrap::Initialize() nsresult rv; printf("Messenger has been bootstrapped!\n"); - nsIScriptNameSetRegistry* registry; - rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID, - nsIScriptNameSetRegistry::GetIID(), - (nsISupports**)®istry); - if (NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIScriptNameSetRegistry, registry, kCScriptNameSetRegistryCID, &rv); + + if (NS_FAILED(rv)) return rv; + nsMessengerNameSet* nameSet = new nsMessengerNameSet(); + if (nameSet == nsnull) rv = NS_ERROR_OUT_OF_MEMORY; else rv = registry->AddExternalNameSet(nameSet); - (void)nsServiceManager::ReleaseService(kCScriptNameSetRegistryCID, - registry); + return rv; } diff --git a/mailnews/compose/src/msgCompGlue.cpp b/mailnews/compose/src/msgCompGlue.cpp index bae9473add0..5cc101e327f 100644 --- a/mailnews/compose/src/msgCompGlue.cpp +++ b/mailnews/compose/src/msgCompGlue.cpp @@ -103,12 +103,10 @@ nsresult ConvertFromUnicode(const nsString aCharset, const nsString inString, char** outCString) { - nsICharsetConverterManager * ccm = nsnull; nsresult res; - res = nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, - (nsISupports**)&ccm); + NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res); + if(NS_SUCCEEDED(res) && (nsnull != ccm)) { nsIUnicodeEncoder* encoder = nsnull; nsString convCharset; @@ -155,7 +153,6 @@ nsresult ConvertFromUnicode(const nsString aCharset, } NS_IF_RELEASE(encoder); } - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccm); } return res; } @@ -165,12 +162,9 @@ nsresult ConvertToUnicode(const nsString aCharset, const char *inCString, nsString &outString) { - nsICharsetConverterManager * ccm = nsnull; nsresult res; + NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res); - res = nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, - (nsISupports**)&ccm); if(NS_SUCCEEDED(res) && (nsnull != ccm)) { nsIUnicodeDecoder* decoder = nsnull; PRUnichar *unichars; @@ -201,7 +195,6 @@ nsresult ConvertToUnicode(const nsString aCharset, } NS_IF_RELEASE(decoder); } - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccm); } return res; } diff --git a/mailnews/compose/src/nsComposer.cpp b/mailnews/compose/src/nsComposer.cpp index 2f66e7b233d..06e44bde8f1 100644 --- a/mailnews/compose/src/nsComposer.cpp +++ b/mailnews/compose/src/nsComposer.cpp @@ -100,19 +100,16 @@ nsComposerBootstrap::Initialize() nsresult rv; printf("Composer has been bootstrapped!\n"); - nsIScriptNameSetRegistry* registry; - rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID, - nsIScriptNameSetRegistry::GetIID(), - (nsISupports**)®istry); - if (NS_FAILED(rv)) - return rv; + NS_WITH_SERVICE(nsIScriptNameSetRegistry, registry, kCScriptNameSetRegistryCID, &rv); + + if (NS_FAILED(rv)) return rv; + nsComposerNameSet* nameSet = new nsComposerNameSet(); if (nameSet == nsnull) rv = NS_ERROR_OUT_OF_MEMORY; else rv = registry->AddExternalNameSet(nameSet); - (void)nsServiceManager::ReleaseService(kCScriptNameSetRegistryCID, - registry); + return rv; } diff --git a/mailnews/compose/src/nsMsgCompPrefs.cpp b/mailnews/compose/src/nsMsgCompPrefs.cpp index 6e87f34b041..0f3380c0107 100644 --- a/mailnews/compose/src/nsMsgCompPrefs.cpp +++ b/mailnews/compose/src/nsMsgCompPrefs.cpp @@ -32,15 +32,11 @@ nsMsgCompPrefs::nsMsgCompPrefs(void * identiy /*= nsnull*/) m_userEmail = nsnull; // get the current identity from the mail session.... - nsIMsgMailSession * mailSession = nsnull; - res = nsServiceManager::GetService(kCMsgMailSessionCID, - nsIMsgMailSession::GetIID(), - (nsISupports **) &mailSession); + NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &res); if (NS_SUCCEEDED(res) && mailSession) { nsIMsgIdentity * identity = nsnull; res = mailSession->GetCurrentIdentity(&identity); // now release the mail service because we are done with it - nsServiceManager::ReleaseService(kCMsgMailSessionCID, mailSession); if (NS_SUCCEEDED(res) && identity) { char * aString = nsnull; diff --git a/mailnews/mime/src/comi18n.cpp b/mailnews/mime/src/comi18n.cpp index 8bc84b5bead..1977b2a83d3 100644 --- a/mailnews/mime/src/comi18n.cpp +++ b/mailnews/mime/src/comi18n.cpp @@ -1182,17 +1182,13 @@ static PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_char { char *dstPtr = nsnull; PRInt32 dstLength = 0; - nsICharsetConverterManager * ccm = nsnull; nsresult res; if (nsnull == from_charset || nsnull == to_charset || - '\0' == *from_charset || '\0' == *to_charset || nsnull == inBuffer) { + '\0' == *from_charset || '\0' == *to_charset || nsnull == inBuffer) return -1; - } - res = nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, - (nsISupports**)&ccm); + NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res); if(NS_SUCCEEDED(res) && (nsnull != ccm)) { nsString aCharset(from_charset); @@ -1243,7 +1239,6 @@ static PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_char } NS_IF_RELEASE(decoder); } - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccm); } // set the results @@ -1255,16 +1250,13 @@ static PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_char static PRInt32 INTL_ConvertToUnicode(const char* from_charset, const char* aBuffer, const PRInt32 aLength, void** uniBuffer, PRInt32* uniLength) { - nsICharsetConverterManager * ccm = nsnull; nsresult res; if (nsnull == from_charset || '\0' == *from_charset|| nsnull == aBuffer) { return -1; } - - res = nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, - (nsISupports**)&ccm); + + NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res); if(NS_SUCCEEDED(res) && (nsnull != ccm)) { nsString aCharset(from_charset); nsIUnicodeDecoder* decoder = nsnull; @@ -1287,8 +1279,7 @@ static PRInt32 INTL_ConvertToUnicode(const char* from_charset, const char* aBuff res = NS_ERROR_OUT_OF_MEMORY; } NS_IF_RELEASE(decoder); - } - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccm); + } } return NS_SUCCEEDED(res) ? 0 : -1; } @@ -1296,16 +1287,13 @@ static PRInt32 INTL_ConvertToUnicode(const char* from_charset, const char* aBuff static PRInt32 INTL_ConvertFromUnicode(const char* to_charset, const void* uniBuffer, const PRInt32 uniLength, char** aBuffer) { - nsICharsetConverterManager * ccm = nsnull; nsresult res; if (nsnull == to_charset || '\0' == *to_charset|| nsnull == uniBuffer) { return -1; } - res = nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, - (nsISupports**)&ccm); + NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res); if(NS_SUCCEEDED(res) && (nsnull != ccm)) { nsString aCharset(to_charset); nsIUnicodeEncoder* encoder = nsnull; @@ -1327,8 +1315,7 @@ static PRInt32 INTL_ConvertFromUnicode(const char* to_charset, const void* uniBu res = NS_ERROR_OUT_OF_MEMORY; } NS_IF_RELEASE(encoder); - } - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccm); + } } return NS_SUCCEEDED(res) ? 0 : -1; }