blob: 73b8ffb4f97fc5fd91bcc0dfb2b39e0c48baed95 [file] [log] [blame]
Noomen Hamza3fb3da21999-01-28 17:56:14 +00001/***************************************************************************************
2 * BindCtx implementation
3 *
4 * Copyright 1999 Noomen Hamza
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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
Noomen Hamza3fb3da21999-01-28 17:56:14 +000019 ***************************************************************************************/
20
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000021#include <stdarg.h>
Noomen Hamza3fb3da21999-01-28 17:56:14 +000022#include <string.h>
23#include <assert.h>
24#include "winerror.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000025#include "windef.h"
Alexandre Julliard74af67e2000-09-26 00:00:55 +000026#include "winbase.h"
Alexandre Julliardc7e7df82000-08-14 14:41:19 +000027#include "wine/unicode.h"
Ove Kaaven1f5315c2002-12-05 20:33:07 +000028#include "objbase.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000029#include "wine/debug.h"
Noomen Hamza3fb3da21999-01-28 17:56:14 +000030
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000031WINE_DEFAULT_DEBUG_CHANNEL(ole);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000032
Noomen Hamzaed494ec1999-03-23 13:48:56 +000033/* represent the first size table and it's increment block size */
Vincent Béron9a624912002-05-31 23:06:46 +000034#define BLOCK_TAB_SIZE 10
Noomen Hamzaed494ec1999-03-23 13:48:56 +000035#define MAX_TAB_SIZE 0xFFFFFFFF
36
37/* data structure of the BindCtx table elements */
38typedef struct BindCtxObject{
39
40 IUnknown* pObj; /* point on a bound object */
41
42 LPOLESTR pkeyObj; /* key associated to this bound object */
43
44 BYTE regType; /* registration type: 1 if RegisterObjectParam and 0 if RegisterObjectBound */
45
46} BindCtxObject;
47
48/* BindCtx data strucrture */
Noomen Hamza3fb3da21999-01-28 17:56:14 +000049typedef struct BindCtxImpl{
50
Francois Gouget01c9ac41999-10-31 01:59:23 +000051 ICOM_VFIELD(IBindCtx); /* VTable relative to the IBindCtx interface.*/
Vincent Béron9a624912002-05-31 23:06:46 +000052
Noomen Hamzaed494ec1999-03-23 13:48:56 +000053 ULONG ref; /* reference counter for this object */
54
Francois Gouget282f7272001-02-28 05:31:02 +000055 BindCtxObject* bindCtxTable; /* this is a table in which all bounded objects are stored*/
Noomen Hamzaed494ec1999-03-23 13:48:56 +000056 DWORD bindCtxTableLastIndex; /* first free index in the table */
57 DWORD bindCtxTableSize; /* size table */
58
Francois Gouget282f7272001-02-28 05:31:02 +000059 BIND_OPTS2 bindOption2; /* a structure which contains the bind options*/
Noomen Hamza3fb3da21999-01-28 17:56:14 +000060
61} BindCtxImpl;
62
Noomen Hamzaed494ec1999-03-23 13:48:56 +000063/* IBindCtx prototype functions : */
Noomen Hamza3fb3da21999-01-28 17:56:14 +000064
Noomen Hamzaed494ec1999-03-23 13:48:56 +000065/* IUnknown functions*/
66static HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject);
67static ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface);
68static ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface);
69/* IBindCtx functions */
70static HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk);
71static HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk);
72static HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface);
Alexandre Julliard87fa2d52002-12-19 22:16:35 +000073static HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts);
74static HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts);
Noomen Hamzaed494ec1999-03-23 13:48:56 +000075static HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot);
76static HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk);
77static HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk);
78static HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** ppenum);
79static HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR pszkey);
80/* Local functions*/
Francois Gougetb0c61291999-02-18 13:26:22 +000081HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This);
82HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This);
Noomen Hamzaed494ec1999-03-23 13:48:56 +000083HRESULT WINAPI BindCtxImpl_GetObjectIndex(BindCtxImpl* This,IUnknown* punk,LPOLESTR pszkey,DWORD *index);
Francois Gougetb0c61291999-02-18 13:26:22 +000084
Noomen Hamzaed494ec1999-03-23 13:48:56 +000085/* Virtual function table for the BindCtx class. */
Noomen Hamza3fb3da21999-01-28 17:56:14 +000086static ICOM_VTABLE(IBindCtx) VT_BindCtxImpl =
Noomen Hamza3fb3da21999-01-28 17:56:14 +000087 {
Paul Quinn2305f3c1999-05-22 11:41:38 +000088 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
Francois Gougetb0c61291999-02-18 13:26:22 +000089 BindCtxImpl_QueryInterface,
90 BindCtxImpl_AddRef,
91 BindCtxImpl_Release,
92 BindCtxImpl_RegisterObjectBound,
93 BindCtxImpl_RevokeObjectBound,
Noomen Hamzaed494ec1999-03-23 13:48:56 +000094 BindCtxImpl_ReleaseBoundObjects,
Francois Gougetb0c61291999-02-18 13:26:22 +000095 BindCtxImpl_SetBindOptions,
96 BindCtxImpl_GetBindOptions,
97 BindCtxImpl_GetRunningObjectTable,
98 BindCtxImpl_RegisterObjectParam,
99 BindCtxImpl_GetObjectParam,
100 BindCtxImpl_EnumObjectParam,
101 BindCtxImpl_RevokeObjectParam
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000102};
103
104/*******************************************************************************
105 * BindCtx_QueryInterface
106 *******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000107HRESULT WINAPI BindCtxImpl_QueryInterface(IBindCtx* iface,REFIID riid,void** ppvObject)
108{
109 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000110
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000111 TRACE("(%p,%p,%p)\n",This,riid,ppvObject);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000112
113 /* Perform a sanity check on the parameters.*/
114 if ( (This==0) || (ppvObject==0) )
115 return E_INVALIDARG;
Vincent Béron9a624912002-05-31 23:06:46 +0000116
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000117 /* Initialize the return parameter.*/
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000118 *ppvObject = 0;
119
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000120 /* Compare the riid with the interface IDs implemented by this object.*/
121 if (IsEqualIID(&IID_IUnknown, riid))
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000122 *ppvObject = (IBindCtx*)This;
123 else
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000124 if (IsEqualIID(&IID_IBindCtx, riid))
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000125 *ppvObject = (IBindCtx*)This;
126
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000127 /* Check that we obtained an interface.*/
128 if ((*ppvObject)==0)
129 return E_NOINTERFACE;
Vincent Béron9a624912002-05-31 23:06:46 +0000130
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000131 /* Query Interface always increases the reference count by one when it is successful */
Francois Gougetb0c61291999-02-18 13:26:22 +0000132 BindCtxImpl_AddRef(iface);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000133
134 return S_OK;
135}
136
137/******************************************************************************
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000138 * BindCtx_AddRef
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000139 ******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000140ULONG WINAPI BindCtxImpl_AddRef(IBindCtx* iface)
141{
142 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000143
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000144 TRACE("(%p)\n",This);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000145
146 return ++(This->ref);
147}
148
149/******************************************************************************
150 * BindCtx_Release
151 ******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000152ULONG WINAPI BindCtxImpl_Release(IBindCtx* iface)
153{
154 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000155
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000156 TRACE("(%p)\n",This);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000157
158 This->ref--;
159
160 if (This->ref==0){
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000161
Alexandre Julliard81ee21d1999-12-27 05:26:00 +0000162 /* release all registered objects */
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000163 BindCtxImpl_ReleaseBoundObjects((IBindCtx*)This);
164
Francois Gougetb0c61291999-02-18 13:26:22 +0000165 BindCtxImpl_Destroy(This);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000166
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000167 return 0;
168 }
Vincent Béron9a624912002-05-31 23:06:46 +0000169 return This->ref;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000170}
171
172
173/******************************************************************************
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000174 * BindCtx_Construct (local function)
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000175 *******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000176HRESULT WINAPI BindCtxImpl_Construct(BindCtxImpl* This)
177{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000178 TRACE("(%p)\n",This);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000179
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000180 /* Initialize the virtual function table.*/
Alexandre Julliardc2ebe1f2003-04-10 18:17:34 +0000181 This->lpVtbl = &VT_BindCtxImpl;
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000182 This->ref = 0;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000183
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000184 /* Initialize the BIND_OPTS2 structure */
185 This->bindOption2.cbStruct = sizeof(BIND_OPTS2);
186 This->bindOption2.grfFlags = 0;
187 This->bindOption2.grfMode = STGM_READWRITE;
188 This->bindOption2.dwTickCountDeadline = 0;
189
190 This->bindOption2.dwTrackFlags = 0;
191 This->bindOption2.dwClassContext = CLSCTX_SERVER;
192 This->bindOption2.locale = 1033;
193 This->bindOption2.pServerInfo = 0;
194
195 /* Initialize the bindctx table */
196 This->bindCtxTableSize=BLOCK_TAB_SIZE;
197 This->bindCtxTableLastIndex=0;
198 This->bindCtxTable= HeapAlloc(GetProcessHeap(), 0,This->bindCtxTableSize*sizeof(BindCtxObject));
199
200 if (This->bindCtxTable==NULL)
201 return E_OUTOFMEMORY;
202
203 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000204}
205
206/******************************************************************************
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000207 * BindCtx_Destroy (local function)
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000208 *******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000209HRESULT WINAPI BindCtxImpl_Destroy(BindCtxImpl* This)
210{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000211 TRACE("(%p)\n",This);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000212
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000213 /* free the table space memory */
214 HeapFree(GetProcessHeap(),0,This->bindCtxTable);
215
216 /* free the bindctx structure */
217 HeapFree(GetProcessHeap(),0,This);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000218
219 return S_OK;
220}
221
222
223/******************************************************************************
224 * BindCtx_RegisterObjectBound
225 ******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000226HRESULT WINAPI BindCtxImpl_RegisterObjectBound(IBindCtx* iface,IUnknown* punk)
227{
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000228 ICOM_THIS(BindCtxImpl,iface);
229 DWORD lastIndex=This->bindCtxTableLastIndex;
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000230
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000231 TRACE("(%p,%p)\n",This,punk);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000232
233 if (punk==NULL)
234 return E_POINTER;
Vincent Béron9a624912002-05-31 23:06:46 +0000235
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000236 IUnknown_AddRef(punk);
Vincent Béron9a624912002-05-31 23:06:46 +0000237
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000238 /* put the object in the first free element in the table */
239 This->bindCtxTable[lastIndex].pObj = punk;
240 This->bindCtxTable[lastIndex].pkeyObj = NULL;
241 This->bindCtxTable[lastIndex].regType = 0;
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000242 lastIndex= ++This->bindCtxTableLastIndex;
243
244 if (lastIndex == This->bindCtxTableSize){ /* the table is full so it must be resized */
245
246 if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE)){
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000247 FIXME("This->bindCtxTableSize: %ld is out of data limite \n",This->bindCtxTableSize);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000248 return E_FAIL;
Patrik Stridvall3c0211f2001-09-11 00:32:32 +0000249 }
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000250
251 This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */
252
253 This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable,
254 This->bindCtxTableSize * sizeof(BindCtxObject));
255 if (!This->bindCtxTable)
256 return E_OUTOFMEMORY;
257 }
258 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000259}
260
261/******************************************************************************
262 * BindCtx_RevokeObjectBound
263 ******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000264HRESULT WINAPI BindCtxImpl_RevokeObjectBound(IBindCtx* iface, IUnknown* punk)
265{
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000266 DWORD index,j;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000267
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000268 ICOM_THIS(BindCtxImpl,iface);
269
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000270 TRACE("(%p,%p)\n",This,punk);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000271
272 /* check if the object was registred or not */
273 if (BindCtxImpl_GetObjectIndex(This,punk,NULL,&index)==S_FALSE)
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000274 return MK_E_NOTBOUND;
275
Alberto Massarifc47be52003-04-05 05:10:37 +0000276 if(This->bindCtxTable[index].pObj)
277 IUnknown_Release(This->bindCtxTable[index].pObj);
278 if(This->bindCtxTable[index].pkeyObj)
279 HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj);
280
Andreas Mohrf32f9182001-04-20 18:36:05 +0000281 /* left-shift all elements in the right side of the current revoked object */
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000282 for(j=index; j<This->bindCtxTableLastIndex-1; j++)
283 This->bindCtxTable[j]= This->bindCtxTable[j+1];
Vincent Béron9a624912002-05-31 23:06:46 +0000284
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000285 This->bindCtxTableLastIndex--;
286
287 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000288}
289
290/******************************************************************************
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000291 * BindCtx_ReleaseBoundObjects
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000292 ******************************************************************************/
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000293HRESULT WINAPI BindCtxImpl_ReleaseBoundObjects(IBindCtx* iface)
Francois Gougetb0c61291999-02-18 13:26:22 +0000294{
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000295 DWORD i;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000296
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000297 ICOM_THIS(BindCtxImpl,iface);
298
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000299 TRACE("(%p)\n",This);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000300
301 for(i=0;i<This->bindCtxTableLastIndex;i++)
Alberto Massarifc47be52003-04-05 05:10:37 +0000302 {
303 if(This->bindCtxTable[i].pObj)
304 IUnknown_Release(This->bindCtxTable[i].pObj);
305 if(This->bindCtxTable[i].pkeyObj)
306 HeapFree(GetProcessHeap(),0,This->bindCtxTable[i].pkeyObj);
307 }
308
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000309 This->bindCtxTableLastIndex = 0;
310
311 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000312}
313
314/******************************************************************************
315 * BindCtx_SetBindOptions
316 ******************************************************************************/
Alexandre Julliard87fa2d52002-12-19 22:16:35 +0000317HRESULT WINAPI BindCtxImpl_SetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts)
Francois Gougetb0c61291999-02-18 13:26:22 +0000318{
319 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000320
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000321 TRACE("(%p,%p)\n",This,pbindopts);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000322
323 if (pbindopts==NULL)
324 return E_POINTER;
Vincent Béron9a624912002-05-31 23:06:46 +0000325
Gerard Patelf44c1f71999-12-10 03:23:35 +0000326 if (pbindopts->cbStruct > sizeof(BIND_OPTS2))
327 {
Francois Gougete76218d2001-05-09 17:31:31 +0000328 WARN("invalid size\n");
Gerard Patelf44c1f71999-12-10 03:23:35 +0000329 return E_INVALIDARG; /* FIXME : not verified */
330 }
331 memcpy(&This->bindOption2, pbindopts, pbindopts->cbStruct);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000332 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000333}
334
335/******************************************************************************
336 * BindCtx_GetBindOptions
337 ******************************************************************************/
Alexandre Julliard87fa2d52002-12-19 22:16:35 +0000338HRESULT WINAPI BindCtxImpl_GetBindOptions(IBindCtx* iface,BIND_OPTS *pbindopts)
Francois Gougetb0c61291999-02-18 13:26:22 +0000339{
340 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000341
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000342 TRACE("(%p,%p)\n",This,pbindopts);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000343
344 if (pbindopts==NULL)
345 return E_POINTER;
346
Gerard Patelf44c1f71999-12-10 03:23:35 +0000347 if (pbindopts->cbStruct > sizeof(BIND_OPTS2))
348 {
Francois Gougete76218d2001-05-09 17:31:31 +0000349 WARN("invalid size\n");
Gerard Patelf44c1f71999-12-10 03:23:35 +0000350 return E_INVALIDARG; /* FIXME : not verified */
351 }
352 memcpy(pbindopts, &This->bindOption2, pbindopts->cbStruct);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000353 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000354}
355
356/******************************************************************************
357 * BindCtx_GetRunningObjectTable
358 ******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000359HRESULT WINAPI BindCtxImpl_GetRunningObjectTable(IBindCtx* iface,IRunningObjectTable** pprot)
360{
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000361 HRESULT res;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000362
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000363 ICOM_THIS(BindCtxImpl,iface);
364
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000365 TRACE("(%p,%p)\n",This,pprot);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000366
367 if (pprot==NULL)
368 return E_POINTER;
Vincent Béron9a624912002-05-31 23:06:46 +0000369
Paul Quinnaaa83061999-06-05 15:23:20 +0000370 res=GetRunningObjectTable(0, pprot);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000371
372 return res;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000373}
374
375/******************************************************************************
376 * BindCtx_RegisterObjectParam
377 ******************************************************************************/
Alexandre Julliarda3960291999-02-26 11:11:13 +0000378HRESULT WINAPI BindCtxImpl_RegisterObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown* punk)
Francois Gougetb0c61291999-02-18 13:26:22 +0000379{
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000380 DWORD index=0;
Francois Gougetb0c61291999-02-18 13:26:22 +0000381 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000382
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000383 TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000384
385 if (punk==NULL)
386 return E_INVALIDARG;
Vincent Béron9a624912002-05-31 23:06:46 +0000387
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000388 if (pszkey!=NULL && BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_OK)
389 {
390 TRACE("Overwriting existing key\n");
391 if(This->bindCtxTable[index].pObj!=NULL)
392 IUnknown_Release(This->bindCtxTable[index].pObj);
393 This->bindCtxTable[index].pObj=punk;
Rolf Kalbermatter919bd782003-08-29 22:10:01 +0000394 IUnknown_AddRef(punk);
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000395 return S_OK;
396 }
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000397 This->bindCtxTable[This->bindCtxTableLastIndex].pObj = punk;
398 This->bindCtxTable[This->bindCtxTableLastIndex].regType = 1;
399
400 if (pszkey==NULL)
401
402 This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=NULL;
403
404 else{
405
406 This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj=
407 HeapAlloc(GetProcessHeap(),0,(sizeof(WCHAR)*(1+lstrlenW(pszkey))));
408
409 if (This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj==NULL)
410 return E_OUTOFMEMORY;
Alexandre Julliardc7e7df82000-08-14 14:41:19 +0000411 strcpyW(This->bindCtxTable[This->bindCtxTableLastIndex].pkeyObj,pszkey);
Patrik Stridvall3c0211f2001-09-11 00:32:32 +0000412 }
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000413
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000414 This->bindCtxTableLastIndex++;
Vincent Béron9a624912002-05-31 23:06:46 +0000415
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000416 if (This->bindCtxTableLastIndex == This->bindCtxTableSize){ /* table is full ! must be resized */
417
418 This->bindCtxTableSize+=BLOCK_TAB_SIZE; /* new table size */
419
420 if (This->bindCtxTableSize > (MAX_TAB_SIZE-BLOCK_TAB_SIZE)){
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000421 FIXME("This->bindCtxTableSize: %ld is out of data limite \n",This->bindCtxTableSize);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000422 return E_FAIL;
423 }
424 This->bindCtxTable = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,This->bindCtxTable,
425 This->bindCtxTableSize * sizeof(BindCtxObject));
426 if (!This->bindCtxTable)
427 return E_OUTOFMEMORY;
428 }
Rolf Kalbermatter919bd782003-08-29 22:10:01 +0000429 IUnknown_AddRef(punk);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000430 return S_OK;
431}
Rolf Kalbermatter919bd782003-08-29 22:10:01 +0000432
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000433/******************************************************************************
434 * BindCtx_GetObjectParam
435 ******************************************************************************/
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000436HRESULT WINAPI BindCtxImpl_GetObjectParam(IBindCtx* iface,LPOLESTR pszkey, IUnknown** punk)
Francois Gougetb0c61291999-02-18 13:26:22 +0000437{
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000438 DWORD index;
Francois Gougetb0c61291999-02-18 13:26:22 +0000439 ICOM_THIS(BindCtxImpl,iface);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000440
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000441 TRACE("(%p,%s,%p)\n",This,debugstr_w(pszkey),punk);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000442
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000443 if (punk==NULL)
444 return E_POINTER;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000445
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000446 *punk=0;
Vincent Béron9a624912002-05-31 23:06:46 +0000447
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000448 if (BindCtxImpl_GetObjectIndex(This,NULL,pszkey,&index)==S_FALSE)
449 return E_FAIL;
450
451 IUnknown_AddRef(This->bindCtxTable[index].pObj);
Vincent Béron9a624912002-05-31 23:06:46 +0000452
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000453 *punk = This->bindCtxTable[index].pObj;
454
455 return S_OK;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000456}
457
458/******************************************************************************
459 * BindCtx_RevokeObjectParam
460 ******************************************************************************/
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000461HRESULT WINAPI BindCtxImpl_RevokeObjectParam(IBindCtx* iface,LPOLESTR ppenum)
Francois Gougetb0c61291999-02-18 13:26:22 +0000462{
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000463 DWORD index,j;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000464
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000465 ICOM_THIS(BindCtxImpl,iface);
466
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000467 TRACE("(%p,%s)\n",This,debugstr_w(ppenum));
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000468
469 if (BindCtxImpl_GetObjectIndex(This,NULL,ppenum,&index)==S_FALSE)
470 return E_FAIL;
471
472 /* release the object if it's found */
Alberto Massarifc47be52003-04-05 05:10:37 +0000473 if(This->bindCtxTable[index].pObj)
474 IUnknown_Release(This->bindCtxTable[index].pObj);
475 if(This->bindCtxTable[index].pkeyObj)
476 HeapFree(GetProcessHeap(),0,This->bindCtxTable[index].pkeyObj);
477
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000478 /* remove the object from the table with a left-shifting of all objects in the right side */
479 for(j=index; j<This->bindCtxTableLastIndex-1; j++)
480 This->bindCtxTable[j]= This->bindCtxTable[j+1];
Vincent Béron9a624912002-05-31 23:06:46 +0000481
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000482 This->bindCtxTableLastIndex--;
483
484 return S_OK;
485}
486
487/******************************************************************************
488 * BindCtx_EnumObjectParam
489 ******************************************************************************/
490HRESULT WINAPI BindCtxImpl_EnumObjectParam(IBindCtx* iface,IEnumString** pszkey)
491{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000492 FIXME("(%p,%p),stub!\n",iface,pszkey);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000493 return E_NOTIMPL;
494}
495
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000496/********************************************************************************
497 * GetObjectIndex (local function)
498 ********************************************************************************/
499HRESULT WINAPI BindCtxImpl_GetObjectIndex(BindCtxImpl* This,
500 IUnknown* punk,
501 LPOLESTR pszkey,
502 DWORD *index)
503{
504
505 DWORD i;
506 BYTE found=0;
Vincent Béron9a624912002-05-31 23:06:46 +0000507
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000508 TRACE("(%p,%p,%p,%p)\n",This,punk,pszkey,index);
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000509
510 if (punk==NULL)
511 /* search object identified by a register key */
512 for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++){
513
514 if(This->bindCtxTable[i].regType==1){
515
516 if ( ( (This->bindCtxTable[i].pkeyObj==NULL) && (pszkey==NULL) ) ||
517 ( (This->bindCtxTable[i].pkeyObj!=NULL) &&
518 (pszkey!=NULL) &&
519 (lstrcmpW(This->bindCtxTable[i].pkeyObj,pszkey)==0)
520 )
521 )
522
523 found=1;
524 }
525 }
526 else
527 /* search object identified by a moniker*/
528 for(i=0; ( (i<This->bindCtxTableLastIndex) && (!found));i++)
529 if(This->bindCtxTable[i].pObj==punk)
530 found=1;
531
532 if (index != NULL)
533 *index=i-1;
534
535 if (found)
536 return S_OK;
Alberto Massaribb7e49a2003-01-02 17:51:34 +0000537 TRACE("key not found\n");
538 return S_FALSE;
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000539}
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000540
541/******************************************************************************
542 * CreateBindCtx16
543 ******************************************************************************/
Francois Gougetb0c61291999-02-18 13:26:22 +0000544HRESULT WINAPI CreateBindCtx16(DWORD reserved, LPBC * ppbc)
545{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000546 FIXME("(%ld,%p),stub!\n",reserved,ppbc);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000547 return E_NOTIMPL;
548}
549
550/******************************************************************************
Dave Miller47fb9382003-09-11 03:06:25 +0000551 * CreateBindCtx (OLE32.@)
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000552 ******************************************************************************/
Alexandre Julliarda3960291999-02-26 11:11:13 +0000553HRESULT WINAPI CreateBindCtx(DWORD reserved, LPBC * ppbc)
Francois Gougetb0c61291999-02-18 13:26:22 +0000554{
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000555 BindCtxImpl* newBindCtx = 0;
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000556 HRESULT hr;
557 IID riid=IID_IBindCtx;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000558
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000559 TRACE("(%ld,%p)\n",reserved,ppbc);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000560
561 newBindCtx = HeapAlloc(GetProcessHeap(), 0, sizeof(BindCtxImpl));
562
563 if (newBindCtx == 0)
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000564 return E_OUTOFMEMORY;
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000565
566 hr = BindCtxImpl_Construct(newBindCtx);
567
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000568 if (FAILED(hr)){
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000569
Noomen Hamzaed494ec1999-03-23 13:48:56 +0000570 HeapFree(GetProcessHeap(),0,newBindCtx);
571 return hr;
572 }
573
574 hr = BindCtxImpl_QueryInterface((IBindCtx*)newBindCtx,&riid,(void**)ppbc);
Noomen Hamza3fb3da21999-01-28 17:56:14 +0000575
576 return hr;
577}
Robert Shearman26781ac2002-12-12 02:17:39 +0000578
579HRESULT WINAPI BindMoniker(LPMONIKER pmk, DWORD grfOpt, REFIID riid, LPVOID * ppvResult)
580{
581 HRESULT res;
582 IBindCtx * pbc;
583
584 TRACE("(%p, %lx, %s, %p)\n", pmk, grfOpt, debugstr_guid(riid), ppvResult);
585
586 res = CreateBindCtx(grfOpt, &pbc);
587 if (SUCCEEDED(res))
588 res = IMoniker_BindToObject(pmk, pbc, NULL, riid, ppvResult);
589 return res;
590}