bridge: Add a prepare vfunc to CockpitChannel

The queueing of cockpit_channel_ready() and cockpit_channel_close()
was too magical and causing too much complexity.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge: When we receive clean close before ready, don't close yet

When we received data or a clean close before the channel is ready
don't close prematurely. Make sure all the data is drained, and
then do the clean close.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge: CockpitChannel "disconnected" when transport closes

The CockpitChannel closes unsuccessfully when the transport
closes. This lets implementations react immediately, even if the
transport closes without error.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge: More robust parsing of channel options

The parsing of channel options was quite haphazard, and didn't
detect bad types for values, etc. This is more verbose, but it's more
failure proof and produces better diagnostic messages.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge: Better diagnostics for file read/write failures

In the file read/replace channels, put some context in the messages
so we can have a clue as to what's causing it. Previously we had:

cockpit-bridge-Message: /tmp/.V3DRPX/foo: Bad file descriptor

Closes #1518
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge, ws: An empty "problem" in a "close" message is a problem

A missing "problem" is a success. If the "problem" is present no matter
what it's content, then that denotes a problem.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge, base ws: Add the "eof" control message and change "close"

The new "eof" control message indicates the end of data in a channel
in a particular direction. It is relevant together with specific
payloads and affects their behavior. It may only be sent once per
direction, and after that point no more messages may be sent in
that direction.

The "eof" provides handshake interlocking for the success case for
payloads where this is necessary.

There is also no longer a "close" handshake. Either end can "close"
a channel, and the channel is considered closed immediately. In the
case of races, further messages are ignored.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Fix uninitialized memory access in CockpitTransport

Closes #1531
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
base: Implement base64 encoding of binary data

This is a surprising omission from the ArrayBuffer and typed array
work. Very odd.

Implementation is a polyfill from MDN, and fixed up.

https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding

Our implementation works with binary data in Array, Uint8Array or
Strings.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
base: Implement UTF8 encoding and decoding

We would like to use this with Arrays and not just strings like
decodeURIComponent() do. In addition we would like to stream and
possibly ignore encoding errors. In some browsers TextEncoder
and TextDecoder do some of this, but none of the solutions do
exactly what we need.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
docker: A new package for docker stuff

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
base: More general name for console CSS styles

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
shell: Give AMD interim module loading its own global

If we hang these off of the shell global, then they start to
conflict with things that are already there.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
docker: Add component that shows docker logs or console

And use this component in our main docker container details pages.
In addition document it for use outside of Cockpit.

Closes #1364
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
tools: Migrate to use nodejs tooling for validation and minify

This requires that npm and nodejs are installed in order to build
Cockpit from git. Tarball builds should not be affected.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
base, shell: Fix issues highlighted by jshint

Closes #1479
Signed-off-by: Marius Vollmer <mvollmer@redhat.com>
 * Fixed more issues found by jshint
shell: Migrate networking code to dbus-json3

This is the first step to moving the Networking page into a component.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
bridge: Remove support for dbus-json2

It's no longer in use now that the networking code has been
migrated to dbus-json3

We also no longer need the CockpitFakeManager code since all of
the dbus-json1 callers are interacting directly with ObjectManager
based services.

Fixes #1388
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
shell: Don't rely on remove notifications for dissappearing NM objects

The dbus-json3 notify code is a lot less intense about aggressively
introspecting every object after every method call, which was a big
performance issue. So we have to know when stuff goes away and clean
it up ourselves.

Closes #1511
Signed-off-by: Stef Walter <stefw@redhat.com>
 * Updated commit message
base: Allow cockpit.format() to accept variable argument lists

These are simpler than constructing an array of arguments.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>