crypt32: Fix a cast for Win64.
[wine/multimedia.git] / dlls / mshtml / navigate.c
blob09e0814b0581614857b2d412faf25414fa05f151
1 /*
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
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,
46 nsQIResult result)
48 nsProtocolStream *This = NSINSTREAM_THIS(iface);
50 *result = NULL;
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);
60 if(*result) {
61 nsIInputStream_AddRef(NSINSTREAM(This));
62 return NS_OK;
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=%ld\n", This, ref);
76 return 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=%ld\n", This, ref);
87 if(!ref)
88 HeapFree(GetProcessHeap(), 0, This);
90 return 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,
108 PRUint32 *_retval)
110 nsProtocolStream *This = NSINSTREAM_THIS(iface);
111 FIXME("(%p)->(%p %ld %p)\n", This, aBuf, aCount, _retval);
112 return NS_ERROR_NOT_IMPLEMENTED;
115 static nsresult NSAPI nsInputStream_ReadSegments(nsIInputStream *iface,
116 nsresult (WINAPI *aWriter)(nsIInputStream*,void*,const char*,PRUint32,PRUint32,PRUint32*),
117 void *aClousure, PRUint32 aCount, PRUint32 *_retval)
119 nsProtocolStream *This = NSINSTREAM_THIS(iface);
120 PRUint32 written = 0;
121 nsresult nsres;
123 FIXME("(%p)->(%p %p %ld %p)\n", This, aWriter, aClousure, aCount, _retval);
125 if(!This->buf_size)
126 return S_OK;
128 if(This->buf_size > aCount)
129 FIXME("buf_size > aCount\n");
131 nsres = aWriter(NSINSTREAM(This), aClousure, This->buf, 0, This->buf_size, &written);
132 if(NS_FAILED(nsres))
133 FIXME("aWritter failed: %08lx\n", nsres);
134 if(written != This->buf_size)
135 FIXME("written != buf_size\n");
137 This->buf_size -= written;
139 return nsres;
142 static nsresult NSAPI nsInputStream_IsNonBlocking(nsIInputStream *iface, PRBool *_retval)
144 nsProtocolStream *This = NSINSTREAM_THIS(iface);
145 FIXME("(%p)->(%p)\n", This, _retval);
146 return NS_ERROR_NOT_IMPLEMENTED;
149 #undef NSINSTREAM_THIS
151 static const nsIInputStreamVtbl nsInputStreamVtbl = {
152 nsInputStream_QueryInterface,
153 nsInputStream_AddRef,
154 nsInputStream_Release,
155 nsInputStream_Close,
156 nsInputStream_Available,
157 nsInputStream_Read,
158 nsInputStream_ReadSegments,
159 nsInputStream_IsNonBlocking
162 static nsProtocolStream *create_nsprotocol_stream(IStream *stream)
164 nsProtocolStream *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(nsProtocolStream));
166 ret->lpInputStreamVtbl = &nsInputStreamVtbl;
167 ret->ref = 1;
168 ret->buf_size = 0;
170 return ret;
173 #define STATUSCLB_THIS(iface) DEFINE_THIS(BSCallback, BindStatusCallback, iface)
175 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallback *iface,
176 REFIID riid, void **ppv)
178 BSCallback *This = STATUSCLB_THIS(iface);
180 *ppv = NULL;
181 if(IsEqualGUID(&IID_IUnknown, riid)) {
182 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
183 *ppv = STATUSCLB(This);
184 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
185 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
186 *ppv = STATUSCLB(This);
187 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
188 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
189 *ppv = SERVPROV(This);
190 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
191 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
192 *ppv = HTTPNEG(This);
193 }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
194 TRACE("(%p)->(IID_IHttpNegotiate2 %p)\n", This, ppv);
195 *ppv = HTTPNEG(This);
196 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
197 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
198 *ppv = BINDINFO(This);
201 if(*ppv) {
202 IBindStatusCallback_AddRef(STATUSCLB(This));
203 return S_OK;
206 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
207 return E_NOINTERFACE;
210 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallback *iface)
212 BSCallback *This = STATUSCLB_THIS(iface);
213 LONG ref = InterlockedIncrement(&This->ref);
215 TRACE("(%p) ref = %ld\n", This, ref);
217 return ref;
220 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallback *iface)
222 BSCallback *This = STATUSCLB_THIS(iface);
223 LONG ref = InterlockedDecrement(&This->ref);
225 TRACE("(%p) ref = %ld\n", This, ref);
227 if(!ref) {
228 if(This->post_data)
229 GlobalFree(This->post_data);
230 if(This->nschannel)
231 nsIChannel_Release(NSCHANNEL(This->nschannel));
232 if(This->nslistener)
233 nsIStreamListener_Release(This->nslistener);
234 if(This->nscontext)
235 nsISupports_Release(This->nscontext);
236 if(This->nsstream)
237 nsIInputStream_Release(NSINSTREAM(This->nsstream));
238 HeapFree(GetProcessHeap(), 0, This->headers);
239 HeapFree(GetProcessHeap(), 0, This);
242 return ref;
245 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
246 DWORD dwReserved, IBinding *pbind)
248 BSCallback *This = STATUSCLB_THIS(iface);
249 FIXME("(%p)->(%ld %p)\n", This, dwReserved, pbind);
250 return S_OK;
253 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
255 BSCallback *This = STATUSCLB_THIS(iface);
256 FIXME("(%p)->(%p)\n", This, pnPriority);
257 return E_NOTIMPL;
260 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
262 BSCallback *This = STATUSCLB_THIS(iface);
263 FIXME("(%p)->(%ld)\n", This, reserved);
264 return E_NOTIMPL;
267 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
268 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
270 BSCallback *This = STATUSCLB_THIS(iface);
272 TRACE("%p)->(%lu %lu %lu %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
273 debugstr_w(szStatusText));
275 switch(ulStatusCode) {
276 case BINDSTATUS_MIMETYPEAVAILABLE: {
277 int len;
279 if(!This->nschannel)
280 return S_OK;
281 HeapFree(GetProcessHeap(), 0, This->nschannel->content);
283 len = WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, NULL, 0, NULL, NULL);
284 This->nschannel->content = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
285 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, This->nschannel->content, -1, NULL, NULL);
289 return S_OK;
292 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
293 HRESULT hresult, LPCWSTR szError)
295 BSCallback *This = STATUSCLB_THIS(iface);
296 FIXME("(%p)->(%08lx %s)\n", This, hresult, debugstr_w(szError));
297 return S_OK;
300 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
301 DWORD *grfBINDF, BINDINFO *pbindinfo)
303 BSCallback *This = STATUSCLB_THIS(iface);
304 DWORD size;
306 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
308 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
310 size = pbindinfo->cbSize;
311 memset(pbindinfo, 0, size);
312 pbindinfo->cbSize = size;
314 pbindinfo->cbStgmedData = This->post_data_len;
315 pbindinfo->dwCodePage = CP_UTF8;
316 pbindinfo->dwOptions = 0x00020000;
318 if(This->post_data) {
319 pbindinfo->dwBindVerb = BINDVERB_POST;
321 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
322 pbindinfo->stgmedData.u.hGlobal = This->post_data;
323 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)STATUSCLB(This);
324 IBindStatusCallback_AddRef(STATUSCLB(This));
327 return S_OK;
330 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
331 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
333 BSCallback *This = STATUSCLB_THIS(iface);
334 nsresult nsres;
335 HRESULT hres;
337 TRACE("(%p)->(%08lx %ld %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
339 if(This->nslistener) {
340 if(!This->nsstream) {
341 This->nsstream = create_nsprotocol_stream(pstgmed->u.pstm);
343 nsres = nsIStreamListener_OnStartRequest(This->nslistener,
344 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
345 if(NS_FAILED(nsres))
346 FIXME("OnStartRequest failed: %08lx\n", nsres);
349 do {
350 hres = IStream_Read(pstgmed->u.pstm, This->nsstream->buf, sizeof(This->nsstream->buf),
351 &This->nsstream->buf_size);
352 if(This->nsstream->buf_size) {
353 nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
354 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
355 NSINSTREAM(This->nsstream), 0 /* FIXME */, dwSize);
356 if(NS_FAILED(nsres))
357 FIXME("OnDataAvailable failed: %08lx\n", nsres);
359 if(This->nsstream->buf_size)
360 FIXME("buffer is not empty!\n");
362 }while(hres == S_OK);
365 return S_OK;
368 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
369 REFIID riid, IUnknown *punk)
371 BSCallback *This = STATUSCLB_THIS(iface);
372 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
373 return E_NOTIMPL;
376 #undef STATUSCLB_THIS
378 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
379 BindStatusCallback_QueryInterface,
380 BindStatusCallback_AddRef,
381 BindStatusCallback_Release,
382 BindStatusCallback_OnStartBinding,
383 BindStatusCallback_GetPriority,
384 BindStatusCallback_OnLowResource,
385 BindStatusCallback_OnProgress,
386 BindStatusCallback_OnStopBinding,
387 BindStatusCallback_GetBindInfo,
388 BindStatusCallback_OnDataAvailable,
389 BindStatusCallback_OnObjectAvailable
392 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
394 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
395 REFIID riid, void **ppv)
397 BSCallback *This = HTTPNEG_THIS(iface);
398 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
401 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
403 BSCallback *This = HTTPNEG_THIS(iface);
404 return IBindStatusCallback_AddRef(STATUSCLB(This));
407 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
409 BSCallback *This = HTTPNEG_THIS(iface);
410 return IBindStatusCallback_Release(STATUSCLB(This));
413 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
414 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
416 BSCallback *This = HTTPNEG_THIS(iface);
417 DWORD size;
419 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
420 dwReserved, pszAdditionalHeaders);
422 if(!This->headers) {
423 *pszAdditionalHeaders = NULL;
424 return S_OK;
427 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
428 *pszAdditionalHeaders = CoTaskMemAlloc(size);
429 memcpy(*pszAdditionalHeaders, This->headers, size);
431 return S_OK;
434 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
435 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
437 BSCallback *This = HTTPNEG_THIS(iface);
438 FIXME("(%p)->(%ld %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
439 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
440 return E_NOTIMPL;
443 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
444 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
446 BSCallback *This = HTTPNEG_THIS(iface);
447 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
448 return E_NOTIMPL;
451 #undef HTTPNEG
453 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
454 HttpNegotiate_QueryInterface,
455 HttpNegotiate_AddRef,
456 HttpNegotiate_Release,
457 HttpNegotiate_BeginningTransaction,
458 HttpNegotiate_OnResponse,
459 HttpNegotiate_GetRootSecurityId
462 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
464 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
465 REFIID riid, void **ppv)
467 BSCallback *This = BINDINFO_THIS(iface);
468 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
471 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
473 BSCallback *This = BINDINFO_THIS(iface);
474 return IBindStatusCallback_AddRef(STATUSCLB(This));
477 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
479 BSCallback *This = BINDINFO_THIS(iface);
480 return IBindStatusCallback_Release(STATUSCLB(This));
483 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
484 DWORD *grfBINDF, BINDINFO *pbindinfo)
486 BSCallback *This = BINDINFO_THIS(iface);
487 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
488 return E_NOTIMPL;
491 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
492 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
494 BSCallback *This = BINDINFO_THIS(iface);
495 FIXME("(%p)->(%lu %p %lu %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
496 return E_NOTIMPL;
499 #undef BINDINFO_THIS
501 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
502 InternetBindInfo_QueryInterface,
503 InternetBindInfo_AddRef,
504 InternetBindInfo_Release,
505 InternetBindInfo_GetBindInfo,
506 InternetBindInfo_GetBindString
509 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
511 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
512 REFIID riid, void **ppv)
514 BSCallback *This = SERVPROV_THIS(iface);
515 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
518 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
520 BSCallback *This = SERVPROV_THIS(iface);
521 return IBindStatusCallback_AddRef(STATUSCLB(This));
524 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
526 BSCallback *This = SERVPROV_THIS(iface);
527 return IBindStatusCallback_Release(STATUSCLB(This));
530 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
531 REFGUID guidService, REFIID riid, void **ppv)
533 BSCallback *This = SERVPROV_THIS(iface);
534 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
535 return E_NOTIMPL;
538 #undef SERVPROV_THIS
540 static const IServiceProviderVtbl ServiceProviderVtbl = {
541 BSCServiceProvider_QueryInterface,
542 BSCServiceProvider_AddRef,
543 BSCServiceProvider_Release,
544 BSCServiceProvider_QueryService
547 BSCallback *create_bscallback(HTMLDocument *doc, LPCOLESTR url)
549 BSCallback *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(BSCallback));
551 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
552 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
553 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
554 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
555 ret->ref = 1;
556 ret->post_data = NULL;
557 ret->headers = NULL;
558 ret->post_data_len = 0;
559 ret->nschannel = NULL;
560 ret->nslistener = NULL;
561 ret->nscontext = NULL;
562 ret->nsstream = NULL;
564 return ret;
567 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
568 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
570 PRUint32 post_data_len = 0, available = 0;
571 HGLOBAL post_data = NULL;
572 LPWSTR headers = NULL;
573 DWORD headers_len = 0, len;
574 const char *ptr, *ptr2, *post_data_end;
576 nsIInputStream_Available(post_data_stream, &available);
577 post_data = GlobalAlloc(0, available+1);
578 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
580 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
582 ptr = ptr2 = post_data;
583 post_data_end = (const char*)post_data+post_data_len;
585 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
586 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
587 ptr++;
589 if(!*ptr) {
590 FIXME("*ptr = 0\n");
591 return;
594 ptr += 2;
596 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
597 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
598 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
599 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
600 ptr2 = ptr;
601 continue;
604 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
606 if(headers)
607 headers = HeapReAlloc(GetProcessHeap(), 0, headers,
608 (headers_len+len+1)*sizeof(WCHAR));
609 else
610 headers = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
612 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
613 headers_len += len;
615 ptr2 = ptr;
618 headers[headers_len] = 0;
619 *headers_ret = headers;
621 if(ptr >= post_data_end-2) {
622 GlobalFree(post_data);
623 return;
626 ptr += 2;
628 if(headers_len) {
629 post_data_len -= ptr-(const char*)post_data;
630 memmove(post_data, ptr, post_data_len);
631 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
634 *post_data_ret = post_data;
635 *post_data_len_ret = post_data_len;
638 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
639 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
641 BSCallback *callback;
642 IBindCtx *bindctx;
643 IMoniker *mon;
644 IHlink *hlink;
646 callback = create_bscallback(doc, uri);
648 if(post_data_stream) {
649 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
650 &callback->post_data_len);
651 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
652 debugstr_an(callback->post_data, callback->post_data_len));
655 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
657 hlink = Hlink_Create();
659 CreateURLMoniker(NULL, uri, &mon);
660 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
662 if(hlnf & HLNF_OPENINNEWWINDOW) {
663 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
664 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
667 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
669 IBindCtx_Release(bindctx);
670 IBindStatusCallback_Release(STATUSCLB(callback));
671 IMoniker_Release(mon);
675 HRESULT start_binding(BSCallback *bscallback, IMoniker *mon)
677 IStream *str = NULL;
678 IBindCtx *bctx;
679 HRESULT hres;
681 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
682 if(FAILED(hres)) {
683 WARN("CreateAsyncBindCtx failed: %08lx\n", hres);
684 return hres;
687 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&str);
688 IBindCtx_Release(bctx);
689 if(FAILED(hres)) {
690 WARN("BindToStorage failed: %08lx\n", hres);
691 return hres;
694 if(str)
695 IStream_Release(str);
697 return S_OK;