зеркало из https://github.com/mozilla/gecko-dev.git
initialize some uninitialized variables. remove nsMsgNewsFolder::GetChildNamed(), the base class has the same implementation. when posting, if the host name is not explictly given, look for the news host that is subscribed to the group. fix a free memory read. (thanks to suresh for finding it)
This commit is contained in:
Родитель
1a7d793534
Коммит
c36aaf7aae
|
@ -560,42 +560,6 @@ NS_IMETHODIMP nsMsgNewsFolder::Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgNewsFolder::GetChildNamed(const char *name, nsISupports ** aChild)
|
||||
{
|
||||
NS_ASSERTION(aChild, "NULL child");
|
||||
|
||||
// will return nsnull if we can't find it
|
||||
*aChild = nsnull;
|
||||
|
||||
nsCOMPtr <nsIMsgFolder> folder;
|
||||
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSubFolders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRUint32 count = cnt;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr <nsISupports> supports;
|
||||
supports = mSubFolders->ElementAt(i);
|
||||
|
||||
if(NS_SUCCEEDED(supports->QueryInterface(kISupportsIID, getter_AddRefs(folder)))) {
|
||||
PRUnichar *folderName;
|
||||
|
||||
folder->GetName(&folderName);
|
||||
|
||||
// case-insensitive compare is probably LCD across OS filesystems
|
||||
if (folderName && nsCRT::strcasecmp(folderName, name)!=0) {
|
||||
*aChild = folder;
|
||||
PR_FREEIF(folderName);
|
||||
return NS_OK;
|
||||
}
|
||||
PR_FREEIF(folderName);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgNewsFolder::GetAbbreviatedName(PRUnichar * *aAbbreviatedName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -878,10 +842,10 @@ NS_IMETHODIMP nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages,
|
|||
NS_WITH_SERVICE(nsINntpService, nntpService, kNntpServiceCID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && nntpService) {
|
||||
char *hostname;
|
||||
char *hostname = nsnull;
|
||||
rv = GetHostname(&hostname);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRUnichar *newsgroupname;
|
||||
PRUnichar *newsgroupname = nsnull;
|
||||
rv = GetName(&newsgroupname);
|
||||
nsCString asciiName(newsgroupname);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -67,7 +67,6 @@ public:
|
|||
NS_IMETHOD Rename (const char *newName);
|
||||
NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos);
|
||||
|
||||
NS_IMETHOD GetChildNamed(const char* name, nsISupports ** aChild);
|
||||
NS_IMETHODIMP GetAbbreviatedName(PRUnichar * *aAbbreviatedName);
|
||||
|
||||
NS_IMETHOD GetFolderURL(char **url);
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIFileLocator.h"
|
||||
#include "nsFileLocations.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
#include "nsINntpIncomingServer.h"
|
||||
|
||||
#undef GetPort // XXX Windows!
|
||||
#undef SetPort // XXX Windows!
|
||||
|
@ -58,9 +60,11 @@ static NS_DEFINE_CID(kCNNTPNewsgroupCID, NS_NNTPNEWSGROUP_CID);
|
|||
static NS_DEFINE_CID(kCNNTPNewsgroupPostCID, NS_NNTPNEWSGROUPPOST_CID);
|
||||
static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
static NS_DEFINE_CID(kCPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
|
||||
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
|
||||
|
||||
nsNntpService::nsNntpService()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -317,21 +321,80 @@ nsresult nsNntpService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListen
|
|||
return rv;
|
||||
}
|
||||
|
||||
typedef struct _findNewsServerEntry {
|
||||
const char *newsgroup;
|
||||
nsINntpIncomingServer *server;
|
||||
} findNewsServerEntry;
|
||||
|
||||
PRBool
|
||||
nsNntpService::findNewsServerWithGroup(nsISupports *aElement, void *data)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsINntpIncomingServer> newsserver = do_QueryInterface(aElement, &rv);
|
||||
if (NS_FAILED(rv) || ! newsserver) return PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(aElement, &rv);
|
||||
if (NS_FAILED(rv) || ! server) return PR_TRUE;
|
||||
|
||||
findNewsServerEntry *entry = (findNewsServerEntry*) data;
|
||||
|
||||
nsCOMPtr<nsIFolder> folder;
|
||||
rv = server->GetRootFolder(getter_AddRefs(folder));
|
||||
if (NS_FAILED(rv) || !folder ) return PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIMsgFolder> msgfolder = do_QueryInterface(folder, &rv);
|
||||
if (NS_FAILED(rv) || !msgfolder) return PR_TRUE;
|
||||
|
||||
PRBool containsGroup = PR_FALSE;
|
||||
rv = msgfolder->ContainsChildNamed((const char *)(entry->newsgroup), &containsGroup);
|
||||
if (NS_FAILED(rv)) return PR_TRUE;
|
||||
|
||||
if (containsGroup) {
|
||||
entry->server = newsserver;
|
||||
return PR_FALSE; // stop on first find
|
||||
}
|
||||
else {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsNntpService::FindServerWithNewsgroup(nsCString &host, nsCString &groupName)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager, kMsgAccountManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return;
|
||||
nsCOMPtr<nsISupportsArray> servers;
|
||||
|
||||
rv = accountManager->GetAllServers(getter_AddRefs(servers));
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
findNewsServerEntry serverInfo;
|
||||
serverInfo.server = nsnull;
|
||||
serverInfo.newsgroup = (const char *)groupName;
|
||||
|
||||
servers->EnumerateForwards(findNewsServerWithGroup, (void *)&serverInfo);
|
||||
if (serverInfo.server) {
|
||||
nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(serverInfo.server);
|
||||
nsXPIDLCString thisHostname;
|
||||
rv = server->GetHostName(getter_Copies(thisHostname));
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
host = (const char *)thisHostname;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsNntpService::FindHostFromGroup(nsCString &host, nsCString &groupName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// host always comes in as ""
|
||||
NS_ASSERTION(host.IsEmpty(), "host is not empty");
|
||||
if (!host.IsEmpty()) return NS_ERROR_FAILURE;
|
||||
|
||||
if (0) {
|
||||
// groupName is "foobar"
|
||||
// todo: look for "foobar" in the newsrc files of all the hosts,
|
||||
// starting with the default nntp host.
|
||||
//
|
||||
// for now, leave host blank so we'll just use the default nntp host.
|
||||
}
|
||||
|
||||
|
||||
FindServerWithNewsgroup(host, groupName);
|
||||
|
||||
if (host.IsEmpty()) {
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kCPrefServiceCID, &rv);
|
||||
if (NS_FAILED(rv) || (!prefs)) {
|
||||
|
@ -355,7 +418,8 @@ nsresult nsNntpService::FindHostFromGroup(nsCString &host, nsCString &groupName)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNames)
|
||||
nsresult
|
||||
nsNntpService::DetermineHostForPosting(nsCString &host, const char *newsgroupsNames)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
@ -431,8 +495,10 @@ nsresult nsNntpService::DetermineHostForPosting(nsCString &host, const char *new
|
|||
else {
|
||||
// theRest is "group"
|
||||
rv = FindHostFromGroup(currentHost, str);
|
||||
PR_FREEIF(list);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_FREEIF(list);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (host.IsEmpty()) {
|
||||
|
@ -641,9 +707,7 @@ nsresult nsNntpService::PostMessage(nsIFileSpec *fileToPost, const char *newsgro
|
|||
|
||||
if (NS_FAILED(rv) || (host.IsEmpty())) return rv;
|
||||
|
||||
#ifdef DEBUG_NEWS
|
||||
printf("post to this host: %s\n",host.GetBuffer());
|
||||
#endif
|
||||
|
||||
char *urlstr = PR_smprintf("%s/%s",kNewsRootURI,host.GetBuffer());
|
||||
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
|
||||
|
|
|
@ -58,11 +58,13 @@ protected:
|
|||
|
||||
nsresult DetermineHostForPosting(nsCString &host, const char *newsgroupNames);
|
||||
nsresult FindHostFromGroup(nsCString &host, nsCString &groupName);
|
||||
void FindServerWithNewsgroup(nsCString &host, nsCString &groupName);
|
||||
|
||||
// a convience routine used to put together news urls.
|
||||
nsresult ConstructNntpUrl(const char * urlString, const char * newsgroupName, nsMsgKey key, nsIUrlListener *aUrlListener, nsIURI ** aUrl);
|
||||
// a convience routine to run news urls
|
||||
nsresult RunNewsUrl (nsIURI * aUrl, nsISupports * aConsumer);
|
||||
static PRBool findNewsServerWithGroup(nsISupports *aElement, void *data);
|
||||
};
|
||||
|
||||
#endif /* nsNntpService_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче