Remove MODULENAME prefix from
[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 #define COBJMACROS
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winnls.h"
35 #include "winreg.h"
36 #include "ole2.h"
37
38 #include "itss.h"
39 #include "uuids.h"
40
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43
44 #include "itsstor.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(itss);
47
48 #include "initguid.h"
49
50 DEFINE_GUID(CLSID_ITStorage,0x5d02926a,0x212e,0x11d0,0x9d,0xf9,0x00,0xa0,0xc9,0x22,0xe6,0xec );
51 DEFINE_GUID(CLSID_ITSProtocol,0x9d148290,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
52 DEFINE_GUID(IID_IITStorage, 0x88cc31de, 0x27ab, 0x11d0, 0x9d, 0xf9, 0x0, 0xa0, 0xc9, 0x22, 0xe6, 0xec);
53
54 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
55
56 ULONG dll_count = 0;
57
58 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
59 {
60     switch(fdwReason) {
61     case DLL_PROCESS_ATTACH:
62         DisableThreadLibraryCalls(hInstDLL);
63         break;
64     case DLL_PROCESS_DETACH:
65         break;
66     }
67     return TRUE;
68 }
69
70 /******************************************************************************
71  * ITSS ClassFactory
72  */
73 typedef struct {
74     IClassFactory ITF_IClassFactory;
75
76     DWORD ref;
77     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
78 } IClassFactoryImpl;
79
80 struct object_creation_info
81 {
82     const CLSID *clsid;
83     LPCSTR szClassName;
84     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
85 };
86
87 static const struct object_creation_info object_creation[] =
88 {
89     { &CLSID_ITStorage, "ITStorage", ITSS_create },
90     { &CLSID_ITSProtocol, "ITSProtocol", ITS_IParseDisplayName_create },
91 };
92
93 static HRESULT WINAPI
94 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
95 {
96     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
97
98     if (IsEqualGUID(riid, &IID_IUnknown)
99         || IsEqualGUID(riid, &IID_IClassFactory))
100     {
101         IClassFactory_AddRef(iface);
102         *ppobj = This;
103         return S_OK;
104     }
105
106     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
107     return E_NOINTERFACE;
108 }
109
110 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
111 {
112     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
113     return InterlockedIncrement(&This->ref);
114 }
115
116 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
117 {
118     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
119
120     ULONG ref = InterlockedDecrement(&This->ref);
121
122     if (ref == 0) {
123         HeapFree(GetProcessHeap(), 0, This);
124         InterlockedDecrement(&dll_count);
125     }
126
127     return ref;
128 }
129
130
131 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
132                                           REFIID riid, LPVOID *ppobj)
133 {
134     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
135     HRESULT hres;
136     LPUNKNOWN punk;
137     
138     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
139
140     *ppobj = NULL;
141     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
142     if (SUCCEEDED(hres)) {
143         hres = IUnknown_QueryInterface(punk, riid, ppobj);
144         IUnknown_Release(punk);
145     }
146     return hres;
147 }
148
149 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
150 {
151     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
152     FIXME("(%p)->(%d),stub!\n",This,dolock);
153     return S_OK;
154 }
155
156 static IClassFactoryVtbl ITSSCF_Vtbl =
157 {
158     ITSSCF_QueryInterface,
159     ITSSCF_AddRef,
160     ITSSCF_Release,
161     ITSSCF_CreateInstance,
162     ITSSCF_LockServer
163 };
164
165
166 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
167 {
168     DWORD i;
169     IClassFactoryImpl *factory;
170
171     TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
172     
173     if ( !IsEqualGUID( &IID_IClassFactory, iid )
174          && ! IsEqualGUID( &IID_IUnknown, iid) )
175         return E_NOINTERFACE;
176
177     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
178     {
179         if (IsEqualGUID(object_creation[i].clsid, rclsid))
180             break;
181     }
182
183     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
184     {
185         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
186         return CLASS_E_CLASSNOTAVAILABLE;
187     }
188
189     TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
190
191     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
192     if (factory == NULL) return E_OUTOFMEMORY;
193
194     factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
195     factory->ref = 1;
196
197     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
198
199     *ppv = &(factory->ITF_IClassFactory);
200     InterlockedIncrement(&dll_count);
201
202     TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
203
204     return S_OK;
205 }
206
207 /*****************************************************************************/
208
209 typedef struct {
210     IITStorageVtbl *vtbl_IITStorage;
211     DWORD ref;
212 } ITStorageImpl;
213
214
215 HRESULT WINAPI ITStorageImpl_QueryInterface(
216     IITStorage* iface,
217     REFIID riid,
218     void** ppvObject)
219 {
220     ITStorageImpl *This = (ITStorageImpl *)iface;
221     if (IsEqualGUID(riid, &IID_IUnknown)
222         || IsEqualGUID(riid, &IID_IITStorage))
223     {
224         IClassFactory_AddRef(iface);
225         *ppvObject = This;
226         return S_OK;
227     }
228
229     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
230     return E_NOINTERFACE;
231 }
232
233 ULONG WINAPI ITStorageImpl_AddRef(
234     IITStorage* iface)
235 {
236     ITStorageImpl *This = (ITStorageImpl *)iface;
237     TRACE("%p\n", This);
238     return InterlockedIncrement(&This->ref);
239 }
240
241 ULONG WINAPI ITStorageImpl_Release(
242     IITStorage* iface)
243 {
244     ITStorageImpl *This = (ITStorageImpl *)iface;
245     ULONG ref = InterlockedDecrement(&This->ref);
246
247     if (ref == 0) {
248         HeapFree(GetProcessHeap(), 0, This);
249         InterlockedDecrement(&dll_count);
250     }
251
252     return ref;
253 }
254
255 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
256     IITStorage* iface,
257     const WCHAR* pwcsName,
258     DWORD grfMode,
259     DWORD reserved,
260     IStorage** ppstgOpen)
261 {
262     ITStorageImpl *This = (ITStorageImpl *)iface;
263
264     TRACE("%p %s %lu %lu %p\n", This,
265           debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
266
267     return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
268                                 0, reserved, ppstgOpen);
269 }
270
271 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
272     IITStorage* iface,
273     ILockBytes* plkbyt,
274     DWORD grfMode,
275     DWORD reserved,
276     IStorage** ppstgOpen)
277 {
278     ITStorageImpl *This = (ITStorageImpl *)iface;
279     FIXME("%p\n", This);
280     return E_NOTIMPL;
281 }
282
283 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
284     IITStorage* iface,
285     const WCHAR* pwcsName)
286 {
287     ITStorageImpl *This = (ITStorageImpl *)iface;
288     FIXME("%p\n", This);
289     return E_NOTIMPL;
290 }
291
292 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
293     IITStorage* iface,
294     ILockBytes* plkbyt)
295 {
296     ITStorageImpl *This = (ITStorageImpl *)iface;
297     FIXME("%p\n", This);
298     return E_NOTIMPL;
299 }
300
301 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
302     IITStorage* iface,
303     const WCHAR* pwcsName,
304     IStorage* pstgPriority,
305     DWORD grfMode,
306     SNB snbExclude,
307     DWORD reserved,
308     IStorage** ppstgOpen)
309 {
310     ITStorageImpl *This = (ITStorageImpl *)iface;
311
312     TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
313            pstgPriority, grfMode, snbExclude );
314
315     return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
316                                 snbExclude, reserved, ppstgOpen);
317 }
318
319 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
320     IITStorage* iface,
321     ILockBytes* plkbyt,
322     IStorage* pStgPriority,
323     DWORD grfMode,
324     SNB snbExclude,
325     DWORD reserved,
326     IStorage** ppstgOpen)
327 {
328     ITStorageImpl *This = (ITStorageImpl *)iface;
329     FIXME("%p\n", This);
330     return E_NOTIMPL;
331 }
332
333 HRESULT WINAPI ITStorageImpl_StgSetTimes(
334     IITStorage* iface,
335     WCHAR* lpszName,
336     FILETIME* pctime,
337     FILETIME* patime,
338     FILETIME* pmtime)
339 {
340     ITStorageImpl *This = (ITStorageImpl *)iface;
341     FIXME("%p\n", This);
342     return E_NOTIMPL;
343 }
344
345 HRESULT WINAPI ITStorageImpl_SetControlData(
346     IITStorage* iface,
347     PITS_Control_Data pControlData)
348 {
349     ITStorageImpl *This = (ITStorageImpl *)iface;
350     FIXME("%p\n", This);
351     return E_NOTIMPL;
352 }
353
354 HRESULT WINAPI ITStorageImpl_DefaultControlData(
355     IITStorage* iface,
356     PITS_Control_Data* ppControlData)
357 {
358     ITStorageImpl *This = (ITStorageImpl *)iface;
359     FIXME("%p\n", This);
360     return E_NOTIMPL;
361 }
362
363 HRESULT WINAPI ITStorageImpl_Compact(
364     IITStorage* iface,
365     const WCHAR* pwcsName,
366     ECompactionLev iLev)
367 {
368     ITStorageImpl *This = (ITStorageImpl *)iface;
369     FIXME("%p\n", This);
370     return E_NOTIMPL;
371 }
372
373 static IITStorageVtbl ITStorageImpl_Vtbl =
374 {
375     ITStorageImpl_QueryInterface,
376     ITStorageImpl_AddRef,
377     ITStorageImpl_Release,
378     ITStorageImpl_StgCreateDocfile,
379     ITStorageImpl_StgCreateDocfileOnILockBytes,
380     ITStorageImpl_StgIsStorageFile,
381     ITStorageImpl_StgIsStorageILockBytes,
382     ITStorageImpl_StgOpenStorage,
383     ITStorageImpl_StgOpenStorageOnILockBytes,
384     ITStorageImpl_StgSetTimes,
385     ITStorageImpl_SetControlData,
386     ITStorageImpl_DefaultControlData,
387     ITStorageImpl_Compact,
388 };
389
390 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
391 {
392     ITStorageImpl *its;
393
394     if( pUnkOuter )
395         return CLASS_E_NOAGGREGATION;
396
397     its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
398     its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
399     its->ref = 1;
400
401     TRACE("-> %p\n", its);
402     *ppObj = (LPVOID) its;
403     InterlockedIncrement(&dll_count);
404
405     return S_OK;
406 }
407
408 /*****************************************************************************/
409
410 HRESULT WINAPI DllRegisterServer(void)
411 {
412     FIXME("\n");
413     return S_OK;
414 }
415
416 HRESULT WINAPI DllCanUnloadNow(void)
417 {
418     TRACE("dll_count = %lu\n", dll_count);
419     return dll_count ? S_FALSE : S_OK;
420 }