Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2017-04-18 16:01:18 +01:00
commit 0aa959d7a3
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, tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key,
size_t *size, int expired) size_t *size, int expired)
{ {
struct client *c = tty->client;
struct tty_key *tk, *tk1; struct tty_key *tk, *tk1;
struct utf8_data ud; struct utf8_data ud;
enum utf8_state more; enum utf8_state more;
u_int i; u_int i;
wchar_t wc; wchar_t wc;
log_debug("next key is %zu (%.*s) (expired=%d)", len, (int)len, buf, log_debug("%s: next key is %zu (%.*s) (expired=%d)", c->name, len,
expired); (int)len, buf, expired);
/* Is this a known key? */ /* Is this a known key? */
tk = tty_keys_find(tty, buf, len, size); tk = tty_keys_find(tty, buf, len, size);
if (tk != NULL && tk->key != KEYC_UNKNOWN) { if (tk != NULL && tk->key != KEYC_UNKNOWN) {
tk1 = tk; tk1 = tk;
do 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); while ((tk1 = tk1->next) != NULL);
if (tk->next != NULL && !expired) if (tk->next != NULL && !expired)
return (1); return (1);
@ -510,7 +511,8 @@ tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key,
return (-1); return (-1);
*key = wc; *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); return (0);
} }
@ -524,6 +526,7 @@ tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key,
key_code key_code
tty_keys_next(struct tty *tty) tty_keys_next(struct tty *tty)
{ {
struct client *c = tty->client;
struct timeval tv; struct timeval tv;
const char *buf; const char *buf;
size_t len, size; size_t len, size;
@ -537,7 +540,7 @@ tty_keys_next(struct tty *tty)
if (len == 0) if (len == 0)
return (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? */ /* Is this a device attributes response? */
switch (tty_keys_device_attributes(tty, buf, len, &size)) { switch (tty_keys_device_attributes(tty, buf, len, &size)) {
@ -606,7 +609,7 @@ first_key:
goto complete_key; goto complete_key;
partial_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 timer is going, check for expiration. */
if (tty->flags & TTY_TIMER) { if (tty->flags & TTY_TIMER) {
@ -633,7 +636,7 @@ partial_key:
return (0); return (0);
complete_key: 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 * Check for backspace key using termios VERASE - the terminfo
@ -668,7 +671,7 @@ complete_key:
return (1); return (1);
discard_key: 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. */ /* Remove data from buffer. */
evbuffer_drain(tty->in, size); evbuffer_drain(tty->in, size);
@ -695,9 +698,10 @@ tty_keys_callback(__unused int fd, __unused short events, void *data)
static int static int
tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size) 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; struct mouse_event *m = &tty->mouse;
u_int i, x, y, b, sgr_b; 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 * 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++) { for (i = 0; i < 3; i++) {
if (len <= *size) if (len <= *size)
return (1); return (1);
c = (u_char)buf[(*size)++]; ch = (u_char)buf[(*size)++];
if (i == 0) if (i == 0)
b = c; b = ch;
else if (i == 1) else if (i == 1)
x = c; x = ch;
else 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. */ /* Check and return the mouse input. */
if (b < 32) if (b < 32)
@ -764,34 +768,35 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
while (1) { while (1) {
if (len <= *size) if (len <= *size)
return (1); return (1);
c = (u_char)buf[(*size)++]; ch = (u_char)buf[(*size)++];
if (c == ';') if (ch == ';')
break; break;
if (c < '0' || c > '9') if (ch < '0' || ch > '9')
return (-1); return (-1);
sgr_b = 10 * sgr_b + (c - '0'); sgr_b = 10 * sgr_b + (ch - '0');
} }
while (1) { while (1) {
if (len <= *size) if (len <= *size)
return (1); return (1);
c = (u_char)buf[(*size)++]; ch = (u_char)buf[(*size)++];
if (c == ';') if (ch == ';')
break; break;
if (c < '0' || c > '9') if (ch < '0' || ch > '9')
return (-1); return (-1);
x = 10 * x + (c - '0'); x = 10 * x + (ch - '0');
} }
while (1) { while (1) {
if (len <= *size) if (len <= *size)
return (1); return (1);
c = (u_char)buf[(*size)++]; ch = (u_char)buf[(*size)++];
if (c == 'M' || c == 'm') if (ch == 'M' || ch == 'm')
break; break;
if (c < '0' || c > '9') if (ch < '0' || ch > '9')
return (-1); 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. */ /* Check and return the mouse input. */
if (x < 1 || y < 1) 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; b = sgr_b;
/* Type is M for press, m for release. */ /* Type is M for press, m for release. */
sgr_type = c; sgr_type = ch;
if (sgr_type == 'm') if (sgr_type == 'm')
b |= 3; b |= 3;
@ -837,6 +842,7 @@ static int
tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len, tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
size_t *size) size_t *size)
{ {
struct client *c = tty->client;
u_int i, a, b; u_int i, a, b;
char tmp[64], *endptr; char tmp[64], *endptr;
static const char *types[] = TTY_TYPES; static const char *types[] = TTY_TYPES;
@ -878,6 +884,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
} else } else
a = b = 0; a = b = 0;
/* Store terminal type. */
type = TTY_UNKNOWN; type = TTY_UNKNOWN;
switch (a) { switch (a) {
case 1: case 1:
@ -901,6 +908,7 @@ tty_keys_device_attributes(struct tty *tty, const char *buf, size_t len,
} }
tty_set_type(tty, type); 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); return (0);
} }