2003-08-13 01:27:48 +00:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2004-07-09 22:25:34 +00:00
|
|
|
* Copyright 2002-2004 Mike McCormack for CodeWeavers
|
2003-08-13 01:27:48 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-08-13 01:27:48 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
static CRITICAL_SECTION MSI_handle_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG MSI_handle_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &MSI_handle_cs,
|
|
|
|
{ &MSI_handle_cs_debug.ProcessLocksList,
|
|
|
|
&MSI_handle_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": MSI_handle_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSI_handle_cs = { &MSI_handle_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2004-12-27 19:29:33 +00:00
|
|
|
static CRITICAL_SECTION MSI_object_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG MSI_object_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &MSI_object_cs,
|
|
|
|
{ &MSI_object_cs_debug.ProcessLocksList,
|
|
|
|
&MSI_object_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": MSI_object_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSI_object_cs = { &MSI_object_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2005-01-06 20:43:04 +00:00
|
|
|
typedef struct msi_handle_info_t
|
|
|
|
{
|
|
|
|
MSIOBJECTHDR *obj;
|
|
|
|
DWORD dwThreadId;
|
|
|
|
} msi_handle_info;
|
|
|
|
|
|
|
|
static msi_handle_info msihandletable[MSIMAXHANDLES];
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIHANDLE alloc_msihandle( MSIOBJECTHDR *obj )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIHANDLE ret = 0;
|
2003-08-13 01:27:48 +00:00
|
|
|
UINT i;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
2004-03-19 19:14:12 +00:00
|
|
|
|
2003-08-13 01:27:48 +00:00
|
|
|
/* find a slot */
|
|
|
|
for(i=0; i<MSIMAXHANDLES; i++)
|
2005-01-06 20:43:04 +00:00
|
|
|
if( !msihandletable[i].obj )
|
2003-08-13 01:27:48 +00:00
|
|
|
break;
|
2005-01-06 20:43:04 +00:00
|
|
|
if( (i>=MSIMAXHANDLES) || msihandletable[i].obj )
|
2004-07-09 22:25:34 +00:00
|
|
|
goto out;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
msiobj_addref( obj );
|
2005-01-06 20:43:04 +00:00
|
|
|
msihandletable[i].obj = obj;
|
|
|
|
msihandletable[i].dwThreadId = GetCurrentThreadId();
|
2004-07-09 22:25:34 +00:00
|
|
|
ret = (MSIHANDLE) (i+1);
|
|
|
|
out:
|
|
|
|
TRACE("%p -> %ld\n", obj, ret );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
return ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *msihandle2msiinfo(MSIHANDLE handle, UINT type)
|
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIOBJECTHDR *ret = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
2003-08-13 01:27:48 +00:00
|
|
|
handle--;
|
|
|
|
if( handle<0 )
|
2004-07-09 22:25:34 +00:00
|
|
|
goto out;
|
2003-08-13 01:27:48 +00:00
|
|
|
if( handle>=MSIMAXHANDLES )
|
2004-07-09 22:25:34 +00:00
|
|
|
goto out;
|
2005-01-06 20:43:04 +00:00
|
|
|
if( !msihandletable[handle].obj )
|
2004-07-09 22:25:34 +00:00
|
|
|
goto out;
|
2005-01-06 20:43:04 +00:00
|
|
|
if( msihandletable[handle].obj->magic != MSIHANDLE_MAGIC )
|
2004-07-09 22:25:34 +00:00
|
|
|
goto out;
|
2005-01-06 20:43:04 +00:00
|
|
|
if( type && (msihandletable[handle].obj->type != type) )
|
2004-07-09 22:25:34 +00:00
|
|
|
goto out;
|
2005-01-06 20:43:04 +00:00
|
|
|
ret = msihandletable[handle].obj;
|
2004-07-09 22:25:34 +00:00
|
|
|
msiobj_addref( ret );
|
|
|
|
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
|
|
|
|
return (void*) ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSIHANDLE msiobj_findhandle( MSIOBJECTHDR *hdr )
|
|
|
|
{
|
|
|
|
MSIHANDLE ret = 0;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("%p\n", hdr);
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
for(i=0; (i<MSIMAXHANDLES) && !ret; i++)
|
2005-01-06 20:43:04 +00:00
|
|
|
if( msihandletable[i].obj == hdr )
|
2004-07-09 22:25:34 +00:00
|
|
|
ret = i+1;
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
|
|
|
|
TRACE("%p -> %ld\n", hdr, ret);
|
|
|
|
|
|
|
|
msiobj_addref( hdr );
|
|
|
|
return ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy )
|
2004-06-28 20:34:35 +00:00
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIOBJECTHDR *info;
|
2004-06-28 20:34:35 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
|
|
|
|
if( info )
|
|
|
|
{
|
|
|
|
info->magic = MSIHANDLE_MAGIC;
|
|
|
|
info->type = type;
|
|
|
|
info->refcount = 1;
|
|
|
|
info->destructor = destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msiobj_addref( MSIOBJECTHDR *info )
|
|
|
|
{
|
|
|
|
TRACE("%p\n", info);
|
2004-06-28 20:34:35 +00:00
|
|
|
|
|
|
|
if( !info )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( info->magic != MSIHANDLE_MAGIC )
|
|
|
|
{
|
|
|
|
ERR("Invalid handle!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-01-20 20:34:29 +00:00
|
|
|
InterlockedIncrement(&info->refcount);
|
2004-06-28 20:34:35 +00:00
|
|
|
}
|
|
|
|
|
2004-12-27 19:29:33 +00:00
|
|
|
void msiobj_lock( MSIOBJECTHDR *info )
|
|
|
|
{
|
|
|
|
EnterCriticalSection( &MSI_object_cs );
|
|
|
|
}
|
|
|
|
|
|
|
|
void msiobj_unlock( MSIOBJECTHDR *info )
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &MSI_object_cs );
|
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
int msiobj_release( MSIOBJECTHDR *info )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
int ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("%p\n",info);
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( !info )
|
2004-07-09 22:25:34 +00:00
|
|
|
return -1;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( info->magic != MSIHANDLE_MAGIC )
|
|
|
|
{
|
|
|
|
ERR("Invalid handle!\n");
|
2004-07-09 22:25:34 +00:00
|
|
|
return -1;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2005-01-20 20:34:29 +00:00
|
|
|
ret = InterlockedDecrement( &info->refcount );
|
|
|
|
if( ret==0 )
|
2004-07-09 22:25:34 +00:00
|
|
|
{
|
2005-01-20 20:34:29 +00:00
|
|
|
if( info->destructor )
|
2004-07-09 22:25:34 +00:00
|
|
|
info->destructor( info );
|
2005-01-20 20:34:29 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, info );
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("object %p destroyed\n", info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-01-06 20:43:04 +00:00
|
|
|
/***********************************************************
|
|
|
|
* MsiCloseHandle [MSI.@]
|
|
|
|
*/
|
2004-07-09 22:25:34 +00:00
|
|
|
UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
|
|
|
|
{
|
|
|
|
MSIOBJECTHDR *info;
|
|
|
|
UINT ret = ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
TRACE("%lx\n",handle);
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
|
|
|
|
info = msihandle2msiinfo(handle, 0);
|
|
|
|
if( !info )
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if( info->magic != MSIHANDLE_MAGIC )
|
|
|
|
{
|
|
|
|
ERR("Invalid handle!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
msiobj_release( info );
|
2005-01-06 20:43:04 +00:00
|
|
|
msihandletable[handle-1].obj = NULL;
|
2004-07-09 22:25:34 +00:00
|
|
|
ret = ERROR_SUCCESS;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("handle %lx Destroyed\n", handle);
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
if( info )
|
|
|
|
msiobj_release( info );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
return ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2005-01-06 20:43:04 +00:00
|
|
|
/***********************************************************
|
|
|
|
* MsiCloseAllHandles [MSI.@]
|
|
|
|
*
|
|
|
|
* Closes all handles owned by the current thread
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The number of handles closed
|
|
|
|
*/
|
2003-08-13 01:27:48 +00:00
|
|
|
UINT WINAPI MsiCloseAllHandles(void)
|
|
|
|
{
|
2005-01-06 20:43:04 +00:00
|
|
|
UINT i, n=0;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
for(i=0; i<MSIMAXHANDLES; i++)
|
2005-01-06 20:43:04 +00:00
|
|
|
{
|
|
|
|
if(msihandletable[i].dwThreadId == GetCurrentThreadId())
|
|
|
|
{
|
|
|
|
MsiCloseHandle( i+1 );
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2005-01-06 20:43:04 +00:00
|
|
|
return n;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|