diff --git a/mozilla/netwerk/protocol/http/public/Makefile.in b/mozilla/netwerk/protocol/http/public/Makefile.in index 2e06448c43b..d34e99aa723 100644 --- a/mozilla/netwerk/protocol/http/public/Makefile.in +++ b/mozilla/netwerk/protocol/http/public/Makefile.in @@ -25,14 +25,14 @@ VPATH = @srcdir@ XPIDL_MODULE = necko_http -XPIDLSRCS = \ - nsIHTTPChannel.idl \ - nsIHttpNotify.idl \ +XPIDLSRCS = \ + nsIHTTPChannel.idl \ + nsIHttpNotify.idl \ + nsIHTTPProtocolHandler.idl \ $(NULL) EXPORTS = \ nsIHttpEventSink.h \ - nsIHTTPHandler.h \ nsHTTPEnums.h \ nsIHTTPCommonHeaders.h \ nsIHTTPRequest.h \ diff --git a/mozilla/netwerk/protocol/http/public/makefile.win b/mozilla/netwerk/protocol/http/public/makefile.win index 088343c3de9..da220c4ba40 100644 --- a/mozilla/netwerk/protocol/http/public/makefile.win +++ b/mozilla/netwerk/protocol/http/public/makefile.win @@ -27,14 +27,14 @@ PUBLIC = $(DEPTH)\netwerk\dist\include XPIDL_MODULE = necko_http -XPIDLSRCS = \ - .\nsIHTTPChannel.idl \ - .\nsIHttpNotify.idl \ +XPIDLSRCS = \ + .\nsIHTTPChannel.idl \ + .\nsIHttpNotify.idl \ + .\nsIHTTPProtocolHandler.idl \ $(NULL) EXPORTS = \ nsIHTTPEventSink.h \ - nsIHTTPHandler.h \ nsHTTPEnums.h \ $(NULL) diff --git a/mozilla/netwerk/protocol/http/public/nsIHTTPProtocolHandler.idl b/mozilla/netwerk/protocol/http/public/nsIHTTPProtocolHandler.idl new file mode 100644 index 00000000000..86f4e4aa2e8 --- /dev/null +++ b/mozilla/netwerk/protocol/http/public/nsIHTTPProtocolHandler.idl @@ -0,0 +1,59 @@ +/* -*- 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 "nsIProtocolHandler.idl" + +interface nsIInputStream; + +[scriptable, uuid(ad1d53ae-3e25-11d3-8cd3-0060b0fc14a3)] +interface nsIHTTPProtocolHandler : nsIProtocolHandler +{ + nsIChannel GetTransport(in string host, + in unsigned long port); + + void ReleaseTransport(in string host, + in unsigned long port, + in nsIChannel transport); + + /** + * + */ + nsIInputStream NewEncodeStream(in nsIInputStream rawStream); + + /** + * + */ + nsIInputStream NewDecodeStream(in nsIInputStream encodedStream); + + /** + * + */ + nsIInputStream NewPostDataStream(in boolean isFile, + in string data); + +}; + +%{C++ + +//Possible errors +#define NS_ERROR_BAD_REQUEST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 200); + +// Create (or get) HTTP Handler +extern NS_METHOD NS_CreateOrGetHTTPHandler(nsIHTTPProtocolHandler* *o_HTTPHandler); + +%} diff --git a/mozilla/netwerk/protocol/http/src/Makefile.in b/mozilla/netwerk/protocol/http/src/Makefile.in index 124cb763b8d..f84c09cf5a9 100644 --- a/mozilla/netwerk/protocol/http/src/Makefile.in +++ b/mozilla/netwerk/protocol/http/src/Makefile.in @@ -32,6 +32,7 @@ CPPSRCS = \ nsHTTPRequest.cpp \ nsHTTPResponseListener.cpp \ nsHTTPResponse.cpp \ + nsHTTPEncodeStream.cpp \ $(NULL) EXPORTS= \ diff --git a/mozilla/netwerk/protocol/http/src/makefile.win b/mozilla/netwerk/protocol/http/src/makefile.win index 4a9f72855ca..1365d04dc3a 100644 --- a/mozilla/netwerk/protocol/http/src/makefile.win +++ b/mozilla/netwerk/protocol/http/src/makefile.win @@ -56,6 +56,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsHTTPRequest.obj \ .\$(OBJDIR)\nsHTTPResponseListener.obj \ .\$(OBJDIR)\nsHTTPResponse.obj \ + .\$(OBJDIR)\nsHTTPEncodeStream.obj \ $(NULL) LOCAL_INCLUDES=-I. diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp new file mode 100644 index 00000000000..18b45be1d5a --- /dev/null +++ b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; 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 "nsHTTPEncodeStream.h" + +//////////////////////////////////////////////////////////////////////////////// +// nsHTTPEncodeStream methods: + +nsHTTPEncodeStream::nsHTTPEncodeStream() + : mInput(nsnull) +{ + NS_INIT_REFCNT(); +} + +nsresult +nsHTTPEncodeStream::Init(nsIInputStream* in) +{ + mInput = in; + NS_ADDREF(mInput); + return NS_OK; +} + +nsHTTPEncodeStream::~nsHTTPEncodeStream() +{ + NS_IF_RELEASE(mInput); +} + +NS_IMPL_ISUPPORTS(nsHTTPEncodeStream, nsIInputStream::GetIID()); + +NS_METHOD +nsHTTPEncodeStream::Create(nsIInputStream *rawStream, nsIInputStream **result) +{ + nsHTTPEncodeStream* str = new nsHTTPEncodeStream(); + if (str == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = str->Init(rawStream); + if (NS_FAILED(rv)) { + NS_RELEASE(str); + return rv; + } + *result = str; + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIBaseStream methods: + +NS_IMETHODIMP +nsHTTPEncodeStream::Close(void) +{ + return mInput->Close(); +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIInputStream methods: + +NS_IMETHODIMP +nsHTTPEncodeStream::GetLength(PRUint32 *result) +{ + // XXX Ugh! This requires buffering up the translation so that you can + // count it, because to walk it consumes the input. + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTTPEncodeStream::Read(char * buf, PRUint32 count, PRUint32 *result) +{ +#define BUF_SIZE 1024 + char buffer[BUF_SIZE]; + nsresult rv; + + PRUint32 amt; + rv = mInput->Read(buffer, BUF_SIZE, &amt); + if (NS_FAILED(rv)) return rv; + if (rv == NS_BASE_STREAM_WOULD_BLOCK) + return rv; + + + + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h new file mode 100644 index 00000000000..a8edc7b3a7f --- /dev/null +++ b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; 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 nsHTTPEncodeStream_h__ +#define nsHTTPEncodeStream_h__ + +#include "nsIInputStream.h" + +class nsHTTPEncodeStream : public nsIInputStream +{ +public: + NS_DECL_ISUPPORTS + + // nsIBaseStream methods: + NS_IMETHOD Close(void); + + // nsIInputStream methods: + NS_IMETHOD GetLength(PRUint32 *result); + NS_IMETHOD Read(char * buf, PRUint32 count, PRUint32 *result); + + // nsHTTPEncodeStream methods: + nsHTTPEncodeStream(); + virtual ~nsHTTPEncodeStream(); + + static NS_METHOD + Create(nsIInputStream *rawStream, nsIInputStream **result); + + nsresult Init(nsIInputStream *rawStream); + +protected: + nsIInputStream* mInput; +}; + +#endif // nsHTTPEncodeStream_h__ diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp index 97f77d4aa78..c9c386e1b31 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp @@ -29,6 +29,9 @@ #include "nsIServiceManager.h" #include "nsIEventSinkGetter.h" #include "nsIHttpEventSink.h" +#include "nsIFileStream.h" +#include "nsIStringStream.h" +#include "nsHTTPEncodeStream.h" #if defined(PR_LOGGING) // @@ -49,7 +52,7 @@ PRLogModuleInfo* gHTTPLog = nsnull; static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID); static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); -NS_METHOD CreateOrGetHTTPHandler(nsIHTTPHandler* *o_HTTPHandler) +NS_METHOD NS_CreateOrGetHTTPHandler(nsIHTTPProtocolHandler* *o_HTTPHandler) { #if defined(PR_LOGGING) // @@ -177,8 +180,8 @@ nsHTTPHandler::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } - if (aIID.Equals(nsCOMTypeInfo::GetIID())) { - *aInstancePtr = (void*) ((nsIHTTPHandler*)this); + if (aIID.Equals(nsCOMTypeInfo::GetIID())) { + *aInstancePtr = (void*) ((nsIHTTPProtocolHandler*)this); NS_ADDREF_THIS(); return NS_OK; } @@ -242,7 +245,7 @@ nsHTTPHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, NS_METHOD nsHTTPHandler::GetTransport(const char* i_Host, - PRUint32& i_Port, + PRUint32 i_Port, nsIChannel** o_pTrans) { #if 0 @@ -280,7 +283,7 @@ nsHTTPHandler::GetTransport(const char* i_Host, NS_METHOD nsHTTPHandler::ReleaseTransport(const char* i_Host, - PRUint32& i_Port, + PRUint32 i_Port, nsIChannel* i_pTrans) { #if 0 @@ -300,3 +303,47 @@ nsHTTPHandler::FollowRedirects(PRBool bFollow) //m_bFollowRedirects = bFollow; return NS_OK; } + +NS_IMETHODIMP +nsHTTPHandler::NewEncodeStream(nsIInputStream *rawStream, nsIInputStream **result) +{ + return nsHTTPEncodeStream::Create(rawStream, result); +} + +NS_IMETHODIMP +nsHTTPHandler::NewDecodeStream(nsIInputStream *encodedStream, nsIInputStream **result) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTTPHandler::NewPostDataStream(PRBool isFile, const char *data, + nsIInputStream **result) +{ + nsresult rv; + if (isFile) { + nsISupports* in; + nsFileSpec spec(data); + rv = NS_NewTypicalInputFileStream(&in, spec); + if (NS_FAILED(rv)) return rv; + + nsIInputStream* rawStream; + rv = in->QueryInterface(nsIInputStream::GetIID(), (void**)&rawStream); + NS_RELEASE(in); + if (NS_FAILED(rv)) return rv; + + rv = NewEncodeStream(rawStream, result); + NS_RELEASE(rawStream); + return rv; + } + else { + nsISupports* in; + rv = NS_NewStringInputStream(&in, data); + if (NS_FAILED(rv)) return rv; + + rv = in->QueryInterface(nsIInputStream::GetIID(), (void**)result); + NS_RELEASE(in); + return rv; + } +} + diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.h b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.h index 4d3ff413fde..9d77079a3cc 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPHandler.h +++ b/mozilla/netwerk/protocol/http/src/nsHTTPHandler.h @@ -35,8 +35,7 @@ */ //TODO turnon the proxy stuff as well. -#include "nsIHTTPHandler.h" -#include "nsIProtocolHandler.h" +#include "nsIHTTPProtocolHandler.h" #include "nsIChannel.h" #include "nsCOMPtr.h" #include "nsISupportsArray.h" @@ -46,7 +45,7 @@ class nsHashtable; class nsIChannel; -class nsHTTPHandler : public nsIHTTPHandler +class nsHTTPHandler : public nsIHTTPProtocolHandler //, public nsIProxy { @@ -89,7 +88,7 @@ public: NS_IMETHOD NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval); - //Functions from nsIHTTPHandler + //Functions from nsIHTTPProtocolHandler #if 0 //Functions from nsIProxy @@ -118,16 +117,20 @@ public: return pHandler; }; - // Functions from nsIHTTPHandler + // Functions from nsIHTTPProtocolHandler /* Pull out an existing transport from the hashtable, or if none exists create one. */ - NS_IMETHOD GetTransport(const char* i_Host, PRUint32& i_Port, nsIChannel* *o_pTrans); + NS_IMETHOD GetTransport(const char* i_Host, PRUint32 i_Port, nsIChannel* *o_pTrans); /* Remove this transport from the hashtable. */ - NS_IMETHOD ReleaseTransport(const char* i_Host, PRUint32& i_Port, nsIChannel* i_pTrans); + NS_IMETHOD ReleaseTransport(const char* i_Host, PRUint32 i_Port, nsIChannel* i_pTrans); + + NS_IMETHOD NewEncodeStream(nsIInputStream *rawStream, nsIInputStream **_retval); + NS_IMETHOD NewDecodeStream(nsIInputStream *encodedStream, nsIInputStream **_retval); + NS_IMETHOD NewPostDataStream(PRBool isFile, const char *data, nsIInputStream **_retval); protected: // None