1 | /* |
1 | /* |
2 | * This file is part of uudeview, the simple and friendly multi-part multi- |
2 | * This file is part of uudeview, the simple and friendly multi-part multi- |
3 | * file uudecoder program (c) 1994 by Frank Pilhofer. The author may be |
3 | * file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may |
4 | * contacted by his email address, fp@informatik.uni-frankfurt.de |
4 | * be contacted at fp@fpx.de |
5 | * |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
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 |
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 |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
9 | * (at your option) any later version. |
… | |
… | |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | */ |
15 | */ |
16 | |
16 | |
17 | /* |
17 | /* |
18 | * This file implements the externally visible functions, as declared |
18 | * This file implements the externally visible functions, as declared |
19 | * in uulib.h, and some internal interfacing functions |
19 | * in uudeview.h, and some internal interfacing functions |
20 | */ |
20 | */ |
21 | |
21 | |
22 | #ifdef HAVE_CONFIG_H |
22 | #ifdef HAVE_CONFIG_H |
23 | #include "config.h" |
23 | #include "config.h" |
24 | #endif |
24 | #endif |
… | |
… | |
74 | /* to get open() in Windows */ |
74 | /* to get open() in Windows */ |
75 | #ifdef HAVE_IO_H |
75 | #ifdef HAVE_IO_H |
76 | #include <io.h> |
76 | #include <io.h> |
77 | #endif |
77 | #endif |
78 | |
78 | |
79 | #include <uulib.h> |
79 | #include <uudeview.h> |
80 | #include <uuint.h> |
80 | #include <uuint.h> |
81 | #include <fptools.h> |
81 | #include <fptools.h> |
82 | #include <uustring.h> |
82 | #include <uustring.h> |
83 | |
83 | |
84 | char * uulib_id = "$Id: uulib.c,v 1.1 2001/06/11 19:48:59 root Exp $"; |
84 | char * uulib_id = "$Id: uulib.c,v 1.2 2001/06/11 20:42:37 root Exp $"; |
85 | |
85 | |
86 | #ifdef SYSTEM_WINDLL |
86 | #ifdef SYSTEM_WINDLL |
87 | BOOL _export WINAPI |
87 | BOOL _export WINAPI |
88 | DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, |
88 | DllEntryPoint (HINSTANCE hInstance, DWORD seginfo, |
89 | LPVOID lpCmdLine) |
89 | LPVOID lpCmdLine) |
… | |
… | |
139 | int uu_overwrite = 1; /* whether it's ok to overwrite ex. files */ |
139 | int uu_overwrite = 1; /* whether it's ok to overwrite ex. files */ |
140 | int uu_ignmode = 0; /* ignore the original file mode */ |
140 | int uu_ignmode = 0; /* ignore the original file mode */ |
141 | int uu_handletext = 0; /* do we want text/plain messages */ |
141 | int uu_handletext = 0; /* do we want text/plain messages */ |
142 | int uu_usepreamble = 0; /* do we want Mime preambles/epilogues */ |
142 | int uu_usepreamble = 0; /* do we want Mime preambles/epilogues */ |
143 | int uu_tinyb64 = 0; /* detect short B64 outside of MIME */ |
143 | int uu_tinyb64 = 0; /* detect short B64 outside of MIME */ |
|
|
144 | int uu_remove_input = 0; /* remove input files after decoding */ |
|
|
145 | int uu_more_mime = 0; /* strictly adhere to MIME headers */ |
144 | |
146 | |
145 | headercount hlcount = { |
147 | headercount hlcount = { |
146 | 3, /* restarting after a MIME body */ |
148 | 3, /* restarting after a MIME body */ |
147 | 2, /* after useful data in freestyle mode */ |
149 | 2, /* after useful data in freestyle mode */ |
148 | 1 /* after useful data and an empty line */ |
150 | 1 /* after useful data and an empty line */ |
… | |
… | |
227 | { &uugen_fnbuffer, 1024 }, /* generic filename buffer */ |
229 | { &uugen_fnbuffer, 1024 }, /* generic filename buffer */ |
228 | { &uugen_inbuffer, 1024 }, /* generic input data buffer */ |
230 | { &uugen_inbuffer, 1024 }, /* generic input data buffer */ |
229 | { &uucheck_lastname, 256 }, /* from uucheck.c */ |
231 | { &uucheck_lastname, 256 }, /* from uucheck.c */ |
230 | { &uucheck_tempname, 256 }, |
232 | { &uucheck_tempname, 256 }, |
231 | { &uuestr_itemp, 256 }, /* from uuencode.c:UUEncodeStream() */ |
233 | { &uuestr_itemp, 256 }, /* from uuencode.c:UUEncodeStream() */ |
232 | { &uuestr_otemp, 256 }, |
234 | { &uuestr_otemp, 1024 }, |
233 | { &uulib_msgstring, 1024 }, /* from uulib.c:UUMessage() */ |
235 | { &uulib_msgstring, 1024 }, /* from uulib.c:UUMessage() */ |
234 | { &uuncdl_fulline, 256+4 }, /* from uunconc.c:UUDecodeLine(). +4 is for leftover parts */ |
236 | { &uuncdl_fulline, 256+4 }, /* from uunconc.c:UUDecodeLine(). +4 is for leftover parts */ |
235 | { &uuncdp_oline, 4*257 }, /* from uunconc.c:UUDecodePart() */ |
237 | { &uuncdp_oline, 4*257 }, /* from uunconc.c:UUDecodePart() */ |
236 | { &uunconc_UUxlat, 256 * sizeof (int) }, /* from uunconc.c:toplevel */ |
238 | { &uunconc_UUxlat, 256 * sizeof (int) }, /* from uunconc.c:toplevel */ |
237 | { &uunconc_UUxlen, 64 * sizeof (int) }, |
239 | { &uunconc_UUxlen, 64 * sizeof (int) }, |
… | |
… | |
485 | break; |
487 | break; |
486 | case UUOPT_ENCEXT: |
488 | case UUOPT_ENCEXT: |
487 | FP_strncpy (cvalue, uuencodeext, clength); |
489 | FP_strncpy (cvalue, uuencodeext, clength); |
488 | result = 0; |
490 | result = 0; |
489 | break; |
491 | break; |
|
|
492 | case UUOPT_REMOVE: |
|
|
493 | if (ivalue) *ivalue = uu_remove_input; |
|
|
494 | result = uu_remove_input; |
|
|
495 | break; |
|
|
496 | case UUOPT_MOREMIME: |
|
|
497 | if (ivalue) *ivalue = uu_more_mime; |
|
|
498 | result = uu_more_mime; |
|
|
499 | break; |
490 | default: |
500 | default: |
491 | return -1; |
501 | return -1; |
492 | } |
502 | } |
493 | return result; |
503 | return result; |
494 | } |
504 | } |
… | |
… | |
538 | uu_tinyb64 = ivalue; |
548 | uu_tinyb64 = ivalue; |
539 | break; |
549 | break; |
540 | case UUOPT_ENCEXT: |
550 | case UUOPT_ENCEXT: |
541 | FP_free (uuencodeext); |
551 | FP_free (uuencodeext); |
542 | uuencodeext = FP_strdup (cvalue); |
552 | uuencodeext = FP_strdup (cvalue); |
|
|
553 | break; |
|
|
554 | case UUOPT_REMOVE: |
|
|
555 | uu_remove_input = ivalue; |
|
|
556 | break; |
|
|
557 | case UUOPT_MOREMIME: |
|
|
558 | uu_more_mime = ivalue; |
543 | break; |
559 | break; |
544 | default: |
560 | default: |
545 | return UURET_ILLVAL; |
561 | return UURET_ILLVAL; |
546 | } |
562 | } |
547 | return UURET_OK; |
563 | return UURET_OK; |
… | |
… | |
737 | fclose (datei); |
753 | fclose (datei); |
738 | return UURET_IOERR; |
754 | return UURET_IOERR; |
739 | } |
755 | } |
740 | |
756 | |
741 | if ((loaded->uudet == QP_ENCODED || loaded->uudet == PT_ENCODED) && |
757 | if ((loaded->uudet == QP_ENCODED || loaded->uudet == PT_ENCODED) && |
|
|
758 | (loaded->filename == NULL || *(loaded->filename) == '\0') && |
742 | !uu_handletext && (loaded->flags&FL_PARTIAL)==0) { |
759 | !uu_handletext && (loaded->flags&FL_PARTIAL)==0) { |
743 | /* |
760 | /* |
744 | * Don't want text |
761 | * Don't want text |
745 | */ |
762 | */ |
746 | UUkillfread (loaded); |
763 | UUkillfread (loaded); |
… | |
… | |
1150 | |
1167 | |
1151 | int UUEXPORT |
1168 | int UUEXPORT |
1152 | UUCleanUp (void) |
1169 | UUCleanUp (void) |
1153 | { |
1170 | { |
1154 | itbd *iter=ftodel, *ptr; |
1171 | itbd *iter=ftodel, *ptr; |
|
|
1172 | uulist *liter; |
|
|
1173 | uufile *fiter; |
1155 | allomap *aiter; |
1174 | allomap *aiter; |
1156 | |
1175 | |
1157 | UUkilllist (UUGlobalFileList); |
|
|
1158 | UUGlobalFileList = NULL; |
|
|
1159 | |
|
|
1160 | /* |
1176 | /* |
1161 | * delete input files |
1177 | * delete temporary input files (such as the copy of stdin) |
1162 | */ |
1178 | */ |
|
|
1179 | |
1163 | while (iter) { |
1180 | while (iter) { |
1164 | if (unlink (iter->fname)) { |
1181 | if (unlink (iter->fname)) { |
1165 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1182 | UUMessage (uulib_id, __LINE__, UUMSG_WARNING, |
1166 | uustring (S_TMP_NOT_REMOVED), |
1183 | uustring (S_TMP_NOT_REMOVED), |
1167 | iter->fname, strerror (uu_errno = errno)); |
1184 | iter->fname, strerror (uu_errno = errno)); |
… | |
… | |
1169 | FP_free (iter->fname); |
1186 | FP_free (iter->fname); |
1170 | ptr = iter; |
1187 | ptr = iter; |
1171 | iter = iter->NEXT; |
1188 | iter = iter->NEXT; |
1172 | FP_free (ptr); |
1189 | FP_free (ptr); |
1173 | } |
1190 | } |
|
|
1191 | |
1174 | ftodel = NULL; |
1192 | ftodel = NULL; |
|
|
1193 | |
|
|
1194 | /* |
|
|
1195 | * Delete input files after successful decoding |
|
|
1196 | */ |
|
|
1197 | |
|
|
1198 | if (uu_remove_input) { |
|
|
1199 | liter = UUGlobalFileList; |
|
|
1200 | while (liter) { |
|
|
1201 | if (liter->state & UUFILE_DECODED) { |
|
|
1202 | fiter = liter->thisfile; |
|
|
1203 | while (fiter) { |
|
|
1204 | if (fiter->data && fiter->data->sfname) { |
|
|
1205 | /* |
|
|
1206 | * Error code ignored. We might want to delete a file multiple |
|
|
1207 | * times |
|
|
1208 | */ |
|
|
1209 | unlink (fiter->data->sfname); |
|
|
1210 | } |
|
|
1211 | fiter = fiter->NEXT; |
|
|
1212 | } |
|
|
1213 | } |
|
|
1214 | liter = liter->NEXT; |
|
|
1215 | } |
|
|
1216 | } |
|
|
1217 | |
|
|
1218 | UUkilllist (UUGlobalFileList); |
|
|
1219 | UUGlobalFileList = NULL; |
1175 | |
1220 | |
1176 | FP_free (uusavepath); |
1221 | FP_free (uusavepath); |
1177 | FP_free (uuencodeext); |
1222 | FP_free (uuencodeext); |
1178 | FP_free (sstate.source); |
1223 | FP_free (sstate.source); |
1179 | |
1224 | |