Include client name in key logging.

pull/382/merge
nicm 2017-04-18 13:34:04 +00:00
parent 175d1854d4
commit 83ff1e9bd3
1 changed files with 37 additions and 29 deletions

View File

@ -470,21 +470,22 @@ static int
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);
@ -510,7 +511,8 @@ tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key,
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);
}
@ -524,6 +526,7 @@ tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key,
key_code
tty_keys_next(struct tty *tty)
{
struct client *c = tty->client;
struct timeval tv;
const char *buf;
size_t len, size;
@ -537,7 +540,7 @@ tty_keys_next(struct tty *tty)
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)) {
@ -606,7 +609,7 @@ first_key:
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) {
@ -633,7 +636,7 @@ partial_key:
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
@ -668,7 +671,7 @@ complete_key:
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);
@ -695,9 +698,10 @@ tty_keys_callback(__unused int fd, __unused short events, void *data)
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
@ -736,15 +740,15 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
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)
@ -764,34 +768,35 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
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)
@ -801,7 +806,7 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
b = sgr_b;
/* Type is M for press, m for release. */
sgr_type = c;
sgr_type = ch;
if (sgr_type == 'm')
b |= 3;
@ -837,6 +842,7 @@ static int
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;
@ -878,6 +884,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
} else
a = b = 0;
/* Store terminal type. */
type = TTY_UNKNOWN;
switch (a) {
case 1:
@ -901,6 +908,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
}
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);
}