urlmon: Added UrlMkSetSessionOption(URLMON_OPTION_USERAGENT) implementation.

This commit is contained in:
Jacek Caban 2009-06-27 00:31:39 +02:00 committed by Alexandre Julliard
parent 9fed06b057
commit 1880de044c
3 changed files with 72 additions and 7 deletions

View File

@ -52,6 +52,13 @@ static CRITICAL_SECTION_DEBUG session_cs_dbg =
};
static CRITICAL_SECTION session_cs = { &session_cs_dbg, -1, 0, 0, 0, 0 };
static const WCHAR internet_settings_keyW[] =
{'S','O','F','T','W','A','R','E',
'\\','M','i','c','r','o','s','o','f','t',
'\\','W','i','n','d','o','w','s',
'\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
'\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
static name_space *find_name_space(LPCWSTR protocol)
{
name_space *iter;
@ -482,15 +489,9 @@ static BOOL get_url_encoding(HKEY root, DWORD *encoding)
DWORD size = sizeof(DWORD), res, type;
HKEY hkey;
static const WCHAR wszKeyName[] =
{'S','O','F','T','W','A','R','E',
'\\','M','i','c','r','o','s','o','f','t',
'\\','W','i','n','d','o','w','s',
'\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
'\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
static const WCHAR wszUrlEncoding[] = {'U','r','l','E','n','c','o','d','i','n','g',0};
res = RegOpenKeyW(root, wszKeyName, &hkey);
res = RegOpenKeyW(root, internet_settings_keyW, &hkey);
if(res != ERROR_SUCCESS)
return FALSE;
@ -500,6 +501,37 @@ static BOOL get_url_encoding(HKEY root, DWORD *encoding)
return res == ERROR_SUCCESS;
}
static LPWSTR user_agent;
static void ensure_useragent(void)
{
DWORD size = sizeof(DWORD), res, type;
HKEY hkey;
static const WCHAR user_agentW[] = {'U','s','e','r',' ','A','g','e','n','t',0};
if(user_agent)
return;
res = RegOpenKeyW(HKEY_CURRENT_USER, internet_settings_keyW, &hkey);
if(res != ERROR_SUCCESS)
return;
res = RegQueryValueExW(hkey, user_agentW, NULL, &type, NULL, &size);
if(res == ERROR_SUCCESS && type == REG_SZ) {
user_agent = heap_alloc(size);
res = RegQueryValueExW(hkey, user_agentW, NULL, &type, (LPBYTE)user_agent, &size);
if(res != ERROR_SUCCESS) {
heap_free(user_agent);
user_agent = NULL;
}
}else {
WARN("Could not find User Agent value: %u\n", res);
}
RegCloseKey(hkey);
}
HRESULT WINAPI UrlMkGetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
DWORD* pdwBufferLength, DWORD dwReserved)
{
@ -509,6 +541,32 @@ HRESULT WINAPI UrlMkGetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBuf
WARN("dwReserved = %d\n", dwReserved);
switch(dwOption) {
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;
}
case URLMON_OPTION_URL_ENCODING: {
DWORD encoding = 0;
@ -528,3 +586,8 @@ HRESULT WINAPI UrlMkGetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBuf
return E_INVALIDARG;
}
void free_session(void)
{
heap_free(user_agent);
}

View File

@ -139,6 +139,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
FreeLibrary(hCabinet);
hCabinet = NULL;
init_session(FALSE);
free_session();
free_tls_list();
URLMON_hInstance = 0;
break;

View File

@ -63,6 +63,7 @@ HRESULT get_protocol_handler(LPCWSTR,CLSID*,BOOL*,IClassFactory**);
IInternetProtocol *get_mime_filter(LPCWSTR);
BOOL is_registered_protocol(LPCWSTR);
void register_urlmon_namespace(IClassFactory*,REFIID,LPCWSTR,BOOL);
void free_session(void);
HRESULT bind_to_storage(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);
HRESULT bind_to_object(IMoniker *mon, LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv);