]>
Commit | Line | Data |
---|---|---|
b24c88b3 RC |
1 | /* |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
3c054baf | 3 | * Copyright (c) 2002, Robert Collins. |
b24c88b3 RC |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * A copy of the GNU General Public License can be found at | |
11 | * http://www.gnu.org/ | |
12 | * | |
13 | * Written by DJ Delorie <dj@cygnus.com> | |
14 | * Made OOP by R Collins <rbtcollins@hotmail.com> | |
15 | * | |
16 | */ | |
17 | ||
18 | #ifndef __TAR_H_ | |
19 | #define __TAR_H_ | |
20 | ||
3c054baf RC |
21 | #include "io_stream.h" |
22 | #include "archive.h" | |
23 | #include "String++.h" | |
19911586 | 24 | #include "win32.h" |
3c054baf | 25 | |
b24c88b3 RC |
26 | typedef struct |
27 | { | |
28 | char name[100]; /* 0 */ | |
29 | char mode[8]; /* 100 */ | |
30 | char uid[8]; /* 108 */ | |
31 | char gid[8]; /* 116 */ | |
32 | char size[12]; /* 124 */ | |
33 | char mtime[12]; /* 136 */ | |
34 | char chksum[8]; /* 148 */ | |
35 | char typeflag; /* 156 */ | |
36 | char linkname[100]; /* 157 */ | |
37 | char magic[6]; /* 257 */ | |
38 | char version[2]; /* 263 */ | |
39 | char uname[32]; /* 265 */ | |
40 | char gname[32]; /* 297 */ | |
41 | char devmajor[8]; /* 329 */ | |
42 | char devminor[8]; /* 337 */ | |
43 | char prefix[155]; /* 345 */ | |
44 | char junk[12]; /* 500 */ | |
45 | } | |
46 | tar_header_type; | |
47 | ||
48 | typedef struct tar_map_result_type_s | |
49 | { | |
50 | struct tar_map_result_type_s *next; | |
3c054baf RC |
51 | String stored_name; |
52 | String mapped_name; | |
b24c88b3 RC |
53 | } |
54 | tar_map_result_type; | |
55 | ||
56 | class tar_state | |
57 | { | |
58 | public: | |
59 | tar_state ():lasterr (0), eocf (0), have_longname ('\0'), file_offset (0), | |
60 | file_length (0), header_read (0) | |
61 | { | |
62 | parent = NULL; | |
63 | filename[0] = '\0'; | |
64 | tar_map_result = NULL; | |
65 | }; | |
66 | io_stream *parent; | |
67 | int lasterr; | |
68 | int eocf; | |
69 | char have_longname; | |
70 | /* where in the current file are we? */ | |
71 | size_t file_offset; | |
72 | size_t file_length; | |
73 | int header_read; | |
74 | tar_header_type tar_header; | |
75 | char filename[_MAX_PATH + 512]; | |
76 | tar_map_result_type *tar_map_result; | |
77 | }; | |
78 | ||
79 | class archive_tar_file:public io_stream | |
80 | { | |
81 | public: | |
82 | archive_tar_file (tar_state &); | |
83 | virtual ssize_t read (void *buffer, size_t len); | |
84 | /* provide data to (double duh!) */ | |
ca9506cc | 85 | virtual ssize_t write (const void *buffer, size_t len); |
b24c88b3 RC |
86 | /* read data without removing it from the class's internal buffer */ |
87 | virtual ssize_t peek (void *buffer, size_t len); | |
88 | virtual long tell (); | |
ca9506cc | 89 | virtual int seek (long where, io_stream_seek_t whence); |
b24c88b3 RC |
90 | /* try guessing this one */ |
91 | virtual int error (); | |
b24c88b3 | 92 | virtual int get_mtime (); |
341988b9 | 93 | virtual size_t get_size () {return state.file_length;}; |
b24c88b3 RC |
94 | virtual int set_mtime (int) |
95 | { | |
96 | return 1; | |
97 | }; | |
98 | virtual ~ archive_tar_file (); | |
99 | private: | |
100 | tar_state & state; | |
101 | }; | |
102 | ||
103 | class archive_tar:public archive | |
104 | { | |
105 | public: | |
106 | archive_tar (io_stream * original); | |
107 | virtual io_stream *extract_file (); | |
108 | /* read data (duh!) */ | |
109 | virtual ssize_t read (void *buffer, size_t len); | |
110 | /* provide data to (double duh!) */ | |
ca9506cc | 111 | virtual ssize_t write (const void *buffer, size_t len); |
b24c88b3 RC |
112 | /* read data without removing it from the class's internal buffer */ |
113 | virtual ssize_t peek (void *buffer, size_t len); | |
114 | virtual long tell (); | |
ca9506cc | 115 | virtual int seek (long where, io_stream_seek_t whence); |
b24c88b3 RC |
116 | /* try guessing this one */ |
117 | virtual int error (); | |
118 | /* Find out the next stream name - | |
119 | * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar | |
120 | * for foobar that is an compress, next_file_name is the next | |
121 | * extractable filename. | |
122 | */ | |
3c054baf | 123 | virtual String const next_file_name (); |
b24c88b3 RC |
124 | virtual archive_file_t next_file_type (); |
125 | /* returns the mtime of the archive file, not of the current file */ | |
126 | virtual int get_mtime (); | |
341988b9 RC |
127 | /* nonsense for a tarball */ |
128 | virtual size_t get_size () {return 0;}; | |
b24c88b3 RC |
129 | /* only of use when we support writing to tar */ |
130 | virtual int set_mtime (int) | |
131 | { | |
132 | return 1; | |
133 | }; | |
3c054baf | 134 | virtual String const linktarget (); |
b24c88b3 RC |
135 | virtual int skip_file (); |
136 | /* if you are still needing these hints... give up now! */ | |
cbfc4215 RC |
137 | virtual ~ archive_tar (); |
138 | archive_tar& operator= (const archive_tar &); | |
139 | archive_tar (archive_tar const &); | |
b24c88b3 RC |
140 | private: |
141 | archive_tar () | |
142 | { | |
143 | }; | |
144 | tar_state state; | |
145 | unsigned int archive_children; | |
146 | }; | |
147 | ||
148 | /* Only one tarfile may be open at a time. gzipped files handled | |
149 | automatically */ | |
150 | ||
151 | /* returns zero on success, nonzero on failure */ | |
152 | //int tar_open (const char *pathname); | |
153 | ||
154 | /* pass adjusted path, returns zero on success, nonzero on failure */ | |
155 | //int tar_read_file (char *path); | |
156 | ||
157 | ||
158 | #if 0 | |
159 | /* pass path to tar file and from/to pairs for path prefix (NULLs at | |
160 | end , returns zero if completely successful, nonzero (counts | |
161 | errors) on failure */ | |
162 | int tar_auto (char *pathname, char **map); | |
163 | #endif | |
164 | ||
165 | ||
166 | //int tar_mkdir_p (int isadir, char *path); | |
167 | ||
168 | /* | |
169 | extern int _tar_verbose; | |
170 | extern FILE * _tar_vfile; | |
171 | */ | |
172 | ||
173 | #endif |