1 |
/* |
2 |
* This file is part of uudeview, the simple and friendly multi-part multi- |
3 |
* file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may |
4 |
* be contacted at fp@fpx.de |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
*/ |
16 |
|
17 |
#ifndef __UUDEVIEW_H__ |
18 |
#define __UUDEVIEW_H__ |
19 |
|
20 |
#include <stdint.h> |
21 |
|
22 |
/* |
23 |
* This include file features all the definitions that should |
24 |
* be externally visible. This isn't much. |
25 |
*/ |
26 |
|
27 |
/* |
28 |
* Message Types |
29 |
*/ |
30 |
|
31 |
#define UUMSG_MESSAGE (0) /* just a message, nothing important */ |
32 |
#define UUMSG_NOTE (1) /* something that should be noticed */ |
33 |
#define UUMSG_WARNING (2) /* important msg, processing continues */ |
34 |
#define UUMSG_ERROR (3) /* processing has been terminated */ |
35 |
#define UUMSG_FATAL (4) /* decoder cannot process further requests */ |
36 |
#define UUMSG_PANIC (5) /* recovery impossible, app must terminate */ |
37 |
|
38 |
/* |
39 |
* Return Values |
40 |
*/ |
41 |
|
42 |
#define UURET_OK (0) /* everything went fine */ |
43 |
#define UURET_IOERR (1) /* I/O Error - examine errno */ |
44 |
#define UURET_NOMEM (2) /* not enough memory */ |
45 |
#define UURET_ILLVAL (3) /* illegal value for operation */ |
46 |
#define UURET_NODATA (4) /* decoder didn't find any data */ |
47 |
#define UURET_NOEND (5) /* encoded data wasn't ended properly */ |
48 |
#define UURET_UNSUP (6) /* unsupported function (encoding) */ |
49 |
#define UURET_EXISTS (7) /* file exists (decoding) */ |
50 |
#define UURET_CONT (8) /* continue -- special from UUScanPart */ |
51 |
#define UURET_CANCEL (9) /* operation canceled */ |
52 |
|
53 |
/* |
54 |
* File states, may be OR'ed |
55 |
*/ |
56 |
|
57 |
#define UUFILE_READ (0) /* Read in, but not further processed */ |
58 |
#define UUFILE_MISPART (1) /* Missing Part(s) detected */ |
59 |
#define UUFILE_NOBEGIN (2) /* No 'begin' found */ |
60 |
#define UUFILE_NOEND (4) /* No 'end' found */ |
61 |
#define UUFILE_NODATA (8) /* File does not contain valid uudata */ |
62 |
#define UUFILE_OK (16) /* All Parts found, ready to decode */ |
63 |
#define UUFILE_ERROR (32) /* Error while decoding */ |
64 |
#define UUFILE_DECODED (64) /* Successfully decoded */ |
65 |
#define UUFILE_TMPFILE (128) /* Temporary decoded file exists */ |
66 |
|
67 |
/* |
68 |
* Encoding Types |
69 |
*/ |
70 |
|
71 |
#define UU_ENCODED (1) /* UUencoded data */ |
72 |
#define B64ENCODED (2) /* Mime-Base64 data */ |
73 |
#define XX_ENCODED (3) /* XXencoded data */ |
74 |
#define BH_ENCODED (4) /* Binhex encoded */ |
75 |
#define PT_ENCODED (5) /* Plain-Text encoded (MIME) */ |
76 |
#define QP_ENCODED (6) /* Quoted-Printable (MIME) */ |
77 |
#define YENC_ENCODED (7) /* yEnc encoded */ |
78 |
|
79 |
/* |
80 |
* Option indices for GetOption / SetOption |
81 |
*/ |
82 |
|
83 |
#define UUOPT_RBUF (90) /* file read I/O buffer size */ |
84 |
#define UUOPT_WBUF (91) /* file write I/O buffer size */ |
85 |
#define UUOPT_VERSION (0) /* version number MAJOR.MINORplPATCH (ro) */ |
86 |
#define UUOPT_FAST (1) /* assumes only one part per file */ |
87 |
#define UUOPT_DUMBNESS (2) /* switch off the program's intelligence */ |
88 |
#define UUOPT_BRACKPOL (3) /* give numbers in [] higher precendence */ |
89 |
#define UUOPT_VERBOSE (4) /* generate informative messages */ |
90 |
#define UUOPT_DESPERATE (5) /* try to decode incomplete files */ |
91 |
#define UUOPT_IGNREPLY (6) /* ignore RE:plies (off by default) */ |
92 |
#define UUOPT_OVERWRITE (7) /* whether it's OK to overwrite ex. files */ |
93 |
#define UUOPT_SAVEPATH (8) /* prefix to save-files on disk */ |
94 |
#define UUOPT_IGNMODE (9) /* ignore the original file mode */ |
95 |
#define UUOPT_DEBUG (10) /* print messages with FILE/LINE info */ |
96 |
#define UUOPT_ERRNO (14) /* get last error code for UURET_IOERR (ro) */ |
97 |
#define UUOPT_PROGRESS (15) /* retrieve progress information */ |
98 |
#define UUOPT_USETEXT (16) /* handle text messages */ |
99 |
#define UUOPT_PREAMB (17) /* handle Mime preambles/epilogues */ |
100 |
#define UUOPT_TINYB64 (18) /* detect short B64 outside of Mime */ |
101 |
#define UUOPT_ENCEXT (19) /* extension for single-part encoded files */ |
102 |
#define UUOPT_REMOVE (20) /* remove input files after decoding */ |
103 |
#define UUOPT_MOREMIME (21) /* strict MIME adherence */ |
104 |
#define UUOPT_DOTDOT (22) /* .. unescaping has not yet been done on input files */ |
105 |
#define UUOPT_AUTOCHECK (23) /* call checkgloballist after every part */ |
106 |
|
107 |
/* |
108 |
* Code for the "action" in the progress structure |
109 |
*/ |
110 |
|
111 |
#define UUACT_IDLE (0) /* we don't do anything */ |
112 |
#define UUACT_SCANNING (1) /* scanning an input file */ |
113 |
#define UUACT_DECODING (2) /* decoding into a temp file */ |
114 |
#define UUACT_COPYING (3) /* copying temp to target */ |
115 |
#define UUACT_ENCODING (4) /* encoding a file */ |
116 |
|
117 |
/* |
118 |
* forward definition |
119 |
*/ |
120 |
|
121 |
struct _uufile; |
122 |
|
123 |
/* |
124 |
* Structure for holding the list of files that have been found |
125 |
* uufile items are inserted into this list with UUInsertPartToList |
126 |
* After inserting a bunch of files, UUCheckGlobalList must be called |
127 |
* to update the states. |
128 |
*/ |
129 |
|
130 |
typedef struct _uulist { |
131 |
struct _uulist *NEXT; /* next item of the list */ |
132 |
struct _uulist *PREV; /* previous item of the list */ |
133 |
|
134 |
uint8_t state; /* Status as described by the macros above */ |
135 |
uint8_t flags; /* flags, especially for single-part files */ |
136 |
uint8_t uudet; /* Encoding type (see macros above) */ |
137 |
|
138 |
int begin; /* part number where begin was detected */ |
139 |
int end; /* part number where end was detected */ |
140 |
|
141 |
uint32_t filename_hash; /* hash of filename for faster comparisons */ |
142 |
uint32_t mimeid_hash; /* hash of filename for faster comparisons */ |
143 |
uint16_t mode; /* file mode as found on begin line */ |
144 |
|
145 |
char *filename; /* malloc'ed file name */ |
146 |
char *subfname; /* malloc'ed ID from subject line */ |
147 |
char *mimeid; /* malloc'ed MIME-ID, if available */ |
148 |
char *mimetype; /* malloc'ed Content-Type, if available */ |
149 |
|
150 |
char *binfile; /* name of temp file, if already decoded */ |
151 |
long size; /* approximate size of resulting file */ |
152 |
|
153 |
struct _uufile *thisfile; /* linked list of this file's parts */ |
154 |
|
155 |
int *haveparts; /* the parts we have (max. 256 are listed) */ |
156 |
int *misparts; /* list of missing parts (max. 256) */ |
157 |
} uulist; |
158 |
|
159 |
/* |
160 |
* The "progress" structure which is passed to the Busy Callback |
161 |
*/ |
162 |
|
163 |
typedef struct { |
164 |
int action; /* see UUACT_* definitions above */ |
165 |
char curfile[256]; /* the file we are working on, incl. path */ |
166 |
int partno; /* part we're currently decoding */ |
167 |
int numparts; /* total number of parts of this file */ |
168 |
long fsize; /* size of the current file */ |
169 |
int percent; /* % of _current part_ */ |
170 |
long foffset; /* file offset -- internal use only */ |
171 |
long totsize; /* file total size -- internal use only */ |
172 |
} uuprogress; |
173 |
|
174 |
/* |
175 |
* Structure that holds the information for a single file / part of |
176 |
* a file. If a subject line is encountered, it is copied to subject; |
177 |
* if a begin is found, the mode and name of the file is extracted. |
178 |
* flags are set if 'begin' or 'end' is detected and 'uudet' if valid |
179 |
* uuencoded data is found. If the file contains a 'From:' line with |
180 |
* a '@' in it (indicating an origin email address), it is preserved |
181 |
* in 'origin'. |
182 |
**/ |
183 |
|
184 |
typedef struct _fileread { |
185 |
char *subject; /* Whole subject line */ |
186 |
char *filename; /* Only filled in if begin detected */ |
187 |
char *origin; /* Whole 'From:' line */ |
188 |
char *mimeid; /* the ID for Mime-encoded files */ |
189 |
char *mimetype; /* Content-Type */ |
190 |
int begin; /* begin detected */ |
191 |
int end; /* end detected */ |
192 |
long yefilesize; /* the yencode file size, or 0 */ |
193 |
|
194 |
uint16_t mode; /* Mode of File (from 'begin') */ |
195 |
uint8_t flags; /* associated flags */ |
196 |
uint8_t uudet; /* valid encoded data. value indicates encoding */ |
197 |
int partno; /* Mime-files have a part number within */ |
198 |
int maxpno; /* ... plus the total number of parts */ |
199 |
|
200 |
char *sfname; /* Associated source file */ |
201 |
long startpos; /* ftell() position where data starts */ |
202 |
long length; /* length of data */ |
203 |
} fileread; |
204 |
|
205 |
/* |
206 |
* Structure for holding one part of a file, with some more information |
207 |
* about it. The UUPreProcessPart() function takes one a fileread structure |
208 |
* and produces this uufile structure. |
209 |
* Linked List, ordered by partno. |
210 |
**/ |
211 |
|
212 |
typedef struct _uufile { |
213 |
struct _uufile *NEXT; |
214 |
char *filename; |
215 |
char *subfname; |
216 |
char *mimeid; |
217 |
char *mimetype; |
218 |
fileread *data; |
219 |
long yefilesize; |
220 |
int partno; |
221 |
} uufile; |
222 |
|
223 |
/* |
224 |
* Externally visible functions and variables |
225 |
*/ |
226 |
|
227 |
#ifndef UUEXPORT |
228 |
#define UUEXPORT |
229 |
#endif |
230 |
|
231 |
#ifdef __cplusplus |
232 |
extern "C" { |
233 |
#endif |
234 |
|
235 |
extern uulist *UUGlobalFileList; |
236 |
|
237 |
extern void (*uu_MsgCallback) (void *, char *, int); |
238 |
extern int (*uu_BusyCallback) (void *, uuprogress *); |
239 |
extern int (*uu_FileCallback) (void *, char *, char *, int); |
240 |
extern char * (*uu_FNameFilter) (void *, char *); |
241 |
extern char * (*uu_FileNameCallback)(void *, char *, char *); |
242 |
|
243 |
int UUEXPORT UUInitialize (void); |
244 |
int UUEXPORT UUGetOption (int, int *, char *, int); |
245 |
int UUEXPORT UUSetOption (int, int, char *); |
246 |
char * UUEXPORT UUstrerror (int); |
247 |
int UUEXPORT UUSetMsgCallback (void *, |
248 |
void (*) (void *, |
249 |
char *, |
250 |
int)); |
251 |
int UUEXPORT UUSetBusyCallback (void *, |
252 |
int (*) (void *, |
253 |
uuprogress *), |
254 |
long); |
255 |
int UUEXPORT UUSetFileCallback (void *, |
256 |
int (*) (void *, char *, |
257 |
char *, int)); |
258 |
int UUEXPORT UUSetFNameFilter (void *, |
259 |
char * (*) (void *, |
260 |
char *)); |
261 |
int UUEXPORT UUSetFileNameCallback (void *, |
262 |
char * (*) (void *, |
263 |
char *, char *)); |
264 |
char * UUEXPORT UUFNameFilter (char *); |
265 |
int UUEXPORT UULoadFile (char *, char *, int, int *); |
266 |
int UUEXPORT UULoadFileWithPartNo (char *, char *, int, int, int *); |
267 |
uulist *UUEXPORT UUGetFileListItem (int); |
268 |
int UUEXPORT UURenameFile (uulist *, char *); |
269 |
int UUEXPORT UUDecodeToTemp (uulist *); |
270 |
int UUEXPORT UURemoveTemp (uulist *); |
271 |
int UUEXPORT UUDecodeFile (uulist *, char *); |
272 |
int UUEXPORT UUInfoFile (uulist *, void *, |
273 |
int (*) (void *, |
274 |
char *)); |
275 |
int UUEXPORT UUSmerge (int); |
276 |
int UUEXPORT UUCleanUp (void); |
277 |
|
278 |
int UUEXPORT UUQuickDecode (FILE *, FILE *, |
279 |
char *, long); |
280 |
|
281 |
int UUEXPORT UUEncodeMulti (FILE *, FILE *, |
282 |
char *, int, |
283 |
char *, char *, int); |
284 |
int UUEXPORT UUEncodePartial (FILE *, FILE *, |
285 |
char *, int, |
286 |
char *, char *, |
287 |
int, int, long, |
288 |
uint32_t *); |
289 |
int UUEXPORT UUEncodeToStream (FILE *, FILE *, |
290 |
char *, int, |
291 |
char *, int); |
292 |
int UUEXPORT UUEncodeToFile (FILE *, char *, int, |
293 |
char *, char *, long); |
294 |
int UUEXPORT UUE_PrepSingle (FILE *, FILE *, |
295 |
char *, int, |
296 |
char *, int, |
297 |
char *, char *, |
298 |
char *, int); |
299 |
int UUEXPORT UUE_PrepPartial (FILE *, FILE *, |
300 |
char *, int, |
301 |
char *, int, |
302 |
int, long, long, char *, |
303 |
char *, char *, int); |
304 |
|
305 |
int UUEXPORT UUE_PrepSingleExt (FILE *, FILE *, |
306 |
char *, int, |
307 |
char *, int, |
308 |
char *, char *, |
309 |
char *, char *, |
310 |
int); |
311 |
int UUEXPORT UUE_PrepPartialExt (FILE *, FILE *, |
312 |
char *, int, |
313 |
char *, int, |
314 |
int, long, long, char *, |
315 |
char *, char *, char *, |
316 |
int); |
317 |
void UUEXPORT UUCheckGlobalList (void); |
318 |
#ifdef __cplusplus |
319 |
} |
320 |
#endif |
321 |
#endif |