Stub implementation of IInternetSecurityManager.
[wine] / dlls / urlmon / urlmon_main.c
1 /*
2  * UrlMon
3  *
4  * Copyright (c) 2000 Patrik Stridvall
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "wtypes.h"
27 #define NO_SHLWAPI_REG
28 #include "shlwapi.h"
29
30 #include "wine/debug.h"
31
32 #include "winuser.h"
33 #include "urlmon.h"
34 #include "urlmon_main.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
37
38 HINSTANCE URLMON_hInstance = 0;
39
40 /***********************************************************************
41  *              DllMain (URLMON.init)
42  */
43 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
44 {
45     TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
46
47     switch(fdwReason) {
48     case DLL_PROCESS_ATTACH:
49         DisableThreadLibraryCalls(hinstDLL);
50         URLMON_hInstance = hinstDLL;
51         break;
52
53     case DLL_PROCESS_DETACH:
54         URLMON_hInstance = 0;
55         break;
56     }
57     return TRUE;
58 }
59
60
61 /***********************************************************************
62  *              DllInstall (URLMON.@)
63  */
64 HRESULT WINAPI URLMON_DllInstall(BOOL bInstall, LPCWSTR cmdline)
65 {
66   FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
67         debugstr_w(cmdline));
68
69   return S_OK;
70 }
71
72 /***********************************************************************
73  *              DllCanUnloadNow (URLMON.@)
74  */
75 HRESULT WINAPI URLMON_DllCanUnloadNow(void)
76 {
77     FIXME("(void): stub\n");
78
79     return S_FALSE;
80 }
81
82
83
84 /******************************************************************************
85  * Urlmon ClassFactory
86  */
87 typedef struct {
88     IClassFactory ITF_IClassFactory;
89
90     DWORD ref;
91     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
92 } IClassFactoryImpl;
93
94 struct object_creation_info
95 {
96     const CLSID *clsid;
97     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
98 };
99  
100 static const struct object_creation_info object_creation[] =
101 {
102     { &CLSID_InternetSecurityManager, &SecManagerImpl_Construct }
103 };
104
105 static HRESULT WINAPI
106 CF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
107 {
108     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
109
110     if (IsEqualGUID(riid, &IID_IUnknown)
111         || IsEqualGUID(riid, &IID_IClassFactory))
112     {
113         IClassFactory_AddRef(iface);
114         *ppobj = This;
115         return S_OK;
116     }
117
118     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
119     return E_NOINTERFACE;
120 }
121
122 static ULONG WINAPI CF_AddRef(LPCLASSFACTORY iface)
123 {
124     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
125     return InterlockedIncrement(&This->ref);
126 }
127
128 static ULONG WINAPI CF_Release(LPCLASSFACTORY iface)
129 {
130     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
131
132     ULONG ref = InterlockedDecrement(&This->ref);
133
134     if (ref == 0)
135         HeapFree(GetProcessHeap(), 0, This);
136
137     return ref;
138 }
139
140
141 static HRESULT WINAPI CF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
142                                         REFIID riid, LPVOID *ppobj)
143 {
144     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
145     HRESULT hres;
146     LPUNKNOWN punk;
147     
148     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
149
150     *ppobj = NULL;
151     if(SUCCEEDED(hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk))) {
152         hres = IUnknown_QueryInterface(punk, riid, ppobj);
153         IUnknown_Release(punk);
154     }
155     return hres;
156 }
157
158 static HRESULT WINAPI CF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
159 {
160     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
161     FIXME("(%p)->(%d),stub!\n",This,dolock);
162     return S_OK;
163 }
164
165 static IClassFactoryVtbl CF_Vtbl =
166 {
167     CF_QueryInterface,
168     CF_AddRef,
169     CF_Release,
170     CF_CreateInstance,
171     CF_LockServer
172 };
173
174 /*******************************************************************************
175  * DllGetClassObject [URLMON.@]
176  * Retrieves class object from a DLL object
177  *
178  * NOTES
179  *    Docs say returns STDAPI
180  *
181  * PARAMS
182  *    rclsid [I] CLSID for the class object
183  *    riid   [I] Reference to identifier of interface for class object
184  *    ppv    [O] Address of variable to receive interface pointer for riid
185  *
186  * RETURNS
187  *    Success: S_OK
188  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
189  *             E_UNEXPECTED
190  */
191
192 DWORD WINAPI URLMON_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
193 {
194     int i;
195     IClassFactoryImpl *factory;
196     
197     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
198     
199     if ( !IsEqualGUID( &IID_IClassFactory, riid )
200          && ! IsEqualGUID( &IID_IUnknown, riid) )
201         return E_NOINTERFACE;
202
203     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
204     {
205         if (IsEqualGUID(object_creation[i].clsid, rclsid))
206             break;
207     }
208
209     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
210     {
211         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
212         return CLASS_E_CLASSNOTAVAILABLE;
213     }
214
215     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
216     if (factory == NULL) return E_OUTOFMEMORY;
217
218     factory->ITF_IClassFactory.lpVtbl = &CF_Vtbl;
219     factory->ref = 1;
220
221     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
222
223     *ppv = &(factory->ITF_IClassFactory);
224     return S_OK;
225 }
226
227
228 /***********************************************************************
229  *              DllRegisterServerEx (URLMON.@)
230  */
231 HRESULT WINAPI URLMON_DllRegisterServerEx(void)
232 {
233     FIXME("(void): stub\n");
234
235     return E_FAIL;
236 }
237
238 /**************************************************************************
239  *                 UrlMkSetSessionOption (URLMON.@)
240  */
241  HRESULT WINAPI UrlMkSetSessionOption(long lost, LPVOID *splat, long time,
242                                         long nosee)
243 {
244     FIXME("(%#lx, %p, %#lx, %#lx): stub\n", lost, splat, time, nosee);
245
246     return S_OK;
247 }
248
249 /**************************************************************************
250  *                 ObtainUserAgentString (URLMON.@)
251  */
252 HRESULT WINAPI ObtainUserAgentString(DWORD dwOption, LPCSTR pcszUAOut, DWORD *cbSize)
253 {
254     FIXME("(%ld, %p, %p): stub\n", dwOption, pcszUAOut, cbSize);
255
256     if(dwOption) {
257       ERR("dwOption: %ld, must be zero\n", dwOption);
258     }
259
260     return S_OK;
261 }
262
263 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
264                                     LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
265 {
266     HRESULT hres;
267     DWORD size = cchResult;
268     
269     TRACE("(%s,%s,0x%08lx,%p,%ld,%p,%ld)\n", debugstr_w(pwzBaseUrl), debugstr_w(pwzRelativeUrl), dwCombineFlags,
270           pwzResult, cchResult, pcchResult, dwReserved);
271     hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
272     if(pcchResult) *pcchResult = size;
273     return hres;
274 }
275
276 HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
277 {
278     TRACE("(%s,%s,%08lx)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
279     return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags)==0?S_OK:S_FALSE;
280 }
281
282 /**************************************************************************
283  *                 IsValidURL (URLMON.@)
284  * 
285  * Determines if a specified string is a valid URL.
286  *
287  * PARAMS
288  *  pBC        [I] ignored, must be NULL.
289  *  szURL      [I] string that represents the URL in question.
290  *  dwReserved [I] reserved and must be zero.
291  *
292  * RETURNS
293  *  Success: S_OK.
294  *  Failure: S_FALSE.
295  *  returns E_INVALIDARG if one or more of the args is invalid.
296  *
297  * TODO:
298  *  test functionality against windows to see what a valid URL is.
299  */
300 HRESULT WINAPI IsValidURL(LPBC pBC, LPCWSTR szURL, DWORD dwReserved)
301 {
302     FIXME("(%p, %s, %ld): stub\n", pBC, debugstr_w(szURL), dwReserved);
303     
304     if (pBC != NULL || dwReserved != 0)
305         return E_INVALIDARG;
306     
307     return S_OK;
308 }