4 * Copyright 1999 Ulrich Czekalla for Corel Corporation
5 * Copyright 2002 Huw D M Davies for CodeWeavers
6 * Copyright 2005 Jacek Caban for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "urlmon_main.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
35 IMoniker IMoniker_iface
;
36 IUriContainer IUriContainer_iface
;
44 static inline URLMoniker
*impl_from_IMoniker(IMoniker
*iface
)
46 return CONTAINING_RECORD(iface
, URLMoniker
, IMoniker_iface
);
49 static HRESULT WINAPI
URLMoniker_QueryInterface(IMoniker
*iface
, REFIID riid
, void **ppv
)
51 URLMoniker
*This
= impl_from_IMoniker(iface
);
56 if(IsEqualIID(&IID_IUnknown
, riid
)) {
57 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
59 }else if(IsEqualIID(&IID_IPersist
, riid
)) {
60 TRACE("(%p)->(IID_IPersist %p)\n", This
, ppv
);
62 }else if(IsEqualIID(&IID_IPersistStream
,riid
)) {
63 TRACE("(%p)->(IID_IPersistStream %p)\n", This
, ppv
);
65 }else if(IsEqualIID(&IID_IMoniker
, riid
)) {
66 TRACE("(%p)->(IID_IMoniker %p)\n", This
, ppv
);
68 }else if(IsEqualIID(&IID_IAsyncMoniker
, riid
)) {
69 TRACE("(%p)->(IID_IAsyncMoniker %p)\n", This
, ppv
);
71 }else if(IsEqualIID(&IID_IUriContainer
, riid
)) {
72 TRACE("(%p)->(IID_IUriContainer %p)\n", This
, ppv
);
73 *ppv
= &This
->IUriContainer_iface
;
75 WARN("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
80 IUnknown_AddRef((IUnknown
*)*ppv
);
84 static ULONG WINAPI
URLMoniker_AddRef(IMoniker
*iface
)
86 URLMoniker
*This
= impl_from_IMoniker(iface
);
87 ULONG refCount
= InterlockedIncrement(&This
->ref
);
89 TRACE("(%p) ref=%u\n",This
, refCount
);
94 static ULONG WINAPI
URLMoniker_Release(IMoniker
*iface
)
96 URLMoniker
*This
= impl_from_IMoniker(iface
);
97 ULONG refCount
= InterlockedDecrement(&This
->ref
);
99 TRACE("(%p) ref=%u\n",This
, refCount
);
103 IUri_Release(This
->uri
);
104 SysFreeString(This
->URLName
);
107 URLMON_UnlockModule();
113 static HRESULT WINAPI
URLMoniker_GetClassID(IMoniker
*iface
, CLSID
*pClassID
)
115 URLMoniker
*This
= impl_from_IMoniker(iface
);
117 TRACE("(%p,%p)\n", This
, pClassID
);
122 /* Windows always returns CLSID_StdURLMoniker */
123 *pClassID
= CLSID_StdURLMoniker
;
127 static HRESULT WINAPI
URLMoniker_IsDirty(IMoniker
*iface
)
129 URLMoniker
*This
= impl_from_IMoniker(iface
);
131 TRACE("(%p)\n",This
);
133 /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
134 method in the OLE-provided moniker interfaces always return S_FALSE because
135 their internal state never changes. */
139 static HRESULT WINAPI
URLMoniker_Load(IMoniker
* iface
,IStream
* pStm
)
141 URLMoniker
*This
= impl_from_IMoniker(iface
);
149 TRACE("(%p,%p)\n",This
,pStm
);
156 * Writes a ULONG containing length of unicode string, followed
157 * by that many unicode characters
159 hres
= IStream_Read(pStm
, &size
, sizeof(ULONG
), &got
);
162 if(got
!= sizeof(ULONG
))
165 new_uri_str
= heap_alloc(size
+sizeof(WCHAR
));
167 return E_OUTOFMEMORY
;
169 hres
= IStream_Read(pStm
, new_uri_str
, size
, NULL
);
170 new_uri_str
[size
/sizeof(WCHAR
)] = 0;
172 hres
= CreateUri(new_uri_str
, 0, 0, &new_uri
);
173 heap_free(new_uri_str
);
177 hres
= IUri_GetDisplayUri(new_uri
, &new_url
);
179 IUri_Release(new_uri
);
183 SysFreeString(This
->URLName
);
185 IUri_Release(This
->uri
);
188 This
->URLName
= new_url
;
192 static HRESULT WINAPI
URLMoniker_Save(IMoniker
*iface
, IStream
* pStm
, BOOL fClearDirty
)
194 URLMoniker
*This
= impl_from_IMoniker(iface
);
198 TRACE("(%p,%p,%d)\n", This
, pStm
, fClearDirty
);
203 size
= (SysStringLen(This
->URLName
) + 1)*sizeof(WCHAR
);
204 res
=IStream_Write(pStm
,&size
,sizeof(ULONG
),NULL
);
206 res
=IStream_Write(pStm
,This
->URLName
,size
,NULL
);
212 static HRESULT WINAPI
URLMoniker_GetSizeMax(IMoniker
* iface
, ULARGE_INTEGER
*pcbSize
)
214 URLMoniker
*This
= impl_from_IMoniker(iface
);
216 TRACE("(%p,%p)\n",This
,pcbSize
);
221 pcbSize
->QuadPart
= sizeof(ULONG
) + ((SysStringLen(This
->URLName
)+1) * sizeof(WCHAR
));
225 static HRESULT WINAPI
URLMoniker_BindToObject(IMoniker
*iface
, IBindCtx
* pbc
, IMoniker
*pmkToLeft
,
226 REFIID riid
, void **ppv
)
228 URLMoniker
*This
= impl_from_IMoniker(iface
);
229 IRunningObjectTable
*obj_tbl
;
232 TRACE("(%p)->(%p,%p,%s,%p)\n", This
, pbc
, pmkToLeft
, debugstr_guid(riid
), ppv
);
234 hres
= IBindCtx_GetRunningObjectTable(pbc
, &obj_tbl
);
235 if(SUCCEEDED(hres
)) {
236 hres
= IRunningObjectTable_IsRunning(obj_tbl
, &This
->IMoniker_iface
);
238 IUnknown
*unk
= NULL
;
240 TRACE("Found in running object table\n");
242 hres
= IRunningObjectTable_GetObject(obj_tbl
, &This
->IMoniker_iface
, &unk
);
243 if(SUCCEEDED(hres
)) {
244 hres
= IUnknown_QueryInterface(unk
, riid
, ppv
);
245 IUnknown_Release(unk
);
248 IRunningObjectTable_Release(obj_tbl
);
252 IRunningObjectTable_Release(obj_tbl
);
260 return bind_to_object(&This
->IMoniker_iface
, This
->uri
, pbc
, riid
, ppv
);
263 static HRESULT WINAPI
URLMoniker_BindToStorage(IMoniker
* iface
, IBindCtx
* pbc
,
264 IMoniker
* pmkToLeft
, REFIID riid
, void **ppvObject
)
266 URLMoniker
*This
= impl_from_IMoniker(iface
);
268 TRACE("(%p)->(%p %p %s %p)\n", This
, pbc
, pmkToLeft
, debugstr_guid(riid
), ppvObject
);
270 if(ppvObject
) *ppvObject
= NULL
;
272 if(!pbc
|| !ppvObject
) return E_INVALIDARG
;
275 FIXME("Unsupported pmkToLeft\n");
280 return bind_to_storage(This
->uri
, pbc
, riid
, ppvObject
);
283 static HRESULT WINAPI
URLMoniker_Reduce(IMoniker
*iface
, IBindCtx
*pbc
,
284 DWORD dwReduceHowFar
, IMoniker
**ppmkToLeft
, IMoniker
**ppmkReduced
)
286 URLMoniker
*This
= impl_from_IMoniker(iface
);
288 TRACE("(%p,%p,%d,%p,%p)\n", This
, pbc
, dwReduceHowFar
, ppmkToLeft
, ppmkReduced
);
293 IMoniker_AddRef(iface
);
294 *ppmkReduced
= iface
;
295 return MK_S_REDUCED_TO_SELF
;
298 static HRESULT WINAPI
URLMoniker_ComposeWith(IMoniker
*iface
, IMoniker
*pmkRight
,
299 BOOL fOnlyIfNotGeneric
, IMoniker
**ppmkComposite
)
301 URLMoniker
*This
= impl_from_IMoniker(iface
);
302 FIXME("(%p)->(%p,%d,%p): stub\n",This
,pmkRight
,fOnlyIfNotGeneric
,ppmkComposite
);
306 static HRESULT WINAPI
URLMoniker_Enum(IMoniker
*iface
, BOOL fForward
, IEnumMoniker
**ppenumMoniker
)
308 URLMoniker
*This
= impl_from_IMoniker(iface
);
310 TRACE("(%p,%d,%p)\n", This
, fForward
, ppenumMoniker
);
315 /* Does not support sub-monikers */
316 *ppenumMoniker
= NULL
;
320 static HRESULT WINAPI
URLMoniker_IsEqual(IMoniker
*iface
, IMoniker
*pmkOtherMoniker
)
322 URLMoniker
*This
= impl_from_IMoniker(iface
);
328 TRACE("(%p,%p)\n",This
, pmkOtherMoniker
);
330 if(pmkOtherMoniker
==NULL
)
333 IMoniker_GetClassID(pmkOtherMoniker
,&clsid
);
335 if(!IsEqualCLSID(&clsid
,&CLSID_StdURLMoniker
))
338 res
= CreateBindCtx(0,&bind
);
343 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker
,bind
,NULL
,&urlPath
))) {
344 int result
= lstrcmpiW(urlPath
, This
->URLName
);
345 CoTaskMemFree(urlPath
);
349 IBindCtx_Release(bind
);
354 static HRESULT WINAPI
URLMoniker_Hash(IMoniker
*iface
, DWORD
*pdwHash
)
356 URLMoniker
*This
= impl_from_IMoniker(iface
);
357 int h
= 0,i
,skip
,len
;
361 TRACE("(%p,%p)\n",This
,pdwHash
);
370 for(i
= len
; i
> 0; i
--) {
371 h
= (h
* 37) + val
[off
++];
374 /* only sample some characters */
376 for(i
= len
; i
> 0; i
-= skip
, off
+= skip
) {
377 h
= (h
* 39) + val
[off
];
384 static HRESULT WINAPI
URLMoniker_IsRunning(IMoniker
* iface
, IBindCtx
* pbc
,
385 IMoniker
*pmkToLeft
, IMoniker
*pmkNewlyRunning
)
387 URLMoniker
*This
= impl_from_IMoniker(iface
);
388 FIXME("(%p)->(%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pmkNewlyRunning
);
392 static HRESULT WINAPI
URLMoniker_GetTimeOfLastChange(IMoniker
*iface
,
393 IBindCtx
*pbc
, IMoniker
*pmkToLeft
, FILETIME
*pFileTime
)
395 URLMoniker
*This
= impl_from_IMoniker(iface
);
396 FIXME("(%p)->(%p,%p,%p): stub\n", This
, pbc
, pmkToLeft
, pFileTime
);
400 static HRESULT WINAPI
URLMoniker_Inverse(IMoniker
*iface
, IMoniker
**ppmk
)
402 URLMoniker
*This
= impl_from_IMoniker(iface
);
403 TRACE("(%p,%p)\n",This
,ppmk
);
404 return MK_E_NOINVERSE
;
407 static HRESULT WINAPI
URLMoniker_CommonPrefixWith(IMoniker
*iface
, IMoniker
*pmkOther
, IMoniker
**ppmkPrefix
)
409 URLMoniker
*This
= impl_from_IMoniker(iface
);
410 FIXME("(%p)->(%p,%p): stub\n",This
,pmkOther
,ppmkPrefix
);
414 static HRESULT WINAPI
URLMoniker_RelativePathTo(IMoniker
*iface
, IMoniker
*pmOther
, IMoniker
**ppmkRelPath
)
416 URLMoniker
*This
= impl_from_IMoniker(iface
);
417 FIXME("(%p)->(%p,%p): stub\n",This
,pmOther
,ppmkRelPath
);
421 static HRESULT WINAPI
URLMoniker_GetDisplayName(IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
,
422 LPOLESTR
*ppszDisplayName
)
424 URLMoniker
*This
= impl_from_IMoniker(iface
);
427 TRACE("(%p,%p,%p,%p)\n", This
, pbc
, pmkToLeft
, ppszDisplayName
);
433 return E_OUTOFMEMORY
;
435 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
436 then look at pmkToLeft to try and complete the URL
438 len
= SysStringLen(This
->URLName
)+1;
439 *ppszDisplayName
= CoTaskMemAlloc(len
*sizeof(WCHAR
));
440 if(!*ppszDisplayName
)
441 return E_OUTOFMEMORY
;
442 lstrcpyW(*ppszDisplayName
, This
->URLName
);
446 static HRESULT WINAPI
URLMoniker_ParseDisplayName(IMoniker
*iface
, IBindCtx
*pbc
, IMoniker
*pmkToLeft
,
447 LPOLESTR pszDisplayName
, ULONG
*pchEaten
, IMoniker
**ppmkOut
)
449 URLMoniker
*This
= impl_from_IMoniker(iface
);
450 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This
,pbc
,pmkToLeft
,pszDisplayName
,pchEaten
,ppmkOut
);
454 static HRESULT WINAPI
URLMoniker_IsSystemMoniker(IMoniker
*iface
, DWORD
*pwdMksys
)
456 URLMoniker
*This
= impl_from_IMoniker(iface
);
458 TRACE("(%p,%p)\n",This
,pwdMksys
);
463 *pwdMksys
= MKSYS_URLMONIKER
;
467 static const IMonikerVtbl URLMonikerVtbl
=
469 URLMoniker_QueryInterface
,
472 URLMoniker_GetClassID
,
476 URLMoniker_GetSizeMax
,
477 URLMoniker_BindToObject
,
478 URLMoniker_BindToStorage
,
480 URLMoniker_ComposeWith
,
484 URLMoniker_IsRunning
,
485 URLMoniker_GetTimeOfLastChange
,
487 URLMoniker_CommonPrefixWith
,
488 URLMoniker_RelativePathTo
,
489 URLMoniker_GetDisplayName
,
490 URLMoniker_ParseDisplayName
,
491 URLMoniker_IsSystemMoniker
494 static inline URLMoniker
*impl_from_IUriContainer(IUriContainer
*iface
)
496 return CONTAINING_RECORD(iface
, URLMoniker
, IUriContainer_iface
);
499 static HRESULT WINAPI
UriContainer_QueryInterface(IUriContainer
*iface
, REFIID riid
, void **ppv
)
501 URLMoniker
*This
= impl_from_IUriContainer(iface
);
502 return IMoniker_QueryInterface(&This
->IMoniker_iface
, riid
, ppv
);
505 static ULONG WINAPI
UriContainer_AddRef(IUriContainer
*iface
)
507 URLMoniker
*This
= impl_from_IUriContainer(iface
);
508 return IMoniker_AddRef(&This
->IMoniker_iface
);
511 static ULONG WINAPI
UriContainer_Release(IUriContainer
*iface
)
513 URLMoniker
*This
= impl_from_IUriContainer(iface
);
514 return IMoniker_Release(&This
->IMoniker_iface
);
517 static HRESULT WINAPI
UriContainer_GetIUri(IUriContainer
*iface
, IUri
**ppIUri
)
519 URLMoniker
*This
= impl_from_IUriContainer(iface
);
521 TRACE("(%p)->(%p)\n", This
, ppIUri
);
528 IUri_AddRef(This
->uri
);
533 static const IUriContainerVtbl UriContainerVtbl
= {
534 UriContainer_QueryInterface
,
536 UriContainer_Release
,
540 static HRESULT
create_moniker(IUri
*uri
, URLMoniker
**ret
)
545 mon
= heap_alloc(sizeof(*mon
));
547 return E_OUTOFMEMORY
;
549 mon
->IMoniker_iface
.lpVtbl
= &URLMonikerVtbl
;
550 mon
->IUriContainer_iface
.lpVtbl
= &UriContainerVtbl
;
554 /* FIXME: try to avoid it */
555 hres
= IUri_GetDisplayUri(uri
, &mon
->URLName
);
573 HRESULT
StdURLMoniker_Construct(IUnknown
*outer
, void **ppv
)
578 TRACE("(%p %p)\n", outer
, ppv
);
580 hres
= create_moniker(NULL
, &mon
);
584 *ppv
= &mon
->IMoniker_iface
;
588 static const DWORD create_flags_map
[3] = {
589 Uri_CREATE_FILE_USE_DOS_PATH
, /* URL_MK_LEGACY */
590 0, /* URL_MK_UNIFORM */
591 Uri_CREATE_NO_CANONICALIZE
/* URL_MK_NO_CANONICALIZE */
594 static const DWORD combine_flags_map
[3] = {
595 URL_FILE_USE_PATHURL
, /* URL_MK_LEGACY */
596 0, /* URL_MK_UNIFORM */
597 URL_DONT_SIMPLIFY
/* URL_MK_NO_CANONICALIZE */
600 /***********************************************************************
601 * CreateURLMonikerEx (URLMON.@)
603 * Create a url moniker.
606 * pmkContext [I] Context
607 * szURL [I] Url to create the moniker for
608 * ppmk [O] Destination for created moniker.
612 * Success: S_OK. ppmk contains the created IMoniker object.
613 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
614 * E_OUTOFMEMORY if memory allocation fails.
616 HRESULT WINAPI
CreateURLMonikerEx(IMoniker
*pmkContext
, LPCWSTR szURL
, IMoniker
**ppmk
, DWORD dwFlags
)
618 IUri
*uri
, *base_uri
= NULL
;
622 TRACE("(%p, %s, %p, %08x)\n", pmkContext
, debugstr_w(szURL
), ppmk
, dwFlags
);
630 if(dwFlags
>= sizeof(create_flags_map
)/sizeof(*create_flags_map
)) {
631 FIXME("Unsupported flags %x\n", dwFlags
);
636 IUriContainer
*uri_container
;
638 hres
= IMoniker_QueryInterface(pmkContext
, &IID_IUriContainer
, (void**)&uri_container
);
639 if(SUCCEEDED(hres
)) {
640 hres
= IUriContainer_GetIUri(uri_container
, &base_uri
);
641 IUriContainer_Release(uri_container
);
648 hres
= CoInternetCombineUrlEx(base_uri
, szURL
, combine_flags_map
[dwFlags
], &uri
, 0);
649 IUri_Release(base_uri
);
651 hres
= CreateUri(szURL
, Uri_CREATE_ALLOW_RELATIVE
|Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
|create_flags_map
[dwFlags
], 0, &uri
);
656 hres
= create_moniker(uri
, &obj
);
661 *ppmk
= &obj
->IMoniker_iface
;
665 /***********************************************************************
666 * CreateURLMonikerEx2 (URLMON.@)
668 HRESULT WINAPI
CreateURLMonikerEx2(IMoniker
*pmkContext
, IUri
*pUri
, IMoniker
**ppmk
, DWORD dwFlags
)
670 IUri
*context_uri
= NULL
, *uri
;
671 IUriContainer
*uri_container
;
675 TRACE("(%p %p %p %x)\n", pmkContext
, pUri
, ppmk
, dwFlags
);
683 if(dwFlags
>= sizeof(create_flags_map
)/sizeof(*create_flags_map
)) {
684 FIXME("Unsupported flags %x\n", dwFlags
);
689 hres
= IMoniker_QueryInterface(pmkContext
, &IID_IUriContainer
, (void**)&uri_container
);
690 if(SUCCEEDED(hres
)) {
691 hres
= IUriContainer_GetIUri(uri_container
, &context_uri
);
694 IUriContainer_Release(uri_container
);
699 hres
= CoInternetCombineIUri(context_uri
, pUri
, combine_flags_map
[dwFlags
], &uri
, 0);
700 IUri_Release(context_uri
);
708 hres
= create_moniker(uri
, &ret
);
713 *ppmk
= &ret
->IMoniker_iface
;
717 /**********************************************************************
718 * CreateURLMoniker (URLMON.@)
720 * Create a url moniker.
723 * pmkContext [I] Context
724 * szURL [I] Url to create the moniker for
725 * ppmk [O] Destination for created moniker.
728 * Success: S_OK. ppmk contains the created IMoniker object.
729 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
730 * E_OUTOFMEMORY if memory allocation fails.
732 HRESULT WINAPI
CreateURLMoniker(IMoniker
*pmkContext
, LPCWSTR szURL
, IMoniker
**ppmk
)
734 return CreateURLMonikerEx(pmkContext
, szURL
, ppmk
, URL_MK_LEGACY
);
737 /***********************************************************************
738 * IsAsyncMoniker (URLMON.@)
740 HRESULT WINAPI
IsAsyncMoniker(IMoniker
*pmk
)
744 TRACE("(%p)\n", pmk
);
747 if(SUCCEEDED(IMoniker_QueryInterface(pmk
, &IID_IAsyncMoniker
, (void**)&am
))) {
748 IUnknown_Release(am
);
754 /***********************************************************************
755 * BindAsyncMoniker (URLMON.@)
757 * Bind a bind status callback to an asynchronous URL Moniker.
760 * pmk [I] Moniker object to bind status callback to
761 * grfOpt [I] Options, seems not used
762 * pbsc [I] Status callback to bind
763 * iidResult [I] Interface to return
764 * ppvResult [O] Resulting asynchronous moniker object
768 * Failure: E_INVALIDARG, if any argument is invalid, or
769 * E_OUTOFMEMORY if memory allocation fails.
771 HRESULT WINAPI
BindAsyncMoniker(IMoniker
*pmk
, DWORD grfOpt
, IBindStatusCallback
*pbsc
, REFIID iidResult
, LPVOID
*ppvResult
)
774 HRESULT hr
= E_INVALIDARG
;
776 TRACE("(%p %08x %p %s %p)\n", pmk
, grfOpt
, pbsc
, debugstr_guid(iidResult
), ppvResult
);
778 if (pmk
&& ppvResult
)
782 hr
= CreateAsyncBindCtx(0, pbsc
, NULL
, &pbc
);
785 hr
= IMoniker_BindToObject(pmk
, pbc
, NULL
, iidResult
, ppvResult
);
786 IBindCtx_Release(pbc
);
792 /***********************************************************************
793 * MkParseDisplayNameEx (URLMON.@)
795 HRESULT WINAPI
MkParseDisplayNameEx(IBindCtx
*pbc
, LPCWSTR szDisplayName
, ULONG
*pchEaten
, LPMONIKER
*ppmk
)
797 TRACE("(%p %s %p %p)\n", pbc
, debugstr_w(szDisplayName
), pchEaten
, ppmk
);
799 if (!pbc
|| !szDisplayName
|| !*szDisplayName
|| !pchEaten
|| !ppmk
)
802 if(is_registered_protocol(szDisplayName
)) {
805 hres
= CreateURLMoniker(NULL
, szDisplayName
, ppmk
);
806 if(SUCCEEDED(hres
)) {
807 *pchEaten
= strlenW(szDisplayName
);
812 return MkParseDisplayName(pbc
, szDisplayName
, pchEaten
, ppmk
);
816 /***********************************************************************
817 * URLDownloadToCacheFileA (URLMON.@)
819 HRESULT WINAPI
URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller
, LPCSTR szURL
, LPSTR szFileName
,
820 DWORD dwBufLength
, DWORD dwReserved
, LPBINDSTATUSCALLBACK pBSC
)
822 LPWSTR url
= NULL
, file_name
= NULL
;
826 TRACE("(%p %s %p %d %d %p)\n", lpUnkCaller
, debugstr_a(szURL
), szFileName
,
827 dwBufLength
, dwReserved
, pBSC
);
830 len
= MultiByteToWideChar(CP_ACP
, 0, szURL
, -1, NULL
, 0);
831 url
= heap_alloc(len
*sizeof(WCHAR
));
832 MultiByteToWideChar(CP_ACP
, 0, szURL
, -1, url
, len
);
836 file_name
= heap_alloc(dwBufLength
*sizeof(WCHAR
));
838 hres
= URLDownloadToCacheFileW(lpUnkCaller
, url
, file_name
, dwBufLength
*sizeof(WCHAR
),
841 if(SUCCEEDED(hres
) && file_name
)
842 WideCharToMultiByte(CP_ACP
, 0, file_name
, -1, szFileName
, dwBufLength
, NULL
, NULL
);
845 heap_free(file_name
);
850 /***********************************************************************
851 * URLDownloadToCacheFileW (URLMON.@)
853 HRESULT WINAPI
URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller
, LPCWSTR szURL
, LPWSTR szFileName
,
854 DWORD dwBufLength
, DWORD dwReserved
, LPBINDSTATUSCALLBACK pBSC
)
856 WCHAR cache_path
[MAX_PATH
+ 1];
857 FILETIME expire
, modified
;
861 static WCHAR header
[] = {
862 'H','T','T','P','/','1','.','0',' ','2','0','0',' ',
863 'O','K','\\','r','\\','n','\\','r','\\','n',0
866 TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller
, debugstr_w(szURL
),
867 szFileName
, dwBufLength
, dwReserved
, pBSC
);
869 if (!szURL
|| !szFileName
)
872 ext
= PathFindExtensionW(szURL
);
874 if (!CreateUrlCacheEntryW(szURL
, 0, ext
, cache_path
, 0))
877 hr
= URLDownloadToFileW(lpUnkCaller
, szURL
, cache_path
, 0, pBSC
);
881 expire
.dwHighDateTime
= 0;
882 expire
.dwLowDateTime
= 0;
883 modified
.dwHighDateTime
= 0;
884 modified
.dwLowDateTime
= 0;
886 if (!CommitUrlCacheEntryW(szURL
, cache_path
, expire
, modified
, NORMAL_CACHE_ENTRY
,
887 header
, sizeof(header
), NULL
, NULL
))
890 if (strlenW(cache_path
) > dwBufLength
)
891 return E_OUTOFMEMORY
;
893 lstrcpyW(szFileName
, cache_path
);
898 /***********************************************************************
899 * HlinkSimpleNavigateToMoniker (URLMON.@)
901 HRESULT WINAPI
HlinkSimpleNavigateToMoniker(IMoniker
*pmkTarget
,
902 LPCWSTR szLocation
, LPCWSTR szTargetFrameName
, IUnknown
*pUnk
,
903 IBindCtx
*pbc
, IBindStatusCallback
*pbsc
, DWORD grfHLNF
, DWORD dwReserved
)
910 hres
= IMoniker_GetDisplayName(pmkTarget
, pbc
, 0, &target
);
912 hres
= HlinkSimpleNavigateToString( target
, szLocation
, szTargetFrameName
,
913 pUnk
, pbc
, pbsc
, grfHLNF
, dwReserved
);
914 CoTaskMemFree(target
);
919 /***********************************************************************
920 * HlinkSimpleNavigateToString (URLMON.@)
922 HRESULT WINAPI
HlinkSimpleNavigateToString( LPCWSTR szTarget
,
923 LPCWSTR szLocation
, LPCWSTR szTargetFrameName
, IUnknown
*pUnk
,
924 IBindCtx
*pbc
, IBindStatusCallback
*pbsc
, DWORD grfHLNF
, DWORD dwReserved
)
926 FIXME("%s %s %s %p %p %p %u %u partial stub\n", debugstr_w( szTarget
), debugstr_w( szLocation
),
927 debugstr_w( szTargetFrameName
), pUnk
, pbc
, pbsc
, grfHLNF
, dwReserved
);
929 /* undocumented: 0 means HLNF_OPENINNEWWINDOW*/
930 if (!grfHLNF
) grfHLNF
= HLNF_OPENINNEWWINDOW
;
932 if (grfHLNF
== HLNF_OPENINNEWWINDOW
)
934 SHELLEXECUTEINFOW sei
;
935 static const WCHAR openW
[] = { 'o', 'p', 'e', 'n', 0 };
937 memset(&sei
, 0, sizeof(sei
));
938 sei
.cbSize
= sizeof(sei
);
940 sei
.nShow
= SW_SHOWNORMAL
;
941 sei
.fMask
= SEE_MASK_FLAG_NO_UI
| SEE_MASK_NO_CONSOLE
;
942 sei
.lpFile
= szTarget
;
944 if (ShellExecuteExW(&sei
)) return S_OK
;
950 /***********************************************************************
951 * HlinkNavigateString (URLMON.@)
953 HRESULT WINAPI
HlinkNavigateString( IUnknown
*pUnk
, LPCWSTR szTarget
)
955 TRACE("%p %s\n", pUnk
, debugstr_w( szTarget
) );
956 return HlinkSimpleNavigateToString(
957 szTarget
, NULL
, NULL
, pUnk
, NULL
, NULL
, 0, 0 );
960 /***********************************************************************
961 * GetSoftwareUpdateInfo (URLMON.@)
963 HRESULT WINAPI
GetSoftwareUpdateInfo( LPCWSTR szDistUnit
, LPSOFTDISTINFO psdi
)
965 FIXME("%s %p\n", debugstr_w(szDistUnit
), psdi
);