2 libmapiserver - MAPI library for Server side
6 Copyright (C) Julien Kerihuel 2009
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.
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.
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/>.
23 \file libmapiserver_oxcprpt.c
25 \brief OXCPRPT ROP Response size calculations
28 #include "libmapiserver.h"
29 #include "libmapi/libmapi.h"
30 #include "libmapi/mapidefs.h"
31 #include "gen_ndr/ndr_exchange.h"
32 #include <util/debug.h>
35 \details Calculate GetPropertiesSpecific Rop size
37 \param request pointer to the GetPropertiesSpecific
38 EcDoRpc_MAPI_REQ structure
39 \param response pointer to the GetPropertiesSpecific
40 EcDoRpc_MAPI_REPL structure
42 \return Size of GetPropsSpecific response
44 _PUBLIC_ uint16_t libmapiserver_RopGetPropertiesSpecific_size(struct EcDoRpc_MAPI_REQ *request,
45 struct EcDoRpc_MAPI_REPL *response)
47 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
49 if (!response || response->error_code) {
53 size += SIZE_DFLT_ROPGETPROPERTIESSPECIFIC;
54 size += response->u.mapi_GetProps.prop_data.length;
61 \details Calculate SetProperties Rop size
63 \param response pointer to the SetProperties EcDoRpc_MAPI_REPL
66 \return Size of SetProperties response
68 _PUBLIC_ uint16_t libmapiserver_RopSetProperties_size(struct EcDoRpc_MAPI_REPL *response)
70 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
72 if (!response || response->error_code) {
76 size += SIZE_DFLT_ROPSETPROPERTIES;
78 if (response->u.mapi_SetProps.PropertyProblemCount) {
79 size += response->u.mapi_SetProps.PropertyProblemCount * sizeof(struct PropertyProblem);
87 \details Calculate SetProperties Rop size
89 \param response pointer to the SetProperties EcDoRpc_MAPI_REPL
92 \return Size of SetProperties response
94 _PUBLIC_ uint16_t libmapiserver_RopDeleteProperties_size(struct EcDoRpc_MAPI_REPL *response)
96 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
98 if (!response || response->error_code) {
102 size += SIZE_DFLT_ROPDELETEPROPERTIES;
104 if (response->u.mapi_DeleteProps.PropertyProblemCount) {
105 size += response->u.mapi_DeleteProps.PropertyProblemCount * sizeof(struct PropertyProblem);
113 \details Calculate OpenStream Rop size
115 \param response pointer to the OpenStream EcDoRpc_MAPI_REPL
118 \return Size of OpenStream response
120 _PUBLIC_ uint16_t libmapiserver_RopOpenStream_size(struct EcDoRpc_MAPI_REPL *response)
122 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
124 if (!response || response->error_code) {
128 size += SIZE_DFLT_ROPOPENSTREAM;
135 \details Calculate ReadStream Rop size
137 \param response pointer to the ReadStream EcDoRpc_MAPI_REPL
140 \return Size of ReadStream response
142 _PUBLIC_ uint16_t libmapiserver_RopReadStream_size(struct EcDoRpc_MAPI_REPL *response)
144 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
146 if (!response || response->error_code) {
150 size += SIZE_DFLT_ROPREADSTREAM;
152 if (response->u.mapi_ReadStream.data.length) {
153 size += response->u.mapi_ReadStream.data.length;
161 \details Calculate WriteStream Rop size
163 \param response pointer to the WriteStream EcDoRpc_MAPI_REPL
166 \return Size of WriteStream response
168 _PUBLIC_ uint16_t libmapiserver_RopWriteStream_size(struct EcDoRpc_MAPI_REPL *response)
170 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
172 if (!response || response->error_code) {
176 size += SIZE_DFLT_ROPWRITESTREAM;
183 \details Calculate GetStreamSize Rop size
185 \param response pointer to the GetStreamSize
186 EcDoRpc_MAPI_REPL structure
188 \return Size of GetStreamSize response
190 _PUBLIC_ uint16_t libmapiserver_RopGetStreamSize_size(struct EcDoRpc_MAPI_REPL *response)
192 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
194 if (!response || response->error_code) {
198 size += SIZE_DFLT_ROPGETSTREAMSIZE;
205 \details Calculate GetPropertyIdsFromNames Rop size
207 \param response pointer to the GetPropertyIdsFromNames
208 EcDoRpc_MAPI_REPL structure
210 \return Size of GetPropertyIdsFromNames response
212 _PUBLIC_ uint16_t libmapiserver_RopGetPropertyIdsFromNames_size(struct EcDoRpc_MAPI_REPL *response)
214 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
216 if (!response || response->error_code) {
220 size += SIZE_DFLT_ROPGETPROPERTYIDSFROMNAMES;
222 if (response->u.mapi_GetIDsFromNames.count) {
223 size += response->u.mapi_GetIDsFromNames.count * sizeof (uint16_t);
231 \details Calculate DeletePropertiesNoReplicate Rop size
233 \param response pointer to the DeletePropertiesNoReplicate
234 EcDoRpc_MAPI_REPL structure
236 \return Size of DeletePropertiesNoReplicate response
238 _PUBLIC_ uint16_t libmapiserver_RopDeletePropertiesNoReplicate_size(struct EcDoRpc_MAPI_REPL *response)
240 uint16_t size = SIZE_DFLT_MAPI_RESPONSE;
242 if (!response || response->error_code) {
246 size += SIZE_DFLT_ROPDELETEPROPERTIESNOREPLICATE;
247 size += (response->u.mapi_DeletePropertiesNoReplicate.PropertyProblemCount
248 * (sizeof(uint16_t) /* PropertyProblem.Index */
249 + sizeof(uint32_t) /* PropertyProblem.PropertyTag */
250 + sizeof(uint32_t) /* PropertyProblem.ErrorCode */));
257 \details Add a property value to a DATA blob. This convenient
258 function should be used when creating a GetPropertiesSpecific reply
261 \param mem_ctx pointer to the memory context
262 \param iconv_convenience pointer to the iconv_convenience context
263 \param property the property tag which value is meant to be
265 \param value generic pointer on the property value
266 \param blob the data blob the function uses to return the blob
267 \param layout whether values should be prefixed by a layout
268 \param flagged define if the properties are flagged or not
270 \note blob.length must be set to 0 before this function is called
271 the first time. Also the function only supports a limited set of
272 property types at the moment.
274 \return 0 on success;
276 _PUBLIC_ int libmapiserver_push_property(TALLOC_CTX *mem_ctx,
277 struct smb_iconv_convenience *iconv_convenience,
284 struct ndr_push *ndr;
286 ndr = ndr_push_init_ctx(mem_ctx);
287 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
290 talloc_free(ndr->data);
291 ndr->data = blob->data;
292 ndr->offset = blob->length;
295 /* Step 1. Is the property flagged */
297 switch (property & 0xFFFF) {
301 ndr_push_uint8(ndr, NDR_SCALARS, layout);
304 ndr_push_uint8(ndr, NDR_SCALARS, PT_ERROR);
309 ndr_push_uint8(ndr, NDR_SCALARS, 0x0);
313 /* Step 2. Set the layout */
315 switch (property & 0xFFFF) {
317 ndr_push_uint8(ndr, NDR_SCALARS, PT_ERROR);
320 ndr_push_uint8(ndr, NDR_SCALARS, 0x0);
325 /* Step 2. Push property data if supported */
326 switch (property & 0xFFFF) {
328 ndr_push_uint16(ndr, NDR_SCALARS, *(uint16_t *) value);
333 ndr_push_uint32(ndr, NDR_SCALARS, *(uint32_t *) value);
336 ndr_push_double(ndr, NDR_SCALARS, *(double *) value);
339 ndr_push_dlong(ndr, NDR_SCALARS, *(uint64_t *) value);
342 ndr_push_uint8(ndr, NDR_SCALARS, *(uint8_t *) value);
345 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM|LIBNDR_FLAG_STR_ASCII);
346 ndr_push_string(ndr, NDR_SCALARS, (char *) value);
349 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_STR_NULLTERM);
350 ndr_push_string(ndr, NDR_SCALARS, (char *) value);
353 ndr_push_SBinary_short(ndr, NDR_SCALARS, (struct SBinary_short *) value);
356 ndr_push_GUID(ndr, NDR_SCALARS, (struct GUID *) value);
359 ndr_push_FILETIME(ndr, NDR_SCALARS, (struct FILETIME *) value);
365 /* Step 3. Steal ndr context */
366 blob->data = ndr->data;
367 talloc_steal(mem_ctx, blob->data);
368 blob->length = ndr->offset;
376 \details Turn request parameters to SPropValue array. This
377 convenient function should be used among MAPI ROPs that have
378 parameters which can be turned to MAPI properties and are stored
381 \param mem_ctx pointer to the memory context
382 \param request generic pointer to the ROP request
383 \param opnum MAPI opnum identifying ROP contents
385 \note Developers must talloc_free returned SRow after they finish
388 \return Allocated SRow on success, otherwise NULL
390 _PUBLIC_ struct SRow *libmapiserver_ROP_request_to_properties(TALLOC_CTX *mem_ctx,
395 struct CreateFolder_req *CreateFolder_req;
397 aRow = talloc_zero(mem_ctx, struct SRow);
398 aRow->lpProps = talloc_array(aRow, struct SPropValue, 2);
402 case op_MAPI_CreateFolder:
403 CreateFolder_req = (struct CreateFolder_req *) request;
404 aRow->lpProps = add_SPropValue(mem_ctx, aRow->lpProps, &(aRow->cValues),
405 PR_FOLDER_TYPE, (void *)&(CreateFolder_req->ulFolderType));
406 switch (CreateFolder_req->ulType) {
407 case MAPI_FOLDER_ANSI:
408 aRow->lpProps = add_SPropValue(mem_ctx, aRow->lpProps, &(aRow->cValues),
409 PR_DISPLAY_NAME, (void *)(CreateFolder_req->FolderName.lpszA));
410 aRow->lpProps = add_SPropValue(mem_ctx, aRow->lpProps, &(aRow->cValues),
411 PR_COMMENT, (void *)(CreateFolder_req->FolderComment.lpszA));
413 case MAPI_FOLDER_UNICODE:
414 aRow->lpProps = add_SPropValue(mem_ctx, aRow->lpProps, &(aRow->cValues),
415 PR_DISPLAY_NAME_UNICODE, (void *)(CreateFolder_req->FolderName.lpszW));
416 aRow->lpProps = add_SPropValue(mem_ctx, aRow->lpProps, &(aRow->cValues),
417 PR_COMMENT_UNICODE, (void *)(CreateFolder_req->FolderComment.lpszW));
423 DEBUG(0, ("[%s:%d]: opnum %d not implemented yet\n", __FUNCTION__, __LINE__, opnum));