d3d9: Reject IDirect3DDevice9::Reset with active default pool resources.
[wine.git] / dlls / urlmon / session.c
blob3571b050384cb6c0d3e9d00110a41bc9d415098e
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "urlmon_main.h"
20 #include "winreg.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
26 typedef struct name_space {
27 LPWSTR protocol;
28 IClassFactory *cf;
29 CLSID clsid;
31 struct name_space *next;
32 } name_space;
34 typedef struct mime_filter {
35 IClassFactory *cf;
36 CLSID clsid;
37 LPWSTR mime;
39 struct mime_filter *next;
40 } mime_filter;
42 static name_space *name_space_list = NULL;
43 static mime_filter *mime_filter_list = NULL;
45 static name_space *find_name_space(LPCWSTR protocol)
47 name_space *iter;
49 for(iter = name_space_list; iter; iter = iter->next) {
50 if(!strcmpW(iter->protocol, protocol))
51 return iter;
54 return NULL;
57 static HRESULT get_protocol_cf(LPCWSTR schema, DWORD schema_len, CLSID *pclsid, IClassFactory **ret)
59 WCHAR str_clsid[64];
60 HKEY hkey = NULL;
61 DWORD res, type, size;
62 CLSID clsid;
63 LPWSTR wszKey;
64 HRESULT hres;
66 static const WCHAR wszProtocolsKey[] =
67 {'P','R','O','T','O','C','O','L','S','\\','H','a','n','d','l','e','r','\\'};
68 static const WCHAR wszCLSID[] = {'C','L','S','I','D',0};
70 wszKey = heap_alloc(sizeof(wszProtocolsKey)+(schema_len+1)*sizeof(WCHAR));
71 memcpy(wszKey, wszProtocolsKey, sizeof(wszProtocolsKey));
72 memcpy(wszKey + sizeof(wszProtocolsKey)/sizeof(WCHAR), schema, (schema_len+1)*sizeof(WCHAR));
74 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszKey, &hkey);
75 heap_free(wszKey);
76 if(res != ERROR_SUCCESS) {
77 TRACE("Could not open protocol handler key\n");
78 return E_FAIL;
81 size = sizeof(str_clsid);
82 res = RegQueryValueExW(hkey, wszCLSID, NULL, &type, (LPBYTE)str_clsid, &size);
83 RegCloseKey(hkey);
84 if(res != ERROR_SUCCESS || type != REG_SZ) {
85 WARN("Could not get protocol CLSID res=%d\n", res);
86 return E_FAIL;
89 hres = CLSIDFromString(str_clsid, &clsid);
90 if(FAILED(hres)) {
91 WARN("CLSIDFromString failed: %08x\n", hres);
92 return hres;
95 if(pclsid)
96 *pclsid = clsid;
98 return CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)ret);
101 IInternetProtocolInfo *get_protocol_info(LPCWSTR url)
103 IInternetProtocolInfo *ret = NULL;
104 IClassFactory *cf;
105 name_space *ns;
106 WCHAR schema[64];
107 DWORD schema_len;
108 HRESULT hres;
110 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(schema[0]),
111 &schema_len, 0);
112 if(FAILED(hres) || !schema_len)
113 return NULL;
115 ns = find_name_space(schema);
116 if(ns) {
117 hres = IClassFactory_QueryInterface(ns->cf, &IID_IInternetProtocolInfo, (void**)&ret);
118 if(SUCCEEDED(hres))
119 return ret;
121 hres = IClassFactory_CreateInstance(ns->cf, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
122 if(SUCCEEDED(hres))
123 return ret;
126 hres = get_protocol_cf(schema, schema_len, NULL, &cf);
127 if(FAILED(hres))
128 return NULL;
130 hres = IClassFactory_QueryInterface(cf, &IID_IInternetProtocolInfo, (void**)&ret);
131 if(FAILED(hres))
132 IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
133 IClassFactory_Release(cf);
135 return ret;
138 HRESULT get_protocol_handler(LPCWSTR url, CLSID *clsid, IClassFactory **ret)
140 name_space *ns;
141 WCHAR schema[64];
142 DWORD schema_len;
143 HRESULT hres;
145 hres = CoInternetParseUrl(url, PARSE_SCHEMA, 0, schema, sizeof(schema)/sizeof(schema[0]),
146 &schema_len, 0);
147 if(FAILED(hres) || !schema_len)
148 return schema_len ? hres : E_FAIL;
150 ns = find_name_space(schema);
151 if(ns) {
152 *ret = ns->cf;
153 IClassFactory_AddRef(*ret);
154 if(clsid)
155 *clsid = ns->clsid;
156 return S_OK;
159 return get_protocol_cf(schema, schema_len, clsid, ret);
162 static HRESULT WINAPI InternetSession_QueryInterface(IInternetSession *iface,
163 REFIID riid, void **ppv)
165 TRACE("(%s %p)\n", debugstr_guid(riid), ppv);
167 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetSession, riid)) {
168 *ppv = iface;
169 IInternetSession_AddRef(iface);
170 return S_OK;
173 *ppv = NULL;
174 return E_NOINTERFACE;
177 static ULONG WINAPI InternetSession_AddRef(IInternetSession *iface)
179 TRACE("()\n");
180 URLMON_LockModule();
181 return 2;
184 static ULONG WINAPI InternetSession_Release(IInternetSession *iface)
186 TRACE("()\n");
187 URLMON_UnlockModule();
188 return 1;
191 static HRESULT WINAPI InternetSession_RegisterNameSpace(IInternetSession *iface,
192 IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzProtocol, ULONG cPatterns,
193 const LPCWSTR *ppwzPatterns, DWORD dwReserved)
195 name_space *new_name_space;
197 TRACE("(%p %s %s %d %p %d)\n", pCF, debugstr_guid(rclsid), debugstr_w(pwzProtocol),
198 cPatterns, ppwzPatterns, dwReserved);
200 if(cPatterns || ppwzPatterns)
201 FIXME("patterns not supported\n");
202 if(dwReserved)
203 WARN("dwReserved = %d\n", dwReserved);
205 if(!pCF || !pwzProtocol)
206 return E_INVALIDARG;
208 new_name_space = heap_alloc(sizeof(name_space));
210 IClassFactory_AddRef(pCF);
211 new_name_space->cf = pCF;
212 new_name_space->clsid = *rclsid;
213 new_name_space->protocol = heap_strdupW(pwzProtocol);
215 new_name_space->next = name_space_list;
216 name_space_list = new_name_space;
217 return S_OK;
220 static HRESULT WINAPI InternetSession_UnregisterNameSpace(IInternetSession *iface,
221 IClassFactory *pCF, LPCWSTR pszProtocol)
223 name_space *iter, *last = NULL;
225 TRACE("(%p %s)\n", pCF, debugstr_w(pszProtocol));
227 if(!pCF || !pszProtocol)
228 return E_INVALIDARG;
230 for(iter = name_space_list; iter; iter = iter->next) {
231 if(iter->cf == pCF && !strcmpW(iter->protocol, pszProtocol))
232 break;
233 last = iter;
236 if(!iter)
237 return S_OK;
239 if(last)
240 last->next = iter->next;
241 else
242 name_space_list = iter->next;
244 IClassFactory_Release(iter->cf);
245 heap_free(iter->protocol);
246 heap_free(iter);
248 return S_OK;
251 static HRESULT WINAPI InternetSession_RegisterMimeFilter(IInternetSession *iface,
252 IClassFactory *pCF, REFCLSID rclsid, LPCWSTR pwzType)
254 mime_filter *filter;
256 TRACE("(%p %s %s)\n", pCF, debugstr_guid(rclsid), debugstr_w(pwzType));
258 filter = heap_alloc(sizeof(mime_filter));
260 IClassFactory_AddRef(pCF);
261 filter->cf = pCF;
262 filter->clsid = *rclsid;
263 filter->mime = heap_strdupW(pwzType);
265 filter->next = mime_filter_list;
266 mime_filter_list = filter;
268 return S_OK;
271 static HRESULT WINAPI InternetSession_UnregisterMimeFilter(IInternetSession *iface,
272 IClassFactory *pCF, LPCWSTR pwzType)
274 mime_filter *iter, *prev = NULL;
276 TRACE("(%p %s)\n", pCF, debugstr_w(pwzType));
278 for(iter = mime_filter_list; iter; iter = iter->next) {
279 if(iter->cf == pCF && !strcmpW(iter->mime, pwzType))
280 break;
281 prev = iter;
284 if(!iter)
285 return S_OK;
287 if(prev)
288 prev->next = iter->next;
289 else
290 mime_filter_list = iter->next;
292 IClassFactory_Release(iter->cf);
293 heap_free(iter->mime);
294 heap_free(iter);
296 return S_OK;
299 static HRESULT WINAPI InternetSession_CreateBinding(IInternetSession *iface,
300 LPBC pBC, LPCWSTR szUrl, IUnknown *pUnkOuter, IUnknown **ppUnk,
301 IInternetProtocol **ppOInetProt, DWORD dwOption)
303 TRACE("(%p %s %p %p %p %08x)\n", pBC, debugstr_w(szUrl), pUnkOuter, ppUnk,
304 ppOInetProt, dwOption);
306 if(pBC || pUnkOuter || ppUnk || dwOption)
307 FIXME("Unsupported arguments\n");
309 return create_binding_protocol(szUrl, FALSE, ppOInetProt);
312 static HRESULT WINAPI InternetSession_SetSessionOption(IInternetSession *iface,
313 DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength, DWORD dwReserved)
315 FIXME("(%08x %p %d %d)\n", dwOption, pBuffer, dwBufferLength, dwReserved);
316 return E_NOTIMPL;
319 static const IInternetSessionVtbl InternetSessionVtbl = {
320 InternetSession_QueryInterface,
321 InternetSession_AddRef,
322 InternetSession_Release,
323 InternetSession_RegisterNameSpace,
324 InternetSession_UnregisterNameSpace,
325 InternetSession_RegisterMimeFilter,
326 InternetSession_UnregisterMimeFilter,
327 InternetSession_CreateBinding,
328 InternetSession_SetSessionOption
331 static IInternetSession InternetSession = { &InternetSessionVtbl };
333 /***********************************************************************
334 * CoInternetGetSession (URLMON.@)
336 * Create a new internet session and return an IInternetSession interface
337 * representing it.
339 * PARAMS
340 * dwSessionMode [I] Mode for the internet session
341 * ppIInternetSession [O] Destination for creates IInternetSession object
342 * dwReserved [I] Reserved, must be 0.
344 * RETURNS
345 * Success: S_OK. ppIInternetSession contains the IInternetSession interface.
346 * Failure: E_INVALIDARG, if any argument is invalid, or
347 * E_OUTOFMEMORY if memory allocation fails.
349 HRESULT WINAPI CoInternetGetSession(DWORD dwSessionMode, IInternetSession **ppIInternetSession,
350 DWORD dwReserved)
352 TRACE("(%d %p %d)\n", dwSessionMode, ppIInternetSession, dwReserved);
354 if(dwSessionMode)
355 ERR("dwSessionMode=%d\n", dwSessionMode);
356 if(dwReserved)
357 ERR("dwReserved=%d\n", dwReserved);
359 IInternetSession_AddRef(&InternetSession);
360 *ppIInternetSession = &InternetSession;
361 return S_OK;
364 /**************************************************************************
365 * UrlMkGetSessionOption (URLMON.@)
367 static BOOL get_url_encoding(HKEY root, DWORD *encoding)
369 DWORD size = sizeof(DWORD), res, type;
370 HKEY hkey;
372 static const WCHAR wszKeyName[] =
373 {'S','O','F','T','W','A','R','E',
374 '\\','M','i','c','r','o','s','o','f','t',
375 '\\','W','i','n','d','o','w','s',
376 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
377 '\\','I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
378 static const WCHAR wszUrlEncoding[] = {'U','r','l','E','n','c','o','d','i','n','g',0};
380 res = RegOpenKeyW(root, wszKeyName, &hkey);
381 if(res != ERROR_SUCCESS)
382 return FALSE;
384 res = RegQueryValueExW(hkey, wszUrlEncoding, NULL, &type, (LPBYTE)encoding, &size);
385 RegCloseKey(hkey);
387 return res == ERROR_SUCCESS;
390 HRESULT WINAPI UrlMkGetSessionOption(DWORD dwOption, LPVOID pBuffer, DWORD dwBufferLength,
391 DWORD* pdwBufferLength, DWORD dwReserved)
393 TRACE("(%x, %p, %d, %p)\n", dwOption, pBuffer, dwBufferLength, pdwBufferLength);
395 if(dwReserved)
396 WARN("dwReserved = %d\n", dwReserved);
398 switch(dwOption) {
399 case URLMON_OPTION_URL_ENCODING: {
400 DWORD encoding = 0;
402 if(!pBuffer || dwBufferLength < sizeof(DWORD) || !pdwBufferLength)
403 return E_INVALIDARG;
405 if(!get_url_encoding(HKEY_CURRENT_USER, &encoding))
406 get_url_encoding(HKEY_LOCAL_MACHINE, &encoding);
408 *pdwBufferLength = sizeof(DWORD);
409 *(DWORD*)pBuffer = encoding ? URL_ENCODING_DISABLE_UTF8 : URL_ENCODING_ENABLE_UTF8;
410 return S_OK;
412 default:
413 FIXME("unsupported option %x\n", dwOption);
416 return E_INVALIDARG;