Added stub implementation for CoGetClassObjectFromURL.
[wine] / dlls / urlmon / sec_mgr.c
1 /*
2  * Internet Security and Zone Manager
3  *
4  * Copyright (c) 2004 Huw D M Davies
5  * Copyright 2004 Jacek Caban
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "wine/debug.h"
31 #include "ole2.h"
32 #include "wine/unicode.h"
33 #include "urlmon.h"
34 #include "urlmon_main.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
37
38 /***********************************************************************
39  *           InternetSecurityManager implementation
40  *
41  */
42 typedef struct SecManagerImpl{
43
44     IInternetSecurityManagerVtbl*  lpvtbl1;  /* VTable relative to the IInternetSecurityManager interface.*/
45
46     ULONG ref; /* reference counter for this object */
47
48 } SecManagerImpl;
49
50 static HRESULT WINAPI SecManagerImpl_QueryInterface(IInternetSecurityManager* iface,REFIID riid,void** ppvObject)
51 {
52     SecManagerImpl *This = (SecManagerImpl *)iface;
53
54     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvObject);
55
56     /* Perform a sanity check on the parameters.*/
57     if ( (This==0) || (ppvObject==0) )
58         return E_INVALIDARG;
59
60     /* Initialize the return parameter */
61     *ppvObject = 0;
62
63     /* Compare the riid with the interface IDs implemented by this object.*/
64     if (IsEqualIID(&IID_IUnknown, riid) ||
65         IsEqualIID(&IID_IInternetSecurityManager, riid))
66         *ppvObject = iface;
67
68     /* Check that we obtained an interface.*/
69     if ((*ppvObject)==0)
70         return E_NOINTERFACE;
71
72     /* Query Interface always increases the reference count by one when it is successful */
73     IInternetSecurityManager_AddRef(iface);
74
75     return S_OK;
76 }
77
78 static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface)
79 {
80     SecManagerImpl *This = (SecManagerImpl *)iface;
81     ULONG refCount = InterlockedIncrement(&This->ref);
82
83     TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
84
85     URLMON_LockModule();
86
87     return refCount;
88 }
89
90 static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface)
91 {
92     SecManagerImpl *This = (SecManagerImpl *)iface;
93     ULONG refCount = InterlockedDecrement(&This->ref);
94
95     TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
96
97     /* destroy the object if there's no more reference on it */
98     if (!refCount){
99         HeapFree(GetProcessHeap(),0,This);
100     }
101
102     URLMON_UnlockModule();
103
104     return refCount;
105 }
106
107 static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface,
108                                                      IInternetSecurityMgrSite *pSite)
109 {
110     FIXME("(%p)->(%p)\n", iface, pSite);
111     return E_NOTIMPL;
112 }
113
114 static HRESULT WINAPI SecManagerImpl_GetSecuritySite(IInternetSecurityManager *iface,
115                                                      IInternetSecurityMgrSite **ppSite)
116 {
117     FIXME("(%p)->( %p)\n", iface, ppSite);
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI SecManagerImpl_MapUrlToZone(IInternetSecurityManager *iface,
122                                                   LPCWSTR pwszUrl, DWORD *pdwZone,
123                                                   DWORD dwFlags)
124 {
125     FIXME("(%p)->(%s %p %08lx)\n", iface, debugstr_w(pwszUrl), pdwZone, dwFlags);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI SecManagerImpl_GetSecurityId(IInternetSecurityManager *iface, 
130                                                    LPCWSTR pwszUrl,
131                                                    BYTE *pbSecurityId, DWORD *pcbSecurityId,
132                                                    DWORD dwReserved)
133 {
134     FIXME("(%p)->(%s %p %p %08lx)\n", iface, debugstr_w(pwszUrl), pbSecurityId, pcbSecurityId,
135           dwReserved);
136     return E_NOTIMPL;
137 }
138
139
140 static HRESULT WINAPI SecManagerImpl_ProcessUrlAction(IInternetSecurityManager *iface,
141                                                       LPCWSTR pwszUrl, DWORD dwAction,
142                                                       BYTE *pPolicy, DWORD cbPolicy,
143                                                       BYTE *pContext, DWORD cbContext,
144                                                       DWORD dwFlags, DWORD dwReserved)
145 {
146     FIXME("(%p)->(%s %08lx %p %08lx %p %08lx %08lx %08lx)\n", iface, debugstr_w(pwszUrl), dwAction,
147           pPolicy, cbPolicy, pContext, cbContext, dwFlags, dwReserved);
148     return E_NOTIMPL;
149 }
150                                                
151
152 static HRESULT WINAPI SecManagerImpl_QueryCustomPolicy(IInternetSecurityManager *iface,
153                                                        LPCWSTR pwszUrl, REFGUID guidKey,
154                                                        BYTE **ppPolicy, DWORD *pcbPolicy,
155                                                        BYTE *pContext, DWORD cbContext,
156                                                        DWORD dwReserved)
157 {
158     FIXME("(%p)->(%s %s %p %p %p %08lx %08lx )\n", iface, debugstr_w(pwszUrl), debugstr_guid(guidKey),
159           ppPolicy, pcbPolicy, pContext, cbContext, dwReserved);
160     return E_NOTIMPL;
161 }
162
163 static HRESULT WINAPI SecManagerImpl_SetZoneMapping(IInternetSecurityManager *iface,
164                                                     DWORD dwZone, LPCWSTR pwszPattern, DWORD dwFlags)
165 {
166     FIXME("(%p)->(%08lx %s %08lx)\n", iface, dwZone, debugstr_w(pwszPattern),dwFlags);
167     return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI SecManagerImpl_GetZoneMappings(IInternetSecurityManager *iface,
171                                                      DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
172 {
173     FIXME("(%p)->(%08lx %p %08lx)\n", iface, dwZone, ppenumString,dwFlags);
174     return E_NOTIMPL;
175 }
176
177 static IInternetSecurityManagerVtbl VT_SecManagerImpl =
178 {
179     SecManagerImpl_QueryInterface,
180     SecManagerImpl_AddRef,
181     SecManagerImpl_Release,
182     SecManagerImpl_SetSecuritySite,
183     SecManagerImpl_GetSecuritySite,
184     SecManagerImpl_MapUrlToZone,
185     SecManagerImpl_GetSecurityId,
186     SecManagerImpl_ProcessUrlAction,
187     SecManagerImpl_QueryCustomPolicy,
188     SecManagerImpl_SetZoneMapping,
189     SecManagerImpl_GetZoneMappings
190 };
191
192 HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
193 {
194     SecManagerImpl *This;
195
196     TRACE("(%p,%p)\n",pUnkOuter,ppobj);
197     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
198
199     /* Initialize the virtual function table. */
200     This->lpvtbl1      = &VT_SecManagerImpl;
201     This->ref          = 1;
202
203     *ppobj = This;
204     return S_OK;
205 }
206
207 /***********************************************************************
208  *           InternetZoneManager implementation
209  *
210  */
211 typedef struct {
212     IInternetZoneManagerVtbl* lpVtbl;
213     ULONG ref;
214 } ZoneMgrImpl;
215
216 /********************************************************************
217  *      IInternetZoneManager_QueryInterface
218  */
219 static HRESULT WINAPI ZoneMgrImpl_QueryInterface(IInternetZoneManager* iface, REFIID riid, void** ppvObject)
220 {
221     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
222
223     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppvObject);
224
225     if(!This || !ppvObject)
226         return E_INVALIDARG;
227
228     if(!IsEqualIID(&IID_IUnknown, riid) && !IsEqualIID(&IID_IInternetZoneManager, riid)) {
229         FIXME("Unknown interface: %s\n", debugstr_guid(riid));
230         *ppvObject = NULL;
231         return E_NOINTERFACE;
232     }
233
234     *ppvObject = iface;
235     IInternetZoneManager_AddRef(iface);
236
237     return S_OK;
238 }
239
240 /********************************************************************
241  *      IInternetZoneManager_AddRef
242  */
243 static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManager* iface)
244 {
245     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
246     ULONG refCount = InterlockedIncrement(&This->ref);
247
248     TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
249
250     URLMON_LockModule();
251
252     return refCount;
253 }
254
255 /********************************************************************
256  *      IInternetZoneManager_Release
257  */
258 static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManager* iface)
259 {
260     ZoneMgrImpl* This = (ZoneMgrImpl*)iface;
261     ULONG refCount = InterlockedDecrement(&This->ref);
262
263     TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
264
265     if(!refCount)
266         HeapFree(GetProcessHeap(), 0, This);
267
268     URLMON_UnlockModule();
269     
270     return refCount;
271 }
272
273 /********************************************************************
274  *      IInternetZoneManager_GetZoneAttributes
275  */
276 static HRESULT WINAPI ZoneMgrImpl_GetZoneAttributes(IInternetZoneManager* iface,
277                                                     DWORD dwZone,
278                                                     ZONEATTRIBUTES* pZoneAttributes)
279 {
280     FIXME("(%p)->(%ld %p) stub\n", iface, dwZone, pZoneAttributes);
281     return E_NOTIMPL;
282 }
283
284 /********************************************************************
285  *      IInternetZoneManager_SetZoneAttributes
286  */
287 static HRESULT WINAPI ZoneMgrImpl_SetZoneAttributes(IInternetZoneManager* iface,
288                                                     DWORD dwZone,
289                                                     ZONEATTRIBUTES* pZoneAttributes)
290 {
291     FIXME("(%p)->(%08lx %p) stub\n", iface, dwZone, pZoneAttributes);
292     return E_NOTIMPL;
293 }
294
295 /********************************************************************
296  *      IInternetZoneManager_GetZoneCustomPolicy
297  */
298 static HRESULT WINAPI ZoneMgrImpl_GetZoneCustomPolicy(IInternetZoneManager* iface,
299                                                       DWORD dwZone,
300                                                       REFGUID guidKey,
301                                                       BYTE** ppPolicy,
302                                                       DWORD* pcbPolicy,
303                                                       URLZONEREG ulrZoneReg)
304 {
305     FIXME("(%p)->(%08lx %s %p %p %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
306                                                     ppPolicy, pcbPolicy, ulrZoneReg);
307     return E_NOTIMPL;
308 }
309
310 /********************************************************************
311  *      IInternetZoneManager_SetZoneCustomPolicy
312  */
313 static HRESULT WINAPI ZoneMgrImpl_SetZoneCustomPolicy(IInternetZoneManager* iface,
314                                                       DWORD dwZone,
315                                                       REFGUID guidKey,
316                                                       BYTE* ppPolicy,
317                                                       DWORD cbPolicy,
318                                                       URLZONEREG ulrZoneReg)
319 {
320     FIXME("(%p)->(%08lx %s %p %08lx %08x) stub\n", iface, dwZone, debugstr_guid(guidKey),
321                                                     ppPolicy, cbPolicy, ulrZoneReg);
322     return E_NOTIMPL;
323 }
324
325 /********************************************************************
326  *      IInternetZoneManager_GetZoneActionPolicy
327  */
328 static HRESULT WINAPI ZoneMgrImpl_GetZoneActionPolicy(IInternetZoneManager* iface,
329                                                       DWORD dwZone,
330                                                       DWORD dwAction,
331                                                       BYTE* pPolicy,
332                                                       DWORD cbPolicy,
333                                                       URLZONEREG urlZoneReg)
334 {
335     FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
336                                                        cbPolicy, urlZoneReg);
337     return E_NOTIMPL;
338 }
339
340 /********************************************************************
341  *      IInternetZoneManager_SetZoneActionPolicy
342  */
343 static HRESULT WINAPI ZoneMgrImpl_SetZoneActionPolicy(IInternetZoneManager* iface,
344                                                       DWORD dwZone,
345                                                       DWORD dwAction,
346                                                       BYTE* pPolicy,
347                                                       DWORD cbPolicy,
348                                                       URLZONEREG urlZoneReg)
349 {
350     FIXME("(%p)->(%08lx %08lx %p %08lx %08x) stub\n", iface, dwZone, dwAction, pPolicy,
351                                                        cbPolicy, urlZoneReg);
352     return E_NOTIMPL;
353 }
354
355 /********************************************************************
356  *      IInternetZoneManager_LogAction
357  */
358 static HRESULT WINAPI ZoneMgrImpl_LogAction(IInternetZoneManager* iface,
359                                             DWORD dwAction,
360                                             LPCWSTR pwszUrl,
361                                             LPCWSTR pwszText,
362                                             DWORD dwLogFlags)
363 {
364     FIXME("(%p)->(%08lx %s %s %08lx) stub\n", iface, dwAction, debugstr_w(pwszUrl),
365                                               debugstr_w(pwszText), dwLogFlags);
366     return E_NOTIMPL;
367 }
368
369 /********************************************************************
370  *      IInternetZoneManager_CreateZoneEnumerator
371  */
372 static HRESULT WINAPI ZoneMgrImpl_CreateZoneEnumerator(IInternetZoneManager* iface,
373                                                        DWORD* pdwEnum,
374                                                        DWORD* pdwCount,
375                                                        DWORD dwFlags)
376 {
377     FIXME("(%p)->(%p %p %08lx) stub\n", iface, pdwEnum, pdwCount, dwFlags);
378     return E_NOTIMPL;
379 }
380
381 /********************************************************************
382  *      IInternetZoneManager_GetZoneAt
383  */
384 static HRESULT WINAPI ZoneMgrImpl_GetZoneAt(IInternetZoneManager* iface,
385                                             DWORD dwEnum,
386                                             DWORD dwIndex,
387                                             DWORD* pdwZone)
388 {
389     FIXME("(%p)->(%08lx %08lx %p) stub\n", iface, dwEnum, dwIndex, pdwZone);
390     return E_NOTIMPL;
391 }
392
393 /********************************************************************
394  *      IInternetZoneManager_DestroyZoneEnumerator
395  */
396 static HRESULT WINAPI ZoneMgrImpl_DestroyZoneEnumerator(IInternetZoneManager* iface,
397                                                         DWORD dwEnum)
398 {
399     FIXME("(%p)->(%08lx) stub\n", iface, dwEnum);
400     return E_NOTIMPL;
401 }
402
403 /********************************************************************
404  *      IInternetZoneManager_CopyTemplatePoliciesToZone
405  */
406 static HRESULT WINAPI ZoneMgrImpl_CopyTemplatePoliciesToZone(IInternetZoneManager* iface,
407                                                              DWORD dwTemplate,
408                                                              DWORD dwZone,
409                                                              DWORD dwReserved)
410 {
411     FIXME("(%p)->(%08lx %08lx %08lx) stub\n", iface, dwTemplate, dwZone, dwReserved);
412     return E_NOTIMPL;
413 }
414
415 /********************************************************************
416  *      IInternetZoneManager_Construct
417  */
418 static IInternetZoneManagerVtbl ZoneMgrImplVtbl = {
419     ZoneMgrImpl_QueryInterface,
420     ZoneMgrImpl_AddRef,
421     ZoneMgrImpl_Release,
422     ZoneMgrImpl_GetZoneAttributes,
423     ZoneMgrImpl_SetZoneAttributes,
424     ZoneMgrImpl_GetZoneCustomPolicy,
425     ZoneMgrImpl_SetZoneCustomPolicy,
426     ZoneMgrImpl_GetZoneActionPolicy,
427     ZoneMgrImpl_SetZoneActionPolicy,
428     ZoneMgrImpl_LogAction,
429     ZoneMgrImpl_CreateZoneEnumerator,
430     ZoneMgrImpl_GetZoneAt,
431     ZoneMgrImpl_DestroyZoneEnumerator,
432     ZoneMgrImpl_CopyTemplatePoliciesToZone,
433 };
434 HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
435 {
436     ZoneMgrImpl* ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ZoneMgrImpl));
437
438     TRACE("(%p %p)\n", pUnkOuter, ppobj);
439     ret->lpVtbl = &ZoneMgrImplVtbl;
440     ret->ref = 1;
441     *ppobj = (IInternetZoneManager*)ret;
442
443     return S_OK;
444 }
445
446 /***********************************************************************
447  *           CoInternetCreateSecurityManager (URLMON.@)
448  *
449  */
450 HRESULT WINAPI CoInternetCreateSecurityManager( IServiceProvider *pSP,
451     IInternetSecurityManager **ppSM, DWORD dwReserved )
452 {
453     TRACE("%p %p %ld\n", pSP, ppSM, dwReserved );
454     return SecManagerImpl_Construct(NULL, (void**) ppSM);
455 }
456
457 /********************************************************************
458  *      CoInternetCreateZoneManager (URLMON.@)
459  */
460 HRESULT WINAPI CoInternetCreateZoneManager(IServiceProvider* pSP, IInternetZoneManager** ppZM, DWORD dwReserved)
461 {
462     TRACE("(%p %p %lx)\n", pSP, ppZM, dwReserved);
463     return ZoneMgrImpl_Construct(NULL, (void**)ppZM);
464 }