Get rid of the no longer used ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
[wine/multimedia.git] / dlls / urlmon / umon.c
blobc71230a5f24adb222f9c848fc71445ea3515aea1
1 /*
2 * UrlMon
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
23 #include <stdarg.h>
24 #include <stdio.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "winternl.h"
32 #include "winuser.h"
33 #include "objbase.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "ole2.h"
37 #include "urlmon.h"
38 #include "wininet.h"
39 #include "shlwapi.h"
40 #include "urlmon_main.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
44 /* native urlmon.dll uses this key, too */
45 static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
47 /*static BOOL registered_wndclass = FALSE;*/
49 /* filemoniker data structure */
50 typedef struct URLMonikerImpl{
52 IMonikerVtbl* lpvtbl1; /* VTable relative to the IMoniker interface.*/
53 IBindingVtbl* lpvtbl2; /* VTable to IBinding interface */
55 ULONG ref; /* reference counter for this object */
57 LPOLESTR URLName; /* URL string identified by this URLmoniker */
59 HWND hwndCallback;
60 IBindCtx *pBC;
61 HINTERNET hinternet, hconnect, hrequest;
62 } URLMonikerImpl;
64 /********************************************************************************/
65 /* URLMoniker prototype functions : */
67 /* IUnknown prototype functions */
68 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject);
69 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface);
70 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface);
72 /* IPersist prototype functions */
73 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface, CLSID *pClassID);
75 /* IPersistStream prototype functions */
76 static HRESULT WINAPI URLMonikerImpl_IsDirty(IMoniker* iface);
77 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface, IStream* pStm);
78 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty);
79 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface, ULARGE_INTEGER* pcbSize);
81 /* IMoniker prototype functions */
82 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
83 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvResult);
84 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,IBindCtx* pbc, DWORD dwReduceHowFar,IMoniker** ppmkToLeft, IMoniker** ppmkReduced);
85 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,IMoniker* pmkRight,BOOL fOnlyIfNotGeneric, IMoniker** ppmkComposite);
86 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker);
87 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker);
88 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash);
89 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, IMoniker* pmkNewlyRunning);
90 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, FILETIME* pFileTime);
91 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk);
92 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther, IMoniker** ppmkPrefix);
93 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath);
94 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR *ppszDisplayName);
95 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,IBindCtx* pbc, IMoniker* pmkToLeft, LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut);
96 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys);
98 /* IBinding interface to moniker */
99 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject);
100 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface);
101 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface);
102 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface);
103 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface);
104 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface);
105 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority);
106 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority);
107 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved);
109 /* Local function used by urlmoniker implementation */
110 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* iface, LPCOLESTR lpszLeftURL, LPCOLESTR lpszURL);
111 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* iface);
113 /********************************************************************************/
114 /* Virtual function table for the URLMonikerImpl class which include IPersist,*/
115 /* IPersistStream and IMoniker functions. */
116 static IMonikerVtbl VT_URLMonikerImpl =
118 URLMonikerImpl_QueryInterface,
119 URLMonikerImpl_AddRef,
120 URLMonikerImpl_Release,
121 URLMonikerImpl_GetClassID,
122 URLMonikerImpl_IsDirty,
123 URLMonikerImpl_Load,
124 URLMonikerImpl_Save,
125 URLMonikerImpl_GetSizeMax,
126 URLMonikerImpl_BindToObject,
127 URLMonikerImpl_BindToStorage,
128 URLMonikerImpl_Reduce,
129 URLMonikerImpl_ComposeWith,
130 URLMonikerImpl_Enum,
131 URLMonikerImpl_IsEqual,
132 URLMonikerImpl_Hash,
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 IBindingVtbl VTBinding_URLMonikerImpl =
145 URLMonikerImpl_IBinding_QueryInterface,
146 URLMonikerImpl_IBinding_AddRef,
147 URLMonikerImpl_IBinding_Release,
148 URLMonikerImpl_IBinding_Abort,
149 URLMonikerImpl_IBinding_Suspend,
150 URLMonikerImpl_IBinding_Resume,
151 URLMonikerImpl_IBinding_SetPriority,
152 URLMonikerImpl_IBinding_GetPriority,
153 URLMonikerImpl_IBinding_GetBindResult
157 /*******************************************************************************
158 * URLMoniker_QueryInterface
159 *******************************************************************************/
160 static HRESULT WINAPI URLMonikerImpl_QueryInterface(IMoniker* iface,REFIID riid,void** ppvObject)
162 ICOM_THIS(URLMonikerImpl,iface);
164 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
166 /* Perform a sanity check on the parameters.*/
167 if ( (This==0) || (ppvObject==0) )
168 return E_INVALIDARG;
170 /* Initialize the return parameter */
171 *ppvObject = 0;
173 /* Compare the riid with the interface IDs implemented by this object.*/
174 if (IsEqualIID(&IID_IUnknown, riid) ||
175 IsEqualIID(&IID_IPersist, riid) ||
176 IsEqualIID(&IID_IPersistStream,riid) ||
177 IsEqualIID(&IID_IMoniker, riid)
179 *ppvObject = iface;
181 /* Check that we obtained an interface.*/
182 if ((*ppvObject)==0)
183 return E_NOINTERFACE;
185 /* Query Interface always increases the reference count by one when it is successful */
186 URLMonikerImpl_AddRef(iface);
188 return S_OK;
191 /******************************************************************************
192 * URLMoniker_AddRef
193 ******************************************************************************/
194 static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
196 ICOM_THIS(URLMonikerImpl,iface);
198 TRACE("(%p)\n",This);
200 return ++(This->ref);
203 /******************************************************************************
204 * URLMoniker_Release
205 ******************************************************************************/
206 static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
208 ICOM_THIS(URLMonikerImpl,iface);
210 TRACE("(%p)\n",This);
212 This->ref--;
214 /* destroy the object if there's no more reference on it */
215 if (This->ref==0){
217 URLMonikerImpl_Destroy(This);
219 return 0;
221 return This->ref;
224 /******************************************************************************
225 * URLMoniker_GetClassID
226 ******************************************************************************/
227 static HRESULT WINAPI URLMonikerImpl_GetClassID(IMoniker* iface,
228 CLSID *pClassID)/* Pointer to CLSID of object */
230 ICOM_THIS(URLMonikerImpl,iface);
232 TRACE("(%p,%p)\n",This,pClassID);
234 if (pClassID==NULL)
235 return E_POINTER;
236 /* Windows always returns CLSID_StdURLMoniker */
237 *pClassID = CLSID_StdURLMoniker;
238 return S_OK;
241 /******************************************************************************
242 * URLMoniker_IsDirty
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);
253 return S_FALSE;
256 /******************************************************************************
257 * URLMoniker_Load
259 * NOTE
260 * Writes a ULONG containing length of unicode string, followed
261 * by that many unicode characters
262 ******************************************************************************/
263 static HRESULT WINAPI URLMonikerImpl_Load(IMoniker* iface,IStream* pStm)
265 ICOM_THIS(URLMonikerImpl,iface);
267 HRESULT res;
268 ULONG len;
269 ULONG got;
270 TRACE("(%p,%p)\n",This,pStm);
272 if(!pStm)
273 return E_INVALIDARG;
275 res = IStream_Read(pStm, &len, sizeof(ULONG), &got);
276 if(SUCCEEDED(res)) {
277 if(got == sizeof(ULONG)) {
278 if(This->URLName)
279 HeapFree(GetProcessHeap(), 0, This->URLName);
280 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(len+1));
281 if(!This->URLName)
282 res = E_OUTOFMEMORY;
283 else {
284 res = IStream_Read(pStm, This->URLName, len, NULL);
285 This->URLName[len] = 0;
288 else
289 res = E_FAIL;
291 return res;
294 /******************************************************************************
295 * URLMoniker_Save
296 ******************************************************************************/
297 static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface,
298 IStream* pStm,/* pointer to the stream where the object is to be saved */
299 BOOL fClearDirty)/* Specifies whether to clear the dirty flag */
301 ICOM_THIS(URLMonikerImpl,iface);
303 HRESULT res;
304 ULONG len;
305 TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty);
307 if(!pStm)
308 return E_INVALIDARG;
310 len = strlenW(This->URLName);
311 res=IStream_Write(pStm,&len,sizeof(ULONG),NULL);
312 if(SUCCEEDED(res))
313 res=IStream_Write(pStm,&This->URLName,len*sizeof(WCHAR),NULL);
314 return res;
318 /******************************************************************************
319 * URLMoniker_GetSizeMax
320 ******************************************************************************/
321 static HRESULT WINAPI URLMonikerImpl_GetSizeMax(IMoniker* iface,
322 ULARGE_INTEGER* pcbSize)/* Pointer to size of stream needed to save object */
324 ICOM_THIS(URLMonikerImpl,iface);
326 TRACE("(%p,%p)\n",This,pcbSize);
328 if(!pcbSize)
329 return E_INVALIDARG;
331 pcbSize->u.LowPart = sizeof(ULONG) + (strlenW(This->URLName) * sizeof(WCHAR));
332 pcbSize->u.HighPart = 0;
333 return S_OK;
336 /******************************************************************************
337 * URLMoniker_Construct (local function)
338 *******************************************************************************/
339 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
341 HRESULT hres;
342 DWORD sizeStr;
344 TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
345 memset(This, 0, sizeof(*This));
347 /* Initialize the virtual function table. */
348 This->lpvtbl1 = &VT_URLMonikerImpl;
349 This->lpvtbl2 = &VTBinding_URLMonikerImpl;
350 This->ref = 0;
352 if(lpszLeftURLName) {
353 hres = UrlCombineW(lpszLeftURLName, lpszURLName, NULL, &sizeStr, 0);
354 if(FAILED(hres)) {
355 return hres;
357 sizeStr++;
359 else
360 sizeStr = lstrlenW(lpszURLName)+1;
362 This->URLName=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(sizeStr));
364 if (This->URLName==NULL)
365 return E_OUTOFMEMORY;
367 if(lpszLeftURLName) {
368 hres = UrlCombineW(lpszLeftURLName, lpszURLName, This->URLName, &sizeStr, 0);
369 if(FAILED(hres)) {
370 HeapFree(GetProcessHeap(), 0, This->URLName);
371 return hres;
374 else
375 strcpyW(This->URLName,lpszURLName);
377 return S_OK;
382 /******************************************************************************
383 * URLMoniker_Destroy (local function)
384 *******************************************************************************/
385 static HRESULT URLMonikerImpl_Destroy(URLMonikerImpl* This)
387 TRACE("(%p)\n",This);
389 if (This->URLName!=NULL)
390 HeapFree(GetProcessHeap(),0,This->URLName);
392 HeapFree(GetProcessHeap(),0,This);
394 return S_OK;
397 /******************************************************************************
398 * URLMoniker_BindToObject
399 ******************************************************************************/
400 static HRESULT WINAPI URLMonikerImpl_BindToObject(IMoniker* iface,
401 IBindCtx* pbc,
402 IMoniker* pmkToLeft,
403 REFIID riid,
404 VOID** ppvResult)
406 ICOM_THIS(URLMonikerImpl,iface);
408 *ppvResult=0;
410 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),
411 ppvResult);
413 return E_NOTIMPL;
416 typedef struct {
417 enum {OnProgress, OnDataAvailable} callback;
418 } URLMON_CallbackData;
421 #if 0
422 static LRESULT CALLBACK URLMON_WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
424 return DefWindowProcA(hwnd, msg, wparam, lparam);
427 static void PostOnProgress(URLMonikerImpl *This, UINT progress, UINT maxprogress, DWORD status, LPCWSTR *str)
431 static void CALLBACK URLMON_InternetCallback(HINTERNET hinet, /*DWORD_PTR*/ DWORD context, DWORD status,
432 void *status_info, DWORD status_info_len)
434 URLMonikerImpl *This = (URLMonikerImpl *)context;
435 TRACE("handle %p this %p status %08lx\n", hinet, This, status);
437 if(This->filesize == -1) {
438 switch(status) {
439 case INTERNET_STATUS_RESOLVING_NAME:
440 PostOnProgess(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, status_info);
441 break;
442 case INTERNET_STATUS_CONNECTING_TO_SERVER:
443 PostOnProgress(This, 0, 0, BINDSTATUS_CONNECTING, NULL);
444 break;
445 case INTERNET_STATUS_SENDING_REQUEST:
446 PostOnProgress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
447 break;
448 case INTERNET_REQUEST_COMPLETE:
450 DWORD len, lensz = sizeof(len);
452 HttpQueryInfoW(hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
453 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
454 This->filesize = len;
455 break;
460 return;
462 #endif
463 /******************************************************************************
464 * URLMoniker_BindToStorage
465 ******************************************************************************/
466 static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
467 IBindCtx* pbc,
468 IMoniker* pmkToLeft,
469 REFIID riid,
470 VOID** ppvObject)
472 ICOM_THIS(URLMonikerImpl,iface);
473 HRESULT hres;
474 IBindStatusCallback *pbscb;
475 BINDINFO bi;
476 DWORD bindf;
478 FIXME("(%p)->(%p,%p,%s,%p): stub\n",This,pbc,pmkToLeft,debugstr_guid(riid),ppvObject);
479 if(pmkToLeft) {
480 FIXME("pmkToLeft != NULL\n");
481 return E_NOTIMPL;
483 if(!IsEqualIID(&IID_IStream, riid)) {
484 FIXME("unsupported iid\n");
485 return E_NOTIMPL;
488 /* FIXME This is a bad hack (tm). We should clearly download to a temporary file.
489 We also need to implement IStream ourselves so that IStream_Read can return
490 E_PENDING */
492 hres = CreateStreamOnHGlobal(0, TRUE, (IStream**)ppvObject);
495 if(SUCCEEDED(hres)) {
496 TRACE("Created dummy stream...\n");
498 hres = IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown**)&pbscb);
499 if(SUCCEEDED(hres)) {
500 TRACE("Got IBindStatusCallback...\n");
502 memset(&bi, 0, sizeof(bi));
503 bi.cbSize = sizeof(bi);
504 bindf = 0;
505 hres = IBindStatusCallback_GetBindInfo(pbscb, &bindf, &bi);
506 if(SUCCEEDED(hres)) {
507 URL_COMPONENTSW url;
508 WCHAR *host, *path;
509 DWORD len, lensz = sizeof(len), total_read = 0;
510 LARGE_INTEGER last_read_pos;
511 FORMATETC fmt;
512 STGMEDIUM stg;
514 TRACE("got bindinfo. bindf = %08lx extrainfo = %s bindinfof = %08lx bindverb = %08lx iid %s\n",
515 bindf, debugstr_w(bi.szExtraInfo), bi.grfBindInfoF, bi.dwBindVerb, debugstr_guid(&bi.iid));
516 hres = IBindStatusCallback_OnStartBinding(pbscb, 0, (IBinding*)&This->lpvtbl2);
517 TRACE("OnStartBinding rets %08lx\n", hres);
519 #if 0
520 if(!registered_wndclass) {
521 WNDCLASSA urlmon_wndclass = {0, URLMON_WndProc,0, 0, URLMON_hInstance, 0, 0, 0, NULL, "URLMON_Callback_Window_Class"};
522 RegisterClassA(&urlmon_wndclass);
523 registered_wndclass = TRUE;
526 This->hwndCallback = CreateWindowA("URLMON_Callback_Window_Class", NULL, 0, 0, 0, 0, 0, 0, 0,
527 URLMON_hInstance, NULL);
529 #endif
530 memset(&url, 0, sizeof(url));
531 url.dwStructSize = sizeof(url);
532 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = 1;
533 InternetCrackUrlW(This->URLName, 0, 0, &url);
534 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
535 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
536 host[url.dwHostNameLength] = '\0';
537 path = HeapAlloc(GetProcessHeap(), 0, (url.dwUrlPathLength + 1) * sizeof(WCHAR));
538 memcpy(path, url.lpszUrlPath, url.dwUrlPathLength * sizeof(WCHAR));
539 path[url.dwUrlPathLength] = '\0';
541 This->hinternet = InternetOpenA("User Agent", 0, NULL, NULL, 0 /*INTERNET_FLAG_ASYNC*/);
542 /* InternetSetStatusCallback(This->hinternet, URLMON_InternetCallback);*/
544 This->hconnect = InternetConnectW(This->hinternet, host, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
545 INTERNET_SERVICE_HTTP, 0, (DWORD)This);
546 This->hrequest = HttpOpenRequestW(This->hconnect, NULL, path, NULL, NULL, NULL, 0, (DWORD)This);
548 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, 0x22, NULL);
549 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
550 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_CONNECTING, NULL);
551 hres = IBindStatusCallback_OnProgress(pbscb, 0, 0, BINDSTATUS_SENDINGREQUEST, NULL);
552 hres = E_OUTOFMEMORY; /* FIXME */
553 if(HttpSendRequestW(This->hrequest, NULL, 0, NULL, 0)) {
555 len = 0;
556 HttpQueryInfoW(This->hrequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &len, &lensz, NULL);
558 TRACE("res = %ld gle = %08lx url len = %ld\n", hres, GetLastError(), len);
560 last_read_pos.u.LowPart = last_read_pos.u.HighPart = 0;
561 fmt.cfFormat = 0;
562 fmt.ptd = NULL;
563 fmt.dwAspect = 0;
564 fmt.lindex = -1;
565 fmt.tymed = TYMED_ISTREAM;
566 stg.tymed = TYMED_ISTREAM;
567 stg.u.pstm = *(IStream**)ppvObject;
568 stg.pUnkForRelease = NULL;
570 while(1) {
571 char buf[4096];
572 DWORD bufread;
573 DWORD written;
574 if(InternetReadFile(This->hrequest, buf, sizeof(buf), &bufread)) {
575 TRACE("read %ld bytes %s...\n", bufread, debugstr_an(buf, 10));
576 if(bufread == 0) break;
577 IStream_Write(*(IStream**)ppvObject, buf, bufread, &written);
578 total_read += bufread;
579 IStream_Seek(*(IStream**)ppvObject, last_read_pos, STREAM_SEEK_SET, NULL);
580 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, (total_read == bufread) ?
581 BINDSTATUS_BEGINDOWNLOADDATA :
582 BINDSTATUS_DOWNLOADINGDATA, NULL);
583 hres = IBindStatusCallback_OnDataAvailable(pbscb,
584 (total_read == bufread) ? BSCF_FIRSTDATANOTIFICATION :
585 BSCF_INTERMEDIATEDATANOTIFICATION,
586 total_read, &fmt, &stg);
587 last_read_pos.u.LowPart += bufread; /* FIXME */
588 } else
589 break;
591 hres = IBindStatusCallback_OnProgress(pbscb, total_read, len, BINDSTATUS_ENDDOWNLOADDATA, NULL);
592 hres = IBindStatusCallback_OnDataAvailable(pbscb, BSCF_LASTDATANOTIFICATION, total_read, &fmt, &stg);
593 TRACE("OnDataAvail rets %08lx\n", hres);
594 hres = IBindStatusCallback_OnStopBinding(pbscb, S_OK, NULL);
595 TRACE("OnStop rets %08lx\n", hres);
596 hres = S_OK;
598 InternetCloseHandle(This->hrequest);
599 InternetCloseHandle(This->hconnect);
600 InternetCloseHandle(This->hinternet);
604 return hres;
607 /******************************************************************************
608 * URLMoniker_Reduce
609 ******************************************************************************/
610 static HRESULT WINAPI URLMonikerImpl_Reduce(IMoniker* iface,
611 IBindCtx* pbc,
612 DWORD dwReduceHowFar,
613 IMoniker** ppmkToLeft,
614 IMoniker** ppmkReduced)
616 ICOM_THIS(URLMonikerImpl,iface);
618 TRACE("(%p,%p,%ld,%p,%p)\n",This,pbc,dwReduceHowFar,ppmkToLeft,ppmkReduced);
620 if(!ppmkReduced)
621 return E_INVALIDARG;
623 URLMonikerImpl_AddRef(iface);
624 *ppmkReduced = iface;
625 return MK_S_REDUCED_TO_SELF;
628 /******************************************************************************
629 * URLMoniker_ComposeWith
630 ******************************************************************************/
631 static HRESULT WINAPI URLMonikerImpl_ComposeWith(IMoniker* iface,
632 IMoniker* pmkRight,
633 BOOL fOnlyIfNotGeneric,
634 IMoniker** ppmkComposite)
636 ICOM_THIS(URLMonikerImpl,iface);
637 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
639 return E_NOTIMPL;
642 /******************************************************************************
643 * URLMoniker_Enum
644 ******************************************************************************/
645 static HRESULT WINAPI URLMonikerImpl_Enum(IMoniker* iface,BOOL fForward, IEnumMoniker** ppenumMoniker)
647 ICOM_THIS(URLMonikerImpl,iface);
648 TRACE("(%p,%d,%p)\n",This,fForward,ppenumMoniker);
650 if(!ppenumMoniker)
651 return E_INVALIDARG;
653 /* Does not support sub-monikers */
654 *ppenumMoniker = NULL;
655 return S_OK;
658 /******************************************************************************
659 * URLMoniker_IsEqual
660 ******************************************************************************/
661 static HRESULT WINAPI URLMonikerImpl_IsEqual(IMoniker* iface,IMoniker* pmkOtherMoniker)
663 ICOM_THIS(URLMonikerImpl,iface);
664 CLSID clsid;
665 LPOLESTR urlPath;
666 IBindCtx* bind;
667 HRESULT res;
669 TRACE("(%p,%p)\n",This,pmkOtherMoniker);
671 if(pmkOtherMoniker==NULL)
672 return E_INVALIDARG;
674 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
676 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
677 return S_FALSE;
679 res = CreateBindCtx(0,&bind);
680 if(FAILED(res))
681 return res;
683 res = S_FALSE;
684 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
685 int result = lstrcmpiW(urlPath, This->URLName);
686 CoTaskMemFree(urlPath);
687 if(result == 0)
688 res = S_OK;
690 IUnknown_Release(bind);
691 return res;
695 /******************************************************************************
696 * URLMoniker_Hash
697 ******************************************************************************/
698 static HRESULT WINAPI URLMonikerImpl_Hash(IMoniker* iface,DWORD* pdwHash)
700 ICOM_THIS(URLMonikerImpl,iface);
702 int h = 0,i,skip,len;
703 int off = 0;
704 LPOLESTR val;
706 TRACE("(%p,%p)\n",This,pdwHash);
708 if(!pdwHash)
709 return E_INVALIDARG;
711 val = This->URLName;
712 len = lstrlenW(val);
714 if(len < 16) {
715 for(i = len ; i > 0; i--) {
716 h = (h * 37) + val[off++];
719 else {
720 /* only sample some characters */
721 skip = len / 8;
722 for(i = len; i > 0; i -= skip, off += skip) {
723 h = (h * 39) + val[off];
726 *pdwHash = h;
727 return S_OK;
730 /******************************************************************************
731 * URLMoniker_IsRunning
732 ******************************************************************************/
733 static HRESULT WINAPI URLMonikerImpl_IsRunning(IMoniker* iface,
734 IBindCtx* pbc,
735 IMoniker* pmkToLeft,
736 IMoniker* pmkNewlyRunning)
738 ICOM_THIS(URLMonikerImpl,iface);
739 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
741 return E_NOTIMPL;
744 /******************************************************************************
745 * URLMoniker_GetTimeOfLastChange
746 ******************************************************************************/
747 static HRESULT WINAPI URLMonikerImpl_GetTimeOfLastChange(IMoniker* iface,
748 IBindCtx* pbc,
749 IMoniker* pmkToLeft,
750 FILETIME* pFileTime)
752 ICOM_THIS(URLMonikerImpl,iface);
753 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pFileTime);
755 return E_NOTIMPL;
758 /******************************************************************************
759 * URLMoniker_Inverse
760 ******************************************************************************/
761 static HRESULT WINAPI URLMonikerImpl_Inverse(IMoniker* iface,IMoniker** ppmk)
763 ICOM_THIS(URLMonikerImpl,iface);
764 TRACE("(%p,%p)\n",This,ppmk);
766 return MK_E_NOINVERSE;
769 /******************************************************************************
770 * URLMoniker_CommonPrefixWith
771 ******************************************************************************/
772 static HRESULT WINAPI URLMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** ppmkPrefix)
774 ICOM_THIS(URLMonikerImpl,iface);
775 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
777 return E_NOTIMPL;
780 /******************************************************************************
781 * URLMoniker_RelativePathTo
782 ******************************************************************************/
783 static HRESULT WINAPI URLMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppmkRelPath)
785 ICOM_THIS(URLMonikerImpl,iface);
786 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
788 return E_NOTIMPL;
791 /******************************************************************************
792 * URLMoniker_GetDisplayName
793 ******************************************************************************/
794 static HRESULT WINAPI URLMonikerImpl_GetDisplayName(IMoniker* iface,
795 IBindCtx* pbc,
796 IMoniker* pmkToLeft,
797 LPOLESTR *ppszDisplayName)
799 ICOM_THIS(URLMonikerImpl,iface);
801 int len;
803 TRACE("(%p,%p,%p,%p)\n",This,pbc,pmkToLeft,ppszDisplayName);
805 if(!ppszDisplayName)
806 return E_INVALIDARG;
808 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
809 then look at pmkToLeft to try and complete the URL
811 len = lstrlenW(This->URLName)+1;
812 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
813 if(!*ppszDisplayName)
814 return E_OUTOFMEMORY;
815 lstrcpyW(*ppszDisplayName, This->URLName);
816 return S_OK;
819 /******************************************************************************
820 * URLMoniker_ParseDisplayName
821 ******************************************************************************/
822 static HRESULT WINAPI URLMonikerImpl_ParseDisplayName(IMoniker* iface,
823 IBindCtx* pbc,
824 IMoniker* pmkToLeft,
825 LPOLESTR pszDisplayName,
826 ULONG* pchEaten,
827 IMoniker** ppmkOut)
829 ICOM_THIS(URLMonikerImpl,iface);
830 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
832 return E_NOTIMPL;
835 /******************************************************************************
836 * URLMoniker_IsSystemMoniker
837 ******************************************************************************/
838 static HRESULT WINAPI URLMonikerImpl_IsSystemMoniker(IMoniker* iface,DWORD* pwdMksys)
840 ICOM_THIS(URLMonikerImpl,iface);
841 TRACE("(%p,%p)\n",This,pwdMksys);
843 if(!pwdMksys)
844 return E_INVALIDARG;
846 *pwdMksys = MKSYS_URLMONIKER;
847 return S_OK;
850 static HRESULT WINAPI URLMonikerImpl_IBinding_QueryInterface(IBinding* iface,REFIID riid,void** ppvObject)
852 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
854 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
856 /* Perform a sanity check on the parameters.*/
857 if ( (This==0) || (ppvObject==0) )
858 return E_INVALIDARG;
860 /* Initialize the return parameter */
861 *ppvObject = 0;
863 /* Compare the riid with the interface IDs implemented by this object.*/
864 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IBinding, riid))
865 *ppvObject = iface;
867 /* Check that we obtained an interface.*/
868 if ((*ppvObject)==0)
869 return E_NOINTERFACE;
871 /* Query Interface always increases the reference count by one when it is successful */
872 URLMonikerImpl_IBinding_AddRef(iface);
874 return S_OK;
878 static ULONG WINAPI URLMonikerImpl_IBinding_AddRef(IBinding* iface)
880 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
881 TRACE("(%p)\n",This);
883 return URLMonikerImpl_AddRef((IMoniker*)This);
886 static ULONG WINAPI URLMonikerImpl_IBinding_Release(IBinding* iface)
888 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
889 TRACE("(%p)\n",This);
891 return URLMonikerImpl_Release((IMoniker*)This);
894 static HRESULT WINAPI URLMonikerImpl_IBinding_Abort(IBinding* iface)
896 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
897 FIXME("(%p): stub\n", This);
899 return E_NOTIMPL;
902 static HRESULT WINAPI URLMonikerImpl_IBinding_GetBindResult(IBinding* iface, CLSID* pclsidProtocol, DWORD* pdwResult, LPOLESTR* pszResult, DWORD* pdwReserved)
904 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
905 FIXME("(%p)->(%s, %p, %p, %p): stub\n", This, debugstr_guid(pclsidProtocol), pdwResult, pszResult, pdwReserved);
907 return E_NOTIMPL;
910 static HRESULT WINAPI URLMonikerImpl_IBinding_GetPriority(IBinding* iface, LONG* pnPriority)
912 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
913 FIXME("(%p)->(%p): stub\n", This, pnPriority);
915 return E_NOTIMPL;
918 static HRESULT WINAPI URLMonikerImpl_IBinding_Resume(IBinding* iface)
920 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
921 FIXME("(%p): stub\n", This);
923 return E_NOTIMPL;
926 static HRESULT WINAPI URLMonikerImpl_IBinding_SetPriority(IBinding* iface, LONG nPriority)
928 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
929 FIXME("(%p)->(%ld): stub\n", This, nPriority);
931 return E_NOTIMPL;
934 static HRESULT WINAPI URLMonikerImpl_IBinding_Suspend(IBinding* iface)
936 ICOM_THIS_MULTI(URLMonikerImpl, lpvtbl2, iface);
937 FIXME("(%p): stub\n", This);
939 return E_NOTIMPL;
942 /***********************************************************************
943 * CreateAsyncBindCtx (URLMON.@)
945 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
946 IEnumFORMATETC *format, IBindCtx **pbind)
948 FIXME("stub.\n");
949 return E_INVALIDARG;
951 /***********************************************************************
952 * CreateAsyncBindCtxEx (URLMON.@)
954 * Create an asynchronous bind context.
956 * FIXME
957 * Not implemented.
959 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
960 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
961 DWORD reserved)
963 FIXME("stub, returns failure\n");
964 return E_INVALIDARG;
968 /***********************************************************************
969 * CreateURLMoniker (URLMON.@)
971 * Create a url moniker.
973 * PARAMS
974 * pmkContext [I] Context
975 * szURL [I] Url to create the moniker for
976 * ppmk [O] Destination for created moniker.
978 * RETURNS
979 * Success: S_OK. ppmk contains the created IMoniker object.
980 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
981 * E_OUTOFMEMORY if memory allocation fails.
983 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
985 URLMonikerImpl *obj;
986 HRESULT hres;
987 IID iid = IID_IMoniker;
988 LPOLESTR lefturl = NULL;
990 TRACE("(%p, %s, %p)\n", pmkContext, debugstr_w(szURL), ppmk);
992 if(!(obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj))))
993 return E_OUTOFMEMORY;
995 if(pmkContext) {
996 CLSID clsid;
997 IBindCtx* bind;
998 IMoniker_GetClassID(pmkContext, &clsid);
999 if(IsEqualCLSID(&clsid, &CLSID_StdURLMoniker) && SUCCEEDED(CreateBindCtx(0, &bind))) {
1000 URLMonikerImpl_GetDisplayName(pmkContext, bind, NULL, &lefturl);
1001 IBindCtx_Release(bind);
1005 hres = URLMonikerImpl_Construct(obj, lefturl, szURL);
1006 CoTaskMemFree(lefturl);
1007 if(SUCCEEDED(hres))
1008 hres = URLMonikerImpl_QueryInterface((IMoniker*)obj, &iid, (void**)ppmk);
1009 else
1010 HeapFree(GetProcessHeap(), 0, obj);
1011 return hres;
1015 /***********************************************************************
1016 * CoInternetGetSession (URLMON.@)
1018 * Create a new internet session and return an IInternetSession interface
1019 * representing it.
1021 * PARAMS
1022 * dwSessionMode [I] Mode for the internet session
1023 * ppIInternetSession [O] Destination for creates IInternetSession object
1024 * dwReserved [I] Reserved, must be 0.
1026 * RETURNS
1027 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
1028 * Failure: E_INVALIDARG, if any argument is invalid, or
1029 * E_OUTOFMEMORY if memory allocation fails.
1031 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, IInternetSession **ppIInternetSession, DWORD dwReserved)
1033 FIXME("(%ld, %p, %ld): stub\n", dwSessionMode, ppIInternetSession, dwReserved);
1035 if(dwSessionMode) {
1036 ERR("dwSessionMode: %ld, must be zero\n", dwSessionMode);
1039 if(dwReserved) {
1040 ERR("dwReserved: %ld, must be zero\n", dwReserved);
1043 *ppIInternetSession=NULL;
1044 return E_OUTOFMEMORY;
1047 /***********************************************************************
1048 * CoInternetQueryInfo (URLMON.@)
1050 * Retrieves information relevant to a specified URL
1052 * RETURNS
1053 * S_OK success
1054 * S_FALSE buffer too small
1055 * INET_E_QUERYOPTIONUNKNOWN invalid option
1058 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
1059 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD * pcbBuffer,
1060 DWORD dwReserved)
1062 FIXME("(%s, %x, %lx, %p, %lx, %p, %lx): stub\n", debugstr_w(pwzUrl),
1063 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
1064 return S_OK;
1067 /***********************************************************************
1068 * CoInternetCreateSecurityManager (URLMON.@)
1071 typedef void *IInternetSecurityManager;
1072 HRESULT CoInternetCreateSecurityManager( IServiceProvider *pSP,
1073 IInternetSecurityManager **ppSM, DWORD dwReserved )
1075 FIXME("%p %ld\n", pSP, dwReserved );
1076 return E_NOTIMPL;
1079 static BOOL URLMON_IsBinary(LPVOID pBuffer, DWORD cbSize)
1081 int binarycount = 0;
1082 int i;
1083 unsigned char *buff = pBuffer;
1084 for(i=0; i<cbSize; i++) {
1085 if(buff[i] < 32)
1086 binarycount++;
1088 return binarycount > (cbSize-binarycount);
1091 /***********************************************************************
1092 * FindMimeFromData (URLMON.@)
1094 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
1096 * NOTE
1097 * See http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp
1099 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
1100 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
1101 LPWSTR* ppwzMimeOut, DWORD dwReserved)
1103 static const WCHAR szBinaryMime[] = {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m','\0'};
1104 static const WCHAR szTextMime[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
1105 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
1106 WCHAR szTmpMime[256];
1107 LPCWSTR mimeType = NULL;
1108 HKEY hKey = NULL;
1110 TRACE("(%p,%s,%p,%ld,%s,0x%lx,%p,0x%lx)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
1111 debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
1113 if((!pwzUrl && (!pBuffer || cbSize <= 0)) || !ppwzMimeOut)
1114 return E_INVALIDARG;
1116 if(pwzMimeProposed)
1117 mimeType = pwzMimeProposed;
1118 else {
1119 /* Try and find the mime type in the registry */
1120 if(pwzUrl) {
1121 LPWSTR ext = strrchrW(pwzUrl, '.');
1122 if(ext) {
1123 DWORD dwSize;
1124 if(!RegOpenKeyExW(HKEY_CLASSES_ROOT, ext, 0, 0, &hKey)) {
1125 if(!RegQueryValueExW(hKey, szContentType, NULL, NULL, (LPBYTE)szTmpMime, &dwSize)) {
1126 mimeType = szTmpMime;
1128 RegCloseKey(hKey);
1133 if(!mimeType && pBuffer && cbSize > 0)
1134 mimeType = URLMON_IsBinary(pBuffer, cbSize)?szBinaryMime:szTextMime;
1136 TRACE("Using %s\n", debugstr_w(mimeType));
1137 *ppwzMimeOut = CoTaskMemAlloc((lstrlenW(mimeType)+1)*sizeof(WCHAR));
1138 if(!*ppwzMimeOut) return E_OUTOFMEMORY;
1139 lstrcpyW(*ppwzMimeOut, mimeType);
1140 return S_OK;
1143 /***********************************************************************
1144 * IsAsyncMoniker (URLMON.@)
1146 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
1148 IUnknown *am;
1150 TRACE("(%p)\n", pmk);
1151 if(!pmk)
1152 return E_INVALIDARG;
1153 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
1154 IUnknown_Release(am);
1155 return S_OK;
1157 return S_FALSE;
1160 /***********************************************************************
1161 * RegisterBindStatusCallback (URLMON.@)
1163 * Register a bind status callback.
1165 * PARAMS
1166 * pbc [I] Binding context
1167 * pbsc [I] Callback to register
1168 * ppbscPrevious [O] Destination for previous callback
1169 * dwReserved [I] Reserved, must be 0.
1171 * RETURNS
1172 * Success: S_OK.
1173 * Failure: E_INVALIDARG, if any argument is invalid, or
1174 * E_OUTOFMEMORY if memory allocation fails.
1176 HRESULT WINAPI RegisterBindStatusCallback(
1177 IBindCtx *pbc,
1178 IBindStatusCallback *pbsc,
1179 IBindStatusCallback **ppbscPrevious,
1180 DWORD dwReserved)
1182 IBindStatusCallback *prev;
1184 TRACE("(%p,%p,%p,%lu)\n", pbc, pbsc, ppbscPrevious, dwReserved);
1186 if (pbc == NULL || pbsc == NULL)
1187 return E_INVALIDARG;
1189 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&prev)))
1191 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1192 if (ppbscPrevious)
1193 *ppbscPrevious = prev;
1194 else
1195 IBindStatusCallback_Release(prev);
1198 return IBindCtx_RegisterObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown *)pbsc);
1201 /***********************************************************************
1202 * RevokeBindStatusCallback (URLMON.@)
1204 * Unregister a bind status callback.
1206 * pbc [I] Binding context
1207 * pbsc [I] Callback to unregister
1209 * RETURNS
1210 * Success: S_OK.
1211 * Failure: E_INVALIDARG, if any argument is invalid, or
1212 * E_FAIL if pbsc wasn't registered with pbc.
1214 HRESULT WINAPI RevokeBindStatusCallback(
1215 IBindCtx *pbc,
1216 IBindStatusCallback *pbsc)
1218 IBindStatusCallback *callback;
1219 HRESULT hr = E_FAIL;
1221 TRACE("(%p,%p)\n", pbc, pbsc);
1223 if (pbc == NULL || pbsc == NULL)
1224 return E_INVALIDARG;
1226 if (SUCCEEDED(IBindCtx_GetObjectParam(pbc, (LPOLESTR)BSCBHolder, (IUnknown **)&callback)))
1228 if (callback == pbsc)
1230 IBindCtx_RevokeObjectParam(pbc, (LPOLESTR)BSCBHolder);
1231 hr = S_OK;
1233 IBindStatusCallback_Release(pbsc);
1236 return hr;
1239 /***********************************************************************
1240 * ReleaseBindInfo (URLMON.@)
1242 * Release the resources used by the specified BINDINFO structure.
1244 * PARAMS
1245 * pbindinfo [I] BINDINFO to release.
1247 * RETURNS
1248 * Nothing.
1250 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
1252 FIXME("(%p)stub!\n", pbindinfo);
1255 /***********************************************************************
1256 * URLDownloadToFileA (URLMON.@)
1258 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1259 * report progress.
1261 * PARAMS
1262 * pCaller [I] controlling IUnknown interface.
1263 * szURL [I] URL of the file to download
1264 * szFileName [I] file name to store the content of the URL
1265 * dwReserved [I] reserved - set to 0
1266 * lpfnCB [I] callback for progress report
1268 * RETURNS
1269 * S_OK on success
1270 * E_OUTOFMEMORY when going out of memory
1272 HRESULT WINAPI URLDownloadToFileA(LPUNKNOWN pCaller,
1273 LPCSTR szURL,
1274 LPCSTR szFileName,
1275 DWORD dwReserved,
1276 LPBINDSTATUSCALLBACK lpfnCB)
1278 UNICODE_STRING szURL_w, szFileName_w;
1280 if ((szURL == NULL) || (szFileName == NULL)) {
1281 FIXME("(%p,%s,%s,%08lx,%p) cannot accept NULL strings !\n", pCaller, debugstr_a(szURL), debugstr_a(szFileName), dwReserved, lpfnCB);
1282 return E_INVALIDARG; /* The error code is not specified in this case... */
1285 if (RtlCreateUnicodeStringFromAsciiz(&szURL_w, szURL)) {
1286 if (RtlCreateUnicodeStringFromAsciiz(&szFileName_w, szFileName)) {
1287 HRESULT ret = URLDownloadToFileW(pCaller, szURL_w.Buffer, szFileName_w.Buffer, dwReserved, lpfnCB);
1289 RtlFreeUnicodeString(&szURL_w);
1290 RtlFreeUnicodeString(&szFileName_w);
1292 return ret;
1293 } else {
1294 RtlFreeUnicodeString(&szURL_w);
1298 FIXME("(%p,%s,%s,%08lx,%p) could not allocate W strings !\n", pCaller, szURL, szFileName, dwReserved, lpfnCB);
1299 return E_OUTOFMEMORY;
1302 /***********************************************************************
1303 * URLDownloadToFileW (URLMON.@)
1305 * Downloads URL szURL to rile szFileName and call lpfnCB callback to
1306 * report progress.
1308 * PARAMS
1309 * pCaller [I] controlling IUnknown interface.
1310 * szURL [I] URL of the file to download
1311 * szFileName [I] file name to store the content of the URL
1312 * dwReserved [I] reserved - set to 0
1313 * lpfnCB [I] callback for progress report
1315 * RETURNS
1316 * S_OK on success
1317 * E_OUTOFMEMORY when going out of memory
1319 HRESULT WINAPI URLDownloadToFileW(LPUNKNOWN pCaller,
1320 LPCWSTR szURL,
1321 LPCWSTR szFileName,
1322 DWORD dwReserved,
1323 LPBINDSTATUSCALLBACK lpfnCB)
1325 HINTERNET hinternet, hcon, hreq;
1326 BOOL r;
1327 CHAR buffer[0x1000];
1328 DWORD sz, total, written;
1329 DWORD total_size = 0xFFFFFFFF, arg_size = sizeof(total_size);
1330 URL_COMPONENTSW url;
1331 WCHAR host[0x80], path[0x100];
1332 HANDLE hfile;
1333 static const WCHAR wszAppName[]={'u','r','l','m','o','n','.','d','l','l',0};
1335 /* Note: all error codes would need to be checked agains real Windows behaviour... */
1336 TRACE("(%p,%s,%s,%08lx,%p) stub!\n", pCaller, debugstr_w(szURL), debugstr_w(szFileName), dwReserved, lpfnCB);
1338 if ((szURL == NULL) || (szFileName == NULL)) {
1339 FIXME(" cannot accept NULL strings !\n");
1340 return E_INVALIDARG;
1343 /* Would be better to use the application name here rather than 'urlmon' :-/ */
1344 hinternet = InternetOpenW(wszAppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1345 if (hinternet == NULL) {
1346 return E_OUTOFMEMORY;
1349 memset(&url, 0, sizeof(url));
1350 url.dwStructSize = sizeof(url);
1351 url.lpszHostName = host;
1352 url.dwHostNameLength = sizeof(host);
1353 url.lpszUrlPath = path;
1354 url.dwUrlPathLength = sizeof(path);
1356 if (!InternetCrackUrlW(szURL, 0, 0, &url)) {
1357 InternetCloseHandle(hinternet);
1358 return E_OUTOFMEMORY;
1361 if (lpfnCB) {
1362 if (IBindStatusCallback_OnProgress(lpfnCB, 0, 0, BINDSTATUS_CONNECTING, url.lpszHostName) == E_ABORT) {
1363 InternetCloseHandle(hinternet);
1364 return S_OK;
1368 hcon = InternetConnectW(hinternet, url.lpszHostName, url.nPort,
1369 url.lpszUserName, url.lpszPassword,
1370 INTERNET_SERVICE_HTTP, 0, 0);
1371 if (!hcon) {
1372 InternetCloseHandle(hinternet);
1373 return E_OUTOFMEMORY;
1376 hreq = HttpOpenRequestW(hcon, NULL, url.lpszUrlPath, NULL, NULL, NULL, 0, 0);
1377 if (!hreq) {
1378 InternetCloseHandle(hinternet);
1379 InternetCloseHandle(hcon);
1380 return E_OUTOFMEMORY;
1383 if (!HttpSendRequestW(hreq, NULL, 0, NULL, 0)) {
1384 InternetCloseHandle(hinternet);
1385 InternetCloseHandle(hcon);
1386 InternetCloseHandle(hreq);
1387 return E_OUTOFMEMORY;
1390 if (HttpQueryInfoW(hreq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
1391 &total_size, &arg_size, NULL)) {
1392 TRACE(" total size : %ld\n", total_size);
1395 hfile = CreateFileW(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1396 FILE_ATTRIBUTE_NORMAL, NULL );
1397 if (hfile == INVALID_HANDLE_VALUE) {
1398 return E_ACCESSDENIED;
1401 if (lpfnCB) {
1402 if (IBindStatusCallback_OnProgress(lpfnCB, 0, total_size != 0xFFFFFFFF ? total_size : 0,
1403 BINDSTATUS_BEGINDOWNLOADDATA, szURL) == E_ABORT) {
1404 InternetCloseHandle(hreq);
1405 InternetCloseHandle(hcon);
1406 InternetCloseHandle(hinternet);
1407 CloseHandle(hfile);
1408 return S_OK;
1412 total = 0;
1413 while (1) {
1414 r = InternetReadFile(hreq, buffer, sizeof(buffer), &sz);
1415 if (!r) {
1416 InternetCloseHandle(hreq);
1417 InternetCloseHandle(hcon);
1418 InternetCloseHandle(hinternet);
1420 CloseHandle(hfile);
1421 return E_OUTOFMEMORY;
1423 if (!sz)
1424 break;
1426 total += sz;
1428 if (lpfnCB) {
1429 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1430 BINDSTATUS_DOWNLOADINGDATA, szURL) == E_ABORT) {
1431 InternetCloseHandle(hreq);
1432 InternetCloseHandle(hcon);
1433 InternetCloseHandle(hinternet);
1434 CloseHandle(hfile);
1435 return S_OK;
1439 if (!WriteFile(hfile, buffer, sz, &written, NULL)) {
1440 InternetCloseHandle(hreq);
1441 InternetCloseHandle(hcon);
1442 InternetCloseHandle(hinternet);
1444 CloseHandle(hfile);
1445 return E_OUTOFMEMORY;
1449 if (lpfnCB) {
1450 if (IBindStatusCallback_OnProgress(lpfnCB, total, total_size != 0xFFFFFFFF ? total_size : 0,
1451 BINDSTATUS_ENDDOWNLOADDATA, szURL) == E_ABORT) {
1452 InternetCloseHandle(hreq);
1453 InternetCloseHandle(hcon);
1454 InternetCloseHandle(hinternet);
1455 CloseHandle(hfile);
1456 return S_OK;
1460 InternetCloseHandle(hreq);
1461 InternetCloseHandle(hcon);
1462 InternetCloseHandle(hinternet);
1464 CloseHandle(hfile);
1466 return S_OK;
1469 /***********************************************************************
1470 * HlinkSimpleNavigateToString (URLMON.@)
1472 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
1473 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
1474 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
1476 FIXME("%s\n", debugstr_w( szTarget ) );
1477 return E_NOTIMPL;
1480 /***********************************************************************
1481 * HlinkNavigateString (URLMON.@)
1483 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
1485 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
1486 return HlinkSimpleNavigateToString(
1487 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );