libarchive-static 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/Makefile +6 -0
- data/ext/extconf.rb +61 -0
- data/ext/libarchive-0.1.1/COPYING.libarchive +60 -0
- data/ext/libarchive-0.1.1/LICENSE.libbzip2 +42 -0
- data/ext/libarchive-0.1.1/README.txt +143 -0
- data/ext/libarchive-0.1.1/ext/Makefile.in +0 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +31 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_read_support_format.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +29 -0
- data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.h +6 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +32 -0
- data/ext/libarchive-0.1.1/ext/archive_write_set_compression.h +6 -0
- data/ext/libarchive-0.1.1/ext/config.h.in +22 -0
- data/ext/libarchive-0.1.1/ext/configure +3904 -0
- data/ext/libarchive-0.1.1/ext/configure.in +11 -0
- data/ext/libarchive-0.1.1/ext/depend +19 -0
- data/ext/libarchive-0.1.1/ext/extconf.rb +6 -0
- data/ext/libarchive-0.1.1/ext/install-sh +250 -0
- data/ext/libarchive-0.1.1/ext/libarchive.c +89 -0
- data/ext/libarchive-0.1.1/ext/libarchive_archive.c +84 -0
- data/ext/libarchive-0.1.1/ext/libarchive_entry.c +1015 -0
- data/ext/libarchive-0.1.1/ext/libarchive_internal.h +155 -0
- data/ext/libarchive-0.1.1/ext/libarchive_reader.c +328 -0
- data/ext/libarchive-0.1.1/ext/libarchive_win32.h +52 -0
- data/ext/libarchive-0.1.1/ext/libarchive_writer.c +246 -0
- data/ext/libarchive-0.1.1/libarchive.c +1762 -0
- data/ext/libarchive-2.8.4/Makefile.in +7076 -0
- data/ext/libarchive-2.8.4/build/autoconf/check_stdcall_func.m4 +51 -0
- data/ext/libarchive-2.8.4/build/autoconf/compile +143 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.guess +1502 -0
- data/ext/libarchive-2.8.4/build/autoconf/config.sub +1708 -0
- data/ext/libarchive-2.8.4/build/autoconf/depcomp +630 -0
- data/ext/libarchive-2.8.4/build/autoconf/install-sh +291 -0
- data/ext/libarchive-2.8.4/build/autoconf/la_uid_t.m4 +20 -0
- data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +8406 -0
- data/ext/libarchive-2.8.4/build/autoconf/missing +376 -0
- data/ext/libarchive-2.8.4/build/pkgconfig/libarchive.pc.in +10 -0
- data/ext/libarchive-2.8.4/config.h.in +772 -0
- data/ext/libarchive-2.8.4/configure +17916 -0
- data/ext/libarchive-2.8.4/libarchive/archive.h +741 -0
- data/ext/libarchive-2.8.4/libarchive/archive_check_magic.c +134 -0
- data/ext/libarchive-2.8.4/libarchive/archive_crc32.h +66 -0
- data/ext/libarchive-2.8.4/libarchive/archive_endian.h +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.c +2202 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry.h +524 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_bhfi.c +74 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_stat.c +77 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_link_resolver.c +405 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_private.h +184 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_stat.c +118 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_strmode.c +87 -0
- data/ext/libarchive-2.8.4/libarchive/archive_entry_xattr.c +158 -0
- data/ext/libarchive-2.8.4/libarchive/archive_hash.h +281 -0
- data/ext/libarchive-2.8.4/libarchive/archive_platform.h +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_private.h +124 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read.c +1249 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_data_into_fd.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +198 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +570 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_private.h +62 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_disk_set_standard_lookup.c +303 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_extract.c +182 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_fd.c +190 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_file.c +165 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +272 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_open_memory.c +156 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_private.h +199 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_all.c +60 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c +353 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c +444 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c +465 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_none.c +40 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_program.c +459 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c +287 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c +627 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c +708 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_all.c +43 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_ar.c +584 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +777 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_empty.c +93 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c +2830 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +1304 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_raw.c +185 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_tar.c +2418 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_xar.c +3151 -0
- data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +903 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.c +453 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string.h +148 -0
- data/ext/libarchive-2.8.4/libarchive/archive_string_sprintf.c +164 -0
- data/ext/libarchive-2.8.4/libarchive/archive_util.c +391 -0
- data/ext/libarchive-2.8.4/libarchive/archive_virtual.c +94 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.c +1236 -0
- data/ext/libarchive-2.8.4/libarchive/archive_windows.h +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write.c +466 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +2628 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_private.h +38 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_disk_set_standard_lookup.c +262 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_fd.c +141 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_file.c +105 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_filename.c +162 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_open_memory.c +126 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_private.h +122 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +408 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c +492 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +477 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +257 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +347 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +438 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format.c +72 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ar.c +550 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_by_name.c +76 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +344 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +295 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +1050 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_pax.c +1386 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_shar.c +626 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ustar.c +587 -0
- data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +667 -0
- data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +154 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.c +161 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork.h +41 -0
- data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +113 -0
- data/ext/libarchive-static-makefile +80 -0
- data/ext/libarchive-static-wrapper-makefile +22 -0
- data/ext/zlib-1.2.5/Makefile.in +257 -0
- data/ext/zlib-1.2.5/adler32.c +169 -0
- data/ext/zlib-1.2.5/compress.c +80 -0
- data/ext/zlib-1.2.5/configure +596 -0
- data/ext/zlib-1.2.5/crc32.c +442 -0
- data/ext/zlib-1.2.5/crc32.h +441 -0
- data/ext/zlib-1.2.5/deflate.c +1834 -0
- data/ext/zlib-1.2.5/deflate.h +342 -0
- data/ext/zlib-1.2.5/example.c +565 -0
- data/ext/zlib-1.2.5/gzclose.c +25 -0
- data/ext/zlib-1.2.5/gzguts.h +132 -0
- data/ext/zlib-1.2.5/gzlib.c +537 -0
- data/ext/zlib-1.2.5/gzread.c +653 -0
- data/ext/zlib-1.2.5/gzwrite.c +531 -0
- data/ext/zlib-1.2.5/infback.c +632 -0
- data/ext/zlib-1.2.5/inffast.c +340 -0
- data/ext/zlib-1.2.5/inffast.h +11 -0
- data/ext/zlib-1.2.5/inffixed.h +94 -0
- data/ext/zlib-1.2.5/inflate.c +1480 -0
- data/ext/zlib-1.2.5/inflate.h +122 -0
- data/ext/zlib-1.2.5/inftrees.c +330 -0
- data/ext/zlib-1.2.5/inftrees.h +62 -0
- data/ext/zlib-1.2.5/minigzip.c +440 -0
- data/ext/zlib-1.2.5/trees.c +1244 -0
- data/ext/zlib-1.2.5/trees.h +128 -0
- data/ext/zlib-1.2.5/uncompr.c +59 -0
- data/ext/zlib-1.2.5/zconf.h +428 -0
- data/ext/zlib-1.2.5/zlib.h +1613 -0
- data/ext/zlib-1.2.5/zutil.c +318 -0
- data/ext/zlib-1.2.5/zutil.h +274 -0
- metadata +211 -0
@@ -0,0 +1,199 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*
|
25
|
+
* $FreeBSD: head/lib/libarchive/archive_read_private.h 201088 2009-12-28 02:18:55Z kientzle $
|
26
|
+
*/
|
27
|
+
|
28
|
+
#ifndef __LIBARCHIVE_BUILD
|
29
|
+
#error This header is only to be used internally to libarchive.
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED
|
33
|
+
#define ARCHIVE_READ_PRIVATE_H_INCLUDED
|
34
|
+
|
35
|
+
#include "archive.h"
|
36
|
+
#include "archive_string.h"
|
37
|
+
#include "archive_private.h"
|
38
|
+
|
39
|
+
struct archive_read;
|
40
|
+
struct archive_read_filter_bidder;
|
41
|
+
struct archive_read_filter;
|
42
|
+
|
43
|
+
/*
|
44
|
+
* How bidding works for filters:
|
45
|
+
* * The bid manager reads the first block from the current source.
|
46
|
+
* * It shows that block to each registered bidder.
|
47
|
+
* * The bid manager creates a new filter structure for the winning
|
48
|
+
* bidder and gives the winning bidder a chance to initialize it.
|
49
|
+
* * The new filter becomes the top filter in the archive_read structure
|
50
|
+
* and we repeat the process.
|
51
|
+
* This ends only when no bidder provides a non-zero bid.
|
52
|
+
*/
|
53
|
+
struct archive_read_filter_bidder {
|
54
|
+
/* Configuration data for the bidder. */
|
55
|
+
void *data;
|
56
|
+
/* Taste the upstream filter to see if we handle this. */
|
57
|
+
int (*bid)(struct archive_read_filter_bidder *,
|
58
|
+
struct archive_read_filter *);
|
59
|
+
/* Initialize a newly-created filter. */
|
60
|
+
int (*init)(struct archive_read_filter *);
|
61
|
+
/* Set an option for the filter bidder. */
|
62
|
+
int (*options)(struct archive_read_filter_bidder *,
|
63
|
+
const char *key, const char *value);
|
64
|
+
/* Release the bidder's configuration data. */
|
65
|
+
int (*free)(struct archive_read_filter_bidder *);
|
66
|
+
};
|
67
|
+
|
68
|
+
/*
|
69
|
+
* This structure is allocated within the archive_read core
|
70
|
+
* and initialized by archive_read and the init() method of the
|
71
|
+
* corresponding bidder above.
|
72
|
+
*/
|
73
|
+
struct archive_read_filter {
|
74
|
+
/* Essentially all filters will need these values, so
|
75
|
+
* just declare them here. */
|
76
|
+
struct archive_read_filter_bidder *bidder; /* My bidder. */
|
77
|
+
struct archive_read_filter *upstream; /* Who I read from. */
|
78
|
+
struct archive_read *archive; /* Associated archive. */
|
79
|
+
/* Return next block. */
|
80
|
+
ssize_t (*read)(struct archive_read_filter *, const void **);
|
81
|
+
/* Skip forward this many bytes. */
|
82
|
+
int64_t (*skip)(struct archive_read_filter *self, int64_t request);
|
83
|
+
/* Close (just this filter) and free(self). */
|
84
|
+
int (*close)(struct archive_read_filter *self);
|
85
|
+
/* My private data. */
|
86
|
+
void *data;
|
87
|
+
|
88
|
+
const char *name;
|
89
|
+
int code;
|
90
|
+
|
91
|
+
/* Used by reblocking logic. */
|
92
|
+
char *buffer;
|
93
|
+
size_t buffer_size;
|
94
|
+
char *next; /* Current read location. */
|
95
|
+
size_t avail; /* Bytes in my buffer. */
|
96
|
+
const void *client_buff; /* Client buffer information. */
|
97
|
+
size_t client_total;
|
98
|
+
const char *client_next;
|
99
|
+
size_t client_avail;
|
100
|
+
int64_t position;
|
101
|
+
char end_of_file;
|
102
|
+
char fatal;
|
103
|
+
};
|
104
|
+
|
105
|
+
/*
|
106
|
+
* The client looks a lot like a filter, so we just wrap it here.
|
107
|
+
*
|
108
|
+
* TODO: Make archive_read_filter and archive_read_client identical so
|
109
|
+
* that users of the library can easily register their own
|
110
|
+
* transformation filters. This will probably break the API/ABI and
|
111
|
+
* so should be deferred at least until libarchive 3.0.
|
112
|
+
*/
|
113
|
+
struct archive_read_client {
|
114
|
+
archive_read_callback *reader;
|
115
|
+
archive_skip_callback *skipper;
|
116
|
+
archive_close_callback *closer;
|
117
|
+
};
|
118
|
+
|
119
|
+
struct archive_read {
|
120
|
+
struct archive archive;
|
121
|
+
|
122
|
+
struct archive_entry *entry;
|
123
|
+
|
124
|
+
/* Dev/ino of the archive being read/written. */
|
125
|
+
dev_t skip_file_dev;
|
126
|
+
ino_t skip_file_ino;
|
127
|
+
|
128
|
+
/*
|
129
|
+
* Used by archive_read_data() to track blocks and copy
|
130
|
+
* data to client buffers, filling gaps with zero bytes.
|
131
|
+
*/
|
132
|
+
const char *read_data_block;
|
133
|
+
off_t read_data_offset;
|
134
|
+
off_t read_data_output_offset;
|
135
|
+
size_t read_data_remaining;
|
136
|
+
|
137
|
+
/* Callbacks to open/read/write/close client archive stream. */
|
138
|
+
struct archive_read_client client;
|
139
|
+
|
140
|
+
/* Registered filter bidders. */
|
141
|
+
struct archive_read_filter_bidder bidders[8];
|
142
|
+
|
143
|
+
/* Last filter in chain */
|
144
|
+
struct archive_read_filter *filter;
|
145
|
+
|
146
|
+
/* File offset of beginning of most recently-read header. */
|
147
|
+
off_t header_position;
|
148
|
+
|
149
|
+
/*
|
150
|
+
* Format detection is mostly the same as compression
|
151
|
+
* detection, with one significant difference: The bidders
|
152
|
+
* use the read_ahead calls above to examine the stream rather
|
153
|
+
* than having the supervisor hand them a block of data to
|
154
|
+
* examine.
|
155
|
+
*/
|
156
|
+
|
157
|
+
struct archive_format_descriptor {
|
158
|
+
void *data;
|
159
|
+
const char *name;
|
160
|
+
int (*bid)(struct archive_read *);
|
161
|
+
int (*options)(struct archive_read *, const char *key,
|
162
|
+
const char *value);
|
163
|
+
int (*read_header)(struct archive_read *, struct archive_entry *);
|
164
|
+
int (*read_data)(struct archive_read *, const void **, size_t *, off_t *);
|
165
|
+
int (*read_data_skip)(struct archive_read *);
|
166
|
+
int (*cleanup)(struct archive_read *);
|
167
|
+
} formats[9];
|
168
|
+
struct archive_format_descriptor *format; /* Active format. */
|
169
|
+
|
170
|
+
/*
|
171
|
+
* Various information needed by archive_extract.
|
172
|
+
*/
|
173
|
+
struct extract *extract;
|
174
|
+
int (*cleanup_archive_extract)(struct archive_read *);
|
175
|
+
};
|
176
|
+
|
177
|
+
int __archive_read_register_format(struct archive_read *a,
|
178
|
+
void *format_data,
|
179
|
+
const char *name,
|
180
|
+
int (*bid)(struct archive_read *),
|
181
|
+
int (*options)(struct archive_read *, const char *, const char *),
|
182
|
+
int (*read_header)(struct archive_read *, struct archive_entry *),
|
183
|
+
int (*read_data)(struct archive_read *, const void **, size_t *, off_t *),
|
184
|
+
int (*read_data_skip)(struct archive_read *),
|
185
|
+
int (*cleanup)(struct archive_read *));
|
186
|
+
|
187
|
+
struct archive_read_filter_bidder
|
188
|
+
*__archive_read_get_bidder(struct archive_read *a);
|
189
|
+
|
190
|
+
const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *);
|
191
|
+
const void *__archive_read_filter_ahead(struct archive_read_filter *,
|
192
|
+
size_t, ssize_t *);
|
193
|
+
ssize_t __archive_read_consume(struct archive_read *, size_t);
|
194
|
+
ssize_t __archive_read_filter_consume(struct archive_read_filter *, size_t);
|
195
|
+
int64_t __archive_read_skip(struct archive_read *, int64_t);
|
196
|
+
int64_t __archive_read_skip_lenient(struct archive_read *, int64_t);
|
197
|
+
int64_t __archive_read_filter_skip(struct archive_read_filter *, int64_t);
|
198
|
+
int __archive_read_program(struct archive_read_filter *, const char *);
|
199
|
+
#endif
|
@@ -0,0 +1,60 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include "archive_platform.h"
|
27
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_compression_all.c 201248 2009-12-30 06:12:03Z kientzle $");
|
28
|
+
|
29
|
+
#include "archive.h"
|
30
|
+
|
31
|
+
int
|
32
|
+
archive_read_support_compression_all(struct archive *a)
|
33
|
+
{
|
34
|
+
/* Bzip falls back to "bunzip2" command-line */
|
35
|
+
archive_read_support_compression_bzip2(a);
|
36
|
+
/* The decompress code doesn't use an outside library. */
|
37
|
+
archive_read_support_compression_compress(a);
|
38
|
+
/* Gzip decompress falls back to "gunzip" command-line. */
|
39
|
+
archive_read_support_compression_gzip(a);
|
40
|
+
/* The LZMA file format has a very weak signature, so it
|
41
|
+
* may not be feasible to keep this here, but we'll try.
|
42
|
+
* This will come back out if there are problems. */
|
43
|
+
/* Lzma falls back to "unlzma" command-line program. */
|
44
|
+
archive_read_support_compression_lzma(a);
|
45
|
+
/* Xz falls back to "unxz" command-line program. */
|
46
|
+
archive_read_support_compression_xz(a);
|
47
|
+
/* The decode code doesn't use an outside library. */
|
48
|
+
archive_read_support_compression_uu(a);
|
49
|
+
/* The decode code doesn't use an outside library. */
|
50
|
+
archive_read_support_compression_rpm(a);
|
51
|
+
|
52
|
+
/* Note: We always return ARCHIVE_OK here, even if some of the
|
53
|
+
* above return ARCHIVE_WARN. The intent here is to enable
|
54
|
+
* "as much as possible." Clients who need specific
|
55
|
+
* compression should enable those individually so they can
|
56
|
+
* verify the level of support. */
|
57
|
+
/* Clear any warning messages set by the above functions. */
|
58
|
+
archive_clear_error(a);
|
59
|
+
return (ARCHIVE_OK);
|
60
|
+
}
|
@@ -0,0 +1,353 @@
|
|
1
|
+
/*-
|
2
|
+
* Copyright (c) 2003-2007 Tim Kientzle
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions
|
7
|
+
* are met:
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
16
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
20
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
21
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
23
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*/
|
25
|
+
|
26
|
+
#include "archive_platform.h"
|
27
|
+
|
28
|
+
__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_compression_bzip2.c 201108 2009-12-28 03:28:21Z kientzle $");
|
29
|
+
|
30
|
+
#ifdef HAVE_ERRNO_H
|
31
|
+
#include <errno.h>
|
32
|
+
#endif
|
33
|
+
#include <stdio.h>
|
34
|
+
#ifdef HAVE_STDLIB_H
|
35
|
+
#include <stdlib.h>
|
36
|
+
#endif
|
37
|
+
#ifdef HAVE_STRING_H
|
38
|
+
#include <string.h>
|
39
|
+
#endif
|
40
|
+
#ifdef HAVE_UNISTD_H
|
41
|
+
#include <unistd.h>
|
42
|
+
#endif
|
43
|
+
#ifdef HAVE_BZLIB_H
|
44
|
+
#include <bzlib.h>
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#include "archive.h"
|
48
|
+
#include "archive_private.h"
|
49
|
+
#include "archive_read_private.h"
|
50
|
+
|
51
|
+
#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
|
52
|
+
struct private_data {
|
53
|
+
bz_stream stream;
|
54
|
+
char *out_block;
|
55
|
+
size_t out_block_size;
|
56
|
+
char valid; /* True = decompressor is initialized */
|
57
|
+
char eof; /* True = found end of compressed data. */
|
58
|
+
};
|
59
|
+
|
60
|
+
/* Bzip2 filter */
|
61
|
+
static ssize_t bzip2_filter_read(struct archive_read_filter *, const void **);
|
62
|
+
static int bzip2_filter_close(struct archive_read_filter *);
|
63
|
+
#endif
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Note that we can detect bzip2 archives even if we can't decompress
|
67
|
+
* them. (In fact, we like detecting them because we can give better
|
68
|
+
* error messages.) So the bid framework here gets compiled even
|
69
|
+
* if bzlib is unavailable.
|
70
|
+
*/
|
71
|
+
static int bzip2_reader_bid(struct archive_read_filter_bidder *, struct archive_read_filter *);
|
72
|
+
static int bzip2_reader_init(struct archive_read_filter *);
|
73
|
+
static int bzip2_reader_free(struct archive_read_filter_bidder *);
|
74
|
+
|
75
|
+
int
|
76
|
+
archive_read_support_compression_bzip2(struct archive *_a)
|
77
|
+
{
|
78
|
+
struct archive_read *a = (struct archive_read *)_a;
|
79
|
+
struct archive_read_filter_bidder *reader = __archive_read_get_bidder(a);
|
80
|
+
|
81
|
+
if (reader == NULL)
|
82
|
+
return (ARCHIVE_FATAL);
|
83
|
+
|
84
|
+
reader->data = NULL;
|
85
|
+
reader->bid = bzip2_reader_bid;
|
86
|
+
reader->init = bzip2_reader_init;
|
87
|
+
reader->options = NULL;
|
88
|
+
reader->free = bzip2_reader_free;
|
89
|
+
#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
|
90
|
+
return (ARCHIVE_OK);
|
91
|
+
#else
|
92
|
+
archive_set_error(_a, ARCHIVE_ERRNO_MISC,
|
93
|
+
"Using external bunzip2 program");
|
94
|
+
return (ARCHIVE_WARN);
|
95
|
+
#endif
|
96
|
+
}
|
97
|
+
|
98
|
+
static int
|
99
|
+
bzip2_reader_free(struct archive_read_filter_bidder *self){
|
100
|
+
(void)self; /* UNUSED */
|
101
|
+
return (ARCHIVE_OK);
|
102
|
+
}
|
103
|
+
|
104
|
+
/*
|
105
|
+
* Test whether we can handle this data.
|
106
|
+
*
|
107
|
+
* This logic returns zero if any part of the signature fails. It
|
108
|
+
* also tries to Do The Right Thing if a very short buffer prevents us
|
109
|
+
* from verifying as much as we would like.
|
110
|
+
*/
|
111
|
+
static int
|
112
|
+
bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_filter *filter)
|
113
|
+
{
|
114
|
+
const unsigned char *buffer;
|
115
|
+
ssize_t avail;
|
116
|
+
int bits_checked;
|
117
|
+
|
118
|
+
(void)self; /* UNUSED */
|
119
|
+
|
120
|
+
/* Minimal bzip2 archive is 14 bytes. */
|
121
|
+
buffer = __archive_read_filter_ahead(filter, 14, &avail);
|
122
|
+
if (buffer == NULL)
|
123
|
+
return (0);
|
124
|
+
|
125
|
+
/* First three bytes must be "BZh" */
|
126
|
+
bits_checked = 0;
|
127
|
+
if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h')
|
128
|
+
return (0);
|
129
|
+
bits_checked += 24;
|
130
|
+
|
131
|
+
/* Next follows a compression flag which must be an ASCII digit. */
|
132
|
+
if (buffer[3] < '1' || buffer[3] > '9')
|
133
|
+
return (0);
|
134
|
+
bits_checked += 5;
|
135
|
+
|
136
|
+
/* After BZh[1-9], there must be either a data block
|
137
|
+
* which begins with 0x314159265359 or an end-of-data
|
138
|
+
* marker of 0x177245385090. */
|
139
|
+
if (memcmp(buffer + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0)
|
140
|
+
bits_checked += 48;
|
141
|
+
else if (memcmp(buffer + 4, "\x17\x72\x45\x38\x50\x90", 6) == 0)
|
142
|
+
bits_checked += 48;
|
143
|
+
else
|
144
|
+
return (0);
|
145
|
+
|
146
|
+
return (bits_checked);
|
147
|
+
}
|
148
|
+
|
149
|
+
#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR)
|
150
|
+
|
151
|
+
/*
|
152
|
+
* If we don't have the library on this system, we can't actually do the
|
153
|
+
* decompression. We can, however, still detect compressed archives
|
154
|
+
* and emit a useful message.
|
155
|
+
*/
|
156
|
+
static int
|
157
|
+
bzip2_reader_init(struct archive_read_filter *self)
|
158
|
+
{
|
159
|
+
int r;
|
160
|
+
|
161
|
+
r = __archive_read_program(self, "bunzip2");
|
162
|
+
/* Note: We set the format here even if __archive_read_program()
|
163
|
+
* above fails. We do, after all, know what the format is
|
164
|
+
* even if we weren't able to read it. */
|
165
|
+
self->code = ARCHIVE_COMPRESSION_BZIP2;
|
166
|
+
self->name = "bzip2";
|
167
|
+
return (r);
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
#else
|
172
|
+
|
173
|
+
/*
|
174
|
+
* Setup the callbacks.
|
175
|
+
*/
|
176
|
+
static int
|
177
|
+
bzip2_reader_init(struct archive_read_filter *self)
|
178
|
+
{
|
179
|
+
static const size_t out_block_size = 64 * 1024;
|
180
|
+
void *out_block;
|
181
|
+
struct private_data *state;
|
182
|
+
|
183
|
+
self->code = ARCHIVE_COMPRESSION_BZIP2;
|
184
|
+
self->name = "bzip2";
|
185
|
+
|
186
|
+
state = (struct private_data *)calloc(sizeof(*state), 1);
|
187
|
+
out_block = (unsigned char *)malloc(out_block_size);
|
188
|
+
if (self == NULL || state == NULL || out_block == NULL) {
|
189
|
+
archive_set_error(&self->archive->archive, ENOMEM,
|
190
|
+
"Can't allocate data for bzip2 decompression");
|
191
|
+
free(out_block);
|
192
|
+
free(state);
|
193
|
+
return (ARCHIVE_FATAL);
|
194
|
+
}
|
195
|
+
|
196
|
+
self->data = state;
|
197
|
+
state->out_block_size = out_block_size;
|
198
|
+
state->out_block = out_block;
|
199
|
+
self->read = bzip2_filter_read;
|
200
|
+
self->skip = NULL; /* not supported */
|
201
|
+
self->close = bzip2_filter_close;
|
202
|
+
|
203
|
+
return (ARCHIVE_OK);
|
204
|
+
}
|
205
|
+
|
206
|
+
/*
|
207
|
+
* Return the next block of decompressed data.
|
208
|
+
*/
|
209
|
+
static ssize_t
|
210
|
+
bzip2_filter_read(struct archive_read_filter *self, const void **p)
|
211
|
+
{
|
212
|
+
struct private_data *state;
|
213
|
+
size_t decompressed;
|
214
|
+
const char *read_buf;
|
215
|
+
ssize_t ret;
|
216
|
+
|
217
|
+
state = (struct private_data *)self->data;
|
218
|
+
|
219
|
+
if (state->eof) {
|
220
|
+
*p = NULL;
|
221
|
+
return (0);
|
222
|
+
}
|
223
|
+
|
224
|
+
/* Empty our output buffer. */
|
225
|
+
state->stream.next_out = state->out_block;
|
226
|
+
state->stream.avail_out = state->out_block_size;
|
227
|
+
|
228
|
+
/* Try to fill the output buffer. */
|
229
|
+
for (;;) {
|
230
|
+
if (!state->valid) {
|
231
|
+
if (bzip2_reader_bid(self->bidder, self->upstream) == 0) {
|
232
|
+
state->eof = 1;
|
233
|
+
*p = state->out_block;
|
234
|
+
decompressed = state->stream.next_out
|
235
|
+
- state->out_block;
|
236
|
+
return (decompressed);
|
237
|
+
}
|
238
|
+
/* Initialize compression library. */
|
239
|
+
ret = BZ2_bzDecompressInit(&(state->stream),
|
240
|
+
0 /* library verbosity */,
|
241
|
+
0 /* don't use low-mem algorithm */);
|
242
|
+
|
243
|
+
/* If init fails, try low-memory algorithm instead. */
|
244
|
+
if (ret == BZ_MEM_ERROR)
|
245
|
+
ret = BZ2_bzDecompressInit(&(state->stream),
|
246
|
+
0 /* library verbosity */,
|
247
|
+
1 /* do use low-mem algo */);
|
248
|
+
|
249
|
+
if (ret != BZ_OK) {
|
250
|
+
const char *detail = NULL;
|
251
|
+
int err = ARCHIVE_ERRNO_MISC;
|
252
|
+
switch (ret) {
|
253
|
+
case BZ_PARAM_ERROR:
|
254
|
+
detail = "invalid setup parameter";
|
255
|
+
break;
|
256
|
+
case BZ_MEM_ERROR:
|
257
|
+
err = ENOMEM;
|
258
|
+
detail = "out of memory";
|
259
|
+
break;
|
260
|
+
case BZ_CONFIG_ERROR:
|
261
|
+
detail = "mis-compiled library";
|
262
|
+
break;
|
263
|
+
}
|
264
|
+
archive_set_error(&self->archive->archive, err,
|
265
|
+
"Internal error initializing decompressor%s%s",
|
266
|
+
detail == NULL ? "" : ": ",
|
267
|
+
detail);
|
268
|
+
return (ARCHIVE_FATAL);
|
269
|
+
}
|
270
|
+
state->valid = 1;
|
271
|
+
}
|
272
|
+
|
273
|
+
/* stream.next_in is really const, but bzlib
|
274
|
+
* doesn't declare it so. <sigh> */
|
275
|
+
read_buf =
|
276
|
+
__archive_read_filter_ahead(self->upstream, 1, &ret);
|
277
|
+
if (read_buf == NULL)
|
278
|
+
return (ARCHIVE_FATAL);
|
279
|
+
state->stream.next_in = (char *)(uintptr_t)read_buf;
|
280
|
+
state->stream.avail_in = ret;
|
281
|
+
/* There is no more data, return whatever we have. */
|
282
|
+
if (ret == 0) {
|
283
|
+
state->eof = 1;
|
284
|
+
*p = state->out_block;
|
285
|
+
decompressed = state->stream.next_out
|
286
|
+
- state->out_block;
|
287
|
+
return (decompressed);
|
288
|
+
}
|
289
|
+
|
290
|
+
/* Decompress as much as we can in one pass. */
|
291
|
+
ret = BZ2_bzDecompress(&(state->stream));
|
292
|
+
__archive_read_filter_consume(self->upstream,
|
293
|
+
state->stream.next_in - read_buf);
|
294
|
+
|
295
|
+
switch (ret) {
|
296
|
+
case BZ_STREAM_END: /* Found end of stream. */
|
297
|
+
switch (BZ2_bzDecompressEnd(&(state->stream))) {
|
298
|
+
case BZ_OK:
|
299
|
+
break;
|
300
|
+
default:
|
301
|
+
archive_set_error(&(self->archive->archive),
|
302
|
+
ARCHIVE_ERRNO_MISC,
|
303
|
+
"Failed to clean up decompressor");
|
304
|
+
return (ARCHIVE_FATAL);
|
305
|
+
}
|
306
|
+
state->valid = 0;
|
307
|
+
/* FALLTHROUGH */
|
308
|
+
case BZ_OK: /* Decompressor made some progress. */
|
309
|
+
/* If we filled our buffer, update stats and return. */
|
310
|
+
if (state->stream.avail_out == 0) {
|
311
|
+
*p = state->out_block;
|
312
|
+
decompressed = state->stream.next_out
|
313
|
+
- state->out_block;
|
314
|
+
return (decompressed);
|
315
|
+
}
|
316
|
+
break;
|
317
|
+
default: /* Return an error. */
|
318
|
+
archive_set_error(&self->archive->archive,
|
319
|
+
ARCHIVE_ERRNO_MISC, "bzip decompression failed");
|
320
|
+
return (ARCHIVE_FATAL);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
/*
|
326
|
+
* Clean up the decompressor.
|
327
|
+
*/
|
328
|
+
static int
|
329
|
+
bzip2_filter_close(struct archive_read_filter *self)
|
330
|
+
{
|
331
|
+
struct private_data *state;
|
332
|
+
int ret = ARCHIVE_OK;
|
333
|
+
|
334
|
+
state = (struct private_data *)self->data;
|
335
|
+
|
336
|
+
if (state->valid) {
|
337
|
+
switch (BZ2_bzDecompressEnd(&state->stream)) {
|
338
|
+
case BZ_OK:
|
339
|
+
break;
|
340
|
+
default:
|
341
|
+
archive_set_error(&self->archive->archive,
|
342
|
+
ARCHIVE_ERRNO_MISC,
|
343
|
+
"Failed to clean up decompressor");
|
344
|
+
ret = ARCHIVE_FATAL;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
free(state->out_block);
|
349
|
+
free(state);
|
350
|
+
return (ret);
|
351
|
+
}
|
352
|
+
|
353
|
+
#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */
|