Necko prep-integration work...add a base implementation class for mailnews urls. This encapsulates some common code that was shared across mailnews protocols. It should make my necko integration work easier as well.

(not part of the build yet).
This commit is contained in:
mscott%netscape.com 1999-06-21 20:36:03 +00:00
Родитель 2d3cbd0b95
Коммит cddba9c895
2 изменённых файлов: 582 добавлений и 0 удалений

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

@ -0,0 +1,443 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "msgCore.h"
#include "nsMsgMailNewsUrl.h"
#ifdef XP_PC
#include <windows.h> // for InterlockedIncrement
#endif
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID);
nsMsgMailNewsUrl::nsMsgMailNewsUrl()
{
NS_INIT_REFCNT();
// nsINetLibUrl specific state
m_URL_s = nsnull;
// nsIURL specific state
m_protocol = nsnull;
m_host = nsnull;
m_file = nsnull;
m_ref = nsnull;
m_port = 0;
m_spec = nsnull;
m_search = nsnull;
m_errorMessage = nsnull;
m_runningUrl = PR_FALSE;
nsComponentManager::CreateInstance(kUrlListenerManagerCID, nsnull, nsIUrlListenerManager::GetIID(), (void **) getter_AddRefs(m_urlListeners));
m_container = nsnull;
}
nsMsgMailNewsUrl::~nsMsgMailNewsUrl()
{
NS_IF_RELEASE(m_container);
PR_FREEIF(m_errorMessage);
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(nsMsgMailNewsUrl);
NS_IMPL_THREADSAFE_RELEASE(nsMsgMailNewsUrl);
nsresult nsMsgMailNewsUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsIURL::GetIID())) {
*aInstancePtr = (void*) ((nsIURL*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(nsINetlibURL::GetIID())) {
*aInstancePtr = (void*) ((nsINetlibURL*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(nsIMsgMailNewsUrl::GetIID()))
{
*aInstancePtr = (void *) ((nsIMsgMailNewsUrl*) this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////////////////
// Begin nsIMsgMailNewsUrl specific support
////////////////////////////////////////////////////////////////////////////////////
nsresult nsMsgMailNewsUrl::GetUrlState(PRBool * aRunningUrl)
{
if (aRunningUrl)
*aRunningUrl = m_runningUrl;
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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;
}
nsresult nsMsgMailNewsUrl::RegisterListener (nsIUrlListener * aUrlListener)
{
if (m_urlListeners)
m_urlListeners->RegisterListener(aUrlListener);
return NS_OK;
}
nsresult nsMsgMailNewsUrl::UnRegisterListener (nsIUrlListener * aUrlListener)
{
if (m_urlListeners)
m_urlListeners->UnRegisterListener(aUrlListener);
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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 nsMsgMailNewsUrl::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;
}
////////////////////////////////////////////////////////////////////////////////////
// End nsIMsgMailNewsUrl specific support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// Begin nsINetlibURL support
////////////////////////////////////////////////////////////////////////////////////
NS_METHOD nsMsgMailNewsUrl::SetURLInfo(URL_Struct *URL_s)
{
nsresult result = NS_OK;
/* Hook us up with the world. */
m_URL_s = URL_s;
return result;
}
NS_METHOD nsMsgMailNewsUrl::GetURLInfo(URL_Struct_** aResult) const
{
nsresult rv;
if (nsnull == aResult)
rv = NS_ERROR_NULL_POINTER;
else
{
*aResult = m_URL_s;
rv = NS_OK;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////////
// End nsINetlibURL support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// Begin nsIURL support
////////////////////////////////////////////////////////////////////////////////////
nsresult nsMsgMailNewsUrl::GetProtocol(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_protocol;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetProtocol(const char *aNewProtocol)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_protocol = nsCRT::strdup(aNewProtocol);
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::GetHost(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_host;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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 nsMsgMailNewsUrl::GetFile(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_file;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetFile(const char *aNewFile)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_file = nsCRT::strdup(aNewFile);
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::GetSpec(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_spec;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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 nsMsgMailNewsUrl::GetRef(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_ref;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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 nsMsgMailNewsUrl::GetHostPort(PRUint32 *result) const
{
NS_LOCK_INSTANCE();
*result = m_port;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetHostPort(PRUint32 aNewPort)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
NS_LOCK_INSTANCE();
m_port = aNewPort;
ReconstructSpec();
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::GetSearch(const char* *result) const
{
NS_LOCK_INSTANCE();
*result = m_search;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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 nsMsgMailNewsUrl::GetContainer(nsISupports* *result) const
{
NS_LOCK_INSTANCE();
*result = m_container;
NS_IF_ADDREF(m_container);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::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 nsMsgMailNewsUrl::GetContentLength(PRInt32 *len)
{
NS_LOCK_INSTANCE();
*len = m_URL_s->content_length;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetPostHeader(const char* name, const char* value)
{
NS_LOCK_INSTANCE();
// XXX
PR_ASSERT(0);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetPostData(nsIInputStream* input)
{
return NS_OK;
}
PRBool nsMsgMailNewsUrl::Equals(const nsIURL* aURL) const
{
PRBool bIsEqual;
nsIMsgMailNewsUrl * other;
NS_LOCK_INSTANCE();
// 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(nsIMsgMailNewsUrl::GetIID(), (void**)&other) == NS_OK) {
bIsEqual = other == (nsIMsgMailNewsUrl *) this; // compare the pointers...
}
else
bIsEqual = PR_FALSE;
NS_UNLOCK_INSTANCE();
return bIsEqual;
}
////////////////////////////////////////////////////////////////////////////////////
// End of nsIURL support
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// The following set of functions should become obsolete once we take them out of
// nsIURL.....
////////////////////////////////////////////////////////////////////////////////////
nsresult nsMsgMailNewsUrl::GetLoadAttribs(nsILoadAttribs* *result) const
{
NS_LOCK_INSTANCE();
*result = NULL;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetLoadAttribs(nsILoadAttribs* aLoadAttribs)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
return NS_OK;
}
nsresult nsMsgMailNewsUrl::GetURLGroup(nsIURLGroup* *result) const
{
return NS_OK;
}
nsresult nsMsgMailNewsUrl::SetURLGroup(nsIURLGroup* group)
{
NS_ASSERTION(m_URL_s == nsnull, "URL has already been opened");
return NS_OK;
}
nsresult nsMsgMailNewsUrl::GetServerStatus(PRInt32 *status)
{
NS_LOCK_INSTANCE();
*status = m_URL_s->server_status;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
nsresult nsMsgMailNewsUrl::ToString(PRUnichar* *aString) const
{
if (aString)
*aString = nsnull;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End of functions which should be made obsolete after modifying nsIURL
////////////////////////////////////////////////////////////////////////////////////

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

@ -0,0 +1,139 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsMsgMailNewsUrl_h___
#define nsMsgMailNewsUrl_h___
#include "nscore.h"
#include "nsISupports.h"
#include "nsIURL.h"
#include "nsINetlibURL.h" /* this should be temporary until Network N2 project lands */
#include "nsIUrlListener.h"
#include "nsIUrlListenerManager.h"
#include "nsCOMPtr.h"
#include "nsIMsgMailNewsUrl.h"
///////////////////////////////////////////////////////////////////////////////////
// Okay, I found that all of the mail and news url interfaces needed to support
// several common interfaces (in addition to those provided through nsIURL).
// So I decided to group them all in this interface.
// This interface may grow or it may get smaller (if these things get pushed up
// into nsIURL). The unfortunate thing is that we'd also like to have all of our
// mail news protocols inherit implementations of this interface. But that is
// implementation inheritance across dlls. We could do it though....something else
// to add to the list =).
//
// mscott - I'm now adding a base url implementation for mailnews to unify
// some common code....
//////////////////////////////////////////////////////////////////////////////////
class NS_MSG_BASE nsMsgMailNewsUrl : public nsIMsgMailNewsUrl, public nsINetlibURL
{
public:
nsMsgMailNewsUrl();
NS_DECL_ISUPPORTS
// nsIMsgMailNewsUrl support
///////////////////////////////////////////////////////////////////////////////
// The idea is to allow the "application" (the part of the code which wants to
// run a url in order to perform some action) to register itself as a listener
// on url. As a url listener, the app will be informed when the url begins to run
// and when the url is finished.
////////////////////////////////////////////////////////////////////////////////
NS_IMETHOD RegisterListener (nsIUrlListener * aUrlListener);
NS_IMETHOD UnRegisterListener (nsIUrlListener * aUrlListener);
///////////////////////////////////////////////////////////////////////////////
// Getters and Setters for the nsMsgMailNewsUrl specific info....
///////////////////////////////////////////////////////////////////////////////
NS_IMETHOD SetErrorMessage (char * errorMessage);
// caller must free using PR_FREE
NS_IMETHOD GetErrorMessage (char ** errorMessage) const;
// if you really want to know what the current state of the url is (running or not
// running) you should look into becoming a urlListener...
NS_IMETHOD SetUrlState(PRBool runningUrl, nsresult aStatusCode);
NS_IMETHOD GetUrlState(PRBool *runningUrl);
// nsIURL support
// 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);
protected:
virtual ~nsMsgMailNewsUrl();
virtual void ReconstructSpec(void) = 0;
// protocol specific code to parse a url...
virtual nsresult ParseUrl(const nsString& aSpec) = 0;
char *m_spec;
char *m_protocol;
char *m_host;
char *m_file;
char *m_ref;
char *m_search;
char *m_errorMessage;
/* Here's our link to the netlib world.... */
URL_Struct *m_URL_s;
PRBool m_runningUrl;
PRInt32 m_port;
nsISupports* m_container;
// manager of all of current url listeners....
nsCOMPtr<nsIUrlListenerManager> m_urlListeners;
};
#endif /* nsMsgMailNewsUrl_h___ */