-/* $OpenBSD: tty-keys.c,v 1.93 2017/02/10 12:59:18 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.94 2017/04/18 13:34:04 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key,
size_t *size, int expired)
{
+ struct client *c = tty->client;
struct tty_key *tk, *tk1;
struct utf8_data ud;
enum utf8_state more;
u_int i;
wchar_t wc;
- log_debug("next key is %zu (%.*s) (expired=%d)", len, (int)len, buf,
- expired);
+ log_debug("%s: next key is %zu (%.*s) (expired=%d)", c->name, len,
+ (int)len, buf, expired);
/* Is this a known key? */
tk = tty_keys_find(tty, buf, len, size);
if (tk != NULL && tk->key != KEYC_UNKNOWN) {
tk1 = tk;
do
- log_debug("keys in list: %#llx", tk1->key);
+ log_debug("%s: keys in list: %#llx", c->name, tk1->key);
while ((tk1 = tk1->next) != NULL);
if (tk->next != NULL && !expired)
return (1);
return (-1);
*key = wc;
- log_debug("UTF-8 key %.*s %#llx", (int)ud.size, buf, *key);
+ log_debug("%s: UTF-8 key %.*s %#llx", c->name, (int)ud.size,
+ buf, *key);
return (0);
}
key_code
tty_keys_next(struct tty *tty)
{
+ struct client *c = tty->client;
struct timeval tv;
const char *buf;
size_t len, size;
if (len == 0)
return (0);
- log_debug("keys are %zu (%.*s)", len, (int)len, buf);
+ log_debug("%s: keys are %zu (%.*s)", c->name, len, (int)len, buf);
/* Is this a device attributes response? */
switch (tty_keys_device_attributes(tty, buf, len, &size)) {
goto complete_key;
partial_key:
- log_debug("partial key %.*s", (int)len, buf);
+ log_debug("%s: partial key %.*s", c->name, (int)len, buf);
/* If timer is going, check for expiration. */
if (tty->flags & TTY_TIMER) {
return (0);
complete_key:
- log_debug("complete key %.*s %#llx", (int)size, buf, key);
+ log_debug("%s: complete key %.*s %#llx", c->name, (int)size, buf, key);
/*
* Check for backspace key using termios VERASE - the terminfo
return (1);
discard_key:
- log_debug("discard key %.*s %#llx", (int)size, buf, key);
+ log_debug("%s: discard key %.*s %#llx", c->name, (int)size, buf, key);
/* Remove data from buffer. */
evbuffer_drain(tty->in, size);
static int
tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
{
+ struct client *c = tty->client;
struct mouse_event *m = &tty->mouse;
u_int i, x, y, b, sgr_b;
- u_char sgr_type, c;
+ u_char sgr_type, ch;
/*
* Standard mouse sequences are \033[M followed by three characters
for (i = 0; i < 3; i++) {
if (len <= *size)
return (1);
- c = (u_char)buf[(*size)++];
+ ch = (u_char)buf[(*size)++];
if (i == 0)
- b = c;
+ b = ch;
else if (i == 1)
- x = c;
+ x = ch;
else
- y = c;
+ y = ch;
}
- log_debug("mouse input: %.*s", (int)*size, buf);
+ log_debug("%s: mouse input: %.*s", c->name, (int)*size, buf);
/* Check and return the mouse input. */
if (b < 32)
while (1) {
if (len <= *size)
return (1);
- c = (u_char)buf[(*size)++];
- if (c == ';')
+ ch = (u_char)buf[(*size)++];
+ if (ch == ';')
break;
- if (c < '0' || c > '9')
+ if (ch < '0' || ch > '9')
return (-1);
- sgr_b = 10 * sgr_b + (c - '0');
+ sgr_b = 10 * sgr_b + (ch - '0');
}
while (1) {
if (len <= *size)
return (1);
- c = (u_char)buf[(*size)++];
- if (c == ';')
+ ch = (u_char)buf[(*size)++];
+ if (ch == ';')
break;
- if (c < '0' || c > '9')
+ if (ch < '0' || ch > '9')
return (-1);
- x = 10 * x + (c - '0');
+ x = 10 * x + (ch - '0');
}
while (1) {
if (len <= *size)
return (1);
- c = (u_char)buf[(*size)++];
- if (c == 'M' || c == 'm')
+ ch = (u_char)buf[(*size)++];
+ if (ch == 'M' || ch == 'm')
break;
- if (c < '0' || c > '9')
+ if (ch < '0' || ch > '9')
return (-1);
- y = 10 * y + (c - '0');
+ y = 10 * y + (ch - '0');
}
- log_debug("mouse input (SGR): %.*s", (int)*size, buf);
+ log_debug("%s: mouse input (SGR): %.*s", c->name, (int)*size,
+ buf);
/* Check and return the mouse input. */
if (x < 1 || y < 1)
b = sgr_b;
/* Type is M for press, m for release. */
- sgr_type = c;
+ sgr_type = ch;
if (sgr_type == 'm')
b |= 3;
tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
size_t *size)
{
+ struct client *c = tty->client;
u_int i, a, b;
char tmp[64], *endptr;
static const char *types[] = TTY_TYPES;
} else
a = b = 0;
+ /* Store terminal type. */
type = TTY_UNKNOWN;
switch (a) {
case 1:
}
tty_set_type(tty, type);
- log_debug("received DA %.*s (%s)", (int)*size, buf, types[type]);
+ log_debug("%s: received DA %.*s (%s)", c->name, (int)*size, buf,
+ types[type]);
return (0);
}