Allocate the correct nr of bytes for lpszCookies in HTTP_HttpOpenRequestA.
[wine.git] / dlls / msi / handle.c
blob363c7158950013e966b28d9991e5c9e51b955c4f
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002 Mike McCormack for CodeWeavers
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.
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.
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winreg.h"
26 #include "shlwapi.h"
27 #include "wine/debug.h"
28 #include "msi.h"
29 #include "msiquery.h"
30 #include "msipriv.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msi);
34 MSIHANDLEINFO *msihandletable[MSIMAXHANDLES];
36 MSIHANDLE alloc_msihandle(UINT type, UINT size, msihandledestructor destroy, void **out)
38 MSIHANDLEINFO *info;
39 UINT i;
41 *out = NULL;
43 /* find a slot */
44 for(i=0; i<MSIMAXHANDLES; i++)
45 if( !msihandletable[i] )
46 break;
47 if( (i>=MSIMAXHANDLES) || msihandletable[i] )
48 return 0;
50 size += sizeof (MSIHANDLEINFO);
51 info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
52 if( !info )
53 return 0;
55 info->magic = MSIHANDLE_MAGIC;
56 info->type = type;
57 info->destructor = destroy;
59 msihandletable[i] = info;
60 *out = (void*) &info[1];
62 return (MSIHANDLE) (i+1);
65 void *msihandle2msiinfo(MSIHANDLE handle, UINT type)
67 handle--;
68 if( handle<0 )
69 return NULL;
70 if( handle>=MSIMAXHANDLES )
71 return NULL;
72 if( !msihandletable[handle] )
73 return NULL;
74 if( msihandletable[handle]->magic != MSIHANDLE_MAGIC )
75 return NULL;
76 if( type && (msihandletable[handle]->type != type) )
77 return NULL;
79 return &msihandletable[handle][1];
82 UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
84 MSIHANDLEINFO *info = msihandle2msiinfo(handle, 0);
86 TRACE("%lx\n",handle);
88 if( !info )
89 return ERROR_INVALID_HANDLE;
91 info--;
93 if( info->magic != MSIHANDLE_MAGIC )
95 ERR("Invalid handle!\n");
96 return ERROR_INVALID_HANDLE;
99 if( info->destructor )
100 info->destructor( &info[1] );
102 HeapFree( GetProcessHeap(), 0, info );
103 msihandletable[handle-1] = NULL;
105 TRACE("Destroyed\n");
107 return 0;
110 UINT WINAPI MsiCloseAllHandles(void)
112 UINT i;
114 TRACE("\n");
116 for(i=0; i<MSIMAXHANDLES; i++)
117 MsiCloseHandle( i+1 );
119 return 0;