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
.s
.LowPart
= last_read_pos
.s
.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
.s
.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 * CreateAsyncBindCtxEx (URLMON.@)
808 * Create an asynchronous bind context.
813 HRESULT WINAPI
CreateAsyncBindCtxEx(IBindCtx
*ibind
, DWORD options
,
814 IBindStatusCallback
*callback
, IEnumFORMATETC
*format
, IBindCtx
** pbind
,
817 FIXME("stub, returns failure\n");
822 /***********************************************************************
823 * CreateURLMoniker (URLMON.@)
825 * Create a url moniker.
828 * pmkContext [I] Context
829 * szURL [I] Url to create the moniker for
830 * ppmk [O] Destination for created moniker.
833 * Success: S_OK. ppmk contains the created IMoniker object.
834 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
835 * E_OUTOFMEMORY if memory allocation fails.
837 HRESULT WINAPI
CreateURLMoniker(IMoniker
*pmkContext
, LPCWSTR szURL
, IMoniker
**ppmk
)
841 IID iid
= IID_IMoniker
;
843 TRACE("(%p, %s, %p)\n", pmkContext
, debugstr_w(szURL
), ppmk
);
845 if (NULL
!= pmkContext
)
846 FIXME("Non-null pmkContext not implemented\n");
848 if(!(obj
= HeapAlloc(GetProcessHeap(), 0, sizeof(*obj
))))
849 return E_OUTOFMEMORY
;
851 hres
= URLMonikerImpl_Construct(obj
, szURL
);
853 hres
= URLMonikerImpl_QueryInterface((IMoniker
*)obj
, &iid
, (void**)ppmk
);
855 HeapFree(GetProcessHeap(), 0, obj
);
860 /***********************************************************************
861 * CoInternetGetSession (URLMON.@)
863 * Create a new internet session and return an IInternetSession interface
867 * dwSessionMode [I] Mode for the internet session
868 * ppIInternetSession [O] Destination for creates IInternetSession object
869 * dwReserved [I] Reserved, must be 0.
872 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
873 * Failure: E_INVALIDARG, if any argument is invalid, or
874 * E_OUTOFMEMORY if memory allocation fails.
876 HRESULT WINAPI
CoInternetGetSession(DWORD dwSessionMode
, /*IInternetSession*/void **ppIInternetSession
, DWORD dwReserved
)
878 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode
, ppIInternetSession
, dwReserved
);
881 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode
);
885 ERR("dwReserved: %ld, must be zero\n", dwReserved
);
888 *ppIInternetSession
=NULL
;
889 return E_OUTOFMEMORY
;
892 /***********************************************************************
893 * CoInternetQueryInfo (URLMON.@)
895 * Retrieves information relevant to a specified URL
899 * S_FALSE buffer too small
900 * INET_E_QUERYOPTIONUNKNOWN invalid option
903 HRESULT WINAPI
CoInternetQueryInfo(LPCWSTR pwzUrl
, QUERYOPTION QueryOption
,
904 DWORD dwQueryFlags
, LPVOID pvBuffer
, DWORD cbBuffer
, DWORD
* pcbBuffer
,
907 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl
),
908 QueryOption
, dwQueryFlags
, pvBuffer
, cbBuffer
, pcbBuffer
, dwReserved
);
912 /***********************************************************************
913 * FindMimeFromData (URLMON.@)
915 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
918 HRESULT WINAPI
FindMimeFromData(LPBC pBC
, LPCWSTR pwzUrl
, LPVOID pBuffer
,
919 DWORD cbSize
, LPCWSTR pwzMimeProposed
, DWORD dwMimeFlags
,
920 LPWSTR
* ppwzMimeOut
, DWORD dwReserved
)
923 return E_OUTOFMEMORY
;
926 /***********************************************************************
927 * RegisterBindStatusCallback (URLMON.@)
929 * Register a bind status callback.
932 * pbc [I] Binding context
933 * pbsc [I] Callback to register
934 * ppbscPrevious [O] Destination for previous callback
935 * dwReserved [I] Reserved, must be 0.
939 * Failure: E_INVALIDARG, if any argument is invalid, or
940 * E_OUTOFMEMORY if memory allocation fails.
942 HRESULT WINAPI
RegisterBindStatusCallback(
944 IBindStatusCallback
*pbsc
,
945 IBindStatusCallback
**ppbscPrevious
,
948 IBindStatusCallback
*prev
;
950 TRACE("(%p,%p,%p,%lu)\n", pbc
, pbsc
, ppbscPrevious
, dwReserved
);
952 if (pbc
== NULL
|| pbsc
== NULL
)
955 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc
, BSCBHolder
, (IUnknown
**)&prev
)))
957 IBindCtx_RevokeObjectParam(pbc
, BSCBHolder
);
959 *ppbscPrevious
= prev
;
961 IBindStatusCallback_Release(prev
);
964 return IBindCtx_RegisterObjectParam(pbc
, BSCBHolder
, (IUnknown
*)pbsc
);
967 /***********************************************************************
968 * RevokeBindStatusCallback (URLMON.@)
970 * Unregister a bind status callback.
972 * pbc [I] Binding context
973 * pbsc [I] Callback to unregister
977 * Failure: E_INVALIDARG, if any argument is invalid, or
978 * E_FAIL if pbsc wasn't registered with pbc.
980 HRESULT WINAPI
RevokeBindStatusCallback(
982 IBindStatusCallback
*pbsc
)
984 IBindStatusCallback
*callback
;
987 TRACE("(%p,%p)\n", pbc
, pbsc
);
989 if (pbc
== NULL
|| pbsc
== NULL
)
992 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc
, BSCBHolder
, (IUnknown
**)&callback
)))
994 if (callback
== pbsc
)
996 IBindCtx_RevokeObjectParam(pbc
, BSCBHolder
);
999 IBindStatusCallback_Release(pbsc
);
1005 /***********************************************************************
1006 * ReleaseBindInfo (URLMON.@)
1008 * Release the resources used by the specified BINDINFO structure.
1011 * pbindinfo [I] BINDINFO to release.
1016 void WINAPI
ReleaseBindInfo(BINDINFO
* pbindinfo
)
1018 FIXME("(%p)stub!\n", pbindinfo
);
1021 /***********************************************************************
1022 * URLDownloadToFileA (URLMON.@)
1024 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1028 * pCaller [I] controlling IUnknown interface.
1029 * szURL [I] URL of the file to download
1030 * szFileName [I] file name to store the content of the URL
1031 * dwReserved [I] reserved - set to 0
1032 * lpfnCB [I] callback for progress report
1036 * E_OUTOFMEMORY when going out of memory
1038 HRESULT WINAPI
URLDownloadToFileA(LPUNKNOWN pCaller
,
1042 LPBINDSTATUSCALLBACK lpfnCB
)
1044 UNICODE_STRING szURL_w
, szFileName_w
;
1046 if ((szURL
== NULL
) || (szFileName
== NULL
)) {
1047 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller
, debugstr_a(szURL
), debugstr_a(szFileName
), dwReserved
, lpfnCB
);
1048 return E_INVALIDARG
; /* The error code is not specified in this case... */
1051 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w
, szURL
)) {
1052 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w
, szFileName
)) {
1053 HRESULT ret
= URLDownloadToFileW(pCaller
, szURL_w
.Buffer
, szFileName_w
.Buffer
, dwReserved
, lpfnCB
);
1055 RtlFreeUnicodeString(&szURL_w
);
1056 RtlFreeUnicodeString(&szFileName_w
);
1060 RtlFreeUnicodeString(&szURL_w
);
1064 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller
, szURL
, szFileName
, dwReserved
, lpfnCB
);
1065 return E_OUTOFMEMORY
;
1068 /***********************************************************************
1069 * URLDownloadToFileW (URLMON.@)
1071 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1075 * pCaller [I] controlling IUnknown interface.
1076 * szURL [I] URL of the file to download
1077 * szFileName [I] file name to store the content of the URL
1078 * dwReserved [I] reserved - set to 0
1079 * lpfnCB [I] callback for progress report
1083 * E_OUTOFMEMORY when going out of memory
1085 HRESULT WINAPI
URLDownloadToFileW(LPUNKNOWN pCaller
,
1089 LPBINDSTATUSCALLBACK lpfnCB
)
1091 HINTERNET hinternet
, hcon
, hreq
;
1093 CHAR buffer
[0x1000];
1094 DWORD sz
, total
, written
;
1095 DWORD total_size
= 0xFFFFFFFF, arg_size
= sizeof(total_size
);
1096 URL_COMPONENTSW url
;
1097 WCHAR host
[0x80], path
[0x100];
1099 WCHAR wszAppName
[]={'u','r','l','m','o','n','.','d','l','l',0};
1101 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1102 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller
, debugstr_w(szURL
), debugstr_w(szFileName
), dwReserved
, lpfnCB
);
1104 if ((szURL
== NULL
) || (szFileName
== NULL
)) {
1105 FIXME(" cannot accept NULL strings !\n");
1106 return E_INVALIDARG
;
1109 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1110 hinternet
= InternetOpenW(wszAppName
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1111 if (hinternet
== NULL
) {
1112 return E_OUTOFMEMORY
;
1115 memset(&url
, 0, sizeof(url
));
1116 url
.dwStructSize
= sizeof(url
);
1117 url
.lpszHostName
= host
;
1118 url
.dwHostNameLength
= sizeof(host
);
1119 url
.lpszUrlPath
= path
;
1120 url
.dwUrlPathLength
= sizeof(path
);
1122 if (!InternetCrackUrlW(szURL
, 0, 0, &url
)) {
1123 InternetCloseHandle(hinternet
);
1124 return E_OUTOFMEMORY
;
1128 if (IBindStatusCallback_OnProgress(lpfnCB
, 0, 0, BINDSTATUS_CONNECTING
, url
.lpszHostName
) == E_ABORT
) {
1129 InternetCloseHandle(hinternet
);
1134 hcon
= InternetConnectW(hinternet
, url
.lpszHostName
, url
.nPort
,
1135 url
.lpszUserName
, url
.lpszPassword
,
1136 INTERNET_SERVICE_HTTP
, 0, 0);
1138 InternetCloseHandle(hinternet
);
1139 return E_OUTOFMEMORY
;
1142 hreq
= HttpOpenRequestW(hcon
, NULL
, url
.lpszUrlPath
, NULL
, NULL
, NULL
, 0, 0);
1144 InternetCloseHandle(hinternet
);
1145 InternetCloseHandle(hcon
);
1146 return E_OUTOFMEMORY
;
1149 if (!HttpSendRequestW(hreq
, NULL
, 0, NULL
, 0)) {
1150 InternetCloseHandle(hinternet
);
1151 InternetCloseHandle(hcon
);
1152 InternetCloseHandle(hreq
);
1153 return E_OUTOFMEMORY
;
1156 if (HttpQueryInfoW(hreq
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
,
1157 &total_size
, &arg_size
, NULL
)) {
1158 TRACE(" total size : %ld\n", total_size
);
1161 hfile
= CreateFileW(szFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1162 FILE_ATTRIBUTE_NORMAL
, NULL
);
1163 if (hfile
== INVALID_HANDLE_VALUE
) {
1164 return E_ACCESSDENIED
;
1168 if (IBindStatusCallback_OnProgress(lpfnCB
, 0, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1169 BINDSTATUS_BEGINDOWNLOADDATA
, szURL
) == E_ABORT
) {
1170 InternetCloseHandle(hreq
);
1171 InternetCloseHandle(hcon
);
1172 InternetCloseHandle(hinternet
);
1180 r
= InternetReadFile(hreq
, buffer
, sizeof(buffer
), &sz
);
1182 InternetCloseHandle(hreq
);
1183 InternetCloseHandle(hcon
);
1184 InternetCloseHandle(hinternet
);
1187 return E_OUTOFMEMORY
;
1195 if (IBindStatusCallback_OnProgress(lpfnCB
, total
, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1196 BINDSTATUS_DOWNLOADINGDATA
, szURL
) == E_ABORT
) {
1197 InternetCloseHandle(hreq
);
1198 InternetCloseHandle(hcon
);
1199 InternetCloseHandle(hinternet
);
1205 if (!WriteFile(hfile
, buffer
, sz
, &written
, NULL
)) {
1206 InternetCloseHandle(hreq
);
1207 InternetCloseHandle(hcon
);
1208 InternetCloseHandle(hinternet
);
1211 return E_OUTOFMEMORY
;
1216 if (IBindStatusCallback_OnProgress(lpfnCB
, total
, total_size
!= 0xFFFFFFFF ? total_size
: 0,
1217 BINDSTATUS_ENDDOWNLOADDATA
, szURL
) == E_ABORT
) {
1218 InternetCloseHandle(hreq
);
1219 InternetCloseHandle(hcon
);
1220 InternetCloseHandle(hinternet
);
1226 InternetCloseHandle(hreq
);
1227 InternetCloseHandle(hcon
);
1228 InternetCloseHandle(hinternet
);