2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2004 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msidb
);
44 #define MSIFIELD_NULL 0
45 #define MSIFIELD_INT 1
46 #define MSIFIELD_WSTR 3
47 #define MSIFIELD_STREAM 4
49 static void MSI_FreeField( MSIFIELD
*field
)
57 msi_free( field
->u
.szwVal
);
60 IStream_Release( field
->u
.stream
);
63 ERR("Invalid field type %d\n", field
->type
);
67 void MSI_CloseRecord( MSIOBJECTHDR
*arg
)
69 MSIRECORD
*rec
= (MSIRECORD
*) arg
;
72 for( i
=0; i
<=rec
->count
; i
++ )
73 MSI_FreeField( &rec
->fields
[i
] );
76 MSIRECORD
*MSI_CreateRecord( UINT cParams
)
80 TRACE("%d\n", cParams
);
85 rec
= alloc_msiobject( MSIHANDLETYPE_RECORD
, FIELD_OFFSET(MSIRECORD
, fields
[cParams
+ 1]),
92 MSIHANDLE WINAPI
MsiCreateRecord( UINT cParams
)
97 TRACE("%d\n", cParams
);
99 rec
= MSI_CreateRecord( cParams
);
102 ret
= alloc_msihandle( &rec
->hdr
);
103 msiobj_release( &rec
->hdr
);
108 UINT
MSI_RecordGetFieldCount( const MSIRECORD
*rec
)
113 UINT WINAPI
MsiRecordGetFieldCount( MSIHANDLE handle
)
118 TRACE("%d\n", handle
);
120 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
124 msiobj_lock( &rec
->hdr
);
125 ret
= MSI_RecordGetFieldCount( rec
);
126 msiobj_unlock( &rec
->hdr
);
127 msiobj_release( &rec
->hdr
);
132 static BOOL
string2intW( LPCWSTR str
, int *out
)
137 if( *p
== '-' ) /* skip the minus sign */
141 if( (*p
< '0') || (*p
> '9') )
148 if( str
[0] == '-' ) /* check if it's negative */
155 WCHAR
*msi_strdupW( const WCHAR
*value
, int len
)
159 if (!value
) return NULL
;
160 if (!(ret
= msi_alloc( (len
+ 1) * sizeof(WCHAR
) ))) return NULL
;
161 memcpy( ret
, value
, len
* sizeof(WCHAR
) );
166 UINT
MSI_RecordCopyField( MSIRECORD
*in_rec
, UINT in_n
,
167 MSIRECORD
*out_rec
, UINT out_n
)
169 UINT r
= ERROR_SUCCESS
;
171 msiobj_lock( &in_rec
->hdr
);
173 if ( in_n
> in_rec
->count
|| out_n
> out_rec
->count
)
174 r
= ERROR_FUNCTION_FAILED
;
175 else if ( in_rec
!= out_rec
|| in_n
!= out_n
)
180 in
= &in_rec
->fields
[in_n
];
181 out
= &out_rec
->fields
[out_n
];
188 out
->u
.iVal
= in
->u
.iVal
;
191 if ((str
= msi_strdupW( in
->u
.szwVal
, in
->len
)))
196 else r
= ERROR_OUTOFMEMORY
;
198 case MSIFIELD_STREAM
:
199 IStream_AddRef( in
->u
.stream
);
200 out
->u
.stream
= in
->u
.stream
;
203 ERR("invalid field type %d\n", in
->type
);
205 if (r
== ERROR_SUCCESS
)
206 out
->type
= in
->type
;
209 msiobj_unlock( &in_rec
->hdr
);
213 int MSI_RecordGetInteger( MSIRECORD
*rec
, UINT iField
)
217 TRACE("%p %d\n", rec
, iField
);
219 if( iField
> rec
->count
)
220 return MSI_NULL_INTEGER
;
222 switch( rec
->fields
[iField
].type
)
225 return rec
->fields
[iField
].u
.iVal
;
227 if( string2intW( rec
->fields
[iField
].u
.szwVal
, &ret
) )
229 return MSI_NULL_INTEGER
;
234 return MSI_NULL_INTEGER
;
237 int WINAPI
MsiRecordGetInteger( MSIHANDLE handle
, UINT iField
)
242 TRACE("%d %d\n", handle
, iField
);
244 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
246 return MSI_NULL_INTEGER
;
248 msiobj_lock( &rec
->hdr
);
249 ret
= MSI_RecordGetInteger( rec
, iField
);
250 msiobj_unlock( &rec
->hdr
);
251 msiobj_release( &rec
->hdr
);
256 UINT WINAPI
MsiRecordClearData( MSIHANDLE handle
)
261 TRACE("%d\n", handle
);
263 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
265 return ERROR_INVALID_HANDLE
;
267 msiobj_lock( &rec
->hdr
);
268 for( i
=0; i
<=rec
->count
; i
++)
270 MSI_FreeField( &rec
->fields
[i
] );
271 rec
->fields
[i
].type
= MSIFIELD_NULL
;
272 rec
->fields
[i
].u
.iVal
= 0;
274 msiobj_unlock( &rec
->hdr
);
275 msiobj_release( &rec
->hdr
);
277 return ERROR_SUCCESS
;
280 UINT
MSI_RecordSetInteger( MSIRECORD
*rec
, UINT iField
, int iVal
)
282 TRACE("%p %u %d\n", rec
, iField
, iVal
);
284 if( iField
> rec
->count
)
285 return ERROR_INVALID_PARAMETER
;
287 MSI_FreeField( &rec
->fields
[iField
] );
289 if (iVal
== MSI_NULL_INTEGER
)
291 rec
->fields
[iField
].type
= MSIFIELD_NULL
;
292 rec
->fields
[iField
].u
.szwVal
= NULL
;
296 rec
->fields
[iField
].type
= MSIFIELD_INT
;
297 rec
->fields
[iField
].u
.iVal
= iVal
;
300 return ERROR_SUCCESS
;
303 UINT WINAPI
MsiRecordSetInteger( MSIHANDLE handle
, UINT iField
, int iVal
)
308 TRACE("%d %u %d\n", handle
, iField
, iVal
);
310 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
312 return ERROR_INVALID_HANDLE
;
314 msiobj_lock( &rec
->hdr
);
315 ret
= MSI_RecordSetInteger( rec
, iField
, iVal
);
316 msiobj_unlock( &rec
->hdr
);
317 msiobj_release( &rec
->hdr
);
321 BOOL
MSI_RecordIsNull( MSIRECORD
*rec
, UINT iField
)
325 TRACE("%p %d\n", rec
, iField
);
327 r
= ( iField
> rec
->count
) ||
328 ( rec
->fields
[iField
].type
== MSIFIELD_NULL
);
333 BOOL WINAPI
MsiRecordIsNull( MSIHANDLE handle
, UINT iField
)
338 TRACE("%d %d\n", handle
, iField
);
340 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
343 msiobj_lock( &rec
->hdr
);
344 ret
= MSI_RecordIsNull( rec
, iField
);
345 msiobj_unlock( &rec
->hdr
);
346 msiobj_release( &rec
->hdr
);
351 UINT
MSI_RecordGetStringA(MSIRECORD
*rec
, UINT iField
,
352 LPSTR szValue
, LPDWORD pcchValue
)
354 UINT len
= 0, ret
= ERROR_SUCCESS
;
357 TRACE("%p %d %p %p\n", rec
, iField
, szValue
, pcchValue
);
359 if( iField
> rec
->count
)
361 if ( szValue
&& *pcchValue
> 0 )
365 return ERROR_SUCCESS
;
368 switch( rec
->fields
[iField
].type
)
371 wsprintfA(buffer
, "%d", rec
->fields
[iField
].u
.iVal
);
372 len
= lstrlenA( buffer
);
374 lstrcpynA(szValue
, buffer
, *pcchValue
);
377 len
= WideCharToMultiByte( CP_ACP
, 0, rec
->fields
[iField
].u
.szwVal
,
378 rec
->fields
[iField
].len
+ 1, NULL
, 0 , NULL
, NULL
);
380 WideCharToMultiByte( CP_ACP
, 0, rec
->fields
[iField
].u
.szwVal
,
381 rec
->fields
[iField
].len
+ 1, szValue
, *pcchValue
, NULL
, NULL
);
382 if( szValue
&& *pcchValue
&& len
>*pcchValue
)
383 szValue
[*pcchValue
-1] = 0;
388 if( szValue
&& *pcchValue
> 0 )
392 ret
= ERROR_INVALID_PARAMETER
;
396 if( szValue
&& *pcchValue
<= len
)
397 ret
= ERROR_MORE_DATA
;
403 UINT WINAPI
MsiRecordGetStringA(MSIHANDLE handle
, UINT iField
,
404 LPSTR szValue
, LPDWORD pcchValue
)
409 TRACE("%d %d %p %p\n", handle
, iField
, szValue
, pcchValue
);
411 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
413 return ERROR_INVALID_HANDLE
;
414 msiobj_lock( &rec
->hdr
);
415 ret
= MSI_RecordGetStringA( rec
, iField
, szValue
, pcchValue
);
416 msiobj_unlock( &rec
->hdr
);
417 msiobj_release( &rec
->hdr
);
421 const WCHAR
*msi_record_get_string( const MSIRECORD
*rec
, UINT field
, int *len
)
423 if (field
> rec
->count
)
426 if (rec
->fields
[field
].type
!= MSIFIELD_WSTR
)
429 if (len
) *len
= rec
->fields
[field
].len
;
431 return rec
->fields
[field
].u
.szwVal
;
434 const WCHAR
*MSI_RecordGetString( const MSIRECORD
*rec
, UINT iField
)
436 return msi_record_get_string( rec
, iField
, NULL
);
439 UINT
MSI_RecordGetStringW(MSIRECORD
*rec
, UINT iField
,
440 LPWSTR szValue
, LPDWORD pcchValue
)
442 UINT len
= 0, ret
= ERROR_SUCCESS
;
445 TRACE("%p %d %p %p\n", rec
, iField
, szValue
, pcchValue
);
447 if( iField
> rec
->count
)
449 if ( szValue
&& *pcchValue
> 0 )
453 return ERROR_SUCCESS
;
456 switch( rec
->fields
[iField
].type
)
459 wsprintfW(buffer
, L
"%d", rec
->fields
[iField
].u
.iVal
);
460 len
= lstrlenW( buffer
);
462 lstrcpynW(szValue
, buffer
, *pcchValue
);
465 len
= rec
->fields
[iField
].len
;
467 memcpy( szValue
, rec
->fields
[iField
].u
.szwVal
, min(len
+ 1, *pcchValue
) * sizeof(WCHAR
) );
470 if( szValue
&& *pcchValue
> 0 )
477 if( szValue
&& *pcchValue
<= len
)
478 ret
= ERROR_MORE_DATA
;
484 UINT WINAPI
MsiRecordGetStringW(MSIHANDLE handle
, UINT iField
,
485 LPWSTR szValue
, LPDWORD pcchValue
)
490 TRACE("%d %d %p %p\n", handle
, iField
, szValue
, pcchValue
);
492 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
494 return ERROR_INVALID_HANDLE
;
496 msiobj_lock( &rec
->hdr
);
497 ret
= MSI_RecordGetStringW( rec
, iField
, szValue
, pcchValue
);
498 msiobj_unlock( &rec
->hdr
);
499 msiobj_release( &rec
->hdr
);
503 static UINT
msi_get_stream_size( IStream
*stm
)
508 r
= IStream_Stat( stm
, &stat
, STATFLAG_NONAME
);
511 return stat
.cbSize
.QuadPart
;
514 static UINT
MSI_RecordDataSize(MSIRECORD
*rec
, UINT iField
)
516 TRACE("%p %d\n", rec
, iField
);
518 if( iField
> rec
->count
)
521 switch( rec
->fields
[iField
].type
)
526 return rec
->fields
[iField
].len
;
529 case MSIFIELD_STREAM
:
530 return msi_get_stream_size( rec
->fields
[iField
].u
.stream
);
535 UINT WINAPI
MsiRecordDataSize(MSIHANDLE handle
, UINT iField
)
540 TRACE("%d %d\n", handle
, iField
);
542 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
545 msiobj_lock( &rec
->hdr
);
546 ret
= MSI_RecordDataSize( rec
, iField
);
547 msiobj_unlock( &rec
->hdr
);
548 msiobj_release( &rec
->hdr
);
552 UINT WINAPI
MsiRecordSetStringA( MSIHANDLE handle
, UINT iField
, LPCSTR szValue
)
554 WCHAR
*valueW
= NULL
;
558 TRACE("%d %d %s\n", handle
, iField
, debugstr_a(szValue
));
560 if (szValue
&& !(valueW
= strdupAtoW( szValue
))) return ERROR_OUTOFMEMORY
;
562 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
566 return ERROR_INVALID_HANDLE
;
568 msiobj_lock( &rec
->hdr
);
569 ret
= MSI_RecordSetStringW( rec
, iField
, valueW
);
570 msiobj_unlock( &rec
->hdr
);
571 msiobj_release( &rec
->hdr
);
576 UINT
msi_record_set_string( MSIRECORD
*rec
, UINT field
, const WCHAR
*value
, int len
)
578 if (field
> rec
->count
)
579 return ERROR_INVALID_FIELD
;
581 MSI_FreeField( &rec
->fields
[field
] );
583 if (value
&& len
< 0) len
= lstrlenW( value
);
587 rec
->fields
[field
].type
= MSIFIELD_WSTR
;
588 rec
->fields
[field
].u
.szwVal
= msi_strdupW( value
, len
);
589 rec
->fields
[field
].len
= len
;
593 rec
->fields
[field
].type
= MSIFIELD_NULL
;
594 rec
->fields
[field
].u
.szwVal
= NULL
;
595 rec
->fields
[field
].len
= 0;
600 UINT
MSI_RecordSetStringW( MSIRECORD
*rec
, UINT iField
, LPCWSTR szValue
)
602 TRACE("%p %d %s\n", rec
, iField
, debugstr_w(szValue
));
604 return msi_record_set_string( rec
, iField
, szValue
, -1 );
607 UINT WINAPI
MsiRecordSetStringW( MSIHANDLE handle
, UINT iField
, LPCWSTR szValue
)
612 TRACE("%d %d %s\n", handle
, iField
, debugstr_w(szValue
));
614 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
616 return ERROR_INVALID_HANDLE
;
618 msiobj_lock( &rec
->hdr
);
619 ret
= MSI_RecordSetStringW( rec
, iField
, szValue
);
620 msiobj_unlock( &rec
->hdr
);
621 msiobj_release( &rec
->hdr
);
625 /* read the data in a file into an IStream */
626 static UINT
RECORD_StreamFromFile(LPCWSTR szFile
, IStream
**pstm
)
628 DWORD sz
, szHighWord
= 0, read
;
632 ULARGE_INTEGER ulSize
;
634 TRACE("reading %s\n", debugstr_w(szFile
));
636 /* read the file into memory */
637 handle
= CreateFileW(szFile
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
638 if( handle
== INVALID_HANDLE_VALUE
)
639 return GetLastError();
640 sz
= GetFileSize(handle
, &szHighWord
);
641 if( sz
!= INVALID_FILE_SIZE
&& szHighWord
== 0 )
643 hGlob
= GlobalAlloc(GMEM_FIXED
, sz
);
646 BOOL r
= ReadFile(handle
, hGlob
, sz
, &read
, NULL
) && read
== sz
;
656 return ERROR_FUNCTION_FAILED
;
658 /* make a stream out of it, and set the correct file size */
659 hr
= CreateStreamOnHGlobal(hGlob
, TRUE
, pstm
);
663 return ERROR_FUNCTION_FAILED
;
666 /* set the correct size - CreateStreamOnHGlobal screws it up */
667 ulSize
.QuadPart
= sz
;
668 IStream_SetSize(*pstm
, ulSize
);
670 TRACE("read %s, %d bytes into IStream %p\n", debugstr_w(szFile
), sz
, *pstm
);
672 return ERROR_SUCCESS
;
675 UINT
MSI_RecordSetStream(MSIRECORD
*rec
, UINT iField
, IStream
*stream
)
677 if ( (iField
== 0) || (iField
> rec
->count
) )
678 return ERROR_INVALID_PARAMETER
;
680 MSI_FreeField( &rec
->fields
[iField
] );
681 rec
->fields
[iField
].type
= MSIFIELD_STREAM
;
682 rec
->fields
[iField
].u
.stream
= stream
;
684 return ERROR_SUCCESS
;
687 UINT
MSI_RecordSetStreamFromFileW(MSIRECORD
*rec
, UINT iField
, LPCWSTR szFilename
)
693 if( (iField
== 0) || (iField
> rec
->count
) )
694 return ERROR_INVALID_PARAMETER
;
696 /* no filename means we should seek back to the start of the stream */
702 if( rec
->fields
[iField
].type
!= MSIFIELD_STREAM
)
703 return ERROR_INVALID_FIELD
;
705 stm
= rec
->fields
[iField
].u
.stream
;
707 return ERROR_INVALID_FIELD
;
710 hr
= IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, &cur
);
712 return ERROR_FUNCTION_FAILED
;
716 /* read the file into a stream and save the stream in the record */
717 ret
= RECORD_StreamFromFile(szFilename
, &stm
);
718 if (ret
!= ERROR_SUCCESS
)
721 /* if all's good, store it in the record */
722 MSI_RecordSetStream(rec
, iField
, stm
);
725 return ERROR_SUCCESS
;
728 UINT WINAPI
MsiRecordSetStreamA(MSIHANDLE hRecord
, UINT iField
, LPCSTR szFilename
)
733 TRACE("%d %d %s\n", hRecord
, iField
, debugstr_a(szFilename
));
737 wstr
= strdupAtoW( szFilename
);
739 return ERROR_OUTOFMEMORY
;
741 ret
= MsiRecordSetStreamW(hRecord
, iField
, wstr
);
747 UINT WINAPI
MsiRecordSetStreamW(MSIHANDLE handle
, UINT iField
, LPCWSTR szFilename
)
752 TRACE("%d %d %s\n", handle
, iField
, debugstr_w(szFilename
));
754 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
756 return ERROR_INVALID_HANDLE
;
758 msiobj_lock( &rec
->hdr
);
759 ret
= MSI_RecordSetStreamFromFileW( rec
, iField
, szFilename
);
760 msiobj_unlock( &rec
->hdr
);
761 msiobj_release( &rec
->hdr
);
765 UINT
MSI_RecordReadStream(MSIRECORD
*rec
, UINT iField
, char *buf
, LPDWORD sz
)
771 TRACE("%p %d %p %p\n", rec
, iField
, buf
, sz
);
774 return ERROR_INVALID_PARAMETER
;
776 if( iField
> rec
->count
)
777 return ERROR_INVALID_PARAMETER
;
779 if ( rec
->fields
[iField
].type
== MSIFIELD_NULL
)
782 return ERROR_INVALID_DATA
;
785 if( rec
->fields
[iField
].type
!= MSIFIELD_STREAM
)
786 return ERROR_INVALID_DATATYPE
;
788 stm
= rec
->fields
[iField
].u
.stream
;
790 return ERROR_INVALID_PARAMETER
;
792 /* if there's no buffer pointer, calculate the length to the end */
796 ULARGE_INTEGER end
, cur
;
798 ofs
.QuadPart
= cur
.QuadPart
= 0;
800 IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, &cur
);
801 IStream_Seek( stm
, ofs
, STREAM_SEEK_END
, &end
);
802 ofs
.QuadPart
= cur
.QuadPart
;
803 IStream_Seek( stm
, ofs
, STREAM_SEEK_SET
, &cur
);
804 *sz
= end
.QuadPart
- cur
.QuadPart
;
806 return ERROR_SUCCESS
;
811 r
= IStream_Read( stm
, buf
, *sz
, &count
);
815 return ERROR_FUNCTION_FAILED
;
820 return ERROR_SUCCESS
;
823 UINT WINAPI
MsiRecordReadStream(MSIHANDLE handle
, UINT iField
, char *buf
, LPDWORD sz
)
828 TRACE("%d %d %p %p\n", handle
, iField
, buf
, sz
);
830 rec
= msihandle2msiinfo( handle
, MSIHANDLETYPE_RECORD
);
832 return ERROR_INVALID_HANDLE
;
833 msiobj_lock( &rec
->hdr
);
834 ret
= MSI_RecordReadStream( rec
, iField
, buf
, sz
);
835 msiobj_unlock( &rec
->hdr
);
836 msiobj_release( &rec
->hdr
);
840 UINT
MSI_RecordSetIStream( MSIRECORD
*rec
, UINT iField
, IStream
*stm
)
842 TRACE("%p %d %p\n", rec
, iField
, stm
);
844 if( iField
> rec
->count
)
845 return ERROR_INVALID_FIELD
;
847 MSI_FreeField( &rec
->fields
[iField
] );
849 rec
->fields
[iField
].type
= MSIFIELD_STREAM
;
850 rec
->fields
[iField
].u
.stream
= stm
;
851 IStream_AddRef( stm
);
853 return ERROR_SUCCESS
;
856 UINT
MSI_RecordGetIStream( MSIRECORD
*rec
, UINT iField
, IStream
**pstm
)
858 TRACE("%p %d %p\n", rec
, iField
, pstm
);
860 if( iField
> rec
->count
)
861 return ERROR_INVALID_FIELD
;
863 if( rec
->fields
[iField
].type
!= MSIFIELD_STREAM
)
864 return ERROR_INVALID_FIELD
;
866 *pstm
= rec
->fields
[iField
].u
.stream
;
867 IStream_AddRef( *pstm
);
869 return ERROR_SUCCESS
;
872 static UINT
msi_dump_stream_to_file( IStream
*stm
, LPCWSTR name
)
880 stgm
= STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
| STGM_FAILIFTHERE
;
881 r
= SHCreateStreamOnFileW( name
, stgm
, &out
);
883 return ERROR_FUNCTION_FAILED
;
886 r
= IStream_Seek( stm
, pos
, STREAM_SEEK_END
, &size
);
891 r
= IStream_Seek( stm
, pos
, STREAM_SEEK_SET
, NULL
);
895 r
= IStream_CopyTo( stm
, out
, size
, NULL
, NULL
);
898 IStream_Release( out
);
900 return ERROR_FUNCTION_FAILED
;
901 return ERROR_SUCCESS
;
904 UINT
MSI_RecordStreamToFile( MSIRECORD
*rec
, UINT iField
, LPCWSTR name
)
909 TRACE("%p %u %s\n", rec
, iField
, debugstr_w(name
));
911 msiobj_lock( &rec
->hdr
);
913 r
= MSI_RecordGetIStream( rec
, iField
, &stm
);
914 if( r
== ERROR_SUCCESS
)
916 r
= msi_dump_stream_to_file( stm
, name
);
917 IStream_Release( stm
);
920 msiobj_unlock( &rec
->hdr
);
925 MSIRECORD
*MSI_CloneRecord(MSIRECORD
*rec
)
930 count
= MSI_RecordGetFieldCount(rec
);
931 clone
= MSI_CreateRecord(count
);
935 for (i
= 0; i
<= count
; i
++)
937 if (rec
->fields
[i
].type
== MSIFIELD_STREAM
)
939 if (FAILED(IStream_Clone(rec
->fields
[i
].u
.stream
,
940 &clone
->fields
[i
].u
.stream
)))
942 msiobj_release(&clone
->hdr
);
945 clone
->fields
[i
].type
= MSIFIELD_STREAM
;
949 r
= MSI_RecordCopyField(rec
, i
, clone
, i
);
950 if (r
!= ERROR_SUCCESS
)
952 msiobj_release(&clone
->hdr
);
961 BOOL
MSI_RecordsAreFieldsEqual(MSIRECORD
*a
, MSIRECORD
*b
, UINT field
)
963 if (a
->fields
[field
].type
!= b
->fields
[field
].type
)
966 switch (a
->fields
[field
].type
)
972 if (a
->fields
[field
].u
.iVal
!= b
->fields
[field
].u
.iVal
)
977 if (a
->fields
[field
].len
!= b
->fields
[field
].len
) return FALSE
;
978 if (memcmp( a
->fields
[field
].u
.szwVal
, b
->fields
[field
].u
.szwVal
,
979 a
->fields
[field
].len
* sizeof(WCHAR
) )) return FALSE
;
982 case MSIFIELD_STREAM
:
990 BOOL
MSI_RecordsAreEqual(MSIRECORD
*a
, MSIRECORD
*b
)
994 if (a
->count
!= b
->count
)
997 for (i
= 0; i
<= a
->count
; i
++)
999 if (!MSI_RecordsAreFieldsEqual( a
, b
, i
))
1006 WCHAR
*msi_dup_record_field( MSIRECORD
*rec
, INT field
)
1012 if (MSI_RecordIsNull( rec
, field
)) return NULL
;
1014 r
= MSI_RecordGetStringW( rec
, field
, NULL
, &sz
);
1015 if (r
!= ERROR_SUCCESS
)
1019 str
= msi_alloc( sz
* sizeof(WCHAR
) );
1020 if (!str
) return NULL
;
1022 r
= MSI_RecordGetStringW( rec
, field
, str
, &sz
);
1023 if (r
!= ERROR_SUCCESS
)
1025 ERR("failed to get string!\n");
1032 void dump_record(MSIRECORD
*rec
)
1042 for (i
= 0; i
<= rec
->count
; i
++)
1044 switch(rec
->fields
[i
].type
)
1046 case MSIFIELD_NULL
: TRACE("(null)"); break;
1047 case MSIFIELD_INT
: TRACE("%d", rec
->fields
[i
].u
.iVal
); break;
1048 case MSIFIELD_WSTR
: TRACE("%s", debugstr_w(rec
->fields
[i
].u
.szwVal
)); break;
1049 case MSIFIELD_STREAM
: TRACE("%p", rec
->fields
[i
].u
.stream
); break;
1051 if (i
< rec
->count
) TRACE(", ");
1056 UINT
copy_remote_record(const struct wire_record
*in
, MSIHANDLE out
)
1060 UINT r
= ERROR_SUCCESS
;
1062 if (!(rec
= msihandle2msiinfo(out
, MSIHANDLETYPE_RECORD
)))
1063 return ERROR_INVALID_HANDLE
;
1065 rec
->cookie
= in
->cookie
;
1066 for (i
= 0; i
<= in
->count
; i
++)
1068 switch (in
->fields
[i
].type
)
1071 MSI_FreeField(&rec
->fields
[i
]);
1072 rec
->fields
[i
].type
= MSIFIELD_NULL
;
1075 r
= MSI_RecordSetInteger(rec
, i
, in
->fields
[i
].u
.iVal
);
1078 r
= MSI_RecordSetStringW(rec
, i
, in
->fields
[i
].u
.szwVal
);
1080 case MSIFIELD_STREAM
:
1081 r
= MSI_RecordSetIStream(rec
, i
, in
->fields
[i
].u
.stream
);
1084 ERR("invalid field type %d\n", in
->fields
[i
].type
);
1090 msiobj_release(&rec
->hdr
);
1095 msiobj_release(&rec
->hdr
);
1096 return ERROR_SUCCESS
;
1099 UINT
unmarshal_record(const struct wire_record
*in
, MSIHANDLE
*out
)
1104 return ERROR_SUCCESS
;
1107 *out
= MsiCreateRecord(in
->count
);
1108 if (!*out
) return ERROR_OUTOFMEMORY
;
1110 return copy_remote_record(in
, *out
);
1113 struct wire_record
*marshal_record(MSIHANDLE handle
)
1115 struct wire_record
*ret
;
1119 if (!(rec
= msihandle2msiinfo(handle
, MSIHANDLETYPE_RECORD
)))
1122 ret
= midl_user_allocate(sizeof(*ret
) + rec
->count
* sizeof(ret
->fields
[0]));
1123 ret
->count
= rec
->count
;
1124 ret
->cookie
= rec
->cookie
;
1126 for (i
= 0; i
<= rec
->count
; i
++)
1128 switch (rec
->fields
[i
].type
)
1133 ret
->fields
[i
].u
.iVal
= rec
->fields
[i
].u
.iVal
;
1136 ret
->fields
[i
].u
.szwVal
= strdupW(rec
->fields
[i
].u
.szwVal
);
1138 case MSIFIELD_STREAM
:
1139 IStream_AddRef(rec
->fields
[i
].u
.stream
);
1140 ret
->fields
[i
].u
.stream
= rec
->fields
[i
].u
.stream
;
1143 ERR("invalid field type %d\n", rec
->fields
[i
].type
);
1146 ret
->fields
[i
].type
= rec
->fields
[i
].type
;
1149 msiobj_release(&rec
->hdr
);
1153 void free_remote_record(struct wire_record
*rec
)
1157 for (i
= 0; i
<= rec
->count
; i
++)
1159 if (rec
->fields
[i
].type
== MSIFIELD_WSTR
)
1160 midl_user_free(rec
->fields
[i
].u
.szwVal
);
1161 else if (rec
->fields
[i
].type
== MSIFIELD_STREAM
)
1162 IStream_Release(rec
->fields
[i
].u
.stream
);
1165 midl_user_free(rec
);