Overhaul of mailbox url to use new nsMsgMailNewsUrl class.This should make necko integration easier and reduce footprint a bit.

This commit is contained in:
mscott%netscape.com 1999-06-22 00:10:23 +00:00
parent 6835a27780
commit b40cf4d579
2 changed files with 18 additions and 505 deletions

View File

@ -118,57 +118,26 @@ static char *nsMailboxGetURI(char *nativepath)
// helper function for parsing the search field of a url
char * extractAttributeValue(const char * searchString, const char * attributeName);
nsMailboxUrl::nsMailboxUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
nsMailboxUrl::nsMailboxUrl()
{
NS_INIT_REFCNT();
// nsIMailboxUrl specific code...
m_errorMessage = nsnull;
// nsINetLibUrl specific state
m_URL_s = nsnull;
// nsIURL specific state
m_protocol = nsnull;
m_host = nsnull;
m_file = nsnull;
m_ref = nsnull;
m_spec = nsnull;
m_search = nsnull;
m_mailboxAction = nsMailboxActionParseMailbox;
m_filePath = nsnull;
m_messageID = nsnull;
m_messageKey = 0;
m_messageSize = 0;
m_messageFileSpec = nsnull;
m_runningUrl = PR_FALSE;
nsComponentManager::CreateInstance(kUrlListenerManagerCID, nsnull, nsIUrlListenerManager::GetIID(), (void **) getter_AddRefs(m_urlListeners));
m_container = aContainer;
NS_IF_ADDREF(m_container);
}
nsMailboxUrl::~nsMailboxUrl()
{
NS_IF_RELEASE(m_container);
PR_FREEIF(m_errorMessage);
delete m_filePath;
PR_FREEIF(m_messageID);
PR_FREEIF(m_spec);
PR_FREEIF(m_protocol);
PR_FREEIF(m_host);
PR_FREEIF(m_file);
PR_FREEIF(m_ref);
PR_FREEIF(m_search);
}
NS_IMPL_THREADSAFE_ADDREF(nsMailboxUrl);
NS_IMPL_THREADSAFE_RELEASE(nsMailboxUrl);
NS_IMPL_ADDREF_INHERITED(nsMailboxUrl, nsMsgMailNewsUrl)
NS_IMPL_RELEASE_INHERITED(nsMailboxUrl, nsMsgMailNewsUrl)
nsresult nsMailboxUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr)
@ -182,24 +151,6 @@ nsresult nsMailboxUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIURL::GetIID()))
{
*aInstancePtr = (void*) ((nsIURL*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsINetlibURL::GetIID()))
{
*aInstancePtr = (void*) ((nsINetlibURL*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMsgMailNewsUrl::GetIID()))
{
*aInstancePtr = (void *) ((nsIMsgMailNewsUrl *) this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMsgUriUrl::GetIID()))
{
*aInstancePtr = (void *) ((nsIMsgUriUrl *) this);
@ -217,7 +168,7 @@ nsresult nsMailboxUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
}
#endif
return NS_NOINTERFACE;
return nsMsgMailNewsUrl::QueryInterface(aIID, aInstancePtr);
}
////////////////////////////////////////////////////////////////////////////////////
@ -297,73 +248,6 @@ nsresult nsMailboxUrl::SetMessageSize(PRUint32 aMessageSize)
return NS_OK;
}
nsresult nsMailboxUrl::SetErrorMessage (char * errorMessage)
{
NS_LOCK_INSTANCE();
if (errorMessage)
{
PR_FREEIF(m_errorMessage);
m_errorMessage = errorMessage;
}
NS_UNLOCK_INSTANCE();
return NS_OK;
}
// caller must free using PR_FREE
nsresult nsMailboxUrl::GetErrorMessage (char ** errorMessage) const
{
NS_LOCK_INSTANCE();
if (errorMessage)
{
if (m_errorMessage)
*errorMessage = nsCRT::strdup(m_errorMessage);
else
*errorMessage = nsnull;
}
NS_UNLOCK_INSTANCE();
return NS_OK;
}
// url listener registration details...
nsresult nsMailboxUrl::RegisterListener (nsIUrlListener * aUrlListener)
{
nsresult rv = NS_OK;
if (m_urlListeners)
rv = m_urlListeners->RegisterListener(aUrlListener);
return rv;
}
nsresult nsMailboxUrl::UnRegisterListener (nsIUrlListener * aUrlListener)
{
nsresult rv = NS_OK;
if (m_urlListeners)
rv = m_urlListeners->UnRegisterListener(aUrlListener);
return rv;
}
nsresult nsMailboxUrl::GetUrlState(PRBool * aRunningUrl)
{
if (aRunningUrl)
*aRunningUrl = m_runningUrl;
return NS_OK;
}
nsresult nsMailboxUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode)
{
m_runningUrl = aRunningUrl;
if (m_urlListeners)
{
if (m_runningUrl)
m_urlListeners->OnStartRunningUrl(this);
else
m_urlListeners->OnStopRunningUrl(this, aExitCode);
}
return NS_OK;
}
// from nsIMsgUriUrl
NS_IMETHODIMP nsMailboxUrl::GetURI(char ** aURI)
{
@ -429,20 +313,9 @@ NS_IMETHODIMP nsMailboxUrl::GetMessageFile(nsIFileSpec ** aFileSpec)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End nsIMailboxUrl specific support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// Begin nsINetlibURL support
////////////////////////////////////////////////////////////////////////////////////
NS_METHOD nsMailboxUrl::SetURLInfo(URL_Struct *URL_s)
NS_IMETHODIMP nsMailboxUrl::SetURLInfo(URL_Struct *URL_s)
{
nsresult result = NS_OK;
/* Hook us up with the world. */
m_URL_s = URL_s;
nsresult rv = nsMsgMailNewsUrl::SetURLInfo(URL_s);
if (m_mailboxAction == nsMailboxActionDisplayMessage || m_mailboxAction == nsMailboxActionCopyMessage
|| m_mailboxAction == nsMailboxActionMoveMessage || m_mailboxAction == nsMailboxActionSaveMessageToDisk
|| m_mailboxAction == nsMailboxActionAppendMessageToDisk)
@ -452,26 +325,11 @@ NS_METHOD nsMailboxUrl::SetURLInfo(URL_Struct *URL_s)
m_URL_s->range_header = byteRange;
}
return result;
}
NS_METHOD nsMailboxUrl::GetURLInfo(URL_Struct_** aResult) const
{
nsresult rv;
if (nsnull == aResult) {
rv = NS_ERROR_NULL_POINTER;
} else {
/* XXX: Should the URL be reference counted here?? */
*aResult = m_URL_s;
rv = NS_OK;
}
return rv;
return rv;
}
////////////////////////////////////////////////////////////////////////////////////
// End nsINetlibURL support
// End nsIMailboxUrl specific support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@ -496,34 +354,13 @@ nsresult nsMailboxUrl::ParseSearchPart()
return NS_OK;
}
// XXX recode to use nsString api's
// XXX don't bother with port numbers
// XXX don't bother with ref's
// XXX null pointer checks are incomplete
// warning: don't assume when parsing the url that the protocol part is "news"...
nsresult nsMailboxUrl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
nsresult nsMailboxUrl::ParseUrl(const nsString& aSpec)
{
// XXX hack!
char* cSpec = aSpec.ToNewCString();
const char* uProtocol = nsnull;
const char* uHost = nsnull;
const char* uFile = nsnull;
PRUint32 uPort;
if (nsnull != aURL)
{
nsresult rslt = aURL->GetProtocol(&uProtocol);
if (rslt != NS_OK) return rslt;
rslt = aURL->GetHost(&uHost);
if (rslt != NS_OK) return rslt;
rslt = aURL->GetFile(&uFile);
if (rslt != NS_OK) return rslt;
rslt = aURL->GetHostPort(&uPort);
if (rslt != NS_OK) return rslt;
}
NS_LOCK_INSTANCE();
PR_FREEIF(m_protocol);
@ -532,21 +369,6 @@ nsresult nsMailboxUrl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
PR_FREEIF(m_ref);
PR_FREEIF(m_search);
if (nsnull == cSpec)
{
if (nsnull == aURL)
{
NS_UNLOCK_INSTANCE();
return NS_ERROR_ILLEGAL_VALUE;
}
m_protocol = (nsnull != uProtocol) ? PL_strdup(uProtocol) : nsnull;
m_host = (nsnull != uHost) ? PL_strdup(uHost) : nsnull;
m_file = (nsnull != uFile) ? PL_strdup(uFile) : nsnull;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
// The URL is considered absolute if and only if it begins with a
// protocol spec. A protocol spec is an alphanumeric string of 1 or
// more characters that is terminated with a colon.
@ -676,253 +498,6 @@ void nsMailboxUrl::ReconstructSpec(void)
m_spec = PR_smprintf("%s://%s", m_protocol, m_file);
}
////////////////////////////////////////////////////////////////////////////////
PRBool nsMailboxUrl::Equals(const nsIURL* aURL) const
{
PRBool bIsEqual;
nsMailboxUrl* other;
NS_LOCK_INSTANCE();
// are they both mailbox urls?? if yes...for now just compare the pointers until
// I figure out if we need to check any of the guts for equality....
if (((nsIURL*)aURL)->QueryInterface(nsIMailboxUrl::GetIID(), (void**)&other) == NS_OK) {
bIsEqual = other == this; // compare the pointers...
}
else
bIsEqual = PR_FALSE;
NS_UNLOCK_INSTANCE();
return bIsEqual;
}
nsresult nsMailboxUrl::GetProtocol(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_protocol;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetProtocol(const char *aNewProtocol)
{
NS_LOCK_INSTANCE();
m_protocol = nsCRT::strdup(aNewProtocol);
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::GetHost(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_host;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetHost(const char *aNewHost)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_host = nsCRT::strdup(aNewHost);
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::GetFile(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_file;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetFile(const char *aNewFile)
{
nsresult rv = NS_OK;
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_file = nsCRT::strdup(aNewFile);
ReconstructSpec();
if (m_filePath) {
delete m_filePath;
m_filePath = nsnull;
}
m_filePath = new nsFileSpec(m_file);
if (m_filePath == nsnull) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
NS_UNLOCK_INSTANCE();
return rv;
}
nsresult nsMailboxUrl::GetSpec(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_spec;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetSpec(const char *aNewSpec)
{
// XXX is this right, or should we call ParseURL?
nsresult rv = NS_OK;
// NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
rv = ParseURL(aNewSpec);
#if 0
PR_FREEIF(m_spec);
m_spec = nsCRT::strdup(aNewSpec);
#endif
NS_UNLOCK_INSTANCE();
return rv;
}
nsresult nsMailboxUrl::GetRef(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_ref;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetRef(const char *aNewRef)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_ref = nsCRT::strdup(aNewRef);
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::GetHostPort(PRUint32 *result) const
{
NS_LOCK_INSTANCE();
*result = 0xFFFFFFFF;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetHostPort(PRUint32 aNewPort)
{
NS_ASSERTION(0, "hmmm mailbox urls don't have a port....");
return NS_OK;
}
nsresult nsMailboxUrl::GetSearch(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_search;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetSearch(const char *aNewSearch)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_search = nsCRT::strdup(aNewSearch);
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::GetContainer(nsISupports* *result) const
{
NS_LOCK_INSTANCE();
*result = m_container;
NS_IF_ADDREF(m_container);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetContainer(nsISupports* container)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
NS_IF_RELEASE(m_container);
m_container = container;
NS_IF_ADDREF(m_container);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::GetContentLength(PRInt32 *len)
{
NS_LOCK_INSTANCE();
*len = m_URL_s->content_length;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End of nsIURL support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// The following set of functions should become obsolete once we take them out of
// nsIURL.....
////////////////////////////////////////////////////////////////////////////////////
nsresult nsMailboxUrl::GetLoadAttribs(nsILoadAttribs* *result) const
{
NS_LOCK_INSTANCE();
*result = NULL;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetLoadAttribs(nsILoadAttribs* aLoadAttribs)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
return NS_OK;
}
nsresult nsMailboxUrl::SetPostHeader(const char* name, const char* value)
{
NS_LOCK_INSTANCE();
// XXX
PR_ASSERT(0);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::SetPostData(nsIInputStream* input)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsMailboxUrl::GetURLGroup(nsIURLGroup* *result) const
{
return NS_OK;
}
nsresult nsMailboxUrl::SetURLGroup(nsIURLGroup* group)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
return NS_OK;
}
nsresult nsMailboxUrl::GetServerStatus(PRInt32 *status)
{
NS_LOCK_INSTANCE();
*status = m_URL_s->server_status;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMailboxUrl::ToString(PRUnichar* *aString) const
{
if (aString)
*aString = nsnull;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End of functions which should be made obsolete after modifying nsIURL
////////////////////////////////////////////////////////////////////////////////////
// takes a string like ?messageID=fooo&number=MsgKey and returns a new string
// containing just the attribute value. i.e you could pass in this string with
// an attribute name of messageID and I'll return fooo. Use PR_Free to delete

View File

@ -20,51 +20,17 @@
#define nsMailboxUrl_h__
#include "nsIMailboxUrl.h"
#include "nsIUrlListenerManager.h"
#include "nsINetlibURL.h" /* this should be temporary until Network N2 project lands */
#include "nsMsgMailNewsUrl.h"
#include "nsFileSpec.h"
#include "nsIFileSpec.h"
#include "nsCOMPtr.h"
class nsMailboxUrl : public nsIMailboxUrl, public nsINetlibURL, public nsIMsgUriUrl
class nsMailboxUrl : public nsIMailboxUrl, public nsMsgMailNewsUrl, public nsIMsgUriUrl
{
public:
// from nsIURL:
// overrides for nsIURL
NS_IMETHOD SetURLInfo(URL_Struct *URL_s);
// mscott: some of these we won't need to implement..as part of the netlib re-write we'll be removing them
// from nsIURL and then we can remove them from here as well....
NS_IMETHOD_(PRBool) Equals(const nsIURL *aURL) const;
NS_IMETHOD GetSpec(const char* *result) const;
NS_IMETHOD SetSpec(const char* spec);
NS_IMETHOD GetProtocol(const char* *result) const;
NS_IMETHOD SetProtocol(const char* protocol);
NS_IMETHOD GetHost(const char* *result) const;
NS_IMETHOD SetHost(const char* host);
NS_IMETHOD GetHostPort(PRUint32 *result) const;
NS_IMETHOD SetHostPort(PRUint32 port);
NS_IMETHOD GetFile(const char* *result) const;
NS_IMETHOD SetFile(const char* file);
NS_IMETHOD GetRef(const char* *result) const;
NS_IMETHOD SetRef(const char* ref);
NS_IMETHOD GetSearch(const char* *result) const;
NS_IMETHOD SetSearch(const char* search);
NS_IMETHOD GetContainer(nsISupports* *result) const;
NS_IMETHOD SetContainer(nsISupports* container);
NS_IMETHOD GetLoadAttribs(nsILoadAttribs* *result) const; // make obsolete
NS_IMETHOD SetLoadAttribs(nsILoadAttribs* loadAttribs); // make obsolete
NS_IMETHOD GetURLGroup(nsIURLGroup* *result) const; // make obsolete
NS_IMETHOD SetURLGroup(nsIURLGroup* group); // make obsolete
NS_IMETHOD SetPostHeader(const char* name, const char* value); // make obsolete
NS_IMETHOD SetPostData(nsIInputStream* input); // make obsolete
NS_IMETHOD GetContentLength(PRInt32 *len);
NS_IMETHOD GetServerStatus(PRInt32 *status); // make obsolete
NS_IMETHOD ToString(PRUnichar* *aString) const;
// from nsINetlibURL:
NS_IMETHOD GetURLInfo(URL_Struct_ **aResult) const;
NS_IMETHOD SetURLInfo(URL_Struct_ *URL_s);
// from nsIMailboxUrl:
NS_IMETHOD GetMessageHeader(nsIMsgDBHdr ** aMsgHdr);
NS_IMETHOD SetMailboxParser(nsIStreamListener * aConsumer);
@ -81,27 +47,17 @@ public:
NS_IMETHOD SetMessageFile(nsIFileSpec * aFileSpec);
NS_IMETHOD GetMessageFile(nsIFileSpec ** aFileSpec);
// from nsIMsgMailNewsUrl:
NS_IMETHOD SetUrlState(PRBool aRunningUrl, nsresult aExitCode);
NS_IMETHOD GetUrlState(PRBool * aRunningUrl);
NS_IMETHOD SetErrorMessage (char * errorMessage);
// caller must free using PR_FREE
NS_IMETHOD GetErrorMessage (char ** errorMessage) const;
NS_IMETHOD RegisterListener (nsIUrlListener * aUrlListener);
NS_IMETHOD UnRegisterListener (nsIUrlListener * aUrlListener);
// from nsIMsgUriUrl
NS_IMETHOD GetURI(char ** aURI);
// nsMailboxUrl
nsMailboxUrl(nsISupports* aContainer, nsIURLGroup* aGroup);
nsMailboxUrl();
virtual ~nsMailboxUrl();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
// protocol specific code to parse a url...
nsresult ParseURL(const nsString& aSpec, const nsIURL* aURL = nsnull);
virtual nsresult ParseUrl(const nsString& aSpec);
protected:
@ -109,24 +65,6 @@ protected:
nsCOMPtr<nsIStreamListener> m_mailboxParser;
nsCOMPtr<nsIStreamListener> m_mailboxCopyHandler;
// manager of all of current url listeners....
nsCOMPtr<nsIUrlListenerManager> m_urlListeners;
/* Here's our link to the old netlib world.... */
URL_Struct *m_URL_s;
char *m_spec;
char *m_protocol;
char *m_host;
char *m_file;
char *m_ref;
char *m_search;
char *m_errorMessage;
PRBool m_runningUrl;
nsISupports *m_container;
nsMailboxAction m_mailboxAction; // the action this url represents...parse mailbox, display messages, etc.
nsFileSpec *m_filePath;
char *m_messageID;
@ -136,7 +74,7 @@ protected:
// used by save message to disk
nsCOMPtr<nsIFileSpec> m_messageFileSpec;
void ReconstructSpec(void);
virtual void ReconstructSpec(void);
nsresult ParseSearchPart();
};