📄 ckcpro.w
字号:
x = zrename(filnam,s); debug(F111,"send RENAME zrename",snd_rename,x); if (x > -1) tlog(F110," renaming source to",s,0);#ifdef COMMENT *s = NUL;#endif /* COMMENT */ } } } g = gnfile(); debug(F111,"<seof>Y gnfile",filnam,g); if (g > 0) { /* Any more files to send? */ if (sfile(xflg)) /* Yes, try to send next file header */ BEGIN ssfile; /* if ok, enter send-file state */ else { /* otherwise */ s = xflg ? "Can't execute command" : (char *)epktmsg; if (!*s) s = "Can't open file"; errpkt((CHAR *)s); /* send error message */ RESUME; /* and quit */ } } else { /* No next file */ tsecs = gtimer(); /* get statistics timers */#ifdef GFTIMER fptsecs = gftimer();#endif /* GFTIMER */ seot(); /* send EOT packet */ BEGIN sseot; /* enter send-eot state */ }}<sseot>Y { /* Got ACK to EOT */ debug(F101,"sseot justone","",justone); RESUME; /* All done, just quit */}E { /* Got Error packet, in any state */ char *s = ""; window(1); /* Close window */ timint = s_timint; /* Restore original timeout */ if (*epktmsg) /* Message from Error packet */ s = (char *)epktmsg; if (!*s) { /* If not there then maybe here */ s = (char *)rdatap; ckstrncpy((char *)epktmsg,(char *)rdatap,PKTMSGLEN); } if (!*s) /* Hopefully we'll never see this. */ s = "Unknown error"; success = 0; /* For IF SUCCESS/FAIL. */ debug(F101,"ckcpro.w justone at E pkt","",justone); x = quiet; quiet = 1; /* Close files silently, */ epktrcvd = 1; /* Prevent messages from clsof() */ clsif(); clsof(1); /* discarding any output file. */ success = 0; /* Transfer failed */ xferstat = success; /* Remember transfer status */ ermsg(s); /* Issue the message (calls screen). */ tstats(); /* Get stats */ quiet = x; /* Restore quiet state *//* If we are executing commands from a command file or macro, let the command file or macro decide whether to exit, based on SET { TAKE, MACRO } ERROR.*/ if (#ifndef NOICP !cmdsrc() &&#endif /* NOICP */ backgrd && !server) fatal("Protocol error"); xitsta |= what; /* Save this for doexit(). */#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 E tmpdir restored",savdir,x); }#endif /* CK_TMPDIR */#ifdef IKSDB if (ikdbopen) slotstate(what,"ERROR", (char *)epktmsg, "");#endif /* IKSDB */ RESUME;}q { success = 0; QUIT; } /* Ctrl-C or connection loss. */. { /* Anything not accounted for above */ errpkt((CHAR *)"Unexpected packet type"); /* Give error message */ window(1); xitsta |= what; /* Save this for doexit(). */ RESUME; /* and quit */}%%/* From here down to proto() are routines that were moved out of the state table switcher because the resulting switch() had become too large. To move the contents of a state-table case to a routine: 1. Add a prototype to the list above the state table switcher. 2. Make a routine with an appropriate name, returning int. 3. Move the code into it. 4. Put a call to the new routine in the former spot: rc = name_of_routine(); if (rc > -1) return(rc); 5. Add "return(-1);" after every RESUME, SERVE, or BEGIN macro and at the end if the code is open-ended.*/static intrcv_firstdata() { if (discard) { /* if we're discarding the file */ ack1((CHAR *)"X"); /* just ack the data like this. */ cancel++; /* and count it */ BEGIN rdpkt; /* and wait for more data packets. */ return(-1); } else { /* Not discarding. */ rf_err = "Can't open file"; 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 */ } } else { /* otherwise */#ifdef CALIBRATE if (calibrate) { /* If calibration run */ x = ckopenx(&iattr); /* open nothing */#ifdef STREAMING if (streaming) /* Streaming */ fastack(); /* ACK without ACKing. */ else#endif /* STREAMING */ ack(); /* Send real ACK */ BEGIN rdpkt; /* Proceed to next state */ return(-1); } else#endif /* CALIBRATE */#ifdef UNIX/* In UNIX we can pipe the file data into the mail program, which is to be preferred to writing it out to a temp file and then mailing it afterwards. This depends rather heavily on all UNIXes having a mail command that accepts '-s "subject"' on the command line. MAILCMD (e.g. mail, Mail, mailx) is defined in ckufio.c.*/ if (*(iattr.disp.val) == 'M') { char *s; char tmp[1024]; extern char *MAILCMD; s = iattr.disp.val + 1; sprintf(tmp,"%s -s %c%s%c %s", MAILCMD, '"', ofn1, '"', s); x = openc(ZOFILE,(char *)tmp); } else if (*(iattr.disp.val) == 'P') { /* Ditto for print */ char tmp[1024]; extern char *PRINTCMD; sprintf(tmp,"%s %s", PRINTCMD, iattr.disp.val + 1); x = openc(ZOFILE,(char *)tmp); } else#endif /* UNIX */ x = opena(filnam,&iattr); /* open the file, with attributes */ } if (x) { /* If file was opened ok */ 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) { errpkt((CHAR *)"Error writing data"); RESUME; return(-1); }#ifdef STREAMING if (streaming) /* Streaming was negotiated */ fastack(); /* ACK without ACKing. */ else#endif /* STREAMING */ ack(); /* acknowledge it */ BEGIN rdpkt; /* and switch to receive-data state */ return(-1); } else { /* otherwise */ errpkt((CHAR *) rf_err); /* send error packet */ RESUME; /* and quit. */ return(-1); } }}static intrcv_shortreply() {#ifdef PKTZEROHACK success = 0; debug(F111,"rcv_shortreply",rdatap,ipktlen); if (!strncmp(ipktack,(char *)rdatap,ipktlen)) { /* No it's the ACK to the I packet again */ x = scmd(vcmd,(CHAR *)cmarg); /* So send the REMOTE command again */ /* Maybe this should be resend() */ debug(F110,"IPKTZEROHACK",ipktack,x); if (x < 0) { errpkt((CHAR *)srimsg); RESUME; return(-1); } } else { ipktack[0] = NUL;#endif /* PKTZEROHACK */ urserver = 1;#ifndef NOSERVER#ifndef NOSPL if (query) { /* If to query, */ qbufp = querybuf; /* initialize query response buffer */ qbufn = 0; querybuf[0] = NUL; }#endif /* NOSPL */ x = 1; if (remfile) { /* Response redirected to file */ rf_err = "Can't open file"; if (rempipe) /* or pipe */ x =#ifndef NOPUSH zxcmd(ZOFILE,remdest) /* Pipe: Start command */#else 0#endif /* NOPUSH */ ; else x = opena(remdest,&iattr); /* File: Open with attributes */ debug(F111,"rcv_shortreply remfile",remdest,x); } else { x = opent(&iattr); /* "open" the screen */ } if (x) { /* If file was opened ok */ if (decode(rdatap,#ifndef NOSPL (query || !remfile) ? puttrm :#else !remfile ? puttrm :#endif /* NOSPL */ zputfil, 1) < 0) { /* Note: zputfil, not putfil. */ errpkt((CHAR *)"Error writing data"); RESUME; return(-1); } else { if (rdatap) /* If we had data */ if (*rdatap) /* add a line terminator */ if (remfile) { /* to file */ zsoutl(ZOFILE,""); } else { /* or to screen. */#ifndef NOICP if (!query || !cmdsrc())#endif /* NOICP */ conoll(""); } if (bye_active && network) { /* I sent BYE or REMOTE LOGOUT */ msleep(500); /* command and got the ACK... */ bye_active = 0; ttclos(0); } clsof(0); if (!epktsent && !epktrcvd) /* If no error packet... */ success = 1; /* success. */ RESUME; return(-1); } } else { /* File not opened OK */ errpkt((CHAR *) rf_err); /* send error message */ RESUME; /* and quit. */ return(-1); }#endif /* NOSERVER */#ifdef PKTZEROHACK }#endif /* PKTZEROHACK */ debug(F101,"rcv_shortreply fallthru","",success); return(-1);}static intsrv_query() {#ifndef NOSERVER#ifndef NOSPL char c;#ifdef CKSYSLOG if (ckxsyslog >= SYSLG_PR && ckxlogging) cksyslog(SYSLG_PR, 1, "server", "REMOTE QUERY", (char *)srvcmd);#endif /* CKSYSLOG */#ifdef IKSDB if (ikdbopen) slotstate(what,"REMOTE QUERY", (char *)(srvcmd+2), "");#endif /* IKSDB */ c = *(srvcmd+2); /* Q = Query, S = Set */ if (c == 'Q') { /* Query */ if (!ENABLED(en_que)) { /* Security */ errpkt((CHAR *)"REMOTE QUERY disabled"); RESUME; return(-1); } else { /* Query allowed */ int n; char *p, *q; qbufp = querybuf; /* Wipe out old stuff */ qbufn = 0; querybuf[0] = NUL; p = (char *) srvcmd + 3; /* Pointer for making wrapper */ n = strlen((char *)srvcmd); /* Position of end */ c = *(srvcmd+4); /* Which type of variable */ if (*(srvcmd+6) == CMDQ) { /* Starts with command quote? */ p = (char *) srvcmd + 6; /* Take it literally */ if (*p == CMDQ) p++; } else { /* They played by the rules */ if (c == 'K') { /* Kermit variable */ int k; k = (int) strlen(p); if (k > 0 && p[k-1] == ')') { p = (char *)(srvcmd + 4); *(srvcmd+4) = CMDQ; *(srvcmd+5) = 'f'; /* Function, so make it \f...() */ } else { *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */ *(srvcmd+4) = 'v'; /* Variable, so make it \v(...) */ *(srvcmd+5) = '('; /* around variable name */ *(srvcmd+n) = ')'; *(srvcmd+n+1) = NUL; } } else { *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */ *(srvcmd+4) = 'v'; /* Variable, so make it \v(...) */ *(srvcmd+5) = '('; /* around variable name */ *(srvcmd+n) = ')'; *(srvcmd+n+1) = NUL; if (c == 'S') { /* System variable */ *(srvcmd+4) = '$'; /* so it's \$(...) */ } else if (c == 'G') { /* Non-\ Global variable */ *(srvcmd+4) = 'm'; /* so wrap it in \m(...) */ } } } /* Now evaluate it */ n = QBUFL; /* Max length */ q = querybuf; /* Where to put it */ if (zzstring(p,&q,&n) < 0) { errpkt((n > 0) ? (CHAR *)"Can't get value" : (CHAR *)"Value too long" ); RESUME; return(-1); } else { if (encstr((CHAR *)querybuf) > -1) { /* Encode it */ ack1(data); /* If it fits, send it back in ACK */ success = 1; RESUME; return(-1); } else if (sndstring(querybuf)) { /* Long form response */ BEGIN ssinit; return(-1); } else { /* sndhlp() fails */ errpkt((CHAR *)"Can't send value"); RESUME; return(-1); } } } } else if (c == 'S') { /* Set (assign) */ if (!ENABLED(en_asg)) { /* Security */ errpkt((CHAR *)"REMOTE ASSIGN disabled"); RESUME; return(-1); } else { /* OK */ int n; n = xunchar(*(srvcmd+3)); /* Length of name */ n = 3 + n + 1; /* Position of length of value */ *(srvcmd+n) = NUL; /* Don't need it */ if (addmac((char *)(srvcmd+4),(char *)(srvcmd+n+1)) < 0) errpkt((CHAR *)"REMOTE ASSIGN failed"); else { ack(); success = 1; } RESUME; return(-1); } } else { errpkt((CHAR *)"Badly formed server command"); RESUME; return(-1); }#else errpkt((CHAR *)"Variable query/set not available"); RESUME; return(-1);#endif /* NOSPL */#endif /* NOSERVER */}static intsrv_copy() {#ifndef NOSERVER#ifdef CKSYSLOG if (ckxsyslog >= SYSLG_PR && ckxlogging) cksyslog(SYSLG_PR, 1, "server", "REMOTE COPY", (char *)srvcmd);#endif /* CKSYSLOG */#ifdef ZCOPY if (!ENABLED(en_cpy)) { errpkt((CHAR *)"REMOTE COPY disabled"); RESUME; return(-1); } else { char *str1, *str2, f1[256], f2[256]; int len1, len2; len1 = xunchar(srvcmd[1]); /* Separate the parameters */ len2 = xunchar(srvcmd[2+len1]); strncpy(f1,(char *)(srvcmd+2),len1); f1[len1] = NUL; strncpy(f2,(char *)(srvcmd+3+len1),len2); f2[len2] = NUL;#ifdef IKSDB if (ikdbopen) slotstate(what,"REMOTE COPY", f1, f2);#endif /* IKSDB */ if (!ENABLED(en_cwd)) { /* If CWD is disabled */ zstrip(f1,&str1); /* and they included a pathname, */ zstrip(f2,&str2); if (strcmp(f1,str1) || strcmp(f2,str2)) { /* Refuse. */ errpkt((CHAR *)"Access denied"); RESUME; /* Remember, this is not a goto! */ return(-1); } } if (state == generic) { /* It's OK to go ahead. */ if (zcopy(f1,f2)) { /* Try */ errpkt((CHAR *)"Can't copy file"); /* give error message */ } e
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -