From 00dde597ed8e47d0c96081a31e7df2c9332935fe Mon Sep 17 00:00:00 2001 From: "ruslan%netscape.com" Date: Tue, 13 Jun 2000 03:00:53 +0000 Subject: [PATCH] Fixing 42107, a=gagan. Documenting some APIs in the process as well. git-svn-id: svn://10.0.0.236/trunk@72089 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/netwerk/base/public/nsIIOService.idl | 28 ++++++++++++++ .../base/public/nsISocketTransportService.idl | 1 + mozilla/netwerk/base/src/nsIOService.cpp | 37 ++++++++++++++++++- mozilla/netwerk/base/src/nsIOService.h | 1 + .../base/src/nsSocketTransportService.cpp | 31 ++++++++++------ 5 files changed, 84 insertions(+), 14 deletions(-) diff --git a/mozilla/netwerk/base/public/nsIIOService.idl b/mozilla/netwerk/base/public/nsIIOService.idl index 6244006a4f8..2ba8664b89c 100644 --- a/mozilla/netwerk/base/public/nsIIOService.idl +++ b/mozilla/netwerk/base/public/nsIIOService.idl @@ -44,6 +44,9 @@ interface nsIIOService : nsISupports { /** * Returns a protocol handler for a given URI scheme. + * + * @param scheme URI scheme + * @return reference to nsIProtcolHandler */ nsIProtocolHandler getProtocolHandler(in string scheme); @@ -52,6 +55,10 @@ interface nsIIOService : nsISupports * of the URI spec, and then delegating the construction of the URI * to the protocol handler for that scheme. QueryInterface can be used * on the resulting URI object to obtain a more specific type of URI. + * + * @param aSpec URI spec (http, ftp, etc) + * @param aBaseURI nsIURI to construct the actual URI from + * @return reference to a new nsIURI object */ nsIURI newURI(in string aSpec, in nsIURI aBaseURI); @@ -66,6 +73,9 @@ interface nsIIOService : nsISupports * (e.g. a file: channel), or if a redirect occurs, causing the current * URL to become different from the original URL. If NULL, the aURI parameter * will be used as the originalURI instead. + * + * @param aURI - nsIURI to make a channel from + * @return a reference to the new nsIChannel object */ nsIChannel newChannelFromURI(in nsIURI aURI); @@ -79,6 +89,10 @@ interface nsIIOService : nsISupports * (e.g. a file: channel), or if a redirect occurs, causing the current * URL to become different from the original URL. If NULL, the aURI parameter * will be used as the originalURI instead. + * + * @param aSpec URI spec to select the appropriate protocol handler + * @param aBaseURI a base URI to create a channel to + * @return a reference to the new nsIChannel object */ nsIChannel newChannel(in string aSpec, in nsIURI aBaseURI); @@ -130,16 +144,26 @@ interface nsIIOService : nsISupports /** * Encode characters into % escaped hexcodes. + * + * @param str a string to convert from + * @param mask a mask of flags to tell the converter which part of the url to escape + * @return escaped string */ string escape(in string str, in short mask); /** * Decode % escaped hex codes into character values. + * + * @param str a string to unescape from + * @return resulted unescaped string */ string unescape(in string str); /** * Get port from string. + * + * @param str URI-style string + * @return port number */ long extractPort(in string str); @@ -150,6 +174,10 @@ interface nsIIOService : nsISupports * "/a/b/c/d/e/" yields "/a/b/c/foo/baz.html". Attempting to * ascend above the base results in the NS_ERROR_MALFORMED_URI * exception. If basePath is null, it treats it as "/". + * + * @param relativePath a relative URI + * @param basePath a base URI + * @return a new string, representing canonical uri */ string resolveRelativePath(in string relativePath, in string basePath); diff --git a/mozilla/netwerk/base/public/nsISocketTransportService.idl b/mozilla/netwerk/base/public/nsISocketTransportService.idl index e9d11c7617a..c681cadb05c 100644 --- a/mozilla/netwerk/base/public/nsISocketTransportService.idl +++ b/mozilla/netwerk/base/public/nsISocketTransportService.idl @@ -60,6 +60,7 @@ interface nsISocketTransportService : nsISupports boolean reuseTransport(in nsIChannel i_Transport); void init (); + void lateInit(); void shutdown(); void wakeup (in nsIChannel i_Transport); diff --git a/mozilla/netwerk/base/src/nsIOService.cpp b/mozilla/netwerk/base/src/nsIOService.cpp index 4c4bc1498e5..3c74d3bda95 100644 --- a/mozilla/netwerk/base/src/nsIOService.cpp +++ b/mozilla/netwerk/base/src/nsIOService.cpp @@ -58,6 +58,7 @@ nsIOService::Init() getter_AddRefs(mSocketTransportService)); if (NS_FAILED(rv)) return rv; + rv = nsServiceManager::GetService(kFileTransportService, NS_GET_IID(nsIFileTransportService), getter_AddRefs(mFileTransportService)); @@ -65,6 +66,16 @@ nsIOService::Init() rv = nsServiceManager::GetService(kDNSServiceCID, NS_GET_IID(nsIDNSService), getter_AddRefs(mDNSService)); + + return rv; +} + +nsresult +nsIOService::LateInit() +{ + nsresult rv; + + rv = mSocketTransportService -> LateInit (); return rv; } @@ -76,20 +87,42 @@ nsIOService::~nsIOService() NS_METHOD nsIOService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { + static nsISupports *_rValue = nsnull; + nsresult rv; NS_ENSURE_NO_AGGREGATION(aOuter); + if (_rValue) + { + NS_ADDREF (_rValue); + *aResult = _rValue; + return NS_OK; + } + nsIOService* _ios = new nsIOService(); if (_ios == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(_ios); rv = _ios->Init(); - if (NS_FAILED(rv)) { + if (NS_FAILED(rv)) + { delete _ios; return rv; } + rv = _ios->QueryInterface(aIID, aResult); - NS_RELEASE(_ios); + + if (NS_FAILED(rv)) + { + delete _ios; + return rv; + } + + _rValue = NS_STATIC_CAST (nsISupports*, *aResult); + _ios -> LateInit (); + NS_RELEASE (_rValue); + _rValue = nsnull; + return rv; } diff --git a/mozilla/netwerk/base/src/nsIOService.h b/mozilla/netwerk/base/src/nsIOService.h index 3cf8d67936a..c3d65756414 100644 --- a/mozilla/netwerk/base/src/nsIOService.h +++ b/mozilla/netwerk/base/src/nsIOService.h @@ -47,6 +47,7 @@ public: Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); nsresult Init(); + nsresult LateInit(); nsresult NewURI(const char* aSpec, nsIURI* aBaseURI, nsIURI* *result, nsIProtocolHandler* *hdlrResult); diff --git a/mozilla/netwerk/base/src/nsSocketTransportService.cpp b/mozilla/netwerk/base/src/nsSocketTransportService.cpp index a2930dcd283..b1b1ec4fa76 100644 --- a/mozilla/netwerk/base/src/nsSocketTransportService.cpp +++ b/mozilla/netwerk/base/src/nsSocketTransportService.cpp @@ -166,6 +166,25 @@ nsSocketTransportService::Init(void) return rv; } +NS_IMETHODIMP +nsSocketTransportService::LateInit(void) +{ + nsresult res; + + if (!m_stringBundle) + { + char* propertyURL = NECKO_MSGS_URL; + + NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res); + if (NS_SUCCEEDED (res) && (nsnull != sBundleService)) + { + nsILocale *locale = nsnull; + res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(m_stringBundle)); + } + } + + return NS_OK; +} nsresult nsSocketTransportService::AddToWorkQ(nsSocketTransport* aTransport) { @@ -659,18 +678,6 @@ nsSocketTransportService::GetNeckoStringByName (const char *aName, PRUnichar **a nsresult res; nsAutoString resultString; resultString.AssignWithConversion(aName); - if (!m_stringBundle) - { - char* propertyURL = NECKO_MSGS_URL; - - NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res); - if (NS_SUCCEEDED (res) && (nsnull != sBundleService)) - { - nsILocale *locale = nsnull; - res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(m_stringBundle)); - } - } - if (m_stringBundle) { nsAutoString unicodeName; unicodeName.AssignWithConversion(aName);