1 #ifndef _YYDECODE_H
2 #define _YYDECODE_H 1
3 
4 #define lenof(str) (sizeof(str) - sizeof(char))
5 
6 #define UUMARKER_BEGIN	"begin "
7 #define UUMARKER_END	"end\n"
8 #define B64MARKER_BEGIN	"begin-base64 "
9 #define B64MARKER_END	"===="
10 
11 #define YMARKER_BEGIN	"=ybegin "
12 #define YMARKER_PART	"=ypart "
13 #define YMARKER_END	"=yend "
14 
15 #define YTAG_PART	" part="
16 #define YTAG_TOTAL	" total="
17 #define YTAG_LINE	" line="
18 #define YTAG_SIZE	" size="
19 #define YTAG_NAME	" name="
20 #define YTAG_BEGIN	" begin="
21 #define YTAG_END	" end="
22 #define YTAG_PCRC32	" pcrc32="
23 #define YTAG_CRC32	" crc32="
24 
25 #define YYDEC_BROKEN_SUFFIX	".broken"
26 
27 /* 8MB for each part */
28 #define PART_SIZE_SOFT_LIMIT	(1 << 23)
29 
30 /* EXIT_SUCCESS = 0, EXIT_FAILURE = 1 */
31 #define EXIT_WARNING	2
32 #define EXIT_EOF	3
33 
34 enum part_status
35 {
36 	part_missing = 0,
37 	part_intact,
38 	part_duplicated,
39 	part_broken
40 };
41 
42 struct decoded_file
43 {
44 	struct decoded_file *next;
45 
46 	/* used only as a key for decoded_filename lookup ... */
47 	char *	filename;
48 	/* ... anything else shall use the following, to avoid user confusion */
49 	char *	outname;
50 	int	mode;
51 	/* if set, ignore this file (can't write to the file for some reason) */
52 	int	previously_existed;
53 
54 	/* zero on the first run */
55 	int	is_seekable;
56 
57 	FILE *	handle;
58 	off_t	bytes_written;
59 
60 	off_t	total_size;
61 	int	total_parts;
62 	enum part_status *status;
63 
64 	/* Follow an optimistic strategy, and assume that most of the time,
65 	 * we'll receive the parts in order, so we do not need to make another
66 	 * pass over the output file to calculate the file CRC. If we get parts
67 	 * out of order, then set crc32_prev_part = -1; we'll have to make a
68 	 * pass over the entire file later on. */
69 
70 	int	crc32_prev_part;
71 	struct crc32_ctx crc32_context;
72 	u_int32_t crc32;
73 };
74 
75 struct decode_context
76 {
77 	const char *inname;
78 	char *out;
79 	size_t out_size;
80 
81 	int part;
82 	int total_parts;
83 	enum part_status status;
84 };
85 
86 typedef int (*read_enc)(struct decode_context *c, struct decoded_file *f, char *buf);
87 
88 #endif /* _YYDECODE_H */
89 
90