4 * Copyright (c) 2000 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "urlmon_main.h"
27 #define NO_SHLWAPI_REG
32 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
38 DEFINE_GUID(CLSID_CUri, 0xDF2FCE13, 0x25EC, 0x45BB, 0x9D,0x4C, 0xCE,0xCD,0x47,0xC2,0x43,0x0C);
40 LONG URLMON_refCount = 0;
42 static HMODULE hCabinet = NULL;
43 static DWORD urlmon_tls = TLS_OUT_OF_INDEXES;
45 static void init_session(BOOL);
47 static struct list tls_list = LIST_INIT(tls_list);
49 static CRITICAL_SECTION tls_cs;
50 static CRITICAL_SECTION_DEBUG tls_cs_dbg =
53 { &tls_cs_dbg.ProcessLocksList, &tls_cs_dbg.ProcessLocksList },
54 0, 0, { (DWORD_PTR)(__FILE__ ": tls") }
57 static CRITICAL_SECTION tls_cs = { &tls_cs_dbg, -1, 0, 0, 0, 0 };
59 tls_data_t *get_tls_data(void)
63 if(urlmon_tls == TLS_OUT_OF_INDEXES) {
64 DWORD tls = TlsAlloc();
65 if(tls == TLS_OUT_OF_INDEXES)
68 tls = InterlockedCompareExchange((LONG*)&urlmon_tls, tls, TLS_OUT_OF_INDEXES);
73 data = TlsGetValue(urlmon_tls);
75 data = heap_alloc_zero(sizeof(tls_data_t));
79 EnterCriticalSection(&tls_cs);
80 list_add_tail(&tls_list, &data->entry);
81 LeaveCriticalSection(&tls_cs);
83 TlsSetValue(urlmon_tls, data);
89 static void free_tls_list(void)
93 if(urlmon_tls == TLS_OUT_OF_INDEXES)
96 while(!list_empty(&tls_list)) {
97 data = LIST_ENTRY(list_head(&tls_list), tls_data_t, entry);
98 list_remove(&data->entry);
105 static void detach_thread(void)
109 if(urlmon_tls == TLS_OUT_OF_INDEXES)
112 data = TlsGetValue(urlmon_tls);
116 EnterCriticalSection(&tls_cs);
117 list_remove(&data->entry);
118 LeaveCriticalSection(&tls_cs);
120 if(data->notif_hwnd) {
121 WARN("notif_hwnd not destroyed\n");
122 DestroyWindow(data->notif_hwnd);
128 static void process_detach(void)
130 HINTERNET internet_session;
132 internet_session = get_internet_session(NULL);
134 InternetCloseHandle(internet_session);
137 FreeLibrary(hCabinet);
144 /***********************************************************************
145 * DllMain (URLMON.init)
147 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
149 TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
151 URLMON_DllMain( hinstDLL, fdwReason, fImpLoad );
154 case DLL_PROCESS_ATTACH:
158 case DLL_PROCESS_DETACH:
160 DeleteCriticalSection(&tls_cs);
163 case DLL_THREAD_DETACH:
171 /***********************************************************************
172 * DllInstall (URLMON.@)
174 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
176 FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
177 debugstr_w(cmdline));
182 /***********************************************************************
183 * DllCanUnloadNow (URLMON.@)
185 HRESULT WINAPI DllCanUnloadNow(void)
187 return URLMON_refCount != 0 ? S_FALSE : S_OK;
192 /******************************************************************************
193 * Urlmon ClassFactory
196 IClassFactory IClassFactory_iface;
198 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
201 static inline ClassFactory *impl_from_IClassFactory(IClassFactory *iface)
203 return CONTAINING_RECORD(iface, ClassFactory, IClassFactory_iface);
206 static HRESULT WINAPI CF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppv)
210 if(IsEqualGUID(riid, &IID_IUnknown)) {
211 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
213 }else if(IsEqualGUID(riid, &IID_IClassFactory)) {
214 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
219 IUnknown_AddRef((IUnknown*)*ppv);
223 WARN("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ppv);
224 return E_NOINTERFACE;
227 static ULONG WINAPI CF_AddRef(IClassFactory *iface)
233 static ULONG WINAPI CF_Release(IClassFactory *iface)
235 URLMON_UnlockModule();
240 static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
241 REFIID riid, LPVOID *ppobj)
243 ClassFactory *This = impl_from_IClassFactory(iface);
247 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
250 if(SUCCEEDED(hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk))) {
251 hres = IUnknown_QueryInterface(punk, riid, ppobj);
252 IUnknown_Release(punk);
257 static HRESULT WINAPI CF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
259 TRACE("(%d)\n", dolock);
264 URLMON_UnlockModule();
269 static const IClassFactoryVtbl ClassFactoryVtbl =
278 static ClassFactory FileProtocolCF =
279 { { &ClassFactoryVtbl }, FileProtocol_Construct};
280 static ClassFactory FtpProtocolCF =
281 { { &ClassFactoryVtbl }, FtpProtocol_Construct};
282 static ClassFactory GopherProtocolCF =
283 { { &ClassFactoryVtbl }, GopherProtocol_Construct};
284 static ClassFactory HttpProtocolCF =
285 { { &ClassFactoryVtbl }, HttpProtocol_Construct};
286 static ClassFactory HttpSProtocolCF =
287 { { &ClassFactoryVtbl }, HttpSProtocol_Construct};
288 static ClassFactory MkProtocolCF =
289 { { &ClassFactoryVtbl }, MkProtocol_Construct};
290 static ClassFactory SecurityManagerCF =
291 { { &ClassFactoryVtbl }, SecManagerImpl_Construct};
292 static ClassFactory ZoneManagerCF =
293 { { &ClassFactoryVtbl }, ZoneMgrImpl_Construct};
294 static ClassFactory StdURLMonikerCF =
295 { { &ClassFactoryVtbl }, StdURLMoniker_Construct};
296 static ClassFactory MimeFilterCF =
297 { { &ClassFactoryVtbl }, MimeFilter_Construct};
298 static ClassFactory CUriCF =
299 { { &ClassFactoryVtbl }, Uri_Construct};
301 struct object_creation_info
308 static const WCHAR wszFile[] = {'f','i','l','e',0};
309 static const WCHAR wszFtp[] = {'f','t','p',0};
310 static const WCHAR wszGopher[] = {'g','o','p','h','e','r',0};
311 static const WCHAR wszHttp[] = {'h','t','t','p',0};
312 static const WCHAR wszHttps[] = {'h','t','t','p','s',0};
313 static const WCHAR wszMk[] = {'m','k',0};
315 static const struct object_creation_info object_creation[] =
317 { &CLSID_FileProtocol, &FileProtocolCF.IClassFactory_iface, wszFile },
318 { &CLSID_FtpProtocol, &FtpProtocolCF.IClassFactory_iface, wszFtp },
319 { &CLSID_GopherProtocol, &GopherProtocolCF.IClassFactory_iface, wszGopher },
320 { &CLSID_HttpProtocol, &HttpProtocolCF.IClassFactory_iface, wszHttp },
321 { &CLSID_HttpSProtocol, &HttpSProtocolCF.IClassFactory_iface, wszHttps },
322 { &CLSID_MkProtocol, &MkProtocolCF.IClassFactory_iface, wszMk },
323 { &CLSID_InternetSecurityManager, &SecurityManagerCF.IClassFactory_iface, NULL },
324 { &CLSID_InternetZoneManager, &ZoneManagerCF.IClassFactory_iface, NULL },
325 { &CLSID_StdURLMoniker, &StdURLMonikerCF.IClassFactory_iface, NULL },
326 { &CLSID_DeCompMimeFilter, &MimeFilterCF.IClassFactory_iface, NULL },
327 { &CLSID_CUri, &CUriCF.IClassFactory_iface, NULL }
330 static void init_session(BOOL init)
334 for(i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++) {
336 if(object_creation[i].protocol)
337 register_urlmon_namespace(object_creation[i].cf, object_creation[i].clsid,
338 object_creation[i].protocol, init);
342 /*******************************************************************************
343 * DllGetClassObject [URLMON.@]
344 * Retrieves class object from a DLL object
347 * Docs say returns STDAPI
350 * rclsid [I] CLSID for the class object
351 * riid [I] Reference to identifier of interface for class object
352 * ppv [O] Address of variable to receive interface pointer for riid
356 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
360 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
365 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
367 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
369 if (IsEqualGUID(object_creation[i].clsid, rclsid))
370 return IClassFactory_QueryInterface(object_creation[i].cf, riid, ppv);
373 hr = URLMON_DllGetClassObject(rclsid, riid, ppv);
377 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
378 return CLASS_E_CLASSNOTAVAILABLE;
381 static HRESULT register_inf(BOOL doregister)
383 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
386 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
388 hAdvpack = LoadLibraryW(wszAdvpack);
389 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
391 return pRegInstall(hProxyDll, doregister ? "RegisterDll" : "UnregisterDll", NULL);
394 /***********************************************************************
395 * DllRegisterServer (URLMON.@)
397 HRESULT WINAPI DllRegisterServer(void)
403 hr = URLMON_DllRegisterServer();
404 return SUCCEEDED(hr) ? register_inf(TRUE) : hr;
407 /***********************************************************************
408 * DllUnregisterServer (URLMON.@)
410 HRESULT WINAPI DllUnregisterServer(void)
416 hr = URLMON_DllUnregisterServer();
417 return SUCCEEDED(hr) ? register_inf(FALSE) : hr;
420 /***********************************************************************
421 * DllRegisterServerEx (URLMON.@)
423 HRESULT WINAPI DllRegisterServerEx(void)
425 FIXME("(void): stub\n");
430 /**************************************************************************
431 * IsValidURL (URLMON.@)
433 * Determines if a specified string is a valid URL.
436 * pBC [I] ignored, should be NULL.
437 * szURL [I] string that represents the URL in question.
438 * dwReserved [I] reserved and must be zero.
443 * returns E_INVALIDARG if one or more of the args is invalid.
446 * test functionality against windows to see what a valid URL is.
448 HRESULT WINAPI IsValidURL(LPBC pBC, LPCWSTR szURL, DWORD dwReserved)
450 FIXME("(%p, %s, %d): stub\n", pBC, debugstr_w(szURL), dwReserved);
452 if (dwReserved || !szURL)
458 /**************************************************************************
459 * FaultInIEFeature (URLMON.@)
461 * Undocumented. Appears to be used by native shdocvw.dll.
463 HRESULT WINAPI FaultInIEFeature( HWND hwnd, uCLSSPEC * pClassSpec,
464 QUERYCONTEXT *pQuery, DWORD flags )
466 FIXME("%p %p %p %08x\n", hwnd, pClassSpec, pQuery, flags);
470 /**************************************************************************
471 * CoGetClassObjectFromURL (URLMON.@)
473 HRESULT WINAPI CoGetClassObjectFromURL( REFCLSID rclsid, LPCWSTR szCodeURL, DWORD dwFileVersionMS,
474 DWORD dwFileVersionLS, LPCWSTR szContentType,
475 LPBINDCTX pBindCtx, DWORD dwClsContext, LPVOID pvReserved,
476 REFIID riid, LPVOID *ppv )
478 FIXME("(%s %s %d %d %s %p %d %p %s %p) Stub!\n", debugstr_guid(rclsid), debugstr_w(szCodeURL),
479 dwFileVersionMS, dwFileVersionLS, debugstr_w(szContentType), pBindCtx, dwClsContext, pvReserved,
480 debugstr_guid(riid), ppv);
481 return E_NOINTERFACE;
484 /***********************************************************************
485 * ReleaseBindInfo (URLMON.@)
487 * Release the resources used by the specified BINDINFO structure.
490 * pbindinfo [I] BINDINFO to release.
495 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
499 TRACE("(%p)\n", pbindinfo);
501 if(!pbindinfo || !(size = pbindinfo->cbSize))
504 CoTaskMemFree(pbindinfo->szExtraInfo);
505 ReleaseStgMedium(&pbindinfo->stgmedData);
507 if(offsetof(BINDINFO, szExtraInfo) < size)
508 CoTaskMemFree(pbindinfo->szCustomVerb);
510 if(pbindinfo->pUnk && offsetof(BINDINFO, pUnk) < size)
511 IUnknown_Release(pbindinfo->pUnk);
513 memset(pbindinfo, 0, size);
514 pbindinfo->cbSize = size;
517 /***********************************************************************
518 * CopyStgMedium (URLMON.@)
520 HRESULT WINAPI CopyStgMedium(const STGMEDIUM *src, STGMEDIUM *dst)
522 TRACE("(%p %p)\n", src, dst);
533 if(src->u.lpszFileName && !src->pUnkForRelease) {
534 DWORD size = (strlenW(src->u.lpszFileName)+1)*sizeof(WCHAR);
535 dst->u.lpszFileName = CoTaskMemAlloc(size);
536 if(!dst->u.lpszFileName)
537 return E_OUTOFMEMORY;
538 memcpy(dst->u.lpszFileName, src->u.lpszFileName, size);
543 IStream_AddRef(dst->u.pstm);
547 IStorage_AddRef(dst->u.pstg);
550 FIXME("Unimplemented tymed %d\n", src->tymed);
553 if(dst->pUnkForRelease)
554 IUnknown_AddRef(dst->pUnkForRelease);
559 /***********************************************************************
560 * CopyBindInfo (URLMON.@)
562 HRESULT WINAPI CopyBindInfo(const BINDINFO *pcbiSrc, BINDINFO *pcbiDest)
567 TRACE("(%p %p)\n", pcbiSrc, pcbiDest);
569 if(!pcbiSrc || !pcbiDest)
571 if(!pcbiSrc->cbSize || !pcbiDest->cbSize)
574 size = pcbiDest->cbSize;
575 if(size > pcbiSrc->cbSize) {
576 memcpy(pcbiDest, pcbiSrc, pcbiSrc->cbSize);
577 memset((char*)pcbiDest+pcbiSrc->cbSize, 0, size-pcbiSrc->cbSize);
579 memcpy(pcbiDest, pcbiSrc, size);
581 pcbiDest->cbSize = size;
583 size = FIELD_OFFSET(BINDINFO, szExtraInfo)+sizeof(void*);
584 if(pcbiSrc->cbSize>=size && pcbiDest->cbSize>=size && pcbiSrc->szExtraInfo) {
585 size = (strlenW(pcbiSrc->szExtraInfo)+1)*sizeof(WCHAR);
586 pcbiDest->szExtraInfo = CoTaskMemAlloc(size);
587 if(!pcbiDest->szExtraInfo)
588 return E_OUTOFMEMORY;
589 memcpy(pcbiDest->szExtraInfo, pcbiSrc->szExtraInfo, size);
592 size = FIELD_OFFSET(BINDINFO, stgmedData)+sizeof(STGMEDIUM);
593 if(pcbiSrc->cbSize>=size && pcbiDest->cbSize>=size) {
594 hres = CopyStgMedium(&pcbiSrc->stgmedData, &pcbiDest->stgmedData);
596 CoTaskMemFree(pcbiDest->szExtraInfo);
601 size = FIELD_OFFSET(BINDINFO, szCustomVerb)+sizeof(void*);
602 if(pcbiSrc->cbSize>=size && pcbiDest->cbSize>=size && pcbiSrc->szCustomVerb) {
603 size = (strlenW(pcbiSrc->szCustomVerb)+1)*sizeof(WCHAR);
604 pcbiDest->szCustomVerb = CoTaskMemAlloc(size);
605 if(!pcbiDest->szCustomVerb) {
606 CoTaskMemFree(pcbiDest->szExtraInfo);
607 ReleaseStgMedium(&pcbiDest->stgmedData);
608 return E_OUTOFMEMORY;
612 size = FIELD_OFFSET(BINDINFO, securityAttributes)+sizeof(SECURITY_ATTRIBUTES);
613 if(pcbiDest->cbSize >= size)
614 memset(&pcbiDest->securityAttributes, 0, sizeof(SECURITY_ATTRIBUTES));
617 IUnknown_AddRef(pcbiDest->pUnk);
622 static BOOL text_richtext_filter(const BYTE *b, DWORD size)
624 return size > 5 && !memcmp(b, "{\\rtf", 5);
627 static BOOL text_html_filter(const BYTE *b, DWORD size)
634 for(i = 0; i < size-5; i++) {
636 && (b[i+1] == 'h' || b[i+1] == 'H')
637 && (b[i+2] == 't' || b[i+2] == 'T')
638 && (b[i+3] == 'm' || b[i+3] == 'M')
639 && (b[i+4] == 'l' || b[i+4] == 'L')) ||
642 && (b[i+1] == 'h' || b[i+1] == 'H')
643 && (b[i+2] == 'e' || b[i+2] == 'E')
644 && (b[i+3] == 'a' || b[i+3] == 'A')
645 && (b[i+4] == 'd' || b[i+4] == 'D')
646 && b[i+5] == '>')) return TRUE;
652 static BOOL audio_basic_filter(const BYTE *b, DWORD size)
655 && b[0] == '.' && b[1] == 's' && b[2] == 'n' && b[3] == 'd';
658 static BOOL audio_wav_filter(const BYTE *b, DWORD size)
661 && b[0] == 'R' && b[1] == 'I' && b[2] == 'F' && b[3] == 'F'
662 && b[8] == 'W' && b[9] == 'A' && b[10] == 'V' && b[11] == 'E';
665 static BOOL image_gif_filter(const BYTE *b, DWORD size)
668 && (b[0] == 'G' || b[0] == 'g')
669 && (b[1] == 'I' || b[1] == 'i')
670 && (b[2] == 'F' || b[2] == 'f')
672 && (b[4] == '7' || b[4] == '9')
673 && (b[5] == 'A' || b[5] == 'a');
676 static BOOL image_pjpeg_filter(const BYTE *b, DWORD size)
678 return size > 2 && b[0] == 0xff && b[1] == 0xd8;
681 static BOOL image_tiff_filter(const BYTE *b, DWORD size)
683 static const BYTE magic1[] = {0x4d,0x4d,0x00,0x2a};
684 static const BYTE magic2[] = {0x49,0x49,0x2a,0xff};
686 return size >= 4 && (!memcmp(b, magic1, 4) || !memcmp(b, magic2, 4));
689 static BOOL image_xpng_filter(const BYTE *b, DWORD size)
691 static const BYTE xpng_header[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a};
692 return size > sizeof(xpng_header) && !memcmp(b, xpng_header, sizeof(xpng_header));
695 static BOOL image_bmp_filter(const BYTE *b, DWORD size)
698 && b[0] == 0x42 && b[1] == 0x4d
699 && *(const DWORD *)(b+6) == 0;
702 static BOOL video_avi_filter(const BYTE *b, DWORD size)
705 && b[0] == 'R' && b[1] == 'I' && b[2] == 'F' && b[3] == 'F'
706 && b[8] == 'A' && b[9] == 'V' && b[10] == 'I' && b[11] == 0x20;
709 static BOOL video_mpeg_filter(const BYTE *b, DWORD size)
712 && !b[0] && !b[1] && b[2] == 0x01
713 && (b[3] == 0xb3 || b[3] == 0xba);
716 static BOOL application_postscript_filter(const BYTE *b, DWORD size)
718 return size > 2 && b[0] == '%' && b[1] == '!';
721 static BOOL application_pdf_filter(const BYTE *b, DWORD size)
723 return size > 4 && b[0] == 0x25 && b[1] == 0x50 && b[2] == 0x44 && b[3] == 0x46;
726 static BOOL application_xzip_filter(const BYTE *b, DWORD size)
728 return size > 2 && b[0] == 0x50 && b[1] == 0x4b;
731 static BOOL application_xgzip_filter(const BYTE *b, DWORD size)
733 return size > 2 && b[0] == 0x1f && b[1] == 0x8b;
736 static BOOL application_java_filter(const BYTE *b, DWORD size)
738 return size > 4 && b[0] == 0xca && b[1] == 0xfe && b[2] == 0xba && b[3] == 0xbe;
741 static BOOL application_xmsdownload(const BYTE *b, DWORD size)
743 return size > 2 && b[0] == 'M' && b[1] == 'Z';
746 static BOOL text_plain_filter(const BYTE *b, DWORD size)
750 for(ptr = b; ptr < b+size-1; ptr++) {
751 if(*ptr < 0x20 && *ptr != '\n' && *ptr != '\r' && *ptr != '\t')
758 static BOOL application_octet_stream_filter(const BYTE *b, DWORD size)
763 static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *proposed_mime, WCHAR **ret_mime)
768 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
769 static const WCHAR text_richtextW[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
770 static const WCHAR audio_basicW[] = {'a','u','d','i','o','/','b','a','s','i','c',0};
771 static const WCHAR audio_wavW[] = {'a','u','d','i','o','/','w','a','v',0};
772 static const WCHAR image_gifW[] = {'i','m','a','g','e','/','g','i','f',0};
773 static const WCHAR image_pjpegW[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
774 static const WCHAR image_tiffW[] = {'i','m','a','g','e','/','t','i','f','f',0};
775 static const WCHAR image_xpngW[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
776 static const WCHAR image_bmpW[] = {'i','m','a','g','e','/','b','m','p',0};
777 static const WCHAR video_aviW[] = {'v','i','d','e','o','/','a','v','i',0};
778 static const WCHAR video_mpegW[] = {'v','i','d','e','o','/','m','p','e','g',0};
779 static const WCHAR app_postscriptW[] =
780 {'a','p','p','l','i','c','a','t','i','o','n','/','p','o','s','t','s','c','r','i','p','t',0};
781 static const WCHAR app_pdfW[] = {'a','p','p','l','i','c','a','t','i','o','n','/','p','d','f',0};
782 static const WCHAR app_xzipW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
783 'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
784 static const WCHAR app_xgzipW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
785 'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
786 static const WCHAR app_javaW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
788 static const WCHAR app_xmsdownloadW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
789 'x','-','m','s','d','o','w','n','l','o','a','d',0};
790 static const WCHAR text_plainW[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
791 static const WCHAR app_octetstreamW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
792 'o','c','t','e','t','-','s','t','r','e','a','m','\0'};
794 static const struct {
796 BOOL (*filter)(const BYTE *,DWORD);
798 {text_htmlW, text_html_filter},
799 {text_richtextW, text_richtext_filter},
800 /* {audio_xaiffW, audio_xaiff_filter}, */
801 {audio_basicW, audio_basic_filter},
802 {audio_wavW, audio_wav_filter},
803 {image_gifW, image_gif_filter},
804 {image_pjpegW, image_pjpeg_filter},
805 {image_tiffW, image_tiff_filter},
806 {image_xpngW, image_xpng_filter},
807 /* {image_xbitmapW, image_xbitmap_filter}, */
808 {image_bmpW, image_bmp_filter},
809 /* {image_xjgW, image_xjg_filter}, */
810 /* {image_xemfW, image_xemf_filter}, */
811 /* {image_xwmfW, image_xwmf_filter}, */
812 {video_aviW, video_avi_filter},
813 {video_mpegW, video_mpeg_filter},
814 {app_postscriptW, application_postscript_filter},
815 /* {app_base64W, application_base64_filter}, */
816 /* {app_macbinhex40W, application_macbinhex40_filter}, */
817 {app_pdfW, application_pdf_filter},
818 /* {app_zcompressedW, application_xcompressed_filter}, */
819 {app_xzipW, application_xzip_filter},
820 {app_xgzipW, application_xgzip_filter},
821 {app_javaW, application_java_filter},
822 {app_xmsdownloadW, application_xmsdownload},
823 {text_plainW, text_plain_filter},
824 {app_octetstreamW, application_octet_stream_filter}
831 len = strlenW(proposed_mime)+1;
832 *ret_mime = CoTaskMemAlloc(len*sizeof(WCHAR));
834 return E_OUTOFMEMORY;
836 memcpy(*ret_mime, proposed_mime, len*sizeof(WCHAR));
840 if(proposed_mime && strcmpW(proposed_mime, app_octetstreamW)) {
841 for(i=0; i < sizeof(mime_filters)/sizeof(*mime_filters); i++) {
842 if(!strcmpW(proposed_mime, mime_filters[i].mime))
846 if(i == sizeof(mime_filters)/sizeof(*mime_filters) || mime_filters[i].filter(buf, size)) {
847 len = strlenW(proposed_mime)+1;
848 *ret_mime = CoTaskMemAlloc(len*sizeof(WCHAR));
850 return E_OUTOFMEMORY;
852 memcpy(*ret_mime, proposed_mime, len*sizeof(WCHAR));
859 if(mime_filters[i].filter(buf, size))
860 ret = mime_filters[i].mime;
864 TRACE("found %s for %s\n", debugstr_w(ret), debugstr_an((const char*)buf, min(32, size)));
867 if(i == sizeof(mime_filters)/sizeof(*mime_filters))
870 /* text/html is a special case */
871 if(!strcmpW(proposed_mime, text_htmlW) && !strcmpW(ret, text_plainW))
875 len = strlenW(ret)+1;
876 *ret_mime = CoTaskMemAlloc(len*sizeof(WCHAR));
878 return E_OUTOFMEMORY;
880 memcpy(*ret_mime, ret, len*sizeof(WCHAR));
884 /***********************************************************************
885 * FindMimeFromData (URLMON.@)
887 * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
889 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
890 DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
891 LPWSTR* ppwzMimeOut, DWORD dwReserved)
893 TRACE("(%p,%s,%p,%d,%s,0x%x,%p,0x%x)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
894 debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
897 WARN("dwMimeFlags=%08x\n", dwMimeFlags);
899 WARN("dwReserved=%d\n", dwReserved);
901 /* pBC seams to not be used */
903 if(!ppwzMimeOut || (!pwzUrl && !pBuffer))
906 if(pwzMimeProposed || pBuffer)
907 return find_mime_from_buffer(pBuffer, cbSize, pwzMimeProposed, ppwzMimeOut);
915 static const WCHAR wszContentType[] =
916 {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
918 ptr = strrchrW(pwzUrl, '.');
922 res = RegOpenKeyW(HKEY_CLASSES_ROOT, ptr, &hkey);
923 if(res != ERROR_SUCCESS)
924 return HRESULT_FROM_WIN32(res);
927 res = RegQueryValueExW(hkey, wszContentType, NULL, NULL, (LPBYTE)mime, &size);
929 if(res != ERROR_SUCCESS)
930 return HRESULT_FROM_WIN32(res);
932 *ppwzMimeOut = CoTaskMemAlloc(size);
933 memcpy(*ppwzMimeOut, mime, size);
940 /***********************************************************************
941 * GetClassFileOrMime (URLMON.@)
943 * Determines the class ID from the bind context, file name or MIME type.
945 HRESULT WINAPI GetClassFileOrMime(LPBC pBC, LPCWSTR pszFilename,
946 LPVOID pBuffer, DWORD cbBuffer, LPCWSTR pszMimeType, DWORD dwReserved,
949 FIXME("(%p, %s, %p, %d, %p, 0x%08x, %p): stub\n", pBC,
950 debugstr_w(pszFilename), pBuffer, cbBuffer, debugstr_w(pszMimeType),
955 /***********************************************************************
958 HRESULT WINAPI Extract(void *dest, LPCSTR szCabName)
960 HRESULT (WINAPI *pExtract)(void *, LPCSTR);
963 hCabinet = LoadLibraryA("cabinet.dll");
965 if (!hCabinet) return HRESULT_FROM_WIN32(GetLastError());
966 pExtract = (void *)GetProcAddress(hCabinet, "Extract");
967 if (!pExtract) return HRESULT_FROM_WIN32(GetLastError());
969 return pExtract(dest, szCabName);
972 /***********************************************************************
973 * IsLoggingEnabledA (URLMON.@)
975 BOOL WINAPI IsLoggingEnabledA(LPCSTR url)
977 FIXME("(%s)\n", debugstr_a(url));
981 /***********************************************************************
982 * IsLoggingEnabledW (URLMON.@)
984 BOOL WINAPI IsLoggingEnabledW(LPCWSTR url)
986 FIXME("(%s)\n", debugstr_w(url));
990 /***********************************************************************
991 * IsProtectedModeURL (URLMON.111)
992 * Undocumented, added in IE7
994 BOOL WINAPI IsProtectedModeURL(const WCHAR *url)
996 FIXME("stub: %s\n", debugstr_w(url));
1000 /***********************************************************************
1001 * LogSqmBits (URLMON.410)
1002 * Undocumented, added in IE8
1004 int WINAPI LogSqmBits(DWORD unk1, DWORD unk2)
1006 FIXME("stub: %d %d\n", unk1, unk2);
1010 /***********************************************************************
1011 * LogSqmUXCommandOffsetInternal (URLMON.423)
1012 * Undocumented, added in IE8
1014 void WINAPI LogSqmUXCommandOffsetInternal(DWORD unk1, DWORD unk2, DWORD unk3, DWORD unk4)
1016 FIXME("stub: %d %d %d %d\n", unk1, unk2, unk3, unk4);
1019 /***********************************************************************
1020 * MapUriToBrowserEmulationState (URLMON.444)
1021 * Undocumented, added in IE8
1023 int WINAPI MapUriToBrowserEmulationState(DWORD unk1, DWORD unk2, DWORD unk3)
1025 FIXME("stub: %d %d %d\n", unk1, unk2, unk3);
1029 /***********************************************************************
1030 * MapBrowserEmulationModeToUserAgent (URLMON.445)
1031 * Undocumented, added in IE8
1033 int WINAPI MapBrowserEmulationModeToUserAgent(DWORD unk1, DWORD unk2)
1035 FIXME("stub: %d %d\n", unk1, unk2);
1039 /***********************************************************************
1040 * RegisterMediaTypes
1041 * Added in IE3, registers known MIME-type strings.
1043 HRESULT WINAPI RegisterMediaTypes(UINT types, LPCSTR *szTypes, CLIPFORMAT *cfTypes)
1045 FIXME("stub: %u %p %p\n", types, szTypes, cfTypes);
1046 return E_INVALIDARG;