2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 #include "win32filter.h"
22 #define WIN32_STREAM_HEADER_SIZE 20 /* the size of the WIN32_STREAM_ID header without the name */
24 /* search in a record of a STREAM_WIN32_DATA for the true data
25 * when found: return true, '*raw' is set at the beginning of the data
26 * and *use_len is the length of data to read.
27 * *raw_len is decremented and contains the amount of data that as not
29 * For this STREAM_WIN32_DATA, you can call have_data() only one
31 * If the stream where the data is can be spread all around the stream
32 * you must call have_data() until *raw_len is zero and increment
33 * *data before the next call.
35 bool Win32Filter::have_data(char **raw, int64_t *raw_len, int64_t *use_len)
40 Dmsg1(100, "have_data(%lld)\n", *raw_len);
41 while (*raw_len > 0) {
42 /* In this rec, we could have multiple streams of data and headers
43 * to handle before to reach the data, then we must iterate
46 Dmsg4(100, "s off=%lld len=%lld skip_size=%lld data_size=%lld\n", *raw-orig, *raw_len, skip_size, data_size);
48 /* skip what the previous header told us to skip */
49 size = *raw_len < skip_size ? *raw_len : skip_size;
55 Dmsg4(100, "h off=%lld len=%lld skip_size=%lld data_size=%lld\n", *raw-orig, *raw_len, skip_size, data_size);
56 if (data_size == 0 && skip_size == 0 && *raw_len > 0) {
57 /* read a WIN32_STREAM header, merge it with the part that was read
58 * from the previous record, if any, if the header was split across
61 size = WIN32_STREAM_HEADER_SIZE - header_pos;
62 if (*raw_len < size) {
65 memcpy((char *)&header + header_pos, *raw, size);
69 if (header_pos == WIN32_STREAM_HEADER_SIZE) {
70 Dmsg5(100, "header pos=%d size=%lld name_size=%d len=%lld StreamId=0x%x\n", header_pos, size,
71 header.dwStreamNameSize, header.Size, header.dwStreamId);
73 skip_size = header.dwStreamNameSize; /* skip the name of the stream */
74 if (header.dwStreamId == WIN32_BACKUP_DATA) {
75 data_size = header.Size;
77 skip_size += header.Size; /* skip the all stream */
80 Dmsg4(100, "H off=%lld len=%lld skip_size=%lld data_size=%lld\n", *raw-orig, *raw_len, skip_size, data_size);
83 Dmsg4(100, "d off=%lld len=%lld skip_size=%lld data_size=%lld\n", *raw - orig, *raw_len, skip_size, data_size);
84 if (data_size > 0 && skip_size == 0 && *raw_len > 0) {
85 /* some data to read */
86 size = *raw_len < data_size ? *raw_len : data_size;
90 Dmsg5(100, "D off=%lld len=%lld use_len=%lld skip_size=%lld data_size=%lld\n", *raw-orig, *raw_len,
91 *use_len, skip_size, data_size);