server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / mapiproxy / libmapiserver / libmapiserver_oxcstor.c
1 /*
2    libmapiserver - MAPI library for Server side
3
4    OpenChange Project
5
6    Copyright (C) Julien Kerihuel 2009
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_oxcstor.c
24
25    \brief OXCSTOR ROP Response size calculations
26  */
27
28 #include "libmapiserver.h"
29 #include <string.h>
30
31 /**
32    \details Calculate Logon Rop size
33
34    \param request pointer to the Logon EcDoRpc_MAPI_REQ structure
35    \param response pointer to the Logon EcDoRpc_MAPI_REPL structure
36
37    \return Size of Logon response
38  */
39 _PUBLIC_ uint16_t libmapiserver_RopLogon_size(struct EcDoRpc_MAPI_REQ *request,
40                                               struct EcDoRpc_MAPI_REPL *response)
41 {
42         uint16_t        size = SIZE_DFLT_MAPI_RESPONSE;
43
44         if (!response || (response->error_code && response->error_code != ecWrongServer)) {
45                 return size;
46         }
47
48         if (response->error_code == ecWrongServer) {
49                 size += SIZE_DFLT_ROPLOGON_REDIRECT;
50                 size += strlen (response->us.mapi_Logon.ServerName) + 1;
51                 return size;
52         }
53
54         if (request->u.mapi_Logon.LogonFlags & LogonPrivate) {
55                 size += SIZE_DFLT_ROPLOGON_MAILBOX;
56         } else {
57                 size += SIZE_DFLT_ROPLOGON_PUBLICFOLDER;
58         }
59         return size;
60 }
61
62
63 /**
64    \details Calculate SetReceiveFolder (0x26) Rop size
65
66    \param response pointer to the SetReceiveFolder EcDoRpc_MAPI_REPL
67    structure
68
69    \return Size of SetReceiveFolder response
70  */
71 _PUBLIC_ uint16_t libmapiserver_RopSetReceiveFolder_size(struct EcDoRpc_MAPI_REPL *response)
72 {
73         return SIZE_DFLT_MAPI_RESPONSE;
74 }
75
76
77 /**
78    \details Calculate GetReceiveFolder Rop size
79
80    \param response pointer to the GetReceiveFolder EcDoRpc_MAPI_REPL structure
81
82    \return Size of GetReceiveFolder response
83  */
84 _PUBLIC_ uint16_t libmapiserver_RopGetReceiveFolder_size(struct EcDoRpc_MAPI_REPL *response)
85 {
86         uint16_t        size = SIZE_DFLT_MAPI_RESPONSE;
87
88         if (!response || response->error_code) {
89                 return size;
90         }
91
92         size += SIZE_DFLT_ROPGETRECEIVEFOLDER;
93         size += strlen(response->u.mapi_GetReceiveFolder.MessageClass) + 1;
94
95         return size;
96 }
97
98
99 /**
100    \details Calculate GetPerUserLongTermIds Rop size
101
102    \param response pointer to the GetPerUserLongTermIds EcDoRpc_MAPI_REPL structure
103
104    \return Size of GetPerUserLongTermIds response
105  */
106 _PUBLIC_ uint16_t libmapiserver_RopGetPerUserLongTermIds_size(struct EcDoRpc_MAPI_REPL *response)
107 {
108         uint16_t        size = SIZE_DFLT_MAPI_RESPONSE;
109         uint16_t        i;
110
111         if (!response || response->error_code) {
112                 return size;
113         }
114
115         size += SIZE_DFLT_ROPGETPERUSERLONGTERMIDS;
116
117         for (i = 0; i < response->u.mapi_GetPerUserLongTermIds.LongTermIdCount; i++) {
118                 size += libmapiserver_LongTermId_size();
119         }
120         
121
122         return size;
123 }
124
125 /**
126    \details Calculate ReadPerUserInformation Rop size
127
128    \param response pointer to the ReadPerUserInformation EcDoRpc_MAPI_REPL structure
129
130    \return Size of ReadPerUserInformation response
131  */
132 _PUBLIC_ uint16_t libmapiserver_RopReadPerUserInformation_size(struct EcDoRpc_MAPI_REPL *response)
133 {
134         uint16_t        size = SIZE_DFLT_MAPI_RESPONSE;
135
136         if (!response || response->error_code) {
137                 return size;
138         }
139
140         size += SIZE_DFLT_ROPREADPERUSERINFORMATION;
141
142         if (response->u.mapi_ReadPerUserInformation.DataSize) {
143                 size += response->u.mapi_ReadPerUserInformation.DataSize;
144         }
145
146         return size;
147 }
148
149 /**
150    \details Calculate GetPerUserLongTermIds Rop size
151
152    \param response pointer to the GetPerUserLongTermIds EcDoRpc_MAPI_REPL structure
153
154    \return Size of GetPerUserLongTermIds response
155  */
156 _PUBLIC_ uint16_t libmapiserver_RopGetPerUserGuid_size(struct EcDoRpc_MAPI_REPL *response)
157 {
158         uint16_t        size = SIZE_DFLT_MAPI_RESPONSE;
159
160         if (!response || response->error_code) {
161                 return size;
162         }
163
164         size += SIZE_DFLT_ROPGETPERUSERGUID;
165
166         return size;
167 }
168
169 /**
170    \details Calculate GetReceiveFolderTable ROP size
171
172    \param response pointer to the GetReceiveFolderTable EcDoRpc_MAPI_REPL structure
173
174    \return Size of GetPerUserLongTermIds response
175  */
176 _PUBLIC_ uint16_t libmapiserver_RopGetReceiveFolderTable_size(struct EcDoRpc_MAPI_REPL *response)
177 {
178         uint32_t        i = 0;
179         uint16_t        size = SIZE_DFLT_MAPI_RESPONSE;
180
181         if (!response || response->error_code) {
182                 return size;
183         }
184
185         size += sizeof(uint32_t); /* cValues */
186         for (i = 0; i < response->u.mapi_GetReceiveFolderTable.cValues; ++i) {
187                 size += sizeof(uint8_t); /* flag */
188                 size += sizeof(uint64_t); /* fid */
189                 size += strlen(response->u.mapi_GetReceiveFolderTable.entries[i].lpszMessageClass) + 1;
190                 size += sizeof(struct FILETIME); /* modiftime */
191         }
192
193         return size;
194 }