wined3d: Pass a pointer to struct wined3d_shader_dst_param to shader_glsl_add_dst_par...
[wine] / dlls / urlmon / urlmon_main.c
1 /*
2  * UrlMon
3  *
4  * Copyright (c) 2000 Patrik Stridvall
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "urlmon_main.h"
24
25 #include "winreg.h"
26
27 #define NO_SHLWAPI_REG
28 #include "shlwapi.h"
29 #include "wine/debug.h"
30
31 #include "urlmon.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
34
35 LONG URLMON_refCount = 0;
36
37 HINSTANCE URLMON_hInstance = 0;
38 static HMODULE hCabinet = NULL;
39
40 static void init_session(BOOL);
41
42 /***********************************************************************
43  *              DllMain (URLMON.init)
44  */
45 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
46 {
47     TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
48
49     switch(fdwReason) {
50     case DLL_PROCESS_ATTACH:
51         DisableThreadLibraryCalls(hinstDLL);
52         URLMON_hInstance = hinstDLL;
53         init_session(TRUE);
54         break;
55
56     case DLL_PROCESS_DETACH:
57         if (hCabinet)
58             FreeLibrary(hCabinet);
59         hCabinet = NULL;
60         init_session(FALSE);
61         URLMON_hInstance = 0;
62         break;
63     }
64     return TRUE;
65 }
66
67
68 /***********************************************************************
69  *              DllInstall (URLMON.@)
70  */
71 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
72 {
73   FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
74         debugstr_w(cmdline));
75
76   return S_OK;
77 }
78
79 /***********************************************************************
80  *              DllCanUnloadNow (URLMON.@)
81  */
82 HRESULT WINAPI DllCanUnloadNow(void)
83 {
84     return URLMON_refCount != 0 ? S_FALSE : S_OK;
85 }
86
87
88
89 /******************************************************************************
90  * Urlmon ClassFactory
91  */
92 typedef struct {
93     const IClassFactoryVtbl *lpClassFactoryVtbl;
94
95     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
96 } ClassFactory;
97
98 #define CLASSFACTORY(x)  ((IClassFactory*)  &(x)->lpClassFactoryVtbl)
99
100 static HRESULT WINAPI CF_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppv)
101 {
102     *ppv = NULL;
103
104     if(IsEqualGUID(riid, &IID_IUnknown)) {
105         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
106         *ppv = iface;
107     }else if(IsEqualGUID(riid, &IID_IClassFactory)) {
108         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
109         *ppv = iface;
110     }
111
112     if(*ppv) {
113         IUnknown_AddRef((IUnknown*)*ppv);
114         return S_OK;
115     }
116
117     WARN("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ppv);
118     return E_NOINTERFACE;
119 }
120
121 static ULONG WINAPI CF_AddRef(IClassFactory *iface)
122 {
123     URLMON_LockModule();
124     return 2;
125 }
126
127 static ULONG WINAPI CF_Release(IClassFactory *iface)
128 {
129     URLMON_UnlockModule();
130     return 1;
131 }
132
133
134 static HRESULT WINAPI CF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
135                                         REFIID riid, LPVOID *ppobj)
136 {
137     ClassFactory *This = (ClassFactory*)iface;
138     HRESULT hres;
139     LPUNKNOWN punk;
140     
141     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
142
143     *ppobj = NULL;
144     if(SUCCEEDED(hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk))) {
145         hres = IUnknown_QueryInterface(punk, riid, ppobj);
146         IUnknown_Release(punk);
147     }
148     return hres;
149 }
150
151 static HRESULT WINAPI CF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
152 {
153     TRACE("(%d)\n", dolock);
154
155     if (dolock)
156            URLMON_LockModule();
157     else
158            URLMON_UnlockModule();
159
160     return S_OK;
161 }
162
163 static const IClassFactoryVtbl ClassFactoryVtbl =
164 {
165     CF_QueryInterface,
166     CF_AddRef,
167     CF_Release,
168     CF_CreateInstance,
169     CF_LockServer
170 };
171
172 static const ClassFactory FileProtocolCF =
173     { &ClassFactoryVtbl, FileProtocol_Construct};
174 static const ClassFactory FtpProtocolCF =
175     { &ClassFactoryVtbl, FtpProtocol_Construct};
176 static const ClassFactory GopherProtocolCF =
177     { &ClassFactoryVtbl, GopherProtocol_Construct};
178 static const ClassFactory HttpProtocolCF =
179     { &ClassFactoryVtbl, HttpProtocol_Construct};
180 static const ClassFactory HttpSProtocolCF =
181     { &ClassFactoryVtbl, HttpSProtocol_Construct};
182 static const ClassFactory MkProtocolCF =
183     { &ClassFactoryVtbl, MkProtocol_Construct};
184 static const ClassFactory SecurityManagerCF =
185     { &ClassFactoryVtbl, SecManagerImpl_Construct};
186 static const ClassFactory ZoneManagerCF =
187     { &ClassFactoryVtbl, ZoneMgrImpl_Construct};
188 static const ClassFactory StdURLMonikerCF =
189     { &ClassFactoryVtbl, StdURLMoniker_Construct};
190  
191 struct object_creation_info
192 {
193     const CLSID *clsid;
194     IClassFactory *cf;
195     LPCWSTR protocol;
196 };
197
198 static const WCHAR wszFile[] = {'f','i','l','e',0};
199 static const WCHAR wszFtp[]  = {'f','t','p',0};
200 static const WCHAR wszGopher[]  = {'g','o','p','h','e','r',0};
201 static const WCHAR wszHttp[] = {'h','t','t','p',0};
202 static const WCHAR wszHttps[] = {'h','t','t','p','s',0};
203 static const WCHAR wszMk[]   = {'m','k',0};
204
205 static const struct object_creation_info object_creation[] =
206 {
207     { &CLSID_FileProtocol,            CLASSFACTORY(&FileProtocolCF),    wszFile },
208     { &CLSID_FtpProtocol,             CLASSFACTORY(&FtpProtocolCF),     wszFtp  },
209     { &CLSID_GopherProtocol,          CLASSFACTORY(&GopherProtocolCF),  wszGopher },
210     { &CLSID_HttpProtocol,            CLASSFACTORY(&HttpProtocolCF),    wszHttp },
211     { &CLSID_HttpSProtocol,           CLASSFACTORY(&HttpSProtocolCF),   wszHttps },
212     { &CLSID_MkProtocol,              CLASSFACTORY(&MkProtocolCF),      wszMk },
213     { &CLSID_InternetSecurityManager, CLASSFACTORY(&SecurityManagerCF), NULL    },
214     { &CLSID_InternetZoneManager,     CLASSFACTORY(&ZoneManagerCF),     NULL    },
215     { &CLSID_StdURLMoniker,           CLASSFACTORY(&StdURLMonikerCF),   NULL    }
216 };
217
218 static void init_session(BOOL init)
219 {
220     unsigned int i;
221
222     for(i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++) {
223
224         if(object_creation[i].protocol)
225             register_urlmon_namespace(object_creation[i].cf, object_creation[i].clsid,
226                                       object_creation[i].protocol, init);
227     }
228 }
229
230 /*******************************************************************************
231  * DllGetClassObject [URLMON.@]
232  * Retrieves class object from a DLL object
233  *
234  * NOTES
235  *    Docs say returns STDAPI
236  *
237  * PARAMS
238  *    rclsid [I] CLSID for the class object
239  *    riid   [I] Reference to identifier of interface for class object
240  *    ppv    [O] Address of variable to receive interface pointer for riid
241  *
242  * RETURNS
243  *    Success: S_OK
244  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
245  *             E_UNEXPECTED
246  */
247
248 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
249 {
250     unsigned int i;
251     
252     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
253     
254     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
255     {
256         if (IsEqualGUID(object_creation[i].clsid, rclsid))
257             return IClassFactory_QueryInterface(object_creation[i].cf, riid, ppv);
258     }
259
260     FIXME("%s: no class found.\n", debugstr_guid(rclsid));
261     return CLASS_E_CLASSNOTAVAILABLE;
262 }
263
264
265 /***********************************************************************
266  *              DllRegisterServerEx (URLMON.@)
267  */
268 HRESULT WINAPI DllRegisterServerEx(void)
269 {
270     FIXME("(void): stub\n");
271
272     return E_FAIL;
273 }
274
275 /**************************************************************************
276  *                 UrlMkSetSessionOption (URLMON.@)
277  */
278 HRESULT WINAPI UrlMkSetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
279                                         DWORD Reserved)
280 {
281     FIXME("(%#x, %p, %#x): stub\n", dwOption, pBuffer, dwBufferLength);
282
283     return S_OK;
284 }
285
286 static const CHAR Agent[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
287
288 /**************************************************************************
289  *                 ObtainUserAgentString (URLMON.@)
290  */
291 HRESULT WINAPI ObtainUserAgentString(DWORD dwOption, LPSTR pcszUAOut, DWORD *cbSize)
292 {
293     FIXME("(%d, %p, %p): stub\n", dwOption, pcszUAOut, cbSize);
294
295     if (pcszUAOut == NULL || cbSize == NULL)
296         return E_INVALIDARG;
297
298     if (*cbSize < sizeof(Agent))
299     {
300         *cbSize = sizeof(Agent);
301         return E_OUTOFMEMORY;
302     }
303
304     if (sizeof(Agent) < *cbSize)
305         *cbSize = sizeof(Agent);
306     lstrcpynA(pcszUAOut, Agent, *cbSize);
307
308     return S_OK;
309 }
310
311 /**************************************************************************
312  *                 IsValidURL (URLMON.@)
313  * 
314  * Determines if a specified string is a valid URL.
315  *
316  * PARAMS
317  *  pBC        [I] ignored, must be NULL.
318  *  szURL      [I] string that represents the URL in question.
319  *  dwReserved [I] reserved and must be zero.
320  *
321  * RETURNS
322  *  Success: S_OK.
323  *  Failure: S_FALSE.
324  *  returns E_INVALIDARG if one or more of the args is invalid.
325  *
326  * TODO:
327  *  test functionality against windows to see what a valid URL is.
328  */
329 HRESULT WINAPI IsValidURL(LPBC pBC, LPCWSTR szURL, DWORD dwReserved)
330 {
331     FIXME("(%p, %s, %d): stub\n", pBC, debugstr_w(szURL), dwReserved);
332     
333     if (pBC != NULL || dwReserved != 0)
334         return E_INVALIDARG;
335     
336     return S_OK;
337 }
338
339 /**************************************************************************
340  *                 FaultInIEFeature (URLMON.@)
341  *
342  *  Undocumented.  Appears to be used by native shdocvw.dll.
343  */
344 HRESULT WINAPI FaultInIEFeature( HWND hwnd, uCLSSPEC * pClassSpec,
345                                  QUERYCONTEXT *pQuery, DWORD flags )
346 {
347     FIXME("%p %p %p %08x\n", hwnd, pClassSpec, pQuery, flags);
348     return E_NOTIMPL;
349 }
350
351 /**************************************************************************
352  *                 CoGetClassObjectFromURL (URLMON.@)
353  */
354 HRESULT WINAPI CoGetClassObjectFromURL( REFCLSID rclsid, LPCWSTR szCodeURL, DWORD dwFileVersionMS,
355                                         DWORD dwFileVersionLS, LPCWSTR szContentType,
356                                         LPBINDCTX pBindCtx, DWORD dwClsContext, LPVOID pvReserved,
357                                         REFIID riid, LPVOID *ppv )
358 {
359     FIXME("(%s %s %d %d %s %p %d %p %s %p) Stub!\n", debugstr_guid(rclsid), debugstr_w(szCodeURL),
360         dwFileVersionMS, dwFileVersionLS, debugstr_w(szContentType), pBindCtx, dwClsContext, pvReserved,
361         debugstr_guid(riid), ppv);
362     return E_NOINTERFACE;
363 }
364
365 /***********************************************************************
366  *           ReleaseBindInfo (URLMON.@)
367  *
368  * Release the resources used by the specified BINDINFO structure.
369  *
370  * PARAMS
371  *  pbindinfo [I] BINDINFO to release.
372  *
373  * RETURNS
374  *  Nothing.
375  */
376 void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
377 {
378     DWORD size;
379
380     TRACE("(%p)\n", pbindinfo);
381
382     if(!pbindinfo || !(size = pbindinfo->cbSize))
383         return;
384
385     CoTaskMemFree(pbindinfo->szExtraInfo);
386     ReleaseStgMedium(&pbindinfo->stgmedData);
387
388     if(offsetof(BINDINFO, szExtraInfo) < size)
389         CoTaskMemFree(pbindinfo->szCustomVerb);
390
391     if(pbindinfo->pUnk && offsetof(BINDINFO, pUnk) < size)
392         IUnknown_Release(pbindinfo->pUnk);
393
394     memset(pbindinfo, 0, size);
395     pbindinfo->cbSize = size;
396 }
397
398 /***********************************************************************
399  *           CopyStgMedium (URLMON.@)
400  */
401 HRESULT WINAPI CopyStgMedium(const STGMEDIUM *src, STGMEDIUM *dst)
402 {
403     TRACE("(%p %p)\n", src, dst);
404
405     if(!src || !dst)
406         return E_POINTER;
407
408     *dst = *src;
409
410     switch(dst->tymed) {
411     case TYMED_NULL:
412         break;
413     case TYMED_FILE:
414         if(src->u.lpszFileName && !src->pUnkForRelease) {
415             DWORD size = (strlenW(src->u.lpszFileName)+1)*sizeof(WCHAR);
416             dst->u.lpszFileName = CoTaskMemAlloc(size);
417             memcpy(dst->u.lpszFileName, src->u.lpszFileName, size);
418         }
419         break;
420     case TYMED_ISTREAM:
421         if(dst->u.pstm)
422             IStream_AddRef(dst->u.pstm);
423         break;
424     case TYMED_ISTORAGE:
425         if(dst->u.pstg)
426             IStorage_AddRef(dst->u.pstg);
427         break;
428     default:
429         FIXME("Unimplemented tymed %d\n", src->tymed);
430     }
431
432     if(dst->pUnkForRelease)
433         IUnknown_AddRef(dst->pUnkForRelease);
434
435     return S_OK;
436 }
437
438 static BOOL text_richtext_filter(const BYTE *b, DWORD size)
439 {
440     return size > 5 && !memcmp(b, "{\\rtf", 5);
441 }
442
443 static BOOL text_html_filter(const BYTE *b, DWORD size)
444 {
445     DWORD i;
446
447     if(size < 5)
448         return FALSE;
449
450     for(i=0; i < size-5; i++) {
451         if(b[i] == '<'
452            && (b[i+1] == 'h' || b[i+1] == 'H')
453            && (b[i+2] == 't' || b[i+2] == 'T')
454            && (b[i+3] == 'm' || b[i+3] == 'M')
455            && (b[i+4] == 'l' || b[i+4] == 'L'))
456             return TRUE;
457     }
458
459     return FALSE;
460 }
461
462 static BOOL audio_basic_filter(const BYTE *b, DWORD size)
463 {
464     return size > 4
465         && b[0] == '.' && b[1] == 's' && b[2] == 'n' && b[3] == 'd';
466 }
467
468 static BOOL audio_wav_filter(const BYTE *b, DWORD size)
469 {
470     return size > 12
471         && b[0] == 'R' && b[1] == 'I' && b[2] == 'F' && b[3] == 'F'
472         && b[8] == 'W' && b[9] == 'A' && b[10] == 'V' && b[11] == 'E';
473 }
474
475 static BOOL image_gif_filter(const BYTE *b, DWORD size)
476 {
477     return size >= 6
478         && (b[0] == 'G' || b[0] == 'g')
479         && (b[1] == 'I' || b[1] == 'i')
480         && (b[2] == 'F' || b[2] == 'f')
481         &&  b[3] == '8'
482         && (b[4] == '7' || b[4] == '9')
483         && (b[5] == 'A' || b[5] == 'a');
484 }
485
486 static BOOL image_pjpeg_filter(const BYTE *b, DWORD size)
487 {
488     return size > 2 && b[0] == 0xff && b[1] == 0xd8;
489 }
490
491 static BOOL image_tiff_filter(const BYTE *b, DWORD size)
492 {
493     return size > 2 && b[0] == 0x4d && b[1] == 0x4d;
494 }
495
496 static BOOL image_xpng_filter(const BYTE *b, DWORD size)
497 {
498     static const BYTE xpng_header[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a};
499     return size > sizeof(xpng_header) && !memcmp(b, xpng_header, sizeof(xpng_header));
500 }
501
502 static BOOL image_bmp_filter(const BYTE *b, DWORD size)
503 {
504     return size >= 14
505         && b[0] == 0x42 && b[1] == 0x4d
506         && *(const DWORD *)(b+6) == 0;
507 }
508
509 static BOOL video_avi_filter(const BYTE *b, DWORD size)
510 {
511     return size > 12
512         && b[0] == 'R' && b[1] == 'I' && b[2] == 'F' && b[3] == 'F'
513         && b[8] == 'A' && b[9] == 'V' && b[10] == 'I' && b[11] == 0x20;
514 }
515
516 static BOOL video_mpeg_filter(const BYTE *b, DWORD size)
517 {
518     return size > 4
519         && !b[0] && !b[1] && b[2] == 0x01
520         && (b[3] == 0xb3 || b[3] == 0xba);
521 }
522
523 static BOOL application_postscript_filter(const BYTE *b, DWORD size)
524 {
525     return size > 2 && b[0] == '%' && b[1] == '!';
526 }
527
528 static BOOL application_pdf_filter(const BYTE *b, DWORD size)
529 {
530     return size > 4 && b[0] == 0x25 && b[1] == 0x50 && b[2] == 0x44 && b[3] == 0x46;
531 }
532
533 static BOOL application_xzip_filter(const BYTE *b, DWORD size)
534 {
535     return size > 2 && b[0] == 0x50 && b[1] == 0x4b;
536 }
537
538 static BOOL application_xgzip_filter(const BYTE *b, DWORD size)
539 {
540     return size > 2 && b[0] == 0x1f && b[1] == 0x8b;
541 }
542
543 static BOOL application_java_filter(const BYTE *b, DWORD size)
544 {
545     return size > 4 && b[0] == 0xca && b[1] == 0xfe && b[2] == 0xba && b[3] == 0xbe;
546 }
547
548 static BOOL application_xmsdownload(const BYTE *b, DWORD size)
549 {
550     return size > 2 && b[0] == 'M' && b[1] == 'Z';
551 }
552
553 static BOOL text_plain_filter(const BYTE *b, DWORD size)
554 {
555     const BYTE *ptr;
556
557     for(ptr = b; ptr < b+size-1; ptr++) {
558         if(*ptr < 0x20 && *ptr != '\n' && *ptr != '\r' && *ptr != '\t')
559             return FALSE;
560     }
561
562     return TRUE;
563 }
564
565 static BOOL application_octet_stream_filter(const BYTE *b, DWORD size)
566 {
567     return TRUE;
568 }
569
570 /***********************************************************************
571  *           FindMimeFromData (URLMON.@)
572  *
573  * Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
574  */
575 HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
576         DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
577         LPWSTR* ppwzMimeOut, DWORD dwReserved)
578 {
579     TRACE("(%p,%s,%p,%d,%s,0x%x,%p,0x%x)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
580             debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
581
582     if(dwMimeFlags)
583         WARN("dwMimeFlags=%08x\n", dwMimeFlags);
584     if(dwReserved)
585         WARN("dwReserved=%d\n", dwReserved);
586
587     /* pBC seams to not be used */
588
589     if(!ppwzMimeOut || (!pwzUrl && !pBuffer))
590         return E_INVALIDARG;
591
592     if(pwzMimeProposed && (!pBuffer || (pBuffer && !cbSize))) {
593         DWORD len;
594
595         if(!pwzMimeProposed)
596             return E_FAIL;
597
598         len = strlenW(pwzMimeProposed)+1;
599         *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
600         memcpy(*ppwzMimeOut, pwzMimeProposed, len*sizeof(WCHAR));
601         return S_OK;
602     }
603
604     if(pBuffer) {
605         const BYTE *buf = pBuffer;
606         DWORD len;
607         LPCWSTR ret = NULL;
608         unsigned int i;
609
610         static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
611         static const WCHAR wszTextRichtext[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
612         static const WCHAR wszAudioBasic[] = {'a','u','d','i','o','/','b','a','s','i','c',0};
613         static const WCHAR wszAudioWav[] = {'a','u','d','i','o','/','w','a','v',0};
614         static const WCHAR wszImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
615         static const WCHAR wszImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
616         static const WCHAR wszImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
617         static const WCHAR wszImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
618         static const WCHAR wszImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
619         static const WCHAR wszVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
620         static const WCHAR wszVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
621         static const WCHAR wszAppPostscript[] =
622             {'a','p','p','l','i','c','a','t','i','o','n','/','p','o','s','t','s','c','r','i','p','t',0};
623         static const WCHAR wszAppPdf[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
624             'p','d','f',0};
625         static const WCHAR wszAppXZip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
626             'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
627         static const WCHAR wszAppXGzip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
628             'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
629         static const WCHAR wszAppJava[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
630             'j','a','v','a',0};
631         static const WCHAR wszAppXMSDownload[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
632             'x','-','m','s','d','o','w','n','l','o','a','d',0};
633         static const WCHAR wszTextPlain[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
634         static const WCHAR wszAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
635             'o','c','t','e','t','-','s','t','r','e','a','m','\0'};
636
637         static const struct {
638             LPCWSTR mime;
639             BOOL (*filter)(const BYTE *,DWORD);
640         } mime_filters[] = {
641             {wszTextHtml,       text_html_filter},
642             {wszTextRichtext,   text_richtext_filter},
643          /* {wszAudioXAiff,     audio_xaiff_filter}, */
644             {wszAudioBasic,     audio_basic_filter},
645             {wszAudioWav,       audio_wav_filter},
646             {wszImageGif,       image_gif_filter},
647             {wszImagePjpeg,     image_pjpeg_filter},
648             {wszImageTiff,      image_tiff_filter},
649             {wszImageXPng,      image_xpng_filter},
650          /* {wszImageXBitmap,   image_xbitmap_filter}, */
651             {wszImageBmp,       image_bmp_filter},
652          /* {wszImageXJg,       image_xjg_filter}, */
653          /* {wszImageXEmf,      image_xemf_filter}, */
654          /* {wszImageXWmf,      image_xwmf_filter}, */
655             {wszVideoAvi,       video_avi_filter},
656             {wszVideoMpeg,      video_mpeg_filter},
657             {wszAppPostscript,  application_postscript_filter},
658          /* {wszAppBase64,      application_base64_filter}, */
659          /* {wszAppMacbinhex40, application_macbinhex40_filter}, */
660             {wszAppPdf,         application_pdf_filter},
661          /* {wszAppXCompressed, application_xcompressed_filter}, */
662             {wszAppXZip,        application_xzip_filter},
663             {wszAppXGzip,       application_xgzip_filter},
664             {wszAppJava,        application_java_filter},
665             {wszAppXMSDownload, application_xmsdownload},
666             {wszTextPlain,      text_plain_filter},
667             {wszAppOctetStream, application_octet_stream_filter}
668         };
669
670         if(!cbSize)
671             return E_FAIL;
672
673         if(pwzMimeProposed && strcmpW(pwzMimeProposed, wszAppOctetStream)) {
674             for(i=0; i < sizeof(mime_filters)/sizeof(*mime_filters); i++) {
675                 if(!strcmpW(pwzMimeProposed, mime_filters[i].mime))
676                     break;
677             }
678
679             if(i == sizeof(mime_filters)/sizeof(*mime_filters)
680                     || mime_filters[i].filter(buf, cbSize)) {
681                 len = strlenW(pwzMimeProposed)+1;
682                 *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
683                 memcpy(*ppwzMimeOut, pwzMimeProposed, len*sizeof(WCHAR));
684                 return S_OK;
685             }
686         }
687
688         i=0;
689         while(!ret) {
690             if(mime_filters[i].filter(buf, cbSize))
691                 ret = mime_filters[i].mime;
692             i++;
693         }
694
695         TRACE("found %s for data\n"
696               "%02x %02x %02x %02x  %02x %02x %02x %02x  %02x %02x %02x %02x  %02x %02x %02x %02x\n",
697               debugstr_w(ret), buf[0],buf[1],buf[2],buf[3], buf[4],buf[5],buf[6],buf[7],
698               buf[8],buf[9],buf[10],buf[11], buf[12],buf[13],buf[14],buf[15]);
699
700         if(pwzMimeProposed) {
701             if(i == sizeof(mime_filters)/sizeof(*mime_filters))
702                 ret = pwzMimeProposed;
703
704             /* text/html is a special case */
705             if(!strcmpW(pwzMimeProposed, wszTextHtml) && !strcmpW(ret, wszTextPlain))
706                 ret = wszTextHtml;
707         }
708
709         len = strlenW(ret)+1;
710         *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
711         memcpy(*ppwzMimeOut, ret, len*sizeof(WCHAR));
712         return S_OK;
713     }
714
715     if(pwzUrl) {
716         HKEY hkey;
717         DWORD res, size;
718         LPCWSTR ptr;
719         WCHAR mime[64];
720
721         static const WCHAR wszContentType[] =
722                 {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
723
724         ptr = strrchrW(pwzUrl, '.');
725         if(!ptr)
726             return E_FAIL;
727
728         res = RegOpenKeyW(HKEY_CLASSES_ROOT, ptr, &hkey);
729         if(res != ERROR_SUCCESS)
730             return HRESULT_FROM_WIN32(res);
731
732         size = sizeof(mime);
733         res = RegQueryValueExW(hkey, wszContentType, NULL, NULL, (LPBYTE)mime, &size);
734         RegCloseKey(hkey);
735         if(res != ERROR_SUCCESS)
736             return HRESULT_FROM_WIN32(res);
737
738         *ppwzMimeOut = CoTaskMemAlloc(size);
739         memcpy(*ppwzMimeOut, mime, size);
740         return S_OK;
741     }
742
743     return E_FAIL;
744 }
745
746 /***********************************************************************
747  *           GetClassFileOrMime (URLMON.@)
748  *
749  * Determines the class ID from the bind context, file name or MIME type.
750  */
751 HRESULT WINAPI GetClassFileOrMime(LPBC pBC, LPCWSTR pszFilename,
752         LPVOID pBuffer, DWORD cbBuffer, LPCWSTR pszMimeType, DWORD dwReserved,
753         CLSID *pclsid)
754 {
755     FIXME("(%p, %s, %p, %d, %p, 0x%08x, %p): stub\n", pBC,
756         debugstr_w(pszFilename), pBuffer, cbBuffer, debugstr_w(pszMimeType),
757         dwReserved, pclsid);
758     return E_NOTIMPL;
759 }
760
761 /***********************************************************************
762  * Extract (URLMON.@)
763  */
764 HRESULT WINAPI Extract(void *dest, LPCSTR szCabName)
765 {
766     HRESULT (WINAPI *pExtract)(void *, LPCSTR);
767
768     if (!hCabinet)
769         hCabinet = LoadLibraryA("cabinet.dll");
770
771     if (!hCabinet) return HRESULT_FROM_WIN32(GetLastError());
772     pExtract = (void *)GetProcAddress(hCabinet, "Extract");
773     if (!pExtract) return HRESULT_FROM_WIN32(GetLastError());
774
775     return pExtract(dest, szCabName);
776 }
777
778 /***********************************************************************
779  *           IsLoggingEnabledA (URLMON.@)
780  */
781 BOOL WINAPI IsLoggingEnabledA(LPCSTR url)
782 {
783     FIXME("(%s)\n", debugstr_a(url));
784     return FALSE;
785 }
786
787 /***********************************************************************
788  *           IsLoggingEnabledW (URLMON.@)
789  */
790 BOOL WINAPI IsLoggingEnabledW(LPCWSTR url)
791 {
792     FIXME("(%s)\n", debugstr_w(url));
793     return FALSE;
794 }