itss.c 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *    ITSS Class Factory
 *
 * Copyright 2002 Lionel Ulmer
 * Copyright 2004 Mike McCormack
 *
 *  see http://bonedaddy.net/pabs3/hhm/#chmspec
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 23 24 25 26 27 28
 */

#include "config.h"

#include <stdarg.h>
#include <stdio.h>

29 30
#define COBJMACROS

31 32 33 34 35
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "ole2.h"
36
#include "rpcproxy.h"
37
#include "advpub.h"
38 39 40 41

#include "wine/unicode.h"
#include "wine/debug.h"

42 43
#include "itsstor.h"

44 45
#include "initguid.h"
#include "wine/itss.h"
Jacek Caban's avatar
Jacek Caban committed
46

47 48 49 50
WINE_DEFAULT_DEBUG_CHANNEL(itss);

static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);

51
LONG dll_count = 0;
52
static HINSTANCE hInst;
53

54 55 56 57 58
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
    switch(fdwReason) {
    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls(hInstDLL);
59
        hInst = hInstDLL;
60 61 62 63 64 65 66 67 68
        break;
    }
    return TRUE;
}

/******************************************************************************
 * ITSS ClassFactory
 */
typedef struct {
69
    IClassFactory IClassFactory_iface;
70 71 72
    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
} IClassFactoryImpl;

73 74 75 76 77
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
    return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}

78 79 80
static HRESULT WINAPI
ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
{
81
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
82

83 84
    if (IsEqualGUID(riid, &IID_IUnknown) ||
        IsEqualGUID(riid, &IID_IClassFactory))
85 86
    {
	IClassFactory_AddRef(iface);
87
	*ppobj = &This->IClassFactory_iface;
88 89 90 91 92 93 94
	return S_OK;
    }

    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
    return E_NOINTERFACE;
}

95 96
static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
{
97
    ITSS_LockModule();
98
    return 2;
99 100
}

101 102
static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
{
103
    ITSS_UnlockModule();
104
    return 1;
105 106 107 108
}


static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
109 110
					  REFIID riid, LPVOID *ppobj)
{
111
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
112 113
    HRESULT hres;
    LPUNKNOWN punk;
114 115

    TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
116

117
    *ppobj = NULL;
118
    hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
119 120 121
    if (SUCCEEDED(hres)) {
        hres = IUnknown_QueryInterface(punk, riid, ppobj);
        IUnknown_Release(punk);
122 123 124 125
    }
    return hres;
}

126
static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
127
{
128 129
    TRACE("(%p)->(%d)\n", iface, dolock);

130
    if (dolock)
131
        ITSS_LockModule();
132
    else
133
        ITSS_UnlockModule();
134

135 136 137
    return S_OK;
}

138
static const IClassFactoryVtbl ITSSCF_Vtbl =
139 140 141 142 143 144 145 146
{
    ITSSCF_QueryInterface,
    ITSSCF_AddRef,
    ITSSCF_Release,
    ITSSCF_CreateInstance,
    ITSSCF_LockServer
};

147 148 149
static const IClassFactoryImpl ITStorage_factory = { { &ITSSCF_Vtbl }, ITSS_create };
static const IClassFactoryImpl MSITStore_factory = { { &ITSSCF_Vtbl }, ITS_IParseDisplayName_create };
static const IClassFactoryImpl ITSProtocol_factory = { { &ITSSCF_Vtbl }, ITSProtocol_create };
150

151 152 153
/***********************************************************************
 *		DllGetClassObject	(ITSS.@)
 */
154
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
155
{
156
    const IClassFactoryImpl *factory;
157

158
    TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
159

160 161
    if (IsEqualGUID(&CLSID_ITStorage, rclsid))
        factory = &ITStorage_factory;
162 163
    else if (IsEqualGUID(&CLSID_MSITStore, rclsid))
        factory = &MSITStore_factory;
164 165
    else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
        factory = &ITSProtocol_factory;
166
    else
167 168 169 170 171
    {
	FIXME("%s: no class found.\n", debugstr_guid(rclsid));
	return CLASS_E_CLASSNOTAVAILABLE;
    }

172
    return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
173 174 175 176 177
}

/*****************************************************************************/

typedef struct {
178
    IITStorage IITStorage_iface;
179
    LONG ref;
180 181
} ITStorageImpl;

182 183 184 185 186
static inline ITStorageImpl *impl_from_IITStorage(IITStorage *iface)
{
    return CONTAINING_RECORD(iface, ITStorageImpl, IITStorage_iface);
}

187

188
static HRESULT WINAPI ITStorageImpl_QueryInterface(
189 190 191 192
    IITStorage* iface,
    REFIID riid,
    void** ppvObject)
{
193
    ITStorageImpl *This = impl_from_IITStorage(iface);
194 195 196
    if (IsEqualGUID(riid, &IID_IUnknown)
	|| IsEqualGUID(riid, &IID_IITStorage))
    {
197 198
	IITStorage_AddRef(iface);
	*ppvObject = iface;
199 200 201 202 203 204 205
	return S_OK;
    }

    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
    return E_NOINTERFACE;
}

206
static ULONG WINAPI ITStorageImpl_AddRef(
207 208
    IITStorage* iface)
{
209
    ITStorageImpl *This = impl_from_IITStorage(iface);
210
    TRACE("%p\n", This);
211
    return InterlockedIncrement(&This->ref);
212 213
}

214
static ULONG WINAPI ITStorageImpl_Release(
215 216
    IITStorage* iface)
{
217
    ITStorageImpl *This = impl_from_IITStorage(iface);
218
    ULONG ref = InterlockedDecrement(&This->ref);
219

220 221
    if (ref == 0) {
        HeapFree(GetProcessHeap(), 0, This);
222
        ITSS_UnlockModule();
223
    }
224 225 226 227

    return ref;
}

228
static HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
229 230 231 232 233 234
    IITStorage* iface,
    const WCHAR* pwcsName,
    DWORD grfMode,
    DWORD reserved,
    IStorage** ppstgOpen)
{
235
    ITStorageImpl *This = impl_from_IITStorage(iface);
236

237
    TRACE("%p %s %u %u %p\n", This,
238 239 240 241 242 243
          debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );

    return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
                                0, reserved, ppstgOpen);
}

244
static HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
245 246 247 248 249 250
    IITStorage* iface,
    ILockBytes* plkbyt,
    DWORD grfMode,
    DWORD reserved,
    IStorage** ppstgOpen)
{
251
    ITStorageImpl *This = impl_from_IITStorage(iface);
252 253 254 255
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

256
static HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
257 258 259
    IITStorage* iface,
    const WCHAR* pwcsName)
{
260
    ITStorageImpl *This = impl_from_IITStorage(iface);
261 262 263 264
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

265
static HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
266 267 268
    IITStorage* iface,
    ILockBytes* plkbyt)
{
269
    ITStorageImpl *This = impl_from_IITStorage(iface);
270 271 272 273
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

274
static HRESULT WINAPI ITStorageImpl_StgOpenStorage(
275 276 277 278 279 280 281 282
    IITStorage* iface,
    const WCHAR* pwcsName,
    IStorage* pstgPriority,
    DWORD grfMode,
    SNB snbExclude,
    DWORD reserved,
    IStorage** ppstgOpen)
{
283
    ITStorageImpl *This = impl_from_IITStorage(iface);
284

285
    TRACE("%p %s %p %d %p\n", This, debugstr_w( pwcsName ),
286 287 288 289 290 291
           pstgPriority, grfMode, snbExclude );

    return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
                                snbExclude, reserved, ppstgOpen);
}

292
static HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
293 294 295 296 297 298 299 300
    IITStorage* iface,
    ILockBytes* plkbyt,
    IStorage* pStgPriority,
    DWORD grfMode,
    SNB snbExclude,
    DWORD reserved,
    IStorage** ppstgOpen)
{
301
    ITStorageImpl *This = impl_from_IITStorage(iface);
302 303 304 305
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

306
static HRESULT WINAPI ITStorageImpl_StgSetTimes(
307
    IITStorage* iface,
308 309 310 311
    const WCHAR* lpszName,
    const FILETIME* pctime,
    const FILETIME* patime,
    const FILETIME* pmtime)
312
{
313
    ITStorageImpl *This = impl_from_IITStorage(iface);
314 315 316 317
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

318
static HRESULT WINAPI ITStorageImpl_SetControlData(
319 320 321
    IITStorage* iface,
    PITS_Control_Data pControlData)
{
322
    ITStorageImpl *This = impl_from_IITStorage(iface);
323 324 325 326
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

327
static HRESULT WINAPI ITStorageImpl_DefaultControlData(
328 329 330
    IITStorage* iface,
    PITS_Control_Data* ppControlData)
{
331
    ITStorageImpl *This = impl_from_IITStorage(iface);
332 333 334 335
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

336
static HRESULT WINAPI ITStorageImpl_Compact(
337 338 339 340
    IITStorage* iface,
    const WCHAR* pwcsName,
    ECompactionLev iLev)
{
341
    ITStorageImpl *This = impl_from_IITStorage(iface);
342 343 344 345
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

346
static const IITStorageVtbl ITStorageImpl_Vtbl =
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
{
    ITStorageImpl_QueryInterface,
    ITStorageImpl_AddRef,
    ITStorageImpl_Release,
    ITStorageImpl_StgCreateDocfile,
    ITStorageImpl_StgCreateDocfileOnILockBytes,
    ITStorageImpl_StgIsStorageFile,
    ITStorageImpl_StgIsStorageILockBytes,
    ITStorageImpl_StgOpenStorage,
    ITStorageImpl_StgOpenStorageOnILockBytes,
    ITStorageImpl_StgSetTimes,
    ITStorageImpl_SetControlData,
    ITStorageImpl_DefaultControlData,
    ITStorageImpl_Compact,
};

static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
{
    ITStorageImpl *its;

367 368 369
    if( pUnkOuter )
        return CLASS_E_NOAGGREGATION;

370
    its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
371
    its->IITStorage_iface.lpVtbl = &ITStorageImpl_Vtbl;
372 373 374
    its->ref = 1;

    TRACE("-> %p\n", its);
375
    *ppObj = its;
376

377
    ITSS_LockModule();
378 379 380 381 382
    return S_OK;
}

/*****************************************************************************/

383
HRESULT WINAPI DllCanUnloadNow(void)
384
{
385
    TRACE("dll_count = %u\n", dll_count);
386
    return dll_count ? S_FALSE : S_OK;
387
}
388 389 390 391 392 393

/***********************************************************************
 *          DllRegisterServer (ITSS.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
394
    return __wine_register_resources( hInst );
395 396 397 398 399 400 401
}

/***********************************************************************
 *          DllUnregisterServer (ITSS.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
402
    return __wine_unregister_resources( hInst );
403
}