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
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 WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
49 /*static BOOL registered_wndclass = FALSE;*/
52 const IBindingVtbl *lpVtbl;
60 HINTERNET hinternet, hconnect, hrequest;
62 IUMCacheStream *pstrCache;
63 IBindStatusCallback *pbscb;
64 DWORD total_read, expected_size;
67 static HRESULT WINAPI Binding_QueryInterface(IBinding* iface, REFIID riid, void **ppvObject)
69 Binding *This = (Binding*)iface;
71 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
73 if((This == NULL) || (ppvObject == NULL))
76 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid)) {
78 IBinding_AddRef(iface);
86 static ULONG WINAPI Binding_AddRef(IBinding* iface)
88 Binding *This = (Binding*)iface;
89 ULONG ref = InterlockedIncrement(&This->ref);
91 TRACE("(%p) ref=%d\n", This, ref);
96 static ULONG WINAPI Binding_Release(IBinding* iface)
98 Binding *This = (Binding*)iface;
99 ULONG ref = InterlockedDecrement(&This->ref);
101 TRACE("(%p) ref=%d\n",This, ref);
104 HeapFree(GetProcessHeap(), 0, This->URLName);
105 if (This->hCacheFile)
106 CloseHandle(This->hCacheFile);
109 UMCloseCacheFileStream(This->pstrCache);
110 IStream_Release((IStream *)This->pstrCache);
113 IBindStatusCallback_Release(This->pbscb);
115 HeapFree(GetProcessHeap(), 0, This);
117 URLMON_UnlockModule();
123 static HRESULT WINAPI Binding_Abort(IBinding* iface)
125 Binding *This = (Binding*)iface;
127 FIXME("(%p): stub\n", This);
132 static HRESULT WINAPI Binding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
134 Binding *This = (Binding*)iface;
136 FIXME("(%p)->(%p, %p, %p, %p): stub\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
141 static HRESULT WINAPI Binding_GetPriority(IBinding* iface, LONG* pnPriority)
143 Binding *This = (Binding*)iface;
145 FIXME("(%p)->(%p): stub\n", This, pnPriority);
150 static HRESULT WINAPI Binding_Resume(IBinding* iface)
152 Binding *This = (Binding*)iface;
154 FIXME("(%p): stub\n", This);
159 static HRESULT WINAPI Binding_SetPriority(IBinding* iface, LONG nPriority)
161 Binding *This = (Binding*)iface;
163 FIXME("(%p)->(%d): stub\n", This, nPriority);
168 static HRESULT WINAPI Binding_Suspend(IBinding* iface)
170 Binding *This = (Binding*)iface;
172 FIXME("(%p): stub\n", This);
177 static void Binding_CloseCacheDownload(Binding *This)
179 CloseHandle(This->hCacheFile);
180 This->hCacheFile = 0;
181 UMCloseCacheFileStream(This->pstrCache);
182 IStream_Release((IStream *)This->pstrCache);
186 static HRESULT Binding_MoreCacheData(Binding *This, const char *buf, DWORD dwBytes)
190 if (WriteFile(This->hCacheFile, buf, dwBytes, &written, NULL) && written == dwBytes)
194 This->total_read += written;
195 hr = IBindStatusCallback_OnProgress(This->pbscb,
196 This->total_read + written,
198 (This->total_read == written) ?
199 BINDSTATUS_BEGINDOWNLOADDATA :
200 BINDSTATUS_DOWNLOADINGDATA,
211 fmt.tymed = TYMED_ISTREAM;
213 stg.tymed = TYMED_ISTREAM;
214 stg.u.pstm = (IStream *)This->pstrCache;
215 stg.pUnkForRelease = NULL;
217 hr = IBindStatusCallback_OnDataAvailable(This->pbscb,
218 (This->total_read == written) ?
219 BSCF_FIRSTDATANOTIFICATION :
220 BSCF_INTERMEDIATEDATANOTIFICATION,
221 This->total_read + written,
225 if (written < dwBytes)
226 return STG_E_MEDIUMFULL;
230 return HRESULT_FROM_WIN32(GetLastError());
233 static void Binding_FinishedDownload(Binding *This, HRESULT hr)
241 fmt.tymed = TYMED_ISTREAM;
243 stg.tymed = TYMED_ISTREAM;
244 stg.u.pstm = (IStream *)This->pstrCache;
245 stg.pUnkForRelease = NULL;
247 IBindStatusCallback_OnProgress(This->pbscb, This->total_read, This->expected_size,
248 BINDSTATUS_ENDDOWNLOADDATA, This->URLName);
249 IBindStatusCallback_OnDataAvailable(This->pbscb, BSCF_LASTDATANOTIFICATION, This->total_read, &fmt, &stg);
252 WCHAR *pwchError = 0;
254 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
255 FORMAT_MESSAGE_ALLOCATE_BUFFER,
257 0, (LPWSTR) &pwchError,
261 static const WCHAR achFormat[] = { '%', '0', '8', 'x', 0 };
263 pwchError =(WCHAR *) LocalAlloc(LMEM_FIXED, sizeof(WCHAR) * 9);
264 wsprintfW(pwchError, achFormat, hr);
266 IBindStatusCallback_OnStopBinding(This->pbscb, hr, pwchError);
267 LocalFree(pwchError);
271 IBindStatusCallback_OnStopBinding(This->pbscb, hr, NULL);
273 IBindStatusCallback_Release(This->pbscb);
277 static const IBindingVtbl BindingVtbl =
279 Binding_QueryInterface,
287 Binding_GetBindResult
290 /* filemoniker data structure */
293 const IMonikerVtbl* lpvtbl; /* VTable relative to the IMoniker interface.*/
295 LONG ref; /* reference counter for this object */
297 LPOLESTR URLName; /* URL string identified by this URLmoniker */
300 /*******************************************************************************
301 * URLMoniker_QueryInterface
302 *******************************************************************************/
303 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
305 URLMonikerImpl *This = (URLMonikerImpl *)iface;
307 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
309 /* Perform a sanity check on the parameters.*/
310 if ( (This==0) || (ppvObject==0) )
313 /* Initialize the return parameter */
316 /* Compare the riid with the interface IDs implemented by this object.*/
317 if (IsEqualIID(&IID_IUnknown, riid) ||
318 IsEqualIID(&IID_IPersist, riid) ||
319 IsEqualIID(&IID_IPersistStream,riid) ||
320 IsEqualIID(&IID_IMoniker, riid)
324 /* Check that we obtained an interface.*/
326 return E_NOINTERFACE;
328 /* Query Interface always increases the reference count by one when it is successful */
329 IMoniker_AddRef(iface);
334 /******************************************************************************
336 ******************************************************************************/
337 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
339 URLMonikerImpl *This = (URLMonikerImpl *)iface;
340 ULONG refCount = InterlockedIncrement(&This->ref);
342 TRACE("(%p) ref=%u\n",This, refCount);
347 /******************************************************************************
349 ******************************************************************************/
350 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
352 URLMonikerImpl *This = (URLMonikerImpl *)iface;
353 ULONG refCount = InterlockedDecrement(&This->ref);
355 TRACE("(%p) ref=%u\n",This, refCount);
357 /* destroy the object if there's no more reference on it */
359 HeapFree(GetProcessHeap(),0,This->URLName);
360 HeapFree(GetProcessHeap(),0,This);
362 URLMON_UnlockModule();
369 /******************************************************************************
370 * URLMoniker_GetClassID
371 ******************************************************************************/
372 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
373 CLSID *pClassID)/* Pointer to CLSID of object */
375 URLMonikerImpl *This = (URLMonikerImpl *)iface;
377 TRACE("(%p,%p)\n",This,pClassID);
381 /* Windows always returns CLSID_StdURLMoniker */
382 *pClassID = CLSID_StdURLMoniker;
386 /******************************************************************************
388 ******************************************************************************/
389 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
391 URLMonikerImpl *This = (URLMonikerImpl *)iface;
392 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
393 method in the OLE-provided moniker interfaces always return S_FALSE because
394 their internal state never changes. */
396 TRACE("(%p)\n",This);
401 /******************************************************************************
405 * Writes a ULONG containing length of unicode string, followed
406 * by that many unicode characters
407 ******************************************************************************/
408 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
410 URLMonikerImpl *This = (URLMonikerImpl *)iface;
415 TRACE("(%p,%p)\n",This,pStm);
420 res = IStream_Read(pStm, &size, sizeof(ULONG), &got);
422 if(got == sizeof(ULONG)) {
423 HeapFree(GetProcessHeap(), 0, This->URLName);
424 This->URLName=HeapAlloc(GetProcessHeap(),0,size);
428 res = IStream_Read(pStm, This->URLName, size, NULL);
429 This->URLName[size/sizeof(WCHAR) - 1] = 0;
438 /******************************************************************************
440 ******************************************************************************/
441 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
442 IStream* pStm,/* pointer to the stream where the object is to be saved */
443 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
445 URLMonikerImpl *This = (URLMonikerImpl *)iface;
449 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
454 size = (strlenW(This->URLName) + 1)*sizeof(WCHAR);
455 res=IStream_Write(pStm,&size,sizeof(ULONG),NULL);
457 res=IStream_Write(pStm,This->URLName,size,NULL);
462 /******************************************************************************
463 * URLMoniker_GetSizeMax
464 ******************************************************************************/
465 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
466 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
468 URLMonikerImpl *This = (URLMonikerImpl *)iface;
470 TRACE("(%p,%p)\n",This,pcbSize);
475 pcbSize->QuadPart = sizeof(ULONG) + ((strlenW(This->URLName)+1) * sizeof(WCHAR));
479 /******************************************************************************
480 * URLMoniker_BindToObject
481 ******************************************************************************/
482 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
488 URLMonikerImpl *This = (URLMonikerImpl *)iface;
492 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
498 /******************************************************************************
499 * URLMoniker_BindToStorage
500 ******************************************************************************/
501 static HRESULT URLMonikerImpl_BindToStorage_hack(LPCWSTR URLName,
509 WCHAR szFileName[MAX_PATH + 1];
513 WARN("(%s %p %s %p)\n", debugstr_w(URLName), pbc, debugstr_guid(riid), ppvObject);
515 if(!IsEqualIID(&IID_IStream, riid)) {
516 FIXME("unsupported iid\n");
520 bind = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Binding));
521 bind->lpVtbl = &BindingVtbl;
525 len = lstrlenW(URLName)+1;
526 bind->URLName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
527 memcpy(bind->URLName, URLName, len*sizeof(WCHAR));
529 hres = UMCreateStreamOnCacheFile(bind->URLName, 0, szFileName, &bind->hCacheFile, &bind->pstrCache);
531 if(SUCCEEDED(hres)) {
532 TRACE("Created stream...\n");
534 *ppvObject = (void *) bind->pstrCache;
535 IStream_AddRef((IStream *) bind->pstrCache);
537 hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&bind->pbscb);
538 if(SUCCEEDED(hres)) {
539 TRACE("Got IBindStatusCallback...\n");
541 memset(&bi, 0, sizeof(bi));
542 bi.cbSize = sizeof(bi);
544 hres = IBindStatusCallback_GetBindInfo(bind->pbscb, &bindf, &bi);
545 if(SUCCEEDED(hres)) {
547 WCHAR *host, *path, *user, *pass;
548 DWORD lensz = sizeof(bind->expected_size);
552 TRACE("got bindinfo. bindf = %08x extrainfo = %s bindinfof = %08x bindverb = %08x iid %s\n",
553 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
554 hres = IBindStatusCallback_OnStartBinding(bind->pbscb, 0, (IBinding*)bind);
555 TRACE("OnStartBinding rets %08x\n", hres);
557 bind->expected_size = 0;
558 bind->total_read = 0;
560 memset(&url, 0, sizeof(url));
561 url.dwStructSize = sizeof(url);
562 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = url.dwUserNameLength = url.dwPasswordLength = 1;
563 InternetCrackUrlW(URLName, 0, ICU_ESCAPE, &url);
564 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
565 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
566 host[url.dwHostNameLength] = '\0';
567 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
568 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
569 path[url.dwUrlPathLength] = '\0';
570 if (url.dwUserNameLength)
572 user = HeapAlloc(GetProcessHeap(), 0, ((url.dwUserNameLength + 1) * sizeof(WCHAR)));
573 memcpy(user, url.lpszUserName, url.dwUserNameLength * sizeof(WCHAR));
574 user[url.dwUserNameLength] = 0;
580 if (url.dwPasswordLength)
582 pass = HeapAlloc(GetProcessHeap(), 0, ((url.dwPasswordLength + 1) * sizeof(WCHAR)));
583 memcpy(pass, url.lpszPassword, url.dwPasswordLength * sizeof(WCHAR));
584 pass[url.dwPasswordLength] = 0;
593 bind->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0);
594 if (!bind->hinternet)
596 hres = HRESULT_FROM_WIN32(GetLastError());
600 switch ((DWORD) url.nScheme)
602 case INTERNET_SCHEME_FTP:
604 url.nPort = INTERNET_DEFAULT_FTP_PORT;
605 dwService = INTERNET_SERVICE_FTP;
608 case INTERNET_SCHEME_GOPHER:
610 url.nPort = INTERNET_DEFAULT_GOPHER_PORT;
611 dwService = INTERNET_SERVICE_GOPHER;
614 case INTERNET_SCHEME_HTTPS:
616 url.nPort = INTERNET_DEFAULT_HTTPS_PORT;
617 dwService = INTERNET_SERVICE_HTTP;
621 bind->hconnect = InternetConnectW(bind->hinternet, host, url.nPort, user, pass,
622 dwService, 0, (DWORD)bind);
625 hres = HRESULT_FROM_WIN32(GetLastError());
626 CloseHandle(bind->hinternet);
630 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, 0x22, NULL);
631 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
632 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
633 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
639 case INTERNET_SERVICE_GOPHER:
640 bind->hrequest = GopherOpenFileW(bind->hconnect,
643 INTERNET_FLAG_RELOAD,
648 hres = HRESULT_FROM_WIN32(GetLastError());
651 case INTERNET_SERVICE_FTP:
652 bind->hrequest = FtpOpenFileW(bind->hconnect,
655 FTP_TRANSFER_TYPE_BINARY |
656 INTERNET_FLAG_TRANSFER_BINARY |
657 INTERNET_FLAG_RELOAD,
662 hres = HRESULT_FROM_WIN32(GetLastError());
665 case INTERNET_SERVICE_HTTP:
666 bind->hrequest = HttpOpenRequestW(bind->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)bind);
669 hres = HRESULT_FROM_WIN32(GetLastError());
671 else if (!HttpSendRequestW(bind->hrequest, NULL, 0, NULL, 0))
673 hres = HRESULT_FROM_WIN32(GetLastError());
674 InternetCloseHandle(bind->hrequest);
678 HttpQueryInfoW(bind->hrequest,
679 HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
680 &bind->expected_size,
689 TRACE("res = %d gle = %u url len = %d\n", hres, GetLastError(), bind->expected_size);
691 IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE, szFileName);
696 if(InternetReadFile(bind->hrequest, buf, sizeof(buf), &bufread)) {
697 TRACE("read %d bytes %s...\n", bufread, debugstr_an(buf, 10));
698 if(bufread == 0) break;
699 hres = Binding_MoreCacheData(bind, buf, bufread);
703 InternetCloseHandle(bind->hrequest);
707 InternetCloseHandle(bind->hconnect);
708 InternetCloseHandle(bind->hinternet);
711 Binding_FinishedDownload(bind, hres);
712 Binding_CloseCacheDownload(bind);
714 HeapFree(GetProcessHeap(), 0, user);
715 HeapFree(GetProcessHeap(), 0, pass);
716 HeapFree(GetProcessHeap(), 0, path);
717 HeapFree(GetProcessHeap(), 0, host);
722 IBinding_Release((IBinding*)bind);
727 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
733 URLMonikerImpl *This = (URLMonikerImpl*)iface;
737 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW), schema,
738 sizeof(schema)/sizeof(WCHAR), 0, NULL, 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0};
741 FIXME("Unsupported pmkToLeft\n");
743 bret = InternetCrackUrlW(This->URLName, 0, ICU_ESCAPE, &url);
745 ERR("InternetCrackUrl failed: %u\n", GetLastError());
749 if(url.nScheme== INTERNET_SCHEME_HTTPS
750 || url.nScheme== INTERNET_SCHEME_FTP
751 || url.nScheme == INTERNET_SCHEME_GOPHER)
752 return URLMonikerImpl_BindToStorage_hack(This->URLName, pbc, riid, ppvObject);
754 TRACE("(%p)->(%p %p %s %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObject);
756 return start_binding(This->URLName, pbc, riid, ppvObject);
759 /******************************************************************************
761 ******************************************************************************/
762 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
764 DWORD dwReduceHowFar,
765 IMoniker** ppmkToLeft,
766 IMoniker** ppmkReduced)
768 URLMonikerImpl *This = (URLMonikerImpl *)iface;
770 TRACE("(%p,%p,%d,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
775 URLMonikerImpl_AddRef(iface);
776 *ppmkReduced = iface;
777 return MK_S_REDUCED_TO_SELF;
780 /******************************************************************************
781 * URLMoniker_ComposeWith
782 ******************************************************************************/
783 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
785 BOOL fOnlyIfNotGeneric,
786 IMoniker** ppmkComposite)
788 URLMonikerImpl *This = (URLMonikerImpl *)iface;
789 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
794 /******************************************************************************
796 ******************************************************************************/
797 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
799 URLMonikerImpl *This = (URLMonikerImpl *)iface;
800 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
805 /* Does not support sub-monikers */
806 *ppenumMoniker = NULL;
810 /******************************************************************************
812 ******************************************************************************/
813 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
815 URLMonikerImpl *This = (URLMonikerImpl *)iface;
821 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
823 if(pmkOtherMoniker==NULL)
826 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
828 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
831 res = CreateBindCtx(0,&bind);
836 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
837 int result = lstrcmpiW(urlPath, This->URLName);
838 CoTaskMemFree(urlPath);
842 IUnknown_Release(bind);
847 /******************************************************************************
849 ******************************************************************************/
850 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
852 URLMonikerImpl *This = (URLMonikerImpl *)iface;
854 int h = 0,i,skip,len;
858 TRACE("(%p,%p)\n",This,pdwHash);
867 for(i = len ; i > 0; i--) {
868 h = (h * 37) + val[off++];
872 /* only sample some characters */
874 for(i = len; i > 0; i -= skip, off += skip) {
875 h = (h * 39) + val[off];
882 /******************************************************************************
883 * URLMoniker_IsRunning
884 ******************************************************************************/
885 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
888 IMoniker* pmkNewlyRunning)
890 URLMonikerImpl *This = (URLMonikerImpl *)iface;
891 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
896 /******************************************************************************
897 * URLMoniker_GetTimeOfLastChange
898 ******************************************************************************/
899 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
904 URLMonikerImpl *This = (URLMonikerImpl *)iface;
905 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
910 /******************************************************************************
912 ******************************************************************************/
913 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
915 URLMonikerImpl *This = (URLMonikerImpl *)iface;
916 TRACE("(%p,%p)\n",This,ppmk);
918 return MK_E_NOINVERSE;
921 /******************************************************************************
922 * URLMoniker_CommonPrefixWith
923 ******************************************************************************/
924 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
926 URLMonikerImpl *This = (URLMonikerImpl *)iface;
927 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
932 /******************************************************************************
933 * URLMoniker_RelativePathTo
934 ******************************************************************************/
935 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
937 URLMonikerImpl *This = (URLMonikerImpl *)iface;
938 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
943 /******************************************************************************
944 * URLMoniker_GetDisplayName
945 ******************************************************************************/
946 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
949 LPOLESTR *ppszDisplayName)
951 URLMonikerImpl *This = (URLMonikerImpl *)iface;
955 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
960 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
961 then look at pmkToLeft to try and complete the URL
963 len = lstrlenW(This->URLName)+1;
964 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
965 if(!*ppszDisplayName)
966 return E_OUTOFMEMORY;
967 lstrcpyW(*ppszDisplayName, This->URLName);
971 /******************************************************************************
972 * URLMoniker_ParseDisplayName
973 ******************************************************************************/
974 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
977 LPOLESTR pszDisplayName,
981 URLMonikerImpl *This = (URLMonikerImpl *)iface;
982 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
987 /******************************************************************************
988 * URLMoniker_IsSystemMoniker
989 ******************************************************************************/
990 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
992 URLMonikerImpl *This = (URLMonikerImpl *)iface;
993 TRACE("(%p,%p)\n",This,pwdMksys);
998 *pwdMksys = MKSYS_URLMONIKER;
1002 /********************************************************************************/
1003 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
1004 /* IPersistStream and IMoniker functions. */
1005 static const IMonikerVtbl VT_URLMonikerImpl =
1007 URLMonikerImpl_QueryInterface,
1008 URLMonikerImpl_AddRef,
1009 URLMonikerImpl_Release,
1010 URLMonikerImpl_GetClassID,
1011 URLMonikerImpl_IsDirty,
1012 URLMonikerImpl_Load,
1013 URLMonikerImpl_Save,
1014 URLMonikerImpl_GetSizeMax,
1015 URLMonikerImpl_BindToObject,
1016 URLMonikerImpl_BindToStorage,
1017 URLMonikerImpl_Reduce,
1018 URLMonikerImpl_ComposeWith,
1019 URLMonikerImpl_Enum,
1020 URLMonikerImpl_IsEqual,
1021 URLMonikerImpl_Hash,
1022 URLMonikerImpl_IsRunning,
1023 URLMonikerImpl_GetTimeOfLastChange,
1024 URLMonikerImpl_Inverse,
1025 URLMonikerImpl_CommonPrefixWith,
1026 URLMonikerImpl_RelativePathTo,
1027 URLMonikerImpl_GetDisplayName,
1028 URLMonikerImpl_ParseDisplayName,
1029 URLMonikerImpl_IsSystemMoniker
1032 /******************************************************************************
1033 * URLMoniker_Construct (local function)
1034 *******************************************************************************/
1035 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
1040 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
1042 This->lpvtbl = &VT_URLMonikerImpl;
1045 This->URLName = HeapAlloc(GetProcessHeap(), 0, INTERNET_MAX_URL_LENGTH*sizeof(WCHAR));
1048 hres = CoInternetCombineUrl(lpszLeftURLName, lpszURLName, URL_FILE_USE_PATHURL,
1049 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
1051 hres = CoInternetParseUrl(lpszURLName, PARSE_CANONICALIZE, URL_FILE_USE_PATHURL,
1052 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
1055 HeapFree(GetProcessHeap(), 0, This->URLName);
1059 URLMON_LockModule();
1061 if(sizeStr != INTERNET_MAX_URL_LENGTH)
1062 This->URLName = HeapReAlloc(GetProcessHeap(), 0, This->URLName, (sizeStr+1)*sizeof(WCHAR));
1064 TRACE("URLName = %s\n", debugstr_w(This->URLName));
1069 /***********************************************************************
1070 * CreateURLMonikerEx (URLMON.@)
1072 * Create a url moniker.
1075 * pmkContext [I] Context
1076 * szURL [I] Url to create the moniker for
1077 * ppmk [O] Destination for created moniker.
1078 * dwFlags [I] Flags.
1081 * Success: S_OK. ppmk contains the created IMoniker object.
1082 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1083 * E_OUTOFMEMORY if memory allocation fails.
1085 HRESULT WINAPI CreateURLMonikerEx(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk, DWORD dwFlags)
1087 URLMonikerImpl *obj;
1089 LPOLESTR lefturl = NULL;
1091 TRACE("(%p, %s, %p, %08x)\n", pmkContext, debugstr_w(szURL), ppmk, dwFlags);
1093 if (dwFlags & URL_MK_UNIFORM) FIXME("ignoring flag URL_MK_UNIFORM\n");
1095 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
1096 return E_OUTOFMEMORY;
1101 IMoniker_IsSystemMoniker(pmkContext, &dwMksys);
1102 if(dwMksys == MKSYS_URLMONIKER && SUCCEEDED(CreateBindCtx(0, &bind))) {
1103 IMoniker_GetDisplayName(pmkContext, bind, NULL, &lefturl);
1104 TRACE("lefturl = %s\n", debugstr_w(lefturl));
1105 IBindCtx_Release(bind);
1109 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
1110 CoTaskMemFree(lefturl);
1112 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &IID_IMoniker, (void**)ppmk);
1114 HeapFree(GetProcessHeap(), 0, obj);
1118 /**********************************************************************
1119 * CreateURLMoniker (URLMON.@)
1121 * Create a url moniker.
1124 * pmkContext [I] Context
1125 * szURL [I] Url to create the moniker for
1126 * ppmk [O] Destination for created moniker.
1129 * Success: S_OK. ppmk contains the created IMoniker object.
1130 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1131 * E_OUTOFMEMORY if memory allocation fails.
1133 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
1135 return CreateURLMonikerEx(pmkContext, szURL, ppmk, URL_MK_LEGACY);
1138 /***********************************************************************
1139 * CoInternetQueryInfo (URLMON.@)
1141 * Retrieves information relevant to a specified URL
1145 * S_FALSE buffer too small
1146 * INET_E_QUERYOPTIONUNKNOWN invalid option
1149 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1150 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1153 FIXME("(%s, %x, %x, %p, %x, %p, %x): stub\n", debugstr_w(pwzUrl),
1154 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1158 /***********************************************************************
1159 * IsAsyncMoniker (URLMON.@)
1161 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1165 TRACE("(%p)\n", pmk);
1167 return E_INVALIDARG;
1168 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1169 IUnknown_Release(am);
1175 /***********************************************************************
1176 * BindAsyncMoniker (URLMON.@)
1178 * Bind a bind status callback to an asynchronous URL Moniker.
1181 * pmk [I] Moniker object to bind status callback to
1182 * grfOpt [I] Options, seems not used
1183 * pbsc [I] Status callback to bind
1184 * iidResult [I] Interface to return
1185 * ppvResult [O] Resulting asynchronous moniker object
1189 * Failure: E_INVALIDARG, if any argument is invalid, or
1190 * E_OUTOFMEMORY if memory allocation fails.
1192 HRESULT WINAPI BindAsyncMoniker(IMoniker *pmk, DWORD grfOpt, IBindStatusCallback *pbsc, REFIID iidResult, LPVOID *ppvResult)
1195 HRESULT hr = E_INVALIDARG;
1197 if (pmk && ppvResult)
1201 hr = CreateAsyncBindCtx(0, pbsc, NULL, &pbc);
1204 hr = IMoniker_BindToObject(pmk, pbc, NULL, iidResult, ppvResult);
1205 IBindCtx_Release(pbc);
1211 /***********************************************************************
1212 * URLDownloadToFileA (URLMON.@)
1214 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1218 * pCaller [I] controlling IUnknown interface.
1219 * szURL [I] URL of the file to download
1220 * szFileName [I] file name to store the content of the URL
1221 * dwReserved [I] reserved - set to 0
1222 * lpfnCB [I] callback for progress report
1226 * E_OUTOFMEMORY when going out of memory
1228 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1232 LPBINDSTATUSCALLBACK lpfnCB)
1234 UNICODE_STRING szURL_w, szFileName_w;
1236 if ((szURL == NULL) || (szFileName == NULL)) {
1237 FIXME("(%p,%s,%s,%08x,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1238 return E_INVALIDARG; /* The error code is not specified in this case... */
1241 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1242 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1243 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1245 RtlFreeUnicodeString(&szURL_w);
1246 RtlFreeUnicodeString(&szFileName_w);
1250 RtlFreeUnicodeString(&szURL_w);
1254 FIXME("(%p,%s,%s,%08x,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1255 return E_OUTOFMEMORY;
1258 /***********************************************************************
1259 * URLDownloadToFileW (URLMON.@)
1261 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1265 * pCaller [I] controlling IUnknown interface.
1266 * szURL [I] URL of the file to download
1267 * szFileName [I] file name to store the content of the URL
1268 * dwReserved [I] reserved - set to 0
1269 * lpfnCB [I] callback for progress report
1273 * E_OUTOFMEMORY when going out of memory
1275 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1279 LPBINDSTATUSCALLBACK lpfnCB)
1281 HINTERNET hinternet, hcon, hreq;
1283 CHAR buffer[0x1000];
1284 DWORD sz, total, written;
1285 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1286 URL_COMPONENTSW url;
1287 WCHAR host[0x80], path[0x100];
1289 static const WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1291 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1292 TRACE("(%p,%s,%s,%08x,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1294 if ((szURL == NULL) || (szFileName == NULL)) {
1295 FIXME(" cannot accept NULL strings !\n");
1296 return E_INVALIDARG;
1299 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1300 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1301 if (hinternet == NULL) {
1302 return E_OUTOFMEMORY;
1305 memset(&url, 0, sizeof(url));
1306 url.dwStructSize = sizeof(url);
1307 url.lpszHostName = host;
1308 url.dwHostNameLength = sizeof(host);
1309 url.lpszUrlPath = path;
1310 url.dwUrlPathLength = sizeof(path);
1312 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1313 InternetCloseHandle(hinternet);
1314 return E_OUTOFMEMORY;
1318 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1319 InternetCloseHandle(hinternet);
1324 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1325 url.lpszUserName, url.lpszPassword,
1326 INTERNET_SERVICE_HTTP, 0, 0);
1328 InternetCloseHandle(hinternet);
1329 return E_OUTOFMEMORY;
1332 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1334 InternetCloseHandle(hinternet);
1335 InternetCloseHandle(hcon);
1336 return E_OUTOFMEMORY;
1339 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1340 InternetCloseHandle(hinternet);
1341 InternetCloseHandle(hcon);
1342 InternetCloseHandle(hreq);
1343 return E_OUTOFMEMORY;
1346 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1347 &total_size, &arg_size, NULL)) {
1348 TRACE(" total size : %d\n", total_size);
1351 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1352 FILE_ATTRIBUTE_NORMAL, NULL );
1353 if (hfile == INVALID_HANDLE_VALUE) {
1354 return E_ACCESSDENIED;
1358 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1359 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1360 InternetCloseHandle(hreq);
1361 InternetCloseHandle(hcon);
1362 InternetCloseHandle(hinternet);
1370 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1372 InternetCloseHandle(hreq);
1373 InternetCloseHandle(hcon);
1374 InternetCloseHandle(hinternet);
1377 return E_OUTOFMEMORY;
1385 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1386 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1387 InternetCloseHandle(hreq);
1388 InternetCloseHandle(hcon);
1389 InternetCloseHandle(hinternet);
1395 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1396 InternetCloseHandle(hreq);
1397 InternetCloseHandle(hcon);
1398 InternetCloseHandle(hinternet);
1401 return E_OUTOFMEMORY;
1406 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1407 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1408 InternetCloseHandle(hreq);
1409 InternetCloseHandle(hcon);
1410 InternetCloseHandle(hinternet);
1416 InternetCloseHandle(hreq);
1417 InternetCloseHandle(hcon);
1418 InternetCloseHandle(hinternet);
1425 /***********************************************************************
1426 * URLDownloadToCacheFileA (URLMON.@)
1428 HRESULT WINAPI URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller, LPCSTR szURL, LPSTR szFileName,
1429 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
1431 LPWSTR url = NULL, file_name = NULL;
1435 TRACE("(%p %s %p %d %d %p)\n", lpUnkCaller, debugstr_a(szURL), szFileName,
1436 dwBufLength, dwReserved, pBSC);
1439 len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
1440 url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1441 MultiByteToWideChar(CP_ACP, 0, szURL, -1, url, -1);
1445 file_name = HeapAlloc(GetProcessHeap(), 0, dwBufLength*sizeof(WCHAR));
1447 hres = URLDownloadToCacheFileW(lpUnkCaller, url, file_name, dwBufLength*sizeof(WCHAR),
1450 if(SUCCEEDED(hres) && file_name)
1451 WideCharToMultiByte(CP_ACP, 0, file_name, -1, szFileName, dwBufLength, NULL, NULL);
1453 HeapFree(GetProcessHeap(), 0, url);
1454 HeapFree(GetProcessHeap(), 0, file_name);
1459 /***********************************************************************
1460 * URLDownloadToCacheFileW (URLMON.@)
1462 HRESULT WINAPI URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller, LPCWSTR szURL, LPWSTR szFileName,
1463 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
1465 WCHAR cache_path[MAX_PATH + 1];
1466 FILETIME expire, modified;
1470 static WCHAR header[] = {
1471 'H','T','T','P','/','1','.','0',' ','2','0','0',' ',
1472 'O','K','\\','r','\\','n','\\','r','\\','n',0
1475 TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller, debugstr_w(szURL),
1476 szFileName, dwBufLength, dwReserved, pBSC);
1478 if (!szURL || !szFileName)
1479 return E_INVALIDARG;
1481 ext = PathFindExtensionW(szURL);
1483 if (!CreateUrlCacheEntryW(szURL, 0, ext, cache_path, 0))
1486 hr = URLDownloadToFileW(lpUnkCaller, szURL, cache_path, 0, pBSC);
1490 expire.dwHighDateTime = 0;
1491 expire.dwLowDateTime = 0;
1492 modified.dwHighDateTime = 0;
1493 modified.dwLowDateTime = 0;
1495 if (!CommitUrlCacheEntryW(szURL, cache_path, expire, modified, NORMAL_CACHE_ENTRY,
1496 header, sizeof(header), NULL, NULL))
1499 if (lstrlenW(cache_path) > dwBufLength)
1500 return E_OUTOFMEMORY;
1502 lstrcpyW(szFileName, cache_path);
1507 /***********************************************************************
1508 * HlinkSimpleNavigateToString (URLMON.@)
1510 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
1511 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1512 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1514 FIXME("%s\n", debugstr_w( szTarget ) );
1518 /***********************************************************************
1519 * HlinkNavigateString (URLMON.@)
1521 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
1523 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
1524 return HlinkSimpleNavigateToString(
1525 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );
1528 /***********************************************************************
1529 * GetSoftwareUpdateInfo (URLMON.@)
1531 HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi )
1533 FIXME("%s %p\n", debugstr_w(szDistUnit), psdi );