doc: Document updated protocol with channels and commands

Note that this changed from earlier iterations. The channel number
is not an MSB integer, but rather a decimal followed by a newline.
This was because binary data cannot be transferred over some older
websocket standards.
doc: Document updated protocol with channels and commands

Note that this changed from earlier iterations. The channel number
is not an MSB integer, but rather a decimal followed by a newline.
This was because binary data cannot be transferred over some older
websocket standards.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Split out mock dbus service into into its own file

I'd like to use it from other tests

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Implement a unit test case for dbus-server.c

We want to start testing dbus-server.c directly, so build straightforward
test case for it that doesn't involve running javascript.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Split out transport framing and io into CockpitTransport

An interface called CockpitTransport handles the high level
concept of sending messages to the various hosts/sessions that
we support.

CockpitFdTransport is a concrete implementation of this which
transfers data over file descriptors.

This simplifies CockpitWebsocket significantly, so that we
can expand it to handle multiple hosts/transports/channels
per WebSocket.

Although there's the concept of channels in the CockpitTransport
API, these are not implemented in this commit. All channels must
be set to zero at this point.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
websocket: Allow basic message assembly during send

Our use of GBytes allows us to try to avoid excessive copies of large
amounts of payload data. This isn't always implemented, but it's possible
with this API.

One exception is how websocket messages are sent. We want to be able to
prefix messages simply without copying and reassembling the entire
message.

So add a @prefix argument to web_socket_conneciton_send(). The @prefix
and @message arguments are concatenated when sent.

Later CockpitWebsocket commits will take advantage of this capability.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Start passing around channel numbers

We start passing around channel numbers before messages. As noted in
PROTOCOL.md these are decimal digits followed by a newline.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
channel.js: Implement cockpit transport code in cockpit-web

This is a new file called channel.js the API is documented in the file
itself. The API is purposefully sparse with predictable behavior to
build off of. In particular most of the transport stuff is hidden in a
private class.

Tested in test-channel.html, which runs from 'make check' or
in a web browser.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
dbus.js: Include dbus.js in cockpit.js

It will soon depend on channel.js, and we also need to include it in
all the lint goodness. Side effect of this is that it speeds up loading.

dbus.js will no longer be a generic thing, but very cockpit specific
using the channels for transport.

Fix all the various coding lint issues in dbus.js that jsl found.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Add cockpit_transport_parse_command() helper function

This parses a control channel command from JSON into its most important
parts and validates that it's all there as expected.

Added tests for this.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
web: Start using multiple channels over the WebSocket protocol

Migrate dbus.js to use the Channel javascript class from previous
commits and start communicating with cockpit-ws over channels.

This means there is only one WebSocket connection, even for
multiple hosts. It means that we have multiple sessions being
handled from CockpitWebsocket.

This commit doesn't yet introduce sending mulitple channels to the
session side (future work), and so each channel opens up a new
cockpit-session or cockpit-agent.

Control messages are not sent, or processed from cockpit-agent. Future
work will implement this half.

This implements alternate credential support as a control message
rather than the text in the first message of the WebSocket connection.
Described in protocol.md

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
dbus-test.html: Don't hang if the DBusClient closes immediately

This helps us catch certain kinds of test failures.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
Web: Close the transport when logging out.

We want to open a new one when logging in again the next time.