📄 ckcfn3.c
字号:
static char *reason[] = { "size", "type", "date", "creator", "account", "area", "password", "blocksize", "access", "encoding", "disposition", "protection", "protection", "origin", "format", "sys-dependent", /* 0 */ "size", /* 1 */ "2", /* 2 */ "3", /* 3 */ "4", /* 4 */ "5", /* 5 */ "6", /* 6 */ "7", /* 7 */ "8", /* 8 */ "9", /* 9 */ ":", /* : */ ";", /* ; */ "<", /* < */ "=", /* = */ ">", /* > */ "name", /* ? */ "@"};static int nreason = sizeof(reason) / sizeof(char *);int rejection = -1;char *getreason(s) char *s; { /* Decode attribute refusal reason */ char c, *p; if (rejection == 1) /* Kludge for SET FIL COLL DISCARD */ return("name"); /* when other Kermit doesn't... */ p = s; if (*p++ != 'N') return(""); /* Should start with N */ else if ((c = *p) > SP) { /* get reason, */ rejection = c; /* remember it, */ c -= '!'; /* get offset */ p = ((unsigned int) ((CHAR) c) <= (unsigned int) nreason) ? reason[c] : "unknown"; } return(p);}intrsattr(s) CHAR *s; { /* Read response to attribute packet */ debug(F111,"rsattr",s,*s); if (*s == 'N') { /* If it's 'N' followed by anything, */ refused = getreason((char *)s); /* they are refusing, get reason. */ debug(F110,"rsattr refused",refused,0); tlog(F110," refused:",refused,0L); return(-1); }#ifdef CK_RESEND if (sendmode == SM_RESEND && *s == '1') { /* RESEND length */ int n; long z; CHAR *p; p = s + 1; n = xunchar(*p++); debug(F101,"rsattr RESEND n","",n); z = 0L; while (n-- > 0) /* We assume the format is good. */ z = 10L * z + (long) (*p++ - '0'); debug(F101,"rsattr RESEND z","",z); if (z > 0L) sendstart = z; debug(F101,"rsattr RESEND sendstart","",sendstart); if (sendstart > 0L) if (zfseek(sendstart) < 0) /* Input file is already open. */ return(0);#ifdef CK_CURSES if (fdispla == XYFD_C) xxscreen(SCR_FS,0,fsize,""); /* Refresh file transfer display */#endif /* CK_CURSES */ }#endif /* CK_RESEND */ refused = ""; return(0);}long rs_len = 0L; /* Length of file being resent to *//* Get attributes from incoming A packet. Returns: 0 on success, file is to be accepted -1 on failure, file is to be refused*/intgattr(s, yy) CHAR *s; struct zattr *yy; { /* Read incoming attribute packet */ char c, d; char *ff; int aln, i;#ifndef NOCSETS extern int r_cset, axcset[];#endif /* NOCSETS */#define ABUFL 40 /* Temporary buffer for conversions */ char abuf[ABUFL+1];#define RFBUFL 10 /* Record-format buffer */ static char rfbuf[RFBUFL+1];#define FTBUFL 10 /* File type buffer */ static char ftbuf[FTBUFL+1];#define DTBUFL 40 /* File creation date */ static char dtbuf[DTBUFL+1];#define TSBUFL 10 /* Transfer syntax */ static char tsbuf[TSBUFL+1];#define IDBUFL 10 /* System ID */ static char idbuf[IDBUFL+1];#ifndef DYNAMIC#define DSBUFL 100 /* Disposition */ static char dsbuf[DSBUFL+1];#define SPBUFL 512 /* System-dependent parameters */ static char spbuf[SPBUFL+1];#else#define DSBUFL 100 /* Disposition */ static char *dsbuf = NULL;#define SPBUFL 512 /* System-dependent parameters */ static char *spbuf = NULL;#endif /* DYNAMIC */#define RPBUFL 20 /* Attribute reply */ static char rpbuf[RPBUFL+1];#ifdef CK_PERMS static char lprmbuf[CK_PERMLEN+1]; static char gprmbuf[2];#endif /* CK_PERMS */ char *rp; /* Pointer to reply buffer */ int retcode; /* Return code */ d = SP; /* Initialize disposition */ ff = filnam; /* Filename returned by rcvfil */ if (fncact == XYFX_R && ofn1x && ofn1[0]) /* But watch out for FC=RENAME */ ff = ofn1; /* because we haven't renamed it yet *//* Fill in the attributes we have received */ rp = rpbuf; /* Initialize reply buffer */ *rp++ = 'N'; /* for negative reply. */ *rp = NUL; retcode = 0; /* Initialize return code. */ if (dest == DEST_P) { /* SET DESTINATION PRINTER */#ifdef DYNAMIC if (!dsbuf) if ((dsbuf = malloc(DSBUFL+1)) == NULL) fatal("gtattr: no memory for dsbuf");#endif /* DYNAMIC */ dsbuf[0] = 'P'; dsbuf[1] = '\0'; yy->disp.val = dsbuf; yy->disp.len = 1; } while (c = *s++) { /* Get attribute tag */ aln = xunchar(*s++); /* Length of attribute string */ switch (c) { case '!': /* File length in K */ for (i = 0; (i < aln) && (i < ABUFL); i++) /* Copy it */ abuf[i] = *s++; abuf[i] = '\0'; /* Terminate with null */ if (i < aln) s += (aln - i); /* If field was too long for buffer */ yy->lengthk = atol(abuf); /* Convert to number */ break; case '/': /* Record format */ rfbuf[1] = NUL; rfbuf[2] = NUL; for (i = 0; (i < aln) && (i < RFBUFL); i++) /* Copy it */ rfbuf[i] = *s++; rfbuf[i] = NUL; /* Terminate with null */ yy->recfm.val = rfbuf; /* Pointer to string */ yy->recfm.len = i; /* Length of string */ if ((rfbuf[0] != 'A') || (rfbuf[1] && rfbuf[1] != 'M') || (rfbuf[2] && rfbuf[2] != 'J')) { debug(F110,"gattr bad recfm",rfbuf,0); *rp++ = c; retcode = -1; } break; case '"': /* File type (text, binary, ...) */ for (i = 0; (i < aln) && (i < FTBUFL); i++) ftbuf[i] = *s++; /* Copy it into a static string */ ftbuf[i] = '\0'; if (i < aln) s += (aln - i); /* TYPE attribute is enabled? */ if (attypi) { yy->type.val = ftbuf; /* Pointer to string */ yy->type.len = i; /* Length of string */ debug(F111,"gattr file type", ftbuf, i); debug(F101,"gattr binary 1","",binary); /* Unknown type? */ if ((*ftbuf != 'A' && *ftbuf != 'B' && *ftbuf != 'I')#ifdef CK_LABELED/* ... Or our FILE TYPE is LABELED and the incoming file is text... */ || (binary == XYFT_L && *ftbuf == 'A' && !xflg)#endif /* CK_LABELED */ ) { retcode = -1; /* Reject the file */ *rp++ = c; if (!opnerr) tlog(F100," refused: type","",0); break; }/* The following code moved here from opena() so we set binary mode as soon as requested by the attribute packet. That way when the first data packet comes, the mode of transfer can be displayed correctly before opena() is called.*/ if (yy->type.val[0] == 'A') { /* Check received attributes. */#ifdef VMS if (binary != XYFT_I) /* VMS IMAGE overrides this */#endif /* VMS */ binary = XYFT_T; /* Set current type to Text. */ debug(F101,"gattr binary 2","",binary); } else if (yy->type.val[0] == 'B') {#ifdef CK_LABELED if (binary != XYFT_L#ifdef VMS && binary != XYFT_U /* VMS special case */#endif /* VMS */ )#endif /* CK_LABELED */#ifdef MAC if (binary != XYFT_M) /* If not MacBinary... */#endif /* MAC */ binary = XYFT_B; debug(F101,"gattr binary 3","",binary); } } break; case '#': /* File creation date */ for (i = 0; (i < aln) && (i < DTBUFL); i++) dtbuf[i] = *s++; /* Copy it into a static string */ if (i < aln) s += (aln - i); dtbuf[i] = '\0'; if (atdati && !xflg) { /* Real file and dates enabled */ yy->date.val = dtbuf; /* Pointer to string */ yy->date.len = i; /* Length of string */ if (fncact == XYFX_U) { /* Receiving in update mode? */ if (zstime(ff,yy,1) > 0) { /* Compare dates */ *rp++ = c; /* Discard if older, reason = date. */ if (!opnerr) tlog(F100," refused: date","",0); retcode = -1; /* Rejection notice. */ } } } break; case '(': /* File Block Size */ for (i = 0; (i < aln) && (i < ABUFL); i++) /* Copy it */ abuf[i] = *s++; abuf[i] = '\0'; /* Terminate with null */ if (i < aln) s += (aln - i); if (atblki) yy->blksize = atol(abuf); /* Convert to number */ break; case '*': /* Encoding (transfer syntax) */ for (i = 0; (i < aln) && (i < TSBUFL); i++) tsbuf[i] = *s++; /* Copy it into a static string */ if (i < aln) s += (aln - i); tsbuf[i] = '\0';#ifndef NOCSETS xlatype = XLA_NONE; /* Assume no translation */#endif /* NOCSETS */ if (atenci) { char * ss; yy->encoding.val = tsbuf; /* Pointer to string */ yy->encoding.len = i; /* Length of string */ debug(F101,"gattr encoding",tsbuf,i); ss = tsbuf+1; switch (*tsbuf) {#ifndef NOCSETS case 'A': /* Normal, nothing special */ tcharset = TC_TRANSP; /* Transparent chars untranslated */ debug(F110,"gattr sets tcharset TC_TRANSP","A",0); break; case 'C': /* Specified character set */ if (!xfrxla) { /* But translation disabled */ tcharset = TC_TRANSP; debug(F110,"gattr sets tcharset TC_TRANSP","C",0); break; }#ifdef UNICODE if (!strcmp("I196",ss)) /* Treat I196 (UTF-8 no level) */ ss = "I190"; /* as I190 (UTF-8 Level 1) */#endif /* UNICODE */ if (!strcmp("I6/204",ss)) /* Treat "Latin-1 + Euro" */ ss = "I6/100"; /* as I6/100 (regular Latin-1) */ for (i = 0; i < ntcsets; i++) { if (!strcmp(tcsinfo[i].designator,ss)) break; } debug(F101,"gattr xfer charset lookup","",i); if (i == ntcsets) { /* If unknown character set, */ debug(F110,"gattr: xfer charset unknown",ss,0); if (!unkcs) { /* and SET UNKNOWN DISCARD, */ retcode = -1; /* reject the file. */ *rp++ = c; if (!opnerr) tlog(F100," refused: character set","",0); } } else { tcharset = tcsinfo[i].code; /* it's known, use it */ debug(F101,"gattr switch tcharset","",tcharset); debug(F101,"gattr fcharset","",fcharset); if (r_cset == XMODE_A) { /* Automatic switching? */ if (tcharset > -1 && tcharset <= MAXTCSETS) { int x; x = axcset[tcharset]; if (x > 0 && x <= MAXFCSETS) { fcharset = x; debug(F101,"gattr switch fcharset","",x); } } } /* Set up translation type and function */ setxlatype(tcharset,fcharset); } break;#endif /* NOCSETS */ default: /* Something else. */ debug(F110,"gattr unk encoding attribute",tsbuf,0); if (!unkcs) { /* If SET UNK DISC */ retcode = -1; *rp++ = c; if (!opnerr) tlog(F100," refused: encoding","",0); } break; } } break; case '+': /* Disposition */#ifdef DYNAMIC if (!dsbuf) if ((dsbuf = malloc(DSBUFL+1)) == NULL) fatal("gtattr: no memory for dsbuf");#endif /* DYNAMIC */ for (i = 0; (i < aln) && (i < DSBUFL); i++) dsbuf[i] = *s++; /* Copy it into a separate string */ dsbuf[i] = '\0'; if (i < aln) s += (aln - i); rs_len = 0; if (atdisi) { /* We are doing this attribute */ /* Copy it into the attribute structure */ yy->disp.val = dsbuf; /* Pointer to string */ yy->disp.len = i; /* Length of string */ d = *dsbuf;#ifndef NODISPO/* Define NODISPO to disable receipt of mail or print files and of RESEND.*/ if (#ifndef datageneral /* MAIL supported only for */#ifndef OS2 /* UNIX, VMS, and OS-9 */#ifndef MAC#ifndef GEMDOS#ifndef AMIGA d != 'M' && /* MAIL */#endif /* AMIGA */#endif /* GEMDOS */#endif /* MAC */#endif /* OS/2 */#endif /* datageneral */#ifdef CK_RESEND d != 'R' && /* RESEND */#endif /* CK_RESEND */ d != 'P') { /* PRINT */ retcode = -1; /* Unknown/unsupported disposition */ *rp++ = c; if (!opnerr) tlog(F101," refused: bad disposition","",d); } dispos = d; debug(F000,"gattr dispos","",dispos); switch (d) {#ifndef NOFRILLS case 'M': if (!en_mai) { retcode = -1; *rp++ = c; if (!opnerr) tlog(F100," refused: mail disabled","",0); dispos = 0; } break;#endif /* NOFRILLS */ case 'P': if (!en_pri) { retcode = -1; *rp++ = c; if (!opnerr) tlog(F100," refused: print disabled","",0); dispos = 0; } break; case 'R': dispos = 0;#ifdef CK_RESEND rs_len = zgetfs(ff); /* Get length of file */ debug(F111,"gattr RESEND",ff,rs_len);#ifdef VMS rs_len &= (long) -512; /* Ensure block boundary if VMS */ rs_len -= 512; /* In case last block not complete */ debug(F111,"gattr rs_len",ff,rs_len);#endif /* VMS */#ifdef COMMENT if (rs_len < 0L) /* Local file doesn't exist */ rs_len = 0L;#endif /* COMMENT *//* Another possibility here (or later, really) would be to check if the two file lengths are the same, and if so, keep the prevailing collision action as is (note: rs_len == length of existing file; yy->length == fsize == length of incoming file). This could be complicated, though, since (a) we might not have received the length attribute yet, and in fact it might even be in a subsequent A-packet, yet (b) we have to accept or reject the Recover attribute now. So better to leave as-is. Anyway, it's probably more useful this way.*/ if (rs_len > 0L) { fncsav = fncact; /* Save collision action */ fncact = XYFX_A; /* Switch to APPEND */ }#else retcode = -1; /* This shouldn't happen */ *rp++ = c; /* 'cause it wasn't negotiated. */ if (!opnerr) tlog(F100," refused: resend","",0);#endif /* CK_RESEND */ }#else /* NODISPO */ retcode = -1; *rp++ = c; if (!opnerr) tlog(F100," refused: NODISPO","",0);#endif /* NODISPO */ } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -