itss.c 9.61 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
 */


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

28 29
#define COBJMACROS

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

#include "wine/debug.h"

40 41
#include "itsstor.h"

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

45 46 47 48
WINE_DEFAULT_DEBUG_CHANNEL(itss);

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

49
LONG dll_count = 0;
50 51 52 53 54

/******************************************************************************
 * ITSS ClassFactory
 */
typedef struct {
55
    IClassFactory IClassFactory_iface;
56 57 58
    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
} IClassFactoryImpl;

59 60 61 62 63
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
    return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}

64 65 66
static HRESULT WINAPI
ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
{
67
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
68

69 70
    if (IsEqualGUID(riid, &IID_IUnknown) ||
        IsEqualGUID(riid, &IID_IClassFactory))
71 72
    {
	IClassFactory_AddRef(iface);
73
	*ppobj = &This->IClassFactory_iface;
74 75 76 77 78 79 80
	return S_OK;
    }

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

81 82
static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
{
83
    ITSS_LockModule();
84
    return 2;
85 86
}

87 88
static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
{
89
    ITSS_UnlockModule();
90
    return 1;
91 92 93
}


94 95
static HRESULT WINAPI ITSSCF_CreateInstance(IClassFactory *iface, IUnknown *outer,
                                            REFIID riid, void **ppv)
96
{
97
    IClassFactoryImpl *This = impl_from_IClassFactory(iface);
98
    IUnknown *unk;
99
    HRESULT hres;
100

101
    TRACE("(%p)->(%p %s %p)\n", This, outer, debugstr_guid(riid), ppv);
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    if(outer && !IsEqualGUID(riid, &IID_IUnknown)) {
        *ppv = NULL;
        return CLASS_E_NOAGGREGATION;
    }

    hres = This->pfnCreateInstance(outer, (void**)&unk);
    if(FAILED(hres)) {
        *ppv = NULL;
        return hres;
    }

    if(!IsEqualGUID(riid, &IID_IUnknown)) {
        hres = IUnknown_QueryInterface(unk, riid, ppv);
        IUnknown_Release(unk);
    }else {
        *ppv = unk;
119 120 121 122
    }
    return hres;
}

123
static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
124
{
125 126
    TRACE("(%p)->(%d)\n", iface, dolock);

127
    if (dolock)
128
        ITSS_LockModule();
129
    else
130
        ITSS_UnlockModule();
131

132 133 134
    return S_OK;
}

135
static const IClassFactoryVtbl ITSSCF_Vtbl =
136 137 138 139 140 141 142 143
{
    ITSSCF_QueryInterface,
    ITSSCF_AddRef,
    ITSSCF_Release,
    ITSSCF_CreateInstance,
    ITSSCF_LockServer
};

144 145 146
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 };
147

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

155
    TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
156

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

169
    return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
170 171 172 173 174
}

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

typedef struct {
175
    IITStorage IITStorage_iface;
176
    LONG ref;
177 178
} ITStorageImpl;

179 180 181 182 183
static inline ITStorageImpl *impl_from_IITStorage(IITStorage *iface)
{
    return CONTAINING_RECORD(iface, ITStorageImpl, IITStorage_iface);
}

184

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

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

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

211
static ULONG WINAPI ITStorageImpl_Release(
212 213
    IITStorage* iface)
{
214
    ITStorageImpl *This = impl_from_IITStorage(iface);
215
    ULONG ref = InterlockedDecrement(&This->ref);
216

217 218
    if (ref == 0) {
        HeapFree(GetProcessHeap(), 0, This);
219
        ITSS_UnlockModule();
220
    }
221 222 223 224

    return ref;
}

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

234
    TRACE("%p %s %lu %lu %p\n", This,
235 236 237 238 239 240
          debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );

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

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

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

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

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

282
    TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
283 284 285 286 287 288
           pstgPriority, grfMode, snbExclude );

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

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

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

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

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

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

343
static const IITStorageVtbl ITStorageImpl_Vtbl =
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
{
    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;

364 365 366
    if( pUnkOuter )
        return CLASS_E_NOAGGREGATION;

367
    its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
368
    its->IITStorage_iface.lpVtbl = &ITStorageImpl_Vtbl;
369 370 371
    its->ref = 1;

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

374
    ITSS_LockModule();
375 376 377 378 379
    return S_OK;
}

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

380
HRESULT WINAPI DllCanUnloadNow(void)
381
{
382
    TRACE("dll_count = %lu\n", dll_count);
383
    return dll_count ? S_FALSE : S_OK;
384
}