mshtml: Added support for custom post data type.

This commit is contained in:
Jacek Caban 2010-08-03 21:40:56 +02:00 committed by Alexandre Julliard
parent ac65368835
commit 22679a2419
3 changed files with 72 additions and 22 deletions

View File

@ -462,6 +462,7 @@ typedef struct {
nsWineURI *uri;
nsIInputStream *post_data_stream;
BOOL parse_stream;
nsILoadGroup *load_group;
nsIInterfaceRequestor *notif_callback;
nsISupports *owner;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 Jacek Caban for CodeWeavers
* Copyright 2006-2010 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -679,20 +679,48 @@ static HRESULT parse_headers(const WCHAR *headers, struct list *headers_list)
return S_OK;
}
static HRESULT read_post_data_stream(nsIInputStream *stream, HGLOBAL *post_data,
ULONG *post_data_len)
{
PRUint32 data_len = 0, available = 0;
char *data;
nsresult nsres;
nsres = nsIInputStream_Available(stream, &available);
if(NS_FAILED(nsres))
return E_FAIL;
data = GlobalAlloc(0, available+1);
if(!data)
return E_OUTOFMEMORY;
nsres = nsIInputStream_Read(stream, data, available, &data_len);
if(NS_FAILED(nsres)) {
GlobalFree(data);
return E_FAIL;
}
data[data_len] = 0;
*post_data = data;
*post_data_len = data_len;
return S_OK;
}
static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
{
PRUint32 post_data_len = 0, available = 0;
ULONG post_data_len;
HGLOBAL post_data = NULL;
LPWSTR headers = NULL;
DWORD headers_len = 0, len;
const char *ptr, *ptr2, *post_data_end;
HRESULT hres;
nsIInputStream_Available(post_data_stream, &available);
post_data = GlobalAlloc(0, available+1);
nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
hres = read_post_data_stream(post_data_stream, &post_data, &post_data_len);
if(FAILED(hres)) {
FIXME("read_post_data_stream failed: %08x\n", hres);
return;
}
ptr = ptr2 = post_data;
post_data_end = (const char*)post_data+post_data_len;
@ -1088,20 +1116,27 @@ static HRESULT nsChannelBSC_start_binding(BSCallback *bsc)
static HRESULT nsChannelBSC_init_bindinfo(BSCallback *bsc)
{
nsChannelBSC *This = NSCHANNELBSC_THIS(bsc);
if(This->nschannel && This->nschannel->post_data_stream) {
WCHAR *headers;
HRESULT hres;
parse_post_data(This->nschannel->post_data_stream, &headers, &This->bsc.post_data, &This->bsc.post_data_len);
if(This->nschannel && This->nschannel->post_data_stream) {
if(This->nschannel->parse_stream) {
WCHAR *headers;
TRACE("headers = %s post_data = %s\n", debugstr_w(headers),
debugstr_an(This->bsc.post_data, This->bsc.post_data_len));
parse_post_data(This->nschannel->post_data_stream, &headers,
&This->bsc.post_data, &This->bsc.post_data_len);
hres = parse_headers(headers, &This->nschannel->request_headers);
heap_free(headers);
if(FAILED(hres))
return hres;
}else {
hres = read_post_data_stream(This->nschannel->post_data_stream,
&This->bsc.post_data, &This->bsc.post_data_len);
if(FAILED(hres))
return hres;
}
TRACE("post_data = %s\n", debugstr_an(This->bsc.post_data, This->bsc.post_data_len));
}
return S_OK;

View File

@ -1323,17 +1323,31 @@ static nsresult NSAPI nsUploadChannel_SetUploadStream(nsIUploadChannel *iface,
nsChannel *This = NSUPCHANNEL_THIS(iface);
const char *content_type;
static const WCHAR content_typeW[] =
{'C','o','n','t','e','n','t','-','T','y','p','e',0};
TRACE("(%p)->(%p %s %d)\n", This, aStream, debugstr_nsacstr(aContentType), aContentLength);
This->parse_stream = TRUE;
if(aContentType) {
nsACString_GetData(aContentType, &content_type);
if(*content_type) {
WCHAR *ct;
ct = heap_strdupAtoW(content_type);
if(!ct)
return NS_ERROR_UNEXPECTED;
set_http_header(&This->request_headers, content_typeW,
sizeof(content_typeW)/sizeof(WCHAR), ct, strlenW(ct));
heap_free(ct);
This->parse_stream = FALSE;
}
}
if(This->post_data_stream)
nsIInputStream_Release(This->post_data_stream);
if(aContentType) {
nsACString_GetData(aContentType, &content_type);
if(*content_type)
FIXME("Unsupported aContentType argument: %s\n", debugstr_a(content_type));
}
if(aContentLength != -1)
FIXME("Unsupported acontentLength = %d\n", aContentLength);