📄 ckcpro.w
字号:
xflg = 0; /* Not screen data */ cancel = 0; /* Reset cancellation counter */#ifdef CALIBRATE if (dest == DEST_N) calibrate = 1;#endif /* CALIBRATE */ if (!rcvfil(filnam)) { /* Figure out local filename */ errpkt((CHAR *)rf_err); /* Trouble */ RESUME; } else { /* Real file, OK to receive */ char * fnp; debug(F111,"<rfile>F winlo 2",fspec,winlo); if (filcnt == 1) /* rcvfil set this to 1 for 1st file */ crc16 = 0L; /* Clear file CRC */ fnp = fspec; /* This is the full path */ if (server && !ENABLED(en_cwd) || /* if DISABLE CD */ !fackpath /* or F-ACK-PATH OFF */ ) { zstrip(fspec,&fnp); /* don't send back full path */ } encstr((CHAR *)fnp); if (fackbug) ack(); else ack1(data); /* Send it back in ACK */ initattr(&iattr); /* Clear file attribute structure */ streamon(); if (window(wslotn) < 0) { /* Allocate negotiated window slots */ errpkt((CHAR *)"Can't open window"); RESUME; }#ifdef IKSDB if (ikdbopen) slotstate(what, server ? "SERVER" : "", "RECEIVE", fspec );#endif /* IKSDB */ BEGIN rattr; /* Now expect Attribute packets */ }}<rgen,rfile>X { /* X-packet instead of file header */ xflg = 1; /* Screen data */ cancel = 0; /* Reset cancellation counter */ ack(); /* Acknowledge the X-packet */ initattr(&iattr); /* Initialize attribute structure */ streamon(); if (window(wslotn) < 0) { /* allocate negotiated window slots */ errpkt((CHAR *)"Can't open window"); RESUME; }#ifndef NOSPL if (query) { /* If this is the response to */ qbufp = querybuf; /* a query that we sent, initialize */ qbufn = 0; /* the response buffer */ querybuf[0] = NUL; }#endif /* NOSPL */ what = W_REMO; /* we're doing a REMOTE command */#ifdef IKSDB if (ikdbopen) slotstate(what, server ? "SERVER" : "", "RECEIVE", fspec );#endif /* IKSDB */ BEGIN rattr; /* Expect Attribute packets */}<rattr>A { /* Attribute packet */ if (gattr(rdatap,&iattr) == 0) { /* Read into attribute structure */#ifdef CK_RESEND ack1((CHAR *)iattr.reply.val); /* Reply with data */#else ack(); /* If OK, acknowledge */#endif /* CK_RESEND */ } else { /* Otherwise */ extern long fsize; char *r; r = getreason(iattr.reply.val); ack1((CHAR *)iattr.reply.val); /* refuse to accept the file */ xxscreen(SCR_ST,ST_REFU,0L,r); /* reason */#ifdef TLOG if (tralog && !tlogfmt) doxlog(what,filnam,fsize,binary,1,r);#endif /* TLOG */ }}<rattr>D { /* First data packet */ rc = rcv_firstdata(); debug(F101,"srv_firstdata","",rc); if (rc > -1) return(rc); /* (see below) */}<rfile>B { /* EOT, no more files */ ack(); /* Acknowledge the B packet */ reot(); /* Do EOT things */#ifdef CK_TMPDIR/* If we were cd'd temporarily to another device or directory ... */ if (f_tmpdir) { int x; x = zchdir((char *) savdir); /* ... restore previous directory */ f_tmpdir = 0; /* and remember we did it. */ debug(F111,"ckcpro.w B tmpdir restoring",savdir,x); }#endif /* CK_TMPDIR */ RESUME; /* and quit */}<rdpkt>D { /* Data packet */ if (cxseen || discard) { /* If file interrupt */#ifdef STREAMING if (streaming) { if (cancel++ == 0) ack1((CHAR *)"X"); /* put "X" in ACK */ else fastack(); } else#endif /* STREAMING */ ack1((CHAR *)"X"); /* put "X" in ACK */ } else if (czseen) { /* If file-group interrupt */#ifdef STREAMING if (streaming) { if (cancel++ == 0) ack1((CHAR *)"Z"); /* put "Z" in ACK */ else fastack(); } else#endif /* STREAMING */ ack1((CHAR *)"Z"); /* put "Z" in ACK */ } else { int rc, qf;#ifndef NOSPL qf = query;#else qf = 0;#endif /* NOSPL */#ifdef CKTUNING rc = (binary && !parity) ? bdecode(rdatap,putfil): decode(rdatap, qf ? puttrm : putfil, 1);#else rc = decode(rdatap, qf ? puttrm : putfil, 1);#endif /* CKTUNING */ if (rc < 0) { discard = (keep == 0 || (keep == SET_AUTO && binary != XYFT_T)); errpkt((CHAR *)"Error writing data"); /* If failure, */ RESUME; } else /* Data written OK, send ACK */#ifdef STREAMING if (streaming) fastack(); else#endif /* STREAMING */ ack(); }}<rattr>Z { /* EOF immediately after A-Packet. */ rf_err = "Can't create file"; timint = s_timint; if (discard) { /* Discarding a real file... */ x = 1; } else if (xflg) { /* If screen data */ if (remfile) { /* redirected to file */ if (rempipe) /* or pipe */ x = openc(ZOFILE,remdest); /* Pipe: start command */ else x = opena(remdest,&iattr); /* File: open with attributes */ } else { /* otherwise */ x = opent(&iattr); /* "open" the screen */ }#ifdef CALIBRATE } else if (calibrate) { /* If calibration run */ x = ckopenx(&iattr); /* do this */#endif /* CALIBRATE */ } else { /* otherwise */ x = opena(filnam,&iattr); /* open the file, with attributes */ } if (!x || reof(filnam, &iattr) < 0) { /* Now close & dispose of the file */ errpkt((CHAR *) rf_err); /* If problem, send error msg */ RESUME; /* and quit */ } else { /* otherwise */ ack(); /* acknowledge the EOF packet */ BEGIN rfile; /* and await another file */ }}<rdpkt>q { /* Ctrl-C or connection loss. */ timint = s_timint; window(1); /* Set window size back to 1... */ cxseen = 1; x = clsof(1); /* Close file */ return(success = 0); /* Failed */}<rdpkt>Z { /* End Of File (EOF) Packet *//* wslots = 1; */ /* (don't set) Window size back to 1 */#ifndef COHERENT /* Coherent compiler blows up on this switch() statement. */ x = reof(filnam, &iattr); /* Handle the EOF packet */ switch (x) { /* reof() sets the success flag */ case -3: /* If problem, send error msg */ errpkt((CHAR *)"Can't print file"); /* Fatal */ RESUME; break; case -2: errpkt((CHAR *)"Can't mail file"); /* Fatal */ RESUME; break; case 2: case 3: xxscreen(SCR_EM,0,0L,"Can't delete temp file"); /* Not fatal */ RESUME; break; default: if (x < 0) { /* Fatal */ errpkt((CHAR *)"Can't close file"); RESUME; } else { /* Success */#ifndef NOSPL if (query) /* Query reponses generally */ conoll(""); /* don't have line terminators */#endif /* NOSPL */ ack(); /* Acknowledge the EOF packet */ BEGIN rfile; /* and await another file */ } }#else if (reof(filnam, &iattr) < 0) { /* Close the file */ errpkt((CHAR *)"Error at end of file"); RESUME; } else { /* reof() sets success flag */ ack(); BEGIN rfile; }#endif /* COHERENT */}<ssinit>Y { /* ACK for Send-Init */ spar(rdatap); /* set parameters from it */ bctu = bctr; /* switch to agreed-upon block check */ bctl = (bctu == 4) ? 2 : bctu; /* Set block-check length */#ifdef CK_RESEND if ((sendmode == SM_RESEND) && (!atcapu || !rscapu)) { /* RESEND */ errpkt((CHAR *) "RESEND capabilities not negotiated"); RESUME; } else {#endif /* CK_RESEND */ what = W_SEND; /* Remember we're sending */ lastxfer = W_SEND; x = sfile(xflg); /* Send X or F header packet */ cancel = 0; /* Reset cancellation counter */ if (x) { /* If the packet was sent OK */ if (!xflg && filcnt == 1) /* and it's a real file */ crc16 = 0L; /* Clear the file CRC */ resetc(); /* reset per-transaction counters */ rtimer(); /* reset timers */#ifdef GFTIMER rftimer();#endif /* GFTIMER */ streamon(); /* turn on streaming */#ifdef IKSDB if (ikdbopen) slotstate(what, (server ? "SERVER" : ""), "SEND", filnam, "");#endif /* IKSDB */ BEGIN ssfile; /* and switch to receive-file state */ } else { /* otherwise send error msg & quit */ s = xflg ? "Can't execute command" : (char *)epktmsg; if (!*s) s = "Can't open file"; errpkt((CHAR *)s); RESUME; }#ifdef CK_RESEND }#endif /* CK_RESEND */}/* These states are necessary to handle the case where we get a server command packet (R, G, or C) reply with an S packet, but the client retransmits the command packet. The input() function doesn't catch this because the packet number is still zero.*/<ssinit>R { /* R packet was retransmitted. */ xsinit(); /* Resend packet 0 */}<ssinit>G { /* Same deal if G packet comes again */ xsinit();}/* should probably add cases for O, W, V, H, J, ... */<ssinit>C { /* Same deal if C packet comes again */ xsinit();}<ssfile>Y { /* ACK for F or X packet */ srvptr = srvcmd; /* Point to string buffer */ decode(rdatap,putsrv,0); /* Decode data field, if any */ putsrv(NUL); /* Terminate with null */ ffc = 0L; /* Reset file byte counter */ if (*srvcmd) { /* If remote name was recorded */ if (sendmode != SM_RESEND) { extern char * srfspec; if (fdispla == XYFD_C || fdispla == XYFD_S) xxscreen(SCR_AN,0,0L,(char *)srvcmd); tlog(F110," remote name:",(char *) srvcmd,0L); makestr(&srfspec,(char *)srvcmd); } } if (atcapu) { /* If attributes are to be used */ if (sattr(xflg | stdinf, 1) < 0) { /* send them */ errpkt((CHAR *)"Can't send attributes"); /* if problem, say so */ RESUME; /* and quit */ } else BEGIN ssattr; /* if ok, switch to attribute state */ } else { /* Attributes not negotiated */ if (window(wslotn) < 0) { /* Open window */ errpkt((CHAR *)"Can't open window"); RESUME; } if ((x = sdata()) == -2) { /* Send first data packet data */ window(1); /* Failed, put window size back to 1 */ x = clsif(); /* Close input file */ return(success = 0); /* Return failure */ } else if (x == -9) { /* User interrupted */ errpkt((CHAR *)"User cancelled"); /* Send Error packet */ window(1); /* Set window size back to 1... */ timint = s_timint; /* Restore timeout */ return(success = 0); /* Failed */ } else if (x == -1) { /* EOF (empty file) */ window(1); /* put window size back to 1, */ debug(F101,"<ssfile>Y cxseen","",cxseen); x = clsif(); /* If not ok, close input file, */ if (x < 0) /* treating failure as interruption */ cxseen = 1; /* Send EOF packet */ seof(cxseen||czseen); BEGIN sseof; /* and switch to EOF state. */ } else { /* First data sent OK */ BEGIN ssdata; /* All ok, switch to send-data state */ } }}<ssattr>Y { /* Got ACK to A packet */ ffc = 0L; /* Reset file byte counter */ if (rsattr(rdatap) < 0) { /* Was the file refused? */ discard = 1; /* Set the discard flag */ clsif(); /* Close the file */ sxeof(1); /* send EOF with "discard" code */ BEGIN sseof; /* switch to send-EOF state */ } else if ((x = sattr(xflg | stdinf, 0)) < 0) { /* Send more? */ errpkt((CHAR *)"Can't send attributes"); /* Trouble... */ RESUME; } else if (x == 0) { /* No more to send so now the data */ if (window(wslotn) < 0) { /* Allocate negotiated window slots */ errpkt((CHAR *)"Can't open window"); RESUME; } if ((x = sdata()) == -2) { /* File accepted, send first data */ return(success = 0); /* Failed */ } else if (x == -9) { /* User interrupted */ errpkt((CHAR *)"User cancelled"); /* Send Error packet */ window(1); /* Set window size back to 1... */ timint = s_timint; /* Restore timeout */ return(success = 0); /* Failed */ } else if (x == -1) { /* EOF */ window(1); /* put window size back to 1, */ debug(F101,"<ssattr>Y cxseen","",cxseen); if (clsif() < 0) /* Close input file */ cxseen = 1; /* Send EOF packet */ seof(cxseen||czseen); BEGIN sseof; /* and switch to EOF state. */ } else { BEGIN ssdata; /* All ok, switch to send-data state */ } }}<ssdata>q { /* Ctrl-C or connection loss. */ window(1); /* Set window size back to 1... */ cxseen = 1; /* To indicate interruption */ x = clsif(); /* Close file */ return(success = 0); /* Failed */}<ssdata>Y { /* Got ACK to Data packet */ canned(rdatap); /* Check if file transfer cancelled */ if ((x = sdata()) == -2) { /* Try to send next data */ window(1); /* Set window size back to 1... */ x = clsif(); /* Close file */ return(success = 0); /* Failed */ } else if (x == -9) { /* User interrupted */ errpkt((CHAR *)"User cancelled"); /* Send Error packet */ window(1); /* Set window size back to 1... */ timint = s_timint; /* Restore original timeout */ return(success = 0); /* Failed */ } else if (x == -1) { /* EOF - finished sending data */ debug(F101,"<ssdata>Y cxseen","",cxseen); window(1); /* Set window size back to 1... */ if (clsif() < 0) /* Close input file */ cxseen = 1; /* Send EOF packet */ debug(F101,"<ssdata>Y CALLING SEOF()","",cxseen); seof(cxseen||czseen); BEGIN sseof; /* and enter send-eof state */ }}<sseof>Y { /* Got ACK to EOF */ int g; success = (cxseen == 0 && czseen == 0); /* Transfer status... */ if (success && rejection > 0) /* If rejected, succeed if */ if (rejection != '#' && /* reason was date */ rejection != 1 && rejection != '?') /* or name; */ success = 0; /* fail otherwise. */ cxseen = 0; /* This goes back to zero. */ if (success) { /* Only if transfer succeeded... */ if (moving) { /* If MOVE'ing */ tlog(F110," deleting",filnam,0); /* delete the file */ zdelet(filnam); } else if (snd_move) { /* Or move it */ int x; tlog(F110," moving source to",snd_move,0); x = zrename(filnam,snd_move); debug(F111,"send MOVE zrename",snd_move,x); } else if (snd_rename) { /* Or rename it */ char *s = snd_rename; /* Renaming string */#ifndef NOSPL int y; /* Pass it thru the evaluator */ extern int cmd_quoting; /* for \v(filename) */ if (cmd_quoting) { /* But only if cmd_quoting is on */ y = MAXRP; s = (char *)srvcmd; zzstring(snd_rename,&s,&y); s = (char *)srvcmd; }#endif /* NOSPL */ if (s) if (*s) { int x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -