BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / telnet / terminal.c
index 1886941..b5ceeda 100644 (file)
@@ -1,12 +1,38 @@
 /*
 /*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)terminal.c 1.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
 #endif /* not lint */
 
 #include <arpa/telnet.h>
 #endif /* not lint */
 
 #include <arpa/telnet.h>
@@ -17,47 +43,52 @@ static char sccsid[] = "@(#)terminal.c      1.20 (Berkeley) %G%";
 #include "externs.h"
 #include "types.h"
 
 #include "externs.h"
 #include "types.h"
 
-Ring   ttyoring, ttyiring;
-char   ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
+Ring           ttyoring, ttyiring;
+unsigned char  ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
 
 int termdata;                  /* Debugging flag */
 
 #ifdef USE_TERMIO
 # ifndef VDISCARD
 
 int termdata;                  /* Debugging flag */
 
 #ifdef USE_TERMIO
 # ifndef VDISCARD
-char termFlushChar;
+cc_t termFlushChar;
 # endif
 # ifndef VLNEXT
 # endif
 # ifndef VLNEXT
-char termLiteralNextChar;
+cc_t termLiteralNextChar;
 # endif
 # ifndef VSUSP
 # endif
 # ifndef VSUSP
-char termSuspChar;
+cc_t termSuspChar;
 # endif
 # ifndef VWERASE
 # endif
 # ifndef VWERASE
-char termWerasChar;
+cc_t termWerasChar;
 # endif
 # ifndef VREPRINT
 # endif
 # ifndef VREPRINT
-char termRprntChar;
+cc_t termRprntChar;
 # endif
 # ifndef VSTART
 # endif
 # ifndef VSTART
-char termStartChar;
+cc_t termStartChar;
 # endif
 # ifndef VSTOP
 # endif
 # ifndef VSTOP
-char termStopChar;
+cc_t termStopChar;
 # endif
 # ifndef VEOL
 # endif
 # ifndef VEOL
-char termForw1Char;
+cc_t termForw1Char;
 # endif
 # ifndef VEOL2
 # endif
 # ifndef VEOL2
-char termForw2Char;
+cc_t termForw2Char;
+# endif
+# ifndef VSTATUS
+cc_t termAytChar;
 # endif
 #else
 # endif
 #else
-char termForw2Char;
+cc_t termForw2Char;
+cc_t termAytChar;
 #endif
 
 /*
  * initialize the terminal data structures.
  */
 
 #endif
 
 /*
  * initialize the terminal data structures.
  */
 
+    void
 init_terminal()
 {
     if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
 init_terminal()
 {
     if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
@@ -81,9 +112,9 @@ init_terminal()
  */
 
 
  */
 
 
-int
+    int
 ttyflush(drop)
 ttyflush(drop)
-int drop;
+    int drop;
 {
     register int n, n0, n1;
 
 {
     register int n, n0, n1;
 
@@ -109,7 +140,8 @@ int drop;
                n1 = n0 - n;
                if (!drop)
                        n1 = TerminalWrite(ttyoring.bottom, n1);
                n1 = n0 - n;
                if (!drop)
                        n1 = TerminalWrite(ttyoring.bottom, n1);
-               n += n1;
+               if (n1 > 0)
+                       n += n1;
        }
        ring_consumed(&ttyoring, n);
     }
        }
        ring_consumed(&ttyoring, n);
     }
@@ -130,7 +162,7 @@ int drop;
  */
 
 
  */
 
 
-int
+    int
 getconnmode()
 {
     extern int linemode;
 getconnmode()
 {
     extern int linemode;
@@ -170,14 +202,38 @@ getconnmode()
     return(mode);
 }
 
     return(mode);
 }
 
-void
+    void
 setconnmode(force)
 setconnmode(force)
+    int force;
 {
 {
-    TerminalNewMode(getconnmode()|(force?MODE_FORCE:0));
+#ifdef ENCRYPTION
+    static int enc_passwd = 0;
+#endif /* ENCRYPTION */
+    register int newmode;
+
+    newmode = getconnmode()|(force?MODE_FORCE:0);
+
+    TerminalNewMode(newmode);
+
+#ifdef  ENCRYPTION
+    if ((newmode & (MODE_ECHO|MODE_EDIT)) == MODE_EDIT) {
+       if (my_want_state_is_will(TELOPT_ENCRYPT)
+                               && (enc_passwd == 0) && !encrypt_output) {
+           encrypt_request_start(0, 0);
+           enc_passwd = 1;
+       }
+    } else {
+       if (enc_passwd) {
+           encrypt_request_end();
+           enc_passwd = 0;
+       }
+    }
+#endif /* ENCRYPTION */
+
 }
 
 
 }
 
 
-void
+    void
 setcommandmode()
 {
     TerminalNewMode(-1);
 setcommandmode()
 {
     TerminalNewMode(-1);