ReactOS  0.4.14-dev-583-g2a1ba2c
handle.c
Go to the documentation of this file.
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2002-2004 Mike McCormack for CodeWeavers
5  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #define COBJMACROS
22 
23 #include <stdarg.h>
24 
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wine/debug.h"
30 #include "msi.h"
31 #include "msiquery.h"
32 #include "msipriv.h"
33 
35 
38 {
39  0, 0, &MSI_handle_cs,
42  0, 0, { (DWORD_PTR)(__FILE__ ": MSI_handle_cs") }
43 };
44 static CRITICAL_SECTION MSI_handle_cs = { &MSI_handle_cs_debug, -1, 0, 0, 0, 0 };
45 
48 {
49  0, 0, &MSI_object_cs,
52  0, 0, { (DWORD_PTR)(__FILE__ ": MSI_object_cs") }
53 };
54 static CRITICAL_SECTION MSI_object_cs = { &MSI_object_cs_debug, -1, 0, 0, 0, 0 };
55 
56 typedef struct msi_handle_info_t
57 {
59  union {
62  } u;
65 
67 static unsigned int msihandletable_size = 0;
68 
70 {
76 }
77 
79 {
80  UINT i;
81 
82  /* find a slot */
83  for(i=0; i<msihandletable_size; i++)
84  if( !msihandletable[i].u.obj && !msihandletable[i].u.unk )
85  break;
86  if( i==msihandletable_size )
87  {
89  int newsize;
90  if (msihandletable_size == 0)
91  {
92  newsize = 256;
93  p = msi_alloc_zero(newsize*sizeof(msi_handle_info));
94  }
95  else
96  {
97  newsize = msihandletable_size * 2;
99  newsize*sizeof(msi_handle_info));
100  }
101  if (!p)
102  return 0;
103  msihandletable = p;
104  msihandletable_size = newsize;
105  }
106  return i + 1;
107 }
108 
110 {
112  MSIHANDLE ret;
113 
115 
117  if (ret)
118  {
119  entry = &msihandletable[ ret - 1 ];
120  msiobj_addref( obj );
121  entry->u.obj = obj;
122  entry->dwThreadId = GetCurrentThreadId();
123  entry->remote = FALSE;
124  }
125 
127 
128  TRACE("%p -> %d\n", obj, ret );
129 
130  return ret;
131 }
132 
134 {
136  MSIHANDLE ret;
137 
139 
141  if (ret)
142  {
143  entry = &msihandletable[ ret - 1 ];
144  IUnknown_AddRef( unk );
145  entry->u.unk = unk;
146  entry->dwThreadId = GetCurrentThreadId();
147  entry->remote = TRUE;
148  }
149 
151 
152  TRACE("%p -> %d\n", unk, ret);
153 
154  return ret;
155 }
156 
158 {
159  MSIOBJECTHDR *ret = NULL;
160 
162  handle--;
163  if( handle >= msihandletable_size )
164  goto out;
165  if( msihandletable[handle].remote)
166  goto out;
167  if( !msihandletable[handle].u.obj )
168  goto out;
169  if( msihandletable[handle].u.obj->magic != MSIHANDLE_MAGIC )
170  goto out;
171  if( type && (msihandletable[handle].u.obj->type != type) )
172  goto out;
174  msiobj_addref( ret );
175 
176 out:
178 
179  return ret;
180 }
181 
183 {
184  IUnknown *unk = NULL;
185 
187  handle--;
189  goto out;
190  if( !msihandletable[handle].remote)
191  goto out;
192  unk = msihandletable[handle].u.unk;
193  if( unk )
194  IUnknown_AddRef( unk );
195 
196 out:
198 
199  return unk;
200 }
201 
203 {
205 
206  info = msi_alloc_zero( size );
207  if( info )
208  {
209  info->magic = MSIHANDLE_MAGIC;
210  info->type = type;
211  info->refcount = 1;
212  info->destructor = destroy;
213  }
214 
215  return info;
216 }
217 
219 {
220  if( !info )
221  return;
222 
223  if( info->magic != MSIHANDLE_MAGIC )
224  {
225  ERR("Invalid handle!\n");
226  return;
227  }
228 
229  InterlockedIncrement(&info->refcount);
230 }
231 
233 {
235 }
236 
238 {
240 }
241 
243 {
244  int ret;
245 
246  if( !info )
247  return -1;
248 
249  if( info->magic != MSIHANDLE_MAGIC )
250  {
251  ERR("Invalid handle!\n");
252  return -1;
253  }
254 
255  ret = InterlockedDecrement( &info->refcount );
256  if( ret==0 )
257  {
258  if( info->destructor )
259  info->destructor( info );
260  msi_free( info );
261  TRACE("object %p destroyed\n", info);
262  }
263 
264  return ret;
265 }
266 
267 /***********************************************************
268  * MsiCloseHandle [MSI.@]
269  */
271 {
274 
275  TRACE("%x\n",handle);
276 
277  if (!handle)
278  return ERROR_SUCCESS;
279 
281 
282  handle--;
284  goto out;
285 
286  if (msihandletable[handle].remote)
287  {
288  IUnknown_Release( msihandletable[handle].u.unk );
289  }
290  else
291  {
293  if( !info )
294  goto out;
295 
296  if( info->magic != MSIHANDLE_MAGIC )
297  {
298  ERR("Invalid handle!\n");
299  goto out;
300  }
301  }
302 
306 
307  ret = ERROR_SUCCESS;
308 
309  TRACE("handle %x destroyed\n", handle+1);
310 out:
312  if( info )
313  msiobj_release( info );
314 
315  return ret;
316 }
317 
318 /***********************************************************
319  * MsiCloseAllHandles [MSI.@]
320  *
321  * Closes all handles owned by the current thread
322  *
323  * RETURNS:
324  * The number of handles closed
325  */
327 {
328  UINT i, n=0;
329 
330  TRACE("\n");
331 
333  for(i=0; i<msihandletable_size; i++)
334  {
336  {
338  MsiCloseHandle( i+1 );
340  n++;
341  }
342  }
344 
345  return n;
346 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
void msiobj_addref(MSIOBJECTHDR *info)
Definition: handle.c:218
union msi_handle_info_t::@483 u
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
UINT WINAPI MsiCloseAllHandles(void)
Definition: handle.c:326
void msiobj_lock(MSIOBJECTHDR *info)
Definition: handle.c:232
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DWORD_PTR
Definition: treelist.c:76
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
GLdouble n
Definition: glext.h:7729
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
VOID(* msihandledestructor)(MSIOBJECTHDR *)
Definition: msipriv.h:70
unsigned long MSIHANDLE
Definition: msiserver.idl:25
static void * msi_alloc_zero(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1210
GLsizei GLsizei GLuint * obj
Definition: glext.h:6042
struct _test_info info[]
Definition: SetCursorPos.c:19
void msiobj_unlock(MSIOBJECTHDR *info)
Definition: handle.c:237
void * alloc_msiobject(UINT type, UINT size, msihandledestructor destroy)
Definition: handle.c:202
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
WINE_DEFAULT_DEBUG_CHANNEL(msi)
void msi_free_handle_table(void)
Definition: handle.c:69
static msi_handle_info * msihandletable
Definition: handle.c:66
smooth NULL
Definition: ftsmooth.c:416
MSIHANDLE alloc_msi_remote_handle(IUnknown *unk)
Definition: handle.c:133
static CRITICAL_SECTION MSI_object_cs
Definition: handle.c:46
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
static MSIHANDLE alloc_handle_table_entry(void)
Definition: handle.c:78
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define WINAPI
Definition: msvc.h:6
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
int msiobj_release(MSIOBJECTHDR *info)
Definition: handle.c:242
MSIOBJECTHDR * obj
Definition: handle.c:60
int ret
DWORD dwThreadId
Definition: fdebug.c:31
void destroy(_Tp *__pointer)
Definition: _construct.h:278
#define InterlockedDecrement
Definition: armddk.h:52
struct msi_handle_info_t msi_handle_info
uint32_t entry
Definition: isohybrid.c:63
LIST_ENTRY ProcessLocksList
Definition: winbase.h:855
UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
Definition: handle.c:270
#define ERR(fmt,...)
Definition: debug.h:109
IUnknown * unk
Definition: handle.c:61
static CRITICAL_SECTION_DEBUG MSI_object_cs_debug
Definition: handle.c:47
#define InterlockedIncrement
Definition: armddk.h:53
static CRITICAL_SECTION_DEBUG MSI_handle_cs_debug
Definition: handle.c:37
MSIHANDLE alloc_msihandle(MSIOBJECTHDR *obj)
Definition: handle.c:109
unsigned int UINT
Definition: ndis.h:50
static BOOL msi_free(void *mem)
Definition: msipriv.h:1227
static CRITICAL_SECTION MSI_handle_cs
Definition: handle.c:36
#define MSIHANDLE_MAGIC
Definition: msipriv.h:713
IUnknown * msi_get_remote(MSIHANDLE handle)
Definition: handle.c:182
static void * msi_realloc_zero(void *mem, size_t len) __WINE_ALLOC_SIZE(2)
Definition: msipriv.h:1222
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
GLfloat GLfloat p
Definition: glext.h:8902
DWORD dwThreadId
Definition: handle.c:63
void * msihandle2msiinfo(MSIHANDLE handle, UINT type)
Definition: handle.c:157
static unsigned int msihandletable_size
Definition: handle.c:67