From 3a5c528a638be2f0185653b7b733d298e4365424 Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Wed, 14 Apr 1999 00:06:07 +0000 Subject: [PATCH] More for http. --- netwerk/base/src/nsFileTransport.cpp | 1 + netwerk/build/nsNetFactory.cpp | 2 - .../http/public/nsIHttpProtocolConnection.h | 18 ++++ netwerk/protocol/http/src/nsHttpFactory.cpp | 2 - .../http/src/nsHttpProtocolConnection.cpp | 96 +++++++++++++++++-- .../http/src/nsHttpProtocolConnection.h | 27 +++++- 6 files changed, 130 insertions(+), 16 deletions(-) diff --git a/netwerk/base/src/nsFileTransport.cpp b/netwerk/base/src/nsFileTransport.cpp index b66150b7f795..a47ddf07d418 100644 --- a/netwerk/base/src/nsFileTransport.cpp +++ b/netwerk/base/src/nsFileTransport.cpp @@ -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; diff --git a/netwerk/build/nsNetFactory.cpp b/netwerk/build/nsNetFactory.cpp index 589b23d536ea..45012595eaf9 100644 --- a/netwerk/build/nsNetFactory.cpp +++ b/netwerk/build/nsNetFactory.cpp @@ -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) diff --git a/netwerk/protocol/http/public/nsIHttpProtocolConnection.h b/netwerk/protocol/http/public/nsIHttpProtocolConnection.h index e50108763dc2..a9d9ebf7cec5 100644 --- a/netwerk/protocol/http/public/nsIHttpProtocolConnection.h +++ b/netwerk/protocol/http/public/nsIHttpProtocolConnection.h @@ -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___ */ diff --git a/netwerk/protocol/http/src/nsHttpFactory.cpp b/netwerk/protocol/http/src/nsHttpFactory.cpp index e0db3e7c825d..1db5f8dcb9ab 100644 --- a/netwerk/protocol/http/src/nsHttpFactory.cpp +++ b/netwerk/protocol/http/src/nsHttpFactory.cpp @@ -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) diff --git a/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp b/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp index 48feca91bbdd..95ff9f507c8f 100644 --- a/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp +++ b/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp @@ -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; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/netwerk/protocol/http/src/nsHttpProtocolConnection.h b/netwerk/protocol/http/src/nsHttpProtocolConnection.h index af9304fe3e4b..a832c7008105 100644 --- a/netwerk/protocol/http/src/nsHttpProtocolConnection.h +++ b/netwerk/protocol/http/src/nsHttpProtocolConnection.h @@ -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___ */