BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / telnet / terminal.c
index 559ad97..7b23409 100644 (file)
@@ -1,24 +1,38 @@
 /*
 /*
- * Copyright (c) 1988 Regents of the University of California.
+ * Copyright (c) 1988, 1990 Regents of the University of California.
  * All rights reserved.
  *
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.21 (Berkeley) 6/28/90";
+static char sccsid[] = "@(#)terminal.c 5.3 (Berkeley) 3/22/91";
 #endif /* not lint */
 
 #include <arpa/telnet.h>
 #endif /* not lint */
 
 #include <arpa/telnet.h>
@@ -29,13 +43,13 @@ static char sccsid[] = "@(#)terminal.c      1.21 (Berkeley) 6/28/90";
 #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
 
 int termdata;                  /* Debugging flag */
 
 #ifdef USE_TERMIO
-# ifndef VFLUSHO
+# ifndef VDISCARD
 cc_t termFlushChar;
 # endif
 # ifndef VLNEXT
 cc_t termFlushChar;
 # endif
 # ifndef VLNEXT
@@ -62,14 +76,19 @@ cc_t termForw1Char;
 # ifndef VEOL2
 cc_t termForw2Char;
 # endif
 # ifndef VEOL2
 cc_t termForw2Char;
 # endif
+# ifndef VSTATUS
+cc_t termAytChar;
+# endif
 #else
 cc_t termForw2Char;
 #else
 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) {
@@ -93,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;
 
@@ -142,7 +161,7 @@ int drop;
  */
 
 
  */
 
 
-int
+    int
 getconnmode()
 {
     extern int linemode;
 getconnmode()
 {
     extern int linemode;
@@ -182,14 +201,38 @@ getconnmode()
     return(mode);
 }
 
     return(mode);
 }
 
-void
+    void
 setconnmode(force)
 setconnmode(force)
+    int force;
 {
 {
-    TerminalNewMode(getconnmode()|(force?MODE_FORCE:0));
+#ifdef ENCRYPT
+    static int enc_passwd = 0;
+#endif
+    register int newmode;
+
+    newmode = getconnmode()|(force?MODE_FORCE:0);
+
+    TerminalNewMode(newmode);
+
+#ifdef  ENCRYPT
+    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
+
 }
 
 
 }
 
 
-void
+    void
 setcommandmode()
 {
     TerminalNewMode(-1);
 setcommandmode()
 {
     TerminalNewMode(-1);