Bug fixes to the state machine
authorPaul Borman <borman@ucbvax.Berkeley.EDU>
Wed, 15 Nov 1989 02:43:55 +0000 (18:43 -0800)
committerPaul Borman <borman@ucbvax.Berkeley.EDU>
Wed, 15 Nov 1989 02:43:55 +0000 (18:43 -0800)
SCCS-vsn: libexec/telnetd/ext.h 5.3
SCCS-vsn: libexec/telnetd/state.c 5.4
SCCS-vsn: libexec/telnetd/telnetd.c 5.41
SCCS-vsn: libexec/telnetd/termstat.c 5.3

usr/src/libexec/telnetd/ext.h
usr/src/libexec/telnetd/state.c
usr/src/libexec/telnetd/telnetd.c
usr/src/libexec/telnetd/termstat.c

index 047ac12..f7b7854 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)ext.h       5.2 (Berkeley) %G%
+ *     @(#)ext.h       5.3 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -54,6 +54,11 @@ extern char  *neturg;                /* one past last bye of urgent data */
 
 extern int     pcc, ncc;
 
 
 extern int     pcc, ncc;
 
+#ifdef CRAY2
+extern int unpcc;  /* characters left unprocessed by CRAY-2 terminal routine */
+extern char *unptyip;  /* pointer to remaining characters in buffer */
+#endif
+
 extern int     pty, net;
 extern char    *line;
 extern int     SYNCHing;               /* we are in TELNET SYNCH mode */
 extern int     pty, net;
 extern char    *line;
 extern int     SYNCHing;               /* we are in TELNET SYNCH mode */
index 0078859..edb6436 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)state.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)state.c    5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -381,7 +381,15 @@ send_do(option, init)
                if ((do_dont_resp[option] == 0 && hisopts[option] == OPT_YES) ||
                    hiswants[option] == OPT_YES)
                        return;
                if ((do_dont_resp[option] == 0 && hisopts[option] == OPT_YES) ||
                    hiswants[option] == OPT_YES)
                        return;
-               hiswants[option] = OPT_YES;
+               /*
+                * Special case for TELOPT_TM:  We send a DO, but pretend
+                * that we sent a DONT, so that we can send more DOs if
+                * we want to.
+                */
+               if (option == TELOPT_TM)
+                       hiswants[option] = OPT_NO;
+               else
+                       hiswants[option] = OPT_YES;
                do_dont_resp[option]++;
        }
        (void) sprintf(nfrontp, doopt, option);
                do_dont_resp[option]++;
        }
        (void) sprintf(nfrontp, doopt, option);
@@ -402,7 +410,8 @@ willoption(option)
                if (do_dont_resp[option] && hisopts[option] == OPT_YES)
                        do_dont_resp[option]--;
        }
                if (do_dont_resp[option] && hisopts[option] == OPT_YES)
                        do_dont_resp[option]--;
        }
-       if ((do_dont_resp[option] == 0) && (hiswants[option] != OPT_YES)) {
+       if (do_dont_resp[option] == 0) {
+           if (hiswants[option] != OPT_YES) {
                switch (option) {
 
                case TELOPT_BINARY:
                switch (option) {
 
                case TELOPT_BINARY:
@@ -478,10 +487,9 @@ willoption(option)
                        }
 #endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
                        /*
                        }
 #endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
                        /*
-                        * Cheat the state machine so that it
-                        * looks like we got back a WONT.
+                        * We never respond to a WILL TM, and
+                        * we leave the state OPT_NO.
                         */
                         */
-                       hiswants[TELOPT_TM] = OPT_NO;
                        return;
 
                case TELOPT_LFLOW:
                        return;
 
                case TELOPT_LFLOW:
@@ -498,11 +506,21 @@ willoption(option)
                case TELOPT_SGA:
                case TELOPT_NAWS:
                case TELOPT_TSPEED:
                case TELOPT_SGA:
                case TELOPT_NAWS:
                case TELOPT_TSPEED:
+                       changeok++;
+                       break;
+
 #ifdef LINEMODE
                case TELOPT_LINEMODE:
 #ifdef LINEMODE
                case TELOPT_LINEMODE:
-#endif LINEMODE
+# ifdef        KLUDGELINEMODE
+                       /*
+                        * Note client's desire to use linemode.
+                        */
+                       lmodetype = REAL_LINEMODE;
+# endif        /* KLUDGELINEMODE */
+                       clientstat(TELOPT_LINEMODE, WILL, 0);
                        changeok++;
                        break;
                        changeok++;
                        break;
+#endif /* LINEMODE */
 
                default:
                        break;
 
                default:
                        break;
@@ -514,29 +532,9 @@ willoption(option)
                        do_dont_resp[option]++;
                        send_dont(option, 0);
                }
                        do_dont_resp[option]++;
                        send_dont(option, 0);
                }
+           }
        }
        hisopts[option] = OPT_YES;
        }
        hisopts[option] = OPT_YES;
-
-       /*
-        * Handle other processing that should occur after we have
-        * responded to client input.
-        */
-       switch (option) {
-#ifdef LINEMODE
-       case TELOPT_LINEMODE:
-# ifdef        KLUDGELINEMODE
-               /*
-                * Note client's desire to use linemode.
-                */
-               lmodetype = REAL_LINEMODE;
-# endif        /* KLUDGELINEMODE */
-               clientstat(TELOPT_LINEMODE, WILL, 0);
-               break;
-#endif LINEMODE
-       
-       default:
-               break;
-       }
 }  /* end of willoption */
 
 send_dont(option, init)
 }  /* end of willoption */
 
 send_dont(option, init)
@@ -567,7 +565,8 @@ wontoption(option)
                if (do_dont_resp[option] && hisopts[option] == OPT_NO)
                        do_dont_resp[option]--;
        }
                if (do_dont_resp[option] && hisopts[option] == OPT_NO)
                        do_dont_resp[option]--;
        }
-       if ((do_dont_resp[option] == 0) && (hiswants[option] != OPT_NO)) {
+       if (do_dont_resp[option] == 0) {
+           if (hiswants[option] != OPT_NO) {
                /* it is always ok to change to negative state */
                switch (option) {
                case TELOPT_ECHO:
                /* it is always ok to change to negative state */
                switch (option) {
                case TELOPT_ECHO:
@@ -594,27 +593,13 @@ wontoption(option)
 #endif LINEMODE
 
                case TELOPT_TM:
 #endif LINEMODE
 
                case TELOPT_TM:
-#if    defined(LINEMODE) && defined(KLUDGELINEMODE)
-                       if (lmodetype < REAL_LINEMODE) {
-                               lmodetype = NO_LINEMODE;
-                               clientstat(TELOPT_LINEMODE, WONT, 0);
-                               send_will(TELOPT_SGA, 1);
-/*@*/                          send_will(TELOPT_ECHO, 1);
-                       }
-#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
                        /*
                         * If we get a WONT TM, and had sent a DO TM,
                         * don't respond with a DONT TM, just leave it
                         * as is.  Short circut the state machine to
                        /*
                         * If we get a WONT TM, and had sent a DO TM,
                         * don't respond with a DONT TM, just leave it
                         * as is.  Short circut the state machine to
-                        * achive this. The bad part of this is that if
-                        * the client sends a WONT TM on his own to
-                        * turn off linemode, then he won't get a
-                        * response.
+                        * achive this.
                         */
                        hiswants[TELOPT_TM] = OPT_NO;
                         */
                        hiswants[TELOPT_TM] = OPT_NO;
-#ifdef notdef
-                       do_dont_resp[TELOPT_TM]--;
-#endif
                        return;
 
                case TELOPT_LFLOW:
                        return;
 
                case TELOPT_LFLOW:
@@ -635,11 +620,21 @@ wontoption(option)
                hiswants[option] = OPT_NO;
                fmt = dont;
                send_dont(option, 0);
                hiswants[option] = OPT_NO;
                fmt = dont;
                send_dont(option, 0);
-       } else if (option == TELOPT_TM) {
-               /*
-                * Special case for TM.
-                */
-               hiswants[option] = OPT_NO;
+           } else {
+               switch (option) {
+               case TELOPT_TM:
+#if    defined(LINEMODE) && defined(KLUDGELINEMODE)
+                       if (lmodetype < REAL_LINEMODE) {
+                               lmodetype = NO_LINEMODE;
+                               clientstat(TELOPT_LINEMODE, WONT, 0);
+                               send_will(TELOPT_SGA, 1);
+/*@*/                          send_will(TELOPT_ECHO, 1);
+                       }
+#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
+               default:
+                       break;
+               }
+           }
        }
        hisopts[option] = OPT_NO;
 
        }
        hisopts[option] = OPT_NO;
 
index 0f199b5..9bca18d 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)telnetd.c  5.40 (Berkeley) %G%";
+static char sccsid[] = "@(#)telnetd.c  5.41 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -698,8 +698,10 @@ int f, p;
                                ptyip = ptyibuf+1;
 #else  /* CRAY2 */
                                if (!uselinemode) {
                                ptyip = ptyibuf+1;
 #else  /* CRAY2 */
                                if (!uselinemode) {
-                                       pcc = term_output(ptyibuf, ptyibuf2,
-                                                               pcc, BUFSIZ);
+                                       unpcc = pcc;
+                                       unptyip = ptyibuf;
+                                       pcc = term_output(&unptyip, ptyibuf2,
+                                                               &unpcc, BUFSIZ);
                                        ptyip = ptyibuf2;
                                } else
                                        ptyip = ptyibuf;
                                        ptyip = ptyibuf2;
                                } else
                                        ptyip = ptyibuf;
@@ -727,6 +729,18 @@ int f, p;
                                        *nfrontp++ = '\0';
                        }
                }
                                        *nfrontp++ = '\0';
                        }
                }
+#ifdef CRAY2
+               /*
+                * If chars were left over from the terminal driver,
+                * note their existence.
+                */
+                if (!uselinemode && unpcc) {
+                       pcc = unpcc;
+                       unpcc = 0;
+                       ptyip = unptyip;
+               }
+#endif /* CRAY2 */
+
                if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
                        netflush();
                if (ncc > 0)
                if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
                        netflush();
                if (ncc > 0)
index 683e4db..ddadde1 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)termstat.c 5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)termstat.c 5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "telnetd.h"
 #endif /* not lint */
 
 #include "telnetd.h"
@@ -205,7 +205,7 @@ localstat()
                        send_dont(TELOPT_LINEMODE, 1);
 # ifdef        KLUDGELINEMODE
                else if (lmodetype == KLUDGE_LINEMODE)
                        send_dont(TELOPT_LINEMODE, 1);
 # ifdef        KLUDGELINEMODE
                else if (lmodetype == KLUDGE_LINEMODE)
-                       send_wont(TELOPT_SGA, 1);
+                       send_will(TELOPT_SGA, 1);
 # endif        /* KLUDGELINEMODE */
                linemode = uselinemode;
                goto done;
 # endif        /* KLUDGELINEMODE */
                linemode = uselinemode;
                goto done;