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
25 #include "urlmon_main.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
36 /* native urlmon.dll uses this key, too */
37 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
39 /*static BOOL registered_wndclass = FALSE;*/
42 const IBindingVtbl *lpVtbl;
50 HINTERNET hinternet, hconnect, hrequest;
52 IUMCacheStream *pstrCache;
53 IBindStatusCallback *pbscb;
54 DWORD total_read, expected_size;
57 static HRESULT WINAPI Binding_QueryInterface(IBinding* iface, REFIID riid, void **ppvObject)
59 Binding *This = (Binding*)iface;
61 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
63 if((This == NULL) || (ppvObject == NULL))
66 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid)) {
68 IBinding_AddRef(iface);
76 static ULONG WINAPI Binding_AddRef(IBinding* iface)
78 Binding *This = (Binding*)iface;
79 ULONG ref = InterlockedIncrement(&This->ref);
81 TRACE("(%p) ref=%d\n", This, ref);
86 static ULONG WINAPI Binding_Release(IBinding* iface)
88 Binding *This = (Binding*)iface;
89 ULONG ref = InterlockedDecrement(&This->ref);
91 TRACE("(%p) ref=%d\n",This, ref);
94 heap_free(This->URLName);
96 CloseHandle(This->hCacheFile);
99 UMCloseCacheFileStream(This->pstrCache);
100 IStream_Release((IStream *)This->pstrCache);
103 IBindStatusCallback_Release(This->pbscb);
107 URLMON_UnlockModule();
113 static HRESULT WINAPI Binding_Abort(IBinding* iface)
115 Binding *This = (Binding*)iface;
117 FIXME("(%p): stub\n", This);
122 static HRESULT WINAPI Binding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
124 Binding *This = (Binding*)iface;
126 FIXME("(%p)->(%p, %p, %p, %p): stub\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
131 static HRESULT WINAPI Binding_GetPriority(IBinding* iface, LONG* pnPriority)
133 Binding *This = (Binding*)iface;
135 FIXME("(%p)->(%p): stub\n", This, pnPriority);
140 static HRESULT WINAPI Binding_Resume(IBinding* iface)
142 Binding *This = (Binding*)iface;
144 FIXME("(%p): stub\n", This);
149 static HRESULT WINAPI Binding_SetPriority(IBinding* iface, LONG nPriority)
151 Binding *This = (Binding*)iface;
153 FIXME("(%p)->(%d): stub\n", This, nPriority);
158 static HRESULT WINAPI Binding_Suspend(IBinding* iface)
160 Binding *This = (Binding*)iface;
162 FIXME("(%p): stub\n", This);
167 static void Binding_CloseCacheDownload(Binding *This)
169 CloseHandle(This->hCacheFile);
170 This->hCacheFile = 0;
171 UMCloseCacheFileStream(This->pstrCache);
172 IStream_Release((IStream *)This->pstrCache);
176 static HRESULT Binding_MoreCacheData(Binding *This, const char *buf, DWORD dwBytes)
180 if (WriteFile(This->hCacheFile, buf, dwBytes, &written, NULL) && written == dwBytes)
184 This->total_read += written;
185 hr = IBindStatusCallback_OnProgress(This->pbscb,
186 This->total_read + written,
188 (This->total_read == written) ?
189 BINDSTATUS_BEGINDOWNLOADDATA :
190 BINDSTATUS_DOWNLOADINGDATA,
201 fmt.tymed = TYMED_ISTREAM;
203 stg.tymed = TYMED_ISTREAM;
204 stg.u.pstm = (IStream *)This->pstrCache;
205 stg.pUnkForRelease = NULL;
207 hr = IBindStatusCallback_OnDataAvailable(This->pbscb,
208 (This->total_read == written) ?
209 BSCF_FIRSTDATANOTIFICATION :
210 BSCF_INTERMEDIATEDATANOTIFICATION,
211 This->total_read + written,
215 if (written < dwBytes)
216 return STG_E_MEDIUMFULL;
220 return HRESULT_FROM_WIN32(GetLastError());
223 static void Binding_FinishedDownload(Binding *This, HRESULT hr)
231 fmt.tymed = TYMED_ISTREAM;
233 stg.tymed = TYMED_ISTREAM;
234 stg.u.pstm = (IStream *)This->pstrCache;
235 stg.pUnkForRelease = NULL;
237 IBindStatusCallback_OnProgress(This->pbscb, This->total_read, This->expected_size,
238 BINDSTATUS_ENDDOWNLOADDATA, This->URLName);
239 IBindStatusCallback_OnDataAvailable(This->pbscb, BSCF_LASTDATANOTIFICATION, This->total_read, &fmt, &stg);
242 WCHAR *pwchError = 0;
244 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
245 FORMAT_MESSAGE_ALLOCATE_BUFFER,
247 0, (LPWSTR) &pwchError,
251 static const WCHAR achFormat[] = { '%', '0', '8', 'x', 0 };
253 pwchError =(WCHAR *) LocalAlloc(LMEM_FIXED, sizeof(WCHAR) * 9);
254 wsprintfW(pwchError, achFormat, hr);
256 IBindStatusCallback_OnStopBinding(This->pbscb, hr, pwchError);
257 LocalFree(pwchError);
261 IBindStatusCallback_OnStopBinding(This->pbscb, hr, NULL);
263 IBindStatusCallback_Release(This->pbscb);
267 static const IBindingVtbl BindingVtbl =
269 Binding_QueryInterface,
277 Binding_GetBindResult
280 /* filemoniker data structure */
283 const IMonikerVtbl* lpvtbl; /* VTable relative to the IMoniker interface.*/
285 LONG ref; /* reference counter for this object */
287 LPOLESTR URLName; /* URL string identified by this URLmoniker */
290 /*******************************************************************************
291 * URLMoniker_QueryInterface
292 *******************************************************************************/
293 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
295 URLMonikerImpl *This = (URLMonikerImpl *)iface;
297 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
299 /* Perform a sanity check on the parameters.*/
300 if ( (This==0) || (ppvObject==0) )
303 /* Initialize the return parameter */
306 /* Compare the riid with the interface IDs implemented by this object.*/
307 if (IsEqualIID(&IID_IUnknown, riid) ||
308 IsEqualIID(&IID_IPersist, riid) ||
309 IsEqualIID(&IID_IPersistStream,riid) ||
310 IsEqualIID(&IID_IMoniker, riid)
314 /* Check that we obtained an interface.*/
316 return E_NOINTERFACE;
318 /* Query Interface always increases the reference count by one when it is successful */
319 IMoniker_AddRef(iface);
324 /******************************************************************************
326 ******************************************************************************/
327 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
329 URLMonikerImpl *This = (URLMonikerImpl *)iface;
330 ULONG refCount = InterlockedIncrement(&This->ref);
332 TRACE("(%p) ref=%u\n",This, refCount);
337 /******************************************************************************
339 ******************************************************************************/
340 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
342 URLMonikerImpl *This = (URLMonikerImpl *)iface;
343 ULONG refCount = InterlockedDecrement(&This->ref);
345 TRACE("(%p) ref=%u\n",This, refCount);
347 /* destroy the object if there's no more reference on it */
349 heap_free(This->URLName);
352 URLMON_UnlockModule();
359 /******************************************************************************
360 * URLMoniker_GetClassID
361 ******************************************************************************/
362 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
363 CLSID *pClassID)/* Pointer to CLSID of object */
365 URLMonikerImpl *This = (URLMonikerImpl *)iface;
367 TRACE("(%p,%p)\n",This,pClassID);
371 /* Windows always returns CLSID_StdURLMoniker */
372 *pClassID = CLSID_StdURLMoniker;
376 /******************************************************************************
378 ******************************************************************************/
379 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
381 URLMonikerImpl *This = (URLMonikerImpl *)iface;
382 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
383 method in the OLE-provided moniker interfaces always return S_FALSE because
384 their internal state never changes. */
386 TRACE("(%p)\n",This);
391 /******************************************************************************
395 * Writes a ULONG containing length of unicode string, followed
396 * by that many unicode characters
397 ******************************************************************************/
398 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
400 URLMonikerImpl *This = (URLMonikerImpl *)iface;
405 TRACE("(%p,%p)\n",This,pStm);
410 res = IStream_Read(pStm, &size, sizeof(ULONG), &got);
412 if(got == sizeof(ULONG)) {
413 heap_free(This->URLName);
414 This->URLName = heap_alloc(size);
418 res = IStream_Read(pStm, This->URLName, size, NULL);
419 This->URLName[size/sizeof(WCHAR) - 1] = 0;
428 /******************************************************************************
430 ******************************************************************************/
431 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
432 IStream* pStm,/* pointer to the stream where the object is to be saved */
433 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
435 URLMonikerImpl *This = (URLMonikerImpl *)iface;
439 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
444 size = (strlenW(This->URLName) + 1)*sizeof(WCHAR);
445 res=IStream_Write(pStm,&size,sizeof(ULONG),NULL);
447 res=IStream_Write(pStm,This->URLName,size,NULL);
452 /******************************************************************************
453 * URLMoniker_GetSizeMax
454 ******************************************************************************/
455 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
456 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
458 URLMonikerImpl *This = (URLMonikerImpl *)iface;
460 TRACE("(%p,%p)\n",This,pcbSize);
465 pcbSize->QuadPart = sizeof(ULONG) + ((strlenW(This->URLName)+1) * sizeof(WCHAR));
469 /******************************************************************************
470 * URLMoniker_BindToObject
471 ******************************************************************************/
472 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
478 URLMonikerImpl *This = (URLMonikerImpl *)iface;
479 IRunningObjectTable *obj_tbl;
482 TRACE("(%p)->(%p,%p,%s,%p): stub\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppv);
484 hres = IBindCtx_GetRunningObjectTable(pbc, &obj_tbl);
485 if(SUCCEEDED(hres)) {
486 FIXME("use running object table\n");
487 IRunningObjectTable_Release(obj_tbl);
490 return bind_to_object(iface, This->URLName, pbc, riid, ppv);
493 /******************************************************************************
494 * URLMoniker_BindToStorage
495 ******************************************************************************/
496 static HRESULT URLMonikerImpl_BindToStorage_hack(LPCWSTR URLName, IBindCtx* pbc, VOID** ppvObject)
501 WCHAR szFileName[MAX_PATH + 1];
505 WARN("(%s %p %p)\n", debugstr_w(URLName), pbc, ppvObject);
507 bind = heap_alloc_zero(sizeof(Binding));
508 bind->lpVtbl = &BindingVtbl;
512 len = lstrlenW(URLName)+1;
513 bind->URLName = heap_alloc(len*sizeof(WCHAR));
514 memcpy(bind->URLName, URLName, len*sizeof(WCHAR));
516 hres = UMCreateStreamOnCacheFile(bind->URLName, 0, szFileName, &bind->hCacheFile, &bind->pstrCache);
518 if(SUCCEEDED(hres)) {
519 TRACE("Created stream...\n");
521 *ppvObject = (void *) bind->pstrCache;
522 IStream_AddRef((IStream *) bind->pstrCache);
524 hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&bind->pbscb);
525 if(SUCCEEDED(hres)) {
526 TRACE("Got IBindStatusCallback...\n");
528 memset(&bi, 0, sizeof(bi));
529 bi.cbSize = sizeof(bi);
531 hres = IBindStatusCallback_GetBindInfo(bind->pbscb, &bindf, &bi);
532 if(SUCCEEDED(hres)) {
534 WCHAR *host, *path, *user, *pass;
538 TRACE("got bindinfo. bindf = %08x extrainfo = %s bindinfof = %08x bindverb = %08x iid %s\n",
539 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
540 hres = IBindStatusCallback_OnStartBinding(bind->pbscb, 0, (IBinding*)bind);
541 TRACE("OnStartBinding rets %08x\n", hres);
543 bind->expected_size = 0;
544 bind->total_read = 0;
546 memset(&url, 0, sizeof(url));
547 url.dwStructSize = sizeof(url);
548 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = url.dwUserNameLength = url.dwPasswordLength = 1;
549 InternetCrackUrlW(URLName, 0, ICU_ESCAPE, &url);
550 host = heap_alloc((url.dwHostNameLength + 1) * sizeof(WCHAR));
551 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
552 host[url.dwHostNameLength] = '\0';
553 path = heap_alloc((url.dwUrlPathLength + 1) * sizeof(WCHAR));
554 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
555 path[url.dwUrlPathLength] = '\0';
556 if (url.dwUserNameLength)
558 user = heap_alloc(((url.dwUserNameLength + 1) * sizeof(WCHAR)));
559 memcpy(user, url.lpszUserName, url.dwUserNameLength * sizeof(WCHAR));
560 user[url.dwUserNameLength] = 0;
566 if (url.dwPasswordLength)
568 pass = heap_alloc(((url.dwPasswordLength + 1) * sizeof(WCHAR)));
569 memcpy(pass, url.lpszPassword, url.dwPasswordLength * sizeof(WCHAR));
570 pass[url.dwPasswordLength] = 0;
579 bind->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0);
580 if (!bind->hinternet)
582 hres = HRESULT_FROM_WIN32(GetLastError());
586 switch ((DWORD) url.nScheme)
588 case INTERNET_SCHEME_FTP:
590 url.nPort = INTERNET_DEFAULT_FTP_PORT;
591 dwService = INTERNET_SERVICE_FTP;
594 case INTERNET_SCHEME_GOPHER:
596 url.nPort = INTERNET_DEFAULT_GOPHER_PORT;
597 dwService = INTERNET_SERVICE_GOPHER;
601 bind->hconnect = InternetConnectW(bind->hinternet, host, url.nPort, user, pass,
602 dwService, 0, (DWORD_PTR)bind);
605 hres = HRESULT_FROM_WIN32(GetLastError());
606 CloseHandle(bind->hinternet);
610 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, 0x22, NULL);
611 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
612 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
613 hres = IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
619 case INTERNET_SERVICE_GOPHER:
620 bind->hrequest = GopherOpenFileW(bind->hconnect,
623 INTERNET_FLAG_RELOAD,
628 hres = HRESULT_FROM_WIN32(GetLastError());
631 case INTERNET_SERVICE_FTP:
632 bind->hrequest = FtpOpenFileW(bind->hconnect,
635 FTP_TRANSFER_TYPE_BINARY |
636 INTERNET_FLAG_TRANSFER_BINARY |
637 INTERNET_FLAG_RELOAD,
642 hres = HRESULT_FROM_WIN32(GetLastError());
647 TRACE("res = %d gle = %u url len = %d\n", hres, GetLastError(), bind->expected_size);
649 IBindStatusCallback_OnProgress(bind->pbscb, 0, 0, BINDSTATUS_CACHEFILENAMEAVAILABLE, szFileName);
654 if(InternetReadFile(bind->hrequest, buf, sizeof(buf), &bufread)) {
655 TRACE("read %d bytes %s...\n", bufread, debugstr_an(buf, 10));
656 if(bufread == 0) break;
657 hres = Binding_MoreCacheData(bind, buf, bufread);
661 InternetCloseHandle(bind->hrequest);
665 InternetCloseHandle(bind->hconnect);
666 InternetCloseHandle(bind->hinternet);
669 Binding_FinishedDownload(bind, hres);
670 Binding_CloseCacheDownload(bind);
680 IBinding_Release((IBinding*)bind);
685 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
691 URLMonikerImpl *This = (URLMonikerImpl*)iface;
695 URL_COMPONENTSW url = {sizeof(URL_COMPONENTSW), schema,
696 sizeof(schema)/sizeof(WCHAR), 0, NULL, 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0};
699 FIXME("Unsupported pmkToLeft\n");
701 bret = InternetCrackUrlW(This->URLName, 0, ICU_ESCAPE, &url);
703 ERR("InternetCrackUrl failed: %u\n", GetLastError());
707 if(IsEqualGUID(&IID_IStream, riid) &&
708 ( url.nScheme == INTERNET_SCHEME_FTP
709 || url.nScheme == INTERNET_SCHEME_GOPHER))
710 return URLMonikerImpl_BindToStorage_hack(This->URLName, pbc, ppvObject);
712 TRACE("(%p)->(%p %p %s %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObject);
714 return bind_to_storage(This->URLName, pbc, riid, ppvObject);
717 /******************************************************************************
719 ******************************************************************************/
720 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
722 DWORD dwReduceHowFar,
723 IMoniker** ppmkToLeft,
724 IMoniker** ppmkReduced)
726 URLMonikerImpl *This = (URLMonikerImpl *)iface;
728 TRACE("(%p,%p,%d,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
733 URLMonikerImpl_AddRef(iface);
734 *ppmkReduced = iface;
735 return MK_S_REDUCED_TO_SELF;
738 /******************************************************************************
739 * URLMoniker_ComposeWith
740 ******************************************************************************/
741 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
743 BOOL fOnlyIfNotGeneric,
744 IMoniker** ppmkComposite)
746 URLMonikerImpl *This = (URLMonikerImpl *)iface;
747 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
752 /******************************************************************************
754 ******************************************************************************/
755 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
757 URLMonikerImpl *This = (URLMonikerImpl *)iface;
758 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
763 /* Does not support sub-monikers */
764 *ppenumMoniker = NULL;
768 /******************************************************************************
770 ******************************************************************************/
771 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
773 URLMonikerImpl *This = (URLMonikerImpl *)iface;
779 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
781 if(pmkOtherMoniker==NULL)
784 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
786 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
789 res = CreateBindCtx(0,&bind);
794 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
795 int result = lstrcmpiW(urlPath, This->URLName);
796 CoTaskMemFree(urlPath);
800 IUnknown_Release(bind);
805 /******************************************************************************
807 ******************************************************************************/
808 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
810 URLMonikerImpl *This = (URLMonikerImpl *)iface;
812 int h = 0,i,skip,len;
816 TRACE("(%p,%p)\n",This,pdwHash);
825 for(i = len ; i > 0; i--) {
826 h = (h * 37) + val[off++];
830 /* only sample some characters */
832 for(i = len; i > 0; i -= skip, off += skip) {
833 h = (h * 39) + val[off];
840 /******************************************************************************
841 * URLMoniker_IsRunning
842 ******************************************************************************/
843 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
846 IMoniker* pmkNewlyRunning)
848 URLMonikerImpl *This = (URLMonikerImpl *)iface;
849 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
854 /******************************************************************************
855 * URLMoniker_GetTimeOfLastChange
856 ******************************************************************************/
857 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
862 URLMonikerImpl *This = (URLMonikerImpl *)iface;
863 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
868 /******************************************************************************
870 ******************************************************************************/
871 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
873 URLMonikerImpl *This = (URLMonikerImpl *)iface;
874 TRACE("(%p,%p)\n",This,ppmk);
876 return MK_E_NOINVERSE;
879 /******************************************************************************
880 * URLMoniker_CommonPrefixWith
881 ******************************************************************************/
882 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
884 URLMonikerImpl *This = (URLMonikerImpl *)iface;
885 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
890 /******************************************************************************
891 * URLMoniker_RelativePathTo
892 ******************************************************************************/
893 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
895 URLMonikerImpl *This = (URLMonikerImpl *)iface;
896 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
901 /******************************************************************************
902 * URLMoniker_GetDisplayName
903 ******************************************************************************/
904 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
907 LPOLESTR *ppszDisplayName)
909 URLMonikerImpl *This = (URLMonikerImpl *)iface;
913 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
918 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
919 then look at pmkToLeft to try and complete the URL
921 len = lstrlenW(This->URLName)+1;
922 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
923 if(!*ppszDisplayName)
924 return E_OUTOFMEMORY;
925 lstrcpyW(*ppszDisplayName, This->URLName);
929 /******************************************************************************
930 * URLMoniker_ParseDisplayName
931 ******************************************************************************/
932 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
935 LPOLESTR pszDisplayName,
939 URLMonikerImpl *This = (URLMonikerImpl *)iface;
940 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
945 /******************************************************************************
946 * URLMoniker_IsSystemMoniker
947 ******************************************************************************/
948 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
950 URLMonikerImpl *This = (URLMonikerImpl *)iface;
951 TRACE("(%p,%p)\n",This,pwdMksys);
956 *pwdMksys = MKSYS_URLMONIKER;
960 /********************************************************************************/
961 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
962 /* IPersistStream and IMoniker functions. */
963 static const IMonikerVtbl VT_URLMonikerImpl =
965 URLMonikerImpl_QueryInterface,
966 URLMonikerImpl_AddRef,
967 URLMonikerImpl_Release,
968 URLMonikerImpl_GetClassID,
969 URLMonikerImpl_IsDirty,
972 URLMonikerImpl_GetSizeMax,
973 URLMonikerImpl_BindToObject,
974 URLMonikerImpl_BindToStorage,
975 URLMonikerImpl_Reduce,
976 URLMonikerImpl_ComposeWith,
978 URLMonikerImpl_IsEqual,
980 URLMonikerImpl_IsRunning,
981 URLMonikerImpl_GetTimeOfLastChange,
982 URLMonikerImpl_Inverse,
983 URLMonikerImpl_CommonPrefixWith,
984 URLMonikerImpl_RelativePathTo,
985 URLMonikerImpl_GetDisplayName,
986 URLMonikerImpl_ParseDisplayName,
987 URLMonikerImpl_IsSystemMoniker
990 /******************************************************************************
991 * URLMoniker_Construct (local function)
992 *******************************************************************************/
993 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
998 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
1000 This->lpvtbl = &VT_URLMonikerImpl;
1003 This->URLName = heap_alloc(INTERNET_MAX_URL_LENGTH*sizeof(WCHAR));
1006 hres = CoInternetCombineUrl(lpszLeftURLName, lpszURLName, URL_FILE_USE_PATHURL,
1007 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
1009 hres = CoInternetParseUrl(lpszURLName, PARSE_CANONICALIZE, URL_FILE_USE_PATHURL,
1010 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
1013 heap_free(This->URLName);
1017 URLMON_LockModule();
1019 if(sizeStr != INTERNET_MAX_URL_LENGTH)
1020 This->URLName = heap_realloc(This->URLName, (sizeStr+1)*sizeof(WCHAR));
1022 TRACE("URLName = %s\n", debugstr_w(This->URLName));
1027 /***********************************************************************
1028 * CreateURLMonikerEx (URLMON.@)
1030 * Create a url moniker.
1033 * pmkContext [I] Context
1034 * szURL [I] Url to create the moniker for
1035 * ppmk [O] Destination for created moniker.
1036 * dwFlags [I] Flags.
1039 * Success: S_OK. ppmk contains the created IMoniker object.
1040 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1041 * E_OUTOFMEMORY if memory allocation fails.
1043 HRESULT WINAPI CreateURLMonikerEx(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk, DWORD dwFlags)
1045 URLMonikerImpl *obj;
1047 LPOLESTR lefturl = NULL;
1049 TRACE("(%p, %s, %p, %08x)\n", pmkContext, debugstr_w(szURL), ppmk, dwFlags);
1051 if (dwFlags & URL_MK_UNIFORM) FIXME("ignoring flag URL_MK_UNIFORM\n");
1053 if(!(obj = heap_alloc(sizeof(*obj))))
1054 return E_OUTOFMEMORY;
1059 IMoniker_IsSystemMoniker(pmkContext, &dwMksys);
1060 if(dwMksys == MKSYS_URLMONIKER && SUCCEEDED(CreateBindCtx(0, &bind))) {
1061 IMoniker_GetDisplayName(pmkContext, bind, NULL, &lefturl);
1062 TRACE("lefturl = %s\n", debugstr_w(lefturl));
1063 IBindCtx_Release(bind);
1067 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
1068 CoTaskMemFree(lefturl);
1070 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &IID_IMoniker, (void**)ppmk);
1076 /**********************************************************************
1077 * CreateURLMoniker (URLMON.@)
1079 * Create a url moniker.
1082 * pmkContext [I] Context
1083 * szURL [I] Url to create the moniker for
1084 * ppmk [O] Destination for created moniker.
1087 * Success: S_OK. ppmk contains the created IMoniker object.
1088 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
1089 * E_OUTOFMEMORY if memory allocation fails.
1091 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
1093 return CreateURLMonikerEx(pmkContext, szURL, ppmk, URL_MK_LEGACY);
1096 /***********************************************************************
1097 * IsAsyncMoniker (URLMON.@)
1099 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1103 TRACE("(%p)\n", pmk);
1105 return E_INVALIDARG;
1106 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1107 IUnknown_Release(am);
1113 /***********************************************************************
1114 * BindAsyncMoniker (URLMON.@)
1116 * Bind a bind status callback to an asynchronous URL Moniker.
1119 * pmk [I] Moniker object to bind status callback to
1120 * grfOpt [I] Options, seems not used
1121 * pbsc [I] Status callback to bind
1122 * iidResult [I] Interface to return
1123 * ppvResult [O] Resulting asynchronous moniker object
1127 * Failure: E_INVALIDARG, if any argument is invalid, or
1128 * E_OUTOFMEMORY if memory allocation fails.
1130 HRESULT WINAPI BindAsyncMoniker(IMoniker *pmk, DWORD grfOpt, IBindStatusCallback *pbsc, REFIID iidResult, LPVOID *ppvResult)
1133 HRESULT hr = E_INVALIDARG;
1135 TRACE("(%p %08x %p %s %p)\n", pmk, grfOpt, pbsc, debugstr_guid(iidResult), ppvResult);
1137 if (pmk && ppvResult)
1141 hr = CreateAsyncBindCtx(0, pbsc, NULL, &pbc);
1144 hr = IMoniker_BindToObject(pmk, pbc, NULL, iidResult, ppvResult);
1145 IBindCtx_Release(pbc);
1151 /***********************************************************************
1152 * MkParseDisplayNameEx (URLMON.@)
1154 HRESULT WINAPI MkParseDisplayNameEx(IBindCtx *pbc, LPCWSTR szDisplayName, ULONG *pchEaten, LPMONIKER *ppmk)
1156 TRACE("(%p %s %p %p)\n", pbc, debugstr_w(szDisplayName), pchEaten, ppmk);
1158 if(is_registered_protocol(szDisplayName)) {
1161 hres = CreateURLMoniker(NULL, szDisplayName, ppmk);
1162 if(SUCCEEDED(hres)) {
1163 *pchEaten = strlenW(szDisplayName);
1168 return MkParseDisplayName(pbc, szDisplayName, pchEaten, ppmk);
1172 /***********************************************************************
1173 * URLDownloadToCacheFileA (URLMON.@)
1175 HRESULT WINAPI URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller, LPCSTR szURL, LPSTR szFileName,
1176 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
1178 LPWSTR url = NULL, file_name = NULL;
1182 TRACE("(%p %s %p %d %d %p)\n", lpUnkCaller, debugstr_a(szURL), szFileName,
1183 dwBufLength, dwReserved, pBSC);
1186 len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
1187 url = heap_alloc(len*sizeof(WCHAR));
1188 MultiByteToWideChar(CP_ACP, 0, szURL, -1, url, -1);
1192 file_name = heap_alloc(dwBufLength*sizeof(WCHAR));
1194 hres = URLDownloadToCacheFileW(lpUnkCaller, url, file_name, dwBufLength*sizeof(WCHAR),
1197 if(SUCCEEDED(hres) && file_name)
1198 WideCharToMultiByte(CP_ACP, 0, file_name, -1, szFileName, dwBufLength, NULL, NULL);
1201 heap_free(file_name);
1206 /***********************************************************************
1207 * URLDownloadToCacheFileW (URLMON.@)
1209 HRESULT WINAPI URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller, LPCWSTR szURL, LPWSTR szFileName,
1210 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
1212 WCHAR cache_path[MAX_PATH + 1];
1213 FILETIME expire, modified;
1217 static WCHAR header[] = {
1218 'H','T','T','P','/','1','.','0',' ','2','0','0',' ',
1219 'O','K','\\','r','\\','n','\\','r','\\','n',0
1222 TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller, debugstr_w(szURL),
1223 szFileName, dwBufLength, dwReserved, pBSC);
1225 if (!szURL || !szFileName)
1226 return E_INVALIDARG;
1228 ext = PathFindExtensionW(szURL);
1230 if (!CreateUrlCacheEntryW(szURL, 0, ext, cache_path, 0))
1233 hr = URLDownloadToFileW(lpUnkCaller, szURL, cache_path, 0, pBSC);
1237 expire.dwHighDateTime = 0;
1238 expire.dwLowDateTime = 0;
1239 modified.dwHighDateTime = 0;
1240 modified.dwLowDateTime = 0;
1242 if (!CommitUrlCacheEntryW(szURL, cache_path, expire, modified, NORMAL_CACHE_ENTRY,
1243 header, sizeof(header), NULL, NULL))
1246 if (strlenW(cache_path) > dwBufLength)
1247 return E_OUTOFMEMORY;
1249 lstrcpyW(szFileName, cache_path);
1254 /***********************************************************************
1255 * HlinkSimpleNavigateToMoniker (URLMON.@)
1257 HRESULT WINAPI HlinkSimpleNavigateToMoniker(IMoniker *pmkTarget,
1258 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1259 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1265 /***********************************************************************
1266 * HlinkSimpleNavigateToString (URLMON.@)
1268 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
1269 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1270 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1272 FIXME("%s\n", debugstr_w( szTarget ) );
1276 /***********************************************************************
1277 * HlinkNavigateString (URLMON.@)
1279 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
1281 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
1282 return HlinkSimpleNavigateToString(
1283 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );
1286 /***********************************************************************
1287 * GetSoftwareUpdateInfo (URLMON.@)
1289 HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi )
1291 FIXME("%s %p\n", debugstr_w(szDistUnit), psdi );