programs/wcmd: Rename to programs/cmd.
[wine.git] / dlls / mshtml / navigate.c
blobc588f05088b44bee4a31b7e03c3a8a0a47929060
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 mshtml_free(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);
112 TRACE("(%p)->(%p %ld %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;
119 if(This->buf_size)
120 memcpy(aBuf, This->buf, This->buf_size);
121 This->buf_size = 0;
123 return NS_OK;
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;
132 nsresult nsres;
134 TRACE("(%p)->(%p %p %ld %p)\n", This, aWriter, aClousure, aCount, _retval);
136 if(!This->buf_size)
137 return S_OK;
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);
143 if(NS_FAILED(nsres))
144 FIXME("aWritter failed: %08lx\n", nsres);
145 if(written != This->buf_size)
146 FIXME("written != buf_size\n");
148 This->buf_size -= written;
150 return nsres;
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,
166 nsInputStream_Close,
167 nsInputStream_Available,
168 nsInputStream_Read,
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;
178 ret->ref = 1;
179 ret->buf_size = 0;
181 return ret;
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);
191 *ppv = NULL;
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);
212 if(*ppv) {
213 IBindStatusCallback_AddRef(STATUSCLB(This));
214 return S_OK;
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 = %ld\n", This, ref);
228 return 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 = %ld\n", This, ref);
238 if(!ref) {
239 if(This->post_data)
240 GlobalFree(This->post_data);
241 if(This->nschannel)
242 nsIChannel_Release(NSCHANNEL(This->nschannel));
243 if(This->nslistener)
244 nsIStreamListener_Release(This->nslistener);
245 if(This->nscontext)
246 nsISupports_Release(This->nscontext);
247 if(This->nsstream)
248 nsIInputStream_Release(NSINSTREAM(This->nsstream));
249 if(This->mon)
250 IMoniker_Release(This->mon);
251 mshtml_free(This->headers);
252 mshtml_free(This);
255 return ref;
258 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallback *iface,
259 DWORD dwReserved, IBinding *pbind)
261 BSCallback *This = STATUSCLB_THIS(iface);
262 FIXME("(%p)->(%ld %p)\n", This, dwReserved, pbind);
263 return S_OK;
266 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
268 BSCallback *This = STATUSCLB_THIS(iface);
269 FIXME("(%p)->(%p)\n", This, pnPriority);
270 return E_NOTIMPL;
273 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
275 BSCallback *This = STATUSCLB_THIS(iface);
276 FIXME("(%p)->(%ld)\n", This, reserved);
277 return E_NOTIMPL;
280 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
281 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
283 BSCallback *This = STATUSCLB_THIS(iface);
285 TRACE("%p)->(%lu %lu %lu %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
286 debugstr_w(szStatusText));
288 switch(ulStatusCode) {
289 case BINDSTATUS_MIMETYPEAVAILABLE: {
290 int len;
292 if(!This->nschannel)
293 return S_OK;
294 mshtml_free(This->nschannel->content);
296 len = WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, NULL, 0, NULL, NULL);
297 This->nschannel->content = mshtml_alloc(len*sizeof(WCHAR));
298 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, This->nschannel->content, -1, NULL, NULL);
302 return S_OK;
305 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
306 HRESULT hresult, LPCWSTR szError)
308 BSCallback *This = STATUSCLB_THIS(iface);
310 TRACE("(%p)->(%08lx %s)\n", This, hresult, debugstr_w(szError));
312 if(This->nslistener) {
313 nsIStreamListener_OnStopRequest(This->nslistener, (nsIRequest*)NSCHANNEL(This->nschannel),
314 This->nscontext, NS_OK);
316 if(This->nschannel->load_group) {
317 nsresult nsres;
319 nsres = nsILoadGroup_RemoveRequest(This->nschannel->load_group,
320 (nsIRequest*)NSCHANNEL(This->nschannel), NULL, NS_OK);
321 if(NS_FAILED(nsres))
322 ERR("RemoveRequest failed: %08lx\n", nsres);
326 return S_OK;
329 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
330 DWORD *grfBINDF, BINDINFO *pbindinfo)
332 BSCallback *This = STATUSCLB_THIS(iface);
333 DWORD size;
335 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
337 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
339 size = pbindinfo->cbSize;
340 memset(pbindinfo, 0, size);
341 pbindinfo->cbSize = size;
343 pbindinfo->cbStgmedData = This->post_data_len;
344 pbindinfo->dwCodePage = CP_UTF8;
345 pbindinfo->dwOptions = 0x00020000;
347 if(This->post_data) {
348 pbindinfo->dwBindVerb = BINDVERB_POST;
350 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
351 pbindinfo->stgmedData.u.hGlobal = This->post_data;
352 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)STATUSCLB(This);
353 IBindStatusCallback_AddRef(STATUSCLB(This));
356 return S_OK;
359 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
360 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
362 BSCallback *This = STATUSCLB_THIS(iface);
363 nsresult nsres;
364 HRESULT hres;
366 TRACE("(%p)->(%08lx %ld %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
368 if(This->nslistener) {
369 if(!This->nsstream) {
370 This->nsstream = create_nsprotocol_stream(pstgmed->u.pstm);
372 nsres = nsIStreamListener_OnStartRequest(This->nslistener,
373 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
374 if(NS_FAILED(nsres))
375 FIXME("OnStartRequest failed: %08lx\n", nsres);
378 do {
379 hres = IStream_Read(pstgmed->u.pstm, This->nsstream->buf, sizeof(This->nsstream->buf),
380 &This->nsstream->buf_size);
381 if(!This->nsstream->buf_size)
382 break;
384 nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
385 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
386 NSINSTREAM(This->nsstream), This->readed, This->nsstream->buf_size);
387 if(NS_FAILED(nsres))
388 FIXME("OnDataAvailable failed: %08lx\n", nsres);
390 if(This->nsstream->buf_size)
391 FIXME("buffer is not empty!\n");
393 This->readed += This->nsstream->buf_size;
394 }while(hres == S_OK);
397 return S_OK;
400 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
401 REFIID riid, IUnknown *punk)
403 BSCallback *This = STATUSCLB_THIS(iface);
404 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
405 return E_NOTIMPL;
408 #undef STATUSCLB_THIS
410 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
411 BindStatusCallback_QueryInterface,
412 BindStatusCallback_AddRef,
413 BindStatusCallback_Release,
414 BindStatusCallback_OnStartBinding,
415 BindStatusCallback_GetPriority,
416 BindStatusCallback_OnLowResource,
417 BindStatusCallback_OnProgress,
418 BindStatusCallback_OnStopBinding,
419 BindStatusCallback_GetBindInfo,
420 BindStatusCallback_OnDataAvailable,
421 BindStatusCallback_OnObjectAvailable
424 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
426 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
427 REFIID riid, void **ppv)
429 BSCallback *This = HTTPNEG_THIS(iface);
430 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
433 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
435 BSCallback *This = HTTPNEG_THIS(iface);
436 return IBindStatusCallback_AddRef(STATUSCLB(This));
439 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
441 BSCallback *This = HTTPNEG_THIS(iface);
442 return IBindStatusCallback_Release(STATUSCLB(This));
445 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
446 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
448 BSCallback *This = HTTPNEG_THIS(iface);
449 DWORD size;
451 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
452 dwReserved, pszAdditionalHeaders);
454 if(!This->headers) {
455 *pszAdditionalHeaders = NULL;
456 return S_OK;
459 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
460 *pszAdditionalHeaders = CoTaskMemAlloc(size);
461 memcpy(*pszAdditionalHeaders, This->headers, size);
463 return S_OK;
466 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
467 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
469 BSCallback *This = HTTPNEG_THIS(iface);
470 FIXME("(%p)->(%ld %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
471 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
472 return E_NOTIMPL;
475 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
476 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
478 BSCallback *This = HTTPNEG_THIS(iface);
479 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
480 return E_NOTIMPL;
483 #undef HTTPNEG
485 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
486 HttpNegotiate_QueryInterface,
487 HttpNegotiate_AddRef,
488 HttpNegotiate_Release,
489 HttpNegotiate_BeginningTransaction,
490 HttpNegotiate_OnResponse,
491 HttpNegotiate_GetRootSecurityId
494 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
496 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
497 REFIID riid, void **ppv)
499 BSCallback *This = BINDINFO_THIS(iface);
500 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
503 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
505 BSCallback *This = BINDINFO_THIS(iface);
506 return IBindStatusCallback_AddRef(STATUSCLB(This));
509 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
511 BSCallback *This = BINDINFO_THIS(iface);
512 return IBindStatusCallback_Release(STATUSCLB(This));
515 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
516 DWORD *grfBINDF, BINDINFO *pbindinfo)
518 BSCallback *This = BINDINFO_THIS(iface);
519 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
520 return E_NOTIMPL;
523 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
524 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
526 BSCallback *This = BINDINFO_THIS(iface);
527 FIXME("(%p)->(%lu %p %lu %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
528 return E_NOTIMPL;
531 #undef BINDINFO_THIS
533 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
534 InternetBindInfo_QueryInterface,
535 InternetBindInfo_AddRef,
536 InternetBindInfo_Release,
537 InternetBindInfo_GetBindInfo,
538 InternetBindInfo_GetBindString
541 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
543 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
544 REFIID riid, void **ppv)
546 BSCallback *This = SERVPROV_THIS(iface);
547 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
550 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
552 BSCallback *This = SERVPROV_THIS(iface);
553 return IBindStatusCallback_AddRef(STATUSCLB(This));
556 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
558 BSCallback *This = SERVPROV_THIS(iface);
559 return IBindStatusCallback_Release(STATUSCLB(This));
562 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
563 REFGUID guidService, REFIID riid, void **ppv)
565 BSCallback *This = SERVPROV_THIS(iface);
566 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
567 return E_NOTIMPL;
570 #undef SERVPROV_THIS
572 static const IServiceProviderVtbl ServiceProviderVtbl = {
573 BSCServiceProvider_QueryInterface,
574 BSCServiceProvider_AddRef,
575 BSCServiceProvider_Release,
576 BSCServiceProvider_QueryService
579 BSCallback *create_bscallback(HTMLDocument *doc, IMoniker *mon)
581 BSCallback *ret = mshtml_alloc(sizeof(BSCallback));
583 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
584 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
585 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
586 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
587 ret->ref = 1;
588 ret->post_data = NULL;
589 ret->headers = NULL;
590 ret->post_data_len = 0;
591 ret->readed = 0;
592 ret->nschannel = NULL;
593 ret->nslistener = NULL;
594 ret->nscontext = NULL;
595 ret->nsstream = NULL;
597 if(mon)
598 IMoniker_AddRef(mon);
599 ret->mon = mon;
601 return ret;
604 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
605 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
607 PRUint32 post_data_len = 0, available = 0;
608 HGLOBAL post_data = NULL;
609 LPWSTR headers = NULL;
610 DWORD headers_len = 0, len;
611 const char *ptr, *ptr2, *post_data_end;
613 nsIInputStream_Available(post_data_stream, &available);
614 post_data = GlobalAlloc(0, available+1);
615 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
617 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
619 ptr = ptr2 = post_data;
620 post_data_end = (const char*)post_data+post_data_len;
622 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
623 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
624 ptr++;
626 if(!*ptr) {
627 FIXME("*ptr = 0\n");
628 return;
631 ptr += 2;
633 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
634 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
635 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
636 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
637 ptr2 = ptr;
638 continue;
641 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
643 if(headers)
644 headers = mshtml_realloc(headers,(headers_len+len+1)*sizeof(WCHAR));
645 else
646 headers = mshtml_alloc((len+1)*sizeof(WCHAR));
648 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
649 headers_len += len;
651 ptr2 = ptr;
654 headers[headers_len] = 0;
655 *headers_ret = headers;
657 if(ptr >= post_data_end-2) {
658 GlobalFree(post_data);
659 return;
662 ptr += 2;
664 if(headers_len) {
665 post_data_len -= ptr-(const char*)post_data;
666 memmove(post_data, ptr, post_data_len);
667 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
670 *post_data_ret = post_data;
671 *post_data_len_ret = post_data_len;
674 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
675 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
677 BSCallback *callback;
678 IBindCtx *bindctx;
679 IMoniker *mon;
680 IHlink *hlink;
682 callback = create_bscallback(doc, NULL);
684 if(post_data_stream) {
685 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
686 &callback->post_data_len);
687 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
688 debugstr_an(callback->post_data, callback->post_data_len));
691 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
693 hlink = Hlink_Create();
695 CreateURLMoniker(NULL, uri, &mon);
696 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
698 if(hlnf & HLNF_OPENINNEWWINDOW) {
699 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
700 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
703 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
705 IBindCtx_Release(bindctx);
706 IBindStatusCallback_Release(STATUSCLB(callback));
707 IMoniker_Release(mon);
711 HRESULT start_binding(BSCallback *bscallback)
713 IStream *str = NULL;
714 IBindCtx *bctx;
715 HRESULT hres;
717 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
718 if(FAILED(hres)) {
719 WARN("CreateAsyncBindCtx failed: %08lx\n", hres);
720 return hres;
723 hres = IMoniker_BindToStorage(bscallback->mon, bctx, NULL, &IID_IStream, (void**)&str);
724 IBindCtx_Release(bctx);
725 if(FAILED(hres)) {
726 WARN("BindToStorage failed: %08lx\n", hres);
727 return hres;
730 if(str)
731 IStream_Release(str);
733 IMoniker_Release(bscallback->mon);
734 bscallback->mon = NULL;
735 return S_OK;