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