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

📄 ckcfn3.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#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 */	    ckstrncpy(rpbuf,"N+",RPBUFL); /* 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? */	ckstrncpy(rpbuf,"N?",RPBUFL);	/* 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);    if (retcode < 0) {			/* If we are rejecting */	discard = 1;			/* remember to discard the file */	rejection = rpbuf[1];		/* and use the first reason given. */	if (fncsav != -1) {	    fncact = fncsav;	    fncsav = -1;	}    }    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->password.val = "";    yy->password.len = 0;    yy->blksize = -1L;    yy->xaccess.val = "";    yy->xaccess.len = 0;#ifdef CK_PERMS    if (!ofperms) ofperms = "";    debug(F110,"initattr ofperms",ofperms,0);    yy->lprotect.val = ofperms;    yy->lprotect.len = 0 - strlen(ofperms); /* <-- NOTE! */    /*      A negative length indicates that we have a permissions string but it has      been inherited from a previously existing file rather than picked up      from an incoming A-packet.    */#else    yy->lprotect.val = "";    yy->lprotect.len = 0;#endif /* CK_PERMS */    yy->gprotect.val = "";    yy->gprotect.len = 0;    yy->recfm.val = "";    yy->recfm.len = 0;    yy->reply.val = "";    yy->reply.len = 0;#ifdef OS2    yy->longname.len = 0 ;    yy->longname.val = "" ;#endif /* OS2 */    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->password.val,zz->password.len);    debug(F101," blksize","",(int) zz->blksize);    debug(F111," access",zz->xaccess.val,zz->xaccess.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.*/extern char *rf_err;intopena(f,zz) char *f; struct zattr *zz; {    int x, dispos = 0;    static struct filinfo fcb;		/* Must be static! */    debug(F110,"opena f",f,0);    debug(F101,"opena discard","",discard);    adebu(f,zz);			/* Write attributes to debug log */    ffc = 0L;				/* Init file-character counter */#ifdef PIPESEND    if (pipesend)			/* Receiving to a pipe - easy. */      return(openo(f,zz,&fcb));		/* Just open the pipe. */#endif /* PIPESEND */    /* Receiving to a file - 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 */    debug(F101,"opena xflg","",xflg);    debug(F101,"opena remfile","",remfile);    debug(F101,"opena remappd","",remappd);    if (xflg && remfile && remappd)	/* REMOTE output redirected with >> */      fcb.dsp = XYFZ_A;    else      fcb.dsp = (fncact == XYFX_A) ? XYFZ_A : XYFZ_N; /* Disposition */    debug(F101,"opena disp","",fcb.dsp);    fcb.os_specific = '\0';		/* OS-specific info */#ifdef CK_LABELED    fcb.lblopts = lf_opts;		/* Labeled file options */#else    fcb.lblopts = 0;#endif /* CK_LABELED */    if (zz->disp.len > 0) {		/* Incoming file has a disposition? */	debug(F111,"open disposition",zz->disp.val,zz->disp.len);	dispos = (int) (*(zz->disp.val));    }    if (!dispos && xflg && remfile && remappd) /* REMOTE redirect append ? */      dispos = fcb.dsp;    debug(F101,"opena dispos","",dispos);    if (!dispos) {			         /* No special disposition? */	if (fncact == XYFX_B && ofn1x && ofn2) { /* File collision = BACKUP? */	    if (zrename(ofn1,ofn2) < 0) {        /* Rename existing file. */		debug(F110,"opena rename fails",ofn1,0);		rf_err = "Can't create backup file";		return(0);	    } else debug(F110,"opena rename ok",ofn2,0);	}    } else if (dispos == 'R') {		/* Receiving a RESEND */#ifdef COMMENT        if (fncact == XYFX_R)		/* and file collision = RENAME */	  if (ofn1x)#endif /* COMMENT */	if (ofn1[0])	  f = ofn1;			/* use original name. */        if (fncact == XYFX_R)		/* if file collision is RENAME */          ckstrncpy(filnam,ofn1,CKMAXPATH+1); /* restore the real name */        xxscreen(SCR_AN,0,0L,f);	/* update name on screen */    }    debug(F111,"opena [file]=mode: ",f,fcb.dsp);    if (x = openo(f,zz,&fcb)) {		/* Try to open the file. */#ifdef pdp11	tlog(F110," local name:",f,0L);	/* OK, open, record local name. */	makestr(&rfspec,f);#else#ifndef ZFNQFP	tlog(F110," local name:",f,0L);	makestr(&rfspec,f);#else	{				/* Log full local pathname */	    char *p = NULL, *q = f;	    if ((p = malloc(CKMAXPATH+1)))	      if (zfnqfp(filnam, CKMAXPATH, p))		q = p;	    tlog(F110," local name:",q,0L);	    makestr(&rfspec,q);	    if (p) free(p);	}#endif /* ZFNQFP */#endif /* pdp11 */	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	    if (fcharset > -1 && fcharset <= MAXFCSETS)	      tlog(F110," file character-set:",fcsinfo[fcharset].name,0L);	    if (tcharset > -1 && tcharset <= MAXTCSETS)	      tlog(F110," xfer character-set:",tcsinfo[tcharset].name,0L);#endif /* NOCSETS */	    debug(F111," opena charset",zz->encoding.val,zz->encoding.len);	}	if (fsize > -1L) xxscreen(SCR_FS,0,fsize,"");#ifdef datageneral/*  Need to turn on multi-tasking console interrupt task here, since multiple  files may be received (huh?) ...*/        if ((local) && (!quiet))        /* Only do this if local & not quiet */	  consta_mt();			/* Start the async read task */#endif /* datageneral */    } else {				/* Did not open file OK. */	rf_err = ck_errstr();		/* Get system error message */	if (*rf_err)	  xxscreen(SCR_EM,0,0l,rf_err);	else	  xxscreen(SCR_EM,0,0l,"Can't open output file");        tlog(F110,"Failure to open",f,0L);        tlog(F110,"Error:",rf_err,0L);	debug(F110,"opena error",rf_err,0);    }    return(x);				/* Pass on return code from openo */}/*  O P E N C  --  Open a command (in place of a file) for output */intopenc(n,s) int n; char * s; {    int x;#ifndef NOPUSH    x = zxcmd(n,s);#else    x = 0;#endif /* NOPUSH */    debug(F111,"openc zxcmd",s,x);    o_isopen = (x > 0) ? 1 : 0;    return(x);}/*  C A N N E D  --  Check if current file transfer cancelled */intcanned(buf) CHAR *buf; {    extern int interrupted;    if (*buf == 'X') cxseen = 1;    if (*buf == 'Z') czseen = 1;    if (czseen || cxseen)      interrupted = 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; {#ifndef NOSERVER    extern int fromgetpath;#endif /* NOSERVER */    int x, filno;    char *name2;    extern CHAR *epktmsg;    epktmsg[0] = NUL;			/* Initialize error message */    if (memstr || sndarray) {		/* Just return if "file" is memory. */	i_isopen = 1;	return(1);    }    debug(F110,"openi name",name,0);    debug(F101,"openi sndsrc","",sndsrc);    filno = (sndsrc == 0) ? ZSTDIO : ZIFILE;    /* ... */    debug(F101,"openi file number","",filno);#ifndef NOSERVER    /* If I'm a server and CWD is disabled and name is not from GET-PATH... */    if (server && !en_cwd && !fromgetpath) {	zstrip(name,&name2);	if (				/* ... check if pathname included. */#ifdef VMS	    zchkpath(name)#else	    strcmp(name,name2)#endif /* VMS */	    ) {	    tlog(F110,name,"access denied",0L);	    debug(F110,"openi CD disabled",name,0);	    ckstrncpy((char *)epktmsg,"Access denied",PKTMSGLEN);	    return(0);	} else name = name2;    }#endif /* NOSERVER */#ifdef PIPESEND    if (pipesend) {	int x;#ifndef NOPUSH	x = zxcmd(ZIFILE,name);#else	x = 0;#endif /* NOPUSH */	i_isopen = (x > 0) ? 1 : 0;	if (!i_isopen)	  ckstrncpy((char *)epktmsg,"Command or pipe failure",PKTMSGLEN);	debug(F111,"openi pipesend zxcmd",name,x);	return(i_isopen);    }#endif /* PIPESEND */#ifdef CALIBRATE    if (calibrate) {	i_isopen = 1;    	return(1);    }#endif /* CALIBRATE */    x = zopeni(filno,name);		/* Otherwise, try to open it. */    debug(F111,"openi zopeni 1",name,x);    if (x) {	i_isopen = 1;    	return(1);    } else {				/* If not found, */	char xname[CKMAXPATH];		/* convert the name */#ifdef NZLTOR	nzrtol(name,xname,fncnv,fnrpath,CKMAXPATH);#else	zrtol(name,xname);		/* to local form and then */#endif /*  NZLTOR */	x = zopeni(filno,xname);	/* try opening it again. */	debug(F101,"openi zopeni 2",xname,x);	if (x) {	    i_isopen = 1;	    return(1);			/* It worked. */        } else {	    char * s;	    s = ck_errstr();	    if (s) if (!s) s = NULL;	    if (!s) s = "Can't open file";	    ckstrncpy((char *)epktmsg,s,PKTMSGLEN);	    tlog(F110,xname,s,0L);	    debug(F110,"openi failed",xname,0);	    debug(F110,"openi message",s,0);	    i_isopen = 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;#ifdef DTILDE    char *dirp;#endif /* DTILDE */    int channel, x;    if (stdouf) {				/* Receiving to stdout? */	x = zopeno(ZSTDIO,"",zz,NULL);	o_isopen = (x > 0);	debug(F101,"openo stdouf zopeno","",x);	return(x);    }    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. */    }    channel = ZOFILE;			/* SET DESTINATION DISK or PRINTER */#ifdef PIPESEND    debug(F101,"openo pipesend","",pipesend);    if (pipesend) {	int x;#ifndef NOPUSH	x = zxcmd(ZOFILE,(char *)srvcmd);#else	x = 0;#endif /* NOPUSH */	o_isopen = x > 0;	debug(F101,"openo zxcmd","",x);

⌨️ 快捷键说明

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