msi: Implement reference counting for tables, manipulated with the HOLD and FREE...
[wine] / dlls / msi / msipriv.h
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2002-2005 Mike McCormack for CodeWeavers
5  * Copyright 2005 Aric Stewart for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #ifndef __WINE_MSI_PRIVATE__
23 #define __WINE_MSI_PRIVATE__
24
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "msi.h"
30 #include "msiquery.h"
31 #include "objbase.h"
32 #include "objidl.h"
33 #include "winnls.h"
34 #include "wine/list.h"
35
36 #define MSI_DATASIZEMASK 0x00ff
37 #define MSITYPE_VALID    0x0100
38 #define MSITYPE_LOCALIZABLE 0x200
39 #define MSITYPE_STRING   0x0800
40 #define MSITYPE_NULLABLE 0x1000
41 #define MSITYPE_KEY      0x2000
42
43 /* Word Count masks */
44 #define MSIWORDCOUNT_SHORTFILENAMES     0x0001
45 #define MSIWORDCOUNT_COMPRESSED         0x0002
46 #define MSIWORDCOUNT_ADMINISTRATIVE     0x0004
47 #define MSIWORDCOUNT_PRIVILEGES         0x0008
48
49 /* Install UI level mask for AND operation to exclude flags */
50 #define INSTALLUILEVEL_MASK             0x0007
51
52 #define MSITYPE_IS_BINARY(type) (((type) & ~MSITYPE_NULLABLE) == (MSITYPE_STRING|MSITYPE_VALID))
53
54 struct tagMSITABLE;
55 typedef struct tagMSITABLE MSITABLE;
56
57 struct string_table;
58 typedef struct string_table string_table;
59
60 struct tagMSIOBJECTHDR;
61 typedef struct tagMSIOBJECTHDR MSIOBJECTHDR;
62
63 typedef VOID (*msihandledestructor)( MSIOBJECTHDR * );
64
65 struct tagMSIOBJECTHDR
66 {
67     UINT magic;
68     UINT type;
69     LONG refcount;
70     msihandledestructor destructor;
71 };
72
73 typedef struct tagMSIDATABASE
74 {
75     MSIOBJECTHDR hdr;
76     IStorage *storage;
77     string_table *strings;
78     UINT bytes_per_strref;
79     LPWSTR path;
80     LPWSTR deletefile;
81     LPCWSTR mode;
82     struct list tables;
83     struct list transforms;
84 } MSIDATABASE;
85
86 typedef struct tagMSIVIEW MSIVIEW;
87
88 typedef struct tagMSIQUERY
89 {
90     MSIOBJECTHDR hdr;
91     MSIVIEW *view;
92     UINT row;
93     MSIDATABASE *db;
94     struct list mem;
95 } MSIQUERY;
96
97 /* maybe we can use a Variant instead of doing it ourselves? */
98 typedef struct tagMSIFIELD
99 {
100     UINT type;
101     union
102     {
103         INT iVal;
104         LPWSTR szwVal;
105         IStream *stream;
106     } u;
107 } MSIFIELD;
108
109 typedef struct tagMSIRECORD
110 {
111     MSIOBJECTHDR hdr;
112     UINT count;       /* as passed to MsiCreateRecord */
113     MSIFIELD fields[1]; /* nb. array size is count+1 */
114 } MSIRECORD;
115
116 typedef struct tagMSISOURCELISTINFO
117 {
118     struct list entry;
119     DWORD context;
120     DWORD options;
121     LPCWSTR property;
122     LPWSTR value;
123 } MSISOURCELISTINFO;
124
125 typedef struct tagMSIMEDIADISK
126 {
127     struct list entry;
128     DWORD context;
129     DWORD options;
130     DWORD disk_id;
131     LPWSTR volume_label;
132     LPWSTR disk_prompt;
133 } MSIMEDIADISK;
134
135 typedef const struct tagMSICOLUMNHASHENTRY *MSIITERHANDLE;
136
137 typedef struct tagMSIVIEWOPS
138 {
139     /*
140      * fetch_int - reads one integer from {row,col} in the table
141      *
142      *  This function should be called after the execute method.
143      *  Data returned by the function should not change until
144      *   close or delete is called.
145      *  To get a string value, query the database's string table with
146      *   the integer value returned from this function.
147      */
148     UINT (*fetch_int)( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val );
149
150     /*
151      * fetch_stream - gets a stream from {row,col} in the table
152      *
153      *  This function is similar to fetch_int, except fetches a
154      *    stream instead of an integer.
155      */
156     UINT (*fetch_stream)( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm );
157
158     /*
159      * set_row - sets values in a row as specified by mask
160      *
161      *  Similar semantics to fetch_int
162      */
163     UINT (*set_row)( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask );
164
165     /*
166      * Inserts a new row into the database from the records contents
167      */
168     UINT (*insert_row)( struct tagMSIVIEW *view, MSIRECORD *record, BOOL temporary );
169
170     /*
171      * Deletes a row from the database
172      */
173     UINT (*delete_row)( struct tagMSIVIEW *view, UINT row );
174
175     /*
176      * execute - loads the underlying data into memory so it can be read
177      */
178     UINT (*execute)( struct tagMSIVIEW *view, MSIRECORD *record );
179
180     /*
181      * close - clears the data read by execute from memory
182      */
183     UINT (*close)( struct tagMSIVIEW *view );
184
185     /*
186      * get_dimensions - returns the number of rows or columns in a table.
187      *
188      *  The number of rows can only be queried after the execute method
189      *   is called. The number of columns can be queried at any time.
190      */
191     UINT (*get_dimensions)( struct tagMSIVIEW *view, UINT *rows, UINT *cols );
192
193     /*
194      * get_column_info - returns the name and type of a specific column
195      *
196      *  The name is HeapAlloc'ed by this function and should be freed by
197      *   the caller.
198      *  The column information can be queried at any time.
199      */
200     UINT (*get_column_info)( struct tagMSIVIEW *view, UINT n, LPWSTR *name, UINT *type );
201
202     /*
203      * modify - not yet implemented properly
204      */
205     UINT (*modify)( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *record );
206
207     /*
208      * delete - destroys the structure completely
209      */
210     UINT (*delete)( struct tagMSIVIEW * );
211
212     /*
213      * find_matching_rows - iterates through rows that match a value
214      *
215      * If the column type is a string then a string ID should be passed in.
216      *  If the value to be looked up is an integer then no transformation of
217      *  the input value is required, except if the column is a string, in which
218      *  case a string ID should be passed in.
219      * The handle is an input/output parameter that keeps track of the current
220      *  position in the iteration. It must be initialised to zero before the
221      *  first call and continued to be passed in to subsequent calls.
222      */
223     UINT (*find_matching_rows)( struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle );
224
225     /*
226      * add_ref - increases the reference count of the table
227      */
228     UINT (*add_ref)( struct tagMSIVIEW *view );
229
230     /*
231      * release - decreases the reference count of the table
232      */
233     UINT (*release)( struct tagMSIVIEW *view );
234 } MSIVIEWOPS;
235
236 struct tagMSIVIEW
237 {
238     MSIOBJECTHDR hdr;
239     const MSIVIEWOPS *ops;
240 };
241
242 struct msi_dialog_tag;
243 typedef struct msi_dialog_tag msi_dialog;
244
245 typedef struct tagMSIPACKAGE
246 {
247     MSIOBJECTHDR hdr;
248     MSIDATABASE *db;
249     struct list components;
250     struct list features;
251     struct list files;
252     struct list tempfiles;
253     struct list folders;
254     LPWSTR ActionFormat;
255     LPWSTR LastAction;
256
257     struct list classes;
258     struct list extensions;
259     struct list progids;
260     struct list mimes;
261     struct list appids;
262
263     struct tagMSISCRIPT *script;
264
265     struct list RunningActions;
266
267     LPWSTR BaseURL;
268     LPWSTR PackagePath;
269     LPWSTR ProductCode;
270
271     UINT CurrentInstallState;
272     msi_dialog *dialog;
273     LPWSTR next_dialog;
274     float center_x;
275     float center_y;
276
277     UINT WordCount;
278
279     struct list subscriptions;
280
281     struct list sourcelist_info;
282     struct list sourcelist_media;
283
284     unsigned char scheduled_action_running : 1;
285     unsigned char commit_action_running : 1;
286     unsigned char rollback_action_running : 1;
287 } MSIPACKAGE;
288
289 typedef struct tagMSIPREVIEW
290 {
291     MSIOBJECTHDR hdr;
292     MSIPACKAGE *package;
293     msi_dialog *dialog;
294 } MSIPREVIEW;
295
296 #define MSI_MAX_PROPS 20
297
298 typedef struct tagMSISUMMARYINFO
299 {
300     MSIOBJECTHDR hdr;
301     IStorage *storage;
302     DWORD update_count;
303     PROPVARIANT property[MSI_MAX_PROPS];
304 } MSISUMMARYINFO;
305
306 typedef struct tagMSIFEATURE
307 {
308     struct list entry;
309     LPWSTR Feature;
310     LPWSTR Feature_Parent;
311     LPWSTR Title;
312     LPWSTR Description;
313     INT Display;
314     INT Level;
315     LPWSTR Directory;
316     INT Attributes;
317     INSTALLSTATE Installed;
318     INSTALLSTATE ActionRequest;
319     INSTALLSTATE Action;
320     struct list Children;
321     struct list Components;
322     INT Cost;
323 } MSIFEATURE;
324
325 typedef struct tagMSICOMPONENT
326 {
327     struct list entry;
328     DWORD magic;
329     LPWSTR Component;
330     LPWSTR ComponentId;
331     LPWSTR Directory;
332     INT Attributes;
333     LPWSTR Condition;
334     LPWSTR KeyPath;
335     INSTALLSTATE Installed;
336     INSTALLSTATE ActionRequest;
337     INSTALLSTATE Action;
338     BOOL ForceLocalState;
339     BOOL Enabled;
340     INT  Cost;
341     INT  RefCount;
342     LPWSTR FullKeypath;
343     LPWSTR AdvertiseString;
344
345     unsigned int hasAdvertiseFeature:1;
346     unsigned int hasLocalFeature:1;
347     unsigned int hasSourceFeature:1;
348 } MSICOMPONENT;
349
350 typedef struct tagComponentList
351 {
352     struct list entry;
353     MSICOMPONENT *component;
354 } ComponentList;
355
356 typedef struct tagFeatureList
357 {
358     struct list entry;
359     MSIFEATURE *feature;
360 } FeatureList;
361
362 typedef struct tagMSIFOLDER
363 {
364     struct list entry;
365     LPWSTR Directory;
366     LPWSTR Parent;
367     LPWSTR TargetDefault;
368     LPWSTR SourceLongPath;
369     LPWSTR SourceShortPath;
370
371     LPWSTR ResolvedTarget;
372     LPWSTR ResolvedSource;
373     LPWSTR Property;   /* initially set property */
374     INT   State;
375         /* 0 = uninitialized */
376         /* 1 = existing */
377         /* 2 = created remove if empty */
378         /* 3 = created persist if empty */
379     INT   Cost;
380     INT   Space;
381 } MSIFOLDER;
382
383 typedef enum _msi_file_state {
384     msifs_invalid,
385     msifs_missing,
386     msifs_overwrite,
387     msifs_present,
388     msifs_installed,
389     msifs_skipped,
390 } msi_file_state;
391
392 typedef struct tagMSIFILE
393 {
394     struct list entry;
395     LPWSTR File;
396     MSICOMPONENT *Component;
397     LPWSTR FileName;
398     LPWSTR ShortName;
399     LPWSTR LongName;
400     INT FileSize;
401     LPWSTR Version;
402     LPWSTR Language;
403     INT Attributes;
404     INT Sequence;
405     msi_file_state state;
406     LPWSTR  SourcePath;
407     LPWSTR  TargetPath;
408     BOOL IsCompressed;
409 } MSIFILE;
410
411 typedef struct tagMSITEMPFILE
412 {
413     struct list entry;
414     LPWSTR Path;
415 } MSITEMPFILE;
416
417 typedef struct tagMSIAPPID
418 {
419     struct list entry;
420     LPWSTR AppID; /* Primary key */
421     LPWSTR RemoteServerName;
422     LPWSTR LocalServer;
423     LPWSTR ServiceParameters;
424     LPWSTR DllSurrogate;
425     BOOL ActivateAtStorage;
426     BOOL RunAsInteractiveUser;
427 } MSIAPPID;
428
429 typedef struct tagMSIPROGID MSIPROGID;
430
431 typedef struct tagMSICLASS
432 {
433     struct list entry;
434     LPWSTR clsid;     /* Primary Key */
435     LPWSTR Context;   /* Primary Key */
436     MSICOMPONENT *Component;
437     MSIPROGID *ProgID;
438     LPWSTR ProgIDText;
439     LPWSTR Description;
440     MSIAPPID *AppID;
441     LPWSTR FileTypeMask;
442     LPWSTR IconPath;
443     LPWSTR DefInprocHandler;
444     LPWSTR DefInprocHandler32;
445     LPWSTR Argument;
446     MSIFEATURE *Feature;
447     INT Attributes;
448     /* not in the table, set during installation */
449     BOOL Installed;
450 } MSICLASS;
451
452 typedef struct tagMSIMIME MSIMIME;
453
454 typedef struct tagMSIEXTENSION
455 {
456     struct list entry;
457     LPWSTR Extension;  /* Primary Key */
458     MSICOMPONENT *Component;
459     MSIPROGID *ProgID;
460     LPWSTR ProgIDText;
461     MSIMIME *Mime;
462     MSIFEATURE *Feature;
463     /* not in the table, set during installation */
464     BOOL Installed;
465     struct list verbs;
466 } MSIEXTENSION;
467
468 struct tagMSIPROGID
469 {
470     struct list entry;
471     LPWSTR ProgID;  /* Primary Key */
472     MSIPROGID *Parent;
473     MSICLASS *Class;
474     LPWSTR Description;
475     LPWSTR IconPath;
476     /* not in the table, set during installation */
477     BOOL InstallMe;
478     MSIPROGID *CurVer;
479     MSIPROGID *VersionInd;
480 };
481
482 typedef struct tagMSIVERB
483 {
484     struct list entry;
485     LPWSTR Verb;
486     INT Sequence;
487     LPWSTR Command;
488     LPWSTR Argument;
489 } MSIVERB;
490
491 struct tagMSIMIME
492 {
493     struct list entry;
494     LPWSTR ContentType;  /* Primary Key */
495     MSIEXTENSION *Extension;
496     LPWSTR clsid;
497     MSICLASS *Class;
498     /* not in the table, set during installation */
499     BOOL InstallMe;
500 };
501
502 enum SCRIPTS {
503     INSTALL_SCRIPT = 0,
504     COMMIT_SCRIPT = 1,
505     ROLLBACK_SCRIPT = 2,
506     TOTAL_SCRIPTS = 3
507 };
508
509 #define SEQUENCE_UI       0x1
510 #define SEQUENCE_EXEC     0x2
511 #define SEQUENCE_INSTALL  0x10
512
513 typedef struct tagMSISCRIPT
514 {
515     LPWSTR  *Actions[TOTAL_SCRIPTS];
516     UINT    ActionCount[TOTAL_SCRIPTS];
517     BOOL    ExecuteSequenceRun;
518     BOOL    CurrentlyScripting;
519     UINT    InWhatSequence;
520     LPWSTR  *UniqueActions;
521     UINT    UniqueActionsCount;
522 } MSISCRIPT;
523
524 #define MSIHANDLETYPE_ANY 0
525 #define MSIHANDLETYPE_DATABASE 1
526 #define MSIHANDLETYPE_SUMMARYINFO 2
527 #define MSIHANDLETYPE_VIEW 3
528 #define MSIHANDLETYPE_RECORD 4
529 #define MSIHANDLETYPE_PACKAGE 5
530 #define MSIHANDLETYPE_PREVIEW 6
531
532 #define MSI_MAJORVERSION 3
533 #define MSI_MINORVERSION 1
534 #define MSI_BUILDNUMBER 4000
535
536 #define GUID_SIZE 39
537
538 #define MSIHANDLE_MAGIC 0x4d434923
539
540 DEFINE_GUID(CLSID_IMsiServer,   0x000C101C,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
541 DEFINE_GUID(CLSID_IMsiServerX1, 0x000C103E,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
542 DEFINE_GUID(CLSID_IMsiServerX2, 0x000C1090,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
543 DEFINE_GUID(CLSID_IMsiServerX3, 0x000C1094,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
544
545 DEFINE_GUID(CLSID_IMsiServerMessage, 0x000C101D,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
546
547 DEFINE_GUID(CLSID_IWineMsiRemoteCustomAction,0xBA26E6FA,0x4F27,0x4f56,0x95,0x3A,0x3F,0x90,0x27,0x20,0x18,0xAA);
548 DEFINE_GUID(CLSID_IWineMsiRemotePackage,0x902b3592,0x9d08,0x4dfd,0xa5,0x93,0xd0,0x7c,0x52,0x54,0x64,0x21);
549
550 /* handle unicode/ascii output in the Msi* API functions */
551 typedef struct {
552     BOOL unicode;
553     union {
554        LPSTR a;
555        LPWSTR w;
556     } str;
557 } awstring;
558
559 typedef struct {
560     BOOL unicode;
561     union {
562        LPCSTR a;
563        LPCWSTR w;
564     } str;
565 } awcstring;
566
567 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz );
568
569 /* msi server interface */
570 extern ITypeLib *get_msi_typelib( LPWSTR *path );
571 extern HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj );
572 extern HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj );
573 extern IUnknown *msi_get_remote(MSIHANDLE handle);
574
575 /* handle functions */
576 extern void *msihandle2msiinfo(MSIHANDLE handle, UINT type);
577 extern MSIHANDLE alloc_msihandle( MSIOBJECTHDR * );
578 extern MSIHANDLE alloc_msi_remote_handle( IUnknown *unk );
579 extern void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy );
580 extern void msiobj_addref(MSIOBJECTHDR *);
581 extern int msiobj_release(MSIOBJECTHDR *);
582 extern void msiobj_lock(MSIOBJECTHDR *);
583 extern void msiobj_unlock(MSIOBJECTHDR *);
584 extern void msi_free_handle_table(void);
585
586 extern void free_cached_tables( MSIDATABASE *db );
587 extern void msi_free_transforms( MSIDATABASE *db );
588 extern UINT MSI_CommitTables( MSIDATABASE *db );
589
590
591 /* string table functions */
592 enum StringPersistence
593 {
594     StringPersistent = 0,
595     StringNonPersistent = 1
596 };
597
598 extern BOOL msi_addstringW( string_table *st, UINT string_no, const WCHAR *data, int len, UINT refcount, enum StringPersistence persistence );
599 extern UINT msi_id2stringW( const string_table *st, UINT string_no, LPWSTR buffer, UINT *sz );
600 extern UINT msi_id2stringA( const string_table *st, UINT string_no, LPSTR buffer, UINT *sz );
601
602 extern UINT msi_string2idW( const string_table *st, LPCWSTR buffer, UINT *id );
603 extern UINT msi_string2idA( const string_table *st, LPCSTR str, UINT *id );
604 extern VOID msi_destroy_stringtable( string_table *st );
605 extern UINT msi_strcmp( const string_table *st, UINT lval, UINT rval, UINT *res );
606 extern const WCHAR *msi_string_lookup_id( const string_table *st, UINT id );
607 extern HRESULT msi_init_string_table( IStorage *stg );
608 extern string_table *msi_load_string_table( IStorage *stg, UINT *bytes_per_strref );
609 extern UINT msi_save_string_table( const string_table *st, IStorage *storage );
610
611
612 extern void msi_table_set_strref(UINT bytes_per_strref);
613 extern BOOL TABLE_Exists( MSIDATABASE *db, LPCWSTR name );
614 extern MSICONDITION MSI_DatabaseIsTablePersistent( MSIDATABASE *db, LPCWSTR table );
615
616 extern UINT read_raw_stream_data( MSIDATABASE *db, LPCWSTR stname,
617                                   USHORT **pdata, UINT *psz );
618 extern UINT read_stream_data( IStorage *stg, LPCWSTR stname, BOOL table,
619                               BYTE **pdata, UINT *psz );
620 extern UINT write_stream_data( IStorage *stg, LPCWSTR stname,
621                                LPCVOID data, UINT sz, BOOL bTable );
622
623 /* transform functions */
624 extern UINT msi_table_apply_transform( MSIDATABASE *db, IStorage *stg );
625 extern UINT MSI_DatabaseApplyTransformW( MSIDATABASE *db,
626                  LPCWSTR szTransformFile, int iErrorCond );
627 extern void append_storage_to_db( MSIDATABASE *db, IStorage *stg );
628
629 /* action internals */
630 extern UINT MSI_InstallPackage( MSIPACKAGE *, LPCWSTR, LPCWSTR );
631 extern void ACTION_free_package_structures( MSIPACKAGE* );
632 extern UINT ACTION_DialogBox( MSIPACKAGE*, LPCWSTR);
633 extern UINT ACTION_ForceReboot(MSIPACKAGE *package);
634 extern UINT MSI_Sequence( MSIPACKAGE *package, LPCWSTR szTable, INT iSequenceMode );
635 extern UINT MSI_SetFeatureStates( MSIPACKAGE *package );
636 extern UINT msi_parse_command_line( MSIPACKAGE *package, LPCWSTR szCommandLine );
637
638 /* record internals */
639 extern UINT MSI_RecordSetIStream( MSIRECORD *, unsigned int, IStream *);
640 extern UINT MSI_RecordGetIStream( MSIRECORD *, unsigned int, IStream **);
641 extern const WCHAR *MSI_RecordGetString( const MSIRECORD *, unsigned int );
642 extern MSIRECORD *MSI_CreateRecord( unsigned int );
643 extern UINT MSI_RecordSetInteger( MSIRECORD *, unsigned int, int );
644 extern UINT MSI_RecordSetStringW( MSIRECORD *, unsigned int, LPCWSTR );
645 extern UINT MSI_RecordSetStringA( MSIRECORD *, unsigned int, LPCSTR );
646 extern BOOL MSI_RecordIsNull( MSIRECORD *, unsigned int );
647 extern UINT MSI_RecordGetStringW( MSIRECORD * , unsigned int, LPWSTR, DWORD *);
648 extern UINT MSI_RecordGetStringA( MSIRECORD *, unsigned int, LPSTR, DWORD *);
649 extern int MSI_RecordGetInteger( MSIRECORD *, unsigned int );
650 extern UINT MSI_RecordReadStream( MSIRECORD *, unsigned int, char *, DWORD *);
651 extern unsigned int MSI_RecordGetFieldCount( const MSIRECORD *rec );
652 extern UINT MSI_RecordSetStream( MSIRECORD *, unsigned int, IStream * );
653 extern UINT MSI_RecordDataSize( MSIRECORD *, unsigned int );
654 extern UINT MSI_RecordStreamToFile( MSIRECORD *, unsigned int, LPCWSTR );
655 extern UINT MSI_RecordCopyField( MSIRECORD *, unsigned int, MSIRECORD *, unsigned int );
656
657 /* stream internals */
658 extern UINT get_raw_stream( MSIHANDLE hdb, LPCWSTR stname, IStream **stm );
659 extern UINT db_get_raw_stream( MSIDATABASE *db, LPCWSTR stname, IStream **stm );
660 extern void enum_stream_names( IStorage *stg );
661 extern BOOL decode_streamname(LPCWSTR in, LPWSTR out);
662 extern LPWSTR encode_streamname(BOOL bTable, LPCWSTR in);
663
664 /* database internals */
665 extern UINT MSI_OpenDatabaseW( LPCWSTR, LPCWSTR, MSIDATABASE ** );
666 extern UINT MSI_DatabaseOpenViewW(MSIDATABASE *, LPCWSTR, MSIQUERY ** );
667 extern UINT MSI_OpenQuery( MSIDATABASE *, MSIQUERY **, LPCWSTR, ... );
668 typedef UINT (*record_func)( MSIRECORD *, LPVOID );
669 extern UINT MSI_IterateRecords( MSIQUERY *, DWORD *, record_func, LPVOID );
670 extern MSIRECORD *MSI_QueryGetRecord( MSIDATABASE *db, LPCWSTR query, ... );
671 extern UINT MSI_DatabaseImport( MSIDATABASE *, LPCWSTR, LPCWSTR );
672 extern UINT MSI_DatabaseExport( MSIDATABASE *, LPCWSTR, LPCWSTR, LPCWSTR );
673 extern UINT MSI_DatabaseGetPrimaryKeys( MSIDATABASE *, LPCWSTR, MSIRECORD ** );
674
675 /* view internals */
676 extern UINT MSI_ViewExecute( MSIQUERY*, MSIRECORD * );
677 extern UINT MSI_ViewFetch( MSIQUERY*, MSIRECORD ** );
678 extern UINT MSI_ViewClose( MSIQUERY* );
679 extern UINT MSI_ViewGetColumnInfo(MSIQUERY *, MSICOLINFO, MSIRECORD **);
680 extern UINT MSI_ViewModify( MSIQUERY *, MSIMODIFY, MSIRECORD * );
681 extern UINT VIEW_find_column( MSIVIEW *, LPCWSTR, UINT * );
682
683
684 /* install internals */
685 extern UINT MSI_SetInstallLevel( MSIPACKAGE *package, int iInstallLevel );
686
687 /* package internals */
688 extern MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *, LPCWSTR );
689 extern UINT MSI_OpenPackageW( LPCWSTR szPackage, MSIPACKAGE **pPackage );
690 extern UINT MSI_SetTargetPathW( MSIPACKAGE *, LPCWSTR, LPCWSTR );
691 extern UINT MSI_SetPropertyW( MSIPACKAGE *, LPCWSTR, LPCWSTR );
692 extern INT MSI_ProcessMessage( MSIPACKAGE *, INSTALLMESSAGE, MSIRECORD * );
693 extern UINT MSI_GetPropertyW( MSIPACKAGE *, LPCWSTR, LPWSTR, DWORD * );
694 extern UINT MSI_GetPropertyA(MSIPACKAGE *, LPCSTR, LPSTR, DWORD* );
695 extern MSICONDITION MSI_EvaluateConditionW( MSIPACKAGE *, LPCWSTR );
696 extern UINT MSI_GetComponentStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * );
697 extern UINT MSI_GetFeatureStateW( MSIPACKAGE *, LPCWSTR, INSTALLSTATE *, INSTALLSTATE * );
698 extern UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE*, LPCWSTR, INSTALLSTATE );
699 extern LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename );
700 extern UINT msi_package_add_info(MSIPACKAGE *, DWORD, DWORD, LPCWSTR, LPWSTR);
701 extern UINT msi_package_add_media_disk(MSIPACKAGE *, DWORD, DWORD, DWORD, LPWSTR, LPWSTR);
702 extern UINT msi_clone_properties(MSIPACKAGE *);
703
704 /* for deformating */
705 extern UINT MSI_FormatRecordW( MSIPACKAGE *, MSIRECORD *, LPWSTR, DWORD * );
706
707 /* registry data encoding/decoding functions */
708 extern BOOL unsquash_guid(LPCWSTR in, LPWSTR out);
709 extern BOOL squash_guid(LPCWSTR in, LPWSTR out);
710 extern BOOL encode_base85_guid(GUID *,LPWSTR);
711 extern BOOL decode_base85_guid(LPCWSTR,GUID*);
712 extern UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create);
713 extern UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create);
714 extern UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create);
715 extern UINT MSIREG_OpenFeatures(HKEY* key);
716 extern UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
717 extern UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create);
718 extern UINT MSIREG_OpenComponents(HKEY* key);
719 extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
720 extern UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
721 extern UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create);
722 extern UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create);
723 extern UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create);
724 extern UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY* key, BOOL create);
725 extern UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
726 extern UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
727 extern UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create);
728 extern UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
729 extern UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szProduct, HKEY* key, BOOL create);
730 extern UINT MSIREG_DeleteProductKey(LPCWSTR szProduct);
731 extern UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct);
732 extern UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct);
733
734 extern LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name );
735 extern BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val);
736
737 extern DWORD msi_version_str_to_dword(LPCWSTR p);
738 extern LPWSTR msi_version_dword_to_str(DWORD version);
739
740 extern LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value );
741 extern LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value );
742 extern LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val );
743 extern LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val );
744
745 /* msi dialog interface */
746 typedef UINT (*msi_dialog_event_handler)( MSIPACKAGE*, LPCWSTR, LPCWSTR, msi_dialog* );
747 extern msi_dialog *msi_dialog_create( MSIPACKAGE*, LPCWSTR, msi_dialog*, msi_dialog_event_handler );
748 extern UINT msi_dialog_run_message_loop( msi_dialog* );
749 extern void msi_dialog_end_dialog( msi_dialog* );
750 extern void msi_dialog_check_messages( HANDLE );
751 extern void msi_dialog_do_preview( msi_dialog* );
752 extern void msi_dialog_destroy( msi_dialog* );
753 extern BOOL msi_dialog_register_class( void );
754 extern void msi_dialog_unregister_class( void );
755 extern void msi_dialog_handle_event( msi_dialog*, LPCWSTR, LPCWSTR, MSIRECORD * );
756 extern UINT msi_dialog_reset( msi_dialog *dialog );
757 extern UINT msi_dialog_directorylist_up( msi_dialog *dialog );
758 extern msi_dialog *msi_dialog_get_parent( msi_dialog *dialog );
759 extern LPWSTR msi_dialog_get_name( msi_dialog *dialog );
760 extern UINT msi_spawn_error_dialog( MSIPACKAGE*, LPWSTR, LPWSTR );
761
762 /* preview */
763 extern MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE * );
764 extern UINT MSI_PreviewDialogW( MSIPREVIEW *, LPCWSTR );
765
766 /* summary information */
767 extern MSISUMMARYINFO *MSI_GetSummaryInformationW( IStorage *stg, UINT uiUpdateCount );
768 extern LPWSTR msi_suminfo_dup_string( MSISUMMARYINFO *si, UINT uiProperty );
769 extern LPWSTR msi_get_suminfo_product( IStorage *stg );
770
771 /* undocumented functions */
772 UINT WINAPI MsiCreateAndVerifyInstallerDirectory( DWORD );
773 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR, LPWSTR, LPWSTR, LPWSTR, DWORD * );
774 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR, LPSTR, LPSTR, LPSTR, DWORD * );
775 LANGID WINAPI MsiLoadStringW( MSIHANDLE, UINT, LPWSTR, int, LANGID );
776 LANGID WINAPI MsiLoadStringA( MSIHANDLE, UINT, LPSTR, int, LANGID );
777
778 /* UI globals */
779 extern INSTALLUILEVEL gUILevel;
780 extern HWND gUIhwnd;
781 extern INSTALLUI_HANDLERA gUIHandlerA;
782 extern INSTALLUI_HANDLERW gUIHandlerW;
783 extern DWORD gUIFilter;
784 extern LPVOID gUIContext;
785 extern WCHAR gszLogFile[MAX_PATH];
786 extern HINSTANCE msi_hInstance;
787
788 /* action related functions */
789 extern UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action, UINT script, BOOL force);
790 extern UINT ACTION_PerformUIAction(MSIPACKAGE *package, const WCHAR *action, UINT script);
791 extern void ACTION_FinishCustomActions( const MSIPACKAGE* package);
792 extern UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action, UINT script, BOOL execute);
793
794 static inline void msi_feature_set_state( MSIFEATURE *feature, INSTALLSTATE state )
795 {
796     feature->ActionRequest = state;
797     feature->Action = state;
798 }
799
800 static inline void msi_component_set_state( MSICOMPONENT *comp, INSTALLSTATE state )
801 {
802     comp->ActionRequest = state;
803     comp->Action = state;
804 }
805
806 /* actions in other modules */
807 extern UINT ACTION_AppSearch(MSIPACKAGE *package);
808 extern UINT ACTION_FindRelatedProducts(MSIPACKAGE *package);
809 extern UINT ACTION_InstallFiles(MSIPACKAGE *package);
810 extern UINT ACTION_RemoveFiles(MSIPACKAGE *package);
811 extern UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
812 extern UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
813 extern UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
814 extern UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package);
815 extern UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package);
816 extern UINT ACTION_RegisterFonts(MSIPACKAGE *package);
817
818 /* Helpers */
819 extern DWORD deformat_string(MSIPACKAGE *package, LPCWSTR ptr, WCHAR** data );
820 extern LPWSTR msi_dup_record_field(MSIRECORD *row, INT index);
821 extern LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop);
822 extern int msi_get_property_int( MSIPACKAGE *package, LPCWSTR prop, int def );
823 extern LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name, BOOL source,
824                       BOOL set_prop, BOOL load_prop, MSIFOLDER **folder);
825 extern MSICOMPONENT *get_loaded_component( MSIPACKAGE* package, LPCWSTR Component );
826 extern MSIFEATURE *get_loaded_feature( MSIPACKAGE* package, LPCWSTR Feature );
827 extern MSIFILE *get_loaded_file( MSIPACKAGE* package, LPCWSTR file );
828 extern MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir );
829 extern int track_tempfile(MSIPACKAGE *package, LPCWSTR path);
830 extern UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action);
831 extern void msi_free_action_script(MSIPACKAGE *package, UINT script);
832 extern LPWSTR build_icon_path(MSIPACKAGE *, LPCWSTR);
833 extern LPWSTR build_directory_name(DWORD , ...);
834 extern BOOL create_full_pathW(const WCHAR *path);
835 extern BOOL ACTION_VerifyComponentForAction(const MSICOMPONENT*, INSTALLSTATE);
836 extern BOOL ACTION_VerifyFeatureForAction(const MSIFEATURE*, INSTALLSTATE);
837 extern void reduce_to_longfilename(WCHAR*);
838 extern void reduce_to_shortfilename(WCHAR*);
839 extern LPWSTR create_component_advertise_string(MSIPACKAGE*, MSICOMPONENT*, LPCWSTR);
840 extern void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature);
841 extern UINT register_unique_action(MSIPACKAGE *, LPCWSTR);
842 extern BOOL check_unique_action(const MSIPACKAGE *, LPCWSTR);
843 extern WCHAR* generate_error_string(MSIPACKAGE *, UINT, DWORD, ... );
844 extern UINT msi_create_component_directories( MSIPACKAGE *package );
845 extern void msi_ui_error( DWORD msg_id, DWORD type );
846
847 /* control event stuff */
848 extern VOID ControlEvent_FireSubscribedEvent(MSIPACKAGE *package, LPCWSTR event,
849                                       MSIRECORD *data);
850 extern VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog);
851 extern VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package);
852 extern VOID ControlEvent_SubscribeToEvent(MSIPACKAGE *package, msi_dialog *dialog,
853                                       LPCWSTR event, LPCWSTR control, LPCWSTR attribute);
854 extern VOID ControlEvent_UnSubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
855                                       LPCWSTR control, LPCWSTR attribute );
856
857 /* OLE automation */
858 extern HRESULT create_msiserver(IUnknown *pOuter, LPVOID *ppObj);
859 extern HRESULT create_session(MSIHANDLE msiHandle, IDispatch *pInstaller, IDispatch **pDispatch);
860 extern HRESULT load_type_info(IDispatch *iface, ITypeInfo **pptinfo, REFIID clsid, LCID lcid);
861
862 /* Scripting */
863 extern DWORD call_script(MSIHANDLE hPackage, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action);
864
865 /* User Interface messages from the actions */
866 extern void ui_progress(MSIPACKAGE *, int, int, int, int);
867 extern void ui_actiondata(MSIPACKAGE *, LPCWSTR, MSIRECORD *);
868
869 /* string consts use a number of places  and defined in helpers.c*/
870 extern const WCHAR cszSourceDir[];
871 extern const WCHAR cszSOURCEDIR[];
872 extern const WCHAR szProductCode[];
873 extern const WCHAR cszRootDrive[];
874 extern const WCHAR cszbs[];
875
876 /* memory allocation macro functions */
877 static inline void *msi_alloc( size_t len )
878 {
879     return HeapAlloc( GetProcessHeap(), 0, len );
880 }
881
882 static inline void *msi_alloc_zero( size_t len )
883 {
884     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
885 }
886
887 static inline void *msi_realloc( void *mem, size_t len )
888 {
889     return HeapReAlloc( GetProcessHeap(), 0, mem, len );
890 }
891
892 static inline void *msi_realloc_zero( void *mem, size_t len )
893 {
894     return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len );
895 }
896
897 static inline BOOL msi_free( void *mem )
898 {
899     return HeapFree( GetProcessHeap(), 0, mem );
900 }
901
902 static inline char *strdupWtoA( LPCWSTR str )
903 {
904     LPSTR ret = NULL;
905     DWORD len;
906
907     if (!str) return ret;
908     len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
909     ret = msi_alloc( len );
910     if (ret)
911         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
912     return ret;
913 }
914
915 static inline LPWSTR strdupAtoW( LPCSTR str )
916 {
917     LPWSTR ret = NULL;
918     DWORD len;
919
920     if (!str) return ret;
921     len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
922     ret = msi_alloc( len * sizeof(WCHAR) );
923     if (ret)
924         MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
925     return ret;
926 }
927
928 static inline LPWSTR strdupW( LPCWSTR src )
929 {
930     LPWSTR dest;
931     if (!src) return NULL;
932     dest = msi_alloc( (lstrlenW(src)+1)*sizeof(WCHAR) );
933     if (dest)
934         lstrcpyW(dest, src);
935     return dest;
936 }
937
938 #endif /* __WINE_MSI_PRIVATE__ */