urlmon: Fix handling of proposed mime.

This commit is contained in:
Jacek Caban 2006-07-06 20:02:49 +02:00 committed by Alexandre Julliard
parent b5fa092756
commit ae9e41c639
1 changed files with 27 additions and 2 deletions

View File

@ -455,7 +455,7 @@ HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
if(!ppwzMimeOut || (!pwzUrl && !pBuffer)) if(!ppwzMimeOut || (!pwzUrl && !pBuffer))
return E_INVALIDARG; return E_INVALIDARG;
if(pwzMimeProposed && (!pwzUrl || !pBuffer || (pBuffer && !cbSize))) { if(pwzMimeProposed && (!pBuffer || (pBuffer && !cbSize))) {
DWORD len; DWORD len;
if(!pwzMimeProposed) if(!pwzMimeProposed)
@ -470,7 +470,7 @@ HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
if(pBuffer) { if(pBuffer) {
DWORD len; DWORD len;
LPCWSTR ret = NULL; LPCWSTR ret = NULL;
int i = 0; int i;
static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0}; static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
static const WCHAR wszImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0}; static const WCHAR wszImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
@ -491,12 +491,37 @@ HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
if(!cbSize) if(!cbSize)
return E_FAIL; return E_FAIL;
if(pwzMimeProposed && strcmpW(pwzMimeProposed, wszAppOctetStream)) {
for(i=0; i < sizeof(mime_filters)/sizeof(*mime_filters); i++) {
if(!strcmpW(pwzMimeProposed, mime_filters[i].mime))
break;
}
if(i == sizeof(mime_filters)/sizeof(*mime_filters)
|| mime_filters[i].filter(pBuffer, cbSize)) {
len = strlenW(pwzMimeProposed)+1;
*ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
memcpy(*ppwzMimeOut, pwzMimeProposed, len*sizeof(WCHAR));
return S_OK;
}
}
i=0;
while(!ret) { while(!ret) {
if(mime_filters[i].filter(pBuffer, cbSize)) if(mime_filters[i].filter(pBuffer, cbSize))
ret = mime_filters[i].mime; ret = mime_filters[i].mime;
i++; i++;
} }
if(pwzMimeProposed) {
if(i == sizeof(mime_filters)/sizeof(*mime_filters))
ret = pwzMimeProposed;
/* text/html is a special case */
if(!strcmpW(pwzMimeProposed, wszTextHtml) && !strcmpW(ret, wszTextPlain))
ret = wszTextHtml;
}
len = strlenW(ret)+1; len = strlenW(ret)+1;
*ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR)); *ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
memcpy(*ppwzMimeOut, ret, len*sizeof(WCHAR)); memcpy(*ppwzMimeOut, ret, len*sizeof(WCHAR));