📄 ckcfn3.c
字号:
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; } else lprmbuf[0] = NUL; 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; } else gprmbuf[0] = NUL; 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;#ifdef DEBUG if (deblog) { sprintf(abuf,"%ld",fsize); /* safe */ 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 = ""; /* 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 */ debug(F101,"opena remote len","",zz->length); debug(F101,"opena local len","",rs_len);#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 */ if (zz->length == rs_len) /* Local and remote lengths equal? */ return(-17); /* Secret code */ } 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(&prfspec,f); /* New preliminary name */#else#ifndef ZFNQFP tlog(F110," local name:",f,0L); makestr(&prfspec,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(&prfspec,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 (xfrxla) { 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); } else { tlog(F110," character-set:","transparent",0L); }#endif /* NOCSETS */ debug(F111,"opena charset",zz->encoding.val,zz->encoding.len); } debug(F101,"opena binary","",binary);#ifdef COMMENT if (fsize > -1L)#endif /* COMMENT */ 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 &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -