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

📄 ckcfn3.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
	      dsbuf[i] = *s++;		/* Copy it into a static string */	    dsbuf[i] = '\0';	    if (i < aln) s += (aln - i);	    if (atdisi) {		yy->disp.val = dsbuf;	/* Pointer to string */		yy->disp.len = i;	/* Length of string */		if (#ifndef datageneral			/* MAIL supported only for */#ifndef OS2				/* UNIX, VMS, and OS-9 */#ifndef MAC#ifndef GEMDOS#ifndef AMIGA		    *dsbuf != 'M' &&#endif /* AMIGA */#endif /* GEMDOS */#endif /* MAC */#endif /* OS/2 */#endif /* datageneral */		    *dsbuf != 'P') {		    retcode = -1;		    *rp++ = c;		}	    }	    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;	  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(filnam,(yy->length))) { /* Check space */		retcode = -1;		*rp++ = '1';	    }	} else if (yy->lengthk > -1L) {	/* Length in K attribute rec'd? */	    if (!zchkspa(filnam,(yy->lengthk * 1024))) {		retcode = -1;		/* Check space */		*rp++ = '!';	    }	}    }    if (yy->length > -1L) {		/* Get 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 */    yy->reply.val = rpbuf;		/* Add it to attribute structure */    yy->reply.len = (int)strlen(rpbuf);    debug(F111,"gattr return",rpbuf,retcode);    return(retcode);}/*  I N I T A T T R  --  Initialize file attribute structure  */intinitattr(yy) struct zattr *yy; {    yy->lengthk = yy->length = -1L;    yy->type.val = "";    yy->type.len = 0;    yy->date.val = "";    yy->date.len = 0;    yy->encoding.val = "";    yy->encoding.len = 0;    yy->disp.val = "";    yy->disp.len = 0;    yy->systemid.val = "";    yy->systemid.len = 0;    yy->sysparam.val = "";    yy->sysparam.len = 0;    yy->creator.val = "";    yy->creator.len = 0;    yy->account.val = "";    yy->account.len = 0;    yy->area.val = "";    yy->area.len = 0;    yy->passwd.val = "";    yy->passwd.len = 0;    yy->blksize = -1L;    yy->access.val = "";    yy->access.len = 0;    yy->lprotect.val = "";    yy->lprotect.len = 0;    yy->gprotect.val = "";    yy->gprotect.len = 0;    yy->recfm.val = "";    yy->recfm.len = 0;    yy->reply.val = "";    yy->reply.len = 0;    return(0);}/*  A D E B U -- Write attribute packet info to debug log  */intadebu(f,zz) char *f; struct zattr *zz; {#ifdef DEBUG    if (deblog == 0) return(0);    debug(F110,"Attributes for incoming file ",f,0);    debug(F101," length in K","",(int) zz->lengthk);    debug(F111," file type",zz->type.val,zz->type.len);    debug(F111," creation date",zz->date.val,zz->date.len);    debug(F111," creator",zz->creator.val,zz->creator.len);    debug(F111," account",zz->account.val,zz->account.len);    debug(F111," area",zz->area.val,zz->area.len);    debug(F111," password",zz->passwd.val,zz->passwd.len);    debug(F101," blksize","",(int) zz->blksize);    debug(F111," access",zz->access.val,zz->access.len);    debug(F111," encoding",zz->encoding.val,zz->encoding.len);    debug(F111," disposition",zz->disp.val,zz->disp.len);    debug(F111," lprotection",zz->lprotect.val,zz->lprotect.len);    debug(F111," gprotection",zz->gprotect.val,zz->gprotect.len);    debug(F111," systemid",zz->systemid.val,zz->systemid.len);    debug(F111," recfm",zz->recfm.val,zz->recfm.len);    debug(F111," sysparam",zz->sysparam.val,zz->sysparam.len);    debug(F101," length","",(int) zz->length);    debug(F110," reply",zz->reply.val,0);#endif /* DEBUG */    return(0);}/*  O P E N A -- Open a file, with attributes.  *//*  This function tries to open a new file to put the arriving data in.  The  filename is the one in the srvcmd buffer.  File collision actions are:  OVERWRITE (the existing file is overwritten), RENAME (the new file is  renamed), BACKUP (the existing file is renamed), DISCARD (the new file is  refused), UPDATE (the incoming file replaces the existing file only if the  incoming file has a newer creation date).  Returns 0 on failure, nonzero on success.*/intopena(f,zz) char *f; struct zattr *zz; {    int x;    static struct filinfo fcb;		/* Must be static! */    debug(F111,"opena discard",f,discard);    adebu(f,zz);			/* Write attributes to debug log */    ffc = 0L;				/* Init file character counter */#ifdef COMMENT/*  This code moved to sattr().*/    if (bsavef) {			/* If somehow file mode */	binary = bsave;			/* was saved but not restored, */	bsavef = 0;			/* restore it. */	debug(F101,"opena restoring binary","",binary);    }    if (zz->type.val[0] == 'A') {	/* Check received attributes */#ifdef VMS	if (binary == XYFT_L)		/* Refuse to receive a file in */	  return(0);			/* labeled mode if sent as text. */#endif /* VMS */	bsave = binary;			/* ASCII.  Save global file type */	bsavef = 1;			/* ( restore it in clsof() ) */	binary = XYFT_T;		/* Set current type to Text. */	debug(F100,"opena attribute A = text","",binary);    } else if (zz->type.val[0] == 'B') {	bsave = binary;			/* Binary.  Save global file type */	bsavef = 1;#ifdef VMS	if (binary != XYFT_L && binary != XYFT_U) /* Special VMS cases */#endif /* VMS */	  binary = XYFT_B;	debug(F101,"opena attribute B = binary","",binary);    }#endif /* COMMENT */    /* Set up file control structure */    fcb.bs = fblksiz;			/* Blocksize */#ifndef NOCSETS    fcb.cs = fcharset;			/* Character set */#else    fcb.cs = 0;				/* Character set */#endif /* NOCSETS */    fcb.rl = frecl;			/* Record Length */    fcb.fmt = frecfm;			/* Record Format */    fcb.org = forg;			/* Organization */    fcb.cc = fcctrl;			/* Carriage control */    fcb.typ = binary;			/* Type */    fcb.dsp = (fncact == XYFX_A) ? XYFZ_A : XYFZ_N; /* Disposition */    fcb.os_specific = '\0';		/* OS specific info */#ifdef VMS    fcb.lblopts = lf_opts;		/* VMS Labeled file options */#else    fcb.lblopts = 0;#endif /* VMS */    if (x = openo(f,zz,&fcb)) {		/* Try to open the file. */	tlog(F110," as",f,0L);		/* OK, open, record name. */	if (binary) {			/* Log file mode in transaction log */	    tlog(F101," mode: binary","",(long) binary);	} else {			/* If text mode, check character set */	    tlog(F100," mode: text","",0L);#ifndef NOCSETS	    tlog(F110," file character set",fcsinfo[fcharset].name,0L);	    if (tcharset == TC_TRANSP)	      tlog(F110," xfer character set","transparent",0L);	    else	      tlog(F110," xfer character set",tcsinfo[tcharset].name,0L);#endif /* NOCSETS */	    debug(F111," opena charset",zz->encoding.val,zz->encoding.len);	}	if (fsize > -1L) screen(SCR_FS,0,fsize,"");#ifdef datageneral/* Need to turn on multi-tasking console interrupt task here, since multiple *//* files may be received. */        if ((local) && (!quiet))        /* Only do this if local & not quiet */            consta_mt();                /* Start the asynch read task */#endif /* datageneral */    } else {				/* Did not open file OK. */#ifdef ATTSV	extern char *sys_errlist[];	extern int errno;	screen(SCR_EM,0,0l,sys_errlist[errno]);#else#ifdef BSD4	extern char *sys_errlist[];	extern int errno;	screen(SCR_EM,0,0l,sys_errlist[errno]);#else	screen(SCR_EM,0,0l,"Can't open output file");#endif /* BSD4 */#endif /* ATTSV */        tlog(F110,"Failure to open",f,0L);    }    return(x);				/* Pass on return code from openo */}/*  C A N N E D  --  Check if current file transfer cancelled */intcanned(buf) CHAR *buf; {    if (*buf == 'X') cxseen = 1;    if (*buf == 'Z') czseen = 1;    debug(F101,"canned: cxseen","",cxseen);    debug(F101," czseen","",czseen);    return((czseen || cxseen) ? 1 : 0);}/*  O P E N I  --  Open an existing file for input  */intopeni(name) char *name; {    int x, filno;    char *name2;    if (memstr) return(1);		/* Just return if file is memory. */    debug(F110,"openi",name,0);    debug(F101," sndsrc","",sndsrc);    filno = (sndsrc == 0) ? ZSTDIO : ZIFILE;    /* ... */    debug(F101," file number","",filno);    if (server && !en_cwd) {		/* If running as server */	zstrip(name,&name2);		/* and CWD is disabled... */	if (				/* check if pathname was included. */#ifdef VMS	zchkpath(name)#else	strcmp(name,name2)#endif /* VMS */        ) {	    tlog(F110,name,"authorization failure",0L);	    debug(F110," openi authorization failure",name,0);	    return(0);	} else name = name2;    }    if (zopeni(filno,name)) {		/* Otherwise, try to open it. */	debug(F110," ok",name,0);    	return(1);    } else {				/* If not found, */	char xname[100];		/* convert the name */	zrtol(name,xname);		/* to local form and then */	x = zopeni(filno,xname);	/* try opening it again. */	debug(F101," zopeni","",x);	if (x) {	    debug(F110," ok",xname,0);	    return(1);			/* It worked. */        } else {#ifdef COMMENT	    screen(SCR_EM,0,0l,"Can't open file");  /* It didn't work. */#endif /* COMMENT */	    tlog(F110,xname,"could not be opened",0L);	    debug(F110," openi failed",xname,0);	    return(0);        }    }}/*  O P E N O  --  Open a new file for output.  */intopeno(name,zz,fcb) char *name; struct zattr *zz; struct filinfo *fcb; {    char *name2;    if (stdouf)				/* Receiving to stdout? */      return(zopeno(ZSTDIO,"",zz,NULL));    debug(F110,"openo: name",name,0);    if (cxseen || czseen || discard) {	/* If interrupted, get out before */	debug(F100," open cancelled","",0); /* destroying existing file. */	return(1);			/* Pretend to succeed. */    }    if (server && !en_cwd) {		/* If running as server */	zstrip(name,&name2);		/* and CWD is disabled, */	if (strcmp(name,name2)) {	/* check if pathname was included. */	    tlog(F110,name,"authorization failure",0L);	    debug(F110," openo authorization failure",name,0);	    return(0);	} else name = name2;    }    if (zopeno(ZOFILE,name,zz,fcb) == 0) { /* Try to open the file */	debug(F110,"openo failed",name,0);	tlog(F110,"Failure to open",name,0L);	return(0);    } else {	debug(F110,"openo ok, name",name,0);	return(1);    }}/*  O P E N T  --  Open the terminal for output, in place of a file  */intopent(zz) struct zattr *zz; {    ffc = tfc = 0L;    if (bsavef) {			/* If somehow file mode */	binary = bsave;			/* was saved but not restored, */	bsavef = 0;			/* restore it. */	debug(F101,"opena restoring binary","",binary);    }    bsave = binary;    bsavef = 1;    binary = XYFT_T;    return(zopeno(ZCTERM,"",zz,NULL));}/*  C L S I F  --  Close the current input file. */intclsif() {    int x = 0;#ifdef datageneral    if ((local) && (!quiet))    /* Only do this if local & not quiet */        if (nfils < 1)          /* More files to send ... leave it on! */            connoi_mt();#endif /* datageneral */    if (memstr) {			/* If input was memory string, */	memstr = 0;			/* indicate no more. */    } else x = zclose(ZIFILE);		/* else close input file. */    if (cxseen || czseen)		/* If interrupted */      screen(SCR_ST,ST_INT,0l,"");	/* say so */    else if (discard)			/* If I'm refusing */      screen(SCR_ST,ST_REFU,0l,refused); /* say why */    else {				/* Otherwise */	fstats();			/* update statistics */	screen(SCR_ST,ST_OK,0l,"");	/* and say transfer was OK */    }    hcflg = 0;				/* Reset flags */    *filnam = '\0';			/* and current file name */    return(x);}/*  C L S O F  --  Close an output file.  *//*  Call with disp != 0 if file is to be discarded.  *//*  Returns -1 upon failure to close, 0 or greater on success. */intclsof(disp) int disp; {    int x;    debug(F101,"clsof disp","",disp);    if (bsavef) {			/* If we saved global file type */	debug(F101,"clsof restoring binary","",binary);	binary = bsave;			/* restore it */	bsavef = 0;			/* only this once. */    }#ifdef datageneral    if ((local) && (!quiet))		/* Only do this if local & not quiet */        connoi_mt();#endif /* datageneral */    cxseen = 0;				/* Reset per-file interruption flag */    if ((x = zclose(ZOFILE)) < 0) {	/* Try to close the file */	tlog(F100,"Failure to close",filnam,0L);	screen(SCR_ST,ST_ERR,0l,"");    } else if (disp) {			/* Interrupted or refused */	if (keep == 0) {		/* If not keep incomplete files */	    if (*filnam) zdelet(filnam); /* Delete it */	    debug(F100,"Discarded","",0);	    tlog(F100,"Discarded","",0L);	    screen(SCR_ST,ST_DISC,0l,"");	} else {			/* Keep incomplete copy */	    if (ffc) ffc++;		/* This is off by one (why?) */	    fstats();	    debug(F100,"Incomplete","",0);	    tlog(F100,"Incomplete","",0L);	    screen(SCR_ST,ST_INC,0l,"");	}    } else {				/* Nothing wrong, just keep it */	debug(F100,"Closed","",0);	/* and give comforting messages. */	if (ffc) ffc++;			/* Correct off-by-1 error */	fstats();	screen(SCR_ST,ST_OK,0l,"");    }    return(x);				/* Send back zclose() return code. */}#ifdef SUNOS4S5tolower(c) char c; { return((c)-'A'+'a'); }toupper(c) char c; { return((c)-'a'+'A'); }#endif /* SUNOS4S5 */

⌨️ 快捷键说明

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