server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / mapiproxy / libmapiserver / libmapiserver_oxcdata.c
1 /*
2    libmapiserver - MAPI library for Server side
3
4    OpenChange Project
5
6    Copyright (C) Julien Kerihuel 2010
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /**
23    \file libmapiserver_oxcdata.c
24
25    \brief OXCDATA Data Structures
26  */
27
28 #include "libmapiserver.h"
29
30 /**
31    \details Calculate the size of a TypedString structure
32
33    \param typedstring TypedString structure
34
35    \return Size of typedstring structure
36  */
37 _PUBLIC_ uint16_t libmapiserver_TypedString_size(struct TypedString typedstring)
38 {
39         uint16_t        size = 0;
40
41         size += sizeof (uint8_t);
42
43         switch (typedstring.StringType) {
44         case StringType_NONE:
45         case StringType_EMPTY:
46                 break;
47         case StringType_STRING8:
48                 if (typedstring.String.lpszA) {
49                         size += strlen(typedstring.String.lpszA) + 1;
50                 }
51                 break;
52         case StringType_UNICODE_REDUCED:
53                 if (typedstring.String.lpszW_reduced) {
54                         size += strlen(typedstring.String.lpszW_reduced) + 1;
55                 }
56                 break;
57         case StringType_UNICODE:
58                 if (typedstring.String.lpszW) {
59                         size += strlen(typedstring.String.lpszW) * 2 + 2;
60                 }
61                 break;
62         }
63
64         return size;
65 }
66
67
68 /**
69    \details Calculate the size of a RecipientRow structure
70
71    \param recipientrow RecipientRow structure
72
73    \return Size of RecipientRow structure
74  */
75 _PUBLIC_ uint16_t libmapiserver_RecipientRow_size(struct RecipientRow recipientrow)
76 {
77         uint16_t        size = 0;
78
79         /* RecipientFlags */
80         size += sizeof (uint16_t);
81
82         /* recipient_type */
83         if (recipientrow.RecipientFlags & 0x1) {
84                 size += sizeof (uint8_t) * 2; /* AddressPrefixUsed + DisplayType */
85                 size += strlen(recipientrow.X500DN.recipient_x500name) + 1;
86         }
87
88         /* recipient_EmailAddress */
89         switch (recipientrow.RecipientFlags & 0x208) {
90         case 0x8:
91                 size += strlen(recipientrow.EmailAddress.lpszA);
92                 break;
93         case 0x208:
94                 size += strlen(recipientrow.EmailAddress.lpszW) * 2 + 2;
95                 break;
96         default:
97                 break;
98         }
99
100         /* recipient_DisplayName */
101         switch (recipientrow.RecipientFlags & 0x210) {
102         case 0x10:
103                 size += strlen(recipientrow.DisplayName.lpszA);
104                 break;
105         case 0x210:
106                 size += strlen(recipientrow.DisplayName.lpszW) * 2 + 2;
107                 break;
108         default:
109                 break;
110         }
111
112         /* recipient_SimpleDisplayName */
113         switch (recipientrow.RecipientFlags & 0x600) {
114         case 0x400:
115                 size += strlen(recipientrow.SimpleDisplayName.lpszA);
116                 break;
117         case 0x600:
118                 size += strlen(recipientrow.SimpleDisplayName.lpszW) * 2 + 2;
119                 break;
120         default:
121                 break;
122         }
123
124         /* recipient_TransmittableDisplayName */
125         switch (recipientrow.RecipientFlags & 0x260) {
126         case 0x20:
127                 size += strlen(recipientrow.TransmittableDisplayName.lpszA);
128                 break;
129         case 0x220:
130                 size += strlen(recipientrow.TransmittableDisplayName.lpszW) * 2 + 2;
131                 break;
132         default:
133                 break;
134         }
135
136         /* prop_count */
137         size += sizeof (uint16_t);
138
139         /* layout */
140         size += sizeof (uint8_t);
141
142         /* prop_values */
143         size += sizeof (uint16_t);
144         size += recipientrow.prop_values.length;
145
146         return size;
147 }
148
149
150 /**
151    \details Calculate the size of a LongTermId structure
152
153    \return Size of LongTermId structure
154  */
155 _PUBLIC_ uint16_t libmapiserver_LongTermId_size(void)
156 {
157         return SIZE_DFLT_LONGTERMID;
158 }