Bug 476150 Move more ParseString users from nsCStringArray to nsTArray<nsCString> r=Standard8 sr=bienvenu

This commit is contained in:
Neil Rashbrook 2009-03-02 16:41:22 +00:00
Родитель fab6840789
Коммит 3de383ee7a
6 изменённых файлов: 102 добавлений и 205 удалений

Просмотреть файл

@ -104,7 +104,7 @@
#define SERVER_PREFIX "server"
#define ID_PREFIX "id"
#define ABOUT_TO_GO_OFFLINE_TOPIC "network:offline-about-to-go-offline"
#define ACCOUNT_DELIMITER ","
#define ACCOUNT_DELIMITER ','
#define APPEND_ACCOUNTS_VERSION_PREF_NAME "append_preconfig_accounts.version"
#define MAILNEWS_ROOT_PREF "mailnews."
#define PREF_MAIL_ACCOUNTMANAGER_APPEND_ACCOUNTS "mail.accountmanager.appendaccounts"
@ -1258,30 +1258,26 @@ nsMsgAccountManager::LoadAccounts()
// Get a list of pre-configured accounts
nsCString appendAccountList;
rv = m_prefs->GetCharPref(PREF_MAIL_ACCOUNTMANAGER_APPEND_ACCOUNTS, getter_Copies(appendAccountList));
appendAccountList.StripWhitespace();
// If there are pre-configured accounts, we need to add them to the existing list.
if (!appendAccountList.IsEmpty()) {
if (!accountList.IsEmpty()) {
nsCStringArray existingAccountsArray;
ParseString(accountList.get(), ACCOUNT_DELIMITER, existingAccountsArray);
// Tokenize the data and add each account if it is not already there
// Tokenize the data and add each account
// in the user's current mailnews account list
char *newAccountStr = appendAccountList.BeginWriting();
char *token = NS_strtok(ACCOUNT_DELIMITER, &newAccountStr);
nsTArray<nsCString> accountsArray;
ParseString(accountList, ACCOUNT_DELIMITER, accountsArray);
PRUint32 i = accountsArray.Length();
nsCAutoString newAccount;
while (token) {
if (token && *token) {
newAccount.Assign(token);
newAccount.StripWhitespace();
// Append each account in the pre-configured account list
ParseString(appendAccountList, ACCOUNT_DELIMITER, accountsArray);
if (existingAccountsArray.IndexOf(newAccount) == -1) {
accountList.Append(',');
accountList.Append(newAccount);
}
// Now add each account that does not already appear in the list
for (; i < accountsArray.Length(); i++) {
if (accountsArray.IndexOf(accountsArray[i]) == i) {
accountList.Append(',');
accountList.Append(accountsArray[i]);
}
token = NS_strtok(ACCOUNT_DELIMITER, &newAccountStr);
}
}
else {

Просмотреть файл

@ -1862,24 +1862,6 @@ NS_MSG_BASE nsresult MsgGetHeadersFromKeys(nsIMsgDatabase *aDB, const nsTArray<n
return rv;
}
NS_MSG_BASE PRBool ParseString(const char *string, const char *delims, nsCStringArray& array)
{
if (string && *string && delims && *delims) {
PRInt32 count = array.Count();
nsCString copy(string);
char *buffer = copy.BeginWriting();
char *token;
while ((token = NS_strtok(delims, &buffer)) != nsnull) {
if (!array.AppendCString(nsDependentCString(token))) {
while (array.Count() > count)
array.RemoveCStringAt(array.Count() - 1);
return PR_FALSE;
}
}
}
return PR_TRUE;
}
#ifdef MOZILLA_1_9_1_BRANCH
NS_MSG_BASE PRBool ParseString(const nsACString& string, char delimiter, nsTArray<nsCString>& array)
{

Просмотреть файл

@ -212,20 +212,6 @@ NS_MSG_BASE PRUnichar *MsgEscapeHTML(const PRUnichar *aSourceBuffer,
NS_MSG_BASE nsresult MsgGetHeadersFromKeys(nsIMsgDatabase *aDB, const nsTArray<nsMsgKey> &aKeys,
nsIMutableArray *aHeaders);
/**
* Parses a given string using the delimiters passed in. Items parsed from the
* string will be appended to the array.
*
* @param string
* The string to parse.
* @param delims
* A set of delimter characters.
* @param array
* The array to append tokens to.
* @deprecated This call needs to be converted to the nsTArray<nsCString> api.
*/
NS_MSG_BASE PRBool ParseString(const char *string, const char *delims, nsCStringArray& array);
#ifdef MOZILLA_1_9_1_BRANCH
/**
* Parses a given string using the delimiter passed in. Items parsed from the

Просмотреть файл

@ -133,7 +133,7 @@ static PRBool _just_to_be_sure_we_create_only_one_compose_service_ = PR_FALSE;
#define HTMLDOMAINUPDATE_DOMAINLIST_PREF_NAME "global_html_domains"
#define USER_CURRENT_HTMLDOMAINLIST_PREF_NAME "html_domains"
#define USER_CURRENT_PLAINTEXTDOMAINLIST_PREF_NAME "plaintext_domains"
#define DOMAIN_DELIMITER ","
#define DOMAIN_DELIMITER ','
#ifdef MSGCOMP_TRACE_PERFORMANCE
static PRLogModuleInfo *MsgComposeLogModule = nsnull;
@ -1383,6 +1383,7 @@ nsresult nsMsgComposeService::AddGlobalHtmlDomains()
rv = prefBranch->GetCharPref(HTMLDOMAINUPDATE_DOMAINLIST_PREF_NAME, getter_Copies(globalHtmlDomainList));
if (NS_SUCCEEDED(rv) && !globalHtmlDomainList.IsEmpty()) {
nsTArray<nsCString> domainArray;
// Get user's current HTML domain set for send format
nsCString currentHtmlDomainList;
@ -1391,9 +1392,7 @@ nsresult nsMsgComposeService::AddGlobalHtmlDomains()
nsCAutoString newHtmlDomainList(currentHtmlDomainList);
// Get the current html domain list into new list var
nsCStringArray htmlDomainArray;
if (!currentHtmlDomainList.IsEmpty())
ParseString(currentHtmlDomainList.get(), DOMAIN_DELIMITER, htmlDomainArray);
ParseString(currentHtmlDomainList, DOMAIN_DELIMITER, domainArray);
// Get user's current Plaintext domain set for send format
nsCString currentPlaintextDomainList;
@ -1401,30 +1400,22 @@ nsresult nsMsgComposeService::AddGlobalHtmlDomains()
NS_ENSURE_SUCCESS(rv,rv);
// Get the current plaintext domain list into new list var
nsCStringArray plaintextDomainArray;
if (!currentPlaintextDomainList.IsEmpty())
ParseString(currentPlaintextDomainList.get(), DOMAIN_DELIMITER, plaintextDomainArray);
ParseString(currentPlaintextDomainList, DOMAIN_DELIMITER, domainArray);
if (htmlDomainArray.Count() || plaintextDomainArray.Count()) {
// Tokenize the data and add each html domain if it is not alredy there in
PRUint32 i = domainArray.Length();
if (i > 0) {
// Append each domain in the preconfigured html domain list
globalHtmlDomainList.StripWhitespace();
ParseString(globalHtmlDomainList, DOMAIN_DELIMITER, domainArray);
// Now add each domain that does not already appear in
// the user's current html or plaintext domain lists
char *newData = globalHtmlDomainList.BeginWriting();
char *token = NS_strtok(DOMAIN_DELIMITER, &newData);
nsCAutoString htmlDomain;
while (token) {
if (token && *token) {
htmlDomain.Assign(token);
htmlDomain.StripWhitespace();
if (htmlDomainArray.IndexOf(htmlDomain) == -1 &&
plaintextDomainArray.IndexOf(htmlDomain) == -1) {
if (!newHtmlDomainList.IsEmpty())
newHtmlDomainList += DOMAIN_DELIMITER;
newHtmlDomainList += htmlDomain;
}
for (; i < domainArray.Length(); i++) {
if (domainArray.IndexOf(domainArray[i]) == i) {
if (!newHtmlDomainList.IsEmpty())
newHtmlDomainList += DOMAIN_DELIMITER;
newHtmlDomainList += domainArray[i];
}
token = NS_strtok(DOMAIN_DELIMITER, &newData);
}
}
else

Просмотреть файл

@ -62,7 +62,7 @@
#include "nsComposeStrings.h"
#define SERVER_DELIMITER ","
#define SERVER_DELIMITER ','
#define APPEND_SERVERS_VERSION_PREF_NAME "append_preconfig_smtpservers.version"
#define MAIL_ROOT_PREF "mail."
#define PREF_MAIL_SMTPSERVERS "mail.smtpservers"
@ -384,140 +384,80 @@ nsSmtpService::GetSmtpServers(nsISimpleEnumerator **aResult)
nsresult
nsSmtpService::loadSmtpServers()
{
if (mSmtpServersLoaded)
return NS_OK;
if (mSmtpServersLoaded)
return NS_OK;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIPrefBranch> prefRootBranch;
prefService->GetBranch(nsnull, getter_AddRefs(prefRootBranch));
if (NS_FAILED(rv)) return rv;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIPrefBranch> prefRootBranch;
prefService->GetBranch(nsnull, getter_AddRefs(prefRootBranch));
if (NS_FAILED(rv))
return rv;
nsCString tempServerList;
nsCString serverList;
rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS, getter_Copies(tempServerList));
nsCString serverList;
rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS, getter_Copies(serverList));
serverList.StripWhitespace();
//Get the pref in a tempServerList and then parse it to see if it has dupes.
//if so remove the dupes and then create the serverList.
if (!tempServerList.IsEmpty()) {
nsTArray<nsCString> servers;
ParseString(serverList, SERVER_DELIMITER, servers);
// Tokenize the data and add each smtp server if it is not already there
// in the user's current smtp server list
nsCStringArray servers;
ParseString(tempServerList.get(), SERVER_DELIMITER, servers);
nsCAutoString tempSmtpServer;
for (PRInt32 i = 0; i < servers.Count(); i++)
{
if (servers.IndexOf(* (servers[i])) == i) {
tempSmtpServer.Assign(* (servers[i]));
tempSmtpServer.StripWhitespace();
if (!serverList.IsEmpty())
serverList += SERVER_DELIMITER;
serverList += tempSmtpServer;
}
}
}
else {
serverList = tempServerList;
}
/**
* Check to see if we need to add pre-configured smtp servers.
* Following prefs are important to note in understanding the procedure here.
*
* 1. pref("mailnews.append_preconfig_smtpservers.version", version number);
* This pref registers the current version in the user prefs file. A default value
* is stored in mailnews.js file. If a given vendor needs to add more preconfigured
* smtp servers, the default version number can be increased. Comparing version
* number from user's prefs file and the default one from mailnews.js, we
* can add new smtp servers and any other version level changes that need to be done.
*
* 2. pref("mail.smtpservers.appendsmtpservers", <comma separated servers list>);
* This pref contains the list of pre-configured smp servers that ISP/Vendor wants to
* to add to the existing servers list.
*/
nsCOMPtr<nsIPrefBranch> defaultsPrefBranch;
rv = prefService->GetDefaultBranch(MAIL_ROOT_PREF, getter_AddRefs(defaultsPrefBranch));
NS_ENSURE_SUCCESS(rv, rv);
// We need to check if we have any pre-configured smtp servers so that
// those servers can be appended to the list.
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(MAIL_ROOT_PREF, getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv,rv);
PRInt32 appendSmtpServersCurrentVersion = 0;
PRInt32 appendSmtpServersDefaultVersion = 0;
rv = prefBranch->GetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, &appendSmtpServersCurrentVersion);
NS_ENSURE_SUCCESS(rv,rv);
rv = defaultsPrefBranch->GetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, &appendSmtpServersDefaultVersion);
NS_ENSURE_SUCCESS(rv,rv);
// Update the smtp server list if needed
if (appendSmtpServersCurrentVersion <= appendSmtpServersDefaultVersion) {
// If there are pre-configured servers, add them to the existing server list
nsCString appendServerList;
rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS_APPEND_SERVERS, getter_Copies(appendServerList));
appendServerList.StripWhitespace();
ParseString(appendServerList, SERVER_DELIMITER, servers);
// Get the list of smtp servers (either from regular pref i.e, mail.smtpservers or
// from preconfigured pref mail.smtpservers.appendsmtpservers) and create a keyed
// server list.
if (!serverList.IsEmpty() || !appendServerList.IsEmpty()) {
/**
* Check to see if we need to add pre-configured smtp servers.
* Following prefs are important to note in understanding the procedure here.
*
* 1. pref("mailnews.append_preconfig_smtpservers.version", version number);
* This pref registers the current version in the user prefs file. A default value
* is stored in mailnews.js file. If a given vendor needs to add more preconfigured
* smtp servers, the default version number can be increased. Comparing version
* number from user's prefs file and the default one from mailnews.js, we
* can add new smtp servers and any other version level changes that need to be done.
*
* 2. pref("mail.smtpservers.appendsmtpservers", <comma separated servers list>);
* This pref contains the list of pre-configured smp servers that ISP/Vendor wants to
* to add to the existing servers list.
*/
nsCOMPtr<nsIPrefBranch> defaultsPrefBranch;
rv = prefService->GetDefaultBranch(MAIL_ROOT_PREF, getter_AddRefs(defaultsPrefBranch));
NS_ENSURE_SUCCESS(rv,rv);
// Increase the version number so that updates will happen as and when needed
prefBranch->SetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, appendSmtpServersCurrentVersion + 1);
}
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(MAIL_ROOT_PREF, getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv,rv);
// use GetServerByKey to check if the key (pref) is already in
// in the list. If not it calls createKeyedServer directly.
PRInt32 appendSmtpServersCurrentVersion = 0;
PRInt32 appendSmtpServersDefaultVersion = 0;
rv = prefBranch->GetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, &appendSmtpServersCurrentVersion);
NS_ENSURE_SUCCESS(rv,rv);
for (PRUint32 i = 0; i < servers.Length(); i++) {
nsCOMPtr<nsISmtpServer> server;
GetServerByKey(servers[i].get(), getter_AddRefs(server));
}
rv = defaultsPrefBranch->GetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, &appendSmtpServersDefaultVersion);
NS_ENSURE_SUCCESS(rv,rv);
saveKeyList();
// Update the smtp server list if needed
if ((appendSmtpServersCurrentVersion <= appendSmtpServersDefaultVersion)) {
// If there are pre-configured servers, add them to the existing server list
if (!appendServerList.IsEmpty()) {
if (!serverList.IsEmpty()) {
nsCStringArray existingSmtpServersArray;
ParseString(serverList.get(), SERVER_DELIMITER, existingSmtpServersArray);
// Tokenize the data and add each smtp server if it is not already there
// in the user's current smtp server list
char *newSmtpServerStr = appendServerList.BeginWriting();
char *token = NS_strtok(SERVER_DELIMITER, &newSmtpServerStr);
nsCAutoString newSmtpServer;
while (token) {
if (token && *token) {
newSmtpServer.Assign(token);
newSmtpServer.StripWhitespace();
if (existingSmtpServersArray.IndexOf(newSmtpServer) == -1) {
serverList += ",";
serverList += newSmtpServer;
}
}
token = NS_strtok(SERVER_DELIMITER, &newSmtpServerStr);
}
}
else {
serverList = appendServerList;
}
// Increase the version number so that updates will happen as and when needed
rv = prefBranch->SetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, appendSmtpServersCurrentVersion + 1);
}
}
char *newStr = serverList.BeginWriting();
char *pref = NS_strtok(", ", &newStr);
while (pref) {
// fix for bug #96207
// code above makes sure that no duplicate entries in mail.smtpservers find
// their way to the mSmtpServers list. But it doesn't check, if a server to be
// added already is in mSmtpServers. That can happen in mail has been sent before
// opening the settings (loading the list).
// use GetServerByKey to check if the key (pref) is already in
// in the list. If not it calls createKeyedServer directly.
nsCOMPtr<nsISmtpServer> server;
rv = GetServerByKey(pref, getter_AddRefs(server));
NS_ASSERTION(NS_SUCCEEDED(rv), "GetServerByKey failed");
pref = NS_strtok(", ", &newStr);
}
}
saveKeyList();
mSmtpServersLoaded = PR_TRUE;
return NS_OK;
mSmtpServersLoaded = PR_TRUE;
return NS_OK;
}
// save the list of keys

Просмотреть файл

@ -275,16 +275,18 @@ net_pop3_load_state(const char* searchhost,
/* It's a line with a UIDL on it. */
if (current)
{
nsCStringArray lineElems;
ParseString(line.get(), " \t", lineElems);
if (lineElems.Count() < 2)
for (PRInt32 pos = line.FindChar('\t'); pos != -1; pos = line.FindChar('\t', pos))
line.Replace(pos, 1, ' ');
nsTArray<nsCString> lineElems;
ParseString(line, ' ', lineElems);
if (lineElems.Length() < 2)
continue;
nsCString *flags = lineElems[0];
nsCString *uidl = lineElems[1];
nsCString *dateReceivedStr = lineElems[2]; // will be null if only 2 elements.
nsCString *flags = &lineElems[0];
nsCString *uidl = &lineElems[1];
PRUint32 dateReceived = TimeInSecondsFromPRTime(PR_Now()); // if we don't find a date str, assume now.
if (dateReceivedStr && !dateReceivedStr->IsEmpty())
dateReceived = atoi(dateReceivedStr->get());
if (lineElems.Length() > 2)
dateReceived = atoi(lineElems[2].get());
if (!flags->IsEmpty() && !uidl->IsEmpty())
{
char flag = flags->CharAt(0);