ReactOS 0.4.17-dev-573-g8315b8c
session.c File Reference
#include "urlmon_main.h"
#include "winreg.h"
#include "wine/debug.h"
Include dependency graph for session.c:

Go to the source code of this file.

Classes

struct  name_space
 
struct  mime_filter
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (urlmon)
 
static name_spacefind_name_space (LPCWSTR protocol)
 
static HRESULT get_protocol_cf (LPCWSTR schema, DWORD schema_len, CLSID *pclsid, IClassFactory **ret)
 
HRESULT register_namespace (IClassFactory *cf, REFIID clsid, LPCWSTR protocol, BOOL urlmon_protocol)
 
static HRESULT unregister_namespace (IClassFactory *cf, LPCWSTR protocol)
 
BOOL is_registered_protocol (LPCWSTR url)
 
IInternetProtocolInfoget_protocol_info (LPCWSTR url)
 
HRESULT get_protocol_handler (IUri *uri, CLSID *clsid, IClassFactory **ret)
 
IInternetProtocolget_mime_filter (LPCWSTR mime)
 
static HRESULT WINAPI InternetSession_QueryInterface (IInternetSession *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI InternetSession_AddRef (IInternetSession *iface)
 
static ULONG WINAPI InternetSession_Release (IInternetSession *iface)
 
static HRESULT WINAPI InternetSession_RegisterNameSpace (IInternetSession *iface, IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzProtocol, ULONG cPatterns, const LPCWSTR *ppwzPatterns, DWORD dwReserved)
 
static HRESULT WINAPI InternetSession_UnregisterNameSpace (IInternetSession *iface, IClassFactory *pCF, LPCWSTR pszProtocol)
 
static HRESULT WINAPI InternetSession_RegisterMimeFilter (IInternetSession *iface, IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzType)
 
static HRESULT WINAPI InternetSession_UnregisterMimeFilter (IInternetSession *iface, IClassFactory *pCF, LPCWSTR pwzType)
 
static HRESULT WINAPI InternetSession_CreateBinding (IInternetSession *iface, LPBC pBC, LPCWSTR szUrl, IUnknown *pUnkOuter, IUnknown **ppUnk, IInternetProtocol **ppOInetProt, DWORD dwOption)
 
static HRESULT WINAPI InternetSession_SetSessionOption (IInternetSession *iface, DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength, DWORD dwReserved)
 
HRESULT WINAPI CoInternetGetSession (DWORD dwSessionMode, IInternetSession **ppIInternetSession, DWORD dwReserved)
 
static BOOL get_url_encoding (HKEY root, DWORD *encoding)
 
static size_t obtain_user_agent (unsigned int version, WCHAR *ret, size_t size)
 
static void ensure_user_agent (void)
 
LPWSTR get_useragent (void)
 
HRESULT WINAPI UrlMkGetSessionOption (DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength, DWORD *pdwBufferLength, DWORD dwReserved)
 
HRESULT WINAPI UrlMkSetSessionOption (DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength, DWORD Reserved)
 
HRESULT WINAPI ObtainUserAgentString (DWORD option, char *ret, DWORD *ret_size)
 
HRESULT WINAPI MapBrowserEmulationModeToUserAgent (const void *arg, WCHAR **ret)
 
void free_session (void)
 

Variables

static struct list name_space_list = LIST_INIT(name_space_list)
 
static struct list mime_filter_list = LIST_INIT(mime_filter_list)
 
static CRITICAL_SECTION session_cs = { &session_cs_dbg, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG session_cs_dbg
 
static const IInternetSessionVtbl InternetSessionVtbl
 
static IInternetSession InternetSession = { &InternetSessionVtbl }
 
static LPWSTR user_agent
 
static BOOL user_agent_set
 

Function Documentation

◆ CoInternetGetSession()

HRESULT WINAPI CoInternetGetSession ( DWORD  dwSessionMode,
IInternetSession **  ppIInternetSession,
DWORD  dwReserved 
)

Definition at line 473 of file session.c.

475{
476 TRACE("(%ld %p %ld)\n", dwSessionMode, ppIInternetSession, dwReserved);
477
478 if(dwSessionMode)
479 ERR("dwSessionMode=%ld\n", dwSessionMode);
480 if(dwReserved)
481 ERR("dwReserved=%ld\n", dwReserved);
482
483 IInternetSession_AddRef(&InternetSession);
484 *ppIInternetSession = &InternetSession;
485 return S_OK;
486}
#define ERR(fmt,...)
Definition: precomp.h:57
static IInternetSession InternetSession
Definition: session.c:455
#define S_OK
Definition: intsafe.h:52
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:95
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by register_protocol(), and register_protocols().

◆ ensure_user_agent()

static void ensure_user_agent ( void  )
static

Definition at line 605 of file session.c.

606{
608
609 if(!user_agent) {
610 WCHAR buf[1024];
613 }
614
616}
#define ARRAY_SIZE(A)
Definition: main.h:20
static wchar_t * wcsdup(const wchar_t *str)
Definition: string.h:94
static CRITICAL_SECTION session_cs
Definition: session.c:46
static LPWSTR user_agent
Definition: session.c:506
static size_t obtain_user_agent(unsigned int version, WCHAR *ret, size_t size)
Definition: session.c:509
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
short WCHAR
Definition: pedump.c:58
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by get_useragent(), and UrlMkGetSessionOption().

◆ find_name_space()

static name_space * find_name_space ( LPCWSTR  protocol)
static

Definition at line 55 of file session.c.

56{
57 name_space *iter;
58
60 if(!wcsicmp(iter->protocol, protocol))
61 return iter;
62 }
63
64 return NULL;
65}
#define NULL
Definition: types.h:112
#define wcsicmp
Definition: compat.h:15
static struct list name_space_list
Definition: session.c:43
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
LPWSTR protocol
Definition: session.c:27

Referenced by get_protocol_handler(), and get_protocol_info().

◆ free_session()

void free_session ( void  )

Definition at line 795 of file session.c.

796{
797 name_space *ns_iter, *ns_last;
798 mime_filter *mf_iter, *mf_last;
799
801 if(!ns_iter->urlmon)
802 IClassFactory_Release(ns_iter->cf);
803 free(ns_iter->protocol);
804 free(ns_iter);
805 }
806
808 IClassFactory_Release(mf_iter->cf);
809 free(mf_iter->mime);
810 free(mf_iter);
811 }
812
814}
#define free
Definition: debug_ros.c:5
static struct list mime_filter_list
Definition: session.c:44
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
IClassFactory * cf
Definition: session.c:36
LPWSTR mime
Definition: session.c:38
BOOL urlmon
Definition: session.c:30
IClassFactory * cf
Definition: session.c:28

Referenced by process_detach().

◆ get_mime_filter()

IInternetProtocol * get_mime_filter ( LPCWSTR  mime)

Definition at line 242 of file session.c.

243{
246 mime_filter *iter;
247 HKEY hlist, hfilter;
248 WCHAR clsidw[64];
249 CLSID clsid;
250 DWORD res, type, size;
252
254
256 if(!wcscmp(iter->mime, mime)) {
257 cf = iter->cf;
258 break;
259 }
260 }
261
263
264 if(cf) {
265 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocol, (void**)&ret);
266 if(FAILED(hres)) {
267 WARN("CreateInstance failed: %08lx\n", hres);
268 return NULL;
269 }
270
271 return ret;
272 }
273
274 res = RegOpenKeyW(HKEY_CLASSES_ROOT, L"Protocols\\Filter", &hlist);
275 if(res != ERROR_SUCCESS) {
276 TRACE("Could not open MIME filters key\n");
277 return NULL;
278 }
279
280 res = RegOpenKeyW(hlist, mime, &hfilter);
281 CloseHandle(hlist);
282 if(res != ERROR_SUCCESS)
283 return NULL;
284
285 size = sizeof(clsidw);
286 res = RegQueryValueExW(hfilter, L"CLSID", NULL, &type, (BYTE*)clsidw, &size);
287 CloseHandle(hfilter);
288 if(res!=ERROR_SUCCESS || type!=REG_SZ) {
289 WARN("Could not get filter CLSID for %s\n", debugstr_w(mime));
290 return NULL;
291 }
292
293 hres = CLSIDFromString(clsidw, &clsid);
294 if(FAILED(hres)) {
295 WARN("CLSIDFromString failed for %s (%lx)\n", debugstr_w(mime), hres);
296 return NULL;
297 }
298
299 hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void**)&ret);
300 if(FAILED(hres)) {
301 WARN("CoCreateInstance failed: %08lx\n", hres);
302 return NULL;
303 }
304
305 return ret;
306}
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
HRESULT WINAPI CLSIDFromString(LPCOLESTR str, LPCLSID clsid)
Definition: combase.c:1470
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
#define CloseHandle
Definition: compat.h:739
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLsizeiptr size
Definition: glext.h:5919
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
const WCHAR * mime
Definition: mimefilter.c:487
HRESULT hres
Definition: protocol.c:465
const CLSID * clsid
Definition: msctf.cpp:50
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
unsigned char BYTE
Definition: xxhash.c:193

Referenced by mime_available().

◆ get_protocol_cf()

static HRESULT get_protocol_cf ( LPCWSTR  schema,
DWORD  schema_len,
CLSID pclsid,
IClassFactory **  ret 
)
static

Definition at line 67 of file session.c.

68{
69 WCHAR str_clsid[64];
70 HKEY hkey = NULL;
73 LPWSTR wszKey;
75
76 static const WCHAR wszProtocolsKey[] =
77 {'P','R','O','T','O','C','O','L','S','\\','H','a','n','d','l','e','r','\\'};
78
79 wszKey = malloc(sizeof(wszProtocolsKey) + (schema_len + 1) * sizeof(WCHAR));
80 memcpy(wszKey, wszProtocolsKey, sizeof(wszProtocolsKey));
81 memcpy(wszKey + ARRAY_SIZE(wszProtocolsKey), schema, (schema_len+1)*sizeof(WCHAR));
82
83 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszKey, &hkey);
84 free(wszKey);
85 if(res != ERROR_SUCCESS) {
86 TRACE("Could not open protocol handler key\n");
87 return MK_E_SYNTAX;
88 }
89
90 size = sizeof(str_clsid);
91 res = RegQueryValueExW(hkey, L"CLSID", NULL, &type, (BYTE*)str_clsid, &size);
92 RegCloseKey(hkey);
93 if(res != ERROR_SUCCESS || type != REG_SZ) {
94 WARN("Could not get protocol CLSID res=%ld\n", res);
95 return MK_E_SYNTAX;
96 }
97
98 hres = CLSIDFromString(str_clsid, &clsid);
99 if(FAILED(hres)) {
100 WARN("CLSIDFromString failed: %08lx\n", hres);
101 return hres;
102 }
103
104 if(pclsid)
105 *pclsid = clsid;
106
107 if(!ret)
108 return S_OK;
109
110 hres = CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)ret);
111 return SUCCEEDED(hres) ? S_OK : MK_E_SYNTAX;
112}
const GUID IID_IClassFactory
#define RegCloseKey(hKey)
Definition: registry.h:49
#define malloc
Definition: debug_ros.c:4
HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscontext, COSERVERINFO *server_info, REFIID riid, void **obj)
Definition: combase.c:1925
#define SUCCEEDED(hr)
Definition: intsafe.h:50
const WCHAR * schema
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint16_t * LPWSTR
Definition: typedefs.h:56
#define MK_E_SYNTAX
Definition: winerror.h:3896

Referenced by get_protocol_handler(), get_protocol_info(), and is_registered_protocol().

◆ get_protocol_handler()

HRESULT get_protocol_handler ( IUri uri,
CLSID clsid,
IClassFactory **  ret 
)

Definition at line 212 of file session.c.

213{
214 name_space *ns;
215 BSTR scheme;
217
218 *ret = NULL;
219
220 /* FIXME: Avoid GetSchemeName call for known schemes */
221 hres = IUri_GetSchemeName(uri, &scheme);
222 if(FAILED(hres))
223 return hres;
224
226
228 if(ns) {
229 *ret = ns->cf;
230 IClassFactory_AddRef(*ret);
231 if(clsid)
232 *clsid = ns->clsid;
233 }
234
236
239 return hres;
240}
OLECHAR * BSTR
Definition: compat.h:2293
static name_space * find_name_space(LPCWSTR protocol)
Definition: session.c:55
static HRESULT get_protocol_cf(LPCWSTR schema, DWORD schema_len, CLSID *pclsid, IClassFactory **ret)
Definition: session.c:67
const WCHAR * uri
Definition: sec_mgr.c:1564
UINT WINAPI SysStringLen(BSTR str)
Definition: oleaut.c:198
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:273
DWORD scheme
Definition: mxnamespace.c:38

Referenced by BindProtocol_StartEx().

◆ get_protocol_info()

IInternetProtocolInfo * get_protocol_info ( LPCWSTR  url)

Definition at line 173 of file session.c.

174{
177 name_space *ns;
178 WCHAR schema[64];
179 DWORD schema_len;
181
182 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, ARRAY_SIZE(schema), &schema_len, 0);
183 if(FAILED(hres) || !schema_len)
184 return NULL;
185
187
189 if(ns && !ns->urlmon) {
190 hres = IClassFactory_QueryInterface(ns->cf, &IID_IInternetProtocolInfo, (void**)&ret);
191 if(FAILED(hres))
192 hres = IClassFactory_CreateInstance(ns->cf, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
193 }
194
196
197 if(ns && SUCCEEDED(hres))
198 return ret;
199
200 hres = get_protocol_cf(schema, schema_len, NULL, &cf);
201 if(FAILED(hres))
202 return NULL;
203
204 hres = IClassFactory_QueryInterface(cf, &IID_IInternetProtocolInfo, (void**)&ret);
205 if(FAILED(hres))
206 IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
207 IClassFactory_Release(cf);
208
209 return ret;
210}
HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags, LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
Definition: internet.c:325
static const WCHAR url[]
Definition: encode.c:1384

Referenced by CoInternetCombineIUri(), CoInternetCombineUrl(), CoInternetCombineUrlEx(), CoInternetCompareUrl(), CoInternetParseIUri(), CoInternetQueryInfo(), parse_canonicalize_url(), parse_domain(), parse_encode(), parse_path_from_url(), parse_rootdocument(), parse_security_domain(), and parse_security_url().

◆ get_url_encoding()

static BOOL get_url_encoding ( HKEY  root,
DWORD encoding 
)
static

Definition at line 491 of file session.c.

492{
493 DWORD size = sizeof(DWORD), res, type;
494 HKEY hkey;
495
496 res = RegOpenKeyW(root, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &hkey);
497 if(res != ERROR_SUCCESS)
498 return FALSE;
499
500 res = RegQueryValueExW(hkey, L"UrlEncoding", NULL, &type, (BYTE*)encoding, &size);
501 RegCloseKey(hkey);
502
503 return res == ERROR_SUCCESS;
504}
#define FALSE
Definition: types.h:117
#define DWORD
Definition: nt_native.h:44

Referenced by UrlMkGetSessionOption().

◆ get_useragent()

LPWSTR get_useragent ( void  )

Definition at line 618 of file session.c.

619{
620 LPWSTR ret;
621
623
627
628 return ret;
629}
static void ensure_user_agent(void)
Definition: session.c:605

Referenced by create_internet_session().

◆ InternetSession_AddRef()

static ULONG WINAPI InternetSession_AddRef ( IInternetSession iface)
static

Definition at line 323 of file session.c.

324{
325 TRACE("()\n");
327 return 2;
328}
static void URLMON_LockModule(void)
Definition: urlmon_main.h:64

◆ InternetSession_CreateBinding()

static HRESULT WINAPI InternetSession_CreateBinding ( IInternetSession iface,
LPBC  pBC,
LPCWSTR  szUrl,
IUnknown pUnkOuter,
IUnknown **  ppUnk,
IInternetProtocol **  ppOInetProt,
DWORD  dwOption 
)
static

Definition at line 415 of file session.c.

418{
421
422 TRACE("(%p %s %p %p %p %08lx)\n", pBC, debugstr_w(szUrl), pUnkOuter, ppUnk,
423 ppOInetProt, dwOption);
424
425 if(pBC || pUnkOuter || ppUnk || dwOption)
426 FIXME("Unsupported arguments\n");
427
429 if(FAILED(hres))
430 return hres;
431
432 *ppOInetProt = (IInternetProtocol*)&protocol->IInternetProtocolEx_iface;
433 return S_OK;
434}
#define FIXME(fmt,...)
Definition: precomp.h:53
HRESULT create_binding_protocol(BindProtocol **protocol)
Definition: bindprot.c:1453

◆ InternetSession_QueryInterface()

static HRESULT WINAPI InternetSession_QueryInterface ( IInternetSession iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 308 of file session.c.

310{
311 TRACE("(%s %p)\n", debugstr_guid(riid), ppv);
312
313 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetSession, riid)) {
314 *ppv = iface;
315 IInternetSession_AddRef(iface);
316 return S_OK;
317 }
318
319 *ppv = NULL;
320 return E_NOINTERFACE;
321}
const GUID IID_IUnknown
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define E_NOINTERFACE
Definition: winerror.h:3479

◆ InternetSession_RegisterMimeFilter()

static HRESULT WINAPI InternetSession_RegisterMimeFilter ( IInternetSession iface,
IClassFactory pCF,
REFCLSID  rclsid,
LPCWSTR  pwzType 
)
static

Definition at line 366 of file session.c.

368{
370
371 TRACE("(%p %s %s)\n", pCF, debugstr_guid(rclsid), debugstr_w(pwzType));
372
373 filter = malloc(sizeof(mime_filter));
374
375 IClassFactory_AddRef(pCF);
376 filter->cf = pCF;
377 filter->clsid = *rclsid;
378 filter->mime = wcsdup(pwzType);
379
381
383
385
386 return S_OK;
387}
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005

◆ InternetSession_RegisterNameSpace()

static HRESULT WINAPI InternetSession_RegisterNameSpace ( IInternetSession iface,
IClassFactory pCF,
REFCLSID  rclsid,
LPCWSTR  pwzProtocol,
ULONG  cPatterns,
const LPCWSTR ppwzPatterns,
DWORD  dwReserved 
)
static

Definition at line 337 of file session.c.

340{
341 TRACE("(%p %s %s %ld %p %ld)\n", pCF, debugstr_guid(rclsid), debugstr_w(pwzProtocol),
342 cPatterns, ppwzPatterns, dwReserved);
343
344 if(cPatterns || ppwzPatterns)
345 FIXME("patterns not supported\n");
346 if(dwReserved)
347 WARN("dwReserved = %ld\n", dwReserved);
348
349 if(!pCF || !pwzProtocol)
350 return E_INVALIDARG;
351
352 return register_namespace(pCF, rclsid, pwzProtocol, FALSE);
353}
#define E_INVALIDARG
Definition: ddrawi.h:101
HRESULT register_namespace(IClassFactory *cf, REFIID clsid, LPCWSTR protocol, BOOL urlmon_protocol)
Definition: session.c:114

◆ InternetSession_Release()

static ULONG WINAPI InternetSession_Release ( IInternetSession iface)
static

Definition at line 330 of file session.c.

331{
332 TRACE("()\n");
334 return 1;
335}
static void URLMON_UnlockModule(void)
Definition: urlmon_main.h:65

◆ InternetSession_SetSessionOption()

static HRESULT WINAPI InternetSession_SetSessionOption ( IInternetSession iface,
DWORD  dwOption,
LPVOID  pBuffer,
DWORD  dwBufferLength,
DWORD  dwReserved 
)
static

Definition at line 436 of file session.c.

438{
439 FIXME("(%08lx %p %ld %ld)\n", dwOption, pBuffer, dwBufferLength, dwReserved);
440 return E_NOTIMPL;
441}
#define E_NOTIMPL
Definition: ddrawi.h:99
PVOID pBuffer

◆ InternetSession_UnregisterMimeFilter()

static HRESULT WINAPI InternetSession_UnregisterMimeFilter ( IInternetSession iface,
IClassFactory pCF,
LPCWSTR  pwzType 
)
static

Definition at line 389 of file session.c.

391{
392 mime_filter *iter;
393
394 TRACE("(%p %s)\n", pCF, debugstr_w(pwzType));
395
397
399 if(iter->cf == pCF && !wcscmp(iter->mime, pwzType)) {
400 list_remove(&iter->entry);
401
403
404 IClassFactory_Release(iter->cf);
405 free(iter->mime);
406 free(iter);
407 return S_OK;
408 }
409 }
410
412 return S_OK;
413}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
struct list entry
Definition: session.c:40

◆ InternetSession_UnregisterNameSpace()

static HRESULT WINAPI InternetSession_UnregisterNameSpace ( IInternetSession iface,
IClassFactory pCF,
LPCWSTR  pszProtocol 
)
static

Definition at line 355 of file session.c.

357{
358 TRACE("(%p %s)\n", pCF, debugstr_w(pszProtocol));
359
360 if(!pCF || !pszProtocol)
361 return E_INVALIDARG;
362
363 return unregister_namespace(pCF, pszProtocol);
364}
static HRESULT unregister_namespace(IClassFactory *cf, LPCWSTR protocol)
Definition: session.c:136

◆ is_registered_protocol()

BOOL is_registered_protocol ( LPCWSTR  url)

Definition at line 160 of file session.c.

161{
162 DWORD schema_len;
163 WCHAR schema[64];
165
166 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, ARRAY_SIZE(schema), &schema_len, 0);
167 if(FAILED(hres))
168 return FALSE;
169
170 return get_protocol_cf(schema, schema_len, NULL, NULL) == S_OK;
171}

Referenced by MkParseDisplayNameEx().

◆ MapBrowserEmulationModeToUserAgent()

HRESULT WINAPI MapBrowserEmulationModeToUserAgent ( const void arg,
WCHAR **  ret 
)

Definition at line 761 of file session.c.

762{
764 const WCHAR *ua;
765 WCHAR buf[1024];
766
767 TRACE("%p %p: semi-stub\n", arg, ret);
768
769 if(user_agent_set) {
770 /* Native ignores first arg if custom user agent has been set, doesn't crash even if NULL */
771 size = (wcslen(user_agent) + 1) * sizeof(WCHAR);
772 ua = user_agent;
773 }else {
774 *ret = NULL;
775
776 /* First arg seems to be a pointer to a structure of unknown size, and crashes
777 if it's too small (or filled with arbitrary values from the stack). For our
778 purposes, we only check first field which seems to be the requested version. */
779 version = *(DWORD*)arg;
780 if(version == 5)
781 version = 7;
782 if(version < 7 || version > 11)
783 return E_FAIL;
784
786 ua = buf;
787 }
788
789 if(!(*ret = CoTaskMemAlloc(size)))
790 return E_OUTOFMEMORY;
791 memcpy(*ret, ua, size);
792 return S_OK;
793}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
void *WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: malloc.c:381
static const WCHAR version[]
Definition: asmname.c:66
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
static BOOL user_agent_set
Definition: session.c:507

◆ obtain_user_agent()

static size_t obtain_user_agent ( unsigned int  version,
WCHAR ret,
size_t  size 
)
static

Definition at line 509 of file session.c.

510{
511 BOOL is_wow, quirks = FALSE, use_current = FALSE;
512 OSVERSIONINFOW info = {sizeof(info)};
513 const WCHAR *os_type, *is_nt;
514 DWORD res;
515 size_t len = 0;
516 HKEY key;
517
518 if(version & UAS_EXACTLEGACY) {
519 version &= ~UAS_EXACTLEGACY;
520 if(version == 7)
521 quirks = TRUE;
522 else {
523 use_current = TRUE;
524 version = 7;
525 }
526 }
527
528 if(version > 11) {
529 FIXME("Unsupported version %u\n", version);
530 version = 11;
531 }
532
533 if(version < 7 || use_current) {
535 if(user_agent) {
536 len = wcslen(user_agent) + 1;
537 memcpy(ret, user_agent, min(size, len) * sizeof(WCHAR));
538 }
540 if(len) return len;
541 }
542
543 if(version < 7)
544 version = 7;
545
546 swprintf(ret, size, L"Mozilla/%s (", version < 9 ? L"4.0" : L"5.0");
547 len = lstrlenW(ret);
548 if(version < 11) {
549 swprintf(ret + len, size - len, L"compatible; MSIE %u.0; ", version);
550 len += wcslen(ret + len);
551 }
552
554 is_nt = info.dwPlatformId == VER_PLATFORM_WIN32_NT ? L"NT " : L"";
555
556 if(sizeof(void*) == 8)
557#ifdef __x86_64__
558 os_type = L"; Win64; x64";
559#else
560 os_type = L"; Win64";
561#endif
562 else if(IsWow64Process(GetCurrentProcess(), &is_wow) && is_wow)
563 os_type = L"; WOW64";
564 else
565 os_type = L"";
566
567 swprintf(ret + len, size - len, L"Windows %s%d.%d%s", is_nt, info.dwMajorVersion,
568 info.dwMinorVersion, os_type);
569 len = lstrlenW(ret);
570
571 if(!quirks) {
572 wcscpy(ret + len, L"; Trident/7.0");
573 len += ARRAY_SIZE(L"; Trident/7.0") - 1;
574 }
575
576 if(version < 9) {
577 res = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
578 "Internet Settings\\5.0\\User Agent\\Post Platform", &key);
579 if(res == ERROR_SUCCESS) {
580 DWORD value_len, idx;
581
582 for(idx = 0;; idx++) {
583 ret[len++] = ';';
584 ret[len++] = ' ';
585
586 value_len = size - len - 2;
587 res = RegEnumValueW(key, idx, ret + len, &value_len, NULL, NULL, NULL, NULL);
588 if(res != ERROR_SUCCESS)
589 break;
590
591 len += value_len;
592 }
593
595 if(idx) len -= 2;
596 }
597 }
598 wcscpy(ret + len, version >= 11 ? L"; rv:11.0) like Gecko" : L")");
599 len += wcslen(ret + len) + 1;
600
601 TRACE("Using user agent %s\n", debugstr_w(ret));
602 return len;
603}
#define TRUE
Definition: types.h:120
unsigned int idx
Definition: utils.c:41
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
#define GetCurrentProcess()
Definition: compat.h:759
#define IsWow64Process
Definition: compat.h:760
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLsizei len
Definition: glext.h:6722
#define min(a, b)
Definition: monoChain.cc:55
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:238
wcscpy
Definition: copy.c:22
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by ensure_user_agent(), MapBrowserEmulationModeToUserAgent(), and ObtainUserAgentString().

◆ ObtainUserAgentString()

HRESULT WINAPI ObtainUserAgentString ( DWORD  option,
char ret,
DWORD ret_size 
)

Definition at line 735 of file session.c.

736{
737 DWORD size, len;
738 WCHAR buf[1024];
739 HRESULT hres = S_OK;
740
741 TRACE("(%ld %p %p)\n", option, ret, ret_size);
742
743 if(!ret || !ret_size)
744 return E_INVALIDARG;
745
748 if(size <= *ret_size)
750 else
752
753 *ret_size = size;
754 return hres;
755}
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
static void ULONG ULONG * ret_size
Definition: time.c:40
Definition: getopt.h:109

Referenced by OmNavigator_get_appVersion(), OmNavigator_get_userAgent(), and test_navigator().

◆ register_namespace()

HRESULT register_namespace ( IClassFactory cf,
REFIID  clsid,
LPCWSTR  protocol,
BOOL  urlmon_protocol 
)

Definition at line 114 of file session.c.

115{
116 name_space *new_name_space;
117
118 new_name_space = malloc(sizeof(name_space));
119
120 if(!urlmon_protocol)
121 IClassFactory_AddRef(cf);
122 new_name_space->cf = cf;
123 new_name_space->clsid = *clsid;
124 new_name_space->urlmon = urlmon_protocol;
125 new_name_space->protocol = wcsdup(protocol);
126
128
129 list_add_head(&name_space_list, &new_name_space->entry);
130
132
133 return S_OK;
134}
CLSID clsid
Definition: session.c:29
struct list entry
Definition: session.c:32

Referenced by init_session(), and InternetSession_RegisterNameSpace().

◆ unregister_namespace()

static HRESULT unregister_namespace ( IClassFactory cf,
LPCWSTR  protocol 
)
static

Definition at line 136 of file session.c.

137{
138 name_space *iter;
139
141
143 if(iter->cf == cf && !wcsicmp(iter->protocol, protocol)) {
144 list_remove(&iter->entry);
145
147
148 if(!iter->urlmon)
149 IClassFactory_Release(iter->cf);
150 free(iter->protocol);
151 free(iter);
152 return S_OK;
153 }
154 }
155
157 return S_OK;
158}

Referenced by InternetSession_UnregisterNameSpace().

◆ UrlMkGetSessionOption()

HRESULT WINAPI UrlMkGetSessionOption ( DWORD  dwOption,
LPVOID  pBuffer,
DWORD  dwBufferLength,
DWORD pdwBufferLength,
DWORD  dwReserved 
)

Definition at line 631 of file session.c.

633{
634 TRACE("(%lx, %p, %ld, %p)\n", dwOption, pBuffer, dwBufferLength, pdwBufferLength);
635
636 if(dwReserved)
637 WARN("dwReserved = %ld\n", dwReserved);
638
639 switch(dwOption) {
640 case URLMON_OPTION_USERAGENT: {
642 DWORD size;
643
644 if(!pdwBufferLength)
645 return E_INVALIDARG;
646
648
650 if(user_agent) {
652 *pdwBufferLength = size;
653 if(size <= dwBufferLength) {
654 if(pBuffer)
656 else
658 }
659 }
660
662
663 /* Tests prove that we have to return E_OUTOFMEMORY on success. */
664 return hres;
665 }
666 case URLMON_OPTION_URL_ENCODING: {
667 DWORD encoding = 0;
668
669 if(!pBuffer || dwBufferLength < sizeof(DWORD) || !pdwBufferLength)
670 return E_INVALIDARG;
671
672 if(!get_url_encoding(HKEY_CURRENT_USER, &encoding))
674
675 *pdwBufferLength = sizeof(DWORD);
676 *(DWORD*)pBuffer = encoding ? URL_ENCODING_DISABLE_UTF8 : URL_ENCODING_ENABLE_UTF8;
677 return S_OK;
678 }
679 default:
680 FIXME("unsupported option %lx\n", dwOption);
681 }
682
683 return E_INVALIDARG;
684}
static BOOL get_url_encoding(HKEY root, DWORD *encoding)
Definition: session.c:491
#define HKEY_CURRENT_USER
Definition: winreg.h:11

◆ UrlMkSetSessionOption()

HRESULT WINAPI UrlMkSetSessionOption ( DWORD  dwOption,
LPVOID  pBuffer,
DWORD  dwBufferLength,
DWORD  Reserved 
)

Definition at line 689 of file session.c.

691{
692 TRACE("(%lx %p %lx)\n", dwOption, pBuffer, dwBufferLength);
693
694 switch(dwOption) {
695 case URLMON_OPTION_USERAGENT: {
696 LPWSTR new_user_agent;
697 char *buf = pBuffer;
698 DWORD len, size;
699
700 if(!pBuffer || !dwBufferLength)
701 return E_INVALIDARG;
702
703 for(len=0; len<dwBufferLength && buf[len]; len++);
704
705 TRACE("Setting user agent %s\n", debugstr_an(buf, len));
706
708 new_user_agent = malloc((size + 1) * sizeof(WCHAR));
709 if(!new_user_agent)
710 return E_OUTOFMEMORY;
711 MultiByteToWideChar(CP_ACP, 0, buf, len, new_user_agent, size);
712 new_user_agent[size] = 0;
713
715
717 user_agent = new_user_agent;
720
722 break;
723 }
724 default:
725 FIXME("Unknown option %lx\n", dwOption);
726 return E_INVALIDARG;
727 }
728
729 return S_OK;
730}
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define MultiByteToWideChar
Definition: compat.h:110
void update_user_agent(WCHAR *user_agent)
Definition: protocol.c:307

Referenced by test_MapBrowserEmulationModeToUserAgent(), and test_user_agent().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( urlmon  )

Variable Documentation

◆ InternetSession

IInternetSession InternetSession = { &InternetSessionVtbl }
static

Definition at line 455 of file session.c.

Referenced by CoInternetGetSession().

◆ InternetSessionVtbl

const IInternetSessionVtbl InternetSessionVtbl
static
Initial value:
= {
}
static HRESULT WINAPI InternetSession_CreateBinding(IInternetSession *iface, LPBC pBC, LPCWSTR szUrl, IUnknown *pUnkOuter, IUnknown **ppUnk, IInternetProtocol **ppOInetProt, DWORD dwOption)
Definition: session.c:415
static HRESULT WINAPI InternetSession_QueryInterface(IInternetSession *iface, REFIID riid, void **ppv)
Definition: session.c:308
static ULONG WINAPI InternetSession_AddRef(IInternetSession *iface)
Definition: session.c:323
static HRESULT WINAPI InternetSession_UnregisterMimeFilter(IInternetSession *iface, IClassFactory *pCF, LPCWSTR pwzType)
Definition: session.c:389
static HRESULT WINAPI InternetSession_RegisterMimeFilter(IInternetSession *iface, IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzType)
Definition: session.c:366
static HRESULT WINAPI InternetSession_SetSessionOption(IInternetSession *iface, DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength, DWORD dwReserved)
Definition: session.c:436
static ULONG WINAPI InternetSession_Release(IInternetSession *iface)
Definition: session.c:330
static HRESULT WINAPI InternetSession_UnregisterNameSpace(IInternetSession *iface, IClassFactory *pCF, LPCWSTR pszProtocol)
Definition: session.c:355
static HRESULT WINAPI InternetSession_RegisterNameSpace(IInternetSession *iface, IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzProtocol, ULONG cPatterns, const LPCWSTR *ppwzPatterns, DWORD dwReserved)
Definition: session.c:337

Definition at line 443 of file session.c.

◆ mime_filter_list

struct list mime_filter_list = LIST_INIT(mime_filter_list)
static

◆ name_space_list

struct list name_space_list = LIST_INIT(name_space_list)
static

Definition at line 43 of file session.c.

Referenced by find_name_space(), free_session(), register_namespace(), and unregister_namespace().

◆ session_cs

◆ session_cs_dbg

CRITICAL_SECTION_DEBUG session_cs_dbg
static
Initial value:
=
{
0, 0, &session_cs,
0, 0, { (DWORD_PTR)(__FILE__ ": session") }
}
static CRITICAL_SECTION_DEBUG session_cs_dbg
Definition: session.c:47
#define DWORD_PTR
Definition: treelist.c:76

Definition at line 47 of file session.c.

◆ user_agent

◆ user_agent_set

BOOL user_agent_set
static

Definition at line 507 of file session.c.

Referenced by MapBrowserEmulationModeToUserAgent(), and UrlMkSetSessionOption().