more checkins for thread/event work

This commit is contained in:
jefft%netscape.com 1999-03-23 23:46:00 +00:00
Родитель af29034d14
Коммит 2975dbc284
4 изменённых файлов: 106 добавлений и 25 удалений

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

@ -147,6 +147,12 @@ void nsImapProtocol::SetupWithUrl(nsIURL * aURL)
const char * hostName = nsnull;
PRUint32 port = IMAP_PORT;
m_runningUrl->GetHost(&hostName);
m_runningUrl->GetHostPort(&port);
/*JT - Should go away when netlib registers itself! */
nsComponentManager::RegisterComponent(kNetServiceCID, NULL, NULL,
"netlib.dll", PR_FALSE, PR_FALSE);
nsINetService* pNetService;
rv = nsServiceManager::GetService(kNetServiceCID,
nsINetService::GetIID(),
@ -280,7 +286,30 @@ NS_IMETHODIMP nsImapProtocol::OnDataAvailable(nsIURL* aURL, nsIInputStream *aISt
// we would read a line from the stream and then parse it.....I think this function can
// effectively replace ReadLineFromSocket...
return NS_OK;
nsIImapUrl *aImapUrl;
nsresult res = aURL->QueryInterface(nsIImapUrl::GetIID(),
(void**)&aImapUrl);
PRUint32 len = aLength > OUTPUT_BUFFER_SIZE-1 ? OUTPUT_BUFFER_SIZE-1 : aLength;
if(NS_SUCCEEDED(res))
{
res = aIStream->Read(m_dataBuf, len, &len);
if (NS_SUCCEEDED(res))
{
m_dataBuf[len] = 0;
nsIImapLog* aImapLog = nsnull;
res = aImapUrl->GetImapLog(&aImapLog);
if (NS_SUCCEEDED(res) && aImapLog)
{
nsImapLogProxy aProxy(aImapLog, m_sinkEventQueue, m_thread);
aProxy.HandleImapLogData(m_dataBuf);
NS_RELEASE(aImapLog);
}
}
NS_RELEASE(aImapUrl);
}
return res;
}
NS_IMETHODIMP nsImapProtocol::OnStartBinding(nsIURL* aURL, const char *aContentType)
@ -419,7 +448,22 @@ nsresult nsImapProtocol::LoadUrl(nsIURL * aURL, nsISupports * aConsumer)
{
// mscott - I think Imap urls always come in fresh for each Imap protocol connection
// so we should always be calling m_transport->open(our url)....
NS_ASSERTION(0, "I don't think we should get here for imap urls");
// NS_ASSERTION(0, "I don't think we should get here for imap
// urls");
// ********** jefft ********* okay let's use ? search string
// for passing the raw command now.
const char *search = nsnull;
aURL->GetSearch(&search);
char *tmpBuffer = nsnull;
if (search && PL_strlen(search))
{
tmpBuffer = PR_smprintf("%s\r\n", search);
if (tmpBuffer)
{
SendData(tmpBuffer);
PR_Free(tmpBuffer);
}
}
}
} // if we have an imap url and a transport
if (aConsumer)

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

@ -103,8 +103,7 @@ private:
static void ImapThreadMain(void *aParm);
void ImapThreadMainLoop(void);
PRBool ImapThreadIsRunning();
nsISupports *m_consumer;
nsISupports* m_consumer;
// initialization function given a new url and transport layer
void SetupWithUrl(nsIURL * aURL);

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

@ -383,6 +383,14 @@ nsresult nsImapUrl::ParseURL(const nsString& aSpec, const nsIURL* aURL)
cp = PL_strchr(cp, '/');
m_port = strtol(cp0, (char **)nsnull, 10);
}
cp = PL_strchr(cp, '?');
if (cp)
{
cp++;
PRInt32 slen = PL_strlen(cp);
m_search = (char*) PR_Malloc(slen+1);
PL_strcpy(m_search, cp);
}
}
delete cSpec;

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

@ -42,6 +42,7 @@
#include "nsIImapLog.h"
#include "nsIMsgIdentity.h"
#include "nsIMsgMailSession.h"
#include "nsIImapLog.h"
#include "nsIEventQueueService.h"
#include "nsXPComCIID.h"
@ -51,6 +52,7 @@
#define NETLIB_DLL "netlib.dll"
#define XPCOM_DLL "xpcom32.dll"
#define PREF_DLL "xppref32.dll"
#define MSGIMAP_DLL "msgimap.dll"
#else
#ifdef XP_MAC
#include "nsMacRepository.h"
@ -58,6 +60,7 @@
#define NETLIB_DLL "libnetlib.so"
#define XPCOM_DLL "libxpcom.so"
#define PREF_DLL "pref.so" // mscott: is this right?
#define MSGIMAP_DLL "libmsgimap.so"
#endif
#endif
@ -71,6 +74,7 @@ static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
static NS_DEFINE_CID(kImapProtocolCID, NS_IMAPPROTOCOL_CID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
/////////////////////////////////////////////////////////////////////////////////
// Define default values to be used to drive the test
/////////////////////////////////////////////////////////////////////////////////
@ -153,28 +157,35 @@ nsIMAP4TestDriver::nsIMAP4TestDriver(PLEventQueue *queue)
strcat(m_urlSpec, "/");
}
NS_IMPL_ADDREF(nsIMAP4TestDriver);
NS_IMPL_RELEASE(nsIMAP4TestDriver);
NS_IMPL_ADDREF(nsIMAP4TestDriver)
NS_IMPL_RELEASE(nsIMAP4TestDriver)
// NS_IMPL_ISUPPORTS(nsIMAP4TestDriver, nsIUrlListener::GetIID())
NS_IMETHODIMP nsIMAP4TestDriver::QueryInterface(const nsIID &aIID, void** aInstancePtr)
nsresult
nsIMAP4TestDriver::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr)
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIStreamListener::GetIID()) || aIID.Equals(kISupportsIID))
{
*aInstancePtr = (void*) ((nsIStreamListener*)this);
AddRef();
return NS_OK;
*aInstancePtr = nsnull;
if (aIID.Equals(nsIUrlListener::GetIID()))
{
*aInstancePtr = (void*)(nsIUrlListener*)this;
}
if (aIID.Equals(nsIImapLog::GetIID()))
{
*aInstancePtr = (void*) ((nsIImapLog*)this);
AddRef();
return NS_OK;
else if (aIID.Equals(nsIImapLog::GetIID()))
{
*aInstancePtr = (void*)(nsIImapLog*)this;
}
return NS_NOINTERFACE;
else if (aIID.Equals(kISupportsIID))
{
*aInstancePtr = (void*)(nsISupports*)(nsIUrlListener*)this;
}
else
return NS_NOINTERFACE;
NS_ADDREF_THIS();
return NS_OK;
}
nsresult nsIMAP4TestDriver::InitializeProtocol(const char * urlString)
@ -183,13 +194,20 @@ nsresult nsIMAP4TestDriver::InitializeProtocol(const char * urlString)
// this is called when we don't have a url nor a protocol instance yet...
// use service manager to get an imap 4 url...
rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull, nsIImapUrl::GetIID(), (void **) &m_url);
rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull,
nsIImapUrl::GetIID(), (void **)
&m_url);
// now create a protocol instance...
if (NS_SUCCEEDED(rv))
if (NS_SUCCEEDED(rv) && m_url)
{
m_url->SetImapLog(this);
rv = nsComponentManager::CreateInstance(kImapProtocolCID, nsnull, nsIImapProtocol::GetIID(), (void **) &m_IMAP4Protocol);
}
if (NS_SUCCEEDED(rv))
{
m_protocolInitialized = PR_TRUE;
m_IMAP4Protocol->Initialize(m_eventQueue);
}
return rv;
}
@ -382,8 +400,15 @@ nsresult nsIMAP4TestDriver::OnRunIMAPCommand()
if (m_protocolInitialized == PR_FALSE)
rv = InitializeProtocol(m_urlString);
if (m_url)
if (!m_url)
rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull,
nsIImapUrl::GetIID(), (void **)
&m_url);
if (NS_SUCCEEDED(rv) && m_url)
{
m_url->SetImapLog(this);
rv = m_url->SetSpec(m_urlString); // reset spec
}
if (NS_SUCCEEDED(rv))
{
@ -542,6 +567,11 @@ int main()
// nsComponentManager::RegisterComponent(kRDFServiceCID, nsnull, nsnull, RDF_DLL, PR_TRUE, PR_TRUE);
nsComponentManager::RegisterComponent(kPrefCID, nsnull, nsnull, PREF_DLL, PR_TRUE, PR_TRUE);
// IMAP Service goes here?
nsComponentManager::RegisterComponent(kImapUrlCID, nsnull, nsnull,
MSGIMAP_DLL, PR_FALSE, PR_FALSE);
nsComponentManager::RegisterComponent(kImapProtocolCID, nsnull, nsnull,
MSGIMAP_DLL, PR_FALSE, PR_FALSE);
// Create the Event Queue for the test app thread...a standin for the ui thread
nsIEventQueueService* pEventQService;