From 0dcbc6fdb8b1c7256a50a85118e63e682a4319be Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Thu, 14 Jun 2007 03:14:51 +0000 Subject: [PATCH] Bug #379070 --> remove nsCRT methods from mailnews\news. Patch by Frank Wein sr=neil --- mailnews/news/build/nsMsgNewsFactory.cpp | 1 - mailnews/news/src/nsNNTPNewsgroupList.cpp | 1 - mailnews/news/src/nsNNTPProtocol.cpp | 26 ++++------ .../news/src/nsNewsDownloadDialogArgs.cpp | 1 - mailnews/news/src/nsNntpIncomingServer.cpp | 2 +- mailnews/news/src/nsNntpService.cpp | 52 +++++-------------- mailnews/news/src/nsNntpUrl.cpp | 1 - 7 files changed, 25 insertions(+), 59 deletions(-) diff --git a/mailnews/news/build/nsMsgNewsFactory.cpp b/mailnews/news/build/nsMsgNewsFactory.cpp index 9ee759eb16c..a73a6f6ca4b 100644 --- a/mailnews/news/build/nsMsgNewsFactory.cpp +++ b/mailnews/news/build/nsMsgNewsFactory.cpp @@ -44,7 +44,6 @@ #include "pratom.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" -#include "nsCRT.h" #include "nsCOMPtr.h" #include "nsNewsFolder.h" diff --git a/mailnews/news/src/nsNNTPNewsgroupList.cpp b/mailnews/news/src/nsNNTPNewsgroupList.cpp index 4da7b3b2b64..c42a37a1b48 100644 --- a/mailnews/news/src/nsNNTPNewsgroupList.cpp +++ b/mailnews/news/src/nsNNTPNewsgroupList.cpp @@ -72,7 +72,6 @@ #include "prmem.h" #include "prprf.h" -#include "nsCRT.h" #include "nsMsgUtils.h" #include "nsMsgDatabase.h" diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 681fd844c9c..7e242b6cb32 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -66,8 +66,6 @@ #include "nsINntpUrl.h" -#include "nsCRT.h" - #include "prtime.h" #include "prlog.h" #include "prerror.h" @@ -1359,9 +1357,9 @@ nsNNTPProtocol::ParseURL(nsIURI * aURL, char ** aGroup, char ** aMessageID, PR_LOG(NNTP,PR_LOG_ALWAYS,("(%p) fullPath = %s",this, fullPath.get())); if (fullPath.First() == '/') - group = nsCRT::strdup(fullPath.get()+1); + group = NS_strdup(fullPath.get()+1); else - group = nsCRT::strdup(fullPath.get()); + group = ToNewCString(fullPath); // more to do here, but for now, this works. // only escape if we are doing a search @@ -1369,11 +1367,11 @@ nsNNTPProtocol::ParseURL(nsIURI * aURL, char ** aGroup, char ** aMessageID, nsUnescape(group); } else if (strchr(group, '@') || strstr(group,"%40")) { - message_id = nsUnescape(group); + message_id = nsUnescape(group); group = 0; } - else if (!*group) { - nsCRT::free(group); + else if (!*group) { + NS_Free(group); group = 0; } @@ -1400,13 +1398,13 @@ nsNNTPProtocol::ParseURL(nsIURI * aURL, char ** aGroup, char ** aMessageID, break; if (*s) { - command_specific_data = nsCRT::strdup (s); + command_specific_data = NS_strdup(s); *s = 0; if (!command_specific_data) { status = MK_OUT_OF_MEMORY; goto FAIL; } - } + } /* Discard any now-empty strings. */ if (message_id && !*message_id) { @@ -1848,7 +1846,7 @@ PRInt32 nsNNTPProtocol::GetPropertiesResponse(nsIInputStream * inputStream, PRUi if ('.' != line[0]) { - char *propertyName = nsCRT::strdup(line); + char *propertyName = NS_strdup(line); if (propertyName) { char *space = PL_strchr(propertyName, ' '); @@ -2565,7 +2563,7 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt /* Don't send content-type to mime parser if we're doing a cancel because it confuses mime parser into not parsing. */ - if (m_typeWanted != CANCEL_WANTED || nsCRT::strncmp(outputBuffer, "Content-Type:", 13)) + if (m_typeWanted != CANCEL_WANTED || strncmp(outputBuffer, "Content-Type:", 13)) { // if we are attempting to cancel, we want to snarf the headers and save the aside, which is what // ParseHeaderForCancel() does. @@ -3138,13 +3136,11 @@ PRInt32 nsNNTPProtocol::ReadNewsList(nsIInputStream * inputStream, PRUint32 leng char rate_buf[RATE_STR_BUF_LEN]; PR_snprintf(rate_buf,RATE_STR_BUF_LEN,"%.1f", rate); - nsAutoString rateStr; - rateStr.Append(NS_ConvertASCIItoUTF16(rate_buf)); - nsAutoString numGroupsStr; numGroupsStr.AppendInt(mNumGroupsListed); + NS_ConvertASCIItoUTF16 rateStr(rate_buf); - const PRUnichar *formatStrings[3] = { numGroupsStr.get(), bytesStr.get(), rateStr.get() }; + const PRUnichar *formatStrings[3] = { numGroupsStr.get(), bytesStr.get(), rateStr.get()}; rv = bundle->FormatStringFromName(NS_LITERAL_STRING("bytesReceived").get(), formatStrings, 3, getter_Copies(statusString)); diff --git a/mailnews/news/src/nsNewsDownloadDialogArgs.cpp b/mailnews/news/src/nsNewsDownloadDialogArgs.cpp index fa57cb78d4d..d1629a34f3c 100644 --- a/mailnews/news/src/nsNewsDownloadDialogArgs.cpp +++ b/mailnews/news/src/nsNewsDownloadDialogArgs.cpp @@ -37,7 +37,6 @@ * ***** END LICENSE BLOCK ***** */ #include "nsNewsDownloadDialogArgs.h" -#include "nsCRT.h" #include "nsReadableUtils.h" nsNewsDownloadDialogArgs::nsNewsDownloadDialogArgs() diff --git a/mailnews/news/src/nsNntpIncomingServer.cpp b/mailnews/news/src/nsNntpIncomingServer.cpp index 9b0352b2eca..7f6fe619c56 100644 --- a/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mailnews/news/src/nsNntpIncomingServer.cpp @@ -1252,7 +1252,7 @@ nsNntpIncomingServer::HandleLine(const char* line, PRUint32 line_size) } } else { - if (nsCRT::strncmp(line,"begingroups", 11) == 0) { + if (strncmp(line,"begingroups", 11) == 0) { mHasSeenBeginGroups = PR_TRUE; } char*equalPos = (char *) PL_strchr(line, '='); diff --git a/mailnews/news/src/nsNntpService.cpp b/mailnews/news/src/nsNntpService.cpp index fb2a924103a..37eb07972c9 100644 --- a/mailnews/news/src/nsNntpService.cpp +++ b/mailnews/news/src/nsNntpService.cpp @@ -57,7 +57,6 @@ #include "nsMsgBaseCID.h" #include "nsIPrefBranch.h" #include "nsIPrefService.h" -#include "nsCRT.h" // for nsCRT::strtok #include "nsNntpService.h" #include "nsIChannel.h" #include "nsILoadGroup.h" @@ -225,7 +224,7 @@ nsNntpService::CreateMessageIDURL(nsIMsgFolder *folder, nsMsgKey key, char **url uri = rootFolderURI.get(); uri += '/'; uri += escapedMessageID; - *url = nsCRT::strdup(uri.get()); + *url = ToNewCString(uri); PR_FREEIF(escapedMessageID); @@ -509,7 +508,7 @@ nsNntpService::DecomposeNewsURI(const char *uri, nsIMsgFolder **folder, nsMsgKey { nsresult rv; // if we fix DecomposeNewsMessage to handle news message scheme, we could use it exclusively - if (nsCRT::strncmp(uri, kNewsMessageRootURI, kNewsMessageRootURILen) == 0) + if (strncmp(uri, kNewsMessageRootURI, kNewsMessageRootURILen) == 0) { rv = DecomposeNewsMessageURI(uri, folder, aMsgKey); NS_ENSURE_SUCCESS(rv,rv); @@ -796,42 +795,33 @@ nsNntpService::GenerateNewsHeaderValsForPosting(const char *newsgroupsList, char // we are not going to allow the user to cross post to multiple hosts. // if we detect that, we stop and return error. - // nsCRT::strtok is going destroy what we pass to it, so we need to make a copy of newsgroupsNames. - char *list = nsCRT::strdup(newsgroupsList); - char *token = nsnull; - char *rest = list; nsCAutoString host; nsCAutoString str; nsCAutoString newsgroups; - token = nsCRT::strtok(rest, ",", &rest); - while (token && *token) + nsCStringArray list; + list.ParseString(newsgroupsList, ","); + for (PRInt32 index = 0; index < list.Count(); index++) { - str = token; - str.StripWhitespace(); - - if (!str.IsEmpty()) + list[index]->StripWhitespace(); + if (!list[index]->IsEmpty()) { nsCAutoString currentHost; nsCAutoString theRest; - // does str start with "news:/"? - if (str.Find(kNewsRootURI) == 0) + if (StringBeginsWith(*list[index], NS_LITERAL_CSTRING(kNewsRootURI))) { // we have news://group or news://host/group // set theRest to what's after news:// - str.Right(theRest, str.Length() - kNewsRootURILen /* for news:/ */ - 1 /* for the slash */); + list[index]->Right(theRest, list[index]->Length() - kNewsRootURILen /* for news:/ */ - 1 /* for the slash */); } - else if (str.Find(":/") != -1) + else if (list[index]->Find(":/") != -1) { // we have x:/y where x != news. this is bad, return failure - CRTFREEIF(list); return NS_ERROR_FAILURE; } else - { - theRest = str; - } + theRest = *list[index]; // theRest is "group" or "host/group" PRInt32 slashpos = theRest.FindChar('/'); @@ -847,10 +837,7 @@ nsNntpService::GenerateNewsHeaderValsForPosting(const char *newsgroupsList, char NS_ASSERTION(!currentGroup.IsEmpty(), "currentGroup is empty"); if (currentGroup.IsEmpty()) - { - CRTFREEIF(list); return NS_ERROR_FAILURE; - } // build up the newsgroups if (!newsgroups.IsEmpty()) @@ -862,39 +849,26 @@ nsNntpService::GenerateNewsHeaderValsForPosting(const char *newsgroupsList, char // str is "group" rv = FindHostFromGroup(currentHost, str); if (NS_FAILED(rv)) - { - CRTFREEIF(list); return rv; - } - // build up the newsgroups if (!newsgroups.IsEmpty()) newsgroups += ","; - newsgroups += str; + newsgroups += *list[index]; } if (!currentHost.IsEmpty()) { if (host.IsEmpty()) - { host = currentHost; - } else { if (!host.Equals(currentHost)) - { - CRTFREEIF(list); return NS_ERROR_NNTP_NO_CROSS_POSTING; - } } } - - str = ""; currentHost = ""; } - token = nsCRT::strtok(rest, ",", &rest); } - CRTFREEIF(list); *newshostHeaderVal = ToNewCString(host); if (!*newshostHeaderVal) return NS_ERROR_OUT_OF_MEMORY; @@ -1248,7 +1222,7 @@ NS_IMETHODIMP nsNntpService::GetNewNews(nsINntpIncomingServer *nntpServer, const server = do_QueryInterface(nntpServer); /* double check that it is a "news:/" url */ - if (nsCRT::strncmp(uri, kNewsRootURI, kNewsRootURILen) == 0) + if (strncmp(uri, kNewsRootURI, kNewsRootURILen) == 0) { nsCOMPtr aUrl; rv = ConstructNntpUrl(uri, aUrlListener, aMsgWindow, nsnull, nsINntpUrl::ActionGetNewNews, getter_AddRefs(aUrl)); diff --git a/mailnews/news/src/nsNntpUrl.cpp b/mailnews/news/src/nsNntpUrl.cpp index ee1818da13a..9144ab92bad 100644 --- a/mailnews/news/src/nsNntpUrl.cpp +++ b/mailnews/news/src/nsNntpUrl.cpp @@ -48,7 +48,6 @@ #include "prmem.h" #include "plstr.h" #include "prprf.h" -#include "nsCRT.h" #include "nsNewsUtils.h" #include "nsISupportsObsolete.h"