From d876a8d7cc32bc297420b3dc4ec852c2675e52f8 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Sat, 26 Jan 2002 00:46:09 +0000 Subject: [PATCH] backing out my changes -- rjc says it causes moz not to startup! --- netwerk/base/src/nsIOServiceMac.cpp | 189 ++++++++++++++-------------- 1 file changed, 95 insertions(+), 94 deletions(-) diff --git a/netwerk/base/src/nsIOServiceMac.cpp b/netwerk/base/src/nsIOServiceMac.cpp index daa1acb7e951..e91aeedba44b 100644 --- a/netwerk/base/src/nsIOServiceMac.cpp +++ b/netwerk/base/src/nsIOServiceMac.cpp @@ -20,8 +20,6 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Alec Flett - * Darin Fisher * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -37,14 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -/* Mac-specific local file url parsing */ #include "nsIOService.h" #include "nsEscape.h" #include "nsPrintfCString.h" -static void SwapSlashColon(char *s) +static void SwapSlashColon(char * s) { - while (*s) { + while (*s){ if (*s == '/') *s++ = ':'; else if (*s == ':') @@ -54,7 +51,7 @@ static void SwapSlashColon(char *s) } } -static void PascalStringCopy(Str255 dst, const char *src) +static void PascalStringCopy(Str255 dst, const char* src) { int srcLength = strlen(src); NS_ASSERTION(srcLength <= 255, "Oops, Str255 can't hold >255 chars"); @@ -65,98 +62,102 @@ static void PascalStringCopy(Str255 dst, const char *src) } -NS_IMETHODIMP -nsIOService::GetURLSpecFromFile(nsIFile *aFile, char **aURL) +NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL) { - NS_ENSURE_ARG_POINTER(aURL); - *aURL = nsnull; + NS_ENSURE_ARG_POINTER(aURL); + *aURL = nsnull; - nsresult rv; - nsXPIDLCString ePath; - - rv = aFile->GetPath(getter_Copies(ePath)); - if (NS_FAILED(rv)) return rv; + nsresult rv; + char* ePath = nsnull; + nsCAutoString escPath; - SwapSlashColon((char *) ePath.get()); - - nsCAutoString escPath; - NS_NAMED_LITERAL_CSTRING(prefix, "file://"); - - // Escape the path with the directory mask - if (NS_EscapeURLPart(ePath.get(), ePath.Length(), esc_Directory+esc_Forced, escPath)) - escPath.Insert(prefix, 0); - else - escPath.Assign(prefix + ePath); - - // XXX this should be unnecessary - if (escPath[escPath.Length() - 1] != '/') { - PRBool dir; - rv = aFile->IsDirectory(&dir); - if (NS_FAILED(rv)) - NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get()); - else if (dir) { - // make sure we have a trailing slash - escPath += "/"; - } - } - - *aURL = ToNewCString(escPath); - return *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -} - -NS_IMETHODIMP -nsIOService::InitFileFromURLSpec(nsIFile *aFile, const char *aURL) -{ - NS_ENSURE_ARG(aURL); - nsresult rv; - - nsXPIDLCString host, directory, fileBaseName, fileExtension; - - nsCOMPtr localFile = do_QueryInterface(aFile, &rv); - if (NS_FAILED(rv)) { - NS_ERROR("Only nsILocalFile supported right now"); - return rv; - } - - rv = ParseFileURL(aURL, getter_Copies(host), - getter_Copies(directory), - getter_Copies(fileBaseName), - getter_Copies(fileExtension)); - if (NS_FAILED(rv)) return rv; - - nsCAutoString path; + rv = aFile->GetPath(&ePath); + if (NS_SUCCEEDED(rv)) { - if (host) { - // We can end up with a host when given: file:// instead of file:/// - // Check to see if the host is a volume name - If so prepend it - Str255 volName; - FSSpec volSpec; + SwapSlashColon(ePath); - PascalStringCopy(volName, host); - volName[++volName[0]] = ':'; - if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr) - path += host; - } - if (directory) { - if (!NS_EscapeURLPart(directory.get(), directory.Length(), esc_Directory, path)) - path += directory; - SwapSlashColon((char *) path.get()); - } - if (fileBaseName) { - if (!NS_EscapeURLPart(fileBaseName.get(), fileBaseName.Length(), esc_FileBaseName, path)) - path += fileBaseName; - } - if (fileExtension) { - path += '.'; - if (!NS_EscapeURLPart(fileExtension.get(), fileExtension.Length(), esc_FileExtension, path)) - path += fileExtension; - } - - NS_UnescapeURL((char *) path.get()); + // Escape the path with the directory mask + rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath); + if (NS_SUCCEEDED(rv)) { + + if (escPath[escPath.Length() - 1] != '/') { - // wack off leading :'s - if (path.CharAt(0) == ':') - path.Cut(0, 1); - - return localFile->InitWithPath(path.get()); + PRBool dir; + rv = aFile->IsDirectory(&dir); + + if (NS_FAILED(rv)) + NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get()); + + if (NS_SUCCEEDED(rv) && dir) + // make sure we have a trailing slash + escPath += "/"; + } + + escPath.Insert("file:///", 0); + *aURL = ToNewCString(escPath); + rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + } + } + CRTFREEIF(ePath); + return rv; +} + +NS_IMETHODIMP nsIOService::InitFileFromURLSpec(nsIFile* aFile, const char * aURL) +{ + NS_ENSURE_ARG(aURL); + nsresult rv; + + nsXPIDLCString host, directory, fileBaseName, fileExtension; + + nsCOMPtr localFile = do_QueryInterface(aFile, &rv); + NS_ASSERTION(NS_SUCCEEDED(rv), "Only nsILocalFile supported right now"); + if (NS_FAILED(rv)) return rv; + + rv = ParseFileURL(aURL, getter_Copies(host), getter_Copies(directory), + getter_Copies(fileBaseName), getter_Copies(fileExtension)); + if (NS_FAILED(rv)) return rv; + + nsCAutoString path; + nsCAutoString component; + + if (host) + { + // We can end up with a host when given: file:// instead of file:/// + // Check to see if the host is a volume name - If so prepend it + Str255 volName; + FSSpec volSpec; + + PascalStringCopy(volName, host); + volName[++volName[0]] = ':'; + if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr) + path += host; + } + if (directory) + { + nsStdEscape(directory, esc_Directory, component); + path += component; + SwapSlashColon((char*)path.get()); + } + if (fileBaseName) + { + nsStdEscape(fileBaseName, esc_FileBaseName, component); + path += component; + } + if (fileExtension) + { + nsStdEscape(fileExtension, esc_FileExtension, component); + path += '.'; + path += component; + } + + nsUnescape((char*)path.get()); + + // wack off leading :'s + if (path.CharAt(0) == ':') + path.Cut(0, 1); + + rv = localFile->InitWithPath(path.get()); + + return rv; + }