support add/removal of SMTP servers

This commit is contained in:
alecf%netscape.com 1999-09-14 07:03:47 +00:00
Родитель 836811052d
Коммит 3c33281fd3
3 изменённых файлов: 86 добавлений и 2 удалений

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

@ -49,6 +49,8 @@ interface nsISmtpService : nsISupports {
in nsIUrlListener aUrlListener, in nsISmtpServer aServer,
out nsIURI aURL);
void GetSmtpServers(out nsISupportsArray aResult);
readonly attribute nsISupportsArray smtpServers;
attribute nsISmtpServer DefaultSmtpServer;
};
nsISmtpServer createSmtpServer();
void deleteSmtpServer(in nsISmtpServer server);
};

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

@ -31,6 +31,13 @@
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
typedef struct _findServerByKeyEntry {
const char *key;
nsISmtpServer *server;
} findServerByKeyEntry;
static NS_DEFINE_CID(kCSmtpUrlCID, NS_SMTPURL_CID);
// foward declarations...
@ -322,3 +329,77 @@ nsSmtpService::SetDefaultSmtpServer(nsISmtpServer *aServer)
return NS_OK;
}
PRBool
nsSmtpService::findServerByKey (nsISupports *element, void *aData)
{
nsresult rv;
nsCOMPtr<nsISmtpServer> server = do_QueryInterface(element, &rv);
if (NS_FAILED(rv)) return PR_TRUE;
findServerByKeyEntry *entry = (findServerByKeyEntry*) aData;
nsXPIDLCString key;
rv = server->GetKey(getter_Copies(key));
if (NS_FAILED(rv)) return PR_TRUE;
if (nsCRT::strcmp(key, entry->key)==0) {
entry->server = server;
return PR_FALSE;
}
return PR_TRUE;
}
NS_IMETHODIMP
nsSmtpService::CreateSmtpServer(nsISmtpServer **aResult)
{
if (!aResult) return NS_ERROR_NULL_POINTER;
nsresult rv;
PRInt32 i=1;
PRBool unique = PR_FALSE;
findServerByKeyEntry entry;
nsCAutoString key;
do {
key = "server";
key.Append(i);
entry.key = key;
entry.server = nsnull;
mSmtpServers->EnumerateForwards(findServerByKey, (void *)&entry);
if (!entry.server) unique=PR_TRUE;
} while (!unique);
rv = nsComponentManager::CreateInstance(NS_SMTPSERVER_PROGID,
nsnull,
NS_GET_IID(nsISmtpServer),
(void **)aResult);
if (NS_SUCCEEDED(rv))
(*aResult)->SetKey(key);
return rv;
}
NS_IMETHODIMP
nsSmtpService::DeleteSmtpServer(nsISmtpServer *aServer)
{
if (!aServer) return NS_OK;
nsresult rv;
PRInt32 idx = 0;
rv = mSmtpServers->GetIndexOf(aServer, &idx);
if (NS_FAILED(rv) || idx==0)
return NS_OK;
rv = mSmtpServers->DeleteElementAt(idx);
return rv;
}

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

@ -57,6 +57,7 @@ protected:
private:
static PRBool findServerByKey (nsISupports *element, void *aData);
nsCOMPtr<nsISupportsArray> mSmtpServers;
nsCOMPtr<nsISmtpServer> mDefaultSmtpServer;
};