aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/api/lzma
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-09-12 22:41:40 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-09-12 22:41:40 +0300
commit320601b2c7b08fc7da9da18d5bf7c3c1a189b080 (patch)
tree3846af51e6904d900e5cd8337baf0728a42a07fe /src/liblzma/api/lzma
parentSimplified debug/known_sizes.c to match the relaxed (diff)
downloadxz-320601b2c7b08fc7da9da18d5bf7c3c1a189b080.tar.xz
Improved the Stream Flags handling API.
Diffstat (limited to 'src/liblzma/api/lzma')
-rw-r--r--src/liblzma/api/lzma/stream_flags.h84
1 files changed, 80 insertions, 4 deletions
diff --git a/src/liblzma/api/lzma/stream_flags.h b/src/liblzma/api/lzma/stream_flags.h
index 80c5f00f..bb080ac7 100644
--- a/src/liblzma/api/lzma/stream_flags.h
+++ b/src/liblzma/api/lzma/stream_flags.h
@@ -36,8 +36,37 @@
*/
typedef struct {
/**
+ * \brief Stream Flags format version
+ *
+ * To prevent API and ABI breakages if new features are needed in
+ * Stream Header or Stream Footer, a version number is used to
+ * indicate which fields in this structure are in use. For now,
+ * version must always be zero. With non-zero version, the
+ * lzma_stream_header_encode() and lzma_stream_footer_encode()
+ * will return LZMA_HEADER_ERROR.
+ *
+ * lzma_stream_header_decode() and lzma_stream_footer_decode()
+ * will always set this to the lowest value that supports all the
+ * features indicated by the Stream Flags field. The application
+ * must check that the version number set by the decoding functions
+ * is supported by the application. Otherwise it is possible that
+ * the application will decode the Stream incorrectly.
+ */
+ uint32_t version;
+
+ /**
* Backward Size must be a multiple of four bytes. In this Stream
* format version Backward Size is the size of the Index field.
+ *
+ * Backward Size isn't actually part of the Stream Flags field, but
+ * it is convenient to include in this structure anyway. Backward
+ * Size is present only in the Stream Footer. There is no need to
+ * initialize backward_size when encoding Stream Header.
+ *
+ * lzma_stream_header_decode() always sets backward_size to
+ * LZMA_VLI_VALUE_UNKNOWN so that it is convenient to use
+ * lzma_stream_flags_compare() when both Stream Header and Stream
+ * Footer have been decoded.
*/
lzma_vli backward_size;
# define LZMA_BACKWARD_SIZE_MIN 4
@@ -48,6 +77,34 @@ typedef struct {
*/
lzma_check check;
+ /**
+ * Reserved space to allow possible future extensions without
+ * breaking the ABI. You should not touch these, because the
+ * names of these variables may change.
+ *
+ * (We will never be able to use all of these since Stream Flags
+ * is just two bytes plus Backward Size of four bytes. But it's
+ * nice to have the proper types when they are needed.)
+ */
+ lzma_reserved_enum reserved_enum1;
+ lzma_reserved_enum reserved_enum2;
+ lzma_reserved_enum reserved_enum3;
+ lzma_reserved_enum reserved_enum4;
+ lzma_reserved_enum reserved_enum5;
+ lzma_reserved_enum reserved_enum6;
+ lzma_bool reserved_bool1;
+ lzma_bool reserved_bool2;
+ lzma_bool reserved_bool3;
+ lzma_bool reserved_bool4;
+ lzma_bool reserved_bool5;
+ lzma_bool reserved_bool6;
+ lzma_bool reserved_bool7;
+ lzma_bool reserved_bool8;
+ uint32_t reserved_int1;
+ uint32_t reserved_int2;
+ uint32_t reserved_int3;
+ uint32_t reserved_int4;
+
} lzma_stream_flags;
@@ -61,6 +118,8 @@ typedef struct {
* need to be initialized.
*
* \return - LZMA_OK: Encoding was successful.
+ * - LZMA_HEADER_ERROR: options->version is not supported by
+ * this liblzma version.
* - LZMA_PROG_ERROR: Invalid options.
*/
extern lzma_ret lzma_stream_header_encode(
@@ -76,6 +135,8 @@ extern lzma_ret lzma_stream_header_encode(
* \param options Stream Footer options to be encoded.
*
* \return - LZMA_OK: Encoding was successful.
+ * - LZMA_HEADER_ERROR: options->version is not supported by
+ * this liblzma version.
* - LZMA_PROG_ERROR: Invalid options.
*/
extern lzma_ret lzma_stream_footer_encode(
@@ -92,7 +153,7 @@ extern lzma_ret lzma_stream_footer_encode(
*
* options->index_size is always set to LZMA_VLI_VALUE_UNKNOWN. This is to
* help comparing Stream Flags from Stream Header and Stream Footer with
- * lzma_stream_flags_equal().
+ * lzma_stream_flags_compare().
*
* \return - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
@@ -121,6 +182,13 @@ extern lzma_ret lzma_stream_header_decode(
* is corrupt.
* - LZMA_HEADER_ERROR: Unsupported options are present
* in the footer.
+ *
+ * \note If Stream Header was already decoded successfully, but
+ * decoding Stream Footer returns LZMA_FORMAT_ERROR, the
+ * application should probably report some other error message
+ * than "unsupported file format", since the file more likely is
+ * corrupt (possibly truncated). Stream decoder in liblzma uses
+ * LZMA_DATA_ERROR in this situation.
*/
extern lzma_ret lzma_stream_footer_decode(
lzma_stream_flags *options, const uint8_t *in)
@@ -130,10 +198,18 @@ extern lzma_ret lzma_stream_footer_decode(
/**
* \brief Compare two lzma_stream_flags structures
*
- * index_size values are compared only if both are not LZMA_VLI_VALUE_UNKNOWN.
+ * backward_size values are compared only if both are not
+ * LZMA_VLI_VALUE_UNKNOWN.
*
- * \return true if both structures are considered equal; false otherwise.
+ * \return - LZMA_OK: Both are equal. If either had backward_size set
+ * to LZMA_VLI_VALUE_UNKNOWN, backward_size values were not
+ * compared or validated.
+ * - LZMA_DATA_ERROR: The structures differ.
+ * - LZMA_HEADER_ERROR: version in either structure is greater
+ * than the maximum supported version (currently zero).
+ * - LZMA_PROG_ERROR: Invalid value, e.g. invalid check or
+ * backward_size.
*/
-extern lzma_bool lzma_stream_flags_equal(
+extern lzma_ret lzma_stream_flags_compare(
const lzma_stream_flags *a, const lzma_stream_flags *b)
lzma_attr_pure;