Working on NS_NewPostDataStream -- doesn't work yet though.

This commit is contained in:
warren%netscape.com 1999-07-21 05:53:25 +00:00
Родитель da5b107d26
Коммит 568cf0dedf
7 изменённых файлов: 97 добавлений и 31 удалений

Просмотреть файл

@ -65,6 +65,6 @@ protected:
#define NS_ERROR_BAD_REQUEST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 200);
// Create (or get) HTTP Handler
extern NS_METHOD CreateOrGetHTTPHandler(nsIHTTPHandler* *o_HTTPHandler);
extern NS_METHOD NS_CreateOrGetHTTPHandler(nsIHTTPHandler* *o_HTTPHandler);
#endif /* _nsIHTTPHandler_h_ */

Просмотреть файл

@ -17,39 +17,41 @@
*/
#include "nsHTTPEncodeStream.h"
#include "nsIHTTPProtocolHandler.h"
////////////////////////////////////////////////////////////////////////////////
// nsHTTPEncodeStream methods:
nsHTTPEncodeStream::nsHTTPEncodeStream()
: mInput(nsnull)
: mInput(nsnull), mFlags(nsIHTTPProtocolHandler::ENCODE_NORMAL),
mLastLineComplete(PR_TRUE)
{
NS_INIT_REFCNT();
}
nsresult
nsHTTPEncodeStream::Init(nsIInputStream* in)
nsHTTPEncodeStream::Init(nsIInputStream* in, PRUint32 flags)
{
mFlags = flags;
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::Create(nsIInputStream *rawStream, PRUint32 flags,
nsIInputStream **result)
{
nsHTTPEncodeStream* str = new nsHTTPEncodeStream();
if (str == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = str->Init(rawStream);
nsresult rv = str->Init(rawStream, flags);
if (NS_FAILED(rv)) {
NS_RELEASE(str);
return rv;
@ -78,21 +80,72 @@ nsHTTPEncodeStream::GetLength(PRUint32 *result)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTTPEncodeStream::Read(char * buf, PRUint32 count, PRUint32 *result)
nsresult
nsHTTPEncodeStream::GetData(char* buf, PRUint32 bufLen, PRUint32 *readCount)
{
*readCount = 0;
PRInt32 len = mPushBackBuffer.Length();
PRUint32 amt = PR_MIN((PRUint32)len, bufLen);
if (amt > 0) {
nsCRT::memcpy(buf, mPushBackBuffer.GetBuffer(), amt);
buf += amt;
bufLen -= amt;
*readCount += amt;
mPushBackBuffer.Cut(0, amt);
}
nsresult rv = NS_OK;
if (bufLen > 0) {
// get more from the input stream
rv = mInput->Read(buf, bufLen, &amt);
}
return rv;
}
nsresult
nsHTTPEncodeStream::PushBack(nsString& data)
{
mPushBackBuffer.Insert(data, 0);
return NS_OK;
}
NS_IMETHODIMP
nsHTTPEncodeStream::Read(char* outBuf, PRUint32 outBufCnt, PRUint32 *result)
{
#define BUF_SIZE 1024
char buffer[BUF_SIZE];
nsresult rv;
#define BUF_SIZE 1024
char readBuf[BUF_SIZE];
PRUint32 amt = 0;
PRUint32 amt;
rv = mInput->Read(buffer, BUF_SIZE, &amt);
if (NS_FAILED(rv)) return rv;
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
return rv;
while (outBufCnt > 0) {
PRUint32 readCnt = PR_MIN(outBufCnt, BUF_SIZE);
rv = GetData(readBuf, readCnt, &amt);
if (NS_FAILED(rv)) return rv;
if (rv == NS_BASE_STREAM_WOULD_BLOCK || amt == 0)
return rv;
if (mFlags & nsIHTTPProtocolHandler::ENCODE_QUOTE_LINES) {
// If this line begins with "." so we need to quote it
// by adding another "." to the beginning of the line.
nsCAutoString str(readBuf);
while (PR_TRUE) {
PRInt32 pos = str.Find("\012."); // LF .
if (pos == -1)
break;
PRUint32 cnt = PR_MIN((PRUint32)pos + 2, // +2 for LF and dot
outBufCnt - 1); // -1 for extra dot
nsCRT::memcpy(outBuf, readBuf, cnt);
outBuf += cnt;
outBufCnt -= cnt;
str.Cut(0, cnt);
}
}
nsCRT::memcpy(outBuf, readBuf, amt);
outBuf += amt;
outBufCnt -= amt;
}
return NS_OK;
}

Просмотреть файл

@ -20,6 +20,8 @@
#define nsHTTPEncodeStream_h__
#include "nsIInputStream.h"
#include "nsString.h"
#include "nsCOMPtr.h"
class nsHTTPEncodeStream : public nsIInputStream
{
@ -38,12 +40,18 @@ public:
virtual ~nsHTTPEncodeStream();
static NS_METHOD
Create(nsIInputStream *rawStream, nsIInputStream **result);
Create(nsIInputStream *rawStream, PRUint32 flags,
nsIInputStream **result);
nsresult Init(nsIInputStream *rawStream);
nsresult Init(nsIInputStream *rawStream, PRUint32 flags);
nsresult GetData(char* buf, PRUint32 bufLen, PRUint32 *readCount);
nsresult PushBack(nsString& data);
protected:
nsIInputStream* mInput;
nsCOMPtr<nsIInputStream> mInput;
PRUint32 mFlags;
nsString mPushBackBuffer;
PRBool mLastLineComplete;
};
#endif // nsHTTPEncodeStream_h__

Просмотреть файл

@ -305,19 +305,21 @@ nsHTTPHandler::FollowRedirects(PRBool bFollow)
}
NS_IMETHODIMP
nsHTTPHandler::NewEncodeStream(nsIInputStream *rawStream, nsIInputStream **result)
nsHTTPHandler::NewEncodeStream(nsIInputStream *rawStream, PRUint32 encodeFlags,
nsIInputStream **result)
{
return nsHTTPEncodeStream::Create(rawStream, result);
return nsHTTPEncodeStream::Create(rawStream, encodeFlags, result);
}
NS_IMETHODIMP
nsHTTPHandler::NewDecodeStream(nsIInputStream *encodedStream, nsIInputStream **result)
nsHTTPHandler::NewDecodeStream(nsIInputStream *encodedStream, PRUint32 decodeFlags,
nsIInputStream **result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTTPHandler::NewPostDataStream(PRBool isFile, const char *data,
nsHTTPHandler::NewPostDataStream(PRBool isFile, const char *data, PRUint32 encodeFlags,
nsIInputStream **result)
{
nsresult rv;
@ -332,7 +334,7 @@ nsHTTPHandler::NewPostDataStream(PRBool isFile, const char *data,
NS_RELEASE(in);
if (NS_FAILED(rv)) return rv;
rv = NewEncodeStream(rawStream, result);
rv = NewEncodeStream(rawStream, nsIHTTPProtocolHandler::ENCODE_NORMAL, result);
NS_RELEASE(rawStream);
return rv;
}

Просмотреть файл

@ -128,9 +128,12 @@ public:
*/
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);
NS_IMETHOD NewEncodeStream(nsIInputStream *rawStream, PRUint32 encodeFlags,
nsIInputStream **_retval);
NS_IMETHOD NewDecodeStream(nsIInputStream *encodedStream, PRUint32 decodeFlags,
nsIInputStream **_retval);
NS_IMETHOD NewPostDataStream(PRBool isFile, const char *data, PRUint32 encodeFlags,
nsIInputStream **_retval);
protected:
// None

Просмотреть файл

@ -57,7 +57,7 @@ NS_NewLoadGroup(nsISupports* outer, nsIStreamObserver* observer,
nsILoadGroup* parent, nsILoadGroup* *result);
extern nsresult
NS_NewPostDataStream(PRBool isFile, const char *data,
NS_NewPostDataStream(PRBool isFile, const char *data, PRUint32 encodeFlags,
nsIInputStream **result);
#endif // nsNeckoUtil_h__

Просмотреть файл

@ -136,7 +136,7 @@ NS_NewLoadGroup(nsISupports* outer, nsIStreamObserver* observer,
}
nsresult
NS_NewPostDataStream(PRBool isFile, const char *data,
NS_NewPostDataStream(PRBool isFile, const char *data, PRUint32 encodeFlags,
nsIInputStream **result)
{
nsresult rv;
@ -150,7 +150,7 @@ NS_NewPostDataStream(PRBool isFile, const char *data,
nsCOMPtr<nsIHTTPProtocolHandler> http = do_QueryInterface(handler, &rv);
if (NS_FAILED(rv)) return rv;
return http->NewPostDataStream(isFile, data, result);
return http->NewPostDataStream(isFile, data, encodeFlags, result);
}
////////////////////////////////////////////////////////////////////////////////