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=%ld\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=%ld\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);
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;
123 FIXME("(%p)->(%p %p %ld %p)\n", This, aWriter, aClousure, aCount, _retval);
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);
133 FIXME("aWritter failed: %08lx\n", nsres);
134 if(written != This->buf_size)
135 FIXME("written != buf_size\n");
137 This->buf_size -= written;
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,
156 nsInputStream_Available,
158 nsInputStream_ReadSegments,
159 nsInputStream_IsNonBlocking
162 static nsProtocolStream *create_nsprotocol_stream(IStream *stream)
164 nsProtocolStream *ret = mshtml_alloc(sizeof(nsProtocolStream));
166 ret->lpInputStreamVtbl = &nsInputStreamVtbl;
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);
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);
202 IBindStatusCallback_AddRef(STATUSCLB(This));
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);
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);
229 GlobalFree(This->post_data);
231 nsIChannel_Release(NSCHANNEL(This->nschannel));
233 nsIStreamListener_Release(This->nslistener);
235 nsISupports_Release(This->nscontext);
237 nsIInputStream_Release(NSINSTREAM(This->nsstream));
238 mshtml_free(This->headers);
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);
253 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
255 BSCallback *This = STATUSCLB_THIS(iface);
256 FIXME("(%p)->(%p)\n", This, pnPriority);
260 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
262 BSCallback *This = STATUSCLB_THIS(iface);
263 FIXME("(%p)->(%ld)\n", This, reserved);
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: {
281 mshtml_free(This->nschannel->content);
283 len = WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, NULL, 0, NULL, NULL);
284 This->nschannel->content = mshtml_alloc(len*sizeof(WCHAR));
285 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, This->nschannel->content, -1, NULL, NULL);
292 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallback *iface,
293 HRESULT hresult, LPCWSTR szError)
295 BSCallback *This = STATUSCLB_THIS(iface);
297 TRACE("(%p)->(%08lx %s)\n", This, hresult, debugstr_w(szError));
300 nsIStreamListener_OnStopRequest(This->nslistener, (nsIRequest*)NSCHANNEL(This->nschannel),
301 This->nscontext, NS_OK);
306 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallback *iface,
307 DWORD *grfBINDF, BINDINFO *pbindinfo)
309 BSCallback *This = STATUSCLB_THIS(iface);
312 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
314 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
316 size = pbindinfo->cbSize;
317 memset(pbindinfo, 0, size);
318 pbindinfo->cbSize = size;
320 pbindinfo->cbStgmedData = This->post_data_len;
321 pbindinfo->dwCodePage = CP_UTF8;
322 pbindinfo->dwOptions = 0x00020000;
324 if(This->post_data) {
325 pbindinfo->dwBindVerb = BINDVERB_POST;
327 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
328 pbindinfo->stgmedData.u.hGlobal = This->post_data;
329 pbindinfo->stgmedData.pUnkForRelease = (IUnknown*)STATUSCLB(This);
330 IBindStatusCallback_AddRef(STATUSCLB(This));
336 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallback *iface,
337 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
339 BSCallback *This = STATUSCLB_THIS(iface);
343 TRACE("(%p)->(%08lx %ld %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
345 if(This->nslistener) {
346 if(!This->nsstream) {
347 This->nsstream = create_nsprotocol_stream(pstgmed->u.pstm);
349 nsres = nsIStreamListener_OnStartRequest(This->nslistener,
350 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext);
352 FIXME("OnStartRequest failed: %08lx\n", nsres);
356 hres = IStream_Read(pstgmed->u.pstm, This->nsstream->buf, sizeof(This->nsstream->buf),
357 &This->nsstream->buf_size);
358 if(This->nsstream->buf_size) {
359 nsres = nsIStreamListener_OnDataAvailable(This->nslistener,
360 (nsIRequest*)NSCHANNEL(This->nschannel), This->nscontext,
361 NSINSTREAM(This->nsstream), 0 /* FIXME */, dwSize);
363 FIXME("OnDataAvailable failed: %08lx\n", nsres);
365 if(This->nsstream->buf_size)
366 FIXME("buffer is not empty!\n");
370 }while(hres == S_OK);
376 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface,
377 REFIID riid, IUnknown *punk)
379 BSCallback *This = STATUSCLB_THIS(iface);
380 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
384 #undef STATUSCLB_THIS
386 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
387 BindStatusCallback_QueryInterface,
388 BindStatusCallback_AddRef,
389 BindStatusCallback_Release,
390 BindStatusCallback_OnStartBinding,
391 BindStatusCallback_GetPriority,
392 BindStatusCallback_OnLowResource,
393 BindStatusCallback_OnProgress,
394 BindStatusCallback_OnStopBinding,
395 BindStatusCallback_GetBindInfo,
396 BindStatusCallback_OnDataAvailable,
397 BindStatusCallback_OnObjectAvailable
400 #define HTTPNEG_THIS(iface) DEFINE_THIS(BSCallback, HttpNegotiate2, iface)
402 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
403 REFIID riid, void **ppv)
405 BSCallback *This = HTTPNEG_THIS(iface);
406 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
409 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
411 BSCallback *This = HTTPNEG_THIS(iface);
412 return IBindStatusCallback_AddRef(STATUSCLB(This));
415 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
417 BSCallback *This = HTTPNEG_THIS(iface);
418 return IBindStatusCallback_Release(STATUSCLB(This));
421 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
422 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
424 BSCallback *This = HTTPNEG_THIS(iface);
427 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders),
428 dwReserved, pszAdditionalHeaders);
431 *pszAdditionalHeaders = NULL;
435 size = (strlenW(This->headers)+1)*sizeof(WCHAR);
436 *pszAdditionalHeaders = CoTaskMemAlloc(size);
437 memcpy(*pszAdditionalHeaders, This->headers, size);
442 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
443 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
445 BSCallback *This = HTTPNEG_THIS(iface);
446 FIXME("(%p)->(%ld %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
447 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
451 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
452 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
454 BSCallback *This = HTTPNEG_THIS(iface);
455 FIXME("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
461 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
462 HttpNegotiate_QueryInterface,
463 HttpNegotiate_AddRef,
464 HttpNegotiate_Release,
465 HttpNegotiate_BeginningTransaction,
466 HttpNegotiate_OnResponse,
467 HttpNegotiate_GetRootSecurityId
470 #define BINDINFO_THIS(iface) DEFINE_THIS(BSCallback, InternetBindInfo, iface)
472 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
473 REFIID riid, void **ppv)
475 BSCallback *This = BINDINFO_THIS(iface);
476 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
479 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
481 BSCallback *This = BINDINFO_THIS(iface);
482 return IBindStatusCallback_AddRef(STATUSCLB(This));
485 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
487 BSCallback *This = BINDINFO_THIS(iface);
488 return IBindStatusCallback_Release(STATUSCLB(This));
491 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
492 DWORD *grfBINDF, BINDINFO *pbindinfo)
494 BSCallback *This = BINDINFO_THIS(iface);
495 FIXME("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
499 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
500 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
502 BSCallback *This = BINDINFO_THIS(iface);
503 FIXME("(%p)->(%lu %p %lu %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
509 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
510 InternetBindInfo_QueryInterface,
511 InternetBindInfo_AddRef,
512 InternetBindInfo_Release,
513 InternetBindInfo_GetBindInfo,
514 InternetBindInfo_GetBindString
517 #define SERVPROV_THIS(iface) DEFINE_THIS(BSCallback, ServiceProvider, iface)
519 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
520 REFIID riid, void **ppv)
522 BSCallback *This = SERVPROV_THIS(iface);
523 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
526 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
528 BSCallback *This = SERVPROV_THIS(iface);
529 return IBindStatusCallback_AddRef(STATUSCLB(This));
532 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
534 BSCallback *This = SERVPROV_THIS(iface);
535 return IBindStatusCallback_Release(STATUSCLB(This));
538 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
539 REFGUID guidService, REFIID riid, void **ppv)
541 BSCallback *This = SERVPROV_THIS(iface);
542 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
548 static const IServiceProviderVtbl ServiceProviderVtbl = {
549 BSCServiceProvider_QueryInterface,
550 BSCServiceProvider_AddRef,
551 BSCServiceProvider_Release,
552 BSCServiceProvider_QueryService
555 BSCallback *create_bscallback(HTMLDocument *doc, LPCOLESTR url)
557 BSCallback *ret = mshtml_alloc(sizeof(BSCallback));
559 ret->lpBindStatusCallbackVtbl = &BindStatusCallbackVtbl;
560 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
561 ret->lpHttpNegotiate2Vtbl = &HttpNegotiate2Vtbl;
562 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
564 ret->post_data = NULL;
566 ret->post_data_len = 0;
567 ret->nschannel = NULL;
568 ret->nslistener = NULL;
569 ret->nscontext = NULL;
570 ret->nsstream = NULL;
575 static void parse_post_data(nsIInputStream *post_data_stream, LPWSTR *headers_ret,
576 HGLOBAL *post_data_ret, ULONG *post_data_len_ret)
578 PRUint32 post_data_len = 0, available = 0;
579 HGLOBAL post_data = NULL;
580 LPWSTR headers = NULL;
581 DWORD headers_len = 0, len;
582 const char *ptr, *ptr2, *post_data_end;
584 nsIInputStream_Available(post_data_stream, &available);
585 post_data = GlobalAlloc(0, available+1);
586 nsIInputStream_Read(post_data_stream, post_data, available, &post_data_len);
588 TRACE("post_data = %s\n", debugstr_an(post_data, post_data_len));
590 ptr = ptr2 = post_data;
591 post_data_end = (const char*)post_data+post_data_len;
593 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n')) {
594 while(ptr < post_data_end && (*ptr != '\r' || ptr[1] != '\n'))
604 if(ptr-ptr2 >= sizeof(CONTENT_LENGTH)
605 && CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
606 CONTENT_LENGTH, sizeof(CONTENT_LENGTH)-1,
607 ptr2, sizeof(CONTENT_LENGTH)-1) == CSTR_EQUAL) {
612 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, NULL, 0);
615 headers = mshtml_realloc(headers,(headers_len+len+1)*sizeof(WCHAR));
617 headers = mshtml_alloc((len+1)*sizeof(WCHAR));
619 len = MultiByteToWideChar(CP_ACP, 0, ptr2, ptr-ptr2, headers+headers_len, -1);
625 headers[headers_len] = 0;
626 *headers_ret = headers;
628 if(ptr >= post_data_end-2) {
629 GlobalFree(post_data);
636 post_data_len -= ptr-(const char*)post_data;
637 memmove(post_data, ptr, post_data_len);
638 post_data = GlobalReAlloc(post_data, post_data_len+1, 0);
641 *post_data_ret = post_data;
642 *post_data_len_ret = post_data_len;
645 void hlink_frame_navigate(HTMLDocument *doc, IHlinkFrame *hlink_frame,
646 LPCWSTR uri, nsIInputStream *post_data_stream, DWORD hlnf)
648 BSCallback *callback;
653 callback = create_bscallback(doc, uri);
655 if(post_data_stream) {
656 parse_post_data(post_data_stream, &callback->headers, &callback->post_data,
657 &callback->post_data_len);
658 TRACE("headers = %s post_data = %s\n", debugstr_w(callback->headers),
659 debugstr_an(callback->post_data, callback->post_data_len));
662 CreateAsyncBindCtx(0, STATUSCLB(callback), NULL, &bindctx);
664 hlink = Hlink_Create();
666 CreateURLMoniker(NULL, uri, &mon);
667 IHlink_SetMonikerReference(hlink, 0, mon, NULL);
669 if(hlnf & HLNF_OPENINNEWWINDOW) {
670 static const WCHAR wszBlank[] = {'_','b','l','a','n','k',0};
671 IHlink_SetTargetFrameName(hlink, wszBlank); /* FIXME */
674 IHlinkFrame_Navigate(hlink_frame, hlnf, bindctx, STATUSCLB(callback), hlink);
676 IBindCtx_Release(bindctx);
677 IBindStatusCallback_Release(STATUSCLB(callback));
678 IMoniker_Release(mon);
682 HRESULT start_binding(BSCallback *bscallback, IMoniker *mon)
688 hres = CreateAsyncBindCtx(0, STATUSCLB(bscallback), NULL, &bctx);
690 WARN("CreateAsyncBindCtx failed: %08lx\n", hres);
694 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&str);
695 IBindCtx_Release(bctx);
697 WARN("BindToStorage failed: %08lx\n", hres);
702 IStream_Release(str);