user32/tests: Test that class data is set with wrong size value too.
[wine/multimedia.git] / dlls / urlmon / umon.c
blob3e43bb83d8ea52f6d6c4d4f68800aeda618439af
1 /*
2 * UrlMon
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"
25 #include "winreg.h"
26 #include "shlwapi.h"
27 #include "hlink.h"
28 #include "shellapi.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
34 typedef struct {
35 IMoniker IMoniker_iface;
36 IUriContainer IUriContainer_iface;
38 LONG ref;
40 IUri *uri;
41 BSTR URLName;
42 } URLMoniker;
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);
53 if(!ppv)
54 return E_INVALIDARG;
56 if(IsEqualIID(&IID_IUnknown, riid)) {
57 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
58 *ppv = iface;
59 }else if(IsEqualIID(&IID_IPersist, riid)) {
60 TRACE("(%p)->(IID_IPersist %p)\n", This, ppv);
61 *ppv = iface;
62 }else if(IsEqualIID(&IID_IPersistStream,riid)) {
63 TRACE("(%p)->(IID_IPersistStream %p)\n", This, ppv);
64 *ppv = iface;
65 }else if(IsEqualIID(&IID_IMoniker, riid)) {
66 TRACE("(%p)->(IID_IMoniker %p)\n", This, ppv);
67 *ppv = iface;
68 }else if(IsEqualIID(&IID_IAsyncMoniker, riid)) {
69 TRACE("(%p)->(IID_IAsyncMoniker %p)\n", This, ppv);
70 *ppv = iface;
71 }else if(IsEqualIID(&IID_IUriContainer, riid)) {
72 TRACE("(%p)->(IID_IUriContainer %p)\n", This, ppv);
73 *ppv = &This->IUriContainer_iface;
74 }else {
75 WARN("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppv);
76 *ppv = NULL;
77 return E_NOINTERFACE;
80 IMoniker_AddRef((IUnknown*)*ppv);
81 return S_OK;
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);
91 return 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);
101 if (!refCount) {
102 if(This->uri)
103 IUri_Release(This->uri);
104 SysFreeString(This->URLName);
105 heap_free(This);
107 URLMON_UnlockModule();
110 return refCount;
113 static HRESULT WINAPI URLMoniker_GetClassID(IMoniker *iface, CLSID *pClassID)
115 URLMoniker *This = impl_from_IMoniker(iface);
117 TRACE("(%p,%p)\n", This, pClassID);
119 if(!pClassID)
120 return E_POINTER;
122 /* Windows always returns CLSID_StdURLMoniker */
123 *pClassID = CLSID_StdURLMoniker;
124 return S_OK;
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. */
136 return S_FALSE;
139 static HRESULT WINAPI URLMoniker_Load(IMoniker* iface,IStream* pStm)
141 URLMoniker *This = impl_from_IMoniker(iface);
142 WCHAR *new_uri_str;
143 IUri *new_uri;
144 BSTR new_url;
145 ULONG size;
146 ULONG got;
147 HRESULT hres;
149 TRACE("(%p,%p)\n",This,pStm);
151 if(!pStm)
152 return E_INVALIDARG;
155 * NOTE
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);
160 if(FAILED(hres))
161 return hres;
162 if(got != sizeof(ULONG))
163 return E_FAIL;
165 new_uri_str = heap_alloc(size+sizeof(WCHAR));
166 if(!new_uri_str)
167 return E_OUTOFMEMORY;
169 hres = IStream_Read(pStm, new_uri_str, size, NULL);
170 new_uri_str[size/sizeof(WCHAR)] = 0;
171 if(SUCCEEDED(hres))
172 hres = CreateUri(new_uri_str, 0, 0, &new_uri);
173 heap_free(new_uri_str);
174 if(FAILED(hres))
175 return hres;
177 hres = IUri_GetDisplayUri(new_uri, &new_url);
178 if(FAILED(hres)) {
179 IUri_Release(new_uri);
180 return hres;
183 SysFreeString(This->URLName);
184 if(This->uri)
185 IUri_Release(This->uri);
187 This->uri = new_uri;
188 This->URLName = new_url;
189 return S_OK;
192 static HRESULT WINAPI URLMoniker_Save(IMoniker *iface, IStream* pStm, BOOL fClearDirty)
194 URLMoniker *This = impl_from_IMoniker(iface);
195 HRESULT res;
196 ULONG size;
198 TRACE("(%p,%p,%d)\n", This, pStm, fClearDirty);
200 if(!pStm)
201 return E_INVALIDARG;
203 size = (SysStringLen(This->URLName) + 1)*sizeof(WCHAR);
204 res=IStream_Write(pStm,&size,sizeof(ULONG),NULL);
205 if(SUCCEEDED(res))
206 res=IStream_Write(pStm,This->URLName,size,NULL);
208 return res;
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);
218 if(!pcbSize)
219 return E_INVALIDARG;
221 pcbSize->QuadPart = sizeof(ULONG) + ((SysStringLen(This->URLName)+1) * sizeof(WCHAR));
222 return S_OK;
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;
230 HRESULT hres;
232 TRACE("(%p)->(%p,%p,%s,%p): stub\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppv);
234 hres = IBindCtx_GetRunningObjectTable(pbc, &obj_tbl);
235 if(SUCCEEDED(hres)) {
236 FIXME("use running object table\n");
237 IRunningObjectTable_Release(obj_tbl);
240 if(!This->uri) {
241 *ppv = NULL;
242 return MK_E_SYNTAX;
245 return bind_to_object(&This->IMoniker_iface, This->uri, pbc, riid, ppv);
248 static HRESULT WINAPI URLMoniker_BindToStorage(IMoniker* iface, IBindCtx* pbc,
249 IMoniker* pmkToLeft, REFIID riid, void **ppvObject)
251 URLMoniker *This = impl_from_IMoniker(iface);
253 TRACE("(%p)->(%p %p %s %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObject);
255 if(ppvObject) *ppvObject = NULL;
257 if(!pbc || !ppvObject) return E_INVALIDARG;
259 if(pmkToLeft)
260 FIXME("Unsupported pmkToLeft\n");
262 if(!This->uri)
263 return MK_E_SYNTAX;
265 return bind_to_storage(This->uri, pbc, riid, ppvObject);
268 static HRESULT WINAPI URLMoniker_Reduce(IMoniker *iface, IBindCtx *pbc,
269 DWORD dwReduceHowFar, IMoniker **ppmkToLeft, IMoniker **ppmkReduced)
271 URLMoniker *This = impl_from_IMoniker(iface);
273 TRACE("(%p,%p,%d,%p,%p)\n", This, pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
275 if(!ppmkReduced)
276 return E_INVALIDARG;
278 IMoniker_AddRef(iface);
279 *ppmkReduced = iface;
280 return MK_S_REDUCED_TO_SELF;
283 static HRESULT WINAPI URLMoniker_ComposeWith(IMoniker *iface, IMoniker *pmkRight,
284 BOOL fOnlyIfNotGeneric, IMoniker **ppmkComposite)
286 URLMoniker *This = impl_from_IMoniker(iface);
287 FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
288 return E_NOTIMPL;
291 static HRESULT WINAPI URLMoniker_Enum(IMoniker *iface, BOOL fForward, IEnumMoniker **ppenumMoniker)
293 URLMoniker *This = impl_from_IMoniker(iface);
295 TRACE("(%p,%d,%p)\n", This, fForward, ppenumMoniker);
297 if(!ppenumMoniker)
298 return E_INVALIDARG;
300 /* Does not support sub-monikers */
301 *ppenumMoniker = NULL;
302 return S_OK;
305 static HRESULT WINAPI URLMoniker_IsEqual(IMoniker *iface, IMoniker *pmkOtherMoniker)
307 URLMoniker *This = impl_from_IMoniker(iface);
308 CLSID clsid;
309 LPOLESTR urlPath;
310 IBindCtx* bind;
311 HRESULT res;
313 TRACE("(%p,%p)\n",This, pmkOtherMoniker);
315 if(pmkOtherMoniker==NULL)
316 return E_INVALIDARG;
318 IMoniker_GetClassID(pmkOtherMoniker,&clsid);
320 if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
321 return S_FALSE;
323 res = CreateBindCtx(0,&bind);
324 if(FAILED(res))
325 return res;
327 res = S_FALSE;
328 if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
329 int result = lstrcmpiW(urlPath, This->URLName);
330 CoTaskMemFree(urlPath);
331 if(result == 0)
332 res = S_OK;
334 IUnknown_Release(bind);
335 return res;
339 static HRESULT WINAPI URLMoniker_Hash(IMoniker *iface, DWORD *pdwHash)
341 URLMoniker *This = impl_from_IMoniker(iface);
342 int h = 0,i,skip,len;
343 int off = 0;
344 LPOLESTR val;
346 TRACE("(%p,%p)\n",This,pdwHash);
348 if(!pdwHash)
349 return E_INVALIDARG;
351 val = This->URLName;
352 len = lstrlenW(val);
354 if(len < 16) {
355 for(i = len ; i > 0; i--) {
356 h = (h * 37) + val[off++];
358 }else {
359 /* only sample some characters */
360 skip = len / 8;
361 for(i = len; i > 0; i -= skip, off += skip) {
362 h = (h * 39) + val[off];
365 *pdwHash = h;
366 return S_OK;
369 static HRESULT WINAPI URLMoniker_IsRunning(IMoniker* iface, IBindCtx* pbc,
370 IMoniker *pmkToLeft, IMoniker *pmkNewlyRunning)
372 URLMoniker *This = impl_from_IMoniker(iface);
373 FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
374 return E_NOTIMPL;
377 static HRESULT WINAPI URLMoniker_GetTimeOfLastChange(IMoniker *iface,
378 IBindCtx *pbc, IMoniker *pmkToLeft, FILETIME *pFileTime)
380 URLMoniker *This = impl_from_IMoniker(iface);
381 FIXME("(%p)->(%p,%p,%p): stub\n", This, pbc, pmkToLeft, pFileTime);
382 return E_NOTIMPL;
385 static HRESULT WINAPI URLMoniker_Inverse(IMoniker *iface, IMoniker **ppmk)
387 URLMoniker *This = impl_from_IMoniker(iface);
388 TRACE("(%p,%p)\n",This,ppmk);
389 return MK_E_NOINVERSE;
392 static HRESULT WINAPI URLMoniker_CommonPrefixWith(IMoniker *iface, IMoniker *pmkOther, IMoniker **ppmkPrefix)
394 URLMoniker *This = impl_from_IMoniker(iface);
395 FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
396 return E_NOTIMPL;
399 static HRESULT WINAPI URLMoniker_RelativePathTo(IMoniker *iface, IMoniker *pmOther, IMoniker **ppmkRelPath)
401 URLMoniker *This = impl_from_IMoniker(iface);
402 FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
403 return E_NOTIMPL;
406 static HRESULT WINAPI URLMoniker_GetDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
407 LPOLESTR *ppszDisplayName)
409 URLMoniker *This = impl_from_IMoniker(iface);
410 int len;
412 TRACE("(%p,%p,%p,%p)\n", This, pbc, pmkToLeft, ppszDisplayName);
414 if(!ppszDisplayName)
415 return E_INVALIDARG;
417 if(!This->URLName)
418 return E_OUTOFMEMORY;
420 /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
421 then look at pmkToLeft to try and complete the URL
423 len = SysStringLen(This->URLName)+1;
424 *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
425 if(!*ppszDisplayName)
426 return E_OUTOFMEMORY;
427 lstrcpyW(*ppszDisplayName, This->URLName);
428 return S_OK;
431 static HRESULT WINAPI URLMoniker_ParseDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
432 LPOLESTR pszDisplayName, ULONG *pchEaten, IMoniker **ppmkOut)
434 URLMoniker *This = impl_from_IMoniker(iface);
435 FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
436 return E_NOTIMPL;
439 static HRESULT WINAPI URLMoniker_IsSystemMoniker(IMoniker *iface, DWORD *pwdMksys)
441 URLMoniker *This = impl_from_IMoniker(iface);
443 TRACE("(%p,%p)\n",This,pwdMksys);
445 if(!pwdMksys)
446 return E_INVALIDARG;
448 *pwdMksys = MKSYS_URLMONIKER;
449 return S_OK;
452 static const IMonikerVtbl URLMonikerVtbl =
454 URLMoniker_QueryInterface,
455 URLMoniker_AddRef,
456 URLMoniker_Release,
457 URLMoniker_GetClassID,
458 URLMoniker_IsDirty,
459 URLMoniker_Load,
460 URLMoniker_Save,
461 URLMoniker_GetSizeMax,
462 URLMoniker_BindToObject,
463 URLMoniker_BindToStorage,
464 URLMoniker_Reduce,
465 URLMoniker_ComposeWith,
466 URLMoniker_Enum,
467 URLMoniker_IsEqual,
468 URLMoniker_Hash,
469 URLMoniker_IsRunning,
470 URLMoniker_GetTimeOfLastChange,
471 URLMoniker_Inverse,
472 URLMoniker_CommonPrefixWith,
473 URLMoniker_RelativePathTo,
474 URLMoniker_GetDisplayName,
475 URLMoniker_ParseDisplayName,
476 URLMoniker_IsSystemMoniker
479 static inline URLMoniker *impl_from_IUriContainer(IUriContainer *iface)
481 return CONTAINING_RECORD(iface, URLMoniker, IUriContainer_iface);
484 static HRESULT WINAPI UriContainer_QueryInterface(IUriContainer *iface, REFIID riid, void **ppv)
486 URLMoniker *This = impl_from_IUriContainer(iface);
487 return IMoniker_QueryInterface(&This->IMoniker_iface, riid, ppv);
490 static ULONG WINAPI UriContainer_AddRef(IUriContainer *iface)
492 URLMoniker *This = impl_from_IUriContainer(iface);
493 return IMoniker_AddRef(&This->IMoniker_iface);
496 static ULONG WINAPI UriContainer_Release(IUriContainer *iface)
498 URLMoniker *This = impl_from_IUriContainer(iface);
499 return IMoniker_Release(&This->IMoniker_iface);
502 static HRESULT WINAPI UriContainer_GetIUri(IUriContainer *iface, IUri **ppIUri)
504 URLMoniker *This = impl_from_IUriContainer(iface);
506 TRACE("(%p)->(%p)\n", This, ppIUri);
508 if(!This->uri) {
509 *ppIUri = NULL;
510 return S_FALSE;
513 IUri_AddRef(This->uri);
514 *ppIUri = This->uri;
515 return S_OK;
518 static const IUriContainerVtbl UriContainerVtbl = {
519 UriContainer_QueryInterface,
520 UriContainer_AddRef,
521 UriContainer_Release,
522 UriContainer_GetIUri
525 static HRESULT create_moniker(IUri *uri, URLMoniker **ret)
527 URLMoniker *mon;
528 HRESULT hres;
530 mon = heap_alloc(sizeof(*mon));
531 if(!mon)
532 return E_OUTOFMEMORY;
534 mon->IMoniker_iface.lpVtbl = &URLMonikerVtbl;
535 mon->IUriContainer_iface.lpVtbl = &UriContainerVtbl;
536 mon->ref = 1;
538 if(uri) {
539 /* FIXME: try to avoid it */
540 hres = IUri_GetDisplayUri(uri, &mon->URLName);
541 if(FAILED(hres)) {
542 heap_free(mon);
543 return hres;
546 IUri_AddRef(uri);
547 mon->uri = uri;
548 }else {
549 mon->URLName = NULL;
550 mon->uri = NULL;
553 URLMON_LockModule();
554 *ret = mon;
555 return S_OK;
558 HRESULT StdURLMoniker_Construct(IUnknown *outer, void **ppv)
560 URLMoniker *mon;
561 HRESULT hres;
563 TRACE("(%p %p)\n", outer, ppv);
565 hres = create_moniker(NULL, &mon);
566 if(FAILED(hres))
567 return hres;
569 *ppv = &mon->IMoniker_iface;
570 return S_OK;
573 static const DWORD create_flags_map[3] = {
574 Uri_CREATE_FILE_USE_DOS_PATH, /* URL_MK_LEGACY */
575 0, /* URL_MK_UNIFORM */
576 Uri_CREATE_NO_CANONICALIZE /* URL_MK_NO_CANONICALIZE */
579 static const DWORD combine_flags_map[3] = {
580 URL_FILE_USE_PATHURL, /* URL_MK_LEGACY */
581 0, /* URL_MK_UNIFORM */
582 URL_DONT_SIMPLIFY /* URL_MK_NO_CANONICALIZE */
585 /***********************************************************************
586 * CreateURLMonikerEx (URLMON.@)
588 * Create a url moniker.
590 * PARAMS
591 * pmkContext [I] Context
592 * szURL [I] Url to create the moniker for
593 * ppmk [O] Destination for created moniker.
594 * dwFlags [I] Flags.
596 * RETURNS
597 * Success: S_OK. ppmk contains the created IMoniker object.
598 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
599 * E_OUTOFMEMORY if memory allocation fails.
601 HRESULT WINAPI CreateURLMonikerEx(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk, DWORD dwFlags)
603 IUri *uri, *base_uri = NULL;
604 URLMoniker *obj;
605 HRESULT hres;
607 TRACE("(%p, %s, %p, %08x)\n", pmkContext, debugstr_w(szURL), ppmk, dwFlags);
609 if (ppmk)
610 *ppmk = NULL;
612 if (!szURL || !ppmk)
613 return E_INVALIDARG;
615 if(dwFlags >= sizeof(create_flags_map)/sizeof(*create_flags_map)) {
616 FIXME("Unsupported flags %x\n", dwFlags);
617 return E_INVALIDARG;
620 if(pmkContext) {
621 IUriContainer *uri_container;
623 hres = IMoniker_QueryInterface(pmkContext, &IID_IUriContainer, (void**)&uri_container);
624 if(SUCCEEDED(hres)) {
625 hres = IUriContainer_GetIUri(uri_container, &base_uri);
626 IUriContainer_Release(uri_container);
627 if(FAILED(hres))
628 return hres;
632 if(base_uri) {
633 hres = CoInternetCombineUrlEx(base_uri, szURL, combine_flags_map[dwFlags], &uri, 0);
634 IUri_Release(base_uri);
635 }else {
636 hres = CreateUri(szURL, Uri_CREATE_ALLOW_RELATIVE|Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME|create_flags_map[dwFlags], 0, &uri);
638 if(FAILED(hres))
639 return hres;
641 hres = create_moniker(uri, &obj);
642 IUri_Release(uri);
643 if(FAILED(hres))
644 return hres;
646 *ppmk = &obj->IMoniker_iface;
647 return S_OK;
650 /***********************************************************************
651 * CreateURLMonikerEx2 (URLMON.@)
653 HRESULT WINAPI CreateURLMonikerEx2(IMoniker *pmkContext, IUri *pUri, IMoniker **ppmk, DWORD dwFlags)
655 IUri *context_uri = NULL, *uri;
656 IUriContainer *uri_container;
657 URLMoniker *ret;
658 HRESULT hres;
660 TRACE("(%p %p %p %x)\n", pmkContext, pUri, ppmk, dwFlags);
662 if (ppmk)
663 *ppmk = NULL;
665 if (!pUri || !ppmk)
666 return E_INVALIDARG;
668 if(dwFlags >= sizeof(create_flags_map)/sizeof(*create_flags_map)) {
669 FIXME("Unsupported flags %x\n", dwFlags);
670 return E_INVALIDARG;
673 if(pmkContext) {
674 hres = IMoniker_QueryInterface(pmkContext, &IID_IUriContainer, (void**)&uri_container);
675 if(SUCCEEDED(hres)) {
676 hres = IUriContainer_GetIUri(uri_container, &context_uri);
677 if(FAILED(hres))
678 context_uri = NULL;
679 IUriContainer_Release(uri_container);
683 if(context_uri) {
684 hres = CoInternetCombineIUri(context_uri, pUri, combine_flags_map[dwFlags], &uri, 0);
685 IUri_Release(context_uri);
686 if(FAILED(hres))
687 return hres;
688 }else {
689 uri = pUri;
690 IUri_AddRef(uri);
693 hres = create_moniker(uri, &ret);
694 IUri_Release(uri);
695 if(FAILED(hres))
696 return hres;
698 *ppmk = &ret->IMoniker_iface;
699 return S_OK;
702 /**********************************************************************
703 * CreateURLMoniker (URLMON.@)
705 * Create a url moniker.
707 * PARAMS
708 * pmkContext [I] Context
709 * szURL [I] Url to create the moniker for
710 * ppmk [O] Destination for created moniker.
712 * RETURNS
713 * Success: S_OK. ppmk contains the created IMoniker object.
714 * Failure: MK_E_SYNTAX if szURL is not a valid url, or
715 * E_OUTOFMEMORY if memory allocation fails.
717 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
719 return CreateURLMonikerEx(pmkContext, szURL, ppmk, URL_MK_LEGACY);
722 /***********************************************************************
723 * IsAsyncMoniker (URLMON.@)
725 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
727 IUnknown *am;
729 TRACE("(%p)\n", pmk);
730 if(!pmk)
731 return E_INVALIDARG;
732 if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
733 IUnknown_Release(am);
734 return S_OK;
736 return S_FALSE;
739 /***********************************************************************
740 * BindAsyncMoniker (URLMON.@)
742 * Bind a bind status callback to an asynchronous URL Moniker.
744 * PARAMS
745 * pmk [I] Moniker object to bind status callback to
746 * grfOpt [I] Options, seems not used
747 * pbsc [I] Status callback to bind
748 * iidResult [I] Interface to return
749 * ppvResult [O] Resulting asynchronous moniker object
751 * RETURNS
752 * Success: S_OK.
753 * Failure: E_INVALIDARG, if any argument is invalid, or
754 * E_OUTOFMEMORY if memory allocation fails.
756 HRESULT WINAPI BindAsyncMoniker(IMoniker *pmk, DWORD grfOpt, IBindStatusCallback *pbsc, REFIID iidResult, LPVOID *ppvResult)
758 LPBC pbc = NULL;
759 HRESULT hr = E_INVALIDARG;
761 TRACE("(%p %08x %p %s %p)\n", pmk, grfOpt, pbsc, debugstr_guid(iidResult), ppvResult);
763 if (pmk && ppvResult)
765 *ppvResult = NULL;
767 hr = CreateAsyncBindCtx(0, pbsc, NULL, &pbc);
768 if (hr == NOERROR)
770 hr = IMoniker_BindToObject(pmk, pbc, NULL, iidResult, ppvResult);
771 IBindCtx_Release(pbc);
774 return hr;
777 /***********************************************************************
778 * MkParseDisplayNameEx (URLMON.@)
780 HRESULT WINAPI MkParseDisplayNameEx(IBindCtx *pbc, LPCWSTR szDisplayName, ULONG *pchEaten, LPMONIKER *ppmk)
782 TRACE("(%p %s %p %p)\n", pbc, debugstr_w(szDisplayName), pchEaten, ppmk);
784 if (!pbc || !szDisplayName || !*szDisplayName || !pchEaten || !ppmk)
785 return E_INVALIDARG;
787 if(is_registered_protocol(szDisplayName)) {
788 HRESULT hres;
790 hres = CreateURLMoniker(NULL, szDisplayName, ppmk);
791 if(SUCCEEDED(hres)) {
792 *pchEaten = strlenW(szDisplayName);
793 return hres;
797 return MkParseDisplayName(pbc, szDisplayName, pchEaten, ppmk);
801 /***********************************************************************
802 * URLDownloadToCacheFileA (URLMON.@)
804 HRESULT WINAPI URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller, LPCSTR szURL, LPSTR szFileName,
805 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
807 LPWSTR url = NULL, file_name = NULL;
808 int len;
809 HRESULT hres;
811 TRACE("(%p %s %p %d %d %p)\n", lpUnkCaller, debugstr_a(szURL), szFileName,
812 dwBufLength, dwReserved, pBSC);
814 if(szURL) {
815 len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
816 url = heap_alloc(len*sizeof(WCHAR));
817 MultiByteToWideChar(CP_ACP, 0, szURL, -1, url, len);
820 if(szFileName)
821 file_name = heap_alloc(dwBufLength*sizeof(WCHAR));
823 hres = URLDownloadToCacheFileW(lpUnkCaller, url, file_name, dwBufLength*sizeof(WCHAR),
824 dwReserved, pBSC);
826 if(SUCCEEDED(hres) && file_name)
827 WideCharToMultiByte(CP_ACP, 0, file_name, -1, szFileName, dwBufLength, NULL, NULL);
829 heap_free(url);
830 heap_free(file_name);
832 return hres;
835 /***********************************************************************
836 * URLDownloadToCacheFileW (URLMON.@)
838 HRESULT WINAPI URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller, LPCWSTR szURL, LPWSTR szFileName,
839 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
841 WCHAR cache_path[MAX_PATH + 1];
842 FILETIME expire, modified;
843 HRESULT hr;
844 LPWSTR ext;
846 static WCHAR header[] = {
847 'H','T','T','P','/','1','.','0',' ','2','0','0',' ',
848 'O','K','\\','r','\\','n','\\','r','\\','n',0
851 TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller, debugstr_w(szURL),
852 szFileName, dwBufLength, dwReserved, pBSC);
854 if (!szURL || !szFileName)
855 return E_INVALIDARG;
857 ext = PathFindExtensionW(szURL);
859 if (!CreateUrlCacheEntryW(szURL, 0, ext, cache_path, 0))
860 return E_FAIL;
862 hr = URLDownloadToFileW(lpUnkCaller, szURL, cache_path, 0, pBSC);
863 if (FAILED(hr))
864 return hr;
866 expire.dwHighDateTime = 0;
867 expire.dwLowDateTime = 0;
868 modified.dwHighDateTime = 0;
869 modified.dwLowDateTime = 0;
871 if (!CommitUrlCacheEntryW(szURL, cache_path, expire, modified, NORMAL_CACHE_ENTRY,
872 header, sizeof(header), NULL, NULL))
873 return E_FAIL;
875 if (strlenW(cache_path) > dwBufLength)
876 return E_OUTOFMEMORY;
878 lstrcpyW(szFileName, cache_path);
880 return S_OK;
883 /***********************************************************************
884 * HlinkSimpleNavigateToMoniker (URLMON.@)
886 HRESULT WINAPI HlinkSimpleNavigateToMoniker(IMoniker *pmkTarget,
887 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
888 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
890 LPWSTR target;
891 HRESULT hres;
893 TRACE("\n");
895 hres = IMoniker_GetDisplayName(pmkTarget, pbc, 0, &target);
896 if(hres == S_OK)
897 hres = HlinkSimpleNavigateToString( target, szLocation, szTargetFrameName,
898 pUnk, pbc, pbsc, grfHLNF, dwReserved );
899 CoTaskMemFree(target);
901 return hres;
904 /***********************************************************************
905 * HlinkSimpleNavigateToString (URLMON.@)
907 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
908 LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
909 IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
911 FIXME("%s %s %s %p %p %p %u %u partial stub\n", debugstr_w( szTarget ), debugstr_w( szLocation ),
912 debugstr_w( szTargetFrameName ), pUnk, pbc, pbsc, grfHLNF, dwReserved);
914 /* undocumented: 0 means HLNF_OPENINNEWWINDOW*/
915 if (!grfHLNF) grfHLNF = HLNF_OPENINNEWWINDOW;
917 if (grfHLNF == HLNF_OPENINNEWWINDOW)
919 SHELLEXECUTEINFOW sei;
920 static const WCHAR openW[] = { 'o', 'p', 'e', 'n', 0 };
922 memset(&sei, 0, sizeof(sei));
923 sei.cbSize = sizeof(sei);
924 sei.lpVerb = openW;
925 sei.nShow = SW_SHOWNORMAL;
926 sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NO_CONSOLE;
927 sei.lpFile = szTarget;
929 if (ShellExecuteExW(&sei)) return S_OK;
932 return E_NOTIMPL;
935 /***********************************************************************
936 * HlinkNavigateString (URLMON.@)
938 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
940 TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
941 return HlinkSimpleNavigateToString(
942 szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );
945 /***********************************************************************
946 * GetSoftwareUpdateInfo (URLMON.@)
948 HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi )
950 FIXME("%s %p\n", debugstr_w(szDistUnit), psdi );
951 return E_FAIL;
954 /***********************************************************************
955 * AsyncInstallDistributionUnit (URLMON.@)
957 HRESULT WINAPI AsyncInstallDistributionUnit( LPCWSTR szDistUnit, LPCWSTR szTYPE,
958 LPCWSTR szExt, DWORD dwFileVersionMS, DWORD dwFileVersionLS,
959 LPCWSTR szURL, IBindCtx *pbc, LPVOID pvReserved, DWORD flags )
961 FIXME(": stub\n");
962 return E_NOTIMPL;