More for http.

This commit is contained in:
warren%netscape.com 1999-04-14 00:06:07 +00:00
parent 63f4c3c732
commit 3a5c528a63
6 changed files with 130 additions and 16 deletions

View File

@ -144,6 +144,7 @@ nsFileTransport::Resume(void)
PR_CEnterMonitor(this);
switch (mState) {
case SUSPENDED:
// XXX re-open the stream and seek here?
mStatus = mService->Resume(this);
mState = RUNNING;

View File

@ -132,8 +132,6 @@ nsresult nsNetFactory::LockFactory(PRBool aLock)
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if (aFactory == nsnull)

View File

@ -34,6 +34,21 @@ class nsIHttpProtocolConnection : public nsIProtocolConnection
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTTPPROTOCOLCONNECTION_IID);
////////////////////////////////////////////////////////////////////////////
// Things that can be done at any time:
NS_IMETHOD GetHeader(const char* header) = 0;
////////////////////////////////////////////////////////////////////////////
// Things done before connecting:
NS_IMETHOD AddHeader(const char* header, const char* value) = 0;
NS_IMETHOD RemoveHeader(const char* header) = 0;
////////////////////////////////////////////////////////////////////////////
// Things done to connect:
NS_IMETHOD Get(void) = 0;
NS_IMETHOD GetByteRange(PRUint32 from, PRUint32 to) = 0;
@ -42,6 +57,9 @@ public:
NS_IMETHOD Post(void) = 0;
////////////////////////////////////////////////////////////////////////////
// Things done after connecting:
};
#endif /* nsIIHttpProtocolConnection_h___ */

View File

@ -104,8 +104,6 @@ nsresult nsNetFactory::LockFactory(PRBool aLock)
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if (aFactory == nsnull)

View File

@ -28,10 +28,12 @@
//static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); // XXX temporary
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
nsHttpProtocolConnection::nsHttpProtocolConnection()
: mUrl(nsnull), mEventSink(nsnull), mConnected(PR_FALSE)
: mUrl(nsnull), mEventSink(nsnull), mState(UNCONNECTED)
{
}
@ -50,11 +52,17 @@ nsHttpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
NS_ASSERTION(aInstancePtr, "no instance pointer");
if (aIID.Equals(nsIHttpProtocolConnection::GetIID()) ||
aIID.Equals(nsIProtocolConnection::GetIID()) ||
aIID.Equals(nsISupports::GetIID())) {
aIID.Equals(kISupportsIID)) {
*aInstancePtr = NS_STATIC_CAST(nsIHttpProtocolConnection*, this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIStreamListener::GetIID()) ||
aIID.Equals(nsIStreamObserver::GetIID())) {
*aInstancePtr = NS_STATIC_CAST(nsIStreamListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -67,7 +75,6 @@ nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink)
NS_ADDREF(mUrl);
rv = eventSink->QueryInterface(nsIHttpEventSink::GetIID(), (void**)&mEventSink);
return rv;
}
@ -77,24 +84,42 @@ nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink)
NS_IMETHODIMP
nsHttpProtocolConnection::Cancel(void)
{
if (!mConnected)
switch (mState) {
case CONNECTED:
break;
case POSTING:
break;
default:
return NS_ERROR_NOT_CONNECTED;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Suspend(void)
{
if (!mConnected)
switch (mState) {
case CONNECTED:
break;
case POSTING:
break;
default:
return NS_ERROR_NOT_CONNECTED;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Resume(void)
{
if (!mConnected)
switch (mState) {
case CONNECTED:
break;
case POSTING:
break;
default:
return NS_ERROR_NOT_CONNECTED;
}
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -104,7 +129,7 @@ nsHttpProtocolConnection::Resume(void)
NS_IMETHODIMP
nsHttpProtocolConnection::GetContentType(char* *contentType)
{
if (!mConnected)
if (mState != CONNECTED)
return NS_ERROR_NOT_CONNECTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -112,7 +137,7 @@ nsHttpProtocolConnection::GetContentType(char* *contentType)
NS_IMETHODIMP
nsHttpProtocolConnection::GetInputStream(nsIInputStream* *result)
{
if (!mConnected)
if (mState != CONNECTED)
return NS_ERROR_NOT_CONNECTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -120,7 +145,7 @@ nsHttpProtocolConnection::GetInputStream(nsIInputStream* *result)
NS_IMETHODIMP
nsHttpProtocolConnection::GetOutputStream(nsIOutputStream* *result)
{
if (!mConnected)
if (mState != CONNECTED)
return NS_ERROR_NOT_CONNECTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -130,7 +155,7 @@ nsHttpProtocolConnection::AsyncWrite(nsIInputStream* data, PRUint32 count,
nsresult (*callback)(void* closure, PRUint32 count),
void* closure)
{
if (!mConnected)
if (mState != CONNECTED)
return NS_ERROR_NOT_CONNECTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -138,15 +163,38 @@ nsHttpProtocolConnection::AsyncWrite(nsIInputStream* data, PRUint32 count,
////////////////////////////////////////////////////////////////////////////////
// nsIHttpProtocolConnection methods:
NS_IMETHODIMP
nsHttpProtocolConnection::GetHeader(const char* header)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHttpProtocolConnection::AddHeader(const char* header, const char* value)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHttpProtocolConnection::RemoveHeader(const char* header)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHttpProtocolConnection::Get(void)
{
nsresult rv;
// NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
// XXX temporary:
NS_WITH_SERVICE(nsIFileTransportService, sts, kFileTransportServiceCID, &rv);
const char* path = "y:/temp/foo.html";
// rv = sts->AsyncWrite();
nsITransport* trans;
// rv = sts->AsyncRead(path, context, appEventQueue, this, &trans);
if (NS_FAILED(rv)) return rv;
return rv;
}
@ -170,3 +218,31 @@ nsHttpProtocolConnection::Post(void)
}
////////////////////////////////////////////////////////////////////////////////
// nsIStreamObserver methods:
NS_IMETHODIMP
nsHttpProtocolConnection::OnStartBinding(nsISupports* context)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHttpProtocolConnection::OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
// nsIStreamListener methods:
NS_IMETHODIMP
nsHttpProtocolConnection::OnDataAvailable(nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aLength)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -20,11 +20,14 @@
#define nsHttpProtocolConnection_h___
#include "nsIHttpProtocolConnection.h"
#include "nsIStreamListener.h"
class nsIConnectionGroup;
class nsIHttpEventSink;
class nsIString;
class nsHttpProtocolConnection : public nsIHttpProtocolConnection
class nsHttpProtocolConnection : public nsIHttpProtocolConnection,
public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
@ -43,21 +46,41 @@ public:
void* closure);
// nsIHttpProtocolConnection methods:
NS_IMETHOD GetHeader(const char* header);
NS_IMETHOD AddHeader(const char* header, const char* value);
NS_IMETHOD RemoveHeader(const char* header);
NS_IMETHOD Get(void);
NS_IMETHOD GetByteRange(PRUint32 from, PRUint32 to);
NS_IMETHOD Put(void);
NS_IMETHOD Post(void);
// nsIStreamObserver methods:
NS_IMETHOD OnStartBinding(nsISupports* context);
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg);
// nsIStreamListener methods:
NS_IMETHOD OnDataAvailable(nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aLength);
// nsHttpProtocolConnection methods:
nsHttpProtocolConnection();
virtual ~nsHttpProtocolConnection();
nsresult Init(nsIUrl* url, nsISupports* eventSink);
enum State {
UNCONNECTED,
POSTING,
CONNECTED
};
protected:
nsIUrl* mUrl;
nsIHttpEventSink* mEventSink;
PRBool mConnected;
State mState;
};
#endif /* nsHttpProtocolConnection_h___ */