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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
39 #include "urlmon_main.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
43 /* native urlmon.dll uses this key, too */
44 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
46 /*static BOOL registered_wndclass = FALSE;*/
48 /* filemoniker data structure */
49 typedef struct URLMonikerImpl{
51 ICOM_VTABLE(IMoniker)* lpvtbl1; /* VTable relative to the IMoniker interface.*/
52 ICOM_VTABLE(IBinding)* lpvtbl2; /* VTable to IBinding interface */
54 ULONG ref; /* reference counter for this object */
56 LPOLESTR URLName; /* URL string identified by this URLmoniker */
60 HINTERNET hinternet, hconnect, hrequest;
63 /********************************************************************************/
64 /* URLMoniker prototype functions : */
66 /* IUnknown prototype functions */
67 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
68 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface);
69 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface);
71 /* IPersist prototype functions */
72 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
74 /* IPersistStream prototype functions */
75 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface);
76 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface, IStream* pStm);
77 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
78 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
80 /* IMoniker prototype functions */
81 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
82 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
83 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
84 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
85 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
86 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
87 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
88 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
89 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
90 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
91 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
92 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
93 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
94 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
95 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
97 /* IBinding interface to moniker */
98 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject);
99 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface);
100 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface);
101 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface);
102 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface);
103 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface);
104 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority);
105 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority);
106 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved);
108 /* Local function used by urlmoniker implementation */
109 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszURL);
110 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface);
112 /********************************************************************************/
113 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
114 /* IPersistStream and IMoniker functions. */
115 static ICOM_VTABLE(IMoniker) VT_URLMonikerImpl =
117 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
118 URLMonikerImpl_QueryInterface,
119 URLMonikerImpl_AddRef,
120 URLMonikerImpl_Release,
121 URLMonikerImpl_GetClassID,
122 URLMonikerImpl_IsDirty,
125 URLMonikerImpl_GetSizeMax,
126 URLMonikerImpl_BindToObject,
127 URLMonikerImpl_BindToStorage,
128 URLMonikerImpl_Reduce,
129 URLMonikerImpl_ComposeWith,
131 URLMonikerImpl_IsEqual,
133 URLMonikerImpl_IsRunning,
134 URLMonikerImpl_GetTimeOfLastChange,
135 URLMonikerImpl_Inverse,
136 URLMonikerImpl_CommonPrefixWith,
137 URLMonikerImpl_RelativePathTo,
138 URLMonikerImpl_GetDisplayName,
139 URLMonikerImpl_ParseDisplayName,
140 URLMonikerImpl_IsSystemMoniker
143 static ICOM_VTABLE(IBinding) VTBinding_URLMonikerImpl =
145 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
146 URLMonikerImpl_IBinding_QueryInterface,
147 URLMonikerImpl_IBinding_AddRef,
148 URLMonikerImpl_IBinding_Release,
149 URLMonikerImpl_IBinding_Abort,
150 URLMonikerImpl_IBinding_Suspend,
151 URLMonikerImpl_IBinding_Resume,
152 URLMonikerImpl_IBinding_SetPriority,
153 URLMonikerImpl_IBinding_GetPriority,
154 URLMonikerImpl_IBinding_GetBindResult
158 /*******************************************************************************
159 * URLMoniker_QueryInterface
160 *******************************************************************************/
161 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
163 ICOM_THIS(URLMonikerImpl,iface);
165 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
167 /* Perform a sanity check on the parameters.*/
168 if ( (This==0) || (ppvObject==0) )
171 /* Initialize the return parameter */
174 /* Compare the riid with the interface IDs implemented by this object.*/
175 if (IsEqualIID(&IID_IUnknown, riid) ||
176 IsEqualIID(&IID_IPersist, riid) ||
177 IsEqualIID(&IID_IPersistStream,riid) ||
178 IsEqualIID(&IID_IMoniker, riid)
182 /* Check that we obtained an interface.*/
184 return E_NOINTERFACE;
186 /* Query Interface always increases the reference count by one when it is successful */
187 URLMonikerImpl_AddRef(iface);
192 /******************************************************************************
194 ******************************************************************************/
195 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
197 ICOM_THIS(URLMonikerImpl,iface);
199 TRACE("(%p)\n",This);
201 return ++(This->ref);
204 /******************************************************************************
206 ******************************************************************************/
207 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
209 ICOM_THIS(URLMonikerImpl,iface);
211 TRACE("(%p)\n",This);
215 /* destroy the object if there's no more reference on it */
218 URLMonikerImpl_Destroy(This);
225 /******************************************************************************
226 * URLMoniker_GetClassID
227 ******************************************************************************/
228 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
229 CLSID *pClassID)/* Pointer to CLSID of object */
231 ICOM_THIS(URLMonikerImpl,iface);
233 FIXME("(%p)->(%p): stub\n",This,pClassID);
241 /******************************************************************************
243 ******************************************************************************/
244 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
246 ICOM_THIS(URLMonikerImpl,iface);
247 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
248 method in the OLE-provided moniker interfaces always return S_FALSE because
249 their internal state never changes. */
251 TRACE("(%p)\n",This);
256 /******************************************************************************
258 ******************************************************************************/
259 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
261 ICOM_THIS(URLMonikerImpl,iface);
263 FIXME("(%p)->(%p): stub\n",This,pStm);
268 /******************************************************************************
270 ******************************************************************************/
271 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
272 IStream* pStm,/* pointer to the stream where the object is to be saved */
273 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
275 ICOM_THIS(URLMonikerImpl,iface);
277 FIXME("(%p)->(%p,%d): stub\n",This,pStm,fClearDirty);
283 /******************************************************************************
284 * URLMoniker_GetSizeMax
285 ******************************************************************************/
286 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
287 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
289 ICOM_THIS(URLMonikerImpl,iface);
291 FIXME("(%p)->(%p): stub\n",This,pcbSize);
296 /******************************************************************************
297 * URLMoniker_Construct (local function)
298 *******************************************************************************/
299 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszURLName)
301 int sizeStr = strlenW(lpszURLName);
303 TRACE("(%p,%s)\n",This,debugstr_w(lpszURLName));
304 memset(This, 0, sizeof(*This));
306 /* Initialize the virtual fgunction table. */
307 This->lpvtbl1 = &VT_URLMonikerImpl;
308 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
311 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
313 if (This->URLName==NULL)
314 return E_OUTOFMEMORY;
316 strcpyW(This->URLName,lpszURLName);
323 /******************************************************************************
324 * URLMoniker_Destroy (local function)
325 *******************************************************************************/
326 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
328 TRACE("(%p)\n",This);
330 if (This->URLName!=NULL)
331 HeapFree(GetProcessHeap(),0,This->URLName);
333 HeapFree(GetProcessHeap(),0,This);
338 /******************************************************************************
339 * URLMoniker_BindToObject
340 ******************************************************************************/
341 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
347 ICOM_THIS(URLMonikerImpl,iface);
351 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
358 enum {OnProgress, OnDataAvailable} callback;
359 } URLMON_CallbackData;
363 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
365 return DefWindowProcA(hwnd, msg, wparam, lparam);
368 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
372 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
373 void *status_info, DWORD status_info_len)
375 URLMonikerImpl *This = (URLMonikerImpl *)context;
376 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
378 if(This->filesize == -1) {
380 case INTERNET_STATUS_RESOLVING_NAME:
381 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
383 case INTERNET_STATUS_CONNECTING_TO_SERVER:
384 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
386 case INTERNET_STATUS_SENDING_REQUEST:
387 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
389 case INTERNET_REQUEST_COMPLETE:
391 DWORD len, lensz = sizeof(len);
393 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
394 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
395 This->filesize = len;
404 /******************************************************************************
405 * URLMoniker_BindToStorage
406 ******************************************************************************/
407 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
413 ICOM_THIS(URLMonikerImpl,iface);
415 IBindStatusCallback *pbscb;
419 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
421 FIXME("pmkToLeft != NULL\n");
424 if(!IsEqualIID(&IID_IStream, riid)) {
425 FIXME("unsupported iid\n");
429 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
430 We also need to implement IStream ourselves so that IStream_Read can return
433 hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
436 if(SUCCEEDED(hres)) {
437 TRACE("Created dummy stream...\n");
439 hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&pbscb);
440 if(SUCCEEDED(hres)) {
441 TRACE("Got IBindStatusCallback...\n");
443 memset(&bi, 0, sizeof(bi));
444 bi.cbSize = sizeof(bi);
446 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
447 if(SUCCEEDED(hres)) {
450 DWORD len, lensz = sizeof(len), total_read = 0;
451 LARGE_INTEGER last_read_pos;
455 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
456 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
457 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
458 TRACE("OnStartBinding rets %08lx\n", hres);
461 if(!registered_wndclass) {
462 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
463 RegisterClassA(&urlmon_wndclass);
464 registered_wndclass = TRUE;
467 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
468 URLMON_hInstance, NULL);
471 memset(&url, 0, sizeof(url));
472 url.dwStructSize = sizeof(url);
473 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
474 InternetCrackUrlW(This->URLName, 0, 0, &url);
475 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
476 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
477 host[url.dwHostNameLength] = '\0';
478 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
479 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
480 path[url.dwUrlPathLength] = '\0';
482 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
483 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
485 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
486 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
487 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
489 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
490 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
491 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
492 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
493 hres = E_OUTOFMEMORY; /* FIXME */
494 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
497 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
499 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
501 last_read_pos.u.LowPart = last_read_pos.u.HighPart = 0;
506 fmt.tymed = TYMED_ISTREAM;
507 stg.tymed = TYMED_ISTREAM;
508 stg.u.pstm = *(IStream**)ppvObject;
509 stg.pUnkForRelease = NULL;
515 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
516 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
517 if(bufread == 0) break;
518 IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
519 total_read += bufread;
520 IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
521 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
522 BINDSTATUS_BEGINDOWNLOADDATA :
523 BINDSTATUS_DOWNLOADINGDATA, NULL);
524 hres = IBindStatusCallback_OnDataAvailable(pbscb,
525 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
526 BSCF_INTERMEDIATEDATANOTIFICATION,
527 total_read, &fmt, &stg);
528 last_read_pos.u.LowPart += bufread; /* FIXME */
532 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
533 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
534 TRACE("OnDataAvail rets %08lx\n", hres);
535 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
536 TRACE("OnStop rets %08lx\n", hres);
539 InternetCloseHandle(This->hrequest);
540 InternetCloseHandle(This->hconnect);
541 InternetCloseHandle(This->hinternet);
548 /******************************************************************************
550 ******************************************************************************/
551 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
553 DWORD dwReduceHowFar,
554 IMoniker** ppmkToLeft,
555 IMoniker** ppmkReduced)
557 ICOM_THIS(URLMonikerImpl,iface);
558 FIXME("(%p)->(%p,%ld,%p,%p): stub\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
563 /******************************************************************************
564 * URLMoniker_ComposeWith
565 ******************************************************************************/
566 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
568 BOOL fOnlyIfNotGeneric,
569 IMoniker** ppmkComposite)
571 ICOM_THIS(URLMonikerImpl,iface);
572 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
577 /******************************************************************************
579 ******************************************************************************/
580 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
582 ICOM_THIS(URLMonikerImpl,iface);
583 FIXME("(%p)->(%d,%p): stub\n",This,fForward,ppenumMoniker);
588 /******************************************************************************
590 ******************************************************************************/
591 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
593 ICOM_THIS(URLMonikerImpl,iface);
594 FIXME("(%p)->(%p): stub\n",This,pmkOtherMoniker);
600 /******************************************************************************
602 ******************************************************************************/
603 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
605 ICOM_THIS(URLMonikerImpl,iface);
606 FIXME("(%p)->(%p): stub\n",This,pdwHash);
611 /******************************************************************************
612 * URLMoniker_IsRunning
613 ******************************************************************************/
614 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
617 IMoniker* pmkNewlyRunning)
619 ICOM_THIS(URLMonikerImpl,iface);
620 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
625 /******************************************************************************
626 * URLMoniker_GetTimeOfLastChange
627 ******************************************************************************/
628 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
633 ICOM_THIS(URLMonikerImpl,iface);
634 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
639 /******************************************************************************
641 ******************************************************************************/
642 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
644 ICOM_THIS(URLMonikerImpl,iface);
645 FIXME("(%p)->(%p): stub\n",This,ppmk);
650 /******************************************************************************
651 * URLMoniker_CommonPrefixWith
652 ******************************************************************************/
653 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
655 ICOM_THIS(URLMonikerImpl,iface);
656 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
661 /******************************************************************************
662 * URLMoniker_RelativePathTo
663 ******************************************************************************/
664 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
666 ICOM_THIS(URLMonikerImpl,iface);
667 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
672 /******************************************************************************
673 * URLMoniker_GetDisplayName
674 ******************************************************************************/
675 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
678 LPOLESTR *ppszDisplayName)
680 ICOM_THIS(URLMonikerImpl,iface);
681 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,ppszDisplayName);
686 /******************************************************************************
687 * URLMoniker_ParseDisplayName
688 ******************************************************************************/
689 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
692 LPOLESTR pszDisplayName,
696 ICOM_THIS(URLMonikerImpl,iface);
697 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
702 /******************************************************************************
703 * URLMoniker_IsSystemMoniker
704 ******************************************************************************/
705 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
707 ICOM_THIS(URLMonikerImpl,iface);
708 FIXME("(%p)->(%p)\n",This,pwdMksys);
713 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
715 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
717 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
719 /* Perform a sanity check on the parameters.*/
720 if ( (This==0) || (ppvObject==0) )
723 /* Initialize the return parameter */
726 /* Compare the riid with the interface IDs implemented by this object.*/
727 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
730 /* Check that we obtained an interface.*/
732 return E_NOINTERFACE;
734 /* Query Interface always increases the reference count by one when it is successful */
735 URLMonikerImpl_IBinding_AddRef(iface);
741 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
743 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
744 TRACE("(%p)\n",This);
746 return URLMonikerImpl_AddRef((IMoniker*)This);
749 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
751 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
752 TRACE("(%p)\n",This);
754 return URLMonikerImpl_Release((IMoniker*)This);
757 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
759 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
760 FIXME("(%p): stub\n", This);
765 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
767 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
768 FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
773 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
775 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
776 FIXME("(%p)->(%p): stub\n", This, pnPriority);
781 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
783 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
784 FIXME("(%p): stub\n", This);
789 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
791 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
792 FIXME("(%p)->(%ld): stub\n", This, nPriority);
797 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
799 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
800 FIXME("(%p): stub\n", This);
805 /***********************************************************************
806 * CreateAsyncBindCtx (URLMON.@)
808 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
809 IEnumFORMATETC *format, IBindCtx **pbind)
814 /***********************************************************************
815 * CreateAsyncBindCtxEx (URLMON.@)
817 * Create an asynchronous bind context.
822 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
823 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
826 FIXME("stub, returns failure\n");
831 /***********************************************************************
832 * CreateURLMoniker (URLMON.@)
834 * Create a url moniker.
837 * pmkContext [I] Context
838 * szURL [I] Url to create the moniker for
839 * ppmk [O] Destination for created moniker.
842 * Success: S_OK. ppmk contains the created IMoniker object.
843 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
844 * E_OUTOFMEMORY if memory allocation fails.
846 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
850 IID iid = IID_IMoniker;
852 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
854 if (NULL != pmkContext)
855 FIXME("Non-null pmkContext not implemented\n");
857 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
858 return E_OUTOFMEMORY;
860 hres = URLMonikerImpl_Construct(obj, szURL);
862 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
864 HeapFree(GetProcessHeap(), 0, obj);
869 /***********************************************************************
870 * CoInternetGetSession (URLMON.@)
872 * Create a new internet session and return an IInternetSession interface
876 * dwSessionMode [I] Mode for the internet session
877 * ppIInternetSession [O] Destination for creates IInternetSession object
878 * dwReserved [I] Reserved, must be 0.
881 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
882 * Failure: E_INVALIDARG, if any argument is invalid, or
883 * E_OUTOFMEMORY if memory allocation fails.
885 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, /*IInternetSession*/void **ppIInternetSession, DWORD dwReserved)
887 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
890 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
894 ERR("dwReserved: %ld, must be zero\n", dwReserved);
897 *ppIInternetSession=NULL;
898 return E_OUTOFMEMORY;
901 /***********************************************************************
902 * CoInternetQueryInfo (URLMON.@)
904 * Retrieves information relevant to a specified URL
908 * S_FALSE buffer too small
909 * INET_E_QUERYOPTIONUNKNOWN invalid option
912 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
913 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
916 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
917 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
921 /***********************************************************************
922 * FindMimeFromData (URLMON.@)
924 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
927 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
928 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
929 LPWSTR* ppwzMimeOut, DWORD dwReserved)
932 return E_OUTOFMEMORY;
935 /***********************************************************************
936 * IsAsyncMoniker (URLMON.@)
938 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
944 /***********************************************************************
945 * RegisterBindStatusCallback (URLMON.@)
947 * Register a bind status callback.
950 * pbc [I] Binding context
951 * pbsc [I] Callback to register
952 * ppbscPrevious [O] Destination for previous callback
953 * dwReserved [I] Reserved, must be 0.
957 * Failure: E_INVALIDARG, if any argument is invalid, or
958 * E_OUTOFMEMORY if memory allocation fails.
960 HRESULT WINAPI RegisterBindStatusCallback(
962 IBindStatusCallback *pbsc,
963 IBindStatusCallback **ppbscPrevious,
966 IBindStatusCallback *prev;
968 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
970 if (pbc == NULL || pbsc == NULL)
973 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&prev)))
975 IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
977 *ppbscPrevious = prev;
979 IBindStatusCallback_Release(prev);
982 return IBindCtx_RegisterObjectParam(pbc, BSCBHolder, (IUnknown *)pbsc);
985 /***********************************************************************
986 * RevokeBindStatusCallback (URLMON.@)
988 * Unregister a bind status callback.
990 * pbc [I] Binding context
991 * pbsc [I] Callback to unregister
995 * Failure: E_INVALIDARG, if any argument is invalid, or
996 * E_FAIL if pbsc wasn't registered with pbc.
998 HRESULT WINAPI RevokeBindStatusCallback(
1000 IBindStatusCallback *pbsc)
1002 IBindStatusCallback *callback;
1003 HRESULT hr = E_FAIL;
1005 TRACE("(%p,%p)\n", pbc, pbsc);
1007 if (pbc == NULL || pbsc == NULL)
1008 return E_INVALIDARG;
1010 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&callback)))
1012 if (callback == pbsc)
1014 IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
1017 IBindStatusCallback_Release(pbsc);
1023 /***********************************************************************
1024 * ReleaseBindInfo (URLMON.@)
1026 * Release the resources used by the specified BINDINFO structure.
1029 * pbindinfo [I] BINDINFO to release.
1034 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1036 FIXME("(%p)stub!\n", pbindinfo);
1039 /***********************************************************************
1040 * URLDownloadToFileA (URLMON.@)
1042 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1046 * pCaller [I] controlling IUnknown interface.
1047 * szURL [I] URL of the file to download
1048 * szFileName [I] file name to store the content of the URL
1049 * dwReserved [I] reserved - set to 0
1050 * lpfnCB [I] callback for progress report
1054 * E_OUTOFMEMORY when going out of memory
1056 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1060 LPBINDSTATUSCALLBACK lpfnCB)
1062 UNICODE_STRING szURL_w, szFileName_w;
1064 if ((szURL == NULL) || (szFileName == NULL)) {
1065 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1066 return E_INVALIDARG; /* The error code is not specified in this case... */
1069 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1070 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1071 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1073 RtlFreeUnicodeString(&szURL_w);
1074 RtlFreeUnicodeString(&szFileName_w);
1078 RtlFreeUnicodeString(&szURL_w);
1082 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1083 return E_OUTOFMEMORY;
1086 /***********************************************************************
1087 * URLDownloadToFileW (URLMON.@)
1089 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1093 * pCaller [I] controlling IUnknown interface.
1094 * szURL [I] URL of the file to download
1095 * szFileName [I] file name to store the content of the URL
1096 * dwReserved [I] reserved - set to 0
1097 * lpfnCB [I] callback for progress report
1101 * E_OUTOFMEMORY when going out of memory
1103 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1107 LPBINDSTATUSCALLBACK lpfnCB)
1109 HINTERNET hinternet, hcon, hreq;
1111 CHAR buffer[0x1000];
1112 DWORD sz, total, written;
1113 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1114 URL_COMPONENTSW url;
1115 WCHAR host[0x80], path[0x100];
1117 WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1119 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1120 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1122 if ((szURL == NULL) || (szFileName == NULL)) {
1123 FIXME(" cannot accept NULL strings !\n");
1124 return E_INVALIDARG;
1127 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1128 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1129 if (hinternet == NULL) {
1130 return E_OUTOFMEMORY;
1133 memset(&url, 0, sizeof(url));
1134 url.dwStructSize = sizeof(url);
1135 url.lpszHostName = host;
1136 url.dwHostNameLength = sizeof(host);
1137 url.lpszUrlPath = path;
1138 url.dwUrlPathLength = sizeof(path);
1140 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1141 InternetCloseHandle(hinternet);
1142 return E_OUTOFMEMORY;
1146 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1147 InternetCloseHandle(hinternet);
1152 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1153 url.lpszUserName, url.lpszPassword,
1154 INTERNET_SERVICE_HTTP, 0, 0);
1156 InternetCloseHandle(hinternet);
1157 return E_OUTOFMEMORY;
1160 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1162 InternetCloseHandle(hinternet);
1163 InternetCloseHandle(hcon);
1164 return E_OUTOFMEMORY;
1167 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1168 InternetCloseHandle(hinternet);
1169 InternetCloseHandle(hcon);
1170 InternetCloseHandle(hreq);
1171 return E_OUTOFMEMORY;
1174 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1175 &total_size, &arg_size, NULL)) {
1176 TRACE(" total size : %ld\n", total_size);
1179 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1180 FILE_ATTRIBUTE_NORMAL, NULL );
1181 if (hfile == INVALID_HANDLE_VALUE) {
1182 return E_ACCESSDENIED;
1186 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1187 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1188 InternetCloseHandle(hreq);
1189 InternetCloseHandle(hcon);
1190 InternetCloseHandle(hinternet);
1198 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1200 InternetCloseHandle(hreq);
1201 InternetCloseHandle(hcon);
1202 InternetCloseHandle(hinternet);
1205 return E_OUTOFMEMORY;
1213 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1214 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1215 InternetCloseHandle(hreq);
1216 InternetCloseHandle(hcon);
1217 InternetCloseHandle(hinternet);
1223 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1224 InternetCloseHandle(hreq);
1225 InternetCloseHandle(hcon);
1226 InternetCloseHandle(hinternet);
1229 return E_OUTOFMEMORY;
1234 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1235 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1236 InternetCloseHandle(hreq);
1237 InternetCloseHandle(hcon);
1238 InternetCloseHandle(hinternet);
1244 InternetCloseHandle(hreq);
1245 InternetCloseHandle(hcon);
1246 InternetCloseHandle(hinternet);