summaryrefslogtreecommitdiffstats
path: root/libmsi/libmsi-summary-info.c
blob: c18f1e8e2da34562ea111272f8d7040796c73393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2002, 2005 Mike McCormack for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>
#include <time.h>
#include <assert.h>

#include "debug.h"
#include "libmsi.h"
#include "msipriv.h"

static const char szSumInfo[] = "\5SummaryInformation";
static const uint8_t fmtid_SummaryInformation[16] =
        { 0xe0, 0x85, 0x9f, 0xf2, 0xf9, 0x4f, 0x68, 0x10, 0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9};

static unsigned load_summary_info( LibmsiSummaryInfo *si, GsfInput *stm );

static void free_prop( LibmsiOLEVariant *prop )
{
    if (prop->vt == OLEVT_LPSTR)
        msi_free( prop->strval );
    prop->vt = OLEVT_EMPTY;
}

static void _libmsi_summary_info_destroy( LibmsiObject *arg )
{
    LibmsiSummaryInfo *si = (LibmsiSummaryInfo *) arg;
    unsigned i;

    for( i = 0; i < MSI_MAX_PROPS; i++ )
        free_prop( &si->property[i] );
    msiobj_release( &si->database->hdr );
}

LibmsiSummaryInfo *_libmsi_get_summary_information( LibmsiDatabase *db, unsigned uiUpdateCount )
{
    GsfInput *stm = NULL;
    LibmsiSummaryInfo *si;
    unsigned r;

    TRACE("%p %d\n", db, uiUpdateCount );

    si = alloc_msiobject( sizeof (LibmsiSummaryInfo), _libmsi_summary_info_destroy );
    if( !si )
        return si;

    si->update_count = uiUpdateCount;
    msiobj_addref( &db->hdr );
    si->database = db;

    /* read the stream... if we fail, we'll start with an empty property set */
    r = msi_get_raw_stream( db, szSumInfo, &stm );
    if( r == 0 )
    {
        load_summary_info( si, stm );
        g_object_unref(G_OBJECT(stm));
    }

    return si;
}

static unsigned get_type( unsigned uiProperty )
{
    switch( uiProperty )
    {
    case MSI_PID_CODEPAGE:
         return OLEVT_I2;

    case MSI_PID_SUBJECT:
    case MSI_PID_AUTHOR:
    case MSI_PID_KEYWORDS:
    case MSI_PID_COMMENTS:
    case MSI_PID_TEMPLATE:
    case MSI_PID_LASTAUTHOR:
    case MSI_PID_REVNUMBER:
    case MSI_PID_APPNAME:
    case MSI_PID_TITLE:
         return OLEVT_LPSTR;

    case MSI_PID_LASTPRINTED:
    case MSI_PID_CREATE_DTM:
    case MSI_PID_LASTSAVE_DTM:
         return OLEVT_FILETIME;

    case MSI_PID_WORDCOUNT:
    case MSI_PID_CHARCOUNT:
    case MSI_PID_SECURITY:
    case MSI_PID_PAGECOUNT:
         return OLEVT_I4;
    }
    return OLEVT_EMPTY;
}

static unsigned get_property_count( const LibmsiOLEVariant *property )
{
    unsigned i, n = 0;

    if( !property )
        return n;
    for( i = 0; i < MSI_MAX_PROPS; i++ )
        if( property[i].vt != OLEVT_EMPTY )
            n++;
    return n;
}

static unsigned read_word( const uint8_t *data, unsigned *ofs )
{
    unsigned val = 0;
    val = data[*ofs];
    val |= data[*ofs+1] << 8;
    *ofs += 2;
    return val;
}

static unsigned read_dword( const uint8_t *data, unsigned *ofs )
{
    unsigned val = 0;
    val = data[*ofs];
    val |= data[*ofs+1] << 8;
    val |= data[*ofs+2] << 16;
    val |= data[*ofs+3] << 24;
    *ofs += 4;
    return val;
}

static void parse_filetime( const char *str, guint64 *ft )
{
    struct tm tm;
    time_t t;
    const char *p = str;
    char *end;


    /* YYYY/MM/DD hh:mm:ss */

    while ( *p == ' ' || *p == '\t' ) p++;

    tm.tm_year = strtol( p, &end, 10 );
    if (*end != '/') return;
    p = end + 1;

    tm.tm_mon = strtol( p, &end, 10 ) - 1;
    if (*end != '/') return;
    p = end + 1;

    tm.tm_mday = strtol( p, &end, 10 );
    if (*end != ' ') return;
    p = end + 1;

    while ( *p == ' ' || *p == '\t' ) p++;

    tm.tm_hour = strtol( p, &end, 10 );
    if (*end != ':') return;
    p = end + 1;

    tm.tm_min = strtol( p, &end, 10 );
    if (*end != ':') return;
    p = end + 1;

    tm.tm_sec = strtol( p, &end, 10 );

    t = mktime(&tm);

    /* Add number of seconds between 1601-01-01 and 1970-01-01,
     * then convert to 100 ns units.
     */
    *ft = (t + 134774ULL * 86400ULL) * 10000000ULL;
}

/* FIXME: doesn't deal with endian conversion */
static void read_properties_from_data( LibmsiOLEVariant *prop, const uint8_t *data, unsigned sz, uint32_t cProperties )
{
    unsigned type;
    unsigned i;
    LibmsiOLEVariant *property;
    uint32_t idofs, len;
    char *str;

    idofs = 8;

    /* now set all the properties */
    for( i = 0; i < cProperties; i++ )
    {
        int propid = read_dword(data, &idofs);
        int dwOffset = read_dword(data, &idofs);
        int proptype;

        if( propid >= MSI_MAX_PROPS )
        {
            ERR("Unknown property ID %d\n", propid );
            break;
        }

        type = get_type( propid );
        if( type == OLEVT_EMPTY )
        {
            ERR("propid %d has unknown type\n", propid);
            break;
        }

        property = &prop[ propid ];

        if( dwOffset + 4 > sz )
        {
            ERR("not enough data for type %d %d \n", dwOffset, sz);
            break;
        }

        proptype = read_dword(data, &dwOffset);
        if( dwOffset + 4 > sz )
        {
            ERR("not enough data for type %d %d \n", dwOffset, sz);
            break;
        }

        property->vt = proptype;
        switch(proptype)
        {
        case OLEVT_I2:
        case OLEVT_I4:
            property->intval = read_dword(data, &dwOffset);
            break;
        case OLEVT_FILETIME:
            if( dwOffset + 8 > sz )
            {
                ERR("not enough data for type %d %d \n", dwOffset, sz);
                break;
            }
            property->filetime = read_dword(data, &dwOffset);
            property->filetime |= (guint64)read_dword(data, &dwOffset) << 32;
            break;
        case OLEVT_LPSTR:
            len = read_dword(data, &dwOffset);
            if( dwOffset + len > sz )
            {
                ERR("not enough data for type %d %d %d \n", dwOffset, len, sz);
                break;
            }
            str = msi_alloc( len );
            memcpy( str, &data[dwOffset], len-1 );
            str[ len - 1 ] = 0;
            break;
        }

        /* check the type is the same as we expect */
        if( type == OLEVT_LPSTR && proptype == OLEVT_LPSTR)
           property->strval = str;
        else if (type == proptype)
           ;
        else if( proptype == OLEVT_LPSTR) {
            if( type == OLEVT_I2 || type == OLEVT_I4) {
                property->intval = atoi( str );
            } else if( type == OLEVT_FILETIME) {
                parse_filetime( str, &property->filetime );
            }
            msi_free (str);
        }
        else
        {
            ERR("invalid type \n");
            break;
        }
    }
}

static unsigned load_summary_info( LibmsiSummaryInfo *si, GsfInput *stm )
{
    unsigned ret = LIBMSI_RESULT_FUNCTION_FAILED;
    uint8_t *data = NULL;
    unsigned ofs, dwOffset;
    unsigned cbSection, cProperties;
    off_t sz;

    TRACE("%p %p\n", si, stm);

    sz = gsf_input_size(stm);
    if (!sz)
        return ret;
    data = g_try_malloc(gsf_input_size(stm));
    if (!data)
        return LIBMSI_RESULT_NOT_ENOUGH_MEMORY;

    if (!gsf_input_read(stm, sz, data))
        goto done;

    /* process the set header */
    ofs = 0;
    if( read_word( data, &ofs) != 0xfffe )
    {
        ERR("property set not little-endian\n");
        goto done;
    }

    /* process the format header */

    /* check the format id is correct */
    ofs = 28;
    if( memcmp( &fmtid_SummaryInformation, &data[ofs], 16 ) )
        goto done;

    /* seek to the location of the section */
    ofs += 16;
    ofs = dwOffset = read_dword(data, &ofs);

    /* read the section itself */
    cbSection = read_dword( data, &ofs );
    cProperties = read_dword( data, &ofs );

    if( cProperties > MSI_MAX_PROPS )
    {
        ERR("too many properties %d\n", cProperties);
        goto done;
    }

    /* read all the data in one go */
    read_properties_from_data( si->property,
                               &data[dwOffset],
                               cbSection, cProperties );

done:
    msi_free( data );
    return ret;
}

static unsigned write_word( uint8_t *data, unsigned ofs, unsigned val )
{
    if( data )
    {
        data[ofs++] = val&0xff;
        data[ofs++] = (val>>8)&0xff;
    }
    return 2;
}

static unsigned write_dword( uint8_t *data, unsigned ofs, unsigned val )
{
    if( data )
    {
        data[ofs++] = val&0xff;
        data[ofs++] = (val>>8)&0xff;
        data[ofs++] = (val>>16)&0xff;
        data[ofs++] = (val>>24)&0xff;
    }
    return 4;
}

static unsigned write_filetime( uint8_t *data, unsigned ofs, const guint64 *ft )
{
    write_dword( data, ofs, (*ft) & 0xFFFFFFFFUL );
    write_dword( data, ofs + 4, (*ft) >> 32 );
    return 8;
}

static unsigned write_string( uint8_t *data, unsigned ofs, const char *str )
{
    unsigned len = strlen( str ) + 1;
    write_dword( data, ofs, len );
    if( data )
        memcpy( &data[ofs + 4], str, len );
    return (7 + len) & ~3;
}

static unsigned write_property_to_data( const LibmsiOLEVariant *prop, uint8_t *data )
{
    unsigned sz = 0;

    if( prop->vt == OLEVT_EMPTY )
        return sz;

    /* add the type */
    sz += write_dword( data, sz, prop->vt );
    switch( prop->vt )
    {
    case OLEVT_I2:
    case OLEVT_I4:
        sz += write_dword( data, sz, prop->intval );
        break;
    case OLEVT_FILETIME: {
        sz += write_filetime( data, sz, &prop->filetime );
        break;
    }
    case OLEVT_LPSTR:
        sz += write_string( data, sz, prop->strval );
        break;
    }
    return sz;
}

static unsigned suminfo_persist( LibmsiSummaryInfo *si )
{
    int cProperties, cbSection, dwOffset;
    GsfInput *stm;
    uint8_t *data = NULL;
    unsigned r, sz;
    int i;

    /* add up how much space the data will take and calculate the offsets */
    cProperties = get_property_count( si->property );
    cbSection = 8 + cProperties * 8;
    for( i = 0; i < MSI_MAX_PROPS; i++ )
        cbSection += write_property_to_data( &si->property[i], NULL );

    sz = 28 + 20 + cbSection;
    data = msi_alloc_zero( sz );

    /* write the set header */
    sz = 0;
    sz += write_word(data, sz, 0xfffe); /* wByteOrder */
    sz += write_word(data, sz, 0);      /* wFormat */
    sz += write_dword(data, sz, 0x00020005); /* dwOSVer - build 5, platform id 2 */
    sz += 16; /* clsID */
    sz += write_dword(data, sz, 1); /* reserved */

    /* write the format header */
    memcpy( &data[sz], &fmtid_SummaryInformation, 16 );
    sz += 16;

    sz += write_dword(data, sz, 28 + 20); /* dwOffset */
    assert(sz == 28 + 20);

    /* write the section header */
    sz += write_dword(data, sz, cbSection);
    sz += write_dword(data, sz, cProperties);
    assert(sz == 28 + 20 + 8);

    dwOffset = 8 + cProperties * 8;
    for( i = 0; i < MSI_MAX_PROPS; i++ )
    {
        int propsz = write_property_to_data( &si->property[i], NULL );
        if( !propsz )
            continue;
        sz += write_dword(data, sz, i);
        sz += write_dword(data, sz, dwOffset);
        dwOffset += propsz;
    }
    assert(dwOffset == cbSection);

    /* write out the data */
    for( i = 0; i < MSI_MAX_PROPS; i++ )
        sz += write_property_to_data( &si->property[i], &data[sz] );

    assert(sz == 28 + 20 + cbSection);

    r = write_raw_stream_data(si->database, szSumInfo, data, sz, &stm);
    if (r == 0) {
        g_object_unref(G_OBJECT(stm));
    }
    msi_free( data );
    return r;
}

LibmsiResult libmsi_database_get_summary_info( LibmsiDatabase *db, 
              unsigned uiUpdateCount, LibmsiSummaryInfo **psi )
{
    LibmsiSummaryInfo *si;
    unsigned ret = LIBMSI_RESULT_FUNCTION_FAILED;

    TRACE("%d %d %p\n", db, uiUpdateCount, psi);

    if( !psi )
        return LIBMSI_RESULT_INVALID_PARAMETER;

    if( !db )
        return LIBMSI_RESULT_INVALID_HANDLE;

    msiobj_addref( &db->hdr);
    si = _libmsi_get_summary_information( db, uiUpdateCount );
    if (si)
    {
        *psi = si;
        ret = LIBMSI_RESULT_SUCCESS;
    }

    msiobj_release( &db->hdr );
    return ret;
}

LibmsiResult libmsi_summary_info_get_property_count(LibmsiSummaryInfo *si, unsigned *pCount)
{
    TRACE("%d %p\n", si, pCount);

    if( !si )
        return LIBMSI_RESULT_INVALID_HANDLE;

    msiobj_addref( &si->hdr );
    if( pCount )
        *pCount = get_property_count( si->property );
    msiobj_release( &si->hdr );

    return LIBMSI_RESULT_SUCCESS;
}

LibmsiResult libmsi_summary_info_get_property(
      LibmsiSummaryInfo *si, unsigned uiProperty, unsigned *puiDataType, int *pintvalue,
      guint64 *pftValue, char *szValueBuf, unsigned *pcchValueBuf)
{
    LibmsiOLEVariant *prop;
    unsigned ret = LIBMSI_RESULT_SUCCESS;

    TRACE("%d %d %p %p %p %p %p\n", si, uiProperty, puiDataType,
          pintvalue, pftValue, szValueBuf, pcchValueBuf);

    if ( uiProperty >= MSI_MAX_PROPS )
    {
        if (puiDataType) *puiDataType = LIBMSI_PROPERTY_TYPE_EMPTY;
        return LIBMSI_RESULT_UNKNOWN_PROPERTY;
    }

    if( !si )
        return LIBMSI_RESULT_INVALID_HANDLE;

    msiobj_addref( &si->hdr );
    prop = &si->property[uiProperty];

    switch( prop->vt )
    {
    case OLEVT_I2:
    case OLEVT_I4:
        if( puiDataType )
            *puiDataType = LIBMSI_PROPERTY_TYPE_INT;

        if( pintvalue )
            *pintvalue = prop->intval;
        break;
    case OLEVT_LPSTR:
        if( puiDataType )
            *puiDataType = LIBMSI_PROPERTY_TYPE_STRING;

        if( pcchValueBuf )
        {
            unsigned len = 0;

            len = strlen( prop->strval );
            if( szValueBuf )
                strcpyn(szValueBuf, prop->strval, *pcchValueBuf );
            if (len >= *pcchValueBuf)
                ret = LIBMSI_RESULT_MORE_DATA;
            *pcchValueBuf = len;
        }
        break;
    case OLEVT_FILETIME:
        if( puiDataType )
            *puiDataType = LIBMSI_PROPERTY_TYPE_FILETIME;

        if( pftValue )
            *pftValue = prop->filetime;
        break;
    case OLEVT_EMPTY:
        if( puiDataType )
            *puiDataType = LIBMSI_PROPERTY_TYPE_EMPTY;

        break;
    default:
        FIXME("Unknown property variant type\n");
        break;
    }
    msiobj_release( &si->hdr );
    return ret;
}

static LibmsiResult _libmsi_summary_info_set_property( LibmsiSummaryInfo *si, unsigned uiProperty,
               unsigned type, int intvalue, guint64* pftValue, const char *szValue )
{
    LibmsiOLEVariant *prop;
    unsigned len;
    unsigned ret;

    if( type == OLEVT_LPSTR && !szValue )
        return LIBMSI_RESULT_INVALID_PARAMETER;

    if( type == OLEVT_FILETIME && !pftValue )
        return LIBMSI_RESULT_INVALID_PARAMETER;

    msiobj_addref( &si->hdr);

    prop = &si->property[uiProperty];

    if( prop->vt == OLEVT_EMPTY )
    {
        ret = LIBMSI_RESULT_FUNCTION_FAILED;
        if( !si->update_count )
            goto end;

        si->update_count--;
    }
    else if( prop->vt != type )
    {
        ret = LIBMSI_RESULT_SUCCESS;
        goto end;
    }

    free_prop( prop );
    prop->vt = type;
    switch( type )
    {
    case OLEVT_I2:
    case OLEVT_I4:
        prop->intval = intvalue;
        break;
    case OLEVT_FILETIME:
        prop->filetime = *pftValue;
        break;
    case OLEVT_LPSTR:
        len = strlen( szValue ) + 1;
        prop->strval = msi_alloc( len );
        strcpy( prop->strval, szValue );
        break;
    }

    ret = LIBMSI_RESULT_SUCCESS;
end:
    msiobj_release( &si->hdr );
    return ret;
}

LibmsiResult libmsi_summary_info_set_property( LibmsiSummaryInfo *si, unsigned uiProperty,
               unsigned uiDataType, int intvalue, guint64* pftValue, const char *szValue )
{
    int type;

    TRACE("%p %u %u %i %p %p\n", si, uiProperty, type, intvalue,
          pftValue, szValue );

    if( !si )
        return LIBMSI_RESULT_INVALID_HANDLE;

    type = get_type( uiProperty );
    switch (type) {
    case OLEVT_EMPTY:
        return LIBMSI_RESULT_DATATYPE_MISMATCH;
    case OLEVT_I2:
    case OLEVT_I4:
        if (uiDataType != LIBMSI_PROPERTY_TYPE_INT) {
            return LIBMSI_RESULT_DATATYPE_MISMATCH;
        }
        break;
    case OLEVT_LPSTR:
        if (uiDataType != LIBMSI_PROPERTY_TYPE_STRING) {
            return LIBMSI_RESULT_DATATYPE_MISMATCH;
        }
        break;
    case OLEVT_FILETIME:
        if (uiDataType != LIBMSI_PROPERTY_TYPE_FILETIME) {
            return LIBMSI_RESULT_DATATYPE_MISMATCH;
        }
        break;
    }

    return _libmsi_summary_info_set_property( si, uiProperty, type, intvalue, pftValue, szValue );
}

static unsigned parse_prop( const char *prop, const char *value, unsigned *pid, int *int_value,
                        guint64 *ft_value, char **str_value )
{
    *pid = atoi( prop );
    switch (*pid)
    {
    case MSI_PID_CODEPAGE:
    case MSI_PID_WORDCOUNT:
    case MSI_PID_CHARCOUNT:
    case MSI_PID_SECURITY:
    case MSI_PID_PAGECOUNT:
        *int_value = atoi( value );
        break;

    case MSI_PID_LASTPRINTED:
    case MSI_PID_CREATE_DTM:
    case MSI_PID_LASTSAVE_DTM:
        parse_filetime( value, ft_value );
        break;

    case MSI_PID_SUBJECT:
    case MSI_PID_AUTHOR:
    case MSI_PID_KEYWORDS:
    case MSI_PID_COMMENTS:
    case MSI_PID_TEMPLATE:
    case MSI_PID_LASTAUTHOR:
    case MSI_PID_REVNUMBER:
    case MSI_PID_APPNAME:
    case MSI_PID_TITLE:
        *str_value = strdup(value);
        break;

    default:
        WARN("unhandled prop id %u\n", *pid);
        return LIBMSI_RESULT_FUNCTION_FAILED;
    }

    return LIBMSI_RESULT_SUCCESS;
}

unsigned msi_add_suminfo( LibmsiDatabase *db, char ***records, int num_records, int num_columns )
{
    unsigned r = LIBMSI_RESULT_FUNCTION_FAILED;
    unsigned i, j;
    LibmsiSummaryInfo *si;

    si = _libmsi_get_summary_information( db, num_records * (num_columns / 2) );
    if (!si)
    {
        ERR("no summary information!\n");
        return LIBMSI_RESULT_FUNCTION_FAILED;
    }

    for (i = 0; i < num_records; i++)
    {
        for (j = 0; j < num_columns; j += 2)
        {
            unsigned pid;
            int int_value = 0;
            guint64 ft_value;
            char *str_value = NULL;

            r = parse_prop( records[i][j], records[i][j + 1], &pid, &int_value, &ft_value, &str_value );
            if (r != LIBMSI_RESULT_SUCCESS)
                goto end;

            assert( get_type(pid) != OLEVT_EMPTY );
            r = _libmsi_summary_info_set_property( si, pid, get_type(pid), int_value, &ft_value, str_value );
            if (r != LIBMSI_RESULT_SUCCESS)
                goto end;

            msi_free(str_value);
        }
    }

end:
    if (r == LIBMSI_RESULT_SUCCESS)
        r = suminfo_persist( si );

    msiobj_release( &si->hdr );
    return r;
}

LibmsiResult libmsi_summary_info_persist( LibmsiSummaryInfo *si )
{
    unsigned ret;

    TRACE("%d\n", si );

    if( !si )
        return LIBMSI_RESULT_INVALID_HANDLE;

    msiobj_addref( &si->hdr);
    ret = suminfo_persist( si );
    msiobj_release( &si->hdr );
    return ret;
}