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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
40 #include "urlmon_main.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
44 /* native urlmon.dll uses this key, too */
45 static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
47 /*static BOOL registered_wndclass = FALSE;*/
49 /* filemoniker data structure */
50 typedef struct URLMonikerImpl{
52 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
53 ICOM_VTABLE(IBinding)* lpvtbl2; /* VTable to IBinding interface */
55 ULONG ref; /* reference counter for this object */
57 LPOLESTR URLName; /* URL string identified by this URLmoniker */
61 HINTERNET hinternet, hconnect, hrequest;
64 /********************************************************************************/
65 /* URLMoniker prototype functions : */
67 /* IUnknown prototype functions */
68 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
69 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface);
70 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface);
72 /* IPersist prototype functions */
73 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
75 /* IPersistStream prototype functions */
76 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface);
77 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface, IStream* pStm);
78 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
79 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
81 /* IMoniker prototype functions */
82 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
83 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
84 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
85 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
86 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
87 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
88 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
89 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
90 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
91 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
92 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
93 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
94 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
95 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
96 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
98 /* IBinding interface to moniker */
99 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject);
100 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface);
101 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface);
102 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface);
103 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface);
104 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface);
105 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority);
106 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority);
107 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved);
109 /* Local function used by urlmoniker implementation */
110 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszLeftURL, LPCOLESTR lpszURL);
111 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface);
113 /********************************************************************************/
114 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
115 /* IPersistStream and IMoniker functions. */
116 static ICOM_VTABLE(IMoniker) VT_URLMonikerImpl =
118 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
119 URLMonikerImpl_QueryInterface,
120 URLMonikerImpl_AddRef,
121 URLMonikerImpl_Release,
122 URLMonikerImpl_GetClassID,
123 URLMonikerImpl_IsDirty,
126 URLMonikerImpl_GetSizeMax,
127 URLMonikerImpl_BindToObject,
128 URLMonikerImpl_BindToStorage,
129 URLMonikerImpl_Reduce,
130 URLMonikerImpl_ComposeWith,
132 URLMonikerImpl_IsEqual,
134 URLMonikerImpl_IsRunning,
135 URLMonikerImpl_GetTimeOfLastChange,
136 URLMonikerImpl_Inverse,
137 URLMonikerImpl_CommonPrefixWith,
138 URLMonikerImpl_RelativePathTo,
139 URLMonikerImpl_GetDisplayName,
140 URLMonikerImpl_ParseDisplayName,
141 URLMonikerImpl_IsSystemMoniker
144 static ICOM_VTABLE(IBinding) VTBinding_URLMonikerImpl =
146 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
147 URLMonikerImpl_IBinding_QueryInterface,
148 URLMonikerImpl_IBinding_AddRef,
149 URLMonikerImpl_IBinding_Release,
150 URLMonikerImpl_IBinding_Abort,
151 URLMonikerImpl_IBinding_Suspend,
152 URLMonikerImpl_IBinding_Resume,
153 URLMonikerImpl_IBinding_SetPriority,
154 URLMonikerImpl_IBinding_GetPriority,
155 URLMonikerImpl_IBinding_GetBindResult
159 /*******************************************************************************
160 * URLMoniker_QueryInterface
161 *******************************************************************************/
162 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
164 ICOM_THIS(URLMonikerImpl,iface);
166 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
168 /* Perform a sanity check on the parameters.*/
169 if ( (This==0) || (ppvObject==0) )
172 /* Initialize the return parameter */
175 /* Compare the riid with the interface IDs implemented by this object.*/
176 if (IsEqualIID(&IID_IUnknown, riid) ||
177 IsEqualIID(&IID_IPersist, riid) ||
178 IsEqualIID(&IID_IPersistStream,riid) ||
179 IsEqualIID(&IID_IMoniker, riid)
183 /* Check that we obtained an interface.*/
185 return E_NOINTERFACE;
187 /* Query Interface always increases the reference count by one when it is successful */
188 URLMonikerImpl_AddRef(iface);
193 /******************************************************************************
195 ******************************************************************************/
196 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
198 ICOM_THIS(URLMonikerImpl,iface);
200 TRACE("(%p)\n",This);
202 return ++(This->ref);
205 /******************************************************************************
207 ******************************************************************************/
208 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
210 ICOM_THIS(URLMonikerImpl,iface);
212 TRACE("(%p)\n",This);
216 /* destroy the object if there's no more reference on it */
219 URLMonikerImpl_Destroy(This);
226 /******************************************************************************
227 * URLMoniker_GetClassID
228 ******************************************************************************/
229 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
230 CLSID *pClassID)/* Pointer to CLSID of object */
232 ICOM_THIS(URLMonikerImpl,iface);
234 TRACE("(%p,%p)\n",This,pClassID);
238 /* Windows always returns CLSID_StdURLMoniker */
239 *pClassID = CLSID_StdURLMoniker;
243 /******************************************************************************
245 ******************************************************************************/
246 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
248 ICOM_THIS(URLMonikerImpl,iface);
249 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
250 method in the OLE-provided moniker interfaces always return S_FALSE because
251 their internal state never changes. */
253 TRACE("(%p)\n",This);
258 /******************************************************************************
262 * Writes a ULONG containing length of unicode string, followed
263 * by that many unicode characters
264 ******************************************************************************/
265 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
267 ICOM_THIS(URLMonikerImpl,iface);
272 TRACE("(%p,%p)\n",This,pStm);
277 res = IStream_Read(pStm, &len, sizeof(ULONG), &got);
279 if(got == sizeof(ULONG)) {
281 HeapFree(GetProcessHeap(), 0, This->URLName);
282 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(len+1));
286 res = IStream_Read(pStm, This->URLName, len, NULL);
287 This->URLName[len] = 0;
296 /******************************************************************************
298 ******************************************************************************/
299 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
300 IStream* pStm,/* pointer to the stream where the object is to be saved */
301 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
303 ICOM_THIS(URLMonikerImpl,iface);
307 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
312 len = strlenW(This->URLName);
313 res=IStream_Write(pStm,&len,sizeof(ULONG),NULL);
315 res=IStream_Write(pStm,&This->URLName,len*sizeof(WCHAR),NULL);
320 /******************************************************************************
321 * URLMoniker_GetSizeMax
322 ******************************************************************************/
323 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
324 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
326 ICOM_THIS(URLMonikerImpl,iface);
328 TRACE("(%p,%p)\n",This,pcbSize);
333 pcbSize->u.LowPart = sizeof(ULONG) + (strlenW(This->URLName) * sizeof(WCHAR));
334 pcbSize->u.HighPart = 0;
338 /******************************************************************************
339 * URLMoniker_Construct (local function)
340 *******************************************************************************/
341 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
346 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
347 memset(This, 0, sizeof(*This));
349 /* Initialize the virtual function table. */
350 This->lpvtbl1 = &VT_URLMonikerImpl;
351 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
354 if(lpszLeftURLName) {
355 hres = UrlCombineW(lpszLeftURLName, lpszURLName, NULL, &sizeStr, 0);
362 sizeStr = lstrlenW(lpszURLName)+1;
364 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr));
366 if (This->URLName==NULL)
367 return E_OUTOFMEMORY;
369 if(lpszLeftURLName) {
370 hres = UrlCombineW(lpszLeftURLName, lpszURLName, This->URLName, &sizeStr, 0);
372 HeapFree(GetProcessHeap(), 0, This->URLName);
377 strcpyW(This->URLName,lpszURLName);
384 /******************************************************************************
385 * URLMoniker_Destroy (local function)
386 *******************************************************************************/
387 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
389 TRACE("(%p)\n",This);
391 if (This->URLName!=NULL)
392 HeapFree(GetProcessHeap(),0,This->URLName);
394 HeapFree(GetProcessHeap(),0,This);
399 /******************************************************************************
400 * URLMoniker_BindToObject
401 ******************************************************************************/
402 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
408 ICOM_THIS(URLMonikerImpl,iface);
412 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
419 enum {OnProgress, OnDataAvailable} callback;
420 } URLMON_CallbackData;
424 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
426 return DefWindowProcA(hwnd, msg, wparam, lparam);
429 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
433 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
434 void *status_info, DWORD status_info_len)
436 URLMonikerImpl *This = (URLMonikerImpl *)context;
437 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
439 if(This->filesize == -1) {
441 case INTERNET_STATUS_RESOLVING_NAME:
442 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
444 case INTERNET_STATUS_CONNECTING_TO_SERVER:
445 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
447 case INTERNET_STATUS_SENDING_REQUEST:
448 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
450 case INTERNET_REQUEST_COMPLETE:
452 DWORD len, lensz = sizeof(len);
454 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
455 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
456 This->filesize = len;
465 /******************************************************************************
466 * URLMoniker_BindToStorage
467 ******************************************************************************/
468 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
474 ICOM_THIS(URLMonikerImpl,iface);
476 IBindStatusCallback *pbscb;
480 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
482 FIXME("pmkToLeft != NULL\n");
485 if(!IsEqualIID(&IID_IStream, riid)) {
486 FIXME("unsupported iid\n");
490 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
491 We also need to implement IStream ourselves so that IStream_Read can return
494 hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
497 if(SUCCEEDED(hres)) {
498 TRACE("Created dummy stream...\n");
500 hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&pbscb);
501 if(SUCCEEDED(hres)) {
502 TRACE("Got IBindStatusCallback...\n");
504 memset(&bi, 0, sizeof(bi));
505 bi.cbSize = sizeof(bi);
507 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
508 if(SUCCEEDED(hres)) {
511 DWORD len, lensz = sizeof(len), total_read = 0;
512 LARGE_INTEGER last_read_pos;
516 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
517 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
518 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
519 TRACE("OnStartBinding rets %08lx\n", hres);
522 if(!registered_wndclass) {
523 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
524 RegisterClassA(&urlmon_wndclass);
525 registered_wndclass = TRUE;
528 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
529 URLMON_hInstance, NULL);
532 memset(&url, 0, sizeof(url));
533 url.dwStructSize = sizeof(url);
534 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
535 InternetCrackUrlW(This->URLName, 0, 0, &url);
536 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
537 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
538 host[url.dwHostNameLength] = '\0';
539 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
540 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
541 path[url.dwUrlPathLength] = '\0';
543 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
544 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
546 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
547 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
548 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
550 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
551 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
552 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
553 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
554 hres = E_OUTOFMEMORY; /* FIXME */
555 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
558 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
560 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
562 last_read_pos.u.LowPart = last_read_pos.u.HighPart = 0;
567 fmt.tymed = TYMED_ISTREAM;
568 stg.tymed = TYMED_ISTREAM;
569 stg.u.pstm = *(IStream**)ppvObject;
570 stg.pUnkForRelease = NULL;
576 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
577 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
578 if(bufread == 0) break;
579 IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
580 total_read += bufread;
581 IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
582 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
583 BINDSTATUS_BEGINDOWNLOADDATA :
584 BINDSTATUS_DOWNLOADINGDATA, NULL);
585 hres = IBindStatusCallback_OnDataAvailable(pbscb,
586 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
587 BSCF_INTERMEDIATEDATANOTIFICATION,
588 total_read, &fmt, &stg);
589 last_read_pos.u.LowPart += bufread; /* FIXME */
593 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
594 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
595 TRACE("OnDataAvail rets %08lx\n", hres);
596 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
597 TRACE("OnStop rets %08lx\n", hres);
600 InternetCloseHandle(This->hrequest);
601 InternetCloseHandle(This->hconnect);
602 InternetCloseHandle(This->hinternet);
609 /******************************************************************************
611 ******************************************************************************/
612 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
614 DWORD dwReduceHowFar,
615 IMoniker** ppmkToLeft,
616 IMoniker** ppmkReduced)
618 ICOM_THIS(URLMonikerImpl,iface);
620 TRACE("(%p,%p,%ld,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
625 URLMonikerImpl_AddRef(iface);
626 *ppmkReduced = iface;
627 return MK_S_REDUCED_TO_SELF;
630 /******************************************************************************
631 * URLMoniker_ComposeWith
632 ******************************************************************************/
633 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
635 BOOL fOnlyIfNotGeneric,
636 IMoniker** ppmkComposite)
638 ICOM_THIS(URLMonikerImpl,iface);
639 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
644 /******************************************************************************
646 ******************************************************************************/
647 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
649 ICOM_THIS(URLMonikerImpl,iface);
650 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
655 /* Does not support sub-monikers */
656 *ppenumMoniker = NULL;
660 /******************************************************************************
662 ******************************************************************************/
663 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
665 ICOM_THIS(URLMonikerImpl,iface);
671 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
673 if(pmkOtherMoniker==NULL)
676 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
678 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
681 res = CreateBindCtx(0,&bind);
686 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
687 int result = lstrcmpiW(urlPath, This->URLName);
688 CoTaskMemFree(urlPath);
692 IUnknown_Release(bind);
697 /******************************************************************************
699 ******************************************************************************/
700 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
702 ICOM_THIS(URLMonikerImpl,iface);
704 int h = 0,i,skip,len;
708 TRACE("(%p,%p)\n",This,pdwHash);
717 for(i = len ; i > 0; i--) {
718 h = (h * 37) + val[off++];
722 /* only sample some characters */
724 for(i = len; i > 0; i -= skip, off += skip) {
725 h = (h * 39) + val[off];
732 /******************************************************************************
733 * URLMoniker_IsRunning
734 ******************************************************************************/
735 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
738 IMoniker* pmkNewlyRunning)
740 ICOM_THIS(URLMonikerImpl,iface);
741 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
746 /******************************************************************************
747 * URLMoniker_GetTimeOfLastChange
748 ******************************************************************************/
749 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
754 ICOM_THIS(URLMonikerImpl,iface);
755 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
760 /******************************************************************************
762 ******************************************************************************/
763 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
765 ICOM_THIS(URLMonikerImpl,iface);
766 TRACE("(%p,%p)\n",This,ppmk);
768 return MK_E_NOINVERSE;
771 /******************************************************************************
772 * URLMoniker_CommonPrefixWith
773 ******************************************************************************/
774 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
776 ICOM_THIS(URLMonikerImpl,iface);
777 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
782 /******************************************************************************
783 * URLMoniker_RelativePathTo
784 ******************************************************************************/
785 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
787 ICOM_THIS(URLMonikerImpl,iface);
788 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
793 /******************************************************************************
794 * URLMoniker_GetDisplayName
795 ******************************************************************************/
796 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
799 LPOLESTR *ppszDisplayName)
801 ICOM_THIS(URLMonikerImpl,iface);
805 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
810 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
811 then look at pmkToLeft to try and complete the URL
813 len = lstrlenW(This->URLName)+1;
814 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
815 if(!*ppszDisplayName)
816 return E_OUTOFMEMORY;
817 lstrcpyW(*ppszDisplayName, This->URLName);
821 /******************************************************************************
822 * URLMoniker_ParseDisplayName
823 ******************************************************************************/
824 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
827 LPOLESTR pszDisplayName,
831 ICOM_THIS(URLMonikerImpl,iface);
832 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
837 /******************************************************************************
838 * URLMoniker_IsSystemMoniker
839 ******************************************************************************/
840 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
842 ICOM_THIS(URLMonikerImpl,iface);
843 TRACE("(%p,%p)\n",This,pwdMksys);
848 *pwdMksys = MKSYS_URLMONIKER;
852 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
854 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
856 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
858 /* Perform a sanity check on the parameters.*/
859 if ( (This==0) || (ppvObject==0) )
862 /* Initialize the return parameter */
865 /* Compare the riid with the interface IDs implemented by this object.*/
866 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
869 /* Check that we obtained an interface.*/
871 return E_NOINTERFACE;
873 /* Query Interface always increases the reference count by one when it is successful */
874 URLMonikerImpl_IBinding_AddRef(iface);
880 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
882 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
883 TRACE("(%p)\n",This);
885 return URLMonikerImpl_AddRef((IMoniker*)This);
888 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
890 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
891 TRACE("(%p)\n",This);
893 return URLMonikerImpl_Release((IMoniker*)This);
896 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
898 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
899 FIXME("(%p): stub\n", This);
904 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
906 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
907 FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
912 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
914 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
915 FIXME("(%p)->(%p): stub\n", This, pnPriority);
920 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
922 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
923 FIXME("(%p): stub\n", This);
928 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
930 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
931 FIXME("(%p)->(%ld): stub\n", This, nPriority);
936 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
938 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
939 FIXME("(%p): stub\n", This);
944 /***********************************************************************
945 * CreateAsyncBindCtx (URLMON.@)
947 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
948 IEnumFORMATETC *format, IBindCtx **pbind)
953 /***********************************************************************
954 * CreateAsyncBindCtxEx (URLMON.@)
956 * Create an asynchronous bind context.
961 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
962 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
965 FIXME("stub, returns failure\n");
970 /***********************************************************************
971 * CreateURLMoniker (URLMON.@)
973 * Create a url moniker.
976 * pmkContext [I] Context
977 * szURL [I] Url to create the moniker for
978 * ppmk [O] Destination for created moniker.
981 * Success: S_OK. ppmk contains the created IMoniker object.
982 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
983 * E_OUTOFMEMORY if memory allocation fails.
985 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
989 IID iid = IID_IMoniker;
990 LPOLESTR lefturl = NULL;
992 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
994 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
995 return E_OUTOFMEMORY;
1000 IMoniker_GetClassID(pmkContext, &clsid);
1001 if(IsEqualCLSID(&clsid, &CLSID_StdURLMoniker) && SUCCEEDED(CreateBindCtx(0, &bind))) {
1002 URLMonikerImpl_GetDisplayName(pmkContext, bind, NULL, &lefturl);
1003 IBindCtx_Release(bind);
1007 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
1008 CoTaskMemFree(lefturl);
1010 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
1012 HeapFree(GetProcessHeap(), 0, obj);
1017 /***********************************************************************
1018 * CoInternetGetSession (URLMON.@)
1020 * Create a new internet session and return an IInternetSession interface
1024 * dwSessionMode [I] Mode for the internet session
1025 * ppIInternetSession [O] Destination for creates IInternetSession object
1026 * dwReserved [I] Reserved, must be 0.
1029 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
1030 * Failure: E_INVALIDARG, if any argument is invalid, or
1031 * E_OUTOFMEMORY if memory allocation fails.
1033 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, /*IInternetSession*/void **ppIInternetSession, DWORD dwReserved)
1035 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
1038 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
1042 ERR("dwReserved: %ld, must be zero\n", dwReserved);
1045 *ppIInternetSession=NULL;
1046 return E_OUTOFMEMORY;
1049 /***********************************************************************
1050 * CoInternetQueryInfo (URLMON.@)
1052 * Retrieves information relevant to a specified URL
1056 * S_FALSE buffer too small
1057 * INET_E_QUERYOPTIONUNKNOWN invalid option
1060 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1061 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1064 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
1065 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1069 static BOOL URLMON_IsBinary(LPVOID pBuffer, DWORD cbSize)
1071 int binarycount = 0;
1073 unsigned char *buff = pBuffer;
1074 for(i=0; i<cbSize; i++) {
1078 return binarycount > (cbSize-binarycount);
1081 /***********************************************************************
1082 * FindMimeFromData (URLMON.@)
1084 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
1087 * See http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
1089 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
1090 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
1091 LPWSTR* ppwzMimeOut, DWORD dwReserved)
1093 static const WCHAR szBinaryMime[] = {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m','\0'};
1094 static const WCHAR szTextMime[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
1095 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
1096 WCHAR szTmpMime[256];
1097 LPCWSTR mimeType = NULL;
1100 TRACE("(%p,%s,%p,%ld,%s,0x%lx,%p,0x%lx)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
1101 debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
1103 if((!pwzUrl && (!pBuffer || cbSize <= 0)) || !ppwzMimeOut)
1104 return E_INVALIDARG;
1107 mimeType = pwzMimeProposed;
1109 /* Try and find the mime type in the registry */
1111 LPWSTR ext = strrchrW(pwzUrl, '.');
1114 if(!RegOpenKeyExW(HKEY_CLASSES_ROOT, ext, 0, 0, &hKey)) {
1115 if(!RegQueryValueExW(hKey, szContentType, NULL, NULL, (LPBYTE)szTmpMime, &dwSize)) {
1116 mimeType = szTmpMime;
1123 if(!mimeType && pBuffer && cbSize > 0)
1124 mimeType = URLMON_IsBinary(pBuffer, cbSize)?szBinaryMime:szTextMime;
1126 TRACE("Using %s\n", debugstr_w(mimeType));
1127 *ppwzMimeOut = CoTaskMemAlloc((lstrlenW(mimeType)+1)*sizeof(WCHAR));
1128 if(!*ppwzMimeOut) return E_OUTOFMEMORY;
1129 lstrcpyW(*ppwzMimeOut, mimeType);
1133 /***********************************************************************
1134 * IsAsyncMoniker (URLMON.@)
1136 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1140 TRACE("(%p)\n", pmk);
1142 return E_INVALIDARG;
1143 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1144 IUnknown_Release(am);
1150 /***********************************************************************
1151 * RegisterBindStatusCallback (URLMON.@)
1153 * Register a bind status callback.
1156 * pbc [I] Binding context
1157 * pbsc [I] Callback to register
1158 * ppbscPrevious [O] Destination for previous callback
1159 * dwReserved [I] Reserved, must be 0.
1163 * Failure: E_INVALIDARG, if any argument is invalid, or
1164 * E_OUTOFMEMORY if memory allocation fails.
1166 HRESULT WINAPI RegisterBindStatusCallback(
1168 IBindStatusCallback *pbsc,
1169 IBindStatusCallback **ppbscPrevious,
1172 IBindStatusCallback *prev;
1174 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
1176 if (pbc == NULL || pbsc == NULL)
1177 return E_INVALIDARG;
1179 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
1181 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1183 *ppbscPrevious = prev;
1185 IBindStatusCallback_Release(prev);
1188 return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
1191 /***********************************************************************
1192 * RevokeBindStatusCallback (URLMON.@)
1194 * Unregister a bind status callback.
1196 * pbc [I] Binding context
1197 * pbsc [I] Callback to unregister
1201 * Failure: E_INVALIDARG, if any argument is invalid, or
1202 * E_FAIL if pbsc wasn't registered with pbc.
1204 HRESULT WINAPI RevokeBindStatusCallback(
1206 IBindStatusCallback *pbsc)
1208 IBindStatusCallback *callback;
1209 HRESULT hr = E_FAIL;
1211 TRACE("(%p,%p)\n", pbc, pbsc);
1213 if (pbc == NULL || pbsc == NULL)
1214 return E_INVALIDARG;
1216 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
1218 if (callback == pbsc)
1220 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1223 IBindStatusCallback_Release(pbsc);
1229 /***********************************************************************
1230 * ReleaseBindInfo (URLMON.@)
1232 * Release the resources used by the specified BINDINFO structure.
1235 * pbindinfo [I] BINDINFO to release.
1240 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1242 FIXME("(%p)stub!\n", pbindinfo);
1245 /***********************************************************************
1246 * URLDownloadToFileA (URLMON.@)
1248 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1252 * pCaller [I] controlling IUnknown interface.
1253 * szURL [I] URL of the file to download
1254 * szFileName [I] file name to store the content of the URL
1255 * dwReserved [I] reserved - set to 0
1256 * lpfnCB [I] callback for progress report
1260 * E_OUTOFMEMORY when going out of memory
1262 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1266 LPBINDSTATUSCALLBACK lpfnCB)
1268 UNICODE_STRING szURL_w, szFileName_w;
1270 if ((szURL == NULL) || (szFileName == NULL)) {
1271 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1272 return E_INVALIDARG; /* The error code is not specified in this case... */
1275 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1276 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1277 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1279 RtlFreeUnicodeString(&szURL_w);
1280 RtlFreeUnicodeString(&szFileName_w);
1284 RtlFreeUnicodeString(&szURL_w);
1288 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1289 return E_OUTOFMEMORY;
1292 /***********************************************************************
1293 * URLDownloadToFileW (URLMON.@)
1295 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1299 * pCaller [I] controlling IUnknown interface.
1300 * szURL [I] URL of the file to download
1301 * szFileName [I] file name to store the content of the URL
1302 * dwReserved [I] reserved - set to 0
1303 * lpfnCB [I] callback for progress report
1307 * E_OUTOFMEMORY when going out of memory
1309 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1313 LPBINDSTATUSCALLBACK lpfnCB)
1315 HINTERNET hinternet, hcon, hreq;
1317 CHAR buffer[0x1000];
1318 DWORD sz, total, written;
1319 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1320 URL_COMPONENTSW url;
1321 WCHAR host[0x80], path[0x100];
1323 static const WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1325 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1326 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1328 if ((szURL == NULL) || (szFileName == NULL)) {
1329 FIXME(" cannot accept NULL strings !\n");
1330 return E_INVALIDARG;
1333 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1334 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1335 if (hinternet == NULL) {
1336 return E_OUTOFMEMORY;
1339 memset(&url, 0, sizeof(url));
1340 url.dwStructSize = sizeof(url);
1341 url.lpszHostName = host;
1342 url.dwHostNameLength = sizeof(host);
1343 url.lpszUrlPath = path;
1344 url.dwUrlPathLength = sizeof(path);
1346 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1347 InternetCloseHandle(hinternet);
1348 return E_OUTOFMEMORY;
1352 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1353 InternetCloseHandle(hinternet);
1358 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1359 url.lpszUserName, url.lpszPassword,
1360 INTERNET_SERVICE_HTTP, 0, 0);
1362 InternetCloseHandle(hinternet);
1363 return E_OUTOFMEMORY;
1366 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1368 InternetCloseHandle(hinternet);
1369 InternetCloseHandle(hcon);
1370 return E_OUTOFMEMORY;
1373 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1374 InternetCloseHandle(hinternet);
1375 InternetCloseHandle(hcon);
1376 InternetCloseHandle(hreq);
1377 return E_OUTOFMEMORY;
1380 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1381 &total_size, &arg_size, NULL)) {
1382 TRACE(" total size : %ld\n", total_size);
1385 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1386 FILE_ATTRIBUTE_NORMAL, NULL );
1387 if (hfile == INVALID_HANDLE_VALUE) {
1388 return E_ACCESSDENIED;
1392 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1393 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1394 InternetCloseHandle(hreq);
1395 InternetCloseHandle(hcon);
1396 InternetCloseHandle(hinternet);
1404 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1406 InternetCloseHandle(hreq);
1407 InternetCloseHandle(hcon);
1408 InternetCloseHandle(hinternet);
1411 return E_OUTOFMEMORY;
1419 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1420 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1421 InternetCloseHandle(hreq);
1422 InternetCloseHandle(hcon);
1423 InternetCloseHandle(hinternet);
1429 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1430 InternetCloseHandle(hreq);
1431 InternetCloseHandle(hcon);
1432 InternetCloseHandle(hinternet);
1435 return E_OUTOFMEMORY;
1440 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1441 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1442 InternetCloseHandle(hreq);
1443 InternetCloseHandle(hcon);
1444 InternetCloseHandle(hinternet);
1450 InternetCloseHandle(hreq);
1451 InternetCloseHandle(hcon);
1452 InternetCloseHandle(hinternet);