⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckcfn3.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	    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 attribute A=text","",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 2","",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) {		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 */		    break;		  case 'C':		/* Specified character set */#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);		}#ifndef NOFRILLS		if (d == 'M' && !en_mai) {		    retcode = -1;		    *rp++ = c;		    if (!opnerr) tlog(F100," refused: mail disabled","",0);		} else#endif /* NOFRILLS */		  if (d == 'P' && !en_pri) {		    retcode = -1;		    *rp++ = c;		    if (!opnerr) tlog(F100," refused: print disabled","",0);		} else if (d == 'R') {	/* File is being resent */#ifdef CK_RESEND		    rs_len = zchki(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 */		    if (rs_len < 0L)		      rs_len = 0L;/*  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;	  case '.':			/* Sender's system ID */	    for (i = 0; (i < aln) && (i < IDBUFL); i++)	      idbuf[i] = *s++;		/* Copy it into a static string */	    idbuf[i] = '\0';	    if (i < aln) s += (aln - i);	    if (atsidi) {		yy->systemid.val = idbuf; /* Pointer to string */		yy->systemid.len = i;	/* Length of string */	    }	    break;	  case '0':			/* System-dependent parameters */#ifdef DYNAMIC	    if (!spbuf && !(spbuf = malloc(SPBUFL)))		fatal("gattr: no memory for spbuf");#endif /* DYNAMIC */	    for (i = 0; (i < aln) && (i < SPBUFL); i++)	      spbuf[i] = *s++;		/* Copy it into a static string */	    spbuf[i] = '\0';	    if (i < aln) s += (aln - i);	    if (atsysi) {		yy->sysparam.val = spbuf; /* Pointer to string */		yy->sysparam.len = i;	/* Length of string */	    }	    break;	  case '1':			/* File length in bytes */	    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);	    yy->length = atol(abuf);	/* Convert to number */	    debug(F111,"gattr length",abuf,(int) yy->length);	    break;#ifdef CK_PERMS	  case ',':			/* System-dependent protection code */	    for (i = 0; (i < aln) && (i < CK_PERMLEN); i++)	      lprmbuf[i] = *s++;	/* Just copy it - decode later */	    lprmbuf[i] = '\0';		/* Terminate with null */	    if (i < aln) s += (aln - i);	    if (atlpri) {		yy->lprotect.val = (char *)lprmbuf;		yy->lprotect.len = i;	    }	    break;	  case '-':			/* Generic "world" protection code */	    gprmbuf[0] = NUL;		/* Just 1 byte by definition */	    for (i = 0; i < aln; i++)	/* But allow for more... */	      if (i == 0) gprmbuf[0] = *s++;	    gprmbuf[1] = NUL;	    if (atgpri) {		yy->gprotect.val = (char *)gprmbuf;		yy->gprotect.len = gprmbuf[0] ? 1 : 0;	    }	    break;#endif /* CK_PERMS */	  default:			/* Unknown attribute */	    s += aln;			/* Just skip past it */	    break;	}    }    /* Check file length now, because we also need to know the file type */    /* in case zchkspa() differentiates text and binary (VMS version does) */    if (atleni) {			/* Length attribute enabled? */	if (yy->length > -1L) {		/* Length-in-bytes attribute rec'd? */	    if (!zchkspa(ff,(yy->length))) { /* Check space */		retcode = -1;		     /* Not enuf */		*rp++ = '1';		if (!opnerr) tlog(F100," refused: length bytes","",0);	    }	} else if (yy->lengthk > -1L) {	/* Length in K attribute rec'd? */	    if (!zchkspa(ff,(yy->lengthk * 1024))) {		retcode = -1;		/* Check space */		*rp++ = '!';		if (!opnerr) tlog(F100," refused: length K","",0);	    }	}    }    if (yy->length > -1L) {		/* Remember the file size */	fsize = yy->length;    } else if (yy->lengthk > -1L) {	fsize = yy->lengthk * 1024L;    } else fsize = -1L;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -