Added file transport stuff.

This commit is contained in:
warren%netscape.com 1999-04-02 09:25:17 +00:00
parent 9ee65b1f03
commit aaef99cff0
15 changed files with 568 additions and 171 deletions

View File

@ -19,16 +19,16 @@ MODULE = netwerk
DEPTH = ..\..\..
EXPORTS = \
nsICancelable.h \
nsIConnectionGroup.h \
nsINetService.h \
nsIProtocolConnection.h \
nsIProtocolHandler.h \
nsIStreamListener.h \
nsITransport.h \
nsITransportService.h \
nsIUrl.h \
EXPORTS = \
nsICancelable.h \
nsIConnectionGroup.h \
nsIFileTransportService.h \
nsINetService.h \
nsIProtocolConnection.h \
nsIProtocolHandler.h \
nsIStreamListener.h \
nsITransport.h \
nsIUrl.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 2; 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIFileTransportService_h___
#define nsIFileTransportService_h___
#include "nsISupports.h"
#include "plevent.h"
class nsIStreamObserver;
class nsIStreamListener;
class nsIProtocolConnection;
class nsITransport;
// XXX regenerate:
#define NS_IFILETRANSPORTSERVICE_IID \
{ /* 677d9a90-93ee-11d2-816a-006008119d7a */ \
0x677d9a90, \
0x93ee, \
0x11d2, \
{0x81, 0x6a, 0x00, 0x60, 0xf8, 0x12, 0x9d, 0x7a} \
}
// XXX regenerate:
#define NS_FILETRANSPORTSERVICE_CID \
{ /* 677d9a90-93ee-11d2-816a-006008119d7a */ \
0x677d9a90, \
0x93ee, \
0x11d2, \
{0x81, 0x6a, 0x00, 0x60, 0xf8, 0x32, 0x9d, 0x7a} \
}
class nsIFileTransportService : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILETRANSPORTSERVICE_IID);
NS_IMETHOD AsyncRead(PLEventQueue* appEventQueue,
nsIProtocolConnection* connection,
nsIStreamListener* listener,
const char* path,
nsITransport* *result) = 0;
NS_IMETHOD AsyncWrite(PLEventQueue* appEventQueue,
nsIProtocolConnection* connection,
nsIStreamObserver* observer,
const char* path,
nsITransport* *result) = 0;
};
////////////////////////////////////////////////////////////////////////////////
#endif /* nsIFileTransportService_h___ */

View File

@ -41,6 +41,10 @@ public:
NS_IMETHOD Open(nsIUrl* url, nsISupports* eventSink) = 0;
// can be called after Open
// freed by caller with delete[]
NS_IMETHOD GetContentType(char* *contentType);
// blocking:
NS_IMETHOD GetInputStream(nsIInputStream* *result) = 0;

View File

@ -25,6 +25,8 @@
class nsIUrl;
class nsIInputStream;
class nsIProtocolConnection;
class nsIString;
// XXX regenerate:
#define NS_ISTREAMLISTENER_IID \
@ -35,11 +37,6 @@ class nsIInputStream;
{0x81, 0x6a, 0x00, 0x60, 0x09, 0x11, 0x9d, 0x7a} \
}
struct nsStreamBindingInfo {
PRBool seekable;
/* ...more... */
};
class nsIStreamListener : public nsISupports
{
public:
@ -52,7 +49,7 @@ public:
* @return The return value is currently ignored. In the future it may be
* used to cancel the URL load..
*/
NS_IMETHOD OnStartBinding(nsIUrl* aUrl, const char *aContentType) = 0;
NS_IMETHOD OnStartBinding(nsIProtocolConnection* connection) = 0;
/**
* Notify the client that data is available in the input stream. This
@ -64,7 +61,8 @@ public:
* @param length The amount of data that was just pushed into the stream.
* @return The return value is currently ignored.
*/
NS_IMETHOD OnDataAvailable(nsIUrl* aUrl, nsIInputStream *aIStream,
NS_IMETHOD OnDataAvailable(nsIProtocolConnection* connection,
nsIInputStream *aIStream,
PRUint32 aLength) = 0;
/**
@ -78,16 +76,9 @@ public:
* @param msg A text string describing the error.
* @return The return value is currently ignored.
*/
NS_IMETHOD OnStopBinding(nsIUrl* aUrl, nsresult aStatus, const PRUnichar* aMsg) = 0;
/**
* Return information regarding the current URL load.<BR>
* The info structure that is passed in is filled out and returned
* to the caller.
*
* This method is currently not called.
*/
NS_IMETHOD GetBindInfo(nsIUrl* aUrl, nsStreamBindingInfo* aInfo) = 0;
NS_IMETHOD OnStopBinding(nsIProtocolConnection* connection,
nsresult aStatus,
nsIString* aMsg) = 0;
};

View File

@ -38,9 +38,6 @@ class nsITransport : public nsICancelable
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITRANSPORT_IID);
NS_IMETHOD AsyncRead(nsIStreamListener* listener) = 0;
NS_IMETHOD AsyncWrite(nsIStreamObserver* observer) = 0;
};
#endif /* nsIITransport_h___ */
#endif /* nsITransport_h___ */

View File

@ -23,6 +23,7 @@
#include "plevent.h"
class nsITransport;
class nsIStreamListener;
// XXX regenerate:
#define NS_ITRANSPORTSERVICE_IID \
@ -47,16 +48,20 @@ class nsITransportService : public nsISupports
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITRANSPORTSERVICE_IID);
NS_IMETHOD GetFileTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
NS_IMETHOD GetFileTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* path,
nsITransport* *result) = 0;
NS_IMETHOD GetSocketTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
NS_IMETHOD GetSocketTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* host, PRInt32 port,
nsITransport* *result) = 0;
NS_IMETHOD GetJarTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
const char* jarFilePath, const char* jarEntryPath,
NS_IMETHOD GetJarTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* jarFilePath,
const char* jarEntryPath,
nsITransport* *result) = 0;
/**

View File

@ -21,18 +21,19 @@ LCFLAGS = -DWIN32_LEAN_AND_MEAN
LIBRARY_NAME=netwerkbase_s
EXPORTS = \
nsConnectionGroup.h \
nsNetService.h \
nsTransportService.h \
nsUrl.h \
EXPORTS = \
nsConnectionGroup.h \
nsNetService.h \
nsFileTransportService.h \
nsUrl.h \
$(NULL)
CPP_OBJS = \
.\$(OBJDIR)\nsConnectionGroup.obj \
.\$(OBJDIR)\nsMarshalingStreamListener.obj \
.\$(OBJDIR)\nsFileTransport.obj \
.\$(OBJDIR)\nsFileTransportService.obj \
.\$(OBJDIR)\nsNetService.obj \
.\$(OBJDIR)\nsTransportService.obj \
.\$(OBJDIR)\nsUrl.obj \
$(NULL)

View File

@ -0,0 +1,162 @@
/* -*- Mode: C++; tab-width: 2; 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFileTransport.h"
#include "nsFileTransportService.h"
#include "nsIStreamListener.h"
#include "nsIProtocolConnection.h"
#include "nsCRT.h"
#include "nscore.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
// nsFileTransport methods:
nsFileTransport::nsFileTransport()
: mPath(nsnull), mListener(nsnull), mCanceled(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsFileTransport::~nsFileTransport()
{
if (mPath)
delete mPath;
NS_IF_RELEASE(mListener);
}
nsresult
nsFileTransport::Init(const char* path,
nsIStreamListener* listener,
PLEventQueue* appEventQueue,
nsIProtocolConnection* connection)
{
nsresult rv;
mPath = nsCRT::strdup(path);
if (mPath == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
mConnection = connection;
NS_ADDREF(mConnection);
rv = NS_NewMarshalingStreamListener(appEventQueue, listener, &mListener);
if (NS_FAILED(rv)) return rv;
return rv;
}
NS_IMPL_ADDREF(nsFileTransport);
NS_IMPL_RELEASE(nsFileTransport);
NS_IMETHODIMP
nsFileTransport::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsITransport::GetIID()) ||
aIID.Equals(nsICancelable::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aInstancePtr = NS_STATIC_CAST(nsITransport*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIRunnable::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIRunnable*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
// nsICancelable methods:
NS_IMETHODIMP
nsFileTransport::Cancel(void)
{
mCanceled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsFileTransport::Suspend(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFileTransport::Resume(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
nsresult
nsFileTransport::OnStartBinding()
{
return mListener->OnStartBinding(mConnection);
}
nsresult
nsFileTransport::OnDataAvailable(nsIInputStream* stream, PRUint32 count)
{
return mListener->OnDataAvailable(mConnection, stream, count);
}
nsresult
nsFileTransport::OnStopBinding(nsresult status, nsIString* msg)
{
return mListener->OnStopBinding(mConnection, status, msg);
}
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileTransport::Run(void)
{
nsresult rv;
#if 0
nsISupports* fs;
nsIInputStream* inStr;
request->OnStartBinding(mConnection); // always send the start notification
rv = NS_NewTypicalInputFileStream(&fs, request->mSpec);
if (NS_FAILED(rv)) goto done;
rv = fs->QueryInterface(nsIInputStream::GetIID(), (void**)&inStr);
NS_RELEASE(fs);
if (NS_FAILED(rv)) goto done;
while (PR_TRUE) {
if (request->IsCanceled()) {
rv = NS_USER_CANCELED;
break;
}
request->OnDataAvailable(mConnection, inStr, count);
}
done:
request->OnStopBinding(mConnection, rv, msg);
NS_RELEASE(inStr);
#endif
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 2; 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsFileTransport_h___
#define nsFileTransport_h___
#include "nsITransport.h"
#include "nsIThread.h"
#include "plevent.h"
class nsFileTransportService;
class nsIProtocolConnection;
class nsIInputStream;
class nsIString;
class nsFileTransport : public nsITransport, public nsIRunnable
{
public:
NS_DECL_ISUPPORTS
// nsICancelable methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
// nsITransport methods:
// nsIRunnable methods:
NS_IMETHOD Run(void);
// nsFileTransport methods:
nsFileTransport();
virtual ~nsFileTransport();
nsresult Init(const char* path,
nsIStreamListener* listener,
PLEventQueue* appEventQueue,
nsIProtocolConnection* connection);
PRBool IsCanceled() { return mCanceled; }
nsresult OnStartBinding();
nsresult OnDataAvailable(nsIInputStream* stream, PRUint32 count);
nsresult OnStopBinding(nsresult status, nsIString* msg);
protected:
nsIProtocolConnection* mConnection;
char* mPath;
nsIStreamListener* mListener;
PRBool mCanceled;
};
#endif /* nsFileTransport_h___ */

View File

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 2; 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFileTransportService.h"
#include "nsFileTransport.h"
#include "nsIThread.h"
#include "nsIFileStream.h"
#include "prcmon.h"
#include "prmem.h"
////////////////////////////////////////////////////////////////////////////////
// nsFileTransportService methods:
nsFileTransportService::nsFileTransportService()
: mPool(nsnull)
{
NS_INIT_REFCNT();
}
nsresult
nsFileTransportService::Init()
{
nsresult rv;
rv = NS_NewThreadPool(&mPool, NS_FILE_TRANSPORT_WORKER_COUNT,
NS_FILE_TRANSPORT_WORKER_COUNT, 8*1024);
return rv;
}
nsFileTransportService::~nsFileTransportService()
{
NS_IF_RELEASE(mPool);
}
NS_IMPL_ISUPPORTS(nsFileTransportService, nsIFileTransportService::GetIID());
NS_IMETHODIMP
nsFileTransportService::AsyncRead(PLEventQueue* appEventQueue,
nsIProtocolConnection* connection,
nsIStreamListener* listener,
const char* path,
nsITransport* *result)
{
nsFileTransport* trans = new nsFileTransport();
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = trans->Init(path, listener, appEventQueue, connection);
if (NS_FAILED(rv)) {
delete trans;
return rv;
}
NS_ADDREF(trans);
rv = mPool->DispatchRequest(NS_STATIC_CAST(nsIRunnable*, trans));
if (NS_FAILED(rv)) {
NS_RELEASE(trans);
return rv;
}
*result = trans;
return NS_OK;
}
NS_IMETHODIMP
nsFileTransportService::AsyncWrite(PLEventQueue* appEventQueue,
nsIProtocolConnection* connection,
nsIStreamObserver* observer,
const char* path,
nsITransport* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 2; 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsFileTransportService_h___
#define nsFileTransportService_h___
#include "nsIFileTransportService.h"
#include "nsISupportsArray.h"
#include "nsIThread.h"
#include "nscore.h"
#include "plevent.h"
class nsIStreamObserver;
class nsIStreamListener;
class nsITransport;
class nsFileTransport;
class nsFileTransportService;
class nsIProtocolConnection;
////////////////////////////////////////////////////////////////////////////////
#define NS_FILE_TRANSPORT_WORKER_COUNT 4
class nsFileTransportService : public nsISupports
{
public:
NS_DECL_ISUPPORTS
// nsIFileTransportService methods:
NS_IMETHOD AsyncRead(PLEventQueue* appEventQueue,
nsIProtocolConnection* connection,
nsIStreamListener* listener,
const char* path,
nsITransport* *result);
NS_IMETHOD AsyncWrite(PLEventQueue* appEventQueue,
nsIProtocolConnection* connection,
nsIStreamObserver* observer,
const char* path,
nsITransport* *result);
// nsFileTransportService methods:
nsFileTransportService();
virtual ~nsFileTransportService();
nsresult Init();
protected:
nsIThreadPool* mPool;
};
////////////////////////////////////////////////////////////////////////////////
#endif /* nsFileTransportService_h___ */

View File

@ -17,8 +17,9 @@
*/
#include "nsIStreamListener.h"
#include "nsIUrl.h"
#include "nsIProtocolConnection.h"
#include "nsIInputStream.h"
#include "nsIString.h"
#include "nsCRT.h"
class nsMarshalingStreamListener : public nsIStreamListener
@ -27,11 +28,13 @@ public:
NS_DECL_ISUPPORTS
// nsIStreamListener methods:
NS_IMETHOD OnStartBinding(nsIUrl* aUrl, const char *aContentType);
NS_IMETHOD OnDataAvailable(nsIUrl* aUrl, nsIInputStream *aIStream,
NS_IMETHOD OnStartBinding(nsIProtocolConnection* connection);
NS_IMETHOD OnDataAvailable(nsIProtocolConnection* connection,
nsIInputStream *aIStream,
PRUint32 aLength);
NS_IMETHOD OnStopBinding(nsIUrl* aUrl, nsresult aStatus, const PRUnichar* aMsg);
NS_IMETHOD GetBindInfo(nsIUrl* aUrl, nsStreamBindingInfo* aInfo);
NS_IMETHOD OnStopBinding(nsIProtocolConnection* connection,
nsresult aStatus,
nsIString* aMsg);
// nsMarshalingStreamListener methods:
nsMarshalingStreamListener(PLEventQueue* eventQueue,
@ -56,7 +59,8 @@ protected:
class nsStreamListenerEvent : public PLEvent
{
public:
nsStreamListenerEvent(nsMarshalingStreamListener* listener, nsIUrl* url);
nsStreamListenerEvent(nsMarshalingStreamListener* listener,
nsIProtocolConnection* connection);
virtual ~nsStreamListenerEvent();
nsresult Fire(PLEventQueue* aEventQ);
@ -68,22 +72,23 @@ protected:
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);
nsMarshalingStreamListener* mListener;
nsIUrl* mURL;
nsIProtocolConnection* mConnection;
};
////////////////////////////////////////////////////////////////////////////////
nsStreamListenerEvent::nsStreamListenerEvent(nsMarshalingStreamListener* listener, nsIUrl* url)
: mListener(listener), mURL(url)
nsStreamListenerEvent::nsStreamListenerEvent(nsMarshalingStreamListener* listener,
nsIProtocolConnection* connection)
: mListener(listener), mConnection(connection)
{
NS_ADDREF(mListener);
NS_ADDREF(mURL);
NS_ADDREF(mConnection);
}
nsStreamListenerEvent::~nsStreamListenerEvent()
{
NS_RELEASE(mListener);
NS_RELEASE(mURL);
NS_RELEASE(mConnection);
}
void PR_CALLBACK nsStreamListenerEvent::HandlePLEvent(PLEvent* aEvent)
@ -131,11 +136,11 @@ NS_IMPL_ISUPPORTS(nsMarshalingStreamListener, nsIStreamListener::GetIID());
class nsOnStartBindingEvent : public nsStreamListenerEvent
{
public:
nsOnStartBindingEvent(nsMarshalingStreamListener* listener, nsIUrl* url)
: nsStreamListenerEvent(listener, url), mContentType(nsnull) {}
nsOnStartBindingEvent(nsMarshalingStreamListener* listener,
nsIProtocolConnection* connection)
: nsStreamListenerEvent(listener, connection), mContentType(nsnull) {}
virtual ~nsOnStartBindingEvent();
nsresult Init(const char* aContentType);
NS_IMETHOD HandleEvent();
protected:
@ -148,34 +153,23 @@ nsOnStartBindingEvent::~nsOnStartBindingEvent()
delete[] mContentType;
}
nsresult
nsOnStartBindingEvent::Init(const char* aContentType)
{
mContentType = nsCRT::strdup(aContentType);
if (mContentType == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsOnStartBindingEvent::HandleEvent()
{
return mListener->GetReceiver()->OnStartBinding(mURL, mContentType);
return mListener->GetReceiver()->OnStartBinding(mConnection);
}
NS_IMETHODIMP
nsMarshalingStreamListener::OnStartBinding(nsIUrl* aUrl, const char *aContentType)
nsMarshalingStreamListener::OnStartBinding(nsIProtocolConnection* connection)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStartBindingEvent* event =
new nsOnStartBindingEvent(this, aUrl);
new nsOnStartBindingEvent(this, connection);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aContentType);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
@ -190,8 +184,10 @@ nsMarshalingStreamListener::OnStartBinding(nsIUrl* aUrl, const char *aContentTyp
class nsOnDataAvailableEvent : public nsStreamListenerEvent
{
public:
nsOnDataAvailableEvent(nsMarshalingStreamListener* listener, nsIUrl* url)
: nsStreamListenerEvent(listener, url), mIStream(nsnull), mLength(0) {}
nsOnDataAvailableEvent(nsMarshalingStreamListener* listener,
nsIProtocolConnection* connection)
: nsStreamListenerEvent(listener, connection),
mIStream(nsnull), mLength(0) {}
virtual ~nsOnDataAvailableEvent();
nsresult Init(nsIInputStream* aIStream, PRUint32 aLength);
@ -219,18 +215,19 @@ nsOnDataAvailableEvent::Init(nsIInputStream* aIStream, PRUint32 aLength)
NS_IMETHODIMP
nsOnDataAvailableEvent::HandleEvent()
{
return mListener->GetReceiver()->OnDataAvailable(mURL, mIStream, mLength);
return mListener->GetReceiver()->OnDataAvailable(mConnection, mIStream, mLength);
}
NS_IMETHODIMP
nsMarshalingStreamListener::OnDataAvailable(nsIUrl* aUrl, nsIInputStream *aIStream,
nsMarshalingStreamListener::OnDataAvailable(nsIProtocolConnection* connection,
nsIInputStream *aIStream,
PRUint32 aLength)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnDataAvailableEvent* event =
new nsOnDataAvailableEvent(this, aUrl);
new nsOnDataAvailableEvent(this, connection);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -250,49 +247,49 @@ nsMarshalingStreamListener::OnDataAvailable(nsIUrl* aUrl, nsIInputStream *aIStre
class nsOnStopBindingEvent : public nsStreamListenerEvent
{
public:
nsOnStopBindingEvent(nsMarshalingStreamListener* listener, nsIUrl* url)
: nsStreamListenerEvent(listener, url), mStatus(NS_OK), mMessage(nsnull) {}
nsOnStopBindingEvent(nsMarshalingStreamListener* listener,
nsIProtocolConnection* connection)
: nsStreamListenerEvent(listener, connection),
mStatus(NS_OK), mMessage(nsnull) {}
virtual ~nsOnStopBindingEvent();
nsresult Init(nsresult status, const PRUnichar* aMsg);
nsresult Init(nsresult status, nsIString* aMsg);
NS_IMETHOD HandleEvent();
protected:
nsresult mStatus;
PRUnichar* mMessage;
nsIString* mMessage;
};
nsOnStopBindingEvent::~nsOnStopBindingEvent()
{
if (mMessage)
delete[] mMessage;
NS_RELEASE(mMessage);
}
nsresult
nsOnStopBindingEvent::Init(nsresult status, const PRUnichar* aMsg)
nsOnStopBindingEvent::Init(nsresult status, nsIString* aMsg)
{
mStatus = status;
mMessage = nsCRT::strdup(aMsg);
if (mMessage == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
mMessage = aMsg;
NS_ADDREF(mMessage);
return NS_OK;
}
NS_IMETHODIMP
nsOnStopBindingEvent::HandleEvent()
{
return mListener->GetReceiver()->OnStopBinding(mURL, mStatus, mMessage);
return mListener->GetReceiver()->OnStopBinding(mConnection, mStatus, mMessage);
}
NS_IMETHODIMP
nsMarshalingStreamListener::OnStopBinding(nsIUrl* aUrl, nsresult aStatus,
const PRUnichar* aMsg)
nsMarshalingStreamListener::OnStopBinding(nsIProtocolConnection* connection,
nsresult aStatus,
nsIString* aMsg)
{
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsOnStopBindingEvent* event =
new nsOnStopBindingEvent(this, aUrl);
new nsOnStopBindingEvent(this, connection);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -309,71 +306,6 @@ nsMarshalingStreamListener::OnStopBinding(nsIUrl* aUrl, nsresult aStatus,
////////////////////////////////////////////////////////////////////////////////
#if 0
class nsGetBindInfoEvent : public nsStreamListenerEvent
{
public:
nsGetBindInfoEvent(nsMarshalingStreamListener* listener, nsIUrl* url)
: nsStreamListenerEvent(listener, url), mContentType(nsnull) {}
virtual ~nsGetBindInfoEvent();
nsresult Init(const char* aContentType);
NS_IMETHOD HandleEvent();
protected:
char* mContentType;
};
nsGetBindInfoEvent::~nsGetBindInfoEvent()
{
if (mContentType)
delete[] mContentType;
}
nsresult
nsGetBindInfoEvent::Init(const char* aContentType)
{
mContentType = nsCRT::strdup(aContentType);
if (mContentType == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsGetBindInfoEvent::HandleEvent()
{
return mListener->GetReceiver()->GetBindInfo(mURL, mContentType);
}
#endif
NS_IMETHODIMP
nsMarshalingStreamListener::GetBindInfo(nsIUrl* aUrl, nsStreamBindingInfo* aInfo)
{
#if 0
nsresult rv = GetStatus();
if (NS_FAILED(rv)) return rv;
nsGetBindInfoEvent* event =
new nsGetBindInfoEvent(this, aUrl);
if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = event->Init(aContentType);
if (NS_FAILED(rv)) goto failed;
rv = event->Fire(mEventQueue);
if (NS_FAILED(rv)) goto failed;
return rv;
failed:
delete event;
return rv;
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
////////////////////////////////////////////////////////////////////////////////
nsresult
NS_NewMarshalingStreamListener(PLEventQueue* eventQueue,
nsIStreamListener* receiver,

View File

@ -17,6 +17,7 @@
*/
#include "nsTransportService.h"
#include "nsFileTransport.h"
NS_IMPL_ISUPPORTS(nsTransportService, nsITransportService::GetIID());
@ -42,15 +43,18 @@ nsTransportService::Init()
// nsITransportService methods:
NS_IMETHODIMP
nsTransportService::GetFileTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
nsTransportService::GetFileTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* path,
nsITransport* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsTransportService::GetSocketTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
nsTransportService::GetSocketTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* host, PRInt32 port,
nsITransport* *result)
{
@ -58,8 +62,10 @@ nsTransportService::GetSocketTransport(PLEventQueue* appEventQueue, nsISupports*
}
NS_IMETHODIMP
nsTransportService::GetJarTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
const char* jarFilePath, const char* jarEntryPath,
nsTransportService::GetJarTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* jarFilePath,
const char* jarEntryPath,
nsITransport* *result)
{
return NS_ERROR_NOT_IMPLEMENTED;
@ -72,4 +78,3 @@ nsTransportService::HasActiveTransports()
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -27,14 +27,18 @@ public:
NS_DECL_ISUPPORTS
// nsITransportService methods:
NS_IMETHOD GetFileTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
NS_IMETHOD GetFileTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* path,
nsITransport* *result);
NS_IMETHOD GetSocketTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
NS_IMETHOD GetSocketTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* host, PRInt32 port,
nsITransport* *result);
NS_IMETHOD GetJarTransport(PLEventQueue* appEventQueue, nsISupports* eventSink,
const char* jarFilePath, const char* jarEntryPath,
NS_IMETHOD GetJarTransport(PLEventQueue* appEventQueue,
nsIStreamListener* listener,
const char* jarFilePath,
const char* jarEntryPath,
nsITransport* *result);
NS_IMETHOD HasActiveTransports();

View File

@ -20,12 +20,12 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsNetService.h"
#include "nsTransportService.h"
#include "nsFileTransportService.h"
#include "nscore.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_CID(kTransportServiceCID, NS_TRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
@ -91,8 +91,8 @@ nsNetFactory::CreateInstance(nsISupports *aOuter,
}
inst = net;
}
else if (mClassID.Equals(kTransportServiceCID)) {
nsTransportService* trans = new nsTransportService();
else if (mClassID.Equals(kFileTransportServiceCID)) {
nsFileTransportService* trans = new nsFileTransportService();
if (trans == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = trans->Init();
@ -153,9 +153,9 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;;
rv = compMgr->RegisterComponent(kTransportServiceCID,
"Transport Service",
"component://netscape/network/transport-service",
rv = compMgr->RegisterComponent(kFileTransportServiceCID,
"File Transport Service",
"component://netscape/network/file-transport-service",
aPath, PR_TRUE, PR_TRUE);
return rv;
}
@ -171,7 +171,7 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
rv = compMgr->UnregisterComponent(kNetServiceCID, aPath);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kTransportServiceCID, aPath);
rv = compMgr->UnregisterComponent(kFileTransportServiceCID, aPath);
return rv;
}