DInput keyboard handling checks for incoming X11 events.
[wine] / dlls / urlmon / umon.c
1 /*
2  * UrlMon
3  *
4  * Copyright 1999 Ulrich Czekalla for Corel Corporation
5  * Copyright 2002 Huw D M Davies for CodeWeavers
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define COM_NO_WINDOWS_H
23 #include <stdio.h>
24
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "objbase.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33 #include "ole2.h"
34 #include "urlmon.h"
35 #include "wininet.h"
36 #include "urlmon_main.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
39
40 /* native urlmon.dll uses this key, too */
41 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
42
43 /*static BOOL registered_wndclass = FALSE;*/
44
45 /* filemoniker data structure */
46 typedef struct URLMonikerImpl{
47
48     ICOM_VTABLE(IMoniker)*  lpvtbl1;  /* VTable relative to the IMoniker interface.*/
49     ICOM_VTABLE(IBinding)*  lpvtbl2;  /* VTable to IBinding interface */
50
51     ULONG ref; /* reference counter for this object */
52
53     LPOLESTR URLName; /* URL string identified by this URLmoniker */
54
55     HWND hwndCallback;
56     IBindCtx *pBC;
57     HINTERNET hinternet, hconnect, hrequest;
58 } URLMonikerImpl;
59
60 /********************************************************************************/
61 /* URLMoniker prototype functions :                                            */
62
63 /* IUnknown prototype functions */
64 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
65 static ULONG   WINAPI URLMonikerImpl_AddRef(IMoniker* iface);
66 static ULONG   WINAPI URLMonikerImpl_Release(IMoniker* iface);
67
68 /* IPersist prototype functions */
69 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
70
71 /* IPersistStream prototype functions */
72 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface);
73 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface, IStream* pStm);
74 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
75 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
76
77 /* IMoniker prototype functions */
78 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
79 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
80 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
81 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
82 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
83 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
84 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
85 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
86 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
87 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
88 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
89 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
90 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
91 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
92 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
93
94 /* IBinding interface to moniker */
95 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject);
96 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface);
97 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface);
98 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface);
99 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface);
100 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface);
101 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority);
102 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority);
103 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved);
104
105 /* Local function used by urlmoniker implementation */
106 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszURL);
107 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface);
108
109 /********************************************************************************/
110 /* Virtual function table for the URLMonikerImpl class which  include IPersist,*/
111 /* IPersistStream and IMoniker functions.                                       */
112 static ICOM_VTABLE(IMoniker) VT_URLMonikerImpl =
113 {
114     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
115     URLMonikerImpl_QueryInterface,
116     URLMonikerImpl_AddRef,
117     URLMonikerImpl_Release,
118     URLMonikerImpl_GetClassID,
119     URLMonikerImpl_IsDirty,
120     URLMonikerImpl_Load,
121     URLMonikerImpl_Save,
122     URLMonikerImpl_GetSizeMax,
123     URLMonikerImpl_BindToObject,
124     URLMonikerImpl_BindToStorage,
125     URLMonikerImpl_Reduce,
126     URLMonikerImpl_ComposeWith,
127     URLMonikerImpl_Enum,
128     URLMonikerImpl_IsEqual,
129     URLMonikerImpl_Hash,
130     URLMonikerImpl_IsRunning,
131     URLMonikerImpl_GetTimeOfLastChange,
132     URLMonikerImpl_Inverse,
133     URLMonikerImpl_CommonPrefixWith,
134     URLMonikerImpl_RelativePathTo,
135     URLMonikerImpl_GetDisplayName,
136     URLMonikerImpl_ParseDisplayName,
137     URLMonikerImpl_IsSystemMoniker
138 };
139
140 static ICOM_VTABLE(IBinding) VTBinding_URLMonikerImpl =
141 {
142     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
143     URLMonikerImpl_IBinding_QueryInterface,
144     URLMonikerImpl_IBinding_AddRef,
145     URLMonikerImpl_IBinding_Release,
146     URLMonikerImpl_IBinding_Abort,
147     URLMonikerImpl_IBinding_Suspend,
148     URLMonikerImpl_IBinding_Resume,
149     URLMonikerImpl_IBinding_SetPriority,
150     URLMonikerImpl_IBinding_GetPriority,
151     URLMonikerImpl_IBinding_GetBindResult
152 };
153
154
155 /*******************************************************************************
156  *        URLMoniker_QueryInterface
157  *******************************************************************************/
158 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
159 {
160     ICOM_THIS(URLMonikerImpl,iface);
161
162     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
163
164     /* Perform a sanity check on the parameters.*/
165     if ( (This==0) || (ppvObject==0) )
166         return E_INVALIDARG;
167
168     /* Initialize the return parameter */
169     *ppvObject = 0;
170
171     /* Compare the riid with the interface IDs implemented by this object.*/
172     if (IsEqualIID(&IID_IUnknown, riid)      ||
173         IsEqualIID(&IID_IPersist, riid)      ||
174         IsEqualIID(&IID_IPersistStream,riid) ||
175         IsEqualIID(&IID_IMoniker, riid)
176        )
177         *ppvObject = iface;
178
179     /* Check that we obtained an interface.*/
180     if ((*ppvObject)==0)
181         return E_NOINTERFACE;
182
183     /* Query Interface always increases the reference count by one when it is successful */
184     URLMonikerImpl_AddRef(iface);
185
186     return S_OK;
187 }
188
189 /******************************************************************************
190  *        URLMoniker_AddRef
191  ******************************************************************************/
192 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
193 {
194     ICOM_THIS(URLMonikerImpl,iface);
195
196     TRACE("(%p)\n",This);
197
198     return ++(This->ref);
199 }
200
201 /******************************************************************************
202  *        URLMoniker_Release
203  ******************************************************************************/
204 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
205 {
206     ICOM_THIS(URLMonikerImpl,iface);
207
208     TRACE("(%p)\n",This);
209
210     This->ref--;
211
212     /* destroy the object if there's no more reference on it */
213     if (This->ref==0){
214
215         URLMonikerImpl_Destroy(This);
216
217         return 0;
218     }
219     return This->ref;
220 }
221
222 /******************************************************************************
223  *        URLMoniker_GetClassID
224  ******************************************************************************/
225 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
226                                                 CLSID *pClassID)/* Pointer to CLSID of object */
227 {
228     ICOM_THIS(URLMonikerImpl,iface);
229
230     FIXME("(%p)->(%p): stub\n",This,pClassID);
231
232     if (pClassID==NULL)
233         return E_POINTER;
234
235     return E_NOTIMPL;
236 }
237
238 /******************************************************************************
239  *        URLMoniker_IsDirty
240  ******************************************************************************/
241 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface)
242 {
243     ICOM_THIS(URLMonikerImpl,iface);
244     /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
245        method in the OLE-provided moniker interfaces always return S_FALSE because
246        their internal state never changes. */
247
248     TRACE("(%p)\n",This);
249
250     return S_FALSE;
251 }
252
253 /******************************************************************************
254  *        URLMoniker_Load
255  ******************************************************************************/
256 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
257 {
258     ICOM_THIS(URLMonikerImpl,iface);
259
260     FIXME("(%p)->(%p): stub\n",This,pStm);
261
262     return E_NOTIMPL;
263 }
264
265 /******************************************************************************
266  *        URLMoniker_Save
267  ******************************************************************************/
268 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
269                                           IStream* pStm,/* pointer to the stream where the object is to be saved */
270                                           BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
271 {
272     ICOM_THIS(URLMonikerImpl,iface);
273
274     FIXME("(%p)->(%p,%d): stub\n",This,pStm,fClearDirty);
275
276     return E_NOTIMPL;
277
278 }
279
280 /******************************************************************************
281  *        URLMoniker_GetSizeMax
282  ******************************************************************************/
283 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
284                                                 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
285 {
286     ICOM_THIS(URLMonikerImpl,iface);
287
288     FIXME("(%p)->(%p): stub\n",This,pcbSize);
289
290     return E_NOTIMPL;
291 }
292
293 /******************************************************************************
294  *         URLMoniker_Construct (local function)
295  *******************************************************************************/
296 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszURLName)
297 {
298     int sizeStr = strlenW(lpszURLName);
299
300     TRACE("(%p,%s)\n",This,debugstr_w(lpszURLName));
301     memset(This, 0, sizeof(*This));
302
303     /* Initialize the virtual fgunction table. */
304     This->lpvtbl1      = &VT_URLMonikerImpl;
305     This->lpvtbl2      = &VTBinding_URLMonikerImpl;
306     This->ref          = 0;
307
308     This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr+1));
309
310     if (This->URLName==NULL)
311         return E_OUTOFMEMORY;
312
313     strcpyW(This->URLName,lpszURLName);
314
315     return S_OK;
316 }
317
318
319
320 /******************************************************************************
321  *        URLMoniker_Destroy (local function)
322  *******************************************************************************/
323 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
324 {
325     TRACE("(%p)\n",This);
326
327     if (This->URLName!=NULL)
328             HeapFree(GetProcessHeap(),0,This->URLName);
329
330     HeapFree(GetProcessHeap(),0,This);
331
332     return S_OK;
333 }
334
335 /******************************************************************************
336  *                  URLMoniker_BindToObject
337  ******************************************************************************/
338 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
339                                                   IBindCtx* pbc,
340                                                   IMoniker* pmkToLeft,
341                                                   REFIID riid,
342                                                   VOID** ppvResult)
343 {
344     ICOM_THIS(URLMonikerImpl,iface);
345
346     *ppvResult=0;
347
348     FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
349           ppvResult);
350
351     return E_NOTIMPL;
352 }
353
354 typedef struct {
355     enum {OnProgress, OnDataAvailable} callback;
356 } URLMON_CallbackData;
357
358
359 #if 0
360 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
361 {
362     return DefWindowProcA(hwnd, msg, wparam, lparam);
363 }
364
365 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
366 {
367 }
368
369 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
370                                              void *status_info, DWORD status_info_len)
371 {
372     URLMonikerImpl *This = (URLMonikerImpl *)context;
373     TRACE("handle %p this %p status %08lx\n", hinet, This, status);
374
375     if(This->filesize == -1) {
376         switch(status) {
377         case INTERNET_STATUS_RESOLVING_NAME:
378             PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
379             break;
380         case INTERNET_STATUS_CONNECTING_TO_SERVER:
381             PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
382             break;
383         case INTERNET_STATUS_SENDING_REQUEST:
384             PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
385             break;
386         case INTERNET_REQUEST_COMPLETE:
387           {
388               DWORD len, lensz = sizeof(len);
389
390             HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
391             TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
392             This->filesize = len;
393             break;
394           }
395         }
396     }
397
398     return;
399 }
400 #endif
401 /******************************************************************************
402  *        URLMoniker_BindToStorage
403  ******************************************************************************/
404 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
405                                                    IBindCtx* pbc,
406                                                    IMoniker* pmkToLeft,
407                                                    REFIID riid,
408                                                    VOID** ppvObject)
409 {
410     ICOM_THIS(URLMonikerImpl,iface);
411     HRESULT hres;
412     IBindStatusCallback *pbscb;
413     BINDINFO bi;
414     DWORD bindf;
415
416     FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
417     if(pmkToLeft) {
418         FIXME("pmkToLeft != NULL\n");
419         return E_NOTIMPL;
420     }
421     if(!IsEqualIID(&IID_IStream, riid)) {
422         FIXME("unsupported iid\n");
423         return E_NOTIMPL;
424     }
425
426     /* FIXME This is a bad hack (tm).  We should clearly download to a temporary file.
427        We also need to implement IStream ourselves so that IStream_Read can return
428        E_PENDING */
429
430     hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
431
432
433     if(SUCCEEDED(hres)) {
434         TRACE("Created dummy stream...\n");
435
436         hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&pbscb);
437         if(SUCCEEDED(hres)) {
438             TRACE("Got IBindStatusCallback...\n");
439
440             memset(&bi, 0, sizeof(bi));
441             bi.cbSize = sizeof(bi);
442             bindf = 0;
443             hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
444             if(SUCCEEDED(hres)) {
445                 URL_COMPONENTSW url;
446                 WCHAR *host, *path;
447                 DWORD len, lensz = sizeof(len), total_read = 0;
448                 LARGE_INTEGER last_read_pos;
449                 FORMATETC fmt;
450                 STGMEDIUM stg;
451
452                 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
453                       bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
454                 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
455                 TRACE("OnStartBinding rets %08lx\n", hres);
456
457 #if 0
458                 if(!registered_wndclass) {
459                     WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
460                     RegisterClassA(&urlmon_wndclass);
461                     registered_wndclass = TRUE;
462                 }
463
464                 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
465                                                    URLMON_hInstance, NULL);
466
467 #endif
468                 memset(&url, 0, sizeof(url));
469                 url.dwStructSize = sizeof(url);
470                 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
471                 InternetCrackUrlW(This->URLName, 0, 0, &url);
472                 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
473                 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
474                 host[url.dwHostNameLength] = '\0';
475                 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
476                 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
477                 path[url.dwUrlPathLength] = '\0';
478
479                 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
480 /*              InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
481
482                 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
483                                             INTERNET_SERVICE_HTTP, 0, (DWORD)This);
484                 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
485
486                 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
487                 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
488                 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
489                 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
490                 hres = E_OUTOFMEMORY; /* FIXME */
491                 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
492
493                     len = 0;
494                     HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
495
496                     TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
497
498                     last_read_pos.s.LowPart = last_read_pos.s.HighPart = 0;
499                     fmt.cfFormat = 0;
500                     fmt.ptd = NULL;
501                     fmt.dwAspect = 0;
502                     fmt.lindex = -1;
503                     fmt.tymed = TYMED_ISTREAM;
504                     stg.tymed = TYMED_ISTREAM;
505                     stg.u.pstm = *(IStream**)ppvObject;
506                     stg.pUnkForRelease = NULL;
507
508                     while(1) {
509                         char buf[4096];
510                         DWORD bufread;
511                         DWORD written;
512                         if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
513                             TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
514                             if(bufread == 0) break;
515                             IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
516                             total_read += bufread;
517                             IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
518                             hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
519                                                                   BINDSTATUS_BEGINDOWNLOADDATA :
520                                                                   BINDSTATUS_DOWNLOADINGDATA, NULL);
521                             hres = IBindStatusCallback_OnDataAvailable(pbscb,
522                                                                        (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
523                                                                        BSCF_INTERMEDIATEDATANOTIFICATION,
524                                                                        total_read, &fmt, &stg);
525                             last_read_pos.s.LowPart += bufread; /* FIXME */
526                         } else
527                             break;
528                     }
529                     hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
530                     hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
531                     TRACE("OnDataAvail rets %08lx\n", hres);
532                     hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
533                     TRACE("OnStop rets %08lx\n", hres);
534                     hres = S_OK;
535                 }
536                 InternetCloseHandle(This->hrequest);
537                 InternetCloseHandle(This->hconnect);
538                 InternetCloseHandle(This->hinternet);
539             }
540         }
541     }
542     return hres;
543 }
544
545 /******************************************************************************
546  *        URLMoniker_Reduce
547  ******************************************************************************/
548 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
549                                             IBindCtx* pbc,
550                                             DWORD dwReduceHowFar,
551                                             IMoniker** ppmkToLeft,
552                                             IMoniker** ppmkReduced)
553 {
554     ICOM_THIS(URLMonikerImpl,iface);
555     FIXME("(%p)->(%p,%ld,%p,%p): stub\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
556
557     return E_NOTIMPL;
558 }
559
560 /******************************************************************************
561  *        URLMoniker_ComposeWith
562  ******************************************************************************/
563 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
564                                                  IMoniker* pmkRight,
565                                                  BOOL fOnlyIfNotGeneric,
566                                                  IMoniker** ppmkComposite)
567 {
568     ICOM_THIS(URLMonikerImpl,iface);
569     FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
570
571     return E_NOTIMPL;
572 }
573
574 /******************************************************************************
575  *        URLMoniker_Enum
576  ******************************************************************************/
577 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
578 {
579     ICOM_THIS(URLMonikerImpl,iface);
580     FIXME("(%p)->(%d,%p): stub\n",This,fForward,ppenumMoniker);
581
582     return E_NOTIMPL;
583 }
584
585 /******************************************************************************
586  *        URLMoniker_IsEqual
587  ******************************************************************************/
588 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
589 {
590     ICOM_THIS(URLMonikerImpl,iface);
591     FIXME("(%p)->(%p): stub\n",This,pmkOtherMoniker);
592
593     return E_NOTIMPL;
594 }
595
596
597 /******************************************************************************
598  *        URLMoniker_Hash
599  ******************************************************************************/
600 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
601 {
602     ICOM_THIS(URLMonikerImpl,iface);
603     FIXME("(%p)->(%p): stub\n",This,pdwHash);
604
605     return E_NOTIMPL;
606 }
607
608 /******************************************************************************
609  *        URLMoniker_IsRunning
610  ******************************************************************************/
611 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
612                                                IBindCtx* pbc,
613                                                IMoniker* pmkToLeft,
614                                                IMoniker* pmkNewlyRunning)
615 {
616     ICOM_THIS(URLMonikerImpl,iface);
617     FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
618
619     return E_NOTIMPL;
620 }
621
622 /******************************************************************************
623  *        URLMoniker_GetTimeOfLastChange
624  ******************************************************************************/
625 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
626                                                          IBindCtx* pbc,
627                                                          IMoniker* pmkToLeft,
628                                                          FILETIME* pFileTime)
629 {
630     ICOM_THIS(URLMonikerImpl,iface);
631     FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
632
633     return E_NOTIMPL;
634 }
635
636 /******************************************************************************
637  *        URLMoniker_Inverse
638  ******************************************************************************/
639 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
640 {
641     ICOM_THIS(URLMonikerImpl,iface);
642     FIXME("(%p)->(%p): stub\n",This,ppmk);
643
644     return E_NOTIMPL;
645 }
646
647 /******************************************************************************
648  *        URLMoniker_CommonPrefixWith
649  ******************************************************************************/
650 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
651 {
652     ICOM_THIS(URLMonikerImpl,iface);
653     FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
654
655     return E_NOTIMPL;
656 }
657
658 /******************************************************************************
659  *        URLMoniker_RelativePathTo
660  ******************************************************************************/
661 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
662 {
663     ICOM_THIS(URLMonikerImpl,iface);
664     FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
665
666     return E_NOTIMPL;
667 }
668
669 /******************************************************************************
670  *        URLMoniker_GetDisplayName
671  ******************************************************************************/
672 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
673                                                     IBindCtx* pbc,
674                                                     IMoniker* pmkToLeft,
675                                                     LPOLESTR *ppszDisplayName)
676 {
677     ICOM_THIS(URLMonikerImpl,iface);
678     FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,ppszDisplayName);
679
680     return E_NOTIMPL;
681 }
682
683 /******************************************************************************
684  *        URLMoniker_ParseDisplayName
685  ******************************************************************************/
686 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
687                                                       IBindCtx* pbc,
688                                                       IMoniker* pmkToLeft,
689                                                       LPOLESTR pszDisplayName,
690                                                       ULONG* pchEaten,
691                                                       IMoniker** ppmkOut)
692 {
693     ICOM_THIS(URLMonikerImpl,iface);
694     FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
695
696     return E_NOTIMPL;
697 }
698
699 /******************************************************************************
700  *        URLMoniker_IsSystemMoniker
701  ******************************************************************************/
702 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
703 {
704     ICOM_THIS(URLMonikerImpl,iface);
705     FIXME("(%p)->(%p)\n",This,pwdMksys);
706
707     return E_NOTIMPL;
708 }
709
710 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
711 {
712     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
713
714     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
715
716     /* Perform a sanity check on the parameters.*/
717     if ( (This==0) || (ppvObject==0) )
718         return E_INVALIDARG;
719
720     /* Initialize the return parameter */
721     *ppvObject = 0;
722
723     /* Compare the riid with the interface IDs implemented by this object.*/
724     if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
725         *ppvObject = iface;
726
727     /* Check that we obtained an interface.*/
728     if ((*ppvObject)==0)
729         return E_NOINTERFACE;
730
731     /* Query Interface always increases the reference count by one when it is successful */
732     URLMonikerImpl_IBinding_AddRef(iface);
733
734     return S_OK;
735
736 }
737
738 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
739 {
740     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
741     TRACE("(%p)\n",This);
742
743     return URLMonikerImpl_AddRef((IMoniker*)This);
744 }
745
746 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
747 {
748     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
749     TRACE("(%p)\n",This);
750
751     return URLMonikerImpl_Release((IMoniker*)This);
752 }
753
754 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
755 {
756     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
757     FIXME("(%p): stub\n", This);
758
759     return E_NOTIMPL;
760 }
761
762 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
763 {
764     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
765     FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
766
767     return E_NOTIMPL;
768 }
769
770 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
771 {
772     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
773     FIXME("(%p)->(%p): stub\n", This, pnPriority);
774
775     return E_NOTIMPL;
776 }
777
778 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
779 {
780     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
781     FIXME("(%p): stub\n", This);
782
783     return E_NOTIMPL;
784 }
785
786 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
787 {
788     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
789     FIXME("(%p)->(%ld): stub\n", This, nPriority);
790
791     return E_NOTIMPL;
792 }
793
794 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
795 {
796     ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
797     FIXME("(%p): stub\n", This);
798
799     return E_NOTIMPL;
800 }
801
802 /***********************************************************************
803  *           CreateAsyncBindCtxEx (URLMON.@)
804  *
805  * Create an asynchronous bind context.
806  *
807  * FIXME
808  *   Not implemented.
809  */
810 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
811     IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
812     DWORD reserved)
813 {
814      FIXME("stub, returns failure\n");
815      return E_INVALIDARG;
816 }
817
818
819 /***********************************************************************
820  *           CreateURLMoniker (URLMON.@)
821  *
822  * Create a url moniker.
823  *
824  * PARAMS
825  *    pmkContext [I] Context
826  *    szURL      [I] Url to create the moniker for
827  *    ppmk       [O] Destination for created moniker.
828  *
829  * RETURNS
830  *    Success: S_OK. ppmk contains the created IMoniker object.
831  *    Failure: MK_E_SYNTAX if szURL is not a valid url, or
832  *             E_OUTOFMEMORY if memory allocation fails.
833  */
834 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
835 {
836     URLMonikerImpl *obj;
837     HRESULT hres;
838     IID iid = IID_IMoniker;
839
840     TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
841
842     if (NULL != pmkContext)
843         FIXME("Non-null pmkContext not implemented\n");
844
845     if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
846         return E_OUTOFMEMORY;
847
848     hres = URLMonikerImpl_Construct(obj, szURL);
849     if(SUCCEEDED(hres))
850         hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
851     else
852         HeapFree(GetProcessHeap(), 0, obj);
853     return hres;
854 }
855
856
857 /***********************************************************************
858  *           CoInternetGetSession (URLMON.@)
859  *
860  * Create a new internet session and return an IInternetSession interface
861  * representing it.
862  *
863  * PARAMS
864  *    dwSessionMode      [I] Mode for the internet session
865  *    ppIInternetSession [O] Destination for creates IInternetSession object
866  *    dwReserved         [I] Reserved, must be 0.
867  *
868  * RETURNS
869  *    Success: S_OK. ppIInternetSession contains the IInternetSession interface.
870  *    Failure: E_INVALIDARG, if any argument is invalid, or
871  *             E_OUTOFMEMORY if memory allocation fails.
872  */
873 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, /*IInternetSession*/void **ppIInternetSession, DWORD dwReserved)
874 {
875     FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
876
877     if(dwSessionMode) {
878       ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
879     }
880
881     if(dwReserved) {
882       ERR("dwReserved: %ld, must be zero\n", dwReserved);
883     }
884
885     *ppIInternetSession=NULL;
886     return E_OUTOFMEMORY;
887 }
888
889 /***********************************************************************
890  *           CoInternetQueryInfo (URLMON.@)
891  *
892  * Retrieves information relevant to a specified URL
893  *
894  * RETURNS
895  *    S_OK                      success
896  *    S_FALSE                   buffer too small
897  *    INET_E_QUERYOPTIONUNKNOWN invalid option
898  *
899  */
900 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
901   DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
902   DWORD dwReserved)
903 {
904   FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
905     QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
906   return S_OK;
907 }
908
909 /***********************************************************************
910  *           FindMimeFromData (URLMON.@)
911  *
912  * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
913  *
914  */
915 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
916    DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
917    LPWSTR* ppwzMimeOut, DWORD dwReserved)
918 {
919   FIXME("stub\n");
920   return E_OUTOFMEMORY;
921 }
922
923 /***********************************************************************
924  *           RegisterBindStatusCallback (URLMON.@)
925  *
926  * Register a bind status callback.
927  *
928  * PARAMS
929  *  pbc           [I] Binding context
930  *  pbsc          [I] Callback to register
931  *  ppbscPrevious [O] Destination for previous callback
932  *  dwReserved    [I] Reserved, must be 0.
933  *
934  * RETURNS
935  *    Success: S_OK.
936  *    Failure: E_INVALIDARG, if any argument is invalid, or
937  *             E_OUTOFMEMORY if memory allocation fails.
938  */
939 HRESULT WINAPI RegisterBindStatusCallback(
940     IBindCtx *pbc,
941     IBindStatusCallback *pbsc,
942     IBindStatusCallback **ppbscPrevious,
943     DWORD dwReserved)
944 {
945     IBindStatusCallback *prev;
946
947         TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
948
949     if (pbc == NULL || pbsc == NULL)
950         return E_INVALIDARG;
951
952     if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&prev)))
953     {
954         IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
955         if (ppbscPrevious)
956             *ppbscPrevious = prev;
957         else
958             IBindStatusCallback_Release(prev);
959     }
960
961         return IBindCtx_RegisterObjectParam(pbc, BSCBHolder, (IUnknown *)pbsc);
962 }
963
964 /***********************************************************************
965  *           RevokeBindStatusCallback (URLMON.@)
966  *
967  * Unregister a bind status callback.
968  *
969  *  pbc           [I] Binding context
970  *  pbsc          [I] Callback to unregister
971  *
972  * RETURNS
973  *    Success: S_OK.
974  *    Failure: E_INVALIDARG, if any argument is invalid, or
975  *             E_FAIL if pbsc wasn't registered with pbc.
976  */
977 HRESULT WINAPI RevokeBindStatusCallback(
978     IBindCtx *pbc,
979     IBindStatusCallback *pbsc)
980 {
981     IBindStatusCallback *callback;
982     HRESULT hr = E_FAIL;
983
984         TRACE("(%p,%p)\n", pbc, pbsc);
985
986     if (pbc == NULL || pbsc == NULL)
987         return E_INVALIDARG;
988
989     if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown **)&callback)))
990     {
991         if (callback == pbsc)
992         {
993             IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
994             hr = S_OK;
995         }
996         IBindStatusCallback_Release(pbsc);
997     }
998
999     return hr;
1000 }
1001
1002 /***********************************************************************
1003  *           ReleaseBindInfo (URLMON.@)
1004  *
1005  * Release the resources used by the specified BINDINFO structure.
1006  *
1007  * PARAMS
1008  *  pbindinfo [I] BINDINFO to release.
1009  *
1010  * RETURNS
1011  *  Nothing.
1012  */
1013 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1014 {
1015     FIXME("(%p)stub!\n", pbindinfo);
1016 }