Commit graph

136 commits

Author SHA1 Message Date
Peter Hutterer
b052d30978 test: fix an unused variable complaint
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:34:36 +10:00
Peter Hutterer
7965e8f4df libei: plug a memleak if we get more than one message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
515b67c6da tools: use a cleanup function for unlinking the socket
This way we can't forget to remove the file.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
39b5ba74a4 Switch the various coordinates to doubles
Original idea of 1/1000 of a pixel was to allow subpixels while sending fixed
width down the wire. Let's not care about that and use doubles instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
7d58a76254 libei: rework the wire message parsing for slightly better readability
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
09f6ef8d7a libei: use a macro to define the tests
Having to define a separate name and test function for each test is annoying.
The unit-tests can leak the tests names anyway, so let's shortcut this with a
macro.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
f35b591b9c libei: ei_get_user_data() is a public API
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
b309ebcc66 libei: define a cleanup helper for the internal message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
f149a93743 libei: unify the wire message logging in one place
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
81cb24124d libei: drop the nested event types
There's relatively little benefit here since we won't have a lot of different
events and any caller will do the switch based on the event type anyway.
So let's just export a single event type and have everything contained in
that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
b547fdc529 Improve naming for the DeviceAdded message
DeviceAdded is more self-explanatory than just "Added"

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
325622ed7c libeis: unify the wire message logging in one place
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
6c823b1308 libeis: keep a ref of the client during dispatch
On error, we call eis_client_disconnect() which unrefs the client. Since we're
using it afterwards for debugging logs, we need to keep at least one ref
going.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
fb7bbbd4ce libeis: plug a memory leak if we get more than one message per dispatch
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
2e944450a0 tools: change the default socket to $XDG_RUNTIME_DIR/eis-0
This matches the future portal implementation

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:17:51 +10:00
Peter Hutterer
ce91763683 util: add a errno wrapper
Converts into a negative errno or the respective value

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-13 16:15:09 +10:00
Peter Hutterer
8cdbcda7a7 test: add EIS integration tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:42:09 +10:00
Peter Hutterer
dd426757fb test: fix the suite name for the EI integration tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:36:10 +10:00
Peter Hutterer
efa01ffc38 test: move the with_server/with_client helper macros to eierpecken.h
We want to re-use those.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:35:41 +10:00
Peter Hutterer
d38f9c82ce meson.build: rename the test binary eitest
Faster to type, no other reason.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:35:19 +10:00
Peter Hutterer
c0ced9f234 meson.build: eierpecken helper lib must link against ei and eis
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:34:46 +10:00
Peter Hutterer
d7bc93cb4f libei: send the name in the original connect message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:17:36 +10:00
Peter Hutterer
bfee550834 More log messages for debugging
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:16:09 +10:00
Peter Hutterer
017260798b README: update the blurb about batched processing
Short story, we can't do it but it's simple enough to work around in the
caller so let them do it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:16:09 +10:00
Peter Hutterer
78b0b99883 README: add a blurb about libreis
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:16:09 +10:00
Peter Hutterer
7d75b3eb8c test: use drop caps, not reject caps as terminology
And add a test that tests for dropped caps

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 13:01:36 +10:00
Peter Hutterer
7ae661a029 test: add a test for a device dropped to zero caps and refused
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 13:01:36 +10:00
Peter Hutterer
a95d2bdd8b test: fix the accept/reject behaviour for peck eis contexts
Rejecting means disabling the accept and vice versa

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 13:01:36 +10:00
Peter Hutterer
21d6b6a5ca test: fix the default behaviour of the peck EI context
This is a flag, not a value.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 13:01:36 +10:00
Peter Hutterer
3db476930b Add a bunch of log_debug messages
We can remove those when we have a working implementation, for now it's too
painful to debug when an exchange doesn't  work for some reason.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 13:01:36 +10:00
Peter Hutterer
57a9892f5d eis: send the removed deviceid down the wire
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 11:13:14 +10:00
Peter Hutterer
2a98906b32 util: add name lookup to tristate handling
And make it more obvious that _val isn't something you should access directly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 11:06:34 +10:00
Peter Hutterer
b717837b14 Downgrade the ECANCELED warning to a mere info
ECANCELED is used for any time the other end disconnects, so it's not really
an error.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 11:06:07 +10:00
Peter Hutterer
ce51392241 test: fix the device add test
Check that we're actually adding the device and getting the message back

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-11 10:51:30 +10:00
Peter Hutterer
55246512f0 Add capabilities to the Added event
This makes it possible for the server to limit capabilities.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 19:32:34 +10:00
Peter Hutterer
fb707a3395 Add a prefix to the logger
Makes it easier to distinguish between ei and eis when everything in the tests
is just printed to stderr anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 13:50:13 +10:00
Peter Hutterer
6f75463261 Rename "accepted" to "added" for consistency with the public API
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:49:22 +10:00
Peter Hutterer
2631854dbb libreis: update the API docs a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:42:25 +10:00
Peter Hutterer
12a04fa657 libei: update the API docs a bit
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:40:53 +10:00
Peter Hutterer
fe22b9b5a5 proto: specify that the protocol isn't batch-compatible after all
The protocol itself could work like originally described here but there's a
stumbling block: the decision on whether to accept a device is made by the
caller through EIS_EVENT_DEVICE_ADDED and the following eis_device_connect()
call. We cannot process any events from that device until that call is
complete and that effectively disallows batch submission of requests.

To allow batching we'd have to pause the protocol but that means missing out
on other devices (and their events) and disconnect events. The alternative to
that would be for libeis to peek at incoming requests and sort them by device
ID so we only pause one device's stream but now we're also mangling the device
event order and potentially triggering all sorts of side-effects.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-10 08:04:05 +10:00
Peter Hutterer
626a13268e test: switch to SOCK_STREAM for the test sockets
SOCK_DGRAM gives us free message framing but the sockets we'll likely deal
with (or at least *have* to handle) are stream. This was a leftover anyway
from some debug testing.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 16:56:10 +10:00
Peter Hutterer
427d58a664 util: add a missing include to util-io.h
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 16:06:23 +10:00
Peter Hutterer
4cfa6e6225 Add configuration messages to the protocol
For the Portal case, we'll have the portal open the sockets for us and then
(depending on policy) restrict what the client can do. Then the socket can be
passed to the client with e.g. keyboards disabled and the client is none the
wiser (other than that the server will reject any keyboard caps).

Since the portal doesn't need a EI context, the configuration is a separate
small library.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 16:05:57 +10:00
Peter Hutterer
5d99d858bf libeis: a device in NEW state must be disconnected too
NEW means "client has sent request" which means we have a ref to it internally
and we have to disconnect it accordingly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 15:05:40 +10:00
Peter Hutterer
2f855c568c Drop the "hello" message
The main purpose of that was for (plain-text protocol) debugging. With the
current intentions to "preload" a connection with restrictions, having the
server initiate a connection is not useful.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
92737f7762 libeis: fix a crasher if the socket is removed before a listener starts
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
9c2c912353 util: change the sources API to source_new and sink_add_source
This is a more explicit API that makes it more obvious where the ref/unref
calls need to go. The sink now has two refs to the sources as well (epoll data
pointer and the list) which means a caller cannot just source_unref() anymore
without removing a source. Since this is how we've been using it anyway - meh.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
9d18f04e9b libeis: drain events before destroying the context
Avoid valgrind complaining about memleaks - disconnecting the clients on the
final unref queues emulated events so let's make sure we get rid of those.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
69546a4802 libei: discard all events on the final unref
ei_disconnect() may queue an event during destroy, so let's get rid of that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00
Peter Hutterer
e6b410a56a test: drain all events before exiting
We don't want valgrind to complain about leaks when we only handle a portion
of the events on the socket.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-07 14:46:20 +10:00