aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kkbd.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-08-24 18:51:36 +0200
committerMattias Andrée <maandree@operamail.com>2015-08-24 18:51:36 +0200
commit69846f9c3da4e9171016d5dcea64ffad64d16385 (patch)
tree8ef7d665a07b7d550c0f3584bb32fcd171ba9d77 /src/mds-kkbd.c
parentmds-kkbd: decipher handle_keyboard_enumeration and fix a minor bug in it (diff)
downloadmds-69846f9c3da4e9171016d5dcea64ffad64d16385.tar.gz
mds-69846f9c3da4e9171016d5dcea64ffad64d16385.tar.bz2
mds-69846f9c3da4e9171016d5dcea64ffad64d16385.tar.xz
mds-kkbd: handle_keyboard_enumeration did not add the keyboard, what an oversight
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/mds-kkbd.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mds-kkbd.c b/src/mds-kkbd.c
index c4883d0..dc0356e 100644
--- a/src/mds-kkbd.c
+++ b/src/mds-kkbd.c
@@ -780,6 +780,11 @@ int handle_keyboard_enumeration(const char* recv_modify_id)
n += received.payload_size;
+ /* Calculate upper bound for the outbound message's payload */
+ n += lengthof("Length: \n") + 3 * sizeof(size_t);
+ n += lengthof(KEYBOARD_ID "\n");
+
+
/* Calculate an upper bound for the outbound message.
`off` is an upper bound for the outbound message's
headers plus empty line and thus where we should
@@ -813,7 +818,7 @@ int handle_keyboard_enumeration(const char* recv_modify_id)
have_len = 1;
sprintf(send_buffer + n,
"Length: %zu\n",
- strlen(KEYBOARD_ID "\n") + received.payload_size);
+ received.payload_size + lengthof(KEYBOARD_ID "\n"));
n += strlen(send_buffer + n);
}
else
@@ -823,11 +828,20 @@ int handle_keyboard_enumeration(const char* recv_modify_id)
send_buffer[n++] = '\n';
}
}
+ /* If we did not `Length`-header we must add it as we will extend the payload. */
+ if (!have_len)
+ sprintf(send_buffer + n,
+ "Length: %zu\n",
+ lengthof(KEYBOARD_ID "\n")),
+ n += strlen(send_buffer + n);
/* Mark end of inbound headers. */
send_buffer[n++] = '\n';
/* Write inbound message's payload to the outbound message. */
memcpy(send_buffer + n, received.payload, received.payload_size * sizeof(char));
n += received.payload_size;
+ /* Add our keyboard to the payload. */
+ memcpy(send_buffer + n, KEYBOARD_ID "\n", lengthof(KEYBOARD_ID "\n") * sizeof(char));
+ n += lengthof(KEYBOARD_ID "\n");
/* Change `n` to tell the length of the outbound message's payload. */
n -= off;