aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/api/lzma/extra.h
blob: 29426a741bbe4600deed72920e074fa80ae5a039 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
 * \file        lzma/extra.h
 * \brief       Handling of Extra Records in Metadata
 *
 * \author      Copyright (C) 1999-2006 Igor Pavlov
 * \author      Copyright (C) 2007 Lasse Collin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

#ifndef LZMA_H_INTERNAL
#	error Never include this file directly. Use <lzma.h> instead.
#endif


/*
 * Extra Record IDs
 *
 * See the .lzma file format specification for description what each
 * Extra Record type exactly means.
 *
 * If you ever need to update .lzma files with Extra Records, note that
 * the Record IDs are divided in two categories:
 *  - Safe-to-Copy Records may be preserved as is when the
 *    Stream is modified in ways that don't change the actual
 *    uncompressed data. Examples of such operatings include
 *    recompressing and adding, modifying, or deleting unrelated
 *    Extra Records.
 *  - Unsafe-to-Copy Records should be removed (and possibly
 *    recreated) when any kind of changes are made to the Stream.
 */

#define LZMA_EXTRA_PADDING      0x00
#define LZMA_EXTRA_OPENPGP      0x01
#define LZMA_EXTRA_FILTERS      0x02
#define LZMA_EXTRA_COMMENT      0x03
#define LZMA_EXTRA_CHECKS       0x04
#define LZMA_EXTRA_FILENAME     0x05
#define LZMA_EXTRA_MTIME        0x07
#define LZMA_EXTRA_MTIME_HR     0x09
#define LZMA_EXTRA_MIME_TYPE    0x0B
#define LZMA_EXTRA_HOMEPAGE     0x0D


/**
 * \brief       Extra Records
 *
 * The .lzma format provides a way to store custom information along
 * the actual compressed content. Information about these Records
 * are passed to and from liblzma via this linked list.
 */
typedef struct lzma_extra_s lzma_extra;
struct lzma_extra_s {
	/**
	 * \brief       Pointer to the next Extra Record
	 *
	 * This is NULL on the last Extra Record.
	 */
	lzma_extra *next;

	/**
	 * \brief       Record ID
	 *
	 * Extra Record IDs are divided in three categories:
	 *   - Zero is a special case used for padding. It doesn't have
	 *     Size of Data fields.
	 *   - Odd IDs (1, 3, 5, ...) are Safe-to-Copy IDs.
	 *     These can be preserved as is if the Stream is
	 *     modified in a way that doesn't alter the actual
	 *     uncompressed content.
	 *   - Even IDs (2, 4, 6, ...) are Unsafe-to-Copy IDs.
	 *     If the .lzma Stream is modified in any way,
	 *     the Extra Records having a sensitive ID should
	 *     be removed or updated accordingly.
	 *
	 * Refer to the .lzma file format specification for
	 * the up to date list of Extra Record IDs.
	 */
	lzma_vli id;

	/**
	 * \brief       Size of the Record data
	 *
	 * In case of strings, this should not include the
	 * trailing '\0'.
	 */
	size_t size;

	/**
	 * \brief       Record data
	 *
	 * Record data is often a string in UTF-8 encoding,
	 * but it can be arbitrary binary data. In case of
	 * strings, the trailing '\0' is usually not stored
	 * in the .lzma file.
	 *
	 * To ease working with Extra Records containing strings,
	 * liblzma always adds '\0' to the end of data even when
	 * it wasn't present in the .lzma file. This '\0' is not
	 * counted in the size of the data.
	 */
	uint8_t *data;
};


extern void lzma_extra_free(lzma_extra *extra, lzma_allocator *allocator);