~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to libmapi/property.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        /* Sanity checks */
87
87
        OPENCHANGE_RETVAL_IF(!mem_ctx, MAPI_E_NOT_INITIALIZED, NULL);
88
88
        OPENCHANGE_RETVAL_IF(!SPropTagArray, MAPI_E_INVALID_PARAMETER, NULL);
89
 
        OPENCHANGE_RETVAL_IF(!SPropTagArray->cValues, MAPI_E_INVALID_PARAMETER, NULL);
 
89
        OPENCHANGE_RETVAL_IF(!SPropTagArray->aulPropTag, MAPI_E_INVALID_PARAMETER, NULL);
90
90
 
91
91
        SPropTagArray->cValues += 1;
92
92
        SPropTagArray->aulPropTag = (enum MAPITAGS *) talloc_realloc(mem_ctx, SPropTagArray->aulPropTag,
97
97
        return MAPI_E_SUCCESS;
98
98
}
99
99
 
 
100
/**
 
101
   \details Delete a property tag from an existing properties array
 
102
 
 
103
   \param mem_ctx talloc memory context to use for allocation
 
104
   \param SPropTagArray existing properties array to remove from
 
105
   \param aulPropTag the property tag to remove
 
106
 
 
107
   \return MAPI_E_SUCCESS on success, otherwise MAPI error.
 
108
 
 
109
   \note Possible MAPI error codes are:
 
110
   - MAPI_E_NOT_INITIALIZED: MAPI subsystem has not been initialized
 
111
   - MAPI_E_INVALID_PARAMETER: SPropTagArray parameter is not correctly set
 
112
*/
 
113
_PUBLIC_ enum MAPISTATUS SPropTagArray_delete(TALLOC_CTX *mem_ctx,
 
114
                                              struct SPropTagArray *SPropTagArray,
 
115
                                              uint32_t aulPropTag)
 
116
{
 
117
        uint32_t i, removed = 0;
 
118
 
 
119
        /* Sanity checks */
 
120
        OPENCHANGE_RETVAL_IF(!mem_ctx, MAPI_E_NOT_INITIALIZED, NULL);
 
121
        OPENCHANGE_RETVAL_IF(!SPropTagArray, MAPI_E_INVALID_PARAMETER, NULL);
 
122
        OPENCHANGE_RETVAL_IF(!SPropTagArray->cValues, MAPI_E_INVALID_PARAMETER, NULL);
 
123
 
 
124
        for (i = 0; i < SPropTagArray->cValues; i++) {
 
125
                if (SPropTagArray->aulPropTag[i] == aulPropTag) {
 
126
                        removed++;
 
127
                }
 
128
                else if (removed > 0) {
 
129
                        SPropTagArray->aulPropTag[i-removed] = SPropTagArray->aulPropTag[i];
 
130
                }
 
131
        }
 
132
 
 
133
        SPropTagArray->cValues -= removed;
 
134
        SPropTagArray->aulPropTag = (enum MAPITAGS *) talloc_realloc(mem_ctx, SPropTagArray->aulPropTag,
 
135
                                                                     uint32_t, SPropTagArray->cValues + 1);
 
136
        SPropTagArray->aulPropTag[SPropTagArray->cValues] = (enum MAPITAGS) 0;
 
137
 
 
138
        return MAPI_E_SUCCESS;
 
139
}
 
140
 
 
141
/**
 
142
   \details Return the index of a property tag in an existing properties array
 
143
 
 
144
   \param SPropTagArray existing properties array to remove from
 
145
   \param aulPropTag the property tag to find
 
146
   \param propIdx the index of the found property (undefined when MAPI_E_NOT_FOUND is returned)
 
147
 
 
148
   \return MAPI_E_SUCCESS on success, otherwise MAPI error.
 
149
 
 
150
   \note Possible MAPI error codes are:
 
151
   - MAPI_E_NOT_INITIALIZED: MAPI subsystem has not been initialized
 
152
   - MAPI_E_INVALID_PARAMETER: SPropTagArray parameter is not correctly set
 
153
*/
 
154
_PUBLIC_ enum MAPISTATUS SPropTagArray_find(struct SPropTagArray SPropTagArray,
 
155
                                            enum MAPITAGS aulPropTag, 
 
156
                                            uint32_t *propIdx)
 
157
{
 
158
        uint32_t i;
 
159
 
 
160
        /* Sanity checks */
 
161
        OPENCHANGE_RETVAL_IF(!propIdx, MAPI_E_INVALID_PARAMETER, NULL);
 
162
 
 
163
        for (i = 0; i < SPropTagArray.cValues; i++) {
 
164
                if (SPropTagArray.aulPropTag[i] == aulPropTag) {
 
165
                        *propIdx = i;
 
166
                        return MAPI_E_SUCCESS;
 
167
                }
 
168
        }
 
169
 
 
170
        return MAPI_E_NOT_FOUND;
 
171
}
 
172
 
100
173
_PUBLIC_ const void *get_SPropValue(struct SPropValue *lpProps, 
101
174
                                    enum MAPITAGS ulPropTag)
102
175
{
161
234
{
162
235
        uint32_t        i;
163
236
 
 
237
        if ( ! aRow) {
 
238
                return NULL;
 
239
        }
 
240
 
164
241
        for (i = 0; i < aRow->cValues; i++) {
165
242
                if (ulPropTag == aRow->lpProps[i].ulPropTag) {
166
243
                        return (&aRow->lpProps[i]);
236
313
{
237
314
        uint32_t i;
238
315
 
239
 
        if ( ! aRow) {
 
316
        if (!aRow) {
240
317
                return NULL;
241
318
        }
242
319
 
298
375
                return (const void *)(struct mapi_MV_LONG_STRUCT *)&lpProp->value.MVl;
299
376
        case PT_MV_STRING8:
300
377
                return (const void *)(struct mapi_SLPSTRArray *)&lpProp->value.MVszA;
 
378
        case PT_MV_UNICODE:
 
379
                return (const void *)(struct mapi_SLPSTRArrayW *)&lpProp->value.MVszW;
301
380
        case PT_MV_BINARY:
302
381
                return (const void *)(struct mapi_SBinaryArray *)&lpProp->value.MVbin;
303
382
        default:
333
412
        case PT_CLSID:
334
413
                return (const void *)lpProps->value.lpguid;
335
414
        case PT_BINARY:
 
415
        case PT_SVREID:
336
416
                return (const void *)&lpProps->value.bin;
337
417
        case PT_OBJECT:
338
418
                return (const void *)&lpProps->value.object;
343
423
        case PT_MV_STRING8:
344
424
                return (const void *)(struct StringArray_r *)&lpProps->value.MVszA;
345
425
        case PT_MV_UNICODE:
346
 
                return (const void *)(struct WStringArray_r *)&lpProps->value.MVszW;
 
426
                return (const void *)(struct StringArrayW_r *)&lpProps->value.MVszW;
347
427
        case PT_MV_BINARY:
348
428
                return (const void *)(struct BinaryArray_r *)&lpProps->value.MVbin;
349
429
        case PT_MV_SYSTIME:
376
456
 
377
457
        return lpProps;
378
458
}
379
 
/*
380
 
  TODO: should this be public?
381
 
*/
 
459
 
 
460
_PUBLIC_ bool set_mapi_SPropValue(TALLOC_CTX *mem_ctx, struct mapi_SPropValue *lpProps, const void *data)
 
461
{
 
462
        if (data == NULL) {
 
463
                lpProps->ulPropTag = (lpProps->ulPropTag & 0xffff0000) | PT_ERROR;
 
464
                lpProps->value.err = MAPI_E_NOT_FOUND;
 
465
                return false;
 
466
        }
 
467
        switch (lpProps->ulPropTag & 0xFFFF) {
 
468
        case PT_SHORT:
 
469
                lpProps->value.i = *((const uint16_t *)data);
 
470
                break;
 
471
        case PT_LONG:
 
472
                lpProps->value.l = *((const uint32_t *)data);
 
473
                break;
 
474
        case PT_DOUBLE:
 
475
                memcpy(&lpProps->value.dbl, (uint8_t *)data, 8);
 
476
                break;
 
477
        case PT_I8:
 
478
                lpProps->value.d = *((const uint64_t *)data);
 
479
                break;
 
480
        case PT_BOOLEAN:
 
481
                lpProps->value.b = *((const uint8_t *)data);
 
482
                break;
 
483
        case PT_STRING8:
 
484
                lpProps->value.lpszA = (const char *) data;
 
485
                break;
 
486
        case PT_BINARY:
 
487
        {
 
488
                struct Binary_r *bin;
 
489
 
 
490
                bin = (struct Binary_r *)data;
 
491
                lpProps->value.bin.cb = (uint16_t)bin->cb;
 
492
                lpProps->value.bin.lpb = (void *)bin->lpb;
 
493
        }
 
494
                break;
 
495
        case PT_UNICODE: 
 
496
                lpProps->value.lpszW = (const char *) data;
 
497
                break;
 
498
        case PT_CLSID:
 
499
                lpProps->value.lpguid = *((struct GUID *) data);
 
500
                break;
 
501
        case PT_SYSTIME:
 
502
                lpProps->value.ft = *((const struct FILETIME *) data);
 
503
                break;
 
504
        case PT_ERROR:
 
505
                lpProps->value.err = *((const uint32_t *)data);
 
506
                break;
 
507
        case PT_MV_LONG:
 
508
                lpProps->value.MVl = *((const struct mapi_MV_LONG_STRUCT *)data);
 
509
                break;
 
510
        case PT_MV_STRING8:
 
511
                lpProps->value.MVszA = *((const struct mapi_SLPSTRArray *)data);
 
512
                break;
 
513
        case PT_MV_BINARY:
 
514
                lpProps->value.MVbin = *((const struct mapi_SBinaryArray *)data);
 
515
                break;
 
516
        case PT_MV_CLSID:
 
517
                lpProps->value.MVguid = *((const struct mapi_SGuidArray *)data);
 
518
                break;
 
519
        case PT_MV_UNICODE:
 
520
                lpProps->value.MVszW = *((const struct mapi_SLPSTRArrayW *)data);
 
521
                break;
 
522
        default:
 
523
                lpProps->ulPropTag = (lpProps->ulPropTag & 0xffff0000) | PT_ERROR;
 
524
                lpProps->value.err = MAPI_E_NOT_FOUND;
 
525
 
 
526
                return false;
 
527
        }
 
528
 
 
529
        return true;
 
530
}
 
531
 
 
532
_PUBLIC_ bool set_mapi_SPropValue_proptag(TALLOC_CTX *mem_ctx, struct mapi_SPropValue *lpProps, uint32_t aulPropTag, const void *data)
 
533
{
 
534
        lpProps->ulPropTag = aulPropTag;
 
535
 
 
536
        return (set_mapi_SPropValue(mem_ctx, lpProps, data));
 
537
}
 
538
 
 
539
_PUBLIC_ struct mapi_SPropValue *add_mapi_SPropValue(TALLOC_CTX *mem_ctx, struct mapi_SPropValue *lpProps, uint16_t *cValues, uint32_t aulPropTag, const void *data)
 
540
{
 
541
        lpProps = talloc_realloc(mem_ctx, lpProps, struct mapi_SPropValue, *cValues + 2);
 
542
        DEBUG(0, ("%d: setting value for 0x%.8x\n", *cValues, aulPropTag));
 
543
        set_mapi_SPropValue_proptag(mem_ctx, &lpProps[*cValues], aulPropTag, data);
 
544
        *cValues = *cValues + 1;
 
545
 
 
546
        return lpProps;
 
547
}
 
548
 
382
549
_PUBLIC_ bool set_SPropValue(struct SPropValue *lpProps, const void *data)
383
550
{
384
551
        if (data == NULL) {
 
552
                lpProps->ulPropTag = (lpProps->ulPropTag & 0xffff0000) | PT_ERROR;
385
553
                lpProps->value.err = MAPI_E_NOT_FOUND;
386
554
                return false;
387
555
        }
405
573
                lpProps->value.lpszA = (const char *) data;
406
574
                break;
407
575
        case PT_BINARY:
 
576
        case PT_SVREID:
408
577
                lpProps->value.bin = *((const struct Binary_r *)data);
409
578
                break;
410
579
        case PT_UNICODE:
435
604
                lpProps->value.MVguid = *((const struct FlatUIDArray_r *)data);
436
605
                break;
437
606
        case PT_MV_UNICODE:
438
 
                lpProps->value.MVszW = *((const struct WStringArray_r *)data);
 
607
                lpProps->value.MVszW = *((const struct StringArrayW_r *)data);
439
608
                break;
440
609
        case PT_MV_SYSTIME:
441
610
                lpProps->value.MVft = *((const struct DateTimeArray_r *)data);
447
616
                lpProps->value.object = *((const uint32_t *)data);
448
617
                break;
449
618
        default:
 
619
                lpProps->ulPropTag = (lpProps->ulPropTag & 0xffff0000) | PT_ERROR;
450
620
                lpProps->value.err = MAPI_E_NOT_FOUND;
451
621
 
452
622
                return false;
483
653
 
484
654
 
485
655
/**
 
656
   \details Convenience function to copy an array of struct SPropValue or a
 
657
   part thereof into another array, by duplicating and properly parenting
 
658
   pointer data. The destination array is considered to be preallocated.
 
659
*/
 
660
_PUBLIC_ void mapi_copy_spropvalues(TALLOC_CTX *mem_ctx, struct SPropValue *source_values, struct SPropValue *dest_values, uint32_t count)
 
661
{
 
662
        uint32_t                i;
 
663
        struct SPropValue       *source_value, *dest_value;
 
664
        uint16_t                prop_type;
 
665
 
 
666
        for (i = 0; i < count; i++) {
 
667
                source_value = source_values + i;
 
668
                dest_value = dest_values + i;
 
669
                *dest_value = *source_value;
 
670
 
 
671
                prop_type = (source_value->ulPropTag & 0xFFFF);
 
672
                if ((prop_type & MV_FLAG)) {
 
673
                        DEBUG(5, ("multivalues not handled\n"));
 
674
                        abort();
 
675
                }
 
676
                else {
 
677
                        switch(prop_type) {
 
678
                        case PT_STRING8:
 
679
                                dest_value->value.lpszA = talloc_strdup(mem_ctx, source_value->value.lpszA);
 
680
                                break;
 
681
                        case PT_UNICODE:
 
682
                                dest_value->value.lpszW = talloc_strdup(mem_ctx, source_value->value.lpszW);
 
683
                                break;
 
684
                        case PT_BINARY:
 
685
                                dest_value->value.bin.cb = source_value->value.bin.cb;
 
686
                                dest_value->value.bin.lpb = talloc_memdup(mem_ctx, source_value->value.bin.lpb, sizeof(uint8_t) * source_value->value.bin.cb);
 
687
                                break;
 
688
                        default:
 
689
                                *dest_value = *source_value;
 
690
                        }
 
691
                }
 
692
        }
 
693
}
 
694
 
 
695
/**
486
696
   \details Convenience function to convert a SPropValue structure
487
697
   into a mapi_SPropValue structure and return the associated size.
488
698
 
574
784
                                                               mapi_sprop->value.MVszW.cValues);
575
785
                for (i = 0; i < mapi_sprop->value.MVszW.cValues; i++) {
576
786
                        mapi_sprop->value.MVszW.strings[i].lppszW = sprop->value.MVszW.lppszW[i];
577
 
                        size += strlen(mapi_sprop->value.MVszW.strings[i].lppszW) + 1;
 
787
                        size += get_utf8_utf16_conv_length(mapi_sprop->value.MVszW.strings[i].lppszW);
578
788
                }
579
789
                return size;
580
790
        }
606
816
                }
607
817
                return sizeof(mapi_sprop->value.MVl.cValues) + (mapi_sprop->value.MVl.cValues * sizeof (uint32_t));
608
818
        }
 
819
        case PT_MV_CLSID:
 
820
        {
 
821
                uint32_t i;
 
822
                DATA_BLOB b;
 
823
 
 
824
                mapi_sprop->value.MVguid.cValues = sprop->value.MVguid.cValues;
 
825
                mapi_sprop->value.MVguid.lpguid = talloc_array (mem_ctx, struct GUID, mapi_sprop->value.MVguid.cValues);
 
826
                for (i = 0; i < mapi_sprop->value.MVguid.cValues; i++) {
 
827
                        b.data = sprop->value.MVguid.lpguid[i]->ab;
 
828
                        b.length = 16;
 
829
 
 
830
                        GUID_from_ndr_blob(&b, &(mapi_sprop->value.MVguid.lpguid[i]));
 
831
                }
 
832
                return sizeof(mapi_sprop->value.MVguid.cValues) + (mapi_sprop->value.MVguid.cValues * sizeof (struct GUID));
 
833
        }
609
834
        default:
610
835
                printf("unhandled conversion case in cast_mapi_SPropValue(): 0x%x\n", (sprop->ulPropTag & 0xFFFF));
611
836
                OPENCHANGE_ASSERT();
664
889
        {
665
890
                DATA_BLOB       b;
666
891
                
667
 
                GUID_to_ndr_blob(&(mapi_sprop->value.lpguid), talloc_autofree_context(), &b);
 
892
                GUID_to_ndr_blob(&(mapi_sprop->value.lpguid), mem_ctx, &b);
668
893
                sprop->value.lpguid = talloc_zero(mem_ctx, struct FlatUID_r);
669
894
                sprop->value.lpguid = (struct FlatUID_r *)memcpy(sprop->value.lpguid->ab, b.data, 16);
670
895
                return (sizeof (struct FlatUID_r));
721
946
                sprop->value.MVszW.lppszW = talloc_array(mem_ctx, const char*, sprop->value.MVszW.cValues);
722
947
                for (i = 0; i < sprop->value.MVszW.cValues; i++) {
723
948
                        sprop->value.MVszW.lppszW[i] = mapi_sprop->value.MVszW.strings[i].lppszW;
724
 
                        size += 2 * (strlen(sprop->value.MVszW.lppszW[i]) + 1);
 
949
                        size += get_utf8_utf16_conv_length(sprop->value.MVszW.lppszW[i]);
725
950
                }
726
951
                return size;
727
952
        }
746
971
                        DATA_BLOB       b;
747
972
                        
748
973
                        sprop->value.MVguid.lpguid[i] = talloc_zero(mem_ctx, struct FlatUID_r);
749
 
                        GUID_to_ndr_blob(&(mapi_sprop->value.MVguid.lpguid[i]), talloc_autofree_context(), &b);
 
974
                        GUID_to_ndr_blob(&(mapi_sprop->value.MVguid.lpguid[i]), mem_ctx, &b);
750
975
                        sprop->value.MVguid.lpguid[i] = (struct FlatUID_r *)memcpy(sprop->value.MVguid.lpguid[i]->ab, b.data, sizeof(struct FlatUID_r));
751
976
                        size += (sizeof (struct FlatUID_r));
752
977
                }
868
1093
        uint16_t                count;
869
1094
        uint32_t                i;
870
1095
 
871
 
        mem_ctx = talloc_named(NULL, 0, "mapi_SPropValue_array_named");
 
1096
        mem_ctx = talloc_named(mapi_object_get_session(obj), 0, "mapi_SPropValue_array_named");
872
1097
 
873
1098
        for (i = 0; i < props->cValues; i++) {
874
1099
                if ((props->lpProps[i].ulPropTag & 0xFFFF0000) > 0x80000000) {
1006
1231
 
1007
1232
        return RecurrencePattern;
1008
1233
}
 
1234
 
 
1235
_PUBLIC_ size_t set_RecurrencePattern_size(const struct RecurrencePattern *rp)
 
1236
{
 
1237
        size_t size = SIZE_DFLT_RECURRENCEPATTERN;
 
1238
 
 
1239
        switch (rp->PatternType) {
 
1240
        case PatternType_MonthNth:
 
1241
        case PatternType_HjMonthNth:
 
1242
                size += sizeof(uint32_t);
 
1243
        case PatternType_Week:
 
1244
        case PatternType_Month:
 
1245
        case PatternType_MonthEnd:
 
1246
        case PatternType_HjMonth:
 
1247
        case PatternType_HjMonthEnd:
 
1248
                size += sizeof(uint32_t);
 
1249
        case PatternType_Day:
 
1250
                break;
 
1251
        default:
 
1252
                DEBUG(0, ("%s: unrecognized pattern type: %d", __PRETTY_FUNCTION__, rp->PatternType));
 
1253
        }
 
1254
 
 
1255
        size += rp->DeletedInstanceCount * sizeof(uint32_t);
 
1256
        size += rp->ModifiedInstanceCount * sizeof(uint32_t);
 
1257
 
 
1258
        return size;
 
1259
}
 
1260
 
 
1261
_PUBLIC_ struct Binary_r *set_RecurrencePattern(TALLOC_CTX *mem_ctx, const struct RecurrencePattern *rp)
 
1262
{
 
1263
        struct Binary_r                 *bin = NULL;
 
1264
        struct ndr_push                 *ndr;
 
1265
        enum ndr_err_code               ndr_err_code;
 
1266
        size_t                          bin_size;
 
1267
        
 
1268
        /* SANITY CHECKS */
 
1269
        if (!rp) return NULL;
 
1270
 
 
1271
        bin_size = set_RecurrencePattern_size(rp);
 
1272
        bin = talloc_zero(mem_ctx, struct Binary_r);
 
1273
        bin->cb = bin_size;
 
1274
        bin->lpb = talloc_array(bin, uint8_t, bin_size);
 
1275
 
 
1276
        ndr = talloc_zero(mem_ctx, struct ndr_push);
 
1277
        ndr->offset = 0;
 
1278
        ndr->data = bin->lpb;
 
1279
 
 
1280
        ndr_err_code = ndr_push_RecurrencePattern(ndr, NDR_SCALARS, rp);
 
1281
 
 
1282
        talloc_free(ndr);
 
1283
 
 
1284
        if (ndr_err_code != NDR_ERR_SUCCESS) {
 
1285
                talloc_free(bin);
 
1286
                return NULL;
 
1287
        }
 
1288
 
 
1289
        return bin;
 
1290
}
 
1291
 
1009
1292
_PUBLIC_ struct AppointmentRecurrencePattern *get_AppointmentRecurrencePattern(TALLOC_CTX *mem_ctx, 
1010
 
                                                         struct Binary_r *bin)
 
1293
                                                                               struct Binary_r *bin)
1011
1294
{
1012
1295
        struct AppointmentRecurrencePattern             *arp = NULL;
1013
1296
        struct ndr_pull                                 *ndr;
1049
1332
        arp->RecurrencePattern.DeletedInstanceDates = talloc_reference(arp,arp->RecurrencePattern.DeletedInstanceDates);
1050
1333
        arp->RecurrencePattern.ModifiedInstanceDates = talloc_reference(arp, arp->RecurrencePattern.ModifiedInstanceDates);
1051
1334
        
1052
 
 
1053
 
        
1054
 
 
1055
1335
        return arp;
1056
1336
}
1057
1337
 
 
1338
_PUBLIC_ size_t set_AppointmentRecurrencePattern_size(const struct AppointmentRecurrencePattern *arp)
 
1339
{
 
1340
        size_t size = SIZE_DFLT_APPOINTMENTRECURRENCEPATTERN;
 
1341
        uint16_t i;
 
1342
 
 
1343
        size += set_RecurrencePattern_size(&arp->RecurrencePattern);
 
1344
        for (i = 0; i < arp->ExceptionCount; i++) {
 
1345
                size += set_ExceptionInfo_size(arp->ExceptionInfo + i);
 
1346
                /* size += set_ExtendedException_size(arp->ExtendedException +
 
1347
                   i); */
 
1348
        }
 
1349
        size += arp->ReservedBlock1Size * sizeof(uint32_t);
 
1350
        /* size += arp->ReservedBlock2Size * sizeof(uint32_t); */
 
1351
 
 
1352
        return size;
 
1353
}
 
1354
 
 
1355
_PUBLIC_ struct Binary_r *set_AppointmentRecurrencePattern(TALLOC_CTX *mem_ctx, const struct AppointmentRecurrencePattern *arp)
 
1356
{
 
1357
        struct Binary_r                 *bin = NULL;
 
1358
        struct ndr_push                 *ndr;
 
1359
        enum ndr_err_code               ndr_err_code;
 
1360
        size_t                          bin_size;
 
1361
        
 
1362
        /* SANITY CHECKS */
 
1363
        if (!arp) return NULL;
 
1364
 
 
1365
        ndr = ndr_push_init_ctx(mem_ctx);
 
1366
        ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
 
1367
        ndr->offset = 0;
 
1368
        bin_size = set_AppointmentRecurrencePattern_size(arp);
 
1369
        talloc_free(ndr->data);
 
1370
        ndr->data = talloc_array(ndr, uint8_t, bin_size);
 
1371
 
 
1372
        ndr_err_code = ndr_push_AppointmentRecurrencePattern(ndr, NDR_SCALARS, arp);
 
1373
        if (ndr_err_code != NDR_ERR_SUCCESS) {
 
1374
                return NULL;
 
1375
        }
 
1376
 
 
1377
        bin = talloc_zero(mem_ctx, struct Binary_r);
 
1378
        bin->cb = bin_size;
 
1379
        bin->lpb = ndr->data;
 
1380
        talloc_steal(bin, bin->lpb);
 
1381
 
 
1382
        talloc_free(ndr);
 
1383
 
 
1384
        return bin;
 
1385
}
 
1386
 
 
1387
_PUBLIC_ size_t set_ExceptionInfo_size(const struct ExceptionInfo *exc_info)
 
1388
{
 
1389
        size_t size = SIZE_DFLT_EXCEPTIONINFO;
 
1390
 
 
1391
        if ((exc_info->OverrideFlags & ARO_SUBJECT)) {
 
1392
                size += 3 * sizeof(uint16_t); /* SubjectLength + SubjectLength2 + Subject */
 
1393
        }
 
1394
        if ((exc_info->OverrideFlags & ARO_MEETINGTYPE)) {
 
1395
                size += sizeof(uint32_t);
 
1396
        }
 
1397
        if ((exc_info->OverrideFlags & ARO_REMINDERDELTA)) {
 
1398
                size += sizeof(uint32_t);
 
1399
        }
 
1400
        if ((exc_info->OverrideFlags & ARO_REMINDER)) {
 
1401
                size += sizeof(uint32_t);
 
1402
        }
 
1403
        if ((exc_info->OverrideFlags & ARO_LOCATION)) {
 
1404
                size += 2 * sizeof(uint16_t); /* LocationLength + LocationLength2 */
 
1405
                size += sizeof(uint32_t); /* Location */
 
1406
        }
 
1407
        if ((exc_info->OverrideFlags & ARO_BUSYSTATUS)) {
 
1408
                size += sizeof(uint32_t);
 
1409
        }
 
1410
        if ((exc_info->OverrideFlags & ARO_ATTACHMENT)) {
 
1411
                size += sizeof(uint32_t);
 
1412
        }
 
1413
        if ((exc_info->OverrideFlags & ARO_SUBTYPE)) {
 
1414
                size += sizeof(uint32_t);
 
1415
        }
 
1416
        if ((exc_info->OverrideFlags & ARO_APPTCOLOR)) {
 
1417
                size += sizeof(uint32_t);
 
1418
        }
 
1419
 
 
1420
        return size;
 
1421
}
1058
1422
 
1059
1423
/**
1060
1424
   \details Retrieve a TimeZoneStruct structure from a binary blob
1102
1466
 
1103
1467
 
1104
1468
/**
 
1469
   \details Retrieve a PtypServerId structure from a binary blob
 
1470
 
 
1471
   \param mem_ctx pointer to the memory context
 
1472
   \param bin pointer to the Binary_r structure with raw PtypServerId data
 
1473
 
 
1474
   \return Allocated PtypServerId structure on success, otherwise
 
1475
   NULL
 
1476
 
 
1477
   \note Developers must free the allocated PtypServerId when
 
1478
   finished.
 
1479
 */
 
1480
_PUBLIC_ struct PtypServerId *get_PtypServerId(TALLOC_CTX *mem_ctx, struct Binary_r *bin)
 
1481
{
 
1482
        struct PtypServerId     *PtypServerId = NULL;
 
1483
        struct ndr_pull         *ndr;
 
1484
        enum ndr_err_code       ndr_err_code;
 
1485
 
 
1486
        /* Sanity checks */
 
1487
        if (!bin) return NULL;
 
1488
        if (!bin->cb) return NULL;
 
1489
        if (!bin->lpb) return NULL;
 
1490
 
 
1491
        ndr = talloc_zero(mem_ctx, struct ndr_pull);
 
1492
        ndr->offset = 0;
 
1493
        ndr->data = bin->lpb;
 
1494
        ndr->data_size = bin->cb;
 
1495
 
 
1496
        ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
 
1497
        PtypServerId = talloc_zero(mem_ctx, struct PtypServerId);
 
1498
        ndr_err_code = ndr_pull_PtypServerId(ndr, NDR_SCALARS, PtypServerId);
 
1499
 
 
1500
        talloc_free(ndr);
 
1501
 
 
1502
        if (ndr_err_code != NDR_ERR_SUCCESS) {
 
1503
                talloc_free(PtypServerId);
 
1504
                return NULL;
 
1505
        }
 
1506
 
 
1507
        return PtypServerId;
 
1508
}
 
1509
 
 
1510
/**
1105
1511
   \details Retrieve a GlobalObjectId structure from a binary blob
1106
1512
 
1107
1513
   \param mem_ctx pointer to the memory context
1146
1552
}
1147
1553
 
1148
1554
/**
 
1555
   \details Retrieve a MessageEntryId structure from a binary blob
 
1556
 
 
1557
   \param mem_ctx pointer to the memory context
 
1558
   \param bin pointer to the Binary_r structure with raw
 
1559
   MessageEntryId data
 
1560
 
 
1561
   \return Allocated MessageEntryId structure on success, otherwise
 
1562
   NULL
 
1563
 
 
1564
   \note Developers must free the allocated MessageEntryId when
 
1565
   finished.
 
1566
 */
 
1567
_PUBLIC_ struct MessageEntryId *get_MessageEntryId(TALLOC_CTX *mem_ctx, struct Binary_r *bin)
 
1568
{
 
1569
        struct MessageEntryId   *MessageEntryId = NULL;
 
1570
        struct ndr_pull         *ndr;
 
1571
        enum ndr_err_code       ndr_err_code;
 
1572
 
 
1573
        /* Sanity checks */
 
1574
        if (!bin) return NULL;
 
1575
        if (!bin->cb) return NULL;
 
1576
        if (!bin->lpb) return NULL;
 
1577
 
 
1578
        ndr = talloc_zero(mem_ctx, struct ndr_pull);
 
1579
        ndr->offset = 0;
 
1580
        ndr->data = bin->lpb;
 
1581
        ndr->data_size = bin->cb;
 
1582
 
 
1583
        ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
 
1584
        MessageEntryId = talloc_zero(mem_ctx, struct MessageEntryId);
 
1585
        ndr_err_code = ndr_pull_MessageEntryId(ndr, NDR_SCALARS, MessageEntryId);
 
1586
 
 
1587
        talloc_free(ndr);
 
1588
 
 
1589
        if (ndr_err_code != NDR_ERR_SUCCESS) {
 
1590
                talloc_free(MessageEntryId);
 
1591
                return NULL;
 
1592
        }
 
1593
 
 
1594
        return MessageEntryId;
 
1595
}
 
1596
 
 
1597
/**
 
1598
   \details Retrieve a FolderEntryId structure from a binary blob
 
1599
 
 
1600
   \param mem_ctx pointer to the memory context
 
1601
   \param bin pointer to the Binary_r structure with raw FolderEntryId data
 
1602
 
 
1603
   \return Allocated FolderEntryId structure on success, otherwise
 
1604
   NULL
 
1605
 
 
1606
   \note Developers must free the allocated FolderEntryId when
 
1607
   finished.
 
1608
 */
 
1609
_PUBLIC_ struct FolderEntryId *get_FolderEntryId(TALLOC_CTX *mem_ctx, struct Binary_r *bin)
 
1610
{
 
1611
        struct FolderEntryId    *FolderEntryId = NULL;
 
1612
        struct ndr_pull         *ndr;
 
1613
        enum ndr_err_code       ndr_err_code;
 
1614
 
 
1615
        /* Sanity checks */
 
1616
        if (!bin) return NULL;
 
1617
        if (!bin->cb) return NULL;
 
1618
        if (!bin->lpb) return NULL;
 
1619
 
 
1620
        ndr = talloc_zero(mem_ctx, struct ndr_pull);
 
1621
        ndr->offset = 0;
 
1622
        ndr->data = bin->lpb;
 
1623
        ndr->data_size = bin->cb;
 
1624
 
 
1625
        ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
 
1626
        FolderEntryId = talloc_zero(mem_ctx, struct FolderEntryId);
 
1627
        ndr_err_code = ndr_pull_FolderEntryId(ndr, NDR_SCALARS, FolderEntryId);
 
1628
 
 
1629
        talloc_free(ndr);
 
1630
 
 
1631
        if (ndr_err_code != NDR_ERR_SUCCESS) {
 
1632
                talloc_free(FolderEntryId);
 
1633
                return NULL;
 
1634
        }
 
1635
 
 
1636
        return FolderEntryId;
 
1637
}
 
1638
 
 
1639
/**
 
1640
   \details Retrieve a AddressBookEntryId structure from a binary blob
 
1641
 
 
1642
   \param mem_ctx pointer to the memory context
 
1643
   \param bin pointer to the Binary_r structure with raw AddressBookEntryId data
 
1644
 
 
1645
   \return Allocated AddressBookEntryId structure on success, otherwise NULL
 
1646
 
 
1647
   \note Developers must free the allocated AddressBookEntryId when finished.
 
1648
 */
 
1649
_PUBLIC_ struct AddressBookEntryId *get_AddressBookEntryId(TALLOC_CTX *mem_ctx, struct Binary_r *bin)
 
1650
{
 
1651
        struct AddressBookEntryId       *AddressBookEntryId = NULL;
 
1652
        struct ndr_pull                 *ndr;
 
1653
        enum ndr_err_code               ndr_err_code;
 
1654
 
 
1655
        /* Sanity checks */
 
1656
        if (!bin) return NULL;
 
1657
        if (!bin->cb) return NULL;
 
1658
        if (!bin->lpb) return NULL;
 
1659
 
 
1660
        ndr = talloc_zero(mem_ctx, struct ndr_pull);
 
1661
        ndr->offset = 0;
 
1662
        ndr->data = bin->lpb;
 
1663
        ndr->data_size = bin->cb;
 
1664
 
 
1665
        ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
 
1666
        AddressBookEntryId = talloc_zero(mem_ctx, struct AddressBookEntryId);
 
1667
        ndr_err_code = ndr_pull_AddressBookEntryId(ndr, NDR_SCALARS, AddressBookEntryId);
 
1668
 
 
1669
        talloc_free(ndr);
 
1670
 
 
1671
        if (ndr_err_code != NDR_ERR_SUCCESS) {
 
1672
                talloc_free(AddressBookEntryId);
 
1673
                return NULL;
 
1674
        }
 
1675
 
 
1676
        return AddressBookEntryId;
 
1677
}
 
1678
 
 
1679
/**
1149
1680
   \details Return the effective value used in a TypedString
1150
1681
   structure.
1151
1682