Merge pull request #3296 from stoeckmann/filter_writer
This commit is contained in:
12 files changed
+518
-403
No files matched your search
@@ -64,6 +64,7 @@ static int archive_filter_b64encode_close(struct archive_write_filter *);
|
||||
static int archive_filter_b64encode_free(struct archive_write_filter *);
|
||||
static void la_b64_encode(struct archive_string *, const unsigned char *, size_t);
|
||||
static int64_t atol8(const char *, size_t);
|
||||
static void free_data(struct private_b64encode *);
|
||||
|
||||
static const char base64[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
@@ -80,34 +81,38 @@ static const char base64[] = {
|
||||
* Add a compress filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_b64encode(struct archive *_a)
|
||||
archive_write_add_filter_b64encode(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_b64encode *state;
|
||||
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_b64encode");
|
||||
|
||||
state = calloc(1, sizeof(*state));
|
||||
if (state == NULL) {
|
||||
archive_set_error(f->archive, ENOMEM,
|
||||
"Can't allocate data for b64encode filter");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (state == NULL)
|
||||
goto memerr;
|
||||
archive_strcpy(&state->name, "-");
|
||||
state->mode = 0644;
|
||||
|
||||
f->data = state;
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "b64encode";
|
||||
f->code = ARCHIVE_FILTER_UU;
|
||||
f->open = archive_filter_b64encode_open;
|
||||
f->data = state;
|
||||
f->options = archive_filter_b64encode_options;
|
||||
f->open = archive_filter_b64encode_open;
|
||||
f->write = archive_filter_b64encode_write;
|
||||
f->close = archive_filter_b64encode_close;
|
||||
f->free = archive_filter_b64encode_free;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
memerr:
|
||||
free_data(state);
|
||||
archive_set_error(a, ENOMEM,
|
||||
"Can't allocate data for b64encode filter");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -180,7 +185,6 @@ archive_filter_b64encode_open(struct archive_write_filter *f)
|
||||
archive_string_sprintf(&state->encoded_buff, "begin-base64 %o %s\n",
|
||||
(unsigned int)state->mode, state->name.s);
|
||||
|
||||
f->data = state;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -285,11 +289,8 @@ archive_filter_b64encode_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_filter_b64encode_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_b64encode *state = (struct private_b64encode *)f->data;
|
||||
|
||||
archive_string_free(&state->name);
|
||||
archive_string_free(&state->encoded_buff);
|
||||
free(state);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -316,3 +317,12 @@ atol8(const char *p, size_t char_cnt)
|
||||
return (l);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_b64encode *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
archive_string_free(&data->name);
|
||||
archive_string_free(&data->encoded_buff);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -71,48 +71,64 @@ static int archive_compressor_bzip2_options(struct archive_write_filter *,
|
||||
const char *, const char *);
|
||||
static int archive_compressor_bzip2_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
/*
|
||||
* Add a bzip2 compression filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_bzip2(struct archive *_a)
|
||||
archive_write_add_filter_bzip2(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_data *data;
|
||||
int r;
|
||||
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_bzip2");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
data->compression_level = 9; /* default */
|
||||
|
||||
f->data = data;
|
||||
f->options = &archive_compressor_bzip2_options;
|
||||
f->close = &archive_compressor_bzip2_close;
|
||||
f->free = &archive_compressor_bzip2_free;
|
||||
f->open = &archive_compressor_bzip2_open;
|
||||
f->code = ARCHIVE_FILTER_BZIP2;
|
||||
f->name = "bzip2";
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
|
||||
return (ARCHIVE_OK);
|
||||
data->compression_level = 9;
|
||||
|
||||
r = ARCHIVE_OK;
|
||||
#else
|
||||
data->pdata = __archive_write_program_allocate("bzip2");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
data->compression_level = 0;
|
||||
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
||||
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external bzip2 program");
|
||||
return (ARCHIVE_WARN);
|
||||
r = ARCHIVE_WARN;
|
||||
#endif
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "bzip2";
|
||||
f->code = ARCHIVE_FILTER_BZIP2;
|
||||
f->data = data;
|
||||
f->options = archive_compressor_bzip2_options;
|
||||
f->open = archive_compressor_bzip2_open;
|
||||
f->write = archive_compressor_bzip2_write;
|
||||
f->close = archive_compressor_bzip2_close;
|
||||
f->free = archive_compressor_bzip2_free;
|
||||
|
||||
return (r);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_compressor_bzip2_free(struct archive_write_filter *f)
|
||||
{
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -190,13 +206,11 @@ archive_compressor_bzip2_open(struct archive_write_filter *f)
|
||||
memset(&data->stream, 0, sizeof(data->stream));
|
||||
data->stream.next_out = data->compressed;
|
||||
data->stream.avail_out = (uint32_t)data->compressed_buffer_size;
|
||||
f->write = archive_compressor_bzip2_write;
|
||||
|
||||
/* Initialize compression library */
|
||||
ret = BZ2_bzCompressInit(&(data->stream),
|
||||
data->compression_level, 0, 30);
|
||||
if (ret == BZ_OK) {
|
||||
f->data = data;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -276,20 +290,6 @@ archive_compressor_bzip2_close(struct archive_write_filter *f)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
archive_compressor_bzip2_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
|
||||
/* May already have been called, but not necessarily. */
|
||||
(void)BZ2_bzCompressEnd(&(data->stream));
|
||||
|
||||
free(data->compressed);
|
||||
free(data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function to push input data through compressor, writing
|
||||
* full output blocks as necessary.
|
||||
@@ -347,6 +347,18 @@ drive_compressor(struct archive_write_filter *f,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
/* May already have been called, but not necessarily. */
|
||||
(void)BZ2_bzCompressEnd(&(data->stream));
|
||||
|
||||
free(data->compressed);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
|
||||
|
||||
static int
|
||||
@@ -364,7 +376,6 @@ archive_compressor_bzip2_open(struct archive_write_filter *f)
|
||||
archive_strcat(&as, " -");
|
||||
archive_strappend_char(&as, '0' + data->compression_level);
|
||||
}
|
||||
f->write = archive_compressor_bzip2_write;
|
||||
|
||||
r = __archive_write_program_open(f, data->pdata, as.s);
|
||||
archive_string_free(&as);
|
||||
@@ -388,14 +399,13 @@ archive_compressor_bzip2_close(struct archive_write_filter *f)
|
||||
return __archive_write_program_close(f, data->pdata);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_compressor_bzip2_free(struct archive_write_filter *f)
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
return (ARCHIVE_OK);
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
|
||||
@@ -111,6 +111,7 @@ static int archive_compressor_compress_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static int archive_compressor_compress_close(struct archive_write_filter *);
|
||||
static int archive_compressor_compress_free(struct archive_write_filter *);
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
#if ARCHIVE_VERSION_NUMBER < 4000000
|
||||
int
|
||||
@@ -125,17 +126,35 @@ archive_write_set_compression_compress(struct archive *a)
|
||||
* Add a compress filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_compress(struct archive *_a)
|
||||
archive_write_add_filter_compress(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_data *state;
|
||||
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_compress");
|
||||
f->open = &archive_compressor_compress_open;
|
||||
f->code = ARCHIVE_FILTER_COMPRESS;
|
||||
|
||||
state = calloc(1, sizeof(*state));
|
||||
if (state == NULL)
|
||||
goto memerr;
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "compress";
|
||||
f->code = ARCHIVE_FILTER_COMPRESS;
|
||||
f->data = state;
|
||||
f->open = archive_compressor_compress_open;
|
||||
f->write = archive_compressor_compress_write;
|
||||
f->close = archive_compressor_compress_close;
|
||||
f->free = archive_compressor_compress_free;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
memerr:
|
||||
free_data(state);
|
||||
archive_set_error(a, ENOMEM,
|
||||
"Can't allocate data for compression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -144,19 +163,9 @@ archive_write_add_filter_compress(struct archive *_a)
|
||||
static int
|
||||
archive_compressor_compress_open(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *state;
|
||||
struct private_data *state = f->data;
|
||||
size_t bs = 65536, bpb;
|
||||
|
||||
f->code = ARCHIVE_FILTER_COMPRESS;
|
||||
f->name = "compress";
|
||||
|
||||
state = calloc(1, sizeof(*state));
|
||||
if (state == NULL) {
|
||||
archive_set_error(f->archive, ENOMEM,
|
||||
"Can't allocate data for compression");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
if (f->archive->magic == ARCHIVE_WRITE_MAGIC) {
|
||||
/* Buffer size should be a multiple number of the bytes
|
||||
* per block for performance. */
|
||||
@@ -172,14 +181,9 @@ archive_compressor_compress_open(struct archive_write_filter *f)
|
||||
if (state->compressed == NULL) {
|
||||
archive_set_error(f->archive, ENOMEM,
|
||||
"Can't allocate data for compression buffer");
|
||||
free(state);
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
f->write = archive_compressor_compress_write;
|
||||
f->close = archive_compressor_compress_close;
|
||||
f->free = archive_compressor_compress_free;
|
||||
|
||||
state->max_maxcode = 0x10000; /* Should NEVER generate this code. */
|
||||
state->in_count = 0; /* Length of input. */
|
||||
state->bit_buf = 0;
|
||||
@@ -199,7 +203,6 @@ archive_compressor_compress_open(struct archive_write_filter *f)
|
||||
state->compressed[2] = 0x90; /* Block mode, 16bit max */
|
||||
state->compressed_offset = 3;
|
||||
|
||||
f->data = state;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -437,9 +440,16 @@ archive_compressor_compress_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_compressor_compress_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *state = (struct private_data *)f->data;
|
||||
|
||||
free(state->compressed);
|
||||
free(state);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
free(data->compressed);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -46,42 +46,45 @@ static int archive_write_grzip_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static int archive_write_grzip_close(struct archive_write_filter *);
|
||||
static int archive_write_grzip_free(struct archive_write_filter *);
|
||||
static void free_data(struct write_grzip *);
|
||||
|
||||
int
|
||||
archive_write_add_filter_grzip(struct archive *_a)
|
||||
archive_write_add_filter_grzip(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct write_grzip *data;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_grzip");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(_a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
data->pdata = __archive_write_program_allocate("grzip");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(_a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "grzip";
|
||||
f->code = ARCHIVE_FILTER_GRZIP;
|
||||
f->data = data;
|
||||
f->open = archive_write_grzip_open;
|
||||
f->options = archive_write_grzip_options;
|
||||
f->open = archive_write_grzip_open;
|
||||
f->write = archive_write_grzip_write;
|
||||
f->close = archive_write_grzip_close;
|
||||
f->free = archive_write_grzip_free;
|
||||
|
||||
/* Note: This filter always uses an external program, so we
|
||||
* return "warn" to inform of the fact. */
|
||||
archive_set_error(_a, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external grzip program for grzip compression");
|
||||
return (ARCHIVE_WARN);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -125,9 +128,16 @@ archive_write_grzip_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_write_grzip_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct write_grzip *data = (struct write_grzip *)f->data;
|
||||
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct write_grzip *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -89,63 +89,64 @@ static int archive_compressor_gzip_free(struct archive_write_filter *);
|
||||
static int drive_compressor(struct archive_write_filter *,
|
||||
struct private_data *, int finishing);
|
||||
#endif
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
|
||||
/*
|
||||
* Add a gzip compression filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_gzip(struct archive *_a)
|
||||
archive_write_add_filter_gzip(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_data *data;
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
int r;
|
||||
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_gzip");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
f->data = data;
|
||||
f->open = &archive_compressor_gzip_open;
|
||||
f->options = &archive_compressor_gzip_options;
|
||||
f->close = &archive_compressor_gzip_close;
|
||||
f->free = &archive_compressor_gzip_free;
|
||||
f->code = ARCHIVE_FILTER_GZIP;
|
||||
f->name = "gzip";
|
||||
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
data->original_filename = NULL;
|
||||
#ifdef HAVE_ZLIB_H
|
||||
data->compression_level = Z_DEFAULT_COMPRESSION;
|
||||
return (ARCHIVE_OK);
|
||||
|
||||
r = ARCHIVE_OK;
|
||||
#else
|
||||
data->pdata = __archive_write_program_allocate("gzip");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
data->compression_level = 0;
|
||||
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
||||
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external gzip program");
|
||||
return (ARCHIVE_WARN);
|
||||
r = ARCHIVE_WARN;
|
||||
#endif
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "gzip";
|
||||
f->code = ARCHIVE_FILTER_GZIP;
|
||||
f->data = data;
|
||||
f->options = archive_compressor_gzip_options;
|
||||
f->open = archive_compressor_gzip_open;
|
||||
f->write = archive_compressor_gzip_write;
|
||||
f->close = archive_compressor_gzip_close;
|
||||
f->free = archive_compressor_gzip_free;
|
||||
|
||||
return (r);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_compressor_gzip_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
free(data->compressed);
|
||||
#else
|
||||
__archive_write_program_free(data->pdata);
|
||||
#endif
|
||||
free((void*)data->original_filename);
|
||||
free(data);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
@@ -273,8 +274,6 @@ archive_compressor_gzip_open(struct archive_write_filter *f)
|
||||
}
|
||||
}
|
||||
|
||||
f->write = archive_compressor_gzip_write;
|
||||
|
||||
/* Initialize compression library. */
|
||||
init_success = deflateInit2(&(data->stream),
|
||||
data->compression_level,
|
||||
@@ -284,7 +283,6 @@ archive_compressor_gzip_open(struct archive_write_filter *f)
|
||||
Z_DEFAULT_STRATEGY);
|
||||
|
||||
if (init_success == Z_OK) {
|
||||
f->data = data;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@@ -427,6 +425,16 @@ drive_compressor(struct archive_write_filter *f,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
free(data->compressed);
|
||||
free(data->original_filename);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* HAVE_ZLIB_H */
|
||||
|
||||
static int
|
||||
@@ -451,7 +459,6 @@ archive_compressor_gzip_open(struct archive_write_filter *f)
|
||||
/* Save timestamp. */
|
||||
archive_strcat(&as, " -N");
|
||||
|
||||
f->write = archive_compressor_gzip_write;
|
||||
r = __archive_write_program_open(f, data->pdata, as.s);
|
||||
archive_string_free(&as);
|
||||
return (r);
|
||||
@@ -474,4 +481,13 @@ archive_compressor_gzip_close(struct archive_write_filter *f)
|
||||
return __archive_write_program_close(f, data->pdata);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data->original_filename);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
@@ -52,42 +52,45 @@ static int archive_write_lrzip_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static int archive_write_lrzip_close(struct archive_write_filter *);
|
||||
static int archive_write_lrzip_free(struct archive_write_filter *);
|
||||
static void free_data(struct write_lrzip *);
|
||||
|
||||
int
|
||||
archive_write_add_filter_lrzip(struct archive *_a)
|
||||
archive_write_add_filter_lrzip(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct write_lrzip *data;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lrzip");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(_a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
data->pdata = __archive_write_program_allocate("lrzip");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(_a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "lrzip";
|
||||
f->code = ARCHIVE_FILTER_LRZIP;
|
||||
f->data = data;
|
||||
f->open = archive_write_lrzip_open;
|
||||
f->options = archive_write_lrzip_options;
|
||||
f->open = archive_write_lrzip_open;
|
||||
f->write = archive_write_lrzip_write;
|
||||
f->close = archive_write_lrzip_close;
|
||||
f->free = archive_write_lrzip_free;
|
||||
|
||||
/* Note: This filter always uses an external program, so we
|
||||
* return "warn" to inform of the fact. */
|
||||
archive_set_error(_a, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external lrzip program for lrzip compression");
|
||||
return (ARCHIVE_WARN);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -196,9 +199,16 @@ archive_write_lrzip_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_write_lrzip_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct write_lrzip *data = (struct write_lrzip *)f->data;
|
||||
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct write_lrzip *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -85,30 +85,27 @@ static int archive_filter_lz4_options(struct archive_write_filter *,
|
||||
const char *, const char *);
|
||||
static int archive_filter_lz4_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
/*
|
||||
* Add an lz4 compression filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_lz4(struct archive *_a)
|
||||
archive_write_add_filter_lz4(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_data *data;
|
||||
int r;
|
||||
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lz4");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
/*
|
||||
* Setup default settings.
|
||||
*/
|
||||
data->compression_level = 1;
|
||||
data->version_number = 0x01;
|
||||
data->block_independence = 1;
|
||||
data->block_checksum = 0;
|
||||
@@ -116,35 +113,53 @@ archive_write_add_filter_lz4(struct archive *_a)
|
||||
data->stream_checksum = 1;
|
||||
data->preset_dictionary = 0;
|
||||
data->block_maximum_size = 7;
|
||||
|
||||
/*
|
||||
* Setup a filter setting.
|
||||
*/
|
||||
f->data = data;
|
||||
f->options = &archive_filter_lz4_options;
|
||||
f->close = &archive_filter_lz4_close;
|
||||
f->free = &archive_filter_lz4_free;
|
||||
f->open = &archive_filter_lz4_open;
|
||||
f->code = ARCHIVE_FILTER_LZ4;
|
||||
f->name = "lz4";
|
||||
#if defined(HAVE_LIBLZ4) && LZ4_VERSION_MAJOR >= 1 && LZ4_VERSION_MINOR >= 2
|
||||
return (ARCHIVE_OK);
|
||||
data->compression_level = 1;
|
||||
|
||||
r = ARCHIVE_OK;
|
||||
#else
|
||||
/*
|
||||
* We don't have lz4 library, and execute external lz4 program
|
||||
* instead.
|
||||
*/
|
||||
data->pdata = __archive_write_program_allocate("lz4");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
data->compression_level = 0;
|
||||
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
||||
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external lz4 program");
|
||||
return (ARCHIVE_WARN);
|
||||
r = ARCHIVE_WARN;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Setup a filter setting.
|
||||
*/
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "lz4";
|
||||
f->code = ARCHIVE_FILTER_LZ4;
|
||||
f->data = data;
|
||||
f->options = archive_filter_lz4_options;
|
||||
f->open = archive_filter_lz4_open;
|
||||
f->write = archive_filter_lz4_write;
|
||||
f->close = archive_filter_lz4_close;
|
||||
f->free = archive_filter_lz4_free;
|
||||
|
||||
return (r);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_filter_lz4_free(struct archive_write_filter *f)
|
||||
{
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -277,8 +292,6 @@ archive_filter_lz4_open(struct archive_write_filter *f)
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
f->write = archive_filter_lz4_write;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -364,35 +377,6 @@ archive_filter_lz4_close(struct archive_write_filter *f)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
archive_filter_lz4_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
|
||||
if (data->lz4_stream != NULL) {
|
||||
#ifdef HAVE_LZ4HC_H
|
||||
if (data->compression_level >= 3)
|
||||
#if LZ4_VERSION_MAJOR >= 1 && LZ4_VERSION_MINOR >= 7
|
||||
LZ4_freeStreamHC(data->lz4_stream);
|
||||
#else
|
||||
LZ4_freeHC(data->lz4_stream);
|
||||
#endif
|
||||
else
|
||||
#endif
|
||||
#if LZ4_VERSION_MINOR >= 3
|
||||
LZ4_freeStream(data->lz4_stream);
|
||||
#else
|
||||
LZ4_free(data->lz4_stream);
|
||||
#endif
|
||||
}
|
||||
free(data->out_buffer);
|
||||
free(data->in_buffer_allocated);
|
||||
free(data->xxh32_state);
|
||||
free(data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
lz4_write_stream_descriptor(struct archive_write_filter *f)
|
||||
{
|
||||
@@ -637,6 +621,33 @@ drive_compressor_dependence(struct archive_write_filter *f, const char *p,
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
if (data->lz4_stream != NULL) {
|
||||
#ifdef HAVE_LZ4HC_H
|
||||
if (data->compression_level >= 3)
|
||||
#if LZ4_VERSION_MAJOR >= 1 && LZ4_VERSION_MINOR >= 7
|
||||
LZ4_freeStreamHC(data->lz4_stream);
|
||||
#else
|
||||
LZ4_freeHC(data->lz4_stream);
|
||||
#endif
|
||||
else
|
||||
#endif
|
||||
#if LZ4_VERSION_MINOR >= 3
|
||||
LZ4_freeStream(data->lz4_stream);
|
||||
#else
|
||||
LZ4_free(data->lz4_stream);
|
||||
#endif
|
||||
}
|
||||
free(data->out_buffer);
|
||||
free(data->in_buffer_allocated);
|
||||
free(data->xxh32_state);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* HAVE_LIBLZ4 */
|
||||
|
||||
static int
|
||||
@@ -665,8 +676,6 @@ archive_filter_lz4_open(struct archive_write_filter *f)
|
||||
if (data->block_independence == 0)
|
||||
archive_strcat(&as, " -BD");
|
||||
|
||||
f->write = archive_filter_lz4_write;
|
||||
|
||||
r = __archive_write_program_open(f, data->pdata, as.s);
|
||||
archive_string_free(&as);
|
||||
return (r);
|
||||
@@ -689,14 +698,13 @@ archive_filter_lz4_close(struct archive_write_filter *f)
|
||||
return __archive_write_program_close(f, data->pdata);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_filter_lz4_free(struct archive_write_filter *f)
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
return (ARCHIVE_OK);
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBLZ4 */
|
||||
@@ -80,6 +80,7 @@ static int archive_write_lzop_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static int archive_write_lzop_close(struct archive_write_filter *);
|
||||
static int archive_write_lzop_free(struct archive_write_filter *);
|
||||
static void free_data(struct write_lzop *);
|
||||
|
||||
#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
|
||||
/* Maximum block size. */
|
||||
@@ -133,73 +134,72 @@ static const unsigned char header[] = {
|
||||
#endif
|
||||
|
||||
int
|
||||
archive_write_add_filter_lzop(struct archive *_a)
|
||||
archive_write_add_filter_lzop(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct write_lzop *data;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lzop");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(_a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
f->name = "lzop";
|
||||
f->code = ARCHIVE_FILTER_LZOP;
|
||||
f->data = data;
|
||||
f->open = archive_write_lzop_open;
|
||||
f->options = archive_write_lzop_options;
|
||||
f->write = archive_write_lzop_write;
|
||||
f->close = archive_write_lzop_close;
|
||||
f->free = archive_write_lzop_free;
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
|
||||
if (lzo_init() != LZO_E_OK) {
|
||||
free(data);
|
||||
archive_set_error(_a, ARCHIVE_ERRNO_MISC,
|
||||
free_data(data);
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"lzo_init(type check) failed");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (lzo_version() < 0x940) {
|
||||
free(data);
|
||||
archive_set_error(_a, ARCHIVE_ERRNO_MISC,
|
||||
free_data(data);
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"liblzo library is too old(%s < 0.940)",
|
||||
lzo_version_string());
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
data->compression_level = 5;
|
||||
return (ARCHIVE_OK);
|
||||
|
||||
r = ARCHIVE_OK;
|
||||
#else
|
||||
data->pdata = __archive_write_program_allocate("lzop");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(_a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
data->compression_level = 0;
|
||||
|
||||
/* Note: We return "warn" to inform of using an external lzop
|
||||
* program. */
|
||||
archive_set_error(_a, ARCHIVE_ERRNO_MISC,
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external lzop program for lzop compression");
|
||||
return (ARCHIVE_WARN);
|
||||
r = ARCHIVE_WARN;
|
||||
#endif
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "lzop";
|
||||
f->code = ARCHIVE_FILTER_LZOP;
|
||||
f->data = data;
|
||||
f->options = archive_write_lzop_options;
|
||||
f->open = archive_write_lzop_open;
|
||||
f->write = archive_write_lzop_write;
|
||||
f->close = archive_write_lzop_close;
|
||||
f->free = archive_write_lzop_free;
|
||||
|
||||
return (r);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Can't allocate memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_write_lzop_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct write_lzop *data = (struct write_lzop *)f->data;
|
||||
|
||||
#if defined(HAVE_LZO_LZOCONF_H) && defined(HAVE_LZO_LZO1X_H)
|
||||
free(data->uncompressed);
|
||||
free(data->compressed);
|
||||
free(data->work_buffer);
|
||||
#else
|
||||
__archive_write_program_free(data->pdata);
|
||||
#endif
|
||||
free(data);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -439,6 +439,17 @@ archive_write_lzop_close(struct archive_write_filter *f)
|
||||
return __archive_write_filter(f->next_filter, &endmark, sizeof(endmark));
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct write_lzop *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
free(data->uncompressed);
|
||||
free(data->compressed);
|
||||
free(data->work_buffer);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
static int
|
||||
archive_write_lzop_open(struct archive_write_filter *f)
|
||||
@@ -477,4 +488,13 @@ archive_write_lzop_close(struct archive_write_filter *f)
|
||||
|
||||
return __archive_write_program_close(f, data->pdata);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct write_lzop *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -81,34 +81,31 @@ static int archive_compressor_program_write(struct archive_write_filter *,
|
||||
const void *, size_t);
|
||||
static int archive_compressor_program_close(struct archive_write_filter *);
|
||||
static int archive_compressor_program_free(struct archive_write_filter *);
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
/*
|
||||
* Add a filter to this write handle that passes all data through an
|
||||
* external program.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_program(struct archive *_a, const char *cmd)
|
||||
archive_write_add_filter_program(struct archive *a, const char *cmd)
|
||||
{
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_data *data;
|
||||
static const char prefix[] = "Program: ";
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_program");
|
||||
|
||||
f->data = calloc(1, sizeof(*data));
|
||||
if (f->data == NULL)
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
data = (struct private_data *)f->data;
|
||||
|
||||
data->cmd = strdup(cmd);
|
||||
if (data->cmd == NULL)
|
||||
goto memerr;
|
||||
|
||||
data->pdata = __archive_write_program_allocate(cmd);
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
|
||||
/* Make up a description string. */
|
||||
if (archive_string_ensure(&data->description,
|
||||
strlen(prefix) + strlen(cmd) + 1) == NULL)
|
||||
@@ -116,16 +113,21 @@ archive_write_add_filter_program(struct archive *_a, const char *cmd)
|
||||
archive_strcpy(&data->description, prefix);
|
||||
archive_strcat(&data->description, cmd);
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = data->description.s;
|
||||
f->code = ARCHIVE_FILTER_PROGRAM;
|
||||
f->data = data;
|
||||
f->open = archive_compressor_program_open;
|
||||
f->write = archive_compressor_program_write;
|
||||
f->close = archive_compressor_program_close;
|
||||
f->free = archive_compressor_program_free;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
memerr:
|
||||
archive_compressor_program_free(f);
|
||||
archive_set_error(_a, ENOMEM,
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM,
|
||||
"Can't allocate memory for filter program");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
@@ -158,15 +160,8 @@ archive_compressor_program_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_compressor_program_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
|
||||
if (data) {
|
||||
free(data->cmd);
|
||||
archive_string_free(&data->description);
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
f->data = NULL;
|
||||
}
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -391,3 +386,13 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data) {
|
||||
free(data->cmd);
|
||||
archive_string_free(&data->description);
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -64,39 +64,44 @@ static int archive_filter_uuencode_close(struct archive_write_filter *);
|
||||
static int archive_filter_uuencode_free(struct archive_write_filter *);
|
||||
static void uu_encode(struct archive_string *, const unsigned char *, size_t);
|
||||
static int64_t atol8(const char *, size_t);
|
||||
static void free_data(struct private_uuencode *);
|
||||
|
||||
/*
|
||||
* Add a compress filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_uuencode(struct archive *_a)
|
||||
archive_write_add_filter_uuencode(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_uuencode *state;
|
||||
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_uu");
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_uuencode");
|
||||
|
||||
state = calloc(1, sizeof(*state));
|
||||
if (state == NULL) {
|
||||
archive_set_error(f->archive, ENOMEM,
|
||||
"Can't allocate data for uuencode filter");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (state == NULL)
|
||||
goto memerr;
|
||||
archive_strcpy(&state->name, "-");
|
||||
state->mode = 0644;
|
||||
|
||||
f->data = state;
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "uuencode";
|
||||
f->code = ARCHIVE_FILTER_UU;
|
||||
f->open = archive_filter_uuencode_open;
|
||||
f->data = state;
|
||||
f->options = archive_filter_uuencode_options;
|
||||
f->open = archive_filter_uuencode_open;
|
||||
f->write = archive_filter_uuencode_write;
|
||||
f->close = archive_filter_uuencode_close;
|
||||
f->free = archive_filter_uuencode_free;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
memerr:
|
||||
free_data(state);
|
||||
archive_set_error(a, ENOMEM,
|
||||
"Can't allocate data for uuencode filter");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -169,7 +174,6 @@ archive_filter_uuencode_open(struct archive_write_filter *f)
|
||||
archive_string_sprintf(&state->encoded_buff, "begin %o %s\n",
|
||||
(unsigned int)state->mode, state->name.s);
|
||||
|
||||
f->data = state;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -276,11 +280,8 @@ archive_filter_uuencode_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_filter_uuencode_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_uuencode *state = (struct private_uuencode *)f->data;
|
||||
|
||||
archive_string_free(&state->name);
|
||||
archive_string_free(&state->encoded_buff);
|
||||
free(state);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
|
||||
@@ -307,3 +308,12 @@ atol8(const char *p, size_t char_cnt)
|
||||
return (l);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_uuencode *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
archive_string_free(&data->name);
|
||||
archive_string_free(&data->encoded_buff);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
@@ -122,6 +122,7 @@ static int archive_compressor_xz_close(struct archive_write_filter *);
|
||||
static int archive_compressor_xz_free(struct archive_write_filter *);
|
||||
static int drive_compressor(struct archive_write_filter *,
|
||||
struct private_data *, int finishing);
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
struct option_value {
|
||||
uint32_t dict_size;
|
||||
@@ -142,80 +143,67 @@ static const struct option_value option_values[] = {
|
||||
};
|
||||
|
||||
static int
|
||||
common_setup(struct archive_write_filter *f)
|
||||
common_setup(struct archive *a, const char *name, int code)
|
||||
{
|
||||
struct private_data *data;
|
||||
struct archive_write *a = (struct archive_write *)f->archive;
|
||||
struct archive_write_filter *f;
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
f->data = data;
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
data->compression_level = LZMA_PRESET_DEFAULT;
|
||||
data->threads = 1;
|
||||
f->open = &archive_compressor_xz_open;
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = name;
|
||||
f->code = code;
|
||||
f->data = data;
|
||||
f->options = archive_compressor_xz_options;
|
||||
f->open = archive_compressor_xz_open;
|
||||
f->write = archive_compressor_xz_write;
|
||||
f->close = archive_compressor_xz_close;
|
||||
f->free = archive_compressor_xz_free;
|
||||
f->options = &archive_compressor_xz_options;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an xz compression filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_xz(struct archive *_a)
|
||||
archive_write_add_filter_xz(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_xz");
|
||||
f = __archive_write_allocate_filter(_a);
|
||||
r = common_setup(f);
|
||||
if (r == ARCHIVE_OK) {
|
||||
f->code = ARCHIVE_FILTER_XZ;
|
||||
f->name = "xz";
|
||||
}
|
||||
return (r);
|
||||
|
||||
return common_setup(a, "xz", ARCHIVE_FILTER_XZ);
|
||||
}
|
||||
|
||||
/* LZMA is handled identically, we just need a different compression
|
||||
* code set. (The liblzma setup looks at the code to determine
|
||||
* the one place that XZ and LZMA require different handling.) */
|
||||
int
|
||||
archive_write_add_filter_lzma(struct archive *_a)
|
||||
archive_write_add_filter_lzma(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lzma");
|
||||
f = __archive_write_allocate_filter(_a);
|
||||
r = common_setup(f);
|
||||
if (r == ARCHIVE_OK) {
|
||||
f->code = ARCHIVE_FILTER_LZMA;
|
||||
f->name = "lzma";
|
||||
}
|
||||
return (r);
|
||||
|
||||
return common_setup(a, "lzma", ARCHIVE_FILTER_LZMA);
|
||||
}
|
||||
|
||||
int
|
||||
archive_write_add_filter_lzip(struct archive *_a)
|
||||
archive_write_add_filter_lzip(struct archive *a)
|
||||
{
|
||||
struct archive_write_filter *f;
|
||||
int r;
|
||||
|
||||
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_lzip");
|
||||
f = __archive_write_allocate_filter(_a);
|
||||
r = common_setup(f);
|
||||
if (r == ARCHIVE_OK) {
|
||||
f->code = ARCHIVE_FILTER_LZIP;
|
||||
f->name = "lzip";
|
||||
}
|
||||
return (r);
|
||||
|
||||
return common_setup(a, "lzip", ARCHIVE_FILTER_LZIP);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -330,8 +318,6 @@ archive_compressor_xz_open(struct archive_write_filter *f)
|
||||
}
|
||||
}
|
||||
|
||||
f->write = archive_compressor_xz_write;
|
||||
|
||||
/* Initialize compression library. */
|
||||
if (f->code == ARCHIVE_FILTER_LZIP) {
|
||||
const struct option_value *val =
|
||||
@@ -362,7 +348,6 @@ archive_compressor_xz_open(struct archive_write_filter *f)
|
||||
}
|
||||
ret = archive_compressor_xz_init_stream(f, data);
|
||||
if (ret == LZMA_OK) {
|
||||
f->data = data;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
return (ARCHIVE_FATAL);
|
||||
@@ -478,9 +463,7 @@ archive_compressor_xz_close(struct archive_write_filter *f)
|
||||
static int
|
||||
archive_compressor_xz_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
free(data->compressed);
|
||||
free(data);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
@@ -552,4 +535,13 @@ drive_compressor(struct archive_write_filter *f,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
free(data->compressed);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_LZMA_H */
|
||||
@@ -105,33 +105,25 @@ static int archive_compressor_zstd_free(struct archive_write_filter *);
|
||||
static int drive_compressor(struct archive_write_filter *,
|
||||
struct private_data *, int, const void *, size_t);
|
||||
#endif
|
||||
static void free_data(struct private_data *);
|
||||
|
||||
|
||||
/*
|
||||
* Add a zstd compression filter to this write handle.
|
||||
*/
|
||||
int
|
||||
archive_write_add_filter_zstd(struct archive *_a)
|
||||
archive_write_add_filter_zstd(struct archive *a)
|
||||
{
|
||||
struct archive_write *a = (struct archive_write *)_a;
|
||||
struct archive_write_filter *f = __archive_write_allocate_filter(_a);
|
||||
struct archive_write_filter *f;
|
||||
struct private_data *data;
|
||||
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
|
||||
int r;
|
||||
|
||||
archive_check_magic(a, ARCHIVE_WRITE_MAGIC,
|
||||
ARCHIVE_STATE_NEW, "archive_write_add_filter_zstd");
|
||||
|
||||
data = calloc(1, sizeof(*data));
|
||||
if (data == NULL) {
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
f->data = data;
|
||||
f->open = &archive_compressor_zstd_open;
|
||||
f->options = &archive_compressor_zstd_options;
|
||||
f->flush = &archive_compressor_zstd_flush;
|
||||
f->close = &archive_compressor_zstd_close;
|
||||
f->free = &archive_compressor_zstd_free;
|
||||
f->code = ARCHIVE_FILTER_ZSTD;
|
||||
f->name = "zstd";
|
||||
if (data == NULL)
|
||||
goto memerr;
|
||||
data->compression_level = CLEVEL_DEFAULT;
|
||||
data->threads = 0;
|
||||
data->long_distance = 0;
|
||||
@@ -144,38 +136,44 @@ archive_write_add_filter_zstd(struct archive *_a)
|
||||
data->cur_frame_in = 0;
|
||||
data->cur_frame_out = 0;
|
||||
data->cstream = ZSTD_createCStream();
|
||||
if (data->cstream == NULL) {
|
||||
free(data);
|
||||
archive_set_error(&a->archive, ENOMEM,
|
||||
"Failed to allocate zstd compressor object");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
if (data->cstream == NULL)
|
||||
goto memerr;
|
||||
|
||||
return (ARCHIVE_OK);
|
||||
r = ARCHIVE_OK;
|
||||
#else
|
||||
data->pdata = __archive_write_program_allocate("zstd");
|
||||
if (data->pdata == NULL) {
|
||||
free(data);
|
||||
archive_set_error(&a->archive, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
|
||||
if (data->pdata == NULL)
|
||||
goto memerr;
|
||||
|
||||
archive_set_error(a, ARCHIVE_ERRNO_MISC,
|
||||
"Using external zstd program");
|
||||
return (ARCHIVE_WARN);
|
||||
r = ARCHIVE_WARN;
|
||||
#endif
|
||||
|
||||
f = __archive_write_allocate_filter(a);
|
||||
if (f == NULL)
|
||||
goto memerr;
|
||||
f->name = "zstd";
|
||||
f->code = ARCHIVE_FILTER_ZSTD;
|
||||
f->data = data;
|
||||
f->options = archive_compressor_zstd_options;
|
||||
f->open = archive_compressor_zstd_open;
|
||||
f->write = archive_compressor_zstd_write;
|
||||
f->flush = archive_compressor_zstd_flush;
|
||||
f->close = archive_compressor_zstd_close;
|
||||
f->free = archive_compressor_zstd_free;
|
||||
|
||||
return (r);
|
||||
memerr:
|
||||
free_data(data);
|
||||
archive_set_error(a, ENOMEM, "Out of memory");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static int
|
||||
archive_compressor_zstd_free(struct archive_write_filter *f)
|
||||
{
|
||||
struct private_data *data = (struct private_data *)f->data;
|
||||
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
|
||||
ZSTD_freeCStream(data->cstream);
|
||||
free(data->out.dst);
|
||||
#else
|
||||
__archive_write_program_free(data->pdata);
|
||||
#endif
|
||||
free(data);
|
||||
free_data(f->data);
|
||||
f->data = NULL;
|
||||
return (ARCHIVE_OK);
|
||||
}
|
||||
@@ -403,8 +401,6 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
|
||||
}
|
||||
}
|
||||
|
||||
f->write = archive_compressor_zstd_write;
|
||||
|
||||
if (ZSTD_isError(ZSTD_initCStream(data->cstream,
|
||||
data->compression_level))) {
|
||||
archive_set_error(f->archive, ARCHIVE_ERRNO_MISC,
|
||||
@@ -529,6 +525,16 @@ fatal:
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
ZSTD_freeCStream(data->cstream);
|
||||
free(data->out.dst);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* HAVE_ZSTD_H && HAVE_ZSTD_compressStream */
|
||||
|
||||
static int
|
||||
@@ -560,7 +566,6 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
|
||||
archive_string_sprintf(&as, " --long=%d", data->long_distance);
|
||||
}
|
||||
|
||||
f->write = archive_compressor_zstd_write;
|
||||
r = __archive_write_program_open(f, data->pdata, as.s);
|
||||
archive_string_free(&as);
|
||||
return (r);
|
||||
@@ -591,4 +596,13 @@ archive_compressor_zstd_close(struct archive_write_filter *f)
|
||||
return __archive_write_program_close(f, data->pdata);
|
||||
}
|
||||
|
||||
static void
|
||||
free_data(struct private_data *data)
|
||||
{
|
||||
if (data != NULL) {
|
||||
__archive_write_program_free(data->pdata);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_ZSTD_H && HAVE_ZSTD_compressStream */
|
||||
Reference in new issue
Block a user