final patch for bug 109179 "replace nsStdEscape with NS_EscapeURL"

r=dougt, sr=alecf
This commit is contained in:
darin%netscape.com 2002-02-05 03:08:15 +00:00
parent d3a61dde4e
commit 96d9e2d527
6 changed files with 145 additions and 150 deletions

View File

@ -629,15 +629,14 @@ nsMsgFolder::parseURI(PRBool needServer)
if (mName.IsEmpty()) { if (mName.IsEmpty()) {
// mName: // mName:
// the name is the trailing directory in the path // the name is the trailing directory in the path
nsXPIDLCString fileName; char *fileName = nsnull;
rv = url->GetFileName(getter_Copies(fileName)); url->GetFileName(&fileName);
if (NS_SUCCEEDED(rv) && (const char*)fileName != nsnull) { if (fileName) {
// XXX conversion to unicode here? is fileName in UTF8? // XXX conversion to unicode here? is fileName in UTF8?
// yes, let's say it is in utf8 // yes, let's say it is in utf8
NS_UnescapeURL(fileName);
nsXPIDLCString result; mName = NS_ConvertUTF8toUCS2(fileName);
rv = nsStdUnescape((char*)fileName.get(), getter_Copies(result)); nsMemory::Free(fileName);
mName.AssignWithConversion(result);
} }
} }
@ -689,22 +688,24 @@ nsMsgFolder::parseURI(PRBool needServer)
// now try to find the local path for this folder // now try to find the local path for this folder
if (server) { if (server) {
nsXPIDLCString urlPath;
url->GetFilePath(getter_Copies(urlPath));
nsXPIDLCString result;
rv = nsStdUnescape((char*)urlPath.get(), getter_Copies(result));
// transform the filepath from the URI, such as
// "/folder1/folder2/foldern"
// to
// "folder1.sbd/folder2.sbd/foldern"
// (remove leading / and add .sbd to first n-1 folders)
// to be appended onto the server's path
nsCAutoString newPath; nsCAutoString newPath;
NS_MsgCreatePathStringFromFolderURI(result, newPath);
char *urlPath = nsnull;
url->GetFilePath(&urlPath);
if (urlPath) {
NS_UnescapeURL(urlPath);
// transform the filepath from the URI, such as
// "/folder1/folder2/foldern"
// to
// "folder1.sbd/folder2.sbd/foldern"
// (remove leading / and add .sbd to first n-1 folders)
// to be appended onto the server's path
NS_MsgCreatePathStringFromFolderURI(urlPath, newPath);
nsMemory::Free(urlPath);
}
// now append munged path onto server path // now append munged path onto server path
nsCOMPtr<nsIFileSpec> serverPath; nsCOMPtr<nsIFileSpec> serverPath;

View File

@ -1545,28 +1545,24 @@ QuotingOutputStreamListener::QuotingOutputStreamListener(const char * originalMs
if (! mHeadersOnly) if (! mHeadersOnly)
{ {
nsXPIDLString replyHeaderOriginalmessage; nsXPIDLString replyHeaderOriginalmessage;
// For the built message body... // For the built message body...
nsCOMPtr <nsIMsgDBHdr> originalMsgHdr; nsCOMPtr <nsIMsgDBHdr> originalMsgHdr;
rv = GetMsgDBHdrFromURI(originalMsgURI, getter_AddRefs(originalMsgHdr)); rv = GetMsgDBHdrFromURI(originalMsgURI, getter_AddRefs(originalMsgHdr));
if (NS_SUCCEEDED(rv) && originalMsgHdr && !quoteHeaders) if (NS_SUCCEEDED(rv) && originalMsgHdr && !quoteHeaders)
{ {
// Setup the cite information.... // Setup the cite information....
nsXPIDLCString myGetter; nsXPIDLCString myGetter;
if (NS_SUCCEEDED(originalMsgHdr->GetMessageId(getter_Copies(myGetter)))) if (NS_SUCCEEDED(originalMsgHdr->GetMessageId(getter_Copies(myGetter))))
{ {
nsCString unencodedURL(myGetter); if (!myGetter.IsEmpty())
// would be nice, if nsXPIDL*String were ns*String
nsCAutoString encodedURL;
if (!unencodedURL.IsEmpty() && NS_SUCCEEDED(rv))
{ {
if (NS_SUCCEEDED(nsStdEscape(unencodedURL.get(), const char *escapedMessageId;
esc_FileBaseName | esc_Forced, encodedURL ))) nsCAutoString buf;
{ if (NS_EscapeURLPart(myGetter.get(), myGetter.Length(), esc_FileBaseName | esc_Forced, buf))
mCiteReference = NS_LITERAL_STRING("mid:"); escapedMessageId = buf.get();
mCiteReference.AppendWithConversion(encodedURL.get());
}
else else
mCiteReference.Truncate(); escapedMessageId = myGetter.get();
mCiteReference = NS_LITERAL_STRING("mid") + NS_ConvertASCIItoUCS2(escapedMessageId);
} }
} }

View File

@ -83,138 +83,140 @@ NS_IMPL_ISUPPORTS_INHERITED2(nsMsgMailboxParser, nsParseMailMessageState, nsIStr
NS_IMETHODIMP nsMsgMailboxParser::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, nsIInputStream *aIStream, PRUint32 sourceOffset, NS_IMETHODIMP nsMsgMailboxParser::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, nsIInputStream *aIStream, PRUint32 sourceOffset,
PRUint32 aLength) PRUint32 aLength)
{ {
// right now, this really just means turn around and process the url // right now, this really just means turn around and process the url
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIURI> url = do_QueryInterface(ctxt, &rv); nsCOMPtr<nsIURI> url = do_QueryInterface(ctxt, &rv);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
rv = ProcessMailboxInputStream(url, aIStream, aLength); rv = ProcessMailboxInputStream(url, aIStream, aLength);
return rv; return rv;
} }
NS_IMETHODIMP nsMsgMailboxParser::OnStartRequest(nsIRequest *request, nsISupports *ctxt) NS_IMETHODIMP nsMsgMailboxParser::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
{ {
nsTime currentTime; nsTime currentTime;
m_startTime = currentTime; m_startTime = currentTime;
// extract the appropriate event sinks from the url and initialize them in our protocol data // extract the appropriate event sinks from the url and initialize them in our protocol data
// the URL should be queried for a nsIMailboxURL. If it doesn't support a mailbox URL interface then // the URL should be queried for a nsIMailboxURL. If it doesn't support a mailbox URL interface then
// we have an error. // we have an error.
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIIOService> ioServ(do_GetService(kIOServiceCID, &rv)); nsCOMPtr<nsIIOService> ioServ(do_GetService(kIOServiceCID, &rv));
nsCOMPtr<nsIMailboxUrl> runningUrl = do_QueryInterface(ctxt, &rv); nsCOMPtr<nsIMailboxUrl> runningUrl = do_QueryInterface(ctxt, &rv);
nsCOMPtr<nsIMsgMailNewsUrl> url = do_QueryInterface(ctxt); nsCOMPtr<nsIMsgMailNewsUrl> url = do_QueryInterface(ctxt);
if (NS_SUCCEEDED(rv) && runningUrl) if (NS_SUCCEEDED(rv) && runningUrl)
{ {
url->GetStatusFeedback(getter_AddRefs(m_statusFeedback)); url->GetStatusFeedback(getter_AddRefs(m_statusFeedback));
// okay, now fill in our event sinks...Note that each getter ref counts before // okay, now fill in our event sinks...Note that each getter ref counts before
// it returns the interface to us...we'll release when we are done // it returns the interface to us...we'll release when we are done
nsXPIDLCString fileName;
nsXPIDLCString folderName; char *fileName = nsnull; // may be shortened by NS_UnescapeURL
rv = url->GetFilePath(getter_Copies(fileName)); url->GetFilePath(&fileName);
url->GetFileName(getter_Copies(folderName));
nsXPIDLCString tempfolder; char *folderName = nsnull; // may be shortened by NS_UnescapeURL
rv = nsStdUnescape((char*)folderName.get(), getter_Copies(tempfolder)); url->GetFileName(&folderName);
if (folderName)
{
NS_UnescapeURL(folderName);
// convert from OS native charset to unicode // convert from OS native charset to unicode
rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), tempfolder, m_folderName); rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), folderName, m_folderName);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
m_folderName.AssignWithConversion(tempfolder); m_folderName.AssignWithConversion(folderName);
if (fileName) nsMemory::Free(folderName);
{ }
char* result = nsnull;
rv = nsStdUnescape((char*)fileName.get(), &result);
nsFilePath dbPath(result);
CRTFREEIF(result);
nsFileSpec dbName(dbPath);
// the size of the mailbox file is our total base line for measuring progress if (fileName)
m_graph_progress_total = dbName.GetFileSize(); {
UpdateStatusText(LOCAL_STATUS_SELECTING_MAILBOX); NS_UnescapeURL(fileName);
nsFilePath dbPath(fileName);
nsCOMPtr<nsIMsgDatabase> mailDB; nsFileSpec dbName(dbPath);
rv = nsComponentManager::CreateInstance(kCMailDB, nsnull, NS_GET_IID(nsIMsgDatabase), (void **) getter_AddRefs(mailDB));
if (NS_SUCCEEDED(rv) && mailDB) // the size of the mailbox file is our total base line for measuring progress
{ m_graph_progress_total = dbName.GetFileSize();
nsCOMPtr <nsIFileSpec> dbFileSpec; UpdateStatusText(LOCAL_STATUS_SELECTING_MAILBOX);
NS_NewFileSpecWithSpec(dbName, getter_AddRefs(dbFileSpec));
rv = mailDB->Open(dbFileSpec, PR_TRUE, PR_TRUE, (nsIMsgDatabase **) getter_AddRefs(m_mailDB)); nsCOMPtr<nsIMsgDatabase> mailDB;
if (m_mailDB) rv = nsComponentManager::CreateInstance(kCMailDB, nsnull, NS_GET_IID(nsIMsgDatabase), (void **) getter_AddRefs(mailDB));
m_mailDB->AddListener(this); if (NS_SUCCEEDED(rv) && mailDB)
} {
NS_ASSERTION(m_mailDB, "failed to open mail db parsing folder"); nsCOMPtr <nsIFileSpec> dbFileSpec;
NS_NewFileSpecWithSpec(dbName, getter_AddRefs(dbFileSpec));
rv = mailDB->Open(dbFileSpec, PR_TRUE, PR_TRUE, (nsIMsgDatabase **) getter_AddRefs(m_mailDB));
if (m_mailDB)
m_mailDB->AddListener(this);
}
NS_ASSERTION(m_mailDB, "failed to open mail db parsing folder");
#ifdef DEBUG_mscott #ifdef DEBUG_mscott
printf("url file = %s\n", (const char *)fileName); printf("url file = %s\n", fileName);
#endif #endif
} nsMemory::Free(fileName);
} }
}
// need to get the mailbox name out of the url and call SetMailboxName with it.
// then, we need to open the mail db for this parser.
return rv;
// need to get the mailbox name out of the url and call SetMailboxName with it.
// then, we need to open the mail db for this parser.
return rv;
} }
// stop binding is a "notification" informing us that the stream associated with aURL is going away. // stop binding is a "notification" informing us that the stream associated with aURL is going away.
NS_IMETHODIMP nsMsgMailboxParser::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus) NS_IMETHODIMP nsMsgMailboxParser::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus)
{ {
DoneParsingFolder(aStatus); DoneParsingFolder(aStatus);
// what can we do? we can close the stream? // what can we do? we can close the stream?
m_urlInProgress = PR_FALSE; // don't close the connection...we may be re-using it. m_urlInProgress = PR_FALSE; // don't close the connection...we may be re-using it.
if (m_mailDB) if (m_mailDB)
m_mailDB->RemoveListener(this); m_mailDB->RemoveListener(this);
// and we want to mark ourselves for deletion or some how inform our protocol manager that we are // and we want to mark ourselves for deletion or some how inform our protocol manager that we are
// available for another url if there is one.... // available for another url if there is one....
#ifdef DEBUG1 #ifdef DEBUG1
// let's dump out the contents of our db, if possible. // let's dump out the contents of our db, if possible.
if (m_mailDB) if (m_mailDB)
{ {
nsMsgKeyArray keys; nsMsgKeyArray keys;
nsCAutoString author; nsCAutoString author;
nsCAutoString subject; nsCAutoString subject;
// m_mailDB->PrePopulate(); // m_mailDB->PrePopulate();
m_mailDB->ListAllKeys(keys); m_mailDB->ListAllKeys(keys);
PRUint32 size = keys.GetSize(); PRUint32 size = keys.GetSize();
for (PRUint32 keyindex = 0; keyindex < size; keyindex++) for (PRUint32 keyindex = 0; keyindex < size; keyindex++)
{ {
nsCOMPtr<nsIMsgDBHdr> msgHdr; nsCOMPtr<nsIMsgDBHdr> msgHdr;
nsresult ret = nsresult ret =
m_mailDB->GetMsgHdrForKey(keys[keyindex], m_mailDB->GetMsgHdrForKey(keys[keyindex],
getter_AddRefs(msgHdr)); getter_AddRefs(msgHdr));
if (NS_SUCCEEDED(ret) && msgHdr) if (NS_SUCCEEDED(ret) && msgHdr)
{ {
nsMsgKey key; nsMsgKey key;
msgHdr->GetMessageKey(&key); msgHdr->GetMessageKey(&key);
msgHdr->GetAuthor(&author); msgHdr->GetAuthor(&author);
msgHdr->GetSubject(&subject); msgHdr->GetSubject(&subject);
#ifdef DEBUG_bienvenu #ifdef DEBUG_bienvenu
// leak nsString return values... // leak nsString return values...
printf("hdr key = %d, author = %s subject = %s\n", key, author.get(), subject.get()); printf("hdr key = %d, author = %s subject = %s\n", key, author.get(), subject.get());
#endif #endif
} }
} }
m_mailDB->Close(PR_TRUE); m_mailDB->Close(PR_TRUE);
} }
#endif #endif
// be sure to clear any status text and progress info.. // be sure to clear any status text and progress info..
m_graph_progress_received = 0; m_graph_progress_received = 0;
UpdateProgressPercent(); UpdateProgressPercent();
UpdateStatusText(LOCAL_STATUS_DOCUMENT_DONE); UpdateStatusText(LOCAL_STATUS_DOCUMENT_DONE);
return NS_OK;
return NS_OK;
} }

View File

@ -1860,19 +1860,18 @@ nsFtpState::Init(nsIFTPChannel* aChannel,
rv = aURL->GetFilePath(&path); rv = aURL->GetFilePath(&path);
else else
rv = mURL->GetPath(&path); rv = mURL->GetPath(&path);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// Skip leading slash // Skip leading slash
char* fwdPtr= NS_CONST_CAST(char*, path); char* fwdPtr= path;
if (fwdPtr && (*fwdPtr == '/')) if (fwdPtr && (*fwdPtr == '/'))
fwdPtr++; fwdPtr++;
if (*fwdPtr != '\0') { if (*fwdPtr != '\0') {
// now unescape it // now unescape it... %xx reduced inline to resulting character
char *unescPath = nsnull; NS_UnescapeURL(fwdPtr);
nsStdUnescape(fwdPtr,&unescPath); mPath.Assign(fwdPtr);
nsMemory::Free(path);
mPath.Adopt(unescPath);
} }
nsMemory::Free(path);
// pull any username and/or password out of the uri // pull any username and/or password out of the uri
nsXPIDLCString uname; nsXPIDLCString uname;

View File

@ -201,7 +201,7 @@ private:
nsCOMPtr<nsIURI> mURL; // the uri we're connecting to nsCOMPtr<nsIURI> mURL; // the uri we're connecting to
PRInt32 mPort; // the port to connect to PRInt32 mPort; // the port to connect to
nsAutoString mFilename; // url filename (if any) nsAutoString mFilename; // url filename (if any)
nsXPIDLCString mPath; // the url's path nsCString mPath; // the url's path
nsCString mPwd; // login Path nsCString mPwd; // login Path
// ****** other vars // ****** other vars

View File

@ -900,16 +900,13 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel)
{ {
// try to extract the file name from the url and use that as a first pass as the // try to extract the file name from the url and use that as a first pass as the
// leaf name of our temp file... // leaf name of our temp file...
nsXPIDLCString leafName; char *leafName = nsnull; // may be shortened by NS_UnescapeURL
url->GetFileName(getter_Copies(leafName)); url->GetFileName(&leafName);
if (leafName.get()) if (leafName)
{ {
nsXPIDLCString unescapedFileName; NS_UnescapeURL(leafName);
rv = nsStdUnescape((char*)leafName.get(), getter_Copies(unescapedFileName)); mSuggestedFileName = NS_ConvertUTF8toUCS2(leafName);
if (NS_SUCCEEDED(rv)) nsMemory::Free(leafName);
mSuggestedFileName.Assign(NS_ConvertUTF8toUCS2(unescapedFileName));
else
mSuggestedFileName.AssignWithConversion(leafName);
} }
} }