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

📄 ckcfn3.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 4 页
字号:
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) <= 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," 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)	  screen(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;#define ABUFL 40			/* Temporary buffer for conversions */    char abuf[ABUFL];#define FTBUFL 10			/* File type buffer */    static char ftbuf[FTBUFL];#define DTBUFL 40			/* File creation date */    static char dtbuf[DTBUFL];#define TSBUFL 10			/* Transfer syntax */    static char tsbuf[TSBUFL];#define IDBUFL 10			/* System ID */    static char idbuf[IDBUFL];#ifndef DYNAMIC#define DSBUFL 100			/* Disposition */    static char dsbuf[DSBUFL];#define SPBUFL 512			/* System-dependent parameters */    static char spbuf[SPBUFL];#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];    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 '"':			/* file type */	    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);	    if (attypi) {		/* TYPE attribute is enabled? */		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","",binary);		if (			/* Unknown type? */		    (*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. */		    binary = XYFT_T;	/* Set current type to Text. */		    debug(F100,"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 attribute B = binary","",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';	    if (atenci) {		yy->encoding.val = tsbuf; /* Pointer to string */		yy->encoding.len = i;	/* Length of string */		debug(F101,"gattr encoding",tsbuf,i);		switch (*tsbuf) {#ifndef NOCSETS		  case 'A':		/* Normal, nothing special */		    tcharset = TC_TRANSP; /* Transparent chars untranslated */		    break;		  case 'C':		/* Specified character set */		    for (i = 0; i < ntcsets; i++) { 			if (!strcmp(tcsinfo[i].designator,tsbuf+1)) break;		    }		    debug(F101,"gattr xfer charset lookup","",i);		    if (i == ntcsets) {	/* If unknown character set, */			debug(F110,"gattr: xfer charset unknown",tsbuf+1,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; /* if known, use it */			rx = xlr[tcharset][fcharset]; /* xlation function */		    }		    debug(F101,"gattr tcharset","",tcharset);		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;		    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 STRATUS	  case '/':			/* Format of data in packets */	    /* We just copy it into the record and let the fio module */	    /* figure out what to do with it. */	    for (i = 0; (i < aln) && (i < ABUFL); i++) /* Copy it */	      abuf[i] = *s++;	    abuf[i] = '\0';		/* Terminate with null */	    if (atsysi) {		/* same switch as OS-DEPENDENT */		yy->recfm.val = spbuf;	/* Pointer to string */		yy->recfm.len = i;	/* Length of string */	    }	    break;#endif /* STRATUS */	  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;#ifdef DEBUG    if (deblog) {	sprintf(abuf,"%ld",fsize);	debug(F110,"gattr fsize",abuf,0);    }#endif /* DEBUG */    if (retcode == 0) rp = rpbuf;	/* Null reply string if accepted */    *rp = '\0';				/* End of reply string */#ifdef CK_RESEND    if (d == 'R') {			/* Receiving a RESEND? */	debug(F101,"gattr RESEND","",retcode);	/* We ignore retcodes because this overrides */	if (binary != XYFT_B) {		/* Reject if not binary */	    retcode = -1;		/* in case type field came */	    strcpy(rpbuf,"N+");		/* after the disposition field */	    debug(F111,"gattr RESEND not binary",rpbuf,binary);	} else {			/* Binary mode */	    retcode = 0;		/* Accept the file */	    discard = 0;		/* If SET FILE COLLISION DISCARD */	    sprintf(rpbuf+2,"%ld",rs_len); /* Reply with length of file */	    rpbuf[0] = '1';		/* '1' means Length in Bytes */	    rpbuf[1] = tochar((int)strlen(rpbuf+2)); /* Length of length */	    debug(F111,"gattr RESEND OK",rpbuf,retcode);	}    }#endif /* CK_RESEND */    if (retcode == 0 && discard != 0) {	/* Do we still have a discard flag? */	strcpy(rpbuf,"N?");		/* Yes, must be filename collision */	retcode = -1;			/* "?" = name (reply-only code) */    }    yy->reply.val = rpbuf;		/* Add it to attribute structure */    yy->reply.len = (int)strlen(rpbuf);

⌨️ 快捷键说明

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