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