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;*/
51 /* filemoniker data structure */
52 typedef struct URLMonikerImpl{
54 IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
55 IBindingVtbl* lpvtbl2; /* VTable to IBinding interface */
57 ULONG ref; /* reference counter for this object */
59 LPOLESTR URLName; /* URL string identified by this URLmoniker */
63 HINTERNET hinternet, hconnect, hrequest;
66 /********************************************************************************/
67 /* URLMoniker prototype functions : */
69 /* IUnknown prototype functions */
70 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
71 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface);
72 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface);
74 /* IPersist prototype functions */
75 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
77 /* IPersistStream prototype functions */
78 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface);
79 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface, IStream* pStm);
80 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
81 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
83 /* IMoniker prototype functions */
84 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
85 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
86 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
87 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
88 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
89 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
90 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
91 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
92 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
93 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
94 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
95 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
96 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
97 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
98 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
100 /* IBinding interface to moniker */
101 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject);
102 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface);
103 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface);
104 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface);
105 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface);
106 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface);
107 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority);
108 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority);
109 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved);
111 /* Local function used by urlmoniker implementation */
112 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszLeftURL, LPCOLESTR lpszURL);
113 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface);
115 /********************************************************************************/
116 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
117 /* IPersistStream and IMoniker functions. */
118 static IMonikerVtbl VT_URLMonikerImpl =
120 URLMonikerImpl_QueryInterface,
121 URLMonikerImpl_AddRef,
122 URLMonikerImpl_Release,
123 URLMonikerImpl_GetClassID,
124 URLMonikerImpl_IsDirty,
127 URLMonikerImpl_GetSizeMax,
128 URLMonikerImpl_BindToObject,
129 URLMonikerImpl_BindToStorage,
130 URLMonikerImpl_Reduce,
131 URLMonikerImpl_ComposeWith,
133 URLMonikerImpl_IsEqual,
135 URLMonikerImpl_IsRunning,
136 URLMonikerImpl_GetTimeOfLastChange,
137 URLMonikerImpl_Inverse,
138 URLMonikerImpl_CommonPrefixWith,
139 URLMonikerImpl_RelativePathTo,
140 URLMonikerImpl_GetDisplayName,
141 URLMonikerImpl_ParseDisplayName,
142 URLMonikerImpl_IsSystemMoniker
145 static IBindingVtbl VTBinding_URLMonikerImpl =
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 URLMonikerImpl *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 URLMonikerImpl *This = (URLMonikerImpl *)iface;
200 TRACE("(%p)\n",This);
202 return InterlockedIncrement(&This->ref);
205 /******************************************************************************
207 ******************************************************************************/
208 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
210 URLMonikerImpl *This = (URLMonikerImpl *)iface;
213 TRACE("(%p)\n",This);
215 ref = InterlockedDecrement(&This->ref);
217 /* destroy the object if there's no more reference on it */
218 if (ref == 0) URLMonikerImpl_Destroy(This);
223 /******************************************************************************
224 * URLMoniker_GetClassID
225 ******************************************************************************/
226 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
227 CLSID *pClassID)/* Pointer to CLSID of object */
229 URLMonikerImpl *This = (URLMonikerImpl *)iface;
231 TRACE("(%p,%p)\n",This,pClassID);
235 /* Windows always returns CLSID_StdURLMoniker */
236 *pClassID = CLSID_StdURLMoniker;
240 /******************************************************************************
242 ******************************************************************************/
243 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
245 URLMonikerImpl *This = (URLMonikerImpl *)iface;
246 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
247 method in the OLE-provided moniker interfaces always return S_FALSE because
248 their internal state never changes. */
250 TRACE("(%p)\n",This);
255 /******************************************************************************
259 * Writes a ULONG containing length of unicode string, followed
260 * by that many unicode characters
261 ******************************************************************************/
262 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
264 URLMonikerImpl *This = (URLMonikerImpl *)iface;
269 TRACE("(%p,%p)\n",This,pStm);
274 res = IStream_Read(pStm, &len, sizeof(ULONG), &got);
276 if(got == sizeof(ULONG)) {
278 HeapFree(GetProcessHeap(), 0, This->URLName);
279 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(len+1));
283 res = IStream_Read(pStm, This->URLName, len, NULL);
284 This->URLName[len] = 0;
293 /******************************************************************************
295 ******************************************************************************/
296 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
297 IStream* pStm,/* pointer to the stream where the object is to be saved */
298 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
300 URLMonikerImpl *This = (URLMonikerImpl *)iface;
304 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
309 len = strlenW(This->URLName);
310 res=IStream_Write(pStm,&len,sizeof(ULONG),NULL);
312 res=IStream_Write(pStm,&This->URLName,len*sizeof(WCHAR),NULL);
317 /******************************************************************************
318 * URLMoniker_GetSizeMax
319 ******************************************************************************/
320 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
321 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
323 URLMonikerImpl *This = (URLMonikerImpl *)iface;
325 TRACE("(%p,%p)\n",This,pcbSize);
330 pcbSize->u.LowPart = sizeof(ULONG) + (strlenW(This->URLName) * sizeof(WCHAR));
331 pcbSize->u.HighPart = 0;
335 /******************************************************************************
336 * URLMoniker_Construct (local function)
337 *******************************************************************************/
338 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
343 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
344 memset(This, 0, sizeof(*This));
346 /* Initialize the virtual function table. */
347 This->lpvtbl1 = &VT_URLMonikerImpl;
348 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
351 if(lpszLeftURLName) {
352 hres = UrlCombineW(lpszLeftURLName, lpszURLName, NULL, &sizeStr, 0);
359 sizeStr = lstrlenW(lpszURLName)+1;
361 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr));
363 if (This->URLName==NULL)
364 return E_OUTOFMEMORY;
366 if(lpszLeftURLName) {
367 hres = UrlCombineW(lpszLeftURLName, lpszURLName, This->URLName, &sizeStr, 0);
369 HeapFree(GetProcessHeap(), 0, This->URLName);
374 strcpyW(This->URLName,lpszURLName);
381 /******************************************************************************
382 * URLMoniker_Destroy (local function)
383 *******************************************************************************/
384 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
386 TRACE("(%p)\n",This);
388 if (This->URLName!=NULL)
389 HeapFree(GetProcessHeap(),0,This->URLName);
391 HeapFree(GetProcessHeap(),0,This);
396 /******************************************************************************
397 * URLMoniker_BindToObject
398 ******************************************************************************/
399 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
405 URLMonikerImpl *This = (URLMonikerImpl *)iface;
409 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
416 enum {OnProgress, OnDataAvailable} callback;
417 } URLMON_CallbackData;
421 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
423 return DefWindowProcA(hwnd, msg, wparam, lparam);
426 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
430 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
431 void *status_info, DWORD status_info_len)
433 URLMonikerImpl *This = (URLMonikerImpl *)context;
434 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
436 if(This->filesize == -1) {
438 case INTERNET_STATUS_RESOLVING_NAME:
439 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
441 case INTERNET_STATUS_CONNECTING_TO_SERVER:
442 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
444 case INTERNET_STATUS_SENDING_REQUEST:
445 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
447 case INTERNET_REQUEST_COMPLETE:
449 DWORD len, lensz = sizeof(len);
451 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
452 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
453 This->filesize = len;
462 /******************************************************************************
463 * URLMoniker_BindToStorage
464 ******************************************************************************/
465 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
471 URLMonikerImpl *This = (URLMonikerImpl *)iface;
473 IBindStatusCallback *pbscb;
477 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
479 FIXME("pmkToLeft != NULL\n");
482 if(!IsEqualIID(&IID_IStream, riid)) {
483 FIXME("unsupported iid\n");
487 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
488 We also need to implement IStream ourselves so that IStream_Read can return
491 hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
494 if(SUCCEEDED(hres)) {
495 TRACE("Created dummy stream...\n");
497 hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&pbscb);
498 if(SUCCEEDED(hres)) {
499 TRACE("Got IBindStatusCallback...\n");
501 memset(&bi, 0, sizeof(bi));
502 bi.cbSize = sizeof(bi);
504 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
505 if(SUCCEEDED(hres)) {
508 DWORD len, lensz = sizeof(len), total_read = 0;
509 LARGE_INTEGER last_read_pos;
513 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
514 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
515 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
516 TRACE("OnStartBinding rets %08lx\n", hres);
519 if(!registered_wndclass) {
520 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
521 RegisterClassA(&urlmon_wndclass);
522 registered_wndclass = TRUE;
525 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
526 URLMON_hInstance, NULL);
529 memset(&url, 0, sizeof(url));
530 url.dwStructSize = sizeof(url);
531 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
532 InternetCrackUrlW(This->URLName, 0, 0, &url);
533 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
534 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
535 host[url.dwHostNameLength] = '\0';
536 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
537 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
538 path[url.dwUrlPathLength] = '\0';
540 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
541 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
543 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
544 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
545 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
547 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
548 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
549 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
550 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
551 hres = E_OUTOFMEMORY; /* FIXME */
552 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
555 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
557 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
559 last_read_pos.u.LowPart = last_read_pos.u.HighPart = 0;
564 fmt.tymed = TYMED_ISTREAM;
565 stg.tymed = TYMED_ISTREAM;
566 stg.u.pstm = *(IStream**)ppvObject;
567 stg.pUnkForRelease = NULL;
573 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
574 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
575 if(bufread == 0) break;
576 IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
577 total_read += bufread;
578 IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
579 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
580 BINDSTATUS_BEGINDOWNLOADDATA :
581 BINDSTATUS_DOWNLOADINGDATA, NULL);
582 hres = IBindStatusCallback_OnDataAvailable(pbscb,
583 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
584 BSCF_INTERMEDIATEDATANOTIFICATION,
585 total_read, &fmt, &stg);
586 last_read_pos.u.LowPart += bufread; /* FIXME */
590 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
591 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
592 TRACE("OnDataAvail rets %08lx\n", hres);
593 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
594 TRACE("OnStop rets %08lx\n", hres);
597 InternetCloseHandle(This->hrequest);
598 InternetCloseHandle(This->hconnect);
599 InternetCloseHandle(This->hinternet);
606 /******************************************************************************
608 ******************************************************************************/
609 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
611 DWORD dwReduceHowFar,
612 IMoniker** ppmkToLeft,
613 IMoniker** ppmkReduced)
615 URLMonikerImpl *This = (URLMonikerImpl *)iface;
617 TRACE("(%p,%p,%ld,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
622 URLMonikerImpl_AddRef(iface);
623 *ppmkReduced = iface;
624 return MK_S_REDUCED_TO_SELF;
627 /******************************************************************************
628 * URLMoniker_ComposeWith
629 ******************************************************************************/
630 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
632 BOOL fOnlyIfNotGeneric,
633 IMoniker** ppmkComposite)
635 URLMonikerImpl *This = (URLMonikerImpl *)iface;
636 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
641 /******************************************************************************
643 ******************************************************************************/
644 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
646 URLMonikerImpl *This = (URLMonikerImpl *)iface;
647 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
652 /* Does not support sub-monikers */
653 *ppenumMoniker = NULL;
657 /******************************************************************************
659 ******************************************************************************/
660 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
662 URLMonikerImpl *This = (URLMonikerImpl *)iface;
668 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
670 if(pmkOtherMoniker==NULL)
673 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
675 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
678 res = CreateBindCtx(0,&bind);
683 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
684 int result = lstrcmpiW(urlPath, This->URLName);
685 CoTaskMemFree(urlPath);
689 IUnknown_Release(bind);
694 /******************************************************************************
696 ******************************************************************************/
697 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
699 URLMonikerImpl *This = (URLMonikerImpl *)iface;
701 int h = 0,i,skip,len;
705 TRACE("(%p,%p)\n",This,pdwHash);
714 for(i = len ; i > 0; i--) {
715 h = (h * 37) + val[off++];
719 /* only sample some characters */
721 for(i = len; i > 0; i -= skip, off += skip) {
722 h = (h * 39) + val[off];
729 /******************************************************************************
730 * URLMoniker_IsRunning
731 ******************************************************************************/
732 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
735 IMoniker* pmkNewlyRunning)
737 URLMonikerImpl *This = (URLMonikerImpl *)iface;
738 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
743 /******************************************************************************
744 * URLMoniker_GetTimeOfLastChange
745 ******************************************************************************/
746 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
751 URLMonikerImpl *This = (URLMonikerImpl *)iface;
752 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
757 /******************************************************************************
759 ******************************************************************************/
760 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
762 URLMonikerImpl *This = (URLMonikerImpl *)iface;
763 TRACE("(%p,%p)\n",This,ppmk);
765 return MK_E_NOINVERSE;
768 /******************************************************************************
769 * URLMoniker_CommonPrefixWith
770 ******************************************************************************/
771 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
773 URLMonikerImpl *This = (URLMonikerImpl *)iface;
774 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
779 /******************************************************************************
780 * URLMoniker_RelativePathTo
781 ******************************************************************************/
782 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
784 URLMonikerImpl *This = (URLMonikerImpl *)iface;
785 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
790 /******************************************************************************
791 * URLMoniker_GetDisplayName
792 ******************************************************************************/
793 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
796 LPOLESTR *ppszDisplayName)
798 URLMonikerImpl *This = (URLMonikerImpl *)iface;
802 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
807 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
808 then look at pmkToLeft to try and complete the URL
810 len = lstrlenW(This->URLName)+1;
811 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
812 if(!*ppszDisplayName)
813 return E_OUTOFMEMORY;
814 lstrcpyW(*ppszDisplayName, This->URLName);
818 /******************************************************************************
819 * URLMoniker_ParseDisplayName
820 ******************************************************************************/
821 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
824 LPOLESTR pszDisplayName,
828 URLMonikerImpl *This = (URLMonikerImpl *)iface;
829 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
834 /******************************************************************************
835 * URLMoniker_IsSystemMoniker
836 ******************************************************************************/
837 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
839 URLMonikerImpl *This = (URLMonikerImpl *)iface;
840 TRACE("(%p,%p)\n",This,pwdMksys);
845 *pwdMksys = MKSYS_URLMONIKER;
849 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
851 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
853 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
855 /* Perform a sanity check on the parameters.*/
856 if ( (This==0) || (ppvObject==0) )
859 /* Initialize the return parameter */
862 /* Compare the riid with the interface IDs implemented by this object.*/
863 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
866 /* Check that we obtained an interface.*/
868 return E_NOINTERFACE;
870 /* Query Interface always increases the reference count by one when it is successful */
871 URLMonikerImpl_IBinding_AddRef(iface);
877 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
879 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
880 TRACE("(%p)\n",This);
882 return URLMonikerImpl_AddRef((IMoniker*)This);
885 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
887 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
888 TRACE("(%p)\n",This);
890 return URLMonikerImpl_Release((IMoniker*)This);
893 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
895 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
896 FIXME("(%p): stub\n", This);
901 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
903 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
904 FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
909 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
911 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
912 FIXME("(%p)->(%p): stub\n", This, pnPriority);
917 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
919 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
920 FIXME("(%p): stub\n", This);
925 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
927 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
928 FIXME("(%p)->(%ld): stub\n", This, nPriority);
933 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
935 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
936 FIXME("(%p): stub\n", This);
941 /***********************************************************************
942 * CreateAsyncBindCtx (URLMON.@)
944 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
945 IEnumFORMATETC *format, IBindCtx **pbind)
950 /***********************************************************************
951 * CreateAsyncBindCtxEx (URLMON.@)
953 * Create an asynchronous bind context.
958 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
959 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
962 FIXME("stub, returns failure\n");
967 /***********************************************************************
968 * CreateURLMoniker (URLMON.@)
970 * Create a url moniker.
973 * pmkContext [I] Context
974 * szURL [I] Url to create the moniker for
975 * ppmk [O] Destination for created moniker.
978 * Success: S_OK. ppmk contains the created IMoniker object.
979 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
980 * E_OUTOFMEMORY if memory allocation fails.
982 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
986 IID iid = IID_IMoniker;
987 LPOLESTR lefturl = NULL;
989 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
991 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
992 return E_OUTOFMEMORY;
997 IMoniker_GetClassID(pmkContext, &clsid);
998 if(IsEqualCLSID(&clsid, &CLSID_StdURLMoniker) && SUCCEEDED(CreateBindCtx(0, &bind))) {
999 URLMonikerImpl_GetDisplayName(pmkContext, bind, NULL, &lefturl);
1000 IBindCtx_Release(bind);
1004 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
1005 CoTaskMemFree(lefturl);
1007 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
1009 HeapFree(GetProcessHeap(), 0, obj);
1014 /***********************************************************************
1015 * CoInternetGetSession (URLMON.@)
1017 * Create a new internet session and return an IInternetSession interface
1021 * dwSessionMode [I] Mode for the internet session
1022 * ppIInternetSession [O] Destination for creates IInternetSession object
1023 * dwReserved [I] Reserved, must be 0.
1026 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
1027 * Failure: E_INVALIDARG, if any argument is invalid, or
1028 * E_OUTOFMEMORY if memory allocation fails.
1030 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, IInternetSession **ppIInternetSession, DWORD dwReserved)
1032 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
1035 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
1039 ERR("dwReserved: %ld, must be zero\n", dwReserved);
1042 *ppIInternetSession=NULL;
1043 return E_OUTOFMEMORY;
1046 /***********************************************************************
1047 * CoInternetQueryInfo (URLMON.@)
1049 * Retrieves information relevant to a specified URL
1053 * S_FALSE buffer too small
1054 * INET_E_QUERYOPTIONUNKNOWN invalid option
1057 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1058 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1061 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
1062 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1066 static BOOL URLMON_IsBinary(LPVOID pBuffer, DWORD cbSize)
1068 unsigned int i, binarycount = 0;
1069 unsigned char *buff = pBuffer;
1070 for(i=0; i<cbSize; i++) {
1074 return binarycount > (cbSize-binarycount);
1077 /***********************************************************************
1078 * FindMimeFromData (URLMON.@)
1080 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
1083 * See http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
1085 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
1086 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
1087 LPWSTR* ppwzMimeOut, DWORD dwReserved)
1089 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'};
1090 static const WCHAR szTextMime[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
1091 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
1092 WCHAR szTmpMime[256];
1093 LPCWSTR mimeType = NULL;
1096 TRACE("(%p,%s,%p,%ld,%s,0x%lx,%p,0x%lx)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
1097 debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
1099 if((!pwzUrl && (!pBuffer || cbSize <= 0)) || !ppwzMimeOut)
1100 return E_INVALIDARG;
1103 mimeType = pwzMimeProposed;
1105 /* Try and find the mime type in the registry */
1107 LPWSTR ext = strrchrW(pwzUrl, '.');
1110 if(!RegOpenKeyExW(HKEY_CLASSES_ROOT, ext, 0, 0, &hKey)) {
1111 if(!RegQueryValueExW(hKey, szContentType, NULL, NULL, (LPBYTE)szTmpMime, &dwSize)) {
1112 mimeType = szTmpMime;
1119 if(!mimeType && pBuffer && cbSize > 0)
1120 mimeType = URLMON_IsBinary(pBuffer, cbSize)?szBinaryMime:szTextMime;
1122 TRACE("Using %s\n", debugstr_w(mimeType));
1123 *ppwzMimeOut = CoTaskMemAlloc((lstrlenW(mimeType)+1)*sizeof(WCHAR));
1124 if(!*ppwzMimeOut) return E_OUTOFMEMORY;
1125 lstrcpyW(*ppwzMimeOut, mimeType);
1129 /***********************************************************************
1130 * IsAsyncMoniker (URLMON.@)
1132 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1136 TRACE("(%p)\n", pmk);
1138 return E_INVALIDARG;
1139 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1140 IUnknown_Release(am);
1146 /***********************************************************************
1147 * RegisterBindStatusCallback (URLMON.@)
1149 * Register a bind status callback.
1152 * pbc [I] Binding context
1153 * pbsc [I] Callback to register
1154 * ppbscPrevious [O] Destination for previous callback
1155 * dwReserved [I] Reserved, must be 0.
1159 * Failure: E_INVALIDARG, if any argument is invalid, or
1160 * E_OUTOFMEMORY if memory allocation fails.
1162 HRESULT WINAPI RegisterBindStatusCallback(
1164 IBindStatusCallback *pbsc,
1165 IBindStatusCallback **ppbscPrevious,
1168 IBindStatusCallback *prev;
1170 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
1172 if (pbc == NULL || pbsc == NULL)
1173 return E_INVALIDARG;
1175 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
1177 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1179 *ppbscPrevious = prev;
1181 IBindStatusCallback_Release(prev);
1184 return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
1187 /***********************************************************************
1188 * RevokeBindStatusCallback (URLMON.@)
1190 * Unregister a bind status callback.
1192 * pbc [I] Binding context
1193 * pbsc [I] Callback to unregister
1197 * Failure: E_INVALIDARG, if any argument is invalid, or
1198 * E_FAIL if pbsc wasn't registered with pbc.
1200 HRESULT WINAPI RevokeBindStatusCallback(
1202 IBindStatusCallback *pbsc)
1204 IBindStatusCallback *callback;
1205 HRESULT hr = E_FAIL;
1207 TRACE("(%p,%p)\n", pbc, pbsc);
1209 if (pbc == NULL || pbsc == NULL)
1210 return E_INVALIDARG;
1212 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
1214 if (callback == pbsc)
1216 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1219 IBindStatusCallback_Release(pbsc);
1225 /***********************************************************************
1226 * ReleaseBindInfo (URLMON.@)
1228 * Release the resources used by the specified BINDINFO structure.
1231 * pbindinfo [I] BINDINFO to release.
1236 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1238 FIXME("(%p)stub!\n", pbindinfo);
1241 /***********************************************************************
1242 * URLDownloadToFileA (URLMON.@)
1244 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1248 * pCaller [I] controlling IUnknown interface.
1249 * szURL [I] URL of the file to download
1250 * szFileName [I] file name to store the content of the URL
1251 * dwReserved [I] reserved - set to 0
1252 * lpfnCB [I] callback for progress report
1256 * E_OUTOFMEMORY when going out of memory
1258 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1262 LPBINDSTATUSCALLBACK lpfnCB)
1264 UNICODE_STRING szURL_w, szFileName_w;
1266 if ((szURL == NULL) || (szFileName == NULL)) {
1267 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1268 return E_INVALIDARG; /* The error code is not specified in this case... */
1271 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1272 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1273 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1275 RtlFreeUnicodeString(&szURL_w);
1276 RtlFreeUnicodeString(&szFileName_w);
1280 RtlFreeUnicodeString(&szURL_w);
1284 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1285 return E_OUTOFMEMORY;
1288 /***********************************************************************
1289 * URLDownloadToFileW (URLMON.@)
1291 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1295 * pCaller [I] controlling IUnknown interface.
1296 * szURL [I] URL of the file to download
1297 * szFileName [I] file name to store the content of the URL
1298 * dwReserved [I] reserved - set to 0
1299 * lpfnCB [I] callback for progress report
1303 * E_OUTOFMEMORY when going out of memory
1305 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1309 LPBINDSTATUSCALLBACK lpfnCB)
1311 HINTERNET hinternet, hcon, hreq;
1313 CHAR buffer[0x1000];
1314 DWORD sz, total, written;
1315 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1316 URL_COMPONENTSW url;
1317 WCHAR host[0x80], path[0x100];
1319 static const WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1321 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1322 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1324 if ((szURL == NULL) || (szFileName == NULL)) {
1325 FIXME(" cannot accept NULL strings !\n");
1326 return E_INVALIDARG;
1329 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1330 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1331 if (hinternet == NULL) {
1332 return E_OUTOFMEMORY;
1335 memset(&url, 0, sizeof(url));
1336 url.dwStructSize = sizeof(url);
1337 url.lpszHostName = host;
1338 url.dwHostNameLength = sizeof(host);
1339 url.lpszUrlPath = path;
1340 url.dwUrlPathLength = sizeof(path);
1342 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1343 InternetCloseHandle(hinternet);
1344 return E_OUTOFMEMORY;
1348 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1349 InternetCloseHandle(hinternet);
1354 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1355 url.lpszUserName, url.lpszPassword,
1356 INTERNET_SERVICE_HTTP, 0, 0);
1358 InternetCloseHandle(hinternet);
1359 return E_OUTOFMEMORY;
1362 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1364 InternetCloseHandle(hinternet);
1365 InternetCloseHandle(hcon);
1366 return E_OUTOFMEMORY;
1369 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1370 InternetCloseHandle(hinternet);
1371 InternetCloseHandle(hcon);
1372 InternetCloseHandle(hreq);
1373 return E_OUTOFMEMORY;
1376 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1377 &total_size, &arg_size, NULL)) {
1378 TRACE(" total size : %ld\n", total_size);
1381 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1382 FILE_ATTRIBUTE_NORMAL, NULL );
1383 if (hfile == INVALID_HANDLE_VALUE) {
1384 return E_ACCESSDENIED;
1388 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1389 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1390 InternetCloseHandle(hreq);
1391 InternetCloseHandle(hcon);
1392 InternetCloseHandle(hinternet);
1400 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1402 InternetCloseHandle(hreq);
1403 InternetCloseHandle(hcon);
1404 InternetCloseHandle(hinternet);
1407 return E_OUTOFMEMORY;
1415 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1416 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1417 InternetCloseHandle(hreq);
1418 InternetCloseHandle(hcon);
1419 InternetCloseHandle(hinternet);
1425 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1426 InternetCloseHandle(hreq);
1427 InternetCloseHandle(hcon);
1428 InternetCloseHandle(hinternet);
1431 return E_OUTOFMEMORY;
1436 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1437 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1438 InternetCloseHandle(hreq);
1439 InternetCloseHandle(hcon);
1440 InternetCloseHandle(hinternet);
1446 InternetCloseHandle(hreq);
1447 InternetCloseHandle(hcon);
1448 InternetCloseHandle(hinternet);
1455 /***********************************************************************
1456 * HlinkSimpleNavigateToString (URLMON.@)
1458 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
1459 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1460 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1462 FIXME("%s\n", debugstr_w( szTarget ) );
1466 /***********************************************************************
1467 * HlinkNavigateString (URLMON.@)
1469 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
1471 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
1472 return HlinkSimpleNavigateToString(
1473 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );