diff --git a/config/rules.mak b/config/rules.mak index b2f4909391bb..aea7fead53c8 100644 --- a/config/rules.mak +++ b/config/rules.mak @@ -854,6 +854,3 @@ $(CHROME_L10N:.\=CLOBBER\.\): !endif # CONFIG_RULES_MAK -# Easier than typing it by hand, works from any directory: -debug:: - start msdev $(DIST)\bin\mozilla.exe diff --git a/content/html/style/src/nsCSSLoader.cpp b/content/html/style/src/nsCSSLoader.cpp index 60ae879146fc..68dd1d5de004 100644 --- a/content/html/style/src/nsCSSLoader.cpp +++ b/content/html/style/src/nsCSSLoader.cpp @@ -66,7 +66,7 @@ public: NS_ADDREF(mURL); mHashValue = 0; - char* urlStr = nsnull; + char* urlStr; mURL->GetSpec(&urlStr); if (urlStr) { mHashValue = nsCRT::HashValue(urlStr); diff --git a/layout/html/style/src/nsCSSLoader.cpp b/layout/html/style/src/nsCSSLoader.cpp index 60ae879146fc..68dd1d5de004 100644 --- a/layout/html/style/src/nsCSSLoader.cpp +++ b/layout/html/style/src/nsCSSLoader.cpp @@ -66,7 +66,7 @@ public: NS_ADDREF(mURL); mHashValue = 0; - char* urlStr = nsnull; + char* urlStr; mURL->GetSpec(&urlStr); if (urlStr) { mHashValue = nsCRT::HashValue(urlStr); diff --git a/layout/style/nsCSSLoader.cpp b/layout/style/nsCSSLoader.cpp index 60ae879146fc..68dd1d5de004 100644 --- a/layout/style/nsCSSLoader.cpp +++ b/layout/style/nsCSSLoader.cpp @@ -66,7 +66,7 @@ public: NS_ADDREF(mURL); mHashValue = 0; - char* urlStr = nsnull; + char* urlStr; mURL->GetSpec(&urlStr); if (urlStr) { mHashValue = nsCRT::HashValue(urlStr); diff --git a/mailnews/base/util/nsMsgMailNewsUrl.cpp b/mailnews/base/util/nsMsgMailNewsUrl.cpp index 77ec4bf684a2..4fb907eb642e 100644 --- a/mailnews/base/util/nsMsgMailNewsUrl.cpp +++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp @@ -309,6 +309,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetScheme(const char * aScheme) return m_baseURL->SetScheme(aScheme); } + NS_IMETHODIMP nsMsgMailNewsUrl::GetPreHost(char * *aPreHost) { return m_baseURL->GetPreHost(aPreHost); @@ -319,26 +320,6 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetPreHost(const char * aPreHost) return m_baseURL->SetPreHost(aPreHost); } -NS_IMETHODIMP nsMsgMailNewsUrl::GetUsername(char * *aUsername) -{ - return m_baseURL->GetUsername(aUsername); -} - -NS_IMETHODIMP nsMsgMailNewsUrl::SetUsername(const char * aUsername) -{ - return m_baseURL->SetUsername(aUsername); -} - -NS_IMETHODIMP nsMsgMailNewsUrl::GetPassword(char * *aPassword) -{ - return m_baseURL->GetPassword(aPassword); -} - -NS_IMETHODIMP nsMsgMailNewsUrl::SetPassword(const char * aPassword) -{ - return m_baseURL->SetPassword(aPassword); -} - NS_IMETHODIMP nsMsgMailNewsUrl::GetHost(char * *aHost) { return m_baseURL->GetHost(aHost); @@ -369,21 +350,12 @@ NS_IMETHODIMP nsMsgMailNewsUrl::SetPath(const char * aPath) return m_baseURL->SetPath(aPath); } -NS_IMETHODIMP nsMsgMailNewsUrl::GetURLParser(nsIURLParser * *aURLParser) -{ - return m_baseURL->GetURLParser(aURLParser); -} - -NS_IMETHODIMP nsMsgMailNewsUrl::SetURLParser(nsIURLParser* aURLParser) -{ - return m_baseURL->SetURLParser(aURLParser); -} - NS_IMETHODIMP nsMsgMailNewsUrl::Equals(nsIURI *other, PRBool *_retval) { return m_baseURL->Equals(other, _retval); } + NS_IMETHODIMP nsMsgMailNewsUrl::Clone(nsIURI **_retval) { return m_baseURL->Clone(_retval); @@ -417,22 +389,22 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetFileName(char * *aFileName) NS_IMETHODIMP nsMsgMailNewsUrl::GetFileBaseName(char * *aFileBaseName) { - return m_baseURL->GetFileBaseName(aFileBaseName); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsMsgMailNewsUrl::SetFileBaseName(const char * aFileBaseName) { - return m_baseURL->SetFileBaseName(aFileBaseName); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsMsgMailNewsUrl::GetFileExtension(char * *aFileExtension) { - return m_baseURL->GetFileExtension(aFileExtension); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsMsgMailNewsUrl::SetFileExtension(const char * aFileExtension) { - return m_baseURL->SetFileExtension(aFileExtension); + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsMsgMailNewsUrl::SetFileName(const char * aFileName) diff --git a/mailnews/compose/src/nsSmtpUrl.cpp b/mailnews/compose/src/nsSmtpUrl.cpp index 37d0e9857d46..126e3c56ffa2 100644 --- a/mailnews/compose/src/nsSmtpUrl.cpp +++ b/mailnews/compose/src/nsSmtpUrl.cpp @@ -318,26 +318,6 @@ NS_IMETHODIMP nsMailtoUrl::SetPreHost(const char * aPreHost) return m_baseURL->SetPreHost(aPreHost); } -NS_IMETHODIMP nsMailtoUrl::GetUsername(char * *aUsername) -{ - return m_baseURL->GetUsername(aUsername); -} - -NS_IMETHODIMP nsMailtoUrl::SetUsername(const char * aUsername) -{ - return m_baseURL->SetUsername(aUsername); -} - -NS_IMETHODIMP nsMailtoUrl::GetPassword(char * *aPassword) -{ - return m_baseURL->GetPassword(aPassword); -} - -NS_IMETHODIMP nsMailtoUrl::SetPassword(const char * aPassword) -{ - return m_baseURL->SetPassword(aPassword); -} - NS_IMETHODIMP nsMailtoUrl::GetHost(char * *aHost) { return m_baseURL->GetHost(aHost); @@ -368,16 +348,6 @@ NS_IMETHODIMP nsMailtoUrl::SetPath(const char * aPath) return m_baseURL->SetPath(aPath); } -NS_IMETHODIMP nsMailtoUrl::GetURLParser(nsIURLParser * *aURLParser) -{ - return m_baseURL->GetURLParser(aURLParser); -} - -NS_IMETHODIMP nsMailtoUrl::SetURLParser(nsIURLParser * aURLParser) -{ - return m_baseURL->SetURLParser(aURLParser); -} - NS_IMETHODIMP nsMailtoUrl::Equals(nsIURI *other, PRBool *_retval) { return m_baseURL->Equals(other, _retval); diff --git a/modules/libjar/nsJARURI.cpp b/modules/libjar/nsJARURI.cpp index 77e8a5ad7b12..74804bb673c6 100644 --- a/modules/libjar/nsJARURI.cpp +++ b/modules/libjar/nsJARURI.cpp @@ -157,30 +157,6 @@ nsJARURI::SetPreHost(const char * aPreHost) return NS_ERROR_FAILURE; } -NS_IMETHODIMP -nsJARURI::GetUsername(char * *aUsername) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::SetUsername(const char * aUsername) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::GetPassword(char * *aPassword) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::SetPassword(const char * aPassword) -{ - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsJARURI::GetHost(char * *aHost) { @@ -217,18 +193,6 @@ nsJARURI::SetPath(const char * aPath) return NS_ERROR_FAILURE; } -NS_IMETHODIMP -nsJARURI::GetURLParser(nsIURLParser * *aURLParser) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::SetURLParser(nsIURLParser * aURLParser) -{ - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsJARURI::Equals(nsIURI *other, PRBool *_retval) { diff --git a/netwerk/base/public/MANIFEST_IDL b/netwerk/base/public/MANIFEST_IDL index b1bc4aa47153..5783699d5d77 100644 --- a/netwerk/base/public/MANIFEST_IDL +++ b/netwerk/base/public/MANIFEST_IDL @@ -12,4 +12,3 @@ nsISocketTransportService.idl nsIFileTransportService.idl nsIFileSystem.idl nsIUnicharStreamLoader.idl -nsIURLParser.idl diff --git a/netwerk/base/public/Makefile.in b/netwerk/base/public/Makefile.in index bbefd8f16af2..b443e5cac72a 100644 --- a/netwerk/base/public/Makefile.in +++ b/netwerk/base/public/Makefile.in @@ -51,7 +51,6 @@ XPIDLSRCS = \ nsIUnicharStreamLoader.idl \ nsINetPrompt.idl \ nsISocketTransport.idl \ - nsIURLParser.idl \ $(NULL) EXPORTS = \ diff --git a/netwerk/base/public/makefile.win b/netwerk/base/public/makefile.win index 5e4b56500723..bc8505c0aebb 100644 --- a/netwerk/base/public/makefile.win +++ b/netwerk/base/public/makefile.win @@ -50,9 +50,8 @@ XPIDLSRCS = \ .\nsIStatusCodeEventSink.idl \ .\nsIFileSystem.idl \ .\nsIUnicharStreamLoader.idl \ - .\nsINetPrompt.idl \ - .\nsISocketTransport.idl \ - .\nsIURLParser.idl \ + .\nsINetPrompt.idl \ + .\nsISocketTransport.idl \ $(NULL) include <$(DEPTH)/config/rules.mak> diff --git a/netwerk/base/public/nsIIOService.idl b/netwerk/base/public/nsIIOService.idl index 99fb1557986c..fe100fd84ccb 100644 --- a/netwerk/base/public/nsIIOService.idl +++ b/netwerk/base/public/nsIIOService.idl @@ -39,20 +39,6 @@ interface nsILoadGroupObserver; [scriptable, uuid(1daf19f0-8ea7-11d3-93ad-00104ba0fd40)] interface nsIIOService : nsISupports { - /** - * constants for the Escape mask in the call to URLEscape - */ - const short url_Scheme = (1<<0); - const short url_Username = (1<<1); - const short url_Password = (1<<2); - const short url_Host = (1<<3); - const short url_Directory = (1<<4); - const short url_FileBaseName = (1<<5); - const short url_FileExtension = (1<<6); - const short url_Param = (1<<7); - const short url_Query = (1<<8); - const short url_Ref = (1<<9); - /** * Returns a protocol handler for a given URI scheme. */ @@ -174,18 +160,6 @@ interface nsIIOService : nsISupports * causing the dialer to come up). */ attribute boolean offline; - - /** - * escapes the string str with mask - */ - void URLEscape (in string str, - in short mask, - out string result); - /** - * unescapes str - */ - void URLUnescape(in string str, - out string result); }; %{C++ diff --git a/netwerk/base/public/nsIURI.idl b/netwerk/base/public/nsIURI.idl index 8d44bef0f88d..8efcef5ad380 100644 --- a/netwerk/base/public/nsIURI.idl +++ b/netwerk/base/public/nsIURI.idl @@ -21,7 +21,6 @@ */ #include "nsISupports.idl" -#include "nsIURLParser.idl" /** * URIs are essentially structured names for things -- anything. @@ -80,10 +79,6 @@ interface nsIURI : nsISupports */ attribute string preHost; - attribute string username; - - attribute string password; - /** * The Host is the internet domain name to which this URI refers. * Note that it could be an IP address as well. @@ -108,11 +103,6 @@ interface nsIURI : nsISupports */ attribute string path; - /** - * This is a handle to the Parser used to parse the URI - */ - attribute nsIURLParser URLParser; - /** * Note that this comparison is only on char* level. Use * the scheme specific URI to do a more thorough check. For example, @@ -147,7 +137,6 @@ interface nsIURI : nsISupports * This method subsumes the deprecated method nsIIOService::MakeAbsolute. */ string resolve(in string relativePath); - }; %{C++ diff --git a/netwerk/base/public/nsIURLParser.idl b/netwerk/base/public/nsIURLParser.idl deleted file mode 100644 index 39cfab3355c1..000000000000 --- a/netwerk/base/public/nsIURLParser.idl +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Andreas Otte - * - * Contributor(s): - */ - -#include "nsISupports.idl" - -/** - * nsIURLParser is the abstract base class for parsing URLs - */ - -[scriptable, uuid(4b4975f9-f128-47fd-b11e-88402233cbdf)] -interface nsIURLParser : nsISupports -{ - - /** - * Parses a URL and thinks it is parsing the scheme - */ - void ParseAtScheme(in string i_Spec, - out string o_Scheme, - out string o_Username, - out string o_Password, - out string o_Host, - out long o_Port, - out string o_Path); - - /** - * Parses a URL and thinks it is parsing the prehost - */ - void ParseAtPreHost(in string i_Spec, - out string o_Username, - out string o_Password, - out string o_Host, - out long o_Port, - out string o_Path); - - /** - * Parses a URL and thinks it is parsing the host - */ - void ParseAtHost(in string i_Spec, - out string o_Host, - out long o_Port, - out string o_Path); - - /** - * Parses a URL and thinks it is parsing the port - */ - void ParseAtPort(in string i_Spec, - out long o_Port, - out string o_Path); - - /** - * Parses a URL and thinks it is parsing the path - */ - void ParseAtPath(in string i_Spec, - out string o_Path); - - /** - * Parses a URL-path and thinks it is parsing the directory - */ - void ParseAtDirectory(in string i_Path, - out string o_Directory, - out string o_FileBaseName, - out string o_FileExtension, - out string o_Param, - out string o_Query, - out string o_Ref); - - /** - * Parses the URL-PreHost into its components - */ - void ParsePreHost(in string i_PreHost, - out string o_Username, - out string o_Password); - - /** - * Parses the URL-Filename into its components - */ - void ParseFileName(in string i_FileName, - out string o_FileBaseName, - out string o_FileExtension); - -}; - -%{C++ - -#define NS_NOAUTHORITYURLPARSER_CID \ -{ /* 9eeb1b89-c87e-4404-9de6-dbd41aeaf3d7 */ \ - 0x9eeb1b89, \ - 0xc87e, \ - 0x4404, \ - {0x9d, 0xe6, 0xdb, 0xd4, 0x1a, 0xea, 0xf3, 0xd7} \ -} - -#define NS_AUTHORITYURLPARSER_CID \ -{ /* 90012125-1616-4fa1-ae14-4e7fa5766eb6 */ \ - 0x90012125, \ - 0x1616, \ - 0x4fa1, \ - {0xae, 0x14, 0x4e, 0x7f, 0xa5, 0x76, 0x6e, 0xb6} \ -} - -%} diff --git a/netwerk/base/src/Makefile.in b/netwerk/base/src/Makefile.in index 5f7ebd2f820f..0b295bfdcc00 100644 --- a/netwerk/base/src/Makefile.in +++ b/netwerk/base/src/Makefile.in @@ -29,16 +29,7 @@ include $(DEPTH)/config/autoconf.mk MODULE = necko LIBRARY_NAME = neckobase_s -EXPORTS = \ - nsAuthURLParser.h \ - nsNoAuthURLParser.h \ - $(NULL) - CPPSRCS = \ - nsURLHelper.cpp \ - nsStdURLParser.cpp \ - nsAuthURLParser.cpp \ - nsNoAuthURLParser.cpp \ nsAsyncStreamListener.cpp \ nsSyncStreamListener.cpp \ nsIOService.cpp \ @@ -62,3 +53,4 @@ override NO_SHARED_LIB=1 override NO_STATIC_LIB= include $(topsrcdir)/config/rules.mk + diff --git a/netwerk/base/src/makefile.win b/netwerk/base/src/makefile.win index bf58a5c757f3..0a4d65763ea3 100644 --- a/netwerk/base/src/makefile.win +++ b/netwerk/base/src/makefile.win @@ -27,10 +27,6 @@ LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET LIBRARY_NAME=neckobase_s CPP_OBJS = \ - .\$(OBJDIR)\nsURLHelper.obj \ - .\$(OBJDIR)\nsStdURLParser.obj \ - .\$(OBJDIR)\nsAuthURLParser.obj \ - .\$(OBJDIR)\nsNoAuthURLParser.obj \ .\$(OBJDIR)\nsAsyncStreamListener.obj \ .\$(OBJDIR)\nsSyncStreamListener.obj \ .\$(OBJDIR)\nsIOService.obj \ @@ -48,11 +44,6 @@ CPP_OBJS = \ .\$(OBJDIR)\nsUnicharStreamLoader.obj \ $(NULL) -EXPORTS = \ - nsAuthURLParser.h \ - nsNoAuthURLParser.h \ - $(NULL) - INCS = $(INCS) \ -I$(DEPTH)\dist\include \ $(NULL) diff --git a/netwerk/base/src/nsAuthURLParser.cpp b/netwerk/base/src/nsAuthURLParser.cpp deleted file mode 100644 index 05631ab3c423..000000000000 --- a/netwerk/base/src/nsAuthURLParser.cpp +++ /dev/null @@ -1,436 +0,0 @@ -/* -*- 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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Andreas Otte. - * - * Contributor(s): - */ - -#include "nsAuthURLParser.h" -#include "nsURLHelper.h" -#include "nsCRT.h" -#include "nsString.h" -#include "prprf.h" - -NS_IMPL_ISUPPORTS1(nsAuthURLParser, - nsIURLParser) - -nsAuthURLParser::~nsAuthURLParser() -{ -} - - -NS_METHOD -nsAuthURLParser::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - if (aOuter) - return NS_ERROR_NO_AGGREGATION; - nsAuthURLParser* p = new nsAuthURLParser(); - if (p == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(p); - nsresult rv = p->QueryInterface(aIID, aResult); - NS_RELEASE(p); - return rv; -} - -nsresult -nsAuthURLParser::ParseAtScheme(const char* i_Spec, char* *o_Scheme, - char* *o_Username, char* *o_Password, - char* *o_Host, PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - - NS_PRECONDITION( (nsnull != i_Spec), "Parse called on empty url!"); - if (!i_Spec) - return NS_ERROR_MALFORMED_URI; - - int len = PL_strlen(i_Spec); - if (len >= 2 && *i_Spec == '/' && *(i_Spec+1) == '/') // No Scheme - { - rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host, o_Port, - o_Path); - return rv; - } - - static const char delimiters[] = "/:@?"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - - if (!brk) // everything is a host - { - rv = ExtractString((char*)i_Spec, o_Host, len); - return rv; - } else - len = PL_strlen(brk); - - switch (*brk) - { - case '/' : - case '?' : - // If the URL starts with a slash then everything is a path - if (brk == i_Spec) - { - rv = ParseAtPath(brk, o_Path); - return rv; - } - else // The first part is host, so its host/path - { - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPath(brk, o_Path); - return rv; - } - break; - case ':' : - if (len >= 2 && *(brk+1) == '/') { - // Standard http://... or malformed http:/... - rv = ExtractString((char*)i_Spec, o_Scheme, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host, - o_Port, o_Path); - return rv; - } else { - // Could be host:port, so try conversion to number - PRInt32 port = ExtractPortFrom(brk+1); - if (port > 0) - { - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPort(brk+1, o_Port, o_Path); - return rv; - } else { - // No, it's not a number try scheme:host... - rv = ExtractString((char*)i_Spec, o_Scheme, - (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host, - o_Port, o_Path); - return rv; - } - } - break; - case '@' : - rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host, - o_Port, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsAuthURLParser::ParseAtPreHost(const char* i_Spec, char* *o_Username, - char* *o_Password, char* *o_Host, - PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - // Skip leading two slashes - char* fwdPtr= (char*) i_Spec; - if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/')) - fwdPtr++; - if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/')) - fwdPtr++; - - // Search for @ - static const char delimiters[] = "@"; - char* brk = PL_strpbrk(fwdPtr, delimiters); - - if (brk) - { - char* e_PreHost = nsnull; - rv = ExtractString(fwdPtr, &e_PreHost, (brk - fwdPtr)); - if (NS_FAILED(rv)) { - CRTFREEIF(e_PreHost); - return rv; - } - rv = ParsePreHost(e_PreHost,o_Username,o_Password); - CRTFREEIF(e_PreHost); - if (NS_FAILED(rv)) - return rv; - - rv = ParseAtHost(brk+1, o_Host, o_Port, o_Path); - } else { - rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path); - } - return rv; -} - -nsresult -nsAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host, - PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - - int len = PL_strlen(i_Spec); - static const char delimiters[] = ":/?"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - if (!brk) // everything is a host - { - rv = ExtractString((char*)i_Spec, o_Host, len); - return rv; - } - - switch (*brk) - { - case '/' : - case '?' : - // Get the Host, the rest is Path - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPath(brk, o_Path); - return rv; - break; - case ':' : - // Get the Host - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPort(brk+1, o_Port, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsAuthURLParser::ParseAtPort(const char* i_Spec, PRInt32 *o_Port, - char* *o_Path) -{ - nsresult rv = NS_OK; - static const char delimiters[] = "/?"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - if (!brk) // everything is a Port - { - *o_Port = ExtractPortFrom(i_Spec); - if (*o_Port <= 0) - return NS_ERROR_MALFORMED_URI; - else - return NS_OK; - } - - switch (*brk) - { - case '/' : - case '?' : - // Get the Port, the rest is Path - *o_Port = ExtractPortFrom(i_Spec); - if (*o_Port <= 0) - return NS_ERROR_MALFORMED_URI; - rv = ParseAtPath(brk, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsAuthURLParser::ParseAtPath(const char* i_Spec, char* *o_Path) -{ - // Just write the path and check for a starting / - nsAutoString dir; - if ('/' != *i_Spec) - dir += "/"; - - dir += i_Spec; - - *o_Path = dir.ToNewCString(); - return (*o_Path ? NS_OK : NS_ERROR_OUT_OF_MEMORY); -} - -nsresult -nsAuthURLParser::ParseAtDirectory(const char* i_Path, char* *o_Directory, - char* *o_FileBaseName, char* *o_FileExtension, - char* *o_Param, char* *o_Query, char* *o_Ref) -{ - // Cleanout - CRTFREEIF(*o_Directory); - CRTFREEIF(*o_FileBaseName); - CRTFREEIF(*o_FileExtension); - CRTFREEIF(*o_Param); - CRTFREEIF(*o_Query); - CRTFREEIF(*o_Ref); - - nsresult rv = NS_OK; - - // Parse the Path into its components - if (!i_Path) - { - DupString(o_Directory, "/"); - return (o_Directory ? NS_OK : NS_ERROR_OUT_OF_MEMORY); - } - - char* dirfile = nsnull; - char* options = nsnull; - - int len = PL_strlen(i_Path); - - /* Factor out the optionpart with ;?# */ - static const char delimiters[] = ";?#"; // for param, query and ref - char* brk = PL_strpbrk(i_Path, delimiters); - - if (!brk) // Everything is just path and filename - { - DupString(&dirfile, i_Path); - } - else - { - int dirfileLen = brk - i_Path; - ExtractString((char*)i_Path, &dirfile, dirfileLen); - len -= dirfileLen; - ExtractString((char*)i_Path + dirfileLen, &options, len); - brk = options; - } - - /* now that we have broken up the path treat every part differently */ - /* first dir+file */ - - char* file; - - int dlen = PL_strlen(dirfile); - if (dlen == 0) - { - DupString(o_Directory, "/"); - file = dirfile; - } else { - CoaleseDirs(dirfile); - // Get length again - dlen = PL_strlen(dirfile); - - // First find the last slash - file = PL_strrchr(dirfile, '/'); - if (!file) - { - DupString(o_Directory, "/"); - file = dirfile; - } - - // If its not the same as the first slash then extract directory - if (file != dirfile) - { - ExtractString(dirfile, o_Directory, (file - dirfile)+1); - } else { - DupString(o_Directory, "/"); - } - } - - /* Extract FileBaseName and FileExtension */ - if (dlen > 0) { - // Look again if there was a slash - char* slash = PL_strrchr(dirfile, '/'); - char* e_FileName = nsnull; - if (slash) { - ExtractString(file+1, &e_FileName, dlen-(slash-dirfile+1)); - } else { - // Use the full String as Filename - ExtractString(dirfile, &e_FileName, dlen); - } - - rv = ParseFileName(e_FileName,o_FileBaseName,o_FileExtension); - - CRTFREEIF(e_FileName); - } - - // Now take a look at the options. "#" has precedence over "?" - // which has precedence over ";" - if (options) { - // Look for "#" first. Everything following it is in the ref - brk = PL_strchr(options, '#'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Ref, pieceLen); - len -= pieceLen + 1; - *brk = '\0'; - } - - // Now look for "?" - brk = PL_strchr(options, '?'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Query, pieceLen); - len -= pieceLen + 1; - } - - // Now look for ';' - brk = PL_strchr(options, ';'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Param, pieceLen); - len -= pieceLen + 1; - *brk = '\0'; - } - } - - nsCRT::free(dirfile); - nsCRT::free(options); - return rv; -} - -nsresult -nsAuthURLParser::ParsePreHost(const char* i_PreHost, char* *o_Username, - char* *o_Password) -{ - nsresult rv = NS_OK; - // Search for : - static const char delimiters[] = ":"; - char* brk = PL_strpbrk(i_PreHost, delimiters); - if (brk) - { - rv = ExtractString((char*)i_PreHost, o_Username, (brk - i_PreHost)); - if (NS_FAILED(rv)) - return rv; - rv = ExtractString(brk+1, o_Password, - (i_PreHost+PL_strlen(i_PreHost) - brk - 1)); - } else { - CRTFREEIF(*o_Password); - rv = DupString(o_Username, i_PreHost); - } - return rv; -} - -nsresult -nsAuthURLParser::ParseFileName(const char* i_FileName, char* *o_FileBaseName, - char* *o_FileExtension) -{ - nsresult rv = NS_OK; - // Search for FileExtension - // Search for last . - // Ignore . at the beginning - char* brk = PL_strrchr(i_FileName+1, '.'); - if (brk) - { - rv = ExtractString((char*)i_FileName, o_FileBaseName, - (brk - i_FileName)); - if (NS_FAILED(rv)) - return rv; - rv = ExtractString(brk + 1, o_FileExtension, - (i_FileName+PL_strlen(i_FileName) - brk - 1)); - } else { - rv = DupString(o_FileBaseName, i_FileName); - } - return rv; -} diff --git a/netwerk/base/src/nsAuthURLParser.h b/netwerk/base/src/nsAuthURLParser.h deleted file mode 100644 index b1048742a47b..000000000000 --- a/netwerk/base/src/nsAuthURLParser.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsAuthURLParser_h__ -#define nsAuthURLParser_h__ - -#include "nsIURLParser.h" -#include "nsIURI.h" -#include "nsAgg.h" -#include "nsCRT.h" - -class nsAuthURLParser : public nsIURLParser -{ -public: - NS_DECL_ISUPPORTS - /////////////////////////////////////////////////////////////////////////// - // nsAuthURLParser methods: - nsAuthURLParser() { - NS_INIT_REFCNT(); - } - virtual ~nsAuthURLParser(); - - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - - /////////////////////////////////////////////////////////////////////////// - // nsIURLParser methods: - NS_DECL_NSIURLPARSER - -}; - -#endif // nsAuthURLParser_h__ diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index 3f927c08e7bb..0cc5437e6b95 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -411,16 +411,4 @@ nsIOService::SetOffline(PRBool offline) return NS_OK; } -NS_IMETHODIMP -nsIOService::URLEscape(const char* str, PRInt16 mask, char **result) -{ - return nsURLEscape((char*)str,mask,result); -} - -NS_IMETHODIMP -nsIOService::URLUnescape(const char* str, char **result) -{ - return nsURLUnescape((char*)str,result); -} - //////////////////////////////////////////////////////////////////////////////// diff --git a/netwerk/base/src/nsIOService.h b/netwerk/base/src/nsIOService.h index a6742fc7797c..cd4a1585fbf2 100644 --- a/netwerk/base/src/nsIOService.h +++ b/netwerk/base/src/nsIOService.h @@ -25,7 +25,6 @@ #include "nsIIOService.h" #include "nsString2.h" -#include "nsURLHelper.h" class nsIOService : public nsIIOService { diff --git a/netwerk/base/src/nsNoAuthURLParser.cpp b/netwerk/base/src/nsNoAuthURLParser.cpp deleted file mode 100644 index 93e57cbadb78..000000000000 --- a/netwerk/base/src/nsNoAuthURLParser.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* -*- 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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Andreas Otte. - * - * Contributor(s): - */ - -#include "nsNoAuthURLParser.h" -#include "nsURLHelper.h" -#include "nsCRT.h" -#include "nsString.h" -#include "prprf.h" - -NS_IMPL_ISUPPORTS1(nsNoAuthURLParser, - nsIURLParser) - -nsNoAuthURLParser::~nsNoAuthURLParser() -{ -} - - -NS_METHOD -nsNoAuthURLParser::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - if (aOuter) - return NS_ERROR_NO_AGGREGATION; - nsNoAuthURLParser* p = new nsNoAuthURLParser(); - if (p == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(p); - nsresult rv = p->QueryInterface(aIID, aResult); - NS_RELEASE(p); - return rv; -} - -nsresult -nsNoAuthURLParser::ParseAtScheme(const char* i_Spec, char* *o_Scheme, - char* *o_Username, char* *o_Password, - char* *o_Host, PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - - NS_PRECONDITION( (nsnull != i_Spec), "Parse called on empty url!"); - if (!i_Spec) - return NS_ERROR_MALFORMED_URI; - - int len = PL_strlen(i_Spec); - if (len >= 2 && *i_Spec == '/' && *(i_Spec+1) == '/') // No Scheme - { - rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host, o_Port, - o_Path); - return rv; - } - - static const char delimiters[] = ":"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - - if (!brk) // everything is a path - { - rv = ParseAtPath((char*)i_Spec, o_Path); - return rv; - } - - switch (*brk) - { - case ':' : - rv = ExtractString((char*)i_Spec, o_Scheme, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host, - o_Port, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsNoAuthURLParser::ParseAtPreHost(const char* i_Spec, char* *o_Username, - char* *o_Password, char* *o_Host, - PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - // Skip leading two slashes - char* fwdPtr= (char*) i_Spec; - if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/')) - fwdPtr++; - if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/')) - fwdPtr++; - - // There is no PreHost - rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path); - return rv; - -} - -nsresult -nsNoAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host, - PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - // There is no Host - rv = ParseAtPath(i_Spec, o_Path); - return rv; -} - -nsresult -nsNoAuthURLParser::ParseAtPort(const char* i_Spec, PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - // There is no Port - rv = ParseAtPath(i_Spec, o_Path); - return NS_OK; -} - -nsresult -nsNoAuthURLParser::ParseAtPath(const char* i_Spec, char* *o_Path) -{ - // Just write the path and check for a starting / - nsAutoString dir; - if ('/' != *i_Spec) - dir += "/"; - - dir += i_Spec; - - *o_Path = dir.ToNewCString(); - return (*o_Path ? NS_OK : NS_ERROR_OUT_OF_MEMORY); -} - -nsresult -nsNoAuthURLParser::ParseAtDirectory(const char* i_Path, char* *o_Directory, - char* *o_FileBaseName, char* *o_FileExtension, - char* *o_Param, char* *o_Query, char* *o_Ref) -{ - // Cleanout - CRTFREEIF(*o_Directory); - CRTFREEIF(*o_FileBaseName); - CRTFREEIF(*o_FileExtension); - CRTFREEIF(*o_Param); - CRTFREEIF(*o_Query); - CRTFREEIF(*o_Ref); - - nsresult rv = NS_OK; - - // Parse the Path into its components - if (!i_Path) - { - DupString(o_Directory, "/"); - return (o_Directory ? NS_OK : NS_ERROR_OUT_OF_MEMORY); - } - - char* dirfile = nsnull; - char* options = nsnull; - - int len = PL_strlen(i_Path); - - /* Factor out the optionpart with ;?# */ - static const char delimiters[] = ";?#"; // for param, query and ref - char* brk = PL_strpbrk(i_Path, delimiters); - - if (!brk) // Everything is just path and filename - { - DupString(&dirfile, i_Path); - } - else - { - int dirfileLen = brk - i_Path; - ExtractString((char*)i_Path, &dirfile, dirfileLen); - len -= dirfileLen; - ExtractString((char*)i_Path + dirfileLen, &options, len); - brk = options; - } - - /* now that we have broken up the path treat every part differently */ - /* first dir+file */ - - char* file; - - int dlen = PL_strlen(dirfile); - if (dlen == 0) - { - DupString(o_Directory, "/"); - file = dirfile; - } else { - CoaleseDirs(dirfile); - // Get length again - dlen = PL_strlen(dirfile); - - // First find the last slash - file = PL_strrchr(dirfile, '/'); - if (!file) - { - DupString(o_Directory, "/"); - file = dirfile; - } - - // If its not the same as the first slash then extract directory - if (file != dirfile) - { - ExtractString(dirfile, o_Directory, (file - dirfile)+1); - } else { - DupString(o_Directory, "/"); - } - } - - /* Extract FileBaseName and FileExtension */ - if (dlen > 0) { - // Look again if there was a slash - char* slash = PL_strrchr(dirfile, '/'); - char* e_FileName = nsnull; - if (slash) { - ExtractString(file+1, &e_FileName, dlen-(slash-dirfile+1)); - } else { - // Use the full String as Filename - ExtractString(dirfile, &e_FileName, dlen); - } - - rv = ParseFileName(e_FileName,o_FileBaseName,o_FileExtension); - CRTFREEIF(e_FileName); - } - - // Now take a look at the options. "#" has precedence over "?" - // which has precedence over ";" - if (options) { - // Look for "#" first. Everything following it is in the ref - brk = PL_strchr(options, '#'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Ref, pieceLen); - len -= pieceLen + 1; - *brk = '\0'; - } - - // Now look for "?" - brk = PL_strchr(options, '?'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Query, pieceLen); - len -= pieceLen + 1; - } - - // Now look for ';' - brk = PL_strchr(options, ';'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Param, pieceLen); - len -= pieceLen + 1; - *brk = '\0'; - } - } - - nsCRT::free(dirfile); - nsCRT::free(options); - return rv; -} - -nsresult -nsNoAuthURLParser::ParsePreHost(const char* i_PreHost, char* *o_Username, - char* *o_Password) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult -nsNoAuthURLParser::ParseFileName(const char* i_FileName, - char* *o_FileBaseName, - char* *o_FileExtension) -{ - nsresult rv = NS_OK; - // Search for FileExtension - // Search for last . - // Ignore . at the beginning - char* brk = PL_strrchr(i_FileName+1, '.'); - if (brk) - { - rv = ExtractString((char*)i_FileName, o_FileBaseName, - (brk - i_FileName)); - if (NS_FAILED(rv)) - return rv; - rv = ExtractString(brk + 1, o_FileExtension, - (i_FileName+PL_strlen(i_FileName) - brk - 1)); - } else { - rv = DupString(o_FileBaseName, i_FileName); - } - return rv; -} diff --git a/netwerk/base/src/nsNoAuthURLParser.h b/netwerk/base/src/nsNoAuthURLParser.h deleted file mode 100644 index 325cb620447a..000000000000 --- a/netwerk/base/src/nsNoAuthURLParser.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsNoAuthURLParser_h__ -#define nsNoAuthURLParser_h__ - -#include "nsIURLParser.h" -#include "nsIURI.h" -#include "nsAgg.h" -#include "nsCRT.h" - -class nsNoAuthURLParser : public nsIURLParser -{ -public: - NS_DECL_ISUPPORTS - /////////////////////////////////////////////////////////////////////////// - // nsNoAuthURLParser methods: - nsNoAuthURLParser() { - NS_INIT_REFCNT(); - } - virtual ~nsNoAuthURLParser(); - - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - - /////////////////////////////////////////////////////////////////////////// - // nsIURLParser methods: - NS_DECL_NSIURLPARSER - -}; - -#endif // nsNoAuthURLParser_h__ diff --git a/netwerk/base/src/nsSimpleURI.cpp b/netwerk/base/src/nsSimpleURI.cpp index d0022358662d..cb4b69b21de0 100644 --- a/netwerk/base/src/nsSimpleURI.cpp +++ b/netwerk/base/src/nsSimpleURI.cpp @@ -27,7 +27,6 @@ #include "nsString.h" #include "prmem.h" #include "prprf.h" -#include "nsURLHelper.h" static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); static NS_DEFINE_CID(kThisSimpleURIImplementationCID, @@ -143,30 +142,6 @@ nsSimpleURI::SetPreHost(const char* preHost) return NS_ERROR_FAILURE; } -NS_IMETHODIMP -nsSimpleURI::GetUsername(char* *result) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsSimpleURI::SetUsername(const char* userName) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsSimpleURI::GetPassword(char* *result) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsSimpleURI::SetPassword(const char* password) -{ - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsSimpleURI::GetHost(char* *result) { @@ -206,18 +181,6 @@ nsSimpleURI::SetPath(const char* path) return NS_OK; } -NS_IMETHODIMP -nsSimpleURI::GetURLParser(nsIURLParser* *result) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsSimpleURI::SetURLParser(nsIURLParser* URLParser) -{ - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsSimpleURI::Equals(nsIURI* other, PRBool *result) { @@ -266,7 +229,8 @@ nsSimpleURI::SetRelativePath(const char *i_RelativePath) NS_IMETHODIMP nsSimpleURI::Resolve(const char *relativePath, char **result) { - return DupString(result,(char*)relativePath); + NS_ASSERTION(PR_FALSE, "This is meaningless in hack context!"); + return NS_ERROR_NOT_IMPLEMENTED; } //////////////////////////////////////////////////////////////////////////////// diff --git a/netwerk/base/src/nsStdURL.cpp b/netwerk/base/src/nsStdURL.cpp index 620b3a246694..53a3ff5dcbf4 100644 --- a/netwerk/base/src/nsStdURL.cpp +++ b/netwerk/base/src/nsStdURL.cpp @@ -20,10 +20,7 @@ * Contributor(s): */ -#include "nsIIOService.h" -#include "nsURLHelper.h" #include "nsStdURL.h" -#include "nsStdURLParser.h" #include "nscore.h" #include "nsCRT.h" #include "nsString.h" @@ -31,115 +28,165 @@ #include "prprf.h" #include "nsXPIDLString.h" #include "nsCOMPtr.h" -#include "nsIServiceManager.h" static NS_DEFINE_CID(kStdURLCID, NS_STANDARDURL_CID); static NS_DEFINE_CID(kThisStdURLImplementationCID, NS_THIS_STANDARDURL_IMPLEMENTATION_CID); -static NS_DEFINE_CID(kStdURLParserCID, NS_STANDARDURLPARSER_CID); -nsStdURL::nsStdURL() - : mScheme(nsnull), - mUsername(nsnull), - mPassword(nsnull), - mHost(nsnull), - mPort(-1), - mDirectory(nsnull), - mFileBaseName(nsnull), - mFileExtension(nsnull), - mParam(nsnull), - mQuery(nsnull), - mRef(nsnull), - mURLParser(nsnull) +//---------------------------------------- + +// Helper function to extract the port # from a string +// PR_sscanf handles spaces and non-digits correctly +static PRInt32 ExtractPortFrom(char* src) { - NS_INIT_REFCNT(); - /* Create the standard URLParser */ - nsComponentManager::CreateInstance(kStdURLParserCID, - nsnull, NS_GET_IID(nsIURLParser), - (void**)&mURLParser); - + PRInt32 returnValue = -1; + return (0 < PR_sscanf(src, "%d", &returnValue)) ? returnValue : -1; } +// Replace all /./ with a / +// Also changes all \ to / +// But only till #?; +static void ReplaceMess(char* io_Path) +{ + /* Stolen from the old netlib's mkparse.c. + * + * modifies a url of the form /foo/../foo1 -> /foo1 + * and /foo/./foo1 -> /foo/foo1 + * and /foo/foo1/.. -> /foo/ + */ + char *fwdPtr = io_Path; + char *urlPtr = io_Path; + + for(; (*fwdPtr != '\0') && + (*fwdPtr != ';') && + (*fwdPtr != '?') && + (*fwdPtr != '#'); ++fwdPtr) + { + if (*fwdPtr == '\\') + *fwdPtr = '/'; + if (*fwdPtr == '/' && *(fwdPtr+1) == '.' && + (*(fwdPtr+2) == '/' || *(fwdPtr+2) == '\\')) + { + // remove . followed by slash or a backslash + fwdPtr += 1; + } + else if(*fwdPtr == '/' && *(fwdPtr+1) == '.' && *(fwdPtr+2) == '.' && + (*(fwdPtr+3) == '/' || + *(fwdPtr+3) == '\0' || + *(fwdPtr+3) == ';' || // This will take care of likes of + *(fwdPtr+3) == '?' || // foo/bar/..#sometag + *(fwdPtr+3) == '#' || + *(fwdPtr+3) == '\\')) + { + // remove foo/.. + // reverse the urlPtr to the previous slash + if(urlPtr != io_Path) + urlPtr--; // we must be going back at least by one + for(;*urlPtr != '/' && urlPtr != io_Path; urlPtr--) + ; // null body + + // forward the fwd_prt past the ../ + fwdPtr += 2; + // special case if we have reached the end to preserve the last / + if (*fwdPtr == '.' && *(fwdPtr+1) == '\0') + urlPtr +=1; + } + else + { + // copy the url incrementaly + *urlPtr++ = *fwdPtr; + } + } + // Copy remaining stuff past the #?; + for (; *fwdPtr != '\0'; ++fwdPtr) + { + *urlPtr++ = *fwdPtr; + } + *urlPtr = '\0'; // terminate the url + + /* + * Now lets remove trailing . case + * /foo/foo1/. -> /foo/foo1/ + */ + + if ((urlPtr > (io_Path+1)) && (*(urlPtr-1) == '.') && (*(urlPtr-2) == '/')) + *(urlPtr-1) = '\0'; +} + + + +//---------------------------------------- + +class nsParsePath +{ +public: + nsParsePath(nsStdURL* i_URL): mURL(i_URL) {} + virtual ~nsParsePath() {mURL->ParsePath();} +private: + nsStdURL* mURL; +}; + nsStdURL::nsStdURL(const char* i_Spec, nsISupports* outer) : mScheme(nsnull), - mUsername(nsnull), - mPassword(nsnull), + mPreHost(nsnull), mHost(nsnull), mPort(-1), + mPath(nsnull), mDirectory(nsnull), - mFileBaseName(nsnull), - mFileExtension(nsnull), + mFileName(nsnull), mParam(nsnull), mQuery(nsnull), - mRef(nsnull), - mURLParser(nsnull) + mRef(nsnull) { - NS_INIT_REFCNT(); - - // Skip leading spaces and control-characters + // Skip leading spaces char* fwdPtr= (char*) i_Spec; - while (fwdPtr && (*fwdPtr > '\0') && (*fwdPtr <= ' ')) + while (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == ' ')) fwdPtr++; - // Remove trailing spaces and control-characters + // Remove trailing spaces if (fwdPtr) { char* bckPtr= (char*)fwdPtr + PL_strlen(fwdPtr) -1; - if (*bckPtr > '\0' && *bckPtr <= ' ') { - while ((bckPtr-fwdPtr) >= 0 && (*bckPtr <= ' ')) { + if (*bckPtr == ' ') { + while ((bckPtr-fwdPtr) >= 0 && (*bckPtr == ' ')) { bckPtr--; } *(bckPtr+1) = '\0'; } } - - /* Create the standard URLParser */ - nsComponentManager::CreateInstance(kStdURLParserCID, - nsnull, NS_GET_IID(nsIURLParser), - (void**)&mURLParser); - + mSpec = fwdPtr ? nsCRT::strdup(fwdPtr) : nsnull; NS_INIT_AGGREGATED(outer); - if (fwdPtr && mURLParser) - Parse((char*)fwdPtr); + if (fwdPtr) + Parse(); } nsStdURL::nsStdURL(const nsStdURL& otherURL) : mPort(otherURL.mPort) { - NS_INIT_REFCNT(); - + mSpec = otherURL.mSpec ? nsCRT::strdup(otherURL.mSpec) : nsnull; mScheme = otherURL.mScheme ? nsCRT::strdup(otherURL.mScheme) : nsnull; - mUsername = otherURL.mUsername ? nsCRT::strdup(otherURL.mUsername) : nsnull; - mPassword = otherURL.mPassword ? nsCRT::strdup(otherURL.mPassword) : nsnull; + mPreHost = otherURL.mPreHost ? nsCRT::strdup(otherURL.mPreHost) : nsnull; mHost = otherURL.mHost ? nsCRT::strdup(otherURL.mHost) : nsnull; + mPath = otherURL.mPath ? nsCRT::strdup(otherURL.mPath) : nsnull; mDirectory = otherURL.mDirectory ? nsCRT::strdup(otherURL.mDirectory) : nsnull; - mFileBaseName = otherURL.mFileBaseName ? nsCRT::strdup(otherURL.mFileBaseName) : nsnull; - mFileExtension = otherURL.mFileExtension ? nsCRT::strdup(otherURL.mFileExtension) : nsnull; + mFileName = otherURL.mFileName ? nsCRT::strdup(otherURL.mFileName) : nsnull; mParam = otherURL.mParam ? nsCRT::strdup(otherURL.mParam) : nsnull; mQuery = otherURL.mQuery ? nsCRT::strdup(otherURL.mQuery) : nsnull; mRef= otherURL.mRef ? nsCRT::strdup(otherURL.mRef) : nsnull; - - NS_IF_ADDREF(otherURL.mURLParser); - mURLParser = otherURL.mURLParser; - NS_INIT_AGGREGATED(nsnull); // Todo! How? } nsStdURL& nsStdURL::operator=(const nsStdURL& otherURL) { + mSpec = otherURL.mSpec ? nsCRT::strdup(otherURL.mSpec) : nsnull; mScheme = otherURL.mScheme ? nsCRT::strdup(otherURL.mScheme) : nsnull; - mUsername = otherURL.mUsername ? nsCRT::strdup(otherURL.mUsername) : nsnull; - mPassword = otherURL.mPassword ? nsCRT::strdup(otherURL.mPassword) : nsnull; + mPreHost = otherURL.mPreHost ? nsCRT::strdup(otherURL.mPreHost) : nsnull; mHost = otherURL.mHost ? nsCRT::strdup(otherURL.mHost) : nsnull; + mPath = otherURL.mPath ? nsCRT::strdup(otherURL.mPath) : nsnull; mDirectory = otherURL.mDirectory ? nsCRT::strdup(otherURL.mDirectory) : nsnull; - mFileBaseName = otherURL.mFileBaseName ? nsCRT::strdup(otherURL.mFileBaseName) : nsnull; - mFileExtension = otherURL.mFileExtension ? nsCRT::strdup(otherURL.mFileExtension) : nsnull; + mFileName = otherURL.mFileName ? nsCRT::strdup(otherURL.mFileName) : nsnull; mParam = otherURL.mParam ? nsCRT::strdup(otherURL.mParam) : nsnull; mQuery = otherURL.mQuery ? nsCRT::strdup(otherURL.mQuery) : nsnull; mRef= otherURL.mRef ? nsCRT::strdup(otherURL.mRef) : nsnull; - - NS_IF_ADDREF(otherURL.mURLParser); - mURLParser = otherURL.mURLParser; - NS_INIT_AGGREGATED(nsnull); // Todo! How? return *this; } @@ -155,16 +202,15 @@ nsStdURL::operator==(const nsStdURL& otherURL) const nsStdURL::~nsStdURL() { CRTFREEIF(mScheme); - CRTFREEIF(mUsername); - CRTFREEIF(mPassword); + CRTFREEIF(mPreHost); CRTFREEIF(mHost); - CRTFREEIF(mDirectory); - CRTFREEIF(mFileBaseName); - CRTFREEIF(mFileExtension); + CRTFREEIF(mPath); + CRTFREEIF(mRef); CRTFREEIF(mParam); CRTFREEIF(mQuery); - CRTFREEIF(mRef); - NS_IF_RELEASE(mURLParser); + CRTFREEIF(mSpec); + CRTFREEIF(mDirectory); + CRTFREEIF(mFileName); } NS_IMPL_AGGREGATED(nsStdURL); @@ -196,12 +242,9 @@ nsStdURL::Equals(nsIURI *i_OtherURI, PRBool *o_Equals) PRBool eq = PR_FALSE; if (i_OtherURI) { nsXPIDLCString spec; - nsXPIDLCString spec2; nsresult rv = i_OtherURI->GetSpec(getter_Copies(spec)); if (NS_FAILED(rv)) return rv; - rv = this->GetSpec(getter_Copies(spec2)); - if (NS_FAILED(rv)) return rv; - eq = nsAutoString(spec).Equals(spec2); + eq = nsAutoString(spec).Equals(this->mSpec); } *o_Equals = eq; return NS_OK; @@ -220,146 +263,433 @@ nsStdURL::Clone(nsIURI **o_URI) return rv; } -nsresult -nsStdURL::GetURLParser(nsIURLParser* *aURLParser) -{ - *aURLParser = mURLParser; - NS_IF_ADDREF(*aURLParser); - return NS_OK; -} - -nsresult -nsStdURL::SetURLParser(nsIURLParser* aURLParser) -{ - NS_IF_RELEASE(mURLParser); - mURLParser = aURLParser; - return NS_OK; -} - nsresult -nsStdURL::Parse(const char* i_Spec) +nsStdURL::Parse(void) { - // Main parser - NS_PRECONDITION( (nsnull != i_Spec), "Parse called on empty url!"); - if (!i_Spec) + + NS_PRECONDITION( (nsnull != mSpec), "Parse called on empty url!"); + if (!mSpec) return NS_ERROR_MALFORMED_URI; - NS_PRECONDITION( (nsnull != mURLParser), "Parse called without parser!"); - if (!mURLParser) - return NS_ERROR_NULL_POINTER; + // Parse the path into its individual elements + // when we are done from here. + nsParsePath pp(this); - // Parse the spec - char* ePath = nsnull; - nsresult rv = mURLParser->ParseAtScheme(i_Spec, &mScheme, &mUsername, - &mPassword, &mHost, &mPort, - &ePath); - if (NS_SUCCEEDED(rv)) { - // Now parse the path - rv = mURLParser->ParseAtDirectory(ePath, &mDirectory, &mFileBaseName, - &mFileExtension, &mParam, - &mQuery, &mRef); - } - CRTFREEIF(ePath); - return rv; -} - -nsresult -nsStdURL::GetString(char** result, char* fromEscapedStr, Format toFormat) -{ - // Given str "foo%20bar", gets "foo bar" if UNESCAPED - nsresult rv = NS_OK; - if (toFormat == UNESCAPED) { - rv = nsURLUnescape(fromEscapedStr, result); - } else - rv = DupString(result, fromEscapedStr); - return rv; -} - -nsresult -nsStdURL::AppendString(nsCString& buffer, char * fromUnescapedStr, - Format toFormat, PRInt16 mask) -{ - // Given str "foo bar", appends "foo%20bar" to buffer if ESCAPED - nsresult rv = NS_OK; - - if (!fromUnescapedStr) - return NS_ERROR_FAILURE; - - char* temp = nsnull; - if (toFormat == ESCAPED) { - rv = nsURLEscape(fromUnescapedStr, mask, &temp); - if (NS_SUCCEEDED(rv)) - buffer += temp; - } else { - buffer += fromUnescapedStr; - } - - CRTFREEIF(temp); - return rv; -} - -nsresult -nsStdURL::AppendPreHost(nsCString& buffer, char* i_Username, - char* i_Password, Format toFormat) -{ - nsresult rv = NS_OK; - if (i_Username) + // Leading spaces are now removed by SetSpec. + int len = PL_strlen(mSpec); + static const char delimiters[] = "/:@?"; //this order is optimized. + char* brk = PL_strpbrk(mSpec, delimiters); + char* lastbrk = brk; + if (!brk) // everything is a host { - rv = AppendString(buffer,i_Username,ESCAPED, - nsIIOService::url_Username); - if (NS_FAILED(rv)) - return rv; - if (i_Password) + ExtractString(mSpec, &mHost, len); + return NS_OK; + } + + switch (*brk) + { + case '/' : + case '?' : + // If the URL starts with a slash then everything is a path + if (brk == mSpec) { - buffer += ':'; - rv = AppendString(buffer,i_Password,ESCAPED, - nsIIOService::url_Password); - if (NS_FAILED(rv)) - return rv; + ExtractString(mSpec, &mPath, len); + return NS_OK; } - buffer += '@'; + else // The first part is host, so its host/path + { + ExtractString(mSpec, &mHost, (brk - mSpec)); + ExtractString(brk, &mPath, (len - (brk - mSpec))); + return NS_OK; + } + break; + case ':' : + if (*(brk+1) == '/') + { + ExtractString(mSpec, &mScheme, (brk - mSpec)); + + if (*(brk+2) == '/') // e.g. http:// + // If the first colon is followed by // then its definitely a spec + { + lastbrk = brk+3; + brk = PL_strpbrk(lastbrk, delimiters); + if (!brk) // everything else is a host, as in http://host + { + ExtractString(lastbrk, &mHost, len - (lastbrk - mSpec)); + return NS_OK; + } + switch (*brk) + { + case '/' : // standard case- http://host/path + case '?' : // missing path cases + ExtractString(lastbrk, &mHost, (brk - lastbrk)); + ExtractString(brk, &mPath, (len - (brk - mSpec))); + + return NS_OK; + break; + case ':' : // http://user:... or http://host:... + { + // It could be http://user:pass@host/path + // or http://host:port/path we find that by checking further... + char* nextbrk = PL_strpbrk(brk+1, delimiters); + if (!nextbrk) // http://host:port + { + ExtractString(lastbrk, &mHost, (brk-lastbrk)); + mPort = ExtractPortFrom(brk+1); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + else + return NS_OK; + } + + switch (*nextbrk) + { + case '/': // http://host:port/path + case '?': // http://host:port?path + ExtractString(lastbrk, &mHost, + (brk-lastbrk)); + mPort = ExtractPortFrom(brk+1); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(nextbrk, &mPath, + len - (nextbrk-mSpec)); + return NS_OK; + break; + case '@': // http://user:pass@host... + ExtractString(lastbrk, &mPreHost, + (nextbrk - lastbrk)); + + brk = PL_strpbrk(nextbrk+1, delimiters); + if (!brk) // its just http://user:pass@host + { + ExtractString(nextbrk+1, &mHost, + len - (nextbrk+1 - mSpec)); + return NS_OK; + } + + ExtractString(nextbrk+1, &mHost, + brk - (nextbrk+1)); + + switch (*brk) + { + case '/': // http://user:pass@host/path + case '?': + ExtractString(brk, &mPath, + len - (brk - mSpec)); + return NS_OK; + break; + case ':': // http://user:pass@host:port... + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, "/?"); + if (brk) // http://user:pass@host:port/path + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(brk, &mPath, + len - (brk-mSpec)); + return NS_OK; + } + else // http://user:pass@host:port + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + return NS_OK; + } + break; + default: NS_POSTCONDITION(0, "This just can't be!"); + break; + } + break; + case ':': // three colons! + return NS_ERROR_MALFORMED_URI; + break; + default: NS_POSTCONDITION(0, "This just can't be!"); + break; + } + } + break; + case '@' : // http://user@host... + { + ExtractString(lastbrk, &mPreHost, + (brk-lastbrk)); + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, delimiters); + if (!brk) // its just http://user@host + { + ExtractString(lastbrk, &mHost, + len - (lastbrk - mSpec)); + return NS_OK; + } + ExtractString(lastbrk, &mHost, + (brk - lastbrk)); + switch (*brk) + { + case ':' : // http://user@host:port... + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, "/?"); + if (brk) // http://user@host:port/path + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(brk, &mPath, + len - (brk-mSpec)); + return NS_OK; + } + else // http://user@host:port + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + return NS_OK; + } + break; + case '/' : // http://user@host/path + case '?' : // http://user@host?path + ExtractString(brk, &mPath, + len - (brk - mSpec)); + return NS_OK; + break; + case '@' : + return NS_ERROR_MALFORMED_URI; + default : NS_POSTCONDITION(0, + "This just can't be!"); + break; + } + } + break; + default: NS_POSTCONDITION(0, "This just can't be!"); + break; + } + } + else // This is a no // path alone case like file:/path, + // there is never a prehost/host in this case. + { + ExtractString(brk+1, &mPath, len - (brk-mSpec+1)); + return NS_OK; + } + } + else // scheme:host or host:port... + { + lastbrk = brk+1; + + if ((*lastbrk >= '0') && (*lastbrk <= '9')) //host:port... + { + ExtractString(mSpec, &mHost, (brk - mSpec)); + brk = PL_strpbrk(lastbrk, delimiters); + if (!brk) // Everything else is just the port + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + return NS_OK; + } + switch (*brk) + { + case '/' : // The path, so its host:port/path + case '?' : // The path, so its host:port?path + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(brk, &mPath, len - (brk-mSpec)); + return NS_OK; + break; + case ':' : + return NS_ERROR_MALFORMED_URI; + break; + case '@' : + // This is a special case of user:pass@host... so + // Cleanout our earliar knowledge of host + CRTFREEIF(mHost); + + ExtractString(mSpec, &mPreHost, (brk-mSpec)); + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, ":/?"); + // its user:pass@host so everthing else is just the host + if (!brk) + { + ExtractString(lastbrk, &mHost, len - (lastbrk-mSpec)); + return NS_OK; + } + ExtractString(lastbrk, &mHost, (brk-lastbrk)); + if (*brk == ':') // user:pass@host:port... + { + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, "/?"); + if (brk) // user:pass@host:port/path + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(brk, &mPath, len - (brk-mSpec)); + return NS_OK; + } + else // user:pass@host:port + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + return NS_OK; + } + } + else // (*brk == '/') || (*brk == '?') + // so user:pass@host/path + { + ExtractString(brk, &mPath, len - (brk - mSpec)); + return NS_OK; + } + break; + default: NS_POSTCONDITION(0, "This just can't be!"); + break; + } + } + else // scheme:host... + { + ExtractString(mSpec, &mScheme, (brk - mSpec)); + brk = PL_strpbrk(lastbrk, delimiters); + if (!brk) // its just scheme:host + { + ExtractString(lastbrk, &mHost, len - (lastbrk-mSpec)); + return NS_OK; + } + switch (*brk) + { + case '/' : // The path, so its scheme:host/path + case '?' : // The path, so its scheme:host?path + ExtractString(lastbrk, &mHost, (brk-lastbrk)); + ExtractString(brk, &mPath, len - (brk - mSpec)); + return NS_OK; + break; + case '@' : // scheme:user@host... + ExtractString(lastbrk, &mPreHost, (brk-lastbrk)); + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, delimiters); + if (!brk) // scheme:user@host only + { + ExtractString(lastbrk, &mHost, len - (lastbrk-mSpec)); + return NS_OK; + } + ExtractString(lastbrk, &mHost, (brk - lastbrk)); + switch (*brk) + { + case ':' : // scheme:user@host:port... + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, "/?"); + if (brk) // user:pass@host:port/path + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(brk, &mPath, len - (brk-mSpec)); + return NS_OK; + } + else // user:pass@host:port + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + return NS_OK; + } + break; + case '/' : + case '?' : + ExtractString(brk, &mPath, len - (brk-mSpec)); + return NS_OK; + break; + case '@' : // bad case + return NS_ERROR_MALFORMED_URI; + break; + default: NS_POSTCONDITION(0, "This just can't be!"); + break; + } + break; + case ':' : // scheme:user:pass@host...or scheme:host:port... + /* TODO + if you find @ in the remaining string + then // scheme:user:pass@host... + { + + + } + else // scheme:host:port + { + ExtractString(lastbrk, &mHost, (brk-lastbrk)); + } + */ + break; + default: NS_POSTCONDITION(0, "This just can't be!"); + break; + } + } + } + break; + case '@' : + //Everything before the @ is the prehost stuff + ExtractString(mSpec, &mPreHost, brk-mSpec); + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, ":/"); + if (!brk) // its user@host so everything else is just the host + { + ExtractString(lastbrk, &mHost, (len - (lastbrk-mSpec))); + return NS_OK; + } + ExtractString(lastbrk, &mHost, (brk-lastbrk)); + if (*brk == ':') // user@host:port... + { + lastbrk = brk+1; + brk = PL_strpbrk(lastbrk, "/?"); + if (brk) // user@host:port/path + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + ExtractString(brk, &mPath, len - (brk-mSpec)); + return NS_OK; + } + else // user@host:port + { + mPort = ExtractPortFrom(lastbrk); + if (mPort <= 0) + return NS_ERROR_MALFORMED_URI; + return NS_OK; + } + } + else // (*brk == '/') so user@host/path + { + ExtractString(brk, &mPath, len - (brk - mSpec)); + return NS_OK; + } + break; + default: + NS_ASSERTION(0, "This just can't be!"); + break; } - return rv; + + return NS_OK; } nsresult -nsStdURL::AppendFileName(nsCString& buffer, char* i_FileBaseName, - char* i_FileExtension, Format toFormat) +nsStdURL::ReconstructSpec() { - nsresult rv = NS_OK; - if (i_FileBaseName) - { - rv = AppendString(buffer,i_FileBaseName,ESCAPED, - nsIIOService::url_FileBaseName); - if (NS_FAILED(rv)) - return rv; - } - if (i_FileExtension) - { - buffer += '.'; - rv = AppendString(buffer,i_FileExtension,ESCAPED, - nsIIOService::url_FileExtension); - } - return rv; -} + if (mSpec) nsCRT::free(mSpec); -nsresult -nsStdURL::GetSpec(char **o_Spec) -{ - nsresult rv = NS_OK; nsCAutoString finalSpec; // guaranteed to be singlebyte. finalSpec.SetCapacity(64); if (mScheme) { - rv = AppendString(finalSpec,mScheme,ESCAPED,nsIIOService::url_Scheme); + finalSpec = mScheme; finalSpec += "://"; } - - rv = AppendPreHost(finalSpec,mUsername,mPassword,ESCAPED); - + if (mPreHost) + { + finalSpec += mPreHost; + finalSpec += '@'; + } if (mHost) { - rv = AppendString(finalSpec,mHost,ESCAPED,nsIIOService::url_Host); + finalSpec += mHost; if (-1 != mPort) { char* portBuffer = PR_smprintf(":%d", mPort); @@ -370,21 +700,12 @@ nsStdURL::GetSpec(char **o_Spec) portBuffer = 0; } } - char* ePath = nsnull; - rv = GetPath(&ePath); - if NS_FAILED(rv) { - CRTFREEIF(ePath); - return rv; - } - - if (ePath) + if (mPath) { - finalSpec += ePath; + finalSpec += mPath; } - *o_Spec = finalSpec.ToNewCString(); - CRTFREEIF(ePath); - - return (*o_Spec ? NS_OK : NS_ERROR_OUT_OF_MEMORY); + mSpec = finalSpec.ToNewCString(); + return (mSpec ? NS_OK : NS_ERROR_OUT_OF_MEMORY); } NS_METHOD @@ -403,31 +724,40 @@ nsStdURL::Create(nsISupports *aOuter, return NS_ERROR_OUT_OF_MEMORY; nsresult rv = url->AggregatedQueryInterface(aIID, aResult); - if (NS_FAILED(rv)) { - delete url; - return rv; - } - + if (NS_FAILED(rv)) { + delete url; + return rv; + } + return rv; } -NS_METHOD -nsStdURL::GetPreHost(char **o_PreHost) +nsresult +nsStdURL::ExtractString(char* i_Src, char* *o_Dest, PRUint32 length) { - if (!o_PreHost) + NS_PRECONDITION( (nsnull != i_Src), "Exract called on empty string!"); + CRTFREEIF(*o_Dest); + if (0 == length) + return NS_OK; + *o_Dest = PL_strndup(i_Src, length); + return (*o_Dest ? NS_OK : NS_ERROR_OUT_OF_MEMORY); +} + +nsresult +nsStdURL::DupString(char* *o_Dest, const char* i_Src) +{ + if (!o_Dest) return NS_ERROR_NULL_POINTER; - - nsCAutoString temp; - - nsresult rv = AppendPreHost(temp,mUsername,mPassword,ESCAPED); - - if (NS_FAILED(rv)) - return rv; - - *o_PreHost = temp.ToNewCString(); - if (!*o_PreHost) - return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; + if (i_Src) + { + *o_Dest = nsCRT::strdup(i_Src); + return (*o_Dest == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; + } + else + { + *o_Dest = nsnull; + return NS_OK; + } } NS_IMETHODIMP @@ -451,11 +781,10 @@ nsStdURL::SetDirectory(const char* i_Directory) dir += "/"; } - CRTFREEIF(mDirectory); mDirectory = dir.ToNewCString(); if (!mDirectory) return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; + return ReconstructPath(); } NS_IMETHODIMP @@ -464,50 +793,54 @@ nsStdURL::SetFileName(const char* i_FileName) if (!i_FileName) return NS_ERROR_NULL_POINTER; - NS_PRECONDITION( (nsnull != mURLParser), "Parse called without parser!"); - if (!mURLParser) - return NS_ERROR_NULL_POINTER; + //Cleanout param, query and ref + CRTFREEIF(mParam); + CRTFREEIF(mQuery); + CRTFREEIF(mRef); //If it starts with a / then everything is the path. if ('/' == *i_FileName) { return SetPath(i_FileName); } - // Otherwise concatenate Directory and Filename and the call SetPath - nsCAutoString dir; - nsresult status = AppendString(dir,mDirectory,ESCAPED, - nsIIOService::url_Directory); - dir += i_FileName; - char *eNewPath = dir.ToNewCString(); - if (!eNewPath) - return NS_ERROR_OUT_OF_MEMORY; - status = SetPath(eNewPath); - CRTFREEIF(eNewPath); + CRTFREEIF(mFileName); + nsresult status = DupString(&mFileName, i_FileName); + + // XXX This is ineffecient + ReconstructPath(); + ParsePath(); + return status; } -NS_IMETHODIMP -nsStdURL::SetParam(const char* i_Param) -{ - CRTFREEIF(mParam); - return DupString(&mParam, (i_Param && (*i_Param == ';')) ? - (i_Param+1) : i_Param); -} - -NS_IMETHODIMP -nsStdURL::SetQuery(const char* i_Query) -{ - CRTFREEIF(mQuery); - return DupString(&mQuery, (i_Query && (*i_Query == '?')) ? - (i_Query+1) : i_Query); -} - NS_IMETHODIMP nsStdURL::SetRef(const char* i_Ref) { - CRTFREEIF(mRef); - return DupString(&mRef, (i_Ref && (*i_Ref == '#')) ? - (i_Ref+1) : i_Ref); + /* + no check for i_Ref = nsnull becuz you can remove # by using it that way + So SetRef(nsnull) removed any existing ref values whereas + SetRef("") will ensure that there is a # at the end. These apply to + ? and ; as well. + */ + nsresult status = DupString(&mRef, + (i_Ref && (*i_Ref == '#')) ? (i_Ref+1) : i_Ref); + return (NS_FAILED(status) ? status : ReconstructPath()); +} + +NS_IMETHODIMP +nsStdURL::SetParam(const char* i_Param) +{ + nsresult status = DupString(&mParam, + (i_Param && (*i_Param == ';')) ? (i_Param+1) : i_Param); + return (NS_FAILED(status) ? status : ReconstructPath()); +} + +NS_IMETHODIMP +nsStdURL::SetQuery(const char* i_Query) +{ + nsresult status = DupString(&mQuery, + (i_Query && (*i_Query == '?')) ? (i_Query+1) : i_Query); + return (NS_FAILED(status) ? status : ReconstructPath()); } NS_IMETHODIMP @@ -518,16 +851,10 @@ nsStdURL::SetRelativePath(const char* i_Relative) char* ref; char* query; char* file; - char* i_Path; - char* ePath = nsnull; if (!i_Relative) return NS_ERROR_NULL_POINTER; - NS_PRECONDITION( (nsnull != mURLParser), "Parse called without parser!"); - if (!mURLParser) - return NS_ERROR_NULL_POINTER; - // Make sure that if there is a : its before other delimiters // If not then its an absolute case static const char delimiters[] = "/;?#:"; @@ -538,56 +865,32 @@ nsStdURL::SetRelativePath(const char* i_Relative) return rv; } - if (*i_Relative == '/' && *(i_Relative+1) != '\0' && - *(i_Relative+1) == '/') { - CRTFREEIF(mUsername); - CRTFREEIF(mPassword); - CRTFREEIF(mHost); - mPort = -1; - rv = mURLParser->ParseAtPreHost((char*)i_Relative, &mUsername, - &mPassword, &mHost, &mPort, &ePath); - if (NS_FAILED(rv)) - return rv; - i_Path = ePath; - } else { - i_Path = (char*)i_Relative; - } - - char* eFileName = nsnull; - - switch (*i_Path) + switch (*i_Relative) { case '/': - rv = SetPath((char*) i_Path); - CRTFREEIF(ePath); - return rv; + return SetPath((char*) i_Relative); case ';': - // Append to Filename add then call SetFileName - rv = GetFileName(&eFileName); - options = eFileName; - CRTFREEIF(eFileName); - options += (char*)i_Path; - file = options.ToNewCString(); + // Append to Filename add then call SetFilePath + options = mFileName; + options += (char*)i_Relative; + file = (char*)options.GetBuffer(); rv = SetFileName(file); - CRTFREEIF(ePath); return rv; case '?': // check for ref part - ref = PL_strrchr(i_Path, '#'); + ref = PL_strrchr(i_Relative, '#'); if (!ref) { CRTFREEIF(mRef); - rv = SetQuery((char*)i_Path); - CRTFREEIF(ePath); - return rv; + return SetQuery((char*)i_Relative); } else { DupString(&query,nsnull); - ExtractString((char*)i_Path, &query, - (PL_strlen(i_Path)-(ref-i_Path))); - CRTFREEIF(ePath); + ExtractString((char*)i_Relative, &query, + (PL_strlen(i_Relative)-(ref-i_Relative))); + rv = SetQuery(query); - CRTFREEIF(query); + nsCRT::free(query); if (NS_FAILED(rv)) return rv; rv = SetRef(ref); return rv; @@ -595,21 +898,17 @@ nsStdURL::SetRelativePath(const char* i_Relative) break; case '#': - rv = SetRef((char*)i_Path); - CRTFREEIF(ePath); - return rv; + return SetRef((char*)i_Relative); default: - rv = SetFileName((char*)i_Path); - CRTFREEIF(ePath); - return rv; + return SetFileName((char*)i_Relative); } } NS_IMETHODIMP nsStdURL::Resolve(const char *relativePath, char **result) { - nsresult rv = NS_OK; + nsresult rv; if (!relativePath) return NS_ERROR_NULL_POINTER; @@ -624,51 +923,26 @@ nsStdURL::Resolve(const char *relativePath, char **result) if (path) { path = PL_strstr((char*)(path+3),"/"); if (path) - CoaleseDirs(path); + ReplaceMess(path); } return rv; } nsCAutoString finalSpec; // guaranteed to be singlebyte. - // This is another case of an almost absolute URL - if (*relativePath == '/' && *(relativePath+1) != '\0' && - *(relativePath+1) == '/') { - - if (mScheme) - { - rv = AppendString(finalSpec,mScheme,ESCAPED, - nsIIOService::url_Scheme); - finalSpec += ":"; - } - - finalSpec += relativePath; - *result = finalSpec.ToNewCString(); - if (*result) { - char* path = PL_strstr(*result,"://"); - if (path) { - path = PL_strstr((char*)(path+3),"/"); - if (path) - CoaleseDirs(path); - } - return NS_OK; - } else - return NS_ERROR_OUT_OF_MEMORY; - } - - const char *start = relativePath; - if (mScheme) { - rv = AppendString(finalSpec,mScheme,ESCAPED,nsIIOService::url_Scheme); + finalSpec = mScheme; finalSpec += "://"; } - - rv = AppendPreHost(finalSpec,mUsername,mPassword,ESCAPED); - + if (mPreHost) + { + finalSpec += mPreHost; + finalSpec += '@'; + } if (mHost) { - rv = AppendString(finalSpec,mHost,ESCAPED,nsIIOService::url_Host); + finalSpec += mHost; if (-1 != mPort) { char* portBuffer = PR_smprintf(":%d", mPort); @@ -680,65 +954,52 @@ nsStdURL::Resolve(const char *relativePath, char **result) } } - if (start) { - switch (*start) - { + switch (*relativePath) + { case '/': - finalSpec += (char*)start; + finalSpec += (char*)relativePath; break; case ';': - rv = AppendString(finalSpec,mDirectory,ESCAPED, - nsIIOService::url_Directory); - rv = AppendFileName(finalSpec,mFileBaseName,mFileExtension, - ESCAPED); - finalSpec += (char*)start; + finalSpec += mDirectory; + finalSpec += mFileName; + finalSpec += (char*)relativePath; break; case '?': - rv = AppendString(finalSpec,mDirectory,ESCAPED, - nsIIOService::url_Directory); - rv = AppendFileName(finalSpec,mFileBaseName,mFileExtension, - ESCAPED); + finalSpec += mDirectory; + finalSpec += mFileName; if (mParam) { finalSpec += ';'; - rv = AppendString(finalSpec,mParam,ESCAPED, - nsIIOService::url_Param); + finalSpec += mParam; } - finalSpec += (char*)start; + finalSpec += (char*)relativePath; break; case '#': - rv = AppendString(finalSpec,mDirectory,ESCAPED, - nsIIOService::url_Directory); - rv = AppendFileName(finalSpec,mFileBaseName,mFileExtension, - ESCAPED); + finalSpec += mDirectory; + finalSpec += mFileName; if (mParam) { finalSpec += ';'; - rv = AppendString(finalSpec,mParam,ESCAPED, - nsIIOService::url_Param); + finalSpec += mParam; } if (mQuery) { finalSpec += '?'; - rv = AppendString(finalSpec,mQuery,ESCAPED, - nsIIOService::url_Query); + finalSpec += mQuery; } - finalSpec += (char*)start; + finalSpec += (char*)relativePath; break; default: - rv = AppendString(finalSpec,mDirectory,ESCAPED, - nsIIOService::url_Directory); - finalSpec += (char*)start; - } + finalSpec += mDirectory; + finalSpec += (char*)relativePath; } *result = finalSpec.ToNewCString(); - if (*result) { char* path = PL_strstr(*result,"://"); if (path) { path = PL_strstr((char*)(path+3),"/"); if (path) - CoaleseDirs(path); + ReplaceMess(path); } return NS_OK; } else @@ -746,144 +1007,255 @@ nsStdURL::Resolve(const char *relativePath, char **result) } nsresult -nsStdURL::GetPath(char** o_Path) +nsStdURL::ReconstructPath(void) { + if (mPath) nsCRT::free(mPath); + //Take all the elements of the path and construct it nsCAutoString path; - nsresult rv = NS_OK; path.SetCapacity(64); if (mDirectory) { - rv = AppendString(path,mDirectory,ESCAPED,nsIIOService::url_Directory); - if (NS_FAILED(rv)) - return rv; + path = mDirectory; + } + if (mFileName) + { + path += mFileName; } - - rv = AppendFileName(path,mFileBaseName,mFileExtension, ESCAPED); - if (NS_FAILED(rv)) - return rv; - if (mParam) { path += ';'; - rv = AppendString(path,mParam,ESCAPED,nsIIOService::url_Param); - if (NS_FAILED(rv)) - return rv; + path += mParam; } if (mQuery) { path += '?'; - rv = AppendString(path,mQuery,ESCAPED,nsIIOService::url_Query); - if (NS_FAILED(rv)) - return rv; + path += mQuery; } if (mRef) { path += '#'; - rv = AppendString(path,mRef,ESCAPED,nsIIOService::url_Ref); - if (NS_FAILED(rv)) - return rv; + path += mRef; } - *o_Path = path.ToNewCString(); - return (*o_Path ? NS_OK : NS_ERROR_OUT_OF_MEMORY); + mPath = path.ToNewCString(); + + return (mPath ? ReconstructSpec() : NS_ERROR_OUT_OF_MEMORY); } +/** Extract the elements like directory/filename, query, or ref from + * the path. + */ nsresult -nsStdURL::GetDirectory(char** o_Directory) +nsStdURL::ParsePath(void) { - nsCAutoString directory; - nsresult rv = NS_OK; - rv = AppendString(directory,mDirectory,ESCAPED, - nsIIOService::url_Directory); - if (NS_FAILED(rv)) - return rv; - *o_Directory = directory.ToNewCString(); - return (*o_Directory ? NS_OK : NS_ERROR_OUT_OF_MEMORY); + CRTFREEIF(mDirectory); + CRTFREEIF(mFileName); + CRTFREEIF(mParam); + CRTFREEIF(mQuery); + CRTFREEIF(mRef); + + if (!mPath) + { + DupString(&mDirectory, "/"); + return (mDirectory ? ReconstructPath() : NS_ERROR_OUT_OF_MEMORY); + } + + char* dirfile = nsnull; + char* options = nsnull; + + int len = PL_strlen(mPath); + + /* Factor out the optionpart with ;?# */ + static const char delimiters[] = ";?#"; // for param, query and ref + char* brk = PL_strpbrk(mPath, delimiters); + + if (!brk) // Everything is just path and filename + { + DupString(&dirfile, mPath); + } + else + { + int dirfileLen = brk - mPath; + ExtractString(mPath, &dirfile, dirfileLen); + len -= dirfileLen; + ExtractString(mPath + dirfileLen, &options, len); + brk = options; + } + + /* now that we have broken up the path treat every part differently */ + /* first dir+file */ + + char* file; + + int dlen = PL_strlen(dirfile); + if (dlen == 0) + { + DupString(&mDirectory, "/"); + file = dirfile; + } else { + ReplaceMess(dirfile); + // check new length + dlen = PL_strlen(dirfile); + + // First find the last slash + file = PL_strrchr(dirfile, '/'); + if (!file) + { + DupString(&mDirectory, "/"); + file = dirfile; + } + + // If its not the same as the first slash then extract directory + if (file != dirfile) + { + ExtractString(dirfile, &mDirectory, (file - dirfile)+1); + } else { + DupString(&mDirectory, "/"); + } + } + + /* Extract Filename */ + if (dlen > 0) { + // Look again if there was a slash + char* slash = PL_strrchr(dirfile, '/'); + if (slash) { + ExtractString(file+1, &mFileName, dlen-(file-dirfile-1)); + } else { + // Use the full String as Filename + ExtractString(dirfile, &mFileName, dlen); + } + } + +#if 0 + // Now take a look at the options. "#" has precedence over "?" + // which has precedence over ";" + if (options) { + // Look for "#" first. Everything following it is in the ref + brk = PL_strchr(options, '#'); + if (brk) { + *brk = 0; + int pieceLen = len - (brk + 1 - options); + ExtractString(brk+1, &mRef, pieceLen); + len -= pieceLen + 1; + } + + // Now look for "?" + brk = PL_strchr(options, '?'); + if (brk) { + *brk = 0; + int pieceLen = len - (brk + 1 - options); + ExtractString(brk+1, &mQuery, pieceLen); + len -= pieceLen + 1; + } + + // Now look for ';' + brk = PL_strchr(options, ';'); + if (brk) { + int pieceLen = len - (brk + 1 - options); + ExtractString(brk+1, &mParam, pieceLen); + len -= pieceLen + 1; + } + } + +#endif + while (brk) + { + int pieceLen; + char* lastbrk = brk; + brk = PL_strpbrk(lastbrk+1, delimiters); + switch (*lastbrk) + { + case ';': // handles cases of ;foo?bar#baz correctly + pieceLen = (brk ? (brk-lastbrk-1) : len); + ExtractString(lastbrk+1, &mParam, pieceLen); + len -= pieceLen; + break; + case '?': // Only # takes higher precedence than this + // so changing brk to only check for # + brk = PL_strpbrk(lastbrk+1 , "#"); + pieceLen = (brk ? (brk-lastbrk-1) : len); + ExtractString(lastbrk+1, &mQuery, pieceLen); + len -= pieceLen; + break; + case '#': + // Since this has the highest precedence everything following it + // is a ref. So... + pieceLen = len; + ExtractString(lastbrk+1, &mRef, pieceLen); + len -= pieceLen; + break; + default: + NS_ASSERTION(0, "This just can't be!"); + break; + } + } + + nsCRT::free(dirfile); + nsCRT::free(options); + + ReconstructPath(); + return NS_OK; } NS_METHOD nsStdURL::SetSpec(const char* i_Spec) { - // Skip leading spaces and control-characters + // Skip leading spaces char* fwdPtr= (char*) i_Spec; - while (fwdPtr && (*fwdPtr > '\0') && (*fwdPtr <= ' ')) + while (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == ' ')) fwdPtr++; - // Remove trailing spaces and control-characters + // Remove trailing spaces if (fwdPtr) { char* bckPtr= (char*)fwdPtr + PL_strlen(fwdPtr) -1; - if (*bckPtr > '\0' && *bckPtr <= ' ') { - while ((bckPtr-fwdPtr) >= 0 && (*bckPtr <= ' ')) { + if (*bckPtr == ' ') { + while ((bckPtr-fwdPtr) >= 0 && (*bckPtr == ' ')) { bckPtr--; } *(bckPtr+1) = '\0'; } } + CRTFREEIF(mSpec); + nsresult status = DupString(&mSpec, fwdPtr); // If spec is being rewritten clean up everything- CRTFREEIF(mScheme); - CRTFREEIF(mUsername); - CRTFREEIF(mPassword); + CRTFREEIF(mPreHost); CRTFREEIF(mHost); mPort = -1; + CRTFREEIF(mPath); CRTFREEIF(mDirectory); - CRTFREEIF(mFileBaseName); - CRTFREEIF(mFileExtension); + CRTFREEIF(mFileName); CRTFREEIF(mParam); CRTFREEIF(mQuery); CRTFREEIF(mRef); - return Parse(fwdPtr); -} - -NS_METHOD -nsStdURL::SetPreHost(const char* i_PreHost) -{ - NS_PRECONDITION( (nsnull != mURLParser), "Parse called without parser!"); - if (!mURLParser) - return NS_ERROR_NULL_POINTER; - - CRTFREEIF(mUsername); - CRTFREEIF(mPassword); - - return mURLParser->ParsePreHost(i_PreHost,&mUsername,&mPassword); + return (NS_FAILED(status) ? status : Parse()); } NS_METHOD nsStdURL::SetPath(const char* i_Path) { - NS_PRECONDITION( (nsnull != mURLParser), "Parse called without parser!"); - if (!mURLParser) - return NS_ERROR_NULL_POINTER; - - CRTFREEIF(mDirectory); - CRTFREEIF(mFileBaseName); - CRTFREEIF(mFileExtension); - CRTFREEIF(mParam); - CRTFREEIF(mQuery); - CRTFREEIF(mRef); - - return mURLParser->ParseAtDirectory((char*)i_Path, &mDirectory, - &mFileBaseName, - &mFileExtension, &mParam, - &mQuery, &mRef); + if (mPath) nsCRT::free(mPath); + nsresult status = DupString(&mPath, i_Path); + ParsePath(); + ReconstructSpec(); + return status; } - + NS_METHOD nsStdURL::GetFilePath(char **o_DirFile) { if (!o_DirFile) return NS_ERROR_NULL_POINTER; - - nsresult rv = NS_OK; - nsCAutoString temp; + + nsAutoString temp; if (mDirectory) { - rv = AppendString(temp,mDirectory,ESCAPED,nsIIOService::url_Directory); + temp = mDirectory; + } + if (mFileName) + { + temp += mFileName; } - - rv = AppendFileName(temp,mFileBaseName,mFileExtension,ESCAPED); - if (NS_FAILED(rv)) - return rv; - *o_DirFile = temp.ToNewCString(); if (!*o_DirFile) return NS_ERROR_OUT_OF_MEMORY; @@ -891,26 +1263,19 @@ nsStdURL::GetFilePath(char **o_DirFile) } NS_METHOD -nsStdURL::GetFileName(char **o_FileName) +nsStdURL::SetFilePath(const char *filePath) { - if (!o_FileName) - return NS_ERROR_NULL_POINTER; - - nsresult rv = NS_OK; - nsCAutoString temp; - - rv = AppendFileName(temp,mFileBaseName,mFileExtension,ESCAPED); - if (NS_FAILED(rv)) - return rv; - - *o_FileName = temp.ToNewCString(); - if (!*o_FileName) - return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } NS_METHOD -nsStdURL::SetFilePath(const char *filePath) +nsStdURL::GetFileBaseName(char **o_name) { - return SetPath(filePath); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD +nsStdURL::SetFileBaseName(const char *name) +{ + return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/netwerk/base/src/nsStdURL.h b/netwerk/base/src/nsStdURL.h index e83abf24cabf..6d878d18db78 100644 --- a/netwerk/base/src/nsStdURL.h +++ b/netwerk/base/src/nsStdURL.h @@ -24,8 +24,6 @@ #define nsStdURL_h__ #include "nsIURL.h" -#include "nsIURLParser.h" -#include "nsURLHelper.h" #include "nsAgg.h" #include "nsCRT.h" #include "nsString.h" // REMOVE Later!! @@ -41,10 +39,9 @@ class nsStdURL : public nsIURL { public: - /////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// // nsStdURL methods: - nsStdURL(); nsStdURL(const char* i_Spec, nsISupports* outer=nsnull); nsStdURL(const nsStdURL& i_URL); virtual ~nsStdURL(); @@ -57,67 +54,156 @@ public: NS_DECL_AGGREGATED - /////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// // nsIURI methods: NS_DECL_NSIURI - /////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// // nsIURL methods: NS_DECL_NSIURL -protected: - enum Format { ESCAPED, UNESCAPED }; - nsresult Parse(const char* i_Spec); - nsresult AppendString(nsCString& buffer, char* fromUnescapedStr, - Format toFormat, PRInt16 mask); - nsresult GetString(char** result, char* fromEscapedStr, - Format toFormat); - nsresult AppendPreHost(nsCString& buffer, char* i_Username, - char* i_Password, Format toFormat); - nsresult AppendFileName(nsCString& buffer, char* i_FileBaseName, - char* i_FileExtension, Format toFormat); + /* todo move this to protected later */ + nsresult ParsePath(void); +protected: + nsresult Parse(void); + nsresult ReconstructPath(void); + nsresult ReconstructSpec(void); + + // Some handy functions + nsresult DupString(char* *o_Dest, const char* i_Src); + nsresult ExtractString(char* i_Src, char* *o_Dest, PRUint32 length); protected: char* mScheme; - char* mUsername; - char* mPassword; + char* mPreHost; char* mHost; PRInt32 mPort; + char* mPath; char* mDirectory; - char* mFileBaseName; - char* mFileExtension; + char* mFileName; char* mParam; char* mQuery; char* mRef; - nsIURLParser* mURLParser; + char* mSpec; }; +inline NS_METHOD +nsStdURL::GetSpec(char* *o_Spec) +{ + return DupString(o_Spec, mSpec); +} + inline NS_METHOD nsStdURL::GetScheme(char* *o_Scheme) { - return GetString(o_Scheme, mScheme, UNESCAPED); + return DupString(o_Scheme, mScheme); } inline NS_METHOD -nsStdURL::GetUsername(char* *o_Username) +nsStdURL::GetPreHost(char* *o_PreHost) { - return GetString(o_Username, mUsername, UNESCAPED); -} - -inline NS_METHOD -nsStdURL::GetPassword(char* *o_Password) -{ - return GetString(o_Password, mPassword, UNESCAPED); + return DupString(o_PreHost, mPreHost); } inline NS_METHOD nsStdURL::GetHost(char* *o_Host) { - return GetString(o_Host, mHost, UNESCAPED); + return DupString(o_Host, mHost); +} + +inline NS_METHOD +nsStdURL::GetPath(char* *o_Path) +{ + return DupString(o_Path, mPath); +} + +inline NS_METHOD +nsStdURL::GetDirectory(char* *o_Directory) +{ + return DupString(o_Directory, mDirectory); +} + +inline NS_METHOD +nsStdURL::GetFileName(char* *o_FileName) +{ + return DupString(o_FileName, mFileName); +} + +inline NS_METHOD +nsStdURL::GetFileExtension(char* *o_FileExtension) +{ + if (!o_FileExtension) + return NS_ERROR_NULL_POINTER; + + char *dot = mFileName; + if (dot) { + // find the last dot + while (*dot) dot++; + while ( (dot != mFileName) && (*dot != '.') ) dot--; // goto the dot. + if (*dot == '.') { + nsCAutoString ext(dot+1); + *o_FileExtension = ext.ToNewCString(); + if (!*o_FileExtension) return NS_ERROR_OUT_OF_MEMORY; + } else { + *o_FileExtension = nsnull; + } + } + return NS_OK; +} + +inline NS_METHOD +nsStdURL::SetFileExtension(const char* FileExtension) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +inline NS_METHOD +nsStdURL::GetRef(char* *o_Ref) +{ + return DupString(o_Ref, mRef); +} + +inline NS_METHOD +nsStdURL::GetParam(char **o_Param) +{ + return DupString(o_Param, mParam); +} + +inline NS_METHOD +nsStdURL::GetQuery(char* *o_Query) +{ + return DupString(o_Query, mQuery); +} + +inline NS_METHOD +nsStdURL::SetScheme(const char* i_Scheme) +{ + if (mScheme) nsCRT::free(mScheme); + nsresult status = DupString(&mScheme, i_Scheme); + ReconstructSpec(); + return status; +} + +inline NS_METHOD +nsStdURL::SetPreHost(const char* i_PreHost) +{ + if (mPreHost) nsCRT::free(mPreHost); + nsresult status = DupString(&mPreHost, i_PreHost); + ReconstructSpec(); + return status; +} + +inline NS_METHOD +nsStdURL::SetHost(const char* i_Host) +{ + if (mHost) nsCRT::free(mHost); + nsresult status = DupString(&mHost, i_Host); + ReconstructSpec(); + return status; } inline NS_METHOD @@ -131,84 +217,12 @@ nsStdURL::GetPort(PRInt32 *aPort) return NS_ERROR_NULL_POINTER; } -inline NS_METHOD -nsStdURL::GetFileBaseName(char* *o_FileBaseName) -{ - return GetString(o_FileBaseName, mFileBaseName, UNESCAPED); -} - -inline NS_METHOD -nsStdURL::GetFileExtension(char* *o_FileExtension) -{ - return GetString(o_FileExtension, mFileExtension, UNESCAPED); -} - -inline NS_METHOD -nsStdURL::GetParam(char **o_Param) -{ - return GetString(o_Param, mParam, UNESCAPED); -} - -inline NS_METHOD -nsStdURL::GetQuery(char* *o_Query) -{ - return GetString(o_Query, mQuery, UNESCAPED); -} - -inline NS_METHOD -nsStdURL::GetRef(char* *o_Ref) -{ - return GetString(o_Ref, mRef, UNESCAPED); -} - -inline NS_METHOD -nsStdURL::SetScheme(const char* i_Scheme) -{ - CRTFREEIF(mScheme); - return DupString(&mScheme, i_Scheme); -} - -inline NS_METHOD -nsStdURL::SetUsername(const char* i_Username) -{ - CRTFREEIF(mUsername); - return DupString(&mUsername, i_Username); -} - -inline NS_METHOD -nsStdURL::SetPassword(const char* i_Password) -{ - CRTFREEIF(mPassword); - return DupString(&mPassword, i_Password); -} - -inline NS_METHOD -nsStdURL::SetHost(const char* i_Host) -{ - CRTFREEIF(mHost); - return DupString(&mHost, i_Host); -} - inline NS_METHOD nsStdURL::SetPort(PRInt32 aPort) { mPort = aPort; + ReconstructSpec(); return NS_OK; } -inline NS_METHOD -nsStdURL::SetFileBaseName(const char* i_FileBaseName) -{ - CRTFREEIF(mFileBaseName); - return DupString(&mFileBaseName, i_FileBaseName); -} - -inline NS_METHOD -nsStdURL::SetFileExtension(const char* i_FileExtension) -{ - CRTFREEIF(mFileExtension); - return DupString(&mFileExtension, i_FileExtension); -} - #endif // nsStdURL_h__ - diff --git a/netwerk/base/src/nsStdURLParser.cpp b/netwerk/base/src/nsStdURLParser.cpp deleted file mode 100644 index 011714aa728c..000000000000 --- a/netwerk/base/src/nsStdURLParser.cpp +++ /dev/null @@ -1,463 +0,0 @@ -/* -*- 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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Andreas Otte. - * - * Contributor(s): - */ - -#include "nsStdURLParser.h" -#include "nsURLHelper.h" -#include "nsCRT.h" -#include "nsString.h" -#include "prprf.h" - -NS_IMPL_ISUPPORTS1(nsStdURLParser, - nsIURLParser) - -nsStdURLParser::~nsStdURLParser() -{ -} - - -NS_METHOD -nsStdURLParser::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - if (aOuter) - return NS_ERROR_NO_AGGREGATION; - nsStdURLParser* p = new nsStdURLParser(); - if (p == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(p); - nsresult rv = p->QueryInterface(aIID, aResult); - NS_RELEASE(p); - return rv; -} - -nsresult -nsStdURLParser::ParseAtScheme(const char* i_Spec, char* *o_Scheme, - char* *o_Username, - char* *o_Password, - char* *o_Host, PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - - NS_PRECONDITION( (nsnull != i_Spec), "Parse called on empty url!"); - if (!i_Spec) - return NS_ERROR_MALFORMED_URI; - - int len = PL_strlen(i_Spec); - if (len >= 2 && *i_Spec == '/' && *(i_Spec+1) == '/') // No Scheme - { - rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host, o_Port, - o_Path); - return rv; - } - - static const char delimiters[] = "/:@?"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - - if (!brk) // everything is a host - { - rv = ExtractString((char*)i_Spec, o_Host, len); - return rv; - } else - len = PL_strlen(brk); - - switch (*brk) - { - case '/' : - case '?' : - // If the URL starts with a slash then everything is a path - if (brk == i_Spec) - { - rv = ParseAtPath(brk, o_Path); - return rv; - } - else // The first part is host, so its host/path - { - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPath(brk, o_Path); - return rv; - } - break; - case ':' : - if (len >= 2 && *(brk+1) == '/' && *(brk+2) == '/') { - // Standard http://... - rv = ExtractString((char*)i_Spec, o_Scheme, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host, - o_Port, o_Path); - if (rv == NS_ERROR_MALFORMED_URI) { - // or not ? Try something else - CRTFREEIF(*o_Username); - CRTFREEIF(*o_Password); - CRTFREEIF(*o_Host); - *o_Port = -1; - rv = ParseAtPath(brk+3, o_Path); - } - return rv; - } else { - if ( len >= 2 && *(brk+1) == '/' && *(brk+2) != '/') { - // May be it is file:/.... - rv = ExtractString((char*)i_Spec, o_Scheme, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPath(brk+1, o_Path); - return rv; - } else { - // Could be host:port, so try conversion to number - PRInt32 port = ExtractPortFrom(brk+1); - if (port <= 0) - { - // No, try normal procedure - rv = ExtractString((char*)i_Spec, o_Scheme, - (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host, - o_Port, o_Path); - if (rv == NS_ERROR_MALFORMED_URI) { - // Try something else - CRTFREEIF(*o_Username); - CRTFREEIF(*o_Password); - CRTFREEIF(*o_Host); - *o_Port = -1; - rv = ParseAtPath(brk+1, o_Path); - } - return rv; - } else { - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPort(brk+1, o_Port, o_Path); - return rv; - } - } - } - break; - case '@' : - rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host, - o_Port, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsStdURLParser::ParseAtPreHost(const char* i_Spec, char* *o_Username, - char* *o_Password, char* *o_Host, - PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - - // Skip leading two slashes - char* fwdPtr= (char*) i_Spec; - if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/')) - fwdPtr++; - if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/')) - fwdPtr++; - - // Search for @ - static const char delimiters[] = "@"; - char* brk = PL_strpbrk(fwdPtr, delimiters); - - if (brk) - { - char* e_PreHost = nsnull; - rv = ExtractString(fwdPtr, &e_PreHost, (brk - fwdPtr)); - if (NS_FAILED(rv)) { - CRTFREEIF(e_PreHost); - return rv; - } - rv = ParsePreHost(e_PreHost,o_Username,o_Password); - CRTFREEIF(e_PreHost); - if (NS_FAILED(rv)) - return rv; - - rv = ParseAtHost(brk+1, o_Host, o_Port, o_Path); - return rv; - } else { - rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path); - return rv; - } - return NS_OK; -} - -nsresult -nsStdURLParser::ParseAtHost(const char* i_Spec, char* *o_Host, - PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - - int len = PL_strlen(i_Spec); - static const char delimiters[] = ":/?"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - if (!brk) // everything is a host - { - rv = ExtractString((char*)i_Spec, o_Host, len); - return rv; - } - - switch (*brk) - { - case '/' : - case '?' : - // Get the Host, the rest is Path - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPath(brk, o_Path); - return rv; - break; - case ':' : - // Get the Host - rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec)); - if (NS_FAILED(rv)) - return rv; - rv = ParseAtPort(brk+1, o_Port, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsStdURLParser::ParseAtPort(const char* i_Spec, PRInt32 *o_Port, char* *o_Path) -{ - nsresult rv = NS_OK; - static const char delimiters[] = "/?"; //this order is optimized. - char* brk = PL_strpbrk(i_Spec, delimiters); - if (!brk) // everything is a Port - { - *o_Port = ExtractPortFrom(i_Spec); - if (*o_Port <= 0) - return NS_ERROR_MALFORMED_URI; - else - return NS_OK; - } - - switch (*brk) - { - case '/' : - case '?' : - // Get the Port, the rest is Path - *o_Port = ExtractPortFrom(i_Spec); - if (*o_Port <= 0) - return NS_ERROR_MALFORMED_URI; - rv = ParseAtPath(brk, o_Path); - return rv; - break; - default: - NS_ASSERTION(0, "This just can't be!"); - break; - } - return NS_OK; -} - -nsresult -nsStdURLParser::ParseAtPath(const char* i_Spec, char* *o_Path) -{ - // Just write the path and check for a starting / - nsAutoString dir; - if ('/' != *i_Spec) - dir += "/"; - - dir += i_Spec; - - *o_Path = dir.ToNewCString(); - return (*o_Path ? NS_OK : NS_ERROR_OUT_OF_MEMORY); -} - -nsresult -nsStdURLParser::ParseAtDirectory(const char* i_Path, char* *o_Directory, - char* *o_FileBaseName, char* *o_FileExtension, - char* *o_Param, char* *o_Query, char* *o_Ref) -{ - // Cleanout - CRTFREEIF(*o_Directory); - CRTFREEIF(*o_FileBaseName); - CRTFREEIF(*o_FileExtension); - CRTFREEIF(*o_Param); - CRTFREEIF(*o_Query); - CRTFREEIF(*o_Ref); - - nsresult rv = NS_OK; - - // Parse the Path into its components - if (!i_Path) - { - DupString(o_Directory, "/"); - return (o_Directory ? NS_OK : NS_ERROR_OUT_OF_MEMORY); - } - - char* dirfile = nsnull; - char* options = nsnull; - - int len = PL_strlen(i_Path); - - /* Factor out the optionpart with ;?# */ - static const char delimiters[] = ";?#"; // for param, query and ref - char* brk = PL_strpbrk(i_Path, delimiters); - - if (!brk) // Everything is just path and filename - { - DupString(&dirfile, i_Path); - } - else - { - int dirfileLen = brk - i_Path; - ExtractString((char*)i_Path, &dirfile, dirfileLen); - len -= dirfileLen; - ExtractString((char*)i_Path + dirfileLen, &options, len); - brk = options; - } - - /* now that we have broken up the path treat every part differently */ - /* first dir+file */ - - char* file= nsnull; - - int dlen = PL_strlen(dirfile); - if (dlen == 0) - { - DupString(o_Directory, "/"); - file = dirfile; - } else { - CoaleseDirs(dirfile); - // Get length again - dlen = PL_strlen(dirfile); - - // First find the last slash - file = PL_strrchr(dirfile, '/'); - if (!file) - { - DupString(o_Directory, "/"); - file = dirfile; - } - - // If its not the same as the first slash then extract directory - if (file != dirfile) - { - ExtractString(dirfile, o_Directory, (file - dirfile)+1); - } else { - DupString(o_Directory, "/"); - } - } - - /* Extract FileBaseName and FileExtension */ - if (dlen > 0) { - // Look again if there was a slash - char* slash = PL_strrchr(dirfile, '/'); - char* e_FileName = nsnull; - if (slash) { - ExtractString(slash+1, &e_FileName, dlen-(slash-dirfile+1)); - } else { - // Use the full String as Filename - ExtractString(dirfile, &e_FileName, dlen); - } - - rv = ParseFileName(e_FileName,o_FileBaseName,o_FileExtension); - CRTFREEIF(e_FileName); - } - - // Now take a look at the options. "#" has precedence over "?" - // which has precedence over ";" - if (options) { - // Look for "#" first. Everything following it is in the ref - brk = PL_strchr(options, '#'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Ref, pieceLen); - len -= pieceLen + 1; - *brk = '\0'; - } - - // Now look for "?" - brk = PL_strchr(options, '?'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Query, pieceLen); - len -= pieceLen + 1; - } - - // Now look for ';' - brk = PL_strchr(options, ';'); - if (brk) { - int pieceLen = len - (brk + 1 - options); - ExtractString(brk+1, o_Param, pieceLen); - len -= pieceLen + 1; - *brk = '\0'; - } - } - - CRTFREEIF(dirfile); - CRTFREEIF(options); - return rv; -} - -nsresult -nsStdURLParser::ParsePreHost(const char* i_PreHost, char* *o_Username, - char* *o_Password) -{ - nsresult rv = NS_OK; - // Search for : - static const char delimiters[] = ":"; - char* brk = PL_strpbrk(i_PreHost, delimiters); - if (brk) - { - rv = ExtractString((char*)i_PreHost, o_Username, (brk - i_PreHost)); - if (NS_FAILED(rv)) - return rv; - rv = ExtractString(brk+1, o_Password, - (i_PreHost+PL_strlen(i_PreHost) - brk - 1)); - } else { - CRTFREEIF(*o_Password); - rv = DupString(o_Username, i_PreHost); - } - return rv; -} - -nsresult -nsStdURLParser::ParseFileName(const char* i_FileName, char* *o_FileBaseName, - char* *o_FileExtension) -{ - nsresult rv = NS_OK; - // Search for FileExtension - // Search for last . - // Ignore . at the beginning - char* brk = PL_strrchr(i_FileName+1, '.'); - if (brk) - { - rv = ExtractString((char*)i_FileName, o_FileBaseName, - (brk - i_FileName)); - if (NS_FAILED(rv)) - return rv; - rv = ExtractString(brk + 1, o_FileExtension, - (i_FileName+PL_strlen(i_FileName) - brk - 1)); - } else { - rv = DupString(o_FileBaseName, i_FileName); - } - return rv; -} diff --git a/netwerk/base/src/nsStdURLParser.h b/netwerk/base/src/nsStdURLParser.h deleted file mode 100644 index 27a0ad35d509..000000000000 --- a/netwerk/base/src/nsStdURLParser.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsStdURLParser_h__ -#define nsStdURLParser_h__ - -#include "nsIURLParser.h" -#include "nsIURI.h" -#include "nsAgg.h" -#include "nsCRT.h" - -#define NS_STANDARDURLPARSER_CID \ -{ /* dbf72351-4fd8-46f0-9dbc-fa5ba60a30c5 */ \ - 0xdbf72351, \ - 0x4fd8, \ - 0x46f0, \ - {0x9d, 0xbc, 0xfa, 0x5b, 0xa6, 0x0a, 0x30, 0x5c} \ -} - -class nsStdURLParser : public nsIURLParser -{ -public: - NS_DECL_ISUPPORTS - /////////////////////////////////////////////////////////////////////////// - // nsStdURLParser methods: - nsStdURLParser() { - NS_INIT_REFCNT(); - } - virtual ~nsStdURLParser(); - - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - - /////////////////////////////////////////////////////////////////////////// - // nsIURLParser methods: - NS_DECL_NSIURLPARSER - -}; - -#endif // nsStdURLParser_h__ diff --git a/netwerk/base/src/nsURLHelper.cpp b/netwerk/base/src/nsURLHelper.cpp deleted file mode 100644 index d327d179fec6..000000000000 --- a/netwerk/base/src/nsURLHelper.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- 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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Andreas Otte. - * - * Contributor(s): - */ - -#include "nsURLHelper.h" -#include "prprf.h" -#include "nsCRT.h" -#include "nsIAllocator.h" - -/* This array tells which chars has to be escaped */ - -const int EscapeChars[256] = -/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ -{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */ - 0,1023, 0, 512, 0, 0,1023, 0,1023,1023,1023,1023,1023,1023, 959,1016, /* 2x !"#$%&'()*+,-./ */ - 1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896, 896, 0, 896, 0, 768, /* 3x 0123456789:;<=>? */ - 896,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, /* 4x @ABCDEFGHIJKLMNO */ - 1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896, 896, 896, 896,1023, /* 5x PQRSTUVWXYZ[\]^_ */ - 0,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, /* 6x `abcdefghijklmno */ - 1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896,1012, 896,1008, 0, /* 7x pqrstuvwxyz{|}~ */ - 0 /* 8x DEL */ -}; - -/* decode % escaped hex codes into character values - */ -#define UNHEX(C) \ -((C >= '0' && C <= '9') ? C - '0' : \ -((C >= 'A' && C <= 'F') ? C - 'A' + 10 : \ -((C >= 'a' && C <= 'f') ? C - 'a' + 10 : 0))) - -/* check if char has to be escaped */ -#define IS_OK(C) (EscapeChars[((unsigned int) (C))] & (mask)) - -/* HEX mask char */ -#define HEX_ESCAPE '%' - -/* returns an escaped string */ -NS_NET nsresult -nsURLEscape(const char* str, PRInt16 mask, char **result) -{ - if (!str) - return NS_OK; - - int i, extra = 0; - char* hexChars = "0123456789ABCDEF"; - static const char CheckHexChars[] = "0123456789ABCDEFabcdef"; - int len = PL_strlen(str); - - register const unsigned char* src = (const unsigned char *) str; - for (i = 0; i < len; i++) - { - if (!IS_OK(*src++)) { - extra += 2; /* the escape, plus an extra byte for each nibble */ - } - } - - *result = (char *)nsAllocator::Alloc(len + extra + 1); - if (!*result) - return NS_ERROR_OUT_OF_MEMORY; - - register unsigned char* dst = (unsigned char *) *result; - src = (const unsigned char *) str; - - for (i = 0; i < len; i++) - { - const char* checker = (char*) src; - unsigned char c = *src++; - /* if the char has not to be escaped or whatever follows % is - a valid escaped string, just copy the char */ - if (IS_OK(c) || (c == HEX_ESCAPE && (checker+1) && (checker+2) && - PL_strpbrk(((checker+1)), CheckHexChars) != 0 && - PL_strpbrk(((checker+2)), CheckHexChars) != 0)) - *dst++ = c; - else - /* do the escape magic */ - { - *dst++ = HEX_ESCAPE; - *dst++ = hexChars[c >> 4]; /* high nibble */ - *dst++ = hexChars[c & 0x0f]; /* low nibble */ - } - } - *dst = '\0'; - return NS_OK; -} - -/* returns an unescaped string */ -NS_NET nsresult -nsURLUnescape(char* str, char **result) -{ - if (!str) - return NS_OK; - - register char *src = str; - static const char hexChars[] = "0123456789ABCDEF"; - int len = PL_strlen(str); - - *result = (char *)nsAllocator::Alloc(len + 1); - if (!*result) - return NS_ERROR_OUT_OF_MEMORY; - - src = str; - register unsigned char* dst = (unsigned char *) *result; - - while (*src) - /* check for valid escaped sequence */ - if (*src != HEX_ESCAPE || PL_strpbrk(((src+1)), hexChars) == 0 || - PL_strpbrk(((src+2)), hexChars) == 0 ) - *dst++ = *src++; - else - { - src++; /* walk over escape */ - if (*src) - { - *dst = UNHEX(*src) << 4; - src++; - } - if (*src) - { - *dst = (*dst + UNHEX(*src)); - src++; - } - dst++; - } - - *dst = '\0'; - return NS_OK; -} - -/* extract portnumber from string */ -NS_NET PRInt32 -ExtractPortFrom(const char* src) -{ - PRInt32 returnValue = -1; - return (0 < PR_sscanf(src, "%d", &returnValue)) ? returnValue : -1; -} - -/* extract string from other string */ -NS_NET nsresult -ExtractString(char* i_Src, char* *o_Dest, PRUint32 length) -{ - NS_PRECONDITION( (nsnull != i_Src), "Extract called on empty string!"); - CRTFREEIF(*o_Dest); - *o_Dest = PL_strndup(i_Src, length); - return (*o_Dest ? NS_OK : NS_ERROR_OUT_OF_MEMORY); -} - -/* duplicate string */ -NS_NET nsresult -DupString(char* *o_Dest, const char* i_Src) -{ - if (!o_Dest) - return NS_ERROR_NULL_POINTER; - if (i_Src) - { - *o_Dest = nsCRT::strdup(i_Src); - return (*o_Dest == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; - } - else - { - *o_Dest = nsnull; - return NS_OK; - } -} - -// Replace all /./ with a / -// Also changes all \ to / -// But only till #?; -NS_NET void -CoaleseDirs(char* io_Path) -{ - /* Stolen from the old netlib's mkparse.c. - * - * modifies a url of the form /foo/../foo1 -> /foo1 - * and /foo/./foo1 -> /foo/foo1 - * and /foo/foo1/.. -> /foo/ - */ - char *fwdPtr = io_Path; - char *urlPtr = io_Path; - - for(; (*fwdPtr != '\0') && - (*fwdPtr != ';') && - (*fwdPtr != '?') && - (*fwdPtr != '#'); ++fwdPtr) - { - if (*fwdPtr == '\\') - *fwdPtr = '/'; - if (*fwdPtr == '/' && *(fwdPtr+1) == '.' && - (*(fwdPtr+2) == '/' || *(fwdPtr+2) == '\\')) - { - // remove . followed by slash or a backslash - fwdPtr += 1; - } - else if(*fwdPtr == '/' && *(fwdPtr+1) == '.' && *(fwdPtr+2) == '.' && - (*(fwdPtr+3) == '/' || - *(fwdPtr+3) == '\0' || - *(fwdPtr+3) == ';' || // This will take care of likes of - *(fwdPtr+3) == '?' || // foo/bar/..#sometag - *(fwdPtr+3) == '#' || - *(fwdPtr+3) == '\\')) - { - // remove foo/.. - // reverse the urlPtr to the previous slash - if(urlPtr != io_Path) - urlPtr--; // we must be going back at least by one - for(;*urlPtr != '/' && urlPtr != io_Path; urlPtr--) - ; // null body - - // forward the fwd_prt past the ../ - fwdPtr += 2; - // special case if we have reached the end to preserve the last / - if (*fwdPtr == '.' && *(fwdPtr+1) == '\0') - urlPtr +=1; - } - else - { - // copy the url incrementaly - *urlPtr++ = *fwdPtr; - } - } - // Copy remaining stuff past the #?; - for (; *fwdPtr != '\0'; ++fwdPtr) - { - *urlPtr++ = *fwdPtr; - } - *urlPtr = '\0'; // terminate the url - - /* - * Now lets remove trailing . case - * /foo/foo1/. -> /foo/foo1/ - */ - - if ((urlPtr > (io_Path+1)) && (*(urlPtr-1) == '.') && (*(urlPtr-2) == '/')) - *(urlPtr-1) = '\0'; -} diff --git a/netwerk/base/src/nsURLHelper.h b/netwerk/base/src/nsURLHelper.h deleted file mode 100644 index f49ace428739..000000000000 --- a/netwerk/base/src/nsURLHelper.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- 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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Andreas Otte. - * - * Contributor(s): - */ - -#ifndef _nsURLHelper_h_ -#define _nsURLHelper_h_ - -#include "prtypes.h" -#include "nscore.h" -#include "nsCRT.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* encode characters into % escaped hexcodes */ -NS_NET nsresult nsURLEscape (const char* str, PRInt16 mask, char ** result); - -/* decode % escaped hex codes into character values */ -NS_NET nsresult nsURLUnescape(char* str, char ** result); - -/* Get port from string */ -NS_NET PRInt32 ExtractPortFrom(const char* src); - -/* Extract string out of another */ -NS_NET nsresult ExtractString(char* i_Src, char* *o_Dest, PRUint32 length); - -/* Duplicate string */ -NS_NET nsresult DupString(char* *o_Dest, const char* i_Src); - -/* handle .. in dirs */ -NS_NET void CoaleseDirs(char* io_Path); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/netwerk/build/nsNetModule.cpp b/netwerk/build/nsNetModule.cpp index e696404e67a1..c9a54da87d83 100644 --- a/netwerk/build/nsNetModule.cpp +++ b/netwerk/build/nsNetModule.cpp @@ -30,9 +30,6 @@ #include "nsSocketTransportService.h" #include "nsSocketProviderService.h" #include "nscore.h" -#include "nsStdURLParser.h" -#include "nsAuthURLParser.h" -#include "nsNoAuthURLParser.h" #include "nsStdURL.h" #include "nsSimpleURI.h" #include "nsDnsService.h" @@ -101,20 +98,7 @@ static nsModuleComponentInfo gNetModuleInfo[] = { { "Load Group", NS_LOADGROUP_CID, "component://netscape/network/load-group", - nsLoadGroup::Create }, - { "StdURLParser", - NS_STANDARDURLPARSER_CID, - "component://netscape/network/standard-urlparser", - nsStdURLParser::Create }, - { "AuthURLParser", - NS_AUTHORITYURLPARSER_CID, - "component://netscape/network/authority-urlparser", - nsAuthURLParser::Create }, - { "NoAuthURLParser", - NS_NOAUTHORITYURLPARSER_CID, - "component://netscape/network/no-authority-urlparser", - nsNoAuthURLParser::Create }, + nsLoadGroup::Create } }; NS_IMPL_NSGETMODULE("net", gNetModuleInfo) - diff --git a/netwerk/macbuild/netwerk.mcp b/netwerk/macbuild/netwerk.mcp index 0f9821f9b4b4..47b05d09feae 100644 Binary files a/netwerk/macbuild/netwerk.mcp and b/netwerk/macbuild/netwerk.mcp differ diff --git a/netwerk/macbuild/netwerkIDL.mcp b/netwerk/macbuild/netwerkIDL.mcp index 20dfd90c851a..9a077f6823c6 100644 Binary files a/netwerk/macbuild/netwerkIDL.mcp and b/netwerk/macbuild/netwerkIDL.mcp differ diff --git a/netwerk/protocol/file/macbuild/file.mcp b/netwerk/protocol/file/macbuild/file.mcp index 8714ec7d037f..4d0d8545aa24 100644 Binary files a/netwerk/protocol/file/macbuild/file.mcp and b/netwerk/protocol/file/macbuild/file.mcp differ diff --git a/netwerk/protocol/file/src/nsFileProtocolHandler.cpp b/netwerk/protocol/file/src/nsFileProtocolHandler.cpp index 7b52f4f48425..31866b53b034 100644 --- a/netwerk/protocol/file/src/nsFileProtocolHandler.cpp +++ b/netwerk/protocol/file/src/nsFileProtocolHandler.cpp @@ -34,8 +34,7 @@ #include "nsFileSpec.h" #include "nsAutoLock.h" -static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID); -static NS_DEFINE_CID(kNoAuthUrlParserCID, NS_NOAUTHORITYURLPARSER_CID); +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); //////////////////////////////////////////////////////////////////////////////// @@ -104,31 +103,17 @@ nsFileProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, // file: URLs (currently) have no additional structure beyond that provided by standard // URLs, so there is no "outer" given to CreateInstance - nsIURI* url = nsnull; - nsIURLParser* urlparser = nsnull; + nsIURI* url; if (aBaseURI) { rv = aBaseURI->Clone(&url); if (NS_FAILED(rv)) return rv; rv = url->SetRelativePath(aSpec); } else { - rv = nsComponentManager::CreateInstance(kNoAuthUrlParserCID, - nsnull, NS_GET_IID(nsIURLParser), - (void**)&urlparser); + rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, + NS_GET_IID(nsIURI), + (void**)&url); if (NS_FAILED(rv)) return rv; - rv = nsComponentManager::CreateInstance(kStandardUrlCID, - nsnull, NS_GET_IID(nsIURI), - (void**)&url); - if (NS_FAILED(rv)) { - NS_RELEASE(urlparser); - return rv; - } - rv = url->SetURLParser(urlparser); - if (NS_FAILED(rv)) { - NS_RELEASE(urlparser); - NS_RELEASE(url); - return rv; - } rv = url->SetSpec((char*)aSpec); } diff --git a/netwerk/protocol/ftp/macbuild/ftp.mcp b/netwerk/protocol/ftp/macbuild/ftp.mcp index 7afc38701131..e3cbbec95bbc 100644 Binary files a/netwerk/protocol/ftp/macbuild/ftp.mcp and b/netwerk/protocol/ftp/macbuild/ftp.mcp differ diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index 841f5b814831..e2e5f94c117c 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -46,8 +46,7 @@ PRLogModuleInfo* gFTPLog = nsnull; #endif /* PR_LOGGING */ -static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID); -static NS_DEFINE_CID(kAuthUrlParserCID, NS_AUTHORITYURLPARSER_CID); +static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); //////////////////////////////////////////////////////////////////////////////// @@ -131,31 +130,17 @@ nsFtpProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, nsresult rv; PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("FTP attempt at %s ", aSpec)); - nsIURI* url = nsnull; - nsIURLParser* urlparser = nsnull; + nsIURI* url; if (aBaseURI) { rv = aBaseURI->Clone(&url); if (NS_FAILED(rv)) return rv; rv = url->SetRelativePath(aSpec); } else { - rv = nsComponentManager::CreateInstance(kAuthUrlParserCID, - nsnull, NS_GET_IID(nsIURLParser), - (void**)&urlparser); + rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, + NS_GET_IID(nsIURI), + (void**)&url); if (NS_FAILED(rv)) return rv; - rv = nsComponentManager::CreateInstance(kStandardUrlCID, - nsnull, NS_GET_IID(nsIURI), - (void**)&url); - if (NS_FAILED(rv)) { - NS_RELEASE(urlparser); - return rv; - } - rv = url->SetURLParser(urlparser); - if (NS_FAILED(rv)) { - NS_RELEASE(urlparser); - NS_RELEASE(url); - return rv; - } rv = url->SetSpec((char*)aSpec); } if (NS_FAILED(rv)) { diff --git a/netwerk/protocol/http/macbuild/http.mcp b/netwerk/protocol/http/macbuild/http.mcp index 18d650c86ae5..5215100438e8 100644 Binary files a/netwerk/protocol/http/macbuild/http.mcp and b/netwerk/protocol/http/macbuild/http.mcp differ diff --git a/netwerk/protocol/http/src/nsHTTPHandler.cpp b/netwerk/protocol/http/src/nsHTTPHandler.cpp index d8a5351fd406..365aaf2cb205 100644 --- a/netwerk/protocol/http/src/nsHTTPHandler.cpp +++ b/netwerk/protocol/http/src/nsHTTPHandler.cpp @@ -39,7 +39,6 @@ #include "nsHTTPEncodeStream.h" #include "nsHTTPAtoms.h" #include "nsFileSpec.h" - #include "nsIPref.h" // preferences stuff #ifdef DEBUG_gagan #include "nsUnixColorPrintf.h" @@ -64,7 +63,6 @@ PRLogModuleInfo* gHTTPLog = nsnull; #define MAX_NUMBER_OF_OPEN_TRANSPORTS 8 static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID); -static NS_DEFINE_CID(kAuthUrlParserCID, NS_AUTHORITYURLPARSER_CID); static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); @@ -266,7 +264,6 @@ nsHTTPHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, nsresult rv; nsIURI* url = nsnull; - nsIURLParser* urlparser = nsnull; if (aBaseURI) { rv = aBaseURI->Clone(&url); @@ -275,23 +272,10 @@ nsHTTPHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, } else { - rv = nsComponentManager::CreateInstance(kAuthUrlParserCID, - nsnull, NS_GET_IID(nsIURLParser), - (void**)&urlparser); - if (NS_FAILED(rv)) return rv; rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURI), (void**)&url); - if (NS_FAILED(rv)) { - NS_RELEASE(urlparser); - return rv; - } - rv = url->SetURLParser(urlparser); - if (NS_FAILED(rv)) { - NS_RELEASE(urlparser); - NS_RELEASE(url); - return rv; - } + if (NS_FAILED(rv)) return rv; rv = url->SetSpec((char*)aSpec); } if (NS_FAILED(rv)) { diff --git a/netwerk/protocol/jar/src/nsJARURI.cpp b/netwerk/protocol/jar/src/nsJARURI.cpp index 77e8a5ad7b12..74804bb673c6 100644 --- a/netwerk/protocol/jar/src/nsJARURI.cpp +++ b/netwerk/protocol/jar/src/nsJARURI.cpp @@ -157,30 +157,6 @@ nsJARURI::SetPreHost(const char * aPreHost) return NS_ERROR_FAILURE; } -NS_IMETHODIMP -nsJARURI::GetUsername(char * *aUsername) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::SetUsername(const char * aUsername) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::GetPassword(char * *aPassword) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::SetPassword(const char * aPassword) -{ - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsJARURI::GetHost(char * *aHost) { @@ -217,18 +193,6 @@ nsJARURI::SetPath(const char * aPath) return NS_ERROR_FAILURE; } -NS_IMETHODIMP -nsJARURI::GetURLParser(nsIURLParser * *aURLParser) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsJARURI::SetURLParser(nsIURLParser * aURLParser) -{ - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsJARURI::Equals(nsIURI *other, PRBool *_retval) { diff --git a/netwerk/protocol/res/src/nsResChannel.cpp b/netwerk/protocol/res/src/nsResChannel.cpp index 08c360783461..ac0fa42318f5 100644 --- a/netwerk/protocol/res/src/nsResChannel.cpp +++ b/netwerk/protocol/res/src/nsResChannel.cpp @@ -121,7 +121,7 @@ nsResChannel::Substitutions::Init() NS_ASSERTION(mSubstitutions == nsnull, "failed to call destructor"); - char* root = nsnull; + char* root; rv = channel->mResourceURI->GetHost(&root); if (NS_SUCCEEDED(rv)) { rv = channel->mHandler->GetSubstitutions(root, &mSubstitutions); diff --git a/rdf/base/src/nsRDFXMLDataSource.cpp b/rdf/base/src/nsRDFXMLDataSource.cpp index e685e8845c9d..6cd05c148814 100644 --- a/rdf/base/src/nsRDFXMLDataSource.cpp +++ b/rdf/base/src/nsRDFXMLDataSource.cpp @@ -637,7 +637,7 @@ static const char kResourceURIPrefix[] = "resource:"; // XXX this is a hack: any "file:" URI is considered writable. All // others are considered read-only. - char* realURL = nsnull; + char* realURL; mURL->GetSpec(&realURL); if ((PL_strncmp(realURL, kFileURIPrefix, sizeof(kFileURIPrefix) - 1) != 0) && (PL_strncmp(realURL, kResourceURIPrefix, sizeof(kResourceURIPrefix) - 1) != 0)) {