📄 ckucon.c
字号:
/* NOTREACHED */ } else continue; /* Negotiation OK, get next char. */ } else if (parity) c &= 0x7f; if (TELOPT_ME(TELOPT_ECHO) && tn_rem_echo) ttoc(c); /* I'm echoing for the remote */#endif /* TNCODE */ if (debses) { /* Output character to screen */ char *s; /* Debugging display... */ s = dbchr(c); while (*s) ckcputc(*s++); } else { /* Regular display ... */ c &= cmask; /* Apply Kermit-to-remote mask */#ifdef CK_AUTODL/* Autodownload. Check for Kermit S packet prior to translation, since that can change the packet and make it unrecognizable (as when the terminal character set is an ISO 646 one)... Ditto for Zmodem start packet.*/ if (autodl /* Autodownload enabled? */#ifdef IKS_OPTION || TELOPT_SB(TELOPT_KERMIT).kermit.me_start#endif /* IKS_OPTION */ ) { int k; k = kstart((CHAR)c); /* Kermit S or I packet? */#ifdef CK_XYZ if (!k && zmdlok) /* Or an "sz" start? */ k = zstart((CHAR)c);#endif /* CK_XYZ */ if (k) { int ksign = 0; debug(F101,"CONNECT autodownload k","",k); if (k < 0) { /* Minus-Protocol? */#ifdef NOSERVER goto noserver; /* Need server mode for this */#else ksign = 1; /* Remember */ k = 0 - k; /* Convert to actual protocol */ justone = 1; /* Flag for protocol module */#endif /* NOSERVER */ } else justone = 0; k--; /* Adjust [kz]start's return value */ if (k == PROTO_K#ifdef CK_XYZ || k == PROTO_Z#endif /* CK_XYZ */ ) { /* Now damage the packet so that it does not */ /* trigger autodownload detection on subsquent */ /* links. */ if (k == PROTO_K) { int i, len = strlen((char*)ksbuf); for (i = 0; i < len; i++) ckcputc(BS); }#ifdef CK_XYZ else { int i; for (i = 0; i < 3; i++) ckcputc(CAN); }#endif /* CK_XYZ */ /* Notify parent */ pipemsg(justone ? CEV_AUL : CEV_ADL);/* Send our memory back up to the top fork thru the pipe. CAREFUL -- Write this stuff in the same order it is to be read!*/ /* Copy our Kermit packet to the parent fork */ n = (int) strlen((char *)ksbuf); write(xpipe[1], (char *)&n, sizeof(n)); if (n > 0) write(xpipe[1], (char *)ksbuf, n+1); debug(F111,"CONNECT autodownload ksbuf",ksbuf,n); debug(F101,"CONNECT autodownload justone","", justone); /* Construct the APC command */ sprintf(apcbuf, "set proto %s, %s, set proto %s", ptab[k].p_name, ksign ? "server" : "receive", ptab[protocol].p_name ); apclength = strlen(apcbuf); debug(F111,"CONNECT ksbuf",ksbuf,k); debug(F110,"CONNECT autodownload",apcbuf,0); apcactive = APC_LOCAL; ckcputf(); /* Force screen update */ /* Write buffer including trailing NUL byte */ debug(F101,"CONNECT write xpipe apclength","", apclength); write(xpipe[1], (char *)&apclength, sizeof(apclength) ); debug(F110,"CONNECT write xpipe apcbuf",apcbuf,0); write(xpipe[1], apcbuf, apclength+1); /* Copy our input buffer to the parent fork */ debug(F101,"CONNECT autodownload complete ibc", "",ibc); debug(F101,"CONNECT autodownload complete obc", "",obc); write(xpipe[1], (char *)&ibc, sizeof(ibc)); if (ibc > 0) { write(xpipe[1], (char *)&ibp, sizeof(ibp)); write(xpipe[1], ibp, ibc); } ck_sndmsg(); /* Wait to be killed */ /* NOTREACHED */ } } }#ifdef NOSERVER noserver:#endif /* NOSERVER */#endif /* CK_AUTODL */ if (sosi) { /* Handle SI/SO */ if (c == SO) { /* Shift Out */ inshift = 1; continue; } else if (c == SI) { /* Shift In */ inshift = 0; continue; } if (inshift) c |= 0200; } inxbuf[0] = c; /* In case there is no translation */ inxcount = 1; /* ... */#ifndef NOCSETS if (inesc == ES_NORMAL) { /* If not in an escape sequence */#ifdef UNICODE int x; /* Translate character sets */ CHAR ch; ch = c; if (unicode == 1) { /* Remote is UTF-8 */ x = u_to_b(ch); if (x < 0) continue; inxbuf[0] = (unsigned)(x & 0xff); c = inxbuf[0]; } else if (unicode == 2) { /* Local is UTF-8 */ inxcount = b_to_u(ch,inxbuf,OUTXBUFSIZ,tcssize); c = inxbuf[0]; } else {#endif /* UNICODE */ if (sxi) c = (*sxi)((CHAR)c); if (rxi) c = (*rxi)((CHAR)c); inxbuf[0] = c;#ifdef UNICODE }#endif /* UNICODE */ }#endif /* NOCSETS */#ifndef NOESCSEQ if (escseq) /* If handling escape sequences */ apcrc = chkaes((char)c); /* update our state */#ifdef CK_APC/* If we are handling APCs, we have several possibilities at this point: 1. Ordinary character to be written to the screen. 2. An Esc; we can't write it because it might be the beginning of an APC. 3. The character following an Esc, in which case we write Esc, then char, but only if we have not just entered an APC sequence.*/ if (escseq && (apcstatus & APC_ON)) { if (inesc == ES_GOTESC) /* Don't write ESC yet */ continue; else if (oldesc == ES_GOTESC && !apcactive) { ckcputc(ESC); /* Write saved ESC */ if (seslog && !sessft) logchar((char)ESC); } else if (apcrc) { /* We have an APC */ debug(F111,"CONNECT APC complete",apcbuf,apclength); ckcputf(); /* Force screen update */ pipemsg(CEV_APC); /* Notify parent */ write(xpipe[1], (char *)&apclength, sizeof(apclength) ); /* Write buffer including trailing NUL byte */ write(xpipe[1], apcbuf, apclength+1); /* Copy our input buffer to the parent fork */ debug(F101,"CONNECT APC complete ibc","",ibc); debug(F101,"CONNECT APC complete obc","",obc); write(xpipe[1], (char *)&ibc, sizeof(ibc)); if (ibc > 0) { write(xpipe[1], (char *)&ibp, sizeof(ibp)); write(xpipe[1], ibp, ibc); } ck_sndmsg(); /* Wait to be killed */ /* NOTREACHED */ } }#endif /* CK_APC */#endif /* NOESCSEQ */ for (i = 0; i < inxcount; i++) { /* Loop thru */ c = inxbuf[i]; /* input expansion buffer... */ if (#ifdef CK_APC !apcactive /* Ignore APC sequences */#else 1#endif /* CK_APC */ ) { c &= cmdmsk; /* Apply command mask. */ if (c == CR && tt_crd) { /* SET TERM CR-DISPLA CRLF? */ ckcputc(c); /* Yes, output CR */ if (seslog && !sessft) logchar((char)c); c = LF; /* and insert a linefeed */ } ckcputc(c); /* Write character to screen */ } if (seslog && !sessft) /* Handle session log */ logchar((char)c);#ifdef CK_TRIGGER /* Check for trigger string */ if (tt_trigger[0]) if ((ix = autoexitchk((CHAR)c)) > -1) { ckcputf(); /* Force screen update */#ifdef NOSETBUF fflush(stdout); /* I mean really force it */#endif /* NOSETBUF */ pipemsg(CEV_TRI); /* Send up trigger indication */ write(xpipe[1], (char *)&ix, sizeof(ix)); /* index */ write(xpipe[1], (char *)&ibc, sizeof(ibc)); if (ibc > 0) { write(xpipe[1], (char *)&ibp, sizeof(ibp)); write(xpipe[1], ibp, ibc); } debug(F100,"CONNECT concld trigger","",0); ck_sndmsg(); /* Wait to be killed */ active = 0; /* Shouldn't be necessary... */ break; } /* NOTREACHED */#endif /* CK_TRIGGER */ } }#ifdef ANYX25 }#endif /* ANYX25 */ }}/* C O N E C T -- Interactive terminal connection */intconect() { int n; /* General purpose counter */ int i; /* For loops... */ int c; /* c is a character, but must be signed integer to pass thru -1, which is the modem disconnection signal, and is different from the character 0377 */ int c2; /* A copy of c */ int csave; /* Another copy of c */#ifndef NOESCSEQ int apcrc;#endif /* NOESCSEQ */ int conret = 0; /* Return value from conect() */ int msgflg = 0; /* jbchksum = -1L; */ jbset = 0; /* jmp_buf not set yet, don't use it */ debok = 1; debug(F101,"CONNECT fork signal","",CK_FORK_SIG); debug(F101,"CONNECT entry pid","",pid); msgflg = !quiet#ifdef CK_APC && !apcactive#endif /* CK_APC */ ;/* The following is to handle a fork left behind if we exit CONNECT mode without killing it, and then return to CONNECT mode. This happened in HP-UX, where the Reset key would raise SIGINT even though SIGINT was set to SIG_IGN. The code below fixes the symptom; the real fix is in the main SIGINT handler (if SIGINT shows up during CONNECT, just return rather than taking the longjmp).*/ if (pid) { /* This should be 0 */ int x = 0; debug(F101,"CONNECT entry killing stale pid","",pid); printf("WARNING: Old CONNECT fork seems to be active.\n"); printf("Attempting to remove it...");#ifdef BEOSORBEBOX { long ret_val; x = kill(pid,SIGKILLTHR); /* Kill lower fork */ wait_for_thread (pid, &ret_val); }#else#ifdef Plan9 x = kill(pid,SIGKILL); /* Kill lower fork */#else x = kill(pid,9);#endif /* Plan9 */#endif /* BEOSORBEBOX */ wait((WAIT_T *)0); /* Wait till gone. */ if (x < 0) { printf("ERROR: Failure to kill pid %d: %s, errno=%d\n", (int) pid, ck_errstr(), errno); debug(F111,"CONNECT error killing stale pid",ck_errstr(),pid); } pid = (PID_T) 0; printf("\n"); } signal(CK_FORK_SIG, SIG_IGN); /* Initial CK_FORK_SIG handling, *//* The following ttimoff() call should not be necessary, but evidently there are cases where a timer is left active and then goes off, taking a longjmp to nowhere after the program's stack has changed. In any case, this is safe because the CONNECT module uses no timer of any kind, and no other timer should be armed while Kermit is in CONNECT mode.*/ ttimoff(); /* Turn off any timer interrupts */#ifdef CK_TRIGGER makestr(&triggerval,NULL); /* Reset trigger */#endif /* CK_TRIGGER */ if (!local) {#ifdef NETCONN printf("Sorry, you must SET LINE or SET HOST first\n");#else printf("Sorry, you must SET LINE first\n");#endif /* NETCONN */ goto conret0; } if (speed < 0L && network == 0 && ttfdflg == 0) { printf("Sorry, you must SET SPEED first\n"); goto conret0; }#ifdef TCPSOCKET if (network && (nettype != NET_TCPB)#ifdef SUNX25 && (nettype != NET_SX25)#endif /* SUNX25 */#ifdef IBMX25 && (nettype != NET_IX25)#endif /* IBMX25 */#ifdef NETCMD && (nettype != NET_CMD)#endif /* NETCMD */#ifdef NETPTY && (nettype != NET_PTY)#endif /* NETPTY */ ) { printf("Sorry, network type not supported\n"); goto conret0; }#endif /* TCPSOCKET */#ifdef DYNAMIC if (!ibuf) { if (!(ibuf = malloc(IBUFL+1))) { /* Allocate input line buffer */ printf("Sorry, CONNECT input buffer can't be allocated\n"); goto conret0; } else { ibp = ibuf; ibc = 0; } } if (!obuf) { if (!(obuf = malloc(OBUFL+1))) { /* Allocate output line buffer */ printf("Sorry, CONNECT output buffer can't be allocated\n"); goto conret0; } else { obp = obuf; obc = 0; } } if (!kbuf) { if (!(kbuf = malloc(KBUFL+1))) { /* Allocate keyboard input buffer */ printf("Sorry, CONNECT keyboard buffer can't be allocated\n"); goto conret0; } } if (!temp) { if (!(temp = malloc(TMPLEN+1))) { /* Allocate temporary buffer */ printf("Sorry, CONNECT temporary buffer can't be allocated\n"); goto conret0; } }#else#ifdef COMMENT ibp = ibuf; ibc = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -