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.2.3 by root, Sun Oct 13 13:03:08 2002 UTC vs.
Revision 1.3.2.4 by root, Thu Nov 6 13:08:24 2003 UTC

53#include <uudeview.h> 53#include <uudeview.h>
54#include <uuint.h> 54#include <uuint.h>
55#include <fptools.h> 55#include <fptools.h>
56#include <uustring.h> 56#include <uustring.h>
57 57
58char * uunconc_id = "$Id: uunconc.c,v 1.3.2.3 2002/10/13 13:03:08 root Exp $"; 58char * uunconc_id = "$Id: uunconc.c,v 1.3.2.4 2003/11/06 13:08:24 root Exp $";
59 59
60/* for braindead systems */ 60/* for braindead systems */
61#ifndef SEEK_SET 61#ifndef SEEK_SET
62#ifdef L_BEGIN 62#ifdef L_BEGIN
63#define SEEK_SET L_BEGIN 63#define SEEK_SET L_BEGIN
539 539
540 nflag = UUBrokenByNetscape (line); 540 nflag = UUBrokenByNetscape (line);
541 541
542 while (vflag == 0 && nflag && safety--) { 542 while (vflag == 0 && nflag && safety--) {
543 if (nflag == 1) { /* need next line to repair */ 543 if (nflag == 1) { /* need next line to repair */
544 if (strlen (line) > 250)
545 break;
544 ptr = line + strlen (line); 546 ptr = line + strlen (line);
545 while (ptr>line && (*(ptr-1)=='\015' || *(ptr-1)=='\012')) 547 while (ptr>line && (*(ptr-1)=='\015' || *(ptr-1)=='\012'))
546 ptr--; 548 ptr--;
547 if (_FP_fgets (ptr, 255-(ptr-line), datei) == NULL) 549 if (_FP_fgets (ptr, 255-(ptr-line), datei) == NULL)
548 break; 550 break;
892 } 894 }
893 } 895 }
894 return UURET_OK; 896 return UURET_OK;
895} 897}
896 898
899/*
900 * Decode a single field using method. For the moment, this supports
901 * Base64 and Quoted Printable only, to support RFC 1522 header decoding.
902 * Quit when seeing the RFC 1522 ?= end marker.
903 */
904
905int
906UUDecodeField (char *s, char *d, int method)
907{
908 int z1, z2, z3, z4;
909 int count=0;
910
911 if (method == B64ENCODED) {
912 while ((z1 = B64xlat[ACAST(*s)]) != -1) {
913 if ((z2 = B64xlat[ACAST(*(s+1))]) == -1) break;
914 if ((z3 = B64xlat[ACAST(*(s+2))]) == -1) break;
915 if ((z4 = B64xlat[ACAST(*(s+3))]) == -1) break;
916
917 d[count++] = (z1 << 2) | (z2 >> 4);
918 d[count++] = (z2 << 4) | (z3 >> 2);
919 d[count++] = (z3 << 6) | (z4);
920
921 s+=4;
922 }
923 if (z1 != -1 && z2 != -1 && *(s+2) == '=') {
924 d[count++] = (z1 << 2) | (z2 >> 4);
925 s+=2;
926 }
927 else if (z1 != -1 && z2 != -1 && z3 != -1 && *(s+3) == '=') {
928 d[count++] = (z1 << 2) | (z2 >> 4);
929 d[count++] = (z2 << 4) | (z3 >> 2);
930 s+=3;
931 }
932 }
933 else if (method == QP_ENCODED) {
934 while (*s && (*s != '?' || *(s+1) != '=')) {
935 while (*s && *s != '=' && (*s != '?' || *(s+1) != '=')) {
936 d[count++] = *s++;
937 }
938 if (*s == '=') {
939 if (isxdigit (*(s+1)) && isxdigit (*(s+2))) {
940 d[count] = (isdigit (*(s+1)) ? (*(s+1)-'0') : (tolower (*(s+1))-'a'+10)) << 4;
941 d[count] |= (isdigit (*(s+2)) ? (*(s+2)-'0') : (tolower (*(s+2))-'a'+10));
942 count++;
943 s+=3;
944 }
945 else if (*(s+1) == '\012' || *(s+1) == '\015') {
946 s+=2;
947 }
948 else {
949 d[count++] = *s++;
950 }
951 }
952 }
953 }
954 else {
955 return -1;
956 }
957
958 d[count] = '\0';
959 return count;
960}
961
897int 962int
898UUDecodePart (FILE *datain, FILE *dataout, int *state, 963UUDecodePart (FILE *datain, FILE *dataout, int *state,
899 long maxpos, int method, int flags, 964 long maxpos, int method, int flags,
900 char *boundary) 965 char *boundary)
901{ 966{
1334 * let's rock! 1399 * let's rock!
1335 */ 1400 */
1336 1401
1337 iter = data->thisfile; 1402 iter = data->thisfile;
1338 while (iter) { 1403 while (iter) {
1339 if (part != -1 && iter->partno != part+1) 1404 if (part != -1 && iter->partno != part+1 && !uu_desperate)
1340 break; 1405 break;
1341 else 1406 else
1342 part = iter->partno; 1407 part = iter->partno;
1343 1408
1344 if (iter->data->sfname == NULL) { 1409 if (iter->data->sfname == NULL) {
1398 if (state == DATA && 1463 if (state == DATA &&
1399 (data->uudet == B64ENCODED || data->uudet == QP_ENCODED || 1464 (data->uudet == B64ENCODED || data->uudet == QP_ENCODED ||
1400 data->uudet == PT_ENCODED)) 1465 data->uudet == PT_ENCODED))
1401 state = DONE; /* assume we're done */ 1466 state = DONE; /* assume we're done */
1402 1467
1403 fclose (dataout); 1468 if (fclose (dataout)) {
1469 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1470 uustring (S_WR_ERR_TEMP),
1471 strerror (uu_errno = errno));
1472 res = UURET_IOERR;
1473 }
1404 1474
1405 if (res != UURET_OK || (state != DONE && !uu_desperate)) { 1475 if (res != UURET_OK || (state != DONE && !uu_desperate)) {
1406 unlink (data->binfile); 1476 unlink (data->binfile);
1407 _FP_free (data->binfile); 1477 _FP_free (data->binfile);
1408 data->binfile = NULL; 1478 data->binfile = NULL;
1548 /* 1618 /*
1549 * replace temp file 1619 * replace temp file
1550 */ 1620 */
1551 1621
1552 fclose (datain); 1622 fclose (datain);
1553 fclose (dataout); 1623 if (fclose (dataout)) {
1624 UUMessage (uunconc_id, __LINE__, UUMSG_ERROR,
1625 uustring (S_WR_ERR_TARGET),
1626 ntmp, strerror (uu_errno = errno));
1627 unlink (ntmp);
1628 free (ntmp);
1629 return UURET_IOERR;
1630 }
1554 1631
1555 if (unlink (data->binfile)) { 1632 if (unlink (data->binfile)) {
1556 UUMessage (uunconc_id, __LINE__, UUMSG_WARNING, 1633 UUMessage (uunconc_id, __LINE__, UUMSG_WARNING,
1557 uustring (S_TMP_NOT_REMOVED), 1634 uustring (S_TMP_NOT_REMOVED),
1558 data->binfile, strerror (uu_errno = errno)); 1635 data->binfile, strerror (uu_errno = errno));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines