4 * Copyright 1999 Ulrich Czekalla for Corel Corporation
5 * Copyright 2002 Huw D M Davies for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define COM_NO_WINDOWS_H
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
42 #include "urlmon_main.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
46 /* native urlmon.dll uses this key, too */
47 static const WCHAR BSCBHolder
[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
49 /*static BOOL registered_wndclass = FALSE;*/
52 const IBindingVtbl
*lpVtbl
;
60 HINTERNET hinternet
, hconnect
, hrequest
;
62 IUMCacheStream
*pstrCache
;
63 IBindStatusCallback
*pbscb
;
64 DWORD total_read
, expected_size
;
67 static HRESULT WINAPI
Binding_QueryInterface(IBinding
* iface
, REFIID riid
, void **ppvObject
)
69 Binding
*This
= (Binding
*)iface
;
71 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppvObject
);
73 if((This
== NULL
) || (ppvObject
== NULL
))
76 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IBinding
, riid
)) {
78 IBinding_AddRef(iface
);
86 static ULONG WINAPI
Binding_AddRef(IBinding
* iface
)
88 Binding
*This
= (Binding
*)iface
;
89 ULONG ref
= InterlockedIncrement(&This
->ref
);
91 TRACE("(%p) ref=%ld\n", This
, ref
);
96 static ULONG WINAPI
Binding_Release(IBinding
* iface
)
98 Binding
*This
= (Binding
*)iface
;
99 ULONG ref
= InterlockedDecrement(&This
->ref
);
101 TRACE("(%p) ref=%ld\n",This
, ref
);
104 HeapFree(GetProcessHeap(), 0, This
->URLName
);
105 if (This
->hCacheFile
)
106 CloseHandle(This
->hCacheFile
);
109 UMCloseCacheFileStream(This
->pstrCache
);
110 IStream_Release((IStream
*)This
->pstrCache
);
113 IBindStatusCallback_Release(This
->pbscb
);
115 HeapFree(GetProcessHeap(), 0, This
);
117 URLMON_UnlockModule();
123 static HRESULT WINAPI
Binding_Abort(IBinding
* iface
)
125 Binding
*This
= (Binding
*)iface
;
127 FIXME("(%p): stub\n", This
);
132 static HRESULT WINAPI
Binding_GetBindResult(IBinding
* iface
, CLSID
* pclsidProtocol
, DWORD
* pdwResult
, LPOLESTR
* pszResult
, DWORD
* pdwReserved
)
134 Binding
*This
= (Binding
*)iface
;
136 FIXME("(%p)->(%p, %p, %p, %p): stub\n", This
, pclsidProtocol
, pdwResult
, pszResult
, pdwReserved
);
141 static HRESULT WINAPI
Binding_GetPriority(IBinding
* iface
, LONG
* pnPriority
)
143 Binding
*This
= (Binding
*)iface
;
145 FIXME("(%p)->(%p): stub\n", This
, pnPriority
);
150 static HRESULT WINAPI
Binding_Resume(IBinding
* iface
)
152 Binding
*This
= (Binding
*)iface
;
154 FIXME("(%p): stub\n", This
);
159 static HRESULT WINAPI
Binding_SetPriority(IBinding
* iface
, LONG nPriority
)
161 Binding
*This
= (Binding
*)iface
;
163 FIXME("(%p)->(%ld): stub\n", This
, nPriority
);
168 static HRESULT WINAPI
Binding_Suspend(IBinding
* iface
)
170 Binding
*This
= (Binding
*)iface
;
172 FIXME("(%p): stub\n", This
);
177 static void Binding_CloseCacheDownload(Binding
*This
)
179 CloseHandle(This
->hCacheFile
);
180 This
->hCacheFile
= 0;
181 UMCloseCacheFileStream(This
->pstrCache
);
182 IStream_Release((IStream
*)This
->pstrCache
);
186 static HRESULT
Binding_MoreCacheData(Binding
*This
, char *buf
, DWORD dwBytes
)
190 if (WriteFile(This
->hCacheFile
, buf
, dwBytes
, &written
, NULL
) && written
== dwBytes
)
194 This
->total_read
+= written
;
195 hr
= IBindStatusCallback_OnProgress(This
->pbscb
,
196 This
->total_read
+ written
,
198 (This
->total_read
== written
) ?
199 BINDSTATUS_BEGINDOWNLOADDATA
:
200 BINDSTATUS_DOWNLOADINGDATA
,
211 fmt
.tymed
= TYMED_ISTREAM
;
213 stg
.tymed
= TYMED_ISTREAM
;
214 stg
.u
.pstm
= (IStream
*)This
->pstrCache
;
215 stg
.pUnkForRelease
= NULL
;
217 hr
= IBindStatusCallback_OnDataAvailable(This
->pbscb
,
218 (This
->total_read
== written
) ?
219 BSCF_FIRSTDATANOTIFICATION
:
220 BSCF_INTERMEDIATEDATANOTIFICATION
,
221 This
->total_read
+ written
,
225 if (written
< dwBytes
)
226 return STG_E_MEDIUMFULL
;
230 return HRESULT_FROM_WIN32(GetLastError());
233 static void Binding_FinishedDownload(Binding
*This
, HRESULT hr
)
241 fmt
.tymed
= TYMED_ISTREAM
;
243 stg
.tymed
= TYMED_ISTREAM
;
244 stg
.u
.pstm
= (IStream
*)This
->pstrCache
;
245 stg
.pUnkForRelease
= NULL
;
247 IBindStatusCallback_OnProgress(This
->pbscb
, This
->total_read
, This
->expected_size
,
248 BINDSTATUS_ENDDOWNLOADDATA
, This
->URLName
);
249 IBindStatusCallback_OnDataAvailable(This
->pbscb
, BSCF_LASTDATANOTIFICATION
, This
->total_read
, &fmt
, &stg
);
252 WCHAR
*pwchError
= 0;
254 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM
|
255 FORMAT_MESSAGE_ALLOCATE_BUFFER
,
257 0, (LPWSTR
) &pwchError
,
261 static WCHAR achFormat
[] = { '%', '0', '8', 'x', 0 };
263 pwchError
=(WCHAR
*) LocalAlloc(LMEM_FIXED
, sizeof(WCHAR
) * 9);
264 wsprintfW(pwchError
, achFormat
, hr
);
266 IBindStatusCallback_OnStopBinding(This
->pbscb
, hr
, pwchError
);
267 LocalFree(pwchError
);
271 IBindStatusCallback_OnStopBinding(This
->pbscb
, hr
, NULL
);
273 IBindStatusCallback_Release(This
->pbscb
);
277 static const IBindingVtbl BindingVtbl
=
279 Binding_QueryInterface
,
287 Binding_GetBindResult
290 /* filemoniker data structure */
293 const IMonikerVtbl
* lpvtbl
; /* VTable relative to the IMoniker interface.*/
295 LONG ref
; /* reference counter for this object */
297 LPOLESTR URLName
; /* URL string identified by this URLmoniker */
300 /*******************************************************************************
301 * URLMoniker_QueryInterface
302 *******************************************************************************/
303 static HRESULT WINAPI
URLMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
305 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
307 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
309 /* Perform a sanity check on the parameters.*/
310 if ( (This
==0) || (ppvObject
==0) )
313 /* Initialize the return parameter */
316 /* Compare the riid with the interface IDs implemented by this object.*/
317 if (IsEqualIID(&IID_IUnknown
, riid
) ||
318 IsEqualIID(&IID_IPersist
, riid
) ||
319 IsEqualIID(&IID_IPersistStream
,riid
) ||
320 IsEqualIID(&IID_IMoniker
, riid
)
324 /* Check that we obtained an interface.*/
326 return E_NOINTERFACE
;
328 /* Query Interface always increases the reference count by one when it is successful */
329 IMoniker_AddRef(iface
);
334 /******************************************************************************
336 ******************************************************************************/
337 static ULONG WINAPI
URLMonikerImpl_AddRef(IMoniker
* iface
)
339 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
340 ULONG refCount
= InterlockedIncrement(&This
->ref
);
342 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
347 /******************************************************************************
349 ******************************************************************************/
350 static ULONG WINAPI
URLMonikerImpl_Release(IMoniker
* iface
)
352 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
353 ULONG refCount
= InterlockedDecrement(&This
->ref
);
355 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
357 /* destroy the object if there's no more reference on it */
359 HeapFree(GetProcessHeap(),0,This
->URLName
);
360 HeapFree(GetProcessHeap(),0,This
);
362 URLMON_UnlockModule();
369 /******************************************************************************
370 * URLMoniker_GetClassID
371 ******************************************************************************/
372 static HRESULT WINAPI
URLMonikerImpl_GetClassID(IMoniker
* iface
,
373 CLSID
*pClassID
)/* Pointer to CLSID of object */
375 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
377 TRACE("(%p,%p)\n",This
,pClassID
);
381 /* Windows always returns CLSID_StdURLMoniker */
382 *pClassID
= CLSID_StdURLMoniker
;
386 /******************************************************************************
388 ******************************************************************************/
389 static HRESULT WINAPI
URLMonikerImpl_IsDirty(IMoniker
* iface
)
391 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
392 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
393 method in the OLE-provided moniker interfaces always return S_FALSE because
394 their internal state never changes. */
396 TRACE("(%p)\n",This
);
401 /******************************************************************************
405 * Writes a ULONG containing length of unicode string, followed
406 * by that many unicode characters
407 ******************************************************************************/
408 static HRESULT WINAPI
URLMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
410 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
415 TRACE("(%p,%p)\n",This
,pStm
);
420 res
= IStream_Read(pStm
, &len
, sizeof(ULONG
), &got
);
422 if(got
== sizeof(ULONG
)) {
423 HeapFree(GetProcessHeap(), 0, This
->URLName
);
424 This
->URLName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(len
+1));
428 res
= IStream_Read(pStm
, This
->URLName
, len
, NULL
);
429 This
->URLName
[len
] = 0;
438 /******************************************************************************
440 ******************************************************************************/
441 static HRESULT WINAPI
URLMonikerImpl_Save(IMoniker
* iface
,
442 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
443 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
445 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
449 TRACE("(%p,%p,%d)\n",This
,pStm
,fClearDirty
);
454 len
= strlenW(This
->URLName
);
455 res
=IStream_Write(pStm
,&len
,sizeof(ULONG
),NULL
);
457 res
=IStream_Write(pStm
,&This
->URLName
,len
*sizeof(WCHAR
),NULL
);
462 /******************************************************************************
463 * URLMoniker_GetSizeMax
464 ******************************************************************************/
465 static HRESULT WINAPI
URLMonikerImpl_GetSizeMax(IMoniker
* iface
,
466 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
468 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
470 TRACE("(%p,%p)\n",This
,pcbSize
);
475 pcbSize
->u
.LowPart
= sizeof(ULONG
) + (strlenW(This
->URLName
) * sizeof(WCHAR
));
476 pcbSize
->u
.HighPart
= 0;
480 /******************************************************************************
481 * URLMoniker_BindToObject
482 ******************************************************************************/
483 static HRESULT WINAPI
URLMonikerImpl_BindToObject(IMoniker
* iface
,
489 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
493 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This
,pbc
,pmkToLeft
,debugstr_guid(riid
),
500 enum {OnProgress
, OnDataAvailable
} callback
;
501 } URLMON_CallbackData
;
505 static LRESULT CALLBACK
URLMON_WndProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
507 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
510 static void PostOnProgress(URLMonikerImpl
*This
, UINT progress
, UINT maxprogress
, DWORD status
, LPCWSTR
*str
)
514 static void CALLBACK
URLMON_InternetCallback(HINTERNET hinet
, /*DWORD_PTR*/ DWORD context
, DWORD status
,
515 void *status_info
, DWORD status_info_len
)
517 URLMonikerImpl
*This
= (URLMonikerImpl
*)context
;
518 TRACE("handle %p this %p status %08lx\n", hinet
, This
, status
);
520 if(This
->filesize
== -1) {
522 case INTERNET_STATUS_RESOLVING_NAME
:
523 PostOnProgess(This
, 0, 0, BINDSTATUS_FINDINGRESOURCE
, status_info
);
525 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
526 PostOnProgress(This
, 0, 0, BINDSTATUS_CONNECTING
, NULL
);
528 case INTERNET_STATUS_SENDING_REQUEST
:
529 PostOnProgress(This
, 0, 0, BINDSTATUS_SENDINGREQUEST
, NULL
);
531 case INTERNET_REQUEST_COMPLETE
:
533 DWORD len
, lensz
= sizeof(len
);
535 HttpQueryInfoW(hrequest
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &len
, &lensz
, NULL
);
536 TRACE("res = %ld gle = %08lx url len = %ld\n", hres
, GetLastError(), len
);
537 This
->filesize
= len
;
548 /******************************************************************************
549 * URLMoniker_BindToStorage
550 ******************************************************************************/
551 static HRESULT
URLMonikerImpl_BindToStorage_hack(LPCWSTR URLName
,
560 WCHAR szFileName
[MAX_PATH
+ 1];
564 WARN("(%s %p %p %s %p)\n", debugstr_w(URLName
), pbc
, pmkToLeft
, debugstr_guid(riid
),
568 FIXME("pmkToLeft != NULL\n");
571 if(!IsEqualIID(&IID_IStream
, riid
)) {
572 FIXME("unsupported iid\n");
576 bind
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Binding
));
577 bind
->lpVtbl
= &BindingVtbl
;
581 len
= lstrlenW(URLName
)+1;
582 bind
->URLName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
583 memcpy(bind
->URLName
, URLName
, len
*sizeof(WCHAR
));
585 hres
= UMCreateStreamOnCacheFile(bind
->URLName
, 0, szFileName
, &bind
->hCacheFile
, &bind
->pstrCache
);
587 if(SUCCEEDED(hres
)) {
588 TRACE("Created stream...\n");
590 *ppvObject
= (void *) bind
->pstrCache
;
591 IStream_AddRef((IStream
*) bind
->pstrCache
);
593 hres
= IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
**)&bind
->pbscb
);
594 if(SUCCEEDED(hres
)) {
595 TRACE("Got IBindStatusCallback...\n");
597 memset(&bi
, 0, sizeof(bi
));
598 bi
.cbSize
= sizeof(bi
);
600 hres
= IBindStatusCallback_GetBindInfo(bind
->pbscb
, &bindf
, &bi
);
601 if(SUCCEEDED(hres
)) {
602 WCHAR
*urlcopy
, *tmpwc
;
604 WCHAR
*host
, *path
, *partial_path
, *user
, *pass
;
605 DWORD lensz
= sizeof(bind
->expected_size
);
609 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
610 bindf
, debugstr_w(bi
.szExtraInfo
), bi
.grfBindInfoF
, bi
.dwBindVerb
, debugstr_guid(&bi
.iid
));
611 hres
= IBindStatusCallback_OnStartBinding(bind
->pbscb
, 0, (IBinding
*)bind
);
612 TRACE("OnStartBinding rets %08lx\n", hres
);
614 /* This class will accept URLs with the backslash in them. But InternetCrackURL will not - it
615 * requires forward slashes (this is the behaviour of Microsoft's INETAPI). So we need to make
616 * a copy of the URL here and change the backslash to a forward slash everywhere it appears -
617 * but only before any '#' or '?', after which backslash should be left alone.
619 urlcopy
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (lstrlenW(bind
->URLName
) + 1));
620 lstrcpyW(urlcopy
, bind
->URLName
);
621 for (tmpwc
= urlcopy
; *tmpwc
&& *tmpwc
!= '#' && *tmpwc
!= '?'; ++tmpwc
)
626 if(!registered_wndclass
) {
627 WNDCLASSA urlmon_wndclass
= {0, URLMON_WndProc
,0, 0, URLMON_hInstance
, 0, 0, 0, NULL
, "URLMON_Callback_Window_Class"};
628 RegisterClassA(&urlmon_wndclass
);
629 registered_wndclass
= TRUE
;
632 This
->hwndCallback
= CreateWindowA("URLMON_Callback_Window_Class", NULL
, 0, 0, 0, 0, 0, 0, 0,
633 URLMON_hInstance
, NULL
);
636 bind
->expected_size
= 0;
637 bind
->total_read
= 0;
639 memset(&url
, 0, sizeof(url
));
640 url
.dwStructSize
= sizeof(url
);
641 url
.dwSchemeLength
= url
.dwHostNameLength
= url
.dwUrlPathLength
= url
.dwUserNameLength
= url
.dwPasswordLength
= 1;
642 InternetCrackUrlW(urlcopy
, 0, ICU_ESCAPE
, &url
);
643 host
= HeapAlloc(GetProcessHeap(), 0, (url
.dwHostNameLength
+ 1) * sizeof(WCHAR
));
644 memcpy(host
, url
.lpszHostName
, url
.dwHostNameLength
* sizeof(WCHAR
));
645 host
[url
.dwHostNameLength
] = '\0';
646 path
= HeapAlloc(GetProcessHeap(), 0, (url
.dwUrlPathLength
+ 1) * sizeof(WCHAR
));
647 memcpy(path
, url
.lpszUrlPath
, url
.dwUrlPathLength
* sizeof(WCHAR
));
648 path
[url
.dwUrlPathLength
] = '\0';
649 if (url
.dwUserNameLength
)
651 user
= HeapAlloc(GetProcessHeap(), 0, ((url
.dwUserNameLength
+ 1) * sizeof(WCHAR
)));
652 memcpy(user
, url
.lpszUserName
, url
.dwUserNameLength
* sizeof(WCHAR
));
653 user
[url
.dwUserNameLength
] = 0;
659 if (url
.dwPasswordLength
)
661 pass
= HeapAlloc(GetProcessHeap(), 0, ((url
.dwPasswordLength
+ 1) * sizeof(WCHAR
)));
662 memcpy(pass
, url
.lpszPassword
, url
.dwPasswordLength
* sizeof(WCHAR
));
663 pass
[url
.dwPasswordLength
] = 0;
670 switch ((DWORD
) url
.nScheme
)
672 case INTERNET_SCHEME_FTP
:
673 case INTERNET_SCHEME_GOPHER
:
674 case INTERNET_SCHEME_HTTP
:
675 case INTERNET_SCHEME_HTTPS
:
677 bind
->hinternet
= InternetOpenA("User Agent", 0, NULL
, NULL
, 0 /*INTERNET_FLAG_ASYNC*/);
678 /* InternetSetStatusCallback(bind->hinternet, URLMON_InternetCallback);*/
679 if (!bind
->hinternet
)
681 hres
= HRESULT_FROM_WIN32(GetLastError());
685 switch ((DWORD
) url
.nScheme
)
687 case INTERNET_SCHEME_FTP
:
689 url
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
690 dwService
= INTERNET_SERVICE_FTP
;
693 case INTERNET_SCHEME_GOPHER
:
695 url
.nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
696 dwService
= INTERNET_SERVICE_GOPHER
;
699 case INTERNET_SCHEME_HTTP
:
701 url
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
702 dwService
= INTERNET_SERVICE_HTTP
;
705 case INTERNET_SCHEME_HTTPS
:
707 url
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
708 dwService
= INTERNET_SERVICE_HTTP
;
712 bind
->hconnect
= InternetConnectW(bind
->hinternet
, host
, url
.nPort
, user
, pass
,
713 dwService
, 0, (DWORD
)bind
);
716 hres
= HRESULT_FROM_WIN32(GetLastError());
717 CloseHandle(bind
->hinternet
);
721 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, 0x22, NULL
);
722 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_FINDINGRESOURCE
, NULL
);
723 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_CONNECTING
, NULL
);
724 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_SENDINGREQUEST
, NULL
);
730 case INTERNET_SERVICE_GOPHER
:
731 bind
->hrequest
= GopherOpenFileW(bind
->hconnect
,
734 INTERNET_FLAG_RELOAD
,
739 hres
= HRESULT_FROM_WIN32(GetLastError());
742 case INTERNET_SERVICE_FTP
:
743 bind
->hrequest
= FtpOpenFileW(bind
->hconnect
,
746 FTP_TRANSFER_TYPE_BINARY
|
747 INTERNET_FLAG_TRANSFER_BINARY
|
748 INTERNET_FLAG_RELOAD
,
753 hres
= HRESULT_FROM_WIN32(GetLastError());
756 case INTERNET_SERVICE_HTTP
:
757 bind
->hrequest
= HttpOpenRequestW(bind
->hconnect
, NULL
, path
, NULL
, NULL
, NULL
, 0, (DWORD
)bind
);
760 hres
= HRESULT_FROM_WIN32(GetLastError());
762 else if (!HttpSendRequestW(bind
->hrequest
, NULL
, 0, NULL
, 0))
764 hres
= HRESULT_FROM_WIN32(GetLastError());
765 InternetCloseHandle(bind
->hrequest
);
769 HttpQueryInfoW(bind
->hrequest
,
770 HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
,
771 &bind
->expected_size
,
780 TRACE("res = %ld gle = %08lx url len = %ld\n", hres
, GetLastError(), bind
->expected_size
);
782 IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE
, szFileName
);
787 if(InternetReadFile(bind
->hrequest
, buf
, sizeof(buf
), &bufread
)) {
788 TRACE("read %ld bytes %s...\n", bufread
, debugstr_an(buf
, 10));
789 if(bufread
== 0) break;
790 hres
= Binding_MoreCacheData(bind
, buf
, bufread
);
794 InternetCloseHandle(bind
->hrequest
);
798 InternetCloseHandle(bind
->hconnect
);
799 InternetCloseHandle(bind
->hinternet
);
802 case INTERNET_SCHEME_FILE
:
803 partial_path
= bind
->URLName
+ 5; /* Skip the "file:" part */
804 if ((partial_path
[0] != '/' && partial_path
[0] != '\\') ||
805 (partial_path
[1] != '/' && partial_path
[1] != '\\'))
814 if (partial_path
[0] == '/' || partial_path
[0] == '\\')
816 h
= CreateFileW(partial_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
817 if (h
== (HANDLE
) HFILE_ERROR
)
819 hres
= HRESULT_FROM_WIN32(GetLastError());
826 IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE
, szFileName
);
828 while (ReadFile(h
, buf
, sizeof(buf
), &bufread
, NULL
) && bufread
> 0)
829 hres
= Binding_MoreCacheData(bind
, buf
, bufread
);
839 FIXME("Unsupported URI scheme");
842 Binding_CloseCacheDownload(bind
);
843 Binding_FinishedDownload(bind
, hres
);
846 HeapFree(GetProcessHeap(), 0, user
);
848 HeapFree(GetProcessHeap(), 0, pass
);
849 HeapFree(GetProcessHeap(), 0, path
);
850 HeapFree(GetProcessHeap(), 0, host
);
851 HeapFree(GetProcessHeap(), 0, urlcopy
);
856 IBinding_Release((IBinding
*)bind
);
861 static HRESULT WINAPI
URLMonikerImpl_BindToStorage(IMoniker
* iface
,
867 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
871 URL_COMPONENTSW url
= {sizeof(URL_COMPONENTSW
), schema
,
872 sizeof(schema
)/sizeof(WCHAR
), 0, NULL
, 0, 0, NULL
, 0, NULL
, 0, NULL
, 0, NULL
, 0};
874 bret
= InternetCrackUrlW(This
->URLName
, 0, ICU_ESCAPE
, &url
);
876 ERR("InternetCrackUrl failed: %ld\n", GetLastError());
880 if(url
.nScheme
== INTERNET_SCHEME_HTTP
881 || url
.nScheme
== INTERNET_SCHEME_HTTPS
882 || url
.nScheme
== INTERNET_SCHEME_FTP
883 || url
.nScheme
== INTERNET_SCHEME_GOPHER
884 || url
.nScheme
== INTERNET_SCHEME_FILE
)
885 return URLMonikerImpl_BindToStorage_hack(This
->URLName
, pbc
, pmkToLeft
, riid
, ppvObject
);
887 TRACE("(%p)->(%p %p %s %p)\n", This
, pbc
, pmkToLeft
, debugstr_guid(riid
), ppvObject
);
889 return start_binding(This
->URLName
, pbc
, riid
, ppvObject
);
892 /******************************************************************************
894 ******************************************************************************/
895 static HRESULT WINAPI
URLMonikerImpl_Reduce(IMoniker
* iface
,
897 DWORD dwReduceHowFar
,
898 IMoniker
** ppmkToLeft
,
899 IMoniker
** ppmkReduced
)
901 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
903 TRACE("(%p,%p,%ld,%p,%p)\n",This
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
908 URLMonikerImpl_AddRef(iface
);
909 *ppmkReduced
= iface
;
910 return MK_S_REDUCED_TO_SELF
;
913 /******************************************************************************
914 * URLMoniker_ComposeWith
915 ******************************************************************************/
916 static HRESULT WINAPI
URLMonikerImpl_ComposeWith(IMoniker
* iface
,
918 BOOL fOnlyIfNotGeneric
,
919 IMoniker
** ppmkComposite
)
921 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
922 FIXME("(%p)->(%p,%d,%p): stub\n",This
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
927 /******************************************************************************
929 ******************************************************************************/
930 static HRESULT WINAPI
URLMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
932 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
933 TRACE("(%p,%d,%p)\n",This
,fForward
,ppenumMoniker
);
938 /* Does not support sub-monikers */
939 *ppenumMoniker
= NULL
;
943 /******************************************************************************
945 ******************************************************************************/
946 static HRESULT WINAPI
URLMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
948 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
954 TRACE("(%p,%p)\n",This
,pmkOtherMoniker
);
956 if(pmkOtherMoniker
==NULL
)
959 IMoniker_GetClassID(pmkOtherMoniker
,&clsid
);
961 if(!IsEqualCLSID(&clsid
,&CLSID_StdURLMoniker
))
964 res
= CreateBindCtx(0,&bind
);
969 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&urlPath
))) {
970 int result
= lstrcmpiW(urlPath
, This
->URLName
);
971 CoTaskMemFree(urlPath
);
975 IUnknown_Release(bind
);
980 /******************************************************************************
982 ******************************************************************************/
983 static HRESULT WINAPI
URLMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
985 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
987 int h
= 0,i
,skip
,len
;
991 TRACE("(%p,%p)\n",This
,pdwHash
);
1000 for(i
= len
; i
> 0; i
--) {
1001 h
= (h
* 37) + val
[off
++];
1005 /* only sample some characters */
1007 for(i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
1008 h
= (h
* 39) + val
[off
];
1015 /******************************************************************************
1016 * URLMoniker_IsRunning
1017 ******************************************************************************/
1018 static HRESULT WINAPI
URLMonikerImpl_IsRunning(IMoniker
* iface
,
1020 IMoniker
* pmkToLeft
,
1021 IMoniker
* pmkNewlyRunning
)
1023 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1024 FIXME("(%p)->(%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pmkNewlyRunning
);
1029 /******************************************************************************
1030 * URLMoniker_GetTimeOfLastChange
1031 ******************************************************************************/
1032 static HRESULT WINAPI
URLMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
1034 IMoniker
* pmkToLeft
,
1035 FILETIME
* pFileTime
)
1037 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1038 FIXME("(%p)->(%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pFileTime
);
1043 /******************************************************************************
1044 * URLMoniker_Inverse
1045 ******************************************************************************/
1046 static HRESULT WINAPI
URLMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
1048 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1049 TRACE("(%p,%p)\n",This
,ppmk
);
1051 return MK_E_NOINVERSE
;
1054 /******************************************************************************
1055 * URLMoniker_CommonPrefixWith
1056 ******************************************************************************/
1057 static HRESULT WINAPI
URLMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
1059 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1060 FIXME("(%p)->(%p,%p): stub\n",This
,pmkOther
,ppmkPrefix
);
1065 /******************************************************************************
1066 * URLMoniker_RelativePathTo
1067 ******************************************************************************/
1068 static HRESULT WINAPI
URLMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
1070 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1071 FIXME("(%p)->(%p,%p): stub\n",This
,pmOther
,ppmkRelPath
);
1076 /******************************************************************************
1077 * URLMoniker_GetDisplayName
1078 ******************************************************************************/
1079 static HRESULT WINAPI
URLMonikerImpl_GetDisplayName(IMoniker
* iface
,
1081 IMoniker
* pmkToLeft
,
1082 LPOLESTR
*ppszDisplayName
)
1084 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1088 TRACE("(%p,%p,%p,%p)\n",This
,pbc
,pmkToLeft
,ppszDisplayName
);
1090 if(!ppszDisplayName
)
1091 return E_INVALIDARG
;
1093 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
1094 then look at pmkToLeft to try and complete the URL
1096 len
= lstrlenW(This
->URLName
)+1;
1097 *ppszDisplayName
= CoTaskMemAlloc(len
*sizeof(WCHAR
));
1098 if(!*ppszDisplayName
)
1099 return E_OUTOFMEMORY
;
1100 lstrcpyW(*ppszDisplayName
, This
->URLName
);
1104 /******************************************************************************
1105 * URLMoniker_ParseDisplayName
1106 ******************************************************************************/
1107 static HRESULT WINAPI
URLMonikerImpl_ParseDisplayName(IMoniker
* iface
,
1109 IMoniker
* pmkToLeft
,
1110 LPOLESTR pszDisplayName
,
1114 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1115 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
1120 /******************************************************************************
1121 * URLMoniker_IsSystemMoniker
1122 ******************************************************************************/
1123 static HRESULT WINAPI
URLMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
1125 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1126 TRACE("(%p,%p)\n",This
,pwdMksys
);
1129 return E_INVALIDARG
;
1131 *pwdMksys
= MKSYS_URLMONIKER
;
1135 /********************************************************************************/
1136 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
1137 /* IPersistStream and IMoniker functions. */
1138 static const IMonikerVtbl VT_URLMonikerImpl
=
1140 URLMonikerImpl_QueryInterface
,
1141 URLMonikerImpl_AddRef
,
1142 URLMonikerImpl_Release
,
1143 URLMonikerImpl_GetClassID
,
1144 URLMonikerImpl_IsDirty
,
1145 URLMonikerImpl_Load
,
1146 URLMonikerImpl_Save
,
1147 URLMonikerImpl_GetSizeMax
,
1148 URLMonikerImpl_BindToObject
,
1149 URLMonikerImpl_BindToStorage
,
1150 URLMonikerImpl_Reduce
,
1151 URLMonikerImpl_ComposeWith
,
1152 URLMonikerImpl_Enum
,
1153 URLMonikerImpl_IsEqual
,
1154 URLMonikerImpl_Hash
,
1155 URLMonikerImpl_IsRunning
,
1156 URLMonikerImpl_GetTimeOfLastChange
,
1157 URLMonikerImpl_Inverse
,
1158 URLMonikerImpl_CommonPrefixWith
,
1159 URLMonikerImpl_RelativePathTo
,
1160 URLMonikerImpl_GetDisplayName
,
1161 URLMonikerImpl_ParseDisplayName
,
1162 URLMonikerImpl_IsSystemMoniker
1165 /******************************************************************************
1166 * URLMoniker_Construct (local function)
1167 *******************************************************************************/
1168 static HRESULT
URLMonikerImpl_Construct(URLMonikerImpl
* This
, LPCOLESTR lpszLeftURLName
, LPCOLESTR lpszURLName
)
1171 DWORD sizeStr
= INTERNET_MAX_URL_LENGTH
;
1173 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszLeftURLName
),debugstr_w(lpszURLName
));
1174 memset(This
, 0, sizeof(*This
));
1176 /* Initialize the virtual function table. */
1177 This
->lpvtbl
= &VT_URLMonikerImpl
;
1180 if(lpszLeftURLName
) {
1181 hres
= UrlCombineW(lpszLeftURLName
, lpszURLName
, NULL
, &sizeStr
, 0);
1188 sizeStr
= lstrlenW(lpszURLName
)+1;
1190 This
->URLName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr
));
1192 if (This
->URLName
==NULL
)
1193 return E_OUTOFMEMORY
;
1195 if(lpszLeftURLName
) {
1196 hres
= UrlCombineW(lpszLeftURLName
, lpszURLName
, This
->URLName
, &sizeStr
, 0);
1198 HeapFree(GetProcessHeap(), 0, This
->URLName
);
1203 strcpyW(This
->URLName
,lpszURLName
);
1205 URLMON_LockModule();
1210 /***********************************************************************
1211 * CreateAsyncBindCtx (URLMON.@)
1213 HRESULT WINAPI
CreateAsyncBindCtx(DWORD reserved
, IBindStatusCallback
*callback
,
1214 IEnumFORMATETC
*format
, IBindCtx
**pbind
)
1216 TRACE("(%08lx %p %p %p)\n", reserved
, callback
, format
, pbind
);
1219 return E_INVALIDARG
;
1221 return CreateAsyncBindCtxEx(NULL
, 0, callback
, format
, pbind
, 0);
1223 /***********************************************************************
1224 * CreateAsyncBindCtxEx (URLMON.@)
1226 * Create an asynchronous bind context.
1228 HRESULT WINAPI
CreateAsyncBindCtxEx(IBindCtx
*ibind
, DWORD options
,
1229 IBindStatusCallback
*callback
, IEnumFORMATETC
*format
, IBindCtx
** pbind
,
1236 TRACE("(%p %08lx %p %p %p %ld)\n", ibind
, options
, callback
, format
, pbind
, reserved
);
1239 return E_INVALIDARG
;
1242 FIXME("not supported options %08lx", options
);
1244 FIXME("format is not supported\n");
1247 WARN("reserved=%ld\n", reserved
);
1249 hres
= CreateBindCtx(0, &bctx
);
1253 bindopts
.cbStruct
= sizeof(BIND_OPTS
);
1254 bindopts
.grfFlags
= BIND_MAYBOTHERUSER
;
1255 bindopts
.grfMode
= STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
1256 bindopts
.dwTickCountDeadline
= 0;
1257 IBindCtx_SetBindOptions(bctx
, &bindopts
);
1260 RegisterBindStatusCallback(bctx
, callback
, NULL
, 0);
1268 /***********************************************************************
1269 * CreateURLMoniker (URLMON.@)
1271 * Create a url moniker.
1274 * pmkContext [I] Context
1275 * szURL [I] Url to create the moniker for
1276 * ppmk [O] Destination for created moniker.
1279 * Success: S_OK. ppmk contains the created IMoniker object.
1280 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1281 * E_OUTOFMEMORY if memory allocation fails.
1283 HRESULT WINAPI
CreateURLMoniker(IMoniker
*pmkContext
, LPCWSTR szURL
, IMoniker
**ppmk
)
1285 URLMonikerImpl
*obj
;
1287 IID iid
= IID_IMoniker
;
1288 LPOLESTR lefturl
= NULL
;
1290 TRACE("(%p, %s, %p)\n", pmkContext
, debugstr_w(szURL
), ppmk
);
1292 if(!(obj
= HeapAlloc(GetProcessHeap(), 0, sizeof(*obj
))))
1293 return E_OUTOFMEMORY
;
1298 IMoniker_IsSystemMoniker(pmkContext
, &dwMksys
);
1299 if(dwMksys
== MKSYS_URLMONIKER
&& SUCCEEDED(CreateBindCtx(0, &bind
))) {
1300 IMoniker_GetDisplayName(pmkContext
, bind
, NULL
, &lefturl
);
1301 TRACE("lefturl = %s\n", debugstr_w(lefturl
));
1302 IBindCtx_Release(bind
);
1306 hres
= URLMonikerImpl_Construct(obj
, lefturl
, szURL
);
1307 CoTaskMemFree(lefturl
);
1309 hres
= URLMonikerImpl_QueryInterface((IMoniker
*)obj
, &iid
, (void**)ppmk
);
1311 HeapFree(GetProcessHeap(), 0, obj
);
1315 /***********************************************************************
1316 * CoInternetQueryInfo (URLMON.@)
1318 * Retrieves information relevant to a specified URL
1322 * S_FALSE buffer too small
1323 * INET_E_QUERYOPTIONUNKNOWN invalid option
1326 HRESULT WINAPI
CoInternetQueryInfo(LPCWSTR pwzUrl
, QUERYOPTION QueryOption
,
1327 DWORD dwQueryFlags
, LPVOID pvBuffer
, DWORD cbBuffer
, DWORD
* pcbBuffer
,
1330 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl
),
1331 QueryOption
, dwQueryFlags
, pvBuffer
, cbBuffer
, pcbBuffer
, dwReserved
);
1335 /***********************************************************************
1336 * IsAsyncMoniker (URLMON.@)
1338 HRESULT WINAPI
IsAsyncMoniker(IMoniker
*pmk
)
1342 TRACE("(%p)\n", pmk
);
1344 return E_INVALIDARG
;
1345 if(SUCCEEDED(IMoniker_QueryInterface(pmk
, &IID_IAsyncMoniker
, (void**)&am
))) {
1346 IUnknown_Release(am
);
1352 /***********************************************************************
1353 * RegisterBindStatusCallback (URLMON.@)
1355 * Register a bind status callback.
1358 * pbc [I] Binding context
1359 * pbsc [I] Callback to register
1360 * ppbscPrevious [O] Destination for previous callback
1361 * dwReserved [I] Reserved, must be 0.
1365 * Failure: E_INVALIDARG, if any argument is invalid, or
1366 * E_OUTOFMEMORY if memory allocation fails.
1368 HRESULT WINAPI
RegisterBindStatusCallback(
1370 IBindStatusCallback
*pbsc
,
1371 IBindStatusCallback
**ppbscPrevious
,
1374 IBindStatusCallback
*prev
;
1376 TRACE("(%p,%p,%p,%lu)\n", pbc
, pbsc
, ppbscPrevious
, dwReserved
);
1378 if (pbc
== NULL
|| pbsc
== NULL
)
1379 return E_INVALIDARG
;
1381 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
**)&prev
)))
1383 IBindCtx_RevokeObjectParam(pbc
, (LPOLESTR
)BSCBHolder
);
1385 *ppbscPrevious
= prev
;
1387 IBindStatusCallback_Release(prev
);
1390 return IBindCtx_RegisterObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
*)pbsc
);
1393 /***********************************************************************
1394 * RevokeBindStatusCallback (URLMON.@)
1396 * Unregister a bind status callback.
1398 * pbc [I] Binding context
1399 * pbsc [I] Callback to unregister
1403 * Failure: E_INVALIDARG, if any argument is invalid, or
1404 * E_FAIL if pbsc wasn't registered with pbc.
1406 HRESULT WINAPI
RevokeBindStatusCallback(
1408 IBindStatusCallback
*pbsc
)
1410 IBindStatusCallback
*callback
;
1411 HRESULT hr
= E_FAIL
;
1413 TRACE("(%p,%p)\n", pbc
, pbsc
);
1415 if (pbc
== NULL
|| pbsc
== NULL
)
1416 return E_INVALIDARG
;
1418 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
**)&callback
)))
1420 if (callback
== pbsc
)
1422 IBindCtx_RevokeObjectParam(pbc
, (LPOLESTR
)BSCBHolder
);
1425 IBindStatusCallback_Release(pbsc
);
1431 /***********************************************************************
1432 * URLDownloadToFileA (URLMON.@)
1434 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1438 * pCaller [I] controlling IUnknown interface.
1439 * szURL [I] URL of the file to download
1440 * szFileName [I] file name to store the content of the URL
1441 * dwReserved [I] reserved - set to 0
1442 * lpfnCB [I] callback for progress report
1446 * E_OUTOFMEMORY when going out of memory
1448 HRESULT WINAPI
URLDownloadToFileA(LPUNKNOWN pCaller
,
1452 LPBINDSTATUSCALLBACK lpfnCB
)
1454 UNICODE_STRING szURL_w
, szFileName_w
;
1456 if ((szURL
== NULL
) || (szFileName
== NULL
)) {
1457 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller
, debugstr_a(szURL
), debugstr_a(szFileName
), dwReserved
, lpfnCB
);
1458 return E_INVALIDARG
; /* The error code is not specified in this case... */
1461 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w
, szURL
)) {
1462 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w
, szFileName
)) {
1463 HRESULT ret
= URLDownloadToFileW(pCaller
, szURL_w
.Buffer
, szFileName_w
.Buffer
, dwReserved
, lpfnCB
);
1465 RtlFreeUnicodeString(&szURL_w
);
1466 RtlFreeUnicodeString(&szFileName_w
);
1470 RtlFreeUnicodeString(&szURL_w
);
1474 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller
, szURL
, szFileName
, dwReserved
, lpfnCB
);
1475 return E_OUTOFMEMORY
;
1478 /***********************************************************************
1479 * URLDownloadToFileW (URLMON.@)
1481 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1485 * pCaller [I] controlling IUnknown interface.
1486 * szURL [I] URL of the file to download
1487 * szFileName [I] file name to store the content of the URL
1488 * dwReserved [I] reserved - set to 0
1489 * lpfnCB [I] callback for progress report
1493 * E_OUTOFMEMORY when going out of memory
1495 HRESULT WINAPI
URLDownloadToFileW(LPUNKNOWN pCaller
,
1499 LPBINDSTATUSCALLBACK lpfnCB
)
1501 HINTERNET hinternet
, hcon
, hreq
;
1503 CHAR buffer
[0x1000];
1504 DWORD sz
, total
, written
;
1505 DWORD total_size
= 0xFFFFFFFF, arg_size
= sizeof(total_size
);
1506 URL_COMPONENTSW url
;
1507 WCHAR host
[0x80], path
[0x100];
1509 static const WCHAR wszAppName
[]={'u','r','l','m','o','n','.','d','l','l',0};
1511 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1512 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller
, debugstr_w(szURL
), debugstr_w(szFileName
), dwReserved
, lpfnCB
);
1514 if ((szURL
== NULL
) || (szFileName
== NULL
)) {
1515 FIXME(" cannot accept NULL strings !\n");
1516 return E_INVALIDARG
;
1519 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1520 hinternet
= InternetOpenW(wszAppName
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1521 if (hinternet
== NULL
) {
1522 return E_OUTOFMEMORY
;
1525 memset(&url
, 0, sizeof(url
));
1526 url
.dwStructSize
= sizeof(url
);
1527 url
.lpszHostName
= host
;
1528 url
.dwHostNameLength
= sizeof(host
);
1529 url
.lpszUrlPath
= path
;
1530 url
.dwUrlPathLength
= sizeof(path
);
1532 if (!InternetCrackUrlW(szURL
, 0, 0, &url
)) {
1533 InternetCloseHandle(hinternet
);
1534 return E_OUTOFMEMORY
;
1538 if (IBindStatusCallback_OnProgress(lpfnCB
, 0, 0, BINDSTATUS_CONNECTING
, url
.lpszHostName
) == E_ABORT
) {
1539 InternetCloseHandle(hinternet
);
1544 hcon
= InternetConnectW(hinternet
, url
.lpszHostName
, url
.nPort
,
1545 url
.lpszUserName
, url
.lpszPassword
,
1546 INTERNET_SERVICE_HTTP
, 0, 0);
1548 InternetCloseHandle(hinternet
);
1549 return E_OUTOFMEMORY
;
1552 hreq
= HttpOpenRequestW(hcon
, NULL
, url
.lpszUrlPath
, NULL
, NULL
, NULL
, 0, 0);
1554 InternetCloseHandle(hinternet
);
1555 InternetCloseHandle(hcon
);
1556 return E_OUTOFMEMORY
;
1559 if (!HttpSendRequestW(hreq
, NULL
, 0, NULL
, 0)) {
1560 InternetCloseHandle(hinternet
);
1561 InternetCloseHandle(hcon
);
1562 InternetCloseHandle(hreq
);
1563 return E_OUTOFMEMORY
;
1566 if (HttpQueryInfoW(hreq
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
,
1567 &total_size
, &arg_size
, NULL
)) {
1568 TRACE(" total size : %ld\n", total_size
);
1571 hfile
= CreateFileW(szFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1572 FILE_ATTRIBUTE_NORMAL
, NULL
);
1573 if (hfile
== INVALID_HANDLE_VALUE
) {
1574 return E_ACCESSDENIED
;
1578 if (IBindStatusCallback_OnProgress(lpfnCB
, 0, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1579 BINDSTATUS_BEGINDOWNLOADDATA
, szURL
) == E_ABORT
) {
1580 InternetCloseHandle(hreq
);
1581 InternetCloseHandle(hcon
);
1582 InternetCloseHandle(hinternet
);
1590 r
= InternetReadFile(hreq
, buffer
, sizeof(buffer
), &sz
);
1592 InternetCloseHandle(hreq
);
1593 InternetCloseHandle(hcon
);
1594 InternetCloseHandle(hinternet
);
1597 return E_OUTOFMEMORY
;
1605 if (IBindStatusCallback_OnProgress(lpfnCB
, total
, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1606 BINDSTATUS_DOWNLOADINGDATA
, szURL
) == E_ABORT
) {
1607 InternetCloseHandle(hreq
);
1608 InternetCloseHandle(hcon
);
1609 InternetCloseHandle(hinternet
);
1615 if (!WriteFile(hfile
, buffer
, sz
, &written
, NULL
)) {
1616 InternetCloseHandle(hreq
);
1617 InternetCloseHandle(hcon
);
1618 InternetCloseHandle(hinternet
);
1621 return E_OUTOFMEMORY
;
1626 if (IBindStatusCallback_OnProgress(lpfnCB
, total
, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1627 BINDSTATUS_ENDDOWNLOADDATA
, szURL
) == E_ABORT
) {
1628 InternetCloseHandle(hreq
);
1629 InternetCloseHandle(hcon
);
1630 InternetCloseHandle(hinternet
);
1636 InternetCloseHandle(hreq
);
1637 InternetCloseHandle(hcon
);
1638 InternetCloseHandle(hinternet
);
1645 /***********************************************************************
1646 * URLDownloadToCacheFileA (URLMON.@)
1648 HRESULT WINAPI
URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller
, LPCSTR szURL
, LPSTR szFileName
,
1649 DWORD dwBufLength
, DWORD dwReserved
, LPBINDSTATUSCALLBACK pBSC
)
1651 LPWSTR url
= NULL
, file_name
= NULL
;
1655 TRACE("(%p %s %p %ld %ld %p)\n", lpUnkCaller
, debugstr_a(szURL
), szFileName
,
1656 dwBufLength
, dwReserved
, pBSC
);
1659 len
= MultiByteToWideChar(CP_ACP
, 0, szURL
, -1, NULL
, 0);
1660 url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1661 MultiByteToWideChar(CP_ACP
, 0, szURL
, -1, url
, -1);
1665 file_name
= HeapAlloc(GetProcessHeap(), 0, dwBufLength
*sizeof(WCHAR
));
1667 hres
= URLDownloadToCacheFileW(lpUnkCaller
, url
, file_name
, dwBufLength
*sizeof(WCHAR
),
1670 if(SUCCEEDED(hres
) && file_name
)
1671 WideCharToMultiByte(CP_ACP
, 0, file_name
, -1, szFileName
, dwBufLength
, NULL
, NULL
);
1673 HeapFree(GetProcessHeap(), 0, url
);
1674 HeapFree(GetProcessHeap(), 0, file_name
);
1679 /***********************************************************************
1680 * URLDownloadToCacheFileW (URLMON.@)
1682 HRESULT WINAPI
URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller
, LPCWSTR szURL
, LPWSTR szFileName
,
1683 DWORD dwBufLength
, DWORD dwReserved
, LPBINDSTATUSCALLBACK pBSC
)
1685 FIXME("(%p %s %p %ld %ld %p)\n", lpUnkCaller
, debugstr_w(szURL
), szFileName
,
1686 dwBufLength
, dwReserved
, pBSC
);
1690 /***********************************************************************
1691 * HlinkSimpleNavigateToString (URLMON.@)
1693 HRESULT WINAPI
HlinkSimpleNavigateToString( LPCWSTR szTarget
,
1694 LPCWSTR szLocation
, LPCWSTR szTargetFrameName
, IUnknown
*pUnk
,
1695 IBindCtx
*pbc
, IBindStatusCallback
*pbsc
, DWORD grfHLNF
, DWORD dwReserved
)
1697 FIXME("%s\n", debugstr_w( szTarget
) );
1701 /***********************************************************************
1702 * HlinkNavigateString (URLMON.@)
1704 HRESULT WINAPI
HlinkNavigateString( IUnknown
*pUnk
, LPCWSTR szTarget
)
1706 TRACE("%p %s\n", pUnk
, debugstr_w( szTarget
) );
1707 return HlinkSimpleNavigateToString(
1708 szTarget
, NULL
, NULL
, pUnk
, NULL
, NULL
, 0, 0 );
1711 /***********************************************************************
1712 * GetSoftwareUpdateInfo (URLMON.@)
1714 HRESULT WINAPI
GetSoftwareUpdateInfo( LPCWSTR szDistUnit
, LPSOFTDISTINFO psdi
)
1716 FIXME("%s %p\n", debugstr_w(szDistUnit
), psdi
);