2000-04-24 20:03:54 +02:00
|
|
|
/*
|
|
|
|
* UrlMon
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000 Patrik Stridvall
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-04-24 20:03:54 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-06-30 22:53:48 +02:00
|
|
|
#include "winbase.h"
|
2005-09-12 22:12:40 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
|
2004-05-05 03:32:00 +02:00
|
|
|
#define NO_SHLWAPI_REG
|
|
|
|
#include "shlwapi.h"
|
2000-04-24 20:03:54 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2005-09-12 22:12:40 +02:00
|
|
|
#include "wine/unicode.h"
|
2000-04-24 20:03:54 +02:00
|
|
|
|
2004-09-28 21:18:52 +02:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "urlmon.h"
|
2002-08-13 20:20:24 +02:00
|
|
|
#include "urlmon_main.h"
|
2006-05-25 18:43:34 +02:00
|
|
|
#include "ole2.h"
|
2002-08-13 20:20:24 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
2005-02-03 20:38:37 +01:00
|
|
|
LONG URLMON_refCount = 0;
|
|
|
|
|
2002-08-13 20:20:24 +02:00
|
|
|
HINSTANCE URLMON_hInstance = 0;
|
|
|
|
|
2006-05-25 18:35:35 +02:00
|
|
|
DWORD urlmon_tls = 0;
|
|
|
|
|
2002-08-13 20:20:24 +02:00
|
|
|
/***********************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain (URLMON.init)
|
2002-08-13 20:20:24 +02:00
|
|
|
*/
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
2002-08-13 20:20:24 +02:00
|
|
|
{
|
2002-10-19 01:48:57 +02:00
|
|
|
TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
|
2002-08-13 20:20:24 +02:00
|
|
|
|
|
|
|
switch(fdwReason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2003-06-30 22:53:48 +02:00
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
2002-08-13 20:20:24 +02:00
|
|
|
URLMON_hInstance = hinstDLL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2006-05-25 18:35:35 +02:00
|
|
|
if(urlmon_tls)
|
|
|
|
TlsFree(urlmon_tls);
|
2002-08-13 20:20:24 +02:00
|
|
|
URLMON_hInstance = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:03:54 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* DllInstall (URLMON.@)
|
2000-04-24 20:03:54 +02:00
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
|
2000-04-24 20:03:54 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
|
2000-04-24 20:03:54 +02:00
|
|
|
debugstr_w(cmdline));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-05-05 21:40:57 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DllCanUnloadNow (URLMON.@)
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
2002-05-05 21:40:57 +02:00
|
|
|
{
|
2005-02-03 20:38:37 +01:00
|
|
|
return URLMON_refCount != 0 ? S_FALSE : S_OK;
|
2002-05-05 21:40:57 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 21:18:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Urlmon ClassFactory
|
2002-05-05 21:40:57 +02:00
|
|
|
*/
|
2004-09-28 21:18:52 +02:00
|
|
|
typedef struct {
|
|
|
|
IClassFactory ITF_IClassFactory;
|
|
|
|
|
2005-07-03 14:05:03 +02:00
|
|
|
LONG ref;
|
2004-09-28 21:18:52 +02:00
|
|
|
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
|
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
|
|
|
struct object_creation_info
|
|
|
|
{
|
|
|
|
const CLSID *clsid;
|
|
|
|
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct object_creation_info object_creation[] =
|
|
|
|
{
|
2005-09-06 11:27:04 +02:00
|
|
|
{ &CLSID_FileProtocol, FileProtocol_Construct },
|
2005-09-14 17:38:26 +02:00
|
|
|
{ &CLSID_FtpProtocol, FtpProtocol_Construct },
|
|
|
|
{ &CLSID_HttpProtocol, HttpProtocol_Construct },
|
2004-11-30 22:14:21 +01:00
|
|
|
{ &CLSID_InternetSecurityManager, &SecManagerImpl_Construct },
|
|
|
|
{ &CLSID_InternetZoneManager, ZoneMgrImpl_Construct }
|
2004-09-28 21:18:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IClassFactory))
|
|
|
|
{
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
*ppobj = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CF_AddRef(LPCLASSFACTORY iface)
|
|
|
|
{
|
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI CF_Release(LPCLASSFACTORY iface)
|
2002-05-05 21:40:57 +02:00
|
|
|
{
|
2004-09-28 21:18:52 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
|
|
|
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2002-05-05 21:40:57 +02:00
|
|
|
|
2005-07-02 12:49:56 +02:00
|
|
|
if (ref == 0) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
}
|
2005-02-03 20:38:37 +01:00
|
|
|
|
2004-09-28 21:18:52 +02:00
|
|
|
return ref;
|
2002-05-05 21:40:57 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 21:18:52 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI CF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
|
|
|
|
REFIID riid, LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
|
|
|
HRESULT hres;
|
|
|
|
LPUNKNOWN punk;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
|
|
|
|
|
|
|
|
*ppobj = NULL;
|
|
|
|
if(SUCCEEDED(hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk))) {
|
|
|
|
hres = IUnknown_QueryInterface(punk, riid, ppobj);
|
|
|
|
IUnknown_Release(punk);
|
|
|
|
}
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI CF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
|
|
|
|
{
|
2005-02-03 20:38:37 +01:00
|
|
|
TRACE("(%d)\n", dolock);
|
|
|
|
|
|
|
|
if (dolock)
|
|
|
|
URLMON_LockModule();
|
|
|
|
else
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
|
2004-09-28 21:18:52 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IClassFactoryVtbl CF_Vtbl =
|
2004-09-28 21:18:52 +02:00
|
|
|
{
|
|
|
|
CF_QueryInterface,
|
|
|
|
CF_AddRef,
|
|
|
|
CF_Release,
|
|
|
|
CF_CreateInstance,
|
|
|
|
CF_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* DllGetClassObject [URLMON.@]
|
|
|
|
* Retrieves class object from a DLL object
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Docs say returns STDAPI
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* rclsid [I] CLSID for the class object
|
|
|
|
* riid [I] Reference to identifier of interface for class object
|
|
|
|
* ppv [O] Address of variable to receive interface pointer for riid
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
|
|
|
|
* E_UNEXPECTED
|
|
|
|
*/
|
|
|
|
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
2004-09-28 21:18:52 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
IClassFactoryImpl *factory;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if ( !IsEqualGUID( &IID_IClassFactory, riid )
|
|
|
|
&& ! IsEqualGUID( &IID_IUnknown, riid) )
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(object_creation[i].clsid, rclsid))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == sizeof(object_creation)/sizeof(object_creation[0]))
|
|
|
|
{
|
|
|
|
FIXME("%s: no class found.\n", debugstr_guid(rclsid));
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
|
|
|
|
if (factory == NULL) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
factory->ITF_IClassFactory.lpVtbl = &CF_Vtbl;
|
|
|
|
factory->ref = 1;
|
|
|
|
factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
|
|
|
|
|
|
|
|
*ppv = &(factory->ITF_IClassFactory);
|
2005-07-02 12:49:56 +02:00
|
|
|
|
|
|
|
URLMON_LockModule();
|
|
|
|
|
2004-09-28 21:18:52 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-29 16:26:13 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServerEx (URLMON.@)
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllRegisterServerEx(void)
|
2000-04-29 16:26:13 +02:00
|
|
|
{
|
|
|
|
FIXME("(void): stub\n");
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2000-11-01 02:46:24 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* UrlMkSetSessionOption (URLMON.@)
|
|
|
|
*/
|
2005-06-10 21:29:16 +02:00
|
|
|
HRESULT WINAPI UrlMkSetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
|
2004-11-30 22:14:21 +01:00
|
|
|
DWORD Reserved)
|
2000-11-01 02:46:24 +01:00
|
|
|
{
|
2004-11-30 22:14:21 +01:00
|
|
|
FIXME("(%#lx, %p, %#lx): stub\n", dwOption, pBuffer, dwBufferLength);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* UrlMkGetSessionOption (URLMON.@)
|
|
|
|
*/
|
2005-06-10 21:29:16 +02:00
|
|
|
HRESULT WINAPI UrlMkGetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
|
2004-11-30 22:14:21 +01:00
|
|
|
DWORD* pdwBufferLength, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
FIXME("(%#lx, %p, %#lx, %p): stub\n", dwOption, pBuffer, dwBufferLength, pdwBufferLength);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-11-01 02:46:24 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-21 11:44:47 +02:00
|
|
|
static const CHAR Agent[] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
|
|
|
|
|
2002-03-21 02:25:42 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* ObtainUserAgentString (URLMON.@)
|
|
|
|
*/
|
2005-06-10 21:29:16 +02:00
|
|
|
HRESULT WINAPI ObtainUserAgentString(DWORD dwOption, LPSTR pcszUAOut, DWORD *cbSize)
|
2002-03-21 02:25:42 +01:00
|
|
|
{
|
|
|
|
FIXME("(%ld, %p, %p): stub\n", dwOption, pcszUAOut, cbSize);
|
|
|
|
|
|
|
|
if(dwOption) {
|
|
|
|
ERR("dwOption: %ld, must be zero\n", dwOption);
|
|
|
|
}
|
|
|
|
|
2005-06-21 11:44:47 +02:00
|
|
|
if (sizeof(Agent) < *cbSize)
|
|
|
|
*cbSize = sizeof(Agent);
|
|
|
|
lstrcpynA(pcszUAOut, Agent, *cbSize);
|
|
|
|
|
2002-05-05 21:40:57 +02:00
|
|
|
return S_OK;
|
2002-04-09 00:45:34 +02:00
|
|
|
}
|
2004-05-05 03:32:00 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
|
|
|
|
{
|
|
|
|
TRACE("(%s,%s,%08lx)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
|
|
|
|
return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags)==0?S_OK:S_FALSE;
|
|
|
|
}
|
2004-09-09 21:17:57 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IsValidURL (URLMON.@)
|
|
|
|
*
|
|
|
|
* Determines if a specified string is a valid URL.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pBC [I] ignored, must be NULL.
|
|
|
|
* szURL [I] string that represents the URL in question.
|
|
|
|
* dwReserved [I] reserved and must be zero.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: S_FALSE.
|
|
|
|
* returns E_INVALIDARG if one or more of the args is invalid.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* test functionality against windows to see what a valid URL is.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI IsValidURL(LPBC pBC, LPCWSTR szURL, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %s, %ld): stub\n", pBC, debugstr_w(szURL), dwReserved);
|
|
|
|
|
|
|
|
if (pBC != NULL || dwReserved != 0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2005-04-11 14:58:58 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* FaultInIEFeature (URLMON.@)
|
|
|
|
*
|
|
|
|
* Undocumented. Appears to be used by native shdocvw.dll.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI FaultInIEFeature( HWND hwnd, uCLSSPEC * pClassSpec,
|
|
|
|
QUERYCONTEXT *pQuery, DWORD flags )
|
|
|
|
{
|
|
|
|
FIXME("%p %p %p %08lx\n", hwnd, pClassSpec, pQuery, flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2005-05-05 11:50:57 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* CoGetClassObjectFromURL (URLMON.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI CoGetClassObjectFromURL( REFCLSID rclsid, LPCWSTR szCodeURL, DWORD dwFileVersionMS,
|
|
|
|
DWORD dwFileVersionLS, LPCWSTR szContentType,
|
|
|
|
LPBINDCTX pBindCtx, DWORD dwClsContext, LPVOID pvReserved,
|
2005-05-06 16:32:48 +02:00
|
|
|
REFIID riid, LPVOID *ppv )
|
2005-05-05 11:50:57 +02:00
|
|
|
{
|
|
|
|
FIXME("(%s %s %ld %ld %s %p %ld %p %s %p) Stub!\n", debugstr_guid(rclsid), debugstr_w(szCodeURL),
|
|
|
|
dwFileVersionMS, dwFileVersionLS, debugstr_w(szContentType), pBindCtx, dwClsContext, pvReserved,
|
|
|
|
debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2005-09-08 13:01:46 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReleaseBindInfo (URLMON.@)
|
|
|
|
*
|
|
|
|
* Release the resources used by the specified BINDINFO structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pbindinfo [I] BINDINFO to release.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*/
|
|
|
|
void WINAPI ReleaseBindInfo(BINDINFO* pbindinfo)
|
|
|
|
{
|
2006-05-25 18:43:34 +02:00
|
|
|
DWORD size;
|
|
|
|
|
2005-09-08 13:01:46 +02:00
|
|
|
TRACE("(%p)\n", pbindinfo);
|
|
|
|
|
2006-05-25 18:43:34 +02:00
|
|
|
if(!pbindinfo || !(size = pbindinfo->cbSize))
|
2005-09-08 13:01:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
CoTaskMemFree(pbindinfo->szExtraInfo);
|
2006-05-25 18:43:34 +02:00
|
|
|
ReleaseStgMedium(&pbindinfo->stgmedData);
|
|
|
|
|
|
|
|
if(offsetof(BINDINFO, szExtraInfo) < size)
|
|
|
|
CoTaskMemFree(pbindinfo->szCustomVerb);
|
2005-09-08 13:01:46 +02:00
|
|
|
|
2006-05-25 18:43:34 +02:00
|
|
|
|
|
|
|
if(pbindinfo->pUnk && offsetof(BINDINFO, pUnk) < size)
|
2005-09-08 13:01:46 +02:00
|
|
|
IUnknown_Release(pbindinfo->pUnk);
|
2006-05-25 18:43:34 +02:00
|
|
|
|
|
|
|
memset(pbindinfo, 0, size);
|
|
|
|
pbindinfo->cbSize = size;
|
2005-09-08 13:01:46 +02:00
|
|
|
}
|
2005-09-12 22:12:40 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FindMimeFromData (URLMON.@)
|
|
|
|
*
|
|
|
|
* Determines the Multipurpose Internet Mail Extensions (MIME) type from the data provided.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI FindMimeFromData(LPBC pBC, LPCWSTR pwzUrl, LPVOID pBuffer,
|
|
|
|
DWORD cbSize, LPCWSTR pwzMimeProposed, DWORD dwMimeFlags,
|
|
|
|
LPWSTR* ppwzMimeOut, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%s,%p,%ld,%s,0x%lx,%p,0x%lx)\n", pBC, debugstr_w(pwzUrl), pBuffer, cbSize,
|
|
|
|
debugstr_w(pwzMimeProposed), dwMimeFlags, ppwzMimeOut, dwReserved);
|
|
|
|
|
|
|
|
if(dwMimeFlags)
|
|
|
|
WARN("dwMimeFlags=%08lx\n", dwMimeFlags);
|
|
|
|
if(dwReserved)
|
|
|
|
WARN("dwReserved=%ld\n", dwReserved);
|
|
|
|
|
|
|
|
/* pBC seams to not be used */
|
|
|
|
|
|
|
|
if(!ppwzMimeOut || (!pwzUrl && !pBuffer))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(pwzMimeProposed && (!pwzUrl || !pBuffer || (pBuffer && !cbSize))) {
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if(!pwzMimeProposed)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
len = strlenW(pwzMimeProposed)+1;
|
|
|
|
*ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
|
|
|
|
memcpy(*ppwzMimeOut, pwzMimeProposed, len*sizeof(WCHAR));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pBuffer) {
|
|
|
|
UCHAR *ptr = pBuffer;
|
|
|
|
DWORD len;
|
|
|
|
LPCWSTR ret;
|
|
|
|
|
|
|
|
static const WCHAR wszAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
|
|
|
|
'o','c','t','e','t','-','s','t','r','e','a','m','\0'};
|
|
|
|
static const WCHAR wszTextPlain[] = {'t','e','x','t','/','p','l','a','i','n','\0'};
|
|
|
|
|
|
|
|
if(!cbSize)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
ret = wszTextPlain;
|
|
|
|
for(ptr = pBuffer; ptr < (UCHAR*)pBuffer+cbSize-1; ptr++) {
|
|
|
|
if(*ptr < 0x20 && *ptr != '\n' && *ptr != '\r' && *ptr != '\t') {
|
|
|
|
ret = wszAppOctetStream;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlenW(ret)+1;
|
|
|
|
*ppwzMimeOut = CoTaskMemAlloc(len*sizeof(WCHAR));
|
|
|
|
memcpy(*ppwzMimeOut, ret, len*sizeof(WCHAR));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pwzUrl) {
|
|
|
|
HKEY hkey;
|
|
|
|
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 E_FAIL;
|
|
|
|
|
|
|
|
size = sizeof(mime);
|
|
|
|
res = RegQueryValueExW(hkey, wszContentType, NULL, NULL, (LPBYTE)mime, &size);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
*ppwzMimeOut = CoTaskMemAlloc(size);
|
|
|
|
memcpy(*ppwzMimeOut, mime, size);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|