1/******************************************************
2Copyright (c) 2011-2017 Percona LLC and/or its affiliates.
3
4The xbstream format interface.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
19*******************************************************/
20
21#ifndef XBSTREAM_H
22#define XBSTREAM_H
23
24#include <my_base.h>
25
26/* Magic value in a chunk header */
27#define XB_STREAM_CHUNK_MAGIC "XBSTCK01"
28
29/* Chunk flags */
30/* Chunk can be ignored if unknown version/format */
31#define XB_STREAM_FLAG_IGNORABLE 0x01
32
33/* Magic + flags + type + path len */
34#define CHUNK_HEADER_CONSTANT_LEN ((sizeof(XB_STREAM_CHUNK_MAGIC) - 1) + \
35 1 + 1 + 4)
36#define CHUNK_TYPE_OFFSET (sizeof(XB_STREAM_CHUNK_MAGIC) - 1 + 1)
37#define PATH_LENGTH_OFFSET (sizeof(XB_STREAM_CHUNK_MAGIC) - 1 + 1 + 1)
38
39typedef struct xb_wstream_struct xb_wstream_t;
40
41typedef struct xb_wstream_file_struct xb_wstream_file_t;
42
43typedef enum {
44 XB_STREAM_FMT_NONE,
45 XB_STREAM_FMT_XBSTREAM
46} xb_stream_fmt_t;
47
48/************************************************************************
49Write interface. */
50
51typedef ssize_t xb_stream_write_callback(xb_wstream_file_t *file,
52 void *userdata,
53 const void *buf, size_t len);
54
55xb_wstream_t *xb_stream_write_new(void);
56
57xb_wstream_file_t *xb_stream_write_open(xb_wstream_t *stream, const char *path,
58 MY_STAT *mystat, void *userdata,
59 xb_stream_write_callback *onwrite);
60
61int xb_stream_write_data(xb_wstream_file_t *file, const void *buf, size_t len);
62
63int xb_stream_write_close(xb_wstream_file_t *file);
64
65int xb_stream_write_done(xb_wstream_t *stream);
66
67/************************************************************************
68Read interface. */
69
70typedef enum {
71 XB_STREAM_READ_CHUNK,
72 XB_STREAM_READ_EOF,
73 XB_STREAM_READ_ERROR
74} xb_rstream_result_t;
75
76typedef enum {
77 XB_CHUNK_TYPE_UNKNOWN = '\0',
78 XB_CHUNK_TYPE_PAYLOAD = 'P',
79 XB_CHUNK_TYPE_EOF = 'E'
80} xb_chunk_type_t;
81
82typedef struct xb_rstream_struct xb_rstream_t;
83
84typedef struct {
85 uchar flags;
86 xb_chunk_type_t type;
87 uint pathlen;
88 char path[FN_REFLEN];
89 size_t length;
90 my_off_t offset;
91 my_off_t checksum_offset;
92 void *data;
93 ulong checksum;
94 size_t buflen;
95} xb_rstream_chunk_t;
96
97xb_rstream_t *xb_stream_read_new(void);
98
99xb_rstream_result_t xb_stream_read_chunk(xb_rstream_t *stream,
100 xb_rstream_chunk_t *chunk);
101
102int xb_stream_read_done(xb_rstream_t *stream);
103
104int xb_stream_validate_checksum(xb_rstream_chunk_t *chunk);
105
106#endif
107