4 * Copyright 1999 Ulrich Czekalla for Corel Corporation
5 * Copyright 2002 Huw D M Davies for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define COM_NO_WINDOWS_H
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
42 #include "urlmon_main.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
46 /* native urlmon.dll uses this key, too */
47 static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
49 /*static BOOL registered_wndclass = FALSE;*/
51 /* filemoniker data structure */
52 typedef struct URLMonikerImpl{
54 IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
55 IBindingVtbl* lpvtbl2; /* VTable to IBinding interface */
57 ULONG ref; /* reference counter for this object */
59 LPOLESTR URLName; /* URL string identified by this URLmoniker */
63 HINTERNET hinternet, hconnect, hrequest;
66 /*******************************************************************************
67 * URLMoniker_QueryInterface
68 *******************************************************************************/
69 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
71 URLMonikerImpl *This = (URLMonikerImpl *)iface;
73 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
75 /* Perform a sanity check on the parameters.*/
76 if ( (This==0) || (ppvObject==0) )
79 /* Initialize the return parameter */
82 /* Compare the riid with the interface IDs implemented by this object.*/
83 if (IsEqualIID(&IID_IUnknown, riid) ||
84 IsEqualIID(&IID_IPersist, riid) ||
85 IsEqualIID(&IID_IPersistStream,riid) ||
86 IsEqualIID(&IID_IMoniker, riid)
90 /* Check that we obtained an interface.*/
94 /* Query Interface always increases the reference count by one when it is successful */
95 IMoniker_AddRef(iface);
100 /******************************************************************************
102 ******************************************************************************/
103 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
105 URLMonikerImpl *This = (URLMonikerImpl *)iface;
106 ULONG refCount = InterlockedIncrement(&This->ref);
108 TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
113 /******************************************************************************
115 ******************************************************************************/
116 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
118 URLMonikerImpl *This = (URLMonikerImpl *)iface;
119 ULONG refCount = InterlockedDecrement(&This->ref);
121 TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
123 /* destroy the object if there's no more reference on it */
125 HeapFree(GetProcessHeap(),0,This->URLName);
126 HeapFree(GetProcessHeap(),0,This);
132 /******************************************************************************
133 * URLMoniker_GetClassID
134 ******************************************************************************/
135 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
136 CLSID *pClassID)/* Pointer to CLSID of object */
138 URLMonikerImpl *This = (URLMonikerImpl *)iface;
140 TRACE("(%p,%p)\n",This,pClassID);
144 /* Windows always returns CLSID_StdURLMoniker */
145 *pClassID = CLSID_StdURLMoniker;
149 /******************************************************************************
151 ******************************************************************************/
152 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
154 URLMonikerImpl *This = (URLMonikerImpl *)iface;
155 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
156 method in the OLE-provided moniker interfaces always return S_FALSE because
157 their internal state never changes. */
159 TRACE("(%p)\n",This);
164 /******************************************************************************
168 * Writes a ULONG containing length of unicode string, followed
169 * by that many unicode characters
170 ******************************************************************************/
171 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
173 URLMonikerImpl *This = (URLMonikerImpl *)iface;
178 TRACE("(%p,%p)\n",This,pStm);
183 res = IStream_Read(pStm, &len, sizeof(ULONG), &got);
185 if(got == sizeof(ULONG)) {
186 HeapFree(GetProcessHeap(), 0, This->URLName);
187 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(len+1));
191 res = IStream_Read(pStm, This->URLName, len, NULL);
192 This->URLName[len] = 0;
201 /******************************************************************************
203 ******************************************************************************/
204 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
205 IStream* pStm,/* pointer to the stream where the object is to be saved */
206 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
208 URLMonikerImpl *This = (URLMonikerImpl *)iface;
212 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
217 len = strlenW(This->URLName);
218 res=IStream_Write(pStm,&len,sizeof(ULONG),NULL);
220 res=IStream_Write(pStm,&This->URLName,len*sizeof(WCHAR),NULL);
225 /******************************************************************************
226 * URLMoniker_GetSizeMax
227 ******************************************************************************/
228 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
229 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
231 URLMonikerImpl *This = (URLMonikerImpl *)iface;
233 TRACE("(%p,%p)\n",This,pcbSize);
238 pcbSize->u.LowPart = sizeof(ULONG) + (strlenW(This->URLName) * sizeof(WCHAR));
239 pcbSize->u.HighPart = 0;
243 /******************************************************************************
244 * URLMoniker_BindToObject
245 ******************************************************************************/
246 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
252 URLMonikerImpl *This = (URLMonikerImpl *)iface;
256 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
263 enum {OnProgress, OnDataAvailable} callback;
264 } URLMON_CallbackData;
268 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
270 return DefWindowProcA(hwnd, msg, wparam, lparam);
273 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
277 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
278 void *status_info, DWORD status_info_len)
280 URLMonikerImpl *This = (URLMonikerImpl *)context;
281 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
283 if(This->filesize == -1) {
285 case INTERNET_STATUS_RESOLVING_NAME:
286 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
288 case INTERNET_STATUS_CONNECTING_TO_SERVER:
289 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
291 case INTERNET_STATUS_SENDING_REQUEST:
292 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
294 case INTERNET_REQUEST_COMPLETE:
296 DWORD len, lensz = sizeof(len);
298 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
299 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
300 This->filesize = len;
309 /******************************************************************************
310 * URLMoniker_BindToStorage
311 ******************************************************************************/
312 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
318 URLMonikerImpl *This = (URLMonikerImpl *)iface;
320 IBindStatusCallback *pbscb;
325 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
327 FIXME("pmkToLeft != NULL\n");
330 if(!IsEqualIID(&IID_IStream, riid)) {
331 FIXME("unsupported iid\n");
335 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
336 We also need to implement IStream ourselves so that IStream_Read can return
339 hres = CreateStreamOnHGlobal(0, TRUE, &pstr);
341 if(SUCCEEDED(hres)) {
342 TRACE("Created dummy stream...\n");
344 hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&pbscb);
345 if(SUCCEEDED(hres)) {
346 TRACE("Got IBindStatusCallback...\n");
348 memset(&bi, 0, sizeof(bi));
349 bi.cbSize = sizeof(bi);
351 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
352 if(SUCCEEDED(hres)) {
355 DWORD len, lensz = sizeof(len), total_read = 0;
356 LARGE_INTEGER last_read_pos;
360 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
361 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
362 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
363 TRACE("OnStartBinding rets %08lx\n", hres);
366 if(!registered_wndclass) {
367 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
368 RegisterClassA(&urlmon_wndclass);
369 registered_wndclass = TRUE;
372 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
373 URLMON_hInstance, NULL);
376 memset(&url, 0, sizeof(url));
377 url.dwStructSize = sizeof(url);
378 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
379 InternetCrackUrlW(This->URLName, 0, 0, &url);
380 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
381 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
382 host[url.dwHostNameLength] = '\0';
383 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
384 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
385 path[url.dwUrlPathLength] = '\0';
387 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
388 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
390 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
391 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
392 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
394 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
395 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
396 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
397 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
398 hres = E_OUTOFMEMORY; /* FIXME */
399 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
401 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
403 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
405 last_read_pos.u.LowPart = last_read_pos.u.HighPart = 0;
410 fmt.tymed = TYMED_ISTREAM;
411 stg.tymed = TYMED_ISTREAM;
413 stg.pUnkForRelease = NULL;
419 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
420 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
421 if(bufread == 0) break;
422 IStream_Write(pstr, buf, bufread, &written);
423 total_read += bufread;
424 IStream_Seek(pstr, last_read_pos, STREAM_SEEK_SET, NULL);
425 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
426 BINDSTATUS_BEGINDOWNLOADDATA :
427 BINDSTATUS_DOWNLOADINGDATA, NULL);
428 hres = IBindStatusCallback_OnDataAvailable(pbscb,
429 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
430 BSCF_INTERMEDIATEDATANOTIFICATION,
431 total_read, &fmt, &stg);
432 last_read_pos.u.LowPart += bufread; /* FIXME */
436 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
437 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
438 TRACE("OnDataAvail rets %08lx\n", hres);
439 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
440 TRACE("OnStop rets %08lx\n", hres);
443 InternetCloseHandle(This->hrequest);
444 InternetCloseHandle(This->hconnect);
445 InternetCloseHandle(This->hinternet);
446 IBindStatusCallback_Release(pbscb);
450 *ppvObject = (VOID*)pstr;
454 /******************************************************************************
456 ******************************************************************************/
457 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
459 DWORD dwReduceHowFar,
460 IMoniker** ppmkToLeft,
461 IMoniker** ppmkReduced)
463 URLMonikerImpl *This = (URLMonikerImpl *)iface;
465 TRACE("(%p,%p,%ld,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
470 URLMonikerImpl_AddRef(iface);
471 *ppmkReduced = iface;
472 return MK_S_REDUCED_TO_SELF;
475 /******************************************************************************
476 * URLMoniker_ComposeWith
477 ******************************************************************************/
478 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
480 BOOL fOnlyIfNotGeneric,
481 IMoniker** ppmkComposite)
483 URLMonikerImpl *This = (URLMonikerImpl *)iface;
484 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
489 /******************************************************************************
491 ******************************************************************************/
492 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
494 URLMonikerImpl *This = (URLMonikerImpl *)iface;
495 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
500 /* Does not support sub-monikers */
501 *ppenumMoniker = NULL;
505 /******************************************************************************
507 ******************************************************************************/
508 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
510 URLMonikerImpl *This = (URLMonikerImpl *)iface;
516 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
518 if(pmkOtherMoniker==NULL)
521 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
523 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
526 res = CreateBindCtx(0,&bind);
531 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
532 int result = lstrcmpiW(urlPath, This->URLName);
533 CoTaskMemFree(urlPath);
537 IUnknown_Release(bind);
542 /******************************************************************************
544 ******************************************************************************/
545 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
547 URLMonikerImpl *This = (URLMonikerImpl *)iface;
549 int h = 0,i,skip,len;
553 TRACE("(%p,%p)\n",This,pdwHash);
562 for(i = len ; i > 0; i--) {
563 h = (h * 37) + val[off++];
567 /* only sample some characters */
569 for(i = len; i > 0; i -= skip, off += skip) {
570 h = (h * 39) + val[off];
577 /******************************************************************************
578 * URLMoniker_IsRunning
579 ******************************************************************************/
580 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
583 IMoniker* pmkNewlyRunning)
585 URLMonikerImpl *This = (URLMonikerImpl *)iface;
586 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
591 /******************************************************************************
592 * URLMoniker_GetTimeOfLastChange
593 ******************************************************************************/
594 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
599 URLMonikerImpl *This = (URLMonikerImpl *)iface;
600 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
605 /******************************************************************************
607 ******************************************************************************/
608 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
610 URLMonikerImpl *This = (URLMonikerImpl *)iface;
611 TRACE("(%p,%p)\n",This,ppmk);
613 return MK_E_NOINVERSE;
616 /******************************************************************************
617 * URLMoniker_CommonPrefixWith
618 ******************************************************************************/
619 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
621 URLMonikerImpl *This = (URLMonikerImpl *)iface;
622 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
627 /******************************************************************************
628 * URLMoniker_RelativePathTo
629 ******************************************************************************/
630 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
632 URLMonikerImpl *This = (URLMonikerImpl *)iface;
633 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
638 /******************************************************************************
639 * URLMoniker_GetDisplayName
640 ******************************************************************************/
641 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
644 LPOLESTR *ppszDisplayName)
646 URLMonikerImpl *This = (URLMonikerImpl *)iface;
650 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
655 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
656 then look at pmkToLeft to try and complete the URL
658 len = lstrlenW(This->URLName)+1;
659 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
660 if(!*ppszDisplayName)
661 return E_OUTOFMEMORY;
662 lstrcpyW(*ppszDisplayName, This->URLName);
666 /******************************************************************************
667 * URLMoniker_ParseDisplayName
668 ******************************************************************************/
669 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
672 LPOLESTR pszDisplayName,
676 URLMonikerImpl *This = (URLMonikerImpl *)iface;
677 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
682 /******************************************************************************
683 * URLMoniker_IsSystemMoniker
684 ******************************************************************************/
685 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
687 URLMonikerImpl *This = (URLMonikerImpl *)iface;
688 TRACE("(%p,%p)\n",This,pwdMksys);
693 *pwdMksys = MKSYS_URLMONIKER;
697 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
699 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
701 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
703 /* Perform a sanity check on the parameters.*/
704 if ( (This==0) || (ppvObject==0) )
707 /* Initialize the return parameter */
710 /* Compare the riid with the interface IDs implemented by this object.*/
711 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
714 /* Check that we obtained an interface.*/
716 return E_NOINTERFACE;
718 /* Query Interface always increases the reference count by one when it is successful */
719 IBinding_AddRef(iface);
725 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
727 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
728 TRACE("(%p)\n",This);
730 return URLMonikerImpl_AddRef((IMoniker*)This);
733 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
735 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
736 TRACE("(%p)\n",This);
738 return URLMonikerImpl_Release((IMoniker*)This);
741 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
743 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
744 FIXME("(%p): stub\n", This);
749 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
751 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
752 FIXME("(%p)->(%p, %p, %p, %p): stub\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
757 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
759 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
760 FIXME("(%p)->(%p): stub\n", This, pnPriority);
765 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
767 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
768 FIXME("(%p): stub\n", This);
773 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
775 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
776 FIXME("(%p)->(%ld): stub\n", This, nPriority);
781 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
783 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
784 FIXME("(%p): stub\n", This);
789 /********************************************************************************/
790 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
791 /* IPersistStream and IMoniker functions. */
792 static IMonikerVtbl VT_URLMonikerImpl =
794 URLMonikerImpl_QueryInterface,
795 URLMonikerImpl_AddRef,
796 URLMonikerImpl_Release,
797 URLMonikerImpl_GetClassID,
798 URLMonikerImpl_IsDirty,
801 URLMonikerImpl_GetSizeMax,
802 URLMonikerImpl_BindToObject,
803 URLMonikerImpl_BindToStorage,
804 URLMonikerImpl_Reduce,
805 URLMonikerImpl_ComposeWith,
807 URLMonikerImpl_IsEqual,
809 URLMonikerImpl_IsRunning,
810 URLMonikerImpl_GetTimeOfLastChange,
811 URLMonikerImpl_Inverse,
812 URLMonikerImpl_CommonPrefixWith,
813 URLMonikerImpl_RelativePathTo,
814 URLMonikerImpl_GetDisplayName,
815 URLMonikerImpl_ParseDisplayName,
816 URLMonikerImpl_IsSystemMoniker
819 static IBindingVtbl VTBinding_URLMonikerImpl =
821 URLMonikerImpl_IBinding_QueryInterface,
822 URLMonikerImpl_IBinding_AddRef,
823 URLMonikerImpl_IBinding_Release,
824 URLMonikerImpl_IBinding_Abort,
825 URLMonikerImpl_IBinding_Suspend,
826 URLMonikerImpl_IBinding_Resume,
827 URLMonikerImpl_IBinding_SetPriority,
828 URLMonikerImpl_IBinding_GetPriority,
829 URLMonikerImpl_IBinding_GetBindResult
832 /******************************************************************************
833 * URLMoniker_Construct (local function)
834 *******************************************************************************/
835 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
840 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
841 memset(This, 0, sizeof(*This));
843 /* Initialize the virtual function table. */
844 This->lpvtbl1 = &VT_URLMonikerImpl;
845 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
848 if(lpszLeftURLName) {
849 hres = UrlCombineW(lpszLeftURLName, lpszURLName, NULL, &sizeStr, 0);
856 sizeStr = lstrlenW(lpszURLName)+1;
858 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr));
860 if (This->URLName==NULL)
861 return E_OUTOFMEMORY;
863 if(lpszLeftURLName) {
864 hres = UrlCombineW(lpszLeftURLName, lpszURLName, This->URLName, &sizeStr, 0);
866 HeapFree(GetProcessHeap(), 0, This->URLName);
871 strcpyW(This->URLName,lpszURLName);
876 /***********************************************************************
877 * CreateAsyncBindCtx (URLMON.@)
879 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
880 IEnumFORMATETC *format, IBindCtx **pbind)
886 TRACE("(%08lx %p %p %p)\n", reserved, callback, format, pbind);
891 FIXME("format is not supported yet\n");
893 hres = CreateBindCtx(0, &bctx);
897 bindopts.cbStruct = sizeof(BIND_OPTS);
898 bindopts.grfFlags = BIND_MAYBOTHERUSER;
899 bindopts.grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
900 bindopts.dwTickCountDeadline = 0;
901 IBindCtx_SetBindOptions(bctx, &bindopts);
903 hres = IBindCtx_RegisterObjectParam(bctx, (LPOLESTR)BSCBHolder, (IUnknown*)callback);
905 IBindCtx_Release(bctx);
913 /***********************************************************************
914 * CreateAsyncBindCtxEx (URLMON.@)
916 * Create an asynchronous bind context.
921 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
922 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
925 FIXME("stub, returns failure\n");
930 /***********************************************************************
931 * CreateURLMoniker (URLMON.@)
933 * Create a url moniker.
936 * pmkContext [I] Context
937 * szURL [I] Url to create the moniker for
938 * ppmk [O] Destination for created moniker.
941 * Success: S_OK. ppmk contains the created IMoniker object.
942 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
943 * E_OUTOFMEMORY if memory allocation fails.
945 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
949 IID iid = IID_IMoniker;
950 LPOLESTR lefturl = NULL;
952 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
954 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
955 return E_OUTOFMEMORY;
960 IMoniker_GetClassID(pmkContext, &clsid);
961 if(IsEqualCLSID(&clsid, &CLSID_StdURLMoniker) && SUCCEEDED(CreateBindCtx(0, &bind))) {
962 URLMonikerImpl_GetDisplayName(pmkContext, bind, NULL, &lefturl);
963 IBindCtx_Release(bind);
967 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
968 CoTaskMemFree(lefturl);
970 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
972 HeapFree(GetProcessHeap(), 0, obj);
977 /***********************************************************************
978 * CoInternetGetSession (URLMON.@)
980 * Create a new internet session and return an IInternetSession interface
984 * dwSessionMode [I] Mode for the internet session
985 * ppIInternetSession [O] Destination for creates IInternetSession object
986 * dwReserved [I] Reserved, must be 0.
989 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
990 * Failure: E_INVALIDARG, if any argument is invalid, or
991 * E_OUTOFMEMORY if memory allocation fails.
993 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, IInternetSession **ppIInternetSession, DWORD dwReserved)
995 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
998 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
1002 ERR("dwReserved: %ld, must be zero\n", dwReserved);
1005 *ppIInternetSession=NULL;
1006 return E_OUTOFMEMORY;
1009 /***********************************************************************
1010 * CoInternetQueryInfo (URLMON.@)
1012 * Retrieves information relevant to a specified URL
1016 * S_FALSE buffer too small
1017 * INET_E_QUERYOPTIONUNKNOWN invalid option
1020 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1021 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1024 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
1025 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1029 static BOOL URLMON_IsBinary(LPVOID pBuffer, DWORD cbSize)
1031 unsigned int i, binarycount = 0;
1032 unsigned char *buff = pBuffer;
1033 for(i=0; i<cbSize; i++) {
1037 return binarycount > (cbSize-binarycount);
1040 /***********************************************************************
1041 * FindMimeFromData (URLMON.@)
1043 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
1046 * See http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
1048 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
1049 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
1050 LPWSTR* ppwzMimeOut, DWORD dwReserved)
1052 static const WCHAR szBinaryMime[] = {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m','\0'};
1053 static const WCHAR szTextMime[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
1054 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
1055 WCHAR szTmpMime[256];
1056 LPCWSTR mimeType = NULL;
1059 TRACE("(%p,%s,%p,%ld,%s,0x%lx,%p,0x%lx)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
1060 debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
1062 if((!pwzUrl && (!pBuffer || cbSize <= 0)) || !ppwzMimeOut)
1063 return E_INVALIDARG;
1066 mimeType = pwzMimeProposed;
1068 /* Try and find the mime type in the registry */
1070 LPWSTR ext = strrchrW(pwzUrl, '.');
1073 if(!RegOpenKeyExW(HKEY_CLASSES_ROOT, ext, 0, 0, &hKey)) {
1074 if(!RegQueryValueExW(hKey, szContentType, NULL, NULL, (LPBYTE)szTmpMime, &dwSize)) {
1075 mimeType = szTmpMime;
1082 if(!mimeType && pBuffer && cbSize > 0)
1083 mimeType = URLMON_IsBinary(pBuffer, cbSize)?szBinaryMime:szTextMime;
1085 TRACE("Using %s\n", debugstr_w(mimeType));
1086 *ppwzMimeOut = CoTaskMemAlloc((lstrlenW(mimeType)+1)*sizeof(WCHAR));
1087 if(!*ppwzMimeOut) return E_OUTOFMEMORY;
1088 lstrcpyW(*ppwzMimeOut, mimeType);
1092 /***********************************************************************
1093 * IsAsyncMoniker (URLMON.@)
1095 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1099 TRACE("(%p)\n", pmk);
1101 return E_INVALIDARG;
1102 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1103 IUnknown_Release(am);
1109 /***********************************************************************
1110 * RegisterBindStatusCallback (URLMON.@)
1112 * Register a bind status callback.
1115 * pbc [I] Binding context
1116 * pbsc [I] Callback to register
1117 * ppbscPrevious [O] Destination for previous callback
1118 * dwReserved [I] Reserved, must be 0.
1122 * Failure: E_INVALIDARG, if any argument is invalid, or
1123 * E_OUTOFMEMORY if memory allocation fails.
1125 HRESULT WINAPI RegisterBindStatusCallback(
1127 IBindStatusCallback *pbsc,
1128 IBindStatusCallback **ppbscPrevious,
1131 IBindStatusCallback *prev;
1133 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
1135 if (pbc == NULL || pbsc == NULL)
1136 return E_INVALIDARG;
1138 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
1140 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1142 *ppbscPrevious = prev;
1144 IBindStatusCallback_Release(prev);
1147 return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
1150 /***********************************************************************
1151 * RevokeBindStatusCallback (URLMON.@)
1153 * Unregister a bind status callback.
1155 * pbc [I] Binding context
1156 * pbsc [I] Callback to unregister
1160 * Failure: E_INVALIDARG, if any argument is invalid, or
1161 * E_FAIL if pbsc wasn't registered with pbc.
1163 HRESULT WINAPI RevokeBindStatusCallback(
1165 IBindStatusCallback *pbsc)
1167 IBindStatusCallback *callback;
1168 HRESULT hr = E_FAIL;
1170 TRACE("(%p,%p)\n", pbc, pbsc);
1172 if (pbc == NULL || pbsc == NULL)
1173 return E_INVALIDARG;
1175 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
1177 if (callback == pbsc)
1179 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1182 IBindStatusCallback_Release(pbsc);
1188 /***********************************************************************
1189 * ReleaseBindInfo (URLMON.@)
1191 * Release the resources used by the specified BINDINFO structure.
1194 * pbindinfo [I] BINDINFO to release.
1199 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1201 FIXME("(%p)stub!\n", pbindinfo);
1204 /***********************************************************************
1205 * URLDownloadToFileA (URLMON.@)
1207 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1211 * pCaller [I] controlling IUnknown interface.
1212 * szURL [I] URL of the file to download
1213 * szFileName [I] file name to store the content of the URL
1214 * dwReserved [I] reserved - set to 0
1215 * lpfnCB [I] callback for progress report
1219 * E_OUTOFMEMORY when going out of memory
1221 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1225 LPBINDSTATUSCALLBACK lpfnCB)
1227 UNICODE_STRING szURL_w, szFileName_w;
1229 if ((szURL == NULL) || (szFileName == NULL)) {
1230 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1231 return E_INVALIDARG; /* The error code is not specified in this case... */
1234 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1235 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1236 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1238 RtlFreeUnicodeString(&szURL_w);
1239 RtlFreeUnicodeString(&szFileName_w);
1243 RtlFreeUnicodeString(&szURL_w);
1247 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1248 return E_OUTOFMEMORY;
1251 /***********************************************************************
1252 * URLDownloadToFileW (URLMON.@)
1254 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1258 * pCaller [I] controlling IUnknown interface.
1259 * szURL [I] URL of the file to download
1260 * szFileName [I] file name to store the content of the URL
1261 * dwReserved [I] reserved - set to 0
1262 * lpfnCB [I] callback for progress report
1266 * E_OUTOFMEMORY when going out of memory
1268 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1272 LPBINDSTATUSCALLBACK lpfnCB)
1274 HINTERNET hinternet, hcon, hreq;
1276 CHAR buffer[0x1000];
1277 DWORD sz, total, written;
1278 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1279 URL_COMPONENTSW url;
1280 WCHAR host[0x80], path[0x100];
1282 static const WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1284 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1285 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1287 if ((szURL == NULL) || (szFileName == NULL)) {
1288 FIXME(" cannot accept NULL strings !\n");
1289 return E_INVALIDARG;
1292 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1293 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1294 if (hinternet == NULL) {
1295 return E_OUTOFMEMORY;
1298 memset(&url, 0, sizeof(url));
1299 url.dwStructSize = sizeof(url);
1300 url.lpszHostName = host;
1301 url.dwHostNameLength = sizeof(host);
1302 url.lpszUrlPath = path;
1303 url.dwUrlPathLength = sizeof(path);
1305 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1306 InternetCloseHandle(hinternet);
1307 return E_OUTOFMEMORY;
1311 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1312 InternetCloseHandle(hinternet);
1317 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1318 url.lpszUserName, url.lpszPassword,
1319 INTERNET_SERVICE_HTTP, 0, 0);
1321 InternetCloseHandle(hinternet);
1322 return E_OUTOFMEMORY;
1325 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1327 InternetCloseHandle(hinternet);
1328 InternetCloseHandle(hcon);
1329 return E_OUTOFMEMORY;
1332 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1333 InternetCloseHandle(hinternet);
1334 InternetCloseHandle(hcon);
1335 InternetCloseHandle(hreq);
1336 return E_OUTOFMEMORY;
1339 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1340 &total_size, &arg_size, NULL)) {
1341 TRACE(" total size : %ld\n", total_size);
1344 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1345 FILE_ATTRIBUTE_NORMAL, NULL );
1346 if (hfile == INVALID_HANDLE_VALUE) {
1347 return E_ACCESSDENIED;
1351 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1352 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1353 InternetCloseHandle(hreq);
1354 InternetCloseHandle(hcon);
1355 InternetCloseHandle(hinternet);
1363 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1365 InternetCloseHandle(hreq);
1366 InternetCloseHandle(hcon);
1367 InternetCloseHandle(hinternet);
1370 return E_OUTOFMEMORY;
1378 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1379 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1380 InternetCloseHandle(hreq);
1381 InternetCloseHandle(hcon);
1382 InternetCloseHandle(hinternet);
1388 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1389 InternetCloseHandle(hreq);
1390 InternetCloseHandle(hcon);
1391 InternetCloseHandle(hinternet);
1394 return E_OUTOFMEMORY;
1399 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1400 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1401 InternetCloseHandle(hreq);
1402 InternetCloseHandle(hcon);
1403 InternetCloseHandle(hinternet);
1409 InternetCloseHandle(hreq);
1410 InternetCloseHandle(hcon);
1411 InternetCloseHandle(hinternet);
1418 /***********************************************************************
1419 * HlinkSimpleNavigateToString (URLMON.@)
1421 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
1422 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1423 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1425 FIXME("%s\n", debugstr_w( szTarget ) );
1429 /***********************************************************************
1430 * HlinkNavigateString (URLMON.@)
1432 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
1434 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
1435 return HlinkSimpleNavigateToString(
1436 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );