2 Stand-alone MAPI testsuite
4 OpenChange Project - LZXPRESS compression/decompression
6 Copyright (C) Julien Kerihuel 2010
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/>.
22 #include "utils/mapitest/mapitest.h"
23 #include "utils/mapitest/proto.h"
24 #include "gen_ndr/ndr_exchange.h"
25 #include "libmapi/libmapi_private.h"
28 \file module_lzxpress.c
30 \brief LZXPRESS compression and decompression test suite
33 _PUBLIC_ bool mapitest_lzxpress_validate_test_001(struct mapitest *mt)
36 char *filename = NULL;
40 struct ndr_print *ndr_print;
41 struct ndr_pull *ndr_pull;
42 struct ndr_push *ndr_push;
43 struct ndr_push *ndr_comp;
44 struct ndr_push *ndr_rgbIn;
45 struct RPC_HEADER_EXT RPC_HEADER_EXT;
47 struct mapi2k7_request request;
49 enum ndr_err_code ndr_err;
51 /* Step 1. Load Test File 001_Outlook_2007_in_ModifyRecipients_comp.dat */
52 filename = talloc_asprintf(mt->mem_ctx, "%s/001_Outlook_2007_in_ModifyRecipients_comp.dat", LZXPRESS_DATADIR);
53 /* filename = talloc_asprintf(mt->mem_ctx, "%s/002_Outlook_2007_in_Tables_operations_comp.dat", LZXPRESS_DATADIR); */
54 data = (uint8_t *)file_load(filename, &size, 0, mt->mem_ctx);
57 mapitest_print_retval_fmt(mt, "lzxpress_validate", "Error while loading %s", filename);
58 talloc_free(filename);
63 mapitest_print_retval_step(mt, "1", "Loading 001_Outlook_2007_in_ModifyRecipients_comp.dat", MAPI_E_SUCCESS);
65 ndr_print = talloc_zero(mt->mem_ctx, struct ndr_print);
66 ndr_print->print = ndr_print_debug_helper;
69 /* Step 2. Pull 001_Outlook_2007_in_ModifyRecipients_comp.dat data */
70 ndr_pull = ndr_pull_init_blob(&blob, mt->mem_ctx);
71 ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
73 ndr_err = ndr_pull_EcDoRpcExt2(ndr_pull, NDR_IN, &r);
74 talloc_free(ndr_pull);
75 status = ndr_map_error2ntstatus(ndr_err);
76 if (NT_STATUS_IS_OK(status)) {
77 mapitest_print_retval_step(mt, "2", "001_Outlook_2007_in_ModifyRecipients_comp.dat",
80 mapitest_print_retval_step(mt, "2", "Pulling 001_Outlook_2007_in_ModifyRecipients_comp.dat",
85 /* Step 4. Decompress data */
86 blob.data = talloc_memdup(mt->mem_ctx, r.in.rgbIn, r.in.cbIn);
87 blob.length = r.in.cbIn;
88 ndr_pull = ndr_pull_init_blob(&blob, mt->mem_ctx);
89 ndr_set_flags(&ndr_pull->flags, LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_REF_ALLOC);
90 ndr_err = ndr_pull_mapi2k7_request(ndr_pull, NDR_SCALARS|NDR_BUFFERS, &request);
91 talloc_free(blob.data);
92 talloc_free(ndr_pull);
93 status = ndr_map_error2ntstatus(ndr_err);
94 if (NT_STATUS_IS_OK(status)) {
95 DEBUG(0, ("Success\n"));
98 /* Step 5. Recompress data */
99 ndr_push = ndr_push_init_ctx(mt->mem_ctx);
100 ndr_set_flags(&ndr_push->flags, LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_REF_ALLOC);
101 ndr_push_mapi_request(ndr_push, NDR_SCALARS|NDR_BUFFERS, request.mapi_request);
102 ndr_comp = ndr_push_init_ctx(mt->mem_ctx);
103 ndr_push_lzxpress_compress(ndr_comp, ndr_push);
105 /* Recreate complete blob */
106 ndr_rgbIn = ndr_push_init_ctx(mt->mem_ctx);
107 ndr_set_flags(&ndr_rgbIn->flags, LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_REF_ALLOC);
109 RPC_HEADER_EXT.Version = 0x0000;
110 RPC_HEADER_EXT.Flags = RHEF_Compressed|RHEF_Last;
111 RPC_HEADER_EXT.Size = ndr_comp->offset;
112 RPC_HEADER_EXT.SizeActual = ndr_push->offset;
113 ndr_push_RPC_HEADER_EXT(ndr_rgbIn, NDR_SCALARS|NDR_BUFFERS, &RPC_HEADER_EXT);
115 ndr_push_bytes(ndr_rgbIn, ndr_comp->data, ndr_comp->offset);
116 talloc_free(ndr_comp);
118 /* Compare Outlook and openchange rgbIn compressed blob */
119 DEBUG(0, ("Outlook compressed blob size = 0x%x\n", r.in.cbIn));
120 DEBUG(0, ("OpenChange compressed blob size = 0x%x\n", ndr_rgbIn->offset));
126 min = (ndr_rgbIn->offset >= r.in.cbIn) ? r.in.cbIn : ndr_rgbIn->offset;
127 DEBUG(0, ("Comparing Outlook and OpenChange blobs on 0x%x bytes\n", min));
128 for (i = 0; i < min; i++) {
129 if (r.in.rgbIn[i] != ndr_rgbIn->data[i]) {
130 DEBUG(0, ("Bytes differs at offset 0x%x: Outlook (0x%.2x) OpenChange (0x%.2x)\n",
131 i, r.in.rgbIn[i], ndr_rgbIn->data[i]));
138 mapitest_print(mt, "Compressed rgbIn by Outlook\n");
139 mapitest_print(mt, "==============================\n");
140 dump_data(0, r.in.rgbIn, r.in.cbIn);
141 mapitest_print(mt, "==============================\n");
143 mapitest_print(mt, "Compressed rgbIn by OpenChange\n");
144 mapitest_print(mt, "==============================\n");
145 dump_data(0, ndr_rgbIn->data, ndr_rgbIn->offset);
146 mapitest_print(mt, "==============================\n");
148 talloc_free(ndr_rgbIn);