urlmon: Fallback to URL-based MIME search in FindMimeFromData if found MIME is not concrete.
This commit is contained in:
parent
dbfe0572bd
commit
e5d09bea24
|
@ -417,10 +417,35 @@ static BOOL application_octet_stream_filter(const BYTE *b, DWORD size)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *proposed_mime, WCHAR **ret_mime)
|
static HRESULT find_mime_from_url(const WCHAR *url, WCHAR **ret)
|
||||||
{
|
{
|
||||||
LPCWSTR ret = NULL;
|
const WCHAR *ptr;
|
||||||
int len, i, any_pos_mime = -1;
|
DWORD res, size;
|
||||||
|
WCHAR mime[64];
|
||||||
|
HKEY hkey;
|
||||||
|
|
||||||
|
static const WCHAR content_typeW[] = {'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
|
||||||
|
|
||||||
|
ptr = strrchrW(url, '.');
|
||||||
|
if(!ptr)
|
||||||
|
return E_FAIL;
|
||||||
|
|
||||||
|
res = RegOpenKeyW(HKEY_CLASSES_ROOT, ptr, &hkey);
|
||||||
|
if(res != ERROR_SUCCESS)
|
||||||
|
return HRESULT_FROM_WIN32(res);
|
||||||
|
|
||||||
|
size = sizeof(mime);
|
||||||
|
res = RegQueryValueExW(hkey, content_typeW, NULL, NULL, (LPBYTE)mime, &size);
|
||||||
|
RegCloseKey(hkey);
|
||||||
|
if(res != ERROR_SUCCESS)
|
||||||
|
return HRESULT_FROM_WIN32(res);
|
||||||
|
|
||||||
|
TRACE("found MIME %s\n", debugstr_w(mime));
|
||||||
|
|
||||||
|
*ret = CoTaskMemAlloc(size);
|
||||||
|
memcpy(*ret, mime, size);
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
|
static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
|
||||||
static const WCHAR text_richtextW[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
|
static const WCHAR text_richtextW[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
|
||||||
|
@ -441,8 +466,7 @@ static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *p
|
||||||
'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
|
'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
|
||||||
static const WCHAR app_xgzipW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
|
static const WCHAR app_xgzipW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
|
||||||
'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
|
'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
|
||||||
static const WCHAR app_javaW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
|
static const WCHAR app_javaW[] = {'a','p','p','l','i','c','a','t','i','o','n','/','j','a','v','a',0};
|
||||||
'j','a','v','a',0};
|
|
||||||
static const WCHAR app_xmsdownloadW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
|
static const WCHAR app_xmsdownloadW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
|
||||||
'x','-','m','s','d','o','w','n','l','o','a','d',0};
|
'x','-','m','s','d','o','w','n','l','o','a','d',0};
|
||||||
static const WCHAR text_plainW[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
|
static const WCHAR text_plainW[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
|
||||||
|
@ -450,7 +474,7 @@ static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *p
|
||||||
'o','c','t','e','t','-','s','t','r','e','a','m','\0'};
|
'o','c','t','e','t','-','s','t','r','e','a','m','\0'};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
LPCWSTR mime;
|
const WCHAR *mime;
|
||||||
BOOL (*filter)(const BYTE *,DWORD);
|
BOOL (*filter)(const BYTE *,DWORD);
|
||||||
} mime_filters_any_pos[] = {
|
} mime_filters_any_pos[] = {
|
||||||
{text_htmlW, text_html_filter},
|
{text_htmlW, text_html_filter},
|
||||||
|
@ -484,6 +508,28 @@ static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *p
|
||||||
{app_octetstreamW, application_octet_stream_filter}
|
{app_octetstreamW, application_octet_stream_filter}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static BOOL is_known_mime_type(const WCHAR *mime)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for(i=0; i < sizeof(mime_filters_any_pos)/sizeof(*mime_filters_any_pos); i++) {
|
||||||
|
if(!strcmpW(mime, mime_filters_any_pos[i].mime))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i < sizeof(mime_filters)/sizeof(*mime_filters); i++) {
|
||||||
|
if(!strcmpW(mime, mime_filters[i].mime))
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *proposed_mime, const WCHAR *url, WCHAR **ret_mime)
|
||||||
|
{
|
||||||
|
int len, i, any_pos_mime = -1;
|
||||||
|
const WCHAR *ret = NULL;
|
||||||
|
|
||||||
if(!buf || !size) {
|
if(!buf || !size) {
|
||||||
if(!proposed_mime)
|
if(!proposed_mime)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
@ -565,6 +611,21 @@ static HRESULT find_mime_from_buffer(const BYTE *buf, DWORD size, const WCHAR *p
|
||||||
if(ret == app_octetstreamW)
|
if(ret == app_octetstreamW)
|
||||||
ret = proposed_mime;
|
ret = proposed_mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(url && (ret == app_octetstreamW || ret == text_plainW)) {
|
||||||
|
WCHAR *url_mime;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
hres = find_mime_from_url(url, &url_mime);
|
||||||
|
if(SUCCEEDED(hres)) {
|
||||||
|
if(!is_known_mime_type(url_mime)) {
|
||||||
|
*ret_mime = url_mime;
|
||||||
|
return hres;
|
||||||
|
}
|
||||||
|
CoTaskMemFree(url_mime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TRACE("found %s for %s\n", debugstr_w(ret), debugstr_an((const char*)buf, min(32, size)));
|
TRACE("found %s for %s\n", debugstr_w(ret), debugstr_an((const char*)buf, min(32, size)));
|
||||||
|
|
||||||
len = strlenW(ret)+1;
|
len = strlenW(ret)+1;
|
||||||
|
@ -599,35 +660,10 @@ HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
|
||||||
if(pwzMimeProposed || pBuffer)
|
if(pwzMimeProposed || pBuffer)
|
||||||
return find_mime_from_buffer(pBuffer, cbSize, pwzMimeProposed, ppwzMimeOut);
|
return find_mime_from_buffer(pBuffer, cbSize, pwzMimeProposed, pwzUrl, ppwzMimeOut);
|
||||||
|
|
||||||
if(pwzUrl) {
|
if(pwzUrl)
|
||||||
HKEY hkey;
|
return find_mime_from_url(pwzUrl, ppwzMimeOut);
|
||||||
DWORD res, size;
|
|
||||||
LPCWSTR ptr;
|
|
||||||
WCHAR mime[64];
|
|
||||||
|
|
||||||
static const WCHAR wszContentType[] =
|
|
||||||
{'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
|
|
||||||
|
|
||||||
ptr = strrchrW(pwzUrl, '.');
|
|
||||||
if(!ptr)
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
res = RegOpenKeyW(HKEY_CLASSES_ROOT, ptr, &hkey);
|
|
||||||
if(res != ERROR_SUCCESS)
|
|
||||||
return HRESULT_FROM_WIN32(res);
|
|
||||||
|
|
||||||
size = sizeof(mime);
|
|
||||||
res = RegQueryValueExW(hkey, wszContentType, NULL, NULL, (LPBYTE)mime, &size);
|
|
||||||
RegCloseKey(hkey);
|
|
||||||
if(res != ERROR_SUCCESS)
|
|
||||||
return HRESULT_FROM_WIN32(res);
|
|
||||||
|
|
||||||
*ppwzMimeOut = CoTaskMemAlloc(size);
|
|
||||||
memcpy(*ppwzMimeOut, mime, size);
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue