jcs
/subtext
/amendments
/154
telnet: Implement auto-enabling of vt100 attr based on TTYPE received
jcs made amendment 154 over 2 years ago
--- telnet.c Fri Jun 17 13:39:41 2022
+++ telnet.c Fri Jun 17 14:47:24 2022
@@ -118,6 +118,17 @@ static bool did_initial_log = false;
#define MAX_BANNED_IPS 25
static ip_addr banned_ips[MAX_BANNED_IPS] = { 0 };
+/* terminals that will have vt100 set by default */
+static const char * vt100_terms[] = {
+ "ansi",
+ "syncterm",
+ "xterm",
+ "tmux",
+ "screen",
+ "vt100",
+ NULL,
+};
+
void telnet_setup(struct session *session);
void telnet_create_listener_node(short node_idx);
void telnet_output_iac(struct session *session, char *iacs, size_t len);
@@ -334,7 +345,7 @@ short
telnet_input(struct session *session)
{
struct telnet_node *node = (struct telnet_node *)session->cookie;
- short error, n;
+ short error, n, j;
unsigned char c;
char iac_out[8] = { IAC, 0 };
@@ -461,11 +472,20 @@ telnet_input(struct session *session)
strlcpy(session->terminal_type,
(char *)&node->iac_sb + 2,
sizeof(session->terminal_type));
-
- /* TODO: compare terminal type to list */
- session->vt100 = 1;
+
session_log(session, "IAC TTYPE IS %s",
session->terminal_type);
+
+ for (j = 0; vt100_terms[j][0] != 0; j++) {
+ if (strncasecmp(session->terminal_type,
+ vt100_terms[j], strlen(vt100_terms[j])) == 0) {
+ session_log(session, "Activating vt100 ANSI "
+ "support for matching %s", vt100_terms[j]);
+ session->vt100 = 1;
+ break;
+ }
+ }
+
break;
}
node->iac_state = TELNET_IAC_STATE_IDLE;