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.4 by root, Sun Mar 31 20:04:30 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.4 2002/03/31 20:04:30 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
296UUValidData (char *ptr, int encoding, int *bhflag) 296UUValidData (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
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 == '\t' || *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
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;
887 static int bhflag=0; 906 static int bhflag=0;
888 size_t count=0; 907 size_t count=0;
908 char *ptr;
889 909
890 if (datain == NULL || dataout == NULL) { 910 if (datain == NULL || dataout == NULL) {
891 bhflag = 0; 911 bhflag = 0;
892 return UURET_OK; 912 return UURET_OK;
893 } 913 }
906 lc[0] = lc[1] = 0; 926 lc[0] = lc[1] = 0;
907 vflag = 0; 927 vflag = 0;
908 928
909 uulboundary = -1; 929 uulboundary = -1;
910 930
931 if (method == YENC_ENCODED) {
932 *state = BEGIN;
933 }
934
911 while (!feof (datain) && *state != DONE && 935 while (!feof (datain) && *state != DONE &&
912 (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 || 936 (ftell(datain)<maxpos || flags&FL_TOEND || maxpos==-1 ||
913 (!(flags&FL_PROPER) && uu_fast_scanning))) { 937 (!(flags&FL_PROPER) && uu_fast_scanning))) {
914 if (FP_fgets (line, 255, datain) == NULL) 938 if (FP_fgets (line, 299, datain) == NULL)
915 break; 939 break;
940
916 if (ferror (datain)) { 941 if (ferror (datain)) {
917 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 942 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
918 uustring (S_SOURCE_READ_ERR), 943 uustring (S_SOURCE_READ_ERR),
919 strerror (uu_errno = errno)); 944 strerror (uu_errno = errno));
920 return UURET_IOERR; 945 return UURET_IOERR;
921 } 946 }
947
922 if (line[0]=='\015' || line[0]=='\012') { /* Empty line? */ 948 if (line[0]=='\015' || line[0]=='\012') { /* Empty line? */
923 if (*state == DATA && 949 if (*state == DATA &&
924 (method == UU_ENCODED || method == XX_ENCODED)) 950 (method == UU_ENCODED || method == XX_ENCODED))
925 *state = END; 951 *state = END;
952
926 /* 953 /*
927 * if we had a whole block of valid lines before, we reset our 954 * 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 955 * 'valid data' flag, tf. Without this 'if', we'd break decoding
929 * files with interleaved blank lines. The value of 5 is chosen 956 * files with interleaved blank lines. The value of 5 is chosen
930 * quite arbitrarly. 957 * quite arbitrarly.
931 */ 958 */
959
932 if (vlc > 5) 960 if (vlc > 5)
933 tf = tc = 0; 961 tf = tc = 0;
934 vlc = 0; 962 vlc = 0;
935 continue; 963 continue;
936 } 964 }
947 975
948 /* 976 /*
949 * try to make sense of data 977 * try to make sense of data
950 */ 978 */
951 979
952 line[255] = '\0'; /* For Safety of string functions */ 980 line[299] = '\0'; /* For Safety of string functions */
953 count = 0; 981 count = 0;
954 982
955 if (boundary && line[0]=='-' && line[1]=='-' && 983 if (boundary && line[0]=='-' && line[1]=='-' &&
956 strncmp (line+2, boundary, strlen (boundary)) == 0) { 984 strncmp (line+2, boundary, strlen (boundary)) == 0) {
957 if (line[strlen(boundary)+2]=='-') 985 if (line[strlen(boundary)+2]=='-')
986 if (FP_strnicmp (line, "Content-Type", 12) == 0) 1014 if (FP_strnicmp (line, "Content-Type", 12) == 0)
987 hadct = 1; 1015 hadct = 1;
988 } 1016 }
989 1017
990 if (*state == BEGIN) { 1018 if (*state == BEGIN) {
1019 if ((method == UU_ENCODED || method == XX_ENCODED) &&
991 if (strncmp (line, "begin ", 6) == 0 || 1020 (strncmp (line, "begin ", 6) == 0 ||
992 FP_strnicmp (line, "<pre>begin ", 11) == 0) { /* for LYNX */ 1021 FP_strnicmp (line, "<pre>begin ", 11) == 0)) { /* for LYNX */
993 *state = DATA; 1022 *state = DATA;
994 continue; 1023 continue;
995 } 1024 }
996 else if (method == BH_ENCODED && line[0] == ':') { 1025 else if (method == BH_ENCODED && line[0] == ':') {
997 if (UUValidData (line, BH_ENCODED, &bhflag) == BH_ENCODED) { 1026 if (UUValidData (line, BH_ENCODED, &bhflag) == BH_ENCODED) {
999 *state = DATA; 1028 *state = DATA;
1000 } 1029 }
1001 else 1030 else
1002 continue; 1031 continue;
1003 } 1032 }
1004 else 1033 else if (method == YENC_ENCODED &&
1034 strncmp (line, "=ybegin ", 8) == 0 &&
1035 FP_strstr (line, " size=") != NULL &&
1036 FP_strstr (line, " name=") != NULL) {
1037 *state = DATA;
1038
1039 ptr = FP_strstr (line, " size=") + 6;
1040 yefilesize = atoi (ptr);
1041
1042 if (FP_strstr (line, " part=") != NULL) {
1043 if (FP_fgets (line, 299, datain) == NULL) {
1044 break;
1045 }
1046
1047 if ((ptr = FP_strstr (line, " end=")) == NULL) {
1048 break;
1049 }
1050
1051 yepartends = atoi (ptr + 5);
1052 }
1053 tf = 1;
1005 continue; 1054 continue;
1055 }
1056 else {
1057 continue;
1058 }
1006 1059
1007 tc = tf = vlc = 0; 1060 tc = tf = vlc = 0;
1008 lc[0] = lc[1] = 0; 1061 lc[0] = lc[1] = 0;
1009 } 1062 }
1010 else if ((*state == END) && 1063 else if ((*state == END) &&
1012 if (strncmp (line, "end", 3) == 0) { 1065 if (strncmp (line, "end", 3) == 0) {
1013 *state = DONE; 1066 *state = DONE;
1014 break; 1067 break;
1015 } 1068 }
1016 } 1069 }
1070
1071 if (*state == DATA && method == YENC_ENCODED &&
1072 strncmp (line, "=yend ", 6) == 0) {
1073 if (yepartends == 0 || yepartends >= yefilesize) {
1074 *state = DONE;
1075 }
1076 break;
1077 }
1078
1017 if (*state == DATA || *state == END) { 1079 if (*state == DATA || *state == END) {
1018 if (method==B64ENCODED && line[0]=='-' && line[1]=='-' && tc) { 1080 if (method==B64ENCODED && line[0]=='-' && line[1]=='-' && tc) {
1019 break; 1081 break;
1020 } 1082 }
1021 1083
1060 lc[1] = 3; 1122 lc[1] = 3;
1061 } 1123 }
1062 else { 1124 else {
1063 FP_strncpy (save[tc++], line, 256); 1125 FP_strncpy (save[tc++], line, 256);
1064 } 1126 }
1127
1065 if (method == UU_ENCODED) 1128 if (method == UU_ENCODED)
1066 *state = (line[0] == 'M') ? DATA : END; 1129 *state = (line[0] == 'M') ? DATA : END;
1067 else if (method == XX_ENCODED) 1130 else if (method == XX_ENCODED)
1068 *state = (line[0] == 'h') ? DATA : END; 1131 *state = (line[0] == 'h') ? DATA : END;
1069 else if (method == B64ENCODED) 1132 else if (method == B64ENCODED)
1078 } 1141 }
1079 } 1142 }
1080 else if (*state != DONE) { 1143 else if (*state != DONE) {
1081 return UURET_NOEND; 1144 return UURET_NOEND;
1082 } 1145 }
1146
1083 if (count) { 1147 if (count) {
1084 if (method == BH_ENCODED) { 1148 if (method == BH_ENCODED) {
1085 if (UUbhwrite (oline, 1, count, dataout) != count) { 1149 if (UUbhwrite (oline, 1, count, dataout) != count) {
1086 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR, 1150 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1087 uustring (S_WR_ERR_TEMP), 1151 uustring (S_WR_ERR_TEMP),

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines