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