ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/uulib/uunconc.c
(Generate patch)

Comparing Convert-UUlib/uulib/uunconc.c (file contents):
Revision 1.3 by root, Sun Feb 10 22:47:18 2002 UTC vs.
Revision 1.3.2.2 by root, Sun Mar 31 19:52:07 2002 UTC

52#include <uudeview.h> 52#include <uudeview.h>
53#include <uuint.h> 53#include <uuint.h>
54#include <fptools.h> 54#include <fptools.h>
55#include <uustring.h> 55#include <uustring.h>
56 56
57char * uunconc_id = "$Id: uunconc.c,v 1.3 2002/02/10 22:47:18 root Exp $"; 57char * uunconc_id = "$Id: uunconc.c,v 1.3.2.2 2002/03/31 19:52:07 root Exp $";
58 58
59/* for braindead systems */ 59/* for braindead systems */
60#ifndef SEEK_SET 60#ifndef SEEK_SET
61#ifdef L_BEGIN 61#ifdef L_BEGIN
62#define SEEK_SET L_BEGIN 62#define SEEK_SET L_BEGIN
116 116
117/* 117/*
118 * To prevent warnings when using a char as index into an array 118 * To prevent warnings when using a char as index into an array
119 */ 119 */
120 120
121#define ACAST(s) ((int)(uchar)(s)) 121#define ACAST(s) ((int)(unsigned char)(s))
122 122
123/* 123/*
124 * Initialize decoding tables 124 * Initialize decoding tables
125 */ 125 */
126 126
193 int len; 193 int len;
194 194
195 if (string==NULL || (len=strlen(string))<3) 195 if (string==NULL || (len=strlen(string))<3)
196 return 0; 196 return 0;
197 197
198 if ((ptr = FP_stristr (string, "<a href=")) != NULL) { 198 if ((ptr = _FP_stristr (string, "<a href=")) != NULL) {
199 if (FP_stristr (string, "</a>") > ptr) 199 if (_FP_stristr (string, "</a>") > ptr)
200 return 2; 200 return 2;
201 } 201 }
202 202
203 ptr = string + len; 203 ptr = string + len;
204 204
207 } 207 }
208 if (len<3) return 0; 208 if (len<3) return 0;
209 if (*--ptr == ' ') ptr--; 209 if (*--ptr == ' ') ptr--;
210 ptr--; 210 ptr--;
211 211
212 if (FP_strnicmp (ptr, "<a", 2) == 0) 212 if (_FP_strnicmp (ptr, "<a", 2) == 0)
213 return 1; 213 return 1;
214 214
215 return 0; 215 return 0;
216} 216}
217 217
241 /* 241 /*
242 * First pass 242 * First pass
243 */ 243 */
244 while (*p1) { 244 while (*p1) {
245 if (*p1 == '&') { 245 if (*p1 == '&') {
246 if (FP_strnicmp (p1, "&amp;", 5) == 0) { p1+=5; *p2++='&'; res=1; } 246 if (_FP_strnicmp (p1, "&amp;", 5) == 0) { p1+=5; *p2++='&'; res=1; }
247 else if (FP_strnicmp (p1, "&lt;", 4) == 0) { p1+=4; *p2++='<'; res=1; } 247 else if (_FP_strnicmp (p1, "&lt;", 4) == 0) { p1+=4; *p2++='<'; res=1; }
248 else if (FP_strnicmp (p1, "&gt;", 4) == 0) { p1+=4; *p2++='>'; res=1; } 248 else if (_FP_strnicmp (p1, "&gt;", 4) == 0) { p1+=4; *p2++='>'; res=1; }
249 else *p2++ = *p1++; 249 else *p2++ = *p1++;
250 res = 1;
251 } 250 }
252 else *p2++ = *p1++; 251 else *p2++ = *p1++;
253 } 252 }
254 *p2 = '\0'; 253 *p2 = '\0';
255 /* 254 /*
257 */ 256 */
258 p1 = p2 = string; 257 p1 = p2 = string;
259 258
260 while (*p1) { 259 while (*p1) {
261 if (*p1 == '<') { 260 if (*p1 == '<') {
262 if ((FP_strnicmp (p1, "<ahref=", 7) == 0 || 261 if ((_FP_strnicmp (p1, "<ahref=", 7) == 0 ||
263 FP_strnicmp (p1, "<a href=",8) == 0) && 262 _FP_strnicmp (p1, "<a href=",8) == 0) &&
264 (FP_strstr (p1, "</a>") != 0 || FP_strstr (p1, "</A>") != 0)) { 263 (_FP_strstr (p1, "</a>") != 0 || _FP_strstr (p1, "</A>") != 0)) {
265 while (*p1 && *p1!='>') p1++; 264 while (*p1 && *p1!='>') p1++;
266 if (*p1=='\0' || *(p1+1)!='<') return 0; 265 if (*p1=='\0' || *(p1+1)!='<') return 0;
267 p1++; 266 p1++;
268 while (*p1 && (*p1!='<' || FP_strnicmp(p1,"</a>",4)!=0)) { 267 while (*p1 && (*p1!='<' || _FP_strnicmp(p1,"</a>",4)!=0)) {
269 *p2++ = *p1++; 268 *p2++ = *p1++;
270 } 269 }
271 if (FP_strnicmp(p1,"</a>",4) != 0) 270 if (_FP_strnicmp(p1,"</a>",4) != 0)
272 return 0; 271 return 0;
273 p1+=4; 272 p1+=4;
274 res=1; 273 res=1;
275 } 274 }
276 else 275 else
296UUValidData (char *ptr, int encoding, int *bhflag) 295UUValidData (char *ptr, int encoding, int *bhflag)
297{ 296{
298 int i=0, j, len=0, suspicious=0, flag=0; 297 int i=0, j, len=0, suspicious=0, flag=0;
299 char *s = ptr; 298 char *s = ptr;
300 299
301 if ((s == NULL) || ((schar)*s < '\0')) { 300 if ((s == NULL) || (*s == '\0')) {
302 return(0); /* bad string */ 301 return 0; /* bad string */
303 }
304 302 }
303
305 while (*s && *s!='\012' && *s!='\015') { 304 while (*s && *s!='\012' && *s!='\015') {
306 s++; 305 s++;
307 len++; 306 len++;
308 i++; 307 i++;
309 } 308 }
318 goto _t_XX; 317 goto _t_XX;
319 case B64ENCODED: 318 case B64ENCODED:
320 goto _t_B64; 319 goto _t_B64;
321 case BH_ENCODED: 320 case BH_ENCODED:
322 goto _t_Binhex; 321 goto _t_Binhex;
322 case YENC_ENCODED:
323 return YENC_ENCODED;
323 } 324 }
324 325
325 _t_Binhex: /* Binhex Test */ 326 _t_Binhex: /* Binhex Test */
326 len = i; s = ptr; 327 len = i; s = ptr;
327 328
467 */ 468 */
468 if (encoding != UU_ENCODED) 469 if (encoding != UU_ENCODED)
469 if (strchr (ptr, ' ') != NULL) 470 if (strchr (ptr, ' ') != NULL)
470 goto _t_XX; 471 goto _t_XX;
471 472
472/* suspicious = 1; we're careful here REMOVED 0.4.15 _FP__ */ 473/* suspicious = 1; we're careful here REMOVED 0.4.15 __FP__ */
473 len = j; 474 len = j;
474 } 475 }
475 476
476 while (len--) { 477 while (len--) {
477 if (*s < 0 || UUxlat[ACAST(*s++)] < 0) { 478 if (*s < 0 || UUxlat[ACAST(*s++)] < 0) {
540 while (vflag == 0 && nflag && safety--) { 541 while (vflag == 0 && nflag && safety--) {
541 if (nflag == 1) { /* need next line to repair */ 542 if (nflag == 1) { /* need next line to repair */
542 ptr = line + strlen (line); 543 ptr = line + strlen (line);
543 while (ptr>line && (*(ptr-1)=='\015' || *(ptr-1)=='\012')) 544 while (ptr>line && (*(ptr-1)=='\015' || *(ptr-1)=='\012'))
544 ptr--; 545 ptr--;
545 if (FP_fgets (ptr, 255-(ptr-line), datei) == NULL) 546 if (_FP_fgets (ptr, 255-(ptr-line), datei) == NULL)
546 break; 547 break;
547 } 548 }
548 else { /* don't need next line to repair */ 549 else { /* don't need next line to repair */
549 } 550 }
550 if (UUNetscapeCollapse (line)) { 551 if (UUNetscapeCollapse (line)) {
616 if (method == UU_ENCODED) 617 if (method == UU_ENCODED)
617 table = UUxlat; 618 table = UUxlat;
618 else 619 else
619 table = XXxlat; 620 table = XXxlat;
620 621
621 i = table [(uchar)*s++]; 622 i = table [ACAST(*s++)];
622 j = UUxlen[i] - 1; 623 j = UUxlen[i] - 1;
623 624
624 while(j > 0) { 625 while(j > 0) {
625 c = table[(uchar)*s++] << 2; 626 c = table[ACAST(*s++)] << 2;
626 cc = table[(uchar)*s++]; 627 cc = table[ACAST(*s++)];
627 c |= (cc >> 4); 628 c |= (cc >> 4);
628 629
629 if(i-- > 0) 630 if(i-- > 0)
630 d[count++] = c; 631 d[count++] = c;
631 632
632 cc <<= 4; 633 cc <<= 4;
633 c = table[(uchar)*s++]; 634 c = table[ACAST(*s++)];
634 cc |= (c >> 2); 635 cc |= (c >> 2);
635 636
636 if(i-- > 0) 637 if(i-- > 0)
637 d[count++] = cc; 638 d[count++] = cc;
638 639
639 c <<= 6; 640 c <<= 6;
640 c |= table[(uchar)*s++]; 641 c |= table[ACAST(*s++)];
641 642
642 if(i-- > 0) 643 if(i-- > 0)
643 d[count++] = c; 644 d[count++] = c;
644 645
645 j -= 4; 646 j -= 4;
704 d[count++] = (z2 << 4) | (z3 >> 2); 705 d[count++] = (z2 << 4) | (z3 >> 2);
705 s+=3; 706 s+=3;
706 } 707 }
707 while (BHxlat[ACAST(*s)] != -1) 708 while (BHxlat[ACAST(*s)] != -1)
708 uuncdl_fulline[leftover++] = *s++; 709 uuncdl_fulline[leftover++] = *s++;
710 }
711 else if (method == YENC_ENCODED) {
712 while (*s) {
713 if (*s == '=') {
714 if (*++s != '\0') {
715 d[count++] = (char) ((int) *s - 64 - 42);
716 s++;
717 }
718 }
719 else if (*s == '\t' || *s == '\n' || *s == '\r') {
720 s++; /* ignore */
721 }
722 else {
723 d[count++] = (char) ((int) *s++ - 42);
724 }
725 }
709 } 726 }
710 727
711 return count; 728 return count;
712} 729}
713 730
726 uulboundary = -1; 743 uulboundary = -1;
727 744
728 while (!feof (datain) && 745 while (!feof (datain) &&
729 (ftell(datain)<maxpos || flags&FL_TOEND || 746 (ftell(datain)<maxpos || flags&FL_TOEND ||
730 (!(flags&FL_PROPER) && uu_fast_scanning))) { 747 (!(flags&FL_PROPER) && uu_fast_scanning))) {
731 if (FP_fgets (line, 255, datain) == NULL) 748 if (_FP_fgets (line, 255, datain) == NULL)
732 break; 749 break;
733 if (ferror (datain)) { 750 if (ferror (datain)) {
734 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 751 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
735 uustring (S_SOURCE_READ_ERR), 752 uustring (S_SOURCE_READ_ERR),
736 strerror (uu_errno = errno)); 753 strerror (uu_errno = errno));
823 uulboundary = -1; 840 uulboundary = -1;
824 841
825 while (!feof (datain) && 842 while (!feof (datain) &&
826 (ftell(datain)<maxpos || flags&FL_TOEND || 843 (ftell(datain)<maxpos || flags&FL_TOEND ||
827 (!(flags&FL_PROPER) && uu_fast_scanning))) { 844 (!(flags&FL_PROPER) && uu_fast_scanning))) {
828 if (FP_fgets (line, 255, datain) == NULL) 845 if (_FP_fgets (line, 255, datain) == NULL)
829 break; 846 break;
830 if (ferror (datain)) { 847 if (ferror (datain)) {
831 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 848 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
832 uustring (S_SOURCE_READ_ERR), 849 uustring (S_SOURCE_READ_ERR),
833 strerror (uu_errno = errno)); 850 strerror (uu_errno = errno));
882 char *boundary) 899 char *boundary)
883{ 900{
884 char *line=uugen_fnbuffer, *oline=uuncdp_oline; 901 char *line=uugen_fnbuffer, *oline=uuncdp_oline;
885 int warning=0, vlc=0, lc[2], hadct=0; 902 int warning=0, vlc=0, lc[2], hadct=0;
886 int tc=0, tf=0, vflag, haddata=0, haddh=0; 903 int tc=0, tf=0, vflag, haddata=0, haddh=0;
904 long yefilesize=0, yepartends=0;
887 static int bhflag=0; 905 static int bhflag=0;
888 size_t count=0; 906 size_t count=0;
907 char *ptr;
889 908
890 if (datain == NULL || dataout == NULL) { 909 if (datain == NULL || dataout == NULL) {
891 bhflag = 0; 910 bhflag = 0;
892 return UURET_OK; 911 return UURET_OK;
893 } 912 }
906 lc[0] = lc[1] = 0; 925 lc[0] = lc[1] = 0;
907 vflag = 0; 926 vflag = 0;
908 927
909 uulboundary = -1; 928 uulboundary = -1;
910 929
930 if (method == YENC_ENCODED) {
931 *state = BEGIN;
932 }
933
911 while (!feof (datain) && *state != DONE && 934 while (!feof (datain) && *state != DONE &&
912 (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 || 935 (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 ||
913 (!(flags&FL_PROPER) && uu_fast_scanning))) { 936 (!(flags&FL_PROPER) && uu_fast_scanning))) {
914 if (FP_fgets (line, 255, datain) == NULL) 937 if (_FP_fgets (line, 299, datain) == NULL)
915 break; 938 break;
939
916 if (ferror (datain)) { 940 if (ferror (datain)) {
917 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 941 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
918 uustring (S_SOURCE_READ_ERR), 942 uustring (S_SOURCE_READ_ERR),
919 strerror (uu_errno = errno)); 943 strerror (uu_errno = errno));
920 return UURET_IOERR; 944 return UURET_IOERR;
921 } 945 }
946
922 if (line[0]=='\015' || line[0]=='\012') { /* Empty line? */ 947 if (line[0]=='\015' || line[0]=='\012') { /* Empty line? */
923 if (*state == DATA && 948 if (*state == DATA &&
924 (method == UU_ENCODED || method == XX_ENCODED)) 949 (method == UU_ENCODED || method == XX_ENCODED))
925 *state = END; 950 *state = END;
951
926 /* 952 /*
927 * if we had a whole block of valid lines before, we reset our 953 * 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 954 * 'valid data' flag, tf. Without this 'if', we'd break decoding
929 * files with interleaved blank lines. The value of 5 is chosen 955 * files with interleaved blank lines. The value of 5 is chosen
930 * quite arbitrarly. 956 * quite arbitrarly.
931 */ 957 */
958
932 if (vlc > 5) 959 if (vlc > 5)
933 tf = tc = 0; 960 tf = tc = 0;
934 vlc = 0; 961 vlc = 0;
935 continue; 962 continue;
936 } 963 }
947 974
948 /* 975 /*
949 * try to make sense of data 976 * try to make sense of data
950 */ 977 */
951 978
952 line[255] = '\0'; /* For Safety of string functions */ 979 line[299] = '\0'; /* For Safety of string functions */
953 count = 0; 980 count = 0;
954 981
955 if (boundary && line[0]=='-' && line[1]=='-' && 982 if (boundary && line[0]=='-' && line[1]=='-' &&
956 strncmp (line+2, boundary, strlen (boundary)) == 0) { 983 strncmp (line+2, boundary, strlen (boundary)) == 0) {
957 if (line[strlen(boundary)+2]=='-') 984 if (line[strlen(boundary)+2]=='-')
965 * Use this pseudo-handling only if !FL_PROPER 992 * Use this pseudo-handling only if !FL_PROPER
966 */ 993 */
967 994
968 if ((flags&FL_PROPER) == 0) { 995 if ((flags&FL_PROPER) == 0) {
969 if (strncmp (line, "BEGIN", 5) == 0 && 996 if (strncmp (line, "BEGIN", 5) == 0 &&
970 FP_strstr (line, "CUT HERE") && !tf) { /* I hate these lines */ 997 _FP_strstr (line, "CUT HERE") && !tf) { /* I hate these lines */
971 tc = tf = vlc = 0; 998 tc = tf = vlc = 0;
972 continue; 999 continue;
973 } 1000 }
974 /* MIME body boundary */ 1001 /* MIME body boundary */
975 if (line[0] == '-' && line[1] == '-' && method == B64ENCODED) { 1002 if (line[0] == '-' && line[1] == '-' && method == B64ENCODED) {
981 } 1008 }
982 hadct = 0; 1009 hadct = 0;
983 haddh = 1; 1010 haddh = 1;
984 continue; 1011 continue;
985 } 1012 }
986 if (FP_strnicmp (line, "Content-Type", 12) == 0) 1013 if (_FP_strnicmp (line, "Content-Type", 12) == 0)
987 hadct = 1; 1014 hadct = 1;
988 } 1015 }
989 1016
990 if (*state == BEGIN) { 1017 if (*state == BEGIN) {
1018 if ((method == UU_ENCODED || method == XX_ENCODED) &&
991 if (strncmp (line, "begin ", 6) == 0 || 1019 (strncmp (line, "begin ", 6) == 0 ||
992 FP_strnicmp (line, "<pre>begin ", 11) == 0) { /* for LYNX */ 1020 _FP_strnicmp (line, "<pre>begin ", 11) == 0)) { /* for LYNX */
993 *state = DATA; 1021 *state = DATA;
994 continue; 1022 continue;
995 } 1023 }
996 else if (method == BH_ENCODED && line[0] == ':') { 1024 else if (method == BH_ENCODED && line[0] == ':') {
997 if (UUValidData (line, BH_ENCODED, &bhflag) == BH_ENCODED) { 1025 if (UUValidData (line, BH_ENCODED, &bhflag) == BH_ENCODED) {
999 *state = DATA; 1027 *state = DATA;
1000 } 1028 }
1001 else 1029 else
1002 continue; 1030 continue;
1003 } 1031 }
1004 else 1032 else if (method == YENC_ENCODED &&
1033 strncmp (line, "=ybegin ", 8) == 0 &&
1034 _FP_strstr (line, " size=") != NULL &&
1035 _FP_strstr (line, " name=") != NULL) {
1036 *state = DATA;
1037
1038 ptr = _FP_strstr (line, " size=") + 6;
1039 yefilesize = atoi (ptr);
1040
1041 if (_FP_strstr (line, " part=") != NULL) {
1042 if (_FP_fgets (line, 299, datain) == NULL) {
1043 break;
1044 }
1045
1046 if ((ptr = _FP_strstr (line, " end=")) == NULL) {
1047 break;
1048 }
1049
1050 yepartends = atoi (ptr + 5);
1051 }
1052 tf = 1;
1005 continue; 1053 continue;
1054 }
1055 else {
1056 continue;
1057 }
1006 1058
1007 tc = tf = vlc = 0; 1059 tc = tf = vlc = 0;
1008 lc[0] = lc[1] = 0; 1060 lc[0] = lc[1] = 0;
1009 } 1061 }
1010 else if ((*state == END) && 1062 else if ((*state == END) &&
1012 if (strncmp (line, "end", 3) == 0) { 1064 if (strncmp (line, "end", 3) == 0) {
1013 *state = DONE; 1065 *state = DONE;
1014 break; 1066 break;
1015 } 1067 }
1016 } 1068 }
1069
1070 if (*state == DATA && method == YENC_ENCODED &&
1071 strncmp (line, "=yend ", 6) == 0) {
1072 if (yepartends == 0 || yepartends >= yefilesize) {
1073 *state = DONE;
1074 }
1075 break;
1076 }
1077
1017 if (*state == DATA || *state == END) { 1078 if (*state == DATA || *state == END) {
1018 if (method==B64ENCODED && line[0]=='-' && line[1]=='-' && tc) { 1079 if (method==B64ENCODED && line[0]=='-' && line[1]=='-' && tc) {
1019 break; 1080 break;
1020 } 1081 }
1021 1082
1058 } 1119 }
1059 lc[0] = 0; 1120 lc[0] = 0;
1060 lc[1] = 3; 1121 lc[1] = 3;
1061 } 1122 }
1062 else { 1123 else {
1063 FP_strncpy (save[tc++], line, 256); 1124 _FP_strncpy (save[tc++], line, 256);
1064 } 1125 }
1126
1065 if (method == UU_ENCODED) 1127 if (method == UU_ENCODED)
1066 *state = (line[0] == 'M') ? DATA : END; 1128 *state = (line[0] == 'M') ? DATA : END;
1067 else if (method == XX_ENCODED) 1129 else if (method == XX_ENCODED)
1068 *state = (line[0] == 'h') ? DATA : END; 1130 *state = (line[0] == 'h') ? DATA : END;
1069 else if (method == B64ENCODED) 1131 else if (method == B64ENCODED)
1078 } 1140 }
1079 } 1141 }
1080 else if (*state != DONE) { 1142 else if (*state != DONE) {
1081 return UURET_NOEND; 1143 return UURET_NOEND;
1082 } 1144 }
1145
1083 if (count) { 1146 if (count) {
1084 if (method == BH_ENCODED) { 1147 if (method == BH_ENCODED) {
1085 if (UUbhwrite (oline, 1, count, dataout) != count) { 1148 if (UUbhwrite (oline, 1, count, dataout) != count) {
1086 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 1149 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1087 uustring (S_WR_ERR_TEMP), 1150 uustring (S_WR_ERR_TEMP),
1137 FILE *datain, *dataout; 1200 FILE *datain, *dataout;
1138 unsigned char r[8]; 1201 unsigned char r[8];
1139 char *mode, *ntmp; 1202 char *mode, *ntmp;
1140 uufile *iter; 1203 uufile *iter;
1141 size_t bytes; 1204 size_t bytes;
1142#ifdef HAVE_MKSTEMP
1143 int tmpfd;
1144 const char *tmpprefix = "uuXXXXXX";
1145 char *tmpdir = NULL;
1146#endif /* HAVE_MKSTEMP */
1147 1205
1148 if (data == NULL || data->thisfile == NULL) 1206 if (data == NULL || data->thisfile == NULL)
1149 return UURET_ILLVAL; 1207 return UURET_ILLVAL;
1150 1208
1151 if (data->state & UUFILE_TMPFILE) 1209 if (data->state & UUFILE_TMPFILE)
1160 if (data->uudet == PT_ENCODED) 1218 if (data->uudet == PT_ENCODED)
1161 mode = "wt"; /* open text files in text mode */ 1219 mode = "wt"; /* open text files in text mode */
1162 else 1220 else
1163 mode = "wb"; /* otherwise in binary */ 1221 mode = "wb"; /* otherwise in binary */
1164 1222
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) { 1223 if ((data->binfile = tempnam (NULL, "uu")) == NULL) {
1178#endif /* HAVE_MKSTEMP */
1179 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 1224 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1180 uustring (S_NO_TEMP_NAME)); 1225 uustring (S_NO_TEMP_NAME));
1181 return UURET_NOMEM; 1226 return UURET_NOMEM;
1182 } 1227 }
1183 1228
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) { 1229 if ((dataout = fopen (data->binfile, mode)) == NULL) {
1193#endif /* HAVE_MKSTEMP */
1194 /* 1230 /*
1195 * we couldn't create a temporary file. Usually this means that TMP 1231 * we couldn't create a temporary file. Usually this means that TMP
1196 * and TEMP aren't set 1232 * and TEMP aren't set
1197 */ 1233 */
1198 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 1234 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1199 uustring (S_WR_ERR_TARGET), 1235 uustring (S_WR_ERR_TARGET),
1200 data->binfile, strerror (uu_errno = errno)); 1236 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); 1237 _FP_free (data->binfile);
1208 data->binfile = NULL; 1238 data->binfile = NULL;
1209 uu_errno = errno; 1239 uu_errno = errno;
1210 return UURET_IOERR; 1240 return UURET_IOERR;
1211 } 1241 }
1212
1213 /* 1242 /*
1214 * we don't have begin lines in Base64 or plain text files. 1243 * we don't have begin lines in Base64 or plain text files.
1215 */ 1244 */
1216 if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED || 1245 if (data->uudet == B64ENCODED || data->uudet == QP_ENCODED ||
1217 data->uudet == PT_ENCODED) 1246 data->uudet == PT_ENCODED)
1232 /* 1261 /*
1233 * initialize progress information 1262 * initialize progress information
1234 */ 1263 */
1235 progress.action = 0; 1264 progress.action = 0;
1236 if (data->filename != NULL) { 1265 if (data->filename != NULL) {
1237 FP_strncpy (progress.curfile, 1266 _FP_strncpy (progress.curfile,
1238 (strlen(data->filename)>255)? 1267 (strlen(data->filename)>255)?
1239 (data->filename+strlen(data->filename)-255):data->filename, 1268 (data->filename+strlen(data->filename)-255):data->filename,
1240 256); 1269 256);
1241 } 1270 }
1242 else { 1271 else {
1243 FP_strncpy (progress.curfile, 1272 _FP_strncpy (progress.curfile,
1244 (strlen(data->binfile)>255)? 1273 (strlen(data->binfile)>255)?
1245 (data->binfile+strlen(data->binfile)-255):data->binfile, 1274 (data->binfile+strlen(data->binfile)-255):data->binfile,
1246 256); 1275 256);
1247 } 1276 }
1248 progress.partno = 0; 1277 progress.partno = 0;
1297 uustring (S_NOT_OPEN_FILE), 1326 uustring (S_NOT_OPEN_FILE),
1298 iter->data->sfname, strerror (uu_errno = errno)); 1327 iter->data->sfname, strerror (uu_errno = errno));
1299 res = UURET_IOERR; 1328 res = UURET_IOERR;
1300 break; 1329 break;
1301 } 1330 }
1302 FP_strncpy (uugen_fnbuffer, iter->data->sfname, 1024); 1331 _FP_strncpy (uugen_fnbuffer, iter->data->sfname, 1024);
1303 } 1332 }
1304 1333
1305 progress.partno = part; 1334 progress.partno = part;
1306 progress.fsize = (iter->data->length)?iter->data->length:-1; 1335 progress.fsize = (iter->data->length)?iter->data->length:-1;
1307 progress.percent = 0; 1336 progress.percent = 0;
1329 1358
1330 fclose (dataout); 1359 fclose (dataout);
1331 1360
1332 if (res != UURET_OK || (state != DONE && !uu_desperate)) { 1361 if (res != UURET_OK || (state != DONE && !uu_desperate)) {
1333 unlink (data->binfile); 1362 unlink (data->binfile);
1334 FP_free (data->binfile); 1363 _FP_free (data->binfile);
1335 data->binfile = NULL; 1364 data->binfile = NULL;
1336 data->state &= ~UUFILE_TMPFILE; 1365 data->state &= ~UUFILE_TMPFILE;
1337 data->state |= UUFILE_ERROR; 1366 data->state |= UUFILE_ERROR;
1338 1367
1339 if (res == UURET_OK && state != DONE) 1368 if (res == UURET_OK && state != DONE)
1351 /* 1380 /*
1352 * If this was a BinHex file, we must extract its data or resource fork 1381 * If this was a BinHex file, we must extract its data or resource fork
1353 */ 1382 */
1354 1383
1355 if (data->uudet == BH_ENCODED && data->binfile) { 1384 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) { 1385 if ((ntmp = tempnam (NULL, "uu")) == NULL) {
1362#endif /* HAVE_MKSTEMP */
1363 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 1386 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1364 uustring (S_NO_TEMP_NAME)); 1387 uustring (S_NO_TEMP_NAME));
1365 progress.action = 0; 1388 progress.action = 0;
1366 return UURET_NOMEM; 1389 return UURET_NOMEM;
1367 } 1390 }
1371 data->binfile, strerror (uu_errno = errno)); 1394 data->binfile, strerror (uu_errno = errno));
1372 progress.action = 0; 1395 progress.action = 0;
1373 free (ntmp); 1396 free (ntmp);
1374 return UURET_IOERR; 1397 return UURET_IOERR;
1375 } 1398 }
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) { 1399 if ((dataout = fopen (ntmp, "wb")) == NULL) {
1384#endif /* HAVE_MKSTEMP */
1385 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 1400 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1386 uustring (S_NOT_OPEN_TARGET), 1401 uustring (S_NOT_OPEN_TARGET),
1387 ntmp, strerror (uu_errno = errno)); 1402 ntmp, strerror (uu_errno = errno));
1388 progress.action = 0; 1403 progress.action = 0;
1389 fclose (datain); 1404 fclose (datain);
1390#ifdef HAVE_MKSTEMP
1391 if (tmpfd != -1) {
1392 unlink(ntmp);
1393 close(tmpfd);
1394 }
1395#endif /* HAVE_MKSTEMP */
1396 free (ntmp); 1405 free (ntmp);
1397 return UURET_IOERR; 1406 return UURET_IOERR;
1398 } 1407 }
1399
1400 /* 1408 /*
1401 * read fork lengths. remember they're in Motorola format 1409 * read fork lengths. remember they're in Motorola format
1402 */ 1410 */
1403 r[0] = fgetc (datain); 1411 r[0] = fgetc (datain);
1404 hb = (int) r[0] + 22; 1412 hb = (int) r[0] + 22;
1530 */ 1538 */
1531 1539
1532 memset (&myenv, 0, sizeof (headers)); 1540 memset (&myenv, 0, sizeof (headers));
1533 UUScanHeader (datain, &myenv); 1541 UUScanHeader (datain, &myenv);
1534 1542
1535 if (FP_stristr (myenv.ctenc, "uu") != NULL) 1543 if (_FP_stristr (myenv.ctenc, "uu") != NULL)
1536 encoding = UU_ENCODED; 1544 encoding = UU_ENCODED;
1537 else if (FP_stristr (myenv.ctenc, "xx") != NULL) 1545 else if (_FP_stristr (myenv.ctenc, "xx") != NULL)
1538 encoding = XX_ENCODED; 1546 encoding = XX_ENCODED;
1539 else if (FP_stricmp (myenv.ctenc, "base64") == 0) 1547 else if (_FP_stricmp (myenv.ctenc, "base64") == 0)
1540 encoding = B64ENCODED; 1548 encoding = B64ENCODED;
1541 else if (FP_stricmp (myenv.ctenc, "quoted-printable") == 0) 1549 else if (_FP_stricmp (myenv.ctenc, "quoted-printable") == 0)
1542 encoding = QP_ENCODED; 1550 encoding = QP_ENCODED;
1543 else 1551 else
1544 encoding = PT_ENCODED; 1552 encoding = PT_ENCODED;
1545 1553
1546 UUkillheaders (&myenv); 1554 UUkillheaders (&myenv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines