Added source offset parameter to OnDataAvailable (for byte-range requests).
git-svn-id: svn://10.0.0.236/trunk@28694 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -48,7 +48,8 @@ public:
|
||||
* @return The return value is currently ignored.
|
||||
*/
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength) = 0;
|
||||
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIByteBufferInputStream.h"
|
||||
#include "prcmon.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
@@ -33,7 +34,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
nsFileTransport::nsFileTransport()
|
||||
: mPath(nsnull), mContext(nsnull), mListener(nsnull), mState(ENDED),
|
||||
mSuspended(PR_FALSE), mFileStream(nsnull), mBufferStream(nsnull),
|
||||
mStatus(NS_OK), mService(nsnull)
|
||||
mStatus(NS_OK), mService(nsnull), mSourceOffset(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
@@ -222,7 +223,7 @@ nsFileTransport::OpenOutputStream(nsIOutputStream* *result)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
nsFileTransport::Continue(void)
|
||||
nsFileTransport::Process(void)
|
||||
{
|
||||
PR_CEnterMonitor(this);
|
||||
switch (mState) {
|
||||
@@ -255,9 +256,12 @@ nsFileTransport::Continue(void)
|
||||
if (NS_FAILED(mStatus)) goto error;
|
||||
|
||||
// and feed the buffer to the application via the byte buffer stream:
|
||||
mStatus = mListener->OnDataAvailable(mContext, mBufferStream, amt); // XXX maybe amt should be mBufferStream->GetLength()
|
||||
// XXX maybe amt should be mBufferStream->GetLength():
|
||||
mStatus = mListener->OnDataAvailable(mContext, mBufferStream, mSourceOffset, amt);
|
||||
if (NS_FAILED(mStatus)) goto error;
|
||||
|
||||
mSourceOffset += amt;
|
||||
|
||||
// stay in the READING state
|
||||
break;
|
||||
}
|
||||
@@ -316,7 +320,7 @@ NS_IMETHODIMP
|
||||
nsFileTransport::Run(void)
|
||||
{
|
||||
while (mState != ENDED && !mSuspended) {
|
||||
Continue();
|
||||
Process();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
nsresult Init(nsISupports* context,
|
||||
nsIStreamListener* listener,
|
||||
State state);
|
||||
void Continue(void);
|
||||
void Process(void);
|
||||
|
||||
protected:
|
||||
char* mPath;
|
||||
@@ -84,6 +84,7 @@ protected:
|
||||
nsIBaseStream* mFileStream; // cast to nsIInputStream/nsIOutputStream for reading/writing
|
||||
nsIByteBufferInputStream* mBufferStream;
|
||||
nsresult mStatus;
|
||||
PRUint32 mSourceOffset;
|
||||
};
|
||||
|
||||
#define NS_FILE_TRANSPORT_BUFFER_SIZE (4*1024)
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
// nsMarshalingStreamListener methods:
|
||||
@@ -240,11 +241,13 @@ public:
|
||||
mIStream(nsnull), mLength(0) {}
|
||||
virtual ~nsOnDataAvailableEvent();
|
||||
|
||||
nsresult Init(nsIInputStream* aIStream, PRUint32 aLength);
|
||||
nsresult Init(nsIInputStream* aIStream, PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
NS_IMETHOD HandleEvent();
|
||||
|
||||
protected:
|
||||
nsIInputStream* mIStream;
|
||||
PRUint32 mSourceOffset;
|
||||
PRUint32 mLength;
|
||||
};
|
||||
|
||||
@@ -254,8 +257,10 @@ nsOnDataAvailableEvent::~nsOnDataAvailableEvent()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsOnDataAvailableEvent::Init(nsIInputStream* aIStream, PRUint32 aLength)
|
||||
nsOnDataAvailableEvent::Init(nsIInputStream* aIStream, PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
mSourceOffset = aSourceOffset;
|
||||
mLength = aLength;
|
||||
mIStream = aIStream;
|
||||
NS_ADDREF(mIStream);
|
||||
@@ -266,12 +271,13 @@ NS_IMETHODIMP
|
||||
nsOnDataAvailableEvent::HandleEvent()
|
||||
{
|
||||
nsIStreamListener* receiver = (nsIStreamListener*)mListener->GetReceiver();
|
||||
return receiver->OnDataAvailable(mContext, mIStream, mLength);
|
||||
return receiver->OnDataAvailable(mContext, mIStream, mSourceOffset, mLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMarshalingStreamListener::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
nsresult rv = GetStatus();
|
||||
@@ -282,7 +288,7 @@ nsMarshalingStreamListener::OnDataAvailable(nsISupports* context,
|
||||
if (event == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = event->Init(aIStream, aLength);
|
||||
rv = event->Init(aIStream, aSourceOffset, aLength);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
rv = event->Fire(mEventQueue);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; 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
|
||||
@@ -124,6 +124,7 @@ nsSocketTransport::nsSocketTransport()
|
||||
mWriteStream = nsnull;
|
||||
mListener = nsnull;
|
||||
mContext = nsnull;
|
||||
mSourceOffset = 0;
|
||||
mService = nsnull;
|
||||
|
||||
//
|
||||
@@ -516,7 +517,8 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
|
||||
// been filled into the stream as possible...
|
||||
//
|
||||
if (totalBytesWritten) {
|
||||
mListener->OnDataAvailable(mContext, mReadStream, totalBytesWritten);
|
||||
mListener->OnDataAvailable(mContext, mReadStream, mSourceOffset, totalBytesWritten);
|
||||
mSourceOffset += totalBytesWritten;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -543,7 +545,7 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
|
||||
//-----
|
||||
nsresult nsSocketTransport::doWrite(PRInt16 aSelectFlags)
|
||||
{
|
||||
PRUint32 size, bytesRead;
|
||||
PRUint32 bytesRead;
|
||||
PRInt32 len;
|
||||
PRErrorCode code;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -110,6 +110,7 @@ protected:
|
||||
nsIStreamListener* mListener;
|
||||
nsIByteBufferInputStream* mReadStream;
|
||||
nsIInputStream* mWriteStream;
|
||||
PRUint32 mSourceOffset;
|
||||
|
||||
nsSocketTransportService* mService;
|
||||
};
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
NS_IMETHOD OnStartBinding(nsISupports* context);
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
NS_IMETHOD OnStopBinding(nsISupports* context,
|
||||
nsresult aStatus,
|
||||
@@ -47,7 +48,7 @@ public:
|
||||
nsresult Init(nsIInputStream* *result);
|
||||
|
||||
protected:
|
||||
nsIByteBufferOutputStream* mOutputStream;
|
||||
nsIOutputStream* mOutputStream;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -57,17 +58,10 @@ nsSyncStreamListener::Init(nsIInputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIInputStream* in;
|
||||
nsIOutputStream* out;
|
||||
|
||||
rv = NS_NewPipe(&in, &out);
|
||||
rv = NS_NewPipe(&in, &mOutputStream);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = out->QueryInterface(nsIByteBufferOutputStream::GetIID(), (void**)&mOutputStream);
|
||||
NS_RELEASE(out);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(in);
|
||||
return rv;
|
||||
}
|
||||
*result = in;
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -103,6 +97,7 @@ nsSyncStreamListener::OnStartBinding(nsISupports* context)
|
||||
NS_IMETHODIMP
|
||||
nsSyncStreamListener::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -316,8 +316,9 @@ nsFtpProtocolConnection::OnStopBinding(nsISupports* context,
|
||||
// routine/logic for handling.
|
||||
NS_IMETHODIMP
|
||||
nsFtpProtocolConnection::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aLength) {
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength) {
|
||||
nsresult rv;
|
||||
|
||||
// we've got some data. suck it out of the inputSteam.
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
// nsIStreamListener methods:
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
// nsFtpProtocolConnection methods:
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#ifndef nsIHttpEventSink_h___
|
||||
#define nsIHttpEventSink_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nscore.h"
|
||||
|
||||
class nsIUrl;
|
||||
@@ -37,7 +37,7 @@ class nsIUrl;
|
||||
* argument of nsINetService::NewConnection for http URLs. It defines
|
||||
* the callbacks to the application program (the html parser).
|
||||
*/
|
||||
class nsIHttpEventSink : public nsISupports
|
||||
class nsIHttpEventSink : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTTPEVENTSINK_IID);
|
||||
@@ -45,12 +45,17 @@ public:
|
||||
/**
|
||||
* Notify the EventSink that progress as occurred for the URL load.<BR>
|
||||
*/
|
||||
NS_IMETHOD OnProgress(nsIUrl* aURL, PRUint32 aProgress, PRUint32 aProgressMax) = 0;
|
||||
NS_IMETHOD OnProgress(nsISupports* context, PRUint32 aProgress, PRUint32 aProgressMax) = 0;
|
||||
|
||||
/**
|
||||
* Notify the EventSink with a status message for the URL load.<BR>
|
||||
*/
|
||||
NS_IMETHOD OnStatus(nsIUrl* aURL, const PRUnichar* aMsg) = 0;
|
||||
NS_IMETHOD OnStatus(nsISupports* context, const PRUnichar* aMsg) = 0;
|
||||
|
||||
/**
|
||||
* Called after the headers have been received signaling that they now may be accessed.
|
||||
*/
|
||||
NS_IMETHOD OnHeadersAvailable(nsISupports* context) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -241,6 +241,10 @@ nsHttpProtocolConnection::Get(void)
|
||||
rv = Write(in, CRLF, 2);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
// blank line to end the request
|
||||
rv = Write(in, CRLF, 2);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
// send it to the server:
|
||||
rv = mTransport->AsyncWrite(in,
|
||||
NS_STATIC_CAST(nsIProtocolConnection*, this),
|
||||
@@ -316,9 +320,25 @@ nsHttpProtocolConnection::OnStopBinding(nsISupports* context,
|
||||
NS_IMETHODIMP
|
||||
nsHttpProtocolConnection::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsresult rv = NS_OK;
|
||||
switch (mState) {
|
||||
case WAITING_REPLY:
|
||||
// data coming in for our request
|
||||
|
||||
// XXX do some header parsing here
|
||||
|
||||
// mEventSink->OnProgress();
|
||||
rv = mEventSink->OnDataAvailable(context, aIStream, aSourceOffset, aLength);
|
||||
|
||||
break;
|
||||
default:
|
||||
NS_NOTREACHED("bad state");
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
// nsIStreamListener methods:
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
// nsHttpProtocolConnection methods:
|
||||
|
||||
@@ -93,6 +93,7 @@ public:
|
||||
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength) {
|
||||
PR_CEnterMonitor(this);
|
||||
char buf[1025];
|
||||
@@ -171,6 +172,7 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
|
||||
nsIInputStream* fileStr = nsnull;
|
||||
nsIByteBufferInputStream* bufStr = nsnull;
|
||||
nsFileSpec spec(path);
|
||||
PRUint32 sourceOffset = 0;
|
||||
|
||||
rv = reader->OnStartBinding(nsnull);
|
||||
if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer?
|
||||
@@ -194,8 +196,10 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
|
||||
}
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
rv = reader->OnDataAvailable(nsnull, bufStr, amt);
|
||||
rv = reader->OnDataAvailable(nsnull, bufStr, sourceOffset, amt);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
sourceOffset += amt;
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIByteBufferInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#define XPCOM_DLL "xpcom32.dll"
|
||||
@@ -62,6 +63,7 @@ public:
|
||||
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
NS_IMETHOD OnStopBinding(nsISupports* context,
|
||||
@@ -95,6 +97,7 @@ InputTestConsumer::OnStartBinding(nsISupports* context)
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
char buf[1025];
|
||||
@@ -226,7 +229,7 @@ main(int argc, char* argv[])
|
||||
rv = NS_NewByteBufferInputStream(&stream);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *buffer = PR_smprintf("GET %s HTML/1.0\r\n\r\n", fileName);
|
||||
char *buffer = PR_smprintf("GET %s HTML/1.0%s%s", fileName, CRLF, CRLF);
|
||||
stream->Fill(buffer, strlen(buffer), &bytesWritten);
|
||||
printf("\n+++ Request is: %s\n", buffer);
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
|
||||
NS_IMETHOD OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
NS_IMETHOD OnStopBinding(nsISupports* context,
|
||||
@@ -90,6 +91,7 @@ InputTestConsumer::OnStartBinding(nsISupports* context)
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnDataAvailable(nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
char buf[1025];
|
||||
|
||||
Reference in New Issue
Block a user