Implement MsiModifyView (MSIMODIFY_INSERT_TEMPORARY).
[wine] / dlls / msi / msipriv.h
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2002-2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_MSI_PRIVATE__
22 #define __WINE_MSI_PRIVATE__
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "msi.h"
29 #include "msiquery.h"
30 #include "objbase.h"
31 #include "objidl.h"
32 #include "winnls.h"
33 #include "wine/list.h"
34
35 #define MSI_DATASIZEMASK 0x00ff
36 #define MSITYPE_VALID    0x0100
37 #define MSITYPE_STRING   0x0800
38 #define MSITYPE_NULLABLE 0x1000
39 #define MSITYPE_KEY      0x2000
40
41 #define MSITYPE_BINARY 0x8900
42
43 struct tagMSITABLE;
44 typedef struct tagMSITABLE MSITABLE;
45
46 struct string_table;
47 typedef struct string_table string_table;
48
49 struct tagMSIOBJECTHDR;
50 typedef struct tagMSIOBJECTHDR MSIOBJECTHDR;
51
52 typedef VOID (*msihandledestructor)( MSIOBJECTHDR * );
53
54 struct tagMSIOBJECTHDR
55 {
56     UINT magic;
57     UINT type;
58     LONG refcount;
59     msihandledestructor destructor;
60     struct tagMSIOBJECTHDR *next;
61     struct tagMSIOBJECTHDR *prev;
62 };
63
64 typedef struct tagMSIDATABASE
65 {
66     MSIOBJECTHDR hdr;
67     IStorage *storage;
68     string_table *strings;
69     LPCWSTR mode;
70     MSITABLE *first_table, *last_table;
71 } MSIDATABASE;
72
73 typedef struct tagMSIVIEW MSIVIEW;
74
75 typedef struct tagMSIQUERY
76 {
77     MSIOBJECTHDR hdr;
78     MSIVIEW *view;
79     UINT row;
80     MSIDATABASE *db;
81     struct list mem;
82 } MSIQUERY;
83
84 /* maybe we can use a Variant instead of doing it ourselves? */
85 typedef struct tagMSIFIELD
86 {
87     UINT type;
88     union
89     {
90         INT iVal;
91         LPWSTR szwVal;
92         IStream *stream;
93     } u;
94 } MSIFIELD;
95
96 typedef struct tagMSIRECORD
97 {
98     MSIOBJECTHDR hdr;
99     UINT count;       /* as passed to MsiCreateRecord */
100     MSIFIELD fields[1]; /* nb. array size is count+1 */
101 } MSIRECORD;
102
103 typedef struct tagMSIVIEWOPS
104 {
105     /*
106      * fetch_int - reads one integer from {row,col} in the table
107      *
108      *  This function should be called after the execute method.
109      *  Data returned by the function should not change until 
110      *   close or delete is called.
111      *  To get a string value, query the database's string table with
112      *   the integer value returned from this function.
113      */
114     UINT (*fetch_int)( struct tagMSIVIEW *, UINT row, UINT col, UINT *val );
115
116     /*
117      * fetch_int - reads one integer from {row,col} in the table
118      *
119      *  This function is similar to fetch_int, except fetches a
120      *    stream instead of an integer.
121      */
122     UINT (*fetch_stream)( struct tagMSIVIEW *, UINT row, UINT col, IStream **stm );
123
124     /*
125      * get_int - sets one integer at {row,col} in the table
126      *
127      *  Similar semantics to fetch_int
128      */
129     UINT (*set_int)( struct tagMSIVIEW *, UINT row, UINT col, UINT val );
130
131     /*
132      * Inserts a new row into the database from the records contents
133      */
134     UINT (*insert_row)( struct tagMSIVIEW *, MSIRECORD * );
135
136     /*
137      * execute - loads the underlying data into memory so it can be read
138      */
139     UINT (*execute)( struct tagMSIVIEW *, MSIRECORD * );
140
141     /*
142      * close - clears the data read by execute from memory
143      */
144     UINT (*close)( struct tagMSIVIEW * );
145
146     /*
147      * get_dimensions - returns the number of rows or columns in a table.
148      *
149      *  The number of rows can only be queried after the execute method
150      *   is called. The number of columns can be queried at any time.
151      */
152     UINT (*get_dimensions)( struct tagMSIVIEW *, UINT *rows, UINT *cols );
153
154     /*
155      * get_column_info - returns the name and type of a specific column
156      *
157      *  The name is HeapAlloc'ed by this function and should be freed by
158      *   the caller.
159      *  The column information can be queried at any time.
160      */
161     UINT (*get_column_info)( struct tagMSIVIEW *, UINT n, LPWSTR *name, UINT *type );
162
163     /*
164      * modify - not yet implemented properly
165      */
166     UINT (*modify)( struct tagMSIVIEW *, MSIMODIFY, MSIRECORD * );
167
168     /*
169      * delete - destroys the structure completely
170      */
171     UINT (*delete)( struct tagMSIVIEW * );
172
173 } MSIVIEWOPS;
174
175 struct tagMSIVIEW
176 {
177     MSIOBJECTHDR hdr;
178     MSIVIEWOPS   *ops;
179 };
180
181 struct msi_dialog_tag;
182 typedef struct msi_dialog_tag msi_dialog;
183
184 typedef struct tagMSIPACKAGE
185 {
186     MSIOBJECTHDR hdr;
187     MSIDATABASE *db;
188     struct list components;
189     struct list features;
190     struct list files;
191     struct list folders;
192     LPWSTR ActionFormat;
193     LPWSTR LastAction;
194
195     struct tagMSICLASS *classes;
196     UINT loaded_classes;
197     struct tagMSIEXTENSION *extensions;
198     UINT loaded_extensions;
199     struct tagMSIPROGID *progids;
200     UINT loaded_progids;
201     struct tagMSIVERB *verbs;
202     UINT loaded_verbs;
203     struct tagMSIMIME *mimes;
204     UINT loaded_mimes;
205     struct list appids;
206     
207     struct tagMSISCRIPT *script;
208
209     struct tagMSIRUNNINGACTION *RunningAction;
210     UINT RunningActionCount;
211
212     LPWSTR PackagePath;
213     LPWSTR msiFilePath;
214     LPWSTR ProductCode;
215
216     UINT CurrentInstallState;
217     msi_dialog *dialog;
218     LPWSTR next_dialog;
219     
220     struct list subscriptions;
221 } MSIPACKAGE;
222
223 typedef struct tagMSIPREVIEW
224 {
225     MSIOBJECTHDR hdr;
226     MSIPACKAGE *package;
227     msi_dialog *dialog;
228 } MSIPREVIEW;
229
230 #define MSIHANDLETYPE_ANY 0
231 #define MSIHANDLETYPE_DATABASE 1
232 #define MSIHANDLETYPE_SUMMARYINFO 2
233 #define MSIHANDLETYPE_VIEW 3
234 #define MSIHANDLETYPE_RECORD 4
235 #define MSIHANDLETYPE_PACKAGE 5
236 #define MSIHANDLETYPE_PREVIEW 6
237
238 #define MSI_MAJORVERSION 2
239 #define MSI_MINORVERSION 0
240 #define MSI_BUILDNUMBER 2600
241
242 #define GUID_SIZE 39
243
244 #define MSIHANDLE_MAGIC 0x4d434923
245 #define MSIMAXHANDLES 0xf0
246
247 #define MSISUMINFO_OFFSET 0x30LL
248
249 DEFINE_GUID(CLSID_IMsiServer,   0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
250 DEFINE_GUID(CLSID_IMsiServerX1, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
251 DEFINE_GUID(CLSID_IMsiServerX2, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
252 DEFINE_GUID(CLSID_IMsiServerX3, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
253
254 DEFINE_GUID(CLSID_IMsiServerMessage, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
255
256
257 /* handle functions */
258 extern void *msihandle2msiinfo(MSIHANDLE handle, UINT type);
259 extern MSIHANDLE alloc_msihandle( MSIOBJECTHDR * );
260 extern void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy );
261 extern void msiobj_addref(MSIOBJECTHDR *);
262 extern int msiobj_release(MSIOBJECTHDR *);
263 extern void msiobj_lock(MSIOBJECTHDR *);
264 extern void msiobj_unlock(MSIOBJECTHDR *);
265 extern MSIHANDLE msiobj_findhandle( MSIOBJECTHDR *hdr );
266
267 /* add this table to the list of cached tables in the database */
268 extern void add_table(MSIDATABASE *db, MSITABLE *table);
269 extern void remove_table( MSIDATABASE *db, MSITABLE *table );
270 extern void free_table( MSIDATABASE *db, MSITABLE *table );
271 extern void free_cached_tables( MSIDATABASE *db );
272 extern UINT find_cached_table(MSIDATABASE *db, LPCWSTR name, MSITABLE **table);
273 extern UINT get_table(MSIDATABASE *db, LPCWSTR name, MSITABLE **table);
274 extern UINT load_string_table( MSIDATABASE *db );
275 extern UINT MSI_CommitTables( MSIDATABASE *db );
276 extern HRESULT init_string_table( IStorage *stg );
277
278
279 /* string table functions */
280 extern BOOL msi_addstring( string_table *st, UINT string_no, const CHAR *data, int len, UINT refcount );
281 extern BOOL msi_addstringW( string_table *st, UINT string_no, const WCHAR *data, int len, UINT refcount );
282 extern UINT msi_id2stringW( string_table *st, UINT string_no, LPWSTR buffer, UINT *sz );
283 extern UINT msi_id2stringA( string_table *st, UINT string_no, LPSTR buffer, UINT *sz );
284
285 extern LPWSTR MSI_makestring( MSIDATABASE *db, UINT stringid);
286 extern UINT msi_string2idW( string_table *st, LPCWSTR buffer, UINT *id );
287 extern UINT msi_string2idA( string_table *st, LPCSTR str, UINT *id );
288 extern string_table *msi_init_stringtable( int entries, UINT codepage );
289 extern VOID msi_destroy_stringtable( string_table *st );
290 extern UINT msi_string_count( string_table *st );
291 extern UINT msi_id_refcount( string_table *st, UINT i );
292 extern UINT msi_string_totalsize( string_table *st, UINT *last );
293 extern UINT msi_strcmp( string_table *st, UINT lval, UINT rval, UINT *res );
294 extern const WCHAR *msi_string_lookup_id( string_table *st, UINT id );
295 extern UINT msi_string_get_codepage( string_table *st );
296
297
298 extern UINT VIEW_find_column( MSIVIEW *view, LPCWSTR name, UINT *n );
299
300 extern BOOL TABLE_Exists( MSIDATABASE *db, LPWSTR name );
301
302 extern UINT read_raw_stream_data( MSIDATABASE*, LPCWSTR stname,
303                               USHORT **pdata, UINT *psz );
304
305 /* action internals */
306 extern UINT ACTION_DoTopLevelINSTALL( MSIPACKAGE *, LPCWSTR, LPCWSTR, LPCWSTR );
307 extern void ACTION_free_package_structures( MSIPACKAGE* );
308 extern UINT ACTION_DialogBox( MSIPACKAGE*, LPCWSTR);
309
310 /* record internals */
311 extern UINT MSI_RecordSetIStream( MSIRECORD *, unsigned int, IStream *);
312 extern UINT MSI_RecordGetIStream( MSIRECORD *, unsigned int, IStream **);
313 extern const WCHAR *MSI_RecordGetString( MSIRECORD *, unsigned int );
314 extern MSIRECORD *MSI_CreateRecord( unsigned int );
315 extern UINT MSI_RecordSetInteger( MSIRECORD *, unsigned int, int );
316 extern UINT MSI_RecordSetStringW( MSIRECORD *, unsigned int, LPCWSTR );
317 extern UINT MSI_RecordSetStringA( MSIRECORD *, unsigned int, LPCSTR );
318 extern BOOL MSI_RecordIsNull( MSIRECORD *, unsigned int );
319 extern UINT MSI_RecordGetStringW( MSIRECORD * , unsigned int, LPWSTR, DWORD *);
320 extern UINT MSI_RecordGetStringA( MSIRECORD *, unsigned int, LPSTR, DWORD *);
321 extern int MSI_RecordGetInteger( MSIRECORD *, unsigned int );
322 extern UINT MSI_RecordReadStream( MSIRECORD *, unsigned int, char *, DWORD *);
323 extern unsigned int MSI_RecordGetFieldCount( MSIRECORD *rec );
324 extern UINT MSI_RecordSetStreamW( MSIRECORD *, unsigned int, LPCWSTR );
325 extern UINT MSI_RecordSetStreamA( MSIRECORD *, unsigned int, LPCSTR );
326 extern UINT MSI_RecordDataSize( MSIRECORD *, unsigned int );
327 extern UINT MSI_RecordStreamToFile( MSIRECORD *, unsigned int, LPCWSTR );
328
329 /* stream internals */
330 extern UINT get_raw_stream( MSIHANDLE hdb, LPCWSTR stname, IStream **stm );
331 extern UINT db_get_raw_stream( MSIDATABASE *db, LPCWSTR stname, IStream **stm );
332 extern void enum_stream_names( IStorage *stg );
333
334 /* database internals */
335 extern UINT MSI_OpenDatabaseW( LPCWSTR, LPCWSTR, MSIDATABASE ** );
336 extern UINT MSI_DatabaseOpenViewW(MSIDATABASE *, LPCWSTR, MSIQUERY ** );
337 extern UINT MSI_OpenQuery( MSIDATABASE *, MSIQUERY **, LPCWSTR, ... );
338 typedef UINT (*record_func)( MSIRECORD *, LPVOID );
339 extern UINT MSI_IterateRecords( MSIQUERY *, DWORD *, record_func, LPVOID );
340 extern MSIRECORD *MSI_QueryGetRecord( MSIDATABASE *db, LPCWSTR query, ... );
341 extern UINT MSI_DatabaseImport( MSIDATABASE *, LPCWSTR, LPCWSTR );
342 extern UINT MSI_DatabaseExport( MSIDATABASE *, LPCWSTR, LPCWSTR, LPCWSTR );
343 extern UINT MSI_DatabaseGetPrimaryKeys( MSIDATABASE *, LPCWSTR, MSIRECORD ** );
344
345 /* view internals */
346 extern UINT MSI_ViewExecute( MSIQUERY*, MSIRECORD * );
347 extern UINT MSI_ViewFetch( MSIQUERY*, MSIRECORD ** );
348 extern UINT MSI_ViewClose( MSIQUERY* );
349
350 /* package internals */
351 extern MSIPACKAGE *MSI_CreatePackage( MSIDATABASE * );
352 extern UINT MSI_OpenPackageW( LPCWSTR szPackage, MSIPACKAGE ** );
353 extern UINT MSI_SetTargetPathW( MSIPACKAGE *, LPCWSTR, LPCWSTR );
354 extern UINT MSI_SetPropertyW( MSIPACKAGE *, LPCWSTR, LPCWSTR );
355 extern INT MSI_ProcessMessage( MSIPACKAGE *, INSTALLMESSAGE, MSIRECORD * );
356 extern UINT MSI_GetPropertyW( MSIPACKAGE *, LPCWSTR, LPWSTR, DWORD * );
357 extern UINT MSI_GetPropertyA(MSIPACKAGE *, LPCSTR, LPSTR, DWORD* );
358 extern MSICONDITION MSI_EvaluateConditionW( MSIPACKAGE *, LPCWSTR );
359 extern UINT MSI_GetComponentStateW( MSIPACKAGE *, LPWSTR, INSTALLSTATE *, INSTALLSTATE * );
360 extern UINT MSI_GetFeatureStateW( MSIPACKAGE *, LPWSTR, INSTALLSTATE *, INSTALLSTATE * );
361 extern UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE*, LPCWSTR, INSTALLSTATE );
362
363 /* for deformating */
364 extern UINT MSI_FormatRecordW( MSIPACKAGE *, MSIRECORD *, LPWSTR, DWORD * );
365 extern UINT MSI_FormatRecordA( MSIPACKAGE *, MSIRECORD *, LPSTR, DWORD * );
366     
367 /* registry data encoding/decoding functions */
368 extern BOOL unsquash_guid(LPCWSTR in, LPWSTR out);
369 extern BOOL squash_guid(LPCWSTR in, LPWSTR out);
370 extern BOOL encode_base85_guid(GUID *,LPWSTR);
371 extern BOOL decode_base85_guid(LPCWSTR,GUID*);
372 extern UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create);
373 extern UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create);
374 extern UINT MSIREG_OpenFeatures(HKEY* key);
375 extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
376 extern UINT MSIREG_OpenComponents(HKEY* key);
377 extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
378 extern UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
379 extern UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create);
380 extern UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
381 extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
382 extern UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
383 extern UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
384
385 /* msi dialog interface */
386 typedef UINT (*msi_dialog_event_handler)( MSIPACKAGE*, LPCWSTR, LPCWSTR, msi_dialog* );
387 extern msi_dialog *msi_dialog_create( MSIPACKAGE*, LPCWSTR, msi_dialog_event_handler );
388 extern UINT msi_dialog_run_message_loop( msi_dialog* );
389 extern void msi_dialog_end_dialog( msi_dialog* );
390 extern void msi_dialog_check_messages( HANDLE );
391 extern void msi_dialog_do_preview( msi_dialog* );
392 extern void msi_dialog_destroy( msi_dialog* );
393 extern BOOL msi_dialog_register_class( void );
394 extern void msi_dialog_unregister_class( void );
395 extern void msi_dialog_handle_event( msi_dialog*, LPCWSTR, LPCWSTR, MSIRECORD * );
396
397 /* preview */
398 extern MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE * );
399 extern UINT MSI_PreviewDialogW( MSIPREVIEW *, LPCWSTR );
400
401 /* undocumented functions */
402 UINT WINAPI MsiCreateAndVerifyInstallerDirectory( DWORD );
403 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR, LPWSTR, LPWSTR, LPWSTR, DWORD * );
404 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR, LPSTR, LPSTR, LPSTR, DWORD * );
405 LANGID WINAPI MsiLoadStringW( MSIHANDLE, UINT, LPWSTR, int, LANGID );
406 LANGID WINAPI MsiLoadStringA( MSIHANDLE, UINT, LPSTR, int, LANGID );
407
408 /* UI globals */
409 extern INSTALLUILEVEL gUILevel;
410 extern HWND gUIhwnd;
411 extern INSTALLUI_HANDLERA gUIHandlerA;
412 extern INSTALLUI_HANDLERW gUIHandlerW;
413 extern DWORD gUIFilter;
414 extern LPVOID gUIContext;
415 extern WCHAR gszLogFile[MAX_PATH];
416
417 inline static char *strdupWtoA( LPCWSTR str )
418 {
419     LPSTR ret = NULL;
420     if (str)
421     {
422         DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
423 );
424         if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
425             WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
426     }
427     return ret;
428 }
429
430 inline static LPWSTR strdupAtoW( LPCSTR str )
431 {
432     LPWSTR ret = NULL;
433     if (str)
434     {
435         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
436         if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
437             MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
438     }
439     return ret;
440 }
441
442 inline static LPWSTR strdupW( LPCWSTR src )
443 {
444     LPWSTR dest;
445     if (!src) return NULL;
446     dest = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(src)+1)*sizeof(WCHAR));
447     lstrcpyW(dest, src);
448     return dest;
449 }
450
451 #endif /* __WINE_MSI_PRIVATE__ */