2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
39 #define CONTENT_LENGTH "Content-Length"
41 #define NSINSTREAM(x) ((nsIInputStream*) &(x)->lpInputStreamVtbl)
43 #define NSINSTREAM_THIS(iface) DEFINE_THIS(nsProtocolStream, InputStream, iface)
45 static nsresult NSAPI
nsInputStream_QueryInterface(nsIInputStream
*iface
, nsIIDRef riid
,
48 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
52 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
53 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
54 *result
= NSINSTREAM(This
);
55 }else if(IsEqualGUID(&IID_nsIInputStream
, riid
)) {
56 TRACE("(%p)->(IID_nsIInputStream %p)\n", This
, result
);
57 *result
= NSINSTREAM(This
);
61 nsIInputStream_AddRef(NSINSTREAM(This
));
65 WARN("unsupported interface %s\n", debugstr_guid(riid
));
66 return NS_NOINTERFACE
;
69 static nsrefcnt NSAPI
nsInputStream_AddRef(nsIInputStream
*iface
)
71 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
72 LONG ref
= InterlockedIncrement(&This
->ref
);
74 TRACE("(%p) ref=%d\n", This
, ref
);
80 static nsrefcnt NSAPI
nsInputStream_Release(nsIInputStream
*iface
)
82 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
83 LONG ref
= InterlockedDecrement(&This
->ref
);
85 TRACE("(%p) ref=%d\n", This
, ref
);
93 static nsresult NSAPI
nsInputStream_Close(nsIInputStream
*iface
)
95 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
96 FIXME("(%p)\n", This
);
97 return NS_ERROR_NOT_IMPLEMENTED
;
100 static nsresult NSAPI
nsInputStream_Available(nsIInputStream
*iface
, PRUint32
*_retval
)
102 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
103 FIXME("(%p)->(%p)\n", This
, _retval
);
104 return NS_ERROR_NOT_IMPLEMENTED
;
107 static nsresult NSAPI
nsInputStream_Read(nsIInputStream
*iface
, char *aBuf
, PRUint32 aCount
,
110 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
112 TRACE("(%p)->(%p %d %p)\n", This
, aBuf
, aCount
, _retval
);
114 /* Gecko always calls Read with big enough buffer */
115 if(aCount
< This
->buf_size
)
116 FIXME("aCount < This->buf_size\n");
118 *_retval
= This
->buf_size
;
120 memcpy(aBuf
, This
->buf
, This
->buf_size
);
126 static nsresult NSAPI
nsInputStream_ReadSegments(nsIInputStream
*iface
,
127 nsresult (WINAPI
*aWriter
)(nsIInputStream
*,void*,const char*,PRUint32
,PRUint32
,PRUint32
*),
128 void *aClousure
, PRUint32 aCount
, PRUint32
*_retval
)
130 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
131 PRUint32 written
= 0;
134 TRACE("(%p)->(%p %p %d %p)\n", This
, aWriter
, aClousure
, aCount
, _retval
);
139 if(This
->buf_size
> aCount
)
140 FIXME("buf_size > aCount\n");
142 nsres
= aWriter(NSINSTREAM(This
), aClousure
, This
->buf
, 0, This
->buf_size
, &written
);
144 FIXME("aWritter failed: %08x\n", nsres
);
145 if(written
!= This
->buf_size
)
146 FIXME("written != buf_size\n");
148 This
->buf_size
-= written
;
153 static nsresult NSAPI
nsInputStream_IsNonBlocking(nsIInputStream
*iface
, PRBool
*_retval
)
155 nsProtocolStream
*This
= NSINSTREAM_THIS(iface
);
156 FIXME("(%p)->(%p)\n", This
, _retval
);
157 return NS_ERROR_NOT_IMPLEMENTED
;
160 #undef NSINSTREAM_THIS
162 static const nsIInputStreamVtbl nsInputStreamVtbl
= {
163 nsInputStream_QueryInterface
,
164 nsInputStream_AddRef
,
165 nsInputStream_Release
,
167 nsInputStream_Available
,
169 nsInputStream_ReadSegments
,
170 nsInputStream_IsNonBlocking
173 static nsProtocolStream
*create_nsprotocol_stream(IStream
*stream
)
175 nsProtocolStream
*ret
= mshtml_alloc(sizeof(nsProtocolStream
));
177 ret
->lpInputStreamVtbl
= &nsInputStreamVtbl
;
184 #define STATUSCLB_THIS(iface) DEFINE_THIS(BSCallback, BindStatusCallback, iface)
186 static HRESULT WINAPI
BindStatusCallback_QueryInterface(IBindStatusCallback
*iface
,
187 REFIID riid
, void **ppv
)
189 BSCallback
*This
= STATUSCLB_THIS(iface
);
192 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
193 TRACE("(%p)->(IID_IUnknown, %p)\n", This
, ppv
);
194 *ppv
= STATUSCLB(This
);
195 }else if(IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
196 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This
, ppv
);
197 *ppv
= STATUSCLB(This
);
198 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
199 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
200 *ppv
= SERVPROV(This
);
201 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
202 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
203 *ppv
= HTTPNEG(This
);
204 }else if(IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
205 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This
, ppv
);
206 *ppv
= HTTPNEG(This
);
207 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
208 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
209 *ppv
= BINDINFO(This
);
213 IBindStatusCallback_AddRef(STATUSCLB(This
));
217 TRACE("Unsupported riid = %s\n", debugstr_guid(riid
));
218 return E_NOINTERFACE
;
221 static ULONG WINAPI
BindStatusCallback_AddRef(IBindStatusCallback
*iface
)
223 BSCallback
*This
= STATUSCLB_THIS(iface
);
224 LONG ref
= InterlockedIncrement(&This
->ref
);
226 TRACE("(%p) ref = %d\n", This
, ref
);
231 static ULONG WINAPI
BindStatusCallback_Release(IBindStatusCallback
*iface
)
233 BSCallback
*This
= STATUSCLB_THIS(iface
);
234 LONG ref
= InterlockedDecrement(&This
->ref
);
236 TRACE("(%p) ref = %d\n", This
, ref
);
240 GlobalFree(This
->post_data
);
242 nsIChannel_Release(NSCHANNEL(This
->nschannel
));
244 nsIStreamListener_Release(This
->nslistener
);
246 nsISupports_Release(This
->nscontext
);
248 nsIInputStream_Release(NSINSTREAM(This
->nsstream
));
250 IMoniker_Release(This
->mon
);
252 IBinding_Release(This
->binding
);
253 mshtml_free(This
->headers
);
260 static HRESULT WINAPI
BindStatusCallback_OnStartBinding(IBindStatusCallback
*iface
,
261 DWORD dwReserved
, IBinding
*pbind
)
263 BSCallback
*This
= STATUSCLB_THIS(iface
);
265 TRACE("(%p)->(%d %p)\n", This
, dwReserved
, pbind
);
267 IBinding_AddRef(pbind
);
268 This
->binding
= pbind
;
273 static HRESULT WINAPI
BindStatusCallback_GetPriority(IBindStatusCallback
*iface
, LONG
*pnPriority
)
275 BSCallback
*This
= STATUSCLB_THIS(iface
);
276 FIXME("(%p)->(%p)\n", This
, pnPriority
);
280 static HRESULT WINAPI
BindStatusCallback_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
282 BSCallback
*This
= STATUSCLB_THIS(iface
);
283 FIXME("(%p)->(%d)\n", This
, reserved
);
287 static HRESULT WINAPI
BindStatusCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
288 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
290 BSCallback
*This
= STATUSCLB_THIS(iface
);
292 TRACE("%p)->(%u %u %u %s)\n", This
, ulProgress
, ulProgressMax
, ulStatusCode
,
293 debugstr_w(szStatusText
));
295 switch(ulStatusCode
) {
296 case BINDSTATUS_MIMETYPEAVAILABLE
: {
301 mshtml_free(This
->nschannel
->content
);
303 len
= WideCharToMultiByte(CP_ACP
, 0, szStatusText
, -1, NULL
, 0, NULL
, NULL
);
304 This
->nschannel
->content
= mshtml_alloc(len
*sizeof(WCHAR
));
305 WideCharToMultiByte(CP_ACP
, 0, szStatusText
, -1, This
->nschannel
->content
, -1, NULL
, NULL
);
312 static HRESULT WINAPI
BindStatusCallback_OnStopBinding(IBindStatusCallback
*iface
,
313 HRESULT hresult
, LPCWSTR szError
)
315 BSCallback
*This
= STATUSCLB_THIS(iface
);
317 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
319 IBinding_Release(This
->binding
);
320 This
->binding
= NULL
;
322 if(This
->nslistener
) {
323 nsIStreamListener_OnStopRequest(This
->nslistener
, (nsIRequest
*)NSCHANNEL(This
->nschannel
),
324 This
->nscontext
, NS_OK
);
326 if(This
->nschannel
->load_group
) {
329 nsres
= nsILoadGroup_RemoveRequest(This
->nschannel
->load_group
,
330 (nsIRequest
*)NSCHANNEL(This
->nschannel
), NULL
, NS_OK
);
332 ERR("RemoveRequest failed: %08x\n", nsres
);
337 task_t
*task
= mshtml_alloc(sizeof(task_t
));
339 task
->doc
= This
->doc
;
340 task
->task_id
= TASK_PARSECOMPLETE
;
344 * This should be done in the worker thread that parses HTML,
345 * but we don't have such thread (Gecko parses HTML for us).
353 static HRESULT WINAPI
BindStatusCallback_GetBindInfo(IBindStatusCallback
*iface
,
354 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
356 BSCallback
*This
= STATUSCLB_THIS(iface
);
359 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
361 *grfBINDF
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
363 size
= pbindinfo
->cbSize
;
364 memset(pbindinfo
, 0, size
);
365 pbindinfo
->cbSize
= size
;
367 pbindinfo
->cbstgmedData
= This
->post_data_len
;
368 pbindinfo
->dwCodePage
= CP_UTF8
;
369 pbindinfo
->dwOptions
= 0x80000;
371 if(This
->post_data
) {
372 pbindinfo
->dwBindVerb
= BINDVERB_POST
;
374 pbindinfo
->stgmedData
.tymed
= TYMED_HGLOBAL
;
375 pbindinfo
->stgmedData
.u
.hGlobal
= This
->post_data
;
376 pbindinfo
->stgmedData
.pUnkForRelease
= (IUnknown
*)STATUSCLB(This
);
377 IBindStatusCallback_AddRef(STATUSCLB(This
));
383 static HRESULT WINAPI
BindStatusCallback_OnDataAvailable(IBindStatusCallback
*iface
,
384 DWORD grfBSCF
, DWORD dwSize
, FORMATETC
*pformatetc
, STGMEDIUM
*pstgmed
)
386 BSCallback
*This
= STATUSCLB_THIS(iface
);
390 TRACE("(%p)->(%08x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
392 if(This
->nslistener
) {
393 if(!This
->nsstream
) {
394 This
->nsstream
= create_nsprotocol_stream(pstgmed
->u
.pstm
);
396 nsres
= nsIStreamListener_OnStartRequest(This
->nslistener
,
397 (nsIRequest
*)NSCHANNEL(This
->nschannel
), This
->nscontext
);
399 FIXME("OnStartRequest failed: %08x\n", nsres
);
403 hres
= IStream_Read(pstgmed
->u
.pstm
, This
->nsstream
->buf
, sizeof(This
->nsstream
->buf
),
404 &This
->nsstream
->buf_size
);
405 if(!This
->nsstream
->buf_size
)
408 nsres
= nsIStreamListener_OnDataAvailable(This
->nslistener
,
409 (nsIRequest
*)NSCHANNEL(This
->nschannel
), This
->nscontext
,
410 NSINSTREAM(This
->nsstream
), This
->readed
, This
->nsstream
->buf_size
);
412 FIXME("OnDataAvailable failed: %08x\n", nsres
);
414 if(This
->nsstream
->buf_size
)
415 FIXME("buffer is not empty!\n");
417 This
->readed
+= This
->nsstream
->buf_size
;
418 }while(hres
== S_OK
);
424 static HRESULT WINAPI
BindStatusCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
425 REFIID riid
, IUnknown
*punk
)
427 BSCallback
*This
= STATUSCLB_THIS(iface
);
428 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), punk
);
432 #undef STATUSCLB_THIS
434 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
435 BindStatusCallback_QueryInterface
,
436 BindStatusCallback_AddRef
,
437 BindStatusCallback_Release
,
438 BindStatusCallback_OnStartBinding
,
439 BindStatusCallback_GetPriority
,
440 BindStatusCallback_OnLowResource
,
441 BindStatusCallback_OnProgress
,
442 BindStatusCallback_OnStopBinding
,
443 BindStatusCallback_GetBindInfo
,
444 BindStatusCallback_OnDataAvailable
,
445 BindStatusCallback_OnObjectAvailable
448 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
450 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
,
451 REFIID riid
, void **ppv
)
453 BSCallback
*This
= HTTPNEG_THIS(iface
);
454 return IBindStatusCallback_QueryInterface(STATUSCLB(This
), riid
, ppv
);
457 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
459 BSCallback
*This
= HTTPNEG_THIS(iface
);
460 return IBindStatusCallback_AddRef(STATUSCLB(This
));
463 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
465 BSCallback
*This
= HTTPNEG_THIS(iface
);
466 return IBindStatusCallback_Release(STATUSCLB(This
));
469 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
,
470 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
472 BSCallback
*This
= HTTPNEG_THIS(iface
);
475 TRACE("(%p)->(%s %s %d %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
),
476 dwReserved
, pszAdditionalHeaders
);
479 *pszAdditionalHeaders
= NULL
;
483 size
= (strlenW(This
->headers
)+1)*sizeof(WCHAR
);
484 *pszAdditionalHeaders
= CoTaskMemAlloc(size
);
485 memcpy(*pszAdditionalHeaders
, This
->headers
, size
);
490 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
491 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
493 BSCallback
*This
= HTTPNEG_THIS(iface
);
494 FIXME("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
495 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
499 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
500 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
502 BSCallback
*This
= HTTPNEG_THIS(iface
);
503 FIXME("(%p)->(%p %p %ld)\n", This
, pbSecurityId
, pcbSecurityId
, dwReserved
);
509 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl
= {
510 HttpNegotiate_QueryInterface
,
511 HttpNegotiate_AddRef
,
512 HttpNegotiate_Release
,
513 HttpNegotiate_BeginningTransaction
,
514 HttpNegotiate_OnResponse
,
515 HttpNegotiate_GetRootSecurityId
518 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
520 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
521 REFIID riid
, void **ppv
)
523 BSCallback
*This
= BINDINFO_THIS(iface
);
524 return IBindStatusCallback_QueryInterface(STATUSCLB(This
), riid
, ppv
);
527 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
529 BSCallback
*This
= BINDINFO_THIS(iface
);
530 return IBindStatusCallback_AddRef(STATUSCLB(This
));
533 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
535 BSCallback
*This
= BINDINFO_THIS(iface
);
536 return IBindStatusCallback_Release(STATUSCLB(This
));
539 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
540 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
542 BSCallback
*This
= BINDINFO_THIS(iface
);
543 FIXME("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
547 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
548 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
550 BSCallback
*This
= BINDINFO_THIS(iface
);
551 FIXME("(%p)->(%u %p %u %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
557 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
558 InternetBindInfo_QueryInterface
,
559 InternetBindInfo_AddRef
,
560 InternetBindInfo_Release
,
561 InternetBindInfo_GetBindInfo
,
562 InternetBindInfo_GetBindString
565 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
567 static HRESULT WINAPI
BSCServiceProvider_QueryInterface(IServiceProvider
*iface
,
568 REFIID riid
, void **ppv
)
570 BSCallback
*This
= SERVPROV_THIS(iface
);
571 return IBindStatusCallback_QueryInterface(STATUSCLB(This
), riid
, ppv
);
574 static ULONG WINAPI
BSCServiceProvider_AddRef(IServiceProvider
*iface
)
576 BSCallback
*This
= SERVPROV_THIS(iface
);
577 return IBindStatusCallback_AddRef(STATUSCLB(This
));
580 static ULONG WINAPI
BSCServiceProvider_Release(IServiceProvider
*iface
)
582 BSCallback
*This
= SERVPROV_THIS(iface
);
583 return IBindStatusCallback_Release(STATUSCLB(This
));
586 static HRESULT WINAPI
BSCServiceProvider_QueryService(IServiceProvider
*iface
,
587 REFGUID guidService
, REFIID riid
, void **ppv
)
589 BSCallback
*This
= SERVPROV_THIS(iface
);
590 FIXME("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
596 static const IServiceProviderVtbl ServiceProviderVtbl
= {
597 BSCServiceProvider_QueryInterface
,
598 BSCServiceProvider_AddRef
,
599 BSCServiceProvider_Release
,
600 BSCServiceProvider_QueryService
603 BSCallback
*create_bscallback(IMoniker
*mon
)
605 BSCallback
*ret
= mshtml_alloc(sizeof(BSCallback
));
607 ret
->lpBindStatusCallbackVtbl
= &BindStatusCallbackVtbl
;
608 ret
->lpServiceProviderVtbl
= &ServiceProviderVtbl
;
609 ret
->lpHttpNegotiate2Vtbl
= &HttpNegotiate2Vtbl
;
610 ret
->lpInternetBindInfoVtbl
= &InternetBindInfoVtbl
;
612 ret
->post_data
= NULL
;
614 ret
->post_data_len
= 0;
616 ret
->nschannel
= NULL
;
617 ret
->nslistener
= NULL
;
618 ret
->nscontext
= NULL
;
619 ret
->nsstream
= NULL
;
624 IMoniker_AddRef(mon
);
630 static void parse_post_data(nsIInputStream
*post_data_stream
, LPWSTR
*headers_ret
,
631 HGLOBAL
*post_data_ret
, ULONG
*post_data_len_ret
)
633 PRUint32 post_data_len
= 0, available
= 0;
634 HGLOBAL post_data
= NULL
;
635 LPWSTR headers
= NULL
;
636 DWORD headers_len
= 0, len
;
637 const char *ptr
, *ptr2
, *post_data_end
;
639 nsIInputStream_Available(post_data_stream
, &available
);
640 post_data
= GlobalAlloc(0, available
+1);
641 nsIInputStream_Read(post_data_stream
, post_data
, available
, &post_data_len
);
643 TRACE("post_data = %s\n", debugstr_an(post_data
, post_data_len
));
645 ptr
= ptr2
= post_data
;
646 post_data_end
= (const char*)post_data
+post_data_len
;
648 while(ptr
< post_data_end
&& (*ptr
!= '\r' || ptr
[1] != '\n')) {
649 while(ptr
< post_data_end
&& (*ptr
!= '\r' || ptr
[1] != '\n'))
659 if(ptr
-ptr2
>= sizeof(CONTENT_LENGTH
)
660 && CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
,
661 CONTENT_LENGTH
, sizeof(CONTENT_LENGTH
)-1,
662 ptr2
, sizeof(CONTENT_LENGTH
)-1) == CSTR_EQUAL
) {
667 len
= MultiByteToWideChar(CP_ACP
, 0, ptr2
, ptr
-ptr2
, NULL
, 0);
670 headers
= mshtml_realloc(headers
,(headers_len
+len
+1)*sizeof(WCHAR
));
672 headers
= mshtml_alloc((len
+1)*sizeof(WCHAR
));
674 len
= MultiByteToWideChar(CP_ACP
, 0, ptr2
, ptr
-ptr2
, headers
+headers_len
, -1);
680 headers
[headers_len
] = 0;
681 *headers_ret
= headers
;
683 if(ptr
>= post_data_end
-2) {
684 GlobalFree(post_data
);
691 post_data_len
-= ptr
-(const char*)post_data
;
692 memmove(post_data
, ptr
, post_data_len
);
693 post_data
= GlobalReAlloc(post_data
, post_data_len
+1, 0);
696 *post_data_ret
= post_data
;
697 *post_data_len_ret
= post_data_len
;
700 void hlink_frame_navigate(HTMLDocument
*doc
, IHlinkFrame
*hlink_frame
,
701 LPCWSTR uri
, nsIInputStream
*post_data_stream
, DWORD hlnf
)
703 BSCallback
*callback
;
708 callback
= create_bscallback(NULL
);
710 if(post_data_stream
) {
711 parse_post_data(post_data_stream
, &callback
->headers
, &callback
->post_data
,
712 &callback
->post_data_len
);
713 TRACE("headers = %s post_data = %s\n", debugstr_w(callback
->headers
),
714 debugstr_an(callback
->post_data
, callback
->post_data_len
));
717 CreateAsyncBindCtx(0, STATUSCLB(callback
), NULL
, &bindctx
);
719 hlink
= Hlink_Create();
721 CreateURLMoniker(NULL
, uri
, &mon
);
722 IHlink_SetMonikerReference(hlink
, 0, mon
, NULL
);
724 if(hlnf
& HLNF_OPENINNEWWINDOW
) {
725 static const WCHAR wszBlank
[] = {'_','b','l','a','n','k',0};
726 IHlink_SetTargetFrameName(hlink
, wszBlank
); /* FIXME */
729 IHlinkFrame_Navigate(hlink_frame
, hlnf
, bindctx
, STATUSCLB(callback
), hlink
);
731 IBindCtx_Release(bindctx
);
732 IBindStatusCallback_Release(STATUSCLB(callback
));
733 IMoniker_Release(mon
);
737 HRESULT
start_binding(BSCallback
*bscallback
)
743 hres
= CreateAsyncBindCtx(0, STATUSCLB(bscallback
), NULL
, &bctx
);
745 WARN("CreateAsyncBindCtx failed: %08x\n", hres
);
749 hres
= IMoniker_BindToStorage(bscallback
->mon
, bctx
, NULL
, &IID_IStream
, (void**)&str
);
750 IBindCtx_Release(bctx
);
752 WARN("BindToStorage failed: %08x\n", hres
);
757 IStream_Release(str
);
759 IMoniker_Release(bscallback
->mon
);
760 bscallback
->mon
= NULL
;
764 void set_document_bscallback(HTMLDocument
*doc
, BSCallback
*callback
)
766 if(doc
->bscallback
) {
767 if(doc
->bscallback
->binding
)
768 IBinding_Abort(doc
->bscallback
->binding
);
769 doc
->bscallback
->doc
= NULL
;
770 IBindStatusCallback_Release(STATUSCLB(doc
->bscallback
));
773 doc
->bscallback
= callback
;
776 IBindStatusCallback_AddRef(STATUSCLB(callback
));