4 * Copyright 1999 Ulrich Czekalla for Corel Corporation
5 * Copyright 2002 Huw D M Davies for CodeWeavers
6 * Copyright 2005 Jacek Caban for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define COM_NO_WINDOWS_H
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
43 #include "urlmon_main.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
47 /* native urlmon.dll uses this key, too */
48 static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
50 /*static BOOL registered_wndclass = FALSE;*/
53 const IBindingVtbl *lpVtbl;
61 HINTERNET hinternet, hconnect, hrequest;
63 IUMCacheStream *pstrCache;
64 IBindStatusCallback *pbscb;
65 DWORD total_read, expected_size;
68 static HRESULT WINAPI Binding_QueryInterface(IBinding* iface, REFIID riid, void **ppvObject)
70 Binding *This = (Binding*)iface;
72 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
74 if((This == NULL) || (ppvObject == NULL))
77 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid)) {
79 IBinding_AddRef(iface);
87 static ULONG WINAPI Binding_AddRef(IBinding* iface)
89 Binding *This = (Binding*)iface;
90 ULONG ref = InterlockedIncrement(&This->ref);
92 TRACE("(%p) ref=%d\n", This, ref);
97 static ULONG WINAPI Binding_Release(IBinding* iface)
99 Binding *This = (Binding*)iface;
100 ULONG ref = InterlockedDecrement(&This->ref);
102 TRACE("(%p) ref=%d\n",This, ref);
105 HeapFree(GetProcessHeap(), 0, This->URLName);
106 if (This->hCacheFile)
107 CloseHandle(This->hCacheFile);
110 UMCloseCacheFileStream(This->pstrCache);
111 IStream_Release((IStream *)This->pstrCache);
114 IBindStatusCallback_Release(This->pbscb);
116 HeapFree(GetProcessHeap(), 0, This);
118 URLMON_UnlockModule();
124 static HRESULT WINAPI Binding_Abort(IBinding* iface)
126 Binding *This = (Binding*)iface;
128 FIXME("(%p): stub\n", This);
133 static HRESULT WINAPI Binding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
135 Binding *This = (Binding*)iface;
137 FIXME("(%p)->(%p, %p, %p, %p): stub\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
142 static HRESULT WINAPI Binding_GetPriority(IBinding* iface, LONG* pnPriority)
144 Binding *This = (Binding*)iface;
146 FIXME("(%p)->(%p): stub\n", This, pnPriority);
151 static HRESULT WINAPI Binding_Resume(IBinding* iface)
153 Binding *This = (Binding*)iface;
155 FIXME("(%p): stub\n", This);
160 static HRESULT WINAPI Binding_SetPriority(IBinding* iface, LONG nPriority)
162 Binding *This = (Binding*)iface;
164 FIXME("(%p)->(%d): stub\n", This, nPriority);
169 static HRESULT WINAPI Binding_Suspend(IBinding* iface)
171 Binding *This = (Binding*)iface;
173 FIXME("(%p): stub\n", This);
178 static void Binding_CloseCacheDownload(Binding *This)
180 CloseHandle(This->hCacheFile);
181 This->hCacheFile = 0;
182 UMCloseCacheFileStream(This->pstrCache);
183 IStream_Release((IStream *)This->pstrCache);
187 static HRESULT Binding_MoreCacheData(Binding *This, char *buf, DWORD dwBytes)
191 if (WriteFile(This->hCacheFile, buf, dwBytes, &written, NULL) && written == dwBytes)
195 This->total_read += written;
196 hr = IBindStatusCallback_OnProgress(This->pbscb,
197 This->total_read + written,
199 (This->total_read == written) ?
200 BINDSTATUS_BEGINDOWNLOADDATA :
201 BINDSTATUS_DOWNLOADINGDATA,
212 fmt.tymed = TYMED_ISTREAM;
214 stg.tymed = TYMED_ISTREAM;
215 stg.u.pstm = (IStream *)This->pstrCache;
216 stg.pUnkForRelease = NULL;
218 hr = IBindStatusCallback_OnDataAvailable(This->pbscb,
219 (This->total_read == written) ?
220 BSCF_FIRSTDATANOTIFICATION :
221 BSCF_INTERMEDIATEDATANOTIFICATION,
222 This->total_read + written,
226 if (written < dwBytes)
227 return STG_E_MEDIUMFULL;
231 return HRESULT_FROM_WIN32(GetLastError());
234 static void Binding_FinishedDownload(Binding *This, HRESULT hr)
242 fmt.tymed = TYMED_ISTREAM;
244 stg.tymed = TYMED_ISTREAM;
245 stg.u.pstm = (IStream *)This->pstrCache;
246 stg.pUnkForRelease = NULL;
248 IBindStatusCallback_OnProgress(This->pbscb, This->total_read, This->expected_size,
249 BINDSTATUS_ENDDOWNLOADDATA, This->URLName);
250 IBindStatusCallback_OnDataAvailable(This->pbscb, BSCF_LASTDATANOTIFICATION, This->total_read, &fmt, &stg);
253 WCHAR *pwchError = 0;
255 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
256 FORMAT_MESSAGE_ALLOCATE_BUFFER,
258 0, (LPWSTR) &pwchError,
262 static const WCHAR achFormat[] = { '%', '0', '8', 'x', 0 };
264 pwchError =(WCHAR *) LocalAlloc(LMEM_FIXED, sizeof(WCHAR) * 9);
265 wsprintfW(pwchError, achFormat, hr);
267 IBindStatusCallback_OnStopBinding(This->pbscb, hr, pwchError);
268 LocalFree(pwchError);
272 IBindStatusCallback_OnStopBinding(This->pbscb, hr, NULL);
274 IBindStatusCallback_Release(This->pbscb);
278 static const IBindingVtbl BindingVtbl =
280 Binding_QueryInterface,
288 Binding_GetBindResult
291 /* filemoniker data structure */
294 const IMonikerVtbl* lpvtbl; /* VTable relative to the IMoniker interface.*/
296 LONG ref; /* reference counter for this object */
298 LPOLESTR URLName; /* URL string identified by this URLmoniker */
301 /*******************************************************************************
302 * URLMoniker_QueryInterface
303 *******************************************************************************/
304 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
306 URLMonikerImpl *This = (URLMonikerImpl *)iface;
308 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
310 /* Perform a sanity check on the parameters.*/
311 if ( (This==0) || (ppvObject==0) )
314 /* Initialize the return parameter */
317 /* Compare the riid with the interface IDs implemented by this object.*/
318 if (IsEqualIID(&IID_IUnknown, riid) ||
319 IsEqualIID(&IID_IPersist, riid) ||
320 IsEqualIID(&IID_IPersistStream,riid) ||
321 IsEqualIID(&IID_IMoniker, riid)
325 /* Check that we obtained an interface.*/
327 return E_NOINTERFACE;
329 /* Query Interface always increases the reference count by one when it is successful */
330 IMoniker_AddRef(iface);
335 /******************************************************************************
337 ******************************************************************************/
338 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
340 URLMonikerImpl *This = (URLMonikerImpl *)iface;
341 ULONG refCount = InterlockedIncrement(&This->ref);
343 TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
348 /******************************************************************************
350 ******************************************************************************/
351 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
353 URLMonikerImpl *This = (URLMonikerImpl *)iface;
354 ULONG refCount = InterlockedDecrement(&This->ref);
356 TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
358 /* destroy the object if there's no more reference on it */
360 HeapFree(GetProcessHeap(),0,This->URLName);
361 HeapFree(GetProcessHeap(),0,This);
363 URLMON_UnlockModule();
370 /******************************************************************************
371 * URLMoniker_GetClassID
372 ******************************************************************************/
373 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
374 CLSID *pClassID)/* Pointer to CLSID of object */
376 URLMonikerImpl *This = (URLMonikerImpl *)iface;
378 TRACE("(%p,%p)\n",This,pClassID);
382 /* Windows always returns CLSID_StdURLMoniker */
383 *pClassID = CLSID_StdURLMoniker;
387 /******************************************************************************
389 ******************************************************************************/
390 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
392 URLMonikerImpl *This = (URLMonikerImpl *)iface;
393 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
394 method in the OLE-provided moniker interfaces always return S_FALSE because
395 their internal state never changes. */
397 TRACE("(%p)\n",This);
402 /******************************************************************************
406 * Writes a ULONG containing length of unicode string, followed
407 * by that many unicode characters
408 ******************************************************************************/
409 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
411 URLMonikerImpl *This = (URLMonikerImpl *)iface;
416 TRACE("(%p,%p)\n",This,pStm);
421 res = IStream_Read(pStm, &len, sizeof(ULONG), &got);
423 if(got == sizeof(ULONG)) {
424 HeapFree(GetProcessHeap(), 0, This->URLName);
425 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(len+1));
429 res = IStream_Read(pStm, This->URLName, len, NULL);
430 This->URLName[len] = 0;
439 /******************************************************************************
441 ******************************************************************************/
442 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
443 IStream* pStm,/* pointer to the stream where the object is to be saved */
444 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
446 URLMonikerImpl *This = (URLMonikerImpl *)iface;
450 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
455 len = strlenW(This->URLName);
456 res=IStream_Write(pStm,&len,sizeof(ULONG),NULL);
458 res=IStream_Write(pStm,&This->URLName,len*sizeof(WCHAR),NULL);
463 /******************************************************************************
464 * URLMoniker_GetSizeMax
465 ******************************************************************************/
466 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
467 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
469 URLMonikerImpl *This = (URLMonikerImpl *)iface;
471 TRACE("(%p,%p)\n",This,pcbSize);
476 pcbSize->u.LowPart = sizeof(ULONG) + (strlenW(This->URLName) * sizeof(WCHAR));
477 pcbSize->u.HighPart = 0;
481 /******************************************************************************
482 * URLMoniker_BindToObject
483 ******************************************************************************/
484 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
490 URLMonikerImpl *This = (URLMonikerImpl *)iface;
494 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
500 /******************************************************************************
501 * URLMoniker_BindToStorage
502 ******************************************************************************/
503 static HRESULT URLMonikerImpl_BindToStorage_hack(LPCWSTR URLName,
512 WCHAR szFileName[MAX_PATH + 1];
516 WARN("(%s %p %p %s %p)\n", debugstr_w(URLName), pbc, pmkToLeft, debugstr_guid(riid),
520 FIXME("pmkToLeft != NULL\n");
523 if(!IsEqualIID(&IID_IStream, riid)) {
524 FIXME("unsupported iid\n");
528 bind = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Binding));
529 bind->lpVtbl = &BindingVtbl;
533 len = lstrlenW(URLName)+1;
534 bind->URLName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
535 memcpy(bind->URLName, URLName, len*sizeof(WCHAR));
537 hres = UMCreateStreamOnCacheFile(bind->URLName, 0, szFileName, &bind->hCacheFile, &bind->pstrCache);
539 if(SUCCEEDED(hres)) {
540 TRACE("Created stream...\n");
542 *ppvObject = (void *) bind->pstrCache;
543 IStream_AddRef((IStream *) bind->pstrCache);
545 hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&bind->pbscb);
546 if(SUCCEEDED(hres)) {
547 TRACE("Got IBindStatusCallback...\n");
549 memset(&bi, 0, sizeof(bi));
550 bi.cbSize = sizeof(bi);
552 hres = IBindStatusCallback_GetBindInfo(bind->pbscb, &bindf, &bi);
553 if(SUCCEEDED(hres)) {
554 WCHAR *urlcopy, *tmpwc;
556 WCHAR *host, *path, *user, *pass;
557 DWORD lensz = sizeof(bind->expected_size);
561 TRACE("got bindinfo. bindf = %08x extrainfo = %s bindinfof = %08x bindverb = %08x iid %s\n",
562 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
563 hres = IBindStatusCallback_OnStartBinding(bind->pbscb, 0, (IBinding*)bind);
564 TRACE("OnStartBinding rets %08x\n", hres);
566 /* This class will accept URLs with the backslash in them. But InternetCrackURL will not - it
567 * requires forward slashes (this is the behaviour of Microsoft's INETAPI). So we need to make
568 * a copy of the URL here and change the backslash to a forward slash everywhere it appears -
569 * but only before any '#' or '?', after which backslash should be left alone.
571 urlcopy = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(bind->URLName) + 1));
572 lstrcpyW(urlcopy, bind->URLName);
573 for (tmpwc = urlcopy; *tmpwc && *tmpwc != '#' && *tmpwc != '?'; ++tmpwc)
577 bind->expected_size = 0;
578 bind->total_read = 0;
580 memset(&url, 0, sizeof(url));
581 url.dwStructSize = sizeof(url);
582 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = url.dwUserNameLength = url.dwPasswordLength = 1;
583 InternetCrackUrlW(urlcopy, 0, ICU_ESCAPE, &url);
584 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
585 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
586 host[url.dwHostNameLength] = '\0';
587 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
588 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
589 path[url.dwUrlPathLength] = '\0';
590 if (url.dwUserNameLength)
592 user = HeapAlloc(GetProcessHeap(), 0, ((url.dwUserNameLength + 1) * sizeof(WCHAR)));
593 memcpy(user, url.lpszUserName, url.dwUserNameLength * sizeof(WCHAR));
594 user[url.dwUserNameLength] = 0;
600 if (url.dwPasswordLength)
602 pass = HeapAlloc(GetProcessHeap(), 0, ((url.dwPasswordLength + 1) * sizeof(WCHAR)));
603 memcpy(pass, url.lpszPassword, url.dwPasswordLength * sizeof(WCHAR));
604 pass[url.dwPasswordLength] = 0;
613 bind->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0);
614 if (!bind->hinternet)
616 hres = HRESULT_FROM_WIN32(GetLastError());
620 switch ((DWORD) url.nScheme)
622 case INTERNET_SCHEME_FTP:
624 url.nPort = INTERNET_DEFAULT_FTP_PORT;
625 dwService = INTERNET_SERVICE_FTP;
628 case INTERNET_SCHEME_GOPHER:
630 url.nPort = INTERNET_DEFAULT_GOPHER_PORT;
631 dwService = INTERNET_SERVICE_GOPHER;
634 case INTERNET_SCHEME_HTTP:
636 url.nPort = INTERNET_DEFAULT_HTTP_PORT;
637 dwService = INTERNET_SERVICE_HTTP;
640 case INTERNET_SCHEME_HTTPS:
642 url.nPort = INTERNET_DEFAULT_HTTPS_PORT;
643 dwService = INTERNET_SERVICE_HTTP;
647 bind->hconnect = InternetConnectW(bind->hinternet, host, url.nPort, user, pass,
648 dwService, 0, (DWORD)bind);
651 hres = HRESULT_FROM_WIN32(GetLastError());
652 CloseHandle(bind->hinternet);
656 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, 0x22, NULL);
657 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
658 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
659 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
665 case INTERNET_SERVICE_GOPHER:
666 bind->hrequest = GopherOpenFileW(bind->hconnect,
669 INTERNET_FLAG_RELOAD,
674 hres = HRESULT_FROM_WIN32(GetLastError());
677 case INTERNET_SERVICE_FTP:
678 bind->hrequest = FtpOpenFileW(bind->hconnect,
681 FTP_TRANSFER_TYPE_BINARY |
682 INTERNET_FLAG_TRANSFER_BINARY |
683 INTERNET_FLAG_RELOAD,
688 hres = HRESULT_FROM_WIN32(GetLastError());
691 case INTERNET_SERVICE_HTTP:
692 bind->hrequest = HttpOpenRequestW(bind->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)bind);
695 hres = HRESULT_FROM_WIN32(GetLastError());
697 else if (!HttpSendRequestW(bind->hrequest, NULL, 0, NULL, 0))
699 hres = HRESULT_FROM_WIN32(GetLastError());
700 InternetCloseHandle(bind->hrequest);
704 HttpQueryInfoW(bind->hrequest,
705 HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
706 &bind->expected_size,
715 TRACE("res = %d gle = %08x url len = %d\n", hres, GetLastError(), bind->expected_size);
717 IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE, szFileName);
722 if(InternetReadFile(bind->hrequest, buf, sizeof(buf), &bufread)) {
723 TRACE("read %d bytes %s...\n", bufread, debugstr_an(buf, 10));
724 if(bufread == 0) break;
725 hres = Binding_MoreCacheData(bind, buf, bufread);
729 InternetCloseHandle(bind->hrequest);
733 InternetCloseHandle(bind->hconnect);
734 InternetCloseHandle(bind->hinternet);
737 Binding_FinishedDownload(bind, hres);
738 Binding_CloseCacheDownload(bind);
740 HeapFree(GetProcessHeap(), 0, user);
741 HeapFree(GetProcessHeap(), 0, pass);
742 HeapFree(GetProcessHeap(), 0, path);
743 HeapFree(GetProcessHeap(), 0, host);
744 HeapFree(GetProcessHeap(), 0, urlcopy);
749 IBinding_Release((IBinding*)bind);
754 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
760 URLMonikerImpl *This = (URLMonikerImpl*)iface;
764 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW), schema,
765 sizeof(schema)/sizeof(WCHAR), 0, NULL, 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0};
767 bret = InternetCrackUrlW(This->URLName, 0, ICU_ESCAPE, &url);
769 ERR("InternetCrackUrl failed: %d\n", GetLastError());
773 if(url.nScheme == INTERNET_SCHEME_HTTP
774 || url.nScheme== INTERNET_SCHEME_HTTPS
775 || url.nScheme== INTERNET_SCHEME_FTP
776 || url.nScheme == INTERNET_SCHEME_GOPHER)
777 return URLMonikerImpl_BindToStorage_hack(This->URLName, pbc, pmkToLeft, riid, ppvObject);
779 TRACE("(%p)->(%p %p %s %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObject);
781 return start_binding(This->URLName, pbc, riid, ppvObject);
784 /******************************************************************************
786 ******************************************************************************/
787 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
789 DWORD dwReduceHowFar,
790 IMoniker** ppmkToLeft,
791 IMoniker** ppmkReduced)
793 URLMonikerImpl *This = (URLMonikerImpl *)iface;
795 TRACE("(%p,%p,%d,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
800 URLMonikerImpl_AddRef(iface);
801 *ppmkReduced = iface;
802 return MK_S_REDUCED_TO_SELF;
805 /******************************************************************************
806 * URLMoniker_ComposeWith
807 ******************************************************************************/
808 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
810 BOOL fOnlyIfNotGeneric,
811 IMoniker** ppmkComposite)
813 URLMonikerImpl *This = (URLMonikerImpl *)iface;
814 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
819 /******************************************************************************
821 ******************************************************************************/
822 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
824 URLMonikerImpl *This = (URLMonikerImpl *)iface;
825 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
830 /* Does not support sub-monikers */
831 *ppenumMoniker = NULL;
835 /******************************************************************************
837 ******************************************************************************/
838 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
840 URLMonikerImpl *This = (URLMonikerImpl *)iface;
846 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
848 if(pmkOtherMoniker==NULL)
851 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
853 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
856 res = CreateBindCtx(0,&bind);
861 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
862 int result = lstrcmpiW(urlPath, This->URLName);
863 CoTaskMemFree(urlPath);
867 IUnknown_Release(bind);
872 /******************************************************************************
874 ******************************************************************************/
875 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
877 URLMonikerImpl *This = (URLMonikerImpl *)iface;
879 int h = 0,i,skip,len;
883 TRACE("(%p,%p)\n",This,pdwHash);
892 for(i = len ; i > 0; i--) {
893 h = (h * 37) + val[off++];
897 /* only sample some characters */
899 for(i = len; i > 0; i -= skip, off += skip) {
900 h = (h * 39) + val[off];
907 /******************************************************************************
908 * URLMoniker_IsRunning
909 ******************************************************************************/
910 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
913 IMoniker* pmkNewlyRunning)
915 URLMonikerImpl *This = (URLMonikerImpl *)iface;
916 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
921 /******************************************************************************
922 * URLMoniker_GetTimeOfLastChange
923 ******************************************************************************/
924 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
929 URLMonikerImpl *This = (URLMonikerImpl *)iface;
930 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
935 /******************************************************************************
937 ******************************************************************************/
938 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
940 URLMonikerImpl *This = (URLMonikerImpl *)iface;
941 TRACE("(%p,%p)\n",This,ppmk);
943 return MK_E_NOINVERSE;
946 /******************************************************************************
947 * URLMoniker_CommonPrefixWith
948 ******************************************************************************/
949 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
951 URLMonikerImpl *This = (URLMonikerImpl *)iface;
952 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
957 /******************************************************************************
958 * URLMoniker_RelativePathTo
959 ******************************************************************************/
960 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
962 URLMonikerImpl *This = (URLMonikerImpl *)iface;
963 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
968 /******************************************************************************
969 * URLMoniker_GetDisplayName
970 ******************************************************************************/
971 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
974 LPOLESTR *ppszDisplayName)
976 URLMonikerImpl *This = (URLMonikerImpl *)iface;
980 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
985 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
986 then look at pmkToLeft to try and complete the URL
988 len = lstrlenW(This->URLName)+1;
989 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
990 if(!*ppszDisplayName)
991 return E_OUTOFMEMORY;
992 lstrcpyW(*ppszDisplayName, This->URLName);
996 /******************************************************************************
997 * URLMoniker_ParseDisplayName
998 ******************************************************************************/
999 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
1001 IMoniker* pmkToLeft,
1002 LPOLESTR pszDisplayName,
1006 URLMonikerImpl *This = (URLMonikerImpl *)iface;
1007 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
1012 /******************************************************************************
1013 * URLMoniker_IsSystemMoniker
1014 ******************************************************************************/
1015 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
1017 URLMonikerImpl *This = (URLMonikerImpl *)iface;
1018 TRACE("(%p,%p)\n",This,pwdMksys);
1021 return E_INVALIDARG;
1023 *pwdMksys = MKSYS_URLMONIKER;
1027 /********************************************************************************/
1028 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
1029 /* IPersistStream and IMoniker functions. */
1030 static const IMonikerVtbl VT_URLMonikerImpl =
1032 URLMonikerImpl_QueryInterface,
1033 URLMonikerImpl_AddRef,
1034 URLMonikerImpl_Release,
1035 URLMonikerImpl_GetClassID,
1036 URLMonikerImpl_IsDirty,
1037 URLMonikerImpl_Load,
1038 URLMonikerImpl_Save,
1039 URLMonikerImpl_GetSizeMax,
1040 URLMonikerImpl_BindToObject,
1041 URLMonikerImpl_BindToStorage,
1042 URLMonikerImpl_Reduce,
1043 URLMonikerImpl_ComposeWith,
1044 URLMonikerImpl_Enum,
1045 URLMonikerImpl_IsEqual,
1046 URLMonikerImpl_Hash,
1047 URLMonikerImpl_IsRunning,
1048 URLMonikerImpl_GetTimeOfLastChange,
1049 URLMonikerImpl_Inverse,
1050 URLMonikerImpl_CommonPrefixWith,
1051 URLMonikerImpl_RelativePathTo,
1052 URLMonikerImpl_GetDisplayName,
1053 URLMonikerImpl_ParseDisplayName,
1054 URLMonikerImpl_IsSystemMoniker
1057 /******************************************************************************
1058 * URLMoniker_Construct (local function)
1059 *******************************************************************************/
1060 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
1065 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
1067 This->lpvtbl = &VT_URLMonikerImpl;
1070 This->URLName = HeapAlloc(GetProcessHeap(), 0, INTERNET_MAX_URL_LENGTH*sizeof(WCHAR));
1073 hres = CoInternetCombineUrl(lpszLeftURLName, lpszURLName, URL_FILE_USE_PATHURL,
1074 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
1076 hres = CoInternetParseUrl(lpszURLName, PARSE_CANONICALIZE, URL_FILE_USE_PATHURL,
1077 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
1080 HeapFree(GetProcessHeap(), 0, This->URLName);
1084 URLMON_LockModule();
1086 if(sizeStr != INTERNET_MAX_URL_LENGTH)
1087 This->URLName = HeapReAlloc(GetProcessHeap(), 0, This->URLName, (sizeStr+1)*sizeof(WCHAR));
1089 TRACE("URLName = %s\n", debugstr_w(This->URLName));
1094 /***********************************************************************
1095 * CreateAsyncBindCtx (URLMON.@)
1097 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
1098 IEnumFORMATETC *format, IBindCtx **pbind)
1100 TRACE("(%08x %p %p %p)\n", reserved, callback, format, pbind);
1103 return E_INVALIDARG;
1105 return CreateAsyncBindCtxEx(NULL, 0, callback, format, pbind, 0);
1107 /***********************************************************************
1108 * CreateAsyncBindCtxEx (URLMON.@)
1110 * Create an asynchronous bind context.
1112 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
1113 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
1120 TRACE("(%p %08x %p %p %p %d)\n", ibind, options, callback, format, pbind, reserved);
1123 return E_INVALIDARG;
1126 FIXME("not supported options %08x\n", options);
1128 FIXME("format is not supported\n");
1131 WARN("reserved=%d\n", reserved);
1133 hres = CreateBindCtx(0, &bctx);
1137 bindopts.cbStruct = sizeof(BIND_OPTS);
1138 bindopts.grfFlags = BIND_MAYBOTHERUSER;
1139 bindopts.grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
1140 bindopts.dwTickCountDeadline = 0;
1141 IBindCtx_SetBindOptions(bctx, &bindopts);
1144 RegisterBindStatusCallback(bctx, callback, NULL, 0);
1152 /***********************************************************************
1153 * CreateURLMoniker (URLMON.@)
1155 * Create a url moniker.
1158 * pmkContext [I] Context
1159 * szURL [I] Url to create the moniker for
1160 * ppmk [O] Destination for created moniker.
1163 * Success: S_OK. ppmk contains the created IMoniker object.
1164 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1165 * E_OUTOFMEMORY if memory allocation fails.
1167 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
1169 URLMonikerImpl *obj;
1171 IID iid = IID_IMoniker;
1172 LPOLESTR lefturl = NULL;
1174 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
1176 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
1177 return E_OUTOFMEMORY;
1182 IMoniker_IsSystemMoniker(pmkContext, &dwMksys);
1183 if(dwMksys == MKSYS_URLMONIKER && SUCCEEDED(CreateBindCtx(0, &bind))) {
1184 IMoniker_GetDisplayName(pmkContext, bind, NULL, &lefturl);
1185 TRACE("lefturl = %s\n", debugstr_w(lefturl));
1186 IBindCtx_Release(bind);
1190 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
1191 CoTaskMemFree(lefturl);
1193 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
1195 HeapFree(GetProcessHeap(), 0, obj);
1199 /***********************************************************************
1200 * CoInternetQueryInfo (URLMON.@)
1202 * Retrieves information relevant to a specified URL
1206 * S_FALSE buffer too small
1207 * INET_E_QUERYOPTIONUNKNOWN invalid option
1210 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1211 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1214 FIXME("(%s, %x, %x, %p, %x, %p, %x): stub\n", debugstr_w(pwzUrl),
1215 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1219 /***********************************************************************
1220 * IsAsyncMoniker (URLMON.@)
1222 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1226 TRACE("(%p)\n", pmk);
1228 return E_INVALIDARG;
1229 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1230 IUnknown_Release(am);
1236 /***********************************************************************
1237 * BindAsyncMoniker (URLMON.@)
1239 * Bind a bind status callback to an asynchronous URL Moniker.
1242 * pmk [I] Moniker object to bind status callback to
1243 * grfOpt [I] Options, seems not used
1244 * pbsc [I] Status callback to bind
1245 * iidResult [I] Interface to return
1246 * ppvResult [O] Resulting asynchronous moniker object
1250 * Failure: E_INVALIDARG, if any argument is invalid, or
1251 * E_OUTOFMEMORY if memory allocation fails.
1253 HRESULT WINAPI BindAsyncMoniker(IMoniker *pmk, DWORD grfOpt, IBindStatusCallback *pbsc, REFIID iidResult, LPVOID *ppvResult)
1256 HRESULT hr = E_INVALIDARG;
1258 if (pmk && ppvResult)
1262 hr = CreateAsyncBindCtx(0, pbsc, NULL, &pbc);
1265 hr = IMoniker_BindToObject(pmk, pbc, NULL, iidResult, ppvResult);
1266 IBindCtx_Release(pbc);
1272 /***********************************************************************
1273 * RegisterBindStatusCallback (URLMON.@)
1275 * Register a bind status callback.
1278 * pbc [I] Binding context
1279 * pbsc [I] Callback to register
1280 * ppbscPrevious [O] Destination for previous callback
1281 * dwReserved [I] Reserved, must be 0.
1285 * Failure: E_INVALIDARG, if any argument is invalid, or
1286 * E_OUTOFMEMORY if memory allocation fails.
1288 HRESULT WINAPI RegisterBindStatusCallback(
1290 IBindStatusCallback *pbsc,
1291 IBindStatusCallback **ppbscPrevious,
1294 IBindStatusCallback *prev;
1296 TRACE("(%p,%p,%p,%u)\n", pbc, pbsc, ppbscPrevious, dwReserved);
1298 if (pbc == NULL || pbsc == NULL)
1299 return E_INVALIDARG;
1301 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
1303 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1305 *ppbscPrevious = prev;
1307 IBindStatusCallback_Release(prev);
1310 return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
1313 /***********************************************************************
1314 * RevokeBindStatusCallback (URLMON.@)
1316 * Unregister a bind status callback.
1318 * pbc [I] Binding context
1319 * pbsc [I] Callback to unregister
1323 * Failure: E_INVALIDARG, if any argument is invalid, or
1324 * E_FAIL if pbsc wasn't registered with pbc.
1326 HRESULT WINAPI RevokeBindStatusCallback(
1328 IBindStatusCallback *pbsc)
1330 IBindStatusCallback *callback;
1331 HRESULT hr = E_FAIL;
1333 TRACE("(%p,%p)\n", pbc, pbsc);
1335 if (pbc == NULL || pbsc == NULL)
1336 return E_INVALIDARG;
1338 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
1340 if (callback == pbsc)
1342 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1345 IBindStatusCallback_Release(pbsc);
1351 /***********************************************************************
1352 * URLDownloadToFileA (URLMON.@)
1354 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1358 * pCaller [I] controlling IUnknown interface.
1359 * szURL [I] URL of the file to download
1360 * szFileName [I] file name to store the content of the URL
1361 * dwReserved [I] reserved - set to 0
1362 * lpfnCB [I] callback for progress report
1366 * E_OUTOFMEMORY when going out of memory
1368 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1372 LPBINDSTATUSCALLBACK lpfnCB)
1374 UNICODE_STRING szURL_w, szFileName_w;
1376 if ((szURL == NULL) || (szFileName == NULL)) {
1377 FIXME("(%p,%s,%s,%08x,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1378 return E_INVALIDARG; /* The error code is not specified in this case... */
1381 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1382 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1383 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1385 RtlFreeUnicodeString(&szURL_w);
1386 RtlFreeUnicodeString(&szFileName_w);
1390 RtlFreeUnicodeString(&szURL_w);
1394 FIXME("(%p,%s,%s,%08x,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1395 return E_OUTOFMEMORY;
1398 /***********************************************************************
1399 * URLDownloadToFileW (URLMON.@)
1401 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1405 * pCaller [I] controlling IUnknown interface.
1406 * szURL [I] URL of the file to download
1407 * szFileName [I] file name to store the content of the URL
1408 * dwReserved [I] reserved - set to 0
1409 * lpfnCB [I] callback for progress report
1413 * E_OUTOFMEMORY when going out of memory
1415 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1419 LPBINDSTATUSCALLBACK lpfnCB)
1421 HINTERNET hinternet, hcon, hreq;
1423 CHAR buffer[0x1000];
1424 DWORD sz, total, written;
1425 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1426 URL_COMPONENTSW url;
1427 WCHAR host[0x80], path[0x100];
1429 static const WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1431 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1432 TRACE("(%p,%s,%s,%08x,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1434 if ((szURL == NULL) || (szFileName == NULL)) {
1435 FIXME(" cannot accept NULL strings !\n");
1436 return E_INVALIDARG;
1439 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1440 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1441 if (hinternet == NULL) {
1442 return E_OUTOFMEMORY;
1445 memset(&url, 0, sizeof(url));
1446 url.dwStructSize = sizeof(url);
1447 url.lpszHostName = host;
1448 url.dwHostNameLength = sizeof(host);
1449 url.lpszUrlPath = path;
1450 url.dwUrlPathLength = sizeof(path);
1452 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1453 InternetCloseHandle(hinternet);
1454 return E_OUTOFMEMORY;
1458 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1459 InternetCloseHandle(hinternet);
1464 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1465 url.lpszUserName, url.lpszPassword,
1466 INTERNET_SERVICE_HTTP, 0, 0);
1468 InternetCloseHandle(hinternet);
1469 return E_OUTOFMEMORY;
1472 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1474 InternetCloseHandle(hinternet);
1475 InternetCloseHandle(hcon);
1476 return E_OUTOFMEMORY;
1479 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1480 InternetCloseHandle(hinternet);
1481 InternetCloseHandle(hcon);
1482 InternetCloseHandle(hreq);
1483 return E_OUTOFMEMORY;
1486 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1487 &total_size, &arg_size, NULL)) {
1488 TRACE(" total size : %d\n", total_size);
1491 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1492 FILE_ATTRIBUTE_NORMAL, NULL );
1493 if (hfile == INVALID_HANDLE_VALUE) {
1494 return E_ACCESSDENIED;
1498 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1499 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1500 InternetCloseHandle(hreq);
1501 InternetCloseHandle(hcon);
1502 InternetCloseHandle(hinternet);
1510 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1512 InternetCloseHandle(hreq);
1513 InternetCloseHandle(hcon);
1514 InternetCloseHandle(hinternet);
1517 return E_OUTOFMEMORY;
1525 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1526 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1527 InternetCloseHandle(hreq);
1528 InternetCloseHandle(hcon);
1529 InternetCloseHandle(hinternet);
1535 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1536 InternetCloseHandle(hreq);
1537 InternetCloseHandle(hcon);
1538 InternetCloseHandle(hinternet);
1541 return E_OUTOFMEMORY;
1546 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1547 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1548 InternetCloseHandle(hreq);
1549 InternetCloseHandle(hcon);
1550 InternetCloseHandle(hinternet);
1556 InternetCloseHandle(hreq);
1557 InternetCloseHandle(hcon);
1558 InternetCloseHandle(hinternet);
1565 /***********************************************************************
1566 * URLDownloadToCacheFileA (URLMON.@)
1568 HRESULT WINAPI URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller, LPCSTR szURL, LPSTR szFileName,
1569 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
1571 LPWSTR url = NULL, file_name = NULL;
1575 TRACE("(%p %s %p %d %d %p)\n", lpUnkCaller, debugstr_a(szURL), szFileName,
1576 dwBufLength, dwReserved, pBSC);
1579 len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
1580 url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1581 MultiByteToWideChar(CP_ACP, 0, szURL, -1, url, -1);
1585 file_name = HeapAlloc(GetProcessHeap(), 0, dwBufLength*sizeof(WCHAR));
1587 hres = URLDownloadToCacheFileW(lpUnkCaller, url, file_name, dwBufLength*sizeof(WCHAR),
1590 if(SUCCEEDED(hres) && file_name)
1591 WideCharToMultiByte(CP_ACP, 0, file_name, -1, szFileName, dwBufLength, NULL, NULL);
1593 HeapFree(GetProcessHeap(), 0, url);
1594 HeapFree(GetProcessHeap(), 0, file_name);
1599 /***********************************************************************
1600 * URLDownloadToCacheFileW (URLMON.@)
1602 HRESULT WINAPI URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller, LPCWSTR szURL, LPWSTR szFileName,
1603 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
1605 WCHAR cache_path[MAX_PATH + 1];
1606 FILETIME expire, modified;
1610 static const WCHAR header[] = {
1611 'H','T','T','P','/','1','.','0',' ','2','0','0',' ',
1612 'O','K','\\','r','\\','n','\\','r','\\','n',0
1615 TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller, debugstr_w(szURL),
1616 szFileName, dwBufLength, dwReserved, pBSC);
1618 if (!szURL || !szFileName)
1619 return E_INVALIDARG;
1621 ext = PathFindExtensionW(szURL);
1623 if (!CreateUrlCacheEntryW(szURL, 0, ext, cache_path, 0))
1626 hr = URLDownloadToFileW(lpUnkCaller, szURL, cache_path, 0, pBSC);
1630 expire.dwHighDateTime = 0;
1631 expire.dwLowDateTime = 0;
1632 modified.dwHighDateTime = 0;
1633 modified.dwLowDateTime = 0;
1635 if (!CommitUrlCacheEntryW(szURL, cache_path, expire, modified, NORMAL_CACHE_ENTRY,
1636 (LPWSTR)header, sizeof(header), NULL, NULL))
1639 if (lstrlenW(cache_path) > dwBufLength)
1640 return E_OUTOFMEMORY;
1642 lstrcpyW(szFileName, cache_path);
1647 /***********************************************************************
1648 * HlinkSimpleNavigateToString (URLMON.@)
1650 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
1651 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1652 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1654 FIXME("%s\n", debugstr_w( szTarget ) );
1658 /***********************************************************************
1659 * HlinkNavigateString (URLMON.@)
1661 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
1663 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
1664 return HlinkSimpleNavigateToString(
1665 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );
1668 /***********************************************************************
1669 * GetSoftwareUpdateInfo (URLMON.@)
1671 HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi )
1673 FIXME("%s %p\n", debugstr_w(szDistUnit), psdi );