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
, BINDSTATUS_ENDDOWNLOADDATA
, NULL
);
248 IBindStatusCallback_OnDataAvailable(This
->pbscb
, BSCF_LASTDATANOTIFICATION
, This
->total_read
, &fmt
, &stg
);
251 WCHAR
*pwchError
= 0;
253 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM
|
254 FORMAT_MESSAGE_ALLOCATE_BUFFER
,
256 0, (LPWSTR
) &pwchError
,
260 static WCHAR achFormat
[] = { '%', '0', '8', 'x', 0 };
262 pwchError
=(WCHAR
*) LocalAlloc(LMEM_FIXED
, sizeof(WCHAR
) * 9);
263 wsprintfW(pwchError
, achFormat
, hr
);
265 IBindStatusCallback_OnStopBinding(This
->pbscb
, hr
, pwchError
);
266 LocalFree(pwchError
);
270 IBindStatusCallback_OnStopBinding(This
->pbscb
, hr
, NULL
);
272 IBindStatusCallback_Release(This
->pbscb
);
276 static const IBindingVtbl BindingVtbl
=
278 Binding_QueryInterface
,
286 Binding_GetBindResult
289 /* filemoniker data structure */
292 const IMonikerVtbl
* lpvtbl
; /* VTable relative to the IMoniker interface.*/
294 LONG ref
; /* reference counter for this object */
296 LPOLESTR URLName
; /* URL string identified by this URLmoniker */
299 /*******************************************************************************
300 * URLMoniker_QueryInterface
301 *******************************************************************************/
302 static HRESULT WINAPI
URLMonikerImpl_QueryInterface(IMoniker
* iface
,REFIID riid
,void** ppvObject
)
304 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
306 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),ppvObject
);
308 /* Perform a sanity check on the parameters.*/
309 if ( (This
==0) || (ppvObject
==0) )
312 /* Initialize the return parameter */
315 /* Compare the riid with the interface IDs implemented by this object.*/
316 if (IsEqualIID(&IID_IUnknown
, riid
) ||
317 IsEqualIID(&IID_IPersist
, riid
) ||
318 IsEqualIID(&IID_IPersistStream
,riid
) ||
319 IsEqualIID(&IID_IMoniker
, riid
)
323 /* Check that we obtained an interface.*/
325 return E_NOINTERFACE
;
327 /* Query Interface always increases the reference count by one when it is successful */
328 IMoniker_AddRef(iface
);
333 /******************************************************************************
335 ******************************************************************************/
336 static ULONG WINAPI
URLMonikerImpl_AddRef(IMoniker
* iface
)
338 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
339 ULONG refCount
= InterlockedIncrement(&This
->ref
);
341 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
- 1);
346 /******************************************************************************
348 ******************************************************************************/
349 static ULONG WINAPI
URLMonikerImpl_Release(IMoniker
* iface
)
351 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
352 ULONG refCount
= InterlockedDecrement(&This
->ref
);
354 TRACE("(%p)->(ref before=%lu)\n",This
, refCount
+ 1);
356 /* destroy the object if there's no more reference on it */
358 HeapFree(GetProcessHeap(),0,This
->URLName
);
359 HeapFree(GetProcessHeap(),0,This
);
361 URLMON_UnlockModule();
368 /******************************************************************************
369 * URLMoniker_GetClassID
370 ******************************************************************************/
371 static HRESULT WINAPI
URLMonikerImpl_GetClassID(IMoniker
* iface
,
372 CLSID
*pClassID
)/* Pointer to CLSID of object */
374 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
376 TRACE("(%p,%p)\n",This
,pClassID
);
380 /* Windows always returns CLSID_StdURLMoniker */
381 *pClassID
= CLSID_StdURLMoniker
;
385 /******************************************************************************
387 ******************************************************************************/
388 static HRESULT WINAPI
URLMonikerImpl_IsDirty(IMoniker
* iface
)
390 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
391 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
392 method in the OLE-provided moniker interfaces always return S_FALSE because
393 their internal state never changes. */
395 TRACE("(%p)\n",This
);
400 /******************************************************************************
404 * Writes a ULONG containing length of unicode string, followed
405 * by that many unicode characters
406 ******************************************************************************/
407 static HRESULT WINAPI
URLMonikerImpl_Load(IMoniker
* iface
,IStream
* pStm
)
409 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
414 TRACE("(%p,%p)\n",This
,pStm
);
419 res
= IStream_Read(pStm
, &len
, sizeof(ULONG
), &got
);
421 if(got
== sizeof(ULONG
)) {
422 HeapFree(GetProcessHeap(), 0, This
->URLName
);
423 This
->URLName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(len
+1));
427 res
= IStream_Read(pStm
, This
->URLName
, len
, NULL
);
428 This
->URLName
[len
] = 0;
437 /******************************************************************************
439 ******************************************************************************/
440 static HRESULT WINAPI
URLMonikerImpl_Save(IMoniker
* iface
,
441 IStream
* pStm
,/* pointer to the stream where the object is to be saved */
442 BOOL fClearDirty
)/* Specifies whether to clear the dirty flag */
444 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
448 TRACE("(%p,%p,%d)\n",This
,pStm
,fClearDirty
);
453 len
= strlenW(This
->URLName
);
454 res
=IStream_Write(pStm
,&len
,sizeof(ULONG
),NULL
);
456 res
=IStream_Write(pStm
,&This
->URLName
,len
*sizeof(WCHAR
),NULL
);
461 /******************************************************************************
462 * URLMoniker_GetSizeMax
463 ******************************************************************************/
464 static HRESULT WINAPI
URLMonikerImpl_GetSizeMax(IMoniker
* iface
,
465 ULARGE_INTEGER
* pcbSize
)/* Pointer to size of stream needed to save object */
467 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
469 TRACE("(%p,%p)\n",This
,pcbSize
);
474 pcbSize
->u
.LowPart
= sizeof(ULONG
) + (strlenW(This
->URLName
) * sizeof(WCHAR
));
475 pcbSize
->u
.HighPart
= 0;
479 /******************************************************************************
480 * URLMoniker_BindToObject
481 ******************************************************************************/
482 static HRESULT WINAPI
URLMonikerImpl_BindToObject(IMoniker
* iface
,
488 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
492 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This
,pbc
,pmkToLeft
,debugstr_guid(riid
),
499 enum {OnProgress
, OnDataAvailable
} callback
;
500 } URLMON_CallbackData
;
504 static LRESULT CALLBACK
URLMON_WndProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
506 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
509 static void PostOnProgress(URLMonikerImpl
*This
, UINT progress
, UINT maxprogress
, DWORD status
, LPCWSTR
*str
)
513 static void CALLBACK
URLMON_InternetCallback(HINTERNET hinet
, /*DWORD_PTR*/ DWORD context
, DWORD status
,
514 void *status_info
, DWORD status_info_len
)
516 URLMonikerImpl
*This
= (URLMonikerImpl
*)context
;
517 TRACE("handle %p this %p status %08lx\n", hinet
, This
, status
);
519 if(This
->filesize
== -1) {
521 case INTERNET_STATUS_RESOLVING_NAME
:
522 PostOnProgess(This
, 0, 0, BINDSTATUS_FINDINGRESOURCE
, status_info
);
524 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
525 PostOnProgress(This
, 0, 0, BINDSTATUS_CONNECTING
, NULL
);
527 case INTERNET_STATUS_SENDING_REQUEST
:
528 PostOnProgress(This
, 0, 0, BINDSTATUS_SENDINGREQUEST
, NULL
);
530 case INTERNET_REQUEST_COMPLETE
:
532 DWORD len
, lensz
= sizeof(len
);
534 HttpQueryInfoW(hrequest
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &len
, &lensz
, NULL
);
535 TRACE("res = %ld gle = %08lx url len = %ld\n", hres
, GetLastError(), len
);
536 This
->filesize
= len
;
547 /******************************************************************************
548 * URLMoniker_BindToStorage
549 ******************************************************************************/
550 static HRESULT WINAPI
URLMonikerImpl_BindToStorage(IMoniker
* iface
,
556 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
560 WCHAR szFileName
[MAX_PATH
+ 1];
565 FIXME("pmkToLeft != NULL\n");
568 if(!IsEqualIID(&IID_IStream
, riid
)) {
569 FIXME("unsupported iid\n");
573 bind
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(Binding
));
574 bind
->lpVtbl
= &BindingVtbl
;
578 len
= lstrlenW(This
->URLName
)+1;
579 bind
->URLName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
580 memcpy(bind
->URLName
, This
->URLName
, len
*sizeof(WCHAR
));
582 hres
= UMCreateStreamOnCacheFile(bind
->URLName
, 0, szFileName
, &bind
->hCacheFile
, &bind
->pstrCache
);
584 if(SUCCEEDED(hres
)) {
585 TRACE("Created stream...\n");
587 *ppvObject
= (void *) bind
->pstrCache
;
588 IStream_AddRef((IStream
*) bind
->pstrCache
);
590 hres
= IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
**)&bind
->pbscb
);
591 if(SUCCEEDED(hres
)) {
592 TRACE("Got IBindStatusCallback...\n");
594 memset(&bi
, 0, sizeof(bi
));
595 bi
.cbSize
= sizeof(bi
);
597 hres
= IBindStatusCallback_GetBindInfo(bind
->pbscb
, &bindf
, &bi
);
598 if(SUCCEEDED(hres
)) {
599 WCHAR
*urlcopy
, *tmpwc
;
601 WCHAR
*host
, *path
, *partial_path
, *user
, *pass
;
602 DWORD lensz
= sizeof(bind
->expected_size
);
606 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
607 bindf
, debugstr_w(bi
.szExtraInfo
), bi
.grfBindInfoF
, bi
.dwBindVerb
, debugstr_guid(&bi
.iid
));
608 hres
= IBindStatusCallback_OnStartBinding(bind
->pbscb
, 0, (IBinding
*)bind
);
609 TRACE("OnStartBinding rets %08lx\n", hres
);
611 /* This class will accept URLs with the backslash in them. But InternetCrackURL will not - it
612 * requires forward slashes (this is the behaviour of Microsoft's INETAPI). So we need to make
613 * a copy of the URL here and change the backslash to a forward slash everywhere it appears -
614 * but only before any '#' or '?', after which backslash should be left alone.
616 urlcopy
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (lstrlenW(bind
->URLName
) + 1));
617 lstrcpyW(urlcopy
, bind
->URLName
);
618 for (tmpwc
= urlcopy
; *tmpwc
&& *tmpwc
!= '#' && *tmpwc
!= '?'; ++tmpwc
)
623 if(!registered_wndclass
) {
624 WNDCLASSA urlmon_wndclass
= {0, URLMON_WndProc
,0, 0, URLMON_hInstance
, 0, 0, 0, NULL
, "URLMON_Callback_Window_Class"};
625 RegisterClassA(&urlmon_wndclass
);
626 registered_wndclass
= TRUE
;
629 This
->hwndCallback
= CreateWindowA("URLMON_Callback_Window_Class", NULL
, 0, 0, 0, 0, 0, 0, 0,
630 URLMON_hInstance
, NULL
);
633 bind
->expected_size
= 0;
634 bind
->total_read
= 0;
636 memset(&url
, 0, sizeof(url
));
637 url
.dwStructSize
= sizeof(url
);
638 url
.dwSchemeLength
= url
.dwHostNameLength
= url
.dwUrlPathLength
= url
.dwUserNameLength
= url
.dwPasswordLength
= 1;
639 InternetCrackUrlW(urlcopy
, 0, ICU_ESCAPE
, &url
);
640 host
= HeapAlloc(GetProcessHeap(), 0, (url
.dwHostNameLength
+ 1) * sizeof(WCHAR
));
641 memcpy(host
, url
.lpszHostName
, url
.dwHostNameLength
* sizeof(WCHAR
));
642 host
[url
.dwHostNameLength
] = '\0';
643 path
= HeapAlloc(GetProcessHeap(), 0, (url
.dwUrlPathLength
+ 1) * sizeof(WCHAR
));
644 memcpy(path
, url
.lpszUrlPath
, url
.dwUrlPathLength
* sizeof(WCHAR
));
645 path
[url
.dwUrlPathLength
] = '\0';
646 if (url
.dwUserNameLength
)
648 user
= HeapAlloc(GetProcessHeap(), 0, ((url
.dwUserNameLength
+ 1) * sizeof(WCHAR
)));
649 memcpy(user
, url
.lpszUserName
, url
.dwUserNameLength
* sizeof(WCHAR
));
650 user
[url
.dwUserNameLength
] = 0;
656 if (url
.dwPasswordLength
)
658 pass
= HeapAlloc(GetProcessHeap(), 0, ((url
.dwPasswordLength
+ 1) * sizeof(WCHAR
)));
659 memcpy(pass
, url
.lpszPassword
, url
.dwPasswordLength
* sizeof(WCHAR
));
660 pass
[url
.dwPasswordLength
] = 0;
667 switch ((DWORD
) url
.nScheme
)
669 case INTERNET_SCHEME_FTP
:
670 case INTERNET_SCHEME_GOPHER
:
671 case INTERNET_SCHEME_HTTP
:
672 case INTERNET_SCHEME_HTTPS
:
674 bind
->hinternet
= InternetOpenA("User Agent", 0, NULL
, NULL
, 0 /*INTERNET_FLAG_ASYNC*/);
675 /* InternetSetStatusCallback(bind->hinternet, URLMON_InternetCallback);*/
676 if (!bind
->hinternet
)
678 hres
= HRESULT_FROM_WIN32(GetLastError());
682 switch ((DWORD
) url
.nScheme
)
684 case INTERNET_SCHEME_FTP
:
686 url
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
687 dwService
= INTERNET_SERVICE_FTP
;
690 case INTERNET_SCHEME_GOPHER
:
692 url
.nPort
= INTERNET_DEFAULT_GOPHER_PORT
;
693 dwService
= INTERNET_SERVICE_GOPHER
;
696 case INTERNET_SCHEME_HTTP
:
698 url
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
699 dwService
= INTERNET_SERVICE_HTTP
;
702 case INTERNET_SCHEME_HTTPS
:
704 url
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
705 dwService
= INTERNET_SERVICE_HTTP
;
709 bind
->hconnect
= InternetConnectW(bind
->hinternet
, host
, url
.nPort
, user
, pass
,
710 dwService
, 0, (DWORD
)bind
);
713 hres
= HRESULT_FROM_WIN32(GetLastError());
714 CloseHandle(bind
->hinternet
);
718 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, 0x22, NULL
);
719 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_FINDINGRESOURCE
, NULL
);
720 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_CONNECTING
, NULL
);
721 hres
= IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_SENDINGREQUEST
, NULL
);
727 case INTERNET_SERVICE_GOPHER
:
728 bind
->hrequest
= GopherOpenFileW(bind
->hconnect
,
731 INTERNET_FLAG_RELOAD
,
736 hres
= HRESULT_FROM_WIN32(GetLastError());
739 case INTERNET_SERVICE_FTP
:
740 bind
->hrequest
= FtpOpenFileW(bind
->hconnect
,
743 FTP_TRANSFER_TYPE_BINARY
|
744 INTERNET_FLAG_TRANSFER_BINARY
|
745 INTERNET_FLAG_RELOAD
,
750 hres
= HRESULT_FROM_WIN32(GetLastError());
753 case INTERNET_SERVICE_HTTP
:
754 bind
->hrequest
= HttpOpenRequestW(bind
->hconnect
, NULL
, path
, NULL
, NULL
, NULL
, 0, (DWORD
)bind
);
757 hres
= HRESULT_FROM_WIN32(GetLastError());
759 else if (!HttpSendRequestW(bind
->hrequest
, NULL
, 0, NULL
, 0))
761 hres
= HRESULT_FROM_WIN32(GetLastError());
762 InternetCloseHandle(bind
->hrequest
);
766 HttpQueryInfoW(bind
->hrequest
,
767 HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
,
768 &bind
->expected_size
,
777 TRACE("res = %ld gle = %08lx url len = %ld\n", hres
, GetLastError(), bind
->expected_size
);
779 IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE
, szFileName
);
784 if(InternetReadFile(bind
->hrequest
, buf
, sizeof(buf
), &bufread
)) {
785 TRACE("read %ld bytes %s...\n", bufread
, debugstr_an(buf
, 10));
786 if(bufread
== 0) break;
787 hres
= Binding_MoreCacheData(bind
, buf
, bufread
);
791 InternetCloseHandle(bind
->hrequest
);
795 InternetCloseHandle(bind
->hconnect
);
796 InternetCloseHandle(bind
->hinternet
);
799 case INTERNET_SCHEME_FILE
:
800 partial_path
= bind
->URLName
+ 5; /* Skip the "file:" part */
801 if ((partial_path
[0] != '/' && partial_path
[0] != '\\') ||
802 (partial_path
[1] != '/' && partial_path
[1] != '\\'))
811 if (partial_path
[0] == '/' || partial_path
[0] == '\\')
813 h
= CreateFileW(partial_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
814 if (h
== (HANDLE
) HFILE_ERROR
)
816 hres
= HRESULT_FROM_WIN32(GetLastError());
823 IBindStatusCallback_OnProgress(bind
->pbscb
, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE
, szFileName
);
825 while (ReadFile(h
, buf
, sizeof(buf
), &bufread
, NULL
) && bufread
> 0)
826 hres
= Binding_MoreCacheData(bind
, buf
, bufread
);
836 FIXME("Unsupported URI scheme");
839 Binding_CloseCacheDownload(bind
);
840 Binding_FinishedDownload(bind
, hres
);
843 HeapFree(GetProcessHeap(), 0, user
);
845 HeapFree(GetProcessHeap(), 0, pass
);
846 HeapFree(GetProcessHeap(), 0, path
);
847 HeapFree(GetProcessHeap(), 0, host
);
848 HeapFree(GetProcessHeap(), 0, urlcopy
);
853 IBinding_Release((IBinding
*)bind
);
858 /******************************************************************************
860 ******************************************************************************/
861 static HRESULT WINAPI
URLMonikerImpl_Reduce(IMoniker
* iface
,
863 DWORD dwReduceHowFar
,
864 IMoniker
** ppmkToLeft
,
865 IMoniker
** ppmkReduced
)
867 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
869 TRACE("(%p,%p,%ld,%p,%p)\n",This
,pbc
,dwReduceHowFar
,ppmkToLeft
,ppmkReduced
);
874 URLMonikerImpl_AddRef(iface
);
875 *ppmkReduced
= iface
;
876 return MK_S_REDUCED_TO_SELF
;
879 /******************************************************************************
880 * URLMoniker_ComposeWith
881 ******************************************************************************/
882 static HRESULT WINAPI
URLMonikerImpl_ComposeWith(IMoniker
* iface
,
884 BOOL fOnlyIfNotGeneric
,
885 IMoniker
** ppmkComposite
)
887 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
888 FIXME("(%p)->(%p,%d,%p): stub\n",This
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
893 /******************************************************************************
895 ******************************************************************************/
896 static HRESULT WINAPI
URLMonikerImpl_Enum(IMoniker
* iface
,BOOL fForward
, IEnumMoniker
** ppenumMoniker
)
898 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
899 TRACE("(%p,%d,%p)\n",This
,fForward
,ppenumMoniker
);
904 /* Does not support sub-monikers */
905 *ppenumMoniker
= NULL
;
909 /******************************************************************************
911 ******************************************************************************/
912 static HRESULT WINAPI
URLMonikerImpl_IsEqual(IMoniker
* iface
,IMoniker
* pmkOtherMoniker
)
914 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
920 TRACE("(%p,%p)\n",This
,pmkOtherMoniker
);
922 if(pmkOtherMoniker
==NULL
)
925 IMoniker_GetClassID(pmkOtherMoniker
,&clsid
);
927 if(!IsEqualCLSID(&clsid
,&CLSID_StdURLMoniker
))
930 res
= CreateBindCtx(0,&bind
);
935 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&urlPath
))) {
936 int result
= lstrcmpiW(urlPath
, This
->URLName
);
937 CoTaskMemFree(urlPath
);
941 IUnknown_Release(bind
);
946 /******************************************************************************
948 ******************************************************************************/
949 static HRESULT WINAPI
URLMonikerImpl_Hash(IMoniker
* iface
,DWORD
* pdwHash
)
951 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
953 int h
= 0,i
,skip
,len
;
957 TRACE("(%p,%p)\n",This
,pdwHash
);
966 for(i
= len
; i
> 0; i
--) {
967 h
= (h
* 37) + val
[off
++];
971 /* only sample some characters */
973 for(i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
974 h
= (h
* 39) + val
[off
];
981 /******************************************************************************
982 * URLMoniker_IsRunning
983 ******************************************************************************/
984 static HRESULT WINAPI
URLMonikerImpl_IsRunning(IMoniker
* iface
,
987 IMoniker
* pmkNewlyRunning
)
989 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
990 FIXME("(%p)->(%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pmkNewlyRunning
);
995 /******************************************************************************
996 * URLMoniker_GetTimeOfLastChange
997 ******************************************************************************/
998 static HRESULT WINAPI
URLMonikerImpl_GetTimeOfLastChange(IMoniker
* iface
,
1000 IMoniker
* pmkToLeft
,
1001 FILETIME
* pFileTime
)
1003 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1004 FIXME("(%p)->(%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pFileTime
);
1009 /******************************************************************************
1010 * URLMoniker_Inverse
1011 ******************************************************************************/
1012 static HRESULT WINAPI
URLMonikerImpl_Inverse(IMoniker
* iface
,IMoniker
** ppmk
)
1014 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1015 TRACE("(%p,%p)\n",This
,ppmk
);
1017 return MK_E_NOINVERSE
;
1020 /******************************************************************************
1021 * URLMoniker_CommonPrefixWith
1022 ******************************************************************************/
1023 static HRESULT WINAPI
URLMonikerImpl_CommonPrefixWith(IMoniker
* iface
,IMoniker
* pmkOther
,IMoniker
** ppmkPrefix
)
1025 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1026 FIXME("(%p)->(%p,%p): stub\n",This
,pmkOther
,ppmkPrefix
);
1031 /******************************************************************************
1032 * URLMoniker_RelativePathTo
1033 ******************************************************************************/
1034 static HRESULT WINAPI
URLMonikerImpl_RelativePathTo(IMoniker
* iface
,IMoniker
* pmOther
, IMoniker
** ppmkRelPath
)
1036 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1037 FIXME("(%p)->(%p,%p): stub\n",This
,pmOther
,ppmkRelPath
);
1042 /******************************************************************************
1043 * URLMoniker_GetDisplayName
1044 ******************************************************************************/
1045 static HRESULT WINAPI
URLMonikerImpl_GetDisplayName(IMoniker
* iface
,
1047 IMoniker
* pmkToLeft
,
1048 LPOLESTR
*ppszDisplayName
)
1050 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1054 TRACE("(%p,%p,%p,%p)\n",This
,pbc
,pmkToLeft
,ppszDisplayName
);
1056 if(!ppszDisplayName
)
1057 return E_INVALIDARG
;
1059 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
1060 then look at pmkToLeft to try and complete the URL
1062 len
= lstrlenW(This
->URLName
)+1;
1063 *ppszDisplayName
= CoTaskMemAlloc(len
*sizeof(WCHAR
));
1064 if(!*ppszDisplayName
)
1065 return E_OUTOFMEMORY
;
1066 lstrcpyW(*ppszDisplayName
, This
->URLName
);
1070 /******************************************************************************
1071 * URLMoniker_ParseDisplayName
1072 ******************************************************************************/
1073 static HRESULT WINAPI
URLMonikerImpl_ParseDisplayName(IMoniker
* iface
,
1075 IMoniker
* pmkToLeft
,
1076 LPOLESTR pszDisplayName
,
1080 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1081 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
1086 /******************************************************************************
1087 * URLMoniker_IsSystemMoniker
1088 ******************************************************************************/
1089 static HRESULT WINAPI
URLMonikerImpl_IsSystemMoniker(IMoniker
* iface
,DWORD
* pwdMksys
)
1091 URLMonikerImpl
*This
= (URLMonikerImpl
*)iface
;
1092 TRACE("(%p,%p)\n",This
,pwdMksys
);
1095 return E_INVALIDARG
;
1097 *pwdMksys
= MKSYS_URLMONIKER
;
1101 /********************************************************************************/
1102 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
1103 /* IPersistStream and IMoniker functions. */
1104 static const IMonikerVtbl VT_URLMonikerImpl
=
1106 URLMonikerImpl_QueryInterface
,
1107 URLMonikerImpl_AddRef
,
1108 URLMonikerImpl_Release
,
1109 URLMonikerImpl_GetClassID
,
1110 URLMonikerImpl_IsDirty
,
1111 URLMonikerImpl_Load
,
1112 URLMonikerImpl_Save
,
1113 URLMonikerImpl_GetSizeMax
,
1114 URLMonikerImpl_BindToObject
,
1115 URLMonikerImpl_BindToStorage
,
1116 URLMonikerImpl_Reduce
,
1117 URLMonikerImpl_ComposeWith
,
1118 URLMonikerImpl_Enum
,
1119 URLMonikerImpl_IsEqual
,
1120 URLMonikerImpl_Hash
,
1121 URLMonikerImpl_IsRunning
,
1122 URLMonikerImpl_GetTimeOfLastChange
,
1123 URLMonikerImpl_Inverse
,
1124 URLMonikerImpl_CommonPrefixWith
,
1125 URLMonikerImpl_RelativePathTo
,
1126 URLMonikerImpl_GetDisplayName
,
1127 URLMonikerImpl_ParseDisplayName
,
1128 URLMonikerImpl_IsSystemMoniker
1131 /******************************************************************************
1132 * URLMoniker_Construct (local function)
1133 *******************************************************************************/
1134 static HRESULT
URLMonikerImpl_Construct(URLMonikerImpl
* This
, LPCOLESTR lpszLeftURLName
, LPCOLESTR lpszURLName
)
1137 DWORD sizeStr
= INTERNET_MAX_URL_LENGTH
;
1139 TRACE("(%p,%s,%s)\n",This
,debugstr_w(lpszLeftURLName
),debugstr_w(lpszURLName
));
1140 memset(This
, 0, sizeof(*This
));
1142 /* Initialize the virtual function table. */
1143 This
->lpvtbl
= &VT_URLMonikerImpl
;
1146 if(lpszLeftURLName
) {
1147 hres
= UrlCombineW(lpszLeftURLName
, lpszURLName
, NULL
, &sizeStr
, 0);
1154 sizeStr
= lstrlenW(lpszURLName
)+1;
1156 This
->URLName
=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR
)*(sizeStr
));
1158 if (This
->URLName
==NULL
)
1159 return E_OUTOFMEMORY
;
1161 if(lpszLeftURLName
) {
1162 hres
= UrlCombineW(lpszLeftURLName
, lpszURLName
, This
->URLName
, &sizeStr
, 0);
1164 HeapFree(GetProcessHeap(), 0, This
->URLName
);
1169 strcpyW(This
->URLName
,lpszURLName
);
1171 URLMON_LockModule();
1176 /***********************************************************************
1177 * CreateAsyncBindCtx (URLMON.@)
1179 HRESULT WINAPI
CreateAsyncBindCtx(DWORD reserved
, IBindStatusCallback
*callback
,
1180 IEnumFORMATETC
*format
, IBindCtx
**pbind
)
1182 TRACE("(%08lx %p %p %p)\n", reserved
, callback
, format
, pbind
);
1185 return E_INVALIDARG
;
1187 return CreateAsyncBindCtxEx(NULL
, 0, callback
, format
, pbind
, 0);
1189 /***********************************************************************
1190 * CreateAsyncBindCtxEx (URLMON.@)
1192 * Create an asynchronous bind context.
1194 HRESULT WINAPI
CreateAsyncBindCtxEx(IBindCtx
*ibind
, DWORD options
,
1195 IBindStatusCallback
*callback
, IEnumFORMATETC
*format
, IBindCtx
** pbind
,
1202 TRACE("(%p %08lx %p %p %p %ld)\n", ibind
, options
, callback
, format
, pbind
, reserved
);
1205 return E_INVALIDARG
;
1208 FIXME("not supported options %08lx", options
);
1210 FIXME("format is not supported\n");
1213 WARN("reserved=%ld\n", reserved
);
1215 hres
= CreateBindCtx(0, &bctx
);
1219 bindopts
.cbStruct
= sizeof(BIND_OPTS
);
1220 bindopts
.grfFlags
= BIND_MAYBOTHERUSER
;
1221 bindopts
.grfMode
= STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
;
1222 bindopts
.dwTickCountDeadline
= 0;
1223 IBindCtx_SetBindOptions(bctx
, &bindopts
);
1226 RegisterBindStatusCallback(bctx
, callback
, NULL
, 0);
1234 /***********************************************************************
1235 * CreateURLMoniker (URLMON.@)
1237 * Create a url moniker.
1240 * pmkContext [I] Context
1241 * szURL [I] Url to create the moniker for
1242 * ppmk [O] Destination for created moniker.
1245 * Success: S_OK. ppmk contains the created IMoniker object.
1246 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1247 * E_OUTOFMEMORY if memory allocation fails.
1249 HRESULT WINAPI
CreateURLMoniker(IMoniker
*pmkContext
, LPCWSTR szURL
, IMoniker
**ppmk
)
1251 URLMonikerImpl
*obj
;
1253 IID iid
= IID_IMoniker
;
1254 LPOLESTR lefturl
= NULL
;
1256 TRACE("(%p, %s, %p)\n", pmkContext
, debugstr_w(szURL
), ppmk
);
1258 if(!(obj
= HeapAlloc(GetProcessHeap(), 0, sizeof(*obj
))))
1259 return E_OUTOFMEMORY
;
1264 IMoniker_IsSystemMoniker(pmkContext
, &dwMksys
);
1265 if(dwMksys
== MKSYS_URLMONIKER
&& SUCCEEDED(CreateBindCtx(0, &bind
))) {
1266 IMoniker_GetDisplayName(pmkContext
, bind
, NULL
, &lefturl
);
1267 TRACE("lefturl = %s\n", debugstr_w(lefturl
));
1268 IBindCtx_Release(bind
);
1272 hres
= URLMonikerImpl_Construct(obj
, lefturl
, szURL
);
1273 CoTaskMemFree(lefturl
);
1275 hres
= URLMonikerImpl_QueryInterface((IMoniker
*)obj
, &iid
, (void**)ppmk
);
1277 HeapFree(GetProcessHeap(), 0, obj
);
1282 /***********************************************************************
1283 * CoInternetGetSession (URLMON.@)
1285 * Create a new internet session and return an IInternetSession interface
1289 * dwSessionMode [I] Mode for the internet session
1290 * ppIInternetSession [O] Destination for creates IInternetSession object
1291 * dwReserved [I] Reserved, must be 0.
1294 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
1295 * Failure: E_INVALIDARG, if any argument is invalid, or
1296 * E_OUTOFMEMORY if memory allocation fails.
1298 HRESULT WINAPI
CoInternetGetSession(DWORD dwSessionMode
, IInternetSession
**ppIInternetSession
, DWORD dwReserved
)
1300 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode
, ppIInternetSession
, dwReserved
);
1303 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode
);
1307 ERR("dwReserved: %ld, must be zero\n", dwReserved
);
1310 *ppIInternetSession
=NULL
;
1311 return E_OUTOFMEMORY
;
1314 /***********************************************************************
1315 * CoInternetQueryInfo (URLMON.@)
1317 * Retrieves information relevant to a specified URL
1321 * S_FALSE buffer too small
1322 * INET_E_QUERYOPTIONUNKNOWN invalid option
1325 HRESULT WINAPI
CoInternetQueryInfo(LPCWSTR pwzUrl
, QUERYOPTION QueryOption
,
1326 DWORD dwQueryFlags
, LPVOID pvBuffer
, DWORD cbBuffer
, DWORD
* pcbBuffer
,
1329 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl
),
1330 QueryOption
, dwQueryFlags
, pvBuffer
, cbBuffer
, pcbBuffer
, dwReserved
);
1334 /***********************************************************************
1335 * IsAsyncMoniker (URLMON.@)
1337 HRESULT WINAPI
IsAsyncMoniker(IMoniker
*pmk
)
1341 TRACE("(%p)\n", pmk
);
1343 return E_INVALIDARG
;
1344 if(SUCCEEDED(IMoniker_QueryInterface(pmk
, &IID_IAsyncMoniker
, (void**)&am
))) {
1345 IUnknown_Release(am
);
1351 /***********************************************************************
1352 * RegisterBindStatusCallback (URLMON.@)
1354 * Register a bind status callback.
1357 * pbc [I] Binding context
1358 * pbsc [I] Callback to register
1359 * ppbscPrevious [O] Destination for previous callback
1360 * dwReserved [I] Reserved, must be 0.
1364 * Failure: E_INVALIDARG, if any argument is invalid, or
1365 * E_OUTOFMEMORY if memory allocation fails.
1367 HRESULT WINAPI
RegisterBindStatusCallback(
1369 IBindStatusCallback
*pbsc
,
1370 IBindStatusCallback
**ppbscPrevious
,
1373 IBindStatusCallback
*prev
;
1375 TRACE("(%p,%p,%p,%lu)\n", pbc
, pbsc
, ppbscPrevious
, dwReserved
);
1377 if (pbc
== NULL
|| pbsc
== NULL
)
1378 return E_INVALIDARG
;
1380 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
**)&prev
)))
1382 IBindCtx_RevokeObjectParam(pbc
, (LPOLESTR
)BSCBHolder
);
1384 *ppbscPrevious
= prev
;
1386 IBindStatusCallback_Release(prev
);
1389 return IBindCtx_RegisterObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
*)pbsc
);
1392 /***********************************************************************
1393 * RevokeBindStatusCallback (URLMON.@)
1395 * Unregister a bind status callback.
1397 * pbc [I] Binding context
1398 * pbsc [I] Callback to unregister
1402 * Failure: E_INVALIDARG, if any argument is invalid, or
1403 * E_FAIL if pbsc wasn't registered with pbc.
1405 HRESULT WINAPI
RevokeBindStatusCallback(
1407 IBindStatusCallback
*pbsc
)
1409 IBindStatusCallback
*callback
;
1410 HRESULT hr
= E_FAIL
;
1412 TRACE("(%p,%p)\n", pbc
, pbsc
);
1414 if (pbc
== NULL
|| pbsc
== NULL
)
1415 return E_INVALIDARG
;
1417 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc
, (LPOLESTR
)BSCBHolder
, (IUnknown
**)&callback
)))
1419 if (callback
== pbsc
)
1421 IBindCtx_RevokeObjectParam(pbc
, (LPOLESTR
)BSCBHolder
);
1424 IBindStatusCallback_Release(pbsc
);
1430 /***********************************************************************
1431 * URLDownloadToFileA (URLMON.@)
1433 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1437 * pCaller [I] controlling IUnknown interface.
1438 * szURL [I] URL of the file to download
1439 * szFileName [I] file name to store the content of the URL
1440 * dwReserved [I] reserved - set to 0
1441 * lpfnCB [I] callback for progress report
1445 * E_OUTOFMEMORY when going out of memory
1447 HRESULT WINAPI
URLDownloadToFileA(LPUNKNOWN pCaller
,
1451 LPBINDSTATUSCALLBACK lpfnCB
)
1453 UNICODE_STRING szURL_w
, szFileName_w
;
1455 if ((szURL
== NULL
) || (szFileName
== NULL
)) {
1456 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller
, debugstr_a(szURL
), debugstr_a(szFileName
), dwReserved
, lpfnCB
);
1457 return E_INVALIDARG
; /* The error code is not specified in this case... */
1460 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w
, szURL
)) {
1461 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w
, szFileName
)) {
1462 HRESULT ret
= URLDownloadToFileW(pCaller
, szURL_w
.Buffer
, szFileName_w
.Buffer
, dwReserved
, lpfnCB
);
1464 RtlFreeUnicodeString(&szURL_w
);
1465 RtlFreeUnicodeString(&szFileName_w
);
1469 RtlFreeUnicodeString(&szURL_w
);
1473 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller
, szURL
, szFileName
, dwReserved
, lpfnCB
);
1474 return E_OUTOFMEMORY
;
1477 /***********************************************************************
1478 * URLDownloadToFileW (URLMON.@)
1480 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1484 * pCaller [I] controlling IUnknown interface.
1485 * szURL [I] URL of the file to download
1486 * szFileName [I] file name to store the content of the URL
1487 * dwReserved [I] reserved - set to 0
1488 * lpfnCB [I] callback for progress report
1492 * E_OUTOFMEMORY when going out of memory
1494 HRESULT WINAPI
URLDownloadToFileW(LPUNKNOWN pCaller
,
1498 LPBINDSTATUSCALLBACK lpfnCB
)
1500 HINTERNET hinternet
, hcon
, hreq
;
1502 CHAR buffer
[0x1000];
1503 DWORD sz
, total
, written
;
1504 DWORD total_size
= 0xFFFFFFFF, arg_size
= sizeof(total_size
);
1505 URL_COMPONENTSW url
;
1506 WCHAR host
[0x80], path
[0x100];
1508 static const WCHAR wszAppName
[]={'u','r','l','m','o','n','.','d','l','l',0};
1510 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1511 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller
, debugstr_w(szURL
), debugstr_w(szFileName
), dwReserved
, lpfnCB
);
1513 if ((szURL
== NULL
) || (szFileName
== NULL
)) {
1514 FIXME(" cannot accept NULL strings !\n");
1515 return E_INVALIDARG
;
1518 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1519 hinternet
= InternetOpenW(wszAppName
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1520 if (hinternet
== NULL
) {
1521 return E_OUTOFMEMORY
;
1524 memset(&url
, 0, sizeof(url
));
1525 url
.dwStructSize
= sizeof(url
);
1526 url
.lpszHostName
= host
;
1527 url
.dwHostNameLength
= sizeof(host
);
1528 url
.lpszUrlPath
= path
;
1529 url
.dwUrlPathLength
= sizeof(path
);
1531 if (!InternetCrackUrlW(szURL
, 0, 0, &url
)) {
1532 InternetCloseHandle(hinternet
);
1533 return E_OUTOFMEMORY
;
1537 if (IBindStatusCallback_OnProgress(lpfnCB
, 0, 0, BINDSTATUS_CONNECTING
, url
.lpszHostName
) == E_ABORT
) {
1538 InternetCloseHandle(hinternet
);
1543 hcon
= InternetConnectW(hinternet
, url
.lpszHostName
, url
.nPort
,
1544 url
.lpszUserName
, url
.lpszPassword
,
1545 INTERNET_SERVICE_HTTP
, 0, 0);
1547 InternetCloseHandle(hinternet
);
1548 return E_OUTOFMEMORY
;
1551 hreq
= HttpOpenRequestW(hcon
, NULL
, url
.lpszUrlPath
, NULL
, NULL
, NULL
, 0, 0);
1553 InternetCloseHandle(hinternet
);
1554 InternetCloseHandle(hcon
);
1555 return E_OUTOFMEMORY
;
1558 if (!HttpSendRequestW(hreq
, NULL
, 0, NULL
, 0)) {
1559 InternetCloseHandle(hinternet
);
1560 InternetCloseHandle(hcon
);
1561 InternetCloseHandle(hreq
);
1562 return E_OUTOFMEMORY
;
1565 if (HttpQueryInfoW(hreq
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
,
1566 &total_size
, &arg_size
, NULL
)) {
1567 TRACE(" total size : %ld\n", total_size
);
1570 hfile
= CreateFileW(szFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1571 FILE_ATTRIBUTE_NORMAL
, NULL
);
1572 if (hfile
== INVALID_HANDLE_VALUE
) {
1573 return E_ACCESSDENIED
;
1577 if (IBindStatusCallback_OnProgress(lpfnCB
, 0, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1578 BINDSTATUS_BEGINDOWNLOADDATA
, szURL
) == E_ABORT
) {
1579 InternetCloseHandle(hreq
);
1580 InternetCloseHandle(hcon
);
1581 InternetCloseHandle(hinternet
);
1589 r
= InternetReadFile(hreq
, buffer
, sizeof(buffer
), &sz
);
1591 InternetCloseHandle(hreq
);
1592 InternetCloseHandle(hcon
);
1593 InternetCloseHandle(hinternet
);
1596 return E_OUTOFMEMORY
;
1604 if (IBindStatusCallback_OnProgress(lpfnCB
, total
, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1605 BINDSTATUS_DOWNLOADINGDATA
, szURL
) == E_ABORT
) {
1606 InternetCloseHandle(hreq
);
1607 InternetCloseHandle(hcon
);
1608 InternetCloseHandle(hinternet
);
1614 if (!WriteFile(hfile
, buffer
, sz
, &written
, NULL
)) {
1615 InternetCloseHandle(hreq
);
1616 InternetCloseHandle(hcon
);
1617 InternetCloseHandle(hinternet
);
1620 return E_OUTOFMEMORY
;
1625 if (IBindStatusCallback_OnProgress(lpfnCB
, total
, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1626 BINDSTATUS_ENDDOWNLOADDATA
, szURL
) == E_ABORT
) {
1627 InternetCloseHandle(hreq
);
1628 InternetCloseHandle(hcon
);
1629 InternetCloseHandle(hinternet
);
1635 InternetCloseHandle(hreq
);
1636 InternetCloseHandle(hcon
);
1637 InternetCloseHandle(hinternet
);
1644 /***********************************************************************
1645 * HlinkSimpleNavigateToString (URLMON.@)
1647 HRESULT WINAPI
HlinkSimpleNavigateToString( LPCWSTR szTarget
,
1648 LPCWSTR szLocation
, LPCWSTR szTargetFrameName
, IUnknown
*pUnk
,
1649 IBindCtx
*pbc
, IBindStatusCallback
*pbsc
, DWORD grfHLNF
, DWORD dwReserved
)
1651 FIXME("%s\n", debugstr_w( szTarget
) );
1655 /***********************************************************************
1656 * HlinkNavigateString (URLMON.@)
1658 HRESULT WINAPI
HlinkNavigateString( IUnknown
*pUnk
, LPCWSTR szTarget
)
1660 TRACE("%p %s\n", pUnk
, debugstr_w( szTarget
) );
1661 return HlinkSimpleNavigateToString(
1662 szTarget
, NULL
, NULL
, pUnk
, NULL
, NULL
, 0, 0 );
1665 /***********************************************************************
1666 * GetSoftwareUpdateInfo (URLMON.@)
1668 HRESULT WINAPI
GetSoftwareUpdateInfo( LPCWSTR szDistUnit
, LPSOFTDISTINFO psdi
)
1670 FIXME("%s %p\n", debugstr_w(szDistUnit
), psdi
);