… | |
… | |
47 | #endif |
47 | #endif |
48 | #ifdef HAVE_ERRNO_H |
48 | #ifdef HAVE_ERRNO_H |
49 | #include <errno.h> |
49 | #include <errno.h> |
50 | #endif |
50 | #endif |
51 | |
51 | |
|
|
52 | #include <crc32.h> |
52 | #include <uudeview.h> |
53 | #include <uudeview.h> |
53 | #include <uuint.h> |
54 | #include <uuint.h> |
54 | #include <fptools.h> |
55 | #include <fptools.h> |
55 | #include <uustring.h> |
56 | #include <uustring.h> |
56 | |
57 | |
57 | char * uunconc_id = "$Id: uunconc.c,v 1.3 2002/02/10 22:47:18 root Exp $"; |
58 | char * uunconc_id = "$Id: uunconc.c,v 1.3.2.3 2002/10/13 13:03:08 root Exp $"; |
58 | |
59 | |
59 | /* for braindead systems */ |
60 | /* for braindead systems */ |
60 | #ifndef SEEK_SET |
61 | #ifndef SEEK_SET |
61 | #ifdef L_BEGIN |
62 | #ifdef L_BEGIN |
62 | #define SEEK_SET L_BEGIN |
63 | #define SEEK_SET L_BEGIN |
… | |
… | |
116 | |
117 | |
117 | /* |
118 | /* |
118 | * To prevent warnings when using a char as index into an array |
119 | * To prevent warnings when using a char as index into an array |
119 | */ |
120 | */ |
120 | |
121 | |
121 | #define ACAST(s) ((int)(uchar)(s)) |
122 | #define ACAST(s) ((int)(unsigned char)(s)) |
122 | |
123 | |
123 | /* |
124 | /* |
124 | * Initialize decoding tables |
125 | * Initialize decoding tables |
125 | */ |
126 | */ |
126 | |
127 | |
… | |
… | |
193 | int len; |
194 | int len; |
194 | |
195 | |
195 | if (string==NULL || (len=strlen(string))<3) |
196 | if (string==NULL || (len=strlen(string))<3) |
196 | return 0; |
197 | return 0; |
197 | |
198 | |
198 | if ((ptr = FP_stristr (string, "<a href=")) != NULL) { |
199 | if ((ptr = _FP_stristr (string, "<a href=")) != NULL) { |
199 | if (FP_stristr (string, "</a>") > ptr) |
200 | if (_FP_stristr (string, "</a>") > ptr) |
200 | return 2; |
201 | return 2; |
201 | } |
202 | } |
202 | |
203 | |
203 | ptr = string + len; |
204 | ptr = string + len; |
204 | |
205 | |
… | |
… | |
207 | } |
208 | } |
208 | if (len<3) return 0; |
209 | if (len<3) return 0; |
209 | if (*--ptr == ' ') ptr--; |
210 | if (*--ptr == ' ') ptr--; |
210 | ptr--; |
211 | ptr--; |
211 | |
212 | |
212 | if (FP_strnicmp (ptr, "<a", 2) == 0) |
213 | if (_FP_strnicmp (ptr, "<a", 2) == 0) |
213 | return 1; |
214 | return 1; |
214 | |
215 | |
215 | return 0; |
216 | return 0; |
216 | } |
217 | } |
217 | |
218 | |
… | |
… | |
241 | /* |
242 | /* |
242 | * First pass |
243 | * First pass |
243 | */ |
244 | */ |
244 | while (*p1) { |
245 | while (*p1) { |
245 | if (*p1 == '&') { |
246 | if (*p1 == '&') { |
246 | if (FP_strnicmp (p1, "&", 5) == 0) { p1+=5; *p2++='&'; res=1; } |
247 | if (_FP_strnicmp (p1, "&", 5) == 0) { p1+=5; *p2++='&'; res=1; } |
247 | else if (FP_strnicmp (p1, "<", 4) == 0) { p1+=4; *p2++='<'; res=1; } |
248 | else if (_FP_strnicmp (p1, "<", 4) == 0) { p1+=4; *p2++='<'; res=1; } |
248 | else if (FP_strnicmp (p1, ">", 4) == 0) { p1+=4; *p2++='>'; res=1; } |
249 | else if (_FP_strnicmp (p1, ">", 4) == 0) { p1+=4; *p2++='>'; res=1; } |
249 | else *p2++ = *p1++; |
250 | else *p2++ = *p1++; |
250 | res = 1; |
|
|
251 | } |
251 | } |
252 | else *p2++ = *p1++; |
252 | else *p2++ = *p1++; |
253 | } |
253 | } |
254 | *p2 = '\0'; |
254 | *p2 = '\0'; |
255 | /* |
255 | /* |
… | |
… | |
257 | */ |
257 | */ |
258 | p1 = p2 = string; |
258 | p1 = p2 = string; |
259 | |
259 | |
260 | while (*p1) { |
260 | while (*p1) { |
261 | if (*p1 == '<') { |
261 | if (*p1 == '<') { |
262 | if ((FP_strnicmp (p1, "<ahref=", 7) == 0 || |
262 | if ((_FP_strnicmp (p1, "<ahref=", 7) == 0 || |
263 | FP_strnicmp (p1, "<a href=",8) == 0) && |
263 | _FP_strnicmp (p1, "<a href=",8) == 0) && |
264 | (FP_strstr (p1, "</a>") != 0 || FP_strstr (p1, "</A>") != 0)) { |
264 | (_FP_strstr (p1, "</a>") != 0 || _FP_strstr (p1, "</A>") != 0)) { |
265 | while (*p1 && *p1!='>') p1++; |
265 | while (*p1 && *p1!='>') p1++; |
266 | if (*p1=='\0' || *(p1+1)!='<') return 0; |
266 | if (*p1=='\0' || *(p1+1)!='<') return 0; |
267 | p1++; |
267 | p1++; |
268 | while (*p1 && (*p1!='<' || FP_strnicmp(p1,"</a>",4)!=0)) { |
268 | while (*p1 && (*p1!='<' || _FP_strnicmp(p1,"</a>",4)!=0)) { |
269 | *p2++ = *p1++; |
269 | *p2++ = *p1++; |
270 | } |
270 | } |
271 | if (FP_strnicmp(p1,"</a>",4) != 0) |
271 | if (_FP_strnicmp(p1,"</a>",4) != 0) |
272 | return 0; |
272 | return 0; |
273 | p1+=4; |
273 | p1+=4; |
274 | res=1; |
274 | res=1; |
275 | } |
275 | } |
276 | else |
276 | else |
… | |
… | |
296 | UUValidData (char *ptr, int encoding, int *bhflag) |
296 | UUValidData (char *ptr, int encoding, int *bhflag) |
297 | { |
297 | { |
298 | int i=0, j, len=0, suspicious=0, flag=0; |
298 | int i=0, j, len=0, suspicious=0, flag=0; |
299 | char *s = ptr; |
299 | char *s = ptr; |
300 | |
300 | |
301 | if ((s == NULL) || ((schar)*s < '\0')) { |
301 | if ((s == NULL) || (*s == '\0')) { |
302 | return(0); /* bad string */ |
302 | return 0; /* bad string */ |
303 | } |
|
|
304 | |
303 | } |
|
|
304 | |
305 | while (*s && *s!='\012' && *s!='\015') { |
305 | while (*s && *s!='\012' && *s!='\015') { |
306 | s++; |
306 | s++; |
307 | len++; |
307 | len++; |
308 | i++; |
308 | i++; |
309 | } |
309 | } |
… | |
… | |
318 | goto _t_XX; |
318 | goto _t_XX; |
319 | case B64ENCODED: |
319 | case B64ENCODED: |
320 | goto _t_B64; |
320 | goto _t_B64; |
321 | case BH_ENCODED: |
321 | case BH_ENCODED: |
322 | goto _t_Binhex; |
322 | goto _t_Binhex; |
|
|
323 | case YENC_ENCODED: |
|
|
324 | return YENC_ENCODED; |
323 | } |
325 | } |
324 | |
326 | |
325 | _t_Binhex: /* Binhex Test */ |
327 | _t_Binhex: /* Binhex Test */ |
326 | len = i; s = ptr; |
328 | len = i; s = ptr; |
327 | |
329 | |
… | |
… | |
467 | */ |
469 | */ |
468 | if (encoding != UU_ENCODED) |
470 | if (encoding != UU_ENCODED) |
469 | if (strchr (ptr, ' ') != NULL) |
471 | if (strchr (ptr, ' ') != NULL) |
470 | goto _t_XX; |
472 | goto _t_XX; |
471 | |
473 | |
472 | /* suspicious = 1; we're careful here REMOVED 0.4.15 _FP__ */ |
474 | /* suspicious = 1; we're careful here REMOVED 0.4.15 __FP__ */ |
473 | len = j; |
475 | len = j; |
474 | } |
476 | } |
475 | |
477 | |
476 | while (len--) { |
478 | while (len--) { |
477 | if (*s < 0 || UUxlat[ACAST(*s++)] < 0) { |
479 | if (*s < 0 || UUxlat[ACAST(*s++)] < 0) { |
… | |
… | |
540 | while (vflag == 0 && nflag && safety--) { |
542 | while (vflag == 0 && nflag && safety--) { |
541 | if (nflag == 1) { /* need next line to repair */ |
543 | if (nflag == 1) { /* need next line to repair */ |
542 | ptr = line + strlen (line); |
544 | ptr = line + strlen (line); |
543 | while (ptr>line && (*(ptr-1)=='\015' || *(ptr-1)=='\012')) |
545 | while (ptr>line && (*(ptr-1)=='\015' || *(ptr-1)=='\012')) |
544 | ptr--; |
546 | ptr--; |
545 | if (FP_fgets (ptr, 255-(ptr-line), datei) == NULL) |
547 | if (_FP_fgets (ptr, 255-(ptr-line), datei) == NULL) |
546 | break; |
548 | break; |
547 | } |
549 | } |
548 | else { /* don't need next line to repair */ |
550 | else { /* don't need next line to repair */ |
549 | } |
551 | } |
550 | if (UUNetscapeCollapse (line)) { |
552 | if (UUNetscapeCollapse (line)) { |
… | |
… | |
616 | if (method == UU_ENCODED) |
618 | if (method == UU_ENCODED) |
617 | table = UUxlat; |
619 | table = UUxlat; |
618 | else |
620 | else |
619 | table = XXxlat; |
621 | table = XXxlat; |
620 | |
622 | |
621 | i = table [(uchar)*s++]; |
623 | i = table [ACAST(*s++)]; |
622 | j = UUxlen[i] - 1; |
624 | j = UUxlen[i] - 1; |
623 | |
625 | |
624 | while(j > 0) { |
626 | while(j > 0) { |
625 | c = table[(uchar)*s++] << 2; |
627 | c = table[ACAST(*s++)] << 2; |
626 | cc = table[(uchar)*s++]; |
628 | cc = table[ACAST(*s++)]; |
627 | c |= (cc >> 4); |
629 | c |= (cc >> 4); |
628 | |
630 | |
629 | if(i-- > 0) |
631 | if(i-- > 0) |
630 | d[count++] = c; |
632 | d[count++] = c; |
631 | |
633 | |
632 | cc <<= 4; |
634 | cc <<= 4; |
633 | c = table[(uchar)*s++]; |
635 | c = table[ACAST(*s++)]; |
634 | cc |= (c >> 2); |
636 | cc |= (c >> 2); |
635 | |
637 | |
636 | if(i-- > 0) |
638 | if(i-- > 0) |
637 | d[count++] = cc; |
639 | d[count++] = cc; |
638 | |
640 | |
639 | c <<= 6; |
641 | c <<= 6; |
640 | c |= table[(uchar)*s++]; |
642 | c |= table[ACAST(*s++)]; |
641 | |
643 | |
642 | if(i-- > 0) |
644 | if(i-- > 0) |
643 | d[count++] = c; |
645 | d[count++] = c; |
644 | |
646 | |
645 | j -= 4; |
647 | j -= 4; |
… | |
… | |
704 | d[count++] = (z2 << 4) | (z3 >> 2); |
706 | d[count++] = (z2 << 4) | (z3 >> 2); |
705 | s+=3; |
707 | s+=3; |
706 | } |
708 | } |
707 | while (BHxlat[ACAST(*s)] != -1) |
709 | while (BHxlat[ACAST(*s)] != -1) |
708 | uuncdl_fulline[leftover++] = *s++; |
710 | uuncdl_fulline[leftover++] = *s++; |
|
|
711 | } |
|
|
712 | else if (method == YENC_ENCODED) { |
|
|
713 | while (*s) { |
|
|
714 | if (*s == '=') { |
|
|
715 | if (*++s != '\0') { |
|
|
716 | d[count++] = (char) ((int) *s - 64 - 42); |
|
|
717 | s++; |
|
|
718 | } |
|
|
719 | } |
|
|
720 | else if (*s == '\n' || *s == '\r') { |
|
|
721 | s++; /* ignore */ |
|
|
722 | } |
|
|
723 | else { |
|
|
724 | d[count++] = (char) ((int) *s++ - 42); |
|
|
725 | } |
|
|
726 | } |
709 | } |
727 | } |
710 | |
728 | |
711 | return count; |
729 | return count; |
712 | } |
730 | } |
713 | |
731 | |
… | |
… | |
726 | uulboundary = -1; |
744 | uulboundary = -1; |
727 | |
745 | |
728 | while (!feof (datain) && |
746 | while (!feof (datain) && |
729 | (ftell(datain)<maxpos || flags&FL_TOEND || |
747 | (ftell(datain)<maxpos || flags&FL_TOEND || |
730 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
748 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
731 | if (FP_fgets (line, 255, datain) == NULL) |
749 | if (_FP_fgets (line, 255, datain) == NULL) |
732 | break; |
750 | break; |
733 | if (ferror (datain)) { |
751 | if (ferror (datain)) { |
734 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
752 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
735 | uustring (S_SOURCE_READ_ERR), |
753 | uustring (S_SOURCE_READ_ERR), |
736 | strerror (uu_errno = errno)); |
754 | strerror (uu_errno = errno)); |
… | |
… | |
823 | uulboundary = -1; |
841 | uulboundary = -1; |
824 | |
842 | |
825 | while (!feof (datain) && |
843 | while (!feof (datain) && |
826 | (ftell(datain)<maxpos || flags&FL_TOEND || |
844 | (ftell(datain)<maxpos || flags&FL_TOEND || |
827 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
845 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
828 | if (FP_fgets (line, 255, datain) == NULL) |
846 | if (_FP_fgets (line, 255, datain) == NULL) |
829 | break; |
847 | break; |
830 | if (ferror (datain)) { |
848 | if (ferror (datain)) { |
831 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
849 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
832 | uustring (S_SOURCE_READ_ERR), |
850 | uustring (S_SOURCE_READ_ERR), |
833 | strerror (uu_errno = errno)); |
851 | strerror (uu_errno = errno)); |
… | |
… | |
882 | char *boundary) |
900 | char *boundary) |
883 | { |
901 | { |
884 | char *line=uugen_fnbuffer, *oline=uuncdp_oline; |
902 | char *line=uugen_fnbuffer, *oline=uuncdp_oline; |
885 | int warning=0, vlc=0, lc[2], hadct=0; |
903 | int warning=0, vlc=0, lc[2], hadct=0; |
886 | int tc=0, tf=0, vflag, haddata=0, haddh=0; |
904 | int tc=0, tf=0, vflag, haddata=0, haddh=0; |
|
|
905 | long yefilesize=0, yepartends=0; |
|
|
906 | crc32_t yepartcrc=crc32(0L, Z_NULL, 0); |
|
|
907 | static crc32_t yefilecrc=0; |
887 | static int bhflag=0; |
908 | static int bhflag=0; |
888 | size_t count=0; |
909 | size_t count=0; |
|
|
910 | size_t yepartsize=0; |
|
|
911 | char *ptr; |
889 | |
912 | |
890 | if (datain == NULL || dataout == NULL) { |
913 | if (datain == NULL || dataout == NULL) { |
|
|
914 | yefilecrc = crc32(0L, Z_NULL, 0); |
891 | bhflag = 0; |
915 | bhflag = 0; |
892 | return UURET_OK; |
916 | return UURET_OK; |
893 | } |
917 | } |
894 | |
918 | |
895 | /* |
919 | /* |
… | |
… | |
906 | lc[0] = lc[1] = 0; |
930 | lc[0] = lc[1] = 0; |
907 | vflag = 0; |
931 | vflag = 0; |
908 | |
932 | |
909 | uulboundary = -1; |
933 | uulboundary = -1; |
910 | |
934 | |
|
|
935 | if (method == YENC_ENCODED) { |
|
|
936 | *state = BEGIN; |
|
|
937 | } |
|
|
938 | |
911 | while (!feof (datain) && *state != DONE && |
939 | while (!feof (datain) && *state != DONE && |
912 | (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 || |
940 | (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 || |
913 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
941 | (!(flags&FL_PROPER) && uu_fast_scanning))) { |
914 | if (FP_fgets (line, 255, datain) == NULL) |
942 | if (_FP_fgets (line, 299, datain) == NULL) |
915 | break; |
943 | break; |
|
|
944 | |
916 | if (ferror (datain)) { |
945 | if (ferror (datain)) { |
917 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
946 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
918 | uustring (S_SOURCE_READ_ERR), |
947 | uustring (S_SOURCE_READ_ERR), |
919 | strerror (uu_errno = errno)); |
948 | strerror (uu_errno = errno)); |
920 | return UURET_IOERR; |
949 | return UURET_IOERR; |
921 | } |
950 | } |
|
|
951 | |
922 | if (line[0]=='\015' || line[0]=='\012') { /* Empty line? */ |
952 | if (line[0]=='\015' || line[0]=='\012') { /* Empty line? */ |
923 | if (*state == DATA && |
953 | if (*state == DATA && |
924 | (method == UU_ENCODED || method == XX_ENCODED)) |
954 | (method == UU_ENCODED || method == XX_ENCODED)) |
925 | *state = END; |
955 | *state = END; |
|
|
956 | |
926 | /* |
957 | /* |
927 | * if we had a whole block of valid lines before, we reset our |
958 | * if we had a whole block of valid lines before, we reset our |
928 | * 'valid data' flag, tf. Without this 'if', we'd break decoding |
959 | * 'valid data' flag, tf. Without this 'if', we'd break decoding |
929 | * files with interleaved blank lines. The value of 5 is chosen |
960 | * files with interleaved blank lines. The value of 5 is chosen |
930 | * quite arbitrarly. |
961 | * quite arbitrarly. |
931 | */ |
962 | */ |
|
|
963 | |
932 | if (vlc > 5) |
964 | if (vlc > 5) |
933 | tf = tc = 0; |
965 | tf = tc = 0; |
934 | vlc = 0; |
966 | vlc = 0; |
935 | continue; |
967 | continue; |
936 | } |
968 | } |
… | |
… | |
947 | |
979 | |
948 | /* |
980 | /* |
949 | * try to make sense of data |
981 | * try to make sense of data |
950 | */ |
982 | */ |
951 | |
983 | |
952 | line[255] = '\0'; /* For Safety of string functions */ |
984 | line[299] = '\0'; /* For Safety of string functions */ |
953 | count = 0; |
985 | count = 0; |
954 | |
986 | |
955 | if (boundary && line[0]=='-' && line[1]=='-' && |
987 | if (boundary && line[0]=='-' && line[1]=='-' && |
956 | strncmp (line+2, boundary, strlen (boundary)) == 0) { |
988 | strncmp (line+2, boundary, strlen (boundary)) == 0) { |
957 | if (line[strlen(boundary)+2]=='-') |
989 | if (line[strlen(boundary)+2]=='-') |
… | |
… | |
965 | * Use this pseudo-handling only if !FL_PROPER |
997 | * Use this pseudo-handling only if !FL_PROPER |
966 | */ |
998 | */ |
967 | |
999 | |
968 | if ((flags&FL_PROPER) == 0) { |
1000 | if ((flags&FL_PROPER) == 0) { |
969 | if (strncmp (line, "BEGIN", 5) == 0 && |
1001 | if (strncmp (line, "BEGIN", 5) == 0 && |
970 | FP_strstr (line, "CUT HERE") && !tf) { /* I hate these lines */ |
1002 | _FP_strstr (line, "CUT HERE") && !tf) { /* I hate these lines */ |
971 | tc = tf = vlc = 0; |
1003 | tc = tf = vlc = 0; |
972 | continue; |
1004 | continue; |
973 | } |
1005 | } |
974 | /* MIME body boundary */ |
1006 | /* MIME body boundary */ |
975 | if (line[0] == '-' && line[1] == '-' && method == B64ENCODED) { |
1007 | if (line[0] == '-' && line[1] == '-' && method == B64ENCODED) { |
… | |
… | |
981 | } |
1013 | } |
982 | hadct = 0; |
1014 | hadct = 0; |
983 | haddh = 1; |
1015 | haddh = 1; |
984 | continue; |
1016 | continue; |
985 | } |
1017 | } |
986 | if (FP_strnicmp (line, "Content-Type", 12) == 0) |
1018 | if (_FP_strnicmp (line, "Content-Type", 12) == 0) |
987 | hadct = 1; |
1019 | hadct = 1; |
988 | } |
1020 | } |
989 | |
1021 | |
990 | if (*state == BEGIN) { |
1022 | if (*state == BEGIN) { |
|
|
1023 | if ((method == UU_ENCODED || method == XX_ENCODED) && |
991 | if (strncmp (line, "begin ", 6) == 0 || |
1024 | (strncmp (line, "begin ", 6) == 0 || |
992 | FP_strnicmp (line, "<pre>begin ", 11) == 0) { /* for LYNX */ |
1025 | _FP_strnicmp (line, "<pre>begin ", 11) == 0)) { /* for LYNX */ |
993 | *state = DATA; |
1026 | *state = DATA; |
994 | continue; |
1027 | continue; |
995 | } |
1028 | } |
996 | else if (method == BH_ENCODED && line[0] == ':') { |
1029 | else if (method == BH_ENCODED && line[0] == ':') { |
997 | if (UUValidData (line, BH_ENCODED, &bhflag) == BH_ENCODED) { |
1030 | if (UUValidData (line, BH_ENCODED, &bhflag) == BH_ENCODED) { |
… | |
… | |
999 | *state = DATA; |
1032 | *state = DATA; |
1000 | } |
1033 | } |
1001 | else |
1034 | else |
1002 | continue; |
1035 | continue; |
1003 | } |
1036 | } |
1004 | else |
1037 | else if (method == YENC_ENCODED && |
|
|
1038 | strncmp (line, "=ybegin ", 8) == 0 && |
|
|
1039 | _FP_strstr (line, " name=") != NULL) { |
|
|
1040 | *state = DATA; |
|
|
1041 | |
|
|
1042 | if ((ptr = _FP_strstr (line, " size=")) != NULL) { |
|
|
1043 | ptr += 6; |
|
|
1044 | yefilesize = atoi (ptr); |
|
|
1045 | } |
|
|
1046 | else { |
|
|
1047 | yefilesize = -1; |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | if (_FP_strstr (line, " part=") != NULL) { |
|
|
1051 | if (_FP_fgets (line, 299, datain) == NULL) { |
|
|
1052 | break; |
|
|
1053 | } |
|
|
1054 | |
|
|
1055 | if ((ptr = _FP_strstr (line, " end=")) == NULL) { |
|
|
1056 | break; |
|
|
1057 | } |
|
|
1058 | |
|
|
1059 | yepartends = atoi (ptr + 5); |
|
|
1060 | } |
|
|
1061 | tf = 1; |
1005 | continue; |
1062 | continue; |
|
|
1063 | } |
|
|
1064 | else { |
|
|
1065 | continue; |
|
|
1066 | } |
1006 | |
1067 | |
1007 | tc = tf = vlc = 0; |
1068 | tc = tf = vlc = 0; |
1008 | lc[0] = lc[1] = 0; |
1069 | lc[0] = lc[1] = 0; |
1009 | } |
1070 | } |
1010 | else if ((*state == END) && |
1071 | else if ((*state == END) && |
… | |
… | |
1012 | if (strncmp (line, "end", 3) == 0) { |
1073 | if (strncmp (line, "end", 3) == 0) { |
1013 | *state = DONE; |
1074 | *state = DONE; |
1014 | break; |
1075 | break; |
1015 | } |
1076 | } |
1016 | } |
1077 | } |
|
|
1078 | |
|
|
1079 | if (*state == DATA && method == YENC_ENCODED && |
|
|
1080 | strncmp (line, "=yend ", 6) == 0) { |
|
|
1081 | if ((ptr = _FP_strstr (line, " pcrc32=")) != NULL) { |
|
|
1082 | crc32_t pcrc32 = strtoul (ptr + 8, NULL, 16); |
|
|
1083 | if (pcrc32 != yepartcrc) { |
|
|
1084 | UUMessage (uunconc_id, __LINE__, UUMSG_WARNING, |
|
|
1085 | uustring (S_PCRC_MISMATCH), progress.curfile, progress.partno); |
|
|
1086 | } |
|
|
1087 | } |
|
|
1088 | if ((ptr = _FP_strstr (line, " crc32=")) != NULL) |
|
|
1089 | { |
|
|
1090 | crc32_t fcrc32 = strtoul (ptr + 7, NULL, 16); |
|
|
1091 | if (fcrc32 != yefilecrc) { |
|
|
1092 | UUMessage (uunconc_id, __LINE__, UUMSG_WARNING, |
|
|
1093 | uustring (S_CRC_MISMATCH), progress.curfile); |
|
|
1094 | } |
|
|
1095 | } |
|
|
1096 | if ((ptr = _FP_strstr (line, " size=")) != NULL) |
|
|
1097 | { |
|
|
1098 | size_t size = atol(ptr + 6); |
|
|
1099 | if (size != yepartsize && yefilesize != -1) { |
|
|
1100 | if (size != yefilesize) |
|
|
1101 | UUMessage (uunconc_id, __LINE__, UUMSG_WARNING, |
|
|
1102 | uustring (S_PSIZE_MISMATCH), progress.curfile, |
|
|
1103 | progress.partno, yepartsize, size); |
|
|
1104 | else |
|
|
1105 | UUMessage (uunconc_id, __LINE__, UUMSG_WARNING, |
|
|
1106 | uustring (S_SIZE_MISMATCH), progress.curfile, |
|
|
1107 | yepartsize, size); |
|
|
1108 | } |
|
|
1109 | } |
|
|
1110 | if (yepartends == 0 || yepartends >= yefilesize) { |
|
|
1111 | *state = DONE; |
|
|
1112 | } |
|
|
1113 | break; |
|
|
1114 | } |
|
|
1115 | |
1017 | if (*state == DATA || *state == END) { |
1116 | if (*state == DATA || *state == END) { |
1018 | if (method==B64ENCODED && line[0]=='-' && line[1]=='-' && tc) { |
1117 | if (method==B64ENCODED && line[0]=='-' && line[1]=='-' && tc) { |
1019 | break; |
1118 | break; |
1020 | } |
1119 | } |
1021 | |
1120 | |
… | |
… | |
1033 | } |
1132 | } |
1034 | |
1133 | |
1035 | if (vflag == method) { |
1134 | if (vflag == method) { |
1036 | if (tf) { |
1135 | if (tf) { |
1037 | count = UUDecodeLine (line, oline, method); |
1136 | count = UUDecodeLine (line, oline, method); |
|
|
1137 | if (method == YENC_ENCODED) { |
|
|
1138 | if (yepartends) |
|
|
1139 | yepartcrc = crc32(yepartcrc, oline, count); |
|
|
1140 | yefilecrc = crc32(yefilecrc, oline, count); |
|
|
1141 | yepartsize += count; |
|
|
1142 | } |
1038 | vlc++; lc[1]++; |
1143 | vlc++; lc[1]++; |
1039 | } |
1144 | } |
1040 | else if (tc == 3) { |
1145 | else if (tc == 3) { |
1041 | count = UUDecodeLine (save[0], oline, method); |
1146 | count = UUDecodeLine (save[0], oline, method); |
1042 | count += UUDecodeLine (save[1], oline + count, method); |
1147 | count += UUDecodeLine (save[1], oline + count, method); |
… | |
… | |
1058 | } |
1163 | } |
1059 | lc[0] = 0; |
1164 | lc[0] = 0; |
1060 | lc[1] = 3; |
1165 | lc[1] = 3; |
1061 | } |
1166 | } |
1062 | else { |
1167 | else { |
1063 | FP_strncpy (save[tc++], line, 256); |
1168 | _FP_strncpy (save[tc++], line, 256); |
1064 | } |
1169 | } |
|
|
1170 | |
1065 | if (method == UU_ENCODED) |
1171 | if (method == UU_ENCODED) |
1066 | *state = (line[0] == 'M') ? DATA : END; |
1172 | *state = (line[0] == 'M') ? DATA : END; |
1067 | else if (method == XX_ENCODED) |
1173 | else if (method == XX_ENCODED) |
1068 | *state = (line[0] == 'h') ? DATA : END; |
1174 | *state = (line[0] == 'h') ? DATA : END; |
1069 | else if (method == B64ENCODED) |
1175 | else if (method == B64ENCODED) |
… | |
… | |
1078 | } |
1184 | } |
1079 | } |
1185 | } |
1080 | else if (*state != DONE) { |
1186 | else if (*state != DONE) { |
1081 | return UURET_NOEND; |
1187 | return UURET_NOEND; |
1082 | } |
1188 | } |
|
|
1189 | |
1083 | if (count) { |
1190 | if (count) { |
1084 | if (method == BH_ENCODED) { |
1191 | if (method == BH_ENCODED) { |
1085 | if (UUbhwrite (oline, 1, count, dataout) != count) { |
1192 | if (UUbhwrite (oline, 1, count, dataout) != count) { |
1086 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1193 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1087 | uustring (S_WR_ERR_TEMP), |
1194 | uustring (S_WR_ERR_TEMP), |
… | |
… | |
1137 | FILE *datain, *dataout; |
1244 | FILE *datain, *dataout; |
1138 | unsigned char r[8]; |
1245 | unsigned char r[8]; |
1139 | char *mode, *ntmp; |
1246 | char *mode, *ntmp; |
1140 | uufile *iter; |
1247 | uufile *iter; |
1141 | size_t bytes; |
1248 | size_t bytes; |
1142 | #ifdef HAVE_MKSTEMP |
|
|
1143 | int tmpfd; |
|
|
1144 | const char *tmpprefix = "uuXXXXXX"; |
|
|
1145 | char *tmpdir = NULL; |
|
|
1146 | #endif /* HAVE_MKSTEMP */ |
|
|
1147 | |
1249 | |
1148 | if (data == NULL || data->thisfile == NULL) |
1250 | if (data == NULL || data->thisfile == NULL) |
1149 | return UURET_ILLVAL; |
1251 | return UURET_ILLVAL; |
1150 | |
1252 | |
1151 | if (data->state & UUFILE_TMPFILE) |
1253 | if (data->state & UUFILE_TMPFILE) |
… | |
… | |
1160 | if (data->uudet == PT_ENCODED) |
1262 | if (data->uudet == PT_ENCODED) |
1161 | mode = "wt"; /* open text files in text mode */ |
1263 | mode = "wt"; /* open text files in text mode */ |
1162 | else |
1264 | else |
1163 | mode = "wb"; /* otherwise in binary */ |
1265 | mode = "wb"; /* otherwise in binary */ |
1164 | |
1266 | |
1165 | #ifdef HAVE_MKSTEMP |
|
|
1166 | if ((getuid()==geteuid()) && (getgid()==getegid())) { |
|
|
1167 | tmpdir=getenv("TMPDIR"); |
|
|
1168 | } |
|
|
1169 | |
|
|
1170 | if (!tmpdir) { |
|
|
1171 | tmpdir = "/tmp"; |
|
|
1172 | } |
|
|
1173 | data->binfile = malloc(strlen(tmpdir)+strlen(tmpprefix)+2); |
|
|
1174 | |
|
|
1175 | if (!data->binfile) { |
|
|
1176 | #else |
|
|
1177 | if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |
1267 | if ((data->binfile = tempnam (NULL, "uu")) == NULL) { |
1178 | #endif /* HAVE_MKSTEMP */ |
|
|
1179 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1268 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1180 | uustring (S_NO_TEMP_NAME)); |
1269 | uustring (S_NO_TEMP_NAME)); |
1181 | return UURET_NOMEM; |
1270 | return UURET_NOMEM; |
1182 | } |
1271 | } |
1183 | |
1272 | |
1184 | #ifdef HAVE_MKSTEMP |
|
|
1185 | strcpy(data->binfile, tmpdir); |
|
|
1186 | strcat(data->binfile, "/"); |
|
|
1187 | strcat(data->binfile, tmpprefix); |
|
|
1188 | |
|
|
1189 | if ((tmpfd = mkstemp(data->binfile)) == -1 || |
|
|
1190 | (dataout = fdopen(tmpfd, mode)) == NULL) { |
|
|
1191 | #else |
|
|
1192 | if ((dataout = fopen (data->binfile, mode)) == NULL) { |
1273 | if ((dataout = fopen (data->binfile, mode)) == NULL) { |
1193 | #endif /* HAVE_MKSTEMP */ |
|
|
1194 | /* |
1274 | /* |
1195 | * we couldn't create a temporary file. Usually this means that TMP |
1275 | * we couldn't create a temporary file. Usually this means that TMP |
1196 | * and TEMP aren't set |
1276 | * and TEMP aren't set |
1197 | */ |
1277 | */ |
1198 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1278 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1199 | uustring (S_WR_ERR_TARGET), |
1279 | uustring (S_WR_ERR_TARGET), |
1200 | data->binfile, strerror (uu_errno = errno)); |
1280 | data->binfile, strerror (uu_errno = errno)); |
1201 | #ifdef HAVE_MKSTEMP |
|
|
1202 | if (tmpfd != -1) { |
|
|
1203 | unlink(data->binfile); |
|
|
1204 | close(tmpfd); |
|
|
1205 | } |
|
|
1206 | #endif /* HAVE_MKSTEMP */ |
|
|
1207 | FP_free (data->binfile); |
1281 | _FP_free (data->binfile); |
1208 | data->binfile = NULL; |
1282 | data->binfile = NULL; |
1209 | uu_errno = errno; |
1283 | uu_errno = errno; |
1210 | return UURET_IOERR; |
1284 | return UURET_IOERR; |
1211 | } |
1285 | } |
1212 | |
|
|
1213 | /* |
1286 | /* |
1214 | * we don't have begin lines in Base64 or plain text files. |
1287 | * we don't have begin lines in Base64 or plain text files. |
1215 | */ |
1288 | */ |
1216 | if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED || |
1289 | if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED || |
1217 | data->uudet == PT_ENCODED) |
1290 | data->uudet == PT_ENCODED) |
… | |
… | |
1232 | /* |
1305 | /* |
1233 | * initialize progress information |
1306 | * initialize progress information |
1234 | */ |
1307 | */ |
1235 | progress.action = 0; |
1308 | progress.action = 0; |
1236 | if (data->filename != NULL) { |
1309 | if (data->filename != NULL) { |
1237 | FP_strncpy (progress.curfile, |
1310 | _FP_strncpy (progress.curfile, |
1238 | (strlen(data->filename)>255)? |
1311 | (strlen(data->filename)>255)? |
1239 | (data->filename+strlen(data->filename)-255):data->filename, |
1312 | (data->filename+strlen(data->filename)-255):data->filename, |
1240 | 256); |
1313 | 256); |
1241 | } |
1314 | } |
1242 | else { |
1315 | else { |
1243 | FP_strncpy (progress.curfile, |
1316 | _FP_strncpy (progress.curfile, |
1244 | (strlen(data->binfile)>255)? |
1317 | (strlen(data->binfile)>255)? |
1245 | (data->binfile+strlen(data->binfile)-255):data->binfile, |
1318 | (data->binfile+strlen(data->binfile)-255):data->binfile, |
1246 | 256); |
1319 | 256); |
1247 | } |
1320 | } |
1248 | progress.partno = 0; |
1321 | progress.partno = 0; |
… | |
… | |
1297 | uustring (S_NOT_OPEN_FILE), |
1370 | uustring (S_NOT_OPEN_FILE), |
1298 | iter->data->sfname, strerror (uu_errno = errno)); |
1371 | iter->data->sfname, strerror (uu_errno = errno)); |
1299 | res = UURET_IOERR; |
1372 | res = UURET_IOERR; |
1300 | break; |
1373 | break; |
1301 | } |
1374 | } |
1302 | FP_strncpy (uugen_fnbuffer, iter->data->sfname, 1024); |
1375 | _FP_strncpy (uugen_fnbuffer, iter->data->sfname, 1024); |
1303 | } |
1376 | } |
1304 | |
1377 | |
1305 | progress.partno = part; |
1378 | progress.partno = part; |
1306 | progress.fsize = (iter->data->length)?iter->data->length:-1; |
1379 | progress.fsize = (iter->data->length)?iter->data->length:-1; |
1307 | progress.percent = 0; |
1380 | progress.percent = 0; |
… | |
… | |
1329 | |
1402 | |
1330 | fclose (dataout); |
1403 | fclose (dataout); |
1331 | |
1404 | |
1332 | if (res != UURET_OK || (state != DONE && !uu_desperate)) { |
1405 | if (res != UURET_OK || (state != DONE && !uu_desperate)) { |
1333 | unlink (data->binfile); |
1406 | unlink (data->binfile); |
1334 | FP_free (data->binfile); |
1407 | _FP_free (data->binfile); |
1335 | data->binfile = NULL; |
1408 | data->binfile = NULL; |
1336 | data->state &= ~UUFILE_TMPFILE; |
1409 | data->state &= ~UUFILE_TMPFILE; |
1337 | data->state |= UUFILE_ERROR; |
1410 | data->state |= UUFILE_ERROR; |
1338 | |
1411 | |
1339 | if (res == UURET_OK && state != DONE) |
1412 | if (res == UURET_OK && state != DONE) |
… | |
… | |
1351 | /* |
1424 | /* |
1352 | * If this was a BinHex file, we must extract its data or resource fork |
1425 | * If this was a BinHex file, we must extract its data or resource fork |
1353 | */ |
1426 | */ |
1354 | |
1427 | |
1355 | if (data->uudet == BH_ENCODED && data->binfile) { |
1428 | if (data->uudet == BH_ENCODED && data->binfile) { |
1356 | #ifdef HAVE_MKSTEMP |
|
|
1357 | ntmp = malloc(strlen(tmpdir)+strlen(tmpprefix)+2); |
|
|
1358 | |
|
|
1359 | if (ntmp == NULL) { |
|
|
1360 | #else |
|
|
1361 | if ((ntmp = tempnam (NULL, "uu")) == NULL) { |
1429 | if ((ntmp = tempnam (NULL, "uu")) == NULL) { |
1362 | #endif /* HAVE_MKSTEMP */ |
|
|
1363 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1430 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1364 | uustring (S_NO_TEMP_NAME)); |
1431 | uustring (S_NO_TEMP_NAME)); |
1365 | progress.action = 0; |
1432 | progress.action = 0; |
1366 | return UURET_NOMEM; |
1433 | return UURET_NOMEM; |
1367 | } |
1434 | } |
… | |
… | |
1371 | data->binfile, strerror (uu_errno = errno)); |
1438 | data->binfile, strerror (uu_errno = errno)); |
1372 | progress.action = 0; |
1439 | progress.action = 0; |
1373 | free (ntmp); |
1440 | free (ntmp); |
1374 | return UURET_IOERR; |
1441 | return UURET_IOERR; |
1375 | } |
1442 | } |
1376 | #ifdef HAVE_MKSTEMP |
|
|
1377 | strcpy(ntmp, tmpdir); |
|
|
1378 | strcat(ntmp, "/"); |
|
|
1379 | strcat(ntmp, tmpprefix); |
|
|
1380 | if ((tmpfd = mkstemp(ntmp)) == -1 || |
|
|
1381 | (dataout = fdopen(tmpfd, "wb")) == NULL) { |
|
|
1382 | #else |
|
|
1383 | if ((dataout = fopen (ntmp, "wb")) == NULL) { |
1443 | if ((dataout = fopen (ntmp, "wb")) == NULL) { |
1384 | #endif /* HAVE_MKSTEMP */ |
|
|
1385 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1444 | UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, |
1386 | uustring (S_NOT_OPEN_TARGET), |
1445 | uustring (S_NOT_OPEN_TARGET), |
1387 | ntmp, strerror (uu_errno = errno)); |
1446 | ntmp, strerror (uu_errno = errno)); |
1388 | progress.action = 0; |
1447 | progress.action = 0; |
1389 | fclose (datain); |
1448 | fclose (datain); |
1390 | #ifdef HAVE_MKSTEMP |
|
|
1391 | if (tmpfd != -1) { |
|
|
1392 | unlink(ntmp); |
|
|
1393 | close(tmpfd); |
|
|
1394 | } |
|
|
1395 | #endif /* HAVE_MKSTEMP */ |
|
|
1396 | free (ntmp); |
1449 | free (ntmp); |
1397 | return UURET_IOERR; |
1450 | return UURET_IOERR; |
1398 | } |
1451 | } |
1399 | |
|
|
1400 | /* |
1452 | /* |
1401 | * read fork lengths. remember they're in Motorola format |
1453 | * read fork lengths. remember they're in Motorola format |
1402 | */ |
1454 | */ |
1403 | r[0] = fgetc (datain); |
1455 | r[0] = fgetc (datain); |
1404 | hb = (int) r[0] + 22; |
1456 | hb = (int) r[0] + 22; |
… | |
… | |
1530 | */ |
1582 | */ |
1531 | |
1583 | |
1532 | memset (&myenv, 0, sizeof (headers)); |
1584 | memset (&myenv, 0, sizeof (headers)); |
1533 | UUScanHeader (datain, &myenv); |
1585 | UUScanHeader (datain, &myenv); |
1534 | |
1586 | |
1535 | if (FP_stristr (myenv.ctenc, "uu") != NULL) |
1587 | if (_FP_stristr (myenv.ctenc, "uu") != NULL) |
1536 | encoding = UU_ENCODED; |
1588 | encoding = UU_ENCODED; |
1537 | else if (FP_stristr (myenv.ctenc, "xx") != NULL) |
1589 | else if (_FP_stristr (myenv.ctenc, "xx") != NULL) |
1538 | encoding = XX_ENCODED; |
1590 | encoding = XX_ENCODED; |
1539 | else if (FP_stricmp (myenv.ctenc, "base64") == 0) |
1591 | else if (_FP_stricmp (myenv.ctenc, "base64") == 0) |
1540 | encoding = B64ENCODED; |
1592 | encoding = B64ENCODED; |
1541 | else if (FP_stricmp (myenv.ctenc, "quoted-printable") == 0) |
1593 | else if (_FP_stricmp (myenv.ctenc, "quoted-printable") == 0) |
1542 | encoding = QP_ENCODED; |
1594 | encoding = QP_ENCODED; |
1543 | else |
1595 | else |
1544 | encoding = PT_ENCODED; |
1596 | encoding = PT_ENCODED; |
1545 | |
1597 | |
1546 | UUkillheaders (&myenv); |
1598 | UUkillheaders (&myenv); |