2005-09-15 20:47:13 +02:00
|
|
|
/*
|
2006-05-24 18:00:08 +02:00
|
|
|
* Copyright 2005-2006 Jacek Caban for CodeWeavers
|
2005-09-15 20:47:13 +02: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
|
2005-09-15 20:47:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "urlmon_main.h"
|
2007-12-13 20:26:51 +01:00
|
|
|
#include "winreg.h"
|
2005-09-15 20:47:13 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
typedef struct {
|
2006-05-24 17:59:07 +02:00
|
|
|
LPWSTR protocol;
|
|
|
|
IClassFactory *cf;
|
2007-01-23 19:35:35 +01:00
|
|
|
CLSID clsid;
|
2008-02-21 13:08:06 +01:00
|
|
|
BOOL urlmon;
|
2006-05-24 17:59:07 +02:00
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
struct list entry;
|
2006-05-24 17:59:07 +02:00
|
|
|
} name_space;
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
typedef struct {
|
2007-12-28 02:00:10 +01:00
|
|
|
IClassFactory *cf;
|
|
|
|
CLSID clsid;
|
|
|
|
LPWSTR mime;
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
struct list entry;
|
2007-12-28 02:00:10 +01:00
|
|
|
} mime_filter;
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
static struct list name_space_list = LIST_INIT(name_space_list);
|
|
|
|
static struct list mime_filter_list = LIST_INIT(mime_filter_list);
|
2006-05-24 17:59:07 +02:00
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
static CRITICAL_SECTION session_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG session_cs_dbg =
|
|
|
|
{
|
|
|
|
0, 0, &session_cs,
|
|
|
|
{ &session_cs_dbg.ProcessLocksList, &session_cs_dbg.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": session") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION session_cs = { &session_cs_dbg, -1, 0, 0, 0, 0 };
|
|
|
|
|
2007-01-23 19:35:35 +01:00
|
|
|
static name_space *find_name_space(LPCWSTR protocol)
|
2005-11-14 13:28:18 +01:00
|
|
|
{
|
2006-05-24 18:00:08 +02:00
|
|
|
name_space *iter;
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &name_space_list, name_space, entry) {
|
2019-06-24 10:15:45 +02:00
|
|
|
if(!wcsicmp(iter->protocol, protocol))
|
2007-01-23 19:35:35 +01:00
|
|
|
return iter;
|
2006-05-24 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-22 21:13:01 +01:00
|
|
|
static HRESULT get_protocol_cf(LPCWSTR schema, DWORD schema_len, CLSID *pclsid, IClassFactory **ret)
|
2006-05-24 18:00:08 +02:00
|
|
|
{
|
|
|
|
WCHAR str_clsid[64];
|
2005-11-14 13:28:18 +01:00
|
|
|
HKEY hkey = NULL;
|
2006-05-24 18:00:08 +02:00
|
|
|
DWORD res, type, size;
|
2005-11-14 13:28:18 +01:00
|
|
|
CLSID clsid;
|
|
|
|
LPWSTR wszKey;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR wszProtocolsKey[] =
|
|
|
|
{'P','R','O','T','O','C','O','L','S','\\','H','a','n','d','l','e','r','\\'};
|
|
|
|
|
2007-11-29 22:12:34 +01:00
|
|
|
wszKey = heap_alloc(sizeof(wszProtocolsKey)+(schema_len+1)*sizeof(WCHAR));
|
2005-11-14 13:28:18 +01:00
|
|
|
memcpy(wszKey, wszProtocolsKey, sizeof(wszProtocolsKey));
|
2018-07-05 17:22:32 +02:00
|
|
|
memcpy(wszKey + ARRAY_SIZE(wszProtocolsKey), schema, (schema_len+1)*sizeof(WCHAR));
|
2005-11-14 13:28:18 +01:00
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszKey, &hkey);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(wszKey);
|
2005-11-14 13:28:18 +01:00
|
|
|
if(res != ERROR_SUCCESS) {
|
2006-07-22 15:21:20 +02:00
|
|
|
TRACE("Could not open protocol handler key\n");
|
2010-10-06 14:10:08 +02:00
|
|
|
return MK_E_SYNTAX;
|
2005-11-14 13:28:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof(str_clsid);
|
2020-12-03 00:32:46 +01:00
|
|
|
res = RegQueryValueExW(hkey, L"CLSID", NULL, &type, (BYTE*)str_clsid, &size);
|
2005-11-14 13:28:18 +01:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
if(res != ERROR_SUCCESS || type != REG_SZ) {
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("Could not get protocol CLSID res=%d\n", res);
|
2010-10-06 14:10:08 +02:00
|
|
|
return MK_E_SYNTAX;
|
2005-11-14 13:28:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hres = CLSIDFromString(str_clsid, &clsid);
|
|
|
|
if(FAILED(hres)) {
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("CLSIDFromString failed: %08x\n", hres);
|
2005-11-14 13:28:18 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2007-01-23 19:35:35 +01:00
|
|
|
if(pclsid)
|
|
|
|
*pclsid = clsid;
|
|
|
|
|
2008-01-29 00:18:33 +01:00
|
|
|
if(!ret)
|
|
|
|
return S_OK;
|
|
|
|
|
2010-10-06 14:10:08 +02:00
|
|
|
hres = CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)ret);
|
|
|
|
return SUCCEEDED(hres) ? S_OK : MK_E_SYNTAX;
|
2005-11-14 13:28:18 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:09:30 +01:00
|
|
|
HRESULT register_namespace(IClassFactory *cf, REFIID clsid, LPCWSTR protocol, BOOL urlmon_protocol)
|
2008-02-21 13:07:41 +01:00
|
|
|
{
|
|
|
|
name_space *new_name_space;
|
|
|
|
|
|
|
|
new_name_space = heap_alloc(sizeof(name_space));
|
|
|
|
|
|
|
|
if(!urlmon_protocol)
|
|
|
|
IClassFactory_AddRef(cf);
|
|
|
|
new_name_space->cf = cf;
|
|
|
|
new_name_space->clsid = *clsid;
|
2008-02-21 13:08:06 +01:00
|
|
|
new_name_space->urlmon = urlmon_protocol;
|
2008-02-21 13:07:41 +01:00
|
|
|
new_name_space->protocol = heap_strdupW(protocol);
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
list_add_head(&name_space_list, &new_name_space->entry);
|
2008-02-21 13:07:41 +01:00
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
2008-02-21 13:07:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-21 13:08:06 +01:00
|
|
|
static HRESULT unregister_namespace(IClassFactory *cf, LPCWSTR protocol)
|
2008-02-21 13:07:41 +01:00
|
|
|
{
|
2012-03-13 14:09:09 +01:00
|
|
|
name_space *iter;
|
2008-02-21 13:07:41 +01:00
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &name_space_list, name_space, entry) {
|
2019-06-24 10:15:45 +02:00
|
|
|
if(iter->cf == cf && !wcsicmp(iter->protocol, protocol)) {
|
2012-03-13 14:09:09 +01:00
|
|
|
list_remove(&iter->entry);
|
2008-02-21 13:07:41 +01:00
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
2008-02-21 13:07:41 +01:00
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
if(!iter->urlmon)
|
|
|
|
IClassFactory_Release(iter->cf);
|
|
|
|
heap_free(iter->protocol);
|
|
|
|
heap_free(iter);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-02-21 13:07:41 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
2008-02-21 13:07:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-29 00:18:33 +01:00
|
|
|
BOOL is_registered_protocol(LPCWSTR url)
|
|
|
|
{
|
|
|
|
DWORD schema_len;
|
|
|
|
WCHAR schema[64];
|
|
|
|
HRESULT hres;
|
|
|
|
|
2018-07-05 17:22:32 +02:00
|
|
|
hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, ARRAY_SIZE(schema), &schema_len, 0);
|
2008-01-29 00:18:33 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return get_protocol_cf(schema, schema_len, NULL, NULL) == S_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-24 18:00:08 +02:00
|
|
|
IInternetProtocolInfo *get_protocol_info(LPCWSTR url)
|
|
|
|
{
|
|
|
|
IInternetProtocolInfo *ret = NULL;
|
2007-02-22 21:13:01 +01:00
|
|
|
IClassFactory *cf;
|
2007-01-23 19:35:35 +01:00
|
|
|
name_space *ns;
|
2006-05-24 18:00:08 +02:00
|
|
|
WCHAR schema[64];
|
|
|
|
DWORD schema_len;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2018-07-05 17:22:32 +02:00
|
|
|
hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, ARRAY_SIZE(schema), &schema_len, 0);
|
2006-05-24 18:00:08 +02:00
|
|
|
if(FAILED(hres) || !schema_len)
|
|
|
|
return NULL;
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
EnterCriticalSection(&session_cs);
|
2008-02-21 13:08:06 +01:00
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
ns = find_name_space(schema);
|
|
|
|
if(ns && !ns->urlmon) {
|
2007-01-23 19:35:35 +01:00
|
|
|
hres = IClassFactory_QueryInterface(ns->cf, &IID_IInternetProtocolInfo, (void**)&ret);
|
2008-02-21 13:08:44 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
hres = IClassFactory_CreateInstance(ns->cf, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
|
2006-05-24 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
|
|
|
if(ns && SUCCEEDED(hres))
|
|
|
|
return ret;
|
|
|
|
|
2007-02-22 21:13:01 +01:00
|
|
|
hres = get_protocol_cf(schema, schema_len, NULL, &cf);
|
2006-05-24 18:00:08 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
2007-02-22 21:13:01 +01:00
|
|
|
hres = IClassFactory_QueryInterface(cf, &IID_IInternetProtocolInfo, (void**)&ret);
|
|
|
|
if(FAILED(hres))
|
|
|
|
IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
|
|
|
|
IClassFactory_Release(cf);
|
2006-05-24 18:00:08 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-08 18:18:17 +02:00
|
|
|
HRESULT get_protocol_handler(IUri *uri, CLSID *clsid, IClassFactory **ret)
|
2006-05-24 18:00:08 +02:00
|
|
|
{
|
2007-01-23 19:35:35 +01:00
|
|
|
name_space *ns;
|
2010-11-15 12:37:35 +01:00
|
|
|
BSTR scheme;
|
2006-05-24 18:00:08 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
*ret = NULL;
|
|
|
|
|
2010-11-15 12:37:35 +01:00
|
|
|
/* FIXME: Avoid GetSchemeName call for known schemes */
|
|
|
|
hres = IUri_GetSchemeName(uri, &scheme);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2006-05-24 18:00:08 +02:00
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
2010-11-15 12:37:35 +01:00
|
|
|
ns = find_name_space(scheme);
|
2007-01-23 19:35:35 +01:00
|
|
|
if(ns) {
|
|
|
|
*ret = ns->cf;
|
2007-07-24 07:14:58 +02:00
|
|
|
IClassFactory_AddRef(*ret);
|
2007-01-23 19:35:35 +01:00
|
|
|
if(clsid)
|
|
|
|
*clsid = ns->clsid;
|
2006-05-24 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
2018-05-08 18:18:17 +02:00
|
|
|
hres = *ret ? S_OK : get_protocol_cf(scheme, SysStringLen(scheme), clsid, ret);
|
2010-11-15 12:37:35 +01:00
|
|
|
SysFreeString(scheme);
|
|
|
|
return hres;
|
2006-05-24 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
2009-05-18 18:35:32 +02:00
|
|
|
IInternetProtocol *get_mime_filter(LPCWSTR mime)
|
|
|
|
{
|
|
|
|
IClassFactory *cf = NULL;
|
|
|
|
IInternetProtocol *ret;
|
|
|
|
mime_filter *iter;
|
2012-03-13 14:10:38 +01:00
|
|
|
HKEY hlist, hfilter;
|
|
|
|
WCHAR clsidw[64];
|
|
|
|
CLSID clsid;
|
|
|
|
DWORD res, type, size;
|
2009-05-18 18:35:32 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &mime_filter_list, mime_filter, entry) {
|
2019-06-24 10:15:45 +02:00
|
|
|
if(!wcscmp(iter->mime, mime)) {
|
2009-05-18 18:35:32 +02:00
|
|
|
cf = iter->cf;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
2012-03-13 14:10:38 +01:00
|
|
|
if(cf) {
|
|
|
|
hres = IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocol, (void**)&ret);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("CreateInstance failed: %08x\n", hres);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:32:46 +01:00
|
|
|
res = RegOpenKeyW(HKEY_CLASSES_ROOT, L"Protocols\\Filter", &hlist);
|
2012-03-13 14:10:38 +01:00
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
TRACE("Could not open MIME filters key\n");
|
2009-05-18 18:35:32 +02:00
|
|
|
return NULL;
|
2012-03-13 14:10:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
res = RegOpenKeyW(hlist, mime, &hfilter);
|
|
|
|
CloseHandle(hlist);
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = sizeof(clsidw);
|
2020-12-03 00:32:46 +01:00
|
|
|
res = RegQueryValueExW(hfilter, L"CLSID", NULL, &type, (BYTE*)clsidw, &size);
|
2012-03-13 14:10:38 +01:00
|
|
|
CloseHandle(hfilter);
|
|
|
|
if(res!=ERROR_SUCCESS || type!=REG_SZ) {
|
|
|
|
WARN("Could not get filter CLSID for %s\n", debugstr_w(mime));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = CLSIDFromString(clsidw, &clsid);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("CLSIDFromString failed for %s (%x)\n", debugstr_w(mime), hres);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-18 18:35:32 +02:00
|
|
|
|
2012-03-13 14:10:38 +01:00
|
|
|
hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void**)&ret);
|
2009-05-18 18:35:32 +02:00
|
|
|
if(FAILED(hres)) {
|
2012-03-13 14:10:38 +01:00
|
|
|
WARN("CoCreateInstance failed: %08x\n", hres);
|
2009-05-18 18:35:32 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-09-15 20:47:13 +02:00
|
|
|
static HRESULT WINAPI InternetSession_QueryInterface(IInternetSession *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
TRACE("(%s %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetSession, riid)) {
|
|
|
|
*ppv = iface;
|
|
|
|
IInternetSession_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetSession_AddRef(IInternetSession *iface)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
URLMON_LockModule();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetSession_Release(IInternetSession *iface)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetSession_RegisterNameSpace(IInternetSession *iface,
|
|
|
|
IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzProtocol, ULONG cPatterns,
|
|
|
|
const LPCWSTR *ppwzPatterns, DWORD dwReserved)
|
|
|
|
{
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p %s %s %d %p %d)\n", pCF, debugstr_guid(rclsid), debugstr_w(pwzProtocol),
|
2006-05-24 17:59:07 +02:00
|
|
|
cPatterns, ppwzPatterns, dwReserved);
|
|
|
|
|
|
|
|
if(cPatterns || ppwzPatterns)
|
|
|
|
FIXME("patterns not supported\n");
|
|
|
|
if(dwReserved)
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("dwReserved = %d\n", dwReserved);
|
2006-05-24 17:59:07 +02:00
|
|
|
|
|
|
|
if(!pCF || !pwzProtocol)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-02-21 13:07:41 +01:00
|
|
|
return register_namespace(pCF, rclsid, pwzProtocol, FALSE);
|
2005-09-15 20:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetSession_UnregisterNameSpace(IInternetSession *iface,
|
|
|
|
IClassFactory *pCF, LPCWSTR pszProtocol)
|
|
|
|
{
|
2006-05-24 17:59:07 +02:00
|
|
|
TRACE("(%p %s)\n", pCF, debugstr_w(pszProtocol));
|
|
|
|
|
|
|
|
if(!pCF || !pszProtocol)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-02-21 13:08:06 +01:00
|
|
|
return unregister_namespace(pCF, pszProtocol);
|
2005-09-15 20:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetSession_RegisterMimeFilter(IInternetSession *iface,
|
|
|
|
IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzType)
|
|
|
|
{
|
2007-12-28 02:00:10 +01:00
|
|
|
mime_filter *filter;
|
|
|
|
|
|
|
|
TRACE("(%p %s %s)\n", pCF, debugstr_guid(rclsid), debugstr_w(pwzType));
|
|
|
|
|
|
|
|
filter = heap_alloc(sizeof(mime_filter));
|
|
|
|
|
|
|
|
IClassFactory_AddRef(pCF);
|
|
|
|
filter->cf = pCF;
|
|
|
|
filter->clsid = *rclsid;
|
|
|
|
filter->mime = heap_strdupW(pwzType);
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
list_add_head(&mime_filter_list, &filter->entry);
|
2007-12-28 02:00:10 +01:00
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
2007-12-28 02:00:10 +01:00
|
|
|
return S_OK;
|
2005-09-15 20:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetSession_UnregisterMimeFilter(IInternetSession *iface,
|
|
|
|
IClassFactory *pCF, LPCWSTR pwzType)
|
|
|
|
{
|
2012-03-13 14:09:09 +01:00
|
|
|
mime_filter *iter;
|
2007-12-28 02:00:10 +01:00
|
|
|
|
|
|
|
TRACE("(%p %s)\n", pCF, debugstr_w(pwzType));
|
|
|
|
|
2008-02-21 13:08:44 +01:00
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(iter, &mime_filter_list, mime_filter, entry) {
|
2019-06-24 10:15:45 +02:00
|
|
|
if(iter->cf == pCF && !wcscmp(iter->mime, pwzType)) {
|
2012-03-13 14:09:09 +01:00
|
|
|
list_remove(&iter->entry);
|
2007-12-28 02:00:10 +01:00
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
2007-12-28 02:00:10 +01:00
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
IClassFactory_Release(iter->cf);
|
|
|
|
heap_free(iter->mime);
|
|
|
|
heap_free(iter);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-02-21 13:08:44 +01:00
|
|
|
}
|
2007-12-28 02:00:10 +01:00
|
|
|
|
2012-03-13 14:09:09 +01:00
|
|
|
LeaveCriticalSection(&session_cs);
|
2007-12-28 02:00:10 +01:00
|
|
|
return S_OK;
|
2005-09-15 20:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetSession_CreateBinding(IInternetSession *iface,
|
|
|
|
LPBC pBC, LPCWSTR szUrl, IUnknown *pUnkOuter, IUnknown **ppUnk,
|
2005-09-19 16:29:16 +02:00
|
|
|
IInternetProtocol **ppOInetProt, DWORD dwOption)
|
2005-09-15 20:47:13 +02:00
|
|
|
{
|
2011-01-10 18:25:44 +01:00
|
|
|
BindProtocol *protocol;
|
2010-11-15 12:37:03 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2007-01-23 19:33:30 +01:00
|
|
|
TRACE("(%p %s %p %p %p %08x)\n", pBC, debugstr_w(szUrl), pUnkOuter, ppUnk,
|
2005-09-15 20:47:13 +02:00
|
|
|
ppOInetProt, dwOption);
|
2007-01-23 19:33:30 +01:00
|
|
|
|
|
|
|
if(pBC || pUnkOuter || ppUnk || dwOption)
|
|
|
|
FIXME("Unsupported arguments\n");
|
|
|
|
|
2018-05-09 14:58:49 +02:00
|
|
|
hres = create_binding_protocol(&protocol);
|
2010-11-15 12:37:03 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-01-12 00:43:44 +01:00
|
|
|
*ppOInetProt = (IInternetProtocol*)&protocol->IInternetProtocolEx_iface;
|
2010-11-15 12:37:03 +01:00
|
|
|
return S_OK;
|
2005-09-15 20:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetSession_SetSessionOption(IInternetSession *iface,
|
|
|
|
DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength, DWORD dwReserved)
|
|
|
|
{
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%08x %p %d %d)\n", dwOption, pBuffer, dwBufferLength, dwReserved);
|
2005-09-15 20:47:13 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IInternetSessionVtbl InternetSessionVtbl = {
|
|
|
|
InternetSession_QueryInterface,
|
|
|
|
InternetSession_AddRef,
|
|
|
|
InternetSession_Release,
|
|
|
|
InternetSession_RegisterNameSpace,
|
|
|
|
InternetSession_UnregisterNameSpace,
|
|
|
|
InternetSession_RegisterMimeFilter,
|
|
|
|
InternetSession_UnregisterMimeFilter,
|
|
|
|
InternetSession_CreateBinding,
|
|
|
|
InternetSession_SetSessionOption
|
|
|
|
};
|
|
|
|
|
|
|
|
static IInternetSession InternetSession = { &InternetSessionVtbl };
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CoInternetGetSession (URLMON.@)
|
|
|
|
*
|
|
|
|
* Create a new internet session and return an IInternetSession interface
|
|
|
|
* representing it.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dwSessionMode [I] Mode for the internet session
|
|
|
|
* ppIInternetSession [O] Destination for creates IInternetSession object
|
|
|
|
* dwReserved [I] Reserved, must be 0.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppIInternetSession contains the IInternetSession interface.
|
|
|
|
* Failure: E_INVALIDARG, if any argument is invalid, or
|
|
|
|
* E_OUTOFMEMORY if memory allocation fails.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, IInternetSession **ppIInternetSession,
|
|
|
|
DWORD dwReserved)
|
|
|
|
{
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%d %p %d)\n", dwSessionMode, ppIInternetSession, dwReserved);
|
2005-09-15 20:47:13 +02:00
|
|
|
|
|
|
|
if(dwSessionMode)
|
2006-10-05 23:49:11 +02:00
|
|
|
ERR("dwSessionMode=%d\n", dwSessionMode);
|
2005-09-15 20:47:13 +02:00
|
|
|
if(dwReserved)
|
2006-10-05 23:49:11 +02:00
|
|
|
ERR("dwReserved=%d\n", dwReserved);
|
2005-09-15 20:47:13 +02:00
|
|
|
|
2007-01-26 18:49:59 +01:00
|
|
|
IInternetSession_AddRef(&InternetSession);
|
2005-09-15 20:47:13 +02:00
|
|
|
*ppIInternetSession = &InternetSession;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-07-16 21:40:33 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* UrlMkGetSessionOption (URLMON.@)
|
|
|
|
*/
|
|
|
|
static BOOL get_url_encoding(HKEY root, DWORD *encoding)
|
|
|
|
{
|
|
|
|
DWORD size = sizeof(DWORD), res, type;
|
|
|
|
HKEY hkey;
|
|
|
|
|
2020-12-03 00:32:46 +01:00
|
|
|
res = RegOpenKeyW(root, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &hkey);
|
2006-07-16 21:40:33 +02:00
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-12-03 00:32:46 +01:00
|
|
|
res = RegQueryValueExW(hkey, L"UrlEncoding", NULL, &type, (BYTE*)encoding, &size);
|
2006-07-16 21:40:33 +02:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
|
|
|
|
return res == ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-06-27 00:31:39 +02:00
|
|
|
static LPWSTR user_agent;
|
|
|
|
|
|
|
|
static void ensure_useragent(void)
|
|
|
|
{
|
2012-04-06 12:34:12 +02:00
|
|
|
OSVERSIONINFOW info = {sizeof(info)};
|
|
|
|
const WCHAR *os_type, *is_nt;
|
2013-10-01 13:21:00 +02:00
|
|
|
WCHAR buf[512], *ret, *tmp;
|
|
|
|
DWORD res, idx=0;
|
|
|
|
size_t len, size;
|
2012-04-06 12:34:12 +02:00
|
|
|
BOOL is_wow;
|
2013-10-01 13:21:00 +02:00
|
|
|
HKEY key;
|
2012-04-06 12:34:12 +02:00
|
|
|
|
2009-06-27 00:31:39 +02:00
|
|
|
if(user_agent)
|
|
|
|
return;
|
|
|
|
|
2012-04-06 12:34:12 +02:00
|
|
|
GetVersionExW(&info);
|
2020-12-03 00:32:46 +01:00
|
|
|
is_nt = info.dwPlatformId == VER_PLATFORM_WIN32_NT ? L"NT " : L"";
|
2009-06-27 00:31:39 +02:00
|
|
|
|
2012-04-06 12:34:12 +02:00
|
|
|
if(sizeof(void*) == 8)
|
2020-12-03 00:32:46 +01:00
|
|
|
os_type = L"Win64; x64; ";
|
2012-04-06 12:34:12 +02:00
|
|
|
else if(IsWow64Process(GetCurrentProcess(), &is_wow) && is_wow)
|
2020-12-03 00:32:46 +01:00
|
|
|
os_type = L"WOW64; ";
|
2012-04-06 12:34:12 +02:00
|
|
|
else
|
2020-12-03 00:32:46 +01:00
|
|
|
os_type = L"";
|
2009-06-27 00:31:39 +02:00
|
|
|
|
2020-12-03 00:32:46 +01:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), L"Mozilla/4.0 (compatible; MSIE 8.0; Windows %s%d.%d; %sTrident/5.0",
|
|
|
|
is_nt, info.dwMajorVersion, info.dwMinorVersion, os_type);
|
2019-06-24 10:15:45 +02:00
|
|
|
len = lstrlenW(buf);
|
2013-10-01 13:21:00 +02:00
|
|
|
|
|
|
|
size = len+40;
|
|
|
|
ret = heap_alloc(size * sizeof(WCHAR));
|
|
|
|
if(!ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(ret, buf, len*sizeof(WCHAR));
|
|
|
|
|
2020-12-03 00:32:46 +01:00
|
|
|
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
|
|
|
|
"Internet Settings\\5.0\\User Agent\\Post Platform", &key);
|
2013-10-01 13:21:00 +02:00
|
|
|
if(res == ERROR_SUCCESS) {
|
|
|
|
DWORD value_len;
|
|
|
|
|
|
|
|
while(1) {
|
2018-07-05 17:22:32 +02:00
|
|
|
value_len = ARRAY_SIZE(buf);
|
2013-10-01 13:21:00 +02:00
|
|
|
res = RegEnumValueW(key, idx, buf, &value_len, NULL, NULL, NULL, NULL);
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
if(len + value_len + 2 /* strlen("; ") */ + 1 /* trailing ')' */ >= size) {
|
|
|
|
tmp = heap_realloc(ret, (size*2+value_len)*sizeof(WCHAR));
|
|
|
|
if(!tmp)
|
|
|
|
break;
|
|
|
|
ret = tmp;
|
|
|
|
size = size*2+value_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret[len++] = ';';
|
|
|
|
ret[len++] = ' ';
|
|
|
|
memcpy(ret+len, buf, value_len*sizeof(WCHAR));
|
|
|
|
len += value_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret[len++] = ')';
|
|
|
|
ret[len++] = 0;
|
|
|
|
|
|
|
|
user_agent = ret;
|
|
|
|
TRACE("Using user agent %s\n", debugstr_w(user_agent));
|
2009-06-27 00:31:39 +02:00
|
|
|
}
|
|
|
|
|
2009-08-02 00:11:46 +02:00
|
|
|
LPWSTR get_useragent(void)
|
|
|
|
{
|
|
|
|
LPWSTR ret;
|
|
|
|
|
|
|
|
ensure_useragent();
|
|
|
|
|
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
ret = heap_strdupW(user_agent);
|
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-16 21:40:33 +02:00
|
|
|
HRESULT WINAPI UrlMkGetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
|
|
|
|
DWORD* pdwBufferLength, DWORD dwReserved)
|
|
|
|
{
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%x, %p, %d, %p)\n", dwOption, pBuffer, dwBufferLength, pdwBufferLength);
|
2006-07-16 21:40:33 +02:00
|
|
|
|
|
|
|
if(dwReserved)
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("dwReserved = %d\n", dwReserved);
|
2006-07-16 21:40:33 +02:00
|
|
|
|
|
|
|
switch(dwOption) {
|
2009-06-27 00:31:39 +02:00
|
|
|
case URLMON_OPTION_USERAGENT: {
|
|
|
|
HRESULT hres = E_OUTOFMEMORY;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if(!pdwBufferLength)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
|
|
|
ensure_useragent();
|
|
|
|
if(user_agent) {
|
|
|
|
size = WideCharToMultiByte(CP_ACP, 0, user_agent, -1, NULL, 0, NULL, NULL);
|
|
|
|
*pdwBufferLength = size;
|
|
|
|
if(size <= dwBufferLength) {
|
|
|
|
if(pBuffer)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, user_agent, -1, pBuffer, size, NULL, NULL);
|
|
|
|
else
|
|
|
|
hres = E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
|
|
|
|
/* Tests prove that we have to return E_OUTOFMEMORY on success. */
|
|
|
|
return hres;
|
|
|
|
}
|
2006-07-16 21:40:33 +02:00
|
|
|
case URLMON_OPTION_URL_ENCODING: {
|
|
|
|
DWORD encoding = 0;
|
|
|
|
|
|
|
|
if(!pBuffer || dwBufferLength < sizeof(DWORD) || !pdwBufferLength)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(!get_url_encoding(HKEY_CURRENT_USER, &encoding))
|
|
|
|
get_url_encoding(HKEY_LOCAL_MACHINE, &encoding);
|
|
|
|
|
|
|
|
*pdwBufferLength = sizeof(DWORD);
|
|
|
|
*(DWORD*)pBuffer = encoding ? URL_ENCODING_DISABLE_UTF8 : URL_ENCODING_ENABLE_UTF8;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
default:
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("unsupported option %x\n", dwOption);
|
2006-07-16 21:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-06-27 00:31:39 +02:00
|
|
|
|
2009-06-27 00:37:11 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* UrlMkSetSessionOption (URLMON.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI UrlMkSetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
|
|
|
|
DWORD Reserved)
|
|
|
|
{
|
|
|
|
TRACE("(%x %p %x)\n", dwOption, pBuffer, dwBufferLength);
|
|
|
|
|
|
|
|
switch(dwOption) {
|
|
|
|
case URLMON_OPTION_USERAGENT: {
|
|
|
|
LPWSTR new_user_agent;
|
|
|
|
char *buf = pBuffer;
|
|
|
|
DWORD len, size;
|
|
|
|
|
|
|
|
if(!pBuffer || !dwBufferLength)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for(len=0; len<dwBufferLength && buf[len]; len++);
|
|
|
|
|
|
|
|
TRACE("Setting user agent %s\n", debugstr_an(buf, len));
|
|
|
|
|
|
|
|
size = MultiByteToWideChar(CP_ACP, 0, buf, len, NULL, 0);
|
|
|
|
new_user_agent = heap_alloc((size+1)*sizeof(WCHAR));
|
|
|
|
if(!new_user_agent)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buf, len, new_user_agent, size);
|
|
|
|
new_user_agent[size] = 0;
|
|
|
|
|
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
|
|
|
heap_free(user_agent);
|
|
|
|
user_agent = new_user_agent;
|
2014-11-05 12:57:36 +01:00
|
|
|
update_user_agent(user_agent);
|
2009-06-27 00:37:11 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("Unknown option %x\n", dwOption);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-27 00:37:52 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* ObtainUserAgentString (URLMON.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI ObtainUserAgentString(DWORD dwOption, LPSTR pcszUAOut, DWORD *cbSize)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
HRESULT hres = E_FAIL;
|
|
|
|
|
|
|
|
TRACE("(%d %p %p)\n", dwOption, pcszUAOut, cbSize);
|
|
|
|
|
|
|
|
if(!pcszUAOut || !cbSize)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&session_cs);
|
|
|
|
|
|
|
|
ensure_useragent();
|
|
|
|
if(user_agent) {
|
|
|
|
size = WideCharToMultiByte(CP_ACP, 0, user_agent, -1, NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if(size <= *cbSize) {
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, user_agent, -1, pcszUAOut, *cbSize, NULL, NULL);
|
|
|
|
hres = S_OK;
|
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cbSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&session_cs);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2009-06-27 00:31:39 +02:00
|
|
|
void free_session(void)
|
|
|
|
{
|
2012-03-13 14:09:30 +01:00
|
|
|
name_space *ns_iter, *ns_last;
|
|
|
|
mime_filter *mf_iter, *mf_last;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(ns_iter, ns_last, &name_space_list, name_space, entry) {
|
|
|
|
if(!ns_iter->urlmon)
|
|
|
|
IClassFactory_Release(ns_iter->cf);
|
|
|
|
heap_free(ns_iter->protocol);
|
|
|
|
heap_free(ns_iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(mf_iter, mf_last, &mime_filter_list, mime_filter, entry) {
|
|
|
|
IClassFactory_Release(mf_iter->cf);
|
|
|
|
heap_free(mf_iter->mime);
|
|
|
|
heap_free(mf_iter);
|
|
|
|
}
|
|
|
|
|
2009-06-27 00:31:39 +02:00
|
|
|
heap_free(user_agent);
|
|
|
|
}
|