Fix signed/unsigned comparison warnings.
[wine] / dlls / itss / itss.c
1 /*
2  *    ITSS Class Factory
3  *
4  * Copyright 2002 Lionel Ulmer
5  * Copyright 2004 Mike McCormack
6  *
7  *  see http://bonedaddy.net/pabs3/hhm/#chmspec
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 #include "winreg.h"
34 #include "ole2.h"
35
36 #include "itss.h"
37 #include "uuids.h"
38
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
41
42 #include "itsstor.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(itss);
45
46 #include "initguid.h"
47
48 DEFINE_GUID(CLSID_ITStorage,0x5d02926a,0x212e,0x11d0,0x9d,0xf9,0x00,0xa0,0xc9,0x22,0xe6,0xec );
49 DEFINE_GUID(CLSID_ITSProtocol,0x9d148290,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
50 DEFINE_GUID(IID_IITStorage, 0x88cc31de, 0x27ab, 0x11d0, 0x9d, 0xf9, 0x0, 0xa0, 0xc9, 0x22, 0xe6, 0xec);
51
52 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
53
54 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
55 {
56     switch(fdwReason) {
57     case DLL_PROCESS_ATTACH:
58         DisableThreadLibraryCalls(hInstDLL);
59         break;
60     case DLL_PROCESS_DETACH:
61         break;
62     }
63     return TRUE;
64 }
65
66 /******************************************************************************
67  * ITSS ClassFactory
68  */
69 typedef struct {
70     IClassFactory ITF_IClassFactory;
71
72     DWORD ref;
73     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
74 } IClassFactoryImpl;
75
76 struct object_creation_info
77 {
78     const CLSID *clsid;
79     LPCSTR szClassName;
80     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
81 };
82
83 static const struct object_creation_info object_creation[] =
84 {
85     { &CLSID_ITStorage, "ITStorage", ITSS_create },
86     { &CLSID_ITSProtocol, "ITSProtocol", ITS_IParseDisplayName_create },
87 };
88
89 static HRESULT WINAPI
90 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
91 {
92     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
93
94     if (IsEqualGUID(riid, &IID_IUnknown)
95         || IsEqualGUID(riid, &IID_IClassFactory))
96     {
97         IClassFactory_AddRef(iface);
98         *ppobj = This;
99         return S_OK;
100     }
101
102     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
103     return E_NOINTERFACE;
104 }
105
106 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface) {
107     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
108     return ++(This->ref);
109 }
110
111 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface) {
112     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
113
114     ULONG ref = --This->ref;
115
116     if (ref == 0)
117         HeapFree(GetProcessHeap(), 0, This);
118
119     return ref;
120 }
121
122
123 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
124                                           REFIID riid, LPVOID *ppobj) {
125     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
126     HRESULT hres;
127     LPUNKNOWN punk;
128     
129     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
130
131     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
132     if (FAILED(hres)) {
133         *ppobj = NULL;
134         return hres;
135     }
136     hres = IUnknown_QueryInterface(punk, riid, ppobj);
137     if (FAILED(hres)) {
138         *ppobj = NULL;
139         return hres;
140     }
141     IUnknown_Release(punk);
142     return hres;
143 }
144
145 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
146     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
147     FIXME("(%p)->(%d),stub!\n",This,dolock);
148     return S_OK;
149 }
150
151 static IClassFactoryVtbl ITSSCF_Vtbl =
152 {
153     ITSSCF_QueryInterface,
154     ITSSCF_AddRef,
155     ITSSCF_Release,
156     ITSSCF_CreateInstance,
157     ITSSCF_LockServer
158 };
159
160
161 HRESULT WINAPI ITSS_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
162 {
163     int i;
164     IClassFactoryImpl *factory;
165
166     TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
167     
168     if ( !IsEqualGUID( &IID_IClassFactory, iid )
169          && ! IsEqualGUID( &IID_IUnknown, iid) )
170         return E_NOINTERFACE;
171
172     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
173     {
174         if (IsEqualGUID(object_creation[i].clsid, rclsid))
175             break;
176     }
177
178     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
179     {
180         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
181         return CLASS_E_CLASSNOTAVAILABLE;
182     }
183
184     TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
185
186     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
187     if (factory == NULL) return E_OUTOFMEMORY;
188
189     factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
190     factory->ref = 1;
191
192     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
193
194     *ppv = &(factory->ITF_IClassFactory);
195
196     TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
197
198     return S_OK;
199 }
200
201 /*****************************************************************************/
202
203 typedef struct {
204     IITStorageVtbl *vtbl_IITStorage;
205     DWORD ref;
206 } ITStorageImpl;
207
208
209 HRESULT WINAPI ITStorageImpl_QueryInterface(
210     IITStorage* iface,
211     REFIID riid,
212     void** ppvObject)
213 {
214     ITStorageImpl *This = (ITStorageImpl *)iface;
215     if (IsEqualGUID(riid, &IID_IUnknown)
216         || IsEqualGUID(riid, &IID_IITStorage))
217     {
218         IClassFactory_AddRef(iface);
219         *ppvObject = This;
220         return S_OK;
221     }
222
223     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
224     return E_NOINTERFACE;
225 }
226
227 ULONG WINAPI ITStorageImpl_AddRef(
228     IITStorage* iface)
229 {
230     ITStorageImpl *This = (ITStorageImpl *)iface;
231     TRACE("%p\n", This);
232     return ++(This->ref);
233 }
234
235 ULONG WINAPI ITStorageImpl_Release(
236     IITStorage* iface)
237 {
238     ITStorageImpl *This = (ITStorageImpl *)iface;
239     ULONG ref = --This->ref;
240
241     if (ref == 0)
242         HeapFree(GetProcessHeap(), 0, This);
243
244     return ref;
245 }
246
247 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
248     IITStorage* iface,
249     const WCHAR* pwcsName,
250     DWORD grfMode,
251     DWORD reserved,
252     IStorage** ppstgOpen)
253 {
254     ITStorageImpl *This = (ITStorageImpl *)iface;
255
256     TRACE("%p %s %lu %lu %p\n", This,
257           debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
258
259     return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
260                                 0, reserved, ppstgOpen);
261 }
262
263 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
264     IITStorage* iface,
265     ILockBytes* plkbyt,
266     DWORD grfMode,
267     DWORD reserved,
268     IStorage** ppstgOpen)
269 {
270     ITStorageImpl *This = (ITStorageImpl *)iface;
271     FIXME("%p\n", This);
272     return E_NOTIMPL;
273 }
274
275 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
276     IITStorage* iface,
277     const WCHAR* pwcsName)
278 {
279     ITStorageImpl *This = (ITStorageImpl *)iface;
280     FIXME("%p\n", This);
281     return E_NOTIMPL;
282 }
283
284 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
285     IITStorage* iface,
286     ILockBytes* plkbyt)
287 {
288     ITStorageImpl *This = (ITStorageImpl *)iface;
289     FIXME("%p\n", This);
290     return E_NOTIMPL;
291 }
292
293 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
294     IITStorage* iface,
295     const WCHAR* pwcsName,
296     IStorage* pstgPriority,
297     DWORD grfMode,
298     SNB snbExclude,
299     DWORD reserved,
300     IStorage** ppstgOpen)
301 {
302     ITStorageImpl *This = (ITStorageImpl *)iface;
303
304     TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
305            pstgPriority, grfMode, snbExclude );
306
307     return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
308                                 snbExclude, reserved, ppstgOpen);
309 }
310
311 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
312     IITStorage* iface,
313     ILockBytes* plkbyt,
314     IStorage* pStgPriority,
315     DWORD grfMode,
316     SNB snbExclude,
317     DWORD reserved,
318     IStorage** ppstgOpen)
319 {
320     ITStorageImpl *This = (ITStorageImpl *)iface;
321     FIXME("%p\n", This);
322     return E_NOTIMPL;
323 }
324
325 HRESULT WINAPI ITStorageImpl_StgSetTimes(
326     IITStorage* iface,
327     WCHAR* lpszName,
328     FILETIME* pctime,
329     FILETIME* patime,
330     FILETIME* pmtime)
331 {
332     ITStorageImpl *This = (ITStorageImpl *)iface;
333     FIXME("%p\n", This);
334     return E_NOTIMPL;
335 }
336
337 HRESULT WINAPI ITStorageImpl_SetControlData(
338     IITStorage* iface,
339     PITS_Control_Data pControlData)
340 {
341     ITStorageImpl *This = (ITStorageImpl *)iface;
342     FIXME("%p\n", This);
343     return E_NOTIMPL;
344 }
345
346 HRESULT WINAPI ITStorageImpl_DefaultControlData(
347     IITStorage* iface,
348     PITS_Control_Data* ppControlData)
349 {
350     ITStorageImpl *This = (ITStorageImpl *)iface;
351     FIXME("%p\n", This);
352     return E_NOTIMPL;
353 }
354
355 HRESULT WINAPI ITStorageImpl_Compact(
356     IITStorage* iface,
357     const WCHAR* pwcsName,
358     ECompactionLev iLev)
359 {
360     ITStorageImpl *This = (ITStorageImpl *)iface;
361     FIXME("%p\n", This);
362     return E_NOTIMPL;
363 }
364
365 static IITStorageVtbl ITStorageImpl_Vtbl =
366 {
367     ITStorageImpl_QueryInterface,
368     ITStorageImpl_AddRef,
369     ITStorageImpl_Release,
370     ITStorageImpl_StgCreateDocfile,
371     ITStorageImpl_StgCreateDocfileOnILockBytes,
372     ITStorageImpl_StgIsStorageFile,
373     ITStorageImpl_StgIsStorageILockBytes,
374     ITStorageImpl_StgOpenStorage,
375     ITStorageImpl_StgOpenStorageOnILockBytes,
376     ITStorageImpl_StgSetTimes,
377     ITStorageImpl_SetControlData,
378     ITStorageImpl_DefaultControlData,
379     ITStorageImpl_Compact,
380 };
381
382 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
383 {
384     ITStorageImpl *its;
385
386     its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
387     its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
388     its->ref = 1;
389
390     TRACE("-> %p\n", its);
391     *ppObj = (LPVOID) its;
392
393     return S_OK;
394 }
395
396 /*****************************************************************************/
397
398 HRESULT WINAPI ITSS_DllRegisterServer(void)
399 {
400     FIXME("\n");
401     return S_OK;
402 }
403
404 BOOL WINAPI ITSS_DllCanUnloadNow(void)
405 {
406     FIXME("\n");
407
408     return FALSE;
409 }