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